diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevHorizontal03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevHorizontal03.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d717a344fc72724f9500a2fef68c83937b78e6d --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevHorizontal03.lean @@ -0,0 +1,354 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CharacterFactorization01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped BigOperators commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +end +end + + + +section +open scoped BigOperators commutatorElement +noncomputable section +namespace RealCharacters +variable {G : Type*} [Group G] +def scaledFamily (Ξ : Finset (G →* Multiplicative ℝ)) (R : ℕ) : Finset (G →* Multiplicative ℝ) := by + classical + exact Ξ.biUnion (fun χ => (Finset.Icc (-(R:ℤ)) (R:ℤ)).image (intScale χ)) +lemma mem_scaledFamily {Ξ : Finset (G →* Multiplicative ℝ)} {R : ℕ} + {χ : G →* Multiplicative ℝ} {q : ℤ} (hχ : χ∈Ξ) (hq : |q| ≤ R) : + intScale χ q∈scaledFamily Ξ R := by + classical + exact Finset.mem_biUnion.mpr ⟨χ,hχ,Finset.mem_image.mpr ⟨q,Finset.mem_Icc.mpr (abs_le.mp hq),rfl⟩⟩ +lemma scaledFamily_continuous [TopologicalSpace G] (Ξ : Finset (G →* Multiplicative ℝ)) (R : ℕ) + (hχ : ∀ χ∈Ξ, Continuous χ) : ∀ χ∈scaledFamily Ξ R, Continuous χ := by + classical + intro χ hm + obtain ⟨ψ,hψ,hm⟩ := Finset.mem_biUnion.mp hm + obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hm + exact intScale_continuous ψ q (hχ ψ hψ) +lemma scaledFamily_integral (Ξ : Finset (G →* Multiplicative ℝ)) (R : ℕ) (Γ : Subgroup G) + (hχ : ∀ χ∈Ξ, ∀ g∈Γ, ∃ z : ℤ, (χ g).toAdd=z) : + ∀ χ∈scaledFamily Ξ R, ∀ g∈Γ, ∃ z : ℤ, (χ g).toAdd=z := by + classical + intro χ hm + obtain ⟨ψ,hψ,hm⟩ := Finset.mem_biUnion.mp hm + obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hm + exact intScale_integral ψ q Γ (hχ ψ hψ) +end RealCharacters +namespace MalcevHorizontal +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n d : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) +variable (hlin : ∀ i : Fin d, c.correction (Fin.castLE hd i)=0) +def boundedCharacters (R : ℕ) : Finset (G →* Multiplicative ℝ) := by + classical + exact (Fintype.piFinset (fun _ : Fin d => Finset.Icc (-(R:ℤ)) (R:ℤ))).image (character c hd hlin) +omit [IsTopologicalGroup G] in +lemma mem_boundedCharacters (R : ℕ) (k : Fin d → ℤ) (hk : ∀ i, |k i| ≤ R) : + character c hd hlin k∈boundedCharacters c hd hlin R := by + classical + exact Finset.mem_image.mpr ⟨k,Fintype.mem_piFinset.mpr (fun i => Finset.mem_Icc.mpr (abs_le.mp (hk i))),rfl⟩ +omit [IsTopologicalGroup G] in +lemma boundedCharacters_continuous (R : ℕ) : + ∀ χ∈boundedCharacters c hd hlin R, Continuous χ := by + classical + intro χ hm + obtain ⟨k,hk,rfl⟩ := Finset.mem_image.mp hm + exact character_continuous c hd hlin k +omit [IsTopologicalGroup G] in +lemma boundedCharacters_integral (R : ℕ) (Γ : Subgroup G) + (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) : + ∀ χ∈boundedCharacters c hd hlin R, ∀ g∈Γ, ∃ z : ℤ, (χ g).toAdd=z := by + classical + intro χ hm + obtain ⟨k,hk,rfl⟩ := Finset.mem_image.mp hm + exact fun _ hg => character_integer c hd hlin Γ hΓ k hg +end MalcevHorizontal +end +end + + + +section +noncomputable section +open scoped BigOperators commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace MalcevHorizontal +open RationalLattice CubeFaces LeibmanSquare SquareHorizontalCharacter +open RealCharacters CharacterFactorization MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] [T2Space G] +variable {n d m : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) +variable (hlin : ∀ i : Fin d, c.correction (Fin.castLE hd i)=0) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hlevel : ∀ g : G, g∈H.level 2 ↔ horizontal c hd g=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable (c₂ : RealCoordinates (H.level 2) m) (hsk₂ : SecondKind c₂) +variable (hΓ₂ : ∀ x : H.level 2, x.val∈Γ ↔ ∀ i, ∃ z : ℤ, c₂.coord x i=z) + +include hlin hlevel hΓ hsk₂ hΓ₂ in + + +theorem uniform_character_or_proper_factorization (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) + (r : Fin (s+1) → ℕ) + (hlevel₂ : ∀ i (x : H.level 2), x.val∈H.level (i.val+2) ↔ + ∀ u : Fin m, u.val ξ.comp (diagonal H h0 h1))) R + let V := scaledFamily (Ξ.image (fun ξ => ξ.comp (lower H h0))) R + have hVc : ∀ χ∈V, Continuous χ := by + apply scaledFamily_continuous + intro χ hm + obtain ⟨ξ,hξ,rfl⟩ := Finset.mem_image.mp hm + exact (hΞc ξ hξ).comp (lower_continuous H h0) + have hVΓ : ∀ χ∈V, ∀ x : H.level 2, x.val∈Γ → ∃ z : ℤ, (χ x).toAdd=z := by + apply scaledFamily_integral _ _ (Γ.comap (H.level 2).subtype) + intro χ hm + obtain ⟨ξ,hξ,rfl⟩ := Finset.mem_image.mp hm + exact lower_integral H h0 ξ Γ (hΞΓ ξ hξ) + obtain ⟨B,hB,Tmax,hTmax,hfactor⟩ := finite_lower_factorizations H Γ c₂ h0 hsk₂ hΓ₂ hs r hlevel₂ + V hVc hVΓ s E C hC.le + refine ⟨U,V,C,hC,B,hB,Tmax,hTmax,N₀,hN₀,?_⟩ + intro N hNN ξ hξ hξ0 f hf hf0 hf1 v hv hvΓ S hSN hS hsmall + have hN : 1 ≤ (N:ℝ) := by exact_mod_cast (Nat.succ_le_iff.mpr (hN₀.trans_le hNN)) + rcases hdesc N hNN ξ hξ (hΞc ξ hξ) (hΞΓ ξ hξ) f hf hf0 hf1 v hv hvΓ S hSN hS hsmall with hob | hzero + · left + obtain ⟨k,hk,hkR,χ,hχeq,hχ0,hχc,hχΓ,P,hP,hPe,hPc⟩ := hob + refine ⟨χ,?_,hχ0,hχc,hχΓ,P,hP.trans (by omega),hPe,hPc⟩ + exact Finset.mem_union_left _ (hχeq ▸ mem_boundedCharacters c hd hlin R k hkR) + · obtain ⟨hp,q,hq,hqR,P,Q,hP,hQ,hQ0,hQ1,hPe,hQe,hPc,hQc⟩ := hzero + by_cases hd0 : ξ.comp (diagonal H h0 h1)=1 + · right + let χ := intScale (ξ.comp (lower H h0)) q + have hχV : χ∈V := mem_scaledFamily (Finset.mem_image.mpr ⟨ξ,hξ,rfl⟩) hqR + have hχ0 : χ≠1 := intScale_ne_one _ hq (lower_ne_one_of_diagonal H h0 h1 ξ hξ0 hd0) + have hc : ∀ a b : G, ⁅a,b⁆∈χ.ker.map (H.level 2).subtype := zero_pairing_kernel H h0 h1 ξ q hp + refine ⟨χ,hχV,hχ0,hVc χ hχV,hVΓ χ hχV,hc,lower_kernel_lt H χ hχ0,?_⟩ + apply hfactor χ hχV hc (N:ℝ) hN f hf hf0 (by rw [h1]; trivial) (Polynomial.C (q:ℝ)*Q) + · exact (natDegree_C_mul_le _ _).trans hQ + · intro z + simp only [eval_mul,eval_C,hQe,intScale_apply,χ] + · intro j hj + simpa only [coeff_C_mul] using hQc j hj + · left + let χ := intScale (ξ.comp (diagonal H h0 h1)) q + have hχU : χ∈U := Finset.mem_union_right _ + (mem_scaledFamily (Finset.mem_image.mpr ⟨ξ,hξ,rfl⟩) hqR) + refine ⟨χ,hχU,intScale_ne_one _ hq hd0, + intScale_continuous _ q ((hΞc ξ hξ).comp (diagonal_continuous H h0 h1)), + intScale_integral _ q Γ (diagonal_integral H h0 h1 ξ Γ (hΞΓ ξ hξ)), + Polynomial.C (q:ℝ)*P,(natDegree_C_mul_le _ _).trans hP,?_,?_⟩ + · intro z + simp only [eval_mul,eval_C,hPe,intScale_apply,χ] + · intro j hj + simpa only [coeff_C_mul] using hPc j hj + +end MalcevHorizontal +end +end + + + +section +noncomputable section +open scoped commutatorElement +namespace LeibmanSquare +open CubeFaces CubePolynomials RationalLattice +variable {G : Type*} [Group G] +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) + +include h1 in + + +lemma lattice_linear_normalization (Γ : Subgroup G) {f : ℤ → G} + (hf : Polynomial H 0 f) (hf0 : f 0=1) + (v γ : G) (hγ : γ∈Γ) (hav : f 1=v*γ) : + let g:=fun n : ℤ => f n*(γ^n)⁻¹ + Polynomial H 0 g ∧ g 0=1 ∧ g 1=v ∧ + ∀ n, QuotientGroup.mk (g n)=(QuotientGroup.mk (f n):G⧸Γ) := by + dsimp only + have hlin : (fun n : ℤ => γ^n)∈polynomials H 0 := by + simpa using NilpotentTaylor.binomial_mem (H:=H) 1 0 γ (by rw [Nat.add_zero,h1]; trivial) + refine ⟨polynomial_of_cube_mem _ ((polynomials H 0).mul_mem + (cube_mem_of_polynomial _ hf) ((polynomials H 0).inv_mem hlin)),?_,?_,?_⟩ + · simp [hf0] + · simp [hav,mul_assoc] + · intro n + exact QuotientGroup.mk_mul_of_mem _ (Γ.inv_mem (Γ.zpow_mem hγ n)) + +include h0 in +lemma polynomial_conjugate {f : ℤ → G} (hf : Polynomial H 0 f) (a : G) : + Polynomial H 0 (fun n => a*f n*a⁻¹) := by + apply polynomial_of_cube_mem + apply (polynomials H 0).mul_mem + · exact (polynomials H 0).mul_mem (const_mem (by rw [h0]; trivial)) + (cube_mem_of_polynomial _ hf) + · exact const_mem (by rw [h0]; trivial) + +include h0 in + + +lemma constant_normalization (Γ : Subgroup G) {f : ℤ → G} + (hf : Polynomial H 0 f) (v γ : G) (hγ : γ∈Γ) (hav : f 0=v*γ) : + let g:=fun n => γ*(f 0)⁻¹*f n*γ⁻¹ + Polynomial H 0 g ∧ g 0=1 ∧ + ∀ n, QuotientGroup.mk (v*g n)=(QuotientGroup.mk (f n):G⧸Γ) := by + dsimp only + have hp : Polynomial H 0 (fun n => γ*(f 0)⁻¹*f n*γ⁻¹) := by + apply polynomial_of_cube_mem + exact (polynomials H 0).mul_mem ((polynomials H 0).mul_mem + (const_mem (by rw [h0]; trivial)) (cube_mem_of_polynomial _ hf)) + (const_mem (by rw [h0]; trivial)) + refine ⟨hp,by group,?_⟩ + intro n + have he : v*(γ*(f 0)⁻¹*f n*γ⁻¹)=f n*γ⁻¹ := by rw [hav]; group + rw [he,QuotientGroup.mk_mul_of_mem _ (Γ.inv_mem hγ)] + +end LeibmanSquare +end +end + + + +section +noncomputable section +open scoped ComplexConjugate +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare PolynomialWeyl MeasureTheory UniformSquareObservable CompactFamilyDescent +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + + +theorem uniform_dense_linear_square_descent + (H : Filtration G) (h0 : H.level 0 = ⊤) (h1 : H.level 1 = ⊤) + (Γ : Subgroup G) (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1) = ⊥) + [TopologicalSpace.MetrizableSpace (ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs)] + [CompactSpace (ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs)] + (F : C(G ⧸ Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (χ : G → ℂ) + (hχ : ∀ n ∈ H.level s, ‖χ n‖ = 1) + (hw : ∀ n ∈ H.level s, ∀ x : G, + F (QuotientGroup.mk (x*n)) = χ n * F (QuotientGroup.mk x)) + (z : G) (hz : z ∈ H.level s) (hχz : χ z ≠ 1) + (C : Set G) (hCc : IsCompact C) (hC : ∀ g : G, ∃ c ∈ C, c⁻¹*g ∈ Γ) + (δ : ℝ) (hδ : 0 < δ) : + let R := restricted H h0 + letI := last_normal H h0 (by omega : 1 ≤ s) hs + let π := QuotientGroup.mk' (R.level s) + let Q := mapFiltration R π + let X := ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs + letI := TopologicalSpace.metrizableSpaceMetric X + letI : MeasurableSpace X := borel X + ∃ tests : Finset {Ψ : C(X,ℂ) // Ψ ∈ lipschitzMaps (Y := X)}, + ∃ η : ℝ, 0 < η ∧ + ∀ μ : Measure X, IsProbabilityMeasure μ → + SMulInvariantMeasure ((level H h0 1) ⧸ R.level s) X μ → + ∀ (f : ℤ → G) (hf : Polynomial H 0 f) (hf0 : f 0=1), + ∀ N T : ℕ, 0 < N → 0 < T → + δ ≤ ‖mean N (fun n => F (QuotientGroup.mk (f n)))‖ → + 4 * (T : ℝ) / N ≤ δ^2/4 → + ∃ A : Finset ℕ, + (∀ h ∈ A, h < T) ∧ δ^2/8*T ≤ (A.card : ℝ) ∧ + ∀ h ∈ A, ∃ Ψ ∈ tests, ∃ v ∈ C, ∃ γ ∈ Γ, + f 1^(h:ℤ) = v*γ ∧ + let p := fun n => π (linearNormalizedPair H h0 h1 hf + (linearRemainder H h0 hf hf0 h) h v n) + Polynomial Q 0 p ∧ + (∀ ts : List ℤ, s ≤ ts.length → ∀ n, iterDiff ts p n = 1) ∧ + η ≤ ‖mean N (fun n => Ψ.val (QuotientGroup.mk (p n))) - + ∫ x, Ψ.val x ∂μ‖ := by + classical + let R := restricted H h0 + let := last_normal H h0 (by omega : 1 ≤ s) hs + let π := QuotientGroup.mk' (R.level s) + let X := ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs + let := TopologicalSpace.metrizableSpaceMetric X + let : MeasurableSpace X := borel X + let : BorelSpace X := ⟨rfl⟩ + obtain ⟨tests,η,hη,htests⟩ := finite_square_tests H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs F χ hχ hw + (insert 1 C) (hCc.insert 1) (δ^2/8) 2 (by positivity) (by norm_num) + refine ⟨tests,η,hη,?_⟩ + intro μ hprob hinv f hf hf0 N T hN hT hlarge hboundary + let := hprob + obtain ⟨A,hAT,hAc,hAd⟩ := SquareDifferences.exists_dense_one_sided hN hT + (fun n => F (QuotientGroup.mk (f n))) (fun n => hF _) δ hδ hlarge hboundary + refine ⟨A,hAT,hAc,?_⟩ + intro h ha + obtain ⟨v,hv,hvΓ⟩ := hC (f 1^(h:ℤ)) + let γ:=v⁻¹*f 1^(h:ℤ) + have hav : f 1^(h:ℤ)=v*γ := by dsimp [γ]; group + let u:=linearRemainder H h0 hf hf0 (h:ℤ) + let q:=linearNormalizedPair H h0 h1 hf u (h:ℤ) v + let p:=fun n => π (q n) + let Φ:=observable H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs F χ hχ hw (1,v) + have hΦ : ∀ x : level H h0 1, Φ (QuotientGroup.mk (π x))=balanced H h0 Γ F 1 v x := fun _ => rfl + have hzero : (∫ x, Φ x ∂μ)=0 := + reduced_observable_mean_zero H h0 h1 Γ F 1 v s hs2 hs χ hw z hz hχz μ hinv Φ hΦ + have heval (n : ℤ) : Φ (QuotientGroup.mk (p n))= + F (QuotientGroup.mk (f n))*conj (F (QuotientGroup.mk (f (n+h)))) := by + rw [hΦ] + exact balanced_linearNormalizedPair H h0 h1 Γ F hf hf0 (f 1) u h v γ hvΓ hav + (linearRemainder_mul H h0 hf hf0 h) n + have hcorr : δ^2/8 ≤ ‖mean N (fun n => Φ (QuotientGroup.mk (p n)))‖ := by + have hc := hAd h ha + rw [SquareDifferences.norm_mean_derivative_swap N h 0] at hc + convert hc using 1 + congr 1 + apply congrArg (mean N) + funext n + rw [heval] + simp only [PolynomialWeyl.derivative,Nat.add_zero,Nat.cast_add] + let L : C(X,ℂ) →ₗ[ℂ] ℂ := discrepancy μ N (fun n => QuotientGroup.mk (p n)) + have hL : ∀ Ψ, ‖L Ψ‖ ≤ 2 * ‖Ψ‖ := discrepancy_bound μ N hN _ + have hcorr' : δ^2/8 ≤ ‖L Φ‖ := by + change δ^2/8 ≤ ‖mean N (fun n => Φ (QuotientGroup.mk (p n))) - ∫ x, Φ x ∂μ‖ + simpa only [hzero,sub_zero] using hcorr + obtain ⟨Ψ,hΨ,hΨcorr⟩ := htests L hL ⟨1,Set.mem_insert _ _,v,Set.mem_insert_of_mem _ hv,hcorr'⟩ + obtain ⟨hp,hptop⟩ := linearNormalizedPair_reduced H h0 h1 hf u (h:ℤ) v + (le_trans (by decide : 1 ≤ 2) hs2) hs + exact ⟨Ψ,hΨ,v,hv,γ,hvΓ,hav,hp,hptop,hΨcorr⟩ + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail01.lean new file mode 100644 index 0000000000000000000000000000000000000000..d352f0b34f680a05b93e54f166d6630b3cb3cd81 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail01.lean @@ -0,0 +1,369 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.LeibmanSquare05 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped commutatorElement BigOperators +end +end + + + +section +noncomputable section +open scoped BigOperators +namespace MalcevHorizontal +open CubeFaces LeibmanSquare RationalLattice _root_.Polynomial _root_.OAI.Polynomial +variable {G : Type*} [Group G] [TopologicalSpace G] +variable {n d : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) +variable (hlin : ∀ i : Fin d, c.correction (Fin.castLE hd i)=0) +variable (H : Filtration G) (h0 : H.level 0=⊤) +variable (hlevel : ∀ g : G, g∈H.level 2 ↔ horizontal c hd g=0) + +include hlevel in +lemma character_lower_trivial (k : Fin d → ℤ) (u : H.level 2) : character c hd hlin k u=1 := by + change Multiplicative.ofAdd (∑ i,(k i:ℝ)*horizontal c hd u i)=1 + rw [(hlevel u).mp u.property] + simp + +include h0 hlevel in +lemma original_horizontal_linear {f : ℤ → G} (hf : Polynomial H 0 f) (hf0 : f 0=1) + (k : Fin d → ℤ) (z : ℤ) : + (character c hd hlin k (f z)).toAdd=(z:ℝ)*∑ i,(k i:ℝ)*horizontal c hd (f 1) i := by + have he := congrArg (character c hd hlin k) (linearRemainder_mul H h0 hf hf0 z) + rw [map_mul,character_lower_trivial c hd hlin H hlevel,map_zpow,one_mul] at he + have hh:=congrArg Multiplicative.toAdd he + simpa only [toAdd_zpow,zsmul_eq_mul,character,MonoidHom.coe_mk,OneHom.coe_mk,toAdd_ofAdd] using hh + +include h0 hlevel in + + +theorem original_horizontal_obstruction + (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + {f : ℤ → G} (hf : Polynomial H 0 f) (hf0 : f 0=1) + (R N : ℕ) (A : ℝ) (hA : 0 ≤ A) + (k : Fin d → ℤ) (hk : k≠0) (hkR : ∀ i, |k i| ≤ R) + (m : ℤ) (hm : |(∑ i,(k i:ℝ)*horizontal c hd (f 1) i)-m| ≤ A/N) : + ∃ χ : G →* Multiplicative ℝ, χ≠1 ∧ Continuous χ ∧ + (∀ g∈Γ, ∃ z : ℤ, (χ g).toAdd=z) ∧ + (∃ k' : Fin d → ℤ, (∀ i, |k' i| ≤ R) ∧ χ=character c hd hlin k') ∧ + ∃ P : ℝ[X], P.natDegree ≤ 1 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(χ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 character_integer c hd hlin Γ hΓ k hg,⟨k,hkR,rfl⟩,C α*X,?_,?_,?_⟩ + · exact (natDegree_mul_le.trans (by simp [natDegree_C,natDegree_X])) + · intro z + rw [eval_mul,eval_C,eval_X,original_horizontal_linear c hd hlin H h0 hlevel hf hf0 k z] + change α*(z:ℝ)=(z:ℝ)*α + ring + · intro j hj + by_cases hj1 : j=1 + · subst j + exact ⟨m,by simpa [coeff_C_mul,α] using hm⟩ + · refine ⟨0,?_⟩ + simp only [coeff_C_mul,coeff_X,ite_eq_right (Ne.symm hj1),mul_zero,Int.cast_zero,sub_zero,abs_zero] + positivity + +end MalcevHorizontal +end +end + + + +section +noncomputable section +namespace MalcevHorizontal +open RationalLattice CubeFaces LeibmanSquare BracketHyperplanes +variable {G : Type*} [Group G] [TopologicalSpace G] +variable {n d : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) +variable (hlin : ∀ i : Fin d, c.correction (Fin.castLE hd i)=0) + +include hlin in +lemma horizontal_pow (a : G) (h : ℕ) : + horizontal c hd (a^h)=fun i => (h:ℝ)*horizontal c hd a i := by + have he := congrArg Multiplicative.toAdd (map_pow (quotientHom c hd hlin) a h) + rw [toAdd_pow] at he + change horizontal c hd (a^h)=h • horizontal c hd a at he + funext i + simpa only [Pi.smul_apply,nsmul_eq_mul] using congrFun he i + +variable (Γ : Subgroup G) +variable (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + +include hlin hΓ in + + +lemma representative_torus (a : G) (v : ℕ → G) + (hv : ∀ h, (v h)⁻¹*a^h∈Γ) (h : ℕ) : + BracketHyperplanes.torusMap (horizontal c hd (v h))= + BracketHyperplanes.torusMap (fun i => horizontal c hd a i*(h:ℝ)+(0:Fin d → ℝ) i) := by + funext i + obtain ⟨z,hz⟩ := (hΓ ((v h)⁻¹*a^h)).mp (hv h) (Fin.castLE hd i) + change horizontal c hd ((v h)⁻¹*a^h) i=(z:ℝ) at hz + rw [horizontal_mul c hd hlin,horizontal_inv c hd hlin,horizontal_pow c hd hlin] at hz + change -horizontal c hd (v h) i+(h:ℝ)*horizontal c hd a i=(z:ℝ) at hz + have he : horizontal c hd a i*(h:ℝ)=horizontal c hd (v h) i+(z:ℝ) := by linarith + change (horizontal c hd (v h) i:UnitAddCircle)= + ((horizontal c hd a i*(h:ℝ)+0:ℝ):UnitAddCircle) + rw [he] + simp + +lemma reduced_horizontal_bound (a : G) : ‖horizontal c hd (reduceCoordinates c a n)‖ ≤ 1 := by + apply (pi_norm_le_iff_of_nonneg (by norm_num : (0:ℝ)≤1)).mpr + intro i + have hi := reduceCoordinates_bounds c a n (Fin.castLE hd i) (Fin.castLE hd i).isLt + change |c.coord (reduceCoordinates c a n) (Fin.castLE hd i)| ≤ 1 + rw [abs_of_nonneg hi.1] + exact hi.2.le + +include hlin hΓ in + + +lemma canonical_representative_orbit (a : G) : + let v:=fun h : ℕ => reduceCoordinates c (a^h) n + (∀ h, ‖horizontal c hd (v h)‖≤1) ∧ + (∀ h, (v h)⁻¹*a^h∈Γ) ∧ + ∀ h,BracketHyperplanes.torusMap (horizontal c hd (v h))= + BracketHyperplanes.torusMap (fun i => horizontal c hd a i*(h:ℝ)+(0:Fin d → ℝ) i) := by + dsimp only + have hv (h : ℕ) := reduceCoordinates_coset c Γ hΓ (a^h) n + exact ⟨fun h => reduced_horizontal_bound c hd _,hv, + representative_torus c hd hlin Γ hΓ a _ hv⟩ + +end MalcevHorizontal +end +end + + + +section +noncomputable section +open scoped BigOperators commutatorElement +namespace MalcevHorizontal +open RationalLattice CubeFaces LeibmanSquare SquareHorizontalCharacter _root_.Polynomial _root_.OAI.Polynomial BracketDrift +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n d : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) +variable (hlin : ∀ i : Fin d, c.correction (Fin.castLE hd i)=0) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hlevel : ∀ g : G, g∈H.level 2 ↔ horizontal c hd g=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + +include hlin hlevel hΓ in + + +theorem geometric_scalar_descent (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) + (Ξ : Finset (level H h0 1 →* Multiplicative ℝ)) (δ A : ℝ) (hδ : 0<δ) (hA : 0≤A) : + ∃ R : ℕ, 0 horizontal c hd (v h)) hv (representative_torus c hd hlin Γ hΓ (f 1) v hvΓ) + P Q hP hQ S hSN hS hsmall' with hfirst | hzero + · left + obtain ⟨k,hk,hkR,m,hm⟩ := hfirst + obtain ⟨χ,hχ0,hχc,hχΓ,hχk,P',hP',hPe',hPc'⟩ := + original_horizontal_obstruction c hd hlin H h0 hlevel Γ hΓ hf hf0 R N C hC.le k hk hkR m hm + obtain ⟨k',hk'R,hχeq⟩ := hχk + refine ⟨k',?_,hk'R,χ,hχeq,hχ0,hχc,hχΓ,P',hP',hPe',hPc'⟩ + intro hz + apply hχ0 + rw [hχeq,hz] + ext x + simp [character] + · right + obtain ⟨hMz,q,hq,hqR,hPc,hQc⟩ := hzero + exact ⟨(matrix_zero_iff c hd H h0 h1 ξ M hM).mp hMz, + q,hq,hqR,P,Q,hP,hQ,hQ0,hQ1,hPe,hQe,hPc,hQc⟩ + +end MalcevHorizontal +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace MalcevTailSection +open RationalLattice MalcevCharacters IntegerHyperplane +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) (hsk : SecondKind c) + +def axisHom (i : Fin n) : Multiplicative ℝ →* G where + toFun t := axis c i t.toAdd + map_one' := axis_zero c i + map_mul' s t := hsk.axis_add i s.toAdd t.toAdd + +def HasPivot (k : Fin n → ℤ) (r : ℕ) : Prop := ∃ p : Fin n, r ≤ p.val ∧ k p ≠ 0 + + + +def tailSection (k : Fin n → ℤ) (r : ℕ) (t : ℝ) : G := by + classical + exact if h : HasPivot k r then axis c h.choose (t/(k h.choose:ℝ)) else 1 + +lemma section_zero (k : Fin n → ℤ) (r : ℕ) : tailSection c k r 0 = 1 := by + classical + unfold tailSection + split_ifs <;> simp +include hsk in +lemma section_add (k : Fin n → ℤ) (r : ℕ) (s t : ℝ) : + tailSection c k r (s+t) = tailSection c k r s * tailSection c k r t := by + classical + unfold tailSection + split_ifs <;> simp [add_div,hsk.axis_add] + +def flow (k : Fin n → ℤ) (r : ℕ) : Multiplicative ℝ →* G where + toFun t := tailSection c k r t.toAdd + map_one' := section_zero c k r + map_mul' s t := section_add c hsk k r s.toAdd t.toAdd + +include hsk in +lemma section_zpow (k : Fin n → ℤ) (r : ℕ) (t : ℝ) (z : ℤ) : + tailSection c k r (z*t) = tailSection c k r t ^ z := by + have h := (flow c hsk k r).map_zpow (Multiplicative.ofAdd t) z + simpa [flow,zsmul_eq_mul] using h + +lemma section_continuous (k : Fin n → ℤ) (r : ℕ) : Continuous (tailSection c k r) := by + classical + unfold tailSection + split_ifs + · exact (axis_continuous c _).comp (continuous_id.div_const _) + · exact continuous_const + +lemma section_tail (k : Fin n → ℤ) (r : ℕ) (t : ℝ) (i : Fin n) (hi : i.val < r) : + c.coord (tailSection c k r t) i = 0 := by + classical + unfold tailSection + split_ifs with h + · rw [coord_axis] + apply Pi.single_eq_of_ne + intro he + have := h.choose_spec.1 + subst i + omega + · exact c.one_coord i + +lemma section_rational (k : Fin n → ℤ) (r : ℕ) (t : ℚ) : + IsRational c (tailSection c k r t) := by + classical + intro i + unfold tailSection + split_ifs with h + · refine ⟨if i=h.choose then t/(k h.choose:ℚ) else 0,?_⟩ + rw [coord_axis] + simp only [Pi.single_apply] + split_ifs <;> push_cast <;> rfl + · exact ⟨0,by simpa using (c.one_coord i).symm⟩ + +lemma section_bound (k : Fin n → ℤ) (r : ℕ) (t : ℝ) (i : Fin n) : + |c.coord (tailSection c k r t) i| ≤ |t| := by + classical + unfold tailSection + split_ifs with h + · rw [coord_axis] + by_cases hi : i=h.choose + · subst i + rw [Pi.single_eq_same,abs_div] + have hk : (1:ℝ) ≤ |(k h.choose:ℝ)| := by + exact_mod_cast (Int.one_le_abs h.choose_spec.2) + exact div_le_self (abs_nonneg t) hk + · simp [Pi.single_eq_of_ne hi,abs_nonneg] + · simp [c.one_coord,abs_nonneg] + +lemma form_zero_of_no_pivot (k : Fin n → ℤ) (r : ℕ) + (hk : ¬ HasPivot k r) (x : Fin n → ℝ) (hx : ∀ i, i.val < r → x i = 0) : + form k x = 0 := by + change (∑ i, (k i:ℝ)*x i) = 0 + apply Finset.sum_eq_zero + intro i _ + by_cases hir : i.val < r + · rw [hx i hir,mul_zero] + · have hi : k i = 0 := by by_contra he; exact hk ⟨i,by omega,he⟩ + simp [hi] + +variable (χ : G →* Multiplicative ℝ) (k : Fin n → ℤ) +variable (hχ : ∀ g, (χ g).toAdd = form k (c.coord g)) +include hχ in +lemma character_section (r : ℕ) (t : ℝ) (ht : ¬ HasPivot k r → t=0) : + (χ (tailSection c k r t)).toAdd = t := by + classical + unfold tailSection + split_ifs with h + · rw [hχ,coord_axis] + change (∑ i, (k i:ℝ)*(Pi.single h.choose (t/(k h.choose:ℝ)) : Fin n → ℝ) i) = t + simp only [Pi.single_apply,mul_ite,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + exact mul_div_cancel₀ t (by exact_mod_cast h.choose_spec.2) + · rw [ht h] + simp + +end MalcevTailSection + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail02.lean new file mode 100644 index 0000000000000000000000000000000000000000..b927f83fc946ea033a2c66f4f5383dff4eca1cac --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail02.lean @@ -0,0 +1,337 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevTail01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped BigOperators +noncomputable section +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace MalcevTailFactor +open RationalLattice MalcevCharacters MalcevTailSection IntegerHyperplane +open CubeFaces CubePolynomials RationalFactorPeriods +variable {G : Type*} [Group G] [TopologicalSpace G] {n l : ℕ} +variable (c : RealCoordinates G n) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (k : Fin n → ℤ) +variable (hχ : ∀ g, (χ g).toAdd = form k (c.coord g)) +variable (r : Fin l → ℕ) (a : Fin l → G) + +def beta (i : Fin l) : ℝ := (χ (a i)).toAdd + +def numerator (i : Fin l) : ℤ := round (beta χ a i) + +def error (i : Fin l) : ℝ := beta χ a i - (numerator χ a i : ℝ) + +def smallCoeff (i : Fin l) : G := tailSection c k (r i) (error χ a i) + +def rationalGenerator (i : Fin l) : G := tailSection c k (r i) 1 + +def rationalCoeff (i : Fin l) : G := rationalGenerator c k r i ^ numerator χ a i + +variable (ha : ∀ i, ∀ u : Fin n, u.val < r i → c.coord (a i) u = 0) +include hχ ha in +lemma beta_zero (i : Fin l) (h : ¬ HasPivot k (r i)) : beta χ a i = 0 := by + rw [beta,hχ] + exact form_zero_of_no_pivot k (r i) h _ (ha i) + +include hχ ha in +lemma error_zero (i : Fin l) (h : ¬ HasPivot k (r i)) : error χ a i = 0 := by + simp [error,numerator,beta_zero c χ k hχ r a ha i h] + +include hsk in +lemma rationalCoeff_eq (i : Fin l) : rationalCoeff c χ k r a i = + tailSection c k (r i) (numerator χ a i) := by + simpa [rationalCoeff,rationalGenerator] using + (section_zpow c hsk k (r i) 1 (numerator χ a i)).symm + +include hχ ha in +lemma small_character (i : Fin l) : + (χ (smallCoeff c χ k r a i)).toAdd = error χ a i := by + exact character_section c χ k hχ (r i) (error χ a i) + (error_zero c χ k hχ r a ha i) + +include hsk hχ ha in +lemma rational_character (i : Fin l) : + (χ (rationalCoeff c χ k r a i)).toAdd = numerator χ a i := by + rw [rationalCoeff_eq c hsk χ k r a i] + apply character_section c χ k hχ + intro h + simp [numerator,beta_zero c χ k hχ r a ha i h] + +lemma generator_rational (i : Fin l) : IsRational c (rationalGenerator c k r i) := by + simpa [rationalGenerator] using section_rational c k (r i) 1 + +lemma small_bound (i : Fin l) (u : Fin n) : + |c.coord (smallCoeff c χ k r a i) u| ≤ ‖(beta χ a i : UnitAddCircle)‖ := by + rw [UnitAddCircle.norm_eq] + exact section_bound c k (r i) (error χ a i) u + +variable (j : Fin l → ℕ) +include hsk hχ ha in +lemma word_character_split (b : ℤ) : + (χ (orderedWord a j b)).toAdd = + (χ (orderedWord (smallCoeff c χ k r a) j b)).toAdd + + (χ (orderedWord (rationalCoeff c χ k r a) j b)).toAdd := by + simp only [orderedWord_character,small_character c χ k hχ r a ha, + rational_character c hsk χ k hχ r a ha,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + change ((Ring.choose b (j i) : ℤ) : ℝ)*beta χ a i = _ + simp [error,mul_sub] + +include hsk hχ ha in +lemma residual_kernel (b : ℤ) : + (orderedWord (smallCoeff c χ k r a) j b)⁻¹ * orderedWord a j b * + (orderedWord (rationalCoeff c χ k r a) j b)⁻¹ ∈ χ.ker := by + change χ _ = 1 + apply Multiplicative.toAdd.injective + simp only [map_mul,map_inv,toAdd_mul,toAdd_inv, + toAdd_one] + linarith [word_character_split c hsk χ k hχ r a ha j b] + +variable (H : Filtration G) (q : ℕ) +variable (hlevel : ∀ i g, g ∈ H.level (j i+q) ↔ ∀ u : Fin n, u.val < r i → c.coord g u = 0) +include hlevel in +lemma small_polynomial : orderedWord (smallCoeff c χ k r a) j ∈ polynomials H q := by + apply orderedWord_mem + intro i + rw [hlevel] + exact section_tail c k (r i) _ + +include hsk hlevel in +lemma rational_polynomial : orderedWord (rationalCoeff c χ k r a) j ∈ polynomials H q := by + apply orderedWord_mem + intro i + rw [rationalCoeff_eq c hsk χ k r a i,hlevel] + exact section_tail c k (r i) _ + +end MalcevTailFactor +end +end + + + +section +open scoped commutatorElement +noncomputable section +namespace CubePolynomials +open CubeFaces +variable {G A : Type*} [Group G] [Group A] + + + +theorem residual_refinement (H : Filtration G) (s : ℕ) (hbot : H.level s = ⊥) + (φ : A →* G) (χ : A →* Multiplicative ℝ) + (hcomm : ∀ a b : G, ⁅a,b⁆ ∈ χ.ker.map φ) + (g : ℤ → G) (hg : g ∈ polynomials H 0) (a : G) (ha : a ∈ H.level 1) + (q e v : ℤ → A) (he : (fun n => φ (e n)) ∈ polynomials H 0) + (hv : (fun n => φ (v n)) ∈ polynomials H 0) + (hgq : ∀ n, g n = φ (q n) * a^n) + (hker : ∀ n, (e n)⁻¹ * q n * (v n)⁻¹ ∈ χ.ker) : + (fun n => (φ (e n))⁻¹ * g n * (φ (v n))⁻¹) ∈ + polynomials (H.refine (χ.ker.map φ) hcomm) 0 := by + let K := χ.ker.map φ + have hf : (fun n => (φ (e n))⁻¹ * g n * (φ (v n))⁻¹) ∈ polynomials H 0 := + (polynomials H 0).mul_mem ((polynomials H 0).mul_mem + ((polynomials H 0).inv_mem he) hg) ((polynomials H 0).inv_mem hv) + apply refine_of_linear_coset H _ hcomm s hbot _ hf a ha + intro n + have hrow : (φ (e n))⁻¹ * φ (q n) * (φ (v n))⁻¹ ∈ K := by + have hm : φ ((e n)⁻¹ * q n * (v n)⁻¹) ∈ K := + Subgroup.mem_map_of_mem φ (hker n) + simpa only [map_mul,map_inv] using hm + have hc := hcomm (φ (v n)) (a^n) + have hprod := K.mul_mem hrow hc + convert hprod using 1 + rw [hgq] + simp only [commutatorElement_def] + group + +end CubePolynomials +end +end + + + +section +noncomputable section +namespace RationalFactorPeriods +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable [PreconnectedSpace G] [LocallyCompactSpace G] [T2Space G] {n l : ℕ} + + + +theorem uniform_rational_word_period + (c : RationalLattice.RealCoordinates G n) (Γ : Subgroup G) [DiscreteTopology Γ] + (hΓrat : Γ ≤ RationalLattice.rationalSubgroup c) + (C : Set G) (hC : IsCompact C) (hreps : ∀ g : G, ∃ x ∈ C, x⁻¹*g ∈ Γ) + (v : Fin l → G) (hv : ∀ i, RationalLattice.IsRational c (v i)) + (j : Fin l → ℕ) (s : ℕ) (hj : ∀ i, j i ≤ s) : + ∃ T : ℕ, 0 < T ∧ ∀ m : Fin l → ℤ, + Function.Periodic (fun b => (QuotientGroup.mk + (orderedWord (fun i => v i ^ m i) j b) : G ⧸ Γ)) (T : ℤ) := by + classical + let S := Finset.univ.image v + have hSrat : ∀ g ∈ S, RationalLattice.IsRational c g := by + intro g hg + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hg + exact hv i + obtain ⟨H,hΓH,hSH,hHrat,hHd,hHi⟩ := + RationalLattice.finite_rational_extension c Γ hΓrat C hC hreps S hSrat + let : (Γ.subgroupOf H).FiniteIndex := hHi + let : Fintype (H ⧸ Γ.subgroupOf H) := Fintype.ofFinite _ + let K := Equiv.Perm (H ⧸ Γ.subgroupOf H) + let φ : H →* K := MulAction.toPermHom H (H ⧸ Γ.subgroupOf H) + have hvH (i : Fin l) : v i ∈ H := hSH (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + refine ⟨Fintype.card K * s.factorial,Nat.mul_pos Fintype.card_pos s.factorial_pos,?_⟩ + intro m b + let a : Fin l → H := fun i => ⟨v i ^ m i,H.zpow_mem (hvH i) _⟩ + have he := congrArg (fun e : K => e (QuotientGroup.mk (1:H))) + (finite_image_periodic φ a j s hj b) + have hquot : (QuotientGroup.mk (orderedWord a j (b+(Fintype.card K*s.factorial:ℕ))) : H ⧸ Γ.subgroupOf H) = + QuotientGroup.mk (orderedWord a j b) := by + simpa [φ,K,MulAction.toPermHom] using he + have hmem := QuotientGroup.eq.mp hquot + have heG : (QuotientGroup.mk ((orderedWord a j (b+(Fintype.card K*s.factorial:ℕ)) : H):G) : G ⧸ Γ) = + QuotientGroup.mk ((orderedWord a j b : H):G) := QuotientGroup.eq.mpr hmem + have hmap (b : ℤ) : ((orderedWord a j b : H):G) = + orderedWord (fun i => v i ^ m i) j b := orderedWord_map H.subtype a j b + simpa only [hmap] using heG + +end RationalFactorPeriods +end +end + + + +section +open scoped commutatorElement BigOperators +noncomputable section +namespace CharacterFactorization +open CubeFaces CubePolynomials RationalFactorPeriods RationalLattice MalcevCharacters MalcevTailFactor +variable {G : Type*} [Group G] [TopologicalSpace G] +variable (H : Filtration G) {n s : ℕ} (c : RealCoordinates (H.level 2) n) (hsk : SecondKind c) +variable (χ : H.level 2 →* Multiplicative ℝ) (k : Fin n → ℤ) +variable (hχ : ∀ x, (χ x).toAdd = IntegerHyperplane.form k (c.coord x)) +variable (r : Fin s → ℕ) +variable (hlevel : ∀ i (x : H.level 2), x.val ∈ H.level (i.val+2) ↔ + ∀ u : Fin n, u.val < r i → c.coord x u = 0) +variable (hcomm : ∀ a b : G, ⁅a,b⁆ ∈ χ.ker.map (H.level 2).subtype) + +def epsilon (a : Fin s → H.level 2) (z : ℤ) : G := + (orderedWord (smallCoeff c χ k r a) (fun i => i.val+2) z).val + +def gamma (a : Fin s → H.level 2) (z : ℤ) : G := + (orderedWord (rationalCoeff c χ k r a) (fun i => i.val+2) z).val + +def residual (g : ℤ → G) (a : Fin s → H.level 2) (z : ℤ) : G := + (epsilon H c χ k r a z)⁻¹ * g z * (gamma H c χ k r a z)⁻¹ + +lemma factorization_identity (g : ℤ → G) (a : Fin s → H.level 2) (z : ℤ) : + g z = epsilon H c χ k r a z * residual H c χ k r g a z * gamma H c χ k r a z := by + unfold residual + group + +include hlevel in +lemma epsilon_polynomial (a : Fin s → H.level 2) : + epsilon H c χ k r a ∈ polynomials H 0 := by + have he : epsilon H c χ k r a = orderedWord (fun i => (smallCoeff c χ k r a i).val) + (fun i => i.val+2) := funext (fun z => orderedWord_map (H.level 2).subtype _ _ z) + rw [he] + apply orderedWord_mem + intro i + simp only [add_zero] + rw [hlevel] + exact MalcevTailSection.section_tail c k (r i) _ + +include hsk hlevel in +lemma gamma_polynomial (a : Fin s → H.level 2) : + gamma H c χ k r a ∈ polynomials H 0 := by + have he : gamma H c χ k r a = orderedWord (fun i => (rationalCoeff c χ k r a i).val) + (fun i => i.val+2) := funext (fun z => orderedWord_map (H.level 2).subtype _ _ z) + rw [he] + apply orderedWord_mem + intro i + simp only [add_zero] + rw [hlevel,rationalCoeff_eq c hsk χ k r a i] + exact MalcevTailSection.section_tail c k (r i) _ + +lemma epsilon_zero (a : Fin s → H.level 2) : epsilon H c χ k r a 0 = 1 := by + have he : ∀ i : Fin s, smallCoeff c χ k r a i ^ Ring.choose (0:ℤ) (i.val+2) = 1 := by + intro i + rw [Ring.choose_zero_pos ℤ (by omega),zpow_zero] + simp [epsilon,orderedWord] + +include hsk hχ hlevel in +lemma residual_polynomial (hbot : H.level s = ⊥) + (g : ℤ → G) (hg : g ∈ polynomials H 0) (h1 : g 1 ∈ H.level 1) + (a : Fin s → H.level 2) (ha : ∀ i, (a i).val ∈ H.level (i.val+2)) + (he : ∀ z, g z = (orderedWord a (fun i => i.val+2) z).val * g 1 ^ z) : + residual H c χ k r g a ∈ polynomials (H.refine (χ.ker.map (H.level 2).subtype) hcomm) 0 := by + apply residual_refinement H s hbot (H.level 2).subtype χ hcomm g hg (g 1) h1 + (orderedWord a (fun i => i.val+2)) + (orderedWord (smallCoeff c χ k r a) (fun i => i.val+2)) + (orderedWord (rationalCoeff c χ k r a) (fun i => i.val+2)) + (epsilon_polynomial H c χ k r hlevel a) + (gamma_polynomial H c hsk χ k r hlevel a) he + exact MalcevTailFactor.residual_kernel c hsk χ k hχ r a + (fun i => (hlevel i (a i)).mp (ha i)) (fun i => i.val+2) + +include hsk hχ hlevel in + + +theorem normalized_factorization (hbot : H.level s = ⊥) + (g : ℤ → G) (hg : g ∈ polynomials H 0) (h0 : g 0=1) (h1 : g 1 ∈ H.level 1) : + ∃ a : Fin s → H.level 2, + (∀ i, (a i).val ∈ H.level (i.val+2)) ∧ + (∀ z, g z = (orderedWord a (fun i => i.val+2) z).val * g 1 ^ z) ∧ + epsilon H c χ k r a ∈ polynomials H 0 ∧ + gamma H c χ k r a ∈ polynomials H 0 ∧ + residual H c χ k r g a ∈ polynomials (H.refine (χ.ker.map (H.level 2).subtype) hcomm) 0 := by + obtain ⟨a,ha,he⟩ := NilpotentTaylor.normalized_subgroup_taylor H s hbot g hg h0 h1 + exact ⟨a,ha,he,epsilon_polynomial H c χ k r hlevel a, + gamma_polynomial H c hsk χ k r hlevel a, + residual_polynomial H c hsk χ k hχ r hlevel hcomm hbot g hg h1 a ha he⟩ + + + +variable [IsTopologicalGroup G] [T2Space G] + +theorem uniform_gamma_period (Γ : Subgroup G) + (hΓ : ∀ x : H.level 2, x.val ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord x i = z) : + ∃ T : ℕ, 0 < T ∧ ∀ a : Fin s → H.level 2, + Function.Periodic (fun z => (QuotientGroup.mk (gamma H c χ k r a z) : G ⧸ Γ)) (T:ℤ) := by + let L := Γ.comap (H.level 2).subtype + have hL : ∀ x : H.level 2, x ∈ L ↔ ∀ i, ∃ z : ℤ, c.coord x i = z := hΓ + let : DiscreteTopology L := integerCoordinates_discrete c L hL + let : ConnectedSpace (H.level 2) := c.coord.symm.surjective.connectedSpace c.coord.symm.continuous + let : LocallyCompactSpace (H.level 2) := c.coord.locallyCompactSpace_iff.mpr inferInstance + obtain ⟨C,hC,hrep⟩ := compact_reps_of_integerCoordinates c L hL + obtain ⟨T,hT,hper⟩ := uniform_rational_word_period c L (integerCoordinates_rational c L hL) + C hC hrep (rationalGenerator c k r) (generator_rational c k r) + (fun i => i.val+2) (s+2) (fun i => by omega) + refine ⟨T,hT,fun a z => ?_⟩ + have hp := hper (numerator χ a) z + have hm := QuotientGroup.eq.mp hp + exact QuotientGroup.eq.mpr hm + +end CharacterFactorization + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail03.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad6c4172b502497fe02d45321b99cad755f8d7b1 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevTail03.lean @@ -0,0 +1,273 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevTail02 +import OAI.Combinatorics.SumProduct.Alignment.SmoothBinomial01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +end + + + +section +noncomputable section +namespace SmoothBinomial +open Set + + +theorem smooth_binomial_increment (j : ℕ) (A C : ℝ) (hC : 0 ≤ C) : + ∃ B > 0, ∀ L lam : ℝ, 1 ≤ L → |L^j*lam| ≤ C → + (∀ x : ℝ, |x| ≤ A*L → |lam*Ring.choose x j| ≤ B) ∧ + (∀ x y : ℝ, |x| ≤ A*L → |y| ≤ A*L → + |lam*Ring.choose x j - lam*Ring.choose y j| ≤ (B/L)*|x-y|) := by + obtain ⟨B0,hB0,hv⟩ := smooth_binomial_bounds j 0 A C hC + obtain ⟨B1,hB1,hd⟩ := smooth_binomial_bounds j 1 A C hC + refine ⟨B0+B1,by positivity,?_⟩ + intro L lam hL hlam + have hLp : 0 < L := lt_of_lt_of_le zero_lt_one hL + have hdiff : Differentiable ℝ (fun x : ℝ => lam*Ring.choose x j) := by + simp only [choose_eq_product] + fun_prop + constructor + · intro x hx + have he := hv L lam hL hlam x hx + simp only [iteratedDeriv_zero,pow_zero,div_one] at he + linarith + · intro x y hx hy + have hbound : ∀ z ∈ Icc (- (A*L)) (A*L), ‖deriv (fun w : ℝ => lam*Ring.choose w j) z‖ ≤ B1/L := by + intro z hz + simpa using hd L lam hL hlam z (abs_le.mpr hz) + have he := Convex.norm_image_sub_le_of_norm_deriv_le (fun z _ => hdiff z) + hbound (convex_Icc (- (A*L)) (A*L)) (abs_le.mp hy) (abs_le.mp hx) + change |lam*Ring.choose x j - lam*Ring.choose y j| ≤ (B1/L)*|x-y| at he + exact he.trans (mul_le_mul_of_nonneg_right + (div_le_div_of_nonneg_right (by linarith) hLp.le) (abs_nonneg _)) + +end SmoothBinomial +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace MalcevTailSection +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {n l : ℕ} +variable (c : RealCoordinates G n) (k : Fin n → ℤ) (r : Fin l → ℕ) (j : Fin l → ℕ) + + + +lemma binomial_parameters_bounds (A C : ℝ) (hC : 0 ≤ C) : + ∃ U > 0, ∀ L : ℝ, ∀ lam : Fin l → ℝ, 1 ≤ L → (∀ i, |L^(j i)*lam i| ≤ C) → + (∀ x : ℝ, |x| ≤ A*L → ‖fun i => lam i*Ring.choose x (j i)‖ ≤ U) ∧ + (∀ x y : ℝ, |x| ≤ A*L → |y| ≤ A*L → + ‖(fun i => lam i*Ring.choose x (j i))-(fun i => lam i*Ring.choose y (j i))‖ ≤ (U/L)*|x-y|) := by + classical + choose b hb hh using (fun i => SmoothBinomial.smooth_binomial_increment (j i) A C hC) + let U := (∑ i, b i)+1 + have hU : 0 < U := by + have he : 0 ≤ ∑ i, b i := Finset.sum_nonneg (fun i _ => (hb i).le) + dsimp [U] + linarith + have hbU (i : Fin l) : b i ≤ U := by + have he := Finset.single_le_sum (fun t (_ : t ∈ (Finset.univ : Finset (Fin l))) => (hb t).le) (Finset.mem_univ i) + dsimp [U] + linarith + refine ⟨U,hU,?_⟩ + intro L lam hL hlam + have hLp : 0 < L := lt_of_lt_of_le zero_lt_one hL + constructor + · intro x hx + apply (pi_norm_le_iff_of_nonneg hU.le).mpr + intro i + exact ((hh i L (lam i) hL (hlam i)).1 x hx).trans (hbU i) + · intro x y hx hy + apply (pi_norm_le_iff_of_nonneg (by positivity)).mpr + intro i + exact ((hh i L (lam i) hL (hlam i)).2 x y hx hy).trans + (mul_le_mul_of_nonneg_right (div_le_div_of_nonneg_right (hbU i) hLp.le) (abs_nonneg _)) + + + +omit [IsTopologicalGroup G] in +theorem smooth_word_bounds (A C : ℝ) (hC : 0 ≤ C) : + ∃ B > 0, ∀ L : ℝ, ∀ lam : Fin l → ℝ, 1 ≤ L → (∀ i, |L^(j i)*lam i| ≤ C) → + (∀ x : ℝ, |x| ≤ A*L → + ‖c.coord (flowWord c k r (fun i => lam i*Ring.choose x (j i)))‖ ≤ B) ∧ + (∀ x y : ℝ, |x| ≤ A*L → |y| ≤ A*L → + ‖c.coord (flowWord c k r (fun i => lam i*Ring.choose x (j i))) - + c.coord (flowWord c k r (fun i => lam i*Ring.choose y (j i)))‖ ≤ (B/L)*|x-y|) := by + obtain ⟨U,hU,hu⟩ := binomial_parameters_bounds j A C hC + obtain ⟨M,hM,hm,hd⟩ := flowWord_bounds c k r U + refine ⟨M*(U+1),by positivity,?_⟩ + intro L lam hL hlam + obtain ⟨hv,he⟩ := hu L lam hL hlam + have hLp : 0 < L := lt_of_lt_of_le zero_lt_one hL + constructor + · intro x hx + exact (hm _ (hv x hx)).trans (by nlinarith) + · intro x y hx hy + have h1 := hd _ _ (hv x hx) (hv y hy) + have h2 := mul_le_mul_of_nonneg_left (he x y hx hy) hM.le + apply h1.trans (h2.trans _) + have h3 : M*U ≤ M*(U+1) := by nlinarith + have h4 := mul_le_mul_of_nonneg_right (div_le_div_of_nonneg_right h3 hLp.le) (abs_nonneg (x-y)) + convert h4 using 1; ring + +end MalcevTailSection +end +end + + + +section +noncomputable section +namespace MalcevTailSection +open RationalLattice RationalPolynomialMap +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {n l : ℕ} +variable (c : RealCoordinates G n) (k : Fin n → ℤ) (r : Fin l → ℕ) + +def flowDifference (t : (Fin l ⊕ Fin l) → ℝ) : G := + flowWord c k r (fun i => t (Sum.inl i)) * (flowWord c k r (fun i => t (Sum.inr i)))⁻¹ + +omit [IsTopologicalGroup G] in +lemma polynomialMap_flowDifference : IsPolynomialMap c (flowDifference c k r) := by + apply polynomialMap_mul + · exact polynomialMap_comp c (polynomialMap_flowWord c k r) (fun i => RationalPolynomialMap.coordinate (Sum.inl i)) + · apply polynomialMap_inv + exact polynomialMap_comp c (polynomialMap_flowWord c k r) (fun i => RationalPolynomialMap.coordinate (Sum.inr i)) + +omit [IsTopologicalGroup G] in +lemma flowDifference_contDiff : ContDiff ℝ (⊤ : ℕ∞) (fun x => c.coord (flowDifference c k r x)) := by + apply contDiff_pi.mpr + intro i + exact RationalPolynomialMap.contDiff (polynomialMap_flowDifference c k r i) + + + +omit [IsTopologicalGroup G] in +theorem flow_displacement_bounds (R : ℝ) : + ∃ M > 0, ∀ x y : Fin l → ℝ, ‖x‖ ≤ R → ‖y‖ ≤ R → + ‖c.coord (flowWord c k r x * (flowWord c k r y)⁻¹)‖ ≤ M*‖x-y‖ := by + have hd := flowDifference_contDiff c k r + obtain ⟨D,hD⟩ := (isCompact_closedBall (0 : (Fin l ⊕ Fin l) → ℝ) R).exists_bound_of_continuousOn + (hd.continuous_fderiv (by simp)).continuousOn + refine ⟨max D 0+1,by positivity,?_⟩ + intro x y hx hy + have hR : 0 ≤ R := (norm_nonneg x).trans hx + have hb (u v : Fin l → ℝ) (hu : ‖u‖ ≤ R) (hv : ‖v‖ ≤ R) : ‖Sum.elim u v‖ ≤ R := by + apply (pi_norm_le_iff_of_nonneg hR).mpr + intro i + cases i with + | inl i => exact (norm_le_pi_norm u i).trans hu + | inr i => exact (norm_le_pi_norm v i).trans hv + have hdiff : ‖Sum.elim x y - Sum.elim y y‖ ≤ ‖x-y‖ := by + apply (pi_norm_le_iff_of_nonneg (norm_nonneg _)).mpr + intro i + cases i with + | inl i => exact norm_le_pi_norm (x-y) i + | inr i => simp + have hid : c.coord (flowDifference c k r (Sum.elim y y)) = 0 := by + funext i + simp only [flowDifference,Sum.elim_inl,Sum.elim_inr,mul_inv_cancel,c.one_coord,Pi.zero_apply] + have he := Convex.norm_image_sub_le_of_norm_fderiv_le + (fun x (_ : x ∈ Metric.closedBall (0 : (Fin l ⊕ Fin l) → ℝ) R) => hd.differentiable (by simp) x) + (fun x hx => (hD x hx).trans (show D ≤ max D 0+1 by grind)) + (convex_closedBall (0 : (Fin l ⊕ Fin l) → ℝ) R) + (by simpa using hb y y hy hy) (by simpa using hb x y hx hy) + rw [hid,sub_zero] at he + exact he.trans (mul_le_mul_of_nonneg_left hdiff (by positivity)) + +end MalcevTailSection +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace MalcevTailSection +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {n l : ℕ} +variable (c : RealCoordinates G n) (k : Fin n → ℤ) (r : Fin l → ℕ) (j : Fin l → ℕ) + + + +omit [IsTopologicalGroup G] in +theorem smooth_word_displacement (A C : ℝ) (hC : 0 ≤ C) : + ∃ B > 0, ∀ L : ℝ, ∀ lam : Fin l → ℝ, 1 ≤ L → (∀ i, |L^(j i)*lam i| ≤ C) → + ∀ x y : ℝ, |x| ≤ A*L → |y| ≤ A*L → + ‖c.coord (flowWord c k r (fun i => lam i*Ring.choose x (j i)) * + (flowWord c k r (fun i => lam i*Ring.choose y (j i)))⁻¹)‖ ≤ (B/L)*|x-y| := by + obtain ⟨U,hU,hu⟩ := binomial_parameters_bounds j A C hC + obtain ⟨M,hM,hm⟩ := flow_displacement_bounds c k r U + refine ⟨M*U,by positivity,?_⟩ + intro L lam hL hlam x y hx hy + obtain ⟨hv,he⟩ := hu L lam hL hlam + have h1 := hm _ _ (hv x hx) (hv y hy) + have h2 := mul_le_mul_of_nonneg_left (he x y hx hy) hM.le + apply h1.trans + convert h2 using 1; ring + +end MalcevTailSection + +namespace MalcevTailFactor +open RationalLattice RationalFactorPeriods MalcevCharacters MalcevTailSection +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {n l : ℕ} +variable (c : RealCoordinates G n) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (k : Fin n → ℤ) (r : Fin l → ℕ) (j : Fin l → ℕ) + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma error_abs (a : Fin l → G) (i : Fin l) : + |error χ a i| = ‖(beta χ a i : UnitAddCircle)‖ := by + rw [UnitAddCircle.norm_eq] + rfl + +include hsk in + + +omit [IsTopologicalGroup G] in +theorem small_word_smooth (A C : ℝ) (hC : 0 ≤ C) : + ∃ B > 0, ∀ L : ℝ, ∀ a : Fin l → G, 1 ≤ L → + (∀ i, L^(j i)*‖(beta χ a i : UnitAddCircle)‖ ≤ C) → + (∀ z : ℤ, |(z:ℝ)| ≤ A*L → + ‖c.coord (orderedWord (smallCoeff c χ k r a) j z)‖ ≤ B) ∧ + (∀ z w : ℤ, |(z:ℝ)| ≤ A*L → |(w:ℝ)| ≤ A*L → + ‖c.coord (orderedWord (smallCoeff c χ k r a) j z * + (orderedWord (smallCoeff c χ k r a) j w)⁻¹)‖ ≤ (B/L)*|(z:ℝ)-(w:ℝ)|) := by + obtain ⟨B,hB,hb⟩ := smooth_word_bounds c k r j A C hC + obtain ⟨D,hD,hd⟩ := smooth_word_displacement c k r j A C hC + refine ⟨B+D,by positivity,?_⟩ + intro L a hL ha + have hLp : 0 < L := lt_of_lt_of_le zero_lt_one hL + have he : ∀ i, |L^(j i)*error χ a i| ≤ C := by + intro i + rw [abs_mul,abs_of_nonneg (pow_nonneg hLp.le _),error_abs] + exact ha i + have hv (z : ℤ) : flowWord c k r (fun i => error χ a i*Ring.choose (z:ℝ) (j i)) = + orderedWord (smallCoeff c χ k r a) j z := flowWord_integer c k r hsk _ j z + constructor + · intro z hz + rw [← hv z] + exact ((hb L _ hL he).1 z hz).trans (by linarith) + · intro z w hz hw + rw [← hv z,← hv w] + exact (hd L _ hL he z w hz hw).trans + (mul_le_mul_of_nonneg_right (div_le_div_of_nonneg_right (by linarith) hLp.le) (abs_nonneg _)) + +end MalcevTailFactor + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevWeighted01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevWeighted01.lean new file mode 100644 index 0000000000000000000000000000000000000000..56082903141fcd1249f88d6bb259ae5c612a0e36 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevWeighted01.lean @@ -0,0 +1,290 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.LeibmanSquare02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +end +end + + + +section +noncomputable section +namespace MalcevSubspaceQuotient +open RationalLattice MalcevCharacters + +lemma prod_map_mul_of_central {A M : Type*} [Monoid M] (f g : A → M) + (hg : ∀ a, g a ∈ Submonoid.center M) (l : List A) : + (l.map (fun a => f a*g a)).prod=(l.map f).prod*(l.map g).prod := by + induction l with + | nil => simp + | cons a l ih => + simp only [List.map_cons,List.prod_cons,ih] + have hc : g a * (l.map f).prod=(l.map f).prod*g a := + (Submonoid.mem_center_iff.mp (hg a) _).symm + calc + _ = f a*(g a*(l.map f).prod)*(l.map g).prod := by simp [mul_assoc] + _ = _ := by rw [hc]; simp [mul_assoc] + +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (N : Subgroup G) [N.Normal] + +include hsk in +omit [IsTopologicalGroup G] in +lemma mk_coordinates_add_central (x y : Fin n → ℝ) + (hy : ∀ i, (QuotientGroup.mk (axis c i (y i)) : G ⧸ N) ∈ Subgroup.center (G ⧸ N)) : + (QuotientGroup.mk (c.coord.symm (x+y)) : G ⧸ N) = + QuotientGroup.mk (c.coord.symm x)*QuotientGroup.mk (c.coord.symm y) := by + rw [mk_coordinates c hsk N,mk_coordinates c hsk N,mk_coordinates c hsk N] + simp only [Pi.add_apply,hsk.axis_add,QuotientGroup.mk_mul,List.ofFn_eq_map] + apply prod_map_mul_of_central + exact hy + +include hsk in +omit [IsTopologicalGroup G] in +lemma mk_coordinates_central (y : Fin n → ℝ) + (hy : ∀ i, (QuotientGroup.mk (axis c i (y i)) : G ⧸ N) ∈ Subgroup.center (G ⧸ N)) : + (QuotientGroup.mk (c.coord.symm y) : G ⧸ N) ∈ Subgroup.center (G ⧸ N) := by + rw [mk_coordinates c hsk N] + apply Subgroup.list_prod_mem + intro a ha + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp ha + exact hy i + +variable (J : Set (Fin n)) +variable (hJ : ∀ j∈J, ∀ t : ℝ, + (QuotientGroup.mk (axis c j t) : G ⧸ N) ∈ Subgroup.center (G ⧸ N)) + +include hJ in +omit [IsTopologicalGroup G] in +lemma mask_central (x : Fin n → ℝ) (i : Fin n) : + (QuotientGroup.mk (axis c i (mask J x i)) : G ⧸ N) ∈ Subgroup.center (G ⧸ N) := by + classical + by_cases hi : i∈J + · simpa only [mask,ite_eq_left hi] using hJ i hi (x i) + · simp [mask,hi] + +lemma mask_compl_add_mask (x : Fin n → ℝ) : mask Jᶜ x+mask J x=x := by + classical + funext i + by_cases hi : i∈J <;> simp [mask,hi] + +variable (I : Set (Fin n)) +variable (hN : ∀ g : G, g ∈ N ↔ ∀ i∈I, c.coord g i=0) + +include hsk hN hJ in + + +omit [IsTopologicalGroup G] in +theorem coord_mul_cut (g h : G) (i : Fin n) (hi : i∈I) (hij : i∈J) : + c.coord (g*h) i=c.coord g i+c.coord h i+ + c.coord (strip c Jᶜ g*strip c Jᶜ h) i := by + classical + let x:=c.coord g + let y:=c.coord h + let a:=strip c Jᶜ g + let b:=strip c Jᶜ h + let u:=c.coord.symm (mask J x) + let v:=c.coord.symm (mask J y) + let q:=QuotientGroup.mk' N + have hx : q g=q a*q u := by + have he := mk_coordinates_add_central c hsk N (mask Jᶜ x) (mask J x) (mask_central c N J hJ x) + rw [mask_compl_add_mask] at he + simpa only [x,a,u,q,strip,QuotientGroup.mk'_apply,Homeomorph.symm_apply_apply] using he + have hy : q h=q b*q v := by + have he := mk_coordinates_add_central c hsk N (mask Jᶜ y) (mask J y) (mask_central c N J hJ y) + rw [mask_compl_add_mask] at he + simpa only [y,b,v,q,strip,QuotientGroup.mk'_apply,Homeomorph.symm_apply_apply] using he + have hu : q u ∈ Subgroup.center (G ⧸ N) := + mk_coordinates_central c hsk N (mask J x) (mask_central c N J hJ x) + have hcenter (j : Fin n) : + (QuotientGroup.mk (axis c j ((mask J x+mask J y) j)) : G ⧸ N) ∈ Subgroup.center (G ⧸ N) := by + by_cases hj : j∈J + · exact hJ j hj _ + · simp [mask,hj] + have he₁ := mk_coordinates_add_central c hsk N (c.coord (a*b)) (mask J x+mask J y) hcenter + have he₂ := mk_coordinates_add_central c hsk N (mask J x) (mask J y) (mask_central c N J hJ y) + have he : (QuotientGroup.mk (g*h) : G ⧸ N) = + QuotientGroup.mk (c.coord.symm (c.coord (a*b)+(mask J x+mask J y))) := by + rw [he₁,he₂,Homeomorph.symm_apply_apply] + change q (g*h)=q (a*b)*(q u*q v) + rw [map_mul,hx,hy,map_mul] + have hc := Subgroup.mem_center_iff.mp hu (q b) + calc + _ = q a*(q u*q b)*q v := by simp [mul_assoc] + _ = _ := by rw [← hc]; simp [mul_assoc] + have he' := (eq_coset_iff c hsk N I hN _ _).mp he i hi + simp only [Homeomorph.apply_symm_apply,Pi.add_apply,mask,ite_eq_left hij] at he' + change c.coord (g*h) i=c.coord g i+c.coord h i+c.coord (a*b) i + dsimp [x,y] at he' + linarith only [he'] + +end MalcevSubspaceQuotient +end +end + + + +section +noncomputable section +open scoped commutatorElement +namespace MalcevWeightedCoordinates +open RationalLattice MalcevCharacters CubeFaces MalcevSubspaceQuotient +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable (w : Fin n → ℕ) +variable (hH : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin n, w i + apply commutatorElement_eq_one_iff_mul_comm.mp + change ⁅(QuotientGroup.mk' (H.level (k+1))) a, + (QuotientGroup.mk' (H.level (k+1))) (axis c j t)⁆ = 1 + rw [← map_commutatorElement (QuotientGroup.mk' (H.level (k+1)))] + apply (QuotientGroup.eq_one_iff _).mpr + have ha : a∈H.level 1 := by rw [h1]; trivial + have hb : axis c j t∈H.level k := H.antitone hj (axis_mem_level c H w hH j t) + have hc := H.commutator_le 1 k (Subgroup.commutator_mem_commutator ha hb) + simpa only [Nat.add_comm] using hc + +include hsk h0 h1 hH in + + +omit [IsTopologicalGroup G] in +theorem weighted_mul (g h : G) (i : Fin n) : + c.coord (g*h) i=c.coord g i+c.coord h i+ + c.coord (strip c {j | w i≤w j}ᶜ g*strip c {j | w i≤w j}ᶜ h) i := by + let := LeibmanSquare.level_normal H h0 (w i+1) + apply coord_mul_cut c hsk (H.level (w i+1)) {j | w i≤w j} + (fun j hj t => axis_central_mod_next c H h1 w hH (w i) j hj t) + {j | w j x (p.symm j)) + left_inv g := by + change c.coord.symm (fun j => c.coord g (p (p.symm j)))=g + simp + right_inv x := by + funext i + change c.coord (c.coord.symm (fun j => x (p.symm j))) (p i)=x i + simp + continuous_toFun := continuous_pi (fun i => (continuous_apply (p i)).comp c.coord.continuous) + continuous_invFun := c.coord.symm.continuous.comp (continuous_pi (fun j => continuous_apply (p.symm j))) + +include hp in +lemma lower_index {a i : Fin n} (ha : w a < w (p i)) : (p.symm a).val < i.val := by + by_contra hn + have he : i ≤ p.symm a := Nat.le_of_not_gt hn + have hw := hp he + have hw' : w (p i) ≤ w a := by simpa only [Function.comp_apply,Equiv.apply_symm_apply] using hw + exact (not_lt_of_ge hw') ha + + + +def lowerVector (i : Fin n) (x : Fin i.val → ℝ) (a : Fin n) : ℝ := + if ha : w a < w (p i) then x ⟨(p.symm a).val,lower_index w p hp ha⟩ else 0 + +omit [IsTopologicalGroup G] in +lemma lowerVector_coordinates (i : Fin n) (g : G) : + lowerVector w p hp i (fun j => c.coord g (p ⟨j.val,lt_trans j.isLt i.isLt⟩)) = + mask {j | w (p i) ≤ w j}ᶜ (c.coord g) := by + funext a + unfold lowerVector mask + by_cases ha : w a < w (p i) + · have hn : ¬ w (p i) ≤ w a := not_le_of_gt ha + simp only [dite_eq_left ha,Set.mem_compl_iff,Set.mem_ofPred_eq,ite_eq_left hn] + exact congrArg (c.coord g) (p.apply_symm_apply a) + · have hn : w (p i) ≤ w a := le_of_not_gt ha + simp [ha,hn] + +omit [IsTopologicalGroup G] in +lemma lower_correction_exists (i : Fin n) : + ∃ P : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ, + ∀ v : (Fin i.val ⊕ Fin i.val) → ℝ, + c.coord (c.coord.symm (lowerVector w p hp i (fun j => v (Sum.inl j))) * + c.coord.symm (lowerVector w p hp i (fun j => v (Sum.inr j)))) (p i) = + MvPolynomial.eval₂ (algebraMap ℚ ℝ) v P := by + apply polynomialMap_mul c + all_goals + intro a + simp only [Homeomorph.apply_symm_apply] + unfold lowerVector + split_ifs with ha + · exact RationalPolynomialMap.coordinate _ + · exact RationalPolynomialMap.zero + +def sortedCorrection (i : Fin n) : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ := + (lower_correction_exists c w p hp i).choose + +variable (hsk : SecondKind c) (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable (hH : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin n, w i < k → c.coord g i=0) + +include hsk h0 h1 hH in +omit [IsTopologicalGroup G] in +lemma sorted_mul (g h : G) (i : Fin n) : + c.coord (g*h) (p i)=c.coord g (p i)+c.coord h (p i)+ + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => c.coord g (p ⟨j.val,lt_trans j.isLt i.isLt⟩)) + (fun j => c.coord h (p ⟨j.val,lt_trans j.isLt i.isLt⟩))) + (sortedCorrection c w p hp i) := by + rw [weighted_mul c hsk H h0 h1 w hH g h (p i)] + congr 1 + have he := (lower_correction_exists c w p hp i).choose_spec + (Sum.elim (fun j => c.coord g (p ⟨j.val,lt_trans j.isLt i.isLt⟩)) + (fun j => c.coord h (p ⟨j.val,lt_trans j.isLt i.isLt⟩))) + simpa only [Sum.elim_inl,Sum.elim_inr,lowerVector_coordinates,strip,sortedCorrection] using he + + + +def sortedCoordinates : RealCoordinates G n where + coord := reorderHomeomorph c p + one_coord i := c.one_coord (p i) + correction := sortedCorrection c w p hp + mul_coord := sorted_mul c w p hp hsk H h0 h1 hH + +end MalcevWeightedCoordinates + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevWeighted02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevWeighted02.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1282aa284b44c64673f72d8150012b79d83b9d1 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MalcevWeighted02.lean @@ -0,0 +1,273 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevWeighted01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +end +end + + + +section +noncomputable section +namespace MalcevWeightedCoordinates + +lemma exists_sorting_permutation {n : ℕ} (w : Fin n → ℕ) : + ∃ p : Equiv.Perm (Fin n), Monotone (w ∘ p) := by + classical + let l := (List.finRange n).mergeSort (fun i j => decide (w i ≤ w j)) + have hl : l.Perm (List.finRange n) := List.mergeSort_perm _ _ + have hlen : l.length=n := by simpa using hl.length_eq + have hnd : l.Nodup := hl.nodup_iff.mpr (List.nodup_finRange n) + have hall : ∀ i : Fin n, i∈l := fun i => hl.mem_iff.mpr (List.mem_finRange i) + let e := List.Nodup.getEquivOfForallMemList l hnd hall + let p := (Fin.castOrderIso hlen.symm).toEquiv.trans e + refine ⟨p,?_⟩ + have hs : l.Pairwise (fun i j => w i ≤ w j) := by + have hh := List.pairwise_mergeSort (le := fun i j : Fin n => decide (w i ≤ w j)) + (fun a b c hab hbc => by simpa using le_trans (of_decide_eq_true hab) (of_decide_eq_true hbc)) + (fun a b => by simpa using le_total (w a) (w b)) (List.finRange n) + simpa only [decide_eq_true_eq] using hh + intro i j hij + change w (l.get (Fin.cast hlen.symm i)) ≤ w (l.get (Fin.cast hlen.symm j)) + rcases eq_or_lt_of_le hij with he|he + · simp [he] + · exact hs.rel_get_of_lt he + +lemma exists_weight_cutoff {n : ℕ} (w : Fin n → ℕ) (hw : Monotone w) (k : ℕ) : + ∃ r : ℕ, r ≤ n ∧ ∀ i : Fin n, w i < k ↔ i.val < r := by + classical + let P : ℕ → Prop := fun r => ∀ i : Fin n, r ≤ i.val → k ≤ w i + have hex : ∃ r, P r := ⟨n,by intro i hi; omega⟩ + refine ⟨Nat.find hex,Nat.find_min' hex (show P n from by intro i hi; omega),?_⟩ + intro i + constructor + · intro hi + by_contra hn + exact (not_le_of_gt hi) (Nat.find_spec hex i (Nat.le_of_not_gt hn)) + · intro hi + by_contra hn + have hki : k ≤ w i := Nat.le_of_not_gt hn + have hp : P i.val := by + intro j hj + exact hki.trans (hw hj) + have hh := Nat.find_min' hex hp + omega + +end MalcevWeightedCoordinates +end +end + + + +section +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) +variable (H : Subgroup G) (I : Set (Fin n)) +variable (hH : ∀ g : G, g ∈ H ↔ ∀ i ∈ I, c.coord g i = 0) + +include hH in +lemma basisFlow_mem_subspace {i : Fin n} (hi : i ∉ I) (t : ℝ) : basisFlow c i t ∈ H := by + apply realPower_mem_of_coordinates c H I hH + apply (hH _).mpr + intro j hj + have hji : j ≠ i := by intro he; exact hi (he ▸ hj) + simp [basisElement,hji] + +include hH in +lemma peel_mem_subspace {g : G} (hg : g ∈ H) (k : ℕ) : peel c g k ∈ H := by + classical + induction k with + | zero => exact hg + | succ k ih => + unfold peel + split_ifs with hk + · apply H.mul_mem _ ih + by_cases hi : (⟨k,hk⟩ : Fin n) ∈ I + · rw [(hH _).mp ih _ hi,neg_zero,basisFlow_zero] + exact H.one_mem + · exact basisFlow_mem_subspace c H I hH hi _ + · exact ih + +include hH in +lemma expCoordinates_subspace (g : G) : + g ∈ H ↔ ∀ i ∈ I, expCoordinates c g i = 0 := by + classical + constructor + · intro hg i hi + exact (hH _).mp (peel_mem_subspace c H I hH hg i.val) i hi + · intro hg + rw [← expProduct_expCoordinates c g] + apply H.list_prod_mem + intro x hx + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hx + by_cases hi : i ∈ I + · rw [hg i hi,basisFlow_zero] + exact H.one_mem + · exact basisFlow_mem_subspace c H I hH hi _ + +include hH in + + +theorem secondCoordinates_subspace [IsTopologicalGroup G] (g : G) : + g ∈ H ↔ ∀ i ∈ I, (secondCoordinates c).coord g i = 0 := + expCoordinates_subspace c H I hH g + +end RationalLattice +end +end + + + +section +noncomputable section +namespace MalcevWeightedCoordinates +open RationalLattice MalcevCharacters CubeFaces +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) (H : Filtration G) +variable (s : ℕ) (hs : H.level (s+1)=⊥) + +include hs in +lemma exists_axis_out (i : Fin n) : ∃ k, axis c i 1∉H.level k := by + refine ⟨s+1,?_⟩ + rw [hs,Subgroup.mem_bot] + intro he + have hf := congrArg (fun g => c.coord g i) he + simp [axis,c.one_coord] at hf + +def subspaceWeight (i : Fin n) : ℕ := by + classical + exact Nat.find (exists_axis_out c H s hs i)-1 + +variable (h0 : H.level 0=⊤) +include h0 hs in +lemma weight_lt_iff_out (i : Fin n) (k : ℕ) : + subspaceWeight c H s hs i < k ↔ axis c i 1∉H.level k := by + classical + have hz : 0 < Nat.find (exists_axis_out c H s hs i) := by + by_contra hn + have he : Nat.find (exists_axis_out c H s hs i)=0 := by omega + have hnot := Nat.find_spec (exists_axis_out c H s hs i) + rw [he,h0] at hnot + exact hnot (Subgroup.mem_top _) + constructor + · intro hk hm + have hle : Nat.find (exists_axis_out c H s hs i) ≤ k := by + change Nat.find (exists_axis_out c H s hs i)-1 < k at hk + omega + exact Nat.find_spec (exists_axis_out c H s hs i) (H.antitone hle hm) + · intro hm + have hle := Nat.find_min' (exists_axis_out c H s hs i) hm + unfold subspaceWeight + omega + +lemma axis_mem_subspace_iff (A : Subgroup G) (I : Set (Fin n)) + (hA : ∀ g : G, g∈A ↔ ∀ i∈I, c.coord g i=0) (i : Fin n) : + axis c i 1∈A ↔ i∉I := by + classical + constructor + · intro hm hi + have hz := (hA _).mp hm i hi + simp [axis] at hz + · intro hi + apply (hA _).mpr + intro j hj + have hji : j≠i := by intro he; subst j; exact hi hj + simp [axis,hji] + +variable (hH : ∀ k : ℕ, ∃ I : Set (Fin n), ∀ g : G, + g∈H.level k ↔ ∀ i∈I, c.coord g i=0) +include h0 hH hs in + + +theorem subspaceWeight_level (k : ℕ) (g : G) : + g∈H.level k ↔ ∀ i : Fin n, subspaceWeight c H s hs i < k → c.coord g i=0 := by + classical + obtain ⟨I,hI⟩ := hH k + have hi (i : Fin n) : subspaceWeight c H s hs i < k ↔ i∈I := by + rw [weight_lt_iff_out c H s hs h0,axis_mem_subspace_iff c (H.level k) I hI] + simp + rw [hI] + simp only [hi] + +end MalcevWeightedCoordinates +end +end + + + +section +noncomputable section +namespace MalcevWeightedCoordinates +open RationalLattice MalcevCharacters CubeFaces +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable (s : ℕ) (hs : H.level (s+1)=⊥) +variable (hH : ∀ k : ℕ, ∃ I : Set (Fin n), ∀ g : G, + g∈H.level k ↔ ∀ i∈I, c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +include h0 h1 hs hH hΓ in + + +theorem exists_adapted_secondKind_coordinates : + ∃ c' : RealCoordinates G n, SecondKind c' ∧ + (∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c'.coord g i=z) ∧ + ∀ k : ℕ, ∃ r : ℕ, r ≤ n ∧ ∀ g : G, + g∈H.level k ↔ ∀ i : Fin n, i.val < r → c'.coord g i=0 := by + classical + let c₁ := secondCoordinates c + have hk₁ : SecondKind c₁ := secondCoordinates_secondKind c + have hH₁ : ∀ k : ℕ, ∃ I : Set (Fin n), ∀ g : G, + g∈H.level k ↔ ∀ i∈I, c₁.coord g i=0 := by + intro k + obtain ⟨I,hI⟩ := hH k + exact ⟨I,secondCoordinates_subspace c (H.level k) I hI⟩ + have hΓ₁ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c₁.coord g i=z := + expCoordinates_lattice c Γ hΓ + let w:=subspaceWeight c₁ H s hs + have hw : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin n, w i < k → c₁.coord g i=0 := + subspaceWeight_level c₁ H s hs h0 hH₁ + obtain ⟨p,hp⟩ := exists_sorting_permutation w + let c₂ := sortedCoordinates c₁ w p hp hk₁ H h0 h1 hw + have hcoord (g : G) (i : Fin n) : c₂.coord g i=c₁.coord g (p i) := rfl + have hΓ₂ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c₂.coord g i=z := by + intro g + rw [hΓ₁] + constructor + · intro hg i + exact hg (p i) + · intro hg i + simpa only [hcoord,Equiv.apply_symm_apply] using hg (p.symm i) + refine ⟨secondCoordinates c₂,secondCoordinates_secondKind c₂, + expCoordinates_lattice c₂ Γ hΓ₂,?_⟩ + intro k + obtain ⟨r,hr,hrk⟩ := exists_weight_cutoff (w ∘ p) hp k + refine ⟨r,hr,?_⟩ + apply secondCoordinates_adapted c₂ (H.level k) r + intro g + rw [hw] + constructor + · intro hg i hi + exact hg (p i) ((hrk i).mpr hi) + · intro hg i hi + have hpi : (w ∘ p) (p.symm i) < k := by simpa using hi + simpa only [hcoord,Equiv.apply_symm_apply] using hg (p.symm i) ((hrk _).mp hpi) + +end MalcevWeightedCoordinates + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MenuLiteral01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MenuLiteral01.lean new file mode 100644 index 0000000000000000000000000000000000000000..5cac6a393fd206093780f4d01110a407992520ea --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MenuLiteral01.lean @@ -0,0 +1,172 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.Blocks02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +noncomputable section +open Filter MeasureTheory +open scoped BigOperators ENNReal Topology +noncomputable section +open scoped BigOperators Topology BoundedContinuousFunction +noncomputable section +open scoped BigOperators +open MeasureTheory Filter Function +noncomputable section +open scoped BigOperators +noncomputable section +open Filter MeasureTheory +open scoped Topology BoundedContinuousFunction NNReal +noncomputable section +open scoped Topology BigOperators +noncomputable section +open scoped Topology BigOperators commutatorElement +noncomputable section +open scoped Topology BoundedContinuousFunction NNReal +noncomputable section +open scoped BigOperators +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal +noncomputable section +open scoped Topology BigOperators +noncomputable section +open scoped Topology BoundedContinuousFunction NNReal BigOperators +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal +namespace SourceMenuLiteral +open SourceProductChart SourceChartedMenu SourceFiniteMenuModels +open SourceAdmissible SourceBlocks SourceMenuAlignment SourcePivotPaths +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales +variable {a s r s' : ℕ} + + +structure CosetPiece (F : Menu s) (K : ℝ≥0) where + index : Fin F.size + g : F.G index + x : F.G index ⧸ F.Γ index + obs : (F.G index ⧸ F.Γ index) →ᵇ ℝ + lip : letI : MetricSpace (F.G index ⧸ F.Γ index) := + (F.metric index).replaceTopology (F.compatible index) + LipschitzWith K obs + range : ∀ z, obs z ∈ Set.Icc (0:ℝ) 1 + +variable {F : Menu s} {K : ℝ≥0} +def CosetPiece.eval (P : CosetPiece F K) (k : ℤ) : ℝ := P.obs (P.g^k • P.x) + +def CosetPiece.lift (P : CosetPiece F K) : Piece F K where + index := P.index + g := P.g + x := P.x.out + obs := P.obs + lip := P.lip + range := P.range + +lemma CosetPiece.lift_eval (P : CosetPiece F K) (k : ℤ) : P.lift.eval k = P.eval k := by + change P.obs (P.g^k • (QuotientGroup.mk P.x.out : F.G P.index ⧸ F.Γ P.index)) = _ + rw [show (QuotientGroup.mk P.x.out : F.G P.index ⧸ F.Γ P.index)=P.x from Quotient.out_eq P.x] + rfl + + + +def raiseChart {G : Type} [Group G] [TopologicalSpace G] {Γ : Subgroup G} + (C : Chart s G Γ) (h : s ≤ s') : Chart s' G Γ := + { C with + step := by + refine le_antisymm ?_ bot_le + calc C.filtration.level (s'+1) ≤ C.filtration.level (s+1) := + C.filtration.antitone (Nat.add_le_add_right h 1) + _ = ⊥ := C.step } + +def raiseMenu (F : Menu s) (h : s ≤ s') : Menu s' := + { F with chart := fun i => raiseChart (F.chart i) h } + +def CosetPiece.raise (P : CosetPiece F K) (h : s ≤ s') : CosetPiece (raiseMenu F h) K := + { P with } + + + +structure ModelsSystem (A : Parameters a) (vs : Finset ℚ) (r : ℕ) (F : Menu s) where + model : ℕ → Models a r + K : ℝ≥0 + piece : ℕ → Block a → ∀ (v : ℚ), v ∈ vs → + Fin r → ℤ → ℤ → CosetPiece F K + represents : ∀ N B v hv c k, + model N B v c k = + (piece N B v hv c (k/(A.H N B.1 : ℤ)) (k%(A.M N : ℤ))).eval + ((k-k%(A.M N : ℤ))/(A.M N : ℤ)) + +variable {A : Parameters a} {vs : Finset ℚ} (S : ModelsSystem A vs r F) + +def ModelsSystem.lift : System A vs r F where + model := S.model + K := S.K + piece N B v hv c j l := (S.piece N B v hv c j l).lift + represents := by + intro N B v hv c k + rw [CosetPiece.lift_eval] + exact S.represents N B v hv c k + +def ModelsSystem.raise (h : s ≤ s') : ModelsSystem A vs r (raiseMenu F h) where + model := S.model + K := S.K + piece N B v hv c j l := (S.piece N B v hv c j l).raise h + represents := S.represents + + + +theorem charted_finite_menu_alignment (a r s : ℕ) : + ∃ (bs : Finset (Scale a)) (vs : Finset ℚ) (δ : ℝ), + 0 < δ ∧ + (∀ b ∈ bs, ∀ j, 0 < b j) ∧ (∀ v ∈ vs, 0 < v) ∧ + (∀ b ∈ bs, ∀ B : Block a, blockProduct b B.set ∈ vs) ∧ + ∀ (A : Parameters a) (F : Menu s) (S : ModelsSystem A vs r F) + (μ : ℕ → Measure (Fin a → ℕ)), + (∀ N (hX : ∀ i, 4*primorial (N+1) ≤ A.X N i), μ N = A.law N hX) → + ∀ τ : ℝ, 0 < τ → + δ ≤ Filter.liminf (fun N => (μ N).real (event bs (S.model N) (A.ht N) τ)) atTop := by + let t := max 1 s + have ht : 1 ≤ t := le_max_left _ _ + have hs : s ≤ t := le_max_right _ _ + refine ⟨tuples t r ht,values t r ht,delta t r ht (pivots a), + delta_pos t r ht _,tuples_pos t r ht,values_pos t r ht,closure t r ht,?_⟩ + intro A F S μ hμ τ hτ + exact menu_alignment_liminf t r ht A (raiseMenu F hs) (S.raise hs).lift μ hμ τ hτ + +end SourceMenuLiteral + + + + + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellFibers01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellFibers01.lean new file mode 100644 index 0000000000000000000000000000000000000000..c4d7b1360c78b2f964938d368464ce05892f20bc --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellFibers01.lean @@ -0,0 +1,263 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RawHarmonic01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section RawSuccessInlineScope11 +noncomputable section +open Filter Topology MeasureTheory +open scoped BigOperators +end +end RawSuccessInlineScope11 + + + + + +section RawSuccessInlineScope12 +noncomputable section +open MeasureTheory Filter Topology +open scoped BigOperators +namespace MicrocellConditional +open Finset RawHarmonicProbability +attribute [local instance] Classical.propDecidable + +def eventMass (C:Finset ℕ) (A:Set ℕ) : ℝ := ∑ p∈C,if p∈A then (p:ℝ)⁻¹ else 0 + +lemma law_apply_units (X W:ℕ) (hw:0 simp_all + +lemma subset_event_sum (X W:ℕ) (C:Finset ℕ) (hC:C⊆units X W) (A:Set ℕ) : + eventMass (units X W) (A∩(C:Set ℕ))=eventMass C A := by + unfold eventMass + symm + calc + _ = ∑ p∈C,if p∈A∩(C:Set ℕ) then (p:ℝ)⁻¹ else 0 := by + apply sum_congr rfl + intro p hp + simp [hp] + _ = ∑ p∈units X W,if p∈A∩(C:Set ℕ) then (p:ℝ)⁻¹ else 0 := + sum_subset hC (fun p hp hnot=>by simp [hnot]) + _ = _ := by + apply sum_congr rfl + intro p hp + split_ifs <;> rfl + + + +theorem conditional_ratio (X W:ℕ) (hw:0(p.1:ℝ)⁻¹) + (fun p=>inv_pos.mpr (by exact_mod_cast hpos p.1 p.2)) + Subtype.val : Measure ℕ).real A = + eventMass C A/(∑ p∈C,(p:ℝ)⁻¹) := by + classical + let : Nonempty C:=hC.coe_sort + rw [MicrocellProbability.weightedLaw_apply _ _ _ _ MeasurableSet.of_discrete] + simp only [MicrocellHarmonic.weight] + rw [sum_coe_sort C (fun p:ℕ=>(p:ℝ)⁻¹)] + rw [sum_coe_sort C (fun p:ℕ=>(p:ℝ)⁻¹/(∑ q∈C,(q:ℝ)⁻¹)*(if p∈A then 1 else 0))] + unfold eventMass + rw [sum_div] + apply sum_congr rfl + intro p hp + split_ifs <;> simp_all + + + +theorem conditional_event_error (X W:ℕ) (hw:0(p.1:ℝ)) x₀ R hx₀ hR + (fun p=>hwindow p.1 p.2) (Subtype.val:C→ℕ) A MeasurableSet.of_discrete + exact hh.trans (div_le_div_of_nonneg_left hR hxp hbase) + + + +theorem conditional_success (X W:ℕ) (hw:0p%M=r) + +def point (M k r b:ℕ) : ℕ := M*k+r+M*b + +lemma point_mem (M N k r:ℕ) (_:0⟨point M k r b,point_mem M N k r hM hr b⟩) (by + constructor + · intro a b hab + apply Fin.ext + exact point_injective M k r hM (congrArg Subtype.val hab) + · intro p + obtain ⟨b,hb⟩:=represent M N k r p hM p.2 + exact ⟨b,Subtype.ext hb⟩) + +lemma fiber_card (M N k r:ℕ) (hM:0point M k r b):Measure ℕ).real A := by + let : Nonempty (fiber M N k r):=(fiber_nonempty M N k r hM hN hr).coe_sort + let : Nonempty (Fin N):=Fin.pos_iff_nonempty.mp hN + rw [MicrocellProbability.uniformLaw_apply _ _ MeasurableSet.of_discrete, + MicrocellProbability.uniformLaw_apply _ _ MeasurableSet.of_discrete] + unfold MicrocellHarmonic.uniform + simp only [Fintype.card_coe,Fintype.card_fin,fiber_card M N k r hM hr] + exact (Equiv.sum_comp (parametrization M N k r hM hr) + (fun p:fiber M N k r=>(N:ℝ)⁻¹*(if p.1∈A then 1 else 0))).symm + + + +theorem raw_fiber_success (X W M N k r:ℕ) (hW:0point M k r b):Measure ℕ).real A) : + c/3<(law X W hW hX:Measure ℕ).real (A∩(fiber M N k r:Set ℕ)) / + (law X W hW hX:Measure ℕ).real (fiber M N k r:Set ℕ) := by + refine conditional_success X W hW hX (fiber M N k r) + (fiber_nonempty M N k r hM hN hr) (fiber_subset_units X W M N k r hWM hWR hlo hhi) + (M*k) (M*N) c (by exact_mod_cast hlo) (by positivity) ?_ A (by simpa only [Nat.cast_mul] using herr) ?_ + · intro p hp + obtain ⟨hp₀,hp₁⟩:=mem_Ico.mp (mem_filter.mp hp).1 + constructor + · exact_mod_cast hp₀ + · have hp':p≤M*k+M*N:=by nlinarith + exact_mod_cast hp' + · rw [uniform_fiber M N k r hM hN hr A] + exact hm + +end MicrocellFibers +end +end RawSuccessInlineScope13 + + + + + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellHarmonic01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellHarmonic01.lean new file mode 100644 index 0000000000000000000000000000000000000000..95b46fbe89438308e5acb5269cc9fb3bcff664c4 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellHarmonic01.lean @@ -0,0 +1,282 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.HarmonicExposure02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end +end + +section +noncomputable section +namespace RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + +theorem raw_conditional_face_uniform (hsk : SecondKind c) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0U n j) atTop atTop) + (hUV : ∀ n j,U n j≤V n j) + (hZ : ∀ a : ℝ,0Z0 n/(1+∑ j,V n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z0 n) atTop (𝓝 0)) + (hM : ∀ n,0U n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) → + ∀ X W : ℕ,(W:ℤ)∣(M n:ℤ) → b.a.natAbs.Coprime W → + (∀ t∈productTimes b.S b.r (L n),(X:ℝ)≤b.Q/(∏ j,(t j:ℝ))) → + (∀ t∈productTimes b.S b.r (L n),(b.Q+b.Δ)/(∏ j,(t j:ℝ))≤(X:ℝ)^2) → + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),LipschitzWith K σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + HarmonicExposure.rawFiberMass + (exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n)) + X W b.Q b.Δ b.a (M n) / + HarmonicExposure.rawFiberMass (productTimes b.S b.r (L n)) + X W b.Q b.Δ b.a (M n)<ε + := by + classical + intro ε hε + have hu := conditional_face_uniform (Γ:=Γ) (c:=c) hsk hΓ htop m v D d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M U V Z0 H L hw hU hUV hZ hH hHZ + hM hMs hL hsm hWL hUL ε hε + have hup : ∀ᶠ n in atTop,∀ j,0(hU j).eventually (eventually_gt_atTop 0)) + filter_upwards [hu,hup] with n hn hUn + intro b hb X W hWM ha hlo hhi A P hP σ hσ h hh hid + have hτ : ∀ t∈productTimes b.S b.r (L n),0<∏ j,(t j:ℝ) := by + intro t ht + apply Finset.prod_pos + intro j hj + have htj := Fintype.mem_piFinset.mp ht j + have htpos := (mem_times (b.S j) (b.r j) (L n) (t j) (hL n)).mp htj + exact (hUn j).trans_le (((hb.1 j).1).trans htpos.1) + have he (T : Finset (Fin m→ℤ)) (hT : T⊆productTimes b.S b.r (L n)) := + HarmonicExposure.rawFiberMass_eq_exposed T X W b.Q b.Δ b.a (M n) + (by exact_mod_cast hM n) hWM ha + (fun t ht=>hτ t (hT ht)) (fun t ht=>hlo t (hT ht)) (fun t ht=>hhi t (hT ht)) + have hsub : exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n) ⊆ + productTimes b.S b.r (L n) := Finset.filter_subset _ _ + rw [he _ hsub,he _ (Finset.Subset.refl _)] + exact hn b hb A P hP σ hσ h hh hid + +end RoughFaceShift +end +end + +section +noncomputable section +namespace HarmonicExposure +open RoughSamplingWeights RoughSourceExceptional RoughProductRemoval Finset +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +def rawTailFiber {m : ℕ} (X : Fin m→ℕ) (W : ℕ) (S : Fin m→ℝ) + (r : Fin m→ℤ) (L : ℤ) : Finset (Fin m→ℕ) := by + classical + exact Fintype.piFinset (fun j=>(Ico (X j) ((X j)^2)).filter (fun t=> + W.Coprime t ∧ S j≤(t:ℝ) ∧ (t:ℝ)<2*S j ∧ L∣(t:ℤ)-r j)) + +def literalFiberMass {m : ℕ} (E : Set (Fin m→ℤ)) (X : Fin m→ℕ) (Xp W : ℕ) + (S : Fin m→ℝ) (r : Fin m→ℤ) (L : ℤ) (Q Δ : ℝ) (a M : ℤ) : ℝ := by + classical + exact ∑ t∈(rawTailFiber X W S r L).filter (fun t=>(fun j=>(t j:ℤ))∈E), + (∏ j,(t j:ℝ)⁻¹)*∑ p∈pivotFiber Xp Q Δ (∏ j,(t j:ℝ)) a M, + if W.Coprime p then (p:ℝ)⁻¹ else 0 + +lemma rawTail_cast_mem {m : ℕ} (X : Fin m→ℕ) (W : ℕ) (S : Fin m→ℝ) + (r : Fin m→ℤ) (L : ℤ) (hL : 0(t j:ℤ))∈productTimes S r L := by + classical + apply Fintype.mem_piFinset.mpr + intro j + have hj := mem_filter.mp (Fintype.mem_piFinset.mp ht j) + apply (mem_times (S j) (r j) L (t j) hL).mpr + obtain ⟨z,hz⟩ := hj.2.2.2.2 + exact ⟨by simpa using hj.2.2.1,by simpa using hj.2.2.2.1,z,by linarith⟩ + +lemma times_nonneg {m : ℕ} (X : Fin m→ℕ) (S : Fin m→ℝ) (r : Fin m→ℤ) (L : ℤ) + (hL : 0(t j).toNat)∈rawTailFiber X W S r L := by + classical + apply Fintype.mem_piFinset.mpr + intro j + have hj := (mem_times (S j) (r j) L (t j) hL).mp (Fintype.mem_piFinset.mp ht j) + have hn : ((t j).toNat:ℤ)=t j := Int.toNat_of_nonneg (times_nonneg X S r L hL hlo t ht j) + have hnr : ((t j).toNat:ℝ)=(t j:ℝ) := by exact_mod_cast hn + obtain ⟨z,hz⟩ := hj.2.2 + have hcong : L∣((t j).toNat:ℤ)-r j := ⟨z,by rw [hn,hz]; ring⟩ + apply mem_filter.mpr + refine ⟨mem_Ico.mpr ⟨?_,?_⟩,residue_unit W (t j).toNat (r j) L hWL (hr j) hcong, + ?_,?_,hcong⟩ + · have hh := (hlo j).trans hj.1 + rw [←hnr] at hh + exact_mod_cast hh + · have hh := hj.2.1.trans_le (hhi j) + rw [←hnr] at hh + exact_mod_cast hh + · rw [hnr] + exact hj.1 + · rw [hnr] + exact hj.2.1 + + + +theorem literal_mass_eq {m : ℕ} (E : Set (Fin m→ℤ)) (X : Fin m→ℕ) (Xp W : ℕ) + (S : Fin m→ℝ) (r : Fin m→ℤ) (L : ℤ) (Q Δ : ℝ) (a M : ℤ) + (hL : 0t∈E)) Xp W Q Δ a M + := by + classical + unfold literalFiberMass rawFiberMass + apply sum_bij (fun t _=>fun j=>(t j:ℤ)) + · intro t ht + obtain ⟨ht,hE⟩ := mem_filter.mp ht + exact mem_filter.mpr ⟨rawTail_cast_mem X W S r L hL t ht,hE⟩ + · intro t ht u hu he + funext j + exact_mod_cast congrFun he j + · intro t ht + obtain ⟨ht,hE⟩ := mem_filter.mp ht + have hh : (fun j=>((t j).toNat:ℤ))=t := funext (fun j=> + Int.toNat_of_nonneg (times_nonneg X S r L hL hlo t ht j)) + refine ⟨fun j=>(t j).toNat,mem_filter.mpr ⟨times_nat_mem X W S r L hL hWL hr hlo hhi t ht,?_⟩,hh⟩ + rwa [hh] + · intro t ht + simp only [Int.cast_natCast] + +end HarmonicExposure +end +end + +section + + + + + +section RawSuccessInlineScope0 +noncomputable section +open MeasureTheory Filter Topology +open scoped BigOperators +namespace MicrocellHarmonic +variable {I : Type*} [Fintype I] [Nonempty I] + + +def weight (w : I → ℝ) (i : I) : ℝ := w i / ∑ j,w j + +def uniform (_i : I) : ℝ := (Fintype.card I : ℝ)⁻¹ + +lemma total_pos (w : I → ℝ) (hw : ∀ i,0hw i) Finset.univ_nonempty + +lemma sum_weight (w : I → ℝ) (hw : ∀ i,0he i j) + _ = _ := by rw [Finset.mul_sum] + have heq : weight w i-uniform i = (∑ j,(w i-w j))/((Fintype.card I : ℝ)*(∑ j,w j)) := by + simp only [weight,uniform,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + rw [heq,abs_div,abs_of_pos (mul_pos hc hW)] + calc + _ ≤ (ε*∑ j,w j)/((Fintype.card I : ℝ)*(∑ j,w j)) := + div_le_div_of_nonneg_right hn (mul_pos hc hW).le + _ = _ := by field_simp + + + +theorem l1_error (w : I → ℝ) (hw : ∀ i,0normalized_error w hw ε he i) + _ = ε := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp + + + +theorem test_error (w : I → ℝ) (hw : ∀ i,0(p j)⁻¹) i*f i)-(∑ i,uniform i*f i)| ≤ R/X := by + simpa only [one_mul] using test_error (fun j=>(p j)⁻¹) + (fun j=>inv_pos.mpr (hX.trans_le (hp j).1)) (R/X) 1 zero_le_one + (fun i j=>reciprocal_oscillation hX hR (hp i).1 (hp i).2 (hp j).1 (hp j).2) f hf + +end MicrocellHarmonic + +end +end RawSuccessInlineScope0 +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellSaturation01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellSaturation01.lean new file mode 100644 index 0000000000000000000000000000000000000000..165674daa758e68a410b9b424e279503eae64e72 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellSaturation01.lean @@ -0,0 +1,400 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MicrocellFibers01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section RawSuccessInlineScope14 + +noncomputable section +open MeasureTheory Filter Topology +open scoped BigOperators +namespace RawSmallCells +attribute [local instance] Classical.propDecidable +open Finset RawHarmonicProbability MicrocellConditional DyadicHarmonicBoundary + +lemma finite_event (X W:ℕ) (hW:0mem_biUnion.mpr (hcover p hp)) + rw [finite_event X W hW hX E hE] + calc + _ ≤ ((E.card:ℝ)/X)/(mass X (X^2) W) := by + apply div_le_div_of_nonneg_right ?_ (mass_nonneg _ _ _) + calc + _ ≤ ∑ _p∈E,(X:ℝ)⁻¹ := sum_le_sum (by + intro p hp + apply inv_anti₀ hx + exact_mod_cast (mem_Ico.mp (mem_filter.mp (hE hp)).1).1) + _ = _:=by simp;ring + _ ≤ ((T.card:ℝ)*W.totient*((R:ℝ)/W+2)/X)/((W.totient:ℝ)/(4*W)) := by + apply div_le_div₀ (by positivity) (div_le_div_of_nonneg_right hc hx.le) (by positivity) hm + _ = _:=by field_simp + + + +def partialCells (X W R:ℕ) : Finset ℕ := (RawHarmonicProbability.units X W).filter + (fun p=>¬(X≤R*(p/R) ∧ R*(p/R+1)≤X^2)) + +lemma partial_cover (X W R p:ℕ) (hR:0if i=0 then X else X^2-R) (partialCells X W R) (filter_subset _ _) (by + intro p hp + rcases partial_cover X W R p hR hp with h|h + · exact ⟨0,mem_univ _,by simpa using h⟩ + · exact ⟨1,mem_univ _,by simpa using h⟩) + norm_num at hh ⊢ + exact hh + +lemma partial_cost_simple (X W R:ℕ) (hW:0(R n:ℝ)/X n) atTop (𝓝 0)) : + ∃ ε:ℕ→ℝ,Tendsto ε atTop (𝓝 0) ∧ ∀ᶠ n in atTop, + ∀ (hw:024*((R n:ℝ)/X n),by simpa using hr.const_mul 24,?_⟩ + filter_upwards [hbase] with n hn hw hx + simpa [mul_div_assoc] using partial_cost_simple (X n) (W n) (R n) hw hx hn.2.2 + +end RawSmallCells +end +end RawSuccessInlineScope14 + + + + + +section RawSuccessInlineScope15 +noncomputable section +open scoped BigOperators +open Finset MeasureTheory +namespace RawPartitionSuccess +attribute [local instance] Classical.propDecidable + + + +theorem finite_partition {α ι : Type*} [DecidableEq α] [DecidableEq ι] + (S : Finset α) (w : α → ℝ) (hw : ∀ x∈S,0≤w x) + (π : α → ι) (G : Set ι) (A : Set α) (a ε : ℝ) (ha : 0≤a) + (hZ : 0 < ∑ x∈S,w x) + (hbad : (∑ x∈S.filter (fun x => π x∉G),w x) ≤ ε*(∑ x∈S,w x)) + (hs : ∀ i∈S.image π,i∈G → + a*(∑ x∈S.filter (fun x => π x=i),w x) ≤ + ∑ x∈S.filter (fun x => π x=i),if x∈A then w x else 0) : + a*(1-ε) ≤ (∑ x∈S,if x∈A then w x else 0)/(∑ x∈S,w x) := by + classical + let T := (S.image π).filter (·∈G) + have hb : (∑ x∈S.filter (fun x => π x∈G),w x) + + (∑ x∈S.filter (fun x => π x∉G),w x) = ∑ x∈S,w x := by + exact sum_filter_add_sum_filter_not S (fun x => π x∈G) w + have hf : S.filter (fun x => π x∈T)=S.filter (fun x => π x∈G) := by + ext x + simp only [mem_filter,T] + constructor + · rintro ⟨hx,hxT⟩;exact ⟨hx,hxT.2⟩ + · rintro ⟨hx,hxG⟩;exact ⟨hx,mem_image_of_mem π hx,hxG⟩ + have hsum : a*(∑ x∈S.filter (fun x => π x∈G),w x) ≤ + ∑ x∈S,if x∈A then w x else 0 := by + calc + _ = ∑ i∈T,a*(∑ x∈S.filter (fun x => π x=i),w x) := by + rw [←mul_sum,sum_fiberwise_eq_sum_filter,hf] + _ ≤ ∑ i∈T,∑ x∈S.filter (fun x => π x=i),if x∈A then w x else 0 := + sum_le_sum (fun i hi => hs i (mem_filter.mp hi).1 (mem_filter.mp hi).2) + _ = ∑ x∈S.filter (fun x => π x∈G),if x∈A then w x else 0 := by + rw [sum_fiberwise_eq_sum_filter,hf] + _ ≤ ∑ x∈S,if x∈A then w x else 0 := by + apply sum_le_sum_of_subset_of_nonneg (filter_subset _ _) + intro x hx hnot + split_ifs <;> simp_all + apply (le_div_iff₀ hZ).mpr + have hlo : (1-ε)*(∑ x∈S,w x) ≤ ∑ x∈S.filter (fun x => π x∈G),w x := by + linarith + have hh := mul_le_mul_of_nonneg_left hlo ha + nlinarith + +open RawHarmonicProbability MicrocellConditional + + + +theorem raw_partition {ι : Type*} [DecidableEq ι] + (X W : ℕ) (hW : 0 π p=i):Set ℕ)) / + (law X W hW hX : Measure ℕ).real + ((units X W).filter (fun p => π p=i):Set ℕ)) : + a*(1-ε) ≤ (law X W hW hX : Measure ℕ).real A := by + have hZ := mass_pos X W hW hX + rw [mass_units] at hZ + rw [law_apply_units] at hbad ⊢ + rw [mass_units] at hbad ⊢ + apply finite_partition (units X W) (fun p => (p:ℝ)⁻¹) + (fun p hp => by positivity) π G A a ε ha hZ + · have hh := (div_le_iff₀ hZ).mp hbad + have he : eventMass (units X W) {p | π p∉G} = + ∑ p∈(units X W).filter (fun p=>π p∉G),(p:ℝ)⁻¹ := by + unfold eventMass + rw [sum_filter] + apply sum_congr rfl + intro p hp + split_ifs <;> simp_all + rw [he] at hh + exact hh + · intro i hi hG + have hcond := hs i hi hG + rw [conditional_ratio X W hW hX _ (filter_subset _ _) A] at hcond + have hCi : ((units X W).filter (fun p => π p=i)).Nonempty := by + obtain ⟨p,hp,rfl⟩ := mem_image.mp hi + exact ⟨p,mem_filter.mpr ⟨hp,rfl⟩⟩ + have hCpos : 0 < ∑ p∈(units X W).filter (fun p => π p=i),(p:ℝ)⁻¹ := by + apply sum_pos _ hCi + intro p hp + apply inv_pos.mpr + exact units_pos (by omega) ⟨p,(mem_filter.mp hp).1⟩ + exact (le_div_iff₀ hCpos).mp hcond + +end RawPartitionSuccess +end +end RawSuccessInlineScope15 + + + + + +section RawSuccessInlineScope16 +noncomputable section +open scoped BigOperators +open Finset MeasureTheory +namespace MicrocellSaturation +open RawHarmonicProbability RawSmallCells RawPartitionSuccess MicrocellFibers +attribute [local instance] Classical.propDecidable + + + +def good {J : Type*} (X R H : ℕ) (t : J→ℕ) (i : ℕ×ℕ) : Prop := + X≤R*i.1 ∧ R*(i.1+1)≤X^2 ∧ + ∀ j,t j*(R*i.1-R)/H=t j*(R*(i.1+1)+R)/H + +def label (R M p : ℕ) : ℕ×ℕ := (p/R,p%M) + +lemma quotient_window (R p : ℕ) (hR : 0 label (M*N) M p=(q,r)) = + fiber M N (N*q) r := by + have hlo' : X≤M*(N*q) := by simpa only [mul_assoc] using hlo + have hhi' : M*(N*q+N)≤X^2 := by nlinarith + have hR : 0 nlinarith + · intro hp + have hpU := fiber_subset_units X W M N (N*q) r hWM hWR hlo' hhi' hp + obtain ⟨hpI,hpr⟩ := mem_filter.mp hp + obtain ⟨hpl,hph⟩ := mem_Ico.mp hpI + apply mem_filter.mpr + refine ⟨hpU,Prod.ext ?_ hpr⟩ + exact Nat.div_eq_of_lt_le (by nlinarith) (by nlinarith) + +lemma label_unit (X W M R : ℕ) (hM : 0 point M (N*i.1) i.2 b):Measure ℕ).real A) : + (c/3)*(1-(8*((M*N:ℕ):ℝ)+16*W)/X-Fintype.card J*ε) ≤ + (law X W hW hX : Measure ℕ).real A := by + have hbad := bad_conditioning_bound X W (M*N) H M hW hX (Nat.mul_pos hM hN) t ε hb + have hp := raw_partition X W hW hX (label (M*N) M) + {i | good X (M*N) H t i} A (c/3) + (8*(((M*N:ℕ):ℝ)+2*W)/X+Fintype.card J*ε) (by positivity) hbad + have hcond : ∀ i∈(units X W).image (label (M*N) M),good X (M*N) H t i → + c/3 ≤ (law X W hW hX : Measure ℕ).real + (A∩((units X W).filter (fun p => label (M*N) M p=i):Set ℕ)) / + (law X W hW hX : Measure ℕ).real + ((units X W).filter (fun p => label (M*N) M p=i):Set ℕ) := by + intro i hi hg + obtain ⟨hr,hWr⟩ := label_unit X W M (M*N) hM hWM i hi + rw [show i=(i.1,i.2) from rfl, + conditioned_fiber X W M N i.1 i.2 hM hN hr hWr hWM hg.1 hg.2.1] + apply le_of_lt + apply raw_fiber_success X W M N (N*i.1) i.2 hW hX hM hN hr hWr hWM + (by simpa only [mul_assoc] using hg.1) (by nlinarith [hg.2.1]) c A herr + exact hs i hi hg + have hh := hp hcond + convert hh using 1 + ring + +end MicrocellSaturation + +end +end RawSuccessInlineScope16 +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellScale01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellScale01.lean new file mode 100644 index 0000000000000000000000000000000000000000..02f616703139b15f1115d0123600e746e8c4456f --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/MicrocellScale01.lean @@ -0,0 +1,334 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MicrocellHarmonic01 +import OAI.Combinatorics.SumProduct.Alignment.PointLaw02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section RawSuccessInlineScope1 +open scoped Topology BigOperators +open Filter MeasureTheory Set +open scoped Topology BigOperators +open Filter MeasureTheory Set +open scoped Topology BigOperators BoundedContinuousFunction ENNReal +open MeasureTheory Set Filter +namespace SourcePointLaw +noncomputable section +open scoped Topology BigOperators BoundedContinuousFunction ENNReal +open MeasureTheory Set Filter + +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + [TopologicalSpace Y] [OpensMeasurableSpace Y] +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + + + +theorem beta_integrand_continuous (μ : ProbabilityMeasure X) (T : ℝ × X → Y) + (hT : Measurable T) (hc : ∀ x, Continuous (fun β => T (β, x))) (F : Y →ᵇ E) : + Continuous (fun β => ∫ x, F (T (β, x)) ∂(μ : Measure X)) := by + apply continuous_of_dominated (bound := fun _ => ‖F‖) + · intro β + exact (F.continuous.measurable.comp + (hT.comp (measurable_const.prodMk measurable_id))).aestronglyMeasurable + · intro β + exact Eventually.of_forall (fun x => F.norm_coe_le_norm _) + · exact integrable_const _ + · exact Eventually.of_forall (fun x => F.continuous.comp (hc x)) + + + +def empiricalLaw (p : ℕ → Y) (N : ℕ) : ProbabilityMeasure Y := + if h : 0 < N then + letI : NeZero N := ⟨h.ne'⟩ + uniformMixture (fun i : Fin N => (⟨Measure.dirac (p i.val), inferInstance⟩ : ProbabilityMeasure Y)) + else ⟨Measure.dirac (p 0), inferInstance⟩ + +lemma integral_empiricalLaw [CompleteSpace E] (p : ℕ → Y) (N : ℕ) (hN : 0 < N) (F : Y →ᵇ E) : + ∫ y, F y ∂(empiricalLaw p N : Measure Y) = + (N : ℝ)⁻¹ • ∑ n ∈ Finset.range N, F (p n) := by + let : NeZero N := ⟨hN.ne'⟩ + have he : empiricalLaw p N = uniformMixture + (fun i : Fin N => (⟨Measure.dirac (p i.val), inferInstance⟩ : ProbabilityMeasure Y)) := by + exact dite_eq_left hN + rw [he] + trans (Fintype.card (Fin N) : ℝ)⁻¹ • ∑ i : Fin N, + ∫ y, F y ∂(Measure.dirac (p i.val)) + · exact integral_uniformMixture + (fun i : Fin N => (⟨Measure.dirac (p i.val), inferInstance⟩ : ProbabilityMeasure Y)) F + simp only [Fintype.card_fin, integral_dirac' F _ F.continuous.measurable.stronglyMeasurable, + Finset.sum_range] + +end +end SourcePointLaw + +namespace SourcePointLaw +noncomputable section +open scoped Topology BigOperators BoundedContinuousFunction ENNReal NNReal +open MeasureTheory Set Filter + + + +theorem empirical_tendsto_betaMixture + {Y : Type*} [PseudoMetricSpace Y] [MeasurableSpace Y] [OpensMeasurableSpace Y] + (P : ℕ → ℤ → Y) (d : ℕ) [NeZero d] + (X : Fin d → Type*) [∀ r, MeasurableSpace (X r)] + (μ : ∀ r, ProbabilityMeasure (X r)) (T : ∀ r, ℝ × X r → Y) + (hT : ∀ r, Measurable (T r)) + (hc : ∀ r x, Continuous (fun β => T r (β, x))) + (hloc : ∀ r (F : Y →ᵇ ℝ) (L : ℝ≥0), LipschitzWith L F → + ∀ x ∈ Icc (0 : ℝ) 1, ∀ ε > 0, + ∀ᶠ α : ℝ in 𝓝[>] 0, ∀ᶠ N : ℕ in atTop, + ∀ a b : ℝ, 0 ≤ a → a ≤ x → x ≤ b → b ≤ 1 → b - a = α → + ‖(𝔼 n ∈ residueInterval d r.val (a * N) (b * N), F (P N n)) - + ∫ y, F (T r (x, y)) ∂(μ r : Measure (X r))‖ < ε) : + Tendsto (fun N : ℕ => empiricalLaw (fun n => P N n) N) atTop + (𝓝 (uniformMixture (fun r => betaImage (μ r) (T r) (hT r)))) := by + apply MeasureTheory.tendsto_iff_forall_lipschitz_integral_tendsto.mpr + intro f hb hl + obtain ⟨L, hL⟩ := hl + let F : Y →ᵇ ℝ := ⟨⟨f, hL.continuous⟩, hb⟩ + change Tendsto (fun N : ℕ => ∫ y, F y ∂(empiricalLaw (fun n => P N n) N : Measure Y)) + atTop (𝓝 (∫ y, F y ∂(uniformMixture (fun r => betaImage (μ r) (T r) (hT r)) : Measure Y))) + rw [integral_uniformMixture] + simp only [Fintype.card_fin, integral_betaImage] + have hlim := global_point_law_fin (fun N n => F (P N n)) d (Nat.pos_of_ne_zero (NeZero.ne d)) + (fun r β => ∫ y, F (T r (β, y)) ∂(μ r : Measure (X r))) + (fun r => (beta_integrand_continuous (μ r) (T r) (hT r) (hc r) F).continuousOn) + (fun r => hloc r F L hL) + apply hlim.congr' + filter_upwards [Filter.eventually_ge_atTop (1 : ℕ)] with N hN + exact (integral_empiricalLaw (fun n => P N n) N (by omega) F).symm + +end +end SourcePointLaw + +end RawSuccessInlineScope1 + + + + + +section RawSuccessInlineScope2 + + +noncomputable section +open MeasureTheory Filter Topology +open scoped BigOperators ENNReal +namespace MicrocellProbability +variable {I Y : Type*} [Fintype I] [Nonempty I] [MeasurableSpace Y] +open MicrocellHarmonic +attribute [local instance] Classical.propDecidable + +lemma weight_pos (w:I→ℝ) (hw:∀ i,0(weight_pos w hw i).le),sum_weight w hw] + norm_num⟩ + + +def uniformLaw (p:I→Y) : ProbabilityMeasure Y := + SourcePointLaw.uniformMixture (fun i=>⟨Measure.dirac (p i),inferInstance⟩) + +lemma weightedLaw_apply (w:I→ℝ) (hw:∀ i,0 simp [Set.indicator,hi,ENNReal.toReal_ofReal (weight_pos w hw i).le] + · intro i _ + by_cases hi:p i∈S <;> simp [Set.indicator,hi] + +lemma uniformLaw_apply (p:I→Y) (S:Set Y) (hS:MeasurableSet S) : + (uniformLaw p:Measure Y).real S = ∑ i,uniform i*(if p i∈S then 1 else 0) := by + classical + change (((Fintype.card I : ℝ≥0∞)⁻¹ • (∑ i,Measure.dirac (p i)) : Measure Y) S).toReal = _ + simp only [Measure.smul_apply,Measure.finsetSum_apply,smul_eq_mul, + ENNReal.toReal_mul,ENNReal.toReal_inv,ENNReal.toReal_natCast,Measure.dirac_apply' _ hS] + rw [ENNReal.toReal_sum] + · rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + by_cases hi:p i∈S <;> simp [uniform,Set.indicator,hi] + · intro i _ + by_cases hi:p i∈S <;> simp [Set.indicator,hi] + + + +theorem harmonic_event_error (x:I→ℝ) (X R:ℝ) (hX:0(x i)⁻¹) (fun i=>inv_pos.mpr (hX.trans_le (hx i).1)) p:Measure Y).real S - + (uniformLaw p:Measure Y).real S| ≤ R/X := by + rw [weightedLaw_apply _ _ _ _ hS,uniformLaw_apply _ _ hS] + apply harmonic_test_error x X R hX hR hx + intro i + split_ifs <;> norm_num + + + +theorem harmonic_success (x:I→ℝ) (X R c:ℝ) (hX:0(x i)⁻¹) (fun i=>inv_pos.mpr (hX.trans_le (hx i).1)) p:Measure Y).real S := by + have he:=harmonic_event_error x X R hX hR hx p S hS + have he':= (abs_le.mp he).1 + linarith + +lemma empiricalLaw_eq (p:ℕ→Y) (N:ℕ) (hN:0p i) := by + exact dite_eq_left hN + +end MicrocellProbability +end +end RawSuccessInlineScope2 + + + + + +section RawSuccessInlineScope3 +noncomputable section +open Filter Topology +namespace MicrocellScale + + +def radius (M H:ℕ) : ℕ := M*⌊Real.sqrt (H:ℝ)/(M:ℝ)⌋₊ +def length (M H:ℕ) : ℕ := radius M H/M + +lemma modulus_dvd (M H:ℕ) : M∣radius M H := dvd_mul_right _ _ +lemma length_eq (M H:ℕ) (hM:0A n/(S n)^C) atTop atTop + +lemma sqrt_dominates {H:ℕ→ℕ} {S:ℕ→ℝ} + (hS:∀ᶠ n in atTop,1≤S n) (hd: Dominates (fun n=>(H n:ℝ)) S) + (C:ℝ) (hC:0Real.sqrt (H n:ℝ)/(S n)^C) atTop atTop := by + have hh:=Real.tendsto_sqrt_atTop.comp (hd (2*C) (by positivity)) + apply hh.congr' + filter_upwards [hS] with n hn + exact sqrt_ratio (H n) (S n) C (by positivity) (by linarith) + + + +theorem radius_dominates {M H:ℕ→ℕ} {S:ℕ→ℝ} + (hM:∀ᶠ n in atTop,0(H n:ℝ)) S) : + Dominates (fun n=>(radius (M n) (H n):ℝ)) S := by + intro C hC + have hsmall:∀ᶠ n in atTop,4*(M n:ℝ)^2≤H n := by + filter_upwards [hM,hS,(hd 2 (by norm_num)).eventually_ge_atTop 4] with n hm hs hh + have hs0:0(Real.sqrt (H n:ℝ)/(S n)^C)/2) atTop atTop := + hc.atTop_div_const (by norm_num) + apply tendsto_atTop_mono' atTop _ hh + filter_upwards [hS,hM,hsmall] with n hs hm hn + have hh:=radius_half_sqrt (M n) (H n) hm.1 hn + have hp:0<(S n)^C:=Real.rpow_pos_of_pos (by linarith) C + convert div_le_div_of_nonneg_right hh hp.le using 1 + ring + + + +theorem boundary_rate {M H t:ℕ→ℕ} {S:ℕ→ℝ} + (hM:∀ᶠ n in atTop,0(H n:ℝ)) S) : + Tendsto (fun n=>(t n:ℝ)*radius (M n) (H n)/H n) atTop (𝓝 0) := by + have hh:Tendsto (fun n=>(S n)^2/Real.sqrt (H n:ℝ)) atTop (𝓝 0) := by + simpa only [Function.comp_def,inv_div,Real.rpow_two] using + tendsto_inv_atTop_zero.comp (sqrt_dominates hS hd 2 (by norm_num)) + have hp:∀ᶠ n in atTop,0<(H n:ℝ) := by + filter_upwards [hS,(hd 1 (by norm_num)).eventually_ge_atTop 1] with n hs hn + rw [Real.rpow_one] at hn + have hpos:0by positivity)) ?_ hh + filter_upwards [hM,ht,hp] with n hm ht hn + have hs:0Real.log (X n:ℝ)/(H n:ℝ)) atTop atTop) : + Tendsto (fun n=>(radius (M n) (H n):ℝ)/X n) atTop (𝓝 0) := by + have hh:Tendsto (fun n=>(X n:ℝ)/(H n:ℝ)) atTop atTop := by + apply tendsto_atTop_mono' atTop _ hd + exact Filter.Eventually.of_forall (fun n=>div_le_div_of_nonneg_right + (Real.log_le_self (by positivity)) (by positivity)) + have hz:Tendsto (fun n=>(H n:ℝ)/(X n:ℝ)) atTop (𝓝 0) := by + simpa only [Function.comp_def,inv_div] using tendsto_inv_atTop_zero.comp hh + apply squeeze_zero' (Filter.Eventually.of_forall (fun n=>by positivity)) ?_ hz + filter_upwards [hM,hH] with n hm hn + apply div_le_div_of_nonneg_right _ (by positivity) + apply (radius_le _ _ hm).trans + apply Real.sqrt_le_iff.mpr + have hn':(1:ℝ)≤H n:=by exact_mod_cast hn + constructor <;> nlinarith + +end MicrocellScale + +end +end RawSuccessInlineScope3 +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/NearLattice01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/NearLattice01.lean new file mode 100644 index 0000000000000000000000000000000000000000..0e708c46a4718d415dc3fdf9d661c180162d78fc --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/NearLattice01.lean @@ -0,0 +1,314 @@ +import Mathlib +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +namespace NearLattice +open scoped BigOperators +noncomputable section + + +theorem card_int_interval_le (a b : ℝ) (hab : a ≤ b) : + ((Finset.Icc ⌈a⌉ ⌊b⌋).card : ℝ) ≤ b - a + 1 := by + by_cases h : ⌈a⌉ ≤ ⌊b⌋ + 1 + · have he : ((Finset.Icc ⌈a⌉ ⌊b⌋).card : ℝ) = (⌊b⌋ : ℝ) + 1 - (⌈a⌉ : ℝ) := by + exact_mod_cast Int.card_Icc_of_le ⌈a⌉ ⌊b⌋ h + rw [he] + linarith [Int.floor_le b, Int.le_ceil a] + · have he : Finset.Icc ⌈a⌉ ⌊b⌋ = ∅ := Finset.Icc_eq_empty (by omega) + simp only [he, Finset.card_empty, Nat.cast_zero] + linarith + +theorem card_int_subset_interval_le (S : Finset ℤ) (a b : ℝ) (hab : a ≤ b) + (hS : ∀ n ∈ S, a ≤ (n : ℝ) ∧ (n : ℝ) ≤ b) : + (S.card : ℝ) ≤ b - a + 1 := by + have hs : S ⊆ Finset.Icc ⌈a⌉ ⌊b⌋ := by + intro n hn + exact Finset.mem_Icc.mpr ⟨Int.ceil_le.mpr (hS n hn).1, Int.le_floor.mpr (hS n hn).2⟩ + exact (show (S.card : ℝ) ≤ (Finset.Icc ⌈a⌉ ⌊b⌋).card from + Nat.cast_le.mpr (Finset.card_le_card hs)).trans (card_int_interval_le a b hab) + +theorem card_nat_subset_interval_le (S : Finset ℕ) (a b : ℝ) (hab : a ≤ b) + (hS : ∀ n ∈ S, a ≤ (n : ℝ) ∧ (n : ℝ) ≤ b) : + (S.card : ℝ) ≤ b - a + 1 := by + have hinj : Function.Injective (fun n : ℕ => (n : ℤ)) := Int.ofNat_injective + have hc : (S.image (fun n : ℕ => (n : ℤ))).card = S.card := + Finset.card_image_of_injective S hinj + rw [← hc] + apply card_int_subset_interval_le _ a b hab + intro n hn + obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp hn + simpa only [Int.cast_natCast] using hS i hi + + + +theorem card_affine_near_le (S : Finset ℕ) (L : ℕ) (γ β ε : ℝ) + (hβ : 0 < β) (hε : 0 ≤ ε) (hSL : ∀ n ∈ S, n < L) + (hgood : ∀ n ∈ S, ∃ m : ℤ, |γ + β * n - m| ≤ ε) : + (S.card : ℝ) ≤ (β * L + 2 * ε + 1) * (2 * ε / β + 1) := by + classical + let m (n : ℕ) : ℤ := if hn : n ∈ S then (hgood n hn).choose else 0 + have hm (n : ℕ) (hn : n ∈ S) : |γ + β * n - m n| ≤ ε := by + simp only [m, dite_eq_left hn] + exact (hgood n hn).choose_spec + let T := S.image m + have hT : (T.card : ℝ) ≤ β * L + 2 * ε + 1 := by + have he := card_int_subset_interval_le T (γ - ε) (γ + β * L + ε) + (by have : 0 ≤ β * (L : ℝ) := mul_nonneg hβ.le (Nat.cast_nonneg _); linarith) ?_ + · linarith + · intro z hz + obtain ⟨n, hn, rfl⟩ := Finset.mem_image.mp hz + have h := abs_le.mp (hm n hn) + have hn₀ : 0 ≤ (n : ℝ) := Nat.cast_nonneg _ + have hn₁ : (n : ℝ) ≤ L := by exact_mod_cast (hSL n hn).le + constructor <;> nlinarith + have hfiber (z : ℤ) : ((S.filter (fun n => m n = z)).card : ℝ) ≤ 2 * ε / β + 1 := by + have he := card_nat_subset_interval_le (S.filter (fun n => m n = z)) + (((z : ℝ) - ε - γ) / β) (((z : ℝ) + ε - γ) / β) + (div_le_div_of_nonneg_right (by linarith) hβ.le) ?_ + · have hr : ((z : ℝ) + ε - γ) / β - ((z : ℝ) - ε - γ) / β = 2 * ε / β := by ring + rwa [hr] at he + · intro n hn + obtain ⟨hn, he⟩ := Finset.mem_filter.mp hn + have h := abs_le.mp (hm n hn) + rw [he] at h + constructor + · apply (div_le_iff₀ hβ).mpr + nlinarith + · apply (le_div_iff₀ hβ).mpr + nlinarith + have hmT : Set.MapsTo m S T := by + intro n hn + exact Finset.mem_image.mpr ⟨n, hn, rfl⟩ + have hc : (S.card : ℝ) = ∑ z ∈ T, ((S.filter (fun n => m n = z)).card : ℝ) := by + exact_mod_cast Finset.card_eq_sum_card_fiberwise hmT + calc + _ = ∑ z ∈ T, ((S.filter (fun n => m n = z)).card : ℝ) := hc + _ ≤ ∑ _z ∈ T, (2 * ε / β + 1) := Finset.sum_le_sum (fun z _ => hfiber z) + _ = (T.card : ℝ) * (2 * ε / β + 1) := by simp only [Finset.sum_const, nsmul_eq_mul] + _ ≤ _ := mul_le_mul_of_nonneg_right hT (by positivity) + + +theorem card_affine_near_abs_le (S : Finset ℕ) (L : ℕ) (γ β ε : ℝ) + (hβ : β ≠ 0) (hε : 0 ≤ ε) (hSL : ∀ n ∈ S, n < L) + (hgood : ∀ n ∈ S, ∃ m : ℤ, |γ + β * n - m| ≤ ε) : + (S.card : ℝ) ≤ (|β| * L + 2 * ε + 1) * (2 * ε / |β| + 1) := by + rcases lt_or_gt_of_ne hβ with hβ | hβ + · have hh : ∀ n ∈ S, ∃ m : ℤ, |-γ + (-β) * n - m| ≤ ε := by + intro n hn + obtain ⟨m, hm⟩ := hgood n hn + refine ⟨-m, ?_⟩ + have he : -γ + (-β) * (n : ℝ) - ((-m : ℤ) : ℝ) = -(γ + β * n - m) := by + push_cast + ring + rwa [he, abs_neg] + simpa only [abs_of_neg hβ] using + card_affine_near_le S L (-γ) (-β) ε (neg_pos.mpr hβ) hε hSL hh + · simpa only [abs_of_pos hβ] using card_affine_near_le S L γ β ε hβ hε hSL hgood + + + +theorem card_near_of_approx (S : Finset ℕ) (N q : ℕ) (hq : 0 < q) + (α γ β ε : ℝ) (m : ℤ) (happrox : α * q = m + β) + (hβ : β ≠ 0) (hβsmall : |β| ≤ 2 * ε) (hε : 0 ≤ ε) (hεsmall : ε ≤ 1 / 4) + (hSN : ∀ n ∈ S, n < N) + (hgood : ∀ n ∈ S, ∃ z : ℤ, |α * n + γ - z| ≤ ε) : + (S.card : ℝ) ≤ 4 * ε * N + 3 * q + 4 * q * ε / |β| := by + classical + let L := N / q + 1 + let B := (|β| * L + 2 * ε + 1) * (2 * ε / |β| + 1) + have hfiber (r : ℕ) : ((S.filter (fun n => n % q = r)).card : ℝ) ≤ B := by + let Sᵣ := S.filter (fun n => n % q = r) + let T := Sᵣ.image (fun n => n / q) + have hc : T.card = Sᵣ.card := by + apply Finset.card_image_iff.mpr + intro x hx y hy he + change x / q = y / q at he + have hx' := (Finset.mem_filter.mp hx).2 + have hy' := (Finset.mem_filter.mp hy).2 + have h₁ := Nat.mod_add_div x q + have h₂ := Nat.mod_add_div y q + rw [hx', he] at h₁ + rw [hy'] at h₂ + omega + have hTL : ∀ k ∈ T, k < L := by + intro k hk + obtain ⟨n, hn, rfl⟩ := Finset.mem_image.mp hk + have h := Nat.div_le_div_right (c := q) (hSN n (Finset.mem_filter.mp hn).1).le + exact Nat.lt_succ_of_le h + have hTgood : ∀ k ∈ T, ∃ z : ℤ, |(α * r + γ) + β * k - z| ≤ ε := by + intro k hk + obtain ⟨n, hn, rfl⟩ := Finset.mem_image.mp hk + obtain ⟨hn, hr⟩ := Finset.mem_filter.mp hn + obtain ⟨z, hz⟩ := hgood n hn + refine ⟨z - m * (n / q : ℕ), ?_⟩ + have he : (n : ℝ) = (r : ℝ) + (q : ℝ) * (n / q : ℕ) := by + have ht := Nat.mod_add_div n q + rw [hr] at ht + exact_mod_cast ht.symm + have heq : (α * r + γ) + β * (n / q : ℕ) - ((z - m * (n / q : ℕ) : ℤ) : ℝ) = + α * n + γ - z := by + simp only [Int.cast_sub, Int.cast_mul, Int.cast_natCast] + rw [he] + linear_combination -(n / q : ℕ) * happrox + rwa [heq] + have h := card_affine_near_abs_le T L (α * r + γ) β ε hβ hε hTL hTgood + rwa [hc] at h + have hm : Set.MapsTo (fun n => n % q) S (Finset.range q) := by + intro n _ + exact Finset.mem_range.mpr (Nat.mod_lt _ hq) + have hc : (S.card : ℝ) = + ∑ r ∈ Finset.range q, ((S.filter (fun n => n % q = r)).card : ℝ) := by + exact_mod_cast Finset.card_eq_sum_card_fiberwise hm + have hb : (S.card : ℝ) ≤ (q : ℝ) * B := by + rw [hc] + calc + _ ≤ ∑ _r ∈ Finset.range q, B := Finset.sum_le_sum (fun r _ => hfiber r) + _ = _ := by simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] + have hbpos : 0 < |β| := abs_pos.mpr hβ + have hL : (q : ℝ) * L ≤ N + q := by + have h := Nat.div_mul_le_self N q + dsimp [L] + push_cast + have h' : (q : ℝ) * (N / q : ℕ) ≤ N := by exact_mod_cast (by simpa [Nat.mul_comm] using h) + nlinarith + have hq₀ : 0 ≤ (q : ℝ) := Nat.cast_nonneg _ + have hqL₀ : 0 ≤ (q : ℝ) * L := by positivity + have hB : (q : ℝ) * B ≤ 4 * ε * N + 3 * q + 4 * q * ε / |β| := by + have hc₀ : 0 ≤ 2 * ε / |β| + 1 := by positivity + have hc₁ : 2 * ε + 1 ≤ 2 := by linarith + have hstep : (q : ℝ) * B ≤ q * ((|β| * L + 2) * (2 * ε / |β| + 1)) := by + apply mul_le_mul_of_nonneg_left _ hq₀ + exact mul_le_mul_of_nonneg_right (by linarith) hc₀ + have heq : (q : ℝ) * ((|β| * L + 2) * (2 * ε / |β| + 1)) = + q * L * (2 * ε + |β|) + 4 * q * ε / |β| + 2 * q := by + field_simp + ring + have hi₁ := mul_le_mul_of_nonneg_left hβsmall hqL₀ + have hi₂ := mul_le_mul_of_nonneg_left hL (show 0 ≤ 4 * ε by positivity) + have hi₃ := mul_le_mul_of_nonneg_right hεsmall hq₀ + rw [heq] at hstep + nlinarith + exact hb.trans hB + + + +theorem exists_small_denominator (S : Finset ℕ) (N Q : ℕ) (hQ : 0 < Q) + (α γ ε : ℝ) (hSN : ∀ n ∈ S, n < N) + (hcard : N / Q + 1 < S.card) + (hgood : ∀ n ∈ S, ∃ z : ℤ, |α * n + γ - z| ≤ ε) : + ∃ q : ℕ, 0 < q ∧ q < Q ∧ ∃ m : ℤ, |α * q - m| ≤ 2 * ε := by + classical + have hh : Set.MapsTo (fun n => n / Q) S (Finset.range (N / Q + 1)) := by + intro n hn + apply Finset.mem_range.mpr + exact Nat.lt_succ_of_le (Nat.div_le_div_right (hSN n hn).le) + have hcard' : (Finset.range (N / Q + 1)).card < S.card := by simpa using hcard + obtain ⟨x, hx, y, hy, hxy, he⟩ := Finset.exists_ne_map_eq_of_card_lt_of_maps_to hcard' hh + change x / Q = y / Q at he + have hp (x y : ℕ) (hx : x ∈ S) (hy : y ∈ S) (hlt : x < y) (he : x / Q = y / Q) : + ∃ q : ℕ, 0 < q ∧ q < Q ∧ ∃ m : ℤ, |α * q - m| ≤ 2 * ε := by + obtain ⟨a, ha⟩ := hgood x hx + obtain ⟨b, hb⟩ := hgood y hy + refine ⟨y - x, Nat.sub_pos_of_lt hlt, ?_, b - a, ?_⟩ + · have hx' := Nat.mod_add_div x Q + have hy' := Nat.mod_add_div y Q + have hymod := Nat.mod_lt y hQ + rw [he] at hx' + omega + · have heq : α * (y - x : ℕ) - ((b - a : ℤ) : ℝ) = + (α * y + γ - b) - (α * x + γ - a) := by + rw [Nat.cast_sub hlt.le, Int.cast_sub] + ring + rw [heq] + exact (abs_sub _ _).trans (by linarith) + rcases lt_or_gt_of_ne hxy with hxy | hxy + · exact hp x y hx hy hxy he + · exact hp y x hy hx hxy he.symm + + + +theorem vinogradov_inverse (S : Finset ℕ) (N K : ℕ) + (hK : 0 < K) (hN : 32 * K ^ 2 ≤ N) (α γ ε : ℝ) + (hε : 0 ≤ ε) (hεsmall : ε ≤ 1 / (16 * (K : ℝ))) + (hSN : ∀ n ∈ S, n < N) + (hdensity : (N : ℝ) / K ≤ S.card) + (hgood : ∀ n ∈ S, ∃ z : ℤ, |α * n + γ - z| ≤ ε) : + ∃ q : ℕ, 0 < q ∧ q ≤ 2 * K ∧ ∃ m : ℤ, + |α * q - m| ≤ 16 * (K : ℝ) ^ 2 * ε / N := by + have hK₀ : 0 < (K : ℝ) := Nat.cast_pos.mpr hK + have hK₁ : 1 ≤ (K : ℝ) := by exact_mod_cast hK + have hN₀ : 0 < (N : ℝ) := by + have h : 32 * (K : ℝ) ^ 2 ≤ N := by exact_mod_cast hN + nlinarith + have hN' : 32 * (K : ℝ) ^ 2 ≤ N := by exact_mod_cast hN + have hcard : N / (2 * K) + 1 < S.card := by + have hdiv : ((N / (2 * K) : ℕ) : ℝ) ≤ (N : ℝ) / (2 * K) := by + simpa only [Nat.cast_mul, Nat.cast_ofNat] using + (Nat.cast_div_le (m := N) (n := 2 * K) (α := ℝ)) + have he : (N : ℝ) / (2 * K) + 1 < (N : ℝ) / K := by + apply (lt_div_iff₀ hK₀).mpr + have heq : ((N : ℝ) / (2 * K) + 1) * K = N / 2 + K := by + field_simp + rw [heq] + nlinarith + have : ((N / (2 * K) : ℕ) : ℝ) + 1 < S.card := lt_of_lt_of_le (by linarith) hdensity + exact_mod_cast this + obtain ⟨q, hq₀, hq₁, m, hm⟩ := exists_small_denominator S N (2 * K) (by omega) + α γ ε hSN hcard hgood + refine ⟨q, hq₀, hq₁.le, m, ?_⟩ + let β := α * q - m + have heps : ε ≤ 1 / 4 := by + have ht := (le_div_iff₀ (show 0 < 16 * (K : ℝ) by positivity)).mp hεsmall + nlinarith + by_cases hβ : β = 0 + · change |β| ≤ _ + rw [hβ, abs_zero] + positivity + · have hβpos : 0 < |β| := abs_pos.mpr hβ + have hq : (q : ℝ) ≤ 2 * K := by exact_mod_cast hq₁.le + have hq₀' : 0 ≤ (q : ℝ) := Nat.cast_nonneg _ + have hc := card_near_of_approx S N q hq₀ α γ β ε m (by dsimp [β]; ring) + hβ hm hε heps hSN hgood + have hepsmul : 16 * (K : ℝ) * ε ≤ 1 := by + have h := (le_div_iff₀ (show 0 < 16 * (K : ℝ) by positivity)).mp hεsmall + nlinarith + have hb₁ : 4 * ε * N ≤ (N : ℝ) / (4 * K) := by + apply (le_div_iff₀ (show 0 < 4 * (K : ℝ) by positivity)).mpr + have h := mul_le_mul_of_nonneg_right hepsmul hN₀.le + nlinarith + have hb₂ : 3 * (q : ℝ) ≤ (N : ℝ) / (4 * K) := by + apply (le_div_iff₀ (show 0 < 4 * (K : ℝ) by positivity)).mpr + have h := mul_le_mul_of_nonneg_right hq hK₀.le + nlinarith + have hr : (N : ℝ) / (2 * K) ≤ 4 * q * ε / |β| := by + have he₁ : (N : ℝ) / K = 2 * ((N : ℝ) / (2 * K)) := by ring + have he₂ : (N : ℝ) / (4 * K) = ((N : ℝ) / (2 * K)) / 2 := by ring + rw [he₁] at hdensity + rw [he₂] at hb₁ hb₂ + linarith + have hr' := (le_div_iff₀ hβpos).mp hr + have ht := mul_le_mul_of_nonneg_right hr' (show 0 ≤ 2 * (K : ℝ) by positivity) + have heq : ((N : ℝ) / (2 * K) * |β|) * (2 * K) = N * |β| := by + field_simp + rw [heq] at ht + have hqε := mul_le_mul_of_nonneg_right hq (show 0 ≤ 8 * (K : ℝ) * ε by positivity) + change |β| ≤ _ + apply (le_div_iff₀ hN₀).mpr + nlinarith + +end +end NearLattice + + + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail01.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f24e8cfe572c14bc0e33ec0b990e11a5f400c03 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail01.lean @@ -0,0 +1,316 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice04 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +end +end + + + +section +noncomputable section +namespace MalcevPrefixQuotient +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n r : ℕ} +variable (c : RealCoordinates G n) (hr : r ≤ n) +variable (N : Subgroup G) [N.Normal] +variable (hN : ∀ g : G, g ∈ N ↔ ∀ i : Fin n, i.val < r → c.coord g i = 0) + +omit [N.Normal] in +lemma represent_coordinates (x : G ⧸ N) (i : Fin n) : + c.coord (represent c (coordinates c hr N hN x)) i = + if h : i.val < r then coordinates c hr N hN x ⟨i.val,h⟩ else 0 := by + simp [represent,lift] + +lemma quotient_coordinates_mk (g : G) (i : Fin r) : + (quotientChart c hr N hN).coord (QuotientGroup.mk g) i = c.coord g (embed hr i) := rfl + + + +theorem quotient_lattice (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) (x : G ⧸ N) : + x ∈ Γ.map (QuotientGroup.mk' N) ↔ + ∀ i, ∃ z : ℤ, (quotientChart c hr N hN).coord x i = z := by + constructor + · rintro ⟨g,hg,rfl⟩ i + exact (hΓ g).mp hg (embed hr i) + · intro hx + refine ⟨represent c (coordinates c hr N hN x),?_,rebuild_coordinates c hr N hN x⟩ + apply (hΓ _).mpr + intro i + rw [represent_coordinates] + split_ifs with hi + · exact hx ⟨i.val,hi⟩ + · exact ⟨0,by simp⟩ + + +theorem quotient_adapted (K : Subgroup G) (s : ℕ) + (hK : ∀ g : G, g ∈ K ↔ ∀ i : Fin n, i.val < s → c.coord g i = 0) (x : G ⧸ N) : + x ∈ K.map (QuotientGroup.mk' N) ↔ + ∀ i : Fin r, i.val < s → (quotientChart c hr N hN).coord x i = 0 := by + constructor + · rintro ⟨g,hg,rfl⟩ i hi + exact (hK g).mp hg (embed hr i) hi + · intro hx + refine ⟨represent c (coordinates c hr N hN x),?_,rebuild_coordinates c hr N hN x⟩ + apply (hK _).mpr + intro i hi + rw [represent_coordinates] + split_ifs with hir + · exact hx ⟨i.val,hir⟩ hi + · rfl + + + +theorem quotient_rational (x : G ⧸ N) : IsRational (quotientChart c hr N hN) x ↔ + ∃ g : G, IsRational c g ∧ (QuotientGroup.mk g : G ⧸ N) = x := by + constructor + · intro hx + refine ⟨represent c (coordinates c hr N hN x),?_,rebuild_coordinates c hr N hN x⟩ + intro i + rw [represent_coordinates] + split_ifs with hi + · exact hx ⟨i.val,hi⟩ + · exact ⟨0,by simp⟩ + · rintro ⟨g,hg,rfl⟩ i + exact hg (embed hr i) + +end MalcevPrefixQuotient +end +end + + + +section +noncomputable section +namespace PairTail +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (K : Subgroup G) [K.Normal] + + +def square : Subgroup (G × G) where + carrier := {x | x.1⁻¹*x.2 ∈ K} + one_mem' := by simp + mul_mem' := by + intro a b ha hb + have hh := K.mul_mem ((inferInstance : K.Normal).conj_mem _ ha b.1⁻¹) hb + simpa [mul_assoc] using hh + inv_mem' := by + intro a ha + have hh := (inferInstance : K.Normal).conj_mem _ (K.inv_mem ha) a.1 + simpa [mul_assoc] using hh + +def first : square K →* G := (MonoidHom.fst G G).comp (square K).subtype + +def difference (x : square K) : K := ⟨x.val.1⁻¹*x.val.2,x.property⟩ + +def pair (g : G) (u : K) : square K := ⟨(g,g*u),by change g⁻¹*(g*u) ∈ K; simp⟩ + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +@[simp] lemma first_pair (g : G) (u : K) : first K (pair K g u) = g := rfl +omit [TopologicalSpace G] [IsTopologicalGroup G] in +@[simp] lemma difference_pair (g : G) (u : K) : difference K (pair K g u) = u := by + apply Subtype.ext + simp [difference,pair] +omit [TopologicalSpace G] [IsTopologicalGroup G] in +@[simp] lemma pair_first_difference (x : square K) : pair K (first K x) (difference K x) = x := by + apply Subtype.ext + ext <;> simp [pair,first,difference] +omit [IsTopologicalGroup G] in +lemma first_continuous : Continuous (first K) := continuous_fst.comp continuous_subtype_val +lemma difference_continuous : Continuous (difference K) := by + apply Continuous.subtype_mk + exact ((continuous_fst.comp continuous_subtype_val).inv).mul + (continuous_snd.comp continuous_subtype_val) +lemma pair_continuous : Continuous (fun x : G × K => pair K x.1 x.2) := by + apply Continuous.subtype_mk + exact continuous_fst.prodMk (continuous_fst.mul (continuous_subtype_val.comp continuous_snd)) + +def squareHomeomorph : square K ≃ₜ G × K where + toFun x := (first K x,difference K x) + invFun x := pair K x.1 x.2 + left_inv := pair_first_difference K + right_inv x := by simp + continuous_toFun := (first_continuous K).prodMk (difference_continuous K) + continuous_invFun := pair_continuous K + +variable (N : Subgroup G) + +def diagonal : Subgroup (square K) where + carrier := {x | x.val.1 ∈ N ∧ x.val.2 = x.val.1} + one_mem' := ⟨N.one_mem,rfl⟩ + mul_mem' := by + rintro a b ⟨ha,hea⟩ ⟨hb,heb⟩ + exact ⟨N.mul_mem ha hb,by change a.val.2*b.val.2 = a.val.1*b.val.1; rw [hea,heb]⟩ + inv_mem' := by + rintro a ⟨ha,he⟩ + exact ⟨N.inv_mem ha,by change a.val.2⁻¹ = a.val.1⁻¹; rw [he]⟩ + +variable (hcent : N ≤ Subgroup.center G) +include hcent in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma diagonal_normal : (diagonal K N).Normal where + conj_mem x hx y := by + rcases hx with ⟨hx,he⟩ + have hc := Subgroup.mem_center_iff.mp (hcent hx) + have h1 : y.val.1*x.val.1*y.val.1⁻¹ = x.val.1 := by + rw [hc y.val.1]; simp [mul_assoc] + have h2 : y.val.2*x.val.2*y.val.2⁻¹ = x.val.1 := by + rw [he,hc y.val.2]; simp [mul_assoc] + exact ⟨by change y.val.1*x.val.1*y.val.1⁻¹ ∈ N; rw [h1]; exact hx, + by change y.val.2*x.val.2*y.val.2⁻¹ = y.val.1*x.val.1*y.val.1⁻¹; rw [h1,h2]⟩ + +include hcent in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma eq_coset_iff (x y : square K) : + (QuotientGroup.mk x : square K ⧸ diagonal K N) = QuotientGroup.mk y ↔ + (QuotientGroup.mk (first K x) : G ⧸ N) = QuotientGroup.mk (first K y) ∧ + difference K x = difference K y := by + rw [QuotientGroup.eq,QuotientGroup.eq] + change (x.val.1⁻¹*y.val.1 ∈ N ∧ x.val.2⁻¹*y.val.2 = x.val.1⁻¹*y.val.1) ↔ _ + change _ ↔ x.val.1⁻¹*y.val.1 ∈ N ∧ difference K x = difference K y + constructor + · rintro ⟨hn,he⟩ + refine ⟨hn,Subtype.ext ?_⟩ + change x.val.1⁻¹*x.val.2 = y.val.1⁻¹*y.val.2 + have hc := Subgroup.mem_center_iff.mp (hcent hn) + have hy : y.val.2 = x.val.2*(x.val.1⁻¹*y.val.1) := by rw [← he]; simp + rw [hy] + symm + calc + y.val.1⁻¹*(x.val.2*(x.val.1⁻¹*y.val.1)) = + (y.val.1⁻¹*x.val.2)*(x.val.1⁻¹*y.val.1) := by group + _ = (x.val.1⁻¹*y.val.1)*(y.val.1⁻¹*x.val.2) := hc _ + _ = _ := by group + · rintro ⟨hn,hd⟩ + refine ⟨hn,?_⟩ + have hd' := congrArg Subtype.val hd + change x.val.1⁻¹*x.val.2 = y.val.1⁻¹*y.val.2 at hd' + have hy : y.val.2 = y.val.1*(x.val.1⁻¹*x.val.2) := by rw [hd']; simp + have hc := Subgroup.mem_center_iff.mp (hcent hn) + rw [hy] + calc + x.val.2⁻¹*(y.val.1*(x.val.1⁻¹*x.val.2)) = + x.val.2⁻¹*x.val.1*(x.val.1⁻¹*y.val.1)*(x.val.1⁻¹*x.val.2) := by group + _ = (x.val.1⁻¹*y.val.1)*(x.val.2⁻¹*x.val.1)*(x.val.1⁻¹*x.val.2) := by + rw [hc (x.val.2⁻¹*x.val.1)] + _ = x.val.1⁻¹*y.val.1 := by group + +def quotientCoordinates (x : square K ⧸ diagonal K N) : (G ⧸ N) × K := + Quotient.lift (fun x : square K => (QuotientGroup.mk (first K x),difference K x)) + (by + intro x y he + have h := (eq_coset_iff K N hcent x y).mp (Quotient.sound he) + exact Prod.ext h.1 h.2) x + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +@[simp] lemma quotientCoordinates_mk (x : square K) : + quotientCoordinates K N hcent (QuotientGroup.mk x) = + (QuotientGroup.mk (first K x),difference K x) := rfl +lemma quotientCoordinates_continuous : Continuous (quotientCoordinates K N hcent) := by + rw [(QuotientGroup.isQuotientMap_mk (diagonal K N)).continuous_iff] + exact (QuotientGroup.continuous_mk.comp (first_continuous K)).prodMk (difference_continuous K) + +variable (s : G ⧸ N → G) (hs : ∀ x, (QuotientGroup.mk (s x) : G ⧸ N) = x) +variable (hsc : Continuous s) +def quotientRebuild (x : (G ⧸ N) × K) : square K ⧸ diagonal K N := + QuotientGroup.mk (pair K (s x.1) x.2) +include hs in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma quotientCoordinates_rebuild (x : (G ⧸ N) × K) : + quotientCoordinates K N hcent (quotientRebuild K N s x) = x := by + simp [quotientRebuild,hs] +include hs in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma quotientRebuild_coordinates (x : square K ⧸ diagonal K N) : + quotientRebuild K N s (quotientCoordinates K N hcent x) = x := by + induction x using Quotient.inductionOn with | h x => + apply (eq_coset_iff K N hcent _ _).mpr + simp [quotientCoordinates_mk,hs] +include hsc in +lemma quotientRebuild_continuous : Continuous (quotientRebuild K N s) := by + exact QuotientGroup.continuous_mk.comp ((pair_continuous K).comp + ((hsc.comp continuous_fst).prodMk continuous_snd)) + +def quotientHomeomorph : (square K ⧸ diagonal K N) ≃ₜ (G ⧸ N) × K where + toFun := quotientCoordinates K N hcent + invFun := quotientRebuild K N s + left_inv := quotientRebuild_coordinates K N hcent s hs + right_inv := quotientCoordinates_rebuild K N hcent s hs + continuous_toFun := quotientCoordinates_continuous K N hcent + continuous_invFun := quotientRebuild_continuous K N s hsc + +end PairTail +end +end + + + +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace RationalPolynomialMap +variable {σ τ : Type*} + +def IsPolynomial (f : (σ → ℝ) → ℝ) : Prop := + ∃ P : MvPolynomial σ ℚ, ∀ x, f x = MvPolynomial.eval₂ (algebraMap ℚ ℝ) x P + +lemma const (q : ℚ) : IsPolynomial (fun _ : σ → ℝ => (q:ℝ)) := ⟨MvPolynomial.C q,by simp⟩ +lemma zero : IsPolynomial (fun _ : σ → ℝ => (0:ℝ)) := by simpa using const (σ:=σ) 0 +lemma one : IsPolynomial (fun _ : σ → ℝ => (1:ℝ)) := by simpa using const (σ:=σ) 1 +lemma coordinate (i : σ) : IsPolynomial (fun x : σ → ℝ => x i) := ⟨MvPolynomial.X i,by simp⟩ +lemma add {f g : (σ → ℝ) → ℝ} (hf : IsPolynomial f) (hg : IsPolynomial g) : + IsPolynomial (fun x => f x+g x) := by + obtain ⟨p,hp⟩ := hf + obtain ⟨q,hq⟩ := hg + exact ⟨p+q,by simp [hp,hq]⟩ +lemma mul {f g : (σ → ℝ) → ℝ} (hf : IsPolynomial f) (hg : IsPolynomial g) : + IsPolynomial (fun x => f x*g x) := by + obtain ⟨p,hp⟩ := hf + obtain ⟨q,hq⟩ := hg + exact ⟨p*q,by simp [hp,hq]⟩ +lemma neg {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) : IsPolynomial (fun x => -f x) := by + obtain ⟨p,hp⟩ := hf + exact ⟨-p,by simp [hp]⟩ +lemma sub {f g : (σ → ℝ) → ℝ} (hf : IsPolynomial f) (hg : IsPolynomial g) : + IsPolynomial (fun x => f x-g x) := by simpa [sub_eq_add_neg] using add hf (neg hg) + +lemma eval {f : τ → (σ → ℝ) → ℝ} (hf : ∀ i, IsPolynomial (f i)) + (P : MvPolynomial τ ℚ) : IsPolynomial (fun x => + MvPolynomial.eval₂ (algebraMap ℚ ℝ) (fun i => f i x) P) := by + induction P using MvPolynomial.induction_on with + | C q => simpa using const (σ:=σ) q + | add p q hp hq => simpa using add hp hq + | mul_X p i hp => simpa using mul hp (hf i) + +lemma comp {f : (τ → ℝ) → ℝ} (hf : IsPolynomial f) {g : (σ → ℝ) → (τ → ℝ)} + (hg : ∀ i, IsPolynomial (fun x => g x i)) : IsPolynomial (fun x => f (g x)) := by + obtain ⟨p,hp⟩ := hf + simpa only [hp] using eval hg p + +lemma polynomial_eval (P : ℚ[X]) {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) : + IsPolynomial (fun x => P.eval₂ (algebraMap ℚ ℝ) (f x)) := by + induction P using Polynomial.induction_on' with + | add p q hp hq => simpa using add hp hq + | monomial i a => + have hi : IsPolynomial (fun x => (f x)^i) := by + induction i with + | zero => simpa using one (σ:=σ) + | succ i ih => simpa only [pow_succ] using mul ih hf + simpa using mul (const a) hi +end RationalPolynomialMap + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail02.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a6082fe2aae996ad0576d347fe64a57fb654c08 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail02.lean @@ -0,0 +1,279 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice07 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +end +end + + + +section +noncomputable section +namespace PairTail +open RationalLattice RationalPolynomialMap +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d r : ℕ} (c : RealCoordinates G (t+d)) + +def lowerArgs (i : Fin (r+d)) (X Y : Fin (r+d) → ℝ) : (Fin i.val ⊕ Fin i.val) → ℝ := + Sum.elim (fun j => X ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => Y ⟨j.val,lt_trans j.isLt i.isLt⟩) + +def baseInput (j : Fin d) (v : (Fin (r+j.val) ⊕ Fin (r+j.val)) → ℝ) : G := + c.coord.symm (fun a => if h : a.val < r then v (.inr ⟨a.val,by omega⟩) else 0) + +def tailInput (j : Fin d) (v : Fin (r+j.val) → ℝ) : Fin (t+j.val) → ℝ := + fun a => if h : t ≤ a.val then v ⟨r+(a.val-t),by have := a.isLt; omega⟩ else 0 + +omit [IsTopologicalGroup G] in +lemma baseInput_polynomial (j : Fin d) : + IsPolynomialMap c (baseInput c (r:=r) j) := by + intro a + simp only [baseInput,Homeomorph.apply_symm_apply] + split_ifs + · exact coordinate _ + · exact zero + +omit [IsTopologicalGroup G] in +lemma tailCorrection_exists (j : Fin d) : + ∃ P : MvPolynomial (Fin (r+j.val) ⊕ Fin (r+j.val)) ℚ, + ∀ v : (Fin (r+j.val) ⊕ Fin (r+j.val)) → ℝ, + c.coord ((baseInput c j v)⁻¹ * + truncate c (RationalTailCoordinates.embed t j) (tailInput j (fun a => v (.inl a))) * + baseInput c j v * + truncate c (RationalTailCoordinates.embed t j) (tailInput j (fun a => v (.inr a)))) + (RationalTailCoordinates.embed t j) = MvPolynomial.eval₂ (algebraMap ℚ ℝ) v P := by + have hu : IsPolynomialMap c (fun v : (Fin (r+j.val) ⊕ Fin (r+j.val)) → ℝ => + truncate c (RationalTailCoordinates.embed t j) (tailInput j (fun a => v (.inl a)))) := by + apply polynomialMap_truncate + intro a + unfold tailInput + split_ifs + · exact coordinate _ + · exact zero + have hv : IsPolynomialMap c (fun v : (Fin (r+j.val) ⊕ Fin (r+j.val)) → ℝ => + truncate c (RationalTailCoordinates.embed t j) (tailInput j (fun a => v (.inr a)))) := by + apply polynomialMap_truncate + intro a + unfold tailInput + split_ifs + · exact coordinate _ + · exact zero + exact polynomialMap_mul c (polynomialMap_mul c + (polynomialMap_mul c (polynomialMap_inv c (baseInput_polynomial c j)) hu) + (baseInput_polynomial c j)) hv (RationalTailCoordinates.embed t j) + +def tailCorrection (j : Fin d) : MvPolynomial (Fin (r+j.val) ⊕ Fin (r+j.val)) ℚ := + (tailCorrection_exists c j).choose + +omit [IsTopologicalGroup G] in +lemma baseInput_args (j : Fin d) (X Y : Fin (r+d) → ℝ) : + baseInput c j (lowerArgs (j.natAdd r) X Y) = + MalcevPrefixQuotient.represent c (fun a : Fin r => Y (a.castAdd d)) := by + apply c.coord.injective + funext a + simp only [baseInput,MalcevPrefixQuotient.represent,Homeomorph.apply_symm_apply, + MalcevPrefixQuotient.lift] + split_ifs <;> rfl + +variable (K : Subgroup G) [K.Normal] +variable (hK : ∀ g : G, g ∈ K ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i = 0) + +omit [IsTopologicalGroup G] [K.Normal] in +lemma tailInput_args (j : Fin d) (X : Fin (r+d) → ℝ) (a : Fin (t+j.val)) : + tailInput j (fun u : Fin (r+j.val) => X ⟨u.val,by have := u.isLt; have := j.isLt; omega⟩) a = + c.coord (RationalTailCoordinates.rebuild c K hK (fun u : Fin d => X (u.natAdd r))).val + ⟨a.val,by have := a.isLt; have := j.isLt; omega⟩ := by + simp only [tailInput,RationalTailCoordinates.rebuild,Homeomorph.apply_symm_apply, + RationalTailCoordinates.lift] + split_ifs <;> rfl + +omit [IsTopologicalGroup G] [K.Normal] in +lemma tailCorrection_args (j : Fin d) (X Y : Fin (r+d) → ℝ) : + MvPolynomial.eval₂ (algebraMap ℚ ℝ) (lowerArgs (j.natAdd r) X Y) (tailCorrection c j) = + c.coord ( + (MalcevPrefixQuotient.represent c (fun a : Fin r => Y (a.castAdd d)))⁻¹ * + truncate c (RationalTailCoordinates.embed t j) (fun a => + c.coord (RationalTailCoordinates.rebuild c K hK (fun u : Fin d => X (u.natAdd r))).val + ⟨a.val,lt_trans a.isLt (RationalTailCoordinates.embed t j).isLt⟩) * + MalcevPrefixQuotient.represent c (fun a : Fin r => Y (a.castAdd d)) * + truncate c (RationalTailCoordinates.embed t j) (fun a => + c.coord (RationalTailCoordinates.rebuild c K hK (fun u : Fin d => Y (u.natAdd r))).val + ⟨a.val,lt_trans a.isLt (RationalTailCoordinates.embed t j).isLt⟩)) + (RationalTailCoordinates.embed t j) := by + unfold tailCorrection + rw [← (tailCorrection_exists c j).choose_spec,baseInput_args] + have hx : tailInput j (fun a => lowerArgs (j.natAdd r) X Y (.inl a)) = + (fun a : Fin (t+j.val) => c.coord + (RationalTailCoordinates.rebuild c K hK (fun u : Fin d => X (u.natAdd r))).val + ⟨a.val,by have := a.isLt; have := j.isLt; omega⟩) := by + funext a + exact tailInput_args c K hK j X a + have hy : tailInput j (fun a => lowerArgs (j.natAdd r) X Y (.inr a)) = + (fun a : Fin (t+j.val) => c.coord + (RationalTailCoordinates.rebuild c K hK (fun u : Fin d => Y (u.natAdd r))).val + ⟨a.val,by have := a.isLt; have := j.isLt; omega⟩) := by + funext a + exact tailInput_args c K hK j Y a + rw [hx,hy] + rfl + +variable (hr : r ≤ t+d) (N : Subgroup G) [N.Normal] +variable (hN : ∀ g : G, g ∈ N ↔ ∀ i : Fin (t+d), i.val < r → c.coord g i = 0) +variable (hcent : N ≤ Subgroup.center G) +variable [(diagonal K N).Normal] + +def correction (i : Fin (r+d)) : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ := + Fin.addCases (motive := fun i : Fin (r+d) => MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ) + (fun j : Fin r => c.correction (MalcevPrefixQuotient.embed hr j)) + (fun j : Fin d => tailCorrection c j) i + +omit [IsTopologicalGroup G] in +@[simp] lemma correction_base (j : Fin r) : correction c hr (j.castAdd d) = + c.correction (MalcevPrefixQuotient.embed hr j) := by + exact Fin.addCases_left (motive := fun i : Fin (r+d) => + MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ) j +omit [IsTopologicalGroup G] in +@[simp] lemma correction_tail (j : Fin d) : correction c hr (j.natAdd r) = tailCorrection c j := by + exact Fin.addCases_right (motive := fun i : Fin (r+d) => + MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ) j + +omit [N.Normal] in +lemma coordinate_mul (x y : square K ⧸ diagonal K N) (i : Fin (r+d)) : + chartHomeomorph c K hK hr N hN hcent (x*y) i = + chartHomeomorph c K hK hr N hN hcent x i + chartHomeomorph c K hK hr N hN hcent y i + + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (lowerArgs i (chartHomeomorph c K hK hr N hN hcent x) + (chartHomeomorph c K hK hr N hN hcent y)) (correction c hr i) := by + obtain ⟨X,rfl⟩ := (chartHomeomorph c K hK hr N hN hcent).symm.surjective x + obtain ⟨Y,rfl⟩ := (chartHomeomorph c K hK hr N hN hcent).symm.surjective y + simp only [Homeomorph.apply_symm_apply] + rw [chart_rebuild_base,chart_rebuild_base,← QuotientGroup.mk_mul] + refine Fin.addCases (fun j => ?_) (fun j => ?_) i + · rw [chart_base,correction_base] + change c.coord (_ * _) _ = _ + rw [c.mul_coord] + simp only [pair,MalcevPrefixQuotient.represent,Homeomorph.apply_symm_apply] + congr 1 + · simp [MalcevPrefixQuotient.lift,MalcevPrefixQuotient.embed] + · congr 1 + funext a + cases a with + | inl a => + change (if h : a.val < r then X ⟨a.val,by omega⟩ else 0) = X ⟨a.val,by have ha : a.val < j.val := a.isLt; have := j.isLt; omega⟩ + rw [dite_eq_left (lt_trans a.isLt j.isLt)] + | inr a => + change (if h : a.val < r then Y ⟨a.val,by omega⟩ else 0) = Y ⟨a.val,by have ha : a.val < j.val := a.isLt; have := j.isLt; omega⟩ + rw [dite_eq_left (lt_trans a.isLt j.isLt)] + · rw [chart_tail,correction_tail,tailCorrection_args c K hK] + let a := MalcevPrefixQuotient.represent c (fun i : Fin r => X (i.castAdd d)) + let b := MalcevPrefixQuotient.represent c (fun i : Fin r => Y (i.castAdd d)) + let u := (RationalTailCoordinates.rebuild c K hK (fun i : Fin d => X (i.natAdd r))).val + let v := (RationalTailCoordinates.rebuild c K hK (fun i : Fin d => Y (i.natAdd r))).val + change c.coord ((a*b)⁻¹*((a*u)*(b*v))) _ = _ + rw [show (a*b)⁻¹*((a*u)*(b*v)) = b⁻¹*u*b*v from by group] + rw [conj_mul_truncated] + congr 2 + · simp [u,RationalTailCoordinates.rebuild] + · simp [v,RationalTailCoordinates.rebuild] + + +def reducedCoordinates : RealCoordinates (square K ⧸ diagonal K N) (r+d) where + coord := chartHomeomorph c K hK hr N hN hcent + one_coord i := congrFun (chart_one c K hK hr N hN hcent) i + correction := correction c hr + mul_coord := coordinate_mul c K hK hr N hN hcent + +end PairTail +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + + + +def reduceCoordinates (g : G) : ℕ → G + | 0 => g + | k+1 => if h : k < n then + reduceCoordinates g k * basisFlow c ⟨k,h⟩ (-(⌊c.coord (reduceCoordinates g k) ⟨k,h⟩⌋:ℝ)) + else reduceCoordinates g k + +lemma reduceCoordinates_bounds (g : G) (k : ℕ) : + ∀ i : Fin n, i.val < k → c.coord (reduceCoordinates c g k) i ∈ Set.Ico (0:ℝ) 1 := by + induction k with + | zero => intro i hi; omega + | succ k ih => + intro i hi + by_cases hk : k < n + · rw [reduceCoordinates,dite_eq_left hk] + rw [coord_mul_of_right_zero c _ _ i (by + intro j hj + rw [basisFlow_coord c _ j (show j.val ≤ k from by change j.val < i.val at hj; omega)] + simp [show j ≠ (⟨k,hk⟩:Fin n) from fun h => by + have := congrArg Fin.val h; change j.val < i.val at hj; dsimp at this; omega])] + by_cases hik : i.val < k + · rw [basisFlow_coord c _ i (show i.val ≤ k from by omega)] + simp only [ite_eq_right (show i ≠ (⟨k,hk⟩:Fin n) from fun h => by + have := congrArg Fin.val h; dsimp at this; omega),add_zero] + exact ih i hik + · have he : i = (⟨k,hk⟩:Fin n) := Fin.ext (show i.val = k from by omega) + subst i + rw [basisFlow_coord c _ _ le_rfl,ite_eq_left rfl] + constructor + · have h := Int.floor_le (c.coord (reduceCoordinates c g k) ⟨k,hk⟩); linarith + · have h := Int.lt_floor_add_one (c.coord (reduceCoordinates c g k) ⟨k,hk⟩); linarith + · rw [reduceCoordinates,dite_eq_right hk] + exact ih i (by omega) + +variable (Γ : Subgroup G) +variable (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) +include hΓ in +lemma reduceCoordinates_coset (g : G) (k : ℕ) : (reduceCoordinates c g k)⁻¹*g ∈ Γ := by + induction k with + | zero => simp [reduceCoordinates] + | succ k ih => + simp only [reduceCoordinates] + split_ifs with hk + · rw [mul_inv_rev,mul_assoc] + apply Γ.mul_mem _ ih + apply Γ.inv_mem + rw [← Int.cast_neg] + exact basisFlow_int_mem c Γ hΓ _ _ + · exact ih + +include hΓ in + + +theorem compact_reps_of_integerCoordinates : + ∃ C : Set G, IsCompact C ∧ ∀ g : G, ∃ a ∈ C, a⁻¹*g ∈ Γ := by + let B : Set (Fin n → ℝ) := Set.pi Set.univ (fun _ => Set.Icc (0:ℝ) 1) + have hB : IsCompact B := isCompact_univ_pi (fun _ => isCompact_Icc) + refine ⟨c.coord.symm '' B,hB.image c.coord.symm.continuous,fun g => ?_⟩ + refine ⟨reduceCoordinates c g n,?_,reduceCoordinates_coset c Γ hΓ g n⟩ + refine ⟨c.coord (reduceCoordinates c g n),?_,c.coord.symm_apply_apply _⟩ + intro i _ + exact ⟨(reduceCoordinates_bounds c g n i i.isLt).1, + (reduceCoordinates_bounds c g n i i.isLt).2.le⟩ + +end RationalLattice + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail03.lean new file mode 100644 index 0000000000000000000000000000000000000000..2cc5b6bd69b010cfbc442c779191da3905b3c723 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail03.lean @@ -0,0 +1,271 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CoordinateSubspace01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +end +end + + + +section +noncomputable section +namespace PairTail +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d r : ℕ} (c : RealCoordinates G (t+d)) +variable (K : Subgroup G) [K.Normal] +variable (hK : ∀ g : G, g ∈ K ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i = 0) +variable (hr : r ≤ t+d) (N : Subgroup G) [N.Normal] +variable (hN : ∀ g : G, g ∈ N ↔ ∀ i : Fin (t+d), i.val < r → c.coord g i = 0) +variable (hcent : N ≤ Subgroup.center G) [(diagonal K N).Normal] + + +def pairLevel (A B : Subgroup G) [B.Normal] : Subgroup (square K) := + (A.comap (first K)) ⊓ (square B).comap (square K).subtype + +def reducedLevel (A B : Subgroup G) [B.Normal] : Subgroup (square K ⧸ diagonal K N) := + (pairLevel K A B).map (QuotientGroup.mk' (diagonal K N)) + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma mem_pairLevel (A B : Subgroup G) [B.Normal] (x : square K) : + x ∈ pairLevel K A B ↔ x.val.1 ∈ A ∧ x.val.1⁻¹*x.val.2 ∈ B := Iff.rfl + +variable {a b : ℕ} (ha : a ≤ r) +variable (A B : Subgroup G) [B.Normal] +variable (hA : ∀ g : G, g ∈ A ↔ ∀ i : Fin (t+d), i.val < a → c.coord g i = 0) +variable (hB : ∀ g : G, g ∈ B ↔ ∀ i : Fin (t+d), i.val < b → c.coord g i = 0) + +include ha hA hB in + + +omit [N.Normal] in +theorem reducedLevel_coordinates (x : square K ⧸ diagonal K N) : + x ∈ reducedLevel K N A B ↔ + (∀ i : Fin r, i.val < a → + (reducedCoordinates c K hK hr N hN hcent).coord x (i.castAdd d) = 0) ∧ + (∀ j : Fin d, t+j.val < b → + (reducedCoordinates c K hK hr N hN hcent).coord x (j.natAdd r) = 0) := by + constructor + · rintro ⟨y,hy,rfl⟩ + change y.val.1 ∈ A ∧ y.val.1⁻¹*y.val.2 ∈ B at hy + constructor + · intro i hi + change chartHomeomorph c K hK hr N hN hcent (QuotientGroup.mk y) _ = 0 + rw [chart_base] + exact (hA y.val.1).mp hy.1 _ hi + · intro j hj + change chartHomeomorph c K hK hr N hN hcent (QuotientGroup.mk y) _ = 0 + rw [chart_tail] + exact (hB _).mp hy.2 _ hj + · induction x using Quotient.inductionOn with | h x => + intro hx + refine ⟨x,?_,rfl⟩ + change x.val.1 ∈ A ∧ x.val.1⁻¹*x.val.2 ∈ B + constructor + · apply (hA _).mpr + intro i hi + have hir : i.val < r := lt_of_lt_of_le hi ha + have he := hx.1 ⟨i.val,hir⟩ hi + change chartHomeomorph c K hK hr N hN hcent (QuotientGroup.mk x) _ = 0 at he + rw [chart_base] at he + exact he + · apply (hB _).mpr + intro i hi + by_cases hit : i.val < t + · exact (hK _).mp x.property i hit + · have hid : i.val-t < d := by have := i.isLt; omega + have he := hx.2 ⟨i.val-t,hid⟩ (by dsimp; omega) + change chartHomeomorph c K hK hr N hN hcent (QuotientGroup.mk x) _ = 0 at he + rw [chart_tail] at he + have hiEq : RationalTailCoordinates.embed t (⟨i.val-t,hid⟩ : Fin d) = i := + Fin.ext (by dsimp [RationalTailCoordinates.embed]; omega) + simpa only [hiEq] using he + + +def levelIndices (r d t a b : ℕ) : Finset (Fin (r+d)) := + Finset.univ.filter (fun i => (i.val < r → a ≤ i.val) ∧ (r ≤ i.val → b ≤ t+(i.val-r))) + +def levelEmbedding (r d t a b : ℕ) : + Fin (levelIndices r d t a b).card ↪o Fin (r+d) := + (levelIndices r d t a b).orderEmbOfFin rfl + +lemma mem_range_levelEmbedding (i : Fin (r+d)) : + i ∈ Set.range (levelEmbedding r d t a b) ↔ + (i.val < r → a ≤ i.val) ∧ (r ≤ i.val → b ≤ t+(i.val-r)) := by + rw [levelEmbedding,Finset.range_orderEmbOfFin] + simp only [Finset.mem_coe,levelIndices,Finset.mem_filter,Finset.mem_univ,true_and] + +include ha hA hB in +omit [N.Normal] in +lemma reducedLevel_subspace (x : square K ⧸ diagonal K N) : + x ∈ reducedLevel K N A B ↔ ∀ i, + i ∉ Set.range (levelEmbedding r d t a b) → + (reducedCoordinates c K hK hr N hN hcent).coord x i = 0 := by + rw [reducedLevel_coordinates c K hK hr N hN hcent ha A B hA hB] + constructor + · rintro ⟨hbase,htail⟩ i hi + rw [mem_range_levelEmbedding] at hi + by_cases hir : i.val < r + · have hia : i.val < a := by omega + exact hbase ⟨i.val,hir⟩ hia + · have hid : i.val-r < d := by have := i.isLt; omega + have hib : t+(i.val-r) < b := by omega + have hiEq : Fin.natAdd r (⟨i.val-r,hid⟩ : Fin d) = i := Fin.ext (by dsimp; omega) + simpa only [hiEq] using htail ⟨i.val-r,hid⟩ hib + · intro hx + constructor + · intro i hi + apply hx + rw [mem_range_levelEmbedding] + simp only [Fin.val_castAdd] + omega + · intro j hj + apply hx + rw [mem_range_levelEmbedding] + simp only [Fin.val_natAdd] + omega + + + +def reducedLevelCoordinates : RealCoordinates (reducedLevel K N A B) + (levelIndices r d t a b).card := + CoordinateSubspace.restrictedCoordinates + (reducedCoordinates c K hK hr N hN hcent) (levelEmbedding r d t a b) + (reducedLevel K N A B) (reducedLevel_subspace c K hK hr N hN hcent ha A B hA hB) + +omit [N.Normal] in +lemma reducedLevel_lattice (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) + (x : reducedLevel K N A B) : + x ∈ (reducedLattice K N Γ).comap (reducedLevel K N A B).subtype ↔ + ∀ i, ∃ z : ℤ, (reducedLevelCoordinates c K hK hr N hN hcent ha A B hA hB).coord x i = z := + CoordinateSubspace.restricted_lattice _ _ _ _ (reducedLattice K N Γ) + (reducedLattice_iff c K hK hr N hN hcent Γ hΓ) x + +end PairTail +end +end + + + +section +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +include c in +lemma coordinates_connected : ConnectedSpace G := + c.coord.connectedSpace_iff.mpr inferInstance + +include c in +lemma coordinates_simplyConnected : SimplyConnectedSpace G := + c.coord.toHomotopyEquiv.simplyConnectedSpace_iff.mpr inferInstance + +include c in +lemma coordinates_locallyCompact : LocallyCompactSpace G := + c.coord.locallyCompactSpace_iff.mpr inferInstance + +include c in +lemma coordinates_secondCountable : SecondCountableTopology G := + c.coord.secondCountableTopology + +end RationalLattice + +namespace PairTail +open RationalLattice MeasureTheory +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d r : ℕ} (c : RealCoordinates G (t+d)) +variable (K : Subgroup G) [K.Normal] +variable (hK : ∀ g : G, g ∈ K ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i = 0) +variable (hr : r ≤ t+d) (N : Subgroup G) [N.Normal] +variable (hN : ∀ g : G, g ∈ N ↔ ∀ i : Fin (t+d), i.val < r → c.coord g i = 0) +variable (hcent : N ≤ Subgroup.center G) [(diagonal K N).Normal] +variable {a b : ℕ} (ha : a ≤ r) +variable (A B : Subgroup G) [B.Normal] +variable (hA : ∀ g : G, g ∈ A ↔ ∀ i : Fin (t+d), i.val < a → c.coord g i = 0) +variable (hB : ∀ g : G, g ∈ B ↔ ∀ i : Fin (t+d), i.val < b → c.coord g i = 0) + +include ha hA hB hK hN hcent hr in +omit [N.Normal] in +lemma reducedLevel_connected : ConnectedSpace (reducedLevel K N A B) := + coordinates_connected (reducedLevelCoordinates c K hK hr N hN hcent ha A B hA hB) + +include ha hA hB hK hN hcent hr in +omit [N.Normal] in +lemma reducedLevel_simplyConnected : SimplyConnectedSpace (reducedLevel K N A B) := + coordinates_simplyConnected (reducedLevelCoordinates c K hK hr N hN hcent ha A B hA hB) + +variable (Γ : Subgroup G) +variable (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) + +include ha hA hB hK hN hcent hr hΓ in +omit [N.Normal] in +lemma reducedLevel_compact_reps : + ∃ C : Set (reducedLevel K N A B), IsCompact C ∧ ∀ g : reducedLevel K N A B, + ∃ x ∈ C, x⁻¹*g ∈ (reducedLattice K N Γ).comap (reducedLevel K N A B).subtype := + compact_reps_of_integerCoordinates + (reducedLevelCoordinates c K hK hr N hN hcent ha A B hA hB) + ((reducedLattice K N Γ).comap (reducedLevel K N A B).subtype) + (reducedLevel_lattice c K hK hr N hN hcent ha A B hA hB Γ hΓ) + +include ha hA hB hK hN hcent hr hΓ in +omit [N.Normal] in +lemma reducedLevel_discrete : + DiscreteTopology ((reducedLattice K N Γ).comap (reducedLevel K N A B).subtype) := + integerCoordinates_discrete + (reducedLevelCoordinates c K hK hr N hN hcent ha A B hA hB) + ((reducedLattice K N Γ).comap (reducedLevel K N A B).subtype) + (reducedLevel_lattice c K hK hr N hN hcent ha A B hA hB Γ hΓ) + +include ha hA hB hK hN hcent hr hΓ in + + +omit [N.Normal] in +lemma reducedLevelHaar_existsUnique + [MeasurableSpace ((reducedLevel K N A B) ⧸ + (reducedLattice K N Γ).comap (reducedLevel K N A B).subtype)] + [BorelSpace ((reducedLevel K N A B) ⧸ + (reducedLattice K N Γ).comap (reducedLevel K N A B).subtype)] : + ∃! μ : ProbabilityMeasure ((reducedLevel K N A B) ⧸ + (reducedLattice K N Γ).comap (reducedLevel K N A B).subtype), + SMulInvariantMeasure (reducedLevel K N A B) + ((reducedLevel K N A B) ⧸ + (reducedLattice K N Γ).comap (reducedLevel K N A B).subtype) + (μ : Measure ((reducedLevel K N A B) ⧸ + (reducedLattice K N Γ).comap (reducedLevel K N A B).subtype)) := + existsUnique_coordinateHaar + (reducedLevelCoordinates c K hK hr N hN hcent ha A B hA hB) + ((reducedLattice K N Γ).comap (reducedLevel K N A B).subtype) + (reducedLevel_lattice c K hK hr N hN hcent ha A B hA hB Γ hΓ) + +end PairTail +end +end + + + +section + + + +open scoped commutatorElement + +namespace CubeFaces + + +end CubeFaces + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail04.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail04.lean new file mode 100644 index 0000000000000000000000000000000000000000..0972254997f15ea548fdfaa5b9f5442df070c657 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail04.lean @@ -0,0 +1,302 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevWeighted02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +end +end + + + +section +noncomputable section +open scoped commutatorElement +namespace PairTail +open RationalLattice CubeFaces +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ k : ℕ, (H.level k).Normal] + + + +def squareFiltration : Filtration (square (H.level 2)) where + level k := (LeibmanSquare.level H h0 (max 1 k)).comap (square (H.level 2)).subtype + antitone := by + intro i j hij + exact Subgroup.comap_mono (LeibmanSquare.level_antitone H h0 (max_le_max_left 1 hij)) + commutator_le i j := by + apply Subgroup.commutator_le.mpr + intro x hx y hy + change (↑⁅x,y⁆ : G × G)∈LeibmanSquare.level H h0 (max 1 (i+j)) + have hc := LeibmanSquare.commutator_mem_level H h0 (max 1 i) (max 1 j) hx hy + exact LeibmanSquare.level_antitone H h0 (by omega) hc + +include h1 in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma squareFiltration_zero : (squareFiltration H h0).level 0=⊤ := by + ext x + change (x.val.1∈H.level 1 ∧ x.val.2∈H.level 1 ∧ + x.val.1⁻¹*x.val.2∈H.level 2) ↔ True + simp only [h1,Subgroup.mem_top,true_and,iff_true] + exact x.property + +include h1 in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma squareFiltration_one : (squareFiltration H h0).level 1=⊤ := by + change (squareFiltration H h0).level 0=⊤ + exact squareFiltration_zero H h0 h1 + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma squareFiltration_eq_pairLevel (k : ℕ) : + (squareFiltration H h0).level k= + pairLevel (H.level 2) (H.level (max 1 k)) (H.level (max 1 k+1)) := by + ext x + change (x.val.1∈H.level (max 1 k) ∧ x.val.2∈H.level (max 1 k) ∧ + x.val.1⁻¹*x.val.2∈H.level (max 1 k+1)) ↔ + (x.val.1∈H.level (max 1 k) ∧ x.val.1⁻¹*x.val.2∈H.level (max 1 k+1)) + constructor + · exact fun hx => ⟨hx.1,hx.2.2⟩ + · rintro ⟨hx,hd⟩ + refine ⟨hx,?_,hd⟩ + have hh := (H.level (max 1 k)).mul_mem hx (H.antitone (by omega : max 1 k ≤ max 1 k+1) hd) + simpa using hh + +variable (s : ℕ) (hs1 : 1 ≤ s) (hs : H.level (s+1)=⊥) +include hs1 hs in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma squareFiltration_last : (squareFiltration H h0).level s=diagonal (H.level 2) (H.level s) := by + ext x + change x.val∈LeibmanSquare.level H h0 (max 1 s) ↔ _ + rw [max_eq_right hs1,LeibmanSquare.last_level H h0 s hs] + change (x.val.1∈H.level s ∧ x.val.1=x.val.2) ↔ (x.val.1∈H.level s ∧ x.val.2=x.val.1) + exact and_congr_right fun _ => eq_comm + +include h1 hs in +omit [TopologicalSpace G] [IsTopologicalGroup G] [∀ levelIndex : ℕ, (H.level levelIndex).Normal] in +lemma level_last_central : H.level s ≤ Subgroup.center G := by + intro x hx + apply Subgroup.mem_center_iff.mpr + intro y + apply commutatorElement_eq_one_iff_mul_comm.mp + have hy : y∈H.level 1 := by rw [h1]; trivial + have hh := H.commutator_le 1 s (Subgroup.commutator_mem_commutator hy hx) + rw [Nat.add_comm,hs] at hh + exact hh + +variable [(diagonal (H.level 2) (H.level s)).Normal] + + +def reducedSquareFiltration : Filtration (square (H.level 2) ⧸ diagonal (H.level 2) (H.level s)) := + LeibmanSquare.mapFiltration (squareFiltration H h0) + (QuotientGroup.mk' (diagonal (H.level 2) (H.level s))) + +include h1 in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma reducedSquareFiltration_zero : (reducedSquareFiltration H h0 s).level 0=⊤ := by + change ((squareFiltration H h0).level 0).map _=⊤ + rw [squareFiltration_zero H h0 h1,Subgroup.map_top_of_surjective _ (QuotientGroup.mk'_surjective _)] + +include h1 in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma reducedSquareFiltration_one : (reducedSquareFiltration H h0 s).level 1=⊤ := by + change ((squareFiltration H h0).level 1).map _=⊤ + rw [squareFiltration_one H h0 h1,Subgroup.map_top_of_surjective _ (QuotientGroup.mk'_surjective _)] + +include hs1 hs in +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma reducedSquareFiltration_last : (reducedSquareFiltration H h0 s).level s=⊥ := by + change ((squareFiltration H h0).level s).map _=⊥ + rw [squareFiltration_last H h0 s hs1 hs,Subgroup.map_eq_bot_iff,QuotientGroup.ker_mk'] + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma reducedSquareFiltration_level (k : ℕ) : + (reducedSquareFiltration H h0 s).level k= + reducedLevel (H.level 2) (H.level s) (H.level (max 1 k)) (H.level (max 1 k+1)) := by + change ((squareFiltration H h0).level k).map _=_ + rw [squareFiltration_eq_pairLevel] + rfl + +end PairTail +end +end + + + +section +noncomputable section +namespace PairTail +open RationalLattice MalcevCharacters MalcevWeightedCoordinates CubeFaces +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + +omit [IsTopologicalGroup G] in +lemma filtration_cutoff_monotone {n : ℕ} (c : RealCoordinates G n) + (H : Filtration G) (q : ℕ → ℕ) (hqbound : ∀ k, q k ≤ n) + (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin n, i.val < q k → c.coord g i=0) : + Monotone q := by + classical + intro a b hab + by_contra hn + have hba : q b < q a := Nat.lt_of_not_ge hn + let i : Fin n := ⟨q b,lt_of_lt_of_le hba (hqbound a)⟩ + have hm : axis c i 1∈H.level b := by + apply (hq b _).mpr + intro j hj + have hji : j≠i := by intro he; subst j; exact (lt_irrefl _ hj) + simp [hji] + have hz := (hq a _).mp (H.antitone hab hm) i hba + simp at hz + +variable {t d : ℕ} (c : RealCoordinates G (t+d)) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ k : ℕ, (H.level k).Normal] +variable (s : ℕ) (hs1 : 1 ≤ s) (hs : H.level (s+1)=⊥) +variable [(diagonal (H.level 2) (H.level s)).Normal] +variable (q : ℕ → ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i=0) + +include hq hq2 in +omit [IsTopologicalGroup G] [∀ levelIndex : ℕ, (H.level levelIndex).Normal] in +lemma square_tail_equation (g : G) : + g∈H.level 2 ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := by + rw [hq,hq2] + +include h1 hs1 hs hqbound hq2 hq in + + +theorem exists_adapted_reducedCoordinates (Γ : Subgroup G) + (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) : + ∃ c' : RealCoordinates (square (H.level 2) ⧸ diagonal (H.level 2) (H.level s)) (q s+d), + SecondKind c' ∧ + (∀ g, g∈reducedLattice (H.level 2) (H.level s) Γ ↔ ∀ i, ∃ z : ℤ, c'.coord g i=z) ∧ + ∀ k : ℕ, ∃ r : ℕ, r ≤ q s+d ∧ ∀ g, + g∈(reducedSquareFiltration H h0 s).level k ↔ + ∀ i : Fin (q s+d), i.val < r → c'.coord g i=0 := by + classical + have hK := square_tail_equation c H q hq2 hq + have hcent := level_last_central H h1 s hs + let cR := reducedCoordinates c (H.level 2) hK (hqbound s) (H.level s) (hq s) hcent + let Q:=reducedSquareFiltration H h0 s + have hQ0 : Q.level 0=⊤ := reducedSquareFiltration_zero H h0 h1 s + have hQ1 : Q.level 1=⊤ := reducedSquareFiltration_one H h0 h1 s + have hQs : Q.level s=⊥ := reducedSquareFiltration_last H h0 s hs1 hs + have hQdeg : Q.level (s+1)=⊥ := le_antisymm (by + rw [← hQs] + exact Q.antitone (by omega)) bot_le + have hsub : ∀ k : ℕ, ∃ I : Set (Fin (q s+d)), ∀ x, + x∈Q.level k ↔ ∀ i∈I, cR.coord x i=0 := by + intro k + by_cases hk : k < s + · have hks : max 1 k ≤ s := by omega + have ha : q (max 1 k) ≤ q s := filtration_cutoff_monotone c H q hqbound hq hks + refine ⟨(Set.range (levelEmbedding (q s) d t (q (max 1 k)) (q (max 1 k+1))))ᶜ,?_⟩ + intro x + change x∈(reducedSquareFiltration H h0 s).level k ↔ _ + rw [reducedSquareFiltration_level] + exact reducedLevel_subspace c (H.level 2) hK (hqbound s) (H.level s) (hq s) + hcent ha (H.level (max 1 k)) (H.level (max 1 k+1)) (hq (max 1 k)) (hq (max 1 k+1)) x + · have hbot : Q.level k=⊥ := le_antisymm (by + rw [← hQs] + exact Q.antitone (by omega)) bot_le + refine ⟨Set.univ,?_⟩ + intro x + rw [hbot,Subgroup.mem_bot] + constructor + · intro hx i _ + rw [hx] + exact cR.one_coord i + · intro hx + apply cR.coord.injective + funext i + rw [hx i (Set.mem_univ i),cR.one_coord] + apply exists_adapted_secondKind_coordinates cR Q hQ0 hQ1 s hQdeg hsub + exact reducedLattice_iff c (H.level 2) hK (hqbound s) (H.level s) (hq s) hcent Γ hΓ + +end PairTail +end +end + + + +section +noncomputable section +namespace RationalLattice +open MalcevCharacters +variable {G K : Type*} [Group G] [Group K] [TopologicalSpace G] [TopologicalSpace K] + [IsTopologicalGroup G] [IsTopologicalGroup K] {n : ℕ} +variable (c : RealCoordinates K n) (e : G ≃* K) + (hc : Continuous e) (hci : Continuous e.symm) + +omit [IsTopologicalGroup G] [IsTopologicalGroup K] in +@[simp] lemma pullCoordinates_axis (i : Fin n) (t : ℝ) : + e (axis (pullCoordinates c e hc hci) i t)=axis c i t := by + change e (e.symm (c.coord.symm (Pi.single i t)))=c.coord.symm (Pi.single i t) + exact e.apply_symm_apply _ + +omit [IsTopologicalGroup G] [IsTopologicalGroup K] in +lemma pullCoordinates_secondKind (hsk : SecondKind c) : + SecondKind (pullCoordinates c e hc hci) where + axis_add i s t := by + apply e.injective + simp only [map_mul,pullCoordinates_axis,hsk.axis_add] + ordered g := by + apply e.injective + rw [map_list_prod,List.map_ofFn] + simp only [Function.comp_def,pullCoordinates_axis] + exact hsk.ordered (e g) +end RationalLattice + +namespace LeibmanSquare +open CubeFaces RationalLattice MalcevCharacters PairTail +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (s : ℕ) (hs0 : 1 ≤ s) (hs : H.level (s+1)=⊥) +variable [((restricted H h0).level s).Normal] +variable [(PairTail.diagonal (H.level 2) (H.level s)).Normal] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) +variable (q : ℕ → ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i=0) + +include h1 hs0 hs hqbound hq2 hq in + + +theorem exists_adapted_sourceReducedCoordinates (Γ : Subgroup G) + (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) : + ∃ c' : RealCoordinates ((level H h0 1) ⧸ (restricted H h0).level s) (q s+d), + SecondKind c' ∧ + (∀ g, g∈((Γ.prod Γ).comap (level H h0 1).subtype).map + (QuotientGroup.mk' ((restricted H h0).level s)) ↔ ∀ i, ∃ z : ℤ, c'.coord g i=z) ∧ + ∀ k : ℕ, ∃ r : ℕ, r ≤ q s+d ∧ ∀ g, + g∈(mapFiltration (restricted H h0) (QuotientGroup.mk' ((restricted H h0).level s))).level k ↔ + ∀ i : Fin (q s+d), i.val < r → c'.coord g i=0 := by + obtain ⟨cR,hsk,hRL,hRF⟩ := exists_adapted_reducedCoordinates c H h0 h1 s hs0 hs q hqbound hq2 hq Γ hΓ + let e:=reducedPairEquiv H h0 h1 s hs0 hs + have hc : Continuous e := reducedPairEquiv_continuous H h0 h1 s hs0 hs + have hci : Continuous e.symm := reducedPairEquiv_symm_continuous H h0 h1 s hs0 hs + refine ⟨pullCoordinates cR e hc hci,pullCoordinates_secondKind cR e hc hci hsk,?_,?_⟩ + · intro g + change g∈_ ↔ ∀ i, ∃ z : ℤ, cR.coord (e g) i=z + rw [← hRL,← reducedLattice_map H h0 h1 s hs0 hs Γ] + simp only [Subgroup.mem_map_equiv,e,MulEquiv.symm_apply_apply] + · intro k + obtain ⟨r,hr,hrg⟩ := hRF k + refine ⟨r,hr,fun g => ?_⟩ + change g∈((restricted H h0).level k).map _ ↔ ∀ i : Fin (q s+d), i.val < r → cR.coord (e g) i=0 + rw [← hrg,PairTail.reducedSquareFiltration_level,← reducedLevel_map H h0 h1 s hs0 hs k] + simp only [Subgroup.mem_map_equiv,e,MulEquiv.symm_apply_apply] + +end LeibmanSquare + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail05.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail05.lean new file mode 100644 index 0000000000000000000000000000000000000000..243ff9d26e98936a6d3d8cd9d66b17a2990a8b67 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail05.lean @@ -0,0 +1,342 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CompactFamily01 +import OAI.Combinatorics.SumProduct.Alignment.CoordinateSubspace01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped commutatorElement Pointwise +namespace SquareInduction +open MeasureTheory +open scoped BigOperators +noncomputable section +section Probability +variable {X : Type*} [TopologicalSpace X] [CompactSpace X] + [MeasurableSpace X] [BorelSpace X] (μ : Measure X) [IsProbabilityMeasure μ] + + + +def discrepancy (N : ℕ) (x : ℕ → X) : C(X, ℂ) →ₗ[ℂ] ℂ where + toFun f := (𝔼 n ∈ Finset.range N, f (x n)) - ∫ t, f t ∂μ + map_add' f g := by + change (𝔼 n ∈ Finset.range N, (f (x n) + g (x n))) - + ∫ t, f t + g t ∂μ = _ + rw [Finset.expect_add_distrib, integral_add + (f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace f)) + (g.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace g))] + ring + map_smul' z f := by + change (𝔼 n ∈ Finset.range N, z • f (x n)) - ∫ t, z • f t ∂μ = _ + rw [← Finset.smul_expect, integral_smul] + simp only [RingHom.id_apply, smul_sub] + +theorem discrepancy_bound (N : ℕ) (hN : 0 < N) (x : ℕ → X) (f : C(X, ℂ)) : + ‖discrepancy μ N x f‖ ≤ 2 * ‖f‖ := by + have hm : ‖𝔼 n ∈ Finset.range N, f (x n)‖ ≤ ‖f‖ := + (RCLike.norm_expect_le (K := ℂ)).trans (Finset.expect_le + (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)) (fun n _ => f.norm_coe_le_norm _)) + have hi : ‖∫ t, f t ∂μ‖ ≤ ‖f‖ := by + simpa only [probReal_univ, mul_one] using norm_integral_le_of_norm_le_const (μ := μ) + (Filter.Eventually.of_forall (f.norm_coe_le_norm)) + exact (norm_sub_le _ _).trans (by linarith only [hm, hi]) + +theorem discrepancy_const (N : ℕ) (hN : 0 < N) (x : ℕ → X) (z : ℂ) : + discrepancy μ N x (ContinuousMap.const _ z) = 0 := by + simp only [discrepancy, LinearMap.coe_mk, AddHom.coe_mk, ContinuousMap.const_apply, + Finset.expect_const (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)), + integral_const, probReal_univ, one_smul, sub_self] +end Probability +end +end SquareInduction + +namespace SquareInduction +open CubeFaces LeibmanSquare PolynomialWeyl UniformSquareObservable +open CompactFamilyDescent MeasureTheory Topology +open scoped BigOperators ComplexConjugate +noncomputable section +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + + +theorem uniform_dense_square_descent_tracked + (H : Filtration G) (h0 : H.level 0 = ⊤) (h1 : H.level 1 = ⊤) + (Γ : Subgroup G) (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1) = ⊥) + [TopologicalSpace.MetrizableSpace (ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs)] + [CompactSpace (ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs)] + (F : C(G ⧸ Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (χ : G → ℂ) + (hχ : ∀ n ∈ H.level s, ‖χ n‖ = 1) + (hw : ∀ n ∈ H.level s, ∀ x : G, + F (QuotientGroup.mk (x*n)) = χ n * F (QuotientGroup.mk x)) + (z : G) (hz : z ∈ H.level s) (hχz : χ z ≠ 1) + (C : Set G) (hCc : IsCompact C) (hC : ∀ g : G, ∃ c ∈ C, c⁻¹*g ∈ Γ) + (δ : ℝ) (hδ : 0 < δ) : + let R := restricted H h0 + letI := last_normal H h0 (by omega : 1 ≤ s) hs + let π := QuotientGroup.mk' (R.level s) + let Q := mapFiltration R π + let X := ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs + letI := TopologicalSpace.metrizableSpaceMetric X + letI : MeasurableSpace X := borel X + ∃ tests : Finset {Ψ : C(X,ℂ) // Ψ ∈ lipschitzMaps (Y := X)}, + ∃ η : ℝ, 0 < η ∧ + ∀ μ : Measure X, IsProbabilityMeasure μ → + SMulInvariantMeasure ((level H h0 1) ⧸ R.level s) X μ → + ∀ (f : ℤ → G), Polynomial H 0 f → + ∀ N T : ℕ, 0 < N → 0 < T → + δ ≤ ‖mean N (fun n => F (QuotientGroup.mk (f n)))‖ → + 4 * (T : ℝ) / N ≤ δ^2/2 → + ∃ b ∈ Finset.range T, ∃ A : Finset ℕ, + (∀ a ∈ A, a < T) ∧ δ^2/4*T ≤ (A.card : ℝ) ∧ + ∀ a ∈ A, ∃ Ψ ∈ tests, ∃ p : ℤ → (level H h0 1) ⧸ R.level s, + ∃ u ∈ C, ∃ v ∈ C, ∃ γ ∈ Γ, ∃ ε ∈ Γ, + f a = u*γ ∧ f b = v*ε ∧ + (∀ n : ℤ, ∃ x : level H h0 1, p n = π x ∧ + x.val = (u⁻¹*f (n+a)*γ⁻¹, v⁻¹*f (n+b)*ε⁻¹)) ∧ + Polynomial Q 0 p ∧ + (∀ ts : List ℤ, s ≤ ts.length → ∀ n, iterDiff ts p n = 1) ∧ + η ≤ ‖mean N (fun n => Ψ.val (QuotientGroup.mk (p n))) - + ∫ x, Ψ.val x ∂μ‖ := by + classical + let R := restricted H h0 + let := last_normal H h0 (by omega : 1 ≤ s) hs + let π := QuotientGroup.mk' (R.level s) + let X := ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs + let := TopologicalSpace.metrizableSpaceMetric X + let : MeasurableSpace X := borel X + let : BorelSpace X := ⟨rfl⟩ + obtain ⟨tests,η,hη,htests⟩ := finite_square_tests H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs F χ hχ hw + C hCc (δ^2/4) 2 (by positivity) (by norm_num) + refine ⟨tests,η,hη,?_⟩ + intro μ hprob hinv f hf N T hN hT hlarge hboundary + let := hprob + obtain ⟨b,hb,A,hAT,hAc,hAd⟩ := dense_reduced_square_orbits_tracked H h0 h1 Γ F hF s hs2 hs + χ hχ hw C hC f hf N T hN hT δ hδ hlarge hboundary + refine ⟨b,hb,A,hAT,hAc,?_⟩ + intro a ha + obtain ⟨u,hu,v,hv,Φ,p,γ,hγ,ε,hε,hfa,hfb,hlift,hΦbound,hΦ,hp,hptop,heval,hcorr⟩ := hAd a ha + have heq : Φ = observable H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs F χ hχ hw (u,v) := by + ext x + induction x using Quotient.inductionOn with | h y => + induction y using Quotient.inductionOn with | h w => + exact hΦ w + have hzero : (∫ x, Φ x ∂μ) = 0 := + reduced_observable_mean_zero H h0 h1 Γ F u v s hs2 hs χ hw z hz hχz μ hinv Φ hΦ + let L : C(X,ℂ) →ₗ[ℂ] ℂ := discrepancy μ N (fun n => QuotientGroup.mk (p n)) + have hL : ∀ Ψ, ‖L Ψ‖ ≤ 2 * ‖Ψ‖ := discrepancy_bound μ N hN _ + have hcorr' : δ^2/4 ≤ ‖L (observable H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs F χ hχ hw (u,v))‖ := by + rw [← heq] + change δ^2/4 ≤ ‖mean N (fun n => Φ (QuotientGroup.mk (p n))) - ∫ x, Φ x ∂μ‖ + simpa only [hzero,sub_zero] using hcorr + obtain ⟨Ψ,hΨ,hΨcorr⟩ := htests L hL ⟨u,hu,v,hv,hcorr'⟩ + exact ⟨Ψ,hΨ,p,u,hu,v,hv,γ,hγ,ε,hε,hfa,hfb,hlift,hp,hptop,hΨcorr⟩ + +end +end SquareInduction + +end + + + +section +noncomputable section +open scoped BigOperators ComplexConjugate +namespace SquareDifferences +open PolynomialWeyl + +lemma norm_mean_derivative_swap (N a b : ℕ) (f : ℕ → ℂ) : + ‖mean N (derivative a b f)‖=‖mean N (derivative b a f)‖ := by + have he : mean N (derivative a b f)=conj (mean N (derivative b a f)) := by + simp only [mean,derivative,map_expect (starRingEnd ℂ),map_mul,starRingEnd_self_apply] + apply Finset.expect_congr rfl + intro n _ + ring + rw [he,RCLike.norm_conj] + +lemma derivative_shift_error {N : ℕ} (hN : 0 derivative (a-b) 0 f (n+b) := by + funext n + simp only [derivative,Nat.add_zero] + congr 2 + omega + have ht := norm_mean_shift_sub_le hN b (derivative (a-b) 0 f) + (norm_derivative_le_one (a-b) 0 f hf) + rw [←he] at ht + have hn := norm_sub_norm_le (mean N (derivative a b f)) (mean N (derivative (a-b) 0 f)) + linarith + +lemma nat_dist_image_card (S : Finset ℕ) (b : ℕ) : + S.card ≤ 2*(S.image (fun a => Nat.dist a b)).card := by + classical + let A := S.image (fun a => Nat.dist a b) + have hc := Finset.card_le_card_of_injOn (s:=S) (t:=A.product (Finset.univ : Finset Bool)) + (fun a => (Nat.dist a b,decide (b≤a))) (by + intro a ha + exact Finset.mem_product.mpr ⟨Finset.mem_image.mpr ⟨a,ha,rfl⟩,Finset.mem_univ _⟩) (by + intro a ha c hc he + have h1 := congrArg Prod.fst he + have h2 := congrArg Prod.snd he + have h3 : (b≤a) ↔ b≤c := by simpa only [Prod.snd,decide_eq_decide] using h2 + simp only [Nat.dist] at h1 + omega) + simpa only [Finset.product_eq_sprod,Finset.card_product,Finset.card_univ,Fintype.card_bool,Nat.mul_comm,A] using hc + + + +theorem exists_dense_one_sided {N T : ℕ} (hN : 0 Nat.dist a b),?_,?_,?_⟩ + · intro h hh + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hh + have haT := hST a ha + simp only [Nat.dist] + omega + · have hc := nat_dist_image_card S b + have hc' : (S.card:ℝ)≤2*((S.image (fun a => Nat.dist a b)).card:ℝ) := by exact_mod_cast hc + linarith + · intro h hh + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hh + have hsmall : ∀ k : ℕ, k simp [pair] + map_mul' g h := by apply Subtype.ext; ext <;> simp [pair] +def lowerEmbedding : K →* square K where + toFun u := pair K 1 u + map_one' := by apply Subtype.ext; ext <;> simp [pair] + map_mul' g h := by apply Subtype.ext; ext <;> simp [pair] +lemma diagonalEmbedding_continuous : Continuous (diagonalEmbedding K) := + (pair_continuous K).comp (continuous_id.prodMk continuous_const) +lemma lowerEmbedding_continuous : Continuous (lowerEmbedding K) := + (pair_continuous K).comp (continuous_const.prodMk continuous_id) +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma pair_decompose [TopologicalSpace G] [IsTopologicalGroup G] (g : G) (u : K) : + pair K g u = diagonalEmbedding K g * lowerEmbedding K u := by + apply Subtype.ext + ext <;> simp [pair,diagonalEmbedding,lowerEmbedding] + +variable (η : square K →* Multiplicative ℝ) +def baseCharacter : G →* Multiplicative ℝ := η.comp (diagonalEmbedding K) +def lowerCharacter : K →* Multiplicative ℝ := η.comp (lowerEmbedding K) +lemma baseCharacter_continuous (hη : Continuous η) : Continuous (baseCharacter K η) := + hη.comp (diagonalEmbedding_continuous K) +lemma lowerCharacter_continuous (hη : Continuous η) : Continuous (lowerCharacter K η) := + hη.comp (lowerEmbedding_continuous K) + + +lemma character_split (x : square K) : + Multiplicative.toAdd (η x) = Multiplicative.toAdd (baseCharacter K η x.val.1) + + Multiplicative.toAdd (lowerCharacter K η (difference K x)) := by + conv_lhs => rw [← pair_first_difference K x,pair_decompose,map_mul] + rfl + +lemma character_nonzero (hη : η ≠ 1) : baseCharacter K η ≠ 1 ∨ lowerCharacter K η ≠ 1 := by + by_contra h + push Not at h + apply hη + ext x + apply Multiplicative.toAdd.injective + rw [character_split,h.1,h.2] + simp + + + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma lowerCharacter_conj [TopologicalSpace G] [IsTopologicalGroup G] (g : G) (u : K) : + lowerCharacter K η ⟨g*u*g⁻¹,(inferInstance : K.Normal).conj_mem _ u.property g⟩ = + lowerCharacter K η u := by + have he : lowerEmbedding K ⟨g*u*g⁻¹,(inferInstance : K.Normal).conj_mem _ u.property g⟩ = + diagonalEmbedding K g * lowerEmbedding K u * (diagonalEmbedding K g)⁻¹ := by + apply Subtype.ext + ext <;> simp [pair,diagonalEmbedding,lowerEmbedding,mul_assoc] + change η _ = η _ + rw [he,map_mul,map_mul,map_inv] + simp [mul_assoc] + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma lower_commutator_mem [TopologicalSpace G] [IsTopologicalGroup G] + (g : G) (u : K) : ⁅g,u.val⁆ ∈ K := + K.mul_mem ((inferInstance : K.Normal).conj_mem _ u.property g) (K.inv_mem u.property) + +lemma lowerCharacter_commutator (g : G) (u : K) : + lowerCharacter K η ⟨⁅g,u.val⁆,lower_commutator_mem K g u⟩ = 1 := by + let v : K := ⟨g*u*g⁻¹,(inferInstance : K.Normal).conj_mem _ u.property g⟩ + have he : (⟨⁅g,u.val⁆,lower_commutator_mem K g u⟩ : K) = v*u⁻¹ := by + apply Subtype.ext + rfl + rw [he,map_mul,map_inv,lowerCharacter_conj] + exact mul_inv_cancel _ + +variable (Γ : Subgroup G) +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma baseCharacter_integral [TopologicalSpace G] [IsTopologicalGroup G] + (hη : ∀ x ∈ squareLattice K Γ, ∃ z : ℤ, Multiplicative.toAdd (η x) = z) : + ∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (baseCharacter K η g) = z := by + intro g hg + apply hη (diagonalEmbedding K g) + simpa [diagonalEmbedding,pair] using And.intro hg hg +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma lowerCharacter_integral [TopologicalSpace G] [IsTopologicalGroup G] + (hη : ∀ x ∈ squareLattice K Γ, ∃ z : ℤ, Multiplicative.toAdd (η x) = z) : + ∀ u : K, u.val ∈ Γ → ∃ z : ℤ, Multiplicative.toAdd (lowerCharacter K η u) = z := by + intro u hu + apply hη (lowerEmbedding K u) + simpa [lowerEmbedding,pair] using And.intro Γ.one_mem hu + +end PairTail + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail06.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail06.lean new file mode 100644 index 0000000000000000000000000000000000000000..05cdf90e0e866dbea15ccd2022a1fa28fcc504ae --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PairTail06.lean @@ -0,0 +1,369 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.LeibmanSquare02 +import OAI.Combinatorics.SumProduct.Alignment.LeibmanSquare03 +import OAI.Combinatorics.SumProduct.Alignment.PairTail05 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped commutatorElement +noncomputable section +end +end + + + +section +open scoped commutatorElement BigOperators +noncomputable section +namespace PairTail +open RationalLattice MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (K : Subgroup G) [K.Normal] +variable (η : square K →* Multiplicative ℝ) +variable (hcomm : ∀ a b : G, ⁅a,b⁆ ∈ K) + +def bracket (a b : G) : K := ⟨⁅a,b⁆,hcomm a b⟩ + +def bracketCharacter (a : G) : G →* Multiplicative ℝ where + toFun b := lowerCharacter K η (bracket K hcomm a b) + map_one' := by + have he : bracket K hcomm a 1 = 1 := by apply Subtype.ext; simp [bracket] + rw [he,map_one] + map_mul' b c := by + have he : bracket K hcomm a (b*c) = bracket K hcomm a b * + ⟨b*(bracket K hcomm a c).val*b⁻¹, + (inferInstance : K.Normal).conj_mem _ (bracket K hcomm a c).property b⟩ := by + apply Subtype.ext + change ⁅a,b*c⁆ = ⁅a,b⁆ * (b*⁅a,c⁆*b⁻¹) + rw [commutatorElement_mul_right_eq_mul_conj] + group + rw [he,map_mul,lowerCharacter_conj] + +lemma bracketCharacter_continuous (hη : Continuous η) (a : G) : + Continuous (bracketCharacter K η hcomm a) := by + apply (lowerCharacter_continuous K η hη).comp + apply Continuous.subtype_mk + exact ((continuous_const.mul continuous_id).mul continuous_const).mul continuous_inv + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma bracket_skew (a b : G) : + lowerCharacter K η (bracket K hcomm b a) = + (lowerCharacter K η (bracket K hcomm a b))⁻¹ := by + have he : bracket K hcomm b a = (bracket K hcomm a b)⁻¹ := by + apply Subtype.ext + exact (commutatorElement_inv a b).symm + rw [he,map_inv] + + + +def leftBracketCharacter (b : G) : G →* Multiplicative ℝ := + (bracketCharacter K η hcomm b)⁻¹ +lemma leftBracketCharacter_apply (a b : G) : + leftBracketCharacter K η hcomm b a = lowerCharacter K η (bracket K hcomm a b) := + (bracket_skew K η hcomm b a).symm +lemma leftBracketCharacter_continuous (hη : Continuous η) (b : G) : + Continuous (leftBracketCharacter K η hcomm b) := + (bracketCharacter_continuous K η hcomm hη b).inv + +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) + +def bracketMatrix (i j : Fin n) : ℝ := + Multiplicative.toAdd (lowerCharacter K η (bracket K hcomm (axis c i 1) (axis c j 1))) + +include hsk in + + +lemma bracket_coordinates (hη : Continuous η) (a b : G) : + Multiplicative.toAdd (lowerCharacter K η (bracket K hcomm a b)) = + ∑ i, ∑ j, c.coord a i * c.coord b j * bracketMatrix K η hcomm c i j := by + have hright := character_coordinates c hsk (bracketCharacter K η hcomm a) + (bracketCharacter_continuous K η hcomm hη a) b + change Multiplicative.toAdd (lowerCharacter K η (bracket K hcomm a b)) = _ at hright + rw [hright] + have hleft (j : Fin n) : Multiplicative.toAdd + (bracketCharacter K η hcomm a (axis c j 1)) = + ∑ i, c.coord a i * bracketMatrix K η hcomm c i j := by + have he := character_coordinates c hsk (leftBracketCharacter K η hcomm (axis c j 1)) + (leftBracketCharacter_continuous K η hcomm hη (axis c j 1)) a + simpa only [leftBracketCharacter_apply,bracketMatrix,bracketCharacter,MonoidHom.coe_mk,OneHom.coe_mk] using he + simp_rw [hleft,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + +omit [IsTopologicalGroup G] in +lemma bracketMatrix_skew (i j : Fin n) : + bracketMatrix K η hcomm c j i = - bracketMatrix K η hcomm c i j := by + unfold bracketMatrix + rw [bracket_skew] + rfl +omit [IsTopologicalGroup G] in +lemma bracketMatrix_diagonal (i : Fin n) : bracketMatrix K η hcomm c i i = 0 := by + have he := bracketMatrix_skew K η hcomm c i i + linarith + +variable (Γ : Subgroup G) +include hsk in + + +theorem integer_commutator_matrix (hη : Continuous η) + (hletters : ∀ i : Fin n, axis c i 1 ∈ Γ) + (hz : ∀ x ∈ squareLattice K Γ, ∃ z : ℤ, Multiplicative.toAdd (η x) = z) : + ∃ M : Fin n → Fin n → ℤ, + (∀ i j, (M i j : ℝ) = bracketMatrix K η hcomm c i j) ∧ + (∀ a b : G, Multiplicative.toAdd (lowerCharacter K η (bracket K hcomm a b)) = + ∑ i, ∑ j, c.coord a i * c.coord b j * (M i j : ℝ)) ∧ + (∀ i j, M j i = -M i j) ∧ (∀ i, M i i = 0) := by + have hi (i j : Fin n) : ∃ z : ℤ, bracketMatrix K η hcomm c i j = z := by + apply lowerCharacter_integral K η Γ hz (bracket K hcomm (axis c i 1) (axis c j 1)) + exact Γ.mul_mem (Γ.mul_mem (Γ.mul_mem (hletters i) (hletters j)) (Γ.inv_mem (hletters i))) + (Γ.inv_mem (hletters j)) + choose M hM using hi + refine ⟨M,fun i j => (hM i j).symm,?_,?_,?_⟩ + · intro a b + simpa only [hM] using bracket_coordinates K η hcomm c hsk hη a b + · intro i j + have he := bracketMatrix_skew K η hcomm c i j + rw [hM,hM] at he + exact_mod_cast he + · intro i + have he := bracketMatrix_diagonal K η hcomm c i + rw [hM] at he + exact_mod_cast he + +end PairTail +end +end + + + +section +noncomputable section +open scoped commutatorElement +namespace PairTail +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (K : Subgroup G) [K.Normal] +variable (η : square K →* Multiplicative ℝ) +variable (hcomm : ∀ a b : G, ⁅a,b⁆ ∈ K) + +def insideConj (a : G) (u : K) : K := + ⟨a*u*a⁻¹,(inferInstance : K.Normal).conj_mem _ u.property a⟩ + +lemma lower_insideConj (a : G) (u : K) : + lowerCharacter K η (insideConj K a u) = lowerCharacter K η u := + lowerCharacter_conj K η a u + +lemma bracket_inv_inv (a b : G) : + lowerCharacter K η (bracket K hcomm a⁻¹ b⁻¹) = + lowerCharacter K η (bracket K hcomm a b) := by + change bracketCharacter K η hcomm a⁻¹ b⁻¹ = _ + rw [map_inv] + change (lowerCharacter K η (bracket K hcomm a⁻¹ b))⁻¹ = _ + rw [← leftBracketCharacter_apply, map_inv, leftBracketCharacter_apply, inv_inv] + +def normalizedTail (u w : K) (a v : G) : K := + insideConj K a⁻¹ u⁻¹ * insideConj K (a⁻¹*v⁻¹) w * bracket K hcomm a⁻¹ v⁻¹ + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma normalizedTail_val (u w : K) (a v : G) : + (normalizedTail K hcomm u w a v).val = (u.val*a)⁻¹*(v⁻¹*w.val*a*v) := by + change (a⁻¹*u.val⁻¹*(a⁻¹)⁻¹)*((a⁻¹*v⁻¹)*w.val*(a⁻¹*v⁻¹)⁻¹)* + ⁅a⁻¹,v⁻¹⁆ = _ + simp only [commutatorElement_def] + group + +lemma lower_normalizedTail (u w : K) (a v : G) : + lowerCharacter K η (normalizedTail K hcomm u w a v) = + (lowerCharacter K η u)⁻¹ * lowerCharacter K η w * + lowerCharacter K η (bracket K hcomm a v) := by + rw [normalizedTail,map_mul,map_mul,lower_insideConj,lower_insideConj,map_inv, + bracket_inv_inv] + + + +def normalizedPair (u w : K) (a v : G) : square K := + pair K (u.val*a) (normalizedTail K hcomm u w a v) + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma normalizedPair_val (u w : K) (a v : G) : + (normalizedPair K hcomm u w a v).val = (u.val*a,v⁻¹*w.val*a*v) := by + ext + · rfl + · change (u.val*a)*(normalizedTail K hcomm u w a v).val = _ + rw [normalizedTail_val,mul_inv_cancel_left] + +lemma normalizedPair_character (u w : K) (a v : G) : + Multiplicative.toAdd (η (normalizedPair K hcomm u w a v)) = + Multiplicative.toAdd (baseCharacter K η (u.val*a)) + + Multiplicative.toAdd (lowerCharacter K η w) - + Multiplicative.toAdd (lowerCharacter K η u) + + Multiplicative.toAdd (lowerCharacter K η (bracket K hcomm a v)) := by + rw [character_split] + change Multiplicative.toAdd (baseCharacter K η (u.val*a)) + + Multiplicative.toAdd (lowerCharacter K η (difference K + (pair K (u.val*a) (normalizedTail K hcomm u w a v)))) = _ + rw [difference_pair,lower_normalizedTail] + simp only [toAdd_mul,toAdd_inv] + ring + +lemma bracket_zpow (a v : G) (n : ℤ) : + Multiplicative.toAdd (lowerCharacter K η (bracket K hcomm (a^n) v)) = + (n:ℝ)*Multiplicative.toAdd (lowerCharacter K η (bracket K hcomm a v)) := by + rw [← leftBracketCharacter_apply,map_zpow,leftBracketCharacter_apply] + simp only [toAdd_zpow,zsmul_eq_mul] + + + +theorem square_orbit_identity (a v : G) (u : ℤ → K) (h n : ℤ) : + Multiplicative.toAdd (η (normalizedPair K hcomm (u n) (u (n+h)) (a^n) v)) = + Multiplicative.toAdd (baseCharacter K η ((u n).val*a^n)) + + (Multiplicative.toAdd (lowerCharacter K η (u (n+h))) - + Multiplicative.toAdd (lowerCharacter K η (u n))) + + (n:ℝ)*Multiplicative.toAdd (lowerCharacter K η (bracket K hcomm a v)) := by + rw [normalizedPair_character,bracket_zpow] + ring + +end PairTail +end +end + + + +section +noncomputable section +open scoped commutatorElement ComplexConjugate +namespace LeibmanSquare +open CubeFaces CubePolynomials +variable {G : Type*} [Group G] +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) + +include h0 in + + +lemma linear_remainder_mem {f : ℤ → G} (hf : Polynomial H 0 f) (hf0 : f 0=1) (n : ℤ) : + f n*(f 1^n)⁻¹∈H.level 2 := by + let := level_normal H h0 2 + let π:=QuotientGroup.mk' (H.level 2) + have hadd (a b : ℤ) : π (f (a+b))=π (f a)*π (f b) := by + have hm := hf [b,a] 0 + have hz : π (iterDiff [b,a] f 0)=1 := (QuotientGroup.eq_one_iff _).mpr hm + simp only [iterDiff,diff,zero_add,hf0,inv_one,one_mul,map_mul,map_inv] at hz + have he := congrArg (fun x => π (f a)*π (f b)*x) hz + convert he using 1 <;> group + let φ : Multiplicative ℤ →* G ⧸ H.level 2 := { + toFun z := π (f z.toAdd) + map_one' := by change π (f 0)=1; rw [hf0,map_one] + map_mul' a b := hadd a.toAdd b.toAdd } + have he : (Multiplicative.ofAdd (1:ℤ))^n=Multiplicative.ofAdd n := by + apply Multiplicative.toAdd.injective + simp + have hn : π (f n)=π (f 1)^n := by + simpa [φ] using map_zpow φ (Multiplicative.ofAdd (1:ℤ)) n + apply (QuotientGroup.eq_one_iff _).mp + change π (f n*(f 1^n)⁻¹)=1 + rw [map_mul,map_inv,map_zpow,hn,mul_inv_cancel] + +def linearRemainder {f : ℤ → G} (hf : Polynomial H 0 f) (hf0 : f 0=1) (n : ℤ) : H.level 2 := + ⟨f n*(f 1^n)⁻¹,linear_remainder_mem H h0 hf hf0 n⟩ + +lemma linearRemainder_mul {f : ℤ → G} (hf : Polynomial H 0 f) (hf0 : f 0=1) (n : ℤ) : + f n=(linearRemainder H h0 hf hf0 n).val*f 1^n := by + simp [linearRemainder,mul_assoc] + + +def tailSquare (u : H.level 2) : level H h0 1 := + ⟨(1,u.val),by + refine ⟨(H.level 1).one_mem,?_,?_⟩ + · rw [h1]; trivial + · simp⟩ + +def linearNormalizedPair {f : ℤ → G} (hf : Polynomial H 0 f) + (u : H.level 2) (h : ℤ) (v : G) : ℤ → level H h0 1 := fun n => + restrictedConj H h0 h1 1 v⁻¹ + (restrictedConj H h0 h1 1 (f h) (normalizedPair H h0 hf h n) * tailSquare H h0 h1 u) + +lemma linearNormalizedPair_polynomial {f : ℤ → G} (hf : Polynomial H 0 f) + (u : H.level 2) (h : ℤ) (v : G) : + Polynomial (restricted H h0) 0 (linearNormalizedPair H h0 h1 hf u h v) := by + apply polynomial_filtered_map _ _ _ (restrictedConj_filtered H h0 h1 1 v⁻¹) + apply polynomial_of_cube_mem + exact (polynomials (restricted H h0) 0).mul_mem + (cube_mem_of_polynomial _ (normalized_conjugate_polynomial H h0 h1 hf h 1 (f h))) + (const_mem (by rw [restricted_zero]; trivial)) + +lemma linearNormalizedPair_val {f : ℤ → G} (hf : Polynomial H 0 f) + (hf0 : f 0=1) (a : G) (u : H.level 2) (h : ℤ) (v : G) + (huh : f h=u.val*a^h) (n : ℤ) : + (linearNormalizedPair H h0 h1 hf u h v n).val = + (f n,v⁻¹*f (n+h)*(a^h)⁻¹*v) := by + change (1*(1*((f 0)⁻¹*f n)*1⁻¹*1)*1⁻¹, + v⁻¹*((f h*((f h)⁻¹*f (n+h))*(f h)⁻¹)*u.val)*(v⁻¹)⁻¹)=_ + simp only [hf0,inv_one,one_mul,mul_one,inv_inv,huh,mul_inv_rev] + congr 1 + group + +lemma linearNormalizedPair_reduced {f : ℤ → G} (hf : Polynomial H 0 f) + (u : H.level 2) (h : ℤ) (v : G) {s : ℕ} (hs0 : 1 ≤ s) (hs : H.level (s+1) = ⊥) : + letI := last_normal H h0 hs0 hs + let π:=QuotientGroup.mk' ((restricted H h0).level s) + let Q:=mapFiltration (restricted H h0) π + let p:=fun n => π (linearNormalizedPair H h0 h1 hf u h v n) + Polynomial Q 0 p ∧ ∀ ts : List ℤ, s≤ts.length → ∀ n, iterDiff ts p n=1 := by + dsimp only + let := last_normal H h0 hs0 hs + have hp:=polynomial_map _ (QuotientGroup.mk' ((restricted H h0).level s)) + (linearNormalizedPair_polynomial H h0 h1 hf u h v) + refine ⟨hp,?_⟩ + intro ts hts n + have hm := (mapFiltration (restricted H h0) (QuotientGroup.mk' ((restricted H h0).level s))).antitone + (by omega : s≤0+ts.length) (hp ts n) + simpa only [(quotient_lowers_degree H h0 hs0 hs).2.2,Subgroup.mem_bot] using hm + +variable [TopologicalSpace G] [IsTopologicalGroup G] + +omit [IsTopologicalGroup G] in +lemma balanced_linearNormalizedPair (Γ : Subgroup G) (F : C(G ⧸ Γ,ℂ)) + {f : ℤ → G} (hf : Polynomial H 0 f) (hf0 : f 0=1) (a : G) + (u : H.level 2) (h : ℤ) (v γ : G) (hγ : γ∈Γ) (hav : a^h=v*γ) + (huh : f h=u.val*a^h) (n : ℤ) : + balanced H h0 Γ F 1 v (linearNormalizedPair H h0 h1 hf u h v n)= + F (QuotientGroup.mk (f n))*conj (F (QuotientGroup.mk (f (n+h)))) := by + unfold balanced + rw [linearNormalizedPair_val H h0 h1 hf hf0 a u h v huh n] + simp only [one_mul] + have he : v*(v⁻¹*f (n+h)*(a^h)⁻¹*v)=f (n+h)*γ⁻¹ := by rw [hav]; group + rw [he,QuotientGroup.mk_mul_of_mem _ (Γ.inv_mem hγ)] + +variable [∀ i, (H.level i).Normal] + + + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma linearNormalizedPair_eq_pairTail {f : ℤ → G} (hf : Polynomial H 0 f) + (hf0 : f 0=1) (a : G) (u : ℤ → H.level 2) (hu : ∀ n, f n=(u n).val*a^n) + (hcomm : ∀ a b : G, ⁅a,b⁆∈H.level 2) (h n : ℤ) (v : G) : + firstPairEquiv H h0 h1 (linearNormalizedPair H h0 h1 hf (u h) h v n)= + PairTail.normalizedPair (H.level 2) hcomm (u n) (u (n+h)) (a^n) v := by + apply Subtype.ext + rw [firstPairEquiv_val,linearNormalizedPair_val H h0 h1 hf hf0 a (u h) h v (hu h) n, + PairTail.normalizedPair_val,hu n,hu (n+h),zpow_add] + congr 1 + group + +end LeibmanSquare + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/ParametricSmooth01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/ParametricSmooth01.lean new file mode 100644 index 0000000000000000000000000000000000000000..54ae0c180f5abc6d04466f284221428fe8c9c2fb --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/ParametricSmooth01.lean @@ -0,0 +1,408 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.AllLevel04 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +open scoped BigOperators Topology commutatorElement +open Filter +end + +end + +section + + + + +noncomputable section +open scoped BigOperators Topology commutatorElement +open Filter +open Topology +universe u +namespace AllLevelStates +open RationalLattice CubeFaces CubePolynomials NilpotentTaylor AllLevelFactorization +open AllLevelDomains AllLevelRemovals CubeHorizontalIrrationality +variable {G : Type u} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} {c : RealCoordinates G n} {Γ : Subgroup G} {s : ℕ} +variable {K : Filtration G} {P : ℕ → ℤ → G} {L : ℕ → ℝ} +namespace State + + + +theorem descend_of_not_irrational (S : State c Γ s K P L) + (hL : ∀ N,0(χ (S.coeff N j)).toAdd) j d hd hbad) + + + +theorem exists_irrational_state (S₀ : State c Γ s K P L) (hL : ∀ N,0word (fun k=>(a N k).val) (s+1)) L where + domain := + { Carrier := G + embed := MonoidHom.id G + injective := Function.injective_id + continuous := continuous_id + closedEmbedding := IsClosedEmbedding.id + dim := n + chart := c + secondKind := hsk + lattice := Γ + integer_lattice := hΓ + lattice_image := fun _ h=>h + rational_image := fun _ h=>h + filtration := K + zero_top := hK0 + one_top := hK1 + terminal := hKs + cutoff := r + cutoff_le := hr + adapted := hadapt } + subseq := id + strictmono := strictMono_id + coeff := a + zero := ha0 + level_image := fun _ _ h=>h + removals := [] + realization := by intro N z; simp [leftWord,rightWord] + + + +theorem normalized_factorization_exists (hsk : MalcevCharacters.SecondKind c) + (hΓ : ∀ x : G,x∈Γ ↔ ∀ i,∃ z : ℤ,c.coord x i=z) + (hK0 : K.level 0=⊤) (hK1 : K.level 1=⊤) (hKs : K.level (s+1)=⊥) + (r : ℕ → ℕ) (hr : ∀ k,r k≤n) + (hadapt : ∀ k (x : G),x∈K.level k ↔ ∀ i : Fin n,i.val + if hk : k(a N k).val) (s+1)=P N := by + rw [hword] + apply word_congr + intro k hk + dsimp only [a] + rw [dite_eq_left hk] + have ha0 (N : ℕ) : (a N 0).val=1 := by + rw [← word_zero (fun k=>(a N k).val) s,haword,hP0] + obtain ⟨S,hirr⟩:=(initialState (L:=L) hsk hΓ hK0 hK1 hKs r hr hadapt a ha0).exists_irrational_state hL + have he : (fun N=>word (fun k=>(a N k).val) (s+1))=P:=funext haword + exact he ▸ ⟨S,hirr⟩ + +end AllLevelStates +end + +end + +section + + + + +noncomputable section +open scoped Topology +open Filter +universe u +namespace AllLevelRemovals +open RationalLattice RationalFactorPeriods +variable {G : Type u} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n s : ℕ} {c : RealCoordinates G n} {L : ℕ → ℝ} + +omit [IsTopologicalGroup G] in +lemma rightWord_ordered [IsTopologicalGroup G] (W : List (Removal c L s)) (N : ℕ) (z : ℤ) : + rightWord W N z=orderedWord + (fun i : Fin W.reverse.length => + (W.reverse.get i).flow (Multiplicative.ofAdd 1) ^ (W.reverse.get i).integer N) + (fun i=>(W.reverse.get i).degree) z := by + unfold rightWord orderedWord + simp only [← zpow_mul] + have hl:=List.map_get_finRange W.reverse + conv_lhs => rw [← hl, List.map_map] + rfl + + + +theorem rightWord_residues [PreconnectedSpace G] [LocallyCompactSpace G] [T2Space G] + (Γ : Subgroup G) [DiscreteTopology Γ] + (hΓrat : Γ≤rationalSubgroup c) + (C : Set G) (hC : IsCompact C) (hreps : ∀ g : G,∃ x∈C,x⁻¹*g∈Γ) + (W : List (Removal c L s)) : + ∃ (φ : ℕ → ℕ) (T : ℕ) (σ : Fin T → G),StrictMono φ ∧ 0(W.reverse.get i).flow (Multiplicative.ofAdd 1)) + (fun i=>(W.reverse.get i).rational_unit) + (fun N i=>(W.reverse.get i).integer N) + (fun i=>(W.reverse.get i).degree) s (fun i=>(W.reverse.get i).degree_le) + refine ⟨φ,T,σ,hφ,hT,hσ,?_⟩ + intro N z + rw [rightWord_ordered] + exact he N z + +end AllLevelRemovals +namespace AllLevelStates +open RationalLattice AllLevelDomains AllLevelRemovals CubeFaces NilpotentTaylor +variable {G : Type u} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n s : ℕ} {c : RealCoordinates G n} {Γ : Subgroup G} +variable {K : Filtration G} {P : ℕ → ℤ → G} {L : ℕ → ℝ} +namespace State + + + +def reindex (S : State c Γ s K P L) (φ : ℕ → ℕ) (hφ : StrictMono φ) : + State c Γ s K P L where + domain := S.domain + subseq := S.subseq∘φ + strictmono := S.strictmono.comp hφ + coeff := fun N=>S.coeff (φ N) + zero := fun N=>S.zero (φ N) + level_image := S.level_image + removals := S.removals.map (fun w=>w.reindex φ hφ) + realization := by + intro N z + rw [leftWord_reindex,rightWord_reindex] + exact S.realization (φ N) z + +lemma irrational_reindex (S : State c Γ s K P L) (hirr : S.Irrational) + (φ : ℕ → ℕ) (hφ : StrictMono φ) : (S.reindex φ hφ).Irrational := by + intro j hj hjs χ hne hcont hrat hnext hbr + exact (hirr j hj hjs χ hne hcont hrat hnext hbr).comp hφ.tendsto_atTop + + + +theorem exists_irrational_fixed_residues + [PreconnectedSpace G] [LocallyCompactSpace G] [T2Space G] [DiscreteTopology Γ] + (hΓrat : Γ≤rationalSubgroup c) + (C : Set G) (hC : IsCompact C) (hreps : ∀ g : G,∃ x∈C,x⁻¹*g∈Γ) + (S : State c Γ s K P L) (hirr : S.Irrational) : + ∃ (T : State c Γ s K P L) (d : ℕ) (σ : Fin d → G), + T.Irrational ∧ 0w.reindex φ hφ)) N z) : G⧸Γ)= + QuotientGroup.mk (σ r) + rw [rightWord_reindex] + exact he N z + +end State +end AllLevelStates +end + +end + +section + + + + +noncomputable section +open scoped BigOperators Topology +open Filter +namespace ParametricSmooth +open _root_.Polynomial _root_.OAI.Polynomial +variable {σ : Type*} + +def family (p : Polynomial (MvPolynomial σ ℝ)) (t : σ → ℝ) : Polynomial ℝ := + p.map (MvPolynomial.eval t) + +def IsPolynomial (f : (σ → ℝ) → ℝ → ℝ) : Prop := + ∃ p : Polynomial (MvPolynomial σ ℝ),∀ t x,(family p t).eval x=f t x + +lemma constant (a : ℝ) : IsPolynomial (fun (_ : σ → ℝ) _=>a) := + ⟨C (MvPolynomial.C a),by intro t x; simp [family]⟩ +lemma coordinate : IsPolynomial (fun (_ : σ → ℝ) x=>x) := + ⟨X,by intro t x; simp [family]⟩ +lemma parameter (i : σ) : IsPolynomial (fun (t : σ → ℝ) _=>t i) := + ⟨C (MvPolynomial.X i),by intro t x; simp [family]⟩ +lemma add {f g : (σ → ℝ) → ℝ → ℝ} (hf : IsPolynomial f) (hg : IsPolynomial g) : + IsPolynomial (fun t x=>f t x+g t x) := by + obtain ⟨p,hp⟩:=hf + obtain ⟨q,hq⟩:=hg + refine ⟨p+q,?_⟩ + intro t x + change ((p+q).map _).eval x=_ + rw [Polynomial.map_add,eval_add] + exact congrArg₂ (·+·) (hp t x) (hq t x) +lemma mul {f g : (σ → ℝ) → ℝ → ℝ} (hf : IsPolynomial f) (hg : IsPolynomial g) : + IsPolynomial (fun t x=>f t x*g t x) := by + obtain ⟨p,hp⟩:=hf + obtain ⟨q,hq⟩:=hg + refine ⟨p*q,?_⟩ + intro t x + change ((p*q).map _).eval x=_ + rw [Polynomial.map_mul,eval_mul] + exact congrArg₂ (·*·) (hp t x) (hq t x) +lemma neg {f : (σ → ℝ) → ℝ → ℝ} (hf : IsPolynomial f) : + IsPolynomial (fun t x=>-f t x) := by + simpa using mul (constant (-1)) hf +lemma sub {f g : (σ → ℝ) → ℝ → ℝ} (hf : IsPolynomial f) (hg : IsPolynomial g) : + IsPolynomial (fun t x=>f t x-g t x) := by simpa [sub_eq_add_neg] using add hf (neg hg) +lemma pow {f : (σ → ℝ) → ℝ → ℝ} (hf : IsPolynomial f) (k : ℕ) : + IsPolynomial (fun t x=>(f t x)^k) := by + induction k with + | zero => simpa using constant (σ:=σ) 1 + | succ k ih => simpa [pow_succ] using mul ih hf +lemma finite_sum {ι : Type*} (S : Finset ι) {f : ι → (σ → ℝ) → ℝ → ℝ} + (hf : ∀ i∈S,IsPolynomial (f i)) : IsPolynomial (fun t x=>∑ i∈S,f i t x) := by + classical + induction S using Finset.induction_on with + | empty => simpa using constant (σ:=σ) 0 + | @insert i S hi ih => + simpa [Finset.sum_insert hi] using add (hf i (by simp)) (ih (fun j hj=>hf j (by simp [hj]))) +lemma finite_prod {ι : Type*} (S : Finset ι) {f : ι → (σ → ℝ) → ℝ → ℝ} + (hf : ∀ i∈S,IsPolynomial (f i)) : IsPolynomial (fun t x=>∏ i∈S,f i t x) := by + classical + induction S using Finset.induction_on with + | empty => simpa using constant (σ:=σ) 1 + | @insert i S hi ih => + simpa [Finset.prod_insert hi] using mul (hf i (by simp)) (ih (fun j hj=>hf j (by simp [hj]))) +lemma polynomial_eval (p : Polynomial ℝ) {f : (σ → ℝ) → ℝ → ℝ} (hf : IsPolynomial f) : + IsPolynomial (fun t x=>p.eval (f t x)) := by + simp only [Polynomial.eval_eq_sum_range] + exact finite_sum _ (fun i _=>mul (constant _) (pow hf i)) +lemma mvpolynomial_eval {ι : Type*} (p : MvPolynomial ι ℚ) + {f : ι → (σ → ℝ) → ℝ → ℝ} (hf : ∀ i,IsPolynomial (f i)) : + IsPolynomial (fun t x=>MvPolynomial.eval₂ (algebraMap ℚ ℝ) (fun i=>f i t x) p) := by + induction p using MvPolynomial.induction_on with + | C a => simpa using constant (σ:=σ) (a:ℝ) + | add p q hp hq => simpa using add hp hq + | mul_X p i hp => simpa using mul hp (hf i) + +lemma rename_parameters {τ : Type*} {f : (σ → ℝ) → ℝ → ℝ} + (hf : IsPolynomial f) (e : σ → τ) : IsPolynomial (fun t x=>f (t∘e) x) := by + obtain ⟨p,hp⟩:=hf + refine ⟨p.map (MvPolynomial.rename e).toRingHom,?_⟩ + intro t x + have he : (MvPolynomial.eval t).comp (MvPolynomial.rename e).toRingHom= + MvPolynomial.eval (t∘e) := by + apply RingHom.ext + intro P + exact MvPolynomial.eval_rename e t P + simp only [family,Polynomial.map_map,he] + exact hp (t∘e) x + +lemma continuous_eval (p : Polynomial (MvPolynomial σ ℝ)) : + Continuous (fun z : (σ → ℝ) × ℝ=>(family p z.1).eval z.2) := by + simp only [family,eval_map,eval₂_eq_sum_range] + apply continuous_finsetSum + intro i _ + exact ((MvPolynomial.continuous_eval (p.coeff i)).comp continuous_fst).mul (continuous_snd.pow i) + +lemma derivative_family (p : Polynomial (MvPolynomial σ ℝ)) (t : σ → ℝ) (k : ℕ) : + derivative^[k] (family p t)=family (derivative^[k] p) t := by + induction k generalizing p with + | zero => rfl + | succ k ih => + rw [Function.iterate_succ_apply,Function.iterate_succ_apply] + rw [show derivative (family p t)=family p.derivative t from derivative_map p _] + exact ih p.derivative + + + +theorem compact_derivative_limit [Fintype σ] {ι : Type*} {l : Filter ι} + {f : (σ → ℝ) → ℝ → ℝ} (hf : IsPolynomial f) + {a : ι → σ → ℝ} {a₀ : σ → ℝ} (ha : Tendsto a l (𝓝 a₀)) + (k : ℕ) (K : Set ℝ) (hK : IsCompact K) : + TendstoUniformlyOn (fun N=>iteratedDeriv k (f (a N))) (iteratedDeriv k (f a₀)) l K := by + obtain ⟨p,hp⟩:=hf + have he (t : σ → ℝ) : f t=fun x=>(family p t).eval x:=funext (fun x=>(hp t x).symm) + simp_rw [he,SmoothBinomial.iteratedDeriv_eval,derivative_family] + let : CompactSpace K:=isCompact_iff_compactSpace.mp hK + let F : (σ → ℝ) → K → ℝ:=fun t x=>(family (derivative^[k] p) t).eval x.val + have hF : Continuous (Function.uncurry F):= + (continuous_eval (derivative^[k] p)).comp + (continuous_fst.prodMk (continuous_subtype_val.comp continuous_snd)) + have hu:=hF.tendstoUniformly F a₀ + rw [tendstoUniformlyOn_iff_tendstoUniformly_comp_coe] + intro u hu' + exact ha.eventually (hu u hu') + + + +theorem compact_derivative_bound {f : (σ → ℝ) → ℝ → ℝ} (hf : IsPolynomial f) + {a : ℕ → σ → ℝ} {a₀ : σ → ℝ} (ha : Tendsto a atTop (𝓝 a₀)) + (k : ℕ) (K : Set ℝ) (hK : IsCompact K) : + ∃ B>0,∀ N x,x∈K → |iteratedDeriv k (f (a N)) x|≤B := by + obtain ⟨p,hp⟩:=hf + have he (t : σ → ℝ) : f t=fun x=>(family p t).eval x:=funext (fun x=>(hp t x).symm) + obtain ⟨M,hM⟩:=(ha.isCompact_insert_range.prod hK).exists_bound_of_continuousOn + (continuous_eval (derivative^[k] p)).continuousOn + refine ⟨max M 0+1,by positivity,?_⟩ + intro N x hx + rw [he,SmoothBinomial.iteratedDeriv_eval,derivative_family] + have hb:=hM (a N,x) ⟨Set.mem_insert_of_mem _ (Set.mem_range_self N),hx⟩ + have hb' : |(family (derivative^[k] p) (a N)).eval x|≤M:=by + simpa only [Real.norm_eq_abs] using hb + exact hb'.trans (by linarith [le_max_left M 0]) + +end ParametricSmooth + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PhysicalDecay01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PhysicalDecay01.lean new file mode 100644 index 0000000000000000000000000000000000000000..1ff138bd8e32313f1bdd65598b006a0fa5936692 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PhysicalDecay01.lean @@ -0,0 +1,332 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.AllLevel09 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +noncomputable section +open MeasureTheory Topology +end + +end + +noncomputable section +open Filter +open scoped Topology BigOperators +namespace SourcePhysicalDecay +open RoughSamplingWeights FinitePieceAverages +variable {Y : Type} [TopologicalSpace Y] {v : ℕ} + + +def AllBoxes (Z : ℕ→ℝ) (state : ℕ→(Fin v→ℤ)→Y) (S : C(Y,Y)) : Prop := + ∀ (d : ℕ),0mean (physicalResidueBox (lo N) (hi N) (res N) d) + (fun b=>f (S (state N b)))-mean (physicalResidueBox (lo N) (hi N) (res N) d) + (fun b=>f (state N b))) atTop (𝓝 0) + + + +theorem allBoxes_subsequence (Z : ℕ→ℝ) (hZ : ∀ N,0≤Z N) + (state : ℕ→(Fin v→ℤ)→Y) (S : C(Y,Y)) + (h : AllBoxes Z state S) (ψ : ℕ→ℕ) (hψ : StrictMono ψ) : + AllBoxes (Z∘ψ) (state∘ψ) S + := by + classical + intro d hd c C hc hC lo hi res hb f + let lo' := Function.extend ψ lo (fun N (_ : Fin v)=>-(c+C)*Z N) + let hi' := Function.extend ψ hi (fun N (_ : Fin v)=>(c+C)*Z N) + let res' := Function.extend ψ res (fun _ (_ : Fin v)=>0) + have hlo (k : ℕ) : lo' (ψ k)=lo k := hψ.injective.extend_apply _ _ _ + have hhi (k : ℕ) : hi' (ψ k)=hi k := hψ.injective.extend_apply _ _ _ + have hres (k : ℕ) : res' (ψ k)=res k := hψ.injective.extend_apply _ _ _ + have hb' : ∀ᶠ N in atTop,(∀ i,c*Z N≤hi' N i-lo' N i) ∧ + (∀ i,-(c+C)*Z N≤lo' N i ∧ hi' N i≤(c+C)*Z N) := by + obtain ⟨N₀,hN₀⟩ := eventually_atTop.mp hb + apply eventually_atTop.mpr + refine ⟨ψ N₀,fun N hN=>?_⟩ + by_cases hn : ∃ k,ψ k=N + · obtain ⟨k,rfl⟩:=hn + have hk:=hN₀ k (hψ.le_iff_le.mp hN) + rw [hlo,hhi] + refine ⟨hk.1,fun i=>?_⟩ + have hz:=hZ (ψ k) + have hcz:=mul_nonneg hc.le hz + constructor <;> dsimp only [Function.comp_apply] at hk + · nlinarith [(hk.2 i).1] + · nlinarith [(hk.2 i).2] + · have hl : lo' N=(fun _ : Fin v=>-(c+C)*Z N) := Function.extend_apply' _ _ _ hn + have hr : hi' N=(fun _ : Fin v=>(c+C)*Z N) := Function.extend_apply' _ _ _ hn + rw [hl,hr] + refine ⟨fun _=>?_,fun _=>⟨le_rfl,le_rfl⟩⟩ + have hz:=hZ N + have hc':=mul_nonneg hc.le hz + have hC':=mul_nonneg hC.le hz + nlinarith + have hh:=(h d hd c (c+C) hc (add_pos hc hC) lo' hi' res' hb' f).comp hψ.tendsto_atTop + simpa only [Function.comp_def,hlo,hhi,hres] using hh + +end SourcePhysicalDecay +end + +noncomputable section +open MeasureTheory Filter +open scoped Topology BigOperators +namespace SourcePhysicalDecay +attribute [local instance] Classical.propDecidable +open RoughSamplingWeights FinitePieceAverages CubeLocalHaar +lemma physical_box_eq_rectangle {v : ℕ} (lo hi : Fin v→ℝ) (a : Fin v→ℤ) (d : ℕ) + (ha : ∀ i,0≤a i ∧ a i<(d:ℤ)) : + physicalResidueBox lo hi a d=physicalResidueRectangle lo hi a d := by + classical + ext b + simp only [physicalResidueBox,Finset.mem_filter,mem_boxIndices _ _ _ _ zero_lt_one, + physicalResidueRectangle_mem,zero_add,one_mul,Int.ModEq,Int.emod_eq_of_lt (ha _).1 (ha _).2] + +lemma mean_eq_expect {α : Type*} (s : Finset α) (f : α→ℂ) : mean s f=𝔼 x∈s,f x := by + rw [mean,Finset.expect_eq_sum_div_card,div_eq_mul_inv,mul_comm] + +lemma mean_ofReal {α : Type*} (s : Finset α) (f : α→ℝ) : + mean s (fun x=>(f x:ℂ))=((𝔼 x∈s,f x : ℝ):ℂ) := by + rw [mean_eq_expect] + exact (map_expect (Complex.ofRealCLM.toLinearMap.restrictScalars ℚ≥0) f s).symm +end SourcePhysicalDecay +end +noncomputable section +open MeasureTheory Filter +open scoped Topology BigOperators +namespace SourcePhysicalDecay +open RationalLattice CubeFaces CubeTaylorExpansion CubeLocalHaar RoughSamplingWeights FinitePieceAverages +open AllLevelFactorization AllLevelFactorization.Factorization AllLevelFactorization.Factorization.ResidueCover +variable {G ι : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable [Fintype ι] [DecidableEq ι] +variable {n s : ℕ} {c : RealCoordinates G n} {Γ : Subgroup G} +variable {K : Filtration G} {P : ℕ→ℤ→G} {L : ℕ→ℝ} +variable {F : Factorization c Γ s K P L} {r : Fin F.period} (C : F.ResidueCover r) +variable [MeasurableSpace (C.CubeSpace (ι:=ι))] [BorelSpace (C.CubeSpace (ι:=ι))] +variable [CompactSpace (G⧸Γ)] [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] +variable [SecondCountableTopology (G⧸Γ)] +variable {Y : Type} [TopologicalSpace Y] [MeasurableSpace Y] [BorelSpace Y] +variable [CompactSpace Y] [HasOuterApproxClosed Y] + + +omit [CompactSpace (G⧸Γ)] [CompactSpace Y] in +theorem haar_invariant_of_allBoxes (hL : ∀ N,0π (fun w=>QuotientGroup.mk (P N (vertex (fun i=>b (e i)) w)))) S) + (d : ℕ) (hd : 0b (e i)) w:ℝ)/L (F.state.subseq N)) β≤B*α) : + Measure.map S (C.marginalCubeHaar β π : Measure Y)=(C.marginalCubeHaar β π : Measure Y) + := by + apply C.marginal_haar_invariant hL ht e d hd a ha hdp ha0 hai lo hi hb β B hgeo π S + intro α hα f + obtain ⟨c₀,C₀,hc₀,hC₀,hbα⟩ := hb α hα + let ff : C(Y,ℂ):=⟨fun y=>(f y:ℂ),Complex.continuous_ofReal.comp f.continuous⟩ + have hh:=(allBoxes_subsequence L (fun N=>(hL N).le) _ S h F.state.subseq F.state.strictmono) + d hd c₀ C₀ hc₀ hC₀ (lo α) (hi α) (fun _=>a) hbα ff + have he (N : ℕ) : + (mean (physicalResidueBox (lo α N) (hi α N) a d) + (fun b=>ff (S (π (fun w=>QuotientGroup.mk + (P (F.state.subseq N) (vertex (fun i=>b (e i)) w))))))- + mean (physicalResidueBox (lo α N) (hi α N) a d) + (fun b=>ff (π (fun w=>QuotientGroup.mk + (P (F.state.subseq N) (vertex (fun i=>b (e i)) w))))))= + ((marginalBoxAverage (F:=F) e d a lo hi π α N (f.comp S)- + marginalBoxAverage (F:=F) e d a lo hi π α N f:ℝ):ℂ) := by + rw [physical_box_eq_rectangle _ _ _ _ ha] + dsimp only [ff,ContinuousMap.coe_mk] + rw [mean_ofReal,mean_ofReal,←Complex.ofReal_sub] + rfl + have hn:=hh.norm + simpa only [Function.comp_apply,he,norm_zero,Complex.norm_real,Real.norm_eq_abs] using hn + +end SourcePhysicalDecay +end + +noncomputable section +open MeasureTheory Filter +open scoped Topology BigOperators +namespace SourcePhysicalDecay +open RationalLattice AllLevelFactorization AllLevelFactorization.Factorization +open CubeFaces CubeLocalHaar PhysicalCubeMaps SourceIntegerArrays +attribute [local instance] Classical.propDecidable +variable {Y : Type} [TopologicalSpace Y] + + +def AllCompatibleHaar (L : ℕ→ℝ) (state : ℕ→ℤ→Y) (v : ℕ) (j : Fin v) (S : C(Y,Y)) : Prop := + letI : MeasurableSpace (Finset (Fin v)→Y):=borel _ + letI : BorelSpace (Finset (Fin v)→Y):=⟨rfl⟩ + ∀ (H : Type) [Group H] [TopologicalSpace H] [IsTopologicalGroup H], + ∀ (n s : ℕ) (c : RealCoordinates H n) (Λ : Subgroup H) + [CompactSpace (H⧸Λ)] [SecondCountableTopology (H⧸Λ)], + letI : MeasurableSpace (H⧸Λ):=borel _ + letI : BorelSpace (H⧸Λ):=⟨rfl⟩ + ∀ (K : Filtration H) (P : ℕ→ℤ→H) (F : Factorization c Λ s K P L) + (p : C(H⧸Λ,Y)), (∀ N b,p (QuotientGroup.mk (P N b))=state N b) → + ∀ (r : Fin F.period) (C : F.ResidueCover r), + letI : MeasurableSpace (C.CubeSpace (ι:=Fin v)):=borel _ + letI : BorelSpace (C.CubeSpace (ι:=Fin v)):=⟨rfl⟩ + ∀ (d : ℕ),0state N (cubeVertex v b w)) (upperFace j S)) : + AllCompatibleHaar L state v j S + := by + classical + intro H _ _ _ n s c Λ _ _ + let : MeasurableSpace (H⧸Λ):=borel _ + let : BorelSpace (H⧸Λ):=⟨rfl⟩ + intro K P F p hp r C + let : MeasurableSpace (Finset (Fin v)→Y):=borel _ + let : BorelSpace (Finset (Fin v)→Y):=⟨rfl⟩ + let : MeasurableSpace (C.CubeSpace (ι:=Fin v)):=borel _ + let : BorelSpace (C.CubeSpace (ι:=Fin v)):=⟨rfl⟩ + intro d hd a ha hdp ha0 hai lo hi hb β B hgeo + let e : Option (Fin v)≃Fin (v+1):=(finSuccEquiv v).symm + have he (b : Fin (v+1)→ℤ) (w : Finset (Fin v)) : + vertex (fun i=>b (e i)) w=cubeVertex v b w := by simp [vertex,cubeVertex,e] + have hh : AllBoxes L (fun N b=>vertices p + (fun w=>QuotientGroup.mk (P N (vertex (fun i=>b (e i)) w)))) (upperFace j S) := by + have heq : (fun N b=>vertices p (fun w=>QuotientGroup.mk + (P N (vertex (fun i=>b (e i)) w))))=(fun N b w=>state N (cubeVertex v b w)) := by + funext N b w + simp only [vertices_apply,he,hp] + rw [heq] + exact h + apply haar_invariant_of_allBoxes C hL hLt e (vertices p) (upperFace j S) hh d hd a ha hdp + (by simpa [e] using ha0) (by simpa [e] using hai) lo hi hb β B + simpa only [he] using hgeo + +end SourcePhysicalDecay +end + +noncomputable section +namespace SourceIntegerArrays +open RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift RoughTopologicalFace RoughArrayCoordinates SourceResidueAlignment +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory Filter +open scoped BigOperators Topology ENNReal +attribute [local instance] Classical.propDecidable +variable {τ : Type} [Fintype τ] {ι : τ→Type} [∀ t,Fintype (ι t)] +variable (G : ∀ t,ι t→Type) [∀ t i,Group (G t i)] +variable [∀ t i,TopologicalSpace (G t i)] [∀ t i,IsTopologicalGroup (G t i)] +variable (n : ∀ t,ι t→ℕ) (q : τ→ℕ) (c : ∀ t i,RealCoordinates (G t i) (n t i)) +variable (hsk : ∀ t i,SecondKind (c t i)) (A : ∀ t i,CubeFaces.Filtration (G t i)) +variable (w : ∀ t i,Fin (n t i)→ℕ) +variable (hA : ∀ t i k (g : G t i),g∈(A t i).level k ↔ ∀ j,w t i jX N j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ N,0R N/(Xp N:ℝ)) atTop (𝓝 0)) + (hZ : ∀ t (u : ℝ),0(R N/(M N:ℝ))/ + (1+∑ j : Fin (m t),(X N (perm t (j.castAdd (h t))):ℝ)^2)^u) atTop atTop) + (hQ0 : ∀ N,0≤Q N) + (hSize : ∀ t,Tendsto (fun N=>(Q N+(∏ l : Fin (m t),(X N (perm t (l.castAdd (h t))):ℝ)^2)*(L N:ℝ))/R N) atTop (𝓝 0)) + (hWM : ∀ N,(primorial (w0 N):ℤ)∣(M N:ℤ)) + (hM : ∀ N,0(X N (perm t (j.castAdd (h t))):ℝ)/(L N:ℝ)) atTop atTop) + (g x : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→∀ i,G t i) + (slot : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→ι t→ℤ) + (qval : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→Fin (q t)→ℤ) + (hQ : ∀ t N y,y∈outsideDomain (fun l : Fin (h t)=>X N (perm t (l.natAdd (m t)))) (primorial (w0 N)) → + ∀ b,b∈(fullDomain (fun l : Fin (m t)=>X N (perm t (l.castAdd (h t)))) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) →∀ k,|(qval t N y b k:ℝ)|≤Q N) + (E : ℕ→Set ((Fin a→ℕ)×ℕ)) (ε : ℝ≥0∞) (hε : 0<ε) + (hE : ∀ N,ε≤(jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) + (hX N) (hXp N)) (E N)) : + ∃ φ : ℕ→ℕ,StrictMono φ ∧ ∃ z : ℕ→(Fin a→ℕ)×ℕ, + (∀ k,z k∈E (φ k) ∧ z k∈fullDomain (X (φ k)) (Xp (φ k)) (primorial (w0 (φ k)))) ∧ + ∀ t, + let zout := fun k l=>(z k).1 (perm t (l.natAdd (m t))) + let zin := fun k=>((fun l=>(z k).1 (perm t (l.castAdd (h t)))),(z k).2) + let label := fun k=>expose (L (φ k)) (M (φ k):ℤ) (R (φ k)) (zin k) + let Z := fun k=>R (φ k)/(M (φ k):ℝ) + ∀ (e : Fin (q t)) (j : Fin (v t)) (pstar : ℕ→ℤ), + (∀ k,(M (φ k):ℤ)∣pstar k-((z k).2:ℤ)) → + (∀ k,|(pstar k:ℝ)-((z k).2:ℝ)|≤R (φ k)) → + let state := fun k b=>QuotientGroup.mk + (literalState (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (hw t) + (M (φ k)) (L (φ k)) (label k) (fun l=>((zin k).1 l:ℤ)) (pstar k) + (fun _ (_ : Fin 1)=>1) + (g t (φ k) (zout k) (label k)) (x t (φ k) (zout k) (label k)) + (slot t (φ k) (zout k) (label k)) (qval t (φ k) (zout k) (label k)) (fun _=>b)) + SourcePhysicalDecay.AllCompatibleHaar Z state (v t) j + (faceAction (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (Γ t) + (fun _ (_ : Fin 1)=>1) e 0) + := by + classical + obtain ⟨φ,hφ,z,hz,hgood⟩:=source_global_literal_cube_faces G n q c hsk A w hA hw Γ hΓ + a m h v perm w0 M Xp X R Q L hw0 hX hXp hXt hXpt hR hRX hZ hQ0 hSize hWM hM hMs + hL hsm hWL hML hLexact hXL g x slot qval hQ E ε hε hE + refine ⟨φ,hφ,z,hz,?_⟩ + intro t + dsimp only + intro e j pstar hpstar hpclose + let Y := (Carrier (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t))⧸ + lattice (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (Γ t) + have htop:=joint_array_topology (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (hw t) (Γ t) (hΓ t) + let : CompactSpace Y:=htop.2.2.1 + let : TopologicalSpace.MetrizableSpace Y:=htop.2.2.2 + have hZpos (N : ℕ) : 0R N/(M N:ℝ)) atTop atTop := by + have ht : Tendsto (fun N=>(R N/(M N:ℝ))/ + (1+∑ j : Fin (m t),(X N (perm t (j.castAdd (h t))):ℝ)^2)) atTop atTop := by + simpa only [Real.rpow_one] using hZ t 1 zero_lt_one + apply tendsto_atTop.mpr + intro B + filter_upwards [ht.eventually (eventually_ge_atTop B)] with N hN + apply hN.trans + apply div_le_self (hZpos N).le + have hn : 0≤∑ j : Fin (m t),(X N (perm t (j.castAdd (h t))):ℝ)^2:= + Finset.sum_nonneg (fun _ _=>sq_nonneg _) + linarith + apply SourcePhysicalDecay.compatible_haar_of_allBoxes _ (fun k=>hZpos (φ k)) + (hZT.comp hφ.tendsto_atTop) + intro d hd c₀ C₀ hc₀ hC₀ lo hi res hbox F + exact hgood t e j d hd pstar hpstar hpclose c₀ C₀ hc₀ hC₀ lo hi res hbox F + +end SourceIntegerArrays + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PivotExtension01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotExtension01.lean new file mode 100644 index 0000000000000000000000000000000000000000..3ddd62b33d9f8a56b58ae19af10bfd2db2309877 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotExtension01.lean @@ -0,0 +1,312 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.HarmonicTranslation01 +import OAI.Combinatorics.SumProduct.Alignment.ProductExposure04 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section + +noncomputable section +namespace SourceJointShift +open MeasureTheory Filter Topology ProductExposureLaw RawHarmonicProbability +open scoped BigOperators ENNReal +attribute [local instance] Classical.propDecidable + +private lemma raw_eval_nat (X W : ℕ) (f : ℤ→ℝ) : + HarmonicTranslation.eval (HarmonicTranslation.raw X W) f = + ∑ n∈Finset.Ico X (X^2),if W.Coprime n then (n:ℝ)⁻¹*f (n:ℤ) else 0 := by + have hs : (HarmonicTranslation.raw X W).support ⊆ Finset.Ico (X:ℤ) ((X:ℤ)^2) := by + intro n hn + have hh:=Finsupp.mem_support_iff.mp hn + rw [HarmonicTranslation.raw_apply] at hh + split_ifs at hh with h + · exact Finset.mem_Ico.mpr ⟨h.1,h.2.1⟩ + · exact (hh rfl).elim + rw [HarmonicTranslation.eval,(HarmonicTranslation.raw X W).sum_of_support_subset hs + (fun n a=>a*f n) (by simp)] + symm + apply Finset.sum_bij (fun (n:ℕ) _=>(n:ℤ)) + · intro n hn + rcases Finset.mem_Ico.mp hn with ⟨hn1,hn2⟩ + exact Finset.mem_Ico.mpr ⟨by exact_mod_cast hn1,by exact_mod_cast hn2⟩ + · intro n hn k hk he + exact_mod_cast he + · intro z hz + rcases Finset.mem_Ico.mp hz with ⟨hz1,hz2⟩ + have hz0 : 0≤z := (Int.natCast_nonneg X).trans hz1 + refine ⟨z.toNat,Finset.mem_Ico.mpr ⟨?_,?_⟩,Int.toNat_of_nonneg hz0⟩ + · have ht : (X:ℤ)≤(z.toNat:ℤ) := by rwa [Int.toNat_of_nonneg hz0] + exact_mod_cast ht + · apply (Int.toNat_lt hz0).mpr + exact_mod_cast hz2 + · intro n hn + rcases Finset.mem_Ico.mp hn with ⟨hn1,hn2⟩ + have h1 : (X:ℤ)≤n := by exact_mod_cast hn1 + have h2 : (n:ℤ)<(X:ℤ)^2 := by exact_mod_cast hn2 + simp only [HarmonicTranslation.raw_apply,h1,h2,true_and,Int.isCoprime_iff_nat_coprime, + Int.natAbs_natCast,Int.cast_natCast,Nat.coprime_comm (n:=n) (m:=W)] + split_ifs <;> simp + +private lemma raw_mass_nat (X W : ℕ) : + HarmonicTranslation.mass (HarmonicTranslation.raw X W)= + DyadicHarmonicBoundary.mass X (X^2) W := by + have hh:=raw_eval_nat X W (fun _=>1) + simpa [HarmonicTranslation.eval,HarmonicTranslation.mass,DyadicHarmonicBoundary.mass] using hh + +private lemma law_eval_nat (X W : ℕ) (hW : 0if n∈A then 1 else 0)= + (law X W hW hX:Measure ℕ).real {p | (p:ℤ)∈A} := by + rw [law_apply,HarmonicTranslation.law,HarmonicTranslation.eval,Finsupp.sum_smul_index (by simp)] + have he : (HarmonicTranslation.raw X W).sum + (fun n a=>(HarmonicTranslation.mass (HarmonicTranslation.raw X W))⁻¹ * a * (if n∈A then 1 else 0)) = + (HarmonicTranslation.mass (HarmonicTranslation.raw X W))⁻¹ * + HarmonicTranslation.eval (HarmonicTranslation.raw X W) (fun n=>if n∈A then 1 else 0) := by + simp only [HarmonicTranslation.eval,Finsupp.sum,mul_assoc,Finset.mul_sum] + rw [he,raw_eval_nat,raw_mass_nat,←div_eq_inv_mul] + congr 1 + apply Finset.sum_congr rfl + intro p hp + simp only [Set.mem_ofPred_eq] + split_ifs <;> simp_all + +private lemma law_shift_event (X W : ℕ) (hW : 0if n+h∈A then 1 else 0)- + HarmonicTranslation.eval (HarmonicTranslation.law X W) (fun n=>if n∈A then 1 else 0)|≤_ + rw [←HarmonicTranslation.eval_shift h (HarmonicTranslation.law X W) (fun n=>if n∈A then 1 else 0), + ←HarmonicTranslation.eval_sub] + have hb:=HarmonicTranslation.eval_bound + (HarmonicTranslation.shift h (HarmonicTranslation.law X W)-HarmonicTranslation.law X W) + (fun n=>if n∈A then 1 else 0) (B:=1) (by intro n; split_ifs <;> norm_num) + rw [mul_one] at hb + exact hb.trans (HarmonicTranslation.law_translation hW (by omega) hh) + +private lemma joint_pivot_disintegration {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) + (hW : 0 rw [←Measure.restrict_eq_self_of_ae_mem (outside_ae_domain X W hW hX)] + rw [lintegral_finset,ENNReal.toReal_sum] + · apply Finset.sum_congr rfl + intro y hy + rw [ENNReal.toReal_mul,mul_comm] + rfl + · intro y hy + exact ENNReal.mul_ne_top (by finiteness) (by finiteness) + + +theorem raw_joint_shift {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) + (hW : 0conditioningLabel M J u=conditioningLabel M J z) +def slotEvent {m V : ℕ} (slot : Fin V→(Fin m→ℕ)→ℤ) (A : (Fin m→ℕ)→Set ℤ) : Set ((Fin m→ℕ)×ℕ) := + {z | ∃ v,(z.2:ℤ)+slot v z.1∈A z.1} + + +def conditionalSlotMass {m V : ℕ} (X : Fin m→ℕ) (Xp W M J : ℕ) + (hW : 0x∈A):Set α) := by ext x; simp [and_comm] + rw [he,←sum_measureReal_singleton,Finset.sum_filter] + +private lemma finite_ratio_bound {α β : Type*} [DecidableEq α] [DecidableEq β] + (S : Finset α) (w : α→ℝ) (hw : ∀ x∈S,0≤w x) (π : α→β) + (E : Set β) (A : Set α) (c : ℝ) (hc : 0≤c) : + c*((∑ x∈S,if π x∈E then w x else 0)- + ∑ x∈S,if (∑ y∈S.filter (fun y=>π y=π x),if y∈A then w y else 0)/ + (∑ y∈S.filter (fun y=>π y=π x),w y)≤c then w x else 0) ≤ + ∑ x∈S,if π x∈E ∧ x∈A then w x else 0 := by + classical + let d (i : β) := ∑ y∈S.filter (fun y=>π y=i),w y + let n (i : β) := ∑ y∈S.filter (fun y=>π y=i),if y∈A then w y else 0 + let G : Set β := {i | i∈E ∧ cπ x∈T)=S.filter (fun x=>π x∈G) := by + ext x + simp only [Finset.mem_filter,T] + constructor + · exact fun h=>⟨h.1,h.2.2⟩ + · exact fun h=>⟨h.1,Finset.mem_image_of_mem π h.1,h.2⟩ + have hs : c*(∑ x∈S.filter (fun x=>π x∈G),w x) ≤ + ∑ x∈S,if π x∈E ∧ x∈A then w x else 0 := by + calc + _ = ∑ i∈T,c*d i := by rw [←Finset.mul_sum,Finset.sum_fiberwise_eq_sum_filter,hf] + _ ≤ ∑ i∈T,∑ x∈S.filter (fun x=>π x=i),if π x∈E ∧ x∈A then w x else 0 := by + apply Finset.sum_le_sum + intro i hi + have hg : i∈E ∧ chw y (Finset.mem_filter.mp hy).1) + have hn : 0≤n i := Finset.sum_nonneg (by intro y hy; split_ifs; exact hw y (Finset.mem_filter.mp hy).1; rfl) + have hh : c*d i≤n i := by + rcases eq_or_lt_of_le hd with h0|h0 + · rw [←h0,mul_zero]; exact hn + · exact le_of_lt ((lt_div_iff₀ h0).mp hg.2) + apply hh.trans_eq + apply Finset.sum_congr rfl + intro x hx + simp only [(Finset.mem_filter.mp hx).2,hg.1,true_and] + _ = ∑ x∈S.filter (fun x=>π x∈G),if π x∈E ∧ x∈A then w x else 0 := by + rw [Finset.sum_fiberwise_eq_sum_filter,hf] + _ ≤ _ := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + intro x hx _ + split_ifs + · exact hw x hx + · rfl + apply le_trans ?_ hs + apply mul_le_mul_of_nonneg_left _ hc + rw [Finset.sum_filter,←Finset.sum_sub_distrib] + apply Finset.sum_le_sum + intro x hx + change (if π x∈E then w x else 0)-(if n (π x)/d (π x)≤c then w x else 0) ≤ + if π x∈G then w x else 0 + by_cases he : π x∈E <;> by_cases hb : n (π x)/d (π x)≤c + · simp [he,hb,G,not_lt.mpr hb] + · simp [he,hb,G,lt_of_not_ge hb] + · simp [he,hb,G,hw x hx] + · simp [he,hb,G] + +private lemma support_ae {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) + (hW : 0⟨h,hz⟩,fun h=>h.1⟩ + +private lemma conditional_mass_sum {m V : ℕ} (X : Fin m→ℕ) (Xp W M J : ℕ) + (hW : 0conditioningLabel M J y=conditioningLabel M J z), + if y∈slotEvent slot A then (jointLaw X Xp W hW hX hXp).real {y} else 0)/ + (∑ y∈(fullDomain X Xp W).filter (fun y=>conditioningLabel M J y=conditioningLabel M J z), + (jointLaw X Xp W hW hX hXp).real {y}) := by + unfold conditionalSlotMass + rw [finite_real,←sum_measureReal_singleton] + rfl + +private lemma conditional_extension {m V : ℕ} (X : Fin m→ℕ) (Xp W M J : ℕ) + (hW : 0(jointLaw X Xp W hW hX hXp).real {z}) (fun _ _=>measureReal_nonneg) + (conditioningLabel M J) {i | i.1∈E} (slotEvent slot A) c hc + rw [joint_real X Xp W hW hX hXp,joint_real X Xp W hW hX hXp, + joint_real X Xp W hW hX hXp] + simp only [Set.mem_ofPred_eq,conditional_mass_sum] + simp only [Set.mem_ofPred_eq,conditioningLabel] at hh + apply hh.trans_eq + apply Finset.sum_congr rfl + intro point _ + exact (ite_eq_ite _ _ _).mpr trivial + + + +theorem raw_pivot_extension {m V : ℕ} (X : Fin m→ℕ) (Xp W M J : ℕ) + (hW : 0{z | z.1∈E ∧ (z.2:ℤ)+slot v z.1∈A z.1} + have he : {z : (Fin m→ℕ)×ℕ | z.1∈E ∧ z∈slotEvent slot A}=⋃ v,F v := by + ext z + simp only [Set.mem_ofPred_eq,slotEvent,Set.mem_iUnion,F] + aesop + rw [he] + calc + _ ≤ ∑ v,(jointLaw X Xp W hW hX hXp).real (F v) := measureReal_iUnion_fintype_le F + _ ≤ ∑ _v : Fin V,((jointLaw X Xp W hW hX hXp).real + {z | z.1∈E ∧ (z.2:ℤ)∈A z.1}+4*(W:ℝ)*B/Xp) := by + apply Finset.sum_le_sum + intro v hv + have h:=(abs_le.mp (SourceJointShift.raw_joint_shift X Xp W hW hX hXp E A (slot v) B hB (hslot v))).2 + change (jointLaw X Xp W hW hX hXp).real {z | z.1∈E ∧ (z.2:ℤ)+slot v z.1∈A z.1}≤_ + linarith + _ = _ := by simp; ring + +end SourcePivotExtension + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PivotExtension02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotExtension02.lean new file mode 100644 index 0000000000000000000000000000000000000000..b554133ea088a08f47f87608c99c8397ea763e76 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotExtension02.lean @@ -0,0 +1,368 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.IntegerArrays14 +import OAI.Combinatorics.SumProduct.Alignment.PivotExtension01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +noncomputable section +end + +noncomputable section +namespace SourcePivotExtension +open MeasureTheory ProductExposureLaw ProductExposureLabels RoughFaceShift RawHarmonicProbability +open SourceIntegerArrays +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +private lemma unit_atom_pos (X W : ℕ) (hW : 0p/(M*J)=z.2/(M*J) ∧ p%M=z.2%M)):Set ℕ) := by + ext u + simp only [Finset.mem_coe,conditioningCell,Finset.mem_filter] + rw [full_support_mem] + simp only [conditioningLabel,Prod.mk.injEq,Set.mem_prod,Set.mem_singleton_iff, + Finset.mem_coe,Finset.mem_filter] + constructor + · rintro ⟨⟨hu,hp⟩,hy,hq,hr⟩ + exact ⟨hy,hp,hq,hr⟩ + · rintro ⟨hy,hp,hq,hr⟩ + exact ⟨⟨hy.symm ▸ hz,hp⟩,hy,hq,hr⟩ + +private lemma joint_rectangle_real {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) + (hW : 0p/(M*J)=z.2/(M*J) ∧ p%M=z.2%M) + let C : Set ℕ := {p | (z.1,p)∈slotEvent slot A} + let ν : Measure ℕ := (law Xp W hW hXp:Measure ℕ) + have heC : (conditioningCell X Xp W M J z:Set _)={z.1}×ˢ(F:Set ℕ) := + raw_cell_product X Xp W M J z hz + have heN : slotEvent slot A ∩ (conditioningCell X Xp W M J z:Set _) = + {z.1}×ˢ(C∩(F:Set ℕ)) := by + rw [heC] + ext u + simp only [Set.mem_inter_iff,Set.mem_prod,Set.mem_singleton_iff] + constructor + · rintro ⟨hu,hy,hp⟩ + have he : u=(z.1,u.2):=Prod.ext hy rfl + exact ⟨hy,(congrArg (fun t=>t∈slotEvent slot A) he).mp hu,hp⟩ + · rintro ⟨hy,hu,hp⟩ + have he : u=(z.1,u.2):=Prod.ext hy rfl + exact ⟨(congrArg (fun t=>t∈slotEvent slot A) he).mpr hu,hy,hp⟩ + have hr : conditionalSlotMass X Xp W M J hW hX hXp slot A z= + ν.real (C∩(F:Set ℕ))/ν.real (F:Set ℕ) := by + unfold conditionalSlotMass + rw [heN,heC,joint_rectangle_real,joint_rectangle_real] + exact mul_div_mul_left _ _ (outside_atom_pos X W hW hX z.1 hz).ne' + have hF : (F:Set ℕ)=(units Xp W:Set ℕ)∩(sourceCell M J z.2:Set ℕ) := by + ext p + simp only [F,Finset.mem_coe,Finset.mem_filter,Set.mem_inter_iff, + label_source_cell M J z.2 p hM hJ] + have hf : ν.real (F:Set ℕ)=ν.real (sourceCell M J z.2:Set ℕ) := by + rw [hF] + apply measureReal_congr + filter_upwards [law_ae_units Xp W hW hXp] with p hp + exact propext ⟨fun h=>h.2,fun h=>⟨hp,h⟩⟩ + have hn : ν.real (C∩(F:Set ℕ))=ν.real (C∩(sourceCell M J z.2:Set ℕ)) := by + rw [hF] + apply measureReal_congr + filter_upwards [law_ae_units Xp W hW hXp] with p hp + exact propext ⟨fun h=>⟨h.1,h.2.2⟩,fun h=>⟨h.1,hp,h.2⟩⟩ + have himage : (MicrocellFibers.point M (J*(z.2/(M*J))) (z.2%M) '' + {k | (z.1,MicrocellFibers.point M (J*(z.2/(M*J))) (z.2%M) k)∈slotEvent slot A}) ∩ + (sourceCell M J z.2:Set ℕ) = C∩(sourceCell M J z.2:Set ℕ) := by + ext p + constructor + · rintro ⟨⟨k,hk,rfl⟩,hp⟩ + exact ⟨hk,hp⟩ + · rintro ⟨hp,hC⟩ + obtain ⟨k,hk⟩:=MicrocellFibers.represent M J (J*(z.2/(M*J))) (z.2%M) p hM hC + refine ⟨⟨k.val,?_,hk⟩,hC⟩ + change (z.1,MicrocellFibers.point M (J*(z.2/(M*J))) (z.2%M) k.val)∈slotEvent slot A + rw [hk] + exact hp + rw [hr,hf,hn] + unfold cellRatio + rw [himage] + +end SourcePivotExtension +end + +noncomputable section +namespace SourceIntegerArrays.GlobalJoint.SourceFrozenFamily +open ProductExposureLabels SourceExposureSlots SourceResidueAlignment ConstructedWordPlan.GlobalWordPlan.SourceTerminalArithmetic +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales ConstructedWordPlan.RationalPivotPlan +open scoped BigOperators BoundedContinuousFunction +attribute [local instance] Classical.propDecidable +variable {a : ℕ} (D : Pivot a) +variable (s r : ℕ) (hs : 1 ≤ s) (Fs : Finset (Scale a)) (q₀ : ℕ) (b₀ : Scale a) +local notation "I" => FiniteModelSlots.Index D s r hs Fs q₀ b₀ +variable (G₀ : Fin D.targets→ℚ→Fin r→Type) +variable [∀ t v c,Group (G₀ t v c)] [∀ t v c,TopologicalSpace (G₀ t v c)] +variable (Γ₀ : ∀ t v c,Subgroup (G₀ t v c)) +variable (M J R H : ℕ→ℕ) (L : ℕ→ℤ) (C : ℕ→Fin D.pairs→ℤ) +variable (g₀ x₀ : ∀ t,ℕ→(Fin (h D t)→ℕ)→∀ v c,ℤ→ℤ→G₀ t v c) +variable (obs₀ : ∀ t,ℕ→(Fin (h D t)→ℕ)→∀ v c,ℤ→ℤ→((G₀ t v c)⧸Γ₀ t v c) →ᵇ ℝ) +variable (ht : ℕ→Fin a→ℤ) +open MeasureTheory SourcePivotExtension RawHarmonicProbability ProductExposureLaw +abbrev slotCount := Fintype.card {v : Slots D // v∈slots D s r hs Fs q₀ b₀} +def rawSlot (N : ℕ) (v : Fin (slotCount D s r hs Fs q₀ b₀)) (u : Fin a→ℕ) : ℤ := + slotValue D (L N) (heightCoeff D q₀ ht N) (fun j=>(u j:ℤ)) + ((Fintype.equivFin {v : Slots D // v∈slots D s r hs Fs q₀ b₀}).symm v).val +def pivotSet (N : ℕ) (τ : ℝ) (u : Fin a→ℕ) : Set ℤ := + {x | 0⟨h,hp⟩,fun h=>h.1⟩ + rw [he] + refine measureReal_mono ?_ (by finiteness) + rintro p ⟨⟨⟨k,hk,hkp⟩,hcell⟩,hpunit⟩ + refine ⟨⟨k,?_,hkp⟩,hcell⟩ + have hpge : (Xp:ℤ)≤(p:ℤ) := by + exact_mod_cast (Finset.mem_Ico.mp (Finset.mem_filter.mp hpunit).1).1 + have hpform : (p:ℤ)=firstPivot (M N) (J N) z.2+(M N:ℤ)*(k:ℤ) := by + rw [←hkp,firstPivot_eq_point] + simp only [f,MicrocellFibers.point,Nat.cast_add,Nat.cast_mul,mul_zero,add_zero] + have hread:=source_pivot_reading D s r hs Fs q₀ b₀ G₀ Γ₀ M J R H L g₀ x₀ obs₀ ht + N w z k p hq₀ hQq hw hL hWL hML hu hd hb₀ hFs hht hratio hpform + (fun v hv=>(hlarge v hv).trans_le hpge) τ + obtain ⟨v,hv,hpos,hprop⟩:=hread hk + let vv : {v : Slots D // v∈slots D s r hs Fs q₀ b₀}:=⟨v,hv⟩ + change ∃ j,(f k:ℤ)+slot j z.1∈A z.1 + refine ⟨(Fintype.equivFin _ ) vv,?_⟩ + dsimp only [slot,rawSlot] + rw [Equiv.symm_apply_apply,hkp] + exact ⟨hpos,hprop⟩ + +end SourceIntegerArrays.GlobalJoint.SourceFrozenFamily +end + +noncomputable section +namespace SourceIntegerArrays.GlobalJoint.SourceFrozenFamily +open ProductExposureLabels SourceExposureSlots SourceResidueAlignment ConstructedWordPlan.GlobalWordPlan.SourceTerminalArithmetic +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales ConstructedWordPlan.RationalPivotPlan +open scoped BigOperators BoundedContinuousFunction +attribute [local instance] Classical.propDecidable +variable {a : ℕ} (D : Pivot a) +variable (s r : ℕ) (hs : 1 ≤ s) (Fs : Finset (Scale a)) (q₀ : ℕ) (b₀ : Scale a) +local notation "I" => FiniteModelSlots.Index D s r hs Fs q₀ b₀ +variable (G₀ : Fin D.targets→ℚ→Fin r→Type) +variable [∀ t v c,Group (G₀ t v c)] [∀ t v c,TopologicalSpace (G₀ t v c)] +variable (Γ₀ : ∀ t v c,Subgroup (G₀ t v c)) +variable (M J R H : ℕ→ℕ) (L : ℕ→ℤ) (C : ℕ→Fin D.pairs→ℤ) +variable (g₀ x₀ : ∀ t,ℕ→(Fin (h D t)→ℕ)→∀ v c,ℤ→ℤ→G₀ t v c) +variable (obs₀ : ∀ t,ℕ→(Fin (h D t)→ℕ)→∀ v c,ℤ→ℤ→((G₀ t v c)⧸Γ₀ t v c) →ᵇ ℝ) +variable (ht : ℕ→Fin a→ℤ) +open MeasureTheory SourcePivotExtension RawHarmonicProbability ProductExposureLaw + + +def slotBudget : ℤ := ∑ v∈slots D s r hs Fs q₀ b₀,∑ e,|v e| + + +theorem source_actual_extension (N w : ℕ) (X : Fin a→ℕ) (Xp : ℕ) + (hW : 0Finset.sum_nonneg (fun e he=>abs_nonneg _)) + have hbudget (v : Slots D) (hv : v∈slots D s r hs Fs q₀ b₀) : + (∑ e,|v e|) ≤ slotBudget D s r hs Fs q₀ b₀:= by + unfold slotBudget + exact Finset.single_le_sum (f:=fun v : Slots D=>∑ e,|v e|) + (fun v hv=>Finset.sum_nonneg (fun e he=>abs_nonneg (v e))) hv + have hB : 0≤B:=mul_nonneg (by exact_mod_cast hbudget0) (by exact_mod_cast hL.le) + have hunits (y : Fin a→ℕ) (hy : y∈outsideDomain X (primorial w)) (j : Fin a) : + IsCoprime (y j:ℤ) (L N) := by + have hj:=(Finset.mem_filter.mp (Fintype.mem_piFinset.mp hy j)).2 + apply (RoughScales.coprime_smooth_rough hsm _).symm + apply (RoughScales.rough_iff_coprime w (y j:ℤ)).mpr + simpa only [Int.natAbs_natCast] using hj.symm + have ht₁:=(source_terminal_arithmetic D (outcomeScales D s r hs Fs b₀)).choose_spec.2 + q₀ hq₀ hQq w hw 1 (by simp [outcomeScales]) (by intro j;exact zero_lt_one) + (ht N) (fun _=>1) hht hratio + have hcoeff : ∀ e,(primorial w:ℤ)∣heightCoeff D q₀ ht N e := by + intro e + simpa [heightCoeff,coefficient,height] using ht₁.1 e + have hslot : ∀ v y,y∈outsideDomain X (primorial w) → + (primorial w:ℤ)∣slot v y ∧ |(slot v y:ℝ)|≤B := by + intro i y hy + let v:=((Fintype.equivFin {v : Slots D // v∈slots D s r hs Fs q₀ b₀}).symm i).val + have hv : v∈slots D s r hs Fs q₀ b₀:=((Fintype.equivFin _).symm i).property + change (primorial w:ℤ)∣slotValue D (L N) (heightCoeff D q₀ ht N) (fun j=>(y j:ℤ)) v ∧ _ + by_cases hn : Nonempty (Fin D.targets) + · let t:=Classical.choice hn + have hh:=(source_exposure_slots D (L N) (primorial w:ℤ) hL hWL (heightCoeff D q₀ ht N) hcoeff + (fun j=>(y j:ℤ)) (fun j=>(y j:ℤ)) (hunits y hy) t + (fun j hj=>Int.ModEq.refl _) (fun j hj=>rfl) hd).2.2 v + refine ⟨hh.2.1,?_⟩ + have hbi:=hh.2.2.trans (mul_le_mul_of_nonneg_right (hbudget v hv) hL.le) + change |(slotValue D (L N) (heightCoeff D q₀ ht N) (fun j=>(y j:ℤ)) v:ℝ)|≤_ + dsimp only [B] + exact_mod_cast hbi + · let : IsEmpty (Fin D.pairs):=⟨fun e=>hn ⟨D.owner e⟩⟩ + simp only [slotValue,Finset.univ_eq_empty,Finset.sum_empty,dvd_zero,true_and] + change |((∑ e,v e*rValue D (L N) (heightCoeff D q₀ ht N) (fun j=>(y j:ℤ)) e:ℤ):ℝ)|≤B + simpa using hB + have ho : ∀ᵐ z ∂μ,z.1∈outsideDomain X (primorial w) := + (measurePreserving_fst (μ:=outsideLaw X (primorial w) hW hX) + (ν:=(law Xp (primorial w) hW hXp:Measure ℕ))).quasiMeasurePreserving.ae + (outside_ae_domain X (primorial w) hW hX) + have hbad : μ.real {z | conditionalSlotMass X Xp (primorial w) (M N) (J N) hW hX hXp slot A z≤c}≤μ.real bad := by + apply ENNReal.toReal_mono (by finiteness) + apply measure_mono_ae + filter_upwards [ho] with z hz + intro hpost + have hh:=source_posterior_domination D s r hs Fs q₀ b₀ G₀ Γ₀ M J R H L g₀ x₀ obs₀ ht + N w z X Xp hW hX hXp hz hM hJ hq₀ hQq hw hL hWL hML (hunits z.1 hz) hd hb₀ hFs hht hratio + (fun v hv=>(mul_le_mul_of_nonneg_right (hbudget v hv) hL.le).trans_lt hlarge) τ + exact hh.trans hpost + have hh:=raw_pivot_extension X Xp (primorial w) (M N) (J N) hW hX hXp E A slot B c hB hc hslot + change c*(μ.real {z | z.1∈E}-μ.real bad)≤_ + apply le_trans (mul_le_mul_of_nonneg_left (sub_le_sub_left hbad _) hc) + apply hh.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + have hp : μ.real {z | z.1∈E ∧ (z.2:ℤ)∈A z.1}≤ + μ.real {z | z.1∈E ∧ pivotProperty D s r hs Fs b₀ G₀ Γ₀ M H g₀ x₀ obs₀ ht N z.1 z.2 τ} := by + refine measureReal_mono ?_ (by finiteness) + rintro z ⟨hz,hp⟩ + exact ⟨hz,hp.2⟩ + have he : 4*(primorial w:ℝ)*B/Xp=4*(primorial w:ℝ)*(slotBudget D s r hs Fs q₀ b₀:ℝ)*(L N:ℝ)/Xp := by + dsimp [B] + ring + rw [he] + exact add_le_add hp le_rfl + +end SourceIntegerArrays.GlobalJoint.SourceFrozenFamily + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths01.lean new file mode 100644 index 0000000000000000000000000000000000000000..e98c14a892cb07d0ee543f1dd8c5489da2462a07 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths01.lean @@ -0,0 +1,276 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.IntegerArrays14 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +noncomputable section +open scoped BigOperators BoundedContinuousFunction Topology NNReal ENNReal +end + + + + + + + +noncomputable section +open Filter MeasureTheory +open scoped BigOperators ENNReal Topology +namespace SourceRawPrefix +variable {n : ℕ} + + +def Earlier (i : Fin n) (E : Set (Fin n → ℕ)) : Prop := + ∀ u v, (∀ j, j < i → u j = v j) → (u ∈ E ↔ v ∈ E) + +def Through (i : Fin n) (E : Set (Fin n → ℕ)) : Prop := + ∀ u v, (∀ j, j ≤ i → u j = v j) → (u ∈ E ↔ v ∈ E) + +lemma Earlier.update_iff {i : Fin n} {E : Set (Fin n → ℕ)} (hE : Earlier i E) + (u : Fin n → ℕ) (x : ℕ) : Function.update u i x ∈ E ↔ u ∈ E := by + apply hE + intro j hj + exact Function.update_of_ne (ne_of_lt hj) _ _ + +lemma Through.earlier {i j : Fin n} {E : Set (Fin n → ℕ)} (hE : Through i E) + (hij : i < j) : Earlier j E := by + intro u v huv + apply hE + intro k hk + exact huv k (hk.trans_lt hij) + +lemma earlier_univ (i : Fin n) : Earlier i Set.univ := by + intro u v h + simp + +lemma through_inter {i : Fin n} {E F : Set (Fin n → ℕ)} + (hE : Through i E) (hF : Through i F) : Through i (E ∩ F) := by + intro u v h + exact and_congr (hE u v h) (hF u v h) + + + +theorem resample_preserves (ν : Fin n → Measure ℕ) [∀ i, IsProbabilityMeasure (ν i)] + (i : Fin n) : + MeasurePreserving (fun z : (Fin n → ℕ) × ℕ => Function.update z.1 i z.2) + ((Measure.pi ν).prod (ν i)) (Measure.pi ν) := by + refine ⟨measurable_of_countable _, ?_⟩ + apply Measure.ext_of_singleton + intro u + rw [Measure.map_apply (measurable_of_countable _) (measurableSet_singleton _)] + have he : (fun z : (Fin n → ℕ) × ℕ => Function.update z.1 i z.2) ⁻¹' {u} = + (Set.univ.pi (Function.update (fun j => {u j}) i Set.univ)) ×ˢ {u i} := by + ext z + simp only [Set.mem_preimage, Set.mem_singleton_iff, Set.mem_prod, + Set.mem_pi, Set.mem_univ, forall_true_left] + constructor + · intro hz + constructor + · intro j + by_cases hji : j = i + · subst j; simp + · simpa [Function.update_of_ne hji] using congrFun hz j + · simpa using congrFun hz i + · rintro ⟨hy,hx⟩ + ext j + by_cases hji : j = i + · subst j; simpa using hx + · simpa [Function.update_of_ne hji] using hy j + rw [he, Measure.prod_prod, Measure.pi_pi, Measure.pi_singleton] + have hf : (fun j => ν j (Function.update (fun k : Fin n => ({u k} : Set ℕ)) i (Set.univ : Set ℕ) j)) = + Function.update (fun j => ν j {u j}) i 1 := by + funext j + by_cases hji : j = i + · subst j; simp + · simp [hji] + rw [hf, Finset.prod_update_of_mem (Finset.mem_univ i)] + simp only [one_mul] + simpa only [Finset.sdiff_singleton_eq_erase] using Finset.prod_erase_mul Finset.univ (fun j => ν j {u j}) (Finset.mem_univ i) + +open RawHarmonicProbability ProductExposureLaw + +lemma raw_resample (X : Fin n → ℕ) (W : ℕ) (hW : 0 < W) + (hX : ∀ j, 4*W ≤ X j) (i : Fin n) : + MeasurePreserving (fun z : (Fin n → ℕ) × ℕ => Function.update z.1 i z.2) + (jointLaw X (X i) W hW hX (hX i)) (outsideLaw X W hW hX) := + resample_preserves (fun j => (law (X j) W hW (hX j) : Measure ℕ)) i + + +lemma raw_resample_real (X : Fin n → ℕ) (W : ℕ) (hW : 0 < W) + (hX : ∀ j, 4*W ≤ X j) (i : Fin n) (E : Set (Fin n → ℕ)) : + (jointLaw X (X i) W hW hX (hX i)).real + {z | Function.update z.1 i z.2 ∈ E} = (outsideLaw X W hW hX).real E := by + apply congrArg ENNReal.toReal + exact (raw_resample X W hW hX i).measure_preimage (Set.to_countable E).measurableSet.nullMeasurableSet + +end SourceRawPrefix + + + + + + + +noncomputable section +open scoped BigOperators Topology BoundedContinuousFunction +namespace SourcePivotPaths +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales +open ConstructedWordPlan.RationalPivotPlan +open ConstructedWordPlan.GlobalWordPlan.SourceTerminalArithmetic +open SourceIntegerArrays.GlobalJoint.SourceFrozenFamily +open SourceRawPrefix +attribute [local instance] Classical.propDecidable +variable {a : ℕ} (D : Pivot a) (r : ℕ) + + + +abbrev ScalarModels := Fin D.targets → ℚ → Fin r → ℤ → ℝ + + +def comparison (S : ScalarModels D r) (ht : Fin a → ℤ) (b : Scale a) + (u : Fin a → ℕ) (x : ℕ) (τ : ℝ) : Prop := + ∀ (t : Fin D.targets) (U : OwnSubset D t) (c : Fin r), + let av := blockProduct b (block D.index D.tail t) + ∃ Δ : ℤ, + (Δ : ℚ) = ∑ e ∈ U.val, + ((height ht (D.added e) : ℚ)*blockProduct b (D.added e)/ + ((height ht (block D.index D.tail (D.owner e)) : ℚ)* + blockProduct b (block D.index D.tail (D.owner e))))* + (height (fun j => (u j : ℤ)) (D.added e) : ℚ) ∧ + (2*τ < S t av c (height (fun j => (u j : ℤ)) (D.tail t)*(x : ℤ)) → + τ < S t av c (height (fun j => (u j : ℤ)) (D.tail t)*(x : ℤ)+Δ)) + + +def outcome (Fs : Finset (Scale a)) (S : ScalarModels D r) (ht : Fin a → ℤ) + (b : Scale a) (p : Path D) (u : Fin a → ℕ) (x : ℕ) (τ : ℝ) : Prop := + ∀ d ∈ Fs, comparison D r S ht (scaleRun D 0 p b*d) u x τ + +def success (s : ℕ) (hs : 1 ≤ s) (Fs : Finset (Scale a)) + (S : ScalarModels D r) (ht : Fin a → ℤ) (b : Scale a) + (u : Fin a → ℕ) (x : ℕ) (τ : ℝ) : Prop := + ∃ p ∈ pivotOptions s r hs D Fs, outcome D r Fs S ht b p u x τ + +lemma comparison_congr (S : ScalarModels D r) (ht : Fin a → ℤ) (b : Scale a) + (u v : Fin a → ℕ) (huv : ∀ j, j < D.index → u j = v j) (x : ℕ) (τ : ℝ) : + comparison D r S ht b u x τ ↔ comparison D r S ht b v x τ := by + have ha (e) : height (fun j => (u j : ℤ)) (D.added e) = + height (fun j => (v j : ℤ)) (D.added e) := by + apply Finset.prod_congr rfl + intro j hj + exact congrArg (fun m : ℕ => (m : ℤ)) (huv j (D.added_lt e j hj)) + have ht' (t) : height (fun j => (u j : ℤ)) (D.tail t) = + height (fun j => (v j : ℤ)) (D.tail t) := by + apply Finset.prod_congr rfl + intro j hj + exact congrArg (fun m : ℕ => (m : ℤ)) (huv j (D.tail_lt t j hj)) + simp only [comparison, ha, ht'] + +lemma comparison_through (S : ScalarModels D r) (ht : Fin a → ℤ) (b : Scale a) (τ : ℝ) : + Through D.index {u | comparison D r S ht b u (u D.index) τ} := by + intro u v huv + change comparison D r S ht b u (u D.index) τ ↔ comparison D r S ht b v (v D.index) τ + rw [huv D.index le_rfl] + exact comparison_congr D r S ht b u v (fun j hj => huv j hj.le) _ τ + +lemma outcome_through (Fs : Finset (Scale a)) (S : ScalarModels D r) + (ht : Fin a → ℤ) (b : Scale a) (p : Path D) (τ : ℝ) : + Through D.index {u | outcome D r Fs S ht b p u (u D.index) τ} := by + intro u v huv + simp only [Set.mem_ofPred_eq, outcome] + apply forall_congr' + intro d + apply forall_congr' + intro hd + exact comparison_through D r S ht _ τ u v huv + +lemma success_through (s : ℕ) (hs : 1 ≤ s) (Fs : Finset (Scale a)) + (S : ScalarModels D r) (ht : Fin a → ℤ) (b : Scale a) (τ : ℝ) : + Through D.index {u | success D r s hs Fs S ht b u (u D.index) τ} := by + intro u v huv + simp only [Set.mem_ofPred_eq, success] + apply exists_congr + intro p + apply and_congr_right + intro hp + exact outcome_through D r Fs S ht b p τ u v huv + +lemma success_update_iff (s : ℕ) (hs : 1 ≤ s) (Fs : Finset (Scale a)) + (S : ScalarModels D r) (ht : Fin a → ℤ) (b : Scale a) + (u : Fin a → ℕ) (x : ℕ) (τ : ℝ) : + success D r s hs Fs S ht b (Function.update u D.index x) x τ ↔ + success D r s hs Fs S ht b u x τ := by + simp only [success, outcome] + apply exists_congr + intro p + apply and_congr_right + intro hp + apply forall_congr' + intro d + apply forall_congr' + intro hd + apply comparison_congr + intro j hj + exact Function.update_of_ne (ne_of_lt hj) _ _ + +section OriginalModels +variable (s : ℕ) (hs : 1 ≤ s) (Fs : Finset (Scale a)) (b : Scale a) +variable (G : Fin D.targets → ℚ → Fin r → Type) + [∀ t v c, Group (G t v c)] [∀ t v c, TopologicalSpace (G t v c)] + (Γ : ∀ t v c, Subgroup (G t v c)) + (M H : ℕ → ℕ) (ht : ℕ → Fin a → ℤ) + (g x : ∀ t, ℕ → ∀ v c, ℤ → ℤ → G t v c) + (F : ∀ t, ℕ → ∀ v c, ℤ → ℤ → ((G t v c) ⧸ Γ t v c) →ᵇ ℝ) + +def scalarModels (N : ℕ) : ScalarModels D r := + fun t v c k => SourceIntegerArrays.pieceModel (Γ t v c) (M N) (H N) + (g t N v c) (x t N v c) (fun b r => F t N v c b r) k + + +lemma original_success (N : ℕ) (u : Fin a → ℕ) (xp : ℕ) (τ : ℝ) : + pivotProperty D s r hs Fs b G Γ M H + (fun t N _ => g t N) (fun t N _ => x t N) (fun t N _ => F t N) ht N u xp τ ↔ + success D r s hs Fs (scalarModels D r G Γ M H g x F N) (ht N) b u xp τ := by + simp only [pivotProperty, success] + apply exists_congr + intro p + apply and_congr_right + intro hp + constructor + · intro h d hd t U c + exact h (⟨d,hd⟩,⟨t,U⟩,c) + · intro h i + exact h i.1.val i.1.property i.2.1.1 i.2.1.2 i.2.2 +end OriginalModels + +open MeasureTheory ProductExposureLaw RawHarmonicProbability + + + +theorem success_mass_resample (s : ℕ) (hs : 1 ≤ s) (Fs : Finset (Scale a)) + (S : ScalarModels D r) (ht : Fin a → ℤ) (b : Scale a) (τ : ℝ) + (X : Fin a → ℕ) (W : ℕ) (hW : 0 < W) (hX : ∀ j, 4*W ≤ X j) + (E : Set (Fin a → ℕ)) (hE : Earlier D.index E) : + (jointLaw X (X D.index) W hW hX (hX D.index)).real + {z | z.1 ∈ E ∧ success D r s hs Fs S ht b z.1 z.2 τ} = + (outsideLaw X W hW hX).real + {u | u ∈ E ∧ success D r s hs Fs S ht b u (u D.index) τ} := by + rw [← raw_resample_real X W hW hX D.index] + congr 1 + ext z + simp only [Set.mem_ofPred_eq, Function.update_self, hE.update_iff, + success_update_iff] + +end SourcePivotPaths + + + + + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths02.lean new file mode 100644 index 0000000000000000000000000000000000000000..f68715f6f5ba08e6efa1679570841c212dd08df2 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths02.lean @@ -0,0 +1,406 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.HierarchyRates01 +import OAI.Combinatorics.SumProduct.Alignment.PivotPaths01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +noncomputable section +open Filter MeasureTheory +open scoped BigOperators ENNReal Topology +noncomputable section +open scoped BigOperators Topology BoundedContinuousFunction +noncomputable section +open scoped BigOperators BoundedContinuousFunction Topology NNReal ENNReal +namespace SourceIntegerArrays.GlobalJoint.SourceFrozenFamily +open ProductExposureLabels ProductExposureLaw SourceExposureSlots SourceResidueAlignment +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales +open ConstructedWordPlan.RationalPivotPlan +open ConstructedWordPlan.GlobalWordPlan.SourceTerminalArithmetic +open RawHarmonicProbability +attribute [local instance] Classical.propDecidable +variable {a : ℕ} (D : Pivot a) + +variable (s r : ℕ) (hs : 1 ≤ s) (Fs : Finset (Scale a)) (q₀ : ℕ) (b₀ : Scale a) +local notation "I" => FiniteModelSlots.Index D s r hs Fs q₀ b₀ + +open Filter MeasureTheory RationalLattice MalcevCharacters +open MicrocellScale AdmissibleMicrocellBoundary RoughScales IntegerAlignment +open RoughSamplingWeights SourceMacroSelection + +section Harmonic +variable (G₀ : Fin D.targets → ℚ → Fin r → Type) +variable [∀ t v c, Group (G₀ t v c)] [∀ t v c, TopologicalSpace (G₀ t v c)] +variable [∀ t v c, IsTopologicalGroup (G₀ t v c)] +variable (Γ₀ : ∀ t v c, Subgroup (G₀ t v c)) +variable (n₀ : Fin D.targets → ℚ → Fin r → ℕ) +variable (c₀ : ∀ t v c, RealCoordinates (G₀ t v c) (n₀ t v c)) +variable (hsk : ∀ t v c, SecondKind (c₀ t v c)) +variable (A₀ : ∀ t v c, CubeFaces.Filtration (G₀ t v c)) +variable (weight : ∀ t v c, Fin (n₀ t v c) → ℕ) +variable (hA : ∀ t v c k (g : G₀ t v c), g ∈ (A₀ t v c).level k ↔ + ∀ j, weight t v c j < k → (c₀ t v c).coord g j = 0) +variable (hw : ∀ t v c j, 0 < weight t v c j) +include hsk hA hw +open SourcePivotPaths SourceRawPrefix + + + +theorem source_uniform_prefix_extension + (hΓ : ∀ t v c g, g ∈ Γ₀ t v c ↔ ∀ j, ∃ z : ℤ, (c₀ t v c).coord g j = z) + (hmono : ∀ t v c, Monotone (weight t v c)) + (h0 : ∀ t v c, (A₀ t v c).level 0 = ⊤) + (h1 : ∀ t v c, (A₀ t v c).level 1 = ⊤) + (hstep : ∀ t v c, (A₀ t v c).level (s+1) = ⊥) + (M J R H : ℕ → ℕ) (L : ℕ → ℤ) (ht : ℕ → Fin a → ℤ) + (g₀ x₀ : ∀ t, ℕ → ∀ v c, ℤ → ℤ → G₀ t v c) + (obs₀ : ∀ t, ℕ → ∀ v c, ℤ → ℤ → ((G₀ t v c) ⧸ Γ₀ t v c) →ᵇ ℝ) + (w0 : ℕ → ℕ) (X : ℕ → Fin a → ℕ) + (hw0 : Tendsto w0 atTop atTop) + (hX : ∀ N j, 4*primorial (w0 N) ≤ X N j) + (hXt : ∀ j, Tendsto (fun N => X N j) atTop atTop) + (hWM : ∀ N, (primorial (w0 N) : ℤ) ∣ (M N : ℤ)) + (hM : ∀ N, 0 < M N) (hMs : ∀ N, RoughScales.Smooth (w0 N) (M N : ℤ)) + (hJ : ∀ N, 0 < J N) (hRJ : ∀ N, R N = M N*J N) + (hL : ∀ N, 0 < L N) (hsm : ∀ N, RoughScales.Smooth (w0 N) (L N)) + (hWL : ∀ N, (primorial (w0 N) : ℤ) ∣ L N) (hML : ∀ N, (M N : ℤ) ∣ L N) + (hLexact : ∀ N, L N = (M N : ℤ)*(primorial (w0 N) : ℤ)^(w0 N)) + (hXL : ∀ t (j : Fin (m D t)), Tendsto (fun N => + (X N (perm D t (j.castAdd (h D t))) : ℝ)/(L N : ℝ)) atTop atTop) + (hH : ∀ N, 0 < H N) (hRrad : ∀ N, R N = radius (M N) (H N)) + (hdom : Dominates (fun N => (H N : ℝ)) (earlierScale M (fun N => previousProduct D (X N)))) + (hxdom : Dominates (fun N => Real.log (X N D.index : ℝ)) (fun N => (H N : ℝ))) + (hpowWM : ∀ N, primorial (w0 N)^(w0 N) ∣ M N) + (hq₀ : 0 < q₀) (hht : ∀ N j, 0 < ht N j) + (hheight : ∀ N e, height (ht N) (D.added e) ≤ M N) + (hd : ∀ e, Disjoint (D.added e) (D.tail (D.owner e))) + (hQq : terminalDenom D s r hs Fs b₀ ∣ q₀) + (hb₀ : ∀ j, 0 < b₀ j) (hFs : ∀ b ∈ Fs, ∀ j, 0 < b j) + (hratio : ∀ N e, ∃ d : ℤ, height (ht N) (D.added e) = + height (ht N) (block D.index D.tail (D.owner e)) * ((primorial (w0 N) : ℤ)^(w0 N) * d)) + (metric : ∀ t v c, MetricSpace ((G₀ t v c) ⧸ Γ₀ t v c)) + (hmetric : ∀ t v c, QuotientGroup.instTopologicalSpace (Γ₀ t v c) = + (metric t v c).toUniformSpace.toTopologicalSpace) : + letI : ∀ t v c, MetricSpace ((G₀ t v c) ⧸ Γ₀ t v c) := + fun t v c => (metric t v c).replaceTopology (hmetric t v c) + ∀ (Kobs : ℝ≥0) (Bobs : ℝ), + (∀ t N v c b r', LipschitzWith Kobs (obs₀ t N v c b r')) → + (∀ t N v c b r' z, |obs₀ t N v c b r' z| ≤ Bobs) → + ∀ (Bs : Finset (Scale a)), b₀ ∈ Bs → + pivotModulus s r hs D Fs Bs ∣ q₀ → ∀ (τ : ℝ), 0 < τ → + ∀ ε : ℝ, 0 < ε → ∀ᶠ N in atTop, ∀ E : Set (Fin a → ℕ), Earlier D.index E → + let μ := outsideLaw (X N) (primorial (w0 N)) (primorial_pos _) (hX N) + let Q : ℝ := (pivotOptions s r hs D Fs).card + (Q⁻¹/3/Q)*μ.real E ≤ μ.real {u | u ∈ E ∧ + success D r s hs Fs (scalarModels D r G₀ Γ₀ M H g₀ x₀ obs₀ N) (ht N) b₀ u (u D.index) τ} + ε := by + let : ∀ t v c, MetricSpace ((G₀ t v c) ⧸ Γ₀ t v c) := + fun t v c => (metric t v c).replaceTopology (hmetric t v c) + intro Kobs Bobs hLip hBound Bs hb hq τ hτ ε hε + let Q : ℝ := (pivotOptions s r hs D Fs).card + have hQ : 0 < Q := by + dsimp only [Q] + exact_mod_cast Finset.card_pos.mpr (pivotOptions_nonempty s r hs D Fs) + have hV : (slotCount D s r hs Fs q₀ b₀ : ℝ) ≤ Q := by + have hh : slotCount D s r hs Fs q₀ b₀ ≤ (pivotOptions s r hs D Fs).card := by + dsimp only [slotCount] + rw [Fintype.card_coe (slots D s r hs Fs q₀ b₀)] + unfold slots + exact Finset.card_image_le + dsimp only [Q] + exact_mod_cast hh + have hExt := source_uniform_extension D s r hs Fs q₀ b₀ G₀ Γ₀ n₀ c₀ hsk A₀ weight hA hw + hΓ hmono h0 h1 hstep M J R H L ht (fun t N _ => g₀ t N) (fun t N _ => x₀ t N) + (fun t N _ => obs₀ t N) w0 (fun N => X N D.index) X hw0 hX (fun N => hX N D.index) + hXt (hXt D.index) hWM hM hMs hJ hRJ hL hsm hWL hML hLexact hXL hH hRrad hdom hxdom + hpowWM hq₀ hht hheight hd hQq hb₀ hFs hratio metric hmetric Kobs Bobs + (fun t N _ v c b r' => hLip t N v c b r') + (fun t N _ v c b r' z => hBound t N v c b r' z) + Bs hb hq τ hτ (ε*Q) (mul_pos hε hQ) + filter_upwards [hExt] with N hN + intro E hE + let μ := outsideLaw (X N) (primorial (w0 N)) (primorial_pos _) (hX N) + let ν := jointLaw (X N) (X N D.index) (primorial (w0 N)) (primorial_pos _) (hX N) (hX N D.index) + let S := scalarModels D r G₀ Γ₀ M H g₀ x₀ obs₀ N + have hEarly : ν.real {z | z.1 ∈ E} = μ.real E := by + apply congrArg ENNReal.toReal + exact (measurePreserving_fst (μ := μ) + (ν := (law (X N D.index) (primorial (w0 N)) (primorial_pos _) (hX N D.index) : Measure ℕ))).measure_preimage + (Set.to_countable E).measurableSet.nullMeasurableSet + have he := hN E + simp_rw [original_success] at he + change (Q⁻¹/3)*ν.real {z | z.1 ∈ E} ≤ (slotCount D s r hs Fs q₀ b₀ : ℝ)* + ν.real {z | z.1 ∈ E ∧ success D r s hs Fs S (ht N) b₀ z.1 z.2 τ}+ε*Q at he + rw [hEarly, success_mass_resample D r s hs Fs S (ht N) b₀ τ (X N) + (primorial (w0 N)) (primorial_pos _) (hX N) E hE] at he + have hem := mul_le_mul_of_nonneg_right hV + (show 0 ≤ μ.real {u | u ∈ E ∧ success D r s hs Fs S (ht N) b₀ u (u D.index) τ} from measureReal_nonneg) + change (Q⁻¹/3/Q)*μ.real E ≤ μ.real {u | u ∈ E ∧ + success D r s hs Fs S (ht N) b₀ u (u D.index) τ}+ε + apply (mul_le_mul_iff_right₀ hQ).mp + calc + _ = (Q⁻¹/3)*μ.real E := by field_simp + _ ≤ Q*μ.real {u | u ∈ E ∧ success D r s hs Fs S (ht N) b₀ u (u D.index) τ}+ε*Q := + he.trans (add_le_add hem le_rfl) + _ = _ := by ring + +end Harmonic +end SourceIntegerArrays.GlobalJoint.SourceFrozenFamily +end + + + + + + + +noncomputable section +open scoped BigOperators +open MeasureTheory Filter Function +namespace SourcePivotPaths +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales +open ConstructedWordPlan.RationalPivotPlan +open SourceRawPrefix +attribute [local instance] Classical.propDecidable +variable {a : ℕ} (s r : ℕ) (hs : 1 ≤ s) + +def sourcePlan : (Ds : List (Pivot a)) → Plan Ds + | [] => () + | D :: Ds => (pivotOptions s r hs D (multipliers (sourcePlan Ds)), sourcePlan Ds) + +def gain (D : Pivot a) (Fs : Finset (Scale a)) : ℝ := + ((pivotOptions s r hs D Fs).card : ℝ)⁻¹/3/(pivotOptions s r hs D Fs).card + +lemma gain_pos (D : Pivot a) (Fs : Finset (Scale a)) : 0 < gain s r hs D Fs := by + have hp : 0 < ((pivotOptions s r hs D Fs).card : ℝ) := by + exact_mod_cast Finset.card_pos.mpr (pivotOptions_nonempty s r hs D Fs) + exact div_pos (div_pos (inv_pos.mpr hp) (by norm_num)) hp + +lemma gain_le_one (D : Pivot a) (Fs : Finset (Scale a)) : gain s r hs D Fs ≤ 1 := by + have hp : 1 ≤ ((pivotOptions s r hs D Fs).card : ℝ) := by + exact_mod_cast Finset.card_pos.mpr (pivotOptions_nonempty s r hs D Fs) + have hi : ((pivotOptions s r hs D Fs).card : ℝ)⁻¹ ≤ 1 := inv_le_one_of_one_le₀ hp + unfold gain + apply div_le_one_of_le₀ _ (by linarith) + exact (div_le_self (inv_nonneg.mpr (by linarith)) (by norm_num : (1 : ℝ) ≤ 3)).trans (hi.trans hp) + +def delta : List (Pivot a) → ℝ + | [] => 1 + | D :: Ds => gain s r hs D (multipliers (sourcePlan s r hs Ds)) * delta Ds + +def errorCost : List (Pivot a) → ℕ + | [] => 0 + | D :: Ds => 1 + (pivotOptions s r hs D (multipliers (sourcePlan s r hs Ds))).card * errorCost Ds + +lemma delta_pos (Ds : List (Pivot a)) : 0 < delta s r hs Ds := by + induction Ds with + | nil => exact zero_lt_one + | cons D Ds ih => exact mul_pos (gain_pos s r hs D _) ih + +lemma delta_le_one (Ds : List (Pivot a)) : delta s r hs Ds ≤ 1 := by + induction Ds with + | nil => exact le_rfl + | cons D Ds ih => + exact (mul_le_mul_of_nonneg_left ih (gain_pos s r hs D _).le).trans (by simpa using gain_le_one s r hs D (multipliers (sourcePlan s r hs Ds))) + +variable (S : (D : Pivot a) → ScalarModels D r) (ht : Fin a → ℤ) (τ : ℝ) + + + +def runSuccess : List (Pivot a) → Scale a → (Fin a → ℕ) → Prop + | [], _, _ => True + | D :: Ds, b, u => ∃ p ∈ (sourcePlan s r hs (D :: Ds)).1, + outcome D r (multipliers (sourcePlan s r hs Ds)) (S D) ht b p u (u D.index) τ ∧ + runSuccess Ds (scaleRun D 0 p b) u + + +theorem runSuccess_final (Ds : List (Pivot a)) (b : Scale a) (u : Fin a → ℕ) + (h : runSuccess s r hs S ht τ Ds b u) : + ∃ p : ChoicePath Ds, Admitted (sourcePlan s r hs Ds) p ∧ + ∀ D ∈ Ds, comparison D r (S D) ht (b * pathMultiplier p) u (u D.index) τ := by + induction Ds generalizing b with + | nil => exact ⟨(), True.intro, by simp⟩ + | cons D Ds ih => + obtain ⟨p,hp,hhead,htail⟩ := h + obtain ⟨q,hq,hfinal⟩ := ih (scaleRun D 0 p b) htail + refine ⟨(p,q), ⟨hp,hq⟩, ?_⟩ + have he : b * pathMultiplier (Ds := D :: Ds) (p,q) = + scaleRun D 0 p b * pathMultiplier q := by + change b * (scaleRun D 0 p 1 * pathMultiplier q) = _ + rw [scaleRun_eq_mul D p 0 b, mul_assoc] + intro E hE + rw [he] + rcases List.mem_cons.mp hE with rfl | hE + · exact hhead (pathMultiplier q) (pathMultiplier_mem _ _ hq) + · exact hfinal E hE + +variable (μ : Measure (Fin a → ℕ)) [IsProbabilityMeasure μ] + + + +def stepBounds (η : ℝ) : List (Pivot a) → Scale a → Prop + | [], _ => True + | D :: Ds, b => + (∀ E : Set (Fin a → ℕ), Earlier D.index E → + gain s r hs D (multipliers (sourcePlan s r hs Ds)) * μ.real E ≤ + μ.real {u | u ∈ E ∧ success D r s hs (multipliers (sourcePlan s r hs Ds)) + (S D) ht b u (u D.index) τ} + η) ∧ + ∀ p ∈ (sourcePlan s r hs (D :: Ds)).1, + stepBounds η Ds (scaleRun D 0 p b) + +private lemma through_disjointed {i : Fin a} {v : ℕ} + (f : Fin v → Set (Fin a → ℕ)) (h : ∀ j, Through i (f j)) (j : Fin v) : + Through i (disjointed f j) := by + intro u w huw + simp only [disjointed_eq_inter_compl, Set.mem_inter_iff, Set.mem_iInter, + Set.mem_compl_iff] + exact and_congr (h j u w huw) (forall_congr' (fun k => forall_congr' (fun _ => not_congr (h k u w huw)))) + + + +theorem iterate_mass (Ds : List (Pivot a)) (b : Scale a) + (horder : Ds.Pairwise (fun D E => D.index < E.index)) + (η : ℝ) (hη : 0 ≤ η) (hsteps : stepBounds s r hs S ht τ μ η Ds b) + (E : Set (Fin a → ℕ)) (hE : ∀ D ∈ Ds, Earlier D.index E) : + delta s r hs Ds * μ.real E ≤ + μ.real {u | u ∈ E ∧ runSuccess s r hs S ht τ Ds b u} + errorCost s r hs Ds * η := by + induction Ds generalizing b E with + | nil => simp [delta, runSuccess, errorCost] + | cons D Ds ih => + let P := pivotOptions s r hs D (multipliers (sourcePlan s r hs Ds)) + let f : Fin P.card → Path D := fun j => ((Finset.equivFin P).symm j).val + have hf (j : Fin P.card) : f j ∈ P := ((Finset.equivFin P).symm j).property + let A (j : Fin P.card) : Set (Fin a → ℕ) := {u | u ∈ E ∧ + outcome D r (multipliers (sourcePlan s r hs Ds)) (S D) ht b (f j) u (u D.index) τ} + let C := disjointed A + have hEh : Earlier D.index E := hE D (by simp) + have hEth : Through D.index E := fun u v hv => hEh u v (fun j hj => hv j hj.le) + have hCth (j : Fin P.card) : Through D.index (C j) := + through_disjointed A (fun j => through_inter hEth (outcome_through D r _ (S D) ht b (f j) τ)) j + have hlist := List.pairwise_cons.mp horder + let T (j : Fin P.card) : Set (Fin a → ℕ) := {u | u ∈ C j ∧ + runSuccess s r hs S ht τ Ds (scaleRun D 0 (f j) b) u} + have htail (j : Fin P.card) : delta s r hs Ds * μ.real (C j) ≤ + μ.real (T j) + errorCost s r hs Ds * η := + ih (scaleRun D 0 (f j) b) hlist.2 (hsteps.2 (f j) (hf j)) (C j) + (fun D' hD' => (hCth j).earlier (hlist.1 D' hD')) + have hCu : (⋃ j, C j) = {u | u ∈ E ∧ + success D r s hs (multipliers (sourcePlan s r hs Ds)) (S D) ht b u (u D.index) τ} := by + rw [show (⋃ j, C j) = ⋃ j, A j from iUnion_disjointed] + ext u + simp only [Set.mem_iUnion, A, Set.mem_ofPred_eq, success] + constructor + · rintro ⟨j,hu,hj⟩ + exact ⟨hu,f j,hf j,hj⟩ + · rintro ⟨hu,p,hp,hp'⟩ + refine ⟨Finset.equivFin P ⟨p,hp⟩,hu,?_⟩ + simpa only [f, Equiv.symm_apply_apply] using hp' + have hCeq : μ.real (⋃ j, C j) = ∑ j, μ.real (C j) := + measureReal_iUnion_fintype (disjoint_disjointed A) (fun j => (Set.to_countable _).measurableSet) + have hTdisj : Pairwise (Disjoint on T) := by + intro i j hij + exact (disjoint_disjointed A hij).mono Set.inter_subset_left Set.inter_subset_left + have hTeq : μ.real (⋃ j, T j) = ∑ j, μ.real (T j) := + measureReal_iUnion_fintype hTdisj (fun j => (Set.to_countable _).measurableSet) + have hTu : (⋃ j, T j) ⊆ {u | u ∈ E ∧ runSuccess s r hs S ht τ (D :: Ds) b u} := by + apply Set.iUnion_subset + intro j u hu + have hA : u ∈ A j := disjointed_subset A j hu.1 + exact ⟨hA.1,f j,hf j,hA.2,hu.2⟩ + have hsum := Finset.sum_le_sum (s := Finset.univ) (fun j _ => htail j) + rw [Finset.sum_add_distrib, ← Finset.mul_sum] at hsum + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hsum + rw [← hCeq, ← hTeq, hCu] at hsum + have hh := mul_le_mul_of_nonneg_left (hsteps.1 E hEh) (delta_pos s r hs Ds).le + have hde : delta s r hs Ds * η ≤ η := mul_le_of_le_one_left hη (delta_le_one s r hs Ds) + have hmono := measureReal_mono (μ := μ) hTu + change (gain s r hs D (multipliers (sourcePlan s r hs Ds)) * delta s r hs Ds) * μ.real E ≤ _ + simp only [errorCost, Nat.cast_add, Nat.cast_one, Nat.cast_mul] + dsimp only [P] at hsum + nlinarith + + + +def localEstimates (μs : ℕ → Measure (Fin a → ℕ)) + (Ss : ℕ → (D : Pivot a) → ScalarModels D r) (hts : ℕ → Fin a → ℤ) : + List (Pivot a) → Scale a → Prop + | [], _ => True + | D :: Ds, b => + (∀ ε : ℝ, 0 < ε → ∀ᶠ N in atTop, + ∀ E : Set (Fin a → ℕ), Earlier D.index E → + gain s r hs D (multipliers (sourcePlan s r hs Ds)) * (μs N).real E ≤ + (μs N).real {u | u ∈ E ∧ success D r s hs (multipliers (sourcePlan s r hs Ds)) + (Ss N D) (hts N) b u (u D.index) τ} + ε) ∧ + ∀ p ∈ (sourcePlan s r hs (D :: Ds)).1, + localEstimates μs Ss hts Ds (scaleRun D 0 p b) + +lemma eventually_stepBounds (μs : ℕ → Measure (Fin a → ℕ)) + (Ss : ℕ → (D : Pivot a) → ScalarModels D r) (hts : ℕ → Fin a → ℤ) + (Ds : List (Pivot a)) (b : Scale a) + (h : localEstimates s r hs τ μs Ss hts Ds b) (ε : ℝ) (hε : 0 < ε) : + ∀ᶠ N in atTop, stepBounds s r hs (Ss N) (hts N) τ (μs N) ε Ds b := by + induction Ds generalizing b with + | nil => exact Eventually.of_forall (fun _ => True.intro) + | cons D Ds ih => + let P := (sourcePlan s r hs (D :: Ds)).1 + have ht : ∀ p : P, ∀ᶠ N in atTop, + stepBounds s r hs (Ss N) (hts N) τ (μs N) ε Ds (scaleRun D 0 p.val b) := + fun p => ih _ (h.2 p.val p.property) + filter_upwards [h.1 ε hε, eventually_all.mpr ht] with N hN hT + exact ⟨hN, fun p hp => hT ⟨p,hp⟩⟩ + + + +theorem iterate_eventually (μs : ℕ → Measure (Fin a → ℕ)) [∀ N, IsProbabilityMeasure (μs N)] + (Ss : ℕ → (D : Pivot a) → ScalarModels D r) (hts : ℕ → Fin a → ℤ) + (Ds : List (Pivot a)) (b : Scale a) + (horder : Ds.Pairwise (fun D E => D.index < E.index)) + (h : localEstimates s r hs τ μs Ss hts Ds b) (ε : ℝ) (hε : 0 < ε) : + ∀ᶠ N in atTop, ∀ E : Set (Fin a → ℕ), (∀ D ∈ Ds, Earlier D.index E) → + delta s r hs Ds * (μs N).real E ≤ + (μs N).real {u | u ∈ E ∧ runSuccess s r hs (Ss N) (hts N) τ Ds b u} + ε := by + let η := ε / (errorCost s r hs Ds + 1) + have hc : (0 : ℝ) < errorCost s r hs Ds + 1 := by positivity + have hη : 0 < η := div_pos hε hc + have hcost : (errorCost s r hs Ds : ℝ) * η ≤ ε := by + have he : η * (errorCost s r hs Ds + 1) = ε := div_mul_cancel₀ _ hc.ne' + have heta : 0 ≤ η := hη.le + nlinarith + filter_upwards [eventually_stepBounds s r hs τ μs Ss hts Ds b h η hη] with N hN + intro E hE + exact (iterate_mass s r hs (Ss N) (hts N) τ (μs N) Ds b horder η hη.le hN E hE).trans + (add_le_add le_rfl hcost) + + + +theorem eventual_final_alignment (μs : ℕ → Measure (Fin a → ℕ)) [∀ N, IsProbabilityMeasure (μs N)] + (Ss : ℕ → (D : Pivot a) → ScalarModels D r) (hts : ℕ → Fin a → ℤ) + (Ds : List (Pivot a)) (horder : Ds.Pairwise (fun D E => D.index < E.index)) + (h : localEstimates s r hs τ μs Ss hts Ds 1) (ε : ℝ) (hε : 0 < ε) : + ∀ᶠ N in atTop, delta s r hs Ds ≤ + (μs N).real {u | ∃ b ∈ multipliers (sourcePlan s r hs Ds), + ∀ D ∈ Ds, comparison D r (Ss N D) (hts N) b u (u D.index) τ} + ε := by + filter_upwards [iterate_eventually s r hs τ μs Ss hts Ds 1 horder h ε hε] with N hN + have hm := hN Set.univ (fun D _ => earlier_univ D.index) + have hsub : {u | u ∈ Set.univ ∧ runSuccess s r hs (Ss N) (hts N) τ Ds 1 u} ⊆ + {u | ∃ b ∈ multipliers (sourcePlan s r hs Ds), + ∀ D ∈ Ds, comparison D r (Ss N D) (hts N) b u (u D.index) τ} := by + intro u hu + obtain ⟨p,hp,hfinal⟩ := runSuccess_final s r hs (Ss N) (hts N) τ Ds 1 u hu.2 + exact ⟨pathMultiplier p, pathMultiplier_mem _ _ hp, by simpa only [one_mul] using hfinal⟩ + simpa only [probReal_univ, mul_one] using hm.trans + (add_le_add (measureReal_mono hsub) le_rfl) + +end SourcePivotPaths + + + + + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths03.lean new file mode 100644 index 0000000000000000000000000000000000000000..4fdbe9ef739e41b22167cea514a3bb295ed3621b --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PivotPaths03.lean @@ -0,0 +1,416 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.PivotPaths02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +noncomputable section +open Filter MeasureTheory +open scoped BigOperators ENNReal Topology +noncomputable section +open scoped BigOperators Topology BoundedContinuousFunction +noncomputable section +open scoped BigOperators +open MeasureTheory Filter Function +noncomputable section +open scoped BigOperators +namespace SourcePivotPaths +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales +open ConstructedWordPlan.RationalPivotPlan +open ConstructedWordPlan.GlobalWordPlan.SourceTerminalArithmetic +open SourceIntegerArrays.GlobalJoint.SourceFrozenFamily +attribute [local instance] Classical.propDecidable +variable {a : ℕ} (s r : ℕ) (hs : 1 ≤ s) + + +lemma scaleRun_pos (D : Pivot a) (p : Path D) (hp : ∀ o ∈ p, 0 < o.1) + (j : ℕ) (b : Scale a) (hb : ∀ l, 0 < b l) : ∀ l, 0 < scaleRun D j p b l := by + induction p generalizing j b with + | nil => exact hb + | cons o p ih => + apply ih (fun o ho => hp o (List.mem_cons_of_mem _ ho)) + intro l + exact mul_pos (hb l) (multiplier_pos D.index (tailAt D.tail j) + (by exact_mod_cast hp o List.mem_cons_self) l) + +lemma sourcePlan_positive (Ds : List (Pivot a)) : positivePlan (sourcePlan s r hs Ds) := by + induction Ds with + | nil => trivial + | cons D Ds ih => exact ⟨pivotOptions_paths s r hs D _, ih⟩ + +lemma source_multipliers_pos (Ds : List (Pivot a)) : + ∀ b ∈ multipliers (sourcePlan s r hs Ds), ∀ l, 0 < b l := by + induction Ds with + | nil => + intro b hb + simp only [multipliers, Finset.mem_singleton] at hb + subst b + simp + | cons D Ds ih => + intro b hb + obtain ⟨p,hp,hb⟩ := Finset.mem_biUnion.mp hb + obtain ⟨d,hd,rfl⟩ := Finset.mem_image.mp hb + exact fun l => mul_pos + (scaleRun_pos D p (pivotOptions_paths s r hs D _ p hp).2 0 1 (by simp) l) (ih d hd l) + +def nextScales (D : Pivot a) (Ds : List (Pivot a)) (B : Finset (Scale a)) : Finset (Scale a) := + B.biUnion (fun b => (pivotOptions s r hs D (multipliers (sourcePlan s r hs Ds))).image + (fun p => scaleRun D 0 p b)) + +lemma mem_nextScales (D : Pivot a) (Ds : List (Pivot a)) (B : Finset (Scale a)) + (b : Scale a) (hb : b ∈ B) (p : Path D) + (hp : p ∈ pivotOptions s r hs D (multipliers (sourcePlan s r hs Ds))) : + scaleRun D 0 p b ∈ nextScales s r hs D Ds B := + Finset.mem_biUnion.mpr ⟨b,hb,Finset.mem_image.mpr ⟨p,hp,rfl⟩⟩ + +lemma nextScales_pos (D : Pivot a) (Ds : List (Pivot a)) (B : Finset (Scale a)) + (hB : ∀ b ∈ B, ∀ l, 0 < b l) : + ∀ b ∈ nextScales s r hs D Ds B, ∀ l, 0 < b l := by + intro b hb + obtain ⟨b₀,hb₀,hb⟩ := Finset.mem_biUnion.mp hb + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hb + exact scaleRun_pos D p (pivotOptions_paths s r hs D _ p hp).2 0 b₀ (hB b₀ hb₀) + + + +def planModulus : List (Pivot a) → Finset (Scale a) → ℕ + | [], _ => 1 + | D :: Ds, B => + (pivotModulus s r hs D (multipliers (sourcePlan s r hs Ds)) B * + ∏ b ∈ B, terminalDenom D s r hs (multipliers (sourcePlan s r hs Ds)) b) * + planModulus Ds (nextScales s r hs D Ds B) + +lemma terminalDenom_pos (D : Pivot a) (Fs : Finset (Scale a)) (b : Scale a) : + 0 < terminalDenom D s r hs Fs b := + (source_terminal_arithmetic D (outcomeScales D s r hs Fs b)).choose_spec.1 + +lemma planModulus_pos (Ds : List (Pivot a)) (B : Finset (Scale a)) : + 0 < planModulus s r hs Ds B := by + induction Ds generalizing B with + | nil => exact Nat.zero_lt_one + | cons D Ds ih => + exact Nat.mul_pos (Nat.mul_pos (pivotModulus_pos s r hs D _ B) + (Finset.prod_pos fun b _ => terminalDenom_pos s r hs D _ b)) (ih _) + +lemma planModulus_head (D : Pivot a) (Ds : List (Pivot a)) (B : Finset (Scale a)) : + pivotModulus s r hs D (multipliers (sourcePlan s r hs Ds)) B ∣ planModulus s r hs (D :: Ds) B := + dvd_trans (dvd_mul_right _ _) (dvd_mul_right _ _) + +lemma planModulus_terminal (D : Pivot a) (Ds : List (Pivot a)) (B : Finset (Scale a)) + (b : Scale a) (hb : b ∈ B) : + terminalDenom D s r hs (multipliers (sourcePlan s r hs Ds)) b ∣ planModulus s r hs (D :: Ds) B := + dvd_trans (Finset.dvd_prod_of_mem _ hb) (dvd_trans (dvd_mul_left _ _) (dvd_mul_right _ _)) + +lemma planModulus_tail (D : Pivot a) (Ds : List (Pivot a)) (B : Finset (Scale a)) : + planModulus s r hs Ds (nextScales s r hs D Ds B) ∣ planModulus s r hs (D :: Ds) B := + dvd_mul_left _ _ + +end SourcePivotPaths + + + + + + + +noncomputable section +open Filter MeasureTheory +open scoped Topology BoundedContinuousFunction NNReal +namespace SourceChartedAlignment +open RationalLattice MalcevCharacters CubeFaces +open MicrocellScale AdmissibleMicrocellBoundary RoughScales +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales +open SourceIntegerArrays +open ConstructedWordPlan.GlobalWordPlan.SourceTerminalArithmetic +open SourceIntegerArrays.GlobalJoint.SourceFrozenFamily +open SourceIntegerArrays.GlobalJoint.SourceExposureSlots ProductExposureLaw SourceResidueAlignment +open ConstructedWordPlan.RationalPivotPlan + +structure CommonScales (a : ℕ) where + w : ℕ → ℕ + M : ℕ → ℕ + X : ℕ → Fin a → ℕ + ht : ℕ → Fin a → ℤ + L : ℕ → ℤ + hw : Tendsto w atTop atTop + hX : ∀ N j, 4 * primorial (w N) ≤ X N j + hXt : ∀ j, Tendsto (fun N => X N j) atTop atTop + hWM : ∀ N, (primorial (w N) : ℤ) ∣ (M N : ℤ) + hM : ∀ N, 0 < M N + hMs : ∀ N, RoughScales.Smooth (w N) (M N : ℤ) + hL : ∀ N, 0 < L N + hLs : ∀ N, RoughScales.Smooth (w N) (L N) + hWL : ∀ N, (primorial (w N) : ℤ) ∣ L N + hML : ∀ N, (M N : ℤ) ∣ L N + hLexact : ∀ N, L N = (M N : ℤ) * (primorial (w N) : ℤ) ^ w N + hpowWM : ∀ N, primorial (w N) ^ w N ∣ M N + hht : ∀ N j, 0 < ht N j + hXL : ∀ j, Tendsto (fun N => (X N j : ℝ) / (L N : ℝ)) atTop atTop + +structure PivotScales {a : ℕ} (C : CommonScales a) (D : Pivot a) where + H : ℕ → ℕ + J : ℕ → ℕ + R : ℕ → ℕ + hJ : ∀ N, 0 < J N + hRJ : ∀ N, R N = C.M N * J N + hH : ∀ N, 0 < H N + hRrad : ∀ N, R N = radius (C.M N) (H N) + hdom : Dominates (fun N => (H N : ℝ)) (earlierScale C.M (fun N => previousProduct D (C.X N))) + hxdom : Dominates (fun N => Real.log (C.X N D.index : ℝ)) (fun N => (H N : ℝ)) + hheight : ∀ N e, height (C.ht N) (D.added e) ≤ C.M N + hdisj : ∀ e, Disjoint (D.added e) (D.tail (D.owner e)) + hratio : ∀ N e, ∃ d : ℤ, height (C.ht N) (D.added e) = + height (C.ht N) (block D.index D.tail (D.owner e)) * + ((primorial (C.w N) : ℤ) ^ C.w N * d) + +structure ChartedModels {a : ℕ} (s r : ℕ) (D : Pivot a) where + G : Fin D.targets → ℚ → Fin r → Type + [group : ∀ t v c, Group (G t v c)] + [topology : ∀ t v c, TopologicalSpace (G t v c)] + [topGroup : ∀ t v c, IsTopologicalGroup (G t v c)] + Γ : ∀ t v c, Subgroup (G t v c) + dim : Fin D.targets → ℚ → Fin r → ℕ + coords : ∀ t v c, RealCoordinates (G t v c) (dim t v c) + second : ∀ t v c, SecondKind (coords t v c) + filtration : ∀ t v c, CubeFaces.Filtration (G t v c) + weight : ∀ t v c, Fin (dim t v c) → ℕ + level_iff : ∀ t v c k (g : G t v c), g ∈ (filtration t v c).level k ↔ + ∀ j, weight t v c j < k → (coords t v c).coord g j = 0 + weight_pos : ∀ t v c j, 0 < weight t v c j + lattice_iff : ∀ t v c g, g ∈ Γ t v c ↔ ∀ j, ∃ z : ℤ, (coords t v c).coord g j = z + weight_mono : ∀ t v c, Monotone (weight t v c) + level0 : ∀ t v c, (filtration t v c).level 0 = ⊤ + level1 : ∀ t v c, (filtration t v c).level 1 = ⊤ + step : ∀ t v c, (filtration t v c).level (s+1) = ⊥ + g : ∀ t, ℕ → ∀ v c, ℤ → ℤ → G t v c + x : ∀ t, ℕ → ∀ v c, ℤ → ℤ → G t v c + obs : ∀ t, ℕ → ∀ v c, ℤ → ℤ → ((G t v c) ⧸ Γ t v c) →ᵇ ℝ + metric : ∀ t v c, MetricSpace ((G t v c) ⧸ Γ t v c) + compatible : ∀ t v c, QuotientGroup.instTopologicalSpace (Γ t v c) = + (metric t v c).toUniformSpace.toTopologicalSpace + K : ℝ≥0 + B : ℝ + lip : letI : ∀ t v c, MetricSpace ((G t v c) ⧸ Γ t v c) := + fun t v c => (metric t v c).replaceTopology (compatible t v c) + ∀ t N v c b r', LipschitzWith K (obs t N v c b r') + bound : ∀ t N v c b r' z, |obs t N v c b r' z| ≤ B + +attribute [instance] ChartedModels.group ChartedModels.topology ChartedModels.topGroup + +variable {a : ℕ} +def CommonScales.law (C : CommonScales a) (N : ℕ) : Measure (Fin a → ℕ) := + outsideLaw (C.X N) (primorial (C.w N)) (primorial_pos _) (C.hX N) + +instance (C : CommonScales a) (N : ℕ) : IsProbabilityMeasure (C.law N) := by + unfold CommonScales.law + infer_instance + +def ChartedModels.scalar {s r : ℕ} {D : Pivot a} (C : CommonScales a) (P : PivotScales C D) + (F : ChartedModels s r D) (N : ℕ) : SourcePivotPaths.ScalarModels D r := + SourcePivotPaths.scalarModels D r F.G F.Γ C.M P.H F.g F.x F.obs N + +end SourceChartedAlignment + + + + + + + +noncomputable section +open scoped Topology BigOperators +namespace SourceProductCoordinates +open RationalLattice MalcevCharacters +attribute [local instance] Classical.propDecidable +variable {d N : ℕ} (n : Fin d → ℕ) + (G : Fin d → Type) [∀ i, Group (G i)] [∀ i, TopologicalSpace (G i)] + (c : ∀ i, RealCoordinates (G i) (n i)) + (e : Fin N ≃ Σ i, Fin (n i)) + (he : ∀ i, StrictMono (fun j : Fin (n i) => e.symm ⟨i,j⟩)) + + +def homeomorph : (∀ i, G i) ≃ₜ (Fin N → ℝ) where + toFun g k := (c (e k).1).coord (g (e k).1) (e k).2 + invFun v i := (c i).coord.symm (fun j => v (e.symm ⟨i,j⟩)) + left_inv g := by + funext i + apply (c i).coord.injective + ext j + simp only [Homeomorph.apply_symm_apply] + exact congrArg (fun z : Σ i, Fin (n i) => (c z.1).coord (g z.1) z.2) + (e.apply_symm_apply ⟨i,j⟩) + right_inv v := by + funext k + simp + continuous_toFun := continuous_pi fun k => + (continuous_apply (e k).2).comp ((c (e k).1).coord.continuous.comp (continuous_apply (e k).1)) + continuous_invFun := continuous_pi fun i => + (c i).coord.symm.continuous.comp (continuous_pi fun j => continuous_apply (e.symm ⟨i,j⟩)) + + +def lower (k : Fin N) (j : Fin (e k).2.val) : Fin k.val := + ⟨(e.symm ⟨(e k).1,⟨j.val,lt_trans j.isLt (e k).2.isLt⟩⟩).val, by + have h := he (e k).1 (show (⟨j.val,lt_trans j.isLt (e k).2.isLt⟩ : Fin (n (e k).1)) < (e k).2 from j.isLt) + simpa only [Sigma.eta, Equiv.symm_apply_apply, Fin.lt_def] using h⟩ + +lemma homeomorph_lower (g : ∀ i, G i) (k : Fin N) (j : Fin (e k).2.val) : + homeomorph n G c e g ⟨(lower n e he k j).val,lt_trans (lower n e he k j).isLt k.isLt⟩ = + (c (e k).1).coord (g (e k).1) ⟨j.val,lt_trans j.isLt (e k).2.isLt⟩ := by + change (c (e (e.symm _)).1).coord (g (e (e.symm _)).1) (e (e.symm _)).2 = _ + exact congrArg (fun z : Σ i, Fin (n i) => (c z.1).coord (g z.1) z.2) + (e.apply_symm_apply _) + + +def coordinates : RealCoordinates (∀ i, G i) N where + coord := homeomorph n G c e + one_coord k := (c (e k).1).one_coord (e k).2 + correction k := MvPolynomial.rename (Sum.map (lower n e he k) (lower n e he k)) + ((c (e k).1).correction (e k).2) + mul_coord g h k := by + change (c (e k).1).coord (g (e k).1 * h (e k).1) (e k).2 = _ + rw [(c (e k).1).mul_coord] + congr 1 + rw [MvPolynomial.eval₂_rename] + congr 1 + funext j + cases j with + | inl j => exact (homeomorph_lower n G c e he g k j).symm + | inr j => exact (homeomorph_lower n G c e he h k j).symm + + +def select (i : Fin d) (k : Fin N) : Option (Fin (n i)) := + if h : (e k).1 = i then some (h ▸ (e k).2) else none + +lemma select_some_iff (i : Fin d) (k : Fin N) (j : Fin (n i)) : + select n e i k = some j ↔ e k = ⟨i,j⟩ := by + unfold select + split_ifs with h + · subst i + simp only [Option.some.injEq] + constructor + · intro h + cases h + rfl + · intro h + exact eq_of_heq (Sigma.mk.inj h).2 + · constructor + · intro h' + cases h' + · intro h' + exact False.elim (h (congrArg Sigma.fst h')) + +include he in +lemma select_enumeration (i : Fin d) : + (List.ofFn (fun k : Fin N => k)).filterMap (select n e i) = + List.ofFn (fun j : Fin (n i) => j) := by + apply List.Pairwise.eq_of_mem_iff (r := (· < ·)) + · apply List.pairwise_filterMap.mpr + apply List.pairwise_ofFn.mpr + intro k l hkl j hj j' hj' + have hk : e.symm ⟨i,j⟩ = k := e.symm_apply_eq.mpr ((select_some_iff n e i k j).mp hj).symm + have hl : e.symm ⟨i,j'⟩ = l := e.symm_apply_eq.mpr ((select_some_iff n e i l j').mp hj').symm + exact (he i).lt_iff_lt.mp (by simpa only [hk,hl] using hkl) + · exact List.pairwise_ofFn.mpr (fun _ _ h => h) + · intro j + simp only [List.mem_filterMap, List.mem_ofFn] + constructor + · intro h + exact ⟨j,rfl⟩ + · intro h + refine ⟨e.symm ⟨i,j⟩,⟨e.symm ⟨i,j⟩,rfl⟩,?_⟩ + exact (select_some_iff n e i _ j).mpr (e.apply_symm_apply _) + +lemma axis_selected (k : Fin N) (t : ℝ) (i : Fin d) (j : Fin (n i)) + (hk : e k = ⟨i,j⟩) : + axis (coordinates n G c e he) k t i = axis (c i) j t := by + apply (c i).coord.injective + ext v + change (c i).coord ((c i).coord.symm (fun v => (Pi.single k t : Fin N → ℝ) (e.symm ⟨i,v⟩))) v = _ + rw [(c i).coord.apply_symm_apply] + simp only [axis, Homeomorph.apply_symm_apply] + have hkv : e.symm ⟨i,v⟩ = k ↔ v=j := by + rw [e.symm_apply_eq, hk] + constructor + · intro h + exact eq_of_heq (Sigma.mk.inj h).2 + · rintro rfl + rfl + simp only [Pi.single_apply, hkv] + +lemma axis_other (k : Fin N) (t : ℝ) (i : Fin d) (hk : (e k).1 ≠ i) : + axis (coordinates n G c e he) k t i = 1 := by + apply (c i).coord.injective + ext v + change (c i).coord ((c i).coord.symm (fun v => (Pi.single k t : Fin N → ℝ) (e.symm ⟨i,v⟩))) v = _ + rw [(c i).coord.apply_symm_apply, (c i).one_coord] + apply Pi.single_eq_of_ne + intro h + have h' := e.symm_apply_eq.mp h + exact hk (congrArg Sigma.fst h').symm + + +lemma prod_select {α β M : Type*} [Monoid M] (l : List α) + (f : α → Option β) (g : β → M) (h : α → M) + (hh : ∀ x, h x = (f x).elim 1 g) : + (l.map h).prod = ((l.filterMap f).map g).prod := by + induction l with + | nil => rfl + | cons x xs ih => + cases hf : f x with + | none => simpa [hh x, hf] using ih + | some y => simpa [hh x, hf] using congrArg (fun z => g y*z) ih + + + +theorem secondKind (hs : ∀ i, SecondKind (c i)) : + SecondKind (coordinates n G c e he) where + axis_add k s t := by + funext i + by_cases hi : (e k).1 = i + · subst i + rw [axis_selected n G c e he k (s+t) (e k).1 (e k).2 rfl, + Pi.mul_apply, axis_selected n G c e he k s (e k).1 (e k).2 rfl, + axis_selected n G c e he k t (e k).1 (e k).2 rfl] + exact (hs _).axis_add _ _ _ + · rw [axis_other n G c e he k (s+t) i hi, Pi.mul_apply, + axis_other n G c e he k s i hi, axis_other n G c e he k t i hi, one_mul] + ordered g := by + funext i + change g i = (Pi.evalMonoidHom G i) + (List.ofFn (fun k => axis (coordinates n G c e he) k ((coordinates n G c e he).coord g k))).prod + rw [map_list_prod, List.map_ofFn] + change g i = (List.ofFn (fun k : Fin N => + axis (coordinates n G c e he) k ((coordinates n G c e he).coord g k) i)).prod + have hprod := prod_select (List.ofFn (fun k : Fin N => k)) (select n e i) + (fun j => axis (c i) j ((c i).coord (g i) j)) + (fun k => axis (coordinates n G c e he) k ((coordinates n G c e he).coord g k) i) (by + intro k + by_cases hi : (e k).1 = i + · have hk : e k = ⟨i,hi ▸ (e k).2⟩ := by cases hi; rfl + rw [select, dite_eq_left hi, Option.elim_some, axis_selected n G c e he _ _ _ _ hk] + congr 1 + change (c (e k).1).coord (g (e k).1) (e k).2 = _ + exact congrArg (fun z : Σ i, Fin (n i) => (c z.1).coord (g z.1) z.2) hk + · rw [select, dite_eq_right hi, Option.elim_none, axis_other n G c e he _ _ _ hi]) + rw [List.map_ofFn, select_enumeration n e he i, List.map_ofFn] at hprod + exact ((hs i).ordered (g i)).trans hprod.symm + +end SourceProductCoordinates + + + + + + + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PointLaw01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PointLaw01.lean new file mode 100644 index 0000000000000000000000000000000000000000..54863bd9f546366c8a6414dafc2b0f7d1d930a58 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PointLaw01.lean @@ -0,0 +1,289 @@ +import Mathlib +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section RawSuccessInlineScope0 +noncomputable section +open MeasureTheory Filter Topology +open scoped BigOperators +end +end RawSuccessInlineScope0 + + + + + +section RawSuccessInlineScope1 + + + +open scoped Topology BigOperators +open Filter MeasureTheory Set + +namespace SourcePointLaw + +noncomputable section + + + +theorem interval_induction (p : ℝ → ℝ → Prop) + (hjoin : ∀ a b : ℝ, 0 ≤ a → a < b → b ≤ 1 → + p a ((a + b) / 2) → p ((a + b) / 2) b → p a b) + (hlocal : ∀ x ∈ Icc (0 : ℝ) 1, ∃ δ > 0, ∀ a b : ℝ, + 0 ≤ a → a < b → b ≤ 1 → a ≤ x → x ≤ b → b - a < δ → p a b) : + p 0 1 := by + let I : BoxIntegral.Box Unit := ⟨fun _ => 0, fun _ => 1, fun _ => by norm_num⟩ + change p (I.lower ()) (I.upper ()) + apply I.subbox_induction_on' (p := fun J => p (J.lower ()) (J.upper ())) + · intro J hJ hs + have hlo : 0 ≤ J.lower () := (BoxIntegral.Box.le_iff_bounds.mp hJ).1 () + have hup : J.upper () ≤ 1 := (BoxIntegral.Box.le_iff_bounds.mp hJ).2 () + have h₁ := hs (∅ : Set Unit) + have h₂ := hs (univ : Set Unit) + simp [BoxIntegral.Box.splitCenterBox] at h₁ h₂ + exact hjoin _ _ hlo (J.lower_lt_upper ()) hup h₁ h₂ + · intro z hz + have hz' : z () ∈ Icc (0 : ℝ) 1 := ⟨hz.1 (), hz.2 ()⟩ + obtain ⟨δ, hδ, hδp⟩ := hlocal (z ()) hz' + refine ⟨{y : Unit → ℝ | |y () - z ()| < δ / 3}, ?_, ?_⟩ + · apply mem_nhdsWithin_of_mem_nhds + have hh : Continuous (fun y : Unit → ℝ => |y () - z ()|) := + ((continuous_apply ()).sub continuous_const).abs + exact IsOpen.mem_nhds (isOpen_lt hh continuous_const) (by simp only [Set.mem_ofPred_eq, sub_self, abs_zero]; positivity) + · intro J hJ m hzJ hsub _ + have hlo : 0 ≤ J.lower () := (BoxIntegral.Box.le_iff_bounds.mp hJ).1 () + have hup : J.upper () ≤ 1 := (BoxIntegral.Box.le_iff_bounds.mp hJ).2 () + have hl := hsub J.lower_mem_Icc + have hu := hsub J.upper_mem_Icc + change |J.lower () - z ()| < δ / 3 at hl + change |J.upper () - z ()| < δ / 3 at hu + apply hδp _ _ hlo (J.lower_lt_upper ()) hup (hzJ.1 ()) (hzJ.2 ()) + have hl' := (abs_lt.mp hl).1 + have hu' := (abs_lt.mp hu).2 + linarith + + + +theorem tendsto_of_local_interval_law + {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + {ι : Type*} (l : Filter ι) (A : ι → ℝ → ℝ → E) (f : ℝ → E) + (hadd : ∀ N a b c, 0 ≤ a → a ≤ b → b ≤ c → c ≤ 1 → + A N a c = A N a b + A N b c) + (hf : ContinuousOn f (Icc (0 : ℝ) 1)) + (hlocal : ∀ x ∈ Icc (0 : ℝ) 1, ∀ ε > 0, ∃ δ > 0, + ∀ a b : ℝ, 0 ≤ a → a < b → b ≤ 1 → a ≤ x → x ≤ b → b - a < δ → + ∀ᶠ N : ι in l, ‖A N a b - (b - a) • f x‖ ≤ ε * (b - a)) : + Tendsto (fun N => A N 0 1) l (𝓝 (∫ x in (0 : ℝ)..1, f x)) := by + have hint (a b : ℝ) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ 1) : + IntervalIntegrable f volume a b := + ContinuousOn.intervalIntegrable_of_Icc hab (hf.mono (Icc_subset_Icc ha hb)) + apply Metric.tendsto_nhds.mpr + intro ε hε + have hε4 : 0 < ε / 4 := by positivity + have hevent : ∀ᶠ N : ι in l, + ‖A N 0 1 - ∫ x in (0 : ℝ)..1, f x‖ ≤ ε / 2 * (1 - 0) := by + apply interval_induction (fun a b => ∀ᶠ N : ι in l, + ‖A N a b - ∫ x in a..b, f x‖ ≤ ε / 2 * (b - a)) + · intro a b ha hab hb hl hr + let c := (a + b) / 2 + have hac : a ≤ c := by dsimp [c]; linarith + have hcb : c ≤ b := by dsimp [c]; linarith + have hic := hint a c ha hac (hcb.trans hb) + have hci := hint c b (ha.trans hac) hcb hb + filter_upwards [hl, hr] with N hNl hNr + rw [hadd N a c b ha hac hcb hb, + ← intervalIntegral.integral_add_adjacent_intervals hic hci] + calc + ‖A N a c + A N c b - + ((∫ x in a..c, f x) + ∫ x in c..b, f x)‖ = + ‖(A N a c - ∫ x in a..c, f x) + (A N c b - ∫ x in c..b, f x)‖ := + congrArg norm (by abel) + _ ≤ ‖A N a c - ∫ x in a..c, f x‖ + ‖A N c b - ∫ x in c..b, f x‖ := + norm_add_le _ _ + _ ≤ ε / 2 * (b - a) := by dsimp [c] at *; linarith + · intro x hx + obtain ⟨δ₁, hδ₁, hδ₁p⟩ := hlocal x hx (ε / 4) hε4 + obtain ⟨δ₂, hδ₂, hδ₂p⟩ := Metric.continuousWithinAt_iff.mp (hf x hx) (ε / 4) hε4 + refine ⟨min δ₁ δ₂, lt_min hδ₁ hδ₂, ?_⟩ + intro a b ha hab hb hax hxb hδ + have hδa : b - a < δ₁ := hδ.trans_le (min_le_left _ _) + have hδb : b - a < δ₂ := hδ.trans_le (min_le_right _ _) + have hi := hint a b ha hab.le hb + have herr : ‖(b - a) • f x - ∫ y in a..b, f y‖ ≤ ε / 4 * (b - a) := by + rw [← intervalIntegral.integral_const, + ← intervalIntegral.integral_sub intervalIntegrable_const hi] + have hbound : ∀ y ∈ uIoc a b, ‖f x - f y‖ ≤ ε / 4 := by + intro y hy + rw [uIoc_of_le hab.le] at hy + have hy' : y ∈ Icc (0 : ℝ) 1 := ⟨ha.trans hy.1.le, hy.2.trans hb⟩ + have hdist : dist y x ≤ b - a := by + rw [Real.dist_eq, abs_le] + constructor <;> linarith [hy.1, hy.2] + have hc := (hδ₂p hy' (hdist.trans_lt hδb)).le + simpa only [dist_eq_norm, norm_sub_rev] using hc + simpa only [abs_of_pos (sub_pos.mpr hab)] using + intervalIntegral.norm_integral_le_of_norm_le_const hbound + filter_upwards [hδ₁p a b ha hab hb hax hxb hδa] with N hN + calc + ‖A N a b - ∫ y in a..b, f y‖ ≤ + ‖A N a b - (b - a) • f x‖ + ‖(b - a) • f x - ∫ y in a..b, f y‖ := + by simpa only [dist_eq_norm] using + dist_triangle (A N a b) ((b - a) • f x) (∫ y in a..b, f y) + _ ≤ ε / 2 * (b - a) := by linarith + filter_upwards [hevent] with N hN + rw [dist_eq_norm] + have : ε / 2 < ε := by linarith + exact hN.trans_lt (by simpa using this) + +end +end SourcePointLaw + + + +open scoped Topology BigOperators +open Filter MeasureTheory Set + +namespace SourcePointLaw +noncomputable section + + +def residueInterval (d : ℕ) (r : ℤ) (a b : ℝ) : Finset ℤ := + (Finset.Ico ⌈a⌉ ⌈b⌉).filter (fun n => n % (d : ℤ) = r) + +lemma mem_residueInterval (d : ℕ) (r n : ℤ) (a b : ℝ) : + n ∈ residueInterval d r a b ↔ (a ≤ (n : ℝ) ∧ (n : ℝ) < b) ∧ n % (d : ℤ) = r := by + simp only [residueInterval, Finset.mem_filter, Finset.mem_Ico, Int.ceil_le, Int.lt_ceil] + +lemma residueInterval_affine (d : ℕ) (hd : 0 < d) (r : ℤ) + (hr : 0 ≤ r ∧ r < (d : ℤ)) (a b : ℝ) : + residueInterval d r a b = + (Finset.Ico ⌈(a - (r : ℝ)) / (d : ℝ)⌉ ⌈(b - (r : ℝ)) / (d : ℝ)⌉).map + ⟨fun k => r + (d : ℤ) * k, by + intro x y h + have hd' : (d : ℤ) ≠ 0 := by exact_mod_cast hd.ne' + exact mul_left_cancel₀ hd' (add_left_cancel h)⟩ := by + have hdR : (0 : ℝ) < d := by exact_mod_cast hd + have hmem (k : ℤ) : + k ∈ Finset.Ico ⌈(a - (r : ℝ)) / (d : ℝ)⌉ ⌈(b - (r : ℝ)) / (d : ℝ)⌉ ↔ + a ≤ ((r + (d : ℤ) * k : ℤ) : ℝ) ∧ ((r + (d : ℤ) * k : ℤ) : ℝ) < b := by + simp only [Finset.mem_Ico, Int.ceil_le, Int.lt_ceil, Int.cast_add, Int.cast_mul, + Int.cast_natCast, div_le_iff₀ hdR, lt_div_iff₀ hdR] + constructor <;> intro h <;> constructor <;> nlinarith [h.1, h.2] + ext n + rw [mem_residueInterval, Finset.mem_map] + constructor + · rintro ⟨hn, hmod⟩ + have he : r + (d : ℤ) * (n / (d : ℤ)) = n := by + rw [← hmod] + exact Int.emod_add_mul_ediv n d + refine ⟨n / (d : ℤ), hmem _ |>.mpr ?_, he⟩ + simpa only [he] using hn + · rintro ⟨k, hk, rfl⟩ + refine ⟨(hmem k).mp hk, ?_⟩ + change (r + (d : ℤ) * k) % (d : ℤ) = r + rw [Int.add_mul_emod_self_left] + exact Int.emod_eq_of_lt hr.1 hr.2 + + +theorem residueInterval_card_error (d : ℕ) (hd : 0 < d) (r : ℤ) + (hr : 0 ≤ r ∧ r < (d : ℤ)) (a b : ℝ) (hab : a ≤ b) : + |((residueInterval d r a b).card : ℝ) - (b - a) / (d : ℝ)| < 1 := by + have hdR : (0 : ℝ) < d := by exact_mod_cast hd + let u := (a - (r : ℝ)) / (d : ℝ) + let v := (b - (r : ℝ)) / (d : ℝ) + have huv : u ≤ v := div_le_div_of_nonneg_right (sub_le_sub_right hab _) hdR.le + have hceil : ⌈u⌉ ≤ ⌈v⌉ := Int.ceil_mono huv + have hcard : ((residueInterval d r a b).card : ℤ) = ⌈v⌉ - ⌈u⌉ := by + rw [residueInterval_affine d hd r hr, Finset.card_map, Int.card_Ico] + exact Int.toNat_of_nonneg (sub_nonneg.mpr hceil) + have hcardR : ((residueInterval d r a b).card : ℝ) = (⌈v⌉ : ℝ) - (⌈u⌉ : ℝ) := by + exact_mod_cast hcard + have hvu : v - u = (b - a) / (d : ℝ) := by dsimp [v, u]; ring + rw [hcardR, ← hvu, abs_lt] + constructor <;> linarith [Int.le_ceil u, Int.ceil_lt_add_one u, + Int.le_ceil v, Int.ceil_lt_add_one v] + + +theorem residueInterval_card_scaled_error (d : ℕ) (hd : 0 < d) (r : ℤ) + (hr : 0 ≤ r ∧ r < (d : ℤ)) (a b : ℝ) (hab : a ≤ b) + (N : ℕ) (hN : 0 < N) : + |((residueInterval d r (a * N) (b * N)).card : ℝ) / N - (b - a) / (d : ℝ)| < + 1 / (N : ℝ) := by + have hNR : (0 : ℝ) < N := by exact_mod_cast hN + have he := residueInterval_card_error d hd r hr (a * N) (b * N) + (mul_le_mul_of_nonneg_right hab hNR.le) + have hi : ((residueInterval d r (a * N) (b * N)).card : ℝ) / N - (b - a) / (d : ℝ) = + (((residueInterval d r (a * N) (b * N)).card : ℝ) - + (b * N - a * N) / (d : ℝ)) / N := by + field_simp + rw [hi, abs_div, abs_of_pos hNR] + exact (div_lt_div_iff_of_pos_right hNR).mpr he + + +theorem residueInterval_card_tendsto (d : ℕ) (hd : 0 < d) (r : ℤ) + (hr : 0 ≤ r ∧ r < (d : ℤ)) (a b : ℝ) (hab : a ≤ b) : + Tendsto (fun N : ℕ => ((residueInterval d r (a * N) (b * N)).card : ℝ) / N) + atTop (𝓝 ((b - a) / (d : ℝ))) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + apply squeeze_zero' (Filter.Eventually.of_forall (fun _ => norm_nonneg _)) + · filter_upwards [Filter.eventually_ge_atTop (1 : ℕ)] with N hN + simpa only [Real.norm_eq_abs] using + (residueInterval_card_scaled_error d hd r hr a b hab N (by omega)).le + · exact tendsto_const_div_atTop_nhds_zero_nat (1 : ℝ) + +lemma residueInterval_union (d : ℕ) (r : ℤ) (a b c : ℝ) + (hab : a ≤ b) (hbc : b ≤ c) : + residueInterval d r a c = residueInterval d r a b ∪ residueInterval d r b c := by + ext n + simp only [mem_residueInterval, Finset.mem_union] + constructor + · rintro ⟨⟨hna, hnc⟩, hnmod⟩ + by_cases hnb : (n : ℝ) < b + · exact Or.inl ⟨⟨hna, hnb⟩, hnmod⟩ + · exact Or.inr ⟨⟨le_of_not_gt hnb, hnc⟩, hnmod⟩ + · rintro (⟨⟨hna, hnb⟩, hnmod⟩ | ⟨⟨hnb, hnc⟩, hnmod⟩) + · exact ⟨⟨hna, hnb.trans_le hbc⟩, hnmod⟩ + · exact ⟨⟨hab.trans hnb, hnc⟩, hnmod⟩ + +lemma residueInterval_disjoint (d : ℕ) (r : ℤ) (a b c : ℝ) : + Disjoint (residueInterval d r a b) (residueInterval d r b c) := by + apply Finset.disjoint_left.mpr + intro n hn hm + rw [mem_residueInterval] at hn hm + exact (not_lt_of_ge hm.1.1) hn.1.2 + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + + +def windowSum (P : ℕ → ℤ → E) (d : ℕ) (r : ℤ) (N : ℕ) (a b : ℝ) : E := + (N : ℝ)⁻¹ • ∑ n ∈ residueInterval d r (a * N) (b * N), P N n + +lemma windowSum_add (P : ℕ → ℤ → E) (d : ℕ) (r : ℤ) (N : ℕ) + (a b c : ℝ) (hab : a ≤ b) (hbc : b ≤ c) : + windowSum P d r N a c = windowSum P d r N a b + windowSum P d r N b c := by + have hN : (0 : ℝ) ≤ N := Nat.cast_nonneg _ + simp only [windowSum, residueInterval_union d r _ _ _ + (mul_le_mul_of_nonneg_right hab hN) (mul_le_mul_of_nonneg_right hbc hN), + Finset.sum_union (residueInterval_disjoint d r _ _ _), smul_add] + + + +lemma windowSum_eq [Module ℚ≥0 E] (P : ℕ → ℤ → E) (d : ℕ) (r : ℤ) (N : ℕ) (a b : ℝ) : + windowSum P d r N a b = + (((residueInterval d r (a * N) (b * N)).card : ℝ) / N) • + (𝔼 n ∈ residueInterval d r (a * N) (b * N), P N n) := by + rw [windowSum, ← Finset.card_smul_expect] + rw [← Nat.cast_smul_eq_nsmul ℝ, smul_smul] + congr 1 + ring + +end +end SourcePointLaw + +end RawSuccessInlineScope1 +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PointLaw02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PointLaw02.lean new file mode 100644 index 0000000000000000000000000000000000000000..6bcf184ea34ddf118df7c50973cbda449b947894 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PointLaw02.lean @@ -0,0 +1,255 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.PointLaw01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section RawSuccessInlineScope1 +open scoped Topology BigOperators +open Filter MeasureTheory Set +open scoped Topology BigOperators +open Filter MeasureTheory Set +namespace SourcePointLaw +noncomputable section +open scoped Topology BigOperators +open Filter MeasureTheory Set + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] [Module ℚ≥0 E] + + + +theorem residue_point_law + (P : ℕ → ℤ → E) (d : ℕ) (hd : 0 < d) (r : ℤ) + (hr : 0 ≤ r ∧ r < (d : ℤ)) (f : ℝ → E) + (hf : ContinuousOn f (Icc (0 : ℝ) 1)) + (hloc : ∀ x ∈ Icc (0 : ℝ) 1, ∀ ε > 0, + ∀ᶠ α : ℝ in 𝓝[>] 0, ∀ᶠ N : ℕ in atTop, + ∀ a b : ℝ, 0 ≤ a → a ≤ x → x ≤ b → b ≤ 1 → b - a = α → + ‖(𝔼 n ∈ residueInterval d r (a * N) (b * N), P N n) - f x‖ < ε) : + Tendsto (fun N => windowSum P d r N 0 1) atTop + (𝓝 ((d : ℝ)⁻¹ • ∫ x in (0 : ℝ)..1, f x)) := by + have hdR : (0 : ℝ) < d := by exact_mod_cast hd + rw [← intervalIntegral.integral_smul] + apply tendsto_of_local_interval_law atTop (windowSum P d r) + (fun x => (d : ℝ)⁻¹ • f x) + · intro N a b c _ hab hbc _ + exact windowSum_add P d r N a b c hab hbc + · exact hf.const_smul _ + · intro x hx ε hε + have hη : 0 < ε * (d : ℝ) / 4 := by positivity + obtain ⟨δ, hδ, hδp⟩ := mem_nhdsGT_iff_exists_Ioo_subset.mp (hloc x hx _ hη) + refine ⟨δ, hδ, ?_⟩ + intro a b ha hab hb hax hxb hlen + have hlocal := hδp ⟨sub_pos.mpr hab, hlen⟩ + have hm := residueInterval_card_tendsto d hd r hr a b hab.le + have hup : ∀ᶠ N : ℕ in atTop, + ((residueInterval d r (a * N) (b * N)).card : ℝ) / N < + 2 * (b - a) / (d : ℝ) := + (tendsto_order.mp hm).2 _ (by rw [mul_div_assoc]; have : 0 < (b-a)/(d:ℝ) := div_pos (sub_pos.mpr hab) hdR; linarith) + have hsm := hm.smul (tendsto_const_nhds (x := f x)) + have heps : 0 < ε * (b - a) / 2 := by positivity + have herr := (Metric.tendsto_nhds.mp hsm) _ heps + filter_upwards [hlocal, hup, herr] with N hN hupper herror + have hmass : 0 ≤ ((residueInterval d r (a * N) (b * N)).card : ℝ) / N := + div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + have havg := hN a b ha hax hxb hb rfl + rw [windowSum_eq] + have hscale : (b - a) • ((d : ℝ)⁻¹ • f x) = ((b - a)/(d : ℝ)) • f x := by + simp only [smul_smul, div_eq_mul_inv] + rw [hscale] + calc + _ ≤ ‖(((residueInterval d r (a * N) (b * N)).card : ℝ) / N) • + ((𝔼 n ∈ residueInterval d r (a * N) (b * N), P N n) - f x)‖ + + ‖(((residueInterval d r (a * N) (b * N)).card : ℝ) / N) • f x - + ((b - a)/(d : ℝ)) • f x‖ := by + rw [smul_sub] + exact (show _ from norm_add_le _ _).trans_eq' (congrArg norm (by abel)) + _ ≤ (2 * (b - a) / (d : ℝ)) * (ε * (d : ℝ) / 4) + ε * (b - a) / 2 := by + apply add_le_add + · rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg hmass] + exact mul_le_mul hupper.le havg.le (norm_nonneg _) (by positivity) + · simpa only [dist_eq_norm] using herror.le + _ = ε * (b - a) := by field_simp; ring + +end +end SourcePointLaw + +namespace SourcePointLaw +noncomputable section +open scoped Topology BigOperators +open Filter MeasureTheory Set +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + +omit [NormedSpace ℝ E] in +lemma residueInterval_sum (d : ℕ) (hd : 0 < d) (a b : ℝ) (F : ℤ → E) : + ∑ r ∈ Finset.Ico (0 : ℤ) (d : ℤ), ∑ n ∈ residueInterval d r a b, F n = + ∑ n ∈ Finset.Ico ⌈a⌉ ⌈b⌉, F n := by + apply Finset.sum_fiberwise_of_maps_to + intro n hn + have hd' : (0 : ℤ) < d := by exact_mod_cast hd + exact Finset.mem_Ico.mpr ⟨Int.emod_nonneg n hd'.ne', Int.emod_lt_of_pos n hd'⟩ + +omit [NormedSpace ℝ E] in +lemma sum_int_Ico_zero_nat (N : ℕ) (F : ℤ → E) : + ∑ n ∈ Finset.Ico (0 : ℤ) (N : ℤ), F n = ∑ n ∈ Finset.range N, F n := by + symm + apply Finset.sum_bij (fun (n : ℕ) _ => (n : ℤ)) + · intro n hn + simp only [Finset.mem_range] at hn + exact Finset.mem_Ico.mpr ⟨Int.natCast_nonneg _, by exact_mod_cast hn⟩ + · intro a ha b hb hab + exact_mod_cast hab + · intro n hn + obtain ⟨hn0, hnN⟩ := Finset.mem_Ico.mp hn + refine ⟨n.toNat, ?_, Int.toNat_of_nonneg hn0⟩ + simp only [Finset.mem_range] + have : (n.toNat : ℤ) < (N : ℤ) := by simpa only [Int.toNat_of_nonneg hn0] using hnN + exact_mod_cast this + · intro n hn + rfl + + + +lemma sum_windowSum (P : ℕ → ℤ → E) (d : ℕ) (hd : 0 < d) (N : ℕ) : + ∑ r ∈ Finset.Ico (0 : ℤ) (d : ℤ), windowSum P d r N 0 1 = + (N : ℝ)⁻¹ • ∑ n ∈ Finset.range N, P N n := by + simp only [windowSum, ← Finset.smul_sum] + rw [residueInterval_sum d hd] + simp only [zero_mul, one_mul, Int.ceil_zero, Int.ceil_natCast] + rw [sum_int_Ico_zero_nat] + + + +theorem global_point_law [CompleteSpace E] [Module ℚ≥0 E] + (P : ℕ → ℤ → E) (d : ℕ) (hd : 0 < d) (f : ℤ → ℝ → E) + (hf : ∀ r ∈ Finset.Ico (0 : ℤ) (d : ℤ), ContinuousOn (f r) (Icc (0 : ℝ) 1)) + (hloc : ∀ r ∈ Finset.Ico (0 : ℤ) (d : ℤ), ∀ x ∈ Icc (0 : ℝ) 1, ∀ ε > 0, + ∀ᶠ α : ℝ in 𝓝[>] 0, ∀ᶠ N : ℕ in atTop, + ∀ a b : ℝ, 0 ≤ a → a ≤ x → x ≤ b → b ≤ 1 → b - a = α → + ‖(𝔼 n ∈ residueInterval d r (a * N) (b * N), P N n) - f r x‖ < ε) : + Tendsto (fun N : ℕ => (N : ℝ)⁻¹ • ∑ n ∈ Finset.range N, P N n) atTop + (𝓝 ((d : ℝ)⁻¹ • ∑ r ∈ Finset.Ico (0 : ℤ) (d : ℤ), ∫ x in (0 : ℝ)..1, f r x)) := by + simpa only [sum_windowSum P d hd, Finset.smul_sum] using + tendsto_finsetSum (Finset.Ico (0 : ℤ) (d : ℤ)) (fun r hr => + residue_point_law P d hd r (Finset.mem_Ico.mp hr) (f r) (hf r hr) (hloc r hr)) + +end +end SourcePointLaw + +namespace SourcePointLaw +noncomputable section +open scoped Topology BigOperators +open Filter MeasureTheory Set +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +lemma sum_windowSum_fin (P : ℕ → ℤ → E) (d : ℕ) (hd : 0 < d) (N : ℕ) : + ∑ r : Fin d, windowSum P d r.val N 0 1 = + (N : ℝ)⁻¹ • ∑ n ∈ Finset.range N, P N n := by + calc + _ = ∑ r ∈ Finset.range d, windowSum P d r N 0 1 := (Finset.sum_range _).symm + _ = ∑ r ∈ Finset.Ico (0 : ℤ) (d : ℤ), windowSum P d r N 0 1 := + (sum_int_Ico_zero_nat d (fun r => windowSum P d r N 0 1)).symm + _ = _ := sum_windowSum P d hd N + + + +theorem global_point_law_fin [CompleteSpace E] [Module ℚ≥0 E] + (P : ℕ → ℤ → E) (d : ℕ) (hd : 0 < d) (f : Fin d → ℝ → E) + (hf : ∀ r, ContinuousOn (f r) (Icc (0 : ℝ) 1)) + (hloc : ∀ r, ∀ x ∈ Icc (0 : ℝ) 1, ∀ ε > 0, + ∀ᶠ α : ℝ in 𝓝[>] 0, ∀ᶠ N : ℕ in atTop, + ∀ a b : ℝ, 0 ≤ a → a ≤ x → x ≤ b → b ≤ 1 → b - a = α → + ‖(𝔼 n ∈ residueInterval d r.val (a * N) (b * N), P N n) - f r x‖ < ε) : + Tendsto (fun N : ℕ => (N : ℝ)⁻¹ • ∑ n ∈ Finset.range N, P N n) atTop + (𝓝 ((d : ℝ)⁻¹ • ∑ r : Fin d, ∫ x in (0 : ℝ)..1, f r x)) := by + have hres (r : Fin d) := residue_point_law P d hd r.val + (show 0 ≤ (r.val : ℤ) ∧ (r.val : ℤ) < (d : ℤ) from + ⟨Int.natCast_nonneg _, by exact_mod_cast r.isLt⟩) (f r) (hf r) (hloc r) + simpa only [sum_windowSum_fin P d hd, Finset.smul_sum] using + tendsto_finsetSum Finset.univ (fun r _ => hres r) + +end +end SourcePointLaw + + + +open scoped Topology BigOperators BoundedContinuousFunction ENNReal +open MeasureTheory Set Filter + +namespace SourcePointLaw +noncomputable section + +def betaMeasure : Measure ℝ := volume.restrict (Icc (0 : ℝ) 1) + +instance betaMeasure_probability : IsProbabilityMeasure betaMeasure where + measure_univ := by simp [betaMeasure] + +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + + + +def betaImage (μ : ProbabilityMeasure X) (T : ℝ × X → Y) (hT : Measurable T) : + ProbabilityMeasure Y := + ⟨Measure.map T (betaMeasure.prod (μ : Measure X)), + (Measure.isProbabilityMeasure_map_iff hT.aemeasurable).mpr inferInstance⟩ + +variable [TopologicalSpace Y] [OpensMeasurableSpace Y] +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + + + +theorem integral_betaImage (μ : ProbabilityMeasure X) (T : ℝ × X → Y) + (hT : Measurable T) (F : Y →ᵇ E) : + ∫ y, F y ∂(betaImage μ T hT : Measure Y) = + ∫ β in (0 : ℝ)..1, ∫ x, F (T (β, x)) ∂(μ : Measure X) := by + change (∫ y, F y ∂Measure.map T (betaMeasure.prod (μ : Measure X))) = _ + rw [integral_map hT.aemeasurable F.continuous.measurable.aestronglyMeasurable] + have hi : Integrable (fun z : ℝ × X => F (T z)) (betaMeasure.prod (μ : Measure X)) := + (integrable_const ‖F‖).mono' + (F.continuous.measurable.comp hT).aestronglyMeasurable + (Eventually.of_forall (fun z => F.norm_coe_le_norm (T z))) + rw [integral_prod _ hi] + rw [intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1)] + exact integral_Icc_eq_integral_Ioc + +end +end SourcePointLaw + +namespace SourcePointLaw +noncomputable section +open scoped Topology BigOperators BoundedContinuousFunction ENNReal +open MeasureTheory Set Filter + +variable {I Y : Type*} [Fintype I] [Nonempty I] [MeasurableSpace Y] + + +def uniformMixture (μ : I → ProbabilityMeasure Y) : ProbabilityMeasure Y := + ⟨(Fintype.card I : ℝ≥0∞)⁻¹ • ∑ i, (μ i : Measure Y), by + constructor + simp [Measure.smul_apply, Finset.sum_apply, ENNReal.inv_mul_cancel, + Fintype.card_ne_zero]⟩ + +variable [TopologicalSpace Y] [OpensMeasurableSpace Y] +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + +lemma integral_uniformMixture (μ : I → ProbabilityMeasure Y) (F : Y →ᵇ E) : + ∫ y, F y ∂(uniformMixture μ : Measure Y) = + (Fintype.card I : ℝ)⁻¹ • ∑ i, ∫ y, F y ∂(μ i : Measure Y) := by + change (∫ y, F y ∂((Fintype.card I : ℝ≥0∞)⁻¹ • ∑ i, (μ i : Measure Y))) = _ + rw [integral_smul_measure, integral_finsetSum_measure] + · simp only [ENNReal.toReal_inv, ENNReal.toReal_natCast] + · intro i hi + exact F.integrable _ + +end +end SourcePointLaw + +end RawSuccessInlineScope1 +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialArray01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialArray01.lean new file mode 100644 index 0000000000000000000000000000000000000000..78f71c6adccb3793cc20bb649214b5ea072e1aaa --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialArray01.lean @@ -0,0 +1,279 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice15 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace PolynomialArrayInterpolation +open CorrectedBoxLeibman MvPolynomial WeightedPolynomial +open IntegerGridInterpolation (tensorWeight tensor_orthogonality) +abbrev Grid := IntegerGridInterpolation.Grid + +lemma bounded_totalDegree {q d : ℕ} {p : MvPolynomial (Fin q) ℝ} + (hp : Bounded (fun _ : Fin q=>1) d p) : p.totalDegree≤d := by + rw [MvPolynomial.totalDegree] + apply Finset.sup_le + intro e he + have hh:=hp e (MvPolynomial.mem_support_iff.mp he) + simpa only [Finsupp.weight_apply,smul_eq_mul,mul_one] using hh + +lemma real_orthogonality (q d : ℕ) (e f : Grid q d) : + ∑ v : Grid q d,(tensorWeight q d e v:ℝ)*∏ i,((v i).val:ℝ)^(f i).val= + if e=f then 1 else 0 := by + have hh:=congrArg (fun x : ℚ => (x:ℝ)) (tensor_orthogonality q d e f) + push_cast at hh + split_ifs at hh ⊢ <;> simpa only [Rat.cast_one,Rat.cast_zero] using hh + +lemma reconstruction (q d : ℕ) (a : Grid q d → ℝ) (e : Grid q d) : + ∑ v : Grid q d,(tensorWeight q d e v:ℝ)* + (∑ f : Grid q d,a f*∏ i,((v i).val:ℝ)^(f i).val)=a e := by + classical + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + simp_rw [mul_left_comm (tensorWeight q d e _:ℝ) (a _)] + simp_rw [← Finset.mul_sum,real_orthogonality] + simp + +def coefficients {q d : ℕ} (f : (Fin q → ℝ) → ℝ) (e : Grid q d) : ℝ:= + ∑ v : Grid q d,(tensorWeight q d e v:ℝ)*f (fun i=>((v i).val:ℝ)) + +lemma coefficients_eval {q d : ℕ} (p : MvPolynomial (Fin q) ℝ) (hp : p.totalDegree≤d) + (e : Grid q d) : coefficients (fun x=>eval x p) e=polynomialGrid p e := by + unfold coefficients + simp_rw [← gridEval_polynomial p hp] + exact reconstruction q d (polynomialGrid p) e + +lemma reconstruction_function {q d : ℕ} {f : (Fin q → ℝ) → ℝ} + (hf : IsWeighted (fun _ : Fin q=>1) d f) (x : Fin q → ℝ) : + gridEval (coefficients f : Grid q d → ℝ) x=f x := by + obtain ⟨p,hp,he⟩:=hf + have htd:=bounded_totalDegree hp + have hf : f=fun x=>eval x p:=funext he + rw [hf] + have hc : (coefficients (fun x=>eval x p) : Grid q d → ℝ)=polynomialGrid p := + funext (coefficients_eval p htd) + rw [hc] + exact gridEval_polynomial p htd x + +lemma coefficients_zero_high {q d : ℕ} {f : (Fin q → ℝ) → ℝ} {k : ℕ} + (hf : IsWeighted (fun _ : Fin q=>1) k f) (hkd : k≤d) (e : Grid q d) + (he : keval x p:=funext hf + rw [hfun,coefficients_eval p (htd.trans hkd)] + change p.coeff (gridExponent e)=0 + by_contra hn + have hh:=hp (gridExponent e) hn + have hd : Finsupp.weight (fun _ : Fin q=>1) (gridExponent e)=PolynomialLineCoefficients.totalDegree e := by + rw [Finsupp.weight_apply] + simpa only [smul_eq_mul,mul_one] using gridExponent_degree e + rw [hd] at hh + omega + +lemma coefficients_continuous {q d : ℕ} (e : Grid q d) : + Continuous (fun f : ((Fin q → ℝ) → ℝ)=>coefficients f e) := by + apply continuous_finsetSum + intro v hv + exact continuous_const.mul (continuous_apply _) + +lemma gridEval_weighted {q d k : ℕ} (a : Grid q d → ℝ) + (ha : ∀ e,k1) k (gridEval a) := by + classical + refine ⟨∑ e : Grid q d,monomial (gridExponent e) (a e),?_,?_⟩ + · apply bounded_sum + intro e he m hm + have hme : gridExponent e=m := by + by_contra h + simp only [coeff_monomial,h,ite_false] at hm + exact hm rfl + subst m + have hae : a e≠0 := by simpa only [coeff_monomial,ite_true] using hm + have hd : Finsupp.weight (fun _ : Fin q=>1) (gridExponent e)= + PolynomialLineCoefficients.totalDegree e := by + rw [Finsupp.weight_apply] + simpa only [smul_eq_mul,mul_one] using gridExponent_degree e + rw [hd] + by_contra h + exact hae (ha e (Nat.lt_of_not_ge h)) + · intro x + simp only [gridEval,map_sum,eval_monomial] + apply Finset.sum_congr rfl + intro e he + congr 1 + rw [Finsupp.prod_fintype _ _ (by intro i; simp)] + rfl + +lemma coefficients_gridEval {q d : ℕ} (a : Grid q d → ℝ) (e : Grid q d) : + coefficients (gridEval a) e=a e := reconstruction q d a e + +lemma grid_injective {q d : ℕ} {f g : (Fin q → ℝ) → ℝ} + (hf : IsWeighted (fun _ : Fin q=>1) d f) + (hg : IsWeighted (fun _ : Fin q=>1) d g) + (hfg : ∀ v : Grid q d,f (fun i=>((v i).val:ℝ))=g (fun i=>((v i).val:ℝ))) : f=g := by + have hc : (coefficients f : Grid q d → ℝ)=coefficients g := by + funext e + simp only [coefficients,hfg] + funext x + rw [← reconstruction_function hf x,← reconstruction_function hg x,hc] + +end PolynomialArrayInterpolation +end + +end + +section + + + +noncomputable section +namespace SortedFiniteWeights +variable {σ : Type*} [Fintype σ] +lemma exists_ordered (w : σ → ℕ) : + ∃ e : Fin (Fintype.card σ) ≃ σ,Monotone (fun i=>w (e i)) := by + classical + let f (i : σ) : ℕ ×ₗ Fin (Fintype.card σ):=toLex (w i,Fintype.equivFin σ i) + have hf : Function.Injective f := by + intro i j h + apply (Fintype.equivFin σ).injective + exact congrArg (fun x=> (ofLex x).2) h + let : LinearOrder σ:=LinearOrder.lift' f hf + let e:=Fintype.orderIsoFinOfCardEq σ rfl + refine ⟨e.toEquiv,?_⟩ + intro i j hij + have hh : f (e i) ≤ f (e j):=e.monotone hij + rcases Prod.Lex.le_iff.mp hh with h|h + · exact Nat.le_of_lt h + · exact le_of_eq h.1 + +def indexing (w : σ → ℕ) : Fin (Fintype.card σ) ≃ σ:=(exists_ordered w).choose +lemma indexing_monotone (w : σ → ℕ) : Monotone (fun i=>w (indexing w i)) := + (exists_ordered w).choose_spec + +end SortedFiniteWeights +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalLattice.PolynomialArrays +open PolynomialArrayInterpolation WeightedPolynomial MalcevCharacters +open CorrectedBoxLeibman (gridEval) +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w icanonicalExp c (toLog w x u)) := by + intro i + simp only [canonicalLog_exp] + apply gridEval_weighted + intro e he + simp only [fullCoeff,dite_eq_right (not_le.mpr he)] + +def coefficients (f : group (q:=q) c hsk A w hA) (a : Index w q) : ℝ := + PolynomialArrayInterpolation.coefficients (fun u=>canonicalLog c (f.val u) a.1) a.2.val + +lemma fullCoeff_coefficients (f : group (q:=q) c hsk A w hA) (i : Fin n) : + fullCoeff w (coefficients c hsk A w hA f) i= + PolynomialArrayInterpolation.coefficients (fun u=>canonicalLog c (f.val u) i) := by + funext e + dsimp only [fullCoeff] + split_ifs with he + · rfl + · exact (coefficients_zero_high (f.property i) le_rfl e (Nat.lt_of_not_ge he)).symm + +lemma toLog_coefficients (f : group (q:=q) c hsk A w hA) (u : Fin q → ℝ) : + toLog w (coefficients c hsk A w hA f) u=canonicalLog c (f.val u) := by + funext i + rw [toLog,fullCoeff_coefficients] + exact reconstruction_function (f.property i) u + +lemma coefficients_toLog (x : Index w q → ℝ) (a : Index w q) : + PolynomialArrayInterpolation.coefficients (fun u=>toLog w x u a.1) a.2.val=x a := by + rw [show (fun u=>toLog w x u a.1)=gridEval (fullCoeff w x a.1) from rfl, + coefficients_gridEval] + simp only [fullCoeff,dite_eq_left a.2.property] + +lemma toLog_continuous (u : Fin q → ℝ) : Continuous (fun x : Index w q → ℝ=>toLog w x u) := by + apply continuous_pi + intro i + apply continuous_finsetSum + intro e he + apply Continuous.mul _ continuous_const + unfold fullCoeff + split_ifs + · exact continuous_apply _ + · exact continuous_const + +lemma coefficients_continuous : Continuous (coefficients (q:=q) c hsk A w hA) := by + apply continuous_pi + intro a + apply (PolynomialArrayInterpolation.coefficients_continuous a.2.val).comp + apply continuous_pi + intro u + exact (continuous_apply a.1).comp ((canonicalLog_continuous c).comp + ((continuous_apply u).comp continuous_subtype_val)) + +def coefficientHomeomorph : group (q:=q) c hsk A w hA ≃ₜ (Index w q → ℝ) where + toFun:=coefficients c hsk A w hA + invFun x:=⟨fun u=>canonicalExp c (toLog w x u),toLog_array c w x⟩ + left_inv f:=by + apply Subtype.ext + funext u + change canonicalExp c (toLog w (coefficients c hsk A w hA f) u)=f.val u + rw [toLog_coefficients,canonicalExp_log] + right_inv x:=by + funext a + change PolynomialArrayInterpolation.coefficients + (fun u=>canonicalLog c (canonicalExp c (toLog w x u)) a.1) a.2.val=x a + simp only [canonicalLog_exp] + exact coefficients_toLog w x a + continuous_toFun:=coefficients_continuous c hsk A w hA + continuous_invFun:=by + apply Continuous.subtype_mk + apply continuous_pi + intro u + exact (logHomeomorph c).symm.continuous.comp (toLog_continuous w u) + +lemma coefficientHomeomorph_one : coefficientHomeomorph (q:=q) c hsk A w hA 1=0 := by + funext a + change PolynomialArrayInterpolation.coefficients (fun u=>canonicalLog c (1:G) a.1) a.2.val=0 + simp [PolynomialArrayInterpolation.coefficients,canonicalLog_one] + +end RationalLattice.PolynomialArrays + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialCharacter01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialCharacter01.lean new file mode 100644 index 0000000000000000000000000000000000000000..a44cd7cf1f881c3ea8f048f35f50bb689f7fbc3d --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialCharacter01.lean @@ -0,0 +1,342 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevHorizontal02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial Finset +open scoped BigOperators +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial Finset +open scoped BigOperators +namespace PolynomialCharacterDescent + +lemma derivative_bound (d N : ℕ) (hN : 0 < N) (C : ℝ) (hC : 0 ≤ C) + (p : ℝ[X]) (hp : p.natDegree ≤ d) + (hc : ∀ j : ℕ, 0 < j → j ≤ d → |p.coeff j| ≤ C/(N:ℝ)^j) + (x : ℝ) (hx : x ∈ Set.Icc 0 (N:ℝ)) : + |p.derivative.eval x| ≤ ((d+1):ℝ)*d*C/N := by + have hNr : (0:ℝ) if 2 norm_num <;> positivity + intro h hh + have hbound := derivative_bound d N hN C hC p hpd hpc h + ⟨Nat.cast_nonneg _,by exact_mod_cast hh.le⟩ + have huval : (u.map (Int.castRingHom ℝ)).derivative.eval (h:ℝ) = + ((u.derivative.eval (h:ℤ):ℤ):ℝ) := by + rw [derivative_map,eval_map] + exact eval₂_at_apply (Int.castRingHom ℝ) (h:ℤ) + refine ⟨u.derivative.eval h,?_⟩ + convert hbound using 2 + simp only [p,derivative_sub,derivative_C_mul,eval_sub,eval_mul,eval_C,huval, + coeff_sub,taylor_coeff_one] + simp only [low,derivative_add,derivative_mul,derivative_C,zero_mul,derivative_X, + mul_one,derivative_pow,eval_add,eval_mul,eval_C] + norm_num + ring + + + +theorem polynomial_descent (d : ℕ) (hd : 2 ≤ d) (δ A : ℝ) (hδ : 0 < δ) (hA : 0 ≤ A) : + ∃ B : ℕ, 0 < B ∧ ∃ C : ℝ, 0 < C ∧ ∃ N₀ : ℕ, 0 < N₀ ∧ + ∀ N : ℕ, N₀ ≤ N → ∀ P Q : ℝ[X], Q.natDegree ≤ d → + ∀ σ : ℕ → ℝ, ∀ S : Finset ℕ, S ⊆ range N → δ*N ≤ (S.card:ℝ) → + (∀ h ∈ S, ∃ z : ℤ, |(P+taylor (h:ℝ) Q-Q).coeff 2-z| ≤ A/(N:ℝ)^2) → + (∀ h ∈ S, ∃ z : ℤ, |(P+taylor (h:ℝ) Q-Q).coeff 1+σ h-z| ≤ A/N) → + ∃ q : ℤ, q ≠ 0 ∧ |q| ≤ B ∧ + (∀ j : ℕ, 2 < j → j ≤ d → ∃ m : ℤ, |(q:ℝ)*Q.coeff j-m| ≤ C/(N:ℝ)^j) ∧ + (∀ h ∈ S, ∃ z : ℤ, |(q:ℝ)*P.coeff 1+2*(q:ℝ)*Q.coeff 2*h+(q:ℝ)*σ h-z| ≤ C/N) := by + classical + obtain ⟨B,hB,C,hC,L,hL,hdesc⟩ := high_coefficients d δ A hδ hA + let C' := max C ((B:ℝ)*A+((d+1):ℝ)*d*C) + have hCC : C ≤ C' := le_max_left _ _ + have hsum : (B:ℝ)*A+((d+1):ℝ)*d*C ≤ C' := le_max_right _ _ + refine ⟨B,hB,C',hC.trans_le hCC,L,hL,?_⟩ + intro N hLN P Q hQ σ S hSN hS hsecond hfirst + have hN : 0 hm⟩ + · exact ⟨0,fun h₁ h₂ => False.elim (hj ⟨h₁,h₂⟩)⟩ + choose m hm using hex + refine ⟨q,hq,hqB,?_,?_⟩ + · intro j hj hjd + exact ⟨m j,(hm j hj hjd).trans (div_le_div_of_nonneg_right hCC (by positivity))⟩ + · intro h hh + obtain ⟨z,hz⟩ := linear_residual d N hd hN Q hQ q C hC.le m hm h (mem_range.mp (hSN hh)) + obtain ⟨k,hk⟩ := hfirst h hh + have hqR : |(q:ℝ)| ≤ B := by exact_mod_cast hqB + refine ⟨q*k-z,?_⟩ + calc + _ = |(q:ℝ)*((P+taylor (h:ℝ) Q-Q).coeff 1+σ h-k)- + ((q:ℝ)*(taylor (h:ℝ) Q-Q).coeff 1-2*(q:ℝ)*Q.coeff 2*h-z)| := by + push_cast + congr 1 + simp only [coeff_sub,coeff_add] + ring + _ ≤ |(q:ℝ)*((P+taylor (h:ℝ) Q-Q).coeff 1+σ h-k)|+ + |(q:ℝ)*(taylor (h:ℝ) Q-Q).coeff 1-2*(q:ℝ)*Q.coeff 2*h-z| := abs_sub _ _ + _ ≤ (B:ℝ)*(A/N)+((d+1):ℝ)*d*C/N := by + apply add_le_add _ hz + rw [abs_mul] + exact mul_le_mul hqR hk (abs_nonneg _) (Nat.cast_nonneg B) + _ = ((B:ℝ)*A+((d+1):ℝ)*d*C)/N := by ring + _ ≤ C'/N := div_le_div_of_nonneg_right hsum hNr.le + +end PolynomialCharacterDescent +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial Finset +open scoped BigOperators +namespace PolynomialCharacterDescent + +lemma taylor_coefficient_bound (d N : ℕ) (hN : 0 first | exact hx.1 | exact hx.2 + _ = |p.coeff (k+j)| * (N:ℝ)^(k+j) := by rw [pow_add]; ring + _ ≤ C := hcoef + rw [abs_mul,abs_mul,abs_of_nonneg (Nat.cast_nonneg _),abs_of_nonneg (pow_nonneg hx.1 _)] + apply (le_div_iff₀ (pow_pos hNr j)).mpr + calc + _ = ((k+j).choose j:ℝ)*(|p.coeff (k+j)| * x^k*(N:ℝ)^j) := by ring + _ ≤ ((k+j).choose j:ℝ)*C := mul_le_mul_of_nonneg_left hsmall (Nat.cast_nonneg _) + _ ≤ _ := mul_le_mul_of_nonneg_right hchoose hC + · rw [coeff_eq_zero_of_natDegree_lt (by omega),mul_zero,zero_mul,abs_zero] + positivity + calc + _ ≤ ∑ k∈range (d+1),|((hasseDeriv j p).coeff k)*x^k| := abs_sum_le_sum_abs _ _ + _ ≤ ∑ _k∈range (d+1),(2:ℝ)^d*C/(N:ℝ)^j := sum_le_sum hterm + _ = _ := by simp only [sum_const,card_range,nsmul_eq_mul]; push_cast; ring + + + +lemma nonlinear_shift_residual (d N : ℕ) (hd : 1≤d) (hN : 0 if 1 hsmall h hh 1 (by decide) hd) + have hex (j : ℕ) : ∃ m : ℤ, 1 hm⟩ + · exact ⟨0,fun h1 h2 => (hj ⟨h1,h2⟩).elim⟩ + choose m hm using hex + have hres := nonlinear_shift_residual d N hd hN Q hQ q C hC.le m hm + have hqBr : |(q:ℝ)|≤B := by exact_mod_cast hqB + refine ⟨q,hq,hqB,?_,?_⟩ + · intro j hj + by_cases hjd : j≤d + · have hpos : (0:ℝ) (n : ℝ) ^ d) (N - 1) + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + have h := pow_le_pow_left₀ (by positivity : (0 : ℝ) ≤ ((N - 1 : ℕ) : ℝ)) + (show ((N - 1 : ℕ) : ℝ) ≤ N by exact_mod_cast Nat.sub_le N 1) d + linarith [pow_nonneg (show (0 : ℝ) ≤ 0 by rfl) d] + + + +theorem weighted_mean_large_prefix (N : ℕ) (hN : 0 < N) + (f w : ℕ → ℂ) (hf : ∀ n, ‖f n‖ ≤ 1) (hw : ∀ n, ‖w n‖ ≤ 1) + (V δ : ℝ) (hV : 0 ≤ V) (hδ : 0 < δ) + (hvar : ∑ n ∈ Finset.range (N - 1), ‖w (n + 1) - w n‖ ≤ V) + (hlarge : δ ≤ ‖mean N (fun n => w n * f n)‖) : + ∃ M : ℕ, 0 < M ∧ M ≤ N ∧ δ * N / (1 + V) ≤ M ∧ + δ / (1 + V) ≤ ‖mean M f‖ := by + classical + let F : ℕ → ℂ := fun M => ∑ n ∈ Finset.range M, f n + obtain ⟨M, hM, hmax⟩ := (Finset.Icc 1 N).exists_max_image (fun M => ‖F M‖) + ⟨1, Finset.mem_Icc.mpr ⟨le_rfl, hN⟩⟩ + have hM₀ : 0 < M := (Finset.mem_Icc.mp hM).1 + have hMN : M ≤ N := (Finset.mem_Icc.mp hM).2 + have hbound : ‖∑ n ∈ Finset.range N, w n * f n‖ ≤ (1 + V) * ‖F M‖ := by + have he := Finset.sum_range_by_parts w f N + simp only [smul_eq_mul] at he + rw [he] + calc + _ ≤ ‖w (N - 1) * F N‖ + + ‖∑ n ∈ Finset.range (N - 1), (w (n + 1) - w n) * F (n + 1)‖ := norm_sub_le _ _ + _ ≤ 1 * ‖F M‖ + ∑ n ∈ Finset.range (N - 1), ‖w (n + 1) - w n‖ * ‖F M‖ := by + apply add_le_add + · rw [norm_mul] + exact mul_le_mul (hw _) (hmax N (Finset.mem_Icc.mpr ⟨hN, le_rfl⟩)) + (norm_nonneg _) (by norm_num) + · apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro n hn + rw [norm_mul] + apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) + exact hmax (n + 1) (Finset.mem_Icc.mpr ⟨by omega, + by have := Finset.mem_range.mp hn; omega⟩) + _ ≤ (1 + V) * ‖F M‖ := by + rw [← Finset.sum_mul] + nlinarith only [mul_le_mul_of_nonneg_right hvar (norm_nonneg (F M))] + have hsum : δ * N ≤ (1 + V) * ‖F M‖ := by + have he : ‖mean N (fun n => w n * f n)‖ = + ‖∑ n ∈ Finset.range N, w n * f n‖ / N := by + simp [mean, Finset.expect_eq_sum_div_card ] + rw [he] at hlarge + exact ((le_div_iff₀ (Nat.cast_pos.mpr hN)).mp hlarge).trans hbound + have hF : ‖F M‖ ≤ M := by + apply (norm_sum_le _ _).trans + calc + (∑ n ∈ Finset.range M, ‖f n‖) ≤ ∑ n ∈ Finset.range M, (1 : ℝ) := + Finset.sum_le_sum (fun n _ => hf n) + _ = M := by simp + have hVM : 0 < 1 + V := by linarith + refine ⟨M, hM₀, hMN, ?_, ?_⟩ + · apply (div_le_iff₀ hVM).mpr + nlinarith only [hsum, hF, mul_le_mul_of_nonneg_left hF hVM.le] + · have he : ‖mean M f‖ = ‖F M‖ / M := by + simp [mean, F, Finset.expect_eq_sum_div_card ] + rw [he] + apply (div_le_div_iff₀ hVM (Nat.cast_pos.mpr hM₀)).mpr + have hMN' : (M : ℝ) ≤ N := by exact_mod_cast hMN + nlinarith only [hsum, mul_le_mul_of_nonneg_left hMN' hδ.le] + + +def fourierCoefficient {q : ℕ} [NeZero q] (F : ZMod q → ℂ) (k : ZMod q) : ℂ := + (q : ℂ)⁻¹ * ZMod.dft F k + +theorem norm_fourierCoefficient_le_one {q : ℕ} [NeZero q] + (F : ZMod q → ℂ) (hF : ∀ x, ‖F x‖ ≤ 1) (k : ZMod q) : + ‖fourierCoefficient F k‖ ≤ 1 := by + have he : fourierCoefficient F k = + 𝔼 j : ZMod q, ZMod.stdAddChar (-(j * k)) * F j := by + simp [fourierCoefficient, ZMod.dft_apply, Finset.expect_eq_sum_div_card, div_eq_mul_inv, + mul_comm] + rw [he] + apply (RCLike.norm_expect_le (K := ℂ)).trans + apply Finset.expect_le Finset.univ_nonempty + intro j _ + simpa only [norm_mul, ZMod.stdAddChar_apply, Circle.norm_coe, one_mul] using hF j + +theorem fourier_expansion {q : ℕ} [NeZero q] (F : ZMod q → ℂ) (x : ZMod q) : + F x = ∑ k : ZMod q, fourierCoefficient F k * ZMod.stdAddChar (k * x) := by + have h := congrFun (ZMod.dft.symm_apply_apply F) x + rw [ZMod.invDFT_apply] at h + rw [← h] + simp only [smul_eq_mul, Finset.mul_sum, fourierCoefficient] + apply Finset.sum_congr rfl + intro k _ + ring + +theorem stdAddChar_int_phase {q : ℕ} [NeZero q] (z : ℤ) : + ZMod.stdAddChar (z : ZMod q) = phase ((z : ℝ) / q) := by + rw [ZMod.stdAddChar_coe, phase] + congr 1 + push_cast + ring + +theorem stdAddChar_mul_nat_phase {q : ℕ} [NeZero q] (k : ZMod q) (n : ℕ) : + ZMod.stdAddChar (k * (n : ZMod q)) = phase ((k.val : ℝ) / q * n) := by + have he : (((k.val : ℤ) * n : ℤ) : ZMod q) = k * (n : ZMod q) := by simp + rw [← he, stdAddChar_int_phase] + congr 1 + push_cast + ring + +theorem rational_monomial_phase {q : ℕ} [NeZero q] (m : ℤ) (d n : ℕ) : + phase ((m : ℝ) / q * (n : ℝ) ^ d) = + ZMod.stdAddChar ((m : ZMod q) * (n : ZMod q) ^ d) := by + have he : ((m * (n : ℤ) ^ d : ℤ) : ZMod q) = + (m : ZMod q) * (n : ZMod q) ^ d := by push_cast; rfl + rw [← he, stdAddChar_int_phase] + congr 1 + push_cast + ring + + + +theorem periodic_weight_large_frequency {q : ℕ} [NeZero q] + (F : ZMod q → ℂ) (hF : ∀ x, ‖F x‖ ≤ 1) (f : ℕ → ℂ) + (N : ℕ) (δ : ℝ) (hlarge : δ ≤ ‖mean N (fun n => F (n : ZMod q) * f n)‖) : + ∃ k : ZMod q, δ / q ≤ + ‖mean N (fun n => ZMod.stdAddChar (k * (n : ZMod q)) * f n)‖ := by + classical + let G := fun k : ZMod q => mean N (fun n => ZMod.stdAddChar (k * (n : ZMod q)) * f n) + have he : mean N (fun n => F (n : ZMod q) * f n) = + ∑ k : ZMod q, fourierCoefficient F k * G k := by + unfold mean + conv_lhs => arg 2; ext n; dsimp only; rw [fourier_expansion F (n : ZMod q)] + simp_rw [Finset.sum_mul, mul_assoc] + rw [Finset.expect_sum_comm] + simp_rw [← Finset.mul_expect] + rfl + obtain ⟨k, _, hmax⟩ := Finset.univ.exists_max_image (fun k : ZMod q => ‖G k‖) + Finset.univ_nonempty + refine ⟨k, ?_⟩ + have hbound : δ ≤ (q : ℝ) * ‖G k‖ := by + apply hlarge.trans + rw [he] + apply (norm_sum_le _ _).trans + calc + (∑ j : ZMod q, ‖fourierCoefficient F j * G j‖) ≤ ∑ _j : ZMod q, ‖G k‖ := by + apply Finset.sum_le_sum + intro j _ + rw [norm_mul] + exact (mul_le_mul (norm_fourierCoefficient_le_one F hF j) + (hmax j (Finset.mem_univ j)) (norm_nonneg _) (by norm_num)).trans_eq (one_mul _) + _ = (q : ℝ) * ‖G k‖ := by simp + apply (div_le_iff₀ (show 0 < (q : ℝ) by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne q))).mpr + nlinarith only [hbound] + + + +theorem remove_rational_monomial (q B N d : ℕ) (hq : 0 < q) (hqB : q ≤ B) + (hN : 0 < N) (m : ℤ) (ε A δ : ℝ) (hA : 0 ≤ A) (hδ : 0 < δ) + (hε : |ε| * (N : ℝ) ^ d ≤ A) (f : ℕ → ℂ) (hf : ∀ n, ‖f n‖ ≤ 1) + (hlarge : δ ≤ ‖mean N (fun n => + phase ((m : ℝ) / q * (n : ℝ) ^ d) * phase (ε * (n : ℝ) ^ d) * f n)‖) : + ∃ l : ℕ, l < q ∧ ∃ M : ℕ, 0 < M ∧ M ≤ N ∧ + δ / ((B : ℝ) * (1 + 2 * Real.pi * A)) * N ≤ M ∧ + δ / ((B : ℝ) * (1 + 2 * Real.pi * A)) ≤ + ‖mean M (fun n => phase ((l : ℝ) / q * n) * f n)‖ := by + let : NeZero q := ⟨Nat.ne_of_gt hq⟩ + let F : ZMod q → ℂ := fun x => ZMod.stdAddChar ((m : ZMod q) * x ^ d) + have hlarge' : δ ≤ ‖mean N (fun n => + F (n : ZMod q) * (phase (ε * (n : ℝ) ^ d) * f n))‖ := by + simpa only [F, ← rational_monomial_phase, mul_assoc] using hlarge + obtain ⟨k, hk⟩ := periodic_weight_large_frequency F + (fun x => by simp [F, ZMod.stdAddChar_apply, Circle.norm_coe]) + (fun n => phase (ε * (n : ℝ) ^ d) * f n) N δ hlarge' + have hk' : δ / q ≤ ‖mean N (fun n => phase (ε * (n : ℝ) ^ d) * + (phase ((k.val : ℝ) / q * n) * f n))‖ := by + simpa only [stdAddChar_mul_nat_phase, mul_left_comm] using hk + obtain ⟨M, hM, hMN, hlength, hmean⟩ := weighted_mean_large_prefix N hN + (fun n => phase ((k.val : ℝ) / q * n) * f n) + (fun n => phase (ε * (n : ℝ) ^ d)) + (fun n => by simpa only [norm_mul, norm_phase, one_mul] using hf n) + (fun n => by simp) (2 * Real.pi * A) (δ / q) (by positivity) (by positivity) + (by + apply (monomial_phase_variation N d ε).trans + have h := mul_le_mul_of_nonneg_left hε (by positivity : 0 ≤ 2 * Real.pi) + nlinarith only [h]) hk' + have hq₀ : 0 < (q : ℝ) := Nat.cast_pos.mpr hq + have hB₀ : 0 < (B : ℝ) := Nat.cast_pos.mpr (hq.trans_le hqB) + have hden : 0 < 1 + 2 * Real.pi * A := by positivity + have hweak : δ / ((B : ℝ) * (1 + 2 * Real.pi * A)) ≤ + (δ / q) / (1 + 2 * Real.pi * A) := by + rw [div_div] + apply div_le_div_of_nonneg_left hδ.le (by positivity) + exact mul_le_mul_of_nonneg_right (Nat.cast_le.mpr hqB) hden.le + refine ⟨k.val, ZMod.val_lt k, M, hM, hMN, ?_, hweak.trans hmean⟩ + have he : (δ / q) * N / (1 + 2 * Real.pi * A) = + ((δ / q) / (1 + 2 * Real.pi * A)) * N := by ring + rw [he] at hlength + exact (mul_le_mul_of_nonneg_right hweak (Nat.cast_nonneg N)).trans hlength + +end +end PolynomialDephasing + +namespace WeylCoefficients +open scoped BigOperators ComplexConjugate +open PolynomialWeyl PolynomialDephasing WeylInverse +noncomputable section + + + +def lowerWithFrequency (p : Polynomial ℝ) (d l q : ℕ) : Polynomial ℝ := + p.erase (d + 1) + Polynomial.monomial 1 ((l : ℝ) / q) + +theorem lowerWithFrequency_degree (p : Polynomial ℝ) (d l q : ℕ) + (hd : 0 < d) (hp : p.natDegree ≤ d + 1) : + (lowerWithFrequency p d l q).natDegree ≤ d := by + apply Polynomial.natDegree_add_le_of_degree_le + · rw [Polynomial.natDegree_le_iff_coeff_eq_zero] + intro j hj + by_cases he : j = d + 1 + · simp [he] + · rw [Polynomial.erase_ne p he] + exact Polynomial.coeff_eq_zero_of_natDegree_lt (by omega) + · exact (Polynomial.natDegree_monomial_le _).trans hd + +theorem lowerWithFrequency_coeff (p : Polynomial ℝ) (d l q j : ℕ) (hj : j ≤ d) : + (lowerWithFrequency p d l q).coeff j = p.coeff j + if j = 1 then (l : ℝ) / q else 0 := by + simp only [lowerWithFrequency, Polynomial.coeff_add, + Polynomial.erase_ne p (show j ≠ d + 1 by omega), Polynomial.coeff_monomial] + by_cases he : j = 1 <;> simp [he, eq_comm] + + + +theorem remove_leading_coefficient (d A N q : ℕ) (_hA : 0 < A) (hN : 0 < N) + (hq : 0 < q) (hqA : q ≤ A) (p : Polynomial ℝ) (m : ℤ) (δ : ℝ) (hδ : 0 < δ) + (hm : |(q : ℝ) * p.coeff (d + 1) - m| ≤ (A : ℝ) / (N : ℝ) ^ (d + 1)) + (hlarge : δ ≤ ‖mean N (polynomialPhase p)‖) : + ∃ l : ℕ, l < q ∧ ∃ M : ℕ, 0 < M ∧ M ≤ N ∧ + δ / ((A : ℝ) * (1 + 2 * Real.pi * A)) * N ≤ M ∧ + δ / ((A : ℝ) * (1 + 2 * Real.pi * A)) ≤ + ‖mean M (polynomialPhase (lowerWithFrequency p d l q))‖ := by + let ε := p.coeff (d + 1) - (m : ℝ) / q + have hq₀ : 0 < (q : ℝ) := Nat.cast_pos.mpr hq + have hq₁ : 1 ≤ (q : ℝ) := by exact_mod_cast hq + have hεeq : (q : ℝ) * ε = (q : ℝ) * p.coeff (d + 1) - m := by + dsimp [ε] + field_simp + have hε : |ε| * (N : ℝ) ^ (d + 1) ≤ A := by + apply (le_div_iff₀ (pow_pos (Nat.cast_pos.mpr hN) _)).mp + apply le_trans _ hm + rw [← hεeq, abs_mul, abs_of_pos hq₀] + have h := mul_le_mul_of_nonneg_right hq₁ (abs_nonneg ε) + simpa only [one_mul] using h + have he (n : ℕ) : p.eval (n : ℝ) = + (m : ℝ) / q * (n : ℝ) ^ (d + 1) + ε * (n : ℝ) ^ (d + 1) + + (p.erase (d + 1)).eval (n : ℝ) := by + have h := congrArg (fun u : Polynomial ℝ => u.eval (n : ℝ)) (p.monomial_add_erase (d + 1)) + simp only [Polynomial.eval_add, Polynomial.eval_monomial] at h + dsimp [ε] + linarith only [h] + obtain ⟨l, hl, M, hM, hMN, hlength, hmean⟩ := remove_rational_monomial q A N (d + 1) + hq hqA hN m ε A δ (Nat.cast_nonneg _) hδ hε (polynomialPhase (p.erase (d + 1))) + (fun n => by simp [polynomialPhase]) (by + change δ ≤ ‖mean N (fun n => phase (p.eval (n : ℝ)))‖ at hlarge + simp_rw [he, phase_add] at hlarge + exact hlarge) + refine ⟨l, hl, M, hM, hMN, hlength, ?_⟩ + have hfun : polynomialPhase (lowerWithFrequency p d l q) = + (fun n : ℕ => phase ((l : ℝ) / q * (n : ℝ)) * polynomialPhase (p.erase (d + 1)) n) := by + funext n + simp [polynomialPhase, lowerWithFrequency, Polynomial.eval_add, + Polynomial.eval_monomial, phase_add, mul_comm] + rw [hfun] + exact hmean + + + +theorem prefix_error_transfer (N M T d j : ℕ) (hN : 0 < N) (hM : 0 < M) + (hT : 1 ≤ T) (hj : j ≤ d) (hNM : (N : ℝ) ≤ (T : ℝ) * M) + (C : ℝ) (hC : 0 ≤ C) : + C / (M : ℝ) ^ j ≤ C * (T : ℝ) ^ d / (N : ℝ) ^ j := by + apply (div_le_div_iff₀ (pow_pos (Nat.cast_pos.mpr hM) _) + (pow_pos (Nat.cast_pos.mpr hN) _)).mpr + have hpow : (N : ℝ) ^ j ≤ (T : ℝ) ^ d * (M : ℝ) ^ j := by + calc + _ ≤ ((T : ℝ) * M) ^ j := pow_le_pow_left₀ (Nat.cast_nonneg _) hNM _ + _ = (T : ℝ) ^ j * (M : ℝ) ^ j := mul_pow .. + _ ≤ _ := mul_le_mul_of_nonneg_right (pow_le_pow_right₀ (by exact_mod_cast hT) hj) + (by positivity) + have h := mul_le_mul_of_nonneg_left hpow hC + nlinarith only [h] + + + +def CoefficientInverse (d : ℕ) : Prop := + ∀ δ : ℝ, 0 < δ → ∃ A : ℕ, 0 < A ∧ + ∀ N : ℕ, 0 < N → ∀ p : Polynomial ℝ, p.natDegree ≤ d → + δ ≤ ‖mean N (polynomialPhase p)‖ → + ∃ q : ℕ, 0 < q ∧ q ≤ A ∧ ∃ m : ℕ → ℤ, + ∀ j : ℕ, 0 < j → j ≤ d → + |(q : ℝ) * p.coeff j - m j| ≤ (A : ℝ) / (N : ℝ) ^ j + +theorem coefficient_inverse_zero : CoefficientInverse 0 := by + intro δ _ + refine ⟨1, by omega, ?_⟩ + intro N _ p _ _ + exact ⟨1, by omega, le_rfl, fun _ => 0, fun j hj hj' => by omega⟩ + +theorem coefficient_inverse_one : CoefficientInverse 1 := by + intro δ hδ + obtain ⟨A, hA, hinv⟩ := leading_inverse_one δ hδ + refine ⟨A, hA, ?_⟩ + intro N hN p hp hlarge + obtain ⟨q, hq, hqA, m, hm⟩ := hinv N hN p hp hlarge + refine ⟨q, hq, hqA, fun _ => m, ?_⟩ + intro j hj hj' + have : j = 1 := by omega + subst j + exact hm + + + +theorem coefficient_inverse_succ (d : ℕ) (hd : 0 < d) + (ih : CoefficientInverse d) : CoefficientInverse (d + 1) := by + intro δ hδ + obtain ⟨A, hA, hlead⟩ := leading_inverse (d + 1) (by omega) δ hδ + let τ := δ / ((A : ℝ) * (1 + 2 * Real.pi * A)) + have hτ : 0 < τ := by dsimp [τ]; positivity + obtain ⟨A', hA', hlower⟩ := ih τ hτ + obtain ⟨T, hT⟩ := exists_nat_gt (max (1 : ℝ) (1 / τ)) + have hT₁ : 1 ≤ (T : ℝ) := (le_max_left _ _).trans hT.le + have hTnat : 1 ≤ T := by exact_mod_cast hT₁ + have hTτ : 1 ≤ (T : ℝ) * τ := + (div_le_iff₀ hτ).mp ((le_max_right _ _).trans hT.le) + let C := A * A' + let B := C * T ^ d + C + 1 + have hB : 0 < B := by dsimp [B]; omega + have hCB : C ≤ B := by dsimp [B]; omega + have hCTB : C * T ^ d ≤ B := by dsimp [B]; omega + refine ⟨B, hB, ?_⟩ + intro N hN p hp hlarge + obtain ⟨q, hq, hqA, m, hm⟩ := hlead N hN p hp hlarge + obtain ⟨l, _, M, hM, _, hlength, hmean⟩ := remove_leading_coefficient d A N q + hA hN hq hqA p m δ hδ hm hlarge + obtain ⟨b, hb, hbA', z, hz⟩ := hlower M hM (lowerWithFrequency p d l q) + (lowerWithFrequency_degree p d l q hd hp) hmean + have hNM : (N : ℝ) ≤ (T : ℝ) * M := by + change τ * N ≤ (M : ℝ) at hlength + have h₁ := mul_le_mul_of_nonneg_right hTτ (Nat.cast_nonneg N) + have h₂ := mul_le_mul_of_nonneg_left hlength (Nat.cast_nonneg T) + nlinarith only [h₁, h₂] + let z' : ℕ → ℤ := fun j => if j = d + 1 then (b : ℤ) * m else + (q : ℤ) * z j - if j = 1 then (b : ℤ) * l else 0 + refine ⟨q * b, by positivity, (Nat.mul_le_mul hqA hbA').trans hCB, z', ?_⟩ + intro j hj hjd + have hN₀ : 0 < (N : ℝ) := Nat.cast_pos.mpr hN + have hM₀ : 0 < (M : ℝ) := Nat.cast_pos.mpr hM + have hq₀ : 0 < (q : ℝ) := Nat.cast_pos.mpr hq + have hb₀ : 0 < (b : ℝ) := Nat.cast_pos.mpr hb + have hCB' : (C : ℝ) ≤ B := by exact_mod_cast hCB + by_cases hjtop : j = d + 1 + · subst j + have he : ((q * b : ℕ) : ℝ) * p.coeff (d + 1) - (z' (d + 1) : ℝ) = + (b : ℝ) * ((q : ℝ) * p.coeff (d + 1) - m) := by + simp only [z', ite_eq_left rfl, Int.cast_mul, Int.cast_natCast, Nat.cast_mul] + ring + rw [he, abs_mul, abs_of_pos hb₀] + calc + _ ≤ (b : ℝ) * ((A : ℝ) / (N : ℝ) ^ (d + 1)) := + mul_le_mul_of_nonneg_left hm hb₀.le + _ ≤ (C : ℝ) / (N : ℝ) ^ (d + 1) := by + rw [← mul_div_assoc] + apply div_le_div_of_nonneg_right _ (by positivity) + have h := mul_le_mul_of_nonneg_right (Nat.cast_le.mpr hbA' : (b : ℝ) ≤ A') + (Nat.cast_nonneg A) + simp only [C, Nat.cast_mul] + nlinarith only [h] + _ ≤ _ := div_le_div_of_nonneg_right hCB' (by positivity) + · have hjd' : j ≤ d := by omega + have he : ((q * b : ℕ) : ℝ) * p.coeff j - (z' j : ℝ) = + (q : ℝ) * ((b : ℝ) * (lowerWithFrequency p d l q).coeff j - z j) := by + rw [lowerWithFrequency_coeff p d l q j hjd'] + by_cases hjone : j = 1 + · simp only [z', ite_eq_right hjtop, ite_eq_left hjone, Int.cast_sub, Int.cast_mul, + Int.cast_natCast, Nat.cast_mul] + field_simp + ring + · simp only [z', ite_eq_right hjtop, ite_eq_right hjone, Int.cast_mul, + Int.cast_natCast, Nat.cast_mul, sub_zero, add_zero] + ring + rw [he, abs_mul, abs_of_pos hq₀] + calc + _ ≤ (q : ℝ) * ((A' : ℝ) / (M : ℝ) ^ j) := + mul_le_mul_of_nonneg_left (hz j hj hjd') hq₀.le + _ ≤ (C : ℝ) / (M : ℝ) ^ j := by + rw [← mul_div_assoc] + apply div_le_div_of_nonneg_right _ (by positivity) + have h := mul_le_mul_of_nonneg_right (Nat.cast_le.mpr hqA : (q : ℝ) ≤ A) + (Nat.cast_nonneg A') + simpa only [C, Nat.cast_mul] using h + _ ≤ (C : ℝ) * (T : ℝ) ^ d / (N : ℝ) ^ j := + prefix_error_transfer N M T d j hN hM hTnat hjd' hNM C (Nat.cast_nonneg _) + _ ≤ _ := by + apply div_le_div_of_nonneg_right _ (by positivity) + exact_mod_cast hCTB + + + +theorem coefficient_inverse (d : ℕ) : CoefficientInverse d := by + induction d with + | zero => exact coefficient_inverse_zero + | succ d ih => + by_cases hd : d = 0 + · subst d + exact coefficient_inverse_one + · exact coefficient_inverse_succ d (Nat.pos_of_ne_zero hd) ih + +end +end WeylCoefficients + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialLine01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialLine01.lean new file mode 100644 index 0000000000000000000000000000000000000000..37f2ea37fe488e6c20c4892a20766b838156fcd7 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialLine01.lean @@ -0,0 +1,360 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction14 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus RationalTailCoordinates UnitAddTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (s : ℕ) (hs : H.level (s+1)=⊥) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ b : Fin (t+d)→ℤ, b≠0 ∧ (∀ i, |(b i:ℝ)|≤A) ∧ (∀ a b : G, ξ (a*b*a⁻¹*b⁻¹)=1) ∧ + (∀ g : G, (ξ g).toAdd=∑ i, c.coord g i*(b i:ℝ)) ∧ + ∃ α : ℕ→ℝ, (∀ j : ℕ, s Finset.sum_nonneg (fun i _ => abs_nonneg _)) + let A : ℝ := 1+S+BinomialDifference.conversionBound s*C + have hconv : 0 BinomialDifference.coefficient ℝ j P,?_,?_,?_⟩ + · intro hb0 + apply hξ0 + ext g + apply Multiplicative.toAdd.injective + change (ξ g).toAdd=0 + rw [hb,hb0] + simp + · intro i + have h1 : |(ξ (axis c i 1)).toAdd| ≤ ∑ j, |(ξ (axis c j 1)).toAdd| := + Finset.single_le_sum (f := fun j : Fin (t+d) => |(ξ (axis c j 1)).toAdd|) (fun j _ => abs_nonneg _) (Finset.mem_univ i) + have h2 : (∑ j, |(ξ (axis c j 1)).toAdd|)≤S := + Finset.single_le_sum (f := fun χ : G→*Multiplicative ℝ => ∑ j, |(χ (axis c j 1)).toAdd|) (fun χ _ => Finset.sum_nonneg (fun j _ => abs_nonneg _)) hξ + rw [hbi] + dsimp [A] + linarith + · intro a b + apply Multiplicative.toAdd.injective + simp only [map_mul,map_inv,toAdd_mul,toAdd_inv] + change (ξ a).toAdd+(ξ b).toAdd+(-(ξ a).toAdd)+(-(ξ b).toAdd)=0 + ring + · intro j hj + exact BinomialDifference.coefficient_eq_zero ℝ j P (hP.trans_lt hj) + · exact character_binomial_expansion H s hs hf ξ P hPe + · intro j hj + have hNr : 1≤(N:ℝ) := by exact_mod_cast hN + have hbnd := BinomialDifference.coefficient_bound s 1 P hP (N:ℝ) C hNr hC.le + (fun i hi => hPc i hi) j hj + apply hbnd.trans + dsimp [A] + linarith + +end SquareInduction +end +end + + + +section + +namespace IntegerGridInterpolation +open scoped BigOperators +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section + +abbrev Grid (n d : ℕ) := Fin n → Fin (d + 1) + +def weight (d : ℕ) (j t : Fin (d + 1)) : ℚ := + (Lagrange.basis Finset.univ (fun t : Fin (d + 1) => (t.val : ℚ)) t).coeff j.val + +theorem one_dimensional (d : ℕ) (j k : Fin (d + 1)) : + ∑ t : Fin (d + 1), weight d j t * (t.val : ℚ) ^ k.val = + if j = k then 1 else 0 := by + classical + have hinj : Set.InjOn (fun t : Fin (d + 1) => (t.val : ℚ)) + (↑(Finset.univ : Finset (Fin (d + 1))) : Set (Fin (d + 1))) := by + intro a _ b _ hab + apply Fin.ext + exact_mod_cast (show (a.val : ℚ) = b.val from hab) + have hp : (X ^ k.val : ℚ[X]).degree < (Finset.univ : Finset (Fin (d + 1))).card := by + simp only [degree_X_pow, Finset.card_univ, Fintype.card_fin, Nat.cast_lt] + exact_mod_cast k.isLt + have h := congrArg (fun p : ℚ[X] => p.coeff j.val) + (Lagrange.eq_interpolate (v := fun t : Fin (d + 1) => (t.val : ℚ)) + hinj hp : (X ^ k.val : ℚ[X]) = _) + simp only [Lagrange.interpolate_apply, finsetSum_coeff, eval_pow, eval_X, + coeff_C_mul, coeff_X_pow] at h + simpa only [weight, mul_comm, Fin.ext_iff] using h.symm + +def tensorWeight (n d : ℕ) (e v : Grid n d) : ℚ := ∏ i, weight d (e i) (v i) + +theorem tensor_orthogonality (n d : ℕ) (e f : Grid n d) : + ∑ v : Grid n d, tensorWeight n d e v * (∏ i, ((v i).val : ℚ) ^ (f i).val) = + if e = f then 1 else 0 := by + classical + simp only [tensorWeight, ← Finset.prod_mul_distrib] + rw [← Fintype.prod_sum (fun i (t : Fin (d + 1)) => weight d (e i) t * (t.val : ℚ) ^ (f i).val)] + simp_rw [one_dimensional] + by_cases h : e = f + · subst f; simp + · rw [ite_eq_right h] + obtain ⟨i, hi⟩ := Function.ne_iff.mp h + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +theorem reconstruction (n d : ℕ) (a : Grid n d → ℚ) (e : Grid n d) : + ∑ v : Grid n d, tensorWeight n d e v * + (∑ f : Grid n d, a f * ∏ i, ((v i).val : ℚ) ^ (f i).val) = a e := by + classical + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + simp_rw [mul_left_comm (tensorWeight n d e _) (a _)] + simp_rw [← Finset.mul_sum] + change (∑ f : Grid n d, a f * (∑ v : Grid n d, tensorWeight n d e v * ∏ i, ((v i).val : ℚ) ^ (f i).val)) = a e + simp_rw [tensor_orthogonality] + simp + +theorem clear_denominators {ι : Type*} [Fintype ι] (f : ι → ℚ) : + ∃ (B : ℕ), 0 < B ∧ ∃ w : ι → ℤ, ∀ i, (B : ℚ) * f i = w i := by + classical + let B := ∏ i, (f i).den + have hB : 0 < B := Finset.prod_pos (fun i _ => (f i).den_pos) + refine ⟨B, hB, (fun i => (B / (f i).den : ℕ) * (f i).num), ?_⟩ + intro i + have hd : (f i).den ∣ B := Finset.dvd_prod_of_mem (fun i => (f i).den) (Finset.mem_univ i) + have he : (B : ℚ) = ((B / (f i).den : ℕ) : ℚ) * (f i).den := by + exact_mod_cast (Nat.div_mul_cancel hd).symm + have hq : ((f i).den : ℚ) * f i = (f i).num := by + rw [mul_comm] + exact (eq_div_iff (by exact_mod_cast (f i).den_ne_zero)).mp (f i).num_div_den.symm + rw [he, mul_assoc, hq] + push_cast + rfl + +theorem exists_integer_weights (n d : ℕ) : + ∃ B : ℕ, 0 < B ∧ ∃ w : Grid n d → Grid n d → ℤ, + ∀ e f : Grid n d, + ∑ v : Grid n d, (w e v : ℝ) * ∏ i, ((v i).val : ℝ) ^ (f i).val = + if e = f then (B : ℝ) else 0 := by + classical + obtain ⟨B, hB, w, hw⟩ := clear_denominators + (fun p : Grid n d × Grid n d => tensorWeight n d p.1 p.2) + refine ⟨B, hB, (fun e v => w (e, v)), ?_⟩ + intro e f + have hh : ∀ v, (w (e,v) : ℝ) = (B : ℝ) * (tensorWeight n d e v : ℝ) := by + intro v + exact_mod_cast (hw (e,v)).symm + simp_rw [hh, mul_assoc] + rw [← Finset.mul_sum] + have hid : (∑ v : Grid n d, (tensorWeight n d e v : ℝ) * + ∏ i, ((v i).val : ℝ) ^ (f i).val) = if e = f then 1 else 0 := by + have h := congrArg (fun q : ℚ => (q : ℝ)) (tensor_orthogonality n d e f) + push_cast at h + split_ifs at h ⊢ <;> simpa only [Rat.cast_one, Rat.cast_zero] using h + rw [hid] + split_ifs <;> simp + +theorem real_reconstruction {n d B : ℕ} (w : Grid n d → Grid n d → ℤ) + (hw : ∀ e f : Grid n d, + ∑ v : Grid n d, (w e v : ℝ) * ∏ i, ((v i).val : ℝ) ^ (f i).val = + if e = f then (B : ℝ) else 0) + (a : Grid n d → ℝ) (e : Grid n d) : + ∑ v : Grid n d, (w e v : ℝ) * + (∑ f : Grid n d, a f * ∏ i, ((v i).val : ℝ) ^ (f i).val) = B * a e := by + classical + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + simp_rw [mul_left_comm (w e _ : ℝ) (a _)] + simp_rw [← Finset.mul_sum, hw] + simp [mul_comm] + +end +end IntegerGridInterpolation + + +namespace PolynomialLineCoefficients +open scoped BigOperators +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section + +abbrev Grid (n d : ℕ) := Fin n → Fin (d + 1) +def totalDegree {n d : ℕ} (e : Grid n d) : ℕ := ∑ i, (e i).val + +def natLine {n d : ℕ} (e : Grid n d) (x v : Fin n → ℕ) : ℕ[X] := + ∏ i, (C (x i) + C (v i) * X) ^ (e i).val + +theorem linear_degree (x v : ℕ) : (C x + C v * X : ℕ[X]).natDegree ≤ 1 := by + apply natDegree_add_le_of_degree_le + · simp + · exact (natDegree_C_mul_le _ _).trans natDegree_X_le + +theorem prod_degree {ι : Type*} [DecidableEq ι] (s : Finset ι) + (f : ι → ℕ[X]) (d : ι → ℕ) (hd : ∀ i ∈ s, (f i).natDegree ≤ d i) : + (∏ i ∈ s, f i).natDegree ≤ ∑ i ∈ s, d i := + (natDegree_prod_le s f).trans (Finset.sum_le_sum hd) + +theorem prod_top_coeff {ι : Type*} [DecidableEq ι] (s : Finset ι) + (f : ι → ℕ[X]) (d : ι → ℕ) (hd : ∀ i ∈ s, (f i).natDegree ≤ d i) : + (∏ i ∈ s, f i).coeff (∑ i ∈ s, d i) = ∏ i ∈ s, (f i).coeff (d i) := by + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => + rw [Finset.prod_insert hi, Finset.sum_insert hi, Finset.prod_insert hi] + rw [coeff_mul_add_eq_of_natDegree_le (hd i (Finset.mem_insert_self _ _)) + (prod_degree s f d (fun j hj => hd j (Finset.mem_insert_of_mem hj)))] + rw [ih (fun j hj => hd j (Finset.mem_insert_of_mem hj))] + +theorem natLine_degree {n d : ℕ} (e : Grid n d) (x v : Fin n → ℕ) : + (natLine e x v).natDegree ≤ totalDegree e := by + apply prod_degree + intro i _ + simpa using natDegree_pow_le_of_le (e i).val (linear_degree (x i) (v i)) + +theorem natLine_coeff_zero {n d j : ℕ} (e : Grid n d) (x v : Fin n → ℕ) + (hj : totalDegree e < j) : (natLine e x v).coeff j = 0 := + coeff_eq_zero_of_natDegree_lt ((natLine_degree e x v).trans_lt hj) + +theorem natLine_top_coeff {n d : ℕ} (e : Grid n d) (x v : Fin n → ℕ) : + (natLine e x v).coeff (totalDegree e) = ∏ i, v i ^ (e i).val := by + rw [natLine, totalDegree, prod_top_coeff] + · apply Finset.prod_congr rfl + intro i _ + have hh := coeff_pow_of_natDegree_le (m := (e i).val) (linear_degree (x i) (v i)) + simpa using hh + · intro i _ + simpa using natDegree_pow_le_of_le (e i).val (linear_degree (x i) (v i)) + +theorem coeff_times_pow_le_eval (p : ℕ[X]) (j N : ℕ) : + p.coeff j * N ^ j ≤ p.eval N := by + classical + rw [eval_eq_sum, Polynomial.sum] + by_cases hj : j ∈ p.support + · exact Finset.single_le_sum (f := fun i => p.coeff i * N ^ i) (fun i _ => Nat.zero_le _) hj + · have hh : p.coeff j = 0 := notMem_support_iff.mp hj + simp [hh] + +theorem totalDegree_le {n d : ℕ} (e : Grid n d) : totalDegree e ≤ n * d := by + calc + _ ≤ ∑ _i : Fin n, d := Finset.sum_le_sum (fun i _ => Nat.le_of_lt_succ (e i).isLt) + _ = _ := by simp + +theorem natLine_eval_bound {n d N : ℕ} (e : Grid n d) (x v : Fin n → ℕ) + (hx : ∀ i, x i ≤ N) (hv : ∀ i, v i ≤ d) : + (natLine e x v).eval N ≤ ((d + 1) * N) ^ totalDegree e := by + simp only [natLine, eval_prod, eval_pow, eval_add, eval_C, eval_mul, eval_X] + rw [totalDegree, ← Finset.prod_pow_eq_pow_sum] + apply Finset.prod_le_prod₀ (fun i _ => Nat.zero_le _) + intro i _ + apply Nat.pow_le_pow_left + nlinarith [hx i, hv i] + +theorem natLine_coeff_bound {n d N j : ℕ} (hN : 0 < N) (e : Grid n d) + (x v : Fin n → ℕ) (hx : ∀ i, x i ≤ N) (hv : ∀ i, v i ≤ d) + (hj : j ≤ totalDegree e) : + ((natLine e x v).coeff j : ℝ) ≤ (d + 1 : ℝ) ^ (n * d) * (N : ℝ) ^ (totalDegree e - j) := by + have h := (coeff_times_pow_le_eval (natLine e x v) j N).trans (natLine_eval_bound e x v hx hv) + have h' : ((natLine e x v).coeff j : ℝ) * (N : ℝ) ^ j ≤ + ((d + 1 : ℝ) * N) ^ totalDegree e := by exact_mod_cast h + have hp : 0 < (N : ℝ) ^ j := pow_pos (Nat.cast_pos.mpr hN) _ + apply (mul_le_mul_iff_left₀ hp).mp + have he : (N : ℝ) ^ (totalDegree e - j) * N ^ j = N ^ totalDegree e := by + rw [← pow_add, Nat.sub_add_cancel hj] + calc + _ ≤ ((d + 1 : ℝ) * N) ^ totalDegree e := h' + _ ≤ (d + 1 : ℝ) ^ (n * d) * (N : ℝ) ^ totalDegree e := by + rw [mul_pow] + exact mul_le_mul_of_nonneg_right + (pow_le_pow_right₀ (by have := Nat.cast_nonneg (α := ℝ) d; linarith : (1 : ℝ) ≤ d + 1) (totalDegree_le e)) + (pow_nonneg (Nat.cast_nonneg N) _) + _ = _ := by rw [mul_assoc, he] + +def line {n d : ℕ} (a : Grid n d → ℝ) (x v : Fin n → ℕ) : ℝ[X] := + ∑ e : Grid n d, C (a e) * (natLine e x v).map (Nat.castRingHom ℝ) + +theorem line_coeff {n d : ℕ} (a : Grid n d → ℝ) (x v : Fin n → ℕ) (j : ℕ) : + (line a x v).coeff j = ∑ e : Grid n d, a e * ((natLine e x v).coeff j : ℝ) := by + simp [line, finsetSum_coeff] + +theorem line_eval {n d : ℕ} (a : Grid n d → ℝ) (x v : Fin n → ℕ) (t : ℕ) : + (line a x v).eval (t : ℝ) = + ∑ e : Grid n d, a e * ∏ i, ((x i + t * v i : ℕ) : ℝ) ^ (e i).val := by + simp only [line, eval_finsetSum, eval_mul, eval_C, eval_map, eval₂_at_natCast, + natLine, eval_prod, eval_pow, eval_add, eval_C, eval_mul, eval_X] + push_cast + simp only [mul_comm (v _ : ℝ) (t : ℝ)] + +theorem line_degree {n d : ℕ} (a : Grid n d → ℝ) (x v : Fin n → ℕ) : + (line a x v).natDegree ≤ n * d := by + apply natDegree_sum_le_of_forall_le + intro e _ + exact (natDegree_C_mul_le _ _).trans + (natDegree_map_le.trans ((natLine_degree e x v).trans (totalDegree_le e))) + +end +end PolynomialLineCoefficients + + + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialWeyl01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialWeyl01.lean new file mode 100644 index 0000000000000000000000000000000000000000..551334d8b2312b43296c53347713c6e0c2def716 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/PolynomialWeyl01.lean @@ -0,0 +1,618 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalFactor01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +end + + + +section +open scoped BigOperators +noncomputable section +namespace RationalFactorPeriods +open CubeFaces CubePolynomials +variable {G : Type*} [Group G] + +lemma orderedWord_mem {H : Filtration G} {k l : ℕ} (a : Fin l → G) (j : Fin l → ℕ) + (ha : ∀ i, a i ∈ H.level (j i+k)) : orderedWord a j ∈ polynomials H k := by + have hs : ((List.finRange l).map (fun i => (fun n : ℤ => a i ^ Ring.choose n (j i)))).prod + ∈ polynomials H k := by + apply Subgroup.list_prod_mem + intro f hf + obtain ⟨i,_,rfl⟩ := List.mem_map.mp hf + exact NilpotentTaylor.binomial_mem (j i) k (a i) (ha i) + convert hs using 1 + funext n + simp [orderedWord,Pi.list_prod_apply,List.map_map,Function.comp_def] + +lemma orderedWord_character (χ : G →* Multiplicative ℝ) {l : ℕ} + (a : Fin l → G) (j : Fin l → ℕ) (n : ℤ) : + (χ (orderedWord a j n)).toAdd = ∑ i, ((Ring.choose n (j i) : ℤ) : ℝ) * (χ (a i)).toAdd := by + rw [orderedWord_map] + simp only [orderedWord,toAdd_list_sum,List.map_map,Function.comp_def,toAdd_zpow,zsmul_eq_mul] + exact (Fin.sum_univ_def (fun i : Fin l => ((Ring.choose n (j i) : ℤ) : ℝ) * (χ (a i)).toAdd)).symm + +lemma List.prod_finRange_castSucc {d : ℕ} (f : Fin (d+1) → G) : + ((List.finRange (d+1)).map f).prod = + ((List.finRange d).map (fun i => f i.castSucc)).prod * f (Fin.last d) := by + rw [List.finRange_succ_last,List.map_append,List.prod_append] + simp [List.map_map,Function.comp_def] + +lemma word_eq_orderedWord (a : ℕ → G) (d : ℕ) : + NilpotentTaylor.word a d = orderedWord (fun i : Fin d => a i.val) (fun i => i.val) := by + induction d with + | zero => funext n; simp [NilpotentTaylor.word,orderedWord] + | succ d ih => + funext n + simp only [NilpotentTaylor.word,Pi.mul_apply,ih,orderedWord,List.prod_finRange_castSucc] + rfl + +end RationalFactorPeriods +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace NilpotentTaylor +open CubeFaces CubePolynomials RationalFactorPeriods +variable {G : Type*} [Group G] + +lemma word_zero (a : ℕ → G) (d : ℕ) : word a (d+1) 0 = a 0 := by + induction d with + | zero => simp [word] + | succ d ih => simpa [word,Ring.choose_zero_succ] using ih + +lemma choose_one_high {d : ℕ} (hd : 2 ≤ d) : Ring.choose (1:ℤ) d = 0 := by + rw [← Int.natCast_one,Ring.choose_natCast,Nat.choose_eq_zero_of_lt (by omega : 1 < d),Nat.cast_zero] + +lemma word_one (a : ℕ → G) (d : ℕ) : word a (d+2) 1 = a 0 * a 1 := by + induction d with + | zero => simp [word] + | succ d ih => + change word a (d+2) 1 * a (d+2) ^ Ring.choose (1:ℤ) (d+2) = _ + rw [choose_one_high (by omega),zpow_zero,mul_one,ih] + +lemma word_tail_two (a : ℕ → G) (d : ℕ) (h0 : a 0=1) (h1 : a 1=1) : + word a (d+2) = orderedWord (fun i : Fin d => a (i.val+2)) (fun i => i.val+2) := by + induction d with + | zero => funext n; simp [word,orderedWord,h0,h1] + | succ d ih => + funext n + change word a (d+2) n * a (d+2) ^ Ring.choose n (d+2) = _ + rw [ih] + simp only [orderedWord,RationalFactorPeriods.List.prod_finRange_castSucc] + rfl + + + +theorem normalized_taylor (H : Filtration G) (s : ℕ) (hbot : H.level s = ⊥) + (g : ℤ → G) (hg : g ∈ polynomials H 0) (h0 : g 0=1) (h1 : g 1=1) : + ∃ a : Fin s → G, (∀ i, a i ∈ H.level (i.val+2)) ∧ + g = orderedWord a (fun i => i.val+2) := by + have hb : H.level ((s+2)+0) = ⊥ := by + apply le_bot_iff.mp + simpa [hbot] using H.antitone (show s ≤ (s+2)+0 by omega) + obtain ⟨a,ha,he⟩ := exists_taylor hb hg + have ha0 : a 0=1 := by + have hx := congrFun he 0 + rw [h0,show s+2=(s+1)+1 by omega,word_zero] at hx + exact hx.symm + have ha1 : a 1=1 := by + have hx := congrFun he 1 + rw [h1,word_one,ha0,one_mul] at hx + exact hx.symm + refine ⟨fun i => a (i.val+2),fun i => ?_,?_⟩ + · simpa using ha (i.val+2) (by omega) + · exact he.trans (word_tail_two a s ha0 ha1) + + + +theorem normalized_subgroup_taylor (H : Filtration G) (s : ℕ) (hbot : H.level s = ⊥) + (g : ℤ → G) (hg : g ∈ polynomials H 0) (h0 : g 0=1) + (h1 : g 1 ∈ H.level 1) : + ∃ a : Fin s → H.level 2, + (∀ i, (a i).val ∈ H.level (i.val+2)) ∧ + ∀ z, g z = (orderedWord a (fun i => i.val+2) z).val * g 1 ^ z := by + let lin : ℤ → G := fun z => g 1 ^ z + have hlin : lin ∈ polynomials H 0 := by + simpa [lin] using binomial_mem (H:=H) 1 0 (g 1) h1 + let f : ℤ → G := g * lin⁻¹ + have hf : f ∈ polynomials H 0 := (polynomials H 0).mul_mem hg ((polynomials H 0).inv_mem hlin) + have hf0 : f 0=1 := by simp [f,lin,h0] + have hf1 : f 1=1 := by simp [f,lin] + obtain ⟨a,ha,he⟩ := normalized_taylor H s hbot f hf hf0 hf1 + let a' : Fin s → H.level 2 := fun i => ⟨a i,H.antitone (by omega : 2 ≤ i.val+2) (ha i)⟩ + refine ⟨a',ha,fun z => ?_⟩ + have hz := congrFun he z + change g z * (g 1 ^ z)⁻¹ = orderedWord a (fun i => i.val+2) z at hz + have hm := orderedWord_map (H.level 2).subtype a' (fun i => i.val+2) z + change ((orderedWord a' (fun i => i.val+2) z : H.level 2):G) = orderedWord a _ z at hm + rw [hm,←hz] + group + +end NilpotentTaylor +end +end + + + +section + + + +namespace PolynomialWeyl +open scoped BigOperators ComplexConjugate +noncomputable section + + +def mean (N : ℕ) (f : ℕ → ℂ) : ℂ := 𝔼 x ∈ Finset.range N, f x + +def derivative (a b : ℕ) (f : ℕ → ℂ) (x : ℕ) : ℂ := + f (x + a) * conj (f (x + b)) + +theorem norm_mean_le_one {N : ℕ} (f : ℕ → ℂ) (hf : ∀ x, ‖f x‖ ≤ 1) : + ‖mean N f‖ ≤ 1 := by + by_cases hN : N = 0 + · simp [mean, hN] + · exact (RCLike.norm_expect_le (K := ℂ)).trans + (Finset.expect_le (Finset.nonempty_range_iff.mpr hN) + (fun x _ => hf x)) + +theorem norm_derivative_le_one (a b : ℕ) (f : ℕ → ℂ) (hf : ∀ x, ‖f x‖ ≤ 1) : + ∀ x, ‖derivative a b f x‖ ≤ 1 := by + intro x + simp only [derivative, norm_mul, RCLike.norm_conj] + calc + _ ≤ 1 * 1 := mul_le_mul (hf (x + a)) (hf (x + b)) (norm_nonneg _) (by norm_num) + _ = 1 := by norm_num + + +theorem norm_mean_shift_sub_le {N : ℕ} (hN : 0 < N) (h : ℕ) (f : ℕ → ℂ) + (hf : ∀ x, ‖f x‖ ≤ 1) : + ‖mean N (fun x => f (x + h)) - mean N f‖ ≤ 2 * (h : ℝ) / N := by + have hs : (∑ x ∈ Finset.range N, f (x + h)) - (∑ x ∈ Finset.range N, f x) = + (∑ x ∈ Finset.range h, f (x + N)) - (∑ x ∈ Finset.range h, f x) := by + have h₁ := Finset.sum_range_add f N h + have h₂ := Finset.sum_range_add f h N + rw [Nat.add_comm h N] at h₂ + have e₁ : (∑ x ∈ Finset.range h, f (N + x)) = ∑ x ∈ Finset.range h, f (x + N) := by + apply Finset.sum_congr rfl + intro x _ + rw [Nat.add_comm N x] + have e₂ : (∑ x ∈ Finset.range N, f (h + x)) = ∑ x ∈ Finset.range N, f (x + h) := by + apply Finset.sum_congr rfl + intro x _ + rw [Nat.add_comm h x] + rw [e₁] at h₁ + rw [e₂] at h₂ + linear_combination h₁ - h₂ + have hb (k : ℕ) : ‖∑ x ∈ Finset.range h, f (x + k)‖ ≤ (h : ℝ) := by + calc + _ ≤ ∑ x ∈ Finset.range h, ‖f (x + k)‖ := norm_sum_le _ _ + _ ≤ ∑ x ∈ Finset.range h, (1 : ℝ) := Finset.sum_le_sum (fun x _ => hf (x + k)) + _ = _ := by simp + have hb₀ : ‖∑ x ∈ Finset.range h, f x‖ ≤ (h : ℝ) := by simpa using hb 0 + rw [mean, mean, Finset.expect_eq_sum_div_card, Finset.expect_eq_sum_div_card] + simp only [Finset.card_range, ← sub_div, hs, norm_div, Complex.norm_natCast] + apply div_le_div_of_nonneg_right _ (Nat.cast_pos.mpr hN).le + calc + _ ≤ ‖∑ x ∈ Finset.range h, f (x + N)‖ + ‖∑ x ∈ Finset.range h, f x‖ := norm_sub_le _ _ + _ ≤ 2 * (h : ℝ) := by linarith [hb N] + + +theorem norm_expect_sq_le {ι : Type*} (s : Finset ι) (f : ι → ℂ) : + ‖𝔼 i ∈ s, f i‖ ^ 2 ≤ 𝔼 i ∈ s, ‖f i‖ ^ 2 := by + classical + by_cases hs : s.Nonempty + · have h₁ := RCLike.norm_expect_le (K := ℂ) (s := s) (f := f) + have h₂ := Finset.expect_mul_sq_le_sq_mul_sq s (fun i => ‖f i‖) (fun _ => (1 : ℝ)) + simp only [mul_one, one_pow, Finset.expect_const hs] at h₂ + nlinarith [norm_nonneg (𝔼 i ∈ s, f i)] + · simp [Finset.not_nonempty_iff_eq_empty.mp hs] + + +theorem shift_average_error {N H : ℕ} (hN : 0 < N) (hH : 0 < H) + (f : ℕ → ℂ) (hf : ∀ x, ‖f x‖ ≤ 1) : + ‖(𝔼 x ∈ Finset.range N, 𝔼 h ∈ Finset.range H, f (x + h)) - mean N f‖ ≤ + 2 * (H : ℝ) / N := by + rw [Finset.expect_comm] + conv_lhs => rhs; rw [← Finset.expect_const (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hH)) (mean N f)] + rw [← Finset.expect_sub_distrib] + apply (RCLike.norm_expect_le (K := ℂ)).trans + apply Finset.expect_le (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hH)) + intro h hh + apply (norm_mean_shift_sub_le hN h f hf).trans + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg N) + have : (h : ℝ) ≤ H := by exact_mod_cast (Finset.mem_range.mp hh).le + linarith + + +theorem norm_expect_sq_eq {ι : Type*} (s : Finset ι) (f : ι → ℂ) : + ‖𝔼 i ∈ s, f i‖ ^ 2 = (𝔼 a ∈ s, 𝔼 b ∈ s, f a * conj (f b)).re := by + simp_rw [← Finset.mul_expect, ← map_expect (starRingEnd ℂ)] + rw [← Finset.expect_mul, Complex.mul_conj] + rw [Complex.ofReal_re, Complex.normSq_eq_norm_sq] + + + +theorem van_der_corput {N H : ℕ} (hN : 0 < N) (hH : 0 < H) + (f : ℕ → ℂ) (hf : ∀ x, ‖f x‖ ≤ 1) : + ‖mean N f‖ ^ 2 ≤ + (𝔼 a ∈ Finset.range H, 𝔼 b ∈ Finset.range H, ‖mean N (derivative a b f)‖) + + 4 * (H : ℝ) / N := by + let z := 𝔼 x ∈ Finset.range N, 𝔼 h ∈ Finset.range H, f (x + h) + have hz : ‖z‖ ≤ 1 := by + apply (RCLike.norm_expect_le (K := ℂ)).trans + apply Finset.expect_le (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)) + intro x _ + apply (RCLike.norm_expect_le (K := ℂ)).trans + exact Finset.expect_le (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hH)) (fun h _ => hf (x + h)) + have hm := norm_mean_le_one f hf (N := N) + have he := shift_average_error hN hH f hf + have ht : ‖mean N f‖ - ‖z‖ ≤ 2 * (H : ℝ) / N := by + have ht := norm_sub_norm_le (mean N f) z + rw [norm_sub_rev] at ht + exact ht.trans he + have hs : ‖mean N f‖ ^ 2 ≤ ‖z‖ ^ 2 + 4 * (H : ℝ) / N := by + have he₀ : 0 ≤ 2 * (H : ℝ) / N := by positivity + have he₁ := mul_le_mul_of_nonneg_right ht (show 0 ≤ ‖mean N f‖ + ‖z‖ by positivity) + have he₂ := mul_le_mul_of_nonneg_left (show ‖mean N f‖ + ‖z‖ ≤ 2 by linarith) he₀ + have hr : 2 * (H : ℝ) / N * 2 = 4 * H / N := by ring + rw [hr] at he₂ + nlinarith + apply hs.trans + apply add_le_add _ le_rfl + calc + ‖z‖ ^ 2 ≤ 𝔼 x ∈ Finset.range N, ‖𝔼 h ∈ Finset.range H, f (x + h)‖ ^ 2 := + norm_expect_sq_le _ _ + _ = (𝔼 a ∈ Finset.range H, 𝔼 b ∈ Finset.range H, + mean N (derivative a b f)).re := by + simp only [norm_expect_sq_eq, ← Complex.re_expect] + congr 1 + rw [Finset.expect_comm] + apply Finset.expect_congr rfl + intro a _ + rw [Finset.expect_comm] + rfl + _ ≤ _ := by + rw [Complex.re_expect] + apply Finset.expect_le_expect + intro a _ + rw [Complex.re_expect] + exact Finset.expect_le_expect (fun b _ => Complex.re_le_norm _) + + +theorem pow_le_pow_add_error {x y e : ℝ} (hx₀ : 0 ≤ x) (hx₁ : x ≤ 1) + (hy₀ : 0 ≤ y) (hy₁ : y ≤ 1) (he : 0 ≤ e) (hxy : x ≤ y + e) (n : ℕ) : + x ^ n ≤ y ^ n + n * e := by + induction n with + | zero => simp + | succ n ih => + have hy := pow_le_one₀ hy₀ hy₁ (n := n) + have hp := pow_nonneg hy₀ n + have hn : 0 ≤ (n : ℝ) * e := mul_nonneg (Nat.cast_nonneg _) he + have h₁ := mul_le_mul_of_nonneg_right ih hx₀ + have h₂ := mul_le_mul_of_nonneg_left hxy hp + have h₃ := mul_le_mul_of_nonneg_right hy he + have h₄ := mul_le_mul_of_nonneg_left hx₁ hn + rw [pow_succ, pow_succ, Nat.cast_add, Nat.cast_one] + nlinarith + + +theorem expect_pow_two_pow_le {ι : Type*} (s : Finset ι) (hs : s.Nonempty) + (f : ι → ℝ) (k : ℕ) : + (𝔼 i ∈ s, f i) ^ (2 ^ k) ≤ 𝔼 i ∈ s, (f i) ^ (2 ^ k) := by + induction k generalizing f with + | zero => simp + | succ k ih => + have hcs := Finset.expect_mul_sq_le_sq_mul_sq s f (fun _ => (1 : ℝ)) + simp only [mul_one, one_pow, Finset.expect_const hs] at hcs + calc + _ = ((𝔼 i ∈ s, f i) ^ 2) ^ (2 ^ k) := by rw [← pow_mul]; congr 1; omega + _ ≤ (𝔼 i ∈ s, (f i) ^ 2) ^ (2 ^ k) := pow_le_pow_left₀ (sq_nonneg _) hcs _ + _ ≤ 𝔼 i ∈ s, ((f i) ^ 2) ^ (2 ^ k) := ih _ + _ = _ := by + apply Finset.expect_congr rfl + intro i _ + rw [← pow_mul] + congr 1 + omega + + + +def differencedMean (N H : ℕ) : ℕ → (ℕ → ℂ) → ℝ + | 0, f => ‖mean N f‖ + | k + 1, f => 𝔼 a ∈ Finset.range H, 𝔼 b ∈ Finset.range H, + differencedMean N H k (derivative a b f) + +theorem differencedMean_nonneg (N H k : ℕ) (f : ℕ → ℂ) : + 0 ≤ differencedMean N H k f := by + induction k generalizing f with + | zero => exact norm_nonneg _ + | succ k ih => + exact Finset.expect_nonneg (fun a _ => Finset.expect_nonneg (fun b _ => ih _)) + +theorem differencedMean_le_one (N H k : ℕ) (f : ℕ → ℂ) (hf : ∀ x, ‖f x‖ ≤ 1) : + differencedMean N H k f ≤ 1 := by + induction k generalizing f with + | zero => exact norm_mean_le_one f hf + | succ k ih => + by_cases hH : H = 0 + · simp [differencedMean, hH] + · exact Finset.expect_le (Finset.nonempty_range_iff.mpr hH) (fun a _ => + Finset.expect_le (Finset.nonempty_range_iff.mpr hH) (fun b _ => + ih _ (norm_derivative_le_one a b f hf))) + + + +theorem iterated_van_der_corput {N H : ℕ} (hN : 0 < N) (hH : 0 < H) + (k : ℕ) (f : ℕ → ℂ) (hf : ∀ x, ‖f x‖ ≤ 1) : + ‖mean N f‖ ^ (2 ^ k) ≤ + differencedMean N H k f + ((2 : ℝ) ^ k - 1) * (4 * H / N) := by + induction k generalizing f with + | zero => simp [differencedMean] + | succ k ih => + let u (a b : ℕ) := ‖mean N (derivative a b f)‖ + let v := 𝔼 a ∈ Finset.range H, 𝔼 b ∈ Finset.range H, u a b + have hs := Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hH) + have hv₀ : 0 ≤ v := Finset.expect_nonneg (fun a _ => + Finset.expect_nonneg (fun b _ => norm_nonneg _)) + have hv₁ : v ≤ 1 := Finset.expect_le hs (fun a _ => Finset.expect_le hs + (fun b _ => norm_mean_le_one _ (norm_derivative_le_one a b f hf))) + have hf₁ := norm_mean_le_one f hf (N := N) + have hf₀ := norm_nonneg (mean N f) + have hn : (‖mean N f‖ ^ 2) ≤ 1 := by nlinarith + have he : 0 ≤ 4 * (H : ℝ) / N := by positivity + have hpow := pow_le_pow_add_error (sq_nonneg _) hn hv₀ hv₁ he + (van_der_corput hN hH f hf) (2 ^ k) + calc + _ = (‖mean N f‖ ^ 2) ^ (2 ^ k) := by rw [← pow_mul]; congr 1; omega + _ ≤ v ^ (2 ^ k) + (2 ^ k : ℕ) * (4 * (H : ℝ) / N) := hpow + _ ≤ (𝔼 a ∈ Finset.range H, 𝔼 b ∈ Finset.range H, (u a b) ^ (2 ^ k)) + + (2 ^ k : ℕ) * (4 * (H : ℝ) / N) := by + apply add_le_add _ le_rfl + exact (expect_pow_two_pow_le _ hs _ k).trans + (Finset.expect_le_expect (fun a _ => expect_pow_two_pow_le _ hs _ k)) + _ ≤ (𝔼 a ∈ Finset.range H, 𝔼 b ∈ Finset.range H, + (differencedMean N H k (derivative a b f) + + ((2 : ℝ) ^ k - 1) * (4 * H / N))) + + (2 ^ k : ℕ) * (4 * (H : ℝ) / N) := by + apply add_le_add _ le_rfl + exact Finset.expect_le_expect (fun a _ => Finset.expect_le_expect (fun b _ => + ih _ (norm_derivative_le_one a b f hf))) + _ = _ := by + simp only [Finset.expect_add_distrib, Finset.expect_const hs, + differencedMean, Nat.cast_pow, Nat.cast_ofNat, pow_succ] + ring + + +def phase (t : ℝ) : ℂ := Complex.exp ((2 * Real.pi * t : ℝ) * Complex.I) + +@[simp] theorem norm_phase (t : ℝ) : ‖phase t‖ = 1 := + Complex.norm_exp_ofReal_mul_I _ + +@[simp] theorem phase_add (x y : ℝ) : phase (x + y) = phase x * phase y := by + simp only [phase, mul_add, Complex.ofReal_add, Complex.exp_add, add_mul] + +@[simp] theorem phase_neg (x : ℝ) : phase (-x) = conj (phase x) := by + rw [phase, phase, ← Complex.exp_conj] + congr 1 + simp only [map_mul, Complex.conj_ofReal, Complex.conj_I, mul_neg, Complex.ofReal_neg] + ring + +@[simp] theorem phase_sub (x y : ℝ) : phase (x - y) = phase x * conj (phase y) := by + rw [sub_eq_add_neg, phase_add, phase_neg] + +@[simp] theorem phase_nat_mul (x : ℝ) (n : ℕ) : phase ((n : ℝ) * x) = (phase x) ^ n := by + rw [phase, phase, ← Complex.exp_nat_mul] + congr 1 + push_cast + ring + + +def polynomialPhase (p : Polynomial ℝ) (x : ℕ) : ℂ := phase (p.eval (x : ℝ)) + + +def polynomialDifference (a b : ℕ) (p : Polynomial ℝ) : Polynomial ℝ := + Polynomial.taylor (a : ℝ) p - Polynomial.taylor (b : ℝ) p + +@[simp] theorem polynomialPhase_difference (a b : ℕ) (p : Polynomial ℝ) : + polynomialPhase (polynomialDifference a b p) = derivative a b (polynomialPhase p) := by + funext x + simp [polynomialPhase, polynomialDifference, derivative, Polynomial.taylor_eval, + Nat.cast_add] + + +theorem taylor_coeff_top (p : Polynomial ℝ) (d : ℕ) (hp : p.natDegree ≤ d) (a : ℝ) : + (Polynomial.taylor a p).coeff d = p.coeff d := by + by_cases hd : p.natDegree = d + · subst d + exact Polynomial.coeff_taylor_natDegree a p + · have hl : p.natDegree < d := lt_of_le_of_ne hp hd + rw [Polynomial.coeff_eq_zero_of_natDegree_lt hl, + Polynomial.coeff_eq_zero_of_natDegree_lt] + rwa [Polynomial.natDegree_taylor] + + + +theorem polynomialDifference_degree (a b : ℕ) (p : Polynomial ℝ) (d : ℕ) + (hp : p.natDegree ≤ d + 1) : + (polynomialDifference a b p).natDegree ≤ d := by + rw [Polynomial.natDegree_le_iff_coeff_eq_zero] + intro n hn + simp only [polynomialDifference, Polynomial.coeff_sub] + by_cases he : n = d + 1 + · subst n + rw [taylor_coeff_top p _ hp, taylor_coeff_top p _ hp, sub_self] + · have hlt : p.natDegree < n := by omega + have h₁ : (Polynomial.taylor (a : ℝ) p).natDegree < n := by + rwa [Polynomial.natDegree_taylor] + have h₂ : (Polynomial.taylor (b : ℝ) p).natDegree < n := by + rwa [Polynomial.natDegree_taylor] + rw [Polynomial.coeff_eq_zero_of_natDegree_lt h₁, + Polynomial.coeff_eq_zero_of_natDegree_lt h₂, sub_self] + + +theorem taylor_coeff_below_top (p : Polynomial ℝ) (d : ℕ) (hp : p.natDegree ≤ d + 1) (a : ℝ) : + (Polynomial.taylor a p).coeff d = p.coeff d + (d + 1 : ℕ) * p.coeff (d + 1) * a := by + rw [Polynomial.taylor_coeff] + have hdeg : ((Polynomial.hasseDeriv d) p).natDegree < 2 := by + have h := Polynomial.natDegree_hasseDeriv_le p d + omega + rw [Polynomial.eval_eq_sum_range' hdeg] + simp only [Finset.sum_range_succ, Finset.sum_range_zero, zero_add, + Polynomial.hasseDeriv_coeff, Nat.choose_self, Nat.cast_one, + one_mul, pow_zero, mul_one, pow_one] + rw [Nat.add_comm 1 d, Nat.choose_succ_self_right] + + +theorem polynomialDifference_coeff (a b : ℕ) (p : Polynomial ℝ) (d : ℕ) + (hp : p.natDegree ≤ d + 1) : + (polynomialDifference a b p).coeff d = + (d + 1 : ℕ) * p.coeff (d + 1) * ((a : ℝ) - b) := by + simp only [polynomialDifference, Polynomial.coeff_sub, taylor_coeff_below_top p d hp] + ring + + +def linearBound (N : ℕ) (α : ℝ) : ℝ := + if phase α = 1 then 1 else min 1 (2 / ((N : ℝ) * ‖phase α - 1‖)) + +theorem norm_linear_mean_le {N : ℕ} (hN : 0 < N) (α β : ℝ) : + ‖mean N (fun x => phase (α * x + β))‖ ≤ linearBound N α := by + have hunit : ∀ x : ℕ, ‖phase (α * x + β)‖ ≤ 1 := by simp + have h₁ := norm_mean_le_one _ hunit (N := N) + unfold linearBound + split_ifs with hα + · exact h₁ + · apply le_min h₁ + have heq : mean N (fun x => phase (α * x + β)) = + phase β * (∑ x ∈ Finset.range N, (phase α) ^ x) / (N : ℂ) := by + simp only [mean, Finset.expect_eq_sum_div_card, Finset.card_range] + congr 1 + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + rw [phase_add, mul_comm α, phase_nat_mul, mul_comm] + rw [heq, norm_div, norm_mul, norm_phase, one_mul, Complex.norm_natCast, + geom_sum_eq hα, norm_div] + have hb : ‖(phase α) ^ N - 1‖ ≤ 2 := by + calc + _ ≤ ‖(phase α) ^ N‖ + ‖(1 : ℂ)‖ := norm_sub_le _ _ + _ = 2 := by simp only [norm_pow, norm_phase, one_pow, norm_one]; norm_num + calc + _ ≤ (2 / ‖phase α - 1‖) / N := + div_le_div_of_nonneg_right (div_le_div_of_nonneg_right hb (norm_nonneg _)) + (Nat.cast_pos.mpr hN).le + _ = _ := by ring + + + +def weylBound (N H : ℕ) : ℕ → ℝ → ℝ + | 0, α => linearBound N α + | d + 1, α => 𝔼 a ∈ Finset.range H, 𝔼 b ∈ Finset.range H, + weylBound N H d ((d + 2 : ℕ) * α * ((a : ℝ) - b)) + +theorem differencedMean_polynomial_le {N : ℕ} (hN : 0 < N) (H d : ℕ) + (p : Polynomial ℝ) (hp : p.natDegree ≤ d + 1) : + differencedMean N H d (polynomialPhase p) ≤ weylBound N H d (p.coeff (d + 1)) := by + induction d generalizing p with + | zero => + have he (x : ℕ) : p.eval (x : ℝ) = p.coeff 1 * x + p.coeff 0 := by + rw [Polynomial.eval_eq_sum_range' (show p.natDegree < 2 by omega)] + simp only [Finset.sum_range_succ, Finset.sum_range_zero, zero_add, + pow_zero, mul_one, pow_one] + ring + change ‖mean N (fun x => phase (p.eval (x : ℝ)))‖ ≤ linearBound N (p.coeff 1) + simp_rw [he] + exact norm_linear_mean_le hN (p.coeff 1) (p.coeff 0) + | succ d ih => + apply Finset.expect_le_expect + intro a _ + apply Finset.expect_le_expect + intro b _ + have h := ih (polynomialDifference a b p) (polynomialDifference_degree a b p (d + 1) hp) + rwa [polynomialPhase_difference, polynomialDifference_coeff a b p (d + 1) hp] at h + + + +theorem polynomial_weyl_inequality {N H : ℕ} (hN : 0 < N) (hH : 0 < H) + (d : ℕ) (p : Polynomial ℝ) (hp : p.natDegree ≤ d + 1) : + ‖mean N (polynomialPhase p)‖ ^ (2 ^ d) ≤ + weylBound N H d (p.coeff (d + 1)) + ((2 : ℝ) ^ d - 1) * (4 * H / N) := by + apply (iterated_van_der_corput hN hH d (polynomialPhase p) (fun x => by simp [polynomialPhase])).trans + exact add_le_add (differencedMean_polynomial_le hN H d p hp) le_rfl + +@[simp] theorem phase_int (m : ℤ) : phase (m : ℝ) = 1 := by + unfold phase + convert Complex.exp_int_mul_two_pi_mul_I m using 1 + congr 1 + push_cast + ring + + + +theorem exists_int_close_of_phase (α : ℝ) : + ∃ m : ℤ, |α - m| ≤ ‖phase α - 1‖ / 4 := by + let m : ℤ := ⌊α + 1 / 2⌋ + let t : ℝ := α - m + have ht : |t| ≤ 1 / 2 := by + apply abs_le.mpr + have h₁ := Int.floor_le (α + 1 / 2) + have h₂ := Int.lt_floor_add_one (α + 1 / 2) + dsimp [t, m] + constructor <;> linarith + have he : phase t = phase α := by simp [t] + have hnorm : ‖phase t - 1‖ = 2 * |Real.sin (Real.pi * t)| := by + unfold phase + rw [mul_comm _ Complex.I, Complex.norm_exp_I_mul_ofReal_sub_one] + have harg : 2 * Real.pi * t / 2 = Real.pi * t := by ring + rw [harg, Real.norm_eq_abs, abs_mul, abs_of_pos (by norm_num : (0 : ℝ) < 2)] + have hbound : |Real.pi * t| ≤ Real.pi / 2 := by + rw [abs_mul, abs_of_pos Real.pi_pos] + nlinarith [Real.pi_pos] + have hs := Real.mul_abs_le_abs_sin hbound + rw [abs_mul, abs_of_pos Real.pi_pos] at hs + have hsim : 2 / Real.pi * (Real.pi * |t|) = 2 * |t| := by field_simp + rw [hsim] at hs + refine ⟨m, ?_⟩ + change |t| ≤ _ + rw [← he, hnorm] + linarith + +theorem linear_inverse {N : ℕ} (hN : 0 < N) (α β δ : ℝ) + (hδ : 0 < δ) (hlarge : δ ≤ ‖mean N (fun x => phase (α * x + β))‖) : + ∃ m : ℤ, |α - m| ≤ 1 / (δ * N) := by + obtain ⟨m, hm⟩ := exists_int_close_of_phase α + refine ⟨m, hm.trans ?_⟩ + have hNp : 0 < (N : ℝ) := Nat.cast_pos.mpr hN + by_cases hα : phase α = 1 + · simp only [hα, sub_self, norm_zero, zero_div] + positivity + · have hnorm : 0 < ‖phase α - 1‖ := norm_pos_iff.mpr (sub_ne_zero.mpr hα) + have hl := norm_linear_mean_le hN α β + simp only [linearBound, ite_eq_right hα] at hl + have hd : δ ≤ 2 / ((N : ℝ) * ‖phase α - 1‖) := hlarge.trans (hl.trans (min_le_right _ _)) + have hd' := (le_div_iff₀ (mul_pos hNp hnorm)).mp hd + apply (le_div_iff₀ (mul_pos hδ hNp)).mpr + nlinarith + +end +end PolynomialWeyl + + + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure01.lean new file mode 100644 index 0000000000000000000000000000000000000000..672e5d7cda5aaf4fdb4c4ba983e2f0b95337b98a --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure01.lean @@ -0,0 +1,275 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MicrocellSaturation01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section RawSuccessInlineScope16 +noncomputable section +open scoped BigOperators +open Finset MeasureTheory +end +end RawSuccessInlineScope16 + + + + + +section RawSuccessInlineScope17 +noncomputable section +open Filter Topology +namespace MicrocellEarlierScale +open MicrocellScale AdmissibleMicrocellBoundary + + + +theorem radius_dominates_square {M P H:ℕ→ℕ} + (hM:∀ᶠ n in atTop,0(H n:ℝ)) (earlierScale M P)) : + Dominates (fun n=>(radius (M n) (H n):ℝ)) (fun n=>(M n:ℝ)+(P n:ℝ)^2) := by + have hm:∀ᶠ n in atTop,0((radius (M n) (H n):ℝ)/(earlierScale M P n)^(2*C))/2^C) atTop atTop := + (hr (2*C) (by positivity)).atTop_div_const (Real.rpow_pos_of_pos (by norm_num) C) + apply tendsto_atTop_mono' atTop _ hh + filter_upwards [hM] with n hn + let S:=earlierScale M P n + let T:ℝ:=(M n:ℝ)+(P n:ℝ)^2 + have hS:1≤S:=scale_one M P n + have hs:0(H n:ℝ)) (earlierScale M P)) : + Tendsto (fun n=>length (M n) (H n)) atTop atTop := by + have hm:∀ᶠ n in atTop,0(radius (M n) (H n):ℝ)/earlierScale M P n) atTop atTop := by + simpa only [Real.rpow_one] using hr + apply (tendsto_natCast_atTop_iff (R:=ℝ)).mp + apply tendsto_atTop_mono' atTop _ hr' + filter_upwards [hm] with n hn + rw [length_cast] + apply div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast hn.1) hn.2 + +end MicrocellEarlierScale +end +end RawSuccessInlineScope17 + + + + + +section RawSuccessInlineScope18 +noncomputable section +open scoped BigOperators +open Finset MeasureTheory Filter Topology +namespace AdmissibleRawSuccess +open MicrocellScale AdmissibleMicrocellBoundary MicrocellSaturation RawHarmonicProbability +attribute [local instance] Classical.propDecidable + + + +theorem eventually_global {J : Type*} [Fintype J] + {M P H X W : ℕ→ℕ} (c : ℝ) (hc : 0(H n:ℝ)) (earlierScale M P)) + (hx : Dominates (fun n=>Real.log (X n:ℝ)) (fun n=>(H n:ℝ))) : + ∀ᶠ n in atTop,∃ (hw : 0 + MicrocellFibers.point (M n) (length (M n) (H n)*i.1) i.2 b):Measure ℕ).real A) → + c/4 ≤ (law (X n) (W n) hw hX : Measure ℕ).real A := by + have hbase' : ∀ᶠ n in atTop,0hn.2.1) + have hH := hbase.mono (fun _ hn=>hn.2.2.2.1) + obtain ⟨ε,hε,hbd⟩ := uniform_raw_boundary 2 (by decide) hbase' hd hx + have hfour := radius_four_modulus (P:=P) + (hbase'.mono (fun _ hn=>⟨hn.2.1,hn.2.2.1⟩)) hd + have hR := endpoint_rate hM hH (by simpa only [Real.rpow_one] using hx 1 (by norm_num)) + have hL := MicrocellEarlierScale.length_tendsto hM hd + have herror : Tendsto (fun n=>24*((radius (M n) (H n):ℝ)/X n)+ + (Fintype.card J:ℝ)*ε n) atTop (𝓝 0) := by + simpa using (hR.const_mul 24).add (hε.const_mul (Fintype.card J:ℝ)) + filter_upwards [hbase,hfour,hbd,hL.eventually_ge_atTop 1, + hR.eventually_lt_const (show (0:ℝ)<1 by norm_num), + hR.eventually_le_const (show (0:ℝ)hbd (t j) (ht j).1 (ht j).2)) + (by simpa only [hlen] using hs) + rw [hlen] at hp + have hWR : (W n:ℝ)≤radius (M n) (H n) := by + exact_mod_cast (show W n≤radius (M n) (H n) by omega) + have hcost : (8*(radius (M n) (H n):ℝ)+16*W n)/X n ≤ + 24*((radius (M n) (H n):ℝ)/X n) := by + rw [←mul_div_assoc] + apply div_le_div_of_nonneg_right _ hxp.le + linarith + have hlo : (3/4:ℝ)≤1-(8*(radius (M n) (H n):ℝ)+16*W n)/X n- + (Fintype.card J:ℝ)*ε n := by linarith + have hh := mul_le_mul_of_nonneg_left hlo (show 0≤c/3 by positivity) + linarith + +end AdmissibleRawSuccess +end +end RawSuccessInlineScope18 + + +end + +section +noncomputable section +namespace ProductExposureLaw +open MeasureTheory Filter Topology +open scoped BigOperators +open HarmonicExposure RawHarmonicProbability DyadicHarmonicBoundary +attribute [local instance] Classical.propDecidable + +def jointLaw {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) (hW : 0(law (X j) W hW (hX j):Measure ℕ))).prod + (law Xp W hW hXp:Measure ℕ) + +instance jointLaw_probability {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) (hW : 0 + (fun j=>(z.1 j:ℤ))∈E ∧ M∣(z.2:ℤ)-a ∧ + Q≤(∏ j,(z.1 j:ℝ))*(z.2:ℝ) ∧ (∏ j,(z.1 j:ℝ))*(z.2:ℝ)(law (X j) W hW (hX j):Measure ℕ))).real {t} = + ∏ j,(law (X j) W hW (hX j):Measure ℕ).real {t j} := by + simp only [measureReal_def,Measure.pi_singleton,ENNReal.toReal_prod] + rw [jointLaw,←Set.singleton_prod_singleton,measureReal_prod_prod,hpi,hpp] + simp_rw [hj] + rw [Finset.prod_div_distrib] + ring + +lemma joint_fiber_mass {m : ℕ} (E : Set (Fin m→ℤ)) (X : Fin m→ℕ) (Xp W : ℕ) + (hW : 0(t j:ℤ))∈E + · simp only [hE,true_and,ite_true] + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro p hp + by_cases hb : M∣(p:ℤ)-a ∧ Q≤(∏ j,(t j:ℝ))*(p:ℝ) ∧ + (∏ j,(t j:ℝ))*(p:ℝ)(mass_pos (X j) W hW (hX j)).ne') + · exact (mass_pos Xp W hW hXp).ne' + exact div_div_div_cancel_right₀ hN _ _ + +end ProductExposureLaw + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure02.lean new file mode 100644 index 0000000000000000000000000000000000000000..36405467b3148c7574b5cb53cc1f10e53cde82e6 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure02.lean @@ -0,0 +1,369 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.ProductExposure01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end +end + +section +noncomputable section +namespace RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + +theorem source_raw_joint_face_uniform (hsk : SecondKind c) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0U n j) atTop atTop) + (hUV : ∀ n j,U n j≤V n j) + (hZ : ∀ a : ℝ,0Z0 n/(1+∑ j,V n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z0 n) atTop (𝓝 0)) + (hWM : ∀ n,(primorial (w n):ℤ)∣(M n:ℤ)) + (hM : ∀ n,0U n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) → + ∀ (X : Fin m→ℕ) (Xp : ℕ) (hX : ∀ j,4*primorial (w n)≤X j) + (hXp : 4*primorial (w n)≤Xp),b.a.natAbs.Coprime (primorial (w n)) → + (∀ j,(X j:ℝ)≤b.S j) → (∀ j,2*b.S j≤(X j:ℝ)^2) → + (∀ t∈productTimes b.S b.r (L n),(Xp:ℝ)≤b.Q/(∏ j,(t j:ℝ))) → + (∀ t∈productTimes b.S b.r (L n),(b.Q+b.Δ)/(∏ j,(t j:ℝ))≤(Xp:ℝ)^2) → + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),LipschitzWith K σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (ProductExposureLaw.jointLaw X Xp (primorial (w n)) (primorial_pos _) hX hXp).real + (ProductExposureLaw.jointFiber + {t | badFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ t} + X Xp (primorial (w n)) b.S b.r (L n) b.Q b.Δ b.a (M n) : Set _) / + (ProductExposureLaw.jointLaw X Xp (primorial (w n)) (primorial_pos _) hX hXp).real + (ProductExposureLaw.jointFiber Set.univ + X Xp (primorial (w n)) b.S b.r (L n) b.Q b.Δ b.a (M n) : Set _) < ε + := by + classical + intro ε hε + have hu := raw_conditional_face_uniform (Γ:=Γ) (c:=c) hsk hΓ htop m v D d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M U V Z0 H L hw hU hUV hZ hH hHZ + hM hMs hL hsm hWL hUL ε hε + filter_upwards [hu] with n hn + intro b hb X Xp hX hXp ha hloD hhiD hloP hhiP A P hP σ hσ h hh hid + rw [ProductExposureLaw.conditional_exact, + HarmonicExposure.literal_mass_eq _ X Xp _ b.S b.r (L n) b.Q b.Δ b.a (M n) + (hL n) (hWL n) hb.2.2.1 hloD hhiD, + HarmonicExposure.literal_mass_eq Set.univ X Xp _ b.S b.r (L n) b.Q b.Δ b.a (M n) + (hL n) (hWL n) hb.2.2.1 hloD hhiD] + simpa only [exceptionalFace,Set.mem_ofPred_eq,Set.mem_univ,Finset.filter_true_of_mem (fun _ _=>True.intro)] using + hn b hb Xp (primorial (w n)) (hWM n) ha hloP hhiP A P hP σ hσ h hh hid + +end RoughFaceShift +end +end + +section +noncomputable section +namespace ProductExposureLabels +open scoped BigOperators +open HarmonicExposure ProductExposureLaw +attribute [local instance] Classical.propDecidable + +structure Label (m : ℕ) where + dyadic : Fin m → ℕ + residue : Fin m → ℤ + pivotResidue : ℤ + bin : ℤ + +def Label.scales {m : ℕ} (b : Label m) (j : Fin m) : ℝ := 2 ^ b.dyadic j + +def Label.width {m : ℕ} (b : Label m) (R : ℝ) : ℝ := (∏ j,b.scales j)*R + +def Label.left {m : ℕ} (b : Label m) (R : ℝ) : ℝ := b.bin*b.width R + +def expose {m : ℕ} (L M : ℤ) (R : ℝ) (z : (Fin m→ℕ)×ℕ) : Label m where + dyadic := fun j=>(z.1 j).log2 + residue := fun j=>(z.1 j:ℤ)%L + pivotResidue := (z.2:ℤ)%M + bin := ⌊(∏ j,(z.1 j:ℝ))*(z.2:ℝ) / ((∏ j,(2:ℝ)^(z.1 j).log2)*R)⌋ + +def rawDomain {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) : Finset ((Fin m→ℕ)×ℕ) := + (Fintype.piFinset (fun j=>RawHarmonicProbability.units (X j) W)).product + (Finset.Ico Xp (Xp^2)) + +@[ext] lemma Label.ext {m : ℕ} {a b : Label m} (h₁ : a.dyadic=b.dyadic) + (h₂ : a.residue=b.residue) (h₃ : a.pivotResidue=b.pivotResidue) + (h₄ : a.bin=b.bin) : a=b := by cases a; cases b; simp_all + +lemma dyadic_iff (t k : ℕ) (ht : 0 intro h + · constructor + · exact_mod_cast h.1 + · have hh : (t:ℝ)<(2:ℝ)^(k+1) := by exact_mod_cast h.2 + simpa [pow_succ,mul_comm] using hh + · constructor + · exact_mod_cast h.1 + · have hh : (t:ℝ)<(2:ℝ)^(k+1) := by simpa [pow_succ,mul_comm] using h.2 + exact_mod_cast hh + +lemma residue_iff (t L r : ℤ) (hr : 0≤r ∧ rpow_pos (by norm_num) _)) hR + +lemma expose_eq_iff {m : ℕ} (L M : ℤ) (R : ℝ) (hR : 0(z.1 j).log2)=b.dyadic) : + ((∏ j,(2:ℝ)^(z.1 j).log2)*R)=b.width R := by + unfold Label.width Label.scales + congr 1 + apply Finset.prod_congr rfl + intro j hj + rw [congrFun hd j] + constructor + · intro heq + have hd : (fun j=>(z.1 j).log2)=b.dyadic := congrArg Label.dyadic heq + have hre : (fun j=>(z.1 j:ℤ)%L)=b.residue := congrArg Label.residue heq + have hap : (z.2:ℤ)%M=b.pivotResidue := congrArg Label.pivotResidue heq + have hb : ⌊(∏ j,(z.1 j:ℝ))*(z.2:ℝ)/((∏ j,(2:ℝ)^(z.1 j).log2)*R)⌋=b.bin := + congrArg Label.bin heq + rw [hw hd] at hb + exact ⟨fun j=>(dyadic_iff _ _ (ht j)).mp (congrFun hd j), + fun j=>(residue_iff _ _ _ (hr j)).mp (congrFun hre j), + (residue_iff _ _ _ ha).mp hap, + (floor_bin_iff _ _ _ (b.width_pos R hR)).mp hb⟩ + · rintro ⟨hd,hrd,had,hb⟩ + have hde : (fun j=>(z.1 j).log2)=b.dyadic := + funext (fun j=>(dyadic_iff _ _ (ht j)).mpr (hd j)) + apply Label.ext hde + · exact funext (fun j=>(residue_iff _ _ _ (hr j)).mpr (hrd j)) + · exact (residue_iff _ _ _ ha).mpr had + · change ⌊(∏ j,(z.1 j:ℝ))*(z.2:ℝ)/((∏ j,(2:ℝ)^(z.1 j).log2)*R)⌋=b.bin + rw [hw hde] + exact (floor_bin_iff _ _ _ (b.width_pos R hR)).mpr hb + + + +theorem fiber_eq {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) (hX : ∀ j,0expose L M R z=b) = + jointFiber Set.univ X Xp W b.scales b.residue L (b.left R) (b.width R) + b.pivotResidue M + := by + classical + apply Finset.ext + rintro ⟨t,p⟩ + simp only [rawDomain,Finset.product_eq_sprod,Finset.mem_filter,Finset.mem_product,Fintype.mem_piFinset, + RawHarmonicProbability.units,Finset.mem_filter,jointFiber,rawTailFiber,Finset.product_eq_sprod, + Set.mem_univ,true_and] + constructor + · rintro ⟨⟨ht,hp⟩,he⟩ + have htpos : ∀ j,0(hX j).trans_le (Finset.mem_Ico.mp (ht j).1).1 + obtain ⟨hd,hrd,ha,hb⟩ := (expose_eq_iff L M R hR (t,p) htpos b hr ha).mp he + exact ⟨⟨fun j=>⟨(ht j).1,(ht j).2,(hd j).1,(hd j).2,hrd j⟩,hp⟩,ha,hb⟩ + · rintro ⟨⟨ht,hp⟩,had,hb⟩ + have htpos : ∀ j,0(hX j).trans_le (Finset.mem_Ico.mp (ht j).1).1 + refine ⟨⟨fun j=>⟨(ht j).1,(ht j).2.1⟩,hp⟩,?_⟩ + exact (expose_eq_iff L M R hR (t,p) htpos b hr ha).mpr + ⟨fun j=>⟨(ht j).2.2.1,(ht j).2.2.2.1⟩,fun j=>(ht j).2.2.2.2,had,hb⟩ + +end ProductExposureLabels +end +end + +section +noncomputable section +namespace ProductExposureCutoff +open DyadicHarmonicBoundary RawHarmonicProbability Finset Filter MeasureTheory +open scoped Topology BigOperators + +def cutoff (X C : ℕ) : Set ℕ := {p | p ≤ 2^C*X ∨ X^2 ≤ 2^C*p} + +lemma mass_mono_interval {A B C D W : ℕ} (hCA : C≤A) (hBD : B≤D) : + mass A B W≤ mass C D W := + sum_le_sum_of_subset_of_nonneg (Ico_subset_Ico hCA hBD) (by intros; positivity) + +lemma many_dyadic_lower (X W K : ℕ) (hW : 0p≤2^C*X) ⊆ (Ico X (X*2^(C+1))).filter W.Coprime := by + intro p hp + have hp₁ := mem_filter.mp hp + have hp₂ := mem_filter.mp hp₁.1 + have hp₃ := mem_filter.mp hp₂.1 + have hlo := hp₁.2 + have hc := hp₂.2 + have hwp := hp₃.2 + obtain ⟨hxp,hpx⟩ := mem_Ico.mp hp₃.1 + exact mem_filter.mpr ⟨mem_Ico.mpr ⟨hxp,hlo.trans_lt hlower⟩,hwp⟩ + have hs₂ : E.filter (fun p=>¬p≤2^C*X) ⊆ (Ico A (A*2^(C+1))).filter W.Coprime := by + intro p hp + have hp₁ := mem_filter.mp hp + have hp₂ := mem_filter.mp hp₁.1 + have hp₃ := mem_filter.mp hp₂.1 + have hlo := hp₁.2 + have hc := hp₂.2 + have hwp := hp₃.2 + obtain ⟨hxp,hpx⟩ := mem_Ico.mp hp₃.1 + have hc' : X^2≤2^C*p := (show p≤2^C*X ∨ X^2≤2^C*p from hc).resolve_left hlo + have hap : A≤p := by + dsimp [A] + apply (Nat.div_le_iff_le_mul hpow0).mpr + have hh : X^2≤p*2^C := by simpa only [mul_comm] using hc' + omega + exact mem_filter.mpr ⟨mem_Ico.mpr ⟨hap,hpx.trans hupper⟩,hwp⟩ + have hb₁ : (∑ p∈E.filter (fun p=>p≤2^C*X),(p:ℝ)⁻¹) ≤ mass X (X*2^(C+1)) W := by + have h := sum_le_sum_of_subset_of_nonneg hs₁ (fun _ _ _=>by positivity : ∀ i∈(Ico X (X*2^(C+1))).filter W.Coprime, i∉E.filter (fun p=>p≤2^C*X) → 0≤(i:ℝ)⁻¹) + simpa only [sum_filter,mass] using h + have hb₂ : (∑ p∈E.filter (fun p=>¬p≤2^C*X),(p:ℝ)⁻¹) ≤ mass A (A*2^(C+1)) W := by + have h := sum_le_sum_of_subset_of_nonneg hs₂ (fun _ _ _=>by positivity : ∀ i∈(Ico A (A*2^(C+1))).filter W.Coprime, i∉E.filter (fun p=>¬p≤2^C*X) → 0≤(i:ℝ)⁻¹) + simpa only [sum_filter,mass] using h + rw [hE,←sum_filter_add_sum_filter_not E (fun p=>p≤2^C*X)] + have h₁ := many_dyadic_upper X W (C+1) hW hX + have h₂ := many_dyadic_upper A W (C+1) hW (hX.trans hAx) + push_cast at h₁ h₂ + linarith + + +theorem raw_cutoff_bound (X W C K : ℕ) (hW : 0(law (X n) (W n) (hW n) (hX n) : Measure ℕ).real + (cutoff (X n) C)) atTop (𝓝 0) := by + apply tendsto_order.mpr + constructor + · intro a ha + exact Filter.Eventually.of_forall (fun n=>ha.trans_le (measureReal_nonneg)) + · intro ε hε + obtain ⟨K,hK⟩ := exists_nat_gt (12*((C:ℝ)+1)/ε) + have hk : (0:ℝ)z.1 j) + (jointLaw X Xp W hW hX hXp) (law (X j) W hW (hX j):Measure ℕ) := + (measurePreserving_eval (fun i=>(law (X i) W hW (hX i):Measure ℕ)) j).comp + measurePreserving_fst + exact hf.measureReal_preimage MeasurableSet.of_discrete.nullMeasurableSet + +lemma pivot_marginal {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) (hW : 0(law (X j) W hW (hX j):Measure ℕ))) + (ν:=(law Xp W hW hXp:Measure ℕ))).measureReal_preimage + MeasurableSet.of_discrete.nullMeasurableSet + +lemma law_ae_units (X W : ℕ) (hW : 0⟨ha,hz⟩⟩ + +lemma expose_bounds {m : ℕ} (L M : ℤ) (R : ℝ) (hR : 0(dyadic_iff _ _ (ht j)).mp rfl,?_⟩ + exact (floor_bin_iff _ _ _ ((expose L M R z).width_pos R hR)).mp rfl + +lemma product_dyadic_bounds {m : ℕ} (b : Label m) (t : Fin m→ℕ) + (ht : ∀ j,b.scales j≤(t j:ℝ) ∧ (t j:ℝ)<2*b.scales j) : + (∏ j,b.scales j)≤(∏ j,(t j:ℝ)) ∧ + (∏ j,(t j:ℝ))≤2^m*(∏ j,b.scales j) := by + constructor + · exact Finset.prod_le_prod₀ (fun j _=>by unfold Label.scales; positivity) (fun j _=>(ht j).1) + · calc + _ ≤ ∏ j,2*b.scales j := Finset.prod_le_prod₀ (fun _ _=>by positivity) (fun j _=>(ht j).2.le) + _ = _ := by rw [Finset.prod_mul_distrib]; simp + +lemma good_of_not_cutoff {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) + (hX : ∀ j,0(hX j).trans_le (Finset.mem_Ico.mp + (Finset.mem_filter.mp (hzT j)).1).1 + obtain ⟨hdy,hq,hq'⟩ := expose_bounds L M R hR z htpos + obtain ⟨hprod,hprod'⟩ := product_dyadic_bounds (expose L M R z) z.1 hdy + have hspos : 0<∏ j,(expose L M R z).scales j := + Finset.prod_pos (fun j _=>pow_pos (by norm_num) _) + constructor + · intro j + have hcut : ¬(z.1 j≤2*X j ∨(X j)^2≤2*z.1 j) := by + simpa [cutoff] using htc j + push Not at hcut + have hl : (2:ℝ)*X j<(z.1 j:ℝ) := by exact_mod_cast hcut.1 + have hu : (2:ℝ)*(z.1 j:ℝ)<(X j:ℝ)^2 := by exact_mod_cast hcut.2 + constructor <;> nlinarith [(hdy j).1,(hdy j).2] + · intro τ hτ hτ' + by_contra hn + have hbad : (expose L M R z).left R/τhn (Or.inr h) + have ht : ∀ j,z.1 j∉cutoff (X j) 1 := fun j h=>hn (Or.inl (Set.mem_iUnion.mpr ⟨j,h⟩)) + exact hz.1 (good_of_not_cutoff X Xp W (fun j=>by have:=hX j; omega) + (by omega) L M R hR hRX z hz.2 ht hp) + calc + _ ≤ _ := measureReal_mono hsub + _ ≤ _ := measureReal_union_le _ _ + _ ≤ (∑ j,(jointLaw X Xp W hW hX hXp).real {z | z.1 j∈cutoff (X j) 1})+ + (jointLaw X Xp W hW hX hXp).real {z | z.2∈cutoff Xp (m+2)} := + add_le_add (measureReal_iUnion_fintype_le _) le_rfl + _ = _ := by simp only [tail_marginal,pivot_marginal] + + + +theorem raw_good_decay {m : ℕ} (X : ℕ→Fin m→ℕ) (Xp W : ℕ→ℕ) + (L M : ℕ→ℤ) (R : ℕ→ℝ) (hW : ∀ n,0X n j) atTop atTop) + (hXpt : Tendsto Xp atTop atTop) (hR : ∀ n,0(jointLaw (X n) (Xp n) (W n) (hW n) (hX n) (hXp n)).real + {z | ¬Good (X n) (Xp n) (R n) (expose (L n) (M n) (R n) z)}) atTop (𝓝 0) + := by + apply squeeze_zero (fun _=>measureReal_nonneg) (fun n=> + bad_good_bound (X n) (Xp n) (W n) (hW n) (hX n) (hXp n) (L n) (M n) (R n) (hR n) (hRX n)) + have htail := tendsto_finsetSum Finset.univ (fun j _=> + raw_cutoff_decay (fun n=>X n j) W 1 hW (fun n=>hX n j) (hXt j)) + have hp := raw_cutoff_decay Xp W (m+2) hW hXp hXpt + simpa using htail.add hp + +end ProductExposureLabels + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure04.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure04.lean new file mode 100644 index 0000000000000000000000000000000000000000..28416f8fe236a543a5ea9ae34af138e959ec4aea --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/ProductExposure04.lean @@ -0,0 +1,297 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.ResidueAlignment01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +noncomputable section +end + +noncomputable section +namespace ProductExposureLaw +open MeasureTheory ProductExposureLabels RawHarmonicProbability +open scoped BigOperators ENNReal +attribute [local instance] Classical.propDecidable + +def outsideDomain {h : ℕ} (X : Fin h→ℕ) (W : ℕ) : Finset (Fin h→ℕ) := + Fintype.piFinset (fun j=>units (X j) W) + +def outsideLaw {h : ℕ} (X : Fin h→ℕ) (W : ℕ) (hW : 0(law (X j) W hW (hX j):Measure ℕ)) + +instance outsideLaw_probability {h : ℕ} (X : Fin h→ℕ) (W : ℕ) (hW : 0Fin.append z.1 y (e.symm j),z.2) +lemma outside_ae_domain {h : ℕ} (X : Fin h→ℕ) (W : ℕ) (hW : 0(law (X j) W hW (hX j):Measure ℕ)) j).quasiMeasurePreserving.ae + (law_ae_units (X j) W hW (hX j)) + filter_upwards [ae_all_iff.mpr hh] with y hy + exact Fintype.mem_piFinset.mpr hy + +lemma outside_weights_sum {h : ℕ} (X : Fin h→ℕ) (W : ℕ) (hW : 0Set.mem_univ _,fun _=>hy⟩ + simpa using hh + +lemma joint_reassemble {m h n : ℕ} (e : Fin (m+h)≃Fin n) + (X : Fin n→ℕ) (Xp W : ℕ) (hW : 0reassemble e yz.1 yz.2) + ((outsideLaw (fun j : Fin h=>X (e (j.natAdd m))) W hW (fun _=>hX _)).prod + (jointLaw (fun j : Fin m=>X (e (j.castAdd h))) Xp W hW (fun _=>hX _) hXp)) = + jointLaw X Xp W hW hX hXp := by + apply Measure.ext_of_singleton + intro z + rw [Measure.map_apply (measurable_of_countable _) (measurableSet_singleton _)] + have he : (fun yz=>reassemble e yz.1 yz.2) ⁻¹' {z} = + {fun j : Fin h=>z.1 (e (j.natAdd m))} ×ˢ + {(fun j : Fin m=>z.1 (e (j.castAdd h)),z.2)} := by + ext yz + constructor + · intro hy + change reassemble e yz.1 yz.2=z at hy + have h1 := congrArg Prod.fst hy + have h2 := congrArg Prod.snd hy + refine ⟨?_,?_⟩ + · apply funext + intro j + have hh := congrFun h1 (e (j.natAdd m)) + simpa [reassemble] using hh + · apply Prod.ext + · apply funext + intro j + have hh := congrFun h1 (e (j.castAdd h)) + simpa [reassemble] using hh + · exact h2 + · rintro ⟨hy,hz⟩ + change yz.1=(fun j : Fin h=>z.1 (e (j.natAdd m))) at hy + change yz.2=(fun j : Fin m=>z.1 (e (j.castAdd h)),z.2) at hz + change reassemble e yz.1 yz.2=z + rw [hy,hz] + apply Prod.ext + · funext j + rcases e.surjective j with ⟨i,rfl⟩ + refine Fin.addCases ?_ ?_ i + · intro a + simp [reassemble] + · intro a + simp [reassemble] + · rfl + rw [he,Measure.prod_prod] + change _ = (jointLaw X Xp W hW hX hXp) {(z.1,z.2)} + simp only [outsideLaw,jointLaw,←Set.singleton_prod_singleton,Measure.prod_prod,Measure.pi_singleton] + rw [mul_left_comm,←mul_assoc] + congr 1 + calc + _ = ∏ i : Fin (m+h),(law (X (e i)) W hW (hX (e i)):Measure ℕ) {z.1 (e i)} := by + simpa using (Fin.prod_univ_add (fun i : Fin (m+h)=> + (law (X (e i)) W hW (hX (e i)):Measure ℕ) {z.1 (e i)})).symm + _ = _ := e.prod_comp (fun j=>(law (X j) W hW (hX j):Measure ℕ) {z.1 j}) + + +theorem joint_outside_disintegration {m h n : ℕ} (e : Fin (m+h)≃Fin n) + (X : Fin n→ℕ) (Xp W : ℕ) (hW : 0X (e (j.castAdd h)) + let Xo := fun j : Fin h=>X (e (j.natAdd m)) + (jointLaw X Xp W hW hX hXp).real E = + ∑ y∈outsideDomain Xo W,(outsideLaw Xo W hW (fun _=>hX _)).real {y} * + (jointLaw Xi Xp W hW (fun _=>hX _) hXp).real {z | reassemble e y z∈E} + := by + classical + dsimp only + have hm := joint_reassemble e X Xp W hW hX hXp + rw [←hm,measureReal_def,Measure.map_apply (measurable_of_countable _) MeasurableSet.of_discrete, + Measure.prod_apply MeasurableSet.of_discrete] + conv_lhs => rw [←Measure.restrict_eq_self_of_ae_mem + (outside_ae_domain (fun j : Fin h=>X (e (j.natAdd m))) W hW (fun j=>hX _))] + rw [lintegral_finset,ENNReal.toReal_sum] + · apply Finset.sum_congr rfl + intro y hy + rw [ENNReal.toReal_mul,mul_comm] + rfl + · intro y hy + exact ENNReal.mul_ne_top (by finiteness) (by finiteness) + +end ProductExposureLaw +end + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift RoughTopologicalFace RoughArrayCoordinates SourceResidueAlignment +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory Filter +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jX N j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ N,0R N/(Xp N:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R N/(M N:ℝ))/ + (1+∑ j : Fin m,(X N (perm (j.castAdd h)):ℝ)^2)^a) atTop atTop) + (hQ0 : ∀ N,0≤Q N) + (hSize : Tendsto (fun N=>(Q N+(∏ l : Fin m,(X N (perm (l.castAdd h)):ℝ)^2)*(L N:ℝ))/R N) atTop (𝓝 0)) + (hWM : ∀ N,(primorial (w0 N):ℤ)∣(M N:ℤ)) + (hM : ∀ N,0(X N (perm (j.castAdd h)):ℝ)/(L N:ℝ)) atTop atTop) + (pattern : ι→Fin (v+1)→ℤ) (e : Fin q) (j : Fin (v+1)) + (g x : ℕ→(Fin h→ℕ)→Label m→∀ i,G i) (b0 b1 : ℕ→(Fin h→ℕ)→Label m→ι→ℝ) + (qval : ℕ→(Fin h→ℕ)→Label m→Fin q→ℤ) + (hQ : ∀ N y,y∈outsideDomain (fun l : Fin h=>X N (perm (l.natAdd m))) (primorial (w0 N)) → + ∀ b,b∈(fullDomain (fun l : Fin m=>X N (perm (l.castAdd h))) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) →∀ k,|(qval N y b k:ℝ)|≤Q N) : + Tendsto (fun N=>(jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) + (hX N) (hXp N)).real {z | + let y := fun l : Fin h=>z.1 (perm (l.natAdd m)) + (fun l : Fin m=>z.1 (perm (l.castAdd h)),z.2)∈ + rawPhysicalEvent (lattice G n q c hsk A w hA Γ) m v c₀ C₀ B η (R N) d (M N) (L N) + (fun b=>actualData G n q c hsk A w hA hw Γ pattern (g N y b) (x N y b) + (b0 N y b) (b1 N y b) (fun k=>(qval N y b k:ℝ)/(M N:ℝ)) + (fun k=>-(residueData (L N) (qval N y b k) b:ℝ)/(M N:ℝ)) e j + (coarseOrigin v (M N) (R N) b) (shift (M N) (L N) (qval N y b e) b))}) + atTop (𝓝 0) + := by + classical + let Xo (N : ℕ) (l : Fin h) := X N (perm (l.natAdd m)) + let Xi (N : ℕ) (l : Fin m) := X N (perm (l.castAdd h)) + let κ (N : ℕ) := ↥(outsideDomain (Xo N) (primorial (w0 N))) + let p (N : ℕ) (y : κ N) := + (outsideLaw (Xo N) (primorial (w0 N)) (primorial_pos _) (fun l=>hX N _)).real {y.val} + have hsum (N : ℕ) (f : (Fin h→ℕ)→ℝ) : + ∑ y : κ N,f y.val = ∑ y∈outsideDomain (Xo N) (primorial (w0 N)),f y := by + exact (Finset.sum_subtype _ (fun _=>Iff.rfl) f).symm + have hp (N : ℕ) (y : κ N) : 0≤p N y := measureReal_nonneg + have hmass (N : ℕ) : ∑ y,p N y=1 := by + dsimp only [p] + exact (hsum N (fun y=>(outsideLaw (Xo N) (primorial (w0 N)) + (primorial_pos _) (fun l=>hX N _)).real {y})).trans + (outside_weights_sum (Xo N) (primorial (w0 N)) (primorial_pos _) (fun l=>hX N _)) + have hh := source_outside_conditioning_face_decay G n q c hsk A w hA hw Γ hΓ htop + m v d hd c₀ C₀ B η hc₀ hC₀ hB hη w0 M Xp Xi R Q L hw0 (fun N l=>hX N _) hXp + (fun l=>hXt _) hXpt hR hRX hZ hQ0 hSize hWM hM hMs hL hsm hWL hML hLexact hXL + pattern e j κ p hp hmass (fun N y=>g N y.val) (fun N y=>x N y.val) + (fun N y=>b0 N y.val) (fun N y=>b1 N y.val) (fun N y=>qval N y.val) + (fun N y=>hQ N y.val y.property) + apply hh.congr' (Eventually.of_forall (fun N=>?_)) + rw [joint_outside_disintegration perm] + dsimp only [p] + rw [hsum N (fun y=>(outsideLaw (Xo N) (primorial (w0 N)) + (primorial_pos _) (fun l=>hX N _)).real {y} * + (jointLaw (Xi N) (Xp N) (primorial (w0 N)) (primorial_pos _) (fun l=>hX N _) (hXp N)).real + (rawPhysicalEvent (lattice G n q c hsk A w hA Γ) m v c₀ C₀ B η (R N) d (M N) (L N) + (fun b=>actualData G n q c hsk A w hA hw Γ pattern (g N y b) (x N y b) + (b0 N y b) (b1 N y b) (fun k=>(qval N y b k:ℝ)/(M N:ℝ)) + (fun k=>-(residueData (L N) (qval N y b k) b:ℝ)/(M N:ℝ)) e j + (coarseOrigin v (M N) (R N) b) (shift (M N) (L N) (qval N y b e) b))))] + apply Finset.sum_congr rfl + intro y hy + congr 2 + ext z + simp only [Set.mem_ofPred_eq,reassemble,Equiv.symm_apply_apply,Fin.append_left,Fin.append_right] + +end RoughArrayFace +end + + + +noncomputable section +open MeasureTheory Filter Topology +open scoped ENNReal BigOperators +namespace ConditionalDiagonal +variable (Ω : ℕ → Type) [∀ N,MeasurableSpace (Ω N)] +variable (μ : ∀ N,Measure (Ω N)) (A : ∀ N,Set (Ω N)) +variable (E : ∀ N,ℕ → Ω N → ℝ) (ε : ℝ≥0∞) (hε : 0<ε) +variable (hA : ∀ N,ε≤μ N (A N)) +variable (hE : ∀ i δ,0<δ → Tendsto + (fun N=>μ N {x | δ≤|E N i x|}) atTop (𝓝 0)) + +include hε hA hE in + + +theorem select : ∃ φ : ℕ → ℕ,StrictMono φ ∧ ∃ x : ∀ k,Ω (φ k), + (∀ k,x k∈A (φ k)) ∧ ∀ i,Tendsto (fun k=>E (φ k) i (x k)) atTop (𝓝 0) := by + classical + have hev (k : ℕ) : ∀ᶠ N in atTop,∃ x∈A N,∀ i≤k,|E N i x|<1/((k:ℝ)+1) := by + let δ : ℝ:=1/((k:ℝ)+1) + have hδ : 0<δ := by dsimp [δ]; positivity + have ht : Tendsto (fun N=>∑ i∈Finset.range (k+1),μ N {x | δ≤|E N i x|}) + atTop (𝓝 0) := by + simpa only [Finset.sum_const_zero] using + (tendsto_finsetSum (Finset.range (k+1)) (fun i _=>hE i δ hδ)) + filter_upwards [ht.eventually (gt_mem_nhds hε)] with N hN + let Bad : Set (Ω N):=⋃ i∈Finset.range (k+1),{x | δ≤|E N i x|} + have hm : μ N Bad<μ N (A N) := + (measure_biUnion_finset_le (Finset.range (k+1)) _).trans_lt (hN.trans_le (hA N)) + have hn : ¬A N⊆Bad := fun h=>not_lt_of_ge (measure_mono h) hm + obtain ⟨x,hx,hxb⟩:=Set.not_subset.mp hn + refine ⟨x,hx,?_⟩ + intro i hi + by_contra! h + exact hxb (Set.mem_iUnion.mpr ⟨i,Set.mem_iUnion.mpr ⟨Finset.mem_range.mpr (by omega),h⟩⟩) + have hth (k : ℕ) : ∃ T : ℕ,∀ N≥T,∃ x∈A N,∀ i≤k,|E N i x|<1/((k:ℝ)+1) := + Filter.eventually_atTop.mp (hev k) + choose T hT using hth + let φ (k : ℕ):=k+∑ j∈Finset.range (k+1),T j + have hφ : StrictMono φ := by + apply strictMono_nat_of_lt_succ + intro k + simp only [φ,Finset.sum_range_succ] + omega + have hφT (k : ℕ) : T k≤φ k := by + have hsum : T k≤∑ j∈Finset.range (k+1),T j := + Finset.single_le_sum (fun _ _=>Nat.zero_le _) (Finset.mem_range.mpr (Nat.lt_succ_self k)) + exact hsum.trans (Nat.le_add_left _ _) + choose x hx hxe using (fun k=>hT k (φ k) (hφT k)) + refine ⟨φ,hφ,x,hx,?_⟩ + intro i + apply Metric.tendsto_atTop.mpr + intro δ hδ + have ht : ∀ᶠ k : ℕ in atTop,1/((k:ℝ)+1)<δ := + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).eventually (gt_mem_nhds hδ) + obtain ⟨N,hN⟩:=Filter.eventually_atTop.mp ht + refine ⟨max N i,?_⟩ + intro k hk + simpa only [Real.dist_eq,sub_zero] using + (hxe k i ((le_max_right N i).trans hk)).trans (hN k ((le_max_left N i).trans hk)) + +end ConditionalDiagonal + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/ProgressionPartition01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/ProgressionPartition01.lean new file mode 100644 index 0000000000000000000000000000000000000000..a47e3595ca3ce776f297699724247cd2f46cd952 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/ProgressionPartition01.lean @@ -0,0 +1,259 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CubePolynomials01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped ComplexConjugate +end +end + + + +section +noncomputable section +open scoped BigOperators +namespace FactorProgression +open CubeFaces CubePolynomials +variable {G : Type*} [Group G] + +lemma affine_polynomial (H : Filtration G) {k : ℕ} {f : ℤ → G} + (hf : f∈polynomials H k) (a b : ℤ) : + (fun z => f (a*z+b))∈polynomials H k := by + rw [mem_polynomials] at hf ⊢ + intro I h n + convert hf I (fun i => a*h i) (a*n+b) using 1 + ext v + change f (a*(n+∑ i∈v∩I,h i)+b)=f (a*n+b+∑ i∈v∩I,a*h i) + rw [← Finset.mul_sum] + congr 1 + ring + +lemma conjugate_polynomial (H : Filtration G) (h0 : H.level 0=⊤) + {f : ℤ → G} (hf : f∈polynomials H 0) (v : G) : + (fun z => v⁻¹*f z*v)∈polynomials H 0 := by + have hv : (fun _ : ℤ => v)∈polynomials H 0 := const_mem (by rw [h0]; trivial) + exact (polynomials H 0).mul_mem ((polynomials H 0).mul_mem ((polynomials H 0).inv_mem hv) hf) hv + +lemma affine_conjugate_polynomial (H : Filtration G) (h0 : H.level 0=⊤) + {f : ℤ → G} (hf : f∈polynomials H 0) (a b : ℤ) (v : G) : + (fun z => v⁻¹*f (a*z+b)*v)∈polynomials H 0 := + conjugate_polynomial H h0 (affine_polynomial H hf a b) v + +lemma factor_coset (Γ : Subgroup G) (e f b v : G) + (hv : (QuotientGroup.mk b : G⧸Γ)=QuotientGroup.mk v) : + (QuotientGroup.mk (e*f*b) : G⧸Γ) = (e*v) • QuotientGroup.mk (v⁻¹*f*v) := by + calc + _ = (e*f) • (QuotientGroup.mk b : G⧸Γ) := rfl + _ = (e*f) • QuotientGroup.mk v := by rw [hv] + _ = QuotientGroup.mk ((e*f)*v) := rfl + _ = QuotientGroup.mk ((e*v)*(v⁻¹*f*v)) := by congr 1; group + _ = _ := rfl + + + +theorem periodic_factor_coset (Γ : Subgroup G) (f e f' b : ℤ → G) + (he : ∀ z, f z=e z*f' z*b z) (T : ℤ) + (hper : Function.Periodic (fun z => (QuotientGroup.mk (b z) : G⧸Γ)) T) + (r : ℤ) (v : G) (hv : (QuotientGroup.mk (b r) : G⧸Γ)=QuotientGroup.mk v) (z : ℤ) : + (QuotientGroup.mk (f (T*z+r)) : G⧸Γ) = + (e (T*z+r)*v) • QuotientGroup.mk (v⁻¹*f' (T*z+r)*v) := by + rw [he] + apply factor_coset + have hh := (hper.int_mul z) r + have hi : T*z+r=r+z*T := by ring + rw [hi] + have hh' : (QuotientGroup.mk (b (r+z*T)) : G⧸Γ)=QuotientGroup.mk (b r) := by simpa using hh + exact hh'.trans hv + +end FactorProgression +end +end + + + +section +noncomputable section +open scoped Topology +namespace CompactActionFreeze +variable {G V X : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + [NormedAddCommGroup V] [MetricSpace X] [CompactSpace X] + [MulAction G X] [ContinuousSMul G X] + + + +omit [IsTopologicalGroup G] in +theorem small_displacement [IsTopologicalGroup G] (c : G ≃ₜ V) (hc : c 1=0) (ε : ℝ) (hε : 0<ε) : + ∃ u : ℝ, 0 dist (c.symm p.1 • p.2) p.2,by fun_prop⟩ + let A : C(V,C(X,ℝ)) := F.curry + have hA0 : A 0=0 := by + ext x + have he : c.symm 0=1 := by rw [← hc,c.symm_apply_apply] + simp [A,F,ContinuousMap.curry_apply,he] + obtain ⟨u,hu,hs⟩ := Metric.continuousAt_iff.mp A.continuous.continuousAt ε hε + refine ⟨u/2,by positivity,fun g hg x => ?_⟩ + have hd : dist (c g) 0 simp + | succ A ih => + rw [Nat.succ_mul,Finset.sum_range_add,ih,Finset.sum_range_succ] + +lemma sum_progressions {M : Type*} [AddCommMonoid M] (f : ℕ → M) (J K T : ℕ) : + (∑ i ∈ Finset.range (J*K*T), f i) = + ∑ a ∈ Finset.range J, ∑ r ∈ Finset.range T, + ∑ n ∈ Finset.range K, f ((a*K+n)*T+r) := by + rw [sum_blocks f (J*K) T,sum_blocks (fun i => ∑ r ∈ Finset.range T, f (i*T+r)) J K] + apply Finset.sum_congr rfl + intro a ha + exact Finset.sum_comm + +lemma residual_bound (f : ℕ → ℂ) (μ : ℂ) (hf : ∀ i, ‖f i‖ ≤ 1) (hμ : ‖μ‖ ≤ 1) + (A B : ℕ) : + ‖∑ i ∈ Finset.range (A+B), (f i-μ)‖ ≤ + ‖∑ i ∈ Finset.range A, (f i-μ)‖+2*B := by + rw [Finset.sum_range_add] + refine (norm_add_le _ _).trans (add_le_add le_rfl ?_) + calc + _ ≤ ∑ i ∈ Finset.range B, ‖f (A+i)-μ‖ := norm_sum_le _ _ + _ ≤ ∑ _i ∈ Finset.range B, (2:ℝ) := Finset.sum_le_sum (fun i _ => + (norm_sub_le _ _).trans (by linarith [hf (A+i)])) + _ = _ := by simp; ring + + + +theorem obstruction (f : ℕ → ℂ) (g : ℕ → ℕ → ℕ → ℂ) (μ : ℂ) + (J K T N : ℕ) (δ : ℝ) (hδ : 0<δ) (hN : 0 hfreeze a ha r hr n (Finset.mem_range.mp hn))) + · exact (hno a ha r hr).le + _ = _ := by simp; ring + have hblock : ‖∑ i ∈ Finset.range (J*K*T), (f i-μ)‖ ≤ δ/2*(J*K*T:ℕ) := by + rw [sum_progressions] + calc + _ ≤ ∑ a ∈ Finset.range J, ‖∑ r ∈ Finset.range T, + ∑ n ∈ Finset.range K, (f ((a*K+n)*T+r)-μ)‖ := norm_sum_le _ _ + _ ≤ ∑ a ∈ Finset.range J, ∑ r ∈ Finset.range T, δ/2*K := by + apply Finset.sum_le_sum + intro a ha + exact (norm_sum_le _ _).trans (Finset.sum_le_sum (fun r hr => hcell a (Finset.mem_range.mp ha) r (Finset.mem_range.mp hr))) + _ = _ := by simp; ring + have hres := residual_bound f μ hf hμ (J*K*T) (N-J*K*T) + rw [Nat.add_sub_of_le hM] at hres + have hm : (J*K*T:ℕ) ≤ (N:ℝ) := by exact_mod_cast hM + have hn : (0:ℝ) ?_⟩ + dsimp only + have hd : 0.trans hN) + have hK : 0Read j a y t)) +variable (hS : ∀ j (a : Shifts D),Continuous (fun y : Y j=>a • y)) +variable (M : ∀ a : Fin E.period,∀ β : ℝ, + PhysicalMarginalFaceData D (C a).pivotChart.chart (C a).pointFiltration (C a).pointLattice + π ((C a).pivotImage β) s) + +include hπ hRead hS M hq₀ hb hτ in + + +theorem physical_pivot_empirical_success_mass (hL : ∀ N,0centerReading_continuous D π Read hπ hRead F q₀ b p.val) + (fun p=>translatedReading_continuous D π Read hπ hRead hS F q₀ b p.val) + he' hhalf hm' + simpa only [O,AN,TN,Set.iUnion_subtype] using hh + +end AllLevelFactorization.Factorization +end + +end + +section + + + + +noncomputable section +namespace CubeFaces +variable {G H ι : Type*} [Group G] [Group H] [DecidableEq ι] +variable (p : G →* H) + +def vertexMap : (Finset ι → G) →* (Finset ι → H) where + toFun f w:=p (f w) + map_one' := by ext w; exact p.map_one + map_mul' f g:=by ext w; exact p.map_mul _ _ + +omit [DecidableEq ι] in +@[simp] lemma vertexMap_apply (f : Finset ι → G) (w : Finset ι) : + vertexMap p f w=p (f w) := rfl + +lemma vertexMap_face (D : Finset ι) : + (vertexMap p).comp (face D)=(face D).comp p := by + ext g w + simp only [MonoidHom.comp_apply,vertexMap_apply,face_apply] + split_ifs <;> simp + +lemma map_cube (K : Filtration G) (L : Filtration H) + (honto : ∀ j,(K.level j).map p=L.level j) (I : Finset ι) (l : ℕ) : + (cube K I l).map (vertexMap p)=cube L I l := by + simp only [cube,Subgroup.map_iSup,Subgroup.map_map,vertexMap_face] + simp only [←Subgroup.map_map,honto] + +lemma exists_cube_lift (K : Filtration G) (L : Filtration H) + (honto : ∀ j,(K.level j).map p=L.level j) (I : Finset ι) (l : ℕ) + (f : Finset ι → H) (hf : f∈cube L I l) : + ∃ g∈cube K I l,∀ w,p (g w)=f w := by + rw [←map_cube p K L honto I l] at hf + obtain ⟨g,hg,he⟩:=hf + exact ⟨g,hg,fun w=>congrFun he w⟩ + +end CubeFaces +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalEchelon + +variable {K : Type*} [Field K] + +structure Chart {n : ℕ} (W : Submodule K (Fin n → K)) where + dim : ℕ + pivot : Fin dim → Fin n + mono : StrictMono pivot + embed : (Fin dim → K) →ₗ[K] (Fin n → K) + mem : ∀ x,embed x∈W + onto : ∀ v∈W,∃ x,embed x=v + at_pivot : ∀ x i,embed x (pivot i)=x i + prefix_eq : ∀ j x y,(∀ i,pivot i ≤ j → x i=y i) → embed x j=embed y j + +def dropLast (n : ℕ) : (Fin (n+1) → K) →ₗ[K] (Fin n → K) where + toFun x i:=x i.castSucc + map_add' _ _:=rfl + map_smul' _ _:=rfl + +def snocZero (n : ℕ) : (Fin n → K) →ₗ[K] (Fin (n+1) → K) where + toFun x:=Fin.snoc x 0 + map_add' x y:=by ext i; refine Fin.lastCases ?_ (fun i=>?_) i <;> simp + map_smul' a x:=by ext i; refine Fin.lastCases ?_ (fun i=>?_) i <;> simp + +lemma expansion {n : ℕ} (x : Fin n → K) : x=∑ i : Fin n,x i • Pi.single i 1 := by + ext j + simp [Finset.sum_apply,Pi.smul_apply,Pi.single_apply] + + + +lemma lift {n d : ℕ} (W : Submodule K (Fin (n+1) → K)) + (e : (Fin d → K) →ₗ[K] (Fin n → K)) + (he : ∀ x,e x∈W.map (dropLast n)) : + ∃ f : (Fin d → K) →ₗ[K] (Fin (n+1) → K), + (∀ x,f x∈W) ∧ ∀ x,dropLast n (f x)=e x := by + have hex (i : Fin d) : ∃ b∈W,dropLast n b=e (Pi.single i 1) := + Submodule.mem_map.mp (he _) + choose b hb hpb using hex + let f : (Fin d → K) →ₗ[K] (Fin (n+1) → K):= + ∑ i : Fin d,(LinearMap.proj i).smulRight (b i) + have hf (x) : f x=∑ i : Fin d,x i • b i := by simp [f,LinearMap.sum_apply] + refine ⟨f,?_,?_⟩ + · intro x + rw [hf] + exact W.sum_mem (fun i _=>W.smul_mem _ (hb i)) + · intro x + rw [hf,map_sum] + simp only [map_smul,hpb] + conv_rhs=>rw [expansion x,map_sum] + simp + + + +theorem chart_exists {n : ℕ} (W : Submodule K (Fin n → K)) : Nonempty (Chart W) := by + induction n with + | zero => + exact ⟨{ dim:=0 + pivot:=Fin.elim0 + mono:=by intro i; exact Fin.elim0 i + embed:=0 + mem:=by intro x; exact W.zero_mem + onto:=by intro v hv; exact ⟨Fin.elim0,Subsingleton.elim _ _⟩ + at_pivot:=by intro x i; exact Fin.elim0 i + prefix_eq:=by intro j; exact Fin.elim0 j }⟩ + | succ n ih => + let V:=W.map (dropLast n) + obtain ⟨E⟩:=ih V + obtain ⟨f,hf,hpf⟩:=lift W E.embed E.mem + by_cases hker : ∀ v∈W,dropLast n v=0 → v=0 + · have hinj : ∀ u∈W,∀ v∈W,dropLast n u=dropLast n v → u=v := by + intro u hu v hv huv + apply sub_eq_zero.mp + apply hker (u-v) (W.sub_mem hu hv) + rw [map_sub,huv,sub_self] + refine ⟨{ dim:=E.dim + pivot:=fun i=>(E.pivot i).castSucc + mono:=by intro i j hij; exact E.mono hij + embed:=f + mem:=hf + onto:=?_ + at_pivot:=?_ + prefix_eq:=?_ }⟩ + · intro v hv + obtain ⟨x,hx⟩:=E.onto (dropLast n v) (Submodule.mem_map.mpr ⟨v,hv,rfl⟩) + exact ⟨x,hinj _ (hf _) _ hv ((hpf x).trans hx)⟩ + · intro x i + exact (congrFun (hpf x) (E.pivot i)).trans (E.at_pivot x i) + · intro j x y hxy + revert hxy + refine Fin.lastCases ?_ (fun j=>?_) j <;> intro hxy + · have he : x=y:=funext fun i=>hxy i (Fin.le_last _) + rw [he] + · exact (congrFun (hpf x) j).trans ((E.prefix_eq j x y (fun i hi=>hxy i hi)).trans + (congrFun (hpf y) j).symm) + · push Not at hker + obtain ⟨v,hv,hpv,hv0⟩:=hker + have hvl : v (Fin.last n)≠0 := by + intro hh + apply hv0 + ext i + refine Fin.lastCases hh (fun i=>?_) i + exact congrFun hpv i + have haxis : Pi.single (Fin.last n) (1:K)∈W := by + have he : (v (Fin.last n))⁻¹ • v=Pi.single (Fin.last n) 1 := by + ext i + refine Fin.lastCases ?_ (fun i=>?_) i + · simp [hvl] + · have hz : v i.castSucc=0:=congrFun hpv i + simp [hz,Fin.castSucc_ne_last] + rw [← he] + exact W.smul_mem _ hv + have hzero (x : Fin E.dim → K) : snocZero n (E.embed x)∈W := by + have hx:=hf x + have he : snocZero n (E.embed x)=f x-f x (Fin.last n) • Pi.single (Fin.last n) 1 := by + ext i + refine Fin.lastCases ?_ (fun i=>?_) i + · simp [snocZero] + · have hh:=congrFun (hpf x) i + simpa [snocZero,dropLast,Fin.castSucc_ne_last] using hh.symm + rw [he] + exact W.sub_mem hx (W.smul_mem _ haxis) + let e : (Fin (E.dim+1) → K) →ₗ[K] (Fin (n+1) → K) := + (snocZero n).comp (E.embed.comp (dropLast E.dim)) + + (LinearMap.proj (Fin.last E.dim)).smulRight (Pi.single (Fin.last n) 1) + have he (x : Fin (E.dim+1) → K) : e x=Fin.snoc (E.embed (dropLast E.dim x)) (x (Fin.last E.dim)) := by + ext i + refine Fin.lastCases ?_ (fun i=>?_) i <;> + simp [e,snocZero,Fin.castSucc_ne_last] + let p : Fin (E.dim+1) → Fin (n+1):=Fin.snoc (fun i=>(E.pivot i).castSucc) (Fin.last n) + refine ⟨{ dim:=E.dim+1 + pivot:=p + mono:=?_ + embed:=e + mem:=?_ + onto:=?_ + at_pivot:=?_ + prefix_eq:=?_ }⟩ + · intro i j hij + revert hij + refine Fin.lastCases ?_ (fun j=>?_) j <;> intro hij + · have hi : i≠Fin.last E.dim:=ne_of_lt hij + obtain ⟨i,rfl⟩:=Fin.eq_castSucc_of_ne_last hi + simp [p] + · revert hij + refine Fin.lastCases ?_ (fun i=>?_) i <;> intro hij + · exact False.elim (not_lt_of_ge (Fin.le_last _) hij) + · simpa [p] using E.mono hij + · intro x + exact W.add_mem (hzero _) (W.smul_mem _ haxis) + · intro y hy + obtain ⟨x,hx⟩:=E.onto (dropLast n y) (Submodule.mem_map.mpr ⟨y,hy,rfl⟩) + refine ⟨Fin.snoc x (y (Fin.last n)),?_⟩ + rw [he] + have hd : dropLast E.dim (Fin.snoc x (y (Fin.last n)))=x:=by ext i; simp [dropLast] + rw [hd,hx] + ext i + refine Fin.lastCases ?_ (fun i=>?_) i <;> simp [dropLast] + · intro x i + refine Fin.lastCases ?_ (fun i=>?_) i + · simp [he,p] + · simpa [he,p,dropLast] using E.at_pivot (dropLast E.dim x) i + · intro j x y hxy + revert hxy + refine Fin.lastCases ?_ (fun j=>?_) j <;> intro hxy + · simp only [he,Fin.snoc_last] + exact hxy (Fin.last E.dim) (by simp [p]) + · simp only [he,Fin.snoc_castSucc] + apply E.prefix_eq + intro i hi + exact hxy i.castSucc (by simpa [p] using hi) + +end RationalEchelon + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalEchelon02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalEchelon02.lean new file mode 100644 index 0000000000000000000000000000000000000000..93b8ef2e56eee9bfc9c706012bc419b152942cbd --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalEchelon02.lean @@ -0,0 +1,361 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalEchelon01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalMatrix +variable {n m k : ℕ} + +def real (f : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) : + (Fin n → ℝ) →ₗ[ℝ] (Fin m → ℝ) := + ∑ i : Fin n,(LinearMap.proj i).smulRight (fun j=>(f (Pi.single i 1) j:ℝ)) + +lemma real_apply (f : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) (x : Fin n → ℝ) (j : Fin m) : + real f x j=∑ i : Fin n,x i*(f (Pi.single i 1) j:ℝ) := by + simp [real,LinearMap.sum_apply,Finset.sum_apply,Pi.smul_apply,smul_eq_mul] + +lemma real_single (f : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) (i : Fin n) : + real f (Pi.single i 1)=fun j=>(f (Pi.single i 1) j:ℝ) := by + ext j + simp [real_apply,Pi.single_apply] + +lemma real_rat (f : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) (x : Fin n → ℚ) : + real f (fun i=>(x i:ℝ))=fun j=>(f x j:ℝ) := by + ext j + rw [real_apply] + conv_rhs=>rw [RationalEchelon.expansion x,map_sum] + simp [map_smul,Finset.sum_apply,Pi.smul_apply,smul_eq_mul] + +lemma real_comp (f : (Fin m → ℚ) →ₗ[ℚ] (Fin k → ℚ)) + (g : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) : + real (f.comp g)=(real f).comp (real g) := by + apply (Pi.basisFun ℝ (Fin n)).ext + intro i + simp only [Pi.basisFun_apply,real_single,LinearMap.comp_apply] + exact (real_rat f (g (Pi.single i 1))).symm + +lemma real_id : real (LinearMap.id : (Fin n → ℚ) →ₗ[ℚ] (Fin n → ℚ))=LinearMap.id := by + apply (Pi.basisFun ℝ (Fin n)).ext + intro i + ext j + simp [real_single,Pi.basisFun_apply,Pi.single_apply,apply_ite] + +lemma real_sub (f g : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) : + real (f-g)=real f-real g := by + ext x j + simp [real_apply,mul_sub,Finset.sum_sub_distrib] + +lemma real_injective : Function.Injective (@real n m) := by + intro f g h + apply (Pi.basisFun ℚ (Fin n)).ext + intro i + ext j + have hh:=congrArg (fun p=>(p (Pi.single i 1)) j) h + simpa only [real_single,Pi.basisFun_apply,Rat.cast_inj] using hh + +lemma real_injective_of_injective (f : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) + (hf : Function.Injective f) : Function.Injective (real f) := by + obtain ⟨g,hg⟩:=f.exists_leftInverse_of_injective (LinearMap.ker_eq_bot.mpr hf) + have hh:=congrArg real hg + rw [real_comp,real_id] at hh + exact Function.LeftInverse.injective (fun x=>LinearMap.congr_fun hh x) + +end RationalMatrix + +namespace RationalEchelon.Chart +variable {n : ℕ} {W : Submodule ℚ (Fin n → ℚ)} (E : Chart W) + +def coords : (Fin n → ℚ) →ₗ[ℚ] (Fin E.dim → ℚ) where + toFun x i:=x (E.pivot i) + map_add' _ _:=rfl + map_smul' _ _:=rfl + +lemma coords_embed (x : Fin E.dim → ℚ) : E.coords (E.embed x)=x := by + ext i + exact E.at_pivot x i + +lemma embed_coords {x : Fin n → ℚ} (hx : x∈W) : E.embed (E.coords x)=x := by + obtain ⟨y,rfl⟩:=E.onto x hx + rw [coords_embed] + +lemma real_coords (x : Fin n → ℝ) (i : Fin E.dim) : + RationalMatrix.real E.coords x i=x (E.pivot i) := by + simp [RationalMatrix.real_apply,coords,Pi.single_apply,apply_ite] + +lemma real_at_pivot (x : Fin E.dim → ℝ) (i : Fin E.dim) : + RationalMatrix.real E.embed x (E.pivot i)=x i := by + simp [RationalMatrix.real_apply,E.at_pivot,Pi.single_apply,apply_ite] + +lemma coeff_zero (j : Fin n) (i : Fin E.dim) (hji : jx (E.pivot i)) := by + rw [normal,RationalMatrix.real_sub,RationalMatrix.real_id,RationalMatrix.real_comp] + have hh : RationalMatrix.real E.coords x=(fun i=>x (E.pivot i)):=funext (E.real_coords x) + change x-RationalMatrix.real E.embed (RationalMatrix.real E.coords x)=_ + rw [hh] + +lemma real_normal_pivot (x : Fin n → ℝ) (i : Fin E.dim) : + RationalMatrix.real E.normal x (E.pivot i)=0 := by + rw [E.real_normal] + simp [E.real_at_pivot] + +lemma real_normal_tail (q : ℕ) (x : Fin n → ℝ) (hx : ∀ j : Fin n,j.valx (E.pivot i)) j=0 + rw [hx j hj] + have he:=E.real_prefix j (fun i=>x (E.pivot i)) 0 (by + intro i hi + exact hx _ (lt_of_le_of_lt hi hj)) + simpa using congrArg Neg.neg he + +end RationalEchelon.Chart +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalMatrix +variable {a b : ℕ} +def select (u : Fin a → Fin b) : (Fin b → ℚ) →ₗ[ℚ] (Fin a → ℚ) where + toFun x i:=x (u i) + map_add' _ _:=rfl + map_smul' _ _:=rfl +lemma real_select (u : Fin a → Fin b) (x : Fin b → ℝ) (i : Fin a) : + real (select u) x i=x (u i) := by + simp [real_apply,select,Pi.single_apply,apply_ite] +end RationalMatrix + +namespace RationalEchelon.Chart +variable {n : ℕ} {W : Submodule ℚ (Fin n → ℚ)} (E : Chart W) + +def freeSet : Finset (Fin n):=Finset.univ.filter (fun j=>j∉Set.range E.pivot) +def free : Fin E.freeSet.card ↪o Fin n:=E.freeSet.orderEmbOfFin rfl + +lemma free_ne_pivot (i : Fin E.freeSet.card) (j : Fin E.dim) : E.free i≠E.pivot j := by + have hh:=(Finset.mem_filter.mp (E.freeSet.orderEmbOfFin_mem rfl i)).2 + exact fun he=>hh ⟨j,he.symm⟩ + +lemma pivot_or_free (j : Fin n) : + (∃ i : Fin E.dim,E.pivot i=j) ∨ ∃ i : Fin E.freeSet.card,E.free i=j := by + by_cases h : j∈Set.range E.pivot + · exact Or.inl h + · right + have hh : j∈E.freeSet:=Finset.mem_filter.mpr ⟨Finset.mem_univ _,h⟩ + have he:=E.freeSet.range_orderEmbOfFin rfl + change j∈Set.range E.free + rw [show Set.range E.free=E.freeSet from he] + exact hh + +def sectionMap : (Fin E.freeSet.card → ℚ) →ₗ[ℚ] (Fin n → ℚ):= + ∑ i : Fin E.freeSet.card,(LinearMap.proj i).smulRight (Pi.single (E.free i) 1) + +def quotientMap : (Fin n → ℚ) →ₗ[ℚ] (Fin E.freeSet.card → ℚ):= + (RationalMatrix.select E.free).comp E.normal + +lemma section_apply (x : Fin E.freeSet.card → ℚ) (j : Fin n) : + E.sectionMap x j=∑ i : Fin E.freeSet.card,x i*(Pi.single (E.free i) 1 : Fin n → ℚ) j := by + simp [sectionMap,LinearMap.sum_apply,Finset.sum_apply,Pi.smul_apply,smul_eq_mul] + +lemma section_free (x : Fin E.freeSet.card → ℚ) (i : Fin E.freeSet.card) : + E.sectionMap x (E.free i)=x i := by + simp [E.section_apply,Pi.single_apply,E.free.injective.eq_iff] + +lemma section_pivot (x : Fin E.freeSet.card → ℚ) (j : Fin E.dim) : + E.sectionMap x (E.pivot j)=0 := by + rw [E.section_apply] + apply Finset.sum_eq_zero + intro i hi + simp [(E.free_ne_pivot i j).symm] + +lemma normal_section (x : Fin E.freeSet.card → ℚ) : E.normal (E.sectionMap x)=E.sectionMap x := by + have he : E.coords (E.sectionMap x)=0:=funext (E.section_pivot x) + rw [normal_apply,he,map_zero,sub_zero] + +lemma quotient_section (x : Fin E.freeSet.card → ℚ) : E.quotientMap (E.sectionMap x)=x := by + change (RationalMatrix.select E.free) (E.normal (E.sectionMap x))=x + rw [E.normal_section] + ext i + exact E.section_free x i + +lemma section_quotient (x : Fin n → ℚ) : E.sectionMap (E.quotientMap x)=E.normal x := by + ext j + rcases E.pivot_or_free j with ⟨i,rfl⟩|⟨i,rfl⟩ + · rw [E.section_pivot,E.normal_pivot] + · rw [E.section_free] + rfl + +lemma quotient_eq_zero_iff (x : Fin n → ℚ) : E.quotientMap x=0 ↔ x∈W := by + rw [← E.normal_eq_zero_iff,← E.section_quotient] + constructor + · intro h + rw [h,map_zero] + · intro hx + have hh:=congrArg E.quotientMap hx + simpa only [E.quotient_section,map_zero] using hh + +lemma remainder_mem (x : Fin n → ℚ) : x-E.sectionMap (E.quotientMap x)∈W := by + rw [E.section_quotient] + exact E.normal_sub x + +lemma real_quotient (x : Fin n → ℝ) (i : Fin E.freeSet.card) : + RationalMatrix.real E.quotientMap x i=RationalMatrix.real E.normal x (E.free i) := by + rw [quotientMap,RationalMatrix.real_comp] + exact RationalMatrix.real_select E.free _ i + +lemma real_section_free (x : Fin E.freeSet.card → ℝ) (i : Fin E.freeSet.card) : + RationalMatrix.real E.sectionMap x (E.free i)=x i := by + simp [RationalMatrix.real_apply,E.section_free,Pi.single_apply,apply_ite] + +lemma real_section_pivot (x : Fin E.freeSet.card → ℝ) (j : Fin E.dim) : + RationalMatrix.real E.sectionMap x (E.pivot j)=0 := by + simp [RationalMatrix.real_apply,E.section_pivot] + +lemma real_quotient_section (x : Fin E.freeSet.card → ℝ) : + RationalMatrix.real E.quotientMap (RationalMatrix.real E.sectionMap x)=x := by + have he : E.quotientMap.comp E.sectionMap=LinearMap.id:=LinearMap.ext E.quotient_section + have hh:=congrArg RationalMatrix.real he + rw [RationalMatrix.real_comp,RationalMatrix.real_id] at hh + exact LinearMap.congr_fun hh x + +lemma real_section_quotient (x : Fin n → ℝ) : + RationalMatrix.real E.sectionMap (RationalMatrix.real E.quotientMap x)=RationalMatrix.real E.normal x := by + have he : E.sectionMap.comp E.quotientMap=E.normal:=LinearMap.ext E.section_quotient + have hh:=congrArg RationalMatrix.real he + rw [RationalMatrix.real_comp] at hh + exact LinearMap.congr_fun hh x + +lemma real_normal_level (w : Fin n → ℕ) (hw : Monotone w) (l : ℕ) (x : Fin n → ℝ) + (hx : ∀ j,w jx (E.pivot i)) j=0 + rw [hx j hj] + have he:=E.real_prefix j (fun i=>x (E.pivot i)) 0 (by + intro i hi + exact hx _ (lt_of_le_of_lt (hw hi) hj)) + simpa using congrArg Neg.neg he + +lemma real_quotient_level (w : Fin n → ℕ) (hw : Monotone w) (l : ℕ) (x : Fin n → ℝ) + (hx : ∀ j,w j aesop + have hjb : b ∈ H.level j := by split_ifs at hb <;> aesop + have hc := H.commutator_le i j (Subgroup.commutator_mem_commutator hia hjb) + split_ifs + · exact hc + · exact ⟨hc,hcomm a b⟩ +end CubeFaces + +namespace CubePolynomials +open CubeFaces +variable {G A : Type*} [Group G] [Group A] + + + +theorem pullback_mem (H : Filtration G) (φ : A →* G) (hφ : Function.Injective φ) + (q k : ℕ) (hbot : H.level (k+q) = ⊥) (f : ℤ → A) + (hf : (fun n => φ (f n)) ∈ polynomials H k) : + f ∈ polynomials (H.pullback φ) k := by + induction q generalizing k f with + | zero => + have he : f = 1 := by + funext n + apply hφ + have hv := eval_mem hf n + have hb : H.level k = ⊥ := by simpa using hbot + simpa [hb] using hv + rw [he] + exact (polynomials _ _).one_mem + | succ q ih => + apply mem_of_derivatives + · intro n + exact eval_mem hf n + · intro t + apply ih (k+1) (by convert hbot using 1; congr 1; omega) + convert derivative_mem hf t using 1 + ext n + simp [shift,map_mul,map_inv] + + + +theorem refine_mem (H : Filtration G) (K : Subgroup G) + (hcomm : ∀ a b : G, ⁅a,b⁆ ∈ K) (q k : ℕ) (hbot : H.level (k+q) = ⊥) + (f : ℤ → G) (hf : f ∈ polynomials H k) (hK : ∀ n, f n ∈ K) : + f ∈ polynomials (H.refine K hcomm) k := by + induction q generalizing k f with + | zero => + have he : f = 1 := by + funext n + have hv := eval_mem hf n + have hb : H.level k = ⊥ := by simpa using hbot + simpa [hb] using hv + rw [he] + exact (polynomials _ _).one_mem + | succ q ih => + apply mem_of_derivatives + · intro n + change f n ∈ (if k < 2 then H.level k else H.level k ⊓ K) + split_ifs + · exact eval_mem hf n + · exact ⟨eval_mem hf n,hK n⟩ + · intro t + apply ih (k+1) (by convert hbot using 1; congr 1; omega) + _ (derivative_mem hf t) + intro n + exact K.mul_mem (K.inv_mem (hK n)) (hK (n+t)) + + + +theorem refine_of_linear_coset (H : Filtration G) (K : Subgroup G) + (hcomm : ∀ a b : G, ⁅a,b⁆ ∈ K) (s : ℕ) (hbot : H.level s = ⊥) + (f : ℤ → G) (hf : f ∈ polynomials H 0) (a : G) (ha : a ∈ H.level 1) + (hK : ∀ n, f n * (a^n)⁻¹ ∈ K) : f ∈ polynomials (H.refine K hcomm) 0 := by + have hl : (fun n : ℤ => a^n) ∈ polynomials H 0 := by + simpa using NilpotentTaylor.binomial_mem (H:=H) 1 0 a ha + have hl' : (fun n : ℤ => a^n) ∈ polynomials (H.refine K hcomm) 0 := by + apply (by simpa using NilpotentTaylor.binomial_mem (H:=H.refine K hcomm) 1 0 a ha) + have hr := refine_mem H K hcomm s 0 (by simpa using hbot) + (f*(fun n : ℤ => a^n)⁻¹) ((polynomials H 0).mul_mem hf ((polynomials H 0).inv_mem hl)) hK + have he : (f*(fun n : ℤ => a^n)⁻¹) * (fun n : ℤ => a^n) = f := by group + rw [← he] + exact (polynomials _ _).mul_mem hr hl' + +end CubePolynomials +end +end + + + +section +namespace RationalFactorPeriods +noncomputable section +lemma eval_desc (n : ℤ) (j : ℕ) : + (descPochhammer ℤ j).eval n = (j.factorial : ℤ) * Ring.choose n j := by + have h := Ring.descPochhammer_eq_factorial_smul_choose n j + rw [← Polynomial.aeval_eq_smeval] at h + simpa using h + + + +lemma choose_period_dvd (m : ℕ) {j d : ℕ} (hj : j ≤ d) (n : ℤ) : + (m : ℤ) ∣ Ring.choose (n + (m * d.factorial : ℕ)) j - Ring.choose n j := by + have h := Polynomial.sub_dvd_eval_sub (n + (m*d.factorial : ℕ)) n + (descPochhammer ℤ j) + rw [add_sub_cancel_left,eval_desc,eval_desc,← mul_sub] at h + have hfac : (j.factorial : ℤ) ∣ (d.factorial : ℤ) := + Int.natCast_dvd_natCast.mpr (Nat.factorial_dvd_factorial hj) + have hdiv : (j.factorial : ℤ) * m ∣ (m*d.factorial : ℕ) := by + rw [Nat.cast_mul,mul_comm (j.factorial : ℤ)] + exact mul_dvd_mul_left (m : ℤ) hfac + exact (Int.mul_dvd_mul_iff_left (by exact_mod_cast j.factorial_ne_zero)).mp (hdiv.trans h) + +variable {G : Type*} [Group G] +lemma zpow_eq_of_sub_dvd {a : G} {m : ℕ} (ha : a^m = 1) {u v : ℤ} + (h : (m : ℤ) ∣ u-v) : a^u = a^v := by + obtain ⟨z,hz⟩ := h + have he : u = (m : ℤ)*z+v := by omega + rw [he,zpow_add,zpow_mul,zpow_natCast,ha,one_zpow,one_mul] + + + +def orderedWord {k : ℕ} (a : Fin k → G) (j : Fin k → ℕ) (b : ℤ) : G := + ((List.finRange k).map (fun i => a i ^ Ring.choose b (j i))).prod + +lemma orderedWord_map {K : Type*} [Group K] (φ : G →* K) {k : ℕ} + (a : Fin k → G) (j : Fin k → ℕ) (b : ℤ) : + φ (orderedWord a j b) = orderedWord (fun i => φ (a i)) j b := by + simp [orderedWord,map_list_prod,List.map_map,Function.comp_def] + +lemma orderedWord_congr {k : ℕ} {a a' : Fin k → G} + (ha : ∀ i, a i = a' i) (j : Fin k → ℕ) (b : ℤ) : + orderedWord a j b = orderedWord a' j b := by + have h : a = a' := funext ha + rw [h] + +lemma orderedWord_periodic {k : ℕ} (a : Fin k → G) (j : Fin k → ℕ) + (m s : ℕ) (ha : ∀ i, a i ^ m = 1) (hj : ∀ i, j i ≤ s) : + Function.Periodic (orderedWord a j) (m * s.factorial : ℕ) := by + intro b + unfold orderedWord + congr 1 + apply List.map_congr_left + intro i _ + exact zpow_eq_of_sub_dvd (ha i) (choose_period_dvd m (hj i) b) + +lemma finite_image_periodic {K : Type*} [Group K] [Fintype K] + (φ : G →* K) {k : ℕ} (a : Fin k → G) (j : Fin k → ℕ) + (s : ℕ) (hj : ∀ i, j i ≤ s) : + Function.Periodic (fun b => φ (orderedWord a j b)) + (Fintype.card K * s.factorial : ℕ) := by + intro b + simp only [orderedWord_map] + exact orderedWord_periodic (fun i => φ (a i)) j (Fintype.card K) s + (fun _ => pow_card_eq_one) hj b + +lemma finite_image_stabilizes {K : Type*} [Group K] [Finite K] + (φ : G →* K) {k : ℕ} (a : ℕ → Fin k → G) (j : Fin k → ℕ) : + ∃ u : ℕ → ℕ, StrictMono u ∧ ∀ l b, + φ (orderedWord (a (u l)) j b) = φ (orderedWord (a (u 0)) j b) := by + classical + let F : ℕ → (Fin k → K) := fun l i => φ (a l i) + obtain ⟨v,hv⟩ := Finite.exists_infinite_fiber F + have hi : (Set.ofPred (fun l => F l = v)).Infinite := Set.infinite_coe_iff.mp hv + refine ⟨Nat.nth (fun l => F l = v),Nat.nth_strictMono hi,?_⟩ + intro l b + simp only [orderedWord_map] + apply orderedWord_congr + intro i + have hl := congrFun (Nat.nth_mem_of_infinite hi l) i + have hz := congrFun (Nat.nth_mem_of_infinite hi 0) i + exact hl.trans hz.symm + +lemma coset_pattern_stabilizes (Γ : Subgroup G) [Γ.FiniteIndex] + {k : ℕ} (a : ℕ → Fin k → G) (j : Fin k → ℕ) + (s : ℕ) (hj : ∀ i, j i ≤ s) : + ∃ (u : ℕ → ℕ) (T : ℕ), StrictMono u ∧ 0 < T ∧ + (∀ l b, (QuotientGroup.mk (orderedWord (a (u l)) j b) : G ⧸ Γ) = + QuotientGroup.mk (orderedWord (a (u 0)) j b)) ∧ + Function.Periodic + (fun b => (QuotientGroup.mk (orderedWord (a (u 0)) j b) : G ⧸ Γ)) (T : ℤ) := by + classical + let : Fintype (G ⧸ Γ) := Fintype.ofFinite _ + let K := Equiv.Perm (G ⧸ Γ) + let φ : G →* K := MulAction.toPermHom G (G ⧸ Γ) + obtain ⟨u,hu,he⟩ := finite_image_stabilizes φ a j + refine ⟨u,Fintype.card K * s.factorial,hu, + Nat.mul_pos Fintype.card_pos s.factorial_pos,?_,?_⟩ + · intro l b + have h := congrArg (fun e : K => e (QuotientGroup.mk (1:G))) (he l b) + simpa [φ,K,MulAction.toPermHom] using h + · intro b + have h := congrArg (fun e : K => e (QuotientGroup.mk (1:G))) + (finite_image_periodic φ (a (u 0)) j s hj b) + simpa [φ,K,MulAction.toPermHom] using h + +lemma periodic_mod {α : Type*} {f : ℤ → α} {T : ℤ} + (hf : Function.Periodic f T) (b : ℤ) : f (b % T) = f b := by + have h := hf.sub_int_mul_eq (x := b) (b / T) + simpa [Int.emod_def,mul_comm] using h + + + +theorem rational_right_factors [TopologicalSpace G] [IsTopologicalGroup G] + [PreconnectedSpace G] [LocallyCompactSpace G] [T2Space G] {n k : ℕ} + (c : RationalLattice.RealCoordinates G n) (Γ : Subgroup G) [DiscreteTopology Γ] + (hΓrat : Γ ≤ RationalLattice.rationalSubgroup c) + (C : Set G) (hC : IsCompact C) (hreps : ∀ g : G, ∃ x ∈ C, x⁻¹*g ∈ Γ) + (v : Fin k → G) (hv : ∀ i, RationalLattice.IsRational c (v i)) + (m : ℕ → Fin k → ℤ) (j : Fin k → ℕ) (s : ℕ) (hj : ∀ i, j i ≤ s) : + ∃ (u : ℕ → ℕ) (T : ℕ) (σ : Fin T → G), StrictMono u ∧ 0 < T ∧ + (∀ r, RationalLattice.IsRational c (σ r)) ∧ + ∀ l b, ∃ r : Fin T, (r.val : ℤ) = b % (T : ℤ) ∧ + (QuotientGroup.mk (orderedWord (fun i => v i ^ m (u l) i) j b) : G ⧸ Γ) = + QuotientGroup.mk (σ r) := by + classical + let S := Finset.univ.image v + have hSrat : ∀ g ∈ S, RationalLattice.IsRational c g := by + intro g hg + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hg + exact hv i + obtain ⟨H,hΓH,hSH,hHrat,hHd,hHi⟩ := + RationalLattice.finite_rational_extension c Γ hΓrat C hC hreps S hSrat + let : (Γ.subgroupOf H).FiniteIndex := hHi + have hvH (i : Fin k) : v i ∈ H := hSH (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + let a : ℕ → Fin k → H := fun l i => ⟨v i ^ m l i,H.zpow_mem (hvH i) _⟩ + obtain ⟨u,T,hu,hT,hfix,hper⟩ := coset_pattern_stabilizes (Γ.subgroupOf H) a j s hj + let σ : Fin T → G := fun r => (orderedWord (a (u 0)) j (r.val : ℤ) : H) + refine ⟨u,T,σ,hu,hT,?_,?_⟩ + · intro r + exact hHrat (orderedWord (a (u 0)) j (r.val : ℤ)).property + · intro l b + have hnonneg : 0 ≤ b % (T : ℤ) := Int.emod_nonneg _ (by omega) + have hlt : b % (T : ℤ) < T := Int.emod_lt_of_pos _ (by omega) + let r : Fin T := ⟨(b % (T : ℤ)).toNat,by omega⟩ + have hr : (r.val : ℤ) = b % (T : ℤ) := Int.toNat_of_nonneg hnonneg + refine ⟨r,hr,?_⟩ + have he : (QuotientGroup.mk (orderedWord (a (u l)) j b) : H ⧸ Γ.subgroupOf H) = + QuotientGroup.mk (orderedWord (a (u 0)) j (r.val : ℤ)) := by + rw [hr] + exact (hfix l b).trans (periodic_mod hper b).symm + have hmem := QuotientGroup.eq.mp he + have hquot : (QuotientGroup.mk ((orderedWord (a (u l)) j b : H) : G) : G ⧸ Γ) = + QuotientGroup.mk (σ r) := QuotientGroup.eq.mpr hmem + have hmap : ((orderedWord (a (u l)) j b : H) : G) = + orderedWord (fun i => v i ^ m (u l) i) j b := + orderedWord_map H.subtype (a (u l)) j b + rw [hmap] at hquot + exact hquot + +end +end RationalFactorPeriods + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice01.lean new file mode 100644 index 0000000000000000000000000000000000000000..769be680eb69992f6646ad3db380458eb6b82d0f --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice01.lean @@ -0,0 +1,257 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.TriangularDenominators01 +import OAI.Geometry.NilpotentCharts.Coordinates +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +namespace RationalLattice +noncomputable section +variable {G : Type*} [Group G] [TopologicalSpace G] +variable {n : ℕ} + +def IsRational (c : RealCoordinates G n) (g : G) : Prop := + ∀ i, ∃ x : ℚ, (x : ℝ) = c.coord g i + +lemma eval_rational {ι : Type*} (P : MvPolynomial ι ℚ) (x : ι → ℝ) + (hx : ∀ i, ∃ q : ℚ, (q : ℝ) = x i) : + ∃ q : ℚ, (q : ℝ) = MvPolynomial.eval₂ (algebraMap ℚ ℝ) x P := by + classical + let q : ι → ℚ := fun i => Classical.choose (hx i) + have hq : (algebraMap ℚ ℝ) ∘ q = x := funext (fun i => Classical.choose_spec (hx i)) + refine ⟨MvPolynomial.eval q P,?_⟩ + simpa [hq] using (MvPolynomial.eval₂_comp (algebraMap ℚ ℝ) q P) + +lemma rational_one (c : RealCoordinates G n) : IsRational c 1 := by + intro i + exact ⟨0,by simp [c.one_coord]⟩ + +lemma rational_mul (c : RealCoordinates G n) {g h : G} + (hg : IsRational c g) (hh : IsRational c h) : IsRational c (g*h) := by + intro i + obtain ⟨a,ha⟩ := hg i + obtain ⟨b,hb⟩ := hh i + obtain ⟨e,he⟩ := eval_rational (c.correction i) + (Sum.elim (fun j => c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) + (by intro k; cases k with | inl j => exact hg _ | inr j => exact hh _) + exact ⟨a+b+e,by rw [Rat.cast_add,Rat.cast_add,ha,hb,he,c.mul_coord]⟩ + +lemma rational_inv (c : RealCoordinates G n) {g : G} (hg : IsRational c g) : + IsRational c g⁻¹ := by + intro i + have hpartial : ∀ j (hj : j < n), ∃ q : ℚ, (q : ℝ) = c.coord g⁻¹ ⟨j,hj⟩ := by + intro j + induction j using Nat.strong_induction_on with + | h j ih => + intro hj + let i : Fin n := ⟨j,hj⟩ + obtain ⟨a,ha⟩ := hg i + obtain ⟨e,he⟩ := eval_rational (c.correction i) + (Sum.elim (fun k => c.coord g ⟨k.val,lt_trans k.isLt i.isLt⟩) + (fun k => c.coord g⁻¹ ⟨k.val,lt_trans k.isLt i.isLt⟩)) + (by + intro k + cases k with + | inl k => exact hg _ + | inr k => exact ih k.val k.isLt _) + refine ⟨-(a+e),?_⟩ + have hmul := c.mul_coord g g⁻¹ i + rw [mul_inv_cancel,c.one_coord,← ha,← he] at hmul + rw [Rat.cast_neg,Rat.cast_add] + change -((a : ℝ)+e) = c.coord g⁻¹ i + linarith + exact hpartial i.val i.isLt + +def rationalSubgroup (c : RealCoordinates G n) : Subgroup G where + carrier := IsRational c + one_mem' := rational_one c + mul_mem' := rational_mul c + inv_mem' := rational_inv c + +def qcoord (c : RealCoordinates G n) (g : rationalSubgroup c) (i : Fin n) : ℚ := + Classical.choose (g.property i) + +lemma qcoord_spec (c : RealCoordinates G n) (g : rationalSubgroup c) (i : Fin n) : + (qcoord c g i : ℝ) = c.coord g i := Classical.choose_spec (g.property i) + +lemma qcoord_injective (c : RealCoordinates G n) : Function.Injective (qcoord c) := by + intro g h heq + apply Subtype.ext + apply c.coord.injective + funext i + rw [← qcoord_spec c g i,← qcoord_spec c h i,heq] + +lemma qcoord_continuous (c : RealCoordinates G n) (i : Fin n) : + Continuous (fun g => qcoord c g i) := by + apply Rat.isEmbedding_coe_real.isInducing.continuous_iff.mpr + change Continuous (fun g : rationalSubgroup c => (qcoord c g i : ℝ)) + simp_rw [qcoord_spec] + exact (continuous_apply i).comp (c.coord.continuous.comp continuous_subtype_val) + +def rationalCoordinates (c : RealCoordinates G n) : + TriangularDenominators.Coordinates (rationalSubgroup c) n where + coord := qcoord c + one_coord i := by + apply Rat.cast_injective (α := ℝ) + rw [qcoord_spec] + exact (c.one_coord i).trans Rat.cast_zero.symm + correction := c.correction + mul_coord g h i := by + apply Rat.cast_injective (α := ℝ) + rw [Rat.cast_add,Rat.cast_add,qcoord_spec,qcoord_spec,qcoord_spec] + have hp := MvPolynomial.eval₂_comp (algebraMap ℚ ℝ) + (Sum.elim (fun j => qcoord c g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => qcoord c h ⟨j.val,lt_trans j.isLt i.isLt⟩)) (c.correction i) + have hcast (q : ℚ) : (algebraMap ℚ ℝ) q = (q : ℝ) := by simp + simp only [hcast] at hp + rw [hp] + change c.coord ((g:G)*(h:G)) i = _ + rw [c.mul_coord] + congr 2 + funext k + cases k with + | inl j => exact (qcoord_spec c g _).symm + | inr j => exact (qcoord_spec c h _).symm + + + +theorem rational_fg_discrete [IsTopologicalGroup G] (c : RealCoordinates G n) + (H : Subgroup (rationalSubgroup c)) (hH : H.FG) : DiscreteTopology H := by + obtain ⟨S,hS⟩ := hH + rw [← hS] + exact TriangularDenominators.closure_discrete (rationalCoordinates c) + (qcoord_injective c) (qcoord_continuous c) S + +end +end RationalLattice + +namespace RationalLattice +noncomputable section +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + [PreconnectedSpace G] [LocallyCompactSpace G] [T2Space G] {n : ℕ} + + + +theorem finite_rational_extension (c : RealCoordinates G n) (Γ : Subgroup G) + [DiscreteTopology Γ] (hΓrat : Γ ≤ rationalSubgroup c) + (C : Set G) (hC : IsCompact C) (hreps : ∀ g : G, ∃ x ∈ C, x⁻¹*g ∈ Γ) + (S : Finset G) (hSrat : ∀ g ∈ S, IsRational c g) : + ∃ H : Subgroup G, Γ ≤ H ∧ (S : Set G) ⊆ H ∧ H ≤ rationalSubgroup c ∧ + DiscreteTopology H ∧ (Γ.subgroupOf H).FiniteIndex := by + let H := Γ ⊔ Subgroup.closure (S : Set G) + have hHrat : H ≤ rationalSubgroup c := by + apply sup_le hΓrat + rw [Subgroup.closure_le] + exact hSrat + have hH : H.FG := (CocompactLattice.fg_of_compact_reps Γ C hC hreps).sup ⟨S,rfl⟩ + let : Group.FG H := (Group.fg_iff_subgroup_fg H).mpr hH + let e := Subgroup.subgroupOfContinuousMulEquivOfLe hHrat + have hqG : Group.FG (H.subgroupOf (rationalSubgroup c)) := + Group.fg_of_surjective (f := e.symm.toMonoidHom) e.symm.surjective + have hq : (H.subgroupOf (rationalSubgroup c)).FG := + (Group.fg_iff_subgroup_fg _).mp hqG + have hdq := rational_fg_discrete c _ hq + have hd : DiscreteTopology H := e.discreteTopology_iff.mp hdq + let : DiscreteTopology H := hd + refine ⟨H,le_sup_left,?_,hHrat,hd,?_⟩ + · exact fun _ hg => Subgroup.mem_sup_right (Subgroup.subset_closure hg) + · exact TriangularDenominators.finiteIndex_of_compact_reps Γ H le_sup_left C hC hreps + +end +end RationalLattice +end + + + +section +open scoped BigOperators +noncomputable section +namespace Polynomial +open scoped _root_.Polynomial +variable {K : Type*} [Field K] [CharZero K] + +lemma exists_antidifference_monomial (i : ℕ) (a : K) : + ∃ q : K[X], q.comp (1+_root_.Polynomial.X) - q = _root_.Polynomial.C a * _root_.Polynomial.X^i := by + let b : K[X] := (_root_.Polynomial.bernoulli (i+1)).map (algebraMap ℚ K) + have hb : b.comp (1+_root_.Polynomial.X) = b + _root_.Polynomial.C (i+1 : K) * _root_.Polynomial.X^i := by + have h := congrArg (Polynomial.map (algebraMap ℚ K)) (_root_.Polynomial.bernoulli_comp_one_add_X (i+1)) + simpa [b, _root_.Polynomial.map_comp, nsmul_eq_mul] using h + refine ⟨_root_.Polynomial.C (a / (i+1 : K)) * b,?_⟩ + rw [_root_.Polynomial.mul_comp,_root_.Polynomial.C_comp,hb] + have hi : (i+1 : K) ≠ 0 := by exact_mod_cast Nat.succ_ne_zero i + calc + _root_.Polynomial.C (a / (i+1 : K)) * (b + _root_.Polynomial.C (i+1 : K) * _root_.Polynomial.X^i) - _root_.Polynomial.C (a / (i+1 : K)) * b = + (_root_.Polynomial.C (a / (i+1 : K)) * _root_.Polynomial.C (i+1 : K)) * _root_.Polynomial.X^i := by ring + _ = _root_.Polynomial.C a * _root_.Polynomial.X^i := by rw [← _root_.Polynomial.C_mul,div_mul_cancel₀ _ hi] + + +theorem exists_antidifference (p : K[X]) : ∃ q : K[X], + q.eval 0 = 0 ∧ q.comp (1+_root_.Polynomial.X) - q = p := by + have hex : ∃ q : K[X], q.comp (1+_root_.Polynomial.X) - q = p := by + induction p using Polynomial.induction_on' with + | add p r hp hr => + obtain ⟨q,hq⟩ := hp + obtain ⟨s,hs⟩ := hr + refine ⟨q+s,?_⟩ + rw [_root_.Polynomial.add_comp] + linear_combination hq+hs + | monomial i a => + simpa only [_root_.Polynomial.C_mul_X_pow_eq_monomial] using exists_antidifference_monomial i a + obtain ⟨q,hq⟩ := hex + exact ⟨q-_root_.Polynomial.C (q.eval 0),by simp,by simpa [_root_.Polynomial.sub_comp] using hq⟩ + +end Polynomial + +namespace Polynomial +open scoped _root_.Polynomial +variable {A : Type*} [CommRing A] [Algebra ℚ A] + +lemma exists_antidifference_monomial_algebra (i : ℕ) (a : A) : + ∃ q : A[X], q.comp (1+_root_.Polynomial.X) - q = _root_.Polynomial.C a * _root_.Polynomial.X^i := by + let b : A[X] := (_root_.Polynomial.bernoulli (i+1)).map (algebraMap ℚ A) + have hb : b.comp (1+_root_.Polynomial.X) = b + _root_.Polynomial.C (i+1 : A) * _root_.Polynomial.X^i := by + have h := congrArg (Polynomial.map (algebraMap ℚ A)) (_root_.Polynomial.bernoulli_comp_one_add_X (i+1)) + simpa [b,_root_.Polynomial.map_comp,nsmul_eq_mul] using h + let u : A := (algebraMap ℚ A) ((i+1:ℚ)⁻¹) + have hui : u*(i+1:A) = 1 := by + have hi : (i+1:ℚ) ≠ 0 := by positivity + have h := congrArg (algebraMap ℚ A) (inv_mul_cancel₀ hi) + simpa [u] using h + refine ⟨_root_.Polynomial.C (a*u)*b,?_⟩ + rw [_root_.Polynomial.mul_comp,_root_.Polynomial.C_comp,hb] + calc + _root_.Polynomial.C (a*u) * (b + _root_.Polynomial.C (i+1:A) * _root_.Polynomial.X^i) - _root_.Polynomial.C (a*u)*b = + (_root_.Polynomial.C (a*u)*_root_.Polynomial.C (i+1:A))*_root_.Polynomial.X^i := by ring + _ = _root_.Polynomial.C a*_root_.Polynomial.X^i := by rw [← _root_.Polynomial.C_mul,mul_assoc,hui,mul_one] + + + +theorem exists_antidifference_algebra (p : A[X]) : ∃ q : A[X], + q.eval 0 = 0 ∧ q.comp (1+_root_.Polynomial.X) - q = p := by + have hex : ∃ q : A[X], q.comp (1+_root_.Polynomial.X) - q = p := by + induction p using Polynomial.induction_on' with + | add p r hp hr => + obtain ⟨q,hq⟩ := hp + obtain ⟨s,hs⟩ := hr + refine ⟨q+s,?_⟩ + rw [_root_.Polynomial.add_comp] + linear_combination hq+hs + | monomial i a => + simpa only [_root_.Polynomial.C_mul_X_pow_eq_monomial] using exists_antidifference_monomial_algebra i a + obtain ⟨q,hq⟩ := hex + exact ⟨q-_root_.Polynomial.C (q.eval 0),by simp,by simpa [_root_.Polynomial.sub_comp] using hq⟩ + +end Polynomial + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice02.lean new file mode 100644 index 0000000000000000000000000000000000000000..1223987af7e137623891f0dbbb142e66edd3dd2d --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice02.lean @@ -0,0 +1,291 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped BigOperators +noncomputable section +end +end + + + +section +open scoped BigOperators +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace Polynomial +open scoped _root_.Polynomial +variable {K : Type*} [Field K] [CharZero K] +lemma eq_of_eval_nat_eq {p q : K[X]} (h : ∀ m : ℕ, p.eval (m : K) = q.eval (m : K)) : p = q := by + apply _root_.Polynomial.eq_of_infinite_eval_eq + apply (Set.infinite_range_of_injective (Nat.cast_injective (R := K))).mono + rintro x ⟨m,rfl⟩ + exact h m +end Polynomial +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +lemma polynomial_substitute_eval {ι : Type*} (P : MvPolynomial ι ℚ) + (p : ι → ℝ[X]) (t : ℝ) : + (MvPolynomial.eval₂ (Polynomial.C.comp (algebraMap ℚ ℝ)) p P).eval t = + MvPolynomial.eval₂ (algebraMap ℚ ℝ) (fun i => (p i).eval t) P := by + have h := MvPolynomial.eval₂_comp_left (Polynomial.evalRingHom t) + (Polynomial.C.comp (algebraMap ℚ ℝ)) p P + have hc : (Polynomial.evalRingHom t).comp (Polynomial.C.comp (algebraMap ℚ ℝ)) = + algebraMap ℚ ℝ := by + ext q + simp + rw [hc] at h + exact h + + + +theorem natpow_polynomial (g : G) (i : Fin n) : + ∃ p : ℝ[X], ∀ m : ℕ, p.eval (m : ℝ) = c.coord (g^m) i := by + have aux : ∀ l : ℕ, ∀ hl : l + intro hl + choose p hp using (fun j : Fin l => ih j.val j.isLt (lt_trans j.isLt hl)) + let x : (Fin l ⊕ Fin l) → ℝ[X] := Sum.elim p + (fun j => Polynomial.C (c.coord g ⟨j.val,lt_trans j.isLt hl⟩)) + let Q : ℝ[X] := Polynomial.C (c.coord g ⟨l,hl⟩) + + MvPolynomial.eval₂ (Polynomial.C.comp (algebraMap ℚ ℝ)) x (c.correction ⟨l,hl⟩) + obtain ⟨P,hP0,hP⟩ := Polynomial.exists_antidifference Q + refine ⟨P,?_⟩ + intro m + induction m with + | zero => simpa [c.one_coord] using hP0 + | succ m hm => + have he := congrArg (Polynomial.eval (m : ℝ)) hP + simp only [Polynomial.eval_sub,Polynomial.eval_comp,Polynomial.eval_add, + Polynomial.eval_one,Polynomial.eval_X] at he + have hx : (fun a => (x a).eval (m : ℝ)) = + Sum.elim (fun j => c.coord (g^m) ⟨j.val,lt_trans j.isLt hl⟩) + (fun j => c.coord g ⟨j.val,lt_trans j.isLt hl⟩) := by + funext j + cases j with + | inl j => exact hp j m + | inr j => simp [x] + simp only [Q,Polynomial.eval_add,Polynomial.eval_C,polynomial_substitute_eval,hx] at he + rw [pow_succ,c.mul_coord] + rw [Nat.cast_succ,add_comm (m:ℝ) 1] + linarith + exact aux i.val i.isLt + +def powerPolynomial (g : G) (i : Fin n) : ℝ[X] := (natpow_polynomial c g i).choose +lemma powerPolynomial_nat (g : G) (i : Fin n) (m : ℕ) : + (powerPolynomial c g i).eval (m : ℝ) = c.coord (g^m) i := + (natpow_polynomial c g i).choose_spec m + + +def realPower (g : G) (t : ℝ) : G := + c.coord.symm (fun i => (powerPolynomial c g i).eval t) + +lemma realPower_coord (g : G) (t : ℝ) (i : Fin n) : + c.coord (realPower c g t) i = (powerPolynomial c g i).eval t := by + simp [realPower] + +lemma realPower_nat (g : G) (m : ℕ) : realPower c g m = g^m := by + apply c.coord.injective + funext i + rw [realPower_coord,powerPolynomial_nat] + +@[simp] lemma realPower_zero (g : G) : realPower c g 0 = 1 := by + simpa using realPower_nat c g 0 +@[simp] lemma realPower_one (g : G) : realPower c g 1 = g := by + simpa using realPower_nat c g 1 + +lemma realPower_continuous (g : G) : Continuous (realPower c g) := + c.coord.symm.continuous.comp (continuous_pi fun i => (powerPolynomial c g i).continuous) + +end RationalLattice + +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +def evalPath (p : Fin n → ℝ[X]) (t : ℝ) : G := c.coord.symm (fun i => (p i).eval t) +def pathMul (p q : Fin n → ℝ[X]) (i : Fin n) : ℝ[X] := + p i + q i + MvPolynomial.eval₂ (C.comp (algebraMap ℚ ℝ)) + (Sum.elim (fun j => p ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => q ⟨j.val,lt_trans j.isLt i.isLt⟩)) (c.correction i) + +lemma evalPath_coord (p : Fin n → ℝ[X]) (t : ℝ) (i : Fin n) : + c.coord (evalPath c p t) i = (p i).eval t := by simp [evalPath] +lemma evalPath_C (g : G) (t : ℝ) : evalPath c (fun i => C (c.coord g i)) t = g := by + simp [evalPath] +lemma evalPath_comp (p : Fin n → ℝ[X]) (q : ℝ[X]) (t : ℝ) : + evalPath c (fun i => (p i).comp q) t = evalPath c p (q.eval t) := by + simp [evalPath,Polynomial.eval_comp] +lemma evalPath_mul (p q : Fin n → ℝ[X]) (t : ℝ) : + evalPath c (pathMul c p q) t = evalPath c p t * evalPath c q t := by + apply c.coord.injective + funext i + rw [evalPath_coord,c.mul_coord] + simp only [pathMul,Polynomial.eval_add,polynomial_substitute_eval,evalPath_coord] + congr 2 + funext a + cases a <;> rfl + +lemma evalPath_ext_nat {p q : Fin n → ℝ[X]} + (h : ∀ m : ℕ, evalPath c p (m:ℝ) = evalPath c q (m:ℝ)) : + ∀ t : ℝ, evalPath c p t = evalPath c q t := by + have hpq : p=q := by + funext i + apply Polynomial.eq_of_eval_nat_eq + intro m + have h' := congrArg (fun g => c.coord g i) (h m) + simpa [evalPath] using h' + rw [hpq] + exact fun _ => rfl + +lemma realPower_add_nat (g : G) (t : ℝ) (m : ℕ) : + realPower c g (t+m) = realPower c g t * g^m := by + let p := powerPolynomial c g + let q : Fin n → ℝ[X] := fun i => (p i).comp (X+C (m:ℝ)) + let r := pathMul c p (fun i => C (c.coord (g^m) i)) + have hq (s : ℝ) : evalPath c q s = realPower c g (s+m) := by + simp [q,realPower,evalPath,p] + have hr (s : ℝ) : evalPath c r s = realPower c g s * g^m := by + rw [evalPath_mul,evalPath_C] + rfl + have he : ∀ k : ℕ, evalPath c q k = evalPath c r k := by + intro k + rw [hq,hr,← Nat.cast_add,realPower_nat,realPower_nat,pow_add] + simpa only [hq,hr] using evalPath_ext_nat c he t + + + +theorem realPower_add (g : G) (s t : ℝ) : + realPower c g (s+t) = realPower c g s * realPower c g t := by + let p := powerPolynomial c g + let q : Fin n → ℝ[X] := fun i => (p i).comp (C s+X) + let r := pathMul c (fun i => C (c.coord (realPower c g s) i)) p + have hq (v : ℝ) : evalPath c q v = realPower c g (s+v) := by + simp [q,realPower,evalPath,p] + have hr (v : ℝ) : evalPath c r v = realPower c g s * realPower c g v := by + rw [evalPath_mul,evalPath_C] + rfl + have he : ∀ k : ℕ, evalPath c q k = evalPath c r k := by + intro k + rw [hq,hr,realPower_nat] + exact realPower_add_nat c g s k + simpa only [hq,hr] using evalPath_ext_nat c he t + +lemma realPower_neg (g : G) (s : ℝ) : realPower c g (-s) = (realPower c g s)⁻¹ := by + symm + apply inv_eq_of_mul_eq_one_right + rw [← realPower_add,add_neg_cancel,realPower_zero] + +end RationalLattice +end +end + + + +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +abbrev ParamPoly (n : ℕ) := Polynomial (MvPolynomial (Fin n) ℚ) + +def parameterEval (x : Fin n → ℝ) : MvPolynomial (Fin n) ℚ →+* ℝ := + MvPolynomial.eval₂Hom (algebraMap ℚ ℝ) x + +@[simp] lemma parameterEval_X (x : Fin n → ℝ) (i : Fin n) : + parameterEval x (MvPolynomial.X i) = x i := by simp [parameterEval] + +lemma universal_substitute_eval {ι : Type*} (P : MvPolynomial ι ℚ) + (p : ι → ParamPoly n) (x : Fin n → ℝ) (t : ℝ) : + (MvPolynomial.eval₂ (C.comp MvPolynomial.C) p P).eval₂ (parameterEval x) t = + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (fun i => (p i).eval₂ (parameterEval x) t) P := by + have h := MvPolynomial.eval₂_comp_left (Polynomial.eval₂RingHom (parameterEval x) t) + (C.comp MvPolynomial.C) p P + have hc : (Polynomial.eval₂RingHom (parameterEval x) t).comp (C.comp MvPolynomial.C) = + algebraMap ℚ ℝ := by + ext q + simp [parameterEval] + rw [hc] at h + exact h + + + +theorem universal_natpow_polynomial (i : Fin n) : + ∃ P : ParamPoly n, ∀ (g : G) (m : ℕ), + P.eval₂ (parameterEval (c.coord g)) (m:ℝ) = c.coord (g^m) i := by + have aux : ∀ l : ℕ, ∀ hl : l + intro hl + choose p hp using (fun j : Fin l => ih j.val j.isLt (lt_trans j.isLt hl)) + let x : (Fin l ⊕ Fin l) → ParamPoly n := Sum.elim p + (fun j => C (MvPolynomial.X ⟨j.val,lt_trans j.isLt hl⟩)) + let Q : ParamPoly n := C (MvPolynomial.X ⟨l,hl⟩) + + MvPolynomial.eval₂ (C.comp MvPolynomial.C) x (c.correction ⟨l,hl⟩) + obtain ⟨P,hP0,hP⟩ := Polynomial.exists_antidifference_algebra Q + refine ⟨P,?_⟩ + intro g m + induction m with + | zero => + have he := congrArg (parameterEval (c.coord g)) hP0 + simpa [Polynomial.eval₂_at_apply,← Polynomial.eval₂_at_apply, + c.one_coord] using he + | succ m hm => + have he := congrArg (Polynomial.eval₂ (parameterEval (c.coord g)) (m:ℝ)) hP + simp only [Polynomial.eval₂_sub,Polynomial.eval₂_comp,Polynomial.eval₂_add, + Polynomial.eval₂_one,Polynomial.eval₂_X] at he + have hx : (fun a => (x a).eval₂ (parameterEval (c.coord g)) (m:ℝ)) = + Sum.elim (fun j => c.coord (g^m) ⟨j.val,lt_trans j.isLt hl⟩) + (fun j => c.coord g ⟨j.val,lt_trans j.isLt hl⟩) := by + funext j + cases j with + | inl j => exact hp j g m + | inr j => simp [x,parameterEval] + simp only [Q,Polynomial.eval₂_add,Polynomial.eval₂_C,universal_substitute_eval,hx] at he + simp only [parameterEval_X] at he + rw [pow_succ,c.mul_coord] + rw [Nat.cast_succ,add_comm (m:ℝ) 1] + linarith + exact aux i.val i.isLt + +def universalPowerPolynomial (i : Fin n) : ParamPoly n := (universal_natpow_polynomial c i).choose +lemma universalPowerPolynomial_nat (g : G) (i : Fin n) (m : ℕ) : + (universalPowerPolynomial c i).eval₂ (parameterEval (c.coord g)) (m:ℝ) = + c.coord (g^m) i := (universal_natpow_polynomial c i).choose_spec g m + +theorem powerPolynomial_eq_universal (g : G) (i : Fin n) : + powerPolynomial c g i = (universalPowerPolynomial c i).map (parameterEval (c.coord g)) := by + apply Polynomial.eq_of_eval_nat_eq + intro m + rw [powerPolynomial_nat,Polynomial.eval_map,universalPowerPolynomial_nat] + +lemma realPower_coord_universal (g : G) (t : ℝ) (i : Fin n) : + c.coord (realPower c g t) i = + (universalPowerPolynomial c i).eval₂ (parameterEval (c.coord g)) t := by + rw [realPower_coord,powerPolynomial_eq_universal,Polynomial.eval_map] + +end RationalLattice + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice03.lean new file mode 100644 index 0000000000000000000000000000000000000000..da2401dbb301325abb0a16c2c32ca31eb6c28e12 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice03.lean @@ -0,0 +1,308 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +end +end + + + +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + + +lemma realPower_mem_of_coordinates (H : Subgroup G) (I : Set (Fin n)) + (hH : ∀ g : G, g ∈ H ↔ ∀ i ∈ I, c.coord g i = 0) + {g : G} (hg : g ∈ H) (t : ℝ) : realPower c g t ∈ H := by + apply (hH _).mpr + intro i hi + rw [realPower_coord] + have hp : powerPolynomial c g i = 0 := by + apply Polynomial.eq_of_eval_nat_eq + intro m + rw [powerPolynomial_nat,Polynomial.eval_zero] + exact (hH (g^m)).mp (H.pow_mem hg m) i hi + simp [hp] + +def characterPower (χ : G →* Multiplicative ℝ) (g : G) : ℝ →+ ℝ where + toFun t := Multiplicative.toAdd (χ (realPower c g t)) + map_zero' := by simp + map_add' s t := by rw [realPower_add,map_mul]; rfl + +lemma character_realPower (χ : G →* Multiplicative ℝ) (hχ : Continuous χ) + (g : G) (t : ℝ) : + Multiplicative.toAdd (χ (realPower c g t)) = t * Multiplicative.toAdd (χ g) := by + have hc : Continuous (characterPower c χ g) := hχ.comp (realPower_continuous c g) + have h := map_real_smul (characterPower c χ g) hc t 1 + simpa [characterPower] using h + +include c in + + +theorem character_kernel_pathConnected (χ : G →* Multiplicative ℝ) (hχ : Continuous χ) : + IsPathConnected (χ.ker : Set G) := by + refine ⟨1,χ.ker.one_mem,?_⟩ + intro g hg + let p : Path (1:G) g := + { toFun := fun t => realPower c g t + continuous_toFun := (realPower_continuous c g).comp continuous_subtype_val + source' := by simp + target' := by simp } + refine ⟨p,?_⟩ + intro t + change χ (realPower c g t) = 1 + apply Multiplicative.toAdd.injective + rw [character_realPower c χ hχ] + change χ g = 1 at hg + simp [hg] + + +theorem character_kernel_inter_pathConnected (χ : G →* Multiplicative ℝ) + (hχ : Continuous χ) (H : Subgroup G) (I : Set (Fin n)) + (hH : ∀ g : G, g ∈ H ↔ ∀ i ∈ I, c.coord g i = 0) : + IsPathConnected ((H ⊓ χ.ker : Subgroup G) : Set G) := by + refine ⟨1,(H ⊓ χ.ker).one_mem,?_⟩ + intro g hg + let p : Path (1:G) g := + { toFun := fun t => realPower c g t + continuous_toFun := (realPower_continuous c g).comp continuous_subtype_val + source' := by simp + target' := by simp } + refine ⟨p,?_⟩ + intro t + refine ⟨realPower_mem_of_coordinates c H I hH hg.1 t,?_⟩ + change χ (realPower c g t) = 1 + apply Multiplicative.toAdd.injective + rw [character_realPower c χ hχ] + have hg' : χ g = 1 := hg.2 + simp [hg'] + +end RationalLattice +end +end + + + +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +lemma parameterEval_continuous (P : MvPolynomial (Fin n) ℚ) : + Continuous (fun x : Fin n → ℝ => parameterEval x P) := by + simpa only [parameterEval,MvPolynomial.coe_eval₂Hom,MvPolynomial.eval₂_eq_eval_map] using + (MvPolynomial.continuous_eval (P.map (algebraMap ℚ ℝ))) + +lemma paramPoly_continuous (P : ParamPoly n) : + Continuous (fun v : (Fin n → ℝ) × ℝ => P.eval₂ (parameterEval v.1) v.2) := by + induction P using Polynomial.induction_on' with + | add p q hp hq => simpa only [Polynomial.eval₂_add,Pi.add_apply] using hp.fun_add hq + | monomial i a => + simpa only [Polynomial.eval₂_monomial,Pi.mul_apply,Pi.pow_apply,Function.comp_apply] using + ((parameterEval_continuous a).comp continuous_fst).fun_mul (continuous_snd.fun_pow i) + + + +theorem realPower_joint_continuous : Continuous (fun v : G × ℝ => realPower c v.1 v.2) := by + have h (v : G × ℝ) : realPower c v.1 v.2 = + c.coord.symm (fun i => (universalPowerPolynomial c i).eval₂ + (parameterEval (c.coord v.1)) v.2) := by + apply c.coord.injective + funext i + simp [realPower_coord_universal] + simp_rw [h] + apply c.coord.symm.continuous.comp + apply continuous_pi + intro i + exact (paramPoly_continuous _).comp ((c.coord.continuous.comp continuous_fst).prodMk continuous_snd) + +include c in + + +theorem contractible_of_realPower_closed (S : Set G) (h1 : (1:G) ∈ S) + (hS : ∀ g ∈ S, ∀ t : ℝ, realPower c g t ∈ S) : ContractibleSpace S := by + apply (contractible_iff_id_nullhomotopic S).mpr + refine ⟨⟨1,h1⟩,⟨?_⟩⟩ + refine + { toFun := fun v => ⟨realPower c v.2.val (1-(v.1:ℝ)),hS _ v.2.property _⟩ + continuous_toFun := ?_ + map_zero_left := ?_ + map_one_left := ?_ } + · apply Continuous.subtype_mk + exact (realPower_joint_continuous c).comp + ((continuous_subtype_val.comp continuous_snd).prodMk + (continuous_const.sub (continuous_subtype_val.comp continuous_fst))) + · intro g + apply Subtype.ext + simp + · intro g + apply Subtype.ext + simp + +include c in + +theorem character_kernel_contractible (χ : G →* Multiplicative ℝ) (hχ : Continuous χ) : + ContractibleSpace χ.ker := by + apply contractible_of_realPower_closed c (χ.ker:Set G) χ.ker.one_mem + intro g hg t + change χ (realPower c g t) = 1 + apply Multiplicative.toAdd.injective + rw [character_realPower c χ hχ] + change χ g = 1 at hg + simp [hg] + + + +theorem character_kernel_inter_contractible (χ : G →* Multiplicative ℝ) + (hχ : Continuous χ) (H : Subgroup G) (I : Set (Fin n)) + (hH : ∀ g : G, g ∈ H ↔ ∀ i ∈ I, c.coord g i = 0) : + ContractibleSpace ↥(H ⊓ χ.ker) := by + apply contractible_of_realPower_closed c ((H ⊓ χ.ker : Subgroup G):Set G) (H ⊓ χ.ker).one_mem + intro g hg t + refine ⟨realPower_mem_of_coordinates c H I hH hg.1 t,?_⟩ + change χ (realPower c g t) = 1 + apply Multiplicative.toAdd.injective + rw [character_realPower c χ hχ] + have hg' : χ g = 1 := hg.2 + simp [hg'] + +end RationalLattice + +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) (H : Subgroup G) (I : Set (Fin n)) +variable (hH : ∀ g : G, g ∈ H ↔ ∀ i ∈ I, c.coord g i = 0) + +def subgroupRealPower (g : H) (t : ℝ) : H := + ⟨realPower c g t,realPower_mem_of_coordinates c H I hH g.property t⟩ + +lemma subgroupRealPower_continuous (g : H) : Continuous (subgroupRealPower c H I hH g) := + (realPower_continuous c g).subtype_mk _ + +lemma subgroupRealPower_zero (g : H) : subgroupRealPower c H I hH g 0 = 1 := by + apply Subtype.ext + exact realPower_zero c g +lemma subgroupRealPower_one (g : H) : subgroupRealPower c H I hH g 1 = g := by + apply Subtype.ext + exact realPower_one c g +lemma subgroupRealPower_add (g : H) (s t : ℝ) : + subgroupRealPower c H I hH g (s+t) = + subgroupRealPower c H I hH g s * subgroupRealPower c H I hH g t := by + apply Subtype.ext + exact realPower_add c g s t + +def subgroupCharacterPower (χ : H →* Multiplicative ℝ) (g : H) : ℝ →+ ℝ where + toFun t := Multiplicative.toAdd (χ (subgroupRealPower c H I hH g t)) + map_zero' := by rw [subgroupRealPower_zero,map_one]; rfl + map_add' s t := by rw [subgroupRealPower_add,map_mul]; rfl + +lemma character_subgroupRealPower (χ : H →* Multiplicative ℝ) (hχ : Continuous χ) + (g : H) (t : ℝ) : + Multiplicative.toAdd (χ (subgroupRealPower c H I hH g t)) = + t * Multiplicative.toAdd (χ g) := by + have hc : Continuous (subgroupCharacterPower c H I hH χ g) := + hχ.comp (subgroupRealPower_continuous c H I hH g) + have he := map_real_smul (subgroupCharacterPower c H I hH χ g) hc t 1 + simpa [subgroupCharacterPower,subgroupRealPower_one] using he + +include hH in +lemma realPower_mem_mapped_kernel (χ : H →* Multiplicative ℝ) (hχ : Continuous χ) + {g : G} (hg : g ∈ χ.ker.map H.subtype) (t : ℝ) : + realPower c g t ∈ χ.ker.map H.subtype := by + obtain ⟨u,hu,rfl⟩ := hg + refine ⟨subgroupRealPower c H I hH u t,?_,rfl⟩ + change χ (subgroupRealPower c H I hH u t) = 1 + apply Multiplicative.toAdd.injective + rw [character_subgroupRealPower c H I hH χ hχ] + change χ u = 1 at hu + simp [hu] + +include hH in + + +theorem lower_kernel_inter_contractible (χ : H →* Multiplicative ℝ) + (hχ : Continuous χ) (K : Subgroup G) (J : Set (Fin n)) + (hK : ∀ g : G, g ∈ K ↔ ∀ i ∈ J, c.coord g i = 0) : + ContractibleSpace ↥(K ⊓ χ.ker.map H.subtype) := by + apply contractible_of_realPower_closed c + ((K ⊓ χ.ker.map H.subtype : Subgroup G):Set G) (K ⊓ χ.ker.map H.subtype).one_mem + intro g hg t + exact ⟨realPower_mem_of_coordinates c K J hK hg.1 t, + realPower_mem_mapped_kernel c H I hH χ hχ hg.2 t⟩ + +end RationalLattice +end +end + + + +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace TriangularDenominators +variable {G : Type*} [Group G] {n : ℕ} +lemma substitute_eval {ι : Type*} (P : MvPolynomial ι ℚ) (p : ι → ℚ[X]) (t : ℚ) : + (MvPolynomial.eval₂ C p P).eval t = MvPolynomial.eval (fun i => (p i).eval t) P := by + have h := MvPolynomial.eval₂_comp_left (Polynomial.evalRingHom t) C p P + have hc : (Polynomial.evalRingHom t).comp C = RingHom.id ℚ := by ext; simp + rw [hc] at h + exact h + + +theorem natpow_polynomial (c : Coordinates G n) (g : G) (i : Fin n) : + ∃ p : ℚ[X], ∀ m : ℕ, p.eval (m:ℚ) = c.coord (g^m) i := by + have aux : ∀ l : ℕ, ∀ hl : l + intro hl + choose p hp using (fun j : Fin l => ih j.val j.isLt (lt_trans j.isLt hl)) + let x : (Fin l ⊕ Fin l) → ℚ[X] := Sum.elim p + (fun j => C (c.coord g ⟨j.val,lt_trans j.isLt hl⟩)) + let Q : ℚ[X] := C (c.coord g ⟨l,hl⟩) + + MvPolynomial.eval₂ C x (c.correction ⟨l,hl⟩) + obtain ⟨P,hP0,hP⟩ := Polynomial.exists_antidifference Q + refine ⟨P,?_⟩ + intro m + induction m with + | zero => simpa [c.one_coord] using hP0 + | succ m hm => + have he := congrArg (Polynomial.eval (m : ℚ)) hP + simp only [Polynomial.eval_sub,Polynomial.eval_comp,Polynomial.eval_add, + Polynomial.eval_one,Polynomial.eval_X] at he + have hx : (fun a => (x a).eval (m : ℚ)) = + Sum.elim (fun j => c.coord (g^m) ⟨j.val,lt_trans j.isLt hl⟩) + (fun j => c.coord g ⟨j.val,lt_trans j.isLt hl⟩) := by + funext j + cases j with + | inl j => exact hp j m + | inr j => simp [x] + simp only [Q,Polynomial.eval_add,Polynomial.eval_C,substitute_eval,hx] at he + rw [pow_succ,c.mul_coord] + rw [Nat.cast_succ,add_comm (m:ℚ) 1] + linarith + exact aux i.val i.isLt +end TriangularDenominators + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice04.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice04.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab69bbcf13e3642a93aa64f6edf968fe8151a80c --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice04.lean @@ -0,0 +1,367 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice03 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +theorem powerPolynomial_rational {g : G} (hg : IsRational c g) (i : Fin n) : + ∃ p : ℚ[X], powerPolynomial c g i = p.map (algebraMap ℚ ℝ) := by + let h : rationalSubgroup c := ⟨g,hg⟩ + obtain ⟨p,hp⟩ := TriangularDenominators.natpow_polynomial (rationalCoordinates c) h i + refine ⟨p,Polynomial.eq_of_eval_nat_eq ?_⟩ + intro m + rw [powerPolynomial_nat] + have he := congrArg (fun q : ℚ => (q:ℝ)) (hp m) + change ((p.eval (m:ℚ) : ℚ) : ℝ) = (qcoord c (h^m) i : ℝ) at he + rw [qcoord_spec] at he + change ((p.eval (m:ℚ) : ℚ) : ℝ) = c.coord (g^m) i at he + rw [← he] + simpa using (Polynomial.eval_map_apply (p:=p) (algebraMap ℚ ℝ) (m:ℚ)).symm + + + +theorem realPower_rational {g : G} (hg : IsRational c g) (t : ℚ) : + IsRational c (realPower c g t) := by + intro i + obtain ⟨p,hp⟩ := powerPolynomial_rational c hg i + refine ⟨p.eval t,?_⟩ + rw [realPower_coord,hp] + exact (Polynomial.eval_map_apply (p:=p) (algebraMap ℚ ℝ) t).symm + +end RationalLattice +end +end + + + +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +lemma coord_mul_of_left_zero (g h : G) (i : Fin n) + (hg : ∀ j : Fin n, j < i → c.coord g j = 0) : + c.coord (g*h) i = c.coord g i + c.coord h i := by + have he : (Sum.elim (fun j : Fin i.val => c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) = + (Sum.elim (fun j : Fin i.val => c.coord 1 ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) := by + funext a + cases a with + | inl j => simp only [Sum.elim_inl]; rw [hg _ j.isLt,c.one_coord] + | inr j => rfl + have hm := c.mul_coord 1 h i + rw [one_mul,c.one_coord,zero_add] at hm + rw [c.mul_coord,he] + linarith + +lemma coord_mul_of_right_zero (g h : G) (i : Fin n) + (hh : ∀ j : Fin n, j < i → c.coord h j = 0) : + c.coord (g*h) i = c.coord g i + c.coord h i := by + have he : (Sum.elim (fun j : Fin i.val => c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) = + (Sum.elim (fun j : Fin i.val => c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord 1 ⟨j.val,lt_trans j.isLt i.isLt⟩)) := by + funext a + cases a with + | inl j => rfl + | inr j => simp only [Sum.elim_inr]; rw [hh _ j.isLt,c.one_coord] + have hm := c.mul_coord g 1 i + rw [mul_one,c.one_coord,add_zero] at hm + rw [c.mul_coord,he] + linarith + +lemma realPower_coord_of_lower_zero (g : G) (i : Fin n) + (hg : ∀ j : Fin n, j < i → c.coord g j = 0) (t : ℝ) : + c.coord (realPower c g t) i = t * c.coord g i := by + have hp : powerPolynomial c g i = X * C (c.coord g i) := by + apply Polynomial.eq_of_eval_nat_eq + intro m + rw [powerPolynomial_nat] + simp only [Polynomial.eval_mul,Polynomial.eval_X,Polynomial.eval_C] + induction m with + | zero => simp [c.one_coord] + | succ m ih => rw [pow_succ,coord_mul_of_right_zero c _ _ i hg,ih]; push_cast; ring + rw [realPower_coord,hp] + simp only [Polynomial.eval_mul,Polynomial.eval_X,Polynomial.eval_C] + +def basisElement (i : Fin n) : G := c.coord.symm (Pi.single i 1) +def basisFlow (i : Fin n) (t : ℝ) : G := realPower c (basisElement c i) t + +lemma basisFlow_continuous (i : Fin n) : Continuous (basisFlow c i) := + realPower_continuous c _ +@[simp] lemma basisFlow_zero (i : Fin n) : basisFlow c i 0 = 1 := realPower_zero c _ +lemma basisFlow_add (i : Fin n) (s t : ℝ) : + basisFlow c i (s+t) = basisFlow c i s * basisFlow c i t := realPower_add c _ _ _ +lemma basisFlow_neg (i : Fin n) (t : ℝ) : basisFlow c i (-t) = (basisFlow c i t)⁻¹ := + realPower_neg c _ _ + +lemma basisFlow_coord (i j : Fin n) (hji : j ≤ i) (t : ℝ) : + c.coord (basisFlow c i t) j = if j=i then t else 0 := by + classical + have hzero (k : Fin n) (hk : k < j) : c.coord (basisElement c i) k = 0 := by + have hki : k ≠ i := ne_of_lt (lt_of_lt_of_le hk hji) + simp [basisElement,hki] + change c.coord (realPower c (basisElement c i) t) j = _ + rw [realPower_coord_of_lower_zero c _ j hzero] + simp only [basisElement,Homeomorph.apply_symm_apply,Pi.single_apply] + split_ifs <;> simp_all + + +def peel (g : G) : ℕ → G + | 0 => g + | k+1 => if h : k peel c g k) := by + induction k with + | zero => exact continuous_id + | succ k ih => + simp only [peel] + split_ifs with h + · exact ((basisFlow_continuous c _).comp ((continuous_apply _).comp + (c.coord.continuous.comp ih)).neg).mul ih + · exact ih + +lemma peel_zero_coordinates (g : G) (k : ℕ) : + ∀ i : Fin n, i.val < k → c.coord (peel c g k) i = 0 := by + induction k with + | zero => intro i hi; omega + | succ k ih => + intro i hi + by_cases hk : k by have := congrArg Fin.val h; change j.val < i.val at hj; dsimp at this; omega])] + by_cases hik : i.val < k + · rw [ih i hik,basisFlow_coord c _ i (show i.val ≤ k from by omega)] + simp [show i ≠ (⟨k,hk⟩:Fin n) from fun h => by have := congrArg Fin.val h; dsimp at this; omega] + · have he : i = (⟨k,hk⟩:Fin n) := Fin.ext (show i.val = k from by omega) + subst i + rw [basisFlow_coord c _ _ le_rfl] + simp + · rw [peel,dite_eq_right hk] + exact ih i (by omega) + +lemma peel_dimension (g : G) : peel c g n = 1 := by + apply c.coord.injective + funext i + rw [peel_zero_coordinates c g n i i.isLt,c.one_coord] + +def expCoordinates (g : G) (i : Fin n) : ℝ := c.coord (peel c g i.val) i + +def tailProduct (x : Fin n → ℝ) (k : ℕ) : G := + ((List.ofFn (fun i => basisFlow c i (x i))).drop k).prod + +def expProduct (x : Fin n → ℝ) : G := tailProduct c x 0 + +lemma tailProduct_dimension (x : Fin n → ℝ) : tailProduct c x n = 1 := by + have h := List.drop_length (l := List.ofFn (fun i => basisFlow c i (x i))) + simp only [List.length_ofFn] at h + simp only [tailProduct,h,List.prod_nil] + +lemma tailProduct_step (x : Fin n → ℝ) (k : ℕ) (hk : k intro i hi; rw [tailProduct_dimension,c.one_coord] + | of_succ k hk ih => + intro i hi + rw [tailProduct_step c x k hk,coord_mul_of_left_zero c _ _ i (by + intro j hj + rw [basisFlow_coord c _ j (show j.val ≤ k from by change j.val < i.val at hj; omega)] + rw [ite_eq_right (fun h => by have := congrArg Fin.val h; change j.val < i.val at hj; dsimp at this; omega)])] + rw [basisFlow_coord c _ i (show i.val ≤ k from by omega),ih i (by omega)] + rw [ite_eq_right (fun h => by have := congrArg Fin.val h; dsimp at this; omega),zero_add] + +lemma tailProduct_coord (x : Fin n → ℝ) (i : Fin n) : + c.coord (tailProduct c x i.val) i = x i := by + rw [tailProduct_step c x i.val i.isLt,coord_mul_of_left_zero c _ _ i (by + intro j hj + rw [basisFlow_coord c i j (le_of_lt hj),ite_eq_right (ne_of_lt hj)])] + rw [basisFlow_coord c i i le_rfl,ite_eq_left rfl, + tailProduct_lower c x (i.val+1) i.isLt i (Nat.lt_succ_self _),add_zero] + +lemma peel_expProduct (x : Fin n → ℝ) (k : ℕ) (hk : k ≤ n) : + peel c (expProduct c x) k = tailProduct c x k := by + induction k with + | zero => rfl + | succ k ih => + have hkn : k rw [tailProduct_dimension,peel_dimension] + | of_succ k hk ih => + rw [tailProduct_step c _ k hk,ih,expCoordinates,peel,dite_eq_left hk,basisFlow_neg] + exact mul_inv_cancel_left _ _ + +lemma expProduct_expCoordinates (g : G) : expProduct c (expCoordinates c g) = g := by + simpa only [expProduct,peel] using tailProduct_expCoordinates c g 0 (Nat.zero_le n) + +lemma expCoordinates_continuous [IsTopologicalGroup G] : Continuous (expCoordinates c) := by + apply continuous_pi + intro i + exact (continuous_apply i).comp (c.coord.continuous.comp (peel_continuous c i.val)) + +lemma expProduct_continuous [IsTopologicalGroup G] : Continuous (expProduct c) := by + change Continuous (fun x : Fin n → ℝ => (List.ofFn (fun i => basisFlow c i (x i))).prod) + simp only [List.ofFn_eq_map] + exact continuous_list_prod _ (fun i _ => (basisFlow_continuous c i).comp (continuous_apply i)) + + + +def secondKindHomeomorph [IsTopologicalGroup G] : G ≃ₜ (Fin n → ℝ) where + toFun := expCoordinates c + invFun := expProduct c + left_inv := expProduct_expCoordinates c + right_inv := expCoordinates_expProduct c + continuous_toFun := expCoordinates_continuous c + continuous_invFun := expProduct_continuous c + +end RationalLattice +end +end + + + +section +noncomputable section +namespace MalcevPrefixQuotient +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n r : ℕ} +variable (c : RealCoordinates G n) (hr : r ≤ n) + +include hr in + + +lemma prefix_eq_iff (g h : G) : + (∀ i : Fin n, i.val < r → c.coord g i = c.coord h i) ↔ + (∀ i : Fin n, i.val < r → c.coord (g⁻¹*h) i = 0) := by + constructor + · intro he i hi + have haux : ∀ m : ℕ, ∀ hm : m < r, c.coord (g⁻¹*h) ⟨m,lt_of_lt_of_le hm hr⟩ = 0 := by + intro m + induction m using Nat.strong_induction_on with + | h m ih => + intro hm + let j : Fin n := ⟨m,lt_of_lt_of_le hm hr⟩ + have hd : ∀ u : Fin n, u < j → c.coord (g⁻¹*h) u = 0 := by + intro u hu + exact ih u.val hu (lt_trans hu hm) + have hc := coord_mul_of_right_zero c g (g⁻¹*h) j hd + rw [mul_inv_cancel_left] at hc + have he' := he j hm + linarith + exact haux i.val hi + · intro hd i hi + have hc := coord_mul_of_right_zero c g (g⁻¹*h) i (fun u hu => hd u (lt_trans hu hi)) + rw [mul_inv_cancel_left,hd i hi,add_zero] at hc + exact hc.symm + +variable (N : Subgroup G) +variable (hN : ∀ g : G, g ∈ N ↔ ∀ i : Fin n, i.val < r → c.coord g i = 0) +include hr hN in +lemma eq_coset_iff (g h : G) : + (QuotientGroup.mk g : G ⧸ N) = QuotientGroup.mk h ↔ + ∀ i : Fin n, i.val < r → c.coord g i = c.coord h i := by + rw [QuotientGroup.eq,hN] + exact (prefix_eq_iff c hr g h).symm + +def embed (i : Fin r) : Fin n := ⟨i.val,lt_of_lt_of_le i.isLt hr⟩ +def lift (x : Fin r → ℝ) (i : Fin n) : ℝ := if h : i.val < r then x ⟨i.val,h⟩ else 0 +@[simp] lemma lift_embed (x : Fin r → ℝ) (i : Fin r) : lift x (embed hr i) = x i := by + simp [lift,embed,i.isLt] +lemma lift_continuous : Continuous (lift (n:=n) (r:=r)) := by + apply continuous_pi + intro i + unfold lift + split_ifs + · exact continuous_apply _ + · exact continuous_const + +def coordinates (x : G ⧸ N) (i : Fin r) : ℝ := Quotient.lift (fun g : G => c.coord g (embed hr i)) + (by + intro g h he + exact ((prefix_eq_iff c hr g h).mpr ((hN _).mp (QuotientGroup.leftRel_apply.mp he))) (embed hr i) i.isLt) x + +@[simp] lemma coordinates_mk (g : G) (i : Fin r) : + coordinates c hr N hN (QuotientGroup.mk g) i = c.coord g (embed hr i) := rfl + +def represent (x : Fin r → ℝ) : G := c.coord.symm (lift x) +def rebuild (x : Fin r → ℝ) : G ⧸ N := QuotientGroup.mk (represent c x) + +lemma coordinates_rebuild (x : Fin r → ℝ) : coordinates c hr N hN (rebuild c N x) = x := by + funext i + simp [rebuild,represent,coordinates_mk] +lemma rebuild_coordinates (x : G ⧸ N) : rebuild c N (coordinates c hr N hN x) = x := by + induction x using Quotient.inductionOn with | h g => + apply (eq_coset_iff c hr N hN _ _).mpr + intro i hi + simp [represent,lift,hi,embed] +lemma coordinates_continuous : Continuous (coordinates c hr N hN) := by + rw [(QuotientGroup.isQuotientMap_mk N).continuous_iff] + apply continuous_pi + intro i + change Continuous (fun g : G => c.coord g (embed hr i)) + exact (continuous_apply (embed hr i)).comp c.coord.continuous +lemma rebuild_continuous : Continuous (rebuild c (r:=r) N) := + QuotientGroup.continuous_mk.comp (c.coord.symm.continuous.comp lift_continuous) + +def homeomorph : (G ⧸ N) ≃ₜ (Fin r → ℝ) where + toFun := coordinates c hr N hN + invFun := rebuild c N + left_inv := rebuild_coordinates c hr N hN + right_inv := coordinates_rebuild c hr N hN + continuous_toFun := coordinates_continuous c hr N hN + continuous_invFun := rebuild_continuous c N + +variable [N.Normal] + + + +def quotientChart : RealCoordinates (G ⧸ N) r where + coord := homeomorph c hr N hN + one_coord i := c.one_coord _ + correction i := c.correction (embed hr i) + mul_coord g h i := by + induction g using Quotient.inductionOn with | h g => + induction h using Quotient.inductionOn with | h h => + exact c.mul_coord g h (embed hr i) + +end MalcevPrefixQuotient + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice05.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice05.lean new file mode 100644 index 0000000000000000000000000000000000000000..3739eac019226aaa25be6a003543a4e442c4d53f --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice05.lean @@ -0,0 +1,443 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.PairTail01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace RationalLattice +open RationalPolynomialMap +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) {σ : Type*} + +def IsPolynomialMap (f : (σ → ℝ) → G) : Prop := + ∀ i, RationalPolynomialMap.IsPolynomial (fun x => c.coord (f x) i) + +lemma polynomialMap_const {g : G} (hg : IsRational c g) : + IsPolynomialMap c (fun _ : σ → ℝ => g) := by + intro i + obtain ⟨q,hq⟩ := hg i + simpa only [← hq] using RationalPolynomialMap.const (σ:=σ) q + +lemma polynomialMap_one : IsPolynomialMap c (fun _ : σ → ℝ => (1:G)) := + polynomialMap_const c (rational_one c) + +lemma polynomialMap_mul {f g : (σ → ℝ) → G} (hf : IsPolynomialMap c f) + (hg : IsPolynomialMap c g) : IsPolynomialMap c (fun x => f x*g x) := by + intro i + have hc : IsPolynomial (fun x => MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j : Fin i.val => c.coord (f x) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord (g x) ⟨j.val,lt_trans j.isLt i.isLt⟩)) (c.correction i)) := by + apply RationalPolynomialMap.eval + intro j + cases j with + | inl j => exact hf _ + | inr j => exact hg _ + simpa only [c.mul_coord] using RationalPolynomialMap.add (RationalPolynomialMap.add (hf i) (hg i)) hc + +lemma polynomialMap_basisFlow (i : Fin n) {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) : + IsPolynomialMap c (fun x => basisFlow c i (f x)) := by + intro j + obtain ⟨p,hp⟩ := powerPolynomial_rational c (g := basisElement c i) (by + intro k + classical + refine ⟨if k=i then 1 else 0,?_⟩ + simp only [basisElement,Homeomorph.apply_symm_apply,Pi.single_apply] + split_ifs <;> simp) j + change IsPolynomial (fun x => c.coord (realPower c (basisElement c i) (f x)) j) + simpa only [realPower_coord,hp,Polynomial.eval_map] using polynomial_eval p hf + +lemma polynomialMap_peel {f : (σ → ℝ) → G} (hf : IsPolynomialMap c f) (k : ℕ) : + IsPolynomialMap c (fun x => peel c (f x) k) := by + induction k with + | zero => exact hf + | succ k ih => + simp only [peel] + split_ifs with hk + · exact polynomialMap_mul c + (polynomialMap_basisFlow c ⟨k,hk⟩ (RationalPolynomialMap.neg (ih _))) ih + · exact ih + +lemma polynomial_expCoordinates {f : (σ → ℝ) → G} (hf : IsPolynomialMap c f) (i : Fin n) : + IsPolynomial (fun x => expCoordinates c (f x) i) := polynomialMap_peel c hf i.val i + +lemma polynomialMap_expProduct {f : (σ → ℝ) → (Fin n → ℝ)} + (hf : ∀ i, IsPolynomial (fun x => f x i)) : IsPolynomialMap c (fun x => expProduct c (f x)) := by + change IsPolynomialMap c (fun x => (List.ofFn (fun i => basisFlow c i (f x i))).prod) + simp only [List.ofFn_eq_map] + generalize List.finRange n = l + induction l with + | nil => exact polynomialMap_one c + | cons i l ih => + simp only [List.map_cons,List.prod_cons] + exact polynomialMap_mul c (polynomialMap_basisFlow c i (hf i)) ih + +end RationalLattice +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace MalcevCharacters +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) + +omit [IsTopologicalGroup G] in +@[simp] lemma coord_axis (i : Fin n) (t : ℝ) : c.coord (axis c i t) = Pi.single i t := + c.coord.apply_symm_apply _ + +omit [IsTopologicalGroup G] in +@[simp] lemma axis_zero (i : Fin n) : axis c i 0 = 1 := by + apply c.coord.injective + ext j + simp [c.one_coord] + +omit [IsTopologicalGroup G] in +lemma axis_continuous (i : Fin n) : Continuous (axis c i) := by + apply c.coord.symm.continuous.comp + exact continuous_pi (fun j => by + by_cases h : j = i + · subst j + change Continuous (fun t : ℝ => (Pi.single i t : Fin n → ℝ) i) + simp only [Pi.single_eq_same] + exact continuous_id + · simpa [Pi.single_apply,h] using (continuous_const : Continuous (fun _ : ℝ => (0 : ℝ)))) + + + +variable (hsk : SecondKind c) (χ : G →* Multiplicative ℝ) +include hsk + +def axisCharacter (i : Fin n) : ℝ →+ ℝ where + toFun t := Multiplicative.toAdd (χ (axis c i t)) + map_zero' := by simp + map_add' s t := by + change Multiplicative.toAdd (χ (axis c i (s+t))) = _ + rw [hsk.axis_add, map_mul] + rfl + +omit [IsTopologicalGroup G] in +lemma axisCharacter_continuous (hχ : Continuous χ) (i : Fin n) : + Continuous (axisCharacter c hsk χ i) := hχ.comp (axis_continuous c i) + +omit [IsTopologicalGroup G] in +lemma character_axis (hχ : Continuous χ) (i : Fin n) (t : ℝ) : + Multiplicative.toAdd (χ (axis c i t)) = t * Multiplicative.toAdd (χ (axis c i 1)) := by + change axisCharacter c hsk χ i t = t * axisCharacter c hsk χ i 1 + have h := map_real_smul (axisCharacter c hsk χ i) (axisCharacter_continuous c hsk χ hχ i) t 1 + simpa using h + + + +omit [IsTopologicalGroup G] in +theorem character_coordinates (hχ : Continuous χ) (g : G) : + Multiplicative.toAdd (χ g) = + ∑ i, c.coord g i * Multiplicative.toAdd (χ (axis c i 1)) := by + conv_lhs => rw [hsk.ordered g] + rw [map_list_prod, List.map_ofFn] + change Multiplicative.toAdd ((List.ofFn fun i => χ (axis c i (c.coord g i))).prod) = _ + simp only [toAdd_list_sum, List.map_ofFn, List.sum_ofFn] + apply Finset.sum_congr rfl + intro i _ + exact character_axis c hsk χ hχ i _ + +variable (Γ : Subgroup G) +variable (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) + +omit hsk [IsTopologicalGroup G] in +include hΓ in +lemma axis_one_mem (i : Fin n) : axis c i 1 ∈ Γ := by + classical + apply (hΓ _).mpr + intro j + by_cases h : j = i + · subst j + exact ⟨1,by simp⟩ + · exact ⟨0,by simp [h]⟩ + +include hΓ in + +omit [IsTopologicalGroup G] in +theorem integer_character_coordinates (hχ : Continuous χ) + (hz : ∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) : + ∃ k : Fin n → ℤ, ∀ g : G, Multiplicative.toAdd (χ g) = ∑ i, c.coord g i * (k i : ℝ) := by + choose k hk using (fun i => hz _ (axis_one_mem c Γ hΓ i)) + refine ⟨k,fun g => ?_⟩ + rw [character_coordinates c hsk χ hχ g] + simp_rw [hk] + + +def coordinateForm (a : Fin n → ℝ) : (Fin n → ℝ) →ₗ[ℝ] ℝ where + toFun x := ∑ i, x i * a i + map_add' x y := by simp [add_mul,Finset.sum_add_distrib] + map_smul' r x := by simp [Finset.mul_sum,mul_assoc] + +omit [IsTopologicalGroup G] in +lemma kernel_eq_image (hχ : Continuous χ) : + (χ.ker : Set G) = c.coord.symm '' + ((coordinateForm (fun i => Multiplicative.toAdd (χ (axis c i 1)))).ker : Set (Fin n → ℝ)) := by + ext g + constructor + · intro hg + refine ⟨c.coord g,?_,c.coord.symm_apply_apply g⟩ + change (∑ i, c.coord g i * Multiplicative.toAdd (χ (axis c i 1))) = 0 + rw [← character_coordinates c hsk χ hχ g] + change χ g = 1 at hg + rw [hg] + rfl + · rintro ⟨x,hx,rfl⟩ + change χ (c.coord.symm x) = 1 + apply Multiplicative.toAdd.injective + rw [character_coordinates c hsk χ hχ] + simpa [coordinateForm] using hx + + + +omit [IsTopologicalGroup G] in +theorem kernel_connected (hχ : Continuous χ) : IsConnected (χ.ker : Set G) := by + rw [kernel_eq_image c hsk χ hχ] + exact ((coordinateForm (fun i => Multiplicative.toAdd (χ (axis c i 1)))).ker.convex.isConnected + ⟨0,by simp⟩).image _ c.coord.symm.continuous.continuousOn + +end MalcevCharacters +end +end + + + +section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +def prefixProduct (x : Fin n → ℝ) (k : ℕ) : G := + ((List.ofFn (fun i => basisFlow c i (x i))).take k).prod + +lemma prefix_mul_tail (x : Fin n → ℝ) (k : ℕ) : + prefixProduct c x k * tailProduct c x k = expProduct c x := + List.prod_take_mul_prod_drop _ _ + +lemma expProduct_coord (x : Fin n → ℝ) (i : Fin n) : + c.coord (expProduct c x) i = c.coord (prefixProduct c x i.val) i + x i := by + rw [← prefix_mul_tail c x i.val] + rw [coord_mul_of_right_zero c _ _ i (fun j hj => + tailProduct_lower c x i.val (Nat.le_of_lt i.isLt) j hj),tailProduct_coord] + +lemma prefixProduct_eq (x y : Fin n → ℝ) (k : ℕ) + (h : ∀ i : Fin n, i.val < k → x i = y i) : prefixProduct c x k = prefixProduct c y k := by + apply congrArg List.prod + apply List.ext_getElem + · simp only [List.length_take,List.length_ofFn] + · intro i h1 h2 + simp only [List.getElem_take,List.getElem_ofFn] + congr 1 + apply h + simp only [List.length_take,List.length_ofFn] at h1 + exact lt_of_lt_of_le h1 (min_le_left _ _) + +lemma expProduct_coord_sub (x y : Fin n → ℝ) (i : Fin n) + (h : ∀ j : Fin n, j < i → x j = y j) : + c.coord (expProduct c x) i - c.coord (expProduct c y) i = x i-y i := by + rw [expProduct_coord,expProduct_coord,prefixProduct_eq c x y i.val h] + ring + +lemma expProduct_coord_eq (x y : Fin n → ℝ) (i : Fin n) + (h : ∀ j : Fin n, j ≤ i → x j = y j) : + c.coord (expProduct c x) i = c.coord (expProduct c y) i := by + have he := expProduct_coord_sub c x y i (fun j hj => h j (le_of_lt hj)) + rw [h i le_rfl,sub_self] at he + linarith + +lemma expCoordinates_prefix_eq (g h : G) (i : Fin n) + (he : ∀ j : Fin n, j ≤ i → c.coord g j = c.coord h j) : + expCoordinates c g i = expCoordinates c h i := by + have aux : ∀ k : ℕ, ∀ hk : k + intro hk he + have hl : ∀ j : Fin n, j < (⟨k,hk⟩:Fin n) → expCoordinates c g j = expCoordinates c h j := by + intro j hj + apply ih j.val hj j.isLt + intro a ha + exact he a (by change j.val < k at hj; omega) + have hs := expProduct_coord_sub c (expCoordinates c g) (expCoordinates c h) ⟨k,hk⟩ hl + rw [expProduct_expCoordinates,expProduct_expCoordinates,he _ le_rfl,sub_self] at hs + linarith + exact aux i.val i.isLt he + +lemma expCoordinates_coord_sub (g h : G) (i : Fin n) + (he : ∀ j : Fin n, j < i → c.coord g j = c.coord h j) : + expCoordinates c g i - expCoordinates c h i = c.coord g i - c.coord h i := by + have hl : ∀ j : Fin n, j < i → expCoordinates c g j = expCoordinates c h j := by + intro j hj + exact expCoordinates_prefix_eq c g h j (fun a ha => he a (lt_of_le_of_lt ha hj)) + have hs := expProduct_coord_sub c (expCoordinates c g) (expCoordinates c h) i hl + rw [expProduct_expCoordinates,expProduct_expCoordinates] at hs + exact hs.symm + +def lowerExtend (i : Fin n) (x : Fin i.val → ℝ) (j : Fin n) : ℝ := + if h : j.val< i.val then x ⟨j.val,h⟩ else 0 + +lemma expCoordinates_mul_difference (x y : Fin n → ℝ) (i : Fin n) : + expCoordinates c (expProduct c x * expProduct c y) i = x i + y i + + expCoordinates c (expProduct c (lowerExtend i (fun j => x ⟨j.val,lt_trans j.isLt i.isLt⟩)) * + expProduct c (lowerExtend i (fun j => y ⟨j.val,lt_trans j.isLt i.isLt⟩))) i := by + let x0 := lowerExtend i (fun j => x ⟨j.val,lt_trans j.isLt i.isLt⟩) + let y0 := lowerExtend i (fun j => y ⟨j.val,lt_trans j.isLt i.isLt⟩) + have hx : ∀ j : Fin n, j< i → x j = x0 j := by intro j hj; simp [x0,lowerExtend,hj] + have hy : ∀ j : Fin n, j< i → y j = y0 j := by intro j hj; simp [y0,lowerExtend,hj] + have cx : ∀ j : Fin n, j< i → c.coord (expProduct c x) j = c.coord (expProduct c x0) j := by + intro j hj + exact expProduct_coord_eq c x x0 j (fun a ha => hx a (lt_of_le_of_lt ha hj)) + have cy : ∀ j : Fin n, j< i → c.coord (expProduct c y) j = c.coord (expProduct c y0) j := by + intro j hj + exact expProduct_coord_eq c y y0 j (fun a ha => hy a (lt_of_le_of_lt ha hj)) + have cm : ∀ j : Fin n, j< i → + c.coord (expProduct c x * expProduct c y) j = c.coord (expProduct c x0 * expProduct c y0) j := by + intro j hj + rw [c.mul_coord,c.mul_coord,cx j hj,cy j hj] + congr 2 + funext a + cases a with + | inl a => exact cx _ (lt_trans a.isLt hj) + | inr a => exact cy _ (lt_trans a.isLt hj) + have hcorr : MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j : Fin i.val => c.coord (expProduct c x) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord (expProduct c y) ⟨j.val,lt_trans j.isLt i.isLt⟩)) (c.correction i) = + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j : Fin i.val => c.coord (expProduct c x0) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord (expProduct c y0) ⟨j.val,lt_trans j.isLt i.isLt⟩)) (c.correction i) := by + congr 1 + funext a + cases a with + | inl a => exact cx _ a.isLt + | inr a => exact cy _ a.isLt + have hs := expCoordinates_coord_sub c _ _ i cm + rw [c.mul_coord,c.mul_coord,hcorr] at hs + have hdx := expProduct_coord_sub c x x0 i hx + have hdy := expProduct_coord_sub c y y0 i hy + have hx0 : x0 i = 0 := by simp [x0,lowerExtend] + have hy0 : y0 i = 0 := by simp [y0,lowerExtend] + rw [hx0] at hdx + rw [hy0] at hdy + change expCoordinates c (expProduct c x * expProduct c y) i = x i+y i+ + expCoordinates c (expProduct c x0 * expProduct c y0) i + linarith + +lemma exists_second_correction (i : Fin n) : + ∃ P : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ, + ∀ v : (Fin i.val ⊕ Fin i.val) → ℝ, + expCoordinates c + (expProduct c (lowerExtend i (fun j => v (Sum.inl j))) * + expProduct c (lowerExtend i (fun j => v (Sum.inr j)))) i = + MvPolynomial.eval₂ (algebraMap ℚ ℝ) v P := by + apply polynomial_expCoordinates c + apply polynomialMap_mul c <;> apply polynomialMap_expProduct c <;> intro j + all_goals + unfold lowerExtend + split_ifs with hj + · exact RationalPolynomialMap.coordinate _ + · exact RationalPolynomialMap.zero + +lemma expProduct_zero : expProduct c 0 = 1 := by + change (List.ofFn (fun i => basisFlow c i 0)).prod = 1 + apply List.prod_eq_one + intro x hx + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hx + exact basisFlow_zero c i + +lemma expCoordinates_one : expCoordinates c 1 = 0 := by + rw [← expProduct_zero c,expCoordinates_expProduct] + +def secondCorrection (i : Fin n) : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ := + (exists_second_correction c i).choose + +lemma second_mul_coord (g h : G) (i : Fin n) : + expCoordinates c (g*h) i = expCoordinates c g i + expCoordinates c h i + + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => expCoordinates c g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => expCoordinates c h ⟨j.val,lt_trans j.isLt i.isLt⟩)) (secondCorrection c i) := by + have hm := expCoordinates_mul_difference c (expCoordinates c g) (expCoordinates c h) i + rw [expProduct_expCoordinates,expProduct_expCoordinates] at hm + rw [hm] + congr 1 + exact (exists_second_correction c i).choose_spec + (Sum.elim (fun j => expCoordinates c g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => expCoordinates c h ⟨j.val,lt_trans j.isLt i.isLt⟩)) + + +def secondCoordinates [IsTopologicalGroup G] : RealCoordinates G n where + coord := secondKindHomeomorph c + one_coord i := congrFun (expCoordinates_one c) i + correction := secondCorrection c + mul_coord := second_mul_coord c + +lemma expProduct_single (i : Fin n) (t : ℝ) : expProduct c (Pi.single i t) = basisFlow c i t := by + classical + change (List.ofFn (fun j => basisFlow c j ((Pi.single i t : Fin n → ℝ) j))).prod = _ + rw [List.ofFn_eq_map,List.prod_map_eq_pow_single i] + · simp + · intro j hji hj + simp [hji] + +lemma second_axis [IsTopologicalGroup G] (i : Fin n) (t : ℝ) : + MalcevCharacters.axis (secondCoordinates c) i t = basisFlow c i t := expProduct_single c i t + + + +theorem secondCoordinates_secondKind [IsTopologicalGroup G] : + MalcevCharacters.SecondKind (secondCoordinates c) where + axis_add i s t := by simp only [second_axis]; exact basisFlow_add c i s t + ordered g := by + simp only [second_axis] + exact (expProduct_expCoordinates c g).symm + +lemma coordinates_prefix_zeros_iff (g : G) (k : ℕ) : + (∀ i : Fin n, i.val < k → expCoordinates c g i = 0) ↔ + (∀ i : Fin n, i.val < k → c.coord g i = 0) := by + constructor + · intro hg i hi + have he := expProduct_coord_eq c (expCoordinates c g) 0 i (fun j hj => hg j (by + change j.val ≤ i.val at hj; omega)) + rw [expProduct_expCoordinates,expProduct_zero,c.one_coord] at he + exact he + · intro hg i hi + have he := expCoordinates_prefix_eq c g 1 i (by + intro j hj + rw [c.one_coord] + apply hg + change j.val ≤ i.val at hj + omega) + rw [expCoordinates_one] at he + exact he + + + +theorem secondCoordinates_adapted [IsTopologicalGroup G] (H : Subgroup G) (k : ℕ) + (hH : ∀ g : G, g ∈ H ↔ ∀ i : Fin n, i.val < k → c.coord g i = 0) (g : G) : + g ∈ H ↔ ∀ i : Fin n, i.val < k → (secondCoordinates c).coord g i = 0 := by + exact (hH g).trans (coordinates_prefix_zeros_iff c g k).symm + +end RationalLattice + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice06.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice06.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6507c83f6193269a9413d01b1ed2fd5ca62a4ea --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice06.lean @@ -0,0 +1,309 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.IntegerHyperplane01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped BigOperators +noncomputable section +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +lemma realPower_int (g : G) (z : ℤ) : realPower c g z = g^z := by + cases z with + | ofNat m => simpa using realPower_nat c g m + | negSucc m => + rw [Int.cast_negSucc,realPower_neg] + simp only [realPower_nat,zpow_negSucc] + +lemma basisElement_rational (i : Fin n) : IsRational c (basisElement c i) := by + classical + intro j + refine ⟨if j=i then 1 else 0,?_⟩ + simp only [basisElement,Homeomorph.apply_symm_apply,Pi.single_apply] + split_ifs <;> simp + +lemma basisFlow_rational (i : Fin n) (t : ℚ) : IsRational c (basisFlow c i t) := + realPower_rational c (basisElement_rational c i) t + +variable (Γ : Subgroup G) +variable (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) +include hΓ + +lemma basisElement_mem (i : Fin n) : basisElement c i ∈ Γ := by + classical + apply (hΓ _).mpr + intro j + refine ⟨if j=i then 1 else 0,?_⟩ + simp only [basisElement,Homeomorph.apply_symm_apply,Pi.single_apply] + split_ifs <;> simp + +lemma basisFlow_int_mem (i : Fin n) (t : ℤ) : basisFlow c i t ∈ Γ := by + change realPower c (basisElement c i) t ∈ Γ + rw [realPower_int] + exact Γ.zpow_mem (basisElement_mem c Γ hΓ i) _ + +lemma peel_mem_lattice {g : G} (hg : g ∈ Γ) (k : ℕ) : peel c g k ∈ Γ := by + induction k with + | zero => exact hg + | succ k ih => + simp only [peel] + split_ifs with hk + · obtain ⟨z,hz⟩ := (hΓ _).mp ih ⟨k,hk⟩ + rw [hz,← Int.cast_neg] + exact Γ.mul_mem (basisFlow_int_mem c Γ hΓ _ _) ih + · exact ih + + + +theorem expCoordinates_lattice (g : G) : + g ∈ Γ ↔ ∀ i, ∃ z : ℤ, expCoordinates c g i = z := by + constructor + · intro hg i + exact (hΓ _).mp (peel_mem_lattice c Γ hΓ hg i.val) i + · intro hg + rw [← expProduct_expCoordinates c g] + change (List.ofFn (fun i => basisFlow c i (expCoordinates c g i))).prod ∈ Γ + apply list_prod_mem + intro x hx + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hx + obtain ⟨z,hz⟩ := hg i + rw [hz] + exact basisFlow_int_mem c Γ hΓ i z + +omit hΓ in + + +theorem character_expCoordinates (χ : G →* Multiplicative ℝ) (hχ : Continuous χ) (g : G) : + Multiplicative.toAdd (χ g) = + ∑ i, expCoordinates c g i * Multiplicative.toAdd (χ (basisElement c i)) := by + conv_lhs => rw [← expProduct_expCoordinates c g] + change Multiplicative.toAdd (χ ((List.ofFn (fun i => + basisFlow c i (expCoordinates c g i))).prod)) = _ + rw [map_list_prod,List.map_ofFn] + simp only [toAdd_list_sum,List.map_ofFn,List.sum_ofFn] + apply Finset.sum_congr rfl + intro i _ + exact character_realPower c χ hχ _ _ + + + +theorem integer_character_expCoordinates (χ : G →* Multiplicative ℝ) (hχ : Continuous χ) + (hz : ∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) : + ∃ k : Fin n → ℤ, ∀ g : G, Multiplicative.toAdd (χ g) = + ∑ i, expCoordinates c g i * (k i : ℝ) := by + choose k hk using (fun i => hz _ (basisElement_mem c Γ hΓ i)) + refine ⟨k,fun g => ?_⟩ + rw [character_expCoordinates c χ hχ] + simp_rw [hk] + +end RationalLattice +end +end + + + +section +open Set Topology +noncomputable section +namespace CharacterKernelLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (χ : G →* Multiplicative ℝ) (hχ : Continuous χ) +variable (Γ : Subgroup G) (C : Set G) (hC : IsCompact C) +variable (hreps : ∀ g : G, ∃ c ∈ C, c⁻¹*g ∈ Γ) +variable (hZ : ∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) +include hχ hC hreps hZ + + + +theorem compact_kernel_representatives : + ∃ D : Set G, IsCompact D ∧ D ⊆ χ.ker ∧ + ∀ g ∈ χ.ker, ∃ d ∈ D, d⁻¹*g ∈ Γ := by + classical + let p : G → ℝ := fun g => Multiplicative.toAdd (χ g) + have hp : Continuous p := hχ + let J : Set ℤ := {z | (z : ℝ) ∈ p '' C ∧ ∃ γ ∈ Γ, p γ = z} + have hJ : J.Finite := by + apply Set.Finite.subset ((Int.isClosedEmbedding_coe_real.isCompact_preimage (hC.image hp)).finite ⟨inferInstance⟩) + exact fun z hz => hz.1 + have hex (z : J) : ∃ γ ∈ Γ, p γ = (z.val : ℝ) := z.property.2 + choose δ hδΓ hδp using hex + let D : Set G := ⋃ z : J, (fun c => c * (δ z)⁻¹) '' (C ∩ {c | p c = (z.val : ℝ)}) + refine ⟨D,?_,?_,?_⟩ + · have : Finite J := hJ.to_subtype + exact isCompact_iUnion fun z => (hC.inter_right (isClosed_eq hp continuous_const)).image + (continuous_id.mul continuous_const) + · intro d hd + obtain ⟨z,c,hc,rfl⟩ := Set.mem_iUnion.mp hd + change χ (c*(δ z)⁻¹) = 1 + apply Multiplicative.toAdd.injective + change p (c*(δ z)⁻¹) = 0 + change Multiplicative.toAdd (χ (c*(δ z)⁻¹)) = 0 + rw [map_mul,map_inv] + change p c - p (δ z) = 0 + rw [hc.2,hδp] + exact sub_self _ + · intro g hg + obtain ⟨c,hc,hcg⟩ := hreps g + obtain ⟨z,hz⟩ := hZ (c⁻¹*g) hcg + have hp0 : p g = 0 := hg + have hpc : p c = (-z : ℤ) := by + have hh : p (c⁻¹*g) = -p c + p g := by + dsimp [p]; rw [map_mul,map_inv]; rfl + change p (c⁻¹*g) = (z : ℝ) at hz + rw [hh,hp0,add_zero] at hz + push_cast + linarith + have hzJ : (-z) ∈ J := by + refine ⟨⟨c,hc,hpc⟩, (c⁻¹*g)⁻¹,Γ.inv_mem hcg,?_⟩ + change Multiplicative.toAdd (χ ((c⁻¹*g)⁻¹)) = _ + rw [map_inv] + change -Multiplicative.toAdd (χ (c⁻¹*g)) = _ + rw [hz] + simp + let j : J := ⟨-z,hzJ⟩ + refine ⟨c*(δ j)⁻¹,Set.mem_iUnion.mpr ⟨j,c,⟨hc,hpc⟩,rfl⟩,?_⟩ + have he : (c*(δ j)⁻¹)⁻¹*g = δ j*(c⁻¹*g) := by group + rw [he] + exact Γ.mul_mem (hδΓ j) hcg + + + +theorem compact_kernel_representatives_inter : + ∃ D : Set G, IsCompact D ∧ D ⊆ χ.ker ∧ + ∀ g ∈ χ.ker, ∃ d ∈ D, d⁻¹*g ∈ Γ ⊓ χ.ker := by + obtain ⟨D,hD,hDK,hrep⟩ := compact_kernel_representatives χ hχ Γ C hC hreps hZ + refine ⟨D,hD,hDK,fun g hg => ?_⟩ + obtain ⟨d,hd,hdg⟩ := hrep g hg + exact ⟨d,hd,hdg,χ.ker.mul_mem (χ.ker.inv_mem (hDK hd)) hg⟩ + +end CharacterKernelLattice +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace MalcevCharacters +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) + +include hsk in +omit [IsTopologicalGroup G] in +lemma character_ext_coordinates {χ ψ : G →* Multiplicative ℝ} + (hχ : Continuous χ) (hψ : Continuous ψ) + (he : ∀ i, χ (axis c i 1) = ψ (axis c i 1)) : χ = ψ := by + ext g + apply Multiplicative.toAdd.injective + rw [character_coordinates c hsk χ hχ,character_coordinates c hsk ψ hψ] + simp_rw [he] + +include hsk in + + +omit [IsTopologicalGroup G] in +theorem bounded_integral_characters_finite (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) (A : ℝ) : + {χ : G →* Multiplicative ℝ | Continuous χ ∧ + (∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) ∧ + ∀ i, |Multiplicative.toAdd (χ (axis c i 1))| ≤ A}.Finite := by + classical + let S : Set ℝ := (Int.cast : ℤ → ℝ) '' {z : ℤ | |(z : ℝ)| ≤ A} + have hs : S.Finite := by + apply Set.Finite.image + have hc := Int.isClosedEmbedding_coe_real.isCompact_preimage + (isCompact_closedBall (0 : ℝ) A) + have hf := hc.finite (show IsDiscrete ((Int.cast : ℤ → ℝ) ⁻¹' Metric.closedBall 0 A) from ⟨inferInstance⟩) + simpa only [Set.preimage_ofPred_eq, Metric.closedBall, dist_zero_right,Real.norm_eq_abs] using hf + let f (χ : G →* Multiplicative ℝ) (i : Fin n) := Multiplicative.toAdd (χ (axis c i 1)) + apply Set.Finite.of_finite_image (f := f) + · apply (Set.Finite.pi' (fun _ : Fin n => hs)).subset + rintro y ⟨χ,hχ,rfl⟩ i + obtain ⟨z,hz⟩ := hχ.2.1 _ (axis_one_mem c Γ hΓ i) + exact ⟨z,by simpa [← hz] using hχ.2.2 i,hz.symm⟩ + · intro χ hχ ψ hψ he + apply character_ext_coordinates c hsk hχ.1 hψ.1 + intro i + exact Multiplicative.toAdd.injective (congrFun he i) + +variable (χ : G →* Multiplicative ℝ) (hχ : Continuous χ) +include hsk hχ + + + +omit [IsTopologicalGroup G] in +theorem kernel_inter_connected (H : Subgroup G) (V : Submodule ℝ (Fin n → ℝ)) + (hV : ∀ g : G, g ∈ H ↔ c.coord g ∈ V) : IsConnected (↑H ∩ (χ.ker : Set G)) := by + let W := V ⊓ (coordinateForm (fun i => Multiplicative.toAdd (χ (axis c i 1)))).ker + have he : (↑H ∩ (χ.ker : Set G)) = c.coord.symm '' (W : Set (Fin n → ℝ)) := by + ext g + constructor + · intro hg + refine ⟨c.coord g,⟨(hV g).mp hg.1,?_⟩,c.coord.symm_apply_apply g⟩ + change (∑ i, c.coord g i * Multiplicative.toAdd (χ (axis c i 1))) = 0 + rw [← character_coordinates c hsk χ hχ g] + exact congrArg Multiplicative.toAdd hg.2 + · rintro ⟨x,hx,rfl⟩ + refine ⟨(hV _).mpr (by simpa using hx.1),?_⟩ + apply Multiplicative.toAdd.injective + rw [character_coordinates c hsk χ hχ] + simpa [coordinateForm] using hx.2 + rw [he] + exact (W.convex.isConnected ⟨0,by simp⟩).image _ c.coord.symm.continuous.continuousOn + + + +omit [IsTopologicalGroup G] in +theorem nontrivial_kernel_geometry (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) + (hz : ∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) (hne : χ ≠ 1) : + ∃ k : Fin n → ℤ, k ≠ 0 ∧ + (∀ g, Multiplicative.toAdd (χ g) = ∑ i, c.coord g i * (k i : ℝ)) ∧ + (χ.ker : Set G) = c.coord.symm '' ((IntegerHyperplane.form k).ker : Set (Fin n → ℝ)) ∧ + Module.finrank ℝ (IntegerHyperplane.form k).ker = n-1 := by + obtain ⟨k,hk⟩ := integer_character_coordinates c hsk χ Γ hΓ hχ hz + have hk0 : k ≠ 0 := by + intro he + apply hne + ext g + apply Multiplicative.toAdd.injective + rw [hk,he] + simp + refine ⟨k,hk0,hk,?_,IntegerHyperplane.kernel_finrank k hk0⟩ + ext g + constructor + · intro hg + refine ⟨c.coord g,?_,c.coord.symm_apply_apply g⟩ + change (∑ i, (k i : ℝ) * c.coord g i) = 0 + rw [Finset.sum_congr rfl (fun i _ => mul_comm _ _), ← hk] + exact congrArg Multiplicative.toAdd hg + · rintro ⟨x,hx,rfl⟩ + apply Multiplicative.toAdd.injective + rw [hk] + simpa [IntegerHyperplane.form,mul_comm] using hx + +end MalcevCharacters + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice07.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice07.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed08d920a717c2146fc35e0e697314c484b955bf --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice07.lean @@ -0,0 +1,289 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalTail01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped BigOperators +noncomputable section +end +end + + + +section +noncomputable section +namespace RationalPolynomialMap +variable {σ : Type*} [Fintype σ] +lemma contDiff {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) : ContDiff ℝ (⊤ : ℕ∞) f := by + obtain ⟨p,hp⟩ := hf + have he : f = fun x => MvPolynomial.eval₂ (algebraMap ℚ ℝ) x p := funext hp + rw [he] + clear hp he f + induction p using MvPolynomial.induction_on with + | C q => simpa using (contDiff_const : ContDiff ℝ (⊤ : ℕ∞) (fun _ : σ → ℝ => (q:ℝ))) + | add p q hp hq => simpa using hp.add hq + | mul_X p i hp => simpa using hp.mul (by fun_prop) + + + +lemma bounded_lipschitz {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) (B : ℝ) : + ∃ M > 0, + (∀ x, ‖x‖ ≤ B → |f x| ≤ M) ∧ + (∀ x y, ‖x‖ ≤ B → ‖y‖ ≤ B → |f x-f y| ≤ M*‖x-y‖) := by + have hd := contDiff hf + obtain ⟨M,hM⟩ := (isCompact_closedBall (0 : σ → ℝ) B).exists_bound_of_continuousOn hd.continuous.continuousOn + obtain ⟨D,hD⟩ := (isCompact_closedBall (0 : σ → ℝ) B).exists_bound_of_continuousOn + (hd.continuous_fderiv (by simp)).continuousOn + refine ⟨max (max M D) 0 + 1,by positivity,?_,?_⟩ + · intro x hx + have he := hM x (by simpa using hx) + change |f x| ≤ M at he + exact he.trans (by grind) + · intro x y hx hy + have he := Convex.norm_image_sub_le_of_norm_fderiv_le + (fun x (_ : x ∈ Metric.closedBall (0 : σ → ℝ) B) => hd.differentiable (by simp) x) + hD (convex_closedBall (0 : σ → ℝ) B) (by simpa using hy) (by simpa using hx) + change |f x-f y| ≤ D * ‖x-y‖ at he + exact he.trans (mul_le_mul_of_nonneg_right (by grind) (norm_nonneg _)) + +end RationalPolynomialMap +end +end + + + +section +noncomputable section +namespace RationalLattice +open RationalPolynomialMap +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) {σ τ : Type*} + +lemma polynomialMap_comp {f : (τ → ℝ) → G} (hf : IsPolynomialMap c f) + {g : (σ → ℝ) → (τ → ℝ)} (hg : ∀ i, IsPolynomial (fun x => g x i)) : + IsPolynomialMap c (fun x => f (g x)) := fun i => RationalPolynomialMap.comp (hf i) hg + +lemma polynomialMap_inv {f : (σ → ℝ) → G} (hf : IsPolynomialMap c f) : + IsPolynomialMap c (fun x => (f x)⁻¹) := by + have h : ∀ m : ℕ, ∀ hm : m < n, + IsPolynomial (fun x => c.coord ((f x)⁻¹) ⟨m,hm⟩) := by + intro m + induction m using Nat.strong_induction_on with + | h m ih => + intro hm + let i : Fin n := ⟨m,hm⟩ + have he (x : σ → ℝ) : c.coord ((f x)⁻¹) i = -c.coord (f x) i - + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j : Fin i.val => c.coord (f x) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord ((f x)⁻¹) ⟨j.val,lt_trans j.isLt i.isLt⟩)) (c.correction i) := by + have he := c.mul_coord (f x) ((f x)⁻¹) i + rw [mul_inv_cancel,c.one_coord] at he + linarith + simp_rw [show (⟨m,hm⟩ : Fin n)=i from rfl,he] + apply RationalPolynomialMap.sub (RationalPolynomialMap.neg (hf i)) + apply RationalPolynomialMap.eval + intro j + cases j with + | inl j => exact hf _ + | inr j => exact ih j.val j.isLt (lt_trans j.isLt hm) + intro i + exact h i.val i.isLt + +end RationalLattice +end +end + + + +section +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +lemma correction_eq_of_lower_eq (i : Fin n) {g g' h h' : G} + (hg : ∀ j : Fin n, j < i → c.coord g j = c.coord g' j) + (hh : ∀ j : Fin n, j < i → c.coord h j = c.coord h' j) : + c.coord (g*h) i - c.coord g i - c.coord h i = + c.coord (g'*h') i - c.coord g' i - c.coord h' i := by + rw [c.mul_coord g h,c.mul_coord g' h'] + have he : (Sum.elim (fun j : Fin i.val => c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) = + (Sum.elim (fun j : Fin i.val => c.coord g' ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val => c.coord h' ⟨j.val,lt_trans j.isLt i.isLt⟩)) := by + funext j + cases j with + | inl j => exact hg _ j.isLt + | inr j => exact hh _ j.isLt + rw [he] + ring + +lemma mul_lower_congr (i : Fin n) {g g' h h' : G} + (hg : ∀ j : Fin n, j < i → c.coord g j = c.coord g' j) + (hh : ∀ j : Fin n, j < i → c.coord h j = c.coord h' j) : + ∀ j : Fin n, j < i → c.coord (g*h) j = c.coord (g'*h') j := by + intro j hj + have he := correction_eq_of_lower_eq c j (fun k hk => hg k (lt_trans hk hj)) + (fun k hk => hh k (lt_trans hk hj)) + rw [hg j hj,hh j hj] at he + linarith + +lemma conj_lower_congr (a : G) (i : Fin n) {u v : G} + (huv : ∀ j : Fin n, j < i → c.coord u j = c.coord v j) : + ∀ j : Fin n, j < i → c.coord (a⁻¹*u*a) j = c.coord (a⁻¹*v*a) j := by + exact mul_lower_congr c i (mul_lower_congr c i (fun _ _ => rfl) huv) (fun _ _ => rfl) + +lemma conj_coord_difference (a : G) (i : Fin n) {u v : G} + (huv : ∀ j : Fin n, j < i → c.coord u j = c.coord v j) : + c.coord (a⁻¹*u*a) i - c.coord (a⁻¹*v*a) i = c.coord u i - c.coord v i := by + have h1 := correction_eq_of_lower_eq c i (g:=a⁻¹) (g':=a⁻¹) (fun _ _ => rfl) huv + have h2 := correction_eq_of_lower_eq c i + (mul_lower_congr c i (g:=a⁻¹) (g':=a⁻¹) (fun _ _ => rfl) huv) (h:=a) (h':=a) (fun _ _ => rfl) + linarith + +lemma conj_mul_coord_difference (a : G) (i : Fin n) {u u' v v' : G} + (hu : ∀ j : Fin n, j < i → c.coord u j = c.coord u' j) + (hv : ∀ j : Fin n, j < i → c.coord v j = c.coord v' j) : + c.coord (a⁻¹*u*a*v) i - c.coord (a⁻¹*u'*a*v') i = + c.coord u i - c.coord u' i + c.coord v i - c.coord v' i := by + have h1 := conj_coord_difference c a i hu + have h2 := correction_eq_of_lower_eq c i (conj_lower_congr c a i hu) hv + linarith + + +def truncate (i : Fin n) (v : Fin i.val → ℝ) : G := + c.coord.symm (fun j => if h : j < i then v ⟨j.val,h⟩ else 0) +@[simp] lemma truncate_coord_self (i : Fin n) (v : Fin i.val → ℝ) : + c.coord (truncate c i v) i = 0 := by simp [truncate] +lemma truncate_coord_lower (i : Fin n) (v : Fin i.val → ℝ) (j : Fin n) (hj : j < i) : + c.coord (truncate c i v) j = v ⟨j.val,hj⟩ := by simp [truncate,hj] + +lemma conj_mul_truncated (a u v : G) (i : Fin n) : + c.coord (a⁻¹*u*a*v) i = c.coord u i + c.coord v i + + c.coord (a⁻¹*truncate c i (fun j => c.coord u ⟨j.val,lt_trans j.isLt i.isLt⟩)*a* + truncate c i (fun j => c.coord v ⟨j.val,lt_trans j.isLt i.isLt⟩)) i := by + have hu : ∀ j : Fin n, j < i → c.coord u j = + c.coord (truncate c i (fun j => c.coord u ⟨j.val,lt_trans j.isLt i.isLt⟩)) j := by + intro j hj + rw [truncate_coord_lower c i _ j hj] + have hv : ∀ j : Fin n, j < i → c.coord v j = + c.coord (truncate c i (fun j => c.coord v ⟨j.val,lt_trans j.isLt i.isLt⟩)) j := by + intro j hj + rw [truncate_coord_lower c i _ j hj] + have he := conj_mul_coord_difference c a i hu hv + rw [truncate_coord_self,truncate_coord_self] at he + linarith + +lemma polynomialMap_truncate {σ : Type*} (i : Fin n) {f : (σ → ℝ) → (Fin i.val → ℝ)} + (hf : ∀ j, RationalPolynomialMap.IsPolynomial (fun x => f x j)) : + IsPolynomialMap c (fun x => truncate c i (f x)) := by + intro j + simp only [truncate,Homeomorph.apply_symm_apply] + split_ifs + · exact hf _ + · exact RationalPolynomialMap.zero + +end RationalLattice +end +end + + + +section +noncomputable section +namespace PairTail +open RationalLattice + +def joinHomeomorph (r d : ℕ) : ((Fin r → ℝ) × (Fin d → ℝ)) ≃ₜ (Fin (r+d) → ℝ) where + toFun x := Fin.append x.1 x.2 + invFun x := (fun i => x (i.castAdd d),fun j => x (j.natAdd r)) + left_inv x := by simp + right_inv x := by funext i; exact Fin.addCases (fun _ => by simp) (fun _ => by simp) i + continuous_toFun := by + apply continuous_pi + intro i + refine Fin.addCases (fun j => ?_) (fun j => ?_) i + · simp only [Fin.append_left] + exact (continuous_apply j).comp continuous_fst + · simp only [Fin.append_right] + exact (continuous_apply j).comp continuous_snd + continuous_invFun := (continuous_pi (fun _ => continuous_apply _)).prodMk + (continuous_pi (fun _ => continuous_apply _)) + +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d r : ℕ} (c : RealCoordinates G (t+d)) +variable (K : Subgroup G) [K.Normal] +variable (hK : ∀ g : G, g ∈ K ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i = 0) +variable (hr : r ≤ t+d) (N : Subgroup G) [N.Normal] +variable (hN : ∀ g : G, g ∈ N ↔ ∀ i : Fin (t+d), i.val < r → c.coord g i = 0) +variable (hcent : N ≤ Subgroup.center G) + +def baseSection (x : G ⧸ N) : G := MalcevPrefixQuotient.represent c + (MalcevPrefixQuotient.coordinates c hr N hN x) +omit [IsTopologicalGroup G] [N.Normal] in +lemma section_spec (x : G ⧸ N) : (QuotientGroup.mk (baseSection c hr N hN x) : G ⧸ N) = x := + MalcevPrefixQuotient.rebuild_coordinates c hr N hN x +omit [IsTopologicalGroup G] [N.Normal] in +lemma section_continuous : Continuous (baseSection c hr N hN) := + c.coord.symm.continuous.comp (MalcevPrefixQuotient.lift_continuous.comp + (MalcevPrefixQuotient.coordinates_continuous c hr N hN)) + + + +def chartHomeomorph : (square K ⧸ diagonal K N) ≃ₜ (Fin (r+d) → ℝ) := + (quotientHomeomorph K N hcent (baseSection c hr N hN) (section_spec c hr N hN) + (section_continuous c hr N hN)).trans + (((MalcevPrefixQuotient.homeomorph c hr N hN).prodCongr + (RationalTailCoordinates.tailHomeomorph c K hK)).trans (joinHomeomorph r d)) + +omit [N.Normal] in +@[simp] lemma chart_base (x : square K) (i : Fin r) : + chartHomeomorph c K hK hr N hN hcent (QuotientGroup.mk x) (i.castAdd d) = + c.coord x.val.1 (MalcevPrefixQuotient.embed hr i) := by + change Fin.append _ _ (i.castAdd d) = _ + rw [Fin.append_left] + rfl +omit [N.Normal] in +@[simp] lemma chart_tail (x : square K) (j : Fin d) : + chartHomeomorph c K hK hr N hN hcent (QuotientGroup.mk x) (j.natAdd r) = + c.coord (x.val.1⁻¹*x.val.2) (RationalTailCoordinates.embed t j) := by + change Fin.append _ _ (j.natAdd r) = _ + rw [Fin.append_right] + rfl + +omit [N.Normal] in +lemma chart_one : chartHomeomorph c K hK hr N hN hcent (QuotientGroup.mk (1:square K)) = 0 := by + funext i + refine Fin.addCases (fun j => ?_) (fun j => ?_) i + · simpa using c.one_coord (MalcevPrefixQuotient.embed hr j) + · simpa using c.one_coord (RationalTailCoordinates.embed t j) + +omit [N.Normal] in +lemma chart_rebuild_base (x : Fin (r+d) → ℝ) : + (chartHomeomorph c K hK hr N hN hcent).symm x = + QuotientGroup.mk (pair K + (MalcevPrefixQuotient.represent c (fun i : Fin r => x (i.castAdd d))) + (RationalTailCoordinates.rebuild c K hK (fun i : Fin d => x (i.natAdd r)))) := by + apply (chartHomeomorph c K hK hr N hN hcent).injective + rw [Homeomorph.apply_symm_apply] + funext i + refine Fin.addCases (fun j => ?_) (fun j => ?_) i + · rw [chart_base] + simp [pair,MalcevPrefixQuotient.represent] + · rw [chart_tail] + simp [pair,RationalTailCoordinates.rebuild] + +end PairTail + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice08.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice08.lean new file mode 100644 index 0000000000000000000000000000000000000000..310b63f440e58f61c13b3b6da37aa6103fefdd91 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice08.lean @@ -0,0 +1,414 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.IntegerHyperplane02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped BigOperators +end +end + + + +section +noncomputable section +open scoped BigOperators +namespace RationalCharacterFirst +open RationalLattice IntegerHyperplane RationalPolynomialMap +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G (n+1)) (χ : G →* Multiplicative ℝ) +variable (k : Fin (n+1) → ℤ) (p : Fin (n+1)) (hp : k p ≠ 0) +variable (hχ : ∀ g : G, Multiplicative.toAdd (χ g) = form k (c.coord g)) +variable (hlast : ∀ j : Fin (n+1), p < j → k j = 0) + +def coordinates (g : G) : Fin (n+1) → ℝ := splitCoordinates k p (c.coord g) + +lemma exists_correction (i : Fin n) : + ∃ P : MvPolynomial (Fin (i.val+1) ⊕ Fin (i.val+1)) ℚ, + ∀ v : (Fin (i.val+1) ⊕ Fin (i.val+1)) → ℝ, + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim + (fun a => splitLift k p (lowerExtend i.succ (fun j => v (Sum.inl j))) + ⟨a.val,lt_trans a.isLt (p.succAbove i).isLt⟩) + (fun a => splitLift k p (lowerExtend i.succ (fun j => v (Sum.inr j))) + ⟨a.val,lt_trans a.isLt (p.succAbove i).isLt⟩)) (c.correction (p.succAbove i)) = + MvPolynomial.eval₂ (algebraMap ℚ ℝ) v P := by + apply RationalPolynomialMap.eval + intro a + cases a with + | inl a => + apply RationalPolynomialMap.comp (splitLift_polynomial k p _) + intro j + unfold lowerExtend + split_ifs + · exact RationalPolynomialMap.coordinate _ + · exact RationalPolynomialMap.zero + | inr a => + apply RationalPolynomialMap.comp (splitLift_polynomial k p _) + intro j + unfold lowerExtend + split_ifs + · exact RationalPolynomialMap.coordinate _ + · exact RationalPolynomialMap.zero + +def tailCorrection (i : Fin n) : MvPolynomial (Fin (i.val+1) ⊕ Fin (i.val+1)) ℚ := + (exists_correction c k p i).choose + +include hp hlast in +lemma tail_mul_coord (g h : G) (i : Fin n) : + coordinates c k p (g*h) i.succ = coordinates c k p g i.succ + coordinates c k p h i.succ + + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => coordinates c k p g ⟨j.val,lt_trans j.isLt i.succ.isLt⟩) + (fun j => coordinates c k p h ⟨j.val,lt_trans j.isLt i.succ.isLt⟩)) (tailCorrection c k p i) := by + change c.coord (g*h) (p.succAbove i) = _ + rw [c.mul_coord] + change coordinates c k p g i.succ + coordinates c k p h i.succ + _ = _ + congr 1 + let v : (Fin (i.val+1) ⊕ Fin (i.val+1)) → ℝ := + Sum.elim (fun j => coordinates c k p g ⟨j.val,lt_trans j.isLt i.succ.isLt⟩) + (fun j => coordinates c k p h ⟨j.val,lt_trans j.isLt i.succ.isLt⟩) + unfold tailCorrection + rw [← (exists_correction c k p i).choose_spec v] + congr 1 + funext a + have hl (u : G) (a : Fin (p.succAbove i).val) : + c.coord u ⟨a.val,lt_trans a.isLt (p.succAbove i).isLt⟩ = + splitLift k p (lowerExtend i.succ + (fun j => coordinates c k p u ⟨j.val,lt_trans j.isLt i.succ.isLt⟩)) + ⟨a.val,lt_trans a.isLt (p.succAbove i).isLt⟩ := by + conv_lhs => rw [← splitLift_splitCoordinates k p hp (c.coord u)] + apply splitLift_lower_dep k p hlast i + · intro j hj + have hj' : j.val < i.succ.val := hj + simp only [lowerExtend,hj',dite_eq_left,coordinates] + · exact a.isLt + cases a with + | inl a => exact hl g a + | inr a => exact hl h a + +include hχ in +lemma head_mul_coord (g h : G) : + coordinates c k p (g*h) 0 = coordinates c k p g 0+coordinates c k p h 0 := by + change form k (c.coord (g*h))/(k p:ℝ) = form k (c.coord g)/(k p:ℝ)+form k (c.coord h)/(k p:ℝ) + rw [← hχ,← hχ,← hχ,map_mul] + exact add_div _ _ _ + + + +def characterFirstCoordinates : RealCoordinates G (n+1) where + coord := c.coord.trans (splitHomeomorph k p hp) + one_coord i := by + refine Fin.cases ?_ (fun j => ?_) i + · change form k (c.coord 1)/(k p:ℝ) = 0 + simp [form,c.one_coord] + · exact c.one_coord _ + correction := Fin.cases 0 (tailCorrection c k p) + mul_coord g h i := by + refine Fin.cases ?_ (fun j => ?_) i + · change coordinates c k p (g*h) 0 = coordinates c k p g 0+coordinates c k p h 0+ + MvPolynomial.eval₂ _ _ 0 + rw [MvPolynomial.eval₂_zero,add_zero] + exact head_mul_coord c χ k p hχ g h + · exact tail_mul_coord c k p hp hlast g h j + +lemma inclusion_polynomial (i : Fin (n+1)) : + RationalPolynomialMap.IsPolynomial (fun x : Fin (n+1) → ℝ => + c.coord ((characterFirstCoordinates c χ k p hp hχ hlast).coord.symm x) i) := by + change RationalPolynomialMap.IsPolynomial (fun x => c.coord (c.coord.symm (splitLift k p x)) i) + simp only [Homeomorph.apply_symm_apply] + exact splitLift_polynomial k p i + +include hp hχ hlast in +lemma characterFirst_adapted (H : Subgroup G) (r : ℕ) + (hH : ∀ g : G, g ∈ H ↔ ∀ i : Fin (n+1), i.val < r → c.coord g i = 0) (g : G) : + g ∈ H ⊓ χ.ker ↔ ∀ i : Fin (n+1), i.val < deletedCutoff p r+1 → + (characterFirstCoordinates c χ k p hp hχ hlast).coord g i = 0 := by + have hpR : (k p:ℝ) ≠ 0 := by exact_mod_cast hp + have hhead : (characterFirstCoordinates c χ k p hp hχ hlast).coord g 0 = 0 ↔ g ∈ χ.ker := by + change form k (c.coord g)/(k p:ℝ) = 0 ↔ χ g=1 + rw [← hχ,div_eq_zero_iff] + simp only [hpR,or_false] + constructor + · intro h + exact Multiplicative.toAdd.injective h + · intro h + rw [h] + rfl + constructor + · rintro ⟨hg,hker⟩ i + refine Fin.cases ?_ (fun j => ?_) i + · intro _; exact hhead.mpr hker + · intro hi + have ha := (RationalCharacterKernel.kernelCoordinates_adapted c χ k p hp hχ hlast H r hH ⟨g,hker⟩).mp hg + exact ha j (by change j.val+1 < deletedCutoff p r+1 at hi; omega) + · intro hg + have hker := hhead.mp (hg 0 (by change 0 < deletedCutoff p r+1; omega)) + refine ⟨?_,hker⟩ + apply (RationalCharacterKernel.kernelCoordinates_adapted c χ k p hp hχ hlast H r hH ⟨g,hker⟩).mpr + intro j hj + exact hg j.succ (by change j.val+1 < deletedCutoff p r+1; omega) + +end RationalCharacterFirst +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace TriangularDenominators + + + +theorem polynomial_origin_grid {ι : Type*} (P : MvPolynomial ι ℚ) : + ∃ D : ℕ, 0 < D ∧ ∀ T : ℕ, ∀ x : ι → ℤ, ∃ z : ℤ, + MvPolynomial.eval (fun j => (D:ℚ)*(T:ℚ)*(x j:ℚ)) P - + MvPolynomial.eval (fun _ => 0) P = (T:ℚ)*(z:ℚ) := by + induction P using MvPolynomial.induction_on with + | C a => exact ⟨1,by norm_num,fun T x => ⟨0,by simp⟩⟩ + | add P Q hP hQ => + obtain ⟨D,hD,hP⟩ := hP + obtain ⟨E,hE,hQ⟩ := hQ + refine ⟨D*E,Nat.mul_pos hD hE,?_⟩ + intro T x + obtain ⟨a,ha⟩ := hP T (fun j => (E:ℤ)*x j) + obtain ⟨b,hb⟩ := hQ T (fun j => (D:ℤ)*x j) + have hDE : (fun j => (D:ℚ)*(T:ℚ)*(((E:ℤ)*x j):ℚ)) = + (fun j => ((D*E:ℕ):ℚ)*(T:ℚ)*(x j:ℚ)) := by funext j; push_cast; ring + have hED : (fun j => (E:ℚ)*(T:ℚ)*(((D:ℤ)*x j):ℚ)) = + (fun j => ((D*E:ℕ):ℚ)*(T:ℚ)*(x j:ℚ)) := by funext j; push_cast; ring + simp only [Int.cast_mul] at ha hb + rw [hDE] at ha + rw [hED] at hb + refine ⟨a+b,?_⟩ + simp only [map_add,Int.cast_add] + linarith + | mul_X P i hP => + obtain ⟨D,hD,hgrid⟩ := polynomial_grid P 1 (by norm_num) + refine ⟨D,hD,?_⟩ + intro T x + obtain ⟨a,ha⟩ := hgrid (fun j => (D:ℚ)*(T:ℚ)*(x j:ℚ)) (by + intro j + refine ⟨(D:ℤ)*(T:ℤ)*x j,?_⟩ + simp) + refine ⟨a*x i,?_⟩ + simp only [map_mul,MvPolynomial.eval_X,mul_zero,sub_zero,Int.cast_mul] + calc + _ = (T:ℚ)*((D:ℚ)*MvPolynomial.eval (fun j => (D:ℚ)*(T:ℚ)*(x j:ℚ)) P)*(x i:ℚ) := by ring + _ = _ := by rw [ha]; ring + +theorem polynomial_origin_grid_real {ι : Type*} (P : MvPolynomial ι ℚ) : + ∃ D : ℕ, 0 < D ∧ ∀ T : ℕ, ∀ x : ι → ℝ, + (∀ j, ∃ z : ℤ, x j = ((D*T:ℕ):ℝ)*(z:ℝ)) → ∃ z : ℤ, + MvPolynomial.eval₂ (algebraMap ℚ ℝ) x P - + MvPolynomial.eval₂ (algebraMap ℚ ℝ) (fun _ => 0) P = (T:ℝ)*(z:ℝ) := by + obtain ⟨D,hD,hgrid⟩ := polynomial_origin_grid P + refine ⟨D,hD,?_⟩ + intro T x hx + choose z hz using hx + obtain ⟨a,ha⟩ := hgrid T z + refine ⟨a,?_⟩ + have he : ∀ v : ι → ℚ, ((MvPolynomial.eval v P : ℚ):ℝ) = + MvPolynomial.eval₂ (algebraMap ℚ ℝ) (fun i => (v i:ℝ)) P := by + intro v + exact MvPolynomial.eval₂_comp_left (algebraMap ℚ ℝ) (RingHom.id ℚ) v P + have hh := congrArg (fun q : ℚ => (q:ℝ)) ha + simp only [Rat.cast_sub,Rat.cast_mul,Rat.cast_natCast,Rat.cast_intCast] at hh + rw [he,he] at hh + simp only [Rat.cast_zero] at hh + convert hh using 1 + · congr 1 + congr 1 + funext j + simpa only [Rat.cast_mul,Rat.cast_natCast,Rat.cast_intCast,Nat.cast_mul] using hz j +end TriangularDenominators + +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +def correctionDenom (i : Fin n) : ℕ := + (TriangularDenominators.polynomial_origin_grid_real (c.correction i)).choose + +lemma correctionDenom_pos (i : Fin n) : 0 < correctionDenom c i := + (TriangularDenominators.polynomial_origin_grid_real (c.correction i)).choose_spec.1 + +lemma correction_at_zero (i : Fin n) : + MvPolynomial.eval₂ (algebraMap ℚ ℝ) (fun _ => 0) (c.correction i) = 0 := by + have h := c.mul_coord 1 1 i + simp only [mul_one,c.one_coord,zero_add] at h + have he : (Sum.elim (fun _ : Fin i.val => (0:ℝ)) (fun _ : Fin i.val => (0:ℝ))) = (fun _ => (0:ℝ)) := by + funext j; cases j <;> rfl + rw [he] at h + exact h.symm + +variable (w : Fin n → ℕ) +variable (hw : ∀ i : Fin n, ∀ j : Fin n, j < i → correctionDenom c i * w i ∣ w j) + +def OnGrid (g : G) : Prop := ∀ i, ∃ z : ℤ, c.coord g i = (w i:ℝ)*(z:ℝ) + +include hw in +lemma correction_on_grid (g h : G) (i : Fin n) + (hg : ∀ j : Fin n, j < i → ∃ z : ℤ, c.coord g j = (w j:ℝ)*(z:ℝ)) + (hh : ∀ j : Fin n, j < i → ∃ z : ℤ, c.coord h j = (w j:ℝ)*(z:ℝ)) : + ∃ z : ℤ, MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) (c.correction i) = (w i:ℝ)*(z:ℝ) := by + have hl (a : G) (ha : ∀ j : Fin n, j < i → ∃ z : ℤ, c.coord a j = (w j:ℝ)*(z:ℝ)) + (j : Fin i.val) : ∃ z : ℤ, c.coord a ⟨j.val,lt_trans j.isLt i.isLt⟩ = + ((correctionDenom c i*w i:ℕ):ℝ)*(z:ℝ) := by + let k : Fin n := ⟨j.val,lt_trans j.isLt i.isLt⟩ + obtain ⟨z,hz⟩ := ha k j.isLt + obtain ⟨b,hb⟩ := hw i k j.isLt + refine ⟨(b:ℤ)*z,?_⟩ + change c.coord a k = _ + rw [hz,hb] + push_cast + ring + have he := (TriangularDenominators.polynomial_origin_grid_real (c.correction i)).choose_spec.2 + (w i) (Sum.elim (fun j => c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) (by + intro j + cases j with + | inl j => exact hl g hg j + | inr j => exact hl h hh j) + simpa only [correction_at_zero,sub_zero] using he + +include hw in +lemma onGrid_mul {g h : G} (hg : OnGrid c w g) (hh : OnGrid c w h) : OnGrid c w (g*h) := by + intro i + obtain ⟨a,ha⟩ := hg i + obtain ⟨b,hb⟩ := hh i + obtain ⟨d,hd⟩ := correction_on_grid c w hw g h i (fun j _ => hg j) (fun j _ => hh j) + refine ⟨a+b+d,?_⟩ + rw [c.mul_coord,ha,hb,hd] + push_cast + ring + +include hw in +lemma onGrid_inv {g : G} (hg : OnGrid c w g) : OnGrid c w g⁻¹ := by + have hi : ∀ a : ℕ, ∀ ha : a < n, ∃ z : ℤ, + c.coord g⁻¹ ⟨a,ha⟩ = (w ⟨a,ha⟩:ℝ)*(z:ℝ) := by + intro a + induction a using Nat.strong_induction_on with + | h a ih => + intro ha + let i : Fin n := ⟨a,ha⟩ + obtain ⟨b,hb⟩ := hg i + obtain ⟨d,hd⟩ := correction_on_grid c w hw g g⁻¹ i (fun j _ => hg j) + (fun j hj => ih j.val hj j.isLt) + have he := c.mul_coord g g⁻¹ i + rw [mul_inv_cancel,c.one_coord,hb,hd] at he + refine ⟨-b-d,?_⟩ + change c.coord g⁻¹ i = _ + push_cast + linarith + exact fun i => hi i.val i.isLt + + + +def weightedLattice : Subgroup G where + carrier := OnGrid c w + one_mem' := fun i => ⟨0,by simp [c.one_coord]⟩ + mul_mem' := onGrid_mul c w hw + inv_mem' := onGrid_inv c w hw + + + +theorem exists_lattice_weights (E : ℕ) (hE : 0 < E) : ∃ w : Fin n → ℕ, + (∀ i, 0 < w i) ∧ (∀ i, E ∣ w i) ∧ + ∀ i : Fin n, ∀ j : Fin n, j < i → correctionDenom c i*w i ∣ w j := by + let D : ℕ := E * ∏ i, correctionDenom c i + have hD : 0 < D := Nat.mul_pos hE (Finset.prod_pos (fun i _ => correctionDenom_pos c i)) + refine ⟨fun i => D^(n-i.val),fun i => pow_pos hD _,?_,?_⟩ + · intro i + exact (dvd_mul_right E _).trans (dvd_pow_self D (by omega)) + · intro i j hji + have hc : correctionDenom c i ∣ D := + (Finset.dvd_prod_of_mem (fun i => correctionDenom c i) (Finset.mem_univ i)).trans (dvd_mul_left _ _) + have he : correctionDenom c i*D^(n-i.val) ∣ D^(n-i.val+1) := by + rw [pow_succ] + rw [mul_comm (D^(n-i.val)) D] + exact mul_dvd_mul_right hc _ + exact he.trans (pow_dvd_pow D (by change j.val < i.val at hji; omega)) + +variable (hpos : ∀ i, 0 < w i) + +def divideCoordinates : (Fin n → ℝ) ≃ₜ (Fin n → ℝ) where + toFun x i := x i/(w i:ℝ) + invFun x i := (w i:ℝ)*x i + left_inv x := by funext i; exact mul_div_cancel₀ (x i) (by exact_mod_cast (hpos i).ne') + right_inv x := by funext i; exact mul_div_cancel_left₀ (x i) (by exact_mod_cast (hpos i).ne') + continuous_toFun := continuous_pi (fun i => (continuous_apply i).div_const _) + continuous_invFun := continuous_pi (fun i => continuous_const.mul (continuous_apply i)) + +lemma exists_scaled_correction (i : Fin n) : + ∃ P : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ, ∀ x : (Fin i.val ⊕ Fin i.val) → ℝ, + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => (w ⟨j.val,lt_trans j.isLt i.isLt⟩:ℝ)*x (Sum.inl j)) + (fun j => (w ⟨j.val,lt_trans j.isLt i.isLt⟩:ℝ)*x (Sum.inr j))) + (c.correction i) / (w i:ℝ) = MvPolynomial.eval₂ (algebraMap ℚ ℝ) x P := by + have he : RationalPolynomialMap.IsPolynomial (fun x : (Fin i.val ⊕ Fin i.val) → ℝ => + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => (w ⟨j.val,lt_trans j.isLt i.isLt⟩:ℝ)*x (Sum.inl j)) + (fun j => (w ⟨j.val,lt_trans j.isLt i.isLt⟩:ℝ)*x (Sum.inr j))) (c.correction i)) := by + apply RationalPolynomialMap.eval + intro j + cases j with + | inl j => simpa using RationalPolynomialMap.mul (RationalPolynomialMap.const (w ⟨j.val,lt_trans j.isLt i.isLt⟩:ℚ)) (RationalPolynomialMap.coordinate (Sum.inl j)) + | inr j => simpa using RationalPolynomialMap.mul (RationalPolynomialMap.const (w ⟨j.val,lt_trans j.isLt i.isLt⟩:ℚ)) (RationalPolynomialMap.coordinate (Sum.inr j)) + have hm := RationalPolynomialMap.mul he (RationalPolynomialMap.const (w i:ℚ)⁻¹) + simpa only [RationalPolynomialMap.IsPolynomial,div_eq_mul_inv,Rat.cast_inv,Rat.cast_natCast] using hm + +def scaledCorrection (i : Fin n) : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ := + (exists_scaled_correction c w i).choose + + +def scaledCoordinates : RealCoordinates G n where + coord := c.coord.trans (divideCoordinates w hpos) + one_coord i := by change c.coord 1 i / (w i:ℝ) = 0; rw [c.one_coord,zero_div] + correction := scaledCorrection c w + mul_coord g h i := by + change c.coord (g*h) i/(w i:ℝ) = _ + have he := (exists_scaled_correction c w i).choose_spec + (Sum.elim (fun j => c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩/(w ⟨j.val,lt_trans j.isLt i.isLt⟩:ℝ)) + (fun j => c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩/(w ⟨j.val,lt_trans j.isLt i.isLt⟩:ℝ))) + have hc (v : ℝ) (j : Fin n) : (w j:ℝ)*(v/(w j:ℝ)) = v := mul_div_cancel₀ _ (by exact_mod_cast (hpos j).ne') + simp only [Sum.elim_inl,Sum.elim_inr,hc] at he + change c.coord (g*h) i/(w i:ℝ) = c.coord g i/(w i:ℝ)+c.coord h i/(w i:ℝ)+_ + dsimp [scaledCorrection,divideCoordinates] + rw [← he,c.mul_coord] + ring + +lemma weightedLattice_iff (g : G) : g ∈ weightedLattice c w hw ↔ + ∀ i, ∃ z : ℤ, (scaledCoordinates c w hpos).coord g i = z := by + constructor <;> intro hg i <;> obtain ⟨z,hz⟩ := hg i <;> refine ⟨z,?_⟩ + · change c.coord g i/(w i:ℝ) = z + rw [hz] + exact mul_div_cancel_left₀ _ (by exact_mod_cast (hpos i).ne') + · change c.coord g i/(w i:ℝ) = z at hz + exact (div_eq_iff (by exact_mod_cast (hpos i).ne')).mp hz |>.trans (mul_comm _ _) + +end RationalLattice + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice09.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice09.lean new file mode 100644 index 0000000000000000000000000000000000000000..1dfa60edd6743f46b1d853ae8ab1c66fd949cd5c --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice09.lean @@ -0,0 +1,267 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevCentral01 +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +end +end + + + +section +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + +include hΓ in + +lemma coordinate_quotient_t2 : T2Space (G⧸Γ) := by + let : T2Space G := c.coord.symm.t2Space + let : DiscreteTopology Γ := integerCoordinates_discrete c Γ hΓ + have hc : IsClosed (Γ : Set G) := Γ.isClosed_of_discreteTopology + apply (t2Space_iff_of_isOpenQuotientMap (QuotientGroup.isOpenQuotientMap_mk (N:=Γ))).mpr + have he : {p : G×G | (QuotientGroup.mk p.1 : G⧸Γ)=QuotientGroup.mk p.2}= + (fun p : G×G => p.1⁻¹*p.2) ⁻¹' (Γ:Set G) := by + ext p + exact QuotientGroup.eq + rw [he] + exact hc.preimage (continuous_fst.inv.mul continuous_snd) + +include hΓ in +lemma coordinate_quotient_metrizable : TopologicalSpace.MetrizableSpace (G⧸Γ) := by + let : T2Space (G⧸Γ) := coordinate_quotient_t2 c Γ hΓ + let : CompactSpace (G⧸Γ) := AbelianMalcevTorus.quotient_compact c Γ hΓ + let : SecondCountableTopology G := c.coord.secondCountableTopology + infer_instance + + + +abbrev coordinateQuotientMetric : MetricSpace (G⧸Γ) := + letI := coordinate_quotient_metrizable c Γ hΓ + TopologicalSpace.metrizableSpaceMetric (G⧸Γ) + +lemma coordinateQuotientMetric_topology : + (coordinateQuotientMetric c Γ hΓ).toUniformSpace.toTopologicalSpace= + QuotientGroup.instTopologicalSpace Γ := rfl + +end RationalLattice +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace AbelianMalcevTorus +open RationalLattice MalcevCharacters CubeFaces LeibmanSquare MeasureTheory RationalQuotientFunctions +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n r : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) (hr : r ≤ n) +variable (N Γ : Subgroup G) [N.Normal] (hcomm : _root_.commutator G ≤ N) +variable (hN : ∀ g : G, g∈N ↔ ∀ i : Fin n, i.val QuotientGroup.mk (f k)) F‖ → + ∃ χ∈U, χ≠1 ∧ ∃ P : ℝ[X], P.natDegree ≤ s ∧ + (∀ z : ℤ, P.eval (z:ℝ)=(χ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 + induction h using Quotient.inductionOn with | h h => + exact prefix_coord_mul c hsk N r hcomm (fun a ha => (hN a).mp ha) + (MalcevPrefixQuotient.embed hr i) i.isLt g h + let : MetricSpace ((G⧸N)⧸ΓQ) := coordinateQuotientMetric cQ ΓQ hΓQ + let : CompactSpace ((G⧸N)⧸ΓQ) := quotient_compact cQ ΓQ hΓQ + let : MeasurableSpace ((G⧸N)⧸ΓQ) := borel _ + let : BorelSpace ((G⧸N)⧸ΓQ) := ⟨rfl⟩ + let Q := quotientMap N Γ + have hQ : Continuous Q := continuous_quotientMap N Γ + let ν := Measure.map Q μ + let : IsProbabilityMeasure ν := + (Measure.isProbabilityMeasure_map_iff hQ.measurable.aemeasurable).mpr inferInstance + let : SMulInvariantMeasure (G⧸N) ((G⧸N)⧸ΓQ) ν := CentralQuotientAction.invariant_quotientMap N Γ μ + obtain ⟨FQ,hFQ,_⟩ := existsUnique_normalDescend N Γ + (⟨fun g => F (QuotientGroup.mk g),F.continuous.comp QuotientGroup.continuous_mk⟩ : C(G,ℂ)) hF + (fun g a ha => congrArg F (QuotientGroup.mk_mul_of_mem g ha)) + have hFQall : ∀ x : G⧸Γ, FQ (Q x)=F x := by + intro x + induction x using Quotient.inductionOn with | h g => exact hFQ g + let HQ := mapFiltration H (QuotientGroup.mk' N) + have hsQ : HQ.level (s+1)=⊥ := by + change (H.level (s+1)).map (QuotientGroup.mk' N)=⊥ + rw [hs,Subgroup.map_bot] + obtain ⟨U,hU,A,hA,hprod⟩ := quantitative_abelian_compact_producer cQ hadd ΓQ hΓQ rfl + HQ s hsQ ν {FQ} (isCompact_singleton) δ hδ + let liftχ : (G⧸N →* Multiplicative ℝ) → (G→*Multiplicative ℝ) := fun χ => χ.comp (QuotientGroup.mk' N) + refine ⟨U.image liftχ,?_,A,hA,?_⟩ + · intro χ hχ + obtain ⟨ξ,hξ,rfl⟩ := Finset.mem_image.mp hχ + refine ⟨(hU ξ hξ).1.comp QuotientGroup.continuous_mk,?_⟩ + intro g hg + exact (hU ξ hξ).2 _ ⟨g,hg,rfl⟩ + · intro L hL f hf hdisc + have hint : (∫ x, FQ x ∂ν)=(∫ x,F x ∂μ) := by + rw [show ν=Measure.map Q μ from rfl,integral_map hQ.measurable.aemeasurable FQ.continuous.aestronglyMeasurable] + apply integral_congr_ae + exact Filter.Eventually.of_forall hFQall + have hdiscQ : δ ≤ ‖FourierObstruction.discrepancy ν L + (fun k => QuotientGroup.mk (QuotientGroup.mk' N (f k))) FQ‖ := by + change δ ≤ ‖PolynomialWeyl.mean L (fun k => FQ (QuotientGroup.mk (QuotientGroup.mk' N (f k))))-(∫ x,FQ x ∂ν)‖ + simp only [hFQ,hint] + exact hdisc + obtain ⟨χ,hχ,hχ0,P,hP,hPe,hPc⟩ := hprod L hL (fun z => QuotientGroup.mk' N (f z)) + (polynomial_map H (QuotientGroup.mk' N) hf) ⟨FQ,Set.mem_singleton FQ,hdiscQ⟩ + refine ⟨liftχ χ,Finset.mem_image.mpr ⟨χ,hχ,rfl⟩,?_,P,hP,hPe,hPc⟩ + intro he + apply hχ0 + apply MonoidHom.ext + intro x + obtain ⟨g,rfl⟩ := QuotientGroup.mk_surjective x + exact congrArg (fun ψ : G→*Multiplicative ℝ => ψ g) he + +end AbelianMalcevTorus +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) (hcomm : H.level 2=_root_.commutator G) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val by simpa only [hq2] using hq 2 g + letI := tailAction c hsk (H.level 2) Γ (last_central_ambient H h1 2 hs) htail hΓ + ∀ (F : C(G⧸Γ,ℂ)) (k : Fin d→ℤ), TorusVerticalFourier.HasWeight k F → + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 by simpa only [hq2] using hq 2 g + let hcent := last_central_ambient H h1 2 hs + let := tailAction c hsk (H.level 2) Γ hcent htail hΓ + let := continuous_tailAction c hsk (H.level 2) Γ hcent htail hΓ + let := invariant_tailAction c hsk (H.level 2) Γ hcent htail hΓ μ + dsimp only + intro F k hw + by_cases hk : k=0 + · have hF : ∀ g a, a∈H.level 2 → F (QuotientGroup.mk (g*a))=F (QuotientGroup.mk g) := by + intro g a ha + have he := hw (torusProjection (tailCoordinates c (H.level 2) htail) ⟨a,ha⟩) (QuotientGroup.mk g) + rw [tailProjection_vadd c hsk (H.level 2) Γ hcent htail hΓ] at he + simpa only [hk,mFourier_zero,ContinuousMap.one_apply,one_mul] using he + obtain ⟨U,hU,A,hA,hprod⟩ := quantitative_abelian_quotient_observable c hsk + (Nat.le_add_right t d) (H.level 2) Γ hcomm.ge htail hΓ H 2 hs μ F hF δ hδ + refine ⟨U,A,hA,1,by decide,?_⟩ + intro N hN f hf _ hdisc + obtain ⟨ξ,hξ,hξ0,P,hP,hPe,hPc⟩ := hprod N hN f hf hdisc + exact ⟨ξ,hξ,hξ0,(hU ξ hξ).1,(hU ξ hξ).2,P,hP,hPe,hPc⟩ + · let D : ℝ := 1+‖F‖ + have hD : 0 if hg : g∈H.level 2 then + mFourier k (torusProjection (tailCoordinates c (H.level 2) htail) ⟨g,hg⟩) else 1 + have hχ : ∀ g∈H.level 2, ‖χ g‖=1 := by + intro g hg + simp only [χ,dite_eq_left hg] + exact TorusVerticalFourier.character_norm _ _ + have hright : ∀ a∈H.level 2, ∀ g : G, + F' (QuotientGroup.mk (g*a))=χ a*F' (QuotientGroup.mk g) := by + intro a ha g + have he := hw' (torusProjection (tailCoordinates c (H.level 2) htail) ⟨a,ha⟩) (QuotientGroup.mk g) + rw [tailProjection_vadd c hsk (H.level 2) Γ hcent htail hΓ] at he + simpa only [χ,dite_eq_left ha] using he + obtain ⟨s,hs⟩ := TorusVerticalFourier.character_nontrivial hk + obtain ⟨a,ha⟩ := torusProjection_surjective (tailCoordinates c (H.level 2) htail) s + have hχa : χ a.val≠1 := by simpa only [χ,dite_eq_left a.property,ha] using hs + obtain ⟨U,A,hA,N₀,hN₀,hprod⟩ := quadratic_source_vertical_correlation c hsk H h0 h1 + (show H.level 3=⊥ from ‹H.level 3=⊥›) hcomm q hqbound hq2 hq Γ hΓ F' hF' χ hχ hright a.val a.property hχa + (δ/D) (div_pos hδ hD) + refine ⟨U,A,hA,N₀,hN₀,?_⟩ + intro N hN f hf hf0 hdisc + apply hprod N hN f hf hf0 + have hzero := TorusVerticalFourier.integral_hasWeight_eq_zero μ F' hk hw' + have hdisc' : δ/D ≤ ‖FourierObstruction.discrepancy μ N (fun k => QuotientGroup.mk (f k)) F'‖ := by + change δ/D ≤ ‖FourierObstruction.discrepancy μ N _ ((D:ℂ)⁻¹ • F)‖ + rw [map_smul,norm_smul,norm_inv,Complex.norm_real,Real.norm_eq_abs,abs_of_pos hD,div_eq_inv_mul] + exact mul_le_mul_of_nonneg_left hdisc (inv_nonneg.mpr hD.le) + change δ/D ≤ ‖mean N (fun n => F' (QuotientGroup.mk (f n)))-(∫ x,F' x ∂μ)‖ at hdisc' + simpa only [hzero,sub_zero] using hdisc' + +end SquareInduction +end +end + + + + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice10.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice10.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a5b4ab42ce21b7e791abeddbdf1d919723c8e89 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice10.lean @@ -0,0 +1,269 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CubeLocal09 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped BigOperators +end +end + + + +section +noncomputable section +open scoped BigOperators Topology commutatorElement NNReal +namespace CubeLocalHaar +open CubeFaces LeibmanSquare CubeTaylorExpansion CubeHorizontalIrrationality +open RationalLattice MeasureTheory Filter ComparableBoxLeibman MalcevCharacters AbelianMalcevTorus +variable {G ι : Type} [Group G] [PseudoMetricSpace G] [IsTopologicalGroup G] +variable [Fintype ι] [DecidableEq ι] +variable {n t d v : ℕ} (c : RealCoordinates G n) (H : Filtration G) +variable (S : ℕ→Set (Fin n)) +variable (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i∈S k,c.coord g i=0) +variable (Λ : Subgroup G) (σ : G) (h01 : H.level 0=H.level 1) +variable (s : ℕ) (hs : H.level (s+1)=⊥) (e : Option ι≃Fin v) +variable (cc : RealCoordinates (cube H (Finset.univ : Finset ι) 0) (t+d)) +variable (hsk : SecondKind cc) +variable (q : ℕ→ℕ) (hqbound : ∀ k,q k ≤ t+d) +variable (hq : ∀ k (g : cube H (Finset.univ : Finset ι) 0), + g∈(CubeMaxFiltration.filtration H Finset.univ).level k ↔ + ∀ i : Fin (t+d),i.val < q k → cc.coord g i=0) +variable (hΓ : ∀ g : cube H (Finset.univ : Finset ι) 0, + g∈cubeLattice H (conjugateLattice Λ σ) ↔ ∀ i,∃ z : ℤ,cc.coord g i=z) +variable [MeasurableSpace ((cube H (Finset.univ : Finset ι) 0)⧸cubeLattice H (conjugateLattice Λ σ))] +variable [hBorel : @BorelSpace ((cube H (Finset.univ : Finset ι) 0)⧸cubeLattice H (conjugateLattice Λ σ)) (QuotientGroup.instTopologicalSpace (cubeLattice H (conjugateLattice Λ σ))) inferInstance] +variable (mtr : MetricSpace ((cube H (Finset.univ : Finset ι) 0)⧸cubeLattice H (conjugateLattice Λ σ))) +variable (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace (cubeLattice H (conjugateLattice Λ σ))) + +variable [MeasurableSpace (G⧸Λ)] [BorelSpace (G⧸Λ)] +variable [SecondCountableTopology (G⧸Λ)] + +variable [CompactSpace (G⧸Λ)] +variable (qmtr : MetricSpace (G⧸Λ)) +variable (hqtop : qmtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Λ) + +include S hH h01 hs hsk hqbound hq hΓ htop hqtop in + + +theorem source_comparable_physical_cube_haar + (μ : Measure ((cube H (Finset.univ : Finset ι) 0)⧸cubeLattice H (conjugateLattice Λ σ))) + [IsProbabilityMeasure μ] + [SMulInvariantMeasure (cube H (Finset.univ : Finset ι) 0) _ μ] + (a : ℕ→∀ k : ℕ,H.level k) + (hirr : ∀ j : ℕ,0 < j → j ≤ s → ∀ ξ : H.level j→*Multiplicative ℝ, + ξ≠1 → Continuous ξ → RationalCharacter (conjugateLattice Λ σ) ξ → + (∀ x (hx : x∈H.level (j+1)),ξ ⟨x,H.antitone (Nat.le_succ _) hx⟩=1) → + (∀ i k : ℕ,0 < i → 0 < k → ∀ h : i+k=j, + ∀ x (hx : x∈H.level i) y (hy : y∈H.level k), + ξ ⟨⁅x,y⁆,by rw [←h]; exact H.commutator_le i k (Subgroup.commutator_mem_commutator hx hy)⟩=1) → + Tendsto (fun N : ℕ => ‖((ξ (a N j)).toAdd:UnitAddCircle)‖*(N:ℝ)^j) + atTop atTop) + + (d₀ r₀ : ℕ) (hd₀ : 0 h β) + ∀ ε : ℝ,0<ε → ∀ᶠ α : ℝ in 𝓝[>] 0,∀ᶠ N : ℕ in atTop, + ∀ lo hi : Fin v→ℝ, + (∀ i,(cBox*α)*(N:ℝ)≤hi i-lo i) → + (∀ i,-CBox*(N:ℝ)≤lo i ∧ hi i≤CBox*(N:ℝ)) → + (∀ b∈physicalResidueRectangle lo hi (sourceResidue e r₀) d₀, + |((b (e none):ℝ)/(N:ℝ))-β|≤C*α ∧ + ∀ i : ι,|((b (e (some i)):ℝ)/(N:ℝ))|≤C*α) → + ∀ F : C((Finset ι→G⧸Λ),ℂ), + LipschitzWith L F → ‖F‖≤B → + ‖(𝔼 b∈physicalResidueRectangle lo hi (sourceResidue e r₀) d₀, + F (fun w : Finset ι => QuotientGroup.mk + (P N (b (e none)+∑ i∈w,b (e (some i))))))- + (∫ y,F y ∂(m:Measure (Finset ι→G⧸Λ)))‖<ε := by + let : MetricSpace (G⧸Λ) := MetricSpace.replaceTopology qmtr hqtop.symm + intro m + have hd : 0<(d₀:ℝ) := by exact_mod_cast hd₀ + have hr : ∀ i : Fin v,0 ≤ sourceResidue e r₀ i ∧ sourceResidue e r₀ i<(d₀:ℤ) := by + intro i + have hd' : (0:ℤ) (lo i-(sourceResidue e r₀ i:ℝ))/(d₀:ℝ) + let hi' : Fin v→ℝ := fun i => (hi i-(sourceResidue e r₀ i:ℝ))/(d₀:ℝ) + have hs' : ∀ i,((cBox/(d₀:ℝ))*α)*(N:ℝ)≤hi' i-lo' i := by + intro i + have hh := div_le_div_of_nonneg_right (hside i) hd.le + dsimp only [hi',lo'] + have h₁ : ((cBox/(d₀:ℝ))*α)*(N:ℝ)=((cBox*α)*(N:ℝ))/(d₀:ℝ) := by ring + have h₂ : (hi i-(sourceResidue e r₀ i:ℝ))/(d₀:ℝ)- + (lo i-(sourceResidue e r₀ i:ℝ))/(d₀:ℝ)=(hi i-lo i)/(d₀:ℝ) := by ring + rw [h₁,h₂] + exact hh + have ha' : ∀ i,-C'*(N:ℝ)≤lo' i ∧ hi' i≤C'*(N:ℝ) := by + intro i + have hn : (1:ℝ)≤N := by exact_mod_cast hN1 + have hr0 : (0:ℝ)≤(sourceResidue e r₀ i:ℝ) := by exact_mod_cast (hr i).1 + have hrd : (sourceResidue e r₀ i:ℝ)<(d₀:ℝ) := by exact_mod_cast (hr i).2 + dsimp only [lo',hi',C'] + rw [le_div_iff₀ hd,div_le_iff₀ hd] + have hx : -((CBox+(d₀:ℝ))/(d₀:ℝ))*(N:ℝ)*(d₀:ℝ)= + -(CBox+(d₀:ℝ))*(N:ℝ) := by field_simp + have hy : ((CBox+(d₀:ℝ))/(d₀:ℝ))*(N:ℝ)*(d₀:ℝ)= + (CBox+(d₀:ℝ))*(N:ℝ) := by field_simp + rw [hx,hy] + constructor <;> nlinarith [(habs i).1,(habs i).2] + have hl' : ∀ z∈halfOpenBox v lo' hi', + |(((sourceResidue e r₀ (e none)+(d₀:ℤ)*z (e none):ℤ):ℝ)/(N:ℝ))-β|≤C*α ∧ + ∀ i : ι,|(((sourceResidue e r₀ (e (some i))+(d₀:ℤ)*z (e (some i)):ℤ):ℝ)/(N:ℝ))|≤C*α := by + intro z hz + exact hlocal _ ((physicalResidueRectangle_affine lo hi (sourceResidue e r₀) d₀ hd₀ hr z).mpr hz) + rw [physicalResidueRectangle_expect lo hi (sourceResidue e r₀) d₀ hd₀ hr] + simp_rw [hv] + exact hN lo' hi' hs' ha' hl' F hL hB + +end CubeLocalHaar +end +end + + +end + +section + + + +noncomputable section +namespace RationalLattice +variable {G K : Type*} [Group G] [Group K] [TopologicalSpace G] [TopologicalSpace K] +variable {m n : ℕ} + +lemma scaledCoordinates_rational (d : RealCoordinates K n) (w : Fin n → ℕ) + (hpos : ∀ i,0 c.coord (F (d.coord.symm x)) i)) + +include hpoly in +lemma rationalHom_rational {g : K} (hg : IsRational d g) : IsRational c (F g) := by + intro i + obtain ⟨P,hP⟩:=hpoly i + obtain ⟨q,hq⟩:=eval_rational P (d.coord g) hg + refine ⟨q,?_⟩ + rw [hq,←hP] + simp + +variable [IsTopologicalGroup G] [IsTopologicalGroup K] +variable (Γ : Subgroup G) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable (hc : Continuous F) (hinj : Function.Injective F) +include hpoly hΓ hc hinj in + + +theorem exists_integer_sublattice_rational : + ∃ Λ : Subgroup K,∃ e : RealCoordinates K n, + (∀ g : K,g∈Λ ↔ ∀ i,∃ z : ℤ,e.coord g i=z) ∧ + Λ≤Γ.comap F ∧ (Λ.subgroupOf (Γ.comap F)).FiniteIndex ∧ + (∀ g : K,∀ i,e.coord g i=0 ↔ d.coord g i=0) ∧ + (∀ g : K,IsRational e g ↔ IsRational d g) := by + classical + obtain ⟨E,hE,hgrid⟩:=rationalHom_origin_grid c d F hpoly + obtain ⟨w,hpos,hEw,hw⟩:=exists_lattice_weights d E hE + let Λ:=weightedLattice d w hw + let e:=scaledCoordinates d w hpos + have hΛ : ∀ g : K,g∈Λ ↔ ∀ i,∃ z : ℤ,e.coord g i=z := + weightedLattice_iff d w hw hpos + have hle : Λ≤Γ.comap F := by + intro g hg + apply (hΓ (F g)).mpr + have hx : ∀ j,∃ z : ℤ,d.coord g j=(E:ℝ)*(z:ℝ) := by + intro j + obtain ⟨a,ha⟩:=hg j + obtain ⟨b,hb⟩:=hEw j + refine ⟨(b:ℤ)*a,?_⟩ + rw [ha,hb] + push_cast + ring + simpa using hgrid (d.coord g) hx + let : T2Space K:=d.coord.symm.t2Space + let : DiscreteTopology Γ:=integerCoordinates_discrete c Γ hΓ + let : DiscreteTopology (Γ.comap F):= + DiscreteTopology.preimage_of_continuous_injective (Γ:Set G) hc hinj + obtain ⟨C,hC,hrep⟩:=compact_reps_of_integerCoordinates e Λ hΛ + have hi:=TriangularDenominators.finiteIndex_of_compact_reps Λ (Γ.comap F) hle C hC hrep + refine ⟨Λ,e,hΛ,hle,hi,?_,scaledCoordinates_rational d w hpos⟩ + intro g i + change d.coord g i/(w i:ℝ)=0 ↔ d.coord g i=0 + rw [div_eq_zero_iff] + have hn : (w i:ℝ)≠0 := by exact_mod_cast (hpos i).ne' + simp [hn] + +end RationalLattice + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice11.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice11.lean new file mode 100644 index 0000000000000000000000000000000000000000..032bcdf8d28bf699cb1eb4ad1cb8c867825fc7ff --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice11.lean @@ -0,0 +1,307 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalTriangular01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +lemma natpow_prefix_eq (g h : G) (i : Fin n) + (he : ∀ j : Fin n,j < i → c.coord g j=c.coord h j) (m : ℕ) : + ∀ j : Fin n,j < i → c.coord (g^m) j=c.coord (h^m) j := by + induction m with + | zero => intro j hj; simp + | succ m ih => + intro j hj + rw [pow_succ,pow_succ,c.mul_coord,c.mul_coord,ih j hj,he j hj] + congr 1 + apply congrArg (fun a=>MvPolynomial.eval₂ (algebraMap ℚ ℝ) a (c.correction j)) + funext a + cases a with + | inl k => exact ih _ (lt_trans k.isLt hj) + | inr k => exact he _ (lt_trans k.isLt hj) + +lemma powerPolynomial_sub_of_prefix_eq (g h : G) (i : Fin n) + (he : ∀ j : Fin n,j < i → c.coord g j=c.coord h j) : + powerPolynomial c g i-powerPolynomial c h i=X*C (c.coord g i-c.coord h i) := by + apply Polynomial.eq_of_eval_nat_eq + intro m + simp only [eval_sub,powerPolynomial_nat,eval_mul,eval_X,eval_C] + induction m with + | zero => simp [c.one_coord] + | succ m ih => + rw [pow_succ,pow_succ,c.mul_coord,c.mul_coord] + have hh : (Sum.elim (fun j : Fin i.val=>c.coord (g^m) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val=>c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩))= + (Sum.elim (fun j : Fin i.val=>c.coord (h^m) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val=>c.coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) := by + funext a + cases a with + | inl j => exact natpow_prefix_eq c g h i he m _ j.isLt + | inr j => exact he _ j.isLt + rw [hh] + push_cast + linarith + +def canonicalLog (g : G) (i : Fin n) : ℝ := (powerPolynomial c g i).coeff 1 + +lemma canonicalLog_sub_of_prefix_eq (g h : G) (i : Fin n) + (he : ∀ j : Fin n,j < i → c.coord g j=c.coord h j) : + canonicalLog c g i-canonicalLog c h i=c.coord g i-c.coord h i := by + have hh:=congrArg (fun p : ℝ[X]=>p.coeff 1) (powerPolynomial_sub_of_prefix_eq c g h i he) + simpa [canonicalLog,Polynomial.coeff_X_mul] using hh + +lemma canonicalLog_polynomial (i : Fin n) : RationalPolynomialMap.IsPolynomial + (fun x=>canonicalLog c (c.coord.symm x) i) := by + refine ⟨(universalPowerPolynomial c i).coeff 1,?_⟩ + intro x + simp only [canonicalLog,powerPolynomial_eq_universal,Polynomial.coeff_map, + Homeomorph.apply_symm_apply] + rfl + +def prefixSection (i : Fin n) (x : Fin i.val → ℝ) (j : Fin n) : ℝ := + if h : j < i then x ⟨j.val,h⟩ else 0 + +lemma prefixSection_polynomial (i j : Fin n) : RationalPolynomialMap.IsPolynomial + (fun x=>prefixSection i x j) := by + unfold prefixSection + split_ifs with h + · exact RationalPolynomialMap.coordinate _ + · exact RationalPolynomialMap.zero + +lemma logCorrection_exists (i : Fin n) : ∃ p : MvPolynomial (Fin i.val) ℚ, + ∀ x,canonicalLog c (c.coord.symm (prefixSection i x)) i= + MvPolynomial.eval₂ (algebraMap ℚ ℝ) x p := + RationalPolynomialMap.comp (canonicalLog_polynomial c i) (prefixSection_polynomial i) + +def logCorrection (i : Fin n) : MvPolynomial (Fin i.val) ℚ := (logCorrection_exists c i).choose + +lemma logCorrection_eval (i : Fin n) (x : Fin i.val → ℝ) : + canonicalLog c (c.coord.symm (prefixSection i x)) i= + MvPolynomial.eval₂ (algebraMap ℚ ℝ) x (logCorrection c i) := + (logCorrection_exists c i).choose_spec x + +lemma canonicalLog_eq_forward (g : G) : canonicalLog c g= + RationalTriangularChange.forward (logCorrection c) (c.coord g) := by + funext i + let x : Fin i.val → ℝ := fun j=>c.coord g ⟨j.val,lt_trans j.isLt i.isLt⟩ + let h:=c.coord.symm (prefixSection i x) + have hp : ∀ j : Fin n,j < i → c.coord g j=c.coord h j := by + intro j hj + simp only [h,Homeomorph.apply_symm_apply,prefixSection,dite_eq_left hj] + rfl + have hh:=canonicalLog_sub_of_prefix_eq c g h i hp + have hz : c.coord h i=0 := by simp [h,prefixSection] + rw [hz,sub_zero,logCorrection_eval] at hh + exact (sub_eq_iff_eq_add.mp hh).trans (by rfl) + +def logHomeomorph : G ≃ₜ (Fin n → ℝ) := + c.coord.trans (RationalTriangularChange.homeomorph (logCorrection c)) + +lemma logHomeomorph_apply (g : G) : logHomeomorph c g=canonicalLog c g := + (canonicalLog_eq_forward c g).symm + +def canonicalExp (x : Fin n → ℝ) : G := (logHomeomorph c).symm x + +@[simp] lemma canonicalLog_exp (x : Fin n → ℝ) : canonicalLog c (canonicalExp c x)=x := by + rw [← logHomeomorph_apply] + exact (logHomeomorph c).apply_symm_apply x + +@[simp] lemma canonicalExp_log (g : G) : canonicalExp c (canonicalLog c g)=g := by + rw [← logHomeomorph_apply] + exact (logHomeomorph c).symm_apply_apply g + +lemma canonicalExp_polynomial : IsPolynomialMap c (canonicalExp c) := by + intro i + have he (x : Fin n → ℝ) : c.coord (canonicalExp c x)= + RationalTriangularChange.inverse (logCorrection c) x := by + change c.coord (c.coord.symm (RationalTriangularChange.inverse (logCorrection c) x))=_ + exact c.coord.apply_symm_apply _ + simpa only [he] using RationalTriangularChange.inverse_polynomial (logCorrection c) i + +lemma canonicalLog_continuous : Continuous (canonicalLog c) := by + have he : canonicalLog c=(logHomeomorph c) := funext (fun x=>(logHomeomorph_apply c x).symm) + rw [he] + exact (logHomeomorph c).continuous + +lemma canonicalExp_continuous : Continuous (canonicalExp c) := (logHomeomorph c).symm.continuous + +lemma realPower_nat_mul (g : G) (t : ℝ) (m : ℕ) : + realPower c g (t*m)=(realPower c g t)^m := by + induction m with + | zero => simp + | succ m ih => + rw [Nat.cast_succ,mul_add,mul_one,realPower_add,ih,pow_succ] + +lemma powerPolynomial_realPower (g : G) (t : ℝ) (i : Fin n) : + powerPolynomial c (realPower c g t) i=(powerPolynomial c g i).comp (C t*X) := by + apply Polynomial.eq_of_eval_nat_eq + intro m + rw [powerPolynomial_nat,eval_comp,eval_mul,eval_C,eval_X,← realPower_coord,realPower_nat_mul] + +lemma canonicalLog_realPower (g : G) (t : ℝ) : + canonicalLog c (realPower c g t)=t • canonicalLog c g := by + funext i + simp only [canonicalLog,powerPolynomial_realPower,comp_C_mul_X_coeff,pow_one, + Pi.smul_apply,smul_eq_mul] + exact mul_comm _ _ + +@[simp] lemma canonicalLog_one : canonicalLog c (1:G)=0 := by + simpa using canonicalLog_realPower c (1:G) 0 + +@[simp] lemma canonicalExp_zero : canonicalExp c 0=(1:G) := by + apply (logHomeomorph c).injective + simp only [logHomeomorph_apply,canonicalLog_exp,canonicalLog_one] + +lemma canonicalExp_smul (x : Fin n → ℝ) (t : ℝ) : + canonicalExp c (t • x)=realPower c (canonicalExp c x) t := by + apply (logHomeomorph c).injective + simp only [logHomeomorph_apply,canonicalLog_exp,canonicalLog_realPower] + +lemma canonicalLog_prefix_zero (g : G) (k : ℕ) + (hg : ∀ i : Fin n,i.val simp [c.one_coord] + | succ m ih => + rw [pow_succ,coord_mul_of_right_zero c _ _ i (fun j hj=>hg j (lt_trans hj hi)),ih,hg i hi] + exact zero_add 0 + simp only [canonicalLog,he,coeff_zero] + +lemma coord_prefix_zero_of_log (g : G) (k : ℕ) + (hg : ∀ i : Fin n,i.val + intro hj hk + have hh:=canonicalLog_sub_of_prefix_eq c g 1 ⟨j,hj⟩ (by + intro l hl + rw [ih l.val hl l.isLt (lt_trans hl hk),c.one_coord]) + simpa only [hg ⟨j,hj⟩ hk,canonicalLog_one,Pi.zero_apply,sub_self,c.one_coord,sub_zero] using hh.symm + exact fun i hi=>h i.val i.isLt hi + +lemma canonicalLog_prefix_zero_iff (g : G) (k : ℕ) : + (∀ i : Fin n,i.vala) := ⟨MvPolynomial.C a,by simp⟩ +lemma coordinate (i : σ) : IsPolynomial (fun x : σ → ℝ=>x i) := ⟨MvPolynomial.X i,by simp⟩ +lemma add {f g : (σ → ℝ) → ℝ} (hf : IsPolynomial f) (hg : IsPolynomial g) : + IsPolynomial (fun x=>f x+g x) := by + obtain ⟨p,hp⟩:=hf + obtain ⟨q,hq⟩:=hg + exact ⟨p+q,by simp [hp,hq]⟩ +lemma mul {f g : (σ → ℝ) → ℝ} (hf : IsPolynomial f) (hg : IsPolynomial g) : + IsPolynomial (fun x=>f x*g x) := by + obtain ⟨p,hp⟩:=hf + obtain ⟨q,hq⟩:=hg + exact ⟨p*q,by simp [hp,hq]⟩ +lemma neg {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) : IsPolynomial (fun x=>-f x) := by + obtain ⟨p,hp⟩:=hf + exact ⟨-p,by simp [hp]⟩ +lemma eval {f : τ → (σ → ℝ) → ℝ} (hf : ∀ i,IsPolynomial (f i)) (p : MvPolynomial τ ℝ) : + IsPolynomial (fun x=>MvPolynomial.eval (fun i=>f i x) p) := by + induction p using MvPolynomial.induction_on with + | C a => simpa using const (σ:=σ) a + | add p q hp hq => simpa using add hp hq + | mul_X p i hp => simpa using mul hp (hf i) +lemma rational_eval {f : τ → (σ → ℝ) → ℝ} (hf : ∀ i,IsPolynomial (f i)) + (p : MvPolynomial τ ℚ) : + IsPolynomial (fun x=>MvPolynomial.eval₂ (algebraMap ℚ ℝ) (fun i=>f i x) p) := by + simpa only [MvPolynomial.eval_map] using eval hf (MvPolynomial.map (algebraMap ℚ ℝ) p) +lemma of_rational {f : (σ → ℝ) → ℝ} (hf : RationalPolynomialMap.IsPolynomial f) : + IsPolynomial f := by + obtain ⟨p,hp⟩:=hf + exact ⟨MvPolynomial.map (algebraMap ℚ ℝ) p,by simp only [MvPolynomial.eval_map,← hp]; simp⟩ +lemma comp {f : (τ → ℝ) → ℝ} (hf : IsPolynomial f) {g : (σ → ℝ) → (τ → ℝ)} + (hg : ∀ i,IsPolynomial (fun x=>g x i)) : IsPolynomial (fun x=>f (g x)) := by + obtain ⟨p,hp⟩:=hf + simpa only [hp] using eval hg p +lemma polynomial_eval (p : Polynomial ℝ) {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) : + IsPolynomial (fun x=>p.eval (f x)) := by + induction p using Polynomial.induction_on' with + | add p q hp hq => simpa using add hp hq + | monomial i a => + have hpow : IsPolynomial (fun x=>(f x)^i) := by + induction i with + | zero => simpa using const (σ:=σ) 1 + | succ i ih => simpa [pow_succ] using mul ih hf + simpa using mul (const a) hpow + +lemma contDiff_eval [Fintype σ] (p : MvPolynomial σ ℝ) : + ContDiff ℝ ⊤ (fun x : σ → ℝ=>MvPolynomial.eval x p) := by + induction p using MvPolynomial.induction_on with + | C a => simpa using (contDiff_const : ContDiff ℝ ⊤ (fun _ : σ → ℝ=>a)) + | add p q hp hq => simpa using hp.add hq + | mul_X p i hp => simpa using hp.mul (contDiff_apply ℝ ℝ i) + +lemma contDiff [Fintype σ] {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) : ContDiff ℝ ⊤ f := by + obtain ⟨p,hp⟩:=hf + have he : f=(fun x=>MvPolynomial.eval x p) := funext hp + rw [he] + exact contDiff_eval p + +lemma homogeneous_eq_fderiv {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F} + (hf : DifferentiableAt ℝ f 0) (hh : ∀ t : ℝ,∀ x,f (t • x)=t • f x) (x : E) : + (fderiv ℝ f 0) x=f x := by + have hr : HasDerivAt (fun t : ℝ=>t • x) x 0 := by + simpa using (hasDerivAt_id (0:ℝ)).smul_const x + have h₁ : HasDerivAt (fun t : ℝ=>f (t • x)) ((fderiv ℝ f 0) x) 0 := by + have hf' : HasFDerivAt f (fderiv ℝ f 0) ((0:ℝ) • x) := by simpa using hf.hasFDerivAt + exact hf'.comp_hasDerivAt 0 hr + have h₂ : HasDerivAt (fun t : ℝ=>f (t • x)) (f x) 0 := by + simpa only [hh,one_smul,id_eq] using (hasDerivAt_id (0:ℝ)).smul_const (f x) + exact h₁.unique h₂ + +end RealPolynomialMap + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice12.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice12.lean new file mode 100644 index 0000000000000000000000000000000000000000..79b11861bb39bdb79f0e2df145ce7cb3fdb860bc --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice12.lean @@ -0,0 +1,315 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice11 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalLattice +open MalcevCharacters RationalLevelFlow +variable {G H : Type*} [Group G] [Group H] +variable [TopologicalSpace G] [TopologicalSpace H] +variable [IsTopologicalGroup G] [IsTopologicalGroup H] +variable {m n : ℕ} (c : RealCoordinates G m) (d : RealCoordinates H n) + +def IsRealPolynomialMap {σ : Type*} (f : (σ → ℝ) → G) : Prop := + ∀ i,RealPolynomialMap.IsPolynomial (fun x=>c.coord (f x) i) + +omit [IsTopologicalGroup G] in +lemma realPolynomialMap_one [IsTopologicalGroup G] {σ : Type*} : IsRealPolynomialMap c (fun _ : σ → ℝ=>(1:G)) := by + intro i + simpa only [c.one_coord] using RealPolynomialMap.const (σ:=σ) 0 + +omit [IsTopologicalGroup G] in +lemma realPolynomialMap_mul [IsTopologicalGroup G] {σ : Type*} {f g : (σ → ℝ) → G} + (hf : IsRealPolynomialMap c f) (hg : IsRealPolynomialMap c g) : + IsRealPolynomialMap c (fun x=>f x*g x) := by + intro i + have hp : RealPolynomialMap.IsPolynomial (fun x=>MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j : Fin i.val=>c.coord (f x) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val=>c.coord (g x) ⟨j.val,lt_trans j.isLt i.isLt⟩)) (c.correction i)) := by + apply RealPolynomialMap.rational_eval + intro j + cases j with + | inl j => exact hf _ + | inr j => exact hg _ + simpa only [c.mul_coord] using RealPolynomialMap.add (RealPolynomialMap.add (hf i) (hg i)) hp + +lemma realPolynomialMap_list_prod {σ : Type*} (V : List ((σ → ℝ) → G)) + (hV : ∀ f∈V,IsRealPolynomialMap c f) : + IsRealPolynomialMap c (fun x=>(V.map (fun f=>f x)).prod) := by + induction V with + | nil => simpa using realPolynomialMap_one c + | cons f V ih => + simpa using realPolynomialMap_mul c (hV f (by simp)) (ih (fun f hf=>hV f (by simp [hf]))) + +omit [IsTopologicalGroup G] in +lemma realPolynomialMap_realPower [IsTopologicalGroup G] {σ : Type*} (g : G) {f : (σ → ℝ) → ℝ} + (hf : RealPolynomialMap.IsPolynomial f) : + IsRealPolynomialMap c (fun x=>realPower c g (f x)) := by + intro i + simpa only [realPower_coord] using RealPolynomialMap.polynomial_eval (powerPolynomial c g i) hf + +omit [IsTopologicalGroup H] in +lemma map_realPower [IsTopologicalGroup H] (F : H →* G) (hF : Continuous F) (g : H) (t : ℝ) : + F (realPower d g t)=realPower c (F g) t := by + let A : Multiplicative ℝ →* H := + { toFun := fun t=>realPower d g t.toAdd + map_one' := realPower_zero d g + map_mul' := fun t u=>realPower_add d g t.toAdd u.toAdd } + have he:=continuous_flow_eq_realPower c (F.comp A) + (hF.comp ((realPower_continuous d g).comp continuous_toAdd)) t + change F (realPower d g t)=realPower c (F (realPower d g 1)) t at he + simpa only [realPower_one] using he + +omit [IsTopologicalGroup H] in +theorem realHom_polynomial [IsTopologicalGroup H] (hsk : SecondKind d) (F : H →* G) (hF : Continuous F) : + IsRealPolynomialMap c (fun x : Fin n → ℝ=>F (d.coord.symm x)) := by + let A (i : Fin n) : Multiplicative ℝ →* H := + { toFun := fun t=>axis d i t.toAdd + map_one' := axis_zero d i + map_mul' := fun t u=>hsk.axis_add i t.toAdd u.toAdd } + have he (i : Fin n) (t : ℝ) : F (axis d i t)=realPower c (F (axis d i 1)) t := + continuous_flow_eq_realPower c (F.comp (A i)) + (hF.comp ((axis_continuous d i).comp continuous_toAdd)) t + have hp (i : Fin n) : IsRealPolynomialMap c (fun x : Fin n → ℝ=>F (axis d i (x i))) := by + have hfun : (fun x : Fin n → ℝ=>F (axis d i (x i)))= + (fun x=>realPower c (F (axis d i 1)) (x i)) := funext (fun x=>he i (x i)) + rw [hfun] + exact realPolynomialMap_realPower c _ (RealPolynomialMap.coordinate i) + have hprod:=realPolynomialMap_list_prod c (List.ofFn (fun i : Fin n=> + (fun x : Fin n → ℝ=>F (axis d i (x i))))) (by + intro f hf + obtain ⟨i,rfl⟩:=List.mem_ofFn.mp hf + exact hp i) + have hw (x : Fin n → ℝ) : F (d.coord.symm x)= + ((List.ofFn (fun i : Fin n=>(fun x : Fin n → ℝ=>F (axis d i (x i))))).map + (fun f=>f x)).prod := by + conv_lhs => rw [hsk.ordered (d.coord.symm x)] + rw [map_list_prod,List.map_ofFn,List.map_ofFn] + simp only [Homeomorph.apply_symm_apply,Function.comp_def] + simpa only [← hw] using hprod + +def logHom (F : H →* G) (x : Fin n → ℝ) : Fin m → ℝ := + canonicalLog c (F (canonicalExp d x)) + +lemma logHom_polynomial (hsk : SecondKind d) (F : H →* G) (hF : Continuous F) (i : Fin m) : + RealPolynomialMap.IsPolynomial (fun x=>logHom c d F x i) := by + have hexp (j : Fin n) : RealPolynomialMap.IsPolynomial + (fun x=>d.coord (canonicalExp d x) j) := + RealPolynomialMap.of_rational (canonicalExp_polynomial d j) + have hh (j : Fin m) : RealPolynomialMap.IsPolynomial + (fun x=>c.coord (F (canonicalExp d x)) j) := by + simpa only [Homeomorph.symm_apply_apply] using + RealPolynomialMap.comp (realHom_polynomial c d hsk F hF j) hexp + simpa only [logHom,Homeomorph.symm_apply_apply] using + RealPolynomialMap.comp (RealPolynomialMap.of_rational (canonicalLog_polynomial c i)) hh + +lemma logHom_smul (F : H →* G) (hF : Continuous F) (t : ℝ) (x : Fin n → ℝ) : + logHom c d F (t • x)=t • logHom c d F x := by + simp only [logHom,canonicalExp_smul,map_realPower c d F hF,canonicalLog_realPower] + +lemma logHom_contDiff (hsk : SecondKind d) (F : H →* G) (hF : Continuous F) : + ContDiff ℝ ⊤ (logHom c d F) := + contDiff_pi.mpr (fun i=>RealPolynomialMap.contDiff (logHom_polynomial c d hsk F hF i)) + +def logHomLinear (F : H →* G) : (Fin n → ℝ) →L[ℝ] (Fin m → ℝ) := + fderiv ℝ (logHom c d F) 0 + +lemma logHomLinear_apply (hsk : SecondKind d) (F : H →* G) (hF : Continuous F) + (x : Fin n → ℝ) : logHomLinear c d F x=logHom c d F x := + RealPolynomialMap.homogeneous_eq_fderiv + ((logHom_contDiff c d hsk F hF).differentiable (by simp)).differentiableAt + (logHom_smul c d F hF) x + +lemma map_canonicalExp (hsk : SecondKind d) (F : H →* G) (hF : Continuous F) + (x : Fin n → ℝ) : F (canonicalExp d x)=canonicalExp c (logHomLinear c d F x) := by + rw [logHomLinear_apply c d hsk F hF,logHom,canonicalExp_log] + +lemma logHomLinear_log (hsk : SecondKind d) (F : H →* G) (hF : Continuous F) (g : H) : + logHomLinear c d F (canonicalLog d g)=canonicalLog c (F g) := by + rw [logHomLinear_apply c d hsk F hF,logHom,canonicalExp_log] + +end RationalLattice +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters IntegerHyperplane +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (k : Fin (n+1) → ℤ) (p : Fin (n+1)) +variable (hp : k p ≠ 0) +variable (hχ : ∀ g : G,(χ g).toAdd=form k (c.coord g)) + +def sectionFlow : Multiplicative ℝ →* G where + toFun t := axis c p (t.toAdd/(k p:ℝ)) + map_one' := by simp + map_mul' t u := by change axis c p ((t.toAdd+u.toAdd)/(k p:ℝ))=_; rw [add_div,hsk.axis_add] + +omit [IsTopologicalGroup G] in +lemma sectionFlow_continuous [IsTopologicalGroup G] : Continuous (sectionFlow c hsk k p) := + (axis_continuous c p).comp (continuous_toAdd.div_const _) + +include hp hχ in +omit [IsTopologicalGroup G] in +lemma sectionFlow_character [IsTopologicalGroup G] (t : ℝ) : + (χ (sectionFlow c hsk k p (Multiplicative.ofAdd t))).toAdd=t := by + classical + change (χ (axis c p (t/(k p:ℝ)))).toAdd=t + rw [hχ,coord_axis] + change (∑ i,(k i:ℝ)*(Pi.single p (t/(k p:ℝ)) : Fin (n+1) → ℝ) i)=t + simp only [Pi.single_apply,mul_ite,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + exact mul_div_cancel₀ t (by exact_mod_cast hp) + +omit [IsTopologicalGroup G] in +lemma sectionFlow_rational [IsTopologicalGroup G] (t : ℚ) : + IsRational c (sectionFlow c hsk k p (Multiplicative.ofAdd (t:ℝ))) := by + classical + intro i + refine ⟨if i=p then t/(k p:ℚ) else 0,?_⟩ + change _=c.coord (axis c p ((t:ℝ)/(k p:ℝ))) i + rw [coord_axis] + simp only [Pi.single_apply] + split_ifs <;> push_cast <;> rfl + +omit [IsTopologicalGroup G] in +lemma sectionFlow_polynomial [IsTopologicalGroup G] {σ : Type*} {f : (σ → ℝ) → ℝ} + (hf : RealPolynomialMap.IsPolynomial f) : + IsRealPolynomialMap c (fun x=>sectionFlow c hsk k p (Multiplicative.ofAdd (f x))) := by + classical + intro i + change RealPolynomialMap.IsPolynomial (fun x=>c.coord (axis c p (f x/(k p:ℝ))) i) + simp only [coord_axis,Pi.single_apply] + split_ifs + · simpa [div_eq_mul_inv] using RealPolynomialMap.mul hf (RealPolynomialMap.const (k p:ℝ)⁻¹) + · exact RealPolynomialMap.const 0 + +lemma sectionFlow_exponential (t : ℝ) : + canonicalExp c (t • canonicalLog c (sectionFlow c hsk k p (Multiplicative.ofAdd 1)))= + sectionFlow c hsk k p (Multiplicative.ofAdd t) := by + rw [canonicalExp_smul,canonicalExp_log] + exact (RationalLevelFlow.continuous_flow_eq_realPower c (sectionFlow c hsk k p) + (sectionFlow_continuous c hsk k p) t).symm + +variable (Γ : Subgroup G) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + +include hp hΓ in +omit [IsTopologicalGroup G] in +lemma sectionFlow_period [IsTopologicalGroup G] : ∃ K : ℕ,0(z:ℝ)) (Int.natAbs_sq (k p)) + simpa only [Int.cast_pow,Int.cast_natCast,Nat.cast_pow] using hh + have hpR : (k p:ℝ)≠0 := by exact_mod_cast hp + have hdiv : (((k p).natAbs^2:ℕ):ℝ)/(k p:ℝ)=(k p:ℝ) := by + rw [he,pow_two,mul_div_cancel_right₀ _ hpR] + intro i + change ∃ z : ℤ,c.coord (axis c p ((((k p).natAbs^2:ℕ):ℝ)/(k p:ℝ))) i=(z:ℝ) + rw [hdiv,coord_axis] + classical + by_cases hi : i=p + · subst i + exact ⟨k p,by simp⟩ + · exact ⟨0,by simp [hi]⟩ + +omit [IsTopologicalGroup G] in +lemma same_coset_of_mod [IsTopologicalGroup G] (K : ℕ) + (hK : sectionFlow c hsk k p (Multiplicative.ofAdd (K:ℝ))∈Γ) + (z j : ℤ) (hmod : (K:ℤ)∣z-j) : + (QuotientGroup.mk (sectionFlow c hsk k p (Multiplicative.ofAdd (z:ℝ))) : G⧸Γ)= + QuotientGroup.mk (sectionFlow c hsk k p (Multiplicative.ofAdd (j:ℝ))) := by + apply QuotientGroup.eq.mpr + obtain ⟨q,hq⟩:=hmod + have hz : -(z:ℝ)+(j:ℝ)=(K:ℝ)*(-q:ℤ) := by + have hh : (z:ℝ)-(j:ℝ)=(K:ℝ)*(q:ℝ) := by exact_mod_cast hq + push_cast + linarith + have he : (sectionFlow c hsk k p (Multiplicative.ofAdd (z:ℝ)))⁻¹* + sectionFlow c hsk k p (Multiplicative.ofAdd (j:ℝ))= + sectionFlow c hsk k p (Multiplicative.ofAdd (K:ℝ))^(-q) := by + rw [← map_inv,← map_mul,← map_zpow] + congr 1 + apply Multiplicative.toAdd.injective + change -(z:ℝ)+(j:ℝ)=(-q) • (K:ℝ) + simpa [zsmul_eq_mul,mul_comm] using hz + rw [he] + exact Γ.zpow_mem hK _ + +variable (hlast : ∀ j : Fin (n+1),phh (p.succAbove i) + +end RoughKernelFactorization + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice13.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice13.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab8bea12b526fdd8d8b322759fb0c21260144ffa --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice13.lean @@ -0,0 +1,275 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CubePolynomials01 +import OAI.Combinatorics.SumProduct.Alignment.MalcevWeighted01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end +end + +end + +section + + + +section + + + +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +namespace Polynomial +open scoped _root_.Polynomial +lemma natDegree_le_of_taylor_sub (p : ℝ[X]) (d : ℕ) + (hp : ∀ t : ℝ,(_root_.Polynomial.taylor t p-p).natDegree ≤ d) : p.natDegree ≤ d+1 := by + have he : _root_.Polynomial.hasseDeriv (d+1) p=_root_.Polynomial.C (p.coeff (d+1)) := by + apply Polynomial.funext + intro t + have h:=_root_.Polynomial.coeff_eq_zero_of_natDegree_lt (lt_of_le_of_lt (hp t) (Nat.lt_succ_self d)) + rw [_root_.Polynomial.coeff_sub,_root_.Polynomial.taylor_coeff] at h + simpa only [_root_.Polynomial.eval_C] using sub_eq_zero.mp h + have hd:=congrArg Polynomial.natDegree he + rw [_root_.Polynomial.natDegree_hasseDeriv,_root_.Polynomial.natDegree_C] at hd + omega +end Polynomial + +namespace CubePolynomials +open CubeFaces +variable {G : Type*} [Group G] +lemma real_polynomial_mem (H : Filtration G) (A : Multiplicative ℝ →* G) + (e k : ℕ) (hA : ∀ t : ℝ,A (Multiplicative.ofAdd t)∈H.level (e+k)) + (p : ℝ[X]) (hp : p.natDegree ≤ e) : + (fun t : ℝ=>A (Multiplicative.ofAdd (p.eval t)))∈polynomials H k := by + induction e generalizing k p with + | zero => + have he : p=C (p.coeff 0) := eq_C_of_natDegree_eq_zero (Nat.eq_zero_of_le_zero hp) + rw [he] + simp only [eval_C] + exact const_mem (by simpa using hA (p.coeff 0)) + | succ e ih => + apply mem_of_derivatives + · intro t + exact H.antitone (Nat.le_add_left k (e+1)) (hA (p.eval t)) + · intro t + let q:=taylor t p-p + have hq : q.natDegree ≤ e := by + by_cases hp0 : p=0 + · simp [q,hp0] + by_cases hq0 : q=0 + · simp [hq0] + have hd : q.degree < p.degree := + degree_sub_lt_right (degree_taylor p t) hp0 (leadingCoeff_taylor t p) + have hd':q.natDegree < p.natDegree := (natDegree_lt_natDegree_iff hq0).mpr hd + omega + have hA' : ∀ t : ℝ,A (Multiplicative.ofAdd t)∈H.level (e+(k+1)) := by + simpa only [Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using hA + convert ih (k+1) hA' q hq using 1 + funext x + change (A (Multiplicative.ofAdd (p.eval x)))⁻¹*A (Multiplicative.ofAdd (p.eval (x+t)))= + A (Multiplicative.ofAdd (q.eval x)) + rw [← map_inv,← map_mul] + congr 1 + apply Multiplicative.toAdd.injective + simp [q,taylor_apply,eval_comp] + ring +end CubePolynomials + +namespace RationalLattice +open CubeFaces CubePolynomials MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) + +omit [IsTopologicalGroup G] in +lemma prefix_zero_inv (g : G) (i : Fin n) + (hz : ∀ j : Fin n,j < i → c.coord g j=0) : + ∀ j : Fin n,j < i → c.coord g⁻¹ j=0 := by + intro j hj + have hh:=coord_mul_of_right_zero c g⁻¹ g j (fun l hl=>hz l (lt_trans hl hj)) + rw [inv_mul_cancel,c.one_coord,hz j hj,add_zero] at hh + exact hh.symm + +omit [IsTopologicalGroup G] in +lemma coord_inv_of_prefix_zero (g : G) (i : Fin n) + (hz : ∀ j : Fin n,j < i → c.coord g j=0) : c.coord g⁻¹ i= -c.coord g i := by + have hh:=coord_mul_of_right_zero c g⁻¹ g i hz + rw [inv_mul_cancel,c.one_coord] at hh + linarith + +omit [IsTopologicalGroup G] in +lemma tail_coord_natDegree (H : Filtration G) (w : Fin n → ℕ) + (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + (i : Fin n) (d k : ℕ) (hdk : w i < k+d+1) + (f : ℝ → G) (hf : f∈polynomials H k) + (hz : ∀ t (j : Fin n),j < i → c.coord (f t) j=0) + (p : ℝ[X]) (hp : ∀ t,p.eval t=c.coord (f t) i) : p.natDegree ≤ d := by + induction d generalizing k f p with + | zero => + have hw : w i < k+1 := by omega + by_cases h : w i < k + · have he : p=0 := by + apply Polynomial.funext + intro t + rw [eval_zero,hp] + exact (hH k (f t)).mp (eval_mem hf t) i h + simp [he] + · + have hq (t : ℝ) : taylor t p-p=0 := by + apply Polynomial.funext + intro x + simp only [eval_sub,taylor_apply,eval_comp,eval_add,eval_X,eval_C,eval_zero,hp] + have hh: c.coord ((f x)⁻¹*f (x+t)) i=0 := + (hH (k+1) _).mp (eval_mem (derivative_mem hf t) x) i hw + rw [coord_mul_of_left_zero c _ _ i (prefix_zero_inv c _ i (hz x)), + coord_inv_of_prefix_zero c _ i (hz x)] at hh + linarith + have he : p=C (p.eval 0) := by + apply Polynomial.funext + intro t + have hh:=congrArg (fun q : ℝ[X]=>q.eval 0) (hq t) + simp only [eval_sub,taylor_apply,eval_comp,eval_add,eval_X,eval_C,zero_add,eval_zero] at hh + simpa only [eval_C] using sub_eq_zero.mp hh + rw [he,natDegree_C] + | succ d ih => + apply natDegree_le_of_taylor_sub + intro t + let f' : ℝ → G:=fun x=>(f x)⁻¹*f (x+t) + have hf' : f'∈polynomials H (k+1) := derivative_mem hf t + have hz' (x : ℝ) (j : Fin n) (hj : j < i) : c.coord (f' x) j=0 := by + change c.coord ((f x)⁻¹*f (x+t)) j=0 + rw [coord_mul_of_left_zero c _ _ j (fun l hl=>prefix_zero_inv c _ i (hz x) l (lt_trans hl hj)), + prefix_zero_inv c _ i (hz x) j hj,hz (x+t) j hj] + simp + apply ih (k+1) (by omega) f' hf' hz' (taylor t p-p) + intro x + simp only [eval_sub,taylor_apply,eval_comp,eval_add,eval_X,eval_C,hp,f'] + rw [coord_mul_of_left_zero c _ _ i (prefix_zero_inv c _ i (hz x)), + coord_inv_of_prefix_zero c _ i (hz x)] + ring + +end RationalLattice +end + +end + +section + + +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +namespace RationalLattice +open CubeFaces CubePolynomials MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) + +lemma prod_ofFn_suffix {M : Type*} [Monoid M] {n : ℕ} (f : Fin n → M) (k : ℕ) : + (List.ofFn (fun i=>if k ≤ i.val then f i else 1)).prod=((List.ofFn f).drop k).prod := by + induction n generalizing k with + | zero => simp + | succ n ih => + cases k with + | zero => simp + | succ k => + rw [List.ofFn_succ,List.ofFn_succ] + simpa using ih (fun i=>f i.succ) k + +def suffixCoords (x : Fin n → ℝ) (k : ℕ) (i : Fin n) : ℝ := if k ≤ i.val then x i else 0 + +lemma suffixCoords_zero (x : Fin n → ℝ) : suffixCoords x 0=x := by + funext i + simp [suffixCoords] + +def suffixGroup (x : Fin n → ℝ) (k : ℕ) : G := c.coord.symm (suffixCoords x k) + +include hsk in +omit [IsTopologicalGroup G] in +lemma suffixGroup_eq_prod (x : Fin n → ℝ) (k : ℕ) : + suffixGroup c x k=((List.ofFn (fun i=>axis c i (x i))).drop k).prod := by + rw [hsk.ordered (suffixGroup c x k)] + simp only [suffixGroup,Homeomorph.apply_symm_apply,suffixCoords] + have he (i : Fin n) : axis c i (if k ≤ i.val then x i else 0)= + if k ≤ i.val then axis c i (x i) else 1 := by split_ifs <;> simp + simp only [he] + exact prod_ofFn_suffix _ _ + +include hsk in +omit [IsTopologicalGroup G] in +lemma suffixGroup_succ (x : Fin n → ℝ) (k : ℕ) (hk : k < n) : + suffixGroup c x k=axis c ⟨k,hk⟩ (x ⟨k,hk⟩)*suffixGroup c x (k+1) := by + rw [suffixGroup_eq_prod c hsk x k,suffixGroup_eq_prod c hsk x (k+1), + List.drop_eq_getElem_cons (by simpa using hk),List.prod_cons,List.getElem_ofFn] + +include hsk in +omit [IsTopologicalGroup G] in +lemma axis_polynomial_mem (H : Filtration G) (w : Fin n → ℕ) + (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + (i : Fin n) (p : ℝ[X]) (hp : p.natDegree ≤ w i) : + (fun t : ℝ=>axis c i (p.eval t))∈polynomials H 0 := by + let A : Multiplicative ℝ →* G := + { toFun := fun t=>axis c i t.toAdd + map_one' := axis_zero c i + map_mul' := fun t u=>hsk.axis_add i t.toAdd u.toAdd } + exact real_polynomial_mem H A (w i) 0 + (by intro t; exact MalcevWeightedCoordinates.axis_mem_level c H w hH i t) p hp + +include hsk in +omit [IsTopologicalGroup G] in +theorem coordinate_natDegree (H : Filtration G) (w : Fin n → ℕ) + (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + (f : ℝ → G) (hf : f∈polynomials H 0) + (p : Fin n → ℝ[X]) (hp : ∀ t i,(p i).eval t=c.coord (f t) i) : + ∀ i,(p i).natDegree ≤ w i := by + have hmem : ∀ k,(fun t : ℝ=>suffixGroup c (c.coord (f t)) k)∈polynomials H 0 := by + intro k + induction k with + | zero => simpa only [suffixGroup,suffixCoords_zero,Homeomorph.symm_apply_apply] using hf + | succ k ih => + by_cases hk : k < n + · let i : Fin n:=⟨k,hk⟩ + have hd : (p i).natDegree ≤ w i := by + apply tail_coord_natDegree c H w hH i (w i) 0 (by omega) + (fun t=>suffixGroup c (c.coord (f t)) k) ih + · intro t j hj + simp only [suffixGroup,Homeomorph.apply_symm_apply,suffixCoords] + rw [ite_eq_right (by change j.val < k at hj; omega)] + · intro t + simpa only [suffixGroup,Homeomorph.apply_symm_apply,suffixCoords,i,le_refl,ite_true] using hp t i + have ha:=axis_polynomial_mem c hsk H w hH i (p i) hd + have hh: (fun t : ℝ=>suffixGroup c (c.coord (f t)) (k+1))= + (fun t=>axis c i ((p i).eval t))⁻¹*(fun t=>suffixGroup c (c.coord (f t)) k) := by + funext t + change _=(axis c i ((p i).eval t))⁻¹*suffixGroup c (c.coord (f t)) k + rw [suffixGroup_succ c hsk _ k hk,hp] + simp [i] + rw [hh] + exact (polynomials H 0).mul_mem ((polynomials H 0).inv_mem ha) ih + · have hh : (fun t : ℝ=>suffixGroup c (c.coord (f t)) (k+1))=1 := by + funext t + apply c.coord.injective + funext j + simp only [suffixGroup,Homeomorph.apply_symm_apply,suffixCoords,Pi.one_apply,c.one_coord] + rw [ite_eq_right (by have:=j.isLt; omega)] + rw [hh] + exact (polynomials H 0).one_mem + intro i + apply tail_coord_natDegree c H w hH i (w i) 0 (by omega) + (fun t=>suffixGroup c (c.coord (f t)) i.val) (hmem i.val) + · intro t j hj + simp only [suffixGroup,Homeomorph.apply_symm_apply,suffixCoords] + rw [ite_eq_right (by change j.val < i.val at hj; omega)] + · intro t + simpa only [suffixGroup,Homeomorph.apply_symm_apply,suffixCoords,le_refl,ite_true] using hp t i + +end RationalLattice + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice14.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice14.lean new file mode 100644 index 0000000000000000000000000000000000000000..c2b5c9fcc44d2ffe0c82a124ccaf3abfdd25e2a3 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice14.lean @@ -0,0 +1,300 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.WeightedPolynomial02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + +noncomputable section +namespace RationalLattice +open WeightedPolynomial MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (H : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + +include hsk hH in +lemma log_multiplication_weighted (i : Fin n) : + IsWeighted (Sum.elim w w) (w i) (fun x=>canonicalLog c + (canonicalExp c (fun j=>x (Sum.inl j))*canonicalExp c (fun j=>x (Sum.inr j))) i) := by + have he (j : Fin n ⊕ Fin n) : IsWeighted (Sum.elim w w) ((Sum.elim w w) j) + (fun x=>Sum.elim (fun k=>c.coord (canonicalExp c (fun l=>x (Sum.inl l))) k) + (fun k=>c.coord (canonicalExp c (fun l=>x (Sum.inr l))) k) j) := by + cases j with + | inl j => + exact IsWeighted.comp (canonicalExp_weighted c hsk H w hH j) + (fun k=>IsWeighted.coordinate (Sum.elim w w) (Sum.inl k)) + | inr j => + exact IsWeighted.comp (canonicalExp_weighted c hsk H w hH j) + (fun k=>IsWeighted.coordinate (Sum.elim w w) (Sum.inr k)) + have hm (j : Fin n) := IsWeighted.comp (multiplication_weighted c hsk H w hH j) he + simp only [Sum.elim_inl,Sum.elim_inr,Homeomorph.symm_apply_apply] at hm + have hl:=IsWeighted.comp (canonicalLog_weighted c hsk H w hH i) hm + simpa only [Homeomorph.symm_apply_apply] using hl + +include hsk hH in + + +theorem log_left_displacement_weighted (hw : ∀ i,0 < w i) (a : G) (i : Fin n) : + IsWeighted w (w i-1) (fun y=>canonicalLog c (a*canonicalExp c y) i-y i) := by + obtain ⟨p,hp,he⟩:=log_multiplication_weighted c hsk H w hH i + let q:=p-MvPolynomial.X (Sum.inr i) + have hq : Bounded (Sum.elim w w) (w i) q := hp.sub (bounded_X (Sum.inr i)) + have hz (y : Fin n → ℝ) : MvPolynomial.eval (Sum.elim (fun _ : Fin n=>0) y) q=0 := by + simp only [q,map_sub,MvPolynomial.eval_X,Sum.elim_inr] + have h:=he (Sum.elim (fun _ : Fin n=>0) y) + change canonicalLog c (canonicalExp c 0*canonicalExp c y) i=_ at h + simp only [canonicalExp_zero,one_mul,canonicalLog_exp] at h + rw [← h,sub_self] + let Q:=MvPolynomial.eval₂Hom MvPolynomial.C + (Sum.elim (fun j=>MvPolynomial.C (canonicalLog c a j)) (fun j=>MvPolynomial.X j)) q + refine ⟨Q,fixed_left_spends_weight w w hw q hq hz (canonicalLog c a),?_⟩ + intro y + change _=MvPolynomial.eval y (MvPolynomial.eval₂ MvPolynomial.C _ q) + rw [← MvPolynomial.eval_assoc] + have hv : (MvPolynomial.eval y ∘ Sum.elim + (fun j=>MvPolynomial.C (canonicalLog c a j)) (fun j=>MvPolynomial.X j))= + Sum.elim (canonicalLog c a) y := by funext j; cases j <;> simp + rw [hv] + simp only [q,map_sub,MvPolynomial.eval_X,Sum.elim_inr] + rw [← he] + simp only [Sum.elim_inl,Sum.elim_inr,canonicalExp_log] + +end RationalLattice +end + +end + +section + + +noncomputable section +namespace RationalLattice +open WeightedPolynomial MalcevCharacters MalcevWeightedCoordinates +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) + +omit [IsTopologicalGroup G] in +lemma canonicalLog_congr_prefix (g h : G) (k : ℕ) + (he : ∀ j : Fin n,j.val < k → c.coord g j=c.coord h j) : + ∀ j : Fin n,j.val < k → canonicalLog c g j=canonicalLog c h j := by + intro j hj + have hh:=canonicalLog_sub_of_prefix_eq c g h j (fun l hl=>he l (lt_trans hl hj)) + rw [he j hj,sub_self,sub_eq_zero] at hh + exact hh + +omit [IsTopologicalGroup G] in +lemma canonicalLog_mul_prefix (g h : G) (k : ℕ) + (hh : ∀ j : Fin n,j.val < k → c.coord h j=0) : + ∀ j : Fin n,j.val < k → canonicalLog c (g*h) j=canonicalLog c g j := by + apply canonicalLog_congr_prefix + intro j hj + rw [coord_mul_of_right_zero c _ _ j (fun l hl=>hh l (lt_trans hl hj)),hh j hj,add_zero] + +variable (H : CubeFaces.Filtration G) (w : Fin n → ℕ) (hmono : Monotone w) +variable (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) +include hmono hH in +omit [IsTopologicalGroup G] in +lemma mem_level_iff_log (k : ℕ) (g : G) : + g∈H.level k ↔ ∀ i : Fin n,w i < k → canonicalLog c g i=0 := by + obtain ⟨r,hr,he⟩:=exists_weight_cutoff w hmono k + rw [hH] + simp only [he] + exact (canonicalLog_prefix_zero_iff c g r).symm + +include hmono hH in +omit [IsTopologicalGroup G] in +lemma canonicalExp_mem_level_iff (k : ℕ) (x : Fin n → ℝ) : + canonicalExp c x∈H.level k ↔ ∀ i : Fin n,w i < k → x i=0 := by + rw [mem_level_iff_log c H w hmono hH,canonicalLog_exp] + +include hmono hH in +omit [IsTopologicalGroup G] in +lemma canonicalLog_mul_level (k : ℕ) (g h : G) (hh : h∈H.level k) : + ∀ j : Fin n,w j < k → canonicalLog c (g*h) j=canonicalLog c g j := by + obtain ⟨r,hr,he⟩:=exists_weight_cutoff w hmono k + have hz : ∀ j : Fin n,j.val < r → c.coord h j=0 := + fun j hj=>(hH k h).mp hh j ((he j).mpr hj) + exact fun j hj=>canonicalLog_mul_prefix c g h r hz j ((he j).mp hj) + +include hmono hH in + + +theorem logHomLinear_lowers_of_displacement (hsk : SecondKind c) (F : G →* G) + (hF : Continuous F) (k : ℕ) + (hd : ∀ g∈H.level k,g⁻¹*F g∈H.level (k+1)) + (x : Fin n → ℝ) (hx : ∀ j : Fin n,w j < k → x j=0) : + ∀ j : Fin n,w j < k+1 → (logHomLinear c c F x-x) j=0 := by + have hg : canonicalExp c x∈H.level k := (canonicalExp_mem_level_iff c H w hmono hH _ _).mpr hx + have he:=canonicalLog_mul_level c H w hmono hH (k+1) (canonicalExp c x) + ((canonicalExp c x)⁻¹*F (canonicalExp c x)) (hd _ hg) + simp only [mul_inv_cancel_left,canonicalLog_exp] at he + intro j hj + rw [logHomLinear_apply c c hsk F hF] + exact sub_eq_zero.mpr (he j hj) + +end RationalLattice +end + +end + +section + + +noncomputable section +open scoped BigOperators +namespace WeightedPolynomial +open MvPolynomial +variable {σ τ : Type*} + +lemma IsWeighted.smul {w : σ → ℕ} {d : ℕ} {f : (σ → ℝ) → ℝ} + (hf : IsWeighted w d f) (a : ℝ) : IsWeighted w d (fun x=>a*f x) := by + obtain ⟨p,hp,he⟩:=hf + refine ⟨C a*p,?_,by simp [he]⟩ + simpa only [Nat.zero_add] using (bounded_C (w:=w) (d:=0) a).mul hp +lemma IsWeighted.sum {ι : Type*} (s : Finset ι) {w : σ → ℕ} {d : ℕ} + {f : ι → (σ → ℝ) → ℝ} (hf : ∀ i∈s,IsWeighted w d (f i)) : + IsWeighted w d (fun x=>∑ i∈s,f i x) := by + classical + induction s using Finset.induction_on with + | empty => simpa using IsWeighted.const w d 0 + | @insert i s hi ih => + simpa only [Finset.sum_insert hi] using + (hf i (Finset.mem_insert_self _ _)).add (ih (fun j hj=>hf j (Finset.mem_insert_of_mem hj))) + +lemma IsWeighted.linear [Fintype σ] [DecidableEq σ] (w : σ → ℕ) (d : ℕ) + (A : (σ → ℝ) →ₗ[ℝ] ℝ) + (hA : ∀ j,d < w j → A (Pi.single j 1)=0) : IsWeighted w d A := by + have hs : IsWeighted w d (fun x=>∑ j : σ,A (Pi.single j 1)*x j) := by + apply IsWeighted.sum + intro j hj + by_cases hd : w j ≤ d + · exact ((IsWeighted.coordinate w j).mono hd).smul _ + · simp only [hA j (Nat.lt_of_not_ge hd),zero_mul] + exact IsWeighted.const w d 0 + have he (x : σ → ℝ) : A x=∑ j : σ,A (Pi.single j 1)*x j := by + have hx : x=∑ j : σ,x j • Pi.single j 1 := by + ext i + simp [Finset.sum_apply,Pi.smul_apply,Pi.single_apply] + nth_rw 1 [hx] + rw [map_sum] + apply Finset.sum_congr rfl + intro j hj + rw [map_smul,smul_eq_mul,mul_comm] + obtain ⟨p,hp,hq⟩:=hs + exact ⟨p,hp,fun x=>(he x).trans (hq x)⟩ + +end WeightedPolynomial +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace WeightedPolynomial +open MvPolynomial +variable {α β : Type*} + +lemma eval_kill_inl (p : MvPolynomial (α ⊕ β) ℝ) (x : α → ℝ) : + eval x (p.killCompl Sum.inl_injective)=eval (Sum.elim x (fun _ : β=>0)) p := by + induction p using MvPolynomial.induction_on with + | C a => simp + | add p q hp hq => simp [hp,hq] + | mul_X p i hp => + cases i with + | inr i => simp [map_mul,killCompl] + | inl i => + have he : killCompl (R:=ℝ) (Sum.inl_injective (β:=β)) (X (Sum.inl i))=X i := by + rw [← rename_X,killCompl_rename_app] + simp [map_mul,hp,he] + +lemma exists_right_of_vanishing (p : MvPolynomial (α ⊕ β) ℝ) + (hz : ∀ x,eval (Sum.elim x (fun _ : β=>0)) p=0) + (m : (α ⊕ β) →₀ ℕ) (hm : p.coeff m≠0) : ∃ b : β,m (Sum.inr b)≠0 := by + classical + by_contra hh + push Not at hh + have hs : ↑m.support ⊆ Set.range (@Sum.inl α β) := by + intro j hj + cases j with + | inr b => exact False.elim ((Finsupp.mem_support_iff.mp hj) (hh b)) + | inl a => exact ⟨a,rfl⟩ + have hk : p.killCompl Sum.inl_injective=0 := by + apply MvPolynomial.funext + intro x + rw [map_zero,eval_kill_inl,hz] + have hc:=congrArg (fun poly : MvPolynomial α ℝ=> + poly.coeff (m.comapDomain (@Sum.inl α β) Sum.inl_injective.injOn)) hk + rw [coeff_killCompl,m.mapDomain_comapDomain _ Sum.inl_injective hs, + AddMonoidAlgebra.coeff_zero,Finsupp.zero_apply] at hc + exact hm hc + +lemma weight_lt_of_other {σ : Type*} (w : σ → ℕ) (m : σ →₀ ℕ) + (i j : σ) (hne : i≠j) (hi : m i≠0) (hj : m j≠0) (hwj : 0 exact Finsupp.mem_support_iff.mpr (by assumption) + have hsum:=Finset.sum_le_sum_of_subset hs (f:=fun a=>m a*w a) + simp only [Finset.sum_insert (show i∉({j}:Finset σ) by simpa using hne),Finset.sum_singleton] at hsum + have hmi : w i ≤ m i*w i:=by nlinarith [Nat.pos_of_ne_zero hi] + have hmj : 0 < m j * w j:=Nat.mul_pos (Nat.pos_of_ne_zero hj) hwj + simpa only [Finsupp.weight_apply,Finsupp.sum,smul_eq_mul] using + (lt_of_lt_of_le (by omega : w i < m i*w i+m j*w j) hsum) + +lemma mixed_weight_strict {wa : α → ℕ} {wb : β → ℕ} {d : ℕ} + (hwa : ∀ a,00) y) p=0) + (hr : ∀ x,eval (Sum.elim x (fun _ : β=>0)) p=0) + {m : (α ⊕ β) →₀ ℕ} {j : α ⊕ β} (hj : j∈m.support) (hm : p.coeff m≠0) : + (Sum.elim wa wb) j + obtain ⟨b,hb⟩:=exists_right_of_vanishing p hr m hm + exact weight_lt_of_other _ m (Sum.inl a) (Sum.inr b) (by simp) + (Finsupp.mem_support_iff.mp hj) hb (hwb b) + | inr b => + obtain ⟨a,ha⟩:=exists_left_of_vanishing p hl m hm + exact weight_lt_of_other _ m (Sum.inr b) (Sum.inl a) (by simp) + (Finsupp.mem_support_iff.mp hj) ha (hwa a) + exact lt_of_lt_of_le hlt (hp m hm) + + + +theorem mixed_eval_congr {wa : α → ℕ} {wb : β → ℕ} {d : ℕ} + (hwa : ∀ a,00) y) p=0) + (hr : ∀ x,eval (Sum.elim x (fun _ : β=>0)) p=0) + (x y : (α ⊕ β) → ℝ) + (hxy : ∀ j,(Sum.elim wa wb) jx (Sum.inl j))*e.symm (fun j=>x (Sum.inr j))) +def difference (x : (Fin n ⊕ Fin n) → ℝ) (i : Fin n) : ℝ:= + law e x i-x (Sum.inl i)-x (Sum.inr i) + +include he in +lemma difference_left (y : Fin n → ℝ) (i : Fin n) : + difference e (Sum.elim (fun _=>0) y) i=0 := by + have h0 : e.symm 0=1:=e.symm_apply_eq.mpr he.symm + change e (e.symm 0*e.symm y) i-0-y i=0 + simp [h0] +include he in +lemma difference_right (x : Fin n → ℝ) (i : Fin n) : + difference e (Sum.elim x (fun _=>0)) i=0 := by + have h0 : e.symm 0=1:=e.symm_apply_eq.mpr he.symm + change e (e.symm x*e.symm 0) i-x i-0=0 + simp [h0] + +def extend (i : Fin n) (z : (Fin i.val ⊕ Fin i.val) → ℝ) : + (Fin n ⊕ Fin n) → ℝ:=Sum.elim + (fun j=>if h : j.val < i.val then z (Sum.inl ⟨j.val,h⟩) else 0) + (fun j=>if h : j.val < i.val then z (Sum.inr ⟨j.val,h⟩) else 0) + +def restrict (i : Fin n) (z : (Fin n ⊕ Fin n) → ℝ) : + (Fin i.val ⊕ Fin i.val) → ℝ:=Sum.elim + (fun j=>z (Sum.inl ⟨j.val,lt_trans j.isLt i.isLt⟩)) + (fun j=>z (Sum.inr ⟨j.val,lt_trans j.isLt i.isLt⟩)) + +lemma extend_polynomial (i : Fin n) (j : Fin n ⊕ Fin n) : + RationalPolynomialMap.IsPolynomial (fun x=>extend i x j) := by + cases j with + | inl j => + by_cases h : j.val < i.val + · simp only [extend,Sum.elim_inl,dite_eq_left h] + exact RationalPolynomialMap.coordinate _ + · simp only [extend,Sum.elim_inl,dite_eq_right h] + simpa only [Rat.cast_zero] using RationalPolynomialMap.const 0 + | inr j => + by_cases h : j.val < i.val + · simp only [extend,Sum.elim_inr,dite_eq_left h] + exact RationalPolynomialMap.coordinate _ + · simp only [extend,Sum.elim_inr,dite_eq_right h] + simpa only [Rat.cast_zero] using RationalPolynomialMap.const 0 + +variable (hpoly : ∀ i,RationalPolynomialMap.IsPolynomial (fun x=>law e x i)) +variable (hweight : ∀ i,IsWeighted (Sum.elim w w) (w i) (fun x=>law e x i)) + +include hpoly in +lemma difference_polynomial (i : Fin n) : + RationalPolynomialMap.IsPolynomial (fun x=>difference e x i) := + RationalPolynomialMap.sub (RationalPolynomialMap.sub (hpoly i) + (RationalPolynomialMap.coordinate _)) (RationalPolynomialMap.coordinate _) + +include he hw hmono hweight in +lemma difference_restrict (i : Fin n) (x : (Fin n ⊕ Fin n) → ℝ) : + difference e x i=difference e (extend i (restrict i x)) i := by + have hh:=((hweight i).sub (IsWeighted.coordinate (Sum.elim w w) (Sum.inl i))).sub + (IsWeighted.coordinate (Sum.elim w w) (Sum.inr i)) + obtain ⟨p,hp,hpval⟩:=hh + change ∀ x,difference e x i=MvPolynomial.eval x p at hpval + rw [hpval,hpval] + apply mixed_eval_congr hw hw p hp + · intro y + rw [← hpval,difference_left e he] + · intro y + rw [← hpval,difference_right e he] + · intro j hj + cases j with + | inl j => + have hij : j.val < i.val := by + by_contra h + have hh:=hmono (show i≤j by omega) + change w j + have hij : j.val < i.val := by + by_contra h + have hh:=hmono (show i≤j by omega) + change w j1) (w i) (fun u=>canonicalLog c (f u) i) + +omit [IsTopologicalGroup G] in +lemma one_array : IsArray c w (fun _ : Fin q → ℝ=>(1:G)) := by + intro i + simpa only [canonicalLog_one,Pi.zero_apply] using IsWeighted.const (fun _ : Fin q=>1) (w i) 0 + +include hsk hA in +lemma mul_array {f g : (Fin q → ℝ) → G} (hf : IsArray c w f) (hg : IsArray c w g) : + IsArray c w (fun u=>f u*g u) := by + intro i + have hs (j : Fin n ⊕ Fin n) : + IsWeighted (fun _ : Fin q=>1) (Sum.elim w w j) + (fun u=>Sum.elim (canonicalLog c (f u)) (canonicalLog c (g u)) j) := by + cases j with + | inl j=>exact hf j + | inr j=>exact hg j + have hh:=(log_multiplication_weighted c hsk A w hA i).comp hs + simpa only [Sum.elim_inl,Sum.elim_inr,canonicalExp_log] using hh + +omit [IsTopologicalGroup G] in +lemma log_inv (g : G) : canonicalLog c g⁻¹= -canonicalLog c g := by + have hh:=canonicalLog_realPower c g (-1) + rw [show (-1:ℝ)=((-1:ℤ):ℝ) by simp,realPower_int] at hh + simpa using hh + +omit [IsTopologicalGroup G] in +lemma inv_array {f : (Fin q → ℝ) → G} (hf : IsArray c w f) : + IsArray c w (fun u=>(f u)⁻¹) := by + intro i + have hh:=(hf i).smul (-1) + simpa only [log_inv,Pi.neg_apply,neg_one_mul] using hh + + + +def group : Subgroup ((Fin q → ℝ) → G) where + carrier:=IsArray c w + one_mem':=one_array c w + mul_mem':=mul_array c hsk A w hA + inv_mem':=inv_array c w + +omit [IsTopologicalGroup G] in +lemma constant (g : G) : IsArray c w (fun _ : Fin q → ℝ=>g) := + fun _=>IsWeighted.const _ _ _ + +lemma affine_weighted (b : ℝ) (v : Fin q → ℝ) : + IsWeighted (fun _ : Fin q=>1) 1 (fun u=>b+∑ j,v j*u j) := + (IsWeighted.const _ _ b).add (IsWeighted.sum Finset.univ (fun j _=> + (IsWeighted.coordinate (fun _ : Fin q=>1) j).smul (v j))) + +variable (hw : ∀ i,0realPower c g (b+∑ j,v j*u j)) := by + intro i + have hh:=((affine_weighted b v).mono (hw i)).smul (canonicalLog c g i) + simpa only [canonicalLog_realPower,Pi.smul_apply,smul_eq_mul,mul_comm] using hh + +include hsk hA hw in + + +lemma source_array (g x : G) (b : ℝ) (v : Fin q → ℝ) : + IsArray c w (fun u=>realPower c g (b+∑ j,v j*u j)*x) := + mul_array c hsk A w hA (power_affine c w hw g b v) (constant c w x) + +omit [IsTopologicalGroup G] in +lemma translate_array {f : (Fin q → ℝ) → G} (hf : IsArray c w f) (v : Fin q → ℝ) : + IsArray c w (fun u=>f (u+v)) := by + intro i + exact (hf i).comp (fun j=>(IsWeighted.coordinate (fun _ : Fin q=>1) j).add + (IsWeighted.const _ _ (v j))) + + +def shift (v : Fin q → ℝ) : group (q:=q) c hsk A w hA ≃* group (q:=q) c hsk A w hA where + toFun f:=⟨fun u=>f.val (u+v),translate_array c w f.property v⟩ + invFun f:=⟨fun u=>f.val (u-v),by + change IsArray c w (fun u=>f.val (u-v)) + have hh:=translate_array c w f.property (-v) + simpa only [sub_eq_add_neg] using hh⟩ + left_inv f:=by apply Subtype.ext; funext u; simp + right_inv f:=by apply Subtype.ext; funext u; simp + map_mul' f g:=rfl + +lemma shift_continuous (v : Fin q → ℝ) : Continuous (shift c hsk A w hA v) := by + apply Continuous.subtype_mk + exact continuous_pi (fun u=>(continuous_apply (u+v)).comp continuous_subtype_val) + + +def lattice (Γ : Subgroup G) : Subgroup (group (q:=q) c hsk A w hA) where + carrier:=fun f=>∀ z : Fin q → ℤ,f.val (fun j=>(z j:ℝ))∈Γ + one_mem':=fun _=>Γ.one_mem + mul_mem':=fun hf hg z=>Γ.mul_mem (hf z) (hg z) + inv_mem':=fun hf z=>Γ.inv_mem (hf z) + +lemma shift_lattice (Γ : Subgroup G) (v : Fin q → ℤ) (f : group (q:=q) c hsk A w hA) : + shift c hsk A w hA (fun j=>(v j:ℝ)) f∈lattice c hsk A w hA Γ ↔ + f∈lattice c hsk A w hA Γ := by + constructor + · intro hf z + have hh:=hf (z-v) + change f.val (fun j=>((z-v) j:ℝ)+(v j:ℝ))∈Γ at hh + simpa only [Pi.sub_apply,Int.cast_sub,Pi.add_apply,sub_add_cancel] using hh + · intro hf z + have hh:=hf (z+v) + change f.val (fun j=>(z j:ℝ)+(v j:ℝ))∈Γ + simpa only [Pi.add_apply,Int.cast_add] using hh + +end RationalLattice.PolynomialArrays +end + + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice16.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice16.lean new file mode 100644 index 0000000000000000000000000000000000000000..f76c9f4946343c8fe75c5ac6986eb630322753c8 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice16.lean @@ -0,0 +1,302 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.PolynomialArray01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalPolynomialMap +lemma finset_sum {σ ι : Type*} (s : Finset ι) {f : ι → (σ → ℝ) → ℝ} + (hf : ∀ i∈s,IsPolynomial (f i)) : IsPolynomial (fun x=>∑ i∈s,f i x) := by + classical + induction s using Finset.induction_on with + | empty => simpa using (zero (σ:=σ)) + | @insert i s hi ih => + simpa only [Finset.sum_insert hi] using add (hf i (Finset.mem_insert_self _ _)) + (ih (fun j hj=>hf j (Finset.mem_insert_of_mem hj))) +end RationalPolynomialMap +namespace RationalLattice.PolynomialArrays +open WeightedPolynomial MalcevCharacters PolynomialArrayInterpolation +open CorrectedBoxLeibman (gridEval) +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w itoLog w x u i) := by + apply IsWeighted.sum + intro e he + unfold fullCoeff + split_ifs with h + · simpa only [mul_comm,weight] using (IsWeighted.coordinate (weight w) ⟨i,⟨e,h⟩⟩).smul + (∏ j,u j^(e j).val) + · simpa only [zero_mul] using IsWeighted.const (weight (q:=q) w) (w i) 0 + +lemma toLog_integer_polynomial (z : Fin q → ℤ) (i : Fin n) : + RationalPolynomialMap.IsPolynomial (fun x=>toLog w x (fun j=>(z j:ℝ)) i) := by + apply RationalPolynomialMap.finset_sum + intro e he + have hp : (∏ j,(z j:ℝ)^(e j).val)=((∏ j,(z j:ℚ)^(e j).val:ℚ):ℝ) := by push_cast; rfl + unfold fullCoeff + split_ifs with h + · rw [hp] + exact RationalPolynomialMap.mul (RationalPolynomialMap.coordinate (⟨i,⟨e,h⟩⟩ : Index w q)) + (RationalPolynomialMap.const _) + · simpa only [zero_mul] using RationalPolynomialMap.zero + +def multiply (x : (Index w q ⊕ Index w q) → ℝ) (a : Index w q) : ℝ:= + PolynomialArrayInterpolation.coefficients (fun u=>canonicalLog c + (canonicalExp c (toLog w (fun j=>x (Sum.inl j)) u)* + canonicalExp c (toLog w (fun j=>x (Sum.inr j)) u)) a.1) a.2.val + +omit [IsTopologicalGroup G] in +lemma multiply_polynomial (a : Index w q) : + RationalPolynomialMap.IsPolynomial (fun x=>multiply c w x a) := by + apply RationalPolynomialMap.finset_sum + intro v hv + apply RationalPolynomialMap.mul (RationalPolynomialMap.const _) + have hl (i : Fin n):=RationalPolynomialMap.comp + (toLog_integer_polynomial w (fun j=>((v j).val:ℤ)) i) + (fun k=>RationalPolynomialMap.coordinate (Sum.inl k : Index w q ⊕ Index w q)) + have hr (i : Fin n):=RationalPolynomialMap.comp + (toLog_integer_polynomial w (fun j=>((v j).val:ℤ)) i) + (fun k=>RationalPolynomialMap.coordinate (Sum.inr k : Index w q ⊕ Index w q)) + have he (i : Fin n):=RationalPolynomialMap.comp (canonicalExp_polynomial c i) hl + have hf (i : Fin n):=RationalPolynomialMap.comp (canonicalExp_polynomial c i) hr + have hm:=polynomialMap_mul c he hf + have hh:=RationalPolynomialMap.comp (canonicalLog_polynomial c a.1) hm + simpa only [Homeomorph.symm_apply_apply,Int.cast_natCast] using hh + +include hsk hA in +lemma multiply_weighted (a : Index w q) : + IsWeighted (Sum.elim (weight w) (weight w)) (weight w a) (fun x=>multiply c w x a) := by + apply IsWeighted.sum + intro v hv + apply IsWeighted.smul + have hin (j : Fin n ⊕ Fin n) : + IsWeighted (Sum.elim (weight w) (weight w)) (Sum.elim w w j) + (fun x=>Sum.elim + (toLog w (fun k=>x (Sum.inl k)) (fun k=>((v k).val:ℝ))) + (toLog w (fun k=>x (Sum.inr k)) (fun k=>((v k).val:ℝ))) j) := by + cases j with + | inl j => exact (toLog_weighted w _ j).comp (fun k=>IsWeighted.coordinate _ (Sum.inl k)) + | inr j => exact (toLog_weighted w _ j).comp (fun k=>IsWeighted.coordinate _ (Sum.inr k)) + have hm:=(log_multiplication_weighted c hsk A w hA a.1).comp hin + simpa only [Sum.elim_inl,Sum.elim_inr,weight] using hm + +lemma coefficientHomeomorph_mul (f g : group (q:=q) c hsk A w hA) : + coefficientHomeomorph c hsk A w hA (f*g)=multiply c w + (Sum.elim (coefficientHomeomorph c hsk A w hA f) + (coefficientHomeomorph c hsk A w hA g)) := by + funext a + change coefficients c hsk A w hA (f*g) a=_ + unfold multiply + simp only [Sum.elim_inl,Sum.elim_inr] + change _=PolynomialArrayInterpolation.coefficients (fun u=>canonicalLog c + (canonicalExp c (toLog w (coefficients c hsk A w hA f) u)* + canonicalExp c (toLog w (coefficients c hsk A w hA g) u)) a.1) a.2.val + simp only [toLog_coefficients,canonicalExp_log] + rfl + +end RationalLattice.PolynomialArrays +end + +end + +section + + +noncomputable section +namespace RationalLattice.FiniteWeightedLawChart +open WeightedPolynomial +variable {σ K : Type*} [Fintype σ] [Group K] [TopologicalSpace K] +variable (e : K ≃ₜ (σ → ℝ)) (he : e 1=0) (w : σ → ℕ) (hw : ∀ i,0x ((SortedFiniteWeights.indexing w).symm a)) + left_inv g:=by apply e.injective; simp + right_inv x:=by funext i; simp + continuous_toFun:=continuous_pi (fun i=>(continuous_apply _).comp e.continuous) + continuous_invFun:=e.symm.continuous.comp (continuous_pi (fun a=>continuous_apply _)) + +include he in +lemma reindex_one : reindex e w 1=0 := by ext i; exact congrFun he _ + +def law (x : (σ ⊕ σ) → ℝ) (a : σ) : ℝ:= + e (e.symm (fun j=>x (Sum.inl j))*e.symm (fun j=>x (Sum.inr j))) a + +def reshuffle (x : (Fin (Fintype.card σ) ⊕ Fin (Fintype.card σ)) → ℝ) : (σ ⊕ σ) → ℝ:= + Sum.elim (fun a=>x (Sum.inl ((SortedFiniteWeights.indexing w).symm a))) + (fun a=>x (Sum.inr ((SortedFiniteWeights.indexing w).symm a))) + +lemma law_reindex (x : (Fin (Fintype.card σ) ⊕ Fin (Fintype.card σ)) → ℝ) + (i : Fin (Fintype.card σ)) : + WeightedLawChart.law (reindex e w) x i=law e (reshuffle w x) (SortedFiniteWeights.indexing w i) := rfl + +lemma reshuffle_polynomial (a : σ ⊕ σ) : + RationalPolynomialMap.IsPolynomial (fun x=>reshuffle w x a) := by + cases a with + | inl a => exact RationalPolynomialMap.coordinate _ + | inr a => exact RationalPolynomialMap.coordinate _ + +lemma reshuffle_weighted (a : σ ⊕ σ) : + IsWeighted (Sum.elim (fun i=>w (SortedFiniteWeights.indexing w i)) + (fun i=>w (SortedFiniteWeights.indexing w i))) (Sum.elim w w a) + (fun x=>reshuffle w x a) := by + cases a with + | inl a => + simpa only [reshuffle,Sum.elim_inl,Equiv.apply_symm_apply] using (IsWeighted.coordinate + (Sum.elim (fun i=>w (SortedFiniteWeights.indexing w i)) + (fun i=>w (SortedFiniteWeights.indexing w i))) + (Sum.inl ((SortedFiniteWeights.indexing w).symm a))) + | inr a => + simpa only [reshuffle,Sum.elim_inr,Equiv.apply_symm_apply] using (IsWeighted.coordinate + (Sum.elim (fun i=>w (SortedFiniteWeights.indexing w i)) + (fun i=>w (SortedFiniteWeights.indexing w i))) + (Sum.inr ((SortedFiniteWeights.indexing w).symm a))) + +variable (hp : ∀ a,RationalPolynomialMap.IsPolynomial (fun x=>law e x a)) +variable (hb : ∀ a,IsWeighted (Sum.elim w w) (w a) (fun x=>law e x a)) +def chart : RealCoordinates K (Fintype.card σ):= + WeightedLawChart.realCoordinates (reindex e w) (reindex_one e he w) + (fun i=>w (SortedFiniteWeights.indexing w i)) (fun i=>hw _) + (SortedFiniteWeights.indexing_monotone w) + (fun i=>by simpa only [law_reindex] using + RationalPolynomialMap.comp (hp (SortedFiniteWeights.indexing w i)) (reshuffle_polynomial w)) + (fun i=>by simpa only [law_reindex] using + (hb (SortedFiniteWeights.indexing w i)).comp (reshuffle_weighted w)) + +lemma chart_apply (g : K) (i : Fin (Fintype.card σ)) : + (chart e he w hw hp hb).coord g i=e g (SortedFiniteWeights.indexing w i) := rfl +lemma chart_symm_apply (x : Fin (Fintype.card σ) → ℝ) : + (chart e he w hw hp hb).coord.symm x=e.symm + (fun a=>x ((SortedFiniteWeights.indexing w).symm a)) := rfl + +end RationalLattice.FiniteWeightedLawChart +end + +end + +section + + + + +noncomputable section +open scoped BigOperators commutatorElement +namespace RationalLattice.PolynomialArrays +open WeightedPolynomial MalcevCharacters MalcevWeightedCoordinates PolynomialArrayInterpolation +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w i rfl + +def chart : RealCoordinates (group (q:=q) c hsk A w hA) (Fintype.card (Index w q)) := + FiniteWeightedLawChart.chart (coefficientHomeomorph c hsk A w hA) + (coefficientHomeomorph_one c hsk A w hA) (weight w) (fun a=>hw a.1) + (fun a=>by simpa only [finite_law_eq] using multiply_polynomial c w a) + (fun a=>by simpa only [finite_law_eq] using multiply_weighted c hsk A w hA a) + +def orderedWeight (i : Fin (Fintype.card (Index w q))) : ℕ:= + weight w (SortedFiniteWeights.indexing (weight w) i) +include hw in +lemma orderedWeight_pos (i : Fin (Fintype.card (Index w q))) : 0∀ u,f.val u∈A.level k + one_mem':=fun _=>(A.level k).one_mem + mul_mem':=fun hf hg u=>(A.level k).mul_mem (hf u) (hg u) + inv_mem':=fun hf u=>(A.level k).inv_mem (hf u) + +def filtration : CubeFaces.Filtration (group (q:=q) c hsk A w hA) where + level:=level c hsk A w hA + antitone:=fun _ _ hij _ hf u=>A.antitone hij (hf u) + commutator_le i j:=Subgroup.commutator_le.mpr (fun f hf g hg u=> + (Subgroup.commutator_le.mp (A.commutator_le i j)) (f.val u) (hf u) (g.val u) (hg u)) + +variable (hmono : Monotone w) +include hmono in +lemma coefficients_adapted (k : ℕ) (f : group (q:=q) c hsk A w hA) : + f∈level c hsk A w hA k ↔ ∀ a : Index w q,weight w a(D:ℚ)*(T:ℚ)*(x i:ℚ)) (fun j=>(y j:ℚ))) P- + eval (Sum.elim (fun _=>0) (fun j=>(y j:ℚ))) P=(T:ℚ)*(z:ℚ) := by + induction P using MvPolynomial.induction_on with + | C a => exact ⟨1,by norm_num,fun T x y=>⟨0,by simp⟩⟩ + | add P Q hP hQ => + obtain ⟨D,hD,hP⟩:=hP + obtain ⟨E,hE,hQ⟩:=hQ + refine ⟨D*E,Nat.mul_pos hD hE,?_⟩ + intro T x y + obtain ⟨a,ha⟩:=hP T (fun i=>(E:ℤ)*x i) y + obtain ⟨b,hb⟩:=hQ T (fun i=>(D:ℤ)*x i) y + have hDE : (fun i=>(D:ℚ)*(T:ℚ)*(((E:ℤ)*x i):ℚ))= + (fun i=>((D*E:ℕ):ℚ)*(T:ℚ)*(x i:ℚ)) := by funext i; push_cast; ring + have hED : (fun i=>(E:ℚ)*(T:ℚ)*(((D:ℤ)*x i):ℚ))= + (fun i=>((D*E:ℕ):ℚ)*(T:ℚ)*(x i:ℚ)) := by funext i; push_cast; ring + simp only [Int.cast_mul] at ha hb + rw [hDE] at ha + rw [hED] at hb + refine ⟨a+b,?_⟩ + simp only [map_add,Int.cast_add] + linarith + | mul_X P a hP => + cases a with + | inl i => + obtain ⟨D,hD,hgrid⟩:=polynomial_grid P 1 (by norm_num) + refine ⟨D,hD,?_⟩ + intro T x y + obtain ⟨a,ha⟩:=hgrid + (Sum.elim (fun i=>(D:ℚ)*(T:ℚ)*(x i:ℚ)) (fun j=>(y j:ℚ))) (by + intro j + cases j with + | inl j => exact ⟨(D:ℤ)*(T:ℤ)*x j,by simp⟩ + | inr j => exact ⟨y j,by simp⟩) + refine ⟨a*x i,?_⟩ + simp only [map_mul,eval_X,Sum.elim_inl,mul_zero,sub_zero,Int.cast_mul] + calc + _=(T:ℚ)*((D:ℚ)*eval + (Sum.elim (fun i=>(D:ℚ)*(T:ℚ)*(x i:ℚ)) (fun j=>(y j:ℚ))) P)*(x i:ℚ) := by ring + _=_ := by rw [ha]; ring + | inr j => + obtain ⟨D,hD,hP⟩:=hP + refine ⟨D,hD,?_⟩ + intro T x y + obtain ⟨a,ha⟩:=hP T x y + refine ⟨a*y j,?_⟩ + simp only [map_mul,eval_X,Sum.elim_inr,Int.cast_mul] + rw [← sub_mul,ha] + ring + +lemma polynomial_partial_origin_grid_real {σ τ : Type*} (P : MvPolynomial (σ ⊕ τ) ℚ) : + ∃ D : ℕ,0(y j:ℝ))) P- + eval₂ (algebraMap ℚ ℝ) (Sum.elim (fun _=>0) (fun j=>(y j:ℝ))) P=(T:ℝ)*(z:ℝ) := by + obtain ⟨D,hD,hP⟩:=polynomial_partial_origin_grid P + refine ⟨D,hD,?_⟩ + intro T x y hx + choose a ha using hx + obtain ⟨z,hz⟩:=hP T a y + refine ⟨z,?_⟩ + have he (v : (σ ⊕ τ) → ℚ) : ((eval v P:ℚ):ℝ)= + eval₂ (algebraMap ℚ ℝ) (fun j=>(v j:ℝ)) P := + eval₂_comp_left (algebraMap ℚ ℝ) (RingHom.id ℚ) v P + have hh:=congrArg (fun q : ℚ=>(q:ℝ)) hz + simp only [Rat.cast_sub,Rat.cast_mul,Rat.cast_natCast,Rat.cast_intCast] at hh + rw [he,he] at hh + have hx' : (fun j=>((Sum.elim (fun i=>(D:ℚ)*(T:ℚ)*(a i:ℚ)) + (fun j=>(y j:ℚ)) j:ℚ):ℝ))=Sum.elim x (fun j=>(y j:ℝ)) := by + funext j + cases j with + | inl i => simpa only [Sum.elim_inl,Rat.cast_mul,Rat.cast_natCast,Rat.cast_intCast,Nat.cast_mul] using (ha i).symm + | inr j => simp + have hz' : (fun j=>((Sum.elim (fun _ : σ=>0) (fun j=>(y j:ℚ)) j:ℚ):ℝ))= + Sum.elim (fun _ : σ=>0) (fun j=>(y j:ℝ)) := by funext j; cases j <;> simp + rw [hx',hz'] at hh + exact hh + +end TriangularDenominators +end + +end + +section + + + +noncomputable section +open scoped BigOperators +namespace RationalPolynomialMap +lemma power {σ : Type*} {f : (σ → ℝ) → ℝ} (hf : IsPolynomial f) (k : ℕ) : + IsPolynomial (fun x=>f x^k) := by + induction k with + | zero => simpa using (const (σ:=σ) 1) + | succ k ih => simpa only [pow_succ] using mul ih hf +lemma finset_prod {σ ι : Type*} (s : Finset ι) {f : ι → (σ → ℝ) → ℝ} + (hf : ∀ i∈s,IsPolynomial (f i)) : IsPolynomial (fun x=>∏ i∈s,f i x) := by + classical + induction s using Finset.induction_on with + | empty => simpa using (const (σ:=σ) 1) + | @insert i s hi ih => + simpa only [Finset.prod_insert hi] using mul (hf i (Finset.mem_insert_self _ _)) + (ih (fun j hj=>hf j (Finset.mem_insert_of_mem hj))) +end RationalPolynomialMap +namespace RationalLattice.PolynomialArrays +open PolynomialArrayInterpolation MalcevCharacters +open CorrectedBoxLeibman (gridEval) +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w i + toLog w (fun a=>x (Sum.inl a)) (fun j=>x (Sum.inr j)) i) := by + apply RationalPolynomialMap.finset_sum + intro e he + unfold fullCoeff + split_ifs with hd + · apply RationalPolynomialMap.mul (RationalPolynomialMap.coordinate _) + apply RationalPolynomialMap.finset_prod + intro j hj + exact RationalPolynomialMap.power (RationalPolynomialMap.coordinate _) _ + · simpa only [zero_mul] using (RationalPolynomialMap.zero) + +lemma toLog_zero (u : Fin q → ℝ) : toLog w 0 u=0 := by + funext i + unfold toLog gridEval + apply Finset.sum_eq_zero + intro e he + simp only [fullCoeff,Pi.zero_apply,dite_eq_ite,ite_self,zero_mul] + +omit [IsTopologicalGroup G] in +lemma joint_coordinates_polynomial (i : Fin n) : + RationalPolynomialMap.IsPolynomial (fun x : (Index w q ⊕ Fin q) → ℝ=> + c.coord (canonicalExp c (toLog w (fun a=>x (Sum.inl a)) (fun j=>x (Sum.inr j)))) i) := by + have hh:=RationalPolynomialMap.comp (canonicalExp_polynomial c i) (toLog_joint_polynomial (q:=q) w) + simpa only [Homeomorph.symm_apply_apply] using hh + +omit [IsTopologicalGroup G] in +lemma coefficient_grid_lattice (Γ : Subgroup G) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) : + ∃ D : ℕ,0(u j:ℝ)))∈Γ := by + classical + have hi (i : Fin n) : ∃ D : ℕ,0(u j:ℝ)))) i=z := by + obtain ⟨P,hP⟩:=joint_coordinates_polynomial c w (q:=q) i + obtain ⟨D,hD,hgrid⟩:=TriangularDenominators.polynomial_partial_origin_grid_real P + refine ⟨D,hD,?_⟩ + intro x hx u + obtain ⟨z,hz⟩:=hgrid 1 x u (by simpa using hx) + refine ⟨z,?_⟩ + rw [← hP,← hP] at hz + have hzero : toLog w (fun _ : Index w q=>0) (fun j=>(u j:ℝ))=0 := toLog_zero w _ + simpa only [Sum.elim_inl,Sum.elim_inr,hzero,canonicalExp_zero,c.one_coord,sub_zero, + Nat.cast_one,one_mul] using hz + choose D hD hgrid using hi + refine ⟨∏ i,D i,Finset.prod_pos (fun i _=>hD i),?_⟩ + intro x hx u + apply (hΓ _).mpr + intro i + apply hgrid i x _ u + intro a + obtain ⟨z,hz⟩:=hx a + obtain ⟨b,hb⟩:=Finset.dvd_prod_of_mem D (Finset.mem_univ i) + refine ⟨(b:ℤ)*z,?_⟩ + rw [hz,hb] + push_cast + ring + +lemma chart_grid_lattice (Γ : Subgroup G) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) : + ∃ D : ℕ,0 + fun v : Grid q d=>f.val (fun i=>((v i).val:ℝ))) := by + intro f g hfg + apply Subtype.ext + funext u + have he : canonicalLog c (f.val u)=canonicalLog c (g.val u) := by + funext i + have hh:=grid_injective ((f.property i).mono (hd i)) ((g.property i).mono (hd i)) + (fun v=>congrArg (fun a : G=>canonicalLog c a i) (congrFun hfg v)) + exact congrFun hh u + calc f.val u = canonicalExp c (canonicalLog c (f.val u)) := (canonicalExp_log c _).symm + _ = canonicalExp c (canonicalLog c (g.val u)) := congrArg (canonicalExp c) he + _ = g.val u := canonicalExp_log c _ + +def latticeSample (d : ℕ) (f : lattice (q:=q) c hsk A w hA Γ) (v : Grid q d) : Γ:= + ⟨f.val.val (fun i=>((v i).val:ℝ)),by + simpa only [Int.cast_natCast] using f.property (fun i=>((v i).val:ℤ))⟩ + +omit [DiscreteTopology Γ] in +lemma latticeSample_continuous (d : ℕ) : Continuous (latticeSample (q:=q) c hsk A w hA Γ d) := by + apply continuous_pi + intro v + apply Continuous.subtype_mk + exact (continuous_apply _).comp (continuous_subtype_val.comp continuous_subtype_val) + +lemma lattice_discrete : DiscreteTopology (lattice (q:=q) c hsk A w hA Γ) := by + classical + let d:=Finset.univ.sup w + have hd (i : Fin n) : w i≤d:=Finset.le_sup (Finset.mem_univ i) + apply DiscreteTopology.of_continuous_injective (latticeSample_continuous c hsk A w hA Γ d) + intro f g hfg + apply Subtype.ext + apply sampled_injective c hsk A w hA d hd + funext v + exact congrArg Subtype.val (congrFun hfg v) + +end RationalLattice.PolynomialArrays + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice18.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice18.lean new file mode 100644 index 0000000000000000000000000000000000000000..cda610766ee15227096fc98295e9fdf497040283 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice18.lean @@ -0,0 +1,284 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice17 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +namespace RationalLattice.PolynomialArrays +open PolynomialArrayInterpolation MalcevCharacters MalcevWeightedCoordinates +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w i(secondCoordinates_rational d f).trans (hrat f)⟩ + intro k f + obtain ⟨r,hr,he⟩:=exists_weight_cutoff (orderedWeight (q:=q) w) (orderedWeight_monotone w) k + have hd : ∀ f : group (q:=q) c hsk A w hA,f∈(filtration c hsk A w hA).level k ↔ + ∀ i : Fin (Fintype.card (Index w q)),i.valby + obtain ⟨a,ha,haf⟩:=hrep f hf + exact ⟨a,ha,hle haf⟩⟩ + +include hw hΓ in +lemma lattice_compactSpace : CompactSpace ((group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ) := by + obtain ⟨Λ,e,hΛ,hle,_,_,_⟩:=integer_cover c hsk A w hA hw Γ hΓ (q:=q) + obtain ⟨C,hC,hrep⟩:=compact_reps_of_integerCoordinates e Λ hΛ + apply CompactGroupProducts.HasCompactReps.quotient_compactSpace + refine ⟨C,hC,fun _ _=>Subgroup.mem_top _,?_⟩ + intro f _ + obtain ⟨a,ha,haf⟩:=hrep f + exact ⟨a,ha,hle haf⟩ + +include hw hΓ in +lemma lattice_quotient_t2 : T2Space ((group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ) := by + let : T2Space (group (q:=q) c hsk A w hA):=(chart c hsk A w hA hw).coord.symm.t2Space + let : DiscreteTopology Γ:=integerCoordinates_discrete c Γ hΓ + let : DiscreteTopology (lattice (q:=q) c hsk A w hA Γ):=lattice_discrete c hsk A w hA Γ + let : IsClosed (lattice (q:=q) c hsk A w hA Γ : Set (group (q:=q) c hsk A w hA)):= + (lattice (q:=q) c hsk A w hA Γ).isClosed_of_discreteTopology + infer_instance + +end RationalLattice.PolynomialArrays +end + +end + +section + + + + +noncomputable section +namespace RationalLattice.PolynomialArrays +open PolynomialArrayInterpolation MalcevCharacters WeightedPolynomial +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w i + c.coord (evaluate c hsk A w hA (fun j=>(u j:ℝ)) + ((chart c hsk A w hA hw).coord.symm x)) i) := by + have hin (a : Index w q) : RationalPolynomialMap.IsPolynomial + (fun x : Fin (Fintype.card (Index w q)) → ℝ=>x ((SortedFiniteWeights.indexing (weight w)).symm a)):= + RationalPolynomialMap.coordinate _ + have hl (i : Fin n):=RationalPolynomialMap.comp (toLog_integer_polynomial w u i) hin + have hh:=RationalPolynomialMap.comp (canonicalExp_polynomial c i) hl + exact hh + +lemma evaluate_rational (u : Fin q → ℤ) (f : group (q:=q) c hsk A w hA) + (hf : IsRational (chart c hsk A w hA hw) f) : + IsRational c (evaluate c hsk A w hA (fun j=>(u j:ℝ)) f) := + rationalHom_rational c (chart c hsk A w hA hw) (evaluate c hsk A w hA (fun j=>(u j:ℝ))) + (readout_polynomial c hsk A w hA hw u) hf + +lemma shift_coordinates (v : Fin q → ℝ) (f : group (q:=q) c hsk A w hA) (a : Index w q) : + coefficients c hsk A w hA (shift c hsk A w hA v f) a= + PolynomialArrayInterpolation.coefficients + (fun u=>toLog w (coefficients c hsk A w hA f) (u+v) a.1) a.2.val := by + simp only [toLog_coefficients] + rfl + +lemma shift_polynomial (v : Fin q → ℤ) (i : Fin (Fintype.card (Index w q))) : + RationalPolynomialMap.IsPolynomial (fun x=>(chart c hsk A w hA hw).coord + (shift c hsk A w hA (fun j=>(v j:ℝ)) ((chart c hsk A w hA hw).coord.symm x)) i) := by + let a : Index w q:=SortedFiniteWeights.indexing (weight w) i + change RationalPolynomialMap.IsPolynomial (fun x=>coefficients c hsk A w hA + (shift c hsk A w hA (fun j=>(v j:ℝ)) ((chart c hsk A w hA hw).coord.symm x)) a) + simp only [shift_coordinates] + apply RationalPolynomialMap.finset_sum + intro z hz + apply RationalPolynomialMap.mul (RationalPolynomialMap.const _) + have hin (a : Index w q) : RationalPolynomialMap.IsPolynomial + (fun x : Fin (Fintype.card (Index w q)) → ℝ=>x ((SortedFiniteWeights.indexing (weight w)).symm a)):= + RationalPolynomialMap.coordinate _ + have hh:=RationalPolynomialMap.comp (toLog_integer_polynomial w (fun j=>((z j).val:ℤ)+v j) a.1) hin + have he (x : Fin (Fintype.card (Index w q)) → ℝ) : coefficients c hsk A w hA + ((chart c hsk A w hA hw).coord.symm x)=(fun a=>x ((SortedFiniteWeights.indexing (weight w)).symm a)):= + (coefficientHomeomorph c hsk A w hA).apply_symm_apply _ + simpa only [he,Pi.add_def,Int.cast_add,Int.cast_natCast] using hh + +lemma shift_rational (v : Fin q → ℤ) (f : group (q:=q) c hsk A w hA) + (hf : IsRational (chart c hsk A w hA hw) f) : + IsRational (chart c hsk A w hA hw) (shift c hsk A w hA (fun j=>(v j:ℝ)) f) := + rationalHom_rational (chart c hsk A w hA hw) (chart c hsk A w hA hw) + (shift c hsk A w hA (fun j=>(v j:ℝ))).toMonoidHom + (shift_polynomial c hsk A w hA hw v) hf + +lemma shift_level (v : Fin q → ℝ) (k : ℕ) (f : group (q:=q) c hsk A w hA) : + shift c hsk A w hA v f∈(filtration c hsk A w hA).level k ↔ + f∈(filtration c hsk A w hA).level k := by + constructor + · intro hf u + have hh:=hf (u-v) + change f.val (u-v+v)∈A.level k at hh + simpa only [sub_add_cancel] using hh + · intro hf u + exact hf (u+v) + +lemma evaluate_level (u : Fin q → ℝ) (k : ℕ) : + ((filtration c hsk A w hA).level k).map (evaluate c hsk A w hA u)=A.level k := by + ext g + constructor + · rintro ⟨f,hf,rfl⟩ + exact hf u + · intro hg + exact ⟨⟨fun _=>g,constant c w g⟩,fun _=>hg,rfl⟩ + +variable (Γ : Subgroup G) + +def readout (u : Fin q → ℤ) : (group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ → G⧸Γ:= + Quotient.lift (fun f=>QuotientGroup.mk (evaluate c hsk A w hA (fun j=>(u j:ℝ)) f)) (by + intro f g hfg + exact QuotientGroup.eq.mpr ((QuotientGroup.leftRel_apply.mp hfg) u)) +lemma readout_continuous (u : Fin q → ℤ) : Continuous (readout c hsk A w hA Γ u):= + (QuotientGroup.isQuotientMap_mk _).continuous_iff.mpr + (QuotientGroup.continuous_mk.comp (evaluate_continuous c hsk A w hA _)) + +def shifted (v : Fin q → ℤ) : (group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ → + (group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ:= + Quotient.map (shift c hsk A w hA (fun j=>(v j:ℝ))) (by + intro f g hfg + apply QuotientGroup.leftRel_apply.mpr + rw [← map_inv,← map_mul] + exact (shift_lattice c hsk A w hA Γ v _).mpr (QuotientGroup.leftRel_apply.mp hfg)) +lemma shifted_continuous (v : Fin q → ℤ) : Continuous (shifted c hsk A w hA Γ v):= + (QuotientGroup.isQuotientMap_mk _).continuous_iff.mpr + (QuotientGroup.continuous_mk.comp (shift_continuous c hsk A w hA _)) + +lemma shifted_add (v z : Fin q → ℤ) (x : (group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ) : + shifted c hsk A w hA Γ (v+z) x=shifted c hsk A w hA Γ v (shifted c hsk A w hA Γ z x) := by + induction x using Quotient.inductionOn with | h f => + apply congrArg QuotientGroup.mk + apply Subtype.ext + funext u + change f.val (u+(fun j=>((v+z) j:ℝ)))=f.val ((u+(fun j=>(v j:ℝ)))+(fun j=>(z j:ℝ))) + apply congrArg f.val + funext j + simp only [Pi.add_apply,Int.cast_add] + ring +lemma shifted_zero (x : (group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ) : + shifted c hsk A w hA Γ 0 x=x := by + induction x using Quotient.inductionOn with | h f => + apply congrArg QuotientGroup.mk + apply Subtype.ext + funext u + change f.val (u+(fun _=>((0:ℤ):ℝ)))=f.val u + apply congrArg f.val + funext j + simp only [Pi.add_apply,Int.cast_zero,add_zero] + +def shiftedHomeomorph (v : Fin q → ℤ) : + ((group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ) ≃ₜ + ((group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ) where + toFun:=shifted c hsk A w hA Γ v + invFun:=shifted c hsk A w hA Γ (-v) + left_inv x:=by rw [← shifted_add,neg_add_cancel,shifted_zero] + right_inv x:=by rw [← shifted_add,add_neg_cancel,shifted_zero] + continuous_toFun:=shifted_continuous c hsk A w hA Γ v + continuous_invFun:=shifted_continuous c hsk A w hA Γ (-v) + +lemma readout_shifted (u v : Fin q → ℤ) + (x : (group (q:=q) c hsk A w hA)⧸lattice c hsk A w hA Γ) : + readout c hsk A w hA Γ u (shifted c hsk A w hA Γ v x)=readout c hsk A w hA Γ (u+v) x := by + induction x using Quotient.inductionOn with | h f => + change QuotientGroup.mk (f.val ((fun j=>(u j:ℝ))+(fun j=>(v j:ℝ))))= + QuotientGroup.mk (f.val (fun j=>((u+v) j:ℝ))) + simp only [Pi.add_def,Int.cast_add] + +end RationalLattice.PolynomialArrays + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice19.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice19.lean new file mode 100644 index 0000000000000000000000000000000000000000..288723f90a8a340e8b88ad324933146526c6e23b --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice19.lean @@ -0,0 +1,287 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice18 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +namespace RationalLattice.FiniteProducts +open MalcevCharacters MalcevWeightedCoordinates WeightedPolynomial +variable {ι : Type} [Fintype ι] (G : ι → Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι → ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i) → ℕ) (hw : ∀ i j,0x ⟨i,j⟩) + left_inv g:=by funext i; exact canonicalExp_log (c i) (g i) + right_inv x:=by funext a; exact congrFun (canonicalLog_exp (c a.1) (fun j=>x ⟨a.1,j⟩)) a.2 + continuous_toFun:=continuous_pi (fun a=>(continuous_apply a.2).comp + ((canonicalLog_continuous (c a.1)).comp (continuous_apply a.1))) + continuous_invFun:=continuous_pi (fun i=>(logHomeomorph (c i)).symm.continuous.comp + (continuous_pi (fun j : Fin (n i)=>continuous_apply (⟨i,j⟩ : Index n)))) +omit [Fintype ι] [∀ index,IsTopologicalGroup (G index)] in +lemma logCoordinates_one : logCoordinates G n c 1=0 := by + funext a + exact congrFun (canonicalLog_one (c a.1)) a.2 + +omit [Fintype ι] [∀ index,IsTopologicalGroup (G index)] in +lemma law_polynomial (a : Index n) : RationalPolynomialMap.IsPolynomial + (fun x=>FiniteWeightedLawChart.law (logCoordinates G n c) x a) := by + have hl (j : Fin (n a.1)):=RationalPolynomialMap.comp (canonicalExp_polynomial (c a.1) j) + (fun k=>RationalPolynomialMap.coordinate (Sum.inl (⟨a.1,k⟩ : Index n) : Index n ⊕ Index n)) + have hr (j : Fin (n a.1)):=RationalPolynomialMap.comp (canonicalExp_polynomial (c a.1) j) + (fun k=>RationalPolynomialMap.coordinate (Sum.inr (⟨a.1,k⟩ : Index n) : Index n ⊕ Index n)) + have hm:=polynomialMap_mul (c a.1) hl hr + have hh:=RationalPolynomialMap.comp (canonicalLog_polynomial (c a.1) a.2) hm + simp only [Homeomorph.symm_apply_apply] at hh + exact hh + +include hsk hA in +omit [Fintype ι] in +lemma law_weighted (a : Index n) : IsWeighted (Sum.elim (weight n w) (weight n w)) (weight n w a) + (fun x=>FiniteWeightedLawChart.law (logCoordinates G n c) x a) := by + have hi (j : Fin (n a.1) ⊕ Fin (n a.1)) : + IsWeighted (Sum.elim (weight n w) (weight n w)) (Sum.elim (w a.1) (w a.1) j) + (fun x : (Index n ⊕ Index n) → ℝ=>Sum.elim + (fun k=>x (Sum.inl ⟨a.1,k⟩)) (fun k=>x (Sum.inr ⟨a.1,k⟩)) j) := by + cases j with + | inl j=>exact IsWeighted.coordinate (Sum.elim (weight n w) (weight n w)) (Sum.inl (⟨a.1,j⟩ : Index n)) + | inr j=>exact IsWeighted.coordinate (Sum.elim (weight n w) (weight n w)) (Sum.inr (⟨a.1,j⟩ : Index n)) + have hh:=(log_multiplication_weighted (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1) a.2).comp hi + exact hh + +def chart : RealCoordinates (∀ i,G i) (Fintype.card (Index n)) := + FiniteWeightedLawChart.chart (logCoordinates G n c) (logCoordinates_one G n c) + (weight n w) (fun a=>hw a.1 a.2) (law_polynomial G n c) (law_weighted G n c hsk A w hA) +def orderedWeight (i : Fin (Fintype.card (Index n))) : ℕ:= + weight n w (SortedFiniteWeights.indexing (weight n w) i) +include hw in +lemma orderedWeight_positive (i : Fin (Fintype.card (Index n))) : 0∀ i,g i∈(A i).level k + one_mem':=fun i=>(A i).level k |>.one_mem + mul_mem':=fun hg hh i=>((A i).level k).mul_mem (hg i) (hh i) + inv_mem':=fun hg i=>((A i).level k).inv_mem (hg i) +def filtration : CubeFaces.Filtration (∀ i,G i) where + level:=level G A + antitone:=fun _ _ hjk _ hg i=>(A i).antitone hjk (hg i) + commutator_le j k:=Subgroup.commutator_le.mpr (fun g hg h hh i=> + Subgroup.commutator_le.mp ((A i).commutator_le j k) (g i) (hg i) (h i) (hh i)) + +include hmono in +lemma chart_adapted (k : ℕ) (g : ∀ i,G i) : + g∈(filtration G A).level k ↔ ∀ j,orderedWeight n w j + (c i).coord (((chart G n c hsk A w hw hA).coord.symm x) i) j) := by + have hh:=RationalPolynomialMap.comp (canonicalExp_polynomial (c i) j) + (fun k=>RationalPolynomialMap.coordinate ((SortedFiniteWeights.indexing (weight n w)).symm ⟨i,k⟩)) + exact hh + +lemma projection_rational (g : ∀ i,G i) (hg : IsRational (chart G n c hsk A w hw hA) g) (i : ι) : + IsRational (c i) (g i) := by + let F : (∀ i,G i) →* G i:={ toFun:=fun g=>g i,map_one':=rfl,map_mul':=fun _ _=>rfl } + exact rationalHom_rational (c i) (chart G n c hsk A w hw hA) F + (chart_projection_polynomial G n c hsk A w hw hA i) hg + +end RationalLattice.FiniteProducts +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalLattice.PolynomialArrays +open MalcevCharacters CubePolynomials +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w ig,constant c w g⟩ +def sourceElement (g x : G) (b : ℝ) (v : Fin q → ℝ) : group (q:=q) c hsk A w hA := + ⟨fun u=>realPower c g (b+∑ j,v j*u j)*x,source_array c hsk A w hA hw g x b v⟩ + +def sourceOrbit (g x : G) (t : ℤ) (b : ℝ) (v : Fin q → ℝ) (z : ℤ) : + group (q:=q) c hsk A w hA := + constantElement c hsk A w hA (g^t)^z * sourceElement c hsk A w hA hw g x b v + +lemma sourceOrbit_apply (g x : G) (t : ℤ) (b : ℝ) (v u : Fin q → ℝ) (z : ℤ) : + (sourceOrbit c hsk A w hA hw g x t b v z).val u= + realPower c g (b+(t:ℝ)*z+∑ j,v j*u j)*x := by + change evaluate c hsk A w hA u (_^z * _)=_ + rw [map_mul,map_zpow] + change (g^t)^z*(realPower c g (b+∑ j,v j*u j)*x)=_ + rw [← zpow_mul,← realPower_int c g,← mul_assoc,← realPower_add] + congr 2 + push_cast + ring + +end RationalLattice.PolynomialArrays +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace WeightedPolynomial +open MvPolynomial +variable {σ : Type*} +lemma IsWeighted.scale {w : σ → ℕ} {d : ℕ} {f : (σ → ℝ) → ℝ} + (hf : IsWeighted w d f) (D : ℕ) : + IsWeighted (fun j=>D*w j) (D*d) f := by + obtain ⟨p,hp,he⟩:=hf + refine ⟨p,?_,he⟩ + intro m hm + have H:=Nat.mul_le_mul_left D (hp m hm) + have heq : Finsupp.weight (fun j=>D*w j) m=D*Finsupp.weight w m := by + simp only [Finsupp.weight_apply,smul_eq_mul,Finsupp.sum] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j hj + ring + simpa only [heq] using H +end WeightedPolynomial + +namespace RationalLattice +open WeightedPolynomial MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) +omit [IsTopologicalGroup G] in +lemma canonicalLog_natpow (g : G) (m : ℕ) : + canonicalLog c (g^m)=(m:ℝ) • canonicalLog c g := by + have H:=canonicalLog_realPower c g (m:ℝ) + simpa only [realPower_nat] using H + +variable (hsk : SecondKind c) (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i,w i1) D a) (g x : G) (i : Fin n) : + IsWeighted (fun _ : σ=>1) (D*w i) + (fun z=>canonicalLog c (realPower c g (a z)*x) i) := by + have hs (j : Fin n ⊕ Fin n) : IsWeighted (fun _ : σ=>1) (D*Sum.elim w w j) + (fun z=>Sum.elim (canonicalLog c (realPower c g (a z))) (canonicalLog c x) j) := by + cases j with + | inl j => + have hh:=(ha.mono (Nat.le_mul_of_pos_right D (hw j))).smul (canonicalLog c g j) + simpa only [Sum.elim_inl,canonicalLog_realPower,Pi.smul_apply,smul_eq_mul,mul_comm] using hh + | inr j => exact IsWeighted.const _ _ _ + have H:=((log_multiplication_weighted c hsk A w hA i).scale D).comp hs + simpa only [Sum.elim_inl,Sum.elim_inr,canonicalExp_log] using H +end RationalLattice + +namespace RationalLattice.PolynomialArrays +open WeightedPolynomial MalcevCharacters PolynomialArrayInterpolation +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i,w i1) D b) + (hv : ∀ j,IsWeighted (fun _ : σ=>1) D (fun z=>v z j)) + (g x : G) (i : Fin (Fintype.card (Index w q))) : + IsWeighted (fun _ : σ=>1) (D*orderedWeight (q:=q) w i) + (fun z=>canonicalLog (chart c hsk A w hA hw) + (sourceElement c hsk A w hA hw g x (b z) (v z)) i) := by + simp only [chart_canonicalLog] + let a : Index w q:=SortedFiniteWeights.indexing (weight w) i + change IsWeighted (fun _ : σ=>1) (D*w a.1) + (fun z=>∑ u : Grid q (w a.1),(IntegerGridInterpolation.tensorWeight q (w a.1) a.2.val u:ℝ)* + canonicalLog c (realPower c g (b z+∑ j,v z j*((u j).val:ℝ))*x) a.1) + apply IsWeighted.sum + intro u hu + apply IsWeighted.smul + apply power_translate_log_weighted c hsk A w hA hw + apply hb.add + apply IsWeighted.sum + intro j hj + simpa only [mul_comm] using (hv j).smul ((u j).val:ℝ) + +end RationalLattice.PolynomialArrays + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice20.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice20.lean new file mode 100644 index 0000000000000000000000000000000000000000..572e24d4a09e16c57d6fdeba6397308a84d85bf8 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice20.lean @@ -0,0 +1,325 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.IntegerArrays02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +noncomputable section +end + +noncomputable section +namespace SourceIntegerArrays +open RationalLattice MalcevCharacters RoughArrayFace RoughArrayCoordinates SourceResidueAlignment +open ProductExposureLabels +open scoped BigOperators +attribute [local instance] Classical.propDecidable +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jintegerCoordinates_discrete (c i) (Γ i) (hΓ i) + let : ∀ i,DiscreteTopology (PolynomialArrays.lattice (q:=q) (c i) (hsk i) (A i) (w i) (hA i) (Γ i)) := + fun i=>PolynomialArrays.lattice_discrete (c i) (hsk i) (A i) (w i) (hA i) (Γ i) + let emb (f : Λ) : ∀ i,PolynomialArrays.lattice (q:=q) (c i) (hsk i) (A i) (w i) (hA i) (Γ i) := + fun i=>⟨f.val i,f.property i⟩ + have he : Continuous emb := continuous_pi (fun i=>Continuous.subtype_mk + ((continuous_apply i).comp continuous_subtype_val) _) + have hinj : Function.Injective emb := by + intro f g hfg + apply Subtype.ext + funext i + exact congrArg Subtype.val (congrFun hfg i) + let : DiscreteTopology Λ := DiscreteTopology.of_continuous_injective he hinj + let : IsClosed (Λ : Set V) := Λ.isClosed_of_discreteTopology + let : T2Space (V⧸Λ) := inferInstance + let : SecondCountableTopology (V⧸Λ) := inferInstance + obtain ⟨chart,grid,hgridpos,hgrid,J,hJ,hdegree⟩ := source_joint_geometry G n q c hsk A w hA hw Γ hΓ + obtain ⟨Λ₀,ec,hec,hΛ,hle,D,hD,hdeg⟩ := RoughCoveredFace.grid_second_degree_cover chart Λ grid hgridpos hgrid + have hcompact : CompactSpace (V⧸Λ) := by + obtain ⟨S,hS,hrep⟩ := compact_reps_of_integerCoordinates ec Λ₀ hΛ + apply CompactGroupProducts.HasCompactReps.quotient_compactSpace + refine ⟨S,hS,fun _ _=>Subgroup.mem_top _,?_⟩ + intro u _ + obtain ⟨s,hs,hsa⟩ := hrep u + exact ⟨s,hs,hle hsa⟩ + let := hcompact + let : WeaklyLocallyCompactSpace (V⧸Λ) := ⟨fun _=>⟨Set.univ,isCompact_univ,Filter.univ_mem⟩⟩ + let : R1Space (V⧸Λ) := T2Space.r1Space + let : RegularSpace (V⧸Λ) := .of_hasBasis isCompact_isClosed_basis_nhds (fun _ _ ⟨_,_,h⟩=>h) + have : T3Space (V⧸Λ) := instT3Space + exact ⟨inferInstance,inferInstance,hcompact,TopologicalSpace.metrizableSpace_of_t3_secondCountable (V⧸Λ)⟩ + +end SourceIntegerArrays +end + +noncomputable section +namespace SourceIntegerArrays +open RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift RoughTopologicalFace RoughArrayCoordinates SourceResidueAlignment +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory Filter +open scoped BigOperators Topology ENNReal +attribute [local instance] Classical.propDecidable +variable {τ : Type} [Fintype τ] {ι : τ→Type} [∀ t,Fintype (ι t)] +variable (G : ∀ t,ι t→Type) [∀ t i,Group (G t i)] +variable [∀ t i,TopologicalSpace (G t i)] [∀ t i,IsTopologicalGroup (G t i)] +variable (n : ∀ t,ι t→ℕ) (q : τ→ℕ) (c : ∀ t i,RealCoordinates (G t i) (n t i)) +variable (hsk : ∀ t i,SecondKind (c t i)) (A : ∀ t i,CubeFaces.Filtration (G t i)) +variable (w : ∀ t i,Fin (n t i)→ℕ) +variable (hA : ∀ t i k (g : G t i),g∈(A t i).level k ↔ ∀ j,w t i jX N j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ N,0R N/(Xp N:ℝ)) atTop (𝓝 0)) + (hZ : ∀ t (u : ℝ),0(R N/(M N:ℝ))/ + (1+∑ j : Fin (m t),(X N (perm t (j.castAdd (h t))):ℝ)^2)^u) atTop atTop) + (hQ0 : ∀ N,0≤Q N) + (hSize : ∀ t,Tendsto (fun N=>(Q N+(∏ l : Fin (m t),(X N (perm t (l.castAdd (h t))):ℝ)^2)*(L N:ℝ))/R N) atTop (𝓝 0)) + (hWM : ∀ N,(primorial (w0 N):ℤ)∣(M N:ℤ)) + (hM : ∀ N,0(X N (perm t (j.castAdd (h t))):ℝ)/(L N:ℝ)) atTop atTop) + (g x : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→∀ i,G t i) + (slot : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→ι t→ℤ) + (qval : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→Fin (q t)→ℤ) + (hQ : ∀ t N y,y∈outsideDomain (fun l : Fin (h t)=>X N (perm t (l.natAdd (m t)))) (primorial (w0 N)) → + ∀ b,b∈(fullDomain (fun l : Fin (m t)=>X N (perm t (l.castAdd (h t)))) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) →∀ k,|(qval t N y b k:ℝ)|≤Q N) + (E : ℕ→Set ((Fin a→ℕ)×ℕ)) (ε : ℝ≥0∞) (hε : 0<ε) + (hE : ∀ N,ε≤(jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) + (hX N) (hXp N)) (E N)) : + ∃ φ : ℕ→ℕ,StrictMono φ ∧ ∃ z : ℕ→(Fin a→ℕ)×ℕ, + (∀ k,z k∈E (φ k) ∧ z k∈fullDomain (X (φ k)) (Xp (φ k)) (primorial (w0 (φ k)))) ∧ + ∀ t, + let zout := fun k l=>(z k).1 (perm t (l.natAdd (m t))) + let zin := fun k=>((fun l=>(z k).1 (perm t (l.castAdd (h t)))),(z k).2) + let label := fun k=>expose (L (φ k)) (M (φ k):ℤ) (R (φ k)) (zin k) + let Z := fun k=>R (φ k)/(M (φ k):ℝ) + ∀ (e : Fin (q t)) (j : Fin (v t)) (d : ℕ),0QuotientGroup.mk + (literalState (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (hw t) + (M (φ k)) (L (φ k)) (label k) (fun l=>((zin k).1 l:ℤ)) (pstar k) + (fun _ (_ : Fin 1)=>1) + (g t (φ k) (zout k) (label k)) (x t (φ k) (zout k) (label k)) + (slot t (φ k) (zout k) (label k)) (qval t (φ k) (zout k) (label k)) (fun _=>b)) + ∀ (c₀ C₀ : ℝ),0mean (physicalResidueBox (lo k) (hi k) (res k) d) + (fun β=>F (fun S=>if j∈S then + faceAction (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (Γ t) + (fun _ (_ : Fin 1)=>1) e 0 (state k (cubeVertex (v t) β S)) + else state k (cubeVertex (v t) β S)))- + mean (physicalResidueBox (lo k) (hi k) (res k) d) + (fun β=>F (fun S=>state k (cubeVertex (v t) β S)))) atTop (𝓝 0) + := by + classical + let Gd := fun t=>DG (G t) (v t) + let nd := fun t=>Dn (n t) (v t) + let cd := fun t=>Dc (c t) (v t) + let skd := fun t=>Dhsk (hsk t) (v t) + let Ad := fun t=>DA (A t) (v t) + let wd := fun t=>Dw (w t) (v t) + let hAd := fun t=>DhA (hA t) (v t) + let hwd := fun t=>Dhw (hw t) (v t) + let Γd := fun t=>DΓ (Γ t) (v t) + have hΓd : ∀ t i f,f∈Γd t i ↔ ∀ j,∃ z : ℤ,(cd t i).coord f j=z := fun t i=>hΓ t i.1 + let Qd := fun t=>(Carrier (Gd t) (nd t) (q t) (cd t) (skd t) (Ad t) (wd t) (hAd t))⧸ + lattice (Gd t) (nd t) (q t) (cd t) (skd t) (Ad t) (wd t) (hAd t) (Γd t) + let : ∀ t,TopologicalSpace.MetrizableSpace (Qd t) := fun t=> + (joint_array_topology (Gd t) (nd t) (q t) (cd t) (skd t) (Ad t) (wd t) (hAd t) (hwd t) (Γd t) (hΓd t)).2.2.2 + let : ∀ t,MetricSpace (Qd t) := fun t=>TopologicalSpace.metrizableSpaceMetric (Qd t) + have htop : ∀ t,(inferInstance : MetricSpace (Qd t)).toUniformSpace.toTopologicalSpace= + QuotientGroup.instTopologicalSpace (lattice (Gd t) (nd t) (q t) (cd t) (skd t) (Ad t) (wd t) (hAd t) (Γd t)) := + fun _=>rfl + obtain ⟨φ,hφ,z,hz,hgood⟩ := source_global_literal_array_faces Gd nd q cd skd Ad wd hAd hwd Γd hΓd htop + a m h v perm w0 M Xp X R Q L hw0 hX hXp hXt hXpt hR hRX hZ hQ0 hSize hWM hM hMs + hL hsm hWL hML hLexact hXL (fun t b=>cubePattern (v t) b.2) (fun _ _=>rfl) + (fun t N y b i=>g t N y b i.1) (fun t N y b i=>x t N y b i.1) + (fun t N y b i=>slot t N y b i.1) qval hQ E ε hε hE + refine ⟨φ,hφ,z,hz,?_⟩ + intro t + dsimp only + intro e j d hd pstar hpstar hpclose c₀ C₀ hc₀ hC₀ lo hi res hbox F + let π:=cubeProjection (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (Γ t) (v t) + have hh:=hgood t e j.succ d hd pstar hpstar hpclose c₀ C₀ hc₀ hC₀ lo hi res hbox (F.comp π) + apply hh.congr' + apply Filter.Eventually.of_forall + intro k + apply congrArg₂ (fun a b : ℂ=>a-b) + · apply congrArg (mean (physicalResidueBox (lo k) (hi k) (res k) d)) + funext β + apply congrArg F + funext S + dsimp only [π,Gd,nd,cd,skd,Ad,wd,hAd,hwd,Γd] + rw [cubeProjection_face,cubeProjection_literal] + · apply congrArg (mean (physicalResidueBox (lo k) (hi k) (res k) d)) + funext β + apply congrArg F + funext S + exact cubeProjection_literal (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (hw t) (Γ t) (v t) + _ _ _ _ _ _ _ _ _ β S + +end SourceIntegerArrays +end + + + +section + + + + +noncomputable section +open scoped Topology +namespace RationalLattice +open MalcevCharacters +variable {G H : Type*} [Group G] [Group H] +variable [TopologicalSpace G] [TopologicalSpace H] +variable [IsTopologicalGroup G] [IsTopologicalGroup H] +variable {m n : ℕ} (c : RealCoordinates G m) (d : RealCoordinates H n) + + + +theorem exists_joint_integer_sublattice (F : H →* G) + (hpoly : IsPolynomialMap c (fun x : Fin n → ℝ=>F (d.coord.symm x))) + (hc : Continuous F) (hinj : Function.Injective F) + (Γ : Subgroup G) (Ξ : Subgroup H) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (hΞ : ∀ g : H,g∈Ξ ↔ ∀ i,∃ z : ℤ,d.coord g i=z) : + ∃ Δ : Subgroup H,∃ e : RealCoordinates H n, + SecondKind e ∧ (∀ g : H,g∈Δ ↔ ∀ i,∃ z : ℤ,e.coord g i=z) ∧ + Δ≤Ξ ∧ Δ≤Γ.comap F ∧ (Δ.subgroupOf Ξ).FiniteIndex ∧ + (Δ.subgroupOf (Γ.comap F)).FiniteIndex ∧ + (∀ (B : Subgroup H) (k : ℕ), + (∀ g,g∈B ↔ ∀ i : Fin n,i.valσ⁻¹*F x*σ) := + funext (conjugateEmbedding_apply F σ) + rw [he] + exact (continuous_const.mul hc).mul continuous_const + have hinj' : Function.Injective (conjugateEmbedding F σ):= + (MulAut.conj σ⁻¹).injective.comp hinj + have hrat' (x : H) (hx : IsRational d x) : + IsRational c (conjugateEmbedding F σ x) := by + rw [conjugateEmbedding_apply] + exact rational_mul c (rational_mul c (rational_inv c hσ) (hrat x hx)) hσ + exact exists_joint_integer_sublattice c d (conjugateEmbedding F σ) + (rationalHom_polynomial c d hsk _ hcont hrat') hcont hinj' Γ Ξ hΓ hΞ + +end RationalLattice + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice21.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice21.lean new file mode 100644 index 0000000000000000000000000000000000000000..05ccbf53b609c31651d8a6c11252832965a87295 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice21.lean @@ -0,0 +1,287 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice19 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +noncomputable section +end + + + +section + + + + +noncomputable section +namespace RationalLattice +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (Γ : Subgroup G) + +structure CoveredLattice where + small : Subgroup G + integer : ∀ g,g∈small ↔ ∀ i,∃ z : ℤ,c.coord g i=z + le : small≤Γ + discrete : DiscreteTopology Γ + +namespace CoveredLattice +variable (B : CoveredLattice c Γ) +omit [IsTopologicalGroup G] in +lemma conjugate_le [IsTopologicalGroup G] (σ : G) : + CubeLocalHaar.conjugateLattice B.small σ≤CubeLocalHaar.conjugateLattice Γ σ:= + fun _ h=>B.le h +include B in +lemma conjugate_discrete (σ : G) : DiscreteTopology (CubeLocalHaar.conjugateLattice Γ σ) := by + let : DiscreteTopology Γ:=B.discrete + exact DiscreteTopology.preimage_of_continuous_injective (Γ:Set G) + (show Continuous (MulAut.conj σ⁻¹).toMonoidHom from + (continuous_const.mul continuous_id).mul continuous_const) (MulAut.conj σ⁻¹).injective +include B in +lemma conjugate_quotient_t2 (σ : G) : T2Space (G⧸CubeLocalHaar.conjugateLattice Γ σ) := by + let : T2Space G:=c.coord.symm.t2Space + let : DiscreteTopology (CubeLocalHaar.conjugateLattice Γ σ):=B.conjugate_discrete c Γ σ + let : IsClosed (CubeLocalHaar.conjugateLattice Γ σ : Set G):= + (CubeLocalHaar.conjugateLattice Γ σ).isClosed_of_discreteTopology + infer_instance + +variable {K : Type} [Group K] [TopologicalSpace K] [IsTopologicalGroup K] +variable (F : K →* G) (hF : Continuous F) (hinj : Function.Injective F) +include B hF hinj in +omit [IsTopologicalGroup K] in +lemma conjugate_induced_discrete [IsTopologicalGroup K] (σ : G) : + DiscreteTopology ((CubeLocalHaar.conjugateLattice Γ σ).comap F) := by + let : DiscreteTopology (CubeLocalHaar.conjugateLattice Γ σ):=B.conjugate_discrete c Γ σ + exact DiscreteTopology.preimage_of_continuous_injective + (CubeLocalHaar.conjugateLattice Γ σ : Set G) hF hinj +end CoveredLattice + +end RationalLattice +end + +end + +section + + + + +noncomputable section +namespace RationalLattice.PolynomialArrays +open MalcevCharacters MalcevWeightedCoordinates +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n q : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w i(secondCoordinates_rational d g).trans (hr g)⟩ + intro k g + obtain ⟨r,_,he⟩:=exists_weight_cutoff w hmono k + have hd : ∀ g : G,g∈A.level k ↔ ∀ i : Fin n,i.val∀ i,g i∈Γ i + one_mem':=fun i=>(Γ i).one_mem + mul_mem':=fun hg hh i=>(Γ i).mul_mem (hg i) (hh i) + inv_mem':=fun hg i=>(Γ i).inv_mem (hg i) + +def projection (i : ι) : (∀ i,G i) →* G i where + toFun g:=g i + map_one':=rfl + map_mul' _ _:=rfl +omit [Fintype ι] [∀ index,IsTopologicalGroup (G index)] in +lemma projection_continuous [Fintype ι] [∀ index,IsTopologicalGroup (G index)] + (i : ι) : Continuous (projection G i):=continuous_apply i + +include B in +omit [∀ index,IsTopologicalGroup (G index)] in +lemma lattice_discrete [∀ index,IsTopologicalGroup (G index)] : + DiscreteTopology (lattice G Γ) := by + let (i : ι) : DiscreteTopology (Γ i):=(B i).discrete + let F : lattice G Γ → ∀ i,Γ i:=fun g i=>⟨g.val i,g.property i⟩ + have hF : Continuous F:=continuous_pi (fun i=> + ((continuous_apply i).comp continuous_subtype_val).subtype_mk _) + apply DiscreteTopology.of_continuous_injective hF + intro g h he + apply Subtype.ext + funext i + exact congrArg Subtype.val (congrFun he i) + +include B in +lemma grid_lattice : ∃ D : ℕ,0hD i),?_⟩ + intro g hg i + apply (B i).le + apply ((B i).integer _).mpr + have hd : ∀ j,∃ z : ℤ,d.coord g j=(D i:ℝ)*z:=by + intro j + obtain ⟨a,ha⟩:=hg j + obtain ⟨b,hb⟩:=Finset.dvd_prod_of_mem D (Finset.mem_univ i) + refine ⟨(b:ℤ)*a,?_⟩ + rw [ha,hb] + push_cast + ring + have hh:=hgrid i (d.coord g) hd + simp only [Homeomorph.symm_apply_apply] at hh + exact hh + +include B hmono in +lemma covered_geometry : ∃ e : RealCoordinates (∀ i,G i) (Fintype.card (Index n)), + SecondKind e ∧ Nonempty (CoveredLattice e (lattice G Γ)) ∧ + (∀ k g,g∈(filtration G A).level k ↔ ∀ j,orderedWeight n w jSubgroup.mem_top _,?_⟩ + intro g _ + obtain ⟨a,ha,hag⟩:=hrep g + exact ⟨a,ha,C.le hag⟩ + +omit [Fintype ι] [∀ index,IsTopologicalGroup (G index)] in +lemma filtration_top [Fintype ι] [∀ index,IsTopologicalGroup (G index)] + (k : ℕ) (hk : ∀ i,(A i).level k=⊤) : (filtration G A).level k=⊤ := by + apply top_unique + intro g _ i + rw [hk i] + trivial +omit [Fintype ι] [∀ index,IsTopologicalGroup (G index)] in +lemma filtration_terminal [Fintype ι] [∀ index,IsTopologicalGroup (G index)] + (s : ℕ) (hs : ∀ i,(A i).level (s+1)=⊥) : + (filtration G A).level (s+1)=⊥ := by + apply bot_unique + intro g hg + apply Subgroup.mem_bot.mpr + funext i + exact Subgroup.mem_bot.mp (hs i ▸ hg i) + +end RationalLattice.FiniteProducts + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice22.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice22.lean new file mode 100644 index 0000000000000000000000000000000000000000..c4a56a7c32059db2f6a139d9d035c7ad365d21e2 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice22.lean @@ -0,0 +1,318 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.EmbeddedCube01 +import OAI.Combinatorics.SumProduct.Alignment.IntegerArrays01 +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice21 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalLattice.JointArrays +open MalcevCharacters CubePolynomials +variable {ι : Type} [Fintype ι] (G : ι → Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n q : ι → ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i) → ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jPolynomialArrays.filtration (q:=q i) (c i) (hsk i) (A i) (w i) (hA i)) +variable (Γ : ∀ i,Subgroup (G i)) +variable (hΓ : ∀ i g,g∈Γ i ↔ ∀ j,∃ z : ℤ,(c i).coord g j=z) +abbrev lattice : Subgroup (Carrier G n q c hsk A w hA) := FiniteProducts.lattice (Component G n q c hsk A w hA) + (fun i=>PolynomialArrays.lattice (q:=q i) (c i) (hsk i) (A i) (w i) (hA i) (Γ i)) +abbrev jointWeight := FiniteProducts.orderedWeight (dimension n q w) (componentWeight n q w) + +include hw hmono hΓ in +lemma covered_geometry : ∃ e : RealCoordinates (Carrier G n q c hsk A w hA) + (Fintype.card (FiniteProducts.Index (dimension n q w))), + SecondKind e ∧ Nonempty (CoveredLattice e (lattice G n q c hsk A w hA Γ)) ∧ + (∀ k f,f∈(filtration G n q c hsk A w hA).level k ↔ + ∀ j,jointWeight n q w j(u j:ℝ)))) := by + classical + have hi (i : ι):=PolynomialArrays.covered_geometry (q:=q i) + (c i) (hsk i) (A i) (w i) (hA i) (hw i) (hmono i) (Γ i) (hΓ i) + choose d hds hdB hda hdr using hi + let B (i : ι):=Classical.choice (hdB i) + let K:=Component G n q c hsk A w hA + let T i:=PolynomialArrays.filtration (q:=q i) (c i) (hsk i) (A i) (w i) (hA i) + let v i:=PolynomialArrays.orderedWeight (q:=q i) (w i) + have hv (i : ι) (j : Fin (dimension n q w i)) : 0PolynomialArrays.lattice (q:=q i) (c i) (hsk i) (A i) (w i) (hA i) (Γ i)) B + refine ⟨e,he,hB,ha,?_⟩ + intro f hf i u + have hd:=FiniteProducts.projection_rational K (dimension n q w) d hds T v hv hda f (hr f |>.mp hf) i + have hc:=(hdr i (f i)).mp hd + exact PolynomialArrays.evaluate_rational (c i) (hsk i) (A i) (w i) (hA i) (hw i) u (f i) hc + +lemma filtration_top (k : ℕ) (hk : ∀ i,(A i).level k=⊤) : + (filtration G n q c hsk A w hA).level k=⊤ := + FiniteProducts.filtration_top _ _ k (fun i=>PolynomialArrays.filtration_top + (c i) (hsk i) (A i) (w i) (hA i) k (hk i)) +lemma filtration_terminal (s : ℕ) (hs : ∀ i,(A i).level (s+1)=⊥) : + (filtration G n q c hsk A w hA).level (s+1)=⊥ := + FiniteProducts.filtration_terminal _ _ s (fun i=>PolynomialArrays.filtration_terminal + (c i) (hsk i) (A i) (w i) (hA i) s (hs i)) + +def orbit (g x : ∀ i,G i) (t : ι → ℤ) (b : ι → ℝ) (v : ∀ i,Fin (q i) → ℝ) (z : ℤ) : + Carrier G n q c hsk A w hA:= + fun i=>PolynomialArrays.sourceOrbit (c i) (hsk i) (A i) (w i) (hA i) (hw i) + (g i) (x i) (t i) (b i) (v i) z + +omit [Fintype ι] in +lemma orbit_apply [Fintype ι] (g x : ∀ i,G i) (t : ι → ℤ) (b : ι → ℝ) (v : ∀ i,Fin (q i) → ℝ) + (z : ℤ) (i : ι) (u : Fin (q i) → ℝ) : + ((orbit G n q c hsk A w hA hw g x t b v z) i).val u= + realPower (c i) (g i) (b i+(t i:ℝ)*z+∑ j,v i j*u j)*x i := + PolynomialArrays.sourceOrbit_apply (c i) (hsk i) (A i) (w i) (hA i) (hw i) + (g i) (x i) (t i) (b i) (v i) u z + +lemma orbit_polynomial (h0 : ∀ i,(A i).level 0=⊤) (h1 : ∀ i,(A i).level 1=⊤) + (g x : ∀ i,G i) (t : ι → ℤ) (b : ι → ℝ) (v : ∀ i,Fin (q i) → ℝ) : + orbit G n q c hsk A w hA hw g x t b v∈polynomials (filtration G n q c hsk A w hA) 0 := by + let a : Carrier G n q c hsk A w hA:=fun i=>PolynomialArrays.constantElement + (q:=q i) (c i) (hsk i) (A i) (w i) (hA i) (g i^t i) + let x₀ : Carrier G n q c hsk A w hA:=fun i=>PolynomialArrays.sourceElement + (c i) (hsk i) (A i) (w i) (hA i) (hw i) (g i) (x i) (b i) (v i) + have hp:=power_polynomial_mem 1 0 a (by + rw [Nat.add_zero,filtration_top G n q c hsk A w hA 1 h1] + trivial) Polynomial.X (by simp) + have hc : (fun _ : ℤ=>x₀)∈polynomials (filtration G n q c hsk A w hA) 0:=const_mem (by + rw [filtration_top G n q c hsk A w hA 0 h0] + trivial) + have H:=(polynomials (filtration G n q c hsk A w hA) 0).mul_mem hp hc + simp only [Polynomial.eval_X,Pi.mul_def] at H + exact H + +end RationalLattice.JointArrays +end + +end + +section + + + + +noncomputable section +open scoped Topology +open Filter MeasureTheory +namespace AllLevelFactorization +open RationalLattice CubeFaces MalcevCharacters MalcevWeightedCoordinates +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (Γ : Subgroup G) (B : CoveredLattice c Γ) +variable (s : ℕ) (K : Filtration G) (w : Fin n → ℕ) +variable (hsk : SecondKind c) (hmono : Monotone w) +variable (hK : ∀ k (g : G),g∈K.level k ↔ ∀ i,w iexists_weight_cutoff w hmono k + apply factorization_exists hsk B.integer h0 h1 hs r hr _ hP hL + intro k g + rw [hK k g] + exact forall_congr' (fun i=>by rw [he k i]) + + + +def coveredFactorization : Factorization c B.small s K P L := + Classical.choice (covered_factorization_exists c Γ B s K w hsk hmono hK h0 h1 hs P hP L hL) + +def coveredResidues (F : Factorization c B.small s K P L) (r : Fin F.period) : F.ResidueCover r := + F.residueCover B.integer r + +include B in +omit [IsTopologicalGroup G] in +lemma covered_quotient_compact [IsTopologicalGroup G] : CompactSpace (G⧸Γ) := by + obtain ⟨S,hS,hrep⟩:=compact_reps_of_integerCoordinates c B.small B.integer + apply CompactGroupProducts.HasCompactReps.quotient_compactSpace + refine ⟨S,hS,fun _ _=>Subgroup.mem_top _,?_⟩ + intro g _ + obtain ⟨a,ha,hag⟩:=hrep g + exact ⟨a,ha,B.le hag⟩ + +end AllLevelFactorization +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalLattice.JointArrays +open MalcevCharacters CubePolynomials +variable {ι : Type} [Fintype ι] (G : ι → Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n q : ι → ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i) → ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i j(u j:ℝ)))) ∧ + Nonempty (AllLevelFactorization.Factorization e B.small s + (filtration G n q c hsk A w hA) + (fun N=>orbit G n q c hsk A w hA hw (g N) (x N) (t N) (b N) (v N)) L) := by + obtain ⟨e,he,⟨B⟩,ha,hr⟩:=covered_geometry G n q c hsk A w hA hw hmono Γ hΓ + refine ⟨e,B,he,ha,hr,?_⟩ + apply AllLevelFactorization.covered_factorization_exists e _ B s _ (jointWeight n q w) + he (FiniteProducts.orderedWeight_monotone _ _) ha + (filtration_top G n q c hsk A w hA 0 h0) + (filtration_top G n q c hsk A w hA 1 h1) + (filtration_terminal G n q c hsk A w hA s hs) + _ _ L hL + intro N + exact orbit_polynomial G n q c hsk A w hA hw h0 h1 (g N) (x N) (t N) (b N) (v N) + +end RationalLattice.JointArrays +end + +end + +noncomputable section +open scoped BigOperators +namespace SourceIntegerArrays +open ProductExposureLabels +lemma exponent_column_affine {m q : ℕ} (M : ℕ) (hM : 01) (fun _=>u) qval 0= + exponent M L b tail pstar slot (fun _ : Fin 1=>1) (fun _=>0) qval 0+(∏ j,tail j)*u := by + simp only [exponent,Pi.zero_apply,one_mul,mul_zero,Finset.sum_const_zero,add_zero] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,Nat.zero_add,one_nsmul] + have he : (∏ j,tail j)*(pstar+(M:ℤ)*u+slot)-rSlot M b slot= + ((∏ j,tail j)*(pstar+slot)-rSlot M b slot)+(M:ℤ)*((∏ j,tail j)*u) := by ring + rw [he,Int.add_mul_ediv_left _ _ (by exact_mod_cast (hM.ne'))] +end SourceIntegerArrays +end + +noncomputable section +open scoped BigOperators +namespace SourceIntegerArrays +open RationalLattice MalcevCharacters ProductExposureLabels SourceResidueAlignment +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n q m : ι→ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i j + PolynomialArrays.sourceElement (c i) (hsk i) (A i) (w i) (hA i) (hw i) (g i) (x i) + (exponent M L (b i) (tail i) (pstar i) (slot i) (fun _ : Fin 1=>1) (fun _=>u) (qval i) 0:ℝ) + (fun e=>(shift M L (qval i e) (b i) (tail i):ℝ)) + +lemma literalJoint_eq_orbit (M : ℕ) (hM : 0∏ j,tail i j) + (fun i=>(exponent M L (b i) (tail i) (pstar i) (slot i) + (fun _ : Fin 1=>1) (fun _=>0) (qval i) 0:ℝ)) + (fun i e=>(shift M L (qval i e) (b i) (tail i):ℝ)) u := by + funext i + apply Subtype.ext + funext z + rw [JointArrays.orbit_apply] + change realPower (c i) (g i) + ((exponent M L (b i) (tail i) (pstar i) (slot i) (fun _ : Fin 1=>1) (fun _=>u) (qval i) 0:ℝ)+ + ∑ e,(shift M L (qval i e) (b i) (tail i):ℝ)*z e)*x i=_ + rw [exponent_column_affine M hM] + push_cast + rfl + + + +theorem literal_joint_factorization + (hmono : ∀ i,Monotone (w i)) (Γ : ∀ i,Subgroup (G i)) + (hΓ : ∀ i g,g∈Γ i ↔ ∀ j,∃ z : ℤ,(c i).coord g j=z) + (s : ℕ) (h0 : ∀ i,(A i).level 0=⊤) (h1 : ∀ i,(A i).level 1=⊤) + (hs : ∀ i,(A i).level (s+1)=⊥) + (M : ℕ→ℕ) (hM : ∀ N,0(u j:ℝ)))) ∧ + Nonempty (AllLevelFactorization.Factorization e B.small s + (JointArrays.filtration G n q c hsk A w hA) + (fun N=>literalJoint G n q m c hsk A w hA hw (M N) (L N) (b N) (tail N) + (pstar N) (slot N) (qval N) (g N) (x N)) Z) + := by + have he : (fun N=>literalJoint G n q m c hsk A w hA hw (M N) (L N) (b N) (tail N) + (pstar N) (slot N) (qval N) (g N) (x N))= + (fun N=>JointArrays.orbit G n q c hsk A w hA hw (g N) (x N) (fun i=>∏ j,tail N i j) + (fun i=>(exponent (M N) (L N) (b N i) (tail N i) (pstar N i) (slot N i) + (fun _ : Fin 1=>1) (fun _=>0) (qval N i) 0:ℝ)) + (fun i e=>(shift (M N) (L N) (qval N i e) (b N i) (tail N i):ℝ))) := by + funext N u + exact literalJoint_eq_orbit G n q m c hsk A w hA hw (M N) (hM N) (L N) (b N) (tail N) + (pstar N) (slot N) (qval N) (g N) (x N) u + rw [he] + exact JointArrays.factorization_exists G n q c hsk A w hA hw hmono Γ hΓ s h0 h1 hs + g x _ _ _ Z hZ + +end SourceIntegerArrays + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice23.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice23.lean new file mode 100644 index 0000000000000000000000000000000000000000..bf8dce9d1ac647256f16d0ac4b2b81c1bfc6ea7e --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice23.lean @@ -0,0 +1,275 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.IntegerArrays04 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +noncomputable section +end + +noncomputable section +namespace SourceIntegerArrays +open GlobalJoint +open RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift RoughTopologicalFace RoughArrayCoordinates SourceResidueAlignment +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory Filter +open scoped BigOperators Topology ENNReal BoundedContinuousFunction NNReal +attribute [local instance] Classical.propDecidable +variable {τ : Type} [Fintype τ] {ι : τ→Type} [∀ t,Fintype (ι t)] +variable (G : ∀ t,ι t→Type) [∀ t i,Group (G t i)] +variable [∀ t i,TopologicalSpace (G t i)] [∀ t i,IsTopologicalGroup (G t i)] +variable (n : ∀ t,ι t→ℕ) (q : τ→ℕ) (c : ∀ t i,RealCoordinates (G t i) (n t i)) +variable (hsk : ∀ t i,SecondKind (c t i)) (A : ∀ t i,CubeFaces.Filtration (G t i)) +variable (w : ∀ t i,Fin (n t i)→ℕ) +variable (hA : ∀ t i k (g : G t i),g∈(A t i).level k ↔ ∀ j,w t i jX N j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ N,0R N/(Xp N:ℝ)) atTop (𝓝 0)) + (hZ : ∀ t (u : ℝ),0(R N/(M N:ℝ))/ + (1+∑ j : Fin (m t),(X N (perm t (j.castAdd (h t))):ℝ)^2)^u) atTop atTop) + (hQ0 : ∀ N,0≤Q N) + (hSize : ∀ t,Tendsto (fun N=>(Q N+(∏ l : Fin (m t),(X N (perm t (l.castAdd (h t))):ℝ)^2)*(L N:ℝ))/R N) atTop (𝓝 0)) + (hWM : ∀ N,(primorial (w0 N):ℤ)∣(M N:ℤ)) + (hM : ∀ N,0(X N (perm t (j.castAdd (h t))):ℝ)/(L N:ℝ)) atTop atTop) + (g x : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→∀ i,G t i) + (slot : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→ι t→ℤ) + (qval : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→Fin (q t)→ℤ) + (hQ : ∀ t N y,y∈outsideDomain (fun l : Fin (h t)=>X N (perm t (l.natAdd (m t)))) (primorial (w0 N)) → + ∀ b,b∈(fullDomain (fun l : Fin (m t)=>X N (perm t (l.castAdd (h t)))) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) →∀ k,|(qval t N y b k:ℝ)|≤Q N) + {κ : Type} [Fintype κ] (Yobs : κ→Type) [∀ i,MetricSpace (Yobs i)] [∀ i,CompactSpace (Yobs i)] + (Obs : ℕ→((Fin a→ℕ)×ℕ)→(i : κ)→Yobs i →ᵇ ℝ) (Kobs : ℝ≥0) (Bobs : ℝ) + (hLip : ∀ N z i,LipschitzWith Kobs (Obs N z i)) + (hBound : ∀ N z i y,|Obs N z i y|≤Bobs) + (E : ℕ→Set ((Fin a→ℕ)×ℕ)) (ε : ℝ≥0∞) (hε : 0<ε) + (hE : ∀ N,ε≤(jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) + (hX N) (hXp N)) (E N)) : + ∃ φ : ℕ→ℕ,StrictMono φ ∧ ∃ z : ℕ→(Fin a→ℕ)×ℕ, + (∀ k,z k∈E (φ k) ∧ z k∈fullDomain (X (φ k)) (Xp (φ k)) (primorial (w0 (φ k)))) ∧ + ∃ f : (i : κ)→Yobs i →ᵇ ℝ, + (∀ i,TendstoUniformly (fun k=>Obs (φ k) (z k) i) (f i) atTop) ∧ + (∀ η : ℝ,0<η →∀ᶠ k in atTop,∀ i y,|Obs (φ k) (z k) i y-f i y|<η) ∧ + ∀ pstar : τ→ℕ→ℤ, + (∀ t k,(M (φ k):ℤ)∣pstar t k-((z k).2:ℤ)) → + (∀ t k,|(pstar t k:ℝ)-((z k).2:ℝ)|≤R (φ k)) → + let zout := fun t k l=>(z k).1 (perm t (l.natAdd (m t))) + let zin := fun t k=>((fun l=>(z k).1 (perm t (l.castAdd (h t)))),(z k).2) + let label := fun t k=>expose (L (φ k)) (M (φ k):ℤ) (R (φ k)) (zin t k) + FactorizedAllHaar G n q c hsk A w hA Γ s + (fun k=>rawJoint G n q m c hsk A w hA hw (M (φ k)) (L (φ k)) + (fun t=>label t k) (fun t l=>((zin t k).1 l:ℤ)) (fun t=>pstar t k) + (fun t=>slot t (φ k) (zout t k) (label t k)) + (fun t=>qval t (φ k) (zout t k) (label t k)) + (fun t=>g t (φ k) (zout t k) (label t k)) + (fun t=>x t (φ k) (zout t k) (label t k))) + (fun k=>R (φ k)/(M (φ k):ℝ)) + := by + classical + obtain ⟨φ,hφ,z,hz,f,huniform,herror,hgood⟩:=source_global_compact_haar G n q c hsk A w hA hw Γ hΓ + a s m h perm w0 M Xp X R Q L hw0 hX hXp hXt hXpt hR hRX hZ hQ0 hSize hWM hM hMs + hL hsm hWL hML hLexact hXL g x slot qval hQ Yobs Obs Kobs Bobs hLip hBound E ε hε hE + refine ⟨φ,hφ,z,hz,f,huniform,herror,?_⟩ + intro pstar hpstar hpclose + let zout := fun t k (l : Fin (h t))=>(z k).1 (perm t (l.natAdd (m t))) + let zin := fun t k=>((fun l : Fin (m t)=>(z k).1 (perm t (l.castAdd (h t)))),(z k).2) + let label := fun t k=>expose (L (φ k)) (M (φ k):ℤ) (R (φ k)) (zin t k) + let Z := fun k=>R (φ k)/(M (φ k):ℝ) + have hZp (k : ℕ) : 0rawJoint G n q m c hsk A w hA hw (M (φ k)) (L (φ k)) + (fun t=>label t k) (fun t l=>((zin t k).1 l:ℤ)) (fun t=>pstar t k) + (fun t=>slot t (φ k) (zout t k) (label t k)) + (fun t=>qval t (φ k) (zout t k) (label t k)) + (fun t=>g t (φ k) (zout t k) (label t k)) + (fun t=>x t (φ k) (zout t k) (label t k)) + change FactorizedAllHaar G n q c hsk A w hA Γ s P Z + obtain ⟨d,B,hskd,hf,hr,⟨F⟩⟩:=literal_joint_factorization + (FlatG G) (FlatN n) (FlatQ q) (FlatM m) (FlatC c) (FlatSk hsk) (FlatA A) (FlatW w) (FlatHA hA) (FlatHw hw) + (fun a=>hmono a.1 a.2) (FlatΓ Γ) (fun a=>hΓ a.1 a.2) s + (fun a=>h0 a.1 a.2) (fun a=>h1 a.1 a.2) (fun a=>hs a.1 a.2) + (fun k=>M (φ k)) (fun k=>hM (φ k)) (fun k=>L (φ k)) + (fun k b=>label b.1 k) (fun k b l=>((zin b.1 k).1 l:ℤ)) + (fun k b=>pstar b.1 k) (fun k b=>slot b.1 (φ k) (zout b.1 k) (label b.1 k) b.2) + (fun k b=>qval b.1 (φ k) (zout b.1 k) (label b.1 k)) + (fun k b=>g b.1 (φ k) (zout b.1 k) (label b.1 k) b.2) + (fun k b=>x b.1 (φ k) (zout b.1 k) (label b.1 k) b.2) Z hZp + refine ⟨d,B,hskd,hf,?_,F,?_⟩ + · intro f hf t i u + exact hr f hf ⟨t,i⟩ u + · let : SecondCountableTopology (Full G n q c hsk A w hA):=coordinates_secondCountable d + let : CompactSpace ((Full G n q c hsk A w hA)⧸B.small):=AbelianMalcevTorus.quotient_compact d B.small B.integer + let : MeasurableSpace ((Full G n q c hsk A w hA)⧸B.small):=borel _ + let : BorelSpace ((Full G n q c hsk A w hA)⧸B.small):=⟨rfl⟩ + intro t r C ν + let : MeasurableSpace (C.CubeSpace (ι:=Fin (ν.val+1))):=borel _ + let : BorelSpace (C.CubeSpace (ι:=Fin (ν.val+1))):=⟨rfl⟩ + let Y := (Carrier (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t))⧸ + lattice (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (Γ t) + let : MeasurableSpace (Finset (Fin (ν.val+1))→Y):=borel _ + let : BorelSpace (Finset (Fin (ν.val+1))→Y):=⟨rfl⟩ + dsimp only + intro e j β + have hh:=hgood t ν e j (pstar t) (hpstar t) (hpclose t) + exact hh (Full G n q c hsk A w hA) (FullDim n q w) s d B.small + (FullFiltration G n q c hsk A w hA) P F + (targetCoset G n q c hsk A w hA Γ B.small B.le t) (fun _ _=>rfl) r C β + +end SourceIntegerArrays +end + +section + + + + +noncomputable section +namespace RationalLattice +open MalcevCharacters RationalLevelFlow +variable {G H : Type*} [Group G] [Group H] +variable [TopologicalSpace G] [TopologicalSpace H] +variable [IsTopologicalGroup G] [IsTopologicalGroup H] +variable {m n : ℕ} (c : RealCoordinates G m) (d : RealCoordinates H n) + +omit [IsTopologicalGroup H] in +lemma rationalHom_of_basis (hsk : SecondKind d) (F : H →* G) + (hF : Continuous F) (hb : ∀ i,IsRational c (F (axis d i 1))) + (g : H) (hg : IsRational d g) : IsRational c (F g) := by + let A (i : Fin n) : Multiplicative ℝ →* H := + { toFun := fun t=>axis d i t.toAdd + map_one' := axis_zero d i + map_mul' := fun t u=>hsk.axis_add i t.toAdd u.toAdd } + have he (i : Fin n) (t : ℝ) : F (axis d i t)=realPower c (F (axis d i 1)) t := + continuous_flow_eq_realPower c (F.comp (A i)) + (hF.comp ((axis_continuous d i).comp continuous_toAdd)) t + have hp (i : Fin n) : F (axis d i (d.coord g i))∈rationalSubgroup c := by + obtain ⟨q,hq⟩:=hg i + rw [he,←hq] + exact realPower_rational c (hb i) q + have hprod : (List.ofFn (fun i : Fin n=>F (axis d i (d.coord g i)))).prod∈rationalSubgroup c := by + apply Subgroup.list_prod_mem + intro x hx + obtain ⟨i,rfl⟩:=List.mem_ofFn.mp hx + exact hp i + change F g∈rationalSubgroup c + have hmap : F g=(List.ofFn (fun i : Fin n=>F (axis d i (d.coord g i)))).prod := by + conv_lhs => rw [hsk.ordered g] + rw [map_list_prod,List.map_ofFn] + rfl + rw [hmap] + exact hprod + +omit [IsTopologicalGroup H] in +lemma rationalHom_of_lattice (hsk : SecondKind d) (F : H →* G) + (hF : Continuous F) (Δ : Subgroup H) + (hΔ : ∀ g,g∈Δ ↔ ∀ i,∃ z : ℤ,d.coord g i=z) + (himage : ∀ g∈Δ,IsRational c (F g)) : + ∀ g,IsRational d g → IsRational c (F g) := + rationalHom_of_basis c d hsk F hF + (fun i=>himage _ (axis_one_mem d Δ hΔ i)) + +end RationalLattice +end + +end + +noncomputable section +namespace RationalLattice +open MalcevCharacters RationalLevelFlow +variable {H : Type} [Group H] [TopologicalSpace H] [IsTopologicalGroup H] +variable {k : ℕ} (d : RealCoordinates H k) +omit [IsTopologicalGroup H] in +lemma rational_of_pos_pow (g : H) (n : ℕ) (hn : 0C.mem_rational c Γ (p g) (himage g hg)) +end RationalLattice +end +noncomputable section +namespace SourceIntegerArrays.GlobalJoint +open RationalLattice MalcevCharacters RoughArrayFace RoughArrayCoordinates SourceResidueAlignment +open ProductExposureLabels AllLevelFactorization AllLevelFactorization.Factorization +open PhysicalCubeMaps CubeLocalHaar MeasureTheory +open scoped Topology BigOperators +attribute [local instance] Classical.propDecidable +variable {τ : Type} [Fintype τ] {ι : τ→Type} [∀ t,Fintype (ι t)] +variable (G : ∀ t,ι t→Type) [∀ t i,Group (G t i)] +variable [∀ t i,TopologicalSpace (G t i)] [∀ t i,IsTopologicalGroup (G t i)] +variable (n : ∀ t,ι t→ℕ) (q m : τ→ℕ) (c : ∀ t i,RealCoordinates (G t i) (n t i)) +variable (hsk : ∀ t i,SecondKind (c t i)) (A : ∀ t i,CubeFaces.Filtration (G t i)) +variable (w : ∀ t i,Fin (n t i)→ℕ) +variable (hA : ∀ t i k (g : G t i),g∈(A t i).level k ↔ ∀ j,w t i jq t) (w t)))), + ∃ _ : ∀ t,CoveredLattice (dc t) (lattice (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (Γ t)), + (∀ t,SecondKind (dc t)) ∧ + ∀ t f,IsRational d f → IsRational (dc t) (targetHom G n q c hsk A w hA t f) + := by + classical + have hc (t : τ):=JointArrays.covered_geometry (G t) (n t) (fun _=>q t) (c t) (hsk t) + (A t) (w t) (hA t) (hw t) (hmono t) (Γ t) (hΓ t) + choose dc hdc hC ha hr using hc + let C t:=Classical.choice (hC t) + refine ⟨dc,C,hdc,?_⟩ + intro t + exact RationalLattice.rationalHom_covered d (dc t) _ (C t) hd B.small B.integer + (targetHom G n q c hsk A w hA t) (targetHom_continuous G n q c hsk A w hA t) + (fun g hg=>targetHom_lattice G n q c hsk A w hA Γ t g (B.le hg)) + +end SourceIntegerArrays.GlobalJoint + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice24.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice24.lean new file mode 100644 index 0000000000000000000000000000000000000000..7257a281078ad9801f0564ebb8d633aaf36e044b --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice24.lean @@ -0,0 +1,287 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.WeightedLinear01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +noncomputable section +open MeasureTheory Filter Topology Set TopologicalSpace +end + +end + +section + + +noncomputable section +open MeasureTheory Filter Topology Set MvPolynomial +namespace WeightedBoxes +open PolynomialShearPoint FilteredShears.PolynomialShears +variable {σ : Type*} [Fintype σ] + +def boxLaw (w : σ → ℕ) (E : ℝ) : ProbabilityMeasure (σ → ℝ) := + ⟨normalizedRestriction volume (weightedBox w (max E 1)),by + constructor + rw [normalizedRestriction,Measure.smul_apply,Measure.restrict_apply_univ,smul_eq_mul] + exact ENNReal.inv_mul_cancel ((ENNReal.toReal_pos_iff.mp (rect_volume_pos _ (fun i=> + pow_pos (lt_of_lt_of_le zero_lt_one (le_max_right _ _)) _))).1.ne') (rect_finite _)⟩ + +lemma boxLaw_eq {w : σ → ℕ} {E : ℝ} (hE : 1≤E) : + (boxLaw w E : Measure (σ → ℝ))=normalizedRestriction volume (weightedBox w E) := by + exact congrArg (fun t=>normalizedRestriction volume (weightedBox w t)) (max_eq_left hE) + +omit [Fintype σ] in +lemma pointMap_continuous (A : MvPolynomial σ ℝ →ₐ[ℝ] MvPolynomial σ ℝ) : + Continuous (pointMap A) := by + apply continuous_pi + intro i + exact (A (X i)).continuous_eval + + + +theorem boxLaw_shear_invariance (w : σ → ℕ) (hw : ∀ i,0A.val (X i)-X i + have hp (i : σ) : StrictDegree w (w i) (p i) := A.property i + obtain ⟨ε,hε,hb⟩:=weightedBoxLaw_invariance w hw p hp + refine ⟨fun E=>ε (max E 1),hε.comp (tendsto_atTop_mono (fun E=>le_max_left E 1) tendsto_id),?_⟩ + intro E B hB + have he : pointMap A.val.toAlgHom=(fun x i=>x i+eval x (p i)) := by + funext x i + simp [pointMap,p] + change |((normalizedRestriction volume (weightedBox w (max E 1))).map + (pointMap A.val.toAlgHom)).real B-(normalizedRestriction volume + (weightedBox w (max E 1))).real B|≤_ + rw [he] + exact hb _ B hB + +end WeightedBoxes +end + +end + +section + + +noncomputable section +open MeasureTheory Filter Topology Set TopologicalSpace +namespace RationalLattice +open MalcevCharacters WeightedBoxes PolynomialShearPoint FilteredShears.PolynomialShears +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (H : CubeFaces.Filtration G) (w : Fin n → ℕ) (hw : ∀ i,0QuotientGroup.mk (canonicalExp c x), + continuous_quot_mk.comp (canonicalExp_continuous c)⟩ + +def weightedCoverLaw (E : ℝ) : ProbabilityMeasure (G⧸Γ) := + (boxLaw w E).map (expQuotient c Γ) + +include hsk hw hH in + + +lemma weightedCover_translation_invariance [PseudoMetrizableSpace (G⧸Γ)] + [SeparableSpace (G⧸Γ)] (a : G) : + ∃ ε : ℝ → ℝ,Tendsto ε atTop (𝓝 0) ∧ + ∀ E A,MeasurableSet A → + |((weightedCoverLaw c w Γ E).map (a • ·) : Measure (G⧸Γ)).real A- + (weightedCoverLaw c w Γ E : Measure (G⧸Γ)).real A|≤ε E := by + let : PseudoMetricSpace (G⧸Γ):=pseudoMetrizableSpacePseudoMetric (G⧸Γ) + let D (x : Fin n → ℝ):=canonicalLog c (a*canonicalExp c x)-x + obtain ⟨A,hA,_⟩:=exists_shear w hw D (fun i=> + log_left_displacement_weighted c hsk H w hH hw a i) + obtain ⟨ε,hε,hεb⟩:=boxLaw_shear_invariance w hw A + refine ⟨ε,hε,?_⟩ + intro E B hB + apply AsymptoticProbability.pushed_event_bound (boxLaw w E) (expQuotient c Γ) + (expQuotient c Γ).continuous.measurable (pointMap A.val.toAlgHom) + (pointMap_continuous A.val.toAlgHom).measurable (a • ·) (measurable_const_smul a) + _ (hεb E) B hB + intro x + rw [hA] + have he : x+D x=canonicalLog c (a*canonicalExp c x) := by dsimp [D]; abel + rw [he] + change (QuotientGroup.mk (canonicalExp c (canonicalLog c (a*canonicalExp c x))) : G⧸Γ)= + a • QuotientGroup.mk (canonicalExp c x) + rw [canonicalExp_log] + rfl + +include hsk hw hH in + + +theorem weightedCover_weak_haar + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (μ : ProbabilityMeasure (G⧸Γ)) + [SMulInvariantMeasure G (G⧸Γ) (μ:Measure (G⧸Γ))] : + Tendsto (weightedCoverLaw c w Γ) atTop (𝓝 μ) := by + let : T2Space G:=c.coord.symm.t2Space + let : SecondCountableTopology G:=c.coord.secondCountableTopology + let : DiscreteTopology Γ:=integerCoordinates_discrete c Γ hΓ + let : IsClosed (Γ:Set G):=Subgroup.isClosed_of_discreteTopology + obtain ⟨K,hK,hrep⟩:=compact_reps_of_integerCoordinates c Γ hΓ + let : CompactSpace (G⧸Γ):=(show CompactGroupProducts.HasCompactReps ⊤ Γ from + ⟨K,hK,Set.subset_univ _,fun g _=>hrep g⟩).quotient_compactSpace + let : MetricSpace (G⧸Γ):=metrizableSpaceMetric (G⧸Γ) + apply AsymptoticProbability.weak_haar_of_unique (G:=G) (weightedCoverLaw c w Γ) μ + · intro ν hν + let :=hν + obtain ⟨hair,hhair,hunique⟩:=existsUnique_coordinateHaar c Γ hΓ + exact (hunique ν hν).trans (hunique μ inferInstance).symm + · intro a + obtain ⟨ε,hε,hb⟩:=weightedCover_translation_invariance c hsk H w hw hH Γ a + exact ⟨ε,hε,Eventually.of_forall hb⟩ + +end RationalLattice +end + +end + +section + + +noncomputable section +open MeasureTheory Filter Topology Set TopologicalSpace +namespace AsymptoticProbability +lemma map_event_bound {Y X : Type*} [MeasurableSpace Y] [MeasurableSpace X] + (μ ν : ProbabilityMeasure Y) (q : Y → X) (hq : Measurable q) {ε : ℝ} + (h : ∀ B,MeasurableSet B → |(μ:Measure Y).real B-(ν:Measure Y).real B|≤ε) : + ∀ A,MeasurableSet A → + |(μ.map q : Measure X).real A- + (ν.map q : Measure X).real A|≤ε := by + intro A hA + change |(Measure.map q (μ:Measure Y)).real A-(Measure.map q (ν:Measure Y)).real A|≤ε + rw [map_measureReal_apply hq hA,map_measureReal_apply hq hA] + exact h _ (hA.preimage hq) +end AsymptoticProbability + +namespace RationalLattice +open MalcevCharacters WeightedBoxes PolynomialShearPoint FilteredShears.PolynomialShears +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (H : CubeFaces.Filtration G) (w : Fin n → ℕ) (hw : ∀ i,0AsymptoticProbability.map_event_bound _ _ _ + (expQuotient c Γ).continuous.measurable (hb E)⟩ + +include hsk hw hH in + + +theorem weightedShear_weak_haar + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (μ : ProbabilityMeasure (G⧸Γ)) + [SMulInvariantMeasure G (G⧸Γ) (μ:Measure (G⧸Γ))] + (A : shears (R:=ℝ) w) : + Tendsto (weightedShearLaw c w Γ A) atTop (𝓝 μ) := by + let : T2Space G:=c.coord.symm.t2Space + let : SecondCountableTopology G:=c.coord.secondCountableTopology + let : DiscreteTopology Γ:=integerCoordinates_discrete c Γ hΓ + let : IsClosed (Γ:Set G):=Subgroup.isClosed_of_discreteTopology + obtain ⟨K,hK,hrep⟩:=compact_reps_of_integerCoordinates c Γ hΓ + let : CompactSpace (G⧸Γ):=(show CompactGroupProducts.HasCompactReps ⊤ Γ from + ⟨K,hK,Set.subset_univ _,fun g _=>hrep g⟩).quotient_compactSpace + let : MetricSpace (G⧸Γ):=metrizableSpaceMetric (G⧸Γ) + obtain ⟨ε,hε,hb⟩:=weightedShearLaw_event_bound c w hw Γ A + apply AsymptoticProbability.same_weak_limit (weightedCoverLaw c w Γ) + (weightedShearLaw c w Γ A) hε _ (weightedCover_weak_haar c hsk H w hw hH Γ hΓ μ) + exact Eventually.of_forall (fun E B hB=>by rw [abs_sub_comm]; exact hb E B hB) + +include hsk hw hH in + + +theorem weightedShear_pointImage_limit {X : Type*} [TopologicalSpace X] + [MeasurableSpace X] [BorelSpace X] + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (μ : ProbabilityMeasure (G⧸Γ)) + [SMulInvariantMeasure G (G⧸Γ) (μ:Measure (G⧸Γ))] + (A : shears (R:=ℝ) w) (q : C(G⧸Γ,X)) : + Tendsto (fun E=>(weightedShearLaw c w Γ A E).map q) + atTop (𝓝 (μ.map q)) := + ProbabilityMeasure.tendsto_map_of_tendsto_of_continuous _ _ + (weightedShear_weak_haar c hsk H w hw hH Γ hΓ μ A) q.continuous + +end RationalLattice +end + +end + +section + + +noncomputable section +namespace PolynomialShearPoint +open FilteredShears.PolynomialShears +variable {σ J : Type*} (w : σ → ℕ) + + + +instance shearPointAction : MulAction (shears (R:=ℝ) w) (σ → ℝ) where + smul A x := pointMap A.val.symm.toAlgHom x + one_smul x := pointMap_id x + mul_smul A B x := by + change pointMap (A*B).val.symm.toAlgHom x = + pointMap A.val.symm.toAlgHom (pointMap B.val.symm.toAlgHom x) + rw [pointMap_comp] + rfl + +@[simp] lemma shear_smul (A : shears (R:=ℝ) w) (x : σ → ℝ) : + A • x = pointMap A.val.symm.toAlgHom x := rfl + +abbrev CoverGroup (J : Type*) := shears (R:=ℝ) w × Multiplicative (J → ℤ) +abbrev CoverState (J : Type*) := (σ → ℝ) × (J → ℤ) + +instance coverAction : MulAction (CoverGroup w J) (CoverState (σ:=σ) J) where + smul A x := (A.1 • x.1, A.2.toAdd + x.2) + one_smul x := by + change ((1 : shears (R:=ℝ) w) • x.1, (0 : J → ℤ)+x.2)=x + simp + mul_smul A B x := by + change ((A.1*B.1) • x.1, (A.2.toAdd+B.2.toAdd)+x.2)= + (A.1 • (B.1 • x.1), A.2.toAdd+(B.2.toAdd+x.2)) + rw [mul_smul,add_assoc] + +@[simp] lemma cover_smul_fst (A : CoverGroup w J) (x : CoverState (σ:=σ) J) : + (A • x).1 = A.1 • x.1 := rfl +@[simp] lemma cover_smul_snd (A : CoverGroup w J) (x : CoverState (σ:=σ) J) : + (A • x).2 = A.2.toAdd + x.2 := rfl + +lemma cover_lowerCentralSeries {s : ℕ} (hs : 1 ≤ s) (hw : ∀ i, w i ≤ s) : + (⊤ : Subgroup (CoverGroup w J)).lowerCentralSeries s = ⊥ := by + rw [Subgroup.top_lowerCentralSeries_prod,shear_lowerCentralSeries_eq_bot w hw] + have ha : (⊤ : Subgroup (Multiplicative (J → ℤ))).lowerCentralSeries s = ⊥ := by + apply le_antisymm _ bot_le + calc + _ ≤ (⊤ : Subgroup (Multiplicative (J → ℤ))).lowerCentralSeries 1 := + Subgroup.lowerCentralSeries_antitone _ hs + _ = ⊥ := by simp [Subgroup.lowerCentralSeries_succ,CommGroup.center_eq_top] + rw [ha,Subgroup.bot_prod_bot] + +end PolynomialShearPoint + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice25.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice25.lean new file mode 100644 index 0000000000000000000000000000000000000000..3f639cbe000c4cb704032d49f6a7f457f37c9713 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice25.lean @@ -0,0 +1,313 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CoveringSubspace01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +noncomputable section +open Topology +open scoped unitInterval +namespace CoveringSubspace +open CompactGroupProducts +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] [T2Space G] + + + +theorem subgroup_orbit_covering (H Γ : Subgroup G) (hΓ : IsDiscrete (Γ : Set G)) + (hrep : HasCompactReps H Γ) : + IsCoveringMap (imageRestrict (QuotientGroup.mk (s := Γ)) (H : Set G)) := by + let : DiscreteTopology Γ := isDiscrete_iff_discreteTopology.mp hΓ + have hquot : Topology.IsQuotientMap + (imageRestrict (QuotientGroup.mk (s := Γ)) (H : Set G)) := by + obtain ⟨C, hC, hCH, hr⟩ := hrep + apply isQuotientMap_imageRestrict QuotientGroup.continuous_mk hC hCH + intro g hg + obtain ⟨c, hc, hcΓ⟩ := hr g hg + exact ⟨c, hc, QuotientGroup.eq.mpr hcΓ⟩ + have hdisc : IsDiscrete ((Γ.comap H.subtype : Subgroup H) : Set H) := + hΓ.preimage continuous_subtype_val.continuousOn Subtype.val_injective + apply (hquot.isQuotientCoveringMap_of_subgroupOp (E := H) (Γ.comap H.subtype) hdisc ?_).isCoveringMap + intro x y + constructor + · intro hxy + exact (QuotientGroup.eq (s := Γ) (a := x.val) (b := y.val)).mp + (congrArg Subtype.val hxy) + · intro hxy + exact Subtype.ext ((QuotientGroup.eq (s := Γ) (a := x.val) (b := y.val)).mpr hxy) + + + +theorem subgroup_path_mem (H Γ : Subgroup G) (hΓ : IsDiscrete (Γ : Set G)) + (hrep : HasCompactReps H Γ) (f : C(I, G)) (hstart : f 0 ∈ H) + (himage : ∀ t, (f t : G ⧸ Γ) ∈ QuotientGroup.mk '' (H : Set G)) : + ∀ t, f t ∈ H := + path_mem_subspace (Γ.isQuotientCoveringMap hΓ).isCoveringMap (H : Set G) + (subgroup_orbit_covering H Γ hΓ hrep) f hstart himage + +end CoveringSubspace + +namespace CubeFaces +open CompactGroupProducts +variable {G ι : Type} [Group G] [DecidableEq ι] [Fintype ι] + [TopologicalSpace G] [IsTopologicalGroup G] [T2Space G] + +omit [DecidableEq ι] [IsTopologicalGroup G] [T2Space G] in + +lemma latticeArrays_isDiscrete (Γ : Subgroup G) (hΓ : IsDiscrete (Γ : Set G)) : + IsDiscrete (↑(latticeArrays (ι := ι) Γ) : Set (Finset ι → G)) := by + let : DiscreteTopology Γ := isDiscrete_iff_discreteTopology.mp hΓ + have h : IsDiscrete (Set.range (fun f : Finset ι → Γ => fun v => (f v).val)) := + (Topology.IsInducing.piMap + (fun _ : Finset ι => (Topology.IsInducing.subtypeVal : + Topology.IsInducing (Subtype.val : Γ → G)))).isDiscrete_range + have heq : Set.range (fun f : Finset ι → Γ => fun v => (f v).val) = + (↑(latticeArrays (ι := ι) Γ) : Set (Finset ι → G)) := by + ext f + constructor + · rintro ⟨g, rfl⟩ + exact fun v => (g v).property + · intro hf + exact ⟨fun v => ⟨f v, hf v⟩, rfl⟩ + rwa [heq] at h + + + +theorem quotient_affine_face_displacement + (H : Filtration G) (Γ : Subgroup G) (hΓ : IsDiscrete (Γ : Set G)) + (hrep : ∀ j, HasCompactReps (H.level j) Γ) + (D : Finset ι) (a : ι) (ha : a ∉ D) + [PathConnectedSpace (H.level D.card)] + (c g : G) (φ : G →* G) (hφ : Continuous φ) + (hc : c ∈ H.level 1) (hg : g ∈ H.level D.card) + (hpres : ∀ f ∈ cube H (insert a D) 0, + (affineUpper a c φ f : (Finset ι → G) ⧸ latticeArrays Γ) ∈ + QuotientGroup.mk '' (cube H (insert a D) 0 : Set (Finset ι → G))) : + g⁻¹ * φ g ∈ H.level (D.card + 1) := by + let p : Path (1 : H.level D.card) ⟨g, hg⟩ := PathConnectedSpace.somePath _ _ + let q : C(I, Finset ι → G) := + ⟨fun t => affineUpper a c φ (face D (p t).val), by + apply continuous_pi + intro v + dsimp [affineUpper, face_apply] + by_cases hav : a ∈ v <;> by_cases hDv : D ⊆ v <;> simp only [hav, hDv, ite_true, ite_false] + · exact continuous_const.mul (hφ.comp (continuous_subtype_val.comp p.continuous)) + · exact continuous_const + · exact continuous_subtype_val.comp p.continuous + · exact continuous_const⟩ + have hstart : q 0 ∈ cube H (insert a D) 0 := by + have heq : q 0 = face {a} c := by + funext v + simp [q, affineUpper, p.source, face_apply] + rw [heq] + exact face_mem_cube H (by simp) (by simpa using hc) + have himage : ∀ t, (q t : (Finset ι → G) ⧸ latticeArrays Γ) ∈ + QuotientGroup.mk '' (cube H (insert a D) 0 : Set (Finset ι → G)) := by + intro t + apply hpres + exact face_mem_cube H (Finset.subset_insert _ _) (p t).property + have hmem := CoveringSubspace.subgroup_path_mem (cube H (insert a D) 0) + (latticeArrays Γ) (latticeArrays_isDiscrete Γ hΓ) + (cube_hasCompactReps H Γ hrep (insert a D) 0) q hstart himage 1 + apply affine_face_displacement H D a ha c g φ hc hg + simpa [q, p.target] using hmem + +end CubeFaces + +end + +end + +section + + +noncomputable section +open Topology +namespace RationalLattice +open WeightedLinear MalcevCharacters CompactGroupProducts CubeFaces +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] [T2Space G] +variable {n : ℕ} (c : RealCoordinates G n) +variable (H : Filtration G) (w : Fin n → ℕ) (hmono : Monotone w) + (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + +include hmono hH in +omit [IsTopologicalGroup G] [T2Space G] in +lemma chart_level_pathConnected (k : ℕ) : PathConnectedSpace (H.level k) := by + let e : H.level k ≃ₜ (WeightedLinear.level w k) := + (logHomeomorph c).subtype (fun g=>by + change g∈H.level k ↔ ∀ i,w i < k → logHomeomorph c g i=0 + rw [logHomeomorph_apply] + exact mem_level_iff_log c H w hmono hH k g) + exact e.symm.surjective.pathConnectedSpace e.symm.continuous + + +def PreservesFaces (Γ : Subgroup G) (a : G) (F : G →* G) (s : ℕ) : Prop := + ∀ k ≤ s,∀ f∈cube (ι:=Fin (k+1)) H Finset.univ 0, + (affineUpper (Fin.last k) a F f : (Finset (Fin (k+1)) → G) ⧸ latticeArrays Γ)∈ + QuotientGroup.mk '' (↑(cube (ι:=Fin (k+1)) H Finset.univ 0) : Set (Finset (Fin (k+1)) → G)) + +include hmono hH in + + +theorem face_displacement_all_levels (Γ : Subgroup G) (hΓ : IsDiscrete (Γ : Set G)) + (hrep : ∀ j,HasCompactReps (H.level j) Γ) + (a : G) (ha : a∈H.level 1) (F : G →* G) (hF : Continuous F) + (s : ℕ) (hs : H.level (s+1)=⊥) (hpres : PreservesFaces H Γ a F s) + (k : ℕ) (_hk : 0 < k) (g : G) (hg : g∈H.level k) : + g⁻¹*F g∈H.level (k+1) := by + by_cases hks : k ≤ s + · let D : Finset (Fin (k+1)):=Finset.univ.erase (Fin.last k) + have hD : D.card=k := by simp [D] + have hfull : insert (Fin.last k) D=Finset.univ := by simp [D] + let : PathConnectedSpace (H.level D.card) := chart_level_pathConnected c H w hmono hH _ + have hh:=quotient_affine_face_displacement H Γ hΓ hrep D (Fin.last k) + (by simp [D]) a g F hF ha (by simpa [hD] using hg) (by + rw [hfull] + exact hpres k hks) + simpa [hD] using hh + · have hone : g=1 := by + have hh:=H.antitone (show s+1 ≤ k by omega) hg + simpa [hs] using hh + simp [hone] + +include hmono hH in + + +theorem face_affine_displacement_weighted (hsk : SecondKind c) (hw : ∀ i,0 < w i) + (Γ : Subgroup G) (hΓ : IsDiscrete (Γ : Set G)) + (hrep : ∀ j,HasCompactReps (H.level j) Γ) + (a : G) (ha : a∈H.level 1) (F : G →* G) (hF : Continuous F) + (s : ℕ) (hs : H.level (s+1)=⊥) (hpres : PreservesFaces H Γ a F s) (i : Fin n) : + WeightedPolynomial.IsWeighted w (w i-1) + (fun y=>canonicalLog c (a*F (canonicalExp c y)) i-y i) := + affine_log_displacement_weighted c hsk H w hw hmono hH F hF + (fun k hk g hg=>face_displacement_all_levels c H w hmono hH Γ hΓ hrep + a ha F hF s hs hpres k hk g hg) a i + +end RationalLattice +end + +end + +section + + +noncomputable section +namespace RationalLattice +open MalcevCharacters WeightedLinear +variable {G J : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + [Group J] [TopologicalSpace J] [IsTopologicalGroup J] +variable {n m : ℕ} (c : RealCoordinates G n) (d : RealCoordinates J m) + (hsk : SecondKind c) +variable (H : CubeFaces.Filtration G) (K : CubeFaces.Filtration J) + (w : Fin n → ℕ) (v : Fin m → ℕ) (hmono : Monotone w) (hvmono : Monotone v) + (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + (hK : ∀ k (g : J),g∈K.level k ↔ ∀ i : Fin m,v i < k → d.coord g i=0) + (p : G →* J) (hp : Continuous p) + (honto : ∀ k,(H.level k).map p=K.level k) + +include hsk hmono hvmono hH hK hp honto in + + +theorem logHomLinear_level_map (k : ℕ) : + Submodule.map (logHomLinear d c p).toLinearMap (level w k)=level v k := by + ext y + constructor + · rintro ⟨x,hx,rfl⟩ + have hg : canonicalExp c x∈H.level k := + (canonicalExp_mem_level_iff c H w hmono hH _ _).mpr hx + have hpg : p (canonicalExp c x)∈K.level k := by + rw [← honto] + exact Subgroup.mem_map.mpr ⟨_,hg,rfl⟩ + have hlog := (mem_level_iff_log d K v hvmono hK _ _).mp hpg + change ∀ i,v i < k → logHomLinear d c p x i=0 + rw [logHomLinear_apply d c hsk p hp] + exact hlog + · intro hy + have hgy : canonicalExp d y∈K.level k := + (canonicalExp_mem_level_iff d K v hvmono hK _ _).mpr hy + rw [← honto] at hgy + obtain ⟨g,hg,he⟩:=Subgroup.mem_map.mp hgy + refine Submodule.mem_map.mpr ⟨canonicalLog c g, + (mem_level_iff_log c H w hmono hH _ _).mp hg,?_⟩ + rw [ContinuousLinearMap.coe_coe,logHomLinear_apply d c hsk p hp] + change canonicalLog d (p (canonicalExp c (canonicalLog c g)))=y + rw [canonicalExp_log,he,canonicalLog_exp] + +include hsk hmono hvmono hH hK hp honto in +theorem logHomLinear_preserves : Preserves w v (logHomLinear d c p).toLinearMap := by + intro k x hx + rw [← logHomLinear_level_map c d hsk H K w v hmono hvmono hH hK p hp honto k] + exact Submodule.mem_map.mpr ⟨x,hx,rfl⟩ + +end RationalLattice +end + +end + +section + + +noncomputable section +namespace RationalLattice +open MalcevCharacters WeightedLinear CompactGroupProducts CubeFaces +open FilteredShears.PolynomialShears PolynomialShearPoint +variable {G J : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + [Group J] [TopologicalSpace J] [IsTopologicalGroup J] [T2Space J] +variable {n m : ℕ} (c : RealCoordinates G n) (d : RealCoordinates J m) + (hsk : SecondKind c) (hdsk : SecondKind d) +variable (H : Filtration G) (K : Filtration J) + (w : Fin n → ℕ) (v : Fin m → ℕ) (hw : ∀ i,0 < w i) (hv : ∀ j,0 < v j) + (hmono : Monotone w) (hvmono : Monotone v) + (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + (hK : ∀ k (g : J),g∈K.level k ↔ ∀ i : Fin m,v i < k → d.coord g i=0) + (p : G →* J) (hp : Continuous p) + (honto : ∀ k,(H.level k).map p=K.level k) + +include hsk hdsk hw hv hmono hvmono hH hK hp honto in + + +theorem exists_face_lift (Γ : Subgroup J) (hΓ : IsDiscrete (Γ : Set J)) + (hrep : ∀ j,HasCompactReps (K.level j) Γ) + (a : J) (ha : a∈K.level 1) (F : J →* J) (hF : Continuous F) + (s : ℕ) (hs : K.level (s+1)=⊥) (hpres : PreservesFaces K Γ a F s) : + ∃ A : shears (R:=ℝ) w, + (∀ x,p (canonicalExp c (pointMap A.val.toAlgHom x))= + a*F (p (canonicalExp c x))) ∧ + Function.Bijective (pointMap A.val.toAlgHom) := by + let P:=(logHomLinear d c p).toLinearMap + have hon : ∀ k,Submodule.map P (level w k)=level v k := + logHomLinear_level_map c d hsk H K w v hmono hvmono hH hK p hp honto + have hP : Preserves w v P := + logHomLinear_preserves c d hsk H K w v hmono hvmono hH hK p hp honto + obtain ⟨R,hPR,hR⟩:=exists_rightInverse w v P hon + let D (y : Fin m → ℝ):=canonicalLog d (a*F (canonicalExp d y))-y + have hD (j : Fin m) : WeightedPolynomial.IsWeighted v (v j-1) (fun y=>D y j) := + face_affine_displacement_weighted d K v hvmono hK hdsk hv Γ hΓ hrep + a ha F hF s hs hpres j + have hDR (i : Fin n) : WeightedPolynomial.IsWeighted w (w i-1) + (fun x=>R (D (P x)) i) := lifted_displacement_weighted hP hR D hD i + obtain ⟨A,hA,hbij⟩:=exists_shear w hw (fun x=>R (D (P x))) hDR + refine ⟨A,?_,?_⟩ + · intro x + rw [hA,map_canonicalExp d c hsk p hp] + change canonicalExp d (P (x+R (D (P x))))=_ + rw [map_add,hPR] + have he : P x+D (P x)=canonicalLog d (a*F (canonicalExp d (P x))) := by + dsimp [D] + abel + rw [he,canonicalExp_log] + change a*F (canonicalExp d (logHomLinear d c p x))=_ + rw [← map_canonicalExp d c hsk p hp] + · have he : pointMap A.val.toAlgHom=(fun x=>x+R (D (P x))) := funext hA + rwa [he] + +end RationalLattice + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice26.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice26.lean new file mode 100644 index 0000000000000000000000000000000000000000..31e3d43bd934389f783443b95423e3d644264224 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice26.lean @@ -0,0 +1,284 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalEchelon02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + +noncomputable section +open scoped BigOperators +namespace RationalMatrix +lemma real_polynomial {n m : ℕ} (p : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) (j : Fin m) : + RationalPolynomialMap.IsPolynomial (fun x=>real p x j) := by + refine ⟨∑ i : Fin n,MvPolynomial.X i*MvPolynomial.C (p (Pi.single i 1) j),?_⟩ + intro x + simp [real_apply] + +lemma exists_matrix {n m : ℕ} (L : (Fin n → ℝ) →ₗ[ℝ] (Fin m → ℝ)) + (hL : ∀ j,RationalPolynomialMap.IsPolynomial (fun x=>L x j)) : + ∃ p : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ),real p=L := by + have hc (i : Fin n) (j : Fin m) : ∃ q : ℚ,(q:ℝ)=L (Pi.single i 1) j := by + obtain ⟨P,hP⟩:=hL j + dsimp only at hP + rw [hP] + apply RationalLattice.eval_rational + intro a + by_cases ha : a=i + · subst a; exact ⟨1,by simp⟩ + · exact ⟨0,by simp [ha]⟩ + choose a ha using hc + let p : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ):= + ∑ i : Fin n,(LinearMap.proj i).smulRight (a i) + refine ⟨p,?_⟩ + apply (Pi.basisFun ℝ (Fin n)).ext + intro i + ext j + simp only [Pi.basisFun_apply,real_single] + have he : p (Pi.single i 1)=a i := by simp [p,LinearMap.sum_apply,Pi.single_apply] + rw [he,ha] +end RationalMatrix + +namespace RationalLattice +open MalcevCharacters +variable {G H : Type*} [Group G] [Group H] +variable [TopologicalSpace G] [TopologicalSpace H] +variable [IsTopologicalGroup G] [IsTopologicalGroup H] +variable {n m : ℕ} (c : RealCoordinates G n) (d : RealCoordinates H m) +variable (hsk : SecondKind c) (F : G →* H) (hF : Continuous F) +variable (hrat : ∀ x,IsRational c x → IsRational d (F x)) +include hsk hF hrat in +lemma logHom_rational_polynomial (i : Fin m) : + RationalPolynomialMap.IsPolynomial (fun x=>logHom d c F x i) := by + have hh (j : Fin m) : RationalPolynomialMap.IsPolynomial + (fun x=>d.coord (F (canonicalExp c x)) j) := by + simpa only [Homeomorph.symm_apply_apply] using + RationalPolynomialMap.comp (rationalHom_polynomial d c hsk F hF hrat j) + (canonicalExp_polynomial c) + simpa only [logHom,Homeomorph.symm_apply_apply] using + RationalPolynomialMap.comp (canonicalLog_polynomial d i) hh + +include hsk hF hrat in + + +theorem exists_log_matrix : + ∃ p : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ), + RationalMatrix.real p=(logHomLinear d c F).toLinearMap := by + apply RationalMatrix.exists_matrix + intro i + simpa only [ContinuousLinearMap.coe_coe,logHomLinear_apply d c hsk F hF] using + logHom_rational_polynomial c d hsk F hF hrat i + +end RationalLattice +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +open Topology +namespace RationalLattice.QuotientLogImage +open MalcevCharacters +variable {G H : Type*} [Group G] [Group H] +variable [TopologicalSpace G] [TopologicalSpace H] +variable [IsTopologicalGroup G] [IsTopologicalGroup H] +variable {n m : ℕ} (c : RealCoordinates G n) (d : RealCoordinates H m) +variable (hsk : SecondKind c) (F : G →* H) (hF : Continuous F) +variable (p : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) +variable (hp : RationalMatrix.real p=(logHomLinear d c F).toLinearMap) +variable (E : RationalEchelon.Chart (LinearMap.ker p)) + +def parametrization (x : Fin E.freeSet.card → ℝ) : F.range := + ⟨F (canonicalExp c (RationalMatrix.real E.sectionMap x)),⟨_,rfl⟩⟩ + +include hsk hF hp in +lemma parametrization_exp (x : Fin E.freeSet.card → ℝ) : + (parametrization c F p E x:H)= + canonicalExp d (RationalMatrix.real (p.comp E.sectionMap) x) := by + change F (canonicalExp c (RationalMatrix.real E.sectionMap x))=_ + rw [map_canonicalExp d c hsk F hF,RationalMatrix.real_comp,hp] + rfl + +include hsk hF hp in +lemma parametrization_quotient (g : G) : + parametrization c F p E (RationalMatrix.real E.quotientMap (canonicalLog c g))=F.rangeRestrict g := by + apply Subtype.ext + rw [parametrization_exp c d hsk F hF p hp E,RationalMatrix.real_comp] + change canonicalExp d (RationalMatrix.real p (RationalMatrix.real E.sectionMap + (RationalMatrix.real E.quotientMap (canonicalLog c g))))=F g + rw [E.real_map_section_quotient p rfl,hp] + change canonicalExp d (logHomLinear d c F (canonicalLog c g))=F g + rw [logHomLinear_log d c hsk F hF,canonicalExp_log] + +include hsk hF hp in +lemma parametrization_embedding : IsEmbedding (parametrization c F p E) := by + have hi:=RationalMatrix.real_injective_of_injective _ (E.section_map_injective p rfl) + have he:=LinearMap.isClosedEmbedding_of_injective (LinearMap.ker_eq_bot.mpr hi) + have hcomp : IsEmbedding (fun x=>(parametrization c F p E x:H)) := by + have hh:=(logHomeomorph d).symm.isEmbedding.comp he.isEmbedding + change IsEmbedding (fun x=>canonicalExp d (RationalMatrix.real (p.comp E.sectionMap) x)) at hh + simpa only [← parametrization_exp c d hsk F hF p hp E] using hh + exact { toIsInducing:=IsInducing.subtypeVal.of_comp_iff.mp hcomp.toIsInducing + injective:=fun x y hx=>hcomp.injective (congrArg Subtype.val hx) } + +include hsk hF hp in +lemma parametrization_surjective : Function.Surjective (parametrization c F p E) := by + intro y + obtain ⟨g,hg⟩:=y.property + refine ⟨RationalMatrix.real E.quotientMap (canonicalLog c g),?_⟩ + rw [parametrization_quotient c d hsk F hF p hp E] + exact Subtype.ext hg + + + +def coordinates : F.range ≃ₜ (Fin E.freeSet.card → ℝ) := + ((parametrization_embedding c d hsk F hF p hp E).toHomeomorphOfSurjective + (parametrization_surjective c d hsk F hF p hp E)).symm + +lemma coordinates_symm (x : Fin E.freeSet.card → ℝ) : + (coordinates c d hsk F hF p hp E).symm x=parametrization c F p E x := rfl + +lemma coordinates_map (g : G) : + coordinates c d hsk F hF p hp E (F.rangeRestrict g)= + RationalMatrix.real E.quotientMap (canonicalLog c g) := by + rw [← parametrization_quotient c d hsk F hF p hp E] + exact (coordinates c d hsk F hF p hp E).apply_symm_apply _ + +lemma coordinates_one : coordinates c d hsk F hF p hp E 1=0 := by + have hh:=coordinates_map c d hsk F hF p hp E 1 + simpa only [map_one,canonicalLog_one,map_zero] using hh + +include hsk hF hp E in + +theorem image_isClosed : IsClosed (F.range : Set H) := by + have hi:=RationalMatrix.real_injective_of_injective _ (E.section_map_injective p rfl) + have he:=LinearMap.isClosedEmbedding_of_injective (LinearMap.ker_eq_bot.mpr hi) + have hh:=(logHomeomorph d).symm.isClosedEmbedding.comp he + have hr : Set.range (fun x=>(logHomeomorph d).symm (RationalMatrix.real (p.comp E.sectionMap) x))= + (F.range : Set H) := by + ext y + constructor + · rintro ⟨x,rfl⟩ + change canonicalExp d (RationalMatrix.real (p.comp E.sectionMap) x)∈F.range + rw [← parametrization_exp c d hsk F hF p hp E] + exact (parametrization c F p E x).property + · intro hy + obtain ⟨x,hx⟩:=parametrization_surjective c d hsk F hF p hp E ⟨y,hy⟩ + refine ⟨x,?_⟩ + change canonicalExp d (RationalMatrix.real (p.comp E.sectionMap) x)=y + rw [← parametrization_exp c d hsk F hF p hp E] + exact congrArg Subtype.val hx + exact hr ▸ hh.isClosed_range + +include hsk hF in +lemma parametrization_polynomial (hrat : ∀ x,IsRational c x → IsRational d (F x)) : + IsPolynomialMap d (fun x=>(parametrization c F p E x:H)) := by + have hh (j : Fin m) : RationalPolynomialMap.IsPolynomial + (fun x=>d.coord (F (canonicalExp c x)) j) := by + simpa only [Homeomorph.symm_apply_apply] using + RationalPolynomialMap.comp (rationalHom_polynomial d c hsk F hF hrat j) + (canonicalExp_polynomial c) + intro j + exact RationalPolynomialMap.comp (hh j) (RationalMatrix.real_polynomial E.sectionMap) + +end RationalLattice.QuotientLogImage +end + +end + +section + + + + +noncomputable section +namespace RationalLattice.QuotientLaw +open WeightedPolynomial MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) +variable {W : Submodule ℚ (Fin n → ℚ)} (E : RationalEchelon.Chart W) + +def multiply (x : (Fin E.freeSet.card ⊕ Fin E.freeSet.card) → ℝ) : Fin E.freeSet.card → ℝ:= + RationalMatrix.real E.quotientMap (canonicalLog c + (canonicalExp c (RationalMatrix.real E.sectionMap (fun j=>x (Sum.inl j)))* + canonicalExp c (RationalMatrix.real E.sectionMap (fun j=>x (Sum.inr j))))) + +omit [IsTopologicalGroup G] in +lemma multiply_left (y : Fin E.freeSet.card → ℝ) : + multiply c E (Sum.elim (fun _=>0) y)=y := by + change RationalMatrix.real E.quotientMap (canonicalLog c + (canonicalExp c (RationalMatrix.real E.sectionMap 0)*canonicalExp c (RationalMatrix.real E.sectionMap y)))=y + rw [map_zero,canonicalExp_zero,one_mul,canonicalLog_exp,E.real_quotient_section] +omit [IsTopologicalGroup G] in +lemma multiply_right (x : Fin E.freeSet.card → ℝ) : + multiply c E (Sum.elim x (fun _=>0))=x := by + change RationalMatrix.real E.quotientMap (canonicalLog c + (canonicalExp c (RationalMatrix.real E.sectionMap x)*canonicalExp c (RationalMatrix.real E.sectionMap 0)))=x + rw [map_zero,canonicalExp_zero,mul_one,canonicalLog_exp,E.real_quotient_section] + +omit [IsTopologicalGroup G] in +lemma multiply_polynomial (i : Fin E.freeSet.card) : + RationalPolynomialMap.IsPolynomial (fun x=>multiply c E x i) := by + have hl (j : Fin n) := RationalPolynomialMap.comp (RationalMatrix.real_polynomial E.sectionMap j) + (fun k=>RationalPolynomialMap.coordinate (Sum.inl k : Fin E.freeSet.card ⊕ Fin E.freeSet.card)) + have hr (j : Fin n) := RationalPolynomialMap.comp (RationalMatrix.real_polynomial E.sectionMap j) + (fun k=>RationalPolynomialMap.coordinate (Sum.inr k : Fin E.freeSet.card ⊕ Fin E.freeSet.card)) + have hml (j : Fin n):=RationalPolynomialMap.comp (canonicalExp_polynomial c j) hl + have hmr (j : Fin n):=RationalPolynomialMap.comp (canonicalExp_polynomial c j) hr + have hmul:=polynomialMap_mul c hml hmr + have hlog (j : Fin n):=RationalPolynomialMap.comp (canonicalLog_polynomial c j) hmul + have hq:=RationalPolynomialMap.comp (RationalMatrix.real_polynomial E.quotientMap i) hlog + simpa only [multiply,Homeomorph.symm_apply_apply] using hq + +variable (hsk : SecondKind c) (A : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hmono : Monotone w) +variable (hA : ∀ k (g : G),g∈A.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) +include hmono in +lemma quotient_preserves : WeightedLinear.Preserves w (fun i=>w (E.free i)) + (RationalMatrix.real E.quotientMap) := by + intro k x hx + exact E.real_quotient_level w hmono k x hx +lemma section_preserves : WeightedLinear.Preserves (fun i=>w (E.free i)) w + (RationalMatrix.real E.sectionMap) := by + intro k x hx + exact E.real_section_level w k x hx + +include hsk hmono hA in +lemma multiply_weighted (i : Fin E.freeSet.card) : + IsWeighted (Sum.elim (fun i=>w (E.free i)) (fun i=>w (E.free i))) (w (E.free i)) + (fun x=>multiply c E x i) := by + have hs:=section_preserves E w + have hlin (j : Fin n ⊕ Fin n) : + IsWeighted (Sum.elim (fun i=>w (E.free i)) (fun i=>w (E.free i))) (Sum.elim w w j) + (fun x=>Sum.elim + (RationalMatrix.real E.sectionMap (fun i=>x (Sum.inl i))) + (RationalMatrix.real E.sectionMap (fun i=>x (Sum.inr i))) j) := by + cases j with + | inl j => exact (hs.weighted j).comp (fun k=>IsWeighted.coordinate _ (Sum.inl k)) + | inr j => exact (hs.weighted j).comp (fun k=>IsWeighted.coordinate _ (Sum.inr k)) + have hm (j : Fin n):=(log_multiplication_weighted c hsk A w hA j).comp hlin + simp only [Sum.elim_inl,Sum.elim_inr] at hm + exact ((quotient_preserves E w hmono).weighted i).comp hm + +end RationalLattice.QuotientLaw + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice27.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice27.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c098a0f60aa2293cb66eaac3155c9d40357d92a --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalLattice27.lean @@ -0,0 +1,262 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice26 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +noncomputable section +namespace RationalLattice.QuotientLogImage +open MalcevCharacters +variable {G H : Type*} [Group G] [Group H] +variable [TopologicalSpace G] [TopologicalSpace H] +variable [IsTopologicalGroup G] [IsTopologicalGroup H] +variable {n m : ℕ} (c : RealCoordinates G n) (d : RealCoordinates H m) +variable (hsk : SecondKind c) (F : G →* H) (hF : Continuous F) +variable (p : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) +variable (hp : RationalMatrix.real p=(logHomLinear d c F).toLinearMap) +variable (E : RationalEchelon.Chart (LinearMap.ker p)) + +lemma coordinates_mul (g h : F.range) : + coordinates c d hsk F hF p hp E (g*h)= + QuotientLaw.multiply c E (Sum.elim + (coordinates c d hsk F hF p hp E g) (coordinates c d hsk F hF p hp E h)) := by + let e:=coordinates c d hsk F hF p hp E + have hg : g=F.rangeRestrict (canonicalExp c (RationalMatrix.real E.sectionMap (e g))) := + (e.symm_apply_apply g).symm + have hh : h=F.rangeRestrict (canonicalExp c (RationalMatrix.real E.sectionMap (e h))) := + (e.symm_apply_apply h).symm + rw [show g*h=F.rangeRestrict + (canonicalExp c (RationalMatrix.real E.sectionMap (e g))* + canonicalExp c (RationalMatrix.real E.sectionMap (e h))) by rw [map_mul,← hg,← hh]] + rw [coordinates_map] + rfl + +end RationalLattice.QuotientLogImage +end + +end + +section + + + + +noncomputable section +namespace RationalLattice.QuotientLogImage +open MalcevCharacters MalcevWeightedCoordinates +variable {G H : Type*} [Group G] [Group H] +variable [TopologicalSpace G] [TopologicalSpace H] +variable [IsTopologicalGroup G] [IsTopologicalGroup H] +variable {n m : ℕ} (c : RealCoordinates G n) (d : RealCoordinates H m) +variable (hsk : SecondKind c) (F : G →* H) (hF : Continuous F) +variable (p : (Fin n → ℚ) →ₗ[ℚ] (Fin m → ℚ)) +variable (hp : RationalMatrix.real p=(logHomLinear d c F).toLinearMap) +variable (E : RationalEchelon.Chart (LinearMap.ker p)) +variable (A : CubeFaces.Filtration G) (w : Fin n → ℕ) (hw : ∀ i,0 rfl + + + +def imageChart : RealCoordinates F.range E.freeSet.card:= + WeightedLawChart.realCoordinates (coordinates c d hsk F hF p hp E) + (coordinates_one c d hsk F hF p hp E) (fun i=>w (E.free i)) + (fun i=>hw (E.free i)) (hmono.comp E.free.monotone) + (fun i=>by simpa only [law_eq c d hsk F hF p hp E] using QuotientLaw.multiply_polynomial c E i) + (fun i=>by simpa only [law_eq c d hsk F hF p hp E] using + QuotientLaw.multiply_weighted c E hsk A w hmono hA i) + +include hmono hA in +lemma coordinates_adapted (k : ℕ) (g : F.range) : + g∈(A.level k).map F.rangeRestrict ↔ ∀ i,w (E.free i)w (E.free i)) (hmono.comp E.free.monotone) k + have hb : ∀ g : F.range,g∈(A.level k).map F.rangeRestrict ↔ + ∀ i : Fin E.freeSet.card,i.vald.coord + ((imageChart c d hsk F hF p hp E A w hw hmono hA).coord.symm x:H) i) := by + have hh:=RationalPolynomialMap.comp (canonicalExp_polynomial d i) + (RationalMatrix.real_polynomial (p.comp E.sectionMap)) + change RationalPolynomialMap.IsPolynomial (fun x=>d.coord (parametrization c F p E x:H) i) + simpa only [parametrization_exp c d hsk F hF p hp E] using hh + +lemma imageEmbedding_rational (g : F.range) + (hg : IsRational (imageSecondChart c d hsk F hF p hp E A w hw hmono hA) g) : + IsRational d (g:H) := by + have hb:=expProduct_rational (imageChart c d hsk F hF p hp E A w hw hmono hA) hg + change IsRational (imageChart c d hsk F hF p hp E A w hw hmono hA) + (expProduct (imageChart c d hsk F hF p hp E A w hw hmono hA) + (expCoordinates (imageChart c d hsk F hF p hp E A w hw hmono hA) g)) at hb + rw [expProduct_expCoordinates] at hb + intro i + obtain ⟨P,hP⟩:=imageEmbedding_polynomial c d hsk F hF p hp E A w hw hmono hA i + obtain ⟨q,hq⟩:=eval_rational P + ((imageChart c d hsk F hF p hp E A w hw hmono hA).coord g) hb + refine ⟨q,?_⟩ + rw [hq,← hP] + simp only [Homeomorph.symm_apply_apply] + +end RationalLattice.QuotientLogImage +end + +end + +section + + + + +noncomputable section +namespace RationalLattice +open MalcevCharacters MalcevWeightedCoordinates +variable {G K : Type} [Group G] [Group K] +variable [TopologicalSpace G] [TopologicalSpace K] +variable [IsTopologicalGroup G] [IsTopologicalGroup K] +variable {m n : ℕ} (c : RealCoordinates G m) (d : RealCoordinates K n) +variable (hsk : SecondKind d) (F : K →* G) (hF : Continuous F) +variable (hinj : Function.Injective F) +variable (hrat : ∀ x,IsRational d x → IsRational c (F x)) +variable (Γ : Subgroup G) (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + +include hΓ hF hinj in +omit [IsTopologicalGroup K] in +lemma rationalInduced_discrete : DiscreteTopology (Γ.comap F) := by + let : DiscreteTopology Γ:=integerCoordinates_discrete c Γ hΓ + exact DiscreteTopology.preimage_of_continuous_injective (Γ:Set G) hF hinj + +include hsk hF hinj hrat hΓ in +lemma rationalInduced_compact_reps (B : Subgroup K) (w : Fin n → ℕ) + (hmono : Monotone w) (l : ℕ) + (hB : ∀ g : K,g∈B ↔ ∀ i,w iby + obtain ⟨a,ha,hag⟩:=hrep g hg + exact ⟨a,ha,hle hag⟩⟩ + +include hsk hF hinj hrat hΓ in +lemma rationalInduced_compactSpace : CompactSpace (K⧸Γ.comap F) := by + obtain ⟨Λ,e,hΛ,hle,_,_,_⟩:=exists_integer_sublattice_rational c d F + (rationalHom_polynomial c d hsk F hF hrat) Γ hΓ hF hinj + obtain ⟨C,hC,hrep⟩:=compact_reps_of_integerCoordinates e Λ hΛ + apply CompactGroupProducts.HasCompactReps.quotient_compactSpace + refine ⟨C,hC,fun _ _=>Subgroup.mem_top _,?_⟩ + intro g _ + obtain ⟨a,ha,hag⟩:=hrep g + exact ⟨a,ha,hle hag⟩ + +include hsk hF hinj hrat hΓ in +lemma rationalConjugate_compact_reps (σ : G) (hσ : IsRational c σ) + (B : Subgroup K) (w : Fin n → ℕ) (hmono : Monotone w) (l : ℕ) + (hB : ∀ g : K,g∈B ↔ ∀ i,w i c.one_coord i + mul_mem' := by + intro g h hg hh i hi + rw [coord_mul_of_right_zero c g h i (fun j hj => hh j (lt_trans hj hi)),hg i hi,hh i hi] + ring + inv_mem' := by + intro g hg i hi + have he := coord_mul_of_left_zero c g g⁻¹ i (fun j hj => hg j (lt_trans hj hi)) + rw [mul_inv_cancel,c.one_coord,hg i hi] at he + linarith + +@[simp] lemma mem_coordinateTail (k : ℕ) (g : G) : + g ∈ coordinateTail c k ↔ ∀ i : Fin n, i.val < k → c.coord g i = 0 := Iff.rfl +lemma coordinateTail_zero : coordinateTail c 0 = ⊤ := by + ext g + simp +lemma coordinateTail_end (k : ℕ) (hk : n ≤ k) : coordinateTail c k = ⊥ := by + apply le_antisymm _ bot_le + intro g hg + apply (Subgroup.mem_bot).mpr + apply c.coord.injective + funext i + rw [c.one_coord] + exact hg i (lt_of_lt_of_le i.isLt hk) +lemma coordinateTail_antitone : Antitone (coordinateTail c) := by + intro i j hij g hg a ha + exact hg a (lt_of_lt_of_le ha hij) + +lemma coordinateTail_normal (k : ℕ) : (coordinateTail c k).Normal where + conj_mem x hx g := by + intro i hi + have he := conj_coord_difference c g⁻¹ i (u:=x) (v:=1) (by + intro j hj + rw [hx j (lt_trans hj hi),c.one_coord]) + simpa [hx i hi,c.one_coord] using he + + + +lemma coordinateTail_commutator (k : ℕ) (g x : G) (hx : x ∈ coordinateTail c k) : + ⁅g,x⁆ ∈ coordinateTail c (k+1) := by + intro i hi + have hxlow : ∀ j : Fin n, j < i → c.coord x j = 0 := by + intro j hj + exact hx j (by change j.val < i.val at hj; omega) + have hilow : ∀ j : Fin n, j < i → c.coord x⁻¹ j = 0 := by + intro j hj + exact (coordinateTail c k).inv_mem hx j (by change j.val < i.val at hj; omega) + have hc := conj_coord_difference c g⁻¹ i (u:=x) (v:=1) (by + intro j hj + rw [hxlow j hj,c.one_coord]) + simp only [inv_inv,mul_one,mul_inv_cancel,c.one_coord,sub_zero] at hc + have hinv := coord_mul_of_left_zero c x x⁻¹ i hxlow + rw [mul_inv_cancel,c.one_coord] at hinv + rw [commutatorElement_def,coord_mul_of_right_zero c _ _ i hilow] + linarith + +include c in +theorem nilpotent_of_coordinates : Group.IsNilpotent G := by + apply (Subgroup.nilpotent_iff_finite_descending_central_series G).mpr + refine ⟨n,coordinateTail c,⟨coordinateTail_zero c,?_⟩,coordinateTail_end c n le_rfl⟩ + intro x i hx g + simpa only [commutatorElement_inv] using + (coordinateTail c (i+1)).inv_mem (coordinateTail_commutator c i g x hx) + +variable [IsTopologicalGroup G] (Γ : Subgroup G) +variable (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) +include hΓ in + +omit [IsTopologicalGroup G] in +theorem coordinateTail_compact_reps (k : ℕ) : + ∃ C : Set G, IsCompact C ∧ C ⊆ coordinateTail c k ∧ + ∀ g ∈ coordinateTail c k, ∃ a ∈ C, a⁻¹*g ∈ Γ := by + by_cases hk : n ≤ k + · rw [coordinateTail_end c k hk] + refine ⟨{1},isCompact_singleton,by simp,?_⟩ + intro g hg + have hg1 : g=1 := (Subgroup.mem_bot).mp hg + subst g + exact ⟨1,by simp,by simp⟩ + · have hk' : k ≤ n := by omega + obtain ⟨d,rfl⟩ := Nat.exists_eq_add_of_le hk' + let T := coordinateTail c k + let tc := RationalTailCoordinates.tailCoordinates c T (mem_coordinateTail c k) + let Λ := Γ.comap T.subtype + have hΛ : ∀ g : T, g ∈ Λ ↔ ∀ i, ∃ z : ℤ, tc.coord g i = z := by + intro g + exact RationalTailCoordinates.tailCoordinates_lattice c T (mem_coordinateTail c k) Γ hΓ g + obtain ⟨C,hC,hr⟩ := compact_reps_of_integerCoordinates tc Λ hΛ + refine ⟨Subtype.val '' C,hC.image continuous_subtype_val,?_,?_⟩ + · rintro _ ⟨g,hg,rfl⟩ + exact g.property + · intro g hg + obtain ⟨a,ha,he⟩ := hr ⟨g,hg⟩ + exact ⟨a.val,⟨a,ha,rfl⟩,he⟩ + +end RationalLattice +end +end + + + +section + + + +namespace RationalQuotientFunctions +variable {G Y : Type*} [Group G] + + + +def cosetLift (Γ : Subgroup G) (f : G → Y) + (hf : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) : G ⧸ Γ → Y := + Quotient.lift f (by + intro a b h + have hh := hf a (a⁻¹*b) (QuotientGroup.leftRel_apply.mp h) + simpa using hh.symm) + +@[simp] lemma cosetLift_mk (Γ : Subgroup G) (f : G → Y) + (hf : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) (g : G) : + cosetLift Γ f hf (QuotientGroup.mk g) = f g := rfl + +variable [TopologicalSpace G] [TopologicalSpace Y] + +lemma continuous_cosetLift (Γ : Subgroup G) (f : G → Y) + (hf : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) (hc : Continuous f) : + Continuous (cosetLift Γ f hf) := + (QuotientGroup.isQuotientMap_mk Γ).continuous_iff.mpr hc + +variable (N Γ : Subgroup G) [N.Normal] + +omit [TopologicalSpace G] [TopologicalSpace Y] in + + +lemma normal_lift_invariant (f : G → Y) + (hN : ∀ g n, n ∈ N → f (g*n) = f g) + (hΓ : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) + (g : G ⧸ N) (γ : G ⧸ N) (hγ : γ ∈ Γ.map (QuotientGroup.mk' N)) : + cosetLift N f hN (g*γ) = cosetLift N f hN g := by + obtain ⟨c,hc,rfl⟩ := hγ + induction g using Quotient.inductionOn with | h a => + exact hΓ a c hc + + + +def normalDescend (f : G → Y) + (hN : ∀ g n, n ∈ N → f (g*n) = f g) + (hΓ : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) : + ((G ⧸ N) ⧸ Γ.map (QuotientGroup.mk' N)) → Y := + cosetLift _ (cosetLift N f hN) (normal_lift_invariant N Γ f hN hΓ) + +omit [TopologicalSpace G] [TopologicalSpace Y] in +@[simp] lemma normalDescend_mk (f : G → Y) + (hN : ∀ g n, n ∈ N → f (g*n) = f g) + (hΓ : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) (g : G) : + normalDescend N Γ f hN hΓ + (QuotientGroup.mk (QuotientGroup.mk' N g)) = f g := rfl + +lemma continuous_normalDescend (f : G → Y) + (hN : ∀ g n, n ∈ N → f (g*n) = f g) + (hΓ : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) (hc : Continuous f) : + Continuous (normalDescend N Γ f hN hΓ) := + continuous_cosetLift _ _ _ (continuous_cosetLift _ _ _ hc) + + + +omit [TopologicalSpace G] [TopologicalSpace Y] in +lemma normalDescend_forall (f : G → Y) + (hN : ∀ g n, n ∈ N → f (g*n) = f g) + (hΓ : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) (P : Y → Prop) : + (∀ x, P (normalDescend N Γ f hN hΓ x)) ↔ ∀ g, P (f g) := by + constructor + · intro h g + exact h (QuotientGroup.mk (QuotientGroup.mk' N g)) + · intro h x + induction x using Quotient.inductionOn with | h y => + induction y using Quotient.inductionOn with | h g => exact h g + + + +theorem existsUnique_normalDescend (f : C(G,Y)) + (hN : ∀ g n, n ∈ N → f (g*n) = f g) + (hΓ : ∀ g γ, γ ∈ Γ → f (g*γ) = f g) : + ∃! F : C((G ⧸ N) ⧸ Γ.map (QuotientGroup.mk' N),Y), + ∀ g, F (QuotientGroup.mk (QuotientGroup.mk' N g)) = f g := by + refine ⟨⟨normalDescend N Γ f hN hΓ, + continuous_normalDescend N Γ f hN hΓ f.continuous⟩,fun _ => rfl,?_⟩ + intro F hF + ext x + induction x using Quotient.inductionOn with | h y => + induction y using Quotient.inductionOn with | h g => exact hF g + + + +def quotientMap : G ⧸ Γ → (G ⧸ N) ⧸ Γ.map (QuotientGroup.mk' N) := + cosetLift Γ (fun g => QuotientGroup.mk (QuotientGroup.mk' N g)) (by + intro g γ hγ + rw [map_mul] + exact QuotientGroup.mk_mul_of_mem _ ⟨γ,hγ,rfl⟩) + +lemma continuous_quotientMap : Continuous (quotientMap N Γ) := + continuous_cosetLift _ _ _ + (QuotientGroup.continuous_mk.comp QuotientGroup.continuous_mk) + +omit [TopologicalSpace G] in +lemma quotientMap_surjective : Function.Surjective (quotientMap N Γ) := by + intro x + induction x using Quotient.inductionOn with | h y => + induction y using Quotient.inductionOn with | h g => + exact ⟨QuotientGroup.mk g,rfl⟩ + +end RationalQuotientFunctions + + + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTail01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTail01.lean new file mode 100644 index 0000000000000000000000000000000000000000..c937df7dc97ee3da1c73b8b1840239cf02359554 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTail01.lean @@ -0,0 +1,342 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice06 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped BigOperators +noncomputable section +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) +lemma expProduct_rational {x : Fin n → ℝ} (hx : ∀ i, ∃ q : ℚ, (q:ℝ) = x i) : + IsRational c (expProduct c x) := by + intro i + obtain ⟨P,hP⟩ := polynomialMap_expProduct c + (f := fun x : Fin n → ℝ => x) (fun j => RationalPolynomialMap.coordinate j) i + obtain ⟨q,hq⟩ := eval_rational P x hx + exact ⟨q,hq.trans (hP x).symm⟩ +lemma expCoordinates_rational {g : G} (hg : IsRational c g) : + ∀ i, ∃ q : ℚ, (q:ℝ) = expCoordinates c g i := by + intro i + have hpoly : IsPolynomialMap c (fun x : Fin n → ℝ => c.coord.symm x) := by + intro j + simpa only [Homeomorph.apply_symm_apply] using RationalPolynomialMap.coordinate j + obtain ⟨P,hP⟩ := polynomial_expCoordinates c hpoly i + obtain ⟨q,hq⟩ := eval_rational P (c.coord g) hg + refine ⟨q,?_⟩ + rw [hq,← hP] + simp only [Homeomorph.symm_apply_apply] +end RationalLattice + +namespace IntegerHyperplane +variable {n : ℕ} + +lemma exists_last_nonzero (k : Fin (n+1) → ℤ) (hk : k ≠ 0) : + ∃ p : Fin (n+1), k p ≠ 0 ∧ ∀ j : Fin (n+1), p < j → k j = 0 := by + classical + let S := Finset.univ.filter (fun j => k j ≠ 0) + have hs : S.Nonempty := by + by_contra he + apply hk + funext j + by_contra hj + exact he ⟨j,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hj⟩⟩ + refine ⟨S.max' hs,(Finset.mem_filter.mp (Finset.max'_mem S hs)).2,?_⟩ + intro j hj + by_contra hj0 + exact (not_le_of_gt hj) (Finset.le_max' S j (Finset.mem_filter.mpr ⟨Finset.mem_univ _,hj0⟩)) + +def deletedCutoff (p : Fin (n+1)) (r : ℕ) : ℕ := r - if p.val < r then 1 else 0 + +lemma succAbove_lt_cutoff (p : Fin (n+1)) (j : Fin n) (r : ℕ) : + (p.succAbove j).val < r ↔ j.val < deletedCutoff p r := by + unfold deletedCutoff + by_cases hj : j.castSucc < p + · rw [Fin.succAbove_of_castSucc_lt _ _ hj] + have hh : j.val < p.val := hj + simp only [Fin.val_castSucc] + split_ifs <;> omega + · rw [Fin.succAbove_of_le_castSucc _ _ (le_of_not_gt hj)] + have hh : p.val ≤ j.val := le_of_not_gt hj + simp only [Fin.val_succ] + split_ifs <;> omega + +lemma lift_prefix_zero_iff (k : Fin (n+1) → ℤ) (p : Fin (n+1)) + (hlast : ∀ j : Fin (n+1), p < j → k j = 0) (x : Fin n → ℝ) (r : ℕ) : + (∀ a : Fin (n+1), a.val < r → lift k p x a = 0) ↔ + ∀ j : Fin n, j.val < deletedCutoff p r → x j = 0 := by + constructor + · intro hx j hj + simpa using hx (p.succAbove j) ((succAbove_lt_cutoff p j r).mpr hj) + · intro hx a ha + rcases Fin.eq_self_or_eq_succAbove p a with he | ⟨j,he⟩ + · subst a + rw [lift_pivot] + have hs : (∑ j, (k (p.succAbove j):ℝ)*x j) = 0 := by + apply Finset.sum_eq_zero + intro j _ + by_cases hj : (p.succAbove j).val < r + · rw [hx j ((succAbove_lt_cutoff p j r).mp hj),mul_zero] + · have hk := hlast (p.succAbove j) (by change p.val < (p.succAbove j).val; omega) + simp [hk] + simp [hs] + · subst a + rw [lift_succAbove] + exact hx j ((succAbove_lt_cutoff p j r).mp ha) + +end IntegerHyperplane + +namespace RationalCharacterKernel +open RationalLattice IntegerHyperplane +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G (n+1)) (χ : G →* Multiplicative ℝ) +variable (k : Fin (n+1) → ℤ) (p : Fin (n+1)) (hp : k p ≠ 0) +variable (hχ : ∀ g : G, Multiplicative.toAdd (χ g) = form k (c.coord g)) +variable (hlast : ∀ j : Fin (n+1), p < j → k j = 0) + + +lemma kernelCoordinates_adapted (H : Subgroup G) (r : ℕ) + (hH : ∀ g : G, g ∈ H ↔ ∀ i : Fin (n+1), i.val < r → c.coord g i = 0) + (g : χ.ker) : + g.val ∈ H ↔ ∀ i : Fin n, i.val < deletedCutoff p r → + (kernelCoordinates c χ k p hp hχ hlast).coord g i = 0 := by + rw [hH,coord_lift c χ k p hp hχ] + exact lift_prefix_zero_iff k p hlast _ r + +variable [IsTopologicalGroup G] + + +theorem exists_rational_kernel_chart (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) + (hcont : Continuous χ) (hz : ∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) + (hne : χ ≠ 1) : + ∃ d : RealCoordinates χ.ker n, + (∀ g : χ.ker, IsRational d g ↔ IsRational c g.val) ∧ + ∀ H : Subgroup G, ∀ r : ℕ, + (∀ g : G, g ∈ H ↔ ∀ i : Fin (n+1), i.val < r → c.coord g i = 0) → + ∃ t : ℕ, ∀ g : χ.ker, g.val ∈ H ↔ ∀ i : Fin n, i.val < t → d.coord g i = 0 := by + obtain ⟨k,hk⟩ := integer_character_expCoordinates c Γ hΓ χ hcont hz + have hk0 : k ≠ 0 := by + intro he + apply hne + ext g + apply Multiplicative.toAdd.injective + rw [hk,he] + simp + obtain ⟨p,hp,hlast⟩ := exists_last_nonzero k hk0 + have he : ∀ g : G, Multiplicative.toAdd (χ g) = form k ((secondCoordinates c).coord g) := by + intro g + rw [hk] + change (∑ i, expCoordinates c g i * (k i:ℝ)) = ∑ i, (k i:ℝ)*expCoordinates c g i + exact Finset.sum_congr rfl (fun i _ => mul_comm _ _) + let d := kernelCoordinates (secondCoordinates c) χ k p hp he hlast + refine ⟨d,?_,?_⟩ + · intro g + rw [kernelCoordinates_rational] + constructor + · intro hg + rw [← expProduct_expCoordinates c g.val] + exact expProduct_rational c hg + · exact expCoordinates_rational c + · intro H r hH + refine ⟨deletedCutoff p r,fun g => ?_⟩ + exact kernelCoordinates_adapted (secondCoordinates c) χ k p hp he hlast H r + (secondCoordinates_adapted c H r hH) g + +end RationalCharacterKernel +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace RationalTailCoordinates +open RationalLattice RationalPolynomialMap +variable {G : Type*} [Group G] [TopologicalSpace G] {r n : ℕ} +variable (c : RealCoordinates G (r+n)) (H : Subgroup G) +variable (hH : ∀ g : G, g ∈ H ↔ ∀ i : Fin (r+n), i.val < r → c.coord g i = 0) +def embed (r : ℕ) (j : Fin n) : Fin (r+n) := ⟨r+j.val,by omega⟩ +def lift (r : ℕ) (x : Fin n → ℝ) (a : Fin (r+n)) : ℝ := + if h : r ≤ a.val then x ⟨a.val-r,by have := a.isLt; omega⟩ else 0 +@[simp] lemma lift_embed (x : Fin n → ℝ) (j : Fin n) : lift r x (embed r j) = x j := by + simp [lift,embed] +lemma lift_prefix (x : Fin n → ℝ) (a : Fin (r+n)) (ha : a.val < r) : lift r x a = 0 := by + simp [lift,not_le_of_gt ha] +lemma lift_continuous : Continuous (lift (n:=n) r) := by + apply continuous_pi + intro a + unfold lift + split_ifs + · exact continuous_apply _ + · exact continuous_const + +def coordinates (g : H) (i : Fin n) : ℝ := c.coord g.val (embed r i) +include hH in +lemma coord_lift (g : H) : c.coord g.val = lift r (coordinates c H g) := by + funext a + unfold lift + split_ifs with ha + · apply congrArg (c.coord g.val) + apply Fin.ext + change a.val = r+(a.val-r) + omega + · exact (hH g.val).mp g.property a (by omega) + +def rebuild (x : Fin n → ℝ) : H := + ⟨c.coord.symm (lift r x),(hH _).mpr (by + intro a ha + rw [c.coord.apply_symm_apply] + exact lift_prefix x a ha)⟩ +lemma coordinates_rebuild (x : Fin n → ℝ) : coordinates c H (rebuild c H hH x) = x := by + funext j + simp only [coordinates,rebuild,Homeomorph.apply_symm_apply,lift_embed] +lemma rebuild_coordinates (g : H) : rebuild c H hH (coordinates c H g) = g := by + apply Subtype.ext + apply c.coord.injective + simpa only [rebuild,Homeomorph.apply_symm_apply] using (coord_lift c H hH g).symm +lemma coordinates_continuous : Continuous (coordinates c H) := by + apply continuous_pi + intro i + exact (continuous_apply _).comp (c.coord.continuous.comp continuous_subtype_val) +lemma rebuild_continuous : Continuous (rebuild c H hH) := by + apply Continuous.subtype_mk + exact c.coord.symm.continuous.comp lift_continuous + +def tailHomeomorph : H ≃ₜ (Fin n → ℝ) where + toFun := coordinates c H + invFun := rebuild c H hH + left_inv := rebuild_coordinates c H hH + right_inv := coordinates_rebuild c H hH + continuous_toFun := coordinates_continuous c H + continuous_invFun := rebuild_continuous c H hH + +def lowerLift (r : ℕ) (i : Fin n) (x : Fin i.val → ℝ) (a : Fin (r+i.val)) : ℝ := + if h : r ≤ a.val then x ⟨a.val-r,by have := a.isLt; omega⟩ else 0 + +lemma exists_correction (i : Fin n) : + ∃ P : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ, + ∀ v : (Fin i.val ⊕ Fin i.val) → ℝ, + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (lowerLift r i (fun a => v (.inl a))) + (lowerLift r i (fun a => v (.inr a)))) (c.correction (embed r i)) = + MvPolynomial.eval₂ (algebraMap ℚ ℝ) v P := by + apply RationalPolynomialMap.eval + intro a + cases a with + | inl a => + simp only [Sum.elim_inl] + unfold lowerLift + split_ifs + · exact coordinate _ + · exact zero + | inr a => + simp only [Sum.elim_inr] + unfold lowerLift + split_ifs + · exact coordinate _ + · exact zero + +def correction (i : Fin n) : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ := + (exists_correction c i).choose +include hH in +lemma mul_coord (g h : H) (i : Fin n) : + coordinates c H (g*h) i = coordinates c H g i + coordinates c H h i + + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => coordinates c H g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => coordinates c H h ⟨j.val,lt_trans j.isLt i.isLt⟩)) (correction c i) := by + change c.coord (g.val*h.val) (embed r i) = _ + rw [c.mul_coord] + change coordinates c H g i + coordinates c H h i + _ = _ + congr 1 + let v : (Fin i.val ⊕ Fin i.val) → ℝ := + Sum.elim (fun j => coordinates c H g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => coordinates c H h ⟨j.val,lt_trans j.isLt i.isLt⟩) + unfold correction + rw [← (exists_correction c i).choose_spec v] + congr 1 + funext a + have hl (u : H) (a : Fin (r+i.val)) : + c.coord u.val ⟨a.val,by have := a.isLt; have := i.isLt; omega⟩ = + lowerLift r i (fun j => coordinates c H u ⟨j.val,lt_trans j.isLt i.isLt⟩) a := by + unfold lowerLift + split_ifs with ha + · apply congrArg (c.coord u.val) + apply Fin.ext + change a.val = r+(a.val-r) + omega + · exact (hH u.val).mp u.property _ (by change a.val < r; omega) + cases a with + | inl a => exact hl g a + | inr a => exact hl h a + +def tailCoordinates : RealCoordinates H n where + coord := tailHomeomorph c H hH + one_coord i := c.one_coord (embed r i) + correction := correction c + mul_coord := mul_coord c H hH + +lemma tailCoordinates_rational (g : H) : + IsRational (tailCoordinates c H hH) g ↔ IsRational c g.val := by + constructor + · intro hg i + rw [coord_lift c H hH g] + unfold lift + split_ifs + · exact hg _ + · exact ⟨0,by simp⟩ + · intro hg i + exact hg (embed r i) + +lemma tailCoordinates_lattice (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) (g : H) : + g.val ∈ Γ ↔ ∀ i, ∃ z : ℤ, (tailCoordinates c H hH).coord g i = z := by + constructor + · intro hg i + exact (hΓ _).mp hg (embed r i) + · intro hg + apply (hΓ _).mpr + intro i + rw [coord_lift c H hH g] + unfold lift + split_ifs + · exact hg _ + · exact ⟨0,by simp⟩ + +lemma tailCoordinates_adapted (K : Subgroup G) (s : ℕ) + (hK : ∀ g : G, g ∈ K ↔ ∀ i : Fin (r+n), i.val < s → c.coord g i = 0) (g : H) : + g.val ∈ K ↔ ∀ i : Fin n, i.val < s-r → (tailCoordinates c H hH).coord g i = 0 := by + rw [hK] + constructor + · intro hg i hi + exact hg (embed r i) (by dsimp [embed]; omega) + · intro hg i hi + rw [coord_lift c H hH g] + unfold lift + split_ifs with hr + · exact hg _ (by change i.val-r < s-r; omega) + · rfl + +end RationalTailCoordinates + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTail02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTail02.lean new file mode 100644 index 0000000000000000000000000000000000000000..529099893d753887cebf7a30ff0ad8b21f605208 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTail02.lean @@ -0,0 +1,312 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevCharacters01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped BigOperators +end +end + + + +section +noncomputable section +open scoped BigOperators +namespace RationalTailCoordinates +open RationalLattice MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {r n : ℕ} (c : RealCoordinates G (r+n)) (H : Subgroup G) +variable (hH : ∀ g : G, g ∈ H ↔ ∀ i : Fin (r+n), i.val < r → c.coord g i = 0) + + +def extendCoefficient {A : Type*} [Zero A] (k : Fin n → A) : Fin (r+n) → A := + Fin.addCases (fun _ => 0) k + +omit [IsTopologicalGroup G] in +lemma sum_extend [IsTopologicalGroup G] (k : Fin n → ℝ) (g : G) : + (∑ i, c.coord g i * extendCoefficient (r:=r) k i) = + ∑ i, c.coord g (embed r i) * k i := by + rw [Fin.sum_univ_add] + simp only [extendCoefficient,Fin.addCases_left,Fin.addCases_right,mul_zero,Finset.sum_const_zero,zero_add] + rfl + +omit [IsTopologicalGroup G] in +lemma sum_extend_int [IsTopologicalGroup G] (k : Fin n → ℤ) (g : G) : + (∑ i, c.coord g i * ((extendCoefficient (r:=r) k i : ℤ) : ℝ)) = + ∑ i, c.coord g (embed r i) * (k i : ℝ) := by + rw [Fin.sum_univ_add] + simp only [extendCoefficient,Fin.addCases_left,Fin.addCases_right,Int.cast_zero,mul_zero, + Finset.sum_const_zero,zero_add] + rfl + +include hH in + + +theorem exists_integer_extension (hsk : SecondKind c) (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) + (χ : H →* Multiplicative ℝ) (hcont : Continuous χ) + (hz : ∀ g : H, g.val ∈ Γ → ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) + (hcomm : _root_.commutator G ≤ χ.ker.map H.subtype) : + ∃ ψ : G →* Multiplicative ℝ, Continuous ψ ∧ + ψ.comp H.subtype = χ ∧ + (∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (ψ g) = z) ∧ + ∃ k : Fin n → ℤ, ∀ g : G, + Multiplicative.toAdd (ψ g) = ∑ i, c.coord g (embed r i) * (k i : ℝ) := by + obtain ⟨k,hk⟩ := integer_character_coordinates (tailCoordinates c H hH) + (tail_secondKind c H hH hsk) χ (Γ.comap H.subtype) + (fun g => tailCoordinates_lattice c H hH Γ hΓ g) hcont hz + let a : Fin (r+n) → ℝ := fun i => ((extendCoefficient (r:=r) k i : ℤ) : ℝ) + let N := χ.ker.map H.subtype + let : N.Normal := Subgroup.Normal.of_commutator_le G hcomm + have hzero : ∀ g ∈ N, ∑ i, c.coord g i * a i = 0 := by + rintro g ⟨u,hu,rfl⟩ + change (∑ i, c.coord u.val i * ((extendCoefficient (r:=r) k i : ℤ) : ℝ)) = 0 + rw [sum_extend_int] + change (∑ i, (tailCoordinates c H hH).coord u i * (k i : ℝ)) = 0 + rw [← hk] + exact congrArg Multiplicative.toAdd hu + let ψ := abelianCoordinateCharacter c hsk N hcomm a hzero + have hψ (g : G) : Multiplicative.toAdd (ψ g) = + ∑ i, c.coord g (embed r i) * (k i : ℝ) := by + rw [abelianCoordinateCharacter_apply] + exact sum_extend_int c k g + refine ⟨ψ,abelianCoordinateCharacter_continuous c hsk N hcomm a hzero,?_,?_,k,hψ⟩ + · ext u + apply Multiplicative.toAdd.injective + change Multiplicative.toAdd (ψ u.val) = Multiplicative.toAdd (χ u) + rw [hψ,hk] + rfl + · intro g hg + choose z hz using (hΓ g).mp hg + refine ⟨∑ i, z (embed r i) * k i,?_⟩ + rw [hψ] + simp only [hz,Int.cast_sum,Int.cast_mul] + +end RationalTailCoordinates +end +end + + + +section +noncomputable section +open scoped BigOperators +namespace RationalCharacterFirst +open RationalLattice IntegerHyperplane +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {n : ℕ} +variable (c : RealCoordinates G (n+1)) (χ : G →* Multiplicative ℝ) + + + +theorem exists_refined_integer_cover (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) + (hcont : Continuous χ) (hz : ∀ g ∈ Γ, ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) + (hne : χ ≠ 1) : + ∃ Λ : Subgroup G, ∃ e : RealCoordinates G (n+1), + (∀ g : G, g ∈ Λ ↔ ∀ i, ∃ z : ℤ, e.coord g i = z) ∧ + Λ ≤ Γ ∧ (Λ.subgroupOf Γ).FiniteIndex ∧ + ∀ H : Subgroup G, ∀ r : ℕ, + (∀ g : G, g ∈ H ↔ ∀ i : Fin (n+1), i.val < r → c.coord g i = 0) → + ∃ t : ℕ, ∀ g : G, g ∈ H ⊓ χ.ker ↔ ∀ i : Fin (n+1), i.val < t → e.coord g i = 0 := by + obtain ⟨k,hk⟩ := integer_character_expCoordinates c Γ hΓ χ hcont hz + have hk0 : k ≠ 0 := by + intro he + apply hne + ext g + apply Multiplicative.toAdd.injective + rw [hk,he] + simp + obtain ⟨p,hp,hlast⟩ := exists_last_nonzero k hk0 + have he : ∀ g : G, Multiplicative.toAdd (χ g) = form k ((secondCoordinates c).coord g) := by + intro g + rw [hk] + exact Finset.sum_congr rfl (fun i _ => mul_comm _ _) + let d := characterFirstCoordinates (secondCoordinates c) χ k p hp he hlast + have hdpoly : ∀ i, RationalPolynomialMap.IsPolynomial (fun x : Fin (n+1) → ℝ => c.coord (d.coord.symm x) i) := by + intro i + change RationalPolynomialMap.IsPolynomial (fun x => c.coord (expProduct c (splitLift k p x)) i) + exact polynomialMap_expProduct c (fun j => splitLift_polynomial k p j) i + obtain ⟨Λ,e,hΛ,hle,hi,hzero⟩ := exists_integer_sublattice c d (MonoidHom.id G) + hdpoly Γ hΓ continuous_id Function.injective_id + refine ⟨Λ,e,hΛ,hle,hi,?_⟩ + intro H r hH + refine ⟨deletedCutoff p r+1,fun g => ?_⟩ + rw [characterFirst_adapted (secondCoordinates c) χ k p hp he hlast H r + (secondCoordinates_adapted c H r hH)] + exact forall_congr' (fun i => imp_congr_right (fun _ => (hzero g i).symm)) + +end RationalCharacterFirst + +namespace RationalTailCoordinates +open RationalLattice MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {r n : ℕ} (c : RealCoordinates G (r+(n+1))) (H : Subgroup G) +variable (hH : ∀ g : G, g ∈ H ↔ ∀ i : Fin (r+(n+1)), i.val < r → c.coord g i = 0) + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma mapped_kernel_eq_inter [TopologicalSpace G] [IsTopologicalGroup G] + (χ : H →* Multiplicative ℝ) (ψ : G →* Multiplicative ℝ) + (he : ψ.comp H.subtype = χ) : χ.ker.map H.subtype = H ⊓ ψ.ker := by + ext g + constructor + · rintro ⟨u,hu,rfl⟩ + refine ⟨u.property,?_⟩ + change ψ u.val=1 + change χ u = 1 at hu + have hh := DFunLike.congr_fun he u + change ψ u.val = χ u at hh + exact hh.trans hu + · rintro ⟨hg,hψ⟩ + refine ⟨⟨g,hg⟩,?_,rfl⟩ + change χ ⟨g,hg⟩=1 + rw [← he] + exact hψ + +include hH in + + +theorem exists_lower_refinement_geometry (hsk : SecondKind c) (Γ : Subgroup G) + (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) + (χ : H →* Multiplicative ℝ) (hcont : Continuous χ) + (hz : ∀ g : H, g.val ∈ Γ → ∃ z : ℤ, Multiplicative.toAdd (χ g) = z) + (hcomm : _root_.commutator G ≤ χ.ker.map H.subtype) (hne : χ ≠ 1) : + ∃ Λ : Subgroup G, ∃ e : RealCoordinates G (r+(n+1)), + (∀ g : G, g ∈ Λ ↔ ∀ i, ∃ z : ℤ, e.coord g i = z) ∧ + Λ ≤ Γ ∧ (Λ.subgroupOf Γ).FiniteIndex ∧ + ∀ K : Subgroup G, K ≤ H → ∀ s : ℕ, + (∀ g : G, g ∈ K ↔ ∀ i : Fin (r+(n+1)), i.val < s → c.coord g i = 0) → + ∃ t : ℕ, ∀ g : G, + g ∈ K ⊓ χ.ker.map H.subtype ↔ ∀ i : Fin (r+(n+1)), i.val < t → e.coord g i = 0 := by + obtain ⟨ψ,hψ,hagree,hint,_⟩ := exists_integer_extension c H hH hsk Γ hΓ χ hcont hz hcomm + have hnψ : ψ ≠ 1 := by + intro h + apply hne + rw [← hagree,h] + rfl + obtain ⟨Λ,e,hΛ,hle,hi,ha⟩ := RationalCharacterFirst.exists_refined_integer_cover c ψ Γ hΓ hψ hint hnψ + refine ⟨Λ,e,hΛ,hle,hi,?_⟩ + intro K hK s hKs + obtain ⟨t,ht⟩ := ha K s hKs + refine ⟨t,fun g => ?_⟩ + rw [mapped_kernel_eq_inter H χ ψ hagree,← inf_assoc,inf_eq_left.mpr hK] + exact ht g + +end RationalTailCoordinates +end +end + + + +section +noncomputable section +open scoped BigOperators +namespace MalcevCharacters +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (H : Subgroup G) (r : ℕ) (hcomm : _root_.commutator G ≤ H) +variable (hH : ∀ g ∈ H, ∀ i : Fin n, i.val < r → c.coord g i = 0) + +include hsk hcomm hH in + + +lemma prefix_coord_mul (i : Fin n) (hi : i.val < r) (g h : G) : + c.coord (g*h) i = c.coord g i+c.coord h i := by + classical + let : H.Normal := Subgroup.Normal.of_commutator_le G hcomm + have hz : ∀ g ∈ H, ∑ j, c.coord g j * (Pi.single i 1 : Fin n → ℝ) j = 0 := by + intro g hg + simpa [Pi.single_apply] using hH g hg i hi + simpa [Pi.single_apply] using coordinate_form_mul c hsk H hcomm (Pi.single i 1) hz g h + + + +def horizontalCoordinates : RealCoordinates G n where + coord := c.coord + one_coord := c.one_coord + correction i := if i.val < r then 0 else c.correction i + mul_coord g h i := by + split_ifs with hi + · simp only [MvPolynomial.eval₂_zero,add_zero] + exact prefix_coord_mul c hsk H r hcomm hH i hi g h + · exact c.mul_coord g h i + +lemma horizontalCoordinates_correction (i : Fin n) (hi : i.val < r) : + (horizontalCoordinates c hsk H r hcomm hH).correction i = 0 := by + simp [horizontalCoordinates,hi] + +lemma horizontalCoordinates_secondKind : SecondKind (horizontalCoordinates c hsk H r hcomm hH) := + ⟨hsk.axis_add,hsk.ordered⟩ + +end MalcevCharacters +end +end + + + +section +noncomputable section +namespace RationalLatticeCover +open MeasureTheory RationalQuotientFunctions RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + {Λ Γ : Subgroup G} + + +def coverMap (h : Λ ≤ Γ) : C(G⧸Λ,G⧸Γ) := + ⟨cosetLift Λ (fun g => (QuotientGroup.mk g : G⧸Γ)) (by + intro g a ha + exact QuotientGroup.mk_mul_of_mem _ (h ha)), + continuous_cosetLift _ _ _ QuotientGroup.continuous_mk⟩ + +omit [IsTopologicalGroup G] in +@[simp] lemma coverMap_mk [IsTopologicalGroup G] (h : Λ ≤ Γ) (g : G) : + coverMap h (QuotientGroup.mk g) = QuotientGroup.mk g := rfl + +omit [IsTopologicalGroup G] in +lemma coverMap_smul [IsTopologicalGroup G] (h : Λ ≤ Γ) (g : G) (x : G⧸Λ) : + coverMap h (g • x) = g • coverMap h x := by + induction x using Quotient.inductionOn with | h a => rfl + +omit [IsTopologicalGroup G] in +lemma coverMap_surjective [IsTopologicalGroup G] (h : Λ ≤ Γ) : + Function.Surjective (coverMap h) := by + intro x + induction x using Quotient.inductionOn with | h a => exact ⟨QuotientGroup.mk a,rfl⟩ + +variable [MeasurableSpace (G⧸Λ)] [BorelSpace (G⧸Λ)] + [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + + + +theorem map_coordinateHaar {d : ℕ} (c : RealCoordinates G d) + (hint : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + (h : Λ ≤ Γ) (μ : ProbabilityMeasure (G⧸Γ)) (ν : ProbabilityMeasure (G⧸Λ)) + [SMulInvariantMeasure G (G⧸Γ) (μ : Measure (G⧸Γ))] + [SMulInvariantMeasure G (G⧸Λ) (ν : Measure (G⧸Λ))] : + Measure.map (coverMap h) (ν : Measure (G⧸Λ)) = (μ : Measure (G⧸Γ)) := by + let q := coverMap h + let : SMulInvariantMeasure G (G⧸Γ) (Measure.map q (ν : Measure (G⧸Λ))) := + smulInvariantMeasure_map (ν : Measure (G⧸Λ)) q (coverMap_smul h) q.continuous.measurable + let ρ : ProbabilityMeasure (G⧸Γ) := ν.map q + have hρ : SMulInvariantMeasure G (G⧸Γ) (ρ : Measure (G⧸Γ)) := by + change SMulInvariantMeasure G (G⧸Γ) (Measure.map q (ν : Measure (G⧸Λ))) + infer_instance + obtain ⟨hair,hh,hu⟩ := existsUnique_coordinateHaar c Γ hint + have he : ρ=μ := (hu ρ hρ).trans (hu μ inferInstance).symm + exact congrArg (fun p : ProbabilityMeasure (G⧸Γ) => (p : Measure (G⧸Γ))) he + +end RationalLatticeCover + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTriangular01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTriangular01.lean new file mode 100644 index 0000000000000000000000000000000000000000..f069ebf6059f469c6373fe75637f298c47ba13f2 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RationalTriangular01.lean @@ -0,0 +1,366 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.AllLevel05 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +open scoped BigOperators Topology +open Filter +end + +end + +section + + + + +noncomputable section +open scoped BigOperators Topology commutatorElement +open Filter Topology +universe u +namespace AllLevelFactorization +open RationalLattice CubeFaces CubePolynomials NilpotentTaylor +open AllLevelDomains AllLevelRemovals AllLevelStates +variable {G : Type u} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (Γ : Subgroup G) (s : ℕ) +variable (K : Filtration G) (P : ℕ → ℤ → G) (L : ℕ → ℝ) + + + +structure Factorization where + normalized : ℕ → ℤ → G + constantPart : ℕ → G + normal_quotient : ∀ N z,(QuotientGroup.mk (P N z) : G⧸Γ)= + QuotientGroup.mk (constantPart N*normalized N z) + state : State c Γ s K normalized L + irrational : state.Irrational + period : ℕ + period_pos : 0hreps (P N 0) + let γ : ℕ → G:=fun N=>(a N)⁻¹*P N 0 + let R : ℕ → ℤ → G:=fun N z=>(a N)⁻¹*P N z*(γ N)⁻¹ + have hR (N : ℕ) : R N∈polynomials K 0 := by + apply (polynomials K 0).mul_mem + · exact (polynomials K 0).mul_mem (const_mem (by simp [hK0])) (hP N) + · exact const_mem (by simp [hK0]) + have hR0 (N : ℕ) : R N 0=1 := by simp [R,γ] + have hq (N : ℕ) (z : ℤ) : (QuotientGroup.mk (P N z) : G⧸Γ)= + QuotientGroup.mk (a N*R N z) := by + have he : a N*R N z=P N z*(γ N)⁻¹:=by simp [R,← mul_assoc] + rw [he,QuotientGroup.mk_mul_of_mem _ (Γ.inv_mem (hγ N))] + obtain ⟨S,hS⟩:=normalized_factorization_exists hsk hΓ hK0 hK1 hKs r hr hadapt hR hR0 hL + obtain ⟨T,d,σ,hT,hd,hσ,he⟩:=S.exists_irrational_fixed_residues + (integerCoordinates_rational c Γ hΓ) C hC hreps hS + obtain ⟨a₀,_,φ,hφ,ht⟩:=hC.tendsto_subseq (fun N=>ha (T.subseq N)) + refine ⟨{ normalized := R + constantPart := a + normal_quotient := hq + state := T.reindex φ hφ + irrational := T.irrational_reindex hT φ hφ + period := d + period_pos := hd + residue := σ + residue_rational := hσ + right_residue := ?_ + prefixLimit := a₀ + prefix_tendsto := ht }⟩ + intro N z + change ∃ t : Fin d,(t.val:ℤ)=z%(d:ℤ) ∧ + (QuotientGroup.mk (rightWord (T.removals.map (fun w=>w.reindex φ hφ)) N z) : G⧸Γ)= + QuotientGroup.mk (σ t) + rw [rightWord_reindex] + exact he (φ N) z + +namespace Factorization +variable (F : Factorization c Γ s K P L) + +def smoothPart (N : ℕ) (b : ℝ) : G := + F.constantPart (F.state.subseq N)*smoothWord F.state.removals N b + +def smoothLimit (β : ℝ) : G := + F.prefixLimit*AllLevelRemovals.smoothLimit F.state.removals β + +def structuredPart (N : ℕ) (z : ℤ) : F.state.domain.Carrier := + word (fun k=>(F.state.coeff N k).val) (s+1) z + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma quotient_mul_congr [TopologicalSpace G] [IsTopologicalGroup G] (a b g : G) + (h : (QuotientGroup.mk a : G⧸Γ)=QuotientGroup.mk b) : + (QuotientGroup.mk (g*a) : G⧸Γ)=QuotientGroup.mk (g*b) := by + apply QuotientGroup.eq.mpr + have hm:=QuotientGroup.eq.mp h + simpa [mul_inv_rev,mul_assoc] using hm + + +theorem realization (N : ℕ) (z : ℤ) : + ∃ r : Fin F.period,(r.val:ℤ)=z%(F.period:ℤ) ∧ + (QuotientGroup.mk (P (F.state.subseq N) z) : G⧸Γ)= + QuotientGroup.mk (F.smoothPart N z*F.state.domain.embed (F.structuredPart N z)* + F.residue r) := by + obtain ⟨r,hr,he⟩:=F.right_residue N z + refine ⟨r,hr,?_⟩ + rw [F.normal_quotient,F.state.realization] + have hw : smoothWord F.state.removals N (z:ℝ)=leftWord F.state.removals N z:= + smoothWord_integer _ _ _ + dsimp only [smoothPart,structuredPart] + rw [hw] + simpa only [mul_assoc] using quotient_mul_congr + (rightWord F.state.removals N z) (F.residue r) + (F.constantPart (F.state.subseq N)*leftWord F.state.removals N z* + F.state.domain.embed (word (fun k=>(F.state.coeff N k).val) (s+1) z)) he + + + +theorem smooth_limit (hL : ∀ N,0iteratedDeriv k + (fun β=>c.coord (F.smoothPart N (L (F.state.subseq N)*β)) i)) + (iteratedDeriv k (fun β=>c.coord (F.smoothLimit β) i)) atTop A := by + exact prefix_smoothWord_limit F.state.removals (fun N=>hL _) + (ht.comp F.state.strictmono.tendsto_atTop) F.prefix_tendsto k i A hA + +theorem smooth_bounds (hL : ∀ N,00,∀ N β,β∈A → + |iteratedDeriv k (fun β=>c.coord (F.smoothPart N (L (F.state.subseq N)*β)) i) β|≤B := by + exact prefix_smoothWord_bounds F.state.removals (fun N=>hL _) + (ht.comp F.state.strictmono.tendsto_atTop) F.prefix_tendsto k i A hA + +theorem limit_smooth (i : Fin n) : + ContDiff ℝ (⊤ : ℕ∞) (fun β=>c.coord (F.smoothLimit β) i) := + prefix_smoothLimit_smooth F.state.removals F.prefixLimit i + +end Factorization + +end AllLevelFactorization +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalLattice +open MalcevCharacters RationalLevelFlow +variable {G H : Type*} [Group G] [Group H] +variable [TopologicalSpace G] [TopologicalSpace H] +variable [IsTopologicalGroup G] [IsTopologicalGroup H] +variable {m n : ℕ} (c : RealCoordinates G m) (d : RealCoordinates H n) + +omit [IsTopologicalGroup G] in +lemma polynomialMap_realPower [IsTopologicalGroup G] {σ : Type*} {g : G} (hg : IsRational c g) + {f : (σ → ℝ) → ℝ} (hf : RationalPolynomialMap.IsPolynomial f) : + IsPolynomialMap c (fun x=>realPower c g (f x)) := by + intro j + obtain ⟨p,hp⟩:=powerPolynomial_rational c hg j + simpa only [realPower_coord,hp,Polynomial.eval_map] using + RationalPolynomialMap.polynomial_eval p hf + +omit [IsTopologicalGroup G] in +lemma polynomialMap_list_prod [IsTopologicalGroup G] {σ : Type*} (V : List ((σ → ℝ) → G)) + (hV : ∀ f∈V,IsPolynomialMap c f) : + IsPolynomialMap c (fun x=>(V.map (fun f=>f x)).prod) := by + induction V with + | nil => simpa using polynomialMap_one c + | cons f V ih => + simpa using polynomialMap_mul c (hV f (by simp)) (ih (fun f hf=>hV f (by simp [hf]))) + +omit [IsTopologicalGroup H] in +lemma axis_rational [IsTopologicalGroup H] (i : Fin n) (t : ℚ) : IsRational d (axis d i t) := by + classical + intro j + refine ⟨if j=i then t else 0,?_⟩ + simp only [coord_axis,Pi.single_apply] + split_ifs <;> simp + + + +theorem rationalHom_polynomial (hsk : SecondKind d) (F : H →* G) + (hF : Continuous F) (hrat : ∀ x,IsRational d x → IsRational c (F x)) : + IsPolynomialMap c (fun x : Fin n → ℝ=>F (d.coord.symm x)) := by + let A (i : Fin n) : Multiplicative ℝ →* H := + { toFun := fun t=>axis d i t.toAdd + map_one' := axis_zero d i + map_mul' := fun t u=>hsk.axis_add i t.toAdd u.toAdd } + have he (i : Fin n) (t : ℝ) : F (axis d i t)=realPower c (F (axis d i 1)) t := + continuous_flow_eq_realPower c (F.comp (A i)) + (hF.comp ((axis_continuous d i).comp continuous_toAdd)) t + have hp (i : Fin n) : IsPolynomialMap c (fun x : Fin n → ℝ=>F (axis d i (x i))) := by + have hfun : (fun x : Fin n → ℝ=>F (axis d i (x i))) = + (fun x=>realPower c (F (axis d i 1)) (x i)) := funext (fun x=>he i (x i)) + rw [hfun] + simpa only [Rat.cast_one] using polynomialMap_realPower c (hrat _ (axis_rational d i 1)) + (RationalPolynomialMap.coordinate i) + have hprod:=polynomialMap_list_prod c (List.ofFn (fun i : Fin n=> + (fun x : Fin n → ℝ=>F (axis d i (x i))))) (by + intro f hf + obtain ⟨i,rfl⟩:=List.mem_ofFn.mp hf + exact hp i) + have hw (x : Fin n → ℝ) : F (d.coord.symm x)= + ((List.ofFn (fun i : Fin n=>(fun x : Fin n → ℝ=>F (axis d i (x i))))).map + (fun f=>f x)).prod := by + conv_lhs => rw [hsk.ordered (d.coord.symm x)] + rw [map_list_prod,List.map_ofFn,List.map_ofFn] + simp only [Homeomorph.apply_symm_apply,Function.comp_def] + simpa only [← hw] using hprod + +end RationalLattice + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RationalTriangularChange +open MvPolynomial + +def forward {n : ℕ} (p : (i : Fin n) → MvPolynomial (Fin i.val) ℚ) + (x : Fin n → ℝ) (i : Fin n) : ℝ := + x i + eval₂ (algebraMap ℚ ℝ) (fun j=>x ⟨j.val,lt_trans j.isLt i.isLt⟩) (p i) + +def inverse : {n : ℕ} → ((i : Fin n) → MvPolynomial (Fin i.val) ℚ) → + (Fin n → ℝ) → (Fin n → ℝ) + | 0, _, _ => Fin.elim0 + | n+1, p, y => + let x := inverse (fun i : Fin n=>p i.castSucc) (fun i=>y i.castSucc) + Fin.snoc x (y (Fin.last n)-eval₂ (algebraMap ℚ ℝ) x (p (Fin.last n))) + +lemma inverse_castSucc {n : ℕ} (p : (i : Fin (n+1)) → MvPolynomial (Fin i.val) ℚ) + (y : Fin (n+1) → ℝ) (i : Fin n) : + inverse p y i.castSucc=inverse (fun i : Fin n=>p i.castSucc) (fun i=>y i.castSucc) i := by + simp [inverse] + +lemma inverse_last {n : ℕ} (p : (i : Fin (n+1)) → MvPolynomial (Fin i.val) ℚ) + (y : Fin (n+1) → ℝ) : + inverse p y (Fin.last n)=y (Fin.last n)-eval₂ (algebraMap ℚ ℝ) + (inverse (fun i : Fin n=>p i.castSucc) (fun i=>y i.castSucc)) (p (Fin.last n)) := by + simp [inverse] + +lemma forward_inverse {n : ℕ} (p : (i : Fin n) → MvPolynomial (Fin i.val) ℚ) + (y : Fin n → ℝ) : forward p (inverse p y)=y := by + induction n with + | zero => funext i; exact Fin.elim0 i + | succ n ih => + funext i + refine Fin.lastCases ?_ (fun i=>?_) i + · unfold forward + rw [inverse_last] + have hfun : (fun j : Fin (Fin.last n).val=>inverse p y ⟨j.val,lt_trans j.isLt (Fin.last n).isLt⟩)= + inverse (fun i : Fin n=>p i.castSucc) (fun i=>y i.castSucc) := by + funext j + exact inverse_castSucc p y j + rw [hfun] + ring + · have h:=congrFun (ih (fun i : Fin n=>p i.castSucc) (fun i=>y i.castSucc)) i + have hfun : (fun j : Fin i.val=>inverse p y ⟨j.val,lt_trans j.isLt i.castSucc.isLt⟩)= + (fun j : Fin i.val=>inverse (fun i : Fin n=>p i.castSucc) + (fun i=>y i.castSucc) ⟨j.val,lt_trans j.isLt i.isLt⟩) := by + funext j + exact inverse_castSucc p y ⟨j.val,lt_trans j.isLt i.isLt⟩ + unfold forward + rw [inverse_castSucc] + exact (congrArg (fun f=>inverse (fun i : Fin n=>p i.castSucc) + (fun i=>y i.castSucc) i + eval₂ (algebraMap ℚ ℝ) f (p i.castSucc)) hfun).trans h + +lemma forward_injective {n : ℕ} (p : (i : Fin n) → MvPolynomial (Fin i.val) ℚ) : + Function.Injective (forward p) := by + intro x y h + have H : ∀ k,∀ hk : k + intro hk + have hh:=congrFun h ⟨k,hk⟩ + have he : (fun j : Fin k=>x ⟨j.val,lt_trans j.isLt hk⟩)= + (fun j : Fin k=>y ⟨j.val,lt_trans j.isLt hk⟩) := funext fun j=>ih j.val j.isLt _ + simp only [forward,he] at hh + exact add_right_cancel hh + funext i + exact H i.val i.isLt + +lemma inverse_forward {n : ℕ} (p : (i : Fin n) → MvPolynomial (Fin i.val) ℚ) + (x : Fin n → ℝ) : inverse p (forward p x)=x := + forward_injective p (forward_inverse p (forward p x)) + +lemma forward_polynomial {n : ℕ} (p : (i : Fin n) → MvPolynomial (Fin i.val) ℚ) + (i : Fin n) : RationalPolynomialMap.IsPolynomial (fun x=>forward p x i) := by + apply RationalPolynomialMap.add (RationalPolynomialMap.coordinate i) + exact RationalPolynomialMap.eval (fun j=>RationalPolynomialMap.coordinate _) (p i) + +lemma inverse_polynomial {n : ℕ} (p : (i : Fin n) → MvPolynomial (Fin i.val) ℚ) + (i : Fin n) : RationalPolynomialMap.IsPolynomial (fun x=>inverse p x i) := by + induction n with + | zero => exact Fin.elim0 i + | succ n ih => + refine Fin.lastCases ?_ (fun i=>?_) i + · have hx (j : Fin n) : RationalPolynomialMap.IsPolynomial + (fun y : Fin (n+1) → ℝ=>inverse (fun i : Fin n=>p i.castSucc) (fun i=>y i.castSucc) j) := + RationalPolynomialMap.comp (ih _ j) (fun i=>RationalPolynomialMap.coordinate i.castSucc) + simpa only [inverse_last] using RationalPolynomialMap.sub + (RationalPolynomialMap.coordinate (Fin.last n)) (RationalPolynomialMap.eval hx (p (Fin.last n))) + · simpa only [inverse_castSucc] using RationalPolynomialMap.comp + (ih (fun i : Fin n=>p i.castSucc) i) (fun i : Fin n=>RationalPolynomialMap.coordinate i.castSucc) + +lemma polynomial_continuous {σ : Type*} {f : (σ → ℝ) → ℝ} + (hf : RationalPolynomialMap.IsPolynomial f) : Continuous f := by + obtain ⟨p,hp⟩:=hf + have h:=MvPolynomial.continuous_eval (MvPolynomial.map (algebraMap ℚ ℝ) p) + simpa only [MvPolynomial.eval_map, ← hp] using h + +def homeomorph {n : ℕ} (p : (i : Fin n) → MvPolynomial (Fin i.val) ℚ) : + (Fin n → ℝ) ≃ₜ (Fin n → ℝ) where + toFun:=forward p + invFun:=inverse p + left_inv:=inverse_forward p + right_inv:=forward_inverse p + continuous_toFun:=continuous_pi (fun i=>polynomial_continuous (forward_polynomial p i)) + continuous_invFun:=continuous_pi (fun i=>polynomial_continuous (inverse_polynomial p i)) + +end RationalTriangularChange + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RawHarmonic01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RawHarmonic01.lean new file mode 100644 index 0000000000000000000000000000000000000000..c7219c1e570da8abcd60a29ec4616cfca60bb5b4 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RawHarmonic01.lean @@ -0,0 +1,295 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.DyadicHarmonic01 +import OAI.Combinatorics.SumProduct.Alignment.MicrocellScale01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section RawSuccessInlineScope9 +noncomputable section +open scoped BigOperators +open Finset +namespace DyadicHarmonicBoundary +open UnitIntervalCounts MicrocellBoundary + +theorem raw_bad_bound (X W t H R:ℕ) (hW:0(t n:ℝ)*R n/H n) atTop (𝓝 0)) + (hXR:Tendsto (fun n=>(R n:ℝ)/X n) atTop (𝓝 0)) : + Tendsto (fun n=>badMass (X n) ((X n)^2) (W n) (t n) (H n) (R n) / + mass (X n) ((X n)^2) (W n)) atTop (𝓝 0) := by + have hh:Tendsto (fun n=>504*((t n:ℝ)*R n/H n)+336*((R n:ℝ)/X n)) atTop (𝓝 0) := by + simpa only [mul_zero,zero_add] using (hHR.const_mul 504).add (hXR.const_mul 336) + apply squeeze_zero' (Filter.Eventually.of_forall (fun n=>div_nonneg + (badMass_nonneg _ _ _ _ _ _) (mass_nonneg _ _ _))) ?_ hh + filter_upwards [hscale] with n hn + convert raw_bad_bound_simple (X n) (W n) (t n) (H n) (R n) hn.1 hn.2.1 hn.2.2.1 + hn.2.2.2.1 hn.2.2.2.2.1 hn.2.2.2.2.2 using 1 + ring + +end DyadicHarmonicBoundary +end +end RawSuccessInlineScope9 + + + + + +section RawSuccessInlineScope10 +noncomputable section +open Filter Topology +namespace AdmissibleMicrocellBoundary +open MicrocellScale DyadicHarmonicBoundary + + +def earlierScale (M P:ℕ→ℕ) (n:ℕ) : ℝ := 2 + (M n:ℝ) + P n + +lemma scale_one (M P:ℕ→ℕ) (n:ℕ) : 1≤earlierScale M P n := by + unfold earlierScale + have hM := Nat.cast_nonneg (α:=ℝ) (M n) + have hP := Nat.cast_nonneg (α:=ℝ) (P n) + linarith + +lemma radius_four_modulus {M P H W:ℕ→ℕ} + (hM:∀ᶠ n in atTop,0(H n:ℝ)) (earlierScale M P)) : + ∀ᶠ n in atTop,4*W n≤radius (M n) (H n) := by + have hh:=radius_dominates + (by filter_upwards [hM] with n hn + exact ⟨hn.1,by unfold earlierScale; linarith [Nat.cast_nonneg (α:=ℝ) (P n)]⟩) + (Filter.Eventually.of_forall (scale_one M P)) hd 1 (by norm_num) + filter_upwards [hM,hh.eventually_ge_atTop 4] with n hm hn + rw [Real.rpow_one] at hn + have hs:0(H n:ℝ)) (earlierScale M P)) + (hx:Dominates (fun n=>Real.log (X n:ℝ)) (fun n=>(H n:ℝ))) : + Tendsto (fun n=>(P n:ℝ)^2*(K*radius (M n) (H n):ℕ)/H n) atTop (𝓝 0) ∧ + Tendsto (fun n=>(K*radius (M n) (H n):ℕ)/(X n:ℝ)) atTop (𝓝 0) := by + have hb:=boundary_rate (t:=fun n=>(P n)^2) hM + (Filter.Eventually.of_forall (scale_one M P)) + (Filter.Eventually.of_forall (fun n=>by + simp only [Nat.cast_pow] + have hp:(P n:ℝ)≤earlierScale M P n:=by unfold earlierScale; linarith [Nat.cast_nonneg (α:=ℝ) (M n)] + exact pow_le_pow_left₀ (by positivity) hp 2)) hd + have he:=endpoint_rate hM hH (by simpa only [Real.rpow_one] using hx 1 (by norm_num)) + constructor + · convert hb.const_mul (K:ℝ) using 1 <;> simp only [Nat.cast_pow,Nat.cast_mul,mul_zero] + try (funext n; ring) + · convert he.const_mul (K:ℝ) using 1 <;> simp only [Nat.cast_mul,mul_zero] + try (funext n; ring) + + + +theorem uniform_raw_boundary {M P H X W:ℕ→ℕ} (K:ℕ) (hK:0(H n:ℝ)) (earlierScale M P)) + (hx:Dominates (fun n=>Real.log (X n:ℝ)) (fun n=>(H n:ℝ))) : + ∃ ε:ℕ→ℝ,Tendsto ε atTop (𝓝 0) ∧ + ∀ᶠ n in atTop,∀ t:ℕ,0K*radius (M n) (H n) + have hM:∀ᶠ n in atTop,0h.2.1) + have hH:∀ᶠ n in atTop,0h.2.2.2.1) + obtain ⟨hb,he⟩:=enlarged_rates K hM hH hd hx + have hr:∀ᶠ n in atTop,R n≤X n := by + filter_upwards [hbase,he.eventually_lt_const (show (0:ℝ)<1 by norm_num)] with n hn hne + have hxp:(0:ℝ)⟨h.2.1,h.2.2.1⟩)) hd + filter_upwards [hfour] with n hn + exact hn.trans (Nat.le_mul_of_pos_left _ hK) + let ε:ℕ→ℝ:=fun n=>504*((P n:ℝ)^2*R n/H n)+336*((R n:ℝ)/X n) + refine ⟨ε,?_,?_⟩ + · simpa only [ε,mul_zero,zero_add] using (hb.const_mul 504).add (he.const_mul 336) + · filter_upwards [hbase,hr,hw] with n hn hrn hwn + intro t ht htp + have hwr:W n≤R n:=by omega + have hxt:4*W n≤X n:=hwn.trans hrn + have hb':=raw_bad_bound_simple (X n) (W n) t (H n) (R n) hn.1 hxt ht hn.2.2.2.1 hwr hrn + apply hb'.trans + dsimp only [ε] + have htp':(t:ℝ)≤(P n:ℝ)^2:=by exact_mod_cast htp + calc + _ = 504*((t:ℝ)*R n/H n)+336*((R n:ℝ)/X n) := by ring + _ ≤ _ := by gcongr + +end AdmissibleMicrocellBoundary +end +end RawSuccessInlineScope10 + + + + + +section RawSuccessInlineScope11 +noncomputable section +open Filter Topology MeasureTheory +open scoped BigOperators +namespace RawHarmonicProbability +attribute [local instance] Classical.propDecidable +open Finset DyadicHarmonicBoundary AdmissibleMicrocellBoundary MicrocellScale + + +def units (X W:ℕ) : Finset ℕ := (Ico X (X^2)).filter W.Coprime + +lemma mass_units (X W:ℕ) : mass X (X^2) W=∑ p∈units X W,(p:ℝ)⁻¹ := by + simp only [mass,units,sum_filter] + +lemma units_pos {X W:ℕ} (hX:0by positivity)).mp hh + exact ⟨p,hp⟩ + + + +def law (X W:ℕ) (hW:0(p.1:ℝ)⁻¹) + (fun p=>inv_pos.mpr (units_pos (by omega) p)) Subtype.val + +lemma law_apply (X W:ℕ) (hW:0(p:ℝ)⁻¹),←mass_units] + rw [hr] + rw [sum_coe_sort (units X W) (fun p:ℕ=>(p:ℝ)⁻¹ / mass X (X^2) W * (if p∈A then 1 else 0))] + rw [units,sum_filter] + rw [sum_div] + apply sum_congr rfl + intro p hp + split_ifs <;> simp_all + +lemma boundary_law (X W t H R:ℕ) (hW:0 rfl + + + +theorem finite_boundary_bound {J:Type*} [Fintype J] + (X W H R:ℕ) (hW:0by rw [boundary_law]; exact hb j) + _ = _ := by simp + + + +theorem admissible_finite_boundary {J:Type*} [Fintype J] + {M P H X W:ℕ→ℕ} (K:ℕ) (hK:0(H n:ℝ)) (earlierScale M P)) + (hx:Dominates (fun n=>Real.log (X n:ℝ)) (fun n=>(H n:ℝ))) : + ∃ ε:ℕ→ℝ,Tendsto ε atTop (𝓝 0) ∧ + ∀ᶠ n in atTop,∃ (hw:0⟨h.2.1,h.2.2.1⟩)) hd + have hm:∀ᶠ n in atTop,0h.2.1) + have hh:∀ᶠ n in atTop,0h.2.2.2.1) + have hr:=endpoint_rate hm hh (by simpa only [Real.rpow_one] using hx 1 (by norm_num)) + refine ⟨fun n=>(Fintype.card J:ℝ)*ε n,?_,?_⟩ + · simpa only [mul_zero] using he.const_mul (Fintype.card J:ℝ) + · filter_upwards [hbase,hb,hf,hr.eventually_lt_const (show (0:ℝ)<1 by norm_num)] with n hn hb hf hr + have hxp:(0:ℝ)?_⟩ + exact finite_boundary_bound _ _ _ _ _ _ t _ (fun j=>hb (t j) (ht j).1 (ht j).2) + +end RawHarmonicProbability + +end +end RawSuccessInlineScope11 +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RawMenu.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RawMenu.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9736ffb8ad915b973660512d8045ecc7ea38504 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RawMenu.lean @@ -0,0 +1,276 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MenuLiteral01 +import OAI.Geometry.NilpotentCharts.FilteredBasis +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +noncomputable section +open Filter MeasureTheory +open scoped BigOperators ENNReal Topology +noncomputable section +open scoped BigOperators Topology BoundedContinuousFunction +noncomputable section +open scoped BigOperators +open MeasureTheory Filter Function +noncomputable section +open scoped BigOperators +noncomputable section +open Filter MeasureTheory +open scoped Topology BoundedContinuousFunction NNReal +noncomputable section +open scoped Topology BigOperators +noncomputable section +open scoped Topology BigOperators commutatorElement +noncomputable section +open scoped Topology BoundedContinuousFunction NNReal +noncomputable section +open scoped BigOperators +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal +noncomputable section +open scoped Topology BigOperators +noncomputable section +open scoped Topology BoundedContinuousFunction NNReal BigOperators +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal +noncomputable section +open Filter MeasureTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal +noncomputable section +open scoped Manifold ContDiff Topology +open Function Set Manifold +noncomputable section +open Function Set Topology +noncomputable section +open Set Function Topology +open scoped Topology +noncomputable section +open Set Function Topology +open scoped Topology +noncomputable section +open Set Function Topology +open scoped Topology +noncomputable section +open Set Function Topology +open scoped Topology commutatorElement +noncomputable section +open Set Function Topology +open scoped Topology +noncomputable section +open Set Function Topology +noncomputable section +open Set Function Topology +open scoped Topology +noncomputable section +open Set Function +noncomputable section +open Set Function Topology Manifold +open scoped Manifold ContDiff Topology +noncomputable section +open Set Function Topology +open scoped Topology +noncomputable section +open Set Function Topology Manifold +open scoped Manifold ContDiff Topology +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +open scoped Manifold ContDiff Topology +open Function Set Manifold +open scoped BigOperators +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +open scoped BigOperators +noncomputable section +open scoped Manifold ContDiff Topology +open scoped Manifold ContDiff Topology +noncomputable section +open scoped commutatorElement +noncomputable section +open Filter Topology +noncomputable section +open Set Function Topology +open scoped Pointwise +noncomputable section +open Set Function Topology +open scoped commutatorElement Topology +namespace SourceRawMenu +open MeasureTheory Filter SourceAdmissible SourceBlocks SourceMenuAlignment +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales +open scoped Manifold ContDiff Topology NNReal BoundedContinuousFunction + + + +structure Menu (s : ℕ) where + size : ℕ + dimension : Fin size → ℕ + G : Fin size → Type + [group : ∀ i, Group (G i)] + [topology : ∀ i, TopologicalSpace (G i)] + [charted : ∀ i, ChartedSpace (EuclideanSpace ℝ (Fin (dimension i))) (G i)] + [lie : ∀ i, LieGroup 𝓘(ℝ, EuclideanSpace ℝ (Fin (dimension i))) ∞ (G i)] + [hausdorff : ∀ i, T2Space (G i)] + [secondCountable : ∀ i, SecondCountableTopology (G i)] + [connected : ∀ i, ConnectedSpace (G i)] + [simplyConnected : ∀ i, SimplyConnectedSpace (G i)] + Γ : ∀ i, Subgroup (G i) + [discrete : ∀ i, DiscreteTopology (Γ i)] + [cocompact : ∀ i, CompactSpace (G i ⧸ Γ i)] + nilpotent : ∀ i, (⊤ : Subgroup (G i)).lowerCentralSeries s = ⊥ + metric : ∀ i, MetricSpace (G i ⧸ Γ i) + compatible : ∀ i, QuotientGroup.instTopologicalSpace (Γ i) = + (metric i).toUniformSpace.toTopologicalSpace + +attribute [instance] Menu.group Menu.topology Menu.charted Menu.lie Menu.hausdorff + Menu.secondCountable Menu.connected Menu.simplyConnected Menu.discrete Menu.cocompact + + + +structure CosetPiece {s : ℕ} (F : Menu s) (K : ℝ≥0) where + index : Fin F.size + g : F.G index + x : F.G index ⧸ F.Γ index + obs : (F.G index ⧸ F.Γ index) →ᵇ ℝ + lip : letI : MetricSpace (F.G index ⧸ F.Γ index) := + (F.metric index).replaceTopology (F.compatible index) + LipschitzWith K obs + range : ∀ z, obs z ∈ Set.Icc (0:ℝ) 1 + +variable {s a r : ℕ} +def CosetPiece.eval {F : Menu s} {K : ℝ≥0} (P : CosetPiece F K) (k : ℤ) : ℝ := + P.obs (P.g^k • P.x) + + + +structure ModelsSystem (A : Parameters a) (vs : Finset ℚ) (r : ℕ) (F : Menu s) where + model : ℕ → Models a r + K : ℝ≥0 + piece : ℕ → Block a → ∀ (v : ℚ), v ∈ vs → + Fin r → ℤ → ℤ → CosetPiece F K + represents : ∀ N B v hv c k, + model N B v c k = + (piece N B v hv c (k/(A.H N B.1 : ℤ)) (k%(A.M N : ℤ))).eval + ((k-k%(A.M N : ℤ))/(A.M N : ℤ)) + + + +def Alignment : Prop := + ∀ a r s : ℕ, ∃ (bs : Finset (Scale a)) (vs : Finset ℚ) (δ : ℝ), + 0 < δ ∧ + (∀ b ∈ bs, ∀ j, 0 < b j) ∧ (∀ v ∈ vs, 0 < v) ∧ + (∀ b ∈ bs, ∀ B : Block a, blockProduct b B.set ∈ vs) ∧ + ∀ (A : Parameters a) (F : Menu s) (S : ModelsSystem A vs r F) + (μ : ℕ → Measure (Fin a → ℕ)), + (∀ N (hX : ∀ i, 4*primorial (N+1) ≤ A.X N i), μ N = A.law N hX) → + ∀ τ : ℝ, 0 < τ → + δ ≤ Filter.liminf (fun N => (μ N).real (event bs (S.model N) (A.ht N) τ)) atTop +end SourceRawMenu +namespace SourceRawMenu +open scoped Manifold ContDiff Topology NNReal BoundedContinuousFunction +variable {s : ℕ} + + + +def Menu.toCharted (F : Menu s) : SourceChartedMenu.Menu s where + size := F.size + G := F.G + Γ := F.Γ + topGroup := fun i => topologicalGroup_of_lieGroup 𝓘(ℝ, EuclideanSpace ℝ (Fin (F.dimension i))) ∞ + chart i := Classical.choice (SourceRawChartGap.rawChartExists s (F.dimension i) (F.G i) (F.Γ i) (F.nilpotent i)) + metric := F.metric + compatible := F.compatible + +variable {F : Menu s} {K : ℝ≥0} +def CosetPiece.toCharted (P : CosetPiece F K) : SourceMenuLiteral.CosetPiece F.toCharted K where + index := P.index + g := P.g + x := P.x + obs := P.obs + lip := P.lip + range := P.range + +@[simp] lemma CosetPiece.toCharted_eval (P : CosetPiece F K) (k : ℤ) : + P.toCharted.eval k = P.eval k := rfl +end SourceRawMenu + +namespace SourceRawMenu +open MeasureTheory Filter SourceAdmissible SourceBlocks SourceMenuAlignment +open ConstructedWordPlan.GlobalWordPlan ConstructedWordPlan.AlignmentScales +variable {a r s : ℕ} {A : Parameters a} {vs : Finset ℚ} {F : Menu s} + + + +def ModelsSystem.toCharted (S : ModelsSystem A vs r F) : + SourceMenuLiteral.ModelsSystem A vs r F.toCharted where + model := S.model + K := S.K + piece N B v hv c j l := (S.piece N B v hv c j l).toCharted + represents := S.represents + + + +theorem alignment : Alignment := by + intro a r s + obtain ⟨bs,vs,δ,hδ,hb,hv,hcl,h⟩ := SourceMenuLiteral.charted_finite_menu_alignment a r s + refine ⟨bs,vs,δ,hδ,hb,hv,hcl,?_⟩ + intro A F S μ hμ τ hτ + exact h A F.toCharted S.toCharted μ hμ τ hτ +end SourceRawMenu + +theorem raw_alignment_reference : SourceRawMenu.Alignment := SourceRawMenu.alignment + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RegularResidue01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RegularResidue01.lean new file mode 100644 index 0000000000000000000000000000000000000000..d98a4e978f66adc7efdae0caa7f729b40afc83e4 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RegularResidue01.lean @@ -0,0 +1,289 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.FinitePiece01 +import OAI.Combinatorics.SumProduct.Alignment.PolynomialLine01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +namespace RegularBoxPartition + +def left (lo hi : ℝ) (M : ℕ) (k : Fin M) : ℝ:=lo+(hi-lo)*k/M +def right (lo hi : ℝ) (M : ℕ) (k : Fin M) : ℝ:=lo+(hi-lo)*(k+1)/M + +lemma normalized (lo hi x : ℝ) (hL : loone_dimensional (lo i) (hi i) (x i) (hL i) M hM (hx i) + choose k hk hu using hh + refine ⟨k,hk,?_⟩ + intro j hj + funext i + exact hu i (j i) (hj i) + + + +theorem fine_partition (C lam : ℝ) (hlam : 0⟨0,hM⟩ + +omit [DecidableEq ι] in +lemma cell_eq_iff (lo hi : ι → ℝ) (hL : ∀ i,lo ih ▸ hs.1,fun h=>(hs.2 b h).symm⟩ + +def label (lo hi : ι → ℝ) (hL : ∀ i,lo i(a i:ℝ)+q*x i),fun i=>((a i+(q:ℤ)*x i:ℤ):ZMod K)) + +lemma label_correct (lo hi : ι → ℝ) (hL : ∀ i,lo i(a i:ℝ)) q) (b : ι → Fin M) (u : ι → ZMod K) : + label lo hi hL M hM a q K x=(b,u) ↔ + (∀ i,left (lo i) (hi i) M (b i)≤(a i:ℝ)+q*x i ∧ + (a i:ℝ)+q*x iresidue_parameter q K hh (a i) (u i).val + exact ⟨j,hj⟩ + +lemma fiber_eq (lo hi : ι → ℝ) (hL : ∀ i,lo i(a i:ℝ)) q) (label lo hi hL M hM a q K) (b,u)= + refinedSet (fun i=>left (lo i) (hi i) M (b i)) + (fun i=>right (lo i) (hi i) M (b i)) (fun i=>(a i:ℝ)) q j K := by + have hqr : 0<(q:ℝ):=by exact_mod_cast hq + ext x + rw [fiber,Finset.mem_filter,mem_refinedSet _ _ _ _ hqr _ _ hK] + constructor + · rintro ⟨hx,he⟩ + obtain ⟨hb,hu⟩:=(label_correct lo hi hL M hM a q K hq x hx b u).mp he + intro i + refine ⟨hb i,(hj i (x i)).mp ?_⟩ + apply (ZMod.intCast_eq_intCast_iff _ _ _).mp + simpa only [Int.cast_natCast,ZMod.natCast_zmod_val] using hu i + · intro hx + have hpar : x∈boxIndices lo hi (fun i=>(a i:ℝ)) q:=by + rw [mem_boxIndices _ _ _ _ hqr] + intro i + have he:=endpoints (lo i) (hi i) (hL i) M hM (b i) + exact ⟨he.1.trans (hx i).1.1,(hx i).1.2.trans_le he.2.2.1⟩ + refine ⟨hpar,(label_correct lo hi hL M hM a q K hq x hpar b u).mpr ⟨?_,?_⟩⟩ + · exact fun i=>(hx i).1 + · intro i + have hh:=(ZMod.intCast_eq_intCast_iff _ _ _).mpr ((hj i (x i)).mpr (hx i).2) + simpa only [Int.cast_natCast,ZMod.natCast_zmod_val] using hh + +lemma weight_eq (lo hi : ι → ℝ) (hL : ∀ i,lo i(a i:ℝ)) q) (label lo hi hL M hM a q K) (b,u)= + refinedBoxWeight lo hi (fun i=>left (lo i) (hi i) M (b i)) + (fun i=>right (lo i) (hi i) M (b i)) (fun i=>(a i:ℝ)) q j K := by + rw [weight,fiber_eq lo hi hL M hM a q K hq hK b u j hj,refined_mass _ _ _ _ _ _ _ _ hK] + + + +theorem actual_weight_error (lo hi : ι → ℝ) (hL : ∀ i,lo i(a i:ℝ)) q) (label lo hi hL M hM a q K) z- + weight (boxIndices lo hi (fun i=>(b i:ℝ)) t) (label lo hi hL M hM b t K) z|)≤ + (Fintype.card ((ι → Fin M)×(ι → ZMod K)):ℝ)* + ((∑ i,8*(q:ℝ)/(hi i-lo i))+(∑ i,8*(t:ℝ)/(hi i-lo i))) := by + choose ja hja using fun u : ι → ZMod K=>exists_parameters a q K hqK u + choose jb hjb using fun u : ι → ZMod K=>exists_parameters b t K htK u + have hqr : 0<(q:ℝ):=by exact_mod_cast hq + have htr : 0<(t:ℝ):=by exact_mod_cast ht + calc + _≤∑ _z:(ι → Fin M)×(ι → ZMod K), + ((∑ i,8*(q:ℝ)/(hi i-lo i))+(∑ i,8*(t:ℝ)/(hi i-lo i))):=by + apply Finset.sum_le_sum + rintro ⟨v,u⟩ _ + rw [weight_eq lo hi hL M hM a q K hq hK v u (ja u) (hja u), + weight_eq lo hi hL M hM b t K ht hK v u (jb u) (hjb u)] + exact compare_refined_box_weights lo hi + (fun i=>left (lo i) (hi i) M (v i)) + (fun i=>right (lo i) (hi i) M (v i)) + (fun i=>(a i:ℝ)) (fun i=>(b i:ℝ)) q t hqr htr + (fun i=>(endpoints (lo i) (hi i) (hL i) M hM (v i)).1) + (fun i=>(endpoints (lo i) (hi i) (hL i) M hM (v i)).2.1.le) + (fun i=>(endpoints (lo i) (hi i) (hL i) M hM (v i)).2.2.1) + hsq hst (ja u) (jb u) K hK + _=_:=by simp [mul_add] + + + +theorem select_common_piece (lo hi : ι → ℝ) (hL : ∀ i,lo i(b i:ℝ)) t,‖g x‖≤B) + (η ε : ℝ) + (hd : η≤‖mean (boxIndices lo hi (fun i=>(a i:ℝ)) q) f- + mean (boxIndices lo hi (fun i=>(b i:ℝ)) t) g‖) + (he : B*((Fintype.card ((ι → Fin M)×(ι → ZMod K)):ℝ)* + ((∑ i,8*(q:ℝ)/(hi i-lo i))+(∑ i,8*(t:ℝ)/(hi i-lo i))))≤ε) : + ∃ z:(ι → Fin M)×(ι → ZMod K), + (fiber (boxIndices lo hi (fun i=>(a i:ℝ)) q) (label lo hi hL M hM a q K) z).Nonempty ∧ + η-ε≤‖mean (fiber (boxIndices lo hi (fun i=>(a i:ℝ)) q) (label lo hi hL M hM a q K) z) f- + mean (fiber (boxIndices lo hi (fun i=>(b i:ℝ)) t) (label lo hi hL M hM b t K) z) g‖ := by + have hqr : 0<(q:ℝ):=by exact_mod_cast hq + apply FinitePieceAverages.select _ _ (box_nonempty lo hi _ q hqr hsq) + (label lo hi hL M hM a q K) (label lo hi hL M hM b t K) f g B hB hg η ε hd + exact (mul_le_mul_of_nonneg_left + (actual_weight_error lo hi hL M hM a b q t K hq ht hK hqK htK hsq hst) hB).trans he + +end RegularResiduePieces + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/ResidueAlignment01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/ResidueAlignment01.lean new file mode 100644 index 0000000000000000000000000000000000000000..dc5e8221719e020dbe2a050eff400511b727c9ab --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/ResidueAlignment01.lean @@ -0,0 +1,287 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.IntegerAlignment01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +noncomputable section +namespace SourceResidueAlignment +open ProductExposureLabels +open scoped BigOperators + + + +def residue (L t q : ℤ) : ℤ := + if h : 0(coprime_smooth_rough hLs ((rough_iff_coprime _ _).mpr (hr j))).symm) + have hres:=residue_spec L (∏ j,b.residue j) q hL hcop + change 0≤residueData L q b ∧ residueData L q ble_trans + (le_of_lt (pow_pos (by norm_num : (0:ℝ)<2) _)) (htt j).1 + have htu : (∏ j,(t j:ℝ))≤∏ j,(X j:ℝ)^2 := + Finset.prod_le_prod₀ (fun j _=>htt0 j) (fun j _=>(htt j).2.1.le.trans (hX j)) + have ht0 : (0:ℝ)≤∏ j,(t j:ℝ) := Finset.prod_nonneg (fun j _=>htt0 j) + have hr0 : (0:ℝ)≤(residueData L q b:ℝ) := by exact_mod_cast hres.1 + have hrL : (residueData L q b:ℝ)≤(L:ℝ) := by exact_mod_cast hres.2.1.le + have hmul : (∏ j,(t j:ℝ))*(residueData L q b:ℝ)≤(∏ j,(X j:ℝ)^2)*(L:ℝ) := + mul_le_mul htu hrL hr0 (Finset.prod_nonneg (fun j _=>sq_nonneg _)) + have hab := abs_sub (q:ℝ) ((∏ j,(t j:ℝ))*(residueData L q b:ℝ)) + rw [abs_of_nonneg (mul_nonneg ht0 hr0)] at hab + have hka := congrArg abs hkR + rw [abs_mul,abs_of_pos hMr] at hka + apply (le_div_iff₀ hMr).mpr + nlinarith + +end SourceResidueAlignment +end + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift RoughTopologicalFace RoughArrayCoordinates SourceResidueAlignment +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory Filter +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jX N j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ N,0R N/(Xp N:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R N/(M N:ℝ))/ + (1+∑ j,(X N j:ℝ)^2)^a) atTop atTop) + (hQ0 : ∀ N,0≤Q N) + (hSize : Tendsto (fun N=>(Q N+(∏ l : Fin m,(X N l:ℝ)^2)*(L N:ℝ))/R N) atTop (𝓝 0)) + (hWM : ∀ N,(primorial (w0 N):ℤ)∣(M N:ℤ)) + (hM : ∀ N,0(X N j:ℝ)/(L N:ℝ)) atTop atTop) + (pattern : ι→Fin (v+1)→ℤ) (e : Fin q) (j : Fin (v+1)) + (g x : ℕ→Label m→∀ i,G i) (b0 b1 : ℕ→Label m→ι→ℝ) + (qval : ℕ→Label m→Fin q→ℤ) + (hQ : ∀ N b,b∈(fullDomain (X N) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) →∀ k,|(qval N b k:ℝ)|≤Q N) : + Tendsto (fun N=>(jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) + (hX N) (hXp N)).real (rawPhysicalEvent (lattice G n q c hsk A w hA Γ) m v c₀ C₀ B η (R N) d (M N) (L N) + (fun b=>actualData G n q c hsk A w hA hw Γ pattern (g N b) (x N b) + (b0 N b) (b1 N b) (fun k=>(qval N b k:ℝ)/(M N:ℝ)) + (fun k=>-(residueData (L N) (qval N b k) b:ℝ)/(M N:ℝ)) e j (coarseOrigin v (M N) (R N) b) (shift (M N) (L N) (qval N b e) b)))) + atTop (𝓝 0) + := by + let H : ℕ→ℝ:=fun N=>(Q N+(∏ l : Fin m,(X N l:ℝ)^2)*(L N:ℝ))/(M N:ℝ) + have hH : ∀ N,0≤H N := by + intro N + dsimp [H] + apply div_nonneg + · apply add_nonneg (hQ0 N) + exact mul_nonneg (Finset.prod_nonneg (fun l _=>sq_nonneg _)) (by exact_mod_cast (hL N).le) + · positivity + have hHZ : Tendsto (fun N=>H N/(R N/(M N:ℝ))) atTop (𝓝 0) := by + apply hSize.congr' + filter_upwards [] with N + dsimp [H] + field_simp [show (M N:ℝ)≠0 by exact_mod_cast (Nat.ne_of_gt (hM N)),(hR N).ne'] + let a0 : ℕ→Label m→Fin q→ℝ := fun N b k=>if d≤w0 N then (qval N b k:ℝ)/(M N:ℝ) else 0 + let a1 : ℕ→Label m→Fin q→ℝ := fun N b k=>if d≤w0 N then -(residueData (L N) (qval N b k) b:ℝ)/(M N:ℝ) else 0 + let δ : ℕ→Label m→(Fin m→ℤ)→ℤ := fun N b t=>if d≤w0 N then shift (M N) (L N) (qval N b e) b t else 0 + have hδ : ∀ N b,b∈(fullDomain (X N) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) → Good (X N) (Xp N) (R N) b → + ∀ t∈productTimes b.scales b.residue (L N), + (δ N b t:ℝ)=a0 N b e+a1 N b e*∏ l,(t l:ℝ) ∧ + (d:ℤ)∣δ N b t ∧ |(δ N b t:ℝ)|≤H N := by + intro N b hb hg t ht + by_cases hn:d≤w0 N + · simp only [a0,a1,δ,ite_eq_left hn] + have hr:=image_residues (X N) (Xp N) (primorial (w0 N)) (L N) (M N:ℤ) (R N) + (hL N) (by exact_mod_cast hM N) (hWL N) (hWM N) b hb + exact shift_spec (w0 N) (M N) d (hM N) hd hn (L N) (hL N) (hLexact N) + (hsm N) b hr.2.2.1 (X N) (fun l=>(hg.1 l).2) (qval N b e) (Q N) (hQ N b hb e) t ht + · simp only [a0,a1,δ,ite_eq_right hn,Int.cast_zero,zero_mul,add_zero,abs_zero] + exact ⟨True.intro,dvd_zero _,hH N⟩ + have hh:=source_raw_physical_array_own_face_decay G n q c hsk A w hA hw Γ hΓ htop + m v d hd c₀ C₀ B η hc₀ hC₀ hB hη w0 M Xp X R H L hw0 hX hXp hXt hXpt + hR hRX hZ hH hHZ hWM hM hMs hL hsm hWL hML hXL pattern e j g x b0 b1 a0 a1 δ hδ + apply hh.congr' + filter_upwards [hw0.eventually (eventually_ge_atTop d)] with N hn + simp only [a0,a1,δ,ite_eq_left hn] + +end RoughArrayFace +end + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift RoughTopologicalFace RoughArrayCoordinates SourceResidueAlignment +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory Filter +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jX N j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ N,0R N/(Xp N:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R N/(M N:ℝ))/ + (1+∑ j,(X N j:ℝ)^2)^a) atTop atTop) + (hQ0 : ∀ N,0≤Q N) + (hSize : Tendsto (fun N=>(Q N+(∏ l : Fin m,(X N l:ℝ)^2)*(L N:ℝ))/R N) atTop (𝓝 0)) + (hWM : ∀ N,(primorial (w0 N):ℤ)∣(M N:ℤ)) + (hM : ∀ N,0(X N j:ℝ)/(L N:ℝ)) atTop atTop) + (pattern : ι→Fin (v+1)→ℤ) (e : Fin q) (j : Fin (v+1)) + (κ : ℕ→Type) [∀ N,Fintype (κ N)] + (p : ∀ N,κ N→ℝ) (hp : ∀ N y,0≤p N y) (hmass : ∀ N,∑ y,p N y=1) + (g x : ∀ N,κ N→Label m→∀ i,G i) (b0 b1 : ∀ N,κ N→Label m→ι→ℝ) + (qval : ∀ N,κ N→Label m→Fin q→ℤ) + (hQ : ∀ N y b,b∈(fullDomain (X N) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) →∀ k,|(qval N y b k:ℝ)|≤Q N) : + Tendsto (fun N=>∑ y,p N y * (jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) + (hX N) (hXp N)).real (rawPhysicalEvent (lattice G n q c hsk A w hA Γ) m v c₀ C₀ B η (R N) d (M N) (L N) + (fun b=>actualData G n q c hsk A w hA hw Γ pattern (g N y b) (x N y b) + (b0 N y b) (b1 N y b) (fun k=>(qval N y b k:ℝ)/(M N:ℝ)) + (fun k=>-(residueData (L N) (qval N y b k) b:ℝ)/(M N:ℝ)) e j (coarseOrigin v (M N) (R N) b) (shift (M N) (L N) (qval N y b e) b)))) + atTop (𝓝 0) := by + classical + let mass (N : ℕ) (y : κ N) : ℝ := + (jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) (hX N) (hXp N)).real + (rawPhysicalEvent (lattice G n q c hsk A w hA Γ) m v c₀ C₀ B η (R N) d (M N) (L N) + (fun b=>actualData G n q c hsk A w hA hw Γ pattern (g N y b) (x N y b) + (b0 N y b) (b1 N y b) (fun k=>(qval N y b k:ℝ)/(M N:ℝ)) + (fun k=>-(residueData (L N) (qval N y b k) b:ℝ)/(M N:ℝ)) e j + (coarseOrigin v (M N) (R N) b) (shift (M N) (L N) (qval N y b e) b))) + have hne (N : ℕ) : (Finset.univ : Finset (κ N)).Nonempty := by + by_contra hn + have he := Finset.not_nonempty_iff_eq_empty.mp hn + have hh := hmass N + rw [he,Finset.sum_empty] at hh + norm_num at hh + have hmax (N : ℕ) : ∃ y : κ N,∀ z : κ N,mass N z≤ mass N y := by + obtain ⟨y,hy,hm⟩ := Finset.exists_max_image Finset.univ (mass N) (hne N) + exact ⟨y,fun z=>hm z (Finset.mem_univ _)⟩ + choose y hy using hmax + have hh := source_residue_physical_array_face_decay G n q c hsk A w hA hw Γ hΓ htop + m v d hd c₀ C₀ B η hc₀ hC₀ hB hη w0 M Xp X R Q L hw0 hX hXp hXt hXpt + hR hRX hZ hQ0 hSize hWM hM hMs hL hsm hWL hML hLexact hXL pattern e j + (fun N=>g N (y N)) (fun N=>x N (y N)) + (fun N=>b0 N (y N)) (fun N=>b1 N (y N)) (fun N=>qval N (y N)) + (fun N=>hQ N (y N)) + change Tendsto (fun N=>mass N (y N)) atTop (𝓝 0) at hh + change Tendsto (fun N=>∑ z,p N z * mass N z) atTop (𝓝 0) + apply squeeze_zero' (Eventually.of_forall (fun N=>?_)) (Eventually.of_forall (fun N=>?_)) hh + · exact Finset.sum_nonneg (fun z _=>mul_nonneg (hp N z) (measureReal_nonneg)) + · calc + ∑ z,p N z * mass N z ≤ ∑ z,p N z * mass N (y N) := + Finset.sum_le_sum (fun z _=>mul_le_mul_of_nonneg_left (hy N z) (hp N z)) + _ = mass N (y N) := by rw [←Finset.sum_mul,hmass,one_mul] + +end RoughArrayFace + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray01.lean new file mode 100644 index 0000000000000000000000000000000000000000..fce9d1c9b0e8bd72f41421c4e6bc937459fbe771 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray01.lean @@ -0,0 +1,335 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice19 +import OAI.Combinatorics.SumProduct.Alignment.RoughKernel01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open scoped BigOperators +end + +end + +end + +section + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters +open scoped BigOperators +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i j∀ i,f i∈PolynomialArrays.lattice (c i) (hsk i) (A i) (w i) (hA i) (Γ i) + one_mem':=fun i=>(PolynomialArrays.lattice (c i) (hsk i) (A i) (w i) (hA i) (Γ i)).one_mem + mul_mem':=fun hf hg i=>(PolynomialArrays.lattice (c i) (hsk i) (A i) (w i) (hA i) (Γ i)).mul_mem (hf i) (hg i) + inv_mem':=fun hf i=>(PolynomialArrays.lattice (c i) (hsk i) (A i) (w i) (hA i) (Γ i)).inv_mem (hf i) + + + +def sourceState {m v : ℕ} (pattern : ι→Fin v→ℤ) (g x : ∀ i,G i) + (b0 b1 : ι→ℝ) (a0 a1 : Fin q→ℝ) (y : Fin (m+v)→ℝ) : + Carrier G n q c hsk A w hA := + fun i=>PolynomialArrays.sourceElement (c i) (hsk i) (A i) (w i) (hA i) (hw i) + (g i) (x i) + (b0 i+b1 i*(∏ k : Fin m,y (k.castAdd v))+∑ j,(pattern i j:ℝ)*y (j.natAdd m)) + (fun e=>a0 e+a1 e*(∏ k : Fin m,y (k.castAdd v))) + +def inputShift {v : ℕ} (pattern : ι→Fin v→ℤ) (e : Fin q) (j : Fin v) + (i : ι) : Fin q→ℤ := Pi.single e (pattern i j) + +def faceMap {v : ℕ} (pattern : ι→Fin v→ℤ) (e : Fin q) (j : Fin v) : + Carrier G n q c hsk A w hA →* Carrier G n q c hsk A w hA where + toFun f i:=PolynomialArrays.shift (c i) (hsk i) (A i) (w i) (hA i) + (fun k=>(inputShift q pattern e j i k:ℝ)) (f i) + map_one':=by funext i;exact map_one _ + map_mul' f g:=by funext i;exact map_mul _ _ _ + +omit [Fintype ι] in +lemma faceMap_continuous {v : ℕ} (pattern : ι→Fin v→ℤ) (e : Fin q) (j : Fin v) : + Continuous (faceMap G n q c hsk A w hA pattern e j) := + continuous_pi (fun i=>(PolynomialArrays.shift_continuous (c i) (hsk i) (A i) (w i) (hA i) _).comp + (continuous_apply i)) + +variable (Γ : ∀ i,Subgroup (G i)) + +def faceAction {v : ℕ} (pattern : ι→Fin v→ℤ) (e : Fin q) (j : Fin v) : + C((Carrier G n q c hsk A w hA)⧸lattice G n q c hsk A w hA Γ, + (Carrier G n q c hsk A w hA)⧸lattice G n q c hsk A w hA Γ) where + toFun:=Quotient.map (faceMap G n q c hsk A w hA pattern e j) (by + intro f g hfg + apply QuotientGroup.leftRel_apply.mpr + rw [← map_inv,← map_mul] + intro i + exact (PolynomialArrays.shift_lattice (c i) (hsk i) (A i) (w i) (hA i) (Γ i) + (inputShift q pattern e j i) _).mpr ((QuotientGroup.leftRel_apply.mp hfg) i)) + continuous_toFun:= + (QuotientGroup.isQuotientMap_mk _).continuous_iff.mpr + (QuotientGroup.continuous_mk.comp (faceMap_continuous G n q c hsk A w hA pattern e j)) + +end RoughArrayFace +end + +end + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters +open scoped BigOperators +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jy ⟨i,a⟩) + left_inv f:=by + funext i + exact (PolynomialArrays.coefficientHomeomorph (c i) (hsk i) (A i) (w i) (hA i)).symm_apply_apply (f i) + right_inv y:=by + funext a + exact congrFun ((PolynomialArrays.coefficientHomeomorph (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1)).apply_symm_apply + (fun k=>y ⟨a.1,k⟩)) a.2 + continuous_toFun:=continuous_pi (fun a=>(continuous_apply a.2).comp + ((PolynomialArrays.coefficients_continuous (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1)).comp + (continuous_apply a.1))) + continuous_invFun:=continuous_pi (fun i=>(PolynomialArrays.coefficientHomeomorph (c i) (hsk i) (A i) (w i) (hA i)).symm.continuous.comp + (continuous_pi (fun a=>continuous_apply (⟨i,a⟩ : Index n q w)))) + +def jointWeight (a : Index n q w) : ℕ:=w a.1 a.2.1 + +omit [Fintype ι] in +lemma coefficientsHomeomorph_one : coefficientsHomeomorph G n q c hsk A w hA 1=0 := by + funext a + exact congrFun (PolynomialArrays.coefficientHomeomorph_one (q:=q) (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1)) a.2 + +omit [Fintype ι] in +lemma joint_law (y : (Index n q w ⊕ Index n q w)→ℝ) (a : Index n q w) : + FiniteWeightedLawChart.law (coefficientsHomeomorph G n q c hsk A w hA) y a= + PolynomialArrays.multiply (c a.1) (w a.1) + (Sum.elim (fun b=>y (Sum.inl ⟨a.1,b⟩)) (fun b=>y (Sum.inr ⟨a.1,b⟩))) a.2 := by + change (PolynomialArrays.coefficientHomeomorph (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1)) + ((PolynomialArrays.coefficientHomeomorph (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1)).symm + (fun b=>y (Sum.inl ⟨a.1,b⟩)) * + (PolynomialArrays.coefficientHomeomorph (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1)).symm + (fun b=>y (Sum.inr ⟨a.1,b⟩))) a.2=_ + rw [PolynomialArrays.coefficientHomeomorph_mul] + simp only [Homeomorph.apply_symm_apply] + +omit [Fintype ι] in +lemma joint_law_polynomial (a : Index n q w) : RationalPolynomialMap.IsPolynomial + (fun y=>FiniteWeightedLawChart.law (coefficientsHomeomorph G n q c hsk A w hA) y a) := by + have hp:=RationalPolynomialMap.comp (PolynomialArrays.multiply_polynomial (c a.1) (w a.1) a.2) + (g:=fun y=>Sum.elim (fun b=>y (Sum.inl (⟨a.1,b⟩ : Index n q w))) + (fun b=>y (Sum.inr (⟨a.1,b⟩ : Index n q w)))) (by + intro j + cases j with + | inl j=>exact RationalPolynomialMap.coordinate _ + | inr j=>exact RationalPolynomialMap.coordinate _) + simpa only [joint_law] using hp + +omit [Fintype ι] in +lemma joint_law_weighted (a : Index n q w) : + IsWeighted (Sum.elim (jointWeight n q w) (jointWeight n q w)) (jointWeight n q w a) + (fun y=>FiniteWeightedLawChart.law (coefficientsHomeomorph G n q c hsk A w hA) y a) := by + have hp:=(PolynomialArrays.multiply_weighted (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1) a.2).comp + (g:=fun y=>Sum.elim (fun b=>y (Sum.inl (⟨a.1,b⟩ : Index n q w))) + (fun b=>y (Sum.inr (⟨a.1,b⟩ : Index n q w)))) (by + intro j + cases j with + | inl j=>exact IsWeighted.coordinate (Sum.elim (jointWeight n q w) (jointWeight n q w)) (Sum.inl ⟨a.1,j⟩) + | inr j=>exact IsWeighted.coordinate (Sum.elim (jointWeight n q w) (jointWeight n q w)) (Sum.inr ⟨a.1,j⟩)) + simpa only [joint_law,jointWeight,PolynomialArrays.weight] using hp + +def jointChart : RealCoordinates (Carrier G n q c hsk A w hA) (Fintype.card (Index n q w)) := + FiniteWeightedLawChart.chart (coefficientsHomeomorph G n q c hsk A w hA) + (coefficientsHomeomorph_one G n q c hsk A w hA) (jointWeight n q w) (fun a=>hw a.1 a.2.1) + (joint_law_polynomial G n q c hsk A w hA) (joint_law_weighted G n q c hsk A w hA) + +lemma jointChart_at (f : Carrier G n q c hsk A w hA) (a : Index n q w) : + (jointChart G n q c hsk A w hA hw).coord f ((SortedFiniteWeights.indexing (jointWeight n q w)).symm a)= + PolynomialArrays.coefficients (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1) (f a.1) a.2 := by + change (coefficientsHomeomorph G n q c hsk A w hA) f + (SortedFiniteWeights.indexing (jointWeight n q w) ((SortedFiniteWeights.indexing (jointWeight n q w)).symm a))=_ + rw [Equiv.apply_symm_apply] + rfl + +lemma jointChart_natpow (f : Carrier G n q c hsk A w hA) (b : ℕ) + (k : Fin (Fintype.card (Index n q w))) : + (jointChart G n q c hsk A w hA hw).coord (f^b) k= + (b:ℝ)*(jointChart G n q c hsk A w hA hw).coord f k := + PolynomialArrays.coefficients_natpow (c _) (hsk _) (A _) (w _) (hA _) (f _) b _ + +lemma jointChart_canonicalLog (f : Carrier G n q c hsk A w hA) : + canonicalLog (jointChart G n q c hsk A w hA hw) f= + (jointChart G n q c hsk A w hA hw).coord f := by + funext k + let e:=jointChart G n q c hsk A w hA hw + have hp : powerPolynomial e f k=Polynomial.X*Polynomial.C (e.coord f k) := by + apply Polynomial.eq_of_eval_nat_eq + intro b + simp only [powerPolynomial_nat,Polynomial.eval_mul,Polynomial.eval_X,Polynomial.eval_C] + exact jointChart_natpow G n q c hsk A w hA hw f b k + rw [canonicalLog,hp] + simp [e] + +variable (Γ : ∀ i,Subgroup (G i)) +lemma jointChart_grid (hΓ : ∀ i g,g∈Γ i ↔ ∀ j,∃ z : ℤ,(c i).coord g j=z) : + ∃ grid : ℕ,0hD i),?_⟩ + intro f hf i + apply hgrid i (f i) + intro k + let a : Index n q w:=⟨i,SortedFiniteWeights.indexing (PolynomialArrays.weight (w i)) k⟩ + obtain ⟨z,hz⟩:=hf ((SortedFiniteWeights.indexing (jointWeight n q w)).symm a) + rw [jointChart_at] at hz + obtain ⟨b,hb⟩:=Finset.dvd_prod_of_mem D (Finset.mem_univ i) + refine ⟨(b:ℤ)*z,?_⟩ + change PolynomialArrays.coefficients (c i) (hsk i) (A i) (w i) (hA i) (f i) + (SortedFiniteWeights.indexing (PolynomialArrays.weight (w i)) k)=_ + rw [show PolynomialArrays.coefficients (c i) (hsk i) (A i) (w i) (hA i) (f i) + (SortedFiniteWeights.indexing (PolynomialArrays.weight (w i)) k)=(∏ i,D i:ℕ)*z from hz,hb] + push_cast + ring + +end RoughArrayFace +end +noncomputable section +open scoped BigOperators +namespace RoughArrayFace +open RationalLattice MalcevCharacters WeightedPolynomial + +lemma oneWeight_degree {σ : Type*} {f : (σ→ℝ)→ℝ} {D : ℕ} + (hf : IsWeighted (fun _=>1) D f) : RealPolynomialDegree.HasDegree f D := by + obtain ⟨p,hp,he⟩:=hf + refine ⟨p,Finset.sup_le ?_,he⟩ + intro a ha + have H:=hp a (MvPolynomial.mem_support_iff.mp ha) + simpa only [Finsupp.weight_apply,smul_eq_mul,mul_one] using H + +lemma oneWeight_mul {σ : Type*} {f g : (σ→ℝ)→ℝ} {D E : ℕ} + (hf : IsWeighted (fun _=>1) D f) (hg : IsWeighted (fun _=>1) E g) : + IsWeighted (fun _=>1) (D+E) (fun y=>f y*g y) := by + obtain ⟨p,hp,he⟩:=hf + obtain ⟨r,hr,hre⟩:=hg + exact ⟨p*r,hp.mul hr,by simp [he,hre]⟩ + +lemma oneWeight_prod {σ κ : Type*} (s : Finset κ) (f : κ→σ) : + IsWeighted (fun _=>1) s.card (fun y : σ→ℝ=>∏ k∈s,y (f k)) := by + classical + induction s using Finset.induction_on with + | empty=>simpa using IsWeighted.const (σ:=σ) (fun _=>1) 0 1 + | @insert i s hi ih=> + simpa only [Finset.card_insert_of_notMem hi,Finset.prod_insert hi,Nat.add_comm] + using oneWeight_mul (IsWeighted.coordinate (fun _ : σ=>1) (f i)) ih + +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i j1) ((m+1)*jointWeight n q w a) + (fun y=>coefficientsHomeomorph G n q c hsk A w hA + (sourceState G n q c hsk A w hA hw pattern g x b0 b1 a0 a1 y) a) := by + have hprod : IsWeighted (fun _ : Fin (m+v)=>1) (m+1) + (fun y=>∏ k : Fin m,y (k.castAdd v)) := by + have H:=oneWeight_prod Finset.univ (fun k : Fin m=>k.castAdd v) + simp only [Fintype.card_fin,Finset.card_univ] at H + exact H.mono (Nat.le_succ _) + have hb : IsWeighted (fun _ : Fin (m+v)=>1) (m+1) + (fun y=>b0 a.1+b1 a.1*(∏ k : Fin m,y (k.castAdd v))+ + ∑ j,(pattern a.1 j:ℝ)*y (j.natAdd m)) := by + apply ((IsWeighted.const _ _ _).add (hprod.smul _)).add + apply IsWeighted.sum + intro j hj + exact ((IsWeighted.coordinate (fun _ : Fin (m+v)=>1) (j.natAdd m)).mono (by omega)).smul _ + have hv (e : Fin q) : IsWeighted (fun _ : Fin (m+v)=>1) (m+1) + (fun y=>a0 e+a1 e*(∏ k : Fin m,y (k.castAdd v))) := + (IsWeighted.const _ _ _).add (hprod.smul _) + let k:=(SortedFiniteWeights.indexing (PolynomialArrays.weight (w a.1))).symm a.2 + have H:=PolynomialArrays.source_joint_log_weighted (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1) (hw a.1) + hb hv (g a.1) (x a.1) k + simp only [PolynomialArrays.chart_canonicalLog] at H + change IsWeighted _ ((m+1)*PolynomialArrays.weight (w a.1) + (SortedFiniteWeights.indexing (PolynomialArrays.weight (w a.1)) k)) + (fun y=>PolynomialArrays.coefficients (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1) + (sourceState G n q c hsk A w hA hw pattern g x b0 b1 a0 a1 y a.1) + (SortedFiniteWeights.indexing (PolynomialArrays.weight (w a.1)) k)) at H + simp only [k,Equiv.apply_symm_apply] at H + change IsWeighted _ ((m+1)*w a.1 a.2.1) + (fun y=>PolynomialArrays.coefficients (c a.1) (hsk a.1) (A a.1) (w a.1) (hA a.1) + (sourceState G n q c hsk A w hA hw pattern g x b0 b1 a0 a1 y a.1) a.2) + exact H + +variable (Γ : ∀ i,Subgroup (G i)) + + +theorem source_joint_geometry + (hΓ : ∀ i g,g∈Γ i ↔ ∀ j,∃ z : ℤ,(c i).coord g j=z) : + ∃ e : RealCoordinates (Carrier G n q c hsk A w hA) (Fintype.card (Index n q w)), + ∃ grid : ℕ,0canonicalLog e + (sourceState G n q c hsk A w hA hw (m:=m) pattern g x b0 b1 a0 a1 y) k) + (J*(m+1)) + := by + classical + obtain ⟨grid,hgridpos,hgrid⟩:=jointChart_grid G n q c hsk A w hA hw Γ hΓ + refine ⟨jointChart G n q c hsk A w hA hw,grid,hgridpos,hgrid, + 1+∑ a : Index n q w,jointWeight n q w a,by omega,?_⟩ + intro m v pattern g x b0 b1 a0 a1 k + let a:=SortedFiniteWeights.indexing (jointWeight n q w) k + have H:=oneWeight_degree (source_coefficients_weighted G n q c hsk A w hA hw (m:=m) pattern g x b0 b1 a0 a1 a) + have ha : jointWeight n q w a≤1+∑ b : Index n q w,jointWeight n q w b := by + have HH:=Finset.single_le_sum (f:=jointWeight n q w) (fun b _=>Nat.zero_le _) (Finset.mem_univ a) + omega + have H' := RealPolynomialDegree.mono H (Nat.mul_le_mul_left (m+1) ha) + simp only [jointChart_canonicalLog] + change RealPolynomialDegree.HasDegree + (fun y=>coefficientsHomeomorph G n q c hsk A w hA + (sourceState G n q c hsk A w hA hw pattern g x b0 b1 a0 a1 y) a) + ((1+∑ b : Index n q w,jointWeight n q w b)*(m+1)) + simpa only [Nat.mul_comm] using H' + +end RoughArrayFace + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray02.lean new file mode 100644 index 0000000000000000000000000000000000000000..9776722be5010cba0b4069cf7f5da0ef186be454 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray02.lean @@ -0,0 +1,271 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughArray01 +import OAI.Combinatorics.SumProduct.Alignment.RoughTopological03 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +noncomputable section +open scoped BigOperators +end + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters +open scoped BigOperators +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jz k+(Pi.single j δ : Fin v→ℝ) k))) := by + apply congrArg QuotientGroup.mk + funext i + apply Subtype.ext + funext u + change (sourceState G n q c hsk A w hA hw pattern g x b0 b1 a0 a1 (Fin.append t z) i).val + (u+(fun k=>(inputShift q pattern e j i k:ℝ)))= + (sourceState G n q c hsk A w hA hw pattern g x b0 b1 a0 a1 + (Fin.append t (fun k=>z k+(Pi.single j δ : Fin v→ℝ) k)) i).val u + dsimp only [sourceState,PolynomialArrays.sourceElement] + simp only [Fin.append_left,Fin.append_right] + apply congrArg (fun r=>realPower (c i) (g i) r*x i) + simp only [Pi.add_apply,mul_add,Finset.sum_add_distrib] + have hleft : (∑ k : Fin q,(a0 k+a1 k*∏ l,t l)*(inputShift q pattern e j i k:ℝ))= + (a0 e+a1 e*∏ l,t l)*(pattern i j:ℝ) := by + simp [inputShift,Pi.single_apply] + have hright : (∑ k : Fin v,(pattern i k:ℝ)*(Pi.single j δ : Fin v→ℝ) k)=(pattern i j:ℝ)*δ := by + simp [Pi.single_apply] + rw [hleft,hright,hδ] + ring + +end RoughArrayFace +end + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift +open scoped BigOperators +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jPi.single j (δ t) +end RoughArrayFace +end + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift RoughTopologicalFace +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory Filter +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable +variable {ι : Type} [Fintype ι] (G : ι→Type) [∀ i,Group (G i)] +variable [∀ i,TopologicalSpace (G i)] [∀ i,IsTopologicalGroup (G i)] +variable (n : ι→ℕ) (q : ℕ) (c : ∀ i,RealCoordinates (G i) (n i)) +variable (hsk : ∀ i,SecondKind (c i)) (A : ∀ i,CubeFaces.Filtration (G i)) +variable (w : ∀ i,Fin (n i)→ℕ) +variable (hA : ∀ i k (g : G i),g∈(A i).level k ↔ ∀ j,w i jX N j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ N,0R N/(Xp N:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R N/(M N:ℝ))/ + (1+∑ j,(X N j:ℝ)^2)^a) atTop atTop) + (hH : ∀ N,0≤H N) (hHZ : Tendsto (fun N=>H N/(R N/(M N:ℝ))) atTop (𝓝 0)) + (hWM : ∀ N,(primorial (w0 N):ℤ)∣(M N:ℤ)) + (hM : ∀ N,0(X N j:ℝ)/(L N:ℝ)) atTop atTop) + (pattern : ι→Fin v→ℤ) (e : Fin q) (j : Fin v) + (g x : ℕ→Label m→∀ i,G i) (b0 b1 : ℕ→Label m→ι→ℝ) + (a0 a1 : ℕ→Label m→Fin q→ℝ) (origin : ℕ→Label m→Fin v→ℤ) + (δ : ℕ→Label m→(Fin m→ℤ)→ℤ) + (hδ : ∀ N b,b∈(fullDomain (X N) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) → Good (X N) (Xp N) (R N) b → + ∀ t∈productTimes b.scales b.residue (L N), + (δ N b t:ℝ)=a0 N b e+a1 N b e*∏ l,(t l:ℝ) ∧ + (d:ℤ)∣δ N b t ∧ |(δ N b t:ℝ)|≤H N) : + Tendsto (fun N=>(jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) + (hX N) (hXp N)).real (rawFaceEvent (lattice G n q c hsk A w hA Γ) m v c₀ C₀ B η (R N) d (M N) (L N) + (fun b=>actualData G n q c hsk A w hA hw Γ pattern (g N b) (x N b) + (b0 N b) (b1 N b) (a0 N b) (a1 N b) e j (origin N b) (δ N b)))) + atTop (𝓝 0) + := by + obtain ⟨chart,grid,hgridpos,hgrid,J,hJ,hdegree⟩:= + source_joint_geometry G n q c hsk A w hA hw Γ hΓ + apply source_raw_continuous_face_grid_decay (lattice G n q c hsk A w hA Γ) + chart grid hgridpos hgrid htop m v (J*(m+1)) d hd c₀ C₀ B η hc₀ hC₀ hB hη + w0 M Xp X R H L hw0 hX hXp hXt hXpt hR hRX hZ hH hHZ hWM hM hMs hL hsm hWL hXL + (faceAction G n q c hsk A w hA Γ pattern e j) + intro N b hb hg + refine ⟨?_,rfl,?_,?_⟩ + · exact hdegree m v pattern (g N b) (x N b) (b0 N b) (b1 N b) (a0 N b) (a1 N b) + · intro t ht i + obtain ⟨_,hdiv,hbound⟩:=hδ N b hb hg t ht + change (d:ℤ)∣(Pi.single j (δ N b t) : Fin v→ℤ) i ∧ + |((Pi.single j (δ N b t) : Fin v→ℤ) i:ℝ)|≤H N + by_cases hij:i=j + · subst i;simp only [Pi.single_eq_same];exact ⟨hdiv,hbound⟩ + · simp only [Pi.single_eq_of_ne hij,Int.cast_zero,abs_zero] + exact ⟨dvd_zero _,hH N⟩ + · intro t ht z + obtain ⟨hslope,_,_⟩:=hδ N b hb hg t ht + have HH:=source_face_translation G n q c hsk A w hA hw Γ pattern (g N b) (x N b) + (b0 N b) (b1 N b) (a0 N b) (a1 N b) e j (fun l=>(t l:ℝ)) + (fun i=>(z i:ℝ)) (δ N b t:ℝ) hslope + have hcast : (fun i=>(z i:ℝ)+(Pi.single j (δ N b t:ℝ):Fin v→ℝ) i)= + (fun i=>((z i+(Pi.single j (δ N b t):Fin v→ℤ) i:ℤ):ℝ)) := by + funext i + by_cases hij:i=j + · subst i;simp + · simp [Pi.single_eq_of_ne hij] + rw [hcast] at HH + exact HH + +end RoughArrayFace +end + +noncomputable section +namespace RoughArrayCoordinates +open RationalLattice MalcevCharacters RoughFaceShift RoughArrayFace +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators + +def affine {v : ℕ} (K : Fin v→ℤ) (t : ℤ) (b : Fin v→ℤ) : Fin v→ℤ := fun j=>K j+t*b j + +def endpoint {v : ℕ} (K : Fin v→ℤ) (t : ℤ) (lo : Fin v→ℝ) : Fin v→ℝ := + fun j=>(K j:ℝ)+(t:ℝ)*lo j + +end RoughArrayCoordinates +end + +noncomputable section +namespace RoughArrayCoordinates +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators + +lemma coordinate_injective {v : ℕ} (K : Fin v→ℤ) {t : ℤ} (ht : 0dvd_mul_of_dvd_right h _⟩ + +lemma physical_image {v : ℕ} (K A res : Fin v→ℤ) (t : ℤ) (ht : 0 nlinarith [(hb i).1,(hb i).2] + · intro i + exact (affine_residue_iff _ _ _ _ _ hdt).mpr (hres i) + · intro i + have he : (M:ℤ)*(K i+t*b i)+A i=((M:ℤ)*K i+A i)+t*((M:ℤ)*b i) := by ring + dsimp [affine] + rw [he] + exact dvd_add (hK i) (dvd_mul_right _ _) + · rintro ⟨hx,hdiv⟩ + obtain ⟨hx,hres⟩:=(mem_physical _ _ _ _ _).mp hx + have hxb (i : Fin v) : ∃ b : ℤ,x i=K i+t*b := by + have hh:=dvd_sub (hdiv i) (hK i) + have he : (M:ℤ)*x i+A i-((M:ℤ)*K i+A i)=(M:ℤ)*(x i-K i) := by ring + rw [he] at hh + obtain ⟨b,hb⟩:=hMt.symm.dvd_of_dvd_mul_left hh + exact ⟨b,by linarith⟩ + choose b hb using hxb + have he : affine K t b=x := by funext i;exact (hb i).symm + refine ⟨b,(mem_physical _ _ _ _ _).mpr ⟨?_,?_⟩,he⟩ + · intro i + have HH:=hx i + rw [hb i] at HH + dsimp [endpoint] at HH + push_cast at HH + constructor <;> nlinarith [HH.1,HH.2] + · intro i + have HH:=hres i + rw [hb i] at HH + exact (affine_residue_iff _ _ _ _ _ hdt).mp HH + + +theorem mean_affine_nested {v : ℕ} (K A res : Fin v→ℤ) (t : ℤ) (ht : 0f (affine K t b))= + mean (nestedBox (endpoint K t lo) (endpoint K t hi) (affine K t res) A d M t) f + := by + classical + rw [← physical_image K A res t ht d M hdt hMt hK lo hi] + exact (mean_image _ _ (coordinate_injective K ht) f).symm + +end RoughArrayCoordinates + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray03.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f7675f64dccbf7a70db281da4e89072f5359314 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray03.lean @@ -0,0 +1,297 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughArray02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +noncomputable section +end + +noncomputable section +namespace RoughArrayCoordinates +open RationalLattice RoughFaceShift RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators +variable {G : Type} [Group G] [TopologicalSpace G] (Γ : Subgroup G) [MetricSpace (G⧸Γ)] + + +def badPhysical (m v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Nloc : ℝ) + (d : ℕ) (K : Fin v→ℤ) (P : (Fin (m+v)→ℝ)→G) + (σ : (G⧸Γ)→(G⧸Γ)) (t : Fin m→ℤ) : Prop := + ∃ (lo hi : Fin v→ℝ) (res : Fin v→ℤ) (test : (G⧸Γ)→ℂ), + (∀ i,c₀*Nloc≤hi i-lo i) ∧ (∀ i,-C₀*Nloc≤lo i ∧ hi i≤C₀*Nloc) ∧ + LipschitzWith B test ∧ (∀ y,‖test y‖≤B) ∧ + η≤‖mean (physicalResidueBox lo hi res d) + (fun b=>test (σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) + (fun i=>(affine K (∏ j,t j) b i:ℝ)))))))- + mean (physicalResidueBox lo hi res d) + (fun b=>test (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) + (fun i=>(affine K (∏ j,t j) b i:ℝ))))))‖ +end RoughArrayCoordinates +end +noncomputable section +namespace RoughArrayCoordinates +open RationalLattice RoughFaceShift RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators +variable {G : Type} [Group G] [TopologicalSpace G] (Γ : Subgroup G) [MetricSpace (G⧸Γ)] + + +omit [TopologicalSpace G] in +theorem badPhysical_subset {m v : ℕ} (c₀ C₀ Ctail Corigin : ℝ) (B : NNReal) + (η Nloc Z : ℝ) (d M : ℕ) (K A : Fin v→ℤ) (P : (Fin (m+v)→ℝ)→G) + (σ : (G⧸Γ)→(G⧸Γ)) (t : Fin m→ℤ) + (hc₀ : 0≤c₀) (hC₀ : 0≤C₀) (ht : 0<∏ j,t j) + (hscale : Z≤((∏ j,t j:ℤ):ℝ)*Nloc ∧ ((∏ j,t j:ℤ):ℝ)*Nloc≤Ctail*Z) + (hdt : IsCoprime (d:ℤ) (∏ j,t j)) (hMt : IsCoprime (M:ℤ) (∏ j,t j)) + (hKdiv : ∀ i,(∏ j,t j)∣(M:ℤ)*K i+A i) (hK : ∀ i,|(K i:ℝ)|≤Corigin*Z) : + badPhysical Γ m v c₀ C₀ B η Nloc d K P σ t → + badFace Γ m v c₀ (Corigin+C₀*Ctail) B η Z d M A P σ t + := by + rintro ⟨lo,hi,res,test,hside,hbox,hLip,hbound,hbad⟩ + refine ⟨endpoint K (∏ j,t j) lo,endpoint K (∏ j,t j) hi, + affine K (∏ j,t j) res,test,?_,?_,hLip,hbound,?_⟩ + · intro i + have htr : (0:ℝ)<((∏ j,t j:ℤ):ℝ) := by exact_mod_cast ht + have h1:=mul_le_mul_of_nonneg_left (hside i) htr.le + have h2:=mul_le_mul_of_nonneg_left hscale.1 hc₀ + dsimp [endpoint] + nlinarith + · intro i + have htr : (0:ℝ)<((∏ j,t j:ℤ):ℝ) := by exact_mod_cast ht + have h1:=mul_le_mul_of_nonneg_left (hbox i).1 htr.le + have h2:=mul_le_mul_of_nonneg_left (hbox i).2 htr.le + have h3:=mul_le_mul_of_nonneg_left hscale.2 hC₀ + have h4 : -Corigin*Z≤(K i:ℝ) ∧ (K i:ℝ)≤Corigin*Z := by + have hh:=(abs_le.mp (hK i)) + constructor <;> nlinarith [hh.1,hh.2] + dsimp [endpoint] + constructor <;> nlinarith [h4.1,h4.2] + · rw [←mean_affine_nested K A res (∏ j,t j) ht d M hdt hMt hKdiv lo hi, + ←mean_affine_nested K A res (∏ j,t j) ht d M hdt hMt hKdiv lo hi] + exact hbad + +end RoughArrayCoordinates +end + +noncomputable section +namespace RoughArrayCoordinates +open RationalLattice RoughFaceShift RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw +open scoped BigOperators + + +def rStar {m : ℕ} (M : ℕ) (b : Label m) : ℤ := + ((∏ j,b.residue j)*b.pivotResidue)%(M:ℤ) + + +def yStar {m : ℕ} (M : ℕ) (R : ℝ) (b : Label m) : ℤ := ⌊b.left R/(M:ℝ)⌋ + +def coarseOrigin {m : ℕ} (a M : ℕ) (R : ℝ) (b : Label m) : Fin (a+1)→ℤ := + Pi.single 0 ((M:ℤ)*yStar M R b+rStar M b) + + +def physicalOrigin {m : ℕ} (a M : ℕ) (R : ℝ) (b : Label m) + (t pstar : ℤ) : Fin (a+1)→ℤ := + Pi.single 0 ((t*pstar-rStar M b)/(M:ℤ)-yStar M R b) + + + +def rawPhysicalEvent {G : Type} [Group G] [TopologicalSpace G] (Γ : Subgroup G) + [MetricSpace (G⧸Γ)] (m a : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η R : ℝ) + (d M : ℕ) (L : ℤ) (F : Label m→FaceData m (a+1) G Γ) : + Set ((Fin m→ℕ)×ℕ) := + {z | let b:=expose L (M:ℤ) R z + ∃ pstar : ℤ,(M:ℤ)∣pstar-(z.2:ℤ) ∧ |(pstar:ℝ)-(z.2:ℝ)|≤R ∧ + badPhysical Γ m (a+1) c₀ C₀ B η (R/(M:ℝ)) d + (physicalOrigin a M R b (∏ j,(z.1 j:ℤ)) pstar) + (F b).P (F b).σ (fun j=>(z.1 j:ℤ))} +end RoughArrayCoordinates +end + +noncomputable section +namespace RoughArrayCoordinates +open ProductExposureLabels RoughFaceShift RoughScales +open scoped BigOperators + +lemma scalar_origin_bound (M : ℕ) (hM : 0C*x) hZM + constructor + · apply (mul_le_mul_iff_left₀ hMr).mp + nlinarith [hbin.1,hbin.2] + · apply (mul_le_mul_iff_left₀ hMr).mp + nlinarith [hbin.1,hbin.2] + +lemma rStar_expose {m : ℕ} (M : ℕ) (L : ℤ) (hML : (M:ℤ)∣L) + (R : ℝ) (z : (Fin m→ℕ)×ℕ) : + rStar M (expose L (M:ℤ) R z)=((∏ j,(z.1 j:ℤ))*(z.2:ℤ))%(M:ℤ) := by + unfold rStar expose + have hmod (j : Fin m) : ((z.1 j:ℤ)%L)%(M:ℤ)=(z.1 j:ℤ)%(M:ℤ) := + Int.emod_emod_of_dvd _ hML + rw [Int.mul_emod,Int.emod_emod,Finset.prod_int_mod] + simp only [hmod] + rw [←Finset.prod_int_mod,←Int.mul_emod] + +lemma physicalOrigin_div {m : ℕ} (a M : ℕ) (L : ℤ) (hML : (M:ℤ)∣L) + (R : ℝ) (z : (Fin m→ℕ)×ℕ) (pstar : ℤ) (hp : (M:ℤ)∣pstar-(z.2:ℤ)) : + ∀ i,(∏ j,(z.1 j:ℤ))∣(M:ℤ)* + physicalOrigin a M R (expose L (M:ℤ) R z) (∏ j,(z.1 j:ℤ)) pstar i+ + coarseOrigin a M R (expose L (M:ℤ) R z) i := by + let b:=expose L (M:ℤ) R z + let t:ℤ:=∏ j,(z.1 j:ℤ) + have hr : rStar M b=(t*(z.2:ℤ))%(M:ℤ) := rStar_expose M L hML R z + have hdiv : (M:ℤ)∣t*pstar-rStar M b := by + rw [hr] + have h1 : (M:ℤ)∣t*(pstar-(z.2:ℤ)) := dvd_mul_of_dvd_right hp t + have h2 : (M:ℤ)∣t*(z.2:ℤ)-(t*(z.2:ℤ))%(M:ℤ) := by + rw [Int.dvd_iff_emod_eq_zero,Int.sub_emod,Int.emod_emod] + simp + have he : t*pstar-(t*(z.2:ℤ))%(M:ℤ)= + t*(pstar-(z.2:ℤ))+(t*(z.2:ℤ)-(t*(z.2:ℤ))%(M:ℤ)) := by ring + rw [he] + exact dvd_add h1 h2 + intro i + change t∣(M:ℤ)*(Pi.single 0 ((t*pstar-rStar M b)/(M:ℤ)-yStar M R b) : Fin (a+1)→ℤ) i+ + (Pi.single 0 ((M:ℤ)*yStar M R b+rStar M b) : Fin (a+1)→ℤ) i + by_cases hi:i=0 + · subst i + simp only [Pi.single_eq_same] + have hh : (M:ℤ)*((t*pstar-rStar M b)/(M:ℤ))=t*pstar-rStar M b := + Int.mul_ediv_cancel' hdiv + have he : (M:ℤ)*((t*pstar-rStar M b)/(M:ℤ)-yStar M R b)+ + ((M:ℤ)*yStar M R b+rStar M b)=t*pstar := by linear_combination hh + rw [he] + exact dvd_mul_right t pstar + · simp [Pi.single_eq_of_ne hi] + +end RoughArrayCoordinates +end + +noncomputable section +namespace RoughArrayCoordinates +open RationalLattice RoughFaceShift RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw RoughScales RawHarmonicProbability +open scoped BigOperators + +lemma physicalOrigin_bound {m : ℕ} (a M : ℕ) (hM : 0by exact_mod_cast ht j) + have htcast : (t:ℝ)=∏ j,(z.1 j:ℝ) := by simp [t] + have hr : 0≤rStar M b ∧ rStar M b<(M:ℤ) := by + exact ⟨Int.emod_nonneg _ (by exact_mod_cast (Nat.ne_of_gt hM)), + Int.emod_lt_of_pos _ (by exact_mod_cast hM)⟩ + have hs1 : (1:ℝ)≤∏ j,b.scales j := + Finset.one_le_prod₀ (fun j _=>one_le_pow₀ (by norm_num : (1:ℝ)≤2)) + have hZ1 : 1≤(labelExposure b R M).Z := by + change 1≤((∏ j,b.scales j)*R)/(M:ℝ) + have hh:=mul_le_mul_of_nonneg_right hs1 (div_nonneg hR.le hMr.le) + rw [mul_div_assoc] + linarith + have hZM : (labelExposure b R M).Z*(M:ℝ)=(∏ j,b.scales j)*R := by + dsimp [labelExposure,Label.width] + exact div_mul_cancel₀ _ hMr.ne' + obtain ⟨hdy,hbin⟩:=expose_bounds L (M:ℤ) R hR z ht + have hbd:=product_dyadic_bounds b z.1 hdy + have hdiv : (M:ℤ)∣t*pstar-rStar M b := by + rw [rStar_expose M L hML R z] + have h1 : (M:ℤ)∣t*(pstar-(z.2:ℤ)) := dvd_mul_of_dvd_right hp t + have h2 : (M:ℤ)∣t*(z.2:ℤ)-(t*(z.2:ℤ))%(M:ℤ) := by + rw [Int.dvd_iff_emod_eq_zero,Int.sub_emod,Int.emod_emod];simp + have he : t*pstar-(t*(z.2:ℤ))%(M:ℤ)= + t*(pstar-(z.2:ℤ))+(t*(z.2:ℤ)-(t*(z.2:ℤ))%(M:ℤ)) := by ring + rw [he] + exact dvd_add h1 h2 + have hbound:=scalar_origin_bound M hM t (z.2:ℤ) pstar (rStar M b) htpos hr hdiv + (b.left R) R (∏ j,b.scales j) ((2:ℝ)^m) (labelExposure b R M).Z hR.le hZ1 hZM + (by simpa only [htcast] using hbd.2) (by simpa only [htcast,Int.cast_natCast,Label.width] using hbin) hcell + intro i + change |((Pi.single 0 ((t*pstar-rStar M b)/(M:ℤ)-yStar M R b) : Fin (a+1)→ℤ) i:ℝ)|≤_ + by_cases hi:i=0 + · subst i + simpa only [Pi.single_eq_same,yStar] using hbound + · simp only [Pi.single_eq_of_ne hi,Int.cast_zero,abs_zero] + positivity + + + +lemma rawPhysical_subset {G : Type} [Group G] [TopologicalSpace G] (Γ : Subgroup G) + [MetricSpace (G⧸Γ)] (m a w M d : ℕ) (hd : 0(hX j).trans_le (Finset.mem_Ico.mp + (Finset.mem_filter.mp (hdom' j)).1).1 + have hcop : ∀ j,(primorial w).Coprime (z.1 j) := fun j=>(Finset.mem_filter.mp (hdom' j)).2 + have hrough : ∀ j,Rough w (z.1 j:ℤ) := fun j=> + (rough_iff_coprime w _).mpr (by simpa only [Int.natAbs_natCast] using (hcop j).symm) + have hdt : IsCoprime (d:ℤ) (∏ j,(z.1 j:ℤ)) := by + apply Int.isCoprime_iff_nat_coprime.mpr + have HH:=Nat.Coprime.prod_right (fun j (_ : j∈Finset.univ)=>period_coprime_of_rough w d (z.1 j) hd hdw (hcop j).symm) + simpa only [←Nat.cast_prod,Int.natAbs_natCast] using HH + have hMt : IsCoprime (M:ℤ) (∏ j,(z.1 j:ℤ)) := by + apply Int.isCoprime_iff_nat_coprime.mpr + have HH:=Nat.Coprime.prod_right (fun j (_ : j∈Finset.univ)=>smooth_nat_coprime_rough hMs (hrough j)) + simpa only [←Nat.cast_prod,Int.natAbs_natCast] using HH + let b:=expose L (M:ℤ) R z + let Z:ℝ:=(labelExposure b R M).Z + have hs:=product_dyadic_bounds b z.1 (expose_bounds L (M:ℤ) R hR z ht).1 + have hscale : Z≤((∏ j,(z.1 j:ℤ):ℤ):ℝ)*(R/(M:ℝ)) ∧ + ((∏ j,(z.1 j:ℤ):ℤ):ℝ)*(R/(M:ℝ))≤(2:ℝ)^m*Z := by + have hRdiv : 0≤R/(M:ℝ) := div_nonneg hR.le (by positivity) + constructor + · simpa [Z,labelExposure,Label.width,mul_div_assoc] using mul_le_mul_of_nonneg_right hs.1 hRdiv + · simpa [Z,labelExposure,Label.width,mul_div_assoc,mul_assoc] using mul_le_mul_of_nonneg_right hs.2 hRdiv + change badFace Γ m (a+1) c₀ ((2:ℝ)^m+2+C₀*2^m) B η Z d M (F b).A (F b).P (F b).σ _ + rw [hF b] + exact badPhysical_subset Γ c₀ C₀ ((2:ℝ)^m) ((2:ℝ)^m+2) B η (R/(M:ℝ)) Z d M + (physicalOrigin a M R b (∏ j,(z.1 j:ℤ)) pstar) (coarseOrigin a M R b) (F b).P (F b).σ + (fun j=>(z.1 j:ℤ)) hc₀ hC₀ (Finset.prod_pos (fun j _=>by exact_mod_cast ht j)) hscale hdt hMt + (physicalOrigin_div a M L hML R z pstar hp) (physicalOrigin_bound a M hM L hML R hR hRM z ht pstar hp hcell) hbad + +end RoughArrayCoordinates + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray04.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray04.lean new file mode 100644 index 0000000000000000000000000000000000000000..05ada5d58425b8038c61bc96e15d869c4d4a4bee --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughArray04.lean @@ -0,0 +1,262 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.ProductExposure04 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +noncomputable section +open MeasureTheory Filter Topology +open scoped ENNReal BigOperators +end + +noncomputable section +namespace RoughArrayFace +open RationalLattice MalcevCharacters RoughFaceShift RoughTopologicalFace RoughArrayCoordinates SourceResidueAlignment +open RoughScales RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory Filter +open scoped BigOperators Topology ENNReal +attribute [local instance] Classical.propDecidable +variable {τ : Type} [Fintype τ] {ι : τ→Type} [∀ t,Fintype (ι t)] +variable (G : ∀ t,ι t→Type) [∀ t i,Group (G t i)] +variable [∀ t i,TopologicalSpace (G t i)] [∀ t i,IsTopologicalGroup (G t i)] +variable (n : ∀ t,ι t→ℕ) (q : τ→ℕ) (c : ∀ t i,RealCoordinates (G t i) (n t i)) +variable (hsk : ∀ t i,SecondKind (c t i)) (A : ∀ t i,CubeFaces.Filtration (G t i)) +variable (w : ∀ t i,Fin (n t i)→ℕ) +variable (hA : ∀ t i k (g : G t i),g∈(A t i).level k ↔ ∀ j,w t i jX N j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ N,0R N/(Xp N:ℝ)) atTop (𝓝 0)) + (hZ : ∀ t (u : ℝ),0(R N/(M N:ℝ))/ + (1+∑ j : Fin (m t),(X N (perm t (j.castAdd (h t))):ℝ)^2)^u) atTop atTop) + (hQ0 : ∀ N,0≤Q N) + (hSize : ∀ t,Tendsto (fun N=>(Q N+(∏ l : Fin (m t),(X N (perm t (l.castAdd (h t))):ℝ)^2)*(L N:ℝ))/R N) atTop (𝓝 0)) + (hWM : ∀ N,(primorial (w0 N):ℤ)∣(M N:ℤ)) + (hM : ∀ N,0(X N (perm t (j.castAdd (h t))):ℝ)/(L N:ℝ)) atTop atTop) + (pattern : ∀ t,ι t→Fin (v t+1)→ℤ) + (g x : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→∀ i,G t i) + (b0 b1 : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→ι t→ℝ) + (qval : ∀ t,ℕ→(Fin (h t)→ℕ)→Label (m t)→Fin (q t)→ℤ) + (hQ : ∀ t N y,y∈outsideDomain (fun l : Fin (h t)=>X N (perm t (l.natAdd (m t)))) (primorial (w0 N)) → + ∀ b,b∈(fullDomain (fun l : Fin (m t)=>X N (perm t (l.castAdd (h t)))) (Xp N) (primorial (w0 N))).image + (expose (L N) (M N:ℤ) (R N)) →∀ k,|(qval t N y b k:ℝ)|≤Q N) + (E : ℕ→Set ((Fin a→ℕ)×ℕ)) (ε : ℝ≥0∞) (hε : 0<ε) + (hE : ∀ N,ε≤(jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) + (hX N) (hXp N)) (E N)) : + ∃ φ : ℕ→ℕ,StrictMono φ ∧ ∃ z : ℕ→(Fin a→ℕ)×ℕ, + (∀ k,z k∈E (φ k) ∧ z k∈fullDomain (X (φ k)) (Xp (φ k)) (primorial (w0 (φ k)))) ∧ + ∀ t (e : Fin (q t)) (j : Fin (v t+1)) (d : ℕ),0(z k).1 (perm t (l.natAdd (m t))) + (fun l : Fin (m t)=>(z k).1 (perm t (l.castAdd (h t))),(z k).2) ∉ + rawPhysicalEvent (lattice (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (Γ t)) + (m t) (v t) (1/((b:ℝ)+1)) ((b:ℝ)+1) (b+1) (1/((b:ℝ)+1)) + (R (φ k)) d (M (φ k)) (L (φ k)) + (fun l=>actualData (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (hw t) (Γ t) (pattern t) + (g t (φ k) y l) (x t (φ k) y l) (b0 t (φ k) y l) (b1 t (φ k) y l) + (fun u=>(qval t (φ k) y l u:ℝ)/(M (φ k):ℝ)) + (fun u=>-(residueData (L (φ k)) (qval t (φ k) y l u) l:ℝ)/(M (φ k):ℝ)) e j + (coarseOrigin (v t) (M (φ k)) (R (φ k)) l) (shift (M (φ k)) (L (φ k)) (qval t (φ k) y l e) l)) + := by + classical + let μ : ℕ→Measure ((Fin a→ℕ)×ℕ) := fun N=> + jointLaw (X N) (Xp N) (primorial (w0 N)) (primorial_pos _) (hX N) (hXp N) + have (N : ℕ) : IsProbabilityMeasure (μ N) := by dsimp [μ]; infer_instance + let E' (N : ℕ) := E N∩(fullDomain (X N) (Xp N) (primorial (w0 N)):Set _) + have hE' (N : ℕ) : ε≤μ N (E' N) := by + have heq : μ N (E' N)=μ N (E N) := by + apply measure_congr + filter_upwards [joint_ae_fullDomain (X N) (Xp N) (primorial (w0 N)) + (primorial_pos _) (hX N) (hXp N)] with z hz + change (z∈E N ∧ z∈fullDomain (X N) (Xp N) (primorial (w0 N)))=(z∈E N) + exact propext ⟨And.left,fun he=>⟨he,hz⟩⟩ + rw [heq] + exact hE N + let Face := Σ t : τ,Fin (q t)×Fin (v t+1) + let OneBad : ℕ→Face→ℕ→Set ((Fin a→ℕ)×ℕ) := fun N face idx=> + {z | let t := face.1 + let y := fun l : Fin (h t)=>z.1 (perm t (l.natAdd (m t))) + (fun l : Fin (m t)=>z.1 (perm t (l.castAdd (h t))),z.2) ∈ + rawPhysicalEvent (lattice (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (Γ t)) + (m t) (v t) (1/((idx.unpair.2:ℝ)+1)) ((idx.unpair.2:ℝ)+1) (idx.unpair.2+1) + (1/((idx.unpair.2:ℝ)+1)) (R N) (idx.unpair.1+1) (M N) (L N) + (fun l=>actualData (G t) (n t) (q t) (c t) (hsk t) (A t) (w t) (hA t) (hw t) (Γ t) (pattern t) + (g t N y l) (x t N y l) (b0 t N y l) (b1 t N y l) + (fun u=>(qval t N y l u:ℝ)/(M N:ℝ)) + (fun u=>-(residueData (L N) (qval t N y l u) l:ℝ)/(M N:ℝ)) face.2.1 face.2.2 + (coarseOrigin (v t) (M N) (R N) l) (shift (M N) (L N) (qval t N y l face.2.1) l))} + have hOneBadReal (face : Face) (idx : ℕ) : + Tendsto (fun N=>(μ N).real (OneBad N face idx)) atTop (𝓝 0) := by + let t := face.1 + exact source_full_earlier_face_decay (G t) (n t) (q t) (c t) (hsk t) (A t) + (w t) (hA t) (hw t) (Γ t) (hΓ t) (htop t) + (m t) (h t) a (v t) (idx.unpair.1+1) (perm t) (by omega) + (1/((idx.unpair.2:ℝ)+1)) ((idx.unpair.2:ℝ)+1) (idx.unpair.2+1) + (1/((idx.unpair.2:ℝ)+1)) (by positivity) (by positivity) (by positivity) (by positivity) + w0 M Xp X R Q L hw0 hX hXp hXt hXpt hR hRX (hZ t) hQ0 (hSize t) hWM hM hMs + hL hsm hWL hML hLexact (hXL t) (pattern t) face.2.1 face.2.2 + (g t) (x t) (b0 t) (b1 t) (qval t) (hQ t) + have hOneBad (face : Face) (idx : ℕ) : + Tendsto (fun N=>μ N (OneBad N face idx)) atTop (𝓝 0) := by + have hh := ENNReal.tendsto_ofReal (hOneBadReal face idx) + have heq : (fun N=>ENNReal.ofReal ((μ N).real (OneBad N face idx))) = + (fun N=>μ N (OneBad N face idx)) := by + funext N + exact MeasureTheory.ofReal_measureReal (measure_lt_top (μ N) (OneBad N face idx)).ne + rw [heq,ENNReal.ofReal_zero] at hh + exact hh + let Bad (N idx : ℕ) : Set ((Fin a→ℕ)×ℕ) := ⋃ face : Face,OneBad N face idx + have hBad (idx : ℕ) : Tendsto (fun N=>μ N (Bad N idx)) atTop (𝓝 0) := by + have hh : Tendsto (fun N=>∑ face : Face,μ N (OneBad N face idx)) atTop (𝓝 0) := by + simpa using tendsto_finsetSum Finset.univ (fun face _=>hOneBad face idx) + exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hh + (fun _=>bot_le) (fun N=>measure_iUnion_fintype_le (μ N) (fun face=>OneBad N face idx)) + let err : ℕ→ℕ→((Fin a→ℕ)×ℕ)→ℝ := fun N idx z=>if z∈Bad N idx then 1 else 0 + have herr (idx : ℕ) (δ : ℝ) (hδ : 0<δ) : + Tendsto (fun N=>μ N {z | δ≤|err N idx z|}) atTop (𝓝 0) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds (hBad idx) + (fun _=>bot_le) (fun N=>measure_mono ?_) + intro z hz + by_contra hn + have : δ≤(0:ℝ) := by simpa [err,hn] using hz + exact (not_le_of_gt hδ) this + obtain ⟨φ,hφ,z,hz,he⟩ := ConditionalDiagonal.select (fun _=>(Fin a→ℕ)×ℕ) μ E' err ε hε hE' herr + refine ⟨φ,hφ,z,hz,?_⟩ + intro t e j d hd b + have hh := (he (Nat.pair (d-1) b)).eventually_lt_const (show (0:ℝ)<1 by norm_num) + filter_upwards [hh] with k hk + have hn : z k∉Bad (φ k) (Nat.pair (d-1) b) := by + intro hin + have : (1:ℝ)<1 := by simp [err,hin] at hk + exact (lt_irrefl (1:ℝ)) this + have hnOne : z k∉OneBad (φ k) ⟨t,(e,j)⟩ (Nat.pair (d-1) b) := fun hin=> + hn (Set.mem_iUnion.mpr ⟨⟨t,(e,j)⟩,hin⟩) + simpa only [OneBad,Set.mem_ofPred_eq,Nat.unpair_pair,show d-1+1=d by omega] using hnOne + +end RoughArrayFace +end + +noncomputable section +namespace RoughArrayCoordinates +open RationalLattice RoughFaceShift RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval Filter +open scoped BigOperators Topology + + +theorem physical_grid_continuous {G : Type} [Group G] [TopologicalSpace G] + (Γ : Subgroup G) [MetricSpace (G⧸Γ)] [CompactSpace (G⧸Γ)] + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v : ℕ) (Z : ℕ→ℝ) (hZ : ∀ N,0≤Z N) (d : ℕ) + (K : ℕ→Fin v→ℤ) (P : ℕ→(Fin (m+v)→ℝ)→G) + (σ : ℕ→(G⧸Γ)→(G⧸Γ)) (t : ℕ→Fin m→ℤ) + (hgrid : ∀ b : ℕ,∀ᶠ N in atTop, + ¬badPhysical Γ m v (1/((b:ℝ)+1)) ((b:ℝ)+1) (b+1) + (1/((b:ℝ)+1)) (Z N) d (K N) (P N) (σ N) (t N)) + (c₀ C₀ : ℝ) (hc₀ : 0mean (physicalResidueBox (lo N) (hi N) (res N) d) + (fun b=>F (σ N (QuotientGroup.mk (P N (Fin.append (fun j=>(t N j:ℝ)) + (fun i=>(affine (K N) (∏ j,t N j) b i:ℝ)))))))- + mean (physicalResidueBox (lo N) (hi N) (res N) d) + (fun b=>F (QuotientGroup.mk (P N (Fin.append (fun j=>(t N j:ℝ)) + (fun i=>(affine (K N) (∏ j,t N j) b i:ℝ))))))) atTop (𝓝 0) + := by + classical + have hF := F.continuous + have hc : @CompactSpace (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) := inferInstance + let : TopologicalSpace (G⧸Γ) := (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace + let : CompactSpace (G⧸Γ) := by + change @CompactSpace (G⧸Γ) (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace + rw [htop] + exact hc + let ftest : C(G⧸Γ,ℂ) := ⟨F,by + change @Continuous _ _ (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace _ F + rw [htop] + exact hF⟩ + let T (N : ℕ) := physicalResidueBox (lo N) (hi N) (res N) d + let y (N : ℕ) (b : Fin v→ℤ) : G⧸Γ := QuotientGroup.mk (P N + (Fin.append (fun j=>(t N j:ℝ)) (fun i=>(affine (K N) (∏ j,t N j) b i:ℝ)))) + let E (N : ℕ) : C(G⧸Γ,ℂ)→ₗ[ℂ]ℂ := { + toFun := fun f=>mean (T N) (fun b=>f (σ N (y N b)))-mean (T N) (fun b=>f (y N b)) + map_add' := by + intro f g + simp only [ContinuousMap.add_apply,mean,Finset.sum_add_distrib,mul_add] + ring + map_smul' := by + intro a f + simp only [ContinuousMap.smul_apply,mean,smul_eq_mul,←Finset.mul_sum, + RingHom.id_apply] + ring } + have hE (N : ℕ) (f : C(G⧸Γ,ℂ)) : ‖E N f‖≤2*‖f‖ := by + have h₁ := norm_mean_le (T N) (fun b=>f (σ N (y N b))) ‖f‖ (norm_nonneg _) + (fun b _=>f.norm_coe_le_norm _) + have h₂ := norm_mean_le (T N) (fun b=>f (y N b)) ‖f‖ (norm_nonneg _) + (fun b _=>f.norm_coe_le_norm _) + exact (norm_sub_le _ _).trans (by linarith only [h₁,h₂]) + change Tendsto (fun N=>E N ftest) atTop (𝓝 0) + rw [Metric.tendsto_nhds] + intro ε hε + obtain ⟨S,hS,η,hη,htest⟩ := CompactFamilyDescent.finite_unit_lipschitz_obstruction (Y:=G⧸Γ) + ({ftest} : Set C(G⧸Γ,ℂ)) (by exact isCompact_singleton) ε 2 hε (by norm_num) + obtain ⟨b,hb⟩ := exists_nat_gt (max (1/c₀) (max C₀ (1/η))) + have hbc : 1/c₀<(b:ℝ) := (le_max_left _ _).trans_lt hb + have hbC : C₀<(b:ℝ) := (le_trans (le_max_left _ _) (le_max_right _ _)).trans_lt hb + have hbη : 1/η<(b:ℝ) := (le_trans (le_max_right _ _) (le_max_right _ _)).trans_lt hb + have hbp : (0:ℝ)S n j) atTop atTop) + (hZ : ∀ a : ℝ,0Z n/(1+∑ j,S n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z n) atTop (𝓝 0)) + (hM : ∀ n,0S n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),LipschitzWith K σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes (S n) (r n) (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes (S n) (r n) (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + ((exceptionalFace Γ m v c₀ C₀ B η (Z n) d (M n) A P σ (S n) (r n) (L n)).card:ℝ)/ + ((productTimes (S n) (r n) (L n)).card:ℝ)<ε := by + classical + let B' : NNReal := B*(K+1) + have hB' : 01) (T:=fun n=>totalScale (S n)) + (by filter_upwards [] with n; norm_num) (totalScale_pos_eventually S hS) hZ + simpa using h 1 zero_lt_one + have herr : Tendsto (fun n=>(8*(B:ℝ)*(v:ℝ)/c₀)*(H n/Z n)) atTop (𝓝 0) := by + simpa using hHZ.const_mul (8*(B:ℝ)*(v:ℝ)/c₀) + intro ε hε + have hp := source_product_cover_decay c Γ Λ hle hsk hΛ htop m v D d hd c₀ C₀ B' (η/4) + hc₀ hC₀ hB' (by positivity) w M S Z r L hw hS hZ hM hMs hL hsm hWL hr hSL ε hε + filter_upwards [hp,hz.eventually (eventually_ge_atTop (4*(d:ℝ)/c₀)), + herr.eventually (gt_mem_nhds (by positivity : (0:ℝ)<η/4))] with n hpn hzn hen + intro A P hP σ hσ h hh hid + have hW : 4*(d:ℝ)≤c₀*Z n := by + have ht := (div_le_iff₀ hc₀).mp hzn + nlinarith + have hsub : exceptionalFace Γ m v c₀ C₀ B η (Z n) d (M n) A P σ (S n) (r n) (L n) ⊆ + exceptionalProduct Γ m v c₀ C₀ B' (η/4) (Z n) d (M n) A P (S n) (r n) (L n) := by + intro t ht + obtain ⟨ht,hbad⟩ := Finset.mem_filter.mp ht + apply Finset.mem_filter.mpr + refine ⟨ht,?_⟩ + by_contra hgood + obtain ⟨lo,hi,res,test,hside,hbox,hLip,hnorm,hlarge⟩ := hbad + have hcompare (F : (G⧸Γ) → ℂ) (hFL : LipschitzWith B' F) (hFn : ∀ y,‖F y‖≤B') : + ‖mean (physicalResidueBox lo hi res d) + (fun x=>F (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))- + mean (nestedBox lo hi res A d (M n) (∏ j,t j)) + (fun x=>F (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))‖<η/4 := by + apply lt_of_not_ge + intro hh + exact hgood ⟨lo,hi,res,F,hside,hbox,hFL,hFn,hh⟩ + have hplain := hcompare test (hLip.weaken hBB) + (fun y=>(hnorm y).trans (by exact_mod_cast hBB)) + have hface := hcompare (fun y=>test (σ y)) ((hLip.comp hσ).weaken hBK) + (fun y=>(hnorm (σ y)).trans (by exact_mod_cast hBB)) + let f : (Fin v → ℤ) → ℂ := fun x=>test + (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))) + have hshift := residueMean_translation lo hi res (h t) d hd (B:ℝ) (c₀*Z n) (H n) + hB hW hside (hH n) (hh t ht) f (fun x=>hnorm _) + have he : (fun x : Fin v → ℤ=>test + (σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))))= + fun x=>f (x+h t) := by + funext x + rw [hid t ht x] + rfl + have hsmall : ‖mean (physicalResidueBox lo hi res d) (fun x=>f (x+h t))- + mean (physicalResidueBox lo hi res d) f‖<η/4 := by + apply hshift.trans_lt + convert hen using 1 + ring + rw [← he] at hsmall + let X := mean (nestedBox lo hi res A d (M n) (∏ j,t j)) + (fun x=>test (σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))) + let Y := mean (physicalResidueBox lo hi res d) + (fun x=>test (σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))) + let U := mean (physicalResidueBox lo hi res d) f + let V := mean (nestedBox lo hi res A d (M n) (∏ j,t j)) f + have htri : ‖X-V‖≤‖X-Y‖+‖Y-U‖+‖U-V‖ := by + calc + _≤‖X-U‖+‖U-V‖ := norm_sub_le_norm_sub_add_norm_sub X U V + _≤_ := add_le_add (norm_sub_le_norm_sub_add_norm_sub X Y U) (le_refl ‖U-V‖) + change η≤‖X-V‖ at hlarge + change ‖U-V‖<η/4 at hplain + change ‖Y-X‖<η/4 at hface + rw [norm_sub_rev] at hface + change ‖Y-U‖<η/4 at hsmall + linarith + exact (div_le_div_of_nonneg_right (by exact_mod_cast Finset.card_le_card hsub) + (Nat.cast_nonneg _)).trans_lt (hpn A P hP) + +end RoughCoveredFace +end + +end + +section +noncomputable section +namespace RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + + +theorem source_conditional_face_decay (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0S n j) atTop atTop) + (hZ : ∀ a : ℝ,0Z n/(1+∑ j,S n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z n) atTop (𝓝 0)) + (hM : ∀ n,0S n j/(L n:ℝ)) atTop atTop) + (hbin : ∀ᶠ n in atTop,0canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),LipschitzWith K σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes (S n) (r n) (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes (S n) (r n) (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (∑ t∈exceptionalFace Γ m v c₀ C₀ B η (Z n) d (M n) A P σ (S n) (r n) (L n), + HarmonicExposure.exposedWeight (Q n) (Δ n) (a n) (M n) t)/ + (∑ t∈productTimes (S n) (r n) (L n), + HarmonicExposure.exposedWeight (Q n) (Δ n) (a n) (M n) t)<ε := by + classical + have hK : (0:ℝ)<8*2^m := by positivity + intro ε hε + have hf := source_face_decay (Γ:=Γ) (c:=c) Λ hle hsk hΛ htop m v D d hd c₀ C₀ B K η + hc₀ hC₀ hB hη w M S Z H r L hw hS hZ hH hHZ hM hMs hL hsm hWL hr hSL + (ε/(8*2^m)) (div_pos hε hK) + have hpos : ∀ᶠ n in atTop,∀ j,0(hS j).eventually (eventually_gt_atTop 0)) + have hne := productTimes_nonempty_eventually S r L hL hS hSL + filter_upwards [hf,hpos,hne,hbin] with n hfn hsn htn hbn + intro A P hP σ hσ h hh hid + have hfrac := hfn A P hP σ hσ h hh hid + have hdom := HarmonicExposure.conditional_fraction_le m (S n) (r n) (L n) (a n) (M n) + (Q n) (Δ n) hsn (hL n) (by exact_mod_cast hM n) hbn.1 hbn.2.1 hbn.2.2.1 hbn.2.2.2 + htn (exceptionalFace Γ m v c₀ C₀ B η (Z n) d (M n) A P σ (S n) (r n) (L n)) + (Finset.filter_subset _ _) + apply hdom.trans_lt + have hh := mul_lt_mul_of_pos_left hfrac hK + simpa only [mul_div_cancel₀ _ hK.ne'] using hh + +end RoughCoveredFace + +end + +end + +section +noncomputable section +namespace RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + + +theorem conditional_face_uniform (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0U n j) atTop atTop) + (hUV : ∀ n j,U n j≤V n j) + (hZ : ∀ a : ℝ,0Z0 n/(1+∑ j,V n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z0 n) atTop (𝓝 0)) + (hM : ∀ n,0U n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) → + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),LipschitzWith K σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (∑ t∈exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n), + HarmonicExposure.exposedWeight b.Q b.Δ b.a (M n) t)/ + (∑ t∈productTimes b.S b.r (L n), + HarmonicExposure.exposedWeight b.Q b.Δ b.a (M n) t)<ε + := by + classical + intro ε hε + let succeeds (n : ℕ) (b : Exposure m) : Prop := + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),LipschitzWith K σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (∑ t∈exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n), + HarmonicExposure.exposedWeight b.Q b.Δ b.a (M n) t)/ + (∑ t∈productTimes b.S b.r (L n), + HarmonicExposure.exposedWeight b.Q b.Δ b.a (M n) t)<ε + + change ∀ᶠ n in atTop,∀ b : Exposure m, + b.Legal (U n) (V n) (Z0 n) (w n) (M n) → succeeds n b + have hchoice (n : ℕ) : ∃ b : Exposure m, + b.Legal (U n) (V n) (Z0 n) (w n) (M n) ∧ + ((∃ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) ∧ ¬succeeds n b) + → ¬succeeds n b) := by + by_cases he : ∃ b : Exposure m, + b.Legal (U n) (V n) (Z0 n) (w n) (M n) ∧ ¬succeeds n b + · obtain ⟨b,hb,hf⟩ := he + exact ⟨b,hb,fun _=>hf⟩ + · let Δ : ℝ := max 1 (4*(M n:ℝ)*(2^m*∏ j,U n j)) + refine ⟨⟨U n,fun _=>1,Z0 n,Δ,Δ,0⟩,?_,fun hh=>(he hh).elim⟩ + refine ⟨fun j=>⟨le_refl _,hUV n j⟩,le_refl _,?_,?_,?_,le_refl _,?_⟩ + · intro j + simp + · exact zero_lt_one.trans_le (le_max_left _ _) + · exact zero_lt_one.trans_le (le_max_left _ _) + · exact le_max_right _ _ + choose b hb hfail using hchoice + have hS : ∀ j,Tendsto (fun n=>(b n).S j) atTop atTop := fun j=> + tendsto_atTop_mono (fun n=>(hb n).1 j |>.1) (hU j) + have hV : ∀ j,Tendsto (fun n=>V n j) atTop atTop := fun j=> + tendsto_atTop_mono (fun n=>hUV n j) (hU j) + have hspos := totalScale_pos_eventually (fun n=>(b n).S) hS + have hvpos := totalScale_pos_eventually V hV + have hzsmall := domination_smaller (S:=fun _=>1) + (by filter_upwards [] with n; norm_num) hvpos hZ + have hz0 : Tendsto Z0 atTop atTop := by + simpa using hzsmall 1 zero_lt_one + have hZs : ∀ a : ℝ,0(b n).Z/(1+∑ j,(b n).S j)^a) atTop atTop := by + have hh := domination_smaller (S:=fun n=>totalScale (b n).S) + (by filter_upwards [hspos] with n hn; linarith) + (by filter_upwards [] with n + dsimp [totalScale] + have hh := Finset.sum_le_sum (s:=Finset.univ) (fun j _=>(hb n).1 j |>.2) + linarith) hZ + intro a ha + apply tendsto_atTop_mono' atTop ?_ (hh a ha) + filter_upwards [hspos] with n hn + exact div_le_div_of_nonneg_right (hb n).2.1 (Real.rpow_nonneg (by linarith) _) + have hHsmall : Tendsto (fun n=>H n/(b n).Z) atTop (𝓝 0) := by + apply squeeze_zero' ?_ ?_ hHZ + · filter_upwards [hz0.eventually (eventually_gt_atTop 0)] with n hn + exact div_nonneg (hH n) (hn.le.trans (hb n).2.1) + · filter_upwards [hz0.eventually (eventually_gt_atTop 0)] with n hn + exact div_le_div_of_nonneg_left (hH n) hn (hb n).2.1 + have hSL : ∀ j,Tendsto (fun n=>(b n).S j/(L n:ℝ)) atTop atTop := by + intro j + apply tendsto_atTop_mono (fun n=>?_) (hUL j) + exact div_le_div_of_nonneg_right ((hb n).1 j).1 (by exact_mod_cast (hL n).le) + have hbin : ∀ᶠ n in atTop,0<(b n).Q ∧ 0<(b n).Δ ∧ (b n).Δ≤(b n).Q ∧ + 4*(M n:ℝ)*(2^m*∏ j,(b n).S j)≤(b n).Δ := by + filter_upwards [] with n + exact (hb n).2.2.2 + have hh := source_conditional_face_decay (Γ:=Γ) (c:=c) Λ hle hsk hΛ htop m v D d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M (fun n=>(b n).S) (fun n=>(b n).Z) H + (fun n=>(b n).Q) (fun n=>(b n).Δ) (fun n=>(b n).a) + (fun n=>(b n).r) L hw hS hZs hH hHsmall hM hMs hL hsm hWL + (fun n=>(hb n).2.2.1) hSL hbin ε hε + filter_upwards [hh] with n hn + intro z hz + by_contra he + exact hfail n ⟨z,hz,he⟩ hn + +end RoughCoveredFace + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughCovered02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughCovered02.lean new file mode 100644 index 0000000000000000000000000000000000000000..b32082eb169573f6c54fccf517750a2bf1ede6f1 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughCovered02.lean @@ -0,0 +1,289 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughCovered01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section +noncomputable section +namespace RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + +theorem raw_conditional_face_uniform (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0U n j) atTop atTop) + (hUV : ∀ n j,U n j≤V n j) + (hZ : ∀ a : ℝ,0Z0 n/(1+∑ j,V n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z0 n) atTop (𝓝 0)) + (hM : ∀ n,0U n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) → + ∀ X W : ℕ,(W:ℤ)∣(M n:ℤ) → b.a.natAbs.Coprime W → + (∀ t∈productTimes b.S b.r (L n),(X:ℝ)≤b.Q/(∏ j,(t j:ℝ))) → + (∀ t∈productTimes b.S b.r (L n),(b.Q+b.Δ)/(∏ j,(t j:ℝ))≤(X:ℝ)^2) → + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),LipschitzWith K σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + HarmonicExposure.rawFiberMass + (exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n)) + X W b.Q b.Δ b.a (M n) / + HarmonicExposure.rawFiberMass (productTimes b.S b.r (L n)) + X W b.Q b.Δ b.a (M n)<ε + := by + classical + intro ε hε + have hu := conditional_face_uniform (Γ:=Γ) (c:=c) Λ hle hsk hΛ htop m v D d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M U V Z0 H L hw hU hUV hZ hH hHZ + hM hMs hL hsm hWL hUL ε hε + have hup : ∀ᶠ n in atTop,∀ j,0(hU j).eventually (eventually_gt_atTop 0)) + filter_upwards [hu,hup] with n hn hUn + intro b hb X W hWM ha hlo hhi A P hP σ hσ h hh hid + have hτ : ∀ t∈productTimes b.S b.r (L n),0<∏ j,(t j:ℝ) := by + intro t ht + apply Finset.prod_pos + intro j hj + have htj := Fintype.mem_piFinset.mp ht j + have htpos := (mem_times (b.S j) (b.r j) (L n) (t j) (hL n)).mp htj + exact (hUn j).trans_le (((hb.1 j).1).trans htpos.1) + have he (T : Finset (Fin m→ℤ)) (hT : T⊆productTimes b.S b.r (L n)) := + HarmonicExposure.rawFiberMass_eq_exposed T X W b.Q b.Δ b.a (M n) + (by exact_mod_cast hM n) hWM ha + (fun t ht=>hτ t (hT ht)) (fun t ht=>hlo t (hT ht)) (fun t ht=>hhi t (hT ht)) + have hsub : exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n) ⊆ + productTimes b.S b.r (L n) := Finset.filter_subset _ _ + rw [he _ hsub,he _ (Finset.Subset.refl _)] + exact hn b hb A P hP σ hσ h hh hid + +end RoughCoveredFace +end + +end + +section +noncomputable section +namespace RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + +theorem source_raw_joint_face_uniform (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0U n j) atTop atTop) + (hUV : ∀ n j,U n j≤V n j) + (hZ : ∀ a : ℝ,0Z0 n/(1+∑ j,V n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z0 n) atTop (𝓝 0)) + (hWM : ∀ n,(primorial (w n):ℤ)∣(M n:ℤ)) + (hM : ∀ n,0U n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) → + ∀ (X : Fin m→ℕ) (Xp : ℕ) (hX : ∀ j,4*primorial (w n)≤X j) + (hXp : 4*primorial (w n)≤Xp),b.a.natAbs.Coprime (primorial (w n)) → + (∀ j,(X j:ℝ)≤b.S j) → (∀ j,2*b.S j≤(X j:ℝ)^2) → + (∀ t∈productTimes b.S b.r (L n),(Xp:ℝ)≤b.Q/(∏ j,(t j:ℝ))) → + (∀ t∈productTimes b.S b.r (L n),(b.Q+b.Δ)/(∏ j,(t j:ℝ))≤(Xp:ℝ)^2) → + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),LipschitzWith K σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (ProductExposureLaw.jointLaw X Xp (primorial (w n)) (primorial_pos _) hX hXp).real + (ProductExposureLaw.jointFiber + {t | badFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ t} + X Xp (primorial (w n)) b.S b.r (L n) b.Q b.Δ b.a (M n) : Set _) / + (ProductExposureLaw.jointLaw X Xp (primorial (w n)) (primorial_pos _) hX hXp).real + (ProductExposureLaw.jointFiber Set.univ + X Xp (primorial (w n)) b.S b.r (L n) b.Q b.Δ b.a (M n) : Set _) < ε + := by + classical + intro ε hε + have hu := raw_conditional_face_uniform (Γ:=Γ) (c:=c) Λ hle hsk hΛ htop m v D d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M U V Z0 H L hw hU hUV hZ hH hHZ + hM hMs hL hsm hWL hUL ε hε + filter_upwards [hu] with n hn + intro b hb X Xp hX hXp ha hloD hhiD hloP hhiP A P hP σ hσ h hh hid + rw [ProductExposureLaw.conditional_exact, + HarmonicExposure.literal_mass_eq _ X Xp _ b.S b.r (L n) b.Q b.Δ b.a (M n) + (hL n) (hWL n) hb.2.2.1 hloD hhiD, + HarmonicExposure.literal_mass_eq Set.univ X Xp _ b.S b.r (L n) b.Q b.Δ b.a (M n) + (hL n) (hWL n) hb.2.2.1 hloD hhiD] + simpa only [exceptionalFace,Set.mem_ofPred_eq,Set.mem_univ,Finset.filter_true_of_mem (fun _ _=>True.intro)] using + hn b hb Xp (primorial (w n)) (hWM n) ha hloP hhiP A P hP σ hσ h hh hid + +end RoughCoveredFace +end + +end +end + +section +noncomputable section +namespace RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw RawHarmonicProbability ProductExposureCutoff MeasureTheory +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable + + + +theorem source_raw_face_cover_decay {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} + (Λ Γ : Subgroup G) [MetricSpace (G⧸Γ)] [IsTopologicalGroup G] + (c : RealCoordinates G dim) (hsk : SecondKind c) + (hle : Λ≤Γ) (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0X n j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ n,0R n/(Xp n:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R n/(M n:ℝ))/ + (1+∑ j,(X n j:ℝ)^2)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/(R n/(M n:ℝ))) atTop (𝓝 0)) + (hWM : ∀ n,(primorial (w n):ℤ)∣(M n:ℤ)) + (hM : ∀ n,0(X n j:ℝ)/(L n:ℝ)) atTop atTop) + (F : ℕ→Label m→FaceData m v G Γ) + (hF : ∀ n b,b∈(fullDomain (X n) (Xp n) (primorial (w n))).image + (expose (L n) (M n:ℤ) (R n)) → Good (X n) (Xp n) (R n) b → + FaceData.Valid c D d K (H n) (L n) b (F n b)) : + Tendsto (fun n=>(jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) + (hX n) (hXp n)).real (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n))) + atTop (𝓝 0) + := by + have hXpr (n : ℕ) : (0:ℝ)R n/(M n:ℝ)) atTop atTop := by + apply tendsto_atTop_mono (fun n=>?_) (hZ 1 (by norm_num)) + rw [Real.rpow_one] + exact div_le_self (div_nonneg (hR n).le (hMr n).le) + (by have:=Finset.sum_nonneg (fun j (_ : j∈Finset.univ)=>sq_nonneg (X n j:ℝ));linarith) + have hRmin : ∀ᶠ n in atTop,4*(M n:ℝ)*2^m≤R n := by + filter_upwards [(tendsto_atTop.mp hZtop) (4*2^m)] with n hn + have hh := (le_div_iff₀ (hMr n)).mp hn + nlinarith + have hUV : ∀ n j,(X n j:ℝ)≤(X n j:ℝ)^2 := by + intro n j + have h1 : (1:ℝ)≤X n j := by + have:=hX n j;have:=primorial_pos (w n);exact_mod_cast (show 1≤X n j by omega) + nlinarith + have hu := source_raw_joint_face_uniform Γ c Λ hle hsk hΛ htop m v D d hd c₀ C₀ B K η + hc₀ hC₀ hB hη w M (fun n j=>(X n j:ℝ)) (fun n j=>(X n j:ℝ)^2) + (fun n=>R n/(M n:ℝ)) H L hw + (fun j=>tendsto_natCast_atTop_atTop.comp (hXt j)) hUV hZ hH hHZ hWM hM hMs + hL hsm hWL hXL + have hbad : Tendsto (fun n=>(jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) + (hX n) (hXp n)).real {z | ¬Good (X n) (Xp n) (R n) (expose (L n) (M n:ℤ) (R n) z)}) + atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun _=>measureReal_nonneg)) + · filter_upwards [hRsmall] with n hn + exact bad_good_bound (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n) + (L n) (M n:ℤ) (R n) (hR n) (by linarith [hR n]) + · have ht := tendsto_finsetSum Finset.univ (fun j _=> + raw_cutoff_decay (fun n=>X n j) (fun n=>primorial (w n)) 1 + (fun _=>primorial_pos _) (fun n=>hX n j) (hXt j)) + have hp := raw_cutoff_decay Xp (fun n=>primorial (w n)) (m+2) + (fun _=>primorial_pos _) hXp hXpt + simpa using ht.add hp + apply tendsto_order.2 + constructor + · intro a ha + exact Eventually.of_forall (fun _=>lt_of_lt_of_le ha measureReal_nonneg) + · intro e he + let ε := min (e/3) (1/2) + have hε : 0<ε := lt_min (by linarith) (by norm_num) + have hε1 : ε≤1 := (min_le_right _ _).trans (by norm_num) + filter_upwards [hu ε hε,hRsmall,hRmin,(tendsto_order.mp hbad).2 (e/3) (by linarith)] + with n hn hsmall hmin hbadn + have hb := supported_conditional_bad_bound + (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)) + (fullDomain (X n) (Xp n) (primorial (w n))) + (joint_ae_fullDomain (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)) + (expose (L n) (M n:ℤ) (R n)) {b | Good (X n) (Xp n) (R n) b} + (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n)) ε hε.le hε1 + (by + intro b hb hg + have hlegal := label_exposure_legal (X n) (Xp n) (w n) (M n) (L n) (R n) + (hX n) (hXp n) (hL n) (hM n) (hWL n) (hWM n) (hR n) hsmall hmin b hb hg + have hres := image_residues (X n) (Xp n) (primorial (w n)) (L n) (M n:ℤ) (R n) + (hL n) (by exact_mod_cast hM n) (hWL n) (hWM n) b hb + have hv := hF n b hb hg + have hpre := good_preimages (X n) (Xp n) (R n) (hR n).le (L n) (hL n) b hg + have hlocal := hn (labelExposure b (R n) (M n)) hlegal (X n) (Xp n) (hX n) (hXp n) + hres.2.2.2 (fun j=>(hg.1 j).1) (fun j=>(hg.1 j).2) + (fun t ht=>(hpre t ht).1) (fun t ht=>(hpre t ht).2) + (F n b).A (F n b).P hv.1 (F n b).σ hv.2.1 (F n b).h hv.2.2.1 hv.2.2.2 + have heq := label_conditional_exact (X n) (Xp n) (primorial (w n)) (M n) (L n) (R n) + (primorial_pos _) (hX n) (hXp n) (hL n) (hM n) (hR n) (hWL n) (hWM n) b hb + (fun b=>{t | badFace Γ m v c₀ C₀ B η (labelExposure b (R n) (M n)).Z d (M n) + (F n b).A (F n b).P (F n b).σ t}) + exact heq.trans_le hlocal.le) + have hεe : ε≤e/3 := min_le_left _ _ + change (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)).real + (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n)) ≤ ε+ + (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)).real + {z | ¬Good (X n) (Xp n) (R n) (expose (L n) (M n:ℤ) (R n) z)} at hb + change _ + ⟨⌊(K : ℝ)*Int.fract (f (realVertex z))⌋₊, (Nat.floor_lt + (mul_nonneg hKr.le (Int.fract_nonneg _))).mpr (by + simpa using mul_lt_mul_of_pos_left (Int.fract_lt_one (f (realVertex z))) hKr)⟩ + obtain ⟨l, c, hc⟩ := hN color + let f' : (Fin n → ℝ) → ℝ := fun z => f (parameterLift l z) + have hf' : HasDegree f' q := degree_parameterLift l hf + obtain ⟨θ, hθ, hθeval⟩ := realVertex_degree f' q hf' + have hθS (S : Finset (Fin n)) : Eval θ S = f (realVertex (l (fun i => decide (i ∈ S)))) := by + simpa only [vertexSet_decide, f', parameterLift_vertex] using hθeval (fun i => decide (i ∈ S)) + have hspread (S : Finset (Fin n)) : |Int.fract (Eval θ S)-(c.val : ℝ)/(K : ℝ)| ≤ 1/(K : ℝ) := by + have hh := congrArg Fin.val (hc (fun i => decide (i ∈ S))) + change ⌊(K : ℝ)*Int.fract (f (realVertex (l (fun i => decide (i ∈ S)))))⌋₊ = c.val at hh + simpa only [hθS, hh] using ConstantCoefficientRationalization.fractional_cell_bound hK + (f (realVertex (l (fun i => decide (i ∈ S))))) + have hsmall : (2 : ℝ)^(Fintype.card (Fin n))*(1/(K : ℝ)) < 1 := by + rw [Fintype.card_fin, mul_one_div, div_lt_one hKr] + dsimp [K] + rw [Nat.cast_pow, Nat.cast_ofNat] + exact pow_lt_pow_right₀ (by norm_num) (by omega) + obtain ⟨a, ha, hea⟩ := constant_rounding q θ hθ (c.val / (K : ℝ)) (1/(K : ℝ)) (by positivity) hsmall hspread + let aq : Finset (Fin n) → ℚ := fun S => a S + have haq : DegreeLE q aq := by intro S hS; simp [aq, ha S hS] + obtain ⟨m, hm, hem⟩ := realize_boolean_rational aq haq + refine ⟨l, m, hm, ?_⟩ + intro z + rw [hem] + have haev (S : Finset (Fin n)) : Eval aq S = ((Eval a S : ℤ) : ℚ) := by + simp only [Eval, aq, Int.cast_sum] + rw [haev, hea, Rat.cast_intCast, hθeval] + simp only [f', parameterLift_vertex] + +end CubeConstant + +end + +end + + +section + + + +noncomputable section +open Finset +open scoped BigOperators +namespace RoughCubeBlock +open RationalLattice RealPolynomialDegree RoughScales +open FinitePieceAverages RoughSamplingWeights DenseBooleanCubes CubeParameter +open Combinatorics + + +def time {n : ℕ} (a m : ℤ) (h : Fin n → ℕ) (z : Fin n → Bool) : ℤ := + a+m*(∑ i, if z i then h i else 0 : ℕ) + +lemma time_subspace {n N : ℕ} (l : Subspace (Fin n) Bool (Fin N)) + (a m : ℤ) (h : Fin N → ℕ) (z : Fin n → Bool) : + time (a+m*(CubeSubspace.offset l h : ℕ)) m (CubeSubspace.weight l h) z = time a m h (l z) := by + unfold time + rw [CubeSubspace.value] + push_cast + ring + +variable {G : Type*} [Group G] [TopologicalSpace G] {r : ℕ} +variable (c : RealCoordinates G r) (Γ : Subgroup G) [mtr : MetricSpace (G⧸Γ)] +local instance : TopologicalSpace (G⧸Γ) := mtr.toUniformSpace.toTopologicalSpace + +structure Block (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) (w : ℕ) (S Z : ℝ) + (n K : ℕ) where + start : ℤ + step : ℤ + positive : 0 < step + smooth : Smooth w step + weight : Fin n → ℕ + weight_pos : ∀ i, 0 < weight i + weight_bound : ∀ i, weight i ≤ K + scales : ∀ z, S ≤ (time start step weight z : ℝ) ∧ (time start step weight z : ℝ) < 2*S + rough : ∀ z, Rough w (time start step weight z) + P : (Fin (n+v) → ℝ) → G + degree : ∀ i, HasDegree (fun y => canonicalLog c (P y) i) D + lo : (Fin n → Bool) → Fin v → ℝ + hi : (Fin n → Bool) → Fin v → ℝ + res : (Fin n → Bool) → Fin v → ℤ + test : (Fin n → Bool) → (G⧸Γ) → ℂ + side : ∀ z i, c₀*Z ≤ hi z i-lo z i + box : ∀ z i, -C₀*Z ≤ lo z i ∧ hi z i ≤ C₀*Z + lip : ∀ z, LipschitzWith B (test z) + bound : ∀ z y, ‖test z y‖ ≤ B + bad : ∀ z, η ≤ ‖mean (boxIndices (lo z) (hi z) (fun _ => 0) 1) + (fun x => test z (QuotientGroup.mk (P (Fin.append (realVertex z) (fun i => (x i : ℝ)))))) - + mean (physicalResidueBox (lo z) (hi z) (res z) (time start step weight z).natAbs) + (fun x => test z (QuotientGroup.mk (P (Fin.append (realVertex z) (fun i => (x i : ℝ))))))‖ + +namespace Block +variable {c Γ} {v D n N K : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η : ℝ} {w : ℕ} {S Z : ℝ} +variable (b : Block c Γ v D c₀ C₀ B η w S Z N K) + + + +def subspace (l : Subspace (Fin n) Bool (Fin N)) : Block c Γ v D c₀ C₀ B η w S Z n (N*K) where + start := b.start+b.step*(CubeSubspace.offset l b.weight : ℕ) + step := b.step + positive := b.positive + smooth := b.smooth + weight := CubeSubspace.weight l b.weight + weight_pos := CubeSubspace.weight_pos l b.weight b.weight_pos + weight_bound := CubeSubspace.weight_le l b.weight K b.weight_bound + scales := by intro z; simpa only [time_subspace] using b.scales (l z) + rough := by intro z; simpa only [time_subspace] using b.rough (l z) + P := fun y => b.P (CubeParameter.lift l y) + degree := fun i => degree_lift l (b.degree i) + lo := fun z => b.lo (l z) + hi := fun z => b.hi (l z) + res := fun z => b.res (l z) + test := fun z => b.test (l z) + side := fun z => b.side (l z) + box := fun z => b.box (l z) + lip := fun z => b.lip (l z) + bound := fun z => b.bound (l z) + bad := by + intro z + simpa only [time_subspace, lift_vertex] using b.bad (l z) + +end Block + + +def initial (n N : ℕ) (h : n ≤ N) : Subspace (Fin n) Bool (Fin N) where + idxFun i := if hi : i.val < n then Sum.inr ⟨i.val, hi⟩ else Sum.inl false + proper j := by + refine ⟨⟨j.val, j.isLt.trans_le h⟩, ?_⟩ + simp [j.isLt] + +namespace Block +variable {c Γ} {v D n N K : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η : ℝ} {w : ℕ} {S Z : ℝ} +variable (b : Block c Γ v D c₀ C₀ B η w S Z N K) + +def restrict (h : n ≤ N) : Block c Γ v D c₀ C₀ B η w S Z n (N*K) := b.subspace (initial n N h) + +end Block + +end RoughCubeBlock + +end + +end + + +section + + + +noncomputable section +open scoped BigOperators +namespace CubeCharacter +open RationalLattice MalcevCharacters RealPolynomialDegree RoughPolynomialDegree +open CubeParameter CubeCoefficients RoughCubeBlock RoughAnalyticExtraction +open RoughDyadicFiltration RoughLogPolynomialAdaptation PolynomialLineCoefficients +open CorrectedBoxLeibman MeasureTheory AbelianMalcevTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {r : ℕ} +variable (c : RealCoordinates G r) (hsk : SecondKind c) (Γ : Subgroup G) +variable (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [mtr : MetricSpace (G⧸Γ)] +variable (htop : mtr.toUniformSpace.toTopologicalSpace = QuotientGroup.instTopologicalSpace Γ) +local instance : TopologicalSpace (G⧸Γ) := mtr.toUniformSpace.toTopologicalSpace + +include hsk in +omit [IsTopologicalGroup G] in +lemma degree_character {n q : ℕ} (P : (Fin n → ℝ) → G) + (hP : ∀ i, HasDegree (fun y => c.coord (P y) i) q) + (ξ : G →* Multiplicative ℝ) (hξ : Continuous ξ) : + HasDegree (fun y => (ξ (P y)).toAdd) q := by + have he : (fun y => (ξ (P y)).toAdd) = + (fun y => ∑ i, c.coord (P y) i * (ξ (axis c i 1)).toAdd) := + funext (fun y => character_coordinates c hsk ξ hξ (P y)) + rw [he] + apply finite_sum + intro i _ + simpa only [mul_comm] using RealPolynomialDegree.scale (hP i) ((ξ (axis c i 1)).toAdd) + +def coefficients {n v s : ℕ} (P : (Fin (n+v) → ℝ) → G) (ξ : G →* Multiplicative ℝ) : + PolynomialLineCoefficients.Grid v s → (Fin n → ℝ) → ℝ := + CubeCoefficients.coefficients (fun y => (ξ (P y)).toAdd) + +include hsk hΓ htop in + + +theorem character_tools (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0 < c₀) (hC₀ : 0 < C₀) (hB : 0 < B) (hη : 0 < η) : + ∃ q s : ℕ, ∃ U : Finset (G →* Multiplicative ℝ), ∃ A T : ℝ, 0 < A ∧ 1 ≤ T ∧ + (∀ n : ℕ, ∀ P : (Fin (n+v) → ℝ) → G, + (∀ i, HasDegree (fun y => canonicalLog c (P y) i) D) → + ∀ ξ : G →* Multiplicative ℝ, Continuous ξ → + (∀ I, HasDegree (coefficients (s:=s) P ξ I) q) ∧ + ∀ z : Fin n → ℝ, ∀ x : Fin v → ℝ, + gridEval (fun I => coefficients (s:=s) P ξ I z) x = (ξ (P (Fin.append z x))).toAdd) ∧ + ∀ n K w : ℕ, ∀ S Z : ℝ, ∀ b : Block c Γ v D c₀ C₀ B η w S Z n K, + (∀ z, 0 < (time b.start b.step b.weight z).natAbs ∧ + T ≤ Z/(time b.start b.step b.weight z).natAbs) → + ∀ z, ∃ p : ℕ, ∃ u : Fin v → ℤ, + (p=1 ∨ p=(time b.start b.step b.weight z).natAbs) ∧ + (∀ i, 0 ≤ u i ∧ u i < p) ∧ + ∃ ξ ∈ U, CharacterObstruction (s:=s) Γ + (fun x => b.P (Fin.append (realVertex z) (fun i => (x i : ℝ)))) ξ u p Z A := by + classical + let : MeasurableSpace (G⧸Γ) := borel (G⧸Γ) + let : @BorelSpace (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) inferInstance := by + rw [← htop] + exact ⟨rfl⟩ + let : BorelSpace (G⧸Γ) := by + change @BorelSpace (G⧸Γ) mtr.toUniformSpace.toTopologicalSpace inferInstance + exact ⟨rfl⟩ + let : CompactSpace (G⧸Γ) := metric_compact c Γ hΓ mtr htop + let : Group.IsNilpotent G := nilpotent_of_coordinates c + let : ContinuousConstSMul G (G⧸Γ) := by + change @ContinuousConstSMul G (G⧸Γ) mtr.toUniformSpace.toTopologicalSpace inferInstance + rw [htop] + infer_instance + obtain ⟨μ, hinv⟩ := SolvableInvariantMeasure.exists_invariant_measure (G:=G) (X:=G⧸Γ) + let := hinv + obtain ⟨E, hE, hcoord⟩ := coord_degree_bound c + obtain ⟨C, hC, hadapt⟩ := RoughDyadicFiltration.logarithmic_adapted c hsk + let H := RoughDyadicFiltration.filtration c (max 1 (C*D)) + let s := max 1 (C*D)*2^r + obtain ⟨h0, h1, hs, hqb, hq, hpoly⟩ := hadapt v D + obtain ⟨U, A, T, hA, hT, hdetect⟩ := discrepancy_character (t:=r) (d:=0) + c hsk H h0 h1 s hs (cutoff r (max 1 (C*D))) hqb hq Γ hΓ htop + (μ : Measure (G⧸Γ)) v c₀ C₀ B η hc₀ hC₀ hB hη + refine ⟨E*D, s, U, A, T, hA, hT, ?_, ?_⟩ + · intro n P hP ξ hξ + have hscalar := degree_character c hsk P (hcoord (n+v) D P hP) ξ hξ + refine ⟨fun I => coefficients_degree hscalar I, ?_⟩ + intro z x + apply coefficients_grid_real _ hscalar z + have hslice : ∀ i, HasDegree (fun x => canonicalLog c (P (Fin.append z x)) i) D := + fun i => degree_space_restrict (hP i) z + have hPf := (hpoly (fun x => P (Fin.append z x)) hslice).2 + intro x q + exact LeibmanSquare.character_polynomial H s hs + (LeibmanSquare.polynomial_integer_line H hPf x q) ξ + · intro n K w S Z b hscale z + let Pz : (Fin v → ℝ) → G := fun x => b.P (Fin.append (realVertex z) x) + have hPz : ∀ i, HasDegree (fun x => canonicalLog c (Pz x) i) D := + fun i => degree_space_restrict (b.degree i) _ + have hf := (hpoly Pz hPz).2 + let F : C(G⧸Γ, ℂ) := ⟨b.test z, (b.lip z).continuous⟩ + have hFN : ‖F‖ ≤ B := (ContinuousMap.norm_le F B.coe_nonneg).mpr (b.bound z) + exact hdetect Z (time b.start b.step b.weight z).natAbs (hscale z).1 (hscale z).2 + (b.lo z) (b.hi z) (b.res z) (b.side z) (b.box z) _ hf + ⟨F, b.lip z, hFN, b.bad z⟩ + +end CubeCharacter + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughCube02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughCube02.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c7450e687b9451597e8aca9dc0433e51c8063a1 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughCube02.lean @@ -0,0 +1,325 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CubeKernel01 +import OAI.Combinatorics.SumProduct.Alignment.RoughLiteral01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end + +end + + +section + + + +noncomputable section +namespace CubeDimension +open RationalLattice MalcevCharacters RoughCubeBlock RoughScales Filter +open CubeSplitProducer CubeReduction RoughKernelFactorization CubeKernel +open RoughDimensionInduction CubeParameter + +def NoLargeCubes (r : ℕ) : Prop := + ∀ (G : Type) [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + (c : RealCoordinates G r) (_ : SecondKind c) (Γ : Subgroup G) + (_ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + (mtr : MetricSpace (G⧸Γ)) + (_ : mtr.toUniformSpace.toTopologicalSpace = QuotientGroup.instTopologicalSpace Γ) + (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ), + 0 < c₀ → 0 < C₀ → 0 < B → 0 < η → + ∀ (w : ℕ → ℕ) (S Z : ℕ → ℝ), Tendsto w atTop atTop → Tendsto S atTop atTop → + (∀ k : ℕ, Tendsto (fun j => Z j/S j^k) atTop atTop) → + ∃ H : ℕ, ∀ K : ℕ, ∀ᶠ j in atTop, + @IsEmpty (Block c Γ v D c₀ C₀ B η (w j) (S j) (Z j) H K) + + + +theorem no_large_cubes (r : ℕ) : NoLargeCubes r := by + classical + induction r with + | zero => + intro G _ _ _ c hsk Γ hΓ mtr htop v D c₀ C₀ B η hc₀ hC₀ hB hη w S Z hw hS hZ + refine ⟨0, fun K => ?_⟩ + filter_upwards [CubeZero.eventually_no_zero_cubes c Γ v D c₀ C₀ B η hc₀ hη hS hZ] + with j hj using hj 0 K + | succ r ih => + intro G _ _ _ c hsk Γ hΓ mtr htop v D c₀ C₀ B η hc₀ hC₀ hB hη w S Z hw hS hZ + obtain ⟨q,s,U,hU,A,hA,hrat⟩ := split_producer c hsk Γ hΓ htop v D c₀ C₀ B η hc₀ hC₀ hB hη hw hS hZ + let Chars := {ξ // ξ ∈ U} + have hgood (ξ : Chars) : GoodCharacter Γ ξ.val := hU ξ.val ξ.property + have hred (ξ : Chars) : Nonempty (Reduction c hsk ξ.val Γ) := + exists_reduction c hsk ξ.val Γ hΓ (hgood ξ).2.1 (hgood ξ).2.2 (hgood ξ).1 + let R (ξ : Chars) : Reduction c hsk ξ.val Γ := Classical.choice (hred ξ) + have hstep (ξ : Chars) := reduce_split_cubes c hsk ξ.val Γ (R ξ) hΓ + (hgood ξ).2.1 (hgood ξ).2.2 htop v D q s c₀ C₀ A B η hc₀ hC₀ (by linarith) hη + choose Λ d hd hΛ D' c' hc' B' hB' δ hδ hreduce using hstep + have hlow (ξ : Chars) : ∃ H : ℕ, ∀ K : ℕ, ∀ᶠ j in atTop, + letI := coordinateQuotientMetric (d ξ) (Λ ξ) (hΛ ξ) + IsEmpty (Block (d ξ) (Λ ξ) v (D' ξ) (c' ξ) (C₀+1) (B' ξ) (η/2) + (w j) (S j) (Z j/(R ξ).period) H K) := by + exact ih ξ.val.ker (d ξ) (hd ξ) (Λ ξ) (hΛ ξ) + (coordinateQuotientMetric (d ξ) (Λ ξ) (hΛ ξ)) rfl v (D' ξ) (c' ξ) (C₀+1) (B' ξ) (η/2) + (hc' ξ) (by linarith) (hB' ξ) (by positivity) w S (fun j => Z j/(R ξ).period) + hw hS (divide_scale hZ (R ξ).period (R ξ).period_pos) + choose H hlow using hlow + choose N hN using fun ξ => hreduce ξ (H ξ) + let n := max (2*(q+v*s)+1) (Finset.univ.sup N) + have hn : 2*(q+v*s) < n := Nat.lt_of_lt_of_le (Nat.lt_succ_self _) (le_max_left _ _) + have hNn (ξ : Chars) : N ξ ≤ n := + (Finset.le_sup (f:=N) (Finset.mem_univ ξ)).trans (le_max_right _ _) + obtain ⟨N₀,L₀,hN₀⟩ := hrat n hn + refine ⟨N₀, fun K => ?_⟩ + have hall : ∀ᶠ j in atTop, ∀ ξ : Chars, + (R ξ).period ≤ w j ∧ 0 < S j ∧ ((R ξ).period:ℝ) ≤ Z j ∧ 1+2*S j ≤ δ ξ*Z j ∧ + letI := coordinateQuotientMetric (d ξ) (Λ ξ) (hΛ ξ) + IsEmpty (Block (d ξ) (Λ ξ) v (D' ξ) (c' ξ) (C₀+1) (B' ξ) (η/2) + (w j) (S j) (Z j/(R ξ).period) (H ξ) ((N ξ)*(n*(L₀*(N₀*K))))) := by + apply eventually_all.mpr + intro ξ + filter_upwards [eventual_reduction_scales hw hS hZ 0 (R ξ).period (δ ξ) (hδ ξ), + hlow ξ ((N ξ)*(n*(L₀*(N₀*K))))] with j hj hno + exact ⟨hj.2.1,hj.2.2.1,hj.2.2.2.1,hj.2.2.2.2,hno⟩ + filter_upwards [hN₀ K,hall] with j hj hxn + refine ⟨fun b₀ => ?_⟩ + obtain ⟨b,χ,hχ,hsp⟩ := hj b₀ + let ξ : Chars := ⟨χ,hχ⟩ + have hx := hxn ξ + let := coordinateQuotientMetric (d ξ) (Λ ξ) (hΛ ξ) + let b' := b.restrict (hNn ξ) + have hsp' : Split q s b'.P ξ.val (Z j) A := + split_subspace hsp (initial (N ξ) n (hNn ξ)) + obtain ⟨small⟩ := hN ξ (w j) (n*(L₀*(N₀*K))) (S j) (Z j) + hx.1 hx.2.1 hx.2.2.1 hx.2.2.2.1 b' hsp' + exact hx.2.2.2.2.false small + +end CubeDimension + +end + +end + + +section + + + +noncomputable section +namespace RoughCubeDensity +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughPolynomialDegree RoughSourceExceptional RoughProgressionDensity +open CubeParameter RoughCubeBlock DenseBooleanCubes +open scoped BigOperators + +def timeLift {n v : ℕ} (a m : ℤ) (h : Fin n → ℕ) (y : Fin (n+v) → ℝ) : Fin (v+1) → ℝ := + Fin.cons ((a:ℝ)+(m:ℝ)*∑ i, (h i:ℝ)*y (i.castAdd v)) (fun i => y (i.natAdd n)) + +lemma timeLift_degree {n v : ℕ} (a m : ℤ) (h : Fin n → ℕ) (i : Fin (v+1)) : + HasDegree (fun y => timeLift a m h y i) 1 := by + have hs : HasDegree (fun y : Fin (n+v) → ℝ => ∑ i, (h i:ℝ)*y (i.castAdd v)) 1 := + finite_sum Finset.univ _ _ (fun i _ => RealPolynomialDegree.scale (coordinate _) _) + refine Fin.cases ?_ (fun j => ?_) i + · simpa only [timeLift, Fin.cons_zero, max_self] using + RealPolynomialDegree.add (RealPolynomialDegree.const (σ:=Fin (n+v)) (a:ℝ) 1) + (RealPolynomialDegree.scale hs (m:ℝ)) + · exact coordinate _ + +lemma timeLift_vertex {n v : ℕ} (a m : ℤ) (h : Fin n → ℕ) (z : Fin n → Bool) (x : Fin v → ℝ) : + timeLift a m h (Fin.append (realVertex z) x) = Fin.cons (time a m h z:ℝ) x := by + have he : (∑ i, (h i:ℝ)*realVertex z i) = ((∑ i, if z i then h i else 0 : ℕ):ℝ) := by + simp only [Nat.cast_sum, Nat.cast_ite, Nat.cast_zero] + apply Finset.sum_congr rfl + intro i _ + cases hz : z i <;> simp [realVertex, hz] + simp only [timeLift, Fin.append_left, Fin.append_right, he, time, Int.cast_add, Int.cast_mul, + Int.cast_natCast] + +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (c : RealCoordinates G dim) (Γ : Subgroup G) [mtr : MetricSpace (G⧸Γ)] +local instance : TopologicalSpace (G⧸Γ) := mtr.toUniformSpace.toTopologicalSpace + + + +def blockOfCube {v D n K w : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η S Z : ℝ} + (P : (Fin (v+1)→ℝ)→G) (hP : ∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) + (a m : ℤ) (hm : 0 < m) (hsm : Smooth w m) (h : Fin n → ℕ) + (hh : ∀ i,0(hh i).1, weight_bound:=fun i=>(hh i).2, + scales:=hrange, rough:=hrough, + P:=fun y=>P (timeLift a m h y), + degree:=?_, lo:=lo, hi:=hi, res:=res, test:=test, + side:=hside, box:=hbox, lip:=hlip, bound:=hbound, bad:=?_ } + · intro i + simpa only [one_mul] using compose (hP i) (fun j y=>timeLift a m h y j) (timeLift_degree a m h) + · intro z + simpa only [timeLift_vertex] using hdisc z + +lemma no_dense_indices {v D H K w N : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η S Z ε : ℝ} + (hno : IsEmpty (RoughCubeBlock.Block c Γ v D c₀ C₀ B η w S Z H K)) + (hKN : K≤N) + (hcube : ∀ M : ℕ,K≤M → ∀ A : Finset ℕ,A⊆Finset.range M → ε*M≤(A.card:ℝ) → + ∃ a : ℕ,∃ h : Fin H → ℕ,(∀ i,0canonicalLog c (P y) i) D) + (a L : ℤ) (hL : 0Z n/S n^a) atTop atTop) + (hL : ∀ n,0S n/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ P : (Fin (v+1)→ℝ)→G,(∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ((exceptional Γ v c₀ C₀ B η (Z n) (S n) P (r n) (L n)).card:ℝ)/ + ((times (S n) (r n) (L n)).card:ℝ)<ε := by + classical + obtain ⟨H,hno⟩ := CubeDimension.no_large_cubes dim G c hsk Γ hΓ mtr htop + v D c₀ C₀ B η hc₀ hC₀ hB hη w S Z hw hS (integer_scales_of_real hS hZ) + have ht := timeLength_tendsto (r:=r) hL hS hSL + intro ε hε + obtain ⟨K,hK,hcube⟩ := dense_bounded_positive_cube H ε hε + filter_upwards [hno K,ht.eventually (eventually_ge_atTop (K:ℝ))] with j hj hNj + intro P hP + have hKN : K≤timeLength (S j) (r j) (L j) := by exact_mod_cast hNj + have hN : 0<(timeLength (S j) (r j) (L j):ℝ) := by exact_mod_cast hK.trans_le hKN + rw [exceptional_card Γ v c₀ C₀ B η (Z j) (S j) P (r j) (L j) (hL j), + times_card _ _ _ (hL j)] + apply (div_lt_iff₀ hN).mpr + exact no_dense_indices c Γ hj hKN hcube P hP _ _ (hL j) (hsm j) (hWL j) + (firstTime_rough ((rough_iff_coprime _ _).mpr (hr j)) (hWL j)) + (scale_at_index _ _ _ (hL j)) + + + +theorem source_literal_decay (hsk : SecondKind c) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) + (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^a) atTop atTop) + (hL : ∀ n,0S n/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ P : (Fin (v+1)→ℝ)→G,(∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ((RoughLiteralBoxes.exceptional Γ v c₀ C₀ B η (Z n) (S n) P (r n) (L n)).card:ℝ)/ + ((times (S n) (r n) (L n)).card:ℝ)<ε := by + classical + have hbound := source_exceptional_decay c Γ hsk hΓ htop v D (c₀/2) (C₀+1) B η + (by positivity) (by positivity) hB hη w S Z r L hw hS hZ hL hsm hWL hr hSL + have hZ' : Tendsto Z atTop atTop := by + simpa only [pow_zero, div_one] using integer_scales_of_real hS hZ 0 + intro ε hε + filter_upwards [hbound ε hε, hZ'.eventually (eventually_ge_atTop 1), + hZ'.eventually (eventually_ge_atTop (2/c₀))] with j hj hz hcz + intro P hP + have hcZ : 2≤c₀*Z j := by nlinarith [(div_le_iff₀ hc₀).mp hcz] + have hc := Finset.card_le_card (RoughLiteralBoxes.exceptional_subset Γ v c₀ C₀ B η + (Z j) (S j) P (r j) (L j) hz hcZ) + exact (div_le_div_of_nonneg_right (by exact_mod_cast hc) (by positivity)).trans_lt (hj P hP) + + + +theorem rough_step (hsk : SecondKind c) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) + (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^a) atTop atTop) + (hL : ∀ n,0S n/(L n:ℝ)) atTop atTop) + (P : ℕ → (Fin (v+1)→ℝ)→G) + (hP : ∀ n i,HasDegree (fun y=>canonicalLog c (P n y) i) D) : + Tendsto (fun n => + ((RoughLiteralBoxes.exceptional Γ v c₀ C₀ B η (Z n) (S n) (P n) (r n) (L n)).card:ℝ)/ + ((times (S n) (r n) (L n)).card:ℝ)) atTop (nhds 0) := by + have hh := source_literal_decay c Γ hsk hΓ htop v D c₀ C₀ B η hc₀ hC₀ hB hη + w S Z r L hw hS hZ hL hsm hWL hr hSL + apply Metric.tendsto_nhds.mpr + intro ε hε + filter_upwards [hh ε hε] with n hn + rw [Real.dist_eq, sub_zero, abs_of_nonneg (by positivity)] + exact hn (P n) (hP n) + + + +theorem finite_list_uniform {ι : Type} [Fintype ι] + (G : ι → Type) [∀ a, Group (G a)] [∀ a, TopologicalSpace (G a)] + [∀ a, IsTopologicalGroup (G a)] (dim : ι → ℕ) + (c : ∀ a, RealCoordinates (G a) (dim a)) (Γ : ∀ a, Subgroup (G a)) + [mtr : ∀ a, MetricSpace ((G a)⧸(Γ a))] + (hsk : ∀ a, SecondKind (c a)) + (hΓ : ∀ a (g : G a),g∈Γ a ↔ ∀ i,∃ z : ℤ,(c a).coord g i=z) + (htop : ∀ a,(mtr a).toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace (Γ a)) + (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^a) atTop atTop) + (hL : ∀ n,0S n/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, ∀ a, + ∀ P : (Fin (v+1)→ℝ)→G a,(∀ i,HasDegree (fun y=>canonicalLog (c a) (P y) i) D) → + ((RoughLiteralBoxes.exceptional (Γ a) v c₀ C₀ B η (Z n) (S n) P (r n) (L n)).card:ℝ)/ + ((times (S n) (r n) (L n)).card:ℝ)<ε := by + intro ε hε + exact eventually_all.mpr (fun a => source_literal_decay (c a) (Γ a) (hsk a) (hΓ a) (htop a) + v D c₀ C₀ B η hc₀ hC₀ hB hη w S Z r L hw hS hZ hL hsm hWL hr hSL ε hε) + +end RoughCubeDensity + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughDimension01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughDimension01.lean new file mode 100644 index 0000000000000000000000000000000000000000..bec0073f3a3b8587f376f3b12742c33df3c010b1 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughDimension01.lean @@ -0,0 +1,305 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughSplit01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +namespace RoughZeroDimension +open RationalLattice RoughBadBlock RoughSamplingWeights FinitePieceAverages Filter + +lemma constant_mean {α : Type*} (S : Finset α) (hS : S.Nonempty) (z : ℂ) : + mean S (fun _=>z)=z:=by + simp only [mean,Finset.sum_const,nsmul_eq_mul] + rw [←mul_assoc,inv_mul_cancel₀ (by exact_mod_cast hS.card_pos.ne' : (S.card:ℂ)≠0),one_mul] + +lemma physical_nonempty {ι : Type*} [Fintype ι] [DecidableEq ι] + (lo hi : ι→ℝ) (res : ι→ℤ) (t : ℕ) (ht : 0c.coord.injective (Subsingleton.elim _ _)⟩ + let : Subsingleton (G⧸Γ):=inferInstance + refine ⟨fun b=>?_⟩ + let j : Fin (H+1):=⟨0,by omega⟩ + have hscale:=b.scales 0 (by norm_num) (by positivity) + simp only [mul_zero,add_zero] at hscale + have hstart : 00) 1 zero_lt_one hlarge) + have h₂:=physical_nonempty (b.lo j) (b.hi j) (b.res j) b.start.natAbs ht hside + have hF : (fun x : Fin v→ℤ=>b.test j (QuotientGroup.mk + (b.P (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ))))))= + (fun _=>b.test j (QuotientGroup.mk (1:G))):=by + funext x + exact congrArg (b.test j) (Subsingleton.elim _ _) + have hb:=b.bad j + simp only [hF] at hb + have htime : (b.start+b.step*(j.val:ℤ)).natAbs=b.start.natAbs:=by simp [j] + rw [htime,constant_mean _ h₁,constant_mean _ h₂,sub_self,norm_zero] at hb + exact (not_le_of_gt hη) hb + + + +theorem eventually_no_zero_blocks (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^k) atTop atTop) : + ∀ᶠ n in atTop,∀ H : ℕ,IsEmpty (Block c Γ v D c₀ C₀ B η (w n) (S n) (Z n) H):=by + have hr : ∀ᶠ n in atTop,8/c₀≤Z n/S n:=by + simpa only [pow_one] using (hZ 1).eventually (eventually_ge_atTop (8/c₀)) + filter_upwards [hS.eventually (eventually_ge_atTop 1),hr] with n hn hnZ + intro H + apply no_block_at c Γ v D (w n) H c₀ C₀ (S n) (Z n) η B hη hn + have hh : (8/c₀)*S n≤Z n:=(le_div_iff₀ (by linarith)).mp hnZ + have hhh:=mul_le_mul_of_nonneg_left hh hc₀.le + field_simp at hhh + nlinarith + +end RoughZeroDimension + +end + +end + +section + + + + +noncomputable section +namespace RoughDimensionInduction +open RationalLattice MalcevCharacters RoughBadBlock RoughScales Filter +open RoughBlockRationalization RoughSplitBlockReduction RoughKernelFactorization +open RoughRationalBlock PolynomialLineCoefficients CorrectedBoxLeibman + +lemma divide_scale {S Z : ℕ→ℝ} + (hZ : ∀ k : ℕ,Tendsto (fun n=>Z n/S n^k) atTop atTop) + (K : ℕ) (hK : 0(Z n/K)/S n^k) atTop atTop:=by + intro k + have he : (fun n=>(Z n/(K:ℝ))/S n^k)=(fun n=>(Z n/S n^k)/(K:ℝ)):=by + funext n + simp only [div_eq_mul_inv] + ring + rw [he] + exact Tendsto.atTop_div_const (by exact_mod_cast hK) (hZ k) + +lemma eventual_reduction_scales {w : ℕ→ℕ} {S Z : ℕ→ℝ} + (hw : Tendsto w atTop atTop) (hS : Tendsto S atTop atTop) + (hZ : ∀ k : ℕ,Tendsto (fun n=>Z n/S n^k) atTop atTop) + (N K : ℕ) (δ : ℝ) (hδ : 0<δ) : + ∀ᶠ n in atTop,N≤w n ∧ K≤w n ∧ 0hM.2.2.1 I z (hz.trans hNH), + fun I z hz=>hM.2.2.2.1 I z (hz.trans hNH),fun z hz=>hM.2.2.2.2 z (hz.trans hNH)⟩ + + + +def NoLongBlocks (r : ℕ) : Prop := + ∀ (G : Type) [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + (c : RealCoordinates G r) (_ : SecondKind c) (Γ : Subgroup G) + (_ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (mtr : MetricSpace (G⧸Γ)) + (_ : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) + (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ), + 0Z n/S n^k) atTop atTop) → + ∃ H : ℕ,0 + intro G _ _ _ c hsk Γ hΓ mtr htop v D c₀ C₀ B η hc₀ hC₀ hB hη w S Z hw hS hZ + refine ⟨1,by omega,?_⟩ + filter_upwards [RoughZeroDimension.eventually_no_zero_blocks c Γ v D c₀ C₀ B η hc₀ hη hS hZ] + with n hn using hn 1 + | succ r ih=> + intro G _ _ _ c hsk Γ hΓ mtr htop v D c₀ C₀ B η hc₀ hC₀ hB hη w S Z hw hS hZ + obtain ⟨s,U,A,hA,hrat⟩:=rationalized_block c hsk Γ hΓ htop v D c₀ C₀ B η hc₀ hC₀ hB hη hw hS hZ + let Chars:={ξ : U // ξ.val≠1 ∧ Continuous ξ.val ∧ (∀ g∈Γ,∃ z : ℤ,(ξ.val g).toAdd=z)} + let : Fintype Chars:=Fintype.ofFinite _ + have hred (ξ : Chars) : Nonempty (Reduction c hsk ξ.val.val Γ):= + exists_reduction c hsk ξ.val.val Γ hΓ ξ.property.2.1 ξ.property.2.2 ξ.property.1 + let R (ξ : Chars) : Reduction c hsk ξ.val.val Γ:=Classical.choice (hred ξ) + have hstep (ξ : Chars):=reduce_split_blocks c hsk ξ.val.val Γ (R ξ) hΓ + ξ.property.2.1 ξ.property.2.2 htop v D s c₀ C₀ A B η hc₀ hC₀ (by linarith) hη + choose Λ d hd hΛ D' c' hc' B' hB' δ hδ hreduce using hstep + have hlow (ξ : Chars) : ∃ H : ℕ,0Z n/(R ξ).period) + hw hS (divide_scale hZ (R ξ).period (R ξ).period_pos) + choose H hH hlow using hlow + choose N hN using fun ξ=>hreduce ξ (H ξ) (hH ξ) + let K:=max (2*((v+1)*s+1)) (Finset.univ.sup N) + have hNK (ξ : Chars) : N ξ≤K:= + (Finset.le_sup (f:=N) (Finset.mem_univ ξ)).trans (le_max_right _ _) + obtain ⟨N₀,hN₀⟩:=hrat K (le_max_left _ _) + have hall : ∀ᶠ n in atTop,∀ ξ : Chars, + N ξ≤w n ∧ (R ξ).period≤w n ∧ 0?_⟩ + obtain ⟨b,ξ,hξ,hne,hcont,hint,θ,hθ,he,M,hM⟩:=hratn (b₀.restrict (le_max_right _ _)) + let ξ' : Chars:=⟨⟨ξ,hξ⟩,hne,hcont,hint⟩ + have hx:=hxn ξ' + let :=coordinateQuotientMetric (d ξ') (Λ ξ') (hΛ ξ') + let b':=b.restrict (hNK ξ') + have he' : ∀ z : ℝ,∀ x : Fin v→ℝ, + gridEval (fun I=>(θ I).eval z) x=(ξ'.val.val (b'.P (Fin.cons z x))).toAdd:=by + intro z x + simpa only [b',Block.restrict,Block.affine,Nat.cast_zero,Nat.cast_one,zero_add,one_mul, + Fin.cons_zero,Fin.tail_cons,ξ'] using he z x + obtain ⟨bsmall⟩:=hN ξ' (w n) (S n) (Z n) hx.1 hx.2.1 hx.2.2.1 hx.2.2.2.1 hx.2.2.2.2.1 + b' θ M hθ he' (split_restrict (hNK ξ') hM) + exact hx.2.2.2.2.2.false bsmall + +end RoughDimensionInduction + +end + +end + +section + + + + +noncomputable section +namespace RoughNoBadFamily +open RationalLattice MalcevCharacters RoughBadBlock Filter RoughDimensionInduction +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {r : ℕ} +variable (c : RealCoordinates G r) (hsk : SecondKind c) (Γ : Subgroup G) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable [mtr : MetricSpace (G⧸Γ)] +variable (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) + + + +def BadFamily (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) : Prop := + ∀ H : ℕ,∃ (w : ℕ→ℕ) (S Z : ℕ→ℝ), + Tendsto w atTop atTop ∧ Tendsto S atTop atTop ∧ + (∀ k : ℕ,Tendsto (fun n=>Z n/S n^k) atTop atTop) ∧ + ∀ᶠ n in atTop,Nonempty (Block c Γ v D c₀ C₀ B η (w n) (S n) (Z n) H) + +include hsk hΓ htop in + + +theorem no_bad_family (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0(hZ H k.val).eventually (eventually_ge_atTop (H:ℝ))) + filter_upwards [(hw H).eventually (eventually_ge_atTop H), + (hS H).eventually (eventually_ge_atTop (H:ℝ)),hz,hbad H] with n hwn hsn hzn hbn + exact ⟨hwn,hsn,fun k hk=>hzn ⟨k,by omega⟩,hbn⟩ + choose t ht using fun H=>(hgood H).exists + let w' : ℕ→ℕ:=fun H=>w H (t H) + let S' : ℕ→ℝ:=fun H=>S H (t H) + let Z' : ℕ→ℝ:=fun H=>Z H (t H) + have hw' : Tendsto w' atTop atTop:=by + apply tendsto_atTop.mpr + intro K + filter_upwards [eventually_ge_atTop K] with n hn + exact hn.trans (ht n).1 + have hS' : Tendsto S' atTop atTop:=by + apply tendsto_atTop.mpr + intro K + obtain ⟨N,hN⟩:=exists_nat_ge K + filter_upwards [eventually_ge_atTop N] with n hn + exact hN.trans ((Nat.cast_le.mpr hn).trans (ht n).2.1) + have hZ' (k : ℕ) : Tendsto (fun n=>Z' n/S' n^k) atTop atTop:=by + apply tendsto_atTop.mpr + intro K + obtain ⟨N,hN⟩:=exists_nat_ge K + filter_upwards [eventually_ge_atTop N,eventually_ge_atTop k] with n hn hk + exact hN.trans ((Nat.cast_le.mpr hn).trans ((ht n).2.2.1 k hk)) + obtain ⟨H,hH,hno⟩:=no_long_blocks r G c hsk Γ hΓ mtr htop + v D c₀ C₀ B η hc₀ hC₀ hB hη w' S' Z' hw' hS' hZ' + obtain ⟨n,hn,hHn⟩:=(hno.and (eventually_ge_atTop H)).exists + obtain ⟨b⟩:=(ht n).2.2.2 + exact hn.false (b.restrict hHn) + +end RoughNoBadFamily + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughDyadic01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughDyadic01.lean new file mode 100644 index 0000000000000000000000000000000000000000..879b55896e64e24d620610da617aefdc7b2c50b0 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughDyadic01.lean @@ -0,0 +1,324 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughReal01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughAnalyticRationalization +open _root_.Polynomial _root_.OAI.Polynomial Filter Finset RoughScales +open RoughRationalBlock RoughCharacterThinning RoughJointCoefficients +open FinitePieceAverages RoughSamplingWeights ComparableBoxLeibman +open CorrectedBoxLeibman PolynomialLineCoefficients TriangularLatticeRecovery + +lemma cast_progression_bounds {a b N K : ℕ} (h : a+b*K≤N) + (z : ℤ) (hz : 0≤z) (hzK : z≤K) : + 0≤(a:ℤ)+(b:ℤ)*z ∧ (a:ℤ)+(b:ℤ)*z≤N := by + constructor + · positivity + · have hmul:=mul_le_mul_of_nonneg_left hzK (Int.natCast_nonneg b) + have hn : (a:ℤ)+(b:ℤ)*(K:ℤ)≤N:=by exact_mod_cast h + omega + +lemma split_comp {v s w H : ℕ} {Z B : ℝ} + {θ : PolynomialLineCoefficients.Grid v s→ℝ[X]} + {a b : ℕ} {M : PolynomialLineCoefficients.Grid v s→ℚ[X]} + (h : Split w H Z B θ a b M) : + Split w H Z B (fun I=>(θ I).comp (C (a:ℝ)+C (b:ℝ)*X)) 0 1 M := by + rcases h with ⟨hdeg,hden,hint,herr,hzero⟩ + refine ⟨hdeg,hden,hint,?_,?_⟩ + · simpa only [zero_add,one_mul,eval_comp,eval_add,eval_C,eval_mul,eval_X, + Nat.cast_add,Nat.cast_mul] using herr + · simpa only [zero_add,one_mul,eval_comp,eval_add,eval_C,eval_mul,eval_X, + Nat.cast_add,Nat.cast_mul] using hzero + +section Nilmanifold +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus RationalTailCoordinates UnitAddTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0 = ⊤) (h1 : H.level 1 = ⊤) +variable [∀ i, (H.level i).Normal] +variable (s : ℕ) (hs : H.level (s+1) = ⊥) +variable (q : ℕ → ℕ) (hqbound : ∀ k, q k ≤ t+d) +variable (hq : ∀ k (g : G), g ∈ H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i = 0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) +variable [MeasurableSpace (G⧸Γ)] +variable [hBorel : @BorelSpace (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) inferInstance] +variable [mtr : MetricSpace (G⧸Γ)] +variable (htop : mtr.toUniformSpace.toTopologicalSpace = QuotientGroup.instTopologicalSpace Γ) +local instance roughDyadic01NilmanifoldTopology : TopologicalSpace (G⧸Γ) := + mtr.toUniformSpace.toTopologicalSpace + +include hsk h0 h1 hs hqbound hq hΓ htop in + + +theorem rational_split_from_discrepancies + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (v : ℕ) (c₀ C₀ : ℝ) (B₀ : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^k) atTop atTop) : + letI : CompactSpace (G⧸Γ) := metric_compact c Γ hΓ mtr htop + letI : BorelSpace (G⧸Γ) := metric_borelSpace Γ mtr htop + ∃ U : Finset (G→*Multiplicative ℝ),∃ B : ℝ,1 ≤ B ∧ + ∀ h : ℕ,2*((v+1)*s+1)≤ h →∃ N : ℕ,∀ᶠ n in atTop, + ∀ (a₀ m : ℤ),0 < m →Smooth (w n) m → + (∀ z : ℤ,0≤z →z≤N →S n≤((a₀+m*z:ℤ):ℝ) ∧ ((a₀+m*z:ℤ):ℝ)<2*S n)→ + (∀ z : ℤ,0≤z →z≤N →Rough (w n) (a₀+m*z))→ + ∀ f : (Fin (v+1)→ℤ)→G,LeibmanSquare.Polynomial H 0 f → + ∀ (lo hi : Fin (N+1)→Fin v→ℝ) (res : Fin (N+1)→Fin v→ℤ) + (F : Fin (N+1)→C(G⧸Γ,ℂ)), + (∀ j i,c₀*Z n≤hi j i-lo j i)→ + (∀ j i,-C₀*Z n≤lo j i ∧ hi j i≤C₀*Z n)→ + (∀ j,LipschitzWith B₀ (F j) ∧ ‖F j‖≤B₀)→ + (∀ j,η≤‖mean (boxIndices (lo j) (hi j) (fun _=>0) 1) + (fun x=>F j (QuotientGroup.mk (f (Fin.cons (j.val:ℤ) x)))) - + mean (physicalResidueBox (lo j) (hi j) (res j) (a₀+m*(j.val:ℤ)).natAbs) + (fun x=>F j (QuotientGroup.mk (f (Fin.cons (j.val:ℤ) x))))‖) → + ∃ a b : ℕ,0 < b ∧ a+b*h≤N ∧ Smooth (w n) (m*(b:ℤ)) ∧ + ∃ ξ∈U,ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ,∃ z : ℤ,(ξ g).toAdd=z) ∧ + ∃ θ : PolynomialLineCoefficients.Grid v s→ℝ[X], + (∀ I,(θ I).natDegree ≤ s) ∧ + (∀ z : ℤ,∀ x : Fin v→ℤ, + gridEval (fun I=>(θ I).eval (z:ℝ)) (fun i=>(x i:ℝ)) = + (ξ (f (Fin.cons ((a:ℤ)+(b:ℤ)*z) x))).toAdd) ∧ + ∃ M : PolynomialLineCoefficients.Grid v s→ℚ[X],Split (w n) h (Z n) B θ 0 1 M := by + classical + let : CompactSpace (G⧸Γ) := metric_compact c Γ hΓ mtr htop + let : BorelSpace (G⧸Γ) := metric_borelSpace Γ mtr htop + obtain ⟨U,A,T,hA,hT,hchar⟩:=common_character_from_discrepancies + c hsk H h0 h1 s hs q hqbound hq Γ hΓ htop μ v c₀ C₀ B₀ η hc₀ hC₀ hB₀ hη + obtain ⟨B,hB,hrat⟩:=eventual_split v s hA hw hS hZ + refine ⟨U,B,hB,?_⟩ + intro h hh + obtain ⟨K,hK,hKrat⟩:=hrat h hh + obtain ⟨N,hNchar⟩:=hchar K + refine ⟨N,?_⟩ + have hzscale : ∀ᶠ n in atTop,2*T≤Z n/S n:=by + simpa only [pow_one] using (hZ 1).eventually (eventually_ge_atTop (2*T)) + filter_upwards [hKrat,hw.eventually (eventually_ge_atTop N), + hS.eventually (eventually_ge_atTop 1),hzscale] with n hratn hwn hSn hZn + intro a₀ m hm hms hscale hrough f hf lo hi res F hside hbox hF hbad + let k : Fin (N+1)→ℕ:=fun j=>(a₀+m*(j.val:ℤ)).natAbs + have hscalej (j : Fin (N+1)):=hscale (j.val:ℤ) (by positivity) + (by exact_mod_cast Nat.le_of_lt_succ j.isLt) + have hposj (j : Fin (N+1)) : 0<(a₀+m*(j.val:ℤ):ℤ):=by + have h:=lt_of_lt_of_le (by linarith : (0:ℝ)⟨min z.toNat K,by omega⟩ + have hidx (z : ℤ) (hz : 0≤z) (hzK : z≤K) : ((idx z).val:ℤ)=z:=by + dsimp [idx] + rw [Nat.min_eq_left (Int.toNat_le.mpr hzK),Int.toNat_of_nonneg hz] + have hidxr (z : ℤ) (hz : 0≤z) (hzK : z≤K) : ((idx z).val:ℝ)=(z:ℝ):=by + exact_mod_cast hidx z hz hzK + have htime (z : ℤ) : a₀+m*((a:ℤ)+(b:ℤ)*z)=(a₀+m*(a:ℤ))+(m*(b:ℤ))*z:=by ring + have hkidx (z : ℤ) (hz : 0≤z) (hzK : z≤K) : + k (progressionIndex a b hab (idx z))=((a₀+m*(a:ℤ))+(m*(b:ℤ))*z).natAbs:=by + simp only [k,progressionIndex_val,Nat.cast_add,Nat.cast_mul,hidx z hz hzK,htime] + obtain ⟨c',d',hd',hdN,hcd,hsm,M,hM⟩:=hratn (a₀+m*(a:ℤ)) (m*(b:ℤ)) + (mul_pos hm (by exact_mod_cast hb)) hmbs + (fun z hz hzK=>by + simpa only [htime] using hscale _ (cast_progression_bounds hab z hz hzK).1 + (cast_progression_bounds hab z hz hzK).2) + (fun z hz hzK=>by + simpa only [htime] using hrough _ (cast_progression_bounds hab z hz hzK).1 + (cast_progression_bounds hab z hz hzK).2) + θ hθ (fun z=>p (idx z)) (fun z=>u (idx z)) + (fun z hz hzK=>by + rcases hpu (idx z) with hp | hp + · rw [hp]; omega + · rw [hp]; exact hk _) + (fun z hz hzK=>by simpa only [hkidx z hz hzK] using hpu (idx z)) + (fun z _ _=>huu (idx z)) + (fun z hz hzK I hI=>by simpa only [hidxr z hz hzK] using hcoeff (idx z) I hI) + let θ' : PolynomialLineCoefficients.Grid v s→ℝ[X]:=fun I=>(θ I).comp (C (c':ℝ)+C (d':ℝ)*X) + refine ⟨a+b*c',b*d',Nat.mul_pos hb hd',?_,?_,ξ,hξ,hξn,hξc,hξZ,θ', + fun I=>affine_degree (hθ I) _ _,?_,M,split_comp hM⟩ + · nlinarith + · simpa only [Nat.cast_mul,mul_assoc] using hsm + · intro z x + have h:=he ((c':ℤ)+(d':ℤ)*z) x + have ht : (a:ℤ)+(b:ℤ)*((c':ℤ)+(d':ℤ)*z)=((a+b*c':ℕ):ℤ)+((b*d':ℕ):ℤ)*z:=by + push_cast + ring + simpa [θ',Int.cast_add,Int.cast_mul,ht] using h + +end Nilmanifold +end RoughAnalyticRationalization + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators commutatorElement +namespace RoughDyadicFiltration +open RationalLattice MalcevCharacters CubeFaces LeibmanSquare RealPolynomialDegree +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +def weight (D : ℕ) (i : Fin n) : ℕ:=D*2^i.val +lemma weight_mono (D : ℕ) : Monotone (weight (n:=n) D):=by + intro i j hij + exact Nat.mul_le_mul_left D (Nat.pow_le_pow_right (by omega) hij) + +def cutoff (n D k : ℕ) : ℕ:= + Classical.choose (MalcevWeightedCoordinates.exists_weight_cutoff (weight (n:=n) D) (weight_mono D) k) +lemma cutoff_le (D k : ℕ) : cutoff n D k≤n:= + (Classical.choose_spec (MalcevWeightedCoordinates.exists_weight_cutoff (weight (n:=n) D) (weight_mono D) k)).1 +lemma cutoff_spec (D k : ℕ) (i : Fin n) : weight D ihg a (ha.trans_le hij) +lemma level_top {D k : ℕ} (hk : k≤D) : level c D k=⊤:=by + ext g + simp only [mem_level,Subgroup.mem_top,iff_true] + intro i hi + have h1 : 1≤2^i.val:=Nat.one_le_pow _ _ (by omega) + have : D≤weight D i:=by dsimp [weight]; nlinarith + omega +lemma level_terminal (D : ℕ) : level c D (D*2^n+1)=⊥:=by + apply le_antisymm _ bot_le + intro g hg + rw [mem_level] at hg + apply Subgroup.mem_bot.mpr + apply c.coord.injective + funext i + rw [c.one_coord] + apply hg + have hp : 2^i.val≤2^n:=Nat.pow_le_pow_right (by omega) i.isLt.le + dsimp [weight] + nlinarith +lemma twice_weight {j i : Fin n} (hji : j.val < i.val) (D : ℕ) : 2*weight D j≤weight D i:=by + have hp : 2^(j.val+1)≤2^i.val:=Nat.pow_le_pow_right (by omega) hji + rw [pow_succ] at hp + dsimp [weight] + nlinarith [Nat.mul_le_mul_left D hp] + +lemma commutator_le_of_le (D : ℕ) {k l : ℕ} (hkl : k≤l) : + ⁅level c D k,level c D l⁆≤level c D (k+l):=by + apply Subgroup.commutator_le.mpr + intro g hg x hx + rw [mem_level] at hx ⊢ + intro i hi + have hxlow : x∈coordinateTail c i.val:=by + intro j hj + apply hx + have h:=twice_weight hj D + omega + exact coordinateTail_commutator c i.val g x hxlow i (by omega) +lemma bracket (D k l : ℕ) : ⁅level c D k,level c D l⁆≤level c D (k+l):=by + rcases le_total k l with h | h + · exact commutator_le_of_le c D h + · rw [Subgroup.commutator_comm,Nat.add_comm] + exact commutator_le_of_le c D h + +def filtration (D : ℕ) : Filtration G where + level:=level c D + antitone:=level_antitone c D + commutator_le:=bracket c D +instance normal (D k : ℕ) : ((filtration c D).level k).Normal:= + coordinateTail_normal c _ +lemma filtration_zero (D : ℕ) : (filtration c D).level 0=⊤:=level_top c (Nat.zero_le D) +lemma filtration_one {D : ℕ} (hD : 0c.coord (P x) i) D) : + LeibmanSquare.Polynomial (filtration c D) 0 P:=by + classical + have haxis (i : Fin n) : LeibmanSquare.Polynomial (filtration c D) 0 + (fun x=>axis c i (c.coord (P x) i)):=by + obtain ⟨p,hp,he⟩:=hP i + have hdiff : ScalarDifferenceDegree.DegreeAtMost D (fun x=>c.coord (P x) i):=by + simp_rw [he] + exact ScalarDifferenceDegree.eval_polynomial p hp + exact ScalarDifferenceDegree.polynomial_power (filtration c D) + (MalcevTailSection.axisHom c hsk i) D (by + intro r + change _∈level c D D + rw [level_top c le_rfl] + trivial) hdiff + have hp:=CubeTaylorExpansion.polynomial_list_prod (filtration c D) + (List.finRange n) (fun i x=>axis c i (c.coord (P x) i)) (fun i _=>haxis i) + convert hp using 1 + funext x + simp only [← List.ofFn_eq_map] + exact hsk.ordered (P x) + +include hsk in + + +omit [IsTopologicalGroup G] in +theorem logarithmic_adapted : ∃ C : ℕ,0canonicalLog c (P x) i) d)→ + LeibmanSquare.Polynomial (filtration c D) 0 P ∧ + LeibmanSquare.Polynomial (filtration c D) 0 (fun x : Fin v→ℤ=>P (fun i=>(x i:ℝ))) := by + obtain ⟨C,hC,hcoord⟩:=coord_degree_bound c + refine ⟨C,hC,fun v d=>⟨filtration_zero c _,filtration_one c (by omega), + level_terminal c _,fun k=>cutoff_le _ _,fun k g=>unweight_level c _ _ g,?_⟩⟩ + intro P hP + have hp:=coordinate_adapted c hsk P + (fun i=>RealPolynomialDegree.mono (hcoord v d P hP i) (le_max_right 1 (C*d))) + exact ⟨hp,RoughLogPolynomialAdaptation.restrict_integer _ P hp⟩ + +end RoughDyadicFiltration + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughExtremal01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughExtremal01.lean new file mode 100644 index 0000000000000000000000000000000000000000..bd1f03da9caef6db27483fa5ecced310d9d60a72 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughExtremal01.lean @@ -0,0 +1,280 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughDimension01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +namespace RoughExtremalProgressions +open Finset + + +def APFree (H : ℕ) (A : Finset ℕ) : Prop := + ∀ a b : ℕ,0i/K=q)).image (fun i=>i%K) + +lemma blockResidues_subset (A : Finset ℕ) {K : ℕ} (hK : 0i/K=q)).card:=by + classical + apply card_image_iff.mpr + intro i hi j hj he + have hiq: i/K=q:=(mem_filter.mp hi).2 + have hjq: j/K=q:=(mem_filter.mp hj).2 + have hh:=Nat.mod_add_div i K + have hh':=Nat.mod_add_div j K + change i%K=j%K at he + rw [hiq] at hh + rw [hjq] at hh' + omega + +lemma mem_from_residue {A : Finset ℕ} {K q a : ℕ} + (ha : a∈blockResidues A K q) : q*K+a∈A:=by + obtain ⟨i,hi,he⟩:=mem_image.mp ha + obtain ⟨hiA,hiq⟩:=mem_filter.mp hi + have hx : q*K+a=i:=by nlinarith [Nat.mod_add_div i K] + rwa [hx] + + +lemma block_APFree {A : Finset ℕ} {H K : ℕ} (hH : 0i/K=q)).card≤extremal H K:=by + intro q + rw [←blockResidues_card] + exact le_extremal (blockResidues_subset A hK q) (block_APFree hH hK hno q) + have hsum : (∑ q∈range (N/K+1),(A.filter (fun i=>i/K=q)).card)=A.card:=by + rw [sum_card_fiberwise_eq_card_filter] + congr 1 + apply filter_eq_self.mpr + intro i hi + apply mem_range.mpr + have hiN:=mem_range.mp (hA hi) + exact Nat.lt_succ_of_le (Nat.div_le_div_right hiN.le) + rw [←hsum] + calc + _≤∑ q∈range (N/K+1),extremal H K:=sum_le_sum (fun q _=>hfiber q) + _= _:=by simp + + + +theorem density_le_extremal {A : Finset ℕ} {N H K : ℕ} + (hA : A⊆range N) (hN : 00) 1) + (fun x=>test (QuotientGroup.mk (P (Fin.cons (t:ℝ) (fun i=>(x i:ℝ))))))- + mean (physicalResidueBox lo hi res t.natAbs) + (fun x=>test (QuotientGroup.mk (P (Fin.cons (t:ℝ) (fun i=>(x i:ℝ))))))‖ + + + +def blockOfProgression {v D H w : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η S Z : ℝ} + (P : (Fin (v+1)→ℝ)→G) (hP : ∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) + (a m : ℤ) (hm : 0 < m) (hsm : Smooth w m) + (hrange : ∀ z : ℤ,0≤z →z≤H →S≤((a+m*z:ℤ):ℝ) ∧ ((a+m*z:ℤ):ℝ)<2*S) + (hrough : ∀ z : ℤ,0≤z →z≤H →Rough w (a+m*z)) + (hbad : ∀ j : Fin (H+1),BadAt Γ v c₀ C₀ B η Z P (a+m*(j.val:ℤ))) : + Block c Γ v D c₀ C₀ B η w S Z H:=by + classical + choose lo hi res test hside hbox hlip hbound hdisc using hbad + refine { + start:=a, step:=m, positive:=hm, smooth:=hsm, scales:=hrange, rough:=hrough, + P:=fun y=>P (Fin.cons ((a:ℝ)+(m:ℝ)*y 0) (Fin.tail y)), + degree:=fun i=>RoughPolynomialDegree.time_affine (hP i) _ _, + lo:=lo, hi:=hi, res:=res, test:=test, + side:=hside, box:=hbox, lip:=hlip, bound:=hbound, bad:=?_ } + intro j + simpa only [Fin.cons_zero,Fin.tail_cons,Int.cast_add,Int.cast_mul,Int.cast_natCast] + using hdisc j + +lemma rough_add_multiple {w : ℕ} {a L : ℤ} (ha : Rough w a) + (hL : (primorial w:ℤ)∣L) (z : ℤ) : Rough w (a+L*z):=by + intro p hp hpw hdiv + have hpW : (p:ℤ)∣(primorial w:ℤ):=Int.natCast_dvd.mpr (hp.dvd_primorial_iff.mpr hpw) + have hpL : (p:ℤ)∣L:=hpW.trans hL + apply ha p hp hpw + have h:=dvd_sub hdiv (dvd_mul_of_dvd_left hpL z) + simpa using h + + + +def badIndices (v N : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z : ℝ) + (P : (Fin (v+1)→ℝ)→G) (a L : ℤ) : Finset ℕ:=by + classical + exact (Finset.range N).filter (fun i=>BadAt Γ v c₀ C₀ B η Z P (a+L*(i:ℤ))) + +omit [TopologicalSpace G] in +lemma mem_badIndices {v N : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η Z : ℝ} + {P : (Fin (v+1)→ℝ)→G} {a L : ℤ} {i : ℕ} : + i∈badIndices Γ v N c₀ C₀ B η Z P a L ↔ + icanonicalLog c (P y) i) D) + (a L : ℤ) (hL : 0Z n/S n^k) atTop atTop) : + ∃ H : ℕ,0canonicalLog c (P y) i) D) → + ((badIndices Γ v N c₀ C₀ B η (Z n) P a L).card:ℝ)/N≤ + (extremal H K:ℝ)/K+(K:ℝ)/N:=by + classical + obtain ⟨H,hH,hno⟩:=RoughDimensionInduction.no_long_blocks r G c hsk Γ hΓ mtr htop + v D c₀ C₀ B η hc₀ hC₀ hB hη w S Z hw hS hZ + refine ⟨H,hH,fun K hK=>?_⟩ + filter_upwards [hno,hw.eventually (eventually_ge_atTop K)] with n hnoN hwK + intro N hN a L hL hsm hWL ha hscale P hP + exact density_le_extremal (Finset.filter_subset _ _) hN hH hK + (no_bounded_AP c Γ hnoN hwK P hP a L hL hsm hWL ha hscale) + +end RoughProgressionDensity + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace01.lean new file mode 100644 index 0000000000000000000000000000000000000000..65149607300a0ab0973cdbb81d3b0ea10275d8d3 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace01.lean @@ -0,0 +1,322 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughProduct03 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end +end + + +section + + + +noncomputable section +namespace RoughProductRemoval +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {dim : ℕ} +variable (c : RealCoordinates G dim) (Γ : Subgroup G) [mtr : MetricSpace (G⧸Γ)] + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma badProduct_zero_false {v : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η Z : ℝ} + {d M : ℕ} {A : Fin v → ℤ} {P : (Fin (0+v) → ℝ) → G} + {t : Fin 0 → ℤ} (hη : 0<η) : ¬badProduct Γ 0 v c₀ C₀ B η Z d M A P t := by + rintro ⟨lo,hi,res,test,hside,hbox,hlip,hbound,hdisc⟩ + have he : nestedBox lo hi res A d M (∏ j,t j)=physicalResidueBox lo hi res d := by + simp [nestedBox] + rw [he,sub_self,norm_zero] at hdisc + exact hη.not_ge hdisc + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma exceptionalProduct_succ_card {m v : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η Z : ℝ} + {d M : ℕ} {A : Fin v → ℤ} {P : (Fin ((m+1)+v) → ℝ) → G} + {S : Fin (m+1) → ℝ} {r : Fin (m+1) → ℤ} {L : ℤ} : + (exceptionalProduct Γ (m+1) v c₀ C₀ B η Z d M A P S r L).card= + (((times (S 0) (r 0) L).product (productTimes (Fin.tail S) (Fin.tail r) L)).filter + (fun p=>badProduct Γ (m+1) v c₀ C₀ B η Z d M A P (consPair p))).card := by + classical + rw [exceptionalProduct,productTimes_succ,Finset.filter_image, + Finset.card_image_of_injective _ (consPair_injective m)] + +theorem source_product_decay (hsk : SecondKind c) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0S n j) atTop atTop) + (hZ : ∀ a : ℝ,0Z n/(1+∑ j,S n j)^a) atTop atTop) + (_ : ∀ n,0S n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ((exceptionalProduct Γ m v c₀ C₀ B η (Z n) d (M n) A P (S n) (r n) (L n)).card:ℝ)/ + ((productTimes (S n) (r n) (L n)).card:ℝ)<ε := by + classical + induction m generalizing η with + | zero => + intro ε hε + filter_upwards [] with n + intro A P hP + have he : exceptionalProduct Γ 0 v c₀ C₀ B η (Z n) d (M n) A P (S n) (r n) (L n)=∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro t ht + exact badProduct_zero_false Γ hη (Finset.mem_filter.mp ht).2 + rw [he,Finset.card_empty,Nat.cast_zero,zero_div] + exact hε + | succ m ih => + intro ε hε + have htail := ih (η:=η/2) (by positivity) (S:=fun n=>Fin.tail (S n)) + (r:=fun n=>Fin.tail (r n)) (fun j=>hS j.succ) + (tail_domination S Z hS hZ) (fun n j=>hr n j.succ) (fun j=>hSL j.succ) + (ε/3) (by positivity) + have hfirst := firstBad_fiber_eventual c Γ hsk hΓ htop m v D d hd c₀ C₀ B (η/2) + hc₀ hC₀ hB (by positivity) w M S Z r L hw hS hZ hMs hL hsm hWL hr hSL + (ε/3) (by positivity) + have htailnonempty := productTimes_nonempty_eventually (fun n=>Fin.tail (S n)) + (fun n=>Fin.tail (r n)) L hL (fun j=>hS j.succ) (fun j=>hSL j.succ) + have htimepos := timeLength_tendsto (r:=fun n=>r n 0) hL (hS 0) (hSL 0) + filter_upwards [htail,hfirst,htailnonempty,htimepos.eventually (eventually_gt_atTop 0)] with n htn hfn htnon htime + intro A P hP + have htpos : (0:ℝ)<(productTimes (Fin.tail (S n)) (Fin.tail (r n)) (L n)).card := by + exact_mod_cast Finset.card_pos.mpr htnon + have hspos : (0:ℝ)<(times (S n 0) (r n 0) (L n)).card := by + rw [times_card _ _ _ (hL n)] + exact htime + have hf := product_exception_bound (times (S n 0) (r n 0) (L n)) + (productTimes (Fin.tail (S n)) (Fin.tail (r n)) (L n)) + (fun s t=>badProduct Γ m v c₀ C₀ B (η/2) (Z n) d (M n) A + (fun y=>P (tailLift (s:ℝ) y)) t) + (fun s t=>firstBad Γ m v c₀ C₀ B (η/2) (Z n) d (M n) A P s t) + (fun s t=>badProduct Γ (m+1) v c₀ C₀ B η (Z n) d (M n) A P (consPair (s,t))) + (ε/3) (ε/3) + (fun s hs=>((div_lt_iff₀ htpos).mp + (htn A (fun y=>P (tailLift (s:ℝ) y)) (tail_polynomial c P hP _))).le) + (hfn A P hP) + (fun s hs t ht h=>badProduct_succ_split Γ h) + rw [exceptionalProduct_succ_card,card_productTimes_succ,Nat.cast_mul] + apply (div_lt_iff₀ (mul_pos hspos htpos)).mpr + calc + _ ≤ (ε/3+ε/3)*(times (S n 0) (r n 0) (L n)).card* + (productTimes (Fin.tail (S n)) (Fin.tail (r n)) (L n)).card := hf + _ < ε*((times (S n 0) (r n 0) (L n)).card* + (productTimes (Fin.tail (S n)) (Fin.tail (r n)) (L n)).card) := by + nlinarith [mul_pos hspos htpos] + +end RoughProductRemoval +end +end + + +section + +noncomputable section +namespace RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] + +def badFace (m v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z : ℝ) + (d M : ℕ) (A : Fin v → ℤ) (P : (Fin (m+v) → ℝ) → G) + (σ : (G⧸Γ) → (G⧸Γ)) (t : Fin m → ℤ) : Prop := + ∃ (lo hi : Fin v → ℝ) (res : Fin v → ℤ) (test : (G⧸Γ) → ℂ), + (∀ i,c₀*Z≤hi i-lo i) ∧ (∀ i,-C₀*Z≤lo i ∧ hi i≤C₀*Z) ∧ + LipschitzWith B test ∧ (∀ y,‖test y‖≤B) ∧ + η≤‖mean (nestedBox lo hi res A d M (∏ j,t j)) + (fun x=>test (σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))))- + mean (nestedBox lo hi res A d M (∏ j,t j)) + (fun x=>test (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))‖ + +def exceptionalFace (m v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z : ℝ) + (d M : ℕ) (A : Fin v → ℤ) (P : (Fin (m+v) → ℝ) → G) + (σ : (G⧸Γ) → (G⧸Γ)) (S : Fin m → ℝ) (r : Fin m → ℤ) (L : ℤ) : + Finset (Fin m → ℤ) := by + classical + exact (productTimes S r L).filter (badFace Γ m v c₀ C₀ B η Z d M A P σ) + +end RoughFaceShift +end +end + + +section + +noncomputable section +namespace RoughFaceShift +open ComparableBoxLeibman RoughSamplingWeights RoughAnalyticExtraction FinitePieceAverages +open scoped BigOperators + +lemma rectMean_natShift {v : ℕ} {L : Fin v → ℕ} (hL : ∀ i,0f (x+h))-rectMean v L f‖≤ + B * ∑ i,2*(h i:ℝ)/(L i:ℝ) := by + let g : (Fin v → ℕ) → ℂ := fun x=>(B:ℂ)⁻¹*f x + have hg : ∀ x,‖g x‖≤1 := by + intro x + dsimp [g] + rw [norm_mul,norm_inv,Complex.norm_real,Real.norm_eq_abs,abs_of_pos hB] + exact (inv_mul_le_one₀ hB).mpr (hf x) + have he : ∀ x,f x=(B:ℂ)*g x := by + intro x + dsimp [g] + rw [← mul_assoc,mul_inv_cancel₀ (by exact_mod_cast hB.ne'),one_mul] + have hh := rectMean_shift v hL g hg h + have h1 : rectMean v L (fun x=>f (x+h)) = + (B:ℂ)*rectMean v L (fun x=>g (x+h)) := by + rw [← rectMean_smul] + congr 1 + funext x + exact he _ + have h0 : rectMean v L f = (B:ℂ)*rectMean v L g := by + rw [← rectMean_smul] + congr 1 + exact funext he + rw [h1,h0,← mul_sub,norm_mul,Complex.norm_real, + Real.norm_eq_abs,abs_of_pos hB] + exact mul_le_mul_of_nonneg_left hh hB.le + +lemma rectMean_intShift {v : ℕ} {L : Fin v → ℕ} (hL : ∀ i,0f (fun i=>a i+(x i:ℤ)+h i))- + rectMean v L (fun x=>f (fun i=>a i+(x i:ℤ)))‖≤ + B * ∑ i,2*|(h i:ℝ)|/(L i:ℝ) := by + let hp : Fin v → ℕ := fun i=>(h i).toNat + let hm : Fin v → ℕ := fun i=>(-h i).toNat + let g : (Fin v → ℕ) → ℂ := fun x=>f (fun i=>a i+(x i:ℤ)-(hm i:ℤ)) + have hep : (fun x=>f (fun i=>a i+(x i:ℤ)+h i))=fun x=>g (x+hp) := by + funext x + congr 1 + ext i + simp only [Pi.add_apply,Nat.cast_add] + dsimp [hp,hm] + omega + have hem : (fun x=>f (fun i=>a i+(x i:ℤ)))=fun x=>g (x+hm) := by + funext x + congr 1 + ext i + simp only [Pi.add_apply,Nat.cast_add] + omega + rw [hep,hem] + have hgp := rectMean_natShift hL g B hB (fun x=>hf _) hp + have hgm := rectMean_natShift hL g B hB (fun x=>hf _) hm + have ht := (norm_sub_le_norm_sub_add_norm_sub + (rectMean v L (fun x=>g (x+hp))) (rectMean v L g) + (rectMean v L (fun x=>g (x+hm)))).trans + (add_le_add hgp (by simpa only [norm_sub_rev] using hgm)) + have he : (∑ i,2*(hp i:ℝ)/(L i:ℝ))+(∑ i,2*(hm i:ℝ)/(L i:ℝ))= + ∑ i,2*|(h i:ℝ)|/(L i:ℝ) := by + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + have hi : (hp i:ℝ)+(hm i:ℝ)=|(h i:ℝ)| := by + have hi' : (hp i:ℤ)+(hm i:ℤ)=|h i| := by + dsimp [hp,hm] + by_cases hh : 0≤h i + · rw [abs_of_nonneg hh] + omega + · rw [abs_of_neg (by omega : h i<0)] + omega + exact_mod_cast hi' + rw [← add_div,← mul_add,hi] + calc + _ ≤ B*(∑ i,2*(hp i:ℝ)/(L i:ℝ))+B*(∑ i,2*(hm i:ℝ)/(L i:ℝ)) := ht + _ = _ := by rw [← mul_add,he] + +lemma halfOpenLength_lower (lo hi W : ℝ) (hW : 4≤W) (hside : W≤hi-lo) : + W/4≤(integerLength lo ((⌈hi⌉:ℝ)-1):ℝ) := by + have hh := integerLength_lower lo ((⌈hi⌉:ℝ)-1) (W/2) (by linarith) (by + have := Int.le_ceil hi + linarith) + linarith + +lemma boxMean_translation {v : ℕ} (lo hi : Fin v → ℝ) (a : Fin v → ℤ) + (B W H : ℝ) (hB : 00) 1) (fun x=>f (x+a))- + mean (boxIndices lo hi (fun _=>0) 1) f‖ ≤ 8*B*(v:ℝ)*H/W := by + have hlen := fun i=>halfOpenLength_lower (lo i) (hi i) W hW (hside i) + have hpos : ∀ i,0 < integerLength (lo i) ((⌈hi i⌉:ℝ)-1) := by + intro i + have : (0:ℝ)< integerLength (lo i) ((⌈hi i⌉:ℝ)-1) := lt_of_lt_of_le (by linarith) (hlen i) + exact_mod_cast this + simp only [mean_eq_expect,boxIndices_eq_halfOpen,halfOpenBox,integerBox_average] + have hh := rectMean_intShift hpos f B hB hf (fun i=>⌈lo i⌉) a + apply hh.trans + have hterm : ∀ i,2*|(a i:ℝ)|/(integerLength (lo i) ((⌈hi i⌉:ℝ)-1):ℝ)≤8*H/W := by + intro i + have hL : (0:ℝ)< integerLength (lo i) ((⌈hi i⌉:ℝ)-1) := by exact_mod_cast hpos i + apply (div_le_iff₀ hL).mpr + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ (by linarith : 0hterm i)) hB.le + _ = _ := by simp; ring + +lemma residueMean_translation {v : ℕ} (lo hi : Fin v → ℝ) (u a : Fin v → ℤ) + (d : ℕ) (hd : 0f (x+a))- + mean (physicalResidueBox lo hi u d) f‖≤8*B*(v:ℝ)*H/W := by + have hd' : (0:ℝ)(ha i).1 + have hkbound : ∀ i,|(k i:ℝ)|≤H/(d:ℝ) := by + intro i + apply (le_div_iff₀ hd').mpr + have hh := (ha i).2 + rw [hk i,Int.cast_mul,Int.cast_natCast,abs_mul,abs_of_pos hd'] at hh + nlinarith + let lo' := rescaledEndpoint lo u d + let hi' := rescaledEndpoint hi u d + have hside' : ∀ i,W/(d:ℝ)≤hi' i-lo' i := by + intro i + dsimp [lo',hi',rescaledEndpoint] + rw [← sub_div] + apply div_le_div_of_nonneg_right _ hd'.le + linarith [hside i] + have hbound := boxMean_translation lo' hi' k B (W/(d:ℝ)) (H/(d:ℝ)) hB + ((le_div_iff₀ hd').mpr hW) hside' (div_nonneg hH hd'.le) hkbound + (fun y=>f (integerAffine u d y)) (fun y=>hf _) + have he : (fun y=>f (integerAffine u d y+a))= + fun y=>f (integerAffine u d (y+k)) := by + funext y + congr 1 + ext i + dsimp [integerAffine] + simp only [hk i] + ring + rw [residue_mean lo hi u d hd,residue_mean lo hi u d hd,he] + apply hbound.trans_eq + have hW' : W≠0 := ne_of_gt (lt_of_lt_of_le (by positivity) hW) + field_simp + +end RoughFaceShift + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace02.lean new file mode 100644 index 0000000000000000000000000000000000000000..f82584a7b4ee406b555364e4b3cf2f04890867a2 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace02.lean @@ -0,0 +1,288 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.ProductExposure03 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end +end + +section +noncomputable section +namespace RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw MeasureTheory +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable + + +def fullDomain {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) : Finset ((Fin m→ℕ)×ℕ) := + (rawDomain X Xp W).filter (fun z=>W.Coprime z.2) + +def labelExposure {m : ℕ} (b : Label m) (R : ℝ) (M : ℕ) : Exposure m where + S := b.scales + r := b.residue + Z := b.width R / (M:ℝ) + Q := b.left R + Δ := b.width R + a := b.pivotResidue + +structure FaceData (m v : ℕ) (G : Type) [Group G] (Γ : Subgroup G) where + A : Fin v→ℤ + P : (Fin (m+v)→ℝ)→G + σ : (G⧸Γ)→(G⧸Γ) + h : (Fin m→ℤ)→Fin v→ℤ + +def FaceData.Valid {m v : ℕ} {G : Type} [Group G] [TopologicalSpace G] {Γ : Subgroup G} + [MetricSpace (G⧸Γ)] {dim : ℕ} (c : RealCoordinates G dim) (D d : ℕ) + (K : NNReal) (H : ℝ) (L : ℤ) (b : Label m) (F : FaceData m v G Γ) : Prop := + (∀ i,HasDegree (fun y=>canonicalLog c (F.P y) i) D) ∧ + LipschitzWith K F.σ ∧ + (∀ t∈productTimes b.scales b.residue L,∀ i,(d:ℤ)∣F.h t i ∧ |(F.h t i:ℝ)|≤H) ∧ + (∀ t∈productTimes b.scales b.residue L,∀ x : Fin v→ℤ, + F.σ (QuotientGroup.mk (F.P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (F.P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+F.h t i:ℤ):ℝ))))) + +def rawFaceEvent {G : Type} [Group G] (Γ : Subgroup G) [MetricSpace (G⧸Γ)] + (m v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η R : ℝ) (d M : ℕ) (L : ℤ) + (F : Label m→FaceData m v G Γ) : Set ((Fin m→ℕ)×ℕ) := + {z | let b:=expose L (M:ℤ) R z + badFace Γ m v c₀ C₀ B η ((labelExposure b R M).Z) d M + (F b).A (F b).P (F b).σ (fun j=>(z.1 j:ℤ))} + +end RoughFaceShift +end +end + +section +noncomputable section +namespace RoughFaceShift +open ProductExposureLabels ProductExposureLaw RawHarmonicProbability MeasureTheory +open RoughSamplingWeights RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable + +lemma joint_ae_fullDomain {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) (hW : 0⟨ha,hz⟩⟩ + +lemma emod_unit (W t : ℕ) (L : ℤ) (hWL : (W:ℤ)∣L) (ht : W.Coprime t) : + ((t:ℤ)%L).natAbs.Coprime W := by + obtain ⟨k,hk⟩ := hWL + have hc : IsCoprime (t:ℤ) (W:ℤ) := Int.isCoprime_iff_nat_coprime.mpr (by simpa using ht.symm) + have hd := hc.add_mul_left_left (-k*((t:ℤ)/L)) + have he : (t:ℤ)+(W:ℤ)*(-k*((t:ℤ)/L))=(t:ℤ)%L := by + calc + _ = (t:ℤ)-((t:ℤ)/L)*L := by rw [hk]; ring + _ = (t:ℤ)%L := by have hh := Int.emod_add_ediv_mul (t:ℤ) L; linarith + rw [he] at hd + simpa only [Int.natAbs_natCast] using Int.isCoprime_iff_nat_coprime.mp hd + +lemma image_residues {m : ℕ} (X : Fin m→ℕ) (Xp W : ℕ) (L M : ℤ) (R : ℝ) + (hL : 0⟨Int.emod_nonneg _ hL.ne',Int.emod_lt_of_pos _ hL⟩, + ⟨Int.emod_nonneg _ hM.ne',Int.emod_lt_of_pos _ hM⟩,?_,?_⟩ + · intro j + exact emod_unit W (z.1 j) L hWL (Finset.mem_filter.mp (ht j)).2 + · exact emod_unit W z.2 M hWM hp + +lemma label_exposure_legal {m : ℕ} (X : Fin m→ℕ) (Xp w M : ℕ) (L : ℤ) (R : ℝ) + (hX : ∀ j,4*primorial w≤X j) (_ : 4*primorial w≤Xp) + (hL : 0(X j:ℝ)) (fun j=>(X j:ℝ)^2) + (R/(M:ℝ)) w M := by + have hW := primorial_pos w + have hMr : (0:ℝ)pow_pos (by norm_num) _ + have hprodpos : 0<∏ j,b.scales j := Finset.prod_pos (fun j _=>hspos j) + have hsone : ∀ j,1≤b.scales j := by + intro j + have hx : (1:ℝ)≤X j := by have:=hX j; exact_mod_cast (show 1≤X j by omega) + exact hx.trans (hg.1 j).1 + have hprod : (1:ℝ)≤∏ j,b.scales j := Finset.one_le_prod₀ (fun j _=>hsone j) + have hwidth : 0pow_pos (by norm_num) _ + have hb : ∀ j,b.scales j≤(t j:ℝ) ∧ (t j:ℝ)<2*b.scales j := by + intro j + have hh := (mem_times (b.scales j) (b.residue j) L (t j) hL).mp + (Fintype.mem_piFinset.mp ht j) + exact ⟨hh.1,hh.2.1⟩ + have hlo : (∏ j,b.scales j)≤∏ j,(t j:ℝ) := + Finset.prod_le_prod₀ (fun j _=>(hs j).le) (fun j _=>(hb j).1) + have hhi : (∏ j,(t j:ℝ))≤2^m*∏ j,b.scales j := by + calc + _ ≤ ∏ j,2*b.scales j := Finset.prod_le_prod₀ (fun j _=>(hs j).le.trans (hb j).1) + (fun j _=>(hb j).2.le) + _ = _ := by rw [Finset.prod_mul_distrib]; simp + have hh := hg.2 _ hlo hhi + constructor <;> linarith [hh.1,hh.2] + +end RoughFaceShift +end +end + +section +noncomputable section +namespace RoughFaceShift +open Finset MeasureTheory +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +lemma real_support_restrict {α : Type*} [MeasurableSpace α] (μ : Measure α) + (S : Finset α) (hS : ∀ᵐ x ∂μ,x∈S) (A : Set α) : μ.real (A∩(S:Set α))=μ.real A := by + apply measureReal_congr + filter_upwards [hS] with x hx + change (x∈A ∧ x∈S)=(x∈A) + exact propext ⟨And.left,fun h=>⟨h,hx⟩⟩ + +lemma singleton_event_sum {α : Type*} [MeasurableSpace α] [MeasurableSingletonClass α] + (μ : Measure α) [SigmaFinite μ] (S : Finset α) (A : Set α) : + (∑ x∈S,if x∈A then μ.real {x} else 0)=μ.real (A∩(S:Set α)) := by + rw [←sum_filter, sum_measureReal_singleton] + congr 1 + ext x + simp only [mem_coe,mem_filter,Set.mem_inter_iff] + exact and_comm + + + +lemma supported_partition_lower {α ι : Type*} [MeasurableSpace α] + [DiscreteMeasurableSpace α] (μ : Measure α) [IsProbabilityMeasure μ] + (S : Finset α) (hS : ∀ᵐ x ∂μ,x∈S) (π : α→ι) (G : Set ι) (A : Set α) + (a δ : ℝ) (ha : 0≤a) (hbad : μ.real {x | π x∉G}≤δ) + (hc : ∀ b∈S.image π,b∈G → a*μ.real (S.filter (fun x=>π x=b):Set α)≤ + μ.real (A∩(S.filter (fun x=>π x=b):Set α))) : + a*(1-δ)≤μ.real A := by + classical + have htotal : (∑ x∈S,μ.real {x})=1 := by + rw [sum_measureReal_singleton] + have hh := real_support_restrict μ S hS Set.univ + simpa only [Set.univ_inter,probReal_univ] using hh + have hbad' : (∑ x∈S.filter (fun x=>π x∉G),μ.real {x})≤δ*(∑ x∈S,μ.real {x}) := by + have he : (S.filter (fun x=>π x∉G):Set α)={x | π x∉G}∩(S:Set α) := by + ext x + simp only [mem_coe,mem_filter,Set.mem_inter_iff,Set.mem_ofPred_eq] + exact and_comm + rw [sum_measureReal_singleton,he,real_support_restrict μ S hS,htotal,mul_one] + exact hbad + have hs (b : ι) (hb : b∈S.image π) (hG : b∈G) : + a*(∑ x∈S.filter (fun x=>π x=b),μ.real {x}) ≤ + ∑ x∈S.filter (fun x=>π x=b),if x∈A then μ.real {x} else 0 := by + rw [sum_measureReal_singleton,singleton_event_sum] + exact hc b hb hG + have hp := RawPartitionSuccess.finite_partition S (fun x=>μ.real {x}) + (fun _ _=>measureReal_nonneg) π G A a δ ha + (by simpa only [htotal] using (show (0:ℝ)<1 by norm_num)) hbad' hs + rwa [htotal,div_one,singleton_event_sum,real_support_restrict μ S hS] at hp + +lemma supported_conditional_bad_bound {α ι : Type*} [MeasurableSpace α] + [DiscreteMeasurableSpace α] (μ : Measure α) [IsProbabilityMeasure μ] + (S : Finset α) (hS : ∀ᵐ x ∂μ,x∈S) (π : α→ι) (G : Set ι) (A : Set α) + (ε : ℝ) (hε : 0≤ε) (hε1 : ε≤1) + (hc : ∀ b∈S.image π,b∈G → μ.real (A∩(S.filter (fun x=>π x=b):Set α))/ + μ.real (S.filter (fun x=>π x=b):Set α)≤ε) : + μ.real A≤ε+μ.real {x | π x∉G} := by + classical + have hs (b : ι) (hb : b∈S.image π) (hG : b∈G) : + (1-ε)*μ.real (S.filter (fun x=>π x=b):Set α)≤ + μ.real (Aᶜ∩(S.filter (fun x=>π x=b):Set α)) := by + let T:=S.filter (fun x=>π x=b) + have hj : μ.real (A∩(T:Set α))+μ.real (Aᶜ∩(T:Set α))=μ.real (T:Set α) := by + rw [←singleton_event_sum,←singleton_event_sum,←sum_measureReal_singleton, + ←sum_add_distrib] + apply sum_congr rfl + intro x hx + by_cases ha : x∈A <;> simp [ha] + have hnum : μ.real (A∩(T:Set α))≤ε*μ.real (T:Set α) := by + by_cases hz : μ.real (T:Set α)=0 + · have hh : μ.real (A∩(T:Set α))≤0 := by + simpa only [hz] using (measureReal_mono (μ:=μ) + (Set.inter_subset_right (s:=A) (t:=(T:Set α)))) + simpa only [hz,mul_zero] using hh + · have hp : 0<μ.real (T:Set α) := lt_of_le_of_ne measureReal_nonneg (Ne.symm hz) + exact (div_le_iff₀ hp).mp (hc b hb hG) + change (1-ε)*μ.real (T:Set α)≤μ.real (Aᶜ∩(T:Set α)) + nlinarith + have hp := supported_partition_lower μ S hS π G Aᶜ (1-ε) (μ.real {x | π x∉G}) + (by linarith) le_rfl hs + rw [measureReal_compl MeasurableSet.of_discrete,probReal_univ] at hp + have hδ : 0≤μ.real {x | π x∉G} := measureReal_nonneg + nlinarith [mul_nonneg hε hδ] + +end RoughFaceShift + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace03.lean new file mode 100644 index 0000000000000000000000000000000000000000..9951a8b03baf103a82824e8381cc746cd01537ab --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughFace03.lean @@ -0,0 +1,262 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughFace02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end +end + +section +noncomputable section +namespace RoughFaceShift +open ProductExposureLabels ProductExposureLaw HarmonicExposure MeasureTheory +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable + +lemma jointFiber_filter {m : ℕ} (E : Set (Fin m→ℤ)) (X : Fin m→ℕ) (Xp W : ℕ) + (S : Fin m→ℝ) (r : Fin m→ℤ) (L : ℤ) (Q Δ : ℝ) (a M : ℤ) : + jointFiber E X Xp W S r L Q Δ a M = + (jointFiber Set.univ X Xp W S r L Q Δ a M).filter (fun z=>(fun j=>(z.1 j:ℤ))∈E) := by + ext z + simp only [jointFiber,Finset.mem_filter,Set.mem_univ,true_and] + tauto + +lemma label_conditional_exact {m : ℕ} (X : Fin m→ℕ) (Xp W M : ℕ) (L : ℤ) (R : ℝ) + (hW : 0(z.1 j:ℤ))∈E (expose L (M:ℤ) R z)}∩ + ((fullDomain X Xp W).filter (fun z=>expose L (M:ℤ) R z=b):Set _)) / + (jointLaw X Xp W hW hX hXp).real + ((fullDomain X Xp W).filter (fun z=>expose L (M:ℤ) R z=b):Set _) = + (jointLaw X Xp W hW hX hXp).real + (jointFiber (E b) X Xp W b.scales b.residue L (b.left R) (b.width R) b.pivotResidue M:Set _) / + (jointLaw X Xp W hW hX hXp).real + (jointFiber Set.univ X Xp W b.scales b.residue L (b.left R) (b.width R) b.pivotResidue M:Set _) := by + have hres := image_residues X Xp W L (M:ℤ) R hL (by exact_mod_cast hM) hWL hWM b hb + have hc := fiber_eq X Xp W (fun j=>by have:=hX j; omega) L (M:ℤ) R hL + (by exact_mod_cast hM) hR b hres.1 hres.2.1 + apply congrArg₂ (fun a b : ℝ=>a/b) + · apply measureReal_congr + filter_upwards [joint_ae_fullDomain X Xp W hW hX hXp] with z hz + have hzr : z∈rawDomain X Xp W := (Finset.mem_filter.mp hz).1 + change ((fun j=>(z.1 j:ℤ))∈E (expose L (M:ℤ) R z) ∧ + z∈(fullDomain X Xp W).filter (fun z=>expose L (M:ℤ) R z=b)) = + (z∈jointFiber (E b) X Xp W b.scales b.residue L (b.left R) (b.width R) b.pivotResidue M) + apply propext + rw [jointFiber_filter,←hc] + simp only [Finset.mem_filter,hz,hzr,true_and] + by_cases he : expose L (M:ℤ) R z=b <;> simp only [he,and_true,true_and,and_false,false_and] + · apply measureReal_congr + filter_upwards [joint_ae_fullDomain X Xp W hW hX hXp] with z hz + have hzr : z∈rawDomain X Xp W := (Finset.mem_filter.mp hz).1 + change (z∈(fullDomain X Xp W).filter (fun z=>expose L (M:ℤ) R z=b)) = + (z∈jointFiber Set.univ X Xp W b.scales b.residue L (b.left R) (b.width R) b.pivotResidue M) + rw [←hc] + simp only [Finset.mem_filter,hz,hzr,true_and] + +end RoughFaceShift +end +end + +section +noncomputable section +namespace RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw RawHarmonicProbability ProductExposureCutoff MeasureTheory +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable + + + +theorem source_raw_face_decay {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} + (Γ : Subgroup G) [MetricSpace (G⧸Γ)] [IsTopologicalGroup G] + (c : RealCoordinates G dim) (hsk : SecondKind c) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0X n j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ n,0R n/(Xp n:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R n/(M n:ℝ))/ + (1+∑ j,(X n j:ℝ)^2)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/(R n/(M n:ℝ))) atTop (𝓝 0)) + (hWM : ∀ n,(primorial (w n):ℤ)∣(M n:ℤ)) + (hM : ∀ n,0(X n j:ℝ)/(L n:ℝ)) atTop atTop) + (F : ℕ→Label m→FaceData m v G Γ) + (hF : ∀ n b,b∈(fullDomain (X n) (Xp n) (primorial (w n))).image + (expose (L n) (M n:ℤ) (R n)) → Good (X n) (Xp n) (R n) b → + FaceData.Valid c D d K (H n) (L n) b (F n b)) : + Tendsto (fun n=>(jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) + (hX n) (hXp n)).real (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n))) + atTop (𝓝 0) + := by + have hXpr (n : ℕ) : (0:ℝ)R n/(M n:ℝ)) atTop atTop := by + apply tendsto_atTop_mono (fun n=>?_) (hZ 1 (by norm_num)) + rw [Real.rpow_one] + exact div_le_self (div_nonneg (hR n).le (hMr n).le) + (by have:=Finset.sum_nonneg (fun j (_ : j∈Finset.univ)=>sq_nonneg (X n j:ℝ));linarith) + have hRmin : ∀ᶠ n in atTop,4*(M n:ℝ)*2^m≤R n := by + filter_upwards [(tendsto_atTop.mp hZtop) (4*2^m)] with n hn + have hh := (le_div_iff₀ (hMr n)).mp hn + nlinarith + have hUV : ∀ n j,(X n j:ℝ)≤(X n j:ℝ)^2 := by + intro n j + have h1 : (1:ℝ)≤X n j := by + have:=hX n j;have:=primorial_pos (w n);exact_mod_cast (show 1≤X n j by omega) + nlinarith + have hu := source_raw_joint_face_uniform Γ c hsk hΓ htop m v D d hd c₀ C₀ B K η + hc₀ hC₀ hB hη w M (fun n j=>(X n j:ℝ)) (fun n j=>(X n j:ℝ)^2) + (fun n=>R n/(M n:ℝ)) H L hw + (fun j=>tendsto_natCast_atTop_atTop.comp (hXt j)) hUV hZ hH hHZ hWM hM hMs + hL hsm hWL hXL + have hbad : Tendsto (fun n=>(jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) + (hX n) (hXp n)).real {z | ¬Good (X n) (Xp n) (R n) (expose (L n) (M n:ℤ) (R n) z)}) + atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun _=>measureReal_nonneg)) + · filter_upwards [hRsmall] with n hn + exact bad_good_bound (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n) + (L n) (M n:ℤ) (R n) (hR n) (by linarith [hR n]) + · have ht := tendsto_finsetSum Finset.univ (fun j _=> + raw_cutoff_decay (fun n=>X n j) (fun n=>primorial (w n)) 1 + (fun _=>primorial_pos _) (fun n=>hX n j) (hXt j)) + have hp := raw_cutoff_decay Xp (fun n=>primorial (w n)) (m+2) + (fun _=>primorial_pos _) hXp hXpt + simpa using ht.add hp + apply tendsto_order.2 + constructor + · intro a ha + exact Eventually.of_forall (fun _=>lt_of_lt_of_le ha measureReal_nonneg) + · intro e he + let ε := min (e/3) (1/2) + have hε : 0<ε := lt_min (by linarith) (by norm_num) + have hε1 : ε≤1 := (min_le_right _ _).trans (by norm_num) + filter_upwards [hu ε hε,hRsmall,hRmin,(tendsto_order.mp hbad).2 (e/3) (by linarith)] + with n hn hsmall hmin hbadn + have hb := supported_conditional_bad_bound + (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)) + (fullDomain (X n) (Xp n) (primorial (w n))) + (joint_ae_fullDomain (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)) + (expose (L n) (M n:ℤ) (R n)) {b | Good (X n) (Xp n) (R n) b} + (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n)) ε hε.le hε1 + (by + intro b hb hg + have hlegal := label_exposure_legal (X n) (Xp n) (w n) (M n) (L n) (R n) + (hX n) (hXp n) (hL n) (hM n) (hWL n) (hWM n) (hR n) hsmall hmin b hb hg + have hres := image_residues (X n) (Xp n) (primorial (w n)) (L n) (M n:ℤ) (R n) + (hL n) (by exact_mod_cast hM n) (hWL n) (hWM n) b hb + have hv := hF n b hb hg + have hpre := good_preimages (X n) (Xp n) (R n) (hR n).le (L n) (hL n) b hg + have hlocal := hn (labelExposure b (R n) (M n)) hlegal (X n) (Xp n) (hX n) (hXp n) + hres.2.2.2 (fun j=>(hg.1 j).1) (fun j=>(hg.1 j).2) + (fun t ht=>(hpre t ht).1) (fun t ht=>(hpre t ht).2) + (F n b).A (F n b).P hv.1 (F n b).σ hv.2.1 (F n b).h hv.2.2.1 hv.2.2.2 + have heq := label_conditional_exact (X n) (Xp n) (primorial (w n)) (M n) (L n) (R n) + (primorial_pos _) (hX n) (hXp n) (hL n) (hM n) (hR n) (hWL n) (hWM n) b hb + (fun b=>{t | badFace Γ m v c₀ C₀ B η (labelExposure b (R n) (M n)).Z d (M n) + (F n b).A (F n b).P (F n b).σ t}) + exact heq.trans_le hlocal.le) + have hεe : ε≤e/3 := min_le_left _ _ + change (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)).real + (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n)) ≤ ε+ + (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)).real + {z | ¬Good (X n) (Xp n) (R n) (expose (L n) (M n:ℤ) (R n) z)} at hb + change _S n j) atTop atTop) + (hZ : ∀ a : ℝ,0Z n/(1+∑ j,S n j)^a) atTop atTop) + (hM : ∀ n,0S n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ((exceptionalProduct Γ m v c₀ C₀ B η (Z n) d (M n) A P (S n) (r n) (L n)).card:ℝ)/ + ((productTimes (S n) (r n) (L n)).card:ℝ)<ε := by + classical + let : MetricSpace (G⧸Λ) := coordinateQuotientMetric c Λ hΛ + let V : @Homeomorph (G⧸Γ) (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) + mtr.toUniformSpace.toTopologicalSpace := + @Homeomorph.mk _ _ (QuotientGroup.instTopologicalSpace Γ) + mtr.toUniformSpace.toTopologicalSpace (Equiv.refl _) (by rw [htop];exact @continuous_id (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ)) + (by rw [htop];exact @continuous_id (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ)) + obtain ⟨K,hK⟩ := RoughCoverTests.uniform_cover_tests c Λ Γ hΛ hle V B B (η/4) B.2 (by positivity) + let η₀ : NNReal := ⟨η/4,by positivity⟩ + let B' : NNReal := K+B+η₀+1 + have hKB : K≤B' := by dsimp [B'];nlinarith [B.2,η₀.2] + have hBB : (B:ℝ)+η/4≤B' := by + change (B:ℝ)+η/4≤(K:ℝ)+B+(η₀:ℝ)+1 + change (B:ℝ)+η/4≤(K:ℝ)+B+η/4+1 + linarith [K.2] + have hB' : 0(hgb y).trans hBB,?_⟩ + have he := herr (Fin v→ℤ) (physicalResidueBox lo hi res d) + (nestedBox lo hi res A d (M n) (∏ j,t j)) + (fun x=>P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))) η hdisc + linarith + exact (div_le_div_of_nonneg_right (by exact_mod_cast Finset.card_le_card hsub) + (Nat.cast_nonneg _)).trans_lt (hn A P hP) + +end RoughCoveredFace + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughInterpolation01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughInterpolation01.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e76969bd6a0c08a7de95115d082be9d47b6bab2 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughInterpolation01.lean @@ -0,0 +1,351 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.LagrangeBounds01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +open _root_.Polynomial _root_.OAI.Polynomial Finset +open scoped BigOperators +open _root_.Polynomial _root_.OAI.Polynomial + +namespace RoughInterpolation + +def Integral (x : ℚ) : Prop := ∃ z : ℤ, (z : ℚ) = x + +lemma primitive_linear {a b : ℤ} (h : IsCoprime a b) : + (C a + C b * X).IsPrimitive := by + intro d hd + have hc := (C_dvd_iff_dvd_coeff d (C a + C b * X)).mp hd + exact h.isUnit_of_dvd' (by simpa using hc 0) (by simpa only [coeff_add, coeff_C, coeff_C_mul, coeff_X, + one_ne_zero, ↓reduceIte, mul_one, zero_add] using hc 1) + +lemma primitive_pow {p : ℤ[X]} (hp : p.IsPrimitive) (e : ℕ) : + (p ^ e).IsPrimitive := by + induction e with + | zero => simp + | succ e he => simpa [pow_succ] using he.mul hp + + +theorem integral_scaled_quotient {a b D : ℤ} (hab : IsCoprime a b) + (e : ℕ) {R M : ℚ[X]} + (hR : C (D : ℚ) * R ∈ lifts (algebraMap ℤ ℚ)) + (hdiv : R = (C (a : ℚ) + C (b : ℚ) * X) ^ e * M) : + C (D : ℚ) * M ∈ lifts (algebraMap ℤ ℚ) := by + apply (primitive_pow (primitive_linear hab) e).map_mul_mem_lifts_iff.mp + simpa [hdiv, mul_assoc, mul_left_comm, mul_comm] using hR + + +theorem integral_of_coprime_multiples {a b : ℤ} (hab : IsCoprime a b) {x : ℚ} + (ha : Integral ((a : ℚ) * x)) (hb : Integral ((b : ℚ) * x)) : Integral x := by + obtain ⟨u, v, huv⟩ := hab + obtain ⟨y, hy⟩ := ha + obtain ⟨z, hz⟩ := hb + refine ⟨u * y + v * z, ?_⟩ + push_cast + rw [hy, hz] + have huv' : (u : ℚ) * a + (v : ℚ) * b = 1 := by exact_mod_cast huv + linear_combination huv' * x + +lemma integral_eval_of_lifts {p : ℚ[X]} (hp : p ∈ lifts (algebraMap ℤ ℚ)) (z : ℤ) : + Integral (p.eval (z : ℚ)) := by + obtain ⟨p, rfl⟩ := (mem_lifts _).mp hp + exact ⟨p.eval z, by simp⟩ + + +theorem quotient_integral_at {a b D z : ℤ} (hab : IsCoprime a b) + (hDz : IsCoprime D (a + b * z)) (e : ℕ) {R M : ℚ[X]} + (hR : C (D : ℚ) * R ∈ lifts (algebraMap ℤ ℚ)) + (hz : Integral (R.eval (z : ℚ))) + (hdiv : R = (C (a : ℚ) + C (b : ℚ) * X) ^ e * M) : + Integral (M.eval (z : ℚ)) := by + have hMD := integral_eval_of_lifts (integral_scaled_quotient hab e hR hdiv) z + have hMt : Integral (((a + b * z : ℤ) : ℚ) ^ e * M.eval (z : ℚ)) := by + simpa [hdiv] using hz + apply integral_of_coprime_multiples hDz.pow_right + · simpa using hMD + · simpa using hMt + + +lemma integral_rational_eval {p : ℚ[X]} (hp : p ∈ lifts (algebraMap ℤ ℚ)) + {q : ℕ} (hq : p.natDegree ≤ q) (a b : ℤ) (hb : b ≠ 0) : + Integral (p.eval ((a : ℚ) / b) * (b : ℚ) ^ q) := by + obtain ⟨P, rfl⟩ := (mem_lifts _).mp hp + refine ⟨MvPolynomial.eval ![a, b] (P.homogenize q), ?_⟩ + have heq := eval_homogenize hq ![(a : ℚ), (b : ℚ)] (by simpa using hb) + simp only [Matrix.cons_val_zero, Matrix.cons_val_one] at heq + rw [← heq, homogenize_map] + change (algebraMap ℤ ℚ) (MvPolynomial.eval ![a, b] (P.homogenize q)) = _ + rw [MvPolynomial.map_eval] + have hv : (algebraMap ℤ ℚ) ∘ ![a, b] = ![(a : ℚ), (b : ℚ)] := by + funext i + fin_cases i <;> rfl + rw [hv] + +lemma lifts_iterate_derivative {p : ℚ[X]} (hp : p ∈ lifts (algebraMap ℤ ℚ)) (j : ℕ) : + derivative^[j] p ∈ lifts (algebraMap ℤ ℚ) := by + obtain ⟨P, rfl⟩ := (mem_lifts _).mp hp + exact (mem_lifts _).mpr ⟨derivative^[j] P, (iterate_derivative_map _ _ _).symm⟩ + + +lemma derivative_rational_denominator {R : ℚ[X]} {D a b : ℤ} {q : ℕ} + (hR : C (D : ℚ) * R ∈ lifts (algebraMap ℤ ℚ)) + (hq : R.natDegree ≤ q) (hb : b ≠ 0) (j : ℕ) : + Integral ((D : ℚ) * (b : ℚ) ^ q * + (derivative^[j] R).eval ((a : ℚ) / b)) := by + have h := integral_rational_eval (lifts_iterate_derivative hR j) + ((natDegree_iterate_derivative _ _).trans + ((Nat.sub_le _ _).trans ((natDegree_C_mul_le _ _).trans hq))) a b hb + rw [iterate_derivative_C_mul, eval_mul, eval_C] at h + simpa only [mul_assoc, mul_left_comm, mul_comm] using h + + +lemma integral_eq_zero_of_abs_lt_one {x : ℚ} (hx : Integral x) (hsmall : |x| < 1) : x = 0 := by + obtain ⟨z, rfl⟩ := hx + have hz : |z| < 1 := by exact_mod_cast hsmall + have : z = 0 := by + by_contra h + have := Int.one_le_abs h + omega + simp [this] + + +theorem derivative_eq_zero_of_small {R : ℚ[X]} {D a b : ℤ} {q : ℕ} + (hR : C (D : ℚ) * R ∈ lifts (algebraMap ℤ ℚ)) + (hq : R.natDegree ≤ q) (hD : D ≠ 0) (hb : b ≠ 0) (j : ℕ) + (hsmall : |(derivative^[j] R).eval ((a : ℚ) / b)| < + 1 / (|(D : ℚ)| * |(b : ℚ)| ^ q)) : + (derivative^[j] R).eval ((a : ℚ) / b) = 0 := by + have hDq : (D : ℚ) ≠ 0 := by exact_mod_cast hD + have hbq : (b : ℚ) ≠ 0 := by exact_mod_cast hb + have hpos : 0 < |(D : ℚ)| * |(b : ℚ)| ^ q := by positivity + have hz := integral_eq_zero_of_abs_lt_one (derivative_rational_denominator hR hq hb j) + (show |(D : ℚ) * (b : ℚ) ^ q * (derivative^[j] R).eval ((a : ℚ) / b)| < 1 by + rw [abs_mul, abs_mul, abs_pow, mul_comm] + exact (lt_div_iff₀ hpos).mp hsmall) + exact (mul_eq_zero.mp hz).resolve_left (mul_ne_zero hDq (pow_ne_zero _ hbq)) + + +theorem exact_linear_division {R : ℚ[X]} {a b : ℚ} (hb : b ≠ 0) {e : ℕ} + (hzero : ∀ j < e, (derivative^[j] R).eval (-a / b) = 0) : + ∃ M : ℚ[X], R = (C a + C b * X) ^ e * M := by + have hroot : (X - C (-a / b)) ^ e ∣ R := by + by_cases hR : R = 0 + · simp [hR] + by_cases he : e = 0 + · simp [he] + apply (le_rootMultiplicity_iff hR).mp + have h := lt_rootMultiplicity_of_isRoot_iterate_derivative hR + (n := e - 1) (fun j hj => hzero j (by omega)) + omega + obtain ⟨M, hM⟩ := hroot + refine ⟨C (b⁻¹ ^ e) * M, ?_⟩ + rw [hM] + have heq : C a + C b * X = C b * (X - C (-a / b)) := by + rw [mul_sub, ← map_mul] + have ht : b * (-a / b) = -a := by field_simp + rw [ht, map_neg] + ring + rw [heq, mul_pow] + have hunit : (C b : ℚ[X]) ^ e * C (b⁻¹ ^ e) = 1 := by + rw [← map_pow, ← map_mul, ← mul_pow, mul_inv_cancel₀ hb, one_pow, map_one] + calc + _ = ((C b) ^ e * C (b⁻¹ ^ e)) * ((X - C (-a / b)) ^ e * M) := by + rw [hunit, one_mul] + _ = _ := by ring + + +lemma linear_power_derivative_zero {F : Type*} [Field F] {a b : F} (hb : b ≠ 0) + (θ : F[X]) {e j : ℕ} (hj : j < e) : + (derivative^[j] ((C a + C b * X) ^ e * θ)).eval (-a / b) = 0 := by + have hd : (C a + C b * X) ^ (e - j) ∣ + derivative^[j] ((C a + C b * X) ^ e * θ) := + pow_sub_dvd_iterate_derivative_of_pow_dvd j (dvd_mul_right _ _) + obtain ⟨P, hP⟩ := hd + rw [hP, eval_mul, eval_pow, eval_add, eval_C, eval_mul, eval_C, eval_X] + have hz : a + b * (-a / b) = 0 := by field_simp; ring + rw [hz, zero_pow (by omega : e - j ≠ 0), zero_mul] + + +lemma integral_eq_of_near {D : ℤ} (hD : D ≠ 0) {x : ℚ} + (hx : Integral ((D : ℚ) * x)) (n : ℤ) + (hnear : |x - (n : ℚ)| < 1 / |(D : ℚ)|) : x = n := by + obtain ⟨m, hm⟩ := hx + have hint : Integral ((D : ℚ) * (x - n)) := by + refine ⟨m - D * n, ?_⟩ + push_cast + rw [hm] + ring + have hDq : (D : ℚ) ≠ 0 := by exact_mod_cast hD + have hz := integral_eq_zero_of_abs_lt_one hint + (show |(D : ℚ) * (x - n)| < 1 by + rw [abs_mul, mul_comm] + exact (lt_div_iff₀ (abs_pos.mpr hDq)).mp hnear) + exact sub_eq_zero.mp ((mul_eq_zero.mp hz).resolve_left hDq) + +end RoughInterpolation + + + +noncomputable section +namespace ExactInterpolation +open LagrangeBounds RoughInterpolation + +def uniformConstant (q : ℕ) : ℝ := (q + 1 : ℝ) * (2 * q) ^ q + +def derivativeConstant (N q : ℕ) : ℝ := 1 + ∑ j ∈ range q, + ∑ i : Fin (q + 1), coefficientBound + (derivative^[j] (Lagrange.basis univ (fun i => (nodes N q i : ℝ)) i)) q + +lemma derivativeConstant_pos (N q : ℕ) : 0 < derivativeConstant N q := by + have : 0 ≤ ∑ j ∈ range q, ∑ i : Fin (q + 1), coefficientBound + (derivative^[j] (Lagrange.basis univ (fun i => (nodes N q i : ℝ)) i)) q := + sum_nonneg (fun _ _ => sum_nonneg (fun _ _ => coefficientBound_nonneg _ _)) + unfold derivativeConstant + linarith + +lemma derivative_sum_le {N q j : ℕ} (hj : j < q) : + (∑ i : Fin (q + 1), coefficientBound + (derivative^[j] (Lagrange.basis univ (fun i => (nodes N q i : ℝ)) i)) q) ≤ + derivativeConstant N q := by + have h := single_le_sum (s := range q) + (f := fun j => ∑ i : Fin (q + 1), coefficientBound + (derivative^[j] (Lagrange.basis univ (fun i => (nodes N q i : ℝ)) i)) q) + (fun _ _ => sum_nonneg (fun _ _ => coefficientBound_nonneg _ _)) (mem_range.mpr hj) + unfold derivativeConstant + linarith + +lemma quotient_degree {a b : ℚ} (hb : b ≠ 0) {e q : ℕ} {R M : ℚ[X]} + (hR : R.natDegree ≤ q) (hdiv : R = (C a + C b * X) ^ e * M) : + M.natDegree ≤ q - e := by + by_cases hM : M = 0 + · simp [hM] + have hlin : (C a + C b * X).natDegree = 1 := by + rw [natDegree_add_eq_right_of_natDegree_lt (by simp [natDegree_C_mul_X b hb]), + natDegree_C_mul_X b hb] + have hne : C a + C b * X ≠ 0 := by + intro h + rw [h, natDegree_zero] at hlin + omega + rw [hdiv, natDegree_mul (pow_ne_zero _ hne) hM, natDegree_pow, hlin, mul_one] at hR + omega + + + +theorem quantitative_exact_division {N q : ℕ} (hq : 0 < q) (hN : 2 * q ≤ N) : + ∃ D : ℤ, D ≠ 0 ∧ ∀ (a b : ℤ) (e : ℕ) (θ : ℝ[X]) (ε : ℝ), + b ≠ 0 → IsCoprime a b → e ≤ q → 0 ≤ ε → + ((C (a : ℝ) + C (b : ℝ) * X) ^ e * θ).natDegree ≤ q → + (∀ z : ℤ, 0 ≤ z → z ≤ N → ∃ n : ℤ, + |((C (a : ℝ) + C (b : ℝ) * X) ^ e * θ).eval (z : ℝ) - (n : ℝ)| ≤ ε) → + (∀ z : ℤ, 0 ≤ z → z ≤ N → IsCoprime D (a + b * z)) → + (uniformConstant q + 1) * ε < 1 / |(D : ℝ)| → + ε * derivativeConstant N q * (1 + |-(a : ℝ) / b|) ^ q < + 1 / (|(D : ℝ)| * |(b : ℝ)| ^ q) → + ∃ M : ℚ[X], M.natDegree ≤ q - e ∧ + C (D : ℚ) * M ∈ lifts (algebraMap ℤ ℚ) ∧ + (∀ z : ℤ, 0 ≤ z → z ≤ N → Integral (M.eval (z : ℚ))) ∧ + ∀ x : ℝ, x ∈ Set.Icc 0 (N : ℝ) → + |((M.map (algebraMap ℚ ℝ)).eval x - θ.eval x) * ((a : ℝ) + b * x) ^ e| ≤ + uniformConstant q * ε := by + obtain ⟨D, hD, hden⟩ := interpolation_common_denominator + (univ : Finset (Fin (q + 1))) (fun i => (nodes N q i : ℚ)) + refine ⟨D, hD, ?_⟩ + intro a b e θ ε hb hab he hε hT hnear hcop hsmall hderiv + let T : ℝ[X] := (C (a : ℝ) + C (b : ℝ) * X) ^ e * θ + have hnear' : ∀ i : Fin (q + 1), ∃ n : ℤ, |T.eval (nodes N q i : ℝ) - n| ≤ ε := by + intro i + have hi := nodes_mem (N := N) i + exact hnear (nodes N q i) (by exact_mod_cast hi.1) (by exact_mod_cast hi.2) + choose r hr using hnear' + let R : ℚ[X] := Lagrange.interpolate univ (fun i => (nodes N q i : ℚ)) (fun i => (r i : ℚ)) + have hRlifts : C (D : ℚ) * R ∈ lifts (algebraMap ℤ ℚ) := hden r + have hinj : Function.Injective (fun i : Fin (q + 1) => (nodes N q i : ℚ)) := by + intro i j hij + apply nodes_injective hq hN + change (nodes N q i : ℚ) = nodes N q j at hij + have hz : nodes N q i = nodes N q j := by exact_mod_cast hij + change (nodes N q i : ℝ) = nodes N q j + exact_mod_cast hz + have hRdeg : R.natDegree ≤ q := by + apply natDegree_le_of_degree_le + have h := Lagrange.degree_interpolate_le (s := univ) (fun i => (r i : ℚ)) hinj.injOn + simpa only [card_univ, Fintype.card_fin, Nat.add_sub_cancel] using h + have hRmap : R.map (algebraMap ℚ ℝ) = + Lagrange.interpolate univ (fun i => (nodes N q i : ℝ)) (fun i => (r i : ℝ)) := by + change (Lagrange.interpolate univ (fun i => (nodes N q i : ℚ)) (fun i => (r i : ℚ))).map _ = _ + rw [map_interpolate] + simp only [map_intCast] + have herr (x : ℝ) (hx : x ∈ Set.Icc 0 (N : ℝ)) : + |(R.map (algebraMap ℚ ℝ)).eval x - T.eval x| ≤ uniformConstant q * ε := by + rw [hRmap] + apply uniform_integer_interpolation hq hN T hT _ hε _ hx + intro i + simpa only [abs_sub_comm] using hr i + have hzero : ∀ j < e, (derivative^[j] R).eval (-(a : ℚ) / b) = 0 := by + intro j hj + apply derivative_eq_zero_of_small (a := -a) hRlifts hRdeg hD hb j + have hTd : T.degree < ((univ : Finset (Fin (q + 1))).card : WithBot ℕ) := by + simp only [card_univ, Fintype.card_fin] + exact lt_of_le_of_lt (degree_le_natDegree.trans (show (T.natDegree : WithBot ℕ) ≤ (q : WithBot ℕ) by exact_mod_cast hT)) + (by exact_mod_cast Nat.lt_succ_self q) + have h := derivative_interpolation_error univ (fun i => (nodes N q i : ℝ)) + (nodes_injective hq hN).injOn (q := q) (by simp) T hTd (fun i => (r i : ℝ)) + hε (fun i _ => by simpa only [abs_sub_comm] using hr i) j (-(a : ℝ) / b) + rw [← hRmap, iterate_derivative_sub, eval_sub, + linear_power_derivative_zero (by exact_mod_cast hb) θ hj, sub_zero] at h + have h' : |(derivative^[j] (R.map (algebraMap ℚ ℝ))).eval (-(a : ℝ) / b)| < + 1 / (|(D : ℝ)| * |(b : ℝ)| ^ q) := by + apply lt_of_le_of_lt h + exact (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (derivative_sum_le (by omega : j < q)) hε) + (by positivity)).trans_lt hderiv + rw [iterate_derivative_map] at h' + have heval : ((derivative^[j] R).map (algebraMap ℚ ℝ)).eval (-(a : ℝ) / b) = + (((derivative^[j] R).eval (-(a : ℚ) / b) : ℚ) : ℝ) := by + rw [eval_map] + simpa only [eq_ratCast, Rat.cast_div, Rat.cast_neg, Rat.cast_intCast] using + (eval₂_at_apply (p := derivative^[j] R) (algebraMap ℚ ℝ) (-(a : ℚ) / b)) + rw [heval] at h' + exact_mod_cast h' + obtain ⟨M, hdiv⟩ := exact_linear_division (by exact_mod_cast hb) hzero + refine ⟨M, quotient_degree (by exact_mod_cast hb) hRdeg hdiv, + integral_scaled_quotient hab e hRlifts hdiv, ?_, ?_⟩ + · intro z hz0 hzN + apply quotient_integral_at hab (hcop z hz0 hzN) e hRlifts _ hdiv + have hx : (z : ℝ) ∈ Set.Icc 0 (N : ℝ) := ⟨by exact_mod_cast hz0, by exact_mod_cast hzN⟩ + obtain ⟨n, hn⟩ := hnear z hz0 hzN + have hscaled := integral_eval_of_lifts hRlifts z + simp only [eval_mul, eval_C] at hscaled + have hRn : |(R.map (algebraMap ℚ ℝ)).eval (z : ℝ) - (n : ℝ)| < 1 / |(D : ℝ)| := by + calc + _ ≤ |(R.map (algebraMap ℚ ℝ)).eval (z : ℝ) - T.eval (z : ℝ)| + |T.eval (z : ℝ) - (n : ℝ)| := abs_sub_le _ _ _ + _ ≤ uniformConstant q * ε + ε := add_le_add (herr _ hx) hn + _ = (uniformConstant q + 1) * ε := by ring + _ < _ := hsmall + have heval : (R.map (algebraMap ℚ ℝ)).eval (z : ℝ) = ((R.eval (z : ℚ) : ℚ) : ℝ) := by + rw [eval_map] + simpa only [eq_ratCast, Rat.cast_intCast] using (eval₂_at_apply (p := R) (algebraMap ℚ ℝ) (z : ℚ)) + rw [heval] at hRn + have heq := integral_eq_of_near hD hscaled n (by exact_mod_cast hRn) + exact ⟨n, heq.symm⟩ + · intro x hx + have h := herr x hx + rw [hdiv] at h + simp [T] at h + simp only [eval_map_algebraMap] + convert h using 1 + ring_nf + +end ExactInterpolation + + + + + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughJoint01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughJoint01.lean new file mode 100644 index 0000000000000000000000000000000000000000..17b5b5c77cef757cb27f581ef9a71945c472215c --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughJoint01.lean @@ -0,0 +1,405 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughSampling02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +end + + +end + +section + + + + +noncomputable section +open scoped BigOperators + +namespace RoughAnalyticExtraction +open FinitePieceAverages RoughSamplingWeights ComparableBoxLeibman +open CorrectedBoxLeibman PolynomialLineCoefficients + +lemma mean_eq_expect {α : Type*} (s : Finset α) (f : α → ℂ) : + mean s f = 𝔼 x ∈ s, f x := by + rw [mean, Finset.expect_eq_sum_div_card, div_eq_mul_inv, mul_comm] + +lemma boxIndices_eq_halfOpen {v : ℕ} (lo hi : Fin v → ℝ) : + boxIndices lo hi (fun _ => 0) 1 = halfOpenBox v lo hi := by + ext x + rw [mem_boxIndices _ _ _ _ zero_lt_one, mem_halfOpenBox] + simp only [zero_add, one_mul] + +lemma physicalResidueBox_mod {v : ℕ} (lo hi : Fin v → ℝ) (b : Fin v → ℤ) + (p : ℕ) : + physicalResidueBox lo hi (fun i => b i % p) p = physicalResidueBox lo hi b p := by + classical + unfold physicalResidueBox + congr 1 + funext x + apply propext + simp only [Int.ModEq, Int.emod_emod] + +lemma physicalResidueBox_one {v : ℕ} (lo hi : Fin v → ℝ) : + physicalResidueBox lo hi (fun _ => 0) 1 = boxIndices lo hi (fun _ => 0) 1 := by + classical + simp [physicalResidueBox, Int.ModEq] + +lemma halfOpen_bounds_pointwise {v : ℕ} (lo hi : Fin v → ℝ) (c C Z : ℝ) + (hc : 0 < c) (hZ : 2/c ≤ Z) + (hside : ∀ i, c*Z ≤ hi i-lo i) + (hbox : ∀ i, -C*Z ≤ lo i ∧ hi i ≤ C*Z) : + (∀ i, (c/2)*Z ≤ ((⌈hi i⌉:ℝ)-1)-lo i) ∧ + (∀ i, -C*Z ≤ lo i ∧ ((⌈hi i⌉:ℝ)-1) ≤ C*Z) := by + have hcZ : 2 ≤ c*Z := by + have := (div_le_iff₀ hc).mp hZ + nlinarith + constructor + · intro i + have := Int.le_ceil (hi i) + have := hside i + nlinarith + · intro i + refine ⟨(hbox i).1, ?_⟩ + have := Int.ceil_lt_add_one (hi i) + have := (hbox i).2 + linarith + + + +def integerDilation (v p : ℕ) : (Fin v → ℤ) →+ (Fin v → ℤ) where + toFun x := fun i => (p:ℤ)*x i + map_zero' := by ext i; simp + map_add' x y := by ext i; simp [mul_add] + +lemma polynomial_affine {G : Type*} [Group G] (H : CubeFaces.Filtration G) + {v : ℕ} {f : (Fin v → ℤ) → G} (hf : LeibmanSquare.Polynomial H 0 f) + (u : Fin v → ℤ) (p : ℕ) : + LeibmanSquare.Polynomial H 0 (fun x => f (integerAffine u p x)) := + LeibmanSquare.polynomial_affine H hf (integerDilation v p) u + + + +def CharacterObstruction {G : Type*} [Group G] [TopologicalSpace G] {v s : ℕ} + (Γ : Subgroup G) (f : (Fin v → ℤ) → G) + (ξ : G →* Multiplicative ℝ) (u : Fin v → ℤ) (p : ℕ) (Z A : ℝ) : Prop := + ξ ≠ 1 ∧ Continuous ξ ∧ (∀ g ∈ Γ, ∃ z : ℤ, (ξ g).toAdd = z) ∧ + ∃ θ : PolynomialLineCoefficients.Grid v s → ℝ, + (∀ x, gridEval θ (fun i => (x i:ℝ)) = (ξ (f x)).toAdd) ∧ + (∀ I, s < totalDegree I → θ I = 0) ∧ + ∀ I, 0 < totalDegree I → + TriangularLatticeRecovery.circleNorm (gridDilate p (gridTranslate θ u) I) + ≤ A * ((p:ℝ)/Z) ^ totalDegree I + +section Nilmanifold +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus RationalTailCoordinates UnitAddTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0 = ⊤) (h1 : H.level 1 = ⊤) +variable [∀ i, (H.level i).Normal] +variable (s : ℕ) (hs : H.level (s+1) = ⊥) +variable (q : ℕ → ℕ) (hqbound : ∀ k, q k ≤ t+d) +variable (hq : ∀ k (g : G), g ∈ H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i = 0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g ∈ Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i = z) +variable [MeasurableSpace (G⧸Γ)] +variable [hBorel : @BorelSpace (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) inferInstance] +variable [mtr : MetricSpace (G⧸Γ)] +variable (htop : mtr.toUniformSpace.toTopologicalSpace = QuotientGroup.instTopologicalSpace Γ) +local instance : TopologicalSpace (G⧸Γ) := mtr.toUniformSpace.toTopologicalSpace + +include hsk h0 h1 hs hqbound hq hΓ htop in + + +theorem residue_haar_character + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0 < c₀) (hC₀ : 0 < C₀) (hB : 0 < B) (hη : 0 < η) : + letI : CompactSpace (G⧸Γ) := metric_compact c Γ hΓ mtr htop + letI : BorelSpace (G⧸Γ) := metric_borelSpace Γ mtr htop + ∃ U : Finset (G →* Multiplicative ℝ), ∃ A T : ℝ, 0 < A ∧ 1 ≤ T ∧ + ∀ (Z : ℝ) (p : ℕ), 0 < p → T ≤ Z/p → + ∀ (lo hi : Fin v → ℝ) (u : Fin v → ℤ), + (∀ i, 0 ≤ u i ∧ u i < p) → + (∀ i, c₀*Z ≤ hi i-lo i) → + (∀ i, -C₀*Z ≤ lo i ∧ hi i ≤ C₀*Z) → + ∀ f : (Fin v → ℤ) → G, LeibmanSquare.Polynomial H 0 f → + (∃ F : C(G⧸Γ,ℂ), LipschitzWith B F ∧ ‖F‖ ≤ B ∧ + η ≤ ‖mean (physicalResidueBox lo hi u p) (fun x => F (QuotientGroup.mk (f x))) - + ∫ y, F y ∂μ‖) → + ∃ ξ ∈ U, CharacterObstruction (s:=s) Γ f ξ u p Z A := by + classical + let : CompactSpace (G⧸Γ) := metric_compact c Γ hΓ mtr htop + let : BorelSpace (G⧸Γ) := metric_borelSpace Γ mtr htop + obtain ⟨U,A,Z₀,hA,hZ₀,hprod⟩ := comparable_real_box c hsk H h0 h1 s hs q hqbound hq Γ hΓ htop + μ v (c₀/2) (C₀+1) B η (by positivity) (by positivity) hB hη + let T := max 1 (max (2/c₀) Z₀) + refine ⟨U,A,T,hA,le_max_left _ _,?_⟩ + intro Z p hp hZT lo hi u hu hside hbox f hf hbad + have hpR : (0:ℝ) < p := by exact_mod_cast hp + have hscale : 1 ≤ Z/p := (le_max_left _ _).trans hZT + have hpZ : (p:ℝ) ≤ Z := by simpa using (le_div_iff₀ hpR).mp hscale + have hZ : 0 < Z := hpR.trans_le hpZ + have hscale₂ : 2/c₀ ≤ Z/p := (le_max_of_le_right (le_max_left _ _)).trans hZT + have hscale₀ : Z₀ ≤ Z/p := (le_max_of_le_right (le_max_right _ _)).trans hZT + have hg := rescaled_geometry lo hi u p hp Z C₀ c₀ hpZ hC₀.le + (fun i => ⟨(hu i).1,(hu i).2.le⟩) (by simpa only [neg_mul] using hbox) hside + have hb := halfOpen_bounds_pointwise (rescaledEndpoint lo u p) (rescaledEndpoint hi u p) + c₀ (C₀+1) (Z/p) hc₀ hscale₂ (fun i => (hg i).2.2) + (fun i => ⟨(hg i).1,(hg i).2.1⟩) + obtain ⟨F,hFL,hFB,hFD⟩ := hbad + have hbad' : η ≤ ‖(𝔼 x ∈ integerBox v (rescaledEndpoint lo u p) + (fun i => (⌈rescaledEndpoint hi u p i⌉:ℝ)-1), + F (QuotientGroup.mk (f (integerAffine u p x)))) - ∫ y, F y ∂μ‖ := by + rw [residue_mean lo hi u p hp, boxIndices_eq_halfOpen, mean_eq_expect] at hFD + exact hFD + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,a,ha,hat,hab⟩ := hprod (Z/p) hscale₀ + (rescaledEndpoint lo u p) (fun i => (⌈rescaledEndpoint hi u p i⌉:ℝ)-1) + hb.1 hb.2 (fun x => f (integerAffine u p x)) (polynomial_affine H hf u p) + ⟨F,hFL,hFB,hbad'⟩ + obtain ⟨θ,hθ⟩ := character_grid_expansion H s hs hf ξ + have haff : a = gridDilate p (gridTranslate θ u) := + gridAffine_unique p u θ a (fun x => (ha x).trans (hθ (integerAffine u p x)).symm) + refine ⟨ξ,hξ,hξ0,hξc,hξΓ,θ,hθ,?_,?_⟩ + · apply grid_totalDegree (f:=fun x => (ξ (f x)).toAdd) _ θ hθ + intro x q + exact LeibmanSquare.character_polynomial H s hs + (LeibmanSquare.polynomial_integer_line H hf x q) ξ + · intro I hI + rw [← haff] + convert hab I hI using 1 + conv_rhs => rw [div_eq_mul_inv, ← inv_pow, inv_div] + +include hsk h0 h1 hs hqbound hq hΓ htop in + + +theorem discrepancy_character + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0 < c₀) (hC₀ : 0 < C₀) (hB : 0 < B) (hη : 0 < η) : + letI : CompactSpace (G⧸Γ) := metric_compact c Γ hΓ mtr htop + letI : BorelSpace (G⧸Γ) := metric_borelSpace Γ mtr htop + ∃ U : Finset (G →* Multiplicative ℝ), ∃ A T : ℝ, 0 < A ∧ 1 ≤ T ∧ + ∀ (Z : ℝ) (k : ℕ), 0 < k → T ≤ Z/k → + ∀ (lo hi : Fin v → ℝ) (b : Fin v → ℤ), + (∀ i, c₀*Z ≤ hi i-lo i) → + (∀ i, -C₀*Z ≤ lo i ∧ hi i ≤ C₀*Z) → + ∀ f : (Fin v → ℤ) → G, LeibmanSquare.Polynomial H 0 f → + (∃ F : C(G⧸Γ,ℂ), LipschitzWith B F ∧ ‖F‖ ≤ B ∧ + η ≤ ‖mean (boxIndices lo hi (fun _ => 0) 1) + (fun x => F (QuotientGroup.mk (f x))) - + mean (physicalResidueBox lo hi b k) (fun x => F (QuotientGroup.mk (f x)))‖) → + ∃ p : ℕ, ∃ u : Fin v → ℤ, (p = 1 ∨ p = k) ∧ + (∀ i, 0 ≤ u i ∧ u i < p) ∧ + ∃ ξ ∈ U, CharacterObstruction (s:=s) Γ f ξ u p Z A := by + classical + let : CompactSpace (G⧸Γ) := metric_compact c Γ hΓ mtr htop + let : BorelSpace (G⧸Γ) := metric_borelSpace Γ mtr htop + obtain ⟨U,A,T,hA,hT,hprod⟩ := residue_haar_character c hsk H h0 h1 s hs q hqbound hq Γ hΓ htop + μ v c₀ C₀ B (η/2) hc₀ hC₀ hB (by positivity) + refine ⟨U,A,T,hA,hT,?_⟩ + intro Z k hk hTZ lo hi b hside hbox f hf hbad + have hkR : (0:ℝ) < k := by exact_mod_cast hk + have hk1 : (1:ℝ) ≤ k := by exact_mod_cast hk + have hZ : 0 < Z := by + have hh := (le_div_iff₀ hkR).mp (hT.trans hTZ) + nlinarith + have hTZ' : T ≤ Z/(1:ℕ) := by + simp only [Nat.cast_one, div_one] + exact hTZ.trans (div_le_self hZ.le hk1) + obtain ⟨F,hFL,hFB,hFD⟩ := hbad + let a := mean (boxIndices lo hi (fun _ => 0) 1) (fun x => F (QuotientGroup.mk (f x))) + let b' := mean (physicalResidueBox lo hi b k) (fun x => F (QuotientGroup.mk (f x))) + let h := ∫ y, F y ∂μ + have htriangle : ‖a-b'‖ ≤ ‖a-h‖ + ‖b'-h‖ := by + calc + ‖a-b'‖ = ‖(a-h)+(h-b')‖ := by congr 1; ring + _ ≤ ‖a-h‖ + ‖h-b'‖ := norm_add_le _ _ + _ = _ := by rw [norm_sub_rev h b'] + by_cases ha : η/2 ≤ ‖a-h‖ + · refine ⟨1,fun _ => 0,Or.inl rfl,(by intro i; simp),?_⟩ + apply hprod Z 1 zero_lt_one hTZ' lo hi (fun _ => 0) (by intro i; simp) hside hbox f hf + refine ⟨F,hFL,hFB,?_⟩ + simpa only [physicalResidueBox_one] using ha + · have hb : η/2 ≤ ‖b'-h‖ := by + change η ≤ ‖a-b'‖ at hFD + linarith [lt_of_not_ge ha] + let u : Fin v → ℤ := fun i => b i % k + have hu : ∀ i, 0 ≤ u i ∧ u i < k := by + intro i + exact ⟨Int.emod_nonneg _ (by exact_mod_cast hk.ne'), + Int.emod_lt_of_pos _ (by exact_mod_cast hk)⟩ + refine ⟨k,u,Or.inr rfl,hu,?_⟩ + apply hprod Z k hk hTZ lo hi u hu hside hbox f hf + refine ⟨F,hFL,hFB,?_⟩ + simpa only [u,physicalResidueBox_mod] using hb + +end Nilmanifold +end RoughAnalyticExtraction + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughJointCoefficients +open _root_.Polynomial _root_.OAI.Polynomial CorrectedBoxLeibman PolynomialLineCoefficients +open RoughAnalyticExtraction TriangularLatticeRecovery + + +def timeCoefficient {v s : ℕ} (a : PolynomialLineCoefficients.Grid (v+1) s → ℝ) + (I : PolynomialLineCoefficients.Grid v s) : ℝ[X] := + ∑ j : Fin (s+1), C (a (Fin.cons j I)) * X^j.val + +lemma timeCoefficient_degree {v s : ℕ} (a : PolynomialLineCoefficients.Grid (v+1) s → ℝ) + (I : PolynomialLineCoefficients.Grid v s) : (timeCoefficient a I).natDegree ≤ s := by + apply natDegree_sum_le_of_forall_le + intro j hj + exact (natDegree_C_mul_le _ _).trans (by simpa using Nat.le_of_lt_succ j.isLt) + +lemma gridEval_timeCoefficient {v s : ℕ} + (a : PolynomialLineCoefficients.Grid (v+1) s → ℝ) (z : ℝ) (x : Fin v → ℝ) : + gridEval (fun I => (timeCoefficient a I).eval z) x = + gridEval a (Fin.cons z x) := by + classical + simp only [gridEval,timeCoefficient,eval_finsetSum,eval_mul,eval_C,eval_pow,eval_X, + Finset.sum_mul] + rw [Finset.sum_comm] + rw [← Fintype.sum_prod_type'] + apply Fintype.sum_equiv (Fin.consEquiv (fun _ : Fin (v+1) => Fin (s+1))) + intro xj + change (a (Fin.cons xj.1 xj.2) * z^xj.1.val) * (∏ i, x i^(xj.2 i).val) = + a (Fin.cons xj.1 xj.2) * ∏ i, ((Fin.cons z x : Fin (v+1) → ℝ) i)^((Fin.cons xj.1 xj.2 : Fin (v+1) → Fin (s+1)) i).val + simp only [Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ] + ring + + +def spatialEmbedding (v : ℕ) : (Fin v → ℤ) →+ (Fin (v+1) → ℤ) where + toFun x := Fin.cons 0 x + map_zero' := by ext i; exact Fin.cases (by simp) (fun _ => by simp) i + map_add' x y := by ext i; exact Fin.cases (by simp) (fun _ => by simp) i + +lemma fibre_polynomial {G : Type*} [Group G] (H : CubeFaces.Filtration G) + {v : ℕ} {f : (Fin (v+1) → ℤ) → G} (hf : LeibmanSquare.Polynomial H 0 f) (z : ℤ) : + LeibmanSquare.Polynomial H 0 (fun x => f (Fin.cons z x)) := by + have h := LeibmanSquare.polynomial_affine H hf (spatialEmbedding v) (Fin.cons z (fun _ => 0)) + convert h using 1 + funext x + congr 1 + ext i + exact Fin.cases (by simp [spatialEmbedding]) (fun j => by simp [spatialEmbedding]) i + + + +theorem joint_character_coefficients {G : Type*} [Group G] + (H : CubeFaces.Filtration G) (s : ℕ) (hs : H.level (s+1) = ⊥) + {v : ℕ} {f : (Fin (v+1) → ℤ) → G} (hf : LeibmanSquare.Polynomial H 0 f) + (ξ : G →* Multiplicative ℝ) : + ∃ θ : PolynomialLineCoefficients.Grid v s → ℝ[X], + (∀ I, (θ I).natDegree ≤ s) ∧ + ∀ z : ℤ, ∀ x : Fin v → ℤ, + gridEval (fun I => (θ I).eval (z:ℝ)) (fun i => (x i:ℝ)) = + (ξ (f (Fin.cons z x))).toAdd := by + obtain ⟨a,ha⟩ := character_grid_expansion H s hs hf ξ + refine ⟨timeCoefficient a, timeCoefficient_degree a,?_⟩ + intro z x + rw [gridEval_timeCoefficient] + convert ha (Fin.cons z x) using 2 + ext i + exact Fin.cases rfl (fun _ => rfl) i + +lemma obstruction_on_coefficients {G : Type*} [Group G] [TopologicalSpace G] + {v s : ℕ} {Γ : Subgroup G} {f : (Fin v → ℤ) → G} + {ξ : G →* Multiplicative ℝ} {u : Fin v → ℤ} {p : ℕ} {Z A : ℝ} + (h : CharacterObstruction (s:=s) Γ f ξ u p Z A) + (a : PolynomialLineCoefficients.Grid v s → ℝ) + (ha : ∀ x,gridEval a (fun i => (x i:ℝ)) = (ξ (f x)).toAdd) : + ∀ I,0 < totalDegree I → + circleNorm (gridDilate p (gridTranslate a u) I) ≤ A*((p:ℝ)/Z)^totalDegree I := by + obtain ⟨_,_,_,a',ha',_,hb⟩ := h + have he : a = a' := gridEval_integer_injective (fun x => (ha x).trans (ha' x).symm) + simpa only [he] using hb + +@[simp] lemma translationMatrix_self {v s : ℕ} (u : Fin v → ℤ) + (I : PolynomialLineCoefficients.Grid v s) : translationMatrix u I I = 1 := by + unfold translationMatrix + apply Finset.prod_eq_one + intro k hk + unfold translationEntry + rw [coeff_X_add_C_pow] + simp + +lemma translationMatrix_eq_zero_of_degree_le {v s : ℕ} (u : Fin v → ℤ) + (I J : PolynomialLineCoefficients.Grid v s) (hne : I ≠ J) + (hdeg : totalDegree J ≤ totalDegree I) : translationMatrix u I J = 0 := by + by_contra h + have hle := translationMatrix_le u I J h + have heq : ∀ i, (I i).val = (J i).val := by + have heqs : (∑ i, (I i).val) = ∑ i, (J i).val := + le_antisymm (Finset.sum_le_sum (fun i _ => hle i)) hdeg + exact fun i => (Finset.sum_eq_sum_iff_of_le (fun j _ => hle j)).mp heqs i (Finset.mem_univ i) + apply hne + ext i + exact heq i + + + +lemma gridTranslate_peeling {v s : ℕ} (u : Fin v → ℤ) + (a : PolynomialLineCoefficients.Grid v s → ℝ) (I : PolynomialLineCoefficients.Grid v s) : + gridTranslate a u I = a I + + ∑ J ∈ Finset.univ.filter (fun J => totalDegree I < totalDegree J), + (translationMatrix u I J:ℝ)*a J := by + classical + rw [gridTranslate, ← Finset.sum_erase_add (s:=Finset.univ) _ (Finset.mem_univ I)] + rw [translationMatrix_self,Int.cast_one,mul_one,add_comm] + congr 1 + rw [Finset.sum_filter] + calc + _ = ∑ J ∈ Finset.univ.erase I, + if totalDegree I < totalDegree J then (translationMatrix u I J:ℝ)*a J else 0 := by + apply Finset.sum_congr rfl + intro J hJ + have hJI : I≠J := by simpa [eq_comm] using (Finset.mem_erase.mp hJ).1 + by_cases hdeg : totalDegree I < totalDegree J + · simp only [hdeg,ite_eq_left,mul_comm] + · simp [hdeg,translationMatrix_eq_zero_of_degree_le u I J hJI (by omega)] + _ = _ := Finset.sum_subset (Finset.erase_subset _ _) (by + intro J hJ hnot + have hJI : J=I := by simpa using hnot + subst J + simp) + + + +lemma translationMatrix_degree_bound {v s : ℕ} (u : Fin v → ℤ) (p : ℕ) (hp : 0a) d := + ⟨MvPolynomial.C a,by simp,by simp⟩ + +lemma mono {f : (σ → ℝ) → ℝ} {d e : ℕ} (hf : HasDegree f d) (hde : d ≤ e) : + HasDegree f e := by + obtain ⟨p,hp,he⟩:=hf + exact ⟨p,hp.trans hde,he⟩ + +lemma add {f g : (σ → ℝ) → ℝ} {d e : ℕ} + (hf : HasDegree f d) (hg : HasDegree g e) : HasDegree (fun x=>f x+g x) (max d e) := by + obtain ⟨p,hp,he⟩:=hf + obtain ⟨q,hq,hqv⟩:=hg + exact ⟨p+q,(MvPolynomial.totalDegree_add p q).trans (max_le_max hp hq),by simp [he,hqv]⟩ + +lemma mul {f g : (σ → ℝ) → ℝ} {d e : ℕ} + (hf : HasDegree f d) (hg : HasDegree g e) : HasDegree (fun x=>f x*g x) (d+e) := by + obtain ⟨p,hp,he⟩:=hf + obtain ⟨q,hq,hqv⟩:=hg + exact ⟨p*q,(MvPolynomial.totalDegree_mul p q).trans (Nat.add_le_add hp hq),by simp [he,hqv]⟩ + +lemma scale {f : (σ → ℝ) → ℝ} {d : ℕ} (hf : HasDegree f d) (a : ℝ) : + HasDegree (fun x=>a*f x) d := by simpa using mul (const a 0) hf + +lemma neg {f : (σ → ℝ) → ℝ} {d : ℕ} (hf : HasDegree f d) : + HasDegree (fun x=>-f x) d := by simpa using scale hf (-1) + +lemma rational_eval_bound (p : MvPolynomial τ ℚ) : ∃ M : ℕ, + ∀ (σ : Type u) (d : ℕ) (f : τ → (σ → ℝ) → ℝ), + (∀ i,HasDegree (f i) d) → HasDegree + (fun x=>MvPolynomial.eval₂ (algebraMap ℚ ℝ) (fun i=>f i x) p) (M*d) := by + induction p using MvPolynomial.induction_on with + | C a => exact ⟨0,fun σ d f hf=>by simpa using const (σ:=σ) (a:ℝ) 0⟩ + | add p q hp hq => + obtain ⟨M,hM⟩:=hp + obtain ⟨N,hN⟩:=hq + refine ⟨max M N,fun σ d f hf=>?_⟩ + have he:=add (hM σ d f hf) (hN σ d f hf) + have hb : max (M*d) (N*d) ≤ max M N*d := max_le + (Nat.mul_le_mul_right d (le_max_left M N)) + (Nat.mul_le_mul_right d (le_max_right M N)) + have he' := RealPolynomialDegree.mono he hb + simpa only [MvPolynomial.eval₂_add] using he' + | mul_X p i hp => + obtain ⟨M,hM⟩:=hp + refine ⟨M+1,fun σ d f hf=>?_⟩ + have he:=mul (hM σ d f hf) (hf i) + simpa only [MvPolynomial.eval₂_mul,MvPolynomial.eval₂_X,Nat.add_mul,Nat.one_mul] using he + +end RealPolynomialDegree +end + +end + +section + + + + +noncomputable section +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters IntegerHyperplane RealPolynomialDegree +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) + +omit [IsTopologicalGroup G] in +lemma multiplication_degree [IsTopologicalGroup G] : ∃ C : ℕ,0 < C ∧ + ∀ (v d : ℕ) (P Q : (Fin v → ℝ) → G), + (∀ i,HasDegree (fun x=>c.coord (P x) i) d) → + (∀ i,HasDegree (fun x=>c.coord (Q x) i) d) → + ∀ i,HasDegree (fun x=>c.coord (P x*Q x) i) (C*d) := by + classical + choose M hM using fun i=>rational_eval_bound (c.correction i) + let C := Finset.univ.sup M+1 + have hC : 0 < C := Nat.zero_lt_succ _ + have hMC (i : Fin (n+1)) : M i ≤ C := + (Finset.le_sup (f:=M) (Finset.mem_univ i)).trans (Nat.le_add_right _ 1) + refine ⟨C,hC,fun v d P Q hP hQ i=>?_⟩ + have hc:=hM i (Fin v) d + (Sum.elim (fun j : Fin i.val=>fun x=>c.coord (P x) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val=>fun x=>c.coord (Q x) ⟨j.val,lt_trans j.isLt i.isLt⟩)) (by + intro j + cases j with + | inl j=>exact hP _ + | inr j=>exact hQ _) + have ha : HasDegree (fun x=>c.coord (P x) i+c.coord (Q x) i) d := by + simpa using RealPolynomialDegree.add (hP i) (hQ i) + have he:=RealPolynomialDegree.add ha hc + have hd : d ≤ C*d := by simpa using Nat.mul_le_mul_right d hC + have hb : max d (M i*d) ≤ C*d := max_le hd (Nat.mul_le_mul_right d (hMC i)) + have heval (x : Fin v → ℝ) : + (fun j=>Sum.elim + (fun j : Fin i.val=>fun x=>c.coord (P x) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val=>fun x=>c.coord (Q x) ⟨j.val,lt_trans j.isLt i.isLt⟩) j x)= + Sum.elim (fun j : Fin i.val=>c.coord (P x) ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j : Fin i.val=>c.coord (Q x) ⟨j.val,lt_trans j.isLt i.isLt⟩) := by + funext j + cases j <;> rfl + simpa only [c.mul_coord,heval] using RealPolynomialDegree.mono he hb + +variable (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (k : Fin (n+1) → ℤ) (p : Fin (n+1)) +variable (hp : k p ≠ 0) (hχ : ∀ g : G,(χ g).toAdd=form k (c.coord g)) +variable (hlast : ∀ j : Fin (n+1),p < j → k j=0) + +omit [IsTopologicalGroup G] in +lemma sectionFlow_degree [IsTopologicalGroup G] {v d : ℕ} {a : (Fin v → ℝ) → ℝ} (ha : HasDegree a d) : + ∀ i,HasDegree + (fun x=>c.coord (sectionFlow c hsk k p (Multiplicative.ofAdd (a x))) i) d := by + classical + intro i + change HasDegree (fun x=>c.coord (axis c p (a x/(k p:ℝ))) i) d + simp only [coord_axis,Pi.single_apply] + split_ifs + · simpa [div_eq_mul_inv,mul_comm] using RealPolynomialDegree.scale ha (k p:ℝ)⁻¹ + · exact RealPolynomialDegree.const 0 d + + + +theorem residual_degree_uniform : ∃ B : ℕ,0 < B ∧ + ∀ (v d : ℕ) (P : (Fin v → ℝ) → G) (a m : (Fin v → ℝ) → ℝ) + (hP : ∀ x,(χ (P x)).toAdd=a x+m x), + (∀ i,HasDegree (fun x=>c.coord (P x) i) d) → HasDegree a d → HasDegree m d → + ∀ i,HasDegree (fun x=>(RationalCharacterKernel.kernelCoordinates c χ k p hp hχ hlast).coord + (residual c hsk χ k p hp hχ P a m hP x) i) (B*d) := by + obtain ⟨C,hC,hMul⟩:=multiplication_degree c + refine ⟨C*C,Nat.mul_pos hC hC,fun v d P a m hP hpoly ha hm i=>?_⟩ + have h₁:=hMul v d _ _ (sectionFlow_degree c hsk k p (RealPolynomialDegree.neg ha)) hpoly + have h₂:=hMul v (C*d) _ _ h₁ (fun i=> + RealPolynomialDegree.mono (sectionFlow_degree c hsk k p (RealPolynomialDegree.neg hm) i) + (by simpa using Nat.mul_le_mul_right d hC)) + change HasDegree (fun x=>c.coord + (sectionFlow c hsk k p (Multiplicative.ofAdd (-a x))*P x* + sectionFlow c hsk k p (Multiplicative.ofAdd (-m x))) (p.succAbove i)) ((C*C)*d) + simpa only [Nat.mul_assoc] using h₂ (p.succAbove i) + +end RoughKernelFactorization +end + +end + +section + + + +noncomputable section +namespace NonnormalCoset +variable {G A : Type*} [Group G] [Group A] +variable [TopologicalSpace G] [TopologicalSpace A] +variable [IsTopologicalGroup G] [IsTopologicalGroup A] +variable (Γ : Subgroup G) (Λ : Subgroup A) (p : G →* A) +variable (hp : Continuous p) (hΓ : ∀ g∈Γ,p g∈Λ) + +def map : C(G⧸Γ,A⧸Λ) where + toFun:=Quotient.lift (fun g=>QuotientGroup.mk (p g)) (by + intro g h he + apply QuotientGroup.eq.mpr + rw [←map_inv,←map_mul] + exact hΓ _ (QuotientGroup.leftRel_apply.mp he)) + continuous_toFun:= + (QuotientGroup.isQuotientMap_mk Γ).continuous_iff.mpr + (QuotientGroup.continuous_mk.comp hp) + +omit [IsTopologicalGroup G] [IsTopologicalGroup A] in +@[simp] lemma map_mk [IsTopologicalGroup G] [IsTopologicalGroup A] (g : G) : map Γ Λ p hp hΓ (QuotientGroup.mk g)=QuotientGroup.mk (p g):=rfl +end NonnormalCoset + +namespace PhysicalCubeMaps +variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] +variable {ι : Type*} [DecidableEq ι] + +def vertices (p : C(X,Y)) : C((Finset ι → X),(Finset ι → Y)) where + toFun x w:=p (x w) + continuous_toFun:=continuous_pi (fun w=>p.continuous.comp (continuous_apply w)) + +def upperFace (i : ι) (S : C(Y,Y)) : C((Finset ι → Y),(Finset ι → Y)) where + toFun y w:=if i∈w then S (y w) else y w + continuous_toFun:=continuous_pi (fun w=>by + by_cases h : i∈w + · simpa only [h,ite_true,Function.comp_def] using S.continuous.comp (continuous_apply w) + · simpa only [h,ite_false] using (continuous_apply w : Continuous (fun y : Finset ι → Y=>y w))) + +omit [DecidableEq ι] in +@[simp] lemma vertices_apply [DecidableEq ι] (p : C(X,Y)) (x : Finset ι → X) (w : Finset ι) : + vertices p x w=p (x w):=rfl +@[simp] lemma upperFace_apply (i : ι) (S : C(Y,Y)) (x : Finset ι → Y) (w : Finset ι) : + upperFace i S x w=if i∈w then S (x w) else x w:=rfl + +end PhysicalCubeMaps +end + +end + +section + + + + +noncomputable section +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (χ : G →* Multiplicative ℝ) (Γ : Subgroup G) (σ : G) + +def kernelInclusion : χ.ker →* G := + (MulAut.conj σ⁻¹).toMonoidHom.comp χ.ker.subtype + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +@[simp] lemma kernelInclusion_apply [TopologicalSpace G] [IsTopologicalGroup G] (h : χ.ker) : + kernelInclusion χ σ h=σ⁻¹*h.val*σ := by simp [kernelInclusion] + +lemma kernelInclusion_continuous : Continuous (kernelInclusion χ σ) := by + change Continuous (fun h : χ.ker=>kernelInclusion χ σ h) + simp only [kernelInclusion_apply] + exact + ((continuous_const.mul continuous_subtype_val).mul continuous_const : + Continuous (fun h : χ.ker=>σ⁻¹*h.val*σ)) + +def kernelLattice : Subgroup χ.ker := Γ.comap (kernelInclusion χ σ) + +@[simp] lemma mem_kernelLattice (h : χ.ker) : + h∈kernelLattice χ Γ σ ↔ σ⁻¹*h.val*σ∈Γ := by + change kernelInclusion χ σ h∈Γ ↔ _ + rw [kernelInclusion_apply] + + + +def kernelTestMap (ℓ : G) : C(χ.ker⧸kernelLattice χ Γ σ,G⧸Γ) where + toFun x:=(ℓ*σ) • NonnormalCoset.map (kernelLattice χ Γ σ) Γ + (kernelInclusion χ σ) (kernelInclusion_continuous χ σ) (fun _ h=>h) x + continuous_toFun:=(continuous_const : Continuous + (fun _ : χ.ker⧸kernelLattice χ Γ σ=>ℓ*σ)).smul + (NonnormalCoset.map (kernelLattice χ Γ σ) Γ + (kernelInclusion χ σ) (kernelInclusion_continuous χ σ) (fun _ h=>h)).continuous + +@[simp] lemma kernelTestMap_mk (ℓ : G) (h : χ.ker) : + kernelTestMap χ Γ σ ℓ (QuotientGroup.mk h)= + QuotientGroup.mk (ℓ*h.val*σ) := by + change (ℓ*σ) • (QuotientGroup.mk (kernelInclusion χ σ h) : G⧸Γ)=_ + rw [kernelInclusion_apply] + change QuotientGroup.mk ((ℓ*σ)*(σ⁻¹*h.val*σ))=_ + congr 1 + group + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma character_conjugate [TopologicalSpace G] [IsTopologicalGroup G] (x : G) : χ (σ*x*σ⁻¹)=χ x := by + simp only [map_mul,map_inv] + apply Multiplicative.toAdd.injective + change (χ σ).toAdd+(χ x).toAdd+(-(χ σ).toAdd)=(χ x).toAdd + ring + +variable (hcont : Continuous χ) +variable (hZ : ∀ g∈Γ,∃ z : ℤ,(χ g).toAdd=z) +variable (C : Set G) (hC : IsCompact C) (hrep : ∀ g : G,∃ c∈C,c⁻¹*g∈Γ) + +include hcont hZ hC hrep in + +theorem kernel_quotient_compact : CompactSpace (χ.ker⧸kernelLattice χ Γ σ) := by + let Γσ:=Γ.map (MulAut.conj σ).toMonoidHom + let Cσ:=(fun x : G=>σ*x*σ⁻¹) '' C + have hCσ : IsCompact Cσ:=hC.image ((continuous_const.mul continuous_id).mul continuous_const) + have hrepσ : ∀ g : G,∃ c∈Cσ,c⁻¹*g∈Γσ := by + intro g + obtain ⟨c,hc,hg⟩:=hrep (σ⁻¹*g*σ) + refine ⟨σ*c*σ⁻¹,⟨c,hc,rfl⟩,?_⟩ + apply Subgroup.mem_map.mpr + refine ⟨c⁻¹*(σ⁻¹*g*σ),hg,?_⟩ + change σ*(c⁻¹*(σ⁻¹*g*σ))*σ⁻¹=(σ*c*σ⁻¹)⁻¹*g + group + have hZσ : ∀ g∈Γσ,∃ z : ℤ,(χ g).toAdd=z := by + rintro g ⟨a,ha,rfl⟩ + obtain ⟨z,hz⟩:=hZ a ha + refine ⟨z,?_⟩ + change (χ (σ*a*σ⁻¹)).toAdd=(z:ℝ) + rw [character_conjugate] + exact hz + obtain ⟨D,hD,hDker,hDrep⟩:=CharacterKernelLattice.compact_kernel_representatives + χ hcont Γσ Cσ hCσ hrepσ hZσ + have hcompact : IsCompact ((Subtype.val : χ.ker → G) ⁻¹' D) := by + apply Topology.IsInducing.subtypeVal.isCompact_preimage' hD + intro x hx + exact ⟨⟨x,hDker hx⟩,rfl⟩ + apply CompactGroupProducts.HasCompactReps.quotient_compactSpace + refine ⟨(Subtype.val : χ.ker → G) ⁻¹' D,hcompact,by intro x _; trivial,?_⟩ + intro g _ + obtain ⟨d,hd,hg⟩:=hDrep g.val g.property + refine ⟨⟨d,hDker hd⟩,hd,?_⟩ + rw [mem_kernelLattice] + change σ⁻¹*(d⁻¹*g.val)*σ∈Γ + obtain ⟨a,ha,he⟩:=Subgroup.mem_map.mp hg + have hh : σ⁻¹*(d⁻¹*g.val)*σ=a := by + change σ*a*σ⁻¹=d⁻¹*g.val at he + rw [←he] + group + rwa [hh] + +variable {n : ℕ} (c : RealCoordinates G n) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +include hcont hZ hΓ in +theorem integer_kernel_quotient_compact : CompactSpace (χ.ker⧸kernelLattice χ Γ σ) := by + obtain ⟨C,hC,hrep⟩:=compact_reps_of_integerCoordinates c Γ hΓ + exact kernel_quotient_compact χ Γ σ hcont hZ C hC hrep + +end RoughKernelFactorization + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel02.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e178039ceb2a089774d9493b4bdcd3f26290059 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel02.lean @@ -0,0 +1,303 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughKernel01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters IntegerHyperplane +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (Γ : Subgroup G) + +structure Reduction where + k : Fin (n+1) → ℤ + p : Fin (n+1) + pivot : k p≠0 + last : ∀ j : Fin (n+1),pmul_comm _ _) + have hk0 : k≠0 := by + intro he + apply hne + ext g + apply Multiplicative.toAdd.injective + change (χ g).toAdd=0 + rw [hχ,he] + simp [form] + obtain ⟨p,hp,hlast⟩:=exists_last_nonzero k hk0 + obtain ⟨K,hK,hperiod⟩:=sectionFlow_period c hsk k p hp Γ hΓ + exact ⟨⟨k,p,hp,hlast,hχ,K,hK,hperiod⟩⟩ + +namespace Reduction +variable (R : Reduction c hsk χ Γ) + +def chart : RealCoordinates χ.ker n := + RationalCharacterKernel.kernelCoordinates c χ R.k R.p R.pivot R.character R.last + +def flow : Multiplicative ℝ →* G := sectionFlow c hsk R.k R.p + +lemma flow_character (t : ℝ) : (χ (R.flow c hsk χ Γ (Multiplicative.ofAdd t))).toAdd=t := + sectionFlow_character c hsk χ R.k R.p R.pivot R.character t + +lemma flow_rational (t : ℚ) : + IsRational c (R.flow c hsk χ Γ (Multiplicative.ofAdd (t:ℝ))) := + sectionFlow_rational c hsk R.k R.p t + +lemma coset_period (z j : ℤ) (hmod : (R.period:ℤ)∣z-j) : + (QuotientGroup.mk (R.flow c hsk χ Γ (Multiplicative.ofAdd (z:ℝ))) : G⧸Γ)= + QuotientGroup.mk (R.flow c hsk χ Γ (Multiplicative.ofAdd (j:ℝ))) := + same_coset_of_mod c hsk R.k R.p Γ R.period R.periodic z j hmod + + + +theorem lower_dimensional_factorization : ∃ B : ℕ,0c.coord (P x) i) d) → + RealPolynomialDegree.HasDegree a d → RealPolynomialDegree.HasDegree m d → + ∃ Q : (Fin v → ℝ) → χ.ker, + (∀ x,P x=R.flow c hsk χ Γ (Multiplicative.ofAdd (a x))* + (Q x).val*R.flow c hsk χ Γ (Multiplicative.ofAdd (m x))) ∧ + ∀ i,RealPolynomialDegree.HasDegree (fun x=>(R.chart c hsk χ Γ).coord (Q x) i) (B*d) := by + obtain ⟨B,hB,hdeg⟩:=residual_degree_uniform c hsk χ R.k R.p R.pivot R.character R.last + refine ⟨B,hB,fun v d P a m hP hpoly ha hm=>?_⟩ + refine ⟨residual c hsk χ R.k R.p R.pivot R.character P a m hP,?_,?_⟩ + · exact residual_factorization c hsk χ R.k R.p R.pivot R.character P a m hP + · exact hdeg v d P a m hP hpoly ha hm + +end Reduction + +end RoughKernelFactorization +end + +end + +section + + + + +noncomputable section +namespace RealPolynomialDegree +open RationalLattice +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) + +theorem rational_map_bound {τ : Type*} [Fintype τ] {κ : Type*} + (F : τ → (κ → ℝ) → ℝ) (hF : ∀ i,RationalPolynomialMap.IsPolynomial (F i)) : + ∃ C : ℕ,0F i (fun j=>P j x)) (C*d) := by + classical + choose p hp using hF + choose M hM using fun i=>rational_eval_bound (p i) + let C:=Finset.univ.sup M+1 + refine ⟨C,Nat.zero_lt_succ _,fun v d P hP i=>?_⟩ + have hb : M i≤C := (Finset.le_sup (f:=M) (Finset.mem_univ i)).trans (Nat.le_add_right _ 1) + have hh:=RealPolynomialDegree.mono (hM i (Fin v) d P hP) (Nat.mul_le_mul_right d hb) + simpa only [hp i] using hh + +theorem log_degree_bound : ∃ C : ℕ,0c.coord (P x) i) d) → + ∀ i,HasDegree (fun x=>canonicalLog c (P x) i) (C*d) := by + obtain ⟨C,hC,hbound⟩:=rational_map_bound + (fun i x=>canonicalLog c (c.coord.symm x) i) (canonicalLog_polynomial c) + refine ⟨C,hC,fun v d P hP i=>?_⟩ + simpa only [Homeomorph.symm_apply_apply] using hbound v d (fun i x=>c.coord (P x) i) hP i + +theorem coord_degree_bound : ∃ C : ℕ,0canonicalLog c (P x) i) d) → + ∀ i,HasDegree (fun x=>c.coord (P x) i) (C*d) := by + obtain ⟨C,hC,hbound⟩:=rational_map_bound + (fun i x=>c.coord (canonicalExp c x) i) (canonicalExp_polynomial c) + refine ⟨C,hC,fun v d P hP i=>?_⟩ + simpa only [canonicalExp_log] using hbound v d (fun i x=>canonicalLog c (P x) i) hP i + +end RealPolynomialDegree +end + +end + +section + + + + +noncomputable section +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters IntegerHyperplane RealPolynomialDegree +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (Γ : Subgroup G) + +namespace Reduction +variable (R : Reduction c hsk χ Γ) + +include R in +omit [IsTopologicalGroup G] in +lemma kernel_connected [IsTopologicalGroup G] : ConnectedSpace χ.ker := + coordinates_connected (R.chart c hsk χ Γ) + +include R in +omit [IsTopologicalGroup G] in +lemma kernel_simplyConnected [IsTopologicalGroup G] : SimplyConnectedSpace χ.ker := + coordinates_simplyConnected (R.chart c hsk χ Γ) + + + +theorem logarithmic_factorization : ∃ B : ℕ,0canonicalLog c (P x) i) d) → + HasDegree a d → HasDegree m d → + ∃ Q : (Fin v → ℝ) → χ.ker, + (∀ x,P x=R.flow c hsk χ Γ (Multiplicative.ofAdd (a x))* + (Q x).val*R.flow c hsk χ Γ (Multiplicative.ofAdd (m x))) ∧ + ∀ i,HasDegree (fun x=>canonicalLog (R.chart c hsk χ Γ) (Q x) i) (B*d) := by + obtain ⟨E,hE,hcoord⟩:=coord_degree_bound c + obtain ⟨L,hL,hlog⟩:=log_degree_bound (R.chart c hsk χ Γ) + obtain ⟨B,hB,hfactor⟩:=R.lower_dimensional_factorization c hsk χ Γ + refine ⟨L*(B*E),Nat.mul_pos hL (Nat.mul_pos hB hE),fun v d P a m hP hpoly ha hm=>?_⟩ + have hd : d≤E*d := by simpa using Nat.mul_le_mul_right d hE + obtain ⟨Q,hQ,hdeg⟩:=hfactor v (E*d) P a m hP (hcoord v d P hpoly) + (RealPolynomialDegree.mono ha hd) (RealPolynomialDegree.mono hm hd) + refine ⟨Q,hQ,fun i=>?_⟩ + simpa only [Nat.mul_assoc] using hlog v (B*(E*d)) Q hdeg i + +end Reduction +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable (hcont : Continuous χ) (hZ : ∀ g∈Γ,∃ z : ℤ,(χ g).toAdd=z) (hne : χ≠1) +include hΓ hcont hZ hne in + + +theorem exists_logarithmic_kernel_reduction : + ∃ R : Reduction c hsk χ Γ, + ConnectedSpace χ.ker ∧ SimplyConnectedSpace χ.ker ∧ + (∀ σ : G,CompactSpace (χ.ker⧸kernelLattice χ Γ σ)) ∧ + ∃ B : ℕ,0canonicalLog c (P x) i) d) → + HasDegree a d → HasDegree m d → + ∃ Q : (Fin v → ℝ) → χ.ker, + (∀ x,P x=R.flow c hsk χ Γ (Multiplicative.ofAdd (a x))* + (Q x).val*R.flow c hsk χ Γ (Multiplicative.ofAdd (m x))) ∧ + ∀ i,HasDegree (fun x=>canonicalLog (R.chart c hsk χ Γ) (Q x) i) (B*d) := by + obtain ⟨R⟩:=exists_reduction c hsk χ Γ hΓ hcont hZ hne + exact ⟨R,R.kernel_connected c hsk χ Γ,R.kernel_simplyConnected c hsk χ Γ, + fun σ=>integer_kernel_quotient_compact χ Γ σ hcont hZ c hΓ, + R.logarithmic_factorization c hsk χ Γ⟩ + +end RoughKernelFactorization +end + +end + +section + + + + +noncomputable section +open scoped NNReal +namespace UniformLipschitzApproximation +variable {I X : Type*} [PseudoMetricSpace X] [Nonempty X] +variable (f : I → X → ℝ) (B : ℝ) (hB : 0≤B) +variable (hf : ∀ i x,|f i x|≤B) +variable (hmod : ∀ ε : ℝ,0<ε → ∃ δ : ℝ,0<δ ∧ + ∀ i x y,dist x y<δ → |f i x-f i y|<ε) + +include hB hf hmod in +theorem exists_common_bound (ε : ℝ) (hε : 0<ε) : + ∃ K : ℝ≥0,∀ i,∃ g : X → ℝ,LipschitzWith K g ∧ + (∀ x,|g x-f i x|<ε) ∧ ∀ x,|g x|≤B+ε := by + obtain ⟨δ,hδ,hclose⟩:=hmod (ε/2) (by linarith) + let K : ℝ≥0:=⟨2*B/δ,div_nonneg (by positivity) hδ.le⟩ + have hKδ : (K:ℝ)*δ=2*B := by + change (2*B/δ)*δ=2*B + exact div_mul_cancel₀ _ hδ.ne' + refine ⟨K,fun i=>?_⟩ + let A (x z : X):=f i z+(K:ℝ)*dist x z + let g (x : X):=⨅ z,A x z + have hbdd (x : X) : BddBelow (Set.range (A x)) := by + refine ⟨-B,?_⟩ + rintro _ ⟨z,rfl⟩ + have hp : 0≤(K:ℝ)*dist x z:=mul_nonneg K.coe_nonneg dist_nonneg + dsimp [A] + linarith [(abs_le.mp (hf i z)).1] + have hle (x z : X) : g x≤A x z:=ciInf_le (hbdd x) z + have hdiff (x y : X) : g x-g y≤(K:ℝ)*dist x y := by + have hh : g x-(K:ℝ)*dist x y≤g y := by + apply le_ciInf + intro z + have ht:=dist_triangle x y z + have hm:=mul_le_mul_of_nonneg_left ht K.coe_nonneg + have hl:=hle x z + dsimp [A] at hl ⊢ + linarith + linarith + have hLip : LipschitzWith K g := by + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq,abs_le] + exact ⟨by have hh:=hdiff y x; rw [dist_comm y x] at hh; linarith,hdiff x y⟩ + have happ (x : X) : |g x-f i x|<ε := by + have hu : g x≤f i x := by simpa [A] using hle x x + have hl : f i x-ε/2≤g x := by + apply le_ciInf + intro z + by_cases hz : dist x z<δ + · have hh:=hclose i x z hz + have hp:=mul_nonneg K.coe_nonneg (dist_nonneg (x:=x) (y:=z)) + dsimp [A] + linarith [(abs_lt.mp hh).2] + · have hh : 2*B≤(K:ℝ)*dist x z := by + rw [←hKδ] + exact mul_le_mul_of_nonneg_left (le_of_not_gt hz) K.coe_nonneg + dsimp [A] + linarith [(abs_le.mp (hf i x)).2,(abs_le.mp (hf i z)).1] + rw [abs_of_nonpos (sub_nonpos.mpr hu)] + linarith + refine ⟨g,hLip,happ,fun x=>?_⟩ + have hh:=abs_add_le (g x-f i x) (f i x) + have he : g x-f i x+f i x=g x:=by ring + rw [he] at hh + linarith [happ x,hf i x] + +end UniformLipschitzApproximation + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel03.lean new file mode 100644 index 0000000000000000000000000000000000000000..cac44caf8a4c0d87dec5d1231b25bc67c9897776 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel03.lean @@ -0,0 +1,264 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughKernel02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +open scoped NNReal +end + +end + +section + + + + +noncomputable section +open scoped NNReal +namespace UniformLipschitzApproximation +variable {A Y Z : Type*} [PseudoMetricSpace A] [CompactSpace A] +variable [PseudoMetricSpace Y] [CompactSpace Y] [Nonempty Y] [PseudoMetricSpace Z] +variable (H : C(A×Y,Z)) (K : ℝ≥0) (B : ℝ) (hB : 0≤B) + +include hB in +theorem compact_pullback (ε : ℝ) (hε : 0<ε) : + ∃ L : ℝ≥0,∀ (a : A) (F : Z → ℝ),LipschitzWith K F → (∀ z,|F z|≤B) → + ∃ g : Y → ℝ,LipschitzWith L g ∧ + (∀ y,|g y-F (H (a,y))|<ε) ∧ ∀ y,|g y|≤B+ε := by + let J:=A × {F : Z → ℝ // LipschitzWith K F ∧ ∀ z,|F z|≤B} + let f (j : J) (y : Y):=j.2.val (H (j.1,y)) + have hbound : ∀ j y,|f j y|≤B:=fun j y=>j.2.property.2 _ + have hmod : ∀ η : ℝ,0<η → ∃ δ : ℝ,0<δ ∧ + ∀ j y z,dist y z<δ → |f j y-f j z|<η := by + intro η hη + have hp : 0<(K:ℝ)+1:=by positivity + obtain ⟨δ,hδ,hd⟩:=Metric.uniformContinuous_iff.mp (CompactSpace.uniformContinuous_of_continuous H.continuous) + (η/((K:ℝ)+1)) (div_pos hη hp) + refine ⟨δ,hδ,fun j y z hyz=>?_⟩ + have he : dist (j.1,y) (j.1,z)<δ := by simpa [Prod.dist_eq] using hyz + have hh:=hd he + have hf:=j.2.property.1.dist_le_mul (H (j.1,y)) (H (j.1,z)) + change |f j y-f j z|≤(K:ℝ)*dist (H (j.1,y)) (H (j.1,z)) at hf + have hx : ((K:ℝ)+1)*dist (H (j.1,y)) (H (j.1,z))<η := by + have ht:=mul_lt_mul_of_pos_left hh hp + have hc : ((K:ℝ)+1)*(η/((K:ℝ)+1))=η:=mul_div_cancel₀ _ hp.ne' + rwa [hc] at ht + have hn:=dist_nonneg (x:=H (j.1,y)) (y:=H (j.1,z)) + nlinarith + obtain ⟨L,hL⟩:=exists_common_bound f B hB hbound hmod ε hε + exact ⟨L,fun a F hF hb=>hL (a,⟨F,hF,hb⟩)⟩ + +end UniformLipschitzApproximation +end + +end + +section + + +noncomputable section +open scoped NNReal +namespace UniformLipschitzApproximation +variable {A Y Z : Type*} [PseudoMetricSpace A] [CompactSpace A] +variable [PseudoMetricSpace Y] [CompactSpace Y] [Nonempty Y] [PseudoMetricSpace Z] +variable (H : C(A×Y,Z)) (K : ℝ≥0) (B : ℝ) (hB : 0≤B) + +include hB in +theorem compact_pullback_complex (ε : ℝ) (hε : 0<ε) : + ∃ L : ℝ≥0,∀ (a : A) (F : Z → ℂ),LipschitzWith K F → (∀ z,‖F z‖≤B) → + ∃ g : Y → ℂ,LipschitzWith L g ∧ + (∀ y,‖g y-F (H (a,y))‖<ε) ∧ ∀ y,‖g y‖≤B+ε := by + obtain ⟨L,hL⟩:=compact_pullback H K B hB (ε/2) (by linarith) + refine ⟨L+L,fun a F hF hb=>?_⟩ + have hRe : LipschitzWith K (fun z=>(F z).re) := by + apply LipschitzWith.of_dist_le_mul + intro x y + calc + dist (F x).re (F y).re=|(F x-F y).re|:=by simp [Real.dist_eq] + _≤‖F x-F y‖:=Complex.abs_re_le_norm _ + _≤(K:ℝ)*dist x y:=by simpa [dist_eq_norm] using hF.dist_le_mul x y + have hIm : LipschitzWith K (fun z=>(F z).im) := by + apply LipschitzWith.of_dist_le_mul + intro x y + calc + dist (F x).im (F y).im=|(F x-F y).im|:=by simp [Real.dist_eq] + _≤‖F x-F y‖:=Complex.abs_im_le_norm _ + _≤(K:ℝ)*dist x y:=by simpa [dist_eq_norm] using hF.dist_le_mul x y + obtain ⟨u,hu,hue,_⟩:=hL a (fun z=>(F z).re) hRe + (fun z=>(Complex.abs_re_le_norm _).trans (hb z)) + obtain ⟨v,hv,hve,_⟩:=hL a (fun z=>(F z).im) hIm + (fun z=>(Complex.abs_im_le_norm _).trans (hb z)) + let g (y : Y) : ℂ:=⟨u y,v y⟩ + have hg : LipschitzWith (L+L) g := by + apply LipschitzWith.of_dist_le_mul + intro x y + have hh:=Complex.norm_le_abs_re_add_abs_im (g x-g y) + have h₁:=hu.dist_le_mul x y + have h₂:=hv.dist_le_mul x y + simp only [Real.dist_eq] at h₁ h₂ + rw [dist_eq_norm] + change ‖g x-g y‖≤|u x-u y|+|v x-v y| at hh + push_cast + nlinarith + have he (y : Y) : ‖g y-F (H (a,y))‖<ε := by + have hh:=Complex.norm_le_abs_re_add_abs_im (g y-F (H (a,y))) + change ‖g y-F (H (a,y))‖≤|u y-(F (H (a,y))).re|+|v y-(F (H (a,y))).im| at hh + linarith [hue y,hve y] + refine ⟨g,hg,he,fun y=>?_⟩ + have hh:=norm_add_le (g y-F (H (a,y))) (F (H (a,y))) + rw [sub_add_cancel] at hh + linarith [he y,hb (H (a,y))] + +end UniformLipschitzApproximation +end + +end + +section + + + + +noncomputable section +open scoped NNReal +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (χ : G →* Multiplicative ℝ) (Γ : Subgroup G) (σ : G) + +def kernelTestJoint : C(G×(χ.ker⧸kernelLattice χ Γ σ),G⧸Γ) where + toFun x:=kernelTestMap χ Γ σ x.1 x.2 + continuous_toFun:=by + change Continuous (fun x : G×(χ.ker⧸kernelLattice χ Γ σ)=> + (x.1*σ) • NonnormalCoset.map (kernelLattice χ Γ σ) Γ + (kernelInclusion χ σ) (kernelInclusion_continuous χ σ) (fun _ h=>h) x.2) + exact (continuous_fst.mul continuous_const).smul + ((NonnormalCoset.map (kernelLattice χ Γ σ) Γ + (kernelInclusion χ σ) (kernelInclusion_continuous χ σ) (fun _ h=>h)).continuous.comp + continuous_snd) + +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable (hcont : Continuous χ) (hZ : ∀ g∈Γ,∃ z : ℤ,(χ g).toAdd=z) + +noncomputable abbrev kernelCompatibleMetric : MetricSpace (χ.ker⧸kernelLattice χ Γ σ) := by + letI : T2Space G:=c.coord.symm.t2Space + letI : SecondCountableTopology χ.ker:=(R.chart c hsk χ Γ).coord.secondCountableTopology + letI : DiscreteTopology Γ:=integerCoordinates_discrete c Γ hΓ + have hinj : Function.Injective (kernelInclusion χ σ) := + (MulAut.conj σ⁻¹).injective.comp Subtype.val_injective + letI : DiscreteTopology (kernelLattice χ Γ σ):= + DiscreteTopology.preimage_of_continuous_injective (Γ:Set G) + (kernelInclusion_continuous χ σ) hinj + letI : IsClosed (kernelLattice χ Γ σ:Set χ.ker):=Subgroup.isClosed_of_discreteTopology + letI : CompactSpace (χ.ker⧸kernelLattice χ Γ σ):= + integer_kernel_quotient_compact χ Γ σ hcont hZ c hΓ + exact TopologicalSpace.metrizableSpaceMetric _ + +variable {X : Type*} [PseudoMetricSpace X] (e : (G⧸Γ) ≃ₜ X) +include hΓ hcont hZ in + + +theorem uniform_kernel_tests (T : ℝ) (K : ℝ≥0) (B : ℝ) (hB : 0≤B) : + letI := kernelCompatibleMetric χ Γ σ c hsk R hΓ hcont hZ + ∀ ε : ℝ,0<ε → ∃ L : ℝ≥0,∀ (a : Set.Icc (-T) T) (F : X → ℂ), + LipschitzWith K F → (∀ x,‖F x‖≤B) → + ∃ g : (χ.ker⧸kernelLattice χ Γ σ) → ℂ,LipschitzWith L g ∧ + (∀ y,‖g y-F (e (kernelTestMap χ Γ σ + (R.flow c hsk χ Γ (Multiplicative.ofAdd a.val)) y))‖<ε) ∧ + ∀ y,‖g y‖≤B+ε := by + let := kernelCompatibleMetric χ Γ σ c hsk R hΓ hcont hZ + let : CompactSpace (χ.ker⧸kernelLattice χ Γ σ):= + integer_kernel_quotient_compact χ Γ σ hcont hZ c hΓ + let H : C((Set.Icc (-T) T) × (χ.ker⧸kernelLattice χ Γ σ),X):= + { toFun:=fun x=>e (kernelTestMap χ Γ σ + (R.flow c hsk χ Γ (Multiplicative.ofAdd x.1.val)) x.2) + continuous_toFun:=by + apply e.continuous.comp + change Continuous ((kernelTestJoint χ Γ σ) ∘ + (fun x : (Set.Icc (-T) T) × (χ.ker⧸kernelLattice χ Γ σ)=> + (R.flow c hsk χ Γ (Multiplicative.ofAdd x.1.val),x.2))) + apply (kernelTestJoint χ Γ σ).continuous.comp + apply Continuous.prodMk _ continuous_snd + exact (sectionFlow_continuous c hsk R.k R.p).comp + (continuous_ofAdd.comp (continuous_subtype_val.comp continuous_fst)) } + exact UniformLipschitzApproximation.compact_pullback_complex H K B hB + +end RoughKernelFactorization +end + +end + +section + + + + +noncomputable section +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters + +lemma integer_eval_modEq {V : Type*} (K : ℤ) (m : MvPolynomial V ℤ) + (x u : V → ℤ) (hx : ∀ i,Int.ModEq K (x i) (u i)) : + Int.ModEq K (MvPolynomial.eval x m) (MvPolynomial.eval u m) := by + induction m using MvPolynomial.induction_on with + | C a => simpa only [MvPolynomial.eval_C] using (Int.ModEq.refl (n:=K) a) + | add p q hp hq => simpa only [MvPolynomial.eval_add] using hp.add hq + | mul_X p i hp => simpa only [MvPolynomial.eval_mul,MvPolynomial.eval_X] using hp.mul (hx i) + +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (Γ : Subgroup G) +variable (R : Reduction c hsk χ Γ) + + + +lemma polynomial_residue_coset {V : Type*} (m : MvPolynomial V ℤ) + (x u : V → ℤ) (hx : ∀ i,Int.ModEq (R.period:ℤ) (x i) (u i)) : + let j:=MvPolynomial.eval u m % (R.period:ℤ) + (QuotientGroup.mk (R.flow c hsk χ Γ + (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ))) : G⧸Γ)= + QuotientGroup.mk (R.flow c hsk χ Γ (Multiplicative.ofAdd (j:ℝ))) := by + dsimp only + apply R.coset_period c hsk χ Γ + exact ((integer_eval_modEq (R.period:ℤ) m x u hx).trans + (Int.mod_modEq (MvPolynomial.eval u m) (R.period:ℤ)).symm).symm.dvd + + +theorem factorization_on_residue {V : Type*} (m : MvPolynomial V ℤ) + (x u : V → ℤ) (hx : ∀ i,Int.ModEq (R.period:ℤ) (x i) (u i)) + (P ℓ : G) (Q : χ.ker) + (hP : P=ℓ*Q.val*R.flow c hsk χ Γ + (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ))) : + let j:=MvPolynomial.eval u m % (R.period:ℤ) + (QuotientGroup.mk P : G⧸Γ)=kernelTestMap χ Γ + (R.flow c hsk χ Γ (Multiplicative.ofAdd (j:ℝ))) ℓ (QuotientGroup.mk Q) := by + dsimp only + rw [hP,kernelTestMap_mk] + change (ℓ*Q.val) • (QuotientGroup.mk (R.flow c hsk χ Γ + (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ))) : G⧸Γ)= + (ℓ*Q.val) • QuotientGroup.mk (R.flow c hsk χ Γ + (Multiplicative.ofAdd ((MvPolynomial.eval u m % (R.period:ℤ):ℤ):ℝ))) + rw [polynomial_residue_coset c hsk χ Γ R m x u hx] + +omit [IsTopologicalGroup G] in +lemma residue_range [IsTopologicalGroup G] {V : Type*} (m : MvPolynomial V ℤ) (u : V → ℤ) : + 0≤MvPolynomial.eval u m % (R.period:ℤ) ∧ + MvPolynomial.eval u m % (R.period:ℤ)(b i:ℝ)) t,‖g x‖≤B) → ∀ η : ℝ, + η≤‖mean (boxIndices lo hi (fun i=>(a i:ℝ)) q) f- + mean (boxIndices lo hi (fun i=>(b i:ℝ)) t) g‖ → + ∃ (hL : ∀ i,lo i(a i:ℝ)) q) (label lo hi hL M hM a q K) z).Nonempty ∧ + η-ε≤‖mean (fiber (boxIndices lo hi (fun i=>(a i:ℝ)) q) (label lo hi hL M hM a q K) z) f- + mean (fiber (boxIndices lo hi (fun i=>(b i:ℝ)) t) (label lo hi hL M hM b t K) z) g‖ := by + obtain ⟨δ,hδ,h⟩:=uniform_error_threshold (ι:=ι) c B + (Fintype.card ((ι → Fin M)×(ι → ZMod K))) ε hc hB (by positivity) hε + refine ⟨δ,hδ,?_⟩ + intro Z hZ lo hi hside a b q t hq ht hqK htK hqt f g hg η hd + have hqr : 0<(q:ℝ):=by exact_mod_cast hq + have htr : 0<(t:ℝ):=by exact_mod_cast ht + have hL : ∀ i,lo isub_pos.mp (lt_of_lt_of_le (mul_pos hc hZ) (hside i)) + obtain ⟨hsq,hst,he⟩:=h Z q t hZ hqr htr hqt lo hi hside + obtain ⟨z,hz,he⟩:=select_common_piece lo hi hL M hM a b q t K hq ht hK hqK htK + hsq hst f g B hB hg η ε hd he + exact ⟨hL,z,hz,he⟩ + +end RegularResiduePieces +end + +end + +section + + + + +noncomputable section +open scoped BigOperators NNReal +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters UniformSlowPolynomials +open RoughSamplingWeights RegularBoxPartition RegularResiduePieces FinitePieceAverages +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (Γ : Subgroup G) +variable (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable {X : Type*} [PseudoMetricSpace X] (v : (G⧸Γ) ≃ₜ X) +variable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] + +def sampledTest (e : κ → ι → ℕ) (coeff : κ → ℝ) (offset : ι → ℤ) (q : ℕ) + (F : X → ℂ) (tailPoint : (ι → ℤ) → G⧸Γ) (x : ι → ℤ) : ℂ:= + F (v ((R.flow c hsk χ Γ (Multiplicative.ofAdd + (form e coeff (fun i=>(offset i:ℝ)+q*x i)))) • tailPoint x)) + +def frozenSampledTest (e : κ → ι → ℕ) (coeff : κ → ℝ) + (lo hi : ι → ℝ) (hL : ∀ i,lo ileft (lo i) (hi i) M + (cell lo hi hL M hM (fun j=>(offset j:ℝ)+q*x j) i))))) • tailPoint x)) + +include hΓ in + + +theorem regular_sample_freezing (e : κ → ι → ℕ) (A C : ℝ) (hA : 0≤A) (hC : 0≤C) + (L : ℝ≥0) (ε : ℝ) (hε : 0<ε) : + ∃ M : ℕ,∃ hM : 0(offset i:ℝ)) q) + (sampledTest c hsk χ Γ R v e coeff offset q F tailPoint)- + mean (boxIndices lo hi (fun i=>(offset i:ℝ)) q) + (frozenSampledTest c hsk χ Γ R v e coeff lo hi hL M hM offset q F tailPoint)‖≤ε := by + obtain ⟨T,lam,hT,hlam,hfreeze⟩:=polynomial_slow_freezing c hsk χ Γ R hΓ v e A C hA hC L ε hε + obtain ⟨M,hM,hfine⟩:=fine_partition (2*C) lam hlam + refine ⟨M,hM,?_⟩ + intro Z hZ coeff hcoeff lo hi hL hb offset q hq F hF tailPoint + apply mean_error _ _ _ ε hε.le + intro x hx + have hqr : 0<(q:ℝ):=by exact_mod_cast hq + have hphys:= (mem_boxIndices lo hi (fun i=>(offset i:ℝ)) q hqr x).mp hx + let p : ι → ℝ:=fun i=>(offset i:ℝ)+q*x i + let b : ι → Fin M:=cell lo hi hL M hM p + let y : ι → ℝ:=fun i=>left (lo i) (hi i) M (b i) + have hyphys : ∀ i,y i≤p i ∧ p i(a i:ℝ)) q) + (sampledTest c hsk χ Γ R v e coeff₁ a q F₁ tail₁)- + mean (boxIndices lo hi (fun i=>(b i:ℝ)) t) + (sampledTest c hsk χ Γ R v e coeff₂ b t F₂ tail₂)‖ → + ∃ z : (ι → Fin M)×(ι → ZMod K), + (fiber (boxIndices lo hi (fun i=>(a i:ℝ)) q) (label lo hi hL M hM a q K) z).Nonempty ∧ + η-3*ε≤‖mean (fiber (boxIndices lo hi (fun i=>(a i:ℝ)) q) (label lo hi hL M hM a q K) z) + (frozenSampledTest c hsk χ Γ R v e coeff₁ lo hi hL M hM a q F₁ tail₁)- + mean (fiber (boxIndices lo hi (fun i=>(b i:ℝ)) t) (label lo hi hL M hM b t K) z) + (frozenSampledTest c hsk χ Γ R v e coeff₂ lo hi hL M hM b t F₂ tail₂)‖ := by + obtain ⟨M,hM,hfreeze⟩:=regular_sample_freezing c hsk χ Γ R hΓ v e A C hA hC L ε hε + obtain ⟨δ,hδ,hselect⟩:=uniform_piece_selection (ι:=ι) M K hM hK side B ε hside hB hε + refine ⟨M,hM,δ,hδ,?_⟩ + intro Z hZ coeff₁ coeff₂ hc₁ hc₂ lo hi hL hb hsz a b q t hq ht hqK htK hqt + F₁ F₂ hF₁ hF₂ hbound tail₁ tail₂ η hd + let S:=boxIndices lo hi (fun i=>(a i:ℝ)) q + let T:=boxIndices lo hi (fun i=>(b i:ℝ)) t + let f:=frozenSampledTest c hsk χ Γ R v e coeff₁ lo hi hL M hM a q F₁ tail₁ + let g:=frozenSampledTest c hsk χ Γ R v e coeff₂ lo hi hL M hM b t F₂ tail₂ + let u:=mean S (sampledTest c hsk χ Γ R v e coeff₁ a q F₁ tail₁) + let w:=mean T (sampledTest c hsk χ Γ R v e coeff₂ b t F₂ tail₂) + have hu : ‖u-mean S f‖≤ε:=hfreeze Z hZ coeff₁ hc₁ lo hi hL hb a q hq F₁ hF₁ tail₁ + have hw : ‖w-mean T g‖≤ε:=hfreeze Z hZ coeff₂ hc₂ lo hi hL hb b t ht F₂ hF₂ tail₂ + have hdiff : η-2*ε≤‖mean S f-mean T g‖:=by + have h₁:=norm_sub_le (u-mean S f) (w-mean S f) + have h₂:=norm_sub_le (w-mean T g) (mean S f-mean T g) + have he₁ : (u-mean S f)-(w-mean S f)=u-w:=by ring + have he₂ : (w-mean T g)-(mean S f-mean T g)=w-mean S f:=by ring + rw [he₁] at h₁ + rw [he₂] at h₂ + change η≤‖u-w‖ at hd + linarith + have hg : ∀ x∈T,‖g x‖≤B:=by + intro x _ + exact hbound _ + obtain ⟨hL',z,hz,hd'⟩:=hselect Z hZ lo hi hsz a b q t hq ht hqK htK hqt f g hg (η-2*ε) hdiff + refine ⟨z,hz,?_⟩ + change η-3*ε≤‖mean (fiber S (label lo hi hL M hM a q K) z) f- + mean (fiber T (label lo hi hL M hM b t K) z) g‖ + linarith [hd'] + +end RoughKernelFactorization + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel05.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel05.lean new file mode 100644 index 0000000000000000000000000000000000000000..86db2214bc9c07916fa5ebbea0167101b63196b4 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughKernel05.lean @@ -0,0 +1,303 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughPhysical01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughKernelDiscrepancy +open RationalLattice MalcevCharacters RoughKernelFactorization UniformSlowPolynomials +open RoughSamplingWeights RegularBoxPartition RegularResiduePieces FinitePieceAverages +open RoughPhysicalSelection +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G→*Multiplicative ℝ) (Γ : Subgroup G) (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable (hcont : Continuous χ) (hZint : ∀ g∈Γ,∃ z : ℤ,(χ g).toAdd=z) +variable {X : Type*} [PseudoMetricSpace X] (V : (G⧸Γ) ≃ₜ X) +variable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] + +include hΓ hcont hZint in + + +theorem source_kernel_discrepancy (e : κ→ι→ℕ) (A C side B : ℝ) + (hA : 0≤A) (hC : 0≤C) (hside : 0(x i:ℝ))))* + (Q x).val*R.flow c hsk χ Γ (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ))) → + ∀ η : ℝ,η≤‖mean (boxIndices lo hi (fun _=>0) 1) (fun x=>F (V (QuotientGroup.mk (P x))))- + mean (physicalResidueBox lo hi res t) (fun x=>F (V (QuotientGroup.mk (P x))))‖ → + ∃ u : ι→Fin R.period,∃ j : Fin R.period, + let σ:=residueSigma c hsk χ Γ R j + letI :=kernelCompatibleMetric χ Γ σ c hsk R hΓ hcont hZint + ∃ (lo' hi' : ι→ℝ) (res' : ι→ℤ) (g : (χ.ker⧸kernelLattice χ Γ σ)→ℂ), + LipschitzWith L' g ∧ (∀ y,‖g y‖≤B+ε) ∧ + (∀ i,-(C+1)*(Z/R.period)≤lo' i ∧ hi' i≤(C+1)*(Z/R.period)) ∧ + (∀ i,(side/M)*(Z/R.period)≤hi' i-lo' i) ∧ + η-5*ε≤‖mean (boxIndices lo' hi' (fun _=>0) 1) + (fun y=>g (QuotientGroup.mk (Q (integerAffine (fun i=>((u i).val:ℤ)) R.period y))))- + mean (physicalResidueBox lo' hi' res' t) + (fun y=>g (QuotientGroup.mk (Q (integerAffine (fun i=>((u i).val:ℤ)) R.period y))))‖ := by + classical + let : NeZero R.period:=⟨R.period_pos.ne'⟩ + obtain ⟨M,hM,T,δ,hT,hδ,hfreeze⟩:=physical_frozen_selection c hsk χ Γ R hΓ V e A C side B + hA hC hside hB L ε hε + obtain ⟨L',hreduce⟩:=finite_residue_kernel_reduction c hsk χ Γ R hΓ hcont hZint V T L B hB ε hε + refine ⟨M,hM,L',δ,hδ,?_⟩ + intro Z hKZ coeff hcoeff lo hi hbox hside' res t ht htK hsmall F hF hFB P Q m hP η hbad + have hZ : 0sub_pos.mp (lt_of_lt_of_le (mul_pos hside hZ) (hside' i)) + let tail : (ι→ℤ)→G⧸Γ:=fun x=>QuotientGroup.mk ((Q x).val* + R.flow c hsk χ Γ (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ))) + have hval (a : ℝ) (x : ι→ℤ) : + F (V ((R.flow c hsk χ Γ (Multiplicative.ofAdd a)) • tail x))= + F (V (QuotientGroup.mk (R.flow c hsk χ Γ (Multiplicative.ofAdd a)*(Q x).val* + R.flow c hsk χ Γ (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ))))) := by + congr 2 + change (QuotientGroup.mk (_*(_*_)) : G⧸Γ)=QuotientGroup.mk ((_*_)*_) + rw [mul_assoc] + have horig (x : ι→ℤ) : F (V ((R.flow c hsk χ Γ + (Multiplicative.ofAdd (form e coeff (fun i=>(x i:ℝ))))) • tail x))= + F (V (QuotientGroup.mk (P x))):=by rw [hval,←hP] + obtain ⟨b,u,ha,hdisc⟩:=hfreeze Z hZ coeff hcoeff lo hi hL hbox hside' res t ht htK hsmall + F hF hFB tail η (by simpa only [horig] using hbad) + let a : Set.Icc (-T) T:=⟨form e coeff (fun i=>left (lo i) (hi i) M (b i)),abs_le.mp ha⟩ + let u' : ι→Fin R.period:=fun i=>⟨(u i).val,ZMod.val_lt (u i)⟩ + let left' : ι→ℝ:=fun i=>left (lo i) (hi i) M (b i) + let right' : ι→ℝ:=fun i=>right (lo i) (hi i) M (b i) + let S:=physicalResidueBox left' right' (fun i=>((u i).val:ℤ)) R.period + let U:=S.filter (fun x=>∀ i,x i≡res i [ZMOD t]) + let frozenP : (ι→ℤ)→G:=fun x=>R.flow c hsk χ Γ (Multiplicative.ofAdd a.val)*(Q x).val* + R.flow c hsk χ Γ (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ)) + have hdisc' : η-3*ε≤‖mean S (fun x=>F (V (QuotientGroup.mk (frozenP x))))- + mean U (fun x=>F (V (QuotientGroup.mk (frozenP x))))‖:=by + simpa only [hval] using hdisc + obtain ⟨j,hj⟩:=hreduce ι (ι→ℤ) m (fun i=>((u i).val:ℤ)) + let σ:=residueSigma c hsk χ Γ R j + let :=kernelCompatibleMetric χ Γ σ c hsk R hΓ hcont hZint + obtain ⟨g,hg,hgB,hgd⟩:=hj a F hF hFB + have hres : ∀ x∈S∪U,∀ i,x i≡((u i).val:ℤ) [ZMOD R.period]:=by + intro x hx + have hxS : x∈S:=by + rcases Finset.mem_union.mp hx with hx | hx + · exact hx + · exact (Finset.mem_filter.mp hx).1 + exact (mem_physical left' right' _ _ x).mp hxS |>.2 + have hgd':=hgd S U id frozenP Q hres (by intro x hx; rfl) (η-3*ε) hdisc' + have hgd'' : η-5*ε≤‖mean S (fun x=>g (QuotientGroup.mk (Q x)))- + mean U (fun x=>g (QuotientGroup.mk (Q x)))‖:=by linarith + obtain ⟨res',hrescale⟩:=rescaled_discrepancy (fun i=>((u i).val:ℤ)) res R.period t R.period_pos htK.symm + have hfinal:= (hrescale left' right' (fun x=>g (QuotientGroup.mk (Q x))) (η-5*ε)).mp hgd'' + refine ⟨u',j,rescaledEndpoint left' (fun i=>((u i).val:ℤ)) R.period, + rescaledEndpoint right' (fun i=>((u i).val:ℤ)) R.period,res',g,hg,hgB,?_,?_,hfinal⟩ + · have hgeom:=rescaled_geometry left' right' (fun i=>((u i).val:ℤ)) R.period R.period_pos + Z C (side/M) hKZ hC (fun i=>⟨by positivity,by exact_mod_cast (ZMod.val_lt (u i)).le⟩) + (fun i=>⟨(hbox i).1.trans (endpoints (lo i) (hi i) (hL i) M hM (b i)).1, + (endpoints (lo i) (hi i) (hL i) M hM (b i)).2.2.1.trans (hbox i).2⟩) (by + intro i + change (side/M)*Z≤right (lo i) (hi i) M (b i)-left (lo i) (hi i) M (b i) + rw [(endpoints (lo i) (hi i) (hL i) M hM (b i)).2.2.2] + calc _=(side*Z)/M:=by ring + _≤_:=div_le_div_of_nonneg_right (hside' i) (by positivity)) + exact fun i=>⟨(hgeom i).1,(hgeom i).2.1⟩ + · intro i + change (side/M)*(Z/R.period)≤(right' i-(u i).val)/R.period-(left' i-(u i).val)/R.period + have he:= (endpoints (lo i) (hi i) (hL i) M hM (b i)).2.2.2 + change right' i-left' i=(hi i-lo i)/M at he + calc + _=(side*Z/M)/R.period:=by ring + _≤((hi i-lo i)/M)/R.period:=by gcongr; exact hside' i + _=(right' i-left' i)/R.period:=by rw [he] + _=_:=by ring + +end RoughKernelDiscrepancy + +end + +end + +section + + + + +noncomputable section +namespace RoughKernelCover +open RationalLattice MalcevCharacters RoughKernelFactorization RealPolynomialDegree + +section General +variable {G K : Type*} [Group G] [Group K] [TopologicalSpace G] [TopologicalSpace K] +variable [IsTopologicalGroup G] [IsTopologicalGroup K] {m n : ℕ} +variable (c : RealCoordinates G m) (d : RealCoordinates K n) +variable (F : K→*G) (Γ : Subgroup G) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + +include hΓ in + + +omit [IsTopologicalGroup G] in +theorem integer_second_cover + (hpoly : ∀ i,RationalPolynomialMap.IsPolynomial (fun x : Fin n→ℝ=>c.coord (F (d.coord.symm x)) i)) : + ∃ Λ : Subgroup K,∃ e : RealCoordinates K n,SecondKind e ∧ + (∀ g : K,g∈Λ ↔ ∀ i,∃ z : ℤ,e.coord g i=z) ∧ Λ≤Γ.comap F ∧ + ∃ E : ℕ,0canonicalLog d (P x) i) D) → + ∀ i,HasDegree (fun x=>canonicalLog e (P x) i) (E*D) := by + classical + obtain ⟨A,hA,hgrid⟩:=rationalHom_origin_grid c d F hpoly + obtain ⟨w,hw,hAw,hcl⟩:=exists_lattice_weights d A hA + let Λ:=weightedLattice d w hcl + let d':=scaledCoordinates d w hw + have hΛ : ∀ g : K,g∈Λ ↔ ∀ i,∃ z : ℤ,d'.coord g i=z:=weightedLattice_iff d w hcl hw + have hle : Λ≤Γ.comap F:=by + intro g hg + apply (hΓ _).mpr + have hh : ∀ i,∃ z : ℤ,d.coord g i=(A:ℝ)*(z:ℝ):=by + intro i + obtain ⟨a,ha⟩:=hg i + obtain ⟨b,hb⟩:=hAw i + refine ⟨(b:ℤ)*a,?_⟩ + rw [ha,hb] + push_cast + ring + simpa using hgrid (d.coord g) hh + let e:=secondCoordinates d' + have he : ∀ i,RationalPolynomialMap.IsPolynomial (fun x : Fin n→ℝ=>e.coord (d.coord.symm x) i):=by + intro i + apply polynomial_expCoordinates d' + intro j + change RationalPolynomialMap.IsPolynomial (fun x : Fin n→ℝ=>d.coord (d.coord.symm x) j/(w j:ℝ)) + simpa only [Homeomorph.apply_symm_apply,div_eq_mul_inv,Rat.cast_inv,Rat.cast_natCast] using + RationalPolynomialMap.mul (RationalPolynomialMap.coordinate j) (RationalPolynomialMap.const (w j:ℚ)⁻¹) + obtain ⟨C,hC,hcoord⟩:=coord_degree_bound d + obtain ⟨L,hL,hlog⟩:=log_degree_bound e + obtain ⟨T,hT,htransfer⟩:=rational_map_bound (fun i x=>e.coord (d.coord.symm x) i) he + refine ⟨Λ,e,secondCoordinates_secondKind d',expCoordinates_lattice d' Λ hΛ,hle, + L*(T*C),Nat.mul_pos hL (Nat.mul_pos hT hC),?_⟩ + intro v D P hP i + have hc:=hcoord v D P hP + have ht : ∀ j,HasDegree (fun x=>e.coord (P x) j) (T*(C*D)):=by + intro j + simpa only [Homeomorph.symm_apply_apply] using htransfer v (C*D) (fun j x=>d.coord (P x) j) hc j + simpa only [Nat.mul_assoc] using hlog v (T*(C*D)) P ht i +end General + +section Kernel +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G→*Multiplicative ℝ) (Γ : Subgroup G) (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + +lemma kernel_embedding_polynomial (σ : G) (hσ : IsRational c σ) : + ∀ i,RationalPolynomialMap.IsPolynomial (fun x : Fin n→ℝ=> + c.coord (kernelInclusion χ σ ((R.chart c hsk χ Γ).coord.symm x)) i):=by + have hsub : IsPolynomialMap c (fun x : Fin n→ℝ=>((R.chart c hsk χ Γ).coord.symm x).val):=by + intro i + change RationalPolynomialMap.IsPolynomial (fun x : Fin n→ℝ=>c.coord + (c.coord.symm (IntegerHyperplane.lift R.k R.p x)) i) + simpa only [Homeomorph.apply_symm_apply] using IntegerHyperplane.lift_polynomial R.k R.p i + have hσp : IsPolynomialMap c (fun _ : Fin n→ℝ=>σ):=polynomialMap_const c hσ + simpa only [kernelInclusion_apply,IsPolynomialMap] using polynomialMap_mul c (polynomialMap_mul c (polynomialMap_inv c hσp) hsub) hσp + +include hΓ in + + +theorem kernel_integer_cover (j : Fin R.period) : + ∃ Λ : Subgroup χ.ker,∃ e : RealCoordinates χ.ker n,SecondKind e ∧ + (∀ g : χ.ker,g∈Λ ↔ ∀ i,∃ z : ℤ,e.coord g i=z) ∧ + Λ≤kernelLattice χ Γ (residueSigma c hsk χ Γ R j) ∧ + ∃ E : ℕ,0canonicalLog (R.chart c hsk χ Γ) (P x) i) D) → + ∀ i,HasDegree (fun x=>canonicalLog e (P x) i) (E*D) := by + apply integer_second_cover c (R.chart c hsk χ Γ) + (kernelInclusion χ (residueSigma c hsk χ Γ R j)) Γ hΓ + apply kernel_embedding_polynomial c hsk χ Γ R + simpa only [residueSigma,Rat.cast_natCast] using R.flow_rational c hsk χ Γ (j.val:ℚ) +end Kernel + +end RoughKernelCover + +end + +end + +section + + + + +noncomputable section +namespace RoughCoverTests +open RationalLattice FinitePieceAverages +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (Λ Γ : Subgroup G) +variable (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) (hle : Λ≤Γ) +variable {X : Type*} [PseudoMetricSpace X] (V : (G⧸Γ) ≃ₜ X) +include hle in + + +theorem uniform_cover_tests (L : NNReal) (B ε : ℝ) (hB : 0≤B) (hε : 0<ε) : + letI :=coordinateQuotientMetric c Λ hΛ + ∃ L' : NNReal,∀ F : X→ℂ,LipschitzWith L F →(∀ x,‖F x‖≤B) → + ∃ g : (G⧸Λ)→ℂ,LipschitzWith L' g ∧ (∀ y,‖g y‖≤B+ε) ∧ + ∀ (α : Type*) (S T : Finset α) (P : α→G) (η : ℝ), + η≤‖mean S (fun x=>F (V (QuotientGroup.mk (P x))))- + mean T (fun x=>F (V (QuotientGroup.mk (P x))))‖ → + η-2*ε≤‖mean S (fun x=>g (QuotientGroup.mk (P x)))- + mean T (fun x=>g (QuotientGroup.mk (P x)))‖ := by + let :=coordinateQuotientMetric c Λ hΛ + let : CompactSpace (G⧸Λ):=AbelianMalcevTorus.quotient_compact c Λ hΛ + let p : C(G⧸Λ,X):=(⟨V,V.continuous⟩ : C(G⧸Γ,X)).comp + (NonnormalCoset.map Λ Γ (MonoidHom.id G) continuous_id hle) + let H : C(PUnit.{1}×(G⧸Λ),X):=p.comp ContinuousMap.snd + obtain ⟨L',hL'⟩:=UniformLipschitzApproximation.compact_pullback_complex H L B hB ε hε + refine ⟨L',?_⟩ + intro F hF hFB + obtain ⟨g,hg,herr,hgB⟩:=hL' PUnit.unit F hF hFB + refine ⟨g,hg,hgB,?_⟩ + intro α S T P η hbad + let f : α→ℂ:=fun x=>F (V (QuotientGroup.mk (P x))) + let f' : α→ℂ:=fun x=>g (QuotientGroup.mk (P x)) + have hp (x : α) : ‖f x-f' x‖≤ε:=by + rw [norm_sub_rev] + simpa only [f,f',H,p,ContinuousMap.comp_apply,ContinuousMap.coe_mk,ContinuousMap.snd_apply,NonnormalCoset.map_mk,MonoidHom.id_apply] using (herr (QuotientGroup.mk (P x))).le + have hs:=mean_error S f f' ε hε.le (fun x _=>hp x) + have ht:=mean_error T f f' ε hε.le (fun x _=>hp x) + have h₁:=norm_sub_le (mean S f-mean S f') (mean T f-mean S f') + have h₂:=norm_sub_le (mean T f-mean T f') (mean S f'-mean T f') + have he₁ : (mean S f-mean S f')-(mean T f-mean S f')=mean S f-mean T f:=by ring + have he₂ : (mean T f-mean T f')-(mean S f'-mean T f')=mean T f-mean S f':=by ring + rw [he₁] at h₁ + rw [he₂] at h₂ + change η≤‖mean S f-mean T f‖ at hbad + change η-2*ε≤‖mean S f'-mean T f'‖ + linarith + +end RoughCoverTests + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughLiteral01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughLiteral01.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8fa78d52c9392f3cc62c79527606dd5c43477ab --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughLiteral01.lean @@ -0,0 +1,360 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughExtremal01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +namespace RoughSourceExceptional +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights RoughProgressionDensity RoughExtremalProgressions + +lemma Ico_eq_range (a b : ℤ) : + (Finset.Ico a b)=(Finset.range ((Finset.Ico a b).card)).image (fun i : ℕ=>a+(i:ℤ)):=by + ext z + simp only [Finset.mem_Ico,Finset.mem_image,Finset.mem_range,Int.card_Ico] + constructor + · intro hz + refine ⟨(z-a).toNat,?_,?_⟩ <;> omega + · rintro ⟨i,hi,rfl⟩ + omega + +def timeLength (S : ℝ) (r L : ℤ) : ℕ:=(indices S (2*S) r L).card +def firstTime (S : ℝ) (r L : ℤ) : ℤ:=r+L*⌈(S-r)/L⌉ +def times (S : ℝ) (r L : ℤ) : Finset ℤ:=(indices S (2*S) r L).image (fun z=>r+L*z) + +lemma times_eq_range (S : ℝ) (r L : ℤ) : + times S r L=(Finset.range (timeLength S r L)).image (fun i : ℕ=>firstTime S r L+L*(i:ℤ)):=by + unfold times timeLength + conv_lhs => arg 2; unfold indices; rw [Ico_eq_range] + rw [Finset.image_image] + apply Finset.image_congr + intro i hi + simp only [Function.comp_apply,firstTime] + ring + +lemma mem_times (S : ℝ) (r L t : ℤ) (hL : 0firstTime S r L+L*(i:ℤ)):=by + intro i j hij + have hi : (i:ℤ)=(j:ℤ):=mul_left_cancel₀ hL.ne' (add_left_cancel hij) + exact_mod_cast hi + +lemma times_card (S : ℝ) (r L : ℤ) (hL : 0S n/(L n:ℝ)) atTop atTop) : + Tendsto (fun n=>(timeLength (S n) (r n) (L n):ℝ)) atTop atTop:=by + apply tendsto_atTop.mpr + intro A + filter_upwards [hS.eventually (eventually_ge_atTop 0),hSL.eventually (eventually_ge_atTop (A+2))] + with n hsn hsl + have he:=count_error (S n) (2*S n) (r n) (L n) (by exact_mod_cast hL n) (by linarith) + change |(timeLength (S n) (r n) (L n):ℝ)-(2*S n-S n)/(L n:ℝ)|≤2 at he + have hs : (2*S n-S n)/(L n:ℝ)=S n/(L n:ℝ):=by ring + rw [hs,abs_le] at he + linarith + + + +lemma integer_scales_of_real {S Z : ℕ→ℝ} (hS : Tendsto S atTop atTop) + (hZ : ∀ a : ℝ,0Z n/S n^a) atTop atTop) : + ∀ k : ℕ,Tendsto (fun n=>Z n/S n^k) atTop atTop:=by + intro k + cases k with + | zero=> + have hz1 : Tendsto (fun n=>Z n/S n) atTop atTop:=by + simpa only [Real.rpow_one] using hZ 1 (by norm_num) + have hp:=hz1.atTop_mul_atTop₀ hS + have hz : Tendsto Z atTop atTop:=by + apply Filter.Tendsto.congr' _ hp + filter_upwards [hS.eventually (eventually_gt_atTop 0)] with n hn + exact div_mul_cancel₀ _ hn.ne' + simpa only [pow_zero,div_one] using hz + | succ k=> + simpa only [Real.rpow_natCast] using hZ ((k+1:ℕ):ℝ) (by positivity) + +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (c : RealCoordinates G dim) (Γ : Subgroup G) [mtr : MetricSpace (G⧸Γ)] +local instance roughLiteral01ExceptionalTopology : TopologicalSpace (G⧸Γ):= + mtr.toUniformSpace.toTopologicalSpace + + +def exceptional (v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z S : ℝ) + (P : (Fin (v+1)→ℝ)→G) (r L : ℤ) : Finset ℤ:=by + classical + exact (times S r L).filter (BadAt Γ v c₀ C₀ B η Z P) + +omit [TopologicalSpace G] in +lemma exceptional_card (v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z S : ℝ) + (P : (Fin (v+1)→ℝ)→G) (r L : ℤ) (hL : 0Z n/S n^a) atTop atTop) + (hL : ∀ n,0S n/(L n:ℝ)) atTop atTop) : + ∃ H : ℕ,0canonicalLog c (P y) i) D) → + ((exceptional Γ v c₀ C₀ B η (Z n) (S n) P (r n) (L n)).card:ℝ)/ + ((times (S n) (r n) (L n)).card:ℝ)≤(extremal H K:ℝ)/K+ε:=by + classical + obtain ⟨H,hH,hbound⟩:=eventual_density_bound c Γ hsk hΓ htop v D c₀ C₀ B η hc₀ hC₀ hB hη + w S Z hw hS (integer_scales_of_real hS hZ) + have ht:=timeLength_tendsto (r:=r) hL hS hSL + refine ⟨H,hH,fun K hK ε hε=>?_⟩ + filter_upwards [hbound K hK,ht.eventually (eventually_ge_atTop 1), + ht.eventually (eventually_ge_atTop ((K:ℝ)/ε))] with n hbn hn hne + intro P hP + have hNp : 0<(timeLength (S n) (r n) (L n):ℝ):=by linarith + have hN : 0 simp only [lower,leftCondition,Bool.false_eq_true,ite_false,ite_true] + · rw [Int.add_one_le_iff,Int.floor_lt] + · exact Int.ceil_le + +lemma lt_upper_iff (closed : Bool) (a : ℝ) (x : ℤ) : + x simp only [upper,rightCondition,Bool.false_eq_true,ite_false,ite_true] + · exact Int.lt_ceil + · rw [Int.lt_add_one_iff,Int.le_floor] + +lemma lower_bounds (closed : Bool) (a : ℝ) : + a≤(lower closed a:ℝ) ∧ (lower closed a:ℝ)≤a+1 := by + cases closed + · simp only [lower,Bool.false_eq_true,ite_false,Int.cast_add,Int.cast_one] + constructor <;> linarith [Int.floor_le a,Int.lt_floor_add_one a] + · simpa only [lower,ite_true] using And.intro (Int.le_ceil a) (Int.ceil_lt_add_one a).le + +lemma upper_bounds (closed : Bool) (a : ℝ) : + a≤(upper closed a:ℝ) ∧ (upper closed a:ℝ)≤a+1 := by + cases closed + · simpa only [upper,Bool.false_eq_true,ite_false] using + And.intro (Int.le_ceil a) (Int.ceil_lt_add_one a).le + · simp only [upper,ite_true,Int.cast_add,Int.cast_one] + constructor <;> linarith [Int.floor_le a,Int.lt_floor_add_one a] + +variable {v : ℕ} + +def points (lo hi : Fin v→ℝ) (lc rc : Fin v→Bool) : Finset (Fin v→ℤ) := + Fintype.piFinset (fun i=>Finset.Ico (lower (lc i) (lo i)) (upper (rc i) (hi i))) + +lemma mem_points (lo hi : Fin v→ℝ) (lc rc : Fin v→Bool) (x : Fin v→ℤ) : + x∈points lo hi lc rc ↔ ∀ i,leftCondition (lc i) (lo i) (x i) ∧ + rightCondition (rc i) (x i) (hi i) := by + simp only [points,Fintype.mem_piFinset,Finset.mem_Ico,lower_le_iff,lt_upper_iff] + + +lemma points_eq_box (lo hi : Fin v→ℝ) (lc rc : Fin v→Bool) : + points lo hi lc rc = boxIndices (fun i=>(lower (lc i) (lo i):ℝ)) + (fun i=>(upper (rc i) (hi i):ℝ)) (fun _=>0) 1 := by + ext x + simp only [points,Fintype.mem_piFinset,Finset.mem_Ico, + mem_boxIndices _ _ _ _ zero_lt_one,zero_add,one_mul,Int.cast_le,Int.cast_lt] + + +def residuePoints (lo hi : Fin v→ℝ) (lc rc : Fin v→Bool) (res : Fin v→ℤ) (t : ℤ) : + Finset (Fin v→ℤ) := + (points lo hi lc rc).filter (fun x=>∀ i,x i ≡ res i [ZMOD t]) + +lemma residuePoints_eq_box (lo hi : Fin v→ℝ) (lc rc : Fin v→Bool) (res : Fin v→ℤ) (t : ℤ) : + residuePoints lo hi lc rc res t = physicalResidueBox + (fun i=>(lower (lc i) (lo i):ℝ)) (fun i=>(upper (rc i) (hi i):ℝ)) res t.natAbs := by + simp only [residuePoints,physicalResidueBox,points_eq_box,Int.modEq_natAbs] + + +lemma rounded_geometry (lo hi : Fin v→ℝ) (lc rc : Fin v→Bool) (c C Z : ℝ) + (hZ : 1≤Z) (hcZ : 2≤c*Z) + (hs : ∀ i,c*Z≤hi i-lo i) (hb : ∀ i,-C*Z≤lo i ∧ hi i≤C*Z) : + (∀ i,(c/2)*Z≤(upper (rc i) (hi i):ℝ)-(lower (lc i) (lo i):ℝ)) ∧ + (∀ i,-(C+1)*Z≤(lower (lc i) (lo i):ℝ) ∧ (upper (rc i) (hi i):ℝ)≤(C+1)*Z) := by + constructor + · intro i + obtain ⟨hl₀,hl₁⟩:=lower_bounds (lc i) (lo i) + obtain ⟨hh₀,hh₁⟩:=upper_bounds (rc i) (hi i) + nlinarith [hs i] + · intro i + obtain ⟨hl₀,hl₁⟩:=lower_bounds (lc i) (lo i) + obtain ⟨hh₀,hh₁⟩:=upper_bounds (rc i) (hi i) + constructor <;> nlinarith [(hb i).1,(hb i).2] + +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (c : RealCoordinates G dim) (Γ : Subgroup G) [mtr : MetricSpace (G⧸Γ)] +local instance roughLiteral01BoxesTopology : TopologicalSpace (G⧸Γ):= + mtr.toUniformSpace.toTopologicalSpace + + +def BadAt (v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z : ℝ) + (P : (Fin (v+1)→ℝ)→G) (t : ℤ) : Prop := + ∃ (lo hi : Fin v→ℝ) (lc rc : Fin v→Bool) (res : Fin v→ℤ) (test : (G⧸Γ)→ℂ), + (∀ i,c₀*Z≤hi i-lo i) ∧ (∀ i,-C₀*Z≤lo i ∧ hi i≤C₀*Z) ∧ + LipschitzWith B test ∧ (∀ y,‖test y‖≤B) ∧ + η≤‖mean (points lo hi lc rc) + (fun x=>test (QuotientGroup.mk (P (Fin.cons (t:ℝ) (fun i=>(x i:ℝ))))))- + mean (residuePoints lo hi lc rc res t) + (fun x=>test (QuotientGroup.mk (P (Fin.cons (t:ℝ) (fun i=>(x i:ℝ))))))‖ + +omit [TopologicalSpace G] in +lemma badAt_halfopen (v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z : ℝ) + (P : (Fin (v+1)→ℝ)→G) (t : ℤ) (hZ : 1≤Z) (hcZ : 2≤c₀*Z) : + BadAt Γ v c₀ C₀ B η Z P t → + RoughProgressionDensity.BadAt Γ v (c₀/2) (C₀+1) B η Z P t := by + rintro ⟨lo,hi,lc,rc,res,test,hs,hb,hlip,hbound,hbad⟩ + obtain ⟨hs',hb'⟩:=rounded_geometry lo hi lc rc c₀ C₀ Z hZ hcZ hs hb + refine ⟨(fun i=>(lower (lc i) (lo i):ℝ)),(fun i=>(upper (rc i) (hi i):ℝ)), + res,test,hs',hb',hlip,hbound,?_⟩ + simpa only [points_eq_box,residuePoints_eq_box lo hi lc rc res t] using hbad + + +def exceptional (v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z S : ℝ) + (P : (Fin (v+1)→ℝ)→G) (r L : ℤ) : Finset ℤ := by + classical + exact (RoughSourceExceptional.times S r L).filter (BadAt Γ v c₀ C₀ B η Z P) + +omit [TopologicalSpace G] in +lemma exceptional_subset (v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z S : ℝ) + (P : (Fin (v+1)→ℝ)→G) (r L : ℤ) (hZ : 1≤Z) (hcZ : 2≤c₀*Z) : + exceptional Γ v c₀ C₀ B η Z S P r L ⊆ + RoughSourceExceptional.exceptional Γ v (c₀/2) (C₀+1) B η Z S P r L := by + classical + intro t ht + obtain ⟨hmem,hbad⟩:=Finset.mem_filter.mp ht + exact Finset.mem_filter.mpr ⟨hmem,badAt_halfopen Γ v c₀ C₀ B η Z P t hZ hcZ hbad⟩ + +variable [IsTopologicalGroup G] +variable (hsk : SecondKind c) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) + +include hsk hΓ htop in + + +theorem source_literal_bound (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^a) atTop atTop) + (hL : ∀ n,0S n/(L n:ℝ)) atTop atTop) : + ∃ H : ℕ,0canonicalLog c (P y) i) D) → + ((exceptional Γ v c₀ C₀ B η (Z n) (S n) P (r n) (L n)).card:ℝ)/ + ((RoughSourceExceptional.times (S n) (r n) (L n)).card:ℝ)≤(extremal H K:ℝ)/K+ε := by + classical + obtain ⟨H,hH,hbound⟩:=RoughSourceExceptional.source_exceptional_bound c Γ hsk hΓ htop + v D (c₀/2) (C₀+1) B η (by positivity) (by positivity) hB hη + w S Z r L hw hS hZ hL hsm hWL hr hSL + have hZ' : Tendsto Z atTop atTop:=by + simpa only [pow_zero,div_one] using RoughSourceExceptional.integer_scales_of_real hS hZ 0 + refine ⟨H,hH,fun K hK ε hε=>?_⟩ + filter_upwards [hbound K hK ε hε,hZ'.eventually (eventually_ge_atTop 1), + hZ'.eventually (eventually_ge_atTop (2/c₀))] with n hbn hn hn' + intro P hP + have hcn : 2≤c₀*Z n:=by nlinarith [(div_le_iff₀ hc₀).mp hn'] + have hcard := Finset.card_le_card (exceptional_subset Γ v c₀ C₀ B η (Z n) (S n) + P (r n) (L n) hn hcn) + apply le_trans (div_le_div_of_nonneg_right (by exact_mod_cast hcard) (by positivity)) + (hbn P hP) + +end RoughLiteralBoxes + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughLog01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughLog01.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a94d8e37d3639613b824dc62dbaafc7fba7b1a2 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughLog01.lean @@ -0,0 +1,262 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CoefficientPeeling01 +import OAI.Geometry.NilpotentCharts.Filtrations +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +open _root_.Polynomial _root_.OAI.Polynomial Finset +open scoped BigOperators +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial Filter +open scoped Topology +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughCoefficientDescentBridge +open _root_.Polynomial _root_.OAI.Polynomial Finset Filter +open PolynomialLineCoefficients TriangularLatticeRecovery +open RoughJointCoefficients CorrectedBoxLeibman +open RoughScales CoefficientPeeling PositiveCoefficientDescent + +abbrev PositiveGrid (v s : ℕ) := {I : PolynomialLineCoefficients.Grid v s // 0 < totalDegree I} + +lemma totalDegree_le {v s : ℕ} (I : PolynomialLineCoefficients.Grid v s) : + totalDegree I ≤ v*s := by + calc + ∑ i, (I i).val ≤ ∑ _ : Fin v,s := Finset.sum_le_sum (fun i _=>Nat.le_of_lt_succ (I i).isLt) + _ = v*s := by simp + +lemma circleNorm_nearInteger {x ε : ℝ} (h : circleNorm x ≤ ε) : NearInteger x ε := by + exact ⟨round x,by simpa only [circleNorm,UnitAddCircle.norm_eq] using h⟩ + +lemma positive_peeling {v s : ℕ} (u : Fin v → ℤ) + (a : PolynomialLineCoefficients.Grid v s → ℝ) (I : PositiveGrid v s) : + gridTranslate a u I.val = a I.val + + ∑ J ∈ (Finset.univ : Finset (PositiveGrid v s)).filter + (fun J=>totalDegree I.val < totalDegree J.val), + (translationMatrix u I.val J.val:ℝ)*a J.val := by + classical + rw [gridTranslate_peeling] + congr 1 + simp only [Finset.sum_filter] + have hpos : ∑ J ∈ Finset.univ.filter (fun J : PolynomialLineCoefficients.Grid v s=>0(θ I).eval (z:ℝ)) (u z)) I) + ≤ A*((p z:ℝ)/Z)^totalDegree I) : + Input (fun I : PositiveGrid v s=>totalDegree I.val) N ((v+1)*s) w S Z α A (((2:ℝ)^s)^v) where + E := E + in_interval := hE + enough_nodes := hcard + dense := hdens + a := a + b := b + positive_step := hb + smooth_step := hbsm + scale := hscale + rough := hrough + θ := fun I=>θ I.val + polynomial_degree I := by + have hlin : (C (a:ℝ)+C (b:ℝ)*X).natDegree ≤ 1 := + natDegree_add_le_of_degree_le (by simp) ((natDegree_C_mul_le _ _).trans (by simp)) + have hpow : ((C (a:ℝ)+C (b:ℝ)*X)^totalDegree I.val).natDegree ≤ totalDegree I.val := + natDegree_pow_le.trans (by simpa using Nat.mul_le_mul_left (totalDegree I.val) hlin) + exact natDegree_mul_le.trans ((Nat.add_le_add hpow (hθ I.val)).trans (by + simpa only [Nat.add_mul,Nat.one_mul] using Nat.add_le_add_right (totalDegree_le I.val) s)) + p := p + steps := hsteps + c := fun I J z=>translationMatrix (u z) I.val J.val + residue_bound I J z hz hij := translationMatrix_degree_bound (u z) (p z) (hp z hz) + (hu z hz) I.val J.val hij + obstruction I z hz := by + have h := circleNorm_nearInteger (hobs z hz I.val I.property) + simpa only [gridDilate,positive_peeling] using h + + + +theorem eventual_multivariate_coefficients (v s : ℕ) {α A : ℝ} + (hα : 0<α) (hA : 0Z n/S n^k) atTop atTop) : + ∃ B : ℝ,1≤B ∧ ∀ N : ℕ,0(θ I).eval (z:ℝ)) (u z)) I) + ≤ A*((p z:ℝ)/Z n)^totalDegree I), + ∃ M : PositiveGrid v s → ℚ[X],∀ I, + Controlled ((v+1)*s) (w n) (totalDegree I.val) N E (Z n) B (θ I.val) (M I) := by + classical + obtain ⟨B,hB,hprod⟩ := eventual_rational_coefficients + (fun I : PositiveGrid v s=>totalDegree I.val) (v*s) ((v+1)*s) + (C₀ := ((2:ℝ)^s)^v) + (fun I=>⟨I.property,totalDegree_le I.val⟩) (by simp only [Nat.add_mul,Nat.one_mul]; omega) hα hA (by positivity) hw hS hZ + refine ⟨B,hB,?_⟩ + intro N hN + filter_upwards [hprod N hN] with n hn + intro E hE hc hd a b hb hsm hsc hr θ hθ p u hp hst hu ho + exact hn (descentInput E hE hc hd a b hb hsm hsc hr θ hθ p u hp hst hu ho) + +end RoughCoefficientDescentBridge + +end + +end + +section + + + + +namespace StretchedFiltration +open Subgroup +variable {G : Type*} [Group G] + + + +end StretchedFiltration + + +end + +section + + + + +noncomputable section +namespace RoughLogPolynomialAdaptation +open RationalLattice MalcevCharacters RealPolynomialDegree +open CubeFaces CubePolynomials LeibmanSquare + + + +def filtration {G : Type*} [Group G] (D : ℕ) (hD : 0c.coord (P x) i) D) : + LeibmanSquare.Polynomial (filtration D hD) 0 P := by + classical + have haxis (i : Fin n) : LeibmanSquare.Polynomial (filtration D hD) 0 + (fun x=>axis c i (c.coord (P x) i)) := by + obtain ⟨p,hp,he⟩:=hP i + have hdiff : ScalarDifferenceDegree.DegreeAtMost D (fun x=>c.coord (P x) i) := by + simp_rw [he] + exact ScalarDifferenceDegree.eval_polynomial p hp + exact ScalarDifferenceDegree.polynomial_power (filtration D hD) + (MalcevTailSection.axisHom c hsk i) D (by + intro r + change _∈StretchedFiltration.stretch D D + rw [StretchedFiltration.stretch_eq_top hD le_rfl] + trivial) hdiff + have hp:=CubeTaylorExpansion.polynomial_list_prod (filtration D hD) + (List.finRange n) (fun i x=>axis c i (c.coord (P x) i)) (fun i _=>haxis i) + convert hp using 1 + funext x + simp only [← List.ofFn_eq_map] + exact hsk.ordered (P x) + +def intCastVector (v : ℕ) : (Fin v→ℤ)→+(Fin v→ℝ) where + toFun x i := (x i:ℝ) + map_zero' := by ext i; simp + map_add' x y := by ext i; simp + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma restrict_integer {v : ℕ} (H : Filtration G) (P : (Fin v→ℝ)→G) + (hP : LeibmanSquare.Polynomial H 0 P) : + LeibmanSquare.Polynomial H 0 (fun x : Fin v→ℤ=>P (fun i=>(x i:ℝ))) := by + simpa only [intCastVector,AddMonoidHom.coe_mk,ZeroHom.coe_mk,zero_add] using + (LeibmanSquare.polynomial_affine H hP (intCastVector v) 0) + +include hsk in + + +omit [IsTopologicalGroup G] in +theorem logarithmic_adapted : ∃ C : ℕ,0canonicalLog c (P x) i) d) → + LeibmanSquare.Polynomial + (filtration (max 1 (C*d)) (lt_of_lt_of_le Nat.zero_lt_one (le_max_left _ _))) 0 P ∧ + LeibmanSquare.Polynomial + (filtration (max 1 (C*d)) (lt_of_lt_of_le Nat.zero_lt_one (le_max_left _ _))) 0 + (fun x : Fin v→ℤ=>P (fun i=>(x i:ℝ))) := by + obtain ⟨C,hC,hcoord⟩:=coord_degree_bound c + refine ⟨C,hC,fun v d P hP=>?_⟩ + have hp:=coordinate_adapted c hsk + (lt_of_lt_of_le Nat.zero_lt_one (le_max_left 1 (C*d))) P + (fun i=>RealPolynomialDegree.mono (hcoord v d P hP i) (le_max_right _ _)) + exact ⟨hp,restrict_integer _ P hp⟩ + +end RoughLogPolynomialAdaptation + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughPhysical01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughPhysical01.lean new file mode 100644 index 0000000000000000000000000000000000000000..eb196d0f8b8a67648bbf74691b65b5e7502a3a34 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughPhysical01.lean @@ -0,0 +1,377 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughKernel04 +import OAI.Combinatorics.SumProduct.Alignment.RoughRational01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open scoped BigOperators +end + +end + +section + + + + +noncomputable section +namespace RoughBadBlock +open RationalLattice RealPolynomialDegree RoughScales +open FinitePieceAverages RoughSamplingWeights RoughCharacterThinning +variable {G : Type*} [Group G] [TopologicalSpace G] {n : ℕ} +variable (c : RealCoordinates G n) (Γ : Subgroup G) [mtr : MetricSpace (G⧸Γ)] +local instance : TopologicalSpace (G⧸Γ):=mtr.toUniformSpace.toTopologicalSpace + + + +structure Block (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) (w : ℕ) (S Z : ℝ) (H : ℕ) where + start : ℤ + step : ℤ + positive : 0canonicalLog c (P y) i) D + lo : Fin (H+1)→Fin v→ℝ + hi : Fin (H+1)→Fin v→ℝ + res : Fin (H+1)→Fin v→ℤ + test : Fin (H+1)→(G⧸Γ)→ℂ + side : ∀ j i,c₀*Z≤hi j i-lo j i + box : ∀ j i,-C₀*Z≤lo j i ∧ hi j i≤C₀*Z + lip : ∀ j,LipschitzWith B (test j) + bound : ∀ j y,‖test j y‖≤B + bad : ∀ j,η≤‖mean (boxIndices (lo j) (hi j) (fun _=>0) 1) + (fun x=>test j (QuotientGroup.mk (P (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ))))))- + mean (physicalResidueBox (lo j) (hi j) (res j) (start+step*(j.val:ℤ)).natAbs) + (fun x=>test j (QuotientGroup.mk (P (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ))))))‖ + +namespace Block +variable {c Γ} {v D : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η : ℝ} {w : ℕ} {S Z : ℝ} {N H : ℕ} +variable (b₀ : Block c Γ v D c₀ C₀ B η w S Z N) + + + +def affine (a b : ℕ) (hb : 0 push_cast <;> ring_nf + rough:=by + intro z hz hzH + have hza : 0≤(a:ℤ)+(b:ℤ)*z:=by positivity + have hzb : (a:ℤ)+(b:ℤ)*z≤N:=by + have hh : (a:ℤ)+(b:ℤ)*(H:ℤ)≤N:=by exact_mod_cast hab + nlinarith + convert b₀.rough _ hza hzb using 1; ring + P:=fun y=>b₀.P (Fin.cons ((a:ℝ)+(b:ℝ)*y 0) (Fin.tail y)) + degree:=fun i=>RoughPolynomialDegree.time_affine (b₀.degree i) _ _ + lo:=fun j=>b₀.lo (progressionIndex a b hab j) + hi:=fun j=>b₀.hi (progressionIndex a b hab j) + res:=fun j=>b₀.res (progressionIndex a b hab j) + test:=fun j=>b₀.test (progressionIndex a b hab j) + side:=fun j=>b₀.side _ + box:=fun j=>b₀.box _ + lip:=fun j=>b₀.lip _ + bound:=fun j=>b₀.bound _ + bad:=by + intro j + have he : b₀.start+b₀.step*(a:ℤ)+b₀.step*(b:ℤ)*(j.val:ℤ)= + b₀.start+b₀.step*((progressionIndex a b hab j).val:ℤ):=by + simp only [progressionIndex_val,Nat.cast_add,Nat.cast_mul] + ring + simpa only [Fin.cons_zero,Fin.tail_cons,he,progressionIndex_val,Nat.cast_add,Nat.cast_mul] + using b₀.bad (progressionIndex a b hab j) + +def restrict (hHN : H≤N) : Block c Γ v D c₀ C₀ B η w S Z H := + b₀.affine 0 1 (by norm_num) (by simpa using hHN) (by simpa using b₀.smooth) + +end Block + +end RoughBadBlock + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughBlockRationalization +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales +open RoughBadBlock RoughRealRationalization RoughRationalBlock +open PolynomialLineCoefficients CorrectedBoxLeibman Filter MeasureTheory AbelianMalcevTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {r : ℕ} +variable (c : RealCoordinates G r) (hsk : SecondKind c) (Γ : Subgroup G) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable [mtr : MetricSpace (G⧸Γ)] +variable (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) +local instance : TopologicalSpace (G⧸Γ):=mtr.toUniformSpace.toTopologicalSpace + +include hsk hΓ htop in + + +theorem rationalized_block (v D : ℕ) (c₀ C₀ : ℝ) (B₀ : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^k) atTop atTop) : + ∃ s : ℕ,∃ U : Finset (G→*Multiplicative ℝ),∃ A : ℝ,1≤A ∧ + ∀ H : ℕ,2*((v+1)*s+1)≤H →∃ N : ℕ,∀ᶠ n in atTop, + ∀ _ : Block c Γ v D c₀ C₀ B₀ η (w n) (S n) (Z n) N, + ∃ b : Block c Γ v D c₀ C₀ B₀ η (w n) (S n) (Z n) H, + ∃ ξ∈U,ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ,∃ z : ℤ,(ξ g).toAdd=z) ∧ + ∃ θ : PolynomialLineCoefficients.Grid v s→Polynomial ℝ, (∀ I,(θ I).natDegree ≤ s) ∧ + (∀ z : ℝ,∀ x : Fin v→ℝ,gridEval (fun I=>(θ I).eval z) x=(ξ (b.P (Fin.cons z x))).toAdd) ∧ + ∃ M : PolynomialLineCoefficients.Grid v s→Polynomial ℚ,Split (w n) H (Z n) A θ 0 1 M := by + classical + let : MeasurableSpace (G⧸Γ):=borel (G⧸Γ) + let : @BorelSpace (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) inferInstance:=by + rw [←htop] + exact ⟨rfl⟩ + let : BorelSpace (G⧸Γ):=by + change @BorelSpace (G⧸Γ) mtr.toUniformSpace.toTopologicalSpace inferInstance + exact ⟨rfl⟩ + let : CompactSpace (G⧸Γ):=metric_compact c Γ hΓ mtr htop + let : Group.IsNilpotent G:=nilpotent_of_coordinates c + let : ContinuousConstSMul G (G⧸Γ):=by + change @ContinuousConstSMul G (G⧸Γ) mtr.toUniformSpace.toTopologicalSpace inferInstance + rw [htop] + infer_instance + obtain ⟨μ,hinv⟩:=SolvableInvariantMeasure.exists_invariant_measure (G:=G) (X:=G⧸Γ) + let :=hinv + obtain ⟨s,U,A,hA,hprod⟩:=real_rational_split c hsk Γ hΓ htop (μ:Measure (G⧸Γ)) + v D c₀ C₀ B₀ η hc₀ hC₀ hB₀ hη hw hS hZ + refine ⟨s,U,A,hA,?_⟩ + intro H hH + obtain ⟨N,hN⟩:=hprod H hH + refine ⟨N,?_⟩ + filter_upwards [hN] with n hn + intro b₀ + let F : Fin (N+1)→C(G⧸Γ,ℂ):=fun j=>⟨b₀.test j,(b₀.lip j).continuous⟩ + have hF (j) : LipschitzWith B₀ (F j) ∧ ‖F j‖≤B₀:= + ⟨b₀.lip j,(ContinuousMap.norm_le (F j) B₀.coe_nonneg).mpr (b₀.bound j)⟩ + obtain ⟨a,b,hb,hab,hsm,ξ,hξ,hne,hcont,hint,θ,hθ,he,M,hM⟩:= + hn b₀.start b₀.step b₀.positive b₀.smooth b₀.scales b₀.rough b₀.P b₀.degree + b₀.lo b₀.hi b₀.res F b₀.side b₀.box hF b₀.bad + let b' :=b₀.affine a b hb hab hsm + refine ⟨b',ξ,hξ,hne,hcont,hint,θ,hθ,?_,M,hM⟩ + intro z x + simpa only [b',Block.affine,Fin.cons_zero,Fin.tail_cons] using he z x + +end RoughBlockRationalization + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughPhysicalSelection +open RoughSamplingWeights RegularBoxPartition RegularResiduePieces FinitePieceAverages +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma mem_physical (lo hi : ι→ℝ) (u : ι→ℤ) (K : ℕ) (x : ι→ℤ) : + x∈physicalResidueBox lo hi u K ↔ + (∀ i,lo i≤(x i:ℝ) ∧ (x i:ℝ)(a i:ℝ)) q).image (integerAffine a q):=by + rw [rescaled_box lo hi a q hq] + exact physical_residue_reparametrization lo hi a q hq + +lemma physical_mean (lo hi : ι→ℝ) (a : ι→ℤ) (q : ℕ) (hq : 0(a i:ℝ)) q) (fun x=>f (integerAffine a q x)):=by + rw [physical_image lo hi a q hq] + exact mean_image _ _ (affine_injective a q hq) f + +omit [Fintype ι] [DecidableEq ι] in +lemma affine_mod (a : ι→ℤ) (q : ℕ) (x : ι→ℤ) : ∀ i,integerAffine a q x i≡a i [ZMOD q]:=by + intro i + apply Int.modEq_iff_dvd.mpr + exact ⟨-x i,by dsimp [integerAffine]; ring⟩ + +omit [Fintype ι] [DecidableEq ι] in +lemma affine_zero_one (x : ι→ℤ) : integerAffine (fun _=>0) 1 x=x:=by + ext i + simp [integerAffine] + + + +lemma physical_fiber_image (lo hi : ι→ℝ) (hL : ∀ i,lo i(a i:ℝ)) q) (label lo hi hL M hM a q K) (b,u)).image + (integerAffine a q)= + (physicalResidueBox (fun i=>left (lo i) (hi i) M (b i)) + (fun i=>right (lo i) (hi i) M (b i)) (fun i=>((u i).val:ℤ)) K).filter + (fun x=>∀ i,x i≡a i [ZMOD q]) := by + classical + ext x + rw [Finset.mem_filter,mem_physical] + constructor + · intro hx + obtain ⟨y,hy,rfl⟩:=Finset.mem_image.mp hx + obtain ⟨hy,he⟩:=Finset.mem_filter.mp hy + obtain ⟨hb,hu⟩:=(label_correct lo hi hL M hM a q K hq y hy b u).mp he + refine ⟨⟨?_,?_⟩,affine_mod a q y⟩ + · intro i + simpa only [integerAffine,Int.cast_add,Int.cast_mul,Int.cast_natCast] using hb i + · intro i + apply (ZMod.intCast_eq_intCast_iff _ _ _).mp + simpa only [Int.cast_natCast,ZMod.natCast_zmod_val,integerAffine] using hu i + · rintro ⟨⟨hb,hu⟩,hxq⟩ + have hx : x∈physicalResidueBox lo hi a q:=by + rw [mem_physical] + refine ⟨fun i=>?_,hxq⟩ + have he:=endpoints (lo i) (hi i) (hL i) M hM (b i) + exact ⟨he.1.trans (hb i).1,(hb i).2.trans_le he.2.2.1⟩ + rw [physical_image lo hi a q hq] at hx + obtain ⟨y,hy,rfl⟩:=Finset.mem_image.mp hx + apply Finset.mem_image.mpr + refine ⟨y,Finset.mem_filter.mpr ⟨hy,?_⟩,rfl⟩ + apply (label_correct lo hi hL M hM a q K hq y hy b u).mpr + constructor + · intro i + simpa only [integerAffine,Int.cast_add,Int.cast_mul,Int.cast_natCast] using hb i + · intro i + have h:=(ZMod.intCast_eq_intCast_iff _ _ _).mpr (hu i) + simpa only [integerAffine,Int.cast_natCast,ZMod.natCast_zmod_val] using h + +lemma physical_fiber_mean (lo hi : ι→ℝ) (hL : ∀ i,lo i(a i:ℝ)) q) (label lo hi hL M hM a q K) (b,u)) + (fun x=>f (integerAffine a q x))= + mean ((physicalResidueBox (fun i=>left (lo i) (hi i) M (b i)) + (fun i=>right (lo i) (hi i) M (b i)) (fun i=>((u i).val:ℤ)) K).filter + (fun x=>∀ i,x i≡a i [ZMOD q])) f := by + rw [←physical_fiber_image lo hi hL M hM a q K hq b u] + exact (mean_image _ _ (affine_injective a q hq) f).symm + +lemma mean_congr {α : Type*} (S : Finset α) (f g : α→ℂ) (h : ∀ x∈S,f x=g x) : + mean S f=mean S g:=by + simp only [mean] + rw [Finset.sum_congr rfl h] + +section Freezing +open RationalLattice MalcevCharacters RoughKernelFactorization UniformSlowPolynomials +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G→*Multiplicative ℝ) (Γ : Subgroup G) (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable {X : Type*} [PseudoMetricSpace X] (V : (G⧸Γ) ≃ₜ X) +variable {κ : Type*} [Fintype κ] + +include hΓ in + + +theorem physical_frozen_selection (e : κ→ι→ℕ) (A C side B : ℝ) + (hA : 0≤A) (hC : 0≤C) (hside : 00) 1) + (fun x=>F (V ((R.flow c hsk χ Γ (Multiplicative.ofAdd + (form e coeff (fun i=>(x i:ℝ))))) • tail x)))- + mean (physicalResidueBox lo hi res t) + (fun x=>F (V ((R.flow c hsk χ Γ (Multiplicative.ofAdd + (form e coeff (fun i=>(x i:ℝ))))) • tail x)))‖ → + ∃ b : ι→Fin M,∃ u : ι→ZMod R.period, + |form e coeff (fun i=>left (lo i) (hi i) M (b i))|≤T ∧ + η-3*ε≤‖mean (physicalResidueBox + (fun i=>left (lo i) (hi i) M (b i)) (fun i=>right (lo i) (hi i) M (b i)) + (fun i=>((u i).val:ℤ)) R.period) + (fun x=>F (V ((R.flow c hsk χ Γ (Multiplicative.ofAdd + (form e coeff (fun i=>left (lo i) (hi i) M (b i))))) • tail x)))- + mean ((physicalResidueBox + (fun i=>left (lo i) (hi i) M (b i)) (fun i=>right (lo i) (hi i) M (b i)) + (fun i=>((u i).val:ℤ)) R.period).filter (fun x=>∀ i,x i≡res i [ZMOD t])) + (fun x=>F (V ((R.flow c hsk χ Γ (Multiplicative.ofAdd + (form e coeff (fun i=>left (lo i) (hi i) M (b i))))) • tail x)))‖ := by + classical + let : NeZero R.period:=⟨R.period_pos.ne'⟩ + obtain ⟨M,hM,δ,hδ,hselect⟩:=regular_sample_select_frozen c hsk χ Γ R hΓ V e A C side B + hA hC hside hB L R.period R.period_pos ε hε + obtain ⟨T,δ₀,hT,hδ₀,hbound⟩:=scaled_uniformity e A C hA hC 1 (by norm_num) + refine ⟨M,hM,T,δ,hT,hδ,?_⟩ + intro Z hZ coeff hcoeff lo hi hL hbox hside' res t ht htK hsmall F hF hFB tail η hbad + let f : (ι→ℤ)→ℂ:=fun x=>F (V ((R.flow c hsk χ Γ + (Multiplicative.ofAdd (form e coeff (fun i=>(x i:ℝ))))) • tail x)) + have hbad' : η≤‖mean (boxIndices lo hi (fun i=>((0:ℤ):ℝ)) 1) + (sampledTest c hsk χ Γ R V e coeff (fun _=>0) 1 F (fun x=>tail (integerAffine (fun _=>0) 1 x)))- + mean (boxIndices lo hi (fun i=>(res i:ℝ)) t) + (sampledTest c hsk χ Γ R V e coeff res t F (fun x=>tail (integerAffine res t x)))‖:=by + rw [physical_mean lo hi res t ht] at hbad + unfold sampledTest + simpa [affine_zero_one,integerAffine] using hbad + obtain ⟨z,hz,hdisc⟩:=hselect Z hZ coeff coeff hcoeff hcoeff lo hi hL hbox hside' + (fun _=>0) res 1 t (by norm_num) ht (Nat.coprime_one_left _) htK (by simpa using hsmall) + F F hF hF hFB (fun x=>tail (integerAffine (fun _=>0) 1 x)) + (fun x=>tail (integerAffine res t x)) η (by simpa only [Nat.cast_one] using hbad') + let b:=z.1 + let u:=z.2 + let frozen : (ι→ℤ)→ℂ:=fun x=>F (V ((R.flow c hsk χ Γ + (Multiplicative.ofAdd (form e coeff (fun i=>left (lo i) (hi i) M (b i))))) • tail x)) + have hmean (a : ι→ℤ) (q : ℕ) (hq : 0(a i:ℝ)) q) (label lo hi hL M hM a q R.period) z) + (frozenSampledTest c hsk χ Γ R V e coeff lo hi hL M hM a q F + (fun x=>tail (integerAffine a q x))) = + mean ((physicalResidueBox (fun i=>left (lo i) (hi i) M (b i)) + (fun i=>right (lo i) (hi i) M (b i)) (fun i=>((u i).val:ℤ)) R.period).filter + (fun x=>∀ i,x i≡a i [ZMOD q])) frozen := by + calc + _=mean (fiber (boxIndices lo hi (fun i=>(a i:ℝ)) q) (label lo hi hL M hM a q R.period) z) + (fun x=>frozen (integerAffine a q x)):=by + apply mean_congr + intro x hx + have he:=(Finset.mem_filter.mp hx).2 + have hc : cell lo hi hL M hM (fun i=>(a i:ℝ)+q*x i)=b:=congrArg Prod.fst he + simp only [frozenSampledTest,hc,frozen] + _=_:=physical_fiber_mean lo hi hL M hM a q R.period hq b u frozen + rw [hmean (fun _=>0) 1 (by norm_num),hmean res t ht] at hdisc + refine ⟨b,u,?_,?_⟩ + · have hc (i : ι) : |left (lo i) (hi i) M (b i)|≤C*Z:=by + have he:=endpoints (lo i) (hi i) (hL i) M hM (b i) + exact abs_le.mpr ⟨(hbox i).1.trans he.1,he.2.1.le.trans (he.2.2.1.trans (hbox i).2)⟩ + exact (hbound Z hZ coeff hcoeff _ _ hc hc).1 + · simpa only [Nat.cast_one,Int.modEq_one,implies_true,Finset.filter_true,frozen] using hdisc + +end Freezing +end RoughPhysicalSelection + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct01.lean new file mode 100644 index 0000000000000000000000000000000000000000..5b9433afe0fcd1ee7d8bc0c3b58d9e053cf1b733 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct01.lean @@ -0,0 +1,285 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughLiteral01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end + +end + + +section + +noncomputable section +namespace RoughProductRemoval +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional +open scoped BigOperators + + + +def nestedBox {v : ℕ} (lo hi : Fin v → ℝ) (res A : Fin v → ℤ) + (d M : ℕ) (q : ℤ) : Finset (Fin v → ℤ) := by + classical + exact (physicalResidueBox lo hi res d).filter (fun x => ∀ i, q ∣ (M:ℤ)*x i+A i) + +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] + +def badProduct (m v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z : ℝ) + (d M : ℕ) (A : Fin v → ℤ) (P : (Fin (m+v) → ℝ) → G) (t : Fin m → ℤ) : Prop := + ∃ (lo hi : Fin v → ℝ) (res : Fin v → ℤ) (test : (G⧸Γ) → ℂ), + (∀ i,c₀*Z≤hi i-lo i) ∧ (∀ i,-C₀*Z≤lo i ∧ hi i≤C₀*Z) ∧ + LipschitzWith B test ∧ (∀ y,‖test y‖≤B) ∧ + η≤‖mean (physicalResidueBox lo hi res d) + (fun x=>test (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))- + mean (nestedBox lo hi res A d M (∏ j,t j)) + (fun x=>test (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))‖ + +def productTimes {m : ℕ} (S : Fin m → ℝ) (r : Fin m → ℤ) (L : ℤ) : Finset (Fin m → ℤ) := + Fintype.piFinset (fun j => times (S j) (r j) L) + +def exceptionalProduct (m v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z : ℝ) + (d M : ℕ) (A : Fin v → ℤ) (P : (Fin (m+v) → ℝ) → G) + (S : Fin m → ℝ) (r : Fin m → ℤ) (L : ℤ) : Finset (Fin m → ℤ) := by + classical + exact (productTimes S r L).filter (badProduct Γ m v c₀ C₀ B η Z d M A P) + +end RoughProductRemoval +end +end + + +section + + + +noncomputable section +namespace RoughProductRemoval +open RoughSamplingWeights FinitePieceAverages +open scoped BigOperators + +lemma linear_divisibility_class (M q : ℕ) (hc : M.Coprime q) (A : ℤ) : + ∃ b : ℤ,∀ x : ℤ,(q:ℤ)∣(M:ℤ)*x+A ↔ x ≡ b [ZMOD q] := by + obtain ⟨b,hb⟩ := residue_parameter M q hc A 0 + refine ⟨b,fun x=>?_⟩ + have he : (q:ℤ)∣(M:ℤ)*x+A ↔ A+(M:ℤ)*x ≡ 0 [ZMOD q] := by + rw [Int.modEq_zero_iff_dvd] + simp only [add_comm] + exact he.trans (hb x) + +lemma parent_residue (d M q : ℕ) (hd : 0?_⟩ + rw [hb] + have he : (x ≡ a [ZMOD d] ∧ x ≡ b [ZMOD q]) ↔ + (x ≡ u₀ [ZMOD d] ∧ x ≡ u₀ [ZMOD q]) := by + constructor + · rintro ⟨ha,hb⟩ + exact ⟨ha.trans hu₀d.symm,hb.trans hu₀q.symm⟩ + · rintro ⟨ha,hb⟩ + exact ⟨ha.trans hu₀d,hb.trans hu₀q⟩ + rw [he,Int.modEq_and_modEq_iff_modEq_mul (by simpa using hdq)] + exact ⟨fun h=>h.trans hue.symm,fun h=>h.trans hue⟩ + +lemma parent_vector {v : ℕ} (d M q : ℕ) (hd : 0parent_residue d M q hd hq hdq hMq (a i) (A i) + refine ⟨u,fun i=>⟨hu0 i,hult i⟩,fun x=>?_⟩ + rw [← forall_and] + exact forall_congr' (fun i=>hu i (x i)) + +lemma nestedBox_eq_parent {v : ℕ} (d M q : ℕ) (hd : 0.refl _)).2,?_⟩ + intro lo hi + ext x + simp only [nestedBox,physicalResidueBox,Finset.mem_filter] + rw [and_assoc,he x] + norm_cast + + + +lemma nested_linear_parameter (d M q t : ℕ) (hq : 0?_⟩ + have hq0 : (q:ℤ)≠0 := by positivity + have he : (M:ℤ)*(u+((d*q:ℕ):ℤ)*y)+A=(q:ℤ)*(((M*d:ℕ):ℤ)*y+a) := by + push_cast + nlinarith [ha] + rw [he,Nat.cast_mul,mul_dvd_mul_iff_left hq0,hb] + +lemma nested_removed_class {v : ℕ} (d M q t : ℕ) (hq : 0nested_linear_parameter d M q t hq hc (u i) (A i) (hu i) + exact ⟨b,fun y=>forall_congr' (fun i=>hb i (y i))⟩ + +lemma nestedBox_refine {v : ℕ} (lo hi : Fin v → ℝ) (a A : Fin v → ℤ) + (d M q t : ℕ) : + nestedBox lo hi a A d M (q*t) = + (nestedBox lo hi a A d M q).filter (fun x=>∀ i,((q*t:ℕ):ℤ)∣(M:ℤ)*x i+A i) := by + classical + ext x + simp only [nestedBox,Finset.mem_filter] + constructor + · rintro ⟨hmem,hdiv⟩ + refine ⟨⟨hmem,fun i=>?_⟩,hdiv⟩ + exact (by exact ⟨(t:ℤ),by push_cast; rfl⟩ : (q:ℤ)∣((q*t:ℕ):ℤ)).trans (hdiv i) + · exact fun h=>⟨h.1.1,h.2⟩ + + + +theorem nested_residue_means {v : ℕ} (d M q : ℕ) (hd : 00) 1) (fun y=>f (integerAffine u (d*q) y)) ∧ + mean (nestedBox lo hi a A d M (q*t)) f = + mean (physicalResidueBox (rescaledEndpoint lo u (d*q)) + (rescaledEndpoint hi u (d*q)) b t) (fun y=>f (integerAffine u (d*q) y)) := by + classical + obtain ⟨u,hu,hud,he⟩ := nestedBox_eq_parent d M q hd hq hdq hMq a A + refine ⟨u,hu,?_⟩ + intro t hc + obtain ⟨b,hb⟩ := nested_removed_class d M q t hq hc u A hud + have hK : 0⟨?_,?_⟩⟩ + · rw [he] + exact residue_mean lo hi u (d*q) hK f + · rw [nestedBox_refine,he,physical_residue_reparametrization lo hi u (d*q) hK, + Finset.filter_image] + have hp : (fun y : Fin v → ℤ=>∀ i,((q*t:ℕ):ℤ)∣(M:ℤ)*integerAffine u (d*q) y i+A i)= + (fun y : Fin v → ℤ=>∀ i,y i ≡ b i [ZMOD t]) := + funext (fun y=>propext (hb y)) + simp only [hp] + convert mean_image (physicalResidueBox (rescaledEndpoint lo u (d*q)) + (rescaledEndpoint hi u (d*q)) b t) (integerAffine u (d*q)) + (affine_injective u (d*q) hK) f using 1 + congr 2 + ext y + simp only [physicalResidueBox,Finset.mem_filter] + +end RoughProductRemoval +end +end + + +section + + + +noncomputable section +namespace RoughProductRemoval +open RationalLattice MalcevCharacters RealPolynomialDegree RoughPolynomialDegree +open RoughSamplingWeights + + + +def firstLift {m v : ℕ} (t : Fin m → ℝ) (u : Fin v → ℤ) (K : ℕ) + (y : Fin (v+1) → ℝ) : Fin ((m+1)+v) → ℝ := + Fin.append (Fin.cons (y 0) t) (fun i=>(u i:ℝ)+(K:ℝ)*y i.succ) + +lemma firstLift_degree {m v : ℕ} (t : Fin m → ℝ) (u : Fin v → ℤ) (K : ℕ) + (i : Fin ((m+1)+v)) : HasDegree (fun y=>firstLift t u K y i) 1 := by + refine Fin.addCases ?_ ?_ i + · intro j + refine Fin.cases ?_ (fun k=>?_) j + · simpa only [firstLift,Fin.append_left,Fin.cons_zero] using + (coordinate (0:Fin (v+1))) + · simpa only [firstLift,Fin.append_left,Fin.cons_succ] using + (RealPolynomialDegree.const (σ:=Fin (v+1)) (t k) 1) + · intro j + simpa only [firstLift,Fin.append_right,max_self] using + (RealPolynomialDegree.add (RealPolynomialDegree.const (σ:=Fin (v+1)) (u j:ℝ) 1) + (RealPolynomialDegree.scale (coordinate j.succ) (K:ℝ))) + +lemma firstLift_eval {m v : ℕ} (t : Fin m → ℤ) (u : Fin v → ℤ) (K : ℕ) + (s : ℤ) (x : Fin v → ℤ) : + firstLift (fun j=>(t j:ℝ)) u K (Fin.cons (s:ℝ) (fun i=>(x i:ℝ))) = + Fin.append (fun j=>(((Fin.cons s t : Fin (m+1) → ℤ) j):ℝ)) + (fun i=>(integerAffine u K x i:ℝ)) := by + funext i + refine Fin.addCases ?_ ?_ i + · intro j + refine Fin.cases ?_ (fun k=>?_) j <;> + simp only [firstLift,Fin.append_left,Fin.cons_zero,Fin.cons_succ] + · intro j + simp only [firstLift,Fin.append_right,Fin.cons_succ,integerAffine,Int.cast_add, + Int.cast_mul,Int.cast_natCast] + + +def tailLift {m v : ℕ} (a : ℝ) (y : Fin (m+v) → ℝ) : Fin ((m+1)+v) → ℝ := + Fin.append (Fin.cons a (fun j=>y (j.castAdd v))) (fun i=>y (i.natAdd m)) + +lemma tailLift_degree {m v : ℕ} (a : ℝ) (i : Fin ((m+1)+v)) : + HasDegree (fun y=>tailLift a y i) 1 := by + refine Fin.addCases ?_ ?_ i + · intro j + refine Fin.cases ?_ (fun k=>?_) j + · simpa only [tailLift,Fin.append_left,Fin.cons_zero] using + (RealPolynomialDegree.const (σ:=Fin (m+v)) a 1) + · simpa only [tailLift,Fin.append_left,Fin.cons_succ] using coordinate (k.castAdd v) + · intro j + simpa only [tailLift,Fin.append_right] using coordinate (j.natAdd m) + +lemma tailLift_eval {m v : ℕ} (a : ℝ) (t : Fin m → ℝ) (x : Fin v → ℝ) : + tailLift a (Fin.append t x)=Fin.append (Fin.cons a t) x := by + simp only [tailLift,Fin.append_left,Fin.append_right] + +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (c : RealCoordinates G dim) + +lemma first_polynomial {m v D : ℕ} (P : (Fin ((m+1)+v) → ℝ) → G) + (hP : ∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) + (t : Fin m → ℝ) (u : Fin v → ℤ) (K : ℕ) : + ∀ i,HasDegree (fun y=>canonicalLog c (P (firstLift t u K y)) i) D := by + intro i + simpa only [one_mul] using compose (hP i) (fun j y=>firstLift t u K y j) + (firstLift_degree t u K) + +lemma tail_polynomial {m v D : ℕ} (P : (Fin ((m+1)+v) → ℝ) → G) + (hP : ∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) (a : ℝ) : + ∀ i,HasDegree (fun y=>canonicalLog c (P (tailLift a y)) i) D := by + intro i + simpa only [one_mul] using compose (hP i) (fun j y=>tailLift a y j) + (tailLift_degree a) + +end RoughProductRemoval + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct02.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e9364d27d560af1018810f396e470cbe55b6e3f --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct02.lean @@ -0,0 +1,271 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughProduct01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end +end + + +section + + + +noncomputable section +namespace RoughProductRemoval +open RoughScales RoughSourceExceptional Filter +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +def consPair {m : ℕ} (p : ℤ × (Fin m → ℤ)) : Fin (m+1) → ℤ := Fin.cons p.1 p.2 + +lemma consPair_injective (m : ℕ) : + Function.Injective (consPair (m:=m)) := by + intro p q h + apply Prod.ext + · have h0:=congrFun h 0 + simpa only [consPair,Fin.cons_zero] using h0 + · funext i + have hi:=congrFun h i.succ + simpa only [consPair,Fin.cons_succ] using hi + +lemma productTimes_succ {m : ℕ} (S : Fin (m+1) → ℝ) (r : Fin (m+1) → ℤ) (L : ℤ) : + productTimes S r L = + ((times (S 0) (r 0) L).product (productTimes (Fin.tail S) (Fin.tail r) L)).image + consPair := by + classical + ext t + simp only [productTimes,Fintype.mem_piFinset,Finset.mem_image,Finset.product_eq_sprod,Finset.mem_product] + constructor + · intro ht + refine ⟨⟨t 0,Fin.tail t⟩,⟨ht 0,fun j=>ht j.succ⟩,?_⟩ + exact Fin.cons_self_tail t + · rintro ⟨⟨a,b⟩,⟨ha,hb⟩,rfl⟩ + exact Fin.forall_fin_succ.mpr ⟨ha,hb⟩ + +lemma card_productTimes_succ {m : ℕ} (S : Fin (m+1) → ℝ) (r : Fin (m+1) → ℤ) (L : ℤ) : + (productTimes S r L).card = + (times (S 0) (r 0) L).card*(productTimes (Fin.tail S) (Fin.tail r) L).card := by + classical + rw [productTimes_succ,Finset.card_image_of_injective _ (consPair_injective m),Finset.product_eq_sprod,Finset.card_product] + +lemma filter_card_product_left {α β : Type*} [DecidableEq α] [DecidableEq β] + (S : Finset α) (T : Finset β) (E : α → β → Prop) : + (((S.product T).filter (fun p=>E p.1 p.2)).card) = ∑ a∈S,(T.filter (E a)).card := by + simp only [Finset.card_eq_sum_ones,Finset.sum_filter,Finset.product_eq_sprod,Finset.sum_product] + +lemma filter_card_product_right {α β : Type*} [DecidableEq α] [DecidableEq β] + (S : Finset α) (T : Finset β) (E : α → β → Prop) : + letI := Classical.propDecidable + (((S.product T).filter (fun p=>E p.1 p.2)).card) = ∑ b∈T,(S.filter (fun a=>E a b)).card := by + classical + simp only [Finset.card_eq_sum_ones,Finset.sum_filter,Finset.product_eq_sprod,Finset.sum_product] + exact Finset.sum_comm + + +theorem product_exception_bound {α β : Type*} [DecidableEq α] [DecidableEq β] + (S : Finset α) (T : Finset β) (E F H : α → β → Prop) + (a b : ℝ) + (hE : ∀ x∈S,(((T.filter (E x)).card:ℕ):ℝ)≤a*T.card) + (hF : ∀ y∈T,(((S.filter (fun x=>F x y)).card:ℕ):ℝ)≤b*S.card) + (hH : ∀ x∈S,∀ y∈T,H x y → E x y ∨ F x y) : + letI := Classical.propDecidable + ((((S.product T).filter (fun p=>H p.1 p.2)).card:ℕ):ℝ) ≤ + (a+b)*S.card*T.card := by + classical + have hc : ((S.product T).filter (fun p=>H p.1 p.2)).card ≤ + ((S.product T).filter (fun p=>E p.1 p.2)).card+ + ((S.product T).filter (fun p=>F p.1 p.2)).card := by + apply le_trans (Finset.card_le_card (show (S.product T).filter (fun p=>H p.1 p.2)⊆ + ((S.product T).filter (fun p=>E p.1 p.2))∪((S.product T).filter (fun p=>F p.1 p.2)) from ?_)) + (Finset.card_union_le _ _) + intro p hp + obtain ⟨hm,hh⟩:=Finset.mem_filter.mp hp + obtain ⟨hx,hy⟩:=Finset.mem_product.mp hm + rcases hH p.1 hx p.2 hy hh with he|hf + · exact Finset.mem_union_left _ (Finset.mem_filter.mpr ⟨hm,he⟩) + · exact Finset.mem_union_right _ (Finset.mem_filter.mpr ⟨hm,hf⟩) + have he : (((S.product T).filter (fun p=>E p.1 p.2)).card:ℝ) ≤ S.card*(a*T.card) := by + rw [filter_card_product_left S T E,Nat.cast_sum] + simpa using Finset.sum_le_sum hE + have hf : (((S.product T).filter (fun p=>F p.1 p.2)).card:ℝ) ≤ T.card*(b*S.card) := by + rw [filter_card_product_right S T F,Nat.cast_sum] + simpa using Finset.sum_le_sum hF + have hc' : (((S.product T).filter (fun p=>H p.1 p.2)).card:ℝ) ≤ + (((S.product T).filter (fun p=>E p.1 p.2)).card:ℝ)+ + (((S.product T).filter (fun p=>F p.1 p.2)).card:ℝ) := by exact_mod_cast hc + nlinarith + +lemma time_positive_rough {S : ℝ} {r L : ℤ} {w : ℕ} (hS : 0S n j) atTop atTop) + (hSL : ∀ j,Tendsto (fun n=>S n j/(L n:ℝ)) atTop atTop) : + ∀ᶠ n in atTop,(productTimes (S n) (r n) (L n)).Nonempty := by + classical + have hh : ∀ j,∀ᶠ n in atTop,0<(times (S n j) (r n j) (L n)).card := by + intro j + have hlen:=timeLength_tendsto (r:=fun n=>r n j) hL (hS j) (hSL j) + filter_upwards [hlen.eventually (eventually_gt_atTop 0)] with n hn + rw [times_card _ _ _ (hL n)] + exact_mod_cast hn + filter_upwards [eventually_all.mpr hh] with n hn + simp only [productTimes,Fintype.piFinset_nonempty,Finset.card_pos] at * + exact hn + +end RoughProductRemoval +end +end + + +section + + + +noncomputable section +namespace RoughProductRemoval +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional +open scoped BigOperators + +lemma residue_normalize {v : ℕ} (d : ℕ) (hd : 0⟨fun hx=>hx.trans (h i),fun hx=>hx.trans (h i).symm⟩) + +lemma nestedBox_congr {v : ℕ} (lo hi : Fin v → ℝ) (a b A : Fin v → ℤ) + (d M : ℕ) (q : ℤ) (h : ∀ i,a i ≡ b i [ZMOD d]) : + nestedBox lo hi a A d M q=nestedBox lo hi b A d M q := by + unfold nestedBox + rw [physicalResidueBox_congr lo hi a b d h] + +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] + +def firstBad (m v : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η Z : ℝ) + (d M : ℕ) (A : Fin v → ℤ) (P : (Fin ((m+1)+v) → ℝ) → G) + (s : ℤ) (t : Fin m → ℤ) : Prop := + ∃ (lo hi : Fin v → ℝ) (res : Fin v → ℤ) (test : (G⧸Γ) → ℂ), + (∀ i,c₀*Z≤hi i-lo i) ∧ (∀ i,-C₀*Z≤lo i ∧ hi i≤C₀*Z) ∧ + LipschitzWith B test ∧ (∀ y,‖test y‖≤B) ∧ + η≤‖mean (nestedBox lo hi res A d M (∏ j,t j)) + (fun x=>test (QuotientGroup.mk (P (Fin.append (fun j=>((consPair (s,t) j):ℝ)) (fun i=>(x i:ℝ))))))- + mean (nestedBox lo hi res A d M ((∏ j,t j)*s)) + (fun x=>test (QuotientGroup.mk (P (Fin.append (fun j=>((consPair (s,t) j):ℝ)) (fun i=>(x i:ℝ))))))‖ + +omit [TopologicalSpace G] in +lemma badProduct_succ_split {m v : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η Z : ℝ} + {d M : ℕ} {A : Fin v → ℤ} {P : (Fin ((m+1)+v) → ℝ) → G} + {s : ℤ} {t : Fin m → ℤ} + (h : badProduct Γ (m+1) v c₀ C₀ B η Z d M A P (consPair (s,t))) : + badProduct Γ m v c₀ C₀ B (η/2) Z d M A (fun y=>P (tailLift (s:ℝ) y)) t ∨ + firstBad Γ m v c₀ C₀ B (η/2) Z d M A P s t := by + obtain ⟨lo,hi,res,test,hside,hbox,hlip,hbound,hdisc⟩ := h + let f (x : Fin v → ℤ) := test (QuotientGroup.mk + (P (Fin.append (fun j=>((consPair (s,t) j):ℝ)) (fun i=>(x i:ℝ)))) ) + have hf : (fun x : Fin v → ℤ=>test (QuotientGroup.mk + (P (tailLift (s:ℝ) (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))))=f := by + funext x + simp only [tailLift_eval,f,consPair] + congr 4 + funext j + exact Fin.cases (by simp) (fun k=>by simp) j + have hp : (∏ j,consPair (s,t) j)=(∏ j,t j)*s := by + simp only [Fin.prod_univ_succ,consPair,Fin.cons_zero,Fin.cons_succ,mul_comm] + rw [hp] at hdisc + have htri := norm_sub_le_norm_sub_add_norm_sub (mean (physicalResidueBox lo hi res d) f) + (mean (nestedBox lo hi res A d M (∏ j,t j)) f) + (mean (nestedBox lo hi res A d M ((∏ j,t j)*s)) f) + by_cases h₁ : η/2≤‖mean (physicalResidueBox lo hi res d) f- + mean (nestedBox lo hi res A d M (∏ j,t j)) f‖ + · left + refine ⟨lo,hi,res,test,hside,hbox,hlip,hbound,?_⟩ + simpa only [hf] using h₁ + · right + exact ⟨lo,hi,res,test,hside,hbox,hlip,hbound,by dsimp [f] at *; linarith⟩ + +variable (c : RealCoordinates G dim) + + +theorem firstBad_reduction {m v D : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η Z : ℝ} + (d M : ℕ) (hd : 0canonicalLog c (P y) i) D) + (t : Fin m → ℤ) (ht : ∀ j,0canonicalLog c (Q R y) i) D) ∧ + ∀ s : ℤ,0Int.natAbs_pos.mpr (ht j).ne') + have hqe : (q:ℤ)=∏ j,t j := by + dsimp [q] + rw [Nat.cast_prod] + congr 1 + funext j + exact (Int.natCast_natAbs _).trans (abs_of_pos (ht j)) + have hh (R : Fin v → Fin d) := nested_residue_means d M q hd hq hdq hMq + (fun i=>(R i).val) A + choose u hu hem using hh + refine ⟨fun R y=>P (firstLift (fun j=>(t j:ℝ)) (u R) (d*q) y), + fun R=>first_polynomial c P hP _ _ _,?_⟩ + intro s hs hMs hbad + obtain ⟨lo,hi,res,test,hside,hbox,hlip,hbound,hdisc⟩ := hbad + obtain ⟨R,hR⟩ := residue_normalize d hd res + obtain ⟨b,hb⟩ := hem R s.natAbs hMs + have htcast : (s.natAbs:ℤ)=s := (Int.natCast_natAbs _).trans (abs_of_pos hs) + have heq : ((q*s.natAbs:ℕ):ℤ)=(∏ j,t j)*s := by rw [Nat.cast_mul,hqe,htcast] + let f (x : Fin v → ℤ) := test (QuotientGroup.mk + (P (Fin.append (fun j=>((consPair (s,t) j):ℝ)) (fun i=>(x i:ℝ)))) ) + have hh := hb lo hi f + rw [hqe] at hh + rw [htcast] at hh + rw [nestedBox_congr lo hi res (fun i=>(R i).val) A d M (∏ j,t j) hR, + nestedBox_congr lo hi res (fun i=>(R i).val) A d M ((∏ j,t j)*s) hR] at hdisc + change η≤‖mean _ f-mean _ f‖ at hdisc + rw [hh.1,hh.2] at hdisc + have hgeom := rescaled_geometry lo hi (u R) (d*q) (Nat.mul_pos hd hq) + Z C₀ c₀ hZ hC (fun i=>⟨(hu R i).1,(hu R i).2.le⟩) (by simpa only [neg_mul] using hbox) hside + refine ⟨R,rescaledEndpoint lo (u R) (d*q),rescaledEndpoint hi (u R) (d*q), + b,test,(fun i=>(hgeom i).2.2),(fun i=>⟨(hgeom i).1,(hgeom i).2.1⟩),hlip,hbound,?_⟩ + simpa only [firstLift_eval,consPair,f] using hdisc + +end RoughProductRemoval + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct03.lean new file mode 100644 index 0000000000000000000000000000000000000000..29077ddab731398e042e223adbab2cc5bb27a425 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughProduct03.lean @@ -0,0 +1,328 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughCube02 +import OAI.Combinatorics.SumProduct.Alignment.RoughProduct02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end +end + + +section + + + +noncomputable section +namespace RoughCubeUniform +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSourceExceptional + +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {dim : ℕ} +variable (c : RealCoordinates G dim) (Γ : Subgroup G) [mtr : MetricSpace (G⧸Γ)] + + + +theorem larger_scale_uniform (hsk : SecondKind c) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) + (v D : ℕ) (c₀ C₀ : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^a) atTop atTop) + (hL : ∀ n,0S n/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop,∀ Y : ℝ,Z n≤Y → + ∀ P : (Fin (v+1)→ℝ)→G,(∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ((exceptional Γ v c₀ C₀ B η Y (S n) P (r n) (L n)).card:ℝ)/ + ((times (S n) (r n) (L n)).card:ℝ)<ε := by + classical + intro ε hε + let fails (n : ℕ) (Y : ℝ) : Prop := + ∃ P : (Fin (v+1)→ℝ)→G,(∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) ∧ + ε≤((exceptional Γ v c₀ C₀ B η Y (S n) P (r n) (L n)).card:ℝ)/ + ((times (S n) (r n) (L n)).card:ℝ) + have hs (n : ℕ) : ∃ Y : ℝ,Z n≤Y ∧ ((∃ Y,Z n≤Y ∧ fails n Y) → fails n Y) := by + by_cases h : ∃ Y,Z n≤Y ∧ fails n Y + · obtain ⟨Y,hY,hf⟩ := h + exact ⟨Y,hY,fun _=>hf⟩ + · exact ⟨Z n,le_rfl,fun he=>(h he).elim⟩ + choose Y hY hsel using hs + have hYsc : ∀ a : ℝ,0Y n/S n^a) atTop atTop := by + intro a ha + apply tendsto_atTop_mono' atTop ?_ (hZ a ha) + filter_upwards [hS.eventually (eventually_ge_atTop 0)] with n hn + exact div_le_div_of_nonneg_right (hY n) (Real.rpow_nonneg hn _) + have hb := RoughCubeDensity.source_exceptional_decay c Γ hsk hΓ htop v D c₀ C₀ B η + hc₀ hC₀ hB hη w S Y r L hw hS hYsc hL hsm hWL hr hSL ε hε + filter_upwards [hb] with n hn + intro z hz P hP + by_contra! he + obtain ⟨Q,hQ,hbad⟩ := hsel n ⟨z,hz,P,hP,he⟩ + exact (not_lt_of_ge hbad) (hn Q hQ) + +end RoughCubeUniform +end +end + + +section + + + +noncomputable section +namespace RoughProductRemoval +open Filter +open scoped BigOperators + +lemma power_domination_nonneg {T Z : ℕ → ℝ} + (hT : ∀ᶠ n in atTop,0Z n/T n^a) atTop atTop) : + ∀ᶠ n in atTop,0≤Z n := by + filter_upwards [hT,(hZ 1 zero_lt_one).eventually (eventually_ge_atTop 0)] with n ht hz + simp only [Real.rpow_one] at hz + simpa only [div_mul_cancel₀ _ ht.ne'] using mul_nonneg hz ht.le + +lemma domination_smaller {S T Z : ℕ → ℝ} + (hS : ∀ᶠ n in atTop,0Z n/T n^a) atTop atTop) : + ∀ a : ℝ,0Z n/S n^a) atTop atTop := by + have hT : ∀ᶠ n in atTop,0Z n/T n^a) atTop atTop) + (d m : ℕ) (hd : 0(Z n/((d:ℝ)*(2*T n)^m))/S n^a) atTop atTop := by + have hT : ∀ᶠ n in atTop,0hS j) + refine ⟨by dsimp [totalScale]; linarith,?_⟩ + intro j + have hj:=Finset.single_le_sum (fun i _=>hS i) (Finset.mem_univ j) + dsimp [totalScale] + linarith + +lemma totalScale_pos_eventually {m : ℕ} (S : ℕ → Fin m → ℝ) + (hS : ∀ j,Tendsto (fun n=>S n j) atTop atTop) : + ∀ᶠ n in atTop,1≤totalScale (S n) := by + have h := eventually_all.mpr (fun j=>(hS j).eventually (eventually_ge_atTop 0)) + filter_upwards [h] with n hn + exact (totalScale_bounds (S n) hn).1 + +lemma tail_domination {m : ℕ} (S : ℕ → Fin (m+1) → ℝ) (Z : ℕ → ℝ) + (hS : ∀ j,Tendsto (fun n=>S n j) atTop atTop) + (hZ : ∀ a : ℝ,0Z n/(totalScale (S n))^a) atTop atTop) : + ∀ a : ℝ,0Z n/(totalScale (Fin.tail (S n)))^a) atTop atTop := by + apply domination_smaller ?_ ?_ hZ + · filter_upwards [totalScale_pos_eventually (fun n=>Fin.tail (S n)) (fun j=>hS j.succ)] with n hn + linarith + · filter_upwards [(hS 0).eventually (eventually_ge_atTop 0)] with n hn + rw [totalScale_succ] + linarith + +lemma product_tail_bound {m : ℕ} (S : Fin (m+1) → ℝ) (t : Fin m → ℤ) + (hS : ∀ j,0≤S j) (ht : ∀ j,0Int.natAbs_pos.mpr (ht j).1.ne' + constructor + · exact_mod_cast (Finset.prod_pos (fun j _=>hp j)) + · rw [Nat.cast_prod] + calc + (∏ j,((t j).natAbs:ℝ)) ≤ ∏ _j : Fin m,(2*totalScale S) := by + apply Finset.prod_le_prod₀ (fun j _=>by positivity) + intro j _ + have he : ((t j).natAbs:ℝ)=(t j:ℝ) := by + rw [← Int.cast_natCast,Int.natCast_natAbs,(abs_of_pos (ht j).1)] + rw [he] + exact (ht j).2.le.trans (mul_le_mul_of_nonneg_left ((totalScale_bounds S hS).2 j.succ) (by norm_num)) + _=(2*totalScale S)^m := by simp + +end RoughProductRemoval +end +end + + +section + + + +noncomputable section +namespace RoughProductRemoval +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +lemma filter_union_bound {α β : Type*} [DecidableEq α] [Fintype β] + (S : Finset α) (H : α → Prop) (E : β → α → Prop) (a : ℝ) + (hH : ∀ x∈S,H x →∃ b,E b x) + (hE : ∀ b,((S.filter (E b)).card:ℝ)≤a) : + ((S.filter H).card:ℝ)≤(Fintype.card β:ℝ)*a := by + classical + have hs : S.filter H ⊆ Finset.univ.biUnion (fun b=>S.filter (E b)) := by + intro x hx + obtain ⟨hx,h⟩ := Finset.mem_filter.mp hx + obtain ⟨b,hb⟩ := hH x hx h + exact Finset.mem_biUnion.mpr ⟨b,Finset.mem_univ _,Finset.mem_filter.mpr ⟨hx,hb⟩⟩ + have hc := (Finset.card_le_card hs).trans (Finset.card_biUnion_le) + have hc' : ((S.filter H).card:ℝ)≤∑ b : β,((S.filter (E b)).card:ℝ) := by + exact_mod_cast hc + exact hc'.trans (by simpa only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] using Finset.sum_le_sum (s:=Finset.univ) (fun b _=>hE b)) + +lemma smooth_nat_coprime_rough {w M : ℕ} {t : ℤ} (hM : Smooth w (M:ℤ)) + (ht : Rough w t) : M.Coprime t.natAbs := by + simpa only [Int.natAbs_natCast] using + (Int.isCoprime_iff_nat_coprime.mp (coprime_smooth_rough hM ht)) + +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {dim : ℕ} +variable (c : RealCoordinates G dim) (Γ : Subgroup G) [mtr : MetricSpace (G⧸Γ)] + + + +omit [IsTopologicalGroup G] in +theorem firstBad_card_bound {m v D : ℕ} {c₀ C₀ : ℝ} {B : NNReal} {η Z S Y δ : ℝ} + (d M : ℕ) (hd : 0canonicalLog c (P y) i) D) + (t : Fin m → ℤ) (ht : ∀ j,0canonicalLog c (Q y) i) D) → + ((exceptional Γ v c₀ (C₀+1) B η Y' S Q r L).card:ℝ)≤δ*(times S r L).card) : + (((times S r L).filter (fun s=>firstBad Γ m v c₀ C₀ B η Z d M A P s t)).card:ℝ)≤ + (d:ℝ)^v*δ*(times S r L).card := by + classical + obtain ⟨Q,hQ,hred⟩ := firstBad_reduction Γ c d M hd hC A P hP t ht hdq hMq hZ + have hh := filter_union_bound (times S r L) + (fun s=>firstBad Γ m v c₀ C₀ B η Z d M A P s t) + (fun R s=>RoughProgressionDensity.BadAt Γ v c₀ (C₀+1) B η + (Z/(d*(∏ j,(t j).natAbs):ℕ)) (Q R) s) (δ*(times S r L).card) + (fun s hs h=>hred s (htimes s hs).1 (htimes s hs).2 h) + (fun R=>huni _ hY (Q R) (hQ R)) + simpa only [Fintype.card_fun,Fintype.card_fin,Nat.cast_pow,mul_assoc] using hh + + + +theorem firstBad_fiber_eventual (hsk : SecondKind c) + (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0S n j) atTop atTop) + (hZ : ∀ a : ℝ,0Z n/(totalScale (S n))^a) atTop atTop) + (hMs : ∀ n,Smooth (w n) (M n:ℤ)) + (hL : ∀ n,0S n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ (A : Fin v → ℤ) (P : (Fin ((m+1)+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ t∈productTimes (Fin.tail (S n)) (Fin.tail (r n)) (L n), + (((times (S n 0) (r n 0) (L n)).filter + (fun s=>firstBad Γ m v c₀ C₀ B η (Z n) d (M n) A P s t)).card:ℝ)≤ + ε*(times (S n 0) (r n 0) (L n)).card := by + classical + intro ε hε + let U (n : ℕ) := Z n/((d:ℝ)*(2*totalScale (S n))^m) + have hSP := eventually_all.mpr (fun j=>(hS j).eventually (eventually_gt_atTop 0)) + have hST : ∀ᶠ n in atTop,S n 0≤totalScale (S n) := by + filter_upwards [hSP] with n hn + exact (totalScale_bounds _ (fun j=>(hn j).le)).2 0 + have hU := residual_power_domination ((hS 0).eventually (eventually_gt_atTop 0)) hST hZ d m hd + have hUtop : Tendsto U atTop atTop := by + simpa only [pow_zero,div_one] using integer_scales_of_real (hS 0) hU 0 + have hdv : (0:ℝ)<(d:ℝ)^v := pow_pos (by exact_mod_cast hd) _ + have huni := RoughCubeUniform.larger_scale_uniform c Γ hsk hΓ htop v D c₀ (C₀+1) B η + hc₀ (by linarith) hB hη w (fun n=>S n 0) U (fun n=>r n 0) L hw (hS 0) hU + hL hsm hWL (fun n=>hr n 0) (hSL 0) (ε/(d:ℝ)^v) (div_pos hε hdv) + have hcard := timeLength_tendsto (r:=fun n=>r n 0) hL (hS 0) (hSL 0) + filter_upwards [huni,hSP,hw.eventually (eventually_ge_atTop d), + hUtop.eventually (eventually_ge_atTop 1),hcard.eventually (eventually_gt_atTop 0)] with n hn hsn hwn hun hcn + intro A P hP t ht + have htt : ∀ j,t j∈times (S n j.succ) (r n j.succ) (L n) := by + simpa only [productTimes,Fintype.mem_piFinset,Fin.tail] using ht + have htdata (j : Fin m) := time_positive_rough (hsn j.succ) (hL n) (hr n j.succ) (hWL n) (htt j) + have hb := product_tail_bound (S n) t (fun j=>(hsn j).le) + (fun j=>⟨(htdata j).1,(htdata j).2.2⟩) + have hdq : d.Coprime (∏ j,(t j).natAbs) := Nat.Coprime.prod_right (fun j _=> + period_coprime_of_rough (w n) d (t j).natAbs hd hwn + ((rough_iff_coprime _ _).mp (htdata j).2.1)) + have hMq : (M n).Coprime (∏ j,(t j).natAbs) := Nat.Coprime.prod_right + (fun j _=>smooth_nat_coprime_rough (hMs n) (htdata j).2.1) + have hden : (0:ℝ)<(d:ℝ)*(2*totalScale (S n))^m := by + have hh := (totalScale_bounds (S n) (fun j=>(hsn j).le)).1 + positivity + have hZn : 0≤Z n := by + have hh := (le_div_iff₀ hden).mp hun + dsimp [U] at hun + have hh' := (le_div_iff₀ hden).mp hun + linarith + have hKpos : (0:ℝ)<((d*(∏ j,(t j).natAbs):ℕ):ℝ) := by + rw [Nat.cast_mul] + exact mul_pos (by exact_mod_cast hd) hb.1 + have hKle : ((d*(∏ j,(t j).natAbs):ℕ):ℝ)≤(d:ℝ)*(2*totalScale (S n))^m := by + rw [Nat.cast_mul] + exact mul_le_mul_of_nonneg_left hb.2 (by positivity) + have hY : U n≤Z n/(d*(∏ j,(t j).natAbs):ℕ) := + div_le_div_of_nonneg_left hZn hKpos hKle + have hKZ : ((d*(∏ j,(t j).natAbs):ℕ):ℝ)≤Z n := by + have hh := (le_div_iff₀ hKpos).mp (hun.trans hY) + simpa using hh + have hcpos : (0:ℝ)<(times (S n 0) (r n 0) (L n)).card := by + rw [times_card _ _ _ (hL n)] + exact hcn + have hbound := firstBad_card_bound c Γ d (M n) hd hC₀.le A P hP t + (fun j=>(htdata j).1) hdq hMq hKZ hY (r n 0) (L n) (fun s hs=>by + have hh:=time_positive_rough (hsn 0) (hL n) (hr n 0) (hWL n) hs + exact ⟨hh.1,(smooth_nat_coprime_rough (hMs n) hh.2.1).mul_left + (period_coprime_of_rough (w n) d s.natAbs hd hwn ((rough_iff_coprime _ _).mp hh.2.1))⟩) + (fun Y hY Q hQ=>((div_lt_iff₀ hcpos).mp (hn Y hY Q hQ)).le) + convert hbound using 1 + field_simp + +end RoughProductRemoval + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughRational01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughRational01.lean new file mode 100644 index 0000000000000000000000000000000000000000..a61327653c27c8844d656f7fbb8c0cd51681eb0a --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughRational01.lean @@ -0,0 +1,346 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughDyadic01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open scoped BigOperators commutatorElement +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughPolynomialDegree +open RealPolynomialDegree PolynomialLineCoefficients CorrectedBoxLeibman +variable {σ ι : Type*} + +lemma coordinate (i : σ) : HasDegree (fun x : σ→ℝ=>x i) 1:= + ⟨MvPolynomial.X i,by simp,by simp⟩ + +lemma power {f : (σ→ℝ)→ℝ} {d : ℕ} (hf : HasDegree f d) (k : ℕ) : + HasDegree (fun x=>f x^k) (d*k):=by + obtain ⟨p,hp,he⟩:=hf + exact ⟨p^k,(MvPolynomial.totalDegree_pow p k).trans (by simpa only [Nat.mul_comm] using Nat.mul_le_mul_left k hp),by simp [he]⟩ + +lemma finite_sum (S : Finset ι) (f : ι→(σ→ℝ)→ℝ) (d : ℕ) + (hf : ∀ i∈S,HasDegree (f i) d) : HasDegree (fun x=>∑i∈S,f i x) d:=by + classical + induction S using Finset.induction_on with + | empty=>simpa using RealPolynomialDegree.const (σ:=σ) 0 d + | @insert i S hi ih=> + simp only [Finset.sum_insert hi] + simpa only [max_self] using RealPolynomialDegree.add + (hf i (by simp)) (ih (fun j hj=>hf j (Finset.mem_insert_of_mem hj))) + +lemma finite_prod (S : Finset ι) (f : ι→(σ→ℝ)→ℝ) (d : ι→ℕ) + (hf : ∀ i∈S,HasDegree (f i) (d i)) : + HasDegree (fun x=>∏i∈S,f i x) (∑i∈S,d i):=by + classical + induction S using Finset.induction_on with + | empty=>simpa using RealPolynomialDegree.const (σ:=σ) 1 0 + | @insert i S hi ih=> + simp only [Finset.prod_insert hi,Finset.sum_insert hi] + exact RealPolynomialDegree.mul (hf i (by simp)) + (ih (fun j hj=>hf j (Finset.mem_insert_of_mem hj))) + +lemma polynomial_eval {f : (σ→ℝ)→ℝ} {d q : ℕ} (hf : HasDegree f d) + (p : Polynomial ℝ) (hp : p.natDegree ≤ q) : + HasDegree (fun x=>p.eval (f x)) (d*q):=by + have he (x) : p.eval (f x)=∑j∈Finset.range (q+1),p.coeff j*(f x)^j:= + Polynomial.eval_eq_sum_range' (Nat.lt_succ_of_le hp) _ + simp_rw [he] + apply finite_sum + intro j hj + exact RealPolynomialDegree.mono (RealPolynomialDegree.scale (power hf j) (p.coeff j)) + (Nat.mul_le_mul_left d (Nat.le_of_lt_succ (Finset.mem_range.mp hj))) + + + +lemma mv_eval {τ : Type*} (p : MvPolynomial τ ℝ) (d : ℕ) + (g : τ→(σ→ℝ)→ℝ) (hg : ∀ i,HasDegree (g i) d) : + HasDegree (fun x=>MvPolynomial.eval (fun i=>g i x) p) (d*p.totalDegree):=by + classical + have he (x) : MvPolynomial.eval (fun i=>g i x) p= + ∑m∈p.support,p.coeff m*∏i∈m.support,g i x^m i:=by + conv_lhs=>rw [p.as_sum] + simp only [map_sum,MvPolynomial.eval_monomial,Finsupp.prod] + simp_rw [he] + apply finite_sum + intro m hm + have hprod:=finite_prod m.support (fun i x=>g i x^m i) (fun i=>d*m i) + (fun i _=>power (hg i) (m i)) + have hsum : (∑i∈m.support,d*m i)=d*m.sum (fun _ k=>k):=by + simp only [Finsupp.sum,Finset.mul_sum] + rw [hsum] at hprod + exact RealPolynomialDegree.mono (RealPolynomialDegree.scale hprod _) + (Nat.mul_le_mul_left d (MvPolynomial.le_totalDegree hm)) + +lemma compose {τ : Type*} {f : (τ→ℝ)→ℝ} {d e : ℕ} + (hf : HasDegree f d) (g : τ→(σ→ℝ)→ℝ) (hg : ∀ i,HasDegree (g i) e) : + HasDegree (fun x=>f (fun i=>g i x)) (e*d):=by + obtain ⟨p,hp,he⟩:=hf + simp_rw [he] + exact RealPolynomialDegree.mono (mv_eval p e g hg) (Nat.mul_le_mul_left e hp) + +lemma time_affine {v d : ℕ} {f : (Fin (v+1)→ℝ)→ℝ} (hf : HasDegree f d) (a b : ℝ) : + HasDegree (fun y : Fin (v+1)→ℝ=>f (Fin.cons (a+b*y 0) (Fin.tail y))) d:=by + have h:=compose hf (fun i y=>(Fin.cons (a+b*y 0) (Fin.tail y)) i) (e:=1) (by + intro i + refine Fin.cases ?_ (fun j=>?_) i + · simpa only [Fin.cons_zero,max_self] using RealPolynomialDegree.add + (RealPolynomialDegree.const (σ:=Fin (v+1)) a 1) + (RealPolynomialDegree.scale (coordinate (0:Fin (v+1))) b) + · exact coordinate j.succ) + simpa only [one_mul] using h + + + +lemma joint_grid {v s q : ℕ} (θ : PolynomialLineCoefficients.Grid v s→Polynomial ℝ) + (hθ : ∀ I,(θ I).natDegree ≤ q) : + HasDegree (fun y : Fin (v+1)→ℝ=>gridEval (fun I=>(θ I).eval (y 0)) (Fin.tail y)) (q+v*s):=by + classical + apply finite_sum + intro I _ + have htime : HasDegree (fun y : Fin (v+1)→ℝ=>(θ I).eval (y 0)) q:=by + simpa only [one_mul] using polynomial_eval (coordinate (0:Fin (v+1))) (θ I) (hθ I) + have hspace : HasDegree (fun y : Fin (v+1)→ℝ=>∏i,(Fin.tail y i)^(I i).val) (totalDegree I):=by + simpa only [one_mul,totalDegree] using finite_prod Finset.univ + (fun i (y : Fin (v+1)→ℝ)=>(Fin.tail y i)^(I i).val) (fun i=>1*(I i).val) + (fun i _=>power (coordinate i.succ) (I i).val) + exact RealPolynomialDegree.mono (RealPolynomialDegree.mul htime hspace) + (Nat.add_le_add_left (PolynomialLineCoefficients.totalDegree_le I) q) + +end RoughPolynomialDegree + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughRealRationalization +open _root_.Polynomial _root_.OAI.Polynomial Filter Finset RoughScales RealPolynomialDegree +open RoughRationalBlock RoughAnalyticRationalization RoughDyadicFiltration +open FinitePieceAverages RoughSamplingWeights ComparableBoxLeibman +open CorrectedBoxLeibman PolynomialLineCoefficients TriangularLatticeRecovery +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus RationalTailCoordinates UnitAddTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {r : ℕ} (c : RealCoordinates G r) (hsk : SecondKind c) +variable (Γ : Subgroup G) (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] +variable [hBorel : @BorelSpace (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) inferInstance] +variable [mtr : MetricSpace (G⧸Γ)] +variable (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) +local instance : TopologicalSpace (G⧸Γ):=mtr.toUniformSpace.toTopologicalSpace + +include hsk hΓ htop in + + +theorem real_rational_split + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (v d : ℕ) (c₀ C₀ : ℝ) (B₀ : NNReal) (η : ℝ) + (hc₀ : 0Z n/S n^k) atTop atTop) : + letI : CompactSpace (G⧸Γ):=metric_compact c Γ hΓ mtr htop + letI : BorelSpace (G⧸Γ):=metric_borelSpace Γ mtr htop + ∃ s : ℕ,∃ U : Finset (G→*Multiplicative ℝ),∃ B : ℝ,1 ≤ B ∧ + ∀ h : ℕ,2*((v+1)*s+1)≤h →∃ N : ℕ,∀ᶠ n in atTop, + ∀ (a₀ m : ℤ),0 < m →Smooth (w n) m → + (∀ z : ℤ,0≤z →z≤N →S n≤((a₀+m*z:ℤ):ℝ) ∧ ((a₀+m*z:ℤ):ℝ)<2*S n)→ + (∀ z : ℤ,0≤z →z≤N →Rough (w n) (a₀+m*z))→ + ∀ P : (Fin (v+1)→ℝ)→G,(∀ i,HasDegree (fun y=>canonicalLog c (P y) i) d)→ + ∀ (lo hi : Fin (N+1)→Fin v→ℝ) (res : Fin (N+1)→Fin v→ℤ) + (F : Fin (N+1)→C(G⧸Γ,ℂ)), + (∀ j i,c₀*Z n≤hi j i-lo j i)→ + (∀ j i,-C₀*Z n≤lo j i ∧ hi j i≤C₀*Z n)→ + (∀ j,LipschitzWith B₀ (F j) ∧ ‖F j‖≤B₀)→ + (∀ j,η≤‖mean (boxIndices (lo j) (hi j) (fun _=>0) 1) + (fun x=>F j (QuotientGroup.mk (P (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ)))))) - + mean (physicalResidueBox (lo j) (hi j) (res j) (a₀+m*(j.val:ℤ)).natAbs) + (fun x=>F j (QuotientGroup.mk (P (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ))))))‖) → + ∃ a b : ℕ,0 < b ∧ a+b*h≤N ∧ Smooth (w n) (m*(b:ℤ)) ∧ + ∃ ξ∈U,ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ,∃ z : ℤ,(ξ g).toAdd=z) ∧ + ∃ θ : PolynomialLineCoefficients.Grid v s→ℝ[X], + (∀ I,(θ I).natDegree ≤ s) ∧ + (∀ z : ℝ,∀ x : Fin v→ℝ, + gridEval (fun I=>(θ I).eval z) x = + (ξ (P (Fin.cons ((a:ℝ)+(b:ℝ)*z) x))).toAdd) ∧ + ∃ M : PolynomialLineCoefficients.Grid v s→ℚ[X],Split (w n) h (Z n) B θ 0 1 M := by + classical + let : CompactSpace (G⧸Γ):=metric_compact c Γ hΓ mtr htop + let : BorelSpace (G⧸Γ):=metric_borelSpace Γ mtr htop + obtain ⟨C,hC,hA⟩:=RoughDyadicFiltration.logarithmic_adapted c hsk + let D:=max 1 (C*d) + let s:=D*2^r + obtain ⟨h0,h1,hs,hqb,hq,hpoly⟩:=hA (v+1) d + obtain ⟨U,B,hB,hout⟩:=rational_split_from_discrepancies (t:=r) (d:=0) + c hsk (filtration c D) h0 h1 s hs (cutoff r D) hqb hq Γ hΓ htop + μ v c₀ C₀ B₀ η hc₀ hC₀ hB₀ hη hw hS hZ + refine ⟨s,U,B,hB,?_⟩ + intro h hh + obtain ⟨N,hN⟩:=hout h hh + refine ⟨N,?_⟩ + filter_upwards [hN] with n hn + intro a₀ m hm hms hscale hrough P hP lo hi res F hside hbox hF hbad + let f : (Fin (v+1)→ℤ)→G:=fun y=>P (fun i=>(y i:ℝ)) + have hf : LeibmanSquare.Polynomial (filtration c D) 0 f:=(hpoly P hP).2 + have hfcons (z : ℤ) (x : Fin v→ℤ) : f (Fin.cons z x)=P (Fin.cons (z:ℝ) (fun i=>(x i:ℝ))):=by + dsimp only [f] + congr 1 + ext i + exact Fin.cases rfl (fun _=>rfl) i + obtain ⟨a,b,hb,hab,hmb,ξ,hξ,hξn,hξc,hξZ,θ,hθ,he,M,hM⟩:=hn a₀ m hm hms hscale hrough + f hf lo hi res F hside hbox hF (by simpa only [hfcons,Int.cast_natCast] using hbad) + refine ⟨a,b,hb,hab,hmb,ξ,hξ,hξn,hξc,hξZ,θ,hθ,?_,M,hM⟩ + let P' : (Fin (v+1)→ℝ)→G:=fun y=>P (Fin.cons ((a:ℝ)+(b:ℝ)*y 0) (Fin.tail y)) + have hP' : ∀ i,HasDegree (fun y=>canonicalLog c (P' y) i) d:= + fun i=>RoughPolynomialDegree.time_affine (hP i) _ _ + have hreal:=RoughRealCharacterIdentity.character_identity_real c hsk ξ hξc P' hP' θ hθ (by + intro z x + simpa only [P',Fin.cons_zero,Fin.tail_cons,hfcons,Int.cast_add,Int.cast_mul,Int.cast_natCast] + using he z x) + intro z x + exact hreal z x + +end RoughRealRationalization + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughRationalKernel +open _root_.Polynomial _root_.OAI.Polynomial RealPolynomialDegree RoughPolynomialDegree +open CorrectedBoxLeibman PolynomialLineCoefficients RoughRationalBlock +open RoughRealCharacterIdentity RoughCoefficientDescentBridge + +variable {v s : ℕ} +def rationalValue (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) (y : Fin (v+1)→ℝ) : ℝ:= + gridEval (fun I=>((M I).map (algebraMap ℚ ℝ)).eval (y 0)) (Fin.tail y) +def errorCoefficients (θ : PolynomialLineCoefficients.Grid v s→ℝ[X]) + (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) (z : ℝ) : PolynomialLineCoefficients.Grid v s→ℝ:= + fun I=>(θ I).eval z-((M I).map (algebraMap ℚ ℝ)).eval z +def errorValue (θ : PolynomialLineCoefficients.Grid v s→ℝ[X]) + (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) (y : Fin (v+1)→ℝ) : ℝ:= + gridEval (errorCoefficients θ M (y 0)) (Fin.tail y) + +lemma error_eq (θ : PolynomialLineCoefficients.Grid v s→ℝ[X]) + (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) (y : Fin (v+1)→ℝ) : + errorValue θ M y=gridEval (fun I=>(θ I).eval (y 0)) (Fin.tail y)-rationalValue M y:=by + simp only [errorValue,errorCoefficients,rationalValue,gridEval,sub_mul,Finset.sum_sub_distrib] + +lemma rational_degree (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) + (hM : ∀ I,(M I).natDegree ≤ (v+1)*s) : + HasDegree (rationalValue M) ((v+1)*s+v*s):= + joint_grid _ (fun I=>Polynomial.natDegree_map_le.trans (hM I)) + +lemma error_degree (θ : PolynomialLineCoefficients.Grid v s→ℝ[X]) + (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) + (hθ : ∀ I,(θ I).natDegree ≤ s) (hM : ∀ I,(M I).natDegree ≤ (v+1)*s) : + HasDegree (errorValue θ M) ((v+1)*s+v*s):=by + have hθ' : ∀ I,(θ I).natDegree ≤ (v+1)*s:=fun I=>(hθ I).trans (by nlinarith) + have h:=RealPolynomialDegree.add (joint_grid θ hθ') (RealPolynomialDegree.neg (rational_degree M hM)) + simpa only [max_self,← sub_eq_add_neg,← error_eq] using h + +lemma split_error_bound {w H : ℕ} {Z B : ℝ} + {θ : PolynomialLineCoefficients.Grid v s→ℝ[X]} {M : PolynomialLineCoefficients.Grid v s→ℚ[X]} + (h : Split w H Z B θ 0 1 M) (z : ℕ) (hz : z≤H) : + ∀ I,|errorCoefficients θ M (z:ℝ) I| *Z^∑i,(I i).val≤B:=by + intro I + simpa only [errorCoefficients,zero_add,one_mul,totalDegree] using h.2.2.2.1 I z hz + + + +lemma integer_spatial (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) (z : ℕ) + (hM : ∀ I,RoughInterpolation.Integral ((M I).eval (z:ℚ))) : + ∃ m : MvPolynomial (Fin v) ℤ,∀ x : Fin v→ℝ, + MvPolynomial.eval₂ (Int.castRingHom ℝ) x m = rationalValue M (Fin.cons (z:ℝ) x) := by + classical + choose b hb using hM + let m : MvPolynomial (Fin v) ℤ:=∑I,MvPolynomial.monomial (gridExponent I) (b I) + refine ⟨m,?_⟩ + intro x + simp only [m,MvPolynomial.eval₂_sum,MvPolynomial.eval₂_monomial,rationalValue,Fin.cons_zero,Fin.tail_cons,gridEval] + apply Finset.sum_congr rfl + intro I _ + have he : ((M I).map (algebraMap ℚ ℝ)).eval (z:ℝ)=(b I:ℝ):=by + rw [Polynomial.eval_map] + calc + _ = (((M I).eval (z:ℚ):ℚ):ℝ):=by + simp + _ = (b I:ℝ):=by exact_mod_cast (hb I).symm + rw [he] + congr 1 + rw [Finsupp.prod_fintype _ _ (by intro i; simp)] + rfl + +lemma integer_spatial_on_lattice (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) (z : ℕ) + (hM : ∀ I,RoughInterpolation.Integral ((M I).eval (z:ℚ))) : + ∃ m : MvPolynomial (Fin v) ℤ,∀ x : Fin v→ℤ, + ((MvPolynomial.eval x m:ℤ):ℝ)=rationalValue M (Fin.cons (z:ℝ) (fun i=>(x i:ℝ))) := by + obtain ⟨m,hm⟩:=integer_spatial M z hM + refine ⟨m,fun x=>?_⟩ + rw [←hm] + exact MvPolynomial.eval₂_comp (Int.castRingHom ℝ) x m + +section Kernel +open RationalLattice MalcevCharacters RoughKernelFactorization +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G→*Multiplicative ℝ) (Γ : Subgroup G) (R : Reduction c hsk χ Γ) + + + +theorem kernel_polynomial : ∃ E : ℕ,0canonicalLog c (P y) i) d) → + (∀ I,(θ I).natDegree ≤ s) → (∀ I,(M I).natDegree ≤ (v+1)*s) → + (∀ z : ℝ,∀ x : Fin v→ℝ,gridEval (fun I=>(θ I).eval z) x=(χ (P (Fin.cons z x))).toAdd) → + ∃ Q : (Fin (v+1)→ℝ)→χ.ker, + (∀ y,P y=R.flow c hsk χ Γ (Multiplicative.ofAdd (errorValue θ M y))* + (Q y).val*R.flow c hsk χ Γ (Multiplicative.ofAdd (rationalValue M y))) ∧ + ∀ i,HasDegree (fun y=>canonicalLog (R.chart c hsk χ Γ) (Q y) i) + (E*max d ((v+1)*s+v*s)) := by + obtain ⟨E,hE,hfactor⟩:=R.logarithmic_factorization c hsk χ Γ + refine ⟨E,hE,?_⟩ + intro v d s P θ M hP hθ hM he + apply hfactor (v+1) (max d ((v+1)*s+v*s)) P (errorValue θ M) (rationalValue M) + · intro y + rw [error_eq,sub_add_cancel] + simpa only [Fin.cons_self_tail] using (he (y 0) (Fin.tail y)).symm + · exact fun i=>RealPolynomialDegree.mono (hP i) (le_max_left _ _) + · exact RealPolynomialDegree.mono (error_degree θ M hθ hM) (le_max_right _ _) + · exact RealPolynomialDegree.mono (rational_degree M hM) (le_max_right _ _) + +end Kernel +end RoughRationalKernel + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughReal01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughReal01.lean new file mode 100644 index 0000000000000000000000000000000000000000..cee6359b6f98c59dc0c1d119a95a244d6c66d529 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughReal01.lean @@ -0,0 +1,321 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughLog01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughRealCharacterIdentity +open PolynomialLineCoefficients CorrectedBoxLeibman +open RoughJointCoefficients RoughCoefficientDescentBridge RealPolynomialDegree + +lemma sum_degree {v : ℕ} {ι : Type*} (S : Finset ι) (f : ι→(Fin v→ℝ)→ℝ) + (d : ℕ) (hf : ∀ i∈S,HasDegree (f i) d) : + HasDegree (fun x=>∑ i∈S,f i x) d := by + classical + induction S using Finset.induction_on with + | empty => simpa using RealPolynomialDegree.const (σ:=Fin v) 0 d + | @insert i S hi ih => + simp only [Finset.sum_insert hi] + simpa only [max_self] using RealPolynomialDegree.add + (hf i (Finset.mem_insert_self _ _)) (ih (fun j hj=>hf j (Finset.mem_insert_of_mem hj))) + + +lemma eq_of_integer_agree {v d e : ℕ} {f g : (Fin v→ℝ)→ℝ} + (hf : HasDegree f d) (hg : HasDegree g e) + (h : ∀ x : Fin v→ℤ,f (fun i=>(x i:ℝ))=g (fun i=>(x i:ℝ))) : f=g := by + classical + obtain ⟨p,hp,he⟩:=hf + obtain ⟨q,hq,hqv⟩:=hg + have hpq : p=q := by + apply MvPolynomial.funext_set (fun _=>Set.range (Int.cast : ℤ→ℝ)) + (fun _=>Set.infinite_range_of_injective (Int.cast_injective)) + intro x hx + have hx' (i : Fin v) : ∃ z : ℤ,(z:ℝ)=x i := hx i (Set.mem_univ i) + choose z hz using hx' + have hzv : (fun i=>(z i:ℝ))=x := funext hz + rw [← he x,← hqv x,← hzv] + exact h z + funext x + rw [he,hqv,hpq] + + +def gridMv {v s : ℕ} (a : PolynomialLineCoefficients.Grid v s→ℝ) : MvPolynomial (Fin v) ℝ := + ∑ I,MvPolynomial.monomial (gridExponent I) (a I) + +lemma eval_gridMv {v s : ℕ} (a : PolynomialLineCoefficients.Grid v s→ℝ) (x : Fin v→ℝ) : + MvPolynomial.eval x (gridMv a)=gridEval a x := by + classical + simp only [gridMv,map_sum,MvPolynomial.eval_monomial,gridEval] + apply Finset.sum_congr rfl + intro I hI + congr 1 + rw [Finsupp.prod_fintype _ _ (by intro i; simp)] + rfl + +lemma gridMv_degree {v s : ℕ} (a : PolynomialLineCoefficients.Grid v s→ℝ) : + (gridMv a).totalDegree≤v*s := by + classical + apply MvPolynomial.totalDegree_finsetSum_le + intro I _ + exact (MvPolynomial.totalDegree_monomial_le (gridExponent I) (a I)).trans + (by + change (gridExponent I).sum (fun _ k=>k) ≤ v*s + rw [gridExponent_degree] + exact PolynomialLineCoefficients.totalDegree_le I) + + + +def jointArray {v s : ℕ} (θ : PolynomialLineCoefficients.Grid v s→Polynomial ℝ) : + PolynomialLineCoefficients.Grid (v+1) s→ℝ := + fun K=>(θ (Fin.tail K)).coeff (K 0).val + +lemma timeCoefficient_jointArray {v s : ℕ} + (θ : PolynomialLineCoefficients.Grid v s→Polynomial ℝ) + (hθ : ∀ I,(θ I).natDegree ≤ s) (I : PolynomialLineCoefficients.Grid v s) (z : ℝ) : + (timeCoefficient (jointArray θ) I).eval z=(θ I).eval z := by + classical + simp only [timeCoefficient,Polynomial.eval_finsetSum,Polynomial.eval_mul, + Polynomial.eval_C,Polynomial.eval_pow,Polynomial.eval_X,jointArray,Fin.tail_cons,Fin.cons_zero] + rw [Polynomial.eval_eq_sum_range' (Nat.lt_succ_of_le (hθ I))] + exact Fin.sum_univ_eq_sum_range (fun j=>(θ I).coeff j*z^j) (s+1) + +lemma joint_grid_degree {v s : ℕ} + (θ : PolynomialLineCoefficients.Grid v s→Polynomial ℝ) + (hθ : ∀ I,(θ I).natDegree ≤ s) : + HasDegree (fun y : Fin (v+1)→ℝ=>gridEval (fun I=>(θ I).eval (y 0)) (Fin.tail y)) ((v+1)*s) := by + refine ⟨gridMv (jointArray θ),gridMv_degree _,?_⟩ + intro y + rw [eval_gridMv] + have h:=gridEval_timeCoefficient (jointArray θ) (y 0) (Fin.tail y) + simpa only [timeCoefficient_jointArray θ hθ,Fin.cons_self_tail] using h + +section Character +open RationalLattice MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) + +include hsk in +omit [IsTopologicalGroup G] in +lemma character_degree {v d : ℕ} (χ : G→*Multiplicative ℝ) (hχ : Continuous χ) + (P : (Fin v→ℝ)→G) (hP : ∀ i,HasDegree (fun x=>c.coord (P x) i) d) : + HasDegree (fun x=>(χ (P x)).toAdd) d := by + have h:=sum_degree Finset.univ + (fun i x=>(χ (axis c i 1)).toAdd*c.coord (P x) i) d + (fun i _=>RealPolynomialDegree.scale (hP i) _) + convert h using 1 + funext x + simpa only [mul_comm] using character_coordinates c hsk χ hχ (P x) + +include hsk in + + +omit [IsTopologicalGroup G] in +theorem character_identity_real {v d s : ℕ} (χ : G→*Multiplicative ℝ) (hχ : Continuous χ) + (P : (Fin (v+1)→ℝ)→G) + (hP : ∀ i,HasDegree (fun y=>canonicalLog c (P y) i) d) + (θ : PolynomialLineCoefficients.Grid v s→Polynomial ℝ) + (hθ : ∀ I,(θ I).natDegree ≤ s) + (he : ∀ z : ℤ,∀ x : Fin v→ℤ, + gridEval (fun I=>(θ I).eval (z:ℝ)) (fun i=>(x i:ℝ)) = + (χ (P (Fin.cons (z:ℝ) (fun i=>(x i:ℝ))))).toAdd) : + ∀ z : ℝ,∀ x : Fin v→ℝ, + gridEval (fun I=>(θ I).eval z) x=(χ (P (Fin.cons z x))).toAdd := by + obtain ⟨C,hC,hcoord⟩:=coord_degree_bound c + have hchar:=character_degree c hsk χ hχ P (hcoord (v+1) d P hP) + have heq:=eq_of_integer_agree (joint_grid_degree θ hθ) hchar (by + intro y + have hcons : Fin.cons (y 0:ℝ) (fun i=>(Fin.tail y i:ℝ))=(fun i=>(y i:ℝ)) := by + ext i + exact Fin.cases rfl (fun _=>rfl) i + change gridEval (fun I=>(θ I).eval (y 0:ℝ)) (fun i=>(Fin.tail y i:ℝ)) = _ + simpa only [hcons] using he (y 0) (Fin.tail y)) + intro z x + have h:=congrFun heq (Fin.cons z x) + simpa only [Fin.cons_zero,Fin.tail_cons] using h + +end Character +end RoughRealCharacterIdentity + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughRationalBlock +open _root_.Polynomial _root_.OAI.Polynomial Filter Finset +open RoughScales RoughInterpolation PositiveCoefficientDescent +open RoughCoefficientDescentBridge CorrectedBoxLeibman PolynomialLineCoefficients TriangularLatticeRecovery + +lemma smooth_mul {w : ℕ} {a b : ℤ} (ha : Smooth w a) (hb : Smooth w b) : + Smooth w (a*b) := by + intro p hp hd + have hp' : Prime (p:ℤ) := Int.prime_iff_natAbs_prime.mpr (by simpa using hp) + rcases hp'.dvd_mul.mp hd with h | h + · exact ha p hp h + · exact hb p hp h + +lemma affine_degree {p : ℝ[X]} {s : ℕ} (hp : p.natDegree ≤ s) (a b : ℝ) : + (p.comp (C a+C b*X)).natDegree ≤ s := by + have hlin : (C a+C b*X).natDegree ≤ 1 := + natDegree_add_le_of_degree_le (by simp) ((natDegree_C_mul_le _ _).trans (by simp)) + exact natDegree_comp_le.trans ((Nat.mul_le_mul_left _ hlin).trans (by simpa using hp)) + +lemma int_interval_card (N : ℕ) : (Finset.Icc (0:ℤ) (N:ℤ)).card=N+1 := by + rw [Int.card_Icc] + omega + + + +def Split {v s : ℕ} (w H : ℕ) (Z B : ℝ) + (θ : PolynomialLineCoefficients.Grid v s→ℝ[X]) (a b : ℕ) + (M : PolynomialLineCoefficients.Grid v s→ℚ[X]) : Prop := + (∀ I,(M I).natDegree ≤ (v+1)*s) ∧ + (∀ I j p,p.Prime→p∣((M I).coeff j).den → p≤w) ∧ + (∀ I,∀ z : ℕ,z≤H→Integral ((M I).eval (z:ℚ))) ∧ + (∀ I,∀ z : ℕ,z≤H→ + |(θ I).eval ((a+b*z:ℕ):ℝ)-((M I).map (algebraMap ℚ ℝ)).eval (z:ℝ)| * + Z^totalDegree I ≤ B) ∧ + ∀ z : ℕ,z≤H→ + 0≤(θ 0).eval ((a+b*z:ℕ):ℝ)-((M 0).map (algebraMap ℚ ℝ)).eval (z:ℝ) ∧ + (θ 0).eval ((a+b*z:ℕ):ℝ)-((M 0).map (algebraMap ℚ ℝ)).eval (z:ℝ)<1 + + + +theorem eventual_split (v s : ℕ) {A : ℝ} (hA : 0Z n/S n^k) atTop atTop) : + ∃ B : ℝ,1≤B ∧ ∀ H : ℕ,2*((v+1)*s+1)≤H→ + ∃ N : ℕ,0(θ I).eval (z:ℝ)) (u z)) I) + ≤ A*((p z:ℝ)/Z n)^totalDegree I)→ + ∃ c d : ℕ,0(θ I).comp (C (c:ℝ)+C (d:ℝ)*X) + have hθ' (I) : (θ' I).natDegree ≤ s:=affine_degree (hθ I) _ _ + have hindex (z : ℤ) (hz : 0≤z) (hzH : z≤H) : + 0≤(c:ℤ)+(d:ℤ)*z ∧ (c:ℤ)+(d:ℤ)*z≤N := by + constructor + · positivity + · have h:=mul_le_mul_of_nonneg_left hzH (Int.natCast_nonneg d) + have hn : (c:ℤ)+(d:ℤ)*(H:ℤ)≤N:=by exact_mod_cast hcdN + omega + have ht (z : ℤ) : a+b*((c:ℤ)+(d:ℤ)*z)=(a+b*(c:ℤ))+(b*(d:ℤ))*z:=by ring + have heval (I) (z : ℤ) : (θ' I).eval (z:ℝ)=(θ I).eval (((c:ℤ)+(d:ℤ)*z):ℝ):=by + simp [θ'] + obtain ⟨Mp,hMp⟩:=hn E hE hcard hdense (a+b*(c:ℤ)) (b*(d:ℤ)) + (mul_pos hb (by exact_mod_cast hd)) hbds + (fun z hz hzH=>by simpa only [ht] using hscale _ (hindex z hz hzH).1 (hindex z hz hzH).2) + (fun z hz=>by + simpa only [ht] using (hrough _ (hindex z (hE z hz).1 (hE z hz).2).1 + (hindex z (hE z hz).1 (hE z hz).2).2)) + θ' hθ' (fun z=>p ((c:ℤ)+(d:ℤ)*z)) (fun z=>u ((c:ℤ)+(d:ℤ)*z)) + (fun z hz=>hp _ (hindex z (hE z hz).1 (hE z hz).2).1 (hindex z (hE z hz).1 (hE z hz).2).2) + (fun z hz=>by + simpa only [ht] using (hsteps _ (hindex z (hE z hz).1 (hE z hz).2).1 + (hindex z (hE z hz).1 (hE z hz).2).2)) + (fun z hz=>hu _ (hindex z (hE z hz).1 (hE z hz).2).1 (hindex z (hE z hz).1 (hE z hz).2).2) + (fun z hz I hI=>by + simpa only [heval,Int.cast_add,Int.cast_mul,Int.cast_natCast] using (hobs _ (hindex z (hE z hz).1 (hE z hz).2).1 + (hindex z (hE z hz).1 (hE z hz).2).2 I hI)) + let M : PolynomialLineCoefficients.Grid v s→ℚ[X]:=fun I=> + if hI : 0 nlinarith + · rintro ⟨h₁,h₂⟩ + constructor + · apply (div_le_iff₀ hq).mpr; nlinarith + · apply (lt_div_iff₀ hq).mpr; nlinarith + +lemma count_error (lo hi a q : ℝ) (hq : 0 linarith + +lemma indices_subset (lo hi lo' hi' a q : ℝ) (hq : 0 simp + | @insert a s ha ih => + rw [Finset.prod_insert ha,Finset.prod_insert ha,Finset.sum_insert ha] + have hf0:= (hf a).1 + have hf1:= (hf a).2 + have hg0 : 0≤∏ i∈s,g i:=Finset.prod_nonneg (fun i _=>(hg i).1) + have hg1 : (∏ i∈s,g i)≤1:=Finset.prod_le_one₀ (fun i _=>(hg i).1) (fun i _=>(hg i).2) + have he : f a*(∏ i∈s,f i)-g a*(∏ i∈s,g i)= + f a*((∏ i∈s,f i)-(∏ i∈s,g i))+(f a-g a)*(∏ i∈s,g i):=by ring + rw [he] + calc + _≤|f a*((∏ i∈s,f i)-(∏ i∈s,g i))|+|(f a-g a)*(∏ i∈s,g i)|:=abs_add_le _ _ + _≤|(∏ i∈s,f i)-(∏ i∈s,g i)|+|f a-g a|:=by + rw [abs_mul,abs_mul,abs_of_nonneg hf0,abs_of_nonneg hg0] + exact add_le_add (mul_le_of_le_one_left (abs_nonneg _) hf1) + (mul_le_of_le_one_right (abs_nonneg _) hg1) + _≤|f a-g a|+∑ i∈s,|f i-g i|:=by linarith + + +def boxWeight {ι : Type*} [Fintype ι] + (lo hi lo' hi' a : ι → ℝ) (q : ℝ) : ℝ:= + ∏ i,((indices (lo' i) (hi' i) (a i) q).card:ℝ)/(indices (lo i) (hi i) (a i) q).card + + +theorem box_weight_error {ι : Type*} [Fintype ι] + (lo hi lo' hi' a : ι → ℝ) (q : ℝ) (hq : 0?_) (fun i=>?_)).trans + · apply Finset.sum_le_sum + intro i _ + exact (subinterval_weight (lo i) (hi i) (lo' i) (hi' i) (a i) q hq (hl i) (hm i) (hh i) (hscale i)).2.2.2 + · have ht:=subinterval_weight (lo i) (hi i) (lo' i) (hi' i) (a i) q hq (hl i) (hm i) (hh i) (hscale i) + exact ⟨ht.2.1,ht.2.2.1⟩ + · exact ⟨div_nonneg (sub_nonneg.mpr (hm i)) (hpos i).le, + (div_le_one (hpos i)).mpr (by linarith [hl i,hh i])⟩ + + + +theorem compare_box_weights {ι : Type*} [Fintype ι] + (lo hi lo' hi' a b : ι → ℝ) (q t : ℝ) (hq : 0j+K*n) + · intro n hn + change n ∈ indices lo' hi' (a+q*j) (q*K) at hn + change j+(K:ℤ)*n ∈ indices lo hi a q + rw [mem_indices _ _ _ _ (mul_pos hq hKr)] at hn + rw [mem_indices _ _ _ _ hq] + have he : a+q*((j+(K:ℤ)*n:ℤ):ℝ)=(a+q*j)+(q*K)*n:=by push_cast; ring + rw [he] + exact ⟨hl.trans hn.1,hn.2.trans_le hh⟩ + · intro x _ y _ hxy + exact mul_left_cancel₀ hKi (add_left_cancel hxy) + + + +theorem refined_interval_weight (lo hi lo' hi' a q : ℝ) (hq : 0?_) (fun i=>?_)).trans + · apply Finset.sum_le_sum + intro i _ + exact (refined_interval_weight (lo i) (hi i) (lo' i) (hi' i) (a i) q hq + (hl i) (hm i) (hh i) (hscale i) (j i) K hK).2.2.2 + · have ht:=refined_interval_weight (lo i) (hi i) (lo' i) (hi' i) (a i) q hq + (hl i) (hm i) (hh i) (hscale i) (j i) K hK + exact ⟨ht.2.1,ht.2.2.1⟩ + · refine ⟨div_nonneg (div_nonneg (sub_nonneg.mpr (hm i)) (hpos i).le) hKr.le,?_⟩ + apply (div_le_one hKr).mpr + exact ((div_le_one (hpos i)).mpr (by linarith [hl i,hh i])).trans hK1 + + + +theorem compare_refined_box_weights {ι : Type*} [Fintype ι] + (lo hi lo' hi' a b : ι → ℝ) (q t : ℝ) (hq : 0(u-a)*z) hb] + refine ⟨j,fun n=>⟨fun hn=>?_,fun hn=>?_⟩⟩ + · have hc:=Int.ModEq.add_left_cancel' a (hn.trans hu.symm) + rw [Int.modEq_iff_dvd] at hc ⊢ + have hc' : (K:ℤ)∣(q:ℤ)*(j-n):=by simpa [mul_sub] using hc + exact h.symm.isCoprime.dvd_of_dvd_mul_left hc' + · exact (Int.ModEq.add_left a (Int.ModEq.mul_left (q:ℤ) hn)).trans hu + + + +theorem residue_sample (lo hi : ℝ) (q K : ℕ) (hq : 0F (v (QuotientGroup.mk (P x))))- + mean U (fun x=>F (v (QuotientGroup.mk (P x))))‖ → + η-2*ε≤‖mean S (fun x=>g (QuotientGroup.mk (Q x)))- + mean U (fun x=>g (QuotientGroup.mk (Q x)))‖ := by + obtain ⟨L,hL⟩:=uniform_finite_kernel_tests c hsk χ Γ R hΓ hcont hZ v + (residueSigma c hsk χ Γ R) T K B hB ε hε + refine ⟨L,?_⟩ + intro V α _ m u + let r : ℤ:=MvPolynomial.eval u m % (R.period:ℤ) + have hr:=residue_range c hsk χ Γ R m u + let j : Fin R.period:=⟨r.toNat,by + have he : (r.toNat:ℤ)=r:=Int.toNat_of_nonneg hr.1 + exact_mod_cast (show (r.toNat:ℤ)F (v (QuotientGroup.mk (P x))) + let f' : α → ℂ:=fun x=>g (QuotientGroup.mk (Q x)) + have hpoint : ∀ x∈S∪U,‖f x-f' x‖≤ε:=by + intro x hx + have hp:=factorization_on_residue c hsk χ Γ R m (input x) u (hres x hx) + (P x) (R.flow c hsk χ Γ (Multiplicative.ofAdd a.val)) (Q x) (hP x hx) + have hσ : σ=R.flow c hsk χ Γ (Multiplicative.ofAdd (r:ℝ)):=by + dsimp only [σ,residueSigma] + rw [hj] + have hp' : (QuotientGroup.mk (P x) : G⧸Γ)=kernelTestMap χ Γ σ + (R.flow c hsk χ Γ (Multiplicative.ofAdd a.val)) (QuotientGroup.mk (Q x)):=by + rw [hσ] + exact hp + change ‖F (v (QuotientGroup.mk (P x)))-g (QuotientGroup.mk (Q x))‖≤ε + rw [hp',norm_sub_rev] + exact (he (QuotientGroup.mk (Q x))).le + have hs : ‖mean S f-mean S f'‖≤ε:=mean_error S f f' ε hε.le + (fun x hx=>hpoint x (Finset.mem_union_left U hx)) + have hu : ‖mean U f-mean U f'‖≤ε:=mean_error U f f' ε hε.le + (fun x hx=>hpoint x (Finset.mem_union_right S hx)) + have h₁:=norm_sub_le (mean S f-mean S f') (mean U f-mean S f') + have h₂:=norm_sub_le (mean U f-mean U f') (mean S f'-mean U f') + have he₁ : (mean S f-mean S f')-(mean U f-mean S f')=mean S f-mean U f:=by ring + have he₂ : (mean U f-mean U f')-(mean S f'-mean U f')=mean U f-mean S f':=by ring + rw [he₁] at h₁ + rw [he₂] at h₂ + change η≤‖mean S f-mean U f‖ at hd + change η-2*ε≤‖mean S f'-mean U f'‖ + linarith + +end RoughKernelFactorization +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughSamplingWeights +open FinitePieceAverages +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def rescaledEndpoint (v : ι → ℝ) (u : ι → ℤ) (K : ℕ) : ι → ℝ:= + fun i=>(v i-u i)/K + +def integerAffine (u : ι → ℤ) (K : ℕ) (y : ι → ℤ) : ι → ℤ:= + fun i=>u i+(K:ℤ)*y i + +lemma rescaled_box (lo hi : ι → ℝ) (u : ι → ℤ) (K : ℕ) (hK : 0(u i:ℝ)) K= + boxIndices (rescaledEndpoint lo u K) (rescaledEndpoint hi u K) (fun _=>0) 1 := by + have hKr : 0<(K:ℝ):=by exact_mod_cast hK + ext y + rw [mem_boxIndices _ _ _ _ hKr,mem_boxIndices _ _ _ _ zero_lt_one] + apply forall_congr' + intro i + simp only [rescaledEndpoint,zero_add,one_mul,div_le_iff₀ hKr,lt_div_iff₀ hKr] + constructor <;> rintro ⟨h₁,h₂⟩ <;> constructor <;> nlinarith + + + +def physicalResidueBox (lo hi : ι → ℝ) (u : ι → ℤ) (K : ℕ) : Finset (ι → ℤ):= + (boxIndices lo hi (fun _=>0) 1).filter (fun x=>∀ i,x i ≡ u i [ZMOD K]) + +lemma physical_residue_reparametrization (lo hi : ι → ℝ) (u : ι → ℤ) + (K : ℕ) (hK : 00) 1).image + (integerAffine u K) := by + have he : physicalResidueBox lo hi u K=refinedSet lo hi (fun _=>0) 1 u K:=by + ext x + rw [physicalResidueBox,Finset.mem_filter,mem_boxIndices _ _ _ _ zero_lt_one, + mem_refinedSet _ _ _ _ zero_lt_one _ _ hK] + simp only [zero_add,one_mul] + exact forall_and.symm + rw [he,refinedSet] + simp only [zero_add,one_mul] + rw [rescaled_box lo hi u K hK] + rfl + +lemma mean_image {α β : Type*} [DecidableEq β] (s : Finset α) (e : α → β) + (he : Function.Injective e) (f : β → ℂ) : + mean (s.image e) f=mean s (fun x=>f (e x)) := by + rw [mean,Finset.card_image_of_injective _ he,Finset.sum_image] + · rfl + · intro a _ b _ hab + exact he hab + + +theorem residue_mean (lo hi : ι → ℝ) (u : ι → ℤ) (K : ℕ) (hK : 00) 1) + (fun y=>f (integerAffine u K y)) := by + rw [physical_residue_reparametrization lo hi u K hK] + exact mean_image _ _ (affine_injective u K hK) f + + + +omit [Fintype ι] [DecidableEq ι] in +theorem residual_congruences (u a : ι → ℤ) (K t : ℕ) (h : K.Coprime t) : + ∃ b : ι → ℤ,∀ y : ι → ℤ, + (∀ i,integerAffine u K y i ≡ a i [ZMOD t]) ↔ ∀ i,y i ≡ b i [ZMOD t] := by + choose b hb using fun i=>residue_parameter K t h (u i) (a i) + exact ⟨b,fun y=>forall_congr' (fun i=>hb i (y i))⟩ + + + +theorem residual_mean (u a : ι → ℤ) (K t : ℕ) (hK : 0∀ i,x i ≡ a i [ZMOD t])) f= + mean ((boxIndices (rescaledEndpoint lo u K) (rescaledEndpoint hi u K) (fun _=>0) 1).filter + (fun y=>∀ i,y i ≡ b i [ZMOD t])) (fun y=>f (integerAffine u K y)) := by + classical + obtain ⟨b,hb⟩:=residual_congruences u a K t h + refine ⟨b,fun lo hi f=>?_⟩ + rw [physical_residue_reparametrization lo hi u K hK,Finset.filter_image] + have hp : (fun y : ι → ℤ=>∀ i,integerAffine u K y i ≡ a i [ZMOD t])= + (fun y : ι → ℤ=>∀ i,y i ≡ b i [ZMOD t]):=funext (fun y=>propext (hb y)) + simp only [hp] + exact mean_image _ _ (affine_injective u K hK) f + + + +omit [Fintype ι] [DecidableEq ι] in +theorem rescaled_geometry (lo hi : ι → ℝ) (u : ι → ℤ) (K : ℕ) (hK : 0F i^e):=by + conv_lhs => rw [p.as_sum] + simp only [MvPolynomial.eval₂_sum,MvPolynomial.eval₂_monomial] + rw [he] + apply MvPolynomial.totalDegree_finsetSum_le + intro s hs + calc + _≤(MvPolynomial.C (p.coeff s) : MvPolynomial τ ℝ).totalDegree+ + (s.prod (fun i e=>F i^e)).totalDegree:=MvPolynomial.totalDegree_mul _ _ + _=(s.prod (fun i e=>F i^e)).totalDegree:=by simp + _≤∑ i∈s.support,(F i^s i).totalDegree:=MvPolynomial.totalDegree_finsetProd _ _ + _≤∑ i∈s.support,s i:=by + apply Finset.sum_le_sum + intro i _ + exact (MvPolynomial.totalDegree_pow (F i) (s i)).trans (by simpa using Nat.mul_le_mul_left (s i) (hF i)) + _≤p.totalDegree:=MvPolynomial.le_totalDegree hs + + + +theorem affine_comp {f : (σ → ℝ) → ℝ} {d : ℕ} (hf : HasDegree f d) + (a b : σ → ℝ) (θ : σ → τ) : + HasDegree (fun x : τ → ℝ=>f (fun i=>a i+b i*x (θ i))) d := by + obtain ⟨p,hp,he⟩:=hf + let F : σ → MvPolynomial τ ℝ:=fun i=>MvPolynomial.C (a i)+MvPolynomial.C (b i)*MvPolynomial.X (θ i) + have hF : ∀ i,(F i).totalDegree≤1:=by + intro i + apply (MvPolynomial.totalDegree_add _ _).trans + apply max_le + · simp [MvPolynomial.totalDegree_C] + · exact (MvPolynomial.totalDegree_mul _ _).trans (by simp) + refine ⟨MvPolynomial.eval₂ MvPolynomial.C F p,(affine_substitution_totalDegree p F hF).trans hp,?_⟩ + intro x + dsimp only + rw [he] + clear hp he + induction p using MvPolynomial.induction_on with + | C c=>simp + | add p q hp hq=>simpa only [MvPolynomial.eval₂_add,MvPolynomial.eval_add] using congrArg₂ (·+·) hp hq + | mul_X p i hp=>simp [F,MvPolynomial.eval₂_mul,MvPolynomial.eval₂_X,MvPolynomial.eval_mul,hp] + +end RealPolynomialDegree + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughSplit01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughSplit01.lean new file mode 100644 index 0000000000000000000000000000000000000000..23b37f94ebba8822d418576aee315a78efa19ff0 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughSplit01.lean @@ -0,0 +1,344 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughKernel05 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughCommonKernelCover +open RationalLattice MalcevCharacters RoughKernelFactorization RealPolynomialDegree +open RoughKernelCover +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G→*Multiplicative ℝ) (Γ : Subgroup G) (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +include hΓ in + + +theorem common_kernel_cover : + ∃ Λ : Subgroup χ.ker,∃ e : RealCoordinates χ.ker n,SecondKind e ∧ + (∀ g : χ.ker,g∈Λ ↔ ∀ i,∃ z : ℤ,e.coord g i=z) ∧ + (∀ j : Fin R.period,Λ≤kernelLattice χ Γ (residueSigma c hsk χ Γ R j)) ∧ + ∃ E : ℕ,0canonicalLog (R.chart c hsk χ Γ) (P x) i) D) → + ∀ i,HasDegree (fun x=>canonicalLog e (P x) i) (E*D) := by + classical + let d:=R.chart c hsk χ Γ + have hpoly (j : Fin R.period) : ∀ i,RationalPolynomialMap.IsPolynomial (fun x : Fin n→ℝ=> + c.coord (kernelInclusion χ (residueSigma c hsk χ Γ R j) (d.coord.symm x)) i):=by + apply kernel_embedding_polynomial c hsk χ Γ R + simpa only [residueSigma,Rat.cast_natCast] using R.flow_rational c hsk χ Γ (j.val:ℚ) + choose A hA hgrid using fun j=>rationalHom_origin_grid c d + (kernelInclusion χ (residueSigma c hsk χ Γ R j)) (hpoly j) + let T:=∏ j,A j + have hT : 0hA j) + obtain ⟨w,hw,hTw,hcl⟩:=exists_lattice_weights d T hT + let Λ:=weightedLattice d w hcl + let d':=scaledCoordinates d w hw + let e:=secondCoordinates d' + have hΛ : ∀ g : χ.ker,g∈Λ ↔ ∀ i,∃ z : ℤ,d'.coord g i=z:=weightedLattice_iff d w hcl hw + have hle (j : Fin R.period) : Λ≤kernelLattice χ Γ (residueSigma c hsk χ Γ R j):=by + intro g hg + apply (hΓ _).mpr + have hAw (i) : A j∣w i:=(Finset.dvd_prod_of_mem A (Finset.mem_univ j)).trans (hTw i) + have hx : ∀ i,∃ z : ℤ,d.coord g i=(A j:ℝ)*(z:ℝ):=by + intro i + obtain ⟨a,ha⟩:=hg i + obtain ⟨b,hb⟩:=hAw i + refine ⟨(b:ℤ)*a,?_⟩ + rw [ha,hb] + push_cast + ring + simpa using hgrid j (d.coord g) hx + have he : ∀ i,RationalPolynomialMap.IsPolynomial (fun x : Fin n→ℝ=>e.coord (d.coord.symm x) i):=by + intro i + apply polynomial_expCoordinates d' + intro j + change RationalPolynomialMap.IsPolynomial (fun x : Fin n→ℝ=>d.coord (d.coord.symm x) j/(w j:ℝ)) + simpa only [Homeomorph.apply_symm_apply,div_eq_mul_inv,Rat.cast_inv,Rat.cast_natCast] using + RationalPolynomialMap.mul (RationalPolynomialMap.coordinate j) (RationalPolynomialMap.const (w j:ℚ)⁻¹) + obtain ⟨C,hC,hcoord⟩:=coord_degree_bound d + obtain ⟨L,hL,hlog⟩:=log_degree_bound e + obtain ⟨U,hU,htransfer⟩:=rational_map_bound (fun i x=>e.coord (d.coord.symm x) i) he + refine ⟨Λ,e,secondCoordinates_secondKind d',expCoordinates_lattice d' Λ hΛ,hle, + L*(U*C),Nat.mul_pos hL (Nat.mul_pos hU hC),?_⟩ + intro v D P hP i + have hc:=hcoord v D P hP + have ht : ∀ j,HasDegree (fun x=>e.coord (P x) j) (U*(C*D)):=by + intro j + simpa only [Homeomorph.symm_apply_apply] using htransfer v (C*D) (fun j x=>d.coord (P x) j) hc j + simpa only [Nat.mul_assoc] using hlog v (U*(C*D)) P ht i + +end RoughCommonKernelCover + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughCommonKernelDiscrepancy +open RationalLattice MalcevCharacters RoughKernelFactorization UniformSlowPolynomials +open RoughSamplingWeights FinitePieceAverages RoughKernelDiscrepancy RoughCoverTests +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G→*Multiplicative ℝ) (Γ : Subgroup G) (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable (hcont : Continuous χ) (hZint : ∀ g∈Γ,∃ z : ℤ,(χ g).toAdd=z) +variable (Λ : Subgroup χ.ker) (d : RealCoordinates χ.ker n) +variable (hΛ : ∀ g : χ.ker,g∈Λ ↔ ∀ i,∃ z : ℤ,d.coord g i=z) +variable (hle : ∀ j : Fin R.period,Λ≤kernelLattice χ Γ (residueSigma c hsk χ Γ R j)) +variable {X : Type*} [PseudoMetricSpace X] (V : (G⧸Γ) ≃ₜ X) +variable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] +include hΓ hcont hZint hle in + +theorem source_common_kernel_discrepancy (e : κ→ι→ℕ) (A C side B : ℝ) + (hA : 0≤A) (hC : 0≤C) (hside : 0(x i:ℝ))))* + (Q x).val*R.flow c hsk χ Γ (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ))) → + ∀ η : ℝ,η≤‖mean (boxIndices lo hi (fun _=>0) 1) (fun x=>F (V (QuotientGroup.mk (P x))))- + mean (physicalResidueBox lo hi res t) (fun x=>F (V (QuotientGroup.mk (P x))))‖ → + ∃ u : ι→Fin R.period,∃ (lo' hi' : ι→ℝ) (res' : ι→ℤ) (g : (χ.ker⧸Λ)→ℂ), + LipschitzWith L' g ∧ (∀ y,‖g y‖≤L') ∧ + (∀ i,-(C+1)*(Z/R.period)≤lo' i ∧ hi' i≤(C+1)*(Z/R.period)) ∧ + (∀ i,(side/M)*(Z/R.period)≤hi' i-lo' i) ∧ + η-7*ε≤‖mean (boxIndices lo' hi' (fun _=>0) 1) + (fun y=>g (QuotientGroup.mk (Q (integerAffine (fun i=>((u i).val:ℤ)) R.period y))))- + mean (physicalResidueBox lo' hi' res' t) + (fun y=>g (QuotientGroup.mk (Q (integerAffine (fun i=>((u i).val:ℤ)) R.period y))))‖ := by + classical + let :=coordinateQuotientMetric d Λ hΛ + obtain ⟨M,hM,L₀,δ,hδ,hsrc⟩:=source_kernel_discrepancy c hsk χ Γ R hΓ hcont hZint V + e A C side B hA hC hside hB L ε hε + have hall (j : Fin R.period) : + let σ:=residueSigma c hsk χ Γ R j + letI :=kernelCompatibleMetric χ Γ σ c hsk R hΓ hcont hZint + ∃ L₁ : NNReal,∀ F : (χ.ker⧸kernelLattice χ Γ σ)→ℂ,LipschitzWith L₀ F → + (∀ y,‖F y‖≤B+ε) →∃ g : (χ.ker⧸Λ)→ℂ,LipschitzWith L₁ g ∧ (∀ y,‖g y‖≤B+ε+ε) ∧ + ∀ (S T : Finset (ι→ℤ)) (P : (ι→ℤ)→χ.ker) (η : ℝ), + η≤‖mean S (fun x=>F (QuotientGroup.mk (P x)))-mean T (fun x=>F (QuotientGroup.mk (P x)))‖ → + η-2*ε≤‖mean S (fun x=>g (QuotientGroup.mk (P x)))-mean T (fun x=>g (QuotientGroup.mk (P x)))‖:=by + let σ:=residueSigma c hsk χ Γ R j + let :=kernelCompatibleMetric χ Γ σ c hsk R hΓ hcont hZint + obtain ⟨K,hK⟩:=uniform_cover_tests d Λ (kernelLattice χ Γ σ) hΛ (hle j) (Homeomorph.refl _) + L₀ (B+ε) ε (by linarith) hε + refine ⟨K,?_⟩ + intro F hF hFB + obtain ⟨g,hg,hgB,hd⟩:=hK F hF hFB + exact ⟨g,hg,hgB,hd (ι→ℤ)⟩ + choose L₁ hL₁ using hall + let L' : NNReal:=max (Finset.univ.sup L₁) ⟨B+ε+ε,by linarith⟩+1 + have hpos : 0(hfB y).trans hB',hbox',hside'',?_⟩ + have hh:=hfd (boxIndices lo' hi' (fun _=>0) 1) (physicalResidueBox lo' hi' res' t) + (fun y=>Q (integerAffine (fun i=>((u i).val:ℤ)) R.period y)) (η-5*ε) hbad' + linarith + +end RoughCommonKernelDiscrepancy + +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace RoughSplitBlockReduction +open RationalLattice MalcevCharacters RoughKernelFactorization RealPolynomialDegree +open RoughBadBlock RoughRationalKernel RoughRationalBlock RoughScales +open RoughCharacterThinning RoughCommonKernelDiscrepancy RoughCommonKernelCover +open RoughSamplingWeights FinitePieceAverages PolynomialLineCoefficients CorrectedBoxLeibman + +lemma spatial_affine {v d : ℕ} {f : (Fin (v+1)→ℝ)→ℝ} (hf : HasDegree f d) + (u : Fin v→ℝ) (K : ℝ) : + HasDegree (fun y : Fin (v+1)→ℝ=>f (Fin.cons (y 0) (fun i=>u i+K*(Fin.tail y i)))) d:=by + let T (y : Fin (v+1)→ℝ) : Fin (v+1)→ℝ:=Fin.cons (y 0) (fun j=>u j+K*(Fin.tail y j)) + have hg (i : Fin (v+1)) : HasDegree (fun y=>T y i) 1:=by + refine Fin.cases ?_ (fun j=>?_) i + · exact RoughPolynomialDegree.coordinate (0 : Fin (v+1)) + · simpa only [T,Fin.cons_succ,Fin.tail,max_self] using RealPolynomialDegree.add + (RealPolynomialDegree.const (σ:=Fin (v+1)) (u j) 1) + (RealPolynomialDegree.scale (RoughPolynomialDegree.coordinate j.succ) K) + have h:=RoughPolynomialDegree.compose hf (fun i y=>T y i) hg + simpa only [one_mul,T] using h + +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G→*Multiplicative ℝ) (Γ : Subgroup G) (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable (hcont : Continuous χ) (hZint : ∀ g∈Γ,∃ z : ℤ,(χ g).toAdd=z) +variable [mtr : MetricSpace (G⧸Γ)] +variable (htop : mtr.toUniformSpace.toTopologicalSpace=QuotientGroup.instTopologicalSpace Γ) +local instance : TopologicalSpace (G⧸Γ):=mtr.toUniformSpace.toTopologicalSpace + +private def metricIdentity : + @Homeomorph (G⧸Γ) (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) mtr.toUniformSpace.toTopologicalSpace := by + refine @Homeomorph.mk _ _ (QuotientGroup.instTopologicalSpace Γ) mtr.toUniformSpace.toTopologicalSpace + (Equiv.refl _) ?_ ?_ + · rw [htop]; exact @continuous_id (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) + · rw [htop]; exact @continuous_id (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) + +include hΓ hcont hZint htop in + + +theorem reduce_split_blocks (v D s : ℕ) (c₀ C₀ A : ℝ) (B : NNReal) (η : ℝ) + (hc₀ : 0(θ I).eval z) x=(χ (b₀.P (Fin.cons z x))).toAdd) → + Split w N Z A θ 0 1 M → + Nonempty (Block d Λ v D' c' (C₀+1) B' (η/2) w S (Z/R.period) H) := by + classical + obtain ⟨Λ,d,hd,hΛ,hle,E,hE,hdegree⟩:=common_kernel_cover c hsk χ Γ R hΓ + let :=coordinateQuotientMetric d Λ hΛ + obtain ⟨J,hJ,hkernel⟩:=kernel_polynomial c hsk χ Γ R + let ε : ℝ:=η/14 + have hε : 0<ε:=by dsimp [ε]; positivity + obtain ⟨M₀,hM₀,B',hB',δ,hδ,hdisc⟩:=source_common_kernel_discrepancy c hsk χ Γ R hΓ hcont hZint + Λ d hΛ hle (metricIdentity Γ htop) (fun (I : PolynomialLineCoefficients.Grid v s) i=>(I i).val) + A C₀ c₀ (B:ℝ) hA hC₀.le hc₀ B.coe_nonneg B ε hε + let D':=E*(J*max D ((v+1)*s+v*s)) + refine ⟨Λ,d,hd,hΛ,D',c₀/(M₀:ℝ),div_pos hc₀ (by exact_mod_cast hM₀),B',hB',δ,hδ,?_⟩ + intro H hH + obtain ⟨N,hN⟩:=ConstantCoefficientRationalization.finite_van_der_waerden + (Fintype.card (Fin v→Fin R.period)) H + refine ⟨N,?_⟩ + intro w S Z hw hwp hS hZ hsmall b₀ θ M hθ he hM + obtain ⟨Q,hQP,hQdeg⟩:=hkernel v D s b₀.P θ M b₀.degree hθ hM.1 he + have hQd : ∀ i,HasDegree (fun y=>canonicalLog d (Q y) i) D':= + hdegree (v+1) _ Q hQdeg + have hfib (j : Fin (N+1)) : + ∃ u : Fin v→Fin R.period,∃ (lo hi : Fin v→ℝ) (res : Fin v→ℤ) (f : (χ.ker⧸Λ)→ℂ), + LipschitzWith B' f ∧ (∀ y,‖f y‖≤B') ∧ + (∀ i,-(C₀+1)*(Z/R.period)≤lo i ∧ hi i≤(C₀+1)*(Z/R.period)) ∧ + (∀ i,(c₀/M₀)*(Z/R.period)≤hi i-lo i) ∧ + η/2≤‖mean (boxIndices lo hi (fun _=>0) 1) + (fun y=>f (QuotientGroup.mk (Q (Fin.cons (j.val:ℝ) + (fun i=>((integerAffine (fun i=>((u i).val:ℤ)) R.period y i:ℤ):ℝ))))))- + mean (physicalResidueBox lo hi res (b₀.start+b₀.step*(j.val:ℤ)).natAbs) + (fun y=>f (QuotientGroup.mk (Q (Fin.cons (j.val:ℝ) + (fun i=>((integerAffine (fun i=>((u i).val:ℤ)) R.period y i:ℤ):ℝ))))))‖:=by + have hj : (j.val:ℤ)≤N:=by exact_mod_cast Nat.le_of_lt_succ j.isLt + have hscale:=b₀.scales (j.val:ℤ) (by positivity) hj + have htpos : 0<(b₀.start+b₀.step*(j.val:ℤ):ℤ):=by exact_mod_cast hS.trans_le hscale.1 + have hcast : (((b₀.start+b₀.step*(j.val:ℤ)).natAbs:ℕ):ℝ)=((b₀.start+b₀.step*(j.val:ℤ):ℤ):ℝ):=by + simp only [Nat.cast_natAbs,abs_of_nonneg (by exact_mod_cast htpos.le)] + have htK : (b₀.start+b₀.step*(j.val:ℤ)).natAbs.Coprime R.period:= + (period_coprime_of_rough w R.period _ R.period_pos hwp + ((rough_iff_coprime w _).mp (b₀.rough _ (by positivity) hj))).symm + obtain ⟨m,hm⟩:=integer_spatial_on_lattice M j.val (fun I=>hM.2.2.1 I j.val (by omega)) + have hfactor (x : Fin v→ℤ) : + b₀.P (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ)))= + R.flow c hsk χ Γ (Multiplicative.ofAdd (UniformSlowPolynomials.form + (fun (I : PolynomialLineCoefficients.Grid v s) i=>(I i).val) + (errorCoefficients θ M (j.val:ℝ)) (fun i=>(x i:ℝ))))* + (Q (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ)))).val* + R.flow c hsk χ Γ (Multiplicative.ofAdd ((MvPolynomial.eval x m:ℤ):ℝ)):=by + rw [hm] + exact hQP _ + obtain ⟨u,lo,hi,res,f,hf,hfB,hbox,hside,hbad⟩:=hdisc Z hZ + (errorCoefficients θ M (j.val:ℝ)) (split_error_bound hM j.val (by omega)) + (b₀.lo j) (b₀.hi j) (by simpa only [neg_mul] using b₀.box j) (b₀.side j) + (b₀.res j) _ (Int.natAbs_pos.mpr htpos.ne') htK (by rw [hcast]; linarith) + (b₀.test j) (b₀.lip j) (b₀.bound j) + (fun x=>b₀.P (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ)))) + (fun x=>Q (Fin.cons (j.val:ℝ) (fun i=>(x i:ℝ)))) m hfactor η (b₀.bad j) + refine ⟨u,lo,hi,res,f,hf,hfB,hbox,hside,?_⟩ + convert hbad using 1; dsimp [ε]; ring + choose u lo hi res f hf hfB hbox hside hbad using hfib + let e:=Fintype.equivFin (Fin v→Fin R.period) + obtain ⟨a,b,hb,hab,hmono⟩:=hN (fun j=>e (u j)) + let j₀ : Fin (N+1):=⟨a,Nat.lt_succ_of_le ((Nat.le_add_right _ _).trans hab)⟩ + have hu (j : Fin (H+1)) : u (progressionIndex a b hab j)=u j₀:=e.injective (hmono j) + have hbN : b≤N:=by nlinarith + have hsm : Smooth w (b₀.step*(b:ℤ)):=smooth_mul b₀.smooth + (smooth_of_abs_le (by exact_mod_cast hb.ne') (by simpa using hbN.trans hw)) + let b₁:=b₀.affine a b hb hab hsm + let P' : (Fin (v+1)→ℝ)→χ.ker:=fun y=>Q + (Fin.cons ((a:ℝ)+(b:ℝ)*y 0) (fun i=>((u j₀ i).val:ℝ)+(R.period:ℝ)*(Fin.tail y i))) + have hP' (i) : HasDegree (fun y=>canonicalLog d (P' y) i) D':=by + simpa only [Fin.cons_zero,Fin.tail_cons] using + RoughPolynomialDegree.time_affine (spatial_affine (hQd i) (fun i=>((u j₀ i).val:ℝ)) R.period) a b + refine ⟨{ + start:=b₁.start + step:=b₁.step + positive:=b₁.positive + smooth:=b₁.smooth + scales:=b₁.scales + rough:=b₁.rough + P:=P' + degree:=hP' + lo:=fun j=>lo (progressionIndex a b hab j) + hi:=fun j=>hi (progressionIndex a b hab j) + res:=fun j=>res (progressionIndex a b hab j) + test:=fun j=>f (progressionIndex a b hab j) + side:=fun j=>hside _ + box:=fun j=>hbox _ + lip:=fun j=>hf _ + bound:=fun j=>hfB _ + bad:=?_ }⟩ + intro j + have heq : b₁.start+b₁.step*(j.val:ℤ)=b₀.start+b₀.step*((progressionIndex a b hab j).val:ℤ):=by + simp only [b₁,Block.affine,progressionIndex_val,Nat.cast_add,Nat.cast_mul] + ring + simpa only [P',Fin.cons_zero,Fin.tail_cons,integerAffine,hu j,Int.cast_add,Int.cast_mul, + Int.cast_natCast,progressionIndex_val,Nat.cast_add,Nat.cast_mul,heq] + using hbad (progressionIndex a b hab j) + +end RoughSplitBlockReduction + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological01.lean new file mode 100644 index 0000000000000000000000000000000000000000..095ce6bc719c01d31976ed746968a24223ab2410 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological01.lean @@ -0,0 +1,364 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughCovered02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end +end + +section +noncomputable section +namespace RoughCoveredFace +open RationalLattice MalcevCharacters RealPolynomialDegree + + + +theorem grid_second_degree_cover {G : Type} [Group G] [TopologicalSpace G] + [IsTopologicalGroup G] {dim : ℕ} (c : RealCoordinates G dim) (Γ : Subgroup G) + (grid : ℕ) (hgridpos : 0canonicalLog c (P x) i) D) → + ∀ i,HasDegree (fun x=>canonicalLog e (P x) i) (E*D) := by + classical + obtain ⟨w,hw,hgw,hcl⟩:=exists_lattice_weights c grid hgridpos + let Λ:=weightedLattice c w hcl + let d:=scaledCoordinates c w hw + have hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,d.coord g i=z := + weightedLattice_iff c w hcl hw + have hle : Λ≤Γ := by + intro g hg + apply hgrid g + intro i + obtain ⟨a,ha⟩:=hg i + obtain ⟨b,hb⟩:=hgw i + refine ⟨(b:ℤ)*a,?_⟩ + rw [ha,hb] + push_cast + ring + let e:=secondCoordinates d + have he : ∀ i,RationalPolynomialMap.IsPolynomial + (fun x : Fin dim→ℝ=>e.coord (c.coord.symm x) i) := by + intro i + apply polynomial_expCoordinates d + intro j + change RationalPolynomialMap.IsPolynomial + (fun x : Fin dim→ℝ=>c.coord (c.coord.symm x) j/(w j:ℝ)) + simpa only [Homeomorph.apply_symm_apply,div_eq_mul_inv,Rat.cast_inv,Rat.cast_natCast] using + RationalPolynomialMap.mul (RationalPolynomialMap.coordinate j) + (RationalPolynomialMap.const (w j:ℚ)⁻¹) + obtain ⟨C,hC,hcoord⟩:=coord_degree_bound c + obtain ⟨L,hL,hlog⟩:=log_degree_bound e + obtain ⟨T,hT,htransfer⟩:=rational_map_bound (fun i x=>e.coord (c.coord.symm x) i) he + refine ⟨Λ,e,secondCoordinates_secondKind d,expCoordinates_lattice d Λ hΛ,hle, + L*(T*C),Nat.mul_pos hL (Nat.mul_pos hT hC),?_⟩ + intro v D P hP i + have hc:=hcoord v D P hP + have ht : ∀ j,HasDegree (fun x=>e.coord (P x) j) (T*(C*D)) := by + intro j + simpa only [Homeomorph.symm_apply_apply] using + htransfer v (C*D) (fun j x=>c.coord (P x) j) hc j + simpa only [Nat.mul_assoc] using hlog v (T*(C*D)) P ht i + +end RoughCoveredFace +end +end + +section + +section +noncomputable section +namespace RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw ProductExposureCutoff MeasureTheory +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable + + +theorem source_raw_face_grid_decay {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} + (Γ : Subgroup G) [MetricSpace (G⧸Γ)] [IsTopologicalGroup G] + (c : RealCoordinates G dim) (grid : ℕ) (hgridpos : 0X n j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ n,0R n/(Xp n:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R n/(M n:ℝ))/ + (1+∑ j,(X n j:ℝ)^2)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/(R n/(M n:ℝ))) atTop (𝓝 0)) + (hWM : ∀ n,(primorial (w n):ℤ)∣(M n:ℤ)) + (hM : ∀ n,0(X n j:ℝ)/(L n:ℝ)) atTop atTop) + (F : ℕ→Label m→FaceData m v G Γ) + (hF : ∀ n b,b∈(fullDomain (X n) (Xp n) (primorial (w n))).image + (expose (L n) (M n:ℤ) (R n)) → Good (X n) (Xp n) (R n) b → + FaceData.Valid c D d K (H n) (L n) b (F n b)) : + Tendsto (fun n=>(jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) + (hX n) (hXp n)).real (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n))) + atTop (𝓝 0) + := by + obtain ⟨Λ,e,he,hΛ,hle,E,hE,hdeg⟩:=grid_second_degree_cover c Γ grid hgridpos hgrid + apply source_raw_face_cover_decay Λ Γ e he hle hΛ htop m v (E*D) d hd c₀ C₀ B K η + hc₀ hC₀ hB hη w M Xp X R H L hw hX hXp hXt hXpt hR hRX hZ hH hHZ + hWM hM hMs hL hsm hWL hXL F + intro n b hb hg + obtain ⟨hP,hσ,hh,hface⟩:=hF n b hb hg + exact ⟨hdeg (m+v) D (F n b).P hP,hσ,hh,hface⟩ + +end RoughCoveredFace +end +end +end + +section + +noncomputable section +namespace RoughTopologicalFace +open RoughFaceShift RationalLattice MalcevCharacters RealPolynomialDegree RoughProductRemoval + + +def TopologicalValid {m v : ℕ} {G : Type} [Group G] [TopologicalSpace G] + {Γ : Subgroup G} [MetricSpace (G⧸Γ)] {dim : ℕ} (c : RealCoordinates G dim) + (D d : ℕ) (H : ℝ) (L : ℤ) (b : ProductExposureLabels.Label m) + (σ₀ : C(G⧸Γ,G⧸Γ)) (F : FaceData m v G Γ) : Prop := + (∀ i,HasDegree (fun y=>canonicalLog c (F.P y) i) D) ∧ + F.σ=σ₀ ∧ + (∀ t∈productTimes b.scales b.residue L,∀ i,(d:ℤ)∣F.h t i ∧ |(F.h t i:ℝ)|≤H) ∧ + (∀ t∈productTimes b.scales b.residue L,∀ x : Fin v→ℤ, + F.σ (QuotientGroup.mk (F.P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (F.P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+F.h t i:ℤ):ℝ))))) +end RoughTopologicalFace +end + +end + +section + +noncomputable section +namespace RoughTopologicalFace +open RoughFaceShift RationalLattice MalcevCharacters RealPolynomialDegree RoughProductRemoval +open FinitePieceAverages +open scoped BigOperators Topology + + + +def Approximable {X : Type*} [MetricSpace X] (B K : NNReal) (η : ℝ) + (σ : X→X) : Prop := + ∀ f : X→ℂ,LipschitzWith B f → (∀ x,‖f x‖≤B) → + ∃ g : X→ℂ,LipschitzWith K g ∧ (∀ x,‖g x‖≤K) ∧ + ∀ x,‖f (σ x)-g x‖≤η/8 + + + +theorem continuous_approximable {X : Type} [MetricSpace X] [CompactSpace X] + [Nonempty X] (σ : C(X,X)) (B : NNReal) (η : ℝ) (hη : 0<η) : + ∃ K : NNReal,Approximable B K η σ := by + let H : C(PUnit.{1}×X,X):=σ.comp ContinuousMap.snd + obtain ⟨L,hL⟩:=UniformLipschitzApproximation.compact_pullback_complex + H B B B.2 (η/8) (by positivity) + let e : NNReal:=⟨η/8,by positivity⟩ + let K : NNReal:=L+B+e+1 + have hLK : L≤K := by + change (L:ℝ)≤(L:ℝ)+(B:ℝ)+η/8+1 + linarith [B.2] + have hBK : (B:ℝ)+η/8≤(K:ℝ) := by + change (B:ℝ)+η/8≤(L:ℝ)+(B:ℝ)+η/8+1 + linarith [L.2] + refine ⟨K,?_⟩ + intro f hf hB + obtain ⟨g,hg,herr,hgB⟩:=hL PUnit.unit f hf hB + refine ⟨g,hg.weaken hLK,fun x=>(hgB x).trans hBK,?_⟩ + intro x + rw [norm_sub_rev] + simpa only [H,ContinuousMap.comp_apply,ContinuousMap.snd_apply] using (herr x).le + + + +theorem Approximable.compare {X α : Type*} [MetricSpace X] {B K : NNReal} + {η : ℝ} {σ : X→X} (hσ : Approximable B K η σ) (hη : 0<η) + (S T : Finset α) (P : α→X) + (hcompare : ∀ g : X→ℂ,LipschitzWith K g → (∀ x,‖g x‖≤K) → + ‖mean S (fun x=>g (P x))-mean T (fun x=>g (P x))‖<η/4) + (f : X→ℂ) (hf : LipschitzWith B f) (hfB : ∀ x,‖f x‖≤B) : + ‖mean S (fun x=>f (σ (P x)))-mean T (fun x=>f (σ (P x)))‖<η/2 := by + obtain ⟨g,hg,hgB,herr⟩:=hσ f hf hfB + have hS:=mean_error S (fun x=>f (σ (P x))) (fun x=>g (P x)) + (η/8) (by positivity) (fun x _=>herr (P x)) + have hT:=mean_error T (fun x=>f (σ (P x))) (fun x=>g (P x)) + (η/8) (by positivity) (fun x _=>herr (P x)) + have hmid:=hcompare g hg hgB + have htri:=norm_sub_le_norm_sub_add_norm_sub + (mean S (fun x=>f (σ (P x)))) (mean S (fun x=>g (P x))) + (mean T (fun x=>f (σ (P x)))) + have htri':=norm_sub_le_norm_sub_add_norm_sub + (mean S (fun x=>g (P x))) (mean T (fun x=>g (P x))) + (mean T (fun x=>f (σ (P x)))) + rw [norm_sub_rev (mean T (fun x=>g (P x)))] at htri' + linarith + + +def ApproxValid {m v : ℕ} {G : Type} [Group G] [TopologicalSpace G] + {Γ : Subgroup G} [MetricSpace (G⧸Γ)] {dim : ℕ} (c : RealCoordinates G dim) + (D d : ℕ) (B K : NNReal) (η H : ℝ) (L : ℤ) (b : ProductExposureLabels.Label m) + (F : FaceData m v G Γ) : Prop := + (∀ i,HasDegree (fun y=>canonicalLog c (F.P y) i) D) ∧ + Approximable B K η F.σ ∧ + (∀ t∈productTimes b.scales b.residue L,∀ i,(d:ℤ)∣F.h t i ∧ |(F.h t i:ℝ)|≤H) ∧ + (∀ t∈productTimes b.scales b.residue L,∀ x : Fin v→ℤ, + F.σ (QuotientGroup.mk (F.P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (F.P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+F.h t i:ℤ):ℝ))))) + +end RoughTopologicalFace +end + +end + +section + + +section +noncomputable section +namespace RoughTopologicalFace +open RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + + +theorem source_face_decay (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0S n j) atTop atTop) + (hZ : ∀ a : ℝ,0Z n/(1+∑ j,S n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z n) atTop (𝓝 0)) + (hM : ∀ n,0S n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),Approximable B K η σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes (S n) (r n) (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes (S n) (r n) (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + ((exceptionalFace Γ m v c₀ C₀ B η (Z n) d (M n) A P σ (S n) (r n) (L n)).card:ℝ)/ + ((productTimes (S n) (r n) (L n)).card:ℝ)<ε := by + classical + let B' : NNReal := B+K+1 + have hB' : 01) (T:=fun n=>totalScale (S n)) + (by filter_upwards [] with n; norm_num) (totalScale_pos_eventually S hS) hZ + simpa using h 1 zero_lt_one + have herr : Tendsto (fun n=>(8*(B:ℝ)*(v:ℝ)/c₀)*(H n/Z n)) atTop (𝓝 0) := by + simpa using hHZ.const_mul (8*(B:ℝ)*(v:ℝ)/c₀) + intro ε hε + have hp := source_product_cover_decay c Γ Λ hle hsk hΛ htop m v D d hd c₀ C₀ B' (η/4) + hc₀ hC₀ hB' (by positivity) w M S Z r L hw hS hZ hM hMs hL hsm hWL hr hSL ε hε + filter_upwards [hp,hz.eventually (eventually_ge_atTop (4*(d:ℝ)/c₀)), + herr.eventually (gt_mem_nhds (by positivity : (0:ℝ)<η/4))] with n hpn hzn hen + intro A P hP σ hσ h hh hid + have hW : 4*(d:ℝ)≤c₀*Z n := by + have ht := (div_le_iff₀ hc₀).mp hzn + nlinarith + have hsub : exceptionalFace Γ m v c₀ C₀ B η (Z n) d (M n) A P σ (S n) (r n) (L n) ⊆ + exceptionalProduct Γ m v c₀ C₀ B' (η/4) (Z n) d (M n) A P (S n) (r n) (L n) := by + intro t ht + obtain ⟨ht,hbad⟩ := Finset.mem_filter.mp ht + apply Finset.mem_filter.mpr + refine ⟨ht,?_⟩ + by_contra hgood + obtain ⟨lo,hi,res,test,hside,hbox,hLip,hnorm,hlarge⟩ := hbad + have hcompare (F : (G⧸Γ) → ℂ) (hFL : LipschitzWith B' F) (hFn : ∀ y,‖F y‖≤B') : + ‖mean (physicalResidueBox lo hi res d) + (fun x=>F (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))- + mean (nestedBox lo hi res A d (M n) (∏ j,t j)) + (fun x=>F (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))‖<η/4 := by + apply lt_of_not_ge + intro hh + exact hgood ⟨lo,hi,res,F,hside,hbox,hFL,hFn,hh⟩ + have hplain := hcompare test (hLip.weaken hBB) + (fun y=>(hnorm y).trans (by exact_mod_cast hBB)) + have hface := hσ.compare hη (physicalResidueBox lo hi res d) + (nestedBox lo hi res A d (M n) (∏ j,t j)) + (fun x=>QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))) + (fun g hg hgB=>hcompare g (hg.weaken hKB) + (fun y=>(hgB y).trans (by exact_mod_cast hKB))) test hLip hnorm + let f : (Fin v → ℤ) → ℂ := fun x=>test + (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))) + have hshift := residueMean_translation lo hi res (h t) d hd (B:ℝ) (c₀*Z n) (H n) + hB hW hside (hH n) (hh t ht) f (fun x=>hnorm _) + have he : (fun x : Fin v → ℤ=>test + (σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))))= + fun x=>f (x+h t) := by + funext x + rw [hid t ht x] + rfl + have hsmall : ‖mean (physicalResidueBox lo hi res d) (fun x=>f (x+h t))- + mean (physicalResidueBox lo hi res d) f‖<η/4 := by + apply hshift.trans_lt + convert hen using 1 + ring + rw [← he] at hsmall + let X := mean (nestedBox lo hi res A d (M n) (∏ j,t j)) + (fun x=>test (σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))) + let Y := mean (physicalResidueBox lo hi res d) + (fun x=>test (σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ))))))) + let U := mean (physicalResidueBox lo hi res d) f + let V := mean (nestedBox lo hi res A d (M n) (∏ j,t j)) f + have htri : ‖X-V‖≤‖X-Y‖+‖Y-U‖+‖U-V‖ := by + calc + _≤‖X-U‖+‖U-V‖ := norm_sub_le_norm_sub_add_norm_sub X U V + _≤_ := add_le_add (norm_sub_le_norm_sub_add_norm_sub X Y U) (le_refl ‖U-V‖) + change η≤‖X-V‖ at hlarge + change ‖U-V‖<η/4 at hplain + change ‖Y-X‖<η/2 at hface + rw [norm_sub_rev] at hface + change ‖Y-U‖<η/4 at hsmall + linarith + exact (div_le_div_of_nonneg_right (by exact_mod_cast Finset.card_le_card hsub) + (Nat.cast_nonneg _)).trans_lt (hpn A P hP) + +end RoughTopologicalFace + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological02.lean new file mode 100644 index 0000000000000000000000000000000000000000..a7eff654f7dd81675595575d35b2db0a2fc80ae3 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological02.lean @@ -0,0 +1,293 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughTopological01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section +noncomputable section +namespace RoughTopologicalFace +open RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + + +theorem source_conditional_face_decay (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0S n j) atTop atTop) + (hZ : ∀ a : ℝ,0Z n/(1+∑ j,S n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z n) atTop (𝓝 0)) + (hM : ∀ n,0S n j/(L n:ℝ)) atTop atTop) + (hbin : ∀ᶠ n in atTop,0canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),Approximable B K η σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes (S n) (r n) (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes (S n) (r n) (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (∑ t∈exceptionalFace Γ m v c₀ C₀ B η (Z n) d (M n) A P σ (S n) (r n) (L n), + HarmonicExposure.exposedWeight (Q n) (Δ n) (a n) (M n) t)/ + (∑ t∈productTimes (S n) (r n) (L n), + HarmonicExposure.exposedWeight (Q n) (Δ n) (a n) (M n) t)<ε := by + classical + have hK : (0:ℝ)<8*2^m := by positivity + intro ε hε + have hf := source_face_decay (Γ:=Γ) (c:=c) Λ hle hsk hΛ htop m v D d hd c₀ C₀ B K η + hc₀ hC₀ hB hη w M S Z H r L hw hS hZ hH hHZ hM hMs hL hsm hWL hr hSL + (ε/(8*2^m)) (div_pos hε hK) + have hpos : ∀ᶠ n in atTop,∀ j,0(hS j).eventually (eventually_gt_atTop 0)) + have hne := productTimes_nonempty_eventually S r L hL hS hSL + filter_upwards [hf,hpos,hne,hbin] with n hfn hsn htn hbn + intro A P hP σ hσ h hh hid + have hfrac := hfn A P hP σ hσ h hh hid + have hdom := HarmonicExposure.conditional_fraction_le m (S n) (r n) (L n) (a n) (M n) + (Q n) (Δ n) hsn (hL n) (by exact_mod_cast hM n) hbn.1 hbn.2.1 hbn.2.2.1 hbn.2.2.2 + htn (exceptionalFace Γ m v c₀ C₀ B η (Z n) d (M n) A P σ (S n) (r n) (L n)) + (Finset.filter_subset _ _) + apply hdom.trans_lt + have hh := mul_lt_mul_of_pos_left hfrac hK + simpa only [mul_div_cancel₀ _ hK.ne'] using hh + +end RoughTopologicalFace + +end + +end + +section +noncomputable section +namespace RoughTopologicalFace +open RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + + +theorem conditional_face_uniform (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0U n j) atTop atTop) + (hUV : ∀ n j,U n j≤V n j) + (hZ : ∀ a : ℝ,0Z0 n/(1+∑ j,V n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z0 n) atTop (𝓝 0)) + (hM : ∀ n,0U n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) → + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),Approximable B K η σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (∑ t∈exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n), + HarmonicExposure.exposedWeight b.Q b.Δ b.a (M n) t)/ + (∑ t∈productTimes b.S b.r (L n), + HarmonicExposure.exposedWeight b.Q b.Δ b.a (M n) t)<ε + := by + classical + intro ε hε + let succeeds (n : ℕ) (b : Exposure m) : Prop := + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),Approximable B K η σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (∑ t∈exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n), + HarmonicExposure.exposedWeight b.Q b.Δ b.a (M n) t)/ + (∑ t∈productTimes b.S b.r (L n), + HarmonicExposure.exposedWeight b.Q b.Δ b.a (M n) t)<ε + + change ∀ᶠ n in atTop,∀ b : Exposure m, + b.Legal (U n) (V n) (Z0 n) (w n) (M n) → succeeds n b + have hchoice (n : ℕ) : ∃ b : Exposure m, + b.Legal (U n) (V n) (Z0 n) (w n) (M n) ∧ + ((∃ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) ∧ ¬succeeds n b) + → ¬succeeds n b) := by + by_cases he : ∃ b : Exposure m, + b.Legal (U n) (V n) (Z0 n) (w n) (M n) ∧ ¬succeeds n b + · obtain ⟨b,hb,hf⟩ := he + exact ⟨b,hb,fun _=>hf⟩ + · let Δ : ℝ := max 1 (4*(M n:ℝ)*(2^m*∏ j,U n j)) + refine ⟨⟨U n,fun _=>1,Z0 n,Δ,Δ,0⟩,?_,fun hh=>(he hh).elim⟩ + refine ⟨fun j=>⟨le_refl _,hUV n j⟩,le_refl _,?_,?_,?_,le_refl _,?_⟩ + · intro j + simp + · exact zero_lt_one.trans_le (le_max_left _ _) + · exact zero_lt_one.trans_le (le_max_left _ _) + · exact le_max_right _ _ + choose b hb hfail using hchoice + have hS : ∀ j,Tendsto (fun n=>(b n).S j) atTop atTop := fun j=> + tendsto_atTop_mono (fun n=>(hb n).1 j |>.1) (hU j) + have hV : ∀ j,Tendsto (fun n=>V n j) atTop atTop := fun j=> + tendsto_atTop_mono (fun n=>hUV n j) (hU j) + have hspos := totalScale_pos_eventually (fun n=>(b n).S) hS + have hvpos := totalScale_pos_eventually V hV + have hzsmall := domination_smaller (S:=fun _=>1) + (by filter_upwards [] with n; norm_num) hvpos hZ + have hz0 : Tendsto Z0 atTop atTop := by + simpa using hzsmall 1 zero_lt_one + have hZs : ∀ a : ℝ,0(b n).Z/(1+∑ j,(b n).S j)^a) atTop atTop := by + have hh := domination_smaller (S:=fun n=>totalScale (b n).S) + (by filter_upwards [hspos] with n hn; linarith) + (by filter_upwards [] with n + dsimp [totalScale] + have hh := Finset.sum_le_sum (s:=Finset.univ) (fun j _=>(hb n).1 j |>.2) + linarith) hZ + intro a ha + apply tendsto_atTop_mono' atTop ?_ (hh a ha) + filter_upwards [hspos] with n hn + exact div_le_div_of_nonneg_right (hb n).2.1 (Real.rpow_nonneg (by linarith) _) + have hHsmall : Tendsto (fun n=>H n/(b n).Z) atTop (𝓝 0) := by + apply squeeze_zero' ?_ ?_ hHZ + · filter_upwards [hz0.eventually (eventually_gt_atTop 0)] with n hn + exact div_nonneg (hH n) (hn.le.trans (hb n).2.1) + · filter_upwards [hz0.eventually (eventually_gt_atTop 0)] with n hn + exact div_le_div_of_nonneg_left (hH n) hn (hb n).2.1 + have hSL : ∀ j,Tendsto (fun n=>(b n).S j/(L n:ℝ)) atTop atTop := by + intro j + apply tendsto_atTop_mono (fun n=>?_) (hUL j) + exact div_le_div_of_nonneg_right ((hb n).1 j).1 (by exact_mod_cast (hL n).le) + have hbin : ∀ᶠ n in atTop,0<(b n).Q ∧ 0<(b n).Δ ∧ (b n).Δ≤(b n).Q ∧ + 4*(M n:ℝ)*(2^m*∏ j,(b n).S j)≤(b n).Δ := by + filter_upwards [] with n + exact (hb n).2.2.2 + have hh := source_conditional_face_decay (Γ:=Γ) (c:=c) Λ hle hsk hΛ htop m v D d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M (fun n=>(b n).S) (fun n=>(b n).Z) H + (fun n=>(b n).Q) (fun n=>(b n).Δ) (fun n=>(b n).a) + (fun n=>(b n).r) L hw hS hZs hH hHsmall hM hMs hL hsm hWL + (fun n=>(hb n).2.2.1) hSL hbin ε hε + filter_upwards [hh] with n hn + intro z hz + by_contra he + exact hfail n ⟨z,hz,he⟩ hn + +end RoughTopologicalFace +end + +end + +section +noncomputable section +namespace RoughTopologicalFace +open RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + +theorem raw_conditional_face_uniform (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0U n j) atTop atTop) + (hUV : ∀ n j,U n j≤V n j) + (hZ : ∀ a : ℝ,0Z0 n/(1+∑ j,V n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z0 n) atTop (𝓝 0)) + (hM : ∀ n,0U n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) → + ∀ X W : ℕ,(W:ℤ)∣(M n:ℤ) → b.a.natAbs.Coprime W → + (∀ t∈productTimes b.S b.r (L n),(X:ℝ)≤b.Q/(∏ j,(t j:ℝ))) → + (∀ t∈productTimes b.S b.r (L n),(b.Q+b.Δ)/(∏ j,(t j:ℝ))≤(X:ℝ)^2) → + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),Approximable B K η σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + HarmonicExposure.rawFiberMass + (exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n)) + X W b.Q b.Δ b.a (M n) / + HarmonicExposure.rawFiberMass (productTimes b.S b.r (L n)) + X W b.Q b.Δ b.a (M n)<ε + := by + classical + intro ε hε + have hu := conditional_face_uniform (Γ:=Γ) (c:=c) Λ hle hsk hΛ htop m v D d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M U V Z0 H L hw hU hUV hZ hH hHZ + hM hMs hL hsm hWL hUL ε hε + have hup : ∀ᶠ n in atTop,∀ j,0(hU j).eventually (eventually_gt_atTop 0)) + filter_upwards [hu,hup] with n hn hUn + intro b hb X W hWM ha hlo hhi A P hP σ hσ h hh hid + have hτ : ∀ t∈productTimes b.S b.r (L n),0<∏ j,(t j:ℝ) := by + intro t ht + apply Finset.prod_pos + intro j hj + have htj := Fintype.mem_piFinset.mp ht j + have htpos := (mem_times (b.S j) (b.r j) (L n) (t j) (hL n)).mp htj + exact (hUn j).trans_le (((hb.1 j).1).trans htpos.1) + have he (T : Finset (Fin m→ℤ)) (hT : T⊆productTimes b.S b.r (L n)) := + HarmonicExposure.rawFiberMass_eq_exposed T X W b.Q b.Δ b.a (M n) + (by exact_mod_cast hM n) hWM ha + (fun t ht=>hτ t (hT ht)) (fun t ht=>hlo t (hT ht)) (fun t ht=>hhi t (hT ht)) + have hsub : exceptionalFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ b.S b.r (L n) ⊆ + productTimes b.S b.r (L n) := Finset.filter_subset _ _ + rw [he _ hsub,he _ (Finset.Subset.refl _)] + exact hn b hb A P hP σ hσ h hh hid + +end RoughTopologicalFace + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological03.lean new file mode 100644 index 0000000000000000000000000000000000000000..4b86043d4dec0350f6b0623d7c77c06499b029d3 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/RoughTopological03.lean @@ -0,0 +1,300 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughTopological02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +end + +end + +section +noncomputable section +namespace RoughTopologicalFace +open RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open scoped BigOperators Topology +variable {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} +variable (Γ : Subgroup G) [MetricSpace (G⧸Γ)] +variable [IsTopologicalGroup G] (c : RealCoordinates G dim) + + +theorem source_raw_joint_face_uniform (Λ : Subgroup G) (hle : Λ≤Γ) (hsk : SecondKind c) + (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0U n j) atTop atTop) + (hUV : ∀ n j,U n j≤V n j) + (hZ : ∀ a : ℝ,0Z0 n/(1+∑ j,V n j)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/Z0 n) atTop (𝓝 0)) + (hWM : ∀ n,(primorial (w n):ℤ)∣(M n:ℤ)) + (hM : ∀ n,0U n j/(L n:ℝ)) atTop atTop) : + ∀ ε : ℝ,0<ε →∀ᶠ n in atTop, + ∀ b : Exposure m,b.Legal (U n) (V n) (Z0 n) (w n) (M n) → + ∀ (X : Fin m→ℕ) (Xp : ℕ) (hX : ∀ j,4*primorial (w n)≤X j) + (hXp : 4*primorial (w n)≤Xp),b.a.natAbs.Coprime (primorial (w n)) → + (∀ j,(X j:ℝ)≤b.S j) → (∀ j,2*b.S j≤(X j:ℝ)^2) → + (∀ t∈productTimes b.S b.r (L n),(Xp:ℝ)≤b.Q/(∏ j,(t j:ℝ))) → + (∀ t∈productTimes b.S b.r (L n),(b.Q+b.Δ)/(∏ j,(t j:ℝ))≤(Xp:ℝ)^2) → + ∀ (A : Fin v → ℤ) (P : (Fin (m+v)→ℝ)→G), + (∀ i,HasDegree (fun y=>canonicalLog c (P y) i) D) → + ∀ (σ : (G⧸Γ) → (G⧸Γ)),Approximable B K η σ → + ∀ h : (Fin m → ℤ) → Fin v → ℤ, + (∀ t∈productTimes b.S b.r (L n),∀ i,(d:ℤ)∣h t i ∧ |(h t i:ℝ)|≤H n) → + (∀ t∈productTimes b.S b.r (L n),∀ x : Fin v → ℤ, + σ (QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>(x i:ℝ)))))= + QuotientGroup.mk (P (Fin.append (fun j=>(t j:ℝ)) (fun i=>((x i+h t i:ℤ):ℝ))))) → + (ProductExposureLaw.jointLaw X Xp (primorial (w n)) (primorial_pos _) hX hXp).real + (ProductExposureLaw.jointFiber + {t | badFace Γ m v c₀ C₀ B η b.Z d (M n) A P σ t} + X Xp (primorial (w n)) b.S b.r (L n) b.Q b.Δ b.a (M n) : Set _) / + (ProductExposureLaw.jointLaw X Xp (primorial (w n)) (primorial_pos _) hX hXp).real + (ProductExposureLaw.jointFiber Set.univ + X Xp (primorial (w n)) b.S b.r (L n) b.Q b.Δ b.a (M n) : Set _) < ε + := by + classical + intro ε hε + have hu := raw_conditional_face_uniform (Γ:=Γ) (c:=c) Λ hle hsk hΛ htop m v D d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M U V Z0 H L hw hU hUV hZ hH hHZ + hM hMs hL hsm hWL hUL ε hε + filter_upwards [hu] with n hn + intro b hb X Xp hX hXp ha hloD hhiD hloP hhiP A P hP σ hσ h hh hid + rw [ProductExposureLaw.conditional_exact, + HarmonicExposure.literal_mass_eq _ X Xp _ b.S b.r (L n) b.Q b.Δ b.a (M n) + (hL n) (hWL n) hb.2.2.1 hloD hhiD, + HarmonicExposure.literal_mass_eq Set.univ X Xp _ b.S b.r (L n) b.Q b.Δ b.a (M n) + (hL n) (hWL n) hb.2.2.1 hloD hhiD] + simpa only [exceptionalFace,Set.mem_ofPred_eq,Set.mem_univ,Finset.filter_true_of_mem (fun _ _=>True.intro)] using + hn b hb Xp (primorial (w n)) (hWM n) ha hloP hhiP A P hP σ hσ h hh hid + +end RoughTopologicalFace +end + +end + +end + +section + +noncomputable section +namespace RoughTopologicalFace +open RoughCoveredFace +open RoughFaceShift +open RationalLattice MalcevCharacters RealPolynomialDegree RoughScales Filter +open RoughSamplingWeights FinitePieceAverages RoughSourceExceptional RoughProductRemoval +open ProductExposureLabels ProductExposureLaw RawHarmonicProbability ProductExposureCutoff MeasureTheory +open scoped BigOperators Topology +attribute [local instance] Classical.propDecidable + + + +theorem source_raw_approximable_face_cover_decay {G : Type} [Group G] [TopologicalSpace G] {dim : ℕ} + (Λ Γ : Subgroup G) [MetricSpace (G⧸Γ)] [IsTopologicalGroup G] + (c : RealCoordinates G dim) (hsk : SecondKind c) + (hle : Λ≤Γ) (hΛ : ∀ g : G,g∈Λ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) + (htop : (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace = + QuotientGroup.instTopologicalSpace Γ) + (m v D d : ℕ) (hd : 0X n j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ n,0R n/(Xp n:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R n/(M n:ℝ))/ + (1+∑ j,(X n j:ℝ)^2)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/(R n/(M n:ℝ))) atTop (𝓝 0)) + (hWM : ∀ n,(primorial (w n):ℤ)∣(M n:ℤ)) + (hM : ∀ n,0(X n j:ℝ)/(L n:ℝ)) atTop atTop) + (F : ℕ→Label m→FaceData m v G Γ) + (hF : ∀ n b,b∈(fullDomain (X n) (Xp n) (primorial (w n))).image + (expose (L n) (M n:ℤ) (R n)) → Good (X n) (Xp n) (R n) b → + ApproxValid c D d B K η (H n) (L n) b (F n b)) : + Tendsto (fun n=>(jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) + (hX n) (hXp n)).real (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n))) + atTop (𝓝 0) + := by + have hXpr (n : ℕ) : (0:ℝ)R n/(M n:ℝ)) atTop atTop := by + apply tendsto_atTop_mono (fun n=>?_) (hZ 1 (by norm_num)) + rw [Real.rpow_one] + exact div_le_self (div_nonneg (hR n).le (hMr n).le) + (by have:=Finset.sum_nonneg (fun j (_ : j∈Finset.univ)=>sq_nonneg (X n j:ℝ));linarith) + have hRmin : ∀ᶠ n in atTop,4*(M n:ℝ)*2^m≤R n := by + filter_upwards [(tendsto_atTop.mp hZtop) (4*2^m)] with n hn + have hh := (le_div_iff₀ (hMr n)).mp hn + nlinarith + have hUV : ∀ n j,(X n j:ℝ)≤(X n j:ℝ)^2 := by + intro n j + have h1 : (1:ℝ)≤X n j := by + have:=hX n j;have:=primorial_pos (w n);exact_mod_cast (show 1≤X n j by omega) + nlinarith + have hu := source_raw_joint_face_uniform Γ c Λ hle hsk hΛ htop m v D d hd c₀ C₀ B K η + hc₀ hC₀ hB hη w M (fun n j=>(X n j:ℝ)) (fun n j=>(X n j:ℝ)^2) + (fun n=>R n/(M n:ℝ)) H L hw + (fun j=>tendsto_natCast_atTop_atTop.comp (hXt j)) hUV hZ hH hHZ hWM hM hMs + hL hsm hWL hXL + have hbad : Tendsto (fun n=>(jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) + (hX n) (hXp n)).real {z | ¬Good (X n) (Xp n) (R n) (expose (L n) (M n:ℤ) (R n) z)}) + atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun _=>measureReal_nonneg)) + · filter_upwards [hRsmall] with n hn + exact bad_good_bound (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n) + (L n) (M n:ℤ) (R n) (hR n) (by linarith [hR n]) + · have ht := tendsto_finsetSum Finset.univ (fun j _=> + raw_cutoff_decay (fun n=>X n j) (fun n=>primorial (w n)) 1 + (fun _=>primorial_pos _) (fun n=>hX n j) (hXt j)) + have hp := raw_cutoff_decay Xp (fun n=>primorial (w n)) (m+2) + (fun _=>primorial_pos _) hXp hXpt + simpa using ht.add hp + apply tendsto_order.2 + constructor + · intro a ha + exact Eventually.of_forall (fun _=>lt_of_lt_of_le ha measureReal_nonneg) + · intro e he + let ε := min (e/3) (1/2) + have hε : 0<ε := lt_min (by linarith) (by norm_num) + have hε1 : ε≤1 := (min_le_right _ _).trans (by norm_num) + filter_upwards [hu ε hε,hRsmall,hRmin,(tendsto_order.mp hbad).2 (e/3) (by linarith)] + with n hn hsmall hmin hbadn + have hb := supported_conditional_bad_bound + (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)) + (fullDomain (X n) (Xp n) (primorial (w n))) + (joint_ae_fullDomain (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)) + (expose (L n) (M n:ℤ) (R n)) {b | Good (X n) (Xp n) (R n) b} + (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n)) ε hε.le hε1 + (by + intro b hb hg + have hlegal := label_exposure_legal (X n) (Xp n) (w n) (M n) (L n) (R n) + (hX n) (hXp n) (hL n) (hM n) (hWL n) (hWM n) (hR n) hsmall hmin b hb hg + have hres := image_residues (X n) (Xp n) (primorial (w n)) (L n) (M n:ℤ) (R n) + (hL n) (by exact_mod_cast hM n) (hWL n) (hWM n) b hb + have hv := hF n b hb hg + have hpre := good_preimages (X n) (Xp n) (R n) (hR n).le (L n) (hL n) b hg + have hlocal := hn (labelExposure b (R n) (M n)) hlegal (X n) (Xp n) (hX n) (hXp n) + hres.2.2.2 (fun j=>(hg.1 j).1) (fun j=>(hg.1 j).2) + (fun t ht=>(hpre t ht).1) (fun t ht=>(hpre t ht).2) + (F n b).A (F n b).P hv.1 (F n b).σ hv.2.1 (F n b).h hv.2.2.1 hv.2.2.2 + have heq := label_conditional_exact (X n) (Xp n) (primorial (w n)) (M n) (L n) (R n) + (primorial_pos _) (hX n) (hXp n) (hL n) (hM n) (hR n) (hWL n) (hWM n) b hb + (fun b=>{t | badFace Γ m v c₀ C₀ B η (labelExposure b (R n) (M n)).Z d (M n) + (F n b).A (F n b).P (F n b).σ t}) + exact heq.trans_le hlocal.le) + have hεe : ε≤e/3 := min_le_left _ _ + change (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)).real + (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n)) ≤ ε+ + (jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) (hX n) (hXp n)).real + {z | ¬Good (X n) (Xp n) (R n) (expose (L n) (M n:ℤ) (R n) z)} at hb + change _X n j) atTop atTop) (hXpt : Tendsto Xp atTop atTop) + (hR : ∀ n,0R n/(Xp n:ℝ)) atTop (𝓝 0)) + (hZ : ∀ a : ℝ,0(R n/(M n:ℝ))/ + (1+∑ j,(X n j:ℝ)^2)^a) atTop atTop) + (hH : ∀ n,0≤H n) (hHZ : Tendsto (fun n=>H n/(R n/(M n:ℝ))) atTop (𝓝 0)) + (hWM : ∀ n,(primorial (w n):ℤ)∣(M n:ℤ)) + (hM : ∀ n,0(X n j:ℝ)/(L n:ℝ)) atTop atTop) + (σ₀ : C(G⧸Γ,G⧸Γ)) + (F : ℕ→Label m→FaceData m v G Γ) + (hF : ∀ n b,b∈(fullDomain (X n) (Xp n) (primorial (w n))).image + (expose (L n) (M n:ℤ) (R n)) → Good (X n) (Xp n) (R n) b → + TopologicalValid c D d (H n) (L n) b σ₀ (F n b)) : + Tendsto (fun n=>(jointLaw (X n) (Xp n) (primorial (w n)) (primorial_pos _) + (hX n) (hXp n)).real (rawFaceEvent Γ m v c₀ C₀ B η (R n) d (M n) (L n) (F n))) + atTop (𝓝 0) + := by + obtain ⟨Λ,e,he,hΛ,hle,E,hE,hdeg⟩:=grid_second_degree_cover c Γ grid hgridpos hgrid + have hcompact : @CompactSpace (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) := by + obtain ⟨S,hS,hrep⟩:=compact_reps_of_integerCoordinates e Λ hΛ + apply CompactGroupProducts.HasCompactReps.quotient_compactSpace + refine ⟨S,hS,fun _ _=>Subgroup.mem_top _,?_⟩ + intro g _ + obtain ⟨a,ha,hag⟩:=hrep g + exact ⟨a,ha,hle hag⟩ + let : @CompactSpace (G⧸Γ) + (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace := by + rw [htop] + exact hcompact + let σ : @ContinuousMap (G⧸Γ) (G⧸Γ) + (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace + (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace := + @ContinuousMap.mk _ _ + (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace + (inferInstance : MetricSpace (G⧸Γ)).toUniformSpace.toTopologicalSpace + (fun x=>σ₀ x) (by rw [htop];exact σ₀.continuous) + obtain ⟨K,hK⟩:=continuous_approximable σ B η hη + apply source_raw_approximable_face_cover_decay Λ Γ e he hle hΛ htop m v (E*D) d hd + c₀ C₀ B K η hc₀ hC₀ hB hη w M Xp X R H L hw hX hXp hXt hXpt hR hRX hZ hH hHZ + hWM hM hMs hL hsm hWL hXL F + intro n b hb hg + obtain ⟨hP,hσ,hh,hface⟩:=hF n b hb hg + refine ⟨hdeg (m+v) D (F n b).P hP,?_,hh,hface⟩ + intro f hf hb' + obtain ⟨g,hg,hgb,herr⟩:=hK f hf hb' + refine ⟨g,hg,hgb,?_⟩ + intro x + rw [hσ] + exact herr x + +end RoughTopologicalFace + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/ScalarDifference01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/ScalarDifference01.lean new file mode 100644 index 0000000000000000000000000000000000000000..6da3b0314fb33315f2ba41b06ea875b96f999d2b --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/ScalarDifference01.lean @@ -0,0 +1,378 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.CubePolynomials01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped BigOperators Topology commutatorElement +end +end + + + +section + +noncomputable section +open scoped commutatorElement +namespace CubeMaxFiltration +open CubeFaces +variable {G ι : Type*} [Group G] [DecidableEq ι] + + + +def level (H : Filtration G) (I : Finset ι) (k : ℕ) : Subgroup (Finset ι→G) := + ⨆ D : Finset ι, ⨆ (_ : D⊆I), (H.level (max k D.card)).map (face D) + +lemma face_mem (H : Filtration G) {I D : Finset ι} {k : ℕ} + (hD : D⊆I) {g : G} (hg : g∈H.level (max k D.card)) : face D g∈level H I k := + (le_iSup_of_le D (le_iSup_of_le hD le_rfl) : + (H.level (max k D.card)).map (face D) ≤ level H I k) ⟨g,hg,rfl⟩ + +lemma antitone (H : Filtration G) (I : Finset ι) : Antitone (level H I) := by + intro i j hij + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g,hg,rfl⟩ + exact face_mem H hD (H.antitone (max_le_max hij le_rfl) hg) + +@[simp] lemma level_zero (H : Filtration G) (I : Finset ι) : level H I 0=cube H I 0 := by + simp [level,cube] + +lemma level_one (H : Filtration G) (I : Finset ι) (h01 : H.level 0=H.level 1) : + level H I 1=cube H I 0 := by + have hh (D : Finset ι) : H.level (max 1 D.card)=H.level D.card := by + by_cases hD : D.card=0 + · simp [hD,←h01] + · rw [max_eq_right (by omega)] + simp only [level,cube,hh,Nat.add_zero] + +lemma max_union_degree (i j : ℕ) (D E : Finset ι) : + max (i+j) (D∪E).card ≤ max i D.card+max j E.card := by + have := Finset.card_union_le D E + omega + +lemma normalizes (H : Filtration G) (I : Finset ι) (k : ℕ) : + level H I 0 ≤ Subgroup.normalizer (level H I k) := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g,hg,rfl⟩ + have hc (g : G) (hg : g∈H.level (max 0 D.card)) : + ∀ z∈level H I k, face D g*z*(face D g)⁻¹∈level H I k := by + have hle : level H I k ≤ (level H I k).comap (MulAut.conj (face D g)).toMonoidHom := by + refine iSup_le fun E => iSup_le fun hE => ?_ + rintro f ⟨h,hh,rfl⟩ + change face D g*face E h*(face D g)⁻¹∈level H I k + have hdeg := max_union_degree 0 k D E + simp only [Nat.zero_add] at hdeg + have hcomm : ⁅face D g,face E h⁆∈level H I k := by + rw [face_commutator] + exact face_mem H (Finset.union_subset hD hE) + (H.antitone hdeg (H.commutator_le _ _ (Subgroup.commutator_mem_commutator hg hh))) + have heq : face D g*face E h*(face D g)⁻¹=⁅face D g,face E h⁆*face E h := by + simp [commutatorElement_def,mul_assoc] + rw [heq] + exact (level H I k).mul_mem hcomm (face_mem H hE hh) + exact fun z hz => hle hz + rw [Subgroup.mem_normalizer_iff] + intro z + constructor + · exact hc g hg z + · intro hz + have hh := hc g⁻¹ ((H.level _).inv_mem hg) _ hz + simpa [map_inv,mul_assoc] using hh + +lemma face_commutator_mem (H : Filtration G) (I : Finset ι) {i j : ℕ} + {D : Finset ι} (hD : D⊆I) {g : G} (hg : g∈H.level (max i D.card)) + {f : Finset ι→G} (hf : f∈level H I j) : ⁅face D g,f⁆∈level H I (i+j) := by + have hle : level H I j ≤ commModulo (level H I (i+j)) (face D g) := by + refine iSup_le fun E => iSup_le fun hE => ?_ + rintro f ⟨h,hh,rfl⟩ + constructor + · exact normalizes H I _ (antitone H I (Nat.zero_le j) (face_mem H hE hh)) + · rw [face_commutator] + exact face_mem H (Finset.union_subset hD hE) + (H.antitone (max_union_degree i j D E) + (H.commutator_le _ _ (Subgroup.commutator_mem_commutator hg hh))) + exact (hle hf).2 + +lemma commutator_mem (H : Filtration G) (I : Finset ι) {i j : ℕ} + {f g : Finset ι→G} (hf : f∈level H I i) (hg : g∈level H I j) : + ⁅f,g⁆∈level H I (i+j) := by + have hle : level H I i ≤ commModulo (level H I (i+j)) g := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨a,ha,rfl⟩ + constructor + · exact normalizes H I _ (antitone H I (Nat.zero_le i) (face_mem H hD ha)) + · have hh := face_commutator_mem H I hD ha hg + have hinv := (level H I (i+j)).inv_mem hh + simpa [commutatorElement_def,mul_assoc] using hinv + have hinv := (level H I (i+j)).inv_mem (hle hf).2 + simpa [commutatorElement_def,mul_assoc] using hinv + + +def ambient (H : Filtration G) (I : Finset ι) : Filtration (Finset ι→G) where + level := level H I + antitone := antitone H I + commutator_le _ _ := Subgroup.commutator_le.mpr (fun _ hf _ hg => commutator_mem H I hf hg) + + +def filtration (H : Filtration G) (I : Finset ι) : Filtration (cube H I 0) where + level k := (level H I k).comap (cube H I 0).subtype + antitone := fun _ _ hij => Subgroup.comap_mono (antitone H I hij) + commutator_le i j := by + apply Subgroup.commutator_le.mpr + intro f hf g hg + exact commutator_mem H I hf hg + +@[simp] lemma filtration_zero (H : Filtration G) (I : Finset ι) : + (filtration H I).level 0=⊤ := by + ext f + simp [filtration] + +lemma filtration_one (H : Filtration G) (I : Finset ι) (h01 : H.level 0=H.level 1) : + (filtration H I).level 1=⊤ := by + ext f + simp [filtration,level_one H I h01] + +lemma level_bot (H : Filtration G) (I : Finset ι) {s : ℕ} (hs : H.level s=⊥) : + level H I s=⊥ := by + apply le_antisymm _ bot_le + refine iSup_le fun D => iSup_le fun hD => ?_ + have hh : H.level (max s D.card)=⊥ := le_antisymm (hs ▸ H.antitone (le_max_left _ _)) bot_le + rw [hh,Subgroup.map_bot] + +lemma filtration_bot (H : Filtration G) (I : Finset ι) {s : ℕ} (hs : H.level s=⊥) : + (filtration H I).level s=⊥ := by + ext f + simp only [filtration,Subgroup.mem_comap,level_bot H I hs,Subgroup.mem_bot] + exact ⟨fun h => Subtype.ext h,fun h => congrArg Subtype.val h⟩ + + + +lemma taylor_face_mem (H : Filtration G) (I : Finset ι) {D : Finset ι} + (hD : D⊆I) {k l : ℕ} (hkl : k≤l) (hDl : D.card≤l) {a : G} (ha : a∈H.level l) : + face D a∈level H I k := + face_mem H hD (H.antitone (max_le hkl hDl) ha) + +end CubeMaxFiltration +end +end + + + +section + +noncomputable section +open scoped BigOperators +namespace ScalarDifferenceDegree +variable {A R : Type*} [AddCommGroup A] [CommRing R] + +def diff (h : A) (f : A→R) : A→R := fun x => f (x+h)-f x + +def DegreeAtMost : ℕ→(A→R)→Prop + | 0,f => ∀ x y,f x=f y + | d+1,f => ∀ h,DegreeAtMost d (diff h f) + +lemma constant (d : ℕ) (r : R) : DegreeAtMost d (fun _ : A => r) := by + induction d generalizing r with + | zero => intro x y; rfl + | succ d ih => + intro h + change DegreeAtMost d (diff h (fun _ : A => r)) + have he : diff h (fun _ : A => r)=(fun _ => 0) := by ext x; exact sub_self r + rw [he] + exact ih 0 + +lemma add (d : ℕ) {f g : A→R} (hf : DegreeAtMost d f) (hg : DegreeAtMost d g) : + DegreeAtMost d (fun x => f x+g x) := by + induction d generalizing f g with + | zero => intro x y; change f x+g x=f y+g y; rw [hf x y,hg x y] + | succ d ih => + intro h + have he : diff h (fun x => f x+g x)=fun x => diff h f x+diff h g x := by + ext x; simp only [diff]; ring + rw [he] + exact ih (hf h) (hg h) + +lemma mul_const (d : ℕ) {f : A→R} (hf : DegreeAtMost d f) (r : R) : + DegreeAtMost d (fun x => f x*r) := by + induction d generalizing f with + | zero => intro x y; change f x*r=f y*r; rw [hf x y] + | succ d ih => + intro h + have he : diff h (fun x => f x*r)=fun x => diff h f x*r := by + ext x; simp only [diff]; ring + rw [he] + exact ih (hf h) + +lemma mono_step (d : ℕ) {f : A→R} (hf : DegreeAtMost d f) : DegreeAtMost (d+1) f := by + induction d generalizing f with + | zero => intro h x y; simp [diff,hf (x+h) x,hf (y+h) y] + | succ d ih => intro h; exact ih (hf h) + +lemma mono {d e : ℕ} (hde : d≤e) {f : A→R} (hf : DegreeAtMost d f) : DegreeAtMost e f := by + induction e,hde using Nat.le_induction with + | base => exact hf + | succ e he ih => exact mono_step e ih + +lemma shift (d : ℕ) {f : A→R} (hf : DegreeAtMost d f) (t : A) : + DegreeAtMost d (fun x => f (x+t)) := by + induction d generalizing f with + | zero => intro x y; exact hf _ _ + | succ d ih => + intro h + have he : diff h (fun x => f (x+t))=fun x => diff h f (x+t) := by + ext x; simp [diff,add_comm,add_left_comm] + rw [he] + exact ih (hf h) + +lemma mul (d e : ℕ) {f g : A→R} (hf : DegreeAtMost d f) (hg : DegreeAtMost e g) : + DegreeAtMost (d+e) (fun x => f x*g x) := by + induction d generalizing e f g with + | zero => + have he : (fun x => f x*g x)=(fun x => g x*f 0) := by ext x; rw [hf x 0,mul_comm] + rw [he,Nat.zero_add] + exact mul_const e hg _ + | succ d ih => + induction e generalizing f g with + | zero => + have he : (fun x => f x*g x)=(fun x => f x*g 0) := by ext x; rw [hg x 0] + rw [he,Nat.add_zero] + exact mul_const (d+1) hf _ + | succ e ihe => + rw [show (d+1)+(e+1)=(d+(e+1))+1 by omega] + intro h + have he : diff h (fun x => f x*g x)= + fun x => diff h f x*g (x+h)+f x*diff h g x := by + ext x; simp only [diff]; ring + rw [he] + apply add + · exact ih (e+1) (hf h) (shift (e+1) hg h) + · simpa only [Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using ihe hf (hg h) + +lemma pow (d n : ℕ) {f : A→R} (hf : DegreeAtMost d f) : + DegreeAtMost (d*n) (fun x => f x^n) := by + induction n with + | zero => simpa using constant 0 (1:R) + | succ n ih => + simpa only [Nat.mul_succ,pow_succ] using mul (d*n) d ih hf + +lemma sum {T : Type*} (S : Finset T) (d : ℕ) (f : T→A→R) + (hf : ∀ t∈S,DegreeAtMost d (f t)) : DegreeAtMost d (fun x => ∑ t∈S,f t x) := by + classical + induction S using Finset.induction_on with + | empty => simpa using constant d (0:R) + | @insert t S ht ih => + simp only [Finset.sum_insert ht] + exact add d (hf t (Finset.mem_insert_self _ _)) (ih (fun u hu => hf u (Finset.mem_insert_of_mem hu))) + +lemma prod {T : Type*} (S : Finset T) (d : T→ℕ) (f : T→A→R) + (hf : ∀ t∈S,DegreeAtMost (d t) (f t)) : + DegreeAtMost (∑ t∈S,d t) (fun x => ∏ t∈S,f t x) := by + classical + induction S using Finset.induction_on with + | empty => simpa using constant 0 (1:R) + | @insert t S ht ih => + simp only [Finset.sum_insert ht,Finset.prod_insert ht] + exact mul _ _ (hf t (Finset.mem_insert_self _ _)) (ih (fun u hu => hf u (Finset.mem_insert_of_mem hu))) + +lemma hom (φ : A→+R) : DegreeAtMost 1 φ := by + intro h + have hh : diff h φ=fun _ => φ h := by ext x; simp [diff] + rw [hh] + exact constant 0 _ + +lemma eval_monomial {σ : Type*} [Fintype σ] (e : σ→₀ℕ) (r : ℝ) : + DegreeAtMost (e.sum (fun _ n => n)) (fun x : σ→ℝ => MvPolynomial.eval x (MvPolynomial.monomial e r)) := by + classical + have hcoord (i : σ) : DegreeAtMost 1 (fun x : σ→ℝ => x i) := hom ({ toFun := fun x => x i, map_zero' := rfl, map_add' := fun _ _ => rfl } : (σ→ℝ)→+ℝ) + have hh := prod Finset.univ (fun i => e i) (fun i (x : σ→ℝ) => x i^(e i)) + (fun i _ => by simpa using pow 1 (e i) (hcoord i)) + have he : e.sum (fun _ n => n)=∑ i : σ,e i := Finsupp.sum_fintype _ _ (by simp) + rw [he] + have hp (x : σ→ℝ) : e.prod (fun i k => x i^k)=∏ i,x i^(e i) := + Finsupp.prod_fintype _ _ (by intro i; simp) + simp_rw [MvPolynomial.eval_monomial,hp] + simpa only [mul_comm] using mul_const _ hh r + + + +lemma eval_polynomial {σ : Type*} [Fintype σ] (p : MvPolynomial σ ℝ) {d : ℕ} + (hp : p.totalDegree≤d) : DegreeAtMost d (fun x : σ→ℝ => MvPolynomial.eval x p) := by + classical + have he (x : σ→ℝ) : MvPolynomial.eval x p= + ∑ e∈p.support,MvPolynomial.eval x (MvPolynomial.monomial e (p.coeff e)) := by + simpa only [map_sum] using congrArg (MvPolynomial.eval x) (MvPolynomial.as_sum p) + simp_rw [he] + apply sum + intro e he + exact mono ((MvPolynomial.le_totalDegree he).trans hp) (eval_monomial e _) + +def iterDiff : List A→(A→R)→(A→R) + | [],f => f + | h::hs,f => iterDiff hs (diff h f) + +lemma iterDiff_zero_function (hs : List A) : iterDiff hs (fun _ : A => (0:R))=0 := by + induction hs with + | nil => rfl + | cons h hs ih => + have he : diff h (fun _ : A => (0:R))=0 := by ext x; exact sub_self 0 + simpa only [iterDiff,he,Pi.zero_def] using ih + +lemma iterDiff_zero {d : ℕ} {f : A→R} (hf : DegreeAtMost d f) + (hs : List A) (hhs : d + cases hs with + | nil => simp at hhs + | cons h hs => + have he : diff h f=0 := by ext x; exact sub_eq_zero.mpr (hf (x+h) x) + simpa only [iterDiff,he,Pi.zero_def] using iterDiff_zero_function hs + | succ d ih => + cases hs with + | nil => simp at hhs + | cons h hs => exact ih (hf h) hs (by simpa using hhs) + + + +theorem polynomial_power {K : Type*} [Group K] (H : CubeFaces.Filtration K) + (φ : Multiplicative ℝ→*K) (d : ℕ) (hφ : ∀ r,φ (Multiplicative.ofAdd r)∈H.level d) + {f : A→ℝ} (hf : DegreeAtMost d f) : + LeibmanSquare.Polynomial H 0 (fun x => φ (Multiplicative.ofAdd (f x))) := by + have hm (hs : List A) (f : A→ℝ) : + LeibmanSquare.iterDiff hs (fun x => φ (Multiplicative.ofAdd (f x)))= + fun x => φ (Multiplicative.ofAdd (iterDiff hs f x)) := by + induction hs generalizing f with + | nil => rfl + | cons h hs ih => + have he : LeibmanSquare.diff h (fun x => φ (Multiplicative.ofAdd (f x)))= + fun x => φ (Multiplicative.ofAdd (diff h f x)) := by + ext x + change (φ (Multiplicative.ofAdd (f x)))⁻¹*φ (Multiplicative.ofAdd (f (x+h)))= + φ (Multiplicative.ofAdd (f (x+h)-f x)) + rw [←map_inv,←map_mul] + congr 1 + change Multiplicative.ofAdd (-f x+f (x+h))=Multiplicative.ofAdd (f (x+h)-f x) + congr 1 + ring + rw [LeibmanSquare.iterDiff,he,ih] + rfl + intro hs x + rw [hm] + by_cases hd : hs.length≤d + · exact H.antitone (by simpa using hd) (hφ _) + · rw [iterDiff_zero hf hs (lt_of_not_ge hd)] + simp + +end ScalarDifferenceDegree + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SmoothBinomial01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SmoothBinomial01.lean new file mode 100644 index 0000000000000000000000000000000000000000..28661da99da1f450155069ff963a3214f757d8b9 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SmoothBinomial01.lean @@ -0,0 +1,301 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevTail01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +open scoped commutatorElement BigOperators +noncomputable section +end +end + + + +section +open scoped BigOperators +noncomputable section +namespace MalcevTailSection +open RationalLattice RationalPolynomialMap +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {n l : ℕ} +variable (c : RealCoordinates G n) (k : Fin n → ℤ) (r : Fin l → ℕ) + +def flowWord (t : Fin l → ℝ) : G := (List.ofFn (fun i => tailSection c k (r i) (t i))).prod + +omit [IsTopologicalGroup G] in +lemma polynomialMap_section {σ : Type*} (q : ℕ) {f : (σ → ℝ) → ℝ} + (hf : IsPolynomial f) : IsPolynomialMap c (fun x => tailSection c k q (f x)) := by + classical + unfold tailSection + split_ifs with h + · intro i + simp only [MalcevCharacters.coord_axis,Pi.single_apply] + split_ifs + · have he := RationalPolynomialMap.mul hf (RationalPolynomialMap.const (σ:=σ) ((k h.choose:ℚ)⁻¹)) + simpa only [Rat.cast_inv,Rat.cast_intCast,div_eq_mul_inv] using he + · exact RationalPolynomialMap.zero + · exact polynomialMap_one c + +omit [IsTopologicalGroup G] in +lemma polynomialMap_flowWord : IsPolynomialMap c (flowWord c k r) := by + change IsPolynomialMap c (fun x => (List.ofFn (fun i => tailSection c k (r i) (x i))).prod) + simp only [List.ofFn_eq_map] + generalize List.finRange l = v + induction v with + | nil => exact polynomialMap_one c + | cons i v ih => + simp only [List.map_cons,List.prod_cons] + exact polynomialMap_mul c (polynomialMap_section c k (r i) (RationalPolynomialMap.coordinate i)) ih + +omit [IsTopologicalGroup G] in +lemma flowWord_contDiff : ContDiff ℝ (⊤ : ℕ∞) (fun x => c.coord (flowWord c k r x)) := by + apply contDiff_pi.mpr + intro i + exact RationalPolynomialMap.contDiff (polynomialMap_flowWord c k r i) + + + +omit [IsTopologicalGroup G] in +lemma flowWord_bounds (R : ℝ) : + ∃ M > 0, + (∀ x, ‖x‖ ≤ R → ‖c.coord (flowWord c k r x)‖ ≤ M) ∧ + (∀ x y, ‖x‖ ≤ R → ‖y‖ ≤ R → + ‖c.coord (flowWord c k r x)-c.coord (flowWord c k r y)‖ ≤ M*‖x-y‖) := by + have hd := flowWord_contDiff c k r + obtain ⟨M,hM⟩ := (isCompact_closedBall (0 : Fin l → ℝ) R).exists_bound_of_continuousOn hd.continuous.continuousOn + obtain ⟨D,hD⟩ := (isCompact_closedBall (0 : Fin l → ℝ) R).exists_bound_of_continuousOn + (hd.continuous_fderiv (by simp)).continuousOn + refine ⟨max (max M D) 0 + 1,by positivity,?_,?_⟩ + · intro x hx + exact (hM x (by simpa using hx)).trans (by grind) + · intro x y hx hy + have he := Convex.norm_image_sub_le_of_norm_fderiv_le + (fun x (_ : x ∈ Metric.closedBall (0 : Fin l → ℝ) R) => hd.differentiable (by simp) x) + hD (convex_closedBall (0 : Fin l → ℝ) R) (by simpa using hy) (by simpa using hx) + exact he.trans (mul_le_mul_of_nonneg_right (by grind) (norm_nonneg _)) + +omit [IsTopologicalGroup G] in +lemma flowWord_integer (hsk : MalcevCharacters.SecondKind c) + (lam : Fin l → ℝ) (j : Fin l → ℕ) (z : ℤ) : + flowWord c k r (fun i => lam i * Ring.choose (z:ℝ) (j i)) = + RationalFactorPeriods.orderedWord (fun i => tailSection c k (r i) (lam i)) j z := by + unfold flowWord RationalFactorPeriods.orderedWord + apply congrArg List.prod + rw [← List.ofFn_eq_map] + apply congrArg List.ofFn + funext i + have he := Ring.map_choose (Int.castRingHom ℝ) z (j i) + change ((Ring.choose z (j i) : ℤ) : ℝ) = Ring.choose (z:ℝ) (j i) at he + dsimp only + rw [← he,mul_comm,section_zpow c hsk] + +end MalcevTailSection +end +end + + + +section + + + +namespace SmoothBinomial +open Filter Set _root_.Polynomial _root_.OAI.Polynomial +open scoped Topology BigOperators +noncomputable section + + + +def universal (j : ℕ) : Polynomial (Polynomial ℝ) := + C (C (j.factorial : ℝ)⁻¹) * + ∏ i ∈ Finset.range j, (X - C (C (i : ℝ) * X)) + +def family (p : Polynomial (Polynomial ℝ)) (t : ℝ) : Polynomial ℝ := + p.map (evalRingHom t) + +lemma continuous_eval_family (p : Polynomial (Polynomial ℝ)) : + Continuous (fun z : ℝ × ℝ => (family p z.1).eval z.2) := by + simp only [family, eval_map, eval₂_eq_sum_range] + apply continuous_finsetSum + intro i _ + exact ((p.coeff i).continuous.comp continuous_fst).mul (continuous_snd.pow i) + +lemma iteratedDeriv_eval (p : Polynomial ℝ) (k : ℕ) : + iteratedDeriv k (fun x => p.eval x) = fun x => (derivative^[k] p).eval x := by + induction k generalizing p with + | zero => rfl + | succ k ih => + rw [iteratedDeriv_succ', show deriv (fun x => p.eval x) = + (fun x => p.derivative.eval x) from funext (fun x => p.deriv)] + simpa only [Function.iterate_succ_apply] using ih p.derivative + +lemma iterate_derivative_family (p : Polynomial (Polynomial ℝ)) (t : ℝ) (k : ℕ) : + derivative^[k] (family p t) = family (derivative^[k] p) t := by + induction k generalizing p with + | zero => rfl + | succ k ih => + rw [Function.iterate_succ_apply, Function.iterate_succ_apply] + rw [show derivative (family p t) = family p.derivative t from derivative_map p _] + exact ih p.derivative + + + +theorem compact_derivative_limit {ι : Type*} {l : Filter ι} + (p : Polynomial (Polynomial ℝ)) (k : ℕ) + {a t : ι → ℝ} {a₀ t₀ : ℝ} + (ha : Tendsto a l (𝓝 a₀)) (ht : Tendsto t l (𝓝 t₀)) + (K : Set ℝ) (hK : IsCompact K) : + TendstoUniformlyOn + (fun n => iteratedDeriv k (fun x => a n * (family p (t n)).eval x)) + (iteratedDeriv k (fun x => a₀ * (family p t₀).eval x)) l K := by + have hder (a t : ℝ) : + iteratedDeriv k (fun x => a * (family p t).eval x) = + fun x => a * (family (derivative^[k] p) t).eval x := by + have heq : (fun x => a * (family p t).eval x) = + (fun x => (C a * family p t).eval x) := by ext x; simp + rw [heq, iteratedDeriv_eval] + have hd : derivative^[k] (C a * family p t) = + C a * derivative^[k] (family p t) := by + induction k with + | zero => rfl + | succ k ih => + rw [Function.iterate_succ_apply', Function.iterate_succ_apply', ih, + derivative_C_mul] + rw [hd, iterate_derivative_family] + simp + simp_rw [hder] + let : CompactSpace K := isCompact_iff_compactSpace.mp hK + let F : (ℝ × ℝ) → K → ℝ := fun z x => + z.1 * (family (derivative^[k] p) z.2).eval (x : ℝ) + have hF : Continuous (Function.uncurry F) := by + apply Continuous.mul (continuous_fst.fst) + exact (continuous_eval_family (derivative^[k] p)).comp + (continuous_fst.snd.prodMk (continuous_subtype_val.comp continuous_snd)) + have hu := hF.tendstoUniformly F (a₀,t₀) + rw [tendstoUniformlyOn_iff_tendstoUniformly_comp_coe] + intro u hu' + exact (ha.prodMk_nhds ht).eventually (hu u hu') + +lemma universal_eval (j : ℕ) (t x : ℝ) : + (family (universal j) t).eval x = + (j.factorial : ℝ)⁻¹ * ∏ i ∈ Finset.range j, (x - (i : ℝ) * t) := by + simp only [family,universal,Polynomial.map_mul,Polynomial.map_C, + Polynomial.map_prod,Polynomial.map_sub,Polynomial.map_X,eval_mul,eval_C, + eval_prod,eval_sub,eval_X] + change (C (j.factorial : ℝ)⁻¹).eval t * + (∏ i ∈ Finset.range j, (x - (C (i:ℝ) * X).eval t)) = _ + simp + +lemma universal_eval_zero (j : ℕ) (x : ℝ) : + (family (universal j) 0).eval x = (j.factorial : ℝ)⁻¹ * x^j := by + simp [universal_eval] + +lemma choose_eq_product (x : ℝ) (j : ℕ) : + Ring.choose x j = (j.factorial : ℝ)⁻¹ * + ∏ i ∈ Finset.range j, (x - (i : ℝ)) := by + rw [Ring.choose_eq_smul, smul_eq_mul, ← aeval_eq_smeval, + aeval_def, ← eval_map, descPochhammer_map, descPochhammer_eval_eq_prod_range] + +lemma scale_identity (j : ℕ) (L x : ℝ) (hL : L ≠ 0) : + L^j * (family (universal j) L⁻¹).eval x = Ring.choose (L*x) j := by + rw [universal_eval, choose_eq_product] + have hp : (L^j) * (∏ i ∈ Finset.range j, (x-(i:ℝ)*L⁻¹)) = + ∏ i ∈ Finset.range j, (L*x-(i:ℝ)) := by + rw [Finset.pow_eq_prod_const L j, ← Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro i _ + field_simp [hL] + calc + _ = (j.factorial : ℝ)⁻¹ * (L^j * ∏ i ∈ Finset.range j, (x-(i:ℝ)*L⁻¹)) := by ring + _ = _ := by rw [hp] + + +lemma amplitude_identity (j : ℕ) (L lam x : ℝ) (hL : L ≠ 0) : + lam * Ring.choose (L*x) j = + (L^j * lam) * (family (universal j) L⁻¹).eval x := by + rw [← scale_identity j L x hL] + ring + + + +theorem smooth_binomial_limit {ι : Type*} {l : Filter ι} + (j k : ℕ) {L lam : ι → ℝ} {c : ℝ} + (hL : Tendsto L l atTop) (hlam : Tendsto (fun n => (L n)^j * lam n) l (𝓝 c)) + (K : Set ℝ) (hK : IsCompact K) : + TendstoUniformlyOn + (fun n => iteratedDeriv k (fun x => lam n * Ring.choose (L n*x) j)) + (iteratedDeriv k (fun x => c * (j.factorial : ℝ)⁻¹ * x^j)) l K := by + have hz : ∀ᶠ n in l, L n ≠ 0 := (hL.eventually_gt_atTop 0).mono (fun _ h => ne_of_gt h) + have ht : Tendsto (fun n => (L n)⁻¹) l (𝓝 0) := tendsto_inv_atTop_zero.comp hL + have hc := compact_derivative_limit (universal j) k hlam ht K hK + have heq : (fun x => c * (family (universal j) 0).eval x) = + (fun x => c * (j.factorial : ℝ)⁻¹ * x^j) := by + ext x; rw [universal_eval_zero]; ring + rw [heq] at hc + apply hc.congr ?_ + filter_upwards [hz] with n hn + intro x _ + have he : (fun x => lam n * Ring.choose (L n*x) j) = + (fun x => ((L n)^j*lam n)*(family (universal j) (L n)⁻¹).eval x) := by + ext y; exact amplitude_identity j _ _ _ hn + rw [he] + + + +theorem smooth_binomial_bounds (j k : ℕ) (A C₀ : ℝ) (hC : 0 ≤ C₀) : + ∃ B > 0, ∀ L lam : ℝ, 1 ≤ L → |L^j*lam| ≤ C₀ → + ∀ b : ℝ, |b| ≤ A*L → + |iteratedDeriv k (fun x => lam * Ring.choose x j) b| ≤ B / L^k := by + obtain ⟨M,hM⟩ := (isCompact_Icc.prod (isCompact_Icc : IsCompact (Icc (-A) A))).exists_bound_of_continuousOn + (continuous_eval_family (derivative^[k] (universal j))).continuousOn + (s := Icc (0:ℝ) 1 ×ˢ Icc (-A) A) + refine ⟨C₀ * max M 0 + 1,by positivity,?_⟩ + intro L lam hL hlam b hb + have hLp : 0 < L := lt_of_lt_of_le zero_lt_one hL + have hLn : L ≠ 0 := ne_of_gt hLp + have hinv : L⁻¹ ∈ Icc (0:ℝ) 1 := by + exact ⟨inv_nonneg.mpr hLp.le,inv_le_one₀ hLp |>.mpr hL⟩ + have hx : |L⁻¹*b| ≤ A := by + calc + _ = |b|/L := by rw [abs_mul,abs_inv,abs_of_pos hLp]; ring + _ ≤ A := (div_le_iff₀ hLp).mpr hb + have hval := hM (L⁻¹,L⁻¹*b) ⟨hinv,abs_le.mp hx⟩ + simp only [Real.norm_eq_abs] at hval + have he : (fun x => lam*Ring.choose x j) = + fun x => (L^j*lam)*(family (universal j) L⁻¹).eval (L⁻¹*x) := by + ext x + have hh := amplitude_identity j L lam (L⁻¹*x) hLn + simpa only [← mul_assoc,mul_inv_cancel₀ hLn,one_mul] using hh + rw [he] + rw [iteratedDeriv_const_mul_field] + have hpoly : ContDiff ℝ k (fun x => (family (universal j) L⁻¹).eval x) := by + simp only [Polynomial.eval_eq_sum_range] + fun_prop + rw [iteratedDeriv_comp_const_mul hpoly,iteratedDeriv_eval, + iterate_derivative_family] + rw [abs_mul] + change |L^j*lam| * |L⁻¹^k * + (family (derivative^[k] (universal j)) L⁻¹).eval (L⁻¹*b)| ≤ _ + rw [abs_mul (L⁻¹^k),abs_pow L⁻¹,abs_inv,abs_of_pos hLp] + have hv0 : |(family (derivative^[k] (universal j)) L⁻¹).eval (L⁻¹*b)| ≤ max M 0 := + hval.trans (le_max_left _ _) + calc + _ ≤ C₀ * ((L⁻¹)^k * max M 0) := + mul_le_mul hlam (mul_le_mul_of_nonneg_left hv0 (by positivity)) + (by positivity) hC + _ = (C₀ * max M 0) / L^k := by simp [div_eq_mul_inv]; ring + _ ≤ (C₀ * max M 0 + 1) / L^k := + div_le_div_of_nonneg_right (by linarith) (pow_nonneg hLp.le _) + +end +end SmoothBinomial + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareHorizontal01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareHorizontal01.lean new file mode 100644 index 0000000000000000000000000000000000000000..7fb8c54cfb13039bf18577f86952b01a1c4ac4d4 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareHorizontal01.lean @@ -0,0 +1,346 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.PairTail06 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped commutatorElement ComplexConjugate +end +end + + + +section +noncomputable section +open scoped BigOperators +open _root_.Polynomial _root_.OAI.Polynomial Finset +namespace RationalFactorPeriods + +def choosePolynomial (j : ℕ) : ℝ[X] := C (j.factorial:ℝ)⁻¹*descPochhammer ℝ j + +lemma choosePolynomial_eval (j : ℕ) (x : ℝ) : + (choosePolynomial j).eval x=Ring.choose x j := by + rw [choosePolynomial,eval_mul,eval_C,Ring.choose_eq_smul,smul_eq_mul, + ← aeval_eq_smeval,aeval_def,← eval_map,descPochhammer_map] + +lemma choosePolynomial_int (j : ℕ) (n : ℤ) : + (choosePolynomial j).eval (n:ℝ)=(Ring.choose n j:ℤ) := by + rw [choosePolynomial_eval] + exact (Ring.map_choose (Int.castRingHom ℝ) n j).symm + +lemma choosePolynomial_natDegree (j : ℕ) : (choosePolynomial j).natDegree ≤ j := by + calc + _ ≤ (C (j.factorial:ℝ)⁻¹).natDegree+(descPochhammer ℝ j).natDegree := natDegree_mul_le + _ = j := by rw [natDegree_C,descPochhammer_natDegree,zero_add] + +variable {G : Type*} [Group G] +def wordCharacterPolynomial {l : ℕ} (χ : G →* Multiplicative ℝ) + (a : Fin l → G) (j : Fin l → ℕ) : ℝ[X] := + ∑ i, C ((χ (a i)).toAdd)*choosePolynomial (j i) + +lemma wordCharacterPolynomial_eval {l : ℕ} (χ : G →* Multiplicative ℝ) + (a : Fin l → G) (j : Fin l → ℕ) (n : ℤ) : + (wordCharacterPolynomial χ a j).eval (n:ℝ)=(χ (orderedWord a j n)).toAdd := by + rw [wordCharacterPolynomial,eval_finsetSum,orderedWord_character] + apply sum_congr rfl + intro i _ + rw [eval_mul,eval_C,choosePolynomial_int,mul_comm] + +lemma wordCharacterPolynomial_degree {l : ℕ} (χ : G →* Multiplicative ℝ) + (a : Fin l → G) (j : Fin l → ℕ) (s : ℕ) + (h : ∀ i, j i ≤ s ∨ χ (a i)=1) : (wordCharacterPolynomial χ a j).natDegree ≤ s := by + apply natDegree_sum_le_of_forall_le + intro i _ + rcases h i with hi | hi + · exact (natDegree_mul_le.trans (by + simpa only [natDegree_C,zero_add] using choosePolynomial_natDegree (j i))).trans hi + · simpa only [hi,toAdd_one,C_0,zero_mul,natDegree_zero] using Nat.zero_le s +end RationalFactorPeriods + +namespace LeibmanSquare +open CubeFaces CubePolynomials RationalFactorPeriods +variable {G : Type*} [Group G] +variable (H : Filtration G) (h0 : H.level 0=⊤) + + + +lemma character_polynomial (s : ℕ) (hs : H.level (s+1)=⊥) + {f : ℤ → G} (hf : Polynomial H 0 f) (χ : G →* Multiplicative ℝ) : + ∃ P : ℝ[X], P.natDegree ≤ s ∧ ∀ n : ℤ, P.eval (n:ℝ)=(χ (f n)).toAdd := by + obtain ⟨a,ha,he⟩ := NilpotentTaylor.exists_taylor (by simpa using hs) + (cube_mem_of_polynomial H hf) + rw [word_eq_orderedWord] at he + refine ⟨wordCharacterPolynomial χ (fun i : Fin (s+1) => a i.val) (fun i => i.val), + wordCharacterPolynomial_degree _ _ _ s (fun i => Or.inl (by omega)),?_⟩ + intro n + rw [wordCharacterPolynomial_eval] + exact congrArg (fun z => (χ (z n)).toAdd) he.symm + + + +lemma remainder_character_polynomial (h1 : H.level 1=⊤) (s : ℕ) + (hs : H.level (s+1)=⊥) {f : ℤ → G} (hf : Polynomial H 0 f) (hf0 : f 0=1) + (χ : H.level 2 →* Multiplicative ℝ) : + ∃ Q : ℝ[X], Q.natDegree ≤ s ∧ Q.eval 0=0 ∧ Q.eval 1=0 ∧ + ∀ n : ℤ, Q.eval (n:ℝ)=(χ (linearRemainder H h0 hf hf0 n)).toAdd := by + obtain ⟨a,ha,he⟩ := NilpotentTaylor.normalized_subgroup_taylor H (s+1) hs f + (cube_mem_of_polynomial H hf) hf0 (by rw [h1]; trivial) + have ha' (i : Fin (s+1)) : i.val+2 ≤ s ∨ χ (a i)=1 := by + by_cases hi : i.val+2 ≤ s + · exact Or.inl hi + · right + have hz : a i=1 := by + apply Subtype.ext + change (a i).val=1 + have hm := H.antitone (by omega : s+1 ≤ i.val+2) (ha i) + simpa only [hs,Subgroup.mem_bot] using hm + rw [hz,map_one] + let Q:=wordCharacterPolynomial χ a (fun i => i.val+2) + have hQ (n : ℤ) : Q.eval (n:ℝ)=(χ (linearRemainder H h0 hf hf0 n)).toAdd := by + rw [wordCharacterPolynomial_eval] + congr 2 + apply Subtype.ext + change (orderedWord a (fun i => i.val+2) n).val=f n*(f 1^n)⁻¹ + rw [he n] + group + refine ⟨Q,wordCharacterPolynomial_degree _ _ _ s ha',?_,?_,hQ⟩ + · have he0 : linearRemainder H h0 hf hf0 0=1 := by + apply Subtype.ext + change f 0*(f 1^(0:ℤ))⁻¹=1 + simp [hf0] + simpa only [Int.cast_zero,he0,map_one,toAdd_one] using hQ 0 + · have he1 : linearRemainder H h0 hf hf0 1=1 := by + apply Subtype.ext + change f 1*(f 1^(1:ℤ))⁻¹=1 + simp + simpa only [Int.cast_one,he1,map_one,toAdd_one] using hQ 1 + +end LeibmanSquare +end +end + + + +section +open scoped commutatorElement +namespace SquareHorizontalCharacter +open CubeFaces LeibmanSquare +variable {G K : Type*} [Group G] [CommGroup K] +variable (H : Filtration G) (h0 : H.level 0 = ⊤) (h1 : H.level 1 = ⊤) + + +def diagonal : G →* level H h0 1 where + toFun g := ⟨(g,g), by simp [mem_level,h1]⟩ + map_one' := rfl + map_mul' _ _ := rfl + + +def lower : H.level 2 →* level H h0 1 where + toFun u := ⟨(1,u), by + refine ⟨(H.level 1).one_mem,H.antitone (by omega) u.property,?_⟩ + simp⟩ + map_one' := rfl + map_mul' u v := by apply Subtype.ext; ext <;> simp + + +def tail (x : level H h0 1) : H.level 2 := ⟨x.val.1⁻¹*x.val.2,x.property.2.2⟩ + +lemma split (x : level H h0 1) : + diagonal H h0 h1 x.val.1 * lower H h0 (tail H h0 x) = x := by + apply Subtype.ext + ext <;> simp [diagonal,lower,tail] + +variable (ξ : level H h0 1 →* K) + + + +theorem character_split (x : level H h0 1) : + ξ x = (ξ.comp (diagonal H h0 h1)) x.val.1 * + (ξ.comp (lower H h0)) (tail H h0 x) := by + simp only [MonoidHom.comp_apply,← map_mul,split H h0 h1] + +include h1 + +lemma lower_conj (g : G) (u : H.level 2) : + ξ (lower H h0 ⟨g*u*g⁻¹,(level_normal H h0 2).conj_mem _ u.property g⟩) = + ξ (lower H h0 u) := by + have he : lower H h0 ⟨g*u*g⁻¹,(level_normal H h0 2).conj_mem _ u.property g⟩ = + diagonal H h0 h1 g * lower H h0 u * (diagonal H h0 h1 g)⁻¹ := by + apply Subtype.ext + ext <;> simp [diagonal,lower] + rw [he,map_mul,map_mul,map_inv] + calc + _ = ξ (lower H h0 u) * (ξ (diagonal H h0 h1 g) * (ξ (diagonal H h0 h1 g))⁻¹) := by ac_rfl + _ = _ := by simp + + +lemma commutator_mem (a b : G) : ⁅a,b⁆ ∈ H.level 2 := by + apply H.commutator_le 1 1 + apply Subgroup.commutator_mem_commutator <;> rw [h1] <;> trivial + + +def pairing (a b : G) : K := + ξ (lower H h0 ⟨⁅a,b⁆,commutator_mem H h1 a b⟩) + +lemma lower_commutator (g : G) (u : H.level 2) : + ξ (lower H h0 ⟨⁅g,(u:G)⁆,commutator_mem H h1 g u⟩) = 1 := by + have he : (⟨⁅g,(u:G)⁆,commutator_mem H h1 g u⟩ : H.level 2) = + ⟨g*u*g⁻¹,(level_normal H h0 2).conj_mem _ u.property g⟩ * u⁻¹ := by + apply Subtype.ext + simp [commutatorElement_def] + rw [he,map_mul,map_inv,map_mul,map_inv,lower_conj H h0 h1 ξ, mul_inv_cancel] + + + +lemma pairing_mul_right (a b c : G) : + pairing H h0 h1 ξ a (b*c) = pairing H h0 h1 ξ a b * pairing H h0 h1 ξ a c := by + let u : H.level 2 := ⟨⁅a,c⁆,commutator_mem H h1 a c⟩ + have he : (⟨⁅a,b*c⁆,commutator_mem H h1 a (b*c)⟩ : H.level 2) = + ⟨⁅a,b⁆,commutator_mem H h1 a b⟩ * + ⟨b*u*b⁻¹,(level_normal H h0 2).conj_mem _ u.property b⟩ := by + apply Subtype.ext + simpa only [u,Subgroup.coe_mul,mul_assoc] using commutatorElement_mul_right_eq_mul_conj a b c + dsimp only [pairing] + rw [he,map_mul,map_mul,lower_conj H h0 h1 ξ] + +lemma pairing_mul_left (a b c : G) : + pairing H h0 h1 ξ (a*b) c = pairing H h0 h1 ξ a c * pairing H h0 h1 ξ b c := by + let u : H.level 2 := ⟨⁅b,c⁆,commutator_mem H h1 b c⟩ + have he : (⟨⁅a*b,c⁆,commutator_mem H h1 (a*b) c⟩ : H.level 2) = + ⟨a*u*a⁻¹,(level_normal H h0 2).conj_mem _ u.property a⟩ * + ⟨⁅a,c⁆,commutator_mem H h1 a c⟩ := by + apply Subtype.ext + exact commutatorElement_mul_left_eq_conj_mul a b c + dsimp only [pairing] + rw [he,map_mul,map_mul,lower_conj H h0 h1 ξ,mul_comm] + + +def pairingHom (a : G) : G →* K where + toFun := pairing H h0 h1 ξ a + map_one' := by + dsimp only [pairing] + have he : (⟨⁅a,1⁆,commutator_mem H h1 a 1⟩ : H.level 2) = 1 := by + apply Subtype.ext + simp [commutatorElement_def] + rw [he,map_one,map_one] + map_mul' := pairing_mul_right H h0 h1 ξ a + +lemma pairing_self (a : G) : pairing H h0 h1 ξ a a = 1 := by + dsimp only [pairing] + have he : (⟨⁅a,a⁆,commutator_mem H h1 a a⟩ : H.level 2) = 1 := by + apply Subtype.ext + simp + rw [he,map_one,map_one] + +lemma pairing_swap (a b : G) : pairing H h0 h1 ξ b a = (pairing H h0 h1 ξ a b)⁻¹ := by + have he : (⟨⁅b,a⁆,commutator_mem H h1 b a⟩ : H.level 2) = + (⟨⁅a,b⁆,commutator_mem H h1 a b⟩ : H.level 2)⁻¹ := by + apply Subtype.ext + simp [commutatorElement_def,mul_assoc] + dsimp only [pairing] + rw [he,map_inv,map_inv] + +lemma diagonal_conj (a g : G) : + ξ (diagonal H h0 h1 (a*g*a⁻¹)) = ξ (diagonal H h0 h1 g) := by + simp only [map_mul,map_inv] + calc + _ = ξ (diagonal H h0 h1 g) * (ξ (diagonal H h0 h1 a) * (ξ (diagonal H h0 h1 a))⁻¹) := by ac_rfl + _ = _ := by simp + +lemma conjugate_lower (a b : G) (u : H.level 2) : + ξ (restrictedConj H h0 h1 a b (lower H h0 u)) = ξ (lower H h0 u) := by + have he : restrictedConj H h0 h1 a b (lower H h0 u) = + lower H h0 ⟨b*u*b⁻¹,(level_normal H h0 2).conj_mem _ u.property b⟩ := by + apply Subtype.ext + change (a*1*a⁻¹,b*u*b⁻¹) = (1,b*u*b⁻¹) + simp + rw [he] + exact lower_conj H h0 h1 ξ b u + +lemma conjugate_diagonal (a b g : G) : + ξ (restrictedConj H h0 h1 a b (diagonal H h0 h1 g)) = + ξ (diagonal H h0 h1 g) * (pairing H h0 h1 ξ a g)⁻¹ * pairing H h0 h1 ξ b g := by + let u : H.level 2 := (⟨⁅a,g⁆,commutator_mem H h1 a g⟩ : H.level 2)⁻¹ * + ⟨⁅b,g⁆,commutator_mem H h1 b g⟩ + have ht : tail H h0 (restrictedConj H h0 h1 a b (diagonal H h0 h1 g)) = + ⟨g⁻¹*u*g⁻¹⁻¹,(level_normal H h0 2).conj_mem _ u.property g⁻¹⟩ := by + apply Subtype.ext + change (a*g*a⁻¹)⁻¹ * (b*g*b⁻¹) = g⁻¹*(⁅a,g⁆⁻¹*⁅b,g⁆)*g⁻¹⁻¹ + simp [commutatorElement_def,mul_assoc] + rw [character_split H h0 h1 ξ,ht] + change ξ (diagonal H h0 h1 (a*g*a⁻¹)) * ξ (lower H h0 _) = _ + rw [diagonal_conj H h0 h1 ξ,lower_conj H h0 h1 ξ] + simp only [u,map_mul,map_inv,pairing,mul_assoc] + + + +theorem conjugate_character (a b : G) (x : level H h0 1) : + ξ (restrictedConj H h0 h1 a b x) = + ξ x * (pairing H h0 h1 ξ a x.val.1)⁻¹ * pairing H h0 h1 ξ b x.val.1 := by + conv_lhs => rw [← split H h0 h1 x] + simp only [map_mul,conjugate_diagonal H h0 h1 ξ,conjugate_lower H h0 h1 ξ] + rw [character_split H h0 h1 ξ x] + simp only [MonoidHom.comp_apply] + ac_rfl + + + +theorem character_lattice_iff (Γ : Subgroup G) (B : Subgroup K) : + (∀ x : level H h0 1, x.val ∈ Γ.prod Γ → ξ x ∈ B) ↔ + (∀ g ∈ Γ, ξ (diagonal H h0 h1 g) ∈ B) ∧ + (∀ u : H.level 2, (u : G) ∈ Γ → ξ (lower H h0 u) ∈ B) := by + constructor + · intro h + constructor + · intro g hg + exact h _ ⟨hg,hg⟩ + · intro u hu + exact h _ ⟨Γ.one_mem,hu⟩ + · rintro ⟨hd,hl⟩ x hx + rw [character_split H h0 h1 ξ] + exact B.mul_mem (hd x.val.1 hx.1) + (hl (tail H h0 x) (Γ.mul_mem (Γ.inv_mem hx.1) hx.2)) + +lemma pairing_lattice (Γ : Subgroup G) (B : Subgroup K) + (hξ : ∀ x : level H h0 1, x.val ∈ Γ.prod Γ → ξ x ∈ B) + {a b : G} (ha : a ∈ Γ) (hb : b ∈ Γ) : pairing H h0 h1 ξ a b ∈ B := by + apply ((character_lattice_iff H h0 h1 ξ Γ B).mp hξ).2 + exact Γ.mul_mem (Γ.mul_mem (Γ.mul_mem ha hb) (Γ.inv_mem ha)) (Γ.inv_mem hb) + +section Topology +variable [TopologicalSpace G] [IsTopologicalGroup G] + [TopologicalSpace K] [IsTopologicalGroup K] + +omit [IsTopologicalGroup G] in +lemma continuous_diagonal : Continuous (diagonal H h0 h1) := by + apply Continuous.subtype_mk + exact continuous_id.prodMk continuous_id + +omit h1 [IsTopologicalGroup G] in +lemma continuous_lower : Continuous (lower H h0) := by + apply Continuous.subtype_mk + exact continuous_const.prodMk continuous_subtype_val + +omit [IsTopologicalGroup K] in +lemma continuous_pairing (hξ : Continuous ξ) : + Continuous (fun p : G × G => pairing H h0 h1 ξ p.1 p.2) := by + apply hξ.comp + apply (continuous_lower H h0).comp + apply Continuous.subtype_mk + simp only [commutatorElement_def] + fun_prop +end Topology + +end SquareHorizontalCharacter + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction01.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea1185371dcbb4f49999a7b649400181fa705a2f --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction01.lean @@ -0,0 +1,306 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.AbelianMalcev02 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +end +end + + + +section +noncomputable section +open scoped ComplexConjugate +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare PolynomialWeyl MeasureTheory UniformSquareObservable CompactFamilyDescent +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + +theorem uniform_unit_linear_square_descent + (H : Filtration G) (h0 : H.level 0 = ⊤) (h1 : H.level 1 = ⊤) + (Γ : Subgroup G) (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1) = ⊥) + [TopologicalSpace.MetrizableSpace (ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs)] + [CompactSpace (ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs)] + (F : C(G ⧸ Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (χ : G → ℂ) + (hχ : ∀ n ∈ H.level s, ‖χ n‖ = 1) + (hw : ∀ n ∈ H.level s, ∀ x : G, + F (QuotientGroup.mk (x*n)) = χ n * F (QuotientGroup.mk x)) + (z : G) (hz : z ∈ H.level s) (hχz : χ z ≠ 1) + (C : Set G) (hCc : IsCompact C) (hC : ∀ g : G, ∃ c ∈ C, c⁻¹*g ∈ Γ) + (δ : ℝ) (hδ : 0 < δ) : + let R := restricted H h0 + letI := last_normal H h0 (by omega : 1 ≤ s) hs + let π := QuotientGroup.mk' (R.level s) + let Q := mapFiltration R π + let X := ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs + letI := TopologicalSpace.metrizableSpaceMetric X + letI : MeasurableSpace X := borel X + ∃ tests : Finset C(X,ℂ), (∀ Ψ∈tests, LipschitzWith 1 Ψ ∧ ‖Ψ‖ ≤ 1) ∧ + ∃ η : ℝ, 0 < η ∧ + ∀ μ : Measure X, IsProbabilityMeasure μ → + SMulInvariantMeasure ((level H h0 1) ⧸ R.level s) X μ → + ∀ (f : ℤ → G) (hf : Polynomial H 0 f) (hf0 : f 0=1), + ∀ N T : ℕ, 0 < N → 0 < T → + δ ≤ ‖mean N (fun n => F (QuotientGroup.mk (f n)))‖ → + 4 * (T : ℝ) / N ≤ δ^2/4 → + ∃ A : Finset ℕ, + (∀ h ∈ A, h < T) ∧ δ^2/8*T ≤ (A.card : ℝ) ∧ + ∀ h ∈ A, ∃ Ψ ∈ tests, ∃ v ∈ C, ∃ γ ∈ Γ, + f 1^(h:ℤ) = v*γ ∧ + let p := fun n => π (linearNormalizedPair H h0 h1 hf + (linearRemainder H h0 hf hf0 h) h v n) + Polynomial Q 0 p ∧ + (∀ ts : List ℤ, s ≤ ts.length → ∀ n, iterDiff ts p n = 1) ∧ + η ≤ ‖mean N (fun n => Ψ (QuotientGroup.mk (p n))) - + ∫ x, Ψ x ∂μ‖ := by + classical + let R := restricted H h0 + let := last_normal H h0 (by omega : 1 ≤ s) hs + let π := QuotientGroup.mk' (R.level s) + let X := ReducedSpace H h0 Γ s (le_trans (by decide : 1 ≤ 2) hs2) hs + let := TopologicalSpace.metrizableSpaceMetric X + let : MeasurableSpace X := borel X + let : BorelSpace X := ⟨rfl⟩ + obtain ⟨S,ε,hε,hdesc⟩ := uniform_dense_linear_square_descent H h0 h1 Γ s hs2 hs + F hF χ hχ hw z hz hχz C hCc hC δ hδ + let K : Set C(X,ℂ) := Subtype.val '' (S : Set {Ψ : C(X,ℂ) // Ψ∈lipschitzMaps}) + have hK : IsCompact K := (S.finite_toSet.image Subtype.val).isCompact + obtain ⟨tests,htests,η,hη,htest⟩ := finite_unit_lipschitz_obstruction K hK ε 2 hε (by norm_num) + refine ⟨tests,htests,η,hη,?_⟩ + intro μ hprob hinv f hf hf0 N T hN hT hdisc hboundary + let := hprob + obtain ⟨A,hAT,hA,hAd⟩ := hdesc μ hprob hinv f hf hf0 N T hN hT hdisc hboundary + refine ⟨A,hAT,hA,?_⟩ + intro h ha + obtain ⟨Ψ,hΨ,v,hv,γ,hγ,hfac,hp,hptop,hdisc⟩ := hAd h ha + let p := fun n => π (linearNormalizedPair H h0 h1 hf + (linearRemainder H h0 hf hf0 h) h v n) + obtain ⟨Φ,hΦ,hdΦ⟩ := htest (FourierObstruction.discrepancy μ N (fun n => QuotientGroup.mk (p n))) + (FourierObstruction.discrepancy_bound μ N hN _) ⟨Ψ.val,⟨Ψ,hΨ,rfl⟩,hdisc⟩ + exact ⟨Φ,hΦ,v,hv,γ,hγ,hfac,hp,hptop,hdΦ⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable (hs : H.level 3=⊥) +variable [((restricted H h0).level 2).Normal] +variable (Γ : Subgroup G) +variable {r : ℕ} (cR : RealCoordinates ((level H h0 1)⧸(restricted H h0).level 2) r) +variable (hskR : SecondKind cR) +variable (hΓR : ∀ g, g∈((Γ.prod Γ).comap (level H h0 1).subtype).map + (QuotientGroup.mk' ((restricted H h0).level 2)) ↔ ∀ i, ∃ z : ℤ, cR.coord g i=z) + +include hskR hΓR hs in + + +theorem quadratic_square_characters + (F : C(G⧸Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (χ : G→ℂ) + (hχ : ∀ n∈H.level 2, ‖χ n‖=1) + (hw : ∀ n∈H.level 2, ∀ x : G, F (QuotientGroup.mk (x*n))=χ n*F (QuotientGroup.mk x)) + (z : G) (hz : z∈H.level 2) (hχz : χ z≠1) + (C : Set G) (hCc : IsCompact C) (hC : ∀ g : G, ∃ c∈C, c⁻¹*g∈Γ) + (δ : ℝ) (hδ : 0<δ) : + ∃ Ξ : Finset (level H h0 1 →* Multiplicative ℝ), + (∀ ξ∈Ξ, Continuous ξ ∧ ∀ x : level H h0 1, x.val∈Γ.prod Γ → ∃ z : ℤ, (ξ x).toAdd=z) ∧ + ∃ A : ℝ, 0 F (QuotientGroup.mk (f n)))‖ → + 4*(T:ℝ)/N ≤ δ^2/4 → + ∃ S : Finset ℕ, (∀ h∈S, h ξ.comp π) + refine ⟨Ξ,?_,A,hA,δ^2/(8*((U.card:ℝ)+1)),by positivity,?_⟩ + · intro ξ hξ + obtain ⟨ζ,hζ,rfl⟩ := Finset.mem_image.mp hξ + refine ⟨(hU ζ hζ).1.comp continuous_quotient_mk',?_⟩ + intro x hx + exact (hU ζ hζ).2 (π x) (Subgroup.mem_map.mpr ⟨x,hx,rfl⟩) + · intro f hf hf0 N T hN hT hmean hbound + obtain ⟨S,hST,hS,hSd⟩ := hdesc (μ:Measure X) inferInstance hμ f hf hf0 N T hN hT hmean hbound + have hget : ∀ h∈S, ∃ ξ∈U, ξ≠1 ∧ ∃ v∈C, ∃ γ∈Γ, + f 1^(h:ℤ)=v*γ ∧ ∃ W : ℝ[X], W.natDegree ≤ 1 ∧ + (∀ n : ℤ, W.eval (n:ℝ)= + (ξ (π (linearNormalizedPair H h0 h1 hf (linearRemainder H h0 hf hf0 h) h v n))).toAdd) ∧ + ∀ j : ℕ, 0 if hh : h∈S then ξ h hh else 1 + have hmap : ∀ h∈S, ξ' h∈U := by intro h hh; simpa [ξ',hh] using hξ h hh + have hUne : U.Nonempty := by obtain ⟨h,hh⟩ := hSne; exact ⟨ξ' h,hmap h hh⟩ + have hcard : U.card • (δ^2/(8*((U.card:ℝ)+1))*(T:ℝ)) ≤ (S.card:ℝ) := by + rw [nsmul_eq_mul] + calc + _ ≤ δ^2/8*(T:ℝ) := by + have hu : (U.card:ℝ)/((U.card:ℝ)+1) ≤ 1 := by apply (div_le_one (by positivity)).mpr; linarith + calc + _ = ((U.card:ℝ)/((U.card:ℝ)+1)) * (δ^2/8*(T:ℝ)) := by + field_simp + _ ≤ 1*(δ^2/8*(T:ℝ)) := mul_le_mul_of_nonneg_right hu (by positivity) + _ = _ := one_mul _ + _ ≤ _ := hS + obtain ⟨ζ,hζ,hfiber⟩ := Finset.exists_le_card_fiber_of_nsmul_le_card_of_maps_to hmap hUne hcard + let B := S.filter (fun h => ξ' h=ζ) + have hBne : B.Nonempty := by + apply Finset.card_pos.mp + have hpos : 0<δ^2/(8*((U.card:ℝ)+1))*(T:ℝ) := by positivity + have hc : 0<(B.card:ℝ) := hpos.trans_le hfiber + exact_mod_cast hc + have hζ0 : ζ≠1 := by + obtain ⟨h,hh⟩ := hBne + have hhS := (Finset.mem_filter.mp hh).1 + have hhζ : ξ h hhS=ζ := by simpa [ξ',hhS] using (Finset.mem_filter.mp hh).2 + exact hhζ ▸ hξ0 h hhS + refine ⟨B,fun h hh => hST h (Finset.mem_filter.mp hh).1,hfiber, + ζ.comp π,Finset.mem_image.mpr ⟨ζ,hζ,rfl⟩,?_,?_⟩ + · intro he + apply hζ0 + apply MonoidHom.ext + intro x + obtain ⟨y,rfl⟩ := QuotientGroup.mk'_surjective (R.level 2) x + exact DFunLike.congr_fun he y + · intro h hh + have hhS := (Finset.mem_filter.mp hh).1 + have hhζ : ξ h hhS=ζ := by simpa [ξ',hhS] using (Finset.mem_filter.mp hh).2 + refine ⟨v h hhS,hv h hhS,γ h hhS,hγ h hhS,hfac h hhS,W h hhS,hW h hhS,?_,hWc h hhS⟩ + intro n + change _=(ζ (π _)).toAdd + rw [← hhζ] + exact hWe h hhS n + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped BigOperators commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace MalcevHorizontal +open RationalLattice CubeFaces LeibmanSquare SquareHorizontalCharacter RealCharacters MalcevCharacters CharacterFactorization +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n d : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) +variable (hlin : ∀ i : Fin d, c.correction (Fin.castLE hd i)=0) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hlevel : ∀ g : G, g∈H.level 2 ↔ horizontal c hd g=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + +include hlin hlevel hΓ in + + +theorem uniform_character_of_commutator_level (hcomm : H.level 2=_root_.commutator G) + (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) + (Ξ : Finset (level H h0 1 →* Multiplicative ℝ)) + (hΞc : ∀ ξ∈Ξ, Continuous ξ) + (hΞΓ : ∀ ξ∈Ξ, ∀ x : level H h0 1, x.val∈Γ.prod Γ → ∃ z : ℤ, (ξ x).toAdd=z) + (δ A : ℝ) (hδ : 0<δ) (hA : 0 ≤ A) : + ∃ U : Finset (G →* Multiplicative ℝ), ∃ C : ℝ, 0 ξ.comp (diagonal H h0 h1))) R + refine ⟨U,C,hC,N₀,hN₀,?_⟩ + intro N hNN ξ hξ hξ0 f hf hf0 hf1 v hv hvΓ S hSN hS hsmall + rcases hdesc N hNN ξ hξ (hΞc ξ hξ) (hΞΓ ξ hξ) f hf hf0 hf1 v hv hvΓ S hSN hS hsmall with hob | hz + · obtain ⟨k,hk,hkR,χ,hχeq,hχ0,hχc,hχΓ,P,hP,hPe,hPc⟩ := hob + refine ⟨χ,?_,hχ0,hχc,hχΓ,P,hP.trans (by omega),hPe,hPc⟩ + exact Finset.mem_union_left _ (hχeq ▸ mem_boundedCharacters c hd hlin R k hkR) + · obtain ⟨hp,q,hq,hqR,P,Q,hP,hQ,hQ0,hQ1,hPe,hQe,hPc,hQc⟩ := hz + have hd0 : ξ.comp (diagonal H h0 h1)≠1 := by + intro he + let χ := intScale (ξ.comp (lower H h0)) q + have hc := zero_pairing_kernel H h0 h1 ξ q hp + have hk := lower_kernel_lt H χ (intScale_ne_one _ hq (lower_ne_one_of_diagonal H h0 h1 ξ hξ0 he)) + have hle : H.level 2 ≤ χ.ker.map (H.level 2).subtype := by + apply hcomm.le.trans + rw [_root_.commutator_def] + exact Subgroup.commutator_le.mpr (fun a _ b _ => hc a b) + exact (not_le_of_gt hk) hle + let χ := intScale (ξ.comp (diagonal H h0 h1)) q + refine ⟨χ,Finset.mem_union_right _ (mem_scaledFamily (Finset.mem_image.mpr ⟨ξ,hξ,rfl⟩) hqR), + intScale_ne_one _ hq hd0,intScale_continuous _ q ((hΞc ξ hξ).comp (diagonal_continuous H h0 h1)), + intScale_integral _ q Γ (diagonal_integral H h0 h1 ξ Γ (hΞΓ ξ hξ)), + Polynomial.C (q:ℝ)*P,(natDegree_C_mul_le _ _).trans hP,?_,?_⟩ + · intro z + simp only [eval_mul,eval_C,hPe,intScale_apply,χ] + · intro j hj + simpa only [coeff_C_mul] using hPc j hj + +end MalcevHorizontal + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction02.lean new file mode 100644 index 0000000000000000000000000000000000000000..935e86fd645ffb91a8e0299f174f45cfea131f6c --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction02.lean @@ -0,0 +1,298 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.PairTail04 +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped BigOperators commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus MalcevHorizontal +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + +omit [IsTopologicalGroup G] in +lemma compact_horizontal_representatives [IsTopologicalGroup G] + {n d : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) + (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) : + ∃ C : Set G, IsCompact C ∧ (∀ g : G, ∃ a∈C, a⁻¹*g∈Γ) ∧ + ∀ a∈C, ‖horizontal c hd a‖ ≤ 1 := by + let B : Set (Fin n→ℝ) := Set.pi Set.univ (fun _ => Set.Icc (0:ℝ) 1) + have hB : IsCompact B := isCompact_univ_pi (fun _ => isCompact_Icc) + refine ⟨c.coord.symm '' B,hB.image c.coord.symm.continuous,?_,?_⟩ + · intro g + refine ⟨reduceCoordinates c g n,⟨c.coord (reduceCoordinates c g n),?_,c.coord.symm_apply_apply _⟩, + reduceCoordinates_coset c Γ hΓ g n⟩ + intro i _ + exact ⟨(reduceCoordinates_bounds c g n i i.isLt).1,(reduceCoordinates_bounds c g n i i.isLt).2.le⟩ + · intro a ha + obtain ⟨x,hx,rfl⟩ := ha + apply (pi_norm_le_iff_of_nonneg (by norm_num : (0:ℝ) ≤ 1)).mpr + intro i + change |c.coord (c.coord.symm x) (Fin.castLE hd i)| ≤ 1 + rw [c.coord.apply_symm_apply] + have hi := hx (Fin.castLE hd i) (Set.mem_univ _) + exact (abs_of_nonneg hi.1).trans_le hi.2 + +lemma square_shift_scales (δ : ℝ) (hδ : 0<δ) : + ∃ k : ℕ, 0 F (QuotientGroup.mk (f n)))‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 (hΞ ξ h).1) (fun ξ h => (hΞ ξ h).2) + (ρ/(2*k)) B (div_pos hρ hden) hB.le + refine ⟨U,A,hA,max N₀ (2*k),lt_of_lt_of_le hN₀ (le_max_left _ _),?_⟩ + intro N hNN f hf hf0 hf1 hmean + have hNN₀ := (le_max_left N₀ (2*k)).trans hNN + have hNk := (le_max_right N₀ (2*k)).trans hNN + obtain ⟨hT,hTN,hTd,hbound⟩ := hscale N hNk + have hN : 0 if hh : h∈S then v h hh else reduceCoordinates c (f 1^h) n + have hv' (h : ℕ) : ‖horizontal c hd (v' h)‖ ≤ 1 := by + dsimp [v']; split_ifs with hh + · exact hCb _ (hv h hh) + · exact reduced_horizontal_bound c hd _ + have hvΓ' (h : ℕ) : (v' h)⁻¹*f 1^h∈Γ := by + dsimp [v']; split_ifs with hh + · have he : f 1^h=v h hh*γ h hh := by simpa only [zpow_natCast] using hfac h hh + rw [he,inv_mul_cancel_left] + exact hγ h hh + · exact reduceCoordinates_coset c Γ hΓ _ n + apply hdesc N hNN₀ ξ hξ hξ0 f hf hf0 hf1 v' hv' hvΓ' S + · intro h hh + exact Finset.mem_range.mpr ((hST h hh).trans_le hTN) + · calc + ρ/(2*k)*(N:ℝ) = ρ*((N:ℝ)/(2*k)) := by ring + _ ≤ ρ*((N/k:ℕ):ℝ) := mul_le_mul_of_nonneg_left hTd hρ.le + _ ≤ _ := hS + · intro h hh + refine ⟨W h hh,?_,fun j hj _ => hWc h hh j hj⟩ + simpa only [v',dite_eq_left hh] using hWe h hh + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus MalcevHorizontal +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma integer_linear_return [TopologicalSpace G] [IsTopologicalGroup G] + (f : ℤ→G) (γ : G) (ξ : G→*Multiplicative ℝ) + (a : ℤ) (ha : (ξ γ).toAdd=(a:ℝ)) (P : ℝ[X]) (hP : P.natDegree ≤ 2) + (hPe : ∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z*(γ^z)⁻¹)).toAdd) + (A : ℝ) (N : ℕ) + (hPc : ∀ j : ℕ, 0 F (QuotientGroup.mk (f n)))‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 f n*(γ^n)⁻¹) + hg hg0 (by + change ‖horizontal c hd ((fun n : ℤ => f n*(γ^n)⁻¹) 1)‖ ≤ 1 + rw [hg1]; exact reduced_horizontal_bound c hd _) (by simpa only [hge] using hmean) + obtain ⟨a,ha⟩ := hξΓ γ hγ + exact ⟨ξ,hξ,hξ0,hξc,hξΓ,integer_linear_return f γ ξ a ha P hP hPe A N hPc⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus MalcevHorizontal +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) (hcomm : H.level 2=_root_.commutator G) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val F (QuotientGroup.mk (f n)))‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 by simpa only [hq2] using hq 2 g + let hcent := last_central_ambient H h1 2 hs + let := tailAction c hsk (H.level 2) Γ hcent htail hΓ + let := continuous_tailAction c hsk (H.level 2) Γ hcent htail hΓ + let E := {F : C(G⧸Γ,ℂ) // F∈TorusVerticalFourier.eigenfunctions (d:=Fin d)} + have hd : (Submodule.span ℂ (Set.range (fun F : E => F.val))).topologicalClosure=⊤ := by + change (Submodule.span ℂ (Set.range ((↑) : E → C(G⧸Γ,ℂ)))).topologicalClosure=⊤ + have he : Set.range ((↑) : E → C(G⧸Γ,ℂ))=TorusVerticalFourier.eigenfunctions (d:=Fin d) := by + ext F + exact ⟨fun ⟨x,hx⟩ => hx ▸ x.property,fun hF => ⟨⟨F,hF⟩,rfl⟩⟩ + rw [he] + exact + (TorusVerticalFourier.eigenfunctions_dense (d:=Fin d) (X:=G⧸Γ)) + obtain ⟨S,η,hη,htest⟩ := TorusVerticalFourier.finite_tests_of_dense_span (fun F : E => F.val) + hd K hK δ 2 hδ (by norm_num) + have hproduce (F : E) : + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F.val‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 (hA F).le) + dsimp [B] + linarith + have hM : 0 QuotientGroup.mk (f k))) + (FourierObstruction.discrepancy_bound μ N hN _) hdisc + have hFi : N₀ F ≤ M := by + exact (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hF).trans (Nat.le_add_left _ _) + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,hPc⟩ := hp F N (hFi.trans hMN) f hf hf0 hlarge + have hAB : A F ≤ B := by + have hh := Finset.single_le_sum (f:=A) (fun F (_ : F∈S) => (hA F).le) hF + dsimp [B] + linarith + refine ⟨ξ,Finset.mem_biUnion.mpr ⟨F,hF,hξ⟩,hξ0,hξc,hξΓ,P,hP,hPe,?_⟩ + intro j hj + obtain ⟨z,hz⟩ := hPc j hj + exact ⟨z,hz.trans (div_le_div_of_nonneg_right hAB (by positivity))⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) (hcomm : H.level 2=_root_.commutator G) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 FiniteCoverObservable.translated Q p.1 p.2 + let K' := T '' (C ×ˢ K) + have hK' : IsCompact K' := (hC.prod hK).image (FiniteCoverObservable.continuous_translated Q) + obtain ⟨U,A,hA,N₀,hN₀,hprod⟩ := quadratic_normalized_compact_producer c hsk H h0 h1 hs hcomm + q hqbound hq2 hq Γ hΓ μ K' hK' δ hδ + refine ⟨U,A,hA,N₀,hN₀,?_⟩ + intro N hN f hf ⟨F,hF,hdisc⟩ + obtain ⟨v,hv,hγ⟩ := hrep (f 0) + let γ := v⁻¹*f 0 + have hav : f 0=v*γ := by simp [γ] + let g : ℤ→G := fun n => γ*(f 0)⁻¹*f n*γ⁻¹ + obtain ⟨hg,hg0,hge⟩ := constant_normalization H h0 Γ hf v γ hγ hav + let F' := T (v,F) + have hF' : F'∈K' := ⟨(v,F),⟨hv,hF⟩,rfl⟩ + have he (n : ℕ) : F' (QuotientGroup.mk (g n))=F (QuotientGroup.mk (f n)) := by + change F (QuotientGroup.mk (v*g n))=F (QuotientGroup.mk (f n)) + rw [hge] + have hint : (∫ x,F' x ∂μ)=(∫ x,F x ∂μ) := by + change (∫ x,F (v • x) ∂μ)=_ + exact integral_smul_eq_self F + have hdisc' : δ ≤ ‖FourierObstruction.discrepancy μ N (fun k => QuotientGroup.mk (g k)) F'‖ := by + change δ ≤ ‖mean N (fun n => F' (QuotientGroup.mk (g n)))-(∫ x,F' x ∂μ)‖ + change δ ≤ ‖mean N (fun n => F (QuotientGroup.mk (f n)))-(∫ x,F x ∂μ)‖ at hdisc + simpa only [he,hint] using hdisc + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,hPc⟩ := hprod N hN g hg hg0 ⟨F',hF',hdisc'⟩ + refine ⟨ξ,hξ,hξ0,hξc,hξΓ,P+Polynomial.C (ξ (f 0)).toAdd,?_,?_,?_⟩ + · exact natDegree_add_le_of_degree_le hP (by simp) + · intro z + simp only [eval_add,eval_C,hPe,g,map_mul,map_inv,toAdd_mul,toAdd_inv] + ring + · intro j hj + obtain ⟨z,hz⟩ := hPc j hj + refine ⟨z,?_⟩ + simpa only [coeff_add,coeff_C,ite_eq_right (Nat.ne_of_gt hj),add_zero] using hz + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) (hcomm : H.level 2=_root_.commutator G) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 QuotientGroup.mk (f k)) F‖ ≤ δ/2 := by + change ‖(𝔼 k∈Finset.range N,F (QuotientGroup.mk (f k)))-(∫ x,F x ∂μ)‖ ≤ _ + rw [← Finset.expect_const (s:=Finset.range N) + (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)) (∫ x,F x ∂μ),← Finset.expect_sub_distrib] + exact (RCLike.norm_expect_le (K:=ℂ)).trans (Finset.expect_le + (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)) (fun k hk => (hh k hk).le)) + linarith + obtain ⟨k,hk,hkdisc⟩ := hp + have hc : LeibmanSquare.Polynomial H 0 (fun _ : ℤ => f k) := + polynomial_of_cube_mem H (const_mem (by rw [h0]; trivial)) + have hcd : δ/2 ≤ ‖FourierObstruction.discrepancy μ M + (fun _ => QuotientGroup.mk (f k)) F‖ := by + simpa only [FourierObstruction.discrepancy,LinearMap.coe_mk,AddHom.coe_mk, + Finset.expect_const (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hM))] using hkdisc + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,_⟩ := hprod M le_rfl (fun _ => f k) hc ⟨F,hF,hcd⟩ + obtain ⟨P,hP,hPe⟩ := character_polynomial H 2 hs hf ξ + refine ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,?_⟩ + intro j hj + by_cases hj2 : j ≤ 2 + · refine ⟨round (P.coeff j),(abs_sub_round _).trans ?_⟩ + apply (le_div_iff₀ (pow_pos (by positivity : (0:ℝ) QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 x) (by rw [htop]; exact @continuous_id _ (QuotientGroup.instTopologicalSpace Γ)) + let pull := @ContinuousMap.compCLM (G⧸Γ) (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) + mtr.toUniformSpace.toTopologicalSpace ℂ ℂ _ _ _ _ _ _ e0 + have hK' : IsCompact (pull '' K) := hK.image pull.continuous + obtain ⟨U,A,hA,hprod⟩ := quadratic_compact_all_lengths c hsk H h0 h1 hs hcomm + q hqbound hq2 hq Γ hΓ μ (pull '' K) hK' δ hδ + refine ⟨U,A,hA,?_⟩ + intro N hN f hf ⟨F,hFL,hFn,hdisc⟩ + apply hprod N hN f hf + refine ⟨pull F,⟨F,hunit F hFL hFn,rfl⟩,?_⟩ + change δ ≤ ‖mean N (fun k => F (QuotientGroup.mk (f k)))-(∫ x,F x ∂μ)‖ + exact hdisc + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +namespace LeibmanSquare +open CubeFaces CubePolynomials RationalFactorPeriods BinomialDifference +variable {G : Type*} [Group G] + + + +lemma character_binomial_expansion (H : Filtration G) (s : ℕ) + (hs : H.level (s+1)=⊥) {f : ℤ→G} (hf : Polynomial H 0 f) + (χ : G→*Multiplicative ℝ) (P : ℝ[X]) + (hPe : ∀ n : ℤ, P.eval (n:ℝ)=(χ (f n)).toAdd) : + ∀ n : ℤ, (χ (f n)).toAdd = + ∑ j : Fin (s+1), coefficient ℝ j.val P * (Ring.choose n j.val : ℤ) := by + obtain ⟨a,ha,he⟩ := NilpotentTaylor.exists_taylor (by simpa using hs) + (cube_mem_of_polynomial H hf) + rw [word_eq_orderedWord] at he + let b : Fin (s+1)→G := fun j => a j.val + have hp : P=wordCharacterPolynomial χ b (fun j => j.val) := by + apply Polynomial.eq_of_eval_nat_eq + intro n + rw [← Int.cast_natCast (R:=ℝ) n,hPe,wordCharacterPolynomial_eval] + exact congrArg (fun u => (χ (u (n:ℤ))).toAdd) he + have hcoef (j : Fin (s+1)) : + coefficient ℝ j.val (wordCharacterPolynomial χ b (fun j => j.val))=(χ (b j)).toAdd := by + simpa only [Nat.add_zero] using coefficient_word χ b 0 j + intro n + rw [← hPe n,hp,wordCharacterPolynomial,eval_finsetSum] + apply Finset.sum_congr rfl + intro j _ + rw [eval_mul,eval_C,choosePolynomial_int] + exact congrArg (fun r : ℝ => r*(Ring.choose n j.val:ℤ)) (hcoef j).symm + +end LeibmanSquare +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) (hcomm : H.level 2=_root_.commutator G) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ b : Fin (t+d)→ℤ, b≠0 ∧ (∀ i, |(b i:ℝ)|≤A) ∧ (∀ i, t ≤ i.val → b i=0) ∧ + (∀ g : G, (ξ g).toAdd=∑ i, c.coord g i*(b i:ℝ)) ∧ + ∃ α : ℕ→ℝ, (∀ j : ℕ, 2 Finset.sum_nonneg (fun i _ => abs_nonneg _)) + let A : ℝ := 1+S+BinomialDifference.conversionBound 2*C + have hconv : 0 BinomialDifference.coefficient ℝ j P,?_,?_,?_⟩ + · intro hb0 + apply hξ0 + ext g + apply Multiplicative.toAdd.injective + change (ξ g).toAdd=0 + rw [hb,hb0] + simp + · intro i + have h1 : |(ξ (axis c i 1)).toAdd| ≤ ∑ j, |(ξ (axis c j 1)).toAdd| := + Finset.single_le_sum (f := fun j : Fin (t+d) => |(ξ (axis c j 1)).toAdd|) (fun j _ => abs_nonneg _) (Finset.mem_univ i) + have h2 : (∑ j, |(ξ (axis c j 1)).toAdd|)≤S := + Finset.single_le_sum (f := fun χ : G→*Multiplicative ℝ => ∑ j, |(χ (axis c j 1)).toAdd|) (fun χ _ => Finset.sum_nonneg (fun j _ => abs_nonneg _)) hξ + rw [hbi] + dsimp [A] + linarith + · intro i hi + have hai : axis c i 1∈H.level 2 := by + apply (hq 2 _).mpr + intro j hj + have hji : j≠i := by intro he; subst j; rw [hq2] at hj; omega + simp [coord_axis,hji] + have halt : ξ (axis c i 1)=1 := Abelianization.commutator_subset_ker ξ (hcomm ▸ hai) + apply Int.cast_injective (α:=ℝ) + rw [hbi,halt] + change (0:ℝ)=(0:ℤ) + norm_num + · intro j hj + exact BinomialDifference.coefficient_eq_zero ℝ j P (hP.trans_lt hj) + · exact character_binomial_expansion H 2 hs hf ξ P hPe + · intro j hj + have hNr : 1≤(N:ℝ) := by exact_mod_cast hN + have hbnd := BinomialDifference.coefficient_bound 2 1 P hP (N:ℝ) C hNr hC.le + (fun i hi => hPc i hi) j hj + apply hbnd.trans + dsimp [A] + linarith + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped BigOperators +namespace RationalCharacterFirst +open RationalLattice IntegerHyperplane MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] {n : ℕ} + + + +theorem exists_strict_refined_integer_cover + (c : RealCoordinates G (n+1)) (χ : G→*Multiplicative ℝ) + (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + (hcont : Continuous χ) (hz : ∀ g∈Γ, ∃ z : ℤ, (χ g).toAdd=z) + (H : Subgroup G) (r : ℕ) + (hH : ∀ g : G, g∈H ↔ ∀ i : Fin (n+1), i.val mul_comm _ _) + have hrp : r≤p.val := by + by_contra hrp + apply hne + ext g + apply Multiplicative.toAdd.injective + change (χ g.val).toAdd=0 + rw [he] + change (∑ i, (k i:ℝ)*(secondCoordinates c).coord g.val i)=0 + apply Finset.sum_eq_zero + intro i _ + by_cases hir : i.val c.coord (d.coord.symm x) i) := by + intro i + change RationalPolynomialMap.IsPolynomial (fun x => c.coord (expProduct c (splitLift k p x)) i) + exact polynomialMap_expProduct c (fun j => splitLift_polynomial k p j) i + obtain ⟨Λ,e,hΛ,hle,hindex,hzero⟩ := exists_integer_sublattice c d (MonoidHom.id G) + hdpoly Γ hΓ continuous_id Function.injective_id + have hadapt (K : Subgroup G) (s : ℕ) + (hK : ∀ g : G, g∈K ↔ ∀ i : Fin (n+1), i.val imp_congr_right (fun _ => (hzero g i).symm)) + refine ⟨Λ,secondCoordinates e,secondCoordinates_secondKind e, + expCoordinates_lattice e Λ hΛ,hle,hindex,by omega,?_,?_⟩ + · have hd : deletedCutoff p r+1=r+1 := by simp [deletedCutoff,not_lt.mpr hrp] + exact secondCoordinates_adapted e (H⊓χ.ker) (r+1) (by simpa only [hd] using hadapt H r hH) + · intro K s hs hK + refine ⟨deletedCutoff p s+1,?_,secondCoordinates_adapted e (K⊓χ.ker) _ (hadapt K s hK)⟩ + unfold deletedCutoff + split_ifs <;> omega + +end RationalCharacterFirst + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction05.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction05.lean new file mode 100644 index 0000000000000000000000000000000000000000..e45b22ae2a5b4d83c9dac2f44d0c86595cfaf9d2 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction05.lean @@ -0,0 +1,332 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction04 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped BigOperators +end +end + + + +section +noncomputable section +open scoped commutatorElement +namespace RationalTailCoordinates +open RationalLattice MalcevCharacters CubeFaces +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {r n : ℕ} (c : RealCoordinates G (r+(n+1))) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ r+(n+1)) (hq2 : q 2=r) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (r+(n+1)), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +include hsk h0 h1 hqbound hq2 hq hΓ in + + +theorem strict_filtration_refinement_geometry + (χ : H.level 2→*Multiplicative ℝ) (hχ : Continuous χ) + (hχΓ : ∀ g : H.level 2, g.val∈Γ → ∃ z : ℤ, (χ g).toAdd=z) + (hc : ∀ a b : G, ⁅a,b⁆∈χ.ker.map (H.level 2).subtype) (hχ0 : χ≠1) : + ∃ Λ : Subgroup G, ∃ e : RealCoordinates G (r+(n+1)), SecondKind e ∧ + (∀ g : G, g∈Λ ↔ ∀ i, ∃ z : ℤ, e.coord g i=z) ∧ + Λ≤Γ ∧ (Λ.subgroupOf Γ).FiniteIndex ∧ + ∃ q' : ℕ→ℕ, (∀ k, q' k ≤ r+(n+1)) ∧ q' 2=r+1 ∧ + ∀ k (g : G), g∈(H.refine (χ.ker.map (H.level 2).subtype) hc).level k ↔ + ∀ i : Fin (r+(n+1)), i.val < q' k → e.coord g i=0 := by + classical + have htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (r+(n+1)), i.val < r → c.coord g i=0 := + fun g => by simpa only [hq2] using hq 2 g + have hcomm : _root_.commutator G ≤ χ.ker.map (H.level 2).subtype := by + apply Subgroup.commutator_le.mpr + intro a _ b _ + exact hc a b + obtain ⟨ψ,hψ,hagree,hint,_⟩ := exists_integer_extension c (H.level 2) htail hsk Γ hΓ χ hχ hχΓ hcomm + have hnψ : ψ.comp (H.level 2).subtype≠1 := by rwa [hagree] + obtain ⟨Λ,e,hesk,hΛ,hle,hindex,hr,hsecond,hall⟩ := + RationalCharacterFirst.exists_strict_refined_integer_cover c ψ Γ hΓ hψ hint (H.level 2) r htail hnψ + have href (k : ℕ) (hk : 2 ≤ k) : + (H.refine (χ.ker.map (H.level 2).subtype) hc).level k=H.level k⊓ψ.ker := by + simp only [Filtration.refine,not_lt.mpr hk,ite_false] + rw [mapped_kernel_eq_inter (H.level 2) χ ψ hagree,← inf_assoc, + inf_eq_left.mpr (H.antitone hk)] + have hsecond' : ∀ g : G, g∈(H.refine (χ.ker.map (H.level 2).subtype) hc).level 2 ↔ + ∀ i : Fin (r+(n+1)), i.val < r+1 → e.coord g i=0 := by + intro g + rw [href 2 le_rfl] + exact hsecond g + have hall' (k : ℕ) : ∃ u : ℕ, u ≤ r+(n+1) ∧ + ∀ g : G, g∈(H.refine (χ.ker.map (H.level 2).subtype) hc).level k ↔ + ∀ i : Fin (r+(n+1)), i.val < u → e.coord g i=0 := by + by_cases hk : k < 2 + · refine ⟨0,by omega,?_⟩ + have htop : H.level k=⊤ := by rcases (by omega : k=0 ∨ k=1) with he | he <;> simpa only [he] using (by first | exact h0 | exact h1) + intro g + simp only [Filtration.refine,hk,ite_true,htop,Subgroup.mem_top,Nat.not_lt_zero,IsEmpty.forall_iff,implies_true] + · obtain ⟨u,hu,he⟩ := hall (H.level k) (q k) (hqbound k) (hq k) + refine ⟨u,hu,?_⟩ + intro g + rw [href k (by omega)] + exact he g + choose q₀ hq₀ hq₀e using hall' + let q' : ℕ→ℕ := fun k => if k=2 then r+1 else q₀ k + refine ⟨Λ,e,hesk,hΛ,hle,hindex,q',?_,by simp [q'],?_⟩ + · intro k + dsimp [q'] + split_ifs + · omega + · exact hq₀ k + · intro k g + by_cases hk : k=2 + · simpa only [hk,q',ite_true] using hsecond' g + · simpa only [q',hk,ite_false] using hq₀e k g + +end RationalTailCoordinates +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + + +def QuadraticCharacterData (Γ : Subgroup G) (A : ℝ) (N : ℕ) (f : ℤ→G) + (ξ : G→*Multiplicative ℝ) : Prop := + ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, QuadraticCharacterData Γ A N f ξ + +def QuadraticNormalizedEstimate (H : Filtration G) (Γ : Subgroup G) + [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] [CompactSpace (G⧸Γ)] + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] (K : Set C(G⧸Γ,ℂ)) (δ : ℝ) : Prop := + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, QuadraticCharacterData Γ A N f ξ + +omit [IsTopologicalGroup G] in +lemma QuadraticCharacterData.mono [IsTopologicalGroup G] + {Γ : Subgroup G} {A B : ℝ} {N : ℕ} {f : ℤ→G} + {ξ : G→*Multiplicative ℝ} (hd : QuadraticCharacterData Γ A N f ξ) (hAB : A≤B) : + QuadraticCharacterData Γ B N f ξ := by + obtain ⟨hξ,hc,hΓ,P,hP,hPe,hPc⟩ := hd + refine ⟨hξ,hc,hΓ,P,hP,hPe,?_⟩ + intro j hj + obtain ⟨z,hz⟩ := hPc j hj + exact ⟨z,hz.trans (div_le_div_of_nonneg_right hAB (by positivity))⟩ + + + +def QuadraticRankStatement (G : Type*) [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + (n k : ℕ) : Prop := + ∀ (c : RealCoordinates G n), SecondKind c → + ∀ (H : Filtration G), H.level 0=⊤ → H.level 1=⊤ → H.level 3=⊥ → + ∀ q : ℕ→ℕ, (∀ i, q i ≤ n) → + (∀ i (g : G), g∈H.level i ↔ ∀ j : Fin n, j.val < q i → c.coord g j=0) → + n-q 2 ≤ k → + ∀ (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z), + ∀ [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)], + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + ∀ (μ : Measure (G⧸Γ)), ∀ [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ], + ∀ K : Set C(G⧸Γ,ℂ), IsCompact K → ∀ δ : ℝ, 0<δ → + QuadraticCompactEstimate H Γ μ K δ + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus MalcevHorizontal +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n d r : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) +variable (hlin : ∀ i : Fin d, c.correction (Fin.castLE hd i)=0) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) +variable [((restricted H h0).level 2).Normal] +variable (hlevel : ∀ g : G, g∈H.level 2 ↔ horizontal c hd g=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable (cR : RealCoordinates ((level H h0 1)⧸(restricted H h0).level 2) r) +variable (hskR : SecondKind cR) +variable (hΓR : ∀ g, g∈((Γ.prod Γ).comap (level H h0 1).subtype).map + (QuotientGroup.mk' ((restricted H h0).level 2)) ↔ ∀ i, ∃ z : ℤ, cR.coord g i=z) + +variable {m : ℕ} (c₂ : RealCoordinates (H.level 2) m) (hsk₂ : SecondKind c₂) +variable (hΓ₂ : ∀ x : H.level 2, x.val∈Γ ↔ ∀ i, ∃ z : ℤ, c₂.coord x i=z) +variable (r₂ : Fin 3→ℕ) +variable (hlevel₂ : ∀ i (x : H.level 2), x.val∈H.level (i.val+2) ↔ + ∀ u : Fin m, u.val < r₂ i → c₂.coord x u=0) +include hlin hlevel hΓ hskR hΓR h1 hs hsk₂ hΓ₂ hlevel₂ in + + +theorem quadratic_vertical_factor_alternative (E : ℝ) + (F : C(G⧸Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (χ : G→ℂ) + (hχ : ∀ n∈H.level 2, ‖χ n‖=1) + (hw : ∀ n∈H.level 2, ∀ x : G, F (QuotientGroup.mk (x*n))=χ n*F (QuotientGroup.mk x)) + (z : G) (hz : z∈H.level 2) (hχz : χ z≠1) (δ : ℝ) (hδ : 0<δ) : + ∃ U : Finset (G→*Multiplicative ℝ), ∃ V : Finset (H.level 2→*Multiplicative ℝ), + ∃ A : ℝ, 0 F (QuotientGroup.mk (f n)))‖ → + (∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 (hΞ ξ h).1) (fun ξ h => (hΞ ξ h).2) + (ρ/(2*k)) B E (div_pos hρ hden) hB.le + refine ⟨U,V,A,hA,B',hB',Tmax,hTmax,max N₀ (2*k),lt_of_lt_of_le hN₀ (le_max_left _ _),?_⟩ + intro N hNN f hf hf0 hf1 hmean + have hNN₀ := (le_max_left N₀ (2*k)).trans hNN + have hNk := (le_max_right N₀ (2*k)).trans hNN + obtain ⟨hT,hTN,hTd,hbound⟩ := hscale N hNk + have hN : 0 if hh : h∈S then v h hh else reduceCoordinates c (f 1^h) n + have hv' (h : ℕ) : ‖horizontal c hd (v' h)‖ ≤ 1 := by + dsimp [v']; split_ifs with hh + · exact hCb _ (hv h hh) + · exact reduced_horizontal_bound c hd _ + have hvΓ' (h : ℕ) : (v' h)⁻¹*f 1^h∈Γ := by + dsimp [v']; split_ifs with hh + · have he : f 1^h=v h hh*γ h hh := by simpa only [zpow_natCast] using hfac h hh + rw [he,inv_mul_cancel_left] + exact hγ h hh + · exact reduceCoordinates_coset c Γ hΓ _ n + apply hdesc N hNN₀ ξ hξ hξ0 f hf hf0 hf1 v' hv' hvΓ' S + · intro h hh + exact Finset.mem_range.mpr ((hST h hh).trans_le hTN) + · calc + ρ/(2*k)*(N:ℝ) = ρ*((N:ℝ)/(2*k)) := by ring + _ ≤ ρ*((N/k:ℕ):ℝ) := mul_le_mul_of_nonneg_left hTd hρ.le + _ ≤ _ := hS + · intro h hh + refine ⟨W h hh,?_,fun j hj _ => hWc h hh j hj⟩ + simpa only [v',dite_eq_left hh] using hWe h hh + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters RationalTailCoordinates +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus MalcevHorizontal +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + +include hsk h0 h1 hs hqbound hq2 hq hΓ in + + +theorem quadratic_source_factor_alternative + (F : C(G⧸Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (χ : G→ℂ) + (hχ : ∀ n∈H.level 2, ‖χ n‖=1) + (hw : ∀ n∈H.level 2, ∀ x : G, F (QuotientGroup.mk (x*n))=χ n*F (QuotientGroup.mk x)) + (z : G) (hz : z∈H.level 2) (hχz : χ z≠1) (δ : ℝ) (hδ : 0<δ) : + let htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq 2 g + let c₂ := tailCoordinates c (H.level 2) htail + ∃ U : Finset (G→*Multiplicative ℝ), ∃ V : Finset (H.level 2→*Multiplicative ℝ), + ∃ A : ℝ, 0 F (QuotientGroup.mk (f n)))‖ → + (∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 by simpa only [hq2] using hq 2 g + have hcomm : _root_.commutator G ≤ H.level 2 := by + apply Subgroup.commutator_le.mpr + intro a _ b _ + exact SquareHorizontalCharacter.commutator_mem H h1 a b + let cH := horizontalCoordinates c hsk (H.level 2) t hcomm (fun g hg => (htail g).mp hg) + have hlin : ∀ i : Fin t, cH.correction (i.castLE (Nat.le_add_right t d))=0 := by + intro i + exact horizontalCoordinates_correction c hsk (H.level 2) t hcomm + (fun g hg => (htail g).mp hg) _ i.isLt + have hlevel : ∀ g : G, g∈H.level 2 ↔ horizontal cH (Nat.le_add_right t d) g=0 := by + intro g + rw [htail] + constructor + · intro hg + funext i + exact hg (i.castLE (Nat.le_add_right t d)) i.isLt + · intro hg i hi + exact congrFun hg (⟨i.val,hi⟩ : Fin t) + let := last_normal H h0 (by decide : 1 ≤ 2) hs + let := PairTail.diagonal_normal (H.level 2) (H.level 2) (last_central_ambient H h1 2 hs) + obtain ⟨cR,hskR,hΓR,_⟩ := exists_adapted_sourceReducedCoordinates H h0 h1 2 (by decide) hs + c q hqbound hq2 hq Γ hΓ + exact quadratic_vertical_factor_alternative cH (Nat.le_add_right t d) hlin H h0 h1 hs hlevel + Γ hΓ cR hskR hΓR (tailCoordinates c (H.level 2) htail) + (tail_secondKind c (H.level 2) htail hsk) (tailCoordinates_lattice c (H.level 2) htail Γ hΓ) + (fun i => q (i.val+2)-t) (fun i x => tailCoordinates_adapted c (H.level 2) htail + (H.level (i.val+2)) (q (i.val+2)) (hq (i.val+2)) x) + 1 F hF χ hχ hw z hz hχz δ hδ + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction06.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction06.lean new file mode 100644 index 0000000000000000000000000000000000000000..5d8744547c65fbace3e0fb36b0e6dfcf399cfd1a --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction06.lean @@ -0,0 +1,268 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction05 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters RationalTailCoordinates +open MeasureTheory PolynomialWeyl AbelianMalcevTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+(d+1))) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) (hs : H.level 3=⊥) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+(d+1)) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+(d+1)), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h0 h1 hs hqbound hq2 hq hΓ in + + +theorem quadratic_rank_factor_return + (IH : QuadraticRankStatement G (t+(d+1)) d) + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (ψ : H.level 2→*Multiplicative ℝ) (hψ : Continuous ψ) + (hψΓ : ∀ g : H.level 2, g.val∈Γ → ∃ z : ℤ, (ψ g).toAdd=z) + (hc : ∀ a b : G, ⁅a,b⁆∈ψ.ker.map (H.level 2).subtype) (hψ0 : ψ≠1) + (B δ : ℝ) (hB : 0 by simpa only [hq2] using hq 2 g + let c₂ := tailCoordinates c (H.level 2) htail + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, QuadraticCharacterData Γ A N f ξ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (t+(d+1)), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq 2 g + let c₂ := tailCoordinates c (H.level 2) htail + let L := H.refine (ψ.ker.map (H.level 2).subtype) hc + have hL0 : L.level 0=⊤ := by simpa [L,Filtration.refine] using h0 + have hL1 : L.level 1=⊤ := by simpa [L,Filtration.refine] using h1 + have hL3 : L.level 3=⊥ := by simp [L,Filtration.refine,hs] + obtain ⟨Λ,e,hesk,hΛ,hle,hindex,q',hq',hq'2,hadapt⟩ := + strict_filtration_refinement_geometry c hsk H h0 h1 q hqbound hq2 hq Γ hΓ ψ hψ hψΓ hc hψ0 + let : (Λ.subgroupOf Γ).FiniteIndex := hindex + let : MeasurableSpace (G⧸Λ) := borel (G⧸Λ) + let : BorelSpace (G⧸Λ) := ⟨rfl⟩ + let : MetricSpace (G⧸Λ) := coordinateQuotientMetric e Λ hΛ + let : CompactSpace (G⧸Λ) := quotient_compact e Λ hΛ + obtain ⟨ν,hν,_⟩ := existsUnique_coordinateHaar e Λ hΛ + let : SMulInvariantMeasure G (G⧸Λ) (ν : Measure (G⧸Λ)) := hν + let μ' : ProbabilityMeasure (G⧸Γ) := ⟨μ,inferInstance⟩ + let : SMulInvariantMeasure G (G⧸Γ) (μ' : Measure (G⧸Γ)) := by change SMulInvariantMeasure G (G⧸Γ) μ; infer_instance + have hmap := RationalLatticeCover.map_coordinateHaar c hΓ hle μ' ν + obtain ⟨C,hC,hrep⟩ := compact_reps_of_integerCoordinates c Γ hΓ + have hC' : ∀ g : G, ∃ v∈C, (QuotientGroup.mk g : G⧸Γ)=QuotientGroup.mk v := by + intro g + obtain ⟨v,hv,hvg⟩ := hrep g + exact ⟨v,hv,(QuotientGroup.eq.mpr hvg).symm⟩ + obtain ⟨J,hJ,M₀,hM₀,S,hS,η,hη,hcov⟩ := FactorProgression.factor_cover_obstruction H Γ c₂ + (RationalLatticeCover.coverMap hle) (fun g => QuotientGroup.mk g) (fun _ => rfl) + μ (ν : Measure (G⧸Λ)) hmap C hC hC' B δ hB hδ Tmax hTmax + obtain ⟨V,A,hA,M₁,hM₁,hprod⟩ := IH e hesk L hL0 hL1 hL3 q' hq' hadapt + (by rw [hq'2]; omega) Λ hΛ (ν : Measure (G⧸Λ)) (S : Set C(G⧸Λ,ℂ)) (S.finite_toSet.isCompact) η hη + let Ξ := V.filter (fun ξ : G→*Multiplicative ℝ => Continuous ξ ∧ ∀ g∈Λ, ∃ z : ℤ, (ξ g).toAdd=z) + have hΞc : ∀ ξ∈Ξ, Continuous ξ := fun ξ hξ => (Finset.mem_filter.mp hξ).2.1 + have hΞΓ : ∀ ξ∈Ξ, ∀ g∈Λ, ∃ z : ℤ, (ξ g).toAdd=z := fun ξ hξ => (Finset.mem_filter.mp hξ).2.2 + let M : ℕ := 2*J*Tmax + have hM : 0 v⁻¹*f' ((T:ℤ)*z+w)*v) (polynomial_of_cube_mem _ hpp) ⟨Φ,hΦ,hlarge⟩ + have hξΞ : ξ∈Ξ := Finset.mem_filter.mpr ⟨hξ,hcξ,hΓξ⟩ + have hNKr : (N:ℝ) ≤ (M:ℝ)*K := by exact_mod_cast hKN + obtain ⟨ω,hω,hω0,P,hP,hPe,hPc⟩ := htransfer N K hn6 hK hNKr T hT hTT (w:ℤ) + (by positivity) (by exact_mod_cast hw.le) f f' e' b hf + (polynomial_of_cube_mem _ hep) (polynomial_of_cube_mem _ hbp) hfac hper hev' v ξ hξΞ hnξ R hRe hRc + exact ⟨ω,hω,hω0,(hU ω hω).1,(hU ω hω).2,P,hP,hPe,hPc⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters RationalTailCoordinates +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevHorizontal +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+(d+1))) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) (hs : H.level 3=⊥) +variable [∀ i, (H.level i).Normal] +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+(d+1)) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+(d+1)), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h0 h1 hs hqbound hq2 hq hΓ in + + +theorem quadratic_vertical_correlation_of_rank + (IH : QuadraticRankStatement G (t+(d+1)) d) + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (F : C(G⧸Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (hF0 : (∫ x,F x ∂μ)=0) (χ : G→ℂ) + (hχ : ∀ n∈H.level 2, ‖χ n‖=1) + (hw : ∀ n∈H.level 2, ∀ x : G, F (QuotientGroup.mk (x*n))=χ n*F (QuotientGroup.mk x)) + (z : G) (hz : z∈H.level 2) (hχz : χ z≠1) (δ : ℝ) (hδ : 0<δ) : + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 F (QuotientGroup.mk (f n)))‖ → + ∃ ξ∈U, QuadraticCharacterData Γ A N f ξ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + obtain ⟨S,hS,ε,hε,htest⟩ := CompactFamilyDescent.finite_unit_lipschitz_obstruction + ({F} : Set C(G⧸Γ,ℂ)) isCompact_singleton δ 2 hδ (by norm_num) + obtain ⟨U,V,A,hA,B,hB,Tmax,hTmax,M₀,hM₀,hproduces⟩ := + quadratic_source_factor_alternative c hsk H h0 h1 hs q hqbound hq2 hq Γ hΓ + F hF χ hχ hw z hz hχz δ hδ + let good := fun ψ : H.level 2→*Multiplicative ℝ => + ψ≠1 ∧ Continuous ψ ∧ (∀ g : H.level 2, g.val∈Γ → ∃ z : ℤ, (ψ g).toAdd=z) ∧ + ∃ hc : ∀ a b : G, ⁅a,b⁆∈ψ.ker.map (H.level 2).subtype, True + let W := V.filter good + let I := {ψ // ψ∈W} + have hi (i : I) : good i.val := (Finset.mem_filter.mp i.property).2 + let hc (i : I) : ∀ a b : G, ⁅a,b⁆∈i.val.ker.map (H.level 2).subtype := (hi i).2.2.2.choose + have hreturn (i : I) := quadratic_rank_factor_return c hsk H h0 h1 hs q hqbound hq2 hq Γ hΓ + IH μ i.val (hi i).2.1 (hi i).2.2.1 (hc i) (hi i).1 B ε hB hε Tmax hTmax + choose U' A' hA' M' hM' hr using hreturn + let Amax := A+∑ i : I, A' i + let Mmax := M₀+∑ i : I, M' i + have hAmax : 0 (hA' _).le) + dsimp [Amax]; linarith + have hMmax : 0 (hA' _).le) (Finset.mem_univ i) + dsimp [Amax]; linarith + have hMbi (i : I) : M' i ≤ Mmax := by + have hh := Finset.single_le_sum (f:=M') (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) + dsimp [Mmax]; omega + refine ⟨U∪Finset.univ.biUnion U',Amax,hAmax,Mmax,hMmax,?_⟩ + intro N hN f hf hf0 hlin hmean + have hNM : M₀ ≤ N := by dsimp [Mmax] at hN; omega + rcases hproduces N hNM f hf hf0 hlin hmean with hchar | hfac + · obtain ⟨ξ,hξ,hd⟩ := hchar + have hAA : A ≤ Amax := by + have : 0 ≤ ∑ i : I, A' i := Finset.sum_nonneg (fun _ _ => (hA' _).le) + dsimp [Amax]; linarith + exact ⟨ξ,Finset.mem_union_left _ hξ,QuadraticCharacterData.mono hd hAA⟩ + · obtain ⟨ψ,hψ,hψ0,hψc,hψΓ,hψcomm,hstrict,T,hT,hTT,hfac⟩ := hfac + let i : I := ⟨ψ,Finset.mem_filter.mpr ⟨hψ,hψ0,hψc,hψΓ,hψcomm,trivial⟩⟩ + have hdisc : δ ≤ ‖FourierObstruction.discrepancy μ N (fun n => QuotientGroup.mk (f n)) F‖ := by + change δ ≤ ‖mean N (fun n => F (QuotientGroup.mk (f n)))-(∫ x,F x ∂μ)‖ + simpa only [hF0,sub_zero] using hmean + obtain ⟨Φ,hΦ,hlarge⟩ := htest (FourierObstruction.discrepancy μ N (fun n => QuotientGroup.mk (f n))) + (FourierObstruction.discrepancy_bound μ N (hM₀.trans_le hNM) _) ⟨F,Set.mem_singleton F,hdisc⟩ + obtain ⟨ξ,hξ,hd⟩ := hr i N ((hMbi i).trans hN) T hT hTT f hf hfac + Φ (hS Φ hΦ).1 (hS Φ hΦ).2 hlarge + exact ⟨ξ,Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨i,Finset.mem_univ _,hξ⟩),hd.mono (hAbi i)⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters RationalTailCoordinates +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevHorizontal +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+(d+1))) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) (hs : H.level 3=⊥) +variable [∀ i, (H.level i).Normal] +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+(d+1)) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+(d+1)), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h0 h1 hs hqbound hq2 hq hΓ in + +theorem quadratic_vertical_unbounded_of_rank + (IH : QuadraticRankStatement G (t+(d+1)) d) + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (F : C(G⧸Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (hF0 : (∫ x,F x ∂μ)=0) (χ : G→ℂ) + (hχ : ∀ n∈H.level 2, ‖χ n‖=1) + (hw : ∀ n∈H.level 2, ∀ x : G, F (QuotientGroup.mk (x*n))=χ n*F (QuotientGroup.mk x)) + (z : G) (hz : z∈H.level 2) (hχz : χ z≠1) (δ : ℝ) (hδ : 0<δ) : + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 F (QuotientGroup.mk (f n)))‖ → + ∃ ξ∈U, QuadraticCharacterData Γ A N f ξ := by + obtain ⟨U,A,hA,N₀,hN₀,hdesc⟩ := quadratic_vertical_correlation_of_rank c hsk H h0 h1 hs + q hqbound hq2 hq Γ hΓ IH μ F hF hF0 χ hχ hw z hz hχz δ hδ + refine ⟨U,A,hA,N₀,hN₀,?_⟩ + intro N hNN f hf hf0 hmean + let v := reduceCoordinates c (f 1) (t+(d+1)) + let γ := v⁻¹*f 1 + have hγ : γ∈Γ := reduceCoordinates_coset c Γ hΓ (f 1) (t+(d+1)) + have he : f 1=v*γ := by dsimp [γ]; group + obtain ⟨hg,hg0,hg1,hge⟩ := lattice_linear_normalization H h1 Γ hf hf0 v γ hγ he + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,hPc⟩ := hdesc N hNN (fun n => f n*(γ^n)⁻¹) + hg hg0 (by + change ‖horizontal c (Nat.le_add_right t (d+1)) ((fun n : ℤ => f n*(γ^n)⁻¹) 1)‖ ≤ 1 + rw [hg1]; exact reduced_horizontal_bound c (Nat.le_add_right t (d+1)) _) (by simpa only [hge] using hmean) + obtain ⟨a,ha⟩ := hξΓ γ hγ + exact ⟨ξ,hξ,hξ0,hξc,hξΓ,integer_linear_return f γ ξ a ha P hP hPe A N hPc⟩ + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction07.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction07.lean new file mode 100644 index 0000000000000000000000000000000000000000..514db055a7b7c79ebb275f21c5ff9643b6ab04cb --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction07.lean @@ -0,0 +1,274 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction06 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h1 : H.level 1=⊤) (hs : H.level 3=⊥) +variable [∀ i, (H.level i).Normal] +variable (q : ℕ→ℕ) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h1 hs hq2 hq hΓ in + + +theorem quadratic_zero_weight_observable + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (δ : ℝ) (hδ : 0<δ) : + letI : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq 2 g + letI := tailAction c hsk (H.level 2) Γ (last_central_ambient H h1 2 hs) htail hΓ + ∀ F : C(G⧸Γ,ℂ), TorusVerticalFourier.HasWeight (0 : Fin d→ℤ) F → + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, QuadraticCharacterData Γ A N f ξ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq 2 g + let hcent := last_central_ambient H h1 2 hs + let := tailAction c hsk (H.level 2) Γ hcent htail hΓ + dsimp only + intro F hw + have hcomm : _root_.commutator G ≤ H.level 2 := by + apply Subgroup.commutator_le.mpr + intro a _ b _ + exact SquareHorizontalCharacter.commutator_mem H h1 a b + have hF : ∀ g a, a∈H.level 2 → F (QuotientGroup.mk (g*a))=F (QuotientGroup.mk g) := by + intro g a ha + have he := hw (torusProjection (tailCoordinates c (H.level 2) htail) ⟨a,ha⟩) (QuotientGroup.mk g) + rw [tailProjection_vadd c hsk (H.level 2) Γ hcent htail hΓ] at he + simpa only [mFourier_zero,ContinuousMap.one_apply,one_mul] using he + obtain ⟨U,hU,A,hA,hprod⟩ := quantitative_abelian_quotient_observable c hsk + (Nat.le_add_right t d) (H.level 2) Γ hcomm htail hΓ H 2 hs μ F hF δ hδ + refine ⟨U,A,hA,1,by decide,?_⟩ + intro N hN f hf _ hdisc + obtain ⟨ξ,hξ,hξ0,P,hP,hPe,hPc⟩ := hprod N hN f hf hdisc + exact ⟨ξ,hξ,hξ0,(hU ξ hξ).1,(hU ξ hξ).2,P,hP,hPe,hPc⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+(d+1))) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+(d+1)) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+(d+1)), i.val by simpa only [hq2] using hq 2 g + letI := tailAction c hsk (H.level 2) Γ (last_central_ambient H h1 2 hs) htail hΓ + ∀ (F : C(G⧸Γ,ℂ)) (k : Fin (d+1)→ℤ), TorusVerticalFourier.HasWeight k F → + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 by simpa only [hq2] using hq 2 g + let hcent := last_central_ambient H h1 2 hs + let := tailAction c hsk (H.level 2) Γ hcent htail hΓ + let := continuous_tailAction c hsk (H.level 2) Γ hcent htail hΓ + let := invariant_tailAction c hsk (H.level 2) Γ hcent htail hΓ μ + dsimp only + intro F k hw + by_cases hk : k=0 + · subst k + exact quadratic_zero_weight_observable c hsk H h1 hs q hq2 hq Γ hΓ μ δ hδ F hw + · let D : ℝ := 1+‖F‖ + have hD : 0 if hg : g∈H.level 2 then + mFourier k (torusProjection (tailCoordinates c (H.level 2) htail) ⟨g,hg⟩) else 1 + have hχ : ∀ g∈H.level 2, ‖χ g‖=1 := by + intro g hg + simp only [χ,dite_eq_left hg] + exact TorusVerticalFourier.character_norm _ _ + have hright : ∀ a∈H.level 2, ∀ g : G, + F' (QuotientGroup.mk (g*a))=χ a*F' (QuotientGroup.mk g) := by + intro a ha g + have he := hw' (torusProjection (tailCoordinates c (H.level 2) htail) ⟨a,ha⟩) (QuotientGroup.mk g) + rw [tailProjection_vadd c hsk (H.level 2) Γ hcent htail hΓ] at he + simpa only [χ,dite_eq_left ha] using he + obtain ⟨s,hs⟩ := TorusVerticalFourier.character_nontrivial hk + obtain ⟨a,ha⟩ := torusProjection_surjective (tailCoordinates c (H.level 2) htail) s + have hχa : χ a.val≠1 := by simpa only [χ,dite_eq_left a.property,ha] using hs + have hzero := TorusVerticalFourier.integral_hasWeight_eq_zero μ F' hk hw' + obtain ⟨U,A,hA,N₀,hN₀,hprod⟩ := quadratic_vertical_unbounded_of_rank c hsk H h0 h1 + (show H.level 3=⊥ from ‹H.level 3=⊥›) q hqbound hq2 hq Γ hΓ IH μ F' hF' hzero χ hχ hright a.val a.property hχa + (δ/D) (div_pos hδ hD) + refine ⟨U,A,hA,N₀,hN₀,?_⟩ + intro N hN f hf hf0 hdisc + apply hprod N hN f hf hf0 + have hdisc' : δ/D ≤ ‖FourierObstruction.discrepancy μ N (fun k => QuotientGroup.mk (f k)) F'‖ := by + change δ/D ≤ ‖FourierObstruction.discrepancy μ N _ ((D:ℂ)⁻¹ • F)‖ + rw [map_smul,norm_smul,norm_inv,Complex.norm_real,Real.norm_eq_abs,abs_of_pos hD,div_eq_inv_mul] + exact mul_le_mul_of_nonneg_left hdisc (inv_nonneg.mpr hD.le) + change δ/D ≤ ‖mean N (fun n => F' (QuotientGroup.mk (f n)))-(∫ x,F' x ∂μ)‖ at hdisc' + simpa only [hzero,sub_zero] using hdisc' + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h1 : H.level 1=⊤) (hs : H.level 3=⊥) +variable [∀ i, (H.level i).Normal] +variable (q : ℕ→ℕ) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h1 hs hq2 hq hΓ in + + +omit [∀ i, (H.level i).Normal] in +theorem normalized_estimate_of_eigen [∀ i, (H.level i).Normal] + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (heigen : + letI : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq 2 g + letI := tailAction c hsk (H.level 2) Γ (last_central_ambient H h1 2 hs) htail hΓ + ∀ η : ℝ, 0<η → ∀ F : C(G⧸Γ,ℂ), ∀ k : Fin d→ℤ, + TorusVerticalFourier.HasWeight k F → + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, QuadraticCharacterData Γ A N f ξ) + (K : Set C(G⧸Γ,ℂ)) (hK : IsCompact K) (δ : ℝ) (hδ : 0<δ) : + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + QuadraticNormalizedEstimate H Γ μ K δ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (t+d), i.val by simpa only [hq2] using hq 2 g + let hcent := last_central_ambient H h1 2 hs + let := tailAction c hsk (H.level 2) Γ hcent htail hΓ + let := continuous_tailAction c hsk (H.level 2) Γ hcent htail hΓ + let E := {F : C(G⧸Γ,ℂ) // F∈TorusVerticalFourier.eigenfunctions (d:=Fin d)} + have hd : (Submodule.span ℂ (Set.range (fun F : E => F.val))).topologicalClosure=⊤ := by + change (Submodule.span ℂ (Set.range ((↑) : E → C(G⧸Γ,ℂ)))).topologicalClosure=⊤ + have he : Set.range ((↑) : E → C(G⧸Γ,ℂ))=TorusVerticalFourier.eigenfunctions (d:=Fin d) := by + ext F + exact ⟨fun ⟨x,hx⟩ => hx ▸ x.property,fun hF => ⟨⟨F,hF⟩,rfl⟩⟩ + rw [he] + exact + (TorusVerticalFourier.eigenfunctions_dense (d:=Fin d) (X:=G⧸Γ)) + obtain ⟨S,η,hη,htest⟩ := TorusVerticalFourier.finite_tests_of_dense_span (fun F : E => F.val) + hd K hK δ 2 hδ (by norm_num) + have hproduce (F : E) : + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F.val‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 (hA F).le) + dsimp [B] + linarith + have hM : 0 QuotientGroup.mk (f k))) + (FourierObstruction.discrepancy_bound μ N hN _) hdisc + have hFi : N₀ F ≤ M := by + exact (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hF).trans (Nat.le_add_left _ _) + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,hPc⟩ := hp F N (hFi.trans hMN) f hf hf0 hlarge + have hAB : A F ≤ B := by + have hh := Finset.single_le_sum (f:=A) (fun F (_ : F∈S) => (hA F).le) hF + dsimp [B] + linarith + refine ⟨ξ,Finset.mem_biUnion.mpr ⟨F,hF,hξ⟩,hξ0,hξc,hξΓ,P,hP,hPe,?_⟩ + intro j hj + obtain ⟨z,hz⟩ := hPc j hj + exact ⟨z,hz.trans (div_le_div_of_nonneg_right hAB (by positivity))⟩ + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction08.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction08.lean new file mode 100644 index 0000000000000000000000000000000000000000..3f3dfe82dbd34f53fc1218428e08a7ed074693d8 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction08.lean @@ -0,0 +1,295 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction07 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) +variable (H : Filtration G) (h0 : H.level 0=⊤) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include h0 hΓ in + + +theorem compact_estimate_of_normalized + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (hnormalized : + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + ∀ K : Set C(G⧸Γ,ℂ), IsCompact K → ∀ δ : ℝ, 0<δ → + QuadraticNormalizedEstimate H Γ μ K δ) + (K : Set C(G⧸Γ,ℂ)) (hK : IsCompact K) (δ : ℝ) (hδ : 0<δ) : + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + QuadraticCompactEstimate H Γ μ K δ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + obtain ⟨C,hC,hrep⟩ := compact_reps_of_integerCoordinates c Γ hΓ + let Q : C(G⧸Γ,G⧸Γ) := ContinuousMap.id _ + let T := fun p : G×C(G⧸Γ,ℂ) => FiniteCoverObservable.translated Q p.1 p.2 + let K' := T '' (C ×ˢ K) + have hK' : IsCompact K' := (hC.prod hK).image (FiniteCoverObservable.continuous_translated Q) + obtain ⟨U,A,hA,N₀,hN₀,hprod⟩ := hnormalized K' hK' δ hδ + refine ⟨U,A,hA,N₀,hN₀,?_⟩ + intro N hN f hf ⟨F,hF,hdisc⟩ + obtain ⟨v,hv,hγ⟩ := hrep (f 0) + let γ := v⁻¹*f 0 + have hav : f 0=v*γ := by simp [γ] + let g : ℤ→G := fun n => γ*(f 0)⁻¹*f n*γ⁻¹ + obtain ⟨hg,hg0,hge⟩ := constant_normalization H h0 Γ hf v γ hγ hav + let F' := T (v,F) + have hF' : F'∈K' := ⟨(v,F),⟨hv,hF⟩,rfl⟩ + have he (n : ℕ) : F' (QuotientGroup.mk (g n))=F (QuotientGroup.mk (f n)) := by + change F (QuotientGroup.mk (v*g n))=F (QuotientGroup.mk (f n)) + rw [hge] + have hint : (∫ x,F' x ∂μ)=(∫ x,F x ∂μ) := by + change (∫ x,F (v • x) ∂μ)=_ + exact integral_smul_eq_self F + have hdisc' : δ ≤ ‖FourierObstruction.discrepancy μ N (fun k => QuotientGroup.mk (g k)) F'‖ := by + change δ ≤ ‖mean N (fun n => F' (QuotientGroup.mk (g n)))-(∫ x,F' x ∂μ)‖ + change δ ≤ ‖mean N (fun n => F (QuotientGroup.mk (f n)))-(∫ x,F x ∂μ)‖ at hdisc + simpa only [he,hint] using hdisc + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,hPc⟩ := hprod N hN g hg hg0 ⟨F',hF',hdisc'⟩ + refine ⟨ξ,hξ,hξ0,hξc,hξΓ,P+Polynomial.C (ξ (f 0)).toAdd,?_,?_,?_⟩ + · exact natDegree_add_le_of_degree_le hP (by simp) + · intro z + simp only [eval_add,eval_C,hPe,g,map_mul,map_inv,toAdd_mul,toAdd_inv] + ring + · intro j hj + obtain ⟨z,hz⟩ := hPc j hj + refine ⟨z,?_⟩ + simpa only [coeff_add,coeff_C,ite_eq_right (Nat.ne_of_gt hj),add_zero] using hz + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + + +theorem quadratic_rank_statement (n k : ℕ) : QuadraticRankStatement G n k := by + classical + induction k using Nat.strong_induction_on with + | h k ih => + intro c hsk H h0 h1 hs q hqbound hq hr Γ hΓ mΓ bΓ μ pμ sμ K hK δ hδ + let : ∀ i, (H.level i).Normal := fun i => level_normal H h0 i + obtain ⟨d,hn⟩ := Nat.exists_eq_add_of_le (hqbound 2) + subst n + apply compact_estimate_of_normalized c H h0 Γ hΓ μ ?_ K hK δ hδ + intro K' hK' δ' hδ' + apply normalized_estimate_of_eigen c hsk H h1 hs q rfl hq Γ hΓ μ ?_ K' hK' δ' hδ' + cases d with + | zero => + dsimp only + intro η hη F w hw + have hzero : w=0 := by funext i; exact Fin.elim0 i + subst w + exact quadratic_zero_weight_observable c hsk H h1 hs q rfl hq Γ hΓ μ η hη F hw + | succ d => + have hd : d QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 QuotientGroup.mk (f k)) F‖ ≤ δ/2 := by + change ‖(𝔼 k∈Finset.range N,F (QuotientGroup.mk (f k)))-(∫ x,F x ∂μ)‖ ≤ _ + rw [← Finset.expect_const (s:=Finset.range N) + (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)) (∫ x,F x ∂μ),← Finset.expect_sub_distrib] + exact (RCLike.norm_expect_le (K:=ℂ)).trans (Finset.expect_le + (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)) (fun k hk => (hh k hk).le)) + linarith + obtain ⟨k,hk,hkdisc⟩ := hp + have hc : LeibmanSquare.Polynomial H 0 (fun _ : ℤ => f k) := + polynomial_of_cube_mem H (const_mem (by rw [h0]; trivial)) + have hcd : δ/2 ≤ ‖FourierObstruction.discrepancy μ M + (fun _ => QuotientGroup.mk (f k)) F‖ := by + simpa only [FourierObstruction.discrepancy,LinearMap.coe_mk,AddHom.coe_mk, + Finset.expect_const (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hM))] using hkdisc + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,_⟩ := hprod M le_rfl (fun _ => f k) hc ⟨F,hF,hcd⟩ + obtain ⟨P,hP,hPe⟩ := character_polynomial H 2 hs hf ξ + refine ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,?_⟩ + intro j hj + by_cases hj2 : j ≤ 2 + · refine ⟨round (P.coeff j),(abs_sub_round _).trans ?_⟩ + apply (le_div_iff₀ (pow_pos (by positivity : (0:ℝ) QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ 2 ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 x) (by rw [htop]; exact @continuous_id _ (QuotientGroup.instTopologicalSpace Γ)) + let pull := @ContinuousMap.compCLM (G⧸Γ) (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) + mtr.toUniformSpace.toTopologicalSpace ℂ ℂ _ _ _ _ _ _ e0 + have hK' : IsCompact (pull '' K) := hK.image pull.continuous + obtain ⟨U,A,hA,hprod⟩ := quadratic_general_compact_all_lengths c hsk H h0 h1 hs + q hqbound hq Γ hΓ μ (pull '' K) hK' δ hδ + refine ⟨U,A,hA,?_⟩ + intro N hN f hf ⟨F,hFL,hFn,hdisc⟩ + apply hprod N hN f hf + refine ⟨pull F,⟨F,hunit F hFL hFn,rfl⟩,?_⟩ + change δ ≤ ‖mean N (fun k => F (QuotientGroup.mk (f k)))-(∫ x,F x ∂μ)‖ + exact hdisc + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction09.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction09.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a6ccc77fd2c7de5144cd6c25d30510a966bbee7 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction09.lean @@ -0,0 +1,301 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction08 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (hs : H.level 3=⊥) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ b : Fin (t+d)→ℤ, b≠0 ∧ (∀ i, |(b i:ℝ)|≤A) ∧ (∀ a b : G, ξ (a*b*a⁻¹*b⁻¹)=1) ∧ + (∀ g : G, (ξ g).toAdd=∑ i, c.coord g i*(b i:ℝ)) ∧ + ∃ α : ℕ→ℝ, (∀ j : ℕ, 2 Finset.sum_nonneg (fun i _ => abs_nonneg _)) + let A : ℝ := 1+S+BinomialDifference.conversionBound 2*C + have hconv : 0 BinomialDifference.coefficient ℝ j P,?_,?_,?_⟩ + · intro hb0 + apply hξ0 + ext g + apply Multiplicative.toAdd.injective + change (ξ g).toAdd=0 + rw [hb,hb0] + simp + · intro i + have h1 : |(ξ (axis c i 1)).toAdd| ≤ ∑ j, |(ξ (axis c j 1)).toAdd| := + Finset.single_le_sum (f := fun j : Fin (t+d) => |(ξ (axis c j 1)).toAdd|) (fun j _ => abs_nonneg _) (Finset.mem_univ i) + have h2 : (∑ j, |(ξ (axis c j 1)).toAdd|)≤S := + Finset.single_le_sum (f := fun χ : G→*Multiplicative ℝ => ∑ j, |(χ (axis c j 1)).toAdd|) (fun χ _ => Finset.sum_nonneg (fun j _ => abs_nonneg _)) hξ + rw [hbi] + dsimp [A] + linarith + · intro a b + apply Multiplicative.toAdd.injective + simp only [map_mul,map_inv,toAdd_mul,toAdd_inv] + change (ξ a).toAdd+(ξ b).toAdd+(-(ξ a).toAdd)+(-(ξ b).toAdd)=0 + ring + · intro j hj + exact BinomialDifference.coefficient_eq_zero ℝ j P (hP.trans_lt hj) + · exact character_binomial_expansion H 2 hs hf ξ P hPe + · intro j hj + have hNr : 1≤(N:ℝ) := by exact_mod_cast hN + have hbnd := BinomialDifference.coefficient_bound 2 1 P hP (N:ℝ) C hNr hC.le + (fun i hi => hPc i hi) j hj + apply hbnd.trans + dsimp [A] + linarith + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + + +def DegreeCharacterData (s : ℕ) (Γ : Subgroup G) (A : ℝ) (N : ℕ) (f : ℤ→G) + (ξ : G→*Multiplicative ℝ) : Prop := + ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ s ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, DegreeCharacterData s Γ A N f ξ + +def DegreeNormalizedEstimate (s : ℕ) (H : Filtration G) (Γ : Subgroup G) + [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] [CompactSpace (G⧸Γ)] + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] (K : Set C(G⧸Γ,ℂ)) (δ : ℝ) : Prop := + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, DegreeCharacterData s Γ A N f ξ + +omit [IsTopologicalGroup G] in +lemma DegreeCharacterData.mono [IsTopologicalGroup G] {s : ℕ} {Γ : Subgroup G} {A B : ℝ} {N : ℕ} {f : ℤ→G} + {ξ : G→*Multiplicative ℝ} (hd : DegreeCharacterData s Γ A N f ξ) (hAB : A≤B) : + DegreeCharacterData s Γ B N f ξ := by + obtain ⟨hξ,hc,hΓ,P,hP,hPe,hPc⟩ := hd + refine ⟨hξ,hc,hΓ,P,hP,hPe,?_⟩ + intro j hj + obtain ⟨z,hz⟩ := hPc j hj + exact ⟨z,hz.trans (div_le_div_of_nonneg_right hAB (by positivity))⟩ + + + +def DegreeRankStatement (G : Type*) [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + (s n k : ℕ) : Prop := + ∀ (c : RealCoordinates G n), SecondKind c → + ∀ (H : Filtration G), H.level 0=⊤ → H.level 1=⊤ → H.level (s+1)=⊥ → + ∀ q : ℕ→ℕ, (∀ i, q i ≤ n) → + (∀ i (g : G), g∈H.level i ↔ ∀ j : Fin n, j.val < q i → c.coord g j=0) → + n-q 2 ≤ k → + ∀ (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z), + ∀ [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)], + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + ∀ (μ : Measure (G⧸Γ)), ∀ [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ], + ∀ K : Set C(G⧸Γ,ℂ), IsCompact K → ∀ δ : ℝ, 0<δ → + DegreeCompactEstimate s H Γ μ K δ + + + +def DegreeStatement (s : ℕ) : Prop := + ∀ (G : Type), ∀ [Group G] [TopologicalSpace G] [IsTopologicalGroup G], + ∀ n k : ℕ, DegreeRankStatement G s n k + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters RationalTailCoordinates +open MeasureTheory PolynomialWeyl AbelianMalcevTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+(d+1))) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+(d+1)) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+(d+1)), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h0 h1 hs2 hs hqbound hq2 hq hΓ in + + +theorem degree_rank_factor_return + (IH : DegreeRankStatement G s (t+(d+1)) d) + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (ψ : H.level 2→*Multiplicative ℝ) (hψ : Continuous ψ) + (hψΓ : ∀ g : H.level 2, g.val∈Γ → ∃ z : ℤ, (ψ g).toAdd=z) + (hc : ∀ a b : G, ⁅a,b⁆∈ψ.ker.map (H.level 2).subtype) (hψ0 : ψ≠1) + (B δ : ℝ) (hB : 0 by simpa only [hq2] using hq 2 g + let c₂ := tailCoordinates c (H.level 2) htail + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, DegreeCharacterData s Γ A N f ξ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (t+(d+1)), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq 2 g + let c₂ := tailCoordinates c (H.level 2) htail + let L := H.refine (ψ.ker.map (H.level 2).subtype) hc + have hL0 : L.level 0=⊤ := by simpa [L,Filtration.refine] using h0 + have hL1 : L.level 1=⊤ := by simpa [L,Filtration.refine] using h1 + have hL3 : L.level (s+1)=⊥ := by + have he : s+1≠2 := by omega + have he0 : s+1≠0 := by omega + have he1 : s+1≠1 := by omega + simp [L,Filtration.refine,hs] + obtain ⟨Λ,e,hesk,hΛ,hle,hindex,q',hq',hq'2,hadapt⟩ := + strict_filtration_refinement_geometry c hsk H h0 h1 q hqbound hq2 hq Γ hΓ ψ hψ hψΓ hc hψ0 + let : (Λ.subgroupOf Γ).FiniteIndex := hindex + let : MeasurableSpace (G⧸Λ) := borel (G⧸Λ) + let : BorelSpace (G⧸Λ) := ⟨rfl⟩ + let : MetricSpace (G⧸Λ) := coordinateQuotientMetric e Λ hΛ + let : CompactSpace (G⧸Λ) := quotient_compact e Λ hΛ + obtain ⟨ν,hν,_⟩ := existsUnique_coordinateHaar e Λ hΛ + let : SMulInvariantMeasure G (G⧸Λ) (ν : Measure (G⧸Λ)) := hν + let μ' : ProbabilityMeasure (G⧸Γ) := ⟨μ,inferInstance⟩ + let : SMulInvariantMeasure G (G⧸Γ) (μ' : Measure (G⧸Γ)) := by change SMulInvariantMeasure G (G⧸Γ) μ; infer_instance + have hmap := RationalLatticeCover.map_coordinateHaar c hΓ hle μ' ν + obtain ⟨C,hC,hrep⟩ := compact_reps_of_integerCoordinates c Γ hΓ + have hC' : ∀ g : G, ∃ v∈C, (QuotientGroup.mk g : G⧸Γ)=QuotientGroup.mk v := by + intro g + obtain ⟨v,hv,hvg⟩ := hrep g + exact ⟨v,hv,(QuotientGroup.eq.mpr hvg).symm⟩ + obtain ⟨J,hJ,M₀,hM₀,S,hS,η,hη,hcov⟩ := FactorProgression.factor_cover_obstruction H Γ c₂ + (RationalLatticeCover.coverMap hle) (fun g => QuotientGroup.mk g) (fun _ => rfl) + μ (ν : Measure (G⧸Λ)) hmap C hC hC' B δ hB hδ Tmax hTmax + obtain ⟨V,A,hA,M₁,hM₁,hprod⟩ := IH e hesk L hL0 hL1 hL3 q' hq' hadapt + (by rw [hq'2]; omega) Λ hΛ (ν : Measure (G⧸Λ)) (S : Set C(G⧸Λ,ℂ)) (S.finite_toSet.isCompact) η hη + let Ξ := V.filter (fun ξ : G→*Multiplicative ℝ => Continuous ξ ∧ ∀ g∈Λ, ∃ z : ℤ, (ξ g).toAdd=z) + have hΞc : ∀ ξ∈Ξ, Continuous ξ := fun ξ hξ => (Finset.mem_filter.mp hξ).2.1 + have hΞΓ : ∀ ξ∈Ξ, ∀ g∈Λ, ∃ z : ℤ, (ξ g).toAdd=z := fun ξ hξ => (Finset.mem_filter.mp hξ).2.2 + let M : ℕ := 2*J*Tmax + have hM : 0 v⁻¹*f' ((T:ℤ)*z+w)*v) (polynomial_of_cube_mem _ hpp) ⟨Φ,hΦ,hlarge⟩ + have hξΞ : ξ∈Ξ := Finset.mem_filter.mpr ⟨hξ,hcξ,hΓξ⟩ + have hNKr : (N:ℝ) ≤ (M:ℝ)*K := by exact_mod_cast hKN + obtain ⟨ω,hω,hω0,P,hP,hPe,hPc⟩ := htransfer N K hn6 hK hNKr T hT hTT (w:ℤ) + (by positivity) (by exact_mod_cast hw.le) f f' e' b hf + (polynomial_of_cube_mem _ hep) (polynomial_of_cube_mem _ hbp) hfac hper hev' v ξ hξΞ hnξ R hRe hRc + exact ⟨ω,hω,hω0,(hU ω hω).1,(hU ω hω).2,P,hP,hPe,hPc⟩ + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction10.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction10.lean new file mode 100644 index 0000000000000000000000000000000000000000..341bb38e088de2fce7c52f08cb2e8bf7003bc3f9 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction10.lean @@ -0,0 +1,278 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction09 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section +noncomputable section +namespace SquareInduction + +theorem finite_dense_choice {α : Type*} (U : Finset α) (S : Finset ℕ) + (ρ T : ℝ) (hρ : 0<ρ) (hT : 0 if hh : h∈S then a h hh else a₀ + have hmap : ∀ h∈S, f h∈U := by + intro h hh + simpa only [f,dite_eq_left hh] using ha h hh + have hcard : U.card • (ρ/((U.card:ℝ)+1)*T) ≤ (S.card:ℝ) := by + rw [nsmul_eq_mul] + have hu : (U.card:ℝ)/((U.card:ℝ)+1) ≤ 1 := by + apply (div_le_one (by positivity)).mpr + linarith + calc + _ = ((U.card:ℝ)/((U.card:ℝ)+1))*(ρ*T) := by ring + _ ≤ 1*(ρ*T) := mul_le_mul_of_nonneg_right hu (mul_pos hρ hT).le + _ ≤ _ := by simpa only [one_mul] using hS + obtain ⟨a',ha',hfiber⟩ := Finset.exists_le_card_fiber_of_nsmul_le_card_of_maps_to hmap ⟨a₀,ha₀⟩ hcard + let B := S.filter (fun h => f h=a') + refine ⟨B,Finset.filter_subset _ _,?_,hfiber,a',ha',?_⟩ + · apply Finset.card_pos.mp + have hp : 0<ρ/((U.card:ℝ)+1)*T := by positivity + exact_mod_cast hp.trans_le hfiber + · intro h hh + have hhS := (Finset.mem_filter.mp hh).1 + have he : a h hhS=a' := by simpa only [f,dite_eq_left hhS] using (Finset.mem_filter.mp hh).2 + exact he ▸ hPa h hhS + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable (s : ℕ) (hs2 : 2≤ s) (hs : H.level (s+1)=⊥) +variable [((restricted H h0).level s).Normal] +variable (Γ : Subgroup G) +variable {r : ℕ} (cR : RealCoordinates ((level H h0 1)⧸(restricted H h0).level s) r) +variable (hskR : SecondKind cR) +variable (hΓR : ∀ g, g∈((Γ.prod Γ).comap (level H h0 1).subtype).map + (QuotientGroup.mk' ((restricted H h0).level s)) ↔ ∀ i, ∃ z : ℤ, cR.coord g i=z) + +include hskR hΓR hs hs2 in + + +theorem degree_square_characters + (IH : DegreeStatement (s-1)) + (qR : ℕ→ℕ) (hqRbound : ∀ i, qR i ≤ r) + (hqR : ∀ i g, g∈(mapFiltration (restricted H h0) + (QuotientGroup.mk' ((restricted H h0).level s))).level i ↔ + ∀ j : Fin r, j.val F (QuotientGroup.mk (f n)))‖ → + 4*(T:ℝ)/N ≤ δ^2/4 → + ∃ S : Finset ℕ, (∀ h∈S, h Continuous ξ ∧ ∀ g∈L, ∃ z : ℤ, (ξ g).toAdd=z) + have hU (ξ : K→*Multiplicative ℝ) (hξ : ξ∈U) : Continuous ξ ∧ ∀ g∈L, ∃ z : ℤ, (ξ g).toAdd=z := + (Finset.mem_filter.mp hξ).2 + let Ξ := U.image (fun ξ => ξ.comp π) + refine ⟨Ξ,?_,A,hA,δ^2/(8*((U.card:ℝ)+1)),by positivity,N₀,hN₀,?_⟩ + · intro ξ hξ + obtain ⟨ζ,hζ,rfl⟩ := Finset.mem_image.mp hξ + refine ⟨(hU ζ hζ).1.comp continuous_quotient_mk',?_⟩ + intro x hx + exact (hU ζ hζ).2 (π x) (Subgroup.mem_map.mpr ⟨x,hx,rfl⟩) + · intro f hf hf0 N T hNN hT hmean hbound + have hN : 0 QuotientGroup.mk (π (linearNormalizedPair H h0 h1 hf + (linearRemainder H h0 hf hf0 h) h v k))) Ψ‖ := by + exact hd + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,W,hW,hWe,hWc⟩ := hprod N hNN _ hp ⟨Ψ,hΨ,hdisc⟩ + have hξU : ξ∈U := Finset.mem_filter.mpr ⟨hξ,hξc,hξΓ⟩ + exact ⟨ξ,hξU,hξ0,v,hv,γ,hγ,hfac,W,hW,hWe,hWc⟩ + obtain ⟨B,hBS,hBne,hBd,ζ,hζ,hBdata⟩ := finite_dense_choice U S (δ^2/8) (T:ℝ) + (by positivity) (by exact_mod_cast hT) hS _ hget + have hζ0 : ζ≠1 := by + obtain ⟨h,hh⟩ := hBne + exact (hBdata h hh).1 + refine ⟨B,fun h hh => hST h (hBS hh),?_, + ζ.comp π,Finset.mem_image.mpr ⟨ζ,hζ,rfl⟩,?_,?_⟩ + · simpa only [div_div] using hBd + · intro he + apply hζ0 + apply MonoidHom.ext + intro x + obtain ⟨y,rfl⟩ := QuotientGroup.mk'_surjective (R.level s) x + exact DFunLike.congr_fun he y + · intro h hh + exact (hBdata h hh).2 + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus MalcevHorizontal +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n d r : ℕ} (c : RealCoordinates G n) (hd : d ≤ n) +variable (hlin : ∀ i : Fin d, c.correction (Fin.castLE hd i)=0) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) +variable [((restricted H h0).level s).Normal] +variable (hlevel : ∀ g : G, g∈H.level 2 ↔ horizontal c hd g=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable (cR : RealCoordinates ((level H h0 1)⧸(restricted H h0).level s) r) +variable (hskR : SecondKind cR) +variable (hΓR : ∀ g, g∈((Γ.prod Γ).comap (level H h0 1).subtype).map + (QuotientGroup.mk' ((restricted H h0).level s)) ↔ ∀ i, ∃ z : ℤ, cR.coord g i=z) + +variable {m : ℕ} (c₂ : RealCoordinates (H.level 2) m) (hsk₂ : SecondKind c₂) +variable (hΓ₂ : ∀ x : H.level 2, x.val∈Γ ↔ ∀ i, ∃ z : ℤ, c₂.coord x i=z) +variable (r₂ : Fin (s+1)→ℕ) +variable (hlevel₂ : ∀ i (x : H.level 2), x.val∈H.level (i.val+2) ↔ + ∀ u : Fin m, u.val < r₂ i → c₂.coord x u=0) +include hlin hlevel hΓ hskR hΓR h1 hs2 hs hsk₂ hΓ₂ hlevel₂ in + + +theorem degree_vertical_factor_alternative + (IH : DegreeStatement (s-1)) + (qR : ℕ→ℕ) (hqRbound : ∀ i, qR i ≤ r) + (hqR : ∀ i g, g∈(mapFiltration (restricted H h0) + (QuotientGroup.mk' ((restricted H h0).level s))).level i ↔ + ∀ j : Fin r, j.val F (QuotientGroup.mk (f n)))‖ → + (∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ s ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 (hΞ ξ h).1) (fun ξ h => (hΞ ξ h).2) + (ρ/(2*k)) B E (div_pos hρ hden) hB.le + refine ⟨U,V,A,hA,B',hB',Tmax,hTmax,N₀+2*k+M₀,by omega,?_⟩ + intro N hNN f hf hf0 hf1 hmean + have hNN₀ : N₀ ≤ N := by omega + have hNk : 2*k ≤ N := by omega + have hNM₀ : M₀ ≤ N := by omega + obtain ⟨hT,hTN,hTd,hbound⟩ := hscale N hNk + have hN : 0 if hh : h∈S then v h hh else reduceCoordinates c (f 1^h) n + have hv' (h : ℕ) : ‖horizontal c hd (v' h)‖ ≤ 1 := by + dsimp [v']; split_ifs with hh + · exact hCb _ (hv h hh) + · exact reduced_horizontal_bound c hd _ + have hvΓ' (h : ℕ) : (v' h)⁻¹*f 1^h∈Γ := by + dsimp [v']; split_ifs with hh + · have he : f 1^h=v h hh*γ h hh := by simpa only [zpow_natCast] using hfac h hh + rw [he,inv_mul_cancel_left] + exact hγ h hh + · exact reduceCoordinates_coset c Γ hΓ _ n + apply hdesc N hNN₀ ξ hξ hξ0 f hf hf0 hf1 v' hv' hvΓ' S + · intro h hh + exact Finset.mem_range.mpr ((hST h hh).trans_le hTN) + · calc + ρ/(2*k)*(N:ℝ) = ρ*((N:ℝ)/(2*k)) := by ring + _ ≤ ρ*((N/k:ℕ):ℝ) := mul_le_mul_of_nonneg_left hTd hρ.le + _ ≤ _ := hS + · intro h hh + refine ⟨W h hh,?_,fun j hj _ => hWc h hh j hj⟩ + simpa only [v',dite_eq_left hh] using hWe h hh + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction11.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction11.lean new file mode 100644 index 0000000000000000000000000000000000000000..78820b59ae14ebb106a5f69a2455ce5414706bfd --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction11.lean @@ -0,0 +1,268 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction10 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters RationalTailCoordinates +open MeasureTheory PolynomialWeyl UniformSquareObservable AbelianMalcevTorus MalcevHorizontal +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+d) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + +include hsk h0 h1 hs2 hs hqbound hq2 hq hΓ in + + +theorem degree_source_factor_alternative + (IH : DegreeStatement (s-1)) + (F : C(G⧸Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (χ : G→ℂ) + (hχ : ∀ n∈H.level s, ‖χ n‖=1) + (hw : ∀ n∈H.level s, ∀ x : G, F (QuotientGroup.mk (x*n))=χ n*F (QuotientGroup.mk x)) + (z : G) (hz : z∈H.level s) (hχz : χ z≠1) (δ : ℝ) (hδ : 0<δ) : + let htail : ∀ g : G, g∈H.level 2 ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq 2 g + let c₂ := tailCoordinates c (H.level 2) htail + ∃ U : Finset (G→*Multiplicative ℝ), ∃ V : Finset (H.level 2→*Multiplicative ℝ), + ∃ A : ℝ, 0 F (QuotientGroup.mk (f n)))‖ → + (∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ s ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 by simpa only [hq2] using hq 2 g + have hcomm : _root_.commutator G ≤ H.level 2 := by + apply Subgroup.commutator_le.mpr + intro a _ b _ + exact SquareHorizontalCharacter.commutator_mem H h1 a b + let cH := horizontalCoordinates c hsk (H.level 2) t hcomm (fun g hg => (htail g).mp hg) + have hlin : ∀ i : Fin t, cH.correction (i.castLE (Nat.le_add_right t d))=0 := by + intro i + exact horizontalCoordinates_correction c hsk (H.level 2) t hcomm + (fun g hg => (htail g).mp hg) _ i.isLt + have hlevel : ∀ g : G, g∈H.level 2 ↔ horizontal cH (Nat.le_add_right t d) g=0 := by + intro g + rw [htail] + constructor + · intro hg + funext i + exact hg (i.castLE (Nat.le_add_right t d)) i.isLt + · intro hg i hi + exact congrFun hg (⟨i.val,hi⟩ : Fin t) + let := last_normal H h0 (by omega : 1 ≤ s) hs + let := PairTail.diagonal_normal (H.level 2) (H.level s) (last_central_ambient H h1 s hs) + obtain ⟨cR,hskR,hΓR,hcRF⟩ := exists_adapted_sourceReducedCoordinates H h0 h1 s (by omega) hs + c q hqbound hq2 hq Γ hΓ + choose qR hqRbound hqR using hcRF + exact degree_vertical_factor_alternative cH (Nat.le_add_right t d) hlin H h0 h1 s hs2 hs hlevel + Γ hΓ cR hskR hΓR (tailCoordinates c (H.level 2) htail) + (tail_secondKind c (H.level 2) htail hsk) (tailCoordinates_lattice c (H.level 2) htail Γ hΓ) + (fun i => q (i.val+2)-t) (fun i x => tailCoordinates_adapted c (H.level 2) htail + (H.level (i.val+2)) (q (i.val+2)) (hq (i.val+2)) x) + IH qR hqRbound hqR 1 F hF χ hχ hw z hz hχz δ hδ + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters RationalTailCoordinates +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevHorizontal +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+(d+1))) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) +variable [∀ i, (H.level i).Normal] +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+(d+1)) (hq2 : q 2=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+(d+1)), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h0 h1 hs2 hs hqbound hq2 hq hΓ in + + +theorem degree_vertical_correlation_of_rank + (ID : DegreeStatement (s-1)) + (IH : DegreeRankStatement G s (t+(d+1)) d) + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (F : C(G⧸Γ,ℂ)) (hF : ∀ x, ‖F x‖ ≤ 1) (hF0 : (∫ x,F x ∂μ)=0) (χ : G→ℂ) + (hχ : ∀ n∈H.level s, ‖χ n‖=1) + (hw : ∀ n∈H.level s, ∀ x : G, F (QuotientGroup.mk (x*n))=χ n*F (QuotientGroup.mk x)) + (z : G) (hz : z∈H.level s) (hχz : χ z≠1) (δ : ℝ) (hδ : 0<δ) : + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 F (QuotientGroup.mk (f n)))‖ → + ∃ ξ∈U, DegreeCharacterData s Γ A N f ξ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + obtain ⟨S,hS,ε,hε,htest⟩ := CompactFamilyDescent.finite_unit_lipschitz_obstruction + ({F} : Set C(G⧸Γ,ℂ)) isCompact_singleton δ 2 hδ (by norm_num) + obtain ⟨U,V,A,hA,B,hB,Tmax,hTmax,M₀,hM₀,hproduces⟩ := + degree_source_factor_alternative c hsk H h0 h1 s hs2 hs q hqbound hq2 hq Γ hΓ ID + F hF χ hχ hw z hz hχz δ hδ + let good := fun ψ : H.level 2→*Multiplicative ℝ => + ψ≠1 ∧ Continuous ψ ∧ (∀ g : H.level 2, g.val∈Γ → ∃ z : ℤ, (ψ g).toAdd=z) ∧ + ∃ hc : ∀ a b : G, ⁅a,b⁆∈ψ.ker.map (H.level 2).subtype, True + let W := V.filter good + let I := {ψ // ψ∈W} + have hi (i : I) : good i.val := (Finset.mem_filter.mp i.property).2 + let hc (i : I) : ∀ a b : G, ⁅a,b⁆∈i.val.ker.map (H.level 2).subtype := (hi i).2.2.2.choose + have hreturn (i : I) := degree_rank_factor_return c hsk H h0 h1 s hs2 hs q hqbound hq2 hq Γ hΓ + IH μ i.val (hi i).2.1 (hi i).2.2.1 (hc i) (hi i).1 B ε hB hε Tmax hTmax + choose U' A' hA' M' hM' hr using hreturn + let Amax := A+∑ i : I, A' i + let Mmax := M₀+∑ i : I, M' i + have hAmax : 0 (hA' _).le) + dsimp [Amax]; linarith + have hMmax : 0 (hA' _).le) (Finset.mem_univ i) + dsimp [Amax]; linarith + have hMbi (i : I) : M' i ≤ Mmax := by + have hh := Finset.single_le_sum (f:=M') (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) + dsimp [Mmax]; omega + refine ⟨U∪Finset.univ.biUnion U',Amax,hAmax,Mmax,hMmax,?_⟩ + intro N hN f hf hf0 hlin hmean + have hNM : M₀ ≤ N := by dsimp [Mmax] at hN; omega + rcases hproduces N hNM f hf hf0 hlin hmean with hchar | hfac + · obtain ⟨ξ,hξ,hd⟩ := hchar + have hAA : A ≤ Amax := by + have : 0 ≤ ∑ i : I, A' i := Finset.sum_nonneg (fun _ _ => (hA' _).le) + dsimp [Amax]; linarith + exact ⟨ξ,Finset.mem_union_left _ hξ,DegreeCharacterData.mono hd hAA⟩ + · obtain ⟨ψ,hψ,hψ0,hψc,hψΓ,hψcomm,hstrict,T,hT,hTT,hfac⟩ := hfac + let i : I := ⟨ψ,Finset.mem_filter.mpr ⟨hψ,hψ0,hψc,hψΓ,hψcomm,trivial⟩⟩ + have hdisc : δ ≤ ‖FourierObstruction.discrepancy μ N (fun n => QuotientGroup.mk (f n)) F‖ := by + change δ ≤ ‖mean N (fun n => F (QuotientGroup.mk (f n)))-(∫ x,F x ∂μ)‖ + simpa only [hF0,sub_zero] using hmean + obtain ⟨Φ,hΦ,hlarge⟩ := htest (FourierObstruction.discrepancy μ N (fun n => QuotientGroup.mk (f n))) + (FourierObstruction.discrepancy_bound μ N (hM₀.trans_le hNM) _) ⟨F,Set.mem_singleton F,hdisc⟩ + obtain ⟨ξ,hξ,hd⟩ := hr i N ((hMbi i).trans hN) T hT hTT f hf hfac + Φ (hS Φ hΦ).1 (hS Φ hΦ).2 hlarge + exact ⟨ξ,Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨i,Finset.mem_univ _,hξ⟩),hd.mono (hAbi i)⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +open scoped commutatorElement +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters RationalTailCoordinates +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevHorizontal +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma degree_integer_linear_return [TopologicalSpace G] [IsTopologicalGroup G] + (s : ℕ) (hs1 : 1 ≤ s) (f : ℤ→G) (γ : G) (ξ : G→*Multiplicative ℝ) + (a : ℤ) (ha : (ξ γ).toAdd=(a:ℝ)) (P : ℝ[X]) (hP : P.natDegree ≤ s) + (hPe : ∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z*(γ^z)⁻¹)).toAdd) + (A : ℝ) (N : ℕ) + (hPc : ∀ j : ℕ, 0 F (QuotientGroup.mk (f n)))‖ → + ∃ ξ∈U, DegreeCharacterData s Γ A N f ξ := by + obtain ⟨U,A,hA,N₀,hN₀,hdesc⟩ := degree_vertical_correlation_of_rank c hsk H h0 h1 s hs2 hs + q hqbound hq2 hq Γ hΓ ID IH μ F hF hF0 χ hχ hw z hz hχz δ hδ + refine ⟨U,A,hA,N₀,hN₀,?_⟩ + intro N hNN f hf hf0 hmean + let v := reduceCoordinates c (f 1) (t+(d+1)) + let γ := v⁻¹*f 1 + have hγ : γ∈Γ := reduceCoordinates_coset c Γ hΓ (f 1) (t+(d+1)) + have he : f 1=v*γ := by dsimp [γ]; group + obtain ⟨hg,hg0,hg1,hge⟩ := lattice_linear_normalization H h1 Γ hf hf0 v γ hγ he + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,hPc⟩ := hdesc N hNN (fun n => f n*(γ^n)⁻¹) + hg hg0 (by + change ‖horizontal c (Nat.le_add_right t (d+1)) ((fun n : ℤ => f n*(γ^n)⁻¹) 1)‖ ≤ 1 + rw [hg1]; exact reduced_horizontal_bound c (Nat.le_add_right t (d+1)) _) (by simpa only [hge] using hmean) + obtain ⟨a,ha⟩ := hξΓ γ hγ + exact ⟨ξ,hξ,hξ0,hξc,hξΓ,degree_integer_linear_return s (by omega) f γ ξ a ha P hP hPe A N hPc⟩ + +end SquareInduction +end +end + + + + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction12.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction12.lean new file mode 100644 index 0000000000000000000000000000000000000000..5df76811d9125b48a6c0d211ba118997eebd03b0 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction12.lean @@ -0,0 +1,280 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction11 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +namespace SquareInduction +open CubeFaces LeibmanSquare RationalLattice MalcevCharacters MeasureTheory PolynomialWeyl +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + +theorem degree_vertical_unbounded_rank_any {n d : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) + (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) + (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) [∀ i, (H.level i).Normal] + (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ n) + (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin n, i.val F (QuotientGroup.mk (f k)))‖ → + ∃ ξ∈U, DegreeCharacterData s Γ A N f ξ := by + have hn : n=q 2+(d+1) := by have := hqbound 2; omega + subst n + exact degree_vertical_unbounded_of_rank c hsk H h0 h1 s hs2 hs q hqbound rfl hq Γ hΓ + ID IH μ F hF hF0 χ hχ hw z hz hχz δ hδ + +end SquareInduction +end +end + + + +section +noncomputable section +namespace MalcevPrefixQuotient +open RationalLattice MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {r d : ℕ} (c : RealCoordinates G (r+d)) (hsk : SecondKind c) +variable (N : Subgroup G) [N.Normal] +variable (hN : ∀ g : G, g∈N ↔ ∀ i : Fin (r+d), i.val x.val) h) + · intro h; rw [h] + simp only [he] + +include hsk in + + +theorem quotient_secondKind : SecondKind (quotientChart c (Nat.le_add_right r d) N hN) where + axis_add i s t := by + simp only [quotient_axis,hsk.axis_add,map_mul] + ordered x := by + induction x using Quotient.inductionOn with | h g => + change QuotientGroup.mk' N g = _ + conv_lhs => rw [hsk.ordered g,map_list_prod,List.map_ofFn,List.ofFn_add,List.prod_append] + have htail : (List.ofFn (fun i : Fin d => QuotientGroup.mk' N + (axis c (Fin.natAdd r i) (c.coord g (Fin.natAdd r i))))).prod=1 := by + have he : (fun i : Fin d => QuotientGroup.mk' N + (axis c (Fin.natAdd r i) (c.coord g (Fin.natAdd r i))))=fun _ => (1:G⧸N) := by + funext i + apply (QuotientGroup.eq_one_iff _).mpr + apply (hN _).mpr + intro j hj + rw [coord_axis] + have hne : j≠Fin.natAdd r i := by + intro h + have := congrArg Fin.val h + simp only [Fin.val_natAdd] at this + omega + simp [hne] + simp only [he] + simp + simp only [Function.comp_def] + rw [htail,mul_one] + congr 1 + apply congrArg List.ofFn + funext i + rw [quotient_axis] + rfl + +end MalcevPrefixQuotient +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open AbelianMalcevTorus +open RationalLattice MalcevCharacters CubeFaces LeibmanSquare MeasureTheory RationalQuotientFunctions +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {r d : ℕ} (c : RealCoordinates G (r+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable (s : ℕ) (hs1 : 1 ≤ s) (hs : H.level (s+1)=⊥) +variable [∀ i, (H.level i).Normal] +variable (q : ℕ→ℕ) (hqs : q s=r) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (r+d), i.val QuotientGroup.mk (f k)) F‖ → + ∃ χ∈U, DegreeCharacterData s Γ A L f χ := by + classical + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let N := H.level s + let : N.Normal := Subgroup.normal_of_le_center (last_central_ambient H h1 s hs) + have hr := Nat.le_add_right r d + have hN : ∀ g : G, g∈N ↔ ∀ i : Fin (r+d), i.val by simpa only [hqs] using hq s g + let cQ := MalcevPrefixQuotient.quotientChart c hr N hN + let ΓQ := Γ.map (QuotientGroup.mk' N) + have hΓQ : ∀ g : G⧸N, g∈ΓQ ↔ ∀ i, ∃ z : ℤ, cQ.coord g i=z := + MalcevPrefixQuotient.quotient_lattice c hr N hN Γ hΓ + have hskQ : SecondKind cQ := MalcevPrefixQuotient.quotient_secondKind c hsk N hN + let : MetricSpace ((G⧸N)⧸ΓQ) := coordinateQuotientMetric cQ ΓQ hΓQ + let : CompactSpace ((G⧸N)⧸ΓQ) := quotient_compact cQ ΓQ hΓQ + let : MeasurableSpace ((G⧸N)⧸ΓQ) := borel _ + let : BorelSpace ((G⧸N)⧸ΓQ) := ⟨rfl⟩ + let Q := quotientMap N Γ + have hQ : Continuous Q := continuous_quotientMap N Γ + let ν := Measure.map Q μ + let : IsProbabilityMeasure ν := inferInstance + let : SMulInvariantMeasure (G⧸N) ((G⧸N)⧸ΓQ) ν := CentralQuotientAction.invariant_quotientMap N Γ μ + obtain ⟨FQ,hFQ,_⟩ := existsUnique_normalDescend N Γ + (⟨fun g => F (QuotientGroup.mk g),F.continuous.comp QuotientGroup.continuous_mk⟩ : C(G,ℂ)) hF + (fun g a ha => congrArg F (QuotientGroup.mk_mul_of_mem g ha)) + have hFQall : ∀ x : G⧸Γ, FQ (Q x)=F x := by + intro x + induction x using Quotient.inductionOn with | h g => exact hFQ g + let HQ := mapFiltration H (QuotientGroup.mk' N) + have hsQ : HQ.level ((s-1)+1)=⊥ := by + rw [Nat.sub_add_cancel hs1] + apply le_antisymm ?_ bot_le + rintro g ⟨x,hx,rfl⟩ + exact (QuotientGroup.eq_one_iff x).mpr hx + have h0Q : HQ.level 0=⊤ := by + change (H.level 0).map _=⊤ + rw [h0,Subgroup.map_top_of_surjective _ (QuotientGroup.mk'_surjective N)] + have h1Q : HQ.level 1=⊤ := by + change (H.level 1).map _=⊤ + rw [h1,Subgroup.map_top_of_surjective _ (QuotientGroup.mk'_surjective N)] + let qQ := fun k => min (q k) r + have hqQ : ∀ k (g : G⧸N), g∈HQ.level k ↔ ∀ i : Fin r, i.val min_le_right _ _) hqQ (Nat.sub_le _ _) ΓQ hΓQ ν {FQ} isCompact_singleton δ hδ + let liftχ : (G⧸N →* Multiplicative ℝ) → (G→*Multiplicative ℝ) := fun χ => χ.comp (QuotientGroup.mk' N) + refine ⟨U.image liftχ,A,hA,N₀,hN₀,?_⟩ + intro L hL f hf hdisc + have hint : (∫ x, FQ x ∂ν)=(∫ x,F x ∂μ) := by + rw [show ν=Measure.map Q μ from rfl,integral_map hQ.measurable.aemeasurable FQ.continuous.aestronglyMeasurable] + apply integral_congr_ae + exact Filter.Eventually.of_forall hFQall + have hdiscQ : δ ≤ ‖FourierObstruction.discrepancy ν L + (fun k => QuotientGroup.mk (QuotientGroup.mk' N (f k))) FQ‖ := by + change δ ≤ ‖PolynomialWeyl.mean L (fun k => FQ (QuotientGroup.mk (QuotientGroup.mk' N (f k))))-(∫ x,FQ x ∂ν)‖ + simp only [hFQ,hint] + exact hdisc + obtain ⟨χ,hχ,hχ0,hχc,hχΓ,P,hP,hPe,hPc⟩ := hprod L hL (fun z => QuotientGroup.mk' N (f z)) + (polynomial_map H (QuotientGroup.mk' N) hf) ⟨FQ,Set.mem_singleton FQ,hdiscQ⟩ + refine ⟨liftχ χ,Finset.mem_image.mpr ⟨χ,hχ,rfl⟩,?_, + hχc.comp QuotientGroup.continuous_mk,fun g hg => hχΓ _ ⟨g,hg,rfl⟩, + P,hP.trans (Nat.sub_le _ _),hPe,hPc⟩ + intro he + apply hχ0 + apply MonoidHom.ext + intro x + obtain ⟨g,rfl⟩ := QuotientGroup.mk_surjective x + exact congrArg (fun ψ : G→*Multiplicative ℝ => ψ g) he + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) (s : ℕ) (hs1 : 1 ≤ s) (hs : H.level (s+1)=⊥) +variable [∀ i, (H.level i).Normal] +variable (q : ℕ→ℕ) (hq2 : q s=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h0 h1 hs1 hs hq2 hq hΓ in + + +theorem degree_zero_weight_observable (ID : DegreeStatement (s-1)) + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (δ : ℝ) (hδ : 0<δ) : + letI : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level s ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq s g + letI := tailAction c hsk (H.level s) Γ (last_central_ambient H h1 s hs) htail hΓ + ∀ F : C(G⧸Γ,ℂ), TorusVerticalFourier.HasWeight (0 : Fin d→ℤ) F → + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, DegreeCharacterData s Γ A N f ξ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level s ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq s g + let hcent := last_central_ambient H h1 s hs + let := tailAction c hsk (H.level s) Γ hcent htail hΓ + dsimp only + intro F hw + have hF : ∀ g a, a∈H.level s → F (QuotientGroup.mk (g*a))=F (QuotientGroup.mk g) := by + intro g a ha + have he := hw (torusProjection (tailCoordinates c (H.level s) htail) ⟨a,ha⟩) (QuotientGroup.mk g) + rw [tailProjection_vadd c hsk (H.level s) Γ hcent htail hΓ] at he + simpa only [mFourier_zero,ContinuousMap.one_apply,one_mul] using he + obtain ⟨U,A,hA,M,hM,hprod⟩ := degree_quotient_observable c hsk H h0 h1 s hs1 hs + q hq2 hq Γ hΓ ID μ F hF δ hδ + refine ⟨U,A,hA,M,hM,?_⟩ + intro N hN f hf _ hdisc + exact hprod N hN f hf hdisc + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction13.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction13.lean new file mode 100644 index 0000000000000000000000000000000000000000..551e32aa25b2a1a05d5f8aefe30789d01cd4e564 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction13.lean @@ -0,0 +1,281 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction12 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t e d : ℕ} (c : RealCoordinates G (t+e)) (hsk : SecondKind c) +variable (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) +variable [∀ i, (H.level i).Normal] +variable (s : ℕ) (hs2 : 2 ≤ s) (hs : H.level (s+1)=⊥) +variable (q : ℕ→ℕ) (hqbound : ∀ k, q k ≤ t+e) (hq2 : q s=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+e), i.val by simpa only [hq2] using hq s g + letI := tailAction c hsk (H.level s) Γ (last_central_ambient H h1 s hs) htail hΓ + ∀ (F : C(G⧸Γ,ℂ)) (k : Fin e→ℤ), TorusVerticalFourier.HasWeight k F → + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ s ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 by simpa only [hq2] using hq s g + let hcent := last_central_ambient H h1 s hs + let := tailAction c hsk (H.level s) Γ hcent htail hΓ + let := continuous_tailAction c hsk (H.level s) Γ hcent htail hΓ + let := invariant_tailAction c hsk (H.level s) Γ hcent htail hΓ μ + dsimp only + intro F k hw + by_cases hk : k=0 + · subst k + exact degree_zero_weight_observable c hsk H h0 h1 s (by omega) hs q hq2 hq Γ hΓ ID μ δ hδ F hw + · let D : ℝ := 1+‖F‖ + have hD : 0 if hg : g∈H.level s then + mFourier k (torusProjection (tailCoordinates c (H.level s) htail) ⟨g,hg⟩) else 1 + have hχ : ∀ g∈H.level s, ‖χ g‖=1 := by + intro g hg + simp only [χ,dite_eq_left hg] + exact TorusVerticalFourier.character_norm _ _ + have hright : ∀ a∈H.level s, ∀ g : G, + F' (QuotientGroup.mk (g*a))=χ a*F' (QuotientGroup.mk g) := by + intro a ha g + have he := hw' (torusProjection (tailCoordinates c (H.level s) htail) ⟨a,ha⟩) (QuotientGroup.mk g) + rw [tailProjection_vadd c hsk (H.level s) Γ hcent htail hΓ] at he + simpa only [χ,dite_eq_left ha] using he + obtain ⟨aT,haT⟩ := TorusVerticalFourier.character_nontrivial hk + obtain ⟨a,ha⟩ := torusProjection_surjective (tailCoordinates c (H.level s) htail) aT + have hχa : χ a.val≠1 := by simpa only [χ,dite_eq_left a.property,ha] using haT + have hzero := TorusVerticalFourier.integral_hasWeight_eq_zero μ F' hk hw' + obtain ⟨U,A,hA,N₀,hN₀,hprod⟩ := degree_vertical_unbounded_rank_any c hsk H h0 h1 s hs2 hs + q hqbound hq hrank Γ hΓ ID IH μ F' hF' hzero χ hχ hright a.val a.property hχa + (δ/D) (div_pos hδ hD) + refine ⟨U,A,hA,N₀,hN₀,?_⟩ + intro N hN f hf hf0 hdisc + apply hprod N hN f hf hf0 + have hdisc' : δ/D ≤ ‖FourierObstruction.discrepancy μ N (fun k => QuotientGroup.mk (f k)) F'‖ := by + change δ/D ≤ ‖FourierObstruction.discrepancy μ N _ ((D:ℂ)⁻¹ • F)‖ + rw [map_smul,norm_smul,norm_inv,Complex.norm_real,Real.norm_eq_abs,abs_of_pos hD,div_eq_inv_mul] + exact mul_le_mul_of_nonneg_left hdisc (inv_nonneg.mpr hD.le) + change δ/D ≤ ‖mean N (fun n => F' (QuotientGroup.mk (f n)))-(∫ x,F' x ∂μ)‖ at hdisc' + simpa only [hzero,sub_zero] using hdisc' + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {t d : ℕ} (c : RealCoordinates G (t+d)) (hsk : SecondKind c) +variable (s : ℕ) (H : Filtration G) (h1 : H.level 1=⊤) (hs : H.level (s+1)=⊥) +variable [∀ i, (H.level i).Normal] +variable (q : ℕ→ℕ) (hq2 : q s=t) +variable (hq : ∀ k (g : G), g∈H.level k ↔ ∀ i : Fin (t+d), i.val < q k → c.coord g i=0) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include hsk h1 hs hq2 hq hΓ in + + +omit [∀ i, (H.level i).Normal] in +theorem degree_normalized_estimate_of_eigen [∀ i, (H.level i).Normal] + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (heigen : + letI : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level s ↔ ∀ i : Fin (t+d), i.val < t → c.coord g i=0 := + fun g => by simpa only [hq2] using hq s g + letI := tailAction c hsk (H.level s) Γ (last_central_ambient H h1 s hs) htail hΓ + ∀ η : ℝ, 0<η → ∀ F : C(G⧸Γ,ℂ), ∀ k : Fin d→ℤ, + TorusVerticalFourier.HasWeight k F → + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F‖ → + ∃ ξ∈U, DegreeCharacterData s Γ A N f ξ) + (K : Set C(G⧸Γ,ℂ)) (hK : IsCompact K) (δ : ℝ) (hδ : 0<δ) : + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + DegreeNormalizedEstimate s H Γ μ K δ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let htail : ∀ g : G, g∈H.level s ↔ ∀ i : Fin (t+d), i.val by simpa only [hq2] using hq s g + let hcent := last_central_ambient H h1 s hs + let := tailAction c hsk (H.level s) Γ hcent htail hΓ + let := continuous_tailAction c hsk (H.level s) Γ hcent htail hΓ + let E := {F : C(G⧸Γ,ℂ) // F∈TorusVerticalFourier.eigenfunctions (d:=Fin d)} + have hd : (Submodule.span ℂ (Set.range (fun F : E => F.val))).topologicalClosure=⊤ := by + change (Submodule.span ℂ (Set.range ((↑) : E → C(G⧸Γ,ℂ)))).topologicalClosure=⊤ + have he : Set.range ((↑) : E → C(G⧸Γ,ℂ))=TorusVerticalFourier.eigenfunctions (d:=Fin d) := by + ext F + exact ⟨fun ⟨x,hx⟩ => hx ▸ x.property,fun hF => ⟨⟨F,hF⟩,rfl⟩⟩ + rw [he] + exact + (TorusVerticalFourier.eigenfunctions_dense (d:=Fin d) (X:=G⧸Γ)) + obtain ⟨S,η,hη,htest⟩ := TorusVerticalFourier.finite_tests_of_dense_span (fun F : E => F.val) + hd K hK δ 2 hδ (by norm_num) + have hproduce (F : E) : + ∃ U : Finset (G→*Multiplicative ℝ), ∃ A : ℝ, 0 QuotientGroup.mk (f k)) F.val‖ → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ s ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 (hA F).le) + dsimp [B] + linarith + have hM : 0 QuotientGroup.mk (f k))) + (FourierObstruction.discrepancy_bound μ N hN _) hdisc + have hFi : N₀ F ≤ M := by + exact (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hF).trans (Nat.le_add_left _ _) + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,hPc⟩ := hp F N (hFi.trans hMN) f hf hf0 hlarge + have hAB : A F ≤ B := by + have hh := Finset.single_le_sum (f:=A) (fun F (_ : F∈S) => (hA F).le) hF + dsimp [B] + linarith + refine ⟨ξ,Finset.mem_biUnion.mpr ⟨F,hF,hξ⟩,hξ0,hξc,hξΓ,P,hP,hPe,?_⟩ + intro j hj + obtain ⟨z,hz⟩ := hPc j hj + exact ⟨z,hz.trans (div_le_div_of_nonneg_right hAB (by positivity))⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) +variable (s : ℕ) (H : Filtration G) (h0 : H.level 0=⊤) +variable (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + +include h0 hΓ in + + +theorem degree_compact_estimate_of_normalized + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (hnormalized : + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + ∀ K : Set C(G⧸Γ,ℂ), IsCompact K → ∀ δ : ℝ, 0<δ → + DegreeNormalizedEstimate s H Γ μ K δ) + (K : Set C(G⧸Γ,ℂ)) (hK : IsCompact K) (δ : ℝ) (hδ : 0<δ) : + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + DegreeCompactEstimate s H Γ μ K δ := by + classical + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + obtain ⟨C,hC,hrep⟩ := compact_reps_of_integerCoordinates c Γ hΓ + let Q : C(G⧸Γ,G⧸Γ) := ContinuousMap.id _ + let T := fun p : G×C(G⧸Γ,ℂ) => FiniteCoverObservable.translated Q p.1 p.2 + let K' := T '' (C ×ˢ K) + have hK' : IsCompact K' := (hC.prod hK).image (FiniteCoverObservable.continuous_translated Q) + obtain ⟨U,A,hA,N₀,hN₀,hprod⟩ := hnormalized K' hK' δ hδ + refine ⟨U,A,hA,N₀,hN₀,?_⟩ + intro N hN f hf ⟨F,hF,hdisc⟩ + obtain ⟨v,hv,hγ⟩ := hrep (f 0) + let γ := v⁻¹*f 0 + have hav : f 0=v*γ := by simp [γ] + let g : ℤ→G := fun n => γ*(f 0)⁻¹*f n*γ⁻¹ + obtain ⟨hg,hg0,hge⟩ := constant_normalization H h0 Γ hf v γ hγ hav + let F' := T (v,F) + have hF' : F'∈K' := ⟨(v,F),⟨hv,hF⟩,rfl⟩ + have he (n : ℕ) : F' (QuotientGroup.mk (g n))=F (QuotientGroup.mk (f n)) := by + change F (QuotientGroup.mk (v*g n))=F (QuotientGroup.mk (f n)) + rw [hge] + have hint : (∫ x,F' x ∂μ)=(∫ x,F x ∂μ) := by + change (∫ x,F (v • x) ∂μ)=_ + exact integral_smul_eq_self F + have hdisc' : δ ≤ ‖FourierObstruction.discrepancy μ N (fun k => QuotientGroup.mk (g k)) F'‖ := by + change δ ≤ ‖mean N (fun n => F' (QuotientGroup.mk (g n)))-(∫ x,F' x ∂μ)‖ + change δ ≤ ‖mean N (fun n => F (QuotientGroup.mk (f n)))-(∫ x,F x ∂μ)‖ at hdisc + simpa only [he,hint] using hdisc + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,hPc⟩ := hprod N hN g hg hg0 ⟨F',hF',hdisc'⟩ + refine ⟨ξ,hξ,hξ0,hξc,hξΓ,P+Polynomial.C (ξ (f 0)).toAdd,?_,?_,?_⟩ + · exact natDegree_add_le_of_degree_le hP (by simp) + · intro z + simp only [eval_add,eval_C,hPe,g,map_mul,map_inv,toAdd_mul,toAdd_inv] + ring + · intro j hj + obtain ⟨z,hz⟩ := hPc j hj + refine ⟨z,?_⟩ + simpa only [coeff_add,coeff_C,ite_eq_right (Nat.ne_of_gt hj),add_zero] using hz + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction14.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction14.lean new file mode 100644 index 0000000000000000000000000000000000000000..86ac2e3f447a65696a706d8ab038d1894f892848 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/SquareInduction14.lean @@ -0,0 +1,281 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.SquareInduction13 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section +noncomputable section +namespace SquareInduction +open RationalLattice MalcevCharacters CubeFaces LeibmanSquare MeasureTheory AbelianMalcevTorus +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + +theorem degree_abelian_compact {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) + (H : Filtration G) (h1 : H.level 1=⊤) (s : ℕ) (hs : H.level (s+1)=⊥) + (h2 : H.level 2=⊥) + (Γ : Subgroup G) (hΓ : ∀ g : G, g∈Γ ↔ ∀ i, ∃ z : ℤ, c.coord g i=z) + [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] + (μ : Measure (G⧸Γ)) [IsProbabilityMeasure μ] [SMulInvariantMeasure G (G⧸Γ) μ] + (K : Set C(G⧸Γ,ℂ)) (hK : IsCompact K) (δ : ℝ) (hδ : 0<δ) : + letI : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + DegreeCompactEstimate s H Γ μ K δ := by + let : CompactSpace (G⧸Γ) := quotient_compact c Γ hΓ + let : MetricSpace (G⧸Γ) := coordinateQuotientMetric c Γ hΓ + have hc : _root_.commutator G ≤ (⊥ : Subgroup G) := by + rw [← h2] + apply Subgroup.commutator_le.mpr + intro a _ b _ + exact SquareHorizontalCharacter.commutator_mem H h1 a b + have hadd := coordinates_additive_of_commutator_bot c hsk hc + obtain ⟨U,hU,A,hA,hprod⟩ := quantitative_abelian_compact_producer c hadd Γ hΓ rfl H s hs μ K hK δ hδ + refine ⟨U,A,hA,1,by decide,?_⟩ + intro N hN f hf hdisc + obtain ⟨χ,hχ,hχ0,P,hP,hPe,hPc⟩ := hprod N hN f hf hdisc + exact ⟨χ,hχ,hχ0,(hU χ hχ).1,(hU χ hχ).2,P,hP,hPe,hPc⟩ + +end SquareInduction +end +end + + + +section +noncomputable section +namespace SquareInduction +open CubeFaces CubePolynomials LeibmanSquare RationalLattice MalcevCharacters +open MeasureTheory PolynomialWeyl AbelianMalcevTorus MalcevCentralTorus RationalTailCoordinates UnitAddTorus +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + + +theorem degree_rank_statement_of_lower (s : ℕ) (hs2 : 2 ≤ s) + (ID : DegreeStatement (s-1)) (n k : ℕ) : DegreeRankStatement G s n k := by + classical + induction k using Nat.strong_induction_on with + | h k ih => + intro c hsk H h0 h1 hs q hqbound hq hr Γ hΓ mΓ bΓ μ pμ sμ K hK δ hδ + let : ∀ i, (H.level i).Normal := fun i => level_normal H h0 i + cases he : n-q 2 with + | zero => + have h2 : H.level 2=⊥ := by + apply le_antisymm ?_ bot_le + intro g hg + change g=1 + apply c.coord.injective + funext i + rw [c.one_coord] + exact (hq 2 g).mp hg i (by have := hqbound 2; omega) + exact degree_abelian_compact c hsk H h1 s hs h2 Γ hΓ μ K hK δ hδ + | succ d => + have hd : d + intro G _ _ _ n k + by_cases hs2 : 2 ≤ s + · exact degree_rank_statement_of_lower s hs2 (ih (s-1) (by omega)) n k + · intro c hsk H h0 h1 hs q hqbound hq hr Γ hΓ mΓ bΓ μ pμ sμ K hK δ hδ + have h2 : H.level 2=⊥ := by + apply le_antisymm _ bot_le + calc + H.level 2 ≤ H.level (s+1) := H.antitone (by omega) + _ = ⊥ := hs + exact degree_abelian_compact c hsk H h1 s hs h2 Γ hΓ μ K hK δ hδ + + + +theorem degree_compact_producer {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) + (H : Filtration G) (h0 : H.level 0=⊤) (h1 : H.level 1=⊤) (s : ℕ) (hs : H.level (s+1)=⊥) + (q : ℕ→ℕ) (hqbound : ∀ i, q i ≤ n) + (hq : ∀ i (g : G), g∈H.level i ↔ ∀ j : Fin n, j.val QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ s ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 QuotientGroup.mk (f k)) F‖ ≤ δ/2 := by + change ‖(𝔼 k∈Finset.range N,F (QuotientGroup.mk (f k)))-(∫ x,F x ∂μ)‖ ≤ _ + rw [← Finset.expect_const (s:=Finset.range N) + (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)) (∫ x,F x ∂μ),← Finset.expect_sub_distrib] + exact (RCLike.norm_expect_le (K:=ℂ)).trans (Finset.expect_le + (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hN)) (fun k hk => (hh k hk).le)) + linarith + obtain ⟨k,hk,hkdisc⟩ := hp + have hc : LeibmanSquare.Polynomial H 0 (fun _ : ℤ => f k) := + polynomial_of_cube_mem H (const_mem (by rw [h0]; trivial)) + have hcd : δ/2 ≤ ‖FourierObstruction.discrepancy μ M + (fun _ => QuotientGroup.mk (f k)) F‖ := by + simpa only [FourierObstruction.discrepancy,LinearMap.coe_mk,AddHom.coe_mk, + Finset.expect_const (Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hM))] using hkdisc + obtain ⟨ξ,hξ,hξ0,hξc,hξΓ,_⟩ := hprod M le_rfl (fun _ => f k) hc ⟨F,hF,hcd⟩ + obtain ⟨P,hP,hPe⟩ := character_polynomial H s hs hf ξ + refine ⟨ξ,hξ,hξ0,hξc,hξΓ,P,hP,hPe,?_⟩ + intro j hj + by_cases hjs : j ≤ s + · refine ⟨round (P.coeff j),(abs_sub_round _).trans ?_⟩ + apply (le_div_iff₀ (pow_pos (by positivity : (0:ℝ) QuotientGroup.mk (f k)) F‖) → + ∃ ξ∈U, ξ≠1 ∧ Continuous ξ ∧ (∀ g∈Γ, ∃ z : ℤ, (ξ g).toAdd=z) ∧ + ∃ P : ℝ[X], P.natDegree ≤ s ∧ (∀ z : ℤ, P.eval (z:ℝ)=(ξ (f z)).toAdd) ∧ + ∀ j : ℕ, 0 x) (by rw [htop]; exact @continuous_id _ (QuotientGroup.instTopologicalSpace Γ)) + let pull := @ContinuousMap.compCLM (G⧸Γ) (G⧸Γ) (QuotientGroup.instTopologicalSpace Γ) + mtr.toUniformSpace.toTopologicalSpace ℂ ℂ _ _ _ _ _ _ e0 + have hK' : IsCompact (pull '' K) := hK.image pull.continuous + obtain ⟨U,A,hA,hprod⟩ := degree_general_compact_all_lengths c hsk H h0 h1 s hs + q hqbound hq Γ hΓ μ (pull '' K) hK' δ hδ + refine ⟨U,A,hA,?_⟩ + intro N hN f hf ⟨F,hFL,hFn,hdisc⟩ + apply hprod N hN f hf + refine ⟨pull F,⟨F,hunit F hFL hFn,rfl⟩,?_⟩ + change δ ≤ ‖mean N (fun k => F (QuotientGroup.mk (f k)))-(∫ x,F x ∂μ)‖ + exact hdisc + +end SquareInduction + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/TailCharacter01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/TailCharacter01.lean new file mode 100644 index 0000000000000000000000000000000000000000..ecb2d42b08b50a4a1698f034cf83025b1ac5e93b --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/TailCharacter01.lean @@ -0,0 +1,472 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.MalcevCharacters01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace TailRefinementCharts +open RationalLattice MalcevCharacters RationalTailCoordinates IntegerHyperplane +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {r n : ℕ} (c : RealCoordinates G (r+n)) (hsk : SecondKind c) +variable (H : Subgroup G) +variable (hH : ∀ g : G, g∈H ↔ ∀ i : Fin (r+n), i.val < r → c.coord g i=0) + +def prefixVector (x : Fin (r+n) → ℝ) (i : Fin (r+n)) : ℝ := + if i.val < r then x i else 0 + +def prefixElement (g : G) : G := c.coord.symm (prefixVector (r:=r) (c.coord g)) +def tail (g : G) : H := rebuild c H hH (fun i => c.coord g (embed r i)) + +omit [IsTopologicalGroup G] in +@[simp] lemma prefix_coord (g : G) (i : Fin (r+n)) : + c.coord (prefixElement c g) i=prefixVector (r:=r) (c.coord g) i := by + simp [prefixElement] +omit [IsTopologicalGroup G] in +@[simp] lemma tail_coord (g : G) (i : Fin n) : + c.coord (tail c H hH g).val (embed r i)=c.coord g (embed r i) := by + simp [tail,rebuild] + +include hsk in +omit [IsTopologicalGroup G] in +lemma prefix_product (g : G) : prefixElement c g= + (List.ofFn (fun i : Fin r => axis c (i.castLE (Nat.le_add_right r n)) + (c.coord g (i.castLE (Nat.le_add_right r n))))).prod := by + rw [hsk.ordered (prefixElement c g),List.ofFn_add,List.prod_append] + have hz : (List.ofFn (fun i : Fin n => axis c (Fin.natAdd r i) + (c.coord (prefixElement c g) (Fin.natAdd r i)))).prod=1 := by + have he : (fun i : Fin n => axis c (Fin.natAdd r i) + (c.coord (prefixElement c g) (Fin.natAdd r i)))=fun _ => (1:G) := by + funext i + simp [prefixVector] + rw [he] + simp + rw [hz,mul_one] + congr 1 + apply List.ofFn_inj.mpr + funext i + simp [prefixVector,i.isLt] + +include hsk in +lemma decompose (g : G) : g=prefixElement c g*(tail c H hH g).val := by + rw [prefix_product c hsk] + have ht := (tail_secondKind c H hH hsk).ordered (tail c H hH g) + have ht' := congrArg Subtype.val ht + simp only [← H.subtype_apply,map_list_prod,List.map_ofFn] at ht' + change (tail c H hH g).val=(List.ofFn (fun i : Fin n => (axis (tailCoordinates c H hH) i ((tailCoordinates c H hH).coord (tail c H hH g) i)).val)).prod at ht' + simp only [axis_val] at ht' + have hc : ∀ i, (tailCoordinates c H hH).coord (tail c H hH g) i=c.coord g (embed r i) := + fun i => tail_coord c H hH g i + simp_rw [hc] at ht' + rw [ht'] + conv_lhs => rw [hsk.ordered g,List.ofFn_add,List.prod_append] + rfl + +omit [IsTopologicalGroup G] in +lemma prefix_congr {g h : G} (he : ∀ i : Fin (r+n),i.val < r → c.coord g i=c.coord h i) : + prefixElement c g=prefixElement c h := by + unfold prefixElement + apply congrArg c.coord.symm + funext i + unfold prefixVector + split_ifs with hi + · exact he i hi + · rfl + +omit [IsTopologicalGroup G] in +lemma prefix_mul_congr (hr : r < r+n) (g h : G) : + prefixElement c (g*h)=prefixElement c (prefixElement c g*prefixElement c h) := by + apply prefix_congr c + exact mul_lower_congr c ⟨r,hr⟩ + (fun i hi => by simp [prefixVector,(show i.val < r from hi)]) + (fun i hi => by simp [prefixVector,(show i.val < r from hi)]) + +variable (χ : H →* Multiplicative ℝ) +variable (hconj : ∀ (g : G) (x : H), g⁻¹*x.val*g∈H) +variable (hχconj : ∀ (g : G) (x : H), χ ⟨g⁻¹*x.val*g,hconj g x⟩=χ x) + +include hsk hχconj in + + +theorem tail_character_mul (hr : r < r+n) (g h : G) : + (χ (tail c H hH (g*h))).toAdd = (χ (tail c H hH g)).toAdd+ + (χ (tail c H hH h)).toAdd+ + (χ (tail c H hH (prefixElement c g*prefixElement c h))).toAdd := by + let a:=prefixElement c g + let b:=prefixElement c h + let u:=tail c H hH g + let v:=tail c H hH h + let e:=tail c H hH (a*b) + let u':H:=⟨b⁻¹*u.val*b,hconj b u⟩ + have he : tail c H hH (g*h)=e*u'*v := by + apply Subtype.ext + have hg := decompose c hsk H hH g + have hh := decompose c hsk H hH h + have hab := decompose c hsk H hH (a*b) + have hgh := decompose c hsk H hH (g*h) + have hp := prefix_mul_congr c hr g h + change g=a*u.val at hg + change h=b*v.val at hh + change a*b=prefixElement c (a*b)*e.val at hab + change prefixElement c (g*h)=prefixElement c (a*b) at hp + rw [hp] at hgh + change (tail c H hH (g*h)).val=e.val*(b⁻¹*u.val*b)*v.val + apply mul_left_cancel (a:=prefixElement c (a*b)) + rw [← hgh,hg,hh] + calc (a*u.val)*(b*v.val)=(a*b)*((b⁻¹*u.val*b)*v.val) := by group + _ = (prefixElement c (a*b)*e.val)*((b⁻¹*u.val*b)*v.val) := congrArg (fun z => z*((b⁻¹*u.val*b)*v.val)) hab + _ = _ := by group + rw [he,χ.map_mul,χ.map_mul] + change (χ e).toAdd+(χ u').toAdd+(χ v).toAdd=_ + rw [show χ u'=χ u from hχconj b u] + dsimp [e,u,v,a,b] + ring + +end TailRefinementCharts + +namespace BlockSplitCoordinates +open RationalTailCoordinates IntegerHyperplane RationalPolynomialMap +variable {r n : ℕ} + +def blockMap (f : (Fin n → ℝ) → (Fin n → ℝ)) (x : Fin (r+n) → ℝ) + (i : Fin (r+n)) : ℝ := + if hi : i.val < r then x i else f (fun j => x (embed r j)) ⟨i.val-r,by omega⟩ + +@[simp] lemma blockMap_prefix (f : (Fin n → ℝ) → (Fin n → ℝ)) + (x : Fin (r+n) → ℝ) (i : Fin (r+n)) (hi : i.val < r) : blockMap f x i=x i := by + simp [blockMap,hi] +@[simp] lemma blockMap_embed (f : (Fin n → ℝ) → (Fin n → ℝ)) + (x : Fin (r+n) → ℝ) (i : Fin n) : + blockMap f x (embed r i)=f (fun j => x (embed r j)) i := by + simp [blockMap,embed] + +lemma blockMap_comp (f g : (Fin n → ℝ) → (Fin n → ℝ)) (x : Fin (r+n) → ℝ) : + blockMap f (blockMap g x)=blockMap (f ∘ g) x := by + funext i + unfold blockMap + split_ifs with hi + · rfl + · congr 2 + funext j + simp [embed] + +lemma blockMap_id (x : Fin (r+n) → ℝ) : blockMap id x=x := by + funext i + unfold blockMap + split_ifs with hi + · rfl + · apply congrArg x + apply Fin.ext + simp only [embed] + omega + +lemma blockMap_continuous {f : (Fin n → ℝ) → (Fin n → ℝ)} (hf : Continuous f) : + Continuous (blockMap (r:=r) f) := by + apply continuous_pi + intro i + unfold blockMap + split_ifs + · exact continuous_apply _ + · exact (continuous_apply _).comp (hf.comp (continuous_pi (fun _ => continuous_apply _))) + +def blockHomeomorph (f : (Fin n → ℝ) ≃ₜ (Fin n → ℝ)) : + (Fin (r+n) → ℝ) ≃ₜ (Fin (r+n) → ℝ) where + toFun := blockMap f + invFun := blockMap f.symm + left_inv x := by + rw [blockMap_comp] + have he : ((f.symm : (Fin n → ℝ) → (Fin n → ℝ))∘f)=id := by + funext y; exact f.symm_apply_apply y + rw [he,blockMap_id] + right_inv x := by + rw [blockMap_comp] + have he : ((f : (Fin n → ℝ) → (Fin n → ℝ))∘f.symm)=id := by + funext y; exact f.apply_symm_apply y + rw [he,blockMap_id] + continuous_toFun := blockMap_continuous f.continuous + continuous_invFun := blockMap_continuous f.symm.continuous + +lemma blockMap_polynomial (f : (Fin n → ℝ) → (Fin n → ℝ)) + (hf : ∀ j, IsPolynomial (fun x => f x j)) (i : Fin (r+n)) : + IsPolynomial (fun x => blockMap f x i) := by + unfold blockMap + split_ifs + · exact coordinate _ + · exact comp (hf _) (fun _ => coordinate _) + +lemma splitCoordinates_polynomial (k : Fin (n+1) → ℤ) (p : Fin (n+1)) (i : Fin (n+1)) : + IsPolynomial (fun x => splitCoordinates k p x i) := by + refine Fin.cases ?_ (fun j => ?_) i + · change IsPolynomial (fun x => (∑ j,(k j:ℝ)*x j)/(k p:ℝ)) + have hsum : IsPolynomial (fun x : Fin (n+1) → ℝ => ∑ j,(k j:ℝ)*x j) := by + refine ⟨∑ j,MvPolynomial.C (k j:ℚ)*MvPolynomial.X j,?_⟩ + intro x + rw [MvPolynomial.eval₂_sum] + apply Finset.sum_congr rfl + intro j _ + rw [MvPolynomial.eval₂_mul,MvPolynomial.eval₂_C,MvPolynomial.eval₂_X] + simp + simpa only [Rat.cast_inv,Rat.cast_intCast,div_eq_mul_inv] using mul hsum (const ((k p:ℚ)⁻¹)) + · exact coordinate _ +end BlockSplitCoordinates + +namespace TailCharacterRechart +open RationalLattice MalcevCharacters RationalTailCoordinates IntegerHyperplane +open BlockSplitCoordinates TailRefinementCharts RationalPolynomialMap +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {r n : ℕ} (c : RealCoordinates G (r+(n+1))) +variable (k : Fin (n+1) → ℤ) (p : Fin (n+1)) (hp : k p≠0) + +def chartHomeomorph : G ≃ₜ (Fin (r+(n+1)) → ℝ) := + c.coord.trans (blockHomeomorph (r:=r) (splitHomeomorph k p hp)) + +omit [IsTopologicalGroup G] in +lemma chart_prefix (g : G) (i : Fin (r+(n+1))) (hi : i.val < r) : + chartHomeomorph c k p hp g i=c.coord g i := blockMap_prefix _ _ _ hi +omit [IsTopologicalGroup G] in +lemma chart_head (g : G) : chartHomeomorph c k p hp g (embed r 0)= + form k (fun j => c.coord g (embed r j))/(k p:ℝ) := by + change blockMap (splitCoordinates k p) (c.coord g) (embed r 0)=_ + rw [blockMap_embed] + rfl +omit [IsTopologicalGroup G] in +lemma chart_tail (g : G) (i : Fin n) : + chartHomeomorph c k p hp g (embed r i.succ)=c.coord g (embed r (p.succAbove i)) := by + change blockMap (splitCoordinates k p) (c.coord g) (embed r i.succ)=_ + rw [blockMap_embed] + rfl + +omit [IsTopologicalGroup G] in +lemma chart_polynomial (i : Fin (r+(n+1))) : + IsPolynomial (fun x => chartHomeomorph c k p hp (c.coord.symm x) i) := by + change IsPolynomial (fun x => blockMap (splitCoordinates k p) (c.coord (c.coord.symm x)) i) + simp only [Homeomorph.apply_symm_apply] + exact blockMap_polynomial _ (splitCoordinates_polynomial k p) i +omit [IsTopologicalGroup G] in +lemma inverse_polynomial (i : Fin (r+(n+1))) : + IsPolynomial (fun x => c.coord ((chartHomeomorph c k p hp).symm x) i) := by + change IsPolynomial (fun x => c.coord (c.coord.symm (blockMap (splitLift k p) x)) i) + simp only [Homeomorph.apply_symm_apply] + exact blockMap_polynomial _ (splitLift_polynomial k p) i + +omit [IsTopologicalGroup G] in +lemma chart_one (i : Fin (r+(n+1))) : chartHomeomorph c k p hp 1 i=0 := by + by_cases hi : i.val < r + · rw [chart_prefix c k p hp 1 i hi,c.one_coord] + · let a : Fin (n+1):=⟨i.val-r,by omega⟩ + have he : i=embed r a := by apply Fin.ext; simp [a,embed]; omega + rw [he] + refine Fin.cases ?_ (fun j => ?_) a + · rw [chart_head] + simp [form,c.one_coord] + · rw [chart_tail,c.one_coord] + +variable (hlast : ∀ j : Fin (n+1), p < j → k j=0) +include hlast in +omit [IsTopologicalGroup G] in +lemma old_lower_congr (i : Fin n) {g h : G} + (he : ∀ j : Fin (r+(n+1)),j < embed r i.succ → + chartHomeomorph c k p hp g j=chartHomeomorph c k p hp h j) + (a : Fin (r+(n+1))) (ha : a < embed r (p.succAbove i)) : c.coord g a=c.coord h a := by + by_cases har : a.val < r + · rw [← chart_prefix c k p hp g a har,← chart_prefix c k p hp h a har] + exact he a (by change a.val < r+i.val+1; omega) + · let a' : Fin (n+1):=⟨a.val-r,by omega⟩ + have ha' : a=embed r a' := by apply Fin.ext; simp [a',embed]; omega + rw [ha'] + have ht (u : G) : (fun j => c.coord u (embed r j))= + splitLift k p (fun j => chartHomeomorph c k p hp u (embed r j)) := by + have hh := splitLift_splitCoordinates k p hp (fun j => c.coord u (embed r j)) + change (fun j => c.coord u (embed r j))= + splitLift k p (fun j => blockMap (splitCoordinates k p) (c.coord u) (embed r j)) + simp only [blockMap_embed] + exact hh.symm + rw [congrFun (ht g) a',congrFun (ht h) a'] + apply splitLift_lower_dep k p hlast i + · intro j hj + exact he (embed r j) (Nat.add_lt_add_left hj r) + · change a.val < r+(p.succAbove i).val at ha + change a.val-r < (p.succAbove i).val + omega + +def lowerElement (g : G) (i : Fin (r+(n+1))) : G := + (chartHomeomorph c k p hp).symm + (lowerExtend i (fun j => chartHomeomorph c k p hp g ⟨j.val,lt_trans j.isLt i.isLt⟩)) + +omit [IsTopologicalGroup G] in +lemma lowerElement_coord (g : G) (i j : Fin (r+(n+1))) : + chartHomeomorph c k p hp (lowerElement c k p hp g i) j= + if j.val < i.val then chartHomeomorph c k p hp g j else 0 := by + simp only [lowerElement,Homeomorph.apply_symm_apply,lowerExtend] + split_ifs <;> rfl +omit [IsTopologicalGroup G] in +lemma lowerElement_below (g : G) (i j : Fin (r+(n+1))) (hj : j < i) : + chartHomeomorph c k p hp (lowerElement c k p hp g i) j=chartHomeomorph c k p hp g j := by + rw [lowerElement_coord,ite_eq_left (show j.val < i.val from hj)] +omit [IsTopologicalGroup G] in +lemma lowerElement_at (g : G) (i : Fin (r+(n+1))) : + chartHomeomorph c k p hp (lowerElement c k p hp g i) i=0 := by + rw [lowerElement_coord,ite_eq_right (lt_irrefl _)] + +omit [IsTopologicalGroup G] in +lemma exists_correction (i : Fin (r+(n+1))) : + ∃ P : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ, + ∀ v : (Fin i.val ⊕ Fin i.val) → ℝ, + chartHomeomorph c k p hp + ((chartHomeomorph c k p hp).symm (lowerExtend i (fun j => v (.inl j))) * + (chartHomeomorph c k p hp).symm (lowerExtend i (fun j => v (.inr j)))) i= + MvPolynomial.eval₂ (algebraMap ℚ ℝ) v P := by + have hm : IsPolynomialMap c (fun v : (Fin i.val ⊕ Fin i.val) → ℝ => (chartHomeomorph c k p hp).symm (lowerExtend i (fun j => v (.inl j))) * + (chartHomeomorph c k p hp).symm (lowerExtend i (fun j => v (.inr j)))) := by + apply polynomialMap_mul + all_goals + intro a + apply comp (inverse_polynomial c k p hp a) + intro b + unfold lowerExtend + split_ifs + · exact coordinate _ + · exact zero + have hres := comp (chart_polynomial c k p hp i) hm + simpa only [IsPolynomial,Homeomorph.symm_apply_apply] using hres + +def correction (i : Fin (r+(n+1))) : MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ := + (exists_correction c k p hp i).choose + +omit [IsTopologicalGroup G] in +lemma correction_eval (g h : G) (i : Fin (r+(n+1))) : + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => chartHomeomorph c k p hp g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => chartHomeomorph c k p hp h ⟨j.val,lt_trans j.isLt i.isLt⟩)) + (correction c k p hp i)= + chartHomeomorph c k p hp (lowerElement c k p hp g i*lowerElement c k p hp h i) i := + ((exists_correction c k p hp i).choose_spec _).symm + +omit [IsTopologicalGroup G] in +lemma prefix_defect (g h : G) (i : Fin (r+(n+1))) (hi : i.val < r) : + chartHomeomorph c k p hp (g*h) i=chartHomeomorph c k p hp g i+ + chartHomeomorph c k p hp h i+ + chartHomeomorph c k p hp (lowerElement c k p hp g i*lowerElement c k p hp h i) i := by + have hl (u : G) (j : Fin (r+(n+1))) (hj : j < i) : + c.coord u j=c.coord (lowerElement c k p hp u i) j := by + have hjr : j.val < r:=lt_trans hj hi + rw [← chart_prefix c k p hp u j hjr,← chart_prefix c k p hp _ j hjr, + lowerElement_below c k p hp u i j hj] + have hz (u : G) : c.coord (lowerElement c k p hp u i) i=0 := by + rw [← chart_prefix c k p hp _ i hi,lowerElement_at] + have he := correction_eq_of_lower_eq c i (hl g) (hl h) + simp only [hz,sub_zero] at he + simp only [chart_prefix c k p hp _ i hi] + linarith only [he] + +include hlast in +omit [IsTopologicalGroup G] in +lemma tail_defect (g h : G) (i : Fin n) : + chartHomeomorph c k p hp (g*h) (embed r i.succ)= + chartHomeomorph c k p hp g (embed r i.succ)+ + chartHomeomorph c k p hp h (embed r i.succ)+ + chartHomeomorph c k p hp + (lowerElement c k p hp g (embed r i.succ)*lowerElement c k p hp h (embed r i.succ)) + (embed r i.succ) := by + have hl (u : G) : ∀ a : Fin (r+(n+1)),a < embed r (p.succAbove i) → + c.coord u a=c.coord (lowerElement c k p hp u (embed r i.succ)) a := + old_lower_congr c k p hp hlast i (fun j hj => + (lowerElement_below c k p hp u (embed r i.succ) j hj).symm) + have hz (u : G) : c.coord (lowerElement c k p hp u (embed r i.succ)) (embed r (p.succAbove i))=0 := by + rw [← chart_tail c k p hp _ i,lowerElement_at] + have he := correction_eq_of_lower_eq c (embed r (p.succAbove i)) (hl g) (hl h) + simp only [hz,sub_zero] at he + simp only [chart_tail] + linarith only [he] + +variable (hsk : SecondKind c) (H : Subgroup G) +variable (hH : ∀ g : G, g∈H ↔ ∀ i : Fin (r+(n+1)),i.val < r → c.coord g i=0) +variable (χ : H →* Multiplicative ℝ) +variable (hconj : ∀ (g : G) (x : H),g⁻¹*x.val*g∈H) +variable (hχconj : ∀ (g : G) (x : H),χ ⟨g⁻¹*x.val*g,hconj g x⟩=χ x) +variable (hχ : ∀ x : H,(χ x).toAdd=form k ((tailCoordinates c H hH).coord x)) + +include hχ in +omit [IsTopologicalGroup G] in +lemma chart_head_character (g : G) : chartHomeomorph c k p hp g (embed r 0)= + (χ (tail c H hH g)).toAdd/(k p:ℝ) := by + rw [chart_head,hχ] + congr 2 + funext j + exact (tail_coord c H hH g j).symm + +include hsk hχconj hχ in +lemma head_mul (g h : G) : chartHomeomorph c k p hp (g*h) (embed r 0)= + chartHomeomorph c k p hp g (embed r 0)+chartHomeomorph c k p hp h (embed r 0)+ + chartHomeomorph c k p hp (prefixElement c g*prefixElement c h) (embed r 0) := by + simp only [chart_head_character c k p hp H hH χ hχ] + rw [tail_character_mul c hsk H hH χ hconj hχconj (by omega) g h] + ring + +omit [IsTopologicalGroup G] in +lemma prefix_lower_head (g : G) : + prefixElement c (lowerElement c k p hp g (embed r 0))=prefixElement c g := by + apply prefix_congr + intro i hi + rw [← chart_prefix c k p hp _ i hi,← chart_prefix c k p hp g i hi, + lowerElement_below c k p hp g (embed r 0) i (by change i.val < r+0; omega)] + +include hsk hχconj hχ in +lemma head_defect (g h : G) : chartHomeomorph c k p hp (g*h) (embed r 0)= + chartHomeomorph c k p hp g (embed r 0)+chartHomeomorph c k p hp h (embed r 0)+ + chartHomeomorph c k p hp + (lowerElement c k p hp g (embed r 0)*lowerElement c k p hp h (embed r 0)) (embed r 0) := by + rw [head_mul c k p hp hsk H hH χ hconj hχconj hχ g h] + congr 1 + rw [head_mul c k p hp hsk H hH χ hconj hχconj hχ + (lowerElement c k p hp g (embed r 0)) (lowerElement c k p hp h (embed r 0)), + lowerElement_at,lowerElement_at,prefix_lower_head,prefix_lower_head,zero_add,zero_add] + +include hsk hχconj hχ hlast in +lemma mul_coord (g h : G) (i : Fin (r+(n+1))) : + chartHomeomorph c k p hp (g*h) i=chartHomeomorph c k p hp g i+ + chartHomeomorph c k p hp h i+ + MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (Sum.elim (fun j => chartHomeomorph c k p hp g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => chartHomeomorph c k p hp h ⟨j.val,lt_trans j.isLt i.isLt⟩)) + (correction c k p hp i) := by + rw [correction_eval] + by_cases hi : i.val < r + · exact prefix_defect c k p hp g h i hi + · let a : Fin (n+1):=⟨i.val-r,by omega⟩ + have he : i=embed r a := by apply Fin.ext; simp [a,embed]; omega + rw [he] + refine Fin.cases ?_ (fun j => ?_) a + · exact head_defect c k p hp hsk H hH χ hconj hχconj hχ g h + · exact tail_defect c k p hp hlast g h j + + + +def tailCharacterCoordinates : RealCoordinates G (r+(n+1)) where + coord := chartHomeomorph c k p hp + one_coord := chart_one c k p hp + correction := correction c k p hp + mul_coord := mul_coord c k p hp hlast hsk H hH χ hconj hχconj hχ + +end TailCharacterRechart + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/TorusVertical01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/TorusVertical01.lean new file mode 100644 index 0000000000000000000000000000000000000000..96c745a5a8e32bba79337f91417be9484d8a0c55 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/TorusVertical01.lean @@ -0,0 +1,519 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.FourierObstruction01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +end +end + + + +section + + + +namespace TorusVerticalFourier +open MeasureTheory AddCircle UnitAddTorus Set +noncomputable section + +variable {d : Type*} [Fintype d] +local instance : MeasureSpace UnitAddCircle := ⟨AddCircle.haarAddCircle⟩ +local instance : Measure.IsAddHaarMeasure (volume : Measure UnitAddCircle) := + inferInstanceAs (Measure.IsAddHaarMeasure AddCircle.haarAddCircle) +local instance : IsProbabilityMeasure (volume : Measure UnitAddCircle) := + inferInstanceAs (IsProbabilityMeasure AddCircle.haarAddCircle) + + + +theorem finite_tests_of_dense_span {E ι : Type*} [NormedAddCommGroup E] + [NormedSpace ℂ E] (v : ι → E) + (hv : (Submodule.span ℂ (Set.range v)).topologicalClosure = ⊤) + (K : Set E) (hK : IsCompact K) (δ B : ℝ) (hδ : 0 < δ) (hB : 0 < B) : + ∃ S : Finset ι, ∃ η : ℝ, 0 < η ∧ + ∀ L : E →ₗ[ℂ] ℂ, (∀ f, ‖L f‖ ≤ B * ‖f‖) → + (∃ f ∈ K, δ ≤ ‖L f‖) → ∃ i ∈ S, η ≤ ‖L (v i)‖ := by + classical + let ε := δ / (4 * B) + have hε : 0 < ε := by dsimp [ε]; positivity + have happ (f : E) : ∃ c : ι →₀ ℂ, dist f (c.sum fun i a => a • v i) < ε := by + have hf : f ∈ closure (Submodule.span ℂ (Set.range v) : Set E) := by + rw [← Submodule.topologicalClosure_coe, hv] + trivial + obtain ⟨g, hg, hfg⟩ := Metric.mem_closure_iff.mp hf ε hε + obtain ⟨c, rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp hg + exact ⟨c, hfg⟩ + choose c hc using happ + let P : E → E := fun f => (c f).sum fun i a => a • v i + obtain ⟨t, ht⟩ := hK.elim_finite_subcover (fun f => Metric.ball (P f) ε) + (fun _ => Metric.isOpen_ball) (by + intro f _ + exact Set.mem_iUnion.mpr ⟨f, hc f⟩) + let H := 1 + ∑ f ∈ t, ∑ i ∈ (c f).support, ‖c f i‖ + have hH : 0 < H := by + dsimp [H] + positivity + let η := δ / (4 * H) + have hη : 0 < η := by dsimp [η]; positivity + refine ⟨t.biUnion (fun f => (c f).support), η, hη, ?_⟩ + intro L hL ⟨f, hf, hlarge⟩ + obtain ⟨g, hg, hfg⟩ := Set.mem_iUnion₂.mp (ht hf) + have hfg' : dist f (P g) < ε := hfg + by_contra hno + push Not at hno + have hPg : ‖L (P g)‖ ≤ H * η := by + calc + _ = ‖∑ i ∈ (c g).support, (c g i) • L (v i)‖ := by + simp [P, Finsupp.sum, map_sum] + _ ≤ ∑ i ∈ (c g).support, ‖c g i‖ * ‖L (v i)‖ := by + simpa only [norm_smul] using norm_sum_le (c g).support (fun i => c g i • L (v i)) + _ ≤ ∑ i ∈ (c g).support, ‖c g i‖ * η := by + apply Finset.sum_le_sum + intro i hi + apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) + exact (hno i (Finset.mem_biUnion.mpr ⟨g, hg, hi⟩)).le + _ = (∑ i ∈ (c g).support, ‖c g i‖) * η := by rw [Finset.sum_mul] + _ ≤ H * η := by + apply mul_le_mul_of_nonneg_right _ hη.le + have hsum := Finset.single_le_sum (f := fun x => ∑ i ∈ (c x).support, ‖c x i‖) (fun x (_ : x ∈ t) => + Finset.sum_nonneg (fun i _ => norm_nonneg (c x i))) hg + dsimp [H] + linarith only [hsum] + have hdist : ‖L (f - P g)‖ < B * ε := by + calc + _ ≤ B * ‖f - P g‖ := hL _ + _ < B * ε := mul_lt_mul_of_pos_left (by simpa only [dist_eq_norm] using hfg') hB + have hsum := norm_add_le (L (f - P g)) (L (P g)) + rw [← map_add, sub_add_cancel] at hsum + have he₁ : B * ε = δ / 4 := by dsimp [ε]; field_simp + have he₂ : H * η = δ / 4 := by dsimp [η]; field_simp + rw [he₁] at hdist + rw [he₂] at hPg + linarith + + + +theorem compact_superset_unit_lipschitz (X : Type*) [MetricSpace X] [CompactSpace X] : + ∃ K : Set C(X, ℂ), IsCompact K ∧ + ∀ f : C(X, ℂ), LipschitzWith 1 f → ‖f‖ ≤ 1 → f ∈ K := by + let e := ContinuousMap.isometryEquivBoundedOfCompact X ℂ + let A : Set (BoundedContinuousFunction X ℂ) := {f | LipschitzWith 1 f ∧ ‖f‖ ≤ 1} + have heqc : Equicontinuous ((↑) : A → X → ℂ) := by + intro x + rw [Metric.equicontinuousAt_iff] + intro ε hε + refine ⟨ε, hε, ?_⟩ + intro y hxy f + have h := f.property.1.dist_le_mul x y + simp only [NNReal.coe_one, one_mul, dist_comm x y] at h + exact h.trans_lt hxy + have hc : IsCompact (closure A) := BoundedContinuousFunction.arzela_ascoli + (Metric.closedBall (0 : ℂ) 1) (isCompact_closedBall _ _) A (by + intro f x hf + simp only [Metric.mem_closedBall, dist_zero_right] + exact (f.norm_coe_le_norm x).trans hf.2) heqc + refine ⟨e.symm '' closure A, hc.image e.symm.continuous, ?_⟩ + intro f hl hn + refine ⟨e f, subset_closure ⟨hl, ?_⟩, e.symm_apply_apply f⟩ + simpa only [e, ContinuousMap.isometryEquivBoundedOfCompact_apply, + BoundedContinuousFunction.norm_mkOfCompact] using hn + +variable {X : Type*} [MetricSpace X] [CompactSpace X] + [AddAction (UnitAddTorus d) X] [ContinuousVAdd (UnitAddTorus d) X] + +lemma character_add (k : d → ℤ) (s t : UnitAddTorus d) : + mFourier k (s+t) = mFourier k s * mFourier k t := by + simp only [mFourier,ContinuousMap.coe_mk,Pi.add_apply,fourier_apply,smul_add,toCircle_add,Circle.coe_mul, + Finset.prod_mul_distrib] + +lemma character_cancel (k : d → ℤ) (s : (UnitAddTorus d)) : + mFourier k s * mFourier (-k) s = 1 := by + rw [← mFourier_add,add_neg_cancel,mFourier_zero,ContinuousMap.one_apply] + + +def coeff (F : C(X, ℂ)) (k : d → ℤ) : C(X, ℂ) where + toFun x := ∫ t : (UnitAddTorus d), mFourier (-k) t * F (t +ᵥ x) ∂volume + continuous_toFun := by + have h := continuous_parametric_integral_of_continuous + (μ := (volume : Measure (UnitAddTorus d))) + (f := fun x : X => fun t : (UnitAddTorus d) => mFourier (-k) t * F (t +ᵥ x)) + (by fun_prop) (s := Set.univ) isCompact_univ + simpa only [Measure.restrict_univ] using h + +@[simp] lemma coeff_apply (F : C(X, ℂ)) (k : d → ℤ) (x : X) : + coeff F k x = ∫ t : (UnitAddTorus d), mFourier (-k) t * F (t +ᵥ x) ∂volume := rfl + + + +lemma coeff_vadd (F : C(X, ℂ)) (k : d → ℤ) (s : (UnitAddTorus d)) (x : X) : + coeff F k (s +ᵥ x) = mFourier k s * coeff F k x := by + rw [coeff_apply,coeff_apply,← integral_const_mul] + rw [← integral_add_right_eq_self + (fun t : (UnitAddTorus d) => mFourier k s * (mFourier (-k) t * F (t +ᵥ x))) s] + congr 1 + ext t + rw [character_add,add_vadd] + have hc := character_cancel k s + calc + mFourier (-k) t * F (t +ᵥ s +ᵥ x) = + (mFourier k s * mFourier (-k) s) * (mFourier (-k) t * F (t +ᵥ s +ᵥ x)) := by rw [hc,one_mul] + _ = _ := by ring + + + +lemma torus_coeff_unique (F : C((UnitAddTorus d), ℂ)) + (hF : ∀ k : d → ℤ, mFourierCoeff F k = 0) : F = 0 := by + have hc : mFourierCoeff F = (fun _ : d → ℤ => (0 : ℂ)) := funext hF + have hsum : Summable (mFourierCoeff F) := by rw [hc]; exact summable_zero + have h := hasSum_mFourier_series_of_summable hsum + have hz : (fun i : d → ℤ => mFourierCoeff F i • (mFourier i : C((UnitAddTorus d), ℂ))) = + (fun _ : d → ℤ => (0 : C((UnitAddTorus d), ℂ))) := by + funext i + rw [hF i] + ext x + exact zero_mul _ + rw [hz] at h + exact h.unique hasSum_zero + + + +lemma coeff_unique_at (F : C(X, ℂ)) (x : X) + (hF : ∀ k : d → ℤ, coeff F k x = 0) : F x = 0 := by + let H : C((UnitAddTorus d), ℂ) := ⟨fun t => F (t +ᵥ x), by fun_prop⟩ + have hH : H = 0 := torus_coeff_unique H (by + intro k + exact hF k) + have h := congrArg (fun f : C((UnitAddTorus d), ℂ) => f 0) hH + simpa only [H,ContinuousMap.coe_mk,zero_vadd,ContinuousMap.zero_apply] using h + + +def HasWeight (k : d → ℤ) (F : C(X, ℂ)) : Prop := + ∀ (s : (UnitAddTorus d)) (x : X), F (s +ᵥ x) = mFourier k s * F x + +lemma coeff_hasWeight (F : C(X, ℂ)) (k : d → ℤ) : HasWeight k (coeff F k) := coeff_vadd F k + +omit [CompactSpace X] [ContinuousVAdd (UnitAddTorus d) X] in +lemma hasWeight_one : HasWeight (d := d) (X := X) 0 1 := by + intro s x + simp only [ContinuousMap.one_apply,mFourier_zero,ContinuousMap.one_apply,mul_one] + +omit [CompactSpace X] [ContinuousVAdd (UnitAddTorus d) X] in +lemma HasWeight.mul {F G : C(X, ℂ)} {k l : d → ℤ} + (hF : HasWeight k F) (hG : HasWeight l G) : HasWeight (k+l) (F*G) := by + intro s x + simp only [ContinuousMap.mul_apply,hF s,hG s,mFourier_add] + ring + +omit [CompactSpace X] [ContinuousVAdd (UnitAddTorus d) X] in +lemma HasWeight.star {F : C(X, ℂ)} {k : d → ℤ} + (hF : HasWeight k F) : HasWeight (-k) (star F) := by + intro s x + simp only [ContinuousMap.star_apply,hF s,mFourier_neg] + change (starRingEnd ℂ) (_ * _) = (starRingEnd ℂ) _ * (starRingEnd ℂ) _ + exact map_mul _ _ _ + + +def eigenfunctions : Set C(X, ℂ) := {F | ∃ k : d → ℤ, HasWeight k F} + + +def eigenAlgebra : StarSubalgebra ℂ C(X, ℂ) where + toSubalgebra := Algebra.adjoin ℂ (eigenfunctions (d := d)) + star_mem' := by + change Algebra.adjoin ℂ (eigenfunctions (d := d)) ≤ star (Algebra.adjoin ℂ (eigenfunctions (d := d))) + refine Algebra.adjoin_le ?_ + rintro F ⟨k,hk⟩ + exact Algebra.subset_adjoin ⟨-k,hk.star⟩ + +omit [ContinuousVAdd (UnitAddTorus d) X] in +lemma eigenAlgebra_span : (eigenAlgebra (d := d)).toSubalgebra.toSubmodule = + Submodule.span ℂ ((eigenfunctions (d := d) (X := X))) := by + apply Algebra.adjoin_eq_span_of_subset + refine Set.Subset.trans ?_ Submodule.subset_span + intro F hF + refine Submonoid.closure_induction (fun _ => id) ⟨0,hasWeight_one⟩ ?_ hF + rintro F G _ _ ⟨k,hk⟩ ⟨l,hl⟩ + exact ⟨k+l,hk.mul hl⟩ + + +lemma coeff_eval_eq (F : C(X, ℂ)) (x y : X) + (hxy : ∀ k : d → ℤ, coeff F k x = coeff F k y) : F x = F y := by + let H : C((UnitAddTorus d), ℂ) := ⟨fun t => F (t +ᵥ x) - F (t +ᵥ y), by fun_prop⟩ + have hH : H = 0 := torus_coeff_unique H (by + intro k + change (∫ t : (UnitAddTorus d), mFourier (-k) t * (F (t +ᵥ x) - F (t +ᵥ y)) + ∂volume) = 0 + simp only [mul_sub] + rw [integral_sub] + · exact sub_eq_zero.mpr (hxy k) + · exact (show Continuous (fun t : (UnitAddTorus d) => mFourier (-k) t * F (t +ᵥ x)) by + fun_prop).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + · exact (show Continuous (fun t : (UnitAddTorus d) => mFourier (-k) t * F (t +ᵥ y)) by + fun_prop).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _)) + have h := congrArg (fun f : C((UnitAddTorus d), ℂ) => f 0) hH + simpa only [H,ContinuousMap.coe_mk,zero_vadd,ContinuousMap.zero_apply,sub_eq_zero] using h + +lemma eigenAlgebra_separatesPoints : ((eigenAlgebra (d := d) (X := X))).SeparatesPoints := by + intro x y hxy + let F : C(X, ℂ) := ⟨fun z => (dist z x : ℂ), by fun_prop⟩ + have hF : F x ≠ F y := by + intro h + have h' : dist y x = 0 := by + have hc : (0 : ℂ) = (dist y x : ℂ) := by simpa only [F,ContinuousMap.coe_mk,dist_self,Complex.ofReal_zero] using h + exact (Complex.ofReal_eq_zero.mp hc.symm) + exact hxy (dist_eq_zero.mp h').symm + have hk : ∃ k : d → ℤ, coeff F k x ≠ coeff F k y := by + by_contra h + push Not at h + exact hF (coeff_eval_eq F x y h) + obtain ⟨k,hk⟩ := hk + exact ⟨_,⟨coeff F k,Algebra.subset_adjoin ⟨k,coeff_hasWeight F k⟩,rfl⟩,hk⟩ + + + +theorem eigenfunctions_dense : + (Submodule.span ℂ ((eigenfunctions (d := d) (X := X)))).topologicalClosure = ⊤ := by + rw [← eigenAlgebra_span] + exact congrArg (Subalgebra.toSubmodule ∘ StarSubalgebra.toSubalgebra) + (ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints + (eigenAlgebra (d := d)) eigenAlgebra_separatesPoints) + + + +lemma coeff_lipschitz [IsIsometricVAdd (UnitAddTorus d) X] + (F : C(X, ℂ)) {C : NNReal} (hF : LipschitzWith C F) (k : d → ℤ) : + LipschitzWith C (coeff F k) := by + apply LipschitzWith.of_dist_le_mul + intro x y + have hx : Integrable (fun t : (UnitAddTorus d) => mFourier (-k) t * F (t +ᵥ x)) volume := + (show Continuous (fun t : (UnitAddTorus d) => mFourier (-k) t * F (t +ᵥ x)) by + fun_prop).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hy : Integrable (fun t : (UnitAddTorus d) => mFourier (-k) t * F (t +ᵥ y)) volume := + (show Continuous (fun t : (UnitAddTorus d) => mFourier (-k) t * F (t +ᵥ y)) by + fun_prop).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + rw [dist_eq_norm,coeff_apply,coeff_apply,← integral_sub hx hy] + have hb : ∀ t : (UnitAddTorus d), + ‖mFourier (-k) t * F (t +ᵥ x) - mFourier (-k) t * F (t +ᵥ y)‖ ≤ C * dist x y := by + intro t + rw [← mul_sub,norm_mul] + have hn : ‖mFourier (-k) t‖ = 1 := by + simp only [mFourier,ContinuousMap.coe_mk,norm_prod,fourier_apply,Circle.norm_coe,Finset.prod_const_one] + rw [hn,one_mul,← dist_eq_norm] + simpa only [(isometry_vadd X t).dist_eq] using hF.dist_le_mul (t +ᵥ x) (t +ᵥ y) + simpa only [probReal_univ,mul_one] using + norm_integral_le_of_norm_le_const (μ := (volume : Measure (UnitAddTorus d))) + (Filter.Eventually.of_forall hb) + + + +omit [AddAction (UnitAddTorus d) X] [ContinuousVAdd (UnitAddTorus d) X] in +lemma lipschitz_mul (F G : C(X, ℂ)) {C D : NNReal} + (hF : LipschitzWith C F) (hG : LipschitzWith D G) : + LipschitzWith (‖F‖₊ * D + ‖G‖₊ * C) (F*G) := by + apply LipschitzWith.of_dist_le_mul + intro x y + change dist (F x * G x) (F y * G y) ≤ _ + calc + _ = ‖F x * (G x-G y) + (F x-F y) * G y‖ := by rw [dist_eq_norm]; congr 1; ring + _ ≤ ‖F x‖ * ‖G x-G y‖ + ‖F x-F y‖ * ‖G y‖ := by + simpa only [norm_mul] using norm_add_le (F x * (G x-G y)) ((F x-F y) * G y) + _ ≤ ‖F‖ * (D * dist x y) + (C * dist x y) * ‖G‖ := by + gcongr + · exact F.norm_coe_le_norm x + · simpa only [dist_eq_norm] using hG.dist_le_mul x y + · simpa only [dist_eq_norm] using hF.dist_le_mul x y + · exact G.norm_coe_le_norm y + _ = _ := by simp only [NNReal.coe_add,NNReal.coe_mul,coe_nnnorm]; ring + + +def lipEigenfunctions : Set C(X, ℂ) := + {F | (∃ k : d → ℤ, HasWeight k F) ∧ ∃ C : NNReal, LipschitzWith C F} + +omit [CompactSpace X] [ContinuousVAdd (UnitAddTorus d) X] in +lemma lipEigenfunctions_one : (1 : C(X, ℂ)) ∈ (lipEigenfunctions (d := d)) := + ⟨⟨0,hasWeight_one⟩,0,LipschitzWith.const _⟩ + +omit [ContinuousVAdd (UnitAddTorus d) X] in +lemma lipEigenfunctions_mul {F G : C(X, ℂ)} + (hF : F ∈ (lipEigenfunctions (d := d))) (hG : G ∈ (lipEigenfunctions (d := d))) : + F*G ∈ (lipEigenfunctions (d := d)) := by + obtain ⟨⟨k,hk⟩,C,hC⟩ := hF + obtain ⟨⟨l,hl⟩,D,hD⟩ := hG + exact ⟨⟨k+l,hk.mul hl⟩,_,lipschitz_mul F G hC hD⟩ + +omit [CompactSpace X] [ContinuousVAdd (UnitAddTorus d) X] in +lemma lipEigenfunctions_star {F : C(X, ℂ)} (hF : F ∈ (lipEigenfunctions (d := d))) : + star F ∈ (lipEigenfunctions (d := d)) := by + obtain ⟨⟨k,hk⟩,C,hC⟩ := hF + refine ⟨⟨-k,hk.star⟩,C,LipschitzWith.of_dist_le_mul ?_⟩ + intro x y + simpa only [ContinuousMap.star_apply,dist_star_star] using hC.dist_le_mul x y + +def lipEigenAlgebra : StarSubalgebra ℂ C(X, ℂ) where + toSubalgebra := Algebra.adjoin ℂ (lipEigenfunctions (d := d)) + star_mem' := by + change Algebra.adjoin ℂ (lipEigenfunctions (d := d)) ≤ star (Algebra.adjoin ℂ (lipEigenfunctions (d := d))) + refine Algebra.adjoin_le ?_ + intro F hF + exact Algebra.subset_adjoin (lipEigenfunctions_star hF) + +omit [ContinuousVAdd (UnitAddTorus d) X] in +lemma lipEigenAlgebra_span : (lipEigenAlgebra (d := d)).toSubalgebra.toSubmodule = + Submodule.span ℂ ((lipEigenfunctions (d := d) (X := X))) := by + apply Algebra.adjoin_eq_span_of_subset + refine Set.Subset.trans ?_ Submodule.subset_span + intro F hF + exact Submonoid.closure_induction (fun _ => id) lipEigenfunctions_one + (fun _ _ _ _ hf hg => lipEigenfunctions_mul hf hg) hF + +lemma lipEigenAlgebra_separatesPoints [IsIsometricVAdd (UnitAddTorus d) X] : + ((lipEigenAlgebra (d := d) (X := X))).SeparatesPoints := by + intro x y hxy + let F : C(X, ℂ) := ⟨fun z => (dist z x : ℂ), by fun_prop⟩ + have hLip : LipschitzWith 1 F := by + simpa only [one_mul,F,ContinuousMap.coe_mk,Function.comp_def] using! + Complex.isometry_ofReal.lipschitzWith.comp (LipschitzWith.dist_left x) + have hF : F x ≠ F y := by + intro h + have h' : dist y x = 0 := by + have hc : (0 : ℂ) = (dist y x : ℂ) := by + simpa only [F,ContinuousMap.coe_mk,dist_self,Complex.ofReal_zero] using h + exact Complex.ofReal_eq_zero.mp hc.symm + exact hxy (dist_eq_zero.mp h').symm + have hk : ∃ k : d → ℤ, coeff F k x ≠ coeff F k y := by + by_contra h + push Not at h + exact hF (coeff_eval_eq F x y h) + obtain ⟨k,hk⟩ := hk + exact ⟨_,⟨coeff F k,Algebra.subset_adjoin + ⟨⟨k,coeff_hasWeight F k⟩,1,coeff_lipschitz F hLip k⟩,rfl⟩,hk⟩ + + +theorem lipEigenfunctions_dense [IsIsometricVAdd (UnitAddTorus d) X] : + (Submodule.span ℂ ((lipEigenfunctions (d := d) (X := X)))).topologicalClosure = ⊤ := by + rw [← lipEigenAlgebra_span] + exact congrArg (Subalgebra.toSubmodule ∘ StarSubalgebra.toSubalgebra) + (ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints + (lipEigenAlgebra (d := d)) lipEigenAlgebra_separatesPoints) + + + +theorem finite_vertical_obstruction_continuous + (δ B : ℝ) (hδ : 0 < δ) (hB : 0 < B) : + ∃ S : Finset {F : C(X, ℂ) // F ∈ (eigenfunctions (d := d))}, ∃ η : ℝ, 0 < η ∧ + ∀ L : C(X, ℂ) →ₗ[ℂ] ℂ, (∀ F, ‖L F‖ ≤ B * ‖F‖) → + (∃ F : C(X, ℂ), LipschitzWith 1 F ∧ ‖F‖ ≤ 1 ∧ δ ≤ ‖L F‖) → + ∃ F ∈ S, η ≤ ‖L F.val‖ := by + obtain ⟨K,hK,hKLip⟩ := compact_superset_unit_lipschitz X + have hd : (Submodule.span ℂ (Set.range + (fun F : {F : C(X, ℂ) // F ∈ (eigenfunctions (d := d))} => F.val))).topologicalClosure = ⊤ := by + simpa only [Subtype.range_coe_subtype,Set.ofPred_mem_eq] using + (eigenfunctions_dense (X := X)) + obtain ⟨S,η,hη,hS⟩ := finite_tests_of_dense_span _ hd K hK δ B hδ hB + refine ⟨S,η,hη,?_⟩ + intro L hL ⟨F,hLip,hNorm,hLarge⟩ + exact hS L hL ⟨F,hKLip F hLip hNorm,hLarge⟩ + + + +theorem finite_vertical_obstruction [IsIsometricVAdd (UnitAddTorus d) X] + (δ B : ℝ) (hδ : 0 < δ) (hB : 0 < B) : + ∃ S : Finset {F : C(X, ℂ) // F ∈ (lipEigenfunctions (d := d))}, ∃ η : ℝ, 0 < η ∧ + ∀ L : C(X, ℂ) →ₗ[ℂ] ℂ, (∀ F, ‖L F‖ ≤ B * ‖F‖) → + (∃ F : C(X, ℂ), LipschitzWith 1 F ∧ ‖F‖ ≤ 1 ∧ δ ≤ ‖L F‖) → + ∃ F ∈ S, η ≤ ‖L F.val‖ := by + obtain ⟨K,hK,hKLip⟩ := compact_superset_unit_lipschitz X + have hd : (Submodule.span ℂ (Set.range + (fun F : {F : C(X, ℂ) // F ∈ (lipEigenfunctions (d := d))} => F.val))).topologicalClosure = ⊤ := by + simpa only [Subtype.range_coe_subtype,Set.ofPred_mem_eq] using + (lipEigenfunctions_dense (X := X)) + obtain ⟨S,η,hη,hS⟩ := finite_tests_of_dense_span _ hd K hK δ B hδ hB + refine ⟨S,η,hη,?_⟩ + intro L hL ⟨F,hLip,hNorm,hLarge⟩ + exact hS L hL ⟨F,hKLip F hLip hNorm,hLarge⟩ + +omit [CompactSpace X] in + + +lemma integral_hasWeight_eq_zero [MeasurableSpace X] [BorelSpace X] + (μ : Measure X) [VAddInvariantMeasure (UnitAddTorus d) X μ] + (F : C(X, ℂ)) {k : d → ℤ} (hk : k ≠ 0) (hF : HasWeight k F) : + (∫ x, F x ∂μ) = 0 := by + classical + obtain ⟨i,hi⟩ : ∃ i, k i ≠ 0 := by + contrapose! hk + exact funext hk + let s : UnitAddTorus d := Pi.single i (((1 / 2 / (k i : ℝ) : ℝ) : UnitAddCircle)) + have hs : mFourier k s = -1 := by + rw [mFourier] + simp only [ContinuousMap.coe_mk] + rw [Finset.prod_eq_single i] + · simp only [s,Pi.single_eq_same] + simpa only [zero_add,fourier_eval_zero] using + (fourier_add_half_inv_index (T := 1) hi (by norm_num) (0 : UnitAddCircle)) + · intro j _ hji + simp [s,Pi.single_eq_of_ne hji] + · simp + have heq := integral_vadd_eq_self (μ := μ) (fun x => F x) (g := s) + simp only [hF s,hs,neg_one_mul,integral_neg] at heq + exact CharZero.eq_neg_self_iff.mp heq.symm + + +def balanced (F : C(X, ℂ)) : C(X × X, ℂ) where + toFun p := F p.1 * star (F p.2) + continuous_toFun := by fun_prop + +omit [CompactSpace X] [ContinuousVAdd (UnitAddTorus d) X] in +lemma balanced_invariant (F : C(X, ℂ)) {k : d → ℤ} (hF : HasWeight k F) + (s : (UnitAddTorus d)) (p : X × X) : + balanced F (s +ᵥ p) = balanced F p := by + change F (s +ᵥ p.1) * star (F (s +ᵥ p.2)) = F p.1 * star (F p.2) + rw [hF s,hF s] + have he : star (mFourier k s) = mFourier (-k) s := mFourier_neg.symm + rw [star_mul,he] + calc + mFourier k s * F p.1 * (star (F p.2) * mFourier (-k) s) = + (mFourier k s * mFourier (-k) s) * (F p.1 * star (F p.2)) := by ring + _ = _ := by rw [character_cancel,one_mul] + + +abbrev PairQuotient (X : Type*) [AddAction (UnitAddTorus d) X] := + Quotient (AddAction.orbitRel (UnitAddTorus d) (X × X)) + + + +def balancedDescent (F : C(X, ℂ)) {k : d → ℤ} (hF : HasWeight k F) : + C(PairQuotient (d := d) X, ℂ) where + toFun := Quotient.lift (balanced F) (by + intro a b hab + obtain ⟨s,hs⟩ := AddAction.mem_orbit_iff.mp hab + rw [← hs] + exact balanced_invariant F hF s b) + continuous_toFun := by + apply isQuotientMap_quotient_mk'.continuous_iff.mpr + exact (balanced F).continuous + +omit [CompactSpace X] [ContinuousVAdd (UnitAddTorus d) X] in +@[simp] lemma balancedDescent_apply (F : C(X, ℂ)) {k : d → ℤ} (hF : HasWeight k F) + (p : X × X) : balancedDescent F hF ⟦p⟧ = F p.1 * star (F p.2) := rfl + +omit [CompactSpace X] [ContinuousVAdd (UnitAddTorus d) X] in + +lemma balanced_orbit_factorization {A : Type*} (f g : A → X) + (F : C(X, ℂ)) {k : d → ℤ} (hF : HasWeight k F) (n : A) : + F (f n) * star (F (g n)) = balancedDescent F hF ⟦(f n,g n)⟧ := rfl + +end +end TorusVerticalFourier + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/TriangularDenominators01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/TriangularDenominators01.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a2d35c8c91cfa2c12e95a4674bd52065ffe1401 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/TriangularDenominators01.lean @@ -0,0 +1,351 @@ +import Mathlib +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +noncomputable section +end + +end + + +section + + + + +section + + + + +section + + + + + +section + + + +namespace CocompactLattice +open scoped Pointwise +open Set Topology +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] + +lemma closure_eq_top_of_nhds [PreconnectedSpace G] {U : Set G} (hU : U ∈ nhds (1:G)) : + Subgroup.closure U = ⊤ := by + have hopen := (Subgroup.closure U).isOpen_of_mem_nhds + (Filter.mem_of_superset hU (Subgroup.subset_closure (k := U))) + have hclosed := (Subgroup.closure U).isClosed_of_isOpen hopen + have huniv := (show IsClopen (Subgroup.closure U : Set G) from ⟨hclosed,hopen⟩).eq_univ + ⟨1,(Subgroup.closure U).one_mem⟩ + exact SetLike.coe_injective huniv + + + +omit [TopologicalSpace G] [IsTopologicalGroup G] in +lemma generating_intersection (Γ : Subgroup G) (C U : Set G) + (h1C : (1:G) ∈ C) (h1U : (1:G) ∈ U) + (hsym : ∀ u ∈ U, u⁻¹ ∈ U) (hgen : Subgroup.closure U = ⊤) + (hreps : ∀ g : G, ∃ c ∈ C, c⁻¹*g ∈ Γ) : + Subgroup.closure (↑Γ ∩ (C⁻¹ * U * C)) = Γ := by + let S : Set G := ↑Γ ∩ (C⁻¹ * U * C) + let H := Subgroup.closure S + have hHΓ : H ≤ Γ := by + change Subgroup.closure S ≤ Γ + rw [Subgroup.closure_le] + exact fun _ h => h.1 + have hstep (u : G) (hu : u ∈ U) (c : G) (hc : c ∈ C) : + u*c ∈ C*(H:Set G) := by + obtain ⟨v,hv,hvΓ⟩ := hreps (u*c) + have hδ : v⁻¹*(u*c) ∈ H := by + apply Subgroup.subset_closure + refine ⟨hvΓ,?_⟩ + rw [← mul_assoc] + exact Set.mul_mem_mul (Set.mul_mem_mul (by simpa using hv) hu) hc + exact ⟨v,hv,v⁻¹*(u*c),hδ,by group⟩ + have hleft (u : G) (hu : u ∈ U) {g : G} (hg : g ∈ C*(H:Set G)) : + u*g ∈ C*(H:Set G) := by + obtain ⟨c,hc,h,hh,rfl⟩ := hg + obtain ⟨v,hv,δ,hδ,heq⟩ := hstep u hu c hc + change v*δ = u*c at heq + refine ⟨v,hv,δ*h,H.mul_mem hδ hh,?_⟩ + change v * (δ*h) = u * (c*h) + calc + v * (δ*h) = (v*δ)*h := (mul_assoc _ _ _).symm + _ = u*(c*h) := by rw [heq,mul_assoc] + have hall (g : G) : g ∈ C*(H:Set G) := by + have hg : g ∈ Subgroup.closure U := hgen.symm ▸ Subgroup.mem_top g + apply Subgroup.closure_induction_left + (p := fun g _ => g ∈ C*(H:Set G)) ?_ ?_ ?_ hg + · exact ⟨1,h1C,1,H.one_mem,by simp⟩ + · intro u hu g _ hg + exact hleft u hu hg + · intro u hu g _ hg + exact hleft u⁻¹ (hsym u hu) hg + apply le_antisymm hHΓ + intro g hg + obtain ⟨c,hc,h,hh,heq⟩ := hall g + have hcΓ : c ∈ Γ := by + have hx := Γ.mul_mem hg (Γ.inv_mem (hHΓ hh)) + rw [← heq,mul_inv_cancel_right] at hx + exact hx + have hcH : c ∈ H := by + apply Subgroup.subset_closure + refine ⟨hcΓ,?_⟩ + convert Set.mul_mem_mul (Set.mul_mem_mul (show (1:G) ∈ C⁻¹ by simpa using h1C) + h1U) hc using 1; simp + rw [← heq] + exact H.mul_mem hcH hh + + +theorem fg_of_compact_reps [PreconnectedSpace G] [LocallyCompactSpace G] [T2Space G] + (Γ : Subgroup G) [DiscreteTopology Γ] (C : Set G) (hC : IsCompact C) + (hreps : ∀ g : G, ∃ c ∈ C, c⁻¹*g ∈ Γ) : Γ.FG := by + classical + obtain ⟨V,hV,hVnh⟩ := exists_compact_mem_nhds (1:G) + let U := V ∩ V⁻¹ + have hU : IsCompact U := hV.inter hV.inv + have hUnh : U ∈ nhds (1:G) := by + apply Filter.inter_mem hVnh + have hv' : V ∈ nhds ((1:G)⁻¹) := by simpa using hVnh + exact continuous_inv.continuousAt.preimage_mem_nhds hv' + have h1U : (1:G) ∈ U := mem_of_mem_nhds hUnh + have hsym : ∀ u ∈ U, u⁻¹ ∈ U := by + intro u hu + exact ⟨hu.2,by simpa using hu.1⟩ + let K : Set G := insert 1 C + have hK : IsCompact K := hC.insert 1 + have hKrep : ∀ g : G, ∃ c ∈ K, c⁻¹*g ∈ Γ := by + intro g + obtain ⟨c,hc,hcg⟩ := hreps g + exact ⟨c,Set.mem_insert_of_mem 1 hc,hcg⟩ + have hbound : IsCompact (K⁻¹ * U * K) := (hK.inv.mul hU).mul hK + have hfinite : (↑Γ ∩ (K⁻¹*U*K)).Finite := by + have hc := hbound.inter_right (Subgroup.isClosed_of_discreteTopology (U := Γ)) + have hf := hc.finite (IsDiscrete.mono (show IsDiscrete (Γ:Set G) from ⟨inferInstance⟩) + Set.inter_subset_right) + simpa only [Set.inter_comm] using hf + apply (Subgroup.fg_iff Γ).mpr + exact ⟨_,generating_intersection Γ K U (Set.mem_insert 1 C) h1U hsym + (closure_eq_top_of_nhds hUnh) hKrep,hfinite⟩ + +end CocompactLattice + + + +namespace TriangularDenominators +open scoped BigOperators +noncomputable section + +def HasDenom (D : ℕ) (x : ℚ) : Prop := ∃ z : ℤ, (D : ℚ) * x = z + +lemma denom_zero (D : ℕ) : HasDenom D 0 := ⟨0,by simp⟩ +lemma denom_add {D : ℕ} {x y : ℚ} (hx : HasDenom D x) (hy : HasDenom D y) : + HasDenom D (x+y) := by + obtain ⟨a,ha⟩ := hx + obtain ⟨b,hb⟩ := hy + exact ⟨a+b,by rw [mul_add,ha,hb,Int.cast_add]⟩ +lemma denom_neg {D : ℕ} {x : ℚ} (hx : HasDenom D x) : HasDenom D (-x) := by + obtain ⟨a,ha⟩ := hx + exact ⟨-a,by rw [mul_neg,ha,Int.cast_neg]⟩ +lemma denom_mul {D E : ℕ} {x y : ℚ} (hx : HasDenom D x) (hy : HasDenom E y) : + HasDenom (D*E) (x*y) := by + obtain ⟨a,ha⟩ := hx + obtain ⟨b,hb⟩ := hy + refine ⟨a*b,?_⟩ + rw [Nat.cast_mul,mul_mul_mul_comm,ha,hb,Int.cast_mul] +lemma denom_mono {D E : ℕ} (h : D ∣ E) {x : ℚ} (hx : HasDenom D x) : + HasDenom E x := by + obtain ⟨k,rfl⟩ := h + obtain ⟨a,ha⟩ := hx + refine ⟨(k : ℤ)*a,?_⟩ + rw [Nat.cast_mul,mul_comm (D : ℚ),mul_assoc,ha,Int.cast_mul,Int.cast_natCast] +lemma denom_self (x : ℚ) : HasDenom x.den x := by + refine ⟨x.num,?_⟩ + calc + (x.den : ℚ) * x = (x.den : ℚ) * ((x.num : ℚ) / x.den) := + congrArg ((x.den : ℚ) * ·) (Rat.num_div_den x).symm + _ = x.num := mul_div_cancel₀ _ (by exact_mod_cast x.den_ne_zero) + +lemma finite_common_denom {ι : Type*} (s : Finset ι) (f : ι → ℚ) : + ∃ D : ℕ, 0 < D ∧ ∀ i ∈ s, HasDenom D (f i) := by + classical + refine ⟨∏ i ∈ s, (f i).den, Finset.prod_pos (fun i _ => (f i).den_pos),?_⟩ + intro i hi + apply denom_mono (Finset.dvd_prod_of_mem (fun i => (f i).den) hi) + exact denom_self _ + + + +theorem polynomial_grid {ι : Type*} (P : MvPolynomial ι ℚ) (D : ℕ) (hD : 0 < D) : + ∃ E : ℕ, 0 < E ∧ ∀ x : ι → ℚ, (∀ i, HasDenom D (x i)) → + HasDenom E (MvPolynomial.eval x P) := by + induction P using MvPolynomial.induction_on with + | C a => + exact ⟨a.den,a.den_pos,fun _ _ => by simpa using denom_self a⟩ + | add p q hp hq => + obtain ⟨E,hE,hp⟩ := hp + obtain ⟨F,hF,hq⟩ := hq + refine ⟨E*F,Nat.mul_pos hE hF,?_⟩ + intro x hx + rw [map_add] + exact denom_add (denom_mono (dvd_mul_right E F) (hp x hx)) + (denom_mono (dvd_mul_left F E) (hq x hx)) + | mul_X p i hp => + obtain ⟨E,hE,hp⟩ := hp + refine ⟨E*D,Nat.mul_pos hE hD,?_⟩ + intro x hx + simpa using denom_mul (hp x hx) (hx i) + +variable {G : Type*} [Group G] {n : ℕ} + + + +structure Coordinates (G : Type*) [Group G] (n : ℕ) where + coord : G → Fin n → ℚ + one_coord : ∀ i, coord 1 i = 0 + correction : (i : Fin n) → MvPolynomial (Fin i.val ⊕ Fin i.val) ℚ + mul_coord : ∀ g h i, coord (g*h) i = coord g i + coord h i + + MvPolynomial.eval (Sum.elim (fun j => coord g ⟨j.val,lt_trans j.isLt i.isLt⟩) + (fun j => coord h ⟨j.val,lt_trans j.isLt i.isLt⟩)) (correction i) + + + +theorem closure_grid (c : Coordinates G n) (S : Finset G) : + ∃ D : ℕ, 0 < D ∧ ∀ g ∈ Subgroup.closure (S : Set G), + ∀ i, HasDenom D (c.coord g i) := by + classical + have hpartial (j : ℕ) (hj : j ≤ n) : + ∃ D : ℕ, 0 < D ∧ ∀ g ∈ Subgroup.closure (S : Set G), + ∀ i : Fin n, i.val < j → HasDenom D (c.coord g i) := by + induction j with + | zero => exact ⟨1,by decide,fun _ _ i hi => False.elim (Nat.not_lt_zero _ hi)⟩ + | succ j ih => + obtain ⟨D,hD,hd⟩ := ih (by omega) + let i : Fin n := ⟨j,by omega⟩ + obtain ⟨E,hE,he⟩ := polynomial_grid (c.correction i) D hD + obtain ⟨F,hF,hf⟩ := finite_common_denom S (fun g => c.coord g i) + let T := D*E*F + have hDT : D ∣ T := dvd_mul_of_dvd_left (dvd_mul_right D E) F + have hET : E ∣ T := dvd_mul_of_dvd_left (dvd_mul_left E D) F + have hFT : F ∣ T := dvd_mul_left F (D*E) + have herr (g h : G) (hg : g ∈ Subgroup.closure (S : Set G)) + (hh : h ∈ Subgroup.closure (S : Set G)) : + HasDenom T (MvPolynomial.eval + (Sum.elim (fun k => c.coord g ⟨k.val,lt_trans k.isLt i.isLt⟩) + (fun k => c.coord h ⟨k.val,lt_trans k.isLt i.isLt⟩)) (c.correction i)) := by + apply denom_mono hET + apply he + intro k + rcases k with k | k + · exact hd g hg _ k.isLt + · exact hd h hh _ k.isLt + have hi (g : G) (hg : g ∈ Subgroup.closure (S : Set G)) : + HasDenom T (c.coord g i) := by + induction hg using Subgroup.closure_induction with + | mem g hg => exact denom_mono hFT (hf g hg) + | one => rw [c.one_coord]; exact denom_zero T + | mul g h hg hh ig ih => + rw [c.mul_coord] + exact denom_add (denom_add ig ih) (herr g h hg hh) + | inv g hg ig => + have hmul := c.mul_coord g g⁻¹ i + rw [mul_inv_cancel,c.one_coord] at hmul + have hx := denom_neg (denom_add ig + (herr g g⁻¹ hg ((Subgroup.closure (S : Set G)).inv_mem hg))) + convert hx using 1 + linarith + refine ⟨T,Nat.mul_pos (Nat.mul_pos hD hE) hF,?_⟩ + intro g hg k hk + by_cases heq : k.val = j + · have hk' : k = i := Fin.ext heq + subst k + exact hi g hg + · exact denom_mono hDT (hd g hg k (by omega)) + obtain ⟨D,hD,hd⟩ := hpartial n le_rfl + exact ⟨D,hD,fun g hg i => hd g hg i i.isLt⟩ + +lemma denom_small {D : ℕ} (hD : 0 < D) {x : ℚ} (hx : HasDenom D x) + (hsmall : |x| < 1 / (D : ℚ)) : x = 0 := by + obtain ⟨z,hz⟩ := hx + have hp : (0 : ℚ) < D := by exact_mod_cast hD + have hzsmall : |(z : ℚ)| < 1 := by + rw [← hz,abs_mul,abs_of_pos hp] + calc + (D : ℚ) * |x| < (D : ℚ) * (1 / (D : ℚ)) := mul_lt_mul_of_pos_left hsmall hp + _ = 1 := mul_div_cancel₀ _ hp.ne' + have hzi : |z| < 1 := by exact_mod_cast hzsmall + have heq := Int.abs_lt_one_iff.mp hzi + rw [heq,Int.cast_zero] at hz + exact (mul_eq_zero.mp hz).resolve_left hp.ne' + + + +theorem closure_discrete [TopologicalSpace G] [IsTopologicalGroup G] + (c : Coordinates G n) (hinj : Function.Injective c.coord) + (hcont : ∀ i, Continuous (fun g => c.coord g i)) (S : Finset G) : + DiscreteTopology (Subgroup.closure (S : Set G)) := by + obtain ⟨D,hD,hd⟩ := closure_grid c S + let H := Subgroup.closure (S : Set G) + have hopen : IsOpen (⋂ i : Fin n, {g : H | |c.coord g i| < 1 / (D : ℚ)}) := by + apply isOpen_iInter_of_finite + intro i + exact isOpen_lt ((hcont i).comp continuous_subtype_val).abs continuous_const + have heq : (⋂ i : Fin n, {g : H | |c.coord g i| < 1 / (D : ℚ)}) = {1} := by + ext g + simp only [Set.mem_iInter,Set.mem_ofPred_eq,Set.mem_singleton_iff] + constructor + · intro hg + apply Subtype.ext + apply hinj + funext i + change c.coord (g : G) i = c.coord 1 i + rw [c.one_coord] + exact denom_small hD (hd g g.property i) (hg i) + · rintro rfl + intro i + simp only [OneMemClass.coe_one,c.one_coord,abs_zero] + exact one_div_pos.mpr (by exact_mod_cast hD) + rw [heq] at hopen + exact discreteTopology_of_isOpen_singleton_one hopen + +variable [TopologicalSpace G] [IsTopologicalGroup G] [T2Space G] + + + +theorem finiteIndex_of_compact_reps (Γ Λ : Subgroup G) (hΓ : Γ ≤ Λ) + [DiscreteTopology Λ] (C : Set G) (hC : IsCompact C) + (hrep : ∀ g : G, ∃ c ∈ C, c⁻¹*g ∈ Γ) : + (Γ.subgroupOf Λ).FiniteIndex := by + let K : Set Λ := (Subtype.val : Λ → G) ⁻¹' C + have hK : K.Finite := + ((Subgroup.isClosed_of_discreteTopology (U := Λ)).isClosedEmbedding_subtypeVal.isCompact_preimage + hC).finite_of_discrete + let : Finite K := hK.to_subtype + apply Subgroup.finiteIndex_iff_finite_quotient.mpr + apply Finite.of_surjective (fun c : K => (QuotientGroup.mk c.val : Λ ⧸ Γ.subgroupOf Λ)) + intro q + obtain ⟨g,rfl⟩ := Quotient.exists_rep q + obtain ⟨c,hc,hcg⟩ := hrep g + have hcΛ : c ∈ Λ := by + have h := Λ.mul_mem g.property (Λ.inv_mem (hΓ hcg)) + simpa only [mul_inv_rev,inv_inv,mul_inv_cancel_left] using h + refine ⟨⟨⟨c,hcΛ⟩,hc⟩,?_⟩ + apply QuotientGroup.eq.mpr + exact hcg + +end +end TriangularDenominators + + + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/TriangularLattice01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/TriangularLattice01.lean new file mode 100644 index 0000000000000000000000000000000000000000..05b5138e3ae747c3d09c0cd7fc1b352d98caa8e3 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/TriangularLattice01.lean @@ -0,0 +1,322 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.PolynomialLine01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +namespace TriangularLatticeRecovery +open scoped BigOperators +noncomputable section + +def circleNorm (a : ℝ) : ℝ := ‖(a : UnitAddCircle)‖ + +@[simp] theorem circleNorm_zero : circleNorm 0 = 0 := by simp [circleNorm] +theorem circleNorm_nonneg (a : ℝ) : 0 ≤ circleNorm a := norm_nonneg _ +theorem circleNorm_sub_le (a b : ℝ) : circleNorm (a - b) ≤ circleNorm a + circleNorm b := by + simpa only [circleNorm, AddCircle.coe_sub] using norm_sub_le (a : UnitAddCircle) (b : UnitAddCircle) + +theorem circleNorm_int_mul (z : ℤ) (a : ℝ) : + circleNorm ((z : ℝ) * a) ≤ |(z : ℝ)| * circleNorm a := by + simpa only [circleNorm, ← zsmul_eq_mul, AddCircle.coe_zsmul, Int.norm_eq_abs] using + norm_zsmul_le z (a : UnitAddCircle) + +theorem circleNorm_nat_mul (z : ℕ) (a : ℝ) : + circleNorm ((z : ℝ) * a) ≤ (z : ℝ) * circleNorm a := by + simpa using circleNorm_int_mul (z : ℤ) a + +theorem coe_sum {ι : Type*} (s : Finset ι) (f : ι → ℝ) : + ((∑ i ∈ s, f i : ℝ) : UnitAddCircle) = ∑ i ∈ s, (f i : UnitAddCircle) := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => simp only [Finset.sum_insert ha, AddCircle.coe_add, ih] + +theorem circleNorm_sum_le {ι : Type*} (s : Finset ι) (f : ι → ℝ) : + circleNorm (∑ i ∈ s, f i) ≤ ∑ i ∈ s, circleNorm (f i) := by + simpa only [circleNorm, coe_sum] using + norm_sum_le s (fun i => (f i : UnitAddCircle)) + +theorem integer_linear_bound {ι : Type*} (s : Finset ι) (z : ι → ℤ) (a : ι → ℝ) : + circleNorm (∑ i ∈ s, (z i : ℝ) * a i) ≤ ∑ i ∈ s, |(z i : ℝ)| * circleNorm (a i) := + (circleNorm_sum_le s _).trans (Finset.sum_le_sum (fun i _ => circleNorm_int_mul (z i) (a i))) + +section Finite +variable {E V : Type*} [Fintype E] [Fintype V] [DecidableEq E] + + +def lineValue (L : V → ℕ → E → ℤ) (a : E → ℝ) (v : V) (j : ℕ) : ℝ := + ∑ e, a e * (L v j e : ℝ) + +omit [Fintype V] [DecidableEq E] in +theorem lineValue_scale (L : V → ℕ → E → ℤ) (a : E → ℝ) (v : V) (j : ℕ) (B : ℝ) : + lineValue L (fun e => B * a e) v j = B * lineValue L a v j := by + simp only [lineValue, Finset.mul_sum, mul_assoc] + +theorem reconstruct_slice (deg : E → ℕ) (M : V → E → ℤ) (w : E → V → ℤ) (B : ℕ) + (hw : ∀ e f, ∑ v, (w e v : ℝ) * (M v f : ℝ) = if e = f then (B : ℝ) else 0) + (a : E → ℝ) (j : ℕ) (e : E) (he : deg e = j) : + ∑ v, (w e v : ℝ) * (∑ f, (if deg f = j then a f else 0) * (M v f : ℝ)) = B * a e := by + classical + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + simp_rw [mul_left_comm (w e _ : ℝ) (if deg _ = j then a _ else 0), ← Finset.mul_sum, hw] + rw [Finset.sum_eq_single e] + · simp [he, mul_comm] + · intro f _ hf + simp [Ne.symm hf] + · intro he' + exact False.elim (he' (Finset.mem_univ e)) + +omit [Fintype V] [DecidableEq E] in +theorem slice_as_difference (deg : E → ℕ) (M : V → E → ℤ) (L : V → ℕ → E → ℤ) + (hL0 : ∀ v j e, deg e < j → L v j e = 0) + (hLM : ∀ v j e, deg e = j → L v j e = M v e) + (a : E → ℝ) (v : V) (j : ℕ) : + (∑ e, (if deg e = j then a e else 0) * (M v e : ℝ)) = + lineValue L a v j - ∑ e, if j < deg e then a e * (L v j e : ℝ) else 0 := by + classical + rw [lineValue, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro e _ + rcases lt_trichotomy (deg e) j with h | h | h + · simp [hL0 v j e h, ne_of_lt h, not_lt_of_ge h.le] + · simp [h, hLM v j e h] + · simp [Ne.symm (ne_of_lt h), h] + +omit [Fintype V] [DecidableEq E] in +theorem high_part_bound (deg : E → ℕ) (L : V → ℕ → E → ℤ) (X K A : ℝ) + (hX : 0 ≤ X) (hK : 0 ≤ K) (hA : 0 ≤ A) + (a : E → ℝ) (v : V) (j : ℕ) + (ha : ∀ e, j < deg e → circleNorm (a e) * X ^ deg e ≤ A) + (hL : ∀ e, j < deg e → |(L v j e : ℝ)| * X ^ j ≤ K * X ^ deg e) : + circleNorm (∑ e, if j < deg e then a e * (L v j e : ℝ) else 0) * X ^ j ≤ + (Fintype.card E : ℝ) * K * A := by + classical + calc + _ ≤ (∑ e, circleNorm (if j < deg e then a e * (L v j e : ℝ) else 0)) * X ^ j := + mul_le_mul_of_nonneg_right (circleNorm_sum_le _ _) (pow_nonneg hX _) + _ = ∑ e, circleNorm (if j < deg e then a e * (L v j e : ℝ) else 0) * X ^ j := by + rw [Finset.sum_mul] + _ ≤ ∑ _e : E, K * A := by + apply Finset.sum_le_sum + intro e _ + by_cases he : j < deg e + · rw [ite_eq_left he] + calc + _ ≤ (|(L v j e : ℝ)| * circleNorm (a e)) * X ^ j := by + apply mul_le_mul_of_nonneg_right _ (pow_nonneg hX _) + rw [mul_comm (a e)] + exact circleNorm_int_mul _ _ + _ = circleNorm (a e) * (|(L v j e : ℝ)| * X ^ j) := by ring + _ ≤ circleNorm (a e) * (K * X ^ deg e) := + mul_le_mul_of_nonneg_left (hL e he) (circleNorm_nonneg _) + _ = K * (circleNorm (a e) * X ^ deg e) := by ring + _ ≤ K * A := mul_le_mul_of_nonneg_left (ha e he) hK + · simp only [ite_eq_right he, circleNorm_zero, zero_mul] + positivity + _ = _ := by simp; ring + +omit [Fintype V] [DecidableEq E] in +theorem slice_bound (deg : E → ℕ) (M : V → E → ℤ) (L : V → ℕ → E → ℤ) + (hL0 : ∀ v j e, deg e < j → L v j e = 0) + (hLM : ∀ v j e, deg e = j → L v j e = M v e) + (X K A : ℝ) (hX : 0 ≤ X) (hK : 0 ≤ K) (hA : 0 ≤ A) + (a : E → ℝ) (j : ℕ) + (ha : ∀ e, j < deg e → circleNorm (a e) * X ^ deg e ≤ A) + (hL : ∀ v e, j < deg e → |(L v j e : ℝ)| * X ^ j ≤ K * X ^ deg e) + (hb : ∀ v, circleNorm (lineValue L a v j) * X ^ j ≤ A) (v : V) : + circleNorm (∑ e, (if deg e = j then a e else 0) * (M v e : ℝ)) * X ^ j ≤ + (1 + (Fintype.card E : ℝ) * K) * A := by + rw [slice_as_difference deg M L hL0 hLM] + calc + _ ≤ (circleNorm (lineValue L a v j) + + circleNorm (∑ e, if j < deg e then a e * (L v j e : ℝ) else 0)) * X ^ j := + mul_le_mul_of_nonneg_right (circleNorm_sub_le _ _) (pow_nonneg hX _) + _ = circleNorm (lineValue L a v j) * X ^ j + + circleNorm (∑ e, if j < deg e then a e * (L v j e : ℝ) else 0) * X ^ j := by ring + _ ≤ A + (Fintype.card E : ℝ) * K * A := + add_le_add (hb v) (high_part_bound deg L X K A hX hK hA a v j ha (hL v)) + _ = _ := by ring + +theorem recover_one (deg : E → ℕ) (M : V → E → ℤ) (L : V → ℕ → E → ℤ) + (w : E → V → ℤ) (B : ℕ) + (hw : ∀ e f, ∑ v, (w e v : ℝ) * (M v f : ℝ) = if e = f then (B : ℝ) else 0) + (hL0 : ∀ v j e, deg e < j → L v j e = 0) + (hLM : ∀ v j e, deg e = j → L v j e = M v e) + (X K W A : ℝ) (hX : 0 ≤ X) (hK : 0 ≤ K) (hA : 0 ≤ A) + (hwW : ∀ e, ∑ v, |(w e v : ℝ)| ≤ W) + (a : E → ℝ) (j : ℕ) + (ha : ∀ e, j < deg e → circleNorm (a e) * X ^ deg e ≤ A) + (hL : ∀ v e, j < deg e → |(L v j e : ℝ)| * X ^ j ≤ K * X ^ deg e) + (hb : ∀ v, circleNorm (lineValue L a v j) * X ^ j ≤ A) + (e : E) (he : deg e = j) : + circleNorm ((B : ℝ) * a e) * X ^ deg e ≤ W * (1 + (Fintype.card E : ℝ) * K) * A := by + let f (v : V) := ∑ e, (if deg e = j then a e else 0) * (M v e : ℝ) + have hf (v : V) : circleNorm (f v) * X ^ j ≤ (1 + (Fintype.card E : ℝ) * K) * A := + slice_bound deg M L hL0 hLM X K A hX hK hA a j ha hL hb v + rw [← reconstruct_slice deg M w B hw a j e he, he] + change circleNorm (∑ v, (w e v : ℝ) * f v) * X ^ j ≤ _ + calc + _ ≤ (∑ v, |(w e v : ℝ)| * circleNorm (f v)) * X ^ j := + mul_le_mul_of_nonneg_right (integer_linear_bound _ _ _) (pow_nonneg hX _) + _ = ∑ v, |(w e v : ℝ)| * (circleNorm (f v) * X ^ j) := by + rw [Finset.sum_mul]; apply Finset.sum_congr rfl; intro v _; ring + _ ≤ ∑ v, |(w e v : ℝ)| * ((1 + (Fintype.card E : ℝ) * K) * A) := + Finset.sum_le_sum (fun v _ => mul_le_mul_of_nonneg_left (hf v) (abs_nonneg _)) + _ = (∑ v, |(w e v : ℝ)|) * ((1 + (Fintype.card E : ℝ) * K) * A) := by rw [Finset.sum_mul] + _ ≤ W * ((1 + (Fintype.card E : ℝ) * K) * A) := + mul_le_mul_of_nonneg_right (hwW e) (by positivity) + _ = _ := by ring + +theorem scaled_nat_bound (B : ℕ) (a X A T : ℝ) (j : ℕ) + (hX : 0 ≤ X) (hA : 0 ≤ A) (hBT : (B : ℝ) ≤ T) + (ha : circleNorm a * X ^ j ≤ A) : circleNorm ((B : ℝ) * a) * X ^ j ≤ T * A := by + calc + _ ≤ ((B : ℝ) * circleNorm a) * X ^ j := + mul_le_mul_of_nonneg_right (circleNorm_nat_mul B a) (pow_nonneg hX _) + _ = (B : ℝ) * (circleNorm a * X ^ j) := by ring + _ ≤ (B : ℝ) * A := mul_le_mul_of_nonneg_left ha (Nat.cast_nonneg _) + _ ≤ T * A := mul_le_mul_of_nonneg_right hBT hA + + +theorem recover_aux (deg : E → ℕ) (M : V → E → ℤ) (L : V → ℕ → E → ℤ) + (w : E → V → ℤ) (B : ℕ) + (hw : ∀ e f, ∑ v, (w e v : ℝ) * (M v f : ℝ) = if e = f then (B : ℝ) else 0) + (hL0 : ∀ v j e, deg e < j → L v j e = 0) + (hLM : ∀ v j e, deg e = j → L v j e = M v e) + (X K W T : ℝ) (hX : 0 ≤ X) (hK : 0 ≤ K) + (hwW : ∀ e, ∑ v, |(w e v : ℝ)| ≤ W) + (hL : ∀ v j e, j < deg e → |(L v j e : ℝ)| * X ^ j ≤ K * X ^ deg e) + (hBT : (B : ℝ) ≤ T) (hWT : W * (1 + (Fintype.card E : ℝ) * K) ≤ T) + (k : ℕ) : ∀ (a : E → ℝ) (A : ℝ), 0 ≤ A → + (∀ v j, 0 < j → j ≤ k → circleNorm (lineValue L a v j) * X ^ j ≤ A) → + (∀ e, k < deg e → circleNorm (a e) * X ^ deg e ≤ A) → + ∀ e, 0 < deg e → circleNorm ((B : ℝ) ^ k * a e) * X ^ deg e ≤ T ^ k * A := by + have hT : 0 ≤ T := (Nat.cast_nonneg B).trans hBT + induction k with + | zero => + intro a A hA hb ha e he + simpa using ha e he + | succ k ih => + intro a A hA hb ha + let a' (e : E) : ℝ := (B : ℝ) * a e + have hA' : 0 ≤ T * A := mul_nonneg hT hA + have hb' (v : V) (j : ℕ) (hj : 0 < j) (hjk : j ≤ k) : + circleNorm (lineValue L a' v j) * X ^ j ≤ T * A := by + dsimp only [a'] + rw [lineValue_scale] + exact scaled_nat_bound B _ X A T j hX hA hBT (hb v j hj (by omega)) + have ha' (e : E) (he : k < deg e) : circleNorm (a' e) * X ^ deg e ≤ T * A := by + obtain heq | hlt := eq_or_lt_of_le (Nat.succ_le_of_lt he) + · have heq' : deg e = k + 1 := heq.symm + exact (recover_one deg M L w B hw hL0 hLM X K W A hX hK hA hwW + a (k + 1) ha (fun v e hh => hL v (k + 1) e hh) + (fun v => hb v (k + 1) (by omega) le_rfl) e heq').trans + (mul_le_mul_of_nonneg_right hWT hA) + · exact scaled_nat_bound B (a e) X A T (deg e) hX hA hBT (ha e hlt) + intro e he + have hh := ih a' (T * A) hA' hb' ha' e he + have heq : (B : ℝ) ^ (k + 1) * a e = (B : ℝ) ^ k * a' e := by + dsimp only [a']; rw [pow_succ]; ring + have hpow : T ^ (k + 1) * A = T ^ k * (T * A) := by rw [pow_succ]; ring + rw [heq, hpow] + exact hh + +theorem recover (deg : E → ℕ) (d : ℕ) (hdeg : ∀ e, deg e ≤ d) + (M : V → E → ℤ) (L : V → ℕ → E → ℤ) (w : E → V → ℤ) (B : ℕ) + (hw : ∀ e f, ∑ v, (w e v : ℝ) * (M v f : ℝ) = if e = f then (B : ℝ) else 0) + (hL0 : ∀ v j e, deg e < j → L v j e = 0) + (hLM : ∀ v j e, deg e = j → L v j e = M v e) + (X K W T : ℝ) (hX : 0 ≤ X) (hK : 0 ≤ K) + (hwW : ∀ e, ∑ v, |(w e v : ℝ)| ≤ W) + (hL : ∀ v j e, j < deg e → |(L v j e : ℝ)| * X ^ j ≤ K * X ^ deg e) + (hBT : (B : ℝ) ≤ T) (hWT : W * (1 + (Fintype.card E : ℝ) * K) ≤ T) + (a : E → ℝ) (A : ℝ) (hA : 0 ≤ A) + (hb : ∀ v j, 0 < j → j ≤ d → circleNorm (lineValue L a v j) * X ^ j ≤ A) : + ∀ e, 0 < deg e → circleNorm ((B : ℝ) ^ d * a e) * X ^ deg e ≤ T ^ d * A := by + apply recover_aux deg M L w B hw hL0 hLM X K W T hX hK hwW hL hBT hWT d a A hA hb + intro e he + exact False.elim ((not_lt_of_ge (hdeg e)) he) + +end Finite +end +end TriangularLatticeRecovery + +namespace MultivariateCoefficientRecovery +open scoped BigOperators +open PolynomialLineCoefficients TriangularLatticeRecovery +noncomputable section + +theorem recovery_constants (n d : ℕ) : + ∃ B T : ℕ, 0 < B ∧ 0 < T ∧ ∀ N : ℕ, 0 < N → + ∀ x : Grid n d → Fin n → ℕ, (∀ v i, x v i ≤ N) → + ∀ a : Grid n d → ℝ, ∀ A : ℝ, 0 ≤ A → + (∀ v : Grid n d, ∀ j : ℕ, 0 < j → j ≤ n * d → + circleNorm ((line a (x v) (fun i => (v i).val)).coeff j) * (N : ℝ) ^ j ≤ A) → + ∀ e : Grid n d, 0 < totalDegree e → + circleNorm ((B : ℝ) * a e) * (N : ℝ) ^ totalDegree e ≤ (T : ℝ) * A := by + classical + obtain ⟨B, hB, w, hw⟩ := IntegerGridInterpolation.exists_integer_weights n d + let K : ℕ := (d + 1) ^ (n * d) + let W : ℕ := ∑ e : Grid n d, ∑ v : Grid n d, (w e v).natAbs + let T : ℕ := B + W * (1 + Fintype.card (Grid n d) * K) + have hT : 0 < T := by dsimp [T]; omega + refine ⟨B ^ (n * d), T ^ (n * d), pow_pos hB _, pow_pos hT _, ?_⟩ + intro N hN x hx a A hA hb + let M (v e : Grid n d) : ℤ := ∏ i, ((v i).val : ℤ) ^ (e i).val + let L (v : Grid n d) (j : ℕ) (e : Grid n d) : ℤ := + (natLine e (x v) (fun i => (v i).val)).coeff j + have hM (v e : Grid n d) : (M v e : ℝ) = ∏ i, ((v i).val : ℝ) ^ (e i).val := by + simp only [M, Int.cast_prod, Int.cast_pow, Int.cast_natCast] + have hw' (e f : Grid n d) : ∑ v, (w e v : ℝ) * (M v f : ℝ) = + if e = f then (B : ℝ) else 0 := by simpa only [hM] using hw e f + have hL0 (v : Grid n d) (j : ℕ) (e : Grid n d) (he : totalDegree e < j) : L v j e = 0 := by + simp only [L, natLine_coeff_zero e _ _ he, Nat.cast_zero] + have hLM (v : Grid n d) (j : ℕ) (e : Grid n d) (he : totalDegree e = j) : L v j e = M v e := by + subst j + simp only [L, natLine_top_coeff, Nat.cast_prod, Nat.cast_pow, M] + have hW (e : Grid n d) : ∑ v : Grid n d, |(w e v : ℝ)| ≤ (W : ℝ) := by + have hh : ∑ v : Grid n d, (w e v).natAbs ≤ W := + Finset.single_le_sum (f := fun e : Grid n d => ∑ v : Grid n d, (w e v).natAbs) + (fun _ _ => Nat.zero_le _) (Finset.mem_univ e) + simpa only [Nat.cast_sum, Nat.cast_natAbs, Int.cast_abs] using + (Nat.cast_le.mpr hh : ((∑ v : Grid n d, (w e v).natAbs : ℕ) : ℝ) ≤ W) + have hL (v : Grid n d) (j : ℕ) (e : Grid n d) (he : j < totalDegree e) : + |(L v j e : ℝ)| * (N : ℝ) ^ j ≤ (K : ℝ) * (N : ℝ) ^ totalDegree e := by + have hh := natLine_coeff_bound hN e (x v) (fun i => (v i).val) (hx v) + (fun i => Nat.le_of_lt_succ (v i).isLt) he.le + have hn : 0 ≤ (L v j e : ℝ) := by dsimp [L]; positivity + rw [abs_of_nonneg hn] + have heq : (N : ℝ) ^ (totalDegree e - j) * N ^ j = N ^ totalDegree e := by + rw [← pow_add, Nat.sub_add_cancel he.le] + calc + _ ≤ ((d + 1 : ℝ) ^ (n * d) * N ^ (totalDegree e - j)) * N ^ j := + mul_le_mul_of_nonneg_right hh (by positivity) + _ = (K : ℝ) * N ^ totalDegree e := by + dsimp only [K] + push_cast + rw [mul_assoc, heq] + have hBT : (B : ℝ) ≤ T := by exact_mod_cast (Nat.le_add_right B _) + have hWT : (W : ℝ) * (1 + (Fintype.card (Grid n d) : ℝ) * K) ≤ T := by + exact_mod_cast (Nat.le_add_left (W * (1 + Fintype.card (Grid n d) * K)) B) + have hb' (v : Grid n d) (j : ℕ) (hj : 0 < j) (hjd : j ≤ n * d) : + circleNorm (lineValue L a v j) * (N : ℝ) ^ j ≤ A := by + have hh := hb v j hj hjd + simpa only [line_coeff, lineValue, L, Int.cast_natCast] using hh + have hh := recover totalDegree (n * d) totalDegree_le M L w B hw' hL0 hLM + (N : ℝ) K W T (Nat.cast_nonneg _) (Nat.cast_nonneg _) hW hL hBT hWT a A hA hb' + simpa only [Nat.cast_pow] using hh + +end +end MultivariateCoefficientRecovery + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/UniformSlow01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/UniformSlow01.lean new file mode 100644 index 0000000000000000000000000000000000000000..39b29831f9984b34e793c11d429cb33b8a1ca316 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/UniformSlow01.lean @@ -0,0 +1,277 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RoughKernel03 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +open scoped NNReal +namespace UniformParameterTests +variable {A Y Z : Type*} [PseudoMetricSpace A] [CompactSpace A] +variable [PseudoMetricSpace Y] [CompactSpace Y] [PseudoMetricSpace Z] + + +theorem common_modulus (H : C(A×Y,Z)) (K : ℝ≥0) (ε : ℝ) (hε : 0<ε) : + ∃ δ : ℝ,0<δ ∧ ∀ (a b : A),dist a b<δ → + ∀ (F : Z → ℂ),LipschitzWith K F → ∀ y : Y, + ‖F (H (a,y))-F (H (b,y))‖<ε := by + have hp : 0<(K:ℝ)+1:=by positivity + obtain ⟨δ,hδ,hd⟩:=Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous H.continuous) + (ε/((K:ℝ)+1)) (div_pos hε hp) + refine ⟨δ,hδ,fun a b hab F hF y=>?_⟩ + have hab' : dist (a,y) (b,y)<δ:=by simpa [Prod.dist_eq] using hab + have hh:=hd hab' + have hf:=hF.dist_le_mul (H (a,y)) (H (b,y)) + rw [dist_eq_norm] at hf + have hx : ((K:ℝ)+1)*dist (H (a,y)) (H (b,y))<ε := by + have ht:=mul_lt_mul_of_pos_left hh hp + have hc : ((K:ℝ)+1)*(ε/((K:ℝ)+1))=ε:=mul_div_cancel₀ _ hp.ne' + rwa [hc] at ht + have hn:=dist_nonneg (x:=H (a,y)) (y:=H (b,y)) + nlinarith + +end UniformParameterTests +end + +end + +section + + + + +noncomputable section +open scoped NNReal +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (Γ : Subgroup G) +variable (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable (hcont : Continuous χ) (hZ : ∀ g∈Γ,∃ z : ℤ,(χ g).toAdd=z) +variable {X : Type*} [PseudoMetricSpace X] (e : (G⧸Γ) ≃ₜ X) + +include hΓ hcont hZ in + + +theorem uniform_finite_kernel_tests {J : Type*} [Fintype J] (σ : J → G) + (T : ℝ) (K : ℝ≥0) (B : ℝ) (hB : 0≤B) (ε : ℝ) (hε : 0<ε) : + ∃ L : ℝ≥0,∀ j : J, + letI := kernelCompatibleMetric χ Γ (σ j) c hsk R hΓ hcont hZ + ∀ (a : Set.Icc (-T) T) (F : X → ℂ),LipschitzWith K F → (∀ x,‖F x‖≤B) → + ∃ g : (χ.ker⧸kernelLattice χ Γ (σ j)) → ℂ,LipschitzWith L g ∧ + (∀ y,‖g y-F (e (kernelTestMap χ Γ (σ j) + (R.flow c hsk χ Γ (Multiplicative.ofAdd a.val)) y))‖<ε) ∧ + ∀ y,‖g y‖≤B+ε := by + classical + have hall:=fun j : J=>uniform_kernel_tests χ Γ (σ j) c hsk R hΓ hcont hZ e T K B hB ε hε + choose L hL using hall + refine ⟨Finset.univ.sup L,fun j a F hF hb=>?_⟩ + let := kernelCompatibleMetric χ Γ (σ j) c hsk R hΓ hcont hZ + obtain ⟨g,hg,he,hb'⟩:=hL j a F hF hb + refine ⟨g,?_,he,hb'⟩ + apply LipschitzWith.of_dist_le_mul + intro x y + apply (hg.dist_le_mul x y).trans + apply mul_le_mul_of_nonneg_right _ dist_nonneg + exact_mod_cast (Finset.le_sup (f:=L) (Finset.mem_univ j)) + +include hΓ in + + +theorem uniform_slow_freezing (T : ℝ) (K : ℝ≥0) (ε : ℝ) (hε : 0<ε) : + ∃ δ : ℝ,0<δ ∧ ∀ (a b : Set.Icc (-T) T),|a.val-b.val|<δ → + ∀ (F : X → ℂ),LipschitzWith K F → ∀ y : G⧸Γ, + ‖F (e ((R.flow c hsk χ Γ (Multiplicative.ofAdd a.val)) • y))- + F (e ((R.flow c hsk χ Γ (Multiplicative.ofAdd b.val)) • y))‖<ε := by + let : CompactSpace (G⧸Γ):=by + obtain ⟨S,hS,hrep⟩:=compact_reps_of_integerCoordinates c Γ hΓ + exact (show CompactGroupProducts.HasCompactReps ⊤ Γ from + ⟨S,hS,Set.subset_univ _,fun g _=>hrep g⟩).quotient_compactSpace + let : CompactSpace X:=e.surjective.compactSpace e.continuous + let H : C((Set.Icc (-T) T) × X,X):= + { toFun:=fun x=>e ((R.flow c hsk χ Γ (Multiplicative.ofAdd x.1.val)) • e.symm x.2) + continuous_toFun:=by + apply e.continuous.comp + have hf : Continuous (fun x : (Set.Icc (-T) T) × X=> + R.flow c hsk χ Γ (Multiplicative.ofAdd x.1.val)):= + (sectionFlow_continuous c hsk R.k R.p).comp + (continuous_ofAdd.comp (continuous_subtype_val.comp continuous_fst)) + have hq : Continuous (fun x : (Set.Icc (-T) T) × X=>e.symm x.2):= + e.symm.continuous.comp continuous_snd + exact hf.smul hq } + obtain ⟨δ,hδ,hd⟩:=UniformParameterTests.common_modulus H K ε hε + refine ⟨δ,hδ,fun a b hab F hF y=>?_⟩ + have hh:=hd a b (by simpa [Subtype.dist_eq,Real.dist_eq] using hab) F hF (e y) + simpa only [H,ContinuousMap.coe_mk,e.symm_apply_apply] using hh + +end RoughKernelFactorization +end + +end + +section + + + + +noncomputable section +open scoped BigOperators +namespace UniformSlowPolynomials +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +def form (e : κ → ι → ℕ) (a : κ → ℝ) (x : ι → ℝ) : ℝ := + ∑ k, a k * ∏ i, x i ^ e k i + +lemma continuous_form (e : κ → ι → ℕ) : + Continuous (fun p : (κ → ℝ) × (ι → ℝ) => form e p.1 p.2) := by + unfold form + fun_prop + +lemma rescale (e : κ → ι → ℕ) (a : κ → ℝ) (x : ι → ℝ) (Z : ℝ) (hZ : Z≠0) : + form e a x = form e (fun k=>a k*Z^(∑ i,e k i)) (fun i=>x i/Z) := by + unfold form + apply Finset.sum_congr rfl + intro k _ + rw [show (∏ i,(x i/Z)^e k i)=(∏ i,x i^e k i)/Z^(∑ i,e k i) by + simp only [div_pow,Finset.prod_div_distrib,Finset.prod_pow_eq_pow_sum]] + field_simp + + + +theorem normalized_uniformity (e : κ → ι → ℕ) (A C : ℝ) + (hA : 0≤A) (hC : 0≤C) (ε : ℝ) (hε : 0<ε) : + ∃ T δ : ℝ,0form e (fun k=>(p.1 k).val) (fun i=>(p.2 i).val) + continuous_toFun:=by unfold form; fun_prop } + obtain ⟨T,hT⟩:=IsCompact.exists_bound_of_continuousOn (s:=Set.univ) isCompact_univ F.continuous.continuousOn + obtain ⟨δ,hδ,hd⟩:=Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous F.continuous) ε hε + refine ⟨max T (A+C)+1,δ,?_,hδ,?_⟩ + · have hAC := add_nonneg hA hC + linarith [le_max_right T (A+C)] + intro a ha x y hx hy + let a' : B:=fun k=>⟨a k,abs_le.mp (ha k)⟩ + let x' : X:=fun i=>⟨x i,abs_le.mp (hx i)⟩ + let y' : X:=fun i=>⟨y i,abs_le.mp (hy i)⟩ + constructor + · have hh:=hT (a',x') (Set.mem_univ _) + change ‖form e a x‖≤T at hh + rw [Real.norm_eq_abs] at hh + exact hh.trans (by linarith [le_max_left T (A+C)]) + · intro hxy + have hxy' : dist x' y'<δ := by + apply (dist_pi_lt_iff hδ).mpr + intro i + simpa only [Subtype.dist_eq,Real.dist_eq] using hxy i + have hp : dist (a',x') (a',y')<δ:=by simpa only [Prod.dist_eq,dist_self,max_eq_right dist_nonneg] using hxy' + have hh:=hd hp + simpa only [F,ContinuousMap.coe_mk,Real.dist_eq] using hh + + + +theorem scaled_uniformity (e : κ → ι → ℕ) (A C : ℝ) + (hA : 0≤A) (hC : 0≤C) (ε : ℝ) (hε : 0<ε) : + ∃ T δ : ℝ,0a k*Z^(∑ i,e k i)) ha' (fun i=>x i/Z) (fun i=>y i/Z) hx' hy' + rw [←rescale e a x Z hZ.ne'] at hb + refine ⟨hb,fun hxy=>?_⟩ + rw [rescale e a x Z hZ.ne',rescale e a y Z hZ.ne'] + apply hd + intro i + rw [←sub_div,abs_div,abs_of_pos hZ] + exact (div_lt_iff₀ hZ).mpr (hxy i) + +end UniformSlowPolynomials +end + +end + +section + + + + +noncomputable section +open scoped NNReal +namespace RoughKernelFactorization +open RationalLattice MalcevCharacters UniformSlowPolynomials +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G (n+1)) (hsk : SecondKind c) +variable (χ : G →* Multiplicative ℝ) (Γ : Subgroup G) +variable (R : Reduction c hsk χ Γ) +variable (hΓ : ∀ g : G,g∈Γ ↔ ∀ i,∃ z : ℤ,c.coord g i=z) +variable {X : Type*} [PseudoMetricSpace X] (v : (G⧸Γ) ≃ₜ X) + +include hΓ in + + +theorem polynomial_slow_freezing {ι κ : Type*} [Fintype ι] [Fintype κ] + (e : κ → ι → ℕ) (A C : ℝ) (hA : 0≤A) (hC : 0≤C) + (K : ℝ≥0) (ε : ℝ) (hε : 0<ε) : + ∃ T lam : ℝ,0?_⟩ + have hs:=(hslow Z hZ a ha x y hx hy).2 hxy + exact hfreeze ⟨form e a x,abs_le.mp hxb⟩ ⟨form e a y,abs_le.mp hyb⟩ hs F hF z + +end RoughKernelFactorization + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/UnitInterval01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/UnitInterval01.lean new file mode 100644 index 0000000000000000000000000000000000000000..d79a2c2b110a6e190498aa30b6c3f31ce15d7c7f --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/UnitInterval01.lean @@ -0,0 +1,347 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.LeibmanSquare01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section RawSuccessInlineScope3 +noncomputable section +open Filter Topology +end +end RawSuccessInlineScope3 + + + + + +section RawSuccessInlineScope4 + + +namespace IntervalResidueDiscrepancy +open Finset +open scoped BigOperators +noncomputable section + +theorem prefix_bound (b q v : ℕ) (hq : 0 < q) : + |(Nat.count (fun n => Nat.ModEq q n v) b : ℝ) - (b : ℝ)/q| ≤ 1 := by + rw [Nat.count_modEq_card b hq v] + have hqR : (0:ℝ) < q := by exact_mod_cast hq + have hmod : ((b % q : ℕ) : ℝ) < q := by exact_mod_cast Nat.mod_lt b hq + have hmod0 : (0:ℝ) ≤ ((b % q : ℕ) : ℝ) := by positivity + have hid : ((b % q : ℕ) : ℝ) + (q : ℝ) * (b / q : ℕ) = b := by + exact_mod_cast Nat.mod_add_div b q + rw [abs_le] + split_ifs <;> push_cast <;> constructor + all_goals + apply (mul_le_mul_iff_left₀ hqR).mp + field_simp + nlinarith + +theorem interval_sum (A Y q v : ℕ) (hq : 0 < q) : + |(∑ n ∈ Ico A (A+Y), if Nat.ModEq q n v then (1:ℝ) else 0) - (Y : ℝ)/q| ≤ 2 := by + have h1 := prefix_bound (A+Y) q v hq + have h0 := prefix_bound A q v hq + rw [sum_Ico_eq_sub _ (by omega)] + simp only [sum_boole, ← Nat.count_eq_card_filter_range] + have heq : (Nat.count (fun n => Nat.ModEq q n v) (A+Y):ℝ) - + Nat.count (fun n => Nat.ModEq q n v) A - (Y:ℝ)/q = + ((Nat.count (fun n => Nat.ModEq q n v) (A+Y):ℝ) - ((A+Y:ℕ):ℝ)/q) - + ((Nat.count (fun n => Nat.ModEq q n v) A:ℝ) - (A:ℝ)/q) := by push_cast; ring + rw [heq] + exact (abs_sub _ _).trans (by linarith) + +theorem interval_card (A Y q v : ℕ) (hq : 0 < q) : + |(((Ico A (A+Y)).filter (fun n => Nat.ModEq q n v)).card : ℝ) - (Y : ℝ)/q| ≤ 2 := by + simpa only [sum_boole] using interval_sum A Y q v hq + + + +theorem class_and_dvd (A Y p a d : ℕ) (hp : 0 < p) (hd : 0 < d) (hpd : p.Coprime d) : + |(∑ n ∈ (Ico A (A+Y)).filter (fun n => Nat.ModEq p n a), + if d ∣ n then (1:ℝ) else 0) - (d:ℝ)⁻¹*((Y:ℝ)/p)| ≤ 2 := by + let v := Nat.chineseRemainder hpd a 0 + have hm : ∀ n, (Nat.ModEq p n a ∧ d ∣ n) ↔ Nat.ModEq (p*d) n v := by + intro n + constructor + · intro h + exact Nat.chineseRemainder_modEq_unique hpd h.1 (Nat.modEq_zero_iff_dvd.mpr h.2) + · intro h + exact ⟨(h.of_mul_right d).trans v.property.1, + Nat.modEq_zero_iff_dvd.mp ((h.of_mul_left p).trans v.property.2)⟩ + have hsum : (∑ n ∈ (Ico A (A+Y)).filter (fun n => Nat.ModEq p n a), + if d ∣ n then (1:ℝ) else 0) = + ∑ n ∈ Ico A (A+Y), if Nat.ModEq (p*d) n v then (1:ℝ) else 0 := by + simp only [sum_filter, ← ite_and, hm] + rw [hsum] + convert interval_sum A Y (p*d) v (Nat.mul_pos hp hd) using 1 + push_cast + congr 1 + ring + +end +end IntervalResidueDiscrepancy + +end RawSuccessInlineScope4 + + + + + +section RawSuccessInlineScope5 +noncomputable section +open scoped BigOperators +open Finset +namespace UnitIntervalCounts + +def units (A L W:ℕ) : Finset ℕ := (Ico A (A+L)).filter (fun n=>W.Coprime n) +def residues (W:ℕ) : Finset ℕ := (range W).filter (fun v=>W.Coprime v) + +lemma coprime_mod (W n:ℕ) : W.Coprime (n%W) ↔ W.Coprime n := by + simp only [Nat.coprime_iff_gcd_eq_one] + rw [Nat.gcd_rec W n,Nat.gcd_comm (n%W) W] + +lemma card_fibers (A L W:ℕ) (hW:0Nat.ModEq W n v)).card:ℝ) := by + have hf:=Finset.sum_fiberwise_of_maps_to (s:=units A L W) (t:=residues W) + (g:=fun n=>n%W) (fun n hn=> show n%W∈residues W by + simp only [units,mem_filter] at hn + exact mem_filter.mpr ⟨mem_range.mpr (Nat.mod_lt n hW),(coprime_mod W n).mpr hn.2⟩) + (fun _=>(1:ℝ)) + simp only [sum_const,nsmul_eq_mul,mul_one] at hf + rw [←hf] + apply sum_congr rfl + intro v hv + congr 1 + have hv':v⟨h.1.1,h.2⟩ + · intro h + refine ⟨⟨h.1,?_⟩,h.2⟩ + apply (coprime_mod W n).mp + rw [h.2] + exact hv'.2 + + + +theorem discrepancy (A L W:ℕ) (hW:0Nat.ModEq W n v)).card:ℝ)) - + (L:ℝ)*W.totient/W = + ∑ v∈residues W, ((((Ico A (A+L)).filter (fun n=>Nat.ModEq W n v)).card:ℝ)-(L:ℝ)/W) := by + rw [sum_sub_distrib,sum_const,nsmul_eq_mul,ht] + ring + rw [he] + calc + _ ≤ ∑ v∈residues W, |((((Ico A (A+L)).filter (fun n=>Nat.ModEq W n v)).card:ℝ)-(L:ℝ)/W)| := abs_sum_le_sum_abs _ _ + _ ≤ ∑ _v∈residues W,(2:ℝ) := sum_le_sum (fun v _=>IntervalResidueDiscrepancy.interval_card A L W v hW) + _ = _ := by rw [sum_const,nsmul_eq_mul,ht]; ring + +lemma card_upper (A L W:ℕ) (hW:0 n % p = v)).card ≤ Y/p+1 := by + classical + let s := (Finset.Ico A (A+Y)).filter (fun n => n % p = v) + have hbound : ∀ n ∈ s, (n-A)/p ∈ Finset.range (Y/p+1) := by + intro n hn + obtain ⟨hn,hmod⟩ := Finset.mem_filter.mp hn + obtain ⟨hAn,hnY⟩ := Finset.mem_Ico.mp hn + simp only [Finset.mem_range] + have hs : n-A ≤ Y := by omega + have hd := Nat.div_le_div_right hs (c := p) + omega + have hinj : Set.InjOn (fun n : ℕ => (n-A)/p) s := by + intro n hn m hm he + obtain ⟨hn,hmodn⟩ := Finset.mem_filter.mp hn + obtain ⟨hm,hmodm⟩ := Finset.mem_filter.mp hm + obtain ⟨hAn,hnY⟩ := Finset.mem_Ico.mp hn + obtain ⟨hAm,hmY⟩ := Finset.mem_Ico.mp hm + have hmod : Nat.ModEq p n m := hmodn.trans hmodm.symm + have hs : (n-A)%p = (m-A)%p := hmod.sub_right hAn hAm + have hnq := Nat.mod_add_div (n-A) p + have hmq := Nat.mod_add_div (m-A) p + dsimp only at he + rw [hs,he] at hnq + omega + calc + s.card = (s.image (fun n => (n-A)/p)).card := (Finset.card_image_of_injOn hinj).symm + _ ≤ (Finset.range (Y/p+1)).card := Finset.card_le_card (by + intro q hq + obtain ⟨n,hn,rfl⟩ := Finset.mem_image.mp hq + exact hbound n hn) + _ = _ := Finset.card_range _ + + +theorem zmod_card (A Y p : ℕ) (hp : 0 < p) (v : ZMod p) : + ((Finset.Ico A (A+Y)).filter (fun n : ℕ => (n : ZMod p) = v)).card ≤ Y/p+1 := by + classical + let : NeZero p := ⟨hp.ne'⟩ + apply (Finset.card_le_card (t := + ((Finset.Ico A (A+Y)).filter (fun n => n % p = v.val))) ?_).trans + (residue_card A Y p v.val hp) + intro n hn + obtain ⟨hn,hmod⟩ := Finset.mem_filter.mp hn + refine Finset.mem_filter.mpr ⟨hn,?_⟩ + simpa only [ZMod.val_natCast] using congrArg ZMod.val hmod + + + +theorem polynomial_root_card (A Y p : ℕ) [Fact p.Prime] + (f : Polynomial (ZMod p)) (hf : f ≠ 0) : + ((Finset.Ico A (A+Y)).filter (fun n : ℕ => f.eval (n : ZMod p) = 0)).card ≤ + f.natDegree*(Y/p+1) := by + classical + let roots := f.roots.toFinset + have hcover : ((Finset.Ico A (A+Y)).filter (fun n : ℕ => f.eval (n : ZMod p) = 0)) ⊆ + roots.biUnion (fun v => (Finset.Ico A (A+Y)).filter (fun n : ℕ => (n : ZMod p) = v)) := by + intro n hn + obtain ⟨hn,hroot⟩ := Finset.mem_filter.mp hn + apply Finset.mem_biUnion.mpr + refine ⟨(n : ZMod p),?_,Finset.mem_filter.mpr ⟨hn,rfl⟩⟩ + exact Multiset.mem_toFinset.mpr ((Polynomial.mem_roots hf).mpr hroot) + calc + _ ≤ (roots.biUnion (fun v => (Finset.Ico A (A+Y)).filter + (fun n : ℕ => (n : ZMod p) = v))).card := Finset.card_le_card hcover + _ ≤ ∑ v ∈ roots, ((Finset.Ico A (A+Y)).filter + (fun n : ℕ => (n : ZMod p) = v)).card := Finset.card_biUnion_le + _ ≤ ∑ _v ∈ roots, (Y/p+1) := Finset.sum_le_sum (fun v hv => + zmod_card A Y p (Fact.out : p.Prime).pos v) + _ = roots.card*(Y/p+1) := by simp + _ ≤ f.natDegree*(Y/p+1) := Nat.mul_le_mul_right _ + ((Multiset.toFinset_card_le _).trans (Polynomial.card_roots' f)) + + + +theorem harmonic_subset (P S : Finset ℕ) (hPS : S ⊆ P) (hP : P.Nonempty) + (Y : ℕ) (hY : 0 < Y) (hbox : ∀ n ∈ P, Y ≤ n ∧ n < 2*Y) : + (∑ n ∈ S, (n:ℝ)⁻¹) / (∑ n ∈ P, (n:ℝ)⁻¹) ≤ 2*(S.card:ℝ)/P.card := by + have hn (n : ℕ) (hn : n ∈ P) : 0 < (n:ℝ) := by + exact_mod_cast (hY.trans_le (hbox n hn).1) + have hden : 0 < ∑ n ∈ P, (n:ℝ)⁻¹ := + Finset.sum_pos (fun n hn' => inv_pos.mpr (hn n hn')) hP + have hcard : 0 < (P.card:ℝ) := by exact_mod_cast hP.card_pos + have hnum : 0 ≤ ∑ n ∈ S, (n:ℝ)⁻¹ := Finset.sum_nonneg (fun n hn' => by positivity) + have hupp : (Y:ℝ)*(∑ n ∈ S, (n:ℝ)⁻¹) ≤ S.card := by + rw [Finset.mul_sum] + calc + _ ≤ ∑ _n ∈ S, (1:ℝ) := Finset.sum_le_sum (by + intro n hn' + apply (mul_inv_le_iff₀ (hn n (hPS hn'))).mpr + simpa only [one_mul] using (show (Y:ℝ) ≤ n from by + exact_mod_cast (hbox n (hPS hn')).1)) + _ = _ := by simp + have hlow : (P.card:ℝ) ≤ (2*Y)*(∑ n ∈ P, (n:ℝ)⁻¹) := by + rw [Finset.mul_sum] + calc + _ = ∑ _n ∈ P, (1:ℝ) := by simp + _ ≤ _ := Finset.sum_le_sum (by + intro n hn' + apply (le_mul_inv_iff₀ (hn n hn')).mpr + simpa only [one_mul] using (show (n:ℝ) ≤ 2*Y from by + exact_mod_cast (hbox n hn').2.le)) + rw [div_le_div_iff₀ hden hcard] + calc + _ ≤ (∑ n ∈ S, (n:ℝ)⁻¹)*((2*Y)*(∑ n ∈ P, (n:ℝ)⁻¹)) := + mul_le_mul_of_nonneg_left hlow hnum + _ = 2*((Y:ℝ)*(∑ n ∈ S, (n:ℝ)⁻¹))*(∑ n ∈ P, (n:ℝ)⁻¹) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hupp (by norm_num)) hden.le + + + +theorem harmonic_polynomial_roots (P : Finset ℕ) (hP : P.Nonempty) + (Y p : ℕ) (hY : 0 < Y) [Fact p.Prime] + (hbox : ∀ n ∈ P, Y ≤ n ∧ n < 2*Y) + (f : Polynomial (ZMod p)) (hf : f ≠ 0) : + (∑ n ∈ P.filter (fun n : ℕ => f.eval (n:ZMod p) = 0), (n:ℝ)⁻¹) / + (∑ n ∈ P, (n:ℝ)⁻¹) ≤ 2*f.natDegree*(Y/p+1:ℕ)/P.card := by + classical + let S := P.filter (fun n : ℕ => f.eval (n:ZMod p) = 0) + have hS : S.card ≤ f.natDegree*(Y/p+1) := by + apply (Finset.card_le_card (t := (Finset.Ico Y (Y+Y)).filter + (fun n : ℕ => f.eval (n:ZMod p) = 0)) ?_).trans + (polynomial_root_card Y Y p f hf) + intro n hn + obtain ⟨hn,hr⟩ := Finset.mem_filter.mp hn + refine Finset.mem_filter.mpr ⟨Finset.mem_Ico.mpr ?_,hr⟩ + obtain ⟨hl,hu⟩ := hbox n hn + exact ⟨hl,by omega⟩ + calc + _ ≤ 2*(S.card:ℝ)/P.card := harmonic_subset P S (Finset.filter_subset _ _) hP Y hY hbox + _ ≤ _ := by + apply div_le_div_of_nonneg_right _ (by positivity) + have hh : (S.card:ℝ) ≤ (f.natDegree:ℝ)*(Y/p+1:ℕ) := by exact_mod_cast hS + nlinarith + + + +theorem harmonic_integer_polynomial_divisors (P : Finset ℕ) (hP : P.Nonempty) + (Y p : ℕ) (hY : 0 < Y) [Fact p.Prime] + (hbox : ∀ n ∈ P, Y ≤ n ∧ n < 2*Y) + (f : Polynomial ℤ) (hcoeff : ¬ (p:ℤ) ∣ f.leadingCoeff) : + (∑ n ∈ P.filter (fun n : ℕ => (p:ℤ) ∣ f.eval (n:ℤ)), (n:ℝ)⁻¹) / + (∑ n ∈ P, (n:ℝ)⁻¹) ≤ 2*f.natDegree*(Y/p+1:ℕ)/P.card := by + classical + let g := f.map (Int.castRingHom (ZMod p)) + have hg : g ≠ 0 := by + intro hz + have hc := congrArg (fun t : Polynomial (ZMod p) => t.coeff f.natDegree) hz + have hc' : (f.leadingCoeff : ZMod p) = 0 := by + simpa [g, Polynomial.coeff_natDegree] using hc + exact hcoeff ((ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mp hc') + have hev (n : ℕ) : (g.eval (n:ZMod p) = 0) ↔ (p:ℤ) ∣ f.eval (n:ℤ) := by + rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] + simp [g, Polynomial.eval_map, Polynomial.eval₂_at_natCast] + have hh := harmonic_polynomial_roots P hP Y p hY hbox g hg + simp_rw [hev] at hh + apply hh.trans + apply div_le_div_of_nonneg_right _ (by positivity) + have hd : (g.natDegree:ℝ) ≤ f.natDegree := by + exact_mod_cast (show g.natDegree ≤ f.natDegree from Polynomial.natDegree_map_le) + gcongr + +end IntervalPrimeRootCount + +end RawSuccessInlineScope6 +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedBoxes01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedBoxes01.lean new file mode 100644 index 0000000000000000000000000000000000000000..5bcf81d8cde9d7185c83c8bf0a2a38e62796f1f0 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedBoxes01.lean @@ -0,0 +1,395 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.WordPlan01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +end + +section + + +noncomputable section +namespace ConstructedWordPlan.GlobalWordPlan +open AlignmentScales RationalPivotPlan +variable {n : ℕ} (D : Pivot n) {G X : Type*} [Group G] [MulAction G X] + +def jump (L : Fin D.pairs → G) (q₀ : ℕ) : ℕ → Path D → Scale n → G + | _, [], _ => 1 + | j, o::p, b => jump L q₀ (j+1) p (update b D.index (tailAt D.tail j) o.1) * + FreeGroup.lift (letter D.index D.tail D.owner D.added L q₀ b) o.2 + + + +lemma exactRun_snd (L : Fin D.pairs → G) (q₀ j : ℕ) (p : Path D) (b : Scale n) (x : X) : + (exactRun D.index D.tail D.owner D.added L q₀ j p b x).2 = jump D L q₀ j p b • x := by + induction p generalizing j b x with + | nil => simp [exactRun,jump] + | cons o p ih => simp only [exactRun,jump,ih,mul_smul] + +end ConstructedWordPlan.GlobalWordPlan +end + +end + +section + + + +open scoped BigOperators ENNReal +open MvPolynomial + +namespace WeightedBoxes + +variable {σ : Type*} + + +def StrictDegree (w : σ → ℕ) (j : ℕ) (p : MvPolynomial σ ℝ) : Prop := + ∀ m, p.coeff m ≠ 0 → Finsupp.weight w m < j + + +noncomputable def coeffNorm (p : MvPolynomial σ ℝ) : ℝ := + ∑ m ∈ p.support, |p.coeff m| + +lemma coeffNorm_nonneg (p : MvPolynomial σ ℝ) : 0 ≤ coeffNorm p := + Finset.sum_nonneg fun _ _ => abs_nonneg _ + +lemma monomial_bound (w : σ → ℕ) (m : σ →₀ ℕ) (u : σ → ℝ) (E : ℝ) + (hu : ∀ i, |u i| ≤ E ^ w i) : + |m.prod (fun i n => u i ^ n)| ≤ E ^ Finsupp.weight w m := by + classical + simp only [Finsupp.prod, Finsupp.weight_apply, Finsupp.sum, smul_eq_mul] + rw [Finset.abs_prod, ← Finset.prod_pow_eq_pow_sum] + apply Finset.prod_le_prod₀ + · intro i _; exact abs_nonneg _ + · intro i _ + rw [abs_pow, Nat.mul_comm, pow_mul] + exact pow_le_pow_left₀ (abs_nonneg _) (hu i) _ + +lemma eval_bound (w : σ → ℕ) (p : MvPolynomial σ ℝ) (j : ℕ) + (hp : StrictDegree w j p) (u : σ → ℝ) (E : ℝ) + (hE : 1 ≤ E) (hu : ∀ i, |u i| ≤ E ^ w i) : + |eval u p| ≤ coeffNorm p * E ^ (j - 1) := by + classical + rw [eval_eq] + change |∑ m ∈ p.support, p.coeff m * m.prod (fun i n => u i ^ n)| ≤ _ + apply (Finset.abs_sum_le_sum_abs _ _).trans + dsimp [coeffNorm] + rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro m hm + rw [abs_mul] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + apply (monomial_bound w m u E hu).trans + exact pow_le_pow_right₀ hE (Nat.le_sub_one_of_lt (hp m (mem_support_iff.mp hm))) + + +theorem uniform_displacement_bound [Fintype σ] (w : σ → ℕ) + (p : σ → MvPolynomial σ ℝ) (hp : ∀ i, StrictDegree w (w i) (p i)) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ (E : ℝ), 1 ≤ E → ∀ u : σ → ℝ, + (∀ i, |u i| ≤ E ^ w i) → ∀ i, |eval u (p i)| ≤ C * E ^ (w i - 1) := by + refine ⟨∑ i, coeffNorm (p i), Finset.sum_nonneg (fun _ _ => coeffNorm_nonneg _), ?_⟩ + intro E hE u hu i + apply (eval_bound w (p i) (w i) (hp i) u E hE hu).trans + apply mul_le_mul_of_nonneg_right _ (pow_nonneg (by linarith) _) + exact Finset.single_le_sum (fun j _ => coeffNorm_nonneg (p j)) (Finset.mem_univ i) + +open MeasureTheory MeasureTheory.Measure + + +def LowerDependency (w : σ → ℕ) (d : (σ → ℝ) → σ → ℝ) : Prop := + ∀ i u v, (∀ j, w j < w i → u j = v j) → d u i = d v i + + + +theorem measurePreserving_triangular [Fintype σ] (w : σ → ℕ) + (d : (σ → ℝ) → σ → ℝ) (hd : Measurable d) (hdep : LowerDependency w d) + (s : ℕ) (hw : ∀ i, w i ≤ s) : + MeasurePreserving (fun u => u + d u) volume volume := by + induction s generalizing σ with + | zero => + have he : d = fun _ => d 0 := by + funext u i + apply hdep i u 0 + intro j hj + have := hw i + omega + rw [he] + exact measurePreserving_add_right volume (d 0) + | succ s ih => + classical + let e := MeasurableEquiv.piEquivPiSubtypeProd (fun _ : σ => ℝ) (fun i => w i ≤ s) + let low := {i : σ // w i ≤ s} + let high := {i : σ // ¬w i ≤ s} + let ext (u : low → ℝ) : σ → ℝ := e.symm (u, 0) + let dl (u : low → ℝ) (i : low) : ℝ := d (ext u) i + let dh (u : low → ℝ) (i : high) : ℝ := d (ext u) i + have hmext : Measurable ext := e.symm.measurable.comp (measurable_id.prodMk measurable_const) + have hmdl : Measurable dl := Measurable.of_eval (fun i => + (measurable_pi_apply i.val).comp (hd.comp hmext)) + have hmdh : Measurable dh := Measurable.of_eval (fun i => + (measurable_pi_apply i.val).comp (hd.comp hmext)) + have hdlext (u : σ → ℝ) : d (ext (e u).1) = d u := by + funext i + apply hdep i + intro j hj + have hjl : w j ≤ s := by have := hw i; omega + simp [ext, e, MeasurableEquiv.piEquivPiSubtypeProd, Equiv.piEquivPiSubtypeProd, hjl] + have hdepl : LowerDependency (fun i : low => w i) dl := by + intro i u v huv + apply hdep i + intro j hj + have hjl : w j ≤ s := by have := i.property; omega + simpa [ext, e, MeasurableEquiv.piEquivPiSubtypeProd, Equiv.piEquivPiSubtypeProd, hjl] + using huv ⟨j, hjl⟩ hj + have hl := ih (fun i : low => w i) dl hmdl hdepl (fun i => i.property) + have hp : MeasurePreserving + (fun p : (low → ℝ) × (high → ℝ) => (p.1 + dl p.1, p.2 + dh p.1)) + (volume.prod volume) (volume.prod volume) := by + apply hl.skew_product (g := fun x y => y + dh x) + (measurable_snd.add (hmdh.comp measurable_fst)) + exact Filter.Eventually.of_forall fun u => map_add_right_eq_self volume (dh u) + have he := volume_preserving_piEquivPiSubtypeProd (fun _ : σ => ℝ) (fun i => w i ≤ s) + have ht := he.symm.comp (hp.comp he) + convert! ht using 1 + funext u + apply e.injective + simp only [Function.comp_apply] + change e (u + d u) = e (e.symm ((e u).1 + dl (e u).1, (e u).2 + dh (e u).1)) + rw [MeasurableEquiv.apply_symm_apply] + apply Prod.ext + · funext i + change u i + d u i = u i + d (ext (e u).1) i + rw [hdlext] + · funext i + change u i + d u i = u i + d (ext (e u).1) i + rw [hdlext] + +lemma polynomial_lowerDependency (w : σ → ℕ) (p : σ → MvPolynomial σ ℝ) + (hp : ∀ i, StrictDegree w (w i) (p i)) : + LowerDependency w (fun u i => eval u (p i)) := by + intro i u v huv + apply eval₂_congr + intro j m hj hm + apply huv j + have hh := Finsupp.weight_sub_single_add (w := w) (Finsupp.mem_support_iff.mp hj) + have hd := hp i m hm + omega + + + +theorem measurePreserving_polynomialShear [Fintype σ] (w : σ → ℕ) + (p : σ → MvPolynomial σ ℝ) (hp : ∀ i, StrictDegree w (w i) (p i)) : + MeasurePreserving (fun u i => u i + eval u (p i)) volume volume := by + classical + apply measurePreserving_triangular w (fun u i => eval u (p i)) + (Measurable.of_eval (fun i => (p i).continuous_eval.measurable)) + (polynomial_lowerDependency w p hp) (Finset.univ.sup w) + exact fun i => Finset.le_sup (f := w) (Finset.mem_univ i) + +section Boxes +open Set +open scoped symmDiff + +variable [Fintype σ] + + +def rect (r : σ → ℝ) : Set (σ → ℝ) := Set.Icc (-r) r + +omit [Fintype σ] in +lemma mem_rect_iff {r u : σ → ℝ} : u ∈ rect r ↔ ∀ i, |u i| ≤ r i := by + simp only [rect, Set.mem_Icc, Pi.le_def, Pi.neg_apply, abs_le] + exact ⟨fun h i => ⟨h.1 i, h.2 i⟩, fun h => ⟨fun i => (h i).1, fun i => (h i).2⟩⟩ + +lemma measurableSet_rect (r : σ → ℝ) : MeasurableSet (rect r) := measurableSet_Icc + +lemma rect_volume (r : σ → ℝ) (hr : ∀ i, 0 ≤ r i) : + volume.real (rect r) = ∏ i, (2 * r i) := by + rw [Measure.real, rect, Real.volume_Icc_pi_toReal (fun i => by have := hr i; simpa using this)] + apply Finset.prod_congr rfl + intro i _ + simp only [Pi.neg_apply] + ring + +lemma rect_finite (r : σ → ℝ) : volume (rect r) ≠ ∞ := + isCompact_Icc.measure_ne_top + +lemma rect_volume_pos (r : σ → ℝ) (hr : ∀ i, 0 < r i) : + 0 < volume.real (rect r) := by + rw [rect_volume r (fun i => (hr i).le)] + exact Finset.prod_pos fun i _ => mul_pos (by norm_num) (hr i) + +lemma rect_smul_volume (r : σ → ℝ) (hr : ∀ i, 0 ≤ r i) (a : ℝ) (ha : 0 ≤ a) : + volume.real (rect (fun i => a * r i)) = a ^ Fintype.card σ * volume.real (rect r) := by + rw [rect_volume _ (fun i => mul_nonneg ha (hr i)), rect_volume r hr] + simp_rw [mul_left_comm 2 a] + rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ] + + + +lemma symmDiff_bound {α : Type*} [MeasurableSpace α] (μ : Measure α) + {A B C : Set α} (hA : MeasurableSet A) (hB : MeasurableSet B) + (hAC : A ⊆ C) (hBC : B ⊆ C) (hC : μ C ≠ ∞) (heq : μ.real A = μ.real B) : + μ.real (A ∆ B) ≤ 2 * (μ.real C - μ.real A) := by + have hAf := measure_ne_top_of_subset hAC hC + have hBf := measure_ne_top_of_subset hBC hC + rw [measureReal_symmDiff_eq hA hB hAf hBf] + have h₁ := measureReal_sdiff_add_inter (μ := μ) (s := A) hB hAf + have h₂ := measureReal_sdiff_add_inter (μ := μ) (s := B) hA hBf + have h₃ := measureReal_union_add_inter (μ := μ) (s := A) hB hAf hBf + have h₄ := measureReal_mono (μ := μ) (Set.union_subset hAC hBC) hC + rw [Set.inter_comm B A] at h₂ + linarith + + + +lemma preimage_symmDiff_bound {α : Type*} [MeasurableSpace α] (μ : Measure α) + {T : α → α} (hT : MeasurePreserving T μ μ) {A C : Set α} + (hA : MeasurableSet A) (hC : MeasurableSet C) (hAC : A ⊆ C) + (hTC : MapsTo T A C) (hCf : μ C ≠ ∞) : + μ.real (A ∆ (T ⁻¹' A)) ≤ 2 * (μ.real C - μ.real A) := by + have hpmA := hT.measure_preimage hA.nullMeasurableSet + have hpmC := hT.measure_preimage hC.nullMeasurableSet + have hpC : μ (T ⁻¹' C) ≠ ∞ := by rwa [hpmC] + have heq : μ.real A = μ.real (T ⁻¹' A) := by simp only [Measure.real, hpmA] + have h := symmDiff_bound μ hA (hA.preimage hT.measurable) hTC + (Set.preimage_mono hAC) hpC heq + change (μ (A ∆ (T ⁻¹' A))).toReal ≤ + 2 * ((μ (T ⁻¹' C)).toReal - (μ A).toReal) at h + rw [hpmC] at h + exact h + + +def weightedBox (w : σ → ℕ) (E : ℝ) : Set (σ → ℝ) := rect (fun i => E ^ w i) + + +noncomputable def boundaryError (w : σ → ℕ) (T : (σ → ℝ) → σ → ℝ) (E : ℝ) : ℝ := + volume.real (weightedBox w E ∆ (T ⁻¹' weightedBox w E)) / + volume.real (weightedBox w E) + +lemma boundaryError_nonneg (w : σ → ℕ) (T : (σ → ℝ) → σ → ℝ) (E : ℝ) : + 0 ≤ boundaryError w T E := div_nonneg ENNReal.toReal_nonneg ENNReal.toReal_nonneg + + +theorem boundaryError_bound (w : σ → ℕ) (hw : ∀ i, 0 < w i) + (p : σ → MvPolynomial σ ℝ) (hp : ∀ i, StrictDegree w (w i) (p i)) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ E : ℝ, 1 ≤ E → + boundaryError w (fun u i => u i + eval u (p i)) E ≤ + 2 * ((1 + C / E) ^ Fintype.card σ - 1) := by + obtain ⟨C, hC, hCb⟩ := uniform_displacement_bound w p hp + refine ⟨C, hC, ?_⟩ + intro E hE + have hEpos : 0 < E := by linarith + have hf : 1 ≤ 1 + C / E := le_add_of_nonneg_right (div_nonneg hC hEpos.le) + let r : σ → ℝ := fun i => E ^ w i + have hr : ∀ i, 0 < r i := fun i => pow_pos hEpos _ + have hBC : rect r ⊆ rect (fun i => (1 + C / E) * r i) := by + intro u hu + rw [mem_rect_iff] at hu ⊢ + intro i + exact (hu i).trans (le_mul_of_one_le_left (hr i).le hf) + have hTC : MapsTo (fun u i => u i + eval u (p i)) (rect r) + (rect (fun i => (1 + C / E) * r i)) := by + intro u hu + rw [mem_rect_iff] at hu ⊢ + intro i + have hepow : E ^ (w i - 1) = E ^ w i / E := by + apply (eq_div_iff (ne_of_gt hEpos)).2 + rw [← pow_succ, Nat.sub_add_cancel (hw i)] + calc + |u i + eval u (p i)| ≤ |u i| + |eval u (p i)| := abs_add_le _ _ + _ ≤ r i + C * E ^ (w i - 1) := add_le_add (hu i) (hCb E hE u hu i) + _ = (1 + C / E) * r i := by dsimp [r]; rw [hepow]; ring + have hb := preimage_symmDiff_bound volume (measurePreserving_polynomialShear w p hp) + (measurableSet_rect r) (measurableSet_rect _) hBC hTC (rect_finite _) + rw [rect_smul_volume r (fun i => (hr i).le) _ (by positivity)] at hb + unfold boundaryError weightedBox + change volume.real (rect r ∆ ((fun u i => u i + eval u (p i)) ⁻¹' rect r)) / + volume.real (rect r) ≤ _ + rw [div_le_iff₀ (rect_volume_pos r hr)] + nlinarith [hb] + + + +theorem boundaryError_tendsto (w : σ → ℕ) (hw : ∀ i, 0 < w i) + (p : σ → MvPolynomial σ ℝ) (hp : ∀ i, StrictDegree w (w i) (p i)) : + Filter.Tendsto (boundaryError w (fun u i => u i + eval u (p i))) + Filter.atTop (nhds 0) := by + obtain ⟨C, _, hC⟩ := boundaryError_bound w hw p hp + have ht : Filter.Tendsto (fun E : ℝ => 2 * ((1 + C / E) ^ Fintype.card σ - 1)) + Filter.atTop (nhds 0) := by + have hdiv : Filter.Tendsto (fun E : ℝ => C / E) Filter.atTop (nhds 0) := + tendsto_const_nhds.div_atTop Filter.tendsto_id + convert (tendsto_const_nhds.mul (((tendsto_const_nhds.add hdiv).pow + (Fintype.card σ)).sub tendsto_const_nhds)) using 1 + simp + apply squeeze_zero' (Filter.Eventually.of_forall (boundaryError_nonneg w _)) _ ht + exact (Filter.eventually_ge_atTop (1 : ℝ)).mono hC + + +noncomputable def normalizedRestriction {α : Type*} [MeasurableSpace α] + (μ : Measure α) (B : Set α) : Measure α := (μ B)⁻¹ • μ.restrict B + +lemma normalizedRestriction_real {α : Type*} [MeasurableSpace α] + (μ : Measure α) (B : Set α) {A : Set α} (hA : MeasurableSet A) : + (normalizedRestriction μ B).real A = μ.real (A ∩ B) / μ.real B := by + rw [normalizedRestriction, measureReal_ennreal_smul_apply, + measureReal_restrict_apply hA, ENNReal.toReal_inv] + simp only [Measure.real] + ring + + +theorem normalizedRestriction_variation {α : Type*} [MeasurableSpace α] + (μ : Measure α) {T : α → α} (hT : MeasurePreserving T μ μ) + {B : Set α} (hB : MeasurableSet B) (hBf : μ B ≠ ∞) + {A : Set α} (hA : MeasurableSet A) : + |((normalizedRestriction μ B).map T).real A - (normalizedRestriction μ B).real A| ≤ + μ.real (B ∆ (T ⁻¹' B)) / μ.real B := by + rw [map_measureReal_apply hT.measurable hA, + normalizedRestriction_real μ B (hA.preimage hT.measurable), + normalizedRestriction_real μ B hA, ← sub_div, abs_div, + abs_of_nonneg (measureReal_nonneg (μ := μ) (s := B))] + apply div_le_div_of_nonneg_right _ (measureReal_nonneg (μ := μ) (s := B)) + have hpB : μ (T ⁻¹' B) ≠ ∞ := by + rw [hT.measure_preimage hB.nullMeasurableSet]; exact hBf + have hpAB := hT.measure_preimage (hA.inter hB).nullMeasurableSet + have hb : μ.real (A ∩ B) = μ.real ((T ⁻¹' A) ∩ (T ⁻¹' B)) := by + change (μ (A ∩ B)).toReal = (μ (T ⁻¹' (A ∩ B))).toReal + rw [hpAB] + rw [hb] + apply (abs_measureReal_sub_le_measureReal_symmDiff' + ((hA.preimage hT.measurable).inter hB).nullMeasurableSet + ((hA.preimage hT.measurable).inter (hB.preimage hT.measurable)).nullMeasurableSet + (measure_ne_top_of_subset Set.inter_subset_right hBf) + (measure_ne_top_of_subset Set.inter_subset_right hpB)).trans + apply measureReal_mono + · rw [← Set.inter_symmDiff_distrib_left] + exact Set.inter_subset_right + · exact measure_ne_top_of_subset Set.symmDiff_subset_union (measure_union_lt_top hBf.lt_top hpB.lt_top).ne + + + +theorem weightedBoxLaw_invariance (w : σ → ℕ) (hw : ∀ i, 0 < w i) + (p : σ → MvPolynomial σ ℝ) (hp : ∀ i, StrictDegree w (w i) (p i)) : + ∃ ε : ℝ → ℝ, Filter.Tendsto ε Filter.atTop (nhds 0) ∧ + ∀ E : ℝ, ∀ A : Set (σ → ℝ), MeasurableSet A → + |((normalizedRestriction volume (weightedBox w E)).map + (fun u i => u i + eval u (p i))).real A - + (normalizedRestriction volume (weightedBox w E)).real A| ≤ ε E := by + refine ⟨boundaryError w (fun u i => u i + eval u (p i)), + boundaryError_tendsto w hw p hp, ?_⟩ + intro E A hA + exact normalizedRestriction_variation volume (measurePreserving_polynomialShear w p hp) + (measurableSet_rect _) (rect_finite _) hA + +end Boxes + +end WeightedBoxes + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedLinear01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedLinear01.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8a480de4a4a5ccd85e1d924296ab8f52a54abcb --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedLinear01.lean @@ -0,0 +1,366 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.WeightedBoxes01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +open scoped BigOperators ENNReal +open MvPolynomial + + +end + +section + + +noncomputable section +namespace RationalLattice +open WeightedPolynomial MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (H : CubeFaces.Filtration G) (w : Fin n → ℕ) (hw : ∀ i,0 < w i) +variable (hmono : Monotone w) +variable (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) +variable (F : G →* G) (hF : Continuous F) +variable (hd : ∀ k,0 < k → ∀ g∈H.level k,g⁻¹*F g∈H.level (k+1)) + +include hsk hw hmono hH hF hd in +lemma logHomLinear_displacement_weighted (i : Fin n) : + IsWeighted w (w i-1) (fun x=>(logHomLinear c c F x-x) i) := by + let A : (Fin n → ℝ) →ₗ[ℝ] ℝ := + (LinearMap.proj i).comp ((logHomLinear c c F).toLinearMap-LinearMap.id) + change IsWeighted w (w i-1) A + apply IsWeighted.linear + intro j hj + change (logHomLinear c c F (Pi.single j (1:ℝ)) i)-(Pi.single j (1:ℝ) : Fin n → ℝ) i=0 + apply logHomLinear_lowers_of_displacement c H w hmono hH hsk F hF (w j) + (hd (w j) (hw j)) (Pi.single j 1) + · intro l hl + apply Pi.single_eq_of_ne + intro he + subst l + exact (lt_irrefl _ hl) + · omega + +include hsk hw hmono hH hF hd in +lemma logHomLinear_weighted (i : Fin n) : + IsWeighted w (w i) (fun x=>logHomLinear c c F x i) := by + have hs := ((logHomLinear_displacement_weighted c hsk H w hw hmono hH F hF hd i).mono + (Nat.sub_le _ _)).add (IsWeighted.coordinate w i) + simpa only [Pi.sub_apply,sub_add_cancel] using hs + +include hsk hw hmono hH hF hd in + + +theorem affine_log_displacement_weighted (a : G) (i : Fin n) : + IsWeighted w (w i-1) (fun y=>canonicalLog c (a*F (canonicalExp c y)) i-y i) := by + have h₁:=IsWeighted.comp (log_left_displacement_weighted c hsk H w hH hw a i) + (fun j=>logHomLinear_weighted c hsk H w hw hmono hH F hF hd j) + have h₂:=logHomLinear_displacement_weighted c hsk H w hw hmono hH F hF hd i + have he (y : Fin n → ℝ) : + canonicalExp c (logHomLinear c c F y)=F (canonicalExp c y) := by + rw [logHomLinear_apply c c hsk F hF] + exact canonicalExp_log c _ + simpa only [Function.comp_apply,he,Pi.sub_apply,sub_add_sub_cancel] using h₁.add h₂ + +end RationalLattice +end + +end + +section + + +noncomputable section +open scoped BigOperators +namespace WeightedLinear +variable {σ τ : Type*} [Fintype σ] [Fintype τ] [DecidableEq σ] [DecidableEq τ] + + +def level (w : σ → ℕ) (k : ℕ) : Submodule ℝ (σ → ℝ) where + carrier := {x | ∀ i,w i < k → x i=0} + zero_mem' := by simp + add_mem' := by intro x y hx hy i hi; simp [hx i hi,hy i hi] + smul_mem' := by intro a x hx i hi; simp [hx i hi] + +def Preserves (w : σ → ℕ) (v : τ → ℕ) (p : (σ → ℝ) →ₗ[ℝ] (τ → ℝ)) : Prop := + ∀ k ⦃x⦄,x ∈ level w k → p x ∈ level v k + +omit [Fintype σ] in +lemma single_mem (w : σ → ℕ) (i : σ) : Pi.single i (1:ℝ) ∈ level w (w i) := by + intro j hj + apply Pi.single_eq_of_ne + rintro rfl + exact (lt_irrefl _ hj) + +lemma basis_expansion (x : σ → ℝ) : x=∑ i : σ,x i • Pi.single i 1 := by + ext j + simp [Finset.sum_apply,Pi.smul_apply,Pi.single_apply] + +omit [Fintype τ] [DecidableEq τ] in +lemma apply_eq_sum (p : (σ → ℝ) →ₗ[ℝ] (τ → ℝ)) (x : σ → ℝ) (j : τ) : + p x j=∑ i : σ,p (Pi.single i 1) j*x i := by + conv_lhs => rw [basis_expansion x,map_sum] + simp only [Finset.sum_apply,map_smul,Pi.smul_apply,smul_eq_mul] + apply Finset.sum_congr rfl + intro i hi + exact mul_comm _ _ + +omit [Fintype σ] [Fintype τ] [DecidableEq τ] in +lemma Preserves.coeff {w : σ → ℕ} {v : τ → ℕ} + {p : (σ → ℝ) →ₗ[ℝ] (τ → ℝ)} (hp : Preserves w v p) + (i : σ) (j : τ) (hij : v j < w i) : p (Pi.single i 1) j=0 := + hp (w i) (single_mem w i) j hij + +omit [Fintype τ] [DecidableEq τ] in +lemma preserves_of_coeff {w : σ → ℕ} {v : τ → ℕ} + {p : (σ → ℝ) →ₗ[ℝ] (τ → ℝ)} + (hp : ∀ i j,v j < w i → p (Pi.single i 1) j=0) : Preserves w v p := by + intro k x hx j hj + rw [apply_eq_sum] + apply Finset.sum_eq_zero + intro i hi + by_cases hik : w i < k + · rw [hx i hik,mul_zero] + · rw [hp i j (by omega),zero_mul] + +omit [Fintype τ] [DecidableEq τ] in +lemma Preserves.weighted {w : σ → ℕ} {v : τ → ℕ} + {p : (σ → ℝ) →ₗ[ℝ] (τ → ℝ)} (hp : Preserves w v p) (j : τ) : + WeightedPolynomial.IsWeighted w (v j) (fun x=>p x j) := by + exact WeightedPolynomial.IsWeighted.linear w (v j) ((LinearMap.proj j).comp p) + (fun i hi=>hp.coeff i j hi) + + +omit [Fintype σ] [DecidableEq σ] in +theorem exists_rightInverse (w : σ → ℕ) (v : τ → ℕ) + (p : (σ → ℝ) →ₗ[ℝ] (τ → ℝ)) + (honto : ∀ k,Submodule.map p (level w k)=level v k) : + ∃ R : (τ → ℝ) →ₗ[ℝ] (σ → ℝ), + (∀ y,p (R y)=y) ∧ Preserves v w R := by + have hex (j : τ) : ∃ x∈level w (v j),p x=Pi.single j 1 := by + apply Submodule.mem_map.mp + rw [honto] + exact single_mem v j + choose b hb hpb using hex + let R : (τ → ℝ) →ₗ[ℝ] (σ → ℝ) := + ∑ j : τ,(LinearMap.proj j).smulRight (b j) + have hR (y : τ → ℝ) : R y=∑ j : τ,y j • b j := by + simp [R,LinearMap.sum_apply] + refine ⟨R,?_,?_⟩ + · intro y + rw [hR,map_sum] + simp only [map_smul,hpb] + exact (basis_expansion y).symm + · intro k y hy i hi + rw [hR] + simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul] + apply Finset.sum_eq_zero + intro j hj + by_cases hjk : v j < k + · rw [hy j hjk,zero_mul] + · rw [hb j i (by omega),mul_zero] + + + +theorem lifted_displacement_weighted {w : σ → ℕ} {v : τ → ℕ} + {p : (σ → ℝ) →ₗ[ℝ] (τ → ℝ)} {R : (τ → ℝ) →ₗ[ℝ] (σ → ℝ)} + (hp : Preserves w v p) (hR : Preserves v w R) + (D : (τ → ℝ) → (τ → ℝ)) + (hD : ∀ j,WeightedPolynomial.IsWeighted v (v j-1) (fun y=>D y j)) (i : σ) : + WeightedPolynomial.IsWeighted w (w i-1) (fun x=>R (D (p x)) i) := by + have hsum : WeightedPolynomial.IsWeighted w (w i-1) + (fun x=>∑ j : τ,R (Pi.single j 1) i*D (p x) j) := by + apply WeightedPolynomial.IsWeighted.sum + intro j hj + by_cases hji : v j ≤ w i + · have h:=WeightedPolynomial.IsWeighted.comp (hD j) (fun l=>hp.weighted l) + exact (h.mono (Nat.sub_le_sub_right hji 1)).smul _ + · simp only [hR.coeff j i (Nat.lt_of_not_ge hji),zero_mul] + exact WeightedPolynomial.IsWeighted.const w (w i-1) 0 + obtain ⟨P,hP,he⟩:=hsum + exact ⟨P,hP,fun x=>(apply_eq_sum R _ i).trans (he x)⟩ + +end WeightedLinear +end + +end + +section + + +noncomputable section +namespace PolynomialShearPoint +open MvPolynomial FilteredShears.PolynomialShears +variable {σ : Type*} + +def pointMap (A : MvPolynomial σ ℝ →ₐ[ℝ] MvPolynomial σ ℝ) (x : σ → ℝ) : σ → ℝ := + fun i=>eval x (A (X i)) + +lemma eval_pointMap (A : MvPolynomial σ ℝ →ₐ[ℝ] MvPolynomial σ ℝ) + (x : σ → ℝ) (p : MvPolynomial σ ℝ) : eval (pointMap A x) p=eval x (A p) := by + have he : aeval (pointMap A x)=(aeval x).comp A := by + apply algHom_ext + intro i + simp [pointMap,aeval_eq_eval] + exact DFunLike.congr_fun he p + +lemma pointMap_comp (A B : MvPolynomial σ ℝ →ₐ[ℝ] MvPolynomial σ ℝ) + (x : σ → ℝ) : pointMap A (pointMap B x)=pointMap (B.comp A) x := by + funext i + exact eval_pointMap B x (A (X i)) + +@[simp] lemma pointMap_id (x : σ → ℝ) : pointMap (AlgHom.id ℝ _) x=x := by + funext i + simp [pointMap] + +def pointEquiv (A : MvPolynomial σ ℝ ≃ₐ[ℝ] MvPolynomial σ ℝ) : (σ → ℝ) ≃ (σ → ℝ) where + toFun := pointMap A.toAlgHom + invFun := pointMap A.symm.toAlgHom + left_inv x := by rw [pointMap_comp]; simp + right_inv x := by rw [pointMap_comp]; simp + + + +theorem exists_shear (w : σ → ℕ) (hw : ∀ i,0 < w i) + (D : (σ → ℝ) → (σ → ℝ)) + (hD : ∀ i,WeightedPolynomial.IsWeighted w (w i-1) (fun x=>D x i)) : + ∃ A : shears (R:=ℝ) w, + (∀ x,pointMap A.val.toAlgHom x=x+D x) ∧ + Function.Bijective (fun x=>x+D x) := by + choose p hp he using hD + have hp' (i : σ) : p i∈degreeLT w (w i) := by + have h:= (WeightedPolynomial.bounded_iff_degreeLT (p i)).mp (hp i) + rwa [Nat.sub_add_cancel (hw i)] at h + let A:=ofDisplacements w p hp' + have hA : A∈shears (R:=ℝ) w := by + intro i + simpa [A] using hp' i + have ha (x : σ → ℝ) : pointMap A.toAlgHom x=x+D x := by + funext i + simp [pointMap,A,← he] + refine ⟨⟨A,hA⟩,ha,?_⟩ + have hf : (fun x=>x+D x)=pointEquiv A := funext (fun x=>(ha x).symm) + rw [hf] + exact (pointEquiv A).bijective + +end PolynomialShearPoint +end + +end + +section + + +noncomputable section +open MeasureTheory Filter Topology Set TopologicalSpace +namespace AsymptoticProbability +variable {X : Type*} [PseudoMetricSpace X] [MeasurableSpace X] [BorelSpace X] + +lemma levy_bound (μ ν : ProbabilityMeasure X) {ε : ℝ} (hε : 0≤ε) + (h : ∀ A,MeasurableSet A → |(μ:Measure X).real A-(ν:Measure X).real A|≤ε) : + levyProkhorovDist (μ:Measure X) (ν:Measure X) ≤ ε := by + apply levyProkhorovDist_le_of_forall_le _ _ hε + intro δ A hδ hA + have hh : (μ:Measure X).real A ≤ (ν:Measure X).real A+δ := by + have := (le_abs_self ((μ:Measure X).real A-(ν:Measure X).real A)).trans (h A hA) + linarith + have he : (μ:Measure X) A ≤ (ν:Measure X) A+ENNReal.ofReal δ := by + apply (ENNReal.toReal_le_toReal (measure_ne_top _ _) (by finiteness)).mp + rw [ENNReal.toReal_add (measure_ne_top _ _) ENNReal.ofReal_ne_top, + ENNReal.toReal_ofReal (hε.trans hδ.le)] + exact hh + exact he.trans (add_le_add (measure_mono (Metric.self_subset_thickening (hε.trans_lt hδ) A)) le_rfl) + +variable [SeparableSpace X] +lemma same_weak_limit {I : Type*} {l : Filter I} (μ ν : I → ProbabilityMeasure X) + {ε : I → ℝ} (hε : Tendsto ε l (𝓝 0)) + (h : ∀ᶠ i in l,∀ A,MeasurableSet A → + |(μ i:Measure X).real A-(ν i:Measure X).real A|≤ε i) + {μ₀ : ProbabilityMeasure X} (ht : Tendsto μ l (𝓝 μ₀)) : + Tendsto ν l (𝓝 μ₀) := by + let e:=LevyProkhorov.probabilityMeasureHomeomorph (Ω:=X) + have hb : Tendsto (fun i=>dist (e (μ i)) (e (ν i))) l (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun _=>dist_nonneg)) _ hε + filter_upwards [h] with i hi + have hp:0≤ε i := by simpa using hi ∅ MeasurableSet.empty + exact levy_bound (μ i) (ν i) hp hi + have H: Tendsto (fun i=>e (ν i)) l (𝓝 (e μ₀)) := + (e.continuous.continuousAt.tendsto.comp ht).congr_dist hb + simpa only [Function.comp_def,Homeomorph.symm_apply_apply] using e.symm.continuous.continuousAt.tendsto.comp H + +omit [PseudoMetricSpace X] [BorelSpace X] [SeparableSpace X] in +lemma pushed_event_bound {Y : Type*} [MeasurableSpace Y] + (μ : ProbabilityMeasure Y) (q : Y → X) (hq : Measurable q) + (T : Y → Y) (hT : Measurable T) (V : X → X) (hV : Measurable V) + (he : ∀ y,q (T y)=V (q y)) {ε : ℝ} + (h : ∀ B,MeasurableSet B → + |(μ.map T : Measure Y).real B-(μ:Measure Y).real B|≤ε) : + ∀ A,MeasurableSet A → + |((μ.map q).map V : Measure X).real A- + (μ.map q : Measure X).real A|≤ε := by + intro A hA + have H:=h (q ⁻¹' A) (hA.preimage hq) + change |(Measure.map V (Measure.map q (μ:Measure Y))).real A- + (Measure.map q (μ:Measure Y)).real A|≤ε + change |(Measure.map T (μ:Measure Y)).real (q ⁻¹' A)-(μ:Measure Y).real (q ⁻¹' A)|≤ε at H + rw [map_measureReal_apply hT (hA.preimage hq)] at H + rw [map_measureReal_apply hV hA,map_measureReal_apply hq (hA.preimage hV), + map_measureReal_apply hq hA] + have hh : T ⁻¹' (q ⁻¹' A)=q ⁻¹' (V ⁻¹' A) := by + ext y + exact Iff.of_eq (congrArg (·∈A) (he y)) + rwa [hh] at H + +variable {G : Type*} [Group G] [MulAction G X] [ContinuousConstSMul G X] + +lemma cluster_invariant {I : Type*} {l : Filter I} (μ : I → ProbabilityMeasure X) + (h : ∀ g : G,∃ ε : I → ℝ,Tendsto ε l (𝓝 0) ∧ + ∀ᶠ i in l,∀ A,MeasurableSet A → + |((μ i).map (g • ·) : Measure X).real A- + (μ i:Measure X).real A|≤ε i) + {ν : ProbabilityMeasure X} (hc : MapClusterPt ν l μ) : + SMulInvariantMeasure G X (ν:Measure X) := by + obtain ⟨U,hUl,hU⟩:=mapClusterPt_iff_ultrafilter.mp hc + have he (g : G) : ν.map (g • ·)=ν := by + obtain ⟨ε,hε,hεb⟩:=h g + have hεb' : ∀ᶠ i in (U:Filter I),∀ A,MeasurableSet A → + |(μ i:Measure X).real A- + ((μ i).map (g • ·) : Measure X).real A|≤ε i := by + filter_upwards [hUl hεb] with i hi A hA + rw [abs_sub_comm] + exact hi A hA + have ht:=same_weak_limit μ (fun i=>(μ i).map (g • ·)) + (hε.mono_left hUl) hεb' hU + have hmap:=ProbabilityMeasure.tendsto_map_of_tendsto_of_continuous μ ν hU + (continuous_const_smul g) + exact tendsto_nhds_unique hmap ht + refine ⟨?_⟩ + intro g A hA + have hh : Measure.map (g • ·) (ν:Measure X)=(ν:Measure X) := + congrArg (fun z : ProbabilityMeasure X=>(z:Measure X)) (he g) + rw [← Measure.map_apply (measurable_const_smul g) hA,hh] + +lemma weak_haar_of_unique [CompactSpace X] [T2Space X] + {I : Type*} {l : Filter I} (μ : I → ProbabilityMeasure X) + (ν : ProbabilityMeasure X) + (huniq : ∀ θ : ProbabilityMeasure X,SMulInvariantMeasure G X (θ:Measure X) → θ=ν) + (h : ∀ g : G,∃ ε : I → ℝ,Tendsto ε l (𝓝 0) ∧ + ∀ᶠ i in l,∀ A,MeasurableSet A → + |((μ i).map (g • ·) : Measure X).real A- + (μ i:Measure X).real A|≤ε i) : + Tendsto μ l (𝓝 ν) := by + apply tendsto_nhds_of_unique_mapClusterPt + intro θ hθ + exact huniq θ (cluster_invariant μ h hθ) + +end AsymptoticProbability + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedPolynomial01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedPolynomial01.lean new file mode 100644 index 0000000000000000000000000000000000000000..c66f059c904a2ebecbcde2f2bd035dce61073859 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedPolynomial01.lean @@ -0,0 +1,266 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice12 +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice13 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +end + +end + +section + + +noncomputable section +open scoped BigOperators +namespace WeightedPolynomial +open MvPolynomial +variable {σ : Type*} + +def Bounded (w : σ → ℕ) (d : ℕ) (p : MvPolynomial σ ℝ) : Prop := + ∀ m,p.coeff m≠0 → Finsupp.weight w m ≤ d + +def rayTable (w : σ → ℕ) : MvPolynomial σ ℝ →+* Polynomial (MvPolynomial σ ℝ) := + eval₂Hom (Polynomial.C.comp C) + (fun i=>Polynomial.C (X i)*Polynomial.X^(w i)) + +lemma rayTable_monomial (w : σ → ℕ) (m : σ →₀ ℕ) (a : ℝ) : + rayTable w (monomial m a)=Polynomial.monomial (Finsupp.weight w m) (monomial m a) := by + change eval₂ (Polynomial.C.comp C) _ _=_ + rw [eval₂_monomial] + simp only [RingHom.comp_apply,mul_pow,← pow_mul,Finsupp.prod_mul] + have hC : m.prod (fun i e=>(Polynomial.C (X i))^e)= + Polynomial.C (m.prod (fun i e=>(X i : MvPolynomial σ ℝ)^e)) := by + simp only [Finsupp.prod,map_prod,map_pow] + have hX : m.prod (fun i e=>(Polynomial.X : Polynomial (MvPolynomial σ ℝ))^(w i*e))= + Polynomial.X^(Finsupp.weight w m) := by + simp only [Finsupp.prod,Finset.prod_pow_eq_pow_sum,Finsupp.weight_apply,Finsupp.sum, + smul_eq_mul] + congr 1 + apply Finset.sum_congr rfl + intro i hi + exact Nat.mul_comm _ _ + rw [hC,hX,← mul_assoc,← map_mul,← monomial_eq,Polynomial.C_mul_X_pow_eq_monomial] + +lemma coeff_rayTable (w : σ → ℕ) (p : MvPolynomial σ ℝ) (k : ℕ) (m : σ →₀ ℕ) : + ((rayTable w p).coeff k).coeff m=if Finsupp.weight w m=k then p.coeff m else 0 := by + classical + induction p using MvPolynomial.induction_on' with + | monomial l a => + rw [rayTable_monomial] + simp only [Polynomial.coeff_monomial,apply_ite,MvPolynomial.coeff_monomial, + AddMonoidAlgebra.coeff_zero] + by_cases hl : l=m + · subst l; split_ifs <;> simp_all + · split_ifs <;> simp [hl] + | add p q hp hq => + simp only [map_add,Polynomial.coeff_add,AddMonoidAlgebra.coeff_add,Finsupp.add_apply,hp,hq] + split_ifs <;> simp + +def ray (w : σ → ℕ) (x : σ → ℝ) (p : MvPolynomial σ ℝ) : Polynomial ℝ := + (rayTable w p).map (eval x) + +def scale (w : σ → ℕ) (t : ℝ) (x : σ → ℝ) (i : σ) : ℝ := t^(w i)*x i + +lemma ray_C (w : σ → ℕ) (x : σ → ℝ) (a : ℝ) : + ray w x (C a)=Polynomial.C a := by simp [ray,rayTable] +lemma ray_X (w : σ → ℕ) (x : σ → ℝ) (i : σ) : + ray w x (X i)=Polynomial.C (x i)*Polynomial.X^(w i) := by simp [ray,rayTable] +lemma ray_mul (w : σ → ℕ) (x : σ → ℝ) (p q : MvPolynomial σ ℝ) : + ray w x (p*q)=ray w x p*ray w x q := by simp only [ray,map_mul,Polynomial.map_mul] +lemma ray_add (w : σ → ℕ) (x : σ → ℝ) (p q : MvPolynomial σ ℝ) : + ray w x (p+q)=ray w x p+ray w x q := by simp only [ray,map_add,Polynomial.map_add] + +lemma ray_eval (w : σ → ℕ) (x : σ → ℝ) (p : MvPolynomial σ ℝ) (t : ℝ) : + (ray w x p).eval t=eval (scale w t x) p := by + induction p using MvPolynomial.induction_on with + | C a => simp only [ray_C,Polynomial.eval_C,eval_C] + | add p q hp hq => simp only [ray_add,Polynomial.eval_add,map_add,hp,hq] + | mul_X p i hp => + rw [ray_mul,ray_X,Polynomial.eval_mul,Polynomial.eval_mul,Polynomial.eval_C, + Polynomial.eval_pow,Polynomial.eval_X,hp,map_mul,eval_X] + simp only [scale] + ring + +lemma bounded_iff_ray (w : σ → ℕ) (d : ℕ) (p : MvPolynomial σ ℝ) : + Bounded w d p ↔ ∀ x,(ray w x p).natDegree ≤ d := by + constructor + · intro hp x + apply Polynomial.natDegree_le_iff_coeff_eq_zero.mpr + intro k hk + simp only [ray,Polynomial.coeff_map] + have he : (rayTable w p).coeff k=0 := by + ext m + rw [coeff_rayTable] + by_cases hm : Finsupp.weight w m=k + · rw [ite_eq_left hm] + by_contra hc + have hh:=hp m hc + omega + · rw [ite_eq_right hm] + rfl + rw [he,map_zero] + · intro hp m hm + by_contra hd + have he : (rayTable w p).coeff (Finsupp.weight w m)=0 := by + apply MvPolynomial.funext + intro x + have h:=Polynomial.coeff_eq_zero_of_natDegree_lt + (lt_of_le_of_lt (hp x) (Nat.lt_of_not_ge hd)) + simpa only [ray,Polynomial.coeff_map,map_zero] using h + have hh:=congrArg (fun poly : MvPolynomial σ ℝ=>poly.coeff m) he + simp only [coeff_rayTable,AddMonoidAlgebra.coeff_zero,Finsupp.zero_apply] at hh + exact hm hh + +end WeightedPolynomial +end + +end + +section + + +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +open scoped BigOperators +namespace RationalLattice +open CubeFaces CubePolynomials MalcevCharacters WeightedPolynomial +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (H : Filtration G) (w : Fin n → ℕ) +variable (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + +include hsk hH in +omit [IsTopologicalGroup G] in +lemma scale_path_mem (x : Fin n → ℝ) : + (fun t : ℝ=>c.coord.symm (scale w t x))∈polynomials H 0 := by + let V : List (ℝ → G):=List.ofFn (fun i : Fin n=>fun t : ℝ=>axis c i ((monomial (w i) (x i)).eval t)) + have hV : V.prod∈polynomials H 0 := by + apply (polynomials H 0).list_prod_mem + intro f hf + obtain ⟨i,rfl⟩:=List.mem_ofFn.mp hf + exact axis_polynomial_mem c hsk H w hH i _ (natDegree_monomial_le _) + have he : V.prod=(fun t : ℝ=>c.coord.symm (scale w t x)) := by + funext t + let ev : (ℝ → G) →* G := Pi.evalMonoidHom (fun _ : ℝ=>G) t + have hh:=ev.map_list_prod V + change V.prod t=(V.map (fun f=>f t)).prod at hh + rw [hh] + dsimp only [V] + rw [List.map_ofFn] + symm + convert hsk.ordered (c.coord.symm (scale w t x)) using 1 + congr 2 + funext i + simp [scale,mul_comm] + rwa [he] at hV + +include hsk hH in +omit [IsTopologicalGroup G] in +lemma coordinate_weighted {σ : Type*} (ws : σ → ℕ) (f : (σ → ℝ) → G) + (hpoly : IsRealPolynomialMap c f) + (hf : ∀ x,(fun t : ℝ=>f (scale ws t x))∈polynomials H 0) (i : Fin n) : + ∃ p : MvPolynomial σ ℝ,Bounded ws (w i) p ∧ ∀ x,c.coord (f x) i=MvPolynomial.eval x p := by + choose p hp using hpoly + refine ⟨p i,?_,hp i⟩ + apply (bounded_iff_ray ws (w i) (p i)).mpr + intro x + exact coordinate_natDegree c hsk H w hH (fun t=>f (scale ws t x)) (hf x) + (fun j=>ray ws x (p j)) (fun t j=>by rw [ray_eval,← hp]) i + +include hsk hH in + + +theorem multiplication_weighted (i : Fin n) : + ∃ p : MvPolynomial (Fin n ⊕ Fin n) ℝ, + Bounded (Sum.elim w w) (w i) p ∧ + ∀ x,c.coord (c.coord.symm (fun j=>x (Sum.inl j))*c.coord.symm (fun j=>x (Sum.inr j))) i= + MvPolynomial.eval x p := by + apply coordinate_weighted c hsk H w hH (Sum.elim w w) + · apply realPolynomialMap_mul + · intro j + simpa only [Homeomorph.apply_symm_apply] using RealPolynomialMap.coordinate (Sum.inl j) + · intro j + simpa only [Homeomorph.apply_symm_apply] using RealPolynomialMap.coordinate (Sum.inr j) + · intro x + exact (polynomials H 0).mul_mem + (scale_path_mem c hsk H w hH (fun j=>x (Sum.inl j))) + (scale_path_mem c hsk H w hH (fun j=>x (Sum.inr j))) + +end RationalLattice +end + +end + +section + + +noncomputable section +open _root_.Polynomial _root_.OAI.Polynomial +namespace WeightedPolynomial +variable {σ : Type*} + +def coeffPolynomial (p : Polynomial (MvPolynomial σ ℝ)) (m : σ →₀ ℕ) : Polynomial ℝ := + p.sum (fun k a=>monomial k (a.coeff m)) + +lemma coeffPolynomial_add (p q : Polynomial (MvPolynomial σ ℝ)) (m : σ →₀ ℕ) : + coeffPolynomial (p+q) m=coeffPolynomial p m+coeffPolynomial q m := by + apply Polynomial.sum_add_index + · intro i; simp + · intro i a b; simp + +lemma coeffPolynomial_monomial (k : ℕ) (a : MvPolynomial σ ℝ) (m : σ →₀ ℕ) : + coeffPolynomial (monomial k a) m=monomial k (a.coeff m) := by + simp [coeffPolynomial,Polynomial.sum_monomial_index] + +lemma coeff_coeffPolynomial (p : Polynomial (MvPolynomial σ ℝ)) (m : σ →₀ ℕ) (k : ℕ) : + (coeffPolynomial p m).coeff k=(p.coeff k).coeff m := by + induction p using Polynomial.induction_on' with + | monomial l a => + rw [coeffPolynomial_monomial] + simp only [coeff_monomial] + split_ifs <;> simp + | add p q hp hq => + simp only [coeffPolynomial_add,coeff_add,AddMonoidAlgebra.coeff_add,Finsupp.add_apply,hp,hq] + +lemma eval_coeffPolynomial (p : Polynomial (MvPolynomial σ ℝ)) (m : σ →₀ ℕ) (t : ℝ) : + (coeffPolynomial p m).eval t=(p.eval (MvPolynomial.C t)).coeff m := by + induction p using Polynomial.induction_on' with + | monomial k a => + rw [coeffPolynomial_monomial] + simp only [eval_monomial,← map_pow,mul_comm a,MvPolynomial.coeff_C_mul,mul_comm (a.coeff m)] + | add p q hp hq => + simp only [coeffPolynomial_add,eval_add,AddMonoidAlgebra.coeff_add,Finsupp.add_apply,hp,hq] + + + +lemma bounded_coeff_of_nat_evals (w : σ → ℕ) (d : ℕ) + (p : Polynomial (MvPolynomial σ ℝ)) + (hp : ∀ a : ℕ,Bounded w d (p.eval (MvPolynomial.C (a:ℝ)))) (k : ℕ) : + Bounded w d (p.coeff k) := by + intro m hm + by_contra hd + have he : coeffPolynomial p m=0 := by + apply Polynomial.eq_of_eval_nat_eq + intro a + rw [eval_zero,eval_coeffPolynomial] + by_contra ha + exact hd (hp a m ha) + have hh:=congrArg (fun q : Polynomial ℝ=>q.coeff k) he + rw [coeff_coeffPolynomial,coeff_zero] at hh + exact hm hh + +end WeightedPolynomial +end + +end + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedPolynomial02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedPolynomial02.lean new file mode 100644 index 0000000000000000000000000000000000000000..93683574804f974737357492a402b0389bc09ae9 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WeightedPolynomial02.lean @@ -0,0 +1,271 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.FilteredShears01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +open scoped commutatorElement + + +end + +section + + +noncomputable section +open scoped BigOperators +namespace WeightedPolynomial +open MvPolynomial +open FilteredShears.PolynomialShears +variable {σ τ : Type*} {w : σ → ℕ} {d e : ℕ} + +lemma bounded_iff_degreeLT (p : MvPolynomial σ ℝ) : + Bounded w d p ↔ p∈degreeLT w (d+1) := by + constructor <;> intro h m hm + · exact Nat.lt_succ_iff.mpr (h m hm) + · exact Nat.lt_succ_iff.mp (h m hm) +lemma Bounded.mono {p : MvPolynomial σ ℝ} (hp : Bounded w d p) (h : d ≤ e) : + Bounded w e p := fun m hm=>le_trans (hp m hm) h +lemma bounded_zero : Bounded w d (0 : MvPolynomial σ ℝ) := by intro m hm; simp at hm +lemma bounded_C (a : ℝ) : Bounded w d (C a) := + ((bounded_iff_degreeLT _).mpr (C_mem w a)).mono (Nat.zero_le _) +lemma bounded_X (i : σ) : Bounded w (w i) (X (R:=ℝ) i) := + (bounded_iff_degreeLT _).mpr (X_mem w i) +lemma Bounded.add {p q : MvPolynomial σ ℝ} (hp : Bounded w d p) (hq : Bounded w d q) : + Bounded w d (p+q) := + (bounded_iff_degreeLT _).mpr ((degreeLT w (d+1)).add_mem + ((bounded_iff_degreeLT _).mp hp) ((bounded_iff_degreeLT _).mp hq)) +lemma Bounded.neg {p : MvPolynomial σ ℝ} (hp : Bounded w d p) : Bounded w d (-p) := + (bounded_iff_degreeLT _).mpr ((degreeLT w (d+1)).neg_mem ((bounded_iff_degreeLT _).mp hp)) +lemma Bounded.sub {p q : MvPolynomial σ ℝ} (hp : Bounded w d p) (hq : Bounded w d q) : + Bounded w d (p-q) := by simpa only [sub_eq_add_neg] using hp.add hq.neg +lemma Bounded.mul {p q : MvPolynomial σ ℝ} (hp : Bounded w d p) (hq : Bounded w e q) : + Bounded w (d+e) (p*q) := by + apply (bounded_iff_degreeLT _).mpr + simpa only [Nat.add_right_comm] using (mul_mem (w:=w) (a:=d+1) (b:=e) + ((bounded_iff_degreeLT p).mp hp) ((bounded_iff_degreeLT q).mp hq)) +lemma Bounded.pow {p : MvPolynomial σ ℝ} (hp : Bounded w d p) (k : ℕ) : + Bounded w (d*k) (p^k) := by + induction k with + | zero => simpa using bounded_C (w:=w) (d:=0) 1 + | succ k ih => simpa [pow_succ,Nat.mul_succ] using ih.mul hp +lemma bounded_sum {ι : Type*} (s : Finset ι) (p : ι → MvPolynomial σ ℝ) + (hp : ∀ i∈s,Bounded w d (p i)) : Bounded w d (∑ i∈s,p i) := by + classical + induction s using Finset.induction_on with + | empty => simpa using (bounded_zero (w:=w) (d:=d)) + | @insert i s hi ih => + rw [Finset.sum_insert hi] + exact (hp i (Finset.mem_insert_self _ _)).add (ih (fun j hj=>hp j (Finset.mem_insert_of_mem hj))) +lemma bounded_prod {ι : Type*} (s : Finset ι) (p : ι → MvPolynomial σ ℝ) (a : ι → ℕ) + (hp : ∀ i∈s,Bounded w (a i) (p i)) : Bounded w (∑ i∈s,a i) (∏ i∈s,p i) := by + classical + induction s using Finset.induction_on with + | empty => simpa using bounded_C (w:=w) (d:=0) 1 + | @insert i s hi ih => + rw [Finset.sum_insert hi,Finset.prod_insert hi] + exact (hp i (Finset.mem_insert_self _ _)).mul (ih (fun j hj=>hp j (Finset.mem_insert_of_mem hj))) + + + +lemma Bounded.substitute {v : τ → ℕ} {p : MvPolynomial τ ℝ} + (hp : Bounded v d p) (q : τ → MvPolynomial σ ℝ) + (hq : ∀ i,Bounded w (v i) (q i)) : + Bounded w d (eval₂Hom C q p) := by + classical + conv => arg 3; rw [p.as_sum] + rw [map_sum] + apply bounded_sum + intro m hm + change Bounded w d (eval₂ C q (monomial m (p.coeff m))) + rw [eval₂_monomial] + have hprod:=bounded_prod m.support (fun i=>(q i)^(m i)) (fun i=>v i*m i) + (fun i _=>(hq i).pow (m i)) + have he : (∑ i∈m.support,v i*m i)=Finsupp.weight v m := by + simp only [Finsupp.weight_apply,Finsupp.sum,smul_eq_mul,Nat.mul_comm] + rw [he] at hprod + exact ((bounded_C (w:=w) (d:=0) (p.coeff m)).mul hprod).mono + (by simpa using hp m (mem_support_iff.mp hm)) + +end WeightedPolynomial +end + +end + +section + + +noncomputable section +namespace WeightedPolynomial +open MvPolynomial +variable {σ τ : Type*} +def IsWeighted (w : σ → ℕ) (d : ℕ) (f : (σ → ℝ) → ℝ) : Prop := + ∃ p : MvPolynomial σ ℝ,Bounded w d p ∧ ∀ x,f x=eval x p +lemma IsWeighted.const (w : σ → ℕ) (d : ℕ) (a : ℝ) : IsWeighted w d (fun _=>a) := + ⟨C a,bounded_C a,by simp⟩ +lemma IsWeighted.coordinate (w : σ → ℕ) (i : σ) : IsWeighted w (w i) (fun x=>x i) := + ⟨X i,bounded_X i,by simp⟩ +lemma IsWeighted.mono {w : σ → ℕ} {d e : ℕ} {f : (σ → ℝ) → ℝ} + (hf : IsWeighted w d f) (h : d ≤ e) : IsWeighted w e f := by + obtain ⟨p,hp,hf⟩:=hf + exact ⟨p,hp.mono h,hf⟩ +lemma IsWeighted.add {w : σ → ℕ} {d : ℕ} {f g : (σ → ℝ) → ℝ} + (hf : IsWeighted w d f) (hg : IsWeighted w d g) : IsWeighted w d (fun x=>f x+g x) := by + obtain ⟨p,hp,hf⟩:=hf + obtain ⟨q,hq,hg⟩:=hg + exact ⟨p+q,hp.add hq,by simp [hf,hg]⟩ +lemma IsWeighted.sub {w : σ → ℕ} {d : ℕ} {f g : (σ → ℝ) → ℝ} + (hf : IsWeighted w d f) (hg : IsWeighted w d g) : IsWeighted w d (fun x=>f x-g x) := by + obtain ⟨p,hp,hf⟩:=hf + obtain ⟨q,hq,hg⟩:=hg + exact ⟨p-q,hp.sub hq,by simp [hf,hg]⟩ +lemma IsWeighted.comp {w : σ → ℕ} {v : τ → ℕ} {d : ℕ} {f : (τ → ℝ) → ℝ} + (hf : IsWeighted v d f) {g : (σ → ℝ) → (τ → ℝ)} + (hg : ∀ i,IsWeighted w (v i) (fun x=>g x i)) : + IsWeighted w d (fun x=>f (g x)) := by + obtain ⟨p,hp,hf⟩:=hf + choose q hq he using hg + refine ⟨eval₂Hom C q p,hp.substitute q hq,?_⟩ + intro x + change f (g x)=eval x (eval₂ C q p) + rw [hf,← eval_assoc] + exact congrArg (fun a=>eval a p) (funext (fun i=>he i x)) +end WeightedPolynomial + +namespace RationalLattice +open WeightedPolynomial MalcevCharacters +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) (hsk : SecondKind c) +variable (H : CubeFaces.Filtration G) (w : Fin n → ℕ) +variable (hH : ∀ k (g : G),g∈H.level k ↔ ∀ i : Fin n,w i < k → c.coord g i=0) + +include hsk hH in +omit [IsTopologicalGroup G] in +lemma logCorrection_weighted (i : Fin n) : + IsWeighted (fun j : Fin i.val=>w ⟨j.val,lt_trans j.isLt i.isLt⟩) (w i) + (fun x=>MvPolynomial.eval₂ (algebraMap ℚ ℝ) x (logCorrection c i)) := by + have hg (j : Fin n) : IsWeighted (fun j : Fin i.val=>w ⟨j.val,lt_trans j.isLt i.isLt⟩) (w j) + (fun x=>prefixSection i x j) := by + unfold prefixSection + by_cases hj : j < i + · simp only [dite_eq_left hj] + exact IsWeighted.coordinate (fun k : Fin i.val=>w ⟨k.val,lt_trans k.isLt i.isLt⟩) ⟨j.val,hj⟩ + · simp only [dite_eq_right hj] + exact IsWeighted.const _ _ 0 + have hh:=IsWeighted.comp (canonicalLog_weighted c hsk H w hH i) hg + simpa only [logCorrection_eval] using hh + +include hsk hH in + + +omit [IsTopologicalGroup G] in +theorem canonicalExp_weighted (i : Fin n) : + IsWeighted w (w i) (fun x=>c.coord (canonicalExp c x) i) := by + have aux : ∀ k,∀ hk : kc.coord (canonicalExp c x) ⟨k,hk⟩) := by + intro k + induction k using Nat.strong_induction_on with + | h k ih => + intro hk + let i : Fin n:=⟨k,hk⟩ + have hp:=IsWeighted.sub (IsWeighted.coordinate w i) + ((logCorrection_weighted c hsk H w hH i).comp + (fun j : Fin k=>ih j.val j.isLt (lt_trans j.isLt hk))) + have he (x : Fin n → ℝ) : + c.coord (canonicalExp c x) i=x i-MvPolynomial.eval₂ (algebraMap ℚ ℝ) + (fun j : Fin k=>c.coord (canonicalExp c x) ⟨j.val,lt_trans j.isLt hk⟩) + (logCorrection c i) := by + have hh:=congrFun (canonicalLog_eq_forward c (canonicalExp c x)) i + rw [canonicalLog_exp] at hh + change x i=c.coord (canonicalExp c x) i+_ at hh + linarith + obtain ⟨p,hp,hq⟩:=hp + refine ⟨p,hp,?_⟩ + intro x + exact (he x).trans (hq x) + exact aux i.val i.isLt + +end RationalLattice +end + +end + +section + + +noncomputable section +open scoped BigOperators +namespace WeightedPolynomial +open MvPolynomial +variable {α β : Type*} + +lemma eval_kill_inr (p : MvPolynomial (α ⊕ β) ℝ) (y : β → ℝ) : + eval y (p.killCompl Sum.inr_injective)=eval (Sum.elim (fun _ : α=>0) y) p := by + induction p using MvPolynomial.induction_on with + | C a => simp + | add p q hp hq => simp [hp,hq] + | mul_X p i hp => + cases i with + | inl i => simp [map_mul,killCompl] + | inr i => + have he : killCompl (R:=ℝ) (Sum.inr_injective (α:=α)) (X (Sum.inr i))=X i := by + rw [← rename_X,killCompl_rename_app] + simp [map_mul,hp,he] + +lemma exists_left_of_vanishing (p : MvPolynomial (α ⊕ β) ℝ) + (hz : ∀ y,eval (Sum.elim (fun _ : α=>0) y) p=0) + (m : (α ⊕ β) →₀ ℕ) (hm : p.coeff m≠0) : ∃ a : α,m (Sum.inl a)≠0 := by + classical + by_contra hh + push Not at hh + have hs : ↑m.support ⊆ Set.range (@Sum.inr α β) := by + intro j hj + cases j with + | inl a => exact False.elim ((Finsupp.mem_support_iff.mp hj) (hh a)) + | inr b => exact ⟨b,rfl⟩ + have hk : p.killCompl Sum.inr_injective=0 := by + apply MvPolynomial.funext + intro y + rw [map_zero,eval_kill_inr,hz] + have hc:=congrArg (fun poly : MvPolynomial β ℝ=> + poly.coeff (m.comapDomain (@Sum.inr α β) Sum.inr_injective.injOn)) hk + rw [coeff_killCompl,m.mapDomain_comapDomain _ Sum.inr_injective hs, + AddMonoidAlgebra.coeff_zero,Finsupp.zero_apply] at hc + exact hm hc + + + +theorem fixed_left_spends_weight (wa : α → ℕ) (wb : β → ℕ) + (hwa : ∀ a,0 < wa a) {d : ℕ} (p : MvPolynomial (α ⊕ β) ℝ) + (hp : Bounded (Sum.elim wa wb) d p) + (hz : ∀ y,eval (Sum.elim (fun _ : α=>0) y) p=0) (a : α → ℝ) : + Bounded wb (d-1) (eval₂Hom C (Sum.elim (fun i=>C (a i)) (fun j=>X j)) p) := by + have hbound : Bounded (Sum.elim (fun _ : α=>0) wb) (d-1) p := by + intro m hm + obtain ⟨i,hi⟩:=exists_left_of_vanishing p hz m hm + have hlt : Finsupp.weight (Sum.elim (fun _ : α=>0) wb) m < Finsupp.weight (Sum.elim wa wb) m := by + classical + simp only [Finsupp.weight_apply,Finsupp.sum,smul_eq_mul] + apply Finset.sum_lt_sum + · intro j hj + apply Nat.mul_le_mul_left + cases j <;> simp + · refine ⟨Sum.inl i,Finsupp.mem_support_iff.mpr hi,?_⟩ + simpa using Nat.mul_pos (Nat.pos_of_ne_zero hi) (hwa i) + have hle:=hp m hm + omega + apply hbound.substitute + intro i + cases i with + | inl i => exact bounded_C (d:=0) _ + | inr j => exact bounded_X j + +end WeightedPolynomial + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WeylInverse01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WeylInverse01.lean new file mode 100644 index 0000000000000000000000000000000000000000..23db73731507498703a3a3db2fd78cf0bf5521d8 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WeylInverse01.lean @@ -0,0 +1,299 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.NearLattice01 +import OAI.Combinatorics.SumProduct.Alignment.PolynomialWeyl01 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +section +section +section +section +namespace WeylInverse +open scoped BigOperators ComplexConjugate +open PolynomialWeyl NearLattice +noncomputable section + + + +theorem density_of_large_average {ι : Type*} (S : Finset ι) (hS : S.Nonempty) + (f : ι → ℝ) (t : ℝ) (ht : 0 ≤ t) (hf : ∀ x ∈ S, f x ≤ 1) + (havg : 2 * t ≤ 𝔼 x ∈ S, f x) : + t * S.card ≤ ((S.filter (fun x => t ≤ f x)).card : ℝ) := by + classical + have h : (∑ x ∈ S, f x) ≤ ∑ x ∈ S, (t + if t ≤ f x then (1 : ℝ) else 0) := by + apply Finset.sum_le_sum + intro x hx + split_ifs with htx + · linarith [hf x hx] + · linarith + simp only [Finset.sum_add_distrib, Finset.sum_const, nsmul_eq_mul, + Finset.sum_boole] at h + rw [Finset.expect_eq_sum_div_card] at havg + have hc : 0 < (S.card : ℝ) := Nat.cast_pos.mpr (Finset.card_pos.mpr hS) + have havg' := (le_div_iff₀ hc).mp havg + nlinarith + + +theorem exists_dense_fiber (S : Finset ℕ) (A : ℕ) (hA : 0 < A) (q : ℕ → ℕ) + (hq : ∀ n ∈ S, q n ∈ Finset.Icc 1 A) : + ∃ a ∈ Finset.Icc 1 A, + (S.card : ℝ) / A ≤ ((S.filter (fun n => q n = a)).card : ℝ) := by + have hs : (Finset.Icc 1 A).Nonempty := ⟨1, Finset.mem_Icc.mpr ⟨le_rfl, hA⟩⟩ + have he : (𝔼 a ∈ Finset.Icc 1 A, ((S.filter (fun n => q n = a)).card : ℝ)) = + (S.card : ℝ) / A := by + rw [Finset.expect_eq_sum_div_card] + have hsum : (∑ a ∈ Finset.Icc 1 A, ((S.filter (fun n => q n = a)).card : ℝ)) = S.card := by + exact_mod_cast (Finset.card_eq_sum_card_fiberwise hq).symm + rw [hsum] + simp + exact Finset.exists_le_of_le_expect hs he.ge + + + +theorem exists_dense_derivatives {N H : ℕ} (hN : 0 < N) (hH : 0 < H) + (f : ℕ → ℂ) (hf : ∀ x, ‖f x‖ ≤ 1) (δ : ℝ) (hδ : 0 < δ) + (hlarge : δ ≤ ‖mean N f‖) (hboundary : 4 * (H : ℝ) / N ≤ δ ^ 2 / 2) : + ∃ b ∈ Finset.range H, ∃ S : Finset ℕ, + (∀ a ∈ S, a < H) ∧ δ ^ 2 / 4 * H ≤ (S.card : ℝ) ∧ + (∀ a ∈ S, δ ^ 2 / 4 ≤ ‖mean N (derivative a b f)‖) := by + classical + have hv := van_der_corput hN hH f hf + rw [Finset.expect_comm] at hv + have havg : δ ^ 2 / 2 ≤ + 𝔼 b ∈ Finset.range H, 𝔼 a ∈ Finset.range H, ‖mean N (derivative a b f)‖ := by + nlinarith [norm_nonneg (mean N f)] + have hs := Finset.nonempty_range_iff.mpr (Nat.ne_of_gt hH) + obtain ⟨b, hb, hbavg⟩ := Finset.exists_le_of_le_expect hs havg + let t := δ ^ 2 / 4 + let S := (Finset.range H).filter (fun a => t ≤ ‖mean N (derivative a b f)‖) + refine ⟨b, hb, S, ?_, ?_, ?_⟩ + · intro a ha + exact Finset.mem_range.mp (Finset.mem_filter.mp ha).1 + · have h := density_of_large_average (Finset.range H) hs + (fun a => ‖mean N (derivative a b f)‖) t (by dsimp [t]; positivity) + (fun a _ => norm_mean_le_one _ (norm_derivative_le_one a b f hf)) + (by dsimp [t]; linarith) + simpa only [Finset.card_range] using h + · intro a ha + exact (Finset.mem_filter.mp ha).2 + + + +def LeadingInverse (d : ℕ) : Prop := + ∀ δ : ℝ, 0 < δ → ∃ A : ℕ, 0 < A ∧ + ∀ N : ℕ, 0 < N → ∀ p : Polynomial ℝ, p.natDegree ≤ d → + δ ≤ ‖mean N (polynomialPhase p)‖ → + ∃ q : ℕ, 0 < q ∧ q ≤ A ∧ ∃ m : ℤ, + |(q : ℝ) * p.coeff d - m| ≤ (A : ℝ) / (N : ℝ) ^ d + + +theorem leading_inverse_one : LeadingInverse 1 := by + intro δ hδ + obtain ⟨A, hA⟩ := exists_nat_gt (1 / δ) + have hA₀ : 0 < A := by + have : (0 : ℝ) < A := lt_trans (one_div_pos.mpr hδ) hA + exact_mod_cast this + refine ⟨A, hA₀, ?_⟩ + intro N hN p hp hlarge + have he (x : ℕ) : p.eval (x : ℝ) = p.coeff 1 * x + p.coeff 0 := by + rw [Polynomial.eval_eq_sum_range' (show p.natDegree < 2 by omega)] + simp only [Finset.sum_range_succ, Finset.sum_range_zero, zero_add, + pow_zero, mul_one, pow_one] + ring + change δ ≤ ‖mean N (fun x => phase (p.eval (x : ℝ)))‖ at hlarge + simp_rw [he] at hlarge + obtain ⟨m, hm⟩ := linear_inverse hN (p.coeff 1) (p.coeff 0) δ hδ hlarge + refine ⟨1, by omega, hA₀, m, ?_⟩ + simp only [Nat.cast_one, one_mul, pow_one] + apply hm.trans + calc + 1 / (δ * N) = (1 / δ) / N := by ring + _ ≤ (A : ℝ) / N := div_le_div_of_nonneg_right hA.le (Nat.cast_nonneg _) + + + +theorem leading_inverse_step_at_length (d : ℕ) (δ : ℝ) (hδ : 0 < δ) + (A K L N H : ℕ) (hA : 0 < A) (hK : 0 < K) (hN : 0 < N) + (hH : 0 < H) + (hboundary : 4 * (H : ℝ) / N ≤ δ ^ 2 / 2) + (hdensity : (1 : ℝ) / K ≤ δ ^ 2 / (4 * A)) + (hHsize : 32 * K ^ 2 ≤ H) + (hεsmall : (A : ℝ) / (N : ℝ) ^ d ≤ 1 / (16 * K)) + (hHL : (N : ℝ) ≤ (H : ℝ) * L) + (hprev : ∀ p : Polynomial ℝ, p.natDegree ≤ d → + δ ^ 2 / 4 ≤ ‖mean N (polynomialPhase p)‖ → + ∃ q : ℕ, 0 < q ∧ q ≤ A ∧ ∃ m : ℤ, + |(q : ℝ) * p.coeff d - m| ≤ (A : ℝ) / (N : ℝ) ^ d) + (p : Polynomial ℝ) (hp : p.natDegree ≤ d + 1) + (hlarge : δ ≤ ‖mean N (polynomialPhase p)‖) : + ∃ q : ℕ, 0 < q ∧ q ≤ 2 * K * A * (d + 1) ∧ ∃ m : ℤ, + |(q : ℝ) * p.coeff (d + 1) - m| ≤ + (16 * (K : ℝ) ^ 2 * A * L) / (N : ℝ) ^ (d + 1) := by + classical + obtain ⟨b, _, S, hSH, hScard, hSlarge⟩ := exists_dense_derivatives hN hH + (polynomialPhase p) (fun x => by simp [polynomialPhase]) δ hδ hlarge hboundary + have hall : ∀ a : ℕ, ∃ q : ℕ, ∃ m : ℤ, a ∈ S → + 0 < q ∧ q ≤ A ∧ + |(q : ℝ) * (polynomialDifference a b p).coeff d - m| ≤ + (A : ℝ) / (N : ℝ) ^ d := by + intro a + by_cases ha : a ∈ S + · obtain ⟨q, hq, hqA, m, hm⟩ := hprev (polynomialDifference a b p) + (polynomialDifference_degree a b p d hp) + (by simpa only [polynomialPhase_difference] using hSlarge a ha) + exact ⟨q, m, fun _ => ⟨hq, hqA, hm⟩⟩ + · exact ⟨1, 0, fun h => (ha h).elim⟩ + choose q m hqm using hall + obtain ⟨a, ha, hafiber⟩ := exists_dense_fiber S A hA q + (fun n hn => Finset.mem_Icc.mpr ⟨(hqm n hn).1, (hqm n hn).2.1⟩) + have ha₀ : 0 < a := (Finset.mem_Icc.mp ha).1 + have haA : a ≤ A := (Finset.mem_Icc.mp ha).2 + let T := S.filter (fun n => q n = a) + have hTK : (H : ℝ) / K ≤ (T.card : ℝ) := by + have h₁ := mul_le_mul_of_nonneg_right hdensity (Nat.cast_nonneg H) + have h₂ := div_le_div_of_nonneg_right hScard (Nat.cast_nonneg A) + change (S.card : ℝ) / A ≤ (T.card : ℝ) at hafiber + have he : δ ^ 2 / 4 * H / A = δ ^ 2 / (4 * A) * H := by ring + rw [he] at h₂ + have he' : (1 : ℝ) / K * H = (H : ℝ) / K := by ring + rw [he'] at h₁ + exact h₁.trans (h₂.trans hafiber) + let α : ℝ := (a : ℝ) * (d + 1 : ℕ) * p.coeff (d + 1) + obtain ⟨u, hu₀, huK, z, hz⟩ := vinogradov_inverse T H K hK hHsize + α (-α * b) ((A : ℝ) / (N : ℝ) ^ d) (by positivity) hεsmall + (fun n hn => hSH n (Finset.mem_filter.mp hn).1) hTK (by + intro n hn + obtain ⟨hnS, hnq⟩ := Finset.mem_filter.mp hn + refine ⟨m n, ?_⟩ + have hm := (hqm n hnS).2.2 + rw [hnq, polynomialDifference_coeff n b p d hp] at hm + have heq : α * n + (-α * b) - m n = + (a : ℝ) * ((d + 1 : ℕ) * p.coeff (d + 1) * ((n : ℝ) - b)) - m n := by + dsimp [α] + ring + rw [heq] + exact hm) + refine ⟨u * a * (d + 1), by positivity, + Nat.mul_le_mul_right _ (Nat.mul_le_mul huK haA), z, ?_⟩ + have he : ((u * a * (d + 1) : ℕ) : ℝ) * p.coeff (d + 1) = α * u := by + dsimp [α] + push_cast + ring + rw [he] + apply hz.trans + have hN₀ : 0 < (N : ℝ) := Nat.cast_pos.mpr hN + have hH₀ : 0 < (H : ℝ) := Nat.cast_pos.mpr hH + have hi : (1 : ℝ) / H ≤ (L : ℝ) / N := by + apply (div_le_div_iff₀ hH₀ hN₀).mpr + nlinarith only [hHL] + calc + 16 * (K : ℝ) ^ 2 * ((A : ℝ) / (N : ℝ) ^ d) / H = + (16 * (K : ℝ) ^ 2 * A / (N : ℝ) ^ d) * (1 / H) := by ring + _ ≤ (16 * (K : ℝ) ^ 2 * A / (N : ℝ) ^ d) * (L / N) := + mul_le_mul_of_nonneg_left hi (by positivity) + _ = _ := by rw [pow_succ]; ring + + + +theorem leading_inverse_succ (d : ℕ) (hd : 0 < d) + (ih : LeadingInverse d) : LeadingInverse (d + 1) := by + intro δ hδ + obtain ⟨A, hA, hprev⟩ := ih (δ ^ 2 / 4) (by positivity) + obtain ⟨M, hM⟩ := exists_nat_gt (16 / δ ^ 2) + obtain ⟨K, hK⟩ := exists_nat_gt (4 * (A : ℝ) / δ ^ 2) + have hM₀ : 0 < (M : ℝ) := lt_trans (by positivity) hM + have hK₀ : 0 < (K : ℝ) := lt_trans (by positivity) hK + have hMnat : 0 < M := Nat.cast_pos.mp hM₀ + have hKnat : 0 < K := Nat.cast_pos.mp hK₀ + have hMδ : 16 ≤ (M : ℝ) * δ ^ 2 := + ((div_lt_iff₀ (by positivity : 0 < δ ^ 2)).mp hM).le + have hKδ : 4 * (A : ℝ) ≤ (K : ℝ) * δ ^ 2 := + ((div_lt_iff₀ (by positivity : 0 < δ ^ 2)).mp hK).le + let T := M * (32 * K ^ 2 + 1) + 16 * K * A + 2 * M + 1 + let Q := 2 * K * A * (d + 1) + let C := 32 * K ^ 2 * A * M + let B := Q + C + T ^ (d + 1) + 1 + have hB : 0 < B := by dsimp [B]; omega + have hQB : Q ≤ B := by dsimp [B]; omega + have hCB : C ≤ B := by dsimp [B]; omega + have hTB : T ^ (d + 1) ≤ B := by dsimp [B]; omega + refine ⟨B, hB, ?_⟩ + intro N hN p hp hlarge + have hN₀ : 0 < (N : ℝ) := Nat.cast_pos.mpr hN + by_cases hNT : N < T + · refine ⟨1, by omega, hB, ⌊p.coeff (d + 1)⌋, ?_⟩ + simp only [Nat.cast_one, one_mul] + calc + |p.coeff (d + 1) - (⌊p.coeff (d + 1)⌋ : ℝ)| ≤ 1 := by + rw [abs_of_nonneg (sub_nonneg.mpr (Int.floor_le _))] + linarith [Int.lt_floor_add_one (p.coeff (d + 1))] + _ ≤ (B : ℝ) / (N : ℝ) ^ (d + 1) := by + apply (le_div_iff₀ (pow_pos hN₀ _)).mpr + simp only [one_mul] + exact_mod_cast (Nat.pow_le_pow_left hNT.le (d + 1)).trans hTB + · have hTN : T ≤ N := Nat.le_of_not_gt hNT + let H := N / M + have hHsize : 32 * K ^ 2 ≤ H := by + apply (Nat.le_div_iff_mul_le hMnat).mpr + have he : M * (32 * K ^ 2 + 1) = 32 * K ^ 2 * M + M := by ring + dsimp [T] at hTN + rw [he] at hTN + omega + have hH : 0 < H := lt_of_lt_of_le (by positivity) hHsize + have h16 : 16 * K * A ≤ N := by dsimp [T] at hTN; omega + have hHM : (H : ℝ) * M ≤ N := by + exact_mod_cast (Nat.div_mul_le_self N M) + have hboundary : 4 * (H : ℝ) / N ≤ δ ^ 2 / 2 := by + calc + 4 * (H : ℝ) / N ≤ 4 / (M : ℝ) := by + apply (div_le_div_iff₀ hN₀ hM₀).mpr + nlinarith only [hHM] + _ ≤ δ ^ 2 / 2 := by + apply (div_le_iff₀ hM₀).mpr + nlinarith only [hMδ] + have hdensity : (1 : ℝ) / K ≤ δ ^ 2 / (4 * A) := by + apply (div_le_div_iff₀ hK₀ (by positivity : 0 < 4 * (A : ℝ))).mpr + nlinarith only [hKδ] + have heps : (A : ℝ) / (N : ℝ) ^ d ≤ 1 / (16 * K) := by + have hpow : (N : ℝ) ≤ (N : ℝ) ^ d := + le_self_pow₀ (by exact_mod_cast hN) (Nat.ne_of_gt hd) + have h16' : 16 * (K : ℝ) * A ≤ N := by exact_mod_cast h16 + apply (div_le_div_iff₀ (pow_pos hN₀ _) (by positivity : 0 < 16 * (K : ℝ))).mpr + nlinarith only [hpow, h16'] + have hHL : (N : ℝ) ≤ (H : ℝ) * (2 * M : ℕ) := by + have hrem := Nat.mod_lt N hMnat + have he := Nat.div_add_mod N M + have hmH : M ≤ H * M := by nlinarith only [Nat.mul_le_mul_right M hH] + have hh : N ≤ H * (2 * M) := by dsimp [H] at hmH ⊢; nlinarith only [he, hrem, hmH] + exact_mod_cast hh + obtain ⟨q, hq, hqQ, m, hm⟩ := leading_inverse_step_at_length d δ hδ A K (2 * M) + N H hA hKnat hN hH hboundary hdensity hHsize heps hHL + (hprev N hN) p hp hlarge + refine ⟨q, hq, hqQ.trans hQB, m, hm.trans ?_⟩ + apply div_le_div_of_nonneg_right _ (by positivity) + have hCB' : (C : ℝ) ≤ B := by exact_mod_cast hCB + simp only [C, Nat.cast_mul, Nat.cast_pow, Nat.cast_ofNat] at hCB' ⊢ + nlinarith only [hCB'] + + + +theorem leading_inverse (d : ℕ) (hd : 0 < d) : LeadingInverse d := by + induction d using Nat.case_strong_induction_on with + | hz => omega + | hi d ih => + by_cases he : d = 0 + · subst d + exact leading_inverse_one + · exact leading_inverse_succ d (Nat.pos_of_ne_zero he) + (ih d (by omega) (Nat.pos_of_ne_zero he)) + +end +end WeylInverse + +end +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan01.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan01.lean new file mode 100644 index 0000000000000000000000000000000000000000..c391896da68e440608b75544ff3c53c2e41d1df8 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan01.lean @@ -0,0 +1,2883 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.AllLevel11 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +noncomputable section +open scoped BigOperators Topology ENNReal +open MeasureTheory Filter +end + +end + +section + + + + +noncomputable section +open scoped BigOperators Topology +open MeasureTheory Filter +namespace AllLevelFactorization.Factorization +open RationalLattice CubeFaces +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n s : ℕ} {c : RealCoordinates G n} {Γ : Subgroup G} +variable {K : Filtration G} {P : ℕ → ℤ → G} {L : ℕ → ℝ} +variable (F : Factorization c Γ s K P L) +variable (C : (r : Fin F.period) → F.ResidueCover r) +variable [∀ r,MeasurableSpace ((C r).CubeSpace (ι:=Empty))] +variable [∀ r,BorelSpace ((C r).CubeSpace (ι:=Empty))] +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] [CompactSpace (G⧸Γ)] +variable [SecondCountableTopology (G⧸Γ)] + +def smoothAction : C(ℝ×(G⧸Γ),G⧸Γ) := + ⟨fun p=>F.smoothLimit p.1 • p.2, + (F.smoothLimit_continuous.comp continuous_fst).smul continuous_snd⟩ + +def pointMixture : ProbabilityMeasure (G⧸Γ) := + letI : Nonempty (Fin F.period) := ⟨⟨0,F.period_pos⟩⟩ + ProbabilityMixtures.finiteAverage (fun r=> + ProbabilityMixtures.intervalPush (C r).pointHaar F.smoothAction) + +lemma pointMixture_integral (f : C(G⧸Γ,ℂ)) : + (∫ y,f y ∂(F.pointMixture C : Measure _))= + GlobalPointLaw.betaMixture (fun r=>(C r).pointHaar) (F.limitTest f) := by + let : Nonempty (Fin F.period):=⟨⟨0,F.period_pos⟩⟩ + change (∫ y,f y ∂(ProbabilityMixtures.finiteAverage (fun r=> + ProbabilityMixtures.intervalPush (C r).pointHaar F.smoothAction) : Measure _))=_ + rw [ProbabilityMixtures.finiteAverage_integral] + · simp_rw [ProbabilityMixtures.intervalPush_integral] + simp only [Fintype.card_fin,GlobalPointLaw.betaMixture,limitTest,leftTest,smoothAction,ContinuousMap.coe_mk] + · intro r + exact Integrable.of_bound f.continuous.aestronglyMeasurable ‖f‖ + (Eventually.of_forall f.norm_coe_le_norm) + +variable [MeasurableSingletonClass (G⧸Γ)] + +def empiricalPointLaw (N : ℕ) : ProbabilityMeasure (G⧸Γ) := + ProbabilityMixtures.empirical ⌊L (F.state.subseq N)⌋₊ + (fun k=>QuotientGroup.mk (P (F.state.subseq N) (k:ℤ))) + + + +theorem weak_point_law (hL : ∀ N,0QuotientGroup.mk (P (F.state.subseq N) (k:ℤ))) ff).symm + +end AllLevelFactorization.Factorization +end + +end + +section + + + + +namespace ConstructedWordPlan + + + +open scoped commutatorElement +open scoped Pointwise + +namespace CubeFaces + +variable {G ι : Type*} [Group G] [DecidableEq ι] + + + +structure Filtration (G : Type*) [Group G] where + level : ℕ → Subgroup G + antitone : Antitone level + commutator_le : ∀ i j, ⁅level i, level j⁆ ≤ level (i + j) + + +def face (D : Finset ι) : G →* (Finset ι → G) where + toFun g v := if D ⊆ v then g else 1 + map_one' := by funext v; simp + map_mul' g h := by funext v; dsimp; split_ifs <;> simp + +@[simp] lemma face_apply (D v : Finset ι) (g : G) : + face D g v = if D ⊆ v then g else 1 := rfl + +lemma face_commutator (D E : Finset ι) (g h : G) : + ⁅face D g, face E h⁆ = face (D ∪ E) ⁅g,h⁆ := by + funext v + simp only [commutatorElement_def, Pi.mul_apply, Pi.inv_apply, face_apply, + Finset.union_subset_iff] + by_cases hD : D ⊆ v <;> by_cases hE : E ⊆ v <;> simp [hD, hE] + + +def cube (H : Filtration G) (I : Finset ι) (k : ℕ) : Subgroup (Finset ι → G) := + ⨆ D : Finset ι, ⨆ (_ : D ⊆ I), (H.level (D.card + k)).map (face D) + +lemma face_mem_cube (H : Filtration G) {I D : Finset ι} {k : ℕ} + (hD : D ⊆ I) {g : G} (hg : g ∈ H.level (D.card + k)) : + face D g ∈ cube H I k := by + have hle : (H.level (D.card + k)).map (face D) ≤ cube H I k := + le_iSup_of_le D (le_iSup_of_le hD le_rfl) + exact hle ⟨g, hg, rfl⟩ + + +def upper (a : ι) : (Finset ι → G) →* (Finset ι → G) where + toFun f v := if a ∈ v then f v else 1 + map_one' := by funext v; simp + map_mul' f g := by funext v; dsimp; split_ifs <;> simp + +lemma upper_face (a : ι) (D : Finset ι) : + (upper a).comp (face D : G →* (Finset ι → G)) = face (insert a D) := by + ext g v + by_cases ha : a ∈ v <;> by_cases hD : D ⊆ v <;> + simp [upper, face, Finset.insert_subset_iff, ha, hD] + +lemma map_upper_cube (H : Filtration G) (a : ι) (I : Finset ι) (k : ℕ) : + (cube H I (k + 1)).map (upper a) = + ⨆ E : Finset ι, ⨆ (_ : E ⊆ I), + (H.level (E.card + k + 1)).map (face (insert a E)) := by + simp only [cube, Subgroup.map_iSup, Subgroup.map_map, upper_face, Nat.add_assoc] + +@[simp] lemma upper_face_apply (a : ι) (D : Finset ι) (g : G) : + upper a (face D g) = face (insert a D) g := + DFunLike.congr_fun (upper_face a D) g + +lemma face_upper_commutator_mem (H : Filtration G) (a : ι) + {I D E : Finset ι} {k : ℕ} (hD : D ⊆ I) (hE : E ⊆ I) + {g h : G} (hg : g ∈ H.level (D.card + k)) + (hh : h ∈ H.level (E.card + (k + 1))) : + ⁅face D g, upper a (face E h)⁆ ∈ (cube H I (k + 1)).map (upper a) := by + rw [upper_face_apply, face_commutator, Finset.union_insert] + have hdeg : (D ∪ E).card + (k + 1) ≤ (D.card + k) + (E.card + (k + 1)) := by + have := Finset.card_union_le D E + omega + have hc : ⁅g,h⁆ ∈ H.level ((D ∪ E).card + (k + 1)) := + H.antitone hdeg (H.commutator_le _ _ (Subgroup.commutator_mem_commutator hg hh)) + exact ⟨face (D ∪ E) ⁅g,h⁆, face_mem_cube H (Finset.union_subset hD hE) hc, + upper_face_apply a (D ∪ E) ⁅g,h⁆⟩ + +lemma cube_le_normalizer_upper (H : Filtration G) (a : ι) (I : Finset ι) (k : ℕ) : + cube H I k ≤ Subgroup.normalizer ((cube H I (k + 1)).map (upper a)) := by + let R := (cube H I (k + 1)).map (upper a) + change (⨆ D : Finset ι, ⨆ (_ : D ⊆ I), + (H.level (D.card + k)).map (face D)) ≤ Subgroup.normalizer R + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g, hg, rfl⟩ + have hc (g : G) (hg : g ∈ H.level (D.card + k)) : + ∀ z ∈ R, face D g * z * (face D g)⁻¹ ∈ R := by + have hle : cube H I (k + 1) ≤ + R.comap ((MulAut.conj (face D g)).toMonoidHom.comp (upper a)) := by + refine iSup_le fun E => iSup_le fun hE => ?_ + rintro f ⟨h, hh, rfl⟩ + change face D g * upper a (face E h) * (face D g)⁻¹ ∈ R + have hm : upper a (face E h) ∈ R := + ⟨face E h, face_mem_cube H hE hh, rfl⟩ + have hcomm := face_upper_commutator_mem H a hD hE hg hh + have heq : face D g * upper a (face E h) * (face D g)⁻¹ = + ⁅face D g, upper a (face E h)⁆ * upper a (face E h) := by + simp [commutatorElement_def, mul_assoc] + rw [heq] + exact R.mul_mem hcomm hm + rintro z ⟨u, hu, rfl⟩ + exact hle hu + rw [Subgroup.mem_normalizer_iff] + intro z + constructor + · exact hc g hg z + · intro hz + have ht := hc g⁻¹ ((H.level _).inv_mem hg) _ hz + simpa [map_inv, mul_assoc] using ht + +lemma cube_insert_le (H : Filtration G) (a : ι) (I : Finset ι) (k : ℕ) : + cube H (insert a I) k ≤ cube H I k ⊔ (cube H I (k + 1)).map (upper a) := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g, hg, rfl⟩ + by_cases haD : a ∈ D + · have hE : D.erase a ⊆ I := by + intro x hx + rcases Finset.mem_erase.mp hx with ⟨hxa, hx⟩ + exact (Finset.mem_insert.mp (hD hx)).resolve_left hxa + have hcard := Finset.card_erase_add_one haD + have hg' : g ∈ H.level ((D.erase a).card + (k + 1)) := by + have he : (D.erase a).card + (k + 1) = D.card + k := by omega + rwa [he] + apply Subgroup.mem_sup_right + refine ⟨face (D.erase a) g, face_mem_cube H hE hg', ?_⟩ + rw [upper_face_apply, Finset.insert_erase haD] + · have hDI : D ⊆ I := by + intro x hx + rcases Finset.mem_insert.mp (hD hx) with hxa | hxi + · exact False.elim (haD (hxa ▸ hx)) + · exact hxi + exact Subgroup.mem_sup_left (face_mem_cube H hDI hg) + + + +lemma cube_decompose (H : Filtration G) (a : ι) (I : Finset ι) (k : ℕ) + {f : Finset ι → G} (hf : f ∈ cube H (insert a I) k) : + ∃ l ∈ cube H I k, ∃ u ∈ cube H I (k + 1), f = l * upper a u := by + have hx := cube_insert_le H a I k hf + change f ∈ (↑(cube H I k ⊔ (cube H I (k + 1)).map (upper a)) : Set _) at hx + rw [Subgroup.coe_mul_of_left_le_normalizer_right _ _ (cube_le_normalizer_upper H a I k)] at hx + rcases hx with ⟨l, hl, z, ⟨u, hu, rfl⟩, hmul⟩ + exact ⟨l, hl, u, hu, hmul.symm⟩ + + +def evaluation (v : Finset ι) : (Finset ι → G) →* G where + toFun f := f v + map_one' := rfl + map_mul' _ _ := rfl + +lemma cube_insert_irrelevant (H : Filtration G) {I : Finset ι} {a : ι} + (ha : a ∉ I) {k : ℕ} {f : Finset ι → G} (hf : f ∈ cube H I k) + (v : Finset ι) : f (insert a v) = f v := by + have hle : cube H I k ≤ (evaluation (insert a v)).eqLocus (evaluation v) := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g, hg, rfl⟩ + change face D g (insert a v) = face D g v + have he : D ⊆ insert a v ↔ D ⊆ v := by + constructor + · intro hd x hx + have hxa : x ≠ a := by rintro rfl; exact ha (hD hx) + exact (Finset.mem_insert.mp (hd hx)).resolve_left hxa + · intro hd + exact hd.trans (Finset.subset_insert a v) + simp only [face_apply, he] + exact hle hf + +lemma cube_eval_mem (H : Filtration G) {I : Finset ι} {k : ℕ} + {f : Finset ι → G} (hf : f ∈ cube H I k) (v : Finset ι) : f v ∈ H.level k := by + have hle : cube H I k ≤ (H.level k).comap (evaluation v) := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g, hg, rfl⟩ + change face D g v ∈ H.level k + simp only [face_apply] + split_ifs + · exact H.antitone (Nat.le_add_left k D.card) hg + · exact (H.level k).one_mem + exact hle hf + +lemma cube_shift_le (H : Filtration G) (I : Finset ι) {i j : ℕ} (h : i ≤ j) : + cube H I j ≤ cube H I i := by + refine iSup_le fun D => iSup_le fun hD => ?_ + exact (Subgroup.map_mono (H.antitone (Nat.add_le_add_left h _))).trans + (le_iSup_of_le D (le_iSup_of_le hD le_rfl)) + +lemma cube_restrict (H : Filtration G) {I : Finset ι} {k : ℕ} + {f : Finset ι → G} (hf : f ∈ cube H I k) (v : Finset ι) : + f (v ∩ I) = f v := by + have hle : cube H I k ≤ (evaluation (v ∩ I)).eqLocus (evaluation v) := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g,hg,rfl⟩ + change face D g (v ∩ I) = face D g v + simp only [face_apply, Finset.subset_inter_iff, hD, and_true] + exact hle hf + +lemma cube_normalizes (H : Filtration G) (I : Finset ι) (k : ℕ) : + cube H I 0 ≤ Subgroup.normalizer (cube H I k) := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g,hg,rfl⟩ + have hc (g : G) (hg : g ∈ H.level (D.card + 0)) : + ∀ z ∈ cube H I k, face D g * z * (face D g)⁻¹ ∈ cube H I k := by + have hle : cube H I k ≤ (cube H I k).comap (MulAut.conj (face D g)).toMonoidHom := by + refine iSup_le fun E => iSup_le fun hE => ?_ + rintro f ⟨h,hh,rfl⟩ + change face D g * face E h * (face D g)⁻¹ ∈ cube H I k + have hdeg : (D ∪ E).card + k ≤ (D.card + 0) + (E.card + k) := by + have := Finset.card_union_le D E + omega + have hcomm : ⁅face D g, face E h⁆ ∈ cube H I k := by + rw [face_commutator] + exact face_mem_cube H (Finset.union_subset hD hE) + (H.antitone hdeg (H.commutator_le _ _ (Subgroup.commutator_mem_commutator hg hh))) + have heq : face D g * face E h * (face D g)⁻¹ = ⁅face D g, face E h⁆ * face E h := by + simp [commutatorElement_def, mul_assoc] + rw [heq] + exact (cube H I k).mul_mem hcomm (face_mem_cube H hE hh) + exact fun z hz => hle hz + rw [Subgroup.mem_normalizer_iff] + intro z + constructor + · exact hc g hg z + · intro hz + have hh := hc g⁻¹ ((H.level _).inv_mem hg) _ hz + simpa [map_inv, mul_assoc] using hh + + +def commModulo (N : Subgroup G) (a : G) : Subgroup G where + carrier := {b | b ∈ (Subgroup.normalizer (N : Set G)) ∧ ⁅a,b⁆ ∈ N} + one_mem' := by simp + mul_mem' := by + rintro b c ⟨hb,hbc⟩ ⟨hc,hcc⟩ + change b ∈ Subgroup.normalizer (N : Set G) at hb + change c ∈ Subgroup.normalizer (N : Set G) at hc + refine ⟨Subgroup.mul_mem (Subgroup.normalizer (N : Set G)) hb hc, ?_⟩ + have hconj := (Subgroup.mem_normalizer_iff.mp hb ⁅a,c⁆).mp hcc + have he : ⁅a,b*c⁆ = ⁅a,b⁆ * (b * ⁅a,c⁆ * b⁻¹) := by + simp [commutatorElement_def, mul_assoc] + rw [he] + exact N.mul_mem hbc hconj + inv_mem' := by + rintro b ⟨hb,hbc⟩ + change b ∈ Subgroup.normalizer (N : Set G) at hb + refine ⟨Subgroup.inv_mem (Subgroup.normalizer (N : Set G)) hb, ?_⟩ + have hconj := (Subgroup.mem_normalizer_iff.mp ((Subgroup.normalizer (N : Set G)).inv_mem hb) (⁅a,b⁆)⁻¹).mp + (N.inv_mem hbc) + simpa [commutatorElement_def, mul_assoc] using hconj + +lemma face_cube_commutator_mem (H : Filtration G) (I : Finset ι) {i j : ℕ} + {D : Finset ι} (hD : D ⊆ I) {g : G} (hg : g ∈ H.level (D.card+i)) + {f : Finset ι → G} (hf : f ∈ cube H I j) : + ⁅face D g, f⁆ ∈ cube H I (i+j) := by + have hle : cube H I j ≤ commModulo (cube H I (i+j)) (face D g) := by + refine iSup_le fun E => iSup_le fun hE => ?_ + rintro f ⟨h,hh,rfl⟩ + constructor + · exact cube_normalizes H I _ + (cube_shift_le H I (Nat.zero_le j) (face_mem_cube H hE hh)) + · rw [face_commutator] + have hdeg : (D ∪ E).card + (i+j) ≤ (D.card+i) + (E.card+j) := by + have := Finset.card_union_le D E + omega + exact face_mem_cube H (Finset.union_subset hD hE) + (H.antitone hdeg (H.commutator_le _ _ (Subgroup.commutator_mem_commutator hg hh))) + exact (hle hf).2 + +lemma cube_commutator_mem (H : Filtration G) (I : Finset ι) {i j : ℕ} + {f g : Finset ι → G} (hf : f ∈ cube H I i) (hg : g ∈ cube H I j) : + ⁅f,g⁆ ∈ cube H I (i+j) := by + have hle : cube H I i ≤ commModulo (cube H I (i+j)) g := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨a,ha,rfl⟩ + constructor + · exact cube_normalizes H I _ + (cube_shift_le H I (Nat.zero_le i) (face_mem_cube H hD ha)) + · have hh := face_cube_commutator_mem H I hD ha hg + have hinv := (cube H I (i+j)).inv_mem hh + simpa [commutatorElement_def, mul_assoc] using hinv + have hinv := (cube H I (i+j)).inv_mem (hle hf).2 + simpa [commutatorElement_def, mul_assoc] using hinv + +lemma cube_mono (H : Filtration G) {I J : Finset ι} (hIJ : I ⊆ J) (k : ℕ) : + cube H I k ≤ cube H J k := by + refine iSup_le fun D => iSup_le fun hD => ?_ + exact le_iSup_of_le D (le_iSup_of_le (hD.trans hIJ) le_rfl) + +lemma upper_cube_mem (H : Filtration G) {I : Finset ι} {a : ι} (ha : a ∉ I) (k : ℕ) + {f : Finset ι → G} (hf : f ∈ cube H I (k+1)) : upper a f ∈ cube H (insert a I) k := by + have hle : cube H I (k+1) ≤ (cube H (insert a I) k).comap (upper a) := by + refine iSup_le fun D => iSup_le fun hD => ?_ + rintro f ⟨g,hg,rfl⟩ + change upper a (face D g) ∈ cube H (insert a I) k + rw [upper_face_apply] + apply face_mem_cube H (Finset.insert_subset_insert a hD) + have haD : a ∉ D := fun h => ha (hD h) + change g ∈ H.level (D.card + (k+1)) at hg + simpa only [Finset.card_insert_of_notMem haD, Nat.add_assoc, Nat.add_comm, + Nat.add_left_comm] using hg + exact hle hf + +end CubeFaces + +namespace CubePolynomials +open _root_.OAI.ConstructedWordPlan.CubeFaces +noncomputable section +variable {G : Type*} [Group G] + +def pattern (I : Finset ℕ) (h : ℕ → ℤ) (n : ℤ) : (ℤ → G) →* (Finset ℕ → G) where + toFun f v := f (n + ∑ i ∈ v ∩ I, h i) + map_one' := rfl + map_mul' _ _ := rfl + +def polynomials (H : Filtration G) (k : ℕ) : Subgroup (ℤ → G) := + ⨅ (I : Finset ℕ) (h : ℕ → ℤ) (n : ℤ), (cube H I k).comap (pattern I h n) + +lemma mem_polynomials (H : Filtration G) (k : ℕ) (f : ℤ → G) : + f ∈ polynomials H k ↔ ∀ I h n, pattern I h n f ∈ cube H I k := by + simp [polynomials] + +lemma polynomials_antitone (H : Filtration G) : Antitone (polynomials H) := by + intro i j hij f hf + rw [mem_polynomials] at hf ⊢ + intro I h n + exact cube_shift_le H I hij (hf I h n) + +lemma eval_mem {H : Filtration G} {k : ℕ} {f : ℤ → G} + (hf : f ∈ polynomials H k) (n : ℤ) : f n ∈ H.level k := by + have h := (mem_polynomials H k f).mp hf ∅ (fun _ => 0) n + simpa [pattern] using cube_eval_mem H h ∅ + +lemma const_mem {H : Filtration G} {k : ℕ} {g : G} (hg : g ∈ H.level k) : + (fun _ : ℤ => g) ∈ polynomials H k := by + rw [mem_polynomials] + intro I h n + have he : pattern I h n (fun _ : ℤ => g) = face ∅ g := by ext v; simp [pattern, face] + rw [he] + exact face_mem_cube H (Finset.empty_subset I) (by simpa using hg) + +lemma polynomials_eq_bot {H : Filtration G} {k : ℕ} (hk : H.level k = ⊥) : + polynomials H k = ⊥ := by + apply le_antisymm _ bot_le + intro f hf + apply Subgroup.mem_bot.mpr + funext n + have h := eval_mem hf n + simpa [hk] using h + +def shift (t : ℤ) : (ℤ → G) ≃* (ℤ → G) where + toFun f n := f (n+t) + invFun f n := f (n-t) + left_inv f := by ext n; simp + right_inv f := by ext n; simp + map_mul' _ _ := rfl + +lemma shift_mem {H : Filtration G} {k : ℕ} {f : ℤ → G} + (hf : f ∈ polynomials H k) (t : ℤ) : shift t f ∈ polynomials H k := by + rw [mem_polynomials] at hf ⊢ + intro I h n + convert hf I h (n+t) using 1 + ext v + change f ((n + ∑ i ∈ v ∩ I, h i) + t) = f ((n+t) + ∑ i ∈ v ∩ I, h i) + congr 1 + ring + +lemma derivative_mem {H : Filtration G} {k : ℕ} {f : ℤ → G} + (hf : f ∈ polynomials H k) (t : ℤ) : f⁻¹ * shift t f ∈ polynomials H (k+1) := by + rw [mem_polynomials] at hf ⊢ + intro I h n + let a := I.sup id + 1 + have ha : a ∉ I := by + intro ha + have hle : a ≤ I.sup id := Finset.le_sup (f := id) ha + dsimp [a] at hle + omega + let h' := Function.update h a t + have hcube := hf (insert a I) h' n + obtain ⟨l,hl,u,hu,he⟩ := cube_decompose H a I k hcube + have heq : pattern I h n (f⁻¹ * shift t f) = u := by + funext v + let V := v ∩ I + have hVI : V ⊆ I := Finset.inter_subset_right + have haV : a ∉ V := fun h => ha (hVI h) + have hs : ∑ j ∈ V, h' j = ∑ j ∈ V, h j := by + apply Finset.sum_congr rfl + intro j hj + have hjne : j ≠ a := by rintro rfl; exact haV hj + exact Function.update_of_ne hjne t h + have hVa : V ∩ insert a I = V := Finset.inter_eq_left.mpr (hVI.trans (Finset.subset_insert a I)) + have hVai : insert a V ∩ insert a I = insert a V := + Finset.inter_eq_left.mpr (Finset.insert_subset_insert a hVI) + have hlo := congrFun he V + have hhi := congrFun he (insert a V) + change f (n + ∑ j ∈ V ∩ insert a I, h' j) = l V * (if a ∈ V then u V else 1) at hlo + change f (n + ∑ j ∈ insert a V ∩ insert a I, h' j) = + l (insert a V) * (if a ∈ insert a V then u (insert a V) else 1) at hhi + simp only [hVa, haV, ite_false, mul_one, hs] at hlo + simp only [hVai, Finset.mem_insert_self, ite_true, + cube_insert_irrelevant H ha hl, cube_insert_irrelevant H ha hu, + Finset.sum_insert haV, show h' a = t from Function.update_self a t h, hs] at hhi + change (f (n + ∑ j ∈ V, h j))⁻¹ * f ((n + ∑ j ∈ V, h j) + t) = u v + rw [show (n + ∑ j ∈ V, h j) + t = n + (t + ∑ j ∈ V, h j) by ring, + hlo, hhi, inv_mul_cancel_left] + exact cube_restrict H hu v + rw [heq] + exact hu + + + +lemma mem_of_derivatives {H : Filtration G} {k : ℕ} {f : ℤ → G} + (hvalue : ∀ n, f n ∈ H.level k) + (hd : ∀ t, f⁻¹ * shift t f ∈ polynomials H (k+1)) : f ∈ polynomials H k := by + rw [mem_polynomials] + intro I + induction I using Finset.induction_on with + | empty => + intro h n + have he : pattern ∅ h n f = face ∅ (f n) := by ext v; simp [pattern, face] + rw [he] + exact face_mem_cube H (Finset.empty_subset ∅) (by simpa using hvalue n) + | @insert a I ha ih => + intro h n + let l := pattern I h n f + let u := pattern I h n (f⁻¹ * shift (h a) f) + have hl : l ∈ cube H I k := ih h n + have hu : u ∈ cube H I (k+1) := (mem_polynomials H (k+1) _).mp (hd (h a)) I h n + have he : pattern (insert a I) h n f = l * upper a u := by + funext v + have haV : a ∉ v ∩ I := fun hh => ha (Finset.mem_inter.mp hh).2 + by_cases hav : a ∈ v + · have hv : v ∩ insert a I = insert a (v ∩ I) := by + ext b + simp only [Finset.mem_inter, Finset.mem_insert] + aesop + change f (n + ∑ i ∈ v ∩ insert a I, h i) = + f (n + ∑ i ∈ v ∩ I, h i) * (if a ∈ v then + (f (n + ∑ i ∈ v ∩ I, h i))⁻¹ * f ((n + ∑ i ∈ v ∩ I, h i) + h a) else 1) + rw [hv, Finset.sum_insert haV, ite_eq_left hav, mul_inv_cancel_left] + congr 1 + ring + · have hv : v ∩ insert a I = v ∩ I := by + ext b + simp only [Finset.mem_inter, Finset.mem_insert] + aesop + change f (n + ∑ i ∈ v ∩ insert a I, h i) = + f (n + ∑ i ∈ v ∩ I, h i) * (if a ∈ v then u v else 1) + rw [hv, ite_eq_right hav, mul_one] + rw [he] + exact (cube H (insert a I) k).mul_mem + (cube_mono H (Finset.subset_insert a I) k hl) (upper_cube_mem H ha k hu) + +lemma commutator_mem {H : Filtration G} {i j : ℕ} {f g : ℤ → G} + (hf : f ∈ polynomials H i) (hg : g ∈ polynomials H j) : + ⁅f,g⁆ ∈ polynomials H (i+j) := by + rw [mem_polynomials] at hf hg ⊢ + intro I h n + rw [map_commutatorElement] + exact cube_commutator_mem H I (hf I h n) (hg I h n) + +lemma normalizes (H : Filtration G) (k : ℕ) : + polynomials H 0 ≤ (Subgroup.normalizer (polynomials H k)) := by + intro f hf + apply Subgroup.mem_normalizer_iff.mpr + intro g + have hconj {f : ℤ → G} (hf : f ∈ polynomials H 0) {g : ℤ → G} + (hg : g ∈ polynomials H k) : f*g*f⁻¹ ∈ polynomials H k := by + have hc : ⁅f,g⁆ ∈ polynomials H k := by simpa using commutator_mem hf hg + have he : f*g*f⁻¹ = ⁅f,g⁆ * g := by simp [commutatorElement_def, mul_assoc] + rw [he] + exact (polynomials H k).mul_mem hc hg + constructor + · exact hconj hf + · intro hg + have hh := hconj ((polynomials H 0).inv_mem hf) hg + simpa [mul_assoc] using hh + +open _root_.Polynomial _root_.OAI.Polynomial in +lemma power_polynomial_mem {H : Filtration G} (e k : ℕ) (a : G) + (ha : a ∈ H.level (e+k)) (p : ℤ[X]) (hp : p.natDegree ≤ e) : + (fun n : ℤ => a ^ p.eval n) ∈ polynomials H k := by + induction e generalizing k p with + | zero => + have he : p = C (p.coeff 0) := eq_C_of_natDegree_eq_zero (Nat.eq_zero_of_le_zero hp) + rw [he] + simp only [eval_C] + apply const_mem + simpa only [Nat.zero_add] using (H.level (0+k)).zpow_mem ha (p.coeff 0) + | succ e ih => + apply mem_of_derivatives + · intro n + exact (H.level k).zpow_mem (H.antitone (Nat.le_add_left k (e+1)) ha) _ + · intro t + let q := taylor t p - p + have hq : q.natDegree ≤ e := by + by_cases hp0 : p = 0 + · simp [q,hp0] + by_cases hq0 : q = 0 + · simp [hq0] + have hd : q.degree < p.degree := + degree_sub_lt_right (degree_taylor p t) hp0 (leadingCoeff_taylor t p) + have hd' : q.natDegree < p.natDegree := (natDegree_lt_natDegree_iff hq0).mpr hd + omega + have ha' : a ∈ H.level (e+(k+1)) := by simpa only [Nat.add_assoc, Nat.add_comm, + Nat.add_left_comm] using ha + have h := ih (k+1) ha' q hq + convert h using 1 + funext n + change (a ^ p.eval n)⁻¹ * a ^ p.eval (n+t) = a ^ q.eval n + rw [← zpow_neg, ← zpow_add] + congr 1 + simp [q, taylor_apply, eval_comp] + ring + +end +end CubePolynomials + + + +namespace FilteredPET +noncomputable section +open scoped Pointwise + +section Multiset +variable {α : Type*} [DecidableEq α] + +lemma decrease_of_high_embedding (degree : α → ℕ) (S T : Finset α) + (a : α) (ha : a ∈ T) (f : α ↪ α) + (hf : ∀ x, degree (f x) = degree x) + (hhigh : ∀ x ∈ S, degree a ≤ degree x → x ∈ (T.erase a).map f) : + Multiset.IsDershowitzMannaLT (S.val.map degree) (T.val.map degree) := by + classical + let H := S.filter (fun x => degree a ≤ degree x) + let L := S.filter (fun x => ¬ degree a ≤ degree x) + let U := H.val.map degree + let V := L.val.map degree + let W := (T.erase a).val.map degree + have hH : H ⊆ (T.erase a).map f := by + intro x hx + exact hhigh x (Finset.mem_filter.mp hx).1 (Finset.mem_filter.mp hx).2 + have hUW : U ≤ W := by + have h := Multiset.map_le_map (f := degree) (Finset.val_le_iff.mpr hH) + simpa only [Finset.map_val, Multiset.map_map, Function.comp_def, hf] using h + have hS : S.val.map degree = U + V := by + have h := Multiset.filter_add_not (fun x => degree a ≤ degree x) S.val + dsimp [U, V, H, L] + rw [← Multiset.map_add] + exact congrArg (Multiset.map degree) h.symm + have hT : T.val.map degree = W + {degree a} := by + have hv : T.val = a ::ₘ (T.erase a).val := (Multiset.cons_erase ha).symm + rw [hv, Multiset.map_cons] + change degree a ::ₘ (T.erase a).val.map degree = (T.erase a).val.map degree + {degree a} + rw [add_comm, Multiset.singleton_add] + refine ⟨U, V, (W - U) + {degree a}, by simp, hS, ?_, ?_⟩ + · rw [hT, ← add_assoc, add_tsub_cancel_of_le hUW] + · intro y hy + obtain ⟨x, hx, rfl⟩ := Multiset.mem_map.mp hy + refine ⟨degree a, by simp, ?_⟩ + exact Nat.lt_of_not_ge (Finset.mem_filter.mp hx).2 + +end Multiset + +structure Filtration (G : Type*) [Group G] where + level : ℕ → Subgroup G + monotone : Monotone level + zero : level 0 = ⊥ + exhaustive : ∀ g, ∃ d, g ∈ level d + normal : ∀ d, (level d).Normal + +namespace Filtration +variable {G : Type*} [Group G] (F : Filtration G) +instance level_normal (d : ℕ) : (F.level d).Normal := F.normal d + +def degree (g : G) : ℕ := by + classical + exact Nat.find (F.exhaustive g) + +lemma degree_mem (g : G) : g ∈ F.level (F.degree g) := by + classical + exact Nat.find_spec (F.exhaustive g) + +lemma degree_le_iff (g : G) (d : ℕ) : F.degree g ≤ d ↔ g ∈ F.level d := by + classical + constructor + · intro h + exact F.monotone h (F.degree_mem g) + · exact Nat.find_min' (F.exhaustive g) + +@[simp] lemma degree_one : F.degree 1 = 0 := by + apply Nat.eq_zero_of_le_zero + exact (F.degree_le_iff 1 0).mpr (by simp [F.zero]) + +@[simp] lemma degree_eq_zero (g : G) : F.degree g = 0 ↔ g = 1 := by + rw [← Nat.le_zero, F.degree_le_iff, F.zero, Subgroup.mem_bot] + +lemma degree_pos (g : G) : 0 < F.degree g ↔ g ≠ 1 := by + rw [Nat.pos_iff_ne_zero, ne_eq, F.degree_eq_zero] + +lemma degree_mul_le (g h : G) : F.degree (g*h) ≤ max (F.degree g) (F.degree h) := by + apply (F.degree_le_iff _ _).mpr + exact (F.level _).mul_mem (F.monotone (le_max_left _ _) (F.degree_mem g)) + (F.monotone (le_max_right _ _) (F.degree_mem h)) + +@[simp] lemma degree_inv (g : G) : F.degree g⁻¹ = F.degree g := by + apply le_antisymm + · exact (F.degree_le_iff _ _).mpr ((F.level _).inv_mem (F.degree_mem g)) + · exact (F.degree_le_iff _ _).mpr (by simpa using (F.level _).inv_mem (F.degree_mem g⁻¹)) + +abbrev Signature := Σ d : ℕ, G ⧸ F.level (d-1) + +def signature (g : G) : F.Signature := + ⟨F.degree g, QuotientGroup.mk' (F.level (F.degree g - 1)) g⟩ + +lemma signature_at (g : G) (d : ℕ) (h : F.degree g = d) : + F.signature g = ⟨d, QuotientGroup.mk' (F.level (d-1)) g⟩ := by + subst d + rfl + +lemma degree_mul_eq_left {g h : G} (hh : F.degree h < F.degree g) : + F.degree (g*h) = F.degree g := by + apply le_antisymm + · exact (F.degree_mul_le g h).trans (max_le le_rfl hh.le) + · by_contra H + have H' : F.degree (g*h) ≤ F.degree g - 1 := by omega + have Hh : F.degree h ≤ F.degree g - 1 := by omega + have hg : g ∈ F.level (F.degree g - 1) := by + have := (F.level _).mul_mem ((F.degree_le_iff _ _).mp H') + ((F.level _).inv_mem ((F.degree_le_iff _ _).mp Hh)) + simpa only [mul_inv_cancel_right] using this + have := (F.degree_le_iff _ _).mpr hg + omega + +lemma degree_eq_of_lower {f g : G} (h : f*g⁻¹ ∈ F.level (F.degree g - 1)) : + F.degree f = F.degree g := by + by_cases hg : g = 1 + · subst g + simpa [F.zero] using h + have hd : 0 < F.degree g := (F.degree_pos g).mpr hg + have hfg : F.degree f ≤ F.degree g := by + apply (F.degree_le_iff _ _).mpr + have hprod := (F.level _).mul_mem + (F.monotone (Nat.sub_le _ _) h) (F.degree_mem g) + simpa only [inv_mul_cancel_right] using hprod + apply le_antisymm hfg + by_contra H + have H' : F.degree f ≤ F.degree g - 1 := by omega + have hgv : g ∈ F.level (F.degree g - 1) := by + have hprod := (F.level _).mul_mem ((F.level _).inv_mem h) + ((F.degree_le_iff _ _).mp H') + simpa only [mul_inv_rev, inv_inv, mul_assoc, inv_mul_cancel, mul_one] using hprod + have := (F.degree_le_iff _ _).mpr hgv + omega + +lemma signature_eq_of_lower {f g : G} (h : f*g⁻¹ ∈ F.level (F.degree g - 1)) : + F.signature f = F.signature g := by + have hd := F.degree_eq_of_lower h + rw [F.signature_at f (F.degree g) hd] + change (⟨F.degree g, QuotientGroup.mk' (F.level (F.degree g-1)) f⟩ : F.Signature) = + ⟨F.degree g, QuotientGroup.mk' (F.level (F.degree g-1)) g⟩ + congr 1 + apply (mul_inv_eq_one).mp + rw [← map_inv, ← map_mul] + change ((f*g⁻¹ : G) : G ⧸ F.level (F.degree g-1)) = 1 + simpa only [QuotientGroup.eq_one_iff] using h + + + +def leaderShift (d : ℕ) (a : G) : F.Signature ≃ F.Signature where + toFun x := ⟨x.1, if x.1 = d then x.2 * + (QuotientGroup.mk' (F.level (x.1-1)) a)⁻¹ else x.2⟩ + invFun x := ⟨x.1, if x.1 = d then x.2 * + QuotientGroup.mk' (F.level (x.1-1)) a else x.2⟩ + left_inv := by rintro ⟨k,x⟩; by_cases hk : k = d <;> simp [hk] + right_inv := by rintro ⟨k,x⟩; by_cases hk : k = d <;> simp [hk] + +@[simp] lemma leaderShift_degree (d : ℕ) (a : G) (x : F.Signature) : + (F.leaderShift d a x).1 = x.1 := rfl + +lemma quotient_eq_one_iff (d : ℕ) (g : G) : + QuotientGroup.mk' (F.level d) g = 1 ↔ F.degree g ≤ d := by + change (g : G ⧸ F.level d) = 1 ↔ F.degree g ≤ d + rw [QuotientGroup.eq_one_iff, F.degree_le_iff] + +lemma signature_mul_high {g a : G} (ha : F.degree a < F.degree g) : + F.signature (g*a⁻¹) = F.signature g := by + apply F.signature_eq_of_lower + have ha' : a⁻¹ ∈ F.level (F.degree g - 1) := by + apply (F.level _).inv_mem + exact (F.degree_le_iff _ _).mp (by omega) + exact (F.normal _).conj_mem _ ha' g + +lemma signature_mul_equal {g a : G} (hg : F.degree g = F.degree a) (h : F.degree a ≤ F.degree (g*a⁻¹)) : + F.signature (g*a⁻¹) = F.leaderShift (F.degree a) a (F.signature g) := by + have hd : F.degree (g*a⁻¹) = F.degree a := + le_antisymm (by simpa [hg] using F.degree_mul_le g a⁻¹) h + rw [F.signature_at (g*a⁻¹) (F.degree a) hd, + F.signature_at g (F.degree a) hg] + change (⟨F.degree a, QuotientGroup.mk' (F.level (F.degree a-1)) (g*a⁻¹)⟩ : F.Signature) = + ⟨F.degree a, if F.degree a = F.degree a then + QuotientGroup.mk' (F.level (F.degree a-1)) g * + (QuotientGroup.mk' (F.level (F.degree a-1)) a)⁻¹ else + QuotientGroup.mk' (F.level (F.degree a-1)) g⟩ + simp only [ite_true, map_mul, map_inv] + +lemma signature_eq_lower {f g : G} (h : F.signature f = F.signature g) : + f*g⁻¹ ∈ F.level (F.degree g-1) := by + have hd : F.degree f = F.degree g := congrArg Sigma.fst h + rw [F.signature_at f (F.degree g) hd] at h + have hq : QuotientGroup.mk' (F.level (F.degree g-1)) f = + QuotientGroup.mk' (F.level (F.degree g-1)) g := eq_of_heq (Sigma.mk.inj h).2 + apply (QuotientGroup.eq_one_iff _).mp + rw [QuotientGroup.mk_mul, QuotientGroup.mk_inv] + change QuotientGroup.mk' (F.level (F.degree g-1)) f * + (QuotientGroup.mk' (F.level (F.degree g-1)) g)⁻¹ = 1 + rw [hq, mul_inv_cancel] + + + +lemma reduction_signature {q p a : G} (hmin : F.degree a ≤ F.degree p) + (hd : q*a*p⁻¹ ∈ F.level (F.degree p-1)) + (hq : F.degree a ≤ F.degree q) : + F.signature q = F.leaderShift (F.degree a) a (F.signature p) := by + have hs : F.signature (q*a) = F.signature p := F.signature_eq_of_lower hd + have hdeg : F.degree (q*a) = F.degree p := congrArg Sigma.fst hs + rcases lt_or_eq_of_le hmin with hlt | heq + · have hh : F.signature ((q*a)*a⁻¹) = F.signature (q*a) := + F.signature_mul_high (by omega) + rw [show (q*a)*a⁻¹ = q by group, hs] at hh + rw [hh] + simp only [leaderShift, signature, Equiv.coe_fn_mk, ite_eq_right (Nat.ne_of_gt hlt)] + · have hh := F.signature_mul_equal (g := q*a) (a := a) (hdeg.trans heq.symm) + (by simpa only [mul_inv_cancel_right] using hq) + simpa only [mul_inv_cancel_right, hs] using hh + +lemma reduction_same {q p a : G} (ha : 0 < F.degree a) + (hp : F.signature p = F.signature a) + (hd : q*a*p⁻¹ ∈ F.level (F.degree p-1)) : F.degree q < F.degree a := by + have he : F.degree p = F.degree a := congrArg Sigma.fst hp + have hpa := F.signature_eq_lower hp + have hmul := (F.level (F.degree a-1)).mul_mem (he ▸ hd) hpa + have hconj : q ∈ F.level (F.degree a-1) := by + rwa [show (q*a*p⁻¹)*(p*a⁻¹) = q by group] at hmul + have hh := (F.degree_le_iff q _).mpr hconj + omega + +def leaders (P : Finset G) : Finset F.Signature := by + classical + exact (P.erase 1).image F.signature + +def weight (P : Finset G) : Multiset ℕ := (F.leaders P).val.map Sigma.fst + + + +theorem weight_lt (P Q : Finset G) (a : G) (haP : a ∈ P) (ha : a ≠ 1) + (hmin : ∀ p ∈ P, F.degree a ≤ F.degree p) + (hQ : ∀ q ∈ Q, ∃ p ∈ P, q*a*p⁻¹ ∈ F.level (F.degree p-1)) : + Multiset.IsDershowitzMannaLT (F.weight Q) (F.weight P) := by + classical + have hapos := (F.degree_pos a).mpr ha + have hamem : F.signature a ∈ F.leaders P := + Finset.mem_image.mpr ⟨a, Finset.mem_erase.mpr ⟨ha,haP⟩,rfl⟩ + apply decrease_of_high_embedding Sigma.fst (F.leaders Q) (F.leaders P) + (F.signature a) hamem (F.leaderShift (F.degree a) a).toEmbedding + (F.leaderShift_degree _ _) + intro x hx hxhigh + obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨p,hp,hd⟩ := hQ q (Finset.mem_erase.mp hq).2 + have hplead : F.signature p ≠ F.signature a := by + intro heq + exact (Nat.not_le_of_gt (F.reduction_same hapos heq hd)) hxhigh + apply Finset.mem_map.mpr + refine ⟨F.signature p, Finset.mem_erase.mpr ⟨hplead, ?_⟩, ?_⟩ + · apply Finset.mem_image.mpr + refine ⟨p, Finset.mem_erase.mpr ⟨?_,hp⟩,rfl⟩ + intro hh + have := hmin p hp + simp only [hh, F.degree_one] at this + omega + · exact (F.reduction_signature (hmin p hp) hd hxhigh).symm + +end Filtration +end +end FilteredPET +namespace GroupPET +noncomputable section +variable (G S : Type*) [Group G] [Group S] + + + +structure System where + filtration : FilteredPET.Filtration S + eval : ℤ → S →* G + eval_zero : ∀ p, eval 0 p = 1 + shift : S → ℤ → S + shift_eval : ∀ p n k, eval k (shift p n) = (eval n p)⁻¹ * eval (n+k) p + shift_lower : ∀ p n, shift p n * p⁻¹ ∈ filtration.level (filtration.degree p-1) + conjugate : G → S → S + conjugate_eval : ∀ g p k, eval k (conjugate g p) = g⁻¹ * eval k p * g + conjugate_lower : ∀ g p, conjugate g p * p⁻¹ ∈ filtration.level (filtration.degree p-1) + +variable {G S} +namespace System +variable (T : System G S) + +def reduce (p a : S) (n : ℤ) : S := T.shift p n * a⁻¹ + +def reducedFamily (P : Finset S) (a : S) (I : Finset ℤ) : Finset S := by + classical + exact (P ×ˢ I).image (fun pn => T.reduce pn.1 a pn.2) + +lemma reduce_eval (p a : S) (n k : ℤ) : + T.eval k (T.reduce p a n) = (T.eval n p)⁻¹ * T.eval (n+k) p * (T.eval k a)⁻¹ := by + simp only [reduce, map_mul, map_inv, T.shift_eval] + +lemma reducedFamily_weight_lt (P : Finset S) (a : S) (I : Finset ℤ) + (haP : a ∈ P) (ha : a ≠ 1) + (hmin : ∀ p ∈ P, T.filtration.degree a ≤ T.filtration.degree p) : + Multiset.IsDershowitzMannaLT (T.filtration.weight (T.reducedFamily P a I)) + (T.filtration.weight P) := by + classical + apply T.filtration.weight_lt P _ a haP ha hmin + intro q hq + obtain ⟨⟨p,n⟩,hpn,rfl⟩ := Finset.mem_image.mp hq + refine ⟨p,(Finset.mem_product.mp hpn).1,?_⟩ + simpa only [reduce, inv_mul_cancel_right] using T.shift_lower p n + +lemma conjugate_signature (g : G) (p : S) : + T.filtration.signature (T.conjugate g p) = T.filtration.signature p := + T.filtration.signature_eq_of_lower (T.conjugate_lower g p) + +lemma conjugate_eq_one_iff (g : G) (p : S) : T.conjugate g p = 1 ↔ p = 1 := by + have hd : T.filtration.degree (T.conjugate g p) = T.filtration.degree p := + congrArg Sigma.fst (T.conjugate_signature g p) + rw [← T.filtration.degree_eq_zero, ← T.filtration.degree_eq_zero, hd] + +def conjugateFamily (P : Finset S) (I : Finset G) : Finset S := by + classical + exact (P ×ˢ I).image (fun pg => T.conjugate pg.2 pg.1) + +lemma conjugateFamily_leaders (P : Finset S) (I : Finset G) (hI : I.Nonempty) : + T.filtration.leaders (T.conjugateFamily P I) = T.filtration.leaders P := by + classical + ext x + constructor + · intro hx + obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨⟨p,g⟩,hpg,rfl⟩ := Finset.mem_image.mp (Finset.mem_erase.mp hq).2 + rw [T.conjugate_signature] + apply Finset.mem_image.mpr + refine ⟨p, Finset.mem_erase.mpr ⟨?_,(Finset.mem_product.mp hpg).1⟩,rfl⟩ + exact (T.conjugate_eq_one_iff g p).not.mp (Finset.mem_erase.mp hq).1 + · intro hx + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨g,hg⟩ := hI + apply Finset.mem_image.mpr + refine ⟨T.conjugate g p, Finset.mem_erase.mpr ⟨?_,?_⟩, T.conjugate_signature g p⟩ + · exact (T.conjugate_eq_one_iff g p).not.mpr (Finset.mem_erase.mp hp).1 + · exact Finset.mem_image.mpr ⟨(p,g), Finset.mem_product.mpr + ⟨(Finset.mem_erase.mp hp).2,hg⟩,rfl⟩ + +lemma conjugateFamily_weight (P : Finset S) (I : Finset G) (hI : I.Nonempty) : + T.filtration.weight (T.conjugateFamily P I) = T.filtration.weight P := by + simp only [FilteredPET.Filtration.weight, T.conjugateFamily_leaders P I hI] + +end System +end +end GroupPET +namespace MinimalSubsystem +variable {M X : Type*} [Monoid M] [TopologicalSpace X] [MulAction M X] + [ContinuousConstSMul M X] [CompactSpace X] [Nonempty X] + +omit [ContinuousConstSMul M X] in +@[to_additive exists_closed_minimal_add] +theorem exists_closed_minimal : + ∃ S : Set X, Minimal (fun A : Set X => + IsClosed A ∧ A.Nonempty ∧ ∀ g : M, ∀ x ∈ A, g • x ∈ A) S := by + classical + let F : Set (Set X) := {A | IsClosed A ∧ A.Nonempty ∧ ∀ g : M, ∀ x ∈ A, g • x ∈ A} + have H : ∀ c ⊆ F, IsChain (· ⊆ ·) c → c.Nonempty → + ∃ lb ∈ F, ∀ A ∈ c, lb ⊆ A := by + intro c hc hchain hne + have : Nonempty c := hne.to_subtype + refine ⟨⋂₀ c, ⟨?_, ?_, ?_⟩, fun A hA => Set.sInter_subset_of_mem hA⟩ + · exact isClosed_sInter (fun A hA => (hc hA).1) + · exact IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed + (by + intro A hA B hB + rcases hchain.total hA hB with hAB | hBA + · exact ⟨A, hA, Set.Subset.rfl, hAB⟩ + · exact ⟨B, hB, hBA, Set.Subset.rfl⟩) (fun A hA => (hc hA).2.1) + (fun A hA => (hc hA).1.isCompact) (fun A hA => (hc hA).1) + · intro g x hx + apply Set.mem_sInter.mpr + intro A hA + exact (hc hA).2.2 g x (Set.mem_sInter.mp hx A hA) + obtain ⟨S, _, hS⟩ := zorn_superset_nonempty F H Set.univ + ⟨isClosed_univ, Set.univ_nonempty, by simp⟩ + exact ⟨S, hS⟩ + +@[to_additive exists_minimal_subaddaction] +theorem exists_minimal_subaction : + ∃ S : SubMulAction M X, IsClosed (S : Set X) ∧ Nonempty S ∧ MulAction.IsMinimal M S := by + classical + obtain ⟨A, hA⟩ := exists_closed_minimal (M := M) (X := X) + let S : SubMulAction M X := ⟨A, fun g _ hx => hA.1.2.2 g _ hx⟩ + have hSc : IsClosed (S : Set X) := hA.1.1 + have : ContinuousConstSMul M S := ⟨fun g => + ((continuous_const_smul g).comp continuous_subtype_val).subtype_mk _⟩ + refine ⟨S, hSc, hA.1.2.1.to_subtype, ?_⟩ + apply (isMinimal_iff_isClosed_smul_invariant M (α := S)).mpr + intro B hBc hBinv + rcases B.eq_empty_or_nonempty with hBe | hBne + · exact Or.inl hBe + · right + have hImg : IsClosed (Subtype.val '' B : Set X) ∧ + (Subtype.val '' B : Set X).Nonempty ∧ + ∀ g : M, ∀ x ∈ (Subtype.val '' B : Set X), g • x ∈ (Subtype.val '' B : Set X) := by + refine ⟨hSc.isClosedMap_subtype_val B hBc, hBne.image _, ?_⟩ + intro g x hx + obtain ⟨y, hy, rfl⟩ := hx + exact ⟨g • y, hBinv g ⟨y,hy,rfl⟩, rfl⟩ + have hsub : (Subtype.val '' B : Set X) ⊆ A := by + rintro x ⟨y, _, rfl⟩ + exact y.2 + have hEq := hA.eq_of_le hImg hsub + apply Set.eq_univ_of_forall + intro x + have hx : (x : X) ∈ (Subtype.val '' B : Set X) := by rw [hEq]; exact x.2 + obtain ⟨y, hy, heq⟩ := hx + exact (Subtype.ext heq) ▸ hy + +end MinimalSubsystem + +namespace GroupPETRecurrence +open GroupPET System +noncomputable section +variable {G S X : Type*} [Group G] [Group S] [TopologicalSpace X] [MulAction G X] + [ContinuousConstSMul G X] (T : System G S) + + + +def ClopenRecurrence (P : Finset S) : Prop := + ∀ U : Set X, IsClopen U → U.Nonempty → ∀ N : ℕ, + ∃ k : ℕ, N < k ∧ ∃ x ∈ U, ∀ p ∈ P, T.eval (k : ℤ) p • x ∈ U + +variable {C : Type*} [Fintype C] [TopologicalSpace C] [DiscreteTopology C] + +def Focused (P : Finset S) (χ : X → C) (N : ℕ) {n : ℕ} + (t : Fin n → ℕ) (x : Fin n → X) : Prop := + (∀ i j, i < j → N + t i < t j) ∧ + ∀ i j, i ≤ j → ∀ p ∈ P, + χ (T.eval ((t j : ℤ) - (t i : ℤ)) p • x j) = χ (x i) + +omit [TopologicalSpace X] [ContinuousConstSMul G X] [Fintype C] + [TopologicalSpace C] [DiscreteTopology C] in +lemma Focused.monotone {P : Finset S} {χ : X → C} {N n : ℕ} + {t : Fin n → ℕ} {x : Fin n → X} (h : Focused T P χ N t x) : Monotone t := by + intro i j hij + rcases lt_or_eq_of_le hij with hlt | rfl + · exact le_trans (Nat.le_add_left _ _) (h.1 i j hlt).le + · rfl + +omit [TopologicalSpace X] [ContinuousConstSMul G X] [Fintype C] + [TopologicalSpace C] [DiscreteTopology C] in +lemma focused_singleton (P : Finset S) (χ : X → C) (N : ℕ) + (hP : ∀ p ∈ P, T.eval 0 p = 1) (x : X) : + Focused T P χ N (fun _ : Fin 1 => 0) (fun _ => x) := by + constructor + · intro i j hij + have : i = j := Subsingleton.elim _ _ + subst j + exact (lt_irrefl _ hij).elim + · intro i j _ p hp + simp [hP p hp] + +omit [Fintype C] in + +lemma focused_extend (P : Finset S) (p₀ : S) + (hP : ∀ p ∈ P, T.eval 0 p = 1) + (ih : ∀ I : Finset ℤ, ClopenRecurrence T (X := X) (T.reducedFamily P p₀ I)) + (χ : X → C) (hχ : Continuous χ) (N n : ℕ) + (t : Fin (n+1) → ℕ) (x : Fin (n+1) → X) (hf : Focused T P χ N t x) : + ∃ (t' : Fin (n+2) → ℕ) (x' : Fin (n+2) → X), Focused T P χ N t' x' := by + classical + let lastTime := t (Fin.last n) + let offsets : Fin (n+1) → ℤ := fun i => (lastTime : ℤ) - (t i : ℤ) + let I := Finset.univ.image offsets + let Q := T.reducedFamily P p₀ I + let profile : X → (Fin (n+1) × {p // p ∈ P} → C) := + fun y ip => χ (T.eval (offsets ip.1) ip.2.1 • y) + have hprofile : Continuous profile := by + apply continuous_pi + intro ip + exact hχ.comp (continuous_const_smul _) + let U := profile ⁻¹' {profile (x (Fin.last n))} + have hU : IsClopen U := (isClopen_discrete _).preimage hprofile + have hxU : x (Fin.last n) ∈ U := rfl + obtain ⟨k, hk, y, hy, hyQ⟩ := ih I U hU ⟨_, hxU⟩ N + let time := lastTime + k + let point := (T.eval (k : ℤ) p₀)⁻¹ • y + refine ⟨Fin.snoc t time, Fin.snoc x point, ?_, ?_⟩ + · intro i j + refine Fin.lastCases ?_ (fun j => ?_) j + · refine Fin.lastCases ?_ (fun i => ?_) i + · intro hij + exact (lt_irrefl _ hij).elim + · intro _ + simp only [Fin.snoc_castSucc, Fin.snoc_last] + have hti := Focused.monotone T hf (Fin.le_last i) + change t i ≤ lastTime at hti + omega + · refine Fin.lastCases ?_ (fun i => ?_) i + · intro hij + exact (not_lt_of_ge (Fin.le_last _) hij).elim + · intro hij + simp only [Fin.snoc_castSucc] + exact hf.1 i j (by simpa using hij) + · intro i j + refine Fin.lastCases ?_ (fun j => ?_) j + · refine Fin.lastCases ?_ (fun i => ?_) i + · intro _ p hp + simp only [Fin.snoc_last, sub_self, hP p hp, one_smul] + · intro _ p hp + simp only [Fin.snoc_castSucc, Fin.snoc_last] + have hqQ : T.reduce p p₀ (offsets i) ∈ Q := by + apply Finset.mem_image.mpr + refine ⟨(p, offsets i), Finset.mem_product.mpr ⟨hp, ?_⟩, rfl⟩ + exact Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩ + have hcolor := congrFun (hyQ _ hqQ) (i, ⟨p,hp⟩) + change χ (T.eval (offsets i) p • + (T.eval (k : ℤ) (T.reduce p p₀ (offsets i)) • y)) = + χ (T.eval (offsets i) p • x (Fin.last n)) at hcolor + rw [hf.2 i (Fin.last n) (Fin.le_last i) p hp] at hcolor + convert hcolor using 1 + dsimp [point] + rw [← mul_smul, ← mul_smul] + congr 2 + rw [T.reduce_eval] + have harg : ((time : ℕ) : ℤ) - (t i : ℤ) = offsets i + (k : ℤ) := by + dsimp [time, offsets] + ring + rw [harg] + group + · refine Fin.lastCases ?_ (fun i => ?_) i + · intro hij + have := Fin.last_le_iff.mp hij + exact (Fin.castSucc_ne_last j this).elim + · intro hij p hp + simp only [Fin.snoc_castSucc] + exact hf.2 i j (by simpa using hij) p hp + +omit [Fintype C] in +lemma focused_arbitrary [Nonempty X] (P : Finset S) (p₀ : S) + (hP : ∀ p ∈ P, T.eval 0 p = 1) + (ih : ∀ I : Finset ℤ, ClopenRecurrence T (X := X) (T.reducedFamily P p₀ I)) + (χ : X → C) (hχ : Continuous χ) (N n : ℕ) : + ∃ (t : Fin (n+1) → ℕ) (x : Fin (n+1) → X), Focused T P χ N t x := by + induction n with + | zero => + exact ⟨_, _, focused_singleton T P χ N hP (Classical.choice inferInstance)⟩ + | succ n ihn => + obtain ⟨t, x, hf⟩ := ihn + exact focused_extend T P p₀ hP ih χ hχ N n t x hf + +lemma monochromatic_of_lower [Nonempty X] (P : Finset S) (p₀ : S) + (hP : ∀ p ∈ P, T.eval 0 p = 1) + (ih : ∀ I : Finset ℤ, ClopenRecurrence T (X := X) (T.reducedFamily P p₀ I)) + (χ : X → C) (hχ : Continuous χ) (N : ℕ) : + ∃ k : ℕ, N < k ∧ ∃ x : X, ∀ p ∈ P, χ (T.eval (k : ℤ) p • x) = χ x := by + classical + obtain ⟨t, x, hf⟩ := focused_arbitrary T P p₀ hP ih χ hχ N (Fintype.card C) + have hni : ¬Function.Injective (fun i => χ (x i)) := by + intro hinj + have hcard := Fintype.card_le_of_injective _ hinj + simp only [Fintype.card_fin] at hcard + omega + obtain ⟨i, j, heq, hne⟩ := Function.not_injective_iff.mp hni + have finish (i j : Fin (Fintype.card C + 1)) (hij : i < j) (heq : χ (x i) = χ (x j)) : + ∃ k : ℕ, N < k ∧ ∃ x : X, ∀ p ∈ P, χ (T.eval (k : ℤ) p • x) = χ x := by + have htimes := hf.1 i j hij + refine ⟨t j - t i, by omega, x j, ?_⟩ + intro p hp + rw [Nat.cast_sub (Focused.monotone T hf hij.le)] + exact (hf.2 i j hij.le p hp).trans heq + rcases lt_or_gt_of_ne hne with hij | hji + · exact finish i j hij heq + · exact finish j i hji heq.symm + + + +theorem clopen_polynomial_recurrence [CompactSpace X] [MulAction.IsMinimal G X] + (P : Finset S) : ClopenRecurrence T (X := X) P := by + classical + suffices H : ∀ w : Multiset ℕ, ∀ P : Finset S, T.filtration.weight P = w → + ClopenRecurrence T (X := X) P from H (T.filtration.weight P) P rfl + intro w + apply (Multiset.wellFounded_isDershowitzMannaLT (α := ℕ)).induction w + intro w ih P hw + let A := P.erase 1 + have hwA : T.filtration.weight A = w := by + simpa [FilteredPET.Filtration.weight, FilteredPET.Filtration.leaders,A] using hw + have hrecA : ClopenRecurrence T (X := X) A := by + intro U hU hUne N + have : Nonempty X := ⟨hUne.choose⟩ + by_cases hA : A.Nonempty + · obtain ⟨I,hI⟩ := isCompact_univ.elim_finite_subcover + (fun g : G => (g • ·) ⁻¹' U) + (fun g => hU.2.preimage (continuous_const_smul g)) + (by rw [hU.2.iUnion_preimage_smul G hUne]) + let Q := T.conjugateFamily A (insert 1 I) + have hwQ : T.filtration.weight Q = w := + (T.conjugateFamily_weight A _ (Finset.insert_nonempty 1 I)).trans hwA + have hQ : Q.Nonempty := by + obtain ⟨p,hp⟩ := hA + exact ⟨T.conjugate 1 p, Finset.mem_image.mpr ⟨(p,1), + Finset.mem_product.mpr ⟨hp,Finset.mem_insert_self 1 I⟩,rfl⟩⟩ + obtain ⟨a,ha,hmin⟩ := Q.exists_min_image T.filtration.degree hQ + have ha1 : a ≠ 1 := by + obtain ⟨⟨p,g⟩,hpg,rfl⟩ := Finset.mem_image.mp ha + exact (T.conjugate_eq_one_iff g p).not.mpr + (Finset.mem_erase.mp (Finset.mem_product.mp hpg).1).1 + let χ : X → (I → Fin 2) := fun x g => + LocallyConstant.ofIsClopen (hU.preimage (continuous_const_smul (g : G))) x + have hχ : Continuous χ := continuous_pi fun _ => LocallyConstant.continuous _ + have hsmall : ∀ J : Finset ℤ, ClopenRecurrence T (X := X) (T.reducedFamily Q a J) := by + intro J + exact ih _ (hwQ ▸ T.reducedFamily_weight_lt Q a J ha ha1 hmin) _ rfl + obtain ⟨k,hk,x,hx⟩ := monochromatic_of_lower T Q a (fun p _ => T.eval_zero p) + hsmall χ hχ N + obtain ⟨g,hgI,hgx⟩ := Set.mem_iUnion₂.mp (hI (Set.mem_univ x)) + have hmem (y : X) : χ y ⟨g,hgI⟩ = 0 ↔ g • y ∈ U := by + simp [χ, LocallyConstant.ofIsClopen] + refine ⟨k,hk,g • x,hgx,?_⟩ + intro p hp + have hq : T.conjugate g p ∈ Q := Finset.mem_image.mpr + ⟨(p,g),Finset.mem_product.mpr ⟨hp,Finset.mem_insert_of_mem hgI⟩,rfl⟩ + have hcolor := congrFun (hx _ hq) ⟨g,hgI⟩ + have hpy := (hmem _).mp (hcolor.trans ((hmem x).mpr hgx)) + rw [T.conjugate_eval] at hpy + simpa only [mul_smul, inv_smul_smul, smul_inv_smul] using hpy + · obtain ⟨x,hx⟩ := hUne + refine ⟨N+1,Nat.lt_succ_self _,x,hx,?_⟩ + intro p hp + exact (hA ⟨p,hp⟩).elim + intro U hU hUne N + obtain ⟨k,hk,x,hx,hAx⟩ := hrecA U hU hUne N + refine ⟨k,hk,x,hx,?_⟩ + intro p hp + by_cases hp1 : p = 1 + · simpa [hp1] using hx + · exact hAx p (Finset.mem_erase.mpr ⟨hp1,hp⟩) + +omit [Fintype C] in + + +theorem continuous_polynomial_recurrence [CompactSpace X] [Nonempty X] + (P : Finset S) + (χ : X → C) (hχ : Continuous χ) (N : ℕ) : + ∃ k : ℕ, N < k ∧ ∃ x : X, ∀ p ∈ P, χ (T.eval (k : ℤ) p • x) = χ x := by + classical + obtain ⟨S,hSc,hSne,hSmin⟩ := + MinimalSubsystem.exists_minimal_subaction (M := G) (X := X) + have : Nonempty S := hSne + have : CompactSpace S := isCompact_iff_compactSpace.mp hSc.isCompact + have : MulAction.IsMinimal G S := hSmin + have : ContinuousConstSMul G S := ⟨fun g => + ((continuous_const_smul g).comp continuous_subtype_val).subtype_mk _⟩ + let x : S := Classical.choice hSne + let U : Set S := (fun y : S => χ y) ⁻¹' {χ x} + have hU : IsClopen U := (isClopen_discrete _).preimage (hχ.comp continuous_subtype_val) + have hx : x ∈ U := rfl + obtain ⟨k,hk,y,hy,hPy⟩ := clopen_polynomial_recurrence T P U hU ⟨x,hx⟩ N + refine ⟨k,hk,y,?_⟩ + intro p hp + exact (hPy p hp).trans hy.symm + +omit [TopologicalSpace X] [MulAction G X] [ContinuousConstSMul G X] in + + +theorem coloring_polynomial_recurrence + (P : Finset S) + (χ : G → C) (N : ℕ) : + ∃ k : ℕ, N < k ∧ ∃ a : G, ∀ p ∈ P, χ (T.eval (k : ℤ) p * a) = χ a := by + classical + let : MulAction G (G → C) := { + smul := fun a f b => f (b*a) + one_smul := fun f => by + funext b + exact congrArg f (mul_one b) + mul_smul := fun a b f => by + funext c + exact congrArg f (mul_assoc c a b).symm } + have : ContinuousConstSMul G (G → C) := ⟨fun a => + continuous_pi fun b => continuous_apply (b*a)⟩ + let S : SubMulAction G (G → C) := { + carrier := closure (MulAction.orbit G χ) + smul_mem' := fun a f hf => smul_closure_orbit_subset a χ ⟨f,hf,rfl⟩ } + have hSclosed : IsClosed (S : Set (G → C)) := isClosed_closure + have : CompactSpace S := isCompact_iff_compactSpace.mp hSclosed.isCompact + have : Nonempty S := ⟨⟨χ,subset_closure (MulAction.mem_orbit_self χ)⟩⟩ + have : ContinuousConstSMul G S := ⟨fun a => + ((continuous_const_smul a).comp continuous_subtype_val).subtype_mk _⟩ + let eval₀ : S → C := fun f => f.1 1 + have heval : Continuous eval₀ := (continuous_apply 1).comp continuous_subtype_val + obtain ⟨k,hk,ψ,hψ⟩ := continuous_polynomial_recurrence T P eval₀ heval N + let I : Finset G := insert 1 (P.image (fun p => T.eval (k : ℤ) p)) + let profile : (G → C) → (I → C) := fun f i => f i + let U := profile ⁻¹' {profile ψ.1} + have hprofile : Continuous profile := continuous_pi fun i : I => continuous_apply (i : G) + have hU : IsOpen U := (isOpen_discrete ({profile ψ.1} : Set (I → C))).preimage hprofile + have hψU : ψ.1 ∈ U := rfl + obtain ⟨ζ,hζU,hζorb⟩ := mem_closure_iff.mp ψ.2 U hU hψU + obtain ⟨a,rfl⟩ := hζorb + refine ⟨k,hk,a,?_⟩ + intro p hp + have hpI : T.eval (k : ℤ) p ∈ I := Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨p,hp,rfl⟩) + have hzI : (1 : G) ∈ I := Finset.mem_insert_self _ _ + have hcp := congrFun hζU ⟨T.eval (k : ℤ) p,hpI⟩ + have hcz := congrFun hζU ⟨1,hzI⟩ + change χ (T.eval (k : ℤ) p * a) = ψ.1 (T.eval (k : ℤ) p) at hcp + change χ (1*a) = ψ.1 1 at hcz + have hpp := hψ p hp + change ψ.1 (1 * T.eval (k : ℤ) p) = ψ.1 1 at hpp + simp only [one_mul] at hpp hcz + exact hcp.trans (hpp.trans hcz.symm) + +end +end GroupPETRecurrence + +namespace CubePolynomials +open _root_.OAI.ConstructedWordPlan.CubeFaces +noncomputable section +variable {G : Type*} [Group G] + +def evaluation (n : ℤ) : (ℤ → G) →* G where + toFun f := f n + map_one' := rfl + map_mul' _ _ := rfl + +def normalized (H : Filtration G) (k : ℕ) : Subgroup (ℤ → G) := + polynomials H k ⊓ (evaluation 0).ker + +lemma mem_normalized (H : Filtration G) (k : ℕ) (f : ℤ → G) : + f ∈ normalized H k ↔ f ∈ polynomials H k ∧ f 0 = 1 := Iff.rfl + +lemma normalized_antitone (H : Filtration G) : Antitone (normalized H) := by + intro i j hij f hf + exact ⟨polynomials_antitone H hij hf.1,hf.2⟩ + +lemma normalized_normalizes (H : Filtration G) (k : ℕ) : + normalized H 0 ≤ Subgroup.normalizer (normalized H k) := by + intro f hf + rw [mem_normalized] at hf + apply Subgroup.mem_normalizer_iff.mpr + intro g + rw [mem_normalized, mem_normalized] + constructor + · intro hg + refine ⟨(Subgroup.mem_normalizer_iff.mp (normalizes H k hf.1) g).mp hg.1,?_⟩ + change f 0 * g 0 * (f 0)⁻¹ = 1 + rw [hg.2, mul_one, mul_inv_cancel] + · intro hg + refine ⟨(Subgroup.mem_normalizer_iff.mp (normalizes H k hf.1) g).mpr hg.1,?_⟩ + have hz := hg.2 + change f 0 * g 0 * (f 0)⁻¹ = 1 at hz + simpa only [hf.2, one_mul, inv_one, mul_one] using hz + +def reversedFiltration (H : Filtration G) (L : ℕ) (hL : H.level L = ⊥) : + FilteredPET.Filtration (normalized H 0) where + level d := (normalized H (L-d)).subgroupOf (normalized H 0) + monotone := by + intro d e hde f hf + exact normalized_antitone H (Nat.sub_le_sub_left hde L) hf + zero := by + apply le_antisymm _ bot_le + intro f hf + apply Subgroup.mem_bot.mpr + apply Subtype.ext + change (f : ℤ → G) ∈ normalized H (L-0) at hf + rw [mem_normalized, Nat.sub_zero, polynomials_eq_bot hL] at hf + exact Subgroup.mem_bot.mp hf.1 + exhaustive := by + intro f + refine ⟨L,?_⟩ + change (f : ℤ → G) ∈ normalized H (L-L) + simpa only [Nat.sub_self] using f.2 + normal := by + intro d + constructor + intro f hf g + have hg := normalized_normalizes H (L-d) g.2 + exact (Subgroup.mem_normalizer_iff.mp hg f).mp hf + +def normalizeShift (f : ℤ → G) (t : ℤ) : ℤ → G := fun n => (f t)⁻¹ * f (n+t) + +lemma normalizeShift_mem {H : Filtration G} {k : ℕ} {f : ℤ → G} + (hf : f ∈ normalized H k) (t : ℤ) : normalizeShift f t ∈ normalized H k := by + rw [mem_normalized] at hf ⊢ + constructor + · have hc := const_mem ((H.level k).inv_mem (eval_mem hf.1 t)) + exact (polynomials H k).mul_mem hc (shift_mem hf.1 t) + · change (f t)⁻¹ * f (0+t) = 1 + simp + +lemma normalizeShift_lower {H : Filtration G} {k : ℕ} {f : ℤ → G} + (hf : f ∈ normalized H k) (t : ℤ) : + normalizeShift f t * f⁻¹ ∈ normalized H (k+1) := by + rw [mem_normalized] at hf ⊢ + have hd := derivative_mem hf.1 t + have hv : f t ∈ H.level (k+1) := by + have hv := eval_mem hd 0 + change (f 0)⁻¹ * f (0+t) ∈ H.level (k+1) at hv + simpa only [hf.2,inv_one,one_mul,zero_add] using hv + have hn := (Subgroup.mem_normalizer_iff.mp + (normalizes H (k+1) (polynomials_antitone H (Nat.zero_le k) hf.1)) + (f⁻¹ * shift t f)).mp hd + have hc := const_mem ((H.level (k+1)).inv_mem hv) + have he : normalizeShift f t * f⁻¹ = (fun _ : ℤ => (f t)⁻¹) * + (f * (f⁻¹ * shift t f) * f⁻¹) := by + ext n + change (f t)⁻¹ * f (n+t) * (f n)⁻¹ = (f t)⁻¹ * (f n * ((f n)⁻¹ * f (n+t)) * (f n)⁻¹) + group + constructor + · rw [he] + exact (polynomials H (k+1)).mul_mem hc hn + · change ((f t)⁻¹ * f (0+t)) * (f 0)⁻¹ = 1 + simp [hf.2] + +def conjugateSequence (g : G) (f : ℤ → G) : ℤ → G := fun n => g⁻¹ * f n * g + +lemma conjugateSequence_mem {H : Filtration G} {k : ℕ} {f : ℤ → G} + (hf : f ∈ normalized H k) {g : G} (hg : g ∈ H.level 0) : + conjugateSequence g f ∈ normalized H k := by + rw [mem_normalized] at hf ⊢ + constructor + · have hc := const_mem ((H.level 0).inv_mem hg) + have hn := (Subgroup.mem_normalizer_iff.mp (normalizes H k hc) f).mp hf.1 + convert hn using 1 + ext n + simp [conjugateSequence] + · simp [conjugateSequence,hf.2] + +lemma conjugateSequence_lower {H : Filtration G} {k : ℕ} {f : ℤ → G} + (hf : f ∈ normalized H k) {g : G} (hg : g ∈ H.level 1) : + conjugateSequence g f * f⁻¹ ∈ normalized H (k+1) := by + rw [mem_normalized] at hf ⊢ + constructor + · have hc := commutator_mem (const_mem ((H.level 1).inv_mem hg)) hf.1 + have he : conjugateSequence g f * f⁻¹ = ⁅(fun _ : ℤ => g⁻¹),f⁆ := by + ext n + simp [conjugateSequence,commutatorElement_def] + rw [he] + simpa only [Nat.add_comm] using hc + · simp [conjugateSequence,hf.2] + + + +def system (H : Filtration G) (L : ℕ) (htop : H.level 1 = ⊤) (hL : H.level L = ⊥) : + GroupPET.System G (normalized H 0) where + filtration := reversedFiltration H L hL + eval n := (evaluation n).comp (normalized H 0).subtype + eval_zero f := (mem_normalized H 0 f).mp f.2 |>.2 + shift f t := ⟨normalizeShift f t, normalizeShift_mem f.2 t⟩ + shift_eval f n k := by + change (f.val n)⁻¹ * f.val (k+n) = (f.val n)⁻¹ * f.val (n+k) + rw [add_comm k n] + shift_lower := by + intro f t + let F := reversedFiltration H L hL + change (normalizeShift f t * (f : ℤ → G)⁻¹) ∈ normalized H (L-(F.degree f-1)) + by_cases hf1 : f = 1 + · subst f + have he : normalizeShift (1 : ℤ → G) t * (1 : ℤ → G)⁻¹ = 1 := by + ext n + simp [normalizeShift] + rw [Subgroup.coe_one,he] + exact (normalized H _).one_mem + have hpos : 0 < F.degree f := (F.degree_pos f).mpr hf1 + have hbound : F.degree f ≤ L := (F.degree_le_iff f L).mpr (by + change (f : ℤ → G) ∈ normalized H (L-L) + simpa only [Nat.sub_self] using f.2) + have hmem := F.degree_mem f + change (f : ℤ → G) ∈ normalized H (L-F.degree f) at hmem + have he : L-(F.degree f-1) = (L-F.degree f)+1 := by omega + rw [he] + exact normalizeShift_lower hmem t + conjugate g f := ⟨conjugateSequence g f, conjugateSequence_mem f.2 + (H.antitone (Nat.zero_le 1) (by simp [htop]))⟩ + conjugate_eval _ _ _ := rfl + conjugate_lower := by + intro g f + let F := reversedFiltration H L hL + change conjugateSequence g f * (f : ℤ → G)⁻¹ ∈ normalized H (L-(F.degree f-1)) + by_cases hf1 : f = 1 + · subst f + have he : conjugateSequence g (1 : ℤ → G) * (1 : ℤ → G)⁻¹ = 1 := by + ext n + simp [conjugateSequence] + rw [Subgroup.coe_one,he] + exact (normalized H _).one_mem + have hpos : 0 < F.degree f := (F.degree_pos f).mpr hf1 + have hbound : F.degree f ≤ L := (F.degree_le_iff f L).mpr (by + change (f : ℤ → G) ∈ normalized H (L-L) + simpa only [Nat.sub_self] using f.2) + have hmem := F.degree_mem f + change (f : ℤ → G) ∈ normalized H (L-F.degree f) at hmem + have he : L-(F.degree f-1) = (L-F.degree f)+1 := by omega + rw [he] + exact conjugateSequence_lower hmem (by simp [htop]) + +end +end CubePolynomials + + + +namespace StretchedFiltration +open Subgroup +variable {G : Type*} [Group G] + + +lemma rotate_le (A B C N : Subgroup G) [N.Normal] + (h₁ : ⁅⁅B, C⁆, A⁆ ≤ N) (h₂ : ⁅⁅C, A⁆, B⁆ ≤ N) : ⁅⁅A, B⁆, C⁆ ≤ N := by + let f := QuotientGroup.mk' N + have hmap (S : Subgroup G) (hS : S ≤ N) : S.map f = ⊥ := by + apply (Subgroup.map_eq_bot_iff S).mpr + simpa [f, QuotientGroup.ker_mk'] using hS + have h₁' : ⁅⁅B.map f, C.map f⁆, A.map f⁆ = ⊥ := by + simpa only [Subgroup.map_commutator] using hmap _ h₁ + have h₂' : ⁅⁅C.map f, A.map f⁆, B.map f⁆ = ⊥ := by + simpa only [Subgroup.map_commutator] using hmap _ h₂ + have h : (⁅⁅A, B⁆, C⁆).map f = ⊥ := by + simpa only [Subgroup.map_commutator] using + Subgroup.commutator_commutator_eq_bot_of_rotate h₁' h₂' + have := (Subgroup.map_eq_bot_iff _).mp h + simpa [f, QuotientGroup.ker_mk'] using this + + +theorem lower_bracket (a b : ℕ) : + ⁅(⊤ : Subgroup G).lowerCentralSeries a, (⊤ : Subgroup G).lowerCentralSeries b⁆ ≤ + (⊤ : Subgroup G).lowerCentralSeries (a + b + 1) := by + induction a generalizing b with + | zero => + rw [Subgroup.lowerCentralSeries_zero, Subgroup.commutator_comm, + ← Subgroup.lowerCentralSeries_succ] + simp + | succ a ih => + rw [Subgroup.lowerCentralSeries_succ] + apply rotate_le + · rw [Subgroup.commutator_comm (⊤ : Subgroup G), + ← Subgroup.lowerCentralSeries_succ, Subgroup.commutator_comm] + simpa only [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using ih (b + 1) + · have h := Subgroup.commutator_mono + (show ⁅(⊤ : Subgroup G).lowerCentralSeries b, + (⊤ : Subgroup G).lowerCentralSeries a⁆ ≤ + (⊤ : Subgroup G).lowerCentralSeries (a + b + 1) from by + rw [Subgroup.commutator_comm] + exact ih b) (le_refl (⊤ : Subgroup G)) + simpa only [← Subgroup.lowerCentralSeries_succ, + Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using h + + + +def stretch (D : ℕ) (i : ℕ) : Subgroup G := + (⊤ : Subgroup G).lowerCentralSeries ((i - 1) / D) + +lemma stretch_antitone (D : ℕ) : Antitone (stretch (G := G) D) := by + intro i j hij + exact (⊤ : Subgroup G).lowerCentralSeries_antitone (Nat.div_le_div_right (Nat.sub_le_sub_right hij 1)) + +@[simp] lemma stretch_zero (D : ℕ) : stretch (G := G) D 0 = ⊤ := by + simp [stretch] + +@[simp] lemma stretch_one (D : ℕ) : stretch (G := G) D 1 = ⊤ := by + simp [stretch] + +lemma stretch_eq_top {D i : ℕ} (hD : 0 < D) (hi : i ≤ D) : + stretch (G := G) D i = ⊤ := by + have : i - 1 < D := by omega + simp [stretch, Nat.div_eq_of_lt this] + +lemma stretch_terminal {D s : ℕ} (hD : 0 < D) + (hs : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) : + stretch (G := G) D (s * D + 1) = ⊥ := by + simpa [stretch, Nat.mul_div_cancel, Nat.ne_of_gt hD] using hs + +lemma stretch_bracket {D : ℕ} (hD : 0 < D) (i j : ℕ) : + ⁅stretch (G := G) D i, stretch (G := G) D j⁆ ≤ stretch (G := G) D (i + j) := by + rcases Nat.eq_zero_or_pos i with rfl | hi + · simp only [Nat.zero_add, stretch_zero] + unfold stretch + exact Subgroup.commutator_le_right _ _ + rcases Nat.eq_zero_or_pos j with rfl | hj + · simp only [Nat.add_zero, stretch_zero] + unfold stretch + exact Subgroup.commutator_le_left _ _ + apply (lower_bracket ((i - 1) / D) ((j - 1) / D)).trans + apply (⊤ : Subgroup G).lowerCentralSeries_antitone + have h₁ := Nat.mod_lt (i - 1) hD + have h₂ := Nat.mod_lt (j - 1) hD + have h₃ := Nat.div_add_mod (i - 1) D + have h₄ := Nat.div_add_mod (j - 1) D + have h₅ := Nat.div_add_mod (i + j - 1) D + have h₆ := Nat.mod_lt (i + j - 1) hD + by_contra h + have hh : ((i - 1) / D + (j - 1) / D + 2) * D ≤ (i + j - 1) / D * D := + Nat.mul_le_mul_right D (by omega) + have hsum : i + j - 1 = (i - 1) + (j - 1) + 1 := by omega + have hh' : D * ((i - 1) / D) + D * ((j - 1) / D) + 2 * D ≤ + D * ((i + j - 1) / D) := by nlinarith only [hh] + omega + +end StretchedFiltration + +namespace NilpotentPolynomialRecurrence +open _root_.Polynomial _root_.OAI.Polynomial +noncomputable section +variable {G : Type*} [Group G] + + +def word (w : List (G × ℤ[X])) (k : ℤ) : G := + (w.map (fun ap => ap.1 ^ ap.2.eval k)).prod + +lemma word_mem (H : CubeFaces.Filtration G) (D : ℕ) (hD : H.level D = ⊤) + (w : List (G × ℤ[X])) + (hw : ∀ ap ∈ w, ap.2.eval 0 = 0 ∧ ap.2.natDegree ≤ D) : + word w ∈ CubePolynomials.normalized H 0 := by + rw [CubePolynomials.mem_normalized] + induction w with + | nil => + constructor + · exact (CubePolynomials.polynomials H 0).one_mem + · simp [word] + | cons ap w ih => + have hap := hw ap (List.mem_cons_self ..) + have hwt := ih (fun bp hbp => hw bp (List.mem_cons_of_mem _ hbp)) + have ha := CubePolynomials.power_polynomial_mem D 0 ap.1 + (show ap.1 ∈ H.level (D+0) from by simp [hD]) ap.2 hap.2 + constructor + · exact (CubePolynomials.polynomials H 0).mul_mem ha hwt.1 + · simp only [word,List.map_cons,List.prod_cons, hap.1,zpow_zero,one_mul] + exact hwt.2 + + + +theorem coloring_recurrence [Group.IsNilpotent G] {C : Type*} [Fintype C] + (W : Finset (List (G × ℤ[X]))) + (hW : ∀ w ∈ W, ∀ ap ∈ w, ap.2.eval 0 = 0) + (χ : G → C) (N : ℕ) : + ∃ k : ℕ, N < k ∧ ∃ J : G, ∀ w ∈ W, χ (word w k * J) = χ J := by + classical + let D : ℕ := W.sup (fun w => (w.map (fun ap => ap.2.natDegree)).foldr max 0) + 1 + have hD : 0 < D := Nat.zero_lt_succ _ + let H : CubeFaces.Filtration G := { + level := StretchedFiltration.stretch D + antitone := StretchedFiltration.stretch_antitone D + commutator_le := StretchedFiltration.stretch_bracket hD } + obtain ⟨s,hs⟩ := Subgroup.nilpotent_iff_lowerCentralSeries.mp (inferInstance : Group.IsNilpotent G) + let L := s*D+1 + have htop : H.level 1 = ⊤ := StretchedFiltration.stretch_one D + have hL : H.level L = ⊥ := StretchedFiltration.stretch_terminal hD hs + let T := CubePolynomials.system H L htop hL + have hmem : ∀ w ∈ W, word w ∈ CubePolynomials.normalized H 0 := by + intro w hw + apply word_mem H D (StretchedFiltration.stretch_eq_top hD le_rfl) w + intro ap hap + refine ⟨hW w hw ap hap,?_⟩ + have hm : ap.2.natDegree ≤ (w.map (fun ap => ap.2.natDegree)).foldr max 0 := by + clear hw + induction w with + | nil => simp at hap + | cons bp w ih => + simp only [List.mem_cons] at hap + simp only [List.map_cons,List.foldr_cons] + rcases hap with rfl | hap + · exact le_max_left _ _ + · exact (ih hap).trans (le_max_right _ _) + apply hm.trans + calc + _ ≤ W.sup (fun v => (v.map (fun ap => ap.2.natDegree)).foldr max 0) := Finset.le_sup hw + _ ≤ D := Nat.le_succ _ + let lift : W → CubePolynomials.normalized H 0 := fun w => ⟨word w.1, hmem w.1 w.2⟩ + let P := Finset.univ.image lift + let : TopologicalSpace C := ⊥ + let : DiscreteTopology C := ⟨rfl⟩ + obtain ⟨k,hk,J,hJ⟩ := GroupPETRecurrence.coloring_polynomial_recurrence T P χ N + refine ⟨k,hk,J,?_⟩ + intro w hw + exact hJ (lift ⟨w,hw⟩) (Finset.mem_image.mpr ⟨⟨w,hw⟩,Finset.mem_univ _,rfl⟩) + +end +end NilpotentPolynomialRecurrence + + + +namespace UniformRecurrence + +variable {G : Type*} [Group G] {κ : Type*} [Fintype κ] + + +def Recurs {ι : Type*} (w : ι → ℕ → G) (χ : G → κ) : Prop := + ∃ k : ℕ, 0 < k ∧ ∃ J : G, ∀ i, χ (w i k * J) = χ J + + + +theorem finite_alternatives {ι : Type*} [Fintype ι] (w : ι → ℕ → G) + (h : ∀ χ : G → κ, Recurs w χ) : + ∃ O : Finset (ℕ × G), (∀ o ∈ O, 0 < o.1) ∧ + ∀ χ : G → κ, ∃ o ∈ O, ∀ i, χ (w i o.1 * o.2) = χ o.2 := by + classical + let : TopologicalSpace κ := ⊥ + let : DiscreteTopology κ := ⟨rfl⟩ + let U : (ℕ+ × G) → Set (G → κ) := fun o => + {χ | ∀ i, χ (w i o.1 * o.2) = χ o.2} + have hopen (o) : IsOpen (U o) := by + unfold U + simp only [Set.ofPred_forall] + apply isOpen_iInter_of_finite + intro i + change IsOpen ((fun χ : G → κ => (χ (w i o.1 * o.2), χ o.2)) ⁻¹' + {p : κ × κ | p.1 = p.2}) + exact (isOpen_discrete {p : κ × κ | p.1 = p.2}).preimage + ((continuous_apply (w i o.1 * o.2)).prodMk (continuous_apply o.2)) + have hcover : (Set.univ : Set (G → κ)) ⊆ ⋃ o, U o := by + intro χ _ + obtain ⟨k, hk, J, hJ⟩ := h χ + exact Set.mem_iUnion.mpr ⟨(⟨k, hk⟩, J), hJ⟩ + obtain ⟨O, hO⟩ := isCompact_univ.elim_finite_subcover U hopen hcover + refine ⟨O.image (fun o => (o.1.val, o.2)), ?_, ?_⟩ + · intro o ho + obtain ⟨p, _, rfl⟩ := Finset.mem_image.mp ho + exact p.1.pos + · intro χ + have hχ := hO (Set.mem_univ χ) + obtain ⟨o, ho, hχ⟩ := Set.mem_iUnion₂.mp hχ + exact ⟨(o.1.val, o.2), Finset.mem_image.mpr ⟨o, ho, rfl⟩, hχ⟩ + + +structure PolynomialWord (A : Type*) where + letters : List (A × Polynomial ℤ) + vanishes : ∀ u ∈ letters, u.2.eval 0 = 0 + +namespace PolynomialWord +variable {A H : Type*} [Group H] +def eval (p : PolynomialWord A) (a : A → H) (k : ℕ) : H := + (p.letters.map (fun u => a u.1 ^ u.2.eval (k : ℤ))).prod + +lemma map_eval (p : PolynomialWord A) (a : A → G) (f : G →* H) (k : ℕ) : + f (p.eval a k) = p.eval (f ∘ a) k := by + simp [eval, map_list_prod, List.map_map, Function.comp_def] + +lemma eval_zero (p : PolynomialWord A) (a : A → G) : p.eval a 0 = 1 := by + unfold eval + apply List.prod_eq_one + intro x hx + obtain ⟨u, hu, rfl⟩ := List.mem_map.mp hx + simp [p.vanishes u hu] +end PolynomialWord + + + +def FreeNilpotent (A : Type*) (s : ℕ) := + FreeGroup A ⧸ (⊤ : Subgroup (FreeGroup A)).lowerCentralSeries s + +instance {A : Type*} {s : ℕ} : Group (FreeNilpotent A s) := by + unfold FreeNilpotent + infer_instance + +namespace FreeNilpotent +variable {A : Type*} {s : ℕ} + +def of (a : A) : FreeNilpotent A s := + QuotientGroup.mk (FreeGroup.of a) + + +theorem lower_eq_bot : + (⊤ : Subgroup (FreeNilpotent A s)).lowerCentralSeries s = ⊥ := by + let N := (⊤ : Subgroup (FreeGroup A)).lowerCentralSeries s + let f : FreeGroup A →* FreeNilpotent A s := QuotientGroup.mk' N + have htop : (⊤ : Subgroup (FreeGroup A)).map f = ⊤ := + f.range_eq_map.symm.trans (MonoidHom.range_eq_top.mpr (QuotientGroup.mk'_surjective N)) + have hmap : N.map f = ⊥ := (Subgroup.map_eq_bot_iff _).mpr (by + change N ≤ (QuotientGroup.mk' N).ker + rw [QuotientGroup.ker_mk']) + rw [← htop, ← Subgroup.map_lowerCentralSeries] + exact hmap + +instance : Group.IsNilpotent (FreeNilpotent A s) := + Subgroup.nilpotent_iff_lowerCentralSeries.mpr ⟨s, lower_eq_bot⟩ + +instance [Countable A] : Countable (FreeNilpotent A s) := by + have : Countable (FreeGroup A) := by + unfold FreeGroup + infer_instance + exact (QuotientGroup.mk'_surjective + ((⊤ : Subgroup (FreeGroup A)).lowerCentralSeries s)).countable + +private theorem lift_kernel (a : A → G) + (hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) : + (⊤ : Subgroup (FreeGroup A)).lowerCentralSeries s ≤ (FreeGroup.lift a).ker := by + apply (Subgroup.map_eq_bot_iff _).mp + rw [Subgroup.map_lowerCentralSeries] + apply le_bot_iff.mp + calc + ((⊤ : Subgroup (FreeGroup A)).map (FreeGroup.lift a)).lowerCentralSeries s + ≤ (⊤ : Subgroup G).lowerCentralSeries s := Subgroup.lowerCentralSeries_mono s le_top + _ = ⊥ := hG + + +noncomputable def lift (a : A → G) + (hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) : FreeNilpotent A s →* G := + QuotientGroup.lift _ (FreeGroup.lift a) (lift_kernel a hG) + +@[simp] theorem lift_of (a : A → G) + (hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) (x : A) : + lift a hG (of x) = a x := by + change FreeGroup.lift a (FreeGroup.of x) = a x + exact FreeGroup.lift_apply_of + +lemma lift_polynomialWord (p : PolynomialWord A) (a : A → G) + (hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) (k : ℕ) : + lift a hG (p.eval (of (s := s)) k) = p.eval a k := by + rw [PolynomialWord.map_eval] + congr 1 + funext x + exact lift_of a hG x + +end FreeNilpotent + +end UniformRecurrence + +namespace UniformRecurrence +noncomputable section +variable {A ι κ : Type*} [Fintype ι] [Fintype κ] + + + +theorem universal_quotient_alternatives (s : ℕ) (p : ι → PolynomialWord A) : + ∃ O : Finset (ℕ × FreeNilpotent A s), (∀ o ∈ O, 0 < o.1) ∧ + ∀ χ : FreeNilpotent A s → κ, ∃ o ∈ O, ∀ i, + χ ((p i).eval FreeNilpotent.of o.1 * o.2) = χ o.2 := by + classical + apply finite_alternatives + intro χ + let letters (i : ι) : List (FreeNilpotent A s × Polynomial ℤ) := + (p i).letters.map (fun ap => (FreeNilpotent.of ap.1, ap.2)) + let W := Finset.univ.image letters + have hW : ∀ w ∈ W, ∀ ap ∈ w, ap.2.eval 0 = 0 := by + intro w hw ap hap + obtain ⟨i, _, rfl⟩ := Finset.mem_image.mp hw + obtain ⟨bp, hbp, rfl⟩ := List.mem_map.mp hap + exact (p i).vanishes bp hbp + obtain ⟨k, hk, J, hJ⟩ := + NilpotentPolynomialRecurrence.coloring_recurrence W hW χ 0 + refine ⟨k, hk, J, ?_⟩ + intro i + have hi := hJ (letters i) (Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩) + simpa only [NilpotentPolynomialRecurrence.word, letters, List.map_map, + Function.comp_def, PolynomialWord.eval] using hi + + + +theorem universal_finite_alternatives (s : ℕ) (p : ι → PolynomialWord A) : + ∃ O : Finset (ℕ × FreeGroup A), (∀ o ∈ O, 0 < o.1) ∧ + ∀ (G : Type*) [Group G] + (_hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) + (a : A → G) (χ : G → κ), ∃ o ∈ O, ∀ i, + χ ((p i).eval a o.1 * FreeGroup.lift a o.2) = χ (FreeGroup.lift a o.2) := by + classical + obtain ⟨O, hpos, hO⟩ := universal_quotient_alternatives (κ := κ) s p + let N := (⊤ : Subgroup (FreeGroup A)).lowerCentralSeries s + let q : FreeGroup A →* FreeNilpotent A s := QuotientGroup.mk' N + let rep : FreeNilpotent A s → FreeGroup A := fun g => + Classical.choose (QuotientGroup.mk'_surjective N g) + have hrep (g : FreeNilpotent A s) : q (rep g) = g := + Classical.choose_spec (QuotientGroup.mk'_surjective N g) + refine ⟨O.image (fun o => (o.1, rep o.2)), ?_, ?_⟩ + · intro o ho + obtain ⟨u, hu, rfl⟩ := Finset.mem_image.mp ho + exact hpos u hu + · intro G _ hG a χ + let f := FreeNilpotent.lift a hG + obtain ⟨o, ho, heq⟩ := hO (χ ∘ f) + refine ⟨(o.1,rep o.2), Finset.mem_image.mpr ⟨o, ho, rfl⟩, ?_⟩ + intro i + have hf : f o.2 = FreeGroup.lift a (rep o.2) := by + calc + f o.2 = f (q (rep o.2)) := congrArg f (hrep o.2).symm + _ = FreeGroup.lift a (rep o.2) := rfl + have hi := heq i + change χ (f ((p i).eval FreeNilpotent.of o.1 * o.2)) = χ (f o.2) at hi + rw [map_mul, FreeNilpotent.lift_polynomialWord, hf] at hi + exact hi + +end +end UniformRecurrence + +namespace FiniteWordPlan +open UniformRecurrence +noncomputable section +variable {A G X Label κ : Type*} [Group G] [MulAction G X] + + + +def inflate (lam : A → ℕ) (k : ℕ) : FreeGroup A →* FreeGroup A := + FreeGroup.lift (fun a => FreeGroup.of a ^ (k ^ lam a)) + +def polynomial (lam : A → ℕ) (hlam : ∀ a, 0 < lam a) (w : FreeGroup A) : + PolynomialWord A := by + classical + exact { + letters := w.toWord.map (fun u => + (u.1, if u.2 then (Polynomial.X : Polynomial ℤ) ^ lam u.1 else -Polynomial.X ^ lam u.1)) + vanishes := by + intro u hu + obtain ⟨v, _, rfl⟩ := List.mem_map.mp hu + cases v.2 <;> simp [Nat.ne_of_gt (hlam v.1)] } + +lemma eval_polynomial (lam : A → ℕ) (hlam : ∀ a, 0 < lam a) + (w : FreeGroup A) (a : A → G) (k : ℕ) : + (polynomial lam hlam w).eval a k = FreeGroup.lift a (inflate lam k w) := by + classical + conv_rhs => rw [← FreeGroup.mk_toWord (x := w)] + simp only [inflate, FreeGroup.lift_mk, map_list_prod, List.map_map, + Function.comp_def] + unfold PolynomialWord.eval polynomial + simp only [List.map_map, Function.comp_def] + congr 1 + apply List.map_congr_left + intro u _ + cases u.2 <;> simp + all_goals rw [← Int.natCast_pow, zpow_natCast] + +lemma interpretation_inflation (lam : A → ℕ) (k : ℕ) (a a' : A → G) + (h : ∀ u, a' u = a u ^ (k ^ lam u)) (w : FreeGroup A) : + FreeGroup.lift a' w = FreeGroup.lift a (inflate lam k w) := by + have hh : FreeGroup.lift a' = (FreeGroup.lift a).comp (inflate lam k) := by + apply FreeGroup.ext_hom + intro u + simpa [inflate] using h u + exact DFunLike.congr_fun hh w + + + +theorem update_options [Fintype κ] (s : ℕ) (lam : A → ℕ) (hlam : ∀ a, 0 < lam a) + (W : Finset (FreeGroup A)) : + ∃ O : Finset (ℕ × FreeGroup A), (∀ o ∈ O, 0 < o.1) ∧ + ∀ (G : Type*) [Group G] + (_hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) + (X : Type*) [MulAction G X] (a : A → G) (C : X → κ) (x : X), + ∃ o ∈ O, ∀ w ∈ W, + C (FreeGroup.lift a (inflate lam o.1 w) • (FreeGroup.lift a o.2 • x)) = + C (FreeGroup.lift a o.2 • x) := by + classical + obtain ⟨O,hpos,hO⟩ := universal_finite_alternatives (κ := κ) s + (fun w : W => polynomial lam hlam w.1) + refine ⟨O,hpos,?_⟩ + intro G _ hG X _ a C x + obtain ⟨o,ho,heq⟩ := hO G hG a (fun g => C (g • x)) + refine ⟨o,ho,?_⟩ + intro w hw + have hh := heq ⟨w,hw⟩ + simpa only [eval_polynomial, mul_smul] using hh + + +def Requirement (C : Label → X → κ) (a : A → G) + (R : Finset (Label × FreeGroup A)) (x : X) : Prop := + ∀ r ∈ R, C r.1 x = C r.1 (FreeGroup.lift a r.2 • x) + + + +def predecessor [DecidableEq Label] [DecidableEq A] + (lam : A → ℕ) (f : ℕ → Label → Label) + (O : Finset (ℕ × FreeGroup A)) (R : Finset (Label × FreeGroup A)) : + Finset (Label × FreeGroup A) := + O.biUnion (fun o => R.biUnion (fun r => + {(f o.1 r.1,o.2), (f o.1 r.1, inflate lam o.1 r.2 * o.2)})) + + + +lemma protect_jump [DecidableEq Label] [DecidableEq A] + (lam : A → ℕ) (f : ℕ → Label → Label) + (O : Finset (ℕ × FreeGroup A)) (R : Finset (Label × FreeGroup A)) + (C C' : Label → X → κ) (a a' : A → G) (x : X) + (o : ℕ × FreeGroup A) (ho : o ∈ O) + (hC : ∀ l, C' l = C (f o.1 l)) + (ha : ∀ u, a' u = a u ^ (o.1 ^ lam u)) + (h : Requirement C a (predecessor lam f O R) x) : + Requirement C' a' R (FreeGroup.lift a o.2 • x) := by + intro r hr + have hmem₁ : (f o.1 r.1,o.2) ∈ predecessor lam f O R := by + apply Finset.mem_biUnion.mpr ⟨o,ho,?_⟩ + exact Finset.mem_biUnion.mpr ⟨r,hr,by simp⟩ + have hmem₂ : (f o.1 r.1,inflate lam o.1 r.2 * o.2) ∈ predecessor lam f O R := by + apply Finset.mem_biUnion.mpr ⟨o,ho,?_⟩ + exact Finset.mem_biUnion.mpr ⟨r,hr,by simp⟩ + have h₁ := h _ hmem₁ + have h₂ := h _ hmem₂ + dsimp only at h₁ h₂ + rw [hC, interpretation_inflation lam o.1 a a' ha, + ← mul_smul, ← map_mul] + exact h₁.symm.trans h₂ + +end +end FiniteWordPlan + +namespace FiniteWordPlan +noncomputable section + + + +structure ScaleSystem (A Label G X S κ : Type*) [Group G] [MulAction G X] + (lam : ℕ → A → ℕ) (f : ℕ → ℕ → Label → Label) where + update : ℕ → ℕ → S → S + letter : S → A → G + color : S → Label → X → κ + letter_update : ∀ n k st, 0 < k → ∀ a, + letter (update n k st) a = letter st a ^ (k ^ lam n a) + color_update : ∀ n k st, 0 < k → ∀ l, + color (update n k st) l = color st (f n k l) + +variable {A Label G X S κ : Type*} [Group G] [MulAction G X] + {lam : ℕ → A → ℕ} {f : ℕ → ℕ → Label → Label} + + + +def run (T : ScaleSystem A Label G X S κ lam f) : + ℕ → List (ℕ × FreeGroup A) → S → X → S × X + | _, [], st, x => (st, x) + | n, o :: p, st, x => run T (n + 1) p (T.update n o.1 st) + (FreeGroup.lift (T.letter st) o.2 • x) + +lemma run_append (T : ScaleSystem A Label G X S κ lam f) + (p q : List (ℕ × FreeGroup A)) (n : ℕ) (st : S) (x : X) : + run T n (p ++ q) st x = + run T (n + p.length) q (run T n p st x).1 (run T n p st x).2 := by + induction p generalizing n st x with + | nil => simp [run] + | cons o p ih => + simp only [List.cons_append, run, List.length_cons] + rw [ih] + congr 1; omega + + + +theorem pivot_plan [Fintype κ] (s : ℕ) (lam : ℕ → A → ℕ) + (hlam : ∀ n a, 0 < lam n a) (f : ℕ → ℕ → Label → Label) + (tag : Label → ℕ) (htag : ∀ n k l, tag (f n k l) = tag l) + (hfix : ∀ n k l, tag l = n → f n k l = l) + (q : ℕ) (R : Finset (Label × FreeGroup A)) + (hR : ∀ r ∈ R, tag r.1 < q) : + ∃ P : Finset (List (ℕ × FreeGroup A)), + (∀ p ∈ P, p.length = q ∧ ∀ o ∈ p, 0 < o.1) ∧ + ∀ (G : Type*) [Group G] + (_hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) + (X : Type*) [MulAction G X] (S : Type*) + (T : ScaleSystem A Label G X S κ lam f) (st : S) (x : X), + ∃ p ∈ P, Requirement (T.color (run T 0 p st x).1) + (T.letter (run T 0 p st x).1) R (run T 0 p st x).2 := by + classical + induction q generalizing R with + | zero => + refine ⟨{[]}, ?_, ?_⟩ + · intro p hp + simp only [Finset.mem_singleton] at hp + subst p + simp + · intro G _ _ X _ S T st x + refine ⟨[], by simp, ?_⟩ + intro r hr + exact False.elim (Nat.not_lt_zero _ (hR r hr)) + | succ n ih => + let Rold := R.filter (fun r => tag r.1 < n) + let Rnew := R.filter (fun r => tag r.1 = n) + let L := Rnew.image Prod.fst + let W := Rnew.image Prod.snd + obtain ⟨O, hpos, hO⟩ := update_options (κ := L → κ) s (lam n) (hlam n) W + let Rpre := predecessor (lam n) (f n) O Rold + have hpre : ∀ r ∈ Rpre, tag r.1 < n := by + intro r hr + obtain ⟨o, _, ho⟩ := Finset.mem_biUnion.mp hr + obtain ⟨v, hv, hrv⟩ := Finset.mem_biUnion.mp ho + have hvtag := (Finset.mem_filter.mp hv).2 + simp only [Finset.mem_insert, Finset.mem_singleton] at hrv + rcases hrv with rfl | rfl <;> simpa only [htag] using hvtag + obtain ⟨P, hP, hrun⟩ := ih Rpre hpre + refine ⟨P.biUnion (fun p => O.image (fun o => p ++ [o])), ?_, ?_⟩ + · intro p hp + obtain ⟨v, hv, hp⟩ := Finset.mem_biUnion.mp hp + obtain ⟨o, ho, rfl⟩ := Finset.mem_image.mp hp + obtain ⟨hlen, hpositive⟩ := hP v hv + constructor + · simp [hlen] + · intro u hu + rcases List.mem_append.mp hu with hu | hu + · exact hpositive u hu + · have he : u = o := List.mem_singleton.mp hu + simpa only [he] using hpos o ho + · intro G _ hG X _ S T st x + obtain ⟨p, hp, hprev⟩ := hrun G hG X S T st x + let stp := (run T 0 p st x).1 + let xp := (run T 0 p st x).2 + let C : X → L → κ := fun y l => T.color stp l.1 y + obtain ⟨o, ho, hrec⟩ := hO G hG X (T.letter stp) C xp + have hlen := (hP p hp).1 + have hrunlast : run T 0 (p ++ [o]) st x = + (T.update n o.1 stp, FreeGroup.lift (T.letter stp) o.2 • xp) := by + rw [run_append, hlen, Nat.zero_add] + rfl + refine ⟨p ++ [o], Finset.mem_biUnion.mpr ⟨p,hp,Finset.mem_image.mpr ⟨o,ho,rfl⟩⟩, ?_⟩ + rw [hrunlast] + have hold : Requirement (T.color (T.update n o.1 stp)) + (T.letter (T.update n o.1 stp)) Rold + (FreeGroup.lift (T.letter stp) o.2 • xp) := + protect_jump (lam n) (f n) O Rold (T.color stp) + (T.color (T.update n o.1 stp)) (T.letter stp) + (T.letter (T.update n o.1 stp)) xp o ho + (T.color_update n o.1 stp (hpos o ho)) + (T.letter_update n o.1 stp (hpos o ho)) hprev + intro r hr + by_cases ht : tag r.1 < n + · exact hold r (Finset.mem_filter.mpr ⟨hr,ht⟩) + · have htagr : tag r.1 = n := by have := hR r hr; omega + have hrnew : r ∈ Rnew := Finset.mem_filter.mpr ⟨hr,htagr⟩ + have hl : r.1 ∈ L := Finset.mem_image.mpr ⟨r,hrnew,rfl⟩ + have hw : r.2 ∈ W := Finset.mem_image.mpr ⟨r,hrnew,rfl⟩ + have hh := congrFun (hrec r.2 hw) ⟨r.1,hl⟩ + dsimp only [C] at hh + change T.color (T.update n o.1 stp) r.1 _ = + T.color (T.update n o.1 stp) r.1 _ + rw [T.color_update n o.1 stp (hpos o ho), hfix n o.1 r.1 htagr, + interpretation_inflation (lam n) o.1 (T.letter stp) + (T.letter (T.update n o.1 stp)) + (T.letter_update n o.1 stp (hpos o ho))] + exact hh.symm + +end +end FiniteWordPlan + + + +namespace AlignmentScales +open scoped BigOperators + +def weight {n : ℕ} (i : Fin n) : ℕ := 2 ^ (n - (i.val + 1)) +def weightSum {n : ℕ} (A : Finset (Fin n)) : ℕ := ∑ i ∈ A, weight i + +lemma geom_sum (k : ℕ) : (∑ j ∈ Finset.range k, 2 ^ j) + 1 = 2 ^ k := by + induction k with + | zero => simp + | succ k ih => rw [Finset.sum_range_succ, pow_succ]; omega + + +lemma sum_later_lt {n : ℕ} (a : Fin n) (C : Finset (Fin n)) + (hC : ∀ c ∈ C, a < c) : weightSum C < weight a := by + classical + let e : Fin n → ℕ := fun i => n - (i.val + 1) + have hinj : Function.Injective e := by + intro i j h + apply Fin.ext + dsimp [e] at h + have := i.isLt + have := j.isLt + omega + have hsub : C.image e ⊆ Finset.range (e a) := by + intro j hj + obtain ⟨c,hc,rfl⟩ := Finset.mem_image.mp hj + have hlt := hC c hc + change a.val < c.val at hlt + apply Finset.mem_range.mpr + dsimp [e] + have := c.isLt + omega + have hs : weightSum C ≤ ∑ j ∈ Finset.range (e a), 2 ^ j := by + calc + weightSum C = ∑ j ∈ C.image e, 2 ^ j := by + rw [Finset.sum_image (fun i _ j _ h => hinj h)] + rfl + _ ≤ _ := Finset.sum_le_sum_of_subset hsub + have hh := geom_sum (e a) + change weightSum C < 2 ^ e a + omega + +lemma weightSum_nonneg {n : ℕ} (A : Finset (Fin n)) : 0 ≤ (weightSum A : ℤ) := + Int.natCast_nonneg _ + + + +lemma exponent_pos {n : ℕ} (A C T : Finset (Fin n)) + (hAC : ∃ a ∈ A, ∀ c ∈ C, a < c) : + 0 < (weightSum A : ℤ) - weightSum C + weightSum T := by + obtain ⟨a,ha,hC⟩ := hAC + have h₁ := sum_later_lt a C hC + have h₂ : weight a ≤ weightSum A := Finset.single_le_sum (fun i _ => Nat.zero_le _ ) ha + have h₃ := weightSum_nonneg T + omega + + +def updateExponent {n : ℕ} (i : Fin n) (T : Finset (Fin n)) (l : Fin n) : ℤ := + if l < i then weight l else if l = i then -(weightSum T : ℤ) else 0 + + +def multiplier {n : ℕ} (i : Fin n) (T : Finset (Fin n)) (k : ℚ) (l : Fin n) : ℚ := + k ^ updateExponent i T l + +def blockProduct {n : ℕ} (b : Fin n → ℚ) (A : Finset (Fin n)) : ℚ := ∏ l ∈ A, b l + +def update {n : ℕ} (b : Fin n → ℚ) (i : Fin n) (T : Finset (Fin n)) (k : ℚ) : Fin n → ℚ := + fun l => b l * multiplier i T k l + +lemma multiplier_pos {n : ℕ} (i : Fin n) (T : Finset (Fin n)) {k : ℚ} + (hk : 0 < k) (l : Fin n) : 0 < multiplier i T k l := zpow_pos hk _ + +lemma blockProduct_update {n : ℕ} (b : Fin n → ℚ) (i : Fin n) (T A : Finset (Fin n)) + (k : ℚ) : + blockProduct (update b i T k) A = blockProduct b A * blockProduct (multiplier i T k) A := by + exact Finset.prod_mul_distrib + +lemma blockProduct_multiplier {n : ℕ} (i : Fin n) (T A : Finset (Fin n)) + {k : ℚ} (hk : k ≠ 0) : + blockProduct (multiplier i T k) A = k ^ (∑ l ∈ A, updateExponent i T l) := by + classical + induction A using Finset.induction_on with + | empty => simp [blockProduct] + | @insert a A ha ih => + simp only [blockProduct, Finset.prod_insert ha, Finset.sum_insert ha] at * + rw [ih, zpow_add₀ hk] + rfl + +lemma exponentSum_before {n : ℕ} (i : Fin n) (T A : Finset (Fin n)) + (hA : ∀ l ∈ A, l < i) : + (∑ l ∈ A, updateExponent i T l) = (weightSum A : ℤ) := by + simp only [weightSum, Nat.cast_sum] + apply Finset.sum_congr rfl + intro l hl + simp [updateExponent, hA l hl] + +lemma exponentSum_target {n : ℕ} (i : Fin n) (T C : Finset (Fin n)) + (hC : ∀ l ∈ C, l < i) : + (∑ l ∈ insert i C, updateExponent i T l) = (weightSum C : ℤ) - weightSum T := by + classical + have hi : i ∉ C := fun h => (lt_irrefl i) (hC i h) + rw [Finset.sum_insert hi, exponentSum_before i T C hC] + simp [updateExponent] + ring + + +lemma target_preserved {n : ℕ} (b : Fin n → ℚ) (i : Fin n) (T : Finset (Fin n)) + (hT : ∀ l ∈ T, l < i) {k : ℚ} (hk : k ≠ 0) : + blockProduct (update b i T k) (insert i T) = blockProduct b (insert i T) := by + rw [blockProduct_update, blockProduct_multiplier i T _ hk, + exponentSum_target i T T hT, sub_self, zpow_zero, mul_one] + + +lemma ratio_update {n : ℕ} (b : Fin n → ℚ) (i : Fin n) (T A C : Finset (Fin n)) + (hA : ∀ l ∈ A, l < i) (hC : ∀ l ∈ C, l < i) {k : ℚ} (hk : k ≠ 0) : + blockProduct (update b i T k) A / blockProduct (update b i T k) (insert i C) = + (blockProduct b A / blockProduct b (insert i C)) * + k ^ ((weightSum A : ℤ) - weightSum C + weightSum T) := by + rw [blockProduct_update, blockProduct_update, + blockProduct_multiplier i T A hk, blockProduct_multiplier i T (insert i C) hk, + exponentSum_before i T A hA, exponentSum_target i T C hC] + rw [mul_div_mul_comm, ← zpow_sub₀ hk] + congr 2 + ring + +end AlignmentScales + + + +namespace RationalPivotPlan +open AlignmentScales +noncomputable section + +variable {n q : ℕ} (i : Fin n) (tail : Fin q → Finset (Fin n)) + +def tailAt (j : ℕ) : Finset (Fin n) := if h : j < q then tail ⟨j,h⟩ else ∅ + +lemma tailAt_fin (j : Fin q) : tailAt tail j.val = tail j := by + simp [tailAt] + +def block (j : Fin q) : Finset (Fin n) := insert i (tail j) + +def transport (j k : ℕ) (l : Fin q × ℚ) : Fin q × ℚ := + (l.1, l.2 * blockProduct (multiplier i (tailAt tail j) (k : ℚ)) (block i tail l.1)) + +lemma transport_tag (j k : ℕ) (l : Fin q × ℚ) : + (transport i tail j k l).1.val = l.1.val := rfl + + + +def transportPos (j k : ℕ) (l : Fin q × ℚ) : Fin q × ℚ := + if k = 0 then l else transport i tail j k l + +lemma transportPos_tag (j k : ℕ) (l : Fin q × ℚ) : + (transportPos i tail j k l).1.val = l.1.val := by + simp only [transportPos] + split <;> rfl + +lemma transportPos_fix (htail : ∀ j a, a ∈ tail j → a < i) + (j k : ℕ) (l : Fin q × ℚ) (h : l.1.val = j) : + transportPos i tail j k l = l := by + classical + by_cases hk : k = 0 + · simp [transportPos, hk] + · simp only [transportPos, ite_eq_right hk, transport] + apply Prod.ext + · rfl + dsimp + rw [← h, tailAt_fin, block, blockProduct_multiplier _ _ _ (by exact_mod_cast hk), + exponentSum_target i (tail l.1) (tail l.1) (htail l.1), sub_self, zpow_zero, + mul_one] + +variable {E : Type*} (owner : E → Fin q) (added : E → Finset (Fin n)) + +def exponent (j : ℕ) (e : E) : ℤ := + (weightSum (added e) : ℤ) - weightSum (tail (owner e)) + weightSum (tailAt tail j) + +def lam (j : ℕ) (e : E × ℚ) : ℕ := (exponent tail owner added j e.1).toNat + +lemma exponent_positive + (hbefore : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c) (j : ℕ) (e : E) : + 0 < exponent tail owner added j e := + exponent_pos _ _ _ (hbefore e) + +lemma lam_positive + (hbefore : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c) (j : ℕ) (e : E × ℚ) : + 0 < lam tail owner added j e := by + have h := exponent_positive tail owner added hbefore j e.1 + dsimp [lam] + omega + +variable {G X κ : Type*} [Group G] [MulAction G X] + + +abbrev State := (Fin n → ℚ) × (E × ℚ → G) + +def system (C : Fin q → ℚ → X → κ) : + FiniteWordPlan.ScaleSystem (E × ℚ) (Fin q × ℚ) G X + (State (n := n) (E := E) (G := G)) κ + (lam tail owner added) (transportPos i tail) where + update j k st := (update st.1 i (tailAt tail j) k, + fun e => st.2 e ^ (k ^ lam tail owner added j e)) + letter st := st.2 + color st l := C l.1 (l.2 * blockProduct st.1 (block i tail l.1)) + letter_update _ _ _ _ _ := rfl + color_update j k st hk l := by + simp only [transportPos, ite_eq_right (Nat.ne_of_gt hk), transport] + rw [blockProduct_update] + congr 1 + ring + + + +theorem rational_pivot_plan [Fintype κ] (s : ℕ) + (htail : ∀ j a, a ∈ tail j → a < i) + (hbefore : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c) + (R : Finset ((Fin q × ℚ) × FreeGroup (E × ℚ))) : + ∃ P : Finset (List (ℕ × FreeGroup (E × ℚ))), + (∀ p ∈ P, p.length = q ∧ ∀ o ∈ p, 0 < o.1) ∧ + ∀ (G : Type*) [Group G] + (_hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) + (X : Type*) [MulAction G X] (C : Fin q → ℚ → X → κ) + (b : Fin n → ℚ) (a : E × ℚ → G) (x : X), + ∃ p ∈ P, let z := FiniteWordPlan.run (system i tail owner added C) 0 p (b,a) x + FiniteWordPlan.Requirement + (fun l => C l.1 (l.2 * blockProduct z.1.1 (block i tail l.1))) + z.1.2 R z.2 := by + obtain ⟨P,hP,h⟩ := FiniteWordPlan.pivot_plan (κ := κ) s (lam tail owner added) + (lam_positive tail owner added hbefore) (transportPos i tail) (fun l => l.1.val) + (transportPos_tag i tail) (transportPos_fix i tail htail) q R + (fun r _ => r.1.1.isLt) + refine ⟨P,hP,?_⟩ + intro G _ hG X _ C b a x + exact h G hG X _ (system i tail owner added C) (b,a) x + +end +end RationalPivotPlan + +namespace RationalPivotPlan +open AlignmentScales +noncomputable section +variable {n q : ℕ} {E G X κ : Type*} [Group G] [MulAction G X] + (i : Fin n) (tail : Fin q → Finset (Fin n)) + (owner : E → Fin q) (added : E → Finset (Fin n)) + +def qExponent (q₀ : ℕ) (b : Fin n → ℚ) (e : E × ℚ) : ℚ := + q₀ * e.2 * (blockProduct b (added e.1) / blockProduct b (block i tail (owner e.1))) + +lemma qExponent_update + (htail : ∀ j a, a ∈ tail j → a < i) + (hadded : ∀ e a, a ∈ added e → a < i) + (hbefore : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c) + (q₀ : ℕ) (b : Fin n → ℚ) (j k : ℕ) (hk : 0 < k) (e : E × ℚ) : + qExponent i tail owner added q₀ (update b i (tailAt tail j) k) e = + qExponent i tail owner added q₀ b e * (k ^ lam tail owner added j e : ℕ) := by + unfold qExponent + rw [block, ratio_update b i (tailAt tail j) (added e.1) (tail (owner e.1)) + (hadded e.1) (htail (owner e.1)) (by exact_mod_cast Nat.ne_of_gt hk)] + have hh : (lam tail owner added j e : ℤ) = exponent tail owner added j e.1 := + Int.toNat_of_nonneg (le_of_lt (exponent_positive tail owner added hbefore j e.1)) + change (q₀ : ℚ) * e.2 * + (_ * (k : ℚ) ^ exponent tail owner added j e.1) = _ + rw [← hh, zpow_natCast, Nat.cast_pow] + ring + + + +def Realizes (L : E → G) (q₀ : ℕ) (K : Finset (E × ℚ)) + (b : Fin n → ℚ) (a : E × ℚ → G) : Prop := + ∀ e ∈ K, ∃ m : ℤ, qExponent i tail owner added q₀ b e = m ∧ a e = L e.1 ^ m + +lemma realizes_update + (htail : ∀ j a, a ∈ tail j → a < i) + (hadded : ∀ e a, a ∈ added e → a < i) + (hbefore : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c) + (L : E → G) (q₀ : ℕ) (K : Finset (E × ℚ)) (b : Fin n → ℚ) (a : E × ℚ → G) + (h : Realizes i tail owner added L q₀ K b a) (j k : ℕ) (hk : 0 < k) : + Realizes i tail owner added L q₀ K (update b i (tailAt tail j) k) + (fun e => a e ^ (k ^ lam tail owner added j e)) := by + intro e he + obtain ⟨m,hm,ha⟩ := h e he + refine ⟨m * (k ^ lam tail owner added j e : ℕ), ?_, ?_⟩ + · rw [qExponent_update i tail owner added htail hadded hbefore q₀ b j k hk e, hm] + push_cast + rfl + · dsimp only + rw [ha, zpow_mul, zpow_natCast] + +lemma realizes_run + (htail : ∀ j a, a ∈ tail j → a < i) + (hadded : ∀ e a, a ∈ added e → a < i) + (hbefore : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c) + (L : E → G) (q₀ : ℕ) (K : Finset (E × ℚ)) (C : Fin q → ℚ → X → κ) + (p : List (ℕ × FreeGroup (E × ℚ))) (hp : ∀ o ∈ p, 0 < o.1) + (j : ℕ) (b : Fin n → ℚ) (a : E × ℚ → G) (x : X) + (h : Realizes i tail owner added L q₀ K b a) : + let z := FiniteWordPlan.run (system i tail owner added C) j p (b,a) x + Realizes i tail owner added L q₀ K z.1.1 z.1.2 := by + induction p generalizing j b a x with + | nil => exact h + | cons o p ih => + apply ih (fun v hv => hp v (List.mem_cons_of_mem o hv)) + exact realizes_update i tail owner added htail hadded hbefore L q₀ K b a h j o.1 + (hp o (List.mem_cons_self)) + +def letters {A : Type*} (w : FreeGroup A) : Finset A := by + classical + exact (w.toWord.map Prod.fst).toFinset + +lemma lift_congr_on_letters {A : Type*} (a b : A → G) (w : FreeGroup A) + (h : ∀ t ∈ letters w, a t = b t) : FreeGroup.lift a w = FreeGroup.lift b w := by + classical + conv_lhs => rw [← FreeGroup.mk_toWord (x := w), FreeGroup.lift_mk] + conv_rhs => rw [← FreeGroup.mk_toWord (x := w), FreeGroup.lift_mk] + congr 1 + apply List.map_congr_left + intro u hu + have hu' : u.1 ∈ letters w := by + exact List.mem_toFinset.mpr (List.mem_map.mpr ⟨u,hu,rfl⟩) + rw [h u.1 hu'] + + + +def letter (L : E → G) (q₀ : ℕ) (b : Fin n → ℚ) (e : E × ℚ) : G := + L e.1 ^ (qExponent i tail owner added q₀ b e).num + +lemma realizes_lift (L : E → G) (q₀ : ℕ) (K : Finset (E × ℚ)) + (b : Fin n → ℚ) (a : E × ℚ → G) (h : Realizes i tail owner added L q₀ K b a) + (w : FreeGroup (E × ℚ)) (hw : letters w ⊆ K) : + FreeGroup.lift a w = FreeGroup.lift (letter i tail owner added L q₀ b) w := by + apply lift_congr_on_letters + intro e he + obtain ⟨m,hm,ha⟩ := h e (hw he) + simpa [letter,hm] using ha + + +theorem finite_denominator {A : Type*} (K : Finset A) (v : A → ℚ) : + ∃ q₀ : ℕ, 0 < q₀ ∧ ∀ a ∈ K, ∃ m : ℤ, (q₀ : ℚ) * v a = m := by + classical + let q₀ := ∏ a ∈ K, (v a).den + refine ⟨q₀, Finset.prod_pos (fun a _ => (v a).den_pos), ?_⟩ + intro a ha + have hd : (v a).den ∣ q₀ := Finset.dvd_prod_of_mem (fun a => (v a).den) ha + obtain ⟨d,hd⟩ := hd + refine ⟨(d : ℤ) * (v a).num, ?_⟩ + rw [hd] + push_cast + calc + (v a).den * (d : ℚ) * v a = d * ((v a).den * v a) := by ring + _ = _ := by + congr 1 + calc + ((v a).den : ℚ) * v a = (v a).den * ((v a).num / (v a).den) := by rw [Rat.num_div_den] + _ = (v a).num := mul_div_cancel₀ _ (by exact_mod_cast (v a).den_ne_zero) + +end +end RationalPivotPlan + +namespace RationalPivotPlan +open AlignmentScales +noncomputable section +variable {n q : ℕ} {E G X κ : Type*} [Group G] [MulAction G X] + (i : Fin n) (tail : Fin q → Finset (Fin n)) + (owner : E → Fin q) (added : E → Finset (Fin n)) + + + +def exactRun (L : E → G) (q₀ : ℕ) : + ℕ → List (ℕ × FreeGroup (E × ℚ)) → (Fin n → ℚ) → X → (Fin n → ℚ) × X + | _, [], b, x => (b,x) + | j, o :: p, b, x => exactRun L q₀ (j+1) p (update b i (tailAt tail j) o.1) + (FreeGroup.lift (letter i tail owner added L q₀ b) o.2 • x) + +lemma run_eq_exact + (htail : ∀ j a, a ∈ tail j → a < i) + (hadded : ∀ e a, a ∈ added e → a < i) + (hbefore : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c) + (L : E → G) (q₀ : ℕ) (K : Finset (E × ℚ)) (C : Fin q → ℚ → X → κ) + (p : List (ℕ × FreeGroup (E × ℚ))) + (hp : ∀ o ∈ p, 0 < o.1 ∧ letters o.2 ⊆ K) + (j : ℕ) (b : Fin n → ℚ) (a : E × ℚ → G) (x : X) + (h : Realizes i tail owner added L q₀ K b a) : + let z := FiniteWordPlan.run (system i tail owner added C) j p (b,a) x + (z.1.1,z.2) = exactRun i tail owner added L q₀ j p b x := by + induction p generalizing j b a x with + | nil => rfl + | cons o p ih => + have ho := hp o List.mem_cons_self + have hpre := realizes_update i tail owner added htail hadded hbefore L q₀ K b a h j o.1 ho.1 + simp only [FiniteWordPlan.run, exactRun] + change _ = exactRun i tail owner added L q₀ (j+1) p _ _ + calc + _ = exactRun i tail owner added L q₀ (j+1) p _ (FreeGroup.lift a o.2 • x) := + ih (fun v hv => hp v (List.mem_cons_of_mem o hv)) _ _ _ _ hpre + _ = _ := by rw [realizes_lift i tail owner added L q₀ K b a h o.2 ho.2] + +lemma realizes_letter (L : E → G) (q₀ : ℕ) (K : Finset (E × ℚ)) (b : Fin n → ℚ) + (h : ∀ e ∈ K, ∃ m : ℤ, qExponent i tail owner added q₀ b e = m) : + Realizes i tail owner added L q₀ K b (letter i tail owner added L q₀ b) := by + intro e he + obtain ⟨m,hm⟩ := h e he + exact ⟨m,hm, by simp [letter,hm]⟩ + + + +theorem integral_pivot_plan [Fintype κ] (s : ℕ) + (htail : ∀ j a, a ∈ tail j → a < i) + (hadded : ∀ e a, a ∈ added e → a < i) + (hbefore : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c) + (R : Finset ((Fin q × ℚ) × FreeGroup (E × ℚ))) : + ∃ P : Finset (List (ℕ × FreeGroup (E × ℚ))), + (∀ p ∈ P, p.length = q ∧ ∀ o ∈ p, 0 < o.1) ∧ + ∀ B : Finset (Fin n → ℚ), ∃ Q : ℕ, 0 < Q ∧ + ∀ q₀ : ℕ, Q ∣ q₀ → ∀ (G : Type*) [Group G] + (_hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) + (X : Type*) [MulAction G X] (C : Fin q → ℚ → X → κ) + (L : E → G) (b : Fin n → ℚ) (_hb : b ∈ B) (x : X), + ∃ p ∈ P, let z := exactRun i tail owner added L q₀ 0 p b x + FiniteWordPlan.Requirement + (fun l => C l.1 (l.2 * blockProduct z.1 (block i tail l.1))) + (letter i tail owner added L q₀ z.1) R z.2 := by + classical + obtain ⟨P,hP,hrec⟩ := rational_pivot_plan (κ := κ) i tail owner added s htail hbefore R + refine ⟨P,hP,?_⟩ + intro B + let K := (R.biUnion (fun r => letters r.2)) ∪ + P.biUnion (fun p => p.toFinset.biUnion (fun o => letters o.2)) + obtain ⟨Q,hQ,hclear⟩ := finite_denominator (B ×ˢ K) + (fun z => z.2.2 * (blockProduct z.1 (added z.2.1) / + blockProduct z.1 (block i tail (owner z.2.1)))) + refine ⟨Q,hQ,?_⟩ + intro q₀ hq₀ G _ hG X _ C L b hb x + obtain ⟨d,hd⟩ := hq₀ + have hreal := realizes_letter i tail owner added L q₀ K b (by + intro e he + obtain ⟨m,hm⟩ := hclear (b,e) (Finset.mem_product.mpr ⟨hb,he⟩) + refine ⟨(d : ℤ) * m,?_⟩ + dsimp only [qExponent] + rw [hd] + push_cast + calc + (Q : ℚ) * d * e.2 * (blockProduct b (added e.1) / + blockProduct b (block i tail (owner e.1))) = + d * ((Q : ℚ) * (e.2 * (blockProduct b (added e.1) / + blockProduct b (block i tail (owner e.1))))) := by ring + _ = _ := by rw [hm]) + obtain ⟨p,hp,hgood⟩ := hrec G hG X C b (letter i tail owner added L q₀ b) x + have hp' : ∀ o ∈ p, 0 < o.1 ∧ letters o.2 ⊆ K := by + intro o ho + refine ⟨(hP p hp).2 o ho, ?_⟩ + intro e he + exact Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨p,hp, + Finset.mem_biUnion.mpr ⟨o,List.mem_toFinset.mpr ho,he⟩⟩) + have heq := run_eq_exact i tail owner added htail hadded hbefore L q₀ K C p hp' 0 b + (letter i tail owner added L q₀ b) x hreal + have hrun := realizes_run i tail owner added htail hadded hbefore L q₀ K C p + (fun o ho => (hp' o ho).1) 0 b (letter i tail owner added L q₀ b) x hreal + refine ⟨p,hp,?_⟩ + rw [← heq] + dsimp only + intro r hr + have hw : letters r.2 ⊆ K := fun _ he => + Finset.mem_union_left _ (Finset.mem_biUnion.mpr ⟨r,hr,he⟩) + have hg := hgood r hr + rw [realizes_lift i tail owner added L q₀ K _ _ hrun r.2 hw] at hg + exact hg + +end +end RationalPivotPlan + + + +namespace GlobalWordPlan +open AlignmentScales RationalPivotPlan +noncomputable section + +structure Pivot (n : ℕ) where + index : Fin n + targets : ℕ + tail : Fin targets → Finset (Fin n) + pairs : ℕ + owner : Fin pairs → Fin targets + added : Fin pairs → Finset (Fin n) + tail_lt : ∀ j a, a ∈ tail j → a < index + added_lt : ∀ e a, a ∈ added e → a < index + before : ∀ e, ∃ a ∈ added e, ∀ c ∈ tail (owner e), a < c + +variable {n : ℕ} +abbrev Scale (n : ℕ) := Fin n → ℚ +abbrev Alphabet (D : Pivot n) := Fin D.pairs × ℚ +abbrev Path (D : Pivot n) := List (ℕ × FreeGroup (Alphabet D)) + +def scaleRun (D : Pivot n) : ℕ → Path D → Scale n → Scale n + | _, [], b => b + | j, o :: p, b => scaleRun D (j+1) p (update b D.index (tailAt D.tail j) o.1) + +lemma update_mul (b d : Scale n) (i : Fin n) (T : Finset (Fin n)) (k : ℚ) : + update (b*d) i T k = b * update d i T k := by + funext l + simp only [update, Pi.mul_apply] + ring + +lemma scaleRun_mul (D : Pivot n) (p : Path D) (j : ℕ) (b d : Scale n) : + scaleRun D j p (b*d) = b * scaleRun D j p d := by + induction p generalizing j d with + | nil => rfl + | cons o p ih => simp only [scaleRun,update_mul,ih] + +lemma scaleRun_eq_mul (D : Pivot n) (p : Path D) (j : ℕ) (b : Scale n) : + scaleRun D j p b = b * scaleRun D j p 1 := by + simpa only [mul_one] using scaleRun_mul D p j b 1 + +lemma exactRun_fst (D : Pivot n) {G X : Type*} [Group G] [MulAction G X] + (L : Fin D.pairs → G) (q₀ j : ℕ) (p : Path D) (b : Scale n) (x : X) : + (exactRun D.index D.tail D.owner D.added L q₀ j p b x).1 = scaleRun D j p b := by + induction p generalizing j b x with + | nil => rfl + | cons o p ih => exact ih _ _ _ + +lemma blockProduct_mul (b d : Scale n) (A : Finset (Fin n)) : + blockProduct (b*d) A = blockProduct b A * blockProduct d A := by + simp only [blockProduct,Pi.mul_apply,Finset.prod_mul_distrib] + +def adjust (D : Pivot n) (d : Scale n) (e : Alphabet D) : Alphabet D := + (e.1,e.2 * (blockProduct d (D.added e.1) / + blockProduct d (block D.index D.tail (D.owner e.1)))) + +lemma qExponent_adjust (D : Pivot n) (d b : Scale n) (q₀ : ℕ) (e : Alphabet D) : + qExponent D.index D.tail D.owner D.added q₀ b (adjust D d e) = + qExponent D.index D.tail D.owner D.added q₀ (b*d) e := by + simp only [qExponent,adjust,blockProduct_mul] + rw [mul_div_mul_comm] + ring + +lemma lift_adjust (D : Pivot n) (d b : Scale n) (q₀ : ℕ) + {G : Type*} [Group G] (L : Fin D.pairs → G) (w : FreeGroup (Alphabet D)) : + FreeGroup.lift (letter D.index D.tail D.owner D.added L q₀ b) + (FreeGroup.map (adjust D d) w) = + FreeGroup.lift (letter D.index D.tail D.owner D.added L q₀ (b*d)) w := by + have hh : (FreeGroup.lift (letter D.index D.tail D.owner D.added L q₀ b)).comp + (FreeGroup.map (adjust D d)) = + FreeGroup.lift (letter D.index D.tail D.owner D.added L q₀ (b*d)) := by + apply FreeGroup.ext_hom + intro e + simp only [MonoidHom.comp_apply,FreeGroup.map.of,FreeGroup.lift_apply_of,letter, + qExponent_adjust] + rfl + exact DFunLike.congr_fun hh w + + + +def baseWord (D : Pivot n) (U : Finset (Fin D.pairs)) : FreeGroup (Alphabet D) := + (U.toList.map (fun e => FreeGroup.of (e,(1:ℚ)))).prod + +def terminal (D : Pivot n) (F : Finset (Scale n)) : + Finset ((Fin D.targets × ℚ) × FreeGroup (Alphabet D)) := + F.biUnion (fun d => Finset.univ.biUnion (fun j : Fin D.targets => + ((Finset.univ.filter (fun e => D.owner e = j)).powerset).image + (fun U => ((j,blockProduct d (block D.index D.tail j)), + FreeGroup.map (adjust D d) (baseWord D U))))) + +def Good (D : Pivot n) {G X κ : Type*} [Group G] [MulAction G X] + (C : Fin D.targets → ℚ → X → κ) (L : Fin D.pairs → G) + (q₀ : ℕ) (b : Scale n) (x : X) : Prop := + ∀ (j : Fin D.targets) (U : Finset (Fin D.pairs)), (∀ e ∈ U, D.owner e = j) → + C j (blockProduct b (block D.index D.tail j)) x = + C j (blockProduct b (block D.index D.tail j)) + (FreeGroup.lift (letter D.index D.tail D.owner D.added L q₀ b) (baseWord D U) • x) + +lemma good_future (D : Pivot n) (F : Finset (Scale n)) + {G X κ : Type*} [Group G] [MulAction G X] + (C : Fin D.targets → ℚ → X → κ) (L : Fin D.pairs → G) + (q₀ : ℕ) (b : Scale n) (x : X) + (h : FiniteWordPlan.Requirement + (fun l => C l.1 (l.2 * blockProduct b (block D.index D.tail l.1))) + (letter D.index D.tail D.owner D.added L q₀ b) (terminal D F) x) + (d : Scale n) (hd : d ∈ F) : Good D C L q₀ (b*d) x := by + intro j U hU + have hmem : ((j,blockProduct d (block D.index D.tail j)), + FreeGroup.map (adjust D d) (baseWord D U)) ∈ terminal D F := by + apply Finset.mem_biUnion.mpr ⟨d,hd,?_⟩ + apply Finset.mem_biUnion.mpr ⟨j,Finset.mem_univ j,?_⟩ + apply Finset.mem_image.mpr ⟨U,?_,rfl⟩ + exact Finset.mem_powerset.mpr (fun e he => Finset.mem_filter.mpr ⟨Finset.mem_univ e,hU e he⟩) + have hh := h _ hmem + dsimp only at hh + rw [lift_adjust] at hh + simpa only [blockProduct_mul,mul_comm] using hh + + +theorem pivot_future_plan {κ : Type*} [Fintype κ] (s : ℕ) (D : Pivot n) + (F : Finset (Scale n)) : + ∃ P : Finset (Path D), + (∀ p ∈ P, p.length = D.targets ∧ ∀ o ∈ p, 0 < o.1) ∧ + ∀ B : Finset (Scale n), ∃ Q : ℕ, 0 < Q ∧ + ∀ q₀ : ℕ, Q ∣ q₀ → ∀ (G : Type*) [Group G] + (_hG : (⊤ : Subgroup G).lowerCentralSeries s = ⊥) + (X : Type*) [MulAction G X] (C : Fin D.targets → ℚ → X → κ) + (L : Fin D.pairs → G) (b : Scale n) (_hb : b ∈ B) (x : X), + ∃ p ∈ P, ∀ d ∈ F, + Good D C L q₀ (scaleRun D 0 p b * d) + (exactRun D.index D.tail D.owner D.added L q₀ 0 p b x).2 := by + obtain ⟨P,hP,h⟩ := integral_pivot_plan (κ := κ) D.index D.tail D.owner D.added s + D.tail_lt D.added_lt D.before (terminal D F) + refine ⟨P,hP,?_⟩ + intro B + obtain ⟨Q,hQ,h⟩ := h B + refine ⟨Q,hQ,?_⟩ + intro q₀ hq₀ G _ hG X _ C L b hb x + obtain ⟨p,hp,h⟩ := h q₀ hq₀ G hG X C L b hb x + refine ⟨p,hp,?_⟩ + intro d hd + have hg := good_future D F C L q₀ _ _ h d hd + simpa only [exactRun_fst] using hg + +end +end GlobalWordPlan + +namespace GlobalWordPlan +open AlignmentScales RationalPivotPlan +noncomputable section +universe u w +variable {n : ℕ} {κ : Type w} + + +def Plan : List (Pivot n) → Type + | [] => Unit + | D :: Ds => Finset (Path D) × Plan Ds + +def ChoicePath : List (Pivot n) → Type + | [] => Unit + | D :: Ds => Path D × ChoicePath Ds + +def Admitted : {Ds : List (Pivot n)} → Plan Ds → ChoicePath Ds → Prop + | [], _, _ => True + | _ :: _, P, p => p.1 ∈ P.1 ∧ Admitted P.2 p.2 + +def positivePlan : {Ds : List (Pivot n)} → Plan Ds → Prop + | [], _ => True + | D :: _, P => (∀ p ∈ P.1, p.length = D.targets ∧ ∀ o ∈ p, 0 < o.1) ∧ positivePlan P.2 + +def pathMultiplier : {Ds : List (Pivot n)} → ChoicePath Ds → Scale n + | [], _ => 1 + | D :: _, p => scaleRun D 0 p.1 1 * pathMultiplier p.2 + +def multipliers : {Ds : List (Pivot n)} → Plan Ds → Finset (Scale n) + | [], _ => {1} + | D :: _, P => P.1.biUnion (fun p => (multipliers P.2).image + (fun d => scaleRun D 0 p 1 * d)) + +lemma pathMultiplier_mem : {Ds : List (Pivot n)} → (P : Plan Ds) → (p : ChoicePath Ds) → + Admitted P p → pathMultiplier p ∈ multipliers P + | [], _, _, _ => Finset.mem_singleton.mpr rfl + | _ :: _, P, p, h => Finset.mem_biUnion.mpr ⟨p.1,h.1, + Finset.mem_image.mpr ⟨pathMultiplier p.2,pathMultiplier_mem P.2 p.2 h.2,rfl⟩⟩ + + + +structure Action (s : ℕ) (κ : Type w) (D : Pivot n) where + G : Type u + group : Group G + nilpotent : (⊤ : Subgroup G).lowerCentralSeries s = ⊥ + X : Type u + action : MulAction G X + palette : Fin D.targets → ℚ → X → κ + generators : Fin D.pairs → G + +attribute [instance] Action.group Action.action + +def Actions (s : ℕ) (κ : Type w) : List (Pivot n) → Type (max (u+1) w) + | [] => ULift.{max (u+1) w} Unit + | D :: Ds => Action.{u,w} s κ D × Actions s κ Ds + +def States {s : ℕ} : {Ds : List (Pivot n)} → Actions.{u,w} s κ Ds → Type (max (u+1) w) + | [], _ => ULift.{max (u+1) w} Unit + | _ :: _, A => A.1.X × States A.2 + + +def execute {s : ℕ} : {Ds : List (Pivot n)} → (A : Actions.{u,w} s κ Ds) → + ℕ → ChoicePath Ds → Scale n → States A → Scale n × States A + | [], _, _, _, b, x => (b,x) + | D :: _, A, q₀, p, b, x => + let z := exactRun D.index D.tail D.owner D.added A.1.generators q₀ 0 p.1 b x.1 + let y := execute A.2 q₀ p.2 z.1 x.2 + (y.1,(z.2,y.2)) + +def allGood {s : ℕ} : {Ds : List (Pivot n)} → (A : Actions.{u,w} s κ Ds) → + ℕ → Scale n → States A → Prop + | [], _, _, _, _ => True + | D :: _, A, q₀, b, x => + Good D A.1.palette A.1.generators q₀ b x.1 ∧ allGood A.2 q₀ b x.2 + +lemma execute_fst {s : ℕ} : {Ds : List (Pivot n)} → (A : Actions.{u,w} s κ Ds) → + (q₀ : ℕ) → (p : ChoicePath Ds) → (b : Scale n) → (x : States A) → + (execute A q₀ p b x).1 = b * pathMultiplier p + | [], _, _, _, _, _ => (mul_one _).symm + | D :: _, A, q₀, p, b, x => by + change (execute A.2 q₀ p.2 _ x.2).1 = _ + rw [execute_fst A.2,exactRun_fst,scaleRun_eq_mul] + exact mul_assoc _ _ _ + + + +theorem finite_word_plan [Fintype κ] (s : ℕ) (Ds : List (Pivot n)) : + ∃ P : Plan Ds, positivePlan P ∧ + ∀ B : Finset (Scale n), ∃ Q : ℕ, 0 < Q ∧ + ∀ q₀ : ℕ, Q ∣ q₀ → ∀ (A : Actions.{u,w} s κ Ds) + (b : Scale n) (_hb : b ∈ B) (x : States A), + ∃ p : ChoicePath Ds, Admitted P p ∧ + allGood A q₀ (execute A q₀ p b x).1 (execute A q₀ p b x).2 := by + classical + induction Ds with + | nil => + refine ⟨(),True.intro,?_⟩ + intro B + refine ⟨1,by decide,?_⟩ + intro q₀ _ A b _ x + exact ⟨(),True.intro,True.intro⟩ + | cons D Ds ih => + obtain ⟨Ptail,hposTail,hTail⟩ := ih + obtain ⟨Phead,hposHead,hHead⟩ := pivot_future_plan (κ := κ) s D (multipliers Ptail) + refine ⟨(Phead,Ptail),⟨hposHead,hposTail⟩,?_⟩ + intro B + let Bnext := B.biUnion (fun b => Phead.image (fun p => scaleRun D 0 p b)) + obtain ⟨Qhead,hQhead,hHead⟩ := hHead B + obtain ⟨Qtail,hQtail,hTail⟩ := hTail Bnext + refine ⟨Qhead * Qtail,Nat.mul_pos hQhead hQtail,?_⟩ + intro q₀ hq₀ A b hb x + have hdivHead : Qhead ∣ q₀ := dvd_trans (dvd_mul_right Qhead Qtail) hq₀ + have hdivTail : Qtail ∣ q₀ := dvd_trans (dvd_mul_left Qtail Qhead) hq₀ + obtain ⟨phead,hphead,hgoodHead⟩ := hHead q₀ hdivHead A.1.G A.1.nilpotent + A.1.X A.1.palette A.1.generators b hb x.1 + let z := exactRun D.index D.tail D.owner D.added A.1.generators q₀ 0 phead b x.1 + have hz : z.1 ∈ Bnext := by + rw [exactRun_fst] + exact Finset.mem_biUnion.mpr ⟨b,hb,Finset.mem_image.mpr ⟨phead,hphead,rfl⟩⟩ + obtain ⟨ptail,hptail,hgoodTail⟩ := hTail q₀ hdivTail A.2 z.1 hz x.2 + refine ⟨(phead,ptail),⟨hphead,hptail⟩,?_,hgoodTail⟩ + have hg := hgoodHead (pathMultiplier ptail) (pathMultiplier_mem Ptail ptail hptail) + change Good D A.1.palette A.1.generators q₀ + (execute A.2 q₀ ptail z.1 x.2).1 z.2 + rw [execute_fst,exactRun_fst] + exact hg + +end +end GlobalWordPlan + +end ConstructedWordPlan + + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan02.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan02.lean new file mode 100644 index 0000000000000000000000000000000000000000..badda0e9bdeabe0cb2e036097b59fce38e733978 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan02.lean @@ -0,0 +1,278 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.AlignmentMass01 +import OAI.Combinatorics.SumProduct.Alignment.RationalLattice24 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +end + +section + + +noncomputable section +open Filter Topology MeasureTheory +namespace ConstructedWordPlan.GlobalWordPlan +open AlignmentScales RationalPivotPlan PolynomialShearPoint +open FilteredShears.PolynomialShears +variable {n k r : ℕ} (D : Pivot n) +abbrev Slots := Fin D.pairs → ℤ +abbrev Shifts := Multiplicative (Slots D) + +def unitShift (e : Fin D.pairs) : Shifts D := Multiplicative.ofAdd (Pi.single e 1) + +def generators (w : Fin k → ℕ) (A : Fin D.pairs → shears (R:=ℝ) w) : + Fin D.pairs → CoverGroup w (Fin D.pairs) := fun e=>(A e,unitShift D e) + +def terminalShift (q₀ : ℕ) (b : Scale n) (U : Finset (Fin D.pairs)) : Shifts D := + FreeGroup.lift (letter D.index D.tail D.owner D.added (unitShift D) q₀ b) (baseWord D U) + +def jumpSlot (q₀ : ℕ) (p : Path D) (b : Scale n) : Slots D := + (jump D (unitShift D) q₀ 0 p b).toAdd + +lemma lift_map {G H E : Type*} [Group G] [Group H] (f : G →* H) (a : E → G) + (u : FreeGroup E) : f (FreeGroup.lift a u)=FreeGroup.lift (fun e=>f (a e)) u := by + have he : f.comp (FreeGroup.lift a)=FreeGroup.lift (fun e=>f (a e)) := by + apply FreeGroup.ext_hom + intro e + simp + exact DFunLike.congr_fun he u + +lemma jump_map {G H : Type*} [Group G] [Group H] (f : G →* H) + (L : Fin D.pairs → G) (q₀ j : ℕ) (p : Path D) (b : Scale n) : + f (jump D L q₀ j p b)=jump D (fun e=>f (L e)) q₀ j p b := by + induction p generalizing j b with + | nil => simp [jump] + | cons o p ih => + simp only [jump,map_mul,ih,lift_map] + have he : (fun e=>f (letter D.index D.tail D.owner D.added L q₀ b e))= + letter D.index D.tail D.owner D.added (fun e=>f (L e)) q₀ b := by + funext e + simp [letter] + rw [he] + +lemma jump_slot (w : Fin k → ℕ) (A : Fin D.pairs → shears (R:=ℝ) w) + (q₀ : ℕ) (p : Path D) (b : Scale n) : + (jump D (generators D w A) q₀ 0 p b).2.toAdd=jumpSlot D q₀ p b := by + exact congrArg Multiplicative.toAdd + (jump_map D (MonoidHom.snd (shears (R:=ℝ) w) (Shifts D)) (generators D w A) q₀ 0 p b) + +abbrev OwnSubset (j : Fin D.targets) := + {U : Finset (Fin D.pairs) // ∀ e∈U,D.owner e=j} +abbrev Comparison (F : Finset (Scale n)) (r : ℕ) := + {d : Scale n // d∈F} × (Σ j : Fin D.targets, OwnSubset D j) × Fin r + +variable {X : Type*} (Y : Fin D.targets → Type*) +variable [∀ j,MulAction (Shifts D) (Y j)] +variable (π : (j : Fin D.targets) → X → Y j) +variable (Read : (j : Fin D.targets) → ℚ → Y j × Slots D → Fin r → ℝ) + + +def palette (τ : ℝ) (Θ : (Fin k → ℝ) → X) : + Fin D.targets → ℚ → CoverState (σ:=Fin k) (Fin D.pairs) → (Fin r → Bool) := + fun j a x c=>decide (3*τ/2 < Read j a (π j (Θ x.1),x.2) c) + +def centerReading (F : Finset (Scale n)) (q₀ : ℕ) (b : Scale n) (p : Path D) + (i : Comparison D F r) (x : X) : ℝ := + Read i.2.1.1 (blockProduct (scaleRun D 0 p b*i.1.val) (block D.index D.tail i.2.1.1)) + (π i.2.1.1 x,jumpSlot D q₀ p b) i.2.2 + +def translatedReading (F : Finset (Scale n)) (q₀ : ℕ) (b : Scale n) (p : Path D) + (i : Comparison D F r) (x : X) : ℝ := + Read i.2.1.1 (blockProduct (scaleRun D 0 p b*i.1.val) (block D.index D.tail i.2.1.1)) + (terminalShift D q₀ (scaleRun D 0 p b*i.1.val) i.2.1.2.val • + (π i.2.1.1 x,jumpSlot D q₀ p b)) i.2.2 + + + +lemma own_state_reading (w : Fin k → ℕ) (A : Fin D.pairs → shears (R:=ℝ) w) + (Θ : (Fin k → ℝ) → X) + (hown : ∀ j e,D.owner e=j → ∀ z, + π j (Θ (A e • z))=unitShift D e • π j (Θ z)) + (j : Fin D.targets) (q₀ : ℕ) (b : Scale n) (U : OwnSubset D j) + (x : CoverState (σ:=Fin k) (Fin D.pairs)) : + let u:=FreeGroup.lift (letter D.index D.tail D.owner D.added (generators D w A) q₀ b) + (baseWord D U.val) + (π j (Θ (u • x).1),(u • x).2)=terminalShift D q₀ b U.val • (π j (Θ x.1),x.2) := by + apply OwnTerminal.terminal_projection D (fun x=>(π j (Θ x.1),x.2)) + (generators D w A) (unitShift D) j _ q₀ b U.val U.property x + intro e he x + ext + · exact hown j e he x.1 + · rfl + +end ConstructedWordPlan.GlobalWordPlan +end + +end + +section + + +noncomputable section +namespace ConstructedWordPlan.GlobalWordPlan +open AlignmentScales RationalPivotPlan PolynomialShearPoint +open FilteredShears.PolynomialShears +variable {n k r : ℕ} (D : Pivot n) +variable {X : Type*} {Y : Fin D.targets → Type*} +variable [∀ j,MulAction (Shifts D) (Y j)] +variable (π : (j : Fin D.targets) → X → Y j) +variable (Read : (j : Fin D.targets) → ℚ → Y j × Slots D → Fin r → ℝ) + + + +def closedOption (F : Finset (Scale n)) (τ : ℝ) (q₀ : ℕ) (b : Scale n) + (p : Path D) : Set X := AlignmentMass.ClosedGood τ + (centerReading D Y π Read F q₀ b p) (translatedReading D Y π Read F q₀ b p) + + + +lemma closed_cover (w : Fin k → ℕ) (A : Fin D.pairs → shears (R:=ℝ) w) + (Θ : (Fin k → ℝ) → X) + (hown : ∀ j e,D.owner e=j → ∀ z, + π j (Θ (A e • z))=unitShift D e • π j (Θ z)) + (F : Finset (Scale n)) (P : Finset (Path D)) (τ : ℝ) (q₀ : ℕ) (b : Scale n) + (hp : ∀ x : CoverState (σ:=Fin k) (Fin D.pairs), ∃ p∈P,∀ d∈F, + Good D (palette D Y π Read τ Θ) (generators D w A) q₀ (scaleRun D 0 p b*d) + (exactRun D.index D.tail D.owner D.added (generators D w A) q₀ 0 p b x).2) + (z : Fin k → ℝ) : + ∃ p∈P, Θ ((jump D (generators D w A) q₀ 0 p b).1 • z) ∈ + closedOption D π Read F τ q₀ b p := by + classical + obtain ⟨p,hpP,hgood⟩:=hp (z,0) + refine ⟨p,hpP,?_⟩ + intro i + let x : CoverState (σ:=Fin k) (Fin D.pairs):= + (jump D (generators D w A) q₀ 0 p b) • (z,0) + have hx : (exactRun D.index D.tail D.owner D.added (generators D w A) q₀ 0 p b (z,0)).2=x := + exactRun_snd D _ _ _ _ _ _ + have hv : x.2=jumpSlot D q₀ p b := by + dsimp [x] + simp only [add_zero,jump_slot] + have he:=congrFun (hgood i.1.val i.1.property i.2.1.1 i.2.1.2.val i.2.1.2.property) i.2.2 + rw [hx] at he + have hr:=own_state_reading D Y π w A Θ hown i.2.1.1 q₀ + (scaleRun D 0 p b*i.1.val) i.2.1.2 x + dsimp only at hr + dsimp only [palette] at he + rw [hr] at he + have he' : (3*τ/2 < centerReading D Y π Read F q₀ b p i (Θ x.1)) ↔ + (3*τ/2 < translatedReading D Y π Read F q₀ b p i (Θ x.1)) := by + simpa only [centerReading,translatedReading,hv] using (decide_eq_decide.mp he) + suffices centerReading D Y π Read F q₀ b p i (Θ x.1) ≤ 3*τ/2 ∨ + 3*τ/2 ≤ translatedReading D Y π Read F q₀ b p i (Θ x.1) from this + by_cases h : 3*τ/2 < centerReading D Y π Read F q₀ b p i (Θ x.1) + · right + exact le_of_lt (he'.mp h) + · exact Or.inl (le_of_not_gt h) + +open Topology +variable [TopologicalSpace X] [∀ j,TopologicalSpace (Y j)] + +omit [∀ j,MulAction (Shifts D) (Y j)] in +lemma centerReading_continuous + (hπ : ∀ j,Continuous (π j)) + (hRead : ∀ j a c,Continuous (fun y=>Read j a y c)) + (F : Finset (Scale n)) (q₀ : ℕ) (b : Scale n) (p : Path D) + (i : Comparison D F r) : Continuous (centerReading D Y π Read F q₀ b p i) := by + exact (hRead _ _ _).comp ((hπ _).prodMk continuous_const) + +lemma translatedReading_continuous + (hπ : ∀ j,Continuous (π j)) + (hRead : ∀ j a c,Continuous (fun y=>Read j a y c)) + (hS : ∀ j (a : Shifts D),Continuous (fun y : Y j=>a • y)) + (F : Finset (Scale n)) (q₀ : ℕ) (b : Scale n) (p : Path D) + (i : Comparison D F r) : Continuous (translatedReading D Y π Read F q₀ b p i) := by + let t:=terminalShift D q₀ (scaleRun D 0 p b*i.1.val) i.2.1.2.val + exact (hRead _ _ _).comp (((hS _ t).comp (hπ _)).prodMk + (show Continuous (fun _ : X=>t • jumpSlot D q₀ p b) from continuous_const)) + +lemma closedOption_isClosed + (hπ : ∀ j,Continuous (π j)) + (hRead : ∀ j a c,Continuous (fun y=>Read j a y c)) + (hS : ∀ j (a : Shifts D),Continuous (fun y : Y j=>a • y)) + (F : Finset (Scale n)) (τ : ℝ) (q₀ : ℕ) (b : Scale n) (p : Path D) : + IsClosed (closedOption D π Read F τ q₀ b p) := + AlignmentMass.isClosed_closedGood _ _ _ + (centerReading_continuous D π Read hπ hRead F q₀ b p) + (translatedReading_continuous D π Read hπ hRead hS F q₀ b p) + +end ConstructedWordPlan.GlobalWordPlan +end + +end + +section + + +noncomputable section +open MeasureTheory Filter Topology +open scoped NNReal ENNReal +namespace RationalLattice +open MalcevCharacters PolynomialShearPoint FilteredShears.PolynomialShears WeightedBoxes +variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {n : ℕ} (c : RealCoordinates G n) +variable (Γ : Subgroup G) [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] +variable {X : Type*} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + + +def shearedPoint (q : C(G⧸Γ,X)) {w : Fin n → ℕ} (A : shears (R:=ℝ) w) : C((Fin n → ℝ),X) := + q.comp ((expQuotient c Γ).comp ⟨pointMap A.val.toAlgHom,pointMap_continuous _⟩) + +omit [IsTopologicalGroup G] in +lemma weightedShear_imageLaw (q : C(G⧸Γ,X)) (w : Fin n → ℕ) + (A : shears (R:=ℝ) w) (E : ℝ) : + (weightedShearLaw c w Γ A E).map q= + (boxLaw w E).map (shearedPoint c Γ q A) := by + apply Subtype.ext + change Measure.map q (Measure.map (expQuotient c Γ) + (Measure.map (pointMap A.val.toAlgHom) (boxLaw w E : Measure (Fin n → ℝ))))=_ + rw [Measure.map_map q.continuous.measurable (expQuotient c Γ).continuous.measurable, + Measure.map_map (q.continuous.comp (expQuotient c Γ).continuous).measurable + (pointMap_continuous A.val.toAlgHom).measurable] + rfl + +variable (hsk : SecondKind c) (H : CubeFaces.Filtration G) +variable (w : Fin n → ℕ) (hw : ∀ i,0 + (weightedShearLaw c w Γ (A o) (N:ℝ)).map q := by + funext N + exact (weightedShear_imageLaw c Γ q w (A o) N).symm + rw [he] + exact (weightedShear_pointImage_limit c hsk H w hw hH Γ hΓ μ (A o) q).comp + tendsto_natCast_atTop_atTop + · intro N + exact AlignmentMass.cover_sum (boxLaw w (N:ℝ)) + (fun o=>shearedPoint c Γ q (A o)) + (fun o=>(shearedPoint c Γ q (A o)).continuous.measurable) F + (fun o=>(hF o).measurableSet) hcover + +end RationalLattice + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan03.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan03.lean new file mode 100644 index 0000000000000000000000000000000000000000..d17071aeaeeba09a62d79af56fe0d282554dd2dc --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan03.lean @@ -0,0 +1,258 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.AffineOrbit01 +import OAI.Combinatorics.SumProduct.Alignment.AllLevel12 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +noncomputable section +end + +end + +section + + + + +noncomputable section +namespace RationalLattice +open CubeFaces MalcevCharacters CompactGroupProducts +open FilteredShears.PolynomialShears PolynomialShearPoint +variable {G A : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable [Group A] [TopologicalSpace A] [IsTopologicalGroup A] +variable (Λ J : Subgroup A) [T2Space J] +variable {n m : ℕ} (c : RealCoordinates G n) (d : RealCoordinates J m) +variable (hsk : SecondKind c) (hdsk : SecondKind d) +variable (H : Filtration G) (K : Filtration J) +variable (w : Fin n → ℕ) (v : Fin m → ℕ) +variable (hw : ∀ i,0Read j a y t)) +variable (hS : ∀ j (a : Shifts D),Continuous (fun y : Y j=>a • y)) +variable (M : ∀ a : Fin E.period,∀ β : ℝ, + PhysicalMarginalFaceData D (C a).pivotChart.chart (C a).pointFiltration (C a).pointLattice + π ((C a).pivotImage β) s) + +include hπ hRead hS M hq₀ hb in + + +omit [CompactSpace (G⧸Γ)] in +theorem physical_pivot_mixture_mass : + (((pivotOptions s r hs D F).card : ℝ≥0)⁻¹ : ℝ≥0∞) ≤ + (E.pointMixture C : Measure (G⧸Γ)) + (⋃ p∈pivotOptions s r hs D F,closedOption D π Read F τ q₀ b p) := by + classical + let S : Set (G⧸Γ):=⋃ p∈pivotOptions s r hs D F,closedOption D π Read F τ q₀ b p + have hSmeas : MeasurableSet S := by + apply MeasurableSet.biUnion (pivotOptions s r hs D F).countable_toSet + intro p hp + exact (closedOption_isClosed D π Read hπ hRead hS F τ q₀ b p).measurableSet + let : Nonempty (Fin E.period):=⟨⟨0,E.period_pos⟩⟩ + apply ProbabilityMixtures.betaResidue_lower (fun a=>(C a).pointHaar) + (fun _=>E.smoothAction) S hSmeas + intro a + apply Eventually.of_forall + intro β + let T:=(C a).pivotChart + obtain ⟨A,hA⟩:=own_lifts_from_physical_faces D T.chart (C a).pointFiltration + (C a).pointLattice π ((C a).pivotImage β) T.secondKind + T.weights T.positive T.monotone T.adapted (M a β) + have hm:=pivotOptions_mass s r hs D F B q₀ hq₀ b hb τ + T.dim (CubeGroup (F:=E) (ι:=Empty)) T.chart T.secondKind + (C a).pointFiltration T.weights T.positive T.bounded T.adapted + (C a).pointLattice (G⧸Γ) Y π Read T.integer_lattice + ((C a).haar (ι:=Empty)) ((C a).pivotImage β) A hπ hRead hS hA + exact ((C a).pivotImage_event β S hSmeas) ▸ hm + +end AllLevelFactorization.Factorization +end + +end + +end + +end OAI diff --git a/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan04.lean b/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan04.lean new file mode 100644 index 0000000000000000000000000000000000000000..f66c06a08ece88d1b8da5fdc4cd299bb35196af3 --- /dev/null +++ b/lean/OAI/Combinatorics/SumProduct/Alignment/WordPlan04.lean @@ -0,0 +1,271 @@ +import Mathlib +import OAI.Combinatorics.SumProduct.Alignment.AllLevel13 +import OAI.Geometry.NilpotentCharts.Main + +namespace OAI + +open scoped BigOperators +section +section +noncomputable section +open scoped Topology +open MeasureTheory Filter +end + +end + +section + + + + +noncomputable section +namespace ConstructedWordPlan.GlobalWordPlan +open AlignmentScales RationalPivotPlan PolynomialShearPoint RationalLattice MalcevCharacters +open FilteredShears.PolynomialShears +variable {n k : ℕ} (D : Pivot n) +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable (c : RealCoordinates G k) (H : _root_.OAI.CubeFaces.Filtration G) (Γ : Subgroup G) +variable {X : Type} [TopologicalSpace X] +variable {Y : Fin D.targets → Type} [∀ j,MulAction (Shifts D) (Y j)] +variable (π : (j : Fin D.targets) → X → Y j) (q : C(G⧸Γ,X)) + + + +structure CoveredPhysicalData (s : ℕ) where + A : Fin D.targets → Type + [group : ∀ j,Group (A j)] + [topology : ∀ j,TopologicalSpace (A j)] + [topGroup : ∀ j,IsTopologicalGroup (A j)] + dim : Fin D.targets → ℕ + chart : ∀ j,RealCoordinates (A j) (dim j) + Λ : ∀ j,Subgroup (A j) + cover : ∀ j,CoveredLattice (chart j) (Λ j) + offset : ∀ j,A j + residue : ∀ j,A j + residue_rational : ∀ j,IsRational (chart j) (residue j) + projection : ∀ j,G →* A j + continuous : ∀ j,Continuous (projection j) + rational : ∀ j g,IsRational c g → IsRational (chart j) (projection j g) + physical : ∀ j,(A j)⧸Λ j → Y j + physicalProjection : ∀ j z,π j (q (expQuotient c Γ z))= + physical j (QuotientGroup.mk (offset j*projection j (canonicalExp c z)*residue j)) + symmetry : (e : Fin D.pairs) → A (D.owner e) →* A (D.owner e) + symmetryContinuous : ∀ e,Continuous (symmetry e) + preservesPhysicalFaces : ∀ e,AffineOrbitRestriction.PreservesPhysicalFaces + (Λ (D.owner e)) (projection (D.owner e)).range (offset (D.owner e)) (residue (D.owner e)) + (LeibmanSquare.mapFiltration H (projection (D.owner e)).rangeRestrict) (symmetry e) s + ownPhysical : ∀ e (y : (projection (D.owner e)).range), + physical (D.owner e) (QuotientGroup.mk + (symmetry e (offset (D.owner e)*(y:A (D.owner e))*residue (D.owner e))))= + unitShift D e • physical (D.owner e) (QuotientGroup.mk + (offset (D.owner e)*(y:A (D.owner e))*residue (D.owner e))) +attribute [instance] CoveredPhysicalData.group CoveredPhysicalData.topology CoveredPhysicalData.topGroup + +variable (hsk : SecondKind c) (w : Fin k → ℕ) (hw : ∀ i,0(M.projection j).range + t2:=ht2, Λ:=M.Λ, offset:=M.offset, residue:=M.residue + compact:=hcomp + quotient_t2:=fun j=>CoveredLattice.conjugate_quotient_t2 (M.chart j) (M.Λ j) (M.cover j) (M.residue j) + dim:=fun j=>(T j).dim, chart:=fun j=>(T j).chart + secondKind:=fun j=>(T j).secondKind + filtration:=fun j=>LeibmanSquare.mapFiltration H (M.projection j).rangeRestrict + weights:=fun j=>(T j).weights, positive:=fun j=>(T j).positive + monotone:=fun j=>(T j).monotone, adapted:=fun j=>(T j).adapted + terminal:=?_,discreteAmbient:=?_,discrete:=?_,compactReps:=?_ + projection:=fun j=>(M.projection j).rangeRestrict + continuous:=fun j=>(M.continuous j).subtype_mk _ + onto:=fun _ _=>rfl + physical:=M.physical,physicalProjection:=M.physicalProjection + symmetry:=M.symmetry,symmetryContinuous:=M.symmetryContinuous + preservesPhysicalFaces:=M.preservesPhysicalFaces,ownPhysical:=M.ownPhysical } + · intro j + change (H.level (s+1)).map (M.projection j).rangeRestrict=⊥ + rw [hs,Subgroup.map_bot] + · intro j + exact isDiscrete_iff_discreteTopology.mpr + (CoveredLattice.conjugate_discrete (M.chart j) (M.Λ j) (M.cover j) (M.residue j)) + · intro j + exact isDiscrete_iff_discreteTopology.mpr + (CoveredLattice.conjugate_induced_discrete (M.chart j) (M.Λ j) (M.cover j) + (M.projection j).range.subtype continuous_subtype_val Subtype.val_injective (M.residue j)) + · intro j l + exact ImageGeometry.covered_level_compact_reps (M.chart j) (M.Λ j) H (M.projection j) (T j) (M.cover j) + (M.residue j) (M.residue_rational j) l + +include hsk hw hmono hH hs M in +theorem own_lifts_from_covered_physical_faces : + ∃ A : Fin D.pairs → shears (R:=ℝ) w, + ∀ j e,D.owner e=j → ∀ z, + π j (q (expQuotient c Γ (A e • z)))= + unitShift D e • π j (q (expQuotient c Γ z)) := by + exact own_lifts_from_physical_faces D c H Γ π q hsk w hw hmono hH + (CoveredPhysicalData.toPhysical D c H Γ π q hsk w hw hmono hH hs M) + +end ConstructedWordPlan.GlobalWordPlan +end + +end + +section + + + + +noncomputable section +open MeasureTheory Filter Topology +open scoped NNReal ENNReal +namespace AllLevelFactorization.Factorization +open RationalLattice CubeFaces ResidueCover +open ConstructedWordPlan.GlobalWordPlan +open ConstructedWordPlan.AlignmentScales ConstructedWordPlan.RationalPivotPlan +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {k s : ℕ} {c : RealCoordinates G k} {Γ : Subgroup G} +variable {K : Filtration G} {P : ℕ → ℤ → G} {L : ℕ → ℝ} +variable (E : Factorization c Γ s K P L) +variable (C : (r : Fin E.period) → E.ResidueCover r) +variable [∀ r,MeasurableSpace ((C r).CubeSpace (ι:=Empty))] +variable [∀ r,BorelSpace ((C r).CubeSpace (ι:=Empty))] +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] +variable [CompactSpace (G⧸Γ)] [SecondCountableTopology (G⧸Γ)] +variable [HasOuterApproxClosed (G⧸Γ)] [MeasurableSingletonClass (G⧸Γ)] +variable {n r : ℕ} (hs : 1 ≤ s) (D : Pivot n) +variable (F B : Finset (Scale n)) +variable (q₀ : ℕ) (hq₀ : pivotModulus s r hs D F B∣q₀) +variable (b : Scale n) (hb : b∈B) {τ : ℝ} (hτ : 0<τ) +variable (Y : Fin D.targets → Type) [∀ j,TopologicalSpace (Y j)] +variable [∀ j,MulAction (Shifts D) (Y j)] +variable (π : (j : Fin D.targets) → (G⧸Γ) → Y j) +variable (Read : (j : Fin D.targets) → ℚ → Y j × Slots D → Fin r → ℝ) +variable (hπ : ∀ j,Continuous (π j)) +variable (hRead : ∀ j a t,Continuous (fun y=>Read j a y t)) +variable (hS : ∀ j (a : Shifts D),Continuous (fun y : Y j=>a • y)) +variable (M : ∀ a : Fin E.period,∀ β : ℝ, + CoveredPhysicalData D (C a).pivotChart.chart (C a).pointFiltration (C a).pointLattice + π ((C a).pivotImage β) s) + +include hπ hRead hS M hq₀ hb hτ in + + +theorem covered_physical_pivot_empirical_success_mass (hL : ∀ N,0CoveredPhysicalData.toPhysical D (C a).pivotChart.chart + (C a).pointFiltration (C a).pointLattice π ((C a).pivotImage β) + (C a).pivotChart.secondKind (C a).pivotChart.weights (C a).pivotChart.positive + (C a).pivotChart.monotone (C a).pivotChart.adapted + (CubeMaxFiltration.filtration_bot E.state.domain.filtration Finset.univ E.state.domain.terminal) + (M a β)) hL ht ReadN he + +end AllLevelFactorization.Factorization +end + +end + +section + + + + +noncomputable section +open MeasureTheory Filter Topology +open scoped NNReal ENNReal +namespace AllLevelFactorization.Factorization +open RationalLattice CubeFaces ResidueCover +open ConstructedWordPlan.GlobalWordPlan +open ConstructedWordPlan.AlignmentScales ConstructedWordPlan.RationalPivotPlan +variable {G : Type} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] +variable {k s : ℕ} {c : RealCoordinates G k} {Δ : Subgroup G} +variable {K : Filtration G} {P : ℕ → ℤ → G} {L : ℕ → ℝ} +variable (E : Factorization c Δ s K P L) +variable (C : (r : Fin E.period) → E.ResidueCover r) +variable [∀ r,MeasurableSpace ((C r).CubeSpace (ι:=Empty))] +variable [∀ r,BorelSpace ((C r).CubeSpace (ι:=Empty))] +variable [MeasurableSpace (G⧸Δ)] [BorelSpace (G⧸Δ)] +variable [CompactSpace (G⧸Δ)] [SecondCountableTopology (G⧸Δ)] +variable [HasOuterApproxClosed (G⧸Δ)] [MeasurableSingletonClass (G⧸Δ)] +variable (Γ : Subgroup G) (hle : Δ≤Γ) +variable [MeasurableSpace (G⧸Γ)] [BorelSpace (G⧸Γ)] [MeasurableSingletonClass (G⧸Γ)] +variable {n r : ℕ} (hs : 1 ≤ s) (D : Pivot n) (F B : Finset (Scale n)) +variable (q₀ : ℕ) (hq₀ : pivotModulus s r hs D F B∣q₀) +variable (b : Scale n) (hb : b∈B) {τ : ℝ} (hτ : 0<τ) +variable (Y : Fin D.targets → Type) [∀ j,TopologicalSpace (Y j)] +variable [∀ j,MulAction (Shifts D) (Y j)] +variable (π : (j : Fin D.targets) → (G⧸Γ) → Y j) +variable (Read : (j : Fin D.targets) → ℚ → Y j × Slots D → Fin r → ℝ) +variable (hπ : ∀ j,Continuous (π j)) +variable (hRead : ∀ j a t,Continuous (fun y=>Read j a y t)) +variable (hS : ∀ j (a : Shifts D),Continuous (fun y : Y j=>a • y)) +variable (M : ∀ a : Fin E.period,∀ β : ℝ, + CoveredPhysicalData D (C a).pivotChart.chart (C a).pointFiltration (C a).pointLattice + (fun j z=>π j (CosetCover.map Δ Γ hle z)) ((C a).pivotImage β) s) + +include hπ hRead hS M hq₀ hb hτ in + + +omit [BorelSpace (G⧸Γ)] in +theorem actual_lattice_pivot_empirical_success_mass + (hL : ∀ N,0(hπ j).comp (CosetCover.continuous_map Δ Γ hle)) hRead hS M hL ht ReadN he' + filter_upwards [H] with N hN + let S : Set (G⧸Γ):=⋃ p∈pivotOptions s r hs D F,AlignmentMass.Success τ + (centerReading D Y π (ReadN N) F q₀ b p) + (translatedReading D Y π (ReadN N) F q₀ b p) + have heq:=ProbabilityMixtures.empirical_preimage ⌊L (E.state.subseq N)⌋₊ + (fun z=>(QuotientGroup.mk (P (E.state.subseq N) (z:ℤ)) : G⧸Δ)) f S + change _ < (ProbabilityMixtures.empirical ⌊L (E.state.subseq N)⌋₊ + (fun z=>f (QuotientGroup.mk (P (E.state.subseq N) (z:ℤ)))) : Measure (G⧸Γ)) S + rw [←heq] + convert hN using 1 + congr 1 + ext z + simp only [S,Set.mem_preimage,Set.mem_iUnion,AlignmentMass.Success,Set.mem_ofPred_eq] + rfl + +end AllLevelFactorization.Factorization + +end +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Affine.lean b/lean/OAI/Combinatorics/ThinTrees/Affine.lean new file mode 100644 index 0000000000000000000000000000000000000000..c8913648aac637f27a0f87bda148521f22f2c819 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Affine.lean @@ -0,0 +1,70 @@ +import OAI.Combinatorics.ThinTrees.MixedPolynomial + +namespace OAI + +universe uI uD uR uO uO2 uO3 + +section + +noncomputable section +open Matrix Polynomial Finset +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [CommRing R] + +lemma zeroDiff_update (j : I) (M B : Matrix D D R) (A : I → Matrix D D R) : + zeroDiff j (basePencil M (Function.update A j B))= + (M.map (MvPolynomial.C : R →+* MvPolynomial I R) + ∑i ∈ Finset.univ.erase j, + (MvPolynomial.X i : MvPolynomial I R) • (A i).map (MvPolynomial.C : R →+* MvPolynomial I R)).det- + detLinear (M.map (MvPolynomial.C : R →+* MvPolynomial I R) + ∑i ∈ Finset.univ.erase j, + (MvPolynomial.X i : MvPolynomial I R) • (A i).map (MvPolynomial.C : R →+* MvPolynomial I R)) (B.map (MvPolynomial.C : R →+* MvPolynomial I R)) := by + rw [zeroDiff_basePencil,Function.update_self] + have hh : ∑i ∈ Finset.univ.erase j, (MvPolynomial.X i : MvPolynomial I R) • + ((Function.update A j B) i).map (MvPolynomial.C : R →+* MvPolynomial I R)= + ∑i ∈ Finset.univ.erase j, (MvPolynomial.X i : MvPolynomial I R) • (A i).map (MvPolynomial.C : R →+* MvPolynomial I R) := by + apply Finset.sum_congr rfl + intro i hi + rw [Function.update_of_ne (Finset.mem_erase.mp hi).1] + rw [hh] + +omit [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] in +lemma matrix_map_mean {O : Type uO} [Fintype O] (w : O → R) (B : O → Matrix D D R) : + (∑o, w o • B o).map (MvPolynomial.C : R →+* MvPolynomial I R)= + ∑o, (MvPolynomial.C (w o) : MvPolynomial I R) • (B o).map (MvPolynomial.C : R →+* MvPolynomial I R) := by + apply Matrix.ext + intro a b + simp [Matrix.map_apply,Matrix.sum_apply,Matrix.smul_apply] + +lemma zeroDiff_affine {O : Type uO2} [Fintype O] (j : I) (M : Matrix D D R) + (A : I → Matrix D D R) (w : O → R) (B : O → Matrix D D R) (hw : ∑o, w o=1) : + zeroDiff j (basePencil M (Function.update A j (∑o, w o • B o)))= + ∑o, w o • zeroDiff j (basePencil M (Function.update A j (B o))) := by + simp only [zeroDiff_update] + let N := M.map (MvPolynomial.C : R →+* MvPolynomial I R) + ∑i ∈ Finset.univ.erase j, + (MvPolynomial.X i : MvPolynomial I R) • (A i).map (MvPolynomial.C : R →+* MvPolynomial I R) + change N.det-detLinear N ((∑o, w o • B o).map (MvPolynomial.C : R →+* MvPolynomial I R))= + ∑o, w o • (N.det-detLinear N ((B o).map (MvPolynomial.C : R →+* MvPolynomial I R))) + rw [matrix_map_mean,map_sum] + simp only [map_smul,smul_sub,Finset.sum_sub_distrib,←Finset.sum_smul,hw,one_smul] + congr 1 + apply Finset.sum_congr rfl + intro o _ + exact MvPolynomial.C_mul' + +lemma mixedEval_affine_cons {O : Type uO3} [Fintype O] (j : I) (dirs : List I) (hj : j ∉ dirs) + (M : Matrix D D R) (A : I → Matrix D D R) (w : O → R) (B : O → Matrix D D R) + (hw : ∑o, w o=1) : + mixedEval (j::dirs) M (Function.update A j (∑o, w o • B o))= + ∑o, w o * mixedEval (j::dirs) M (Function.update A j (B o)) := by + simp only [mixedEval,eval_zero_diffProduct_cons j dirs hj] + rw [zeroDiff_affine j M A w B hw,map_sum,map_sum] + apply Finset.sum_congr rfl + intro o _ + rw [map_smul] + simp only [←MvPolynomial.C_mul',map_mul,MvPolynomial.eval_C] + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/AlgorithmicMain.lean b/lean/OAI/Combinatorics/ThinTrees/AlgorithmicMain.lean new file mode 100644 index 0000000000000000000000000000000000000000..adbb5136d219d278e1a61fc8640c213f086e8014 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/AlgorithmicMain.lean @@ -0,0 +1,5 @@ +import OAI.Combinatorics.ThinTrees.Arithmetic.WordHead +import OAI.Combinatorics.ThinTrees.Encoding.AlgorithmicMain +import OAI.Combinatorics.ThinTrees.Pencil.Realization +import OAI.Analysis.MatrixSigning.Main +import OAI.Combinatorics.ThinTrees.Main diff --git a/lean/OAI/Combinatorics/ThinTrees/Arithmetic/ArraySums.lean b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/ArraySums.lean new file mode 100644 index 0000000000000000000000000000000000000000..99ffd3b786c14f5b3cf1263c821b56180b584789 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/ArraySums.lean @@ -0,0 +1,55 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.CenteredMatrices + +namespace OAI + +/-! Array sums. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine Matrix +open scoped BigOperators + +def matrixSumData (p : ℕ×List MatrixData) : MatrixData := + weightedSumData (p.1,(List.replicate p.2.length 1,p.2)) +def matrixSum : Realizes (prodCode natCode (listCode matrixCode)) matrixCode matrixSumData := + let n := first natCode (listCode matrixCode) + let xs := second natCode (listCode matrixCode) + let ones := ((constant _ ratCode 1).both (xs.then (lengthList matrixCode))).then (replicateList ratCode) + (n.both (ones.both xs)).then weightedSum +instance poly_matrixSum : PolyTime matrixSum := by + unfold matrixSum + apply poly_then +lemma matrixSum_data {n m : ℕ} (A : Fin m → Matrix (Fin n) (Fin n) ℚ) : + matrixSumData (n,List.ofFn (fun i => matrixData (A i)))=matrixData (∑i,A i) := by + unfold matrixSumData + rw [List.length_ofFn,←List.ofFn_const (n:=m) (1:ℚ),weightedSum_data] + simp + +variable {α β : Type*} {ea : α → Word} {eb : β → Word} +def Realizes.sumFinMatrices {n d : α → ℕ} + {A : (a : α) → Fin (n a) → Matrix (Fin (d a)) (Fin (d a)) ℚ} + (r : Realizes (finFamilyCode ea n) matrixCode (fun a => matrixData (A a.1 a.2))) + (rn : Realizes ea natCode n) (rd : Realizes ea natCode d) : + Realizes ea matrixCode (fun a => matrixData (∑i,A a i)) := + (rd.both (r.tabulateFin rn)).then matrixSum |>.congr (fun a => matrixSum_data (A a)) +instance poly_sumFinMatrices {n d : α → ℕ} + {A : (a : α) → Fin (n a) → Matrix (Fin (d a)) (Fin (d a)) ℚ} + (r : Realizes (finFamilyCode ea n) matrixCode (fun a => matrixData (A a.1 a.2))) + (rn : Realizes ea natCode n) (rd : Realizes ea natCode d) + [PolyTime r] [PolyTime rn] [PolyTime rd] : PolyTime (r.sumFinMatrices rn rd) := by + unfold Realizes.sumFinMatrices;infer_instance + +def Realizes.sumFin {n : α → ℕ} {f : (a : α) → Fin (n a) → ℚ} + (r : Realizes (finFamilyCode ea n) ratCode (fun a => f a.1 a.2)) + (rn : Realizes ea natCode n) : Realizes ea ratCode (fun a => ∑i,f a i) := + ((r.tabulateFin rn).then sumRationals).congr (fun _ => List.sum_ofFn) +instance poly_sumFin {n : α → ℕ} {f : (a : α) → Fin (n a) → ℚ} + (r : Realizes (finFamilyCode ea n) ratCode (fun a => f a.1 a.2)) + (rn : Realizes ea natCode n) [PolyTime r] [PolyTime rn] : PolyTime (r.sumFin rn) := by + unfold Realizes.sumFin;infer_instance +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Arithmetic/BinaryArithmetic.lean b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/BinaryArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..671080b39080697d30c0acb9db4cb412db10d70e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/BinaryArithmetic.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialExplicit +import OAI.Analysis.MatrixSigning.Complexity.PolynomialRoots +import OAI.Analysis.MatrixSigning.Realization.OriginalOutputRoutine +import OAI.Combinatorics.ThinTrees.BasePacking + +namespace OAI + +/-! Binary arithmetic. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 +local notation "X" => NaturalPolynomial.variable + +def wordCons (b : Bool) : Realizes wordCode wordCode (fun w => b::w) where + cost := fun _ => 1 + routine := { + scratch := 0 + program := KS.W07.SchurCounters.pushProgram 0 b + spec := fun w => by + have h := KS.W07.SchurCounters.push_spec (0 : Fin 1) b (io w) + convert h using 1 <;> (try rfl) + funext j; fin_cases j; rfl } +instance poly_wordCons (b : Bool) : PolyTime (wordCons b) := ⟨⟨1,fun _ => le_rfl⟩⟩ + +def binaryToRat : Realizes binaryNatCode ratCode (fun n => (n:ℚ)) := + ((((identity binaryNatCode).both (constant binaryNatCode KS.W01.encodeNat 1)).changeOutput + wordCode (fun n => prodCode binaryNatCode KS.W01.encodeNat (n,1)) (fun _ => rfl)).then + (wordCons false)).changeOutput ratCode (fun n => (n:ℚ)) (fun n => by + simp only [ratCode,KS.W01.encodeRat,Rat.num_natCast,Rat.den_natCast, + KS.W01.encodeInt,prodCode,PairRoutine.pair,binaryNatCode,KS.W01.encodeNat] + rfl) +instance poly_binaryToRat : PolyTime binaryToRat := by unfold binaryToRat;infer_instance + +lemma intPayload_natCast (n : ℕ) : KS.W01.intPayload (n:ℤ)=n := rfl + +def binaryDiv (d : ℕ) : Realizes binaryNatCode binaryNatCode (fun n => n/d) := + (((binaryToRat.div (constant binaryNatCode ratCode d)).then ratFloor).then ratNumBinary).congr + (fun n => by + simp only [Rat.num_intCast,Int.floor_div_natCast,Int.floor_natCast, + ← Int.natCast_ediv,intPayload_natCast]) +instance poly_binaryDiv (d : ℕ) : PolyTime (binaryDiv d) := by unfold binaryDiv;infer_instance + +def binaryMod (d : ℕ) : Realizes binaryNatCode binaryNatCode (fun n => n%d) := + ((binaryToRat.sub ((constant binaryNatCode ratCode d).mul + ((binaryDiv d).then binaryToRat))).then ratNumBinary).congr (fun n => by + have he : (n:ℚ)-(d:ℚ)*(n/d:ℕ)=(n%d:ℕ) := by + have h := Nat.mod_add_div n d + have hh := congrArg (fun a : ℕ => (a:ℚ)) h + push_cast at hh + linarith + rw [he,Rat.num_natCast,intPayload_natCast]) +instance poly_binaryMod (d : ℕ) : PolyTime (binaryMod d) := by unfold binaryMod;infer_instance + +def binaryModUnary (d : ℕ) : Realizes binaryNatCode natCode (fun n => n%d) := + (binaryMod d).then binaryToNat +instance poly_binaryModUnary (d : ℕ) [hd : Fact (0 (q.den:ℚ)) := ratDenBinary.then binaryToRat +instance poly_ratDenRat : PolyTime ratDenRat := by unfold ratDenRat;infer_instance + +def scalarProductBinary : Realizes ratCode binaryNatCode (fun q => q.num.natAbs*q.den) := + ((((identity ratCode).abs.mul (ratDenRat.pow 2))).then ratNumBinary).congr (fun q => by + have he : |q| *(q.den:ℚ)^2=(q.num.natAbs*q.den:ℕ) := by + rw [show |q|=|(q.num:ℚ)/(q.den:ℚ)| from congrArg abs (Rat.num_div_den q).symm, + abs_div,abs_of_pos (by positivity : (0:ℚ) decide (P a))) + (s : Realizes ea boolCode (fun a => decide (Q a))) : + Realizes ea boolCode (fun a => decide (P a ∨ Q a)) := + (r.ite (constant ea boolCode true) s).congr (by intro a;simp) +instance poly_or {P Q : α → Prop} [DecidablePred P] [DecidablePred Q] + (r : Realizes ea boolCode (fun a => decide (P a))) + (s : Realizes ea boolCode (fun a => decide (Q a))) [PolyTime r] [PolyTime s] : PolyTime (r.or s) := by + unfold Realizes.or;infer_instance + +abbrev boolsCode := listCode boolCode + +def anyTrue : Realizes boolsCode boolCode (fun bs => decide (true ∈ bs)) := + ((constant boolsCode natCode 0).nlt + ((((constant boolsCode boolCode false).both (identity boolsCode)).then + (second boolCode boolCode).filterCtx).then (lengthList boolCode))).congr (by + intro bs + simp [List.length_pos_iff, List.filter_eq_nil_iff, Bool.forall_bool]) +instance poly_anyTrue : PolyTime anyTrue := by unfold anyTrue;infer_instance + +def allTrue : Realizes boolsCode boolCode (fun bs => decide (∀b∈bs,b=true)) := + (((identity boolCode).ite (constant boolCode boolCode false) + (constant boolCode boolCode true)).map.then anyTrue).not.congr (by + intro bs + simp) +instance poly_allTrue : PolyTime allTrue := by unfold allTrue;infer_instance + +variable {n : α → ℕ} {P : (a : α) → Fin (n a) → Prop} [∀a,DecidablePred (P a)] +def Realizes.existsFin + (r : Realizes (finFamilyCode ea n) boolCode (fun p => decide (P p.1 p.2))) + (rn : Realizes ea natCode n) : Realizes ea boolCode (fun a => decide (∃i,P a i)) := + ((r.tabulateFin rn).then anyTrue).congr (by + intro a;simp only [List.mem_ofFn,decide_eq_true_eq]) +instance poly_existsFin + (r : Realizes (finFamilyCode ea n) boolCode (fun p => decide (P p.1 p.2))) + (rn : Realizes ea natCode n) [PolyTime r] [PolyTime rn] : PolyTime (r.existsFin rn) := by + unfold Realizes.existsFin;infer_instance + +def Realizes.forallFin + (r : Realizes (finFamilyCode ea n) boolCode (fun p => decide (P p.1 p.2))) + (rn : Realizes ea natCode n) : Realizes ea boolCode (fun a => decide (∀i,P a i)) := + ((r.tabulateFin rn).then allTrue).congr (by + intro a;simp only [List.mem_ofFn,forall_exists_index,forall_apply_eq_imp_iff,decide_eq_true_eq]) +instance poly_forallFin + (r : Realizes (finFamilyCode ea n) boolCode (fun p => decide (P p.1 p.2))) + (rn : Realizes ea natCode n) [PolyTime r] [PolyTime rn] : PolyTime (r.forallFin rn) := by + unfold Realizes.forallFin;infer_instance + +lemma bools_length (bs : List Bool) : (boolsCode bs).length=3*bs.length := by + induction bs with + | nil => rfl + | cons b bs ih => + change (listCode boolCode (b::bs)).length=_ + rw [listCode_cons,prodCode_length] + change 2*1+1+(boolsCode bs).length=3*(bs.length+1) + rw [ih];omega + +lemma bools_ofFn_length {n : ℕ} (f : Fin n → Bool) : + (boolsCode (List.ofFn f)).length=3*n := by rw [bools_length,List.length_ofFn] + +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Arithmetic/ScalarRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/ScalarRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..bc65e88b8150cd0fa2355d3408bccb537f27bd74 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/ScalarRealization.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialCoordinates +import OAI.Analysis.MatrixSigning.Complexity.PolynomialMatrixFold +import OAI.Combinatorics.ThinTrees.Arithmetic.BinaryArithmetic +import OAI.Combinatorics.ThinTrees.RationalMatrix.Squares + +namespace OAI + +/-! Scalar realization. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 AlgorithmicThinTrees.RationalGram +local notation "X" => NaturalPolynomial.variable + +abbrev SquareScan := ℕ×(ℚ×List ℚ) +abbrev squareScanCode := prodCode binaryNatCode (prodCode ratCode vectorCode) +abbrev squarePayload := first binaryNatCode (prodCode ratCode vectorCode) +abbrev squareRest := second binaryNatCode (prodCode ratCode vectorCode) +abbrev squarePower := squareRest.then (first ratCode vectorCode) +abbrev squareAccum := squareRest.then (second ratCode vectorCode) + +def squareScanStep (p : SquareScan) : SquareScan := + (p.1/4,(2*p.2.1,p.2.2++List.replicate (p.1%4) p.2.1)) + +def squareScan : Realizes squareScanCode squareScanCode squareScanStep := + (squarePayload.then (binaryDiv 4)).both + (((constant squareScanCode ratCode 2).mul squarePower).both + ((squareAccum.both ((squarePower.both (squarePayload.then (binaryModUnary 4))).then + (replicateList ratCode))).then (appendList ratCode))) +instance poly_squareScan : PolyTime squareScan := by + let : Fact (0<4) := ⟨by decide⟩ + unfold squareScan + apply poly_both + +lemma squareScan_correct (k n : ℕ) (a : ℚ) (xs : List ℚ) : + (squareScanStep^[k] (n,(a,xs))).2.2= + xs++(base4Squares k n).map (fun v : ℕ => a*(v:ℚ)) := by + induction k generalizing n a xs with + | zero => simp [base4Squares] + | succ k ih => + rw [Function.iterate_succ_apply] + change (squareScanStep^[k] (n/4,(2*a,xs++List.replicate (n%4) a))).2.2=_ + rw [ih] + simp only [base4Squares,List.map_append,List.map_replicate,Nat.cast_one,mul_one, + List.map_map,Function.comp_def,List.append_assoc] + congr 2 + apply List.map_congr_left + intro x hx + push_cast + ring + +lemma squareScan_invariant (p : SquareScan) {b : ℕ} + (hf : QParts b p.2.1) (hx : ∀v∈p.2.2,QParts b v) (k : ℕ) : + let s := squareScanStep^[k] p + s.1≤p.1 ∧ QParts (b+k) s.2.1 ∧ s.2.2.length≤p.2.2.length+3*k ∧ + ∀v∈s.2.2,QParts (b+k) v := by + induction k with + | zero => exact ⟨le_rfl,by simpa using hf,by simp,by simpa using hx⟩ + | succ k ih => + rw [Function.iterate_succ_apply'] + dsimp only at ih ⊢ + generalize he : squareScanStep^[k] p=s at ih ⊢ + dsimp only [squareScanStep] + refine ⟨(Nat.div_le_self _ _).trans ih.1,?_,?_,?_⟩ + · have htwo : QParts 1 (2:ℚ) := by norm_num [QParts] + exact (htwo.mul ih.2.1).mono (by omega) + · simp only [List.length_append,List.length_replicate] + have hh := Nat.mod_lt s.1 (by decide : 0<4) + omega + · intro v hv + simp only [List.mem_append,List.mem_replicate] at hv + rcases hv with h|⟨_,rfl⟩ + · exact (ih.2.2.2 v h).mono (by omega) + · exact ih.2.1.mono (by omega) + +instance size_squareScan : IterateSize squareScan := by + refine ⟨⟨100*(X+1)^2,?_⟩⟩ + intro p k + let S := (squareScanCode p).length + have hn := le_prodCode_left (ea:=binaryNatCode) (eb:=prodCode ratCode vectorCode) p + have hr := le_prodCode_right (ea:=binaryNatCode) (eb:=prodCode ratCode vectorCode) p + have hf := (le_prodCode_left p.2).trans hr + have hx := (le_prodCode_right p.2).trans hr + have hfx := (qparts_length p.2.1).mono hf + have hxx : ∀v∈p.2.2,QParts S v := fun v hv => + (qparts_length v).mono ((mem_length_le_code p.2.2 hv).trans hx) + obtain ⟨hN,hF,hX,hV⟩ := squareScan_invariant p hfx hxx k + have hn' : (binaryNatCode (squareScanStep^[k] p).1).length≤S := by + have h := Nat.size_le_size hN + simpa only [binaryNatCode,KS.W01.natPayloadLength_eq_size,CurrentKS.payload_length] + using h.trans (show p.1.size≤S by simpa only [binaryNatCode,CurrentKS.payload_length] using hn) + have hl := (list_length_le_code ratCode p.2.2).trans hx + have hb := (listCode_length_bound (squareScanStep^[k] p).2.2 (4*(S+k)+7) + (fun v hv => (hV v hv).length)).trans + (Nat.mul_le_mul_right _ (hX.trans (Nat.add_le_add_right hl _))) + have hfl := hF.length + change (squareScanCode (squareScanStep^[k] p)).length≤100*(S+k+1)^2 + simp only [squareScanCode,prodCode_length] + change (ratCode (squareScanStep^[k] p).2.1).length≤4*(S+k)+7 at hfl + change (vectorCode (squareScanStep^[k] p).2.2).length≤(S+3*k)*(2*(4*(S+k)+7)+1) at hb + nlinarith only [hn',hb,hfl,Nat.zero_le S,Nat.zero_le k,sq_nonneg (S:ℤ),sq_nonneg (k:ℤ)] + +def scalarFactorProgram : Realizes ratCode vectorCode scalarFactors := + let n := scalarProductBinary + let a := (constant ratCode ratCode 1).div ratDenRat + let start := n.both (a.both (constant ratCode vectorCode [])) + ((((n.then binarySize).both start).then squareScan.iterate).then squareAccum).congr (fun q => by + rw [squareScan_correct] + simp only [List.nil_append,scalarFactors] + apply List.map_congr_left + intro x hx + ring) +instance poly_scalarFactorProgram : PolyTime scalarFactorProgram := by + unfold scalarFactorProgram;infer_instance + +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Arithmetic/UnaryArithmetic.lean b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/UnaryArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c44a6ce802c8de705baca8b3cb8c9801941ce56 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/UnaryArithmetic.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialCoordinates +import OAI.Combinatorics.ThinTrees.Arithmetic.BinaryArithmetic + +namespace OAI + +/-! Unary arithmetic. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 +local notation "X" => NaturalPolynomial.variable + +lemma pred_iterate (n k : ℕ) : Nat.pred^[k] n = n-k := by + induction k with + | zero => rfl + | succ k ih => rw [Function.iterate_succ_apply',ih,Nat.pred_eq_sub_one]; omega + +instance size_natPred : IterateSize natPred := by + refine ⟨⟨X,?_⟩⟩ + intro n k + change (natCode (Nat.pred^[k] n)).length ≤ (natCode n).length+k + simp only [natCode,List.length_replicate,pred_iterate] + omega + +def natSub : Realizes (prodCode natCode natCode) natCode (fun p => p.1-p.2) := + (((second natCode natCode).both (first natCode natCode)).then natPred.iterate).congr + (fun p => pred_iterate p.1 p.2) +instance poly_natSub : PolyTime natSub := by unfold natSub;infer_instance + +def natDivBinary : Realizes (prodCode natCode natCode) binaryNatCode (fun p => p.1/p.2) := + (((((first natCode natCode).then natToRat).div + ((second natCode natCode).then natToRat)).then ratFloor).then ratNumBinary).congr + (fun p => by + simp only [Rat.num_intCast,Int.floor_div_natCast,Int.floor_natCast, + ←Int.natCast_ediv,intPayload_natCast]) +instance poly_natDivBinary : PolyTime natDivBinary := by unfold natDivBinary;infer_instance + +def natDiv : Realizes (prodCode natCode natCode) natCode (fun p => p.1/p.2) := + natDivBinary.then binaryToNat +instance poly_natDiv : PolyTime natDiv := by + obtain ⟨p,hp⟩ := PolyTime.bound (r:=natDivBinary) + refine ⟨⟨5*p+10*X+4,?_⟩⟩ + intro a + have hc := hp a + have ho := natDivBinary.output_length a + have hn := Nat.div_le_self a.1 a.2 + have hl := le_prodCode_left (ea:=natCode) (eb:=natCode) a + simp only [natCode,List.length_replicate] at hl + change natDivBinary.cost a+(6*(a.1/a.2)+4*(binaryNatCode (a.1/a.2)).length+4)≤ + 5*p.eval (prodCode natCode natCode a).length+10*(prodCode natCode natCode a).length+4 + omega + +def natMod : Realizes (prodCode natCode natCode) natCode (fun p => p.1%p.2) := + ((first natCode natCode).both + (((second natCode natCode).both natDiv).then natMul)).then natSub |>.congr + (fun p => by + dsimp only + have h := Nat.mod_add_div p.1 p.2 + omega) +instance poly_natMod : PolyTime natMod := by unfold natMod;infer_instance + +variable {α : Type*} {ea : α → Word} {f g : α → ℕ} +def Realizes.nadd (r : Realizes ea natCode f) (s : Realizes ea natCode g) := + (r.both s).then natAdd +def Realizes.nmul (r : Realizes ea natCode f) (s : Realizes ea natCode g) := + (r.both s).then natMul +def Realizes.nsub (r : Realizes ea natCode f) (s : Realizes ea natCode g) := + (r.both s).then natSub +def Realizes.ndiv (r : Realizes ea natCode f) (s : Realizes ea natCode g) := + (r.both s).then natDiv +def Realizes.nmod (r : Realizes ea natCode f) (s : Realizes ea natCode g) := + (r.both s).then natMod +def Realizes.neq (r : Realizes ea natCode f) (s : Realizes ea natCode g) := + (r.both s).then natEq +def Realizes.nlt (r : Realizes ea natCode f) (s : Realizes ea natCode g) := + (r.both s).then natLT +instance {r : Realizes ea natCode f} {s : Realizes ea natCode g} + [PolyTime r] [PolyTime s] : PolyTime (r.nadd s) := by unfold Realizes.nadd;infer_instance +instance {r : Realizes ea natCode f} {s : Realizes ea natCode g} + [PolyTime r] [PolyTime s] : PolyTime (r.nmul s) := by unfold Realizes.nmul;infer_instance +instance {r : Realizes ea natCode f} {s : Realizes ea natCode g} + [PolyTime r] [PolyTime s] : PolyTime (r.nsub s) := by unfold Realizes.nsub;infer_instance +instance {r : Realizes ea natCode f} {s : Realizes ea natCode g} + [PolyTime r] [PolyTime s] : PolyTime (r.ndiv s) := by unfold Realizes.ndiv;infer_instance +instance {r : Realizes ea natCode f} {s : Realizes ea natCode g} + [PolyTime r] [PolyTime s] : PolyTime (r.nmod s) := by unfold Realizes.nmod;infer_instance +instance {r : Realizes ea natCode f} {s : Realizes ea natCode g} + [PolyTime r] [PolyTime s] : PolyTime (r.neq s) := by unfold Realizes.neq;infer_instance +instance {r : Realizes ea natCode f} {s : Realizes ea natCode g} + [PolyTime r] [PolyTime s] : PolyTime (r.nlt s) := by unfold Realizes.nlt;infer_instance + +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Arithmetic/UnaryRoot.lean b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/UnaryRoot.lean new file mode 100644 index 0000000000000000000000000000000000000000..c92ec03a47295a81b76356b3fa80b51b2045036b --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/UnaryRoot.lean @@ -0,0 +1,73 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Normalization.Realization + +namespace OAI + +/-! Unary root. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 +local notation "X" => NaturalPolynomial.variable + +abbrev rootCode := prodCode natCode natCode + +def unaryRootStep (d : ℕ) (a : ℕ×ℕ) : ℕ×ℕ := + (a.1,if (a.2+1)^d ≤ a.1 then a.2+1 else a.2) + +def unaryRootStepProgram (d : ℕ) : Realizes rootCode rootCode (unaryRootStep d) := + let r := first natCode natCode + let b := second natCode natCode + let next := b.then natSucc + (r.both (((next.then (AlgorithmicThinTrees.Normalization.Stack.unaryPow d)).both r).then natLE |>.ite next b)).congr (by + intro a; simp [unaryRootStep]) +instance poly_unaryRootStep (d : ℕ) : PolyTime (unaryRootStepProgram d) := by + unfold unaryRootStepProgram + apply poly_congr + +lemma unaryRootStep_iterate_bound (d k : ℕ) (a : ℕ×ℕ) : + ((unaryRootStep d)^[k] a).1=a.1 ∧ ((unaryRootStep d)^[k] a).2≤a.2+k := by + induction k with + | zero => simp + | succ k ih => + rw [Function.iterate_succ_apply'] + dsimp only [unaryRootStep] + constructor + · exact ih.1 + · split <;> omega + +instance size_unaryRootStep (d : ℕ) : IterateSize (unaryRootStepProgram d) := by + refine ⟨⟨X,?_⟩⟩ + intro a k + have h := unaryRootStep_iterate_bound d k a + change (rootCode ((unaryRootStep d)^[k] a)).length≤(rootCode a).length+k + simp only [rootCode,prodCode_length,natCode,List.length_replicate,h.1] + omega + +lemma unaryRootStep_iterate_zero (d : ℕ) (hd : d≠0) (r k : ℕ) : + ((unaryRootStep d)^[k] (r,0)).2=min k (Nat.nthRoot d r) := by + induction k with + | zero => simp + | succ k ih => + rw [Function.iterate_succ_apply'] + dsimp only [unaryRootStep] + simp only [(unaryRootStep_iterate_bound d k (r,0)).1,ih] + simp only [←Nat.le_nthRoot_iff hd] + split <;> omega + +lemma unaryRoot_le (d r : ℕ) (hd : d≠0) : Nat.nthRoot d r≤r := + (Nat.le_self_pow hd _).trans (Nat.pow_nthRoot_le (Or.inl hd)) + +def unaryRoot (d : ℕ) (hd : d≠0) : Realizes natCode natCode (Nat.nthRoot d) := + (((identity natCode).both ((identity natCode).both (constant natCode natCode 0))).then + (unaryRootStepProgram d).iterate |>.then (second natCode natCode)).congr (by + intro r + change ((unaryRootStep d)^[r] (r,0)).2 = Nat.nthRoot d r + rw [unaryRootStep_iterate_zero d hd r r,min_eq_right (unaryRoot_le d r hd)]) +instance poly_unaryRoot (d : ℕ) (hd : d≠0) : PolyTime (unaryRoot d hd) := by + unfold unaryRoot;infer_instance +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Arithmetic/WordHead.lean b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/WordHead.lean new file mode 100644 index 0000000000000000000000000000000000000000..abe0756d27ab9ad0a5e62aadedc2481af10ddef3 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Arithmetic/WordHead.lean @@ -0,0 +1,53 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.GreedyRealization + +namespace OAI + +/-! Word head. -/ + +section + +namespace CurrentKS.WordHead +open KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinators +open CleanRoutine PairRoutine + +def dispatch (_ : Fin 1) (heads : Fin 3 → Fin 3) (_ : Bool) : KS.W01.FixedStack.Instruction 3 1 := + ⟨none,Vector.ofFn (fun j => if j=1 then .push (decide (heads 0=2)) else .stay)⟩ +def flag : Program 3 := ofMachine (compile 0 0 1 dispatch) +def program : Program 3 := compose flag (compose (KS.W04.BinaryStackMoves.clearProgram 0) + (transfer 1 2 0)) +lemma flag_spec (w : Word) : RunSpec flag (io w) (smallState w [w.headD false] []) 1 := by + intro bits hbits + obtain ⟨coin,rfl⟩ := List.length_eq_one_iff.mp hbits + change (compile (0 : Fin 1) 0 1 dispatch).step ⟨some (0 : Fin 1),io w⟩ coin=_ + rw [step_compile] + apply KS.W19.FixedRun.config_ext + · rfl + · intro j + fin_cases j <;> simp [dispatch,KS.W01.FixedStack.Instruction.action,KS.W29.StackAction.apply, + io,smallState,observedHeads] + cases w with + | nil => rfl + | cons b bs => cases b <;> rfl + +def routine : Routine (fun w : Word => w) (fun w => [w.headD false]) (fun w => w.length+6) where + scratch := 2 + program := program + spec w := by + have h := (flag_spec w).compose ((PairRoutine.clear_first [w.headD false] w).compose + (PairRoutine.take_first [w.headD false])) + convert h using 1 <;> (try rfl) + simp + omega +end CurrentKS.WordHead + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 +def wordHead : Realizes wordCode boolCode (fun w => w.headD false) where + cost := fun w => w.length+6 + routine := WordHead.routine +instance poly_wordHead : PolyTime wordHead := ⟨⟨NaturalPolynomial.variable+6,fun _ => le_rfl⟩⟩ +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/AssignedFamilies.lean b/lean/OAI/Combinatorics/ThinTrees/AssignedFamilies.lean new file mode 100644 index 0000000000000000000000000000000000000000..4645aacdf986799721d0c4e75830f27283d0e585 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/AssignedFamilies.lean @@ -0,0 +1,335 @@ +import OAI.Combinatorics.ThinTrees.Phases + +namespace OAI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {η : ℝ} + +structure AssignedFamily (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) (η : ℝ) where + radius : ℝ + positive : 0 < radius + count : ℕ + bag : Fin count → H.AssignedBag G X radius η + owner_injective : Function.Injective (fun i => (bag i).owner) + separated : ∀i, ∀u ∈ (bag i).centers, ∀j, ∀v ∈ (bag j).centers, + (i ≠ j ∨ u ≠ v) → Disjoint ((RadialShell.ball u radius).support X) + ((RadialShell.ball v radius).support X) + +namespace AssignedFamily +variable (F : AssignedFamily H G X η) + +def owners : Finset (Finset (Fin n)) := univ.image (fun i => (F.bag i).owner) +def mass : ℝ := (∑i, ((F.bag i).centers.card : ℝ))*F.radius +def predecessors (E : Finset (Finset (Fin n))) (i : Fin F.count) : Finset (Finset (Fin n)) := + E.filter (fun S => S ⊂ (F.bag i).owner) + +def ProtectedFrom (E : Finset (Finset (Fin n))) : Prop := + ∀i, ∀u ∈ (F.bag i).centers, ((F.bag i).input (F.predecessors E i) u).Protected G X + +lemma owner_mem (i : Fin F.count) : (F.bag i).owner ∈ F.owners := mem_image.mpr ⟨i,mem_univ _,rfl⟩ +lemma owners_nodes : F.owners ⊆ H.nodes := by + intro S hS + obtain ⟨i,hi,rfl⟩ := mem_image.mp hS + exact (F.bag i).owner_mem + +lemma input_valid {q : ℝ} (hX : ∀v, binary (X v)) (hq : 0 < q) + (hconn : H.LocallyConnectedReal G q) (hη : 3072/q ≤ η) + {E : Finset (Finset (Fin n))} (hE : E ⊆ H.nodes) (hprot : F.ProtectedFrom E) + (i : Fin F.count) {u : Fin n} (hu : u ∈ (F.bag i).centers) : + ((F.bag i).input (F.predecessors E i) u).Valid H G X (q/4) := by + have hbound := H.parent_boundary_lower G hconn (F.bag i).owner_mem (F.bag i).nonroot + have hassign := (F.bag i).assignment + have hc : (3072:ℝ) ≤ ((F.bag i).centers.card : ℝ) := by + have ha := mul_le_mul_of_nonneg_right hη (Nat.cast_nonneg (H.parentBoundary G (F.bag i).owner).card) + have hb := mul_le_mul_of_nonneg_left hbound (show 0 ≤ (3072:ℝ)/q by positivity) + have heq : (3072:ℝ)/q*q = 3072 := by field_simp + rw [heq] at hb + linarith + apply (F.bag i).input_valid hX hq.le hconn + (by exact_mod_cast (show (1:ℝ) < ((F.bag i).centers.card : ℝ) by linarith)) + (fun S hS => ⟨hE (mem_filter.mp hS).1,(mem_filter.mp hS).2⟩) hu (hprot i u hu) + +lemma phase {q ε : ℝ} (hX : ∀v, binary (X v)) (hq : 0 < q) + (hconn : H.LocallyConnectedReal G q) (hη : 3072/q ≤ η) + (hε : 0 ≤ ε) (hscale : ε ≤ F.radius/1536) + {E : Finset (Finset (Fin n))} (hE : E ⊆ H.nodes) (hprot : F.ProtectedFrom E) + (hdis : Disjoint E F.owners) + (Z : Finset (Record n)) (hZ : H.LabeledArrangement G X (q/4) Z) + (hown : ∀D ∈ Z, D.owner ∈ E) : + ∃Z' : Finset (Record n), H.LabeledArrangement G X (q/4) Z' ∧ + (∑D ∈ Z, D.baseToken F.radius)+(AssignedAccounting.theta/2)*F.mass ≤ + ∑D ∈ Z', D.baseToken ε ∧ (∀D ∈ Z', D.owner ∈ E∪F.owners) := by + obtain ⟨Z',hZ',hc,ho⟩ := assigned_phase F.bag (F.predecessors E) hX hq hconn hη + F.positive hε hscale univ F.owner_injective.injOn + (fun i _ u hu => F.input_valid hX hq hconn hη hE hprot i hu) + (by + intro i hi u hu j hj v hv hne + apply F.separated i u hu j v hv + by_cases hh : i = j + · right + intro he + subst j; subst v + exact hne rfl + · exact Or.inl hh) + Z hZ + (fun i _ D hD hs => mem_filter.mpr ⟨hown D hD,hs⟩) + (fun i _ D hD heq => Finset.disjoint_left.mp hdis (hown D hD) (heq ▸ F.owner_mem i)) + refine ⟨Z',hZ',?_,?_⟩ + · simpa only [mass,mul_assoc] using hc + · intro D hD + rcases ho D hD with ⟨i,hi,heq⟩ | ⟨B,hB,heq⟩ + · exact mem_union_right _ (heq ▸ F.owner_mem i) + · exact mem_union_left _ (heq ▸ hown B hB) + +end AssignedFamily + +namespace AssignedSequence +abbrev Family := AssignedFamily H G X η + +def initialRadius : List (Family (H := H) (G := G) (X := X) (η := η)) → ℝ + | [] => 0 + | F::_ => F.radius + +def mass : List (Family (H := H) (G := G) (X := X) (η := η)) → ℝ + | [] => 0 + | F::L => F.mass+mass L + +def Geometric : List (Family (H := H) (G := G) (X := X) (η := η)) → Prop + | [] => True + | F::L => initialRadius L ≤ F.radius/1536 ∧ Geometric L + +def Ready (E : Finset (Finset (Fin n))) : List (Family (H := H) (G := G) (X := X) (η := η)) → Prop + | [] => True + | F::L => Disjoint E F.owners ∧ F.ProtectedFrom E ∧ Ready (E∪F.owners) L + +lemma radius_nonneg (L : List (Family (H := H) (G := G) (X := X) (η := η))) : + 0 ≤ initialRadius L := by + cases L with + | nil => exact le_refl _ + | cons F L => exact F.positive.le + +lemma construct {q : ℝ} (hX : ∀v, binary (X v)) (hq : 0 < q) + (hconn : H.LocallyConnectedReal G q) (hη : 3072/q ≤ η) + (L : List (Family (H := H) (G := G) (X := X) (η := η))) + (hgeo : Geometric L) (E : Finset (Finset (Fin n))) (hE : E ⊆ H.nodes) + (hready : Ready E L) (Z : Finset (Record n)) (hZ : H.LabeledArrangement G X (q/4) Z) + (hown : ∀D ∈ Z, D.owner ∈ E) {credit : ℝ} + (hcredit : credit ≤ ∑D ∈ Z, D.baseToken (initialRadius L)) : + ∃Z' : Finset (Record n), H.LabeledArrangement G X (q/4) Z' ∧ + credit+(AssignedAccounting.theta/2)*mass L ≤ ∑D ∈ Z', D.shell.width := by + induction L generalizing E Z credit with + | nil => + refine ⟨Z,hZ,?_⟩ + simp only [mass,mul_zero,add_zero] at * + apply hcredit.trans + exact sum_le_sum (fun D hD => AssignedAccounting.base_le_width D.avoided.isSome + (by have hh := (hZ.1 D hD).2.2.1.2.1; dsimp [RadialShell.width]; linarith) (le_refl _)) + | cons F L ih => + obtain ⟨Z₁,hZ₁,hstep,hown₁⟩ := F.phase hX hq hconn hη (radius_nonneg L) + hgeo.1 hE hready.2.1 hready.1 Z hZ hown + have hc : credit+(AssignedAccounting.theta/2)*F.mass ≤ + ∑D ∈ Z₁, D.baseToken (initialRadius L) := by + change credit ≤ ∑D ∈ Z, D.baseToken F.radius at hcredit + linarith + obtain ⟨Z₂,hZ₂,hc₂⟩ := ih hgeo.2 (E∪F.owners) (union_subset hE F.owners_nodes) + hready.2.2 Z₁ hZ₁ hown₁ hc + refine ⟨Z₂,hZ₂,?_⟩ + dsimp [mass] + linarith + +lemma insertable_bound {q : ℝ} (hX : ∀v, binary (X v)) (hq : 0 < q) + (hconn : H.LocallyConnectedReal G q) (hη : 3072/q ≤ η) + (L : List (Family (H := H) (G := G) (X := X) (η := η))) + (hgeo : Geometric L) (hready : Ready ∅ L) : + (q/4096)*mass L ≤ ∑e : Fin m, l1dist (X (G.left e)) (X (G.right e)) := by + have hempty : H.LabeledArrangement G X (q/4) ∅ := by constructor <;> simp + obtain ⟨Z,hZ,hwidth⟩ := construct hX hq hconn hη L hgeo ∅ (empty_subset _) hready + ∅ hempty (by simp) (credit := 0) (by simp) + have he := H.labeled_energy G X hX hZ + have hh := mul_le_mul_of_nonneg_left hwidth (show 0 ≤ q/4 by positivity) + dsimp [AssignedAccounting.theta] at hh + nlinarith + +end AssignedSequence +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {η : ℝ} + +namespace AssignedFamily +variable (F : AssignedFamily H G X η) + +def goodCenters (E : Finset (Finset (Fin n))) (i : Fin F.count) : Finset (Fin n) := + (F.bag i).centers.filter (fun u => ((F.bag i).input (F.predecessors E i) u).Protected G X) + +def badCenters (E : Finset (Finset (Fin n))) (i : Fin F.count) : Finset (Fin n) := + (F.bag i).centers\F.goodCenters E i + +def badCount (E : Finset (Finset (Fin n))) : ℕ := ∑i, (F.badCenters E i).card + +def boundaryCount (G : MultiGraph n m) (E : Finset (Finset (Fin n))) : ℕ := + ∑S ∈ E, (G.cut univ S).card + +lemma bad_witness {E : Finset (Finset (Fin n))} (i : Fin F.count) {u : Fin n} + (hu : u ∈ F.badCenters E i) : + ∃S ∈ E, ∃e ∈ G.cut univ S, ∃v : Fin n, + (v = G.left e ∨ v = G.right e) ∧ l1dist (X v) (X u) < F.radius := by + have hn : ¬((F.bag i).input (F.predecessors E i) u).Protected G X := by + intro hh + exact (mem_sdiff.mp hu).2 (mem_filter.mpr ⟨(mem_sdiff.mp hu).1,hh⟩) + simp only [Record.Protected,not_forall] at hn + obtain ⟨S,hS,e,he,hn⟩ := hn + have hSE : S ∈ E := (mem_filter.mp hS).1 + change ¬(F.radius ≤ l1dist (X (G.left e)) (X u) ∧ + F.radius ≤ l1dist (X (G.right e)) (X u)) at hn + by_cases hl : l1dist (X (G.left e)) (X u) < F.radius + · exact ⟨S,hSE,e,he,G.left e,Or.inl rfl,hl⟩ + · exact ⟨S,hSE,e,he,G.right e,Or.inr rfl,lt_of_not_ge (fun hr => hn ⟨le_of_not_gt hl,hr⟩)⟩ + +lemma badCount_le (hX : ∀v, binary (X v)) (E : Finset (Finset (Fin n))) : + F.badCount E ≤ 2*boundaryCount G E := by + let B := univ.sigma (F.badCenters E) + let W := E.biUnion (fun S => (G.cut univ S).biUnion (fun e => {G.left e,G.right e})) + have hBW : ∀p ∈ B, ∃v ∈ W, l1dist (X v) (X p.2) < F.radius := by + intro p hp + obtain ⟨S,hS,e,he,v,hv,hd⟩ := F.bad_witness p.1 (mem_sigma.mp hp).2 + refine ⟨v,mem_biUnion.mpr ⟨S,hS,mem_biUnion.mpr ⟨e,he,?_⟩⟩,hd⟩ + simp only [mem_insert,mem_singleton] + exact hv + choose f hfW hfd using hBW + have hinj : ∀p hp q hq, f p hp = f q hq → p = q := by + intro p hp r hr heq + by_contra hh + have hne : p.1 ≠ r.1 ∨ p.2 ≠ r.2 := by + by_contra hn + push Not at hn + exact hh (Sigma.ext hn.1 (heq_of_eq hn.2)) + have hd := F.separated p.1 p.2 (mem_sdiff.mp (mem_sigma.mp hp).2).1 + r.1 r.2 (mem_sdiff.mp (mem_sigma.mp hr).2).1 hne + have ha : X (f p hp) ∈ (RadialShell.ball p.2 F.radius).support X := by + rw [RadialShell.support_ball] + exact ⟨binary_cube (hX _),hfd p hp⟩ + have hb : X (f p hp) ∈ (RadialShell.ball r.2 F.radius).support X := by + rw [RadialShell.support_ball,heq] + exact ⟨binary_cube (hX _),hfd r hr⟩ + exact Set.disjoint_left.mp hd ha hb + have hcard : B.card ≤ W.card := by + apply Finset.card_le_card_of_injective (f := fun p : B => (⟨f p.val p.property,hfW p.val p.property⟩ : W)) + intro p r heq + exact Subtype.ext (hinj p.val p.property r.val r.property (congrArg Subtype.val heq)) + have hW : W.card ≤ 2*boundaryCount G E := by + calc + W.card ≤ ∑S ∈ E, ((G.cut univ S).biUnion (fun e => {G.left e,G.right e})).card := card_biUnion_le + _ ≤ ∑S ∈ E, ∑e ∈ G.cut univ S, ({G.left e,G.right e} : Finset (Fin n)).card := + sum_le_sum (fun S hS => card_biUnion_le) + _ ≤ ∑S ∈ E, ∑_e ∈ G.cut univ S, 2 := + sum_le_sum (fun S hS => sum_le_sum (fun e he => card_le_two)) + _ = _ := by simp [boundaryCount,mul_sum,Nat.mul_comm] + have heq : B.card = F.badCount E := by simp [B,badCount,Finset.card_sigma] + rw [heq] at hcard + exact hcard.trans hW + +lemma prune (E : Finset (Finset (Fin n))) {η' : ℝ} (hη : 2*η' ≤ η) : + ∃F' : AssignedFamily H G X η', F'.radius = F.radius ∧ F'.owners ⊆ F.owners ∧ + (∀E' ⊆ E, F'.ProtectedFrom E') ∧ + F.mass-2*(F.badCount E : ℝ)*F.radius ≤ F'.mass := by + let J := univ.filter (fun i : Fin F.count => (F.bag i).centers.card ≤ 2*(F.goodCenters E i).card) + let e : Fin (Fintype.card J) ≃ J := (Fintype.equivFin J).symm + have hnon : ∀i ∈ J, (F.goodCenters E i).Nonempty := by + intro i hi + apply card_pos.mp + have hn := card_pos.mpr (F.bag i).nonempty + have hc := (mem_filter.mp hi).2 + omega + let a (i : J) : H.AssignedBag G X F.radius η' := { + owner := (F.bag i.val).owner + owner_mem := (F.bag i.val).owner_mem + nonroot := (F.bag i.val).nonroot + centers := F.goodCenters E i.val + nonempty := hnon i.val i.property + radius_pos := F.positive + disjoint := (F.bag i.val).disjoint.mono (filter_subset _ _) + assignment := by + have hc : ((F.bag i.val).centers.card : ℝ) ≤ 2*((F.goodCenters E i.val).card : ℝ) := by + exact_mod_cast (mem_filter.mp i.property).2 + have hh := mul_le_mul_of_nonneg_right hη (Nat.cast_nonneg (H.parentBoundary G (F.bag i.val).owner).card) + have ha := (F.bag i.val).assignment + nlinarith + endpoint := fun u hu => (F.bag i.val).endpoint u (mem_filter.mp hu).1 } + let F' : AssignedFamily H G X η' := { + radius := F.radius + positive := F.positive + count := Fintype.card J + bag := fun i => a (e i) + owner_injective := by + intro i j hij + apply e.injective + apply Subtype.ext + exact F.owner_injective hij + separated := by + intro i u hu j v hv hne + apply F.separated (e i).val u (mem_filter.mp hu).1 (e j).val v (mem_filter.mp hv).1 + rcases hne with hne | hne + · left + intro hh + exact hne (e.injective (Subtype.ext hh)) + · exact Or.inr hne } + have hsum : ∑i : Fin F'.count, ((F'.bag i).centers.card : ℝ) = + ∑i ∈ J, ((F.goodCenters E i).card : ℝ) := by + change (∑i : Fin (Fintype.card J), ((F.goodCenters E (e i).val).card : ℝ)) = _ + rw [e.sum_comp (fun i : J => ((F.goodCenters E i.val).card : ℝ))] + exact Finset.sum_coe_sort J (fun i : Fin F.count => ((F.goodCenters E i).card : ℝ)) + have hgood : ∀i, ((F.bag i).centers.card : ℝ) ≤ + (if i ∈ J then ((F.goodCenters E i).card : ℝ) else 0)+2*((F.badCenters E i).card : ℝ) := by + intro i + have hc : ((F.badCenters E i).card : ℝ)+((F.goodCenters E i).card : ℝ) = + ((F.bag i).centers.card : ℝ) := by + exact_mod_cast card_sdiff_add_card_eq_card (filter_subset (fun u => + ((F.bag i).input (F.predecessors E i) u).Protected G X) (F.bag i).centers) + by_cases hi : i ∈ J + · rw [ite_eq_left hi] + nlinarith [show (0:ℝ) ≤ (F.badCenters E i).card from Nat.cast_nonneg _] + · rw [ite_eq_right hi] + have hh : 2*(F.goodCenters E i).card < (F.bag i).centers.card := by + simpa only [J,mem_filter,mem_univ,true_and,not_le] using hi + have hh' : 2*((F.goodCenters E i).card : ℝ) < ((F.bag i).centers.card : ℝ) := by exact_mod_cast hh + linarith + have hcount := Finset.sum_le_sum (s := univ) (fun i _ => hgood i) + have hcounts : (∑i, ((F.bag i).centers.card : ℝ))-2*(F.badCount E : ℝ) ≤ + ∑i ∈ J, ((F.goodCenters E i).card : ℝ) := by + rw [sum_add_distrib,←mul_sum] at hcount + have heq : (∑i, if i ∈ J then ((F.goodCenters E i).card : ℝ) else 0) = + ∑i ∈ J, ((F.goodCenters E i).card : ℝ) := by simp + rw [heq] at hcount + apply sub_le_iff_le_add.mpr + simpa only [badCount,Nat.cast_sum] using hcount + refine ⟨F',rfl,?_,?_,?_⟩ + · intro S hS + obtain ⟨i,hi,rfl⟩ := mem_image.mp hS + exact F.owner_mem (e i).val + · intro E' hE' i u hu S hS edge hedge + have hp := (mem_filter.mp hu).2 + exact hp S (mem_filter.mpr ⟨hE' (mem_filter.mp hS).1,(mem_filter.mp hS).2⟩) edge hedge + · dsimp [mass] + rw [hsum] + nlinarith [mul_le_mul_of_nonneg_right hcounts F.positive.le] + +end AssignedFamily +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Assignment.lean b/lean/OAI/Combinatorics/ThinTrees/Assignment.lean new file mode 100644 index 0000000000000000000000000000000000000000..4be327e0169aa9d89916d13f7ec492fbdf3ceed7 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Assignment.lean @@ -0,0 +1,471 @@ +import OAI.Combinatorics.ThinTrees.Selection + +namespace OAI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) + +namespace Record + +lemma compatible_ne (hX : ∀v, binary (X v)) {B D : Record n} + (hB : B.Shape H) (hval : B.shell.Valid X) (hBD : B.Compatible H X D) : B ≠ D := by + rintro rfl + exact B.compatible_self_iff H X hX hB hval hBD + +def phaseToken (F : Finset (Record n)) (δ ε : ℝ) (B : Record n) : ℝ := + if B ∈ F then AssignedAccounting.fresh δ ε else + AssignedAccounting.base B.avoided.isSome B.shell.width δ + +lemma restriction_not_fresh {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true) (B : Record n) (a b : ℝ) : + B.restriction a b ∉ F := by + intro hh + have hh' := hF _ hh + simp [restriction,RadialShell.hollow] at hh' + +lemma restriction_token {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true) (B : Record n) (a b δ ε : ℝ) : + phaseToken F δ ε (B.restriction a b) = + AssignedAccounting.base B.avoided.isSome (b-a) δ := by + rw [phaseToken,ite_eq_right (restriction_not_fresh hF B a b)] + rfl + +lemma interior_width {δ : ℝ} {A B : Record n} (hh : A.Interior H X 256 δ B) : + 512*δ < B.shell.width := by + dsimp [RadialShell.width] + linarith [hh.2.1,hh.2.2] + +lemma interior_ball_subset {δ : ℝ} {A B : Record n} (hδ : 0 ≤ δ) + (hA : A.shell = RadialShell.ball A.shell.center δ) + (hh : A.Interior H X 256 δ B) : A.shell.support X ⊆ B.shell.support X := by + rw [hA] + apply RadialShell.ball_subset_of_radial_margin + · linarith [hh.2.1] + · linarith [hh.2.2] + +end Record + +lemma labeled_singleton {q : ℝ} {B : Record n} (hB : B.Valid H G X q) : + H.LabeledArrangement G X q {B} := by + constructor + · intro A hA + simpa only [mem_singleton.mp hA] using hB + · intro A hA D hD hne + exact (hne ((mem_singleton.mp hA).trans (mem_singleton.mp hD).symm)).elim + +lemma labeled_insert {q : ℝ} {Z : Finset (Record n)} {B : Record n} + (hZ : H.LabeledArrangement G X q Z) (hB : B.Valid H G X q) + (hcompat : ∀D ∈ Z, B.Compatible H X D) : + H.LabeledArrangement G X q (insert B Z) := by + rw [← singleton_union] + apply H.labeled_union G X (H.labeled_singleton G X hB) hZ + intro A hA D hD + simpa only [mem_singleton.mp hA] using hcompat D hD + +lemma avoiding_operation (hX : ∀v, binary (X v)) + {q δ ε : ℝ} (hδ : 0 < δ) (hε : ε ≤ δ/1536) + {F Z : Finset (Record n)} (hF : ∀D ∈ F, + D.shell.ordinary = true ∧ D.avoided = none) + (hZ : H.LabeledArrangement G X q Z) {A B : Record n} + (hA : A.Valid H G X q) (hAF : A ∈ F) + (hAball : A.shell = RadialShell.ball A.shell.center δ) + (hB : B ∈ Z) (havoid : B.avoided.isSome = true) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ A.excluded) + (hinter : A.Interior H X 256 δ B) : + ∃Z' : Finset (Record n), H.LabeledArrangement G X q Z' ∧ + (∑D ∈ Z, Record.phaseToken F δ ε D)+AssignedAccounting.theta*δ ≤ + ∑D ∈ Z', Record.phaseToken F δ ε D ∧ + ∀D ∈ Z', D ∈ Z ∨ D = A ∨ ∃a b, D = B.restriction a b ∧ + B.shell.inner ≤ a ∧ b ≤ B.shell.outer ∧ a < b := by + let r := l1dist (X A.shell.center) (X B.shell.center) + let B₁ := B.restriction B.shell.inner (r-δ) + let B₂ := B.restriction (r+δ) B.shell.outer + have hbvalid := hZ.1 B hB + have h1a : B.shell.inner < r-δ := by dsimp [r]; linarith [hinter.2.1] + have h1b : r-δ ≤ B.shell.outer := by dsimp [r]; linarith [hinter.2.2] + have h2a : B.shell.inner ≤ r+δ := by dsimp [r]; linarith [hinter.2.1] + have h2b : r+δ < B.shell.outer := by dsimp [r]; linarith [hinter.2.2] + have hB₁ : B₁.Valid H G X q := Record.restrict_valid H G X hbvalid (le_refl _) h1b h1a + have hB₂ : B₂.Valid H G X q := Record.restrict_valid H G X hbvalid h2a (le_refl _) h2b + have h12 : B₁.Compatible H X B₂ := Or.inl + (RadialShell.concentric_disjoint X B.shell.center (by linarith : r-δ ≤ r+δ)) + have hA1 : A.Compatible H X B₁ := by + left + change Disjoint (A.shell.support X) ((RadialShell.hollow B.shell.center B.shell.inner (r-δ)).support X) + rw [hAball] + exact RadialShell.ball_disjoint_hollow_lower X _ _ (by dsimp [r]; linarith) + have hA2 : A.Compatible H X B₂ := by + left + change Disjoint (A.shell.support X) ((RadialShell.hollow B.shell.center (r+δ) B.shell.outer).support X) + rw [hAball] + exact RadialShell.ball_disjoint_hollow_upper X _ _ (le_refl _) + let W : Finset (Record n) := {A,B₁,B₂} + have hW : H.LabeledArrangement G X q W := by + apply H.labeled_insert G X + · apply H.labeled_insert G X (H.labeled_singleton G X hB₂) hB₁ + intro D hD + simpa only [mem_singleton.mp hD] using h12 + · exact hA + · intro D hD + rcases mem_insert.mp hD with rfl | hD + · exact hA1 + · simpa only [mem_singleton.mp hD] using hA2 + have hancestor : A.owner ∈ B.conflict H := + Record.candidate_ancestor H hA.1 hbvalid.1 (horder B hB) hinter.1 + have hcompat : ∀D ∈ Z.erase B, ∀C ∈ W, D.Compatible H X C := by + intro D hD C hC + obtain ⟨hDB,hDZ⟩ := mem_erase.mp hD + have hBC : B.Compatible H X D := H.labeled_pair G X hZ hB hDZ hDB.symm + apply Record.compatible_symm H X + rcases mem_insert.mp hC with rfl | hC + · exact Record.insert_compatible H G X hZ hA.1 hB hDZ hDB.symm hancestor horder + (Record.interior_ball_subset H X hδ.le hAball hinter) + rcases mem_insert.mp hC with rfl | hC + · exact Record.compatible_heredity H X hBC + (B.restriction_refines H X (le_refl _) h1b).1 (Subset.refl _) + · have heq := mem_singleton.mp hC + subst C + exact Record.compatible_heredity H X hBC + (B.restriction_refines H X h2a (le_refl _)).1 (Subset.refl _) + have hBF : B ∉ F := by + intro hh + rw [(hF B hh).2] at havoid + simp at havoid + have hcredit : Record.phaseToken F δ ε B+AssignedAccounting.theta*δ ≤ + ∑D ∈ W, Record.phaseToken F δ ε D := by + have hne12 := Record.compatible_ne H X hX hB₁.1 hB₁.2.2.1 h12 + have hneA1 := Record.compatible_ne H X hX hA.1 hA.2.2.1 hA1 + have hneA2 := Record.compatible_ne H X hX hA.1 hA.2.2.1 hA2 + have hAnot : A ∉ ({B₁,B₂} : Finset (Record n)) := by simp [hneA1,hneA2] + have h1not : B₁ ∉ ({B₂} : Finset (Record n)) := by simpa using hne12 + dsimp [W] + rw [sum_insert hAnot,sum_insert h1not,sum_singleton] + rw [Record.phaseToken,ite_eq_right hBF,havoid] + rw [show Record.phaseToken F δ ε A = AssignedAccounting.fresh δ ε by simp [Record.phaseToken,hAF]] + rw [Record.restriction_token (fun D hD => (hF D hD).1) B, + Record.restriction_token (fun D hD => (hF D hD).1) B,havoid] + have hh := AssignedAccounting.avoiding_carve hδ.le hε + (Record.interior_width H X hinter).le + (show (r-δ-B.shell.inner)+(B.shell.outer-(r+δ))=B.shell.width-2*δ by + dsimp [RadialShell.width]; ring) + linarith + refine ⟨Z.erase B∪W,H.labeled_replace G X hZ hW B hcompat, + H.replacement_credit G X hX hZ hB hcompat _ hcredit,?_⟩ + intro D hD + rcases mem_union.mp hD with hD | hD + · exact Or.inl (mem_of_mem_erase hD) + right + rcases mem_insert.mp hD with rfl | hD + · exact Or.inl rfl + right + rcases mem_insert.mp hD with rfl | hD + · exact ⟨B.shell.inner,r-δ,rfl,le_refl _,h1b,h1a⟩ + · have heq := mem_singleton.mp hD + exact ⟨r+δ,B.shell.outer,heq,h2a,le_refl _,h2b⟩ + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) + +namespace Record + +def restrictionSet (B : Record n) (a b : ℝ) : Finset (Record n) := + if a < b then {B.restriction a b} else ∅ + +lemma mem_restrictionSet {B D : Record n} {a b : ℝ} : + D ∈ B.restrictionSet a b ↔ a < b ∧ D = B.restriction a b := by + by_cases hh : a < b <;> simp [restrictionSet,hh] + +lemma restrictionSet_valid {q a b : ℝ} {B : Record n} (hB : B.Valid H G X q) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) : + H.LabeledArrangement G X q (B.restrictionSet a b) := by + by_cases hab : a < b + · rw [restrictionSet,ite_eq_left hab] + exact H.labeled_singleton G X (restrict_valid H G X hB ha hb hab) + · rw [restrictionSet,ite_eq_right hab] + exact H.labeled_empty G X q + +lemma restrictionSet_refines {B D : Record n} {a b : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hD : D ∈ B.restrictionSet a b) : D.Refines H X B := by + obtain ⟨hab,rfl⟩ := mem_restrictionSet.mp hD + exact B.restriction_refines H X ha hb + +lemma restrictionSet_token {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true) (B : Record n) (a b : ℝ) + {δ ε : ℝ} (hδ : 0 ≤ δ) : + (∑D ∈ B.restrictionSet a b, phaseToken F δ ε D) = + AssignedAccounting.base B.avoided.isSome (b-a) δ := by + by_cases hab : a < b + · rw [restrictionSet,ite_eq_left hab,sum_singleton,restriction_token hF] + · rw [restrictionSet,ite_eq_right hab,sum_empty,AssignedAccounting.base_discard _ (by linarith) hδ] + +lemma restrictions_compatible (B : Record n) {a b c d : ℝ} (hbc : b ≤ c) + {D E : Record n} (hD : D ∈ B.restrictionSet a b) (hE : E ∈ B.restrictionSet c d) : + D.Compatible H X E := by + obtain ⟨_,rfl⟩ := mem_restrictionSet.mp hD + obtain ⟨_,rfl⟩ := mem_restrictionSet.mp hE + exact Or.inl (RadialShell.concentric_disjoint X B.shell.center hbc) + +end Record + +lemma dense_operation (hX : ∀v, binary (X v)) + {q δ ε a b : ℝ} (hδ : 0 < δ) (hε : ε ≤ δ/1536) + {F Z M : Finset (Record n)} (hF : ∀D ∈ F, + D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hZ : H.LabeledArrangement G X q Z) {B : Record n} (hB : B ∈ Z) + (hMZ : H.LabeledArrangement G X q M) (hMF : M ⊆ F) + (hMball : ∀A ∈ M, A.shell = RadialShell.ball A.shell.center δ) + (hno : B.avoided = none) (hwidth : 512*δ < B.shell.width) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) (hab : a ≤ b) + (hrange : ∀A ∈ M, a-δ < l1dist (X A.shell.center) (X B.shell.center) ∧ + l1dist (X A.shell.center) (X B.shell.center) < b+δ) + (hinter : ∀A ∈ M, A.Interior H X 256 δ B) + (horder : ∀A ∈ M, ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ A.excluded) + (hcount : 765*δ ≤ (M.card : ℝ)*δ) (hdense : 3*(b-a) ≤ (M.card : ℝ)*δ) : + ∃Z' : Finset (Record n), H.LabeledArrangement G X q Z' ∧ + (∑D ∈ Z, Record.phaseToken F δ ε D)+AssignedAccounting.theta*(M.card : ℝ)*δ ≤ + ∑D ∈ Z', Record.phaseToken F δ ε D ∧ + ∀D ∈ Z', D ∈ Z ∨ D ∈ M ∨ ∃c d, D = B.restriction c d ∧ + B.shell.inner ≤ c ∧ d ≤ B.shell.outer ∧ c < d := by + let W₁ := B.restrictionSet B.shell.inner (a-2*δ) + let W₂ := B.restrictionSet (b+2*δ) B.shell.outer + let W := W₁∪W₂∪M + have hbvalid := hZ.1 B hB + have h1b : a-2*δ ≤ B.shell.outer := by linarith + have h2a : B.shell.inner ≤ b+2*δ := by linarith + have hW₁ : H.LabeledArrangement G X q W₁ := + B.restrictionSet_valid H G X hbvalid (le_refl _) h1b + have hW₂ : H.LabeledArrangement G X q W₂ := + B.restrictionSet_valid H G X hbvalid h2a (le_refl _) + have h12 : ∀D ∈ W₁, ∀E ∈ W₂, D.Compatible H X E := by + intro D hD E hE + exact B.restrictions_compatible H X (by linarith : a-2*δ ≤ b+2*δ) hD hE + have hWM : ∀D ∈ W₁∪W₂, ∀A ∈ M, D.Compatible H X A := by + intro D hD A hAM + apply Record.compatible_symm H X + left + rw [hMball A hAM] + rcases mem_union.mp hD with hD | hD + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hD + exact RadialShell.ball_disjoint_hollow_lower X _ _ (by linarith [(hrange A hAM).1]) + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hD + exact RadialShell.ball_disjoint_hollow_upper X _ _ (by linarith [(hrange A hAM).2]) + have hW12 := H.labeled_union G X hW₁ hW₂ h12 + have hW : H.LabeledArrangement G X q W := H.labeled_union G X hW12 hMZ hWM + have hcompat : ∀D ∈ Z.erase B, ∀C ∈ W, D.Compatible H X C := by + intro D hD C hC + obtain ⟨hDB,hDZ⟩ := mem_erase.mp hD + have hBD := H.labeled_pair G X hZ hB hDZ hDB.symm + apply Record.compatible_symm H X + rcases mem_union.mp hC with hC | hC + · rcases mem_union.mp hC with hC | hC + · have hh := B.restrictionSet_refines H X (le_refl _) h1b hC + exact Record.compatible_heredity H X hBD hh.1 hh.2 + · have hh := B.restrictionSet_refines H X h2a (le_refl _) hC + exact Record.compatible_heredity H X hBD hh.1 hh.2 + · have hancestor := Record.candidate_ancestor H (hMZ.1 C hC).1 hbvalid.1 + (horder C hC B hB) (hinter C hC).1 + exact Record.insert_compatible H G X hZ (hMZ.1 C hC).1 hB hDZ hDB.symm hancestor + (horder C hC) (Record.interior_ball_subset H X hδ.le (hMball C hC) (hinter C hC)) + have hBF : B ∉ F := by + intro hh + rw [(hF B hh).2.1] at hwidth + linarith + have hcredit : Record.phaseToken F δ ε B+AssignedAccounting.theta*(M.card : ℝ)*δ ≤ + ∑D ∈ W, Record.phaseToken F δ ε D := by + have hd12 := H.labeled_sets_disjoint G X hX hW₁ h12 + have hdM := H.labeled_sets_disjoint G X hX hW12 hWM + dsimp only [W] + rw [sum_union hdM,sum_union hd12, + Record.restrictionSet_token (fun D hD => (hF D hD).1) B _ _ hδ.le, + Record.restrictionSet_token (fun D hD => (hF D hD).1) B _ _ hδ.le] + have hsumM : (∑D ∈ M, Record.phaseToken F δ ε D) = + (M.card : ℝ)*AssignedAccounting.fresh δ ε := by + calc + _ = ∑D ∈ M, AssignedAccounting.fresh δ ε := sum_congr rfl (fun D hD => by + simp only [Record.phaseToken,ite_eq_left (hMF hD)]) + _ = _ := by simp + rw [hsumM,Record.phaseToken,ite_eq_right hBF,hno,Option.isSome_none] + exact AssignedAccounting.dense_carve hδ.le hε (Nat.cast_nonneg _) hwidth.le + (by dsimp [RadialShell.width]; ring) hdense hcount + refine ⟨Z.erase B∪W,H.labeled_replace G X hZ hW B hcompat, + H.replacement_credit G X hX hZ hB hcompat _ hcredit,?_⟩ + intro D hD + rcases mem_union.mp hD with hD | hD + · exact Or.inl (mem_of_mem_erase hD) + right + rcases mem_union.mp hD with hD | hD + · right + rcases mem_union.mp hD with hD | hD + · obtain ⟨hpos,heq⟩ := Record.mem_restrictionSet.mp hD + exact ⟨B.shell.inner,a-2*δ,heq,le_refl _,h1b,hpos⟩ + · obtain ⟨hpos,heq⟩ := Record.mem_restrictionSet.mp hD + exact ⟨b+2*δ,B.shell.outer,heq,h2a,le_refl _,hpos⟩ + · exact Or.inl hD + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) + +namespace Record + +lemma central_refines {B : Record n} (hshape : B.Shape H) (hno : B.avoided = none) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) {a b c d : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hc : B.shell.inner ≤ c) (hd : d ≤ B.shell.outer) : + (B.innerRecord t a b).Refines H X B ∧ (B.outsideRecord t c d).Refines H X B := by + obtain ⟨h1,h2⟩ := central_conflict H hshape hno ht a b c d + exact ⟨⟨RadialShell.restriction_subset X B.shell ha hb,h1 ▸ filter_subset _ _⟩, + ⟨RadialShell.restriction_subset X B.shell hc hd,h2 ▸ filter_subset _ _⟩⟩ + +lemma hollow_token {F : Finset (Record n)} (hF : ∀D ∈ F, D.shell.ordinary = true) + {B : Record n} (hB : B.shell.ordinary = false) (δ ε : ℝ) : + phaseToken F δ ε B = AssignedAccounting.base B.avoided.isSome B.shell.width δ := by + rw [phaseToken,ite_eq_right] + intro hh + have := hF B hh + simp [hB] at this + +end Record + +lemma sparse_operation (hX : ∀v, binary (X v)) + {q δ ε a b M : ℝ} (hδ : 0 < δ) + {F Z : Finset (Record n)} (hF : ∀D ∈ F, + D.shell.ordinary = true ∧ D.shell.width = δ) + (hZ : H.LabeledArrangement G X q Z) {B : Record n} (hB : B ∈ Z) + (hno : B.avoided = none) (hwidth : 512*δ < B.shell.width) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hwide : 255*δ ≤ b-a) (hsparse : M*δ ≤ 3*(b-a)) + (hinner : (B.innerRecord t (a+δ) (b-δ)).Valid H G X q) + (houter : (B.outsideRecord t a b).Valid H G X q) : + ∃Z' : Finset (Record n), H.LabeledArrangement G X q Z' ∧ + (∑D ∈ Z, Record.phaseToken F δ ε D)+AssignedAccounting.theta*M*δ ≤ + ∑D ∈ Z', Record.phaseToken F δ ε D ∧ + ∀D ∈ Z', D ∈ Z ∨ D = B.innerRecord t (a+δ) (b-δ) ∨ + D = B.outsideRecord t a b ∨ ∃c d, D = B.restriction c d ∧ + B.shell.inner ≤ c ∧ d ≤ B.shell.outer ∧ c < d := by + let C := B.innerRecord t (a+δ) (b-δ) + let D := B.outsideRecord t a b + let W₁ := B.restrictionSet B.shell.inner a + let W₂ := B.restrictionSet b B.shell.outer + let W₀ := W₁∪W₂ + let W₃ := insert C W₀ + let W := insert D W₃ + have hab : a ≤ b := by linarith + have hv := hZ.1 B hB + have hW₁ : H.LabeledArrangement G X q W₁ := + Record.restrictionSet_valid H G X hv (le_refl _) (hab.trans hb) + have hW₂ : H.LabeledArrangement G X q W₂ := + Record.restrictionSet_valid H G X hv (ha.trans hab) (le_refl _) + have h12 : ∀E ∈ W₁, ∀J ∈ W₂, E.Compatible H X J := by + intro E hE J hJ + exact Record.restrictions_compatible H X B hab hE hJ + have hW₀ : H.LabeledArrangement G X q W₀ := H.labeled_union G X hW₁ hW₂ h12 + have hC0 : ∀E ∈ W₀, C.Compatible H X E := by + intro E hE + rcases mem_union.mp hE with hE | hE + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hE + exact Or.inl ((RadialShell.concentric_disjoint X B.shell.center (by linarith : a ≤ a+δ)).symm) + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hE + exact Or.inl (RadialShell.concentric_disjoint X B.shell.center (by linarith : b-δ ≤ b)) + have hW₃ : H.LabeledArrangement G X q W₃ := H.labeled_insert G X hW₀ hinner hC0 + have hD3 : ∀E ∈ W₃, D.Compatible H X E := by + intro E hE + rcases mem_insert.mp hE with rfl | hE + · exact Or.inr (Record.central_domain_disjoint H hv.1 hno ht (a+δ) (b-δ) a b).symm + rcases mem_union.mp hE with hE | hE + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hE + exact Or.inl ((RadialShell.concentric_disjoint X B.shell.center (le_refl a)).symm) + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hE + exact Or.inl (RadialShell.concentric_disjoint X B.shell.center (le_refl b)) + have hW : H.LabeledArrangement G X q W := H.labeled_insert G X hW₃ houter hD3 + have hCD := Record.central_refines H X hv.1 hno ht + (show B.shell.inner ≤ a+δ by linarith) (show b-δ ≤ B.shell.outer by linarith) ha hb + have hWB : ∀E ∈ W, E.Refines H X B := by + intro E hE + rcases mem_insert.mp hE with rfl | hE + · exact hCD.2 + rcases mem_insert.mp hE with rfl | hE + · exact hCD.1 + rcases mem_union.mp hE with hE | hE + · exact Record.restrictionSet_refines H X (le_refl _) (hab.trans hb) hE + · exact Record.restrictionSet_refines H X (ha.trans hab) (le_refl _) hE + have hcompat : ∀J ∈ Z.erase B, ∀E ∈ W, J.Compatible H X E := by + intro J hJ E hE + obtain ⟨hne,hJ⟩ := mem_erase.mp hJ + exact Record.compatible_symm H X (Record.compatible_heredity H X + (H.labeled_pair G X hZ hB hJ hne.symm) (hWB E hE).1 (hWB E hE).2) + have hBF : B ∉ F := by + intro hh + rw [(hF B hh).2] at hwidth + linarith + have hDC : D ∉ W₃ := by + intro hh + exact Record.compatible_self_iff H X D hX houter.1 houter.2.2.1 (hD3 D hh) + have hCW : C ∉ W₀ := by + intro hh + exact Record.compatible_self_iff H X C hX hinner.1 hinner.2.2.1 (hC0 C hh) + have hcredit : Record.phaseToken F δ ε B+AssignedAccounting.theta*M*δ ≤ + ∑E ∈ W, Record.phaseToken F δ ε E := by + have hdis := H.labeled_sets_disjoint G X hX hW₁ h12 + change _ ≤ ∑E ∈ insert D W₃, _ + rw [sum_insert hDC] + change _ ≤ _+(∑E ∈ insert C W₀, _) + rw [sum_insert hCW] + change _ ≤ _+(_+(∑E ∈ W₁∪W₂, _)) + rw [sum_union hdis, + Record.restrictionSet_token (fun D hD => (hF D hD).1) B _ _ hδ.le, + Record.restrictionSet_token (fun D hD => (hF D hD).1) B _ _ hδ.le, + Record.hollow_token (fun D hD => (hF D hD).1) (show D.shell.ordinary = false from rfl), + Record.hollow_token (fun D hD => (hF D hD).1) (show C.shell.ordinary = false from rfl), + Record.phaseToken,ite_eq_right hBF] + simp only [D,C,Record.innerRecord,Record.outsideRecord,RadialShell.hollow, + hno,Option.isSome_none,Option.isSome_some,RadialShell.width] + have hh := AssignedAccounting.sparse_carve hδ.le hwidth.le + (R₁ := a-B.shell.inner) (R₂ := B.shell.outer-b) (L := b-a) + (by dsimp [RadialShell.width]; ring) hwide hsparse + rw [show b-δ-(a+δ) = b-a-2*δ by ring] + dsimp only [RadialShell.width] at hh + linarith + refine ⟨Z.erase B∪W,H.labeled_replace G X hZ hW B hcompat, + H.replacement_credit G X hX hZ hB hcompat _ hcredit,?_⟩ + intro E hE + rcases mem_union.mp hE with hE | hE + · exact Or.inl (mem_of_mem_erase hE) + right + rcases mem_insert.mp hE with heq | hE + · exact Or.inr (Or.inl heq) + rcases mem_insert.mp hE with heq | hE + · exact Or.inl heq + right; right + rcases mem_union.mp hE with hE | hE + · obtain ⟨hpos,heq⟩ := Record.mem_restrictionSet.mp hE + exact ⟨B.shell.inner,a,heq,le_refl _,hab.trans hb,hpos⟩ + · obtain ⟨hpos,heq⟩ := Record.mem_restrictionSet.mp hE + exact ⟨b,B.shell.outer,heq,ha.trans hab,le_refl _,hpos⟩ + +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/BagBounds.lean b/lean/OAI/Combinatorics/ThinTrees/BagBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..e327403392a3b274d571db120091b8ee9b6bf6c0 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/BagBounds.lean @@ -0,0 +1,444 @@ +import OAI.Combinatorics.ThinTrees.Assignment + +namespace OAI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} + +namespace AssignedBag + +lemma neighbor_exists (A : H.AssignedBag G X δ η) {u : Fin n} (hu : u ∈ A.centers) : + ∃v ∈ H.parent A.owner\A.owner, l1dist (X u) (X v) < δ ∧ + ∃e : Fin m, (G.left e = u ∧ G.right e = v) ∨ + (G.left e = v ∧ G.right e = u) := by + obtain ⟨huT,e,he,heu,hlen⟩ := A.endpoint u hu + obtain ⟨heP,heT⟩ := mem_filter.mp he + obtain ⟨hlP,hrP⟩ := (G.mem_inducedEdges _ _).mp heP + rcases heu with heu | heu + · have hrT : G.right e ∉ A.owner := by + rcases heT with hh | hh + · exact hh.2 + · exact (hh.2 (heu.symm ▸ huT)).elim + refine ⟨G.right e,mem_sdiff.mpr ⟨hrP,hrT⟩,?_,e,Or.inl ⟨heu,rfl⟩⟩ + simpa only [heu] using hlen + · have hlT : G.left e ∉ A.owner := by + rcases heT with hh | hh + · exact (hh.2 (heu.symm ▸ huT)).elim + · exact hh.2 + refine ⟨G.left e,mem_sdiff.mpr ⟨hlP,hlT⟩,?_,e,Or.inr ⟨rfl,heu⟩⟩ + simpa only [heu,l1dist_comm] using hlen + +def neighbor (A : H.AssignedBag G X δ η) (u : Fin n) : Fin n := + if hu : u ∈ A.centers then (A.neighbor_exists hu).choose else u + +lemma neighbor_spec (A : H.AssignedBag G X δ η) {u : Fin n} (hu : u ∈ A.centers) : + A.neighbor u ∈ H.parent A.owner\A.owner ∧ + l1dist (X u) (X (A.neighbor u)) < δ ∧ + ∃e : Fin m, (G.left e = u ∧ G.right e = A.neighbor u) ∨ + (G.left e = A.neighbor u ∧ G.right e = u) := by + simpa only [neighbor,dite_eq_left hu] using (A.neighbor_exists hu).choose_spec + +lemma input_injective (A : H.AssignedBag G X δ η) (P : Finset (Finset (Fin n))) : + Function.Injective (A.input P) := by + intro u v hh + exact congrArg (fun B : Record n => B.shell.center) hh + +lemma input_arrangement (A : H.AssignedBag G X δ η) {q : ℝ} + {P : Finset (Finset (Fin n))} {U : Finset (Fin n)} (hU : U ⊆ A.centers) + (hvalid : ∀u ∈ U, (A.input P u).Valid H G X q) : + H.LabeledArrangement G X q (U.image (A.input P)) := by + constructor + · intro B hB + obtain ⟨u,hu,rfl⟩ := mem_image.mp hB + exact hvalid u hu + · intro B hB D hD hne hgeo + obtain ⟨u,hu,rfl⟩ := mem_image.mp hB + obtain ⟨v,hv,rfl⟩ := mem_image.mp hD + exact (hgeo (A.disjoint (hU hu) (hU hv) (fun hh => hne (congrArg (A.input P) hh)))).elim + +end AssignedBag + +namespace Record + +lemma unique_interior (_hX : ∀v, binary (X v)) {q : ℝ} + {Z : Finset (Record n)} (hZ : H.LabeledArrangement G X q Z) + {A B D : Record n} (hA : A.Shape H) (hB : B ∈ Z) (hD : D ∈ Z) + (horder : ∀E ∈ Z, E.owner ⊂ A.owner → E.owner ∈ A.excluded) + (hAB : (A.conflict H ∩ B.conflict H).Nonempty) + (hAD : (A.conflict H ∩ D.conflict H).Nonempty) + (hsub : A.shell.support X ⊆ D.shell.support X) + (hmeet : ¬Disjoint (A.shell.support X) (B.shell.support X)) : B = D := by + by_contra hne + have hba := candidate_ancestor H hA (hZ.1 B hB).1 (horder B hB) hAB + have hda := candidate_ancestor H hA (hZ.1 D hD).1 (horder D hD) hAD + rcases H.labeled_pair G X hZ hB hD hne with hh | hh + · exact hmeet ((hh.symm).mono_left hsub) + · exact Finset.disjoint_left.mp hh hba hda + +lemma strict_owner_of_interior (hX : ∀v, binary (X v)) + {A B : Record n} (hA : A.Shape H) (hB : B.Shape H) + (hAv : A.shell.Valid X) (hδ : 0 ≤ δ) + (hball : A.shell = RadialShell.ball A.shell.center δ) + (horder : B.owner ⊂ A.owner → B.owner ∈ A.excluded) + (hsep : B.owner = A.owner → Disjoint (A.shell.support X) (B.shell.support X)) + (hinter : A.Interior H X 256 δ B) : A.owner ⊂ B.owner := by + have hanc := candidate_ancestor H hA hB horder hinter.1 + have hsub := (H.mem_domain.mp hanc).2.1 + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨hsub,?_⟩ + intro hh + obtain ⟨z,hz⟩ := RadialShell.valid_support_nonempty hX hAv + exact Set.disjoint_left.mp (hsep hh.symm) hz + (interior_ball_subset H X hδ hball hinter hz) + +end Record +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma large_component (A : H.AssignedBag G X δ η) {q : ℝ} + (hq : 0 < q) (hconn : H.LocallyConnectedReal G q) (hη : 3072/q ≤ η) + {U : Finset (Fin n)} (hU : U ⊆ A.centers) (hhalf : A.centers.card ≤ 2*U.card) : + ∃R : Finset (Fin n), R ⊆ H.parent A.owner\A.owner ∧ + G.EdgeConnectedReal R (q/4) ∧ 768 ≤ (U.filter (fun u => A.neighbor u ∈ R)).card := by + obtain ⟨J,hJ,hJc,hcount⟩ := G.outside_connected_partition hq + (hconn (H.parent A.owner) (H.parent_mem A.owner A.owner_mem A.nonroot)) + (H.nonempty A.owner A.owner_mem) (H.parent_strict A.owner A.owner_mem A.nonroot) + have hJn : J.Nonempty := by + have hout : (H.parent A.owner\A.owner).Nonempty := + sdiff_nonempty.mpr (H.parent_strict A.owner A.owner_mem A.nonroot).not_subset + rw [← hJ.2.2] at hout + obtain ⟨R,hR,_⟩ := biUnion_nonempty.mp hout + exact ⟨R,hR⟩ + have hcover : ∀u ∈ U, ∃R ∈ J, A.neighbor u ∈ R := by + intro u hu + have hh := (A.neighbor_spec (hU hu)).1 + rw [← hJ.2.2] at hh + simpa only [mem_biUnion,id_eq] using hh + have hb := H.parent_boundary_lower G hconn A.owner_mem A.nonroot + have hηq : 3072 ≤ η*q := (div_le_iff₀ hq).mp hη + have hsum := mul_le_mul_of_nonneg_right A.assignment hq.le + have hmass := mul_le_mul_of_nonneg_right hηq + (Nat.cast_nonneg (H.parentBoundary G A.owner).card : (0:ℝ) ≤ _) + have hhalf' : (A.centers.card : ℝ) ≤ 2*(U.card : ℝ) := by exact_mod_cast hhalf + have hmul := mul_le_mul_of_nonneg_left hhalf' hq.le + obtain ⟨R,hR,hlarge⟩ := AssignedSelection.large_neighbor_class U J + (fun u R => A.neighbor u ∈ R) hJn hcover hq (lt_of_lt_of_le hq hb) + (by simpa [mul_comm,Hierarchy.parentBoundary] using hcount) + (by nlinarith) + exact ⟨R,(hJ.1 R hR).2,hJc R hR,hlarge⟩ + +lemma selected_interior (A : H.AssignedBag G X δ η) (hX : ∀v, binary (X v)) + {q : ℝ} {P : Finset (Finset (Fin n))} {U : Finset (Fin n)} + {Z : Finset (Record n)} (hZ : H.LabeledArrangement G X q Z) + (hshape : ∀u ∈ U, (A.input P u).Shape H) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hinter : ∀u ∈ U, ∃D ∈ Z, (A.input P u).Interior H X 256 δ D) + {B : Record n} (hB : B ∈ Z) {u₀ : Fin n} + (hint₀ : (A.input P u₀).Interior H X 256 δ B) + {a b : ℝ} (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + {u : Fin n} (hu : u ∈ U) + (hr : a-δ < l1dist (X u) (X B.shell.center) ∧ + l1dist (X u) (X B.shell.center) < b+δ) : + (A.input P u).Interior H X 256 δ B := by + obtain ⟨D,hD,hintD⟩ := hinter u hu + have hconf : ((A.input P u).conflict H ∩ B.conflict H).Nonempty := hint₀.1 + have hmeet : ¬Disjoint ((A.input P u).shell.support X) (B.shell.support X) := + RadialShell.ball_meets_radial hX (hZ.1 B hB).2.2.1 u A.radius_pos + (by linarith [hr.1]) (by linarith [hr.2]) + have heq : B = D := Record.unique_interior hX hZ (hshape u hu) hB hD + (fun E hE hsub => by simpa [input,Record.excluded] using horder E hE hsub) + hconf hintD.1 (Record.interior_ball_subset H X A.radius_pos.le rfl hintD) hmeet + exact heq.symm ▸ hintD + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma radial_group (A : H.AssignedBag G X δ η) (hX : ∀v, binary (X v)) + {q : ℝ} {P : Finset (Finset (Fin n))} {U : Finset (Fin n)} + (hU : U ⊆ A.centers) {Z : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) + (hshape : ∀u ∈ U, (A.input P u).Shape H) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hinter : ∀u ∈ U, ∃D ∈ Z, (A.input P u).Interior H X 256 δ D) + (hno : ∀u ∈ U, ∀D ∈ Z, (A.input P u).Interior H X 256 δ D → D.avoided = none) + {R : Finset (Fin n)} (hlarge : 768 ≤ (U.filter (fun u => A.neighbor u ∈ R)).card) : + ∃(B : Record n) (a b : ℝ) (M : Finset (Fin n)) (u₁ u₂ : Fin n), + B ∈ Z ∧ B.avoided = none ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer ∧ a ≤ b ∧ + M.Nonempty ∧ M = U.filter (fun u => a-δ < l1dist (X u) (X B.shell.center) ∧ + l1dist (X u) (X B.shell.center) < b+δ) ∧ + (∀u ∈ M, (A.input P u).Interior H X 256 δ B) ∧ + (768 ≤ M.card ∨ 255*δ ≤ b-a) ∧ + u₁ ∈ U ∧ u₂ ∈ U ∧ A.neighbor u₁ ∈ R ∧ A.neighbor u₂ ∈ R ∧ + l1dist (X (A.neighbor u₁)) (X B.shell.center) ≤ a ∧ + b ≤ l1dist (X (A.neighbor u₂)) (X B.shell.center) ∧ + l1dist (X u₁) (X B.shell.center) ≤ a+δ ∧ + b-δ ≤ l1dist (X u₂) (X B.shell.center) := by + let K := U.filter (fun u => A.neighbor u ∈ R) + have hKn : K.Nonempty := card_pos.mp (lt_of_lt_of_le (by norm_num : 0<768) hlarge) + obtain ⟨u₀,hu₀⟩ := hKn + obtain ⟨B,hB,hint₀⟩ := hinter u₀ (mem_filter.mp hu₀).1 + let ρ := fun u => l1dist (X u) (X B.shell.center) + obtain ⟨u₁,hu₁,hmin⟩ := K.exists_min_image (fun u => ρ (A.neighbor u)) ⟨u₀,hu₀⟩ + obtain ⟨u₂,hu₂,hmax⟩ := K.exists_max_image (fun u => ρ (A.neighbor u)) ⟨u₀,hu₀⟩ + let a := max B.shell.inner (ρ (A.neighbor u₁)) + let b := min B.shell.outer (ρ (A.neighbor u₂)) + let M := U.filter (fun u => a-δ < ρ u ∧ ρ u < b+δ) + have hnear (u : Fin n) (hu : u ∈ U) : |ρ u - ρ (A.neighbor u)| < δ := + (l1dist_reverse _ _ _).trans_lt (A.neighbor_spec (hU hu)).2.1 + have hr₀ := AssignedSelection.interior_neighbor_in_range A.radius_pos (hmin u₀ hu₀) (hmax u₀ hu₀) + hint₀.2.1 hint₀.2.2 (hnear u₀ (mem_filter.mp hu₀).1) + have hMn : M.Nonempty := ⟨u₀,mem_filter.mpr ⟨(mem_filter.mp hu₀).1,hr₀.2⟩⟩ + have hMinter : ∀u ∈ M, (A.input P u).Interior H X 256 δ B := by + intro u hu + obtain ⟨hu,hr⟩ := mem_filter.mp hu + exact A.selected_interior hX hZ hshape horder hinter hB hint₀ + (le_max_left _ _) (min_le_left _ _) hu hr + have hdich : 768 ≤ M.card ∨ 255*δ ≤ b-a := by + by_cases hs : K ⊆ M + · exact Or.inl (hlarge.trans (card_le_card hs)) + · obtain ⟨u,hu,huM⟩ := Finset.not_subset.mp hs + have hr : ¬(a-δ < ρ u ∧ ρ u < b+δ) := + fun hh => huM (mem_filter.mpr ⟨(mem_filter.mp hu).1,hh⟩) + exact Or.inr (AssignedSelection.radial_range A.radius_pos (hmin u₀ hu₀) (hmax u₀ hu₀) + hint₀.2.1 hint₀.2.2 (hnear u₀ (mem_filter.mp hu₀).1) + (hmin u hu) (hmax u hu) (hnear u (mem_filter.mp hu).1) hr) + have hnear₁ := (abs_lt.mp (hnear u₁ (mem_filter.mp hu₁).1)).2 + have hnear₂ := (abs_lt.mp (hnear u₂ (mem_filter.mp hu₂).1)).1 + refine ⟨B,a,b,M,u₁,u₂,hB,hno u₀ (mem_filter.mp hu₀).1 B hB hint₀, + le_max_left _ _,min_le_left _ _,hr₀.1,hMn,rfl,hMinter,hdich, + (mem_filter.mp hu₁).1,(mem_filter.mp hu₂).1,(mem_filter.mp hu₁).2,(mem_filter.mp hu₂).2, + le_max_right _ _,min_le_right _ _,?_,?_⟩ + · change ρ u₁ ≤ a+δ + have hh : ρ (A.neighbor u₁) ≤ a := le_max_right _ _ + linarith + · change b-δ ≤ ρ u₂ + have hh : b ≤ ρ (A.neighbor u₂) := min_le_right _ _ + linarith + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +namespace Record + +def RadialRefines (D B : Record n) : Prop := + D.shell.center = B.shell.center ∧ B.shell.inner ≤ D.shell.inner ∧ + D.shell.outer ≤ B.shell.outer ∧ D.conflict H ⊆ B.conflict H + +lemma radialRefines_refl (B : Record n) : B.RadialRefines (H := H) B := + ⟨rfl,le_refl _,le_refl _,Subset.refl _⟩ + +lemma restriction_radialRefines (B : Record n) {a b : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) : + (B.restriction a b).RadialRefines (H := H) B := ⟨rfl,ha,hb,Subset.refl _⟩ + +lemma central_radialRefines {B : Record n} (hB : B.Shape H) (hno : B.avoided = none) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) {a b c d : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hc : B.shell.inner ≤ c) (hd : d ≤ B.shell.outer) : + (B.innerRecord t a b).RadialRefines (H := H) B ∧ + (B.outsideRecord t c d).RadialRefines (H := H) B := by + obtain ⟨h1,h2⟩ := central_conflict H hB hno ht a b c d + refine ⟨⟨rfl,ha,hb,?_⟩,⟨rfl,hc,hd,?_⟩⟩ + · rw [h1]; exact filter_subset _ _ + · rw [h2]; exact filter_subset _ _ + +def InteriorTo (δ : ℝ) (Z : Finset (Record n)) (A : Record n) : Prop := + ∃B ∈ Z, A.Interior H X 256 δ B + +end Record + +def Evolution (F Z Z' : Finset (Record n)) : Prop := + ∀D ∈ Z', D ∈ F ∨ ∃B ∈ Z, D.RadialRefines (H := H) B + +def OwnerEvolution (t : Finset (Fin n)) (Z Z' : Finset (Record n)) : Prop := + ∀D ∈ Z', D.owner = t ∨ ∃B ∈ Z, D.owner = B.owner + +lemma evolution_interior {δ : ℝ} (hδ : 0 ≤ δ) + {F Z Z' : Finset (Record n)} (hF : ∀D ∈ F, D.shell.width = δ) + (hevol : Evolution (H := H) F Z Z') {A : Record n} + (hh : A.InteriorTo (H := H) (X := X) δ Z') : A.InteriorTo (H := H) (X := X) δ Z := by + obtain ⟨D,hD,hint⟩ := hh + rcases hevol D hD with hD | ⟨B,hB,href⟩ + · exact (Record.not_interior_ball H X (by norm_num : (1:ℝ) ≤ 256) hδ A D + (hF D hD).le hint).elim + · exact ⟨B,hB,Record.interior_restriction H X href.1 href.2.1 href.2.2.1 href.2.2.2 hint⟩ + +lemma ownerEvolution_order {t : Finset (Fin n)} {P : Finset (Finset (Fin n))} + {Z Z' : Finset (Record n)} (hold : ∀B ∈ Z, B.owner ⊂ t → B.owner ∈ P) + (hevol : OwnerEvolution t Z Z') : ∀B ∈ Z', B.owner ⊂ t → B.owner ∈ P := by + intro B hB hs + rcases hevol B hB with hh | ⟨D,hD,hh⟩ + · exact (hs.ne hh).elim + · rw [hh] at hs ⊢ + exact hold D hD hs + +namespace AssignedBag +variable {δ η : ℝ} (A : H.AssignedBag G X δ η) + +def SameOwnerSeparated (P : Finset (Finset (Fin n))) (U : Finset (Fin n)) + (Z : Finset (Record n)) : Prop := + ∀u ∈ U, (A.input P u).InteriorTo (H := H) (X := X) δ Z → + ∀B ∈ Z, B.owner = A.owner → + Disjoint ((RadialShell.ball u δ).support X) (B.shell.support X) + +lemma metadata_evolution {F Z Z' Q : Finset (Record n)} + (hQ : ∀D ∈ Q, D ∈ F ∨ ∃B ∈ Z, D.RadialRefines (H := H) B) + (hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃B ∈ Z, ∃a b, + D = B.restriction a b ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer) : + Evolution (H := H) F Z Z' := by + intro D hD + rcases hmeta D hD with hD | hD | ⟨B,hB,a,b,rfl,ha,hb⟩ + · exact Or.inr ⟨D,hD,D.radialRefines_refl⟩ + · exact hQ D hD + · exact Or.inr ⟨B,hB,B.restriction_radialRefines ha hb⟩ + +lemma metadata_owners {Z Z' Q : Finset (Record n)} + (hQ : ∀D ∈ Q, D.owner = A.owner ∨ ∃B ∈ Z, D.owner = B.owner) + (hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃B ∈ Z, ∃a b, + D = B.restriction a b ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer) : + OwnerEvolution A.owner Z Z' := by + intro D hD + rcases hmeta D hD with hD | hD | ⟨B,hB,a,b,rfl,_⟩ + · exact Or.inr ⟨D,hD,rfl⟩ + · exact hQ D hD + · exact Or.inr ⟨B,hB,rfl⟩ + +lemma metadata_separation {P : Finset (Finset (Fin n))} {U V : Finset (Fin n)} + (hVU : V ⊆ U) {Z Z' Q F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.width = δ) (hevol : Evolution (H := H) F Z Z') + (hsep : A.SameOwnerSeparated P U Z) + (hQ : ∀D ∈ Q, D.owner = A.owner → ∀u ∈ V, + (A.input P u).InteriorTo (H := H) (X := X) δ Z → + Disjoint ((RadialShell.ball u δ).support X) (D.shell.support X)) + (hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃B ∈ Z, ∃a b, + D = B.restriction a b ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer) : + A.SameOwnerSeparated P V Z' := by + intro u hu hint D hD hown + have hintold := evolution_interior A.radius_pos.le hF hevol hint + rcases hmeta D hD with hD | hD | ⟨B,hB,a,b,rfl,ha,hb⟩ + · exact hsep u (hVU hu) hintold D hD hown + · exact hQ D hD hown u hu hintold + · exact (hsep u (hVU hu) hintold B hB hown).mono_right + (RadialShell.restriction_subset X B.shell ha hb) + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma metadata_fresh (A : H.AssignedBag G X δ η) {P : Finset (Finset (Fin n))} + {F Z Z' Q : Finset (Record n)} {M : Finset (Fin n)} + (hF : ∀D ∈ F, D.shell.ordinary = true) + (hQ : ∀D ∈ Q, D ∈ F → ∃u ∈ M, D = A.input P u) + (hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃B ∈ Z, ∃a b, + D = B.restriction a b ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer) : + ∀D ∈ Z', D ∈ F → D ∈ Z ∨ ∃u ∈ M, D = A.input P u := by + intro D hD hDF + rcases hmeta D hD with hD | hD | ⟨B,hB,a,b,rfl,_⟩ + · exact Or.inl hD + · exact Or.inr (hQ D hD hDF) + · exact (Record.restriction_not_fresh hF B a b hDF).elim + +structure InteriorMove (A : H.AssignedBag G X δ η) + (q ε : ℝ) (P : Finset (Finset (Fin n))) + (F Z : Finset (Record n)) (U : Finset (Fin n)) where + treated : Finset (Fin n) + next : Finset (Record n) + nonempty : treated.Nonempty + treated_interior : ∀u ∈ treated, u ∈ U ∧ + (A.input P u).InteriorTo (H := H) (X := X) δ Z + valid : H.LabeledArrangement G X (q/4) next + credit : (∑D ∈ Z, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*(treated.card : ℝ)*δ ≤ + ∑D ∈ next, Record.phaseToken F δ ε D + evolution : Evolution (H := H) F Z next + owners : OwnerEvolution A.owner Z next + fresh : ∀D ∈ next, D ∈ F → D ∈ Z ∨ ∃u ∈ treated, D = A.input P u + separation : A.SameOwnerSeparated P (U\treated) next + +lemma avoiding_move (A : H.AssignedBag G X δ η) (hX : ∀v, binary (X v)) + {q ε : ℝ} (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} {U : Finset (Fin n)} (hU : U ⊆ A.centers) + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : H.LabeledArrangement G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) + {u : Fin n} (hu : u ∈ U) {B : Record n} (hB : B ∈ Z) + (havoid : B.avoided.isSome = true) (hinter : (A.input P u).Interior H X 256 δ B) : + Nonempty (InteriorMove A q ε P F Z U) := by + obtain ⟨Z',hZ',hcredit,hmeta₀⟩ := H.avoiding_operation G X hX A.radius_pos hε + (fun D hD => ⟨(hF D hD).1,(hF D hD).2.2⟩) hZ (hvalid u (hU hu)) + (hAF u (hU hu)) rfl hB havoid + (fun D hD hs => by simpa [input,Record.excluded] using horder D hD hs) hinter + let Q : Finset (Record n) := {A.input P u} + have hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃E ∈ Z, ∃a b, + D = E.restriction a b ∧ E.shell.inner ≤ a ∧ b ≤ E.shell.outer := by + intro D hD + rcases hmeta₀ D hD with hD | rfl | ⟨a,b,heq,ha,hb,_⟩ + · exact Or.inl hD + · exact Or.inr (Or.inl (mem_singleton_self _)) + · exact Or.inr (Or.inr ⟨B,hB,a,b,heq,ha,hb⟩) + have hevol : Evolution (H := H) F Z Z' := metadata_evolution + (fun D hD => Or.inl ((mem_singleton.mp hD).symm ▸ hAF u (hU hu))) hmeta + have howner : OwnerEvolution A.owner Z Z' := A.metadata_owners + (fun D hD => Or.inl (by rw [mem_singleton.mp hD]; rfl)) hmeta + have hfresh := A.metadata_fresh (fun D hD => (hF D hD).1) + (M := {u}) (by + intro D hD _ + exact ⟨u,mem_singleton_self _,mem_singleton.mp hD⟩) hmeta + have hsep' : A.SameOwnerSeparated P (U\{u}) Z' := by + apply A.metadata_separation sdiff_subset (fun D hD => (hF D hD).2.1) hevol hsep _ hmeta + intro D hD _ v hv _ + rw [mem_singleton.mp hD] + obtain ⟨hv,hvu⟩ := mem_sdiff.mp hv + exact A.disjoint (hU hv) (hU hu) (by simpa only [mem_singleton] using hvu) + refine ⟨⟨{u},Z',singleton_nonempty _,?_,hZ',?_,hevol,howner,hfresh,hsep'⟩⟩ + · intro v hv + rw [mem_singleton.mp hv] + exact ⟨hu,⟨B,hB,hinter⟩⟩ + · simpa only [card_singleton,Nat.cast_one,mul_one] using hcredit + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/BagConstruction.lean b/lean/OAI/Combinatorics/ThinTrees/BagConstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..d1fa48db2d32a930535f7aa90cb5e5e1ea492767 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/BagConstruction.lean @@ -0,0 +1,482 @@ +import OAI.Combinatorics.ThinTrees.BagBounds + +namespace OAI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma dense_move (A : H.AssignedBag G X δ η) (hX : ∀v, binary (X v)) + {q ε a b : ℝ} (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} {U M : Finset (Fin n)} (hU : U ⊆ A.centers) + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : H.LabeledArrangement G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) + {B : Record n} (hB : B ∈ Z) (hno : B.avoided = none) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) (hab : a ≤ b) + (hMn : M.Nonempty) (hMU : M ⊆ U) + (hinter : ∀u ∈ M, (A.input P u).Interior H X 256 δ B) + (hrange : ∀u ∈ M, a-δ < l1dist (X u) (X B.shell.center) ∧ + l1dist (X u) (X B.shell.center) < b+δ) + (hcount : 765*δ ≤ (M.card : ℝ)*δ) (hdense : 3*(b-a) ≤ (M.card : ℝ)*δ) : + Nonempty (InteriorMove A q ε P F Z U) := by + let Q := M.image (A.input P) + have hQcard : Q.card = M.card := card_image_of_injective _ (A.input_injective P) + obtain ⟨u₀,hu₀⟩ := hMn + have hwidth := Record.interior_width H X (hinter u₀ hu₀) + obtain ⟨Z',hZ',hcredit,hmeta₀⟩ := H.dense_operation G X hX A.radius_pos hε hF hZ hB + (A.input_arrangement (hMU.trans hU) (fun u hu => hvalid u (hU (hMU hu)))) + (by intro D hD; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD; exact hAF u (hU (hMU hu))) + (by intro D hD; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD; rfl) hno hwidth ha hb hab + (by intro D hD; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD; exact hrange u hu) + (by intro D hD; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD; exact hinter u hu) + (by intro D hD E hE hs; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + simpa [input,Record.excluded] using horder E hE hs) + (by rwa [hQcard]) (by rwa [hQcard]) + have hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃E ∈ Z, ∃a b, + D = E.restriction a b ∧ E.shell.inner ≤ a ∧ b ≤ E.shell.outer := by + intro D hD + rcases hmeta₀ D hD with hD | hD | ⟨a,b,heq,ha,hb,_⟩ + · exact Or.inl hD + · exact Or.inr (Or.inl hD) + · exact Or.inr (Or.inr ⟨B,hB,a,b,heq,ha,hb⟩) + have hevol : Evolution (H := H) F Z Z' := metadata_evolution (by + intro D hD + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + exact Or.inl (hAF u (hU (hMU hu)))) hmeta + have howner : OwnerEvolution A.owner Z Z' := A.metadata_owners (by + intro D hD + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + exact Or.inl rfl) hmeta + have hfresh := A.metadata_fresh (fun D hD => (hF D hD).1) + (M := M) (by + intro D hD _ + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + exact ⟨u,hu,rfl⟩) hmeta + have hsep' : A.SameOwnerSeparated P (U\M) Z' := by + apply A.metadata_separation sdiff_subset (fun D hD => (hF D hD).2.1) hevol hsep _ hmeta + intro D hD _ v hv _ + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + obtain ⟨hv,hvM⟩ := mem_sdiff.mp hv + exact A.disjoint (hU hv) (hU (hMU hu)) (fun hh => hvM (hh ▸ hu)) + refine ⟨⟨M,Z',⟨u₀,hu₀⟩,fun u hu => ⟨hMU hu,⟨B,hB,hinter u hu⟩⟩, + hZ',?_,hevol,howner,hfresh,hsep'⟩⟩ + rwa [hQcard] at hcredit + +lemma sparse_move (A : H.AssignedBag G X δ η) (hX : ∀v, binary (X v)) + {q ε a b : ℝ} {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} {U M : Finset (Fin n)} (hU : U ⊆ A.centers) + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : H.LabeledArrangement G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) + {B : Record n} (hB : B ∈ Z) (hno : B.avoided = none) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hMn : M.Nonempty) (hMU : M ⊆ U) + (hinter : ∀u ∈ M, (A.input P u).Interior H X 256 δ B) + (hexact : ∀u ∈ U, (A.input P u).InteriorTo (H := H) (X := X) δ Z → + a-δ < l1dist (X u) (X B.shell.center) → + l1dist (X u) (X B.shell.center) < b+δ → u ∈ M) + (hwide : 255*δ ≤ b-a) (hsparse : (M.card : ℝ)*δ ≤ 3*(b-a)) + (hinner : (B.innerRecord A.owner (a+δ) (b-δ)).Valid H G X (q/4)) + (houter : (B.outsideRecord A.owner a b).Valid H G X (q/4)) : + Nonempty (InteriorMove A q ε P F Z U) := by + obtain ⟨u₀,hu₀⟩ := hMn + have hint := hinter u₀ hu₀ + have hov := hvalid u₀ (hU (hMU hu₀)) + have ht := Record.candidate_ancestor H hov.1 (hZ.1 B hB).1 + (fun hs => by simpa [input,Record.excluded] using horder B hB hs) hint.1 + have hstrict : A.owner ⊂ B.owner := Record.strict_owner_of_interior hX + hov.1 (hZ.1 B hB).1 hov.2.2.1 A.radius_pos.le rfl + (fun hs => by simpa [input,Record.excluded] using horder B hB hs) (hsep u₀ (hMU hu₀) ⟨B,hB,hint⟩ B hB) hint + obtain ⟨Z',hZ',hcredit,hmeta₀⟩ := H.sparse_operation G X hX A.radius_pos + (fun D hD => ⟨(hF D hD).1,(hF D hD).2.1⟩) hZ hB hno + (Record.interior_width H X hint) ht ha hb hwide hsparse hinner houter + let C := B.innerRecord A.owner (a+δ) (b-δ) + let D := B.outsideRecord A.owner a b + let Q : Finset (Record n) := {C,D} + have hmeta : ∀E ∈ Z', E ∈ Z ∨ E ∈ Q ∨ ∃K ∈ Z, ∃c d, + E = K.restriction c d ∧ K.shell.inner ≤ c ∧ d ≤ K.shell.outer := by + intro E hE + rcases hmeta₀ E hE with hE | rfl | rfl | ⟨c,d,heq,hc,hd,_⟩ + · exact Or.inl hE + · exact Or.inr (Or.inl (mem_insert_self _ _)) + · exact Or.inr (Or.inl (mem_insert_of_mem (mem_singleton_self _))) + · exact Or.inr (Or.inr ⟨B,hB,c,d,heq,hc,hd⟩) + have href := Record.central_radialRefines (hZ.1 B hB).1 hno ht + (by linarith [A.radius_pos] : B.shell.inner ≤ a+δ) + (by linarith [A.radius_pos] : b-δ ≤ B.shell.outer) ha hb + have hevol : Evolution (H := H) F Z Z' := metadata_evolution (by + intro E hE + rcases mem_insert.mp hE with rfl | hE + · exact Or.inr ⟨B,hB,href.1⟩ + · rw [mem_singleton.mp hE] + exact Or.inr ⟨B,hB,href.2⟩) hmeta + have howner : OwnerEvolution A.owner Z Z' := A.metadata_owners (by + intro E hE + rcases mem_insert.mp hE with rfl | hE + · exact Or.inl rfl + · rw [mem_singleton.mp hE] + exact Or.inr ⟨B,hB,rfl⟩) hmeta + have hfresh := A.metadata_fresh (fun D hD => (hF D hD).1) + (P := P) (M := M) (by + intro E hE hEF + have hh := (hF E hEF).1 + rcases mem_insert.mp hE with rfl | hE + · simp [C,Record.innerRecord,RadialShell.hollow] at hh + · rw [mem_singleton.mp hE] at hh + simp [D,Record.outsideRecord,RadialShell.hollow] at hh) hmeta + have hsep' : A.SameOwnerSeparated P (U\M) Z' := by + apply A.metadata_separation sdiff_subset (fun D hD => (hF D hD).2.1) hevol hsep _ hmeta + intro E hE hown u hu hintold + rcases mem_insert.mp hE with rfl | hE + · obtain ⟨hu,huM⟩ := mem_sdiff.mp hu + by_cases hlo : a-δ < l1dist (X u) (X B.shell.center) + · have hhi : b+δ ≤ l1dist (X u) (X B.shell.center) := + le_of_not_gt (fun hh => huM (hexact u hu hintold hlo hh)) + exact RadialShell.ball_disjoint_hollow_lower X _ _ (by linarith [A.radius_pos]) + · exact RadialShell.ball_disjoint_hollow_upper X _ _ (by + have := not_lt.mp hlo + linarith [A.radius_pos]) + · rw [mem_singleton.mp hE] at hown + exact (hstrict.ne hown.symm).elim + exact ⟨⟨M,Z',⟨u₀,hu₀⟩,fun u hu => ⟨hMU hu,⟨B,hB,hinter u hu⟩⟩, + hZ',hcredit,hevol,howner,hfresh,hsep'⟩⟩ + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma interior_move (A : H.AssignedBag G X δ η) (hX : ∀v, binary (X v)) + {q ε : ℝ} (hq : 0 < q) (hconn : H.LocallyConnectedReal G q) + (hη : 3072/q ≤ η) (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} {U : Finset (Fin n)} (hU : U ⊆ A.centers) + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : H.LabeledArrangement G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) + (hhalf : A.centers.card ≤ 2*(U.filter (fun u => + (A.input P u).InteriorTo (H := H) (X := X) δ Z)).card) : + Nonempty (InteriorMove A q ε P F Z U) := by + by_cases hav : ∃u ∈ U, ∃B ∈ Z, B.avoided.isSome = true ∧ + (A.input P u).Interior H X 256 δ B + · obtain ⟨u,hu,B,hB,hav,hint⟩ := hav + exact A.avoiding_move hX hε hU hF hAF hvalid hZ horder hsep hu hB hav hint + let I := U.filter (fun u => (A.input P u).InteriorTo (H := H) (X := X) δ Z) + have hIU : I ⊆ U := by + intro u hu + exact (mem_filter.mp hu).1 + have hI : ∀u ∈ I, (A.input P u).InteriorTo (H := H) (X := X) δ Z := + fun u hu => (mem_filter.mp hu).2 + obtain ⟨R,hR,hRc,hlarge⟩ := A.large_component hq hconn hη (hIU.trans hU) hhalf + have hno : ∀u ∈ I, ∀D ∈ Z, (A.input P u).Interior H X 256 δ D → D.avoided = none := by + intro u hu D hD hint + cases hh : D.avoided with + | none => rfl + | some t => exact (hav ⟨u,hIU hu,D,hD,by simp [hh],hint⟩).elim + obtain ⟨B,a,b,M,u₁,u₂,hB,hBno,ha,hb,hab,hMn,hMeq,hinter,hdich, + hu₁,hu₂,hv₁,hv₂,hv₁r,hv₂r,hu₁r,hu₂r⟩ := A.radial_group hX (hIU.trans hU) hZ + (fun u hu => (hvalid u (hU (hIU hu))).1) horder hI hno hlarge + have hMI : M ⊆ I := by rw [hMeq]; exact filter_subset _ _ + have hMU : M ⊆ U := hMI.trans hIU + have hrange : ∀u ∈ M, a-δ < l1dist (X u) (X B.shell.center) ∧ + l1dist (X u) (X B.shell.center) < b+δ := by + intro u hu + rw [hMeq] at hu + exact (mem_filter.mp hu).2 + have hdich' : (768:ℝ) ≤ M.card ∨ 255*δ ≤ b-a := by exact_mod_cast hdich + by_cases hdense : 3*(b-a) ≤ (M.card : ℝ)*δ + · have hcount := AssignedSelection.dense_count A.radius_pos.le (by norm_num : (768:ℝ) ≤ 768) + hdich' hdense + exact A.dense_move hX hε hU hF hAF hvalid hZ horder hsep hB hBno ha hb hab + hMn hMU hinter hrange hcount hdense + · have hsparse : (M.card : ℝ)*δ ≤ 3*(b-a) := (not_le.mp hdense).le + have hwide := AssignedSelection.sparse_width A.radius_pos.le (by norm_num : (768:ℝ) ≤ 768) + hdich' hsparse + obtain ⟨u₀,hu₀⟩ := hMn + have hint := hinter u₀ hu₀ + have hov := hvalid u₀ (hU (hMU hu₀)) + have ht := Record.candidate_ancestor H hov.1 (hZ.1 B hB).1 (fun hs => by simpa [input,Record.excluded] using horder B hB hs) hint.1 + have hstrict : A.owner ⊂ B.owner := Record.strict_owner_of_interior hX + hov.1 (hZ.1 B hB).1 hov.2.2.1 A.radius_pos.le rfl + (fun hs => by simpa [input,Record.excluded] using horder B hB hs) (hsep u₀ (hMU hu₀) ⟨B,hB,hint⟩ B hB) hint + obtain ⟨e,he⟩ := (A.neighbor_spec (hU (hIU hu₁))).2.2 + obtain ⟨hin,hout⟩ := Record.central_valid H G X (hZ.1 B hB) hBno hq.le hconn ht hstrict + ha hb A.radius_pos (by linarith [A.radius_pos]) hR hRc + (A.endpoint u₁ (hU (hIU hu₁))).1 (A.endpoint u₂ (hU (hIU hu₂))).1 + hv₁ hv₂ hu₁r hu₂r hv₁r hv₂r he + apply A.sparse_move hX hU hF hvalid hZ horder hsep hB hBno ha hb ⟨u₀,hu₀⟩ hMU + hinter _ hwide hsparse hin hout + intro u hu hint hlo hhi + rw [hMeq] + exact mem_filter.mpr ⟨mem_filter.mpr ⟨hu,hint⟩,hlo,hhi⟩ + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} + +lemma ownerEvolution_refl (t : Finset (Fin n)) (Z : Finset (Record n)) : OwnerEvolution t Z Z := by + intro D hD + exact Or.inr ⟨D,hD,rfl⟩ + +lemma ownerEvolution_trans {t : Finset (Fin n)} {Z W V : Finset (Record n)} + (h1 : OwnerEvolution t Z W) (h2 : OwnerEvolution t W V) : OwnerEvolution t Z V := by + intro D hD + rcases h2 D hD with hh | ⟨E,hE,hh⟩ + · exact Or.inl hh + · rcases h1 E hE with he | ⟨B,hB,he⟩ + · exact Or.inl (hh.trans he) + · exact Or.inr ⟨B,hB,hh.trans he⟩ + +namespace AssignedBag + +lemma interior_loop (A : H.AssignedBag G X δ η) (hX : ∀v, binary (X v)) + {q ε : ℝ} (hq : 0 < q) (hconn : H.LocallyConnectedReal G q) + (hη : 3072/q ≤ η) (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (U : Finset (Fin n)) (hU : U ⊆ A.centers) (Z : Finset (Record n)) + (hZ : H.LabeledArrangement G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) : + ∃(V : Finset (Fin n)) (Z' : Finset (Record n)), V ⊆ U ∧ + H.LabeledArrangement G X (q/4) Z' ∧ + 2*(V.filter (fun u => (A.input P u).InteriorTo (H := H) (X := X) δ Z')).card < + A.centers.card ∧ + (∑D ∈ Z, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*((U.card : ℝ)-(V.card : ℝ))*δ ≤ + ∑D ∈ Z', Record.phaseToken F δ ε D ∧ + (∀B : Record n, B.InteriorTo (H := H) (X := X) δ Z' → + B.InteriorTo (H := H) (X := X) δ Z) ∧ + OwnerEvolution A.owner Z Z' ∧ + (∀D ∈ Z', D ∈ F → D ∈ Z ∨ ∃u ∈ U\V, D = A.input P u) ∧ + A.SameOwnerSeparated P V Z' := by + induction U using Finset.strongInduction generalizing Z with + | H U ih => + by_cases hstop : 2*(U.filter (fun u => + (A.input P u).InteriorTo (H := H) (X := X) δ Z)).card < A.centers.card + · refine ⟨U,Z,Subset.refl _,hZ,hstop,?_,fun _ h => h,ownerEvolution_refl _ _, + fun _ h _ => Or.inl h,hsep⟩ + simp + · obtain ⟨W⟩ := A.interior_move hX hq hconn hη hε hU hF hAF hvalid hZ horder hsep + (not_lt.mp hstop) + have hMU : W.treated ⊆ U := fun u hu => (W.treated_interior u hu).1 + have hss : U\W.treated ⊂ U := by + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨sdiff_subset,?_⟩ + intro hh + obtain ⟨u,hu⟩ := W.nonempty + have hm : u ∈ U\W.treated := hh.symm ▸ hMU hu + exact (mem_sdiff.mp hm).2 hu + obtain ⟨V,Z',hVU,hZ',hstop',hcredit',hinter',howners',hfresh',hsep'⟩ := ih (U\W.treated) hss + (sdiff_subset.trans hU) W.next W.valid (ownerEvolution_order horder W.owners) W.separation + have hcards : ((U\W.treated).card : ℝ)+(W.treated.card : ℝ) = (U.card : ℝ) := by + exact_mod_cast card_sdiff_add_card_eq_card hMU + refine ⟨V,Z',hVU.trans sdiff_subset,hZ',hstop',?_,?_, + ownerEvolution_trans W.owners howners',?_,hsep'⟩ + · calc + (∑D ∈ Z, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*((U.card : ℝ)-(V.card : ℝ))*δ = + ((∑D ∈ Z, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*(W.treated.card : ℝ)*δ)+ + AssignedAccounting.theta*(((U\W.treated).card : ℝ)-(V.card : ℝ))*δ := by + rw [←hcards] + ring + _ ≤ (∑D ∈ W.next, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*(((U\W.treated).card : ℝ)-(V.card : ℝ))*δ := + add_le_add W.credit (le_refl _) + _ ≤ _ := hcredit' + · intro B hB + exact evolution_interior A.radius_pos.le (fun D hD => (hF D hD).2.1) + W.evolution (hinter' B hB) + · intro D hD hDF + rcases hfresh' D hD hDF with hD | ⟨u,hu,heq⟩ + · rcases W.fresh D hD hDF with hD | ⟨u,hu,heq⟩ + · exact Or.inl hD + · exact Or.inr ⟨u,mem_sdiff.mpr ⟨hMU hu, + fun hv => (mem_sdiff.mp (hVU hv)).2 hu⟩,heq⟩ + · exact Or.inr ⟨u,mem_sdiff.mpr ⟨sdiff_subset (mem_sdiff.mp hu).1, + (mem_sdiff.mp hu).2⟩,heq⟩ + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} +namespace Record + +def baseToken (r : ℝ) (B : Record n) : ℝ := + AssignedAccounting.base B.avoided.isSome B.shell.width r + +def shrinkRecord (F : Finset (Record n)) (δ : ℝ) (B : Record n) : Record n := + if B ∈ F then B else B.restriction (B.shell.inner+257*δ) (B.shell.outer-257*δ) + +def shrinkValue (F : Finset (Record n)) (δ ε : ℝ) (B : Record n) : ℝ := + if B ∈ F then AssignedAccounting.fresh δ ε else + AssignedAccounting.base B.avoided.isSome (B.shell.width-514*δ) ε + +lemma fresh_base {δ ε : ℝ} (hδ : 0 ≤ δ) (hε : ε ≤ δ/1536) + {B : Record n} (hwidth : B.shell.width = δ) (hno : B.avoided = none) : + B.baseToken ε = AssignedAccounting.fresh δ ε := by + simp only [baseToken,hwidth,hno,Option.isSome_none,AssignedAccounting.base, + Bool.false_eq_true,↓reduceIte,AssignedAccounting.fresh,div_one] + exact max_eq_left (by linarith) + +lemma shrink_refines {δ : ℝ} (hδ : 0 ≤ δ) (F : Finset (Record n)) (B : Record n) : + (B.shrinkRecord F δ).Refines H X B := by + by_cases hB : B ∈ F + · simp only [shrinkRecord,ite_eq_left hB] + exact ⟨Set.Subset.refl _,Subset.refl _⟩ + · simp only [shrinkRecord,ite_eq_right hB] + exact B.restriction_refines H X (by linarith) (by linarith) + +lemma shrink_valid {δ q : ℝ} (hδ : 0 ≤ δ) {F : Finset (Record n)} {B : Record n} + (hB : B.Valid H G X q) (hw : 0 < (B.shrinkRecord F δ).shell.width) : + (B.shrinkRecord F δ).Valid H G X q := by + by_cases hf : B ∈ F + · simpa only [shrinkRecord,ite_eq_left hf] using hB + · simp only [shrinkRecord,ite_eq_right hf] at hw ⊢ + exact Record.restrict_valid H G X hB (by linarith) (by linarith) + (by simpa only [restriction,RadialShell.hollow,RadialShell.width,sub_pos] using hw) + +lemma shrink_base {δ ε : ℝ} (hδ : 0 ≤ δ) (hε : ε ≤ δ/1536) + {F : Finset (Record n)} (hF : ∀B ∈ F, B.shell.width = δ ∧ B.avoided = none) + (B : Record n) : (B.shrinkRecord F δ).baseToken ε = B.shrinkValue F δ ε := by + by_cases hf : B ∈ F + · simp only [shrinkRecord,shrinkValue,ite_eq_left hf] + exact fresh_base hδ hε (hF B hf).1 (hF B hf).2 + · simp only [shrinkRecord,shrinkValue,ite_eq_right hf,baseToken,restriction,RadialShell.hollow, + RadialShell.width] + congr 1 + ring + +lemma shrink_cost {δ ε : ℝ} (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) + {F : Finset (Record n)} (hF : ∀B ∈ F, B.shell.width = δ ∧ B.avoided = none) + (B : Record n) : + 0 ≤ B.phaseToken F δ ε-B.shrinkValue F δ ε ∧ + B.phaseToken F δ ε-B.shrinkValue F δ ε ≤ + 256*(B.baseToken ε-B.phaseToken F δ ε) := by + by_cases hf : B ∈ F + · rw [phaseToken,shrinkValue,ite_eq_left hf,ite_eq_left hf, + fresh_base hδ hscale (hF B hf).1 (hF B hf).2] + simp + · simp only [phaseToken,shrinkValue,ite_eq_right hf,baseToken] + exact AssignedAccounting.shrink_cost _ hδ hε hscale + +lemma shrink_discard {δ ε : ℝ} (hδ : 0 < δ) (hε : 0 ≤ ε) + {F : Finset (Record n)} (hF : ∀B ∈ F, B.shell.width = δ) + (B : Record n) (hw : ¬0 < (B.shrinkRecord F δ).shell.width) : + B.shrinkValue F δ ε = 0 := by + by_cases hf : B ∈ F + · rw [shrinkRecord,ite_eq_left hf,hF B hf] at hw + exact (hw hδ).elim + · rw [shrinkValue,ite_eq_right hf] + apply AssignedAccounting.base_discard _ _ hε + rw [shrinkRecord,ite_eq_right hf] at hw + dsimp [restriction,RadialShell.hollow,RadialShell.width] at hw ⊢ + linarith [not_lt.mp hw] + +lemma border_shrink_compatible {δ : ℝ} (_hδ : 0 ≤ δ) {F : Finset (Record n)} + (hF : ∀A ∈ F, ∀B ∈ F, A ≠ B → Disjoint (A.shell.support X) (B.shell.support X)) + {A B : Record n} (hA : A ∈ F) (hne : A ≠ B) + (hball : A.shell = RadialShell.ball A.shell.center δ) + (hbor : ¬A.Interior H X 256 δ B) : + A.Compatible H X (B.shrinkRecord F δ) := by + by_cases hf : B ∈ F + · simp only [shrinkRecord,ite_eq_left hf] + exact Or.inl (hF A hA B hf hne) + · simp only [shrinkRecord,ite_eq_right hf] + by_cases hdis : Disjoint (A.conflict H) (B.conflict H) + · exact Or.inr hdis + · have hmeet : (A.conflict H ∩ B.conflict H).Nonempty := by + apply nonempty_iff_ne_empty.mpr + exact fun hh => hdis (Finset.disjoint_iff_inter_eq_empty.mpr hh) + left + rw [hball] + by_cases hlo : B.shell.inner+256*δ < l1dist (X A.shell.center) (X B.shell.center) + · have hhi : B.shell.outer-256*δ ≤ l1dist (X A.shell.center) (X B.shell.center) := + le_of_not_gt (fun hh => hbor ⟨hmeet,hlo,hh⟩) + exact RadialShell.ball_disjoint_hollow_lower X _ _ (by linarith) + · exact RadialShell.ball_disjoint_hollow_upper X _ _ (by linarith [not_lt.mp hlo]) + +end Record + +def shrinkFamily (F Z : Finset (Record n)) (δ : ℝ) : Finset (Record n) := + (Z.filter (fun B => 0 < (B.shrinkRecord F δ).shell.width)).image (Record.shrinkRecord F δ) + +lemma shrinkFamily_valid {q δ : ℝ} (hδ : 0 ≤ δ) {F Z : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) : H.LabeledArrangement G X q (shrinkFamily F Z δ) := by + constructor + · intro D hD + obtain ⟨B,hB,rfl⟩ := mem_image.mp hD + exact Record.shrink_valid hδ (hZ.1 B (mem_filter.mp hB).1) (mem_filter.mp hB).2 + · intro D hD E hE hne hgeo + obtain ⟨B,hB,rfl⟩ := mem_image.mp hD + obtain ⟨C,hC,rfl⟩ := mem_image.mp hE + have hh := Record.compatible_refinements H X + (H.labeled_pair G X hZ (mem_filter.mp hB).1 (mem_filter.mp hC).1 + (fun hh => hne (congrArg (Record.shrinkRecord F δ) hh))) + (Record.shrink_refines hδ F B) (Record.shrink_refines hδ F C) + exact hh.resolve_left hgeo + +lemma shrinkFamily_sum (hX : ∀v, binary (X v)) {q δ ε : ℝ} + (hδ : 0 < δ) (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) {F Z : Finset (Record n)} + (hF : ∀B ∈ F, B.shell.width = δ ∧ B.avoided = none) + (hZ : H.LabeledArrangement G X q Z) : + ∑D ∈ shrinkFamily F Z δ, D.baseToken ε = ∑B ∈ Z, B.shrinkValue F δ ε := by + have hinj : ∀B ∈ Z.filter (fun B => 0 < (B.shrinkRecord F δ).shell.width), + ∀C ∈ Z.filter (fun B => 0 < (B.shrinkRecord F δ).shell.width), + B.shrinkRecord F δ = C.shrinkRecord F δ → B = C := by + intro B hB C hC heq + by_contra hh + have hv := Record.shrink_valid hδ.le (hZ.1 B (mem_filter.mp hB).1) (mem_filter.mp hB).2 + have hc := Record.compatible_refinements H X + (H.labeled_pair G X hZ (mem_filter.mp hB).1 (mem_filter.mp hC).1 hh) + (Record.shrink_refines hδ.le F B) (Record.shrink_refines hδ.le F C) + rw [←heq] at hc + exact (B.shrinkRecord F δ).compatible_self_iff H X hX hv.1 hv.2.2.1 hc + rw [shrinkFamily,sum_image hinj,sum_filter] + apply sum_congr rfl + intro B hB + by_cases hw : 0 < (B.shrinkRecord F δ).shell.width + · rw [ite_eq_left hw,Record.shrink_base hδ.le hscale hF] + · rw [ite_eq_right hw,Record.shrink_discard hδ hε (fun D hD => (hF D hD).1) B hw] + +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/BagGeometry.lean b/lean/OAI/Combinatorics/ThinTrees/BagGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..2a70fbcebbe06d86f90b1c5f77bf2e62ee32298c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/BagGeometry.lean @@ -0,0 +1,290 @@ +import OAI.Combinatorics.ThinTrees.SpectralPacking + +namespace OAI + +universe uV uI uV2 uV3 uI2 uJ + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.Geometry +noncomputable section +open Finset +open scoped Classical +variable {V : Type uV} {I : Type uI} [DecidableEq V] [DecidableEq I] {h : ℕ} + +omit [DecidableEq V] in +lemma distance_balls_disjoint (X : V → Fin h → ℝ) (u v : V) {r : ℝ} + (hsep : 2*r ≤ l1dist (X u) (X v)) : + Disjoint ((RadialShell.ball u r).support X) ((RadialShell.ball v r).support X) := by + apply Set.disjoint_left.mpr + intro z hz hz' + have hx := l1dist_triangle (X u) z (X v) + rw [l1dist_comm (X u) z] at hx + have hz₁ := hz.2.1 + have hz₂ := hz'.2.1 + change l1dist z (X u) < r at hz₁ + change l1dist z (X v) < r at hz₂ + linarith + +lemma l1_separated_net (X : V → Fin h → ℝ) (F : Finset V) (hF : F.Nonempty) + {r : ℝ} (hr : 0 ≤ r) : + ∃S : Finset V, S ⊆ F ∧ S.Nonempty ∧ + (∀u ∈ S, ∀v ∈ S, u ≠ v → r < l1dist (X u) (X v)) ∧ + ∀u ∈ F, ∃v ∈ S, l1dist (X u) (X v) ≤ r := by + let sep : Finset V → Prop := fun S => ∀u ∈ S, ∀v ∈ S, u ≠ v → r < l1dist (X u) (X v) + let good := F.powerset.filter sep + have hgood : good.Nonempty := ⟨∅,mem_filter.mpr ⟨mem_powerset.mpr (empty_subset _),by simp [sep]⟩⟩ + obtain ⟨S,hS,hmax⟩ := exists_max_image good card hgood + obtain ⟨hSF,hsep⟩ := mem_filter.mp hS + have hcover : ∀u ∈ F, ∃v ∈ S, l1dist (X u) (X v) ≤ r := by + intro u hu + by_contra! hn + have huS : u ∉ S := by + intro huS + have hh := hn u huS + rw [l1dist_self] at hh + linarith + have hnew : insert u S ∈ good := by + apply mem_filter.mpr + refine ⟨mem_powerset.mpr (insert_subset hu (mem_powerset.mp hSF)),?_⟩ + intro x hx y hy hxy + rcases mem_insert.mp hx with rfl | hxS + · rcases mem_insert.mp hy with rfl | hyS + · exact (hxy rfl).elim + · exact hn y hyS + · rcases mem_insert.mp hy with rfl | hyS + · rw [l1dist_comm]; exact hn x hxS + · exact hsep x hxS y hyS hxy + have hh := hmax _ hnew + rw [card_insert_of_notMem huS] at hh + omega + refine ⟨S,mem_powerset.mp hSF,?_,hsep,hcover⟩ + obtain ⟨u,hu⟩ := hF + obtain ⟨v,hv,_⟩ := hcover u hu + exact ⟨v,hv⟩ + +omit [DecidableEq V] in + +lemma retain_fibers (S : Finset V) (T : Finset I) (f : V → I) + (hf : ∀u ∈ S, f u ∈ T) (w : I → ℝ) (hw : ∀i ∈ T, 0 < w i) + {c : ℝ} (hc : 0 < c) : + ∃J : Finset I, J ⊆ T ∧ + (∀i ∈ J, (S.filter (fun u => f u=i)).Nonempty ∧ + c*w i ≤ ((S.filter (fun u => f u=i)).card : ℝ)) ∧ + (S.card : ℝ)-c*(∑i ∈ T, w i) ≤ ∑i ∈ J, ((S.filter (fun u => f u=i)).card : ℝ) := by + let J := T.filter (fun i => c*w i ≤ ((S.filter (fun u => f u=i)).card : ℝ)) + have hsum : (∑i ∈ T, ((S.filter (fun u => f u=i)).card : ℝ)) = S.card := by + rw [←Nat.cast_sum] + congr 1 + exact sum_card_fiberwise_eq_card_filter S T f |>.trans (by + congr 1 + exact filter_eq_self.mpr hf) + refine ⟨J,filter_subset _ _,?_,?_⟩ + · intro i hi + obtain ⟨hi,hci⟩ := mem_filter.mp hi + refine ⟨card_pos.mp ?_,hci⟩ + have hh := mul_pos hc (hw i hi) + have : (0:ℝ) < (S.filter (fun u => f u=i)).card := hh.trans_le hci + exact_mod_cast this + · have hbound : ∑i ∈ T, ((S.filter (fun u => f u=i)).card : ℝ) ≤ + (∑i ∈ T, if i ∈ J then ((S.filter (fun u => f u=i)).card : ℝ) else 0)+c*(∑i ∈ T, w i) := by + rw [mul_sum,←sum_add_distrib] + apply sum_le_sum + intro i hi + by_cases hiJ : i ∈ J + · rw [ite_eq_left hiJ] + linarith [mul_pos hc (hw i hi)] + · rw [ite_eq_right hiJ,zero_add] + exact le_of_lt (lt_of_not_ge (fun hh => hiJ (mem_filter.mpr ⟨hi,hh⟩))) + rw [hsum] at hbound + have he : (∑i ∈ T, if i ∈ J then ((S.filter (fun u => f u=i)).card : ℝ) else 0) = + ∑i ∈ J, ((S.filter (fun u => f u=i)).card : ℝ) := by + rw [←sum_filter] + congr 1 + exact filter_mem_eq_inter.trans (inter_eq_right.mpr (filter_subset _ _)) + rw [he] at hbound + linarith + +end +end StrongThinTree.Geometry + +namespace StrongThinTree.Geometry +noncomputable section +open Finset RadialShell +open scoped Classical +variable {V : Type uV2} [DecidableEq V] {h : ℕ} {X : V → Fin h → ℝ} + +lemma compact_from_net (S W : Finset V) (hS : S.Nonempty) (hW : W.Nonempty) + {δ D : ℝ} (hδ : 0 < δ) (hD : δ ≤ D) + (hsep : (S : Set V).Pairwise (fun u v => + Disjoint ((ball u δ).support X) ((ball v δ).support X))) + (hcover : ∀u ∈ S, ∃v ∈ W, l1dist (X u) (X v) ≤ 3*D) + (hsmall : 432*D*(W.card : ℝ) ≤ δ*(S.card : ℝ)) : + ∃F : CompactFamily X δ (6*D), + δ*(S.card : ℝ)/2 ≤ δ*(∑B ∈ F.bags, (B.card : ℝ)) := by + have hD0 : 0 < D := hδ.trans_le hD + obtain ⟨w0,hw0⟩ := hW + have hex : ∀u : V, ∃v ∈ W, u ∈ S → l1dist (X u) (X v) ≤ 3*D := by + intro u + by_cases hu : u ∈ S + · obtain ⟨v,hv,hvu⟩ := hcover u hu + exact ⟨v,hv,fun _ => hvu⟩ + · exact ⟨w0,hw0,fun hh => (hu hh).elim⟩ + choose f hfW hfDist using hex + let fiber := fun i => S.filter (fun u => f u=i) + let c : ℝ := 216*D/δ + have hc : 0 < c := by dsimp [c]; positivity + obtain ⟨J,hJW,hJ,hgain⟩ := retain_fibers S W f (fun u _ => hfW u) + (fun _ => (1:ℝ)) (fun _ _ => zero_lt_one) hc + have hsumRet : (∑i ∈ J, ((fiber i).card : ℝ)) ≥ (S.card : ℝ)/2 := by + have hcost : c*(W.card : ℝ) ≤ (S.card : ℝ)/2 := by + dsimp [c] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ hδ).mpr + nlinarith + simp only [sum_const, nsmul_eq_mul,mul_one] at hgain + dsimp [fiber] + linarith + have hJne : J.Nonempty := by + by_contra hh + rw [not_nonempty_iff_eq_empty.mp hh,sum_empty] at hsumRet + have hs0 : (0:ℝ) < S.card := by exact_mod_cast card_pos.mpr hS + linarith + have hinj : Set.InjOn fiber J := by + intro i hi j hj hij + obtain ⟨u,hu⟩ := (hJ i hi).1 + have huj : u ∈ fiber j := hij ▸ hu + exact (mem_filter.mp hu).2.symm.trans (mem_filter.mp huj).2 + have hfiber : ∀i ∈ J, fiber i ⊆ S := fun i _ => filter_subset _ _ + let F : CompactFamily X δ (6*D) := { + bags := J.image fiber + nonempty := hJne.image fiber + radius_pos := hδ + bags_disjoint := by + intro A hA B hB hAB + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + obtain ⟨j,hj,rfl⟩ := mem_image.mp hB + apply Finset.disjoint_left.mpr + intro u hui huj + have hij := (mem_filter.mp hui).2.symm.trans (mem_filter.mp huj).2 + exact hAB (congrArg fiber hij) + balls_disjoint := by + intro u hu v hv huv + obtain ⟨A,hA,huA⟩ := mem_biUnion.mp hu + obtain ⟨B,hB,hvB⟩ := mem_biUnion.mp hv + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + obtain ⟨j,hj,rfl⟩ := mem_image.mp hB + exact hsep (hfiber i hi huA) (hfiber j hj hvB) huv + cardinal := by + intro A hA + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + have hh := (hJ i hi).2 + have h216 : (216:ℝ) ≤ c := (le_div_iff₀ hδ).mpr (by nlinarith) + have : (2:ℝ) ≤ (fiber i).card := by dsimp [fiber]; nlinarith + exact_mod_cast this + diameter := by + intro A hA u hu v hv + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + have hui := (mem_filter.mp hu).2 + have hvi := (mem_filter.mp hv).2 + have hu' := hfDist u (hfiber i hi hu) + have hv' := hfDist v (hfiber i hi hv) + rw [hui] at hu' + rw [hvi,l1dist_comm (X v) (X i)] at hv' + have htri := l1dist_triangle (X u) (X i) (X v) + linarith + compact := by + intro A hA + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + have hh := (hJ i hi).2 + rw [mul_one] at hh + have hm := (div_le_iff₀ hδ).mp hh + nlinarith } + refine ⟨F,?_⟩ + have he : (∑B ∈ F.bags, (B.card : ℝ)) = ∑i ∈ J, ((fiber i).card : ℝ) := + sum_image hinj + rw [he] + nlinarith [mul_le_mul_of_nonneg_left hsumRet hδ.le] + +end +end StrongThinTree.Geometry + +namespace StrongThinTree.Geometry +noncomputable section +open Finset RadialShell +open scoped Classical +variable {V : Type uV3} {I : Type uI2} {J : Type uJ} [DecidableEq V] [Fintype I] [Fintype J] + [DecidableEq I] [DecidableEq J] {h : ℕ} + +lemma normalized_small_balls (X : V → Fin h → ℝ) (Y : V → EuclideanSpace ℝ J) + (u v : I → V) (j : I → J) (hj : Function.Injective j) + (hN : 0 < Fintype.card I) {a ε c₁ : ℝ} + (ha : 0 < a) (hε : 0 < ε) (hε1 : ε < 1/3) (hc : 0 < c₁) + (hdiag : ∀i, 0 ≤ (Y (u i)-Y (v i)).ofLp (j i) ∧ + c₁ ≤ ((Y (u i)-Y (v i)).ofLp (j i))^2) + (hbound : a * Fintype.card I * (∑i, ‖Y (u i)-Y (v i)‖^2) ≤ + (∑i, (Y (u i)-Y (v i)).ofLp (j i))^2) + (hcontract : ∀x y, ‖Y x-Y y‖^2 ≤ l1dist (X x) (X y)) : + a ≤ 1 ∧ ∃S : Finset V, ∃δ : ℝ, 0 < δ ∧ + S ⊆ (univ.image u ∪ univ.image v) ∧ 2 ≤ S.card ∧ + ε^2*a*Fintype.card I ≤ 1024*S.card ∧ + (S.card : ℝ)*δ = a^ε*c₁*Fintype.card I/(1024/ε^2) ∧ + (S : Set V).Pairwise (fun x y => + Disjoint ((ball x δ).support X) ((ball y δ).support X)) := by + let N : ℝ := Fintype.card I + let A : ℝ := ∑i, (Y (u i)-Y (v i)).ofLp (j i) + have hN0 : 0 < N := by dsimp [N]; exact_mod_cast hN + have hsqrt : ∀i, Real.sqrt c₁ ≤ (Y (u i)-Y (v i)).ofLp (j i) := by + intro i + exact (Real.sqrt_le_iff).mpr ⟨(hdiag i).1,(hdiag i).2⟩ + have hsum : N*Real.sqrt c₁ ≤ A := by + simpa only [sum_const,nsmul_eq_mul,card_univ,N,A] using sum_le_sum (fun i (_ : i ∈ univ) => hsqrt i) + have hA0 : 0 < A := (mul_pos hN0 (Real.sqrt_pos.mpr hc)).trans_le hsum + have hA2 : c₁*N^2 ≤ A^2 := by + have hh := sq_le_sq₀ (by positivity : 0 ≤ N*Real.sqrt c₁) hA0.le |>.mpr hsum + rw [mul_pow,Real.sq_sqrt hc.le] at hh + nlinarith + obtain ⟨ha1,S,r,hr,hSF,hS2,hcard,hmass,hsep⟩ := + StrongThinTree.Spectral.spectral_packing_coordinates Y u v j hj ha hε hε1 + (by change 0 < A^2; positivity) hbound + have hS0 : (0:ℝ) < S.card := by exact_mod_cast (by omega : 0 < S.card) + have he2 : 0 < ε^2 := sq_pos_of_pos hε + have hpow : 0 < a^ε := Real.rpow_pos_of_pos ha _ + let C : ℝ := 1024/ε^2 + have hC : 0 < C := by dsimp [C]; positivity + let w := a^ε*c₁*N/C + let δ := w/S.card + have hw : 0 < w := by dsimp [w]; positivity + have hδ : 0 < δ := div_pos hw hS0 + have hwle : w ≤ (S.card : ℝ)*r := by + have hh := mul_le_mul_of_nonneg_left hA2 (show 0 ≤ ε^2*a^ε by positivity) + change ε^2*a^ε*A^2 ≤ 1024*N*(S.card*r) at hmass + have hh' : ε^2*a^ε*c₁*N ≤ 1024*(S.card*r) := by + apply (mul_le_mul_iff_right₀ hN0).mp + nlinarith + dsimp [w,C] + exact (div_le_iff₀ (div_pos (by norm_num) he2)).mpr (by + rw [←mul_div_assoc] + apply (le_div_iff₀ he2).mpr + nlinarith) + have hδr : δ ≤ r := (div_le_iff₀ hS0).mpr (by nlinarith) + refine ⟨ha1,S,δ,hδ,hSF,hS2,hcard,?_,?_⟩ + · dsimp [δ,w,C,N] + field_simp + · intro x hx y hy hxy + apply distance_balls_disjoint + have hh := hsep x hx y hy hxy + have hh' := hcontract x y + have hs : (Real.sqrt r)^2 = r := Real.sq_sqrt hr.le + have hnorm := norm_nonneg (Y x-Y y) + have hroot := Real.sqrt_nonneg r + nlinarith + +end +end StrongThinTree.Geometry + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Barrier.lean b/lean/OAI/Combinatorics/ThinTrees/Barrier.lean new file mode 100644 index 0000000000000000000000000000000000000000..7ff54066e7d8c5a0e2ef2e39039b029d8f7fb231 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Barrier.lean @@ -0,0 +1,382 @@ +import OAI.Combinatorics.ThinTrees.PartialFractions + +namespace OAI + +universe uI uR uR2 uR3 uR4 uS uR5 uS2 uR6 + +section + +noncomputable section +open Polynomial Finset Filter +open scoped Topology +namespace StrongThinTree.MSS + +variable {I : Type uI} [DecidableEq I] + +def ray {R : Type uR} [CommRing R] (p : MvPolynomial I R) (z : I → R) (i : I) : R[X] := + MvPolynomial.eval₂ Polynomial.C (fun j => Polynomial.C (z j)+if j=i then Polynomial.X else 0) p + +lemma ray_eval {R : Type uR2} [CommRing R] (p : MvPolynomial I R) (z : I → R) (i : I) (t : R) : + (ray p z i).eval t=MvPolynomial.eval (Function.update z i (z i+t)) p := by + induction p using MvPolynomial.induction_on with + | C a => simp [ray] + | add p q hp hq => simpa [ray,MvPolynomial.eval₂_add] using congrArg₂ (·+·) hp hq + | mul_X p j hp => + simp only [ray] at hp + by_cases hji : j=i + · subst j + simp [ray,MvPolynomial.eval₂_mul,hp] + · simp [ray,MvPolynomial.eval₂_mul,hji,hp] + +lemma ray_derivative {R : Type uR3} [CommRing R] (p : MvPolynomial I R) (z : I → R) (i : I) : + (ray p z i).derivative=ray (MvPolynomial.pderiv i p) z i := by + induction p using MvPolynomial.induction_on with + | C a => simp [ray] + | add p q hp hq => + simp only [ray] at hp hq + simp [ray,MvPolynomial.eval₂_add,hp,hq] + | mul_X p j hp => + simp only [ray] at hp + rw [MvPolynomial.pderiv_mul] + by_cases hji : j=i + · subst j + simp [ray,MvPolynomial.eval₂_mul,MvPolynomial.eval₂_add,Polynomial.derivative_mul,hp] + · simp [ray,MvPolynomial.eval₂_mul,Polynomial.derivative_mul,MvPolynomial.pderiv_X,hji,hp] + +lemma ray_map {R : Type uR4} {S : Type uS} [CommRing R] [CommRing S] (f : R →+* S) + (p : MvPolynomial I R) (z : I → R) (i : I) : + (ray p z i).map f=ray (p.map f) (fun j => f (z j)) i := by + induction p using MvPolynomial.induction_on with + | C a => simp [ray] + | add p q hp hq => simpa [ray,MvPolynomial.eval₂_add] using congrArg₂ (·+·) hp hq + | mul_X p j hp => + simp only [ray] at hp + by_cases hji : j=i + · subst j + simp [ray,MvPolynomial.eval₂_mul,hp] + · simp [ray,MvPolynomial.eval₂_mul,hp,hji] + +omit [DecidableEq I] in +lemma eval_map_between {R : Type uR5} {S : Type uS2} [CommRing R] [CommRing S] (f : R →+* S) + (p : MvPolynomial I R) (z : I → R) : + MvPolynomial.eval (fun j => f (z j)) (p.map f)=f (MvPolynomial.eval z p) := by + induction p using MvPolynomial.induction_on with + | C a => simp + | add p q hp hq => simp [hp,hq] + | mul_X p j hp => simp [hp] + +def RealStable (p : MvPolynomial I ℝ) : Prop := Stable (p.map (algebraMap ℝ ℂ)) +def Above (p : MvPolynomial I ℝ) (z : I → ℝ) : Prop := + ∀s : I → ℝ, (∀i, 0 ≤ s i) → 0 < MvPolynomial.eval (z+s) p + +def barrier (p : MvPolynomial I ℝ) (z : I → ℝ) (i : I) : ℝ := + MvPolynomial.eval z (MvPolynomial.pderiv i p)/MvPolynomial.eval z p + +omit [DecidableEq I] in +lemma Above.pos {p : MvPolynomial I ℝ} {z : I → ℝ} (hz : Above p z) : + 0 < MvPolynomial.eval z p := by + simpa using hz 0 (fun _ => le_rfl) + +omit [DecidableEq I] in +lemma Above.add {p : MvPolynomial I ℝ} {z s : I → ℝ} (hz : Above p z) (hs : ∀i, 0 ≤ s i) : + Above p (z+s) := by + intro t ht + simpa [add_assoc] using hz (s+t) (fun i => add_nonneg (hs i) (ht i)) + +lemma Above.update {p : MvPolynomial I ℝ} {z : I → ℝ} (hz : Above p z) (i : I) {t : ℝ} (ht : 0 ≤ t) : + Above p (Function.update z i (z i+t)) := by + have he : Function.update z i (z i+t)=z+Pi.single i t := by + ext j + by_cases hj : j=i + · subst j; simp + · simp [Function.update_of_ne hj,Pi.single_eq_of_ne hj] + rw [he] + exact hz.add (fun j => by by_cases hj : j=i; subst j; simp [ht]; simp [Pi.single_eq_of_ne hj]) + +lemma ray_zero (p : MvPolynomial I ℝ) (z : I → ℝ) (i : I) : + (ray p z i).eval 0=MvPolynomial.eval z p := by simp [ray_eval] + +lemma real_ray_upper {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) (i : I) : + ∀w : ℂ, 0 < w.im → Rational.cval (ray p z i) w ≠ 0 := by + have hs0 : slice (p.map (algebraMap ℝ ℂ)) (fun j => (z j:ℂ)) i ≠ 0 := by + intro he + have hh := slice_eval_self (p.map (algebraMap ℝ ℂ)) (fun j => (z j:ℂ)) i + rw [he] at hh + have hm := eval_map_between (algebraMap ℝ ℂ) p z + change MvPolynomial.eval (fun j => (z j:ℂ)) (p.map (algebraMap ℝ ℂ))=(MvPolynomial.eval z p:ℂ) at hm + rw [hm] at hh + simp only [Polynomial.eval_zero] at hh + exact hz.pos.ne' (by exact_mod_cast hh.symm) + intro w hw + have hh := hp.slice_boundary (fun j => (z j:ℂ)) (fun _ => by simp) i hs0 ((z i:ℂ)+w) + (by simpa using hw) + rw [slice_eval] at hh + unfold Rational.cval + rw [ray_map,ray_eval] + exact hh + +lemma real_ray_splits {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) (i : I) : (ray p z i).Splits := + splits_of_upper_half_plane _ (real_ray_upper hp hz i) + +lemma barrier_nonneg {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) (i : I) : 0 ≤ barrier p z i := by + let g := ray p z i + have hg0 : g.eval 0 ≠ 0 := by simpa [g,ray_zero] using hz.pos.ne' + have hg : g.Splits := real_ray_splits hp hz i + have hgroot : ∀x ∈ g.roots, x < 0 := by + intro x hx + by_contra hx0 + have he : g.eval x=0 := (mem_roots (by intro h0; simp [h0] at hg0)).mp hx + have hp0 := (hz.update i (le_of_not_gt hx0)).pos + rw [←ray_eval] at hp0 + exact hp0.ne' he + have he : barrier p z i=g.derivative.eval 0/g.eval 0 := by + simp [g,ray_derivative,ray_zero,barrier] + rw [he,hg.eval_derivative_div_eval_of_ne_zero hg0] + apply Multiset.sum_nonneg + intro r hr + obtain ⟨x,hx,rfl⟩ := Multiset.mem_map.mp hr + exact div_nonneg zero_le_one (by linarith [hgroot x hx]) + +lemma Stable.log_derivative_im {p : MvPolynomial I ℂ} (hp : Stable p) + (z : I → ℂ) (hz : ∀j, 0 < (z j).im) (i : I) : + (MvPolynomial.eval z (MvPolynomial.pderiv i p)/MvPolynomial.eval z p).im ≤ 0 := by + have hs : ∀w : ℂ, 0 < w.im → (slice p z i).eval w ≠ 0 := by + intro w hw + rw [slice_eval] + apply hp + intro j + by_cases hji : j=i + · subst j; simpa using hw + · simpa [Function.update_of_ne hji] using hz j + have hh := polynomial_log_derivative (hz i) hs + rw [slice_derivative_eval_self,slice_eval_self] at hh + rcases hh with hh | hh + · simp [hh] + · exact hh.le + +lemma ray_log_derivative_im {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) (i j : I) (w : ℂ) (hw : 0 < w.im) : + (Rational.cval (ray (MvPolynomial.pderiv i p) z j) w/Rational.cval (ray p z j) w).im ≤ 0 := by + let P := p.map (algebraMap ℝ ℂ) + let Z : ℝ → I → ℂ := fun t => Function.update (fun k => (z k:ℂ)+(t:ℂ)*Complex.I) j ((z j:ℂ)+w) + have hZ : Continuous Z := by + apply continuous_pi + intro k + by_cases hkj : k=j + · subst k; simp only [Z,Function.update_self]; fun_prop + · simp only [Z,Function.update_of_ne hkj]; fun_prop + have he (q : MvPolynomial I ℝ) : + Rational.cval (ray q z j) w=MvPolynomial.eval (Z 0) (q.map (algebraMap ℝ ℂ)) := by + unfold Rational.cval + rw [ray_map,ray_eval] + simp only [Z,Complex.ofReal_zero,zero_mul,add_zero] + rfl + have hD : MvPolynomial.eval (Z 0) P ≠ 0 := by + exact (he p).symm ▸ real_ray_upper hp hz j w hw + have hA := ((MvPolynomial.continuous_eval (MvPolynomial.pderiv i P)).comp hZ).continuousAt (x:=0) + have hB := ((MvPolynomial.continuous_eval P).comp hZ).continuousAt (x:=0) + have hlim := Complex.continuous_im.continuousAt.tendsto.comp (hA.tendsto.div hB.tendsto hD) + have heq : (MvPolynomial.eval (Z 0) (MvPolynomial.pderiv i P)/MvPolynomial.eval (Z 0) P).im= + (Rational.cval (ray (MvPolynomial.pderiv i p) z j) w/Rational.cval (ray p z j) w).im := by + dsimp [P] + rw [MvPolynomial.pderiv_map,←he,←he] + dsimp only [Function.comp_apply] at hlim + rw [heq] at hlim + apply le_of_tendsto (hlim.mono_left (nhdsWithin_le_nhds (s:=Set.Ioi 0))) + filter_upwards [self_mem_nhdsWithin] with t ht + apply hp.log_derivative_im + intro k + by_cases hkj : k=j + · subst k; simpa only [Z,Function.update_self,Complex.add_im,Complex.ofReal_im,zero_add] using hw + · simpa only [Z,Function.update_of_ne hkj,Complex.add_im,Complex.ofReal_im,Complex.mul_im, + Complex.ofReal_re,Complex.I_im,mul_one,Complex.I_re,mul_zero,zero_add,add_zero,Set.mem_Ioi] using ht + +lemma barrier_ray_representation {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) (i j : I) : + ∃s : Finset ℝ, ∃c : ℝ, ∃d : ℝ → ℝ, 0 ≤ c ∧ + (∀x ∈ s, x < 0 ∧ 0 < d x) ∧ + ∀t : ℝ, 0 ≤ t → barrier p (Function.update z j (z j+t)) i=c+∑x ∈ s, d x/(t-x) := by + have hb : ray p z j ≠ 0 := by + intro h0 + have hh := hz.pos + rw [←ray_zero p z j,h0,Polynomial.eval_zero] at hh + exact lt_irrefl _ hh + have hr : ∀t : ℝ, 0 ≤ t → (ray p z j).eval t ≠ 0 := by + intro t ht + rw [ray_eval] + exact (hz.update j ht).pos.ne' + obtain ⟨s,c,d,hc,hd,he⟩ := Rational.positive_decomposition (ray (MvPolynomial.pderiv i p) z j) + (ray p z j) hb (real_ray_splits hp hz j) hr (real_ray_upper hp hz j) + (ray_log_derivative_im hp hz i j) (fun t ht => by + simpa only [ray_eval,barrier] using barrier_nonneg hp (hz.update j ht) i) + refine ⟨s,c,d,hc,hd,?_⟩ + intro t ht + simpa only [barrier,ray_eval] using he t ht + +lemma barrier_update_le {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) (i j : I) {t : ℝ} (ht : 0 ≤ t) : + barrier p (Function.update z j (z j+t)) i ≤ barrier p z i := by + obtain ⟨s,c,d,_,hd,he⟩ := barrier_ray_representation hp hz i j + have he0 := he 0 le_rfl + simp only [add_zero,Function.update_eq_self] at he0 + rw [he t ht,he0] + apply add_le_add le_rfl + apply Finset.sum_le_sum + intro x hx + exact div_le_div_of_nonneg_left (hd x hx).2.le (by linarith [(hd x hx).1]) (by linarith) + +lemma update_add_single (z : I → ℝ) (i : I) (t : ℝ) : + Function.update z i (z i+t)=z+Pi.single i t := by + ext j + by_cases hj : j=i + · subst j; simp + · simp [Function.update_of_ne hj,Pi.single_eq_of_ne hj] + +lemma barrier_add_le [Fintype I] {p : MvPolynomial I ℝ} (hp : RealStable p) {z s : I → ℝ} + (hz : Above p z) (hs : ∀i, 0 ≤ s i) (i : I) : barrier p (z+s) i ≤ barrier p z i := by + have hh : ∀T : Finset I, barrier p (z+∑j ∈ T, Pi.single j (s j)) i ≤ barrier p z i := by + intro T + induction T using Finset.induction_on with + | empty => simp + | @insert j T hj ih => + have hn : ∀k, 0 ≤ (∑j ∈ T, Pi.single j (s j)) k := by + intro k + rw [Finset.sum_apply] + exact Finset.sum_nonneg (fun l _ => by by_cases hl : k=l; subst l; simp [hs]; simp [Pi.single_eq_of_ne hl]) + have hu := barrier_update_le hp (hz.add hn) i j (hs j) + rw [update_add_single] at hu + rw [Finset.sum_insert hj] + simpa only [add_left_comm,add_assoc,add_comm] using hu.trans ih + simpa only [Finset.univ_sum_single] using hh Finset.univ + +def crossBarrier (p : MvPolynomial I ℝ) (z : I → ℝ) (i j : I) : ℝ := + (MvPolynomial.eval z (MvPolynomial.pderiv j (MvPolynomial.pderiv i p))*MvPolynomial.eval z p- + MvPolynomial.eval z (MvPolynomial.pderiv i p)*MvPolynomial.eval z (MvPolynomial.pderiv j p))/(MvPolynomial.eval z p)^2 + +lemma hasDerivAt_barrier_ray (p : MvPolynomial I ℝ) (z : I → ℝ) (i j : I) {t : ℝ} + (ht : MvPolynomial.eval (Function.update z j (z j+t)) p ≠ 0) : + HasDerivAt (fun u => barrier p (Function.update z j (z j+u)) i) + (crossBarrier p (Function.update z j (z j+t)) i j) t := by + have hh := ((ray (MvPolynomial.pderiv i p) z j).hasDerivAt t).div ((ray p z j).hasDerivAt t) + (by simpa only [ray_eval] using ht) + convert hh using 1 <;> first | rfl | (simp [ray_eval,ray_derivative,barrier,crossBarrier] <;> rfl) + +lemma fractions_tangent {x d t : ℝ} (hx : x < 0) (hd : 0 ≤ d) (ht : 0 ≤ t) : + d/(t-x)+t*(d/(t-x)^2) ≤ d/(0-x) := by + have hb : 0 < t-x := by linarith + calc + d/(t-x)+t*(d/(t-x)^2) = d*(t-x+t)/(t-x)^2 := by field_simp + _ ≤ d/(0-x) := by + rw [div_le_div_iff₀ (sq_pos_of_pos hb) (by linarith)] + nlinarith [mul_nonneg hd (sq_nonneg t)] + +lemma barrier_ray_tangent {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) (i j : I) {t : ℝ} (ht : 0 < t) : + crossBarrier p (Function.update z j (z j+t)) i j ≤ 0 ∧ + barrier p (Function.update z j (z j+t)) i-t*crossBarrier p (Function.update z j (z j+t)) i j ≤ barrier p z i := by + obtain ⟨s,c,d,_,hd,he⟩ := barrier_ray_representation hp hz i j + have hder : HasDerivAt (fun u : ℝ => c+∑x ∈ s, d x/(u-x)) + (-(∑x ∈ s, d x/(t-x)^2)) t := by + have hh : ∀x ∈ s, HasDerivAt (fun u : ℝ => d x/(u-x)) (-(d x/(t-x)^2)) t := by + intro x hx + have hu := (hasDerivAt_const t (d x)).div ((hasDerivAt_id t).sub_const x) (by linarith [(hd x hx).1] : t-x ≠ 0) + convert hu using 1 <;> first | rfl | simp [neg_div] + convert (hasDerivAt_const t c).add (HasDerivAt.fun_sum hh) using 1 + first | rfl | simp [Finset.sum_neg_distrib] + have hder' : HasDerivAt (fun u => barrier p (Function.update z j (z j+u)) i) + (-(∑x ∈ s, d x/(t-x)^2)) t := by + apply hder.congr_of_eventuallyEq + filter_upwards [eventually_gt_nhds ht] with u hu + exact he u hu.le + have hdval := (hasDerivAt_barrier_ray p z i j (hz.update j ht.le).pos.ne').unique hder' + rw [hdval] + constructor + · exact neg_nonpos.mpr (Finset.sum_nonneg (fun x hx => div_nonneg (hd x hx).2.le (sq_nonneg _))) + · have he0 := he 0 le_rfl + simp only [add_zero,Function.update_eq_self] at he0 + rw [he t ht.le,he0,mul_neg,sub_neg_eq_add,add_assoc,Finset.mul_sum,←Finset.sum_add_distrib] + exact add_le_add le_rfl (Finset.sum_le_sum (fun x hx => fractions_tangent (hd x hx).1 (hd x hx).2.le ht.le)) + +lemma pderiv_commute {R : Type uR6} [CommRing R] (p : MvPolynomial I R) (i j : I) : + MvPolynomial.pderiv i (MvPolynomial.pderiv j p)=MvPolynomial.pderiv j (MvPolynomial.pderiv i p) := by + by_cases hij : i=j + · subst j; rfl + induction p using MvPolynomial.induction_on with + | C a => simp + | add p q hp hq => simp [hp,hq] + | mul_X p k hp => + by_cases hki : k=i + · subst k + simp [MvPolynomial.pderiv_X,hij,hp,add_comm] + · by_cases hkj : k=j + · subst k + simp [MvPolynomial.pderiv_X,Ne.symm hij,hp,add_comm] + · simp [MvPolynomial.pderiv_X,hki,hkj,hp] + +omit [DecidableEq I] in +lemma RealStable.sub_pderiv {p : MvPolynomial I ℝ} (hp : RealStable p) (j : I) : + RealStable (p-MvPolynomial.pderiv j p) := by + classical + simpa only [RealStable,map_sub,MvPolynomial.pderiv_map] using Stable.sub_pderiv hp j + +omit [DecidableEq I] in +lemma eval_sub_pderiv {p : MvPolynomial I ℝ} {w : I → ℝ} + (hw : MvPolynomial.eval w p ≠ 0) (j : I) : + MvPolynomial.eval w (p-MvPolynomial.pderiv j p)=MvPolynomial.eval w p*(1-barrier p w j) := by + simp only [map_sub,barrier] + field_simp + +lemma barrier_sub_pderiv {p : MvPolynomial I ℝ} {w : I → ℝ} + (hw : MvPolynomial.eval w p ≠ 0) (i j : I) (hj : 1-barrier p w j ≠ 0) : + barrier (p-MvPolynomial.pderiv j p) w i = + barrier p w i-crossBarrier p w i j/(1-barrier p w j) := by + have hne : MvPolynomial.eval w p-MvPolynomial.eval w (MvPolynomial.pderiv j p) ≠ 0 := by + intro he + have he' := sub_eq_zero.mp he + apply hj + simp [barrier,←he',hw] + simp only [barrier,crossBarrier,map_sub,pderiv_commute p i j] + field_simp + ring + +lemma barrier_shift [Fintype I] {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) (j : I) {δ : ℝ} (hδ : 0 < δ) (hh : barrier p z j+1/δ ≤ 1) : + Above (p-MvPolynomial.pderiv j p) (Function.update z j (z j+δ)) ∧ + ∀i, barrier (p-MvPolynomial.pderiv j p) (Function.update z j (z j+δ)) i ≤ barrier p z i := by + have hzq : Above (p-MvPolynomial.pderiv j p) z := by + intro s hs + rw [eval_sub_pderiv (hz.add hs).pos.ne'] + apply mul_pos (hz.add hs).pos + have hm := barrier_add_le hp hz hs j + have hpos := one_div_pos.mpr hδ + linarith + refine ⟨hzq.update j hδ.le,fun i => ?_⟩ + let w := Function.update z j (z j+δ) + have hw := (hz.update j hδ.le).pos + have hm : 1/δ ≤ 1-barrier p w j := by + have hu := barrier_update_le hp hz j j hδ.le + change barrier p w j ≤ _ at hu + linarith + have hpos : 0 < 1-barrier p w j := lt_of_lt_of_le (one_div_pos.mpr hδ) hm + obtain ⟨hf,ht⟩ := barrier_ray_tangent hp hz i j hδ + change crossBarrier p w i j ≤ 0 at hf + change barrier p w i-δ*crossBarrier p w i j ≤ barrier p z i at ht + rw [barrier_sub_pderiv hw.ne' i j hpos.ne'] + apply le_trans _ ht + change barrier p w i-crossBarrier p w i j/(1-barrier p w j) ≤ barrier p w i-δ*crossBarrier p w i j + apply sub_le_sub_left + rw [le_div_iff₀ hpos] + have he : 1 ≤ δ*(1-barrier p w j) := by + simpa only [mul_comm] using (div_le_iff₀ hδ).mp hm + have hm' := mul_le_mul_of_nonpos_left he hf + nlinarith + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/BasePacking.lean b/lean/OAI/Combinatorics/ThinTrees/BasePacking.lean new file mode 100644 index 0000000000000000000000000000000000000000..e10eba885362d355682fdef308a12adf7a3f9852 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/BasePacking.lean @@ -0,0 +1,820 @@ +import OAI.Combinatorics.ThinTrees.HierarchyBounds + +namespace OAI + +universe uE uI uV uI2 + +section + +noncomputable section +open Finset Submodule +namespace StrongThinTree.Packing + +variable {E : Type uE} {I : Type uI} {V : Type uV} [Fintype E] [DecidableEq E] [Fintype I] [DecidableEq I] + [AddCommGroup V] [Module ℝ V] [FiniteDimensional ℝ V] + +abbrev span (v : E → V) (s : Finset E) : Submodule ℝ V := + Submodule.span ℝ (v '' (s : Set E)) + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] in +lemma span_mono (v : E → V) {s t : Finset E} (h : s ⊆ t) : span v s ≤ span v t := + Submodule.span_mono (Set.image_mono h) + +omit [Fintype E] [FiniteDimensional ℝ V] in +lemma span_insert (v : E → V) (s : Finset E) (e : E) : + span v (insert e s) = Submodule.span ℝ (insert (v e) (v '' (s : Set E))) := by + simp only [span, coe_insert, Set.image_insert_eq] + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] in +lemma mem_span_self (v : E → V) {s : Finset E} {e : E} (he : e ∈ s) : + v e ∈ span v s := Submodule.subset_span ⟨e, he, rfl⟩ + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] in +lemma span_le_iff (v : E → V) {s : Finset E} {W : Submodule ℝ V} : + span v s ≤ W ↔ ∀ e ∈ s, v e ∈ W := by + rw [Submodule.span_le] + constructor + · intro h e he; exact h ⟨e, he, rfl⟩ + · rintro h x ⟨e, he, rfl⟩; exact h e he + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] in +lemma indep_rank (v : E → V) {s : Finset E} (hs : LinearIndepOn ℝ v s) : + Module.finrank ℝ (span v s) = s.card := by + have heq : Set.range (fun e : (s : Set E) => v e) = v '' (s : Set E) := by + ext x; simp + have h := finrank_span_eq_card hs.linearIndependent + change Module.finrank ℝ (Submodule.span ℝ (Set.range (fun e : (s : Set E) => v e))) = _ at h + rw [heq] at h + simpa using h + +omit [Fintype E] [FiniteDimensional ℝ V] in + +lemma support_exchange (v : E → V) {s : Finset E} + (hs : LinearIndepOn ℝ v s) {x : V} {l : E →₀ ℝ} + (hl : l ∈ Finsupp.supported ℝ ℝ (s : Set E)) + (hx : Finsupp.linearCombination ℝ v l = x) {f : E} (hf : f ∈ l.support) : + x ∉ span v (s.erase f) := by + intro h + obtain ⟨l', hl', hx'⟩ := (Finsupp.mem_span_image_iff_linearCombination ℝ).mp h + have hl's : l' ∈ Finsupp.supported ℝ ℝ (s : Set E) := by + rw [Finsupp.mem_supported] at hl' ⊢ + exact hl'.trans (Finset.erase_subset _ _) + have heq : l = l' := (linearIndepOn_iffₛ.mp hs) l hl l' hl's (hx.trans hx'.symm) + have hz : l' f = 0 := by + apply Finsupp.notMem_support_iff.mp + intro hmem + have := ((Finsupp.mem_supported ℝ l').mp hl') hmem + simp at this + exact (Finsupp.mem_support_iff.mp hf) (heq ▸ hz) + +def Valid (v : E → V) (F : I → Finset E) : Prop := + (∀ i, LinearIndepOn ℝ v (F i : Set E)) ∧ Pairwise (fun i j => Disjoint (F i) (F j)) + +abbrev State (v : E → V) (I : Type uI2) [Fintype I] := {F : I → Finset E // Valid v F} + +def cost {v : E → V} (F : State v I) : ℕ := ∑ i, (F.1 i).card + +def unused {v : E → V} (F : State v I) (e : E) : Prop := ∀ i, e ∉ F.1 i + +omit [Fintype E] [DecidableEq E] [Fintype I] [DecidableEq I] [FiniteDimensional ℝ V] in +lemma valid_empty (v : E → V) : Valid v (fun _ : I => ∅) := by + constructor + · intro i; simp + · intro i j h; simp + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] in +lemma valid_update {v : E → V} (F : State v I) (i : I) (s : Finset E) + (hs : LinearIndepOn ℝ v (s : Set E)) + (hd : ∀ j, j ≠ i → Disjoint s (F.1 j)) : Valid v (Function.update F.1 i s) := by + constructor + · intro j + by_cases h : j = i + · subst j; simpa using hs + · simpa [Function.update_of_ne h] using F.2.1 j + · intro j k hjk + by_cases hj : j = i + · subst j + simpa [Function.update_of_ne (Ne.symm hjk)] using hd k (Ne.symm hjk) + · by_cases hk : k = i + · subst k + simpa [Function.update_of_ne hj] using (hd j hj).symm + · simpa [Function.update_of_ne hj, Function.update_of_ne hk] using F.2.2 hjk + +omit [Fintype E] [DecidableEq I] [FiniteDimensional ℝ V] in +lemma disjoint_insert_unused {v : E → V} (F : State v I) {i : I} {s : Finset E} + (hs : s ⊆ F.1 i) {e : E} (he : unused F e) : + ∀ j, j ≠ i → Disjoint (insert e s) (F.1 j) := by + intro j hj + rw [Finset.disjoint_insert_left] + exact ⟨he j, (F.2.2 (Ne.symm hj)).mono_left hs⟩ + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] in +lemma cost_update {v : E → V} (F : State v I) {i : I} {s : Finset E} + (h : Valid v (Function.update F.1 i s)) : + cost (⟨Function.update F.1 i s, h⟩ : State v I) + (F.1 i).card = cost F + s.card := by + unfold cost + have hsum := Finset.sum_update_of_mem (Finset.mem_univ i) (fun j => (F.1 j).card) s.card + have heq : (fun j => ((Function.update F.1 i s) j).card) = + Function.update (fun j => (F.1 j).card) i s.card := by + ext j; by_cases hj : j = i <;> simp [hj, Function.update_of_ne] + rw [heq] + rw [← Finset.sum_erase_add _ _ (Finset.mem_univ i)] + rw [← Finset.sum_erase_add (Finset.univ : Finset I) _ (Finset.mem_univ i)] + simp only [Function.update_self] + have he : ∑ j ∈ Finset.univ.erase i, + Function.update (fun j => (F.1 j).card) i s.card j = + ∑ j ∈ Finset.univ.erase i, (F.1 j).card := by + apply Finset.sum_congr rfl + intro j hj + exact Function.update_of_ne (Finset.mem_erase.mp hj).1 _ _ + rw [he] + omega + +omit [DecidableEq E] [DecidableEq I] [FiniteDimensional ℝ V] in +lemma exists_maximal_state (v : E → V) : + ∃ F : State v I, ∀ F' : State v I, cost F' ≤ cost F := by + classical + let : Fintype (State v I) := Fintype.ofFinite _ + have hne : (Finset.univ : Finset (State v I)).Nonempty := + ⟨⟨fun _ => ∅, valid_empty v⟩, Finset.mem_univ _⟩ + obtain ⟨F, _, hF⟩ := Finset.exists_max_image (Finset.univ : Finset (State v I)) cost hne + exact ⟨F, fun F' => hF F' (Finset.mem_univ _)⟩ + +omit [Fintype E] [FiniteDimensional ℝ V] in +lemma maximal_unused_mem_span {v : E → V} {F : State v I} + (hF : ∀ F' : State v I, cost F' ≤ cost F) {e : E} (he : unused F e) (i : I) : + v e ∈ span v (F.1 i) := by + by_contra h + have hs : LinearIndepOn ℝ v (insert e (F.1 i) : Finset E) := by + simpa only [Finset.coe_insert] using (F.2.1 i).insert h + have hv := valid_update F i _ hs (disjoint_insert_unused F (Subset.refl _) he) + have hc := cost_update F hv + have hu := hF ⟨_, hv⟩ + rw [Finset.card_insert_of_notMem (he i)] at hc + omega + +def Move {v : E → V} (F F' : State v I) : Prop := + ∃ i e f, unused F e ∧ f ∈ F.1 i ∧ + F'.1 = Function.update F.1 i (insert e ((F.1 i).erase f)) + +omit [Fintype E] [FiniteDimensional ℝ V] in +lemma unused_after_exchange {v : E → V} {F F' : State v I} {i : I} {e f : E} + (he : unused F e) (hf : f ∈ F.1 i) + (h : F'.1 = Function.update F.1 i (insert e ((F.1 i).erase f))) : unused F' f := by + intro j + rw [h] + by_cases hj : j = i + · subst j + have hfe : f ≠ e := by rintro rfl; exact he i hf + simp [hfe] + · rw [Function.update_of_ne hj] + exact fun hfj => Finset.disjoint_left.mp (F.2.2 (Ne.symm hj)) hf hfj + +omit [Fintype E] [FiniteDimensional ℝ V] in +lemma Move.cost_eq {v : E → V} {F F' : State v I} (h : Move F F') : cost F' = cost F := by + obtain ⟨i, e, f, he, hf, heq⟩ := h + have hv : Valid v (Function.update F.1 i (insert e ((F.1 i).erase f))) := heq ▸ F'.2 + have hc := cost_update F hv + have hsame : (⟨_, hv⟩ : State v I) = F' := Subtype.ext heq.symm + rw [hsame, Finset.card_insert_of_notMem (fun hh => he i (Finset.mem_erase.mp hh).2), + Finset.card_erase_of_mem hf] at hc + have hfpos := Finset.card_pos.mpr ⟨f, hf⟩ + omega + +omit [Fintype E] [FiniteDimensional ℝ V] in +lemma reachable_cost_eq {v : E → V} {F F' : State v I} + (h : Relation.ReflTransGen Move F F') : cost F' = cost F := by + induction h with + | refl => rfl + | @tail F' F'' hr hm ih => exact hm.cost_eq.trans ih + +omit [Fintype E] [FiniteDimensional ℝ V] in +lemma reachable_maximal {v : E → V} {F F' : State v I} + (hF : ∀ G : State v I, cost G ≤ cost F) + (h : Relation.ReflTransGen Move F F') : ∀ G : State v I, cost G ≤ cost F' := by + intro G + rw [reachable_cost_eq h] + exact hF G + +def recycled {v : E → V} (F : State v I) : Finset E := by + classical + exact Finset.univ.filter fun e => ∃ F', Relation.ReflTransGen Move F F' ∧ unused F' e + +omit [FiniteDimensional ℝ V] in +lemma mem_recycled {v : E → V} {F : State v I} {e : E} : + e ∈ recycled F ↔ ∃ F', Relation.ReflTransGen Move F F' ∧ unused F' e := by + classical + simp [recycled] + +omit [FiniteDimensional ℝ V] in +lemma unused_span_recycled {v : E → V} {F F' : State v I} + (hF : ∀ G : State v I, cost G ≤ cost F) + (hr : Relation.ReflTransGen Move F F') {e : E} (he : unused F' e) (i : I) : + v e ∈ span v (F'.1 i ∩ recycled F) := by + have hsp := maximal_unused_mem_span (reachable_maximal hF hr) he i + obtain ⟨l, hl, hle⟩ := (Finsupp.mem_span_image_iff_linearCombination ℝ).mp hsp + apply (Finsupp.mem_span_image_iff_linearCombination ℝ).mpr + refine ⟨l, ?_, hle⟩ + rw [Finsupp.mem_supported] + intro f hf + have hfi : f ∈ F'.1 i := (Finsupp.mem_supported ℝ l).mp hl hf + refine Finset.mem_inter.mpr ⟨hfi, mem_recycled.mpr ?_⟩ + have hex := support_exchange v (F'.2.1 i) hl hle hf + have hs : LinearIndepOn ℝ v (insert e ((F'.1 i).erase f) : Finset E) := by + simpa only [Finset.coe_insert] using + ((F'.2.1 i).mono (Finset.erase_subset _ _)).insert hex + have hv := valid_update F' i _ hs + (disjoint_insert_unused F' (Finset.erase_subset _ _) he) + let F'' : State v I := ⟨_, hv⟩ + have hm : Move F' F'' := ⟨i, e, f, he, hfi, rfl⟩ + exact ⟨F'', hr.tail hm, unused_after_exchange he hfi rfl⟩ + +omit [FiniteDimensional ℝ V] in +lemma move_span_recycled_eq {v : E → V} {F F' F'' : State v I} + (hF : ∀ G : State v I, cost G ≤ cost F) + (hr : Relation.ReflTransGen Move F F') (hm : Move F' F'') (j : I) : + span v (F''.1 j ∩ recycled F) = span v (F'.1 j ∩ recycled F) := by + obtain ⟨i, e, f, he, hf, hup⟩ := hm + by_cases hji : j = i + · subst j + have heU : v e ∈ span v (F'.1 i ∩ recycled F) := unused_span_recycled hF hr he i + have hfU : v f ∈ span v (F''.1 i ∩ recycled F) := + unused_span_recycled hF (hr.tail ⟨i, e, f, he, hf, hup⟩) + (unused_after_exchange he hf hup) i + apply le_antisymm + · apply (span_le_iff v).mpr + intro g hg + have hgU := (Finset.mem_inter.mp hg).2 + have hg' := (Finset.mem_inter.mp hg).1 + rw [hup, Function.update_self] at hg' + rcases Finset.mem_insert.mp hg' with rfl | hg' + · exact heU + · exact mem_span_self v (Finset.mem_inter.mpr ⟨(Finset.mem_erase.mp hg').2, hgU⟩) + · apply (span_le_iff v).mpr + intro g hg + by_cases hgf : g = f + · subst g; exact hfU + · apply mem_span_self v + apply Finset.mem_inter.mpr + refine ⟨?_, (Finset.mem_inter.mp hg).2⟩ + rw [hup, Function.update_self] + exact Finset.mem_insert_of_mem (Finset.mem_erase.mpr ⟨hgf, (Finset.mem_inter.mp hg).1⟩) + · rw [hup, Function.update_of_ne hji] + +omit [FiniteDimensional ℝ V] in +lemma reachable_span_recycled_eq {v : E → V} {F F' : State v I} + (hF : ∀ G : State v I, cost G ≤ cost F) + (hr : Relation.ReflTransGen Move F F') (i : I) : + span v (F'.1 i ∩ recycled F) = span v (F.1 i ∩ recycled F) := by + induction hr with + | refl => rfl + | @tail F' F'' hr hm ih => exact (move_span_recycled_eq hF hr hm i).trans ih + +omit [FiniteDimensional ℝ V] in + +lemma span_recycled_eq {v : E → V} {F : State v I} + (hF : ∀ G : State v I, cost G ≤ cost F) (i : I) : + span v (recycled F) = span v (F.1 i ∩ recycled F) := by + apply le_antisymm + · apply (span_le_iff v).mpr + intro e he + obtain ⟨F', hr, he'⟩ := mem_recycled.mp he + rw [← reachable_span_recycled_eq hF hr i] + exact unused_span_recycled hF hr he' i + · exact span_mono v Finset.inter_subset_right + +omit [FiniteDimensional ℝ V] in +lemma cost_decomposition {v : E → V} {F : State v I} + (hF : ∀ G : State v I, cost G ≤ cost F) : + cost F = (Finset.univ \ recycled F).card + + Fintype.card I * Module.finrank ℝ (span v (recycled F)) := by + classical + have hcover : Finset.univ \ recycled F = + Finset.univ.biUnion (fun i => F.1 i \ recycled F) := by + ext e + simp only [Finset.mem_sdiff, Finset.mem_univ, true_and, Finset.mem_biUnion] + constructor + · intro he + have hused : ∃ i, e ∈ F.1 i := by + by_contra h + have hu : unused F e := by simpa only [unused, not_exists] using h + exact he (mem_recycled.mpr ⟨F, Relation.ReflTransGen.refl, hu⟩) + obtain ⟨i, hi⟩ := hused + exact ⟨i, hi, he⟩ + · rintro ⟨i, hi, he⟩; exact he + have hdisj : (↑(Finset.univ : Finset I) : Set I).PairwiseDisjoint + (fun i => F.1 i \ recycled F) := by + intro i _ j _ hij + exact (F.2.2 hij).mono Finset.sdiff_subset Finset.sdiff_subset + have hrank (i : I) : (F.1 i ∩ recycled F).card = + Module.finrank ℝ (span v (recycled F)) := by + rw [span_recycled_eq hF i] + exact (indep_rank v ((F.2.1 i).mono Finset.inter_subset_left)).symm + rw [hcover, Finset.card_biUnion hdisj] + calc + cost F = ∑ i, ((F.1 i \ recycled F).card + (F.1 i ∩ recycled F).card) := by + apply Finset.sum_congr rfl + intro i _ + exact (Finset.card_sdiff_add_card_inter _ _).symm + _ = (∑ i, (F.1 i \ recycled F).card) + + Fintype.card I * Module.finrank ℝ (span v (recycled F)) := by + simp_rw [hrank, Finset.sum_add_distrib] + simp + +theorem vector_base_packing (v : E → V) + (hcut : ∀ U : Finset E, + Fintype.card I * Module.finrank ℝ (span v Finset.univ) ≤ + (Finset.univ \ U).card + Fintype.card I * Module.finrank ℝ (span v U)) : + ∃ F : State v I, ∀ i, span v (F.1 i) = span v Finset.univ := by + obtain ⟨F, hF⟩ := exists_maximal_state (I := I) v + have hle (i : I) : (F.1 i).card ≤ Module.finrank ℝ (span v Finset.univ) := by + rw [← indep_rank v (F.2.1 i)] + exact Submodule.finrank_mono (span_mono v (Finset.subset_univ _)) + have htotal : cost F = Fintype.card I * Module.finrank ℝ (span v Finset.univ) := by + apply le_antisymm + · calc + cost F ≤ ∑ _i : I, Module.finrank ℝ (span v Finset.univ) := + Finset.sum_le_sum fun i _ => hle i + _ = _ := by simp + · rw [cost_decomposition hF] + exact hcut (recycled F) + have hcards (i : I) : (F.1 i).card = Module.finrank ℝ (span v Finset.univ) := by + apply (Finset.sum_eq_sum_iff_of_le (fun i (_ : i ∈ (Finset.univ : Finset I)) => hle i)).mp ?_ i + (Finset.mem_univ i) + simpa [cost] using htotal + refine ⟨F, fun i => ?_⟩ + apply Submodule.eq_of_le_of_finrank_eq (span_mono v (Finset.subset_univ _)) + rw [indep_rank v (F.2.1 i), hcards] + +omit [Fintype E] [FiniteDimensional ℝ V] in +lemma masked_span (v : E → V) (T U : Finset E) : + span (fun e => if e ∈ T then v e else 0) U = span v (U ∩ T) := by + classical + apply le_antisymm + · apply (span_le_iff _).mpr + intro e he + by_cases heT : e ∈ T + · simp only [ite_eq_left heT] + exact mem_span_self v (Finset.mem_inter.mpr ⟨he, heT⟩) + · simp [heT] + · apply (span_le_iff _).mpr + intro e he + have hm := mem_span_self (fun e => if e ∈ T then v e else 0) (Finset.mem_inter.mp he).1 + simpa only [ite_eq_left (Finset.mem_inter.mp he).2] using hm + +theorem vector_base_packing_on (v : E → V) (T : Finset E) + (hcut : ∀ U : Finset E, U ⊆ T → + Fintype.card I * Module.finrank ℝ (span v T) ≤ + (T \ U).card + Fintype.card I * Module.finrank ℝ (span v U)) : + ∃ F : I → Finset E, Valid v F ∧ ∀ i, F i ⊆ T ∧ span v (F i) = span v T := by + classical + let w : E → V := fun e => if e ∈ T then v e else 0 + have hcrit : ∀ U : Finset E, Fintype.card I * Module.finrank ℝ (span w Finset.univ) ≤ + (Finset.univ \ U).card + Fintype.card I * Module.finrank ℝ (span w U) := by + intro U + have hw (A : Finset E) : span w A = span v (A ∩ T) := masked_span v T A + rw [hw, hw, Finset.univ_inter] + have h := hcut (U ∩ T) Finset.inter_subset_right + apply h.trans + apply Nat.add_le_add_right + apply Finset.card_le_card + intro e he + simp only [Finset.mem_sdiff, Finset.mem_inter, Finset.mem_univ, true_and] at he ⊢ + tauto + obtain ⟨F, hF⟩ := vector_base_packing (I := I) w hcrit + have hsub (i : I) : F.1 i ⊆ T := by + intro e he + have hz := (F.2.1 i).ne_zero he + by_contra h + exact hz (by simp [w, h]) + refine ⟨F.1, ⟨?_, F.2.2⟩, fun i => ⟨hsub i, ?_⟩⟩ + · intro i + apply (F.2.1 i).congr + intro e he + simp [w, hsub i he] + · have heq := hF i + simpa only [w, masked_span, Finset.inter_eq_left.mpr (hsub i), Finset.univ_inter] using heq + +end StrongThinTree.Packing + +namespace StrongThinTree.MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) + +abbrev edgeSpan (T : Finset (Fin m)) := Packing.span G.incidence T + +def Same (T : Finset (Fin m)) (u v : Fin n) : Prop := + point u - point v ∈ G.edgeSpan T + +lemma same_refl (T : Finset (Fin m)) (u : Fin n) : G.Same T u u := by + simp [Same] + +lemma same_symm {T : Finset (Fin m)} {u v : Fin n} (h : G.Same T u v) : G.Same T v u := by + change point v - point u ∈ G.edgeSpan T + simpa only [neg_sub] using (G.edgeSpan T).neg_mem h + +lemma same_trans {T : Finset (Fin m)} {u v w : Fin n} + (huv : G.Same T u v) (hvw : G.Same T v w) : G.Same T u w := by + change point u - point w ∈ G.edgeSpan T + simpa only [sub_add_sub_cancel] using (G.edgeSpan T).add_mem huv hvw + +def components (T : Finset (Fin m)) : Setoid (Fin n) where + r := G.Same T + iseqv := ⟨G.same_refl T, G.same_symm, G.same_trans⟩ + +def rep (T : Finset (Fin m)) (u : Fin n) : Fin n := (Quotient.mk (G.components T) u).out + +lemma rep_same (T : Finset (Fin m)) (u : Fin n) : G.Same T (G.rep T u) u := + Quotient.mk_out (s := G.components T) u + +lemma rep_eq_iff (T : Finset (Fin m)) (u v : Fin n) : G.rep T u = G.rep T v ↔ G.Same T u v := by + constructor + · intro h + exact G.same_trans (G.same_symm (G.rep_same T u)) (h ▸ G.rep_same T v) + · intro h + exact congrArg Quotient.out (Quotient.sound h) + +lemma rep_idempotent (T : Finset (Fin m)) (u : Fin n) : G.rep T (G.rep T u) = G.rep T u := + (G.rep_eq_iff T _ _).mpr (G.rep_same T u) + +lemma same_endpoints {T : Finset (Fin m)} {e : Fin m} (he : e ∈ T) : + G.Same T (G.left e) (G.right e) := Packing.mem_span_self G.incidence he + +lemma rep_endpoints {T : Finset (Fin m)} {e : Fin m} (he : e ∈ T) : + G.rep T (G.left e) = G.rep T (G.right e) := + (G.rep_eq_iff T _ _).mpr (G.same_endpoints he) + +abbrev repDifference (T : Finset (Fin m)) (u : Fin n) : Fin n → ℝ := + point u - point (G.rep T u) + +lemma repDifference_mem (T : Finset (Fin m)) (u : Fin n) : G.repDifference T u ∈ G.edgeSpan T := + G.same_symm (G.rep_same T u) + +lemma repDifference_independent (T : Finset (Fin m)) : + LinearIndependent ℝ (fun u : {u : Fin n // G.rep T u ≠ u} => G.repDifference T u) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun u => LinearMap.proj u.1) + · intro u v huv + have huv' : u.1 ≠ v.1 := fun h => huv (Subtype.ext h) + have hru : u.1 ≠ G.rep T v.1 := by + intro h + have := G.rep_idempotent T v.1 + rw [← h] at this + exact u.2 this + simp [repDifference, point, huv', hru] + · intro u + simp [repDifference, point, (Ne.symm u.2)] + +lemma edgeSpan_eq_repSpan (T : Finset (Fin m)) : + G.edgeSpan T = Submodule.span ℝ + (Set.range (fun u : {u : Fin n // G.rep T u ≠ u} => G.repDifference T u)) := by + classical + apply le_antisymm + · apply (Packing.span_le_iff G.incidence).mpr + intro e he + have hdiff (u : Fin n) : G.repDifference T u ∈ Submodule.span ℝ + (Set.range (fun u : {u : Fin n // G.rep T u ≠ u} => G.repDifference T u)) := by + by_cases hu : G.rep T u = u + · simp [repDifference, hu] + · exact Submodule.subset_span ⟨⟨u, hu⟩, rfl⟩ + have h := (Submodule.span ℝ _).sub_mem (hdiff (G.left e)) (hdiff (G.right e)) + have heq : G.repDifference T (G.left e) - G.repDifference T (G.right e) = G.incidence e := by + dsimp [repDifference, incidence] + rw [G.rep_endpoints he] + abel + rwa [heq] at h + · apply Submodule.span_le.mpr + rintro x ⟨u, rfl⟩ + exact G.repDifference_mem T u + +def componentCount (T : Finset (Fin m)) : ℕ := (Finset.univ.image (G.rep T)).card + +theorem incidence_rank (T : Finset (Fin m)) : + Module.finrank ℝ (G.edgeSpan T) = n - G.componentCount T := by + classical + rw [G.edgeSpan_eq_repSpan, finrank_span_eq_card (G.repDifference_independent T), + Fintype.card_subtype_compl] + have heq : Finset.univ.image (G.rep T) = Finset.univ.filter (fun u => G.rep T u = u) := by + ext u + simp only [Finset.mem_image, Finset.mem_univ, true_and, Finset.mem_filter] + constructor + · rintro ⟨v, rfl⟩ + exact G.rep_idempotent T v + · intro hu + exact ⟨u, hu⟩ + simp only [componentCount, heq, Fintype.card_fin, Fintype.card_subtype] + +lemma sumOn_point (S : Finset (Fin n)) (v : Fin n) : + (∑ u ∈ S, LinearMap.proj u : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point v) = + if v ∈ S then 1 else 0 := by + simp [LinearMap.sum_apply, point, Pi.single_apply, Finset.sum_ite_eq'] + +theorem connected_iff_same (T : Finset (Fin m)) : + G.Connected T ↔ ∀ u v, G.Same T u v := by + classical + constructor + · intro hconn u v + by_contra huv + let S := Finset.univ.filter (fun w => G.Same T w v) + have hS : S.Nonempty := ⟨v, by simp [S, G.same_refl]⟩ + have hSne : S ≠ Finset.univ := by + intro heq + have hu : u ∈ S := heq ▸ Finset.mem_univ u + exact huv (by simpa [S] using hu) + obtain ⟨e, he⟩ := hconn S hS hSne + obtain ⟨heT, hecut⟩ := Finset.mem_filter.mp he + rcases hecut with ⟨hl, hr⟩ | ⟨hr, hl⟩ + · have hl' : G.Same T (G.left e) v := by simpa [S] using hl + have hr' := G.same_trans (G.same_symm (G.same_endpoints heT)) hl' + exact hr (by simpa [S] using hr') + · have hr' : G.Same T (G.right e) v := by simpa [S] using hr + have hl' := G.same_trans (G.same_endpoints heT) hr' + exact hl (by simpa [S] using hl') + · intro hsame S hS hSne + by_contra hcut + have hempty : G.cut T S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hcut + let f : (Fin n → ℝ) →ₗ[ℝ] ℝ := ∑ u ∈ S, LinearMap.proj u + have hker : G.edgeSpan T ≤ LinearMap.ker f := by + apply (Packing.span_le_iff G.incidence).mpr + intro e he + have hiff : G.left e ∈ S ↔ G.right e ∈ S := by + have h : ¬ ((G.left e ∈ S ∧ G.right e ∉ S) ∨ + (G.right e ∈ S ∧ G.left e ∉ S)) := by + intro hc + have : e ∈ G.cut T S := Finset.mem_filter.mpr ⟨he, hc⟩ + simp [hempty] at this + tauto + change f (G.incidence e) = 0 + rw [incidence, map_sub] + change (∑ u ∈ S, LinearMap.proj u : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point (G.left e)) - + (∑ u ∈ S, LinearMap.proj u : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point (G.right e)) = 0 + simp only [sumOn_point] + simp only [hiff, sub_self] + obtain ⟨u, hu⟩ := hS + have hv : ∃ v, v ∉ S := by + by_contra h + push Not at h + exact hSne (Finset.eq_univ_of_forall h) + obtain ⟨v, hv⟩ := hv + have hz := hker (hsame u v) + change f (point u - point v) = 0 at hz + rw [map_sub] at hz + change (∑ w ∈ S, LinearMap.proj w : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point u) - + (∑ w ∈ S, LinearMap.proj w : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point v) = 0 at hz + simp [sumOn_point, hu, hv] at hz + +lemma connected_of_span_eq {T U : Finset (Fin m)} + (h : G.edgeSpan T = G.edgeSpan U) (hT : G.Connected T) : G.Connected U := by + rw [G.connected_iff_same] at hT ⊢ + intro u v + change point u - point v ∈ G.edgeSpan U + rw [← h] + exact hT u v + +theorem spanningTree_iff_independent (T : Finset (Fin m)) : + G.SpanningTree T ↔ G.Connected T ∧ LinearIndepOn ℝ G.incidence (T : Set (Fin m)) := by + constructor + · rintro ⟨hconn, hmin⟩ + refine ⟨hconn, linearIndepOn_iff_notMem_span.mpr ?_⟩ + intro e he hdep + have hd : G.incidence e ∈ G.edgeSpan (T.erase e) := by + simpa only [edgeSpan, Packing.span, Finset.coe_erase] using hdep + have heq : G.edgeSpan T = G.edgeSpan (T.erase e) := by + calc + G.edgeSpan T = G.edgeSpan (insert e (T.erase e)) := by rw [Finset.insert_erase he] + _ = G.edgeSpan (T.erase e) := by + change Packing.span G.incidence (insert e (T.erase e)) = _ + rw [Packing.span_insert, Submodule.span_insert_eq_span hd] + exact hmin e he (G.connected_of_span_eq heq hconn) + · rintro ⟨hconn, hind⟩ + refine ⟨hconn, fun e he hdel => ?_⟩ + have hnot := linearIndepOn_iff_notMem_span.mp hind e he + apply hnot + have hsame := (G.connected_iff_same (T.erase e)).mp hdel (G.left e) (G.right e) + simpa only [Same, incidence, edgeSpan, Packing.span, Finset.coe_erase] using hsame + +lemma componentCount_pos (hn : 0 < n) (T : Finset (Fin m)) : 0 < G.componentCount T := by + apply Finset.card_pos.mpr + exact ⟨G.rep T ⟨0, hn⟩, Finset.mem_image.mpr ⟨⟨0, hn⟩, Finset.mem_univ _, rfl⟩⟩ + +lemma componentCount_le (T : Finset (Fin m)) : G.componentCount T ≤ n := by + exact (Finset.card_image_le).trans_eq (Finset.card_univ.trans (Fintype.card_fin n)) + +lemma connected_componentCount {T : Finset (Fin m)} (hn : 0 < n) (hc : G.Connected T) : + G.componentCount T = 1 := by + apply Finset.card_eq_one.mpr + let u : Fin n := ⟨0, hn⟩ + refine ⟨G.rep T u, ?_⟩ + ext v + constructor + · intro hv + obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv + exact Finset.mem_singleton.mpr ((G.rep_eq_iff T w u).mpr ((G.connected_iff_same T).mp hc w u)) + · intro hv + have hv' := Finset.mem_singleton.mp hv + subst v + exact Finset.mem_image.mpr ⟨u, Finset.mem_univ _, rfl⟩ + +lemma connected_rank {T : Finset (Fin m)} (hn : 0 < n) (hc : G.Connected T) : + Module.finrank ℝ (G.edgeSpan T) = n - 1 := by + rw [G.incidence_rank, G.connected_componentCount hn hc] + +lemma spanningTree_card {T : Finset (Fin m)} (hn : 0 < n) (hT : G.SpanningTree T) : T.card = n - 1 := by + rw [← Packing.indep_rank G.incidence ((G.spanningTree_iff_independent T).mp hT).2] + exact G.connected_rank hn hT.1 + +def crossing (T : Finset (Fin m)) (p : Fin n → Fin n) : Finset (Fin m) := + T.filter fun e => p (G.left e) ≠ p (G.right e) + +def partitionSize (p : Fin n → Fin n) : ℕ := (Finset.univ.image p).card + +def TreePackable (T : Finset (Fin m)) (r : ℕ) : Prop := + ∃ F : Fin r → Finset (Fin m), + (∀ i, F i ⊆ T ∧ G.SpanningTree (F i)) ∧ Pairwise (fun i j => Disjoint (F i) (F j)) + +lemma connected_of_componentCount_eq_one {T : Finset (Fin m)} + (hc : G.componentCount T = 1) : G.Connected T := by + rw [G.connected_iff_same] + have ⟨v, hv⟩ := Finset.card_eq_one.mp hc + intro a b + have ha : G.rep T a ∈ Finset.univ.image (G.rep T) := + Finset.mem_image.mpr ⟨a, Finset.mem_univ _, rfl⟩ + have hb : G.rep T b ∈ Finset.univ.image (G.rep T) := + Finset.mem_image.mpr ⟨b, Finset.mem_univ _, rfl⟩ + rw [hv, Finset.mem_singleton] at ha hb + exact (G.rep_eq_iff T a b).mp (ha.trans hb.symm) + +lemma crossing_components_subset (T U : Finset (Fin m)) : + G.crossing T (G.rep U) ⊆ T \ U := by + intro e he + obtain ⟨heT, hec⟩ := Finset.mem_filter.mp he + exact Finset.mem_sdiff.mpr ⟨heT, fun heU => hec (G.rep_endpoints heU)⟩ + +lemma crossing_components_self (T : Finset (Fin m)) : G.crossing T (G.rep T) = ∅ := by + apply Finset.eq_empty_of_forall_notMem + intro e he + have := G.crossing_components_subset T T he + simp at this + +theorem partition_criterion_sufficient (T : Finset (Fin m)) {r : ℕ} (hr : 0 < r) (hn : 0 < n) + (hp : ∀ p : Fin n → Fin n, r * (partitionSize p - 1) ≤ (G.crossing T p).card) : + G.TreePackable T r := by + have hc : G.Connected T := by + have h := hp (G.rep T) + rw [G.crossing_components_self, Finset.card_empty] at h + change r * (G.componentCount T - 1) ≤ 0 at h + have hpos := G.componentCount_pos hn T + have hz : G.componentCount T - 1 = 0 := by nlinarith + exact G.connected_of_componentCount_eq_one (by omega) + have hcrit : ∀ U : Finset (Fin m), U ⊆ T → + Fintype.card (Fin r) * Module.finrank ℝ (Packing.span G.incidence T) ≤ + (T \ U).card + Fintype.card (Fin r) * Module.finrank ℝ (Packing.span G.incidence U) := by + intro U hUT + change Fintype.card (Fin r) * Module.finrank ℝ (G.edgeSpan T) ≤ + (T \ U).card + Fintype.card (Fin r) * Module.finrank ℝ (G.edgeSpan U) + rw [Fintype.card_fin, G.connected_rank hn hc, G.incidence_rank] + have hpart := hp (G.rep U) + have hcross := Finset.card_le_card (G.crossing_components_subset T U) + have hcp := G.componentCount_pos hn U + have hcle := G.componentCount_le U + change r * (G.componentCount U - 1) ≤ (G.crossing T (G.rep U)).card at hpart + have hnid : n - 1 = (G.componentCount U - 1) + (n - G.componentCount U) := by omega + rw [hnid, Nat.mul_add] + exact Nat.add_le_add_right (hpart.trans hcross) _ + obtain ⟨F, hv, hF⟩ := Packing.vector_base_packing_on G.incidence T hcrit + refine ⟨F, fun i => ?_, hv.2⟩ + refine ⟨(hF i).1, (G.spanningTree_iff_independent (F i)).mpr ⟨?_, hv.1 i⟩⟩ + exact G.connected_of_span_eq (hF i).2.symm hc + +lemma sum_partition_cuts (T : Finset (Fin m)) (p : Fin n → Fin n) : + (∑ c ∈ Finset.univ.image p, (G.cut T (Finset.univ.filter (p · = c))).card) = + 2 * (G.crossing T p).card := by + classical + simp only [cut, crossing, Finset.card_eq_sum_ones, Finset.sum_filter, + Finset.mem_filter, Finset.mem_univ, true_and] + rw [Finset.sum_comm] + calc + _ = ∑ e ∈ T, if p (G.left e) ≠ p (G.right e) then 2 else 0 := by + apply Finset.sum_congr rfl + intro e he + by_cases h : p (G.left e) = p (G.right e) + · simp [h] + · rw [ite_eq_left h] + have hl : p (G.left e) ∈ Finset.univ.image p := Finset.mem_image.mpr ⟨_, Finset.mem_univ _, rfl⟩ + have hr : p (G.right e) ∈ Finset.univ.image p := Finset.mem_image.mpr ⟨_, Finset.mem_univ _, rfl⟩ + rw [Finset.sum_eq_add (p (G.left e)) (p (G.right e)) h] + · simp [h, Ne.symm h] + · intro c hc hh + simp [Ne.symm hh.1, Ne.symm hh.2] + · exact fun hh => (hh hl).elim + · exact fun hh => (hh hr).elim + _ = _ := by rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intros; split_ifs <;> omega + +lemma partition_fiber_proper (p : Fin n → Fin n) (hp : 1 < partitionSize p) (c : Fin n) : + Finset.univ.filter (p · = c) ≠ Finset.univ := by + intro h + have him : Finset.univ.image p ⊆ {c} := by + intro d hd + obtain ⟨v, hv, rfl⟩ := Finset.mem_image.mp hd + have hv' : v ∈ Finset.univ.filter (p · = c) := by rw [h]; exact Finset.mem_univ v + simpa using hv' + have : partitionSize p ≤ 1 := by simpa [partitionSize] using Finset.card_le_card him + omega + +theorem edgeConnected_treePackable {r : ℕ} (hr : 0 < r) (hn : 0 < n) + (hc : G.EdgeConnected (2 * r)) : G.TreePackable Finset.univ r := by + apply G.partition_criterion_sufficient _ hr hn + intro p + by_cases hp : partitionSize p ≤ 1 + · have : partitionSize p - 1 = 0 := by omega + simp [this] + have hp' : 1 < partitionSize p := by omega + have hsum : (∑ c ∈ Finset.univ.image p, 2 * r) ≤ + ∑ c ∈ Finset.univ.image p, (G.cut Finset.univ (Finset.univ.filter (p · = c))).card := by + apply Finset.sum_le_sum + intro c hc' + obtain ⟨v, hv, rfl⟩ := Finset.mem_image.mp hc' + exact hc _ ⟨v, by simp⟩ (partition_fiber_proper p hp' _) + rw [G.sum_partition_cuts] at hsum + simp only [Finset.sum_const, smul_eq_mul] at hsum + change partitionSize p * (2 * r) ≤ _ at hsum + have : r * partitionSize p ≤ (G.crossing Finset.univ p).card := by nlinarith + exact (Nat.mul_le_mul_left r (Nat.sub_le _ _)).trans this + +lemma same_preserves_label {U : Finset (Fin m)} {p : Fin n → Fin n} + (hp : ∀ e ∈ U, p (G.left e) = p (G.right e)) {u v : Fin n} + (huv : G.Same U u v) : p u = p v := by + classical + by_contra h + let S := Finset.univ.filter (fun w => p w = p u) + let f : (Fin n → ℝ) →ₗ[ℝ] ℝ := ∑ w ∈ S, LinearMap.proj w + have hker : G.edgeSpan U ≤ LinearMap.ker f := by + apply (Packing.span_le_iff G.incidence).mpr + intro e he + change f (G.incidence e) = 0 + rw [incidence, map_sub] + change (∑ w ∈ S, LinearMap.proj w : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point (G.left e)) - + (∑ w ∈ S, LinearMap.proj w : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point (G.right e)) = 0 + simp [sumOn_point, S, hp e he] + have hz := hker huv + change f (point u - point v) = 0 at hz + rw [map_sub] at hz + change (∑ w ∈ S, LinearMap.proj w : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point u) - + (∑ w ∈ S, LinearMap.proj w : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point v) = 0 at hz + simp [sumOn_point, S, Ne.symm h] at hz + +lemma partitionSize_le_components {U : Finset (Fin m)} {p : Fin n → Fin n} + (hp : ∀ e ∈ U, p (G.left e) = p (G.right e)) : + partitionSize p ≤ G.componentCount U := by + apply Finset.card_le_card_of_surjOn p + intro c hc + obtain ⟨v, hv, rfl⟩ := Finset.mem_image.mp hc + exact ⟨G.rep U v, Finset.mem_image.mpr ⟨v, Finset.mem_univ _, rfl⟩, + G.same_preserves_label hp (G.rep_same U v)⟩ + +lemma spanningTree_crossing {T : Finset (Fin m)} (hn : 0 < n) + (hT : G.SpanningTree T) (p : Fin n → Fin n) : + partitionSize p - 1 ≤ (G.crossing T p).card := by + classical + let U := T \ G.crossing T p + have hUT : U ⊆ T := Finset.sdiff_subset + have hUi := ((G.spanningTree_iff_independent T).mp hT).2.mono hUT + have hrank := Packing.indep_rank G.incidence hUi + change Module.finrank ℝ (G.edgeSpan U) = U.card at hrank + rw [G.incidence_rank] at hrank + have hc := G.partitionSize_le_components (U := U) (p := p) (by + intro e he + obtain ⟨heT, hec⟩ := Finset.mem_sdiff.mp he + by_contra h + exact hec (Finset.mem_filter.mpr ⟨heT, h⟩)) + have hcard : U.card + (G.crossing T p).card = T.card := + Finset.card_sdiff_add_card_eq_card (Finset.filter_subset _ _) + rw [G.spanningTree_card hn hT] at hcard + have hle := G.componentCount_le U + omega + +theorem partition_criterion_necessary {T : Finset (Fin m)} {r : ℕ} (hn : 0 < n) + (hpack : G.TreePackable T r) (p : Fin n → Fin n) : + r * (partitionSize p - 1) ≤ (G.crossing T p).card := by + classical + obtain ⟨F, hF, hd⟩ := hpack + have hdis : (↑(Finset.univ : Finset (Fin r)) : Set (Fin r)).PairwiseDisjoint + (fun i => G.crossing (F i) p) := by + intro i hi j hj hij + exact Finset.disjoint_of_subset_left (Finset.filter_subset _ _) + (Finset.disjoint_of_subset_right (Finset.filter_subset _ _) (hd hij)) + have hsub : Finset.univ.biUnion (fun i => G.crossing (F i) p) ⊆ G.crossing T p := by + apply Finset.biUnion_subset.mpr + intro i hi + exact Finset.filter_subset_filter _ (hF i).1 + have hc := Finset.card_le_card hsub + rw [Finset.card_biUnion hdis] at hc + have ht : (∑ i : Fin r, (partitionSize p - 1)) ≤ + ∑ i : Fin r, (G.crossing (F i) p).card := + Finset.sum_le_sum (fun i hi => G.spanningTree_crossing hn (hF i).2 p) + simpa using ht.trans hc + +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Blocks.lean b/lean/OAI/Combinatorics/ThinTrees/Blocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..58c637176c9a8957005f2cb2fbb363aa4b97571b --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Blocks.lean @@ -0,0 +1,82 @@ +import OAI.Combinatorics.ThinTrees.Subisotropic + +namespace OAI + +universe uD uO uI uI2 + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree.MSS +variable {D : Type uD} {O : Type uO} [Fintype D] [DecidableEq D] [Fintype O] [DecidableEq O] + +lemma blockDiagonal_nonneg (A : O → Matrix D D ℝ) (hA : ∀o, 0 ≤ A o) : + 0 ≤ Matrix.blockDiagonal A := by + let S : O → Matrix D D ℝ := fun o => CFC.sqrt (A o) + have hf : ∀o, (S o)ᴴ*S o=A o := by + intro o + rw [(CFC.sqrt_nonneg (A o)).posSemidef.isHermitian.eq] + exact CFC.sqrt_mul_sqrt_self (A o) (hA o) + have he : (Matrix.blockDiagonal S)ᴴ*Matrix.blockDiagonal S=Matrix.blockDiagonal A := by + rw [Matrix.blockDiagonal_conjTranspose,←Matrix.blockDiagonal_mul] + simp only [hf] + rw [←he] + exact (Matrix.posSemidef_conjTranspose_mul_self _).nonneg + +lemma blockDiagonal_mono (A B : O → Matrix D D ℝ) (h : ∀o, A o ≤ B o) : + Matrix.blockDiagonal A ≤ Matrix.blockDiagonal B := by + apply sub_nonneg.mp + rw [←Matrix.blockDiagonal_sub] + exact blockDiagonal_nonneg _ (fun o => sub_nonneg.mpr (h o)) + +omit [Fintype D] [DecidableEq D] [Fintype O] [DecidableEq O] in +lemma blockDiag_mono {A B : Matrix (D × O) (D × O) ℝ} (h : A ≤ B) (o : O) : + Matrix.blockDiag A o ≤ Matrix.blockDiag B o := by + have hh := (sub_nonneg.mpr h).posSemidef.submatrix (fun d : D => (d,o)) + change (Matrix.blockDiag (B-A) o).PosSemidef at hh + simpa only [Matrix.blockDiag_sub,Pi.sub_apply,sub_nonneg] using hh.nonneg + +omit [Fintype O] [DecidableEq O] [Fintype D] [DecidableEq D] in +lemma blockDiag_sum {I : Type uI} (s : Finset I) (A : I → Matrix (D × O) (D × O) ℝ) (o : O) : + Matrix.blockDiag (∑i ∈ s, A i) o=∑i ∈ s, Matrix.blockDiag (A i) o := by + ext a b + simp [Matrix.blockDiag_apply,Matrix.sum_apply] + +omit [Fintype D] [DecidableEq D] in +def blockEmbed (v : D → ℝ) (b : Bool) : D × Bool → ℝ := + fun p => if p.2=b then v p.1 else 0 + +omit [DecidableEq D] in +lemma blockEmbed_trace (v : D → ℝ) (b : Bool) : + (Matrix.vecMulVec (blockEmbed v b) (blockEmbed v b)).trace=(Matrix.vecMulVec v v).trace := by + cases b <;> simp [Matrix.trace,Matrix.diag,Matrix.vecMulVec,blockEmbed,Fintype.sum_prod_type] + +omit [Fintype D] [DecidableEq D] in +lemma blockEmbed_mean (v : D → ℝ) : + (∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (blockEmbed v b) (blockEmbed v b))= + Matrix.blockDiagonal (fun _ : Bool => (1/2 : ℝ) • Matrix.vecMulVec v v) := by + ext ⟨a,c⟩ ⟨d,b⟩ + cases c <;> cases b <;> + simp [Matrix.vecMulVec,blockEmbed,Matrix.blockDiagonal_apply] + +omit [Fintype D] [DecidableEq D] in +lemma blockEmbed_blockDiag (v : D → ℝ) (b c : Bool) : + Matrix.blockDiag (Matrix.vecMulVec (blockEmbed v b) (blockEmbed v b)) c= + if b=c then Matrix.vecMulVec v v else 0 := by + cases b <;> cases c <;> ext a d <;> + simp [Matrix.blockDiag_apply,Matrix.vecMulVec,blockEmbed] + +omit [Fintype O] [DecidableEq O] [Fintype D] [DecidableEq D] in +lemma blockDiagonal_sum {I : Type uI2} (s : Finset I) (A : I → O → Matrix D D ℝ) [DecidableEq O] : + Matrix.blockDiagonal (fun o => ∑i ∈ s, A i o)=∑i ∈ s, Matrix.blockDiagonal (A i) := by + ext ⟨a,b⟩ ⟨c,d⟩ + by_cases h : b=d <;> simp [Matrix.blockDiagonal_apply,h,Matrix.sum_apply] + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Capture.lean b/lean/OAI/Combinatorics/ThinTrees/Capture.lean new file mode 100644 index 0000000000000000000000000000000000000000..d24f62b47933d17e3ceb75d7bb5b622771d3462a --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Capture.lean @@ -0,0 +1,376 @@ +import OAI.Combinatorics.ThinTrees.AssignedFamilies + +namespace OAI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +namespace AssignedFamily +variable {q : ℝ} (F : AssignedFamily H G X (6144/q)) + +def BoundaryRatio (ρ : ℝ) : Prop := ∀i, + (q*ρ)*((G.cut univ (F.bag i).owner).card : ℝ) ≤ (H.parentBoundary G (F.bag i).owner).card + +lemma boundary_mass {ρ : ℝ} (hq : 0 < q) (hR : F.BoundaryRatio ρ) : + 6144*ρ*(boundaryCount G F.owners : ℝ)*F.radius ≤ F.mass := by + have he : (boundaryCount G F.owners : ℝ) = + ∑i, ((G.cut univ (F.bag i).owner).card : ℝ) := by + simp only [boundaryCount,owners,Nat.cast_sum] + exact sum_image F.owner_injective.injOn + have hi : ∀i, (6144*ρ)*((G.cut univ (F.bag i).owner).card : ℝ) ≤ ((F.bag i).centers.card : ℝ) := by + intro i + have hh := mul_le_mul_of_nonneg_left (hR i) (show 0 ≤ (6144:ℝ)/q by positivity) + have hx : (6144:ℝ)/q*((q*ρ)*((G.cut univ (F.bag i).owner).card : ℝ)) = + (6144*ρ)*((G.cut univ (F.bag i).owner).card : ℝ) := by field_simp + rw [hx] at hh + exact hh.trans (F.bag i).assignment + rw [he] + dsimp [mass] + apply mul_le_mul_of_nonneg_right _ F.positive.le + rw [mul_sum] + exact sum_le_sum (fun i _ => hi i) +end AssignedFamily + +namespace AssignedSequence +open AssignedFamily +variable {q : ℝ} + +def Fresh (E : Finset (Finset (Fin n))) : List (AssignedFamily H G X (6144/q)) → Prop + | [] => True + | F::L => Disjoint E F.owners ∧ Fresh (E∪F.owners) L + +def Ratios (ρ : ℝ) : List (AssignedFamily H G X (6144/q)) → Prop + | [] => True + | F::L => F.BoundaryRatio ρ ∧ Ratios ρ L + +def GeometricAt {η : ℝ} (ρ : ℝ) : List (AssignedFamily H G X η) → Prop + | [] => True + | F::L => initialRadius L ≤ ρ*F.radius ∧ GeometricAt ρ L + +lemma geometric_of {η ρ : ℝ} (hρ : ρ ≤ 1/1536) + (L : List (AssignedFamily H G X η)) (hL : GeometricAt ρ L) : Geometric L := by + induction L with + | nil => trivial + | cons F L ih => + refine ⟨?_,ih hL.2⟩ + have hh := mul_le_mul_of_nonneg_right hρ F.positive.le + linarith [hL.1] + +lemma prune_sequence (hX : ∀v, binary (X v)) (hq : 0 < q) + {ρ : ℝ} (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (L : List (AssignedFamily H G X (6144/q))) + (hgeo : GeometricAt ρ L) (hR : Ratios ρ L) + (E E' : Finset (Finset (Fin n))) (hE : E ⊆ H.nodes) (hE' : E' ⊆ E) + (hfresh : Fresh E L) : + ∃L' : List (AssignedFamily H G X (3072/q)), initialRadius L' = initialRadius L ∧ + GeometricAt ρ L' ∧ Ready E' L' ∧ + mass L/2-8*(initialRadius L)*(boundaryCount G E : ℝ) ≤ mass L' := by + induction L generalizing E E' with + | nil => exact ⟨[],rfl,True.intro,True.intro,by simp [mass,initialRadius]⟩ + | cons F L ih => + obtain ⟨F',hrad,howners,hprot,hgain⟩ := F.prune E (η' := 3072/q) (by field_simp; ring_nf; rfl) + have hE₁ : E∪F.owners ⊆ H.nodes := union_subset hE F.owners_nodes + obtain ⟨L',headEq,hgeo',hready',hgain'⟩ := ih hgeo.2 hR.2 + (E∪F.owners) (E'∪F'.owners) hE₁ (union_subset_union hE' howners) hfresh.2 + have hdis : Disjoint E' F'.owners := hfresh.1.mono hE' howners + have hBC : (boundaryCount G (E∪F.owners) : ℝ) = + (boundaryCount G E : ℝ)+(boundaryCount G F.owners : ℝ) := by + simp only [boundaryCount,sum_union hfresh.1,Nat.cast_add] + have hb := F.badCount_le hX E + have hb' : (F.badCount E : ℝ) ≤ 2*(boundaryCount G E : ℝ) := by exact_mod_cast hb + have hpf : F.mass-4*F.radius*(boundaryCount G E : ℝ) ≤ F'.mass := by + have hh := mul_le_mul_of_nonneg_right hb' F.positive.le + nlinarith + have hr := F.boundary_mass hq hR.1 + have heps := radius_nonneg L + have hsc := hgeo.1 + have hsmall := mul_le_mul_of_nonneg_right hρsmall F.positive.le + have hcoal : 4*F.radius+8*initialRadius L ≤ 8*F.radius := by linarith + have hB0 : (0:ℝ) ≤ boundaryCount G E := Nat.cast_nonneg _ + have hBF0 : (0:ℝ) ≤ boundaryCount G F.owners := Nat.cast_nonneg _ + have hc := mul_le_mul_of_nonneg_right hsc hBF0 + have hcost : 8*initialRadius L*(boundaryCount G F.owners : ℝ) ≤ F.mass/2 := by + have hpos : 0 ≤ ρ*F.radius*(boundaryCount G F.owners : ℝ) := + mul_nonneg (mul_nonneg hρ.le F.positive.le) hBF0 + nlinarith + have hprev := mul_le_mul_of_nonneg_right hcoal hB0 + refine ⟨F'::L',hrad,⟨?_,hgeo'⟩,⟨hdis,hprot E' hE',hready'⟩,?_⟩ + · simpa only [headEq,hrad] using hsc + · rw [hBC] at hgain' + dsimp [mass,initialRadius] + nlinarith + +lemma assigned_bound (hX : ∀v, binary (X v)) {q : ℝ} (hq : 0 < q) + (hconn : H.LocallyConnectedReal G q) + {ρ : ℝ} (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (L : List (AssignedFamily H G X (6144/q))) + (hgeo : GeometricAt ρ L) (hR : Ratios ρ L) (hfresh : Fresh ∅ L) : + (q/8192)*mass L ≤ ∑e : Fin m, l1dist (X (G.left e)) (X (G.right e)) := by + obtain ⟨L',hrad,hgeo',hready',hmass⟩ := prune_sequence hX hq hρ hρsmall L hgeo hR ∅ ∅ + (empty_subset _) (Subset.refl _) hfresh + have hcharge := insertable_bound hX hq hconn (le_refl (3072/q)) L' (geometric_of hρsmall L' hgeo') hready' + have hmass' : mass L/2 ≤ mass L' := by simpa [boundaryCount] using hmass + have hh := mul_le_mul_of_nonneg_left hmass' (show 0 ≤ q/4096 by positivity) + nlinarith + +end AssignedSequence +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry StrongThinTree.Geometry.RadialShell +open scoped Classical +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +lemma assigned_from_net (T : Finset (Finset (Fin n))) (W : Finset (Fin n)) + (hW : W.Nonempty) (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hboundary : ∀t ∈ T, 0 < (H.parentBoundary G t).card) + {D η : ℝ} (hD : 0 < D) + (hsep : (W : Set (Fin n)).Pairwise (fun u v => + Disjoint ((ball u D).support X) ((ball v D).support X))) + (hcenter : ∀u ∈ W, ∃t ∈ T, u ∈ t ∧ ∃e ∈ H.parentBoundary G t, + (G.left e = u ∨ G.right e = u) ∧ l1dist (X (G.left e)) (X (G.right e)) < D) + (hη : η ≤ (W.card : ℝ)/(2*(∑t ∈ T, ((H.parentBoundary G t).card : ℝ)))) : + ∃F : AssignedFamily H G X η, F.radius = D ∧ F.owners ⊆ T ∧ + D*(W.card : ℝ)/2 ≤ F.mass := by + obtain ⟨u0,hu0⟩ := hW + obtain ⟨t0,ht0,ht0c⟩ := hcenter u0 hu0 + have hex : ∀u : Fin n, ∃t ∈ T, u ∈ W → u ∈ t ∧ ∃e ∈ H.parentBoundary G t, + (G.left e = u ∨ G.right e = u) ∧ l1dist (X (G.left e)) (X (G.right e)) < D := by + intro u + by_cases hu : u ∈ W + · obtain ⟨t,ht,hc⟩ := hcenter u hu + exact ⟨t,ht,fun _ => hc⟩ + · exact ⟨t0,ht0,fun hh => (hu hh).elim⟩ + choose f hfT hf using hex + let N : ℝ := ∑t ∈ T, ((H.parentBoundary G t).card : ℝ) + have hN : 0 < N := sum_pos (fun t ht => by exact_mod_cast hboundary t ht) ⟨t0,ht0⟩ + have hW0 : (0:ℝ) < W.card := by exact_mod_cast card_pos.mpr ⟨u0,hu0⟩ + let c : ℝ := W.card/(2*N) + have hc : 0 < c := div_pos hW0 (mul_pos (by norm_num) hN) + obtain ⟨J,hJT,hJ,hgain⟩ := retain_fibers W T f (fun u _ => hfT u) + (fun t => ((H.parentBoundary G t).card : ℝ)) + (fun t ht => by exact_mod_cast hboundary t ht) hc + let fiber := fun t => W.filter (fun u => f u=t) + let e : Fin (Fintype.card J) ≃ J := (Fintype.equivFin J).symm + let a (t : J) : H.AssignedBag G X D η := { + owner := t.val + owner_mem := hT (hJT t.property) + nonroot := hroot t.val (hJT t.property) + centers := fiber t.val + nonempty := (hJ t.val t.property).1 + radius_pos := hD + disjoint := hsep.mono (filter_subset _ _) + assignment := (mul_le_mul_of_nonneg_right hη (Nat.cast_nonneg _)).trans (hJ t.val t.property).2 + endpoint := by + intro u hu + obtain ⟨hu,hfu⟩ := mem_filter.mp hu + simpa only [hfu] using hf u hu } + let F : AssignedFamily H G X η := { + radius := D + positive := hD + count := Fintype.card J + bag := fun i => a (e i) + owner_injective := by + intro i j hij + exact e.injective (Subtype.ext hij) + separated := by + intro i u hu j v hv hne + apply hsep (mem_filter.mp hu).1 (mem_filter.mp hv).1 + intro huv + subst v + have hh : (e i).val = (e j).val := + (mem_filter.mp hu).2.symm.trans (mem_filter.mp hv).2 + rcases hne with hne | hne + · exact hne (e.injective (Subtype.ext hh)) + · exact hne rfl } + have hsum : (∑i : Fin F.count, ((F.bag i).centers.card : ℝ)) = + ∑t ∈ J, ((fiber t).card : ℝ) := by + change (∑i : Fin (Fintype.card J), ((fiber (e i).val).card : ℝ)) = _ + rw [e.sum_comp (fun t : J => ((fiber t.val).card : ℝ))] + exact sum_coe_sort J (fun t => ((fiber t).card : ℝ)) + refine ⟨F,rfl,?_,?_⟩ + · intro t ht + obtain ⟨i,hi,rfl⟩ := mem_image.mp ht + exact hJT (e i).property + · have heq : c*N = (W.card : ℝ)/2 := by dsimp [c]; field_simp + change (W.card : ℝ)-c*N ≤ _ at hgain + rw [heq] at hgain + change D*(W.card : ℝ)/2 ≤ (∑i : Fin F.count, ((F.bag i).centers.card : ℝ))*D + rw [hsum] + have hh := mul_le_mul_of_nonneg_left hgain hD.le + nlinarith + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +open scoped Classical +variable {n m : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + +lemma boundary_owner_unique {A B : Finset (Fin n)} {u v : Fin n} + (hA : A ∈ H.nodes) (hB : B ∈ H.nodes) (hAr : A ≠ univ) (hBr : B ≠ univ) + (huA : u ∈ A) (huB : u ∈ B) (hvA : v ∉ A) (hvB : v ∉ B) + (hvPA : v ∈ H.parent A) (hvPB : v ∈ H.parent B) : A = B := by + rcases H.laminar A hA B hB with hAB | hBA | hdis + · by_contra hne + have hp := H.parent_minimal A hA hAr B hB (Finset.ssubset_iff_subset_ne.mpr ⟨hAB,hne⟩) + exact hvB (hp hvPA) + · by_contra hne + have hp := H.parent_minimal B hB hBr A hA (Finset.ssubset_iff_subset_ne.mpr ⟨hBA,Ne.symm hne⟩) + exact hvA (hp hvPB) + · exact (Finset.disjoint_left.mp hdis huA huB).elim + +lemma parentBoundary_multiplicity (T : Finset (Finset (Fin n))) + (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) (e : Fin m) : + (T.filter (fun t => e ∈ H.parentBoundary G t)).card ≤ 2 := by + let S := T.filter (fun t => e ∈ H.parentBoundary G t) + let L := S.filter (fun t => G.left e ∈ t) + let R := S.filter (fun t => G.right e ∈ t) + have hL : L.card ≤ 1 := by + apply card_le_one.mpr + intro A hA B hB + obtain ⟨hA,hlA⟩ := mem_filter.mp hA + obtain ⟨hB,hlB⟩ := mem_filter.mp hB + obtain ⟨hAT,heA⟩ := mem_filter.mp hA + obtain ⟨hBT,heB⟩ := mem_filter.mp hB + obtain ⟨hePA,hcutA⟩ := mem_filter.mp heA + obtain ⟨hePB,hcutB⟩ := mem_filter.mp heB + have hrA : G.right e ∉ A := by rcases hcutA with hh | hh; exact hh.2; exact (hh.2 hlA).elim + have hrB : G.right e ∉ B := by rcases hcutB with hh | hh; exact hh.2; exact (hh.2 hlB).elim + exact H.boundary_owner_unique (hT hAT) (hT hBT) (hroot A hAT) (hroot B hBT) + hlA hlB hrA hrB ((G.mem_inducedEdges _ _).mp hePA).2 ((G.mem_inducedEdges _ _).mp hePB).2 + have hR : R.card ≤ 1 := by + apply card_le_one.mpr + intro A hA B hB + obtain ⟨hA,hrA⟩ := mem_filter.mp hA + obtain ⟨hB,hrB⟩ := mem_filter.mp hB + obtain ⟨hAT,heA⟩ := mem_filter.mp hA + obtain ⟨hBT,heB⟩ := mem_filter.mp hB + obtain ⟨hePA,hcutA⟩ := mem_filter.mp heA + obtain ⟨hePB,hcutB⟩ := mem_filter.mp heB + have hlA : G.left e ∉ A := by rcases hcutA with hh | hh; exact (hh.2 hrA).elim; exact hh.2 + have hlB : G.left e ∉ B := by rcases hcutB with hh | hh; exact (hh.2 hrB).elim; exact hh.2 + exact H.boundary_owner_unique (hT hAT) (hT hBT) (hroot A hAT) (hroot B hBT) + hrA hrB hlA hlB ((G.mem_inducedEdges _ _).mp hePA).1 ((G.mem_inducedEdges _ _).mp hePB).1 + have hsub : S ⊆ L∪R := by + intro A hA + have hc := (mem_filter.mp (mem_filter.mp hA).2).2 + rcases hc with hh | hh + · exact mem_union_left _ (mem_filter.mpr ⟨hA,hh.1⟩) + · exact mem_union_right _ (mem_filter.mpr ⟨hA,hh.1⟩) + exact (card_le_card hsub).trans ((card_union_le _ _).trans (by omega)) + +lemma subset_boundary_multiplicity (T : Finset (Finset (Fin n))) + (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (F : Finset (Fin n) → Finset (Fin m)) (hF : ∀t ∈ T, F t ⊆ H.parentBoundary G t) : + (∑t ∈ T, (F t).card) ≤ 2*(T.biUnion F).card := by + have hdouble : (∑t ∈ T, (F t).card) = + ∑e ∈ T.biUnion F, (T.filter (fun t => e ∈ F t)).card := by + simp only [card_eq_sum_ones,sum_filter] + rw [sum_comm] + apply sum_congr rfl + intro t ht + simp only [←sum_filter] + congr 1 + ext e + simp only [mem_filter,mem_biUnion] + exact ⟨fun hh => ⟨⟨t,ht,hh⟩,hh⟩,fun hh => hh.2⟩ + rw [hdouble] + have heq : 2*(T.biUnion F).card = ∑_e ∈ T.biUnion F, 2 := by simp [mul_comm] + rw [heq] + apply sum_le_sum + intro e he + apply le_trans (card_le_card (show T.filter (fun t => e ∈ F t) ⊆ + T.filter (fun t => e ∈ H.parentBoundary G t) from by + intro t ht + obtain ⟨ht,he⟩ := mem_filter.mp ht + exact mem_filter.mpr ⟨ht,hF t ht he⟩)) + exact H.parentBoundary_multiplicity G T hT hroot e + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry StrongThinTree.Geometry.RadialShell +open scoped Classical +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +lemma capture_small_balls (T : Finset (Finset (Fin n))) (S P : Finset (Fin n)) + (hS : S.Nonempty) (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hboundary : ∀t ∈ T, 0 < (H.parentBoundary G t).card) + {δ c₂ η : ℝ} (hδ : 0 < δ) (hc : 0 < c₂) (_hη : 0 ≤ η) + (hsep : (S : Set (Fin n)).Pairwise (fun u v => + Disjoint ((ball u δ).support X) ((ball v δ).support X))) + (hcover : ∀u ∈ S, ∃v ∈ P, l1dist (X u) (X v) ≤ c₂) + (hP : ∀u ∈ P, ∃t ∈ T, u ∈ t ∧ ∃e ∈ H.parentBoundary G t, + (G.left e = u ∨ G.right e = u) ∧ l1dist (X (G.left e)) (X (G.right e)) ≤ c₂) + (hηδ : 864*η*(∑t ∈ T, ((H.parentBoundary G t).card : ℝ)) ≤ S.card) + (hηc : 1728*η*c₂*(∑t ∈ T, ((H.parentBoundary G t).card : ℝ)) ≤ δ*S.card) : + (∃F : CompactFamily X δ (6*max δ (2*c₂)), + δ*(S.card : ℝ)/864 ≤ δ*(∑B ∈ F.bags, (B.card : ℝ))) ∨ + (∃F : AssignedFamily H G X η, F.radius = max δ (2*c₂) ∧ F.owners ⊆ T ∧ + δ*(S.card : ℝ)/864 ≤ F.mass) := by + let D := max δ (2*c₂) + have hD : 0 < D := hδ.trans_le (le_max_left _ _) + have hcD : c₂ < D := lt_of_lt_of_le (by linarith) (le_max_right _ _) + obtain ⟨u0,hu0⟩ := hS + obtain ⟨v0,hv0,hv0d⟩ := hcover u0 hu0 + have hPne : P.Nonempty := ⟨v0,hv0⟩ + obtain ⟨W,hWP,hW,hWsep,hWcover⟩ := l1_separated_net X P hPne (show 0 ≤ 2*D by positivity) + have hballs : (W : Set (Fin n)).Pairwise (fun u v => + Disjoint ((ball u D).support X) ((ball v D).support X)) := by + intro u hu v hv huv + exact distance_balls_disjoint X u v (hWsep u hu v hv huv).le + have hcover' : ∀u ∈ S, ∃v ∈ W, l1dist (X u) (X v) ≤ 3*D := by + intro u hu + obtain ⟨p,hp,hup⟩ := hcover u hu + obtain ⟨v,hv,hpv⟩ := hWcover p hp + exact ⟨v,hv,(l1dist_triangle (X u) (X p) (X v)).trans (by linarith)⟩ + by_cases hsmall : 432*D*(W.card : ℝ) ≤ δ*(S.card : ℝ) + · obtain ⟨F,hF⟩ := compact_from_net S W ⟨u0,hu0⟩ hW hδ (le_max_left _ _) hsep hcover' hsmall + exact Or.inl ⟨F,(by nlinarith [show (0:ℝ) ≤ S.card from Nat.cast_nonneg _] : δ*(S.card : ℝ)/864 ≤ δ*(S.card : ℝ)/2).trans hF⟩ + · have hlarge : δ*(S.card : ℝ) < 432*D*(W.card : ℝ) := lt_of_not_ge hsmall + have hcenter : ∀u ∈ W, ∃t ∈ T, u ∈ t ∧ ∃e ∈ H.parentBoundary G t, + (G.left e = u ∨ G.right e = u) ∧ l1dist (X (G.left e)) (X (G.right e)) < D := by + intro u hu + obtain ⟨t,ht,hut,e,he,heu,hlen⟩ := hP u (hWP hu) + exact ⟨t,ht,hut,e,he,heu,hlen.trans_lt hcD⟩ + let N : ℝ := ∑t ∈ T, ((H.parentBoundary G t).card : ℝ) + obtain ⟨t0,ht0,ht0c⟩ := hP v0 hv0 + have hN : 0 < N := sum_pos (fun t ht => by exact_mod_cast hboundary t ht) ⟨t0,ht0⟩ + have hnumer : 864*η*N*D ≤ δ*(S.card : ℝ) := by + rcases le_total δ (2*c₂) with hh | hh + · dsimp [D] + rw [max_eq_right hh] + change 1728*η*c₂*N ≤ δ*(S.card : ℝ) at hηc + nlinarith + · dsimp [D] + rw [max_eq_left hh] + change 864*η*N ≤ (S.card : ℝ) at hηδ + simpa [mul_comm δ] using mul_le_mul_of_nonneg_right hηδ hδ.le + have hassign : η ≤ (W.card : ℝ)/(2*N) := by + apply (le_div_iff₀ (mul_pos (by norm_num) hN)).mpr + nlinarith + obtain ⟨F,hFD,hFT,hgain⟩ := assigned_from_net T W hW hT hroot hboundary hD hballs hcenter hassign + exact Or.inr ⟨F,hFD,hFT,(by nlinarith : δ*(S.card : ℝ)/864 ≤ D*(W.card : ℝ)/2).trans hgain⟩ + +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/ChainEdges.lean b/lean/OAI/Combinatorics/ThinTrees/ChainEdges.lean new file mode 100644 index 0000000000000000000000000000000000000000..86b29fa61de3d30dd0282c5400db97cc410fe7ff --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/ChainEdges.lean @@ -0,0 +1,109 @@ +import OAI.Combinatorics.ThinTrees.HierarchyBuilder + +namespace OAI + +section + +namespace StrongThinTree.MultiGraph.PartitionChain +noncomputable section +open Finset +variable {n m : ℕ} (P : PartitionChain n) (G : MultiGraph n m) + +def block (i : ℕ) (v : Fin n) : Finset (Fin n) := (P.part_exists i v).choose +lemma block_mem (i : ℕ) (v : Fin n) : P.block i v ∈ P.parts i := (P.part_exists i v).choose_spec.1 +lemma mem_block (i : ℕ) (v : Fin n) : v ∈ P.block i v := (P.part_exists i v).choose_spec.2 +lemma block_eq_of_mem {i : ℕ} {A : Finset (Fin n)} (hA : A ∈ P.parts i) {v : Fin n} (hv : v ∈ A) : + P.block i v=A := P.intersect_eq (P.block_mem i v) hA ⟨v,mem_inter.mpr ⟨P.mem_block i v,hv⟩⟩ +lemma block_subset {i j : ℕ} (hij : i ≤ j) (v : Fin n) : P.block i v ⊆ P.block j v := + P.subset_of_intersect hij (P.block_mem i v) (P.block_mem j v) + ⟨v,mem_inter.mpr ⟨P.mem_block i v,P.mem_block j v⟩⟩ + +def crossing (i : ℕ) : Finset (Fin m) := univ.filter (fun e => P.block i (G.left e) ≠ P.block i (G.right e)) +lemma mem_crossing (i : ℕ) (e : Fin m) : e ∈ P.crossing G i ↔ P.block i (G.left e) ≠ P.block i (G.right e) := by + simp [crossing] +lemma crossing_antitone : Antitone (P.crossing G) := by + intro i j hij e he + rw [P.mem_crossing] at he ⊢ + intro h + apply he + apply P.block_eq_of_mem (P.block_mem j (G.right e)) + exact P.block_subset hij (G.right e) (h ▸ P.mem_block i (G.left e)) +lemma crossing_root {z : ℕ} (hz : P.parts z={univ}) : P.crossing G z=∅ := by + apply eq_empty_iff_forall_notMem.mpr + intro e he + have hl : P.block z (G.left e)=univ := mem_singleton.mp (hz ▸ P.block_mem z (G.left e)) + have hr : P.block z (G.right e)=univ := mem_singleton.mp (hz ▸ P.block_mem z (G.right e)) + exact (P.mem_crossing G z e).mp he (hl.trans hr.symm) + +lemma cut_part_crossing {i : ℕ} {A : Finset (Fin n)} (hA : A ∈ P.parts i) : + G.cut univ A ⊆ P.crossing G i := by + intro e he + rw [P.mem_crossing] + intro h + have hc := (mem_filter.mp he).2 + rcases hc with ⟨hl,hr⟩ | ⟨hr,hl⟩ + · have hla := P.block_eq_of_mem hA hl + exact hr ((h.symm.trans hla) ▸ P.mem_block i (G.right e)) + · have hra := P.block_eq_of_mem hA hr + exact hl ((h.trans hra) ▸ P.mem_block i (G.left e)) + +lemma boundary_sum_le (i : ℕ) : + ∑A ∈ P.parts i, (G.cut univ A).card ≤ 2*(P.crossing G i).card := by + classical + let C (e : Fin m) := (P.parts i).filter (fun A => e ∈ G.cut univ A) + have hC (e : Fin m) : C e ⊆ {P.block i (G.left e),P.block i (G.right e)} := by + intro A hA + obtain ⟨hAP,he⟩ := mem_filter.mp hA + rcases (mem_filter.mp he).2 with ⟨hl,_⟩ | ⟨hr,_⟩ + · exact mem_insert.mpr (Or.inl (P.block_eq_of_mem hAP hl).symm) + · exact mem_insert.mpr (Or.inr (mem_singleton.mpr (P.block_eq_of_mem hAP hr).symm)) + have hc (e : Fin m) : (C e).card ≤ if e ∈ P.crossing G i then 2 else 0 := by + split_ifs with he + · exact (card_le_card (hC e)).trans (by simpa using card_insert_le (P.block i (G.left e)) {P.block i (G.right e)}) + · have hem : C e=∅ := by + apply eq_empty_iff_forall_notMem.mpr + intro A hA + obtain ⟨hAP,heA⟩ := mem_filter.mp hA + exact he (P.cut_part_crossing G hAP heA) + simp [hem] + have heq : (∑A ∈ P.parts i, (G.cut univ A).card)=∑e : Fin m, (C e).card := by + simp only [C,card_eq_sum_ones,sum_filter] + rw [sum_comm] + apply sum_congr rfl + intro e _ + simp [cut] + rw [heq] + calc + (∑e : Fin m, (C e).card) ≤ ∑e : Fin m, if e ∈ P.crossing G i then 2 else 0 := sum_le_sum (fun e _ => hc e) + _ = 2*(P.crossing G i).card := by rw [←sum_filter]; simp [mul_comm] + +lemma disappearing_in_parentBoundary {I : Finset ℕ} {H : Hierarchy n} (hH : H.nodes=P.nodes I) + {i j : ℕ} (hi : i ∈ I) (hj : j ∈ I) (hij : i < j) + (hnext : ∀k ∈ I, i < k → j ≤ k) {e : Fin m} + (he : e ∈ P.crossing G i \ P.crossing G j) : + ∃A ∈ P.parts i, e ∈ H.parentBoundary G A := by + have he1 := (P.mem_crossing G i e).mp (mem_sdiff.mp he).1 + have he2 : P.block j (G.left e)=P.block j (G.right e) := by + by_contra h + exact (mem_sdiff.mp he).2 ((P.mem_crossing G j e).mpr h) + have hr : G.right e ∉ P.block i (G.left e) := by + intro hr + exact he1 (P.block_eq_of_mem (P.block_mem i (G.left e)) hr).symm + have hrB : G.right e ∈ P.block j (G.left e) := he2 ▸ P.mem_block j (G.right e) + have hstrict : P.block i (G.left e) ⊂ P.block j (G.left e) := by + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨P.block_subset hij.le _,?_⟩ + intro hh + exact hr (hh ▸ hrB) + have hparent := P.parent_at_transition hH hi hj hij hnext (P.block_mem i (G.left e)) (P.block_mem j (G.left e)) hstrict + refine ⟨P.block i (G.left e),P.block_mem i _,?_⟩ + change e ∈ G.cut (G.inducedEdges (H.parent (P.block i (G.left e)))) (P.block i (G.left e)) + rw [hparent] + exact mem_filter.mpr ⟨(G.mem_inducedEdges _ e).mpr ⟨P.mem_block j _,hrB⟩,Or.inl ⟨P.mem_block i _,hr⟩⟩ + +end +end StrongThinTree.MultiGraph.PartitionChain + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Characteristic.lean b/lean/OAI/Combinatorics/ThinTrees/Characteristic.lean new file mode 100644 index 0000000000000000000000000000000000000000..1408115337fca3918a1be66bb6991b7a4e9dd279 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Characteristic.lean @@ -0,0 +1,85 @@ +import OAI.Combinatorics.ThinTrees.Interlacing + +namespace OAI + +universe uI uD uR uO uO2 + +section + +noncomputable section +open Matrix Polynomial Finset +open scoped MatrixOrder +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [CommRing R] + +lemma univ_perm_cons (j : I) : (Finset.univ.toList : List I).Perm (j::(Finset.univ.erase j).toList) := by + apply (List.perm_ext_iff_of_nodup (Finset.nodup_toList _) (List.nodup_cons.mpr + ⟨by simp, Finset.nodup_toList _⟩)).mpr + intro i + simp + tauto + +lemma mixedEval_affine {O : Type uO} [Fintype O] (j : I) (M : Matrix D D R) + (A : I → Matrix D D R) (w : O → R) (B : O → Matrix D D R) (hw : ∑o, w o=1) : + mixedEval Finset.univ.toList M (Function.update A j (∑o, w o • B o))= + ∑o, w o * mixedEval Finset.univ.toList M (Function.update A j (B o)) := by + have hh : ∀A : I → Matrix D D R, mixedEval Finset.univ.toList M A= + mixedEval (j::(Finset.univ.erase j).toList) M A := by + intro A + unfold mixedEval + rw [diffProduct_perm (univ_perm_cons j)] + simp only [hh] + exact mixedEval_affine_cons j _ (by simp) M A w B hw + +def mixedChar (A : I → Matrix D D R) : R[X] := + mixedEval Finset.univ.toList ((Polynomial.X : R[X]) • (1 : Matrix D D R[X])) + (fun i => (A i).map Polynomial.C) + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma map_update (A : I → Matrix D D R) (j : I) (B : Matrix D D R) : + (fun i => ((Function.update A j B) i).map Polynomial.C)= + Function.update (fun i => (A i).map Polynomial.C) j (B.map Polynomial.C) := by + funext i + by_cases hi : i=j <;> simp [hi] + +lemma mixedChar_affine {O : Type uO2} [Fintype O] (j : I) + (A : I → Matrix D D R) (w : O → R) (B : O → Matrix D D R) (hw : ∑o, w o=1) : + mixedChar (Function.update A j (∑o, w o • B o))= + ∑o, Polynomial.C (w o) * mixedChar (Function.update A j (B o)) := by + have hm : (∑o, w o • B o).map Polynomial.C= + ∑o, Polynomial.C (w o) • (B o).map Polynomial.C := by + apply Matrix.ext + intro a b + simp [Matrix.map_apply,Matrix.sum_apply,Matrix.smul_apply] + simp only [mixedChar,map_update,hm] + exact mixedEval_affine j _ _ (fun o => Polynomial.C (w o)) _ (by simpa using congrArg Polynomial.C hw) + +lemma mixedChar_rankOne (A : I → Matrix D D R) (hA : ∀i, ∃u v, A i=Matrix.vecMulVec u v) : + mixedChar A=(∑i, A i).charpoly := by + unfold mixedChar + rw [mixedEval_rankOne _ (Finset.nodup_toList _)] + · rw [Finset.sum_map_toList] + have he : (∑i, (A i).map Polynomial.C)=(∑i, A i).map Polynomial.C := by + apply Matrix.ext + intro a b + simp [Matrix.sum_apply,Matrix.map_apply] + rw [he] + unfold Matrix.charpoly + apply congrArg Matrix.det + apply Matrix.ext + intro a b + by_cases hab : a=b <;> simp [Matrix.sub_apply,Matrix.smul_apply,Matrix.map_apply,hab] + · intro i _ + obtain ⟨u,v,h⟩ := hA i + refine ⟨fun a => Polynomial.C (u a),fun a => Polynomial.C (v a),?_⟩ + rw [h] + apply Matrix.ext + intro a b + simp [Matrix.vecMulVec,Matrix.map_apply] + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Coarea.lean b/lean/OAI/Combinatorics/ThinTrees/Coarea.lean new file mode 100644 index 0000000000000000000000000000000000000000..93add61e4ae26cdca36be11f413c7b0464dc910d --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Coarea.lean @@ -0,0 +1,365 @@ +import OAI.Combinatorics.ThinTrees.Model + +namespace OAI + +universe uV uE uV2 uE2 uV3 uE3 uI uI2 uI3 + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.Geometry +noncomputable section +open Finset MeasureTheory Set + +lemma integrable_interval_indicator (a b c : ℝ) : + Integrable ((Set.Ioc a b).indicator (fun _ : ℝ => c)) := + (integrable_indicator_iff measurableSet_Ioc).mpr (integrableOn_const (by simp [Real.volume_Ioc])) + +lemma integral_interval_indicator (a b c : ℝ) (hab : a ≤ b) : + (∫ t : ℝ, (Set.Ioc a b).indicator (fun _ => c) t) = (b-a)*c := by + rw [integral_indicator_const c measurableSet_Ioc, Real.volume_real_Ioc, + max_eq_left (sub_nonneg.mpr hab), smul_eq_mul] + +lemma threshold_interval {x y t : ℝ} : + ((x < t ∧ ¬ y < t) ∨ (y < t ∧ ¬ x < t)) ↔ t ∈ Set.Ioc (min x y) (max x y) := by + simp only [Set.mem_Ioc, min_lt_iff, le_max_iff, not_lt] + constructor + · rintro (h | h) + · exact ⟨Or.inl h.1, Or.inr h.2⟩ + · exact ⟨Or.inr h.1, Or.inl h.2⟩ + · rintro ⟨h | h, h' | h'⟩ <;> first | (exfalso; linarith) | exact Or.inl ⟨h, h'⟩ | exact Or.inr ⟨h, h'⟩ + +lemma finite_coarea {V : Type uV} {E : Type uE} [Fintype E] [DecidableEq E] + (u v : E → V) (f : V → ℝ) : + (∫ t : ℝ, (((univ.filter (fun e => + (f (u e) (f (u e) (1:ℝ)) t := by + simp only [card_eq_sum_ones, Nat.cast_sum, sum_filter] + apply sum_congr rfl + intro e he + rw [Set.indicator_apply] + simp only [threshold_interval] + split_ifs <;> norm_num + simp_rw [heq] + rw [integral_finsetSum _ (fun e _ => integrable_interval_indicator _ _ _)] + apply sum_congr rfl + intro e he + rw [integral_interval_indicator _ _ _ min_le_max, mul_one] + simpa only [abs_sub_comm] using (max_sub_min_eq_abs (f (u e)) (f (v e))) + +lemma integrable_cut_card {V : Type uV2} {E : Type uE2} [Fintype E] [DecidableEq E] + (u v : E → V) (f : V → ℝ) : + Integrable (fun t : ℝ => + (((univ.filter (fun e => (f (u e) integrable_interval_indicator (min (f (u e)) (f (v e))) + (max (f (u e)) (f (v e))) 1) + apply hi.congr + filter_upwards with t + simp only [card_eq_sum_ones, Nat.cast_sum, sum_filter] + apply sum_congr rfl + intro e he + rw [Set.indicator_apply] + simp only [threshold_interval] + split_ifs <;> norm_num + +lemma cut_range_bound {V : Type uV3} {E : Type uE3} [Fintype E] [DecidableEq E] + (u v : E → V) (f : V → ℝ) {a b k : ℝ} (hab : a ≤ b) + (hcut : ∀t ∈ Set.Ioc a b, k ≤ + (((univ.filter (fun e => (f (u e) k) ≤ + (fun t : ℝ => (((univ.filter (fun e => + (f (u e) clamp a b (f v)) hab + intro t ht + let S := univ.filter (fun v => f v < t) + have hne : S.Nonempty := by + obtain ⟨u, hu⟩ := hu + exact ⟨u, mem_filter.mpr ⟨mem_univ _, lt_of_le_of_lt hu ht.1⟩⟩ + have hproper : S ≠ univ := by + obtain ⟨v, hv⟩ := hv + intro heq + have hh : v ∈ S := heq.symm ▸ mem_univ v + have := (mem_filter.mp hh).2 + linarith [ht.2] + have hc := hk S hne hproper + have hset : (univ.filter (fun e => + (clamp a b (f (G.left e)) nlinarith + +lemma clipped_affine_interval {a b x y : ℝ} (hab : a ≤ b) : + ∃ l r : ℝ, 0 ≤ l ∧ l ≤ r ∧ r ≤ 1 ∧ + |clamp a b x-clamp a b y| = |y-x| *(r-l) ∧ + ∀t ∈ Set.Ioo l r, a < x+t*(y-x) ∧ x+t*(y-x) < b := by + rcases lt_trichotomy x y with hxy | hxy | hxy + · exact clipped_affine_interval_increasing hab hxy + · subst y + exact ⟨0,0,by norm_num,by norm_num,by norm_num,by simp,by simp⟩ + · obtain ⟨l,r,hl,hlr,hr,heq,h⟩ := clipped_affine_interval_increasing hab hxy + refine ⟨1-r,1-l,by linarith,by linarith,by linarith,?_,?_⟩ + · rw [abs_sub_comm, heq, abs_sub_comm x y] + congr 1 + ring + · intro t ht + have hh := h (1-t) ⟨by linarith [ht.2],by linarith [ht.1]⟩ + constructor <;> nlinarith [hh.1,hh.2] + +lemma clamped_affine_disjoint_sum {I : Type uI} [Fintype I] + (a b x y : I → ℝ) {L : ℝ} (hL : 0 ≤ L) + (hab : ∀i, a i ≤ b i) (hslope : ∀i, |y i-x i| ≤ L) + (hdis : ∀ i j, i ≠ j → ∀t ∈ Set.Ioo (0:ℝ) 1, + ¬(a i < x i+t*(y i-x i) ∧ x i+t*(y i-x i) + clipped_affine_interval (x:=x i) (y:=y i) (hab i) + have hsub : (⋃i, Set.Ioo (l i) (r i)) ⊆ Set.Ioo (0:ℝ) 1 := by + rintro t ⟨_,⟨i,rfl⟩,ht⟩ + exact ⟨lt_of_le_of_lt (hl i) ht.1,lt_of_lt_of_le ht.2 (hr i)⟩ + have hd : Pairwise (fun i j => Disjoint (Set.Ioo (l i) (r i)) (Set.Ioo (l j) (r j))) := by + intro i j hij + rw [Set.disjoint_left] + intro t hti htj + exact hdis i j hij t ⟨lt_of_le_of_lt (hl i) hti.1, + lt_of_lt_of_le hti.2 (hr i)⟩ ⟨(hactive i t hti).1,(hactive i t hti).2, + (hactive j t htj).1,(hactive j t htj).2⟩ + have hv := measureReal_mono (μ:=volume) hsub (by simp [Real.volume_Ioo]) + rw [measureReal_iUnion_fintype hd (fun _ => measurableSet_Ioo) + (fun _ => by simp [Real.volume_Ioo]), Real.volume_real_Ioo] at hv + simp only [Real.volume_real_Ioo, max_eq_left (sub_nonneg.mpr (hlr _))] at hv + have hsum : ∑i, (r i-l i) ≤ 1 := by simpa using hv + calc + _ = ∑i, |y i-x i| *(r i-l i) := sum_congr rfl (fun i _ => heq i) + _ ≤ ∑i, L*(r i-l i) := sum_le_sum (fun i _ => + mul_le_mul_of_nonneg_right (hslope i) (sub_nonneg.mpr (hlr i))) + _ = L*∑i, (r i-l i) := (mul_sum _ _ _).symm + _ ≤ L*1 := mul_le_mul_of_nonneg_left hsum hL + _ = L := mul_one L + +end +end StrongThinTree.Geometry + +namespace StrongThinTree.Geometry +noncomputable section +open Finset + +def cube {h : ℕ} (x : Fin h → ℝ) : Prop := ∀j, 0 ≤ x j ∧ x j ≤ 1 + +def binary {h : ℕ} (x : Fin h → ℝ) : Prop := ∀j, x j = 0 ∨ x j = 1 + +def l1dist {h : ℕ} (x y : Fin h → ℝ) : ℝ := ∑j, |x j-y j| + +lemma binary_cube {h : ℕ} {x : Fin h → ℝ} (hx : binary x) : cube x := by + intro j + rcases hx j with h | h <;> simp [h] + +lemma l1dist_nonneg {h : ℕ} (x y : Fin h → ℝ) : 0 ≤ l1dist x y := + sum_nonneg (fun _ _ => abs_nonneg _) + +lemma l1dist_comm {h : ℕ} (x y : Fin h → ℝ) : l1dist x y = l1dist y x := by + simp only [l1dist, abs_sub_comm] + +lemma l1dist_reverse {h : ℕ} (x y z : Fin h → ℝ) : + |l1dist x z-l1dist y z| ≤ l1dist x y := by + rw [l1dist, l1dist, ← sum_sub_distrib] + calc + _ ≤ ∑j, abs (abs (x j-z j) - abs (y j-z j)) := abs_sum_le_sum_abs _ _ + _ ≤ ∑j, |x j-y j| := by + apply sum_le_sum + intro j _ + simpa only [sub_sub_sub_cancel_right] using abs_abs_sub_abs_le_abs_sub (x j-z j) (y j-z j) + _ = _ := rfl + +lemma cube_segment {h : ℕ} {x y : Fin h → ℝ} (hx : cube x) (hy : cube y) + {t : ℝ} (ht : t ∈ Set.Icc (0:ℝ) 1) : cube (fun j => x j+t*(y j-x j)) := by + intro j + have h1 : 0 ≤ (1-t)*x j+t*y j := add_nonneg + (mul_nonneg (by linarith [ht.2]) (hx j).1) (mul_nonneg ht.1 (hy j).1) + have h2 : (1-t)*x j+t*y j ≤ (1-t)*1+t*1 := add_le_add + (mul_le_mul_of_nonneg_left (hx j).2 (by linarith [ht.2])) + (mul_le_mul_of_nonneg_left (hy j).2 ht.1) + constructor <;> nlinarith + +lemma binary_radial_affine {h : ℕ} {x y z : Fin h → ℝ} + (hx : cube x) (hy : cube y) (hz : binary z) + {t : ℝ} (ht : t ∈ Set.Icc (0:ℝ) 1) : + l1dist (fun j => x j+t*(y j-x j)) z = + l1dist x z+t*(l1dist y z-l1dist x z) := by + have hc := cube_segment hx hy ht + unfold l1dist + rw [← sum_sub_distrib, mul_sum, ← sum_add_distrib] + apply sum_congr rfl + intro j _ + rcases hz j with hzj | hzj + · simp only [hzj, sub_zero, abs_of_nonneg (hx j).1, abs_of_nonneg (hy j).1, + abs_of_nonneg (hc j).1] + · rw [hzj, abs_of_nonpos (sub_nonpos.mpr (hc j).2), + abs_of_nonpos (sub_nonpos.mpr (hx j).2), abs_of_nonpos (sub_nonpos.mpr (hy j).2)] + ring + +lemma binary_shell_edge_bound {h : ℕ} {I : Type uI2} [Fintype I] + {x y : Fin h → ℝ} (hx : cube x) (hy : cube y) + (z : I → Fin h → ℝ) (hz : ∀i, binary (z i)) (a b : I → ℝ) + (hab : ∀i, a i ≤ b i) + (hdis : ∀i j, i ≠ j → ∀w, cube w → + ¬(a i < l1dist w (z i) ∧ l1dist w (z i) x j+t*(y j-x j)) (cube_segment hx hy htc) + simpa only [binary_radial_affine hx hy (hz i) htc, + binary_radial_affine hx hy (hz j) htc] using hbad + +end +end StrongThinTree.Geometry + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset StrongThinTree.Geometry + +lemma binary_shell_length_bound {n m h : ℕ} (G : MultiGraph n m) {k : ℕ} + (hk : G.EdgeConnected k) (X : Fin n → Fin h → ℝ) (hX : ∀v, cube (X v)) + {I : Type uI3} [Fintype I] (z : I → Fin h → ℝ) (hz : ∀i, binary (z i)) + (a b : I → ℝ) (hab : ∀i, a i ≤ b i) + (hu : ∀i, ∃u, l1dist (X u) (z i) ≤ a i) + (hv : ∀i, ∃v, b i ≤ l1dist (X v) (z i)) + (hdis : ∀i j, i ≠ j → ∀w, cube w → + ¬(a i < l1dist w (z i) ∧ l1dist w (z i) binary_shell_edge_bound (hX _) (hX _) z hz a b hab hdis) + +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/CompactPacking.lean b/lean/OAI/Combinatorics/ThinTrees/CompactPacking.lean new file mode 100644 index 0000000000000000000000000000000000000000..a68120a1baa60474ba2df1b0f0870a18020a12fd --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/CompactPacking.lean @@ -0,0 +1,475 @@ +import OAI.Combinatorics.ThinTrees.Density + +namespace OAI + +universe uJ uJ2 uJ3 + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset _root_.OAI.StrongThinTree.Geometry Geometry.RadialShell +open scoped Classical + +structure CompactPackage {n h : ℕ} (X : Fin n → Fin h → ℝ) where + radius : ℝ + diameter : ℝ + family : CompactFamily X radius diameter + +namespace CompactPackage +variable {n m h : ℕ} {G : MultiGraph n m} {X : Fin n → Fin h → ℝ} +def mass (F : CompactPackage X) : ℝ := F.radius*(∑D ∈ F.family.bags, (D.card : ℝ)) + +lemma finite_bound {k : ℕ} (hk : G.EdgeConnected k) (hX : ∀v, binary (X v)) + {q : ℕ} (F : Fin q → CompactPackage X) + (hnext : ∀i j : Fin q, i.val+1=j.val → (F j).diameter ≤ (F i).radius/12) : + (k:ℝ)/4*(∑i, (F i).mass) ≤ ∑e : Fin m, l1dist (X (G.left e)) (X (G.right e)) := by + by_cases hq : q=0 + · subst q + simp only [Finset.univ_eq_empty,Finset.sum_empty,mul_zero] + exact sum_nonneg (fun e _ => l1dist_nonneg _ _) + · have hq' : 0 < q := Nat.pos_of_ne_zero hq + let ind : ℕ → Fin q := fun i => ⟨i%q,Nat.mod_lt _ hq'⟩ + have hh := binary_compact_bound G hk X hX q + (fun i => (F (ind i)).radius) (fun i => (F (ind i)).diameter) + (fun i => (F (ind i)).family) (by + intro i hi + apply hnext + simp only [ind,Nat.mod_eq_of_lt hi,Nat.mod_eq_of_lt (show i F (f i)) (by + intro i j hij + apply hgeo + change (e j.rev).val < (e i.rev).val + exact e.strictMono (Fin.rev_lt_rev.mpr (show i (F i).mass)] at hh + exact hh +end CompactPackage + +namespace Hierarchy +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} {X : Fin n → Fin h → ℝ} + +namespace AssignedBag +variable {δ η η' : ℝ} +def weaken (A : H.AssignedBag G X δ η) (hη : η' ≤ η) : H.AssignedBag G X δ η' := + { A with assignment := (mul_le_mul_of_nonneg_right hη (Nat.cast_nonneg _)).trans A.assignment } +end AssignedBag + +namespace AssignedFamily +variable {η η' : ℝ} +def weaken (F : AssignedFamily H G X η) (hη : η' ≤ η) : AssignedFamily H G X η' where + radius := F.radius + positive := F.positive + count := F.count + bag := fun i => (F.bag i).weaken hη + owner_injective := F.owner_injective + separated := F.separated +end AssignedFamily + +namespace AssignedSequence +variable {η q ρ : ℝ} + +lemma mass_eq (L : List (AssignedFamily H G X η)) : mass L = (L.map AssignedFamily.mass).sum := by + induction L with + | nil => rfl + | cons F L ih => simpa only [mass,List.map_cons,List.sum_cons] using congrArg (F.mass+·) ih + +lemma geometric_of_pairwise (hρ : 0 ≤ ρ) (L : List (AssignedFamily H G X η)) + (hL : L.Pairwise (fun F F' => F'.radius ≤ ρ*F.radius)) : GeometricAt ρ L := by + induction L with + | nil => trivial + | cons F L ih => + refine ⟨?_,ih (List.pairwise_cons.mp hL).2⟩ + cases L with + | nil => exact mul_nonneg hρ F.positive.le + | cons F' L => exact (List.pairwise_cons.mp hL).1 F' (by simp) + +lemma ratios_of_mem (L : List (AssignedFamily H G X (6144/q))) + (hL : ∀F ∈ L, F.BoundaryRatio ρ) : Ratios ρ L := by + induction L with + | nil => trivial + | cons F L ih => exact ⟨hL F (by simp),ih (fun F' hF' => hL F' (by simp [hF']))⟩ + +lemma fresh_of_pairwise (L : List (AssignedFamily H G X (6144/q))) + (hL : L.Pairwise (fun F F' => Disjoint F.owners F'.owners)) + (E : Finset (Finset (Fin n))) (hE : ∀F ∈ L, Disjoint E F.owners) : Fresh E L := by + induction L generalizing E with + | nil => trivial + | cons F L ih => + refine ⟨hE F (by simp),ih (List.pairwise_cons.mp hL).2 _ ?_⟩ + intro F' hF' + exact disjoint_union_left.mpr ⟨hE F' (by simp [hF']), (List.pairwise_cons.mp hL).1 F' hF'⟩ + +lemma finite_bound (hX : ∀v, binary (X v)) (hq : 0 < q) + (hconn : H.LocallyConnectedReal G q) (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + {r : ℕ} (F : Fin r → AssignedFamily H G X (6144/q)) + (hgeo : ∀i j, i F (f i)) (by + intro i j hij + apply hgeo + change (e j.rev).val < (e i.rev).val + exact e.strictMono (Fin.rev_lt_rev.mpr hij)) + (fun i => hR (f i)) (fun i j hij => hdis _ _ (f.injective.ne hij.ne)) + rw [f.sum_comp (fun i => (F i).mass)] at hh + exact hh +end AssignedSequence +end Hierarchy +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset _root_.OAI.StrongThinTree.Geometry Geometry.RadialShell +open scoped Classical +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} {X : Fin n → Fin h → ℝ} + +abbrev CapturedFamily (H : Hierarchy n) (G : MultiGraph n m) (X : Fin n → Fin h → ℝ) (η : ℝ) := + Sum (CompactPackage X) (AssignedFamily H G X η) + +namespace CapturedFamily +variable {η : ℝ} +def radius : CapturedFamily H G X η → ℝ + | .inl F => F.radius + | .inr F => F.radius +def upper : CapturedFamily H G X η → ℝ + | .inl F => F.diameter + | .inr F => F.radius +def mass : CapturedFamily H G X η → ℝ + | .inl F => F.mass + | .inr F => F.mass +def owners : CapturedFamily H G X η → Finset (Finset (Fin n)) + | .inl _ => ∅ + | .inr F => F.owners + +def Ratio {q : ℝ} (F : CapturedFamily H G X (6144/q)) (ρ : ℝ) : Prop := + match F with + | .inl _ => True + | .inr F => F.BoundaryRatio ρ + +lemma mass_nonneg (F : CapturedFamily H G X η) : 0 ≤ F.mass := by + cases F with + | inl F => exact mul_nonneg F.family.radius_pos.le (sum_nonneg (fun D _ => Nat.cast_nonneg _)) + | inr F => exact mul_nonneg (sum_nonneg (fun i _ => Nat.cast_nonneg _)) F.positive.le + +lemma mixed_bound {J : Type uJ3} [LinearOrder J] {q : ℕ} + (hq : 0 < q) (hk : G.EdgeConnected q) (hX : ∀v, binary (X v)) + (hconn : H.LocallyConnectedReal G q) {ρ : ℝ} (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (S : Finset J) (F : S → CapturedFamily H G X (6144/q)) + (hgeo : ∀i j : S, j.val < i.val → (F j).upper ≤ ρ*(F i).radius) + (hR : ∀i, (F i).Ratio ρ) + (hdis : ∀i j : S, i≠j → Disjoint (F i).owners (F j).owners) : + ((q:ℝ)/8192)*(∑i, (F i).mass) ≤ 2*∑e : Fin m, l1dist (X (G.left e)) (X (G.right e)) := by + let C : Finset S := univ.filter (fun i => ∃P, F i=Sum.inl P) + let A : Finset S := univ\C + have hexC : ∀i : C, ∃P, F i.val=Sum.inl P := fun i => (mem_filter.mp i.property).2 + have hexA : ∀i : A, ∃P, F i.val=Sum.inr P := by + intro i + cases hh : F i.val with + | inl P => + have hi : i.val ∉ C := (mem_sdiff.mp i.property).2 + exact (hi (mem_filter.mpr ⟨mem_univ _,⟨P,hh⟩⟩)).elim + | inr P => exact ⟨P,rfl⟩ + let FC : C → CompactPackage X := fun i => Classical.choose (hexC i) + let FA : A → AssignedFamily H G X (6144/q) := fun i => Classical.choose (hexA i) + have hFC : ∀i : C, F i.val=Sum.inl (FC i) := fun i => Classical.choose_spec (hexC i) + have hFA : ∀i : A, F i.val=Sum.inr (FA i) := fun i => Classical.choose_spec (hexA i) + have hC := CompactPackage.ordered_bound hk hX C FC (by + intro i j hij + have hh := hgeo i.val j.val hij + rw [hFC i,hFC j] at hh + change (FC j).diameter ≤ ρ*(FC i).radius at hh + have hr : ρ ≤ 1/12 := hρsmall.trans (by norm_num) + have hm := mul_le_mul_of_nonneg_right hr (FC i).family.radius_pos.le + exact hh.trans (by nlinarith only [hm])) + have hA := AssignedSequence.ordered_bound hX (show (0:ℝ) (F i).mass)] + apply sum_congr rfl + intro i hi + rw [hFC i] + rfl + have hsumA : (∑i : A, (FA i).mass) = ∑i ∈ A, (F i).mass := by + rw [←sum_coe_sort A (fun i => (F i).mass)] + apply sum_congr rfl + intro i hi + rw [hFA i] + rfl + rw [hsumC] at hC + rw [hsumA] at hA + have hCn : 0 ≤ ∑i ∈ C, (F i).mass := sum_nonneg (fun i _ => mass_nonneg (F i)) + have hcoef : (q:ℝ)/8192 ≤ (q:ℝ)/4 := by + have hh : (0:ℝ) ≤ q := Nat.cast_nonneg _ + linarith + have hC' := (mul_le_mul_of_nonneg_right hcoef hCn).trans hC + have he : (∑i ∈ A, (F i).mass)+(∑i ∈ C, (F i).mass) = ∑i : S, (F i).mass := + sum_sdiff (subset_univ C) + rw [←he,mul_add] + linarith only [hA,hC'] +end CapturedFamily +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry StrongThinTree.Geometry.RadialShell +open scoped Classical +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} +namespace CapturedFamily +lemma scale_bound {q : ℕ} (hq : 0 < q) (hk : G.EdgeConnected q) + (hX : ∀v, binary (X v)) (hconn : H.LocallyConnectedReal G q) + {ρ s : ℝ} (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) (hs : 0 < s) + {R : ℕ} (hR : 0 < R) (hlog : Real.logb 2 (24/(ρ*s^2)) < R) + (S : Finset ℤ) (F : S → CapturedFamily H G X (6144/q)) + (hlow : ∀i : S, s*2^(i.val:ℝ) ≤ (F i).radius) + (hupp : ∀i : S, (F i).upper ≤ 24*2^(i.val:ℝ)/s) + (hratio : ∀i, (F i).Ratio ρ) + (hdis : ∀i j : S, i≠j → Disjoint (F i).owners (F j).owners) : + ((q:ℝ)/8192)*(∑i, (F i).mass) ≤ + 2*R*(∑e : Fin m, l1dist (X (G.left e)) (X (G.right e))) := by + let residue : ℤ → Fin R := fun i => ⟨(i%R).toNat, by + have hn := Int.emod_nonneg i (show (R:ℤ)≠0 by omega) + have hh := Int.emod_lt_of_pos i (show (0:ℤ) univ.filter (fun i => residue i.val=r) + have hbound : ∀r : Fin R, ((q:ℝ)/8192)*(∑i ∈ C r, (F i).mass) ≤ + 2*∑e : Fin m, l1dist (X (G.left e)) (X (G.right e)) := by + intro r + have hh := mixed_bound hq hk hX hconn hρ hρsmall (C r) (fun i => F i.val) (by + intro i j hij + have hi := (mem_filter.mp i.property).2 + have hj := (mem_filter.mp j.property).2 + have hmod : j.val.val%R=i.val.val%R := by + have he := congrArg Fin.val (hj.trans hi.symm) + dsimp [residue] at he + have hn1 := Int.emod_nonneg i.val.val (show (R:ℤ)≠0 by omega) + have hn2 := Int.emod_nonneg j.val.val (show (R:ℤ)≠0 by omega) + omega + have hsep := ScaleSelection.separated_scales hs hρ hlog + (ScaleSelection.residue_spacing hR hij hmod) + exact (hupp j.val).trans (hsep.le.trans (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_left (hlow i.val) hρ.le))) + (fun i => hratio i.val) + (fun i j hij => hdis i.val j.val (Subtype.val_injective.ne hij)) + rw [←sum_coe_sort (C r) (fun i => (F i).mass)] + exact hh + have hh := sum_le_sum (s := univ) (fun r (_ : r ∈ univ) => hbound r) + rw [←mul_sum] at hh + have he : (∑r : Fin R, ∑i ∈ C r, (F i).mass) = ∑i : S, (F i).mass := by + exact sum_fiberwise_of_maps_to (fun _ _ => mem_univ _) (fun i => (F i).mass) + rw [he] at hh + simpa only [sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul,mul_assoc,mul_left_comm] using hh +end CapturedFamily +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry StrongThinTree.Geometry.RadialShell +open scoped Classical +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +lemma capturePackage (T : Finset (Finset (Fin n))) (F : Finset (Fin n) → Finset (Fin m)) + (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hTne : T.Nonempty) (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hF : ∀t ∈ T, F t ⊆ H.parentBoundary G t) (hFn : ∀t ∈ T, (F t).Nonempty) + {α γ ε c₁ c₂ : ℝ} (hα : 0 < α) (hγ : 0 < γ) + (he : 0 < ε) (he1 : ε < 1/3) (hc₁ : 0 < c₁) (hc₂ : 0 < c₂) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ l1dist (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hmin : ∀t ∈ T, ∀e ∈ F t, c₁ ≤ ((Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hmax : ∀t ∈ T, ∀e ∈ F t, ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ 4*c₁) + (hdmin : ∀t ∈ T, ∀e ∈ F t, c₂/4 ≤ l1dist (X (G.left e)) (X (G.right e))) + (hdmax : ∀t ∈ T, ∀e ∈ F t, l1dist (X (G.left e)) (X (G.right e)) ≤ c₂) + (hbad : ∀t ∈ T, α*((H.parentBoundary G t).card : ℝ)* + (∑e ∈ H.parentBoundary G t, l1dist (X (G.left e)) (X (G.right e))) ≤ + (∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hdom : ∀t ∈ T, γ*(∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ + (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hsmall : (α*γ/32)^ε ≤ 1/(1728*(1024/ε^2))) + {q : ℕ} {ρ : ℝ} + (hassign : (6144:ℝ)/q ≤ (α*γ/32)^(1+2*ε)) + (hratio : ∀t ∈ T, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (H.parentBoundary G t).card) : + let s := α*γ/32 + let R := ∑t ∈ T, (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((H.parentBoundary G t).card : ℝ) + ∃B : CapturedFamily H G X (6144/q), B.owners ⊆ T ∧ B.Ratio ρ ∧ + s*c₁ ≤ B.radius ∧ B.upper ≤ 12*c₁/s ∧ s^ε*R/(6912*(1024/ε^2)) ≤ B.mass := by + obtain hC | hA := homogeneous_family T F Y hTne hT hroot hF hFn hα hγ he he1 hc₁ hc₂ + hcontract hpositive hmin hmax hdmin hdmax hbad hdom hsmall + · obtain ⟨δ,Δ,B,hl,hu,hg⟩ := hC + exact ⟨.inl ⟨δ,Δ,B⟩,empty_subset _,trivial,hl,hu,hg⟩ + · obtain ⟨B,hBT,hl,hu,hg⟩ := hA + refine ⟨.inr (B.weaken hassign),hBT,?_,hl,hu,hg⟩ + intro i + apply hratio + apply hBT + exact mem_image.mpr ⟨i,mem_univ _,rfl⟩ + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry StrongThinTree.Geometry.RadialShell +open scoped Classical +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +lemma homogeneous_scale_bound {q L R : ℕ} (hq : 0 < q) (hL : 0 < L) (hR : 0 < R) + (hk : G.EdgeConnected q) (hX : ∀v, binary (X v)) + (hconn : H.LocallyConnectedReal G q) + (T : Finset (Finset (Fin n))) (F : Finset (Fin n) → Finset (Fin m)) + (idx : Finset (Fin n) → ℤ) (off : Finset (Fin n) → Fin L) + (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hF : ∀t ∈ T, F t ⊆ H.parentBoundary G t) (hFn : ∀t ∈ T, (F t).Nonempty) + {α γ ε ρ : ℝ} (hα : 0 < α) (hγ : 0 < γ) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ l1dist (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hmin : ∀t ∈ T, ∀e ∈ F t, 2^(idx t:ℝ) ≤ ((Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hmax : ∀t ∈ T, ∀e ∈ F t, ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ 4*2^(idx t:ℝ)) + (hdmin : ∀t ∈ T, ∀e ∈ F t, 2^((idx t:ℝ)+(off t).val) ≤ l1dist (X (G.left e)) (X (G.right e))) + (hdmax : ∀t ∈ T, ∀e ∈ F t, l1dist (X (G.left e)) (X (G.right e)) ≤ 4*2^((idx t:ℝ)+(off t).val)) + (hbad : ∀t ∈ T, α*((H.parentBoundary G t).card : ℝ)* + (∑e ∈ H.parentBoundary G t, l1dist (X (G.left e)) (X (G.right e))) ≤ + (∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hdom : ∀t ∈ T, γ*(∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ + (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hsmall : (α*γ/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*γ/32)^(1+2*ε)) + (hratio : ∀t ∈ T, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (H.parentBoundary G t).card) + (hlog : Real.logb 2 (24/(ρ*(α*γ/32)^2)) < R) : + let s := α*γ/32 + let W := ∑t ∈ T, (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((H.parentBoundary G t).card : ℝ) + ((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2)))*(W/(L:ℝ)) ≤ + 2*R*(∑e : Fin m, l1dist (X (G.left e)) (X (G.right e))) := by + let : NeZero L := ⟨Nat.ne_of_gt hL⟩ + let s := α*γ/32 + let w : Finset (Fin n) → ℝ := fun t => + (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/((H.parentBoundary G t).card : ℝ) + let c := s^ε/(6912*(1024/ε^2)) + have hs : 0 < s := by dsimp [s]; positivity + have hc : 0 ≤ c := by dsimp [c]; positivity + obtain ⟨choice,hchoice⟩ := ScaleSelection.select_fibers T idx off w + simp only [Fintype.card_fin] at hchoice + let U := T.filter (fun t => off t=choice (idx t)) + let S := U.image idx + let B : S → Finset (Finset (Fin n)) := fun i => U.filter (fun t => idx t=i.val) + have hBT : ∀i : S, B i ⊆ T := fun i => (filter_subset _ _).trans (filter_subset _ _) + have hBn : ∀i : S, (B i).Nonempty := by + intro i + obtain ⟨t,ht,heq⟩ := mem_image.mp i.property + exact ⟨t,mem_filter.mpr ⟨ht,heq⟩⟩ + have hi : ∀i : S, ∀t ∈ B i, idx t=i.val := fun i t ht => (mem_filter.mp ht).2 + have hoff : ∀i : S, ∀t ∈ B i, off t=choice i.val := by + intro i t ht + have hh := (mem_filter.mp (mem_filter.mp ht).1).2 + change off t=choice (idx t) at hh + rw [hi i t ht] at hh + exact hh + have hex : ∀i : S, ∃P : CapturedFamily H G X (6144/q), + P.owners ⊆ B i ∧ P.Ratio ρ ∧ s*2^(i.val:ℝ) ≤ P.radius ∧ + P.upper ≤ 12*2^(i.val:ℝ)/s ∧ c*(∑t ∈ B i, w t) ≤ P.mass := by + intro i + have hp1 : (0:ℝ) < 2^(i.val:ℝ) := Real.rpow_pos_of_pos (by norm_num) _ + have hp2 : (0:ℝ) < 4*2^((i.val:ℝ)+(choice i.val).val) := by positivity + obtain ⟨P,hP⟩ := capturePackage (B i) F Y (hBn i) ((hBT i).trans hT) + (fun t ht => hroot t (hBT i ht)) (fun t ht => hF t (hBT i ht)) + (fun t ht => hFn t (hBT i ht)) hα hγ he he1 hp1 hp2 hcontract hpositive + (by intro t ht e he; simpa only [hi i t ht] using hmin t (hBT i ht) e he) + (by intro t ht e he; simpa only [hi i t ht] using hmax t (hBT i ht) e he) + (by + intro t ht e he + have hh := hdmin t (hBT i ht) e he + rw [hi i t ht,hoff i t ht] at hh + simpa only [mul_div_cancel_left₀ _ (by norm_num : (4:ℝ)≠0)] using hh) + (by intro t ht e he; simpa only [hi i t ht,hoff i t ht] using hdmax t (hBT i ht) e he) + (fun t ht => hbad t (hBT i ht)) (fun t ht => hdom t (hBT i ht)) hsmall hassign + (fun t ht => hratio t (hBT i ht)) + refine ⟨P,hP.1,hP.2.1,hP.2.2.1,hP.2.2.2.1,?_⟩ + simpa only [c,w,div_mul_eq_mul_div] using hP.2.2.2.2 + let P : S → CapturedFamily H G X (6144/q) := fun i => Classical.choose (hex i) + have hP := fun i => Classical.choose_spec (hex i) + have hbound := CapturedFamily.scale_bound hq hk hX hconn hρ hρsmall hs hR hlog S P + (fun i => (hP i).2.2.1) + (by + intro i + apply (hP i).2.2.2.1.trans + apply div_le_div_of_nonneg_right _ hs.le + exact mul_le_mul_of_nonneg_right (by norm_num : (12:ℝ)≤24) (Real.rpow_nonneg (by norm_num) _)) + (fun i => (hP i).2.1) + (by + intro i j hij + apply Finset.disjoint_left.mpr + intro t hti htj + have he := (hi i t ((hP i).1 hti)).symm.trans (hi j t ((hP j).1 htj)) + exact hij (Subtype.ext he)) + have hfiber : (∑i : S, ∑t ∈ B i, w t) = ∑t ∈ U, w t := by + rw [sum_coe_sort S (fun i => ∑t ∈ U.filter (fun t => idx t=i), w t)] + exact sum_fiberwise_of_maps_to (fun t ht => mem_image_of_mem idx ht) w + have hsum : c*(∑t ∈ U, w t) ≤ ∑i : S, (P i).mass := by + have hh := sum_le_sum (s := univ) (fun i (_ : i ∈ univ) => (hP i).2.2.2.2) + rw [←mul_sum,hfiber] at hh + exact hh + have hgain := (mul_le_mul_of_nonneg_left hchoice hc).trans hsum + have hq0 : 0 ≤ (q:ℝ)/8192 := by positivity + have hh := (mul_le_mul_of_nonneg_left hgain hq0).trans hbound + simpa only [mul_assoc] using hh +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/BitBound.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/BitBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..330b3fbe426632d0d302812d5fcb8fb81d0a69be --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/BitBound.lean @@ -0,0 +1,225 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Realization + +namespace OAI + +/-! Continuation bit bound. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine +lemma QParts.neg {b : ℕ} {q : ℚ} (h : QParts b q) : QParts b (-q) := by + simpa only [QParts,Rat.neg_num,Int.natAbs_neg,Rat.neg_den] using h +lemma QParts.sub {b c : ℕ} {q v : ℚ} (h : QParts b q) (hv : QParts c v) : + QParts (b+c+1) (q-v) := by simpa only [sub_eq_add_neg] using h.add hv.neg +lemma QParts.max {b : ℕ} {q v : ℚ} (h : QParts b q) (hv : QParts b v) : + QParts b (max q v) := by + rcases le_total q v with hl|hl + · simpa only [max_eq_right hl] using hv + · simpa only [max_eq_left hl] using h +end CurrentKS.Realization + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree +open AlgorithmicThinTrees.GraphStack + +structure MeshPoint where + graph : Graph + v : Fin (dimension graph.n graph.m) → ℚ + +def meshPointCode (a : MeshPoint) : Word := prodCode graphCode vectorCode (a.graph,List.ofFn a.v) +abbrev meshView : Realizes meshPointCode (prodCode graphCode vectorCode) + (fun a => (a.graph,List.ofFn a.v)) := + (identity (prodCode graphCode vectorCode)).reindex meshPointCode + (fun a => (a.graph,List.ofFn a.v)) (fun _ => rfl) +private instance poly_meshView : PolyTime meshView := by + unfold meshView + apply poly_reindex + +abbrev meshGraph := meshView.then (first graphCode vectorCode) +abbrev meshVector := meshView.then (second graphCode vectorCode) +def meshRaw : Realizes meshPointCode matrixObjectCode (fun a => ⟨a.graph.n,rawMatrix a.v⟩) := + ((meshGraph.then numVertices).both + ((((meshGraph.then numVertices).both (meshGraph.then numEdges)).both meshVector).then raw)).changeOutput + matrixObjectCode (fun a => ⟨a.graph.n,rawMatrix a.v⟩) (by + intro a + change prodCode natCode matrixCode (a.graph.n, + (List.range a.graph.n).map (fun i => (List.range a.graph.n).map + (fun j => (List.ofFn a.v).getD (j+a.graph.n*i) 0)))=_ + rw [raw_data];rfl) +instance poly_meshRaw : PolyTime meshRaw := by + have hg : PolyTime meshGraph := by unfold meshGraph; apply poly_then + have hv : PolyTime meshVector := by unfold meshVector; apply poly_then + unfold meshRaw + apply poly_changeOutput + +lemma response_parts_bound : ∃b : NaturalPolynomial,∀p : Params,∀i j, + QParts (b.eval (graphCode p.graph).length) + (qresponse (rawMatrix (p.pencil.search (radiusQ p.graph.n p.graph.m) (boundQ p.graph.n p.graph.m) 0)) i j) := by + let a := fun p : Params => MeshPoint.mk p.graph + (p.pencil.search (radiusQ p.graph.n p.graph.m) (boundQ p.graph.n p.graph.m) 0) + have hin := isPoly_pair (isPoly_self (fun p : Params => (graphCode p.graph).length)) search_output_bound + have hout := (RunsPoly.of_poly (meshRaw.then GraphStack.response) a hin).output + obtain ⟨b,hb⟩ := hout + refine ⟨b,?_⟩ + intro p i j + have hh := matrixParts_length (matrixData (qresponse (rawMatrix (a p).v))) + exact (hh _ (List.mem_ofFn.mpr ⟨i,rfl⟩) _ (List.mem_ofFn.mpr ⟨j,rfl⟩)).mono (hb p) + +abbrev coefficients := + let t := extractionGraph.then graphStep + ((constant extractionInputCode ratCode 1).add t).cons + (((constant extractionInputCode ratCode 1).sub t).cons + (((((constant extractionInputCode ratCode 2).mul (extractionCount.then gainProgram)).mul + (extractionCount.then natToRat)).mul t).cons + (t.cons ((extractionGraph.then graphBaseline).then (singleton ratCode))))) + +lemma coefficients_parts_bound : ∃b : NaturalPolynomial,∀G r, + let B := b.eval (extractionInputCode (G,r)).length + QParts B (1+stepQ G.m) ∧ QParts B (1-stepQ G.m) ∧ + QParts B (2*gain r*r*stepQ G.m) ∧ QParts B (stepQ G.m) ∧ QParts B (baselineQ G.m) := by + obtain ⟨b,hb⟩ := (RunsPoly.of_poly coefficients id + (isPoly_self (fun p => (extractionInputCode p).length))).output + refine ⟨b,?_⟩ + intro G r + have hh : ∀q∈[1+stepQ G.m,1-stepQ G.m,2*gain r*r*stepQ G.m,stepQ G.m,baselineQ G.m], + QParts (b.eval (extractionInputCode (G,r)).length) q := by + intro q hq + exact (qparts_length q).mono ((mem_length_le_code _ hq).trans (hb (G,r))) + exact ⟨hh _ (by simp),hh _ (by simp),hh _ (by simp),hh _ (by simp),hh _ (by simp)⟩ + +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open CurrentKS.Realization +open CurrentKS.CleanRoutine KS.W23 +open Stack GraphStack + +variable {n m : ℕ} +def State.Parts (b : ℕ) (a : State n m) : Prop := + QParts b a.scale ∧ QParts b a.quality ∧ (∀i j,QParts b (a.matrix i j)) ∧ + ∀e,QParts b (a.capacity e) +lemma State.Parts.mono {b c : ℕ} {a : State n m} (ha : a.Parts b) (h : b≤c) : a.Parts c := + ⟨ha.1.mono h,ha.2.1.mono h,fun i j => (ha.2.2.1 i j).mono h,fun e => (ha.2.2.2 e).mono h⟩ + +lemma update_parts_bound : ∃P : NaturalPolynomial,∀G : Graph,∀r a b, + a.Parts b → (update G.G r (gain r) a).Parts + (b+P.eval (extractionInputCode (G,r)).length) := by + obtain ⟨c,hc⟩ := coefficients_parts_bound + obtain ⟨v,hv⟩ := search_parts_bound + obtain ⟨w,hw⟩ := response_parts_bound + refine ⟨3*c+v+w+2,?_⟩ + intro G r a b ha + let p : Params := ⟨G,a.scale,baselineQ G.m,stepQ G.m, + target G.m r a.quality (gain r),errorQ G.n G.m,a.capacity⟩ + let L := (extractionInputCode (G,r)).length + let C := c.eval L + let V := v.eval L + let W := w.eval L + have hGl : (graphCode G).length≤L := le_prodCode_left (G,r) + obtain ⟨hplus,hminus,hloss,ht,hbase⟩ := hc G r + have hvec : ∀i,QParts V (search G.G a.scale (target G.m r a.quality (gain r)) a.capacity i) := + fun i => (hv p i).mono (v.eval_mono hGl) + have hresp : ∀i j,QParts W (qresponse (rawMatrix (search G.G a.scale + (target G.m r a.quality (gain r)) a.capacity)) i j) := + fun i j => (hw p i j).mono (w.eval_mono hGl) + change (update G.G r (gain r) a).Parts (b+(3*C+V+W+2)) + refine ⟨(hplus.mul ha.1).mono (by dsimp [C,V,W,L];omega),(ha.2.1.sub hloss).mono (by dsimp [C,V,W,L];omega),?_,?_⟩ + · intro i j + exact ((hminus.mul (ha.2.2.1 i j)).add (ht.mul (hresp i j))).mono (by dsimp [C,V,W,L];omega) + · intro e + change QParts _ (if 0 simpa using ha + | succ k ih => + rw [Function.iterate_succ_apply'] + rw [advance] + split + · simpa only [Nat.add_mul,Nat.one_mul,Nat.add_assoc] using hP G r _ _ ih + · exact ih.mono (by simp only [Nat.add_mul,Nat.one_mul];omega) + +end AlgorithmicThinTrees.MetricTests.RationalStep + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree +open AlgorithmicThinTrees.GraphStack + +lemma loop_parts (a : Loop) : a.state.Parts (loopCode a).length := by + let L := (loopCode a).length + have ht : (loopTailCode a.data.2.2).length≤L := + (le_prodCode_right a.data.2).trans (le_prodCode_right a.data) + have hq := (le_prodCode_right a.data.2.2).trans ht + have harr := (le_prodCode_right a.data.2.2.2).trans hq + have hs := (le_prodCode_left a.data.2.2).trans ht + have hQ := (le_prodCode_left a.data.2.2.2).trans hq + have hmat := (le_prodCode_left a.data.2.2.2.2).trans harr + have hcap := (le_prodCode_right a.data.2.2.2.2).trans harr + refine ⟨(qparts_length _).mono hs,(qparts_length _).mono hQ,?_,?_⟩ + · intro i j + exact ((matrixParts_length (matrixData a.state.matrix)) _ (List.mem_ofFn.mpr ⟨i,rfl⟩) + _ (List.mem_ofFn.mpr ⟨j,rfl⟩)).mono hmat + · intro e + exact (qparts_length _).mono ((mem_length_le_code (List.ofFn a.state.capacity) + (List.mem_ofFn.mpr ⟨e,rfl⟩)).trans hcap) + +lemma loop_parts_length (a : Loop) {b : ℕ} (hb : a.state.Parts b) : + (loopCode a).length ≤ 2*(graphCode a.graph).length+1+2*a.count+1+ + (4*(4*b+7)+3+2*(a.graph.n*(2*(a.graph.n*(2*(4*b+7)+1))+1))+ + a.graph.m*(2*(4*b+7)+1)) := by + have hmat := matrixCode_parts_bound a.state.matrix hb.2.2.1 + have hvec := listCode_length_bound (List.ofFn a.state.capacity) (4*b+7) + (by intro q hq;obtain ⟨e,rfl⟩ := List.mem_ofFn.mp hq;exact (hb.2.2.2 e).length) + rw [List.length_ofFn] at hvec + change (vectorCode (List.ofFn a.state.capacity)).length ≤ _ at hvec + have hs := hb.1.length + have hq := hb.2.1.length + simp only [loopCode,loopDataCode,Loop.data,loopTailCode,prodCode_length,natCode,List.length_replicate] + omega + +instance size_next : IterateSize next := by + obtain ⟨P,hP⟩ := update_parts_bound + let L := fun u : Loop×ℕ => (loopCode u.1).length+u.2 + have ha : IsPoly L (fun u => (loopCode u.1).length) := (isPoly_self L).mono (fun u => Nat.le_add_right _ _) + have hk : IsPoly L Prod.snd := (isPoly_self L).mono (fun u => Nat.le_add_left _ _) + have hg := (RunsPoly.of_poly loopGraph Prod.fst ha).output + have hr := (RunsPoly.of_poly loopCount Prod.fst ha).output + have hr' : IsPoly L (fun u => u.1.count) := by simpa only [natCode,List.length_replicate] using hr + have hpar := isPoly_pair hg hr + have hn := ((RunsPoly.of_poly numVertices (fun u : Loop×ℕ => u.1.graph) hg).output) + have hm := ((RunsPoly.of_poly numEdges (fun u : Loop×ℕ => u.1.graph) hg).output) + have hn' : IsPoly L (fun u => u.1.graph.n) := by simpa only [natCode,List.length_replicate,Graph.data] using hn + have hm' : IsPoly L (fun u => u.1.graph.m) := by simpa only [natCode,List.length_replicate,Graph.data] using hm + have hb := ha.add (hk.mul (hpar.eval P)) + have hrat := ((isPoly_const L 4).mul hb).add (isPoly_const L 7) + have helem := ((isPoly_const L 2).mul hrat).add (isPoly_const L 1) + have hmat := hn'.mul (((isPoly_const L 2).mul (hn'.mul helem)).add (isPoly_const L 1)) + have hvec := hm'.mul helem + have htotal := (((((isPoly_const L 2).mul hg).add (isPoly_const L 1)).add + ((isPoly_const L 2).mul hr')).add (isPoly_const L 1)).add + (((((isPoly_const L 4).mul hrat).add (isPoly_const L 3)).add + ((isPoly_const L 2).mul hmat)).add hvec) + obtain ⟨Q,hQ⟩ := htotal + refine ⟨⟨Q,?_⟩⟩ + intro a k + rw [next_iterate] + apply (loop_parts_length ⟨a.graph,a.count,(advance a.graph.G a.count)^[k] a.state⟩ + (advance_parts hP a.graph a.count (loop_parts a) k)).trans + exact hQ (a,k) + +instance poly_extract : PolyTime extract := by unfold extract; apply poly_congr + +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/CenteredDomain.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/CenteredDomain.lean new file mode 100644 index 0000000000000000000000000000000000000000..8e2e3fae7559ad215db12ebb8d6ce8b461b5a378 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/CenteredDomain.lean @@ -0,0 +1,245 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.Hierarchy + +namespace OAI + +/-! Centered domain. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder Matrix.Norms.Elementwise + +variable {n m : ℕ} + +lemma mul_constant_of_ones {D : Matrix (Fin n) (Fin n) ℝ} (hD0 : D *ᵥ ones n=0) : + D*constantProjection n=0 := by + simp only [constantProjection,mul_smul_comm,mul_vecMulVec,hD0,zero_vecMulVec,smul_zero] + +lemma constant_mul_of_ones {D : Matrix (Fin n) (Fin n) ℝ} (hD : D.IsHermitian) + (hD0 : D *ᵥ ones n=0) : constantProjection n*D=0 := by + have hh := congrArg transpose (mul_constant_of_ones hD0) + simpa only [transpose_mul,constantProjection_symmetric, + (isHermitian_iff_isSymm.mp hD).eq,transpose_zero] using hh + +lemma mul_centering_of_ones {D : Matrix (Fin n) (Fin n) ℝ} (hD0 : D *ᵥ ones n=0) : + D*centering n=D := by + rw [centering,mul_sub,mul_one,mul_constant_of_ones hD0,sub_zero] + +lemma centering_mul_of_ones {D : Matrix (Fin n) (Fin n) ℝ} (hD : D.IsHermitian) + (hD0 : D *ᵥ ones n=0) : centering n*D=D := by + rw [centering,sub_mul,one_mul,constant_mul_of_ones hD hD0,sub_zero] + +lemma centered_eq {D : Matrix (Fin n) (Fin n) ℝ} (hD : D.IsHermitian) + (hD0 : D *ᵥ ones n=0) : centered D=D := by + rw [centered,centering_mul_of_ones hD hD0,mul_centering_of_ones hD0] + +lemma centeredPositive_psd (hn : 0 < n) {D : Matrix (Fin n) (Fin n) ℝ} + (hD : CenteredPositive D) : D.PosSemidef := by + apply PosSemidef.of_dotProduct_mulVec_nonneg hD.1 + intro x + change 0 ≤ qform D x + rw [←centered_eq hD.1 hD.2.1,qform_centered] + by_cases hx : centering n *ᵥ x=0 + · simp [hx,qform] + · exact (hD.2.2 _ (centering_mulVec_sum hn x) hx).le + +lemma regularize_pd (hn : 0 < n) {D : Matrix (Fin n) (Fin n) ℝ} + (hD : CenteredPositive D) : (regularize D).PosDef := by + apply PosDef.of_dotProduct_mulVec_pos (hD.1.add constantProjection_psd.isHermitian) + intro x hx + change 0 < qform (regularize D) x + rw [regularize,qform_add] + by_cases hp : centering n *ᵥ x=0 + · have hs : (∑i, x i) ≠ 0 := by + intro hs + rw [centering_mulVec_of_sum_zero hs] at hp + exact hx hp + have hq : 0 < qform (constantProjection n) x := by + rw [qform_constantProjection] + exact div_pos (sq_pos_of_ne_zero hs) (Nat.cast_pos.mpr hn) + exact add_pos_of_nonneg_of_pos (qform_nonneg (centeredPositive_psd hn hD) _) hq + · have hq : 0 < qform D x := by + rw [←centered_eq hD.1 hD.2.1,qform_centered] + exact hD.2.2 _ (centering_mulVec_sum hn x) hp + exact add_pos_of_pos_of_nonneg hq (qform_nonneg constantProjection_psd _) + +lemma centeredPositive_add_psd {D F : Matrix (Fin n) (Fin n) ℝ} + (hD : CenteredPositive D) (hF : F.PosSemidef) (hF0 : F *ᵥ ones n=0) : + CenteredPositive (D+F) := by + refine ⟨hD.1.add hF.isHermitian,?_,?_⟩ + · simp only [add_mulVec,hD.2.1,hF0,add_zero] + · intro x hx hx0 + rw [qform_add] + exact add_pos_of_pos_of_nonneg (hD.2.2 x hx hx0) (qform_nonneg hF _) + +lemma centered_rankOne {b : Fin n → ℝ} (hb : (∑i, b i)=0) : + centered (vecMulVec b b)=vecMulVec b b := by + apply centered_eq + · simpa only [star_trivial] using (posSemidef_vecMulVec_self_star b).isHermitian + · rw [vecMulVec_mulVec,dotProduct_comm,ones_dot,hb,IsCentralScalar.op_smul_eq_smul,zero_smul] + +lemma centered_regularize {D : Matrix (Fin n) (Fin n) ℝ} (hn : 0 < n) + (hD : D.IsHermitian) (hD0 : D *ᵥ ones n=0) : centered (regularize D)=D := by + have hc0 : centering n*constantProjection n=0 := by + exact mul_constant_of_ones (centering_ones hn) + simp only [centered,regularize,mul_add,hc0,add_zero, + centering_mul_of_ones hD hD0,mul_centering_of_ones hD0] + +lemma centered_resistance_nonneg (G : MultiGraph n m) (hn : 0 < n) + {D : Matrix (Fin n) (Fin n) ℝ} (hD : CenteredPositive D) (e : Fin m) : + 0 ≤ resistance G D e := qform_nonneg (regularize_pd hn hD).inv.posSemidef _ + +lemma centered_inverse_antitone (hn : 0 < n) {D X : Matrix (Fin n) (Fin n) ℝ} + (hD : CenteredPositive D) (hX : CenteredPositive X) (hDX : D ≤ X) (b : Fin n → ℝ) : + qform (inverseOnZeroSum X) b ≤ qform (inverseOnZeroSum D) b := by + apply StrongThinTree.resistance_antitone (regularize_pd hn hX) (regularize_pd hn hD) + have hh : regularize X-regularize D=X-D := by unfold regularize; abel + rw [hh] + exact Matrix.le_iff.mp hDX + +lemma centered_resistance_order (hn : 0 < n) {X : Matrix (Fin n) (Fin n) ℝ} + (hX : CenteredPositive X) {b : Fin n → ℝ} (hb : (∑i, b i)=0) + {a : ℝ} (ha : 0 < a) : + (X-a • vecMulVec b b).PosSemidef ↔ a*qform (inverseOnZeroSum X) b ≤ 1 := by + have heq : a • (a⁻¹ • regularize X-vecMulVec b b)=regularize X-a • vecMulVec b b := by + rw [smul_sub,smul_smul,mul_inv_cancel₀ ha.ne',one_smul] + have hproblem := StrongThinTree.resistance_order (regularize_pd hn hX) b (inv_pos.mpr ha) + constructor + · intro h + have h' : (regularize X-a • vecMulVec b b).PosSemidef := by + convert h.add constantProjection_psd using 1 + unfold regularize + abel + have hinv := h'.smul (inv_nonneg.mpr ha.le) + have hi : a⁻¹ • (regularize X-a • vecMulVec b b)=a⁻¹ • regularize X-vecMulVec b b := by + rw [smul_sub,smul_smul,inv_mul_cancel₀ ha.ne',one_smul] + rw [hi] at hinv + have hh := hproblem.mpr hinv + change qform (inverseOnZeroSum X) b ≤ a⁻¹ at hh + have hm := mul_le_mul_of_nonneg_left hh ha.le + rwa [mul_inv_cancel₀ ha.ne'] at hm + · intro h + have hh : qform (inverseOnZeroSum X) b ≤ a⁻¹ := by + rw [←one_div,le_div_iff₀ ha] + simpa only [mul_comm] using h + have h' := (hproblem.mp hh).smul ha.le + rw [heq] at h' + have hc := centered_psd h' + have he : centered (regularize X-a • vecMulVec b b)=X-a • vecMulVec b b := by + simp only [centered,mul_sub,sub_mul,mul_smul_comm,smul_mul_assoc] + rw [show centering n*regularize X*centering n=X from centered_regularize hn hX.1 hX.2.1] + rw [show centering n*vecMulVec b b*centering n=vecMulVec b b from centered_rankOne hb] + rwa [he] at hc + +def metricDomain (G : MultiGraph n m) : Set (Matrix (Fin n) (Fin n) ℝ) := + {X | X.IsHermitian ∧ X *ᵥ ones n=0 ∧ G.laplacian univ ≤ X ∧ + ∀Z, CenteredTest Z → (X*Z).trace ≤ 3*(G.laplacian univ*Z).trace} + +lemma laplacian_mem_domain (G : MultiGraph n m) : G.laplacian univ ∈ metricDomain G := by + refine ⟨(G.laplacian_psd univ).isHermitian,laplacian_ones G,le_rfl,?_⟩ + intro Z hZ + have hh := trace_pairing_nonneg (G.laplacian_psd univ) hZ.1.1 + linarith only [hh] + +lemma domain_psd (G : MultiGraph n m) {X : Matrix (Fin n) (Fin n) ℝ} + (hX : X ∈ metricDomain G) : X.PosSemidef := + Matrix.nonneg_iff_posSemidef.mp ((Matrix.nonneg_iff_posSemidef.mpr (G.laplacian_psd univ)).trans hX.2.2.1) + +lemma domain_positive (G : MultiGraph n m) (hn : 0 < n) (hG : G.Connected univ) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : X ∈ metricDomain G) : CenteredPositive X := by + refine ⟨hX.1,hX.2.1,?_⟩ + intro x hx hx0 + exact (laplacian_zeroSum_pos G hn hG x hx hx0).trans_le (qform_mono hX.2.2.1 x) + +lemma domain_closed (G : MultiGraph n m) : IsClosed (metricDomain G) := by + have hc : Continuous (fun X : Matrix (Fin n) (Fin n) ℝ => X *ᵥ ones n) := by + fun_prop + have ht : IsClosed {X : Matrix (Fin n) (Fin n) ℝ | ∀Z, CenteredTest Z → + (X*Z).trace ≤ (3:ℝ)*(G.laplacian univ*Z).trace} := by + simp only [show {X : Matrix (Fin n) (Fin n) ℝ | ∀Z, CenteredTest Z → + (X*Z).trace ≤ (3:ℝ)*(G.laplacian univ*Z).trace} = + ⋂ Z : {Z : Matrix (Fin n) (Fin n) ℝ // CenteredTest Z}, + {X | (X*Z.val).trace ≤ 3*(G.laplacian univ*Z.val).trace} by ext; simp] + exact isClosed_iInter fun Z => isClosed_le (trace_pairing_continuous _) continuous_const + exact (isClosed_eq continuous_id.matrix_conjTranspose continuous_id).inter + ((isClosed_eq hc continuous_const).inter ((isClosed_matrixAbove _).inter ht)) + +lemma domain_convex (G : MultiGraph n m) : Convex ℝ (metricDomain G) := by + intro X hX Y hY a b ha hb hab + refine ⟨(hX.1.smul (isSelfAdjoint_iff.mpr (star_trivial a))).add (hY.1.smul (isSelfAdjoint_iff.mpr (star_trivial b))),?_,?_,?_⟩ + · simp only [add_mulVec,smul_mulVec,hX.2.1,hY.2.1,smul_zero,add_zero] + · apply Matrix.le_iff.mpr + have h := ((Matrix.le_iff.mp hX.2.2.1).smul ha).add ((Matrix.le_iff.mp hY.2.2.1).smul hb) + convert h using 1 + rw [smul_sub,smul_sub] + have hh : a • G.laplacian univ+b • G.laplacian univ=G.laplacian univ := by + rw [←add_smul,hab,one_smul] + nth_rw 1 [←hh] + abel + · intro Z hZ + simp only [add_mul,smul_mul_assoc,trace_add,trace_smul,smul_eq_mul] + calc + a*(X*Z).trace+b*(Y*Z).trace ≤ a*(3*(G.laplacian univ*Z).trace)+b*(3*(G.laplacian univ*Z).trace) := + add_le_add (mul_le_mul_of_nonneg_left (hX.2.2.2 Z hZ) ha) (mul_le_mul_of_nonneg_left (hY.2.2.2 Z hZ) hb) + _ = 3*(G.laplacian univ*Z).trace := by rw [←add_mul,hab,one_mul] + +lemma difference_sum (u v : Fin n) : (∑i, difference u v i)=0 := by + simp [difference,point,sum_sub_distrib] + +lemma test_centered (hn : 0 < n) {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : Test Z) : + CenteredTest (centered Z) := by + refine ⟨⟨centered_psd hZ.1,?_⟩,centered_ones hn Z⟩ + intro u v w + simpa only [qform_centered,centering_mulVec_of_sum_zero (difference_sum _ _)] using hZ.2 u v w + +lemma centered_one (hn : 0 < n) : centered (1 : Matrix (Fin n) (Fin n) ℝ)=centering n := by + rw [centered,mul_one,mul_centering_of_ones (centering_ones hn)] + +lemma centering_test (hn : 0 < n) : CenteredTest (centering n) := by + simpa only [centered_one hn] using test_centered hn (test_one (n:=n)) + +lemma domain_trace_bound (G : MultiGraph n m) (hn : 0 < n) {X : Matrix (Fin n) (Fin n) ℝ} + (hX : X ∈ metricDomain G) : X.trace ≤ 3*(G.laplacian univ).trace := by + have hh := hX.2.2.2 _ (centering_test hn) + simpa only [mul_centering_of_ones hX.2.1,mul_centering_of_ones (laplacian_ones G)] using hh + +lemma domain_bounded (G : MultiGraph n m) (hn : 0 < n) : Bornology.IsBounded (metricDomain G) := by + apply isBounded_iff_forall_norm_le.mpr + refine ⟨3*(G.laplacian univ).trace,fun X hX => ?_⟩ + have ht := domain_trace_bound G hn hX + have hp := domain_psd G hX + have hC : 0 ≤ 3*(G.laplacian univ).trace := mul_nonneg (by norm_num) (G.laplacian_psd univ).trace_nonneg + have hd (i : Fin n) : X i i ≤ 3*(G.laplacian univ).trace := + (single_le_sum (fun j _ => hp.diag_nonneg (i:=j)) (mem_univ i)).trans ht + apply (pi_norm_le_iff_of_nonneg hC).mpr + intro i + apply (pi_norm_le_iff_of_nonneg hC).mpr + intro j + simpa only [Real.norm_eq_abs] using psd_entry_bound hp hC hd i j + +lemma domain_compact (G : MultiGraph n m) (hn : 0 < n) : IsCompact (metricDomain G) := + Metric.isCompact_iff_isClosed_bounded.mpr ⟨domain_closed G,domain_bounded G hn⟩ + +lemma shortcut_add_mem_domain {m' : ℕ} (G : MultiGraph n m) (H : MultiGraph n m') + (hn : 0 < n) (hGH : G.laplacian univ ≤ H.laplacian univ) + {D : Matrix (Fin n) (Fin n) ℝ} (hD : CenteredPositive D) + (ht : ∀Z, CenteredTest Z → (D*Z).trace ≤ (G.laplacian univ*Z).trace) : + H.laplacian univ+D ∈ metricDomain H := by + refine ⟨(H.laplacian_psd univ).isHermitian.add hD.1,?_,?_,?_⟩ + · simp only [add_mulVec,laplacian_ones H,hD.2.1,add_zero] + · exact le_add_of_nonneg_right (Matrix.nonneg_iff_posSemidef.mpr (centeredPositive_psd hn hD)) + · intro Z hZ + rw [add_mul,trace_add] + have h1 := ht Z hZ + have h2 := trace_pairing_mono hGH hZ.1.1 + have h3 := trace_pairing_nonneg (H.laplacian_psd univ) hZ.1.1 + linarith only [h1,h2,h3] + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/ConcaveAlternative.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/ConcaveAlternative.lean new file mode 100644 index 0000000000000000000000000000000000000000..ff7f538d0670542e85412caf4d5773d83a85e02f --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/ConcaveAlternative.lean @@ -0,0 +1,73 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Potential.LightPoint +import OAI.Analysis.MatrixSigning.Realization.ScalarRealization +import OAI.Combinatorics.ThinTrees.Duality + +namespace OAI + +/-! Concave alternative. -/ + +section + +namespace AlgorithmicThinTrees.ConvexAlternative +noncomputable section +open Finset +open scoped Classical +variable {E I : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [Fintype I] + +theorem compact_concave_alternative (C : Set E) (hcompact : IsCompact C) + (hne : C.Nonempty) (hconvex : Convex ℝ C) (f : I → E → ℝ) + (hcontinuous : ∀i, ContinuousOn (f i) C) + (hconcave : ∀i, ConcaveOn ℝ C (f i)) + (hinfeasible : ¬∃x ∈ C, ∀i, 0 ≤ f i x) : + ∃ε : ℝ, 0 < ε ∧ ∃w : I → ℝ, (∀i, 0 ≤ w i) ∧ (∑i, w i)=1 ∧ + ∀x ∈ C, (∑i, w i*f i x) ≤ -ε := by + let b : E → ℝ := fun x => ∑i, max 0 (-f i x) + have hbcont : ContinuousOn b C := by + apply continuousOn_finsetSum + intro i _ + exact continuousOn_const.sup (hcontinuous i).neg + have hbpos : ∀x ∈ C, 0 < b x := by + intro x hx + have he : ∃i, f i x < 0 := by + by_contra hh + apply hinfeasible + exact ⟨x,hx,fun i => le_of_not_gt (fun hi => hh ⟨i,hi⟩)⟩ + obtain ⟨i,hi⟩ := he + apply sum_pos' (fun _ _ => le_max_left _ _) + exact ⟨i,mem_univ i,(neg_pos.mpr hi).trans_le (le_max_right _ _)⟩ + obtain ⟨x₀,hx₀,hmin⟩ := hcompact.exists_isMinOn hne hbcont + let ε := b x₀/((Fintype.card I:ℝ)+1) + have hε : 0 < ε := div_pos (hbpos x₀ hx₀) (by positivity) + have heq : ((Fintype.card I:ℝ)+1)*ε=b x₀ := by + dsimp [ε] + exact mul_div_cancel₀ _ (by positivity) + have hno : ¬∃x ∈ C, ∀i, (-f i x)-ε < 0 := by + rintro ⟨x,hx,hh⟩ + have hbx : b x ≤ (Fintype.card I:ℝ)*ε := by + calc + _ ≤ ∑i : I, ε := sum_le_sum (fun i _ => max_le hε.le (by linarith [hh i])) + _ = _ := by simp + have hminx := (isMinOn_iff.mp hmin) x hx + nlinarith only [hbx,hminx,heq,hε] + have hc : ∀i, ConvexOn ℝ C (fun x => -f i x-ε) := by + intro i + refine ⟨hconvex,?_⟩ + intro x hx y hy a d ha hd had + have hh := (hconcave i).2 hx hy ha hd had + change a*f i x+d*f i y ≤ f i (a • x+d • y) at hh + change -f i (a • x+d • y)-ε ≤ a*(-f i x-ε)+d*(-f i y-ε) + nlinarith only [hh,congrArg (fun z : ℝ => z*ε) had] + obtain ⟨w,hw,hws,hbound⟩ := StrongThinTree.Duality.convex_alternative C hconvex hne + (fun i x => -f i x-ε) hc hno + refine ⟨ε,hε,w,hw,hws,?_⟩ + intro x hx + have hh := hbound x hx + simp only [mul_sub,mul_neg,sum_sub_distrib,sum_neg_distrib,←sum_mul,hws,one_mul] at hh + linarith + +end +end AlgorithmicThinTrees.ConvexAlternative +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Coordinates.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Coordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..81de61bc5699ff4f2da25c44551788ec6d0b7159 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Coordinates.lean @@ -0,0 +1,140 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Grid +import OAI.Combinatorics.ThinTrees.Flow.Interior +import OAI.Combinatorics.ThinTrees.Flow.RootedRelaxation + +namespace OAI + +/-! Continuation coordinates. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Orientations + +abbrev Triple (n : ℕ) := Fin n × (Fin n × Fin n) +abbrev Var (n m : ℕ) := + (Fin n × Fin n) ⊕ (Triple n ⊕ ((Fin 3 × Fin m) ⊕ (Fin 2 × (Fin n × Fin m)))) + +def dimension (n m : ℕ) := n*n+(n*(n*n)+(3*m+2*(n*m))) + +def index (n m : ℕ) : Var n m ≃ Fin (dimension n m) := + let et : Triple n ≃ Fin (n*(n*n)) := + ((Equiv.refl (Fin n)).prodCongr finProdFinEquiv).trans finProdFinEquiv + let ef : (Fin 2 × (Fin n × Fin m)) ≃ Fin (2*(n*m)) := + ((Equiv.refl (Fin 2)).prodCongr finProdFinEquiv).trans finProdFinEquiv + let ee := (finProdFinEquiv.sumCongr ef).trans finSumFinEquiv + (finProdFinEquiv.sumCongr ((et.sumCongr ee).trans finSumFinEquiv)).trans finSumFinEquiv + +variable {n m : ℕ} + +def matIndex (i j : Fin n) : Fin (dimension n m) := index n m (.inl (i,j)) +def mulIndex (ijk : Triple n) : Fin (dimension n m) := index n m (.inr (.inl ijk)) +def edgeIndex (p : Fin 3) (e : Fin m) : Fin (dimension n m) := index n m (.inr (.inr (.inl (p,e)))) +def flowIndex (p : Fin 2) (r : Fin n) (e : Fin m) : Fin (dimension n m) := + index n m (.inr (.inr (.inr (p,(r,e))))) + +def rawMatrix {R : Type*} (v : Fin (dimension n m) → R) : Matrix (Fin n) (Fin n) R := + fun i j => v (matIndex i j) +def multiplier {R : Type*} (v : Fin (dimension n m) → R) : DistinctTriple n → R := + fun ijk => v (mulIndex ijk.val) +def y {R : Type*} (v : Fin (dimension n m) → R) : Fin m → R :=fun e => v (edgeIndex 0 e) +def z {R : Type*} (v : Fin (dimension n m) → R) : Fin m → R :=fun e => v (edgeIndex 1 e) +def flowX {R : Type*} (v : Fin (dimension n m) → R) : Fin m → R :=fun e => v (edgeIndex 2 e) +def flowA {R : Type*} (v : Fin (dimension n m) → R) : Fin n → Fin m → R :=fun r e => v (flowIndex 0 r e) +def flowB {R : Type*} (v : Fin (dimension n m) → R) : Fin n → Fin m → R :=fun r e => v (flowIndex 1 r e) + +def step (v : Fin (dimension n m) → ℝ) : StepFree n m := + (rawMatrix v,multiplier v,y v,z v) +def flow (v : Fin (dimension n m) → ℝ) : FlowPoint n m := + ⟨flowX v,flowA v,flowB v⟩ + +def rational (v : Fin (dimension n m) → ℚ) : StepRational n m := + (rawMatrix v,multiplier v,y v,z v) + +lemma rational_real (v : Fin (dimension n m) → ℚ) : + (rational v).real=step (fun i => (v i:ℝ)) := rfl + +noncomputable def encode (c : StepFree n m) (F : FlowPoint n m) : Fin (dimension n m) → ℝ := + fun k => match (index n m).symm k with + | .inl (i,j) => c.1 i j + | .inr (.inl ijk) => + if h : ijk.1 ≠ ijk.2.1 ∧ ijk.2.1 ≠ ijk.2.2 ∧ ijk.1 ≠ ijk.2.2 then c.multiplier ⟨ijk,h⟩ else 0 + | .inr (.inr (.inl (p,e))) => if p=0 then c.y e else if p=1 then c.z e else F.x e + | .inr (.inr (.inr (p,(r,e)))) => if p=0 then F.a r e else F.b r e + +@[simp] lemma encode_mat (c : StepFree n m) (F : FlowPoint n m) (i j : Fin n) : + encode c F (matIndex i j)=c.1 i j := by simp [encode,matIndex] +@[simp] lemma encode_mul (c : StepFree n m) (F : FlowPoint n m) (ijk : DistinctTriple n) : + encode c F (mulIndex ijk.val)=c.multiplier ijk := by simp [encode,mulIndex,ijk.property] +@[simp] lemma encode_y (c : StepFree n m) (F : FlowPoint n m) (e : Fin m) : + encode c F (edgeIndex 0 e)=c.y e := by simp [encode,edgeIndex] +@[simp] lemma encode_z (c : StepFree n m) (F : FlowPoint n m) (e : Fin m) : + encode c F (edgeIndex 1 e)=c.z e := by simp [encode,edgeIndex] +@[simp] lemma encode_x (c : StepFree n m) (F : FlowPoint n m) (e : Fin m) : + encode c F (edgeIndex 2 e)=F.x e := by simp [encode,edgeIndex] +@[simp] lemma encode_a (c : StepFree n m) (F : FlowPoint n m) (r : Fin n) (e : Fin m) : + encode c F (flowIndex 0 r e)=F.a r e := by simp [encode,flowIndex] +@[simp] lemma encode_b (c : StepFree n m) (F : FlowPoint n m) (r : Fin n) (e : Fin m) : + encode c F (flowIndex 1 r e)=F.b r e := by simp [encode,flowIndex] + +lemma encode_step (c : StepFree n m) (F : FlowPoint n m) : step (encode c F)=c := by + apply Prod.ext + · funext i j + exact encode_mat c F i j + · apply Prod.ext + · funext ijk + exact encode_mul c F ijk + · apply Prod.ext + · funext e + exact encode_y c F e + · funext e + exact encode_z c F e +lemma encode_flow (c : StepFree n m) (F : FlowPoint n m) : flow (encode c F)=F := by + have hx : flowX (encode c F)=F.x := funext (encode_x c F) + have ha : flowA (encode c F)=F.a := funext (fun r => funext (encode_a c F r)) + have hb : flowB (encode c F)=F.b := funext (fun r => funext (encode_b c F r)) + simp only [flow,hx,ha,hb] + +lemma close_step_flow (c : StepFree n m) (F : FlowPoint n m) + (v : Fin (dimension n m) → ℝ) {ρ : ℝ} + (h : ∀i, |v i-encode c F i| ≤ ρ) : + (step v).Close c ρ ∧ (flow v).Close F ρ := by + refine ⟨⟨?_,?_,?_,?_⟩,⟨?_,?_,?_⟩⟩ + · intro i j + simpa only [step,flow,StepFree.multiplier,StepFree.y,StepFree.z,rawMatrix,multiplier,y,z,flowX,flowA,flowB,encode_mat] using h (matIndex i j) + · intro ijk + simpa only [step,flow,StepFree.multiplier,StepFree.y,StepFree.z,rawMatrix,multiplier,y,z,flowX,flowA,flowB,encode_mul] using h (mulIndex ijk.val) + · intro e + simpa only [step,flow,StepFree.multiplier,StepFree.y,StepFree.z,rawMatrix,multiplier,y,z,flowX,flowA,flowB,encode_y] using h (edgeIndex 0 e) + · intro e + simpa only [step,flow,StepFree.multiplier,StepFree.y,StepFree.z,rawMatrix,multiplier,y,z,flowX,flowA,flowB,encode_z] using h (edgeIndex 1 e) + · intro e + simpa only [step,flow,StepFree.multiplier,StepFree.y,StepFree.z,rawMatrix,multiplier,y,z,flowX,flowA,flowB,encode_x] using h (edgeIndex 2 e) + · intro r e + simpa only [step,flow,StepFree.multiplier,StepFree.y,StepFree.z,rawMatrix,multiplier,y,z,flowX,flowA,flowB,encode_a] using h (flowIndex 0 r e) + · intro r e + simpa only [step,flow,StepFree.multiplier,StepFree.y,StepFree.z,rawMatrix,multiplier,y,z,flowX,flowA,flowB,encode_b] using h (flowIndex 1 r e) + +lemma encode_bound (c : StepFree n m) (F : FlowPoint n m) {R : ℝ} + (hR : 0 ≤ R) (hc : c.Bounded R) (hF : F.Bounded R) : ∀i, |encode c F i| ≤ R := by + intro i + unfold encode + cases h : (index n m).symm i with + | inl ij => exact hc.1 ij.1 ij.2 + | inr w => + cases w with + | inl ijk => dsimp only; split_ifs <;> first | exact hc.2.1 _ | simpa using hR + | inr w => + cases w with + | inl pe => dsimp only; split_ifs <;> first | exact hc.2.2.1 _ | exact hc.2.2.2 _ | exact hF.1 _ + | inr pre => dsimp only; split_ifs <;> first | exact hF.2.1 _ _ | exact hF.2.2 _ _ + +lemma dimension_bound (n m : ℕ) : dimension n m ≤ (n+m+2)^3 := by + unfold dimension + nlinarith [Nat.zero_le (n*n*m),Nat.zero_le (n*m*m),Nat.zero_le (m*m*m)] + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Domain.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Domain.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b494b1cb93e60499db99d66262f551cc90d788a --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Domain.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.PartitionGeometry +import OAI.Combinatorics.ThinTrees.Continuation.Ramp + +namespace OAI + +/-! Continuation domain. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder Matrix.Norms.Elementwise + +variable {n m : ℕ} + +abbrev ResponseSpace (n m : ℕ) := Matrix (Fin n) (Fin n) ℝ × (Fin m → ℝ) + +def admissible (H : MultiGraph n m) (s : ℝ) (u : Fin m → ℝ) : Set (ResponseSpace n m) := + {x | x.1 ∈ metricDomain H ∧ (∀e, 0 ≤ x.2 e ∧ x.2 e ≤ 1) ∧ + ∀e, 0 < u e → (6*s*x.2 e) • vecMulVec (H.incidence e) (H.incidence e) ≤ x.1} + +lemma admissible_nonempty (H : MultiGraph n m) (s : ℝ) (u : Fin m → ℝ) : + (admissible H s u).Nonempty := by + refine ⟨(H.laplacian univ,0),laplacian_mem_domain H,fun e => ?_,?_⟩ + · exact ⟨le_rfl,by norm_num⟩ + · intro e _ + simp only [Pi.zero_apply,mul_zero,zero_smul] + exact Matrix.nonneg_iff_posSemidef.mpr (H.laplacian_psd univ) + +lemma admissible_closed (H : MultiGraph n m) (s : ℝ) (u : Fin m → ℝ) : + IsClosed (admissible H s u) := by + have hY : IsClosed {x : ResponseSpace n m | x.1 ∈ metricDomain H} := + (domain_closed H).preimage continuous_fst + have hy : IsClosed {x : ResponseSpace n m | ∀e, 0 ≤ x.2 e ∧ x.2 e ≤ 1} := by + simp only [Set.ofPred_forall] + apply isClosed_iInter + intro e + exact (isClosed_le continuous_const ((continuous_apply e).comp continuous_snd)).inter + (isClosed_le ((continuous_apply e).comp continuous_snd) continuous_const) + have hl : IsClosed {x : ResponseSpace n m | ∀e, 0 < u e → + (6*s*x.2 e) • vecMulVec (H.incidence e) (H.incidence e) ≤ x.1} := by + simp only [Set.ofPred_forall] + apply isClosed_iInter + intro e + apply isClosed_iInter + intro _ + have hc : Continuous (fun x : ResponseSpace n m => + x.1-(6*s*x.2 e) • vecMulVec (H.incidence e) (H.incidence e)) := by fun_prop + convert (isClosed_matrixAbove (0 : Matrix (Fin n) (Fin n) ℝ)).preimage hc using 1 + ext x + simp only [Set.mem_preimage,Set.mem_ofPred_eq,sub_nonneg] + exact hY.inter (hy.inter hl) + +lemma admissible_compact (H : MultiGraph n m) (hn : 0 < n) (s : ℝ) (u : Fin m → ℝ) : + IsCompact (admissible H s u) := by + have hb : IsCompact {y : Fin m → ℝ | ∀e, y e ∈ Set.Icc (0:ℝ) 1} := + isCompact_pi_infinite (fun _ => isCompact_Icc) + apply ((domain_compact H hn).prod hb).of_isClosed_subset (admissible_closed H s u) + intro x hx + exact ⟨hx.1,hx.2.1⟩ + +lemma admissible_convex (H : MultiGraph n m) (s : ℝ) (u : Fin m → ℝ) : + Convex ℝ (admissible H s u) := by + intro x hx z hz a b ha hb hab + refine ⟨domain_convex H hx.1 hz.1 ha hb hab,?_,?_⟩ + · intro e + change 0 ≤ a*x.2 e+b*z.2 e ∧ a*x.2 e+b*z.2 e ≤ 1 + refine ⟨add_nonneg (mul_nonneg ha (hx.2.1 e).1) (mul_nonneg hb (hz.2.1 e).1),?_⟩ + have h1 := mul_le_mul_of_nonneg_left (hx.2.1 e).2 ha + have h2 := mul_le_mul_of_nonneg_left (hz.2.1 e).2 hb + nlinarith only [h1,h2,hab] + · intro e he + apply Matrix.le_iff.mpr + have h1 := (Matrix.le_iff.mp (hx.2.2 e he)).smul ha + have h2 := (Matrix.le_iff.mp (hz.2.2 e he)).smul hb + convert h1.add h2 using 1 + change a • x.1+b • z.1-(6*s*(a*x.2 e+b*z.2 e)) • + vecMulVec (H.incidence e) (H.incidence e)=_ + simp only [smul_sub,smul_smul] + module + +lemma lowerCapacity_continuous (κ t u : ℝ) : Continuous (lowerCapacity κ t u) := by + unfold lowerCapacity + split_ifs + · fun_prop + · exact continuous_const + +lemma lowerCapacity_concave (κ t u : ℝ) : ConcaveOn ℝ Set.univ (lowerCapacity κ t u) := by + refine ⟨convex_univ,?_⟩ + intro x _ y _ a b ha hb hab + change a*lowerCapacity κ t u x+b*lowerCapacity κ t u y ≤ + lowerCapacity κ t u (a*x+b*y) + unfold lowerCapacity + split_ifs with hu + · have h1 := mul_le_mul_of_nonneg_left (min_le_left (1:ℝ) (u+t*(5*x-4))) ha + have h2 := mul_le_mul_of_nonneg_left (min_le_left (1:ℝ) (u+t*(5*y-4))) hb + have h3 := mul_le_mul_of_nonneg_left (min_le_right (1:ℝ) (u+t*(5*x-4))) ha + have h4 := mul_le_mul_of_nonneg_left (min_le_right (1:ℝ) (u+t*(5*y-4))) hb + have hc : a*κ+b*κ=κ := by rw [←add_mul,hab,one_mul] + have hlin : a*(u+t*(5*x-4))+b*(u+t*(5*y-4))=u+t*(5*(a*x+b*y)-4) := by + calc + _ = (a+b)*(u-4*t)+5*t*(a*x+b*y) := by ring + _ = _ := by rw [hab]; ring + conv_rhs => rw [add_min] + apply le_min <;> nlinarith only [h1,h2,h3,h4,hc,hlin,hab] + · rw [←add_mul,hab,one_mul] + +def responseSlack (H : MultiGraph n m) (κ t Q : ℝ) (u : Fin m → ℝ) + (p : Setoid (Fin n)) (x : ResponseSpace n m) : ℝ := + Partitions.slack H.left H.right (fun e => lowerCapacity κ t (u e) (x.2 e)) Q p + +lemma responseSlack_continuous (H : MultiGraph n m) (κ t Q : ℝ) (u : Fin m → ℝ) + (p : Setoid (Fin n)) : Continuous (responseSlack H κ t Q u p) := by + unfold responseSlack Partitions.slack Partitions.capacity + apply Continuous.sub _ continuous_const + apply continuous_finsetSum + intro e _ + exact ((lowerCapacity_continuous κ t (u e)).comp + ((continuous_apply e).comp continuous_snd)).mul_const _ + +lemma responseSlack_concave (H : MultiGraph n m) (κ t Q s : ℝ) (u : Fin m → ℝ) + (p : Setoid (Fin n)) : ConcaveOn ℝ (admissible H s u) (responseSlack H κ t Q u p) := by + refine ⟨admissible_convex H s u,?_⟩ + intro x hx z hz a b ha hb hab + have hsum := sum_le_sum (s:=Partitions.crossing H p) (fun e (_ : e ∈ Partitions.crossing H p) => + (lowerCapacity_concave κ t (u e)).2 (Set.mem_univ (x.2 e)) (Set.mem_univ (z.2 e)) ha hb hab) + simp only [smul_eq_mul,←mul_sum,sum_add_distrib] at hsum + change a*responseSlack H κ t Q u p x+b*responseSlack H κ t Q u p z ≤ + responseSlack H κ t Q u p (a • x+b • z) + unfold responseSlack Partitions.slack + rw [Partitions.capacity_eq_sum,Partitions.capacity_eq_sum,Partitions.capacity_eq_sum] + have hc : a*(Q*((Partitions.partCount p:ℝ)-1))+b*(Q*((Partitions.partCount p:ℝ)-1))= + Q*((Partitions.partCount p:ℝ)-1) := by rw [←add_mul,hab,one_mul] + change a*((∑e ∈ Partitions.crossing H p, lowerCapacity κ t (u e) (x.2 e))- + Q*((Partitions.partCount p:ℝ)-1))+ + b*((∑e ∈ Partitions.crossing H p, lowerCapacity κ t (u e) (z.2 e))- + Q*((Partitions.partCount p:ℝ)-1)) ≤ + (∑e ∈ Partitions.crossing H p, lowerCapacity κ t (u e) (a*x.2 e+b*z.2 e))- + Q*((Partitions.partCount p:ℝ)-1) + nlinarith only [hsum,hc] + +lemma responseSlack_submodular (H : MultiGraph n m) {κ t Q s : ℝ} (u : Fin m → ℝ) + (ht : 0 ≤ t) (hκ : 4*t ≤ κ) (hQ : 0 ≤ Q) {x : ResponseSpace n m} + (hx : x ∈ admissible H s u) (p q : Setoid (Fin n)) : + responseSlack H κ t Q u (p ⊓ q) x+responseSlack H κ t Q u (p ⊔ q) x ≤ + responseSlack H κ t Q u p x+responseSlack H κ t Q u q x := + Partitions.slack_submodular H.left H.right _ + (fun e => lowerCapacity_nonneg ht (hx.2.1 e).1 hκ) hQ p q + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Encoding.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Encoding.lean new file mode 100644 index 0000000000000000000000000000000000000000..e673d03a2ff72b469cb2832ed76cf65d942e35b5 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Encoding.lean @@ -0,0 +1,189 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Domain +import OAI.Combinatorics.ThinTrees.Metric.ConeRepresentation + +namespace OAI + +/-! Continuation encoding. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical MatrixOrder Matrix.Norms.Elementwise + +variable {n m : ℕ} + +def responseMatrix (A : Matrix (Fin n) (Fin n) ℝ) : Matrix (Fin n) (Fin n) ℝ := + centered ((1/2 : ℝ) • (A+Aᵀ)) + +lemma responseMatrix_hermitian (A : Matrix (Fin n) (Fin n) ℝ) : + (responseMatrix A).IsHermitian := by + apply isHermitian_iff_isSymm.mpr + simp only [responseMatrix,centered,IsSymm,transpose_mul,transpose_smul,transpose_add, + transpose_transpose,centering_symmetric] + rw [add_comm Aᵀ A,mul_assoc] + +lemma responseMatrix_ones (hn : 0 < n) (A : Matrix (Fin n) (Fin n) ℝ) : + responseMatrix A *ᵥ ones n=0 := centered_ones hn _ + +lemma responseMatrix_fixed {A : Matrix (Fin n) (Fin n) ℝ} + (hA : A.IsHermitian) (hA0 : A *ᵥ ones n=0) : responseMatrix A=A := by + rw [responseMatrix,(isHermitian_iff_isSymm.mp hA).eq, + show (1/2 : ℝ) • (A+A)=A by module,centered_eq hA hA0] + +lemma responseMatrix_add (A B : Matrix (Fin n) (Fin n) ℝ) : + responseMatrix (A+B)=responseMatrix A+responseMatrix B := by + simp only [responseMatrix,transpose_add,centered,smul_add,mul_add,add_mul] + abel + +lemma responseMatrix_smul (c : ℝ) (A : Matrix (Fin n) (Fin n) ℝ) : + responseMatrix (c • A)=c • responseMatrix A := by + simp only [responseMatrix,transpose_smul,←smul_add,smul_comm (1/2:ℝ) c, + centered,mul_smul_comm,smul_mul_assoc] + +lemma responseMatrix_sub (A B : Matrix (Fin n) (Fin n) ℝ) : + responseMatrix (A-B)=responseMatrix A-responseMatrix B := by + simp only [responseMatrix,transpose_sub,centered,smul_sub,mul_sub,sub_mul,smul_add,mul_add,add_mul] + abel + +abbrev StepFree (n m : ℕ) := + Matrix (Fin n) (Fin n) ℝ × (DistinctTriple n → ℝ) × (Fin m → ℝ) × (Fin m → ℝ) + +namespace StepFree + +def matrix (x : StepFree n m) : Matrix (Fin n) (Fin n) ℝ := responseMatrix x.1 +def multiplier (x : StepFree n m) : DistinctTriple n → ℝ := x.2.1 +def y (x : StepFree n m) : Fin m → ℝ := x.2.2.1 +def z (x : StepFree n m) : Fin m → ℝ := x.2.2.2 + +def capacities (κ : ℝ) (u : Fin m → ℝ) (x : StepFree n m) : Fin m → ℝ := + fun e => if 0 < u e then x.z e else κ + +def lowerPencil (H : MultiGraph n m) (x : StepFree n m) := x.matrix-H.laplacian univ +def upperPencil (H : MultiGraph n m) (x : StepFree n m) := + (3 : ℝ) • H.laplacian univ-x.matrix-∑ijk, x.multiplier ijk • triangleGenerator ijk + +def edgePencil (H : MultiGraph n m) (s : ℝ) (x : StepFree n m) (e : Fin m) := + x.matrix-(6*s*x.y e) • vecMulVec (H.incidence e) (H.incidence e) + +lemma matrix_combo (a b : ℝ) (x w : StepFree n m) : + (a • x+b • w).matrix=a • x.matrix+b • w.matrix := by + change responseMatrix (a • x.1+b • w.1)=_ + rw [responseMatrix_add,responseMatrix_smul,responseMatrix_smul] + rfl + +lemma lowerPencil_combo (H : MultiGraph n m) (a b : ℝ) (hab : a+b=1) (x w : StepFree n m) : + lowerPencil H (a • x+b • w)=a • lowerPencil H x+b • lowerPencil H w := by + rw [lowerPencil,matrix_combo,lowerPencil,lowerPencil] + have he : a • H.laplacian univ+b • H.laplacian univ=H.laplacian univ := by rw [←add_smul,hab,one_smul] + simp only [smul_sub] + conv_lhs => rw [←he] + abel + +lemma upperPencil_combo (H : MultiGraph n m) (a b : ℝ) (hab : a+b=1) (x w : StepFree n m) : + upperPencil H (a • x+b • w)=a • upperPencil H x+b • upperPencil H w := by + have he : a • H.laplacian univ+b • H.laplacian univ=H.laplacian univ := by rw [←add_smul,hab,one_smul] + simp only [upperPencil,matrix_combo,multiplier,Prod.fst_add,Prod.smul_fst, + Prod.snd_add,Prod.smul_snd,Pi.add_apply,Pi.smul_apply,smul_eq_mul, + add_smul,mul_smul,sum_add_distrib,←smul_sum,smul_sub] + have h3 : (3 : ℝ) • H.laplacian univ = + a • (3 : ℝ) • H.laplacian univ+b • (3 : ℝ) • H.laplacian univ := by + rw [←add_smul,hab,one_smul] + conv_lhs => rw [h3] + module + +lemma edgePencil_combo (H : MultiGraph n m) (s a b : ℝ) (x w : StepFree n m) (e : Fin m) : + edgePencil H s (a • x+b • w) e=a • edgePencil H s x e+b • edgePencil H s w e := by + simp only [edgePencil,matrix_combo,y,Prod.fst_add,Prod.smul_fst,Prod.snd_add, + Prod.smul_snd,Pi.add_apply,Pi.smul_apply,smul_eq_mul,smul_sub,smul_smul] + module + +lemma capacities_combo (κ a b : ℝ) (hab : a+b=1) (u : Fin m → ℝ) (x w : StepFree n m) : + capacities κ u (a • x+b • w)=a • capacities κ u x+b • capacities κ u w := by + ext e + simp only [capacities,z,Prod.snd_add,Prod.smul_snd,Pi.add_apply,Pi.smul_apply,smul_eq_mul] + split_ifs + · rfl + · rw [←add_mul,hab,one_mul] + +end StepFree + +def stepCore (H : MultiGraph n m) (s κ t : ℝ) (u : Fin m → ℝ) : Set (StepFree n m) := + {x | (x.lowerPencil H).PosSemidef ∧ (x.upperPencil H).PosSemidef ∧ + (∀ijk, 0 ≤ x.multiplier ijk) ∧ (∀e, x.y e ∈ Set.Icc (0 : ℝ) 1) ∧ + (∀e, x.z e ∈ Set.Icc 0 (κ+1)) ∧ + (∀e, 0 < u e → (x.edgePencil H s e).PosSemidef ∧ + x.z e ≤ κ+u e+t*(5*x.y e-4))} + +def stepFeasible (H : MultiGraph n m) (s κ t q : ℝ) (u : Fin m → ℝ) : Set (StepFree n m) := + {x | x ∈ stepCore H s κ t u ∧ ∀p, 0 ≤ slack H.left H.right (x.capacities κ u) q p} + +lemma stepCore_domain (H : MultiGraph n m) (hn : 0 < n) + {s κ t : ℝ} {u : Fin m → ℝ} {x : StepFree n m} (hx : x ∈ stepCore H s κ t u) : + x.matrix ∈ metricDomain H := by + apply (metricDomain_iff_lmi H hn (responseMatrix_hermitian x.1) (responseMatrix_ones hn x.1)).mpr + exact ⟨Matrix.le_iff.mpr hx.1,x.multiplier,hx.2.2.1,hx.2.1⟩ + +lemma stepCore_admissible (H : MultiGraph n m) (hn : 0 < n) + {s κ t : ℝ} {u : Fin m → ℝ} {x : StepFree n m} (hx : x ∈ stepCore H s κ t u) : + (x.matrix,x.y) ∈ admissible H s u := + ⟨stepCore_domain H hn hx,hx.2.2.2.1,fun e he => Matrix.le_iff.mpr ((hx.2.2.2.2.2 e he).1)⟩ + +lemma stepCore_capacity_le (H : MultiGraph n m) + {s κ t : ℝ} {u : Fin m → ℝ} {x : StepFree n m} (hx : x ∈ stepCore H s κ t u) (e : Fin m) : + x.capacities κ u e ≤ lowerCapacity κ t (u e) (x.y e) := by + unfold StepFree.capacities lowerCapacity + split_ifs with he + · rw [add_min] + exact le_min (hx.2.2.2.2.1 e).2 (by simpa only [add_assoc] using (hx.2.2.2.2.2 e he).2) + · exact le_rfl + +lemma stepFeasible_response (H : MultiGraph n m) (hn : 0 < n) + {s κ t q : ℝ} {u : Fin m → ℝ} {x : StepFree n m} (hx : x ∈ stepFeasible H s κ t q u) : + (x.matrix,x.y) ∈ admissible H s u ∧ + ∀p, 0 ≤ responseSlack H κ t q u p (x.matrix,x.y) := by + refine ⟨stepCore_admissible H hn hx.1,fun p => (hx.2 p).trans ?_⟩ + unfold responseSlack slack capacity + apply sub_le_sub_right + exact sum_le_sum (fun e _ => mul_le_mul_of_nonneg_right + (stepCore_capacity_le H hx.1 e) (crossingIndicator_nonneg _ _ _)) + +lemma response_to_stepFeasible (H : MultiGraph n m) (hn : 0 < n) + {s κ t q : ℝ} {u : Fin m → ℝ} (ht : 0 ≤ t) (hκt : 4*t ≤ κ) + {w : ResponseSpace n m} (hw : w ∈ admissible H s u) + (hp : ∀p, 0 ≤ responseSlack H κ t q u p w) : + ∃x ∈ stepFeasible H s κ t q u, x.matrix=w.1 ∧ x.y=w.2 := by + obtain ⟨_,lam,hlam,hP⟩ := (metricDomain_iff_lmi H hn hw.1.1 hw.1.2.1).mp hw.1 + let z : Fin m → ℝ := fun e => lowerCapacity κ t (u e) (w.2 e) + let x : StepFree n m := (w.1,lam,w.2,z) + have hmat : x.matrix=w.1 := responseMatrix_fixed hw.1.1 hw.1.2.1 + have hcap : x.capacities κ u=z := by + ext e + simp only [StepFree.capacities,StepFree.z,x] + split_ifs with he + · rfl + · simp only [z,lowerCapacity,ite_eq_right he] + refine ⟨x,⟨?_,?_⟩,hmat,rfl⟩ + · refine ⟨?_,?_,hlam,hw.2.1,?_,?_⟩ + · simpa only [StepFree.lowerPencil,hmat] using Matrix.le_iff.mp hw.1.2.2.1 + · simpa only [StepFree.upperPencil,hmat,StepFree.multiplier,x] using hP + · intro e + exact ⟨lowerCapacity_nonneg ht (hw.2.1 e).1 hκt,lowerCapacity_le⟩ + · intro e he + refine ⟨?_,?_⟩ + · simpa only [StepFree.edgePencil,hmat,StepFree.y,x] using Matrix.le_iff.mp (hw.2.2 e he) + · change lowerCapacity κ t (u e) (w.2 e) ≤ _ + rw [lowerCapacity,ite_eq_left he] + change κ+min 1 (u e+t*(5*w.2 e-4)) ≤ κ+u e+t*(5*w.2 e-4) + linarith only [min_le_right (1 : ℝ) (u e+t*(5*w.2 e-4))] + · intro p + rw [hcap] + exact hp p + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Feasibility.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Feasibility.lean new file mode 100644 index 0000000000000000000000000000000000000000..af684698d96e3e332644a8718513ce7d0c369c1e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Feasibility.lean @@ -0,0 +1,217 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Domain +import OAI.Combinatorics.ThinTrees.Continuation.Gains +import OAI.Combinatorics.ThinTrees.Continuation.PartitionResponse +import OAI.Combinatorics.ThinTrees.Continuation.PartitionUncrossing + +namespace OAI + +/-! Continuation feasibility. -/ + +section + +namespace AlgorithmicThinTrees.Partitions +noncomputable section +open Finset +open scoped Classical + +lemma slack_top {V E : Type*} [Fintype V] [Nonempty V] [Fintype E] + (left right : E → V) (w : E → ℝ) (Q : ℝ) : + slack left right w Q ⊤=0 := by + simp [slack,capacity,crossingIndicator,partCount_top] + +end +end AlgorithmicThinTrees.Partitions + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Finset Matrix StrongThinTree StrongThinTree.MultiGraph +open Partitions +open scoped Classical MatrixOrder Matrix.Norms.Elementwise + +variable {n m : ℕ} + +lemma capacity_change_worst (F : Finset (Fin m)) (u : Fin m → ℝ) + (hu0 : ∀e, 0 ≤ u e) (hu1 : ∀e, u e ≤ 1) (good : Fin m → Prop) + {κ t : ℝ} (ht : 0 ≤ t) : + -4*t*m ≤ (∑e ∈ F, lowerCapacity κ t (u e) (booleanResponse good e))- + (∑e ∈ F, (u e+κ)) := by + have hh := capacity_change_loss F u hu0 hu1 good (κ:=κ) ht + have hcard : (((F ∩ active u).filter (fun e => ¬good e)).card:ℝ) ≤ m := by + exact_mod_cast (show ((F ∩ active u).filter (fun e => ¬good e)).card ≤ m by + simpa only [Fintype.card_fin] using card_le_univ ((F ∩ active u).filter (fun e => ¬good e))) + have hm := mul_le_mul_of_nonpos_left hcard (by linarith : -4*t ≤ 0) + exact hm.trans hh + +lemma continuation_fraction_cutoff : + ∃r0 : ℕ, 8 ≤ r0 ∧ ∀r : ℕ, r0 ≤ r → + (r:ℝ)^(-1/3:ℝ) ≤ 1/10 ∧ 32*(r:ℝ)^(-1/3:ℝ) ≤ (r:ℝ)^(-1/8:ℝ) := by + open Filter in + have he : ∀ᶠ x : ℝ in atTop, + 10*x^(-1/3:ℝ) ≤ x^(0:ℝ) ∧ 32*x^(-1/3:ℝ) ≤ x^(-1/8:ℝ) := + (ShortcutNumeric.eventually_const_mul_rpow_le_rpow 10 (by norm_num)).and + (ShortcutNumeric.eventually_const_mul_rpow_le_rpow 32 (by norm_num)) + open Filter in + have heN : ∀ᶠ r : ℕ in atTop, + 10*(r:ℝ)^(-1/3:ℝ) ≤ (r:ℝ)^(0:ℝ) ∧ + 32*(r:ℝ)^(-1/3:ℝ) ≤ (r:ℝ)^(-1/8:ℝ) := + (tendsto_natCast_atTop_atTop : Tendsto (fun r : ℕ => (r:ℝ)) atTop atTop).eventually he + obtain ⟨r0,hr0⟩ := heN.exists_forall_of_atTop + refine ⟨max 8 r0,le_max_left _ _,?_⟩ + intro r hr + have hh := hr0 r ((le_max_right _ _).trans hr) + refine ⟨?_,hh.2⟩ + rw [Real.rpow_zero] at hh + linarith only [hh.1] + +lemma chain_continuation_feasible (H : MultiGraph n m) (hn : 2 ≤ n) (_hconn : H.Connected univ) + (u : Fin m → ℝ) (hu0 : ∀e, 0 ≤ u e) (hu1 : ∀e, u e ≤ 1) + {r : ℕ} {κ t Q s g : ℝ} + (hr : 8 ≤ r) (hκ : 0 ≤ κ) (hκm : κ*m < 1) + (ht : 0 ≤ t) (ht1 : t ≤ 1/2) (htm : 4*t*m ≤ 1) + (hQ : 3*(r:ℝ)/4 ≤ Q) (hQr : Q ≤ r) (hg : 0 ≤ g) + (hε : (r:ℝ)^(-1/3:ℝ) ≤ 1/10) (hεg : 32*(r:ℝ)^(-1/3:ℝ) ≤ g) + (_hs : 0 < s) (_hsr : s ≤ (r:ℝ)^(1/4:ℝ)) + (hinv : ∀p, 0 ≤ slack H.left H.right (fun e => u e+κ) Q p) + (hgeom : ∀J : Finset (Setoid (Fin n)), IsChain (· ≤ ·) (J : Set (Setoid (Fin n))) → + (∀p ∈ J, ∀A ∈ parts p, (H.restrict (active u)).EdgeConnectedReal A (r/2:ℕ)) → + (H.restrict (active u)).EdgeConnectedReal univ (r/2:ℕ) → + ∃Y ∈ metricDomain H, CenteredPositive Y ∧ ∀p ∈ J, + (((crossing H p ∩ active u).filter (fun e => + ¬ (6*s) • vecMulVec (H.incidence e) (H.incidence e) ≤ Y)).card:ℝ) ≤ + (r:ℝ)^(-1/3:ℝ)*(crossing H p ∩ active u).card) + (J : Finset (Setoid (Fin n))) (hJ : IsChain (· ≤ ·) (J : Set (Setoid (Fin n)))) : + ∃x ∈ admissible H s u, ∀p ∈ J, 0 ≤ responseSlack H κ t (Q-g*r*t) u p x := by + have : Nonempty (Fin n) := ⟨⟨0,by omega⟩⟩ + have hrR : (8:ℝ) ≤ r := by exact_mod_cast hr + have hQ0 : 0 ≤ Q := by linarith only [hrR,hQ] + have hh : ((r/2:ℕ):ℝ) ≤ Q-2 := by + have hdiv : (2:ℝ)*((r/2:ℕ):ℝ) ≤ r := by exact_mod_cast Nat.mul_div_le r 2 + linarith only [hdiv,hrR,hQ] + let K := J.filter (fun p => p ≠ ⊤ ∧ slack H.left H.right (fun e => u e+κ) Q p ≤ 1) + have hK : IsChain (· ≤ ·) (K : Set (Setoid (Fin n))) := hJ.mono (by + intro p hp + exact (mem_filter.mp hp).1) + have hlocal : ∀p ∈ K, ∀A ∈ parts p, (H.restrict (active u)).EdgeConnectedReal A (r/2:ℕ) := by + intro p hp A hA + exact near_tight_locally_connected H u hu0 hu1 hκ hκm hQ0 hh hinv (mem_filter.mp hp).2.2 hA + have hroot : (H.restrict (active u)).EdgeConnectedReal univ (r/2:ℕ) := + near_tight_locally_connected H u hu0 hu1 hκ hκm hQ0 hh hinv + (by rw [slack_top]; norm_num) (by rw [parts_top]; exact mem_singleton_self _) + obtain ⟨Y,hY,hYP,hbad⟩ := hgeom K hK hlocal hroot + let good : Fin m → Prop := fun e => (6*s) • vecMulVec (H.incidence e) (H.incidence e) ≤ Y + let y := booleanResponse good + have hresponse : (Y,y) ∈ admissible H s u := by + refine ⟨hY,booleanResponse_bounds good,?_⟩ + intro e _ + by_cases he : good e + · change (6*s*booleanResponse good e) • vecMulVec (H.incidence e) (H.incidence e) ≤ Y + simpa only [booleanResponse,ite_eq_left he,mul_one] using he + · change (6*s*booleanResponse good e) • vecMulVec (H.incidence e) (H.incidence e) ≤ Y + simp only [booleanResponse,ite_eq_right he,mul_zero,zero_smul] + exact Matrix.nonneg_iff_posSemidef.mpr (domain_psd H hY) + refine ⟨(Y,y),hresponse,?_⟩ + intro p hp + by_cases htop : p=⊤ + · subst p + simp only [responseSlack,slack_top,le_refl] + have hd : (2:ℝ) ≤ partCount p := by exact_mod_cast two_le_partCount htop + have hβ : 0 ≤ g*(r:ℝ)*t*((partCount p:ℝ)-1) := + mul_nonneg (mul_nonneg (mul_nonneg hg (Nat.cast_nonneg r)) ht) (by linarith) + have hcap := hinv p + unfold slack at hcap + rw [capacity_eq_sum] at hcap + unfold responseSlack slack + rw [capacity_eq_sum] + change 0 ≤ (∑e ∈ crossing H p, lowerCapacity κ t (u e) (booleanResponse good e))- + (Q-g*r*t)*((partCount p:ℝ)-1) + by_cases hnear : slack H.left H.right (fun e => u e+κ) Q p ≤ 1 + · have hKp : p ∈ K := mem_filter.mpr ⟨hp,htop,hnear⟩ + have hb : (((crossing H p ∩ active u).filter (fun e => ¬good e)).card:ℝ) ≤ + (r:ℝ)^(-1/3:ℝ)*(crossing H p ∩ active u).card := hbad p hKp + have hnear' : (∑e ∈ crossing H p, (u e+κ)) ≤ Q*((partCount p:ℝ)-1)+1 := by + unfold slack at hnear + rw [capacity_eq_sum] at hnear + linarith only [hnear] + by_cases hfew : ((crossing H p ∩ active u).card:ℝ) ≤ 8*r*((partCount p:ℝ)-1) + · have hloss := few_edges_loss_bound (crossing H p) u hu0 hu1 good (κ:=κ) ht + (Real.rpow_nonneg (Nat.cast_nonneg r) (-1/3:ℝ)) hεg (Nat.cast_nonneg r) + (by linarith : 1 ≤ (partCount p:ℝ)) hb hfew + nlinarith only [hloss,hcap] + · have hgain := many_edges_gain_bound (crossing H p) u hu0 hu1 good (κ:=κ) ht ht1 hκ + (by linarith : (1:ℝ) ≤ r) hd hQr hε hnear' hb (lt_of_not_ge hfew) + nlinarith only [hgain,hβ,hcap] + · have hfar : 1 < (∑e ∈ crossing H p, (u e+κ))-Q*((partCount p:ℝ)-1) := by + have hh := lt_of_not_ge hnear + simpa only [slack,capacity_eq_sum] using hh + have hloss := capacity_change_worst (crossing H p) u hu0 hu1 good (κ:=κ) ht + nlinarith only [hloss,hβ,hfar,htm] + +def continuationBaseline (m : ℕ) : ℝ := 1/((m:ℝ)+1) + +def continuationStep (m : ℕ) : ℝ := continuationBaseline m/32 + +lemma continuation_parameters (m : ℕ) : + 0 < continuationBaseline m ∧ continuationBaseline m ≤ 1 ∧ + continuationBaseline m*m < 1 ∧ + 0 ≤ continuationStep m ∧ continuationStep m ≤ 1/32 ∧ + 4*continuationStep m ≤ continuationBaseline m ∧ 4*continuationStep m*m ≤ 1 := by + have hmp : (0:ℝ) < m+1 := by positivity + have hκ : 0 < continuationBaseline m := one_div_pos.mpr hmp + have hκeq : continuationBaseline m*((m:ℝ)+1)=1 := div_mul_cancel₀ 1 (ne_of_gt hmp) + have hκm : 0 ≤ continuationBaseline m*m := mul_nonneg hκ.le (Nat.cast_nonneg m) + have hκ1 : continuationBaseline m ≤ 1 := by nlinarith only [hκeq,hκm] + have hκm1 : continuationBaseline m*m < 1 := by nlinarith only [hκeq,hκ] + refine ⟨hκ,hκ1,hκm1,?_,?_,?_,?_⟩ <;> unfold continuationStep <;> + nlinarith only [hκ,hκ1,hκm1,hκm] + +theorem feasible_continuation_response : + ∃r0 : ℕ, 8 ≤ r0 ∧ ∀r : ℕ, r0 ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.Connected univ → + ∀(u : Fin m → ℝ), (∀e, 0 ≤ u e) → (∀e, u e ≤ 1) → + ∀(s Q g : ℝ), 0 < s → s ≤ (r:ℝ)^(1/4:ℝ) → + 3*(r:ℝ)/4 ≤ Q → Q ≤ r → + (r:ℝ)^(-1/8:ℝ) ≤ g → g ≤ 2*(r:ℝ)^(-1/8:ℝ) → + (∀p, 0 ≤ slack H.left H.right (fun e => u e+continuationBaseline m) Q p) → + ∃x ∈ admissible H s u, + ∀p, 0 ≤ responseSlack H (continuationBaseline m) (continuationStep m) + (Q-g*r*continuationStep m) u p x := by + obtain ⟨r0,hr0,hgeom⟩ := finite_chain_response + obtain ⟨r1,hr1,hfrac⟩ := continuation_fraction_cutoff + refine ⟨max r0 r1,hr1.trans (le_max_right _ _),?_⟩ + intro r hr n m H hn hconn u hu0 hu1 s Q g hs hsr hQ hQr hg hgg hinv + have hr0' : r0 ≤ r := (le_max_left _ _).trans hr + have hr1' : r1 ≤ r := (le_max_right _ _).trans hr + have hr8 : 8 ≤ r := hr1.trans hr1' + have hrR : (8:ℝ) ≤ r := by exact_mod_cast hr8 + have hg0 : 0 ≤ g := (Real.rpow_nonneg (Nat.cast_nonneg r) _).trans hg + have hg2 : g ≤ 2 := by + have hp := Real.rpow_le_one_of_one_le_of_nonpos (by linarith : (1:ℝ) ≤ r) + (by norm_num : (-1/8:ℝ) ≤ 0) + linarith only [hp,hgg] + obtain ⟨hκ,hκ1,hκm,ht,ht1,hκt,htm⟩ := continuation_parameters m + have hq : 0 ≤ Q-g*r*continuationStep m := by + have hgt := mul_le_mul hg2 ht1 ht (by norm_num : (0:ℝ) ≤ 2) + have hh := mul_le_mul_of_nonneg_right hgt (Nat.cast_nonneg r) + nlinarith only [hh,hrR,hQ] + have hchains : ∀J : Finset (Setoid (Fin n)), IsChain (· ≤ ·) (J : Set (Setoid (Fin n))) → + ∃x ∈ admissible H s u, ∀p ∈ J, 0 ≤ responseSlack H (continuationBaseline m) + (continuationStep m) (Q-g*r*continuationStep m) u p x := by + intro J hJ + apply chain_continuation_feasible H hn hconn u hu0 hu1 hr8 hκ.le hκm ht + (by linarith : continuationStep m ≤ 1/2) htm hQ hQr hg0 + (hfrac r hr1').1 ((hfrac r hr1').2.trans hg) hs hsr hinv _ J hJ + intro K hK hlocal hroot + exact hgeom r hr0' n m H hn hconn (active u) K hK hlocal hroot s hs hsr + exact feasible_of_chain_feasible (admissible H s u) (admissible_compact H (by omega) s u) + (admissible_nonempty H s u) (admissible_convex H s u) + (responseSlack H (continuationBaseline m) (continuationStep m) (Q-g*r*continuationStep m) u) + (fun p => (responseSlack_continuous H _ _ _ u p).continuousOn) + (fun p => responseSlack_concave H _ _ _ s u p) + (fun _ hx p q => responseSlack_submodular H u ht hκt hq hx p q) hchains + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/FiniteContinuation.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/FiniteContinuation.lean new file mode 100644 index 0000000000000000000000000000000000000000..67ae157b173ebfa790cab2dbbac3fa9f45d1bd7d --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/FiniteContinuation.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Flow.Interior + +namespace OAI + +/-! Finite continuation. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions Orientations +open scoped Classical MatrixOrder Matrix.Norms.Elementwise +variable {n m : ℕ} + +def finiteStep (H : MultiGraph n m) (s κ t qbar ε : ℝ) (u : Fin m → ℝ) + (x : StepFree n m) (F : FlowPoint n m) : Prop := + x ∈ stepCore H s κ t u ∧ F.Feasible H (x.capacities κ u) qbar ε + +lemma finiteStep_sound (H : MultiGraph n m) (hn : 0 < n) + {s κ t qbar ε : ℝ} {u : Fin m → ℝ} {x : StepFree n m} {F : FlowPoint n m} + (hε : 0 ≤ ε) (h : finiteStep H s κ t qbar ε u x F) : + x ∈ stepFeasible H s κ t (qbar-4*ε) u := by + refine ⟨h.1,?_⟩ + apply relaxed_flow_implies_partitions H hn (x.capacities κ u) hε + simpa only [sub_add_cancel] using h.2 + +lemma interior_capacities_lower (H : MultiGraph n m) {s κ t ρ : ℝ} + (hρ : 0 ≤ ρ) (hρκ : ρ ≤ κ) (u : Fin m → ℝ) (c : StepFree n m) + (h : ∀x : StepFree n m, x.Close c ρ → x ∈ stepCore H s κ t u) : + ∀e, ρ ≤ c.capacities κ u e := by + let w : StepFree n m := (c.1,c.multiplier,c.y,fun e => c.z e-ρ) + have hw : w.Close c ρ := by + refine ⟨?_,?_,?_,?_⟩ + · intro i j + simpa only [w,sub_self,abs_zero] using hρ + · intro ijk + simpa only [w,StepFree.multiplier,sub_self,abs_zero] using hρ + · intro e + simpa only [w,StepFree.y,sub_self,abs_zero] using hρ + · intro e + change |c.z e-ρ-c.z e| ≤ ρ + rw [show c.z e-ρ-c.z e = -ρ by ring,abs_neg,abs_of_nonneg hρ] + have hwc := h w hw + intro e + unfold StepFree.capacities + split_ifs + · have he := (hwc.2.2.2.2.1 e).1 + change 0 ≤ c.z e-ρ at he + linarith only [he] + · exact hρκ + +lemma finite_interior_numbers {P β : ℝ} (hP : 5 ≤ P) + (hn : (n:ℝ) ≤ P) (hm : (m:ℝ) ≤ P) (hβ : P⁻¹/32 ≤ β) : + let ε := P^(-10:ℤ) + let α := P^(-12:ℤ) + let γ := P^(-45:ℤ) + let ρ := P^(-30:ℤ) + let δ := P^(-50:ℤ) + 0 < β ∧ α ≤ ε ∧ α*((n:ℝ)-1) ≤ ε ∧ + 4*m*γ ≤ α ∧ 4*m*γ ≤ β ∧ 2*γ ≤ ρ ∧ + δ ≤ ρ ∧ δ ≤ γ/4 ∧ γ ≤ 1 ∧ ρ ≤ P⁻¹ := by + dsimp only + have hP0 : 0 < P := by linarith + have hP1 : 1 ≤ P := by linarith + have hP2 : 25 ≤ P^2 := by nlinarith only [hP,sq_nonneg (P-5)] + have hpw {a b : ℕ} (hab : a ≤ b) : P^a ≤ P^b := pow_le_pow_right₀ hP1 hab + have h4 : (4:ℝ) ≤ P^5 := (by linarith : (4:ℝ) ≤ P).trans (by simpa using hpw (by norm_num : 1 ≤ 5)) + have h32 : (32:ℝ) ≤ P^11 := by + have hh : 32 ≤ P^4 := by nlinarith only [hP2,sq_nonneg (P^2-25)] + exact hh.trans (hpw (by norm_num)) + have hnm : (n:ℝ)-1 ≤ P^2 := calc + _ ≤ P := by linarith only [hn] + _ ≤ P^2 := by simpa using hpw (by norm_num : 1 ≤ 2) + have hnα := scaled_inverse_power hP0 10 2 hnm + have hm4 : 4*(m:ℝ) ≤ P^33 := calc + _ ≤ 4*P := by linarith only [hm] + _ ≤ P^2 := by nlinarith only [hP] + _ ≤ P^33 := hpw (by norm_num) + have hmγ := scaled_inverse_power hP0 12 33 hm4 + have hαβ : P^(-12:ℤ) ≤ β := by + have hh := scaled_inverse_power hP0 1 11 h32 + norm_num only [Nat.cast_ofNat,Nat.reduceAdd,_root_.zpow_neg_one] at hh + linarith only [hh,hβ] + have hgρ := scaled_inverse_power hP0 30 15 + (show (2:ℝ) ≤ P^15 from (by linarith : (2:ℝ) ≤ P).trans (by simpa using hpw (by norm_num : 1 ≤ 15))) + have hdg := scaled_inverse_power hP0 45 5 h4 + norm_num only [Nat.cast_ofNat,Nat.reduceAdd] at hnα hmγ hgρ hdg + have hβ0 : 0 < β := (by positivity : (0:ℝ) < P⁻¹/32).trans_le hβ + refine ⟨hβ0,inverse_power_mono hP1 (by norm_num : 10 ≤ 12),?_,?_,?_,?_, + inverse_power_mono hP1 (by norm_num : 30 ≤ 50),?_,?_,?_⟩ + · simpa only [Nat.cast_ofNat,mul_comm] using hnα + · simpa only [Nat.cast_ofNat,mul_assoc] using hmγ + · exact hmγ.trans hαβ + · simpa only [Nat.cast_ofNat] using hgρ + · simpa only [Nat.cast_ofNat] using (show P^(-50:ℤ) ≤ P^(-45:ℤ)/4 by linarith only [hdg]) + · simpa using inverse_power_mono hP1 (by norm_num : 0 ≤ 45) + · simpa using inverse_power_mono hP1 (by norm_num : 1 ≤ 30) + +theorem finite_continuation_inner_cube (H : MultiGraph n m) (hn : 2 ≤ n) + (hconn : H.Connected univ) {s qbar β : ℝ} + (hs : 0 ≤ s) (hsP : s ≤ graphSize n m) + (hq : (graphSize n m)^(-12:ℤ) ≤ qbar) (hqm : qbar+β ≤ m) + (hβ : (graphSize n m)⁻¹/32 ≤ β) + (u : Fin m → ℝ) (hu : ∀e, 0 ≤ u e) {z : StepFree n m} + (hz : z ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) (qbar+β+β) u) : + ∃(c : StepFree n m) (F : FlowPoint n m), + c.Bounded (6*graphSize n m) ∧ F.Bounded (6*graphSize n m) ∧ + ∀(x : StepFree n m) (W : FlowPoint n m), + x.Close c ((graphSize n m)^(-50:ℤ)) → + W.Close F ((graphSize n m)^(-50:ℤ)) → + finiteStep H s (continuationBaseline m) (continuationStep m) qbar + ((graphSize n m)^(-10:ℤ)) u x W := by + let P := graphSize n m + have hP : 5 ≤ P := connected_size_five H hn hconn + have hP0 : 0 < P := by linarith only [hP] + have hnP : (n:ℝ) ≤ P := by unfold P graphSize; linarith [Nat.cast_nonneg (α:=ℝ) m] + have hmP : (m:ℝ) ≤ P := by unfold P graphSize; linarith [Nat.cast_nonneg (α:=ℝ) n] + obtain ⟨hβ0,hαε,hαn,hmγα,hmγβ,hgρ,hdρ,hdγ,hγ1,hρP⟩ := + finite_interior_numbers hP hnP hmP hβ + have hγ0 : (0:ℝ) < P^(-45:ℤ) := zpow_pos hP0 _ + have hα0 : (0:ℝ) ≤ P^(-12:ℤ) := (zpow_pos hP0 _).le + obtain ⟨c,hc,hball⟩ := bounded_step_inner_cube H hn hconn hs hsP hqm hβ u hu hz + have hρ0 : (0:ℝ) ≤ P^(-30:ℤ) := (zpow_pos hP0 _).le + have hcself := hball c (StepFree.Close.refl c hρ0) + have hcap := interior_capacities_lower H hρ0 (hρP.trans baseline_lower) u c + (fun x hx => (hball x hx).1) + have hcR : ∀e, c.capacities (continuationBaseline m) u e ≤ 2 := by + intro e + unfold StepFree.capacities + split_ifs + · exact (hcself.1.2.2.2.2.1 e).2.trans (by linarith only [baseline_le_one (m:=m)]) + · exact baseline_le_one.trans (by norm_num) + obtain ⟨F,hF,hFball⟩ := flow_inner_cube_vary H (by omega) (c.capacities (continuationBaseline m) u) + hγ0 hα0 hq hαε hαn hβ0 hmγα hmγβ (fun e => hgρ.trans (hcap e)) hcR + (fun p => by have hh := hcself.2 p; unfold slack at hh; linarith only [hh]) + refine ⟨c,F,hc,hF.mono ?_,?_⟩ + · linarith only [hγ1,hP] + · intro x W hx hW + refine ⟨(hball x (hx.mono hdρ)).1,hFball (x.capacities (continuationBaseline m) u) W ?_ (hW.mono hdγ)⟩ + intro e + unfold StepFree.capacities + split_ifs + · have hh := (abs_le.mp (hx.2.2.2 e)).1 + change -(P^(-50:ℤ)) ≤ x.z e-c.z e at hh + linarith only [hh,hdγ,hγ0] + · linarith only [hγ0] + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Gains.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Gains.lean new file mode 100644 index 0000000000000000000000000000000000000000..fc28916fdfa932862f9d985c63a818cdc3801c79 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Gains.lean @@ -0,0 +1,176 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.PartitionLocalConnectivity +import OAI.Combinatorics.ThinTrees.Continuation.Ramp + +namespace OAI + +/-! Continuation gains. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Finset +open scoped Classical + +variable {m : ℕ} + +def booleanResponse (good : Fin m → Prop) : Fin m → ℝ := + fun e => if good e then 1 else 0 + +lemma booleanResponse_bounds (good : Fin m → Prop) (e : Fin m) : + 0 ≤ booleanResponse good e ∧ booleanResponse good e ≤ 1 := by + unfold booleanResponse + split_ifs <;> norm_num + +lemma good_capacity_nondecreasing {κ t u : ℝ} (ht : 0 ≤ t) (hu : u ≤ 1) (hu0 : 0 ≤ u) : + u+κ ≤ lowerCapacity κ t u 1 := by + by_cases he : 0 < u + · simp only [lowerCapacity,ite_eq_left he] + have hh : u ≤ min 1 (u+t*(5*(1:ℝ)-4)) := le_min hu (by linarith) + linarith only [hh] + · have hz : u=0 := le_antisymm (le_of_not_gt he) hu0 + simp [hz,lowerCapacity] + +lemma good_capacity_unsaturated {κ t u : ℝ} (hu : 0 < u) (hu1 : u ≤ 1/2) (ht : t ≤ 1/2) : + lowerCapacity κ t u 1=u+κ+t := by + rw [lowerCapacity,ite_eq_left hu,min_eq_right (by linarith : u+t*(5*(1:ℝ)-4) ≤ 1)] + ring + +lemma bad_capacity_loss {κ t u : ℝ} (ht : 0 ≤ t) (hu : 0 < u) (hu1 : u ≤ 1) : + lowerCapacity κ t u 0=u+κ-4*t := by + rw [lowerCapacity,ite_eq_left hu,min_eq_right (by linarith : u+t*(5*(0:ℝ)-4) ≤ 1)] + ring + +lemma inactive_capacity {κ t u y : ℝ} (hu : 0 ≤ u) (ha : ¬0 < u) : + lowerCapacity κ t u y=u+κ := by + have hz : u=0 := le_antisymm (le_of_not_gt ha) hu + simp [lowerCapacity,hz] + +lemma capacity_change_active (F : Finset (Fin m)) (u : Fin m → ℝ) + (hu : ∀e, 0 ≤ u e) (κ t : ℝ) (y : Fin m → ℝ) : + (∑e ∈ F, lowerCapacity κ t (u e) (y e))-(∑e ∈ F, (u e+κ)) = + ∑e ∈ F ∩ Partitions.active u, (lowerCapacity κ t (u e) (y e)-(u e+κ)) := by + rw [←sum_sub_distrib] + symm + apply sum_subset inter_subset_left + intro e _ he + have hne : ¬0 < u e := by + intro hg + exact he (mem_inter.mpr ⟨by assumption,(Partitions.mem_active u e).mpr hg⟩) + rw [inactive_capacity (hu e) hne,sub_self] + +lemma capacity_change_loss (F : Finset (Fin m)) (u : Fin m → ℝ) + (hu0 : ∀e, 0 ≤ u e) (hu1 : ∀e, u e ≤ 1) (good : Fin m → Prop) + {κ t : ℝ} (ht : 0 ≤ t) : + -4*t*(((F ∩ Partitions.active u).filter (fun e => ¬good e)).card:ℝ) ≤ + (∑e ∈ F, lowerCapacity κ t (u e) (booleanResponse good e))-(∑e ∈ F, (u e+κ)) := by + rw [capacity_change_active F u hu0] + have hb (e : Fin m) (he : e ∈ F ∩ Partitions.active u) : + (if ¬good e then -4*t else 0) ≤ + lowerCapacity κ t (u e) (booleanResponse good e)-(u e+κ) := by + have ha : 0 < u e := (Partitions.mem_active u e).mp (mem_inter.mp he).2 + by_cases hg : good e + · simp only [booleanResponse,hg,not_true_eq_false,ite_false,ite_true] + linarith only [good_capacity_nondecreasing (κ:=κ) ht (hu1 e) (hu0 e)] + · simp only [booleanResponse,hg,not_false_eq_true,ite_true,ite_false, + bad_capacity_loss ht ha (hu1 e)] + ring_nf + exact le_rfl + have hs := sum_le_sum hb + rw [←sum_filter] at hs + simpa only [sum_const,nsmul_eq_mul,mul_comm] using hs + +lemma capacity_change_gain (F : Finset (Fin m)) (u : Fin m → ℝ) + (hu0 : ∀e, 0 ≤ u e) (hu1 : ∀e, u e ≤ 1) (good : Fin m → Prop) + {κ t : ℝ} (ht : 0 ≤ t) (ht1 : t ≤ 1/2) : + t*((F ∩ Partitions.active u).card- + (((F ∩ Partitions.active u).filter (fun e => 1/2 ¬good e)).card:ℝ)) ≤ + (∑e ∈ F, lowerCapacity κ t (u e) (booleanResponse good e))-(∑e ∈ F, (u e+κ)) := by + rw [capacity_change_active F u hu0] + have hb (e : Fin m) (he : e ∈ F ∩ Partitions.active u) : + t-(if 1/2 linarith + have hs := sum_le_sum hb + simp only [sum_sub_distrib,←sum_filter,sum_const,nsmul_eq_mul] at hs + rw [sum_sub_distrib] + nlinarith only [hs] + +lemma large_count_bound (A : Finset (Fin m)) (u : Fin m → ℝ) (hu : ∀e, 0 ≤ u e) : + (((A.filter (fun e => 1/2 linarith [hu e] + have hs := sum_le_sum hb + rw [←sum_filter,sum_const,nsmul_eq_mul,mul_one,←mul_sum] at hs + exact hs + +lemma active_capacity_sum_le (F : Finset (Fin m)) (u : Fin m → ℝ) (hu : ∀e, 0 ≤ u e) + {κ : ℝ} (hκ : 0 ≤ κ) : + (∑e ∈ F ∩ Partitions.active u, u e) ≤ ∑e ∈ F, (u e+κ) := by + calc + _ ≤ ∑e ∈ F, u e := sum_le_sum_of_subset_of_nonneg inter_subset_left (fun e _ _ => hu e) + _ ≤ _ := sum_le_sum (fun e _ => le_add_of_nonneg_right hκ) + +lemma many_edges_half_unsaturated (F : Finset (Fin m)) (u : Fin m → ℝ) + (hu0 : ∀e, 0 ≤ u e) {κ r d Q : ℝ} (hκ : 0 ≤ κ) (hr : 1 ≤ r) (hd : 2 ≤ d) + (hQ : Q ≤ r) (hnear : (∑e ∈ F, (u e+κ)) ≤ Q*(d-1)+1) + (hmany : 8*r*(d-1) < ((F ∩ Partitions.active u).card:ℝ)) : + (((F ∩ Partitions.active u).filter (fun e => 1/2 ¬good e)).card:ℝ) ≤ + ε*(F ∩ Partitions.active u).card) + (hfew : ((F ∩ Partitions.active u).card:ℝ) ≤ 8*r*(d-1)) : + -g*r*t*(d-1) ≤ (∑e ∈ F, lowerCapacity κ t (u e) (booleanResponse good e))- + (∑e ∈ F, (u e+κ)) := by + have h1 := capacity_change_loss F u hu0 hu1 good (κ:=κ) ht + have h2 := mul_le_mul_of_nonneg_left hfew hε + have h3 := mul_le_mul_of_nonneg_left (hbad.trans h2) (by linarith : 0 ≤ 4*t) + have h4 := mul_le_mul_of_nonneg_right hεg (mul_nonneg (mul_nonneg hr ht) (by linarith : 0 ≤ d-1)) + nlinarith only [h1,h3,h4] + +lemma many_edges_gain_bound (F : Finset (Fin m)) (u : Fin m → ℝ) + (hu0 : ∀e, 0 ≤ u e) (hu1 : ∀e, u e ≤ 1) (good : Fin m → Prop) + {κ t r d Q ε : ℝ} (ht : 0 ≤ t) (ht1 : t ≤ 1/2) (hκ : 0 ≤ κ) + (hr : 1 ≤ r) (hd : 2 ≤ d) (hQ : Q ≤ r) (hε : ε ≤ 1/10) + (hnear : (∑e ∈ F, (u e+κ)) ≤ Q*(d-1)+1) + (hbad : (((F ∩ Partitions.active u).filter (fun e => ¬good e)).card:ℝ) ≤ + ε*(F ∩ Partitions.active u).card) + (hmany : 8*r*(d-1) < ((F ∩ Partitions.active u).card:ℝ)) : + 0 ≤ (∑e ∈ F, lowerCapacity κ t (u e) (booleanResponse good e))- + (∑e ∈ F, (u e+κ)) := by + have h1 := capacity_change_gain F u hu0 hu1 good (κ:=κ) ht ht1 + have h2 := many_edges_half_unsaturated F u hu0 hκ hr hd hQ hnear hmany + have h3 := mul_le_mul_of_nonneg_right hε (Nat.cast_nonneg (F ∩ Partitions.active u).card) + have h4 : 0 ≤ ((F ∩ Partitions.active u).card:ℝ)- + (((F ∩ Partitions.active u).filter (fun e => 1/2 ¬good e)).card:ℝ) := by + linarith only [h2,h3,hbad] + exact (mul_nonneg ht h4).trans h1 + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Grid.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Grid.lean new file mode 100644 index 0000000000000000000000000000000000000000..07823cbd4a0834479fd315a7e747d21460360792 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Grid.lean @@ -0,0 +1,270 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Margin + +namespace OAI + +/-! Continuation grid. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical MatrixOrder Matrix.Norms.Elementwise +variable {n m : ℕ} + +namespace StepFree + +def canonical (x : StepFree n m) : StepFree n m := (x.matrix,x.2) + +lemma canonical_matrix (x : StepFree n m) (hn : 0 < n) : + x.canonical.matrix=x.matrix := + responseMatrix_fixed (responseMatrix_hermitian x.1) (responseMatrix_ones hn x.1) + +lemma canonical_core (H : MultiGraph n m) (hn : 0 < n) + {s κ t : ℝ} {u : Fin m → ℝ} {x : StepFree n m} + (hx : x ∈ stepCore H s κ t u) : x.canonical ∈ stepCore H s κ t u := by + simpa only [stepCore,Set.mem_ofPred_eq,lowerPencil,upperPencil,edgePencil, + canonical_matrix x hn, + show x.canonical.multiplier=x.multiplier from rfl, + show x.canonical.y=x.y from rfl,show x.canonical.z=x.z from rfl] using hx + +lemma canonical_feasible (H : MultiGraph n m) (hn : 0 < n) + {s κ t q : ℝ} {u : Fin m → ℝ} {x : StepFree n m} + (hx : x ∈ stepFeasible H s κ t q u) : x.canonical ∈ stepFeasible H s κ t q u := + ⟨canonical_core H hn hx.1,hx.2⟩ + +def Bounded (x : StepFree n m) (R : ℝ) : Prop := + (∀i j, |x.1 i j| ≤ R) ∧ (∀ijk, |x.multiplier ijk| ≤ R) ∧ + (∀e, |x.y e| ≤ R) ∧ (∀e, |x.z e| ≤ R) + +lemma Bounded.combo {x z : StepFree n m} {R a b : ℝ} + (hx : x.Bounded R) (hz : z.Bounded R) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) : + (a • x+b • z).Bounded R := by + have he (v w : ℝ) (hv : |v| ≤ R) (hw : |w| ≤ R) : |a*v+b*w| ≤ R := by + calc + _ ≤ |a*v|+|b*w| := abs_add_le _ _ + _ = a*|v|+b*|w| := by rw [abs_mul,abs_mul,abs_of_nonneg ha,abs_of_nonneg hb] + _ ≤ a*R+b*R := add_le_add (mul_le_mul_of_nonneg_left hv ha) (mul_le_mul_of_nonneg_left hw hb) + _ = R := by rw [←add_mul,hab,one_mul] + exact ⟨fun i j => he _ _ (hx.1 i j) (hz.1 i j), + fun ijk => he _ _ (hx.2.1 ijk) (hz.2.1 ijk), + fun e => he _ _ (hx.2.2.1 e) (hz.2.2.1 e), + fun e => he _ _ (hx.2.2.2 e) (hz.2.2.2 e)⟩ + +lemma canonical_bound (H : MultiGraph n m) (hn : 0 < n) + {s κ t : ℝ} {u : Fin m → ℝ} {x : StepFree n m} (hκ : κ ≤ 1) + (hx : x ∈ stepCore H s κ t u) : x.canonical.Bounded (6*graphSize n m) := by + have hd := stepCore_domain H hn hx + have hp := domain_psd H hd + have ht := domain_trace_size H hn hd + have hmP : (m:ℝ) ≤ graphSize n m := by + unfold graphSize + linarith [Nat.cast_nonneg (α:=ℝ) n] + have hP : 2 ≤ graphSize n m := by + unfold graphSize + linarith [Nat.cast_nonneg (α:=ℝ) n,Nat.cast_nonneg (α:=ℝ) m] + have h6 : 0 ≤ (6:ℝ)*m := by positivity + have hdiag (i : Fin n) : x.matrix i i ≤ 6*m := + (single_le_sum (fun j _ => hp.diag_nonneg (i:=j)) (mem_univ i)).trans ht + refine ⟨fun i j => (psd_entry_bound hp h6 hdiag i j).trans (by linarith only [hmP]),?_,?_,?_⟩ + · intro ijk + change |x.multiplier ijk| ≤ _ + rw [abs_of_nonneg (hx.2.2.1 ijk)] + have hsum := domain_multiplier_bound H hp x.multiplier hx.2.1 + have hle := single_le_sum (fun j _ => hx.2.2.1 j) (mem_univ ijk) + linarith only [hle,hsum,hmP,graphSize_pos (n:=n) (m:=m)] + · intro e + change |x.y e| ≤ _ + rw [abs_of_nonneg (hx.2.2.2.1 e).1] + linarith only [(hx.2.2.2.1 e).2,hP] + · intro e + change |x.z e| ≤ _ + rw [abs_of_nonneg (hx.2.2.2.2.1 e).1] + linarith only [(hx.2.2.2.2.1 e).2,hκ,hP] + +end StepFree + +lemma auxiliaryPoint_canonical (H : MultiGraph n m) (_hn : 0 < n) (κ : ℝ) : + (auxiliaryPoint H κ).canonical=auxiliaryPoint H κ := by + change ((auxiliaryPoint H κ).matrix,(auxiliaryPoint H κ).2)=((auxiliaryPoint H κ).1,(auxiliaryPoint H κ).2) + rw [auxiliaryPoint_matrix] + rfl + +lemma baseline_le_one : continuationBaseline m ≤ 1 := by + unfold continuationBaseline + exact (div_le_one (by positivity)).mpr (by linarith [Nat.cast_nonneg (α:=ℝ) m]) + +theorem bounded_step_inner_cube (H : MultiGraph n m) (hn : 2 ≤ n) (hconn : H.Connected univ) + {s q β : ℝ} (hs : 0 ≤ s) (hsP : s ≤ graphSize n m) + (hq : q ≤ m) (hβ : (graphSize n m)⁻¹/32 ≤ β) + (u : Fin m → ℝ) (hu0 : ∀e, 0 ≤ u e) + {z : StepFree n m} + (hz : z ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) (q+β) u) : + ∃c : StepFree n m, c.Bounded (6*graphSize n m) ∧ + ∀x, x.Close c ((graphSize n m)^(-30:ℤ)) → + x ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) q u := by + have hn0 : 0 < n := by omega + let θ := (graphSize n m)^(-8:ℤ) + let aux := auxiliaryPoint H (continuationBaseline m) + have hθ : 0 ≤ θ := (zpow_pos graphSize_pos _).le + have hθ1 : θ ≤ 1 := by + have hP : 1 ≤ graphSize n m := by + unfold graphSize + linarith [Nat.cast_nonneg (α:=ℝ) n,Nat.cast_nonneg (α:=ℝ) m] + exact (inverse_power_mono hP (by norm_num : 0 ≤ 8)).trans_eq (by simp) + have ha : aux ∈ stepCore H s (continuationBaseline m) (continuationStep m) u := + auxiliary_cube H hn hconn hs hsP u hu0 (StepFree.Close.refl aux (zpow_pos graphSize_pos _).le) + have hab := StepFree.canonical_bound H hn0 baseline_le_one ha + rw [auxiliaryPoint_canonical H hn0] at hab + refine ⟨(1-θ) • z.canonical+θ • aux,?_,?_⟩ + · exact (StepFree.canonical_bound H hn0 baseline_le_one hz.1).combo hab + (sub_nonneg.mpr hθ1) hθ (by ring) + · exact step_inner_cube H hn hconn hs hsP hq hβ u hu0 (z.canonical_feasible H hn0 hz) + +abbrev StepIntegers (n m : ℕ) := + Matrix (Fin n) (Fin n) ℤ × (DistinctTriple n → ℤ) × (Fin m → ℤ) × (Fin m → ℤ) + +abbrev StepRational (n m : ℕ) := + Matrix (Fin n) (Fin n) ℚ × (DistinctTriple n → ℚ) × (Fin m → ℚ) × (Fin m → ℚ) + +namespace StepRational + +def real (x : StepRational n m) : StepFree n m := + (fun i j => (x.1 i j:ℝ),fun ijk => (x.2.1 ijk:ℝ), + fun e => (x.2.2.1 e:ℝ),fun e => (x.2.2.2 e:ℝ)) + +end StepRational + +namespace StepIntegers + +def onGrid (D : ℕ) (a : StepIntegers n m) : StepRational n m := + (fun i j => (a.1 i j:ℚ)/D,fun ijk => (a.2.1 ijk:ℚ)/D, + fun e => (a.2.2.1 e:ℚ)/D,fun e => (a.2.2.2 e:ℚ)/D) + +def Bounded (a : StepIntegers n m) (N : ℕ) : Prop := + (∀i j, |a.1 i j| ≤ N) ∧ (∀ijk, |a.2.1 ijk| ≤ N) ∧ + (∀e, |a.2.2.1 e| ≤ N) ∧ (∀e, |a.2.2.2 e| ≤ N) + +end StepIntegers + +def roundStep (D : ℕ) (x : StepFree n m) : StepIntegers n m := + (fun i j => ⌊(D:ℝ)*x.1 i j⌋,fun ijk => ⌊(D:ℝ)*x.multiplier ijk⌋, + fun e => ⌊(D:ℝ)*x.y e⌋,fun e => ⌊(D:ℝ)*x.z e⌋) + +lemma floorGrid_error {D : ℕ} (hD : 0 < D) (x : ℝ) : + |((⌊(D:ℝ)*x⌋:ℤ):ℝ)/(D:ℝ)-x| ≤ (D:ℝ)⁻¹ := by + have hDr : 0 < (D:ℝ) := by exact_mod_cast hD + have hlo := Int.floor_le ((D:ℝ)*x) + have hhi := Int.lt_floor_add_one ((D:ℝ)*x) + have h1 : ((⌊(D:ℝ)*x⌋:ℤ):ℝ)/(D:ℝ) ≤ x := (div_le_iff₀ hDr).mpr (by linarith only [hlo]) + have h2 : x < (((⌊(D:ℝ)*x⌋:ℤ):ℝ)+1)/(D:ℝ) := (lt_div_iff₀ hDr).mpr (by linarith only [hhi]) + rw [abs_of_nonpos (sub_nonpos.mpr h1)] + rw [add_div,one_div] at h2 + linarith only [h2] + +lemma roundStep_error {D : ℕ} (hD : 0 < D) (x : StepFree n m) : + ((roundStep D x).onGrid D).real.Close x (D:ℝ)⁻¹ := by + refine ⟨?_,?_,?_,?_⟩ + · intro i j + simpa only [StepFree.Close,StepRational.real,StepIntegers.onGrid,roundStep, + Rat.cast_div,Rat.cast_intCast,Rat.cast_natCast] using floorGrid_error hD (x.1 i j) + · intro ijk + simpa only [StepFree.multiplier,StepRational.real,StepIntegers.onGrid,roundStep, + Rat.cast_div,Rat.cast_intCast,Rat.cast_natCast] using floorGrid_error hD (x.multiplier ijk) + · intro e + simpa only [StepFree.y,StepRational.real,StepIntegers.onGrid,roundStep, + Rat.cast_div,Rat.cast_intCast,Rat.cast_natCast] using floorGrid_error hD (x.y e) + · intro e + simpa only [StepFree.z,StepRational.real,StepIntegers.onGrid,roundStep, + Rat.cast_div,Rat.cast_intCast,Rat.cast_natCast] using floorGrid_error hD (x.z e) + +lemma floorGrid_bound {D P : ℕ} {x : ℝ} (hP : 1 ≤ P) (hD : D=P^32) + (hx : |x| ≤ 6*(P:ℝ)) : |⌊(D:ℝ)*x⌋| ≤ (7*P^33:ℕ) := by + have hPr : (1:ℝ) ≤ P := by exact_mod_cast hP + have hlo := Int.floor_le ((D:ℝ)*x) + have hhi := Int.lt_floor_add_one ((D:ℝ)*x) + have hmul := mul_le_mul_of_nonneg_left hx (Nat.cast_nonneg (α:=ℝ) D) + have hmul' : |(D:ℝ)*x| ≤ 6*(P:ℝ)^33 := by + calc + _ = (D:ℝ)*|x| := by rw [abs_mul,abs_of_nonneg (Nat.cast_nonneg (α:=ℝ) D)] + _ ≤ (D:ℝ)*(6*(P:ℝ)) := hmul + _ = _ := by rw [hD,Nat.cast_pow]; ring + have hPl : (1:ℝ) ≤ (P:ℝ)^33 := one_le_pow₀ hPr + have hb : |(⌊(D:ℝ)*x⌋:ℝ)| ≤ 7*(P:ℝ)^33 := by + obtain ⟨hm1,hm2⟩ := abs_le.mp hmul' + apply abs_le.mpr + constructor <;> linarith only [hlo,hhi,hm1,hm2,hPl] + exact_mod_cast hb + +lemma roundStep_bound (x : StepFree n m) (hx : x.Bounded (6*graphSize n m)) : + (roundStep ((n+m+2)^32) x).Bounded (7*(n+m+2)^33) := by + have he (v : ℝ) (hv : |v| ≤ 6*graphSize n m) : + |⌊((n+m+2)^32:ℕ)*v⌋| ≤ (7*(n+m+2)^33:ℕ) := by + apply floorGrid_bound (by omega : 1 ≤ n+m+2) rfl + simpa only [graphSize,Nat.cast_add,Nat.cast_ofNat] using hv + exact ⟨fun i j => he _ (hx.1 i j),fun ijk => he _ (hx.2.1 ijk), + fun e => he _ (hx.2.2.1 e),fun e => he _ (hx.2.2.2 e)⟩ + +theorem bounded_grid_step (H : MultiGraph n m) (hn : 2 ≤ n) (hconn : H.Connected univ) + {s q β : ℝ} (hs : 0 ≤ s) (hsP : s ≤ graphSize n m) + (hq : q ≤ m) (hβ : (graphSize n m)⁻¹/32 ≤ β) + (u : Fin m → ℝ) (hu0 : ∀e, 0 ≤ u e) + {z : StepFree n m} + (hz : z ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) (q+β) u) : + ∃a : StepIntegers n m, a.Bounded (7*(n+m+2)^33) ∧ + (a.onGrid ((n+m+2)^32)).real ∈ + stepFeasible H s (continuationBaseline m) (continuationStep m) q u := by + obtain ⟨c,hc,hball⟩ := bounded_step_inner_cube H hn hconn hs hsP hq hβ u hu0 hz + refine ⟨roundStep ((n+m+2)^32) c,roundStep_bound c hc,hball _ ?_⟩ + apply (roundStep_error (by positivity) c).mono + have hP : 1 ≤ graphSize n m := by + unfold graphSize + linarith [Nat.cast_nonneg (α:=ℝ) n,Nat.cast_nonneg (α:=ℝ) m] + convert inverse_power_mono hP (by norm_num : 30 ≤ 32) using 1 + simp only [graphSize,Nat.cast_pow,Nat.cast_add,Nat.cast_ofNat,_root_.zpow_neg] + rfl + +theorem uniform_continuation_grid : + ∃r0 : ℕ, 8 ≤ r0 ∧ ∀r : ℕ, r0 ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.Connected univ → r ≤ m → + ∀(u : Fin m → ℝ), (∀e, 0 ≤ u e) → (∀e, u e ≤ 1) → + ∀(s Q g : ℝ), 0 < s → s ≤ (r:ℝ)^(1/4:ℝ) → + 3*(r:ℝ)/4 ≤ Q → Q ≤ r → + (r:ℝ)^(-1/8:ℝ) ≤ g → g ≤ 2*(r:ℝ)^(-1/8:ℝ) → + (∀p, 0 ≤ slack H.left H.right (fun e => u e+continuationBaseline m) Q p) → + ∃a : StepIntegers n m, a.Bounded (7*(n+m+2)^33) ∧ + (a.onGrid ((n+m+2)^32)).real ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) + (Q-2*g*r*continuationStep m) u := by + obtain ⟨r0,hr0,hr⟩ := feasible_continuation_response + refine ⟨r0,hr0,?_⟩ + intro r hrr n m H hn hconn hrm u hu0 hu1 s Q g hs hsr hQ hQr hg hgg hinv + have hr1 : 1 ≤ r := by omega + have hrR : (1:ℝ) ≤ r := by exact_mod_cast hr1 + have hsP : s ≤ graphSize n m := by + calc + s ≤ (r:ℝ)^(1/4:ℝ) := hsr + _ ≤ (r:ℝ)^((1:ℝ)) := Real.rpow_le_rpow_of_exponent_le hrR (by norm_num) + _ = r := Real.rpow_one _ + _ ≤ m := by exact_mod_cast hrm + _ ≤ _ := by unfold graphSize; linarith [Nat.cast_nonneg (α:=ℝ) n] + have hβ := continuation_margin_lower (n:=n) (m:=m) hr1 hg + have hβ0 : 0 ≤ g*r*continuationStep m := (div_nonneg (inv_nonneg.mpr (graphSize_pos (n:=n) (m:=m)).le) (by norm_num) : 0 ≤ (graphSize n m)⁻¹/32).trans hβ + obtain ⟨w,hw,hp⟩ := hr r hrr n m H hn hconn u hu0 hu1 s Q g hs hsr hQ hQr hg hgg hinv + obtain ⟨z,hz,_,_⟩ := response_to_stepFeasible H (by omega) + (continuation_parameters m).2.2.2.1 (continuation_parameters m).2.2.2.2.2.1 hw hp + have hq : Q-2*g*r*continuationStep m ≤ m := by + have hh : (r:ℝ) ≤ m := by exact_mod_cast hrm + linarith only [hβ0,hh,hQr] + have hz' : z ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) + ((Q-2*g*r*continuationStep m)+(g*r*continuationStep m)) u := by + rw [show (Q-2*g*r*continuationStep m)+(g*r*continuationStep m) = + Q-g*r*continuationStep m by ring] + exact hz + exact bounded_grid_step H hn hconn hs.le hsP hq hβ u hu0 hz' + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Interior.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Interior.lean new file mode 100644 index 0000000000000000000000000000000000000000..f9d3c86c050bb728efaab42891ed014936da1917 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Interior.lean @@ -0,0 +1,370 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Encoding +import OAI.Combinatorics.ThinTrees.Continuation.Feasibility +import OAI.Combinatorics.ThinTrees.Continuation.SpectralSize + +namespace OAI + +/-! Continuation interior. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical MatrixOrder Matrix.Norms.Elementwise + +variable {n m : ℕ} + +lemma qform_transpose (A : Matrix (Fin n) (Fin n) ℝ) (v : Fin n → ℝ) : + qform Aᵀ v=qform A v := by + simp only [qform,dotProduct_mulVec,vecMul_transpose,dotProduct_comm] + +lemma qform_responseMatrix (A : Matrix (Fin n) (Fin n) ℝ) (v : Fin n → ℝ) : + qform (responseMatrix A) v=qform A (centering n *ᵥ v) := by + rw [responseMatrix,qform_centered,qform_smul,qform_add,qform_transpose] + ring + +lemma qform_sum {J : Type*} [Fintype J] (A : J → Matrix (Fin n) (Fin n) ℝ) (v : Fin n → ℝ) : + qform (∑j, A j) v=∑j, qform (A j) v := by + simp only [qform,sum_mulVec,dotProduct_sum] + +lemma abs_qform_le_entries {A : Matrix (Fin n) (Fin n) ℝ} {η : ℝ} + (hη : 0 ≤ η) (hA : ∀i j, |A i j| ≤ η) (v : Fin n → ℝ) : + |qform A v| ≤ (n : ℝ)*η*(∑i, v i^2) := by + have hq : qform A v=∑i, ∑j, v i*A i j*v j := by + simp only [qform,mulVec,dotProduct,mul_sum] + congr 1 + ext i + exact sum_congr rfl fun j _ => (mul_assoc _ _ _).symm + have hh : ∑i, ∑j, |v i*A i j*v j| ≤ η*(∑i, |v i|)^2 := by + calc + _ ≤ ∑i, ∑j, |v i| *η*|v j| := sum_le_sum fun i _ => sum_le_sum fun j _ => by + rw [abs_mul,abs_mul] + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left (hA i j) (abs_nonneg _)) (abs_nonneg _) + _ = _ := by simp only [←mul_sum,←sum_mul]; ring + have hcs : (∑i, |v i|)^2 ≤ (n : ℝ)*(∑i, v i^2) := by + simpa only [sq_abs,card_univ,Fintype.card_fin] using sq_sum_le_card_mul_sum_sq (s:=univ) (f:=fun i => |v i|) + calc + _ ≤ ∑i, ∑j, |v i*A i j*v j| := by + rw [hq] + exact (abs_sum_le_sum_abs _ _).trans (sum_le_sum fun i _ => abs_sum_le_sum_abs _ _) + _ ≤ η*(∑i, |v i|)^2 := hh + _ ≤ _ := by nlinarith only [mul_le_mul_of_nonneg_left hcs hη] + +lemma difference_outer_centered {a b : Fin n} (hab : a ≠ b) (v : Fin n → ℝ) : + qform (vecMulVec (difference a b) (difference a b)) v ≤ + 2*(∑i, (centering n *ᵥ v) i^2) := by + have h := difference_outer_le hab (centering n *ᵥ v) + rwa [qform_outer,centered_dot _ _ (difference_sum a b),←qform_outer] at h + +lemma abs_triangle_energy (ijk : DistinctTriple n) (v : Fin n → ℝ) : + |qform (triangleGenerator ijk) v| ≤ 6*(∑i, (centering n *ᵥ v) i^2) := by + have h1 := difference_outer_centered ijk.property.1 v + have h2 := difference_outer_centered ijk.property.2.1 v + have h3 := difference_outer_centered ijk.property.2.2 v + have h1n := qform_nonneg (ShortcutDual.outer_posSemidef (difference ijk.1.1 ijk.1.2.1)) v + have h2n := qform_nonneg (ShortcutDual.outer_posSemidef (difference ijk.1.2.1 ijk.1.2.2)) v + have h3n := qform_nonneg (ShortcutDual.outer_posSemidef (difference ijk.1.1 ijk.1.2.2)) v + rw [triangleGenerator,triangleMatrix,qform_sub,qform_add] + apply abs_le.mpr + constructor <;> linarith only [h1,h2,h3,h1n,h2n,h3n] + +lemma distinctTriple_card_le : Fintype.card (DistinctTriple n) ≤ n^3 := by + have h := Fintype.card_subtype_le (fun p : Fin n × Fin n × Fin n => + p.1 ≠ p.2.1 ∧ p.2.1 ≠ p.2.2 ∧ p.1 ≠ p.2.2) + simpa only [Fintype.card_prod,Fintype.card_fin,pow_succ,pow_zero,one_mul,mul_assoc] using h + +lemma abs_triangle_sum {lam : DistinctTriple n → ℝ} {η : ℝ} + (hη : 0 ≤ η) (hlam : ∀ijk, |lam ijk| ≤ η) (v : Fin n → ℝ) : + |qform (∑ijk, lam ijk • triangleGenerator ijk) v| ≤ + 6*(n : ℝ)^3*η*(∑i, (centering n *ᵥ v) i^2) := by + simp only [qform_sum,qform_smul] + calc + _ ≤ ∑ijk, |lam ijk*qform (triangleGenerator ijk) v| := abs_sum_le_sum_abs _ _ + _ ≤ ∑ijk : DistinctTriple n, η*(6*(∑i, (centering n *ᵥ v) i^2)) := by + apply sum_le_sum + intro ijk _ + rw [abs_mul] + exact mul_le_mul (hlam ijk) (abs_triangle_energy ijk v) (abs_nonneg _) hη + _ = (Fintype.card (DistinctTriple n) : ℝ)*η*6*(∑i, (centering n *ᵥ v) i^2) := by + simp only [sum_const,card_univ,nsmul_eq_mul]; ring + _ ≤ _ := by + have hc : (Fintype.card (DistinctTriple n) : ℝ) ≤ (n : ℝ)^3 := by exact_mod_cast distinctTriple_card_le (n:=n) + nlinarith only [mul_le_mul_of_nonneg_right hc + (show 0 ≤ η*6*(∑i, (centering n *ᵥ v) i^2) by positivity)] + +lemma lowerPencil_hermitian (H : MultiGraph n m) (x : StepFree n m) : + (x.lowerPencil H).IsHermitian := + (responseMatrix_hermitian x.1).sub (H.laplacian_psd univ).isHermitian + +lemma upperPencil_hermitian (H : MultiGraph n m) (x : StepFree n m) : + (x.upperPencil H).IsHermitian := by + apply ((H.laplacian_psd univ).smul (by norm_num : (0 : ℝ) ≤ 3)).isHermitian.sub (responseMatrix_hermitian x.1) |>.sub + change (∑ijk, x.multiplier ijk • triangleGenerator ijk)ᴴ = _ + rw [conjTranspose_sum] + apply sum_congr rfl + intro ijk _ + exact (triangleMatrix_hermitian _ _ _).smul (by rfl) + +lemma edgePencil_hermitian (H : MultiGraph n m) (s : ℝ) (x : StepFree n m) (e : Fin m) : + (x.edgePencil H s e).IsHermitian := + (responseMatrix_hermitian x.1).sub ((ShortcutDual.outer_posSemidef _).isHermitian.smul (by rfl)) + +namespace StepFree + +def Close (x w : StepFree n m) (η : ℝ) : Prop := + (∀i j, |x.1 i j-w.1 i j| ≤ η) ∧ + (∀ijk, |x.multiplier ijk-w.multiplier ijk| ≤ η) ∧ + (∀e, |x.y e-w.y e| ≤ η) ∧ (∀e, |x.z e-w.z e| ≤ η) + +lemma Close.symm {x w : StepFree n m} {η : ℝ} (h : Close x w η) : Close w x η := by + simpa only [Close,abs_sub_comm] using h + +lemma Close.mono {x w : StepFree n m} {η δ : ℝ} (h : Close x w η) (hηδ : η ≤ δ) : Close x w δ := + ⟨fun i j => (h.1 i j).trans hηδ,fun ijk => (h.2.1 ijk).trans hηδ, + fun e => (h.2.2.1 e).trans hηδ,fun e => (h.2.2.2 e).trans hηδ⟩ + +lemma Close.qform_bound {x w : StepFree n m} {η : ℝ} + (hη : 0 ≤ η) (h : Close x w η) (v : Fin n → ℝ) : + |qform x.matrix v-qform w.matrix v| ≤ (n : ℝ)*η*(∑i, (centering n *ᵥ v) i^2) := by + rw [←qform_sub,matrix,matrix,←responseMatrix_sub,qform_responseMatrix] + exact abs_qform_le_entries hη h.1 _ + +lemma Close.lower_error (H : MultiGraph n m) {x w : StepFree n m} {η : ℝ} + (hη : 0 ≤ η) (h : Close x w η) (v : Fin n → ℝ) : + |qform (x.lowerPencil H) v-qform (w.lowerPencil H) v| ≤ + (n : ℝ)*η*(∑i, (centering n *ᵥ v) i^2) := by + simpa only [lowerPencil,qform_sub,sub_sub_sub_cancel_right] using h.qform_bound hη v + +lemma Close.upper_error (H : MultiGraph n m) {x w : StepFree n m} {η : ℝ} + (hη : 0 ≤ η) (h : Close x w η) (v : Fin n → ℝ) : + |qform (x.upperPencil H) v-qform (w.upperPencil H) v| ≤ + ((n : ℝ)+6*(n : ℝ)^3)*η*(∑i, (centering n *ᵥ v) i^2) := by + have h1 := h.qform_bound hη v + have h2 := abs_triangle_sum hη h.2.1 v + have he : qform (∑ijk, (x.multiplier ijk-w.multiplier ijk) • triangleGenerator ijk) v= + qform (∑ijk, x.multiplier ijk • triangleGenerator ijk) v- + qform (∑ijk, w.multiplier ijk • triangleGenerator ijk) v := by + simp only [sub_smul,sum_sub_distrib,qform_sub] + rw [he] at h2 + simp only [upperPencil,qform_sub] + have hb : ∀a b c d e : ℝ, |a-b-c-(a-d-e)| ≤ |b-d|+|c-e| := by + intro a b c d e + have h := abs_add_le (b-d) (c-e) + rwa [show a-b-c-(a-d-e) = -((b-d)+(c-e)) by ring,abs_neg] + exact (hb _ _ _ _ _).trans (by nlinarith only [h1,h2]) + +lemma Close.edge_error (H : MultiGraph n m) {x w : StepFree n m} {η : ℝ} + {s : ℝ} (hs : 0 ≤ s) (hη : 0 ≤ η) (h : Close x w η) (e : Fin m) (v : Fin n → ℝ) : + |qform (x.edgePencil H s e) v-qform (w.edgePencil H s e) v| ≤ + ((n : ℝ)+12*s)*η*(∑i, (centering n *ᵥ v) i^2) := by + have h1 := h.qform_bound hη v + have h2 := difference_outer_centered (H.loopless e) v + have hn := qform_nonneg (ShortcutDual.outer_posSemidef (H.incidence e)) v + have hy := h.2.2.1 e + have hr : |6*s*(x.y e-w.y e)*qform (vecMulVec (H.incidence e) (H.incidence e)) v| ≤ + 12*s*η*(∑i, (centering n *ᵥ v) i^2) := by + rw [abs_mul,abs_mul,abs_of_nonneg (by positivity : 0 ≤ 6*s),abs_of_nonneg hn] + have hb := mul_le_mul hy h2 hn hη + change |x.y e-w.y e| *qform (vecMulVec (H.incidence e) (H.incidence e)) v ≤ _ at hb + nlinarith only [mul_le_mul_of_nonneg_left hb (show 0 ≤ 6*s by positivity)] + simp only [edgePencil,qform_sub,qform_smul] + have hrewrite : qform x.matrix v-6*s*x.y e*qform (vecMulVec (H.incidence e) (H.incidence e)) v- + (qform w.matrix v-6*s*w.y e*qform (vecMulVec (H.incidence e) (H.incidence e)) v)= + (qform x.matrix v-qform w.matrix v)-6*s*(x.y e-w.y e)*qform (vecMulVec (H.incidence e) (H.incidence e)) v := by ring + rw [hrewrite] + exact (abs_sub _ _).trans (by nlinarith only [h1,hr]) + +end StepFree + +lemma scaled_inverse_power {P c : ℝ} (hP : 0 < P) (a b : ℕ) (hc : c ≤ P^b) : + c*P^(-((a+b : ℕ) : ℤ)) ≤ P^(-(a : ℤ)) := by + have h := mul_le_mul_of_nonneg_right hc (zpow_nonneg hP.le (-((a+b : ℕ) : ℤ))) + calc + _ ≤ P^b*P^(-((a+b : ℕ) : ℤ)) := h + _ = _ := by + rw [←zpow_natCast,←zpow_add₀ (ne_of_gt hP)] + congr 1 + push_cast + ring + +lemma inverse_power_mono {P : ℝ} (hP : 1 ≤ P) {a b : ℕ} (hab : a ≤ b) : + P^(-(b : ℤ)) ≤ P^(-(a : ℤ)) := by + simp only [_root_.zpow_neg,zpow_natCast] + exact (inv_le_inv₀ (pow_pos (lt_of_lt_of_le zero_lt_one hP) _) + (pow_pos (lt_of_lt_of_le zero_lt_one hP) _)).mpr (pow_le_pow_right₀ hP hab) + +lemma auxiliary_numbers {P s κ : ℝ} (hP : 5 ≤ P) (hnP : (n : ℝ) ≤ P) + (_hs : 0 ≤ s) (hsP : s ≤ P) (hκ : P⁻¹ ≤ κ) : + let c := P^(-8 : ℤ) + let η := P^(-20 : ℤ) + let μ := P^(-3 : ℤ) + 0 < c ∧ 0 < η ∧ η ≤ c ∧ c+η ≤ 1 ∧ 4*η ≤ κ ∧ + (n : ℝ)*η ≤ μ ∧ + (n : ℝ)*η+6*(n : ℝ)^3*(c+η) ≤ μ ∧ + (n : ℝ)*η+12*s*(c+η) ≤ 2*μ := by + dsimp only + have hP0 : 0 < P := by linarith + have hP1 : 1 ≤ P := by linarith + have hc0 := zpow_pos hP0 (-8) + have hη0 := zpow_pos hP0 (-20) + have hηc : P^(-20 : ℤ) ≤ P^(-8 : ℤ) := inverse_power_mono hP1 (by norm_num : 8 ≤ 20) + have hP2 : 25 ≤ P^2 := by nlinarith only [hP,sq_nonneg (P-5)] + have hP4 : 25 ≤ P^4 := by + have hh : P^2 ≤ P^4 := pow_le_pow_right₀ hP1 (by norm_num) + exact hP2.trans hh + have hsmall := scaled_inverse_power hP0 0 8 (show (2 : ℝ) ≤ P^8 by + exact (by linarith : (2 : ℝ) ≤ P).trans (by simpa using pow_le_pow_right₀ hP1 (by norm_num : 1 ≤ 8))) + simp only [Nat.cast_zero,Nat.zero_add,neg_zero,zpow_zero,Nat.cast_ofNat] at hsmall + have hfour : 4*P^(-20 : ℤ) ≤ P⁻¹ := by + have hh := scaled_inverse_power hP0 1 19 (show (4 : ℝ) ≤ P^19 by + exact (by linarith : (4 : ℝ) ≤ P).trans (by simpa using pow_le_pow_right₀ hP1 (by norm_num : 1 ≤ 19))) + simpa using hh + have hnη : (n : ℝ)*P^(-20 : ℤ) ≤ P^(-8 : ℤ) := by + calc + _ ≤ P*P^(-20 : ℤ) := mul_le_mul_of_nonneg_right hnP hη0.le + _ = P^(-19 : ℤ) := by simpa using (zpow_add₀ (ne_of_gt hP0) 1 (-20)).symm + _ ≤ _ := inverse_power_mono hP1 (by norm_num : 8 ≤ 19) + have hn3 : (n : ℝ)^3 ≤ P^3 := pow_le_pow_left₀ (Nat.cast_nonneg _) hnP 3 + have hP3 : 1 ≤ P^3 := one_le_pow₀ hP1 + have hu : 13*P^(-5 : ℤ) ≤ P^(-3 : ℤ) := by + simpa using scaled_inverse_power hP0 3 2 (show (13 : ℝ) ≤ P^2 by linarith) + have he : 25*P^(-7 : ℤ) ≤ P^(-3 : ℤ) := by + simpa using scaled_inverse_power hP0 3 4 hP4 + have hupper : (n : ℝ)*P^(-20 : ℤ)+6*(n : ℝ)^3*(P^(-8 : ℤ)+P^(-20 : ℤ)) ≤ P^(-3 : ℤ) := by + calc + _ ≤ P^(-8 : ℤ)+12*P^3*P^(-8 : ℤ) := by + have hh := mul_le_mul hn3 (show P^(-8 : ℤ)+P^(-20 : ℤ) ≤ 2*P^(-8 : ℤ) by linarith) + (by positivity) (by positivity : 0 ≤ P^3) + nlinarith only [hnη,hh] + _ ≤ 13*P^3*P^(-8 : ℤ) := by nlinarith only [mul_le_mul_of_nonneg_right hP3 hc0.le] + _ = 13*P^(-5 : ℤ) := by rw [mul_assoc,←zpow_natCast,←zpow_add₀ (ne_of_gt hP0)]; norm_num + _ ≤ _ := hu + have hedge : (n : ℝ)*P^(-20 : ℤ)+12*s*(P^(-8 : ℤ)+P^(-20 : ℤ)) ≤ P^(-3 : ℤ) := by + calc + _ ≤ P^(-8 : ℤ)+24*P*P^(-8 : ℤ) := by + have hh := mul_le_mul hsP (show P^(-8 : ℤ)+P^(-20 : ℤ) ≤ 2*P^(-8 : ℤ) by linarith) + (by positivity) hP0.le + nlinarith only [hnη,hh] + _ ≤ 25*P*P^(-8 : ℤ) := by nlinarith only [mul_le_mul_of_nonneg_right hP1 hc0.le] + _ = 25*P^(-7 : ℤ) := by + rw [mul_assoc] + congr 1 + simpa using (zpow_add₀ (ne_of_gt hP0) 1 (-8)).symm + _ ≤ _ := he + exact ⟨hc0,hη0,hηc,by linarith,hfour.trans hκ, + hnη.trans (inverse_power_mono hP1 (by norm_num : 3 ≤ 8)),hupper, + hedge.trans (le_mul_of_one_le_left (zpow_nonneg hP0.le _) (by norm_num))⟩ + +def auxiliaryPoint (H : MultiGraph n m) (κ : ℝ) : StepFree n m := + ((2 : ℝ) • H.laplacian univ,fun _ => (graphSize n m)^(-8 : ℤ), + fun _ => (graphSize n m)^(-8 : ℤ),fun _ => κ/2) + +lemma auxiliaryPoint_matrix (H : MultiGraph n m) {κ : ℝ} : + (auxiliaryPoint H κ).matrix=(2 : ℝ) • H.laplacian univ := by + apply responseMatrix_fixed ((H.laplacian_psd univ).smul (by norm_num : (0 : ℝ) ≤ 2)).isHermitian + rw [smul_mulVec,laplacian_ones,smul_zero] + +lemma connected_size_five (H : MultiGraph n m) (hn : 2 ≤ n) (hc : H.Connected univ) : + 5 ≤ graphSize n m := by + have hm : 0 < m := by + have hproper : ({⟨0,by omega⟩} : Finset (Fin n)) ≠ univ := by + intro h + have hh := congrArg Finset.card h + simp only [card_singleton,card_univ,Fintype.card_fin] at hh + omega + obtain ⟨e,_⟩ := hc _ (singleton_nonempty _) hproper + exact Nat.zero_lt_of_lt e.isLt + dsimp [graphSize] + have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn + have hmR : (1 : ℝ) ≤ m := by exact_mod_cast hm + linarith + +lemma baseline_lower : (graphSize n m)⁻¹ ≤ continuationBaseline m := by + rw [continuationBaseline,one_div] + exact (inv_le_inv₀ graphSize_pos (by positivity : (0 : ℝ) < m+1)).mpr (by + dsimp [graphSize] + have : (0 : ℝ) ≤ n := Nat.cast_nonneg _ + linarith) + +theorem auxiliary_cube (H : MultiGraph n m) (hn : 2 ≤ n) (hc : H.Connected univ) + {s : ℝ} (hs : 0 ≤ s) (hsP : s ≤ graphSize n m) + (u : Fin m → ℝ) (hu0 : ∀e, 0 ≤ u e) + {x : StepFree n m} + (hx : x.Close (auxiliaryPoint H (continuationBaseline m)) ((graphSize n m)^(-20 : ℤ))) : + x ∈ stepCore H s (continuationBaseline m) (continuationStep m) u := by + let P := graphSize n m + let c := P^(-8 : ℤ) + let η := P^(-20 : ℤ) + let μ := P^(-3 : ℤ) + let κ := continuationBaseline m + have hP := connected_size_five H hn hc + have hnP : (n : ℝ) ≤ P := by dsimp [P,graphSize]; linarith [Nat.cast_nonneg (α:=ℝ) m] + obtain ⟨hc0,hη0,hηc,hcy,hηκ,hl,hu,he⟩ := auxiliary_numbers hP hnP hs hsP (baseline_lower (n:=n) (m:=m)) + have hκ0 : 0 < κ := (continuation_parameters m).1 + have hlam (ijk : DistinctTriple n) : 0 ≤ x.multiplier ijk ∧ |x.multiplier ijk| ≤ c+η := by + have hh := abs_le.mp (hx.2.1 ijk) + change -(η) ≤ x.multiplier ijk-c ∧ x.multiplier ijk-c ≤ η at hh + have hl : 0 ≤ x.multiplier ijk := by linarith only [hh.1,hηc] + refine ⟨hl,?_⟩ + rw [abs_of_nonneg hl] + linarith only [hh.2] + have hy (e : Fin m) : 0 ≤ x.y e ∧ x.y e ≤ c+η := by + have hh := abs_le.mp (hx.2.2.1 e) + change -η ≤ x.y e-c ∧ x.y e-c ≤ η at hh + constructor <;> linarith only [hh.1,hh.2,hηc] + have hz (e : Fin m) : κ/2-η ≤ x.z e ∧ x.z e ≤ κ/2+η := by + have hh := abs_le.mp (hx.2.2.2 e) + change -η ≤ x.z e-κ/2 ∧ x.z e-κ/2 ≤ η at hh + constructor <;> linarith only [hh.1,hh.2] + have henergy (v : Fin n → ℝ) : μ*(∑i, (centering n *ᵥ v) i^2) ≤ qform (H.laplacian univ) v := by + simpa only [qform_smul,qform_centering_sum_sq (by omega : 0 < n)] using + qform_mono (laplacian_lower_order H (by omega) hc) v + have herror (v : Fin n → ℝ) : + |qform x.matrix v-2*qform (H.laplacian univ) v| ≤ + (n : ℝ)*η*(∑i, (centering n *ᵥ v) i^2) := by + simpa only [auxiliaryPoint_matrix,qform_smul] using hx.qform_bound hη0.le v + refine ⟨?_,?_,fun ijk => (hlam ijk).1,fun e => ⟨(hy e).1,(hy e).2.trans hcy⟩,?_,?_⟩ + · apply PosSemidef.of_dotProduct_mulVec_nonneg (lowerPencil_hermitian H x) + intro v + change 0 ≤ qform (x.lowerPencil H) v + rw [StepFree.lowerPencil,qform_sub] + have hb := (abs_le.mp (herror v)).1 + have he := mul_le_mul_of_nonneg_right hl (show 0 ≤ ∑i, (centering n *ᵥ v) i^2 by positivity) + linarith only [hb,he,henergy v] + · apply PosSemidef.of_dotProduct_mulVec_nonneg (upperPencil_hermitian H x) + intro v + change 0 ≤ qform (x.upperPencil H) v + rw [StepFree.upperPencil,qform_sub,qform_sub,qform_smul] + have hb := (abs_le.mp (herror v)).2 + have hT := (abs_le.mp (abs_triangle_sum (show 0 ≤ c+η by positivity) (fun ijk => (hlam ijk).2) v)).2 + have he := mul_le_mul_of_nonneg_right hu (show 0 ≤ ∑i, (centering n *ᵥ v) i^2 by positivity) + change ((n : ℝ)*η+6*(n : ℝ)^3*(c+η))*(∑i, (centering n *ᵥ v) i^2) ≤ _ at he + linarith only [hb,hT,he,henergy v] + · intro e + exact ⟨by linarith only [(hz e).1,hηκ,hκ0],by linarith only [(hz e).2,hηκ,hκ0]⟩ + · intro e _ + refine ⟨?_,?_⟩ + · apply PosSemidef.of_dotProduct_mulVec_nonneg (edgePencil_hermitian H s x e) + intro v + change 0 ≤ qform (x.edgePencil H s e) v + rw [StepFree.edgePencil,qform_sub,qform_smul] + have hb := (abs_le.mp (herror v)).1 + have hE : 0 ≤ ∑i, (centering n *ᵥ v) i^2 := by positivity + have hn0 := qform_nonneg (ShortcutDual.outer_posSemidef (H.incidence e)) v + have hR := mul_le_mul (hy e).2 (difference_outer_centered (H.loopless e) v) hn0 (by positivity : 0 ≤ c+η) + have hR' := mul_le_mul_of_nonneg_left hR (show 0 ≤ 6*s by positivity) + change 6*s*(x.y e*qform (vecMulVec (H.incidence e) (H.incidence e)) v) ≤ _ at hR' + have he' := mul_le_mul_of_nonneg_right he hE + change ((n : ℝ)*η+12*s*(c+η))*(∑i, (centering n *ᵥ v) i^2) ≤ _ at he' + linarith only [hb,hR',he',henergy v] + · have hgain : 0 ≤ (κ/32)*x.y e := mul_nonneg (by positivity) (hy e).1 + change x.z e ≤ κ+u e+(κ/32)*(5*x.y e-4) + nlinarith only [(hz e).2,hηκ,hκ0,hu0 e,hgain] + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Iteration.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Iteration.lean new file mode 100644 index 0000000000000000000000000000000000000000..a74a677196eaea826de27330c03c25a4ea445daa --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Iteration.lean @@ -0,0 +1,272 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Search + +namespace OAI + +/-! Continuation iteration. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped MatrixOrder +variable {n m : ℕ} + +lemma continuation_ramp_lower_of_le (G : MultiGraph n m) (hn : 0 < n) + (hconn : G.Connected univ) + {X Y : Matrix (Fin n) (Fin n) ℝ} + (hX : X ∈ metricDomain G) (hY : Y ∈ metricDomain G) + {s t κ : ℝ} (hs : 0 < s) (ht : 0 ≤ t) (ht1 : t ≤ 1/5) + (u y : Fin m → ℝ) (hur : ∀e, u e ≤ ramp G s X e) (hy : ∀e, 0 ≤ y e) + (hresp : ∀e, 0 < u e → + (6*s*y e) • vecMulVec (G.incidence e) (G.incidence e) ≤ Y) : + (1-t) • X+t • Y ∈ metricDomain G ∧ ∀e, + lowerCapacity κ t (u e) (y e) ≤ + ramp G ((1+t)*s) ((1-t) • X+t • Y) e+κ := by + have hnext := domain_convex G hX hY (by linarith : 0 ≤ 1-t) ht (by ring : 1-t+t=1) + refine ⟨hnext,?_⟩ + intro e + by_cases ha : 0 < u e + · rw [lowerCapacity,ite_eq_left ha] + have har : 0 < ramp G s X e := ha.trans_le (hur e) + have hr := continuation_reciprocal G hn (domain_positive G hn hconn hX) + hs ht ht1 (hy e) e (hresp e ha) (domain_positive G hn hconn hnext) + have hscalar := ramp_scalar_lower (ramp_active G har).1 ht ht1 + (cappedParameter_le_two G s X e) (hy e) hr + change min 1 (ramp G s X e+t*(5*y e-4)) ≤ + ramp G ((1+t)*s) ((1-t) • X+t • Y) e at hscalar + have hh := (min_le_min_left (1:ℝ) (show u e+t*(5*y e-4) ≤ ramp G s X e+t*(5*y e-4) by linarith only [hur e])).trans hscalar + linarith only [hh] + · rw [lowerCapacity,ite_eq_right ha] + linarith only [ramp_nonneg G ((1+t)*s) ((1-t) • X+t • Y) e] + +lemma stepFeasible_mono_target (H : MultiGraph n m) (hn : 0 < n) + {s κ t q q' : ℝ} {u : Fin m → ℝ} {x : StepFree n m} + (hx : x ∈ stepFeasible H s κ t q u) (hqq : q' ≤ q) : + x ∈ stepFeasible H s κ t q' u := by + have : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + refine ⟨hx.1,fun p => (hx.2 p).trans ?_⟩ + unfold slack + apply sub_le_sub_left + exact mul_le_mul_of_nonneg_right hqq (by + have hh : (1:ℝ) ≤ partCount p := by exact_mod_cast partCount_pos p + linarith only [hh]) + +noncomputable def StepFree.nextCapacity (x : StepFree n m) (κ : ℝ) (u : Fin m → ℝ) (e : Fin m) : ℝ := + max 0 (x.capacities κ u e-κ) + +lemma StepFree.nextCapacity_nonneg (x : StepFree n m) (κ : ℝ) (u : Fin m → ℝ) (e : Fin m) : + 0 ≤ x.nextCapacity κ u e := le_max_left _ _ + +lemma StepFree.nextCapacity_bounds (H : MultiGraph n m) + {s κ t : ℝ} {u : Fin m → ℝ} {x : StepFree n m} + (hx : x ∈ stepCore H s κ t u) (e : Fin m) : + x.nextCapacity κ u e ≤ 1 ∧ x.capacities κ u e ≤ x.nextCapacity κ u e+κ := by + have he : x.capacities κ u e ≤ κ+1 := by + unfold StepFree.capacities + split_ifs + · exact (hx.2.2.2.2.1 e).2 + · linarith + refine ⟨max_le (by norm_num) (by linarith only [he]),?_⟩ + have hh := le_max_right (0:ℝ) (x.capacities κ u e-κ) + change x.capacities κ u e ≤ max 0 (x.capacities κ u e-κ)+κ + linarith only [hh] + +theorem stepFeasible_update (H : MultiGraph n m) (hn : 0 < n) (hconn : H.Connected univ) + {s κ t q : ℝ} (hs : 0 < s) (ht : 0 ≤ t) (ht1 : t ≤ 1/5) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : X ∈ metricDomain H) + (u : Fin m → ℝ) (hur : ∀e, u e ≤ ramp H s X e) + {x : StepFree n m} (hx : x ∈ stepFeasible H s κ t q u) : + (1-t) • X+t • x.matrix ∈ metricDomain H ∧ + (∀e, x.nextCapacity κ u e ≤ ramp H ((1+t)*s) ((1-t) • X+t • x.matrix) e) ∧ + (∀e, 0 ≤ x.nextCapacity κ u e ∧ x.nextCapacity κ u e ≤ 1) ∧ + ∀p, 0 ≤ slack H.left H.right (fun e => x.nextCapacity κ u e+κ) q p := by + have had := stepCore_admissible H hn hx.1 + obtain ⟨hnew,hramp⟩ := continuation_ramp_lower_of_le H hn hconn hX had.1 hs ht ht1 + u x.y hur (fun e => (had.2.1 e).1) had.2.2 + refine ⟨hnew,?_,?_,?_⟩ + · intro e + apply max_le (ramp_nonneg _ _ _ _) + have hh := (stepCore_capacity_le H hx.1 e).trans (hramp e) + linarith only [hh] + · intro e + exact ⟨x.nextCapacity_nonneg κ u e,(x.nextCapacity_bounds H hx.1 e).1⟩ + · intro p + apply (hx.2 p).trans + unfold slack capacity + apply sub_le_sub_right + apply sum_le_sum + intro e _ + exact mul_le_mul_of_nonneg_right (x.nextCapacity_bounds H hx.1 e).2 + (crossingIndicator_nonneg _ _ _) + +end AlgorithmicThinTrees.MetricTests + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped MatrixOrder +variable {n m : ℕ} + +lemma search_error_le_step (H : MultiGraph n m) (hn : 2 ≤ n) (hc : H.Connected univ) : + 4*(errorQ n m:ℝ) ≤ (stepQ m:ℝ) := by + have hP := connected_size_five H hn hc + have hP0 := graphSize_pos (n:=n) (m:=m) + have hpow : (128:ℝ) ≤ (graphSize n m)^9 := calc + _ ≤ (5:ℝ)^9 := by norm_num + _ ≤ _ := pow_le_pow_left₀ (by norm_num) hP 9 + have hh := scaled_inverse_power hP0 1 9 hpow + norm_num only [Nat.cast_ofNat,Nat.reduceAdd,_root_.zpow_neg_one] at hh + have hbase := baseline_lower (n:=n) (m:=m) + rw [cast_stepQ,cast_errorQ,continuationStep] + linarith only [hh,hbase] + +def target (m r : ℕ) (Q g : ℚ) : ℚ := Q-g*r*stepQ m-2*stepQ m + +lemma cast_target (m r : ℕ) (Q g : ℚ) : + (target m r Q g:ℝ)=(Q:ℝ)-(g:ℝ)*r*continuationStep m-2*continuationStep m := by + simp only [target,Rat.cast_sub,Rat.cast_mul,Rat.cast_natCast,Rat.cast_ofNat,cast_stepQ] + +theorem uniform_search_response : + ∃r0 : ℕ, 8 ≤ r0 ∧ ∀r : ℕ, r0 ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.Connected univ → r ≤ m → + ∀(u : Fin m → ℚ), (∀e, 0 ≤ (u e:ℝ)) → (∀e, (u e:ℝ) ≤ 1) → + ∀(s Q g : ℚ), 0 < (s:ℝ) → (s:ℝ) ≤ (r:ℝ)^(1/4:ℝ) → + 3*(r:ℝ)/4 ≤ (Q:ℝ) → (Q:ℝ) ≤ r → + (r:ℝ)^(-1/8:ℝ) ≤ (g:ℝ) → (g:ℝ) ≤ 2*(r:ℝ)^(-1/8:ℝ) → + 3 ≤ (g:ℝ)*r → + (∀p, 0 ≤ slack H.left H.right (fun e => (u e:ℝ)+continuationBaseline m) (Q:ℝ) p) → + (rational (search H s (target m r Q g) u)).real ∈ + stepFeasible H (s:ℝ) (continuationBaseline m) (continuationStep m) + ((Q:ℝ)-2*(g:ℝ)*r*continuationStep m) (fun e => (u e:ℝ)) := by + obtain ⟨r0,hr0,hr⟩ := feasible_continuation_response + refine ⟨r0,hr0,?_⟩ + intro r hrr n m H hn hc hrm u hu0 hu1 s Q g hs hsr hQ hQr hg hgg hgr hinv + have hr8 : (8:ℝ) ≤ r := by exact_mod_cast hr0.trans hrr + have hr1 : (1:ℝ) ≤ r := by linarith only [hr8] + have hg0 : 0 ≤ (g:ℝ) := (Real.rpow_nonneg (Nat.cast_nonneg r) _).trans hg + have hg2 : (g:ℝ) ≤ 2 := by + have hp := Real.rpow_le_one_of_one_le_of_nonpos hr1 (by norm_num : (-1/8:ℝ) ≤ 0) + linarith only [hp,hgg] + obtain ⟨hκ,hκ1,hκm,ht,ht1,hκt,htm⟩ := continuation_parameters m + have hsP : (s:ℝ) ≤ graphSize n m := calc + _ ≤ (r:ℝ)^(1/4:ℝ) := hsr + _ ≤ (r:ℝ)^((1:ℝ)) := Real.rpow_le_rpow_of_exponent_le hr1 (by norm_num) + _ = r := Real.rpow_one _ + _ ≤ m := by exact_mod_cast hrm + _ ≤ _ := by unfold graphSize; linarith only [Nat.cast_nonneg (α:=ℝ) n] + have hβ : (graphSize n m)⁻¹/32 ≤ continuationStep m := by + unfold continuationStep + linarith only [baseline_lower (n:=n) (m:=m)] + have hgrt : 0 ≤ (g:ℝ)*r*continuationStep m := by positivity + have hq : (graphSize n m)^(-12:ℤ) ≤ (target m r Q g:ℝ) := by + have hP1 : 1 ≤ graphSize n m := by linarith only [connected_size_five H hn hc] + have hpinv : (graphSize n m)^(-12:ℤ) ≤ 1 := zpow_le_one_of_nonpos₀ hP1 (by norm_num) + have hgt := mul_le_mul hg2 ht1 ht (by norm_num : (0:ℝ) ≤ 2) + have hh := mul_le_mul_of_nonneg_right hgt (Nat.cast_nonneg r) + rw [cast_target] + nlinarith only [hpinv,hh,hr8,hQ,ht1] + have hqm : (target m r Q g:ℝ)+continuationStep m ≤ m := by + have hm : (r:ℝ) ≤ m := by exact_mod_cast hrm + rw [cast_target] + linarith only [hQr,hm,hgrt,ht] + obtain ⟨w,hw,hp⟩ := hr r hrr n m H hn hc (fun e => (u e:ℝ)) hu0 hu1 + s Q g hs hsr hQ hQr hg hgg hinv + obtain ⟨z,hz,_,_⟩ := response_to_stepFeasible H (by omega) ht hκt hw hp + have hz' : z ∈ stepFeasible H (s:ℝ) (continuationBaseline m) (continuationStep m) + ((target m r Q g:ℝ)+continuationStep m+continuationStep m) (fun e => (u e:ℝ)) := by + rw [cast_target] + convert hz using 1 + ring_nf + have hout := search_sound H hn hc s (target m r Q g) (continuationStep m) u + hs.le hsP hq hqm hβ hu0 hz' + apply stepFeasible_mono_target H (by omega) hout + rw [cast_target] + have hh := mul_le_mul_of_nonneg_right hgr ht + have he := search_error_le_step H hn hc + rw [cast_stepQ] at he + nlinarith only [hh,he] + +def qresponse (A : Matrix (Fin n) (Fin n) ℚ) : Matrix (Fin n) (Fin n) ℚ := + qproject n*((1/2:ℚ) • (A+Aᵀ))*qproject n + +lemma cast_qresponse (A : Matrix (Fin n) (Fin n) ℚ) : + (qresponse A).map (fun a => (a:ℝ))=responseMatrix (A.map (fun a => (a:ℝ))) := by + ext i j + simp only [qresponse,Matrix.map_apply,Matrix.mul_apply,Rat.cast_sum,Rat.cast_mul, + Matrix.smul_apply,Matrix.add_apply,Matrix.transpose_apply,smul_eq_mul, + Rat.cast_div,Rat.cast_one,Rat.cast_ofNat,Rat.cast_add,cast_qproject, + responseMatrix,centered] + +structure State (n m : ℕ) where + scale : ℚ + quality : ℚ + matrix : Matrix (Fin n) (Fin n) ℚ + capacity : Fin m → ℚ + +def update (H : MultiGraph n m) (r : ℕ) (g : ℚ) (a : State n m) : State n m := + let v := search H a.scale (target m r a.quality g) a.capacity + { scale := (1+stepQ m)*a.scale + quality := a.quality-2*g*r*stepQ m + matrix := (1-stepQ m) • a.matrix+stepQ m • qresponse (rawMatrix v) + capacity := fun e => if 0 < a.capacity e then max 0 (z v e-baselineQ m) else 0 } + +noncomputable def State.realMatrix (a : State n m) : Matrix (Fin n) (Fin n) ℝ := + a.matrix.map (fun q => (q:ℝ)) + +def Invariant (H : MultiGraph n m) (a : State n m) : Prop := + 0 < (a.scale:ℝ) ∧ a.realMatrix ∈ metricDomain H ∧ + (∀e, 0 ≤ (a.capacity e:ℝ) ∧ (a.capacity e:ℝ) ≤ 1 ∧ + (a.capacity e:ℝ) ≤ ramp H (a.scale:ℝ) a.realMatrix e) ∧ + ∀p, 0 ≤ slack H.left H.right (fun e => (a.capacity e:ℝ)+continuationBaseline m) + (a.quality:ℝ) p + +lemma update_realMatrix (H : MultiGraph n m) (r : ℕ) (g : ℚ) (a : State n m) : + (update H r g a).realMatrix=(1-continuationStep m) • a.realMatrix+ + continuationStep m • (rational (search H a.scale (target m r a.quality g) a.capacity)).real.matrix := by + have hh := cast_qresponse (rawMatrix (search H a.scale (target m r a.quality g) a.capacity)) + ext i j + change ((((1-stepQ m)*a.matrix i j+stepQ m*_) : ℚ) : ℝ)=_ + simp only [Rat.cast_add,Rat.cast_mul,Rat.cast_sub,Rat.cast_one,cast_stepQ] + have hhi := congrFun (congrFun hh i) j + exact congrArg (fun z : ℝ => (1-continuationStep m)*a.realMatrix i j+continuationStep m*z) hhi + +lemma update_capacity (H : MultiGraph n m) (r : ℕ) (g : ℚ) (a : State n m) (e : Fin m) : + ((update H r g a).capacity e:ℝ)= + (rational (search H a.scale (target m r a.quality g) a.capacity)).real.nextCapacity + (continuationBaseline m) (fun f => (a.capacity f:ℝ)) e := by + simp only [update,StepFree.nextCapacity,StepFree.capacities] + by_cases he : 0 < a.capacity e + · have heR : 0 < (a.capacity e:ℝ) := by exact_mod_cast he + simp only [ite_eq_left he,ite_eq_left heR,Rat.cast_max,Rat.cast_zero,Rat.cast_sub,cast_baselineQ] + rfl + · have heR : ¬0 < (a.capacity e:ℝ) := by exact_mod_cast he + simp only [ite_eq_right he,ite_eq_right heR,Rat.cast_zero,sub_self,max_self] + +lemma update_invariant (H : MultiGraph n m) (hn : 0 < n) (hc : H.Connected univ) + (r : ℕ) (g : ℚ) (a : State n m) (ha : Invariant H a) + (hv : (rational (search H a.scale (target m r a.quality g) a.capacity)).real ∈ + stepFeasible H (a.scale:ℝ) (continuationBaseline m) (continuationStep m) + ((a.quality:ℝ)-2*(g:ℝ)*r*continuationStep m) (fun e => (a.capacity e:ℝ))) : + Invariant H (update H r g a) := by + have ht := (continuation_parameters m).2.2.2.1 + have ht1 := (continuation_parameters m).2.2.2.2.1 + have hh := stepFeasible_update H hn hc ha.1 ht (by linarith : continuationStep m ≤ 1/5) + ha.2.1 (fun e => (a.capacity e:ℝ)) (fun e => (ha.2.2.1 e).2.2) hv + have hs : ((update H r g a).scale:ℝ)=(1+continuationStep m)*(a.scale:ℝ) := by + simp only [update,Rat.cast_mul,Rat.cast_add,Rat.cast_one,cast_stepQ] + have hq : ((update H r g a).quality:ℝ)=(a.quality:ℝ)-2*(g:ℝ)*r*continuationStep m := by + simp only [update,Rat.cast_sub,Rat.cast_mul,Rat.cast_ofNat,Rat.cast_natCast,cast_stepQ] + refine ⟨?_,?_,?_,?_⟩ + · rw [hs] + exact mul_pos (by linarith only [ht]) ha.1 + · rw [update_realMatrix] + exact hh.1 + · intro e + rw [update_capacity,hs,update_realMatrix] + exact ⟨(hh.2.2.1 e).1,(hh.2.2.1 e).2,hh.2.1 e⟩ + · simpa only [update_capacity,hq] using hh.2.2.2 + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Loop.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Loop.lean new file mode 100644 index 0000000000000000000000000000000000000000..b00a3640ac31b86316c853752c7bad1aeba4a029 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Loop.lean @@ -0,0 +1,130 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Schedule +import OAI.Combinatorics.ThinTrees.Continuation.Start + +namespace OAI + +/-! Continuation loop. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped MatrixOrder +variable {n m : ℕ} + +def advance (H : MultiGraph n m) (r : ℕ) (a : State n m) : State n m := + if a.scale^4 < (r:ℚ) then update H r (gain r) a else a + +def stateAt (H : MultiGraph n m) (r i : ℕ) : State n m := + (advance H r)^[i] (initial H r) + +def extractState (H : MultiGraph n m) (r : ℕ) : State n m := + stateAt H r (scheduleLength m r) + +lemma stateAt_zero (H : MultiGraph n m) (r : ℕ) : stateAt H r 0=initial H r := rfl + +lemma stateAt_succ (H : MultiGraph n m) (r i : ℕ) : + stateAt H r (i+1)=advance H r (stateAt H r i) := Function.iterate_succ_apply' _ _ _ + +lemma active_scale_bound {a : State n m} {r : ℕ} (ha : 0 < (a.scale:ℝ)) + (hactive : a.scale^4 < (r:ℚ)) : (a.scale:ℝ) ≤ (r:ℝ)^(1/4:ℝ) := by + rw [one_div,Real.le_rpow_inv_iff_of_pos ha.le (Nat.cast_nonneg _) (by norm_num : (0:ℝ)<4),Real.rpow_ofNat] + exact_mod_cast hactive.le + +lemma advance_quality (H : MultiGraph n m) (r : ℕ) (a : State n m) : + (a.quality:ℝ)-2*(gain r:ℝ)*r*continuationStep m ≤ ((advance H r a).quality:ℝ) ∧ + ((advance H r a).quality:ℝ) ≤ (a.quality:ℝ) := by + have hg : 0 ≤ (gain r:ℝ) := by simp only [gain,Rat.cast_div,Rat.cast_one,Rat.cast_natCast]; positivity + have ht := (continuation_parameters m).2.2.2.1 + have hc : 0 ≤ 2*(gain r:ℝ)*r*continuationStep m := by positivity + unfold advance + split_ifs <;> (try simp only [update,Rat.cast_sub,Rat.cast_mul,Rat.cast_ofNat,Rat.cast_natCast,cast_stepQ]) <;> + constructor <;> linarith only [hc] + +lemma stateAt_quality (H : MultiGraph n m) (r i : ℕ) : + (r:ℝ)-(i:ℝ)*(2*(gain r:ℝ)*r*continuationStep m) ≤ ((stateAt H r i).quality:ℝ) ∧ + ((stateAt H r i).quality:ℝ) ≤ r := by + induction i with + | zero => simp [stateAt_zero,initial] + | succ i ih => + rw [stateAt_succ] + have hh := advance_quality H r (stateAt H r i) + push_cast + constructor <;> nlinarith only [ih.1,ih.2,hh.1,hh.2] + +lemma scale_dichotomy (H : MultiGraph n m) (r i : ℕ) : + (r:ℚ) ≤ (stateAt H r i).scale^4 ∨ + (stateAt H r i).scale=(1+stepQ m)^i/2 := by + induction i with + | zero => exact Or.inr (by simp [stateAt_zero,initial]) + | succ i ih => + rw [stateAt_succ] + rcases ih with ih|ih + · exact Or.inl (by simpa only [advance,ite_eq_right (not_lt.mpr ih)] using ih) + · by_cases ha : (stateAt H r i).scale^4 < (r:ℚ) + · right + rw [advance,ite_eq_left ha] + simp only [update,ih] + rw [pow_succ] + ring + · left + simpa only [advance,ite_eq_right ha] using not_lt.mp ha + +lemma extract_scale_bound (H : MultiGraph n m) (r : ℕ) (hr : 64^16 ≤ r) + (hp : 0 < ((extractState H r).scale:ℝ)) : + (r:ℝ)^(1/4:ℝ) ≤ ((extractState H r).scale:ℝ) := by + obtain h|h := scale_dichotomy H r (scheduleLength m r) + · rw [one_div,Real.rpow_inv_le_iff_of_pos (Nat.cast_nonneg _) hp.le (by norm_num : (0:ℝ)<4),Real.rpow_ofNat] + exact_mod_cast h + · have he : ((extractState H r).scale:ℝ)=(1+continuationStep m)^(scheduleLength m r)/2 := by + simpa only [Rat.cast_div,Rat.cast_pow,Rat.cast_add,Rat.cast_one,Rat.cast_ofNat,cast_stepQ,extractState] using congrArg (fun q : ℚ => (q:ℝ)) h + rw [he] + exact schedule_growth m r hr + +theorem stateAt_invariant : ∃R : ℕ, 64^16 ≤ R ∧ ∀r : ℕ, R ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.TreePackable univ r → + ∀i, i ≤ scheduleLength m r → Invariant H (stateAt H r i) := by + obtain ⟨R,hR,hresponse⟩ := uniform_search_response + refine ⟨max R (64^16),le_max_right _ _,?_⟩ + intro r hr n m H hn hpack i hi + have hr0 : 0 < r := (by norm_num : 0 < 64^16).trans_le ((le_max_right _ _).trans hr) + have hrlarge : 64^16 ≤ r := (le_max_right _ _).trans hr + have hconn := packing_connected H hr0 hpack + have hrm := packing_count_le_edges H hn hpack + induction i with + | zero => exact initial_invariant H (by omega) hr0 hpack + | succ i ih => + have hii : i ≤ scheduleLength m r := by omega + have ha := ih hii + rw [stateAt_succ] + by_cases hactive : (stateAt H r i).scale^4 < (r:ℚ) + · rw [advance,ite_eq_left hactive] + apply update_invariant H (by omega) hconn r (gain r) (stateAt H r i) ha + apply hresponse r ((le_max_left _ _).trans hr) n m H hn hconn hrm + (stateAt H r i).capacity (fun e => (ha.2.2.1 e).1) (fun e => (ha.2.2.1 e).2.1) + (stateAt H r i).scale (stateAt H r i).quality (gain r) ha.1 + (active_scale_bound ha.1 hactive) + ((running_quality_lower m r i hrlarge hii).trans (stateAt_quality H r i).1) + (stateAt_quality H r i).2 (gain_bounds r hr0).1 (gain_bounds r hr0).2 + (large_gain r hrlarge) ha.2.2.2 + · simpa only [advance,ite_eq_right hactive] using ha + +theorem extractState_correct : ∃R : ℕ, 64^16 ≤ R ∧ ∀r : ℕ, R ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.TreePackable univ r → + Invariant H (extractState H r) ∧ + (r:ℝ)^(1/4:ℝ) ≤ ((extractState H r).scale:ℝ) ∧ + (1-4*(r:ℝ)^(-1/16:ℝ))*r ≤ ((extractState H r).quality:ℝ) ∧ + ((extractState H r).quality:ℝ) ≤ r := by + obtain ⟨R,hR,hcorrect⟩ := stateAt_invariant + refine ⟨R,hR,?_⟩ + intro r hr n m H hn hp + have hi := hcorrect r hr n m H hn hp (scheduleLength m r) le_rfl + have hr0 : 0 < r := (by norm_num : 0 < 64^16).trans_le (hR.trans hr) + refine ⟨hi,extract_scale_bound H r (hR.trans hr) hi.1,?_,(stateAt_quality H r _).2⟩ + exact (running_quality_loss m r _ hr0 le_rfl).trans (stateAt_quality H r _).1 + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Margin.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Margin.lean new file mode 100644 index 0000000000000000000000000000000000000000..930f259023eab576a667e873c81d50402ba12f36 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Margin.lean @@ -0,0 +1,340 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Interior + +namespace OAI + +/-! Continuation margin. -/ + +section + +namespace AlgorithmicThinTrees.Partitions +noncomputable section +open Finset +open scoped Classical + +lemma partCount_le_card {V : Type*} [Fintype V] (p : Setoid V) : + partCount p ≤ Fintype.card V := + Fintype.card_le_of_surjective (Quotient.mk p) Quotient.mk_surjective + +lemma crossingIndicator_le_one {V : Type*} (p : Setoid V) (a b : V) : + crossingIndicator p a b ≤ 1 := by + unfold crossingIndicator + split_ifs <;> norm_num + +lemma slack_combo {V E : Type*} [Fintype V] [Fintype E] + (left right : E → V) (w z : E → ℝ) (q a b : ℝ) (hab : a+b=1) + (p : Setoid V) : + slack left right (a • w+b • z) q p= + a*slack left right w q p+b*slack left right z q p := by + simp only [slack,capacity,Pi.add_apply,Pi.smul_apply,smul_eq_mul, + add_mul,sum_add_distrib,mul_assoc,←mul_sum] + linear_combination (q*((partCount p:ℝ)-1))*hab + +lemma slack_change_target {V E : Type*} [Fintype V] [Fintype E] + (left right : E → V) (w : E → ℝ) (q β : ℝ) (p : Setoid V) : + slack left right w (q-β) p=slack left right w q p+β*((partCount p:ℝ)-1) := by + unfold slack + ring + +end +end AlgorithmicThinTrees.Partitions + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical MatrixOrder Matrix.Norms.Elementwise + +variable {n m : ℕ} + +namespace StepFree + +lemma multiplier_combo (a b : ℝ) (x w : StepFree n m) (ijk : DistinctTriple n) : + (a • x+b • w).multiplier ijk=a*x.multiplier ijk+b*w.multiplier ijk := rfl + +lemma y_combo (a b : ℝ) (x w : StepFree n m) (e : Fin m) : + (a • x+b • w).y e=a*x.y e+b*w.y e := rfl + +lemma z_combo (a b : ℝ) (x w : StepFree n m) (e : Fin m) : + (a • x+b • w).z e=a*x.z e+b*w.z e := rfl + +lemma Close.refl (x : StepFree n m) {η : ℝ} (hη : 0 ≤ η) : Close x x η := by + simp only [Close,sub_self,abs_zero] + exact ⟨fun _ _ => hη,fun _ => hη,fun _ => hη,fun _ => hη⟩ + +lemma close_add_rescale {x c w : StepFree n m} {a η : ℝ} (ha : 0 < a) + (h : Close x c (a*η)) : Close (w+a⁻¹ • (x-c)) w η := by + have he (v z w : ℝ) (hh : |v-z| ≤ a*η) : |w+a⁻¹*(v-z)-w| ≤ η := by + rw [add_sub_cancel_left,abs_mul,abs_of_pos (inv_pos.mpr ha)] + calc + _ ≤ a⁻¹*(a*η) := mul_le_mul_of_nonneg_left hh (inv_nonneg.mpr ha.le) + _ = η := by rw [←mul_assoc,inv_mul_cancel₀ (ne_of_gt ha),one_mul] + refine ⟨fun i j => ?_,fun ijk => ?_,fun e => ?_,fun e => ?_⟩ + · exact he _ _ _ (h.1 i j) + · exact he _ _ _ (h.2.1 ijk) + · exact he _ _ _ (h.2.2.1 e) + · exact he _ _ _ (h.2.2.2 e) + +lemma Close.capacities {x w : StepFree n m} {η : ℝ} (hη : 0 ≤ η) + (h : Close x w η) (κ : ℝ) (u : Fin m → ℝ) (e : Fin m) : + |x.capacities κ u e-w.capacities κ u e| ≤ η := by + unfold StepFree.capacities + split_ifs + · exact h.2.2.2 e + · simpa only [sub_self,abs_zero] using hη + +lemma Close.slack (H : MultiGraph n m) {x w : StepFree n m} {η : ℝ} + (hη : 0 ≤ η) (h : Close x w η) (κ q : ℝ) (u : Fin m → ℝ) (p : Setoid (Fin n)) : + |slack H.left H.right (x.capacities κ u) q p- + slack H.left H.right (w.capacities κ u) q p| ≤ (m : ℝ)*η := by + simp only [Partitions.slack,sub_sub_sub_cancel_right,capacity,←sum_sub_distrib,←sub_mul] + calc + _ ≤ ∑e, |(x.capacities κ u e-w.capacities κ u e)*crossingIndicator p (H.left e) (H.right e)| := + abs_sum_le_sum_abs _ _ + _ ≤ ∑_e : Fin m, η := by + apply sum_le_sum + intro e _ + rw [abs_mul,abs_of_nonneg (crossingIndicator_nonneg _ _ _)] + exact (mul_le_mul (h.capacities hη κ u e) (crossingIndicator_le_one _ _ _) + (crossingIndicator_nonneg _ _ _) hη).trans_eq (mul_one η) + _ = _ := by simp + +end StepFree + +lemma stepCore_convex (H : MultiGraph n m) (s κ t : ℝ) (u : Fin m → ℝ) : + Convex ℝ (stepCore H s κ t u) := by + intro x hx w hw a b ha hb hab + refine ⟨?_,?_,?_,?_,?_,?_⟩ + · rw [StepFree.lowerPencil_combo H a b hab] + exact (hx.1.smul ha).add (hw.1.smul hb) + · rw [StepFree.upperPencil_combo H a b hab] + exact (hx.2.1.smul ha).add (hw.2.1.smul hb) + · intro ijk + rw [StepFree.multiplier_combo] + exact add_nonneg (mul_nonneg ha (hx.2.2.1 ijk)) (mul_nonneg hb (hw.2.2.1 ijk)) + · intro e + rw [StepFree.y_combo] + exact ⟨add_nonneg (mul_nonneg ha (hx.2.2.2.1 e).1) (mul_nonneg hb (hw.2.2.2.1 e).1), + calc + _ ≤ a*1+b*1 := add_le_add (mul_le_mul_of_nonneg_left (hx.2.2.2.1 e).2 ha) + (mul_le_mul_of_nonneg_left (hw.2.2.2.1 e).2 hb) + _ = 1 := by simpa using hab⟩ + · intro e + rw [StepFree.z_combo] + exact ⟨add_nonneg (mul_nonneg ha (hx.2.2.2.2.1 e).1) (mul_nonneg hb (hw.2.2.2.2.1 e).1), + calc + _ ≤ a*(κ+1)+b*(κ+1) := add_le_add (mul_le_mul_of_nonneg_left (hx.2.2.2.2.1 e).2 ha) + (mul_le_mul_of_nonneg_left (hw.2.2.2.2.1 e).2 hb) + _ = κ+1 := by rw [←add_mul,hab,one_mul]⟩ + · intro e he + refine ⟨?_,?_⟩ + · rw [StepFree.edgePencil_combo] + exact ((hx.2.2.2.2.2 e he).1.smul ha).add ((hw.2.2.2.2.2 e he).1.smul hb) + · rw [StepFree.y_combo,StepFree.z_combo] + calc + _ ≤ a*(κ+u e+t*(5*x.y e-4))+b*(κ+u e+t*(5*w.y e-4)) := + add_le_add (mul_le_mul_of_nonneg_left (hx.2.2.2.2.2 e he).2 ha) + (mul_le_mul_of_nonneg_left (hw.2.2.2.2.2 e he).2 hb) + _ = _ := by linear_combination (κ+u e-4*t)*hab + +lemma stepFeasible_convex (H : MultiGraph n m) (s κ t q : ℝ) (u : Fin m → ℝ) : + Convex ℝ (stepFeasible H s κ t q u) := by + intro x hx w hw a b ha hb hab + refine ⟨stepCore_convex H s κ t u hx.1 hw.1 ha hb hab,fun p => ?_⟩ + rw [StepFree.capacities_combo κ a b hab,slack_combo _ _ _ _ q a b hab] + exact add_nonneg (mul_nonneg ha (hx.2 p)) (mul_nonneg hb (hw.2 p)) + +lemma convex_innerCube (K : Set (StepFree n m)) (hK : Convex ℝ K) + (z c : StepFree n m) (hz : z ∈ K) {a η : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) + (hc : ∀x, x.Close c η → x ∈ K) {x : StepFree n m} + (hx : x.Close ((1-a) • z+a • c) (a*η)) : x ∈ K := by + have hu := hc _ (StepFree.close_add_rescale ha hx) + have hh := hK hz hu (sub_nonneg.mpr ha1) ha.le (by ring : 1-a+a=1) + have he : (1-a) • z+a • (c+a⁻¹ • (x-((1-a) • z+a • c)))=x := by + rw [smul_add,smul_smul,mul_inv_cancel₀ (ne_of_gt ha),one_smul] + abel + rwa [he] at hh + +lemma auxiliary_slack (H : MultiGraph n m) (hn : 0 < n) + (u : Fin m → ℝ) {q : ℝ} (hq : q ≤ m) (p : Setoid (Fin n)) : + -(graphSize n m)^2 ≤ slack H.left H.right + ((auxiliaryPoint H (continuationBaseline m)).capacities (continuationBaseline m) u) q p := by + have : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + have hd0 : 0 ≤ (partCount p:ℝ)-1 := by + have hh : (1:ℝ) ≤ partCount p := by exact_mod_cast partCount_pos p + linarith only [hh] + have hd : (partCount p:ℝ)-1 ≤ n := by + have hh : (partCount p:ℝ) ≤ n := by exact_mod_cast (show partCount p ≤ n by simpa using partCount_le_card p) + linarith only [hh] + have hκ : 0 < continuationBaseline m := (continuation_parameters m).1 + have hcap : 0 ≤ capacity H.left H.right + ((auxiliaryPoint H (continuationBaseline m)).capacities (continuationBaseline m) u) p := by + apply sum_nonneg + intro e _ + apply mul_nonneg _ (crossingIndicator_nonneg _ _ _) + unfold StepFree.capacities + split_ifs + · change 0 ≤ continuationBaseline m/2 + positivity + · exact hκ.le + have hm : (m:ℝ) ≤ graphSize n m := by unfold graphSize; linarith [Nat.cast_nonneg (α:=ℝ) n] + have hnP : (n:ℝ) ≤ graphSize n m := by unfold graphSize; linarith [Nat.cast_nonneg (α:=ℝ) m] + have hh : q*((partCount p:ℝ)-1) ≤ (graphSize n m)^2 := by + calc + _ ≤ (m:ℝ)*n := mul_le_mul hq hd hd0 (Nat.cast_nonneg m) + _ ≤ graphSize n m*graphSize n m := mul_le_mul hm hnP (Nat.cast_nonneg n) graphSize_pos.le + _ = _ := (pow_two _).symm + unfold slack + linarith only [hcap,hh] + +lemma mixing_numbers {P β : ℝ} (hP : 5 ≤ P) (hmP : (m:ℝ) ≤ P) + (hβ : P⁻¹/32 ≤ β) : + 0 < P^(-8:ℤ) ∧ P^(-8:ℤ) ≤ 1 ∧ + β/2 ≤ (1-P^(-8:ℤ))*β-P^(-8:ℤ)*P^2 ∧ + P^(-30:ℤ) ≤ P^(-8:ℤ)*P^(-20:ℤ) ∧ + (m:ℝ)*P^(-30:ℤ) ≤ β/2 := by + have hP0 : 0 < P := by linarith + have hP1 : 1 ≤ P := by linarith + have hβ0 : 0 ≤ β := (by positivity : 0 ≤ P⁻¹/32).trans hβ + have hθ0 : 0 < P^(-8:ℤ) := zpow_pos hP0 _ + have h4 : (4:ℝ) ≤ P^8 := (by linarith : (4:ℝ) ≤ P).trans + (by simpa using pow_le_pow_right₀ hP1 (by norm_num : 1 ≤ 8)) + have hθ4 : 4*P^(-8:ℤ) ≤ 1 := by + simpa using scaled_inverse_power hP0 0 8 h4 + have h128 : (128:ℝ) ≤ P^5 := by + have hh := pow_le_pow_left₀ (by norm_num : (0:ℝ) ≤ 5) hP 5 + norm_num at hh + linarith only [hh] + have he : 128*P^(-6:ℤ) ≤ P⁻¹ := by + simpa using scaled_inverse_power hP0 1 5 h128 + have hθP : P^(-8:ℤ)*P^2=P^(-6:ℤ) := by + rw [←zpow_natCast,←zpow_add₀ (ne_of_gt hP0)] + norm_num + have hθβ := mul_le_mul_of_nonneg_right hθ4 hβ0 + have hmδ : (m:ℝ)*P^(-30:ℤ) ≤ P^(-6:ℤ) := by + calc + _ ≤ P*P^(-30:ℤ) := mul_le_mul_of_nonneg_right hmP (zpow_pos hP0 _).le + _ = P^(-29:ℤ) := by simpa using (zpow_add₀ (ne_of_gt hP0) 1 (-30)).symm + _ ≤ _ := inverse_power_mono hP1 (by norm_num : 6 ≤ 29) + refine ⟨hθ0,by linarith only [hθ4],?_,?_,?_⟩ + · rw [hθP] + nlinarith only [hθβ,he,hβ] + · rw [←zpow_add₀ (ne_of_gt hP0)] + norm_num only [show (-8:ℤ)+(-20) = -28 by norm_num] + exact inverse_power_mono hP1 (by norm_num : 28 ≤ 30) + · linarith only [hmδ,he,hβ,hβ0] + +theorem step_inner_cube (H : MultiGraph n m) (hn : 2 ≤ n) (hconn : H.Connected univ) + {s q β : ℝ} (hs : 0 ≤ s) (hsP : s ≤ graphSize n m) + (hq : q ≤ m) (hβ : (graphSize n m)⁻¹/32 ≤ β) + (u : Fin m → ℝ) (hu0 : ∀e, 0 ≤ u e) + {z : StepFree n m} + (hz : z ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) (q+β) u) : + let θ := (graphSize n m)^(-8:ℤ) + let c := (1-θ) • z+θ • auxiliaryPoint H (continuationBaseline m) + ∀x, x.Close c ((graphSize n m)^(-30:ℤ)) → + x ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) q u := by + have : Nonempty (Fin n) := ⟨⟨0,by omega⟩⟩ + let P := graphSize n m + let θ := P^(-8:ℤ) + let aux := auxiliaryPoint H (continuationBaseline m) + let c := (1-θ) • z+θ • aux + have hP := connected_size_five H hn hconn + have hmP : (m:ℝ) ≤ P := by dsimp [P,graphSize]; linarith [Nat.cast_nonneg (α:=ℝ) n] + obtain ⟨hθ,hθ1,hmix,hδ,hpert⟩ := mixing_numbers hP hmP hβ + have hβ0 : 0 ≤ β := (div_nonneg (inv_nonneg.mpr (graphSize_pos (n:=n) (m:=m)).le) (by norm_num) : 0 ≤ (graphSize n m)⁻¹/32).trans hβ + change ∀x : StepFree n m, x.Close c (P^(-30:ℤ)) → _ + intro x hx + refine ⟨?_,fun p => ?_⟩ + · apply convex_innerCube (stepCore H s (continuationBaseline m) (continuationStep m) u) + (stepCore_convex H _ _ _ u) z aux hz.1 hθ hθ1 _ (hx.mono hδ) + intro w hw + exact auxiliary_cube H hn hconn hs hsP u hu0 hw + · by_cases hp : p=⊤ + · subst p + rw [slack_top] + have hd : 1 ≤ (partCount p:ℝ)-1 := by + have hh : (2:ℝ) ≤ partCount p := by exact_mod_cast two_le_partCount hp + linarith only [hh] + have hzβ : β ≤ slack H.left H.right (z.capacities (continuationBaseline m) u) q p := by + have hz' := hz.2 p + have he := slack_change_target H.left H.right (z.capacities (continuationBaseline m) u) (q+β) β p + rw [add_sub_cancel_right] at he + have hdβ := mul_le_mul_of_nonneg_left hd hβ0 + rw [he] + nlinarith only [hz',hdβ] + have haux := auxiliary_slack H (by omega) u hq p + have hc : β/2 ≤ slack H.left H.right (c.capacities (continuationBaseline m) u) q p := by + dsimp only [c] + rw [StepFree.capacities_combo _ (1-θ) θ (by ring),slack_combo _ _ _ _ q _ _ (by ring)] + have hh := add_le_add (mul_le_mul_of_nonneg_left hzβ (sub_nonneg.mpr hθ1)) + (mul_le_mul_of_nonneg_left haux hθ.le) + change (1-θ)*β+θ*(-P^2) ≤ _ at hh + exact hmix.trans (by nlinarith only [hh]) + have hp' := (abs_le.mp (hx.slack H (zpow_pos graphSize_pos _).le + (continuationBaseline m) q u p)).1 + linarith only [hc,hp',hpert] + +lemma gain_at_least_one {R g : ℝ} (hR : 1 ≤ R) (hg : R^(-1/8:ℝ) ≤ g) : + 1 ≤ g*R := by + have hR0 : 0 < R := lt_of_lt_of_le zero_lt_one hR + have hh : 1 ≤ R^((7:ℝ)/8) := Real.one_le_rpow hR (by norm_num) + calc + 1 ≤ R^((7:ℝ)/8) := hh + _ = R^(-1/8:ℝ)*R := by + rw [show (7:ℝ)/8 = -1/8+1 by norm_num,Real.rpow_add hR0,Real.rpow_one] + _ ≤ g*R := mul_le_mul_of_nonneg_right hg hR0.le + +lemma continuation_margin_lower {r : ℕ} {g : ℝ} (hr : 1 ≤ r) + (hg : (r:ℝ)^(-1/8:ℝ) ≤ g) : + (graphSize n m)⁻¹/32 ≤ g*r*continuationStep m := by + have hr1 : (1:ℝ) ≤ r := by exact_mod_cast hr + calc + _ ≤ continuationBaseline m/32 := div_le_div_of_nonneg_right baseline_lower (by norm_num) + _ ≤ g*r*continuationStep m := by + change continuationStep m ≤ _ + simpa only [one_mul] using mul_le_mul_of_nonneg_right (gain_at_least_one hr1 hg) + (continuation_parameters m).2.2.2.1 + +theorem uniform_continuation_inner_cube : + ∃r0 : ℕ, 8 ≤ r0 ∧ ∀r : ℕ, r0 ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.Connected univ → r ≤ m → + ∀(u : Fin m → ℝ), (∀e, 0 ≤ u e) → (∀e, u e ≤ 1) → + ∀(s Q g : ℝ), 0 < s → s ≤ (r:ℝ)^(1/4:ℝ) → + 3*(r:ℝ)/4 ≤ Q → Q ≤ r → + (r:ℝ)^(-1/8:ℝ) ≤ g → g ≤ 2*(r:ℝ)^(-1/8:ℝ) → + (∀p, 0 ≤ slack H.left H.right (fun e => u e+continuationBaseline m) Q p) → + ∃c : StepFree n m, ∀x, x.Close c ((graphSize n m)^(-30:ℤ)) → + x ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) + (Q-2*g*r*continuationStep m) u := by + obtain ⟨r0,hr0,hr⟩ := feasible_continuation_response + refine ⟨r0,hr0,?_⟩ + intro r hrr n m H hn hconn hrm u hu0 hu1 s Q g hs hsr hQ hQr hg hgg hinv + have hr1 : 1 ≤ r := by omega + have hrR : (1:ℝ) ≤ r := by exact_mod_cast hr1 + have hsP : s ≤ graphSize n m := by + calc + s ≤ (r:ℝ)^(1/4:ℝ) := hsr + _ ≤ (r:ℝ)^((1:ℝ)) := Real.rpow_le_rpow_of_exponent_le hrR (by norm_num) + _ = r := Real.rpow_one _ + _ ≤ m := by exact_mod_cast hrm + _ ≤ _ := by unfold graphSize; linarith [Nat.cast_nonneg (α:=ℝ) n] + have hβ := continuation_margin_lower (n:=n) (m:=m) hr1 hg + have hβ0 : 0 ≤ g*r*continuationStep m := (div_nonneg (inv_nonneg.mpr (graphSize_pos (n:=n) (m:=m)).le) (by norm_num) : 0 ≤ (graphSize n m)⁻¹/32).trans hβ + obtain ⟨w,hw,hp⟩ := hr r hrr n m H hn hconn u hu0 hu1 s Q g hs hsr hQ hQr hg hgg hinv + obtain ⟨z,hz,_,_⟩ := response_to_stepFeasible H (by omega) + (continuation_parameters m).2.2.2.1 (continuation_parameters m).2.2.2.2.2.1 hw hp + have hq : Q-2*g*r*continuationStep m ≤ m := by + have hh : (r:ℝ) ≤ m := by exact_mod_cast hrm + linarith only [hβ0,hh,hQr] + have hz' : z ∈ stepFeasible H s (continuationBaseline m) (continuationStep m) + ((Q-2*g*r*continuationStep m)+(g*r*continuationStep m)) u := by + rw [show (Q-2*g*r*continuationStep m)+(g*r*continuationStep m) = + Q-g*r*continuationStep m by ring] + exact hz + exact ⟨_,step_inner_cube H hn hconn hs.le hsP hq hβ u hu0 hz'⟩ + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionGeometry.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..28c97564f8f024555b92635f83ff898ceef84e19 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionGeometry.lean @@ -0,0 +1,162 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.PartitionLattice +import OAI.Combinatorics.ThinTrees.RationalMatrix.SchurHistory + +namespace OAI + +/-! Partition geometry. -/ + +section + +namespace AlgorithmicThinTrees.Partitions +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical + +variable {V : Type*} [Fintype V] + +def block (p : Setoid V) (v : V) : Finset V := univ.filter (p v ·) + +@[simp] lemma mem_block (p : Setoid V) (v w : V) : w ∈ block p v ↔ p v w := by + simp [block] + +lemma self_mem_block (p : Setoid V) (v : V) : v ∈ block p v := + (mem_block p v v).mpr (p.refl v) + +lemma block_eq_iff (p : Setoid V) (v w : V) : block p v=block p w ↔ p v w := by + constructor + · intro he + exact (mem_block p v w).mp (he ▸ self_mem_block p w) + · intro h + ext a + simp only [mem_block] + exact ⟨fun hv => p.trans (p.symm h) hv, fun hw => p.trans h hw⟩ + +lemma block_block (p : Setoid V) {a b v : V} (ha : a ∈ block p v) (hb : b ∈ block p v) : + p a b := p.trans (p.symm ((mem_block _ _ _).mp ha)) ((mem_block _ _ _).mp hb) + +lemma block_mono {p q : Setoid V} (hpq : p ≤ q) (v : V) : block p v ⊆ block q v := by + intro w hw + exact (mem_block _ _ _).mpr (hpq ((mem_block _ _ _).mp hw)) + +def parts (p : Setoid V) : Finset (Finset V) := univ.image (block p) + +lemma block_mem_parts (p : Setoid V) (v : V) : block p v ∈ parts p := + mem_image.mpr ⟨v,mem_univ v,rfl⟩ + +lemma mem_parts (p : Setoid V) (A : Finset V) : A ∈ parts p ↔ ∃v, block p v=A := by + simp [parts] + +lemma parts_top [Nonempty V] : parts (⊤ : Setoid V)={univ} := by + have hb (v : V) : block (⊤ : Setoid V) v=univ := by ext w; simp [block] + unfold parts + rw [show block (⊤ : Setoid V)=(fun _ => univ) from funext hb] + exact image_const univ_nonempty _ + +lemma parts_disjoint (p : Setoid V) {A B : Finset V} (hA : A ∈ parts p) + (hB : B ∈ parts p) (hAB : A ≠ B) : Disjoint A B := by + obtain ⟨a,rfl⟩ := (mem_parts p A).mp hA + obtain ⟨b,rfl⟩ := (mem_parts p B).mp hB + apply disjoint_left.mpr + intro v hva hvb + apply hAB + exact (block_eq_iff p a b).mpr + (p.trans ((mem_block _ _ _).mp hva) (p.symm ((mem_block _ _ _).mp hvb))) + +lemma parts_cover (p : Setoid V) : (parts p).biUnion id=univ := by + apply eq_univ_of_forall + intro v + exact mem_biUnion.mpr ⟨block p v,block_mem_parts p v,self_mem_block p v⟩ + +lemma partCount_pos [Nonempty V] (p : Setoid V) : 0 < partCount p := + Fintype.card_pos_iff.mpr ⟨Quotient.mk p (Classical.arbitrary V)⟩ + +lemma partCount_top [Nonempty V] : partCount (⊤ : Setoid V)=1 := by + apply Fintype.card_eq_one_iff.mpr + refine ⟨Quotient.mk ⊤ (Classical.arbitrary V),?_⟩ + intro y + induction y using Quotient.inductionOn with + | h y => exact Quotient.sound trivial + +lemma two_le_partCount [Nonempty V] {p : Setoid V} (hp : p ≠ ⊤) : 2 ≤ partCount p := by + have hh := partCount_strictAnti (lt_top_iff_ne_top.mpr hp) + rw [partCount_top] at hh + exact hh + +variable {n m : ℕ} + +lemma parts_partition (p : Setoid (Fin n)) : VertexPartition univ (parts p) := by + refine ⟨?_,?_,?_⟩ + · intro A hA + obtain ⟨v,rfl⟩ := (mem_parts p A).mp hA + exact ⟨⟨v,self_mem_block p v⟩,subset_univ _⟩ + · intro A hA B hB hAB + exact parts_disjoint p hA hB hAB + · apply eq_univ_of_forall + intro v + exact mem_biUnion.mpr ⟨block p v,block_mem_parts p v,self_mem_block p v⟩ + +def toChain (f : ℕ → Setoid (Fin n)) (hf : Monotone f) : PartitionChain n where + parts i := parts (f i) + partition i := parts_partition (f i) + coarsens i j hij A hA := by + obtain ⟨v,rfl⟩ := (mem_parts (f i) A).mp hA + exact ⟨block (f j) v,block_mem_parts _ _,block_mono (hf hij) v⟩ + +lemma toChain_block (f : ℕ → Setoid (Fin n)) (hf : Monotone f) (i : ℕ) (v : Fin n) : + (toChain f hf).block i v=block (f i) v := + (toChain f hf).block_eq_of_mem (block_mem_parts _ _) (self_mem_block _ _) + +def crossing (G : MultiGraph n m) (p : Setoid (Fin n)) : Finset (Fin m) := + univ.filter (fun e => ¬p (G.left e) (G.right e)) + +@[simp] lemma mem_crossing (G : MultiGraph n m) (p : Setoid (Fin n)) (e : Fin m) : + e ∈ crossing G p ↔ ¬p (G.left e) (G.right e) := by simp [crossing] + +lemma toChain_crossing (G : MultiGraph n m) (f : ℕ → Setoid (Fin n)) (hf : Monotone f) (i : ℕ) : + (toChain f hf).crossing G i=crossing G (f i) := by + ext e + simp only [PartitionChain.mem_crossing,toChain_block,mem_crossing,block_eq_iff,ne_eq] + +lemma capacity_eq_sum (G : MultiGraph n m) (w : Fin m → ℝ) (p : Setoid (Fin n)) : + capacity G.left G.right w p=∑e ∈ crossing G p, w e := by + simp only [capacity,crossing,sum_filter,crossingIndicator] + apply sum_congr rfl + intro e _ + split_ifs <;> simp_all + +lemma enumerate_chain (J : Finset (Setoid (Fin n))) + (hJ : IsChain (· ≤ ·) (J : Set (Setoid (Fin n)))) : + ∃f : ℕ → Setoid (Fin n), Monotone f ∧ f J.card=⊤ ∧ + (∀i, f i ∈ J ∨ f i=⊤) ∧ ∀p ∈ J, ∃i < J.card, f i=p := by + let : LinearOrder J := hJ.lt_of_le.linearOrder + let e : Fin J.card ≃o J := (univ : Finset J).orderIsoOfFin (by simp) + |>.trans ((Set.orderIsoOfEq _ _ (Finset.coe_univ)).trans OrderIso.Set.univ) + let f (i : ℕ) : Setoid (Fin n) := if hi : i < J.card then (e ⟨i,hi⟩).val else ⊤ + refine ⟨f,?_,?_,?_,?_⟩ + · intro i j hij + dsimp only [f] + split_ifs with hi hj + · exact e.monotone (show (⟨i,hi⟩ : Fin J.card) ≤ ⟨j,hj⟩ from hij) + · exact le_top + · omega + · exact le_rfl + · dsimp [f] + rw [dite_eq_right (lt_irrefl _)] + · intro i + dsimp only [f] + split_ifs with hi + · exact Or.inl (e ⟨i,hi⟩).property + · exact Or.inr rfl + · intro p hp + let j := e.symm ⟨p,hp⟩ + refine ⟨j.val,j.isLt,?_⟩ + dsimp only [f] + rw [dite_eq_left j.isLt] + exact congrArg Subtype.val (e.apply_symm_apply ⟨p,hp⟩) + +end +end AlgorithmicThinTrees.Partitions +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionLattice.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionLattice.lean new file mode 100644 index 0000000000000000000000000000000000000000..17c2e5daa4a130a8eb97d3b219203b960f222e43 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionLattice.lean @@ -0,0 +1,175 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.CompactCharging + +namespace OAI + +/-! Partition lattice. -/ + +section + +namespace AlgorithmicThinTrees.Partitions +noncomputable section +open Finset +open scoped Classical + +variable {V E : Type*} [Fintype V] + +instance partitionsFinite : Finite (Setoid V) := + Finite.of_injective (fun p : Setoid V => p.r) (fun p q h => by + apply Setoid.ext + intro a b + exact iff_of_eq (congrFun (congrFun h a) b)) + +instance partitionsFintype : Fintype (Setoid V) := Fintype.ofFinite _ + +def partCount (p : Setoid V) : ℕ := Fintype.card (Quotient p) + +def constants (p : Setoid V) : Submodule ℝ (V → ℝ) where + carrier := {x | p ≤ Setoid.ker x} + zero_mem' := fun _ _ _ => rfl + add_mem' := by + intro x y hx hy a b hab + change x a+y a=x b+y b + rw [hx hab,hy hab] + smul_mem' := by + intro c x hx a b hab + change c*x a=c*x b + rw [hx hab] + +omit [Fintype V] in +lemma constants_antitone {p q : Setoid V} (hpq : p ≤ q) : constants q ≤ constants p := + fun _ hx => hpq.trans hx + +omit [Fintype V] in +lemma constants_sup (p q : Setoid V) : constants (p ⊔ q)=constants p ⊓ constants q := by + ext x + change (p ⊔ q ≤ Setoid.ker x) ↔ (p ≤ Setoid.ker x) ∧ (q ≤ Setoid.ker x) + exact sup_le_iff + +def quotientConstants (p : Setoid V) : (Quotient p → ℝ) ≃ₗ[ℝ] constants p where + toFun f := ⟨fun a => f (Quotient.mk p a),fun _ _ hab => congrArg f (Quotient.sound hab)⟩ + invFun x := Quotient.lift x (fun _ _ hab => x.property hab) + left_inv f := by + funext a + exact Quotient.inductionOn a (fun _ => rfl) + right_inv x := by + apply Subtype.ext + rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +lemma constants_finrank (p : Setoid V) : Module.finrank ℝ (constants p)=partCount p := by + rw [←(quotientConstants p).finrank_eq,Module.finrank_pi] + rfl + +theorem partCount_supermodular (p q : Setoid V) : + partCount p+partCount q ≤ partCount (p ⊓ q)+partCount (p ⊔ q) := by + have hi : constants p ⊔ constants q ≤ constants (p ⊓ q) := + sup_le (constants_antitone inf_le_left) (constants_antitone inf_le_right) + have hr := Submodule.finrank_mono hi + have he := Submodule.finrank_sup_add_finrank_inf_eq (constants p) (constants q) + rw [←constants_sup,constants_finrank,constants_finrank,constants_finrank] at he + rw [constants_finrank] at hr + omega + +theorem partCount_strictAnti : StrictAnti (partCount (V := V)) := by + intro p q hpq + let f : Quotient p → Quotient q := Quotient.map id hpq.le + have hsur : Function.Surjective f := Quotient.map_surjective hpq.le Function.surjective_id + have hninj : ¬Function.Injective f := by + intro hinj + have hqp : q ≤ p := by + intro a b hab + apply Quotient.exact + apply hinj + change (Quotient.mk q a)=(Quotient.mk q b) + exact Quotient.sound hab + exact (not_le_of_gt hpq) hqp + exact Fintype.card_lt_of_surjective_not_injective f hsur hninj + +lemma partCount_antitone : Antitone (partCount (V := V)) := partCount_strictAnti.antitone + +def potential (p : Setoid V) : ℝ := (partCount p : ℝ)^2 + +theorem potential_uncross {p q : Setoid V} (hpq : ¬p ≤ q) (hqp : ¬q ≤ p) : + potential p+potential q < potential (p ⊓ q)+potential (p ⊔ q) := by + have hip : p ⊓ q < p := lt_of_le_of_ne inf_le_left (by + intro he + exact hpq (he ▸ inf_le_right)) + have hiq : p ⊓ q < q := lt_of_le_of_ne inf_le_right (by + intro he + exact hqp (he ▸ inf_le_left)) + have hps : p < p ⊔ q := lt_of_le_of_ne le_sup_left (by + intro he + exact hqp (he.symm ▸ le_sup_right)) + have hqs : q < p ⊔ q := lt_of_le_of_ne le_sup_right (by + intro he + exact hpq (he.symm ▸ le_sup_left)) + have hcp : (partCount p:ℝ) < partCount (p ⊓ q) := by exact_mod_cast partCount_strictAnti hip + have hcq : (partCount q:ℝ) < partCount (p ⊓ q) := by exact_mod_cast partCount_strictAnti hiq + have hdp : (partCount (p ⊔ q):ℝ) < partCount p := by exact_mod_cast partCount_strictAnti hps + have hdq : (partCount (p ⊔ q):ℝ) < partCount q := by exact_mod_cast partCount_strictAnti hqs + have hsum : (partCount p:ℝ)+partCount q ≤ partCount (p ⊓ q)+partCount (p ⊔ q) := by + exact_mod_cast partCount_supermodular p q + have hm1 := mul_pos (sub_pos.mpr hcp) (sub_pos.mpr hcq) + have hm2 := mul_nonneg (sub_nonneg.mpr hdp.le) (sub_nonneg.mpr hdq.le) + have hm3 := mul_nonneg (show (0:ℝ) ≤ partCount p+partCount q by positivity) + (sub_nonneg.mpr hsum) + dsimp [potential] + nlinarith only [hm1,hm2,hm3] + +def crossingIndicator (p : Setoid V) (a b : V) : ℝ := if p a b then 0 else 1 + +omit [Fintype V] in +lemma crossingIndicator_nonneg (p : Setoid V) (a b : V) : 0 ≤ crossingIndicator p a b := by + unfold crossingIndicator + split_ifs <;> norm_num + +omit [Fintype V] in +theorem crossingIndicator_submodular (p q : Setoid V) (a b : V) : + crossingIndicator (p ⊓ q) a b+crossingIndicator (p ⊔ q) a b ≤ + crossingIndicator p a b+crossingIndicator q a b := by + have hp : p a b → (p ⊔ q) a b := fun h => (show p ≤ p ⊔ q from le_sup_left) h + have hq : q a b → (p ⊔ q) a b := fun h => (show q ≤ p ⊔ q from le_sup_right) h + have hinf : (p ⊓ q) a b ↔ p a b ∧ q a b := Iff.rfl + unfold crossingIndicator + by_cases habp : p a b <;> by_cases habq : q a b + · simp [hinf,habp,habq,hp habp] + · simp [hinf,habp,habq,hp habp] + · simp [hinf,habp,habq,hq habq] + · simp only [hinf,habp,habq,false_and,ite_false] + split_ifs <;> norm_num + +variable [Fintype E] + +def capacity (left right : E → V) (w : E → ℝ) (p : Setoid V) : ℝ := + ∑e, w e*crossingIndicator p (left e) (right e) + +omit [Fintype V] in +theorem capacity_submodular (left right : E → V) (w : E → ℝ) (hw : ∀e, 0 ≤ w e) + (p q : Setoid V) : + capacity left right w (p ⊓ q)+capacity left right w (p ⊔ q) ≤ + capacity left right w p+capacity left right w q := by + simp only [capacity,←sum_add_distrib,←mul_add] + exact sum_le_sum (fun e _ => mul_le_mul_of_nonneg_left + (crossingIndicator_submodular p q (left e) (right e)) (hw e)) + +def slack (left right : E → V) (w : E → ℝ) (r : ℝ) (p : Setoid V) : ℝ := + capacity left right w p-r*((partCount p:ℝ)-1) + +theorem slack_submodular (left right : E → V) (w : E → ℝ) (hw : ∀e, 0 ≤ w e) + {r : ℝ} (hr : 0 ≤ r) (p q : Setoid V) : + slack left right w r (p ⊓ q)+slack left right w r (p ⊔ q) ≤ + slack left right w r p+slack left right w r q := by + have hc := capacity_submodular left right w hw p q + have hrank : (partCount p:ℝ)+partCount q ≤ partCount (p ⊓ q)+partCount (p ⊔ q) := by + exact_mod_cast partCount_supermodular p q + have hm := mul_le_mul_of_nonneg_left hrank hr + dsimp [slack] + linarith + +end +end AlgorithmicThinTrees.Partitions +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionLocalConnectivity.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionLocalConnectivity.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2c24b7f822f33a6e3456e1a657f7f9b9642791f --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionLocalConnectivity.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.PartitionGeometry +import OAI.Combinatorics.ThinTrees.Restriction + +namespace OAI + +/-! Partition local connectivity. -/ + +section + +namespace AlgorithmicThinTrees.Partitions +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical + +variable {V : Type*} [Fintype V] + +def split (p : Setoid V) (S : Finset V) : Setoid V := p ⊓ Setoid.ker (fun v => v ∈ S) + +omit [Fintype V] in +lemma split_iff (p : Setoid V) (S : Finset V) (a b : V) : + split p S a b ↔ p a b ∧ (a ∈ S ↔ b ∈ S) := by + change (p a b ∧ (a ∈ S)=(b ∈ S)) ↔ _ + simp only [eq_iff_iff] + +lemma split_strict {p : Setoid V} {v : V} {S : Finset V} + (hne : S.Nonempty) (hS : S ⊂ block p v) : split p S < p := by + apply lt_of_le_of_ne inf_le_left + intro he + obtain ⟨a,ha⟩ := hne + have hbex : ∃b ∈ block p v, b ∉ S := by + by_contra h + push Not at h + exact hS.not_ge h + obtain ⟨b,hb,hbn⟩ := hbex + have hab : p a b := block_block p (hS.subset ha) hb + have hsplit : split p S a b := Eq.mpr (congrArg (fun q : Setoid V => q a b) he) hab + exact hbn (((split_iff p S a b).mp hsplit).2.mp ha) + +variable {n m : ℕ} + +lemma crossing_split (G : MultiGraph n m) (p : Setoid (Fin n)) (v : Fin n) + {S : Finset (Fin n)} (hS : S ⊆ block p v) : + crossing G (split p S)=crossing G p ∪ G.cut (G.inducedEdges (block p v)) S := by + ext e + simp only [mem_crossing,split_iff,mem_union,MultiGraph.cut,mem_filter,mem_inducedEdges] + have hl : G.left e ∈ S → G.left e ∈ block p v := fun h => hS h + have hr : G.right e ∈ S → G.right e ∈ block p v := fun h => hS h + have hlr : p (G.left e) (G.right e) → G.left e ∈ block p v → G.right e ∈ block p v := by + intro he hleft + exact (mem_block _ _ _).mpr (p.trans ((mem_block _ _ _).mp hleft) he) + have hrl : p (G.left e) (G.right e) → G.right e ∈ block p v → G.left e ∈ block p v := by + intro he hright + exact (mem_block _ _ _).mpr (p.trans ((mem_block _ _ _).mp hright) (p.symm he)) + by_cases hp : p (G.left e) (G.right e) <;> + by_cases hls : G.left e ∈ S <;> by_cases hrs : G.right e ∈ S <;> simp_all + +lemma crossing_split_disjoint (G : MultiGraph n m) (p : Setoid (Fin n)) (v : Fin n) + (S : Finset (Fin n)) : + Disjoint (crossing G p) (G.cut (G.inducedEdges (block p v)) S) := by + apply disjoint_left.mpr + intro e hp hi + have he := (mem_inducedEdges _ _ _).mp (mem_filter.mp hi).1 + exact (mem_crossing G p e).mp hp (block_block p he.1 he.2) + +lemma capacity_split (G : MultiGraph n m) (w : Fin m → ℝ) (p : Setoid (Fin n)) (v : Fin n) + {S : Finset (Fin n)} (hS : S ⊆ block p v) : + capacity G.left G.right w (split p S)=capacity G.left G.right w p+ + ∑e ∈ G.cut (G.inducedEdges (block p v)) S, w e := by + rw [capacity_eq_sum,capacity_eq_sum,crossing_split G p v hS, + sum_union (crossing_split_disjoint G p v S)] + +lemma split_capacity_lower (G : MultiGraph n m) (w : Fin m → ℝ) {Q : ℝ} (hQ : 0 ≤ Q) + (hinv : ∀p, 0 ≤ slack G.left G.right w Q p) + {p : Setoid (Fin n)} (hp : slack G.left G.right w Q p ≤ 1) (v : Fin n) + {S : Finset (Fin n)} (hne : S.Nonempty) (hS : S ⊂ block p v) : + Q-1 ≤ ∑e ∈ G.cut (G.inducedEdges (block p v)) S, w e := by + have hc : partCount p+1 ≤ partCount (split p S) := + partCount_strictAnti (split_strict hne hS) + have hcR : (partCount p:ℝ)+1 ≤ partCount (split p S) := by exact_mod_cast hc + have hi := hinv (split p S) + dsimp only [slack] at hi hp + rw [capacity_split G w p v hS.subset] at hi + have hh := mul_le_mul_of_nonneg_left hcR hQ + nlinarith only [hi,hp,hh] + +def active (u : Fin m → ℝ) : Finset (Fin m) := univ.filter (fun e => 0 < u e) + +@[simp] lemma mem_active (u : Fin m → ℝ) (e : Fin m) : e ∈ active u ↔ 0 < u e := by + simp [active] + +lemma capacity_active_upper (u : Fin m → ℝ) (_hu0 : ∀e, 0 ≤ u e) (hu1 : ∀e, u e ≤ 1) + {κ : ℝ} (hκ : 0 ≤ κ) (F : Finset (Fin m)) : + (∑e ∈ F, (u e+κ)) ≤ ((F ∩ active u).card:ℝ)+κ*m := by + have hpoint (e : Fin m) : u e ≤ if e ∈ active u then (1:ℝ) else 0 := by + split_ifs with he + · exact hu1 e + · have he' : ¬0 < u e := by simpa using he + exact le_of_not_gt he' + have hsum := sum_le_sum (fun e (_ : e ∈ F) => hpoint e) + have he : (∑e ∈ F, if e ∈ active u then (1:ℝ) else 0)=((F ∩ active u).card:ℝ) := by + rw [←sum_filter] + simp only [sum_const,nsmul_eq_mul,mul_one] + congr 1 + rw [he] at hsum + have hcard : (F.card:ℝ) ≤ m := by + exact_mod_cast (show F.card ≤ m by simpa only [Fintype.card_fin] using card_le_univ F) + have hm := mul_le_mul_of_nonneg_left hcard hκ + simp only [sum_add_distrib,sum_const,nsmul_eq_mul] + nlinarith only [hsum,hm] + +lemma restrict_induced (G : MultiGraph n m) (F : Finset (Fin m)) (A : Finset (Fin n)) : + liftEdges F ((G.restrict F).inducedEdges A)=G.inducedEdges A ∩ F := by + ext e + simp only [liftEdges,mem_map,mem_inter,mem_inducedEdges] + constructor + · rintro ⟨i,hi,rfl⟩ + exact ⟨hi,embedding_mem F i⟩ + · rintro ⟨hi,he⟩ + obtain ⟨i,rfl⟩ := embedding_surj F he + exact ⟨i,hi,rfl⟩ + +lemma restrict_internal_cut_card (G : MultiGraph n m) (F : Finset (Fin m)) + (A S : Finset (Fin n)) : + ((G.restrict F).cut ((G.restrict F).inducedEdges A) S).card= + (G.cut (G.inducedEdges A) S ∩ F).card := by + rw [G.restrict_cut_card,restrict_induced] + congr 1 + ext e + simp only [MultiGraph.cut,mem_filter,mem_inter] + tauto + +theorem near_tight_locally_connected (G : MultiGraph n m) (u : Fin m → ℝ) + (hu0 : ∀e, 0 ≤ u e) (hu1 : ∀e, u e ≤ 1) + {κ Q h : ℝ} (hκ : 0 ≤ κ) (hκm : κ*m < 1) (hQ : 0 ≤ Q) (hh : h ≤ Q-2) + (hinv : ∀p, 0 ≤ slack G.left G.right (fun e => u e+κ) Q p) + {p : Setoid (Fin n)} (hp : slack G.left G.right (fun e => u e+κ) Q p ≤ 1) + {A : Finset (Fin n)} (hA : A ∈ parts p) : + (G.restrict (active u)).EdgeConnectedReal A h := by + obtain ⟨v,rfl⟩ := (mem_parts p A).mp hA + intro S hne hS + have hb := split_capacity_lower G (fun e => u e+κ) hQ hinv hp v hne hS + have hu := capacity_active_upper u hu0 hu1 hκ (G.cut (G.inducedEdges (block p v)) S) + rw [restrict_internal_cut_card] + linarith only [hb,hu,hκm,hh] + +end +end AlgorithmicThinTrees.Partitions +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionResponse.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionResponse.lean new file mode 100644 index 0000000000000000000000000000000000000000..ba7da337ce0967b2ef7d20ae12cf62a46e537d18 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionResponse.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.PartitionGeometry +import OAI.Combinatorics.ThinTrees.Metric.Response + +namespace OAI + +/-! Partition response. -/ + +section + +namespace AlgorithmicThinTrees.Partitions +noncomputable section +open Finset Matrix StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder + +variable {n m : ℕ} + +lemma lift_restrict_crossing (H : MultiGraph n m) (F : Finset (Fin m)) (p : Setoid (Fin n)) : + liftEdges F (crossing (H.restrict F) p)=crossing H p ∩ F := by + ext e + simp only [liftEdges,mem_map,mem_crossing,mem_inter] + constructor + · rintro ⟨i,hi,rfl⟩ + exact ⟨hi,embedding_mem F i⟩ + · rintro ⟨hi,he⟩ + obtain ⟨i,rfl⟩ := embedding_surj F he + exact ⟨i,hi,rfl⟩ + +lemma restrict_crossing_card (H : MultiGraph n m) (F : Finset (Fin m)) (p : Setoid (Fin n)) : + (crossing (H.restrict F) p).card=(crossing H p ∩ F).card := by + rw [←lift_restrict_crossing,liftEdges,card_map] + +lemma lift_restrict_crossing_filter (H : MultiGraph n m) (F : Finset (Fin m)) (p : Setoid (Fin n)) + (b : Fin m → Prop) : + liftEdges F ((crossing (H.restrict F) p).filter (fun e => b (edgeEmbedding F e)))= + (crossing H p ∩ F).filter b := by + rw [←lift_restrict_crossing,liftEdges,liftEdges,filter_map] + congr 1 + +lemma restrict_bad_card (H : MultiGraph n m) (F : Finset (Fin m)) (p : Setoid (Fin n)) + (b : Fin m → Prop) : + ((crossing (H.restrict F) p).filter (fun e => b (edgeEmbedding F e))).card= + ((crossing H p ∩ F).filter b).card := by + rw [←lift_restrict_crossing_filter,liftEdges,card_map] + +open MetricTests + +theorem finite_chain_response : + ∃r0 : ℕ, 2 ≤ r0 ∧ ∀r : ℕ, r0 ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.Connected univ → + ∀(F : Finset (Fin m)) (J : Finset (Setoid (Fin n))), + IsChain (· ≤ ·) (J : Set (Setoid (Fin n))) → + (∀p ∈ J, ∀A ∈ parts p, (H.restrict F).EdgeConnectedReal A (r/2:ℕ)) → + (H.restrict F).EdgeConnectedReal univ (r/2:ℕ) → + ∀s : ℝ, 0 < s → s ≤ (r:ℝ)^(1/4:ℝ) → + ∃Y ∈ metricDomain H, CenteredPositive Y ∧ ∀p ∈ J, + (((crossing H p ∩ F).filter (fun e => + ¬ (6*s) • vecMulVec (H.incidence e) (H.incidence e) ≤ Y)).card:ℝ) ≤ + (r:ℝ)^(-1/3:ℝ)*(crossing H p ∩ F).card := by + obtain ⟨r0,hr0,hresp⟩ := simultaneous_metric_response + refine ⟨r0,hr0,?_⟩ + intro r hr n m H hn hconn F J hJ hlocal hroot s hs hsR + have : Nonempty (Fin n) := ⟨⟨0,by omega⟩⟩ + obtain ⟨f,hf,hfroot,hfmem,hfsurj⟩ := enumerate_chain J hJ + let P := toChain f hf + have hpF : P.parts J.card={univ} := by + change parts (f J.card)={univ} + rw [hfroot,parts_top] + have hpL : ∀i ≤ J.card, ∀A ∈ P.parts i, (H.restrict F).EdgeConnectedReal A (r/2:ℕ) := by + intro i _ A hA + rcases hfmem i with hi | hi + · exact hlocal (f i) hi A hA + · change A ∈ parts (f i) at hA + rw [hi,parts_top,mem_singleton] at hA + exact hA ▸ hroot + obtain ⟨Y,hY,hYP,hbad⟩ := hresp r hr n m H hn hconn F P J.card hpF hpL s hs hsR + refine ⟨Y,hY,hYP,?_⟩ + intro p hp + obtain ⟨i,hi,hfi⟩ := hfsurj p hp + have hh := hbad i hi.le + rw [toChain_crossing,hfi,restrict_crossing_card] at hh + have he := restrict_bad_card H F p + (fun e => ¬ (6*s) • vecMulVec (H.incidence e) (H.incidence e) ≤ Y) + have hinc (e : Fin F.card) : (H.restrict F).incidence e=H.incidence (edgeEmbedding F e) := by + ext v + simp only [MultiGraph.incidence,MultiGraph.restrict,Pi.sub_apply] + simp_rw [hinc] at hh + convert hh using 1 + congr 1 + convert he.symm using 1 <;> congr 1 <;> ext e <;> simp only [mem_filter] + +end +end AlgorithmicThinTrees.Partitions +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionUncrossing.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionUncrossing.lean new file mode 100644 index 0000000000000000000000000000000000000000..4135278c8189d4a1ba57feee1957c763f52e014c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/PartitionUncrossing.lean @@ -0,0 +1,140 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.ConcaveAlternative +import OAI.Combinatorics.ThinTrees.Continuation.PartitionLattice + +namespace OAI + +/-! Partition uncrossing. -/ + +section + +namespace AlgorithmicThinTrees.Partitions +noncomputable section +open Finset +open scoped Classical + +variable {V X : Type*} [Fintype V] + +def Certificates (C : Set X) (f : Setoid V → X → ℝ) (b : ℝ) : Set (Setoid V → ℝ) := + {w | (∀p, 0 ≤ w p) ∧ (∑p, w p)=1 ∧ ∀x ∈ C, (∑p, w p*f p x) ≤ b} + +lemma certificates_isClosed (C : Set X) (f : Setoid V → X → ℝ) (b : ℝ) : + IsClosed (Certificates C f b) := by + have h0 : IsClosed {w : Setoid V → ℝ | ∀p, 0 ≤ w p} := by + simp only [Set.ofPred_forall] + exact isClosed_iInter (fun p => isClosed_le continuous_const (continuous_apply p)) + have h1 : IsClosed {w : Setoid V → ℝ | (∑p, w p)=1} := + isClosed_eq (continuous_finsetSum _ (fun p _ => continuous_apply p)) continuous_const + have h2 : IsClosed {w : Setoid V → ℝ | ∀x ∈ C, (∑p, w p*f p x) ≤ b} := by + simp only [Set.ofPred_forall] + exact isClosed_iInter (fun x => isClosed_iInter (fun _ => isClosed_le + (continuous_finsetSum _ (fun p _ => (continuous_apply p).mul_const _)) continuous_const)) + exact h0.inter (h1.inter h2) + +lemma certificates_compact (C : Set X) (f : Setoid V → X → ℝ) (b : ℝ) : + IsCompact (Certificates C f b) := by + have hbox : IsCompact {w : Setoid V → ℝ | ∀p, w p ∈ Set.Icc (0:ℝ) 1} := + isCompact_pi_infinite (fun _ => isCompact_Icc) + apply hbox.of_isClosed_subset (certificates_isClosed C f b) + intro w hw p + refine ⟨hw.1 p,?_⟩ + have hh := single_le_sum (fun q _ => hw.1 q) (mem_univ p) + exact hh.trans_eq hw.2.1 + +def uncrossWeight (w : Setoid V → ℝ) (p q : Setoid V) (δ : ℝ) : Setoid V → ℝ := + fun i => w i+(if i=p ⊓ q then δ else 0)+(if i=p ⊔ q then δ else 0)- + (if i=p then δ else 0)-(if i=q then δ else 0) + +omit [Fintype V] in +lemma uncrossWeight_nonneg (w : Setoid V → ℝ) (hw : ∀i, 0 ≤ w i) + {p q : Setoid V} (hpq : p ≠ q) {δ : ℝ} (hδ : 0 ≤ δ) + (hp : δ ≤ w p) (hq : δ ≤ w q) : ∀i, 0 ≤ uncrossWeight w p q δ i := by + intro i + have hmeet : 0 ≤ (if i=p ⊓ q then δ else 0) := by split_ifs <;> positivity + have hjoin : 0 ≤ (if i=p ⊔ q then δ else 0) := by split_ifs <;> positivity + unfold uncrossWeight + by_cases hip : i=p + · subst i + simp only [ite_true,ite_eq_right hpq] + linarith + · by_cases hiq : i=q + · subst i + simp only [ite_eq_right hip,ite_true] + linarith + · simp only [ite_eq_right hip,ite_eq_right hiq,sub_zero] + linarith [hw i] + +lemma uncrossWeight_dot (w g : Setoid V → ℝ) (p q : Setoid V) (δ : ℝ) : + (∑i, uncrossWeight w p q δ i*g i) = + (∑i, w i*g i)+δ*g (p ⊓ q)+δ*g (p ⊔ q)-δ*g p-δ*g q := by + simp [uncrossWeight,add_mul,sub_mul,sum_add_distrib,sum_sub_distrib,ite_mul] + +lemma uncrossWeight_sum (w : Setoid V → ℝ) (p q : Setoid V) (δ : ℝ) : + (∑i, uncrossWeight w p q δ i)=∑i, w i := by + have hh := uncrossWeight_dot w (fun _ => 1) p q δ + simpa only [mul_one,add_sub_cancel_right] using hh + +theorem chain_certificate (C : Set X) (f : Setoid V → X → ℝ) (b : ℝ) + (hsub : ∀x ∈ C, ∀p q, f (p ⊓ q) x+f (p ⊔ q) x ≤ f p x+f q x) + (hne : (Certificates C f b).Nonempty) : + ∃w ∈ Certificates C f b, IsChain (· ≤ ·) {p | 0 < w p} := by + let Φ : (Setoid V → ℝ) → ℝ := fun w => ∑p, w p*potential p + have hΦ : Continuous Φ := continuous_finsetSum _ + (fun p _ => (continuous_apply p).mul_const _) + obtain ⟨w,hw,hmax⟩ := (certificates_compact C f b).exists_isMaxOn hne hΦ.continuousOn + refine ⟨w,hw,?_⟩ + intro p hp q hq _ + by_contra hincomp + have hpq : ¬p ≤ q := fun h => hincomp (Or.inl h) + have hqp : ¬q ≤ p := fun h => hincomp (Or.inr h) + have hnepq : p ≠ q := fun he => hpq (he ▸ le_rfl) + let δ := min (w p) (w q) + have hδ : 0 < δ := lt_min hp hq + let w' := uncrossWeight w p q δ + have hw' : w' ∈ Certificates C f b := by + refine ⟨uncrossWeight_nonneg w hw.1 hnepq hδ.le (min_le_left _ _) (min_le_right _ _),?_,?_⟩ + · rw [uncrossWeight_sum] + exact hw.2.1 + · intro x hx + dsimp [w'] + rw [uncrossWeight_dot] + have hh := mul_le_mul_of_nonneg_left (hsub x hx p q) hδ.le + linarith [hw.2.2 x hx] + have hgain := mul_pos hδ (sub_pos.mpr (potential_uncross hpq hqp)) + have hdot : Φ w' = Φ w+δ*potential (p ⊓ q)+δ*potential (p ⊔ q)-δ*potential p-δ*potential q := + uncrossWeight_dot w potential p q δ + have hmax' := (isMaxOn_iff.mp hmax) w' hw' + nlinarith only [hgain,hdot,hmax'] + +variable [AddCommGroup X] [Module ℝ X] [TopologicalSpace X] + +theorem feasible_of_chain_feasible (C : Set X) (hcompact : IsCompact C) + (hne : C.Nonempty) (hconvex : Convex ℝ C) (f : Setoid V → X → ℝ) + (hcontinuous : ∀p, ContinuousOn (f p) C) + (hconcave : ∀p, ConcaveOn ℝ C (f p)) + (hsub : ∀x ∈ C, ∀p q, f (p ⊓ q) x+f (p ⊔ q) x ≤ f p x+f q x) + (hchains : ∀J : Finset (Setoid V), IsChain (· ≤ ·) (J : Set (Setoid V)) → + ∃x ∈ C, ∀p ∈ J, 0 ≤ f p x) : + ∃x ∈ C, ∀p, 0 ≤ f p x := by + by_contra hnone + obtain ⟨ε,hε,w,hw,hws,hbound⟩ := ConvexAlternative.compact_concave_alternative C + hcompact hne hconvex f hcontinuous hconcave hnone + obtain ⟨v,hv,hvchain⟩ := chain_certificate C f (-ε) hsub ⟨w,hw,hws,hbound⟩ + let J := univ.filter (fun p => 0 < v p) + have hJ : IsChain (· ≤ ·) (J : Set (Setoid V)) := by + simpa only [J,coe_filter,coe_univ,Set.sep_univ,mem_univ,true_and] using hvchain + obtain ⟨x,hx,hxJ⟩ := hchains J hJ + have hnon : 0 ≤ ∑p, v p*f p x := by + apply sum_nonneg + intro p _ + by_cases hp : 0 < v p + · exact mul_nonneg hp.le (hxJ p (mem_filter.mpr ⟨mem_univ p,hp⟩)) + · have he : v p=0 := le_antisymm (le_of_not_gt hp) (hv.1 p) + simp [he] + linarith only [hnon,hv.2.2 x hx,hε] + +end +end AlgorithmicThinTrees.Partitions +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Pencil.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Pencil.lean new file mode 100644 index 0000000000000000000000000000000000000000..eeca72157821666159ba77c9710f6a954a868a09 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Pencil.lean @@ -0,0 +1,192 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Coordinates +import OAI.Combinatorics.ThinTrees.Pencil.AffinePencil + +namespace OAI + +/-! Continuation pencil. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Orientations RationalForms +open scoped BigOperators +variable {n m : ℕ} + +abbrev Form (n m : ℕ) := Affine (dimension n m) + +def qdiff (i j : Fin n) : Fin n → ℚ := Pi.single i 1-Pi.single j 1 + +def qlap (H : MultiGraph n m) : Matrix (Fin n) (Fin n) ℚ := + ∑e, vecMulVec (qdiff (H.left e) (H.right e)) (qdiff (H.left e) (H.right e)) + +def qtriangle (ijk : DistinctTriple n) : Matrix (Fin n) (Fin n) ℚ := + vecMulVec (qdiff ijk.1.1 ijk.1.2.1) (qdiff ijk.1.1 ijk.1.2.1)+ + vecMulVec (qdiff ijk.1.2.1 ijk.1.2.2) (qdiff ijk.1.2.1 ijk.1.2.2)- + vecMulVec (qdiff ijk.1.1 ijk.1.2.2) (qdiff ijk.1.1 ijk.1.2.2) + +def qproject (n : ℕ) : Matrix (Fin n) (Fin n) ℚ := (1 : Matrix (Fin n) (Fin n) ℚ)-Matrix.of (fun (_ _ : Fin n) => (n:ℚ)⁻¹) + +lemma cast_qdiff (i j k : Fin n) : (qdiff i j k : ℝ)=difference i j k := by + simp only [qdiff, difference, point, Pi.sub_apply, Pi.single_apply, Rat.cast_sub] + split_ifs <;> norm_num +lemma cast_qinc (H : MultiGraph n m) (e : Fin m) (i : Fin n) : + (qdiff (H.left e) (H.right e) i : ℝ)=H.incidence e i := cast_qdiff _ _ _ +lemma cast_qlap (H : MultiGraph n m) (i j : Fin n) : (qlap H i j : ℝ)=H.laplacian univ i j := by + simp [qlap,laplacian,Matrix.sum_apply,Rat.cast_sum,vecMulVec,cast_qinc] +lemma cast_qtriangle (ijk : DistinctTriple n) (i j : Fin n) : + (qtriangle ijk i j : ℝ)=triangleGenerator ijk i j := by + simp [qtriangle,triangleGenerator,triangleMatrix,Matrix.sub_apply,vecMulVec,cast_qdiff] +lemma cast_qproject (i j : Fin n) : (qproject n i j : ℝ)=centering n i j := by + change (((1 : Matrix (Fin n) (Fin n) ℚ) i j-(n:ℚ)⁻¹ : ℚ) : ℝ)=_ + simp only [centering,constantProjection,Matrix.sub_apply,Matrix.smul_apply,smul_eq_mul, + vecMulVec,Matrix.of_apply,ones,mul_one,Rat.cast_sub,Rat.cast_inv,Rat.cast_natCast, + Matrix.one_apply] + split_ifs <;> norm_num + +def matrixForm (i j : Fin n) : Form n m := + ∑b, ∑a, (qproject n i a*qproject n b j/2) • + (Affine.coord (matIndex a b)+Affine.coord (matIndex b a)) + +def lowerForm (H : MultiGraph n m) : Matrix (Fin n) (Fin n) (Form n m) := + fun i j => matrixForm i j-Affine.cst (qlap H i j) + +def upperForm (H : MultiGraph n m) : Matrix (Fin n) (Fin n) (Form n m) := + fun i j => Affine.cst (3*qlap H i j)-matrixForm i j- + ∑ijk : DistinctTriple n, (qtriangle ijk i j) • Affine.coord (mulIndex ijk.val) + +def edgeForm (H : MultiGraph n m) (s : ℚ) (e : Fin m) : Matrix (Fin n) (Fin n) (Form n m) := + fun i j => matrixForm i j- + (6*s*qdiff (H.left e) (H.right e) i*qdiff (H.left e) (H.right e) j) • Affine.coord (edgeIndex 0 e) + +lemma real_matrixForm (v : Fin (dimension n m) → ℝ) (i j : Fin n) : + Affine.real v (matrixForm i j)=(step v).matrix i j := by + simp only [matrixForm,Affine.real_sum,Affine.real_smul,Affine.real_add,Affine.real_coord, + Rat.cast_div,Rat.cast_mul,Rat.cast_ofNat,cast_qproject] + simp only [step,StepFree.matrix,responseMatrix,centered,Matrix.mul_apply, + Matrix.smul_apply,Matrix.add_apply,Matrix.transpose_apply,rawMatrix,smul_eq_mul,sum_mul] + apply sum_congr rfl + intro b _ + apply sum_congr rfl + intro a _ + ring + +lemma real_lowerForm (H : MultiGraph n m) (v : Fin (dimension n m) → ℝ) : + (lowerForm H).map (Affine.real v)=(step v).lowerPencil H := by + ext i j + simp [lowerForm,real_matrixForm,cast_qlap,StepFree.lowerPencil,Matrix.sub_apply] +lemma real_upperForm (H : MultiGraph n m) (v : Fin (dimension n m) → ℝ) : + (upperForm H).map (Affine.real v)=(step v).upperPencil H := by + ext i j + simp only [Matrix.map_apply,upperForm,Affine.real_sub,Affine.real_cst,Affine.real_sum, + Affine.real_smul,Affine.real_coord,real_matrixForm,Rat.cast_mul,Rat.cast_ofNat,cast_qlap,cast_qtriangle] + simp only [StepFree.upperPencil,step,StepFree.multiplier,multiplier,Matrix.sub_apply, + Matrix.smul_apply,smul_eq_mul,Matrix.sum_apply] + congr 1 + apply sum_congr rfl + intro ijk _ + ring +lemma real_edgeForm (H : MultiGraph n m) (s : ℚ) (e : Fin m) (v : Fin (dimension n m) → ℝ) : + (edgeForm H s e).map (Affine.real v)=(step v).edgePencil H (s:ℝ) e := by + ext i j + simp [edgeForm,real_matrixForm,cast_qinc,StepFree.edgePencil,step,StepFree.y,y, + Matrix.sub_apply,vecMulVec] + ring + +abbrev MatBlock (m : ℕ) := Fin 2 ⊕ Fin m + +def matrixBlocks (H : MultiGraph n m) (s : ℚ) (u : Fin m → ℚ) : + MatBlock m → Matrix (Fin n) (Fin n) (Form n m) + | .inl p => if p=0 then lowerForm H else upperForm H + | .inr e => if 0 + simp only [matrixBlocks] + split_ifs + · rw [real_lowerForm] + exact isHermitian_iff_isSymm.mp (lowerPencil_hermitian H _) + · rw [real_upperForm] + exact isHermitian_iff_isSymm.mp (upperPencil_hermitian H _) + | inr e => + simp only [matrixBlocks] + split_ifs + · rw [real_edgeForm] + exact isHermitian_iff_isSymm.mp (edgePencil_hermitian H _ _ _) + · simp + +abbrev ScalarBlock (n m : ℕ) := + Triple n ⊕ ((Fin 7 × Fin m) ⊕ ((Fin 3 × (Fin n × Fin m)) ⊕ ((Fin n × Fin n) ⊕ Fin 1))) + +def capacityForm (κ : ℚ) (u : Fin m → ℚ) (e : Fin m) : Form n m := + if 0 if ijk.1≠ijk.2.1 ∧ ijk.2.1≠ijk.2.2 ∧ ijk.1≠ijk.2.2 then Affine.coord (mulIndex ijk) else 0 + | .inr (.inl (p,e)) => + ![Affine.coord (edgeIndex 0 e),Affine.cst 1-Affine.coord (edgeIndex 0 e), + Affine.coord (edgeIndex 1 e),Affine.cst (κ+1)-Affine.coord (edgeIndex 1 e), + if 0 + ![Affine.coord (flowIndex 0 r e),Affine.coord (flowIndex 1 r e), + Affine.coord (flowIndex 0 r e)+Affine.coord (flowIndex 1 r e)-Affine.coord (edgeIndex 2 e)] p + | .inr (.inr (.inr (.inl (r,v)))) => + Affine.cst (if v=r then ε else qbar)-∑e, + ((if H.left e=v then Affine.coord (flowIndex 0 r e) else 0)+ + (if H.right e=v then Affine.coord (flowIndex 1 r e) else 0)) + | .inr (.inr (.inr (.inr _))) => + (∑e, Affine.coord (edgeIndex 2 e))-Affine.cst (qbar*((n:ℚ)-1)-ε) + +def order (n m : ℕ) := n*(2+m)+(n*(n*n)+(7*m+(3*(n*m)+(n*n+1)))) + +def rowIndex (n m : ℕ) : ((Fin n × MatBlock m) ⊕ ScalarBlock n m) ≃ Fin (order n m) := + let et : Triple n ≃ Fin (n*(n*n)) := + ((Equiv.refl (Fin n)).prodCongr finProdFinEquiv).trans finProdFinEquiv + let ef : (Fin 3 × (Fin n × Fin m)) ≃ Fin (3*(n*m)) := + ((Equiv.refl (Fin 3)).prodCongr finProdFinEquiv).trans finProdFinEquiv + let eu := (finProdFinEquiv.sumCongr (Equiv.refl (Fin 1))).trans finSumFinEquiv + let ee := (finProdFinEquiv.sumCongr ((ef.sumCongr eu).trans finSumFinEquiv)).trans finSumFinEquiv + let em := ((Equiv.refl (Fin n)).prodCongr finSumFinEquiv).trans finProdFinEquiv + (em.sumCongr ((et.sumCongr ee).trans finSumFinEquiv)).trans finSumFinEquiv + +def affineMatrix (H : MultiGraph n m) (s κ t qbar ε : ℚ) (u : Fin m → ℚ) : + Matrix (Fin (order n m)) (Fin (order n m)) (Form n m) := + (Matrix.fromBlocks (Matrix.blockDiagonal (matrixBlocks H s u)) 0 0 + (Matrix.diagonal (scalarForms H κ t qbar ε u))).submatrix (rowIndex n m).symm (rowIndex n m).symm + +lemma affineMatrix_symmetric (H : MultiGraph n m) (s κ t qbar ε : ℚ) (u : Fin m → ℚ) : + (affineMatrix H s κ t qbar ε u).IsSymm := by + apply IsSymm.submatrix + apply IsSymm.ext + intro i j + cases i with + | inl i => + cases j with + | inl j => + simp only [Matrix.fromBlocks_apply₁₁,Matrix.blockDiagonal,Matrix.of_apply] + by_cases h : i.2=j.2 + · simp only [h,ite_true] + exact (matrixBlocks_symmetric H s u j.2).apply _ _ + · simp only [h,Ne.symm h,ite_false] + | inr j => rfl + | inr i => + cases j with + | inl j => rfl + | inr j => + exact (Matrix.isSymm_diagonal _).apply i j + +def continuationPencil (H : MultiGraph n m) (s κ t qbar ε : ℚ) (u : Fin m → ℚ) : + CurrentKS.RationalSDP.Pencil (dimension n m) (order n m) := + pencil (affineMatrix H s κ t qbar ε u) (affineMatrix_symmetric H s κ t qbar ε u) + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/PencilCorrectness.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/PencilCorrectness.lean new file mode 100644 index 0000000000000000000000000000000000000000..aa453f3447a32d0f2c024e3cb9797745a6153559 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/PencilCorrectness.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.FiniteContinuation +import OAI.Combinatorics.ThinTrees.Continuation.Pencil + +namespace OAI + +/-! Continuation pencil correctness. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Orientations RationalForms +open scoped BigOperators +variable {n m : ℕ} + +@[simp] lemma step_y (v : Fin (dimension n m) → ℝ) (e : Fin m) : + (step v).y e = v (edgeIndex 0 e) := rfl +@[simp] lemma step_z (v : Fin (dimension n m) → ℝ) (e : Fin m) : + (step v).z e = v (edgeIndex 1 e) := rfl +@[simp] lemma step_mul (v : Fin (dimension n m) → ℝ) (ijk : DistinctTriple n) : + (step v).multiplier ijk = v (mulIndex ijk.val) := rfl +@[simp] lemma flow_x (v : Fin (dimension n m) → ℝ) (e : Fin m) : + (flow v).x e = v (edgeIndex 2 e) := rfl +@[simp] lemma flow_a (v : Fin (dimension n m) → ℝ) (r : Fin n) (e : Fin m) : + (flow v).a r e = v (flowIndex 0 r e) := rfl +@[simp] lemma flow_b (v : Fin (dimension n m) → ℝ) (r : Fin n) (e : Fin m) : + (flow v).b r e = v (flowIndex 1 r e) := rfl + +lemma real_capacityForm (κ : ℚ) (u : Fin m → ℚ) (e : Fin m) (v : Fin (dimension n m) → ℝ) : + Affine.real v (capacityForm κ u e) = (step v).capacities (κ:ℝ) (fun e => (u e:ℝ)) e := by + simp only [capacityForm,StepFree.capacities,step,StepFree.z,z] + have h : (0:ℝ)<(u e:ℝ) ↔ (0:ℚ) simp + +lemma matrixBlocks_psd (H : MultiGraph n m) (s : ℚ) (u : Fin m → ℚ) + (v : Fin (dimension n m) → ℝ) : + (∀b, ((matrixBlocks H s u b).map (Affine.real v)).PosSemidef) ↔ + ((step v).lowerPencil H).PosSemidef ∧ ((step v).upperPencil H).PosSemidef ∧ + ∀e, (0:ℝ)<(u e:ℝ) → ((step v).edgePencil H (s:ℝ) e).PosSemidef := by + constructor + · intro h + refine ⟨?_,?_,?_⟩ + · simpa only [matrixBlocks,ite_true,real_lowerForm] using h (.inl 0) + · simpa only [matrixBlocks,show (1 : Fin 2)≠0 from by decide,ite_false,real_upperForm] using h (.inl 1) + · intro e he + have he' : 0 simp only [matrixBlocks]; split_ifs <;> first | simpa only [real_lowerForm] using hl | simpa only [real_upperForm] using hu + | inr e => + simp only [matrixBlocks] + split_ifs with h + · simpa only [real_edgeForm] using he e (by exact_mod_cast h) + · simpa using (show (0 : Matrix (Fin n) (Fin n) ℝ).PosSemidef from PosSemidef.zero) + +lemma scalarForms_nonneg (H : MultiGraph n m) (κ t qbar ε : ℚ) (u : Fin m → ℚ) + (v : Fin (dimension n m) → ℝ) : + (∀b, 0 ≤ Affine.real v (scalarForms H κ t qbar ε u b)) ↔ + (∀ijk, 0 ≤ (step v).multiplier ijk) ∧ + (∀e, (step v).y e ∈ Set.Icc (0:ℝ) 1) ∧ + (∀e, (step v).z e ∈ Set.Icc 0 ((κ:ℝ)+1)) ∧ + (∀e, (0:ℝ)<(u e:ℝ) → (step v).z e ≤ (κ:ℝ)+(u e:ℝ)+(t:ℝ)*(5*(step v).y e-4)) ∧ + (flow v).Feasible H ((step v).capacities (κ:ℝ) (fun e => (u e:ℝ))) (qbar:ℝ) (ε:ℝ) := by + have cast_pos (e : Fin m) : (0:ℝ)<(u e:ℝ) ↔ (0:ℚ) rfl + simp only [hi,Affine.real_coord,Affine.real_zero] at hr + have hh : ((if w=r then ε else qbar : ℚ):ℝ) = if w=r then (ε:ℝ) else (qbar:ℝ) := by split_ifs <;> rfl + rw [hh] at hr + exact sub_nonneg.mp hr + · have hh := h (.inr (.inr (.inr (.inr 0)))) + simp only [scalarForms,Affine.real_sub,Affine.real_sum,Affine.real_coord,Affine.real_cst, + Rat.cast_sub,Rat.cast_mul,Rat.cast_natCast,Rat.cast_one] at hh + exact sub_nonneg.mp hh + · rintro ⟨hm,hy,hz,hactive,hF⟩ b + cases b with + | inl ijk => + simp only [scalarForms] + split_ifs with h + · simpa only [Affine.real_coord,step_mul] using hm ⟨ijk,h⟩ + · simp + | inr b => + cases b with + | inl pe => + rcases pe with ⟨p,e⟩ + fin_cases p + · simpa [scalarForms] using (hy e).1 + · simpa [scalarForms] using sub_nonneg.mpr (hy e).2 + · simpa [scalarForms] using (hz e).1 + · simpa [scalarForms] using sub_nonneg.mpr (hz e).2 + · change 0 ≤ Affine.real v (if 0 + cases b with + | inl pre => + rcases pre with ⟨p,r,e⟩ + fin_cases p + · simpa [scalarForms] using (hF.2.1 r e).1 + · simpa [scalarForms] using (hF.2.1 r e).2.1 + · simpa [scalarForms] using sub_nonneg.mpr (hF.2.1 r e).2.2 + | inr b => + cases b with + | inl rv => + rcases rv with ⟨r,w⟩ + have hr := sub_nonneg.mpr (hF.2.2.1 r w) + simp only [scalarForms,Affine.real_sub,Affine.real_sum,Affine.real_add] + have hi (a b : Form n m) (p : Prop) [Decidable p] : + Affine.real v (if p then a else b) = if p then Affine.real v a else Affine.real v b := by split_ifs <;> rfl + simp only [hi,Affine.real_coord,Affine.real_zero,Affine.real_cst] + have hh : ((if w=r then ε else qbar : ℚ):ℝ) = if w=r then (ε:ℝ) else (qbar:ℝ) := by split_ifs <;> rfl + rw [hh] + exact hr + | inr p => + simpa only [scalarForms,Affine.real_sub,Affine.real_sum,Affine.real_coord,flow_x, + Affine.real_cst,Rat.cast_sub,Rat.cast_mul,Rat.cast_natCast,Rat.cast_one] + using sub_nonneg.mpr hF.2.2.2 + +lemma continuationPencil_psd (H : MultiGraph n m) (s κ t qbar ε : ℚ) (u : Fin m → ℚ) + (v : Fin (dimension n m) → ℝ) : + ((continuationPencil H s κ t qbar ε u).realEval v).PosSemidef ↔ + finiteStep H (s:ℝ) (κ:ℝ) (t:ℝ) (qbar:ℝ) (ε:ℝ) (fun e => (u e:ℝ)) (step v) (flow v) := by + rw [continuationPencil,pencil_realEval] + simp only [affineMatrix,←Matrix.submatrix_map,submatrix_equiv_psd,RationalForms.fromBlocks_map, + RationalForms.blockDiagonal_map,RationalForms.diagonal_map,fromBlocks_psd,blockDiagonal_psd,Matrix.posSemidef_diagonal_iff] + rw [matrixBlocks_psd,scalarForms_nonneg] + simp only [finiteStep,stepCore,Set.mem_ofPred_eq,forall_and] + tauto + +lemma order_bound (n m : ℕ) : order n m ≤ (n+m+2)^3 := by + unfold order + nlinarith [Nat.zero_le (n*n*m),Nat.zero_le (n*m*m),Nat.zero_le (m*m*m)] + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Ramp.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Ramp.lean new file mode 100644 index 0000000000000000000000000000000000000000..178aac05acd83db578a1ab560a5a77c69fb1ae8e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Ramp.lean @@ -0,0 +1,179 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.CenteredDomain + +namespace OAI + +/-! Continuation ramp. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder + +variable {n m : ℕ} + +lemma incidence_ne_zero (G : MultiGraph n m) (e : Fin m) : G.incidence e ≠ 0 := by + intro hz + have he := congrFun hz (G.left e) + simp [MultiGraph.incidence,MultiGraph.point,G.loopless e] at he + +lemma centered_resistance_pos (G : MultiGraph n m) (hn : 0 < n) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : CenteredPositive X) (e : Fin m) : + 0 < resistance G X e := by + simpa only [resistance,inverseOnZeroSum,StrongThinTree.qform,star_trivial] using + (regularize_pd hn hX).inv.dotProduct_mulVec_pos (incidence_ne_zero G e) + +def cappedParameter (G : MultiGraph n m) (s : ℝ) (X : Matrix (Fin n) (Fin n) ℝ) (e : Fin m) : ℝ := + min 2 (s*resistance G X e)⁻¹ + +def ramp (G : MultiGraph n m) (s : ℝ) (X : Matrix (Fin n) (Fin n) ℝ) (e : Fin m) : ℝ := + max 0 (cappedParameter G s X e-1) + +lemma cappedParameter_pos (G : MultiGraph n m) (hn : 0 < n) {s : ℝ} (hs : 0 < s) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : CenteredPositive X) (e : Fin m) : + 0 < cappedParameter G s X e := + lt_min (by norm_num) (inv_pos.mpr (mul_pos hs (centered_resistance_pos G hn hX e))) + +lemma cappedParameter_le_two (G : MultiGraph n m) (s : ℝ) (X : Matrix (Fin n) (Fin n) ℝ) (e : Fin m) : + cappedParameter G s X e ≤ 2 := min_le_left _ _ + +lemma ramp_nonneg (G : MultiGraph n m) (s : ℝ) (X : Matrix (Fin n) (Fin n) ℝ) (e : Fin m) : + 0 ≤ ramp G s X e := le_max_left _ _ + +lemma ramp_le_one (G : MultiGraph n m) (s : ℝ) (X : Matrix (Fin n) (Fin n) ℝ) (e : Fin m) : + ramp G s X e ≤ 1 := max_le (by norm_num) (by linarith [cappedParameter_le_two G s X e]) + +lemma ramp_active (G : MultiGraph n m) {s : ℝ} {X : Matrix (Fin n) (Fin n) ℝ} {e : Fin m} + (ha : 0 < ramp G s X e) : + 1 < cappedParameter G s X e ∧ ramp G s X e=cappedParameter G s X e-1 := by + have hp : 0 < cappedParameter G s X e-1 := by + simpa only [ramp,lt_max_iff,lt_self_iff_false,false_or] using ha + exact ⟨by linarith,max_eq_right hp.le⟩ + +lemma capped_rankOne (G : MultiGraph n m) (hn : 0 < n) {s : ℝ} (hs : 0 < s) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : CenteredPositive X) (e : Fin m) : + (s*cappedParameter G s X e) • vecMulVec (G.incidence e) (G.incidence e) ≤ X := by + rw [Matrix.le_iff,centered_resistance_order hn hX (incidence_sum G e) + (mul_pos hs (cappedParameter_pos G hn hs hX e))] + change s*cappedParameter G s X e*resistance G X e ≤ 1 + have hr : 0 < s*resistance G X e := mul_pos hs (centered_resistance_pos G hn hX e) + have hm := mul_le_mul_of_nonneg_right + (min_le_right (2:ℝ) (s*resistance G X e)⁻¹) hr.le + rw [inv_mul_cancel₀ hr.ne'] at hm + dsimp only [cappedParameter] + nlinarith only [hm] + +def lowerCapacity (κ t u y : ℝ) : ℝ := + if 0 < u then κ+min 1 (u+t*(5*y-4)) else κ + +lemma lowerCapacity_lower {κ t u y : ℝ} (ht : 0 ≤ t) (hy : 0 ≤ y) : + κ-4*t ≤ lowerCapacity κ t u y := by + unfold lowerCapacity + split_ifs with hu + · have hm : -4*t ≤ min 1 (u+t*(5*y-4)) := by + apply le_min + · linarith + · nlinarith [mul_nonneg ht hy] + linarith + · linarith + +lemma lowerCapacity_nonneg {κ t u y : ℝ} (ht : 0 ≤ t) (hy : 0 ≤ y) (hκ : 4*t ≤ κ) : + 0 ≤ lowerCapacity κ t u y := (sub_nonneg.mpr hκ).trans (lowerCapacity_lower ht hy) + +lemma lowerCapacity_le {κ t u y : ℝ} : lowerCapacity κ t u y ≤ κ+1 := by + unfold lowerCapacity + split_ifs + · exact add_le_add_right (min_le_left _ _) κ + · linarith + +lemma continuation_scalar {t p y : ℝ} (ht : 0 ≤ t) (ht1 : t ≤ 1/5) + (hp : p ≤ 2) (hy : 0 ≤ y) : + p+t*(5*y-4) ≤ ((1-t)*p+6*t*y)/(1+t) := by + apply (le_div_iff₀ (by linarith : 0 < 1+t)).mpr + have hy' : 0 ≤ (1-5*t)*y := mul_nonneg (by linarith) hy + have hrem : 0 ≤ t*((1-5*t)*y+4+4*t-2*p) := + mul_nonneg ht (by linarith) + nlinarith only [hrem] + +lemma ramp_scalar_lower {p z t y : ℝ} (hp : 1 < p) (ht : 0 ≤ t) (ht1 : t ≤ 1/5) + (hp2 : p ≤ 2) (hy : 0 ≤ y) + (hz : ((1-t)*p+6*t*y)/(1+t) ≤ z) : + min 1 (max 0 (p-1)+t*(5*y-4)) ≤ max 0 (min 2 z-1) := by + rw [max_eq_right (by linarith : 0 ≤ p-1)] + have hz' := (continuation_scalar ht ht1 hp2 hy).trans hz + have hcap := min_le_min_left (2:ℝ) hz' + have he : min (1:ℝ) (p-1+t*(5*y-4))=min 2 (p+t*(5*y-4))-1 := by + rw [←min_sub_sub_right] + congr 1 <;> ring + rw [he] + exact (sub_le_sub_right hcap 1).trans (le_max_right _ _) + +lemma continuation_reciprocal (G : MultiGraph n m) (hn : 0 < n) + {X Y : Matrix (Fin n) (Fin n) ℝ} (hX : CenteredPositive X) + {s t y : ℝ} (hs : 0 < s) (ht : 0 ≤ t) (ht1 : t ≤ 1/5) + (hy : 0 ≤ y) (e : Fin m) + (hresp : (6*s*y) • vecMulVec (G.incidence e) (G.incidence e) ≤ Y) + (hnew : CenteredPositive ((1-t) • X+t • Y)) : + ((1-t)*cappedParameter G s X e+6*t*y)/(1+t) ≤ + ((1+t)*s*resistance G ((1-t) • X+t • Y) e)⁻¹ := by + let b := vecMulVec (G.incidence e) (G.incidence e) + let p := cappedParameter G s X e + let c := ((1-t)*p+6*t*y)*s + have ht' : 0 < 1-t := by linarith + have hp : 0 < p := cappedParameter_pos G hn hs hX e + have hc : 0 < c := mul_pos (add_pos_of_pos_of_nonneg (mul_pos ht' hp) (by positivity)) hs + have horder : c • b ≤ (1-t) • X+t • Y := by + have h1 := (Matrix.le_iff.mp (capped_rankOne G hn hs hX e)).smul ht'.le + have h2 := (Matrix.le_iff.mp hresp).smul ht + apply Matrix.le_iff.mpr + convert h1.add h2 using 1 + dsimp [c,p,b] + simp only [smul_sub,smul_smul] + module + have hrank := (centered_resistance_order hn hnew (incidence_sum G e) hc).mp (Matrix.le_iff.mp horder) + have hR := centered_resistance_pos G hn hnew e + have hnR : 0 < (1+t)*s*resistance G ((1-t) • X+t • Y) e := by positivity + rw [←one_div] + apply (le_div_iff₀ hnR).mpr + have hden : (1-t)*p+6*t*y ≥ 0 := by positivity + have hquot := (div_mul_cancel₀ ((1-t)*p+6*t*y) (by linarith : (1+t) ≠ 0)) + have he : (((1-t)*p+6*t*y)/(1+t))*((1+t)*s*resistance G ((1-t) • X+t • Y) e)= + c*resistance G ((1-t) • X+t • Y) e := by + dsimp [c] + calc + _ = ((((1-t)*p+6*t*y)/(1+t))*(1+t))*(s*resistance G ((1-t) • X+t • Y) e) := by ring + _ = _ := by rw [hquot]; ring + rw [he] + exact hrank + +theorem continuation_ramp_lower (G : MultiGraph n m) (hn : 0 < n) (hconn : G.Connected univ) + {X Y : Matrix (Fin n) (Fin n) ℝ} (hX : X ∈ metricDomain G) (hY : Y ∈ metricDomain G) + {s t κ : ℝ} (hs : 0 < s) (ht : 0 ≤ t) (ht1 : t ≤ 1/5) + (y : Fin m → ℝ) (hy : ∀e, 0 ≤ y e) + (hresp : ∀e, 0 < ramp G s X e → + (6*s*y e) • vecMulVec (G.incidence e) (G.incidence e) ≤ Y) : + ((1-t) • X+t • Y) ∈ metricDomain G ∧ ∀e, + lowerCapacity κ t (ramp G s X e) (y e) ≤ + ramp G ((1+t)*s) ((1-t) • X+t • Y) e+κ := by + have hnext := domain_convex G hX hY (by linarith : 0 ≤ 1-t) ht (by ring : 1-t+t=1) + refine ⟨hnext,?_⟩ + intro e + by_cases hactive : 0 < ramp G s X e + · rw [lowerCapacity,ite_eq_left hactive] + have hrecip := continuation_reciprocal G hn (domain_positive G hn hconn hX) + hs ht ht1 (hy e) e (hresp e hactive) (domain_positive G hn hconn hnext) + have hscalar := ramp_scalar_lower (ramp_active G hactive).1 ht ht1 + (cappedParameter_le_two G s X e) (hy e) hrecip + change min 1 (ramp G s X e+t*(5*y e-4)) ≤ + ramp G ((1+t)*s) ((1-t) • X+t • Y) e at hscalar + linarith + · rw [lowerCapacity,ite_eq_right hactive] + linarith [ramp_nonneg G ((1+t)*s) ((1-t) • X+t • Y) e] + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Realization.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Realization.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea566c799dc03ac697a11d834ecc68192fb192ab --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Realization.lean @@ -0,0 +1,214 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Arithmetic.UnaryRoot +import OAI.Combinatorics.ThinTrees.Continuation.Loop +import OAI.Combinatorics.ThinTrees.Pencil.PointPrograms +import OAI.Combinatorics.ThinTrees.Pencil.SearchRealization + +namespace OAI + +/-! Continuation realization. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree +open AlgorithmicThinTrees.GraphStack + +abbrev graphBaseline : Realizes graphCode ratCode (fun G => baselineQ G.m) := + (constant graphCode ratCode 1).div ((numEdges.then natToRat).add (constant graphCode ratCode 1)) +private instance poly_graphBaseline : PolyTime graphBaseline := by + unfold graphBaseline + apply poly_div + +abbrev graphStep : Realizes graphCode ratCode (fun G => stepQ G.m) := + graphBaseline.div (constant graphCode ratCode 32) +private instance poly_graphStep : PolyTime graphStep := by + unfold graphStep + apply poly_div + +def graphError : Realizes graphCode ratCode (fun G => errorQ G.n G.m) := + ((constant graphCode ratCode 1).div (graphSizeProgram.pow 10)).congr (by + intro G; simp only [errorQ,_root_.zpow_neg,one_div];rfl) +instance poly_graphError : PolyTime graphError := by unfold graphError;infer_instance + +def gainProgram : Realizes natCode ratCode gain := + (constant natCode ratCode 1).div ((unaryRoot 8 (by decide)).then natToRat) +instance poly_gainProgram : PolyTime gainProgram := by unfold gainProgram; apply poly_div + +def clockProgram : Realizes (prodCode natCode natCode) natCode + (fun p => scheduleLength p.1 p.2) := + ((constant (prodCode natCode natCode) natCode 32).nmul + ((first natCode natCode).then natSucc)).nmul + ((second natCode natCode).then (unaryRoot 16 (by decide))) +instance poly_clockProgram : PolyTime clockProgram := by + unfold clockProgram Realizes.nmul + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · refine @poly_both _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · infer_instance + · apply poly_then + · infer_instance + +structure Loop where + graph : Graph + count : ℕ + state : State graph.n graph.m + +abbrev loopTailCode := prodCode ratCode (prodCode ratCode (prodCode matrixCode vectorCode)) +abbrev loopDataCode := prodCode graphCode (prodCode natCode loopTailCode) +def Loop.data (a : Loop) := + (a.graph,(a.count,(a.state.scale,(a.state.quality,(matrixData a.state.matrix,List.ofFn a.state.capacity))))) +def loopCode (a : Loop) : Word := loopDataCode a.data +abbrev loopView : Realizes loopCode loopDataCode Loop.data := + (identity loopDataCode).reindex loopCode Loop.data (fun _ => rfl) +private instance poly_loopView : PolyTime loopView := by + unfold loopView + apply poly_reindex + +abbrev loopGraph : Realizes loopCode graphCode Loop.graph := + loopView.then (first graphCode (prodCode natCode loopTailCode)) +private instance poly_loopGraph : PolyTime loopGraph := by + unfold loopGraph + apply poly_then + +abbrev loopRest := loopView.then (second graphCode (prodCode natCode loopTailCode)) +abbrev loopCount : Realizes loopCode natCode Loop.count := loopRest.then (first natCode loopTailCode) +private instance poly_loopCount : PolyTime loopCount := by + unfold loopCount + apply poly_then + +abbrev loopState := loopRest.then (second natCode loopTailCode) +abbrev loopScale : Realizes loopCode ratCode (fun a => a.state.scale) := + loopState.then (first ratCode (prodCode ratCode (prodCode matrixCode vectorCode))) +private instance poly_loopScale : PolyTime loopScale := by + unfold loopScale + apply poly_then + +abbrev loopTail := loopState.then (second ratCode (prodCode ratCode (prodCode matrixCode vectorCode))) +abbrev loopQuality : Realizes loopCode ratCode (fun a => a.state.quality) := + loopTail.then (first ratCode (prodCode matrixCode vectorCode)) +private instance poly_loopQuality : PolyTime loopQuality := by + unfold loopQuality + apply poly_then + +abbrev loopArrays := loopTail.then (second ratCode (prodCode matrixCode vectorCode)) +abbrev loopMatrix := loopArrays.then (first matrixCode vectorCode) +abbrev loopCapacity := loopArrays.then (second matrixCode vectorCode) +abbrev loopN := loopGraph.then numVertices +abbrev loopM := loopGraph.then numEdges +abbrev loopStep := loopGraph.then graphStep +abbrev loopBase := loopGraph.then graphBaseline +abbrev loopGain := loopCount.then gainProgram +abbrev loopTarget : Realizes loopCode ratCode (fun a => target a.graph.m a.count a.state.quality (gain a.count)) := + (loopQuality.sub ((loopGain.mul (loopCount.then natToRat)).mul loopStep)).sub + ((constant loopCode ratCode 2).mul loopStep) + +private instance poly_loopTarget : PolyTime loopTarget := by + unfold loopTarget + apply poly_sub + +def Loop.params (a : Loop) : Params := + ⟨a.graph,a.state.scale,baselineQ a.graph.m,stepQ a.graph.m, + target a.graph.m a.count a.state.quality (gain a.count),errorQ a.graph.n a.graph.m,a.state.capacity⟩ +def loopParams : Realizes loopCode paramsCode Loop.params := + (loopGraph.both + ((loopScale.cons (loopBase.cons (loopStep.cons (loopTarget.cons + ((loopGraph.then graphError).then (singleton ratCode)))))).both loopCapacity)).changeOutput + paramsCode Loop.params (fun _ => rfl) +instance poly_loopParams : PolyTime loopParams := by unfold loopParams; apply poly_changeOutput + +def Loop.vector (a : Loop) := search a.graph.G a.state.scale + (target a.graph.m a.count a.state.quality (gain a.count)) a.state.capacity + +def found : Realizes loopCode pointCode (fun a => ⟨a.params,a.vector⟩) := + ((loopParams.both (loopParams.then solvePencil)).then pointParser).congr + (fun a => parsePoint_ofFn a.params a.vector) +instance poly_found : PolyTime found := by unfold found; apply poly_congr + +def updatedMatrix : Realizes loopCode matrixCode + (fun a => matrixData ((update a.graph.G a.count (gain a.count) a.state).matrix)) := + (((((constant loopCode ratCode 1).sub loopStep).both loopMatrix).then matrixScale).both + ((loopStep.both (found.then responsePoint)).then matrixScale)).then matrixAdd |>.congr (by + intro a + change matrixAddData ((matrixData a.state.matrix).map (fun row => row.map (fun x => (1-stepQ a.graph.m)*x)), + (matrixData (qresponse (rawMatrix a.vector))).map (fun row => row.map (fun x => stepQ a.graph.m*x))) = _ + rw [matrixScale_data,matrixScale_data] + exact matrixAdd_data _ _) +instance poly_updatedMatrix : PolyTime updatedMatrix := by unfold updatedMatrix; apply poly_congr + +abbrev LoopEdge := Σ a : Loop, Fin a.graph.m +abbrev loopEdgeCode := finFamilyCode loopCode (fun a : Loop => a.graph.m) +abbrev edgeLoop : Realizes loopEdgeCode loopCode (fun x : LoopEdge => x.1) := familyFirst +abbrev edgeNumber : Realizes loopEdgeCode natCode (fun x : LoopEdge => x.2.val) := familyIndex + +def updatedCapacity : Realizes loopEdgeCode ratCode + (fun x => (update x.1.graph.G x.1.count (gain x.1.count) x.1.state).capacity x.2) := + let z := constant loopEdgeCode ratCode 0 + let f := edgeLoop.then found + ((z.lt (storedU f (fun x => x.2) edgeNumber)).ite + (z.max ((edgeCoord 1 f (fun x => x.2) edgeNumber).sub (edgeLoop.then loopBase))) z).congr + (by intro x; simp only [update,decide_eq_true_eq];rfl) +instance poly_updatedCapacity : PolyTime updatedCapacity := by + have hf : PolyTime (edgeLoop.then found) := by apply poly_then + have he : PolyTime edgeNumber := by infer_instance + unfold updatedCapacity + refine @poly_congr _ _ _ _ _ _ _ _ ?_ + refine @poly_ite _ _ _ _ _ _ _ _ _ _ ?_ ?_ ?_ + · refine @poly_lt _ _ _ _ _ _ ?_ ?_ + · infer_instance + · exact @poly_storedU _ _ _ _ _ _ hf he + · refine @poly_max _ _ _ _ _ _ ?_ ?_ + · infer_instance + · refine @poly_sub _ _ _ _ _ _ ?_ ?_ + · exact @poly_edgeCoord _ _ _ _ _ _ _ hf he + · infer_instance + · infer_instance + +def Loop.updated (a : Loop) : Loop := + ⟨a.graph,a.count,update a.graph.G a.count (gain a.count) a.state⟩ +def updateProgram : Realizes loopCode loopCode Loop.updated := + (loopGraph.both (loopCount.both + ((((constant loopCode ratCode 1).add loopStep).mul loopScale).both + ((loopQuality.sub ((((constant loopCode ratCode 2).mul loopGain).mul + (loopCount.then natToRat)).mul loopStep)).both + (updatedMatrix.both (updatedCapacity.tabulateFin loopM)))))).changeOutput + loopCode Loop.updated (fun _ => rfl) +instance poly_updateProgram : PolyTime updateProgram := by unfold updateProgram; apply poly_changeOutput + +def Loop.next (a : Loop) : Loop := ⟨a.graph,a.count,advance a.graph.G a.count a.state⟩ +def next : Realizes loopCode loopCode Loop.next := + (((loopScale.pow 4).lt (loopCount.then natToRat)).ite updateProgram (identity loopCode)).congr + (by intro a; simp only [Loop.next,advance,decide_eq_true_eq];split <;> rfl) +instance poly_next : PolyTime next := by unfold next; apply poly_congr + +lemma next_iterate (a : Loop) (i : ℕ) : + Loop.next^[i] a=⟨a.graph,a.count,(advance a.graph.G a.count)^[i] a.state⟩ := by + induction i with + | zero => rfl + | succ i ih => + rw [Function.iterate_succ_apply',ih] + change Loop.mk a.graph a.count (advance _ _ _) = Loop.mk a.graph a.count _ + rw [Function.iterate_succ_apply'] + +abbrev extractionInputCode := prodCode graphCode natCode +abbrev extractionGraph := first graphCode natCode +abbrev extractionCount := second graphCode natCode + +def initializeLoop : Realizes extractionInputCode loopCode (fun p => ⟨p.1,p.2,initial p.1.G p.2⟩) := + (extractionGraph.both (extractionCount.both + ((constant extractionInputCode ratCode (1/2)).both + ((extractionCount.then natToRat).both + ((extractionGraph.then laplacian).both + (((constant extractionInputCode ratCode 1).both (extractionGraph.then numEdges)).then + (replicateList ratCode))))))).changeOutput loopCode (fun p => ⟨p.1,p.2,initial p.1.G p.2⟩) + (by intro p; simp only [loopCode,Loop.data,initial,List.ofFn_const]) +instance poly_initializeLoop : PolyTime initializeLoop := by unfold initializeLoop;infer_instance + +def extract : Realizes extractionInputCode loopCode + (fun p => ⟨p.1,p.2,extractState p.1.G p.2⟩) := + ((((extractionGraph.then numEdges).both extractionCount).then clockProgram).both initializeLoop).then + next.iterate |>.congr (fun _ => next_iterate _ _) + +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Schedule.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Schedule.lean new file mode 100644 index 0000000000000000000000000000000000000000..d4a569abcb880190806520536396272e6de9a2a6 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Schedule.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Interior + +namespace OAI + +/-! Continuation schedule. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped MatrixOrder +variable {n m : ℕ} + +lemma nthRoot_le_real_root (d r : ℕ) (hd : 0 < d) : + (Nat.nthRoot d r:ℝ) ≤ (r:ℝ)^(1/(d:ℝ)) := by + rw [one_div,Real.le_rpow_inv_iff_of_pos (Nat.cast_nonneg _) (Nat.cast_nonneg _) + (Nat.cast_pos.mpr hd),Real.rpow_natCast] + exact_mod_cast Nat.pow_nthRoot_le (n:=d) (a:=r) (.inl hd.ne') + +lemma real_root_lt_nthRoot_add (d r : ℕ) (hd : 0 < d) : + (r:ℝ)^(1/(d:ℝ)) < (Nat.nthRoot d r:ℝ)+1 := by + rw [one_div,Real.rpow_inv_lt_iff_of_pos (Nat.cast_nonneg _) (by positivity) + (Nat.cast_pos.mpr hd),Real.rpow_natCast] + exact_mod_cast Nat.lt_pow_nthRoot_add_one hd.ne' r + +lemma nthRoot_pos (d r : ℕ) (hd : 0 < d) (hr : 0 < r) : + 1 ≤ Nat.nthRoot d r := by + rw [Nat.le_nthRoot_iff hd.ne',one_pow] + exact hr + +def gain (r : ℕ) : ℚ := 1/(Nat.nthRoot 8 r:ℚ) + +def blocks (r : ℕ) : ℕ := Nat.nthRoot 16 r + +def blockLength (m : ℕ) : ℕ := 32*(m+1) + +def scheduleLength (m r : ℕ) : ℕ := blockLength m*blocks r + +lemma gain_bounds (r : ℕ) (hr : 0 < r) : + (r:ℝ)^(-1/8:ℝ) ≤ (gain r:ℝ) ∧ (gain r:ℝ) ≤ 2*(r:ℝ)^(-1/8:ℝ) := by + have hroot := nthRoot_le_real_root 8 r (by norm_num) + have hr0 : 0 < (r:ℝ) := Nat.cast_pos.mpr hr + have hu1 : (1:ℝ) ≤ Nat.nthRoot 8 r := by exact_mod_cast nthRoot_pos 8 r (by norm_num) hr + have hup := real_root_lt_nthRoot_add 8 r (by norm_num) + have hp : 0 < (r:ℝ)^(1/8:ℝ) := Real.rpow_pos_of_pos hr0 _ + have he : (r:ℝ)^(-1/8:ℝ)=1/((r:ℝ)^(1/8:ℝ)) := by + simp only [show (-1/8:ℝ)= -(1/8:ℝ) by ring,Real.rpow_neg hr0.le,one_div] + simp only [Nat.cast_ofNat] at hroot hup + rw [he] + have hg : (gain r:ℝ)=1/(Nat.nthRoot 8 r:ℝ) := by simp [gain] + rw [hg] + constructor + · exact one_div_le_one_div_of_le (by linarith only [hu1]) hroot + · have hu0 : 0 < (Nat.nthRoot 8 r:ℝ) := by linarith only [hu1] + apply (div_le_iff₀ hu0).mpr + rw [show 2*(1/((r:ℝ)^(1/8:ℝ)))*(Nat.nthRoot 8 r:ℝ)= + (2*(Nat.nthRoot 8 r:ℝ))/((r:ℝ)^(1/8:ℝ)) by ring] + apply (le_div_iff₀ hp).mpr + linarith only [hu1,hup] + +lemma blockLength_step (m : ℕ) : (blockLength m:ℝ)*continuationStep m=1 := by + unfold blockLength continuationStep continuationBaseline + push_cast + field_simp + +lemma blocks_le_root (r : ℕ) : (blocks r:ℝ) ≤ (r:ℝ)^(1/16:ℝ) := + nthRoot_le_real_root 16 r (by norm_num) + +lemma schedule_loss_bound (r : ℕ) (hr : 0 < r) : + 2*(gain r:ℝ)*(blocks r:ℝ) ≤ 4*(r:ℝ)^(-1/16:ℝ) := by + have hr0 : 0 < (r:ℝ) := Nat.cast_pos.mpr hr + have hg := (gain_bounds r hr).2 + have hU := blocks_le_root r + have hh := mul_le_mul hg hU (Nat.cast_nonneg _) (by positivity : 0 ≤ 2*(r:ℝ)^(-1/8:ℝ)) + have he : (r:ℝ)^(-1/8:ℝ)*(r:ℝ)^(1/16:ℝ)=(r:ℝ)^(-1/16:ℝ) := by + rw [←Real.rpow_add hr0] + congr 1 + norm_num + rw [mul_assoc,he] at hh + linarith only [hh] + +lemma large_blocks (r : ℕ) (hr : 64^16 ≤ r) : 64 ≤ blocks r := by + exact (Nat.le_nthRoot_iff (by norm_num : 16≠0)).mpr hr + +lemma large_gain (r : ℕ) (hr : 64^16 ≤ r) : 3 ≤ (gain r:ℝ)*r := by + have hu2 : 2 ≤ Nat.nthRoot 8 r := (Nat.le_nthRoot_iff (by norm_num : 8≠0)).mpr + (le_trans (by norm_num : 2^8 ≤ 64^16) hr) + have hpow : 3*Nat.nthRoot 8 r ≤ (Nat.nthRoot 8 r)^8 := by + have hh : 3 ≤ (Nat.nthRoot 8 r)^7 := (by norm_num : 3 ≤ 2^7).trans (Nat.pow_le_pow_left hu2 7) + calc + _ ≤ (Nat.nthRoot 8 r)^7*Nat.nthRoot 8 r := Nat.mul_le_mul_right _ hh + _ = _ := (pow_succ _ _).symm + have hh := hpow.trans (Nat.pow_nthRoot_le (n:=8) (a:=r) (by left; norm_num)) + have hreal : (3:ℝ)*Nat.nthRoot 8 r ≤ r := by exact_mod_cast hh + have hp : 0 < (Nat.nthRoot 8 r:ℝ) := by exact_mod_cast (show 0 < Nat.nthRoot 8 r by omega) + simp only [gain,Rat.cast_div,Rat.cast_one,Rat.cast_natCast] + rw [one_div,inv_mul_eq_div,le_div_iff₀ hp] + exact hreal + +lemma large_schedule_loss (r : ℕ) (hr : 64^16 ≤ r) : + 2*(gain r:ℝ)*(blocks r:ℝ) ≤ 1/4 := by + have hr0 : 0 < r := lt_of_lt_of_le (by norm_num : 0 < 64^16) hr + have hU : (64:ℝ) ≤ (blocks r:ℝ) := by exact_mod_cast large_blocks r hr + have hp := hU.trans (blocks_le_root r) + have hi : (r:ℝ)^(-1/16:ℝ) ≤ 1/64 := by + rw [show (-1/16:ℝ)= -(1/16:ℝ) by ring,Real.rpow_neg (Nat.cast_nonneg _),←one_div] + exact one_div_le_one_div_of_le (by norm_num) hp + linarith only [schedule_loss_bound r hr0,hi] + +lemma block_growth (m : ℕ) : 2 ≤ (1+continuationStep m)^(blockLength m) := by + have ht := (continuation_parameters m).2.2.2.1 + have hh := one_add_mul_le_pow (by linarith : -2 ≤ continuationStep m) (blockLength m) + rw [blockLength_step] at hh + norm_num only [one_add_one_eq_two] at hh + exact hh + +lemma fourth_power_le_two_pow (U : ℕ) (hU : 64 ≤ U) : 2*(U+1)^4 ≤ 2^U := by + induction U,hU using Nat.le_induction with + | base => norm_num + | succ U hU ih => + have hstep : (U+2)^4 ≤ 2*(U+1)^4 := by + + have hh : 16*(U+2) ≤ 17*(U+1) := by omega + have hpow := Nat.pow_le_pow_left hh 4 + rw [mul_pow,mul_pow] at hpow + norm_num only [Nat.reducePow] at hpow + omega + rw [pow_succ 2 U] + have he : U+1+1=U+2 := by omega + rw [he] + omega + +lemma schedule_growth (m r : ℕ) (hr : 64^16 ≤ r) : + (r:ℝ)^(1/4:ℝ) ≤ (1+continuationStep m)^(scheduleLength m r)/2 := by + have hU := large_blocks r hr + have hpow := fourth_power_le_two_pow (blocks r) hU + have hg := pow_le_pow_left₀ (by norm_num : (0:ℝ) ≤ 2) (block_growth m) (blocks r) + rw [←pow_mul,←scheduleLength] at hg + have hroot : (r:ℝ)^(1/4:ℝ) ≤ ((blocks r:ℝ)+1)^4 := by + have hh := Nat.lt_pow_nthRoot_add_one (by norm_num : 16≠0) r + have hc : (r:ℝ) ≤ ((blocks r:ℝ)+1)^16 := by exact_mod_cast hh.le + rw [one_div,Real.rpow_inv_le_iff_of_pos (Nat.cast_nonneg _) (by positivity) (by norm_num : (0:ℝ)<4)] + simpa only [Real.rpow_ofNat,←pow_mul,Nat.reduceMul] using hc + have hc : 2*((blocks r:ℝ)+1)^4 ≤ (2:ℝ)^(blocks r) := by exact_mod_cast hpow + linarith only [hg,hroot,hc] + +lemma schedule_length_bound (m r : ℕ) (hr : r ≤ m) : scheduleLength m r ≤ 32*(m+1)^2 := by + have hu : blocks r ≤ r := by + have hh := Nat.pow_nthRoot_le (n:=16) (a:=r) (by left; norm_num) + exact (Nat.le_self_pow (by norm_num : 16≠0) _).trans hh + unfold scheduleLength blockLength + nlinarith only [hu,hr] + +lemma scheduleLength_step (m r : ℕ) : (scheduleLength m r:ℝ)*continuationStep m=blocks r := by + simp only [scheduleLength,Nat.cast_mul] + calc + _ = (blocks r:ℝ)*((blockLength m:ℝ)*continuationStep m) := by ring + _ = _ := by rw [blockLength_step,mul_one] + +lemma cost_le_schedule (m r i : ℕ) (hi : i ≤ scheduleLength m r) : + (i:ℝ)*(2*(gain r:ℝ)*r*continuationStep m) ≤ 2*(gain r:ℝ)*(blocks r:ℝ)*r := by + have hg : 0 ≤ (gain r:ℝ) := by simp only [gain,Rat.cast_div,Rat.cast_one,Rat.cast_natCast]; positivity + have hh := mul_le_mul_of_nonneg_right (show (i:ℝ) ≤ scheduleLength m r by exact_mod_cast hi) + (continuation_parameters m).2.2.2.1 + rw [scheduleLength_step] at hh + have hmul := mul_le_mul_of_nonneg_left hh (by positivity : 0 ≤ 2*(gain r:ℝ)*r) + nlinarith only [hmul] + +lemma running_quality_lower (m r i : ℕ) (hr : 64^16 ≤ r) (hi : i ≤ scheduleLength m r) : + 3*(r:ℝ)/4 ≤ (r:ℝ)-(i:ℝ)*(2*(gain r:ℝ)*r*continuationStep m) := by + have hh := cost_le_schedule m r i hi + have hl := mul_le_mul_of_nonneg_right (large_schedule_loss r hr) (Nat.cast_nonneg (α:=ℝ) r) + linarith only [hh,hl] + +lemma running_quality_loss (m r i : ℕ) (hr : 0 < r) (hi : i ≤ scheduleLength m r) : + (1-4*(r:ℝ)^(-1/16:ℝ))*r ≤ (r:ℝ)-(i:ℝ)*(2*(gain r:ℝ)*r*continuationStep m) := by + have hh := cost_le_schedule m r i hi + have hl := mul_le_mul_of_nonneg_right (schedule_loss_bound r hr) (Nat.cast_nonneg (α:=ℝ) r) + nlinarith only [hh,hl] + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Search.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Search.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6ad89298897917b5948ca334979d1a73266d8ee --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Search.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.PencilCorrectness + +namespace OAI + +/-! Continuation search. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Orientations +open scoped BigOperators +variable {n m : ℕ} + +def sizeQ (n m : ℕ) : ℚ := n+m+2 +def baselineQ (m : ℕ) : ℚ := 1/(m+1) +def stepQ (m : ℕ) : ℚ := baselineQ m/32 +def radiusQ (n m : ℕ) : ℚ := (sizeQ n m)^(-50:ℤ) +def boundQ (n m : ℕ) : ℚ := 6*sizeQ n m*(dimension n m+1) +def errorQ (n m : ℕ) : ℚ := (sizeQ n m)^(-10:ℤ) + +@[simp] lemma cast_sizeQ (n m : ℕ) : (sizeQ n m:ℝ)=graphSize n m := by + simp [sizeQ,graphSize] +@[simp] lemma cast_baselineQ (m : ℕ) : (baselineQ m:ℝ)=continuationBaseline m := by + simp [baselineQ,continuationBaseline] +@[simp] lemma cast_stepQ (m : ℕ) : (stepQ m:ℝ)=continuationStep m := by + simp [stepQ,continuationStep] +@[simp] lemma cast_radiusQ (n m : ℕ) : (radiusQ n m:ℝ)=(graphSize n m)^(-50:ℤ) := by + simp [radiusQ] +@[simp] lemma cast_boundQ (n m : ℕ) : (boundQ n m:ℝ)=6*graphSize n m*(dimension n m+1) := by + simp [boundQ] +@[simp] lemma cast_errorQ (n m : ℕ) : (errorQ n m:ℝ)=(graphSize n m)^(-10:ℤ) := by + simp [errorQ] + +lemma sizeQ_two (n m : ℕ) : 2 ≤ sizeQ n m := by + unfold sizeQ + linarith only [Nat.cast_nonneg (α:=ℚ) n,Nat.cast_nonneg (α:=ℚ) m] +lemma radiusQ_pos (n m : ℕ) : 0 < radiusQ n m := + zpow_pos (by linarith only [sizeQ_two n m]) _ +lemma radiusQ_le_one (n m : ℕ) : radiusQ n m ≤ 1 := by + exact zpow_le_one_of_nonpos₀ (by linarith only [sizeQ_two n m]) (by norm_num) + +lemma boundQ_nonneg (n m : ℕ) : 0 ≤ boundQ n m := by + unfold boundQ sizeQ + positivity + +def search (H : MultiGraph n m) (s qbar : ℚ) (u : Fin m → ℚ) : Fin (dimension n m) → ℚ := + (continuationPencil H s (baselineQ m) (stepQ m) qbar (errorQ n m) u).search + (radiusQ n m) (boundQ n m) 0 + +lemma coordinate_ball (c : StepFree n m) (F : FlowPoint n m) {ρ : ℝ} + {v : EuclideanSpace ℝ (Fin (dimension n m))} + (hv : v ∈ Metric.closedBall (WithLp.toLp 2 (encode c F)) ρ) : + (step v).Close c ρ ∧ (flow v).Close F ρ := by + apply close_step_flow + intro i + have hh := PiLp.norm_apply_le (v-WithLp.toLp 2 (encode c F)) i + have hd : ‖v-WithLp.toLp 2 (encode c F)‖ ≤ ρ := by + simpa only [Metric.mem_closedBall,dist_eq_norm] using hv + simpa only [PiLp.sub_apply,PiLp.toLp_apply,Real.norm_eq_abs] using hh.trans hd + +lemma center_norm (c : StepFree n m) (F : FlowPoint n m) + (hc : c.Bounded (6*graphSize n m)) (hF : F.Bounded (6*graphSize n m)) : + ‖CurrentKS.RationalSDP.realVector (0 : Fin (dimension n m) → ℚ)- + WithLp.toLp 2 (encode c F)‖ ≤ (boundQ n m:ℝ) := by + have hb := encode_bound c F (show 0 ≤ 6*graphSize n m from by positivity [graphSize_pos (n:=n) (m:=m)]) hc hF + have hz : CurrentKS.RationalSDP.realVector (0 : Fin (dimension n m) → ℚ)=0 := by + ext i + simp [CurrentKS.RationalSDP.realVector] + rw [hz,zero_sub,norm_neg,cast_boundQ] + calc + _ ≤ ∑i, |encode c F i| := CurrentKS.RationalSDP.norm_le_sum_abs _ + _ ≤ ∑_i : Fin (dimension n m), 6*graphSize n m := sum_le_sum (fun i _ => hb i) + _ = (dimension n m:ℝ)*(6*graphSize n m) := by simp + _ ≤ _ := by nlinarith only [graphSize_pos (n:=n) (m:=m)] + +theorem search_sound (H : MultiGraph n m) (hn : 2 ≤ n) (hconn : H.Connected univ) + (s qbar : ℚ) (β : ℝ) (u : Fin m → ℚ) + (hs : 0 ≤ (s:ℝ)) (hsP : (s:ℝ) ≤ graphSize n m) + (hq : (graphSize n m)^(-12:ℤ) ≤ (qbar:ℝ)) (hqm : (qbar:ℝ)+β ≤ m) + (hβ : (graphSize n m)⁻¹/32 ≤ β) (hu : ∀e, 0 ≤ (u e:ℝ)) + {z : StepFree n m} + (hz : z ∈ stepFeasible H (s:ℝ) (continuationBaseline m) (continuationStep m) + ((qbar:ℝ)+β+β) (fun e => (u e:ℝ))) : + (rational (search H s qbar u)).real ∈ stepFeasible H (s:ℝ) + (continuationBaseline m) (continuationStep m) ((qbar:ℝ)-4*(errorQ n m:ℝ)) + (fun e => (u e:ℝ)) := by + obtain ⟨c,F,hc,hF,hball⟩ := finite_continuation_inner_cube H hn hconn hs hsP hq hqm hβ + (fun e => (u e:ℝ)) hu hz + let B := continuationPencil H s (baselineQ m) (stepQ m) qbar (errorQ n m) u + have hcb : Metric.closedBall (WithLp.toLp 2 (encode c F)) (radiusQ n m:ℝ) ⊆ B.feasible := by + intro v hv + have hclose := coordinate_ball c F hv + rw [cast_radiusQ] at hclose + have hf := hball (step v) (flow v) hclose.1 hclose.2 + change (B.realEval v).PosSemidef + apply (continuationPencil_psd H s (baselineQ m) (stepQ m) qbar (errorQ n m) u v).mpr + simpa only [cast_baselineQ,cast_stepQ,cast_errorQ] using hf + have hsearch := B.search_accepts (radiusQ n m) (boundQ n m) 0 + (WithLp.toLp 2 (encode c F)) (radiusQ_pos n m) (radiusQ_le_one n m) + (boundQ_nonneg n m) hcb (center_norm c F hc hF) + have hp := (B.witness_none_iff _).mp hsearch + change (B.realEval (fun i => (search H s qbar u i:ℝ))).PosSemidef at hp + have hf := (continuationPencil_psd H s (baselineQ m) (stepQ m) qbar (errorQ n m) u _).mp hp + rw [cast_baselineQ,cast_stepQ] at hf + rw [rational_real] + exact finiteStep_sound H (by omega) (by rw [cast_errorQ]; positivity [graphSize_pos (n:=n) (m:=m)]) hf + +lemma search_fuel_bound (n m : ℕ) : + CurrentKS.RationalSDP.searchFuel (dimension n m) (radiusQ n m) (boundQ n m) ≤ + 2304*(n+m+2)^114+1 := by + let P : ℚ := sizeQ n m + let D : ℚ := dimension n m+1 + have hP : 1 ≤ P := by linarith only [sizeQ_two n m] + have hP0 : 0 < P := by linarith only [hP] + have hD : 0 < D := by dsimp [D]; positivity + have hd : D ≤ 2*P^3 := by + have hh : (dimension n m:ℚ) ≤ P^3 := by + dsimp [P, sizeQ] + exact_mod_cast dimension_bound n m + have hp : 1 ≤ P^3 := one_le_pow₀ hP + dsimp only [D] + linarith only [hh,hp] + have he : 4*(boundQ n m)^2/(CurrentKS.RationalSDP.searchStep (dimension n m) (radiusQ n m))^2 = + 144*P^102*D^4 := by + change 4*(6*P*D)^2/(P^(-50:ℤ)/D)^2=144*P^102*D^4 + rw [_root_.zpow_neg] + field_simp + ring + have hpow := pow_le_pow_left₀ hD.le hd 4 + have hh : 4*(boundQ n m)^2/(CurrentKS.RationalSDP.searchStep (dimension n m) (radiusQ n m))^2 ≤ + (2304*(n+m+2)^114:ℕ) := by + rw [he] + have ht := mul_le_mul_of_nonneg_left hpow (by positivity : (0:ℚ) ≤ 144*P^102) + have hr : 144*P^102*(2*P^3)^4=2304*P^114 := by ring + rw [hr] at ht + simpa only [Nat.cast_mul,Nat.cast_ofNat,Nat.cast_pow,Nat.cast_add,P,sizeQ] using ht + unfold CurrentKS.RationalSDP.searchFuel + exact Nat.succ_le_succ ((Nat.ceil_le).mpr hh) + +lemma search_on_mesh (H : MultiGraph n m) (s qbar : ℚ) (u : Fin m → ℚ) : + ∀i, ∃k : ℤ, search H s qbar u i = + CurrentKS.RationalSDP.searchMesh (dimension n m) (radiusQ n m) (boundQ n m)*k := by + apply CurrentKS.RationalSDP.Pencil.iterate_on_mesh + intro i + exact ⟨0,by simp⟩ + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/SpectralSize.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/SpectralSize.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b471a51155be84bcb1e339472274715807d3171 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/SpectralSize.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.ConeRepresentation + +namespace OAI + +/-! Spectral size. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder + +variable {n m : ℕ} + +lemma laplacian_centered_energy (G : MultiGraph n m) (x : Fin n → ℝ) : + qform (G.laplacian univ) (centering n *ᵥ x)=qform (G.laplacian univ) x := by + rw [←qform_centered,centered_eq (G.laplacian_psd univ).isHermitian (laplacian_ones G)] + +lemma range_le_edge_variation (G : MultiGraph n m) (hc : G.Connected univ) + (x : Fin n → ℝ) (a b : Fin n) + (ha : ∀i, x a ≤ x i) (hb : ∀i, x i ≤ x b) : + x b-x a ≤ ∑e : Fin m, |x (G.left e)-x (G.right e)| := by + have he : G.EdgeConnected 1 := fun S hS hp => card_pos.mpr (hc S hS hp) + have h := G.clamped_variation_lower he x (ha b) ⟨a,le_rfl⟩ ⟨b,le_rfl⟩ + have hcl (i : Fin n) : Geometry.clamp (x a) (x b) (x i)=x i := by + simp only [Geometry.clamp,max_eq_right (ha i),min_eq_right (hb i)] + simpa only [Nat.cast_one,one_mul,hcl] using h + +theorem laplacian_poincare (G : MultiGraph n m) (hn : 0 < n) (hc : G.Connected univ) + (x : Fin n → ℝ) (hx : ∑i, x i=0) : + (∑i, x i^2) ≤ (n : ℝ)*m*qform (G.laplacian univ) x := by + have hne : (univ : Finset (Fin n)).Nonempty := ⟨⟨0,hn⟩,mem_univ _⟩ + obtain ⟨a,_,ha⟩ := exists_min_image univ x hne + obtain ⟨b,_,hb⟩ := exists_max_image univ x hne + have ha' : ∀i, x a ≤ x i := fun i => ha i (mem_univ _) + have hb' : ∀i, x i ≤ x b := fun i => hb i (mem_univ _) + have hna : (0 : ℝ) < n := Nat.cast_pos.mpr hn + have ha0 : x a ≤ 0 := by + have h := sum_le_sum (fun i (_ : i ∈ univ) => ha' i) + simp only [sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul,hx] at h + nlinarith only [h,hna] + have hb0 : 0 ≤ x b := by + have h := sum_le_sum (fun i (_ : i ∈ univ) => hb' i) + simp only [sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul,hx] at h + nlinarith only [h,hna] + have hnorm : (∑i, x i^2) ≤ (n : ℝ)*(x b-x a)^2 := by + have h (i : Fin n) : x i^2 ≤ (x b-x a)^2 := by + have hh : |x i| ≤ x b-x a := abs_le.mpr ⟨by linarith [ha' i],by linarith [hb' i]⟩ + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (x i)) hh 2 + simpa only [sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul] using + sum_le_sum (fun i (_ : i ∈ univ) => h i) + have hvar := range_le_edge_variation G hc x a b ha' hb' + have hsqr : (x b-x a)^2 ≤ (∑e : Fin m, |x (G.left e)-x (G.right e)|)^2 := + pow_le_pow_left₀ (sub_nonneg.mpr (ha' b)) hvar 2 + have hCS := sq_sum_le_card_mul_sum_sq (s := univ) + (f := fun e : Fin m => |x (G.left e)-x (G.right e)|) + simp only [card_univ,Fintype.card_fin,sq_abs,←G.laplacian_qform] at hCS + exact hnorm.trans (by + rw [mul_assoc] + exact mul_le_mul_of_nonneg_left (hsqr.trans hCS) hna.le) + +def graphSize (n m : ℕ) : ℝ := n+m+2 + +lemma graphSize_pos : 0 < graphSize n m := by + dsimp [graphSize] + positivity + +lemma vertex_edge_le_size_cube : (n : ℝ)*m ≤ (graphSize n m)^3 := by + have hn : (0 : ℝ) ≤ n := Nat.cast_nonneg _ + have hm : (0 : ℝ) ≤ m := Nat.cast_nonneg _ + have hnP : (n : ℝ) ≤ graphSize n m := by dsimp [graphSize]; linarith + have hmP : (m : ℝ) ≤ graphSize n m := by dsimp [graphSize]; linarith + have hP : 1 ≤ graphSize n m := by dsimp [graphSize]; linarith + have hsq : (n : ℝ)*m ≤ (graphSize n m)^2 := by + simpa only [pow_two] using mul_le_mul hnP hmP hm (le_trans hn hnP) + exact hsq.trans (by + have h := mul_le_mul_of_nonneg_left hP (sq_nonneg (graphSize n m)) + nlinarith only [h]) + +theorem laplacian_spectral_gap (G : MultiGraph n m) (hn : 0 < n) (hc : G.Connected univ) + (x : Fin n → ℝ) (hx : ∑i, x i=0) : + (graphSize n m)^(-3 : ℤ)*(∑i, x i^2) ≤ qform (G.laplacian univ) x := by + have hbound : (∑i, x i^2) ≤ (graphSize n m)^3*qform (G.laplacian univ) x := + (laplacian_poincare G hn hc x hx).trans + (mul_le_mul_of_nonneg_right vertex_edge_le_size_cube (qform_nonneg (G.laplacian_psd univ) x)) + simp only [_root_.zpow_neg,zpow_ofNat] + rw [inv_mul_le_iff₀ (pow_pos graphSize_pos 3)] + exact hbound + +lemma qform_one_sum_sq (x : Fin n → ℝ) : + qform (1 : Matrix (Fin n) (Fin n) ℝ) x=∑i, x i^2 := by + simp only [qform,one_mulVec,dotProduct,pow_two] + +lemma centering_idempotent (hn : 0 < n) : centering n*centering n=centering n := + mul_centering_of_ones (centering_ones hn) + +lemma qform_centering_sum_sq (hn : 0 < n) (x : Fin n → ℝ) : + qform (centering n) x=∑i, (centering n *ᵥ x) i^2 := by + rw [←qform_one_sum_sq,←qform_centered] + simp only [centered,mul_one,centering_idempotent hn] + +lemma centering_psd (hn : 0 < n) : (centering n).PosSemidef := by + have h := centered_psd (PosSemidef.one : (1 : Matrix (Fin n) (Fin n) ℝ).PosSemidef) + simpa only [centered,mul_one,centering_idempotent hn] using h + +theorem laplacian_lower_order (G : MultiGraph n m) (hn : 0 < n) (hc : G.Connected univ) : + (graphSize n m)^(-3 : ℤ) • centering n ≤ G.laplacian univ := by + apply Matrix.le_iff.mpr + apply PosSemidef.of_dotProduct_mulVec_nonneg + ((G.laplacian_psd univ).isHermitian.sub + ((centering_psd hn).smul (zpow_nonneg graphSize_pos.le _)).isHermitian) + intro x + change 0 ≤ qform (G.laplacian univ-(graphSize n m)^(-3 : ℤ) • centering n) x + rw [qform_sub,qform_smul,qform_centering_sum_sq hn] + have h := laplacian_spectral_gap G hn hc (centering n *ᵥ x) (centering_mulVec_sum hn x) + rw [laplacian_centered_energy G x] at h + linarith only [h] + +lemma qform_outer (b x : Fin n → ℝ) : qform (vecMulVec b b) x=(b ⬝ᵥ x)^2 := by + simp only [qform,vecMulVec_mulVec,dotProduct_smul,IsCentralScalar.op_smul_eq_smul,smul_eq_mul] + rw [dotProduct_comm x b,pow_two] + +lemma qform_outer_le (b x : Fin n → ℝ) : + qform (vecMulVec b b) x ≤ (b ⬝ᵥ b)*(∑i, x i^2) := by + simpa only [qform_outer,dotProduct,pow_two] using sum_mul_sq_le_sq_mul_sq univ b x + +lemma difference_outer_le {a b : Fin n} (hab : a ≠ b) (x : Fin n → ℝ) : + qform (vecMulVec (difference a b) (difference a b)) x ≤ 2*(∑i, x i^2) := by + simpa only [difference_norm_sq hab] using qform_outer_le (difference a b) x + +theorem laplacian_upper_energy (G : MultiGraph n m) (x : Fin n → ℝ) : + qform (G.laplacian univ) x ≤ 2*m*(∑i, x i^2) := by + have h (e : Fin m) : (x (G.left e)-x (G.right e))^2 ≤ 2*(∑i, x i^2) := by + have h := difference_outer_le (G.loopless e) x + rw [qform_outer,dotProduct_comm] at h + change (x ⬝ᵥ G.incidence e)^2 ≤ _ at h + simpa only [dotProduct,G.eval_incidence] using h + rw [G.laplacian_qform] + calc + _ ≤ ∑e : Fin m, 2*(∑i, x i^2) := sum_le_sum (fun e _ => h e) + _ = _ := by simp only [sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul]; ring + +theorem laplacian_upper_order (G : MultiGraph n m) : + G.laplacian univ ≤ (2*m : ℝ) • (1 : Matrix (Fin n) (Fin n) ℝ) := by + apply Matrix.le_iff.mpr + apply PosSemidef.of_dotProduct_mulVec_nonneg + ((PosSemidef.one.smul (by positivity : (0 : ℝ) ≤ 2*m)).isHermitian.sub (G.laplacian_psd univ).isHermitian) + intro x + change 0 ≤ qform ((2*m : ℝ) • (1 : Matrix (Fin n) (Fin n) ℝ)-G.laplacian univ) x + rw [qform_sub,qform_smul,qform_one_sum_sq] + exact sub_nonneg.mpr (laplacian_upper_energy G x) + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Continuation/Start.lean b/lean/OAI/Combinatorics/ThinTrees/Continuation/Start.lean new file mode 100644 index 0000000000000000000000000000000000000000..52e8f12566f5e2b3ed604e53ab1bd968708ab697 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Continuation/Start.lean @@ -0,0 +1,98 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.GraphRealization + +namespace OAI + +/-! Continuation start. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped MatrixOrder +variable {n m : ℕ} + +lemma rankOne_le_laplacian (H : MultiGraph n m) (e : Fin m) : + vecMulVec (H.incidence e) (H.incidence e) ≤ H.laplacian univ := by + apply Finset.single_le_sum _ (mem_univ e) + intro f _ + apply Matrix.nonneg_iff_posSemidef.mpr + simpa only [star_trivial] using posSemidef_vecMulVec_self_star (H.incidence f) + +lemma initial_resistance_le_one (H : MultiGraph n m) (hn : 0 < n) + (hc : H.Connected univ) (e : Fin m) : resistance H (H.laplacian univ) e ≤ 1 := by + have hh := (centered_resistance_order hn (domain_positive H hn hc (laplacian_mem_domain H)) + (incidence_sum H e) (by norm_num : (0:ℝ)<1)).mp + (by simpa only [one_smul] using Matrix.le_iff.mp (rankOne_le_laplacian H e)) + simpa only [one_mul,MetricTests.resistance] using hh + +lemma initial_ramp (H : MultiGraph n m) (hn : 0 < n) (hc : H.Connected univ) + (e : Fin m) : ramp H (1/2) (H.laplacian univ) e=1 := by + have hR := initial_resistance_le_one H hn hc e + have hRp := centered_resistance_pos H hn (domain_positive H hn hc (laplacian_mem_domain H)) e + have hi : 2 ≤ ((1/2)*resistance H (H.laplacian univ) e)⁻¹ := by + rw [←one_div] + apply (le_div_iff₀ (by positivity : 0 < (1/2:ℝ)*resistance H (H.laplacian univ) e)).mpr + linarith only [hR] + unfold ramp cappedParameter + rw [min_eq_left hi] + norm_num + +lemma packing_connected (H : MultiGraph n m) {r : ℕ} (hr : 0 < r) + (hp : H.TreePackable univ r) : H.Connected univ := by + intro S hS hS' + apply card_pos.mp + exact hr.trans_le (H.treePackable_edgeConnected hp S hS hS') + +lemma packing_count_le_edges (H : MultiGraph n m) (hn : 2 ≤ n) {r : ℕ} + (hp : H.TreePackable univ r) : r ≤ m := by + let v : Fin n := ⟨0,by omega⟩ + have hS : ({v}:Finset (Fin n))≠univ := by + intro he + have hh := congrArg Finset.card he + simp only [card_singleton,card_univ,Fintype.card_fin] at hh + omega + exact (H.treePackable_edgeConnected hp {v} (singleton_nonempty v) hS).trans + (by simpa only [Fintype.card_fin] using Finset.card_le_univ (H.cut univ {v})) + +lemma packing_partition_slack (H : MultiGraph n m) (hn : 0 < n) {r : ℕ} + (hp : H.TreePackable univ r) (κ : ℝ) (hκ : 0 ≤ κ) : + ∀p, 0 ≤ slack H.left H.right (fun _ => 1+κ) r p := by + obtain ⟨F,hF⟩ := Orientations.packed_exact_flow H hn hp + have hf := hF.mono (fun e => show (1:ℝ) ≤ 1+κ by linarith only [hκ]) + have hfe : F.Feasible H (fun _ => 1+κ) r 0 := by + refine ⟨hf.1,fun r e => ⟨(hf.2.1 r e).1,(hf.2.1 r e).2.1,(hf.2.1 r e).2.2.le⟩, + fun r v => (hf.2.2.1 r v).le,?_⟩ + simpa only [sub_zero] using hf.2.2.2.ge + intro p + have hh := Orientations.flow_partition_bound H (fun _ => 1+κ) hfe p + simpa only [zero_mul,sub_zero,sub_nonneg,slack] using hh + +end AlgorithmicThinTrees.MetricTests + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped MatrixOrder +variable {n m : ℕ} + +def initial (H : MultiGraph n m) (r : ℕ) : State n m := + ⟨1/2,r,qlap H,fun _ => 1⟩ + +lemma initial_invariant (H : MultiGraph n m) (hn : 0 < n) {r : ℕ} + (hr : 0 < r) (hp : H.TreePackable univ r) : Invariant H (initial H r) := by + have hc := packing_connected H hr hp + have hm : (initial H r).realMatrix=H.laplacian univ := by + ext i j + exact cast_qlap H i j + refine ⟨by norm_num [initial],hm.symm ▸ laplacian_mem_domain H,?_,?_⟩ + · intro e + have hs : ((initial H r).scale:ℝ)=1/2 := by norm_num [initial] + rw [hm,hs,initial_ramp H hn hc e] + norm_num [initial] + · simpa only [initial,Rat.cast_one,Rat.cast_natCast] using + packing_partition_slack H hn hp (continuationBaseline m) (continuation_parameters m).1.le + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Density.lean b/lean/OAI/Combinatorics/ThinTrees/Density.lean new file mode 100644 index 0000000000000000000000000000000000000000..9592c2ef6d8191a31a49fc14f8ac2f1523d60901 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Density.lean @@ -0,0 +1,471 @@ +import OAI.Combinatorics.ThinTrees.Capture + +namespace OAI + +universe uT uE uI uI2 uA uB + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.BagDensity +noncomputable section +open Finset +open scoped Classical +variable {T : Type uT} {E : Type uE} [DecidableEq E] + +omit [DecidableEq E] in +lemma sum_square_bound (F : Finset E) (a : E → ℝ) {c : ℝ} + (hc : ∀e ∈ F, (a e)^2 ≤ c) : (∑e ∈ F, a e)^2 ≤ c*(F.card : ℝ)^2 := by + have hcs := Finset.sum_mul_sq_le_sq_mul_sq F (fun _ => (1:ℝ)) a + have hs : (∑e ∈ F, (a e)^2) ≤ (F.card : ℝ)*c := by simpa using sum_le_sum hc + simp only [one_pow,sum_const,nsmul_eq_mul,mul_one,one_mul] at hcs + have hm := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg F.card : (0:ℝ) ≤ _) + nlinarith + +omit [DecidableEq E] in +lemma local_density (O F : Finset E) (a d : E → ℝ) {α γ c₁ c₂ : ℝ} + (hF : F ⊆ O) (hFn : F.Nonempty) (hα : 0 < α) (hγ : 0 < γ) + (hd : ∀e ∈ O, 0 ≤ d e) (hmax : ∀e ∈ F, (a e)^2 ≤ 4*c₁) + (hmin : ∀e ∈ F, c₂/4 ≤ d e) + (hbad : α*(O.card : ℝ)*(∑e ∈ O, d e) ≤ (∑e ∈ O, a e)^2) + (hdom : γ*(∑e ∈ O, a e)^2 ≤ (∑e ∈ F, a e)^2) : + α*γ*(O.card : ℝ)*c₂ ≤ 16*c₁*F.card := by + have hFc : (0:ℝ) < F.card := by exact_mod_cast card_pos.mpr hFn + have hOc : (0:ℝ) ≤ O.card := Nat.cast_nonneg _ + have hsum : (F.card : ℝ)*(c₂/4) ≤ ∑e ∈ O, d e := by + calc + _ = ∑_e ∈ F, c₂/4 := by simp + _ ≤ ∑e ∈ F, d e := sum_le_sum hmin + _ ≤ ∑e ∈ O, d e := sum_le_sum_of_subset_of_nonneg hF (fun e he _ => hd e he) + have hh1 := mul_le_mul_of_nonneg_left hsum (show 0 ≤ γ*α*(O.card : ℝ) by positivity) + have hh2 := mul_le_mul_of_nonneg_left hbad hγ.le + have hu := sum_square_bound F a hmax + apply (mul_le_mul_iff_right₀ hFc).mp + nlinarith + +lemma family_density (Ts : Finset T) (O F : T → Finset E) (a d : E → ℝ) + {α γ c₁ c₂ : ℝ} (hα : 0 < α) (hγ : 0 < γ) (hc : 0 ≤ c₁) + (hF : ∀t ∈ Ts, F t ⊆ O t) (hFn : ∀t ∈ Ts, (F t).Nonempty) + (hd : ∀t ∈ Ts, ∀e ∈ O t, 0 ≤ d e) + (hmax : ∀t ∈ Ts, ∀e ∈ F t, (a e)^2 ≤ 4*c₁) + (hmin : ∀t ∈ Ts, ∀e ∈ F t, c₂/4 ≤ d e) + (hbad : ∀t ∈ Ts, α*((O t).card : ℝ)*(∑e ∈ O t, d e) ≤ (∑e ∈ O t, a e)^2) + (hdom : ∀t ∈ Ts, γ*(∑e ∈ O t, a e)^2 ≤ (∑e ∈ F t, a e)^2) + (hmult : (∑t ∈ Ts, (F t).card) ≤ 2*(Ts.biUnion F).card) : + (α*γ/32)*(∑t ∈ Ts, ((O t).card : ℝ))*c₂ ≤ c₁*(Ts.biUnion F).card ∧ + (∑t ∈ Ts, (∑e ∈ F t, a e)^2/((O t).card : ℝ)) ≤ 8*c₁*(Ts.biUnion F).card := by + have hcast : (∑t ∈ Ts, ((F t).card : ℝ)) ≤ 2*(Ts.biUnion F).card := by exact_mod_cast hmult + constructor + · have hh := sum_le_sum (fun t ht => local_density (O t) (F t) a d + (hF t ht) (hFn t ht) hα hγ (hd t ht) (hmax t ht) (hmin t ht) (hbad t ht) (hdom t ht)) + simp only [←mul_sum,←sum_mul] at hh + have hm := mul_le_mul_of_nonneg_left hcast (show 0 ≤ 16*c₁ by positivity) + nlinarith + · have hu : ∀t ∈ Ts, (∑e ∈ F t, a e)^2/((O t).card : ℝ) ≤ 4*c₁*(F t).card := by + intro t ht + have hm : (0:ℝ) < (O t).card := by exact_mod_cast card_pos.mpr ((hFn t ht).mono (hF t ht)) + have hfm : ((F t).card : ℝ) ≤ (O t).card := by exact_mod_cast card_le_card (hF t ht) + have hs := sum_square_bound (F t) a (hmax t ht) + apply (div_le_iff₀ hm).mpr + have hh := mul_le_mul_of_nonneg_left hfm (show 0 ≤ 4*c₁*(F t).card by positivity) + nlinarith + have hs := sum_le_sum hu + rw [←mul_sum] at hs + have hh := mul_le_mul_of_nonneg_left hcast (show 0 ≤ 4*c₁ by positivity) + nlinarith + +end +end StrongThinTree.BagDensity + +namespace StrongThinTree.CaptureNumeric +noncomputable section + +lemma thresholds {s a ε C N N' c₁ c₂ b δ R : ℝ} + (hs : 0 < s) (ha : s ≤ a) (ha1 : a ≤ 1) + (he : 0 < ε) (he1 : ε ≤ 1/2) (hC : 0 < C) + (hN : 0 < N) (hN' : 0 < N') (hNle : N' ≤ N) + (hc₁ : 0 < c₁) (hc₂ : 0 < c₂) (_hb : 0 < b) (hδ : 0 < δ) + (hscale : a*N' = s*N) (hdensity : s*N*c₂ ≤ c₁*N') + (hcard : a*N'/C ≤ b) (hcard₂ : b ≤ 2*N') + (hmass : b*δ = a^ε*c₁*N'/C) + (hsmall : s^ε ≤ 1/(1728*C)) (hR : R ≤ 8*c₁*N') : + 864*s^(1+2*ε)*N ≤ b ∧ + 1728*s^(1+2*ε)*c₂*N ≤ δ*b ∧ + s*c₁ ≤ δ ∧ max δ (2*c₂) ≤ 2*c₁/s ∧ + s^ε*R/(6912*C) ≤ δ*b/864 := by + have ha0 : 0 < a := hs.trans_le ha + have hs1 : s ≤ 1 := ha.trans ha1 + have hsε : 0 < s^ε := Real.rpow_pos_of_pos hs _ + have haε : 0 < a^ε := Real.rpow_pos_of_pos ha0 _ + have hsε1 : s^ε ≤ 1 := Real.rpow_le_one hs.le hs1 he.le + have haε1 : a^ε ≤ 1 := Real.rpow_le_one ha0.le ha1 he.le + have hsale : s^ε ≤ a^ε := Real.rpow_le_rpow hs.le ha he.le + have hsmall' := (le_div_iff₀ (show 0 < 1728*C by positivity)).mp hsmall + have hη : s^(1+2*ε) = s*(s^ε)^2 := by + rw [Real.rpow_add hs,Real.rpow_one] + congr 1 + rw [mul_comm (2:ℝ) ε,Real.rpow_mul hs.le,Real.rpow_two] + have hfirst : 864*s^(1+2*ε)*N ≤ b := by + have hc := (div_le_iff₀ hC).mp hcard + rw [hscale] at hc + rw [hη] + have hh : 864*(s^ε)^2*C ≤ 1 := by nlinarith only [hsmall',mul_nonneg (sub_nonneg.mpr hsε1) (by positivity : 0 ≤ 1728*C*s^ε)] + have hmul := mul_le_mul_of_nonneg_right hh (show 0 ≤ s*N by positivity) + apply (mul_le_mul_iff_right₀ hC).mp + nlinarith only [hmul,hc] + have hsecond : 1728*s^(1+2*ε)*c₂*N ≤ δ*b := by + have hh := mul_le_mul_of_nonneg_right hdensity (show 0 ≤ 1728*(s^ε)^2*C by positivity) + have hh' : 1728*(s^ε)^2*C ≤ a^ε := by + have hh := mul_le_mul_of_nonneg_right hsmall' hsε.le + nlinarith only [hh,hsale] + have hh'' := mul_le_mul_of_nonneg_right hh' (show 0 ≤ c₁*N' by positivity) + have hm := (eq_div_iff hC.ne').mp hmass + rw [hη] + apply (mul_le_mul_iff_right₀ hC).mp + nlinarith only [hh,hh'',hm] + have hlower : s*c₁ ≤ δ := by + have hpow := Real.rpow_le_rpow_of_exponent_ge hs hs1 (show ε ≤ 1-ε by linarith) + have hex : s = s^ε*s^(1-ε) := by + rw [←Real.rpow_add hs] + have heq : ε+(1-ε) = 1 := by ring + rw [heq,Real.rpow_one] + have hh : 2*C*s ≤ s^ε := by + have hc : 2*C*s^(1-ε) ≤ 1 := by nlinarith only [hsmall',mul_le_mul_of_nonneg_left hpow hC.le] + have hm := mul_le_mul_of_nonneg_left hc hsε.le + nlinarith only [hm,congrArg (fun x : ℝ => 2*C*x) hex] + have hh' := mul_le_mul_of_nonneg_right hh (show 0 ≤ c₁*N' by positivity) + have hh'' := mul_le_mul_of_nonneg_right hsale (show 0 ≤ c₁*N' by positivity) + have hm := (eq_div_iff hC.ne').mp hmass + have hbc := mul_le_mul_of_nonneg_right hcard₂ hδ.le + have hbcC := mul_le_mul_of_nonneg_right hbc hC.le + apply (mul_le_mul_iff_right₀ (show 0 < 2*C*N' by positivity)).mp + nlinarith only [hh',hh'',hm,hbcC] + have hupperδ : δ ≤ c₁/s := by + have hh := mul_le_mul_of_nonneg_right hcard hδ.le + have hm := (eq_div_iff hC.ne').mp hmass + have hc := (div_le_iff₀ hC).mp hcard + have hhC := mul_le_mul_of_nonneg_right hh hC.le + have hhA := mul_le_mul_of_nonneg_right haε1 (show 0 ≤ c₁*N' by positivity) + have hhS := mul_le_mul_of_nonneg_right ha (show 0 ≤ N'*δ by positivity) + apply (le_div_iff₀ hs).mpr + apply (mul_le_mul_iff_right₀ hN').mp + have hcan : (a*N'/C)*δ*C = a*N'*δ := by field_simp + rw [hcan] at hhC + nlinarith only [hhC,hm,hhA,hhS] + have hupperc : c₂ ≤ c₁/s := by + have hh := mul_le_mul_of_nonneg_left hNle (show 0 ≤ s*c₂ by positivity) + apply (le_div_iff₀ hs).mpr + apply (mul_le_mul_iff_right₀ hN').mp + nlinarith only [hh,hdensity] + refine ⟨hfirst,hsecond,hlower,max_le ?_ ?_,?_⟩ + · have hh : 0 ≤ c₁/s := by positivity + rw [mul_div_assoc] + linarith only [hh,hupperδ] + · have hh := mul_le_mul_of_nonneg_left hupperc (show (0:ℝ) ≤ 2 by norm_num) + simpa only [mul_div_assoc] using hh + · have hh := mul_le_mul_of_nonneg_left hR hsε.le + have hh' := mul_le_mul_of_nonneg_right hsale (show 0 ≤ 8*c₁*N' by positivity) + have hm := (eq_div_iff hC.ne').mp hmass + apply (div_le_iff₀ (show 0 < 6912*C by positivity)).mpr + nlinarith only [hh,hh',hm] + +end +end StrongThinTree.CaptureNumeric + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry StrongThinTree.Geometry.RadialShell +open scoped Classical +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +lemma density_spectral_input {I : Type uI} [Fintype I] + (a d : I → ℝ) {c₁ c₂ α : ℝ} + (hc₁ : 0 ≤ c₁) (hα : 0 ≤ α) (ha : ∀i, 0 ≤ a i) + (hmin : ∀i, c₁ ≤ (a i)^2) (hd : ∀i, d i ≤ c₂) + (hscale : α*c₂ ≤ c₁) : + α*(Fintype.card I : ℝ)*(∑i, d i) ≤ (∑i, a i)^2 := by + have hN : (0:ℝ) ≤ Fintype.card I := Nat.cast_nonneg _ + have hsum : (Fintype.card I : ℝ)*Real.sqrt c₁ ≤ ∑i, a i := by + simpa only [sum_const,nsmul_eq_mul,card_univ] using + sum_le_sum (fun i (_ : i ∈ univ) => Real.sqrt_le_iff.mpr ⟨ha i,hmin i⟩) + have hsum0 : 0 ≤ ∑i, a i := sum_nonneg (fun i _ => ha i) + have hsum2 : c₁*(Fintype.card I : ℝ)^2 ≤ (∑i, a i)^2 := by + have hh := (sq_le_sq₀ (mul_nonneg hN (Real.sqrt_nonneg _)) hsum0).mpr hsum + rw [mul_pow,Real.sq_sqrt hc₁] at hh + nlinarith only [hh] + have hdsum : (∑i, d i) ≤ (Fintype.card I : ℝ)*c₂ := by + simpa only [sum_const,nsmul_eq_mul,card_univ] using sum_le_sum (fun i (_ : i ∈ univ) => hd i) + have h1 := mul_le_mul_of_nonneg_left hdsum (mul_nonneg hα hN) + have h2 := mul_le_mul_of_nonneg_right hscale (sq_nonneg (Fintype.card I : ℝ)) + nlinarith only [h1,h2,hsum2] + +lemma homogeneous_family (T : Finset (Finset (Fin n))) (F : Finset (Fin n) → Finset (Fin m)) + (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hTne : T.Nonempty) (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hF : ∀t ∈ T, F t ⊆ H.parentBoundary G t) (hFn : ∀t ∈ T, (F t).Nonempty) + {α γ ε c₁ c₂ : ℝ} (hα : 0 < α) (hγ : 0 < γ) + (he : 0 < ε) (he1 : ε < 1/3) (hc₁ : 0 < c₁) (hc₂ : 0 < c₂) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ l1dist (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hmin : ∀t ∈ T, ∀e ∈ F t, c₁ ≤ ((Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hmax : ∀t ∈ T, ∀e ∈ F t, ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ 4*c₁) + (hdmin : ∀t ∈ T, ∀e ∈ F t, c₂/4 ≤ l1dist (X (G.left e)) (X (G.right e))) + (hdmax : ∀t ∈ T, ∀e ∈ F t, l1dist (X (G.left e)) (X (G.right e)) ≤ c₂) + (hbad : ∀t ∈ T, α*((H.parentBoundary G t).card : ℝ)* + (∑e ∈ H.parentBoundary G t, l1dist (X (G.left e)) (X (G.right e))) ≤ + (∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hdom : ∀t ∈ T, γ*(∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ + (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hsmall : (α*γ/32)^ε ≤ 1/(1728*(1024/ε^2))) : + let s := α*γ/32 + let R := ∑t ∈ T, (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((H.parentBoundary G t).card : ℝ) + (∃δ Δ : ℝ, ∃B : CompactFamily X δ Δ, + s*c₁ ≤ δ ∧ Δ ≤ 12*c₁/s ∧ s^ε*R/(6912*(1024/ε^2)) ≤ δ*(∑D ∈ B.bags, (D.card : ℝ))) ∨ + (∃B : AssignedFamily H G X (s^(1+2*ε)), B.owners ⊆ T ∧ + s*c₁ ≤ B.radius ∧ B.radius ≤ 12*c₁/s ∧ s^ε*R/(6912*(1024/ε^2)) ≤ B.mass) := by + let a : Fin m → ℝ := fun e => (Y (G.left e)-Y (G.right e)).ofLp e + let d : Fin m → ℝ := fun e => l1dist (X (G.left e)) (X (G.right e)) + let E := T.biUnion F + let N : ℝ := ∑t ∈ T, ((H.parentBoundary G t).card : ℝ) + let N' : ℝ := E.card + let s := α*γ/32 + let C : ℝ := 1024/ε^2 + let R := ∑t ∈ T, (∑e ∈ F t, a e)^2/((H.parentBoundary G t).card : ℝ) + have hs : 0 < s := by dsimp [s]; positivity + have hC : 0 < C := by dsimp [C]; positivity + have hEn : E.Nonempty := by + obtain ⟨t,ht⟩ := hTne + obtain ⟨e,he⟩ := hFn t ht + exact ⟨e,mem_biUnion.mpr ⟨t,ht,he⟩⟩ + have hN' : 0 < N' := by dsimp [N']; exact_mod_cast card_pos.mpr hEn + have hboundary : ∀t ∈ T, 0 < (H.parentBoundary G t).card := + fun t ht => card_pos.mpr ((hFn t ht).mono (hF t ht)) + have hN : 0 < N := by + apply sum_pos (fun t ht => ?_) hTne + exact_mod_cast hboundary t ht + have hNle : N' ≤ N := by + have h1 : E.card ≤ ∑t ∈ T, (F t).card := card_biUnion_le + have h2 : (∑t ∈ T, (F t).card) ≤ ∑t ∈ T, (H.parentBoundary G t).card := + sum_le_sum (fun t ht => card_le_card (hF t ht)) + dsimp [N',N] + exact_mod_cast h1.trans h2 + have hd0 : ∀e, 0 ≤ d e := fun e => l1dist_nonneg _ _ + obtain ⟨hdensity,hR⟩ := StrongThinTree.BagDensity.family_density T (H.parentBoundary G) F a d + hα hγ hc₁.le hF hFn (fun t ht e he => hd0 e) hmax hdmin hbad hdom + (H.subset_boundary_multiplicity G T hT hroot F hF) + change s*N*c₂ ≤ c₁*N' at hdensity + change R ≤ 8*c₁*N' at hR + let specα := s*N/N' + have ha0 : 0 < specα := div_pos (mul_pos hs hN) hN' + have hscale : specα*N' = s*N := div_mul_cancel₀ _ hN'.ne' + have has : s ≤ specα := by + apply (le_div_iff₀ hN').mpr + exact mul_le_mul_of_nonneg_left hNle hs.le + have had : specα*c₂ ≤ c₁ := by + change (s*N/N')*c₂ ≤ c₁ + rw [div_mul_eq_mul_div] + exact (div_le_iff₀ hN').mpr hdensity + have hminE : ∀e ∈ E, c₁ ≤ (a e)^2 := by + intro e he + obtain ⟨t,ht,he⟩ := mem_biUnion.mp he + exact hmin t ht e he + have hmaxE : ∀e ∈ E, d e ≤ c₂ := by + intro e he + obtain ⟨t,ht,he⟩ := mem_biUnion.mp he + exact hdmax t ht e he + let u : E → Fin n := fun e => G.left e.val + let v : E → Fin n := fun e => G.right e.val + have hIE : Fintype.card E = E.card := Fintype.card_coe E + have hI : 0 < Fintype.card E := by rw [hIE]; exact card_pos.mpr hEn + have hbnd : specα*(Fintype.card E : ℝ)*(∑e : E, ‖Y (u e)-Y (v e)‖^2) ≤ + (∑e : E, (Y (u e)-Y (v e)).ofLp e.val)^2 := + density_spectral_input (fun e : E => a e.val) (fun e : E => ‖Y (u e)-Y (v e)‖^2) + hc₁.le ha0.le (fun e => hpositive e.val) (fun e => hminE e.val e.property) + (fun e => (hcontract (u e) (v e)).trans (hmaxE e.val e.property)) had + obtain ⟨ha1,S,δ,hδ,hSE,hS2,hSc,hmass,hsep⟩ := normalized_small_balls X Y u v + (fun e : E => e.val) Subtype.val_injective hI ha0 he he1 hc₁ + (fun e => ⟨hpositive e.val,hminE e.val e.property⟩) hbnd hcontract + have hS : S.Nonempty := card_pos.mp (by omega) + have hSc0 : (0:ℝ) < S.card := by exact_mod_cast (by omega : 0 < S.card) + have hcard : specα*N'/C ≤ (S.card : ℝ) := by + apply (div_le_iff₀ hC).mpr + dsimp [C] + rw [←mul_div_assoc] + apply (le_div_iff₀ (sq_pos_of_pos he)).mpr + rw [hIE] at hSc + change ε^2*specα*N' ≤ _ at hSc + nlinarith only [hSc] + have hcard₂ : (S.card : ℝ) ≤ 2*N' := by + have hh := card_le_card hSE + have h1 := card_union_le (univ.image u) (univ.image v) + have h2 := card_image_le (f := u) (s := univ) + have h3 := card_image_le (f := v) (s := univ) + simp only [card_univ,hIE] at h2 h3 + have hSc : S.card ≤ 2*E.card := by omega + dsimp [N']; exact_mod_cast hSc + rw [hIE] at hmass + change (S.card : ℝ)*δ = specα^ε*c₁*N'/C at hmass + obtain ⟨hηδ,hηc,hlower,hupper,hgain⟩ := StrongThinTree.CaptureNumeric.thresholds + hs has ha1 he (by linarith : ε ≤ 1/2) hC hN hN' hNle hc₁ hc₂ hSc0 hδ + hscale hdensity hcard hcard₂ hmass hsmall hR + let P := T.biUnion (fun t => t.filter (fun w => ∃e ∈ F t, G.left e=w ∨ G.right e=w)) + have hP : ∀w ∈ P, ∃t ∈ T, w ∈ t ∧ ∃e ∈ H.parentBoundary G t, + (G.left e=w ∨ G.right e=w) ∧ l1dist (X (G.left e)) (X (G.right e)) ≤ c₂ := by + intro w hw + obtain ⟨t,ht,hw⟩ := mem_biUnion.mp hw + obtain ⟨hwt,e,he,hew⟩ := mem_filter.mp hw + exact ⟨t,ht,hwt,e,hF t ht he,hew,hdmax t ht e he⟩ + have hEnd : ∀e ∈ E, ∃w ∈ P, (G.left e=w ∨ G.right e=w) := by + intro e he + obtain ⟨t,ht,het⟩ := mem_biUnion.mp he + have hc := (mem_filter.mp (hF t ht het)).2 + rcases hc with hc | hc + · exact ⟨G.left e,mem_biUnion.mpr ⟨t,ht,mem_filter.mpr ⟨hc.1,e,het,Or.inl rfl⟩⟩,Or.inl rfl⟩ + · exact ⟨G.right e,mem_biUnion.mpr ⟨t,ht,mem_filter.mpr ⟨hc.1,e,het,Or.inr rfl⟩⟩,Or.inr rfl⟩ + have hcover : ∀w ∈ S, ∃p ∈ P, l1dist (X w) (X p) ≤ c₂ := by + intro w hw + rcases mem_union.mp (hSE hw) with hw | hw + · obtain ⟨e,he,rfl⟩ := mem_image.mp hw + obtain ⟨p,hp,hp'⟩ := hEnd e.val e.property + refine ⟨p,hp,?_⟩ + rcases hp' with hp' | hp' + · simpa [u,hp',l1dist_self] using hc₂.le + · simpa [u,d,hp'] using hmaxE e.val e.property + · obtain ⟨e,he,rfl⟩ := mem_image.mp hw + obtain ⟨p,hp,hp'⟩ := hEnd e.val e.property + refine ⟨p,hp,?_⟩ + rcases hp' with hp' | hp' + · simpa [v,d,hp',l1dist_comm] using hmaxE e.val e.property + · simpa [v,hp',l1dist_self] using hc₂.le + have hNcast : ∑t ∈ T, ((H.parentBoundary G t).card : ℝ) = N := rfl + have hη : 0 ≤ s^(1+2*ε) := (Real.rpow_pos_of_pos hs _).le + obtain hcomp | hass := capture_small_balls T S P hS hT hroot hboundary hδ hc₂ hη + hsep hcover hP hηδ hηc + · obtain ⟨B,hB⟩ := hcomp + refine Or.inl ⟨δ,6*max δ (2*c₂),B,hlower,?_,hgain.trans hB⟩ + change 6*max δ (2*c₂) ≤ 12*c₁/s + calc + _ ≤ 6*(2*c₁/s) := mul_le_mul_of_nonneg_left hupper (by norm_num) + _ = 12*c₁/s := by ring + · obtain ⟨B,hBD,hBT,hB⟩ := hass + refine Or.inr ⟨B,hBT,?_,?_,hgain.trans hB⟩ + · rw [hBD] + exact hlower.trans (le_max_left _ _) + · rw [hBD] + have hh : 0 ≤ c₁/s := by positivity + calc + max δ (2*c₂) ≤ 2*c₁/s := hupper + _ ≤ 12*c₁/s := by rw [mul_div_assoc,mul_div_assoc]; linarith only [hh] + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.ScaleSelection +noncomputable section +open Finset +open scoped Classical + +lemma integer_dyadic {x : ℝ} (hx : 0 < x) : + 2^(⌊Real.logb 2 x⌋ : ℝ) ≤ x ∧ x < 2*2^(⌊Real.logb 2 x⌋ : ℝ) := by + have h1 := (Real.le_logb_iff_rpow_le (by norm_num) hx).mp (Int.floor_le (Real.logb 2 x)) + have h2 := (Real.logb_lt_iff_lt_rpow (by norm_num) hx).mp (Int.lt_floor_add_one (Real.logb 2 x)) + rw [Real.rpow_add (by norm_num),Real.rpow_one] at h2 + constructor + · exact h1 + · nlinarith only [h2] + +lemma integer_dyadic_mono {x y : ℝ} (hx : 0 < x) (hxy : x ≤ y) : + ⌊Real.logb 2 x⌋ ≤ ⌊Real.logb 2 y⌋ := + Int.floor_mono (Real.logb_le_logb_of_le (by norm_num) hx hxy) + +lemma integer_scale_offset {x y K : ℝ} {L : ℕ} + (hx : 0 < x) (hxy : x ≤ y) (hK : y ≤ K*x) + (hL : Real.logb 2 K+1 < L) : + 0 ≤ ⌊Real.logb 2 y⌋-⌊Real.logb 2 x⌋ ∧ + ⌊Real.logb 2 y⌋-⌊Real.logb 2 x⌋ < L := by + have hy : 0 < y := hx.trans_le hxy + have hK0 : 0 < K := by nlinarith only [hK,hy,hx] + have hlogs : Real.logb 2 y ≤ Real.logb 2 K+Real.logb 2 x := by + rw [←Real.logb_mul hK0.ne' hx.ne'] + exact Real.logb_le_logb_of_le (by norm_num) hy hK + constructor + · exact sub_nonneg.mpr (integer_dyadic_mono hx hxy) + · have h1 := Int.floor_le (Real.logb 2 y) + have h2 := Int.lt_floor_add_one (Real.logb 2 x) + have hh : ((⌊Real.logb 2 y⌋-⌊Real.logb 2 x⌋ : ℤ) : ℝ) < L := by + push_cast + linarith only [h1,h2,hlogs,hL] + exact_mod_cast hh + +lemma select_fibers {I : Type uI2} {A : Type uA} {B : Type uB} [DecidableEq I] [DecidableEq A] [Fintype B] + [DecidableEq B] [Nonempty B] + (T : Finset I) (a : I → A) (b : I → B) (w : I → ℝ) : + ∃choice : A → B, + (∑i ∈ T, w i)/(Fintype.card B : ℝ) ≤ + ∑i ∈ T.filter (fun i => b i = choice (a i)), w i := by + have hB : (0:ℝ) < Fintype.card B := by exact_mod_cast Fintype.card_pos (α := B) + have hex : ∀x : A, ∃y : B, + (∑i ∈ T.filter (fun i => a i=x), w i)/(Fintype.card B : ℝ) ≤ + ∑i ∈ (T.filter (fun i => a i=x)).filter (fun i => b i=y), w i := by + intro x + obtain ⟨y,hy,hgain⟩ := exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum + (s := T.filter (fun i => a i=x)) (t := univ) (f := b) (w := w) + (fun _ _ => mem_univ _) univ_nonempty + (b := (∑i ∈ T.filter (fun i => a i=x), w i)/(Fintype.card B : ℝ)) (by + simp only [card_univ,nsmul_eq_mul] + exact (mul_div_cancel₀ _ hB.ne').le) + exact ⟨y,hgain⟩ + choose choice hchoice using hex + refine ⟨choice,?_⟩ + have hs := sum_le_sum (s := T.image a) (fun x hx => hchoice x) + rw [←sum_div] at hs + have hleft : (∑x ∈ T.image a, ∑i ∈ T.filter (fun i => a i=x), w i) = ∑i ∈ T, w i := by + exact sum_fiberwise_of_maps_to (fun i hi => mem_image_of_mem a hi) w + rw [hleft] at hs + have hright : (∑x ∈ T.image a, ∑i ∈ (T.filter (fun i => a i=x)).filter + (fun i => b i=choice x), w i) = ∑i ∈ T.filter (fun i => b i=choice (a i)), w i := by + simp only [sum_filter] + rw [sum_comm] + apply sum_congr rfl + intro i hi + rw [sum_eq_single (a i)] + · simp + · intro x hx hne + simp [Ne.symm hne] + · intro hnot + exact (hnot (mem_image_of_mem a hi)).elim + rw [hright] at hs + exact hs + +lemma residue_spacing {H : ℕ} (_hH : 0 < H) {n n' : ℤ} + (hlt : n' < n) (hmod : n'%H = n%H) : n' ≤ n-H := by + have hd : (H:ℤ) ∣ n-n' := Int.ModEq.dvd hmod + have hh := Int.le_of_dvd (sub_pos.mpr hlt) hd + omega + +lemma separated_scales {s ρ : ℝ} {H : ℕ} {n n' : ℤ} + (hs : 0 < s) (hρ : 0 < ρ) + (hH : Real.logb 2 (24/(ρ*s^2)) < H) + (hgap : n' ≤ n-H) : 24*2^(n':ℝ)/s < ρ*s*2^(n:ℝ) := by + have hpow : 24/(ρ*s^2) < (2:ℝ)^(H:ℝ) := + (Real.logb_lt_iff_lt_rpow (by norm_num) (by positivity)).mp hH + have hgapR : (n':ℝ)+(H:ℝ) ≤ (n:ℝ) := by exact_mod_cast (by omega : n'+H ≤ n) + have hle : (2:ℝ)^(n':ℝ)*(2:ℝ)^(H:ℝ) ≤ (2:ℝ)^(n:ℝ) := by + rw [←Real.rpow_add (by norm_num)] + exact Real.rpow_le_rpow_of_exponent_le (by norm_num) hgapR + have hp := Real.rpow_pos_of_pos (by norm_num : (0:ℝ) < 2) (n':ℝ) + have hh := (div_lt_iff₀ (show 0 < ρ*s^2 by positivity)).mp hpow + have hm := mul_lt_mul_of_pos_left hh hp + have hm' := mul_le_mul_of_nonneg_right hle (show 0 ≤ ρ*s^2 by positivity) + apply (div_lt_iff₀ hs).mpr + nlinarith only [hm,hm'] + +end +end StrongThinTree.ScaleSelection + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/DeterminantCalculus.lean b/lean/OAI/Combinatorics/ThinTrees/DeterminantCalculus.lean new file mode 100644 index 0000000000000000000000000000000000000000..d68e9e98fba228177996de0d842ead2231d72e77 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/DeterminantCalculus.lean @@ -0,0 +1,133 @@ +import OAI.Combinatorics.ThinTrees.Barrier + +namespace OAI + +universe uI uD uR + +section + +noncomputable section +open Matrix Polynomial Finset +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [CommRing R] + +def basePencil (M : Matrix D D R) (A : I → Matrix D D R) : MvPolynomial I R := + (M.map MvPolynomial.C + ∑i, (MvPolynomial.X i : MvPolynomial I R) • (A i).map MvPolynomial.C).det + +def zeroSub (j : I) : MvPolynomial I R →+* MvPolynomial I R := + MvPolynomial.eval₂Hom MvPolynomial.C (Function.update MvPolynomial.X j 0) + +def zeroDiff (j : I) (p : MvPolynomial I R) : MvPolynomial I R := + zeroSub j (p-MvPolynomial.pderiv j p) + +def view (j : I) : MvPolynomial I R →+* (MvPolynomial I R)[X] := + MvPolynomial.eval₂Hom (Polynomial.C.comp MvPolynomial.C) + (Function.update (fun i => Polynomial.C (MvPolynomial.X i)) j Polynomial.X) + +omit [Fintype I] [Fintype D] [DecidableEq D] in +@[simp] lemma view_C (j : I) (r : R) : view j (MvPolynomial.C r)=C (MvPolynomial.C r) := by + simp [view] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +@[simp] lemma view_X (j i : I) : view (R := R) j (MvPolynomial.X i)= + if i=j then X else C (MvPolynomial.X i) := by + simp [view,Function.update_apply] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +@[simp] lemma zeroSub_C (j : I) (r : R) : zeroSub j (MvPolynomial.C r)=MvPolynomial.C r := by + simp [zeroSub] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +@[simp] lemma zeroSub_X (j i : I) : zeroSub (R := R) j (MvPolynomial.X i)= + if i=j then 0 else MvPolynomial.X i := by + simp [zeroSub,Function.update_apply] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma view_derivative (j : I) (p : MvPolynomial I R) : + (view j p).derivative=view j (MvPolynomial.pderiv j p) := by + induction p using MvPolynomial.induction_on with + | C a => simp + | add p q hp hq => simp [hp,hq] + | mul_X p i hp => + rw [map_mul,Polynomial.derivative_mul,MvPolynomial.pderiv_mul,map_add,map_mul,map_mul,hp] + by_cases hi : i=j + · subst i; simp + · simp [hi] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma view_zero (j : I) (p : MvPolynomial I R) : + (view j p).eval 0=zeroSub j p := by + induction p using MvPolynomial.induction_on with + | C a => simp + | add p q hp hq => simp [hp,hq] + | mul_X p i hp => + by_cases hi : i=j + · subst i; simp + · simp [hi,hp] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma zeroDiff_coeff (j : I) (p : MvPolynomial I R) : + zeroDiff j p=(view j p).coeff 0-(view j p).coeff 1 := by + rw [zeroDiff,map_sub,←view_zero,←view_zero,←view_derivative] + simp [←coeff_zero_eq_eval_zero,coeff_derivative] + +omit [Fintype D] [DecidableEq D] in +lemma view_affine_entry (j : I) (c : R) (a : I → R) : + view j (MvPolynomial.C c+∑i, MvPolynomial.X i*MvPolynomial.C (a i))= + C (MvPolynomial.C c+∑i ∈ Finset.univ.erase j, MvPolynomial.X i*MvPolynomial.C (a i))+ + X*C (MvPolynomial.C (a j)) := by + simp only [map_add,map_sum,map_mul,view_C,view_X] + rw [←Finset.add_sum_erase Finset.univ + (fun i => (if i=j then X else C (MvPolynomial.X i))*C (MvPolynomial.C (a i))) (Finset.mem_univ j)] + simp only [ite_true] + have hh : ∑i ∈ Finset.univ.erase j, + (if i=j then X else C (MvPolynomial.X i))*C (MvPolynomial.C (a i))= + ∑i ∈ Finset.univ.erase j, C (MvPolynomial.X i)*C (MvPolynomial.C (a i)) := by + apply Finset.sum_congr rfl + intro i hi + rw [ite_eq_right (Finset.mem_erase.mp hi).1] + rw [hh] + abel + +omit [Fintype D] [DecidableEq D] in +lemma view_baseMatrix (j : I) (M : Matrix D D R) (A : I → Matrix D D R) : + (M.map MvPolynomial.C + ∑i, (MvPolynomial.X i : MvPolynomial I R) • + (A i).map MvPolynomial.C).map (view j)= + (M.map MvPolynomial.C + ∑i ∈ Finset.univ.erase j, + (MvPolynomial.X i : MvPolynomial I R) • (A i).map MvPolynomial.C).map Polynomial.C + + (X : (MvPolynomial I R)[X]) • ((A j).map MvPolynomial.C).map Polynomial.C := by + apply Matrix.ext + intro a b + simp only [Matrix.map_apply,Matrix.add_apply,Matrix.sum_apply,Matrix.smul_apply,smul_eq_mul] + exact view_affine_entry j (M a b) (fun i => A i a b) + +lemma view_basePencil (j : I) (M : Matrix D D R) (A : I → Matrix D D R) : + view j (basePencil M A)= + ((M.map MvPolynomial.C + ∑i ∈ Finset.univ.erase j, + (MvPolynomial.X i : MvPolynomial I R) • (A i).map MvPolynomial.C).map Polynomial.C + + (X : (MvPolynomial I R)[X]) • ((A j).map MvPolynomial.C).map Polynomial.C).det := by + unfold basePencil + rw [(view j).map_det] + exact congrArg Matrix.det (view_baseMatrix j M A) + +lemma zeroDiff_basePencil (j : I) (M : Matrix D D R) (A : I → Matrix D D R) : + zeroDiff j (basePencil M A)= + (M.map MvPolynomial.C + ∑i ∈ Finset.univ.erase j, + (MvPolynomial.X i : MvPolynomial I R) • (A i).map MvPolynomial.C).det- + detLinear (M.map MvPolynomial.C + ∑i ∈ Finset.univ.erase j, + (MvPolynomial.X i : MvPolynomial I R) • (A i).map MvPolynomial.C) ((A j).map MvPolynomial.C) := by + rw [zeroDiff_coeff,view_basePencil,det_linear_pencil_coeff_one] + congr 1 + rw [coeff_zero_eq_eval_zero,show Polynomial.eval (0 : MvPolynomial I R)=Polynomial.evalRingHom 0 from rfl, + (Polynomial.evalRingHom (0 : MvPolynomial I R)).map_det] + congr 1 + apply Matrix.ext + intro a b + simp + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Duality.lean b/lean/OAI/Combinatorics/ThinTrees/Duality.lean new file mode 100644 index 0000000000000000000000000000000000000000..323e0d3482d9b04a19c3e94201bfc0165a290650 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Duality.lean @@ -0,0 +1,906 @@ +import OAI.Combinatorics.ThinTrees.Truncation + +namespace OAI + +universe uE uI uJ uV uI2 uI3 uV2 uW uJ2 uV3 uE2 uT uJ3 uH uI4 + +section + +namespace StrongThinTree.Duality +noncomputable section +open Finset +open scoped Classical +variable {E : Type uE} {I : Type uI} [AddCommGroup E] [Module ℝ E] [Fintype I] + +def strictUpperImage (S : Set E) (F : I → E → ℝ) : Set (I → ℝ) := + {v | ∃x ∈ S, ∀i, F i x < v i} + +omit [AddCommGroup E] [Module ℝ E] in +lemma strictUpperImage_isOpen (S : Set E) (F : I → E → ℝ) : + IsOpen (strictUpperImage S F) := by + have he : strictUpperImage S F = ⋃x ∈ S, ⋂i, {v : I → ℝ | F i x < v i} := by + ext v; simp [strictUpperImage] + rw [he] + exact isOpen_iUnion (fun x => isOpen_iUnion (fun _ => isOpen_iInter_of_finite + (fun i => isOpen_lt continuous_const (continuous_apply i)))) + +omit [Fintype I] in +lemma strictUpperImage_convex (S : Set E) (F : I → E → ℝ) + (hS : Convex ℝ S) (hF : ∀i, ConvexOn ℝ S (F i)) : + Convex ℝ (strictUpperImage S F) := by + intro u hu v hv a b ha hb hab + obtain ⟨x,hx,hxu⟩ := hu + obtain ⟨y,hy,hyv⟩ := hv + refine ⟨a • x+b • y,hS hx hy ha hb hab,?_⟩ + intro i + have hf := (hF i).2 hx hy ha hb hab + change F i (a • x+b • y) < a*u i+b*v i + change F i (a • x+b • y) ≤ a*F i x+b*F i y at hf + have hlt : a*F i x+b*F i y < a*u i+b*v i := by + by_cases ha0 : a=0 + · have hb1 : b=1 := by linarith + simpa [ha0,hb1] using hyv i + · have hapos : 0 < a := lt_of_le_of_ne ha (Ne.symm ha0) + exact add_lt_add_of_lt_of_le (mul_lt_mul_of_pos_left (hxu i) hapos) + (mul_le_mul_of_nonneg_left (hyv i).le hb) + exact hf.trans_lt hlt + +lemma functional_coordinates (l : (I → ℝ) →L[ℝ] ℝ) (v : I → ℝ) : + l v = ∑i, l (Pi.single i 1)*v i := by + have he : v=∑i, v i • Pi.single i (1:ℝ) := by + funext j + simp [Pi.single_apply] + calc + l v = l (∑i, v i • Pi.single i (1:ℝ)) := congrArg l he + _ = ∑i, l (Pi.single i 1)*v i := by + rw [map_sum] + apply sum_congr rfl + intro i _ + rw [map_smul] + simp only [smul_eq_mul,mul_comm] + +lemma convex_alternative (S : Set E) (hS : Convex ℝ S) (hne : S.Nonempty) + (F : I → E → ℝ) (hF : ∀i, ConvexOn ℝ S (F i)) + (hinfeasible : ¬∃x ∈ S, ∀i, F i x < 0) : + ∃w : I → ℝ, (∀i, 0 ≤ w i) ∧ (∑i, w i)=1 ∧ + ∀x ∈ S, 0 ≤ ∑i, w i*F i x := by + have hzero : (0:I → ℝ) ∉ strictUpperImage S F := hinfeasible + obtain ⟨l,hl⟩ := geometric_hahn_banach_point_open (strictUpperImage_convex S F hS hF) + (strictUpperImage_isOpen S F) hzero + simp only [map_zero] at hl + let w : I → ℝ := fun i => l (Pi.single i 1) + obtain ⟨x₀,hx₀⟩ := hne + let v₀ : I → ℝ := fun i => F i x₀+1 + have hv₀ : v₀ ∈ strictUpperImage S F := ⟨x₀,hx₀,fun i => by dsimp [v₀]; linarith⟩ + have hlv : 0 < l v₀ := hl v₀ hv₀ + have hw : ∀i, 0 ≤ w i := by + intro i + by_contra hh + have hi : w i < 0 := lt_of_not_ge hh + let t := (l v₀+1)/(-w i) + have ht : 0 ≤ t := div_nonneg (by linarith only [hlv]) (neg_pos.mpr hi).le + have hv : v₀+t • Pi.single i 1 ∈ strictUpperImage S F := by + refine ⟨x₀,hx₀,?_⟩ + intro j + change F j x₀ < v₀ j+t*((Pi.single i (1:ℝ) : I → ℝ) j) + have hj : 0 ≤ ((Pi.single i (1:ℝ) : I → ℝ) j) := by simp [Pi.single_apply]; split_ifs <;> norm_num + exact (show F j x₀ < v₀ j by dsimp [v₀]; linarith).trans_le (le_add_of_nonneg_right (mul_nonneg ht hj)) + have hh := hl _ hv + rw [map_add,map_smul] at hh + change 0 < l v₀+t*w i at hh + have hid : t*w i=-(l v₀+1) := by dsimp [t]; field_simp [ne_of_lt hi] + linarith only [hh,hid] + let W := ∑i, w i + have hW : 0 < W := by + have hWnon : 0 ≤ W := sum_nonneg (fun i _ => hw i) + by_contra hh + have hW0 : W=0 := le_antisymm (le_of_not_gt hh) hWnon + have hw0 : ∀i, w i=0 := fun i => (sum_eq_zero_iff_of_nonneg (fun i _ => hw i)).mp hW0 i (mem_univ i) + rw [functional_coordinates] at hlv + have hz : ∑i, l (Pi.single i 1)*v₀ i=0 := by + change (∑i, w i*v₀ i)=0 + simp [hw0] + linarith only [hlv,hz] + have hbound : ∀x ∈ S, 0 ≤ ∑i, w i*F i x := by + intro x hx + apply le_of_forall_pos_lt_add + intro ε hε + have heps : 0 < ε/W := div_pos hε hW + have hv : (fun i => F i x+ε/W) ∈ strictUpperImage S F := + ⟨x,hx,fun i => lt_add_of_pos_right _ heps⟩ + have hh := hl _ hv + rw [functional_coordinates] at hh + change 0 < ∑i, w i*(F i x+ε/W) at hh + simp only [mul_add,sum_add_distrib,←sum_mul] at hh + have heq : W*(ε/W)=ε := by field_simp + change 0 < (∑i, w i*F i x)+W*(ε/W) at hh + rwa [heq] at hh + refine ⟨fun i => w i/W,fun i => div_nonneg (hw i) hW.le,?_,?_⟩ + · rw [←sum_div] + exact div_self hW.ne' + · intro x hx + simp only [div_mul_eq_mul_div,←sum_div] + exact div_nonneg (hbound x hx) hW.le +variable {J : Type uJ} [Fintype J] + +lemma slater_certificate (S : Set E) (hS : Convex ℝ S) + (f : I → E → ℝ) (g : J → E → ℝ) + (hf : ∀i, ConvexOn ℝ S (f i)) (hg : ∀j, ConvexOn ℝ S (g j)) + (hslater : ∃x ∈ S, ∀j, g j x < 0) (K : ℝ) + (hinfeasible : ¬∃x ∈ S, (∀i, f i x < K) ∧ (∀j, g j x < 0)) : + ∃lam : I → ℝ, ∃y : J → ℝ, (∀i, 0 ≤ lam i) ∧ (∑i, lam i)=1 ∧ + (∀j, 0 ≤ y j) ∧ ∀x ∈ S, K ≤ (∑i, lam i*f i x)+(∑j, y j*g j x) := by + let F : I ⊕ J → E → ℝ := Sum.elim (fun i x => f i x-K) g + have hF : ∀i, ConvexOn ℝ S (F i) := by + intro i + cases i with + | inl i => + refine ⟨hS,?_⟩ + intro x hx y hy a b ha hb hab + have hh := (hf i).2 hx hy ha hb hab + change f i (a • x+b • y)-K ≤ a*(f i x-K)+b*(f i y-K) + change f i (a • x+b • y) ≤ a*f i x+b*f i y at hh + nlinarith only [hh,congrArg (fun z : ℝ => z*K) hab] + | inr j => exact hg j + have hnone : ¬∃x ∈ S, ∀i, F i x < 0 := by + intro ⟨x,hx,h⟩ + apply hinfeasible + exact ⟨x,hx,fun i => sub_neg.mp (h (Sum.inl i)),fun j => h (Sum.inr j)⟩ + obtain ⟨x₀,hx₀,hg₀⟩ := hslater + obtain ⟨w,hw,hws,hwb⟩ := convex_alternative S hS ⟨x₀,hx₀⟩ F hF hnone + let p := ∑i, w (Sum.inl i) + have hpnon : 0 ≤ p := sum_nonneg (fun i _ => hw (Sum.inl i)) + have hsum : p+(∑j, w (Sum.inr j))=1 := by simpa only [p,Fintype.sum_sum_type] using hws + have hp : 0 < p := by + by_contra hh + have hp0 : p=0 := le_antisymm (le_of_not_gt hh) hpnon + have hwi0 : ∀i, w (Sum.inl i)=0 := fun i => + (sum_eq_zero_iff_of_nonneg (fun i _ => hw (Sum.inl i))).mp hp0 i (mem_univ i) + have hjpos : 0 < ∑j, w (Sum.inr j) := by linarith only [hsum,hp0] + obtain ⟨j,hj,hjpos⟩ := (sum_pos_iff_of_nonneg (fun j _ => hw (Sum.inr j))).mp hjpos + have hgneg : (∑j, w (Sum.inr j)*g j x₀) < 0 := by + apply sum_neg' (fun j _ => mul_nonpos_of_nonneg_of_nonpos (hw (Sum.inr j)) (hg₀ j).le) + exact ⟨j,mem_univ j,mul_neg_of_pos_of_neg hjpos (hg₀ j)⟩ + have hh := hwb x₀ hx₀ + simp only [Fintype.sum_sum_type,F,Sum.elim_inl,Sum.elim_inr,hwi0,zero_mul,sum_const_zero,zero_add] at hh + linarith only [hh,hgneg] + refine ⟨fun i => w (Sum.inl i)/p,fun j => w (Sum.inr j)/p, + fun i => div_nonneg (hw (Sum.inl i)) hp.le,?_, + fun j => div_nonneg (hw (Sum.inr j)) hp.le,?_⟩ + · rw [←sum_div] + exact div_self hp.ne' + · intro x hx + have hh := hwb x hx + simp only [Fintype.sum_sum_type,F,Sum.elim_inl,Sum.elim_inr,mul_sub,sum_sub_distrib,←sum_mul] at hh + simp only [div_mul_eq_mul_div,←sum_div,←add_div] + apply (le_div_iff₀ hp).mpr + change 0 ≤ (∑i, w (Sum.inl i)*f i x)-p*K+(∑j, w (Sum.inr j)*g j x) at hh + linarith only [hh] + +lemma strict_feasible_of_dual_bound (S : Set E) (hS : Convex ℝ S) + (f : I → E → ℝ) (g : J → E → ℝ) + (hf : ∀i, ConvexOn ℝ S (f i)) (hg : ∀j, ConvexOn ℝ S (g j)) + (hslater : ∃x ∈ S, ∀j, g j x < 0) (K : ℝ) + (hdual : ∀lam : I → ℝ, ∀y : J → ℝ, (∀i, 0 ≤ lam i) → (∑i, lam i)=1 → + (∀j, 0 ≤ y j) → ∃x ∈ S, (∑i, lam i*f i x)+(∑j, y j*g j x) < K) : + ∃x ∈ S, (∀i, f i x < K) ∧ (∀j, g j x < 0) := by + by_contra hh + obtain ⟨lam,y,hlam,hlams,hy,hbound⟩ := slater_certificate S hS f g hf hg hslater K hh + obtain ⟨x,hx,hval⟩ := hdual lam y hlam hlams hy + exact (not_lt_of_ge (hbound x hx)) hval +end +end StrongThinTree.Duality + +namespace StrongThinTree.MatrixDual +noncomputable section +open Matrix Finset +open scoped Classical MatrixOrder +variable {V : Type uV} [Fintype V] [DecidableEq V] + +omit [DecidableEq V] in +lemma quadratic_symm {D : Matrix V V ℝ} (hD : D.IsHermitian) (x y : V → ℝ) : + x ⬝ᵥ (D *ᵥ y) = y ⬝ᵥ (D *ᵥ x) := by + have hsym : D.transpose=D := isHermitian_iff_isSymm.mp hD + rw [dotProduct_mulVec,dotProduct_comm,←vecMul_transpose,hsym] + +lemma solve {D : Matrix V V ℝ} (hD : D.PosDef) (b : V → ℝ) : + D *ᵥ (D⁻¹ *ᵥ b)=b := by + rw [mulVec_mulVec,mul_nonsing_inv D ((isUnit_iff_isUnit_det D).mp hD.isUnit),one_mulVec] + +lemma inverse_quadratic_variational {D : Matrix V V ℝ} (hD : D.PosDef) (b x : V → ℝ) : + 2*(b ⬝ᵥ x)-x ⬝ᵥ (D *ᵥ x) ≤ b ⬝ᵥ (D⁻¹ *ᵥ b) := by + let y := D⁻¹ *ᵥ b + have hDy : D *ᵥ y=b := solve hD b + have hs : y ⬝ᵥ (D *ᵥ x)=x ⬝ᵥ b := by rw [quadratic_symm hD.isHermitian,hDy] + have hh := hD.posSemidef.dotProduct_mulVec_nonneg (x-y) + simp only [star_trivial,mulVec_sub,sub_dotProduct,dotProduct_sub,hDy,hs, + dotProduct_comm x b,dotProduct_comm y b] at hh + change 2*(b ⬝ᵥ x)-x ⬝ᵥ (D *ᵥ x) ≤ b ⬝ᵥ y + linarith only [hh] + +lemma inverse_quadratic_attained {D : Matrix V V ℝ} (hD : D.PosDef) (b : V → ℝ) : + b ⬝ᵥ (D⁻¹ *ᵥ b)=2*(b ⬝ᵥ (D⁻¹ *ᵥ b))-(D⁻¹ *ᵥ b) ⬝ᵥ (D *ᵥ (D⁻¹ *ᵥ b)) := by + rw [solve hD b,dotProduct_comm (D⁻¹ *ᵥ b) b] + ring + +omit [Fintype V] [DecidableEq V] in +lemma posDef_convex : Convex ℝ {D : Matrix V V ℝ | D.PosDef} := by + intro X hX Y hY a b ha hb hab + by_cases ha0 : a=0 + · have hb1 : b=1 := by linarith only [hab,ha0] + simpa [ha0,hb1] using hY + · exact (hX.smul (lt_of_le_of_ne ha (Ne.symm ha0))).add_posSemidef (hY.posSemidef.smul hb) + +lemma inverse_quadratic_convex (v : V → ℝ) : + ConvexOn ℝ {D : Matrix V V ℝ | D.PosDef} (fun D => v ⬝ᵥ (D⁻¹ *ᵥ v)) := by + refine ⟨posDef_convex,?_⟩ + intro X hX Y hY a b ha hb hab + let D := a • X+b • Y + have hD : D.PosDef := posDef_convex hX hY ha hb hab + let z := D⁻¹ *ᵥ v + have hXv := inverse_quadratic_variational hX v z + have hYv := inverse_quadratic_variational hY v z + have hDv := inverse_quadratic_attained hD v + have hf : 2*(v ⬝ᵥ z)-z ⬝ᵥ (D *ᵥ z) = + a*(2*(v ⬝ᵥ z)-z ⬝ᵥ (X *ᵥ z))+b*(2*(v ⬝ᵥ z)-z ⬝ᵥ (Y *ᵥ z)) := by + dsimp [D] + simp only [add_mulVec,smul_mulVec,dotProduct_add,dotProduct_smul,smul_eq_mul] + nlinarith only [congrArg (fun t : ℝ => t*(v ⬝ᵥ z)) hab] + change v ⬝ᵥ (D⁻¹ *ᵥ v) ≤ a*(v ⬝ᵥ (X⁻¹ *ᵥ v))+b*(v ⬝ᵥ (Y⁻¹ *ᵥ v)) + rw [hDv] + change 2*(v ⬝ᵥ z)-z ⬝ᵥ (D *ᵥ z) ≤ _ + rw [hf] + exact add_le_add (mul_le_mul_of_nonneg_left hXv ha) (mul_le_mul_of_nonneg_left hYv hb) + +omit [DecidableEq V] in +lemma cut_quadratic_convex (v : V → ℝ) (c : ℝ) : + ConvexOn ℝ {D : Matrix V V ℝ | D.PosDef} (fun D => v ⬝ᵥ (D *ᵥ v)-c) := by + refine ⟨posDef_convex,?_⟩ + intro X hX Y hY a b ha hb hab + simp only [add_mulVec,smul_mulVec,dotProduct_add,dotProduct_smul,smul_eq_mul] + nlinarith only [congrArg (fun t : ℝ => t*c) hab] + +lemma posDef_sqrt {A : Matrix V V ℝ} (hA : A.PosDef) : (CFC.sqrt A).PosDef := by + apply (CFC.sqrt_nonneg A).posSemidef.posDef_iff_isUnit.mpr + apply (isUnit_pow_iff (by decide : 2 ≠ 0)).mp + rw [CFC.sq_sqrt A hA.posSemidef.nonneg] + exact hA.isUnit + +lemma congr_posDef {A S : Matrix V V ℝ} (hA : A.PosDef) + (hSH : S.IsHermitian) (hSU : IsUnit S) : (S*A*S).PosDef := by + simpa only [hSH.eq] using hA.conjTranspose_mul_mul_same + (mulVec_injective_iff_isUnit.mpr hSU) + +lemma trace_objective_attained {A Z : Matrix V V ℝ} (hA : A.PosDef) (hZ : Z.PosDef) : + ∃ D : Matrix V V ℝ, D.PosDef ∧ + (A*D⁻¹).trace+(Z*D).trace = + 2*(CFC.sqrt (CFC.sqrt Z*A*CFC.sqrt Z)).trace := by + let S := CFC.sqrt Z + have hS : S.PosDef := posDef_sqrt hZ + have hSS : S*S=Z := CFC.sqrt_mul_sqrt_self Z hZ.posSemidef.nonneg + have hSi : S*S⁻¹=1 := mul_nonsing_inv _ ((isUnit_iff_isUnit_det _).mp hS.isUnit) + have hiS : S⁻¹*S=1 := nonsing_inv_mul _ ((isUnit_iff_isUnit_det _).mp hS.isUnit) + let C := S*A*S + have hC : C.PosDef := congr_posDef hA hS.isHermitian hS.isUnit + let T := CFC.sqrt C + have hT : T.PosDef := posDef_sqrt hC + have hTT : T*T=C := CFC.sqrt_mul_sqrt_self C hC.posSemidef.nonneg + have hTi : T*T⁻¹=1 := mul_nonsing_inv _ ((isUnit_iff_isUnit_det _).mp hT.isUnit) + let D := S⁻¹*T*S⁻¹ + have hD : D.PosDef := congr_posDef hT hS.inv.isHermitian hS.inv.isUnit + have hDinv : D⁻¹=S*T⁻¹*S := by + apply inv_eq_right_inv + dsimp [D] + simp only [mul_assoc,←mul_assoc S⁻¹ S,hiS,←mul_assoc T T⁻¹,hTi,one_mul] + have hAeq : A=S⁻¹*(T*T)*S⁻¹ := by + rw [hTT] + dsimp [C] + simp only [mul_assoc,hSi,mul_one,←mul_assoc S⁻¹ S,hiS,one_mul] + have htA : (A*D⁻¹).trace=T.trace := by + rw [hDinv,hAeq] + have heq : S⁻¹*(T*T)*S⁻¹*(S*T⁻¹*S)=S⁻¹*T*S := by + simp only [mul_assoc,←mul_assoc S⁻¹ S,hiS,one_mul] + simp only [←mul_assoc T T⁻¹,hTi,one_mul] + rw [heq,Matrix.trace_mul_cycle,hSi,one_mul] + have htZ : (Z*D).trace=T.trace := by + rw [←hSS] + dsimp [D] + have heq : S*S*(S⁻¹*T*S⁻¹)=S*T*S⁻¹ := by + simp only [mul_assoc,←mul_assoc S S⁻¹,hSi,one_mul] + rw [heq,Matrix.trace_mul_cycle,hiS,one_mul] + refine ⟨D,hD,?_⟩ + change (A*D⁻¹).trace+(Z*D).trace=2*T.trace + rw [htA,htZ] + ring + +open Filter Topology +open scoped Matrix.Norms.L2Operator + +lemma sqrt_tendsto {I : Type uI2} {l : Filter I} {A : Matrix V V ℝ} + (hA : A.PosSemidef) {f : I → Matrix V V ℝ} + (hf : Tendsto f l (𝓝 A)) (hfp : ∀ᶠ i in l, (f i).PosSemidef) : + Tendsto (fun i => CFC.sqrt (f i)) l (𝓝 (CFC.sqrt A)) := by + apply (CFC.continuousOn_sqrt A hA.nonneg).tendsto.comp + exact tendsto_nhdsWithin_iff.mpr ⟨hf,hfp.mono (fun i hi => hi.nonneg)⟩ + +lemma traceRoot_tendsto {I : Type uI3} {l : Filter I} {A Z : Matrix V V ℝ} + (hA : A.PosSemidef) (hZ : Z.PosSemidef) {f g : I → Matrix V V ℝ} + (hf : Tendsto f l (𝓝 A)) (hg : Tendsto g l (𝓝 Z)) + (hfp : ∀ᶠ i in l, (f i).PosSemidef) (hgp : ∀ᶠ i in l, (g i).PosSemidef) : + Tendsto (fun i => 2*(CFC.sqrt (CFC.sqrt (g i)*f i*CFC.sqrt (g i))).trace) l + (𝓝 (2*(CFC.sqrt (CFC.sqrt Z*A*CFC.sqrt Z)).trace)) := by + have hs := sqrt_tendsto hZ hg hgp + have hp : (CFC.sqrt Z*A*CFC.sqrt Z).PosSemidef := by + simpa only [(CFC.sqrt_nonneg Z).posSemidef.isHermitian.eq] using + hA.conjTranspose_mul_mul_same (CFC.sqrt Z) + have hps : ∀ᶠ i in l, (CFC.sqrt (g i)*f i*CFC.sqrt (g i)).PosSemidef := by + filter_upwards [hfp] with i hi + simpa only [(CFC.sqrt_nonneg (g i)).posSemidef.isHermitian.eq] using + hi.conjTranspose_mul_mul_same (CFC.sqrt (g i)) + have ht := sqrt_tendsto hp ((hs.mul hf).mul hs) hps + have htr := (continuous_id.matrix_trace.tendsto _).comp ht + exact htr.const_mul 2 + +lemma trace_objective_approx {A Z : Matrix V V ℝ} (hA : A.PosSemidef) (hZ : Z.PosSemidef) + {K : ℝ} (hK : 2*(CFC.sqrt (CFC.sqrt Z*A*CFC.sqrt Z)).trace < K) : + ∃ D : Matrix V V ℝ, D.PosDef ∧ (A*D⁻¹).trace+(Z*D).trace < K := by + let f : ℝ → Matrix V V ℝ := fun t => A+t•1 + let g : ℝ → Matrix V V ℝ := fun t => Z+t•1 + have hf : Tendsto f (𝓝[>] 0) (𝓝 A) := by + have hc : Continuous f := by dsimp [f]; fun_prop + simpa [f] using (hc.continuousAt (x := 0)).tendsto.mono_left nhdsWithin_le_nhds + have hg : Tendsto g (𝓝[>] 0) (𝓝 Z) := by + have hc : Continuous g := by dsimp [g]; fun_prop + simpa [g] using (hc.continuousAt (x := 0)).tendsto.mono_left nhdsWithin_le_nhds + have hpos : ∀ᶠ t : ℝ in 𝓝[>] 0, 0 (hfp t ht).posSemidef)) + (hpos.mono (fun t ht => (hgp t ht).posSemidef)) + obtain ⟨t,ht,htK⟩ := (hpos.and (hv.eventually_lt_const hK)).exists + obtain ⟨D,hD,heq⟩ := trace_objective_attained (hfp t ht) (hgp t ht) + have hterms : (A*D⁻¹).trace+(Z*D).trace ≤ ((f t)*D⁻¹).trace+((g t)*D).trace := by + dsimp [f,g] + simp only [add_mul,smul_mul_assoc,one_mul,trace_add,trace_smul,smul_eq_mul] + nlinarith only [mul_nonneg ht.le hD.inv.posSemidef.trace_nonneg, + mul_nonneg ht.le hD.posSemidef.trace_nonneg] + exact ⟨D,hD,hterms.trans_lt (heq.trans_lt htK)⟩ +end +end StrongThinTree.MatrixDual + +namespace StrongThinTree.Polar +noncomputable section +open Matrix Finset +open scoped Classical MatrixOrder Matrix.Norms.L2Operator +variable {V : Type uV2} {W : Type uW} [Fintype V] [DecidableEq V] [Fintype W] [DecidableEq W] + +lemma sqrt_eq_real_cfc {A : Matrix V V ℝ} (hA : A.PosSemidef) : + CFC.sqrt A=cfc Real.sqrt A := by + rw [CFC.sqrt_eq_cfc,cfc_nnreal_eq_real _ _ hA.nonneg] + unfold Real.sqrt + rfl + +lemma trace_sqrt_roots {A : Matrix V V ℝ} (hA : A.PosSemidef) : + (CFC.sqrt A).trace=(A.charpoly.roots.map Real.sqrt).sum := by + rw [sqrt_eq_real_cfc hA,hA.isHermitian.cfc_eq] + unfold Matrix.IsHermitian.cfc + rw [Unitary.conjStarAlgAut_apply,Matrix.trace_mul_cycle] + simp only [Unitary.coe_star_mul_self,one_mul,trace_diagonal] + rw [hA.isHermitian.roots_charpoly_eq_eigenvalues,Multiset.map_map] + rfl + +lemma trace_sqrt_mul_comm (A : Matrix V W ℝ) (B : Matrix W V ℝ) + (hAB : (A*B).PosSemidef) (hBA : (B*A).PosSemidef) : + (CFC.sqrt (A*B)).trace=(CFC.sqrt (B*A)).trace := by + rw [trace_sqrt_roots hAB,trace_sqrt_roots hBA] + have heq := congrArg (fun p : Polynomial ℝ => (p.roots.map Real.sqrt).sum) + (Matrix.charpoly_mul_comm' A B) + rw [Polynomial.roots_mul (mul_ne_zero (pow_ne_zero _ Polynomial.X_ne_zero) (A*B).charpoly_monic.ne_zero), + Polynomial.roots_mul (mul_ne_zero (pow_ne_zero _ Polynomial.X_ne_zero) (B*A).charpoly_monic.ne_zero)] at heq + have hz (n : ℕ) : ((n • ({0} : Multiset ℝ)).map Real.sqrt).sum=0 := by + induction n with + | zero => simp + | succ n hn => simp [succ_nsmul,Multiset.map_add,hn] + simpa [Polynomial.roots_X_pow,Multiset.map_add,hz] using heq + +lemma trace_sqrt_gram (M : Matrix V W ℝ) : + (CFC.sqrt (M*Mᵀ)).trace=(CFC.sqrt (Mᵀ*M)).trace := by + exact trace_sqrt_mul_comm M Mᵀ + (by simpa using posSemidef_self_mul_conjTranspose M) + (by simpa using posSemidef_conjTranspose_mul_self M) + +lemma cfc_continuousOn {A : Matrix V V ℝ} (hA : A.IsHermitian) (f : ℝ → ℝ) : + ContinuousOn f (spectrum ℝ A) := by + rw [hA.spectrum_real_eq_range_eigenvalues] + exact (Set.finite_range _).continuousOn f + +lemma inverse_sqrt_scalar {x : ℝ} (hx : 0 ≤ x) : (Real.sqrt x)⁻¹*x=Real.sqrt x := by + by_cases hx0 : x=0 + · simp [hx0] + · have hs : Real.sqrt x ≠ 0 := Real.sqrt_ne_zero'.mpr (lt_of_le_of_ne hx (Ne.symm hx0)) + calc + (Real.sqrt x)⁻¹*x=(Real.sqrt x)⁻¹*(Real.sqrt x*Real.sqrt x) := + congrArg (fun t : ℝ => (Real.sqrt x)⁻¹*t) (Real.mul_self_sqrt hx).symm + _=Real.sqrt x := by rw [←mul_assoc,inv_mul_cancel₀ hs,one_mul] + +lemma inverse_sqrt_scalar_bound {x : ℝ} (hx : 0 ≤ x) : + (Real.sqrt x)⁻¹*x*(Real.sqrt x)⁻¹ ≤ 1 := by + rw [inverse_sqrt_scalar hx] + by_cases hs : Real.sqrt x=0 + · simp [hs] + · simp [hs] + +omit [DecidableEq W] in + +lemma polar_optimizer (M : Matrix V W ℝ) : + ∃ U : Matrix W V ℝ, Uᵀ*U ≤ 1 ∧ + (U*M).trace=(CFC.sqrt (M*Mᵀ)).trace := by + let H := M*Mᵀ + have hH : H.PosSemidef := by simpa [H] using posSemidef_self_mul_conjTranspose M + let f : ℝ → ℝ := fun x => (Real.sqrt x)⁻¹ + let P := cfc f H + have hid : cfc (fun x : ℝ => x) H=H := cfc_id ℝ H hH.isHermitian + have hP : P.IsHermitian := cfc_predicate f H + have hPtrans : Pᵀ=P := isHermitian_iff_isSymm.mp hP + have hPH : P*H=CFC.sqrt H := by + rw [sqrt_eq_real_cfc hH] + calc + P*H=cfc (fun x => f x*x) H := by + rw [cfc_mul f (fun x => x) H (cfc_continuousOn hH.isHermitian f) + (cfc_continuousOn hH.isHermitian (fun x => x)),hid] + _=cfc Real.sqrt H := cfc_congr (fun x hx => inverse_sqrt_scalar (spectrum_nonneg_of_nonneg hH.nonneg hx)) + have hPHP : P*H*P ≤ 1 := by + have heq : P*H*P=cfc (fun x => f x*x*f x) H := by + rw [cfc_mul (fun x => f x*x) f H (cfc_continuousOn hH.isHermitian _) + (cfc_continuousOn hH.isHermitian _),cfc_mul f (fun x => x) H + (cfc_continuousOn hH.isHermitian _) (cfc_continuousOn hH.isHermitian _), + hid] + rw [heq] + exact cfc_le_one _ _ (fun x hx => inverse_sqrt_scalar_bound (spectrum_nonneg_of_nonneg hH.nonneg hx)) + refine ⟨Mᵀ*P,?_,?_⟩ + · simpa only [transpose_mul,transpose_transpose,hPtrans,Matrix.mul_assoc,H] using hPHP + · rw [Matrix.trace_mul_cycle] + change (M*Mᵀ*P).trace=(CFC.sqrt H).trace + change (H*P).trace=(CFC.sqrt H).trace + rw [Matrix.trace_mul_comm,hPH] + +omit [DecidableEq W] in +lemma norm_sq_mulVec_le {U : Matrix W V ℝ} (hU : Uᵀ*U ≤ 1) (x : V → ℝ) : + (U *ᵥ x) ⬝ᵥ (U *ᵥ x) ≤ x ⬝ᵥ x := by + have hp := (Matrix.le_iff.mp hU).dotProduct_mulVec_nonneg x + simp only [star_trivial,sub_mulVec,one_mulVec,dotProduct_sub] at hp + have heq : x ⬝ᵥ ((Uᵀ*U) *ᵥ x)=(U *ᵥ x) ⬝ᵥ (U *ᵥ x) := by + rw [←mulVec_mulVec,dotProduct_mulVec,vecMul_transpose] + rw [heq] at hp + linarith only [hp] + +variable {J : Type uJ2} [Fintype J] [DecidableEq J] + +lemma dual_trace_rectangular (C : Matrix V W ℝ) (Y : Matrix J V ℝ) : + (CFC.sqrt (CFC.sqrt (Yᵀ*Y)*(C*Cᵀ)*CFC.sqrt (Yᵀ*Y))).trace = + (CFC.sqrt ((Y*C)*(Y*C)ᵀ)).trace := by + let S := CFC.sqrt (Yᵀ*Y) + have hZ : (Yᵀ*Y).PosSemidef := by simpa using posSemidef_conjTranspose_mul_self Y + have hSH : Sᵀ=S := isHermitian_iff_isSymm.mp (CFC.sqrt_nonneg (Yᵀ*Y)).posSemidef.isHermitian + have hSS : S*S=Yᵀ*Y := CFC.sqrt_mul_sqrt_self _ hZ.nonneg + have hleft : S*(C*Cᵀ)*S=(S*C)*(S*C)ᵀ := by + simp only [transpose_mul,hSH,Matrix.mul_assoc] + change (CFC.sqrt (S*(C*Cᵀ)*S)).trace=_ + rw [hleft,trace_sqrt_gram,trace_sqrt_gram (Y*C)] + congr 2 + simp only [transpose_mul,hSH] + calc + (Cᵀ*S)*(S*C)=Cᵀ*(S*S)*C := by simp only [Matrix.mul_assoc] + _=(Cᵀ*Yᵀ)*(Y*C) := by rw [hSS]; simp only [Matrix.mul_assoc] + +lemma signed_diag_orthogonal (a : W → ℝ) : + let D : Matrix W W ℝ := diagonal (fun e => if 0 ≤ a e then (1:ℝ) else -1) + Dᵀ*D=1 := by + dsimp + rw [diagonal_transpose,diagonal_mul_diagonal] + ext i j + by_cases hij : i=j + · subst j + simp only [diagonal_apply_eq,one_apply_eq] + split_ifs <;> norm_num + · simp [diagonal_apply_ne _ hij,one_apply_ne hij] + +lemma positive_optimizer (M : Matrix V W ℝ) (w : W → ℝ) (hw : ∀e, 0 ≤ w e) : + ∃ U : Matrix W V ℝ, Uᵀ*U ≤ 1 ∧ (∀e, 0 ≤ (U*M) e e) ∧ + (CFC.sqrt ((M*diagonal w)*(M*diagonal w)ᵀ)).trace ≤ + ∑e, w e*(U*M) e e := by + obtain ⟨U,hU,htr⟩ := polar_optimizer (M*diagonal w) + let a : W → ℝ := fun e => (U*M) e e + let s : W → ℝ := fun e => if 0 ≤ a e then 1 else -1 + let D : Matrix W W ℝ := diagonal s + have hDD : Dᵀ*D=1 := signed_diag_orthogonal a + have hsa (e : W) : s e*a e=|a e| := by + dsimp [s] + split_ifs with he + · simp [abs_of_nonneg he] + · simp [abs_of_neg (lt_of_not_ge he)] + have hdiag (e : W) : ((D*U)*M) e e=|a e| := by + rw [Matrix.mul_assoc] + change (diagonal s*(U*M)) e e=|a e| + rw [diagonal_mul] + exact hsa e + refine ⟨D*U,?_,fun e => (hdiag e).symm ▸ abs_nonneg _,?_⟩ + · have heq : (D*U)ᵀ*(D*U)=Uᵀ*U := by + rw [transpose_mul] + calc + (Uᵀ*Dᵀ)*(D*U)=Uᵀ*(Dᵀ*D)*U := by simp only [Matrix.mul_assoc] + _=Uᵀ*U := by rw [hDD,Matrix.mul_one] + rw [heq] + exact hU + · rw [←htr,←Matrix.mul_assoc] + unfold Matrix.trace + apply sum_le_sum + intro e _ + change (U*M*diagonal w) e e ≤ w e*((D*U)*M) e e + rw [mul_diagonal,hdiag] + change a e*w e ≤ w e*|a e| + rw [mul_comm (a e)] + exact mul_le_mul_of_nonneg_left (le_abs_self _) (hw e) +end +end StrongThinTree.Polar + +namespace StrongThinTree.ShortcutDual +noncomputable section +open Matrix Finset Filter Topology +open scoped Classical MatrixOrder Matrix.Norms.L2Operator +variable {V : Type uV3} {E : Type uE2} {T : Type uT} {J : Type uJ3} [Fintype V] [DecidableEq V] + [Fintype E] [DecidableEq E] [Fintype T] [Fintype J] + +def boundaryMatrix (b : E → V → ℝ) (O : T → Finset E) (t : T) : Matrix V V ℝ := + ((O t).card : ℝ)⁻¹ • ∑e ∈ O t, vecMulVec (b e) (b e) + +def boundaryAverage (b : E → V → ℝ) (O : T → Finset E) (t : T) + (D : Matrix V V ℝ) : ℝ := + ((O t).card : ℝ)⁻¹ * ∑e ∈ O t, b e ⬝ᵥ (D⁻¹ *ᵥ b e) + +def objectiveMatrix (b : E → V → ℝ) (O : T → Finset E) (lam : T → ℝ) : Matrix V V ℝ := + ∑t, lam t • boundaryMatrix b O t + +def cutMatrix (c : J → V → ℝ) (y : J → ℝ) : Matrix V V ℝ := + ∑j, y j • vecMulVec (c j) (c j) + +omit [DecidableEq V] in +lemma outer_posSemidef (v : V → ℝ) : (vecMulVec v v).PosSemidef := by + simpa using posSemidef_vecMulVec_self_star v + +omit [Fintype E] [DecidableEq E] [Fintype T] in +omit [DecidableEq V] in +lemma boundaryMatrix_posSemidef (b : E → V → ℝ) (O : T → Finset E) (t : T) : + (boundaryMatrix b O t).PosSemidef := by + apply Matrix.PosSemidef.smul _ (inv_nonneg.mpr (Nat.cast_nonneg _)) + exact Matrix.posSemidef_sum _ (fun e _ => outer_posSemidef (b e)) + +omit [Fintype E] [DecidableEq E] in +omit [DecidableEq V] in +lemma objectiveMatrix_posSemidef (b : E → V → ℝ) (O : T → Finset E) + {lam : T → ℝ} (hlam : ∀t, 0 ≤ lam t) : (objectiveMatrix b O lam).PosSemidef := by + exact Matrix.posSemidef_sum _ (fun t _ => (boundaryMatrix_posSemidef b O t).smul (hlam t)) + +omit [DecidableEq V] in +lemma cutMatrix_posSemidef (c : J → V → ℝ) {y : J → ℝ} (hy : ∀j, 0 ≤ y j) : + (cutMatrix c y).PosSemidef := by + exact Matrix.posSemidef_sum _ (fun j _ => (outer_posSemidef (c j)).smul (hy j)) + +omit [DecidableEq V] in +lemma trace_outer_mul (v : V → ℝ) (D : Matrix V V ℝ) : + (vecMulVec v v * D).trace = v ⬝ᵥ (D *ᵥ v) := by + rw [vecMulVec_mul,trace_vecMulVec,dotProduct_comm,dotProduct_mulVec] + +omit [Fintype E] [DecidableEq E] [Fintype T] in +lemma boundaryAverage_convex (b : E → V → ℝ) (O : T → Finset E) (t : T) : + ConvexOn ℝ {D : Matrix V V ℝ | D.PosDef} (boundaryAverage b O t) := by + refine ⟨MatrixDual.posDef_convex,?_⟩ + intro X hX Y hY a a' ha ha' haa' + have hs := sum_le_sum (fun e (_ : e ∈ O t) => + (MatrixDual.inverse_quadratic_convex (b e)).2 hX hY ha ha' haa') + dsimp [boundaryAverage] + simp only [smul_eq_mul] at hs ⊢ + have h := mul_le_mul_of_nonneg_left hs (inv_nonneg.mpr (Nat.cast_nonneg (O t).card) : + 0 ≤ ((O t).card : ℝ)⁻¹) + simpa only [sum_add_distrib,←mul_sum,mul_add,mul_left_comm] using h + +omit [Fintype E] [DecidableEq E] in +lemma trace_objectiveMatrix (b : E → V → ℝ) (O : T → Finset E) + (lam : T → ℝ) (D : Matrix V V ℝ) : + (objectiveMatrix b O lam * D⁻¹).trace = ∑t, lam t * boundaryAverage b O t D := by + simp only [objectiveMatrix,Finset.sum_mul,smul_mul_assoc,trace_sum,trace_smul, + boundaryMatrix,boundaryAverage,smul_eq_mul,trace_outer_mul] + +lemma trace_cutMatrix (c : J → V → ℝ) (y d : J → ℝ) (D : Matrix V V ℝ) : + (cutMatrix c y * D).trace - ∑j, y j*d j = ∑j, y j*(c j ⬝ᵥ (D *ᵥ c j)-d j) := by + simp only [cutMatrix,Finset.sum_mul,smul_mul_assoc,trace_sum,trace_smul, + smul_eq_mul,trace_outer_mul,mul_sub,sum_sub_distrib] + +lemma cut_slater (c : J → V → ℝ) {d : J → ℝ} (hd : ∀j, 0 < d j) : + ∃D : Matrix V V ℝ, D.PosDef ∧ ∀j, c j ⬝ᵥ (D *ᵥ c j)-d j < 0 := by + have hlim (j : J) : Tendsto (fun t : ℝ => t*(c j ⬝ᵥ c j)) (𝓝[>] 0) (𝓝 0) := by + have hc : Continuous (fun t : ℝ => t*(c j ⬝ᵥ c j)) := by fun_prop + simpa only [zero_mul] using (hc.tendsto 0).mono_left nhdsWithin_le_nhds + have hev : ∀ᶠ t : ℝ in 𝓝[>] 0, ∀j, t*(c j ⬝ᵥ c j) < d j := + eventually_all.mpr (fun j => (hlim j).eventually_lt_const (hd j)) + have hup : ∀ᶠ t : ℝ in 𝓝[>] (0:ℝ), t ∈ Set.Ioi 0 := eventually_mem_nhdsWithin + obtain ⟨t,htd,ht⟩ := (hev.and hup).exists + refine ⟨t • (1 : Matrix V V ℝ), Matrix.PosDef.one.smul ht, ?_⟩ + intro j + simpa only [smul_mulVec,one_mulVec,dotProduct_smul,smul_eq_mul,sub_lt_zero] using htd j + +omit [Fintype E] [DecidableEq E] in + +lemma shortcut_of_trace_bound (b : E → V → ℝ) (O : T → Finset E) + (c : J → V → ℝ) (d : J → ℝ) (hd : ∀j, 0 < d j) {K : ℝ} (hK : 0 ≤ K) + (hbound : ∀lam : T → ℝ, ∀y : J → ℝ, (∀t, 0 ≤ lam t) → (∑t, lam t)=1 → + (∀j, 0 ≤ y j) → + (CFC.sqrt (CFC.sqrt (cutMatrix c y) * objectiveMatrix b O lam * + CFC.sqrt (cutMatrix c y))).trace^2 ≤ K * ∑j, y j*d j) + {eta : ℝ} (heta : 0 < eta) : + ∃D : Matrix V V ℝ, D.PosDef ∧ + (∀t, boundaryAverage b O t D < K+eta) ∧ (∀j, c j ⬝ᵥ (D *ᵥ c j) < d j) := by + have hs := Duality.strict_feasible_of_dual_bound {D : Matrix V V ℝ | D.PosDef} + MatrixDual.posDef_convex (boundaryAverage b O) (fun j D => c j ⬝ᵥ (D *ᵥ c j)-d j) + (boundaryAverage_convex b O) (fun j => MatrixDual.cut_quadratic_convex (c j) (d j)) + (cut_slater c hd) (K+eta) + obtain ⟨D,hD,hf,hg⟩ := hs (by + intro lam y hlam hlams hy + let A := objectiveMatrix b O lam + let Z := cutMatrix c y + let N := (CFC.sqrt (CFC.sqrt Z*A*CFC.sqrt Z)).trace + let v := ∑j, y j*d j + have hv : 0 ≤ v := sum_nonneg (fun j _ => mul_nonneg (hy j) (hd j).le) + have hN : 0 ≤ N := (CFC.sqrt_nonneg _).posSemidef.trace_nonneg + have hb : N^2 ≤ K*v := hbound lam y hlam hlams hy + have hNv : 2*N ≤ K+v := by nlinarith only [hb,hK,hv,hN,sq_nonneg (K-v)] + obtain ⟨D,hD,hval⟩ := MatrixDual.trace_objective_approx + (objectiveMatrix_posSemidef b O hlam) (cutMatrix_posSemidef c hy) + (show 2*N < K+eta+v by linarith only [hNv,heta]) + refine ⟨D,hD,?_⟩ + have htr := trace_cutMatrix c y d D + rw [trace_objectiveMatrix] at hval + change (∑t,lam t*boundaryAverage b O t D) + (cutMatrix c y*D).trace < K+eta+v at hval + linarith only [hval,htr]) + exact ⟨D,hD,hf,fun j => sub_neg.mp (hg j)⟩ + +lemma weighted_rows_bound (O : T → Finset E) (lam : T → ℝ) (a : E → ℝ) + (hlam : ∀t, 0 ≤ lam t) (hsum : (∑t, lam t)=1) (ha : ∀e, 0 ≤ a e) : + (∑e, Real.sqrt (∑t, if e ∈ O t then lam t / ((O t).card : ℝ) else 0)*a e)^2 ≤ + ∑t, (∑e ∈ O t, a e)^2/((O t).card : ℝ) := by + let r : T → ℝ := fun t => Real.sqrt (lam t / ((O t).card : ℝ)) + let c : T → ℝ := fun t => (∑e ∈ O t, a e)/Real.sqrt ((O t).card : ℝ) + have hw (e : E) : Real.sqrt (∑t, if e ∈ O t then lam t / ((O t).card : ℝ) else 0) ≤ + ∑t, if e ∈ O t then r t else 0 := by + apply Real.sqrt_le_iff.mpr + refine ⟨sum_nonneg (fun t _ => by split_ifs; exact Real.sqrt_nonneg _; exact le_rfl), ?_⟩ + calc + (∑t, if e ∈ O t then lam t / ((O t).card : ℝ) else 0) = + ∑t, (if e ∈ O t then r t else 0)^2 := by + apply sum_congr rfl + intro t _ + split_ifs + · exact (Real.sq_sqrt (div_nonneg (hlam t) (Nat.cast_nonneg _))).symm + · norm_num + _ ≤ _ := sum_sq_le_sq_sum_of_nonneg (fun t _ => by split_ifs; exact Real.sqrt_nonneg _; exact le_rfl) + have heq : (∑e, (∑t, if e ∈ O t then r t else 0)*a e) = + ∑t, Real.sqrt (lam t)*c t := by + simp_rw [sum_mul] + rw [sum_comm] + apply sum_congr rfl + intro t _ + calc + (∑e, (if e ∈ O t then r t else 0)*a e) = r t*∑e ∈ O t, a e := by + rw [mul_sum] + simp only [ite_mul,zero_mul] + rw [←sum_filter] + simp + _ = Real.sqrt (lam t)*c t := by + dsimp [r,c] + rw [Real.sqrt_div (hlam t)] + ring + have hle := sum_le_sum (fun e (_ : e ∈ (univ : Finset E)) => + mul_le_mul_of_nonneg_right (hw e) (ha e)) + rw [heq] at hle + have hsq := pow_le_pow_left₀ (sum_nonneg (fun e _ => + mul_nonneg (Real.sqrt_nonneg _) (ha e))) hle 2 + have hc := sum_mul_sq_le_sq_mul_sq univ (fun t => Real.sqrt (lam t)) c + have hs : (∑t, (Real.sqrt (lam t))^2)=1 := by simpa only [Real.sq_sqrt (hlam _)] using hsum + rw [hs,one_mul] at hc + refine hsq.trans (hc.trans_eq ?_) + apply sum_congr rfl + intro t _ + simp only [c,div_pow,Real.sq_sqrt (Nat.cast_nonneg _)] + +def edgeWeight (O : T → Finset E) (lam : T → ℝ) (e : E) : ℝ := + Real.sqrt (∑t, if e ∈ O t then lam t / ((O t).card : ℝ) else 0) + +omit [Fintype V] [DecidableEq V] in +lemma objectiveMatrix_eq_sum_edges (b : E → V → ℝ) (O : T → Finset E) (lam : T → ℝ) : + objectiveMatrix b O lam = ∑e, (∑t, if e ∈ O t then lam t / ((O t).card : ℝ) else 0) • + vecMulVec (b e) (b e) := by + have ht (t : T) : lam t • boundaryMatrix b O t = + ∑e, (if e ∈ O t then lam t / ((O t).card : ℝ) else 0) • vecMulVec (b e) (b e) := by + simp only [boundaryMatrix,smul_smul,div_eq_mul_inv,smul_sum,ite_smul,zero_smul] + rw [←sum_filter] + simp + simp only [objectiveMatrix,ht] + rw [sum_comm] + simp only [sum_smul] + +omit [Fintype V] [DecidableEq V] in +lemma weighted_gram (b : E → V → ℝ) (w : E → ℝ) : + let B : Matrix V E ℝ := fun v e => b e v + (B*diagonal w)*(B*diagonal w)ᵀ=∑e, (w e)^2 • vecMulVec (b e) (b e) := by + dsimp + ext i j + change (∑e, ((Matrix.of (fun v e => b e v))*diagonal w) i e * + ((Matrix.of (fun v e => b e v))*diagonal w) j e) = _ + simp only [mul_diagonal,Matrix.sum_apply,Matrix.smul_apply,smul_eq_mul,vecMulVec_apply,Matrix.of_apply] + apply sum_congr rfl + intro e _ + ring + +omit [Fintype V] [DecidableEq V] in +lemma objectiveMatrix_gram (b : E → V → ℝ) (O : T → Finset E) {lam : T → ℝ} + (hlam : ∀t, 0 ≤ lam t) : + let C : Matrix V E ℝ := (Matrix.of (fun v e => b e v))*diagonal (edgeWeight O lam) + objectiveMatrix b O lam=C*Cᵀ := by + dsimp + rw [weighted_gram,objectiveMatrix_eq_sum_edges] + apply sum_congr rfl + intro e _ + have hp : 0 ≤ ∑t, if e ∈ O t then lam t / ((O t).card : ℝ) else 0 := + sum_nonneg (fun t _ => by split_ifs; exact div_nonneg (hlam t) (Nat.cast_nonneg _); exact le_rfl) + rw [edgeWeight,Real.sq_sqrt hp] + rfl + +lemma nuclear_bound_of_embedding_bound (b : E → V → ℝ) (O : T → Finset E) + {H : Type uH} [Fintype H] [DecidableEq H] (X : Matrix H V ℝ) {K : ℝ} + (hbound : ∀U : Matrix E H ℝ, Uᵀ*U ≤ 1 → (∀e, 0 ≤ (U*(X*(Matrix.of (fun v e => b e v)))) e e) → + (∑t, (∑e ∈ O t, (U*(X*(Matrix.of (fun v e => b e v)))) e e)^2/((O t).card : ℝ)) ≤ K) + {lam : T → ℝ} (hlam : ∀t, 0 ≤ lam t) (hsum : (∑t, lam t)=1) : + (CFC.sqrt (CFC.sqrt (Xᵀ*X)*objectiveMatrix b O lam*CFC.sqrt (Xᵀ*X))).trace^2 ≤ K := by + let B : Matrix V E ℝ := fun v e => b e v + let w := edgeWeight O lam + have hw : ∀e, 0 ≤ w e := fun e => Real.sqrt_nonneg _ + obtain ⟨U,hU,hpos,htr⟩ := Polar.positive_optimizer (X*B) w hw + rw [objectiveMatrix_gram b O hlam,Polar.dual_trace_rectangular] + change (CFC.sqrt ((X*(B*diagonal w))*(X*(B*diagonal w))ᵀ)).trace^2 ≤ K + rw [←Matrix.mul_assoc] + have hsq := pow_le_pow_left₀ (CFC.sqrt_nonneg _).posSemidef.trace_nonneg htr 2 + exact hsq.trans ((weighted_rows_bound O lam (fun e => (U*(X*B)) e e) hlam hsum hpos).trans + (hbound U hU hpos)) + +lemma sqrt_smul_real {A : Matrix V V ℝ} (hA : A.PosSemidef) {s : ℝ} (hs : 0 ≤ s) : + CFC.sqrt (s • A)=Real.sqrt s • CFC.sqrt A := by + apply CFC.sqrt_unique + · simp only [smul_mul_assoc,mul_smul_comm,smul_smul, + Real.mul_self_sqrt hs,CFC.sqrt_mul_sqrt_self A hA.nonneg] + · exact ((CFC.sqrt_nonneg A).posSemidef.smul (Real.sqrt_nonneg s)).nonneg + +lemma traceRoot_sq_smul {A Z : Matrix V V ℝ} (hA : A.PosSemidef) (hZ : Z.PosSemidef) + {s : ℝ} (hs : 0 ≤ s) : + (CFC.sqrt (CFC.sqrt (s • Z)*A*CFC.sqrt (s • Z))).trace^2 = + s*(CFC.sqrt (CFC.sqrt Z*A*CFC.sqrt Z)).trace^2 := by + have hp : (CFC.sqrt Z*A*CFC.sqrt Z).PosSemidef := by + simpa only [(CFC.sqrt_nonneg Z).posSemidef.isHermitian.eq] using + hA.conjTranspose_mul_mul_same (CFC.sqrt Z) + rw [sqrt_smul_real hZ hs] + simp only [smul_mul_assoc,mul_smul_comm,smul_smul,Real.mul_self_sqrt hs] + rw [sqrt_smul_real hp hs,trace_smul] + simp only [smul_eq_mul,mul_pow,Real.sq_sqrt hs] + +lemma traceRoot_sq_tendsto {I : Type uI4} {l : Filter I} {A Z : Matrix V V ℝ} + (hA : A.PosSemidef) (hZ : Z.PosSemidef) {g : I → Matrix V V ℝ} + (hg : Tendsto g l (𝓝 Z)) (hgp : ∀ᶠ i in l, (g i).PosSemidef) : + Tendsto (fun i => (CFC.sqrt (CFC.sqrt (g i)*A*CFC.sqrt (g i))).trace^2) l + (𝓝 ((CFC.sqrt (CFC.sqrt Z*A*CFC.sqrt Z)).trace^2)) := by + have h := MatrixDual.traceRoot_tendsto hA hZ tendsto_const_nhds hg + (Eventually.of_forall (fun _ => hA)) hgp + have hr := h.div_const 2 + simp only [mul_div_cancel_left₀ _ (show (2:ℝ) ≠ 0 by norm_num)] at hr + exact hr.pow 2 + +omit [Fintype V] [DecidableEq V] in +lemma cutMatrix_smul (c : J → V → ℝ) (y : J → ℝ) (s : ℝ) : + cutMatrix c (fun j => s*y j)=s • cutMatrix c y := by + simp only [cutMatrix,smul_sum,smul_smul] + +lemma trace_bound_of_nat_weights {A : Matrix V V ℝ} (hA : A.PosSemidef) + (c : J → V → ℝ) (d : J → ℝ) (K : ℝ) + (hb : ∀a : J → ℕ, + (CFC.sqrt (CFC.sqrt (cutMatrix c (fun j => (a j : ℝ)))*A* + CFC.sqrt (cutMatrix c (fun j => (a j : ℝ))))).trace^2 ≤ K*∑j, (a j : ℝ)*d j) + {y : J → ℝ} (hy : ∀j, 0 ≤ y j) : + (CFC.sqrt (CFC.sqrt (cutMatrix c y)*A*CFC.sqrt (cutMatrix c y))).trace^2 ≤ + K*∑j, y j*d j := by + let a : ℝ → J → ℕ := fun t j => ⌊y j*t⌋₊ + let z : ℝ → J → ℝ := fun t j => (a t j : ℝ)/t + have hz (j : J) : Tendsto (fun t => z t j) atTop (𝓝 (y j)) := + tendsto_nat_floor_mul_div_atTop (hy j) + have hg : Tendsto (fun t => cutMatrix c (z t)) atTop (𝓝 (cutMatrix c y)) := + tendsto_finsetSum univ (fun j _ => (hz j).smul_const (vecMulVec (c j) (c j))) + have hgp : ∀ᶠ t in atTop, (cutMatrix c (z t)).PosSemidef := by + filter_upwards [eventually_gt_atTop (0:ℝ)] with t ht + exact cutMatrix_posSemidef c (fun j => div_nonneg (Nat.cast_nonneg _) ht.le) + have hl := traceRoot_sq_tendsto hA (cutMatrix_posSemidef c hy) hg hgp + have hr : Tendsto (fun t => K*∑j, z t j*d j) atTop (𝓝 (K*∑j,y j*d j)) := + (tendsto_finsetSum univ (fun j _ => (hz j).mul_const (d j))).const_mul K + apply le_of_tendsto_of_tendsto hl hr + filter_upwards [eventually_gt_atTop (0:ℝ)] with t ht + have heq : cutMatrix c (z t)=t⁻¹ • cutMatrix c (fun j => (a t j : ℝ)) := by + simpa only [z,div_eq_mul_inv,mul_comm] using + cutMatrix_smul c (fun j => (a t j : ℝ)) t⁻¹ + rw [heq,traceRoot_sq_smul hA (cutMatrix_posSemidef c (fun j => Nat.cast_nonneg _)) + (inv_nonneg.mpr ht.le)] + have hh := mul_le_mul_of_nonneg_left (hb (a t)) (inv_nonneg.mpr ht.le) + convert hh using 1 + simp only [z,div_eq_mul_inv,mul_sum] + apply sum_congr rfl + intro j _ + ring + +def replicaMatrix (c : J → V → ℝ) (a : J → ℕ) : + Matrix (Fin (Fintype.card (Σj, Fin (a j)))) V ℝ := + fun i v => c ((Fintype.equivFin (Σj, Fin (a j))).symm i).1 v + +omit [Fintype V] [DecidableEq V] in +lemma replicaMatrix_binary (c : J → V → ℝ) (hc : ∀j v, c j v=0 ∨ c j v=1) + (a : J → ℕ) : ∀i v, replicaMatrix c a i v=0 ∨ replicaMatrix c a i v=1 := + fun _i v => hc _ v + +omit [Fintype V] [DecidableEq V] in +lemma replicaMatrix_gram (c : J → V → ℝ) (a : J → ℕ) : + (replicaMatrix c a)ᵀ*replicaMatrix c a=cutMatrix c (fun j => (a j : ℝ)) := by + ext v w + change (∑i, c ((Fintype.equivFin (Σj, Fin (a j))).symm i).1 v * + c ((Fintype.equivFin (Σj, Fin (a j))).symm i).1 w) = _ + rw [(Fintype.equivFin (Σj, Fin (a j))).symm.sum_comp + (fun i : (Σj, Fin (a j)) => c i.1 v*c i.1 w)] + simp only [Fintype.sum_sigma,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + cutMatrix,Matrix.sum_apply,Matrix.smul_apply,smul_eq_mul,vecMulVec_apply] + +omit [DecidableEq V] [DecidableEq E] in +lemma replicaMatrix_energy (b : E → V → ℝ) (c : J → V → ℝ) (a : J → ℕ) : + (∑e, ∑i, (replicaMatrix c a * Matrix.of (fun v e => b e v)) i e ^ 2) = + ∑j, (a j : ℝ)*(∑e, (∑v, c j v*b e v)^2) := by + rw [sum_comm] + change (∑i, (fun j : (Σj, Fin (a j)) => ∑e, (∑v, c j.1 v*b e v)^2) + ((Fintype.equivFin (Σj, Fin (a j))).symm i)) = _ + rw [(Fintype.equivFin (Σj, Fin (a j))).symm.sum_comp + (fun j : (Σj, Fin (a j)) => ∑e, (∑v, c j.1 v*b e v)^2)] + simp only [Fintype.sum_sigma,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + +lemma shortcut_of_binary_bound (b : E → V → ℝ) (O : T → Finset E) + (c : J → V → ℝ) (d : J → ℝ) (hc : ∀j v, c j v=0 ∨ c j v=1) + (hd : ∀j, 0 < d j) (henergy : ∀j, (∑e, (∑v, c j v*b e v)^2)=d j) + {K : ℝ} (hK : 0 ≤ K) + (hbound : ∀h : ℕ, ∀X : Matrix (Fin h) V ℝ, (∀i v, X i v=0 ∨ X i v=1) → + ∀U : Matrix E (Fin h) ℝ, Uᵀ*U ≤ 1 → + (∀e, 0 ≤ (U*(X*Matrix.of (fun v e => b e v))) e e) → + (∑t, (∑e ∈ O t, (U*(X*Matrix.of (fun v e => b e v))) e e)^2/((O t).card : ℝ)) ≤ + K*(∑e, ∑i, (X*Matrix.of (fun v e => b e v)) i e ^2)) + {eta : ℝ} (heta : 0 < eta) : + ∃D : Matrix V V ℝ, D.PosDef ∧ + (∀t, boundaryAverage b O t D < K+eta) ∧ (∀j, c j ⬝ᵥ (D *ᵥ c j) < d j) := by + apply shortcut_of_trace_bound b O c d hd hK _ heta + intro lam y hlam hlams hy + apply trace_bound_of_nat_weights (objectiveMatrix_posSemidef b O hlam) c d K _ hy + intro a + have heq := nuclear_bound_of_embedding_bound b O (replicaMatrix c a) + (hbound _ _ (replicaMatrix_binary c hc a)) hlam hlams + rwa [replicaMatrix_gram,replicaMatrix_energy,show + (∑j, (a j : ℝ)*(∑ e, (∑ v, c j v*b e v)^2))=∑j, (a j : ℝ)*d j by simp_rw [henergy]] at heq + +end +end StrongThinTree.ShortcutDual + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/DyadicSelection.lean b/lean/OAI/Combinatorics/ThinTrees/DyadicSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..eb42f93a7337c4bb7263e6a0b40c205b38bed576 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/DyadicSelection.lean @@ -0,0 +1,81 @@ +import OAI.Combinatorics.ThinTrees.ThresholdChain + +namespace OAI + +section + +namespace StrongThinTree.Dyadic +noncomputable section +open Finset + +def selected (M : ℕ → ℕ) (z : ℕ) : Finset ℕ := + ((range (z+1)).filter (fun i => 0 < M i)).filter + (fun i => ∀j ≤ z, 0 < M j → Nat.log 2 (M j)=Nat.log 2 (M i) → i ≤ j) + +lemma selected_spec {M : ℕ → ℕ} {z i : ℕ} (hi : i ∈ selected M z) : + i ≤ z ∧ 0 < M i ∧ ∀j ≤ z, 0 < M j → Nat.log 2 (M j)=Nat.log 2 (M i) → i ≤ j := by + simp only [selected,mem_filter,mem_range] at hi + exact ⟨by omega,hi.1.2,hi.2⟩ + +lemma selected_injective (M : ℕ → ℕ) (z : ℕ) : + Set.InjOn (fun i => Nat.log 2 (M i)) (selected M z) := by + intro i hi j hj h + obtain ⟨hiz,hip,himin⟩ := selected_spec hi + obtain ⟨hjz,hjp,hjmin⟩ := selected_spec hj + exact Nat.le_antisymm (himin j hjz hjp h.symm) (hjmin i hiz hip h) + +lemma representative {M : ℕ → ℕ} {z i : ℕ} (hiz : i ≤ z) (hip : 0 < M i) : + ∃j ∈ selected M z, j ≤ i ∧ Nat.log 2 (M j)=Nat.log 2 (M i) := by + classical + let C := (range (z+1)).filter (fun j => 0 < M j ∧ Nat.log 2 (M j)=Nat.log 2 (M i)) + have hi : i ∈ C := mem_filter.mpr ⟨mem_range.mpr (by omega),hip,rfl⟩ + let j := C.min' ⟨i,hi⟩ + have hj : j ∈ C := min'_mem _ _ + obtain ⟨hjz,hjp,hlog⟩ := mem_filter.mp hj + refine ⟨j,?_,min'_le _ _ hi,hlog⟩ + apply mem_filter.mpr + refine ⟨mem_filter.mpr ⟨hjz,hjp⟩,?_⟩ + intro k hk hkp hkl + exact min'_le C k (mem_filter.mpr ⟨mem_range.mpr (by omega),hkp,hkl.trans hlog⟩) + +lemma same_bin_ratio {a b : ℕ} (hb : 0 < b) (h : Nat.log 2 a=Nat.log 2 b) : a < 2*b := by + have ha := Nat.lt_pow_succ_log_self (by decide : 1 < 2) a + have hl := Nat.pow_log_le_self 2 (Nat.ne_of_gt hb) + rw [h,pow_succ] at ha + omega + +lemma tail_bound {M : ℕ → ℕ} {z : ℕ} (hmono : Antitone M) {i : ℕ} + (hi : i ∈ selected M z) : + (∑j ∈ (selected M z).filter (fun j => i ≤ j), (M j : ℝ)) ≤ 4*(M i : ℝ) := by + classical + let J := (selected M z).filter (fun j => i ≤ j) + let a := Nat.log 2 (M i) + have hinj : Set.InjOn (fun j => Nat.log 2 (M j)) J := + (selected_injective M z).mono (filter_subset _ _) + have hsub : J.image (fun j => Nat.log 2 (M j)) ⊆ range (a+1) := by + intro b hb + obtain ⟨j,hj,rfl⟩ := mem_image.mp hb + exact mem_range.mpr (Nat.lt_succ_of_le (Nat.log_mono_right (hmono (mem_filter.mp hj).2))) + have hpow : (2 : ℝ)^a ≤ (M i : ℝ) := by + exact_mod_cast Nat.pow_log_le_self 2 (Nat.ne_of_gt (selected_spec hi).2.1) + calc + (∑j ∈ J, (M j : ℝ)) ≤ ∑j ∈ J, (2 : ℝ)^(Nat.log 2 (M j)+1) := by + apply sum_le_sum + intro j _ + exact_mod_cast (Nat.lt_pow_succ_log_self (by decide : 1 < 2) (M j)).le + _ = ∑b ∈ J.image (fun j => Nat.log 2 (M j)), (2 : ℝ)^(b+1) := + (sum_image (f := fun b => (2 : ℝ)^(b+1)) hinj).symm + _ ≤ ∑b ∈ range (a+1), (2 : ℝ)^(b+1) := + sum_le_sum_of_subset_of_nonneg hsub (by intros; positivity) + _ = 2*((2 : ℝ)^(a+1)-1) := by + simp_rw [pow_succ] + rw [←Finset.sum_mul,geom_sum_eq (by norm_num : (2:ℝ) ≠ 1) (a+1)] + ring + _ ≤ 4*(M i : ℝ) := by rw [pow_succ]; nlinarith + +end +end StrongThinTree.Dyadic + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/AlgorithmicMain.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/AlgorithmicMain.lean new file mode 100644 index 0000000000000000000000000000000000000000..55782cd575c8892c26f42bae7b20b24165e57f78 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/AlgorithmicMain.lean @@ -0,0 +1,87 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Realization.OriginalMachine +import OAI.Combinatorics.ThinTrees.Encoding.InputDispatch +import OAI.Combinatorics.ThinTrees.Sparsification.ExplicitAlgorithm + +namespace OAI + +/-! Algorithmic main. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine +variable {α : Type*} {ea : α → Word} {f : α → Word} + +def realizedMachine (r : Realizes ea wordCode f) : CurrentKS.Machine := + ArchivedMachine.machine ({r.routine.program with input := 0,output := 0}.toMachine) + +lemma realizedMachine_run (r : Realizes ea wordCode f) (x : α) : + (realizedMachine r).run (ea x) (r.cost x) = ⟨none,CleanRoutine.io (f x)⟩ := by + let P := {r.routine.program with input := 0,output := 0} + have h : KS.W03.MachineCombinators.RunSpec P (CleanRoutine.io (ea x)) + (CleanRoutine.io (f x)) (r.cost x) := by + intro bits hb + exact (CurrentKS.program_ports_run r.routine.program 0 0 _ bits).trans + (r.routine.spec x bits hb) + have ht := ArchivedMachine.runSpec_transfer P _ _ _ h + change ((ArchivedMachine.machine P.toMachine).step^[r.cost x]) + ((ArchivedMachine.machine P.toMachine).init (ea x))=_ + have hi : (ArchivedMachine.machine P.toMachine).init (ea x) = + ⟨some P.initial,CleanRoutine.io (ea x)⟩ := by + apply congrArg (CurrentKS.Config.mk (some P.initial)) + refine funext (fun (j : Fin (r.routine.scratch+1)) => ?_) + change (if j=(0 : Fin (r.routine.scratch+1)) then ea x else [])= + (if j.val=0 then ea x else []) + simp only [Fin.ext_iff,Fin.val_zero] + rw [hi] + exact ht +end CurrentKS.Realization + +namespace AlgorithmicThinTrees.InputStack +open CurrentKS CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 +open GraphicHalf.Stack + +def machine (R : ℕ) : CurrentKS.Machine := realizedMachine (program R) + +lemma machine_run (R : ℕ) (x : Good) : + (machine R).run x.val.encode ((program R).cost x) = + ⟨none,CurrentKS.CleanRoutine.io (output R x)⟩ := + realizedMachine_run (program R) x + +lemma machine_correct {R : ℕ} {C : ℝ} (hC : 0 x) + (isPoly_self (fun x : InputStack.Good => x.val.length)) + obtain ⟨p,hp⟩ := ht.cost + refine ⟨2*C,by positivity,InputStack.machine R,p.coefficient+1,p.degree,Nat.succ_pos _,?_⟩ + intro x hx + let y : InputStack.Good := ⟨x,hx⟩ + have hr := InputStack.machine_correct hC hcorrect y + have hbound : (InputStack.program R).cost y ≤ + (p.coefficient+1)*(x.length+1)^p.degree := + ((hp y).trans (p.eval_le_input_polynomial x.length)).trans + (Nat.mul_le_mul_right _ (Nat.le_succ p.coefficient)) + have he := CurrentKS.Machine.run_halted hr.1 hbound + dsimp only [y] at he hr + dsimp only + rw [he] + exact hr + +end AlgorithmicThinTrees +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/BinaryReduction.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/BinaryReduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..99ce7e5f10091d6c7baa221537f8d74be87d742f --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/BinaryReduction.lean @@ -0,0 +1,387 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.Specification + +namespace OAI + +/-! Binary reduction. -/ + +section + +namespace AlgorithmicThinTrees +open StrongThinTree Finset + +lemma sum_min_capacity {ι : Type*} (s : Finset ι) (c : ι → ℕ) (k : ℕ) + (hk : k ≤ ∑ i ∈ s, c i) : k ≤ ∑ i ∈ s, min (c i) k := by + classical + by_cases h : ∃ i ∈ s, k ≤ c i + · obtain ⟨i, hi, hc⟩ := h + calc + k = min (c i) k := (min_eq_right hc).symm + _ ≤ ∑ j ∈ s, min (c j) k := single_le_sum (fun j _ => show 0 ≤ min (c j) k from Nat.zero_le _) hi + · have hc : ∀ i ∈ s, c i ≤ k := by + intro i hi + have h' : ¬ k ≤ c i := fun h' => h ⟨i, hi, h'⟩ + omega + simpa only [sum_congr rfl (fun i hi => min_eq_left (hc i hi))] using hk + +lemma sum_div_rounding {ι : Type*} (s : Finset ι) (c : ι → ℕ) {k : ℕ} + (hk : 0 < k) (b : ℕ) (hc : k ≤ ∑ i ∈ s, c i) : + b ≤ (∑ i ∈ s, b * c i / k) + s.card := by + have hi (i : ι) : b * c i ≤ k * (b * c i / k + 1) := by + have hmod := Nat.mod_lt (b * c i) hk + have hid := Nat.mod_add_div (b * c i) k + nlinarith + have hs := sum_le_sum (fun i (_ : i ∈ s) => hi i) + have hleft : b * k ≤ ∑ i ∈ s, b * c i := by + rw [← mul_sum] + exact Nat.mul_le_mul_left b hc + have hright : (∑ i ∈ s, k * (b * c i / k + 1)) = + k * ((∑ i ∈ s, b * c i / k) + s.card) := by + simp [mul_add, sum_add_distrib, mul_sum, Nat.mul_comm] + rw [hright] at hs + have hfinal : k * b ≤ k * ((∑ i ∈ s, b * c i / k) + s.card) := by + simpa only [Nat.mul_comm b k] using hleft.trans hs + exact Nat.le_of_mul_le_mul_left hfinal hk + +namespace BinaryInput + +def crossing (x : BinaryInput) (S : Finset (Fin x.n)) : Finset (Fin x.p) := + univ.filter fun i => (x.left i ∈ S ∧ x.right i ∉ S) ∨ + (x.right i ∈ S ∧ x.left i ∉ S) + +lemma cut_card (x : BinaryInput) (S : Finset (Fin x.n)) : + (x.graph.cut univ S).card = ∑ i ∈ x.crossing S, x.multiplicity i := by + classical + rw [MultiGraph.cut, card_filter] + rw [← x.edgeEquiv.sum_comp] + simp only [graph, Equiv.symm_apply_apply] + rw [Fintype.sum_sigma] + simp [crossing, sum_filter] + apply sum_congr rfl + intro i hi + split_ifs <;> simp + +lemma pairs_bound (x : BinaryInput) (hn : 0 < x.n) : 2 * x.p < x.n ^ 2 := by + classical + let P : Finset (Fin x.n × Fin x.n) := univ.image (fun i => (x.left i, x.right i)) + let Q : Finset (Fin x.n × Fin x.n) := univ.image (fun i => (x.right i, x.left i)) + have hP : P.card = x.p := by simp [P, card_image_of_injective _ x.distinct] + have hinj : Function.Injective (fun i : Fin x.p => (x.right i, x.left i)) := by + intro i j hij + apply x.distinct + exact Prod.ext (congrArg Prod.snd hij) (congrArg Prod.fst hij) + have hQ : Q.card = x.p := by simp [Q, card_image_of_injective _ hinj] + have hdis : Disjoint P Q := by + rw [disjoint_left] + rintro a ha hb + obtain ⟨i, _, hi⟩ := mem_image.mp ha + obtain ⟨j, _, hj⟩ := mem_image.mp hb + have he : (x.left i, x.right i) = (x.right j, x.left j) := hi.trans hj.symm + have he₁ := congrArg Prod.fst he + have he₂ := congrArg Prod.snd he + have hli := x.ordered i + have hlj := x.ordered j + simp only at he₁ he₂ + rw [he₁, he₂] at hli + exact (not_lt_of_gt hlj) hli + have hmiss : ((⟨0, hn⟩ : Fin x.n), (⟨0, hn⟩ : Fin x.n)) ∉ P ∪ Q := by + intro h + rcases mem_union.mp h with h | h + · obtain ⟨i, _, he⟩ := mem_image.mp h + have hl := congrArg Prod.fst he + have hr := congrArg Prod.snd he + have ho := x.ordered i + simp only at hl hr + rw [hl, hr] at ho + exact (lt_irrefl _) ho + · obtain ⟨i, _, he⟩ := mem_image.mp h + have hl := congrArg Prod.snd he + have hr := congrArg Prod.fst he + have ho := x.ordered i + simp only at hl hr + rw [hl, hr] at ho + exact (lt_irrefl _) ho + have hproper : P ∪ Q ⊂ univ := by + refine Finset.ssubset_iff_subset_ne.mpr ⟨subset_univ _, ?_⟩ + intro he + exact hmiss (he.symm ▸ mem_univ _) + have hcard := card_lt_card hproper + rw [card_union_of_disjoint hdis, hP, hQ] at hcard + simpa [sq, two_mul] using hcard + +abbrev reduced (x : BinaryInput) : BinaryInput where + n := x.n + p := x.p + k := x.n ^ 2 + left := x.left + right := x.right + ordered := x.ordered + distinct := x.distinct + multiplicity i := 2 * x.n ^ 2 * min (x.multiplicity i) x.k / x.k + +lemma reduced_crossing (x : BinaryInput) (S : Finset (Fin x.n)) : + x.reduced.crossing S = x.crossing S := rfl + +lemma reduced_multiplicity_le (x : BinaryInput) (hk : 0 < x.k) (i : Fin x.p) : + x.reduced.multiplicity i ≤ 2 * x.n ^ 2 := by + change 2 * x.n ^ 2 * min (x.multiplicity i) x.k / x.k ≤ _ + have h := Nat.div_le_div_right (c := x.k) (Nat.mul_le_mul_left (2 * x.n ^ 2) + (min_le_right (x.multiplicity i) x.k)) + simpa [Nat.ne_of_gt hk] using h + +lemma reduced_edgeConnected (x : BinaryInput) (hn : 0 < x.n) (hk : 0 < x.k) + (hc : x.graph.EdgeConnected x.k) : x.reduced.graph.EdgeConnected (x.n ^ 2) := by + intro S hS hS' + have hc' := hc S hS hS' + rw [cut_card] at hc' + have hmin := sum_min_capacity (x.crossing S) x.multiplicity x.k hc' + have hround := sum_div_rounding (x.crossing S) + (fun i => min (x.multiplicity i) x.k) hk (2 * x.n ^ 2) hmin + rw [cut_card, reduced_crossing] + have hcard : (x.crossing S).card ≤ x.n ^ 2 := by + have hle := card_le_card (filter_subset (fun i => + (x.left i ∈ S ∧ x.right i ∉ S) ∨ (x.right i ∈ S ∧ x.left i ∉ S)) univ) + change (x.crossing S).card ≤ (univ : Finset (Fin x.p)).card at hle + simp only [card_univ, Fintype.card_fin] at hle + have hp := x.pairs_bound hn + omega + change x.n ^ 2 ≤ ∑ i ∈ x.crossing S, 2 * x.n ^ 2 * min (x.multiplicity i) x.k / x.k + omega + +lemma reduced_size (x : BinaryInput) (hn : 0 < x.n) (hk : 0 < x.k) : + Fintype.card x.reduced.Edge < x.n ^ 4 := by + have hsize : Fintype.card x.reduced.Edge ≤ x.p * (2 * x.n ^ 2) := by + simp only [Edge, Fintype.card_sigma, Fintype.card_fin] + calc + ∑ i : Fin x.p, x.reduced.multiplicity i ≤ ∑ _ : Fin x.p, 2 * x.n ^ 2 := + sum_le_sum (fun i _ => reduced_multiplicity_le x hk i) + _ = _ := by simp + have hp := x.pairs_bound hn + have hn2 : 0 < x.n ^ 2 := pow_pos hn 2 + have hlt := Nat.mul_lt_mul_of_pos_right hp hn2 + nlinarith + +lemma reduced_cut_upper (x : BinaryInput) (hk : 0 < x.k) (S : Finset (Fin x.n)) : + ((x.reduced.graph.cut univ S).card : ℝ) ≤ + (2 * (x.n : ℝ) ^ 2 / (x.k : ℝ)) * (x.graph.cut univ S).card := by + have hkR : (0 : ℝ) < x.k := Nat.cast_pos.mpr hk + have hterm (i : Fin x.p) : + (x.reduced.multiplicity i : ℝ) ≤ + 2 * (x.n : ℝ) ^ 2 / (x.k : ℝ) * x.multiplicity i := by + have hnat : x.k * x.reduced.multiplicity i ≤ + 2 * x.n ^ 2 * x.multiplicity i := by + have h₁ := Nat.div_mul_le_self (2 * x.n ^ 2 * min (x.multiplicity i) x.k) x.k + have h₂ := Nat.mul_le_mul_left (2 * x.n ^ 2) (min_le_left (x.multiplicity i) x.k) + change x.k * (2 * x.n ^ 2 * min (x.multiplicity i) x.k / x.k) ≤ _ + simpa [Nat.mul_comm] using h₁.trans h₂ + have hreal : (x.k : ℝ) * x.reduced.multiplicity i ≤ + 2 * (x.n : ℝ) ^ 2 * x.multiplicity i := by exact_mod_cast hnat + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ hkR).mpr + simpa [div_mul_eq_mul_div, mul_comm, mul_left_comm, mul_assoc] using hreal + rw [x.reduced.cut_card S, x.cut_card S, reduced_crossing, Nat.cast_sum, Nat.cast_sum, mul_sum] + exact sum_le_sum (fun i _ => hterm i) + +end BinaryInput +end AlgorithmicThinTrees + +namespace StrongThinTree.MultiGraph +open Finset + +lemma cut_image {n m m' : ℕ} (G : MultiGraph n m) (H : MultiGraph n m') + (f : Fin m → Fin m') (hl : ∀ e, H.left (f e) = G.left e) + (hr : ∀ e, H.right (f e) = G.right e) (T : Finset (Fin m)) + (S : Finset (Fin n)) : H.cut (T.image f) S = (G.cut T S).image f := by + classical + ext e + constructor + · intro he + obtain ⟨⟨a, ha, rfl⟩, hcross⟩ := mem_filter.mp he |>.imp_left mem_image.mp + refine mem_image.mpr ⟨a, ?_, rfl⟩ + exact mem_filter.mpr ⟨ha, by simpa [hl, hr] using hcross⟩ + · intro he + obtain ⟨a, ha, rfl⟩ := mem_image.mp he + obtain ⟨ha, hcross⟩ := mem_filter.mp ha + exact mem_filter.mpr ⟨mem_image.mpr ⟨a, ha, rfl⟩, by simpa [hl, hr] using hcross⟩ + +lemma spanningTree_image {n m m' : ℕ} (G : MultiGraph n m) (H : MultiGraph n m') + (f : Fin m → Fin m') (hl : ∀ e, H.left (f e) = G.left e) + (hr : ∀ e, H.right (f e) = G.right e) {T : Finset (Fin m)} + (hT : G.SpanningTree T) : H.SpanningTree (T.image f) := by + classical + refine ⟨?_, ?_⟩ + · intro S hS hS' + rw [cut_image G H f hl hr] + exact (hT.1 S hS hS').image f + · intro e he hc + obtain ⟨a, ha, rfl⟩ := mem_image.mp he + apply hT.2 a ha + intro S hS hS' + obtain ⟨b, hb⟩ := hc S hS hS' + obtain ⟨hb, hcross⟩ := mem_filter.mp hb + obtain ⟨hne, hb⟩ := mem_erase.mp hb + obtain ⟨c, hc, heq⟩ := mem_image.mp hb + refine ⟨c, mem_filter.mpr ⟨mem_erase.mpr ⟨?_, hc⟩, ?_⟩⟩ + · intro he + subst c + exact hne heq.symm + · simpa only [← heq, hl, hr] using hcross + +lemma cut_image_card_le {n m m' : ℕ} (G : MultiGraph n m) (H : MultiGraph n m') + (f : Fin m → Fin m') (hl : ∀ e, H.left (f e) = G.left e) + (hr : ∀ e, H.right (f e) = G.right e) (T : Finset (Fin m)) + (S : Finset (Fin n)) : (H.cut (T.image f) S).card ≤ (G.cut T S).card := by + rw [cut_image G H f hl hr] + exact card_image_le + +end StrongThinTree.MultiGraph + +namespace AlgorithmicThinTrees.BinaryInput +open StrongThinTree Finset + +lemma original_copy_exists (x : BinaryInput) (e : x.reduced.Edge) : + 0 < x.multiplicity e.1 := by + by_contra h + have hzero : x.multiplicity e.1 = 0 := Nat.eq_zero_of_not_pos h + have := e.2.isLt + simp [reduced, hzero] at this + +def liftCopy (x : BinaryInput) (e : x.reduced.Edge) : x.Edge := + ⟨e.1, ⟨0, x.original_copy_exists e⟩⟩ + +noncomputable def liftLabel (x : BinaryInput) (e : Fin (Fintype.card x.reduced.Edge)) : + Fin (Fintype.card x.Edge) := + x.edgeEquiv (x.liftCopy (x.reduced.edgeEquiv.symm e)) + +lemma liftLabel_left (x : BinaryInput) (e : Fin (Fintype.card x.reduced.Edge)) : + x.graph.left (x.liftLabel e) = x.reduced.graph.left e := by + simp [graph, liftLabel, liftCopy] + +lemma liftLabel_right (x : BinaryInput) (e : Fin (Fintype.card x.reduced.Edge)) : + x.graph.right (x.liftLabel e) = x.reduced.graph.right e := by + simp [graph, liftLabel, liftCopy] + +lemma lift_thinTree (x : BinaryInput) (hn : 0 < x.n) (hk : 0 < x.k) + {C : ℝ} (hC : 0 ≤ C) {T : Finset (Fin (Fintype.card x.reduced.Edge))} + (hT : ThinTree C (x.n ^ 2) x.reduced.graph T) : + ThinTree (2 * C) x.k x.graph (T.image x.liftLabel) := by + refine ⟨x.reduced.graph.spanningTree_image x.graph x.liftLabel x.liftLabel_left + x.liftLabel_right hT.1, ?_⟩ + intro S hS hS' + have hnR : (0 : ℝ) < x.n := Nat.cast_pos.mpr hn + have hkR : (0 : ℝ) < x.k := Nat.cast_pos.mpr hk + have hcoef : 0 ≤ C / (x.n ^ 2 : ℕ) := div_nonneg hC (Nat.cast_nonneg _) + calc + ((x.graph.cut (T.image x.liftLabel) S).card : ℝ) ≤ + (x.reduced.graph.cut T S).card := by + exact_mod_cast x.reduced.graph.cut_image_card_le x.graph x.liftLabel + x.liftLabel_left x.liftLabel_right T S + _ ≤ C / (x.n ^ 2 : ℕ) * (x.reduced.graph.cut univ S).card := hT.2 S hS hS' + _ ≤ C / (x.n ^ 2 : ℕ) * + ((2 * (x.n : ℝ) ^ 2 / (x.k : ℝ)) * (x.graph.cut univ S).card) := + mul_le_mul_of_nonneg_left (x.reduced_cut_upper hk S) hcoef + _ = 2 * C / (x.k : ℝ) * (x.graph.cut univ S).card := by + push_cast + field_simp + +theorem reduction_correct (x : BinaryInput) (hn : 2 ≤ x.n) (hk : 1 ≤ x.k) + (hc : x.graph.EdgeConnected x.k) : + x.reduced.graph.EdgeConnected (x.n ^ 2) ∧ + Fintype.card x.reduced.Edge < x.n ^ 4 ∧ + (∀ S : Finset (Fin x.n), ((x.reduced.graph.cut univ S).card : ℝ) ≤ + 2 * (x.n : ℝ) ^ 2 / (x.k : ℝ) * (x.graph.cut univ S).card) ∧ + (∀ C : ℝ, 0 ≤ C → ∀ T : Finset (Fin (Fintype.card x.reduced.Edge)), + ThinTree C (x.n ^ 2) x.reduced.graph T → + ThinTree (2 * C) x.k x.graph (T.image x.liftLabel)) := by + have hn' : 0 < x.n := by omega + exact ⟨x.reduced_edgeConnected hn' hk hc, x.reduced_size hn' hk, + x.reduced_cut_upper hk, fun _ hC _ hT => x.lift_thinTree hn' hk hC hT⟩ + +end AlgorithmicThinTrees.BinaryInput + +namespace AlgorithmicThinTrees +open StrongThinTree Finset + +lemma framed_nat_length_pos (v : ℕ) : 0 < (CurrentKS.encodeNat v).length := by + unfold CurrentKS.encodeNat + cases Computability.encodeNat v <;> simp [CurrentKS.frame] + +lemma record_count_le_bits (records : List (List Bool)) + (h : ∀ bits ∈ records, 0 < bits.length) : records.length ≤ records.flatten.length := by + induction records with + | nil => simp + | cons bits records ih => + have hb := h bits (List.mem_cons_self ..) + have hr := ih (fun bs hbs => h bs (List.mem_cons_of_mem _ hbs)) + simp only [List.length_cons, List.flatten_cons, List.length_append] + omega + +namespace BinaryInput + +lemma vertices_le_twice_records (x : BinaryInput) (hn : 2 ≤ x.n) (hk : 0 < x.k) + (hc : x.graph.EdgeConnected x.k) : x.n ≤ 2 * x.p := by + classical + let L : Finset (Fin x.n) := univ.image x.left + let R : Finset (Fin x.n) := univ.image x.right + have hcover : univ ⊆ L ∪ R := by + intro v _ + have hproper : ({v} : Finset (Fin x.n)) ≠ univ := by + intro he + have hcard := congrArg Finset.card he + simp only [card_singleton, card_univ, Fintype.card_fin] at hcard + omega + have hcut := hc {v} (singleton_nonempty v) hproper + obtain ⟨e, he⟩ := card_pos.mp (lt_of_lt_of_le hk hcut) + have hcross := (mem_filter.mp he).2 + change (x.left (x.edgeEquiv.symm e).1 ∈ {v} ∧ + x.right (x.edgeEquiv.symm e).1 ∉ {v}) ∨ + (x.right (x.edgeEquiv.symm e).1 ∈ {v} ∧ + x.left (x.edgeEquiv.symm e).1 ∉ {v}) at hcross + rcases hcross with h | h + · exact mem_union_left R (mem_image.mpr + ⟨(x.edgeEquiv.symm e).1, mem_univ _, mem_singleton.mp h.1⟩) + · exact mem_union_right L (mem_image.mpr + ⟨(x.edgeEquiv.symm e).1, mem_univ _, mem_singleton.mp h.1⟩) + have hL : L.card ≤ x.p := by simpa [L] using card_image_le (f := x.left) (s := univ) + have hR : R.card ≤ x.p := by simpa [R] using card_image_le (f := x.right) (s := univ) + have hcard := (card_le_card hcover).trans (card_union_le L R) + simp only [card_univ, Fintype.card_fin] at hcard + omega + +lemma records_le_encoding (x : BinaryInput) : x.p ≤ x.encode.length := by + let records := List.ofFn (fun i : Fin x.p => + CurrentKS.encodeNat (x.left i).val ++ CurrentKS.encodeNat (x.right i).val ++ + CurrentKS.encodeNat (x.multiplicity i)) + have h := record_count_le_bits records (by + intro bits hb + obtain ⟨i, rfl⟩ := List.mem_ofFn.mp hb + have h := framed_nat_length_pos (x.left i).val + simp only [List.length_append] + omega) + simp only [records, List.length_ofFn] at h + unfold encode + simp only [List.length_append] + omega + +lemma vertices_le_binary_length (x : BinaryInput) (hn : 2 ≤ x.n) (hk : 0 < x.k) + (hc : x.graph.EdgeConnected x.k) : x.n ≤ 2 * (Input.binary x).length := by + have hv := x.vertices_le_twice_records hn hk hc + have hr := x.records_le_encoding + simp only [Input.length, Input.encode, List.length_cons] + omega + +theorem reduced_size_binary_bound (x : BinaryInput) (hn : 2 ≤ x.n) (hk : 1 ≤ x.k) + (hc : x.graph.EdgeConnected x.k) : + Fintype.card x.reduced.Edge < 16 * (Input.binary x).length ^ 4 := by + have hsize := x.reduced_size (by omega) hk + have hn' := x.vertices_le_binary_length hn hk hc + calc + Fintype.card x.reduced.Edge < x.n ^ 4 := hsize + _ ≤ (2 * (Input.binary x).length) ^ 4 := Nat.pow_le_pow_left hn' 4 + _ = 16 * (Input.binary x).length ^ 4 := by norm_num [mul_pow] + +end BinaryInput +end AlgorithmicThinTrees +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/BoundaryCases.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/BoundaryCases.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e7f7c9c76891ce0a468f2de478cffd9df67ae18 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/BoundaryCases.lean @@ -0,0 +1,122 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.Specification + +namespace OAI + +/-! Boundary cases. -/ + +section + +namespace AlgorithmicThinTrees +open StrongThinTree Finset + +lemma singleton_vertex_cut (n : ℕ) (hn : n = 1) (S : Finset (Fin n)) + (hS : S.Nonempty) : S = univ := by + subst n + obtain ⟨v, hv⟩ := hS + apply eq_univ_of_forall + intro w + simpa only [Subsingleton.elim w v] using hv + +lemma one_vertex_empty_thinTree {n m : ℕ} (G : MultiGraph n m) (hn : n = 1) + (C : ℝ) (k : ℕ) : ThinTree C k G ∅ := by + refine ⟨⟨?_, ?_⟩, ?_⟩ + · intro S hS hS' + exact (hS' (singleton_vertex_cut n hn S hS)).elim + · simp + · intro S hS hS' + exact (hS' (singleton_vertex_cut n hn S hS)).elim + +lemma one_vertex_tree_unique {n m : ℕ} (G : MultiGraph n m) (hn : n = 1) + {T : Finset (Fin m)} (hT : G.SpanningTree T) : T = ∅ := by + apply eq_empty_iff_forall_notMem.mpr + intro e he + apply hT.2 e he + intro S hS hS' + exact (hS' (singleton_vertex_cut n hn S hS)).elim + +lemma one_vertex_output (C : ℝ) (x : Input) (hn : x.n = 1) : + GoodOutput C x [] := by + refine ⟨?_, fun _ => rfl⟩ + cases x with + | explicit x => + refine ⟨[], List.nodup_nil, rfl, ?_⟩ + exact one_vertex_empty_thinTree x.graph hn C x.k + | binary x => + refine ⟨[], List.nodup_nil, rfl, ?_⟩ + simpa [BinaryInput.selected] using one_vertex_empty_thinTree x.graph hn C x.k + +def emptyTreeMachine : CurrentKS.Machine where + stackCount := 2 + states := 1 + initial := 0 + inputStack := 0 + outputStack := 1 + table := [] + +lemma emptyTreeMachine_run_one (input : List Bool) : + (emptyTreeMachine.run input 1).state = none ∧ + (emptyTreeMachine.run input 1).stacks emptyTreeMachine.outputStack = [] := by + simp [CurrentKS.Machine.run, CurrentKS.Machine.step, CurrentKS.Machine.init, + emptyTreeMachine, CurrentKS.Instruction.halt, CurrentKS.StackAction.apply] + +theorem one_vertex_polynomial : + ∃ M : CurrentKS.Machine, ∃ a degree : ℕ, 0 < a ∧ + ∀ (C : ℝ) (x : Input), x.n = 1 → + let result := M.run x.encode (a * (x.length + 1) ^ degree) + result.state = none ∧ GoodOutput C x (result.stacks M.outputStack) := by + refine ⟨emptyTreeMachine, 1, 0, by decide, ?_⟩ + intro C x hn + simp only [pow_zero, Nat.mul_one] + obtain ⟨hhalt, hout⟩ := emptyTreeMachine_run_one x.encode + exact ⟨hhalt, hout ▸ one_vertex_output C x hn⟩ + +lemma ExplicitInput.treeOutput_of_thinTree (x : ExplicitInput) {C : ℝ} + {T : Finset (Fin x.m)} (hT : ThinTree C x.k x.graph T) : + TreeOutput C (.explicit x) (x.encodeEdges T.toList) := by + classical + exact ⟨T.toList, T.nodup_toList, rfl, by simpa using hT⟩ + +lemma BinaryInput.treeOutput_of_thinTree (x : BinaryInput) {C : ℝ} + {T : Finset (Fin (Fintype.card x.Edge))} (hT : ThinTree C x.k x.graph T) : + ∃ bits, TreeOutput C (.binary x) bits := by + classical + let F : Finset x.Edge := T.map x.edgeEquiv.symm.toEmbedding + have hselected : x.selected F.toList = T := by + ext e + simp [BinaryInput.selected, F] + refine ⟨x.encodeEdges F.toList, F.toList, F.nodup_toList, rfl, ?_⟩ + simpa only [hselected] using hT + +lemma companion_existence_extension + (hcomp : ∃ C : ℝ, 0 < C ∧ ∀ (k : ℕ), 1 ≤ k → ∀ (n m : ℕ), 2 ≤ n → + ∀ G : MultiGraph n m, G.EdgeConnected k → + ∃ T : Finset (Fin m), G.SpanningTree T ∧ + ∀ S : Finset (Fin n), S.Nonempty → S ≠ Finset.univ → + ((G.cut T S).card : ℝ) ≤ (C / (k : ℝ)) * (G.cut Finset.univ S).card) : + ∃ C : ℝ, 0 < C ∧ ∀ x : Input, Valid x → ∃ bits, GoodOutput C x bits := by + obtain ⟨C, hC, hcomp⟩ := hcomp + refine ⟨C, hC, ?_⟩ + intro x hx + by_cases hn : x.n = 1 + · exact ⟨[], one_vertex_output C x hn⟩ + · have wrap : ∀ bits, TreeOutput C x bits → GoodOutput C x bits := + fun bits h => ⟨h, fun h' => (hn h').elim⟩ + cases x with + | explicit x => + obtain ⟨hn', hk, hc⟩ := hx + have htwo : 2 ≤ x.n := by change x.n ≠ 1 at hn; omega + obtain ⟨T, htree, hthin⟩ := hcomp x.k hk x.n x.m htwo x.graph hc + exact ⟨_, wrap _ (x.treeOutput_of_thinTree ⟨htree, hthin⟩)⟩ + | binary x => + obtain ⟨hn', hk, hc⟩ := hx + have htwo : 2 ≤ x.n := by change x.n ≠ 1 at hn; omega + obtain ⟨T, htree, hthin⟩ := + hcomp x.k hk x.n (Fintype.card x.Edge) htwo x.graph hc + obtain ⟨bits, hb⟩ := x.treeOutput_of_thinTree ⟨htree, hthin⟩ + exact ⟨bits, wrap bits hb⟩ + +end AlgorithmicThinTrees +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/CanonicalExpansion.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/CanonicalExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..efb9fb1cfee91128d6ef3c1c6177bda5b2f21ae4 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/CanonicalExpansion.lean @@ -0,0 +1,149 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.BinaryReduction + +namespace OAI + +/-! Canonical expansion. -/ + +section + +namespace AlgorithmicThinTrees.BinaryInput +open StrongThinTree Finset + +def copies (x : BinaryInput) : List x.Edge := + (List.ofFn fun i : Fin x.p => List.ofFn fun j : Fin (x.multiplicity i) => + (⟨i,j⟩ : x.Edge)).flatten + +lemma mem_copies (x : BinaryInput) (e : x.Edge) : e ∈ x.copies := by + rcases e with ⟨i,j⟩ + apply List.mem_flatten.mpr + exact ⟨_,List.mem_ofFn.mpr ⟨i,rfl⟩,List.mem_ofFn.mpr ⟨j,rfl⟩⟩ + +lemma copies_nodup (x : BinaryInput) : x.copies.Nodup := by + rw [copies, List.nodup_flatten] + constructor + · intro l hl + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hl + exact List.nodup_ofFn.mpr (fun j k h => by cases h; rfl) + · apply List.pairwise_iff_get.mpr + intro i j hij + simp only [List.get_eq_getElem, List.getElem_ofFn] + apply List.disjoint_left.mpr + intro e he hf + obtain ⟨a,ha⟩ := List.mem_ofFn.mp he + obtain ⟨b,hb⟩ := List.mem_ofFn.mp hf + have heq := congrArg Sigma.fst (ha.trans hb.symm) + exact (ne_of_lt hij) (Fin.ext (by simpa using congrArg Fin.val heq)) + +lemma copies_length (x : BinaryInput) : x.copies.length = Fintype.card x.Edge := by + classical + have hu : x.copies.toFinset = univ := by ext e; simp [mem_copies] + rw [← List.toFinset_card_of_nodup (x.copies_nodup),hu,card_univ] + +noncomputable def copiesEquiv (x : BinaryInput) : Fin x.copies.length ≃ x.Edge := + Equiv.ofBijective x.copies.get ⟨x.copies_nodup.injective_get, + fun e => List.mem_iff_get.mp (x.mem_copies e)⟩ + +@[simp] lemma copiesEquiv_apply (x : BinaryInput) (e : Fin x.copies.length) : + x.copiesEquiv e = x.copies.get e := rfl + +def expanded (x : BinaryInput) : MultiGraph x.n x.copies.length where + left e := x.left (x.copies.get e).1 + right e := x.right (x.copies.get e).1 + loopless e := ne_of_lt (x.ordered (x.copies.get e).1) + +noncomputable def labelEquiv (x : BinaryInput) : + Fin x.copies.length ≃ Fin (Fintype.card x.Edge) := x.copiesEquiv.trans x.edgeEquiv + +@[simp] lemma labelEquiv_left (x : BinaryInput) (e : Fin x.copies.length) : + x.graph.left (x.labelEquiv e) = x.expanded.left e := by + simp [graph,labelEquiv,expanded] +@[simp] lemma labelEquiv_right (x : BinaryInput) (e : Fin x.copies.length) : + x.graph.right (x.labelEquiv e) = x.expanded.right e := by + simp [graph,labelEquiv,expanded] + +lemma expanded_cut (x : BinaryInput) (S : Finset (Fin x.n)) : + (x.expanded.cut univ S).card = (x.graph.cut univ S).card := by + classical + have hm : univ.image x.labelEquiv = univ := Finset.image_univ_of_surjective x.labelEquiv.surjective + have h := x.expanded.cut_image x.graph x.labelEquiv x.labelEquiv_left x.labelEquiv_right univ S + rw [hm] at h + rw [h,card_image_of_injective _ x.labelEquiv.injective] + +lemma expanded_edgeConnected (x : BinaryInput) {k : ℕ} + (h : x.graph.EdgeConnected k) : x.expanded.EdgeConnected k := by + intro S hS hS' + rw [x.expanded_cut] + exact h S hS hS' + +lemma expanded_thinTree (x : BinaryInput) {C : ℝ} {k : ℕ} + {T : Finset (Fin x.copies.length)} (hT : ThinTree C k x.expanded T) : + ThinTree C k x.graph (T.image x.labelEquiv) := by + refine ⟨x.expanded.spanningTree_image x.graph x.labelEquiv x.labelEquiv_left + x.labelEquiv_right hT.1, ?_⟩ + intro S hS hS' + rw [x.expanded.cut_image x.graph x.labelEquiv x.labelEquiv_left x.labelEquiv_right, + card_image_of_injective _ x.labelEquiv.injective] + simpa only [x.expanded_cut] using hT.2 S hS hS' + +def originalCopy (x : BinaryInput) (e : Fin x.reduced.copies.length) : x.Edge := + x.liftCopy (x.reduced.copies.get e) + +noncomputable def originalLabel (x : BinaryInput) (e : Fin x.reduced.copies.length) : + Fin (Fintype.card x.Edge) := x.edgeEquiv (x.originalCopy e) + +lemma originalLabel_eq (x : BinaryInput) : + x.originalLabel = x.liftLabel ∘ x.reduced.labelEquiv := by + funext e + simp [originalLabel,originalCopy,liftLabel,labelEquiv] + +lemma expanded_lift_thinTree (x : BinaryInput) (hn : 0 < x.n) (hk : 0 < x.k) + {C : ℝ} (hC : 0 ≤ C) {T : Finset (Fin x.reduced.copies.length)} + (hT : ThinTree C (x.n^2) x.reduced.expanded T) : + ThinTree (2*C) x.k x.graph (T.image x.originalLabel) := by + have h := x.lift_thinTree hn hk hC (x.reduced.expanded_thinTree hT) + simpa only [Finset.image_image,←originalLabel_eq] using h + +lemma originalCopy_injOn (x : BinaryInput) (hn : 0 < x.n) + {T : Finset (Fin x.reduced.copies.length)} (hT : x.reduced.expanded.SpanningTree T) : + Set.InjOn x.originalCopy T := by + classical + have hl (e) : x.graph.left (x.originalLabel e) = x.reduced.expanded.left e := by + simp [originalLabel,originalCopy,graph,liftCopy,expanded] + have hr (e) : x.graph.right (x.originalLabel e) = x.reduced.expanded.right e := by + simp [originalLabel,originalCopy,graph,liftCopy,expanded] + have ht := x.reduced.expanded.spanningTree_image x.graph x.originalLabel hl hr hT + have hi : Set.InjOn x.originalLabel T := Finset.card_image_iff.mp (by + rw [x.graph.spanningTree_card hn ht,x.reduced.expanded.spanningTree_card hn hT]) + intro e he f hf heq + exact hi he hf (congrArg x.edgeEquiv heq) + +lemma copies_map (x : BinaryInput) {α : Type*} (f : Fin x.p → α) : + x.copies.map (fun e => f e.1) = + (List.ofFn fun i : Fin x.p => List.replicate (x.multiplicity i) (f i)).flatten := by + simp only [copies,List.map_flatten,List.map_ofFn,Function.comp_def] + simp + +lemma expanded_lefts (x : BinaryInput) : + List.ofFn (fun e => (x.expanded.left e).val) = + (List.ofFn fun i : Fin x.p => List.replicate (x.multiplicity i) (x.left i).val).flatten := by + rw [←copies_map] + simpa only [List.map_ofFn,Function.comp_def,expanded] using + congrArg (List.map (fun e : x.Edge => (x.left e.1).val)) (List.ofFn_get x.copies) +lemma expanded_rights (x : BinaryInput) : + List.ofFn (fun e => (x.expanded.right e).val) = + (List.ofFn fun i : Fin x.p => List.replicate (x.multiplicity i) (x.right i).val).flatten := by + rw [←copies_map] + simpa only [List.map_ofFn,Function.comp_def,expanded] using + congrArg (List.map (fun e : x.Edge => (x.right e.1).val)) (List.ofFn_get x.copies) +lemma expanded_records (x : BinaryInput) : + List.ofFn (fun e : Fin x.copies.length => (x.copies.get e).1.val) = + (List.ofFn fun i : Fin x.p => List.replicate (x.multiplicity i) i.val).flatten := by + rw [←copies_map] + simpa only [List.map_ofFn,Function.comp_def,expanded] using + congrArg (List.map (fun e : x.Edge => e.1.val)) (List.ofFn_get x.copies) + +end AlgorithmicThinTrees.BinaryInput +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/GraphRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/GraphRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..15edc474e47af91d7d424b0d447323fdc6c1cedf --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/GraphRealization.lean @@ -0,0 +1,205 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialFaceChoice +import OAI.Combinatorics.ThinTrees.Arithmetic.UnaryArithmetic +import OAI.Combinatorics.ThinTrees.Continuation.Iteration + +namespace OAI + +/-! Graph realization. -/ + +section + +namespace AlgorithmicThinTrees.GraphStack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree +open AlgorithmicThinTrees.MetricTests.RationalStep +open scoped BigOperators + +structure Graph where + n : ℕ + m : ℕ + G : MultiGraph n m + +abbrev graphDataCode := prodCode natCode (prodCode indicesCode indicesCode) +def Graph.data (a : Graph) := + (a.n,(List.ofFn (fun e => (a.G.left e).val),List.ofFn (fun e => (a.G.right e).val))) +def graphCode (a : Graph) : Word := graphDataCode a.data +abbrev view : Realizes graphCode graphDataCode Graph.data := + (identity graphDataCode).reindex graphCode Graph.data (fun _ => rfl) +private instance poly_view : PolyTime view := by + unfold view + apply poly_reindex + +abbrev numVertices := view.then (first natCode (prodCode indicesCode indicesCode)) +abbrev endpoints := view.then (second natCode (prodCode indicesCode indicesCode)) +abbrev lefts := endpoints.then (first indicesCode indicesCode) +abbrev rights := endpoints.then (second indicesCode indicesCode) +def numEdges : Realizes graphCode natCode Graph.m := + (lefts.then (lengthList natCode)).congr (fun _a => List.length_ofFn) +instance poly_numEdges : PolyTime numEdges := by unfold numEdges;apply poly_congr + +abbrev Edge := Σ a : Graph, Fin a.m +abbrev edgeCode := finFamilyCode graphCode Graph.m +abbrev edgeGraph : Realizes edgeCode graphCode (fun a : Edge => a.1) := familyFirst +abbrev edgeIndex : Realizes edgeCode natCode (fun a : Edge => a.2.val) := familyIndex + +def edgeLeft : Realizes edgeCode natCode (fun a : Edge => (a.1.G.left a.2).val) := + ((edgeIndex.both (edgeGraph.then lefts)).then (getD natCode 0)).congr + (fun a => getD_ofFn _ a.2 0) +def edgeRight : Realizes edgeCode natCode (fun a : Edge => (a.1.G.right a.2).val) := + ((edgeIndex.both (edgeGraph.then rights)).then (getD natCode 0)).congr + (fun a => getD_ofFn _ a.2 0) +instance poly_edgeLeft : PolyTime edgeLeft := by unfold edgeLeft;apply poly_congr +instance poly_edgeRight : PolyTime edgeRight := by unfold edgeRight;apply poly_congr + +def incidence : Realizes edgeCode vectorCode + (fun a => List.ofFn (qdiff (a.1.G.left a.2) (a.1.G.right a.2))) := + let n := edgeGraph.then numVertices + ((((n.both edgeLeft).then basisVector).both ((n.both edgeRight).then basisVector)).then + vectorSub).congr (by + intro a + change zipDefault (fun p : ℚ×ℚ => p.1-p.2) 0 0 + (basisData (a.1.n,(a.1.G.left a.2).val), + basisData (a.1.n,(a.1.G.right a.2).val)) = _ + simp only [basis_data] + rw [vectorSub_data] + rfl) +instance poly_incidence : PolyTime incidence := by unfold incidence;infer_instance + +def incidenceRows : Realizes graphCode matrixCode + (fun a => matrixData (fun e => qdiff (a.G.left e) (a.G.right e))) := + incidence.tabulateFin numEdges +instance poly_incidenceRows : PolyTime incidenceRows := by unfold incidenceRows;apply poly_tabulateFin + +def laplacian : Realizes graphCode matrixCode (fun a => matrixData (qlap a.G)) := + let ones := ((constant graphCode ratCode 1).both numEdges).then (replicateList ratCode) + let atoms := incidenceRows.then Normalization.Stack.outer.map + (numVertices.both (ones.both atoms)).then weightedSum |>.congr (by + intro a + change weightedSumData (a.n,(List.replicate a.m (1:ℚ), + (List.ofFn (fun e => List.ofFn (qdiff (a.G.left e) (a.G.right e)))).map _))=_ + rw [← List.ofFn_const (n:=a.m) (1:ℚ)] + simp only [List.map_ofFn,Function.comp_def] + change weightedSumData (a.n,(List.ofFn (fun _ : Fin a.m => (1:ℚ)), + List.ofFn (fun e => matrixData (vecMulVec (qdiff (a.G.left e) (a.G.right e)) + (qdiff (a.G.left e) (a.G.right e))))))=_ + rw [weightedSum_data] + simp only [one_smul,qlap]) +instance poly_laplacian : PolyTime laplacian := by unfold laplacian;apply poly_congr + +def constantMatrix : Realizes (prodCode natCode ratCode) matrixCode + (fun p => matrixData (Matrix.of (fun (_ _ : Fin p.1) => p.2))) := + let n := first natCode ratCode + let q := second natCode ratCode + ((((q.both n).then (replicateList ratCode)).both n).then + (replicateList vectorCode)).congr (fun p => by + change List.replicate p.1 (List.replicate p.1 p.2)= + List.ofFn (fun _ : Fin p.1 => List.ofFn (fun _ : Fin p.1 => p.2)) + simp) +instance poly_constantMatrix : PolyTime constantMatrix := by unfold constantMatrix;infer_instance + +def projection : Realizes natCode matrixCode (fun n => matrixData (qproject n)) := + let inv := (constant natCode ratCode 1).div natToRat + ((identityMatrix.both (((identity natCode).both inv).then constantMatrix)).then + matrixSub).congr (by + intro n + rw [identityMatrix_data,matrixSub_data] + simp only [one_div] + rfl) +instance poly_projection : PolyTime projection := by unfold projection;infer_instance + +def response : Realizes matrixObjectCode matrixCode (fun a => matrixData (qresponse a.2)) := + let P := matrixDim.then projection + let A := matrixEntries + let symm := (constant matrixObjectCode ratCode (1/2)).scaleMatrix + ((A.both (A.then transposeMatrix)).then matrixAdd) + ((P.both symm).then matrixMul).both P |>.then matrixMul |>.congr (by + intro a + rw [transpose_data] + change matrixMulData (matrixMulData (matrixData (qproject a.1), + matrixScaleData (1/2,matrixAddData (matrixData a.2,matrixData a.2.transpose))), + matrixData (qproject a.1))=_ + unfold matrixAddData matrixScaleData + rw [matrixAdd_data,matrixScale_data,matrixMul_data,matrixMul_data] + rfl) +instance poly_response : PolyTime response := by unfold response;infer_instance + +end AlgorithmicThinTrees.GraphStack + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix +open scoped BigOperators + +lemma matIndex_val {n m : ℕ} (i j : Fin n) : (matIndex (m:=m) i j).val=j.val+n*i.val := rfl +lemma mulIndex_val {n m : ℕ} (i j k : Fin n) : + (mulIndex (m:=m) (i,j,k)).val=n*n+(k.val+n*j.val+n*n*i.val) := rfl +lemma edgeIndex_val {n m : ℕ} (p : Fin 3) (e : Fin m) : + (edgeIndex (n:=n) p e).val=n*n+(n*(n*n)+(e.val+m*p.val)) := rfl +lemma flowIndex_val {n m : ℕ} (p : Fin 2) (r : Fin n) (e : Fin m) : + (flowIndex p r e).val=n*n+(n*(n*n)+(3*m+(e.val+m*r.val+n*m*p.val))) := rfl + +abbrev dimsCode := prodCode natCode natCode +abbrev variablesCode := prodCode dimsCode vectorCode +abbrev variablesDims := first dimsCode vectorCode +abbrev variablesN := variablesDims.then (first natCode natCode) +abbrev variablesM := variablesDims.then (second natCode natCode) +abbrev variableValues := second dimsCode vectorCode + +def dimensionProgram : Realizes dimsCode natCode (fun p => dimension p.1 p.2) := + let n := first natCode natCode + let m := second natCode natCode + (n.nmul n).nadd ((n.nmul (n.nmul n)).nadd + (((constant dimsCode natCode 3).nmul m).nadd + ((constant dimsCode natCode 2).nmul (n.nmul m)))) +instance poly_dimensionProgram : PolyTime dimensionProgram := by + unfold dimensionProgram Realizes.nadd + apply poly_then + +abbrev varEntryCode := prodCode (prodCode variablesCode natCode) natCode +abbrev varEntryContext := first (prodCode variablesCode natCode) natCode +abbrev varEntryVars := varEntryContext.then (first variablesCode natCode) +abbrev varEntryI := varEntryContext.then (second variablesCode natCode) +abbrev varEntryJ := second (prodCode variablesCode natCode) natCode + +def rawEntry : Realizes varEntryCode ratCode + (fun a => a.1.1.2.getD (a.2+a.1.1.1.1*a.1.2) 0) := + ((varEntryJ.nadd ((varEntryVars.then variablesN).nmul varEntryI)).both + (varEntryVars.then variableValues)).then (getD ratCode 0) +instance poly_rawEntry : PolyTime rawEntry := by unfold rawEntry;infer_instance + +def raw : Realizes variablesCode matrixCode + (fun p => (List.range p.1.1).map (fun i => + (List.range p.1.1).map (fun j => p.2.getD (j+p.1.1*i) 0))) := + (((identity variablesCode).both variablesN).both variablesN).then rawEntry.matrixTabulate +instance poly_raw : PolyTime raw := by unfold raw;infer_instance + +lemma raw_data {n m : ℕ} (v : Fin (dimension n m) → ℚ) : + (List.range n).map (fun i => (List.range n).map + (fun j => (List.ofFn v).getD (j+n*i) 0))=matrixData (rawMatrix v) := by + simp only [range_map_fin,matrixData] + apply congrArg List.ofFn + funext i + apply congrArg List.ofFn + funext j + rw [←matIndex_val i j,getD_ofFn] + rfl + +def edgeVariable (p : ℕ) : Realizes (prodCode variablesCode natCode) ratCode + (fun a => a.1.2.getD (a.1.1.1*a.1.1.1+(a.1.1.1*(a.1.1.1*a.1.1.1)+ + (a.2+a.1.1.2*p))) 0) := + let c := first variablesCode natCode + let n := c.then variablesN + let m := c.then variablesM + let e := second variablesCode natCode + let idx := (n.nmul n).nadd ((n.nmul (n.nmul n)).nadd + (e.nadd (m.nmul (constant _ natCode p)))) + (idx.both (c.then variableValues)).then (getD ratCode 0) +instance poly_edgeVariable (p : ℕ) : PolyTime (edgeVariable p) := by unfold edgeVariable;infer_instance + +lemma edgeVariable_data {n m : ℕ} (v : Fin (dimension n m) → ℚ) (p : Fin 3) (e : Fin m) : + (List.ofFn v).getD (n*n+(n*(n*n)+(e.val+m*p.val))) 0=v (edgeIndex p e) := by + rw [←edgeIndex_val p e,getD_ofFn] + +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/GreedyRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/GreedyRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..40449837bae31a880970e768ddf271846655a5cf --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/GreedyRealization.lean @@ -0,0 +1,310 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Arithmetic.BoolPrograms +import OAI.Combinatorics.ThinTrees.Continuation.BitBound +import OAI.Combinatorics.ThinTrees.Encoding.GreedyTree +import OAI.Combinatorics.ThinTrees.Sparsification.Realization + +namespace OAI + +/-! Greedy realization. -/ + +section + +namespace AlgorithmicThinTrees.GreedyTree.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Finset StrongThinTree +open GraphStack +local notation "X" => NaturalPolynomial.variable + +structure Subgraph where + graph : Graph + A : Finset (Fin graph.m) + +def Subgraph.bits (s : Subgraph) := List.ofFn (fun e => decide (e ∈ s.A)) +def subgraphCode (s : Subgraph) : Word := prodCode graphCode boolsCode (s.graph,s.bits) +abbrev subgraphView : Realizes subgraphCode (prodCode graphCode boolsCode) (fun s => (s.graph,s.bits)) := + (identity (prodCode graphCode boolsCode)).reindex subgraphCode (fun s => (s.graph,s.bits)) (fun _ => rfl) +private instance poly_subgraphView : PolyTime subgraphView := by + unfold subgraphView + apply poly_reindex + +abbrev subgraphGraph := subgraphView.then (first graphCode boolsCode) +abbrev subgraphBits := subgraphView.then (second graphCode boolsCode) +abbrev subgraphN : Realizes subgraphCode natCode (fun s => s.graph.n) := subgraphGraph.then numVertices +private instance poly_subgraphN : PolyTime subgraphN := by + unfold subgraphN + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · infer_instance + · unfold numVertices + apply poly_then + +abbrev subgraphM : Realizes subgraphCode natCode (fun s => s.graph.m) := subgraphGraph.then numEdges + +lemma subgraph_length (s : Subgraph) : + (subgraphCode s).length=2*(graphCode s.graph).length+1+3*s.graph.m := by + simp only [subgraphCode,prodCode_length,Subgraph.bits,bools_ofFn_length] + +abbrev SEdge := Σ s : Subgraph, Fin s.graph.m +abbrev sedgeCode := finFamilyCode subgraphCode (fun s : Subgraph => s.graph.m) +abbrev sedgeContext : Realizes sedgeCode subgraphCode (fun s : SEdge => s.1) := familyFirst +abbrev sedgeIndex : Realizes sedgeCode natCode (fun s : SEdge => s.2.val) := familyIndex + +def selected : Realizes sedgeCode boolCode (fun s => decide (s.2 ∈ s.1.A)) := + ((sedgeIndex.both (sedgeContext.then subgraphBits)).then (getD boolCode false)).congr + (fun s => getD_ofFn _ s.2 false) +instance poly_selected : PolyTime selected := by unfold selected; apply poly_congr + +structure ReachState where + subgraph : Subgraph + U : Finset (Fin subgraph.graph.n) + +def ReachState.bits (s : ReachState) := List.ofFn (fun v => decide (v ∈ s.U)) +def reachCode (s : ReachState) : Word := prodCode subgraphCode boolsCode (s.subgraph,s.bits) +abbrev reachView : Realizes reachCode (prodCode subgraphCode boolsCode) (fun s => (s.subgraph,s.bits)) := + (identity (prodCode subgraphCode boolsCode)).reindex reachCode (fun s => (s.subgraph,s.bits)) (fun _ => rfl) +private instance poly_reachView : PolyTime reachView := by + unfold reachView + apply poly_reindex + +abbrev reachSubgraph := reachView.then (first subgraphCode boolsCode) +abbrev reachBits := reachView.then (second subgraphCode boolsCode) +abbrev reachN : Realizes reachCode natCode (fun s => s.subgraph.graph.n) := reachSubgraph.then subgraphN +private instance poly_reachN : PolyTime reachN := by + unfold reachN + apply poly_then + +abbrev reachM : Realizes reachCode natCode (fun s => s.subgraph.graph.m) := reachSubgraph.then subgraphM +abbrev Vertex := Σ s : ReachState, Fin s.subgraph.graph.n +abbrev vertexCode := finFamilyCode reachCode (fun s : ReachState => s.subgraph.graph.n) +abbrev vertexContext : Realizes vertexCode reachCode (fun v : Vertex => v.1) := familyFirst +abbrev vertexIndex : Realizes vertexCode natCode (fun v : Vertex => v.2.val) := familyIndex + +def reached : Realizes vertexCode boolCode (fun v => decide (v.2 ∈ v.1.U)) := + ((vertexIndex.both (vertexContext.then reachBits)).then (getD boolCode false)).congr + (fun v => getD_ofFn _ v.2 false) +instance poly_reached : PolyTime reached := by unfold reached; apply poly_congr + +abbrev Arc := Σ v : Vertex, Fin v.1.subgraph.graph.m +abbrev arcCode := finFamilyCode vertexCode (fun v : Vertex => v.1.subgraph.graph.m) +abbrev arcVertex : Realizes arcCode vertexCode (fun a : Arc => a.1) := familyFirst +abbrev arcNumber : Realizes arcCode natCode (fun a : Arc => a.2.val) := familyIndex +abbrev arcState := arcVertex.then vertexContext + +def arcSubedge : Realizes arcCode sedgeCode (fun a => ⟨a.1.1.subgraph,a.2⟩) := + ((arcState.then reachSubgraph).both arcNumber).changeOutput sedgeCode + (fun a => ⟨a.1.1.subgraph,a.2⟩) (fun _ => rfl) +instance poly_arcSubedge : PolyTime arcSubedge := by unfold arcSubedge; apply poly_changeOutput + +def arcEdge : Realizes arcCode GraphStack.edgeCode (fun a => ⟨a.1.1.subgraph.graph,a.2⟩) := + ((arcState.then reachSubgraph |>.then subgraphGraph).both arcNumber).changeOutput + GraphStack.edgeCode (fun a => ⟨a.1.1.subgraph.graph,a.2⟩) (fun _ => rfl) +instance poly_arcEdge : PolyTime arcEdge := by unfold arcEdge; apply poly_changeOutput +abbrev arcLeft := arcEdge.then edgeLeft +abbrev arcRight := arcEdge.then edgeRight + +def leftReached : Realizes arcCode boolCode + (fun a => decide (a.1.1.subgraph.graph.G.left a.2 ∈ a.1.1.U)) := + ((arcLeft.both (arcState.then reachBits)).then (getD boolCode false)).congr + (fun a => getD_ofFn _ (a.1.1.subgraph.graph.G.left a.2) false) +def rightReached : Realizes arcCode boolCode + (fun a => decide (a.1.1.subgraph.graph.G.right a.2 ∈ a.1.1.U)) := + ((arcRight.both (arcState.then reachBits)).then (getD boolCode false)).congr + (fun a => getD_ofFn _ (a.1.1.subgraph.graph.G.right a.2) false) +instance poly_leftReached : PolyTime leftReached := by unfold leftReached; apply poly_congr +instance poly_rightReached : PolyTime rightReached := by unfold rightReached; apply poly_congr + +def incident : Realizes arcCode boolCode (fun a => decide + (a.2 ∈ a.1.1.subgraph.A ∧ + ((a.1.1.subgraph.graph.G.left a.2=a.1.2 ∧ a.1.1.subgraph.graph.G.right a.2 ∈ a.1.1.U) ∨ + (a.1.1.subgraph.graph.G.right a.2=a.1.2 ∧ a.1.1.subgraph.graph.G.left a.2 ∈ a.1.1.U)))) := + (arcSubedge.then selected).and + (((arcLeft.finEq (arcVertex.then vertexIndex)).and rightReached).or + ((arcRight.finEq (arcVertex.then vertexIndex)).and leftReached)) +instance poly_incident : PolyTime incident := by unfold incident;infer_instance + +def expands : Realizes vertexCode boolCode + (fun v => decide (v.2 ∈ expand v.1.subgraph.graph.G v.1.subgraph.A v.1.U)) := + (reached.or (incident.existsFin (P:=fun a e => e ∈ a.1.subgraph.A ∧ + ((a.1.subgraph.graph.G.left e=a.2 ∧ a.1.subgraph.graph.G.right e ∈ a.1.U) ∨ + (a.1.subgraph.graph.G.right e=a.2 ∧ a.1.subgraph.graph.G.left e ∈ a.1.U))) + (vertexContext.then reachM))).congr (by + intro v + congr 1 + apply propext + simp only [expand,mem_union,mem_image,mem_filter] + constructor + · rintro (h|⟨e,he,h|h⟩) + · exact Or.inl (Or.inl h) + · exact Or.inl (Or.inr ⟨e,⟨he,h.2⟩,h.1⟩) + · exact Or.inr ⟨e,⟨he,h.2⟩,h.1⟩ + · rintro ((h|⟨e,⟨he,hu⟩,hv⟩)|⟨e,⟨he,hu⟩,hv⟩) + · exact Or.inl h + · exact Or.inr ⟨e,he,Or.inl ⟨hv,hu⟩⟩ + · exact Or.inr ⟨e,he,Or.inr ⟨hv,hu⟩⟩) +instance poly_expands : PolyTime expands := by unfold expands; apply poly_congr + +def ReachState.next (s : ReachState) : ReachState := + ⟨s.subgraph,expand s.subgraph.graph.G s.subgraph.A s.U⟩ +def next : Realizes reachCode reachCode ReachState.next := + (reachSubgraph.both (expands.tabulateFin reachN)).changeOutput reachCode ReachState.next (fun _ => rfl) +instance poly_next : PolyTime next := by unfold next; apply poly_changeOutput + +lemma next_length (s : ReachState) : (reachCode s.next).length=(reachCode s).length := by + simp only [reachCode,prodCode_length,ReachState.bits,bools_ofFn_length] + rfl +instance size_next : IterateSize next := by + refine ⟨⟨X,?_⟩⟩ + intro s k + have he : (reachCode (ReachState.next^[k] s)).length=(reachCode s).length := by + induction k with + | zero => rfl + | succ k ih => rw [Function.iterate_succ_apply',next_length,ih] + change (reachCode (ReachState.next^[k] s)).length ≤ (reachCode s).length+k + rw [he];omega + +abbrev InitVertex := Σ s : Subgraph, Fin s.graph.n +abbrev initVertexCode := finFamilyCode subgraphCode (fun s : Subgraph => s.graph.n) +def initBit : Realizes initVertexCode boolCode (fun p => decide (p.2.val=0)) := + (familyIndex.neq (constant initVertexCode natCode 0)) +instance poly_initBit : PolyTime initBit := by unfold initBit;infer_instance + +def Subgraph.start (s : Subgraph) : ReachState := ⟨s,univ.filter (fun v => v.val=0)⟩ +def start : Realizes subgraphCode reachCode Subgraph.start := + ((identity subgraphCode).both (initBit.tabulateFin subgraphN)).changeOutput reachCode Subgraph.start (by + intro s + change prodCode subgraphCode boolsCode (s,List.ofFn (fun v : Fin s.graph.n => decide (v.val=0)))=_ + simp +instances only [reachCode,Subgraph.start,ReachState.bits,mem_filter,mem_univ,true_and]) +instance poly_start : PolyTime start := by unfold start; apply poly_changeOutput + +def Walk (s : Subgraph) : ReachState := ReachState.next^[s.graph.n] s.start +def walk : Realizes subgraphCode reachCode Walk := (subgraphN.both start).then next.iterate +instance poly_walk : PolyTime walk := by unfold walk; apply poly_then + +def reachedAll : Realizes reachCode boolCode (fun s => decide (s.U=univ)) := + (reached.forallFin (P:=fun s v => v ∈ s.U) reachN).congr (by intro s;simp only [Finset.eq_univ_iff_forall]) +instance poly_reachedAll : PolyTime reachedAll := by unfold reachedAll; apply poly_congr + +lemma walk_eq (s : Subgraph) : Walk s = + ⟨s,(expand s.graph.G s.A)^[s.graph.n] (univ.filter (fun v => v.val=0))⟩ := by + have he (k : ℕ) : ReachState.next^[k] s.start = + ⟨s,(expand s.graph.G s.A)^[k] (univ.filter (fun v => v.val=0))⟩ := by + induction k with + | zero => rfl + | succ k ih => rw [Function.iterate_succ_apply',ih,Function.iterate_succ_apply'];rfl + exact he _ + +lemma walk_connected (s : Subgraph) : ((Walk s).U=univ) ↔ s.graph.G.Connected s.A := by + rw [walk_eq] + dsimp only + by_cases hn : 0 < s.graph.n + · let root : Fin s.graph.n := ⟨0,hn⟩ + have he : (univ.filter (fun v : Fin s.graph.n => v.val=0))={root} := by + ext v;simp [Fin.ext_iff,root] + rw [he] + exact (connected_iff_reach s.graph.G s.A root).symm + · have hn0 : s.graph.n=0 := by omega + constructor + · intro _ S hS hS' + obtain ⟨v,_⟩ := hS + exact (Nat.not_lt_zero v.val (hn0 ▸ v.isLt)).elim + · intro _ + apply eq_univ_iff_forall.mpr + intro v + exact (Nat.not_lt_zero v.val (hn0 ▸ v.isLt)).elim + +def connectedProgram : Realizes subgraphCode boolCode (fun s => connected s.graph.G s.A) := + (walk.then reachedAll).congr (by + intro s + apply Bool.eq_iff_iff.mpr + simpa only [decide_eq_true_eq,connected_correct] using walk_connected s) +instance poly_connectedProgram : PolyTime connectedProgram := by unfold connectedProgram;infer_instance + +abbrev EraseInput := Subgraph × ℕ +abbrev eraseInputCode := prodCode subgraphCode natCode +abbrev eraseContext := first subgraphCode natCode +abbrev eraseIndex := second subgraphCode natCode +abbrev EraseEdge := Σ p : EraseInput, Fin p.1.graph.m +abbrev eraseEdgeCode := finFamilyCode eraseInputCode (fun p : EraseInput => p.1.graph.m) +abbrev eraseEdgeContext : Realizes eraseEdgeCode eraseInputCode (fun p : EraseEdge => p.1) := familyFirst +abbrev eraseEdgeIndex : Realizes eraseEdgeCode natCode (fun p : EraseEdge => p.2.val) := familyIndex + +def eraseSubedge : Realizes eraseEdgeCode sedgeCode (fun p => ⟨p.1.1,p.2⟩) := + ((eraseEdgeContext.then eraseContext).both eraseEdgeIndex).changeOutput sedgeCode + (fun p => ⟨p.1.1,p.2⟩) (fun _ => rfl) +instance poly_eraseSubedge : PolyTime eraseSubedge := by unfold eraseSubedge; apply poly_changeOutput + +def eraseBit : Realizes eraseEdgeCode boolCode + (fun p => decide (p.2 ∈ p.1.1.A ∧ p.2.val ≠ p.1.2)) := + (eraseSubedge.then selected).and ((eraseEdgeIndex.neq (eraseEdgeContext.then eraseIndex)).not) +instance poly_eraseBit : PolyTime eraseBit := by unfold eraseBit;infer_instance + +def erase (p : EraseInput) : Subgraph := ⟨p.1.graph,p.1.A.filter (fun e => e.val ≠ p.2)⟩ +def eraseProgram : Realizes eraseInputCode subgraphCode erase := + ((eraseContext.then subgraphGraph).both + (eraseBit.tabulateFin (eraseContext.then subgraphM))).changeOutput subgraphCode erase (by + intro p + simp +instances only [subgraphCode,Subgraph.bits,erase,mem_filter]) +instance poly_eraseProgram : PolyTime eraseProgram := by unfold eraseProgram;infer_instance + +def deleteAt (p : EraseInput) : Subgraph := + if connected (erase p).graph.G (erase p).A then erase p else p.1 + +def deleteProgram : Realizes eraseInputCode subgraphCode deleteAt := + (eraseProgram.then connectedProgram).ite eraseProgram eraseContext +instance poly_deleteProgram : PolyTime deleteProgram := by unfold deleteProgram; apply poly_ite + +lemma deleteAt_graph (s : Subgraph) (i : ℕ) : (deleteAt (s,i)).graph=s.graph := by + unfold deleteAt;split_ifs <;> rfl +lemma folded_graph (s : Subgraph) (xs : List ℕ) : + (xs.foldl (fun s i => deleteAt (s,i)) s).graph=s.graph := by + induction xs generalizing s with + | nil => rfl + | cons i xs ih => rw [List.foldl_cons,ih,deleteAt_graph] + +instance size_deleteProgram : FoldSize deleteProgram := by + refine ⟨⟨X,?_⟩⟩ + intro s xs ys zs he + change (subgraphCode (ys.foldl (fun s i => deleteAt (s,i)) s)).length≤_ + rw [subgraph_length,folded_graph,←subgraph_length] + change (subgraphCode s).length ≤ (prodCode subgraphCode (listCode natCode) (s,xs)).length + exact le_prodCode_left (ea:=subgraphCode) (eb:=listCode natCode) (s,xs) + +def whole : Realizes graphCode subgraphCode (fun g => ⟨g,univ⟩) := + ((identity graphCode).both + (((constant graphCode boolCode true).both numEdges).then (replicateList boolCode))).changeOutput + subgraphCode (fun g => ⟨g,univ⟩) (by intro g;simp [subgraphCode,Subgraph.bits,List.ofFn_const]) +instance poly_whole : PolyTime whole := by unfold whole;infer_instance + +lemma deleteAt_fin (g : Graph) (A : Finset (Fin g.m)) (e : Fin g.m) : + deleteAt (⟨g,A⟩,e.val)=⟨g,eraseIf g.G A e⟩ := by + have he : erase (⟨g,A⟩,e.val)=⟨g,A.erase e⟩ := by + change (Subgraph.mk g (A.filter (fun i => i.val ≠ e.val)))=Subgraph.mk g (A.erase e) + congr 1 + ext i + simp [mem_erase,Fin.ext_iff,and_comm] + unfold deleteAt + rw [he] + change (if connected g.G (A.erase e) then Subgraph.mk g (A.erase e) else Subgraph.mk g A)=_ + unfold eraseIf + split_ifs <;> rfl + +lemma fold_deletes (g : Graph) (A : Finset (Fin g.m)) (es : List (Fin g.m)) : + (es.map Fin.val).foldl (fun s i => deleteAt (s,i)) ⟨g,A⟩=⟨g,deletePass g.G A es⟩ := by + induction es generalizing A with + | nil => rfl + | cons e es ih => + rw [List.map_cons,List.foldl_cons,deleteAt_fin,ih] + rfl + +def treeProgram : Realizes graphCode boolsCode (fun g => List.ofFn (fun e => decide (e ∈ tree g.G))) := + ((((whole.both (numEdges.then range)).then deleteProgram.fold).then subgraphBits)).congr (by + intro g + have he : List.range g.m=(List.finRange g.m).map Fin.val := by simp + change Subgraph.bits ((List.range g.m).foldl (fun s i => deleteAt (s,i)) ⟨g,univ⟩)=_ + rw [he,fold_deletes] + rfl) +instance poly_treeProgram : PolyTime treeProgram := by unfold treeProgram; apply poly_congr + +end AlgorithmicThinTrees.GreedyTree.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/GreedyTree.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/GreedyTree.lean new file mode 100644 index 0000000000000000000000000000000000000000..57a2c48324a212a73e9461da6dfb403b1dcac1b2 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/GreedyTree.lean @@ -0,0 +1,171 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Signing.Realization + +namespace OAI + +/-! Greedy tree. -/ + +section + +namespace AlgorithmicThinTrees.GreedyTree +open Finset StrongThinTree StrongThinTree.MultiGraph +variable {n m : ℕ} + +def expand (G : MultiGraph n m) (A : Finset (Fin m)) (U : Finset (Fin n)) : + Finset (Fin n) := + U ∪ (A.filter (fun e => G.right e ∈ U)).image G.left ∪ + (A.filter (fun e => G.left e ∈ U)).image G.right + +def reach (G : MultiGraph n m) (A : Finset (Fin m)) (root : Fin n) (t : ℕ) : Finset (Fin n) := + (expand G A)^[t] {root} + +lemma subset_expand (G : MultiGraph n m) (A : Finset (Fin m)) (U : Finset (Fin n)) : + U ⊆ expand G A U := (subset_union_left).trans subset_union_left + +lemma reach_succ (G : MultiGraph n m) (A : Finset (Fin m)) (root : Fin n) (t : ℕ) : + reach G A root (t+1)=expand G A (reach G A root t) := Function.iterate_succ_apply' _ _ _ + +lemma reach_mono (G : MultiGraph n m) (A : Finset (Fin m)) (root : Fin n) : + Monotone (reach G A root) := + monotone_nat_of_le_succ (fun t => (reach_succ G A root t).symm ▸ subset_expand G A _) + +lemma reach_root (G : MultiGraph n m) (A : Finset (Fin m)) (root : Fin n) (t : ℕ) : + root ∈ reach G A root t := reach_mono G A root (Nat.zero_le t) (mem_singleton_self root) + +lemma expand_strict (G : MultiGraph n m) (A : Finset (Fin m)) (hc : G.Connected A) + (U : Finset (Fin n)) (hu : U.Nonempty) (hu' : U ≠ univ) : U ⊂ expand G A U := by + obtain ⟨e,he⟩ := hc U hu hu' + obtain ⟨hea,hcut⟩ := mem_filter.mp he + apply ssubset_iff_subset_ne.mpr + refine ⟨subset_expand G A U,?_⟩ + intro heq + rcases hcut with ⟨hl,hr⟩ | ⟨hr,hl⟩ + · apply hr + rw [heq] + exact mem_union_right _ (mem_image.mpr ⟨e,mem_filter.mpr ⟨hea,hl⟩,rfl⟩) + · apply hl + rw [heq] + exact mem_union_left _ (mem_union_right _ (mem_image.mpr ⟨e,mem_filter.mpr ⟨hea,hr⟩,rfl⟩)) + +lemma reach_full (G : MultiGraph n m) (A : Finset (Fin m)) (root : Fin n) + (hc : G.Connected A) : reach G A root n=univ := by + by_contra hne + have hstrict (i : ℕ) (hi : i ≤ n) : reach G A root i ≠ univ := by + intro he + apply hne + exact eq_univ_iff_forall.mpr (fun v => reach_mono G A root hi (he ▸ mem_univ v)) + have hcard : ∀i, i ≤ n → i+1 ≤ (reach G A root i).card := by + intro i hi + induction i with + | zero => simp [reach] + | succ i ih => + have hj := ih (by omega) + have hs := card_lt_card (expand_strict G A hc (reach G A root i) + ⟨root,reach_root G A root i⟩ (hstrict i (by omega))) + rw [reach_succ] + omega + have hh := (hcard n le_rfl).trans (card_le_univ _) + simp only [Fintype.card_fin] at hh + omega + +lemma reach_same (G : MultiGraph n m) (A : Finset (Fin m)) (root : Fin n) (t : ℕ) : + ∀v ∈ reach G A root t, G.Same A v root := by + induction t with + | zero => + intro v hv + have he : v=root := mem_singleton.mp hv + subst v + exact G.same_refl A root + | succ t ih => + intro v hv + rw [reach_succ] at hv + rcases mem_union.mp hv with hv|hv + · rcases mem_union.mp hv with hv|hv + · exact ih v hv + · obtain ⟨e,he,rfl⟩ := mem_image.mp hv + obtain ⟨he,hu⟩ := mem_filter.mp he + exact G.same_trans (G.same_endpoints he) (ih _ hu) + · obtain ⟨e,he,rfl⟩ := mem_image.mp hv + obtain ⟨he,hu⟩ := mem_filter.mp he + exact G.same_trans (G.same_symm (G.same_endpoints he)) (ih _ hu) + +lemma connected_iff_reach (G : MultiGraph n m) (A : Finset (Fin m)) (root : Fin n) : + G.Connected A ↔ reach G A root n=univ := by + refine ⟨reach_full G A root,fun h => ?_⟩ + rw [G.connected_iff_same] + intro u v + exact G.same_trans (reach_same G A root n u (h ▸ mem_univ _)) + (G.same_symm (reach_same G A root n v (h ▸ mem_univ _))) + +def connected (G : MultiGraph n m) (A : Finset (Fin m)) : Bool := + if hn : 0 < n then decide (reach G A ⟨0,hn⟩ n=univ) else true + +lemma connected_correct (G : MultiGraph n m) (A : Finset (Fin m)) : + connected G A=true ↔ G.Connected A := by + unfold connected + split_ifs with hn + · simpa only [decide_eq_true_eq] using (connected_iff_reach G A ⟨0,hn⟩).symm + · have hzero : n=0 := by omega + subst n + simp only [true_iff] + intro S hS _ + obtain ⟨v,_⟩ := hS + exact Fin.elim0 v + +lemma connected_mono (G : MultiGraph n m) {A B : Finset (Fin m)} (h : A ⊆ B) + (hc : G.Connected A) : G.Connected B := by + intro S hS hS' + exact (hc S hS hS').mono (filter_subset_filter _ h) + +def eraseIf (G : MultiGraph n m) (A : Finset (Fin m)) (e : Fin m) : Finset (Fin m) := + if connected G (A.erase e) then A.erase e else A + +def deletePass (G : MultiGraph n m) (A : Finset (Fin m)) (es : List (Fin m)) : Finset (Fin m) := + es.foldl (eraseIf G) A + +def tree (G : MultiGraph n m) : Finset (Fin m) := deletePass G univ (List.finRange m) + +lemma eraseIf_subset (G : MultiGraph n m) (A : Finset (Fin m)) (e : Fin m) : + eraseIf G A e ⊆ A := by + unfold eraseIf + split_ifs <;> simp only [erase_subset,Subset.refl] + +lemma eraseIf_connected (G : MultiGraph n m) (A : Finset (Fin m)) (hc : G.Connected A) + (e : Fin m) : G.Connected (eraseIf G A e) := by + unfold eraseIf + split_ifs with hh + · exact (connected_correct G (A.erase e)).mp hh + · exact hc + +lemma deletePass_correct (G : MultiGraph n m) (es : List (Fin m)) + (A : Finset (Fin m)) (hc : G.Connected A) : + deletePass G A es ⊆ A ∧ G.Connected (deletePass G A es) ∧ + ∀e ∈ es, e ∈ deletePass G A es → ¬G.Connected ((deletePass G A es).erase e) := by + induction es generalizing A with + | nil => exact ⟨subset_rfl,hc,by simp⟩ + | cons e es ih => + rw [deletePass,List.foldl_cons] + change deletePass G (eraseIf G A e) es ⊆ A ∧ _ + obtain ⟨hsub,hconn,hmin⟩ := ih (eraseIf G A e) (eraseIf_connected G A hc e) + refine ⟨hsub.trans (eraseIf_subset G A e),hconn,?_⟩ + intro f hf hmem hcon + rcases List.mem_cons.mp hf with rfl|hf + · have heA : f ∈ eraseIf G A f := hsub hmem + have hbad : connected G (A.erase f)≠true := by + intro he + simp only [eraseIf,he,ite_true,mem_erase,ne_eq,not_true_eq_false,false_and] at heA + apply hbad + apply (connected_correct G (A.erase f)).mpr + exact connected_mono G (erase_subset_erase _ (hsub.trans (eraseIf_subset G A f))) hcon + · exact hmin f hf hmem hcon + +theorem tree_correct (G : MultiGraph n m) (hc : G.Connected univ) : G.SpanningTree (tree G) := by + obtain ⟨_,hconn,hmin⟩ := deletePass_correct G (List.finRange m) univ hc + refine ⟨hconn,?_⟩ + intro e he + exact hmin e (List.mem_finRange _) he + +end AlgorithmicThinTrees.GreedyTree +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/InputArrays.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/InputArrays.lean new file mode 100644 index 0000000000000000000000000000000000000000..f03914459cd7818f39f1e227cb7e9c9e24fa4ce2 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/InputArrays.lean @@ -0,0 +1,221 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.BinaryReduction + +namespace OAI + +/-! Input arrays. -/ + +section + +namespace AlgorithmicThinTrees.InputStack +open StrongThinTree Finset CurrentKS CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 +open GraphicHalf.Stack + +abbrev E := {x : ExplicitInput // 2 ≤ x.n ∧ 1 ≤ x.k ∧ x.graph.EdgeConnected x.k} +abbrev B := {x : BinaryInput // 2 ≤ x.n ∧ 1 ≤ x.k ∧ x.graph.EdgeConnected x.k} +abbrev eCode (x : E) : Word := x.val.encode +abbrev bCode (x : B) : Word := x.val.encode +abbrev fieldsCode := listCode binaryNatCode + +def eFields (x : ExplicitInput) : List ℕ := + [x.n,x.m,x.k] ++ (List.ofFn fun i => [(x.graph.left i).val,(x.graph.right i).val]).flatten +def bFields (x : BinaryInput) : List ℕ := + [x.n,x.p,x.k] ++ (List.ofFn fun i => [(x.left i).val,(x.right i).val,x.multiplicity i]).flatten + +lemma fieldsCode_flatten (rows : List (List ℕ)) : + fieldsCode rows.flatten = (rows.map fieldsCode).flatten := by + induction rows with + | nil => rfl + | cons row rows ih => + change listCode binaryNatCode (row ++ rows.flatten) = + fieldsCode row ++ (rows.map fieldsCode).flatten + rw [listCode_append] + exact congrArg (List.append (fieldsCode row)) ih + +lemma eFields_code (x : ExplicitInput) : fieldsCode (eFields x) = x.encode := by + simp only [eFields,listCode_append,listCode_cons,listCode_nil,prodCode,PairRoutine.pair, + fieldsCode_flatten,List.map_ofFn,Function.comp_def] + simp [binaryNatCode,ExplicitInput.encode, + CurrentKS.DenseInputMachine.encodeNat_eq,KS.W01.encodeNat,List.append_assoc] +lemma bFields_code (x : BinaryInput) : fieldsCode (bFields x) = x.encode := by + simp only [bFields,listCode_append,listCode_cons,listCode_nil,prodCode,PairRoutine.pair, + fieldsCode_flatten,List.map_ofFn,Function.comp_def] + simp [binaryNatCode,BinaryInput.encode, + CurrentKS.DenseInputMachine.encodeNat_eq,KS.W01.encodeNat,List.append_assoc] + +abbrev eView : Realizes eCode fieldsCode (fun x => eFields x.val) := + (identity fieldsCode).reindex eCode (fun x => eFields x.val) (fun x => (eFields_code x.val).symm) +abbrev bView : Realizes bCode fieldsCode (fun x => bFields x.val) := + (identity fieldsCode).reindex bCode (fun x => bFields x.val) (fun x => (bFields_code x.val).symm) + +def field (i : ℕ) : Realizes fieldsCode binaryNatCode (fun xs => xs.getD i 0) := + ((constant fieldsCode natCode i).both (identity fieldsCode)).then (getD binaryNatCode 0) +instance poly_field (i : ℕ) : PolyTime (field i) := by unfold field;infer_instance + +def eNBinary : Realizes eCode binaryNatCode (fun x => x.val.n) := + (eView.then (field 0)).congr (by intro x;rfl) +def eMBinary : Realizes eCode binaryNatCode (fun x => x.val.m) := + (eView.then (field 1)).congr (by intro x;rfl) +def eKBinary : Realizes eCode binaryNatCode (fun x => x.val.k) := + (eView.then (field 2)).congr (by intro x;rfl) +def bNBinary : Realizes bCode binaryNatCode (fun x => x.val.n) := + (bView.then (field 0)).congr (by intro x;rfl) +def bPBinary : Realizes bCode binaryNatCode (fun x => x.val.p) := + (bView.then (field 1)).congr (by intro x;rfl) +def bKBinary : Realizes bCode binaryNatCode (fun x => x.val.k) := + (bView.then (field 2)).congr (by intro x;rfl) +instance poly_eNBinary : PolyTime eNBinary := by unfold eNBinary;apply poly_congr +instance poly_eMBinary : PolyTime eMBinary := by unfold eMBinary;apply poly_congr +instance poly_eKBinary : PolyTime eKBinary := by unfold eKBinary;apply poly_congr +instance poly_bNBinary : PolyTime bNBinary := by unfold bNBinary;apply poly_congr +instance poly_bPBinary : PolyTime bPBinary := by unfold bPBinary;apply poly_congr +instance poly_bKBinary : PolyTime bKBinary := by unfold bKBinary;apply poly_congr + +lemma explicit_records_le (x : ExplicitInput) : x.m ≤ x.encode.length := by + have h := record_count_le_bits (List.ofFn fun i : Fin x.m => + CurrentKS.encodeNat (x.graph.left i).val ++ CurrentKS.encodeNat (x.graph.right i).val) (by + intro bits hb + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hb + have hh := framed_nat_length_pos (x.graph.left i).val + simp only [List.length_append];omega) + simp only [List.length_ofFn] at h + simp only [ExplicitInput.encode,List.length_append] + omega + +lemma graph_dimensions {n m k : ℕ} (G : MultiGraph n m) (hn : 2 ≤ n) (hk : 1 ≤ k) + (hc : G.EdgeConnected k) : k ≤ m ∧ n ≤ 2*m := by + classical + have hsingle (v : Fin n) : ({v} : Finset (Fin n)) ≠ univ := by + intro he + have he := congrArg Finset.card he + simp only [card_singleton,card_univ,Fintype.card_fin] at he + omega + have hcard (S : Finset (Fin n)) : (G.cut univ S).card ≤ m := by + have hh : G.cut univ S ⊆ univ := filter_subset _ _ + simpa only [card_univ,Fintype.card_fin] using card_le_card hh + refine ⟨(hc {⟨0,by omega⟩} (singleton_nonempty _) (hsingle _)).trans (hcard _),?_⟩ + have hcover : univ ⊆ univ.image G.left ∪ univ.image G.right := by + intro v _ + obtain ⟨e,he⟩ := card_pos.mp (lt_of_lt_of_le (by omega : 0 (ea a).length) f) : PolyTime (r.then binaryToNat) := by + have h := RunsPoly.of_poly r id (isPoly_self (fun a => (ea a).length)) + exact ⟨(h.then (runsPoly_binaryToNat f h.output hf)).cost⟩ + +def eN := eNBinary.then binaryToNat +def eM := eMBinary.then binaryToNat +def eK := eKBinary.then binaryToNat +def bN := bNBinary.then binaryToNat +def bP := bPBinary.then binaryToNat +instance poly_eN : PolyTime eN := by + apply poly_bounded_binary + exact ((isPoly_const _ 2).mul (isPoly_self _)).mono eN_bound +instance poly_eM : PolyTime eM := by + apply poly_bounded_binary + exact (isPoly_self _).mono eM_bound +instance poly_eK : PolyTime eK := by + apply poly_bounded_binary + exact (isPoly_self _).mono eK_bound +instance poly_bN : PolyTime bN := by + apply poly_bounded_binary + exact ((isPoly_const _ 2).mul (isPoly_self _)).mono bN_bound +instance poly_bP : PolyTime bP := by + apply poly_bounded_binary + exact (isPoly_self _).mono bP_bound + +lemma records_lookup {n w : ℕ} (a b c : ℕ) (rows : Fin n → List ℕ) + (hl : ∀i,(rows i).length=w) (i : Fin n) (j : ℕ) (hj : j x.val.m) +abbrev eeInput : Realizes eEdgeCode eCode (fun x => x.1) := familyFirst +abbrev eeIndex : Realizes eEdgeCode natCode (fun x => x.2.val) := familyIndex +abbrev bRecCode := finFamilyCode bCode (fun x : B => x.val.p) +abbrev brInput : Realizes bRecCode bCode (fun x => x.1) := familyFirst +abbrev brIndex : Realizes bRecCode natCode (fun x => x.2.val) := familyIndex + +def eEndpointBinary (right : Bool) : Realizes eEdgeCode binaryNatCode + (fun x => if right then (x.1.val.graph.right x.2).val else (x.1.val.graph.left x.2).val) := + ((((constant eEdgeCode natCode 3).nadd (eeIndex.nmul (constant eEdgeCode natCode 2))).nadd + (constant eEdgeCode natCode (if right then 1 else 0))).both (eeInput.then eView)).then + (getD binaryNatCode 0) |>.congr (by + intro x + have hh := records_lookup (w:=2) x.1.val.n x.1.val.m x.1.val.k + (fun i => [(x.1.val.graph.left i).val,(x.1.val.graph.right i).val]) + (fun _ => rfl) x.2 (if right then 1 else 0) (by cases right <;> decide) + cases right <;> simpa [eFields] using hh) +instance poly_eEndpointBinary (right : Bool) : PolyTime (eEndpointBinary right) := by + unfold eEndpointBinary;infer_instance + +def eEndpoint (right : Bool) := (eEndpointBinary right).then binaryToNat +instance poly_eEndpoint (right : Bool) : PolyTime (eEndpoint right) := by + apply poly_bounded_binary + apply ((isPoly_const _ 2).mul (isPoly_self _)).mono + intro x + have hv := eN_bound x.1 + have hl : (eCode x.1).length ≤ (eEdgeCode x).length := + le_prodCode_left (ea:=eCode) (eb:=natCode) (x.1,x.2.val) + have h1 := (x.1.val.graph.left x.2).isLt + have h2 := (x.1.val.graph.right x.2).isLt + cases right <;> simp only [Bool.false_eq_true,↓reduceIte] <;> omega + +def bRecordBinary (j : Fin 3) : Realizes bRecCode binaryNatCode + (fun x => ([(x.1.val.left x.2).val,(x.1.val.right x.2).val,x.1.val.multiplicity x.2]).getD j.val 0) := + ((((constant bRecCode natCode 3).nadd (brIndex.nmul (constant bRecCode natCode 3))).nadd + (constant bRecCode natCode j.val)).both (brInput.then bView)).then (getD binaryNatCode 0) + |>.congr (fun x => records_lookup (w:=3) x.1.val.n x.1.val.p x.1.val.k + (fun i => [(x.1.val.left i).val,(x.1.val.right i).val,x.1.val.multiplicity i]) + (fun _ => rfl) x.2 j.val j.isLt) +instance poly_bRecordBinary (j : Fin 3) : PolyTime (bRecordBinary j) := by + unfold bRecordBinary;apply poly_congr + +def bEndpointBinary (right : Bool) : Realizes bRecCode binaryNatCode + (fun x => if right then (x.1.val.right x.2).val else (x.1.val.left x.2).val) := + (bRecordBinary (if right then 1 else 0)).congr (by intro x;cases right <;> rfl) +instance poly_bEndpointBinary (right : Bool) : PolyTime (bEndpointBinary right) := by + unfold bEndpointBinary;infer_instance + +def bEndpoint (right : Bool) := (bEndpointBinary right).then binaryToNat +instance poly_bEndpoint (right : Bool) : PolyTime (bEndpoint right) := by + apply poly_bounded_binary + apply ((isPoly_const _ 2).mul (isPoly_self _)).mono + intro x + have hv := bN_bound x.1 + have hl : (bCode x.1).length ≤ (bRecCode x).length := + le_prodCode_left (ea:=bCode) (eb:=natCode) (x.1,x.2.val) + have h1 := (x.1.val.left x.2).isLt + have h2 := (x.1.val.right x.2).isLt + cases right <;> simp only [Bool.false_eq_true,↓reduceIte] <;> omega + +end AlgorithmicThinTrees.InputStack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/InputDispatch.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/InputDispatch.lean new file mode 100644 index 0000000000000000000000000000000000000000..7815efbe6af568f95b67e1abba53a3758c491744 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/InputDispatch.lean @@ -0,0 +1,162 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Arithmetic.WordHead +import OAI.Combinatorics.ThinTrees.Encoding.BoundaryCases +import OAI.Combinatorics.ThinTrees.Encoding.InputOutput + +namespace OAI + +/-! Input dispatch. -/ + +section + +namespace AlgorithmicThinTrees.InputStack +open StrongThinTree Finset CurrentKS CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 +open GraphicHalf.Stack + +abbrev Good := {x : AlgorithmicThinTrees.Input // Valid x} +abbrev Large := {x : AlgorithmicThinTrees.Input // Valid x ∧ 2 ≤ x.n} +abbrev goodCode (x : Good) : Word := x.val.encode +abbrev largeCode (x : Large) : Word := x.val.encode +lemma valid_n {x : AlgorithmicThinTrees.Input} (hv : Valid x) : 1≤x.n := by + cases x <;> exact hv.1 + +def isBinary : AlgorithmicThinTrees.Input → Bool + | .explicit _ => false + | .binary _ => true + +def asBinary (x : {x : Large // isBinary x.val = true}) : B := by + rcases x with ⟨⟨x|x,hvalid,hn⟩,hb⟩ + · cases hb + · exact ⟨x,hn,hvalid.2⟩ +def asExplicit (x : {x : Large // ¬isBinary x.val = true}) : E := by + rcases x with ⟨⟨x|x,hvalid,hn⟩,hb⟩ + · exact ⟨x,hn,hvalid.2⟩ + · exact (hb rfl).elim + +lemma asBinary_input (x : {x : Large // isBinary x.val = true}) : + AlgorithmicThinTrees.Input.binary (asBinary x).val = x.val.val := by + rcases x with ⟨⟨x|x,hvalid,hn⟩,hb⟩ + · cases hb + · rfl +lemma asExplicit_input (x : {x : Large // ¬isBinary x.val = true}) : + AlgorithmicThinTrees.Input.explicit (asExplicit x).val = x.val.val := by + rcases x with ⟨⟨x|x,hvalid,hn⟩,hb⟩ + · rfl + · exact (hb rfl).elim + +def formatTest : Realizes largeCode boolCode (fun x => decide (isBinary x.val=true)) := + (wordHead.reindex largeCode largeCode (fun _ => rfl)).congr (by + rintro ⟨x|x,h⟩ <;> rfl) +instance poly_formatTest : PolyTime formatTest := by unfold formatTest;infer_instance + +def binaryTail : Realizes (fun x : {x : Large // isBinary x.val=true} => largeCode x.val) + bCode asBinary := + (wordTail.reindex (fun x : {x : Large // isBinary x.val=true} => largeCode x.val) + (fun x => largeCode x.val) (fun _ => rfl)).changeOutput bCode asBinary (by + rintro ⟨⟨x|x,hv,hn⟩,hb⟩ + · cases hb + · rfl) +def explicitTail : Realizes (fun x : {x : Large // ¬isBinary x.val=true} => largeCode x.val) + eCode asExplicit := + (wordTail.reindex (fun x : {x : Large // ¬isBinary x.val=true} => largeCode x.val) + (fun x => largeCode x.val) (fun _ => rfl)).changeOutput eCode asExplicit (by + rintro ⟨⟨x|x,hv,hn⟩,hb⟩ + · rfl + · exact (hb rfl).elim) +instance poly_binaryTail : PolyTime binaryTail := by unfold binaryTail;infer_instance +instance poly_explicitTail : PolyTime explicitTail := by unfold explicitTail;infer_instance + +def largeOutput (R : ℕ) (x : Large) : Word := + if h : isBinary x.val=true then bOutput R (asBinary ⟨x,h⟩) else eOutput R (asExplicit ⟨x,h⟩) +def largeRun (R : ℕ) : Realizes largeCode wordCode (largeOutput R) := + formatTest.dite (binaryTail.then (bRun R)) (explicitTail.then (eRun R)) + +def makeLarge (x : {x : Good // x.val.n ≠ 1}) : Large := by + refine ⟨x.val.val,x.val.property,?_⟩ + have hv : 1 ≤ x.val.val.n := valid_n x.val.property + have hn := x.property + omega + +lemma makeLarge_input (x : {x : Good // x.val.n ≠ 1}) : (makeLarge x).val=x.val.val := rfl + +def inputFields : AlgorithmicThinTrees.Input → List ℕ + | .explicit x => eFields x + | .binary x => bFields x +lemma inputFields_code (x : AlgorithmicThinTrees.Input) : + fieldsCode (inputFields x) = x.encode.tail := by + cases x with + | explicit x => exact eFields_code x + | binary x => exact bFields_code x + +def goodFields : Realizes goodCode fieldsCode (fun x => inputFields x.val) := + (wordTail.reindex goodCode goodCode (fun _ => rfl)).changeOutput fieldsCode + (fun x => inputFields x.val) (fun x => (inputFields_code x.val).symm) +instance poly_goodFields : PolyTime goodFields := by unfold goodFields;infer_instance + +def goodN : Realizes goodCode binaryNatCode (fun x => x.val.n) := + (goodFields.then (field 0)).congr (by rintro ⟨x|x,h⟩ <;> rfl) +instance poly_goodN : PolyTime goodN := by unfold goodN;infer_instance + +def singletonTest : Realizes goodCode boolCode (fun x => decide (x.val.n=1)) := + ((goodN.then binaryToRat).le (constant goodCode ratCode 1)).congr (by + intro x + have hn : 1 ≤ x.val.n := valid_n x.property + simp only [Nat.cast_le_one] + have he : (x.val.n ≤ 1) ↔ x.val.n=1 := by omega + simp only [he]) +instance poly_singletonTest : PolyTime singletonTest := by unfold singletonTest;infer_instance + +def output (R : ℕ) (x : Good) : Word := + if h : x.val.n=1 then [] else largeOutput R (makeLarge ⟨x,h⟩) +def program (R : ℕ) : Realizes goodCode wordCode (output R) := + singletonTest.dite (constant (fun x : {x : Good // x.val.n=1} => goodCode x.val) wordCode []) + ((largeRun R).reindex (fun x : {x : Good // x.val.n≠1} => goodCode x.val) + makeLarge (fun _ => rfl)) + +variable {R : ℕ} {C : ℝ} +variable (hC : 0 (problemCode (a i)).length) → + (∀i,2 ≤ (a i).d+1 ∧ 1 ≤ (a i).r ∧ (a i).G.EdgeConnected (a i).r) → + RunsPoly L (Iteration.Stack.treeProgram R) a) +include htime in +lemma runsPoly_largeRun {ι : Type} {L : ι → ℕ} (a : ι → Large) + (ha : IsPoly L (fun i => (largeCode (a i)).length)) : RunsPoly L (largeRun R) a := by + unfold largeRun + apply RunsPoly.dite_families (RunsPoly.of_poly _ a ha) + · have ht := RunsPoly.of_poly binaryTail (fun i : {i // isBinary (a i).val=true} => + ⟨a i.val,i.property⟩) (ha.reindex Subtype.val) + exact ht.then (runsPoly_bRun htime _ ht.output) + · have ht := RunsPoly.of_poly explicitTail (fun i : {i // ¬isBinary (a i).val=true} => + ⟨a i.val,i.property⟩) (ha.reindex Subtype.val) + exact ht.then (runsPoly_eRun htime _ ht.output) +include htime in +lemma runsPoly_program {ι : Type} {L : ι → ℕ} (a : ι → Good) + (ha : IsPoly L (fun i => (goodCode (a i)).length)) : RunsPoly L (program R) a := by + unfold program + apply RunsPoly.dite_families (RunsPoly.of_poly _ a ha) + · exact RunsPoly.of_poly _ _ (ha.reindex Subtype.val) + · apply RunsPoly.reindex + exact runsPoly_largeRun htime _ (ha.reindex Subtype.val) + +end AlgorithmicThinTrees.InputStack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/InputExpansion.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/InputExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c5d5582aa826c2acfbf9a85be55f69cdc61cdf9 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/InputExpansion.lean @@ -0,0 +1,149 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.CanonicalExpansion +import OAI.Combinatorics.ThinTrees.Encoding.InputArrays + +namespace OAI + +/-! Input expansion. -/ + +section + +namespace AlgorithmicThinTrees.InputStack +open StrongThinTree Finset CurrentKS CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 +open GraphicHalf.Stack GraphStack + +def makeProblem {n m : ℕ} (G : MultiGraph n m) (hn : 0 v.val) h } + +lemma makeProblem_n {n m : ℕ} (G : MultiGraph n m) (hn : 0 (G.left e).val), + List.ofFn (fun e => (G.right e).val))),k) := by + change prodCode graphDataCode natCode + ((n-1+1,(List.ofFn (fun e => (G.left e).val), List.ofFn (fun e => (G.right e).val))),k)=_ + rw [Nat.sub_add_cancel hn] + +lemma makeProblem_connected {n m : ℕ} (G : MultiGraph n m) (hn : 0 omega + | succ d => simpa [makeProblem] using hc +lemma makeProblem_thin {n m : ℕ} (G : MultiGraph n m) (hn : 0 omega + | succ d => simpa [makeProblem] using h + +abbrev eProblem (x : E) : Problem := makeProblem x.val.graph (by have h:=x.property.1;omega) x.val.k +abbrev bProblem (x : B) : Problem := makeProblem x.val.reduced.expanded + (show 0.changeOutput problemCode eProblem (by + intro x + rw [makeProblem_code] + rfl) +instance poly_ePrepare : PolyTime ePrepare := by unfold ePrepare;infer_instance + +lemma eProblem_good (x : E) : 2 ≤ (eProblem x).d+1 ∧ 1 ≤ (eProblem x).r ∧ + (eProblem x).G.EdgeConnected (eProblem x).r := by + refine ⟨by rw [makeProblem_n];exact x.property.1,x.property.2.1,?_⟩ + exact makeProblem_connected _ _ _ x.property.2.2 + +def bMultiplicityRat : Realizes bRecCode ratCode (fun x => (x.1.val.multiplicity x.2:ℚ)) := + ((bRecordBinary 2).then binaryToRat).congr (fun _ => rfl) +instance poly_bMultiplicityRat : PolyTime bMultiplicityRat := by unfold bMultiplicityRat;apply poly_congr + +def bCountBinary : Realizes bRecCode binaryNatCode (fun x => x.1.val.reduced.multiplicity x.2) := + let k := brInput.then bKBinary |>.then binaryToRat + let n := brInput.then bNBinary |>.then binaryToRat + let c := bMultiplicityRat + let capped := (c.le k).ite c k + ((((constant bRecCode ratCode 2).mul (n.pow 2)).mul capped).div k |>.then ratNatFloorBinary) + |>.congr (by + intro x + have he : (if decide ((x.1.val.multiplicity x.2:ℚ)≤(x.1.val.k:ℚ)) + then (x.1.val.multiplicity x.2:ℚ) else (x.1.val.k:ℚ)) = + (min (x.1.val.multiplicity x.2) x.1.val.k:ℕ) := by + simp only [Nat.cast_le,decide_eq_true_eq] + split_ifs with h + · rw [min_eq_left h] + · rw [min_eq_right (le_of_not_ge h)] + change ⌊2*(x.1.val.n:ℚ)^2*(if decide _ then _ else _)/(x.1.val.k:ℚ)⌋₊ = _ + have hex : (2:ℚ)*(x.1.val.n:ℚ)^2*(min (x.1.val.multiplicity x.2) x.1.val.k:ℕ) = + (2*x.1.val.n^2*min (x.1.val.multiplicity x.2) x.1.val.k:ℕ) := by push_cast; rfl + rw [he,hex,Nat.floor_div_natCast,Nat.floor_natCast]) +instance poly_bCountBinary : PolyTime bCountBinary := by unfold bCountBinary;infer_instance + +def bCount := bCountBinary.then binaryToNat +instance poly_bCount : PolyTime bCount := by + apply poly_bounded_binary + refine ⟨8*NaturalPolynomial.variable^2,?_⟩ + intro x + have hv := bN_bound x.1 + have hl : (bCode x.1).length ≤ (bRecCode x).length := + le_prodCode_left (ea:=bCode) (eb:=natCode) (x.1,x.2.val) + have hc := x.1.val.reduced_multiplicity_le x.1.property.2.1 x.2 + have hn : x.1.val.n ≤ 2*(bRecCode x).length := by omega + have hn2 := Nat.pow_le_pow_left hn 2 + change x.1.val.reduced.multiplicity x.2 ≤ 8*(bRecCode x).length^2 + nlinarith + +def bEndpointBlock (right : Bool) : Realizes bRecCode (listCode natCode) + (fun x => List.replicate (x.1.val.reduced.multiplicity x.2) + (if right then (x.1.val.right x.2).val else (x.1.val.left x.2).val)) := + ((bEndpoint right).both bCount).then (replicateList natCode) +instance poly_bEndpointBlock (right : Bool) : PolyTime (bEndpointBlock right) := by + unfold bEndpointBlock;infer_instance + +def bLefts : Realizes bCode (listCode natCode) + (fun x => List.ofFn (fun e => (x.val.reduced.expanded.left e).val)) := + (((bEndpointBlock false).tabulateFin bP).then (joinList natCode)).congr + (fun x => x.val.reduced.expanded_lefts.symm) +def bRights : Realizes bCode (listCode natCode) + (fun x => List.ofFn (fun e => (x.val.reduced.expanded.right e).val)) := + (((bEndpointBlock true).tabulateFin bP).then (joinList natCode)).congr + (fun x => x.val.reduced.expanded_rights.symm) +def bRecords : Realizes bCode (listCode natCode) + (fun x => List.ofFn (fun e : Fin x.val.reduced.copies.length => + (x.val.reduced.copies.get e).1.val)) := + ((((brIndex.both bCount).then (replicateList natCode)).tabulateFin bP).then + (joinList natCode)).congr (fun x => x.val.reduced.expanded_records.symm) +instance poly_bLefts : PolyTime bLefts := by unfold bLefts;infer_instance +instance poly_bRights : PolyTime bRights := by unfold bRights;infer_instance +instance poly_bRecords : PolyTime bRecords := by unfold bRecords;infer_instance + +def bPrepare : Realizes bCode problemCode bProblem := + ((bN.both (bLefts.both bRights)).both (bN.nmul bN)).changeOutput problemCode bProblem (by + intro x + rw [makeProblem_code] + simp only [pow_two] + rfl) +instance poly_bPrepare : PolyTime bPrepare := by unfold bPrepare;infer_instance + +lemma bProblem_good (x : B) : 2 ≤ (bProblem x).d+1 ∧ 1 ≤ (bProblem x).r ∧ + (bProblem x).G.EdgeConnected (bProblem x).r := by + have hn : 0 x.val.originalCopy + (edgeEmbedding (Iteration.tree R (bProblem x).r (bProblem x).G) i)) +def eOutput (R : ℕ) (x : E) : Word := x.val.encodeEdges (eEdges R x) +def bOutput (R : ℕ) (x : B) : Word := x.val.encodeEdges (bEdges R x) + +def eRun (R : ℕ) : Realizes eCode wordCode (eOutput R) := + ((ePrepare.then (treeProgram R)).then natToBinary.map).changeOutput wordCode (eOutput R) (by + intro x + simp only [treeData,List.map_ofFn,Function.comp_def,id_eq,eOutput,eEdges, + ExplicitInput.encodeEdges,listCode,FramedMapRoutine.tape,wordCode,binaryNatCode] + simp only [List.flatMap_def,List.map_ofFn,Function.comp_def,CurrentKS.DenseInputMachine.encodeNat_eq,KS.W01.encodeNat] + erw [List.map_ofFn] + rfl) + +def lookupPair : Realizes (prodCode indicesCode natCode) fieldsCode + (fun p => [p.1.getD p.2 0,0]) := + (((((second indicesCode natCode).both (first indicesCode natCode)).then (getD natCode 0)).then + natToBinary).both (constant (prodCode indicesCode natCode) fieldsCode [0])).then + (consList binaryNatCode) +instance poly_lookupPair : PolyTime lookupPair := by unfold lookupPair;infer_instance + +def pairsOutput : Realizes (prodCode indicesCode indicesCode) fieldsCode + (fun p => (p.2.map (fun i => [p.1.getD i 0,0])).flatten) := + lookupPair.mapCtx.then (joinList binaryNatCode) +instance poly_pairsOutput : PolyTime pairsOutput := by unfold pairsOutput;infer_instance + +lemma bOutput_code (R : ℕ) (x : B) : + fieldsCode (((treeData R (bProblem x)).map (fun i => + [(List.ofFn (fun e : Fin x.val.reduced.copies.length => + (x.val.reduced.copies.get e).1.val)).getD i 0,0])).flatten) = bOutput R x := by + simp only [treeData,List.map_ofFn,Function.comp_def] + rw [fieldsCode_flatten] + simp only [List.map_ofFn,Function.comp_def,bOutput,bEdges,BinaryInput.encodeEdges, + List.flatMap_def,List.map_ofFn,Function.comp_def] + apply congrArg List.flatten + apply congrArg List.ofFn + funext e + have hget := getD_ofFn (fun i : Fin x.val.reduced.copies.length => + (x.val.reduced.copies.get i).1.val) + (edgeEmbedding (Iteration.tree R (bProblem x).r (bProblem x).G) e) 0 + erw [hget] + simp [fieldsCode,listCode,FramedMapRoutine.tape,BinaryInput.originalCopy, + BinaryInput.liftCopy,binaryNatCode,CurrentKS.DenseInputMachine.encodeNat_eq,KS.W01.encodeNat] + +def bRun (R : ℕ) : Realizes bCode wordCode (bOutput R) := + ((bRecords.both (bPrepare.then (treeProgram R))).then pairsOutput).changeOutput + wordCode (bOutput R) (bOutput_code R) + +lemma enum_toFinset {n : ℕ} (T : Finset (Fin n)) : + (List.ofFn (edgeEmbedding T)).toFinset = T := by + ext e + simp only [List.mem_toFinset,List.mem_ofFn] + constructor + · rintro ⟨i,rfl⟩;exact embedding_mem T i + · exact embedding_surj T +lemma enum_image {n : ℕ} {α : Type*} [DecidableEq α] (T : Finset (Fin n)) (f : Fin n → α) : + (List.ofFn (fun i => f (edgeEmbedding T i))).toFinset = T.image f := by + change (List.ofFn (f ∘ edgeEmbedding T)).toFinset = _ + rw [←List.map_ofFn] + conv_rhs => rw [←enum_toFinset T] + ext a + simp + +lemma thinTree_mono {n m k : ℕ} {G : MultiGraph n m} {T : Finset (Fin m)} + {C D : ℝ} (hCD : C ≤ D) (h : ThinTree C k G T) : ThinTree D k G T := by + refine ⟨h.1,fun S hS hS' => (h.2 S hS hS').trans ?_⟩ + apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) + exact div_le_div_of_nonneg_right hCD (Nat.cast_nonneg _) + +variable {R : ℕ} {C : ℝ} +variable (hC : 0 < C) +variable (hcorrect : ∀p : Problem,2 ≤ p.d+1 → 1 ≤ p.r → p.G.EdgeConnected p.r → + ThinTree C p.r p.G (Iteration.tree R p.r p.G)) + +include hC hcorrect in +lemma eRun_good (x : E) : GoodOutput (2*C) (.explicit x.val) (eOutput R x) := by + obtain ⟨hn,hk,hc⟩ := eProblem_good x + have hT := makeProblem_thin x.val.graph _ x.val.k (hcorrect (eProblem x) hn hk hc) + refine ⟨⟨eEdges R x,?_,rfl,?_⟩,?_⟩ + · exact List.nodup_ofFn.mpr (edgeEmbedding _).injective + · dsimp only [eEdges] + erw [enum_toFinset] + exact thinTree_mono (by linarith : C≤2*C) hT + · intro hh + have hx := x.property.1 + change x.val.n=1 at hh + omega + +include hC hcorrect in +lemma bRun_good (x : B) : GoodOutput (2*C) (.binary x.val) (bOutput R x) := by + classical + obtain ⟨hn,hk,hc⟩ := bProblem_good x + have hpos : 0 (problemCode (a i)).length) → + (∀i,2 ≤ (a i).d+1 ∧ 1 ≤ (a i).r ∧ (a i).G.EdgeConnected (a i).r) → + RunsPoly L (treeProgram R) a) + +include htime in +lemma runsPoly_eRun {ι : Type} {L : ι → ℕ} (a : ι → E) + (ha : IsPoly L (fun i => (eCode (a i)).length)) : RunsPoly L (eRun R) a := by + unfold eRun + apply RunsPoly.changeOutput + apply RunsPoly.then_poly + have hp := RunsPoly.of_poly ePrepare a ha + exact hp.then (htime _ hp.output (fun i => eProblem_good (a i))) +include htime in +lemma runsPoly_bRun {ι : Type} {L : ι → ℕ} (a : ι → B) + (ha : IsPoly L (fun i => (bCode (a i)).length)) : RunsPoly L (bRun R) a := by + unfold bRun + apply RunsPoly.changeOutput + apply RunsPoly.then_poly + refine (RunsPoly.of_poly bRecords a ha).both ?_ + have hp := RunsPoly.of_poly bPrepare a ha + exact hp.then (htime _ hp.output (fun i => bProblem_good (a i))) + +end AlgorithmicThinTrees.InputStack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/OrderedGraph.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/OrderedGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..9108cb79fa37b231ede60fbe0432e733a8b78686 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/OrderedGraph.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Signing.Realization + +namespace OAI + +/-! Ordered graph. -/ + +section + +namespace AlgorithmicThinTrees.OrderedGraph +open Finset StrongThinTree StrongThinTree.MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) + +def edgeEmbedding (F : Finset (Fin m)) : Fin F.card ↪ Fin m := + (F.orderEmbOfFin rfl).toEmbedding +def restrict (F : Finset (Fin m)) : MultiGraph n F.card where + left e := G.left (edgeEmbedding F e) + right e := G.right (edgeEmbedding F e) + loopless e := G.loopless (edgeEmbedding F e) +def liftEdges (F : Finset (Fin m)) (T : Finset (Fin F.card)) : Finset (Fin m) := + T.map (edgeEmbedding F) +noncomputable def lowerEdges (F T : Finset (Fin m)) : Finset (Fin F.card) := + T.preimage (edgeEmbedding F) (edgeEmbedding F).injective.injOn + +lemma embedding_mem (F : Finset (Fin m)) (e : Fin F.card) : edgeEmbedding F e ∈ F := + F.orderEmbOfFin_mem rfl e +lemma embedding_surj (F : Finset (Fin m)) {e : Fin m} (he : e ∈ F) : + ∃i : Fin F.card, edgeEmbedding F i=e := by + refine ⟨(F.orderIsoOfFin rfl).symm ⟨e,he⟩,?_⟩ + change ((F.orderIsoOfFin rfl) ((F.orderIsoOfFin rfl).symm ⟨e,he⟩)).val=e + simp +lemma lift_univ (F : Finset (Fin m)) : liftEdges F univ=F := by + ext e + simp only [liftEdges,mem_map,mem_univ,true_and] + exact ⟨fun ⟨i,hi⟩ => hi ▸ embedding_mem F i, embedding_surj F⟩ +lemma lift_lower (F T : Finset (Fin m)) (hT : T ⊆ F) : liftEdges F (lowerEdges F T)=T := by + ext e + simp only [liftEdges,lowerEdges,mem_map,mem_preimage] + refine ⟨fun ⟨i,hi,hie⟩ => hie ▸ hi,fun he => ?_⟩ + obtain ⟨i,rfl⟩ := embedding_surj F (hT he) + exact ⟨i,he,rfl⟩ +lemma restrict_cut (F : Finset (Fin m)) (T : Finset (Fin F.card)) (S : Finset (Fin n)) : + liftEdges F ((restrict G F).cut T S)=G.cut (liftEdges F T) S := by + ext e + simp only [liftEdges,cut,mem_map,mem_filter] + constructor + · rintro ⟨i,⟨hi,hc⟩,rfl⟩ + exact ⟨⟨i,hi,rfl⟩,hc⟩ + · rintro ⟨⟨i,hi,rfl⟩,hc⟩ + exact ⟨i,⟨hi,hc⟩,rfl⟩ +lemma restrict_cut_card (F : Finset (Fin m)) (T : Finset (Fin F.card)) (S : Finset (Fin n)) : + ((restrict G F).cut T S).card=(G.cut (liftEdges F T) S).card := by + rw [←restrict_cut G] + exact (card_map _).symm +lemma restrict_connected (F : Finset (Fin m)) (T : Finset (Fin F.card)) : + (restrict G F).Connected T ↔ G.Connected (liftEdges F T) := by + unfold Connected + constructor <;> intro h S hS hS' + · rw [←restrict_cut G] + exact map_nonempty.mpr (h S hS hS') + · apply (map_nonempty (f := edgeEmbedding F)).mp + change (liftEdges F ((restrict G F).cut T S)).Nonempty + rw [restrict_cut G] + exact h S hS hS' +lemma restrict_spanningTree (F : Finset (Fin m)) (T : Finset (Fin F.card)) : + (restrict G F).SpanningTree T ↔ G.SpanningTree (liftEdges F T) := by + constructor + · rintro ⟨hc,hmin⟩ + refine ⟨(restrict_connected G F T).mp hc,?_⟩ + intro e he hh + obtain ⟨i,hi,rfl⟩ := mem_map.mp he + apply hmin i hi + apply (restrict_connected G F (T.erase i)).mpr + simpa only [liftEdges,map_erase] using hh + · rintro ⟨hc,hmin⟩ + refine ⟨(restrict_connected G F T).mpr hc,?_⟩ + intro e he hh + apply hmin (edgeEmbedding F e) (mem_map.mpr ⟨e,he,rfl⟩) + have hh' := (restrict_connected G F (T.erase e)).mp hh + simpa only [liftEdges,map_erase] using hh' +lemma restrict_packable (F : Finset (Fin m)) {r : ℕ} (h : G.TreePackable F r) : + (restrict G F).TreePackable univ r := by + obtain ⟨T,hT,hd⟩ := h + refine ⟨fun i => lowerEdges F (T i),fun i => ⟨subset_univ _,?_⟩,?_⟩ + · apply (restrict_spanningTree G F _).mpr + rw [lift_lower F (T i) (hT i).1] + exact (hT i).2 + · intro i j hij + exact disjoint_preimage (hd hij) +end AlgorithmicThinTrees.OrderedGraph +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/SelectionRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/SelectionRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f3fa49069a8f96db2e5082d9b110ccef71925e9 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/SelectionRealization.lean @@ -0,0 +1,74 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Arithmetic.BoolPrograms +import OAI.Combinatorics.ThinTrees.Encoding.OrderedGraph +import OAI.Combinatorics.ThinTrees.Sparsification.Realization + +namespace OAI + +/-! Selection realization. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 Finset +open AlgorithmicThinTrees.OrderedGraph + +variable {α : Type*} + +def maskEntry (ea : α → Word) : Realizes (prodCode boolCode ea) (listCode ea) + (fun p => if p.1 then [p.2] else []) := + (first boolCode ea).ite ((second boolCode ea).then (singleton ea)) + (constant (prodCode boolCode ea) (listCode ea) []) +instance poly_maskEntry (ea : α → Word) : PolyTime (maskEntry ea) := by unfold maskEntry;infer_instance + +def maskArray (ea : α → Word) (z : α) : Realizes (prodCode boolsCode (listCode ea)) (listCode ea) + (fun p => (zipDefault (fun q : Bool×α => if q.1 then [q.2] else []) false z p).flatten) := + ((maskEntry ea).zipWith false z).then (joinList ea) +instance poly_maskArray (ea : α → Word) (z : α) : PolyTime (maskArray ea z) := by + unfold maskArray;infer_instance + +lemma sorted_selected {m : ℕ} (A : Finset (Fin m)) : + (List.finRange m).filter (fun e => decide (e ∈ A))=List.ofFn (edgeEmbedding A) := by + have hh : (List.ofFn (edgeEmbedding A))=A.sort (· ≤ ·) := by + rw [List.ofFn_eq_map] + exact A.listMap_orderEmbOfFin_finRange rfl + rw [hh] + apply ((List.sortedLT_finRange m).pairwise.filter _).sortedLT.eq_of_mem_iff A.sortedLT_sort + intro e + simp + +lemma maskArray_data {m : ℕ} (A : Finset (Fin m)) (f : Fin m → α) (z : α) : + (zipDefault (fun q : Bool×α => if q.1 then [q.2] else []) false z + (List.ofFn (fun e => decide (e ∈ A)),List.ofFn f)).flatten= + List.ofFn (fun i => f (edgeEmbedding A i)) := by + rw [zipDefault_ofFn] + have hh : ∀es : List (Fin m), + (es.map (fun e => if decide (e ∈ A) then [f e] else [])).flatten= + (es.filter (fun e => decide (e ∈ A))).map f := by + intro es + induction es with + | nil => rfl + | cons e es ih => by_cases he : e ∈ A <;> simp_all + dsimp only + rw [List.ofFn_eq_map,hh,sorted_selected,List.map_ofFn] + rfl + +lemma selected_sublist {m : ℕ} (A : Finset (Fin m)) (f : Fin m → α) : + (List.ofFn (fun i => f (edgeEmbedding A i))).Sublist (List.ofFn f) := by + change (List.ofFn (f ∘ edgeEmbedding A)).Sublist (List.ofFn f) + rw [←List.map_ofFn,←sorted_selected,List.ofFn_eq_map (f:=f)] + exact List.Sublist.map f (List.filter_sublist) + +lemma listCode_sublist_le {ea : α → Word} {xs ys : List α} (h : xs.Sublist ys) : + (listCode ea xs).length≤(listCode ea ys).length := by + rw [len_listCode,len_listCode] + exact (h.map (fun x => 2*(ea x).length+1)).sum_le_sum (fun _ _ => Nat.zero_le _) + +lemma listCode_selected_le {m : ℕ} (ea : α → Word) (A : Finset (Fin m)) (f : Fin m → α) : + (listCode ea (List.ofFn (fun i => f (edgeEmbedding A i)))).length≤ + (listCode ea (List.ofFn f)).length := listCode_sublist_le (selected_sublist A f) + +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Encoding/Specification.lean b/lean/OAI/Combinatorics/ThinTrees/Encoding/Specification.lean new file mode 100644 index 0000000000000000000000000000000000000000..68c17bae9c87b73a1f08ec5faa27de4f066795d9 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Encoding/Specification.lean @@ -0,0 +1,103 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.GreedyRealization + +namespace OAI + +/-! Specification. -/ + +section + +namespace AlgorithmicThinTrees +open StrongThinTree + +structure ExplicitInput where + n : ℕ + m : ℕ + k : ℕ + graph : MultiGraph n m + +structure BinaryInput where + n : ℕ + p : ℕ + k : ℕ + left : Fin p → Fin n + right : Fin p → Fin n + ordered : ∀ i, left i < right i + distinct : Function.Injective (fun i => (left i, right i)) + multiplicity : Fin p → ℕ + +abbrev BinaryInput.Edge (x : BinaryInput) := Σ i : Fin x.p, Fin (x.multiplicity i) + +noncomputable def BinaryInput.edgeEquiv (x : BinaryInput) : + x.Edge ≃ Fin (Fintype.card x.Edge) := Fintype.equivFin x.Edge + +noncomputable def BinaryInput.graph (x : BinaryInput) : + MultiGraph x.n (Fintype.card x.Edge) where + left e := x.left (x.edgeEquiv.symm e).1 + right e := x.right (x.edgeEquiv.symm e).1 + loopless e := ne_of_lt (x.ordered (x.edgeEquiv.symm e).1) + +inductive Input where + | explicit (x : ExplicitInput) + | binary (x : BinaryInput) + +def ExplicitInput.encode (x : ExplicitInput) : List Bool := + CurrentKS.encodeNat x.n ++ CurrentKS.encodeNat x.m ++ CurrentKS.encodeNat x.k ++ + (List.ofFn fun i : Fin x.m => + CurrentKS.encodeNat (x.graph.left i).val ++ + CurrentKS.encodeNat (x.graph.right i).val).flatten + +def BinaryInput.encode (x : BinaryInput) : List Bool := + CurrentKS.encodeNat x.n ++ CurrentKS.encodeNat x.p ++ CurrentKS.encodeNat x.k ++ + (List.ofFn fun i : Fin x.p => + CurrentKS.encodeNat (x.left i).val ++ CurrentKS.encodeNat (x.right i).val ++ + CurrentKS.encodeNat (x.multiplicity i)).flatten + +def Input.encode : Input → List Bool + | .explicit x => false :: x.encode + | .binary x => true :: x.encode + +def Input.length (x : Input) : ℕ := x.encode.length + +def Input.n : Input → ℕ + | .explicit x => x.n + | .binary x => x.n + +def Valid : Input → Prop + | .explicit x => 1 ≤ x.n ∧ 1 ≤ x.k ∧ x.graph.EdgeConnected x.k + | .binary x => 1 ≤ x.n ∧ 1 ≤ x.k ∧ x.graph.EdgeConnected x.k + +def ThinTree {n m : ℕ} (C : ℝ) (k : ℕ) (G : MultiGraph n m) + (T : Finset (Fin m)) : Prop := + G.SpanningTree T ∧ ∀ S : Finset (Fin n), S.Nonempty → S ≠ Finset.univ → + ((G.cut T S).card : ℝ) ≤ C / (k : ℝ) * (G.cut Finset.univ S).card + +def ExplicitInput.encodeEdges (x : ExplicitInput) (edges : List (Fin x.m)) : List Bool := + edges.flatMap (fun e => CurrentKS.encodeNat e.val) + +def BinaryInput.encodeEdges (x : BinaryInput) (edges : List x.Edge) : List Bool := + edges.flatMap (fun e => CurrentKS.encodeNat e.1.val ++ CurrentKS.encodeNat e.2.val) + +noncomputable def BinaryInput.selected (x : BinaryInput) (edges : List x.Edge) : + Finset (Fin (Fintype.card x.Edge)) := edges.toFinset.map x.edgeEquiv.toEmbedding + +def TreeOutput (C : ℝ) : Input → List Bool → Prop + | .explicit x, bits => ∃ edges : List (Fin x.m), edges.Nodup ∧ + bits = x.encodeEdges edges ∧ ThinTree C x.k x.graph edges.toFinset + | .binary x, bits => ∃ edges : List x.Edge, edges.Nodup ∧ + bits = x.encodeEdges edges ∧ ThinTree C x.k x.graph (x.selected edges) + +def GoodOutput (C : ℝ) (x : Input) (bits : List Bool) : Prop := + TreeOutput C x bits ∧ (x.n = 1 → bits = []) + +def AlgorithmicStrongThinTrees : Prop := + ∃ C : ℝ, 0 < C ∧ ∃ M : CurrentKS.Machine, ∃ a degree : ℕ, 0 < a ∧ + ∀ x : Input, Valid x → + let result := M.run x.encode (a * (x.length + 1) ^ degree) + result.state = none ∧ GoodOutput C x (result.stacks M.outputStack) + +end AlgorithmicThinTrees + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Expectation.lean b/lean/OAI/Combinatorics/ThinTrees/Expectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..0089e1634715c04e2d610d9b90b7365751baa8c7 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Expectation.lean @@ -0,0 +1,96 @@ +import OAI.Combinatorics.ThinTrees.Extraction + +namespace OAI + +universe uD uR uS + +section + +noncomputable section +open Matrix Polynomial Finset +namespace StrongThinTree.MSS +variable {D : Type uD} {R : Type uR} {S : Type uS} [Fintype D] [DecidableEq D] [CommRing R] [CommRing S] + +def detLinear (M : Matrix D D R) : Matrix D D R →ₗ[R] R := + Matrix.detRowAlternating.toMultilinearMap.linearDeriv M + +lemma detLinear_apply (M A : Matrix D D R) : + detLinear M A=∑i, (Matrix.updateRow M i (A i)).det := by + exact MultilinearMap.linearDeriv_apply _ M A + +lemma detLinear_map (f : R →+* S) (M A : Matrix D D R) : + detLinear (M.map f) (A.map f)=f (detLinear M A) := by + simp only [detLinear_apply,map_sum] + apply Finset.sum_congr rfl + intro i _ + rw [f.map_det] + congr 1 + ext a b + by_cases h : a=i <;> simp [Matrix.updateRow,Matrix.map_apply,Function.update,h] + +lemma det_piecewise_mul (s : Finset D) (c : D → R) (A M : Matrix D D R) : + Matrix.det (s.piecewise (fun i j => c i*A i j) M)= + (∏i ∈ s, c i)*Matrix.det (s.piecewise A M) := by + have he : s.piecewise (fun i j => c i*A i j) M= + Matrix.of (fun i j => (if i ∈ s then c i else 1)*(s.piecewise A M) i j) := by + ext i j + by_cases hi : i ∈ s <;> simp [Finset.piecewise,hi] + rw [he] + have hh := Matrix.det_mul_column (fun i => if i ∈ s then c i else 1) + (Matrix.of (s.piecewise A M)) + convert hh using 1 <;> try rfl + exact congrArg (fun z => z*Matrix.det (s.piecewise A M)) (Finset.prod_ite_mem_eq s c).symm + +lemma det_add_rankOne (M : Matrix D D R) (u v : D → R) : + (M+Matrix.vecMulVec u v).det=M.det+detLinear M (Matrix.vecMulVec u v) := by + have he := Matrix.detRowAlternating.toMultilinearMap.map_add_eq_map_add_linearDeriv_add + M (Matrix.vecMulVec u v) + change (M+Matrix.vecMulVec u v).det=M.det+detLinear M (Matrix.vecMulVec u v)+ + ∑s : Finset D with 2 ≤ s.card, Matrix.det (s.piecewise (Matrix.vecMulVec u v) M) at he + rw [he] + suffices hh : ∑s : Finset D with 2 ≤ s.card, Matrix.det (s.piecewise (Matrix.vecMulVec u v) M)=0 by + rw [hh,add_zero] + apply Finset.sum_eq_zero + intro s hs + have hc : 1 < s.card := by have hh := (Finset.mem_filter.mp hs).2; omega + obtain ⟨i,hi,j,hj,hij⟩ := Finset.one_lt_card.mp hc + change Matrix.det (s.piecewise (fun i j => u i*v j) M)=0 + rw [det_piecewise_mul s u (fun _ => v) M] + have hz : Matrix.det (s.piecewise (fun _ : D => v) M)=0 := by + apply Matrix.det_zero_of_row_eq hij + simp [Finset.piecewise,hi,hj] + rw [hz,mul_zero] + +lemma det_linear_pencil_coeff_one (M A : Matrix D D R) : + ((M.map Polynomial.C + (X : R[X]) • A.map Polynomial.C).det).coeff 1=detLinear M A := by + have he := Matrix.detRowAlternating.toMultilinearMap.map_add_eq_map_add_linearDeriv_add + (M.map Polynomial.C) ((X : R[X]) • A.map Polynomial.C) + change (M.map Polynomial.C + (X : R[X]) • A.map Polynomial.C).det= + (M.map Polynomial.C).det+detLinear (M.map Polynomial.C) ((X : R[X]) • A.map Polynomial.C)+ + ∑s : Finset D with 2 ≤ s.card, + Matrix.det (s.piecewise ((X : R[X]) • A.map Polynomial.C) (M.map Polynomial.C)) at he + rw [he,coeff_add,coeff_add] + have hc : (M.map Polynomial.C).det=C M.det := (Polynomial.C.map_det M).symm + rw [hc,map_smul,detLinear_map,smul_eq_mul,coeff_X_mul,coeff_C_zero,coeff_C] + simp only [one_ne_zero,ite_false,zero_add] + suffices hz : (∑s : Finset D with 2 ≤ s.card, + Matrix.det (s.piecewise ((X : R[X]) • A.map Polynomial.C) (M.map Polynomial.C))).coeff 1=0 by + rw [hz,add_zero] + rw [finsetSum_coeff] + apply Finset.sum_eq_zero + intro s hs + have hc : 2 ≤ s.card := (Finset.mem_filter.mp hs).2 + have hp : Matrix.det (s.piecewise ((X : R[X]) • A.map Polynomial.C) (M.map Polynomial.C))= + (X : R[X])^s.card*Matrix.det (s.piecewise (A.map Polynomial.C) (M.map Polynomial.C)) := by + rw [show (X : R[X]) • A.map Polynomial.C=fun i j => X*(A.map Polynomial.C) i j from rfl, + det_piecewise_mul] + simp + rw [hp,coeff_X_pow_mul'] + simp [show ¬s.card ≤ 1 by omega] + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Extraction.lean b/lean/OAI/Combinatorics/ThinTrees/Extraction.lean new file mode 100644 index 0000000000000000000000000000000000000000..fc53e41d6ad8559fdd8b99676d9609886b5bd680 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Extraction.lean @@ -0,0 +1,28 @@ +import OAI.Combinatorics.ThinTrees.ExtractionBounds + +namespace OAI + +section + +noncomputable section +open Finset Matrix +open scoped MatrixOrder +namespace StrongThinTree.MultiGraph + +theorem extraction : ∃R : ℕ, 4 ≤ R ∧ ∀r : ℕ, R ≤ r → + ∀(n m : ℕ) (G : MultiGraph n m), 2 ≤ n → G.TreePackable univ r → + ∃X ∈ G.matrixDomain, + G.TreePackable (G.thresholdEdges (G.resistance X) (4*resistanceT r)) (extractQ r) := by + obtain ⟨qH,hqH,hresponse⟩ := simultaneous_response_exists + obtain ⟨R,hR,hnum⟩ := eventual_extraction_numeric qH + refine ⟨R,hR,fun r hr n m G hn hp => ?_⟩ + obtain ⟨hq,hqr,hstrict⟩ := hnum r hr + have ht : 0 < resistanceT r := Real.rpow_pos_of_pos + (by exact_mod_cast (show 0 < r by omega)) _ + exact G.extraction_from_response_threshold hqH hresponse hn hqr hq hp ht hstrict +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/ExtractionBounds.lean b/lean/OAI/Combinatorics/ThinTrees/ExtractionBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..4c5d1fffa1f00965c80663dfd94ca7f925f603a2 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/ExtractionBounds.lean @@ -0,0 +1,104 @@ +import OAI.Combinatorics.ThinTrees.ExtractionCriterion + +namespace OAI + +section +noncomputable section +open Filter +open scoped Topology +namespace StrongThinTree + +def extractQ (r : ℕ) : ℕ := ⌊(1-(r:ℝ)^(-1/16:ℝ))*r⌋₊ +def errorU (r : ℕ) : ℝ := (r:ℝ)^(-1/16:ℝ) +def resistanceT (r : ℕ) : ℝ := (r:ℝ)^(-1/2:ℝ) + +lemma extractQ_bounds {r : ℕ} (hr : (4:ℝ) ≤ r) (hu : errorU r ≤ 1/4) : + (r:ℝ)/2 ≤ extractQ r ∧ extractQ r ≤ r ∧ + (extractQ r:ℝ) ≤ (1-errorU r)*r ∧ (1-errorU r)*r-1 ≤ extractQ r := by + have hr0 : (0:ℝ) ≤ r := Nat.cast_nonneg _ + have hu0 : 0 ≤ errorU r := Real.rpow_nonneg hr0 _ + have ha : 0 ≤ (1-errorU r)*r := mul_nonneg (by linarith) hr0 + have hl := Nat.sub_one_lt_floor ((1-errorU r)*r) + have hh := Nat.floor_le ha + change (extractQ r:ℝ) ≤ (1-errorU r)*r at hh + change (1-errorU r)*r-1 < (extractQ r:ℝ) at hl + have hmul := mul_le_mul_of_nonneg_right hu hr0 + have hmul0 := mul_nonneg hu0 hr0 + refine ⟨by nlinarith,?_,hh,hl.le⟩ + have hqr : (extractQ r:ℝ) ≤ r := by nlinarith + exact_mod_cast hqr + +lemma negative_power_q_bound {x y : ℝ} (hx : 0 < x) (hxy : x/2 ≤ y) : + y^(-31/40:ℝ) ≤ 2*x^(-31/40:ℝ) := by + have hh := Real.rpow_le_rpow_of_nonpos (by positivity : 0 < x/2) hxy (by norm_num : (-31/40:ℝ) ≤ 0) + have hp : (2:ℝ)^(31/40:ℝ) ≤ 2 := Real.rpow_le_self_of_one_le (by norm_num) (by norm_num) + have heq : (x/2)^(-31/40:ℝ)=x^(-31/40:ℝ)*(2:ℝ)^(31/40:ℝ) := by + rw [Real.div_rpow hx.le (by norm_num), div_eq_mul_inv, ←Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2)] + norm_num + rw [heq] at hh + exact hh.trans (by nlinarith [Real.rpow_nonneg hx.le (-31/40:ℝ)]) + +lemma extract_response_ratio {r q : ℕ} (hr : 0 < r) (hqr : (r:ℝ)/2 ≤ q) + (hsmall : 64*((r:ℝ)^(-17/80:ℝ)+(r:ℝ)^(-15/16:ℝ)) < 1) : + 2*(16*((q:ℝ)^(-31/40:ℝ)/resistanceT r + 1/q)) < errorU r := by + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hr + have hqR : (0:ℝ) < q := lt_of_lt_of_le (by positivity) hqr + have ht : 0 < resistanceT r := Real.rpow_pos_of_pos hrR _ + have hu : 0 < errorU r := Real.rpow_pos_of_pos hrR _ + have hpow := negative_power_q_bound hrR hqr + have hdiv := div_le_div_of_nonneg_right hpow ht.le + have hinv : 1/(q:ℝ) ≤ 2/(r:ℝ) := by + apply (div_le_div_iff₀ hqR hrR).mpr + nlinarith + have hid : 64*((r:ℝ)^(-17/80:ℝ)+(r:ℝ)^(-15/16:ℝ))*errorU r = + 32*(2*(r:ℝ)^(-31/40:ℝ)/resistanceT r+2/(r:ℝ)) := by + unfold errorU resistanceT + rw [mul_add, add_mul] + have h1 : (r:ℝ)^(-17/80:ℝ)*(r:ℝ)^(-1/16:ℝ) = + (r:ℝ)^(-31/40:ℝ)/(r:ℝ)^(-1/2:ℝ) := by + rw [←Real.rpow_add hrR, ←Real.rpow_sub hrR] + norm_num + have h2 : (r:ℝ)^(-15/16:ℝ)*(r:ℝ)^(-1/16:ℝ) = 1/(r:ℝ) := by + rw [←Real.rpow_add hrR] + norm_num [Real.rpow_neg_one] + calc + _ = 64*((r:ℝ)^(-17/80:ℝ)*(r:ℝ)^(-1/16:ℝ))+ + 64*((r:ℝ)^(-15/16:ℝ)*(r:ℝ)^(-1/16:ℝ)) := by ring + _ = _ := by rw [h1,h2]; ring + have hh := mul_lt_mul_of_pos_right hsmall hu + rw [one_mul,hid] at hh + nlinarith + +lemma eventual_extraction_numeric (qH : ℕ) : ∃R : ℕ, 4 ≤ R ∧ ∀r : ℕ, R ≤ r → + qH ≤ extractQ r ∧ extractQ r ≤ r ∧ + (extractQ r:ℝ) < (1-2*(16*((extractQ r:ℝ)^(-31/40:ℝ)/resistanceT r+1/extractQ r)))*r := by + have hu : Tendsto (fun r : ℕ => errorU r) atTop (𝓝 0) := by + simpa [errorU, Function.comp_def, neg_div] using (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ) < 1/16)).comp tendsto_natCast_atTop_atTop + have hsmall : Tendsto (fun r : ℕ => 64*((r:ℝ)^(-17/80:ℝ)+(r:ℝ)^(-15/16:ℝ))) atTop (𝓝 0) := by + simpa [Function.comp_def, neg_div] using (((tendsto_rpow_neg_atTop (by norm_num : (0:ℝ) < 17/80)).add + (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ) < 15/16))).const_mul 64).comp tendsto_natCast_atTop_atTop + have hevent : ∀ᶠ r : ℕ in atTop, 4 ≤ r ∧ 2*qH ≤ r ∧ errorU r ≤ 1/4 ∧ + 64*((r:ℝ)^(-17/80:ℝ)+(r:ℝ)^(-15/16:ℝ)) < 1 := by + filter_upwards [eventually_ge_atTop 4,eventually_ge_atTop (2*qH), + hu.eventually_lt_const (by norm_num : (0:ℝ) < 1/4), + hsmall.eventually_lt_const (by norm_num : (0:ℝ) < 1)] with r hr hq hu hs + exact ⟨hr,hq,hu.le,hs⟩ + obtain ⟨R,hR⟩ := eventually_atTop.mp hevent + refine ⟨max R 4,le_max_right _ _,fun r hr => ?_⟩ + obtain ⟨hr4,hqr,hu,hs⟩ := hR r ((le_max_left _ _).trans hr) + have hrR : (4:ℝ) ≤ r := by exact_mod_cast hr4 + obtain ⟨hqlo,hqhi,hqfrac,_⟩ := extractQ_bounds hrR hu + have hsmall' := extract_response_ratio (by omega : 0 < r) hqlo hs + have hqH : (qH:ℝ) ≤ extractQ r := by + have hh : (2:ℝ)*qH ≤ r := by exact_mod_cast hqr + linarith + refine ⟨by exact_mod_cast hqH,hqhi,?_⟩ + have hh := mul_lt_mul_of_pos_right hsmall' (show (0:ℝ) < r by exact_mod_cast (by omega : 0 < r)) + nlinarith + +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/ExtractionCriterion.lean b/lean/OAI/Combinatorics/ThinTrees/ExtractionCriterion.lean new file mode 100644 index 0000000000000000000000000000000000000000..86880c2fdf41633d37734a7fdd325f0a5d3abf98 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/ExtractionCriterion.lean @@ -0,0 +1,107 @@ +import OAI.Combinatorics.ThinTrees.ExtractionLimit + +namespace OAI + +section + +noncomputable section +open Finset Matrix +open scoped MatrixOrder +namespace StrongThinTree.MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) +lemma treePackable_edgeConnected {r : ℕ} (hp : G.TreePackable univ r) : G.EdgeConnected r := by + have hh := G.packableOn_edgeConnectedReal ((G.packableOn_univ univ r).mpr hp) + intro S hS hS' + have hs : S ⊂ (univ : Finset (Fin n)) := Finset.ssubset_iff_subset_ne.mpr ⟨subset_univ _,hS'⟩ + have hc := hh S hS hs + have hi : G.inducedEdges univ = univ := by ext e; simp [mem_inducedEdges] + rw [hi] at hc + exact_mod_cast hc + +lemma packable_of_parts_le_one (hn : 0 < n) {F : Finset (Fin m)} {q : ℕ} + (hc : (G.packingParts F q).card ≤ 1) : G.TreePackable F q := by + classical + have hne : (G.packingParts F q).Nonempty := + ⟨G.partOf F q ⟨0,hn⟩,mem_filter.mpr ⟨mem_univ _,(G.partOf_spec F q ⟨0,hn⟩).2⟩⟩ + have hc1 : (G.packingParts F q).card=1 := by have := card_pos.mpr hne; omega + obtain ⟨A,hA⟩ := card_eq_one.mp hc1 + have hh := (G.packingParts_partition F q).2.2 + rw [hA] at hh + have hAu : A = univ := by simpa using hh + apply (G.packableOn_univ F q).mp + rw [hA] at hne + have hp := ((G.packingParts_partition F q).1 A (hA ▸ mem_singleton_self A)).2 + simpa only [hAu] using hp + +lemma consistent_packable (hn : 0 < n) {r q : ℕ} (hqp : 0 < q) + (hp : G.TreePackable univ r) {X : Matrix (Fin n) (Fin n) ℝ} {t δ s : ℝ} + (hst : 2*t < s) (hnum : (q:ℝ) < (1-2*δ)*r) + (hcount : (((G.thresholdCrossing q X s).filter (fun e => 2*t < G.resistance X e)).card:ℝ) ≤ + 2*δ*(G.thresholdCrossing q X s).card) : + G.TreePackable (G.thresholdEdges (G.resistance X) s) q := by + classical + let F := G.thresholdEdges (G.resistance X) s + let p := G.partLabel F q + let B := G.crossing univ p + by_contra hnot + have hd : 1 < (G.packingParts F q).card := by + by_contra hh + exact hnot (G.packable_of_parts_le_one hn (F:=F) (q:=q) (by omega)) + have hupper := G.packingParts_crossing_lt hqp hd + have hlower := G.partition_criterion_necessary hn hp p + rw [G.partLabel_size] at hlower + let Bad := B.filter (fun e => 2*t < G.resistance X e) + let Good := B.filter (fun e => ¬(2*t < G.resistance X e)) + have hsub : Good ⊆ G.crossing F p := by + intro e he + obtain ⟨heB,heR⟩ := mem_filter.mp he + refine mem_filter.mpr ⟨?_,(mem_filter.mp heB).2⟩ + exact mem_filter.mpr ⟨mem_univ _,(le_of_not_gt heR).trans hst.le⟩ + have hsum : Bad.card+Good.card=B.card := card_filter_add_card_filter_not _ + have hrate : 0 < 1-2*δ := by + have hr : (0:ℝ) ≤ r := Nat.cast_nonneg _ + have hq : (0:ℝ) ≤ q := Nat.cast_nonneg _ + nlinarith + have hMR : (r:ℝ)*((G.packingParts F q).card-1:ℕ) ≤ (B.card:ℝ) := by + exact_mod_cast hlower + have hpos : (0:ℝ) < ((G.packingParts F q).card-1:ℕ) := by + exact_mod_cast (show 0 < (G.packingParts F q).card-1 by omega) + have hm := mul_le_mul_of_nonneg_left hMR hrate.le + have hstrict := mul_lt_mul_of_pos_right hnum hpos + have hGood : (Good.card:ℝ) ≤ (G.crossing F p).card := by exact_mod_cast card_le_card hsub + have hu : ((G.crossing F p).card:ℝ) < (q:ℝ)*((G.packingParts F q).card-1:ℕ) := by exact_mod_cast hupper + have hs : (Bad.card:ℝ)+(Good.card:ℝ)=B.card := by exact_mod_cast hsum + change (Bad.card:ℝ) ≤ 2*δ*B.card at hcount + nlinarith + +theorem extraction_from_response_threshold {qH : ℕ} (hqH : 2 ≤ qH) + (hresp : ∀q : ℕ, qH ≤ q → ∀(n m : ℕ) (G : MultiGraph n m), 0 < n → + G.TreePackable univ q → ∀(R : Fin m → ℝ) (t : ℝ), 0 < t → + ∃Y ∈ G.matrixDomain, ∀s : ℝ, + (((univ.filter (fun e => t < G.resistance Y e)) ∩ + G.crossing univ (G.partLabel (G.thresholdEdges R s) q)).card:ℝ) ≤ + 16*((q:ℝ)^(-31/40:ℝ)/t+1/q)*(G.crossing univ (G.partLabel (G.thresholdEdges R s) q)).card) + (hn : 2 ≤ n) {r q : ℕ} (hqr : q ≤ r) (hq : qH ≤ q) + (hp : G.TreePackable univ r) {t : ℝ} (ht : 0 < t) + (hnum : (q:ℝ) < (1-2*(16*((q:ℝ)^(-31/40:ℝ)/t+1/q)))*r) : + ∃X ∈ G.matrixDomain, G.TreePackable (G.thresholdEdges (G.resistance X) (4*t)) q := by + classical + have hqp : 0 < q := by omega + have hc : G.EdgeConnected 1 := fun S hS hS' => (by omega : 1 ≤ r).trans + (G.treePackable_edgeConnected hp S hS hS') + obtain ⟨X,hX,hconsistent⟩ := G.response_limit hn hc q ht (fun X _ => + hresp q hq n m G (by omega) (G.treePackable_mono_count hqr hp) (G.resistance X) t ht) + obtain ⟨s,hs,havoid⟩ := (Set.Ioo_infinite (show 3*t < 4*t by linarith)).exists_notMem_finite + (Set.finite_range (G.resistance X)) + have ha : ∀e, G.resistance X e ≠ s := fun e he => havoid ⟨e,he⟩ + have hpF := G.consistent_packable (by omega) hqp hp (by linarith [hs.1] : 2*t < s) hnum (hconsistent s ha) + refine ⟨X,hX,G.treePackable_mono_edges ?_ hpF⟩ + intro e he + exact mem_filter.mpr ⟨mem_univ _,(mem_filter.mp he).2.trans hs.2.le⟩ + +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/ExtractionLimit.lean b/lean/OAI/Combinatorics/ThinTrees/ExtractionLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab7a19b52dc7ecde76c8ae4deeeff5abc9de2415 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/ExtractionLimit.lean @@ -0,0 +1,111 @@ +import OAI.Combinatorics.ThinTrees.MatrixMixture + +namespace OAI + +section + +noncomputable section +open Matrix Finset Filter +open scoped MatrixOrder Matrix.Norms.Elementwise Topology +namespace StrongThinTree.MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) +def thresholdCrossing (q : ℕ) (X : Matrix (Fin n) (Fin n) ℝ) (s : ℝ) : Finset (Fin m) := + G.crossing univ (G.partLabel (G.thresholdEdges (G.resistance X) s) q) +lemma bad_inter_eq (R : Fin m → ℝ) (t : ℝ) (B : Finset (Fin m)) : + (univ.filter (fun e => t < R e)) ∩ B=B.filter (fun e => t < R e) := by + ext e + simp only [mem_inter,mem_filter,mem_univ,true_and,and_comm] +lemma resistance_domain_continuous (hn : 0 < n) (e : Fin m) : + Continuous (fun X : G.matrixDomain => G.resistance X.val e) := + continuousOn_iff_continuous_domRestrict.mp (G.resistance_continuousOn hn e) +lemma threshold_stable_neighborhood (hn : 0 < n) (X : G.matrixDomain) (s : ℝ) + (havoid : ∀e, G.resistance X.val e ≠ s) : + ∃ε : ℝ, 0 < ε ∧ ∀Y : G.matrixDomain, dist Y X < ε → + G.thresholdEdges (G.resistance Y.val) s=G.thresholdEdges (G.resistance X.val) s := by + have hneigh : ∀ᶠ Y : G.matrixDomain in 𝓝 X, ∀e, + (G.resistance Y.val e ≤ s ↔ G.resistance X.val e ≤ s) := by + apply Filter.eventually_all.mpr + intro e + by_cases hle : G.resistance X.val e ≤ s + · have hlt := lt_of_le_of_ne hle (havoid e) + filter_upwards [(G.resistance_domain_continuous hn e).continuousAt.eventually_lt_const hlt] with Y hY + exact iff_of_true hY.le hle + · have hlt := lt_of_not_ge hle + filter_upwards [(G.resistance_domain_continuous hn e).continuousAt.eventually_const_lt hlt] with Y hY + exact iff_of_false (not_le.mpr hY) hle + obtain ⟨ε,hε,hball⟩ := Metric.mem_nhds_iff.mp hneigh + refine ⟨ε,hε,fun Y hY => ?_⟩ + ext e + simp only [thresholdEdges, mem_filter, mem_univ, true_and] + exact hball hY e + +theorem response_limit (hn : 2 ≤ n) (hc : G.EdgeConnected 1) (q : ℕ) {t δ : ℝ} (ht : 0 < t) + (hresponse : ∀X ∈ G.matrixDomain, ∃Y ∈ G.matrixDomain, ∀s : ℝ, + (((univ.filter (fun e => t < G.resistance Y e)) ∩ G.thresholdCrossing q X s).card:ℝ) ≤ + δ*(G.thresholdCrossing q X s).card) : + ∃X ∈ G.matrixDomain, ∀s : ℝ, (∀e, G.resistance X e ≠ s) → + (((G.thresholdCrossing q X s).filter (fun e => 2*t < G.resistance X e)).card:ℝ) ≤ + 2*δ*(G.thresholdCrossing q X s).card := by + classical + have hnp : 0 < n := by omega + have hK := G.domain_compact hn + have hne := G.domain_nonempty hnp hc + have hcv := G.domain_convex + have hr (X : G.matrixDomain) : ∃Y : G.matrixDomain, ∀s : ℝ, + (((univ.filter (fun e => t < G.resistance Y.val e)) ∩ G.thresholdCrossing q X.val s).card:ℝ) ≤ + δ*(G.thresholdCrossing q X.val s).card := by + obtain ⟨Y,hY,h⟩ := hresponse X.val X.property + exact ⟨⟨Y,hY⟩,h⟩ + choose R hR using hr + have heps (p : ℕ) : (0:ℝ) < 1/((p:ℝ)+1) := by positivity + choose Xp C w hw hw1 heq hnear using fun p => response_fixed_point hK hne hcv R (heps p) + let : CompactSpace G.matrixDomain := isCompact_iff_compactSpace.mp hK + let : FirstCountableTopology (Matrix (Fin n) (Fin n) ℝ) := + inferInstanceAs (FirstCountableTopology (Fin n → Fin n → ℝ)) + obtain ⟨X,_,φ,hφ,hlim⟩ := isCompact_univ.tendsto_subseq (x := Xp) (fun _ => Set.mem_univ _) + have hnearTime : Tendsto (fun p => 1/((φ p:ℝ)+1)+dist (Xp (φ p)) X) atTop (𝓝 0) := by + simpa only [Function.comp_apply, add_zero] using (tendsto_one_div_add_atTop_nhds_zero_nat.comp hφ.tendsto_atTop).add + (tendsto_iff_dist_tendsto_zero.mp hlim) + refine ⟨X.val,X.property,fun s havoid => ?_⟩ + let B := G.thresholdCrossing q X.val s + obtain ⟨ε,hε,hεspec⟩ := G.threshold_stable_neighborhood hnp X s havoid + have hstable : ∀ᶠ p in atTop, ∀c ∈ C (φ p), 0 < w (φ p) c → + G.thresholdCrossing q c.val s=B := by + filter_upwards [hnearTime.eventually_lt_const hε] with p hp + intro c hc hwc + have hd : dist c X < ε := by + have hh := hnear (φ p) c hc hwc + have htri := dist_triangle c (Xp (φ p)) X + linarith + unfold thresholdCrossing + rw [hεspec c hd] + rfl + have hcounts : ∀ᶠ p in atTop, + ((B.filter (fun e => 2*t < G.resistance (Xp (φ p)).val e)).card:ℝ) ≤ 2*δ*B.card := by + filter_upwards [hstable] with p hp + apply mixture_bad_bound B G.incidence (C (φ p)) (w (φ p)) (fun c => (R c).val) + (hw (φ p)) (hw1 (φ p)) (fun c _ => G.domain_pd hnp (R c).property) + (G.domain_pd hnp (Xp (φ p)).property) (heq (φ p)) ht + intro c hc hwc + have hh := hR c s + rw [hp c hc hwc,bad_inter_eq] at hh + exact hh + let Bad := B.filter (fun e => 2*t < G.resistance X.val e) + have hpersist : ∀ᶠ p in atTop, ∀e ∈ Bad, 2*t < G.resistance (Xp (φ p)).val e := by + apply (Filter.eventually_all_finset Bad).mpr + intro e he + have hgt := (mem_filter.mp he).2 + exact ((G.resistance_domain_continuous hnp e).tendsto X |>.comp hlim).eventually_const_lt hgt + obtain ⟨p,hp,hpers⟩ := (hcounts.and hpersist).exists + have hsub : Bad ⊆ B.filter (fun e => 2*t < G.resistance (Xp (φ p)).val e) := by + intro e he + exact mem_filter.mpr ⟨(mem_filter.mp he).1,hpers e he⟩ + exact (show (Bad.card:ℝ) ≤ (B.filter (fun e => 2*t < G.resistance (Xp (φ p)).val e)).card by + exact_mod_cast card_le_card hsub).trans hp + +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/FiniteSelection.lean b/lean/OAI/Combinatorics/ThinTrees/FiniteSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..96dd1f9e2e593e02731bc4133896d75cf8de1339 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/FiniteSelection.lean @@ -0,0 +1,117 @@ +import OAI.Combinatorics.ThinTrees.RealRoots + +namespace OAI + +universe uI uD uO + +section + +noncomputable section +open Matrix Polynomial Finset +open scoped MatrixOrder +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {O : Type uO} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [Fintype O] + +omit [DecidableEq D] in +lemma rankOne_posSemidef (v : D → ℝ) : (Matrix.vecMulVec v v).PosSemidef := by + simpa using Matrix.posSemidef_vecMulVec_self_star v + +lemma mixedChar_segment (j : I) (A : I → Matrix D D ℝ) (B : Matrix D D ℝ) (t : ℝ) : + (1-t) • mixedChar A+t • mixedChar (Function.update A j B)= + mixedChar (Function.update A j ((1-t) • A j+t • B)) := by + have hh := mixedChar_mean (O := Bool) j A (fun b => if b then t else 1-t) + (fun b => if b then B else A j) (by simp) + have hm : (∑b : Bool, (if b then t else 1-t) • (if b then B else A j))= + (1-t) • A j+t • B := by + rw [Fintype.sum_bool] + simp only [Bool.false_eq_true,↓reduceIte] + exact add_comm _ _ + rw [hm,Fintype.sum_bool] at hh + simp only [Bool.false_eq_true,↓reduceIte] at hh + rw [Function.update_eq_self] at hh + rw [hh] + exact add_comm _ _ + +omit [Fintype I] in +omit [DecidableEq D] in +lemma partial_posSemidef (s : Finset I) (A : I → Matrix D D ℝ) + (w : I → O → ℝ) (v : I → O → D → ℝ) (hw : ∀i o, 0 ≤ w i o) + (hA : ∀i ∈ s, A i=∑o, w i o • Matrix.vecMulVec (v i o) (v i o)) + (hfixed : ∀i, i ∉ s → ∃o, A i=Matrix.vecMulVec (v i o) (v i o)) : + ∀i, (A i).PosSemidef := by + intro i + by_cases hi : i ∈ s + · rw [hA i hi] + exact Matrix.posSemidef_sum _ (fun o _ => (rankOne_posSemidef _).smul (hw i o)) + · obtain ⟨o,ho⟩ := hfixed i hi + rw [ho] + exact rankOne_posSemidef _ + +lemma finite_selection_partial (s : Finset I) (A : I → Matrix D D ℝ) + (w : I → O → ℝ) (v : I → O → D → ℝ) (hw : ∀i o, 0 < w i o) + (hsum : ∀i, ∑o, w i o=1) + (hA : ∀i ∈ s, A i=∑o, w i o • Matrix.vecMulVec (v i o) (v i o)) + (hfixed : ∀i, i ∉ s → ∃o, A i=Matrix.vecMulVec (v i o) (v i o)) + {b : ℝ} (hroot : ∀r ∈ (mixedChar A).roots, r ≤ b) : + ∃f : I → O, ∀r ∈ (∑i, Matrix.vecMulVec (v i (f i)) (v i (f i))).charpoly.roots, r ≤ b := by + induction s using Finset.induction_on generalizing A with + | empty => + have hh : ∀i, ∃o, A i=Matrix.vecMulVec (v i o) (v i o) := fun i => hfixed i (by simp) + choose f hf using hh + refine ⟨f,?_⟩ + have hrank : ∀i, ∃a c, A i=Matrix.vecMulVec a c := fun i => ⟨_,_,hf i⟩ + rw [mixedChar_rankOne A hrank] at hroot + simpa only [hf] using hroot + | @insert j s hj ih => + let B : O → Matrix D D ℝ := fun o => Matrix.vecMulVec (v j o) (v j o) + let child : O → I → Matrix D D ℝ := fun o => Function.update A j (B o) + have hchildA : ∀o i, i ∈ s → child o i=∑a, w i a • Matrix.vecMulVec (v i a) (v i a) := by + intro o i hi + dsimp only [child] + rw [Function.update_of_ne (show i ≠ j from fun he => hj (he ▸ hi))] + exact hA i (Finset.mem_insert_of_mem hi) + have hchildfixed : ∀o i, i ∉ s → ∃a, child o i=Matrix.vecMulVec (v i a) (v i a) := by + intro o i hi + by_cases hij : i=j + · subst i; exact ⟨o,by simp [child,B]⟩ + · dsimp only [child] + rw [Function.update_of_ne hij] + exact hfixed i (by simp [hij,hi]) + have hmon : ∀o, (mixedChar (child o)).IsMonicOfDegree (Fintype.card D) := by + intro o + apply mixedChar_monic_partial s _ w v v hsum (hchildA o) + intro i hi + obtain ⟨a,ha⟩ := hchildfixed o i hi + exact ⟨_,_,ha⟩ + have hmean : (∑o, w j o • mixedChar (child o))=mixedChar A := by + rw [←mixedChar_mean j A (w j) B (hsum j),←hA j (by simp)] + simp + have hpsd := partial_posSemidef (insert j s) A w v (fun i o => (hw i o).le) hA hfixed + have hsplit : ∀o t, t ∈ Set.Icc (0 : ℝ) 1 → + ((1-t) • (∑a, w j a • mixedChar (child a))+t • mixedChar (child o)).Splits := by + intro o t ht + rw [hmean,mixedChar_segment] + apply mixedChar_splits + intro i + by_cases hij : i=j + · subst i + simp only [Function.update_self] + exact ((hpsd j).smul (sub_nonneg.mpr ht.2)).add ((rankOne_posSemidef _).smul ht.1) + · rw [Function.update_of_ne hij] + exact hpsd i + obtain ⟨o,ho⟩ := Selection.selection (fun o => mixedChar (child o)) hmon (w j) (hw j) (hsum j) + hsplit (by simpa only [hmean] using hroot) + exact ih (child o) (hchildA o) (hchildfixed o) ho + +lemma finite_selection (w : I → O → ℝ) (v : I → O → D → ℝ) + (hw : ∀i o, 0 < w i o) (hsum : ∀i, ∑o, w i o=1) + {b : ℝ} (hroot : ∀r ∈ (mixedChar (fun i => ∑o, w i o • Matrix.vecMulVec (v i o) (v i o))).roots, r ≤ b) : + ∃f : I → O, ∀r ∈ (∑i, Matrix.vecMulVec (v i (f i)) (v i (f i))).charpoly.roots, r ≤ b := + finite_selection_partial Finset.univ _ w v hw hsum (by intros; rfl) (by simp) hroot + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/FixedPoint.lean b/lean/OAI/Combinatorics/ThinTrees/FixedPoint.lean new file mode 100644 index 0000000000000000000000000000000000000000..a3a60c2bd27279cfdc9eb5623f1dad3b67da647e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/FixedPoint.lean @@ -0,0 +1,841 @@ +import OAI.Combinatorics.ThinTrees.SimultaneousResponse + +namespace OAI + +universe uV uV2 uW uI uV3 uV4 uV5 uE + +section + +namespace StrongThinTree.FixedPoint +noncomputable section +open Finset + +abbrev Chain (V : Type uV) := Finset V →₀ ZMod 2 + +variable {V : Type uV2} {W : Type uW} [DecidableEq V] [DecidableEq W] + +def face (s : Finset V) : Chain V := Finsupp.single s 1 + +def boundary : Chain V →ₗ[ZMod 2] Chain V := + Finsupp.linearCombination (ZMod 2) (fun s : Finset V => ∑ v ∈ s, face (s.erase v)) + +lemma boundary_face (s : Finset V) : boundary (face s) = ∑ v ∈ s, face (s.erase v) := by + simp [face, boundary] + +lemma boundary_empty : boundary (face (∅ : Finset V)) = 0 := by + simp [boundary_face] + +def cone (v : V) : Chain V →ₗ[ZMod 2] Chain V := + Finsupp.linearCombination (ZMod 2) (fun s : Finset V => + if v ∈ s then 0 else face (insert v s)) + +lemma cone_face (v : V) (s : Finset V) : + cone v (face s) = if v ∈ s then 0 else face (insert v s) := by + simp [cone, face] + +omit [DecidableEq V] in +lemma add_self (c : Chain V) : c + c = 0 := by + ext s + exact CharTwo.add_self_eq_zero (c s) + +lemma boundary_cone_face (v : V) (s : Finset V) : + boundary (cone v (face s)) + cone v (boundary (face s)) = face s := by + classical + by_cases hv : v ∈ s + · rw [cone_face, ite_eq_left hv, map_zero, zero_add, boundary_face, map_sum] + rw [Finset.sum_eq_single_of_mem v hv] + · rw [cone_face, ite_eq_right (by simp), Finset.insert_erase hv] + · intro w hw hwv + rw [cone_face, ite_eq_left (Finset.mem_erase.mpr ⟨Ne.symm hwv, hv⟩)] + · rw [cone_face, ite_eq_right hv, boundary_face, Finset.sum_insert hv, Finset.erase_insert hv, + boundary_face, map_sum] + simp only [cone_face] + have heq : (∑ w ∈ s, face ((insert v s).erase w)) = + ∑ w ∈ s, if v ∈ s.erase w then 0 else face (insert v (s.erase w)) := by + apply Finset.sum_congr rfl + intro w hw + rw [ite_eq_right (fun h => hv (Finset.mem_of_mem_erase h)), + Finset.erase_insert_of_ne (ne_of_mem_of_not_mem hw hv).symm] + rw [heq, add_assoc, add_self, add_zero] + +lemma boundary_cone (v : V) (c : Chain V) : + boundary (cone v c) + cone v (boundary c) = c := by + have h : boundary.comp (cone v) + (cone v).comp boundary = + (LinearMap.id : Chain V →ₗ[ZMod 2] Chain V) := by + apply Finsupp.lhom_ext' + intro s + apply LinearMap.ext_ring + simpa [face] using boundary_cone_face v s + exact congrArg (fun f : Chain V →ₗ[ZMod 2] Chain V => f c) h + +lemma boundary_cone_eq (v : V) (c : Chain V) : + boundary (cone v c) = c + cone v (boundary c) := by + have h := congrArg (fun z => z + cone v (boundary c)) (boundary_cone v c) + simpa only [add_assoc, add_self, add_zero] using h + +lemma boundary_boundary_face (s : Finset V) : boundary (boundary (face s)) = 0 := by + induction s using Finset.induction_on with + | empty => simp [boundary_empty] + | @insert v s hv ih => + have hs : face (insert v s) = cone v (face s) := by simp [cone_face, hv] + rw [hs, boundary_cone_eq, map_add, boundary_cone_eq, ih, map_zero, add_zero, + add_self] + +lemma boundary_boundary (c : Chain V) : boundary (boundary c) = 0 := by + have h : boundary.comp boundary = (0 : Chain V →ₗ[ZMod 2] Chain V) := by + apply Finsupp.lhom_ext' + intro s + apply LinearMap.ext_ring + simpa [face] using boundary_boundary_face s + exact congrArg (fun f : Chain V →ₗ[ZMod 2] Chain V => f c) h + +def subdivFace (s : Finset V) : Chain (Finset V) := + if _hs : s = ∅ then face ∅ else + cone s (∑ v : s, subdivFace (s.erase v.1)) +termination_by s.card +decreasing_by exact Finset.card_erase_lt_of_mem v.2 + +def subdivision : Chain V →ₗ[ZMod 2] Chain (Finset V) := + Finsupp.linearCombination (ZMod 2) subdivFace + +lemma subdivision_face (s : Finset V) : subdivision (face s) = subdivFace s := by + simp [subdivision, face] + +lemma subdiv_empty : subdivFace (∅ : Finset V) = face ∅ := by rw [subdivFace, dite_eq_left rfl] + +lemma subdiv_nonempty (s : Finset V) (hs : s.Nonempty) : + subdivFace s = cone s (subdivision (boundary (face s))) := by + rw [subdivFace, dite_eq_right hs.ne_empty, boundary_face] + simp only [map_sum, subdivision_face] + exact Finset.sum_coe_sort s (fun v => cone s (subdivFace (s.erase v))) + +lemma boundary_subdivFace (s : Finset V) : + boundary (subdivFace s) = subdivision (boundary (face s)) := by + induction s using Finset.strongInductionOn with + | _ s ih => + by_cases hs : s = ∅ + · subst s + simp [subdiv_empty, boundary_empty] + · rw [subdiv_nonempty s (Finset.nonempty_iff_ne_empty.mpr hs), boundary_cone_eq] + suffices boundary (subdivision (boundary (face s))) = 0 by simp [this] + rw [boundary_face, map_sum, map_sum] + simp only [subdivision_face] + have heq : (∑ v ∈ s, boundary (subdivFace (s.erase v))) = + subdivision (boundary (boundary (face s))) := by + rw [boundary_face, map_sum, map_sum] + apply Finset.sum_congr rfl + intro v hv + exact ih (s.erase v) (Finset.erase_ssubset hv) + rw [heq, boundary_boundary, map_zero] + +lemma boundary_subdivision (c : Chain V) : + boundary (subdivision c) = subdivision (boundary c) := by + have h : (boundary : Chain (Finset V) →ₗ[ZMod 2] Chain (Finset V)).comp subdivision = + (subdivision : Chain V →ₗ[ZMod 2] _).comp boundary := by + apply Finsupp.lhom_ext' + intro s + apply LinearMap.ext_ring + change boundary (subdivision (face s)) = subdivision (boundary (face s)) + rw [subdivision_face] + exact boundary_subdivFace s + exact congrArg (fun f : Chain V →ₗ[ZMod 2] Chain (Finset V) => f c) h + +def rename (f : V → W) : Chain V →ₗ[ZMod 2] Chain W := by + classical + exact Finsupp.linearCombination (ZMod 2) (fun s : Finset V => + if Set.InjOn f (s : Set V) then face (s.image f) else 0) + +omit [DecidableEq V] in +lemma rename_face (f : V → W) (s : Finset V) : + rename f (face s) = if Set.InjOn f (s : Set V) then face (s.image f) else 0 := by + classical + simp [rename, face] + +lemma rename_cone_face (f : V → W) (v : V) (s : Finset V) : + rename f (cone v (face s)) = cone (f v) (rename f (face s)) := by + classical + by_cases hv : v ∈ s + · rw [cone_face, ite_eq_left hv, map_zero, rename_face] + split_ifs with h + · simp [cone_face, Finset.mem_image_of_mem f hv] + · simp + · rw [cone_face, ite_eq_right hv, rename_face, rename_face] + have hinj : Set.InjOn f (↑(insert v s) : Set V) ↔ + Set.InjOn f (s : Set V) ∧ f v ∉ s.image f := by + simpa using (Set.injOn_insert (f := f) (s := (s : Set V)) hv) + simp only [hinj] + by_cases hs : Set.InjOn f (s : Set V) + · by_cases hf : f v ∈ s.image f + · simp [hs, hf, cone_face] + · simp [hs, hf, cone_face, Finset.image_insert] + · simp [hs] + +lemma rename_cone (f : V → W) (v : V) (c : Chain V) : + rename f (cone v c) = cone (f v) (rename f c) := by + have h : (rename f).comp (cone v) = (cone (f v)).comp (rename f) := by + apply Finsupp.lhom_ext' + intro s + apply LinearMap.ext_ring + simpa [face] using rename_cone_face f v s + exact congrArg (fun g : Chain V →ₗ[ZMod 2] Chain W => g c) h + +lemma boundary_rename_face (f : V → W) (s : Finset V) : + boundary (rename f (face s)) = rename f (boundary (face s)) := by + classical + induction s using Finset.induction_on with + | empty => simp [rename_face, boundary_empty] + | @insert v s hv ih => + have heq : face (insert v s) = cone v (face s) := by simp [cone_face, hv] + rw [heq, rename_cone, boundary_cone_eq, boundary_cone_eq, map_add, rename_cone, ih] + +lemma boundary_rename (f : V → W) (c : Chain V) : + boundary (rename f c) = rename f (boundary c) := by + have h : boundary.comp (rename f) = (rename f).comp boundary := by + apply Finsupp.lhom_ext' + intro s + apply LinearMap.ext_ring + simpa [face] using boundary_rename_face f s + exact congrArg (fun g : Chain V →ₗ[ZMod 2] Chain W => g c) h + +def Supported (P : Finset V → Prop) (c : Chain V) : Prop := + ∀ s, ¬ P s → c s = 0 + +omit [DecidableEq V] in +lemma supported_zero (P : Finset V → Prop) : Supported P 0 := by + intro s hs; rfl + +omit [DecidableEq V] in +lemma supported_face {P : Finset V → Prop} {s : Finset V} (hs : P s) : + Supported P (face s) := by + intro t ht + have hne : s ≠ t := fun h => ht (h ▸ hs) + simp [face, Ne.symm hne] + +omit [DecidableEq V] in +lemma supported_add {P : Finset V → Prop} {c d : Chain V} + (hc : Supported P c) (hd : Supported P d) : Supported P (c + d) := by + intro s hs + simp [hc s hs, hd s hs] + +omit [DecidableEq V] in +lemma supported_smul {P : Finset V → Prop} {c : Chain V} + (hc : Supported P c) (a : ZMod 2) : Supported P (a • c) := by + intro s hs + simp [hc s hs] + +omit [DecidableEq V] in +lemma supported_sum {I : Type uI} (s : Finset I) (f : I → Chain V) + {P : Finset V → Prop} (h : ∀i ∈ s, Supported P (f i)) : + Supported P (∑ i ∈ s, f i) := by + classical + induction s using Finset.induction_on with + | empty => simpa using supported_zero P + | @insert i s hi ih => + rw [Finset.sum_insert hi] + exact supported_add (h i (Finset.mem_insert_self ..)) + (ih (fun j hj => h j (Finset.mem_insert_of_mem hj))) + +omit [DecidableEq V] in +lemma chain_expansion (c : Chain V) : c = ∑ s ∈ c.support, c s • face s := by + simpa [Finsupp.sum, face] using (Finsupp.sum_single c).symm + +omit [DecidableEq V] in +omit [DecidableEq W] in +lemma supported_map (L : Chain V →ₗ[ZMod 2] Chain W) + {P : Finset V → Prop} {Q : Finset W → Prop} {c : Chain V} + (hc : Supported P c) (hL : ∀s, P s → Supported Q (L (face s))) : + Supported Q (L c) := by + classical + rw [chain_expansion c, map_sum] + apply supported_sum + intro s hs + rw [map_smul] + apply supported_smul + apply hL s + by_contra hn + exact (Finsupp.mem_support_iff.mp hs) (hc s hn) + +lemma supported_cone (v : V) {P Q : Finset V → Prop} {c : Chain V} + (hc : Supported P c) (h : ∀ s, P s → v ∉ s → Q (insert v s)) : + Supported Q (cone v c) := by + apply supported_map (cone v) hc + intro s hs + rw [cone_face] + split_ifs with hv + · exact supported_zero Q + · exact supported_face (h s hs hv) + +omit [DecidableEq V] in +lemma supported_mono {P Q : Finset V → Prop} {c : Chain V} + (hc : Supported P c) (h : ∀s, P s → Q s) : Supported Q c := by + intro s hs + exact hc s (fun hp => hs (h s hp)) + +def Flag (s : Finset V) (t : Finset (Finset V)) : Prop := + t.card = s.card ∧ (∀ a ∈ t, a.Nonempty ∧ a ⊆ s) ∧ + ∀ a ∈ t, ∀ b ∈ t, a ⊆ b ∨ b ⊆ a + +lemma subdiv_supported (s : Finset V) : Supported (Flag s) (subdivFace s) := by + induction s using Finset.strongInductionOn with + | _ s ih => + by_cases hs : s = ∅ + · subst s + rw [subdiv_empty] + apply supported_face + simp [Flag] + · rw [subdiv_nonempty s (Finset.nonempty_iff_ne_empty.mpr hs), boundary_face] + simp only [map_sum, subdivision_face] + apply supported_sum + intro v hv + apply supported_cone s (ih (s.erase v) (Finset.erase_ssubset hv)) + intro t ht hst + rcases ht with ⟨hcard, hsub, hnest⟩ + refine ⟨?_, ?_, ?_⟩ + · rw [Finset.card_insert_of_notMem hst, hcard, Finset.card_erase_of_mem hv] + have hpos : 0 < s.card := Finset.card_pos.mpr ⟨v, hv⟩ + omega + · intro a ha + rcases Finset.mem_insert.mp ha with ha | ha + · subst a + exact ⟨Finset.nonempty_iff_ne_empty.mpr hs, Finset.Subset.refl s⟩ + · exact ⟨(hsub a ha).1, (hsub a ha).2.trans (Finset.erase_subset v s)⟩ + · intro a ha b hb + rcases Finset.mem_insert.mp ha with ha | ha + · subst a + rcases Finset.mem_insert.mp hb with hb | hb + · subst b + exact Or.inl (Finset.Subset.refl s) + · exact Or.inr ((hsub b hb).2.trans (Finset.erase_subset v s)) + · rcases Finset.mem_insert.mp hb with hb | hb + · subst b + exact Or.inl ((hsub a ha).2.trans (Finset.erase_subset v s)) + · exact hnest a ha b hb + +omit [DecidableEq V] in +lemma supported_rename (f : V → W) {P : Finset V → Prop} {Q : Finset W → Prop} + {c : Chain V} (hc : Supported P c) + (h : ∀s, P s → Set.InjOn f (s : Set V) → Q (s.image f)) : + Supported Q (rename f c) := by + classical + apply supported_map (rename f) hc + intro s hs + rw [rename_face] + split_ifs with hf + · exact supported_face (h s hs hf) + · exact supported_zero Q + +lemma boundary_face_erase {s : Finset V} {v : V} (hv : v ∈ s) : + boundary (face s) (s.erase v) = 1 := by + classical + rw [boundary_face, Finsupp.finsetSum_apply] + rw [Finset.sum_eq_single_of_mem v hv] + · simp [face] + · intro w hw hwv + have hne : s.erase w ≠ s.erase v := fun h => hwv ((Finset.erase_inj s hw).mp h) + simp [face, Ne.symm hne] + +lemma supported_singleton_eq {c : Chain V} {s : Finset V} + (hc : Supported (fun t => t = s) c) : c = c s • face s := by + ext t + by_cases ht : t = s + · subst t; simp [face] + · simp [hc t ht, face, ht] + +theorem sperner_chain (F : Chain V →ₗ[ZMod 2] Chain W) (f : W → V) + (hboundary : ∀c, boundary (F c) = F (boundary c)) + (hempty : F (face ∅) = face ∅) (s : Finset V) + (hcarrier : ∀u ⊆ s, Supported + (fun t => t.card = u.card ∧ ∀w ∈ t, f w ∈ u) (F (face u))) : + rename f (F (face s)) = face s := by + classical + induction s using Finset.strongInductionOn with + | _ s ih => + by_cases hs : s = ∅ + · subst s + rw [hempty] + simp [rename_face] + · have hsupport : Supported (fun t => t = s) (rename f (F (face s))) := by + apply supported_rename f (hcarrier s (Finset.Subset.refl s)) + intro t ht hf + apply Finset.eq_of_subset_of_card_le + · intro v hv + obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp hv + exact ht.2 w hw + · rw [Finset.card_image_of_injOn hf, ht.1] + have hb : boundary (rename f (F (face s))) = boundary (face s) := by + rw [boundary_rename, hboundary, boundary_face] + simp only [map_sum] + apply Finset.sum_congr rfl + intro v hv + exact ih (s.erase v) (Finset.erase_ssubset hv) + (fun u hu => hcarrier u (hu.trans (Finset.erase_subset v s))) + obtain ⟨v, hv⟩ := Finset.nonempty_iff_ne_empty.mpr hs + have heq := supported_singleton_eq hsupport + rw [heq, map_smul] at hb + have hcoeff := congrArg (fun c : Chain V => c (s.erase v)) hb + simp only [Finsupp.smul_apply, smul_eq_mul, boundary_face_erase hv, mul_one] at hcoeff + rw [heq, hcoeff, one_smul] + +omit [DecidableEq W] in +omit [DecidableEq V] in +lemma map_coefficient_witness (L : Chain V →ₗ[ZMod 2] Chain W) + (c : Chain V) (s : Finset W) (hs : (L c) s ≠ 0) : + ∃t ∈ c.support, (L (face t)) s ≠ 0 := by + classical + by_contra! hn + apply hs + conv_lhs => rw [chain_expansion c] + rw [map_sum, Finsupp.finsetSum_apply] + apply Finset.sum_eq_zero + intro t ht + simp [map_smul, hn t ht] + +theorem sperner_witness (F : Chain V →ₗ[ZMod 2] Chain W) (f : W → V) + (hboundary : ∀c, boundary (F c) = F (boundary c)) + (hempty : F (face ∅) = face ∅) (s : Finset V) + (hcarrier : ∀u ⊆ s, Supported + (fun t => t.card = u.card ∧ ∀w ∈ t, f w ∈ u) (F (face u))) : + ∃t ∈ (F (face s)).support, Set.InjOn f (t : Set W) ∧ t.image f = s := by + classical + have hmain := sperner_chain F f hboundary hempty s hcarrier + have hcoeff : (rename f (F (face s))) s ≠ 0 := by rw [hmain]; simp [face] + obtain ⟨t, ht, hn⟩ := map_coefficient_witness (rename f) (F (face s)) s hcoeff + rw [rename_face] at hn + split_ifs at hn with hf + · refine ⟨t, ht, hf, ?_⟩ + by_contra heq + exact hn (by simp [face, Ne.symm heq]) + · exact (hn rfl).elim + +def IterV (V : Type uV3) : ℕ → Type _ + | 0 => V + | k+1 => Finset (IterV V k) + +instance iterVDecidableEq (V : Type uV4) [DecidableEq V] : + (k : ℕ) → DecidableEq (IterV V k) + | 0 => inferInstanceAs (DecidableEq V) + | k+1 => letI := iterVDecidableEq V k + inferInstanceAs (DecidableEq (Finset (IterV V k))) + +def iterSubdivision : (k : ℕ) → Chain V →ₗ[ZMod 2] Chain (IterV V k) + | 0 => LinearMap.id + | k+1 => subdivision.comp (iterSubdivision k) + +lemma boundary_iterSubdivision (k : ℕ) (c : Chain V) : + boundary (iterSubdivision k c) = iterSubdivision k (boundary c) := by + induction k with + | zero => rfl + | succ k ih => + change boundary (subdivision (iterSubdivision k c)) = + subdivision (iterSubdivision k (boundary c)) + rw [boundary_subdivision, ih] + +lemma iterSubdivision_empty (k : ℕ) : + iterSubdivision k (face (∅ : Finset V)) = face ∅ := by + induction k with + | zero => rfl + | succ k ih => + change subdivision (iterSubdivision k (face (∅ : Finset V))) = face ∅ + rw [ih, subdivision_face, subdiv_empty] + +def mean (z : V → ℝ) (s : Finset V) : ℝ := (∑ v ∈ s, z v) / s.card + +omit [DecidableEq V] in +lemma mean_nonneg {z : V → ℝ} {s : Finset V} (h : ∀v ∈ s, 0 ≤ z v) : + 0 ≤ mean z s := div_nonneg (Finset.sum_nonneg h) (Nat.cast_nonneg _) + +omit [DecidableEq V] in +lemma mean_zero {z : V → ℝ} {s : Finset V} (h : ∀v ∈ s, z v = 0) : + mean z s = 0 := by simp [mean, Finset.sum_eq_zero h] + +omit [DecidableEq V] in +lemma mean_difference (z : V → ℝ) (a b : Finset V) (ha : a.Nonempty) + (hb : b.Nonempty) : + mean z a - mean z b = + (∑ w ∈ a ×ˢ b, (z w.1 - z w.2)) / ((a.card : ℝ) * b.card) := by + have hac : (a.card : ℝ) ≠ 0 := by exact_mod_cast ha.card_ne_zero + have hbc : (b.card : ℝ) ≠ 0 := by exact_mod_cast hb.card_ne_zero + have hsum : (∑ w ∈ a ×ˢ b, (z w.1 - z w.2)) = + (b.card : ℝ) * (∑v ∈ a, z v) - (a.card : ℝ) * (∑v ∈ b, z v) := by + rw [Finset.sum_product] + simp only [Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul] + simp only [Finset.mul_sum] + rw [hsum] + unfold mean + field_simp + +lemma mean_mesh {z : V → ℝ} {a b t : Finset V} {N : ℕ} {D : ℝ} + (ha : a ⊆ t) (hb : b ⊆ t) (hab : (a ∩ b).Nonempty) + (ht : t.card ≤ N) (hD : 0 ≤ D) + (hz : ∀u ∈ t, ∀v ∈ t, |z u - z v| ≤ D) : + |mean z a - mean z b| ≤ (1 - 1 / (N : ℝ)^2) * D := by + classical + obtain ⟨w, hw⟩ := hab + obtain ⟨hwa, hwb⟩ := Finset.mem_inter.mp hw + have hane : a.Nonempty := ⟨w, hwa⟩ + have hbne : b.Nonempty := ⟨w, hwb⟩ + have hac : 0 < (a.card : ℝ) := by exact_mod_cast hane.card_pos + have hbc : 0 < (b.card : ℝ) := by exact_mod_cast hbne.card_pos + have hprod : 0 < (a.card : ℝ) * b.card := mul_pos hac hbc + have hN : 0 < (N : ℝ) := by + have : 0 < N := lt_of_lt_of_le hane.card_pos ((Finset.card_le_card ha).trans ht) + exact_mod_cast this + have hbound : (a.card : ℝ) * b.card ≤ (N : ℝ)^2 := by + have h1 : (a.card : ℝ) ≤ N := by exact_mod_cast (Finset.card_le_card ha).trans ht + have h2 : (b.card : ℝ) ≤ N := by exact_mod_cast (Finset.card_le_card hb).trans ht + nlinarith [mul_le_mul h1 h2 hbc.le hN.le] + have hwprod : (w,w) ∈ a ×ˢ b := Finset.mem_product.mpr ⟨hwa,hwb⟩ + have hsum : |∑ p ∈ a ×ˢ b, (z p.1 - z p.2)| ≤ + ((a.card : ℝ) * b.card - 1) * D := by + rw [← Finset.sum_erase_add _ _ hwprod] + simp only [sub_self, add_zero] + calc + |∑ p ∈ (a ×ˢ b).erase (w,w), (z p.1 - z p.2)| ≤ + ∑ p ∈ (a ×ˢ b).erase (w,w), |z p.1 - z p.2| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _p ∈ (a ×ˢ b).erase (w,w), D := by + apply Finset.sum_le_sum + intro p hp + obtain ⟨hu,hv⟩ := Finset.mem_product.mp (Finset.mem_of_mem_erase hp) + exact hz p.1 (ha hu) p.2 (hb hv) + _ = ((a.card : ℝ) * b.card - 1) * D := by + simp only [Finset.sum_const, nsmul_eq_mul] + congr 1 + rw [Finset.card_erase_of_mem hwprod, Nat.cast_sub (Finset.card_pos.mpr ⟨_, hwprod⟩), + Finset.card_product, Nat.cast_mul, Nat.cast_one] + rw [mean_difference z a b hane hbne, abs_div, abs_of_pos hprod] + apply le_trans (div_le_div_of_nonneg_right hsum hprod.le) + apply (div_le_iff₀ hprod).mpr + have hNsq : 0 < (N : ℝ)^2 := sq_pos_of_pos hN + have hrat : ((a.card : ℝ) * b.card) / (N : ℝ)^2 ≤ 1 := + (div_le_one hNsq).mpr hbound + have : (((a.card : ℝ) * b.card) / (N : ℝ)^2) * D ≤ D := + (mul_le_mul_of_nonneg_right hrat hD).trans_eq (one_mul D) + nlinarith [show (1 / (N : ℝ)^2) * ((a.card : ℝ) * b.card) = + ((a.card : ℝ) * b.card) / (N : ℝ)^2 by ring] + +section Coordinates +variable [Fintype V] + +def CoordFace (s : Finset V) (x : V → ℝ) : Prop := + (∀i, 0 ≤ x i) ∧ (∑i, x i) = 1 ∧ ∀i, i ∉ s → x i = 0 + +def baryPoint (p : W → V → ℝ) (s : Finset W) : V → ℝ := + fun i => mean (fun w => p w i) s + +omit [DecidableEq V] in +omit [DecidableEq W] in +lemma coordFace_bary {s : Finset V} {t : Finset W} {p : W → V → ℝ} + (ht : t.Nonempty) (hp : ∀w ∈ t, CoordFace s (p w)) : + CoordFace s (baryPoint p t) := by + refine ⟨?_, ?_, ?_⟩ + · intro i + exact mean_nonneg (fun w hw => (hp w hw).1 i) + · change (∑i, (∑w ∈ t, p w i) / (t.card : ℝ)) = 1 + rw [← Finset.sum_div, Finset.sum_comm] + have hsum : (∑w ∈ t, ∑i, p w i) = (t.card : ℝ) := by + calc + _ = ∑_w ∈ t, (1 : ℝ) := Finset.sum_congr rfl (fun w hw => (hp w hw).2.1) + _ = _ := by simp + rw [hsum, div_self] + exact_mod_cast ht.card_ne_zero + · intro i hi + exact mean_zero (fun w hw => (hp w hw).2.2 i hi) + +def iterPoint : (k : ℕ) → IterV V k → V → ℝ + | 0 => fun (v : V) i => if v = i then 1 else 0 + | k+1 => baryPoint (iterPoint k) + +def meshFactor (N : ℕ) : ℝ := 1 - 1 / (N : ℝ)^2 + +lemma meshFactor_nonneg {N : ℕ} (hN : 0 < N) : 0 ≤ meshFactor N := by + have hn : (1 : ℝ) ≤ N := by exact_mod_cast hN + have hs : 0 < (N : ℝ)^2 := by positivity + unfold meshFactor + have hsq : (1 : ℝ) ≤ (N : ℝ)^2 := by nlinarith + exact sub_nonneg.mpr ((div_le_one hs).mpr hsq) + +lemma meshFactor_lt_one {N : ℕ} (hN : 0 < N) : meshFactor N < 1 := by + have hn : (0 : ℝ) < N := by exact_mod_cast hN + unfold meshFactor + have : 0 < 1 / (N : ℝ)^2 := by positivity + linarith + +def GeometricFacet (k : ℕ) (s : Finset V) (t : Finset (IterV V k)) : Prop := + t.card = s.card ∧ (∀v ∈ t, CoordFace s (iterPoint k v)) ∧ + ∀u ∈ t, ∀v ∈ t, ∀i, + |iterPoint k u i - iterPoint k v i| ≤ (meshFactor (Fintype.card V))^k + +lemma iterSubdivision_supported (hV : 0 < Fintype.card V) (k : ℕ) (s : Finset V) : + Supported (GeometricFacet k s) (iterSubdivision k (face s)) := by + classical + induction k with + | zero => + change Supported (GeometricFacet 0 s) (face s) + apply supported_face + refine ⟨rfl, ?_, ?_⟩ + · intro v hv + change V at v + refine ⟨?_, ?_, ?_⟩ + · intro i + simp only [iterPoint] + split_ifs <;> norm_num + · simp [iterPoint] + · intro i hi + have hne : v ≠ i := fun h => hi (h ▸ hv) + simp only [iterPoint] + exact ite_eq_right hne + · intro u hu v hv i + simp only [iterPoint, pow_zero] + split_ifs <;> norm_num + | succ k ih => + change Supported (GeometricFacet (k+1) s) + (subdivision (iterSubdivision k (face s))) + apply supported_map subdivision ih + intro t ht + rw [subdivision_face] + apply supported_mono (subdiv_supported t) + intro u hu + refine ⟨hu.1.trans ht.1, ?_, ?_⟩ + · intro a ha + exact coordFace_bary (hu.2.1 a ha).1 + (fun w hw => ht.2.1 w ((hu.2.1 a ha).2 hw)) + · intro a ha b hb i + change Finset (IterV V k) at a b + have hab : (a ∩ b).Nonempty := by + rcases hu.2.2 a ha b hb with hab | hba + · obtain ⟨w, hw⟩ := (hu.2.1 a ha).1 + exact ⟨w, Finset.mem_inter.mpr ⟨hw, hab hw⟩⟩ + · obtain ⟨w, hw⟩ := (hu.2.1 b hb).1 + exact ⟨w, Finset.mem_inter.mpr ⟨hba hw, hw⟩⟩ + have hcard : t.card ≤ Fintype.card V := by + rw [ht.1] + exact Finset.card_le_univ s + have hm := mean_mesh (z := fun w => iterPoint k w i) + (hu.2.1 a ha).2 (hu.2.1 b hb).2 hab hcard + (pow_nonneg (meshFactor_nonneg hV) k) + (fun v hv w hw => ht.2.2 v hv w hw i) + simpa [iterPoint, baryPoint, meshFactor, pow_succ, mul_comm] using hm + +def simplex (V : Type uV5) [Fintype V] : Set (V → ℝ) := + {x | (∀ i, 0 ≤ x i) ∧ ∑ i, x i = 1} + +omit [DecidableEq V] in + +lemma simplex_label {x y : V → ℝ} + (hx : x ∈ simplex V) (hy : y ∈ simplex V) : + ∃i, 0 < x i ∧ y i ≤ x i := by + by_contra! hn + have hex : ∃i, 0 < x i := by + by_contra! h + have hs := Finset.sum_nonpos (s := (univ : Finset V)) (fun i _ => h i) + rw [hx.2] at hs + norm_num at hs + obtain ⟨i, hi⟩ := hex + have hle : ∀j, x j ≤ y j := by + intro j + by_cases hj : 0 < x j + · exact (hn j hj).le + · have he : x j = 0 := le_antisymm (not_lt.mp hj) (hx.1 j) + rw [he] + exact hy.1 j + have hs := Finset.sum_lt_sum (fun j (_ : j ∈ (univ : Finset V)) => hle j) + ⟨i, mem_univ i, hn i hi⟩ + rw [hx.2, hy.2] at hs + exact (lt_irrefl (1 : ℝ)) hs + +abbrev Delta (V : Type uV5) [Fintype V] := {x : V → ℝ // x ∈ simplex V} + +theorem simplex_approximation [Nonempty V] (F : Delta V → Delta V) (k : ℕ) : + ∃ x : V → Delta V, (∀i, (F (x i)).1 i ≤ (x i).1 i) ∧ + ∀i j a, |(x i).1 a - (x j).1 a| ≤ (meshFactor (Fintype.card V))^k := by + classical + let label : IterV V k → V := fun v => + if h : iterPoint k v ∈ simplex V then + (simplex_label h (F ⟨iterPoint k v, h⟩).2).choose + else Classical.choice inferInstance + have hlabel (v : IterV V k) (hv : iterPoint k v ∈ simplex V) : + 0 < iterPoint k v (label v) ∧ + (F ⟨iterPoint k v, hv⟩).1 (label v) ≤ iterPoint k v (label v) := by + dsimp [label] + rw [dite_eq_left hv] + exact (simplex_label hv (F ⟨iterPoint k v, hv⟩).2).choose_spec + have hV : 0 < Fintype.card V := Fintype.card_pos + have hcarrier (u : Finset V) (_ : u ⊆ univ) : + Supported (fun t => t.card = u.card ∧ ∀w ∈ t, label w ∈ u) + (iterSubdivision k (face u)) := by + apply supported_mono (iterSubdivision_supported hV k u) + intro t ht + refine ⟨ht.1, ?_⟩ + intro w hw + have hp := ht.2.1 w hw + have hl := (hlabel w ⟨hp.1, hp.2.1⟩).1 + by_contra hn + rw [hp.2.2 _ hn] at hl + exact (lt_irrefl 0) hl + obtain ⟨t, ht, _, heq⟩ := sperner_witness (iterSubdivision k) label + (boundary_iterSubdivision k) (iterSubdivision_empty k) univ hcarrier + have hgeom : GeometricFacet k univ t := by + by_contra hn + exact (Finsupp.mem_support_iff.mp ht) + (iterSubdivision_supported hV k univ t hn) + have hpre : ∀i : V, ∃v ∈ t, label v = i := by + intro i + have : i ∈ t.image label := heq ▸ mem_univ i + exact mem_image.mp this + choose v hv hl using hpre + let x : V → Delta V := fun i => + ⟨iterPoint k (v i), (hgeom.2.1 (v i) (hv i)).1, + (hgeom.2.1 (v i) (hv i)).2.1⟩ + refine ⟨x, ?_, ?_⟩ + · intro i + have hi := (hlabel (v i) (x i).2).2 + simpa only [hl i] using hi + · intro i j a + exact hgeom.2.2 (v i) (hv i) (v j) (hv j) a + +theorem simplex_fixed_point [Nonempty V] (F : Delta V → Delta V) (hF : Continuous F) : + ∃x, F x = x := by + classical + have hclosed : IsClosed (simplex V) := by + have heq : simplex V = (⋂ i : V, {x : V → ℝ | 0 ≤ x i}) ∩ + {x : V → ℝ | ∑ i, x i = 1} := by + ext x + simp [simplex] + rw [heq] + exact (isClosed_iInter fun i => isClosed_le continuous_const (continuous_apply i)).inter + (isClosed_eq (by fun_prop) continuous_const) + have hcompact : IsCompact (simplex V) := + IsCompact.of_isClosed_subset (s := Set.Icc (0 : V → ℝ) 1) isCompact_Icc hclosed (by + intro x hx + refine ⟨hx.1, fun i => ?_⟩ + change x i ≤ 1 + exact hx.2 ▸ Finset.single_le_sum (fun j _ => hx.1 j) (Finset.mem_univ i)) + let : CompactSpace (Delta V) := isCompact_iff_compactSpace.mp hcompact + choose x hlabel hmesh using simplex_approximation F + let i₀ : V := Classical.choice inferInstance + obtain ⟨z, _, φ, hφ, hz⟩ := isCompact_univ.tendsto_subseq + (x := fun k => x k i₀) (fun _ => Set.mem_univ _) + have hq0 := meshFactor_nonneg (Fintype.card_pos (α := V)) + have hq1 := meshFactor_lt_one (Fintype.card_pos (α := V)) + have hpow := (tendsto_pow_atTop_nhds_zero_of_lt_one hq0 hq1).comp hφ.tendsto_atTop + have hdist (n : ℕ) (i : V) : + dist (x (φ n) i) (x (φ n) i₀) ≤ (meshFactor (Fintype.card V))^(φ n) := by + change dist (x (φ n) i).1 (x (φ n) i₀).1 ≤ _ + apply (dist_pi_le_iff (pow_nonneg hq0 _)).mpr + intro a + exact hmesh (φ n) i i₀ a + have hlim (i : V) : Filter.Tendsto (fun n => x (φ n) i) Filter.atTop (nhds z) := by + apply tendsto_iff_dist_tendsto_zero.mpr + have hz' := tendsto_iff_dist_tendsto_zero.mp hz + apply squeeze_zero (fun _ => dist_nonneg) + (fun n => (dist_triangle _ (x (φ n) i₀) _).trans (_root_.add_le_add (hdist n i) le_rfl)) + simpa only [zero_add, Function.comp_def] using hpow.add hz' + have hle (i : V) : (F z).1 i ≤ z.1 i := by + have hc : Continuous (fun y : Delta V => y.1 i) := + (continuous_apply i).comp continuous_subtype_val + exact le_of_tendsto_of_tendsto ((hc.comp hF).tendsto z |>.comp (hlim i)) + (hc.tendsto z |>.comp (hlim i)) (Filter.Eventually.of_forall (fun n => hlabel (φ n) i)) + refine ⟨z, Subtype.ext (funext fun i => ?_)⟩ + have he := (Finset.sum_eq_sum_iff_of_le + (fun i (_ : i ∈ (univ : Finset V)) => hle i)).mp ((F z).2.2.trans z.2.2.symm) + exact he i (mem_univ i) + +end Coordinates + +section ConvexFixedPoint +variable {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] + +theorem compact_convex_approximation {K : Set E} (hK : IsCompact K) + (hne : K.Nonempty) (hc : Convex ℝ K) (F : K → K) (hF : Continuous F) + {ε : ℝ} (hε : 0 < ε) : ∃x : K, dist x (F x) ≤ ε := by + classical + obtain ⟨t, htK, htfin, htcover⟩ := hK.finite_cover_balls hε + let : Fintype t := htfin.fintype + have htne : t.Nonempty := by + obtain ⟨x, hx⟩ := hne + have h := htcover hx + simp only [Set.mem_iUnion] at h + obtain ⟨y, hy, _⟩ := h + exact ⟨y, hy⟩ + let : Nonempty t := htne.to_subtype + let bump (x : K) (i : t) : ℝ := max 0 (ε - dist x.1 i.1) + let total (x : K) : ℝ := ∑i : t, bump x i + have hbump (x : K) (i : t) : 0 ≤ bump x i := le_max_left _ _ + have htotal (x : K) : 0 < total x := by + obtain ⟨y, hyx⟩ := Set.mem_iUnion.mp (htcover x.2) + obtain ⟨hy, hxy⟩ := Set.mem_iUnion.mp hyx + apply Finset.sum_pos' (fun i _ => hbump x i) + refine ⟨⟨y, hy⟩, mem_univ _, ?_⟩ + exact lt_of_lt_of_le (sub_pos.mpr hxy) (le_max_right _ _) + let weights (x : K) : Delta t := ⟨fun i => bump x i / total x, + (fun i => div_nonneg (hbump x i) (htotal x).le), by + rw [← Finset.sum_div] + exact div_self (htotal x).ne'⟩ + have cbump (i : t) : Continuous (fun x : K => bump x i) := + continuous_const.max (continuous_const.sub (continuous_subtype_val.dist continuous_const)) + have ctotal : Continuous total := continuous_finsetSum _ (fun i _ => cbump i) + have cweights : Continuous weights := by + apply Continuous.subtype_mk + exact continuous_pi (fun i => (cbump i).div ctotal (fun x => (htotal x).ne')) + let combo (u : Delta t) : K := ⟨∑i : t, u.1 i • i.1, + hc.sum_mem (fun i _ => u.2.1 i) u.2.2 (fun i _ => htK i.2)⟩ + have ccombo : Continuous combo := by + apply Continuous.subtype_mk + apply continuous_finsetSum + intro i _ + exact ((continuous_apply i).comp continuous_subtype_val).smul continuous_const + have happrox (y : K) : dist (combo (weights y)) y ≤ ε := by + change dist (∑i : t, (weights y).1 i • i.1) y.1 ≤ ε + rw [dist_eq_norm] + have he : (∑i : t, (weights y).1 i • i.1) - y.1 = + ∑i : t, (weights y).1 i • (i.1 - y.1) := by + rw [Finset.sum_congr rfl (fun i _ => smul_sub _ _ _), Finset.sum_sub_distrib, + ← Finset.sum_smul, (weights y).2.2, one_smul] + rw [he] + calc + _ ≤ ∑i : t, ‖(weights y).1 i • (i.1 - y.1)‖ := norm_sum_le _ _ + _ ≤ ∑i : t, (weights y).1 i * ε := by + apply Finset.sum_le_sum + intro i _ + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ((weights y).2.1 i)] + by_cases hi : bump y i = 0 + · have hw : (weights y).1 i = 0 := by simp [weights, hi] + simp only [hw, zero_mul, le_refl] + · have hd : dist y.1 i.1 < ε := by + have hp : 0 < bump y i := (hbump y i).lt_of_ne' hi + dsimp [bump] at hp + exact sub_pos.mp ((lt_max_iff.mp hp).resolve_left (lt_irrefl 0)) + apply mul_le_mul_of_nonneg_left _ ((weights y).2.1 i) + simpa only [← dist_eq_norm, dist_comm] using hd.le + _ = ε := by rw [← Finset.sum_mul, (weights y).2.2, one_mul] + obtain ⟨u, hu⟩ := simplex_fixed_point (fun u => weights (F (combo u))) + (cweights.comp (hF.comp ccombo)) + refine ⟨combo u, ?_⟩ + have := happrox (F (combo u)) + rwa [hu] at this + +theorem compact_convex_fixed_point {K : Set E} (hK : IsCompact K) + (hne : K.Nonempty) (hc : Convex ℝ K) (F : K → K) (hF : Continuous F) : + ∃x, F x = x := by + classical + let : CompactSpace K := isCompact_iff_compactSpace.mp hK + have heps (n : ℕ) : (0 : ℝ) < 1 / ((n : ℝ) + 1) := by positivity + choose x hx using fun n => compact_convex_approximation hK hne hc F hF (heps n) + obtain ⟨z, _, φ, hφ, hz⟩ := isCompact_univ.tendsto_subseq + (x := x) (fun _ => Set.mem_univ _) + have hlim : Filter.Tendsto (fun n => dist (x (φ n)) (F (x (φ n)))) + Filter.atTop (nhds 0) := + squeeze_zero (fun _ => dist_nonneg) (fun n => hx (φ n)) + (tendsto_one_div_add_atTop_nhds_zero_nat.comp hφ.tendsto_atTop) + have hzero : dist z (F z) = 0 := tendsto_nhds_unique + ((continuous_id.dist hF).tendsto z |>.comp hz) hlim + exact ⟨z, (dist_eq_zero.mp hzero).symm⟩ +end ConvexFixedPoint + +end +end StrongThinTree.FixedPoint + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Flow/FractionalOrientation.lean b/lean/OAI/Combinatorics/ThinTrees/Flow/FractionalOrientation.lean new file mode 100644 index 0000000000000000000000000000000000000000..1091363ef7e8be14090412693c78ad8f32f6c38c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Flow/FractionalOrientation.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Flow.RootedRelaxation + +namespace OAI + +/-! Fractional orientation. -/ + +section + +namespace AlgorithmicThinTrees.Orientations +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical +variable {n m : ℕ} + +def FlowPoint.Exact (G : MultiGraph n m) (c : Fin m → ℝ) (q : ℝ) + (F : FlowPoint n m) : Prop := + (∀e, 0 ≤ F.x e ∧ F.x e ≤ c e) ∧ + (∀r e, 0 ≤ F.a r e ∧ 0 ≤ F.b r e ∧ F.x e = F.a r e+F.b r e) ∧ + (∀r v, out G (F.a r) (F.b r) v = if v=r then 0 else q) ∧ + (∑e, F.x e)=q*((n:ℝ)-1) + +lemma out_sum {I : Type*} [Fintype I] (G : MultiGraph n m) + (a b : I → Fin m → ℝ) (v : Fin n) : + out G (fun e => ∑i, a i e) (fun e => ∑i, b i e) v = ∑i, out G (a i) (b i) v := by + simp only [out] + rw [sum_comm] + apply sum_congr rfl + intro e he + rw [sum_add_distrib] + have hi (p : Prop) [Decidable p] (f : I → ℝ) : (if p then ∑i, f i else 0)=∑i, if p then f i else 0 := by + split_ifs <;> simp + rw [hi,hi] + +lemma out_scale (G : MultiGraph n m) (a b : Fin m → ℝ) (α : ℝ) (v : Fin n) : + out G (fun e => α*a e) (fun e => α*b e) v=α*out G a b v := by + simp only [out,mul_sum,mul_add] + apply sum_congr rfl + intro e he + split_ifs <;> ring + +lemma FlowPoint.Exact.scale {G : MultiGraph n m} {c : Fin m → ℝ} {q : ℝ} + {F : FlowPoint n m} (hF : F.Exact G c q) {α : ℝ} (hα : 0 ≤ α) : + (FlowPoint.mk (fun e => α*F.x e) (fun r e => α*F.a r e) (fun r e => α*F.b r e)).Exact + G (fun e => α*c e) (α*q) := by + refine ⟨fun e => ⟨mul_nonneg hα (hF.1 e).1,mul_le_mul_of_nonneg_left (hF.1 e).2 hα⟩, + fun r e => ⟨mul_nonneg hα (hF.2.1 r e).1,mul_nonneg hα (hF.2.1 r e).2.1,?_⟩,?_,?_⟩ + · simp only [(hF.2.1 r e).2.2,mul_add] + · intro r v + rw [out_scale,hF.2.2.1] + split_ifs <;> simp + · change (∑e, α*F.x e)=_ + rw [←mul_sum,hF.2.2.2] + ring + +lemma FlowPoint.Exact.mono {G : MultiGraph n m} {c d : Fin m → ℝ} {q : ℝ} + {F : FlowPoint n m} (hF : F.Exact G c q) (hcd : ∀e, c e ≤ d e) : F.Exact G d q := + ⟨fun e => ⟨(hF.1 e).1, (hF.1 e).2.trans (hcd e)⟩,hF.2⟩ + +lemma packed_exact_flow (G : MultiGraph n m) (hn : 0 < n) {r : ℕ} + (hpack : G.TreePackable univ r) : + ∃F : FlowPoint n m, F.Exact G (fun _ => 1) r := by + obtain ⟨T,hT,hdis⟩ := hpack + let R (root : Fin n) (i : Fin r) : Rooted G (T i) root := Classical.choice (rooted_exists G (hT i).2 root) + let F : FlowPoint n m := ⟨fun e => ∑i, if e ∈ T i then 1 else 0, + fun root e => ∑i, (R root i).leftFlow e, + fun root e => ∑i, (R root i).rightFlow e⟩ + refine ⟨F,?_,?_,?_,?_⟩ + · intro e + constructor + · change 0 ≤ ∑i : Fin r, if e ∈ T i then (1:ℝ) else 0 + exact sum_nonneg fun i _ => by split_ifs <;> norm_num + · change (∑i, if e ∈ T i then (1:ℝ) else 0) ≤ 1 + rw [sum_boole] + norm_cast + apply card_le_one.mpr + intro i hi j hj + by_contra hij + have h := disjoint_left.mp (hdis hij) + exact h (mem_filter.mp hi).2 (mem_filter.mp hj).2 + · intro root e + change 0 ≤ (∑i, (R root i).leftFlow e) ∧ + 0 ≤ (∑i, (R root i).rightFlow e) ∧ _ + refine ⟨sum_nonneg fun i _ => (R root i).leftFlow_nonneg e, + sum_nonneg fun i _ => (R root i).rightFlow_nonneg e,?_⟩ + change (∑i, if e ∈ T i then (1:ℝ) else 0)=(∑i, (R root i).leftFlow e)+(∑i, (R root i).rightFlow e) + rw [←sum_add_distrib] + exact sum_congr rfl fun i _ => ((R root i).edgeFlow e).symm + · intro root v + change out G (fun e => ∑i, (R root i).leftFlow e) (fun e => ∑i, (R root i).rightFlow e) v=_ + rw [out_sum] + simp only [Rooted.out_eq] + split_ifs <;> simp + · change (∑e, ∑i, if e ∈ T i then (1:ℝ) else 0)=(r:ℝ)*((n:ℝ)-1) + rw [sum_comm] + have hs (i : Fin r) : (∑e, if e ∈ T i then (1:ℝ) else 0)=(n:ℝ)-1 := by + rw [sum_boole,filter_mem_eq_inter,univ_inter,G.spanningTree_card hn (hT i).2] + rw [Nat.cast_sub (show 1 ≤ n by omega),Nat.cast_one] + simp only [hs,sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul] + +def FlowPoint.push {M : ℕ} (π : Fin M → Fin m) (F : FlowPoint n M) : FlowPoint n m := + ⟨fun e => ∑f ∈ univ.filter (fun f => π f=e), F.x f, + fun r e => ∑f ∈ univ.filter (fun f => π f=e), F.a r f, + fun r e => ∑f ∈ univ.filter (fun f => π f=e), F.b r f⟩ + +lemma out_push {M : ℕ} (G : MultiGraph n m) (H : MultiGraph n M) (π : Fin M → Fin m) + (hl : ∀e, G.left (π e)=H.left e) (hr : ∀e, G.right (π e)=H.right e) + (F : FlowPoint n M) (root v : Fin n) : + out G ((F.push π).a root) ((F.push π).b root) v=out H (F.a root) (F.b root) v := by + have hi (p : Prop) [Decidable p] (s : Finset (Fin M)) (a : Fin M → ℝ) : + (if p then ∑f ∈ s, a f else 0)=∑f ∈ s, if p then a f else 0 := by + split_ifs <;> simp + simp only [out,FlowPoint.push,hi,←sum_add_distrib] + trans ∑e : Fin m, ∑f ∈ univ.filter (fun f => π f=e), + ((if H.left f=v then F.a root f else 0)+(if H.right f=v then F.b root f else 0)) + · apply sum_congr rfl + intro e he + apply sum_congr rfl + intro f hf + have hfe := (mem_filter.mp hf).2 + rw [←hfe,hl,hr] + · exact sum_fiberwise_of_maps_to (fun e _ => mem_univ (π e)) _ + +lemma FlowPoint.Exact.push {M : ℕ} (G : MultiGraph n m) (H : MultiGraph n M) (π : Fin M → Fin m) + (hl : ∀e, G.left (π e)=H.left e) (hr : ∀e, G.right (π e)=H.right e) + {c : Fin M → ℝ} {q : ℝ} {F : FlowPoint n M} (hF : F.Exact H c q) : + (F.push π).Exact G (fun e => ∑f ∈ univ.filter (fun f => π f=e), c f) q := by + refine ⟨?_,?_,?_,?_⟩ + · intro e + change 0 ≤ (∑f ∈ univ.filter (fun f => π f=e), F.x f) ∧ + (∑f ∈ univ.filter (fun f => π f=e), F.x f) ≤ (∑f ∈ univ.filter (fun f => π f=e), c f) + exact ⟨sum_nonneg fun f _ => (hF.1 f).1,sum_le_sum fun f _ => (hF.1 f).2⟩ + · intro r e + change 0 ≤ (∑f ∈ univ.filter (fun f => π f=e), F.a r f) ∧ + 0 ≤ (∑f ∈ univ.filter (fun f => π f=e), F.b r f) ∧ _ + refine ⟨sum_nonneg fun f _ => (hF.2.1 r f).1, + sum_nonneg fun f _ => (hF.2.1 r f).2.1,?_⟩ + change (∑f ∈ univ.filter (fun f => π f=e), F.x f)=_ + simp only [FlowPoint.push,←sum_add_distrib] + exact sum_congr rfl fun f _ => (hF.2.1 r f).2.2 + · intro r v + rw [out_push G H π hl hr] + exact hF.2.2.1 r v + · change (∑e, ∑f ∈ univ.filter (fun f => π f=e), F.x f)=_ + rw [sum_fiberwise_of_maps_to (fun f _ => mem_univ (π f)),hF.2.2.2] + +end +end AlgorithmicThinTrees.Orientations +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Flow/FractionalPackingMargin.lean b/lean/OAI/Combinatorics/ThinTrees/Flow/FractionalPackingMargin.lean new file mode 100644 index 0000000000000000000000000000000000000000..9be5a3e8408cc40f4787a960bd87f6683769cc6e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Flow/FractionalPackingMargin.lean @@ -0,0 +1,100 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Flow.FractionalOrientation +import OAI.Combinatorics.ThinTrees.Flow.ParallelCopies + +namespace OAI + +/-! Fractional packing margin. -/ + +section + +namespace AlgorithmicThinTrees.Orientations +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical +variable {n m : ℕ} + +lemma partCount_le_vertices (p : Setoid (Fin n)) : partCount p ≤ n := by + simpa [partCount] using Fintype.card_le_of_surjective (Quotient.mk p) Quotient.mk_surjective + +lemma capacity_nonneg (G : MultiGraph n m) {c : Fin m → ℝ} (hc : ∀e, 0 ≤ c e) + (p : Setoid (Fin n)) : 0 ≤ capacity G.left G.right c p := + sum_nonneg fun e _ => mul_nonneg (hc e) (crossingIndicator_nonneg p _ _) + +lemma floor_capacity_lower (G : MultiGraph n m) (c : Fin m → ℝ) (N : ℕ) + (p : Setoid (Fin n)) : + (N:ℝ)*capacity G.left G.right c p-m ≤ + capacity G.left G.right (fun e => (⌊(N:ℝ)*c e⌋₊:ℕ)) p := by + rw [capacity_eq_sum,capacity_eq_sum] + have h := sum_le_sum (s:=Partitions.crossing G p) (fun e _ => + show (N:ℝ)*c e-1 ≤ (⌊(N:ℝ)*c e⌋₊:ℕ) by linarith [Nat.lt_floor_add_one ((N:ℝ)*c e)]) + simp only [sum_sub_distrib,←mul_sum,sum_const,nsmul_eq_mul,mul_one] at h + have hc : (Partitions.crossing G p).card ≤ m := + (card_le_card (subset_univ _)).trans_eq (card_univ.trans (Fintype.card_fin m)) + have hc' : ((Partitions.crossing G p).card:ℝ) ≤ m := by exact_mod_cast hc + linarith only [h,hc'] + +lemma FlowPoint.zero_exact (G : MultiGraph n m) {c : Fin m → ℝ} (hc : ∀e, 0 ≤ c e) : + (FlowPoint.mk (fun _ => 0) (fun _ _ => 0) (fun _ _ => 0)).Exact G c 0 := by + simp [FlowPoint.Exact,out,hc] + +theorem exact_flow_of_margin (G : MultiGraph n m) (hn : 0 < n) + (c : Fin m → ℝ) (hc : ∀e, 0 ≤ c e) {q δ : ℝ} (hq : 0 ≤ q) (hδ : 0 < δ) + (hp : ∀p : Setoid (Fin n), (q+δ)*((partCount p:ℝ)-1) ≤ capacity G.left G.right c p) : + ∃F : FlowPoint n m, F.Exact G c q := by + rcases eq_or_lt_of_le hq with hq0|hq0 + · subst q + exact ⟨_,FlowPoint.zero_exact G hc⟩ + let : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + obtain ⟨N,hN⟩ := exists_nat_gt (((m:ℝ)+n+1)/δ) + have hNδ : (m:ℝ)+n+1 < (N:ℝ)*δ := (div_lt_iff₀ hδ).mp hN + have hN0 : 0 < (N:ℝ) := by + by_contra h + have hh : (N:ℝ)*δ ≤ 0 := mul_nonpos_of_nonpos_of_nonneg (le_of_not_gt h) hδ.le + have hm0 : (0:ℝ) ≤ m := Nat.cast_nonneg m + have hn0 : (0:ℝ) ≤ n := Nat.cast_nonneg n + linarith only [hh,hNδ,hm0,hn0] + let a : Fin m → ℕ := fun e => ⌊(N:ℝ)*c e⌋₊ + let r : ℕ := ⌈(N:ℝ)*q⌉₊ + have hrlo : (N:ℝ)*q ≤ r := Nat.le_ceil _ + have hrhi : (r:ℝ) ≤ (N:ℝ)*q+1 := (Nat.ceil_lt_add_one (mul_nonneg hN0.le hq)).le + have hrpos : 0 < (r:ℝ) := (mul_pos hN0 hq0).trans_le hrlo + have hr : 0 < r := by exact_mod_cast hrpos + have hpack : (copies G a).TreePackable univ r := by + apply packing_of_partitions _ hn hr + intro p + by_cases htop : p=⊤ + · subst p + simp [capacity,crossingIndicator,partCount_top] + · have hd : (2:ℝ) ≤ partCount p := by exact_mod_cast two_le_partCount htop + have hdhi : (partCount p:ℝ) ≤ n := by exact_mod_cast partCount_le_vertices p + rw [capacity_unit,capacity_copies] + have hf := floor_capacity_lower G c N p + have hpN := mul_le_mul_of_nonneg_left (hp p) hN0.le + have hround := mul_le_mul_of_nonneg_right hrhi (show 0 ≤ (partCount p:ℝ)-1 by linarith) + have hδgain := mul_le_mul_of_nonneg_left (show 1 ≤ (partCount p:ℝ)-1 by linarith) + (mul_nonneg hN0.le hδ.le) + change (r:ℝ)*((partCount p:ℝ)-1) ≤ capacity G.left G.right (fun e => (a e:ℝ)) p + change (N:ℝ)*capacity G.left G.right c p-m ≤ + capacity G.left G.right (fun e => (a e:ℝ)) p at hf + nlinarith only [hf,hpN,hround,hδgain,hNδ,hdhi] + obtain ⟨F,hF⟩ := packed_exact_flow (copies G a) hn hpack + have hpush := hF.push G (copies G a) (copyProjection a) (fun _ => rfl) (fun _ => rfl) + simp only [fiber_copies] at hpush + have hs := hpush.scale (div_nonneg hq hrpos.le) + rw [div_mul_cancel₀ q (ne_of_gt hrpos)] at hs + refine ⟨_,hs.mono fun e => ?_⟩ + have ha : (a e:ℝ) ≤ (N:ℝ)*c e := Nat.floor_le (mul_nonneg hN0.le (hc e)) + have hα : q/(r:ℝ)*N ≤ 1 := by + rw [div_mul_eq_mul_div,div_le_one hrpos] + simpa [mul_comm] using hrlo + calc + _ ≤ (q/(r:ℝ))*((N:ℝ)*c e) := mul_le_mul_of_nonneg_left ha (div_nonneg hq hrpos.le) + _ = ((q/(r:ℝ))*N)*c e := by ring + _ ≤ c e := by simpa using mul_le_mul_of_nonneg_right hα (hc e) + +end +end AlgorithmicThinTrees.Orientations +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Flow/Interior.lean b/lean/OAI/Combinatorics/ThinTrees/Flow/Interior.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab38e675e4a8c071ae4a9db988586675d2b013fc --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Flow/Interior.lean @@ -0,0 +1,190 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Grid +import OAI.Combinatorics.ThinTrees.Flow.FractionalPackingMargin + +namespace OAI + +/-! Flow interior. -/ + +section + +namespace AlgorithmicThinTrees.Orientations +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical +variable {n m : ℕ} + +namespace FlowPoint + +def bump (F : FlowPoint n m) (γ : ℝ) : FlowPoint n m := + ⟨fun e => F.x e+γ,fun r e => F.a r e+γ,fun r e => F.b r e+γ⟩ + +def Close (F H : FlowPoint n m) (ρ : ℝ) : Prop := + (∀e, |F.x e-H.x e| ≤ ρ) ∧ + (∀r e, |F.a r e-H.a r e| ≤ ρ) ∧ (∀r e, |F.b r e-H.b r e| ≤ ρ) + +def Bounded (F : FlowPoint n m) (R : ℝ) : Prop := + (∀e, |F.x e| ≤ R) ∧ (∀r e, |F.a r e| ≤ R) ∧ (∀r e, |F.b r e| ≤ R) + +lemma Exact.bump_bound {G : MultiGraph n m} {c : Fin m → ℝ} {q R γ : ℝ} + {F : FlowPoint n m} (hF : F.Exact G c q) (hc : ∀e, c e ≤ R) (hγ : 0 ≤ γ) : + (F.bump γ).Bounded (R+γ) := by + refine ⟨?_,?_,?_⟩ + · intro e + change |F.x e+γ| ≤ _ + rw [abs_of_nonneg (add_nonneg (hF.1 e).1 hγ)] + linarith only [(hF.1 e).2, hc e] + · intro r e + change |F.a r e+γ| ≤ _ + rw [abs_of_nonneg (add_nonneg (hF.2.1 r e).1 hγ)] + have h := (hF.2.1 r e).2.2 + linarith only [h,(hF.2.1 r e).2.1,(hF.1 e).2,hc e] + · intro r e + change |F.b r e+γ| ≤ _ + rw [abs_of_nonneg (add_nonneg (hF.2.1 r e).2.1 hγ)] + have h := (hF.2.1 r e).2.2 + linarith only [h,(hF.2.1 r e).1,(hF.1 e).2,hc e] + +end FlowPoint + +lemma out_perturb_upper (G : MultiGraph n m) {a b a' b' : Fin m → ℝ} {σ : ℝ} + (hσ : 0 ≤ σ) (ha : ∀e, a' e ≤ a e+σ) (hb : ∀e, b' e ≤ b e+σ) (v : Fin n) : + out G a' b' v ≤ out G a b v+2*m*σ := by + have hi (e : Fin m) : + (if G.left e=v then a' e else 0)+(if G.right e=v then b' e else 0) ≤ + (if G.left e=v then a e else 0)+(if G.right e=v then b e else 0)+2*σ := by + split_ifs <;> linarith only [ha e,hb e,hσ] + have h := sum_le_sum (s:=univ) fun e _ => hi e + simpa only [out,sum_add_distrib,sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul, + mul_comm (m:ℝ),mul_assoc] using h + +lemma exact_bump_cube (G : MultiGraph n m) {c : Fin m → ℝ} {qbar ε α γ : ℝ} + (hγ : 0 < γ) (hα : 0 ≤ α) (hαε : α ≤ ε) (hαn : α*((n:ℝ)-1) ≤ ε) + (hmγ : 4*m*γ ≤ α) {F : FlowPoint n m} + (hF : F.Exact G (fun e => c e-2*γ) (qbar-α)) {H : FlowPoint n m} + (hclose : H.Close (F.bump γ) (γ/4)) : H.Feasible G c qbar ε := by + have hx (e : Fin m) := abs_le.mp (hclose.1 e) + have ha (r : Fin n) (e : Fin m) := abs_le.mp (hclose.2.1 r e) + have hb (r : Fin n) (e : Fin m) := abs_le.mp (hclose.2.2 r e) + simp only [FlowPoint.bump] at hx ha hb + have hg : 0 ≤ (m:ℝ)*γ := mul_nonneg (Nat.cast_nonneg _) hγ.le + refine ⟨?_,?_,?_,?_⟩ + · intro e + constructor + · linarith only [(hx e).1,(hF.1 e).1,hγ] + · linarith only [(hx e).2,(hF.1 e).2,hγ] + · intro r e + refine ⟨?_,?_,?_⟩ + · linarith only [(ha r e).1,(hF.2.1 r e).1,hγ] + · linarith only [(hb r e).1,(hF.2.1 r e).2.1,hγ] + · linarith only [(hx e).2,(ha r e).1,(hb r e).1,(hF.2.1 r e).2.2,hγ] + · intro r v + have ho := out_perturb_upper G (show 0 ≤ γ+γ/4 by linarith) + (fun e => show H.a r e ≤ F.a r e+(γ+γ/4) by linarith only [(ha r e).2]) + (fun e => show H.b r e ≤ F.b r e+(γ+γ/4) by linarith only [(hb r e).2]) v + rw [hF.2.2.1] at ho + split_ifs at ho ⊢ <;> nlinarith only [ho,hmγ,hα,hαε,hg] + · have hsum : (∑e, F.x e) ≤ ∑e, H.x e := sum_le_sum fun e _ => by + linarith only [(hx e).1,hγ] + rw [hF.2.2.2] at hsum + nlinarith only [hsum,hαn] + +lemma capacity_shift_lower (G : MultiGraph n m) (c : Fin m → ℝ) {γ : ℝ} + (hγ : 0 ≤ γ) (p : Setoid (Fin n)) : + capacity G.left G.right c p-γ*m ≤ capacity G.left G.right (fun e => c e-γ) p := by + rw [capacity_eq_sum,capacity_eq_sum] + simp only [sum_sub_distrib,sum_const,nsmul_eq_mul] + have hc : (Partitions.crossing G p).card ≤ m := + (card_le_card (subset_univ _)).trans_eq (card_univ.trans (Fintype.card_fin m)) + have hc' : ((Partitions.crossing G p).card:ℝ) ≤ m := by exact_mod_cast hc + nlinarith only [mul_le_mul_of_nonneg_left hc' hγ] + +theorem flow_inner_cube (G : MultiGraph n m) (hn : 0 < n) (c : Fin m → ℝ) + {qbar ε α β γ R : ℝ} (hγ : 0 < γ) (hα : 0 ≤ α) (hq : α ≤ qbar) + (hαε : α ≤ ε) (hαn : α*((n:ℝ)-1) ≤ ε) (hβ : 0 < β) + (hmγα : 4*m*γ ≤ α) (hmγβ : 4*m*γ ≤ β) + (hc : ∀e, 2*γ ≤ c e) (hcR : ∀e, c e ≤ R) + (hp : ∀p : Setoid (Fin n), (qbar+β)*((partCount p:ℝ)-1) ≤ capacity G.left G.right c p) : + ∃F : FlowPoint n m, F.Bounded (R+γ) ∧ + ∀H : FlowPoint n m, H.Close F (γ/4) → H.Feasible G c qbar ε := by + let : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + have hmargin (p : Setoid (Fin n)) : + (qbar-α+β/2)*((partCount p:ℝ)-1) ≤ capacity G.left G.right (fun e => c e-2*γ) p := by + by_cases htop : p=⊤ + · subst p + simp [capacity,crossingIndicator,partCount_top] + · have hd : (2:ℝ) ≤ partCount p := by exact_mod_cast two_le_partCount htop + have ha : 0 ≤ α*((partCount p:ℝ)-1) := mul_nonneg hα (by linarith) + have hb : β ≤ β*((partCount p:ℝ)-1) := by nlinarith only [hd,hβ] + have hs := capacity_shift_lower G c (show 0 ≤ 2*γ by linarith only [hγ]) p + nlinarith only [hs,hp p,ha,hb,hmγβ] + obtain ⟨F,hF⟩ := exact_flow_of_margin G hn (fun e => c e-2*γ) + (fun e => sub_nonneg.mpr (hc e)) (sub_nonneg.mpr hq) (show 0 < β/2 by linarith) hmargin + refine ⟨F.bump γ,hF.bump_bound (fun e => ?_) hγ.le,fun H hH => ?_⟩ + · linarith only [hcR e,hγ] + · exact exact_bump_cube G hγ hα hαε hαn hmγα hF hH + +end +end AlgorithmicThinTrees.Orientations + +namespace AlgorithmicThinTrees.Orientations +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical +variable {n m : ℕ} + +lemma exact_bump_cube_vary (G : MultiGraph n m) {c c' : Fin m → ℝ} {qbar ε α γ : ℝ} + (hγ : 0 < γ) (hα : 0 ≤ α) (hαε : α ≤ ε) (hαn : α*((n:ℝ)-1) ≤ ε) + (hmγ : 4*m*γ ≤ α) {F : FlowPoint n m} + (hF : F.Exact G (fun e => c e-2*γ) (qbar-α)) + (hc' : ∀e, c e-γ/2 ≤ c' e) {H : FlowPoint n m} + (hclose : H.Close (F.bump γ) (γ/4)) : H.Feasible G c' qbar ε := by + have h := exact_bump_cube G hγ hα hαε hαn hmγ hF hclose + refine ⟨?_,h.2⟩ + intro e + refine ⟨(h.1 e).1,?_⟩ + have hx := (abs_le.mp (hclose.1 e)).2 + change H.x e-(F.x e+γ) ≤ γ/4 at hx + linarith only [hx,(hF.1 e).2,hc' e,hγ] + +theorem flow_inner_cube_vary (G : MultiGraph n m) (hn : 0 < n) (c : Fin m → ℝ) + {qbar ε α β γ R : ℝ} (hγ : 0 < γ) (hα : 0 ≤ α) (hq : α ≤ qbar) + (hαε : α ≤ ε) (hαn : α*((n:ℝ)-1) ≤ ε) (hβ : 0 < β) + (hmγα : 4*m*γ ≤ α) (hmγβ : 4*m*γ ≤ β) + (hc : ∀e, 2*γ ≤ c e) (hcR : ∀e, c e ≤ R) + (hp : ∀p : Setoid (Fin n), (qbar+β)*((partCount p:ℝ)-1) ≤ capacity G.left G.right c p) : + ∃F : FlowPoint n m, F.Bounded (R+γ) ∧ + ∀(c' : Fin m → ℝ) (H : FlowPoint n m), + (∀e, c e-γ/2 ≤ c' e) → H.Close F (γ/4) → H.Feasible G c' qbar ε := by + let : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + have hmargin (p : Setoid (Fin n)) : + (qbar-α+β/2)*((partCount p:ℝ)-1) ≤ capacity G.left G.right (fun e => c e-2*γ) p := by + by_cases htop : p=⊤ + · subst p + simp [capacity,crossingIndicator,partCount_top] + · have hd : (2:ℝ) ≤ partCount p := by exact_mod_cast two_le_partCount htop + have ha : 0 ≤ α*((partCount p:ℝ)-1) := mul_nonneg hα (by linarith) + have hb : β ≤ β*((partCount p:ℝ)-1) := by nlinarith only [hd,hβ] + have hs := capacity_shift_lower G c (show 0 ≤ 2*γ by linarith only [hγ]) p + nlinarith only [hs,hp p,ha,hb,hmγβ] + obtain ⟨F,hF⟩ := exact_flow_of_margin G hn (fun e => c e-2*γ) + (fun e => sub_nonneg.mpr (hc e)) (sub_nonneg.mpr hq) (show 0 < β/2 by linarith) hmargin + refine ⟨F.bump γ,hF.bump_bound (fun e => ?_) hγ.le,?_⟩ + · linarith only [hcR e,hγ] + · intro c' H hc' hH + exact exact_bump_cube_vary G hγ hα hαε hαn hmγα hF hc' hH + +lemma FlowPoint.Close.mono {F H : FlowPoint n m} {ρ σ : ℝ} + (h : F.Close H ρ) (hρσ : ρ ≤ σ) : F.Close H σ := + ⟨fun e => (h.1 e).trans hρσ,fun r e => (h.2.1 r e).trans hρσ, + fun r e => (h.2.2 r e).trans hρσ⟩ + +lemma FlowPoint.Bounded.mono {F : FlowPoint n m} {R R' : ℝ} + (h : F.Bounded R) (hRR' : R ≤ R') : F.Bounded R' := + ⟨fun e => (h.1 e).trans hRR',fun r e => (h.2.1 r e).trans hRR', + fun r e => (h.2.2 r e).trans hRR'⟩ +end +end AlgorithmicThinTrees.Orientations +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Flow/ParallelCopies.lean b/lean/OAI/Combinatorics/ThinTrees/Flow/ParallelCopies.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce8efbf18b9b8d9c05cdf4a34b9fc7307c47a7d2 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Flow/ParallelCopies.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Interior + +namespace OAI + +/-! Parallel copies. -/ + +section + +namespace AlgorithmicThinTrees.Orientations +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical +variable {n m : ℕ} + +abbrev Copy (a : Fin m → ℕ) := Σe, Fin (a e) + +def copyEquiv (a : Fin m → ℕ) : Copy a ≃ Fin (Fintype.card (Copy a)) := Fintype.equivFin _ + +def copyProjection (a : Fin m → ℕ) (f : Fin (Fintype.card (Copy a))) : Fin m := + ((copyEquiv a).symm f).1 + +def copies (G : MultiGraph n m) (a : Fin m → ℕ) : MultiGraph n (Fintype.card (Copy a)) where + left f := G.left (copyProjection a f) + right f := G.right (copyProjection a f) + loopless f := G.loopless (copyProjection a f) + +lemma sum_copies (a : Fin m → ℕ) (f : Fin m → ℝ) : + (∑j : Fin (Fintype.card (Copy a)), f (copyProjection a j))=∑e, (a e:ℝ)*f e := by + rw [←(copyEquiv a).sum_comp] + simp [copyProjection,Fintype.sum_sigma,nsmul_eq_mul] + +lemma fiber_copies (a : Fin m → ℕ) (e : Fin m) : + (∑_copy ∈ univ.filter (fun f => copyProjection a f=e), (1:ℝ))=a e := by + rw [sum_filter] + simpa using sum_copies a (fun e' => if e'=e then (1:ℝ) else 0) + +lemma capacity_unit (G : MultiGraph n m) (p : Setoid (Fin n)) : + capacity G.left G.right (fun _ => 1) p=(Partitions.crossing G p).card := by + rw [capacity_eq_sum] + simp + +lemma capacity_copies (G : MultiGraph n m) (a : Fin m → ℕ) (p : Setoid (Fin n)) : + ((Partitions.crossing (copies G a) p).card:ℝ)= + capacity G.left G.right (fun e => a e) p := by + rw [←capacity_unit] + simp only [capacity,one_mul,copies] + exact sum_copies a (fun e => crossingIndicator p (G.left e) (G.right e)) + +lemma partCount_ker (p : Fin n → Fin n) : partCount (Setoid.ker p)=partitionSize p := by + let f : Quotient (Setoid.ker p) → (univ.image p : Finset (Fin n)) := + Quotient.lift (fun v => ⟨p v,mem_image.mpr ⟨v,mem_univ _,rfl⟩⟩) + (fun a b h => Subtype.ext h) + have hf : Function.Bijective f := by + constructor + · intro a b + induction a,b using Quotient.inductionOn₂ with + | h a b => + intro he + exact Quotient.sound (congrArg Subtype.val he) + · intro A + obtain ⟨v,_,hv⟩ := mem_image.mp A.property + exact ⟨Quotient.mk (Setoid.ker p) v,Subtype.ext hv⟩ + exact (Fintype.card_congr (Equiv.ofBijective f hf)).trans (Fintype.card_coe _) + +lemma crossing_ker (G : MultiGraph n m) (p : Fin n → Fin n) : + Partitions.crossing G (Setoid.ker p)=G.crossing univ p := by + ext e + simp [Partitions.crossing,MultiGraph.crossing] + +lemma packing_of_partitions (G : MultiGraph n m) (hn : 0 < n) {r : ℕ} (hr : 0 < r) + (hp : ∀p : Setoid (Fin n), (r:ℝ)*((partCount p:ℝ)-1) ≤ + capacity G.left G.right (fun _ => 1) p) : G.TreePackable univ r := by + apply G.partition_criterion_sufficient univ hr hn + intro p + have h := hp (Setoid.ker p) + rw [capacity_unit,crossing_ker,partCount_ker] at h + have hp0 : 1 ≤ partitionSize p := by + apply card_pos.mpr + exact ⟨p ⟨0,hn⟩,mem_image.mpr ⟨⟨0,hn⟩,mem_univ _,rfl⟩⟩ + have he : ((r*(partitionSize p-1):ℕ):ℝ)=(r:ℝ)*((partitionSize p:ℝ)-1) := by + rw [Nat.cast_mul,Nat.cast_sub hp0,Nat.cast_one] + exact_mod_cast (show ((r*(partitionSize p-1):ℕ):ℝ) ≤ (G.crossing univ p).card by rwa [he]) + +end +end AlgorithmicThinTrees.Orientations +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Flow/RootedFlow.lean b/lean/OAI/Combinatorics/ThinTrees/Flow/RootedFlow.lean new file mode 100644 index 0000000000000000000000000000000000000000..cffb52ec4cdddc2421023f8b4a1d6588f097dab0 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Flow/RootedFlow.lean @@ -0,0 +1,119 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Flow.RootedOrientation + +namespace OAI + +/-! Rooted flow. -/ + +section + +namespace AlgorithmicThinTrees.Orientations +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical +variable {n m : ℕ} + +def Rooted.leftFlow {G : MultiGraph n m} {T : Finset (Fin m)} {root : Fin n} + (R : Rooted G T root) (e : Fin m) : ℝ := + if he : e ∈ T then if (R.tail ⟨e,he⟩).val=G.left e then 1 else 0 else 0 + +def Rooted.rightFlow {G : MultiGraph n m} {T : Finset (Fin m)} {root : Fin n} + (R : Rooted G T root) (e : Fin m) : ℝ := + if he : e ∈ T then if (R.tail ⟨e,he⟩).val=G.right e then 1 else 0 else 0 + +lemma Rooted.leftFlow_nonneg {G : MultiGraph n m} {T : Finset (Fin m)} {root : Fin n} + (R : Rooted G T root) (e : Fin m) : 0 ≤ R.leftFlow e := by + unfold Rooted.leftFlow + split_ifs <;> norm_num + +lemma Rooted.rightFlow_nonneg {G : MultiGraph n m} {T : Finset (Fin m)} {root : Fin n} + (R : Rooted G T root) (e : Fin m) : 0 ≤ R.rightFlow e := by + unfold Rooted.rightFlow + split_ifs <;> norm_num + +lemma Rooted.edgeFlow {G : MultiGraph n m} {T : Finset (Fin m)} {root : Fin n} + (R : Rooted G T root) (e : Fin m) : + R.leftFlow e+R.rightFlow e=if e ∈ T then 1 else 0 := by + by_cases he : e ∈ T + · obtain hl|hr := R.endpoint ⟨e,he⟩ + · have hnot : (R.tail ⟨e,he⟩).val ≠ G.right e := by rw [hl]; exact G.loopless e + simp [Rooted.leftFlow,Rooted.rightFlow,he,hl,G.loopless e] + · have hnot : (R.tail ⟨e,he⟩).val ≠ G.left e := by rw [hr]; exact (G.loopless e).symm + simp [Rooted.leftFlow,Rooted.rightFlow,he,hr,(G.loopless e).symm] + · simp [Rooted.leftFlow,Rooted.rightFlow,he] + +def out (G : MultiGraph n m) (a b : Fin m → ℝ) (v : Fin n) : ℝ := + ∑e, ((if G.left e=v then a e else 0)+(if G.right e=v then b e else 0)) + +lemma Rooted.arc_at {G : MultiGraph n m} {T : Finset (Fin m)} {root : Fin n} + (R : Rooted G T root) (e : Fin m) (v : Fin n) : + (if G.left e=v then R.leftFlow e else 0)+(if G.right e=v then R.rightFlow e else 0)= + if he : e ∈ T then if (R.tail ⟨e,he⟩).val=v then 1 else 0 else 0 := by + by_cases he : e ∈ T + · obtain hl|hr := R.endpoint ⟨e,he⟩ + · have hnot : (R.tail ⟨e,he⟩).val ≠ G.right e := by rw [hl]; exact G.loopless e + simp [Rooted.leftFlow,Rooted.rightFlow,he,hl,G.loopless e] + · have hnot : (R.tail ⟨e,he⟩).val ≠ G.left e := by rw [hr]; exact (G.loopless e).symm + simp [Rooted.leftFlow,Rooted.rightFlow,he,hr,(G.loopless e).symm] + · simp [Rooted.leftFlow,Rooted.rightFlow,he] + +lemma Rooted.out_eq {G : MultiGraph n m} {T : Finset (Fin m)} {root : Fin n} + (R : Rooted G T root) (v : Fin n) : + out G R.leftFlow R.rightFlow v=if v=root then 0 else 1 := by + simp only [out,R.arc_at] + by_cases hv : v=root + · subst v + simp only [ite_true] + apply sum_eq_zero + intro e he + by_cases h : e ∈ T + · simp only [dite_eq_left h,ite_eq_right (R.tail ⟨e,h⟩).property] + · simp [h] + · rw [ite_eq_right hv] + let f : T := R.tail.symm ⟨v,hv⟩ + have hf : (R.tail f).val=v := congrArg Subtype.val (R.tail.apply_symm_apply ⟨v,hv⟩) + rw [sum_eq_single f.val] + · simp only [dite_eq_left f.property,hf,ite_true] + · intro e he hef + by_cases h : e ∈ T + · rw [dite_eq_left h] + apply ite_eq_right + intro hv' + apply hef + exact congrArg Subtype.val (R.tail.injective (Subtype.ext (hv'.trans hf.symm))) + · simp [h] + · simp + +lemma out_nonneg (G : MultiGraph n m) {a b : Fin m → ℝ} + (ha : ∀e, 0 ≤ a e) (hb : ∀e, 0 ≤ b e) (v : Fin n) : 0 ≤ out G a b v := by + unfold out + apply sum_nonneg + intro e he + exact add_nonneg (by split_ifs; exact ha e; exact le_rfl) + (by split_ifs; exact hb e; exact le_rfl) + +lemma internal_le_out (G : MultiGraph n m) {x a b : Fin m → ℝ} + (ha : ∀e, 0 ≤ a e) (hb : ∀e, 0 ≤ b e) (he : ∀e, x e ≤ a e+b e) + (S : Finset (Fin n)) : + (∑e ∈ univ.filter (fun e => G.left e ∈ S ∧ G.right e ∈ S), x e) ≤ ∑v ∈ S, out G a b v := by + rw [sum_filter] + simp only [out] + rw [sum_comm] + apply sum_le_sum + intro e he' + have hsum : (∑v ∈ S, ((if G.left e=v then a e else 0)+(if G.right e=v then b e else 0)))= + (if G.left e ∈ S then a e else 0)+(if G.right e ∈ S then b e else 0) := by + rw [sum_add_distrib] + simp only [sum_ite_eq] + rw [hsum] + by_cases hl : G.left e ∈ S <;> by_cases hr : G.right e ∈ S + · simpa only [hl,hr,and_self,ite_true] using he e + · simpa only [hl,hr,and_false,ite_false,ite_true,add_zero] using ha e + · simpa only [hl,hr,false_and,ite_false,ite_true,zero_add] using hb e + · simp [hl,hr] + +end +end AlgorithmicThinTrees.Orientations +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Flow/RootedOrientation.lean b/lean/OAI/Combinatorics/ThinTrees/Flow/RootedOrientation.lean new file mode 100644 index 0000000000000000000000000000000000000000..04c690234953b1e0bd1aef76487d419f98b8a232 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Flow/RootedOrientation.lean @@ -0,0 +1,100 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Interior + +namespace OAI + +/-! Rooted orientation. -/ + +section + +namespace AlgorithmicThinTrees.Orientations +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical +variable {n m : ℕ} + +def adjacency (G : MultiGraph n m) (T : Finset (Fin m)) : SimpleGraph (Fin n) where + Adj a b := ∃e ∈ T, (G.left e=a ∧ G.right e=b) ∨ (G.right e=a ∧ G.left e=b) + symm := ⟨by rintro a b ⟨e,he,h|h⟩ <;> exact ⟨e,he,by tauto⟩⟩ + loopless := ⟨by + intro a + rintro ⟨e,he,h|h⟩ + · exact G.loopless e (h.1.trans h.2.symm) + · exact G.loopless e (h.2.trans h.1.symm)⟩ + +lemma reachable (G : MultiGraph n m) {T : Finset (Fin m)} (hT : G.Connected T) + (v root : Fin n) : (adjacency G T).Reachable v root := by + let S : Finset (Fin n) := univ.filter (fun w => (adjacency G T).Reachable w root) + have hr : root ∈ S := by simp only [S,mem_filter,mem_univ,true_and]; exact .refl root + by_contra hv + have hv' : v ∉ S := by simpa only [S,mem_filter,mem_univ,true_and] using hv + have hSne : S ≠ univ := by intro he; exact hv' (he ▸ mem_univ v) + obtain ⟨e,he⟩ := hT S ⟨root,hr⟩ hSne + obtain ⟨heT,hecut⟩ := mem_filter.mp he + have hadj : (adjacency G T).Adj (G.left e) (G.right e) := ⟨e,heT,Or.inl ⟨rfl,rfl⟩⟩ + rcases hecut with ⟨hl,hr⟩ | ⟨hr,hl⟩ + · have h := hadj.reachable.symm.trans ((mem_filter.mp hl).2) + exact hr (mem_filter.mpr ⟨mem_univ _,h⟩) + · have h := hadj.reachable.trans ((mem_filter.mp hr).2) + exact hl (mem_filter.mpr ⟨mem_univ _,h⟩) + +lemma parent_exists (G : MultiGraph n m) {T : Finset (Fin m)} (hT : G.Connected T) + (root : Fin n) (v : Fin n) (hv : v ≠ root) : + ∃e ∈ T, + (G.left e=v ∧ (adjacency G T).dist (G.right e) root < (adjacency G T).dist v root) ∨ + (G.right e=v ∧ (adjacency G T).dist (G.left e) root < (adjacency G T).dist v root) := by + obtain ⟨p,hp⟩ := (reachable G hT v root).exists_walk_length_eq_dist + cases p with + | nil => exact (hv rfl).elim + | @cons v w root h p => + obtain ⟨e,he,h|h⟩ := h + · refine ⟨e,he,Or.inl ⟨h.1,?_⟩⟩ + rw [h.2] + exact lt_of_le_of_lt (SimpleGraph.dist_le p) (by simpa using hp.symm ▸ Nat.lt_succ_self p.length) + · refine ⟨e,he,Or.inr ⟨h.1,?_⟩⟩ + rw [h.2] + exact lt_of_le_of_lt (SimpleGraph.dist_le p) (by simpa using hp.symm ▸ Nat.lt_succ_self p.length) + +structure Rooted (G : MultiGraph n m) (T : Finset (Fin m)) (root : Fin n) where + tail : T ≃ {v : Fin n // v ≠ root} + endpoint : ∀e : T, (tail e).val=G.left e ∨ (tail e).val=G.right e + +lemma rooted_exists (G : MultiGraph n m) {T : Finset (Fin m)} (hT : G.SpanningTree T) + (root : Fin n) : Nonempty (Rooted G T root) := by + choose f hf using fun v : {v : Fin n // v ≠ root} => parent_exists G hT.1 root v v.property + let F : {v : Fin n // v ≠ root} → T := fun v => ⟨f v,(hf v).1⟩ + have hi : Function.Injective F := by + intro v w he + have he' : f v=f w := congrArg Subtype.val he + obtain hvl|hvr := (hf v).2 + obtain hwl|hwr := (hf w).2 + · apply Subtype.ext + exact hvl.1.symm.trans (he' ▸ hwl.1) + · have h1 := hvl.2 + have h2 := hwr.2 + rw [he',hwr.1] at h1 + rw [←he',hvl.1] at h2 + omega + obtain hwl|hwr := (hf w).2 + · have h1 := hvr.2 + have h2 := hwl.2 + rw [he',hwl.1] at h1 + rw [←he',hvr.1] at h2 + omega + · apply Subtype.ext + exact hvr.1.symm.trans (he' ▸ hwr.1) + have hc : Fintype.card {v : Fin n // v ≠ root}=Fintype.card T := by + rw [Fintype.card_subtype_compl,Fintype.card_fin,Fintype.card_subtype_eq root, + Fintype.card_coe,G.spanningTree_card (Fin.pos root) hT] + let E := Equiv.ofBijective F ⟨hi,(Fintype.bijective_iff_injective_and_card F).mpr ⟨hi,hc⟩ |>.2⟩ + refine ⟨⟨E.symm,fun e => ?_⟩⟩ + have he : f (E.symm e)=e := congrArg Subtype.val (E.apply_symm_apply e) + obtain h|h := (hf (E.symm e)).2 + · exact Or.inl (h.1.symm.trans (congrArg G.left he)) + · exact Or.inr (h.1.symm.trans (congrArg G.right he)) + +end +end AlgorithmicThinTrees.Orientations +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Flow/RootedRelaxation.lean b/lean/OAI/Combinatorics/ThinTrees/Flow/RootedRelaxation.lean new file mode 100644 index 0000000000000000000000000000000000000000..736925d29725d61f013f19735dc1327633761871 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Flow/RootedRelaxation.lean @@ -0,0 +1,136 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Flow.RootedFlow + +namespace OAI + +/-! Rooted relaxation. -/ + +section + +namespace AlgorithmicThinTrees.Orientations +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped Classical +variable {n m : ℕ} + +lemma parts_card {V : Type*} [Fintype V] (p : Setoid V) : (parts p).card=partCount p := by + let f : Quotient p → parts p := Quotient.lift + (fun v => ⟨block p v,block_mem_parts p v⟩) + (fun a b h => Subtype.ext ((block_eq_iff p a b).mpr h)) + have hf : Function.Bijective f := by + constructor + · intro a b + induction a,b using Quotient.inductionOn₂ with + | h a b => + intro he + exact Quotient.sound ((block_eq_iff p a b).mp (congrArg Subtype.val he)) + · intro A + obtain ⟨v,hv⟩ := (mem_parts p A.val).mp A.property + exact ⟨Quotient.mk p v,Subtype.ext hv⟩ + exact (Fintype.card_coe (parts p)).symm.trans (Fintype.card_congr (Equiv.ofBijective f hf)).symm + +lemma parts_sum_card (p : Setoid (Fin n)) : ∑A ∈ parts p, A.card=n := by + have h := card_biUnion (s:=parts p) (t:=id) + (fun A hA B hB hAB => parts_disjoint p hA hB hAB) + have hcov : (parts p).biUnion id=(univ : Finset (Fin n)) := by + ext v + simp only [mem_biUnion,mem_univ,iff_true] + exact ⟨block p v,block_mem_parts p v,self_mem_block p v⟩ + rw [hcov,card_univ,Fintype.card_fin] at h + exact h.symm + +lemma block_eq_of_part {p : Setoid (Fin n)} {S : Finset (Fin n)} + (hS : S ∈ parts p) {v : Fin n} (hv : v ∈ S) : S=block p v := by + obtain ⟨w,rfl⟩ := (mem_parts p S).mp hS + exact (block_eq_iff p w v).mpr ((mem_block p w v).mp hv) + +lemma internal_partition_accounting (G : MultiGraph n m) (x : Fin m → ℝ) + (p : Setoid (Fin n)) : + (∑S ∈ parts p, ∑e ∈ univ.filter (fun e => G.left e ∈ S ∧ G.right e ∈ S), x e)+ + capacity G.left G.right x p = ∑e, x e := by + simp only [sum_filter,capacity] + rw [sum_comm,←sum_add_distrib] + apply sum_congr rfl + intro e he + have hi : (∑S ∈ parts p, if G.left e ∈ S ∧ G.right e ∈ S then x e else 0)= + if p (G.left e) (G.right e) then x e else 0 := by + rw [sum_eq_single (block p (G.left e))] + · simp only [self_mem_block,mem_block,true_and] + · intro S hS hSne + apply ite_eq_right + rintro ⟨hl,hr⟩ + exact hSne (block_eq_of_part hS hl) + · intro h + exact (h (block_mem_parts p (G.left e))).elim + rw [hi,crossingIndicator] + split_ifs <;> ring + +structure FlowPoint (n m : ℕ) where + x : Fin m → ℝ + a : Fin n → Fin m → ℝ + b : Fin n → Fin m → ℝ + +def FlowPoint.Feasible (G : MultiGraph n m) (c : Fin m → ℝ) (qbar ε : ℝ) + (F : FlowPoint n m) : Prop := + (∀e, 0 ≤ F.x e ∧ F.x e ≤ c e) ∧ + (∀r e, 0 ≤ F.a r e ∧ 0 ≤ F.b r e ∧ F.x e ≤ F.a r e+F.b r e) ∧ + (∀r v, out G (F.a r) (F.b r) v ≤ if v=r then ε else qbar) ∧ + qbar*((n:ℝ)-1)-ε ≤ ∑e, F.x e + +lemma sum_root_budget {S : Finset (Fin n)} {r : Fin n} (hr : r ∈ S) (qbar ε : ℝ) : + (∑v ∈ S, if v=r then ε else qbar) = qbar*((S.card:ℝ)-1)+ε := by + have he (v : Fin n) : (if v=r then ε else qbar) = + (if v=r then ε-qbar else 0)+qbar := by split_ifs <;> ring + simp only [he,sum_add_distrib,sum_ite_eq',hr,ite_true,sum_const,nsmul_eq_mul] + ring + +lemma internal_flow_bound (G : MultiGraph n m) (c : Fin m → ℝ) {qbar ε : ℝ} + {F : FlowPoint n m} (hF : F.Feasible G c qbar ε) + (S : Finset (Fin n)) (hS : S.Nonempty) : + (∑e ∈ univ.filter (fun e => G.left e ∈ S ∧ G.right e ∈ S), F.x e) ≤ + qbar*((S.card:ℝ)-1)+ε := by + obtain ⟨r,hr⟩ := hS + calc + _ ≤ ∑v ∈ S, out G (F.a r) (F.b r) v := + internal_le_out G (fun e => (hF.2.1 r e).1) (fun e => (hF.2.1 r e).2.1) + (fun e => (hF.2.1 r e).2.2) S + _ ≤ ∑v ∈ S, if v=r then ε else qbar := sum_le_sum fun v _ => hF.2.2.1 r v + _ = _ := sum_root_budget hr qbar ε + +lemma flow_partition_bound (G : MultiGraph n m) (c : Fin m → ℝ) {qbar ε : ℝ} + {F : FlowPoint n m} (hF : F.Feasible G c qbar ε) (p : Setoid (Fin n)) : + qbar*((partCount p:ℝ)-1)-ε*((partCount p:ℝ)+1) ≤ capacity G.left G.right c p := by + have hi := sum_le_sum (s:=parts p) (fun S hS => internal_flow_bound G c hF S + ((parts_partition p).1 S hS).1) + have hs : (∑S ∈ parts p, (qbar*((S.card:ℝ)-1)+ε))= + qbar*((n:ℝ)-partCount p)+ε*partCount p := by + simp only [mul_sub,mul_one,sum_add_distrib,sum_sub_distrib,←mul_sum,sum_const,nsmul_eq_mul] + rw [←Nat.cast_sum,parts_sum_card,parts_card] + ring + rw [hs] at hi + have hcross : capacity G.left G.right F.x p ≤ capacity G.left G.right c p := + sum_le_sum fun e _ => mul_le_mul_of_nonneg_right (hF.1 e).2 (crossingIndicator_nonneg _ _ _) + have htotal := hF.2.2.2 + have haccount := internal_partition_accounting G F.x p + linarith + +theorem relaxed_flow_implies_partitions (G : MultiGraph n m) (hn : 0 < n) + (c : Fin m → ℝ) {q ε : ℝ} (hε : 0 ≤ ε) {F : FlowPoint n m} + (hF : F.Feasible G c (q+4*ε) ε) : + ∀p, 0 ≤ slack G.left G.right c q p := by + let : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + intro p + by_cases hp : p=⊤ + · subst p + simp [slack,capacity,crossingIndicator,partCount_top] + · have hd : (2:ℝ) ≤ partCount p := by exact_mod_cast two_le_partCount hp + have hb := flow_partition_bound G c hF p + have he : 0 ≤ ε*(3*(partCount p:ℝ)-5) := mul_nonneg hε (by linarith) + dsimp [slack] + nlinarith only [hb,he] + +end +end AlgorithmicThinTrees.Orientations +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/GraphMatrix.lean b/lean/OAI/Combinatorics/ThinTrees/GraphMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..18aa6a7a12f618e36c612a189e434d5b6c1fc02b --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/GraphMatrix.lean @@ -0,0 +1,87 @@ +import OAI.Combinatorics.ThinTrees.Matrix + +namespace OAI + +universe uV + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree +variable {V : Type uV} [Fintype V] [DecidableEq V] +def qform (X : Matrix V V ℝ) (v : V → ℝ) : ℝ := v ⬝ᵥ (X *ᵥ v) +omit [DecidableEq V] in +lemma qform_add (X Y : Matrix V V ℝ) (v : V → ℝ) : qform (X+Y) v=qform X v+qform Y v := by + simp [qform,add_mulVec,dotProduct_add] +omit [DecidableEq V] in +lemma qform_sub (X Y : Matrix V V ℝ) (v : V → ℝ) : qform (X-Y) v=qform X v-qform Y v := by + simp [qform,sub_mulVec,dotProduct_sub] +omit [DecidableEq V] in +lemma qform_smul (a : ℝ) (X : Matrix V V ℝ) (v : V → ℝ) : qform (a • X) v=a*qform X v := by + simp [qform,smul_mulVec,dotProduct_smul] +omit [DecidableEq V] in +lemma qform_nonneg {X : Matrix V V ℝ} (hX : X.PosSemidef) (v : V → ℝ) : 0 ≤ qform X v := by + simpa only [qform,star_trivial] using hX.dotProduct_mulVec_nonneg v +omit [DecidableEq V] in +lemma qform_mono {X Y : Matrix V V ℝ} (h : X ≤ Y) (v : V → ℝ) : qform X v ≤ qform Y v := by + have hh := qform_nonneg (Matrix.le_iff.mp h) v + rw [qform_sub] at hh + linarith +omit [DecidableEq V] in +lemma qform_continuous (v : V → ℝ) : Continuous (fun X : Matrix V V ℝ => qform X v) := by + unfold qform mulVec dotProduct + fun_prop +lemma qform_single (X : Matrix V V ℝ) (i : V) : qform X (Pi.single i 1)=X i i := by + simp [qform] +omit [Fintype V] [DecidableEq V] in +lemma posDef_of_le {X Y : Matrix V V ℝ} (hX : X.PosDef) (hXY : X ≤ Y) : Y.PosDef := by + convert hX.add_posSemidef (Matrix.le_iff.mp hXY) using 1; abel + +namespace MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) +def laplacian (F : Finset (Fin m)) : Matrix (Fin n) (Fin n) ℝ := ∑e ∈ F, vecMulVec (G.incidence e) (G.incidence e) +def resistance (X : Matrix (Fin n) (Fin n) ℝ) (e : Fin m) : ℝ := qform X⁻¹ (G.incidence e) +lemma laplacian_psd (F : Finset (Fin m)) : (G.laplacian F).PosSemidef := by + apply Matrix.posSemidef_sum + intro e _ + simpa only [star_trivial] using posSemidef_vecMulVec_self_star (G.incidence e) +lemma laplacian_qform (F : Finset (Fin m)) (v : Fin n → ℝ) : + qform (G.laplacian F) v=∑e ∈ F, (v (G.left e)-v (G.right e))^2 := by + simp only [laplacian,qform,sum_mulVec,dotProduct_sum,rankOne_quadratic] + apply sum_congr rfl + intro e _ + rw [dotProduct_comm] + congr 1 + exact G.eval_incidence v e +lemma laplacian_cut (F : Finset (Fin m)) (S : Finset (Fin n)) : + qform (G.laplacian F) (cutIndicator S)=(G.cut F S).card := by + rw [G.laplacian_qform] + simp only [cut,card_eq_sum_ones,Nat.cast_sum,sum_filter] + apply sum_congr rfl + intro e _ + by_cases hl : G.left e ∈ S <;> by_cases hr : G.right e ∈ S <;> simp [cutIndicator,hl,hr] +lemma indicator_norm (S : Finset (Fin n)) : qform (1 : Matrix (Fin n) (Fin n) ℝ) (cutIndicator S)=S.card := by + simp only [qform,one_mulVec,dotProduct,cutIndicator] + simp + +def baseMatrix : Matrix (Fin n) (Fin n) ℝ := G.laplacian univ+(n:ℝ)⁻¹ • 1 +lemma baseMatrix_pd (hn : 0 < n) : G.baseMatrix.PosDef := by + exact Matrix.PosDef.posSemidef_add (G.laplacian_psd univ) (Matrix.PosDef.one.smul (inv_pos.mpr (Nat.cast_pos.mpr hn))) +lemma baseMatrix_cut (S : Finset (Fin n)) : + qform G.baseMatrix (cutIndicator S)=(G.cut univ S).card+S.card/(n:ℝ) := by + rw [baseMatrix,qform_add,qform_smul,G.laplacian_cut,indicator_norm,mul_comm,←div_eq_mul_inv] +lemma resistance_nonneg {X : Matrix (Fin n) (Fin n) ℝ} (hX : X.PosDef) (e : Fin m) : 0 ≤ G.resistance X e := + qform_nonneg hX.inv.posSemidef _ +lemma resistance_antitone {X Y : Matrix (Fin n) (Fin n) ℝ} (hX : X.PosDef) (hY : Y.PosDef) + (h : Y ≤ X) (e : Fin m) : G.resistance X e ≤ G.resistance Y e := + StrongThinTree.resistance_antitone hX hY (Matrix.le_iff.mp h) _ + +end MultiGraph +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Hierarchy.lean b/lean/OAI/Combinatorics/ThinTrees/Hierarchy.lean new file mode 100644 index 0000000000000000000000000000000000000000..c630fefb2b6c8bfc133f9a7bb30c82a8e8beceb1 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Hierarchy.lean @@ -0,0 +1,324 @@ +import OAI.Combinatorics.ThinTrees.BagGeometry + +namespace OAI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset +variable {n m : ℕ} (G : MultiGraph n m) + +def inducedEdges (A : Finset (Fin n)) : Finset (Fin m) := + univ.filter (fun e => G.left e ∈ A ∧ G.right e ∈ A) + +def EdgeConnectedReal (A : Finset (Fin n)) (q : ℝ) : Prop := + ∀S : Finset (Fin n), S.Nonempty → S ⊂ A → q ≤ (G.cut (G.inducedEdges A) S).card + +lemma mem_inducedEdges (A : Finset (Fin n)) (e : Fin m) : + e ∈ G.inducedEdges A ↔ G.left e ∈ A ∧ G.right e ∈ A := by simp [inducedEdges] + +lemma cut_internal_split {A S : Finset (Fin n)} (hS : S ⊆ A) : + ((G.inducedEdges A).card : ℝ) = (G.inducedEdges S).card+ + (G.inducedEdges (A\S)).card+(G.cut (G.inducedEdges A) S).card := by + have heq : G.inducedEdges A = G.inducedEdges S ∪ G.inducedEdges (A\S) ∪ G.cut (G.inducedEdges A) S := by + ext e + simp only [mem_union,mem_inducedEdges,cut,mem_filter] + simp only [mem_sdiff] + constructor + · intro h + by_cases hl : G.left e ∈ S <;> by_cases hr : G.right e ∈ S <;> tauto + · intro h + rcases h with ((h | h) | h) + · exact ⟨hS h.1,hS h.2⟩ + · exact ⟨h.1.1,h.2.1⟩ + · exact h.1 + have hd : Disjoint (G.inducedEdges S) (G.inducedEdges (A\S)) := by + rw [Finset.disjoint_left] + intro e he hf + rw [mem_inducedEdges] at he hf + exact (mem_sdiff.mp hf.1).2 he.1 + have hd' : Disjoint (G.inducedEdges S ∪ G.inducedEdges (A\S)) (G.cut (G.inducedEdges A) S) := by + rw [Finset.disjoint_left] + intro e he hf + have hc := (mem_filter.mp hf).2 + rcases mem_union.mp he with he | he + · rw [mem_inducedEdges] at he + tauto + · rw [mem_inducedEdges] at he + have hl := (mem_sdiff.mp he.1).2 + have hr := (mem_sdiff.mp he.2).2 + tauto + have hc : (G.inducedEdges A).card = (G.inducedEdges S).card+ + (G.inducedEdges (A\S)).card+(G.cut (G.inducedEdges A) S).card := by + conv_lhs => rw [heq] + rw [card_union_of_disjoint hd',card_union_of_disjoint hd] + exact_mod_cast hc + +def VertexPartition (A : Finset (Fin n)) (P : Finset (Finset (Fin n))) : Prop := + (∀B ∈ P, B.Nonempty ∧ B ⊆ A) ∧ + (P : Set (Finset (Fin n))).Pairwise Disjoint ∧ P.biUnion id = A + +lemma vertexPartition_singleton {A : Finset (Fin n)} (hA : A.Nonempty) : + VertexPartition A {A} := by + refine ⟨?_,?_,by simp⟩ + · intro B hB + have heq := mem_singleton.mp hB + subst B + exact ⟨hA,Subset.rfl⟩ + · intro B hB C hC hne + exact (hne ((mem_singleton.mp hB).trans (mem_singleton.mp hC).symm)).elim + +lemma vertexPartition_union {A B : Finset (Fin n)} {P Q : Finset (Finset (Fin n))} + (hP : VertexPartition A P) (hQ : VertexPartition B Q) (hAB : Disjoint A B) : + VertexPartition (A∪B) (P∪Q) ∧ Disjoint P Q := by + have hd : ∀S ∈ P, ∀T ∈ Q, Disjoint S T := by + intro S hS T hT + exact hAB.mono (hP.1 S hS).2 (hQ.1 T hT).2 + have hPQ : Disjoint P Q := by + rw [Finset.disjoint_left] + intro S hS hT + obtain ⟨u,hu⟩ := (hP.1 S hS).1 + exact Finset.disjoint_left.mp (hd S hS S hT) hu hu + refine ⟨⟨?_,?_,?_⟩,hPQ⟩ + · intro S hS + rcases mem_union.mp hS with hS | hS + · exact ⟨(hP.1 S hS).1,((hP.1 S hS).2).trans (subset_union_left)⟩ + · exact ⟨(hQ.1 S hS).1,((hQ.1 S hS).2).trans (subset_union_right)⟩ + · intro S hS T hT hne + rcases mem_union.mp hS with hS | hS <;> rcases mem_union.mp hT with hT | hT + · exact hP.2.1 hS hT hne + · exact hd S hS T hT + · exact (hd T hT S hS).symm + · exact hQ.2.1 hS hT hne + · rw [union_biUnion,hP.2.2,hQ.2.2] + +lemma connected_partition (A : Finset (Fin n)) (hA : A.Nonempty) {q : ℝ} (_hq : 0 ≤ q) : + ∃P : Finset (Finset (Fin n)), VertexPartition A P ∧ + (∀B ∈ P, G.EdgeConnectedReal B q) ∧ + ((G.inducedEdges A).card : ℝ)-(∑B ∈ P, ((G.inducedEdges B).card : ℝ)) ≤ q*((P.card : ℝ)-1) := by + induction A using Finset.strongInductionOn with + | _ A ih => + by_cases hconn : G.EdgeConnectedReal A q + · exact ⟨{A},vertexPartition_singleton hA,by simpa,by simp⟩ + · obtain ⟨S,hSne,hSA,hcut⟩ : ∃S, S.Nonempty ∧ S ⊂ A ∧ + ((G.cut (G.inducedEdges A) S).card : ℝ) < q := by + simp only [EdgeConnectedReal,not_forall,not_le] at hconn + obtain ⟨S,hSne,hSA,hcut⟩ := hconn + exact ⟨S,hSne,hSA,hcut⟩ + have hRA : A\S ⊂ A := by + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨sdiff_subset,?_⟩ + intro heq + obtain ⟨u,hu⟩ := hSne + have : u ∈ A\S := heq.symm ▸ hSA.subset hu + exact (mem_sdiff.mp this).2 hu + have hRne : (A\S).Nonempty := by + apply sdiff_nonempty.mpr + intro hh + exact (Finset.ssubset_iff_subset_ne.mp hSA).2 (Subset.antisymm hSA.subset hh) + obtain ⟨P,hP,hPc,hPb⟩ := ih S hSA hSne + obtain ⟨Q,hQ,hQc,hQb⟩ := ih (A\S) hRA hRne + obtain ⟨hPQ,hdis⟩ := vertexPartition_union hP hQ (disjoint_sdiff_self_right) + have hcover : S ∪ (A\S) = A := union_sdiff_of_subset hSA.subset + rw [hcover] at hPQ + refine ⟨P∪Q,hPQ,?_,?_⟩ + · intro B hB + rcases mem_union.mp hB with hB | hB + · exact hPc B hB + · exact hQc B hB + · rw [sum_union hdis,card_union_of_disjoint hdis,Nat.cast_add] + have he := G.cut_internal_split hSA.subset + linarith + +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset +variable {n m : ℕ} (G : MultiGraph n m) + +def endpointMass (A : Finset (Fin n)) (e : Fin m) : ℝ := + (if G.left e ∈ A then 1 else 0)+(if G.right e ∈ A then 1 else 0) + +def volume (R A : Finset (Fin n)) : ℝ := ∑e ∈ G.inducedEdges R, G.endpointMass A e + +lemma partition_point_mass {A : Finset (Fin n)} {P : Finset (Finset (Fin n))} + (hP : VertexPartition A P) (v : Fin n) : + (∑B ∈ P, if v ∈ B then (1:ℝ) else 0) = if v ∈ A then (1:ℝ) else 0 := by + by_cases hv : v ∈ A + · obtain ⟨B,hB,hvB⟩ := mem_biUnion.mp (hP.2.2.symm ▸ hv) + rw [ite_eq_left hv,sum_eq_single B] + · exact ite_eq_left hvB + · intro C hC hCB + have hvC : v ∉ C := fun hh => Finset.disjoint_left.mp (hP.2.1 hC hB hCB) hh hvB + simp [hvC] + · exact fun hh => (hh hB).elim + · rw [ite_eq_right hv] + apply sum_eq_zero + intro B hB + exact ite_eq_right (fun hh => hv ((hP.1 B hB).2 hh)) + +lemma volume_partition {A R : Finset (Fin n)} {P : Finset (Finset (Fin n))} + (hP : VertexPartition A P) : (∑B ∈ P, G.volume R B) = G.volume R A := by + simp only [volume] + rw [sum_comm] + apply sum_congr rfl + intro e he + simp only [endpointMass,sum_add_distrib] + rw [partition_point_mass hP,partition_point_mass hP] + +lemma volume_eq_boundary {A B : Finset (Fin n)} (hBA : B ⊆ A) : + G.volume A B = ((G.cut (G.inducedEdges A) B).card : ℝ)+2*(G.inducedEdges B).card := by + have hcard (E : Finset (Fin m)) : (E.card : ℝ) = ∑e : Fin m, if e ∈ E then (1:ℝ) else 0 := by simp + rw [hcard,hcard,mul_sum,← sum_add_distrib] + simp only [volume,inducedEdges,sum_filter] + apply sum_congr rfl + intro e he + simp only [endpointMass,cut,mem_filter,mem_univ,true_and] + have hl := hBA (x := G.left e) + have hr := hBA (x := G.right e) + by_cases hlA : G.left e ∈ A <;> by_cases hrA : G.right e ∈ A <;> + by_cases hlB : G.left e ∈ B <;> by_cases hrB : G.right e ∈ B <;> + norm_num [*] at * + +lemma cut_complement_in {A B : Finset (Fin n)} (_hBA : B ⊆ A) : + G.cut (G.inducedEdges A) (A\B) = G.cut (G.inducedEdges A) B := by + ext e + simp only [cut,mem_filter,mem_inducedEdges,mem_sdiff] + tauto + +lemma outside_connected_partition {A T : Finset (Fin n)} {k : ℝ} + (hk : 0 < k) (hconn : G.EdgeConnectedReal A k) (hT : T.Nonempty) (hTA : T ⊂ A) : + ∃P : Finset (Finset (Fin n)), VertexPartition (A\T) P ∧ + (∀B ∈ P, G.EdgeConnectedReal B (k/4)) ∧ + (P.card : ℝ)*k ≤ 2*(G.cut (G.inducedEdges A) T).card := by + have hR : (A\T).Nonempty := by + apply sdiff_nonempty.mpr + intro hh + exact (Finset.ssubset_iff_subset_ne.mp hTA).2 (Subset.antisymm hTA.subset hh) + obtain ⟨P,hP,hPc,hcost⟩ := G.connected_partition (A\T) hR (by positivity : 0 ≤ k/4) + have hBA : ∀B ∈ P, B ⊆ A := fun B hB => ((hP.1 B hB).2).trans sdiff_subset + have hcuts : (P.card : ℝ)*k ≤ ∑B ∈ P, ((G.cut (G.inducedEdges A) B).card : ℝ) := by + calc + _ = ∑B ∈ P, k := by simp + _ ≤ _ := by + apply sum_le_sum + intro B hB + apply hconn B (hP.1 B hB).1 + refine Finset.ssubset_iff_subset_ne.mpr ⟨hBA B hB,?_⟩ + intro heq + obtain ⟨v,hv⟩ := hT + have hh := (hP.1 B hB).2 (heq.symm ▸ hTA.subset hv) + exact (mem_sdiff.mp hh).2 hv + have hvol : (∑B ∈ P, ((G.cut (G.inducedEdges A) B).card : ℝ))+ + 2*(∑B ∈ P, ((G.inducedEdges B).card : ℝ)) = + ((G.cut (G.inducedEdges A) T).card : ℝ)+2*(G.inducedEdges (A\T)).card := by + calc + _ = ∑B ∈ P, G.volume A B := by + rw [mul_sum,← sum_add_distrib] + exact sum_congr rfl (fun B hB => (G.volume_eq_boundary (hBA B hB)).symm) + _ = G.volume A (A\T) := G.volume_partition hP + _ = _ := by rw [G.volume_eq_boundary sdiff_subset,G.cut_complement_in hTA.subset] + refine ⟨P,hP,hPc,?_⟩ + nlinarith + +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset + +structure Hierarchy (n : ℕ) where + nodes : Finset (Finset (Fin n)) + nonempty : ∀A ∈ nodes, A.Nonempty + root_mem : univ ∈ nodes + singletons : ∀v, {v} ∈ nodes + laminar : ∀A ∈ nodes, ∀B ∈ nodes, A ⊆ B ∨ B ⊆ A ∨ Disjoint A B + parent : Finset (Fin n) → Finset (Fin n) + parent_mem : ∀A ∈ nodes, A ≠ univ → parent A ∈ nodes + parent_strict : ∀A ∈ nodes, A ≠ univ → A ⊂ parent A + parent_minimal : ∀A ∈ nodes, A ≠ univ → ∀B ∈ nodes, A ⊂ B → parent A ⊆ B + +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (G : MultiGraph n m) + +lemma routed_variation_lower {R L : Finset (Fin n)} {q a b : ℝ} + (f : Fin n → ℝ) (hab : a ≤ b) (hconn : G.EdgeConnectedReal R q) + (hu : ∃u ∈ R, u ∈ L ∧ f u ≤ a) (hv : ∃v ∈ R, b ≤ f v) + (hprotect : ∀e ∈ G.inducedEdges R, + ((G.left e ∈ L ∧ G.right e ∉ L) ∨ (G.right e ∈ L ∧ G.left e ∉ L)) → + b ≤ f (G.left e) ∧ b ≤ f (G.right e)) : + q*(b-a) ≤ ∑e ∈ G.inducedEdges L, + |clamp a b (f (G.left e))-clamp a b (f (G.right e))| := by + have hh := cut_range_bound (k := q) (fun e : G.inducedEdges L => G.left e) + (fun e : G.inducedEdges L => G.right e) (fun v => clamp a b (f v)) hab + rw [← Finset.sum_coe_sort] + apply hh + intro t ht + let S := R.filter (fun v => v ∈ L ∧ f v < t) + have hSR : S ⊆ R := filter_subset _ _ + have hSn : S.Nonempty := by + obtain ⟨u,huR,huL,hu⟩ := hu + exact ⟨u,mem_filter.mpr ⟨huR,huL,lt_of_le_of_lt hu ht.1⟩⟩ + have hSproper : S ⊂ R := by + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨hSR,?_⟩ + intro heq + obtain ⟨v,hvR,hv⟩ := hv + have hh := (mem_filter.mp (heq.symm ▸ hvR)).2.2 + linarith [ht.2] + have hc := hconn S hSn hSproper + have hedge : ∀e ∈ G.cut (G.inducedEdges R) S, e ∈ G.inducedEdges L ∧ + ((f (G.left e) hcut.2 (mem_filter.mpr ⟨hrR,hrL,hh⟩) + exact ⟨(G.mem_inducedEdges _ _).mpr ⟨hl.1,hrL⟩,Or.inl ⟨hl.2,hr⟩⟩ + · have hr := (mem_filter.mp hcut.1).2 + have hlL : G.left e ∈ L := by + by_contra hh + have hp := (hprotect e heR (Or.inr ⟨hr.1,hh⟩)).2 + linarith [ht.2,hr.2] + have hl : ¬f (G.left e) hcut.2 (mem_filter.mpr ⟨hlR,hlL,hh⟩) + exact ⟨(G.mem_inducedEdges _ _).mpr ⟨hlL,hr.1⟩,Or.inr ⟨hr.2,hl⟩⟩ + have hcard : (G.cut (G.inducedEdges R) S).card ≤ + (univ.filter (fun e : G.inducedEdges L => + (clamp a b (f (G.left e)) + (clamp a b (f (G.left e)) x.val.val) hh + exact hc.trans (by exact_mod_cast hcard) + +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/HierarchyBounds.lean b/lean/OAI/Combinatorics/ThinTrees/HierarchyBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..9c24a8868eeee260eb271e41cf0790eec2c9ac82 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/HierarchyBounds.lean @@ -0,0 +1,360 @@ +import OAI.Combinatorics.ThinTrees.MatrixDomain + +namespace OAI + +section + +noncomputable section +open Finset Filter +open scoped Topology +namespace StrongThinTree.ShortcutNumeric +open MultiGraph.Hierarchy + +lemma eventually_affine_log_lt_rpow (a b : ℝ) {z : ℝ} (hz : 0 < z) : + ∀ᶠ x : ℝ in atTop, a+b*Real.log x < x^z := by + have hc : Tendsto (fun x : ℝ => a/x^z) atTop (𝓝 0) := by + simpa only [div_eq_mul_inv,mul_zero,Pi.inv_apply] using + ((tendsto_rpow_atTop hz).inv_tendsto_atTop.const_mul a) + have hl := (isLittleO_log_rpow_atTop hz).tendsto_div_nhds_zero.const_mul b + have ht : Tendsto (fun x : ℝ => (a+b*Real.log x)/x^z) atTop (𝓝 0) := by + convert hc.add hl using 1 <;> simp only [mul_zero,add_zero,add_div,mul_div_assoc] + filter_upwards [ht.eventually_lt_const (show (0:ℝ)<1 by norm_num),eventually_gt_atTop (0:ℝ)] with x hx hxp + exact (div_lt_one (Real.rpow_pos_of_pos hxp _)).mp hx + +lemma eventually_const_mul_rpow_le_rpow (c : ℝ) {a b : ℝ} (hab : a < b) : + ∀ᶠ x : ℝ in atTop, c*x^a ≤ x^b := by + have hh := (tendsto_rpow_atTop (sub_pos.mpr hab)).eventually (eventually_ge_atTop c) + filter_upwards [hh,eventually_gt_atTop (0:ℝ)] with x hx hxp + calc + c*x^a ≤ x^(b-a)*x^a := mul_le_mul_of_nonneg_right hx (Real.rpow_nonneg hxp.le _) + _ = x^b := by rw [←Real.rpow_add hxp]; congr 1; ring + +lemma eventually_logb_mul_rpow_lt (c a b : ℝ) (hc : 0 < c) {z : ℝ} (hz : 0 < z) : + ∀ᶠ x : ℝ in atTop, Real.logb 2 (c*x^a)+b < x^z := by + filter_upwards [eventually_affine_log_lt_rpow (Real.log c/Real.log 2+b) (a/Real.log 2) hz, + eventually_gt_atTop (0:ℝ)] with x hx hxp + rw [Real.logb,Real.log_mul hc.ne' (Real.rpow_pos_of_pos hxp a).ne',Real.log_rpow hxp] + convert hx using 1; ring + +def alpha (x : ℝ) : ℝ := x^(-4/5:ℝ) +def gamma (x : ℝ) : ℝ := truncationGain (alpha x) +def scale (x : ℝ) : ℝ := alpha x*gamma x/32 +def rho (x : ℝ) : ℝ := 1/(2*x^2) +def count (x : ℝ) : ℕ := ⌈x^(1/100:ℝ)⌉₊ + +lemma bins_log (x : ℝ) (hx : 0 < x) : + Real.logb 2 (256/(alpha x)^2) = Real.logb 2 256+(8/5:ℝ)/Real.log 2*Real.log x := by + have ha : 0 < alpha x := Real.rpow_pos_of_pos hx _ + rw [Real.logb,Real.log_div (by norm_num) (pow_ne_zero _ ha.ne'),Real.log_pow, + alpha,Real.log_rpow hx,Real.logb] + ring + +lemma eventually_bins_le : + ∀ᶠ x : ℝ in atTop, (truncationBins (alpha x) : ℝ) ≤ x^(1/1000:ℝ) := by + filter_upwards [eventually_affine_log_lt_rpow (Real.logb 2 256+2) ((8/5:ℝ)/Real.log 2) + (show 0 < (1/1000:ℝ) by norm_num),eventually_ge_atTop (1:ℝ)] with x hh hx + have hxp : 0 < x := zero_lt_one.trans_le hx + have hlog : 0 ≤ Real.logb 2 (256/alpha x^2) := by + rw [bins_log x hxp] + have hlogx := Real.log_nonneg hx + have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlog256 : 0 ≤ Real.logb 2 256 := Real.logb_nonneg (by norm_num) (by norm_num) + positivity + have hc := Nat.ceil_lt_add_one hlog + dsimp [truncationBins] + push_cast + rw [bins_log x hxp] at hc ⊢ + linarith + +lemma gamma_pos {x : ℝ} : 0 < gamma x := truncationGain_pos _ +lemma scale_pos {x : ℝ} (hx : 0 < x) : 0 < scale x := by + have ha : 0 < alpha x := Real.rpow_pos_of_pos hx _ + have hg : 0 < gamma x := gamma_pos + dsimp [scale]; positivity + +lemma gamma_le_one (x : ℝ) : gamma x ≤ 1 := by + have hJ : 1 ≤ (truncationBins (alpha x) : ℝ) := by + dsimp [truncationBins] + push_cast + have hh : (0:ℝ) ≤ ⌈Real.logb 2 (256/alpha x^2)⌉₊ := Nat.cast_nonneg _ + linarith + have hp : 1 ≤ (truncationBins (alpha x) : ℝ)^4 := one_le_pow₀ hJ + change 1/(4*(truncationBins (alpha x) : ℝ)^4) ≤ 1 + apply (div_le_one (by positivity : (0:ℝ)<4*(truncationBins (alpha x):ℝ)^4)).mpr + linarith + +lemma eventually_gamma_lower : + ∀ᶠ x : ℝ in atTop, x^(-1/100:ℝ) ≤ gamma x := by + filter_upwards [eventually_bins_le, + eventually_const_mul_rpow_le_rpow 4 (show (1/250:ℝ)<1/100 by norm_num), + eventually_gt_atTop (0:ℝ)] with x hJ hc hx + have hp : 4*(truncationBins (alpha x):ℝ)^4 ≤ x^(1/100:ℝ) := by + calc + _ ≤ 4*(x^(1/1000:ℝ))^4 := mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (Nat.cast_nonneg _) hJ 4) (by norm_num) + _ = 4*x^(1/250:ℝ) := by + rw [←Real.rpow_natCast,←Real.rpow_mul hx.le] + norm_num + _ ≤ _ := hc + have hJp : 0 < (truncationBins (alpha x):ℝ) := by + dsimp [truncationBins] + positivity + rw [show (-1/100:ℝ)=-(1/100) by ring,Real.rpow_neg hx.le] + change (x^(1/100:ℝ))⁻¹ ≤ 1/(4*(truncationBins (alpha x):ℝ)^4) + simpa only [one_div] using one_div_le_one_div_of_le (by positivity) hp + +lemma scale_le_alpha {x : ℝ} (hx : 0 < x) : scale x ≤ alpha x := by + have ha : 0 < alpha x := Real.rpow_pos_of_pos hx _ + have hh := mul_le_mul_of_nonneg_left (gamma_le_one x) ha.le + dsimp [scale] + apply (div_le_iff₀ (by norm_num : (0:ℝ)<32)).mpr + nlinarith + +lemma eventually_scale_lower : + ∀ᶠ x : ℝ in atTop, x^(-41/50:ℝ) ≤ scale x := by + filter_upwards [eventually_gamma_lower, + eventually_const_mul_rpow_le_rpow 32 (show (-41/50:ℝ) < -81/100 by norm_num), + eventually_gt_atTop (0:ℝ)] with x hg hc hx + have ha : 0 < alpha x := Real.rpow_pos_of_pos hx _ + have hh := mul_le_mul_of_nonneg_left hg ha.le + have heq : alpha x*x^(-1/100:ℝ)=x^(-81/100:ℝ) := by + rw [alpha,←Real.rpow_add hx] + norm_num + rw [heq] at hh + dsimp [scale] + apply (le_div_iff₀ (by norm_num : (0:ℝ)<32)).mpr + nlinarith + +lemma count_pos {x : ℝ} (hx : 0 < x) : 0 < count x := + Nat.ceil_pos.mpr (Real.rpow_pos_of_pos hx _) + +lemma count_upper {x : ℝ} (hx : 1 ≤ x) : (count x : ℝ) ≤ 2*x^(1/100:ℝ) := by + have hh : 1 ≤ x^(1/100:ℝ) := Real.one_le_rpow hx (by norm_num) + have hc := Nat.ceil_lt_add_one (Real.rpow_nonneg (zero_le_one.trans hx) (1/100:ℝ)) + change (⌈x^(1/100:ℝ)⌉₊:ℝ) ≤ _ + linarith + +lemma eventually_small : + ∀ᶠ x : ℝ in atTop, (scale x)^(1/10:ℝ) ≤ 1/(1728*(1024/(1/10:ℝ)^2)) := by + have ht : Tendsto (fun x : ℝ => x^(-2/25:ℝ)) atTop (𝓝 0) := by + convert tendsto_rpow_neg_atTop (show (0:ℝ)<2/25 by norm_num) using 1; norm_num + filter_upwards [ht.eventually_lt_const (show (0:ℝ)<1/(1728*(1024/(1/10:ℝ)^2)) by norm_num), + eventually_gt_atTop (0:ℝ)] with x hh hx + have hl := Real.rpow_le_rpow (scale_pos hx).le (scale_le_alpha hx) (by norm_num : (0:ℝ)≤1/10) + have heq : (alpha x)^(1/10:ℝ)=x^(-2/25:ℝ) := by + rw [alpha,←Real.rpow_mul hx.le] + norm_num + rw [heq] at hl + exact hl.trans hh.le + +lemma eventually_assignment : + ∀ᶠ x : ℝ in atTop, 6144/x ≤ (scale x)^(1+2*(1/10:ℝ)) := by + filter_upwards [eventually_scale_lower, + eventually_const_mul_rpow_le_rpow 6144 (show (-1:ℝ) < -123/125 by norm_num), + eventually_gt_atTop (0:ℝ)] with x hs hc hx + have hh := Real.rpow_le_rpow (Real.rpow_nonneg hx.le _) hs + (by norm_num : (0:ℝ)≤1+2*(1/10:ℝ)) + rw [←Real.rpow_mul hx.le] at hh + norm_num at hh + norm_num only at hc ⊢ + simpa only [Real.rpow_neg_one,div_eq_mul_inv] using hc.trans hh + +lemma eventually_log_count_left : + ∀ᶠ x : ℝ in atTop, Real.logb 2 (16/(alpha x*gamma x))+1 < (count x:ℝ) := by + filter_upwards [eventually_gamma_lower, + eventually_logb_mul_rpow_lt 16 (81/100) 1 (by norm_num) (show (0:ℝ)<1/100 by norm_num), + eventually_gt_atTop (0:ℝ)] with x hg hh hx + have hb : x^(-81/100:ℝ) ≤ alpha x*gamma x := by + have h := mul_le_mul_of_nonneg_left hg (Real.rpow_nonneg hx.le (-4/5:ℝ)) + rw [←Real.rpow_add hx] at h + norm_num at h + norm_num [alpha] at ⊢ + exact h + have harg : 16/(alpha x*gamma x) ≤ 16*x^(81/100:ℝ) := by + calc + _ ≤ 16/x^(-81/100:ℝ) := div_le_div_of_nonneg_left (by norm_num) (Real.rpow_pos_of_pos hx _) hb + _ = _ := by rw [show (-81/100:ℝ)=-(81/100) by ring,Real.rpow_neg hx.le,div_inv_eq_mul] + have hp : 0 < 16/(alpha x*gamma x) := by + have ha : 0 < alpha x := Real.rpow_pos_of_pos hx _ + have hg : 0 < gamma x := gamma_pos + positivity + have hl := (Real.logb_le_logb (by norm_num : (1:ℝ)<2) hp (hp.trans_le harg)).mpr harg + have hcount := Nat.le_ceil (x^(1/100:ℝ)) + dsimp [count] + linarith + +lemma eventually_log_count_right : + ∀ᶠ x : ℝ in atTop, Real.logb 2 (24/(rho x*(scale x)^2)) < (count x:ℝ) := by + filter_upwards [eventually_scale_lower, + eventually_logb_mul_rpow_lt 48 (91/25) 0 (by norm_num) (show (0:ℝ)<1/100 by norm_num), + eventually_gt_atTop (0:ℝ)] with x hs hh hx + have hs2 : x^(-41/25:ℝ) ≤ (scale x)^2 := by + have h := pow_le_pow_left₀ (Real.rpow_nonneg hx.le _) hs 2 + rw [←Real.rpow_natCast,←Real.rpow_mul hx.le] at h + norm_num at h + norm_num at ⊢ + exact h + have hr : 0 < rho x := by dsimp [rho]; positivity + have hp : 0 < rho x*(scale x)^2 := mul_pos hr (sq_pos_of_pos (scale_pos hx)) + have harg : 24/(rho x*(scale x)^2) ≤ 48*x^(91/25:ℝ) := by + apply (div_le_iff₀ hp).mpr + calc + 24 = (48*x^(91/25:ℝ)*rho x)*x^(-41/25:ℝ) := by + rw [rho] + have heq : x^(91/25:ℝ)*x^(-41/25:ℝ)=x^2 := by + rw [←Real.rpow_add hx] + norm_num + field_simp + nlinarith only [heq] + _ ≤ (48*x^(91/25:ℝ)*rho x)*(scale x)^2 := + mul_le_mul_of_nonneg_left hs2 (by positivity) + _ = _ := by ring + have hl := (Real.logb_le_logb (by norm_num : (1:ℝ)<2) (div_pos (by norm_num) hp) + ((div_pos (by norm_num) hp).trans_le harg)).mpr harg + exact hl.trans_lt (by simpa only [add_zero,count] using hh.trans_le (Nat.le_ceil _)) + +def coefficient (x : ℝ) : ℝ := + 2*alpha x+2*(count x:ℝ)*(count x:ℝ)/ + ((x/8192)*((scale x)^(1/10:ℝ)/(6912*(1024/(1/10:ℝ)^2)))*gamma x) + +def largeConstant : ℝ := 8*8192*6912*102400 + +lemma coefficient_eq {x : ℝ} (hx : 0 < x) : + coefficient x = 2*alpha x+(2*8192*6912*102400)*((count x:ℝ)^2)/(x*(scale x)^(1/10:ℝ)*gamma x) := by + unfold coefficient + norm_num + field_simp + ring + +lemma eventually_denominator_lower : + ∀ᶠ x : ℝ in atTop, x^(227/250:ℝ) ≤ x*(scale x)^(1/10:ℝ)*gamma x := by + filter_upwards [eventually_scale_lower,eventually_gamma_lower,eventually_gt_atTop (0:ℝ)] with x hs hg hx + have hsp := Real.rpow_le_rpow (Real.rpow_nonneg hx.le _) hs (by norm_num : (0:ℝ)≤1/10) + rw [←Real.rpow_mul hx.le] at hsp + have hh := mul_le_mul (mul_le_mul_of_nonneg_left hsp hx.le) hg (Real.rpow_nonneg hx.le _) + (mul_nonneg hx.le (Real.rpow_nonneg (scale_pos hx).le _)) + have heq : x*x^((-41/50:ℝ)*(1/10))*x^(-1/100:ℝ)=x^(227/250:ℝ) := by + calc + _ = x^((1:ℝ)+(-41/50:ℝ)*(1/10))*x^(-1/100:ℝ) := by + rw [Real.rpow_add hx,Real.rpow_one] + _ = _ := by rw [←Real.rpow_add hx]; norm_num + rwa [heq] at hh + +lemma eventually_coefficient_bound : + ∀ᶠ x : ℝ in atTop, coefficient x ≤ 2*x^(-4/5:ℝ)+largeConstant*x^(-111/125:ℝ) := by + filter_upwards [eventually_denominator_lower,eventually_ge_atTop (1:ℝ)] with x hd hx + have hxp : 0 < x := zero_lt_one.trans_le hx + have hc : (count x:ℝ)^2 ≤ 4*x^(1/50:ℝ) := by + have hh := pow_le_pow_left₀ (Nat.cast_nonneg _) (count_upper hx) 2 + rw [mul_pow,←Real.rpow_natCast (x^(1/100:ℝ)) 2,←Real.rpow_mul hxp.le] at hh + norm_num at hh + exact hh + rw [coefficient_eq hxp] + apply add_le_add (le_refl (2*alpha x)) + calc + _ ≤ (2*8192*6912*102400)*(4*x^(1/50:ℝ))/x^(227/250:ℝ) := + div_le_div₀ (by positivity) (mul_le_mul_of_nonneg_left hc (by norm_num)) + (Real.rpow_pos_of_pos hxp _) hd + _ = largeConstant*x^(-111/125:ℝ) := by + calc + _ = largeConstant*(x^(1/50:ℝ)/x^(227/250:ℝ)) := by unfold largeConstant; ring + _ = _ := by rw [←Real.rpow_sub hxp]; norm_num + +lemma eventually_coefficient_small : + ∀ᶠ x : ℝ in atTop, coefficient x ≤ x^(-31/40:ℝ)/2 := by + filter_upwards [eventually_coefficient_bound, + eventually_const_mul_rpow_le_rpow 8 (show (-4/5:ℝ) < -31/40 by norm_num), + eventually_const_mul_rpow_le_rpow (4*largeConstant) (show (-111/125:ℝ) < -31/40 by norm_num)] + with x hb h1 h2 + nlinarith + +lemma eventually_rho_small : + ∀ᶠ x : ℝ in atTop, rho x ≤ 1/1536 := by + filter_upwards [eventually_ge_atTop (100:ℝ)] with x hx + have hp : 0 < 2*x^2 := by positivity + apply (div_le_iff₀ hp).mpr + nlinarith [sq_nonneg (x-100)] + +structure GoodParameters (x : ℝ) : Prop where + large : 2 ≤ x + small : (scale x)^(1/10:ℝ) ≤ 1/(1728*(1024/(1/10:ℝ)^2)) + assignment : 6144/x ≤ (scale x)^(1+2*(1/10:ℝ)) + rho_small : rho x ≤ 1/1536 + log_left : Real.logb 2 (16/(alpha x*gamma x))+1 < (count x:ℝ) + log_right : Real.logb 2 (24/(rho x*(scale x)^2)) < (count x:ℝ) + coefficient_small : coefficient x ≤ x^(-31/40:ℝ)/2 + +lemma eventually_good : ∀ᶠ x : ℝ in atTop, GoodParameters x := by + filter_upwards [eventually_ge_atTop (2:ℝ),eventually_small,eventually_assignment, + eventually_rho_small,eventually_log_count_left,eventually_log_count_right, + eventually_coefficient_small] with x h1 h2 h3 h4 h5 h6 h7 + exact ⟨h1,h2,h3,h4,h5,h6,h7⟩ + +lemma exists_cutoff : ∃qH : ℕ, 2 ≤ qH ∧ ∀q : ℕ, qH ≤ q → GoodParameters q := by + have hh : ∀ᶠ q : ℕ in atTop, GoodParameters q := + (tendsto_natCast_atTop_atTop : Tendsto (fun q : ℕ => (q:ℝ)) atTop atTop).eventually eventually_good + obtain ⟨qH,hqH⟩ := hh.exists_forall_of_atTop + exact ⟨max 2 qH,le_max_left _ _,fun q hq => hqH q ((le_max_right _ _).trans hq)⟩ + +end StrongThinTree.ShortcutNumeric + +namespace StrongThinTree.MultiGraph.Hierarchy +open Matrix Finset ShortcutNumeric +open scoped Classical MatrixOrder +variable {n m : ℕ} {G : MultiGraph n m} {H : Hierarchy n} + +lemma edgeConnected_of_locally {q : ℕ} (hconn : H.LocallyConnectedReal G q) : G.EdgeConnected q := by + intro S hS hS' + have hh := hconn univ H.root_mem S hS (Finset.ssubset_iff_subset_ne.mpr ⟨subset_univ _,hS'⟩) + have heq : G.inducedEdges univ=univ := by ext e; simp [MultiGraph.inducedEdges] + rw [heq] at hh + exact_mod_cast hh + +theorem polynomial_shortcut : + ∃qH : ℕ, 2 ≤ qH ∧ ∀q : ℕ, qH ≤ q → + ∀(n m : ℕ) (G : MultiGraph n m) (H : Hierarchy n), + H.LocallyConnectedReal G q → + ∀M : Finset (Finset (Fin n)), M ⊆ H.nodes → + (∀t ∈ M, t ≠ univ) → + (∀t ∈ M, ((G.cut univ t).card : ℝ)/q ≤ (H.parentBoundary G t).card) → + ∃D : Matrix (Fin n) (Fin n) ℝ, D.PosDef ∧ + (∀S : Finset (Fin n), S.Nonempty → S ≠ univ → + cutIndicator S ⬝ᵥ (D *ᵥ cutIndicator S) ≤ ((G.cut univ S).card : ℝ)) ∧ + (∀t ∈ M, ShortcutDual.boundaryAverage G.incidence (H.parentBoundary G) t D ≤ + (q:ℝ)^(-31/40:ℝ)) := by + obtain ⟨qH,hqH,hgood⟩ := exists_cutoff + refine ⟨qH,hqH,?_⟩ + intro q hq n m G H hconn M hM hroot hratio + have hg := hgood q hq + have hqpos : 0 < q := lt_of_lt_of_le (by omega : 0 < qH) hq + have hqp : (0:ℝ) < q := Nat.cast_pos.mpr hqpos + have hq1 : (1:ℝ) ≤ q := le_trans (by norm_num) hg.large + have hα : 0 < alpha q := Real.rpow_pos_of_pos hqp _ + have hα1 : alpha q ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos hq1 (by norm_num) + have hρ : 0 < rho q := by dsimp [rho]; positivity + have hr : ∀t ∈ M, (q:ℝ)*rho q*((G.cut univ t).card : ℝ) ≤ (H.parentBoundary G t).card := by + intro t ht + have heq : (q:ℝ)*rho q*((G.cut univ t).card : ℝ)=((G.cut univ t).card : ℝ)/q/2 := by + unfold rho + field_simp + rw [heq] + have hp : (0:ℝ) ≤ ((G.cut univ t).card : ℝ)/q := div_nonneg (Nat.cast_nonneg _) hqp.le + exact (by linarith : ((G.cut univ t).card : ℝ)/q/2 ≤ ((G.cut univ t).card : ℝ)/q).trans (hratio t ht) + have hη : 0 < (q:ℝ)^(-31/40:ℝ)/2 := by positivity + obtain ⟨D,hD,hb,hc⟩ := exists_shortcut_explicit hqpos (count_pos hqp) (count_pos hqp) + (edgeConnected_of_locally hconn) hconn M hM hroot hα hα1 + (by norm_num : (0:ℝ)<1/10) (by norm_num : (1/10:ℝ)<1/3) + hρ hg.rho_small hg.small hg.assignment hr hg.log_left hg.log_right hη + refine ⟨D,hD,fun S hS hS' => (hc S hS hS').le,?_⟩ + intro t ht + have hh := hb t ht + have hcoef : shortcutCoefficient q (count q) (count q) (alpha q) (1/10)=coefficient q := rfl + rw [hcoef] at hh + linarith [hg.coefficient_small] + +end StrongThinTree.MultiGraph.Hierarchy + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/HierarchyBuilder.lean b/lean/OAI/Combinatorics/ThinTrees/HierarchyBuilder.lean new file mode 100644 index 0000000000000000000000000000000000000000..2701edb35b96aabba19fde1fc06e8d89a20920e9 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/HierarchyBuilder.lean @@ -0,0 +1,166 @@ +import OAI.Combinatorics.ThinTrees.PartitionRank + +namespace OAI + +section + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset +variable {n : ℕ} + +namespace Hierarchy + +theorem exists_structure (N : Finset (Finset (Fin n))) + (hne : ∀A ∈ N, A.Nonempty) (hroot : univ ∈ N) + (hleaf : ∀v, {v} ∈ N) + (hlam : ∀A ∈ N, ∀B ∈ N, A ⊆ B ∨ B ⊆ A ∨ Disjoint A B) : + ∃ H : Hierarchy n, H.nodes=N := by + classical + have hp (A : Finset (Fin n)) (hA : A ∈ N) (hAr : A ≠ univ) : + ∃B ∈ N, A ⊂ B ∧ ∀C ∈ N, A ⊂ C → B ⊆ C := by + let U := N.filter (fun B => A ⊂ B) + have hu : univ ∈ U := mem_filter.mpr ⟨hroot, + Finset.ssubset_iff_subset_ne.mpr ⟨subset_univ _,hAr⟩⟩ + obtain ⟨B,hB,hmin⟩ := exists_min_image U card ⟨univ,hu⟩ + obtain ⟨hBN,hAB⟩ := mem_filter.mp hB + refine ⟨B,hBN,hAB,?_⟩ + intro C hCN hAC + rcases hlam B hBN C hCN with hBC | hCB | hd + · exact hBC + · have hc : C ∈ U := mem_filter.mpr ⟨hCN,hAC⟩ + exact (eq_of_subset_of_card_le hCB (hmin C hc)).symm.subset + · obtain ⟨a,ha⟩ := hne A hA + exact False.elim (disjoint_left.mp hd (hAB.subset ha) (hAC.subset ha)) + let par (A : Finset (Fin n)) := if h : A ∈ N ∧ A ≠ univ then (hp A h.1 h.2).choose else univ + have hs (A : Finset (Fin n)) (hA : A ∈ N) (hAr : A ≠ univ) : + par A ∈ N ∧ A ⊂ par A ∧ ∀C ∈ N, A ⊂ C → par A ⊆ C := by + dsimp [par] + rw [dite_eq_left ⟨hA,hAr⟩] + exact (hp A hA hAr).choose_spec + exact ⟨⟨N,hne,hroot,hleaf,hlam,par, + fun A hA hAr => (hs A hA hAr).1, + fun A hA hAr => (hs A hA hAr).2.1, + fun A hA hAr => (hs A hA hAr).2.2⟩,rfl⟩ +end Hierarchy + +structure PartitionChain (n : ℕ) where + parts : ℕ → Finset (Finset (Fin n)) + partition : ∀i, VertexPartition univ (parts i) + coarsens : ∀i j, i ≤ j → ∀A ∈ parts i, ∃B ∈ parts j, A ⊆ B + +namespace PartitionChain +variable (P : PartitionChain n) +lemma parts_nonempty {i : ℕ} {A : Finset (Fin n)} (hA : A ∈ P.parts i) : A.Nonempty := + ((P.partition i).1 A hA).1 + +lemma parts_disjoint {i : ℕ} {A B : Finset (Fin n)} + (hA : A ∈ P.parts i) (hB : B ∈ P.parts i) (hne : A ≠ B) : Disjoint A B := + (P.partition i).2.1 hA hB hne + +lemma part_exists (i : ℕ) (v : Fin n) : ∃A ∈ P.parts i, v ∈ A := by + have hv : v ∈ (P.parts i).biUnion id := (P.partition i).2.2.symm ▸ mem_univ v + exact mem_biUnion.mp hv + +lemma intersect_eq {i : ℕ} {A B : Finset (Fin n)} + (hA : A ∈ P.parts i) (hB : B ∈ P.parts i) (hab : (A ∩ B).Nonempty) : A=B := by + by_contra h + exact hab.ne_empty (disjoint_iff_inter_eq_empty.mp (P.parts_disjoint hA hB h)) + +lemma subset_of_intersect {i j : ℕ} (hij : i ≤ j) {A B : Finset (Fin n)} + (hA : A ∈ P.parts i) (hB : B ∈ P.parts j) (hab : (A ∩ B).Nonempty) : A ⊆ B := by + obtain ⟨C,hC,hAC⟩ := P.coarsens i j hij A hA + have hCB : (C ∩ B).Nonempty := by + obtain ⟨v,hv⟩ := hab + exact ⟨v,mem_inter.mpr ⟨hAC (mem_inter.mp hv).1,(mem_inter.mp hv).2⟩⟩ + exact P.intersect_eq hC hB hCB ▸ hAC + +lemma laminar {i j : ℕ} {A B : Finset (Fin n)} + (hA : A ∈ P.parts i) (hB : B ∈ P.parts j) : + A ⊆ B ∨ B ⊆ A ∨ Disjoint A B := by + by_cases hd : Disjoint A B + · exact Or.inr (Or.inr hd) + have he := not_disjoint_iff_nonempty_inter.mp hd + rcases le_total i j with hij | hji + · exact Or.inl (P.subset_of_intersect hij hA hB he) + · exact Or.inr (Or.inl (P.subset_of_intersect hji hB hA (by simpa [inter_comm] using he))) + +def nodes (I : Finset ℕ) : Finset (Finset (Fin n)) := + I.biUnion P.parts ∪ univ.image (fun v : Fin n => {v}) + +lemma mem_nodes {I : Finset ℕ} {A : Finset (Fin n)} : + A ∈ P.nodes I ↔ (∃i ∈ I, A ∈ P.parts i) ∨ ∃v, A={v} := by + simp only [nodes,mem_union,mem_biUnion,mem_image,mem_univ,true_and] + constructor + · rintro (h | ⟨v,hv⟩) + · exact Or.inl h + · exact Or.inr ⟨v,hv.symm⟩ + · rintro (h | ⟨v,hv⟩) + · exact Or.inl h + · exact Or.inr ⟨v,hv.symm⟩ + +lemma nodes_nonempty {I : Finset ℕ} {A : Finset (Fin n)} (hA : A ∈ P.nodes I) : A.Nonempty := by + rcases P.mem_nodes.mp hA with ⟨i,_,hi⟩ | ⟨v,rfl⟩ + · exact P.parts_nonempty hi + · exact singleton_nonempty _ + +lemma nodes_laminar (I : Finset ℕ) : ∀A ∈ P.nodes I, ∀B ∈ P.nodes I, + A ⊆ B ∨ B ⊆ A ∨ Disjoint A B := by + intro A hA B hB + rcases P.mem_nodes.mp hA with ⟨i,_,hi⟩ | ⟨v,rfl⟩ <;> + rcases P.mem_nodes.mp hB with ⟨j,_,hj⟩ | ⟨w,rfl⟩ + · exact P.laminar hi hj + · by_cases h : w ∈ A + · exact Or.inr (Or.inl (singleton_subset_iff.mpr h)) + · exact Or.inr (Or.inr (disjoint_singleton_right.mpr h)) + · by_cases h : v ∈ B + · exact Or.inl (singleton_subset_iff.mpr h) + · exact Or.inr (Or.inr (disjoint_singleton_left.mpr h)) + · by_cases h : v=w + · exact Or.inl (h ▸ Subset.rfl) + · exact Or.inr (Or.inr (disjoint_singleton.mpr h)) + +lemma exists_hierarchy (I : Finset ℕ) (hroot : ∃i ∈ I, univ ∈ P.parts i) : + ∃H : Hierarchy n, H.nodes=P.nodes I := by + apply Hierarchy.exists_structure (P.nodes I) + · exact fun A hA => P.nodes_nonempty hA + · exact P.mem_nodes.mpr (Or.inl hroot) + · intro v; exact P.mem_nodes.mpr (Or.inr ⟨v,rfl⟩) + · exact P.nodes_laminar I + +lemma parent_at_transition {I : Finset ℕ} {H : Hierarchy n} (hH : H.nodes=P.nodes I) + {i j : ℕ} (hi : i ∈ I) (hj : j ∈ I) (_hij : i < j) + (hnext : ∀k ∈ I, i < k → j ≤ k) + {A B : Finset (Fin n)} (hA : A ∈ P.parts i) (hB : B ∈ P.parts j) (hAB : A ⊂ B) : + H.parent A=B := by + have hAN : A ∈ H.nodes := hH ▸ P.mem_nodes.mpr (Or.inl ⟨i,hi,hA⟩) + have hBN : B ∈ H.nodes := hH ▸ P.mem_nodes.mpr (Or.inl ⟨j,hj,hB⟩) + have hAr : A ≠ univ := fun h => (not_ssubset_of_subset (subset_univ _)) (h ▸ hAB) + have hpB := H.parent_minimal A hAN hAr B hBN hAB + have hAp := H.parent_strict A hAN hAr + apply Subset.antisymm hpB + have hpN : H.parent A ∈ P.nodes I := hH ▸ H.parent_mem A hAN hAr + rcases P.mem_nodes.mp hpN with ⟨k,hk,hp⟩ | ⟨v,hp⟩ + · have hik : i < k := by + by_contra h + have hki : k ≤ i := by omega + have hin : (H.parent A ∩ A).Nonempty := by + obtain ⟨v,hv⟩ := P.parts_nonempty hA + exact ⟨v,mem_inter.mpr ⟨hAp.subset hv,hv⟩⟩ + have he := P.subset_of_intersect hki hp hA hin + exact (not_ssubset_of_subset he) hAp + apply P.subset_of_intersect (hnext k hk hik) hB hp + obtain ⟨v,hv⟩ := P.parts_nonempty hA + exact ⟨v,mem_inter.mpr ⟨hAB.subset hv,hAp.subset hv⟩⟩ + · have hc := card_lt_card hAp + rw [hp,card_singleton] at hc + have hn := card_pos.mpr (P.parts_nonempty hA) + omega + +end PartitionChain +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/HierarchyResponse.lean b/lean/OAI/Combinatorics/ThinTrees/HierarchyResponse.lean new file mode 100644 index 0000000000000000000000000000000000000000..6120ba2f4be0774a8dd9d39a315a69022b55650c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/HierarchyResponse.lean @@ -0,0 +1,116 @@ +import OAI.Combinatorics.ThinTrees.ResponseBounds + +namespace OAI + +universe uE + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree +lemma finite_markov {E : Type uE} [DecidableEq E] (B : Finset E) (R : E → ℝ) + (hR : ∀e ∈ B, 0 ≤ R e) {t a : ℝ} (ht : 0 < t) + (havg : (B.card:ℝ)⁻¹*(∑e ∈ B, R e) ≤ a) : + ((B.filter (fun e => t < R e)).card:ℝ) ≤ a/t*B.card := by + classical + by_cases hz : B=∅ + · simp [hz] + have hc : (0:ℝ) < B.card := Nat.cast_pos.mpr (card_pos.mpr (nonempty_iff_ne_empty.mpr hz)) + have hs : (∑e ∈ B, R e) ≤ a*B.card := by + rw [mul_comm,←div_eq_mul_inv] at havg + exact (div_le_iff₀ hc).mp havg + have hm : ((B.filter (fun e => t < R e)).card:ℝ)*t ≤ ∑e ∈ B, R e := by + calc + _ = ∑e ∈ B.filter (fun e => t < R e), t := by simp + _ ≤ ∑e ∈ B.filter (fun e => t < R e), R e := sum_le_sum (fun e he => (mem_filter.mp he).2.le) + _ ≤ _ := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun e he _ => hR e he) + have hh := (le_div_iff₀ ht).mpr (hm.trans hs) + calc + _ ≤ (a*(B.card:ℝ))/t := hh + _ = _ := by ring + +namespace MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) +lemma parentBoundary_sub (H : Hierarchy n) (A : Finset (Fin n)) : H.parentBoundary G A ⊆ G.cut univ A := by + intro e he + exact mem_filter.mpr ⟨mem_univ _,(mem_filter.mp he).2⟩ +lemma singleton_locally (v : Fin n) (q : ℝ) : G.EdgeConnectedReal {v} q := by + intro S hS hS' + have hlt := card_lt_card hS' + simp only [card_singleton] at hlt + have hp := card_pos.mpr hS + omega +lemma chain_locally (P : PartitionChain n) (I : Finset ℕ) (H : Hierarchy n) (hH : H.nodes=P.nodes I) + {q : ℝ} (hlocal : ∀i ∈ I, ∀A ∈ P.parts i, G.EdgeConnectedReal A q) : H.LocallyConnectedReal G q := by + intro A hA + rw [hH] at hA + rcases P.mem_nodes.mp hA with ⟨i,hi,hA⟩ | ⟨v,rfl⟩ + · exact hlocal i hi A hA + · exact G.singleton_locally v q + +lemma shortcut_response {H : Hierarchy n} {q : ℕ} (hq : 0 < q) (hn : 0 < n) + (hc : G.EdgeConnected 1) {a t : ℝ} (ha : 0 ≤ a) (ht : 0 < t) + (D : Matrix (Fin n) (Fin n) ℝ) (hD : D.PosDef) + (hcut : ∀S : Finset (Fin n), S.Nonempty → S ≠ univ → qform D (cutIndicator S) ≤ (G.cut univ S).card) + (havg : ∀A ∈ H.nodes, A ≠ univ → ((G.cut univ A).card:ℝ)/q ≤ (H.parentBoundary G A).card → + ShortcutDual.boundaryAverage G.incidence (H.parentBoundary G) A D ≤ a) : + ∃Y ∈ G.matrixDomain, ∀A ∈ H.nodes, + (((univ.filter (fun e => t < G.resistance Y e)) ∩ H.parentBoundary G A).card:ℝ) ≤ + (a/t+1/(q:ℝ))*(G.cut univ A).card := by + let Y := G.baseMatrix+D + have hY : Y.PosDef := (G.baseMatrix_pd hn).add hD + have hYm : Y ∈ G.matrixDomain := by + refine ⟨le_add_of_nonneg_right (Matrix.nonneg_iff_posSemidef.mpr hD.posSemidef),?_⟩ + intro S hS hS' + rw [qform_add,G.baseMatrix_cut] + have h1 : (1:ℝ) ≤ (G.cut univ S).card := by exact_mod_cast hc S hS hS' + have hcard : (S.card:ℝ) ≤ n := by exact_mod_cast (show S.card ≤ n by simpa using card_le_univ S) + have hdiv := (div_le_one (Nat.cast_pos.mpr hn)).mpr hcard + linarith [hcut S hS hS'] + have hRY (e : Fin m) : G.resistance Y e ≤ G.resistance D e := by + apply G.resistance_antitone hY hD + have hb := Matrix.nonneg_iff_posSemidef.mpr (G.baseMatrix_pd hn).posSemidef + exact le_add_of_nonneg_left hb + have hcoeff : 0 ≤ a/t := div_nonneg ha ht.le + have hqR : (0:ℝ) < q := Nat.cast_pos.mpr hq + refine ⟨Y,hYm,fun A hA => ?_⟩ + have hsub := G.parentBoundary_sub H A + have hcard : ((H.parentBoundary G A).card:ℝ) ≤ (G.cut univ A).card := by exact_mod_cast card_le_card hsub + have hbadsub : (univ.filter (fun e => t < G.resistance Y e)) ∩ H.parentBoundary G A ⊆ + (H.parentBoundary G A).filter (fun e => t < G.resistance D e) := by + intro e he + obtain ⟨hb,heA⟩ := mem_inter.mp he + exact mem_filter.mpr ⟨heA,(mem_filter.mp hb).2.trans_le (hRY e)⟩ + by_cases hroot : A=univ + · subst A + have he : G.cut univ univ=∅ := by ext e; simp [cut] + have ho : H.parentBoundary G univ=∅ := subset_empty.mp (he ▸ hsub) + simp [ho,he] + by_cases hmark : ((G.cut univ A).card:ℝ)/q ≤ (H.parentBoundary G A).card + · have hm := finite_markov (H.parentBoundary G A) (G.resistance D) (fun e _ => G.resistance_nonneg hD e) + ht (havg A hA hroot hmark) + calc + _ ≤ (((H.parentBoundary G A).filter (fun e => t < G.resistance D e)).card:ℝ) := by exact_mod_cast card_le_card hbadsub + _ ≤ a/t*(H.parentBoundary G A).card := hm + _ ≤ a/t*(G.cut univ A).card := mul_le_mul_of_nonneg_left hcard hcoeff + _ ≤ _ := by + have hnon : 0 ≤ 1/(q:ℝ)*(G.cut univ A).card := by positivity + nlinarith + · have hb : (((univ.filter (fun e => t < G.resistance Y e)) ∩ H.parentBoundary G A).card:ℝ) ≤ + (H.parentBoundary G A).card := by exact_mod_cast card_le_card (inter_subset_right) + have hm := (lt_of_not_ge hmark).le + have hnon : 0 ≤ a/t*(G.cut univ A).card := mul_nonneg hcoeff (Nat.cast_nonneg _) + calc + _ ≤ ((H.parentBoundary G A).card:ℝ) := hb + _ ≤ ((G.cut univ A).card:ℝ)/q := hm + _ ≤ _ := by nlinarith [show ((G.cut univ A).card:ℝ)/q=(1/(q:ℝ))*(G.cut univ A).card by ring] + +end MultiGraph +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/IndependentVectors.lean b/lean/OAI/Combinatorics/ThinTrees/IndependentVectors.lean new file mode 100644 index 0000000000000000000000000000000000000000..f302bd88f0b0f99fba73e265f588c25096892f85 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/IndependentVectors.lean @@ -0,0 +1,59 @@ +import OAI.Combinatorics.ThinTrees.Translation + +namespace OAI + +universe uI uD uO + +section + +noncomputable section +open Matrix Polynomial Finset +open scoped MatrixOrder +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {O : Type uO} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [Fintype O] + +lemma mixedChar_roots_bound (A : I → Matrix D D ℝ) (hA : ∀i, (A i).PosSemidef) + (hsum : ∑i, A i=1) {ε : ℝ} (hε : 0 < ε) (htr : ∀i, (A i).trace ≤ ε) : + ∀r ∈ (mixedChar A).roots, r ≤ (1+Real.sqrt ε)^2 := by + intro r hr + by_contra! hlt + have hp := skew_root_bound A hA hsum hε htr (fun _ => r-(1+Real.sqrt ε)^2) + (fun _ => sub_nonneg.mpr hlt.le) + have he : (fun _ : I => (1+Real.sqrt ε)^2)+(fun _ => r-(1+Real.sqrt ε)^2)=(fun _ => r) := by + funext i + simp only [Pi.add_apply] + ring + rw [he] at hp + have hev := (Polynomial.mem_roots (by intro h; simp [h] at hr)).mp hr + have hd : realDifferentialProduct Finset.univ.toList (pencil A)=diffProduct Finset.univ.toList (pencil A) := + (diffProduct_foldl _ _).symm + rw [hd,←mixedChar_eval_diagonal A hsum r,hev] at hp + exact lt_irrefl _ hp + +lemma matrix_le_of_roots {A : Matrix D D ℝ} (hA : A.IsHermitian) {b : ℝ} + (hr : ∀r ∈ A.charpoly.roots, r ≤ b) : A ≤ b • (1 : Matrix D D ℝ) := by + have hh : A ≤ algebraMap ℝ (Matrix D D ℝ) b := by + apply le_algebraMap_of_spectrum_le (ha := Matrix.isHermitian_iff_isSelfAdjoint.mp hA) + intro r hr' + exact hr r ((Polynomial.mem_roots (Matrix.charpoly_monic A).ne_zero).mpr + (Matrix.mem_spectrum_iff_isRoot_charpoly.mp hr')) + simpa only [Algebra.algebraMap_eq_smul_one] using hh + +theorem small_vectors (w : I → O → ℝ) (v : I → O → D → ℝ) + (hw : ∀i o, 0 < w i o) (hprob : ∀i, ∑o, w i o=1) + (hiso : ∑i, ∑o, w i o • Matrix.vecMulVec (v i o) (v i o)=1) + {ε : ℝ} (hε : 0 < ε) + (hsize : ∀i, (∑o, w i o • Matrix.vecMulVec (v i o) (v i o)).trace ≤ ε) : + ∃f : I → O, (∑i, Matrix.vecMulVec (v i (f i)) (v i (f i))) ≤ + (1+Real.sqrt ε)^2 • (1 : Matrix D D ℝ) := by + have hA : ∀i, (∑o, w i o • Matrix.vecMulVec (v i o) (v i o)).PosSemidef := + fun i => Matrix.posSemidef_sum _ (fun o _ => (rankOne_posSemidef _).smul (hw i o).le) + obtain ⟨f,hf⟩ := finite_selection w v hw hprob (mixedChar_roots_bound _ hA hiso hε hsize) + exact ⟨f,matrix_le_of_roots (Matrix.posSemidef_sum _ (fun i _ => rankOne_posSemidef _)).isHermitian hf⟩ + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Interlacing.lean b/lean/OAI/Combinatorics/ThinTrees/Interlacing.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc80a37d68393515120b2b8fa5a138d0671d9b1a --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Interlacing.lean @@ -0,0 +1,265 @@ +import OAI.Combinatorics.ThinTrees.OptionalDirections + +namespace OAI + +universe uα uι uι2 uι3 + +section + +noncomputable section +open Polynomial Finset Set +open scoped Topology +namespace StrongThinTree.MSS.Selection + +lemma coeff_prod_negative (s : Multiset ℝ) (hs : ∀r ∈ s, r < 0) : + (∀k, 0 ≤ ((s.map (fun r => (X-C r : ℝ[X]))).prod).coeff k) ∧ + ∀k ≤ s.card, 0 < ((s.map (fun r => (X-C r : ℝ[X]))).prod).coeff k := by + induction s using Multiset.induction_on with + | empty => + simp only [Multiset.map_zero,Multiset.prod_zero,Multiset.card_zero] + constructor + · intro k; simp only [coeff_one]; split_ifs <;> norm_num + · intro k hk + have : k=0 := by omega + subst k + simp + | @cons r s ih => + have hr : r < 0 := hs r (Multiset.mem_cons_self _ _) + obtain ⟨hn,hp⟩ := ih (fun a ha => hs a (Multiset.mem_cons_of_mem ha)) + simp only [Multiset.map_cons,Multiset.prod_cons,Multiset.card_cons] + constructor + · intro k + cases k with + | zero => simpa only [sub_mul,coeff_sub,coeff_X_mul_zero,coeff_C_mul,zero_sub,neg_mul] using mul_nonneg (neg_nonneg.mpr hr.le) (hn 0) + | succ k => + simp only [sub_mul,coeff_sub,coeff_X_mul,coeff_C_mul] + exact sub_nonneg.mpr (le_trans (mul_nonpos_of_nonpos_of_nonneg hr.le (hn _)) (hn _)) + · intro k hk + cases k with + | zero => simpa only [sub_mul,coeff_sub,coeff_X_mul_zero,coeff_C_mul,zero_sub,neg_mul] using mul_pos (neg_pos.mpr hr) (hp 0 (Nat.zero_le _)) + | succ k => + simp only [sub_mul,coeff_sub,coeff_X_mul,coeff_C_mul] + exact sub_pos.mpr (lt_of_le_of_lt (mul_nonpos_of_nonpos_of_nonneg hr.le (hn _)) (hp k (by omega))) + +lemma coeff_pos_of_negative_roots {p : ℝ[X]} (hm : p.Monic) (hs : p.Splits) + (hr : ∀r ∈ p.roots, r < 0) : ∀k ≤ p.natDegree, 0 < p.coeff k := by + have hh := (coeff_prod_negative p.roots hr).2 + rw [←hs.eq_prod_roots_of_monic hm] at hh + simpa only [←hs.natDegree_eq_card_roots] using hh + +lemma eval_pos_of_nonneg_coeff {p : ℝ[X]} (hp : ∀k, 0 ≤ p.coeff k) (h0 : 0 < p.coeff 0) + {x : ℝ} (hx : 0 ≤ x) : 0 < p.eval x := by + rw [Polynomial.eval_eq_sum] + apply lt_of_lt_of_le h0 + have hm : 0 ∈ p.support := Polynomial.mem_support_iff.mpr h0.ne' + simpa only [Polynomial.sum,pow_zero,mul_one] using Finset.single_le_sum + (fun k _ => mul_nonneg (hp k) (pow_nonneg hx k)) hm + +lemma coeff_pos_of_nonneg {p : ℝ[X]} (hm : p.Monic) (hs : p.Splits) + (hp : ∀k, 0 ≤ p.coeff k) (h0 : 0 < p.coeff 0) : + ∀k ≤ p.natDegree, 0 < p.coeff k := by + apply coeff_pos_of_negative_roots hm hs + intro r hr + by_contra hh + exact (eval_pos_of_nonneg_coeff hp h0 (le_of_not_gt hh)).ne' + ((Polynomial.mem_roots hm.ne_zero).mp hr) + +lemma positive_coeff_path {α : Type uα} [TopologicalSpace α] [PreconnectedSpace α] + (p : α → ℝ[X]) (d : ℕ) (hc : ∀k, Continuous (fun t => (p t).coeff k)) + (hm : ∀t, (p t).Monic) (hs : ∀t, (p t).Splits) (hd : ∀t, (p t).natDegree=d) + (h0 : ∀t, 0 < (p t).coeff 0) {a : α} (ha : ∀k ≤ d, 0 < (p a).coeff k) : + ∀t k, k ≤ d → 0 < (p t).coeff k := by + let C : Set α := {t | ∀k ≤ d, 0 ≤ (p t).coeff k} + let G : Set α := {t | ∀k ≤ d, 0 < (p t).coeff k} + have he : C=G := by + ext t + constructor + · intro ht k hk + have hp : ∀k, 0 ≤ (p t).coeff k := by + intro k + by_cases hk' : k ≤ d + · exact ht k hk' + · rw [Polynomial.coeff_eq_zero_of_natDegree_lt (by rw [hd]; omega)] + exact coeff_pos_of_nonneg (hm t) (hs t) hp (h0 t) k (by rwa [hd]) + · exact fun ht k hk => (ht k hk).le + have hC : IsClosed C := by + have hh : C=⋂k : Fin (d+1), {t | 0 ≤ (p t).coeff k} := by + ext t + simp only [C,Set.mem_ofPred_eq,Set.mem_iInter] + exact ⟨fun h k => h k (by omega),fun h k hk => h ⟨k,by omega⟩⟩ + rw [hh] + exact isClosed_iInter (fun k => isClosed_le continuous_const (hc k)) + have hG : IsOpen G := by + have hh : G=⋂k : Fin (d+1), {t | 0 < (p t).coeff k} := by + ext t + simp only [G,Set.mem_ofPred_eq,Set.mem_iInter] + exact ⟨fun h k => h k (by omega),fun h k hk => h ⟨k,by omega⟩⟩ + rw [hh] + exact isOpen_iInter_of_finite (fun k => isOpen_lt continuous_const (hc k)) + have heq : G=Set.univ := (IsClopen.eq_univ ⟨he ▸ hC,hG⟩ ⟨a,ha⟩) + intro t + have ht : t ∈ G := heq.symm ▸ Set.mem_univ t + exact ht + +lemma monic_segment {p q : ℝ[X]} {d : ℕ} + (hp : p.IsMonicOfDegree d) (hq : q.IsMonicOfDegree d) (t : ℝ) : + ((1-t) • p + t • q).IsMonicOfDegree d := by + rw [isMonicOfDegree_iff] + constructor + · exact natDegree_add_le_of_degree_le + ((natDegree_smul_le _ _).trans hp.natDegree_eq.le) + ((natDegree_smul_le _ _).trans hq.natDegree_eq.le) + · rw [coeff_add, coeff_smul, coeff_smul] + have hp' : p.coeff d=1 := hp.natDegree_eq ▸ hp.monic.coeff_natDegree + have hq' : q.coeff d=1 := hq.natDegree_eq ▸ hq.monic.coeff_natDegree + simp only [hp',hq',smul_eq_mul,mul_one] + ring + +lemma negative_roots_segment {p q : ℝ[X]} {d : ℕ} + (hp : p.IsMonicOfDegree d) (hq : q.IsMonicOfDegree d) + (hs : ∀t ∈ Set.Icc (0 : ℝ) 1, ((1-t) • p + t • q).Splits) + (hr : ∀r ∈ p.roots, r < 0) (h0p : 0 < p.coeff 0) (h0q : 0 < q.coeff 0) : + ∀r ∈ q.roots, r < 0 := by + let : PreconnectedSpace (Set.Icc (0 : ℝ) 1) := Subtype.preconnectedSpace isPreconnected_Icc + let f : Set.Icc (0 : ℝ) 1 → ℝ[X] := fun t => (1-t.val) • p + t.val • q + have hh := positive_coeff_path f d + (fun k => by + simp only [f,coeff_add,coeff_smul,smul_eq_mul] + fun_prop) + (fun t => (monic_segment hp hq t).monic) + (fun t => hs t t.property) + (fun t => (monic_segment hp hq t).natDegree_eq) + (fun t => by + simp only [f,coeff_add,coeff_smul,smul_eq_mul] + have ht := t.property + have hh : 0 < (1-t.val)*p.coeff 0+t.val*q.coeff 0 := by + by_cases ht0 : t.val=0 + · simp [ht0,h0p] + · exact add_pos_of_nonneg_of_pos (mul_nonneg (sub_nonneg.mpr ht.2) h0p.le) + (mul_pos (lt_of_le_of_ne ht.1 (Ne.symm ht0)) h0q) + exact hh) + (a := ⟨0,by simp⟩) + (by + simpa only [f,sub_zero,one_smul,zero_smul,add_zero,hp.natDegree_eq] using + coeff_pos_of_negative_roots hp.monic (by simpa using hs 0 (by simp)) hr) + have hqpos : ∀k ≤ d, 0 < q.coeff k := by + simpa only [f,sub_self,zero_smul,one_smul,zero_add] using hh ⟨1,by simp⟩ + intro r hrq + by_contra hnr + have hn : ∀k, 0 ≤ q.coeff k := by + intro k + by_cases hk : k ≤ d + · exact (hqpos k hk).le + · rw [coeff_eq_zero_of_natDegree_lt (by rw [hq.natDegree_eq]; omega)] + exact (eval_pos_of_nonneg_coeff hn h0q (le_of_not_gt hnr)).ne' + ((mem_roots hq.ne_zero).mp hrq) + +lemma roots_shift_iff {p : ℝ[X]} (hp : p ≠ 0) (x r : ℝ) : + r ∈ (p.comp (X+C x)).roots ↔ r+x ∈ p.roots := by + rw [mem_roots (comp_X_add_C_ne_zero_iff.mpr hp),mem_roots hp] + simp [IsRoot,eval_comp] + +lemma roots_lt_segment {p q : ℝ[X]} {d : ℕ} + (hp : p.IsMonicOfDegree d) (hq : q.IsMonicOfDegree d) + (hs : ∀t ∈ Set.Icc (0 : ℝ) 1, ((1-t) • p + t • q).Splits) + {x : ℝ} (hr : ∀r ∈ p.roots, r < x) (hxq : 0 < q.eval x) : + ∀r ∈ q.roots, r < x := by + have hp' : (p.comp (X+C x)).IsMonicOfDegree d := by + simpa using hp.comp one_ne_zero (isMonicOfDegree_X_add_one x) + have hq' : (q.comp (X+C x)).IsMonicOfDegree d := by + simpa using hq.comp one_ne_zero (isMonicOfDegree_X_add_one x) + have hrp : ∀r ∈ (p.comp (X+C x)).roots, r < 0 := by + intro r h + have hh := hr (r+x) ((roots_shift_iff hp.ne_zero x r).mp h) + linarith + have hps : p.Splits := by simpa using hs 0 (by simp) + have hp0 := coeff_pos_of_negative_roots hp'.monic (hps.comp_X_add_C x) hrp 0 (Nat.zero_le _) + have hq0 : 0 < (q.comp (X+C x)).coeff 0 := by + rw [coeff_zero_eq_eval_zero,eval_comp] + simpa using hxq + have hsr : ∀t ∈ Set.Icc (0 : ℝ) 1, + ((1-t) • p.comp (X+C x) + t • q.comp (X+C x)).Splits := by + intro t ht + simpa only [add_comp,smul_comp] using (hs t ht).comp_X_add_C x + have hh := negative_roots_segment hp' hq' hsr hrp hp0 hq0 + intro r h + have hm : r-x ∈ (q.comp (X+C x)).roots := by + rw [roots_shift_iff hq.ne_zero] + simpa using h + have hh' := hh _ hm + linarith + +lemma eval_pos_above_roots {p : ℝ[X]} (hp : p.Monic) (hs : p.Splits) + {x : ℝ} (hr : ∀r ∈ p.roots, r < x) : 0 < p.eval x := by + have hshift : ∀r ∈ (p.comp (X+C x)).roots, r < 0 := by + intro r h + have hh := hr (r+x) ((roots_shift_iff hp.ne_zero x r).mp h) + linarith + have hh := coeff_pos_of_negative_roots (hp.comp_X_add_C x) (hs.comp_X_add_C x) + hshift 0 (Nat.zero_le _) + simpa only [coeff_zero_eq_eval_zero,eval_comp,eval_add,eval_X,eval_C,zero_add] using hh + +lemma monic_mean {ι : Type uι} [Fintype ι] (p : ι → ℝ[X]) {d : ℕ} + (hp : ∀i, (p i).IsMonicOfDegree d) (w : ι → ℝ) (hw : ∑i, w i=1) : + (∑i, w i • p i).IsMonicOfDegree d := by + rw [isMonicOfDegree_iff] + constructor + · exact natDegree_sum_le_of_forall_le _ _ (fun i _ => + (natDegree_smul_le _ _).trans (hp i).natDegree_eq.le) + · simp only [finsetSum_coeff,coeff_smul,smul_eq_mul] + have hh : ∀i, (p i).coeff d=1 := fun i => (hp i).natDegree_eq ▸ (hp i).monic.coeff_natDegree + simpa only [hh,mul_one] using hw + +lemma selection_strict {ι : Type uι2} [Fintype ι] (p : ι → ℝ[X]) {d : ℕ} + (hp : ∀i, (p i).IsMonicOfDegree d) (w : ι → ℝ) (hw : ∀i, 0 < w i) + (hsum : ∑i, w i=1) + (hs : ∀i t, t ∈ Set.Icc (0 : ℝ) 1 → + ((1-t) • (∑j, w j • p j) + t • p i).Splits) + {x : ℝ} (hroot : ∀r ∈ (∑i, w i • p i).roots, r < x) : + ∃i, ∀r ∈ (p i).roots, r < x := by + have hne : Nonempty ι := by + by_contra hn + have : IsEmpty ι := not_nonempty_iff.mp hn + simp at hsum + let := hne + have hm := monic_mean p hp w hsum + have hsplit : (∑i, w i • p i).Splits := by + simpa using hs (Classical.arbitrary ι) 0 (by simp) + have he := eval_pos_above_roots hm.monic hsplit hroot + have hei : ∃i, 0 < (p i).eval x := by + by_contra! hh + have hn : ∑i, w i*(p i).eval x ≤ 0 := + Finset.sum_nonpos (fun i _ => mul_nonpos_of_nonneg_of_nonpos (hw i).le (hh i)) + simp only [eval_finsetSum,eval_smul,smul_eq_mul] at he + linarith + obtain ⟨i,hi⟩ := hei + exact ⟨i,roots_lt_segment hm (hp i) (hs i) hroot hi⟩ + +lemma selection {ι : Type uι3} [Fintype ι] (p : ι → ℝ[X]) {d : ℕ} + (hp : ∀i, (p i).IsMonicOfDegree d) (w : ι → ℝ) (hw : ∀i, 0 < w i) + (hsum : ∑i, w i=1) + (hs : ∀i t, t ∈ Set.Icc (0 : ℝ) 1 → + ((1-t) • (∑j, w j • p j) + t • p i).Splits) + {b : ℝ} (hroot : ∀r ∈ (∑i, w i • p i).roots, r ≤ b) : + ∃i, ∀r ∈ (p i).roots, r ≤ b := by + classical + by_contra! hn + choose r hr hbr using hn + have hne : Nonempty ι := by + by_contra hn + have : IsEmpty ι := not_nonempty_iff.mp hn + simp at hsum + let := hne + have hmin : b < Finset.univ.inf' Finset.univ_nonempty r := + (Finset.lt_inf'_iff _).mpr (fun i _ => hbr i) + obtain ⟨x,hbx,hxmin⟩ := exists_between hmin + obtain ⟨i,hi⟩ := selection_strict p hp w hw hsum hs (fun a ha => (hroot a ha).trans_lt hbx) + have hxi : x < r i := hxmin.trans_le (Finset.inf'_le _ (Finset.mem_univ i)) + exact (hi (r i) (hr i)).not_gt hxi + +end StrongThinTree.MSS.Selection + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Iteration.lean b/lean/OAI/Combinatorics/ThinTrees/Iteration.lean new file mode 100644 index 0000000000000000000000000000000000000000..4974b59ee12f96db3d55db03d4e23d193a0d8089 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Iteration.lean @@ -0,0 +1,89 @@ +import OAI.Combinatorics.ThinTrees.IterationBounds + +namespace OAI + +section + +noncomputable section +open Finset +namespace StrongThinTree.MultiGraph + +lemma cut_card_le_full {n m : ℕ} (G : MultiGraph n m) (T : Finset (Fin m)) + (S : Finset (Fin n)) : (G.cut T S).card ≤ (G.cut univ S).card := by + exact card_le_card (filter_subset_filter _ (subset_univ T)) + +theorem packing_thinness : ∃C : ℝ, 0 < C ∧ ∀r : ℕ, 1 ≤ r → + ∀(n m : ℕ) (G : MultiGraph n m), 2 ≤ n → G.TreePackable univ r → + ∃T : Finset (Fin m), G.SpanningTree T ∧ + ∀S : Finset (Fin n), S.Nonempty → S ≠ univ → + ((G.cut T S).card:ℝ) ≤ C/(r:ℝ)*(G.cut univ S).card := by + obtain ⟨R,hR,hstep⟩ := sparsification + have hRR : (0:ℝ) < R := by exact_mod_cast (show 0 < R by omega) + have hI : ∀r : ℕ, 1 ≤ r → ∀(n m : ℕ) (G : MultiGraph n m), + 2 ≤ n → G.TreePackable univ r → + ∃T : Finset (Fin m), G.SpanningTree T ∧ + ∀S : Finset (Fin n), S.Nonempty → S ≠ univ → + ((G.cut T S).card:ℝ) ≤ + R*(iterationPotential r/(r:ℝ))*(G.cut univ S).card := by + intro r + induction r using Nat.strong_induction_on with + | h r ih => + intro hr n m G hn hp + have hrR : (0:ℝ) < r := by exact_mod_cast (show 0 < r by omega) + by_cases hlarge : R ≤ r + · obtain ⟨hnum,hstep'⟩ := hstep r hlarge + obtain ⟨A,hA,hcuts⟩ := hstep' n m G hn hp + have hsR : (0:ℝ) < stepCount r := + lt_of_lt_of_le (by positivity) hnum.lower + have hs : 1 ≤ stepCount r := by exact_mod_cast hsR + have hlt : stepCount r < r := by + have hh : (stepCount r:ℝ) < r := by linarith [hnum.upper] + exact_mod_cast hh + obtain ⟨T,hT,hthin⟩ := ih (stepCount r) hlt hs n A.card (G.restrict A) hn + (G.restrict_packable A hA) + refine ⟨liftEdges A T,(G.restrict_spanningTree A T).mp hT,?_⟩ + intro S hS hS' + have ht := hthin S hS hS' + rw [G.restrict_cut_card,G.restrict_cut_card,lift_univ] at ht + have hcoef : 0 ≤ R*(iterationPotential (stepCount r)/(stepCount r:ℝ)) := + mul_nonneg hRR.le (div_nonneg (iterationPotential_pos _).le hsR.le) + calc + _ ≤ R*(iterationPotential (stepCount r)/(stepCount r:ℝ))*(G.cut A S).card := ht + _ ≤ R*(iterationPotential (stepCount r)/(stepCount r:ℝ))* + ((1/2+3*splitTau r)*(G.cut univ S).card) := + mul_le_mul_of_nonneg_left (hcuts S hS hS') hcoef + _ = R*(iterationPotential (stepCount r)/(stepCount r:ℝ)*(1/2+3*splitTau r))* + (G.cut univ S).card := by ring + _ ≤ R*(iterationPotential r/(r:ℝ))*(G.cut univ S).card := + mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (iteration_coefficient_step hnum) hRR.le) + (Nat.cast_nonneg _) + · obtain ⟨F,hF,_⟩ := hp + let i : Fin r := ⟨0,by omega⟩ + refine ⟨F i,(hF i).2,?_⟩ + intro S _ _ + have hrleR : (r:ℝ) ≤ R := by exact_mod_cast (show r ≤ R by omega) + have hcoef : 1 ≤ R*(iterationPotential r/(r:ℝ)) := by + rw [←mul_div_assoc] + apply (le_div_iff₀ hrR).mpr + have hh := mul_le_mul_of_nonneg_left (iterationPotential_one_le hr) hRR.le + nlinarith + have hc : ((G.cut (F i) S).card:ℝ) ≤ (G.cut univ S).card := by + exact_mod_cast G.cut_card_le_full (F i) S + exact hc.trans (le_mul_of_one_le_left (Nat.cast_nonneg _) hcoef) + refine ⟨R*Real.exp iterationB,mul_pos hRR (Real.exp_pos _),?_⟩ + intro r hr n m G hn hp + obtain ⟨T,hT,hthin⟩ := hI r hr n m G hn hp + refine ⟨T,hT,fun S hS hS' => (hthin S hS hS').trans ?_⟩ + have hrR : (0:ℝ) < r := by exact_mod_cast (show 0 < r by omega) + apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) + rw [←mul_div_assoc] + exact div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (iterationPotential_le r) hRR.le) hrR.le + +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/IterationBounds.lean b/lean/OAI/Combinatorics/ThinTrees/IterationBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..4a3e017261ef6d0b7cecb21d4c09589cd87e03f2 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/IterationBounds.lean @@ -0,0 +1,76 @@ +import OAI.Combinatorics.ThinTrees.Restriction + +namespace OAI + +section + +noncomputable section +namespace StrongThinTree + +def iterationB : ℝ := 15 / ((2:ℝ)^(1/16:ℝ)-1) +def iterationPotential (r : ℕ) : ℝ := Real.exp (iterationB*(1-errorU r)) + +lemma iterationB_pos : 0 < iterationB := by + unfold iterationB + exact div_pos (by norm_num) (sub_pos.mpr (Real.one_lt_rpow (by norm_num) (by norm_num))) +lemma errorU_nonneg (r : ℕ) : 0 ≤ errorU r := Real.rpow_nonneg (Nat.cast_nonneg _) _ +lemma errorU_le_one {r : ℕ} (hr : 1 ≤ r) : errorU r ≤ 1 := by + exact Real.rpow_le_one_of_one_le_of_nonpos (by exact_mod_cast hr) (by norm_num) +lemma iterationPotential_pos (r : ℕ) : 0 < iterationPotential r := Real.exp_pos _ +lemma iterationPotential_one_le {r : ℕ} (hr : 1 ≤ r) : 1 ≤ iterationPotential r := by + exact Real.one_le_exp (mul_nonneg iterationB_pos.le (sub_nonneg.mpr (errorU_le_one hr))) +lemma iterationPotential_le (r : ℕ) : iterationPotential r ≤ Real.exp iterationB := by + apply Real.exp_le_exp.mpr + have := mul_nonneg iterationB_pos.le (errorU_nonneg r) + nlinarith + +lemma errorU_halving {r s : ℕ} (hs : 0 < s) (hrs : (s:ℝ) ≤ (r:ℝ)/2) : + (2:ℝ)^(1/16:ℝ)*errorU r ≤ errorU s := by + have hsR : (0:ℝ) < s := Nat.cast_pos.mpr hs + have hrR : (0:ℝ) < r := by linarith + have hh := Real.rpow_le_rpow_of_nonpos hsR hrs (by norm_num : (-1/16:ℝ) ≤ 0) + rw [Real.div_rpow hrR.le (by norm_num)] at hh + have hi : (2:ℝ)^(-1/16:ℝ)=((2:ℝ)^(1/16:ℝ))⁻¹ := by + rw [show (-1/16:ℝ)=-(1/16:ℝ) by ring,Real.rpow_neg (by norm_num)] + simpa only [hi,div_inv_eq_mul,mul_comm,errorU] using hh + +lemma iterationPotential_step {r s : ℕ} (hs : 0 < s) (hrs : (s:ℝ) ≤ (r:ℝ)/2) : + (1+15*errorU r)*iterationPotential s ≤ iterationPotential r := by + have hd : 0 < (2:ℝ)^(1/16:ℝ)-1 := + sub_pos.mpr (Real.one_lt_rpow (by norm_num) (by norm_num)) + have hm := mul_le_mul_of_nonneg_left (errorU_halving hs hrs) iterationB_pos.le + have hB : iterationB*((2:ℝ)^(1/16:ℝ)-1)=15 := by + unfold iterationB + exact div_mul_cancel₀ _ (ne_of_gt hd) + have hdiff : 15*errorU r ≤ iterationB*(errorU s-errorU r) := by + have hBu := congrArg (fun x : ℝ => x*errorU r) hB + nlinarith + have he : 1+15*errorU r ≤ Real.exp (15*errorU r) := by + simpa only [add_comm] using Real.add_one_le_exp (15*errorU r) + calc + _ ≤ Real.exp (15*errorU r)*iterationPotential s := + mul_le_mul_of_nonneg_right he (iterationPotential_pos s).le + _ = Real.exp (15*errorU r+iterationB*(1-errorU s)) := by + rw [iterationPotential,Real.exp_add] + _ ≤ iterationPotential r := by + apply Real.exp_le_exp.mpr + linarith + +lemma iteration_coefficient_step {r : ℕ} (h : StepNumeric r) : + iterationPotential (stepCount r)/(stepCount r:ℝ)*(1/2+3*splitTau r) ≤ + iterationPotential r/(r:ℝ) := by + have hrR : (0:ℝ) < r := by exact_mod_cast (show 0 < r by have := h.rlarge; omega) + have hsR : (0:ℝ) < stepCount r := lt_of_lt_of_le (by positivity) h.lower + have hs : 0 < stepCount r := Nat.cast_pos.mp hsR + rw [div_mul_eq_mul_div] + apply (div_le_div_iff₀ hsR hrR).mpr + have hp := iterationPotential_step hs h.upper + have hm := mul_le_mul_of_nonneg_left h.ratio (iterationPotential_pos (stepCount r)).le + have hp' := mul_le_mul_of_nonneg_right hp hsR.le + nlinarith +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Main.lean b/lean/OAI/Combinatorics/ThinTrees/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..88f3f50750f5f0e20402df9b52dbe4cf44439faa --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Main.lean @@ -0,0 +1,70 @@ +import OAI.Combinatorics.ThinTrees.Iteration + +namespace OAI + +section + +noncomputable section +open Finset +namespace StrongThinTree.MultiGraph + +lemma connected_has_spanningTree {n m : ℕ} (G : MultiGraph n m) + (hG : G.Connected univ) : ∃T : Finset (Fin m), G.SpanningTree T := by + classical + let A : Finset (Finset (Fin m)) := univ.filter G.Connected + have hA : A.Nonempty := ⟨univ,by simp only [A,mem_filter,mem_univ,true_and]; exact hG⟩ + obtain ⟨T,hT,hmin⟩ := exists_min_image A Finset.card hA + refine ⟨T,(mem_filter.mp hT).2,?_⟩ + intro e he hc + have hh := hmin (T.erase e) (by simp only [A,mem_filter,mem_univ,true_and]; exact hc) + exact (not_le_of_gt (card_erase_lt_of_mem he)) hh + +end MultiGraph + +theorem strongThinTree : MainStatement := by + obtain ⟨C₀,hC₀,hpacking⟩ := MultiGraph.packing_thinness + let C : ℝ := 3*max C₀ 1 + have hm : 1 ≤ max C₀ 1 := le_max_right _ _ + have hC : 0 < C := by dsimp [C]; linarith + refine ⟨C,hC,?_⟩ + intro k hk n m hn G hc + by_cases hk2 : 2 ≤ k + · let r := k/2 + have hr : 0 < r := Nat.div_pos hk2 (by norm_num) + have hr' : 1 ≤ r := hr + have hconn : G.EdgeConnected (2*r) := by + intro S hS hS' + exact (show 2*r ≤ k by dsimp [r]; omega).trans (hc S hS hS') + have hpack := G.edgeConnected_treePackable hr (by omega) hconn + obtain ⟨T,hT,hthin⟩ := hpacking r hr' n m G hn hpack + refine ⟨T,hT,fun S hS hS' => (hthin S hS hS').trans ?_⟩ + apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hr + have hkR : (0:ℝ) < k := by exact_mod_cast (show 0 < k by omega) + apply (div_le_div_iff₀ hrR hkR).mpr + have hkr : (k:ℝ) ≤ 3*(r:ℝ) := by exact_mod_cast (show k ≤ 3*r by dsimp [r]; omega) + have h1 := mul_le_mul_of_nonneg_left hkr hC₀.le + have h2 := mul_le_mul_of_nonneg_right (le_max_left C₀ 1) hrR.le + dsimp [C] + nlinarith + · have hk1 : k=1 := by omega + subst k + have hconn : G.Connected univ := by + intro S hS hS' + exact card_pos.mp (hc S hS hS') + obtain ⟨T,hT⟩ := G.connected_has_spanningTree hconn + refine ⟨T,hT,?_⟩ + intro S _ _ + have hh : ((G.cut T S).card:ℝ) ≤ (G.cut univ S).card := by + exact_mod_cast G.cut_card_le_full T S + have hCle : 1 ≤ C := by dsimp [C]; linarith + simpa only [Nat.cast_one,div_one] using + hh.trans (le_mul_of_one_le_left (Nat.cast_nonneg _) hCle) + +end StrongThinTree + +end + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Matrix.lean b/lean/OAI/Combinatorics/ThinTrees/Matrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..5701d6f992cc36d775232bbe23af2557b50db5a6 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Matrix.lean @@ -0,0 +1,94 @@ +import OAI.Combinatorics.ThinTrees.ShortcutDuality + +namespace OAI + +universe uι + +section +open Matrix +namespace StrongThinTree +section Resistance +variable {ι : Type uι} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma quadratic_cauchy_schwarz {X : Matrix ι ι ℝ} (hX : X.PosSemidef) + (x y : ι → ℝ) : + (x ⬝ᵥ (X *ᵥ y)) ^ 2 ≤ (x ⬝ᵥ (X *ᵥ x)) * (y ⬝ᵥ (X *ᵥ y)) := by + let := X.toSeminormedAddCommGroup hX + let := X.toInnerProductSpace hX + have h := real_inner_mul_inner_self_le x y + change ((X *ᵥ y) ⬝ᵥ star x) * ((X *ᵥ y) ⬝ᵥ star x) ≤ + ((X *ᵥ x) ⬝ᵥ star x) * ((X *ᵥ y) ⬝ᵥ star y) at h + simpa only [star_trivial, dotProduct_comm, pow_two] using h + +omit [DecidableEq ι] in +lemma rankOne_quadratic (b x : ι → ℝ) : + x ⬝ᵥ (vecMulVec b b *ᵥ x) = (b ⬝ᵥ x) ^ 2 := by + rw [vecMulVec_mulVec] + simp [dotProduct, Finset.mul_sum, pow_two, mul_comm, mul_left_comm] + +lemma posDef_solve {X : Matrix ι ι ℝ} (hX : X.PosDef) (b : ι → ℝ) : + X *ᵥ (X⁻¹ *ᵥ b) = b := by + rw [mulVec_mulVec, mul_nonsing_inv X ((isUnit_iff_isUnit_det X).mp hX.isUnit), + one_mulVec] + +theorem resistance_order {X : Matrix ι ι ℝ} (hX : X.PosDef) + (b : ι → ℝ) {t : ℝ} (ht : 0 < t) : + b ⬝ᵥ (X⁻¹ *ᵥ b) ≤ t ↔ (t • X - vecMulVec b b).PosSemidef := by + let y := X⁻¹ *ᵥ b + have hsolve : X *ᵥ y = b := posDef_solve hX b + have hq (x : ι → ℝ) : 0 ≤ x ⬝ᵥ (X *ᵥ x) := by + simpa only [star_trivial] using hX.posSemidef.dotProduct_mulVec_nonneg x + have hr : 0 ≤ b ⬝ᵥ y := by + simpa only [hsolve, dotProduct_comm] using hq y + constructor + · intro h + have hb : (vecMulVec b b).IsHermitian := by + simpa only [star_trivial] using (posSemidef_vecMulVec_self_star b).isHermitian + refine PosSemidef.of_dotProduct_mulVec_nonneg + ((hX.isHermitian.smul (isSelfAdjoint_iff.mpr (star_trivial t))).sub hb) ?_ + intro x + have hcs := quadratic_cauchy_schwarz hX.posSemidef x y + rw [hsolve] at hcs + have hm : (x ⬝ᵥ (X *ᵥ x)) * (b ⬝ᵥ y) ≤ (x ⬝ᵥ (X *ᵥ x)) * t := + mul_le_mul_of_nonneg_left h (hq x) + rw [dotProduct_comm y b, dotProduct_comm x b] at hcs + simp only [star_trivial, sub_mulVec, dotProduct_sub, smul_mulVec, dotProduct_smul, + smul_eq_mul, rankOne_quadratic] + nlinarith + · intro h + have htest := h.dotProduct_mulVec_nonneg y + simp only [star_trivial, sub_mulVec, dotProduct_sub, smul_mulVec, dotProduct_smul, + smul_eq_mul, rankOne_quadratic, hsolve, dotProduct_comm y b] at htest + change b ⬝ᵥ y ≤ t + nlinarith + +theorem resistance_antitone {X Y : Matrix ι ι ℝ} + (hX : X.PosDef) (hY : Y.PosDef) (hXY : (X - Y).PosSemidef) (b : ι → ℝ) : + b ⬝ᵥ (X⁻¹ *ᵥ b) ≤ b ⬝ᵥ (Y⁻¹ *ᵥ b) := by + let x := X⁻¹ *ᵥ b + let y := Y⁻¹ *ᵥ b + have hx : X *ᵥ x = b := posDef_solve hX b + have hy : Y *ᵥ y = b := posDef_solve hY b + have hrX : 0 ≤ b ⬝ᵥ x := by + simpa only [star_trivial, hx, dotProduct_comm] using + hX.posSemidef.dotProduct_mulVec_nonneg x + have hrY : 0 ≤ b ⬝ᵥ y := by + simpa only [star_trivial, hy, dotProduct_comm] using + hY.posSemidef.dotProduct_mulVec_nonneg y + have hcomp : x ⬝ᵥ (Y *ᵥ x) ≤ b ⬝ᵥ x := by + have h := hXY.dotProduct_mulVec_nonneg x + simp only [star_trivial, sub_mulVec, dotProduct_sub, hx, dotProduct_comm x b] at h + linarith + have hcs := quadratic_cauchy_schwarz hY.posSemidef x y + rw [hy, dotProduct_comm x b, dotProduct_comm y b] at hcs + have hm := mul_le_mul_of_nonneg_right hcomp hrY + change b ⬝ᵥ x ≤ b ⬝ᵥ y + nlinarith + +end Resistance +end StrongThinTree + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/MatrixDomain.lean b/lean/OAI/Combinatorics/ThinTrees/MatrixDomain.lean new file mode 100644 index 0000000000000000000000000000000000000000..19b21d40697f7d3917e88f0869aaf9283fcfb7e5 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/MatrixDomain.lean @@ -0,0 +1,109 @@ +import OAI.Combinatorics.ThinTrees.GraphMatrix + +namespace OAI + +universe uV + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder Matrix.Norms.Elementwise +namespace StrongThinTree +variable {V : Type uV} [Fintype V] [DecidableEq V] +omit [DecidableEq V] in +lemma isClosed_psd : IsClosed {X : Matrix V V ℝ | X.PosSemidef} := by + have heq : {X : Matrix V V ℝ | X.PosSemidef}= + {X | X.IsHermitian} ∩ ⋂v : V → ℝ, {X | 0 ≤ qform X v} := by + ext X + simp only [Set.mem_ofPred,Set.mem_inter_iff,Set.mem_iInter] + exact ⟨fun h => ⟨h.isHermitian,qform_nonneg h⟩,fun h => + Matrix.PosSemidef.of_dotProduct_mulVec_nonneg h.1 (by simpa only [star_trivial,qform] using h.2)⟩ + rw [heq] + apply IsClosed.inter + · exact isClosed_eq continuous_id.matrix_conjTranspose continuous_id + · exact isClosed_iInter (fun v => isClosed_le continuous_const (qform_continuous v)) +omit [DecidableEq V] in +lemma isClosed_matrixAbove (A : Matrix V V ℝ) : IsClosed {X : Matrix V V ℝ | A ≤ X} := + isClosed_psd.preimage (continuous_id.sub continuous_const) +lemma psd_entry_bound {X : Matrix V V ℝ} (hX : X.PosSemidef) {C : ℝ} (hC : 0 ≤ C) + (hdiag : ∀i, X i i ≤ C) (i j : V) : |X i j| ≤ C := by + have hi : 0 ≤ X i i := by simpa only [qform_single] using qform_nonneg hX (Pi.single i 1) + have hj : 0 ≤ X j j := by simpa only [qform_single] using qform_nonneg hX (Pi.single j 1) + have hh := quadratic_cauchy_schwarz hX (Pi.single i 1) (Pi.single j 1) + simp only [mulVec_single_one,single_one_dotProduct] at hh + change (X i j)^2 ≤ X i i*X j j at hh + have hm := mul_le_mul (hdiag i) (hdiag j) hj hC + nlinarith [sq_abs (X i j),abs_nonneg (X i j)] + +namespace MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) + +def matrixDomain : Set (Matrix (Fin n) (Fin n) ℝ) := + {X | G.baseMatrix ≤ X ∧ ∀S : Finset (Fin n), S.Nonempty → S ≠ univ → + qform X (cutIndicator S) ≤ 3*(G.cut univ S).card} +lemma domain_pd (hn : 0 < n) {X : Matrix (Fin n) (Fin n) ℝ} (hX : X ∈ G.matrixDomain) : X.PosDef := + posDef_of_le (G.baseMatrix_pd hn) hX.1 +lemma domain_closed : IsClosed G.matrixDomain := by + simp only [matrixDomain,Set.ofPred_and,Set.ofPred_forall] + exact (isClosed_matrixAbove _).inter (isClosed_iInter fun S => isClosed_iInter fun _ => + isClosed_iInter fun _ => isClosed_le (qform_continuous _) continuous_const) +lemma domain_convex : Convex ℝ G.matrixDomain := by + intro X hX Y hY a b ha hb hab + refine ⟨?_,?_⟩ + · have hh := add_le_add (smul_le_smul_of_nonneg_left hX.1 ha) (smul_le_smul_of_nonneg_left hY.1 hb) + simpa only [←add_smul,hab,one_smul] using hh + · intro S hS hS' + rw [qform_add,qform_smul,qform_smul] + have hh := add_le_add (mul_le_mul_of_nonneg_left (hX.2 S hS hS') ha) + (mul_le_mul_of_nonneg_left (hY.2 S hS hS') hb) + simpa only [←add_mul,hab,one_mul] using hh +lemma domain_nonempty (hn : 0 < n) (hc : G.EdgeConnected 1) : G.matrixDomain.Nonempty := by + refine ⟨G.baseMatrix,le_rfl,?_⟩ + intro S hS hS' + rw [G.baseMatrix_cut] + have hcut : (1:ℝ) ≤ (G.cut univ S).card := by exact_mod_cast hc S hS hS' + have hcard : (S.card:ℝ) ≤ n := by exact_mod_cast (show S.card ≤ n by simpa using card_le_univ S) + have hdiv : (S.card:ℝ)/n ≤ 1 := (div_le_one (Nat.cast_pos.mpr hn)).mpr hcard + linarith +lemma indicator_singleton (i : Fin n) : cutIndicator {i}=Pi.single i 1 := by + ext j + simp [cutIndicator,Pi.single_apply,eq_comm] +lemma domain_diag_bound (hn : 2 ≤ n) {X : Matrix (Fin n) (Fin n) ℝ} (hX : X ∈ G.matrixDomain) (i : Fin n) : + X i i ≤ 3*m := by + have hproper : ({i} : Finset (Fin n)) ≠ univ := by + intro he + have hh := congrArg card he + simp only [card_singleton,card_univ,Fintype.card_fin] at hh + omega + have hh := hX.2 {i} (singleton_nonempty _) hproper + rw [indicator_singleton,qform_single] at hh + have hm : ((G.cut univ {i}).card:ℝ) ≤ m := by exact_mod_cast (show (G.cut univ {i}).card ≤ m by simpa using card_le_univ (G.cut univ {i})) + linarith +lemma domain_bounded (hn : 2 ≤ n) : Bornology.IsBounded G.matrixDomain := by + apply isBounded_iff_forall_norm_le.mpr + refine ⟨3*m,fun X hX => ?_⟩ + have hC : (0:ℝ) ≤ 3*m := by positivity + apply (pi_norm_le_iff_of_nonneg hC).mpr + intro i + apply (pi_norm_le_iff_of_nonneg hC).mpr + intro j + simpa only [Real.norm_eq_abs] using psd_entry_bound (G.domain_pd (by omega) hX).posSemidef hC + (G.domain_diag_bound hn hX) i j +lemma domain_compact (hn : 2 ≤ n) : IsCompact G.matrixDomain := + Metric.isCompact_iff_isClosed_bounded.mpr ⟨G.domain_closed,G.domain_bounded hn⟩ +lemma resistance_continuousAt {X : Matrix (Fin n) (Fin n) ℝ} (hX : X.PosDef) (e : Fin m) : + ContinuousAt (fun Y => G.resistance Y e) X := by + apply (qform_continuous (G.incidence e)).continuousAt.comp + apply continuousAt_matrix_inv + simpa only [Ring.inverse_eq_inv'] using continuousAt_inv₀ hX.det_pos.ne' +lemma resistance_continuousOn (hn : 0 < n) (e : Fin m) : ContinuousOn (fun X => G.resistance X e) G.matrixDomain := + fun _ hX => (G.resistance_continuousAt (G.domain_pd hn hX) e).continuousWithinAt + +end MultiGraph +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/MatrixMixture.lean b/lean/OAI/Combinatorics/ThinTrees/MatrixMixture.lean new file mode 100644 index 0000000000000000000000000000000000000000..94b0932f1ae45cc42d2238c93352a835bde2a030 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/MatrixMixture.lean @@ -0,0 +1,102 @@ +import OAI.Combinatorics.ThinTrees.ResponseFixedPoint + +namespace OAI + +universe uI uV uE + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree +variable {I : Type uI} {V : Type uV} [Fintype V] [DecidableEq V] +def mixtureBadWeight (C : Finset I) (w : I → ℝ) (Y : I → Matrix V V ℝ) (t : ℝ) (b : V → ℝ) : ℝ := + ∑i ∈ C, if t < qform (Y i)⁻¹ b then w i else 0 +lemma mixture_resistance (C : Finset I) (w : I → ℝ) (Y : I → Matrix V V ℝ) + (hw : ∀i ∈ C, 0 ≤ w i) (hw1 : (∑i ∈ C, w i)=1) + (hY : ∀i ∈ C, (Y i).PosDef) {X : Matrix V V ℝ} (hX : X.PosDef) + (heq : (∑i ∈ C, w i • Y i)=X) {t : ℝ} (ht : 0 < t) (b : V → ℝ) + (hb : mixtureBadWeight C w Y t b ≤ 1/2) : qform X⁻¹ b ≤ 2*t := by + classical + let good : I → ℝ := fun i => if t < qform (Y i)⁻¹ b then 0 else w i + have hsplit : (∑i ∈ C, good i)+mixtureBadWeight C w Y t b=1 := by + rw [mixtureBadWeight,←sum_add_distrib,←hw1] + apply sum_congr rfl + intro i _ + dsimp [good] + split_ifs <;> simp + have hgood : (1/2:ℝ) ≤ ∑i ∈ C, good i := by linarith + have ho : ∀i ∈ C, good i • vecMulVec b b ≤ (t*w i) • Y i := by + intro i hi + dsimp [good] + split_ifs with h + · simp only [zero_smul] + exact smul_nonneg (mul_nonneg ht.le (hw i hi)) (Matrix.nonneg_iff_posSemidef.mpr (hY i hi).posSemidef) + · have hh : vecMulVec b b ≤ t • Y i := Matrix.le_iff.mpr ((resistance_order (hY i hi) b ht).mp (le_of_not_gt h)) + simpa only [smul_smul,mul_comm] using smul_le_smul_of_nonneg_left hh (hw i hi) + have hs : (∑i ∈ C, good i) • vecMulVec b b ≤ t • X := by + have hh := sum_le_sum ho + rw [←sum_smul] at hh + rw [←heq,smul_sum] + convert hh using 1 + apply sum_congr rfl + intro i _ + rw [smul_smul] + have hbpsd : 0 ≤ vecMulVec b b := Matrix.nonneg_iff_posSemidef.mpr (by simpa only [star_trivial] using posSemidef_vecMulVec_self_star b) + have hhalf : (1/2:ℝ) • vecMulVec b b ≤ t • X := (smul_le_smul_of_nonneg_right hgood hbpsd).trans hs + have hdouble := smul_le_smul_of_nonneg_left hhalf (by norm_num : (0:ℝ) ≤ 2) + have horder : vecMulVec b b ≤ (2*t) • X := by + simpa only [smul_smul,show (2:ℝ)*(1/2)=1 by norm_num,one_smul] using hdouble + exact (resistance_order hX b (by positivity)).mpr (Matrix.le_iff.mp horder) + +lemma mixture_bad_bound {E : Type uE} [DecidableEq E] (B : Finset E) (b : E → V → ℝ) + (C : Finset I) (w : I → ℝ) (Y : I → Matrix V V ℝ) + (hw : ∀i ∈ C, 0 ≤ w i) (hw1 : (∑i ∈ C, w i)=1) + (hY : ∀i ∈ C, (Y i).PosDef) {X : Matrix V V ℝ} (hX : X.PosDef) + (heq : (∑i ∈ C, w i • Y i)=X) {t δ : ℝ} (ht : 0 < t) + (hcount : ∀i ∈ C, 0 < w i → ((B.filter (fun e => t < qform (Y i)⁻¹ (b e))).card:ℝ) ≤ δ*B.card) : + ((B.filter (fun e => 2*t < qform X⁻¹ (b e))).card:ℝ) ≤ 2*δ*B.card := by + classical + by_cases hB : B=∅ + · simp [hB] + have hBp : (0:ℝ) < B.card := Nat.cast_pos.mpr (card_pos.mpr (nonempty_iff_ne_empty.mpr hB)) + let z := fun e => mixtureBadWeight C w Y t (b e) + have hz (e : E) : 0 ≤ z e := sum_nonneg (fun i hi => by split_ifs; exact hw i hi; exact le_rfl) + have hsum : (∑e ∈ B, z e) ≤ δ*B.card := by + calc + _ = ∑i ∈ C, w i*((B.filter (fun e => t < qform (Y i)⁻¹ (b e))).card:ℝ) := by + dsimp [z,mixtureBadWeight] + rw [sum_comm] + apply sum_congr rfl + intro i _ + rw [←sum_filter] + simp [mul_comm] + _ ≤ ∑i ∈ C, w i*(δ*B.card) := by + apply sum_le_sum + intro i hi + rcases (hw i hi).eq_or_lt with hzero | hpos + · simp [←hzero] + · exact mul_le_mul_of_nonneg_left (hcount i hi hpos) (hw i hi) + _ = δ*B.card := by rw [←sum_mul,hw1,one_mul] + have havg : (B.card:ℝ)⁻¹*(∑e ∈ B, z e) ≤ δ := by + rw [mul_comm,←div_eq_mul_inv] + exact (div_le_iff₀ hBp).mpr hsum + have hm := finite_markov B z (fun e _ => hz e) (by norm_num : (0:ℝ)<1/2) havg + have hsub : B.filter (fun e => 2*t < qform X⁻¹ (b e)) ⊆ B.filter (fun e => 1/2 < z e) := by + intro e he + obtain ⟨heB,heR⟩ := mem_filter.mp he + refine mem_filter.mpr ⟨heB,?_⟩ + by_contra h + have hh := mixture_resistance C w Y hw hw1 hY hX heq ht (b e) (le_of_not_gt h) + linarith + have hc : ((B.filter (fun e => 2*t < qform X⁻¹ (b e))).card:ℝ) ≤ (B.filter (fun e => 1/2 < z e)).card := by + exact_mod_cast card_le_card hsub + nlinarith + +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/AssignedCharging.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/AssignedCharging.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ae785bc22d7058439b294d0158c905448839432 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/AssignedCharging.lean @@ -0,0 +1,2852 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.AssignedGeometry +import OAI.Combinatorics.ThinTrees.RationalMatrix.SchurHistory + +namespace OAI + +/-! Metric assigned charging. -/ + +section + +open scoped Classical + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) + +structure Record (n : ℕ) where + shell : RadialShell (Fin n) + owner : Finset (Fin n) + predecessors : Finset (Finset (Fin n)) + avoided : Option (Finset (Fin n)) + deriving DecidableEq + +namespace Record +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) + +def excluded (B : Record n) : Finset (Finset (Fin n)) := + B.predecessors ∪ B.avoided.toFinset + +def conflict (B : Record n) := H.domain B.owner B.excluded +def leafSet (B : Record n) := H.leaves B.owner B.excluded +def routing (B : Record n) : Finset (Fin n) := B.owner\B.avoided.getD ∅ + +def Shape (B : Record n) : Prop := + B.owner ∈ H.nodes ∧ (∀S ∈ B.excluded, S ∈ H.nodes ∧ S ⊂ B.owner) + +def Protected (B : Record n) : Prop := + ∀S ∈ B.predecessors, ∀e ∈ G.cut univ S, + B.shell.outer ≤ normDistance (X (G.left e)) (X B.shell.center) ∧ + B.shell.outer ≤ normDistance (X (G.right e)) (X B.shell.center) + +def RoutingCertificate (q : ℝ) (B : Record n) : Prop := + ∃R : Finset (Fin n), R ⊆ B.routing ∧ G.EdgeConnectedReal R q ∧ + (∃u ∈ R, u ∈ B.leafSet H ∧ normDistance (X u) (X B.shell.center) ≤ B.shell.inner) ∧ + (∃v ∈ R, B.shell.outer ≤ normDistance (X v) (X B.shell.center)) + +def Valid (q : ℝ) (B : Record n) : Prop := + B.Shape H ∧ B.Protected G X ∧ B.shell.Valid X ∧ B.RoutingCertificate H G X q + +lemma root_mem {B : Record n} (hB : B.Shape H) : B.owner ∈ B.conflict H := + H.root_mem_domain hB.1 (fun S hS => (hB.2 S hS).2) + +lemma mem_leafSet {B : Record n} {v : Fin n} : + v ∈ B.leafSet H ↔ v ∈ B.owner ∧ ∀S ∈ B.excluded, v ∉ S := H.mem_leaves + +lemma mem_routing {B : Record n} {v : Fin n} : + v ∈ B.routing ↔ v ∈ B.owner ∧ ∀S ∈ B.avoided.toFinset, v ∉ S := by + cases heq : B.avoided <;> simp [routing,heq] + +omit [PseudoMetricSpace Coord] in +lemma protected_routing_edges {B : Record n} (hB : B.Protected G X) + {R : Finset (Fin n)} (hR : R ⊆ B.routing) : + ∀e ∈ G.inducedEdges R, + ((G.left e ∈ B.leafSet H ∧ G.right e ∉ B.leafSet H) ∨ + (G.right e ∈ B.leafSet H ∧ G.left e ∉ B.leafSet H)) → + B.shell.outer ≤ normDistance (X (G.left e)) (X B.shell.center) ∧ + B.shell.outer ≤ normDistance (X (G.right e)) (X B.shell.center) := by + have hex {u v : Fin n} (hu : u ∈ B.leafSet H) (hv : v ∈ B.routing) + (hn : v ∉ B.leafSet H) : ∃S ∈ B.predecessors, u ∉ S ∧ v ∈ S := by + obtain ⟨hu,hup⟩ := (mem_leafSet H).mp hu + obtain ⟨hv,hva⟩ := mem_routing.mp hv + have : ∃S ∈ B.excluded, v ∈ S := by + by_contra hh + push Not at hh + exact hn ((mem_leafSet H).mpr ⟨hv,hh⟩) + obtain ⟨S,hS,hvS⟩ := this + have hSp : S ∈ B.predecessors := by + rcases mem_union.mp hS with hh | hh + · exact hh + · exact (hva S hh hvS).elim + exact ⟨S,hSp,hup S hS,hvS⟩ + intro e he hcross + obtain ⟨hlR,hrR⟩ := (G.mem_inducedEdges _ _).mp he + rcases hcross with hcross | hcross + · obtain ⟨S,hS,hl,hr⟩ := hex hcross.1 (hR hrR) hcross.2 + exact hB S hS e (mem_filter.mpr ⟨mem_univ _,Or.inr ⟨hr,hl⟩⟩) + · obtain ⟨S,hS,hr,hl⟩ := hex hcross.1 (hR hlR) hcross.2 + exact hB S hS e (mem_filter.mpr ⟨mem_univ _,Or.inl ⟨hl,hr⟩⟩) + +omit [PseudoMetricSpace Coord] in +lemma variation_lower {q : ℝ} {B : Record n} (hB : B.Valid H G X q) : + q*B.shell.width ≤ ∑e ∈ G.inducedEdges (B.leafSet H), + |clamp B.shell.inner B.shell.outer (normDistance (X (G.left e)) (X B.shell.center))- + clamp B.shell.inner B.shell.outer (normDistance (X (G.right e)) (X B.shell.center))| := by + obtain ⟨R,hR,hconn,hu,hv⟩ := hB.2.2.2 + exact G.routed_variation_lower _ hB.2.2.1.2.1.le hconn hu hv + (protected_routing_edges H G X hB.2.1 hR) + +omit [PseudoMetricSpace Coord] in +lemma restrict_valid {q a b : ℝ} {B : Record n} (hB : B.Valid H G X q) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) (hab : a < b) : + ({B with shell := RadialShell.hollow B.shell.center a b}).Valid H G X q := by + refine ⟨hB.1,?_,?_,?_⟩ + · intro S hS e he + exact ⟨hb.trans (hB.2.1 S hS e he).1,hb.trans (hB.2.1 S hS e he).2⟩ + · obtain ⟨u,hu⟩ := hB.2.2.1.2.2.2.1 + obtain ⟨v,hv⟩ := hB.2.2.1.2.2.2.2 + exact ⟨hB.2.2.1.1.trans ha,hab,by simp [RadialShell.hollow],⟨u,hu.trans ha⟩,⟨v,hb.trans hv⟩⟩ + · obtain ⟨R,hR,hconn,⟨u,huR,huL,hu⟩,⟨v,hvR,hv⟩⟩ := hB.2.2.2 + exact ⟨R,hR,hconn,⟨u,huR,huL,hu.trans ha⟩,⟨v,hvR,hb.trans hv⟩⟩ + +end Record +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) + +def LabeledArrangement (q : ℝ) (Z : Finset (Record n)) : Prop := + (∀B ∈ Z, B.Valid H G X q) ∧ + (Z : Set (Record n)).Pairwise (fun B D => + ¬Disjoint (B.shell.support X) (D.shell.support X) → + Disjoint (B.conflict H) (D.conflict H)) + +lemma labeled_energy {q : ℝ} (hX : ∀v, isProfile (X v)) {Z : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) : + q*(∑B ∈ Z, B.shell.width) ≤ ∑e : Fin m, normDistance (X (G.left e)) (X (G.right e)) := by + let f (B : Record n) (e : Fin m) := + |clamp B.shell.inner B.shell.outer (normDistance (X (G.left e)) (X B.shell.center))- + clamp B.shell.inner B.shell.outer (normDistance (X (G.right e)) (X B.shell.center))| + calc + _ = ∑B ∈ Z, q*B.shell.width := mul_sum _ _ _ + _ ≤ ∑B ∈ Z, ∑e ∈ G.inducedEdges (B.leafSet H), f B e := + sum_le_sum (fun B hB => B.variation_lower H G X (hZ.1 B hB)) + _ = ∑e : Fin m, ∑B ∈ Z.filter (fun B => e ∈ G.inducedEdges (B.leafSet H)), f B e := by + simp only [inducedEdges,sum_filter,mem_filter,mem_univ,true_and] + rw [sum_comm] + _ ≤ _ := by + apply sum_le_sum + intro e he + let W := Z.filter (fun B => e ∈ G.inducedEdges (B.leafSet H)) + rw [← Finset.sum_coe_sort] + apply profile_shell_edge_bound (isProfile_inPolytope (hX _)) (isProfile_inPolytope (hX _)) + (fun B : W => X B.val.shell.center) (fun B => hX _) _ _ + · intro B + exact (hZ.1 B.val (mem_filter.mp B.property).1).2.2.1.2.1.le + · intro B D hBD w hw hbad + have hB : B.val ∈ Z := (mem_filter.mp B.property).1 + have hD : D.val ∈ Z := (mem_filter.mp D.property).1 + have hinter : ¬Disjoint (B.val.shell.support X) (D.val.shell.support X) := by + intro hh + exact Set.disjoint_left.mp hh ⟨hw,hbad.2.1,Or.inr hbad.1⟩ + ⟨hw,hbad.2.2.2,Or.inr hbad.2.2.1⟩ + have hdis := hZ.2 hB hD (fun hh => hBD (Subtype.ext hh)) hinter + have hlB := ((G.mem_inducedEdges _ _).mp (mem_filter.mp B.property).2).1 + have hlD := ((G.mem_inducedEdges _ _).mp (mem_filter.mp D.property).2).1 + have hmB : {G.left e} ∈ B.val.conflict H := H.singleton_domain_iff.mpr hlB + have hmD : {G.left e} ∈ D.val.conflict H := H.singleton_domain_iff.mpr hlD + exact Finset.disjoint_left.mp hdis hmB hmD + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) + +def parentBoundary (A : Finset (Fin n)) : Finset (Fin m) := + G.cut (G.inducedEdges (H.parent A)) A + +def LocallyConnectedReal (q : ℝ) : Prop := ∀A ∈ H.nodes, G.EdgeConnectedReal A q + +lemma parent_boundary_lower {q : ℝ} (hconn : LocallyConnectedReal H G q) + {A : Finset (Fin n)} (hA : A ∈ H.nodes) (hne : A ≠ univ) : + q ≤ (parentBoundary H G A).card := + hconn (H.parent A) (H.parent_mem A hA hne) A (H.nonempty A hA) + (H.parent_strict A hA hne) + +structure AssignedBag (δ η : ℝ) where + owner : Finset (Fin n) + owner_mem : owner ∈ H.nodes + nonroot : owner ≠ univ + centers : Finset (Fin n) + nonempty : centers.Nonempty + radius_pos : 0 < δ + disjoint : (centers : Set (Fin n)).Pairwise (fun u v => + Disjoint ((RadialShell.ball u δ).support X) ((RadialShell.ball v δ).support X)) + assignment : η*(parentBoundary H G owner).card ≤ (centers.card : ℝ) + endpoint : ∀u ∈ centers, u ∈ owner ∧ ∃e ∈ parentBoundary H G owner, + (G.left e = u ∨ G.right e = u) ∧ normDistance (X (G.left e)) (X (G.right e)) < δ + +namespace AssignedBag +variable {H G X} {δ η : ℝ} (A : AssignedBag H G X δ η) + +def input (P : Finset (Finset (Fin n))) (u : Fin n) : Record n := + ⟨RadialShell.ball u δ,A.owner,P,none⟩ + +lemma input_leaf {P : Finset (Finset (Fin n))} (hP : ∀S ∈ P, S ⊂ A.owner) + {u : Fin n} (hu : u ∈ A.centers) (hins : (A.input P u).Protected G X) : + u ∈ (A.input P u).leafSet H := by + apply (Record.mem_leafSet H).mpr + refine ⟨(A.endpoint u hu).1,?_⟩ + intro S hS huS + have hSP : S ∈ P := by simpa [Record.excluded,input] using hS + obtain ⟨e,he,heu,hlen⟩ := (A.endpoint u hu).2 + have he' := (mem_filter.mp he).2 + have hcut : e ∈ G.cut univ S := by + apply mem_filter.mpr + refine ⟨mem_univ _,?_⟩ + rcases he' with hh | hh + · have hright : G.right e ∉ S := fun hs => hh.2 ((hP S hSP).subset hs) + rcases heu with heu | heu + · exact Or.inl ⟨heu.symm ▸ huS,hright⟩ + · exact (hright (heu.symm ▸ huS)).elim + · have hleft : G.left e ∉ S := fun hs => hh.2 ((hP S hSP).subset hs) + rcases heu with heu | heu + · exact (hleft (heu.symm ▸ huS)).elim + · exact Or.inr ⟨heu.symm ▸ huS,hleft⟩ + have hp := hins S hSP e hcut + rcases heu with heu | heu + · have hp := hp.1 + change δ ≤ normDistance (X (G.left e)) (X u) at hp + rw [heu,normDistance_self] at hp + linarith [A.radius_pos] + · have hp := hp.2 + change δ ≤ normDistance (X (G.right e)) (X u) at hp + rw [heu,normDistance_self] at hp + linarith [A.radius_pos] + +lemma input_valid (hX : ∀v, isProfile (X v)) {q : ℝ} (_hq : 0 ≤ q) + (hconn : LocallyConnectedReal H G q) (hsize : 1 < A.centers.card) + {P : Finset (Finset (Fin n))} (hP : ∀S ∈ P, S ∈ H.nodes ∧ S ⊂ A.owner) + {u : Fin n} (hu : u ∈ A.centers) (hins : (A.input P u).Protected G X) : + (A.input P u).Valid H G X (q/4) := by + obtain ⟨v,hv,hvu⟩ := Finset.exists_mem_ne hsize u + have hdist := RadialShell.disjoint_balls_distance hX u v (A.disjoint hu hv hvu.symm) + have houter : δ ≤ normDistance (X v) (X u) := by + rw [normDistance_comm] + linarith [A.radius_pos] + refine ⟨?_,hins,?_,?_⟩ + · refine ⟨A.owner_mem,?_⟩ + intro S hS + exact hP S (by simpa [input,Record.excluded] using hS) + · exact ⟨le_refl 0,A.radius_pos,by simp [input,RadialShell.ball], + ⟨u,by simp [input,RadialShell.ball,normDistance_self]⟩,⟨v,houter⟩⟩ + · refine ⟨A.owner,?_,?_,⟨u,(A.endpoint u hu).1,A.input_leaf (fun S hS => (hP S hS).2) hu hins,?_⟩, + ⟨v,(A.endpoint v hv).1,houter⟩⟩ + · simp [input,Record.routing] + · intro S hS hSA + have hh := hconn A.owner A.owner_mem S hS hSA + linarith + · simp [input,RadialShell.ball,normDistance_self] + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) + +lemma predecessor_dichotomy {A t : Finset (Fin n)} {P : Finset (Finset (Fin n))} + (ht : t ∈ H.domain A P) (hP : ∀S ∈ P, S ∈ H.nodes) + {S : Finset (Fin n)} (hS : S ∈ P) : S ⊂ t ∨ Disjoint S t := by + obtain ⟨htn,hta,htP⟩ := H.mem_domain.mp ht + rcases H.laminar S (hP S hS) t htn with hSt | htS | hdis + · left + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨hSt,?_⟩ + intro heq + exact htP S hS (heq ▸ Subset.refl _) + · exact (htP S hS htS).elim + · exact Or.inr hdis + +lemma domain_descendant_partition {A t : Finset (Fin n)} {P : Finset (Finset (Fin n))} + (ht : t ∈ H.domain A P) (hP : ∀S ∈ P, S ∈ H.nodes) : + H.domain t (P.filter (fun S => S ⊂ t)) = + (H.domain A P).filter (fun C => C ⊆ t) := by + obtain ⟨htn,htA,htP⟩ := H.mem_domain.mp ht + ext C + simp only [mem_filter,mem_domain] + constructor + · rintro ⟨hCn,hCt,hCP⟩ + refine ⟨⟨hCn,hCt.trans htA,?_⟩,hCt⟩ + intro S hS hCS + rcases predecessor_dichotomy H ht hP hS with hSt | hdis + · exact hCP S ⟨hS,hSt⟩ hCS + · obtain ⟨v,hv⟩ := H.nonempty C hCn + exact Finset.disjoint_left.mp hdis (hCS hv) (hCt hv) + · rintro ⟨⟨hCn,hCA,hCP⟩,hCt⟩ + exact ⟨hCn,hCt,fun S hS => hCP S hS.1⟩ + +lemma domain_avoid_partition (A t : Finset (Fin n)) (P : Finset (Finset (Fin n))) : + H.domain A (insert t P) = (H.domain A P).filter (fun C => ¬C ⊆ t) := by + ext C + simp only [mem_domain,mem_filter,mem_insert] + constructor + · rintro ⟨hCn,hCA,hCP⟩ + exact ⟨⟨hCn,hCA,fun S hS => hCP S (Or.inr hS)⟩,hCP t (Or.inl rfl)⟩ + · rintro ⟨⟨hCn,hCA,hCP⟩,hCt⟩ + exact ⟨hCn,hCA,fun S hS => by rcases hS with rfl | hS; exact hCt; exact hCP S hS⟩ + +namespace Record +variable (G : MultiGraph n m) (X : Fin n → Doubled Coord → ℝ) + +def innerRecord (B : Record n) (t : Finset (Fin n)) (a b : ℝ) : Record n := + ⟨RadialShell.hollow B.shell.center a b,t,B.predecessors.filter (fun S => S ⊂ t),none⟩ +def outsideRecord (B : Record n) (t : Finset (Fin n)) (a b : ℝ) : Record n := + ⟨RadialShell.hollow B.shell.center a b,B.owner,B.predecessors,some t⟩ + +lemma central_conflict {B : Record n} (hshape : B.Shape H) (hno : B.avoided = none) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) (a b c d : ℝ) : + (B.innerRecord t a b).conflict H = (B.conflict H).filter (fun C => C ⊆ t) ∧ + (B.outsideRecord t c d).conflict H = (B.conflict H).filter (fun C => ¬C ⊆ t) := by + have heq : B.excluded = B.predecessors := by simp [excluded,hno] + have hP : ∀S ∈ B.predecessors, S ∈ H.nodes := fun S hS => (hshape.2 S (heq.symm ▸ hS)).1 + have ht' : t ∈ H.domain B.owner B.predecessors := by simpa only [conflict,heq] using ht + constructor + · simpa only [conflict,innerRecord,excluded,Option.toFinset_none,union_empty,hno] using + domain_descendant_partition H ht' hP + · simpa only [conflict,outsideRecord,excluded,Option.toFinset_some,union_singleton,hno,Option.toFinset_none,union_empty] using + domain_avoid_partition H B.owner t B.predecessors + +lemma central_domain_disjoint {B : Record n} (hshape : B.Shape H) (hno : B.avoided = none) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) (a b c d : ℝ) : + Disjoint ((B.innerRecord t a b).conflict H) ((B.outsideRecord t c d).conflict H) := by + obtain ⟨h1,h2⟩ := central_conflict H hshape hno ht a b c d + rw [h1,h2,Finset.disjoint_left] + intro C hC hD + exact (mem_filter.mp hD).2 (mem_filter.mp hC).2 + +omit [PseudoMetricSpace Coord] in +lemma protected_same_side {B : Record n} (hB : B.Protected G X) + {u v : Fin n} {e : Fin m} + (he : (G.left e = u ∧ G.right e = v) ∨ (G.left e = v ∧ G.right e = u)) + (hu : normDistance (X u) (X B.shell.center) < B.shell.outer) : + ∀S ∈ B.predecessors, u ∈ S ↔ v ∈ S := by + intro S hS + have hn : e ∉ G.cut univ S := by + intro hc + have hh := hB S hS e hc + rcases he with he | he + · rw [he.1] at hh + linarith [hh.1] + · rw [he.2] at hh + linarith [hh.2] + simp only [cut,mem_filter,mem_univ,true_and] at hn + rcases he with he | he <;> simp only [he.1,he.2] at hn <;> tauto + +omit [PseudoMetricSpace Coord] in +lemma central_valid {q a b δ : ℝ} {B : Record n} + (hB : B.Valid H G X (q/4)) (hno : B.avoided = none) + (hq : 0 ≤ q) (hconn : LocallyConnectedReal H G q) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) (htstrict : t ⊂ B.owner) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hδ : 0 < δ) (hab : a+δ < b-δ) + {R : Finset (Fin n)} (hR : R ⊆ H.parent t \ t) + (hRc : G.EdgeConnectedReal R (q/4)) + {u₁ u₂ v₁ v₂ : Fin n} (hu₁ : u₁ ∈ t) (hu₂ : u₂ ∈ t) + (hv₁ : v₁ ∈ R) (hv₂ : v₂ ∈ R) + (hu₁rad : normDistance (X u₁) (X B.shell.center) ≤ a+δ) + (hu₂rad : b-δ ≤ normDistance (X u₂) (X B.shell.center)) + (hv₁rad : normDistance (X v₁) (X B.shell.center) ≤ a) + (hv₂rad : b ≤ normDistance (X v₂) (X B.shell.center)) + {e : Fin m} (he : (G.left e = u₁ ∧ G.right e = v₁) ∨ + (G.left e = v₁ ∧ G.right e = u₁)) : + (B.innerRecord t (a+δ) (b-δ)).Valid H G X (q/4) ∧ + (B.outsideRecord t a b).Valid H G X (q/4) := by + have htn := (H.mem_domain.mp ht).1 + have htne : t ≠ univ := by + intro hh + have := htstrict.not_subset (by simp [hh]) + exact this + have hparent : H.parent t ⊆ B.owner := + H.parent_minimal t htn htne B.owner hB.1.1 htstrict + have hp : ∀S ∈ B.predecessors, S ∈ H.nodes ∧ S ⊂ B.owner := + fun S hS => hB.1.2 S (mem_union_left _ hS) + have htex : t ∈ H.domain B.owner B.predecessors := by + simpa only [conflict,excluded,hno,Option.toFinset_none,union_empty] using ht + have hv₁out : v₁ ∉ t := (mem_sdiff.mp (hR hv₁)).2 + have hsame : ∀S ∈ B.predecessors, u₁ ∈ S ↔ v₁ ∈ S := + protected_same_side G X hB.2.1 he (by linarith) + have huvavoid : ∀S ∈ B.predecessors, u₁ ∉ S ∧ v₁ ∉ S := by + intro S hS + rcases predecessor_dichotomy H htex (fun S hS => (hp S hS).1) hS with hSt | hdis + · have hvS : v₁ ∉ S := fun hh => hv₁out (hSt.subset hh) + exact ⟨fun hh => hvS ((hsame S hS).mp hh),hvS⟩ + · have huS : u₁ ∉ S := fun hh => Finset.disjoint_left.mp hdis hh hu₁ + exact ⟨huS,fun hh => huS ((hsame S hS).mpr hh)⟩ + constructor + · refine ⟨?_,?_,?_,?_⟩ + · refine ⟨htn,?_⟩ + intro S hS + have hS' : S ∈ B.predecessors ∧ S ⊂ t := by + simpa [excluded,innerRecord] using hS + exact ⟨(hp S hS'.1).1,hS'.2⟩ + · intro S hS e he + have hS' : S ∈ B.predecessors := (mem_filter.mp hS).1 + have hh := hB.2.1 S hS' e he + exact ⟨(by dsimp [innerRecord,RadialShell.hollow]; linarith [hh.1]), + (by dsimp [innerRecord,RadialShell.hollow]; linarith [hh.2])⟩ + · refine ⟨?_,hab,by simp [innerRecord,RadialShell.hollow],⟨u₁,hu₁rad⟩,⟨u₂,hu₂rad⟩⟩ + dsimp [innerRecord,RadialShell.hollow] + linarith [hB.2.2.1.1] + · refine ⟨t,?_,?_,⟨u₁,hu₁,?_,hu₁rad⟩,⟨u₂,hu₂,hu₂rad⟩⟩ + · simp [routing,innerRecord] + · intro S hSn hSt + exact (by linarith : q/4 ≤ q).trans (hconn t htn S hSn hSt) + · apply (mem_leafSet H).mpr + refine ⟨hu₁,?_⟩ + intro S hS + have hS' : S ∈ B.predecessors ∧ S ⊂ t := by + simpa [excluded,innerRecord] using hS + exact (huvavoid S hS'.1).1 + · refine ⟨?_,?_,?_,?_⟩ + · refine ⟨hB.1.1,?_⟩ + intro S hS + have hS' : S ∈ B.predecessors ∨ S = t := by + simpa [excluded,outsideRecord,or_comm] using hS + rcases hS' with hS | rfl + · exact hp S hS + · exact ⟨htn,htstrict⟩ + · intro S hS e he + have hh := hB.2.1 S hS e he + exact ⟨hb.trans hh.1,hb.trans hh.2⟩ + · refine ⟨?_,?_,by simp [outsideRecord,RadialShell.hollow],⟨v₁,hv₁rad⟩,⟨v₂,hv₂rad⟩⟩ + · exact hB.2.2.1.1.trans ha + · dsimp [outsideRecord,RadialShell.hollow] + linarith + · refine ⟨R,?_,hRc,⟨v₁,hv₁,?_,hv₁rad⟩,⟨v₂,hv₂,hv₂rad⟩⟩ + · intro v hv + obtain ⟨hvA,hvt⟩ := mem_sdiff.mp (hR hv) + exact mem_sdiff.mpr ⟨hparent hvA,hvt⟩ + · apply (mem_leafSet H).mpr + refine ⟨hparent (mem_sdiff.mp (hR hv₁)).1,?_⟩ + intro S hS + have hS' : S ∈ B.predecessors ∨ S = t := by + simpa [excluded,outsideRecord,or_comm] using hS + rcases hS' with hS | rfl + · exact (huvavoid S hS).2 + · exact hv₁out + +end Record +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) + +namespace Record + +def Compatible (B D : Record n) : Prop := + Disjoint (B.shell.support X) (D.shell.support X) ∨ Disjoint (B.conflict H) (D.conflict H) + +lemma compatible_symm {B D : Record n} (h : B.Compatible H X D) : D.Compatible H X B := + h.elim (fun h => Or.inl h.symm) (fun h => Or.inr h.symm) + +lemma compatible_self_iff (B : Record n) (hX : ∀v, isProfile (X v)) + (hshape : B.Shape H) (hvalid : B.shell.Valid X) : ¬B.Compatible H X B := by + intro hh + rcases hh with hh | hh + · obtain ⟨w,hw⟩ := RadialShell.valid_support_nonempty hX hvalid + exact Set.disjoint_left.mp hh hw hw + · exact Finset.disjoint_left.mp hh (B.root_mem H hshape) (B.root_mem H hshape) + +lemma compatible_heredity {B D C : Record n} (hBD : B.Compatible H X D) + (hCB : C.shell.support X ⊆ B.shell.support X) (hCC : C.conflict H ⊆ B.conflict H) : + C.Compatible H X D := by + rcases hBD with hBD | hBD + · exact Or.inl (hBD.mono_left hCB) + · exact Or.inr (hBD.mono_left hCC) + +lemma candidate_ancestor {A B : Record n} (hA : A.Shape H) (hB : B.Shape H) + (horder : B.owner ⊂ A.owner → B.owner ∈ A.excluded) + (hinter : (A.conflict H ∩ B.conflict H).Nonempty) : A.owner ∈ B.conflict H := by + have hroots := (H.domain_root_test hA.1 hB.1 + (fun S hS => (hA.2 S hS).2) (fun S hS => (hB.2 S hS).2)).mp hinter + rcases hroots with hh | hh + · exact hh + · have hba := (H.mem_domain.mp hh).2.1 + by_cases heq : B.owner = A.owner + · exact heq ▸ B.root_mem H hB + · have hs := horder (Finset.ssubset_iff_subset_ne.mpr ⟨hba,heq⟩) + exact ((H.mem_domain.mp hh).2.2 B.owner hs (Subset.refl _)).elim + +lemma insert_compatible {q : ℝ} {Z : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) {A B D : Record n} + (hA : A.Shape H) (hB : B ∈ Z) (hD : D ∈ Z) (hne : B ≠ D) + (hBA : A.owner ∈ B.conflict H) + (horder : ∀F ∈ Z, F.owner ⊂ A.owner → F.owner ∈ A.excluded) + (hAB : A.shell.support X ⊆ B.shell.support X) : A.Compatible H X D := by + by_cases hgeo : Disjoint (A.shell.support X) (D.shell.support X) + · exact Or.inl hgeo + right + by_contra hh + have hinter : (A.conflict H ∩ D.conflict H).Nonempty := by + apply Finset.nonempty_iff_ne_empty.mpr + intro hempty + exact hh (Finset.disjoint_iff_inter_eq_empty.mpr hempty) + have hDA := candidate_ancestor H hA (hZ.1 D hD).1 (horder D hD) hinter + have hBD : ¬Disjoint (B.shell.support X) (D.shell.support X) := + fun hd => hgeo (hd.mono_left hAB) + exact Finset.disjoint_left.mp (hZ.2 hB hD hne hBD) hBA hDA + +def Interior (C δ : ℝ) (A B : Record n) : Prop := + (A.conflict H ∩ B.conflict H).Nonempty ∧ + B.shell.inner+C*δ < normDistance (X A.shell.center) (X B.shell.center) ∧ + normDistance (X A.shell.center) (X B.shell.center) < B.shell.outer-C*δ + +omit [PseudoMetricSpace Coord] in +lemma interior_restriction {C δ : ℝ} {A B D : Record n} + (hcenter : D.shell.center = B.shell.center) + (ha : B.shell.inner ≤ D.shell.inner) (hb : D.shell.outer ≤ B.shell.outer) + (hdom : D.conflict H ⊆ B.conflict H) (hh : A.Interior H X C δ D) : + A.Interior H X C δ B := by + obtain ⟨⟨S,hS⟩,hl,hr⟩ := hh + rw [hcenter] at hl hr + exact ⟨⟨S,mem_inter.mpr ⟨(mem_inter.mp hS).1,hdom (mem_inter.mp hS).2⟩⟩, + by linarith,by linarith⟩ + +omit [PseudoMetricSpace Coord] in +lemma not_interior_ball {C δ : ℝ} (hC : 1 ≤ C) (hδ : 0 ≤ δ) + (A B : Record n) (hw : B.shell.width ≤ δ) : ¬A.Interior H X C δ B := by + rintro ⟨_,hl,hr⟩ + unfold RadialShell.width at hw + have := mul_le_mul_of_nonneg_right hC hδ + nlinarith + +end Record + +lemma labeled_empty (q : ℝ) : LabeledArrangement H G X q ∅ := by simp [LabeledArrangement] + +lemma labeled_subset {q : ℝ} {Z W : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) (hW : W ⊆ Z) : + LabeledArrangement H G X q W := + ⟨fun B hB => hZ.1 B (hW hB),fun _ hB _ hD hne => hZ.2 (hW hB) (hW hD) hne⟩ + +lemma labeled_pair {q : ℝ} {Z : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) {B D : Record n} + (hB : B ∈ Z) (hD : D ∈ Z) (hne : B ≠ D) : B.Compatible H X D := by + by_cases hh : Disjoint (B.shell.support X) (D.shell.support X) + · exact Or.inl hh + · exact Or.inr (hZ.2 hB hD hne hh) + +lemma labeled_union {q : ℝ} {Z W : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) (hW : LabeledArrangement H G X q W) + (hZW : ∀B ∈ Z, ∀D ∈ W, B.Compatible H X D) : + LabeledArrangement H G X q (Z∪W) := by + constructor + · intro B hB + exact (mem_union.mp hB).elim (hZ.1 B) (hW.1 B) + · intro B hB D hD hne hgeo + rcases mem_union.mp hB with hB | hB <;> rcases mem_union.mp hD with hD | hD + · exact hZ.2 hB hD hne hgeo + · exact (hZW B hB D hD).resolve_left hgeo + · exact (Record.compatible_symm H X (hZW D hD B hB)).resolve_left hgeo + · exact hW.2 hB hD hne hgeo + +lemma labeled_sets_disjoint (hX : ∀v, isProfile (X v)) {q : ℝ} {Z W : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) + (hZW : ∀B ∈ Z, ∀D ∈ W, B.Compatible H X D) : Disjoint Z W := by + rw [Finset.disjoint_left] + intro B hB hBW + exact B.compatible_self_iff H X hX (hZ.1 B hB).1 (hZ.1 B hB).2.2.1 (hZW B hB B hBW) + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) + +namespace Record + +def restriction (B : Record n) (a b : ℝ) : Record n := + {B with shell := RadialShell.hollow B.shell.center a b} + +def Refines (D B : Record n) : Prop := + D.shell.support X ⊆ B.shell.support X ∧ D.conflict H ⊆ B.conflict H + +lemma restriction_refines (B : Record n) {a b : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) : + (B.restriction a b).Refines H X B := + ⟨RadialShell.restriction_subset X B.shell ha hb,Subset.refl _⟩ + +lemma compatible_refinements {A B C D : Record n} + (hBD : B.Compatible H X D) (hAB : A.Refines H X B) (hCD : C.Refines H X D) : + A.Compatible H X C := by + have hh := compatible_heredity H X hBD hAB.1 hAB.2 + have hh' := compatible_heredity H X (compatible_symm H X hh) hCD.1 hCD.2 + exact compatible_symm H X hh' + +end Record + +lemma labeled_replace {q : ℝ} {Z W : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) (hW : LabeledArrangement H G X q W) + (B : Record n) (hcompat : ∀D ∈ Z.erase B, ∀A ∈ W, D.Compatible H X A) : + LabeledArrangement H G X q (Z.erase B∪W) := + labeled_union H G X (labeled_subset H G X hZ (erase_subset _ _)) hW hcompat + +lemma replacement_credit (hX : ∀v, isProfile (X v)) {q : ℝ} {Z W : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) {B : Record n} (hB : B ∈ Z) + (hcompat : ∀D ∈ Z.erase B, ∀A ∈ W, D.Compatible H X A) + (p : Record n → ℝ) {c : ℝ} (hcredit : p B+c ≤ ∑A ∈ W, p A) : + (∑D ∈ Z, p D)+c ≤ ∑D ∈ Z.erase B∪W, p D := by + have hdis := labeled_sets_disjoint H G X hX + (labeled_subset H G X hZ (erase_subset B Z)) hcompat + rw [sum_union hdis] + have hh := sum_erase_add Z p hB + linarith + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) + +namespace Record + +lemma compatible_ne (hX : ∀v, isProfile (X v)) {B D : Record n} + (hB : B.Shape H) (hval : B.shell.Valid X) (hBD : B.Compatible H X D) : B ≠ D := by + rintro rfl + exact B.compatible_self_iff H X hX hB hval hBD + +def phaseToken (F : Finset (Record n)) (δ ε : ℝ) (B : Record n) : ℝ := + if B ∈ F then AssignedAccounting.fresh δ ε else + AssignedAccounting.base B.avoided.isSome B.shell.width δ + +lemma restriction_not_fresh {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true) (B : Record n) (a b : ℝ) : + B.restriction a b ∉ F := by + intro hh + have hh' := hF _ hh + simp [restriction,RadialShell.hollow] at hh' + +lemma restriction_token {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true) (B : Record n) (a b δ ε : ℝ) : + phaseToken F δ ε (B.restriction a b) = + AssignedAccounting.base B.avoided.isSome (b-a) δ := by + rw [phaseToken,ite_eq_right (restriction_not_fresh hF B a b)] + rfl + +omit [PseudoMetricSpace Coord] in +lemma interior_width {δ : ℝ} {A B : Record n} (hh : A.Interior H X 256 δ B) : + 512*δ < B.shell.width := by + dsimp [RadialShell.width] + linarith [hh.2.1,hh.2.2] + +lemma interior_ball_subset {δ : ℝ} {A B : Record n} (hδ : 0 ≤ δ) + (hA : A.shell = RadialShell.ball A.shell.center δ) + (hh : A.Interior H X 256 δ B) : A.shell.support X ⊆ B.shell.support X := by + rw [hA] + apply RadialShell.ball_subset_of_radial_margin + · linarith [hh.2.1] + · linarith [hh.2.2] + +end Record + +lemma labeled_singleton {q : ℝ} {B : Record n} (hB : B.Valid H G X q) : + LabeledArrangement H G X q {B} := by + constructor + · intro A hA + simpa only [mem_singleton.mp hA] using hB + · intro A hA D hD hne + exact (hne ((mem_singleton.mp hA).trans (mem_singleton.mp hD).symm)).elim + +lemma labeled_insert {q : ℝ} {Z : Finset (Record n)} {B : Record n} + (hZ : LabeledArrangement H G X q Z) (hB : B.Valid H G X q) + (hcompat : ∀D ∈ Z, B.Compatible H X D) : + LabeledArrangement H G X q (insert B Z) := by + rw [← singleton_union] + apply labeled_union H G X (labeled_singleton H G X hB) hZ + intro A hA D hD + simpa only [mem_singleton.mp hA] using hcompat D hD + +lemma avoiding_operation (hX : ∀v, isProfile (X v)) + {q δ ε : ℝ} (hδ : 0 < δ) (hε : ε ≤ δ/1536) + {F Z : Finset (Record n)} (hF : ∀D ∈ F, + D.shell.ordinary = true ∧ D.avoided = none) + (hZ : LabeledArrangement H G X q Z) {A B : Record n} + (hA : A.Valid H G X q) (hAF : A ∈ F) + (hAball : A.shell = RadialShell.ball A.shell.center δ) + (hB : B ∈ Z) (havoid : B.avoided.isSome = true) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ A.excluded) + (hinter : A.Interior H X 256 δ B) : + ∃Z' : Finset (Record n), LabeledArrangement H G X q Z' ∧ + (∑D ∈ Z, Record.phaseToken F δ ε D)+AssignedAccounting.theta*δ ≤ + ∑D ∈ Z', Record.phaseToken F δ ε D ∧ + ∀D ∈ Z', D ∈ Z ∨ D = A ∨ ∃a b, D = B.restriction a b ∧ + B.shell.inner ≤ a ∧ b ≤ B.shell.outer ∧ a < b := by + let r := normDistance (X A.shell.center) (X B.shell.center) + let B₁ := B.restriction B.shell.inner (r-δ) + let B₂ := B.restriction (r+δ) B.shell.outer + have hbvalid := hZ.1 B hB + have h1a : B.shell.inner < r-δ := by dsimp [r]; linarith [hinter.2.1] + have h1b : r-δ ≤ B.shell.outer := by dsimp [r]; linarith [hinter.2.2] + have h2a : B.shell.inner ≤ r+δ := by dsimp [r]; linarith [hinter.2.1] + have h2b : r+δ < B.shell.outer := by dsimp [r]; linarith [hinter.2.2] + have hB₁ : B₁.Valid H G X q := Record.restrict_valid H G X hbvalid (le_refl _) h1b h1a + have hB₂ : B₂.Valid H G X q := Record.restrict_valid H G X hbvalid h2a (le_refl _) h2b + have h12 : B₁.Compatible H X B₂ := Or.inl + (RadialShell.concentric_disjoint X B.shell.center (by linarith : r-δ ≤ r+δ)) + have hA1 : A.Compatible H X B₁ := by + left + change Disjoint (A.shell.support X) ((RadialShell.hollow B.shell.center B.shell.inner (r-δ)).support X) + rw [hAball] + exact RadialShell.ball_disjoint_hollow_lower X _ _ (by dsimp [r]; linarith) + have hA2 : A.Compatible H X B₂ := by + left + change Disjoint (A.shell.support X) ((RadialShell.hollow B.shell.center (r+δ) B.shell.outer).support X) + rw [hAball] + exact RadialShell.ball_disjoint_hollow_upper X _ _ (le_refl _) + let W : Finset (Record n) := {A,B₁,B₂} + have hW : LabeledArrangement H G X q W := by + apply labeled_insert H G X + · apply labeled_insert H G X (labeled_singleton H G X hB₂) hB₁ + intro D hD + simpa only [mem_singleton.mp hD] using h12 + · exact hA + · intro D hD + rcases mem_insert.mp hD with rfl | hD + · exact hA1 + · simpa only [mem_singleton.mp hD] using hA2 + have hancestor : A.owner ∈ B.conflict H := + Record.candidate_ancestor H hA.1 hbvalid.1 (horder B hB) hinter.1 + have hcompat : ∀D ∈ Z.erase B, ∀C ∈ W, D.Compatible H X C := by + intro D hD C hC + obtain ⟨hDB,hDZ⟩ := mem_erase.mp hD + have hBC : B.Compatible H X D := labeled_pair H G X hZ hB hDZ hDB.symm + apply Record.compatible_symm H X + rcases mem_insert.mp hC with rfl | hC + · exact Record.insert_compatible H G X hZ hA.1 hB hDZ hDB.symm hancestor horder + (Record.interior_ball_subset H X hδ.le hAball hinter) + rcases mem_insert.mp hC with rfl | hC + · exact Record.compatible_heredity H X hBC + (B.restriction_refines H X (le_refl _) h1b).1 (Subset.refl _) + · have heq := mem_singleton.mp hC + subst C + exact Record.compatible_heredity H X hBC + (B.restriction_refines H X h2a (le_refl _)).1 (Subset.refl _) + have hBF : B ∉ F := by + intro hh + rw [(hF B hh).2] at havoid + simp at havoid + have hcredit : Record.phaseToken F δ ε B+AssignedAccounting.theta*δ ≤ + ∑D ∈ W, Record.phaseToken F δ ε D := by + have hne12 := Record.compatible_ne H X hX hB₁.1 hB₁.2.2.1 h12 + have hneA1 := Record.compatible_ne H X hX hA.1 hA.2.2.1 hA1 + have hneA2 := Record.compatible_ne H X hX hA.1 hA.2.2.1 hA2 + have hAnot : A ∉ ({B₁,B₂} : Finset (Record n)) := by simp [hneA1,hneA2] + have h1not : B₁ ∉ ({B₂} : Finset (Record n)) := by simpa using hne12 + dsimp [W] + rw [sum_insert hAnot,sum_insert h1not,sum_singleton] + rw [Record.phaseToken,ite_eq_right hBF,havoid] + rw [show Record.phaseToken F δ ε A = AssignedAccounting.fresh δ ε by simp [Record.phaseToken,hAF]] + rw [Record.restriction_token (fun D hD => (hF D hD).1) B, + Record.restriction_token (fun D hD => (hF D hD).1) B,havoid] + have hh := AssignedAccounting.avoiding_carve hδ.le hε + (Record.interior_width H X hinter).le + (show (r-δ-B.shell.inner)+(B.shell.outer-(r+δ))=B.shell.width-2*δ by + dsimp [RadialShell.width]; ring) + linarith + refine ⟨Z.erase B∪W,labeled_replace H G X hZ hW B hcompat, + replacement_credit H G X hX hZ hB hcompat _ hcredit,?_⟩ + intro D hD + rcases mem_union.mp hD with hD | hD + · exact Or.inl (mem_of_mem_erase hD) + right + rcases mem_insert.mp hD with rfl | hD + · exact Or.inl rfl + right + rcases mem_insert.mp hD with rfl | hD + · exact ⟨B.shell.inner,r-δ,rfl,le_refl _,h1b,h1a⟩ + · have heq := mem_singleton.mp hD + exact ⟨r+δ,B.shell.outer,heq,h2a,le_refl _,h2b⟩ + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) + +namespace Record + +def restrictionSet (B : Record n) (a b : ℝ) : Finset (Record n) := + if a < b then {B.restriction a b} else ∅ + +lemma mem_restrictionSet {B D : Record n} {a b : ℝ} : + D ∈ B.restrictionSet a b ↔ a < b ∧ D = B.restriction a b := by + by_cases hh : a < b <;> simp [restrictionSet,hh] + +lemma restrictionSet_valid {q a b : ℝ} {B : Record n} (hB : B.Valid H G X q) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) : + LabeledArrangement H G X q (B.restrictionSet a b) := by + by_cases hab : a < b + · rw [restrictionSet,ite_eq_left hab] + exact labeled_singleton H G X (restrict_valid H G X hB ha hb hab) + · rw [restrictionSet,ite_eq_right hab] + exact labeled_empty H G X q + +lemma restrictionSet_refines {B D : Record n} {a b : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hD : D ∈ B.restrictionSet a b) : D.Refines H X B := by + obtain ⟨hab,rfl⟩ := mem_restrictionSet.mp hD + exact B.restriction_refines H X ha hb + +lemma restrictionSet_token {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true) (B : Record n) (a b : ℝ) + {δ ε : ℝ} (hδ : 0 ≤ δ) : + (∑D ∈ B.restrictionSet a b, phaseToken F δ ε D) = + AssignedAccounting.base B.avoided.isSome (b-a) δ := by + by_cases hab : a < b + · rw [restrictionSet,ite_eq_left hab,sum_singleton,restriction_token hF] + · rw [restrictionSet,ite_eq_right hab,sum_empty,AssignedAccounting.base_discard _ (by linarith) hδ] + +lemma restrictions_compatible (B : Record n) {a b c d : ℝ} (hbc : b ≤ c) + {D E : Record n} (hD : D ∈ B.restrictionSet a b) (hE : E ∈ B.restrictionSet c d) : + D.Compatible H X E := by + obtain ⟨_,rfl⟩ := mem_restrictionSet.mp hD + obtain ⟨_,rfl⟩ := mem_restrictionSet.mp hE + exact Or.inl (RadialShell.concentric_disjoint X B.shell.center hbc) + +end Record + +lemma dense_operation (hX : ∀v, isProfile (X v)) + {q δ ε a b : ℝ} (hδ : 0 < δ) (hε : ε ≤ δ/1536) + {F Z M : Finset (Record n)} (hF : ∀D ∈ F, + D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hZ : LabeledArrangement H G X q Z) {B : Record n} (hB : B ∈ Z) + (hMZ : LabeledArrangement H G X q M) (hMF : M ⊆ F) + (hMball : ∀A ∈ M, A.shell = RadialShell.ball A.shell.center δ) + (hno : B.avoided = none) (hwidth : 512*δ < B.shell.width) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) (hab : a ≤ b) + (hrange : ∀A ∈ M, a-δ < normDistance (X A.shell.center) (X B.shell.center) ∧ + normDistance (X A.shell.center) (X B.shell.center) < b+δ) + (hinter : ∀A ∈ M, A.Interior H X 256 δ B) + (horder : ∀A ∈ M, ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ A.excluded) + (hcount : 765*δ ≤ (M.card : ℝ)*δ) (hdense : 3*(b-a) ≤ (M.card : ℝ)*δ) : + ∃Z' : Finset (Record n), LabeledArrangement H G X q Z' ∧ + (∑D ∈ Z, Record.phaseToken F δ ε D)+AssignedAccounting.theta*(M.card : ℝ)*δ ≤ + ∑D ∈ Z', Record.phaseToken F δ ε D ∧ + ∀D ∈ Z', D ∈ Z ∨ D ∈ M ∨ ∃c d, D = B.restriction c d ∧ + B.shell.inner ≤ c ∧ d ≤ B.shell.outer ∧ c < d := by + let W₁ := B.restrictionSet B.shell.inner (a-2*δ) + let W₂ := B.restrictionSet (b+2*δ) B.shell.outer + let W := W₁∪W₂∪M + have hbvalid := hZ.1 B hB + have h1b : a-2*δ ≤ B.shell.outer := by linarith + have h2a : B.shell.inner ≤ b+2*δ := by linarith + have hW₁ : LabeledArrangement H G X q W₁ := + B.restrictionSet_valid H G X hbvalid (le_refl _) h1b + have hW₂ : LabeledArrangement H G X q W₂ := + B.restrictionSet_valid H G X hbvalid h2a (le_refl _) + have h12 : ∀D ∈ W₁, ∀E ∈ W₂, D.Compatible H X E := by + intro D hD E hE + exact B.restrictions_compatible H X (by linarith : a-2*δ ≤ b+2*δ) hD hE + have hWM : ∀D ∈ W₁∪W₂, ∀A ∈ M, D.Compatible H X A := by + intro D hD A hAM + apply Record.compatible_symm H X + left + rw [hMball A hAM] + rcases mem_union.mp hD with hD | hD + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hD + exact RadialShell.ball_disjoint_hollow_lower X _ _ (by linarith [(hrange A hAM).1]) + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hD + exact RadialShell.ball_disjoint_hollow_upper X _ _ (by linarith [(hrange A hAM).2]) + have hW12 := labeled_union H G X hW₁ hW₂ h12 + have hW : LabeledArrangement H G X q W := labeled_union H G X hW12 hMZ hWM + have hcompat : ∀D ∈ Z.erase B, ∀C ∈ W, D.Compatible H X C := by + intro D hD C hC + obtain ⟨hDB,hDZ⟩ := mem_erase.mp hD + have hBD := labeled_pair H G X hZ hB hDZ hDB.symm + apply Record.compatible_symm H X + rcases mem_union.mp hC with hC | hC + · rcases mem_union.mp hC with hC | hC + · have hh := B.restrictionSet_refines H X (le_refl _) h1b hC + exact Record.compatible_heredity H X hBD hh.1 hh.2 + · have hh := B.restrictionSet_refines H X h2a (le_refl _) hC + exact Record.compatible_heredity H X hBD hh.1 hh.2 + · have hancestor := Record.candidate_ancestor H (hMZ.1 C hC).1 hbvalid.1 + (horder C hC B hB) (hinter C hC).1 + exact Record.insert_compatible H G X hZ (hMZ.1 C hC).1 hB hDZ hDB.symm hancestor + (horder C hC) (Record.interior_ball_subset H X hδ.le (hMball C hC) (hinter C hC)) + have hBF : B ∉ F := by + intro hh + rw [(hF B hh).2.1] at hwidth + linarith + have hcredit : Record.phaseToken F δ ε B+AssignedAccounting.theta*(M.card : ℝ)*δ ≤ + ∑D ∈ W, Record.phaseToken F δ ε D := by + have hd12 := labeled_sets_disjoint H G X hX hW₁ h12 + have hdM := labeled_sets_disjoint H G X hX hW12 hWM + dsimp only [W] + rw [sum_union hdM,sum_union hd12, + Record.restrictionSet_token (fun D hD => (hF D hD).1) B _ _ hδ.le, + Record.restrictionSet_token (fun D hD => (hF D hD).1) B _ _ hδ.le] + have hsumM : (∑D ∈ M, Record.phaseToken F δ ε D) = + (M.card : ℝ)*AssignedAccounting.fresh δ ε := by + calc + _ = ∑D ∈ M, AssignedAccounting.fresh δ ε := sum_congr rfl (fun D hD => by + simp only [Record.phaseToken,ite_eq_left (hMF hD)]) + _ = _ := by simp + rw [hsumM,Record.phaseToken,ite_eq_right hBF,hno,Option.isSome_none] + exact AssignedAccounting.dense_carve hδ.le hε (Nat.cast_nonneg _) hwidth.le + (by dsimp [RadialShell.width]; ring) hdense hcount + refine ⟨Z.erase B∪W,labeled_replace H G X hZ hW B hcompat, + replacement_credit H G X hX hZ hB hcompat _ hcredit,?_⟩ + intro D hD + rcases mem_union.mp hD with hD | hD + · exact Or.inl (mem_of_mem_erase hD) + right + rcases mem_union.mp hD with hD | hD + · right + rcases mem_union.mp hD with hD | hD + · obtain ⟨hpos,heq⟩ := Record.mem_restrictionSet.mp hD + exact ⟨B.shell.inner,a-2*δ,heq,le_refl _,h1b,hpos⟩ + · obtain ⟨hpos,heq⟩ := Record.mem_restrictionSet.mp hD + exact ⟨b+2*δ,B.shell.outer,heq,h2a,le_refl _,hpos⟩ + · exact Or.inl hD + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) + +namespace Record + +lemma central_refines {B : Record n} (hshape : B.Shape H) (hno : B.avoided = none) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) {a b c d : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hc : B.shell.inner ≤ c) (hd : d ≤ B.shell.outer) : + (B.innerRecord t a b).Refines H X B ∧ (B.outsideRecord t c d).Refines H X B := by + obtain ⟨h1,h2⟩ := central_conflict H hshape hno ht a b c d + exact ⟨⟨RadialShell.restriction_subset X B.shell ha hb,h1 ▸ filter_subset _ _⟩, + ⟨RadialShell.restriction_subset X B.shell hc hd,h2 ▸ filter_subset _ _⟩⟩ + +lemma hollow_token {F : Finset (Record n)} (hF : ∀D ∈ F, D.shell.ordinary = true) + {B : Record n} (hB : B.shell.ordinary = false) (δ ε : ℝ) : + phaseToken F δ ε B = AssignedAccounting.base B.avoided.isSome B.shell.width δ := by + rw [phaseToken,ite_eq_right] + intro hh + have := hF B hh + simp [hB] at this + +end Record + +lemma sparse_operation (hX : ∀v, isProfile (X v)) + {q δ ε a b M : ℝ} (hδ : 0 < δ) + {F Z : Finset (Record n)} (hF : ∀D ∈ F, + D.shell.ordinary = true ∧ D.shell.width = δ) + (hZ : LabeledArrangement H G X q Z) {B : Record n} (hB : B ∈ Z) + (hno : B.avoided = none) (hwidth : 512*δ < B.shell.width) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hwide : 255*δ ≤ b-a) (hsparse : M*δ ≤ 3*(b-a)) + (hinner : (B.innerRecord t (a+δ) (b-δ)).Valid H G X q) + (houter : (B.outsideRecord t a b).Valid H G X q) : + ∃Z' : Finset (Record n), LabeledArrangement H G X q Z' ∧ + (∑D ∈ Z, Record.phaseToken F δ ε D)+AssignedAccounting.theta*M*δ ≤ + ∑D ∈ Z', Record.phaseToken F δ ε D ∧ + ∀D ∈ Z', D ∈ Z ∨ D = B.innerRecord t (a+δ) (b-δ) ∨ + D = B.outsideRecord t a b ∨ ∃c d, D = B.restriction c d ∧ + B.shell.inner ≤ c ∧ d ≤ B.shell.outer ∧ c < d := by + let C := B.innerRecord t (a+δ) (b-δ) + let D := B.outsideRecord t a b + let W₁ := B.restrictionSet B.shell.inner a + let W₂ := B.restrictionSet b B.shell.outer + let W₀ := W₁∪W₂ + let W₃ := insert C W₀ + let W := insert D W₃ + have hab : a ≤ b := by linarith + have hv := hZ.1 B hB + have hW₁ : LabeledArrangement H G X q W₁ := + Record.restrictionSet_valid H G X hv (le_refl _) (hab.trans hb) + have hW₂ : LabeledArrangement H G X q W₂ := + Record.restrictionSet_valid H G X hv (ha.trans hab) (le_refl _) + have h12 : ∀E ∈ W₁, ∀J ∈ W₂, E.Compatible H X J := by + intro E hE J hJ + exact Record.restrictions_compatible H X B hab hE hJ + have hW₀ : LabeledArrangement H G X q W₀ := labeled_union H G X hW₁ hW₂ h12 + have hC0 : ∀E ∈ W₀, C.Compatible H X E := by + intro E hE + rcases mem_union.mp hE with hE | hE + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hE + exact Or.inl ((RadialShell.concentric_disjoint X B.shell.center (by linarith : a ≤ a+δ)).symm) + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hE + exact Or.inl (RadialShell.concentric_disjoint X B.shell.center (by linarith : b-δ ≤ b)) + have hW₃ : LabeledArrangement H G X q W₃ := labeled_insert H G X hW₀ hinner hC0 + have hD3 : ∀E ∈ W₃, D.Compatible H X E := by + intro E hE + rcases mem_insert.mp hE with rfl | hE + · exact Or.inr (Record.central_domain_disjoint H hv.1 hno ht (a+δ) (b-δ) a b).symm + rcases mem_union.mp hE with hE | hE + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hE + exact Or.inl ((RadialShell.concentric_disjoint X B.shell.center (le_refl a)).symm) + · obtain ⟨_,rfl⟩ := Record.mem_restrictionSet.mp hE + exact Or.inl (RadialShell.concentric_disjoint X B.shell.center (le_refl b)) + have hW : LabeledArrangement H G X q W := labeled_insert H G X hW₃ houter hD3 + have hCD := Record.central_refines H X hv.1 hno ht + (show B.shell.inner ≤ a+δ by linarith) (show b-δ ≤ B.shell.outer by linarith) ha hb + have hWB : ∀E ∈ W, E.Refines H X B := by + intro E hE + rcases mem_insert.mp hE with rfl | hE + · exact hCD.2 + rcases mem_insert.mp hE with rfl | hE + · exact hCD.1 + rcases mem_union.mp hE with hE | hE + · exact Record.restrictionSet_refines H X (le_refl _) (hab.trans hb) hE + · exact Record.restrictionSet_refines H X (ha.trans hab) (le_refl _) hE + have hcompat : ∀J ∈ Z.erase B, ∀E ∈ W, J.Compatible H X E := by + intro J hJ E hE + obtain ⟨hne,hJ⟩ := mem_erase.mp hJ + exact Record.compatible_symm H X (Record.compatible_heredity H X + (labeled_pair H G X hZ hB hJ hne.symm) (hWB E hE).1 (hWB E hE).2) + have hBF : B ∉ F := by + intro hh + rw [(hF B hh).2] at hwidth + linarith + have hDC : D ∉ W₃ := by + intro hh + exact Record.compatible_self_iff H X D hX houter.1 houter.2.2.1 (hD3 D hh) + have hCW : C ∉ W₀ := by + intro hh + exact Record.compatible_self_iff H X C hX hinner.1 hinner.2.2.1 (hC0 C hh) + have hcredit : Record.phaseToken F δ ε B+AssignedAccounting.theta*M*δ ≤ + ∑E ∈ W, Record.phaseToken F δ ε E := by + have hdis := labeled_sets_disjoint H G X hX hW₁ h12 + change _ ≤ ∑E ∈ insert D W₃, _ + rw [sum_insert hDC] + change _ ≤ _+(∑E ∈ insert C W₀, _) + rw [sum_insert hCW] + change _ ≤ _+(_+(∑E ∈ W₁∪W₂, _)) + rw [sum_union hdis, + Record.restrictionSet_token (fun D hD => (hF D hD).1) B _ _ hδ.le, + Record.restrictionSet_token (fun D hD => (hF D hD).1) B _ _ hδ.le, + Record.hollow_token (fun D hD => (hF D hD).1) (show D.shell.ordinary = false from rfl), + Record.hollow_token (fun D hD => (hF D hD).1) (show C.shell.ordinary = false from rfl), + Record.phaseToken,ite_eq_right hBF] + simp only [D,C,Record.innerRecord,Record.outsideRecord,RadialShell.hollow, + hno,Option.isSome_none,Option.isSome_some,RadialShell.width] + have hh := AssignedAccounting.sparse_carve hδ.le hwidth.le + (R₁ := a-B.shell.inner) (R₂ := B.shell.outer-b) (L := b-a) + (by dsimp [RadialShell.width]; ring) hwide hsparse + rw [show b-δ-(a+δ) = b-a-2*δ by ring] + dsimp only [RadialShell.width] at hh + linarith + refine ⟨Z.erase B∪W,labeled_replace H G X hZ hW B hcompat, + replacement_credit H G X hX hZ hB hcompat _ hcredit,?_⟩ + intro E hE + rcases mem_union.mp hE with hE | hE + · exact Or.inl (mem_of_mem_erase hE) + right + rcases mem_insert.mp hE with heq | hE + · exact Or.inr (Or.inl heq) + rcases mem_insert.mp hE with heq | hE + · exact Or.inl heq + right; right + rcases mem_union.mp hE with hE | hE + · obtain ⟨hpos,heq⟩ := Record.mem_restrictionSet.mp hE + exact ⟨B.shell.inner,a,heq,le_refl _,hab.trans hb,hpos⟩ + · obtain ⟨hpos,heq⟩ := Record.mem_restrictionSet.mp hE + exact ⟨b,B.shell.outer,heq,ha.trans hab,le_refl _,hpos⟩ + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} + +namespace AssignedBag + +lemma neighbor_exists (A : AssignedBag H G X δ η) {u : Fin n} (hu : u ∈ A.centers) : + ∃v ∈ H.parent A.owner\A.owner, normDistance (X u) (X v) < δ ∧ + ∃e : Fin m, (G.left e = u ∧ G.right e = v) ∨ + (G.left e = v ∧ G.right e = u) := by + obtain ⟨huT,e,he,heu,hlen⟩ := A.endpoint u hu + obtain ⟨heP,heT⟩ := mem_filter.mp he + obtain ⟨hlP,hrP⟩ := (G.mem_inducedEdges _ _).mp heP + rcases heu with heu | heu + · have hrT : G.right e ∉ A.owner := by + rcases heT with hh | hh + · exact hh.2 + · exact (hh.2 (heu.symm ▸ huT)).elim + refine ⟨G.right e,mem_sdiff.mpr ⟨hrP,hrT⟩,?_,e,Or.inl ⟨heu,rfl⟩⟩ + simpa only [heu] using hlen + · have hlT : G.left e ∉ A.owner := by + rcases heT with hh | hh + · exact (hh.2 (heu.symm ▸ huT)).elim + · exact hh.2 + refine ⟨G.left e,mem_sdiff.mpr ⟨hlP,hlT⟩,?_,e,Or.inr ⟨rfl,heu⟩⟩ + simpa only [heu,normDistance_comm] using hlen + +def neighbor (A : AssignedBag H G X δ η) (u : Fin n) : Fin n := + if hu : u ∈ A.centers then (A.neighbor_exists hu).choose else u + +lemma neighbor_spec (A : AssignedBag H G X δ η) {u : Fin n} (hu : u ∈ A.centers) : + A.neighbor u ∈ H.parent A.owner\A.owner ∧ + normDistance (X u) (X (A.neighbor u)) < δ ∧ + ∃e : Fin m, (G.left e = u ∧ G.right e = A.neighbor u) ∨ + (G.left e = A.neighbor u ∧ G.right e = u) := by + simpa only [neighbor,dite_eq_left hu] using (A.neighbor_exists hu).choose_spec + +lemma input_injective (A : AssignedBag H G X δ η) (P : Finset (Finset (Fin n))) : + Function.Injective (A.input P) := by + intro u v hh + exact congrArg (fun B : Record n => B.shell.center) hh + +lemma input_arrangement (A : AssignedBag H G X δ η) {q : ℝ} + {P : Finset (Finset (Fin n))} {U : Finset (Fin n)} (hU : U ⊆ A.centers) + (hvalid : ∀u ∈ U, (A.input P u).Valid H G X q) : + LabeledArrangement H G X q (U.image (A.input P)) := by + constructor + · intro B hB + obtain ⟨u,hu,rfl⟩ := mem_image.mp hB + exact hvalid u hu + · intro B hB D hD hne hgeo + obtain ⟨u,hu,rfl⟩ := mem_image.mp hB + obtain ⟨v,hv,rfl⟩ := mem_image.mp hD + exact (hgeo (A.disjoint (hU hu) (hU hv) (fun hh => hne (congrArg (A.input P) hh)))).elim + +end AssignedBag + +namespace Record + +lemma unique_interior (_hX : ∀v, isProfile (X v)) {q : ℝ} + {Z : Finset (Record n)} (hZ : LabeledArrangement H G X q Z) + {A B D : Record n} (hA : A.Shape H) (hB : B ∈ Z) (hD : D ∈ Z) + (horder : ∀E ∈ Z, E.owner ⊂ A.owner → E.owner ∈ A.excluded) + (hAB : (A.conflict H ∩ B.conflict H).Nonempty) + (hAD : (A.conflict H ∩ D.conflict H).Nonempty) + (hsub : A.shell.support X ⊆ D.shell.support X) + (hmeet : ¬Disjoint (A.shell.support X) (B.shell.support X)) : B = D := by + by_contra hne + have hba := candidate_ancestor H hA (hZ.1 B hB).1 (horder B hB) hAB + have hda := candidate_ancestor H hA (hZ.1 D hD).1 (horder D hD) hAD + rcases labeled_pair H G X hZ hB hD hne with hh | hh + · exact hmeet ((hh.symm).mono_left hsub) + · exact Finset.disjoint_left.mp hh hba hda + +lemma strict_owner_of_interior (hX : ∀v, isProfile (X v)) + {A B : Record n} (hA : A.Shape H) (hB : B.Shape H) + (hAv : A.shell.Valid X) (hδ : 0 ≤ δ) + (hball : A.shell = RadialShell.ball A.shell.center δ) + (horder : B.owner ⊂ A.owner → B.owner ∈ A.excluded) + (hsep : B.owner = A.owner → Disjoint (A.shell.support X) (B.shell.support X)) + (hinter : A.Interior H X 256 δ B) : A.owner ⊂ B.owner := by + have hanc := candidate_ancestor H hA hB horder hinter.1 + have hsub := (H.mem_domain.mp hanc).2.1 + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨hsub,?_⟩ + intro hh + obtain ⟨z,hz⟩ := RadialShell.valid_support_nonempty hX hAv + exact Set.disjoint_left.mp (hsep hh.symm) hz + (interior_ball_subset H X hδ hball hinter hz) + +end Record +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma large_component (A : AssignedBag H G X δ η) {q : ℝ} + (hq : 0 < q) (hconn : LocallyConnectedReal H G q) (hη : 3072/q ≤ η) + {U : Finset (Fin n)} (hU : U ⊆ A.centers) (hhalf : A.centers.card ≤ 2*U.card) : + ∃R : Finset (Fin n), R ⊆ H.parent A.owner\A.owner ∧ + G.EdgeConnectedReal R (q/4) ∧ 768 ≤ (U.filter (fun u => A.neighbor u ∈ R)).card := by + obtain ⟨J,hJ,hJc,hcount⟩ := G.outside_connected_partition hq + (hconn (H.parent A.owner) (H.parent_mem A.owner A.owner_mem A.nonroot)) + (H.nonempty A.owner A.owner_mem) (H.parent_strict A.owner A.owner_mem A.nonroot) + have hJn : J.Nonempty := by + have hout : (H.parent A.owner\A.owner).Nonempty := + sdiff_nonempty.mpr (H.parent_strict A.owner A.owner_mem A.nonroot).not_subset + rw [← hJ.2.2] at hout + obtain ⟨R,hR,_⟩ := biUnion_nonempty.mp hout + exact ⟨R,hR⟩ + have hcover : ∀u ∈ U, ∃R ∈ J, A.neighbor u ∈ R := by + intro u hu + have hh := (A.neighbor_spec (hU hu)).1 + rw [← hJ.2.2] at hh + simpa only [mem_biUnion,id_eq] using hh + have hb := parent_boundary_lower H G hconn A.owner_mem A.nonroot + have hηq : 3072 ≤ η*q := (div_le_iff₀ hq).mp hη + have hsum := mul_le_mul_of_nonneg_right A.assignment hq.le + have hmass := mul_le_mul_of_nonneg_right hηq + (Nat.cast_nonneg (parentBoundary H G A.owner).card : (0:ℝ) ≤ _) + have hhalf' : (A.centers.card : ℝ) ≤ 2*(U.card : ℝ) := by exact_mod_cast hhalf + have hmul := mul_le_mul_of_nonneg_left hhalf' hq.le + obtain ⟨R,hR,hlarge⟩ := AssignedSelection.large_neighbor_class U J + (fun u R => A.neighbor u ∈ R) hJn hcover hq (lt_of_lt_of_le hq hb) + (by simpa [mul_comm,parentBoundary] using hcount) + (by nlinarith) + exact ⟨R,(hJ.1 R hR).2,hJc R hR,hlarge⟩ + +lemma selected_interior (A : AssignedBag H G X δ η) (hX : ∀v, isProfile (X v)) + {q : ℝ} {P : Finset (Finset (Fin n))} {U : Finset (Fin n)} + {Z : Finset (Record n)} (hZ : LabeledArrangement H G X q Z) + (hshape : ∀u ∈ U, (A.input P u).Shape H) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hinter : ∀u ∈ U, ∃D ∈ Z, (A.input P u).Interior H X 256 δ D) + {B : Record n} (hB : B ∈ Z) {u₀ : Fin n} + (hint₀ : (A.input P u₀).Interior H X 256 δ B) + {a b : ℝ} (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + {u : Fin n} (hu : u ∈ U) + (hr : a-δ < normDistance (X u) (X B.shell.center) ∧ + normDistance (X u) (X B.shell.center) < b+δ) : + (A.input P u).Interior H X 256 δ B := by + obtain ⟨D,hD,hintD⟩ := hinter u hu + have hconf : ((A.input P u).conflict H ∩ B.conflict H).Nonempty := hint₀.1 + have hmeet : ¬Disjoint ((A.input P u).shell.support X) (B.shell.support X) := + RadialShell.ball_meets_radial hX (hZ.1 B hB).2.2.1 u A.radius_pos + (by linarith [hr.1]) (by linarith [hr.2]) + have heq : B = D := Record.unique_interior hX hZ (hshape u hu) hB hD + (fun E hE hsub => by simpa [input,Record.excluded] using horder E hE hsub) + hconf hintD.1 (Record.interior_ball_subset H X A.radius_pos.le rfl hintD) hmeet + exact heq.symm ▸ hintD + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma radial_group (A : AssignedBag H G X δ η) (hX : ∀v, isProfile (X v)) + {q : ℝ} {P : Finset (Finset (Fin n))} {U : Finset (Fin n)} + (hU : U ⊆ A.centers) {Z : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) + (hshape : ∀u ∈ U, (A.input P u).Shape H) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hinter : ∀u ∈ U, ∃D ∈ Z, (A.input P u).Interior H X 256 δ D) + (hno : ∀u ∈ U, ∀D ∈ Z, (A.input P u).Interior H X 256 δ D → D.avoided = none) + {R : Finset (Fin n)} (hlarge : 768 ≤ (U.filter (fun u => A.neighbor u ∈ R)).card) : + ∃(B : Record n) (a b : ℝ) (M : Finset (Fin n)) (u₁ u₂ : Fin n), + B ∈ Z ∧ B.avoided = none ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer ∧ a ≤ b ∧ + M.Nonempty ∧ M = U.filter (fun u => a-δ < normDistance (X u) (X B.shell.center) ∧ + normDistance (X u) (X B.shell.center) < b+δ) ∧ + (∀u ∈ M, (A.input P u).Interior H X 256 δ B) ∧ + (768 ≤ M.card ∨ 255*δ ≤ b-a) ∧ + u₁ ∈ U ∧ u₂ ∈ U ∧ A.neighbor u₁ ∈ R ∧ A.neighbor u₂ ∈ R ∧ + normDistance (X (A.neighbor u₁)) (X B.shell.center) ≤ a ∧ + b ≤ normDistance (X (A.neighbor u₂)) (X B.shell.center) ∧ + normDistance (X u₁) (X B.shell.center) ≤ a+δ ∧ + b-δ ≤ normDistance (X u₂) (X B.shell.center) := by + let K := U.filter (fun u => A.neighbor u ∈ R) + have hKn : K.Nonempty := card_pos.mp (lt_of_lt_of_le (by norm_num : 0<768) hlarge) + obtain ⟨u₀,hu₀⟩ := hKn + obtain ⟨B,hB,hint₀⟩ := hinter u₀ (mem_filter.mp hu₀).1 + let ρ := fun u => normDistance (X u) (X B.shell.center) + obtain ⟨u₁,hu₁,hmin⟩ := K.exists_min_image (fun u => ρ (A.neighbor u)) ⟨u₀,hu₀⟩ + obtain ⟨u₂,hu₂,hmax⟩ := K.exists_max_image (fun u => ρ (A.neighbor u)) ⟨u₀,hu₀⟩ + let a := max B.shell.inner (ρ (A.neighbor u₁)) + let b := min B.shell.outer (ρ (A.neighbor u₂)) + let M := U.filter (fun u => a-δ < ρ u ∧ ρ u < b+δ) + have hnear (u : Fin n) (hu : u ∈ U) : |ρ u - ρ (A.neighbor u)| < δ := + (normDistance_reverse _ _ _).trans_lt (A.neighbor_spec (hU hu)).2.1 + have hr₀ := AssignedSelection.interior_neighbor_in_range A.radius_pos (hmin u₀ hu₀) (hmax u₀ hu₀) + hint₀.2.1 hint₀.2.2 (hnear u₀ (mem_filter.mp hu₀).1) + have hMn : M.Nonempty := ⟨u₀,mem_filter.mpr ⟨(mem_filter.mp hu₀).1,hr₀.2⟩⟩ + have hMinter : ∀u ∈ M, (A.input P u).Interior H X 256 δ B := by + intro u hu + obtain ⟨hu,hr⟩ := mem_filter.mp hu + exact A.selected_interior hX hZ hshape horder hinter hB hint₀ + (le_max_left _ _) (min_le_left _ _) hu hr + have hdich : 768 ≤ M.card ∨ 255*δ ≤ b-a := by + by_cases hs : K ⊆ M + · exact Or.inl (hlarge.trans (card_le_card hs)) + · obtain ⟨u,hu,huM⟩ := Finset.not_subset.mp hs + have hr : ¬(a-δ < ρ u ∧ ρ u < b+δ) := + fun hh => huM (mem_filter.mpr ⟨(mem_filter.mp hu).1,hh⟩) + exact Or.inr (AssignedSelection.radial_range A.radius_pos (hmin u₀ hu₀) (hmax u₀ hu₀) + hint₀.2.1 hint₀.2.2 (hnear u₀ (mem_filter.mp hu₀).1) + (hmin u hu) (hmax u hu) (hnear u (mem_filter.mp hu).1) hr) + have hnear₁ := (abs_lt.mp (hnear u₁ (mem_filter.mp hu₁).1)).2 + have hnear₂ := (abs_lt.mp (hnear u₂ (mem_filter.mp hu₂).1)).1 + refine ⟨B,a,b,M,u₁,u₂,hB,hno u₀ (mem_filter.mp hu₀).1 B hB hint₀, + le_max_left _ _,min_le_left _ _,hr₀.1,hMn,rfl,hMinter,hdich, + (mem_filter.mp hu₁).1,(mem_filter.mp hu₂).1,(mem_filter.mp hu₁).2,(mem_filter.mp hu₂).2, + le_max_right _ _,min_le_right _ _,?_,?_⟩ + · change ρ u₁ ≤ a+δ + have hh : ρ (A.neighbor u₁) ≤ a := le_max_right _ _ + linarith + · change b-δ ≤ ρ u₂ + have hh : b ≤ ρ (A.neighbor u₂) := min_le_right _ _ + linarith + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} + +namespace Record + +def RadialRefines (D B : Record n) : Prop := + D.shell.center = B.shell.center ∧ B.shell.inner ≤ D.shell.inner ∧ + D.shell.outer ≤ B.shell.outer ∧ D.conflict H ⊆ B.conflict H + +lemma radialRefines_refl (B : Record n) : B.RadialRefines (H := H) B := + ⟨rfl,le_refl _,le_refl _,Subset.refl _⟩ + +lemma restriction_radialRefines (B : Record n) {a b : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) : + (B.restriction a b).RadialRefines (H := H) B := ⟨rfl,ha,hb,Subset.refl _⟩ + +lemma central_radialRefines {B : Record n} (hB : B.Shape H) (hno : B.avoided = none) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) {a b c d : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hc : B.shell.inner ≤ c) (hd : d ≤ B.shell.outer) : + (B.innerRecord t a b).RadialRefines (H := H) B ∧ + (B.outsideRecord t c d).RadialRefines (H := H) B := by + obtain ⟨h1,h2⟩ := central_conflict H hB hno ht a b c d + refine ⟨⟨rfl,ha,hb,?_⟩,⟨rfl,hc,hd,?_⟩⟩ + · rw [h1]; exact filter_subset _ _ + · rw [h2]; exact filter_subset _ _ + +def InteriorTo (δ : ℝ) (Z : Finset (Record n)) (A : Record n) : Prop := + ∃B ∈ Z, A.Interior H X 256 δ B + +end Record + +def Evolution (F Z Z' : Finset (Record n)) : Prop := + ∀D ∈ Z', D ∈ F ∨ ∃B ∈ Z, D.RadialRefines (H := H) B + +def OwnerEvolution (t : Finset (Fin n)) (Z Z' : Finset (Record n)) : Prop := + ∀D ∈ Z', D.owner = t ∨ ∃B ∈ Z, D.owner = B.owner + +omit [PseudoMetricSpace Coord] in +lemma evolution_interior {δ : ℝ} (hδ : 0 ≤ δ) + {F Z Z' : Finset (Record n)} (hF : ∀D ∈ F, D.shell.width = δ) + (hevol : Evolution (H := H) F Z Z') {A : Record n} + (hh : A.InteriorTo (H := H) (X := X) δ Z') : A.InteriorTo (H := H) (X := X) δ Z := by + obtain ⟨D,hD,hint⟩ := hh + rcases hevol D hD with hD | ⟨B,hB,href⟩ + · exact (Record.not_interior_ball H X (by norm_num : (1:ℝ) ≤ 256) hδ A D + (hF D hD).le hint).elim + · exact ⟨B,hB,Record.interior_restriction H X href.1 href.2.1 href.2.2.1 href.2.2.2 hint⟩ + +lemma ownerEvolution_order {t : Finset (Fin n)} {P : Finset (Finset (Fin n))} + {Z Z' : Finset (Record n)} (hold : ∀B ∈ Z, B.owner ⊂ t → B.owner ∈ P) + (hevol : OwnerEvolution t Z Z') : ∀B ∈ Z', B.owner ⊂ t → B.owner ∈ P := by + intro B hB hs + rcases hevol B hB with hh | ⟨D,hD,hh⟩ + · exact (hs.ne hh).elim + · rw [hh] at hs ⊢ + exact hold D hD hs + +namespace AssignedBag +variable {δ η : ℝ} (A : AssignedBag H G X δ η) + +def SameOwnerSeparated (P : Finset (Finset (Fin n))) (U : Finset (Fin n)) + (Z : Finset (Record n)) : Prop := + ∀u ∈ U, (A.input P u).InteriorTo (H := H) (X := X) δ Z → + ∀B ∈ Z, B.owner = A.owner → + Disjoint ((RadialShell.ball u δ).support X) (B.shell.support X) + +lemma metadata_evolution {F Z Z' Q : Finset (Record n)} + (hQ : ∀D ∈ Q, D ∈ F ∨ ∃B ∈ Z, D.RadialRefines (H := H) B) + (hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃B ∈ Z, ∃a b, + D = B.restriction a b ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer) : + Evolution (H := H) F Z Z' := by + intro D hD + rcases hmeta D hD with hD | hD | ⟨B,hB,a,b,rfl,ha,hb⟩ + · exact Or.inr ⟨D,hD,D.radialRefines_refl⟩ + · exact hQ D hD + · exact Or.inr ⟨B,hB,B.restriction_radialRefines ha hb⟩ + +lemma metadata_owners {Z Z' Q : Finset (Record n)} + (hQ : ∀D ∈ Q, D.owner = A.owner ∨ ∃B ∈ Z, D.owner = B.owner) + (hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃B ∈ Z, ∃a b, + D = B.restriction a b ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer) : + OwnerEvolution A.owner Z Z' := by + intro D hD + rcases hmeta D hD with hD | hD | ⟨B,hB,a,b,rfl,_⟩ + · exact Or.inr ⟨D,hD,rfl⟩ + · exact hQ D hD + · exact Or.inr ⟨B,hB,rfl⟩ + +lemma metadata_separation {P : Finset (Finset (Fin n))} {U V : Finset (Fin n)} + (hVU : V ⊆ U) {Z Z' Q F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.width = δ) (hevol : Evolution (H := H) F Z Z') + (hsep : A.SameOwnerSeparated P U Z) + (hQ : ∀D ∈ Q, D.owner = A.owner → ∀u ∈ V, + (A.input P u).InteriorTo (H := H) (X := X) δ Z → + Disjoint ((RadialShell.ball u δ).support X) (D.shell.support X)) + (hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃B ∈ Z, ∃a b, + D = B.restriction a b ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer) : + A.SameOwnerSeparated P V Z' := by + intro u hu hint D hD hown + have hintold := evolution_interior A.radius_pos.le hF hevol hint + rcases hmeta D hD with hD | hD | ⟨B,hB,a,b,rfl,ha,hb⟩ + · exact hsep u (hVU hu) hintold D hD hown + · exact hQ D hD hown u hu hintold + · exact (hsep u (hVU hu) hintold B hB hown).mono_right + (RadialShell.restriction_subset X B.shell ha hb) + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma metadata_fresh (A : AssignedBag H G X δ η) {P : Finset (Finset (Fin n))} + {F Z Z' Q : Finset (Record n)} {M : Finset (Fin n)} + (hF : ∀D ∈ F, D.shell.ordinary = true) + (hQ : ∀D ∈ Q, D ∈ F → ∃u ∈ M, D = A.input P u) + (hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃B ∈ Z, ∃a b, + D = B.restriction a b ∧ B.shell.inner ≤ a ∧ b ≤ B.shell.outer) : + ∀D ∈ Z', D ∈ F → D ∈ Z ∨ ∃u ∈ M, D = A.input P u := by + intro D hD hDF + rcases hmeta D hD with hD | hD | ⟨B,hB,a,b,rfl,_⟩ + · exact Or.inl hD + · exact Or.inr (hQ D hD hDF) + · exact (Record.restriction_not_fresh hF B a b hDF).elim + +structure InteriorMove (A : AssignedBag H G X δ η) + (q ε : ℝ) (P : Finset (Finset (Fin n))) + (F Z : Finset (Record n)) (U : Finset (Fin n)) where + treated : Finset (Fin n) + next : Finset (Record n) + nonempty : treated.Nonempty + treated_interior : ∀u ∈ treated, u ∈ U ∧ + (A.input P u).InteriorTo (H := H) (X := X) δ Z + valid : LabeledArrangement H G X (q/4) next + credit : (∑D ∈ Z, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*(treated.card : ℝ)*δ ≤ + ∑D ∈ next, Record.phaseToken F δ ε D + evolution : Evolution (H := H) F Z next + owners : OwnerEvolution A.owner Z next + fresh : ∀D ∈ next, D ∈ F → D ∈ Z ∨ ∃u ∈ treated, D = A.input P u + separation : A.SameOwnerSeparated P (U\treated) next + +lemma avoiding_move (A : AssignedBag H G X δ η) (hX : ∀v, isProfile (X v)) + {q ε : ℝ} (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} {U : Finset (Fin n)} (hU : U ⊆ A.centers) + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : LabeledArrangement H G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) + {u : Fin n} (hu : u ∈ U) {B : Record n} (hB : B ∈ Z) + (havoid : B.avoided.isSome = true) (hinter : (A.input P u).Interior H X 256 δ B) : + Nonempty (InteriorMove A q ε P F Z U) := by + obtain ⟨Z',hZ',hcredit,hmeta₀⟩ := avoiding_operation H G X hX A.radius_pos hε + (fun D hD => ⟨(hF D hD).1,(hF D hD).2.2⟩) hZ (hvalid u (hU hu)) + (hAF u (hU hu)) rfl hB havoid + (fun D hD hs => by simpa [input,Record.excluded] using horder D hD hs) hinter + let Q : Finset (Record n) := {A.input P u} + have hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃E ∈ Z, ∃a b, + D = E.restriction a b ∧ E.shell.inner ≤ a ∧ b ≤ E.shell.outer := by + intro D hD + rcases hmeta₀ D hD with hD | rfl | ⟨a,b,heq,ha,hb,_⟩ + · exact Or.inl hD + · exact Or.inr (Or.inl (mem_singleton_self _)) + · exact Or.inr (Or.inr ⟨B,hB,a,b,heq,ha,hb⟩) + have hevol : Evolution (H := H) F Z Z' := metadata_evolution + (fun D hD => Or.inl ((mem_singleton.mp hD).symm ▸ hAF u (hU hu))) hmeta + have howner : OwnerEvolution A.owner Z Z' := A.metadata_owners + (fun D hD => Or.inl (by rw [mem_singleton.mp hD]; rfl)) hmeta + have hfresh := A.metadata_fresh (fun D hD => (hF D hD).1) + (M := {u}) (by + intro D hD _ + exact ⟨u,mem_singleton_self _,mem_singleton.mp hD⟩) hmeta + have hsep' : A.SameOwnerSeparated P (U\{u}) Z' := by + apply A.metadata_separation sdiff_subset (fun D hD => (hF D hD).2.1) hevol hsep _ hmeta + intro D hD _ v hv _ + rw [mem_singleton.mp hD] + obtain ⟨hv,hvu⟩ := mem_sdiff.mp hv + exact A.disjoint (hU hv) (hU hu) (by simpa only [mem_singleton] using hvu) + refine ⟨⟨{u},Z',singleton_nonempty _,?_,hZ',?_,hevol,howner,hfresh,hsep'⟩⟩ + · intro v hv + rw [mem_singleton.mp hv] + exact ⟨hu,⟨B,hB,hinter⟩⟩ + · simpa only [card_singleton,Nat.cast_one,mul_one] using hcredit + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma dense_move (A : AssignedBag H G X δ η) (hX : ∀v, isProfile (X v)) + {q ε a b : ℝ} (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} {U M : Finset (Fin n)} (hU : U ⊆ A.centers) + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : LabeledArrangement H G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) + {B : Record n} (hB : B ∈ Z) (hno : B.avoided = none) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) (hab : a ≤ b) + (hMn : M.Nonempty) (hMU : M ⊆ U) + (hinter : ∀u ∈ M, (A.input P u).Interior H X 256 δ B) + (hrange : ∀u ∈ M, a-δ < normDistance (X u) (X B.shell.center) ∧ + normDistance (X u) (X B.shell.center) < b+δ) + (hcount : 765*δ ≤ (M.card : ℝ)*δ) (hdense : 3*(b-a) ≤ (M.card : ℝ)*δ) : + Nonempty (InteriorMove A q ε P F Z U) := by + let Q := M.image (A.input P) + have hQcard : Q.card = M.card := card_image_of_injective _ (A.input_injective P) + obtain ⟨u₀,hu₀⟩ := hMn + have hwidth := Record.interior_width H X (hinter u₀ hu₀) + obtain ⟨Z',hZ',hcredit,hmeta₀⟩ := dense_operation H G X hX A.radius_pos hε hF hZ hB + (A.input_arrangement (hMU.trans hU) (fun u hu => hvalid u (hU (hMU hu)))) + (by intro D hD; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD; exact hAF u (hU (hMU hu))) + (by intro D hD; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD; rfl) hno hwidth ha hb hab + (by intro D hD; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD; exact hrange u hu) + (by intro D hD; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD; exact hinter u hu) + (by intro D hD E hE hs; obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + simpa [input,Record.excluded] using horder E hE hs) + (by rwa [hQcard]) (by rwa [hQcard]) + have hmeta : ∀D ∈ Z', D ∈ Z ∨ D ∈ Q ∨ ∃E ∈ Z, ∃a b, + D = E.restriction a b ∧ E.shell.inner ≤ a ∧ b ≤ E.shell.outer := by + intro D hD + rcases hmeta₀ D hD with hD | hD | ⟨a,b,heq,ha,hb,_⟩ + · exact Or.inl hD + · exact Or.inr (Or.inl hD) + · exact Or.inr (Or.inr ⟨B,hB,a,b,heq,ha,hb⟩) + have hevol : Evolution (H := H) F Z Z' := metadata_evolution (by + intro D hD + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + exact Or.inl (hAF u (hU (hMU hu)))) hmeta + have howner : OwnerEvolution A.owner Z Z' := A.metadata_owners (by + intro D hD + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + exact Or.inl rfl) hmeta + have hfresh := A.metadata_fresh (fun D hD => (hF D hD).1) + (M := M) (by + intro D hD _ + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + exact ⟨u,hu,rfl⟩) hmeta + have hsep' : A.SameOwnerSeparated P (U\M) Z' := by + apply A.metadata_separation sdiff_subset (fun D hD => (hF D hD).2.1) hevol hsep _ hmeta + intro D hD _ v hv _ + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + obtain ⟨hv,hvM⟩ := mem_sdiff.mp hv + exact A.disjoint (hU hv) (hU (hMU hu)) (fun hh => hvM (hh ▸ hu)) + refine ⟨⟨M,Z',⟨u₀,hu₀⟩,fun u hu => ⟨hMU hu,⟨B,hB,hinter u hu⟩⟩, + hZ',?_,hevol,howner,hfresh,hsep'⟩⟩ + rwa [hQcard] at hcredit + +lemma sparse_move (A : AssignedBag H G X δ η) (hX : ∀v, isProfile (X v)) + {q ε a b : ℝ} {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} {U M : Finset (Fin n)} (hU : U ⊆ A.centers) + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : LabeledArrangement H G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) + {B : Record n} (hB : B ∈ Z) (hno : B.avoided = none) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hMn : M.Nonempty) (hMU : M ⊆ U) + (hinter : ∀u ∈ M, (A.input P u).Interior H X 256 δ B) + (hexact : ∀u ∈ U, (A.input P u).InteriorTo (H := H) (X := X) δ Z → + a-δ < normDistance (X u) (X B.shell.center) → + normDistance (X u) (X B.shell.center) < b+δ → u ∈ M) + (hwide : 255*δ ≤ b-a) (hsparse : (M.card : ℝ)*δ ≤ 3*(b-a)) + (hinner : (B.innerRecord A.owner (a+δ) (b-δ)).Valid H G X (q/4)) + (houter : (B.outsideRecord A.owner a b).Valid H G X (q/4)) : + Nonempty (InteriorMove A q ε P F Z U) := by + obtain ⟨u₀,hu₀⟩ := hMn + have hint := hinter u₀ hu₀ + have hov := hvalid u₀ (hU (hMU hu₀)) + have ht := Record.candidate_ancestor H hov.1 (hZ.1 B hB).1 + (fun hs => by simpa [input,Record.excluded] using horder B hB hs) hint.1 + have hstrict : A.owner ⊂ B.owner := Record.strict_owner_of_interior hX + hov.1 (hZ.1 B hB).1 hov.2.2.1 A.radius_pos.le rfl + (fun hs => by simpa [input,Record.excluded] using horder B hB hs) (hsep u₀ (hMU hu₀) ⟨B,hB,hint⟩ B hB) hint + obtain ⟨Z',hZ',hcredit,hmeta₀⟩ := sparse_operation H G X hX A.radius_pos + (fun D hD => ⟨(hF D hD).1,(hF D hD).2.1⟩) hZ hB hno + (Record.interior_width H X hint) ht ha hb hwide hsparse hinner houter + let C := B.innerRecord A.owner (a+δ) (b-δ) + let D := B.outsideRecord A.owner a b + let Q : Finset (Record n) := {C,D} + have hmeta : ∀E ∈ Z', E ∈ Z ∨ E ∈ Q ∨ ∃K ∈ Z, ∃c d, + E = K.restriction c d ∧ K.shell.inner ≤ c ∧ d ≤ K.shell.outer := by + intro E hE + rcases hmeta₀ E hE with hE | rfl | rfl | ⟨c,d,heq,hc,hd,_⟩ + · exact Or.inl hE + · exact Or.inr (Or.inl (mem_insert_self _ _)) + · exact Or.inr (Or.inl (mem_insert_of_mem (mem_singleton_self _))) + · exact Or.inr (Or.inr ⟨B,hB,c,d,heq,hc,hd⟩) + have href := Record.central_radialRefines (hZ.1 B hB).1 hno ht + (by linarith [A.radius_pos] : B.shell.inner ≤ a+δ) + (by linarith [A.radius_pos] : b-δ ≤ B.shell.outer) ha hb + have hevol : Evolution (H := H) F Z Z' := metadata_evolution (by + intro E hE + rcases mem_insert.mp hE with rfl | hE + · exact Or.inr ⟨B,hB,href.1⟩ + · rw [mem_singleton.mp hE] + exact Or.inr ⟨B,hB,href.2⟩) hmeta + have howner : OwnerEvolution A.owner Z Z' := A.metadata_owners (by + intro E hE + rcases mem_insert.mp hE with rfl | hE + · exact Or.inl rfl + · rw [mem_singleton.mp hE] + exact Or.inr ⟨B,hB,rfl⟩) hmeta + have hfresh := A.metadata_fresh (fun D hD => (hF D hD).1) + (P := P) (M := M) (by + intro E hE hEF + have hh := (hF E hEF).1 + rcases mem_insert.mp hE with rfl | hE + · simp [C,Record.innerRecord,RadialShell.hollow] at hh + · rw [mem_singleton.mp hE] at hh + simp [D,Record.outsideRecord,RadialShell.hollow] at hh) hmeta + have hsep' : A.SameOwnerSeparated P (U\M) Z' := by + apply A.metadata_separation sdiff_subset (fun D hD => (hF D hD).2.1) hevol hsep _ hmeta + intro E hE hown u hu hintold + rcases mem_insert.mp hE with rfl | hE + · obtain ⟨hu,huM⟩ := mem_sdiff.mp hu + by_cases hlo : a-δ < normDistance (X u) (X B.shell.center) + · have hhi : b+δ ≤ normDistance (X u) (X B.shell.center) := + le_of_not_gt (fun hh => huM (hexact u hu hintold hlo hh)) + exact RadialShell.ball_disjoint_hollow_lower X _ _ (by linarith [A.radius_pos]) + · exact RadialShell.ball_disjoint_hollow_upper X _ _ (by + have := not_lt.mp hlo + linarith [A.radius_pos]) + · rw [mem_singleton.mp hE] at hown + exact (hstrict.ne hown.symm).elim + exact ⟨⟨M,Z',⟨u₀,hu₀⟩,fun u hu => ⟨hMU hu,⟨B,hB,hinter u hu⟩⟩, + hZ',hcredit,hevol,howner,hfresh,hsep'⟩⟩ + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma interior_move (A : AssignedBag H G X δ η) (hX : ∀v, isProfile (X v)) + {q ε : ℝ} (hq : 0 < q) (hconn : LocallyConnectedReal H G q) + (hη : 3072/q ≤ η) (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} {U : Finset (Fin n)} (hU : U ⊆ A.centers) + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : LabeledArrangement H G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) + (hhalf : A.centers.card ≤ 2*(U.filter (fun u => + (A.input P u).InteriorTo (H := H) (X := X) δ Z)).card) : + Nonempty (InteriorMove A q ε P F Z U) := by + by_cases hav : ∃u ∈ U, ∃B ∈ Z, B.avoided.isSome = true ∧ + (A.input P u).Interior H X 256 δ B + · obtain ⟨u,hu,B,hB,hav,hint⟩ := hav + exact A.avoiding_move hX hε hU hF hAF hvalid hZ horder hsep hu hB hav hint + let I := U.filter (fun u => (A.input P u).InteriorTo (H := H) (X := X) δ Z) + have hIU : I ⊆ U := by + intro u hu + exact (mem_filter.mp hu).1 + have hI : ∀u ∈ I, (A.input P u).InteriorTo (H := H) (X := X) δ Z := + fun u hu => (mem_filter.mp hu).2 + obtain ⟨R,hR,hRc,hlarge⟩ := A.large_component hq hconn hη (hIU.trans hU) hhalf + have hno : ∀u ∈ I, ∀D ∈ Z, (A.input P u).Interior H X 256 δ D → D.avoided = none := by + intro u hu D hD hint + cases hh : D.avoided with + | none => rfl + | some t => exact (hav ⟨u,hIU hu,D,hD,by simp [hh],hint⟩).elim + obtain ⟨B,a,b,M,u₁,u₂,hB,hBno,ha,hb,hab,hMn,hMeq,hinter,hdich, + hu₁,hu₂,hv₁,hv₂,hv₁r,hv₂r,hu₁r,hu₂r⟩ := A.radial_group hX (hIU.trans hU) hZ + (fun u hu => (hvalid u (hU (hIU hu))).1) horder hI hno hlarge + have hMI : M ⊆ I := by rw [hMeq]; exact filter_subset _ _ + have hMU : M ⊆ U := hMI.trans hIU + have hrange : ∀u ∈ M, a-δ < normDistance (X u) (X B.shell.center) ∧ + normDistance (X u) (X B.shell.center) < b+δ := by + intro u hu + rw [hMeq] at hu + exact (mem_filter.mp hu).2 + have hdich' : (768:ℝ) ≤ M.card ∨ 255*δ ≤ b-a := by exact_mod_cast hdich + by_cases hdense : 3*(b-a) ≤ (M.card : ℝ)*δ + · have hcount := AssignedSelection.dense_count A.radius_pos.le (by norm_num : (768:ℝ) ≤ 768) + hdich' hdense + exact A.dense_move hX hε hU hF hAF hvalid hZ horder hsep hB hBno ha hb hab + hMn hMU hinter hrange hcount hdense + · have hsparse : (M.card : ℝ)*δ ≤ 3*(b-a) := (not_le.mp hdense).le + have hwide := AssignedSelection.sparse_width A.radius_pos.le (by norm_num : (768:ℝ) ≤ 768) + hdich' hsparse + obtain ⟨u₀,hu₀⟩ := hMn + have hint := hinter u₀ hu₀ + have hov := hvalid u₀ (hU (hMU hu₀)) + have ht := Record.candidate_ancestor H hov.1 (hZ.1 B hB).1 (fun hs => by simpa [input,Record.excluded] using horder B hB hs) hint.1 + have hstrict : A.owner ⊂ B.owner := Record.strict_owner_of_interior hX + hov.1 (hZ.1 B hB).1 hov.2.2.1 A.radius_pos.le rfl + (fun hs => by simpa [input,Record.excluded] using horder B hB hs) (hsep u₀ (hMU hu₀) ⟨B,hB,hint⟩ B hB) hint + obtain ⟨e,he⟩ := (A.neighbor_spec (hU (hIU hu₁))).2.2 + obtain ⟨hin,hout⟩ := Record.central_valid H G X (hZ.1 B hB) hBno hq.le hconn ht hstrict + ha hb A.radius_pos (by linarith [A.radius_pos]) hR hRc + (A.endpoint u₁ (hU (hIU hu₁))).1 (A.endpoint u₂ (hU (hIU hu₂))).1 + hv₁ hv₂ hu₁r hu₂r hv₁r hv₂r he + apply A.sparse_move hX hU hF hvalid hZ horder hsep hB hBno ha hb ⟨u₀,hu₀⟩ hMU + hinter _ hwide hsparse hin hout + intro u hu hint hlo hhi + rw [hMeq] + exact mem_filter.mpr ⟨mem_filter.mpr ⟨hu,hint⟩,hlo,hhi⟩ + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} + +lemma ownerEvolution_refl (t : Finset (Fin n)) (Z : Finset (Record n)) : OwnerEvolution t Z Z := by + intro D hD + exact Or.inr ⟨D,hD,rfl⟩ + +lemma ownerEvolution_trans {t : Finset (Fin n)} {Z W V : Finset (Record n)} + (h1 : OwnerEvolution t Z W) (h2 : OwnerEvolution t W V) : OwnerEvolution t Z V := by + intro D hD + rcases h2 D hD with hh | ⟨E,hE,hh⟩ + · exact Or.inl hh + · rcases h1 E hE with he | ⟨B,hB,he⟩ + · exact Or.inl (hh.trans he) + · exact Or.inr ⟨B,hB,hh.trans he⟩ + +namespace AssignedBag + +lemma interior_loop (A : AssignedBag H G X δ η) (hX : ∀v, isProfile (X v)) + {q ε : ℝ} (hq : 0 < q) (hconn : LocallyConnectedReal H G q) + (hη : 3072/q ≤ η) (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (U : Finset (Fin n)) (hU : U ⊆ A.centers) (Z : Finset (Record n)) + (hZ : LabeledArrangement H G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (hsep : A.SameOwnerSeparated P U Z) : + ∃(V : Finset (Fin n)) (Z' : Finset (Record n)), V ⊆ U ∧ + LabeledArrangement H G X (q/4) Z' ∧ + 2*(V.filter (fun u => (A.input P u).InteriorTo (H := H) (X := X) δ Z')).card < + A.centers.card ∧ + (∑D ∈ Z, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*((U.card : ℝ)-(V.card : ℝ))*δ ≤ + ∑D ∈ Z', Record.phaseToken F δ ε D ∧ + (∀B : Record n, B.InteriorTo (H := H) (X := X) δ Z' → + B.InteriorTo (H := H) (X := X) δ Z) ∧ + OwnerEvolution A.owner Z Z' ∧ + (∀D ∈ Z', D ∈ F → D ∈ Z ∨ ∃u ∈ U\V, D = A.input P u) ∧ + A.SameOwnerSeparated P V Z' := by + induction U using Finset.strongInduction generalizing Z with + | H U ih => + by_cases hstop : 2*(U.filter (fun u => + (A.input P u).InteriorTo (H := H) (X := X) δ Z)).card < A.centers.card + · refine ⟨U,Z,Subset.refl _,hZ,hstop,?_,fun _ h => h,ownerEvolution_refl _ _, + fun _ h _ => Or.inl h,hsep⟩ + simp + · obtain ⟨W⟩ := A.interior_move hX hq hconn hη hε hU hF hAF hvalid hZ horder hsep + (not_lt.mp hstop) + have hMU : W.treated ⊆ U := fun u hu => (W.treated_interior u hu).1 + have hss : U\W.treated ⊂ U := by + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨sdiff_subset,?_⟩ + intro hh + obtain ⟨u,hu⟩ := W.nonempty + have hm : u ∈ U\W.treated := hh.symm ▸ hMU hu + exact (mem_sdiff.mp hm).2 hu + obtain ⟨V,Z',hVU,hZ',hstop',hcredit',hinter',howners',hfresh',hsep'⟩ := ih (U\W.treated) hss + (sdiff_subset.trans hU) W.next W.valid (ownerEvolution_order horder W.owners) W.separation + have hcards : ((U\W.treated).card : ℝ)+(W.treated.card : ℝ) = (U.card : ℝ) := by + exact_mod_cast card_sdiff_add_card_eq_card hMU + refine ⟨V,Z',hVU.trans sdiff_subset,hZ',hstop',?_,?_, + ownerEvolution_trans W.owners howners',?_,hsep'⟩ + · calc + (∑D ∈ Z, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*((U.card : ℝ)-(V.card : ℝ))*δ = + ((∑D ∈ Z, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*(W.treated.card : ℝ)*δ)+ + AssignedAccounting.theta*(((U\W.treated).card : ℝ)-(V.card : ℝ))*δ := by + rw [←hcards] + ring + _ ≤ (∑D ∈ W.next, Record.phaseToken F δ ε D)+ + AssignedAccounting.theta*(((U\W.treated).card : ℝ)-(V.card : ℝ))*δ := + add_le_add W.credit (le_refl _) + _ ≤ _ := hcredit' + · intro B hB + exact evolution_interior A.radius_pos.le (fun D hD => (hF D hD).2.1) + W.evolution (hinter' B hB) + · intro D hD hDF + rcases hfresh' D hD hDF with hD | ⟨u,hu,heq⟩ + · rcases W.fresh D hD hDF with hD | ⟨u,hu,heq⟩ + · exact Or.inl hD + · exact Or.inr ⟨u,mem_sdiff.mpr ⟨hMU hu, + fun hv => (mem_sdiff.mp (hVU hv)).2 hu⟩,heq⟩ + · exact Or.inr ⟨u,mem_sdiff.mpr ⟨sdiff_subset (mem_sdiff.mp hu).1, + (mem_sdiff.mp hu).2⟩,heq⟩ + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} +namespace Record + +def baseToken (r : ℝ) (B : Record n) : ℝ := + AssignedAccounting.base B.avoided.isSome B.shell.width r + +def shrinkRecord (F : Finset (Record n)) (δ : ℝ) (B : Record n) : Record n := + if B ∈ F then B else B.restriction (B.shell.inner+257*δ) (B.shell.outer-257*δ) + +def shrinkValue (F : Finset (Record n)) (δ ε : ℝ) (B : Record n) : ℝ := + if B ∈ F then AssignedAccounting.fresh δ ε else + AssignedAccounting.base B.avoided.isSome (B.shell.width-514*δ) ε + +lemma fresh_base {δ ε : ℝ} (hδ : 0 ≤ δ) (hε : ε ≤ δ/1536) + {B : Record n} (hwidth : B.shell.width = δ) (hno : B.avoided = none) : + B.baseToken ε = AssignedAccounting.fresh δ ε := by + simp only [baseToken,hwidth,hno,Option.isSome_none,AssignedAccounting.base, + Bool.false_eq_true,↓reduceIte,AssignedAccounting.fresh,div_one] + exact max_eq_left (by linarith) + +lemma shrink_refines {δ : ℝ} (hδ : 0 ≤ δ) (F : Finset (Record n)) (B : Record n) : + (B.shrinkRecord F δ).Refines H X B := by + by_cases hB : B ∈ F + · simp only [shrinkRecord,ite_eq_left hB] + exact ⟨Set.Subset.refl _,Subset.refl _⟩ + · simp only [shrinkRecord,ite_eq_right hB] + exact B.restriction_refines H X (by linarith) (by linarith) + +omit [PseudoMetricSpace Coord] in +lemma shrink_valid {δ q : ℝ} (hδ : 0 ≤ δ) {F : Finset (Record n)} {B : Record n} + (hB : B.Valid H G X q) (hw : 0 < (B.shrinkRecord F δ).shell.width) : + (B.shrinkRecord F δ).Valid H G X q := by + by_cases hf : B ∈ F + · simpa only [shrinkRecord,ite_eq_left hf] using hB + · simp only [shrinkRecord,ite_eq_right hf] at hw ⊢ + exact Record.restrict_valid H G X hB (by linarith) (by linarith) + (by simpa only [restriction,RadialShell.hollow,RadialShell.width,sub_pos] using hw) + +lemma shrink_base {δ ε : ℝ} (hδ : 0 ≤ δ) (hε : ε ≤ δ/1536) + {F : Finset (Record n)} (hF : ∀B ∈ F, B.shell.width = δ ∧ B.avoided = none) + (B : Record n) : (B.shrinkRecord F δ).baseToken ε = B.shrinkValue F δ ε := by + by_cases hf : B ∈ F + · simp only [shrinkRecord,shrinkValue,ite_eq_left hf] + exact fresh_base hδ hε (hF B hf).1 (hF B hf).2 + · simp only [shrinkRecord,shrinkValue,ite_eq_right hf,baseToken,restriction,RadialShell.hollow, + RadialShell.width] + congr 1 + ring + +lemma shrink_cost {δ ε : ℝ} (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) + {F : Finset (Record n)} (hF : ∀B ∈ F, B.shell.width = δ ∧ B.avoided = none) + (B : Record n) : + 0 ≤ B.phaseToken F δ ε-B.shrinkValue F δ ε ∧ + B.phaseToken F δ ε-B.shrinkValue F δ ε ≤ + 256*(B.baseToken ε-B.phaseToken F δ ε) := by + by_cases hf : B ∈ F + · rw [phaseToken,shrinkValue,ite_eq_left hf,ite_eq_left hf, + fresh_base hδ hscale (hF B hf).1 (hF B hf).2] + simp + · simp only [phaseToken,shrinkValue,ite_eq_right hf,baseToken] + exact AssignedAccounting.shrink_cost _ hδ hε hscale + +lemma shrink_discard {δ ε : ℝ} (hδ : 0 < δ) (hε : 0 ≤ ε) + {F : Finset (Record n)} (hF : ∀B ∈ F, B.shell.width = δ) + (B : Record n) (hw : ¬0 < (B.shrinkRecord F δ).shell.width) : + B.shrinkValue F δ ε = 0 := by + by_cases hf : B ∈ F + · rw [shrinkRecord,ite_eq_left hf,hF B hf] at hw + exact (hw hδ).elim + · rw [shrinkValue,ite_eq_right hf] + apply AssignedAccounting.base_discard _ _ hε + rw [shrinkRecord,ite_eq_right hf] at hw + dsimp [restriction,RadialShell.hollow,RadialShell.width] at hw ⊢ + linarith [not_lt.mp hw] + +lemma border_shrink_compatible {δ : ℝ} (_hδ : 0 ≤ δ) {F : Finset (Record n)} + (hF : ∀A ∈ F, ∀B ∈ F, A ≠ B → Disjoint (A.shell.support X) (B.shell.support X)) + {A B : Record n} (hA : A ∈ F) (hne : A ≠ B) + (hball : A.shell = RadialShell.ball A.shell.center δ) + (hbor : ¬A.Interior H X 256 δ B) : + A.Compatible H X (B.shrinkRecord F δ) := by + by_cases hf : B ∈ F + · simp only [shrinkRecord,ite_eq_left hf] + exact Or.inl (hF A hA B hf hne) + · simp only [shrinkRecord,ite_eq_right hf] + by_cases hdis : Disjoint (A.conflict H) (B.conflict H) + · exact Or.inr hdis + · have hmeet : (A.conflict H ∩ B.conflict H).Nonempty := by + apply nonempty_iff_ne_empty.mpr + exact fun hh => hdis (Finset.disjoint_iff_inter_eq_empty.mpr hh) + left + rw [hball] + by_cases hlo : B.shell.inner+256*δ < normDistance (X A.shell.center) (X B.shell.center) + · have hhi : B.shell.outer-256*δ ≤ normDistance (X A.shell.center) (X B.shell.center) := + le_of_not_gt (fun hh => hbor ⟨hmeet,hlo,hh⟩) + exact RadialShell.ball_disjoint_hollow_lower X _ _ (by linarith) + · exact RadialShell.ball_disjoint_hollow_upper X _ _ (by linarith [not_lt.mp hlo]) + +end Record + +def shrinkFamily (F Z : Finset (Record n)) (δ : ℝ) : Finset (Record n) := + (Z.filter (fun B => 0 < (B.shrinkRecord F δ).shell.width)).image (Record.shrinkRecord F δ) + +lemma shrinkFamily_valid {q δ : ℝ} (hδ : 0 ≤ δ) {F Z : Finset (Record n)} + (hZ : LabeledArrangement H G X q Z) : LabeledArrangement H G X q (shrinkFamily F Z δ) := by + constructor + · intro D hD + obtain ⟨B,hB,rfl⟩ := mem_image.mp hD + exact Record.shrink_valid hδ (hZ.1 B (mem_filter.mp hB).1) (mem_filter.mp hB).2 + · intro D hD E hE hne hgeo + obtain ⟨B,hB,rfl⟩ := mem_image.mp hD + obtain ⟨C,hC,rfl⟩ := mem_image.mp hE + have hh := Record.compatible_refinements H X + (labeled_pair H G X hZ (mem_filter.mp hB).1 (mem_filter.mp hC).1 + (fun hh => hne (congrArg (Record.shrinkRecord F δ) hh))) + (Record.shrink_refines hδ F B) (Record.shrink_refines hδ F C) + exact hh.resolve_left hgeo + +lemma shrinkFamily_sum (hX : ∀v, isProfile (X v)) {q δ ε : ℝ} + (hδ : 0 < δ) (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) {F Z : Finset (Record n)} + (hF : ∀B ∈ F, B.shell.width = δ ∧ B.avoided = none) + (hZ : LabeledArrangement H G X q Z) : + ∑D ∈ shrinkFamily F Z δ, D.baseToken ε = ∑B ∈ Z, B.shrinkValue F δ ε := by + have hinj : ∀B ∈ Z.filter (fun B => 0 < (B.shrinkRecord F δ).shell.width), + ∀C ∈ Z.filter (fun B => 0 < (B.shrinkRecord F δ).shell.width), + B.shrinkRecord F δ = C.shrinkRecord F δ → B = C := by + intro B hB C hC heq + by_contra hh + have hv := Record.shrink_valid hδ.le (hZ.1 B (mem_filter.mp hB).1) (mem_filter.mp hB).2 + have hc := Record.compatible_refinements H X + (labeled_pair H G X hZ (mem_filter.mp hB).1 (mem_filter.mp hC).1 hh) + (Record.shrink_refines hδ.le F B) (Record.shrink_refines hδ.le F C) + rw [←heq] at hc + exact (B.shrinkRecord F δ).compatible_self_iff H X hX hv.1 hv.2.2.1 hc + rw [shrinkFamily,sum_image hinj,sum_filter] + apply sum_congr rfl + intro B hB + by_cases hw : 0 < (B.shrinkRecord F δ).shell.width + · rw [ite_eq_left hw,Record.shrink_base hδ.le hscale hF] + · rw [ite_eq_right hw,Record.shrink_discard hδ hε (fun D hD => (hF D hD).1) B hw] + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} + +lemma border_transition (hX : ∀v, isProfile (X v)) {q δ ε : ℝ} + (hδ : 0 < δ) (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) + {F Z K : Finset (Record n)} + (hF : ∀B ∈ F, B.shell.ordinary = true ∧ B.shell.width = δ ∧ B.avoided = none) + (hFball : ∀B ∈ F, B.shell = RadialShell.ball B.shell.center δ) + (hFgeo : ∀A ∈ F, ∀B ∈ F, A ≠ B → Disjoint (A.shell.support X) (B.shell.support X)) + (hFvalid : LabeledArrangement H G X q F) + (hZ : LabeledArrangement H G X q Z) (hKF : K ⊆ F) (hKZ : Disjoint K Z) + (hbor : ∀A ∈ K, ¬A.InteriorTo (H := H) (X := X) δ Z) : + ∃Z' : Finset (Record n), LabeledArrangement H G X q Z' ∧ + (∑B ∈ Z, B.phaseToken F δ ε)+AssignedAccounting.theta*(K.card : ℝ)*δ ≤ + ∑B ∈ Z', B.baseToken ε ∧ + (∀D ∈ Z', D ∈ K ∨ ∃B ∈ Z, D.owner = B.owner) := by + let p := ∑B ∈ Z, B.phaseToken F δ ε + let q' := ∑B ∈ Z, B.baseToken ε + have hw : ∀B ∈ F, B.shell.width = δ ∧ B.avoided = none := + fun B hB => (hF B hB).2 + by_cases hex : AssignedAccounting.theta*(K.card : ℝ)*δ ≤ q'-p + · exact ⟨Z,hZ,by dsimp [p,q'] at *; linarith,fun D hD => Or.inr ⟨D,hD,rfl⟩⟩ + let W := shrinkFamily F Z δ + have hW : LabeledArrangement H G X q W := shrinkFamily_valid hδ.le hZ + have hK := labeled_subset H G X hFvalid hKF + have hKW : ∀A ∈ K, ∀B ∈ W, A.Compatible H X B := by + intro A hA D hD + obtain ⟨B,hB,rfl⟩ := mem_image.mp hD + have hBZ : B ∈ Z := (mem_filter.mp hB).1 + exact Record.border_shrink_compatible hδ.le hFgeo (hKF hA) + (fun heq => Finset.disjoint_left.mp hKZ hA (heq.symm ▸ hBZ)) + (hFball A (hKF hA)) (fun hh => hbor A hA ⟨B,hBZ,hh⟩) + have hdis : Disjoint K W := labeled_sets_disjoint H G X hX hK hKW + have hsum : ∑B ∈ W, B.baseToken ε = ∑B ∈ Z, B.shrinkValue F δ ε := + shrinkFamily_sum hX hδ hε hscale hw hZ + have hkSum : ∑B ∈ K, B.baseToken ε = (K.card : ℝ)*AssignedAccounting.fresh δ ε := by + calc + ∑B ∈ K, B.baseToken ε = ∑B ∈ K, AssignedAccounting.fresh δ ε := + sum_congr rfl (fun B hB => Record.fresh_base hδ.le hscale (hw B (hKF hB)).1 (hw B (hKF hB)).2) + _ = _ := by simp + have hcost : p-(∑B ∈ W, B.baseToken ε) ≤ 256*(q'-p) := by + rw [hsum] + dsimp [p,q'] + rw [←sum_sub_distrib,←sum_sub_distrib,Finset.mul_sum] + exact sum_le_sum (fun B hB => (Record.shrink_cost hδ.le hε hscale hw B).2) + have hdef : p-(∑B ∈ W, B.baseToken ε) ≤ (K.card : ℝ)*δ/2 := by + have hh := not_le.mp hex + dsimp [AssignedAccounting.theta] at hh + linarith + have hpay := AssignedAccounting.border_payment hδ.le hscale + (Nat.cast_nonneg K.card : (0:ℝ) ≤ _) hdef + refine ⟨K∪W,labeled_union H G X hK hW hKW,?_,?_⟩ + · rw [sum_union hdis,hkSum] + dsimp [p] at hpay + linarith + · intro D hD + rcases mem_union.mp hD with hD | hD + · exact Or.inl hD + · obtain ⟨B,hB,rfl⟩ := mem_image.mp hD + refine Or.inr ⟨B,(mem_filter.mp hB).1,?_⟩ + dsimp [Record.shrinkRecord] + split_ifs <;> rfl + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma loop_with_border_debt (A : AssignedBag H G X δ η) (hX : ∀v, isProfile (X v)) + {q ε : ℝ} (hq : 0 < q) (hconn : LocallyConnectedReal H G q) + (hη : 3072/q ≤ η) (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : LabeledArrangement H G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (howner : ∀D ∈ Z, D.owner ≠ A.owner) : + ∃(Z' K : Finset (Record n)), LabeledArrangement H G X (q/4) Z' ∧ + K ⊆ A.centers.image (A.input P) ∧ Disjoint K Z' ∧ + (∀B ∈ K, ¬B.InteriorTo (H := H) (X := X) δ Z') ∧ + (∑D ∈ Z, D.phaseToken F δ ε)+ + (AssignedAccounting.theta/2)*(A.centers.card : ℝ)*δ ≤ + (∑D ∈ Z', D.phaseToken F δ ε)+AssignedAccounting.theta*(K.card : ℝ)*δ ∧ + (∀B : Record n, B.InteriorTo (H := H) (X := X) δ Z' → + B.InteriorTo (H := H) (X := X) δ Z) ∧ + OwnerEvolution A.owner Z Z' ∧ + (∀D ∈ Z', D ∈ F → D ∈ Z ∨ ∃u ∈ A.centers, D = A.input P u) := by + obtain ⟨V,Z',hVA,hZ',hstop,hcredit,hinter,howners,hfresh,_⟩ := + A.interior_loop hX hq hconn hη hε hF hAF hvalid A.centers (Subset.refl _) Z hZ horder + (fun u hu hint B hB hh => (howner B hB hh).elim) + let I := V.filter (fun u => (A.input P u).InteriorTo (H := H) (X := X) δ Z') + let B := V.filter (fun u => ¬(A.input P u).InteriorTo (H := H) (X := X) δ Z') + let K := B.image (A.input P) + have hKV : ∀D ∈ K, ∃u ∈ V, D = A.input P u ∧ + ¬D.InteriorTo (H := H) (X := X) δ Z' := by + intro D hD + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + exact ⟨u,(mem_filter.mp hu).1,rfl,(mem_filter.mp hu).2⟩ + have hKcard : K.card = B.card := card_image_of_injective _ (A.input_injective P) + have hcards : (I.card : ℝ)+(K.card : ℝ) = (V.card : ℝ) := by + rw [hKcard] + exact_mod_cast card_filter_add_card_filter_not (s := V) + (p := fun u => (A.input P u).InteriorTo (H := H) (X := X) δ Z') + have hI : 2*(I.card : ℝ) < A.centers.card := by exact_mod_cast hstop + have hcount : (A.centers.card : ℝ)/2 ≤ (A.centers.card : ℝ)-(V.card : ℝ)+(K.card : ℝ) := by + linarith + have hnum := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hcount (by norm_num [AssignedAccounting.theta] : + (0:ℝ) ≤ AssignedAccounting.theta)) A.radius_pos.le + refine ⟨Z',K,hZ',?_,?_,fun D hD => (hKV D hD).choose_spec.2.2,?_,hinter,howners,?_⟩ + · intro D hD + obtain ⟨u,hu,rfl,_⟩ := hKV D hD + exact mem_image.mpr ⟨u,hVA hu,rfl⟩ + · rw [Finset.disjoint_left] + intro D hD hDZ + obtain ⟨u,hu,rfl,_⟩ := hKV D hD + rcases hfresh _ hDZ (hAF u (hVA hu)) with hh | ⟨v,hv,heq⟩ + · exact howner _ hh rfl + · have he : u = v := A.input_injective P heq + exact (mem_sdiff.mp hv).2 (he ▸ hu) + · dsimp [AssignedAccounting.theta] at hnum hcredit ⊢ + nlinarith + · intro D hD hDF + rcases hfresh D hD hDF with hh | ⟨u,hu,heq⟩ + · exact Or.inl hh + · exact Or.inr ⟨u,(mem_sdiff.mp hu).1,heq⟩ + +end AssignedBag +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} + +lemma phase_loops {ι : Type*} [DecidableEq ι] + (A : ι → AssignedBag H G X δ η) (P : ι → Finset (Finset (Fin n))) + (hX : ∀v, isProfile (X v)) {q ε : ℝ} (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) (hη : 3072/q ≤ η) (hε : ε ≤ δ/1536) + {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (J : Finset ι) (hAi : Set.InjOn (fun i => (A i).owner) J) + (hAF : ∀i ∈ J, ∀u ∈ (A i).centers, (A i).input (P i) u ∈ F) + (hvalid : ∀i ∈ J, ∀u ∈ (A i).centers, ((A i).input (P i) u).Valid H G X (q/4)) + (Z : Finset (Record n)) (hZ : LabeledArrangement H G X (q/4) Z) + (horder : ∀i ∈ J, ∀D ∈ Z, D.owner ⊂ (A i).owner → D.owner ∈ P i) + (howner : ∀i ∈ J, ∀D ∈ Z, D.owner ≠ (A i).owner) : + ∃(Z' K : Finset (Record n)), LabeledArrangement H G X (q/4) Z' ∧ K ⊆ F ∧ + (∀D ∈ K, ∃i ∈ J, D.owner = (A i).owner) ∧ Disjoint K Z' ∧ + (∀B ∈ K, ¬B.InteriorTo (H := H) (X := X) δ Z') ∧ + (∑D ∈ Z, D.phaseToken F δ ε)+ + (AssignedAccounting.theta/2)*(∑i ∈ J, ((A i).centers.card : ℝ))*δ ≤ + (∑D ∈ Z', D.phaseToken F δ ε)+AssignedAccounting.theta*(K.card : ℝ)*δ ∧ + (∀B : Record n, B.InteriorTo (H := H) (X := X) δ Z' → + B.InteriorTo (H := H) (X := X) δ Z) ∧ + (∀D ∈ Z', (∃i ∈ J, D.owner = (A i).owner) ∨ ∃B ∈ Z, D.owner = B.owner) ∧ + (∀D ∈ Z', D ∈ F → D ∈ Z ∨ ∃i ∈ J, ∃u ∈ (A i).centers, D = (A i).input (P i) u) := by + induction J using Finset.strongInduction generalizing Z with + | H J ih => + by_cases hn : J.Nonempty + · obtain ⟨j,hj,hmax⟩ := J.exists_max_image (fun i => (A i).owner.card) hn + obtain ⟨Z₁,K₁,hZ₁,hKA,hKZ₁,hbor₁,hcredit₁,hint₁,hown₁,hfresh₁⟩ := + (A j).loop_with_border_debt hX hq hconn hη hε hF (hAF j hj) (hvalid j hj) + hZ (horder j hj) (howner j hj) + have hKi : ∀D ∈ K₁, ∃u ∈ (A j).centers, D = (A j).input (P j) u := by + intro D hD + obtain ⟨u,hu,heq⟩ := mem_image.mp (hKA hD) + exact ⟨u,hu,heq.symm⟩ + have hKown : ∀D ∈ K₁, D.owner = (A j).owner := by + intro D hD + obtain ⟨u,hu,rfl⟩ := hKi D hD + rfl + have hKAf : K₁ ⊆ F := by + intro D hD + obtain ⟨u,hu,rfl⟩ := hKi D hD + exact hAF j hj u hu + have hInj : Set.InjOn (fun i => (A i).owner) (J.erase j) := hAi.mono (erase_subset _ _) + have horder₁ : ∀i ∈ J.erase j, ∀D ∈ Z₁, D.owner ⊂ (A i).owner → D.owner ∈ P i := by + intro i hi D hD hs + rcases hown₁ D hD with hh | ⟨B,hB,hh⟩ + · rw [hh] at hs + have hcard := card_lt_card hs + have hmax := hmax i (mem_of_mem_erase hi) + omega + · rw [hh] at hs ⊢ + exact horder i (mem_of_mem_erase hi) B hB hs + have howner₁ : ∀i ∈ J.erase j, ∀D ∈ Z₁, D.owner ≠ (A i).owner := by + intro i hi D hD heq + rcases hown₁ D hD with hh | ⟨B,hB,hh⟩ + · exact (mem_erase.mp hi).1 (hAi (mem_of_mem_erase hi) hj (heq.symm.trans hh)) + · exact howner i (mem_of_mem_erase hi) B hB (hh.symm.trans heq) + obtain ⟨Z₂,K₂,hZ₂,hKF₂,hKown₂,hKZ₂,hbor₂,hcredit₂,hint₂,hown₂,hfresh₂⟩ := + ih (J.erase j) (erase_ssubset hj) hInj + (fun i hi => hAF i (mem_of_mem_erase hi)) + (fun i hi => hvalid i (mem_of_mem_erase hi)) Z₁ hZ₁ horder₁ howner₁ + have hdis : Disjoint K₁ K₂ := by + rw [Finset.disjoint_left] + intro D hD hD₂ + obtain ⟨i,hi,heq⟩ := hKown₂ D hD₂ + exact (mem_erase.mp hi).1 (hAi (mem_of_mem_erase hi) hj (heq.symm.trans (hKown D hD))) + have hKZ : Disjoint K₁ Z₂ := by + rw [Finset.disjoint_left] + intro D hD hDZ + rcases hfresh₂ D hDZ (hKAf hD) with hD₁ | ⟨i,hi,u,hu,heq⟩ + · exact Finset.disjoint_left.mp hKZ₁ hD hD₁ + · have hoi : D.owner = (A i).owner := congrArg Record.owner heq + exact (mem_erase.mp hi).1 (hAi (mem_of_mem_erase hi) hj (hoi.symm.trans (hKown D hD))) + refine ⟨Z₂,K₁∪K₂,hZ₂,union_subset hKAf hKF₂,?_,disjoint_union_left.mpr ⟨hKZ,hKZ₂⟩, + ?_,?_,fun B hh => hint₁ B (hint₂ B hh),?_,?_⟩ + · intro D hD + rcases mem_union.mp hD with hD | hD + · exact ⟨j,hj,hKown D hD⟩ + · obtain ⟨i,hi,hh⟩ := hKown₂ D hD + exact ⟨i,mem_of_mem_erase hi,hh⟩ + · intro D hD hint + rcases mem_union.mp hD with hD | hD + · exact hbor₁ D hD (hint₂ D hint) + · exact hbor₂ D hD hint + · have hsum := sum_erase_add J (fun i => ((A i).centers.card : ℝ)) hj + have hcard : ((K₁∪K₂).card : ℝ) = (K₁.card : ℝ)+(K₂.card : ℝ) := by + exact_mod_cast card_union_of_disjoint hdis + rw [hcard,←hsum] + dsimp [AssignedAccounting.theta] at hcredit₁ hcredit₂ ⊢ + nlinarith + · intro D hD + rcases hown₂ D hD with ⟨i,hi,hh⟩ | ⟨B,hB,hh⟩ + · exact Or.inl ⟨i,mem_of_mem_erase hi,hh⟩ + · rcases hown₁ B hB with heq | ⟨C,hC,heq⟩ + · exact Or.inl ⟨j,hj,hh.trans heq⟩ + · exact Or.inr ⟨C,hC,hh.trans heq⟩ + · intro D hD hDF + rcases hfresh₂ D hD hDF with hD | ⟨i,hi,u,hu,heq⟩ + · rcases hfresh₁ D hD hDF with hD | ⟨u,hu,heq⟩ + · exact Or.inl hD + · exact Or.inr ⟨j,hj,u,hu,heq⟩ + · exact Or.inr ⟨i,mem_of_mem_erase hi,u,hu,heq⟩ + · have he : J = ∅ := not_nonempty_iff_eq_empty.mp hn + subst J + refine ⟨Z,∅,hZ,empty_subset _,?_,disjoint_empty_left _,?_,?_,fun _ hh => hh,?_,?_⟩ + · simp + · simp + · simp + · intro D hD + exact Or.inr ⟨D,hD,rfl⟩ + · intro D hD _ + exact Or.inl hD + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {δ η : ℝ} + +lemma assigned_phase {ι : Type*} [DecidableEq ι] + (A : ι → AssignedBag H G X δ η) (P : ι → Finset (Finset (Fin n))) + (hX : ∀v, isProfile (X v)) {q ε : ℝ} (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) (hη : 3072/q ≤ η) + (hδ : 0 < δ) (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) + (J : Finset ι) (hAi : Set.InjOn (fun i => (A i).owner) J) + (hvalid : ∀i ∈ J, ∀u ∈ (A i).centers, ((A i).input (P i) u).Valid H G X (q/4)) + (hgeo : ∀i ∈ J, ∀u ∈ (A i).centers, ∀j ∈ J, ∀v ∈ (A j).centers, + ((A i).input (P i) u) ≠ ((A j).input (P j) v) → + Disjoint ((RadialShell.ball u δ).support X) ((RadialShell.ball v δ).support X)) + (Z : Finset (Record n)) (hZ : LabeledArrangement H G X (q/4) Z) + (horder : ∀i ∈ J, ∀D ∈ Z, D.owner ⊂ (A i).owner → D.owner ∈ P i) + (howner : ∀i ∈ J, ∀D ∈ Z, D.owner ≠ (A i).owner) : + ∃Z' : Finset (Record n), LabeledArrangement H G X (q/4) Z' ∧ + (∑D ∈ Z, D.baseToken δ)+(AssignedAccounting.theta/2)* + (∑i ∈ J, ((A i).centers.card : ℝ))*δ ≤ ∑D ∈ Z', D.baseToken ε ∧ + (∀D ∈ Z', (∃i ∈ J, D.owner = (A i).owner) ∨ ∃B ∈ Z, D.owner = B.owner) := by + let F := J.biUnion (fun i => ((A i).centers.image ((A i).input (P i)))) + have hFmem : ∀D : Record n, D ∈ F ↔ ∃i ∈ J, ∃u ∈ (A i).centers, D = (A i).input (P i) u := by + intro D + simp only [F,mem_biUnion,mem_image] + constructor + · rintro ⟨i,hi,u,hu,heq⟩ + exact ⟨i,hi,u,hu,heq.symm⟩ + · rintro ⟨i,hi,u,hu,heq⟩ + exact ⟨i,hi,u,hu,heq.symm⟩ + have hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none := by + intro D hD + obtain ⟨i,hi,u,hu,rfl⟩ := (hFmem D).mp hD + simp [AssignedBag.input,RadialShell.ball,RadialShell.width] + have hFball : ∀B ∈ F, B.shell = RadialShell.ball B.shell.center δ := by + intro D hD + obtain ⟨i,hi,u,hu,rfl⟩ := (hFmem D).mp hD + rfl + have hFg : ∀B ∈ F, ∀D ∈ F, B ≠ D → Disjoint (B.shell.support X) (D.shell.support X) := by + intro B hB D hD hne + obtain ⟨i,hi,u,hu,rfl⟩ := (hFmem B).mp hB + obtain ⟨j,hj,v,hv,rfl⟩ := (hFmem D).mp hD + exact hgeo i hi u hu j hj v hv hne + have hFv : LabeledArrangement H G X (q/4) F := by + refine ⟨?_,?_⟩ + · intro D hD + obtain ⟨i,hi,u,hu,rfl⟩ := (hFmem D).mp hD + exact hvalid i hi u hu + · intro B hB D hD hne hh + exact (hh (hFg B hB D hD hne)).elim + have hAF : ∀i ∈ J, ∀u ∈ (A i).centers, (A i).input (P i) u ∈ F := + fun i hi u hu => (hFmem _).mpr ⟨i,hi,u,hu,rfl⟩ + obtain ⟨Z₁,K,hZ₁,hKF,hKo,hKZ,hbor,hcredit,hint,hown,hfresh⟩ := + phase_loops A P hX hq hconn hη hscale hF J hAi hAF hvalid Z hZ horder howner + obtain ⟨Z₂,hZ₂,hcredit₂,hown₂⟩ := + border_transition hX hδ hε hscale hF hFball hFg hFv hZ₁ hKF hKZ hbor + have hsum : ∑D ∈ Z, D.phaseToken F δ ε = ∑D ∈ Z, D.baseToken δ := by + apply sum_congr rfl + intro D hD + have hn : D ∉ F := by + intro hf + obtain ⟨i,hi,u,hu,heq⟩ := (hFmem D).mp hf + exact howner i hi D hD (congrArg Record.owner heq) + simp only [Record.phaseToken,ite_eq_right hn,Record.baseToken] + refine ⟨Z₂,hZ₂,?_,?_⟩ + · rw [hsum] at hcredit + linarith + · intro D hD + rcases hown₂ D hD with hDK | ⟨B,hB,heq⟩ + · exact Or.inl (hKo D hDK) + · rcases hown B hB with ⟨i,hi,hoi⟩ | ⟨C,hC,hoi⟩ + · exact Or.inl ⟨i,hi,heq.trans hoi⟩ + · exact Or.inr ⟨C,hC,heq.trans hoi⟩ + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {η : ℝ} + +structure AssignedFamily (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Doubled Coord → ℝ) (η : ℝ) where + radius : ℝ + positive : 0 < radius + count : ℕ + bag : Fin count → AssignedBag H G X radius η + owner_injective : Function.Injective (fun i => (bag i).owner) + separated : ∀i, ∀u ∈ (bag i).centers, ∀j, ∀v ∈ (bag j).centers, + (i ≠ j ∨ u ≠ v) → Disjoint ((RadialShell.ball u radius).support X) + ((RadialShell.ball v radius).support X) + +namespace AssignedFamily +variable (F : AssignedFamily H G X η) + +def owners : Finset (Finset (Fin n)) := univ.image (fun i => (F.bag i).owner) +def mass : ℝ := (∑i, ((F.bag i).centers.card : ℝ))*F.radius +def predecessors (E : Finset (Finset (Fin n))) (i : Fin F.count) : Finset (Finset (Fin n)) := + E.filter (fun S => S ⊂ (F.bag i).owner) + +def ProtectedFrom (E : Finset (Finset (Fin n))) : Prop := + ∀i, ∀u ∈ (F.bag i).centers, ((F.bag i).input (F.predecessors E i) u).Protected G X + +lemma owner_mem (i : Fin F.count) : (F.bag i).owner ∈ F.owners := mem_image.mpr ⟨i,mem_univ _,rfl⟩ +lemma owners_nodes : F.owners ⊆ H.nodes := by + intro S hS + obtain ⟨i,hi,rfl⟩ := mem_image.mp hS + exact (F.bag i).owner_mem + +lemma input_valid {q : ℝ} (hX : ∀v, isProfile (X v)) (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) (hη : 3072/q ≤ η) + {E : Finset (Finset (Fin n))} (hE : E ⊆ H.nodes) (hprot : F.ProtectedFrom E) + (i : Fin F.count) {u : Fin n} (hu : u ∈ (F.bag i).centers) : + ((F.bag i).input (F.predecessors E i) u).Valid H G X (q/4) := by + have hbound := parent_boundary_lower H G hconn (F.bag i).owner_mem (F.bag i).nonroot + have hassign := (F.bag i).assignment + have hc : (3072:ℝ) ≤ ((F.bag i).centers.card : ℝ) := by + have ha := mul_le_mul_of_nonneg_right hη (Nat.cast_nonneg (parentBoundary H G (F.bag i).owner).card) + have hb := mul_le_mul_of_nonneg_left hbound (show 0 ≤ (3072:ℝ)/q by positivity) + have heq : (3072:ℝ)/q*q = 3072 := by field_simp + rw [heq] at hb + linarith + apply (F.bag i).input_valid hX hq.le hconn + (by exact_mod_cast (show (1:ℝ) < ((F.bag i).centers.card : ℝ) by linarith)) + (fun S hS => ⟨hE (mem_filter.mp hS).1,(mem_filter.mp hS).2⟩) hu (hprot i u hu) + +lemma phase {q ε : ℝ} (hX : ∀v, isProfile (X v)) (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) (hη : 3072/q ≤ η) + (hε : 0 ≤ ε) (hscale : ε ≤ F.radius/1536) + {E : Finset (Finset (Fin n))} (hE : E ⊆ H.nodes) (hprot : F.ProtectedFrom E) + (hdis : Disjoint E F.owners) + (Z : Finset (Record n)) (hZ : LabeledArrangement H G X (q/4) Z) + (hown : ∀D ∈ Z, D.owner ∈ E) : + ∃Z' : Finset (Record n), LabeledArrangement H G X (q/4) Z' ∧ + (∑D ∈ Z, D.baseToken F.radius)+(AssignedAccounting.theta/2)*F.mass ≤ + ∑D ∈ Z', D.baseToken ε ∧ (∀D ∈ Z', D.owner ∈ E∪F.owners) := by + obtain ⟨Z',hZ',hc,ho⟩ := assigned_phase F.bag (F.predecessors E) hX hq hconn hη + F.positive hε hscale univ F.owner_injective.injOn + (fun i _ u hu => F.input_valid hX hq hconn hη hE hprot i hu) + (by + intro i hi u hu j hj v hv hne + apply F.separated i u hu j v hv + by_cases hh : i = j + · right + intro he + subst j; subst v + exact hne rfl + · exact Or.inl hh) + Z hZ + (fun i _ D hD hs => mem_filter.mpr ⟨hown D hD,hs⟩) + (fun i _ D hD heq => Finset.disjoint_left.mp hdis (hown D hD) (heq ▸ F.owner_mem i)) + refine ⟨Z',hZ',?_,?_⟩ + · simpa only [mass,mul_assoc] using hc + · intro D hD + rcases ho D hD with ⟨i,hi,heq⟩ | ⟨B,hB,heq⟩ + · exact mem_union_right _ (heq ▸ F.owner_mem i) + · exact mem_union_left _ (heq ▸ hown B hB) + +end AssignedFamily + +namespace AssignedSequence +abbrev Family := AssignedFamily H G X η + +def initialRadius : List (Family (H := H) (G := G) (X := X) (η := η)) → ℝ + | [] => 0 + | F::_ => F.radius + +def mass : List (Family (H := H) (G := G) (X := X) (η := η)) → ℝ + | [] => 0 + | F::L => F.mass+mass L + +def Geometric : List (Family (H := H) (G := G) (X := X) (η := η)) → Prop + | [] => True + | F::L => initialRadius L ≤ F.radius/1536 ∧ Geometric L + +def Ready (E : Finset (Finset (Fin n))) : List (Family (H := H) (G := G) (X := X) (η := η)) → Prop + | [] => True + | F::L => Disjoint E F.owners ∧ F.ProtectedFrom E ∧ Ready (E∪F.owners) L + +lemma radius_nonneg (L : List (Family (H := H) (G := G) (X := X) (η := η))) : + 0 ≤ initialRadius L := by + cases L with + | nil => exact le_refl _ + | cons F L => exact F.positive.le + +lemma construct {q : ℝ} (hX : ∀v, isProfile (X v)) (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) (hη : 3072/q ≤ η) + (L : List (Family (H := H) (G := G) (X := X) (η := η))) + (hgeo : Geometric L) (E : Finset (Finset (Fin n))) (hE : E ⊆ H.nodes) + (hready : Ready E L) (Z : Finset (Record n)) (hZ : LabeledArrangement H G X (q/4) Z) + (hown : ∀D ∈ Z, D.owner ∈ E) {credit : ℝ} + (hcredit : credit ≤ ∑D ∈ Z, D.baseToken (initialRadius L)) : + ∃Z' : Finset (Record n), LabeledArrangement H G X (q/4) Z' ∧ + credit+(AssignedAccounting.theta/2)*mass L ≤ ∑D ∈ Z', D.shell.width := by + induction L generalizing E Z credit with + | nil => + refine ⟨Z,hZ,?_⟩ + simp only [mass,mul_zero,add_zero] at * + apply hcredit.trans + exact sum_le_sum (fun D hD => AssignedAccounting.base_le_width D.avoided.isSome + (by have hh := (hZ.1 D hD).2.2.1.2.1; dsimp [RadialShell.width]; linarith) (le_refl _)) + | cons F L ih => + obtain ⟨Z₁,hZ₁,hstep,hown₁⟩ := F.phase hX hq hconn hη (radius_nonneg L) + hgeo.1 hE hready.2.1 hready.1 Z hZ hown + have hc : credit+(AssignedAccounting.theta/2)*F.mass ≤ + ∑D ∈ Z₁, D.baseToken (initialRadius L) := by + change credit ≤ ∑D ∈ Z, D.baseToken F.radius at hcredit + linarith + obtain ⟨Z₂,hZ₂,hc₂⟩ := ih hgeo.2 (E∪F.owners) (union_subset hE F.owners_nodes) + hready.2.2 Z₁ hZ₁ hown₁ hc + refine ⟨Z₂,hZ₂,?_⟩ + dsimp [mass] + linarith + +lemma insertable_bound {q : ℝ} (hX : ∀v, isProfile (X v)) (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) (hη : 3072/q ≤ η) + (L : List (Family (H := H) (G := G) (X := X) (η := η))) + (hgeo : Geometric L) (hready : Ready ∅ L) : + (q/4096)*mass L ≤ ∑e : Fin m, normDistance (X (G.left e)) (X (G.right e)) := by + have hempty : LabeledArrangement H G X (q/4) ∅ := by constructor <;> simp + obtain ⟨Z,hZ,hwidth⟩ := construct hX hq hconn hη L hgeo ∅ (empty_subset _) hready + ∅ hempty (by simp) (credit := 0) (by simp) + have he := labeled_energy H G X hX hZ + have hh := mul_le_mul_of_nonneg_left hwidth (show 0 ≤ q/4 by positivity) + dsimp [AssignedAccounting.theta] at hh + nlinarith + +end AssignedSequence +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} {η : ℝ} + +namespace AssignedFamily +variable (F : AssignedFamily H G X η) + +def goodCenters (E : Finset (Finset (Fin n))) (i : Fin F.count) : Finset (Fin n) := + (F.bag i).centers.filter (fun u => ((F.bag i).input (F.predecessors E i) u).Protected G X) + +def badCenters (E : Finset (Finset (Fin n))) (i : Fin F.count) : Finset (Fin n) := + (F.bag i).centers\F.goodCenters E i + +def badCount (E : Finset (Finset (Fin n))) : ℕ := ∑i, (F.badCenters E i).card + +def boundaryCount (G : MultiGraph n m) (E : Finset (Finset (Fin n))) : ℕ := + ∑S ∈ E, (G.cut univ S).card + +lemma bad_witness {E : Finset (Finset (Fin n))} (i : Fin F.count) {u : Fin n} + (hu : u ∈ F.badCenters E i) : + ∃S ∈ E, ∃e ∈ G.cut univ S, ∃v : Fin n, + (v = G.left e ∨ v = G.right e) ∧ normDistance (X v) (X u) < F.radius := by + have hn : ¬((F.bag i).input (F.predecessors E i) u).Protected G X := by + intro hh + exact (mem_sdiff.mp hu).2 (mem_filter.mpr ⟨(mem_sdiff.mp hu).1,hh⟩) + simp only [Record.Protected,not_forall] at hn + obtain ⟨S,hS,e,he,hn⟩ := hn + have hSE : S ∈ E := (mem_filter.mp hS).1 + change ¬(F.radius ≤ normDistance (X (G.left e)) (X u) ∧ + F.radius ≤ normDistance (X (G.right e)) (X u)) at hn + by_cases hl : normDistance (X (G.left e)) (X u) < F.radius + · exact ⟨S,hSE,e,he,G.left e,Or.inl rfl,hl⟩ + · exact ⟨S,hSE,e,he,G.right e,Or.inr rfl,lt_of_not_ge (fun hr => hn ⟨le_of_not_gt hl,hr⟩)⟩ + +lemma badCount_le (hX : ∀v, isProfile (X v)) (E : Finset (Finset (Fin n))) : + F.badCount E ≤ 2*boundaryCount G E := by + let B := univ.sigma (F.badCenters E) + let W := E.biUnion (fun S => (G.cut univ S).biUnion (fun e => {G.left e,G.right e})) + have hBW : ∀p ∈ B, ∃v ∈ W, normDistance (X v) (X p.2) < F.radius := by + intro p hp + obtain ⟨S,hS,e,he,v,hv,hd⟩ := F.bad_witness p.1 (mem_sigma.mp hp).2 + refine ⟨v,mem_biUnion.mpr ⟨S,hS,mem_biUnion.mpr ⟨e,he,?_⟩⟩,hd⟩ + simp only [mem_insert,mem_singleton] + exact hv + choose f hfW hfd using hBW + have hinj : ∀p hp q hq, f p hp = f q hq → p = q := by + intro p hp r hr heq + by_contra hh + have hne : p.1 ≠ r.1 ∨ p.2 ≠ r.2 := by + by_contra hn + push Not at hn + exact hh (Sigma.ext hn.1 (heq_of_eq hn.2)) + have hd := F.separated p.1 p.2 (mem_sdiff.mp (mem_sigma.mp hp).2).1 + r.1 r.2 (mem_sdiff.mp (mem_sigma.mp hr).2).1 hne + have ha : X (f p hp) ∈ (RadialShell.ball p.2 F.radius).support X := by + rw [RadialShell.support_ball] + exact ⟨isProfile_inPolytope (hX _),hfd p hp⟩ + have hb : X (f p hp) ∈ (RadialShell.ball r.2 F.radius).support X := by + rw [RadialShell.support_ball,heq] + exact ⟨isProfile_inPolytope (hX _),hfd r hr⟩ + exact Set.disjoint_left.mp hd ha hb + have hcard : B.card ≤ W.card := by + apply Finset.card_le_card_of_injective (f := fun p : B => (⟨f p.val p.property,hfW p.val p.property⟩ : W)) + intro p r heq + exact Subtype.ext (hinj p.val p.property r.val r.property (congrArg Subtype.val heq)) + have hW : W.card ≤ 2*boundaryCount G E := by + calc + W.card ≤ ∑S ∈ E, ((G.cut univ S).biUnion (fun e => {G.left e,G.right e})).card := card_biUnion_le + _ ≤ ∑S ∈ E, ∑e ∈ G.cut univ S, ({G.left e,G.right e} : Finset (Fin n)).card := + sum_le_sum (fun S hS => card_biUnion_le) + _ ≤ ∑S ∈ E, ∑_e ∈ G.cut univ S, 2 := + sum_le_sum (fun S hS => sum_le_sum (fun e he => card_le_two)) + _ = _ := by simp [boundaryCount,mul_sum,Nat.mul_comm] + have heq : B.card = F.badCount E := by simp [B,badCount,Finset.card_sigma] + rw [heq] at hcard + exact hcard.trans hW + +lemma prune (E : Finset (Finset (Fin n))) {η' : ℝ} (hη : 2*η' ≤ η) : + ∃F' : AssignedFamily H G X η', F'.radius = F.radius ∧ F'.owners ⊆ F.owners ∧ + (∀E' ⊆ E, F'.ProtectedFrom E') ∧ + F.mass-2*(F.badCount E : ℝ)*F.radius ≤ F'.mass := by + let J := univ.filter (fun i : Fin F.count => (F.bag i).centers.card ≤ 2*(F.goodCenters E i).card) + let e : Fin (Fintype.card J) ≃ J := (Fintype.equivFin J).symm + have hnon : ∀i ∈ J, (F.goodCenters E i).Nonempty := by + intro i hi + apply card_pos.mp + have hn := card_pos.mpr (F.bag i).nonempty + have hc := (mem_filter.mp hi).2 + omega + let a (i : J) : AssignedBag H G X F.radius η' := { + owner := (F.bag i.val).owner + owner_mem := (F.bag i.val).owner_mem + nonroot := (F.bag i.val).nonroot + centers := F.goodCenters E i.val + nonempty := hnon i.val i.property + radius_pos := F.positive + disjoint := (F.bag i.val).disjoint.mono (filter_subset _ _) + assignment := by + have hc : ((F.bag i.val).centers.card : ℝ) ≤ 2*((F.goodCenters E i.val).card : ℝ) := by + exact_mod_cast (mem_filter.mp i.property).2 + have hh := mul_le_mul_of_nonneg_right hη (Nat.cast_nonneg (parentBoundary H G (F.bag i.val).owner).card) + have ha := (F.bag i.val).assignment + nlinarith + endpoint := fun u hu => (F.bag i.val).endpoint u (mem_filter.mp hu).1 } + let F' : AssignedFamily H G X η' := { + radius := F.radius + positive := F.positive + count := Fintype.card J + bag := fun i => a (e i) + owner_injective := by + intro i j hij + apply e.injective + apply Subtype.ext + exact F.owner_injective hij + separated := by + intro i u hu j v hv hne + apply F.separated (e i).val u (mem_filter.mp hu).1 (e j).val v (mem_filter.mp hv).1 + rcases hne with hne | hne + · left + intro hh + exact hne (e.injective (Subtype.ext hh)) + · exact Or.inr hne } + have hsum : ∑i : Fin F'.count, ((F'.bag i).centers.card : ℝ) = + ∑i ∈ J, ((F.goodCenters E i).card : ℝ) := by + change (∑i : Fin (Fintype.card J), ((F.goodCenters E (e i).val).card : ℝ)) = _ + rw [e.sum_comp (fun i : J => ((F.goodCenters E i.val).card : ℝ))] + exact Finset.sum_coe_sort J (fun i : Fin F.count => ((F.goodCenters E i).card : ℝ)) + have hgood : ∀i, ((F.bag i).centers.card : ℝ) ≤ + (if i ∈ J then ((F.goodCenters E i).card : ℝ) else 0)+2*((F.badCenters E i).card : ℝ) := by + intro i + have hc : ((F.badCenters E i).card : ℝ)+((F.goodCenters E i).card : ℝ) = + ((F.bag i).centers.card : ℝ) := by + exact_mod_cast card_sdiff_add_card_eq_card (filter_subset (fun u => + ((F.bag i).input (F.predecessors E i) u).Protected G X) (F.bag i).centers) + by_cases hi : i ∈ J + · rw [ite_eq_left hi] + nlinarith [show (0:ℝ) ≤ (F.badCenters E i).card from Nat.cast_nonneg _] + · rw [ite_eq_right hi] + have hh : 2*(F.goodCenters E i).card < (F.bag i).centers.card := by + simpa only [J,mem_filter,mem_univ,true_and,not_le] using hi + have hh' : 2*((F.goodCenters E i).card : ℝ) < ((F.bag i).centers.card : ℝ) := by exact_mod_cast hh + linarith + have hcount := Finset.sum_le_sum (s := univ) (fun i _ => hgood i) + have hcounts : (∑i, ((F.bag i).centers.card : ℝ))-2*(F.badCount E : ℝ) ≤ + ∑i ∈ J, ((F.goodCenters E i).card : ℝ) := by + rw [sum_add_distrib,←mul_sum] at hcount + have heq : (∑i, if i ∈ J then ((F.goodCenters E i).card : ℝ) else 0) = + ∑i ∈ J, ((F.goodCenters E i).card : ℝ) := by simp + rw [heq] at hcount + apply sub_le_iff_le_add.mpr + simpa only [badCount,Nat.cast_sum] using hcount + refine ⟨F',rfl,?_,?_,?_⟩ + · intro S hS + obtain ⟨i,hi,rfl⟩ := mem_image.mp hS + exact F.owner_mem (e i).val + · intro E' hE' i u hu S hS edge hedge + have hp := (mem_filter.mp hu).2 + exact hp S (mem_filter.mpr ⟨hE' (mem_filter.mp hS).1,(mem_filter.mp hS).2⟩) edge hedge + · dsimp [mass] + rw [hsum] + nlinarith [mul_le_mul_of_nonneg_right hcounts F.positive.le] + +end AssignedFamily +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (mem_domain mem_leaves) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open StrongThinTree.Geometry (clamp) +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} + +namespace AssignedFamily +variable {q : ℝ} (F : AssignedFamily H G X (6144/q)) + +def BoundaryRatio (ρ : ℝ) : Prop := ∀i, + (q*ρ)*((G.cut univ (F.bag i).owner).card : ℝ) ≤ (parentBoundary H G (F.bag i).owner).card + +lemma boundary_mass {ρ : ℝ} (hq : 0 < q) (hR : F.BoundaryRatio ρ) : + 6144*ρ*(boundaryCount G F.owners : ℝ)*F.radius ≤ F.mass := by + have he : (boundaryCount G F.owners : ℝ) = + ∑i, ((G.cut univ (F.bag i).owner).card : ℝ) := by + simp only [boundaryCount,owners,Nat.cast_sum] + exact sum_image F.owner_injective.injOn + have hi : ∀i, (6144*ρ)*((G.cut univ (F.bag i).owner).card : ℝ) ≤ ((F.bag i).centers.card : ℝ) := by + intro i + have hh := mul_le_mul_of_nonneg_left (hR i) (show 0 ≤ (6144:ℝ)/q by positivity) + have hx : (6144:ℝ)/q*((q*ρ)*((G.cut univ (F.bag i).owner).card : ℝ)) = + (6144*ρ)*((G.cut univ (F.bag i).owner).card : ℝ) := by field_simp + rw [hx] at hh + exact hh.trans (F.bag i).assignment + rw [he] + dsimp [mass] + apply mul_le_mul_of_nonneg_right _ F.positive.le + rw [mul_sum] + exact sum_le_sum (fun i _ => hi i) +end AssignedFamily + +namespace AssignedSequence +open AssignedFamily +variable {q : ℝ} + +def Fresh (E : Finset (Finset (Fin n))) : List (AssignedFamily H G X (6144/q)) → Prop + | [] => True + | F::L => Disjoint E F.owners ∧ Fresh (E∪F.owners) L + +def Ratios (ρ : ℝ) : List (AssignedFamily H G X (6144/q)) → Prop + | [] => True + | F::L => F.BoundaryRatio ρ ∧ Ratios ρ L + +def GeometricAt {η : ℝ} (ρ : ℝ) : List (AssignedFamily H G X η) → Prop + | [] => True + | F::L => initialRadius L ≤ ρ*F.radius ∧ GeometricAt ρ L + +lemma geometric_of {η ρ : ℝ} (hρ : ρ ≤ 1/1536) + (L : List (AssignedFamily H G X η)) (hL : GeometricAt ρ L) : Geometric L := by + induction L with + | nil => trivial + | cons F L ih => + refine ⟨?_,ih hL.2⟩ + have hh := mul_le_mul_of_nonneg_right hρ F.positive.le + linarith [hL.1] + +lemma prune_sequence (hX : ∀v, isProfile (X v)) (hq : 0 < q) + {ρ : ℝ} (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (L : List (AssignedFamily H G X (6144/q))) + (hgeo : GeometricAt ρ L) (hR : Ratios ρ L) + (E E' : Finset (Finset (Fin n))) (hE : E ⊆ H.nodes) (hE' : E' ⊆ E) + (hfresh : Fresh E L) : + ∃L' : List (AssignedFamily H G X (3072/q)), initialRadius L' = initialRadius L ∧ + GeometricAt ρ L' ∧ Ready E' L' ∧ + mass L/2-8*(initialRadius L)*(boundaryCount G E : ℝ) ≤ mass L' := by + induction L generalizing E E' with + | nil => exact ⟨[],rfl,True.intro,True.intro,by simp [mass,initialRadius]⟩ + | cons F L ih => + obtain ⟨F',hrad,howners,hprot,hgain⟩ := F.prune E (η' := 3072/q) (by field_simp; ring_nf; rfl) + have hE₁ : E∪F.owners ⊆ H.nodes := union_subset hE F.owners_nodes + obtain ⟨L',headEq,hgeo',hready',hgain'⟩ := ih hgeo.2 hR.2 + (E∪F.owners) (E'∪F'.owners) hE₁ (union_subset_union hE' howners) hfresh.2 + have hdis : Disjoint E' F'.owners := hfresh.1.mono hE' howners + have hBC : (boundaryCount G (E∪F.owners) : ℝ) = + (boundaryCount G E : ℝ)+(boundaryCount G F.owners : ℝ) := by + simp only [boundaryCount,sum_union hfresh.1,Nat.cast_add] + have hb := F.badCount_le hX E + have hb' : (F.badCount E : ℝ) ≤ 2*(boundaryCount G E : ℝ) := by exact_mod_cast hb + have hpf : F.mass-4*F.radius*(boundaryCount G E : ℝ) ≤ F'.mass := by + have hh := mul_le_mul_of_nonneg_right hb' F.positive.le + nlinarith + have hr := F.boundary_mass hq hR.1 + have heps := radius_nonneg L + have hsc := hgeo.1 + have hsmall := mul_le_mul_of_nonneg_right hρsmall F.positive.le + have hcoal : 4*F.radius+8*initialRadius L ≤ 8*F.radius := by linarith + have hB0 : (0:ℝ) ≤ boundaryCount G E := Nat.cast_nonneg _ + have hBF0 : (0:ℝ) ≤ boundaryCount G F.owners := Nat.cast_nonneg _ + have hc := mul_le_mul_of_nonneg_right hsc hBF0 + have hcost : 8*initialRadius L*(boundaryCount G F.owners : ℝ) ≤ F.mass/2 := by + have hpos : 0 ≤ ρ*F.radius*(boundaryCount G F.owners : ℝ) := + mul_nonneg (mul_nonneg hρ.le F.positive.le) hBF0 + nlinarith + have hprev := mul_le_mul_of_nonneg_right hcoal hB0 + refine ⟨F'::L',hrad,⟨?_,hgeo'⟩,⟨hdis,hprot E' hE',hready'⟩,?_⟩ + · simpa only [headEq,hrad] using hsc + · rw [hBC] at hgain' + dsimp [mass,initialRadius] + nlinarith + +lemma assigned_bound (hX : ∀v, isProfile (X v)) {q : ℝ} (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) + {ρ : ℝ} (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (L : List (AssignedFamily H G X (6144/q))) + (hgeo : GeometricAt ρ L) (hR : Ratios ρ L) (hfresh : Fresh ∅ L) : + (q/8192)*mass L ≤ ∑e : Fin m, normDistance (X (G.left e)) (X (G.right e)) := by + obtain ⟨L',hrad,hgeo',hready',hmass⟩ := prune_sequence hX hq hρ hρsmall L hgeo hR ∅ ∅ + (empty_subset _) (Subset.refl _) hfresh + have hcharge := insertable_bound hX hq hconn (le_refl (3072/q)) L' (geometric_of hρsmall L' hgeo') hready' + have hmass' : mass L/2 ≤ mass L' := by simpa [boundaryCount] using hmass + have hh := mul_le_mul_of_nonneg_left hmass' (show 0 ≤ q/4096 by positivity) + nlinarith + +end AssignedSequence +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/AssignedGeometry.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/AssignedGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..156545bb899ce166f8805815cf268e44b5b1710c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/AssignedGeometry.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.CompactCharging + +namespace OAI + +/-! Metric assigned geometry. -/ + +section + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry +noncomputable section +open Finset +open StrongThinTree.Geometry (clamp clamped_affine_disjoint_sum) + +variable {J : Type*} [Fintype J] [PseudoMetricSpace J] + +omit [PseudoMetricSpace J] in +lemma normDistance_nonneg (x y : J → ℝ) : 0 ≤ normDistance x y := norm_nonneg _ + +omit [PseudoMetricSpace J] in +lemma normDistance_reverse (x y z : J → ℝ) : + |normDistance x z-normDistance y z| ≤ normDistance x y := by + simpa only [normDistance,sub_sub_sub_cancel_right] using + abs_norm_sub_norm_le (x-z) (y-z) + +lemma profile_shell_edge_bound {I : Type*} [Fintype I] + {x y : J → ℝ} (hx : inPolytope x) (hy : inPolytope y) + (z : I → J → ℝ) (hz : ∀i, isProfile (z i)) (a b : I → ℝ) + (hab : ∀i, a i ≤ b i) + (hdis : ∀i j, i ≠ j → ∀w, inPolytope w → + ¬(a i < normDistance w (z i) ∧ normDistance w (z i) x j+t*(y j-x j)) (inPolytope_segment hx hy htc) + simpa only [isProfile_radial_affine hx hy (hz i) htc, + isProfile_radial_affine hx hy (hz j) htc] using hbad + +lemma profile_radial_max {x z : Doubled J → ℝ} (hx : isProfile x) (hz : inPolytope z) : + normDistance z x ≤ commonRadius J := by + obtain ⟨⟨s,a⟩,rfl⟩ := hx + have h := opposite_radii hz a + cases s + · change normDistance z (profile (minus a)) ≤ commonRadius J + unfold normDistance + linarith [norm_nonneg (z-profile (plus a))] + · change normDistance z (profile (plus a)) ≤ commonRadius J + unfold normDistance + linarith [norm_nonneg (z-profile (minus a))] + +lemma profile_radial_move {x z : Doubled J → ℝ} (hx : isProfile x) (hz : inPolytope z) + {r : ℝ} (hr : 0 ≤ r) (hrmax : r ≤ commonRadius J) : + ∃w : Doubled J → ℝ, inPolytope w ∧ normDistance w x = r ∧ + normDistance w z = |r-normDistance z x| := by + obtain ⟨⟨s,a⟩,rfl⟩ := hx + cases s + · obtain ⟨w,hw,hwplus,hwz⟩ := radial_motion hz a + (show commonRadius J-r ∈ Set.Icc (0:ℝ) (commonRadius J) from + ⟨by linarith,by linarith⟩) + have hwp := opposite_radii hw a + have hzp := opposite_radii hz a + refine ⟨w,hw,?_,?_⟩ + · change ‖w-profile (minus a)‖ = r + linarith + · change ‖w-z‖ = |r-‖z-profile (minus a)‖| + rw [hwz] + have heq : commonRadius J-r-‖z-profile (plus a)‖ = + -(r-‖z-profile (minus a)‖) := by linarith + rw [heq,abs_neg] + · exact radial_motion hz a ⟨hr,hrmax⟩ + +namespace RadialShell +variable {V : Type*} {X : V → Doubled J → ℝ} + +lemma ball_meets_radial {B : RadialShell V} (hX : ∀v, isProfile (X v)) + (hB : B.Valid X) (z : V) {δ : ℝ} (hδ : 0 < δ) + (hlo : B.inner-δ < normDistance (X z) (X B.center)) + (hhi : normDistance (X z) (X B.center) < B.outer+δ) : + ¬Disjoint ((ball z δ).support X) (B.support X) := by + have hinterval : max B.inner (normDistance (X z) (X B.center)-δ) < + min B.outer (normDistance (X z) (X B.center)+δ) := by + rw [max_lt_iff,lt_min_iff,lt_min_iff] + exact ⟨⟨hB.2.1,by linarith⟩,⟨by linarith,by linarith⟩⟩ + obtain ⟨r,hl,hr⟩ := exists_between hinterval + have hlo' : B.inner < r := (le_max_left _ _).trans_lt hl + have hhi' : r < B.outer := hr.trans_le (min_le_left _ _) + have hradlo : normDistance (X z) (X B.center)-δ < r := (le_max_right _ _).trans_lt hl + have hradhi : r < normDistance (X z) (X B.center)+δ := hr.trans_le (min_le_right _ _) + obtain ⟨v,hv⟩ := hB.2.2.2.2 + have hmax : B.outer ≤ commonRadius J := hv.trans (profile_radial_max (hX _) (isProfile_inPolytope (hX v))) + obtain ⟨w,hw,hwr,hwz⟩ := profile_radial_move (hX B.center) (isProfile_inPolytope (hX z)) + (hB.1.trans hlo'.le) (hhi'.le.trans hmax) + have hwA : w ∈ (ball z δ).support X := by + rw [support_ball] + refine ⟨hw,?_⟩ + rw [hwz,abs_lt] + constructor <;> linarith + have hwB : w ∈ B.support X := ⟨hw,hwr ▸ hhi',Or.inr (hwr ▸ hlo')⟩ + exact fun hdis => Set.disjoint_left.mp hdis hwA hwB + +end RadialShell +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/BagExtraction.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/BagExtraction.lean new file mode 100644 index 0000000000000000000000000000000000000000..704e090593d72fa5a4b6d6deb6f6551bf4e87f09 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/BagExtraction.lean @@ -0,0 +1,610 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.AssignedCharging + +namespace OAI + +/-! Metric bag extraction. -/ + +section + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry +noncomputable section +open Finset +open StrongThinTree.Geometry (retain_fibers) +open scoped Classical +variable {V I : Type*} [DecidableEq V] [DecidableEq I] {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] + +omit [DecidableEq V] in +lemma distance_balls_disjoint (X : V → Coord → ℝ) (u v : V) {r : ℝ} + (hsep : 2*r ≤ normDistance (X u) (X v)) : + Disjoint ((RadialShell.ball u r).support X) ((RadialShell.ball v r).support X) := by + apply Set.disjoint_left.mpr + intro z hz hz' + have hx := normDistance_triangle (X u) z (X v) + rw [normDistance_comm (X u) z] at hx + have hz₁ := hz.2.1 + have hz₂ := hz'.2.1 + change normDistance z (X u) < r at hz₁ + change normDistance z (X v) < r at hz₂ + linarith + +omit [PseudoMetricSpace Coord] in +lemma separated_net (X : V → Coord → ℝ) (F : Finset V) (hF : F.Nonempty) + {r : ℝ} (hr : 0 ≤ r) : + ∃S : Finset V, S ⊆ F ∧ S.Nonempty ∧ + (∀u ∈ S, ∀v ∈ S, u ≠ v → r < normDistance (X u) (X v)) ∧ + ∀u ∈ F, ∃v ∈ S, normDistance (X u) (X v) ≤ r := by + let sep : Finset V → Prop := fun S => ∀u ∈ S, ∀v ∈ S, u ≠ v → r < normDistance (X u) (X v) + let good := F.powerset.filter sep + have hgood : good.Nonempty := ⟨∅,mem_filter.mpr ⟨mem_powerset.mpr (empty_subset _),by simp [sep]⟩⟩ + obtain ⟨S,hS,hmax⟩ := exists_max_image good card hgood + obtain ⟨hSF,hsep⟩ := mem_filter.mp hS + have hcover : ∀u ∈ F, ∃v ∈ S, normDistance (X u) (X v) ≤ r := by + intro u hu + by_contra! hn + have huS : u ∉ S := by + intro huS + have hh := hn u huS + rw [normDistance_self] at hh + linarith + have hnew : insert u S ∈ good := by + apply mem_filter.mpr + refine ⟨mem_powerset.mpr (insert_subset hu (mem_powerset.mp hSF)),?_⟩ + intro x hx y hy hxy + rcases mem_insert.mp hx with rfl | hxS + · rcases mem_insert.mp hy with rfl | hyS + · exact (hxy rfl).elim + · exact hn y hyS + · rcases mem_insert.mp hy with rfl | hyS + · rw [normDistance_comm]; exact hn x hxS + · exact hsep x hxS y hyS hxy + have hh := hmax _ hnew + rw [card_insert_of_notMem huS] at hh + omega + refine ⟨S,mem_powerset.mp hSF,?_,hsep,hcover⟩ + obtain ⟨u,hu⟩ := hF + obtain ⟨v,hv,_⟩ := hcover u hu + exact ⟨v,hv⟩ + +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry +noncomputable section +open Finset +open StrongThinTree.Geometry (retain_fibers) +open RadialShell +open scoped Classical +variable {V : Type*} [DecidableEq V] {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {X : V → Coord → ℝ} + +lemma compact_from_net (S W : Finset V) (hS : S.Nonempty) (hW : W.Nonempty) + {δ D : ℝ} (hδ : 0 < δ) (hD : δ ≤ D) + (hsep : (S : Set V).Pairwise (fun u v => + Disjoint ((ball u δ).support X) ((ball v δ).support X))) + (hcover : ∀u ∈ S, ∃v ∈ W, normDistance (X u) (X v) ≤ 3*D) + (hsmall : 432*D*(W.card : ℝ) ≤ δ*(S.card : ℝ)) : + ∃F : CompactFamily X δ (6*D), + δ*(S.card : ℝ)/2 ≤ δ*(∑B ∈ F.bags, (B.card : ℝ)) := by + have hD0 : 0 < D := hδ.trans_le hD + obtain ⟨w0,hw0⟩ := hW + have hex : ∀u : V, ∃v ∈ W, u ∈ S → normDistance (X u) (X v) ≤ 3*D := by + intro u + by_cases hu : u ∈ S + · obtain ⟨v,hv,hvu⟩ := hcover u hu + exact ⟨v,hv,fun _ => hvu⟩ + · exact ⟨w0,hw0,fun hh => (hu hh).elim⟩ + choose f hfW hfDist using hex + let fiber := fun i => S.filter (fun u => f u=i) + let c : ℝ := 216*D/δ + have hc : 0 < c := by dsimp [c]; positivity + obtain ⟨J,hJW,hJ,hgain⟩ := retain_fibers S W f (fun u _ => hfW u) + (fun _ => (1:ℝ)) (fun _ _ => zero_lt_one) hc + have hsumRet : (∑i ∈ J, ((fiber i).card : ℝ)) ≥ (S.card : ℝ)/2 := by + have hcost : c*(W.card : ℝ) ≤ (S.card : ℝ)/2 := by + dsimp [c] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ hδ).mpr + nlinarith + simp only [sum_const, nsmul_eq_mul,mul_one] at hgain + dsimp [fiber] + linarith + have hJne : J.Nonempty := by + by_contra hh + rw [not_nonempty_iff_eq_empty.mp hh,sum_empty] at hsumRet + have hs0 : (0:ℝ) < S.card := by exact_mod_cast card_pos.mpr hS + linarith + have hinj : Set.InjOn fiber J := by + intro i hi j hj hij + obtain ⟨u,hu⟩ := (hJ i hi).1 + have huj : u ∈ fiber j := hij ▸ hu + exact (mem_filter.mp hu).2.symm.trans (mem_filter.mp huj).2 + have hfiber : ∀i ∈ J, fiber i ⊆ S := fun i _ => filter_subset _ _ + let F : CompactFamily X δ (6*D) := { + bags := J.image fiber + nonempty := hJne.image fiber + radius_pos := hδ + bags_disjoint := by + intro A hA B hB hAB + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + obtain ⟨j,hj,rfl⟩ := mem_image.mp hB + apply Finset.disjoint_left.mpr + intro u hui huj + have hij := (mem_filter.mp hui).2.symm.trans (mem_filter.mp huj).2 + exact hAB (congrArg fiber hij) + balls_disjoint := by + intro u hu v hv huv + obtain ⟨A,hA,huA⟩ := mem_biUnion.mp hu + obtain ⟨B,hB,hvB⟩ := mem_biUnion.mp hv + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + obtain ⟨j,hj,rfl⟩ := mem_image.mp hB + exact hsep (hfiber i hi huA) (hfiber j hj hvB) huv + cardinal := by + intro A hA + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + have hh := (hJ i hi).2 + have h216 : (216:ℝ) ≤ c := (le_div_iff₀ hδ).mpr (by nlinarith) + have : (2:ℝ) ≤ (fiber i).card := by dsimp [fiber]; nlinarith + exact_mod_cast this + diameter := by + intro A hA u hu v hv + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + have hui := (mem_filter.mp hu).2 + have hvi := (mem_filter.mp hv).2 + have hu' := hfDist u (hfiber i hi hu) + have hv' := hfDist v (hfiber i hi hv) + rw [hui] at hu' + rw [hvi,normDistance_comm (X v) (X i)] at hv' + have htri := normDistance_triangle (X u) (X i) (X v) + linarith + compact := by + intro A hA + obtain ⟨i,hi,rfl⟩ := mem_image.mp hA + have hh := (hJ i hi).2 + rw [mul_one] at hh + have hm := (div_le_iff₀ hδ).mp hh + nlinarith } + refine ⟨F,?_⟩ + have he : (∑B ∈ F.bags, (B.card : ℝ)) = ∑i ∈ J, ((fiber i).card : ℝ) := + sum_image hinj + rw [he] + nlinarith [mul_le_mul_of_nonneg_left hsumRet hδ.le] + +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry +noncomputable section +open Finset +open StrongThinTree.Geometry (retain_fibers) +open RadialShell +open scoped Classical +variable {V I J : Type*} [DecidableEq V] [Fintype I] [Fintype J] + [DecidableEq I] [DecidableEq J] {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] + +lemma normalized_small_balls (X : V → Coord → ℝ) (Y : V → EuclideanSpace ℝ J) + (u v : I → V) (j : I → J) (hj : Function.Injective j) + (hN : 0 < Fintype.card I) {a ε c₁ : ℝ} + (ha : 0 < a) (hε : 0 < ε) (hε1 : ε < 1/3) (hc : 0 < c₁) + (hdiag : ∀i, 0 ≤ (Y (u i)-Y (v i)).ofLp (j i) ∧ + c₁ ≤ ((Y (u i)-Y (v i)).ofLp (j i))^2) + (hbound : a * Fintype.card I * (∑i, ‖Y (u i)-Y (v i)‖^2) ≤ + (∑i, (Y (u i)-Y (v i)).ofLp (j i))^2) + (hcontract : ∀x y, ‖Y x-Y y‖^2 ≤ normDistance (X x) (X y)) : + a ≤ 1 ∧ ∃S : Finset V, ∃δ : ℝ, 0 < δ ∧ + S ⊆ (univ.image u ∪ univ.image v) ∧ 2 ≤ S.card ∧ + ε^2*a*Fintype.card I ≤ 1024*S.card ∧ + (S.card : ℝ)*δ = a^ε*c₁*Fintype.card I/(1024/ε^2) ∧ + (S : Set V).Pairwise (fun x y => + Disjoint ((ball x δ).support X) ((ball y δ).support X)) := by + let N : ℝ := Fintype.card I + let A : ℝ := ∑i, (Y (u i)-Y (v i)).ofLp (j i) + have hN0 : 0 < N := by dsimp [N]; exact_mod_cast hN + have hsqrt : ∀i, Real.sqrt c₁ ≤ (Y (u i)-Y (v i)).ofLp (j i) := by + intro i + exact (Real.sqrt_le_iff).mpr ⟨(hdiag i).1,(hdiag i).2⟩ + have hsum : N*Real.sqrt c₁ ≤ A := by + simpa only [sum_const,nsmul_eq_mul,card_univ,N,A] using sum_le_sum (fun i (_ : i ∈ univ) => hsqrt i) + have hA0 : 0 < A := (mul_pos hN0 (Real.sqrt_pos.mpr hc)).trans_le hsum + have hA2 : c₁*N^2 ≤ A^2 := by + have hh := sq_le_sq₀ (by positivity : 0 ≤ N*Real.sqrt c₁) hA0.le |>.mpr hsum + rw [mul_pow,Real.sq_sqrt hc.le] at hh + nlinarith + obtain ⟨ha1,S,r,hr,hSF,hS2,hcard,hmass,hsep⟩ := + StrongThinTree.Spectral.spectral_packing_coordinates Y u v j hj ha hε hε1 + (by change 0 < A^2; positivity) hbound + have hS0 : (0:ℝ) < S.card := by exact_mod_cast (by omega : 0 < S.card) + have he2 : 0 < ε^2 := sq_pos_of_pos hε + have hpow : 0 < a^ε := Real.rpow_pos_of_pos ha _ + let C : ℝ := 1024/ε^2 + have hC : 0 < C := by dsimp [C]; positivity + let w := a^ε*c₁*N/C + let δ := w/S.card + have hw : 0 < w := by dsimp [w]; positivity + have hδ : 0 < δ := div_pos hw hS0 + have hwle : w ≤ (S.card : ℝ)*r := by + have hh := mul_le_mul_of_nonneg_left hA2 (show 0 ≤ ε^2*a^ε by positivity) + change ε^2*a^ε*A^2 ≤ 1024*N*(S.card*r) at hmass + have hh' : ε^2*a^ε*c₁*N ≤ 1024*(S.card*r) := by + apply (mul_le_mul_iff_right₀ hN0).mp + nlinarith + dsimp [w,C] + exact (div_le_iff₀ (div_pos (by norm_num) he2)).mpr (by + rw [←mul_div_assoc] + apply (le_div_iff₀ he2).mpr + nlinarith) + have hδr : δ ≤ r := (div_le_iff₀ hS0).mpr (by nlinarith) + refine ⟨ha1,S,δ,hδ,hSF,hS2,hcard,?_,?_⟩ + · dsimp [δ,w,C,N] + field_simp + · intro x hx y hy hxy + apply distance_balls_disjoint + have hh := hsep x hx y hy hxy + have hh' := hcontract x y + have hs : (Real.sqrt r)^2 = r := Real.sq_sqrt hr.le + have hnorm := norm_nonneg (Y x-Y y) + have hroot := Real.sqrt_nonneg r + nlinarith + +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +open StrongThinTree.Geometry (retain_fibers) +open scoped Classical +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} + +lemma assigned_from_net (T : Finset (Finset (Fin n))) (W : Finset (Fin n)) + (hW : W.Nonempty) (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hboundary : ∀t ∈ T, 0 < (parentBoundary H G t).card) + {D η : ℝ} (hD : 0 < D) + (hsep : (W : Set (Fin n)).Pairwise (fun u v => + Disjoint ((ball u D).support X) ((ball v D).support X))) + (hcenter : ∀u ∈ W, ∃t ∈ T, u ∈ t ∧ ∃e ∈ parentBoundary H G t, + (G.left e = u ∨ G.right e = u) ∧ normDistance (X (G.left e)) (X (G.right e)) < D) + (hη : η ≤ (W.card : ℝ)/(2*(∑t ∈ T, ((parentBoundary H G t).card : ℝ)))) : + ∃F : AssignedFamily H G X η, F.radius = D ∧ F.owners ⊆ T ∧ + D*(W.card : ℝ)/2 ≤ F.mass := by + obtain ⟨u0,hu0⟩ := hW + obtain ⟨t0,ht0,ht0c⟩ := hcenter u0 hu0 + have hex : ∀u : Fin n, ∃t ∈ T, u ∈ W → u ∈ t ∧ ∃e ∈ parentBoundary H G t, + (G.left e = u ∨ G.right e = u) ∧ normDistance (X (G.left e)) (X (G.right e)) < D := by + intro u + by_cases hu : u ∈ W + · obtain ⟨t,ht,hc⟩ := hcenter u hu + exact ⟨t,ht,fun _ => hc⟩ + · exact ⟨t0,ht0,fun hh => (hu hh).elim⟩ + choose f hfT hf using hex + let N : ℝ := ∑t ∈ T, ((parentBoundary H G t).card : ℝ) + have hN : 0 < N := sum_pos (fun t ht => by exact_mod_cast hboundary t ht) ⟨t0,ht0⟩ + have hW0 : (0:ℝ) < W.card := by exact_mod_cast card_pos.mpr ⟨u0,hu0⟩ + let c : ℝ := W.card/(2*N) + have hc : 0 < c := div_pos hW0 (mul_pos (by norm_num) hN) + obtain ⟨J,hJT,hJ,hgain⟩ := retain_fibers W T f (fun u _ => hfT u) + (fun t => ((parentBoundary H G t).card : ℝ)) + (fun t ht => by exact_mod_cast hboundary t ht) hc + let fiber := fun t => W.filter (fun u => f u=t) + let e : Fin (Fintype.card J) ≃ J := (Fintype.equivFin J).symm + let a (t : J) : AssignedBag H G X D η := { + owner := t.val + owner_mem := hT (hJT t.property) + nonroot := hroot t.val (hJT t.property) + centers := fiber t.val + nonempty := (hJ t.val t.property).1 + radius_pos := hD + disjoint := hsep.mono (filter_subset _ _) + assignment := (mul_le_mul_of_nonneg_right hη (Nat.cast_nonneg _)).trans (hJ t.val t.property).2 + endpoint := by + intro u hu + obtain ⟨hu,hfu⟩ := mem_filter.mp hu + simpa only [hfu] using hf u hu } + let F : AssignedFamily H G X η := { + radius := D + positive := hD + count := Fintype.card J + bag := fun i => a (e i) + owner_injective := by + intro i j hij + exact e.injective (Subtype.ext hij) + separated := by + intro i u hu j v hv hne + apply hsep (mem_filter.mp hu).1 (mem_filter.mp hv).1 + intro huv + subst v + have hh : (e i).val = (e j).val := + (mem_filter.mp hu).2.symm.trans (mem_filter.mp hv).2 + rcases hne with hne | hne + · exact hne (e.injective (Subtype.ext hh)) + · exact hne rfl } + have hsum : (∑i : Fin F.count, ((F.bag i).centers.card : ℝ)) = + ∑t ∈ J, ((fiber t).card : ℝ) := by + change (∑i : Fin (Fintype.card J), ((fiber (e i).val).card : ℝ)) = _ + rw [e.sum_comp (fun t : J => ((fiber t.val).card : ℝ))] + exact sum_coe_sort J (fun t => ((fiber t).card : ℝ)) + refine ⟨F,rfl,?_,?_⟩ + · intro t ht + obtain ⟨i,hi,rfl⟩ := mem_image.mp ht + exact hJT (e i).property + · have heq : c*N = (W.card : ℝ)/2 := by dsimp [c]; field_simp + change (W.card : ℝ)-c*N ≤ _ at hgain + rw [heq] at hgain + change D*(W.card : ℝ)/2 ≤ (∑i : Fin F.count, ((F.bag i).centers.card : ℝ))*D + rw [hsum] + have hh := mul_le_mul_of_nonneg_left hgain hD.le + nlinarith + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +open StrongThinTree.Geometry (retain_fibers) +open scoped Classical +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} + +lemma capture_small_balls (T : Finset (Finset (Fin n))) (S P : Finset (Fin n)) + (hS : S.Nonempty) (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hboundary : ∀t ∈ T, 0 < (parentBoundary H G t).card) + {δ c₂ η : ℝ} (hδ : 0 < δ) (hc : 0 < c₂) (_hη : 0 ≤ η) + (hsep : (S : Set (Fin n)).Pairwise (fun u v => + Disjoint ((ball u δ).support X) ((ball v δ).support X))) + (hcover : ∀u ∈ S, ∃v ∈ P, normDistance (X u) (X v) ≤ c₂) + (hP : ∀u ∈ P, ∃t ∈ T, u ∈ t ∧ ∃e ∈ parentBoundary H G t, + (G.left e = u ∨ G.right e = u) ∧ normDistance (X (G.left e)) (X (G.right e)) ≤ c₂) + (hηδ : 864*η*(∑t ∈ T, ((parentBoundary H G t).card : ℝ)) ≤ S.card) + (hηc : 1728*η*c₂*(∑t ∈ T, ((parentBoundary H G t).card : ℝ)) ≤ δ*S.card) : + (∃F : CompactFamily X δ (6*max δ (2*c₂)), + δ*(S.card : ℝ)/864 ≤ δ*(∑B ∈ F.bags, (B.card : ℝ))) ∨ + (∃F : AssignedFamily H G X η, F.radius = max δ (2*c₂) ∧ F.owners ⊆ T ∧ + δ*(S.card : ℝ)/864 ≤ F.mass) := by + let D := max δ (2*c₂) + have hD : 0 < D := hδ.trans_le (le_max_left _ _) + have hcD : c₂ < D := lt_of_lt_of_le (by linarith) (le_max_right _ _) + obtain ⟨u0,hu0⟩ := hS + obtain ⟨v0,hv0,hv0d⟩ := hcover u0 hu0 + have hPne : P.Nonempty := ⟨v0,hv0⟩ + obtain ⟨W,hWP,hW,hWsep,hWcover⟩ := separated_net X P hPne (show 0 ≤ 2*D by positivity) + have hballs : (W : Set (Fin n)).Pairwise (fun u v => + Disjoint ((ball u D).support X) ((ball v D).support X)) := by + intro u hu v hv huv + exact distance_balls_disjoint X u v (hWsep u hu v hv huv).le + have hcover' : ∀u ∈ S, ∃v ∈ W, normDistance (X u) (X v) ≤ 3*D := by + intro u hu + obtain ⟨p,hp,hup⟩ := hcover u hu + obtain ⟨v,hv,hpv⟩ := hWcover p hp + exact ⟨v,hv,(normDistance_triangle (X u) (X p) (X v)).trans (by linarith)⟩ + by_cases hsmall : 432*D*(W.card : ℝ) ≤ δ*(S.card : ℝ) + · obtain ⟨F,hF⟩ := compact_from_net S W ⟨u0,hu0⟩ hW hδ (le_max_left _ _) hsep hcover' hsmall + exact Or.inl ⟨F,(by nlinarith [show (0:ℝ) ≤ S.card from Nat.cast_nonneg _] : δ*(S.card : ℝ)/864 ≤ δ*(S.card : ℝ)/2).trans hF⟩ + · have hlarge : δ*(S.card : ℝ) < 432*D*(W.card : ℝ) := lt_of_not_ge hsmall + have hcenter : ∀u ∈ W, ∃t ∈ T, u ∈ t ∧ ∃e ∈ parentBoundary H G t, + (G.left e = u ∨ G.right e = u) ∧ normDistance (X (G.left e)) (X (G.right e)) < D := by + intro u hu + obtain ⟨t,ht,hut,e,he,heu,hlen⟩ := hP u (hWP hu) + exact ⟨t,ht,hut,e,he,heu,hlen.trans_lt hcD⟩ + let N : ℝ := ∑t ∈ T, ((parentBoundary H G t).card : ℝ) + obtain ⟨t0,ht0,ht0c⟩ := hP v0 hv0 + have hN : 0 < N := sum_pos (fun t ht => by exact_mod_cast hboundary t ht) ⟨t0,ht0⟩ + have hnumer : 864*η*N*D ≤ δ*(S.card : ℝ) := by + rcases le_total δ (2*c₂) with hh | hh + · dsimp [D] + rw [max_eq_right hh] + change 1728*η*c₂*N ≤ δ*(S.card : ℝ) at hηc + nlinarith + · dsimp [D] + rw [max_eq_left hh] + change 864*η*N ≤ (S.card : ℝ) at hηδ + simpa [mul_comm δ] using mul_le_mul_of_nonneg_right hηδ hδ.le + have hassign : η ≤ (W.card : ℝ)/(2*N) := by + apply (le_div_iff₀ (mul_pos (by norm_num) hN)).mpr + nlinarith + obtain ⟨F,hFD,hFT,hgain⟩ := assigned_from_net T W hW hT hroot hboundary hD hballs hcenter hassign + exact Or.inr ⟨F,hFD,hFT,(by nlinarith : δ*(S.card : ℝ)/864 ≤ D*(W.card : ℝ)/2).trans hgain⟩ + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +open StrongThinTree.Geometry (retain_fibers) +open scoped Classical +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} + +lemma density_spectral_input {I : Type*} [Fintype I] + (a d : I → ℝ) {c₁ c₂ α : ℝ} + (hc₁ : 0 ≤ c₁) (hα : 0 ≤ α) (ha : ∀i, 0 ≤ a i) + (hmin : ∀i, c₁ ≤ (a i)^2) (hd : ∀i, d i ≤ c₂) + (hscale : α*c₂ ≤ c₁) : + α*(Fintype.card I : ℝ)*(∑i, d i) ≤ (∑i, a i)^2 := by + have hN : (0:ℝ) ≤ Fintype.card I := Nat.cast_nonneg _ + have hsum : (Fintype.card I : ℝ)*Real.sqrt c₁ ≤ ∑i, a i := by + simpa only [sum_const,nsmul_eq_mul,card_univ] using + sum_le_sum (fun i (_ : i ∈ univ) => Real.sqrt_le_iff.mpr ⟨ha i,hmin i⟩) + have hsum0 : 0 ≤ ∑i, a i := sum_nonneg (fun i _ => ha i) + have hsum2 : c₁*(Fintype.card I : ℝ)^2 ≤ (∑i, a i)^2 := by + have hh := (sq_le_sq₀ (mul_nonneg hN (Real.sqrt_nonneg _)) hsum0).mpr hsum + rw [mul_pow,Real.sq_sqrt hc₁] at hh + nlinarith only [hh] + have hdsum : (∑i, d i) ≤ (Fintype.card I : ℝ)*c₂ := by + simpa only [sum_const,nsmul_eq_mul,card_univ] using sum_le_sum (fun i (_ : i ∈ univ) => hd i) + have h1 := mul_le_mul_of_nonneg_left hdsum (mul_nonneg hα hN) + have h2 := mul_le_mul_of_nonneg_right hscale (sq_nonneg (Fintype.card I : ℝ)) + nlinarith only [h1,h2,hsum2] + +lemma homogeneous_family (T : Finset (Finset (Fin n))) (F : Finset (Fin n) → Finset (Fin m)) + (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hTne : T.Nonempty) (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hF : ∀t ∈ T, F t ⊆ parentBoundary H G t) (hFn : ∀t ∈ T, (F t).Nonempty) + {α γ ε c₁ c₂ : ℝ} (hα : 0 < α) (hγ : 0 < γ) + (he : 0 < ε) (he1 : ε < 1/3) (hc₁ : 0 < c₁) (hc₂ : 0 < c₂) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ normDistance (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hmin : ∀t ∈ T, ∀e ∈ F t, c₁ ≤ ((Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hmax : ∀t ∈ T, ∀e ∈ F t, ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ 4*c₁) + (hdmin : ∀t ∈ T, ∀e ∈ F t, c₂/4 ≤ normDistance (X (G.left e)) (X (G.right e))) + (hdmax : ∀t ∈ T, ∀e ∈ F t, normDistance (X (G.left e)) (X (G.right e)) ≤ c₂) + (hbad : ∀t ∈ T, α*((parentBoundary H G t).card : ℝ)* + (∑e ∈ parentBoundary H G t, normDistance (X (G.left e)) (X (G.right e))) ≤ + (∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hdom : ∀t ∈ T, γ*(∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ + (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hsmall : (α*γ/32)^ε ≤ 1/(1728*(1024/ε^2))) : + let s := α*γ/32 + let R := ∑t ∈ T, (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((parentBoundary H G t).card : ℝ) + (∃δ Δ : ℝ, ∃B : CompactFamily X δ Δ, + s*c₁ ≤ δ ∧ Δ ≤ 12*c₁/s ∧ s^ε*R/(6912*(1024/ε^2)) ≤ δ*(∑D ∈ B.bags, (D.card : ℝ))) ∨ + (∃B : AssignedFamily H G X (s^(1+2*ε)), B.owners ⊆ T ∧ + s*c₁ ≤ B.radius ∧ B.radius ≤ 12*c₁/s ∧ s^ε*R/(6912*(1024/ε^2)) ≤ B.mass) := by + let a : Fin m → ℝ := fun e => (Y (G.left e)-Y (G.right e)).ofLp e + let d : Fin m → ℝ := fun e => normDistance (X (G.left e)) (X (G.right e)) + let E := T.biUnion F + let N : ℝ := ∑t ∈ T, ((parentBoundary H G t).card : ℝ) + let N' : ℝ := E.card + let s := α*γ/32 + let C : ℝ := 1024/ε^2 + let R := ∑t ∈ T, (∑e ∈ F t, a e)^2/((parentBoundary H G t).card : ℝ) + have hs : 0 < s := by dsimp [s]; positivity + have hC : 0 < C := by dsimp [C]; positivity + have hEn : E.Nonempty := by + obtain ⟨t,ht⟩ := hTne + obtain ⟨e,he⟩ := hFn t ht + exact ⟨e,mem_biUnion.mpr ⟨t,ht,he⟩⟩ + have hN' : 0 < N' := by dsimp [N']; exact_mod_cast card_pos.mpr hEn + have hboundary : ∀t ∈ T, 0 < (parentBoundary H G t).card := + fun t ht => card_pos.mpr ((hFn t ht).mono (hF t ht)) + have hN : 0 < N := by + apply sum_pos (fun t ht => ?_) hTne + exact_mod_cast hboundary t ht + have hNle : N' ≤ N := by + have h1 : E.card ≤ ∑t ∈ T, (F t).card := card_biUnion_le + have h2 : (∑t ∈ T, (F t).card) ≤ ∑t ∈ T, (parentBoundary H G t).card := + sum_le_sum (fun t ht => card_le_card (hF t ht)) + dsimp [N',N] + exact_mod_cast h1.trans h2 + have hd0 : ∀e, 0 ≤ d e := fun e => normDistance_nonneg _ _ + obtain ⟨hdensity,hR⟩ := StrongThinTree.BagDensity.family_density T (parentBoundary H G) F a d + hα hγ hc₁.le hF hFn (fun t ht e he => hd0 e) hmax hdmin hbad hdom + (H.subset_boundary_multiplicity G T hT hroot F hF) + change s*N*c₂ ≤ c₁*N' at hdensity + change R ≤ 8*c₁*N' at hR + let specα := s*N/N' + have ha0 : 0 < specα := div_pos (mul_pos hs hN) hN' + have hscale : specα*N' = s*N := div_mul_cancel₀ _ hN'.ne' + have has : s ≤ specα := by + apply (le_div_iff₀ hN').mpr + exact mul_le_mul_of_nonneg_left hNle hs.le + have had : specα*c₂ ≤ c₁ := by + change (s*N/N')*c₂ ≤ c₁ + rw [div_mul_eq_mul_div] + exact (div_le_iff₀ hN').mpr hdensity + have hminE : ∀e ∈ E, c₁ ≤ (a e)^2 := by + intro e he + obtain ⟨t,ht,he⟩ := mem_biUnion.mp he + exact hmin t ht e he + have hmaxE : ∀e ∈ E, d e ≤ c₂ := by + intro e he + obtain ⟨t,ht,he⟩ := mem_biUnion.mp he + exact hdmax t ht e he + let u : E → Fin n := fun e => G.left e.val + let v : E → Fin n := fun e => G.right e.val + have hIE : Fintype.card E = E.card := Fintype.card_coe E + have hI : 0 < Fintype.card E := by rw [hIE]; exact card_pos.mpr hEn + have hbnd : specα*(Fintype.card E : ℝ)*(∑e : E, ‖Y (u e)-Y (v e)‖^2) ≤ + (∑e : E, (Y (u e)-Y (v e)).ofLp e.val)^2 := + density_spectral_input (fun e : E => a e.val) (fun e : E => ‖Y (u e)-Y (v e)‖^2) + hc₁.le ha0.le (fun e => hpositive e.val) (fun e => hminE e.val e.property) + (fun e => (hcontract (u e) (v e)).trans (hmaxE e.val e.property)) had + obtain ⟨ha1,S,δ,hδ,hSE,hS2,hSc,hmass,hsep⟩ := normalized_small_balls X Y u v + (fun e : E => e.val) Subtype.val_injective hI ha0 he he1 hc₁ + (fun e => ⟨hpositive e.val,hminE e.val e.property⟩) hbnd hcontract + have hS : S.Nonempty := card_pos.mp (by omega) + have hSc0 : (0:ℝ) < S.card := by exact_mod_cast (by omega : 0 < S.card) + have hcard : specα*N'/C ≤ (S.card : ℝ) := by + apply (div_le_iff₀ hC).mpr + dsimp [C] + rw [←mul_div_assoc] + apply (le_div_iff₀ (sq_pos_of_pos he)).mpr + rw [hIE] at hSc + change ε^2*specα*N' ≤ _ at hSc + nlinarith only [hSc] + have hcard₂ : (S.card : ℝ) ≤ 2*N' := by + have hh := card_le_card hSE + have h1 := card_union_le (univ.image u) (univ.image v) + have h2 := card_image_le (f := u) (s := univ) + have h3 := card_image_le (f := v) (s := univ) + simp only [card_univ,hIE] at h2 h3 + have hSc : S.card ≤ 2*E.card := by omega + dsimp [N']; exact_mod_cast hSc + rw [hIE] at hmass + change (S.card : ℝ)*δ = specα^ε*c₁*N'/C at hmass + obtain ⟨hηδ,hηc,hlower,hupper,hgain⟩ := StrongThinTree.CaptureNumeric.thresholds + hs has ha1 he (by linarith : ε ≤ 1/2) hC hN hN' hNle hc₁ hc₂ hSc0 hδ + hscale hdensity hcard hcard₂ hmass hsmall hR + let P := T.biUnion (fun t => t.filter (fun w => ∃e ∈ F t, G.left e=w ∨ G.right e=w)) + have hP : ∀w ∈ P, ∃t ∈ T, w ∈ t ∧ ∃e ∈ parentBoundary H G t, + (G.left e=w ∨ G.right e=w) ∧ normDistance (X (G.left e)) (X (G.right e)) ≤ c₂ := by + intro w hw + obtain ⟨t,ht,hw⟩ := mem_biUnion.mp hw + obtain ⟨hwt,e,he,hew⟩ := mem_filter.mp hw + exact ⟨t,ht,hwt,e,hF t ht he,hew,hdmax t ht e he⟩ + have hEnd : ∀e ∈ E, ∃w ∈ P, (G.left e=w ∨ G.right e=w) := by + intro e he + obtain ⟨t,ht,het⟩ := mem_biUnion.mp he + have hc := (mem_filter.mp (hF t ht het)).2 + rcases hc with hc | hc + · exact ⟨G.left e,mem_biUnion.mpr ⟨t,ht,mem_filter.mpr ⟨hc.1,e,het,Or.inl rfl⟩⟩,Or.inl rfl⟩ + · exact ⟨G.right e,mem_biUnion.mpr ⟨t,ht,mem_filter.mpr ⟨hc.1,e,het,Or.inr rfl⟩⟩,Or.inr rfl⟩ + have hcover : ∀w ∈ S, ∃p ∈ P, normDistance (X w) (X p) ≤ c₂ := by + intro w hw + rcases mem_union.mp (hSE hw) with hw | hw + · obtain ⟨e,he,rfl⟩ := mem_image.mp hw + obtain ⟨p,hp,hp'⟩ := hEnd e.val e.property + refine ⟨p,hp,?_⟩ + rcases hp' with hp' | hp' + · simpa [u,hp',normDistance_self] using hc₂.le + · simpa [u,d,hp'] using hmaxE e.val e.property + · obtain ⟨e,he,rfl⟩ := mem_image.mp hw + obtain ⟨p,hp,hp'⟩ := hEnd e.val e.property + refine ⟨p,hp,?_⟩ + rcases hp' with hp' | hp' + · simpa [v,d,hp',normDistance_comm] using hmaxE e.val e.property + · simpa [v,hp',normDistance_self] using hc₂.le + have hNcast : ∑t ∈ T, ((parentBoundary H G t).card : ℝ) = N := rfl + have hη : 0 ≤ s^(1+2*ε) := (Real.rpow_pos_of_pos hs _).le + obtain hcomp | hass := capture_small_balls T S P hS hT hroot hboundary hδ hc₂ hη + hsep hcover hP hηδ hηc + · obtain ⟨B,hB⟩ := hcomp + refine Or.inl ⟨δ,6*max δ (2*c₂),B,hlower,?_,hgain.trans hB⟩ + change 6*max δ (2*c₂) ≤ 12*c₁/s + calc + _ ≤ 6*(2*c₁/s) := mul_le_mul_of_nonneg_left hupper (by norm_num) + _ = 12*c₁/s := by ring + · obtain ⟨B,hBD,hBT,hB⟩ := hass + refine Or.inr ⟨B,hBT,?_,?_,hgain.trans hB⟩ + · rw [hBD] + exact hlower.trans (le_max_left _ _) + · rw [hBD] + have hh : 0 ≤ c₁/s := by positivity + calc + max δ (2*c₂) ≤ 2*c₁/s := hupper + _ ≤ 12*c₁/s := by rw [mul_div_assoc,mul_div_assoc]; linarith only [hh] + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/CenteredMatrices.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/CenteredMatrices.lean new file mode 100644 index 0000000000000000000000000000000000000000..39526dc4160f492635fb8976dc55d45adaea599c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/CenteredMatrices.lean @@ -0,0 +1,245 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.MatrixBound + +namespace OAI + +/-! Centered matrices. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder + +variable {n m : ℕ} + +def ones (n : ℕ) : Fin n → ℝ := fun _ => 1 + +def constantProjection (n : ℕ) : Matrix (Fin n) (Fin n) ℝ := + (n : ℝ)⁻¹ • vecMulVec (ones n) (ones n) + +def centering (n : ℕ) : Matrix (Fin n) (Fin n) ℝ := 1-constantProjection n + +lemma ones_dot (x : Fin n → ℝ) : ones n ⬝ᵥ x=∑i, x i := by + simp [ones,dotProduct] + +lemma constantProjection_psd : (constantProjection n).PosSemidef := by + apply Matrix.PosSemidef.smul _ (inv_nonneg.mpr (Nat.cast_nonneg _)) + simpa only [star_trivial] using posSemidef_vecMulVec_self_star (ones n) + +lemma constantProjection_symmetric : (constantProjection n)ᵀ=constantProjection n := + isHermitian_iff_isSymm.mp constantProjection_psd.isHermitian + +lemma centering_symmetric : (centering n)ᵀ=centering n := by + simp only [centering,transpose_sub,transpose_one,constantProjection_symmetric] + +lemma constantProjection_mulVec (x : Fin n → ℝ) : + constantProjection n *ᵥ x=((∑i, x i)/(n:ℝ)) • ones n := by + ext j + simp [constantProjection,mulVec,dotProduct,Matrix.smul_apply,vecMulVec,ones,div_eq_mul_inv,Finset.sum_mul,mul_comm] + +lemma qform_constantProjection (x : Fin n → ℝ) : + qform (constantProjection n) x=(∑i, x i)^2/(n:ℝ) := by + rw [qform,constantProjection_mulVec,dotProduct_smul,dotProduct_comm x,ones_dot] + simp only [smul_eq_mul] + ring + +lemma centering_mulVec (x : Fin n → ℝ) : + centering n *ᵥ x=x-((∑i, x i)/(n:ℝ)) • ones n := by + rw [centering,sub_mulVec,one_mulVec,constantProjection_mulVec] + +lemma centering_mulVec_of_sum_zero {x : Fin n → ℝ} (hx : ∑i, x i=0) : + centering n *ᵥ x=x := by + simp only [centering_mulVec,hx,zero_div,zero_smul,sub_zero] + +lemma centering_mulVec_sum (hn : 0 < n) (x : Fin n → ℝ) : + ∑i, (centering n *ᵥ x) i=0 := by + rw [centering_mulVec] + simp only [Pi.sub_apply,Pi.smul_apply,smul_eq_mul,ones,sum_sub_distrib,mul_one, + sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul] + field_simp + ring + +lemma constantProjection_ones (hn : 0 < n) : constantProjection n *ᵥ ones n=ones n := by + rw [constantProjection_mulVec] + simp only [ones,sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + rw [div_self (Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn)),one_smul] + +lemma centering_ones (hn : 0 < n) : centering n *ᵥ ones n=0 := by + rw [centering,sub_mulVec,one_mulVec,constantProjection_ones hn,sub_self] + +lemma centered_dot (b y : Fin n → ℝ) (hb : ∑i, b i=0) : + b ⬝ᵥ (centering n *ᵥ y)=b ⬝ᵥ y := by + rw [dotProduct_mulVec,←mulVec_transpose,centering_symmetric,centering_mulVec_of_sum_zero hb] + +def centered (D : Matrix (Fin n) (Fin n) ℝ) : Matrix (Fin n) (Fin n) ℝ := + centering n*D*centering n + +lemma centered_psd {D : Matrix (Fin n) (Fin n) ℝ} (hD : D.PosSemidef) : (centered D).PosSemidef := by + have hh := hD.mul_mul_conjTranspose_same (centering n) + simpa only [centered,conjTranspose_eq_transpose_of_trivial,centering_symmetric] using hh + +lemma centered_ones (hn : 0 < n) (D : Matrix (Fin n) (Fin n) ℝ) : centered D *ᵥ ones n=0 := by + simp only [centered,←mulVec_mulVec,centering_ones hn,mulVec_zero] + +lemma qform_centered (D : Matrix (Fin n) (Fin n) ℝ) (x : Fin n → ℝ) : + qform (centered D) x=qform D (centering n *ᵥ x) := by + unfold centered qform + rw [←mulVec_mulVec,←mulVec_mulVec,dotProduct_mulVec,←mulVec_transpose,centering_symmetric] + +def CenteredPositive (D : Matrix (Fin n) (Fin n) ℝ) : Prop := + D.IsHermitian ∧ D *ᵥ ones n=0 ∧ ∀x : Fin n → ℝ, (∑i, x i)=0 → x ≠ 0 → 0 < qform D x + +def regularize (D : Matrix (Fin n) (Fin n) ℝ) : Matrix (Fin n) (Fin n) ℝ := + D+constantProjection n + +def inverseOnZeroSum (D : Matrix (Fin n) (Fin n) ℝ) : Matrix (Fin n) (Fin n) ℝ := + (regularize D)⁻¹ + +lemma centered_positive (hn : 0 < n) {D : Matrix (Fin n) (Fin n) ℝ} (hD : D.PosDef) : + CenteredPositive (centered D) := by + refine ⟨(centered_psd hD.posSemidef).isHermitian,centered_ones hn D,?_⟩ + intro x hx hne + rw [qform_centered,centering_mulVec_of_sum_zero hx] + simpa only [qform,star_trivial] using hD.dotProduct_mulVec_pos hne + +lemma regularize_centered_pd (hn : 0 < n) {D : Matrix (Fin n) (Fin n) ℝ} (hD : D.PosDef) : + (regularize (centered D)).PosDef := by + apply PosDef.of_dotProduct_mulVec_pos + ((centered_psd hD.posSemidef).add constantProjection_psd).isHermitian + intro x hx + change 0 < qform (regularize (centered D)) x + rw [regularize,qform_add,qform_centered] + by_cases hp : centering n *ᵥ x=0 + · have hs : (∑i, x i) ≠ 0 := by + intro hs + rw [centering_mulVec_of_sum_zero hs] at hp + exact hx hp + have hq : 0 < qform (constantProjection n) x := by + rw [qform_constantProjection] + exact div_pos (sq_pos_of_ne_zero hs) (Nat.cast_pos.mpr hn) + exact add_pos_of_nonneg_of_pos (qform_nonneg hD.posSemidef _) hq + · have hq : 0 < qform D (centering n *ᵥ x) := by + simpa only [qform,star_trivial] using hD.dotProduct_mulVec_pos hp + exact add_pos_of_pos_of_nonneg hq (qform_nonneg constantProjection_psd _) + +lemma inverseOnZeroSum_solves (hn : 0 < n) {D : Matrix (Fin n) (Fin n) ℝ} + (hD0 : D *ᵥ ones n=0) (hD : (regularize D).PosDef) + {b : Fin n → ℝ} (hb : (∑i, b i)=0) : + (∑i, (inverseOnZeroSum D *ᵥ b) i)=0 ∧ D *ᵥ (inverseOnZeroSum D *ᵥ b)=b := by + let y := inverseOnZeroSum D *ᵥ b + have hy : regularize D *ᵥ y=b := posDef_solve hD b + have h1 : regularize D *ᵥ ones n=ones n := by + rw [regularize,add_mulVec,hD0,constantProjection_ones hn,zero_add] + have hys : ∑i, y i=0 := by + have hh := MatrixDual.quadratic_symm hD.isHermitian (ones n) y + rw [hy,h1,dotProduct_comm y,ones_dot,ones_dot,hb] at hh + exact hh.symm + refine ⟨hys,?_⟩ + rw [regularize,add_mulVec,constantProjection_mulVec,hys,zero_div,zero_smul,add_zero] at hy + exact hy + +lemma inverse_centered_le (hn : 0 < n) {D : Matrix (Fin n) (Fin n) ℝ} + (hD : D.PosDef) {b : Fin n → ℝ} (hb : (∑i, b i)=0) : + qform (inverseOnZeroSum (centered D)) b ≤ qform D⁻¹ b := by + let A := regularize (centered D) + have hA : A.PosDef := regularize_centered_pd hn hD + let y := A⁻¹ *ᵥ b + have hs : A *ᵥ y=b := posDef_solve hA b + have hq : qform D (centering n *ᵥ y) ≤ b ⬝ᵥ y := by + have hh : qform A y=b ⬝ᵥ y := by rw [qform,hs,dotProduct_comm] + dsimp [A] at hh + rw [regularize,qform_add,qform_centered] at hh + linarith only [hh,qform_nonneg (constantProjection_psd (n:=n)) y] + have hv := MatrixDual.inverse_quadratic_variational hD b (centering n *ᵥ y) + rw [centered_dot b y hb] at hv + change 2*(b ⬝ᵥ y)-qform D (centering n *ᵥ y) ≤ qform D⁻¹ b at hv + change b ⬝ᵥ y ≤ qform D⁻¹ b + linarith only [hv,hq] + +lemma centeredTest_mul_constant {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : CenteredTest Z) : + Z*constantProjection n=0 := by + have h0 : Z *ᵥ ones n=0 := hZ.2 + simp only [constantProjection,mul_smul_comm,mul_vecMulVec,h0,zero_vecMulVec,smul_zero] + +lemma centeredTest_constant_mul {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : CenteredTest Z) : + constantProjection n*Z=0 := by + have hh := congrArg transpose (centeredTest_mul_constant hZ) + simpa only [transpose_mul,constantProjection_symmetric, + (isHermitian_iff_isSymm.mp hZ.1.1.isHermitian).eq,transpose_zero] using hh + +lemma centeredTest_mul_centering {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : CenteredTest Z) : + Z*centering n=Z := by + rw [centering,mul_sub,mul_one,centeredTest_mul_constant hZ,sub_zero] + +lemma centeredTest_centering_mul {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : CenteredTest Z) : + centering n*Z=Z := by + rw [centering,sub_mul,one_mul,centeredTest_constant_mul hZ,sub_zero] + +lemma centered_trace (D : Matrix (Fin n) (Fin n) ℝ) + {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : CenteredTest Z) : + (centered D*Z).trace=(D*Z).trace := by + rw [centered,mul_assoc (centering n*D),centeredTest_centering_mul hZ, + mul_assoc,trace_mul_comm,mul_assoc,centeredTest_mul_centering hZ] + +lemma regularize_trace (D : Matrix (Fin n) (Fin n) ℝ) + {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : CenteredTest Z) : + (regularize D*Z).trace=(D*Z).trace := by + rw [regularize,add_mul,trace_add,centeredTest_constant_mul hZ,trace_zero,add_zero] + +lemma laplacian_zeroSum_pos (G : MultiGraph n m) (hn : 0 < n) (hc : G.Connected univ) + (x : Fin n → ℝ) (hx : (∑i, x i)=0) (hxne : x ≠ 0) : + 0 < qform (G.laplacian univ) x := by + have hnonneg := qform_nonneg (G.laplacian_psd univ) x + by_contra hpos + have hzero : qform (G.laplacian univ) x=0 := le_antisymm (not_lt.mp hpos) hnonneg + have hedge (e : Fin m) : x (G.left e)-x (G.right e)=0 := by + rw [G.laplacian_qform] at hzero + have he := (single_le_sum (fun i _ => sq_nonneg (x (G.left i)-x (G.right i))) (mem_univ e)) + rw [hzero] at he + exact sq_eq_zero_iff.mp (le_antisymm he (sq_nonneg _)) + let f : (Fin n → ℝ) →ₗ[ℝ] ℝ := + { toFun := fun v => x ⬝ᵥ v + map_add' := fun v w => dotProduct_add x v w + map_smul' := fun c v => dotProduct_smul c x v } + have hf : G.edgeSpan univ ≤ f.ker := by + apply (Packing.span_le_iff G.incidence).mpr + intro e _ + change (∑v, x v*G.incidence e v)=0 + rw [G.eval_incidence] + exact hedge e + have hxx : x ⬝ᵥ x=0 := hf (by rw [G.connected_span_zeroSum hn hc]; exact (mem_zeroSumSpace x).mpr hx) + exact hxne (dotProduct_self_eq_zero.mp hxx) + +lemma laplacian_ones (G : MultiGraph n m) : G.laplacian univ *ᵥ ones n=0 := by + simp only [laplacian,sum_mulVec,vecMulVec_mulVec] + apply Finset.sum_eq_zero + intro e _ + rw [dotProduct_comm] + change MulOpposite.op (∑v, ones n v*G.incidence e v) • G.incidence e=0 + rw [G.eval_incidence] + simp [ones] + +lemma laplacian_centered_positive (G : MultiGraph n m) (hn : 0 < n) (hc : G.Connected univ) : + CenteredPositive (G.laplacian univ) := + ⟨(G.laplacian_psd univ).isHermitian,laplacian_ones G,laplacian_zeroSum_pos G hn hc⟩ + +lemma laplacian_regularize_pd (G : MultiGraph n m) (hn : 0 < n) (hc : G.Connected univ) : + (regularize (G.laplacian univ)).PosDef := by + apply PosDef.of_dotProduct_mulVec_pos ((G.laplacian_psd univ).add constantProjection_psd).isHermitian + intro x hx + change 0 < qform (regularize (G.laplacian univ)) x + rw [regularize,qform_add] + by_cases hxs : (∑i, x i)=0 + · exact add_pos_of_pos_of_nonneg (laplacian_zeroSum_pos G hn hc x hxs hx) + (qform_nonneg constantProjection_psd x) + · apply add_pos_of_nonneg_of_pos (qform_nonneg (G.laplacian_psd univ) x) + rw [qform_constantProjection] + exact div_pos (sq_pos_of_ne_zero hxs) (Nat.cast_pos.mpr hn) + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/CompactCharging.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/CompactCharging.lean new file mode 100644 index 0000000000000000000000000000000000000000..1bf37b6b073be6f6872a44b9d6265e3393043c32 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/CompactCharging.lean @@ -0,0 +1,751 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.ShellCharging +import OAI.Combinatorics.ThinTrees.Normalization.Realization + +namespace OAI + +/-! Metric compact charging. -/ + +section + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry +noncomputable section +open Finset + +section RadialLaws +variable {J : Type*} [Fintype J] [PseudoMetricSpace J] + +def normDistance (q r : J → ℝ) : ℝ := ‖q-r‖ + +def inPolytope (q : J → ℝ) : Prop := q ∈ polytope + +def isProfile (q : J → ℝ) : Prop := ∃ j : J, q = profile j + +omit [PseudoMetricSpace J] in +lemma normDistance_self (q : J → ℝ) : normDistance q q = 0 := by + simp [normDistance] + +omit [PseudoMetricSpace J] in +lemma normDistance_comm (q r : J → ℝ) : normDistance q r = normDistance r q := + norm_sub_rev _ _ + +omit [PseudoMetricSpace J] in +lemma normDistance_triangle (q r s : J → ℝ) : + normDistance q s ≤ normDistance q r + normDistance r s := by + simpa only [normDistance, dist_eq_norm] using dist_triangle q r s + +omit [Fintype J] in +lemma isProfile_inPolytope {q : J → ℝ} (hq : isProfile q) : inPolytope q := by + obtain ⟨j,rfl⟩ := hq + exact profile_mem j + +omit [PseudoMetricSpace J] in +lemma segment_formula (q r : J → ℝ) (t : ℝ) : + (fun j => q j+t*(r j-q j)) = mix q r t := by + ext j + simp only [mix, Pi.add_apply, Pi.smul_apply, smul_eq_mul] + ring + +lemma inPolytope_segment {q r : J → ℝ} (hq : inPolytope q) (hr : inPolytope r) + {t : ℝ} (ht : t ∈ Set.Icc (0:ℝ) 1) : + inPolytope (fun j => q j+t*(r j-q j)) := by + rw [segment_formula] + exact mix_mem hq hr ht + +lemma isProfile_radial_affine {q r c : J → ℝ} (hq : inPolytope q) (hr : inPolytope r) + (hc : isProfile c) {t : ℝ} (ht : t ∈ Set.Icc (0:ℝ) 1) : + normDistance (fun j => q j+t*(r j-q j)) c = + normDistance q c+t*(normDistance r c-normDistance q c) := by + obtain ⟨j,rfl⟩ := hc + rw [segment_formula] + change ‖mix q r t-profile j‖ = _ + rw [radius_mix hq hr j ht] + unfold normDistance + ring +end RadialLaws + +structure RadialShell (V : Type*) where + center : V + inner : ℝ + outer : ℝ + ordinary : Bool + deriving DecidableEq + +namespace RadialShell +variable {V : Type*} {J : Type*} [Fintype J] [PseudoMetricSpace J] + +def ball (v : V) (r : ℝ) : RadialShell V := ⟨v,0,r,true⟩ +def hollow (v : V) (a b : ℝ) : RadialShell V := ⟨v,a,b,false⟩ +def width (H : RadialShell V) : ℝ := H.outer-H.inner + +def support (X : V → J → ℝ) (H : RadialShell V) : Set (J → ℝ) := + {w | inPolytope w ∧ normDistance w (X H.center) linarith [hH.2.1] + have hR : 0 < R := lt_of_lt_of_le (lt_of_le_of_lt hH.1 hH.2.1) hv + let t := q/R + have ht : t ∈ Set.Icc (0:ℝ) 1 := + ⟨div_nonneg (le_trans hH.1 hq.1.le) hR.le, + (div_le_one hR).mpr (le_trans hq.2.le hv)⟩ + let w := fun j => X H.center j+t*(X v j-X H.center j) + have hw : normDistance w (X H.center) = q := by + rw [isProfile_radial_affine (isProfile_inPolytope (hX _)) (isProfile_inPolytope (hX _)) (hX _) ht, + normDistance_self, sub_zero, zero_add] + exact div_mul_cancel₀ _ hR.ne' + exact ⟨w,inPolytope_segment (isProfile_inPolytope (hX _)) (isProfile_inPolytope (hX _)) ht, + hw ▸ hq.2,Or.inr (hw ▸ hq.1)⟩ + +omit [PseudoMetricSpace J] in +lemma restriction_valid {X : V → J → ℝ} {H : RadialShell V} + (hH : H.Valid X) {a b : ℝ} (ha : H.inner ≤ a) (hb : b ≤ H.outer) (hab : a < b) : + (hollow H.center a b).Valid X := by + refine ⟨hH.1.trans ha,hab,by simp [hollow],?_,?_⟩ + · obtain ⟨u,hu⟩ := hH.2.2.2.1 + exact ⟨u,hu.trans ha⟩ + · obtain ⟨v,hv⟩ := hH.2.2.2.2 + exact ⟨v,hb.trans hv⟩ + +lemma restriction_subset (X : V → J → ℝ) (H : RadialShell V) + {a b : ℝ} (ha : H.inner ≤ a) (hb : b ≤ H.outer) : + (hollow H.center a b).support X ⊆ H.support X := by + intro w hw + rw [support_hollow] at hw + exact ⟨hw.1,lt_of_lt_of_le hw.2.2 hb,Or.inr (lt_of_le_of_lt ha hw.2.1)⟩ + +lemma ball_subset_of_radial_margin (X : V → J → ℝ) (H : RadialShell V) + (z : V) {δ : ℝ} (hlo : H.inner+δ ≤ normDistance (X z) (X H.center)) + (hhi : normDistance (X z) (X H.center) ≤ H.outer-δ) : + (ball z δ).support X ⊆ H.support X := by + intro w hw + rw [support_ball] at hw + have htri := normDistance_triangle w (X z) (X H.center) + have htri' := normDistance_triangle (X z) w (X H.center) + rw [normDistance_comm (X z) w] at htri' + exact ⟨hw.1,by linarith [hw.2],Or.inr (by linarith [hw.2])⟩ + +lemma ball_disjoint_hollow_lower (X : V → J → ℝ) (x z : V) {δ q a : ℝ} + (hq : q+δ ≤ normDistance (X z) (X x)) : + Disjoint ((ball z δ).support X) ((hollow x a q).support X) := by + rw [Set.disjoint_left] + intro w hw hz + rw [support_ball] at hw + rw [support_hollow] at hz + have ht := normDistance_triangle (X z) w (X x) + rw [normDistance_comm (X z) w] at ht + linarith [hw.2,hz.2.2] + +lemma ball_disjoint_hollow_upper (X : V → J → ℝ) (x z : V) {δ q b : ℝ} + (hq : normDistance (X z) (X x)+δ ≤ q) : + Disjoint ((ball z δ).support X) ((hollow x q b).support X) := by + rw [Set.disjoint_left] + intro w hw hz + rw [support_ball] at hw + rw [support_hollow] at hz + have ht := normDistance_triangle w (X z) (X x) + linarith [hw.2,hz.2.1] + +lemma concentric_disjoint (X : V → J → ℝ) (x : V) {a b c d : ℝ} (hbc : b ≤ c) : + Disjoint ((hollow x a b).support X) ((hollow x c d).support X) := by + rw [Set.disjoint_left] + intro w hw hz + rw [support_hollow] at hw hz + linarith [hw.2.2,hz.2.1] + +lemma disjoint_balls_distance {X : V → J → ℝ} (hX : ∀v, isProfile (X v)) + (u v : V) {δ : ℝ} (hd : Disjoint ((ball u δ).support X) ((ball v δ).support X)) : + 2*δ ≤ normDistance (X u) (X v) := by + by_contra hh + have hh := not_le.mp hh + let w := fun j => X u j+(1/2:ℝ)*(X v j-X u j) + have hw := inPolytope_segment (isProfile_inPolytope (hX u)) (isProfile_inPolytope (hX v)) + (show (1/2:ℝ) ∈ Set.Icc (0:ℝ) 1 by norm_num) + have hu := isProfile_radial_affine (isProfile_inPolytope (hX u)) (isProfile_inPolytope (hX v)) (hX u) + (show (1/2:ℝ) ∈ Set.Icc (0:ℝ) 1 by norm_num) + have hv := isProfile_radial_affine (isProfile_inPolytope (hX u)) (isProfile_inPolytope (hX v)) (hX v) + (show (1/2:ℝ) ∈ Set.Icc (0:ℝ) 1 by norm_num) + simp only [normDistance_self,normDistance_comm (X v) (X u)] at hu hv + have hwu : w ∈ (ball u δ).support X := by + rw [support_ball]; exact ⟨hw,by dsimp [w]; linarith⟩ + have hwv : w ∈ (ball v δ).support X := by + rw [support_ball]; exact ⟨hw,by dsimp [w]; linarith⟩ + exact Set.disjoint_left.mp hd hwu hwv + +end RadialShell +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +noncomputable section +open Finset +variable {V : Type*} [DecidableEq V] {J : Type*} [Fintype J] [PseudoMetricSpace J] {X : V → J → ℝ} + +def Arrangement (X : V → J → ℝ) (O : Finset (RadialShell V)) : Prop := + (∀H ∈ O, H.Valid X) ∧ (O : Set (RadialShell V)).Pairwise (fun H K => Disjoint (H.support X) (K.support X)) + +omit [DecidableEq V] in +lemma arrangement_empty : Arrangement X ∅ := by simp [Arrangement] + +omit [DecidableEq V] in +lemma arrangement_subset {O P : Finset (RadialShell V)} (hO : Arrangement X O) (hPO : P ⊆ O) : + Arrangement X P := ⟨fun H hH => hO.1 H (hPO hH),hO.2.mono hPO⟩ + +omit [DecidableEq V] in +lemma arrangement_disjoint_finsets (hX : ∀v, isProfile (X v)) + {O P : Finset (RadialShell V)} (hO : Arrangement X O) + (hd : ∀H ∈ O, ∀K ∈ P, Disjoint (H.support X) (K.support X)) : Disjoint O P := by + rw [Finset.disjoint_left] + intro H hHO hHP + obtain ⟨w,hw⟩ := valid_support_nonempty hX (hO.1 H hHO) + exact Set.disjoint_left.mp (hd H hHO H hHP) hw hw + +lemma arrangement_union {O P : Finset (RadialShell V)} + (hO : Arrangement X O) (hP : Arrangement X P) + (hd : ∀H ∈ O, ∀K ∈ P, Disjoint (H.support X) (K.support X)) : Arrangement X (O ∪ P) := by + constructor + · intro H hH + rcases mem_union.mp hH with hH | hH + · exact hO.1 H hH + · exact hP.1 H hH + · intro H hH K hK hne + rcases mem_union.mp hH with hH | hH <;> rcases mem_union.mp hK with hK | hK + · exact hO.2 hH hK hne + · exact hd H hH K hK + · exact (hd K hK H hH).symm + · exact hP.2 hH hK hne + +lemma image_restriction_injective (hX : ∀v, isProfile (X v)) + {O : Finset (RadialShell V)} (hO : Arrangement X O) + (f : RadialShell V → RadialShell V) + (hf : ∀H ∈ O, (f H).Valid X ∧ (f H).support X ⊆ H.support X) : + Set.InjOn f (O : Set (RadialShell V)) := by + intro H hH K hK heq + by_contra hne + obtain ⟨w,hw⟩ := valid_support_nonempty hX (hf H hH).1 + exact Set.disjoint_left.mp (hO.2 hH hK hne) ((hf H hH).2 hw) + ((hf K hK).2 (heq ▸ hw)) + +lemma arrangement_image_restriction {O : Finset (RadialShell V)} (hO : Arrangement X O) + (f : RadialShell V → RadialShell V) + (hf : ∀H ∈ O, (f H).Valid X ∧ (f H).support X ⊆ H.support X) : + Arrangement X (O.image f) := by + constructor + · intro H hH + obtain ⟨K,hK,rfl⟩ := mem_image.mp hH + exact (hf K hK).1 + · intro H hH K hK hne + obtain ⟨H',hH',rfl⟩ := mem_image.mp hH + obtain ⟨K',hK',rfl⟩ := mem_image.mp hK + exact (hO.2 hH' hK' (by intro heq; exact hne (congrArg f heq))).mono + (hf H' hH').2 (hf K' hK').2 + +def capacity (Δ : ℝ) (H : RadialShell V) : ℝ := max (H.width-6*Δ) 0 + +def potential (Δ : ℝ) (O : Finset (RadialShell V)) : ℝ := ∑H ∈ O, capacity Δ H + +omit [DecidableEq V] in +lemma capacity_nonneg (Δ : ℝ) (H : RadialShell V) : 0 ≤ capacity Δ H := le_max_right _ _ +omit [DecidableEq V] in +lemma capacity_ge_formal (Δ : ℝ) (H : RadialShell V) : H.width-6*Δ ≤ capacity Δ H := le_max_left _ _ + +lemma potential_union {O P : Finset (RadialShell V)} (hOP : Disjoint O P) (Δ : ℝ) : + potential Δ (O ∪ P) = potential Δ O+potential Δ P := sum_union hOP + +lemma potential_erase {O : Finset (RadialShell V)} {H : RadialShell V} + (hH : H ∈ O) (Δ : ℝ) : potential Δ (O.erase H)+capacity Δ H = potential Δ O := + sum_erase_add _ _ hH + +lemma potential_image_restriction (hX : ∀v, isProfile (X v)) + {O : Finset (RadialShell V)} (hO : Arrangement X O) + (f : RadialShell V → RadialShell V) + (hf : ∀H ∈ O, (f H).Valid X ∧ (f H).support X ⊆ H.support X) (Δ : ℝ) : + potential Δ (O.image f) = ∑H ∈ O, capacity Δ (f H) := by + exact sum_image (fun H hH K hK heq => image_restriction_injective hX hO f hf hH hK heq) + +omit [DecidableEq V] in +lemma capacity_ball {δ Δ : ℝ} (h : 6*Δ ≤ δ) (v : V) : + capacity Δ (ball v δ) = δ-6*Δ := by + simp only [capacity,width,ball,sub_zero] + exact max_eq_left (sub_nonneg.mpr h) + +omit [DecidableEq V] in +lemma ball_injective (δ : ℝ) : Function.Injective (fun v : V => ball v δ) := by + intro u v heq + exact congrArg RadialShell.center heq + +lemma potential_balls {δ Δ : ℝ} (h : 6*Δ ≤ δ) (C : Finset V) : + potential Δ (C.image (fun v => ball v δ)) = (C.card : ℝ)*(δ-6*Δ) := by + rw [potential,sum_image (fun _ _ _ _ heq => ball_injective δ heq)] + simp only [capacity_ball h,sum_const,nsmul_eq_mul] + +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +noncomputable section +open Finset +variable {V : Type*} [DecidableEq V] {J : Type*} [Fintype J] [PseudoMetricSpace J] {X : V → J → ℝ} + +omit [DecidableEq V] in +lemma potential_filter_width (O : Finset (RadialShell V)) {Δ : ℝ} (hΔ : 0 ≤ Δ) : + potential Δ (O.filter (fun H => 0 < H.width)) = potential Δ O := by + apply sum_subset (filter_subset _ _) + intro H hH hn + have hw : H.width ≤ 0 := le_of_not_gt (fun hh => hn (mem_filter.mpr ⟨hH,hh⟩)) + exact max_eq_right (by nlinarith) + +lemma arrangement_balls {U : Finset V} {δ : ℝ} + (hv : ∀u ∈ U, (ball u δ).Valid X) + (hd : (U : Set V).Pairwise (fun u v => Disjoint ((ball u δ).support X) ((ball v δ).support X))) : + Arrangement X (U.image (fun v => ball v δ)) := by + constructor + · intro H hH + obtain ⟨u,hu,rfl⟩ := mem_image.mp hH + exact hv u hu + · intro H hH K hK hne + obtain ⟨u,hu,rfl⟩ := mem_image.mp hH + obtain ⟨v,hv,rfl⟩ := mem_image.mp hK + exact hd hu hv (by intro heq; exact hne (congrArg (fun z => ball z δ) heq)) + +lemma split_shells (_hX : ∀v, isProfile (X v)) + {H : RadialShell V} (hH : H.Valid X) {L R δ Δ Δ' n : ℝ} + (hδ : 0 < δ) (hΔ : 2*δ ≤ Δ) (_hΔ' : 0 ≤ Δ') (hnext : 6*Δ' ≤ δ/2) + (hL : H.inner+δ ≤ L) (hR : R ≤ H.outer-δ) (hLR : L ≤ R) + (hspan : R-L ≤ Δ) (hn : 36*Δ ≤ n*δ) : + ∃P : Finset (RadialShell V), Arrangement X P ∧ + (∀K ∈ P, K.support X ⊆ H.support X) ∧ + (∀z, L ≤ normDistance (X z) (X H.center) → normDistance (X z) (X H.center) ≤ R → + ∀K ∈ P, Disjoint ((ball z δ).support X) (K.support X)) ∧ + capacity Δ H+n*δ/4 ≤ potential Δ P+n*(δ-6*Δ') := by + let A := hollow H.center H.inner (L-δ) + let B := hollow H.center (R+δ) H.outer + let P := ({A,B} : Finset (RadialShell V)).filter (fun K => 0 < K.width) + have hΔ0 : 0 ≤ Δ := by linarith + have hA : H.inner ≤ L-δ := by linarith + have hB : R+δ ≤ H.outer := by linarith + have hAB : A ≠ B := by + intro heq + have := congrArg RadialShell.inner heq + change H.inner = R+δ at this + linarith + have hpA : L-δ ≤ H.outer := by linarith + have hpB : H.inner ≤ R+δ := by linarith + have hdAB : Disjoint (A.support X) (B.support X) := concentric_disjoint X H.center (by linarith) + have hv : ∀K ∈ P, K.Valid X := by + intro K hK + obtain ⟨hK,hw⟩ := mem_filter.mp hK + rcases mem_insert.mp hK with rfl | hK + · exact restriction_valid hH le_rfl hpA (by exact sub_pos.mp hw) + · have heq := mem_singleton.mp hK + subst K + exact restriction_valid hH hpB le_rfl (by exact sub_pos.mp hw) + have hsub : ∀K ∈ P, K.support X ⊆ H.support X := by + intro K hK + have hK := (mem_filter.mp hK).1 + rcases mem_insert.mp hK with rfl | hK + · exact restriction_subset X H le_rfl hpA + · have heq := mem_singleton.mp hK + subst K + exact restriction_subset X H hpB le_rfl + have harr : Arrangement X P := by + refine ⟨hv,?_⟩ + intro J hJ K hK hne + have hJ := (mem_filter.mp hJ).1 + have hK := (mem_filter.mp hK).1 + simp only [mem_insert,mem_singleton] at hJ hK + rcases hJ with rfl | rfl <;> rcases hK with rfl | rfl + · exact (hne rfl).elim + · exact hdAB + · exact hdAB.symm + · exact (hne rfl).elim + refine ⟨P,harr,hsub,?_,?_⟩ + · intro z hzL hzR K hK + have hK := (mem_filter.mp hK).1 + rcases mem_insert.mp hK with rfl | hK + · exact ball_disjoint_hollow_lower X H.center z (by linarith) + · have heq := mem_singleton.mp hK + subst K + exact ball_disjoint_hollow_upper X H.center z (by linarith) + · have hp : potential Δ P = capacity Δ A+capacity Δ B := by + rw [show P = ({A,B} : Finset (RadialShell V)).filter (fun K => 0 < K.width) from rfl, + potential_filter_width _ hΔ0] + simp [potential,hAB] + rw [hp] + have hn0 : 0 ≤ n := by nlinarith + have hnew : n*δ/2 ≤ n*(δ-6*Δ') := by nlinarith + have hcapA := capacity_ge_formal Δ A + have hcapB := capacity_ge_formal Δ B + have hcapA0 := capacity_nonneg Δ A + have hcapB0 := capacity_nonneg Δ B + change L-δ-H.inner-6*Δ ≤ capacity Δ A at hcapA + change H.outer-(R+δ)-6*Δ ≤ capacity Δ B at hcapB + by_cases ht : H.width-6*Δ ≤ 0 + · rw [capacity,max_eq_right ht] + nlinarith + · rw [capacity,max_eq_left (le_of_not_ge ht)] + dsimp [width] + nlinarith + +lemma shrink_shells (hX : ∀v, isProfile (X v)) + {O : Finset (RadialShell V)} (hO : Arrangement X O) + {δ Δ Δ' : ℝ} (hδ : 0 < δ) (hΔ : 2*δ ≤ Δ) (_hΔ' : 0 ≤ Δ') (hnext : 6*Δ' ≤ δ/2) : + ∃P : Finset (RadialShell V), Arrangement X P ∧ + (∀K ∈ P, ∃H ∈ O, K.support X ⊆ H.support X) ∧ + (∀z, (∀H ∈ O, ¬(H.inner+δ+Δ ≤ normDistance (X z) (X H.center) ∧ + normDistance (X z) (X H.center) ≤ H.outer-δ-Δ)) → + ∀K ∈ P, Disjoint ((ball z δ).support X) (K.support X)) ∧ + potential Δ O ≤ potential Δ' P := by + let s := 2*δ+Δ + let f := fun H : RadialShell V => hollow H.center (H.inner+s) (H.outer-s) + let Q := O.filter (fun H => 2*s < H.width) + have hs : 0 ≤ s := by dsimp [s]; linarith + have hres : 2*s+6*Δ' ≤ 6*Δ := by dsimp [s]; linarith + have hQ : Arrangement X Q := arrangement_subset hO (filter_subset _ _) + have hf : ∀H ∈ Q, (f H).Valid X ∧ (f H).support X ⊆ H.support X := by + intro H hH + obtain ⟨hH,hw⟩ := mem_filter.mp hH + exact ⟨restriction_valid (hO.1 H hH) (by linarith) (by linarith) + (by dsimp [width] at hw; linarith),restriction_subset X H (by linarith) (by linarith)⟩ + refine ⟨Q.image f,arrangement_image_restriction hQ f hf,?_,?_,?_⟩ + · intro K hK + obtain ⟨H,hH,rfl⟩ := mem_image.mp hK + exact ⟨H,(mem_filter.mp hH).1,(hf H hH).2⟩ + · intro z hz K hK + obtain ⟨H,hH,rfl⟩ := mem_image.mp hK + have hz := hz H (mem_filter.mp hH).1 + by_cases hlo : H.inner+δ+Δ ≤ normDistance (X z) (X H.center) + · have hhi : H.outer-δ-Δ < normDistance (X z) (X H.center) := + lt_of_not_ge (fun hh => hz ⟨hlo,hh⟩) + exact ball_disjoint_hollow_lower X H.center z (by dsimp [s]; linarith) + · have hlo := lt_of_not_ge hlo + exact ball_disjoint_hollow_upper X H.center z (by dsimp [s]; linarith) + · rw [potential_image_restriction hX hQ f hf] + have heq : potential Δ O = potential Δ Q := by + symm + apply sum_subset (filter_subset _ _) + intro H hH hn + have hw : H.width ≤ 2*s := le_of_not_gt (fun hh => hn (mem_filter.mpr ⟨hH,hh⟩)) + exact max_eq_right (by linarith) + rw [heq] + apply sum_le_sum + intro H hH + apply max_le_max_right + dsimp [f,width,hollow] + linarith + +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +noncomputable section +open Finset +variable {V : Type*} [DecidableEq V] {J : Type*} [Fintype J] [PseudoMetricSpace J] {X : V → J → ℝ} + +omit [DecidableEq V] [PseudoMetricSpace J] in +lemma radial_span {D : Finset V} (hD : D.Nonempty) {Δ δ : ℝ} + (hdiam : ∀u ∈ D, ∀v ∈ D, normDistance (X u) (X v) ≤ Δ) + {H : RadialShell V} {z : V} (hz : z ∈ D) + (hint : H.inner+δ+Δ ≤ normDistance (X z) (X H.center) ∧ + normDistance (X z) (X H.center) ≤ H.outer-δ-Δ) : + ∃L R : ℝ, H.inner+δ ≤ L ∧ R ≤ H.outer-δ ∧ L ≤ R ∧ R-L ≤ Δ ∧ + (∀u ∈ D, L ≤ normDistance (X u) (X H.center) ∧ normDistance (X u) (X H.center) ≤ R) := by + obtain ⟨u,hu,humin⟩ := D.exists_min_image (fun v => normDistance (X v) (X H.center)) hD + obtain ⟨v,hv,hvmax⟩ := D.exists_max_image (fun v => normDistance (X v) (X H.center)) hD + refine ⟨normDistance (X u) (X H.center),normDistance (X v) (X H.center),?_,?_,?_,?_,?_⟩ + · have ht := normDistance_triangle (X z) (X u) (X H.center) + have hd := hdiam z hz u hu + linarith [hint.1] + · have ht := normDistance_triangle (X v) (X z) (X H.center) + have hd := hdiam v hv z hz + linarith [hint.2] + · exact humin v hv + · have ht := normDistance_triangle (X v) (X u) (X H.center) + linarith [hdiam v hv u hu] + · exact fun w hw => ⟨humin w hw,hvmax w hw⟩ + +lemma compact_phase (hX : ∀v, isProfile (X v)) + {δ Δ Δ' : ℝ} (hδ : 0 < δ) (hΔ : 2*δ ≤ Δ) (hΔ' : 0 ≤ Δ') (hnext : 6*Δ' ≤ δ/2) + (U : Finset V) (hUv : ∀u ∈ U, (ball u δ).Valid X) + (hUd : (U : Set V).Pairwise (fun u v => Disjoint ((ball u δ).support X) ((ball v δ).support X))) + (F : Finset (Finset V)) + (hFd : (F : Set (Finset V)).Pairwise Disjoint) + (hF : ∀D ∈ F, D ⊆ U ∧ D.Nonempty ∧ + (∀u ∈ D, ∀v ∈ D, normDistance (X u) (X v) ≤ Δ) ∧ 36*Δ ≤ (D.card : ℝ)*δ) + (O : Finset (RadialShell V)) (hO : Arrangement X O) + (C : Finset V) (hCU : C ⊆ U) (hCF : ∀D ∈ F, Disjoint C D) + (hOC : ∀H ∈ O, ∀z ∈ C, Disjoint (H.support X) ((ball z δ).support X)) : + ∃Z : Finset (RadialShell V), Arrangement X Z ∧ + potential Δ O+(C.card : ℝ)*(δ-6*Δ')+δ/4*∑D ∈ F, (D.card : ℝ) ≤ potential Δ' Z := by + induction F using Finset.strongInductionOn generalizing O C with + | _ F ih => + by_cases hinter : ∃D ∈ F, ∃z ∈ D, ∃H ∈ O, + H.inner+δ+Δ ≤ normDistance (X z) (X H.center) ∧ + normDistance (X z) (X H.center) ≤ H.outer-δ-Δ + · obtain ⟨D,hDF,z,hz,H,hHO,hint⟩ := hinter + obtain ⟨L,R,hL,hR,hLR,hspan,hbounds⟩ := + radial_span (hF D hDF).2.1 (hF D hDF).2.2.1 hz hint + obtain ⟨P,hP,hPH,hPD,hpot⟩ := split_shells hX (hO.1 H hHO) hδ hΔ hΔ' hnext + hL hR hLR hspan (hF D hDF).2.2.2 + have hballH : ∀u ∈ D, (ball u δ).support X ⊆ H.support X := by + intro u hu + exact ball_subset_of_radial_margin X H u (hL.trans (hbounds u hu).1) + ((hbounds u hu).2.trans hR) + have hcross : ∀K ∈ O.erase H, ∀J ∈ P, Disjoint (K.support X) (J.support X) := by + intro K hK J hJ + exact (hO.2 (mem_of_mem_erase hK) hHO (ne_of_mem_erase hK)).mono_right (hPH J hJ) + have hOE := arrangement_subset hO (erase_subset H O) + have hOP := arrangement_union hOE hP hcross + have hCUD : C ∪ D ⊆ U := union_subset hCU (hF D hDF).1 + have hCDE : ∀E ∈ F.erase D, Disjoint (C ∪ D) E := by + intro E hE + exact disjoint_union_left.mpr ⟨hCF E (mem_of_mem_erase hE), + hFd hDF (mem_of_mem_erase hE) (ne_of_mem_erase hE).symm⟩ + have hnewOC : ∀K ∈ O.erase H ∪ P, ∀u ∈ C ∪ D, + Disjoint (K.support X) ((ball u δ).support X) := by + intro K hK u hu + rcases mem_union.mp hK with hK | hK <;> rcases mem_union.mp hu with hu | hu + · exact hOC K (mem_of_mem_erase hK) u hu + · exact (hO.2 (mem_of_mem_erase hK) hHO (ne_of_mem_erase hK)).mono_right (hballH u hu) + · exact (hOC H hHO u hu).mono_left (hPH K hK) + · exact (hPD u (hbounds u hu).1 (hbounds u hu).2 K hK).symm + obtain ⟨Z,hZ,hZpot⟩ := ih (F.erase D) (erase_ssubset hDF) + (hFd.mono (erase_subset _ _)) (fun E hE => hF E (mem_of_mem_erase hE)) + (O.erase H ∪ P) hOP (C ∪ D) hCUD hCDE hnewOC + refine ⟨Z,hZ,?_⟩ + have hp := potential_union (arrangement_disjoint_finsets hX hOE hcross) Δ + have he := potential_erase hHO Δ + have hc := card_union_of_disjoint (hCF D hDF) + have hs := sum_erase_add F (fun E : Finset V => (E.card : ℝ)) hDF + have hc' : ((C ∪ D).card : ℝ) = (C.card : ℝ)+(D.card : ℝ) := by exact_mod_cast hc + rw [hp,hc'] at hZpot + nlinarith + · obtain ⟨P,hP,hPO,hPF,hpot⟩ := shrink_shells hX hO hδ hΔ hΔ' hnext + let W := C ∪ F.biUnion id + have hWU : W ⊆ U := by + intro u hu + rcases mem_union.mp hu with hu | hu + · exact hCU hu + · obtain ⟨D,hD,hu⟩ := mem_biUnion.mp hu + exact (hF D hD).1 hu + have hB : Arrangement X (W.image (fun u => ball u δ)) := + arrangement_balls (fun u hu => hUv u (hWU hu)) (hUd.mono hWU) + have hcross : ∀H ∈ P, ∀K ∈ W.image (fun u => ball u δ), + Disjoint (H.support X) (K.support X) := by + intro H hH K hK + obtain ⟨u,hu,rfl⟩ := mem_image.mp hK + rcases mem_union.mp hu with hu | hu + · obtain ⟨J,hJ,hsub⟩ := hPO H hH + exact (hOC J hJ u hu).mono_left hsub + · obtain ⟨D,hD,hu⟩ := mem_biUnion.mp hu + exact (hPF u (fun J hJ hh => hinter ⟨D,hD,u,hu,J,hJ,hh⟩) H hH).symm + refine ⟨P ∪ W.image (fun u => ball u δ),arrangement_union hP hB hcross,?_⟩ + rw [potential_union (arrangement_disjoint_finsets hX hP hcross), + potential_balls (show 6*Δ' ≤ δ by linarith)] + have hCW : Disjoint C (F.biUnion id) := by + rw [Finset.disjoint_left] + intro u hu hv + obtain ⟨D,hD,hv⟩ := mem_biUnion.mp hv + exact Finset.disjoint_left.mp (hCF D hD) hu hv + have hflat : (F.biUnion id).card = ∑D ∈ F, D.card := card_biUnion hFd + have hwcard : (W.card : ℝ) = (C.card : ℝ)+∑D ∈ F, (D.card : ℝ) := by + dsimp [W] + rw [card_union_of_disjoint hCW,hflat,Nat.cast_add,Nat.cast_sum] + rw [hwcard] + have hsum : 0 ≤ ∑D ∈ F, (D.card : ℝ) := sum_nonneg (fun D _ => Nat.cast_nonneg _) + have hmass : δ/4*(∑D ∈ F, (D.card : ℝ)) ≤ + (∑D ∈ F, (D.card : ℝ))*(δ-6*Δ') := by nlinarith + nlinarith + +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +noncomputable section +open Finset +variable {V : Type*} [DecidableEq V] {J : Type*} [Fintype J] [PseudoMetricSpace J] {X : V → J → ℝ} + +lemma compact_arrangement (hX : ∀v, isProfile (X v)) + (q : ℕ) (δ Δ : ℕ → ℝ) (U : ℕ → Finset V) (F : ℕ → Finset (Finset V)) + (hδ : ∀i < q, 0 < δ i) (hΔ : ∀i < q, 2*δ i ≤ Δ i) + (hΔ0 : ∀i ≤ q, 0 ≤ Δ i) (hnext : ∀i < q, 6*Δ (i+1) ≤ δ i/2) + (hUv : ∀i < q, ∀u ∈ U i, (ball u (δ i)).Valid X) + (hUd : ∀i < q, (U i : Set V).Pairwise + (fun u v => Disjoint ((ball u (δ i)).support X) ((ball v (δ i)).support X))) + (hFd : ∀i < q, (F i : Set (Finset V)).Pairwise Disjoint) + (hF : ∀i < q, ∀D ∈ F i, D ⊆ U i ∧ D.Nonempty ∧ + (∀u ∈ D, ∀v ∈ D, normDistance (X u) (X v) ≤ Δ i) ∧ 36*Δ i ≤ (D.card : ℝ)*δ i) : + ∃Z : Finset (RadialShell V), Arrangement X Z ∧ + (∑i ∈ range q, δ i*(∑D ∈ F i, (D.card : ℝ)))/4 ≤ potential (Δ q) Z := by + have hex : ∀j ≤ q, ∃Z : Finset (RadialShell V), Arrangement X Z ∧ + (∑i ∈ range j, δ i*(∑D ∈ F i, (D.card : ℝ)))/4 ≤ potential (Δ j) Z := by + intro j + induction j with + | zero => + intro _ + exact ⟨∅,arrangement_empty,by simp [potential]⟩ + | succ j ih => + intro hj + have hjq : j < q := by omega + obtain ⟨O,hO,hpot⟩ := ih (by omega) + obtain ⟨Z,hZ,hZp⟩ := compact_phase hX (hδ j hjq) (hΔ j hjq) + (hΔ0 (j+1) hj) (hnext j hjq) (U j) (hUv j hjq) (hUd j hjq) + (F j) (hFd j hjq) (hF j hjq) O hO ∅ (empty_subset _) (by simp) (by simp) + refine ⟨Z,hZ,?_⟩ + simp only [card_empty,Nat.cast_zero,zero_mul,add_zero] at hZp + rw [sum_range_succ] + linarith + exact hex q le_rfl + +structure CompactFamily (X : V → J → ℝ) (δ Δ : ℝ) where + bags : Finset (Finset V) + nonempty : bags.Nonempty + radius_pos : 0 < δ + bags_disjoint : (bags : Set (Finset V)).Pairwise Disjoint + balls_disjoint : (bags.biUnion id : Set V).Pairwise + (fun u v => Disjoint ((ball u δ).support X) ((ball v δ).support X)) + cardinal : ∀D ∈ bags, 2 ≤ D.card + diameter : ∀D ∈ bags, ∀u ∈ D, ∀v ∈ D, normDistance (X u) (X v) ≤ Δ + compact : ∀D ∈ bags, 36*Δ ≤ (D.card : ℝ)*δ + +lemma CompactFamily.ball_valid (hX : ∀v, isProfile (X v)) {δ Δ : ℝ} + (F : CompactFamily X δ Δ) {u : V} (hu : u ∈ F.bags.biUnion id) : + (ball u δ).Valid X := by + obtain ⟨D,hD,huD⟩ := mem_biUnion.mp hu + have hcard := F.cardinal D hD + obtain ⟨v,hv,hvu⟩ := Finset.exists_mem_ne (by omega : 1 < D.card) u + have hvU : v ∈ F.bags.biUnion id := mem_biUnion.mpr ⟨D,hD,hv⟩ + have hdist := disjoint_balls_distance hX u v (F.balls_disjoint hu hvU hvu.symm) + refine ⟨le_rfl,F.radius_pos,fun _ => rfl,⟨u,by simp [ball,normDistance_self]⟩,v,?_⟩ + change δ ≤ normDistance (X v) (X u) + rw [normDistance_comm] + linarith [F.radius_pos] + +lemma CompactFamily.scale (hX : ∀v, isProfile (X v)) {δ Δ : ℝ} + (F : CompactFamily X δ Δ) : 2*δ ≤ Δ := by + obtain ⟨D,hD⟩ := F.nonempty + have hcard := F.cardinal D hD + obtain ⟨u,hu⟩ := card_pos.mp (by omega : 0 < D.card) + obtain ⟨v,hv,hvu⟩ := Finset.exists_mem_ne (by omega : 1 < D.card) u + have huU : u ∈ F.bags.biUnion id := mem_biUnion.mpr ⟨D,hD,hu⟩ + have hvU : v ∈ F.bags.biUnion id := mem_biUnion.mpr ⟨D,hD,hv⟩ + exact (disjoint_balls_distance hX u v (F.balls_disjoint huU hvU hvu.symm)).trans + (F.diameter D hD u hu v hv) + +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell + +namespace AlgorithmicThinTrees.MetricProfiles.CompactGeometry +noncomputable section +open Finset RadialShell + +variable {J : Type*} [Fintype J] [PseudoMetricSpace J] + +lemma arrangement_length_bound {n m : ℕ} (G : StrongThinTree.MultiGraph n m) {k : ℕ} + (hk : G.EdgeConnected k) (X : Fin n → J → ℝ) (hX : ∀v, isProfile (X v)) + {O : Finset (RadialShell (Fin n))} (hO : Arrangement X O) : + (k:ℝ)*potential 0 O ≤ ∑e : Fin m, normDistance (X (G.left e)) (X (G.right e)) := by + classical + obtain ⟨Y,hY⟩ := Classical.axiomOfChoice hX + have hXY : X = fun v => profile (Y v) := funext hY + subst X + have hb := shell_length_bound G hk Y (fun H : O => Y H.val.center) + (fun H : O => H.val.inner) (fun H : O => H.val.outer) + (fun H => (hO.1 H.val H.property).2.1.le) + (fun H => by + simpa only [normDistance, profile_norm_sub] using + (hO.1 H.val H.property).2.2.2.1) + (fun H => by + simpa only [normDistance, profile_norm_sub] using + (hO.1 H.val H.property).2.2.2.2) ?_ + · convert hb using 2 + · rw [potential,Finset.sum_coe_sort O (fun H : RadialShell (Fin n) => H.outer-H.inner)] + apply sum_congr rfl + intro H hH + simp only [capacity,mul_zero,sub_zero] + exact max_eq_left (valid_width_pos (hO.1 H hH)).le + · simp only [normDistance,profile_norm_sub] + · intro H K hne + apply Set.disjoint_left.mpr + rintro w ⟨hw, hHa, hHb⟩ ⟨_, hKa, hKb⟩ + exact Set.disjoint_left.mp (hO.2 H.property K.property (Subtype.val_injective.ne hne)) + ⟨hw,hHb,Or.inr hHa⟩ ⟨hw,hKb,Or.inr hKa⟩ + +lemma metric_compact_bound {n m : ℕ} (G : StrongThinTree.MultiGraph n m) {k : ℕ} + (hk : G.EdgeConnected k) (X : Fin n → J → ℝ) (hX : ∀v, isProfile (X v)) + (q : ℕ) (δ Δ : ℕ → ℝ) (F : ∀i, CompactFamily X (δ i) (Δ i)) + (hnext : ∀i, i+1 < q → Δ (i+1) ≤ δ i/12) : + (k:ℝ)/4*(∑i ∈ range q, δ i*(∑D ∈ (F i).bags, (D.card : ℝ))) ≤ + ∑e : Fin m, normDistance (X (G.left e)) (X (G.right e)) := by + let D := fun i => if i < q then Δ i else 0 + have hD0 : ∀i ≤ q, 0 ≤ D i := by + intro i hi + dsimp [D] + split_ifs with hh + · linarith [(F i).scale hX,(F i).radius_pos] + · exact le_rfl + obtain ⟨Z,hZ,hZp⟩ := compact_arrangement hX q δ D + (fun i => (F i).bags.biUnion id) (fun i => (F i).bags) + (fun i _ => (F i).radius_pos) + (fun i hi => by simpa [D,hi] using (F i).scale hX) hD0 + (by + intro i hi + dsimp [D] + split_ifs with hh + · linarith [hnext i hh] + · linarith [(F i).radius_pos]) + (fun i _ u hu => (F i).ball_valid hX hu) + (fun i _ => (F i).balls_disjoint) + (fun i _ => (F i).bags_disjoint) + (by + intro i hi S hS + refine ⟨?_,?_,?_,?_⟩ + · intro u hu; exact mem_biUnion.mpr ⟨S,hS,hu⟩ + · exact card_pos.mp (by have := (F i).cardinal S hS; omega) + · simpa [D,hi] using (F i).diameter S hS + · simpa [D,hi] using (F i).compact S hS) + simp only [D,lt_self_iff_false,ite_false] at hZp + have hmul := mul_le_mul_of_nonneg_left hZp (Nat.cast_nonneg k : (0:ℝ) ≤ k) + have hlength := arrangement_length_bound G hk X hX hZ + nlinarith + +lemma doubled_compact_bound {n m : ℕ} (G : StrongThinTree.MultiGraph n m) {k : ℕ} + (hk : G.EdgeConnected k) (X : Fin n → J) + (q : ℕ) (δ Δ : ℕ → ℝ) + (F : ∀i, CompactFamily (fun v => profile (plus (X v))) (δ i) (Δ i)) + (hnext : ∀i, i+1 < q → Δ (i+1) ≤ δ i/12) : + (k:ℝ)/4*(∑i ∈ range q, δ i*(∑D ∈ (F i).bags, (D.card : ℝ))) ≤ + ∑e : Fin m, dist (X (G.left e)) (X (G.right e)) := by + simpa only [normDistance, profile_norm_sub, dist_plus] using + metric_compact_bound G hk (fun v => profile (plus (X v))) + (fun v => ⟨plus (X v),rfl⟩) q δ Δ F hnext + +end +end AlgorithmicThinTrees.MetricProfiles.CompactGeometry +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/CompactDuality.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/CompactDuality.lean new file mode 100644 index 0000000000000000000000000000000000000000..1b4c474062f951e3859661b1a1271f009a4739f4 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/CompactDuality.lean @@ -0,0 +1,158 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.ConicDuality + +namespace OAI + +/-! Metric compact duality. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree +open scoped Classical MatrixOrder Matrix.Norms.Elementwise + +variable {n : ℕ} {E T : Type*} + +lemma average_antitone (b : E → Fin n → ℝ) (O : T → Finset E) (t : T) + {D F : Matrix (Fin n) (Fin n) ℝ} (hD : D.PosDef) (hF : F.PosDef) (hDF : D ≤ F) : + ShortcutDual.boundaryAverage b O t F ≤ ShortcutDual.boundaryAverage b O t D := by + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr (Nat.cast_nonneg _)) + exact sum_le_sum (fun e _ => resistance_antitone hF hD (Matrix.le_iff.mp hDF) (b e)) + +lemma average_smul (b : E → Fin n → ℝ) (O : T → Finset E) (t : T) + {D : Matrix (Fin n) (Fin n) ℝ} (hD : D.PosDef) {c : ℝ} (hc : 0 < c) : + ShortcutDual.boundaryAverage b O t (c • D)=c⁻¹*ShortcutDual.boundaryAverage b O t D := by + let : Invertible c := invertibleOfNonzero hc.ne' + simp only [ShortcutDual.boundaryAverage,Matrix.inv_smul D c ((Matrix.isUnit_iff_isUnit_det D).mp hD.isUnit), + invOf_eq_inv,smul_mulVec,dotProduct_smul,smul_eq_mul,←mul_sum] + ring + +lemma average_continuousAt (b : E → Fin n → ℝ) (O : T → Finset E) (t : T) + {D : Matrix (Fin n) (Fin n) ℝ} (hD : D.PosDef) : + ContinuousAt (ShortcutDual.boundaryAverage b O t) D := by + have hc : Continuous (fun X : Matrix (Fin n) (Fin n) ℝ => + ((O t).card : ℝ)⁻¹ * ∑e ∈ O t, qform X (b e)) := + (continuous_finsetSum _ (fun e _ => qform_continuous (b e))).const_mul _ + apply hc.continuousAt.comp + apply continuousAt_matrix_inv + simpa only [Ring.inverse_eq_inv'] using continuousAt_inv₀ hD.det_pos.ne' + +def pdBox (B : Matrix (Fin n) (Fin n) ℝ) : Set (Matrix (Fin n) (Fin n) ℝ) := + {D | (1/4:ℝ) • B ≤ D ∧ D.trace ≤ B.trace} + +lemma pdBox_pd {B D : Matrix (Fin n) (Fin n) ℝ} (hB : B.PosDef) (hD : D ∈ pdBox B) : D.PosDef := + posDef_of_le (hB.smul (by norm_num : (0:ℝ)<1/4)) hD.1 + +lemma pdBox_closed (B : Matrix (Fin n) (Fin n) ℝ) : IsClosed (pdBox B) := + (isClosed_matrixAbove _).inter (isClosed_le + (by simpa only [mul_one] using trace_pairing_continuous (1 : Matrix (Fin n) (Fin n) ℝ)) continuous_const) + +lemma pdBox_bounded {B : Matrix (Fin n) (Fin n) ℝ} (hB : B.PosDef) : Bornology.IsBounded (pdBox B) := by + apply isBounded_iff_forall_norm_le.mpr + refine ⟨B.trace,fun D hD => ?_⟩ + have hC : 0 ≤ B.trace := hB.posSemidef.trace_nonneg + have hDp := (pdBox_pd hB hD).posSemidef + have hdiag : ∀i, D i i ≤ B.trace := by + intro i + exact (single_le_sum (fun j _ => hDp.diag_nonneg (i := j)) (mem_univ i)).trans hD.2 + apply (pi_norm_le_iff_of_nonneg hC).mpr + intro i + apply (pi_norm_le_iff_of_nonneg hC).mpr + intro j + simpa only [Real.norm_eq_abs] using psd_entry_bound hDp hC hdiag i j + +lemma pdBox_compact {B : Matrix (Fin n) (Fin n) ℝ} (hB : B.PosDef) : IsCompact (pdBox B) := + Metric.isCompact_iff_isClosed_bounded.mpr ⟨pdBox_closed B,pdBox_bounded hB⟩ + +lemma pdBox_objective_closed (b : E → Fin n → ℝ) (O : T → Finset E) + {B : Matrix (Fin n) (Fin n) ℝ} (hB : B.PosDef) (K : ℝ) : + IsClosed {D | D ∈ pdBox B ∧ ∀t, ShortcutDual.boundaryAverage b O t D ≤ K} := by + have ht (t : T) : IsClosed {D | D ∈ pdBox B ∧ ShortcutDual.boundaryAverage b O t D ≤ K} := + (pdBox_closed B).isClosed_le (fun D hD => (average_continuousAt b O t (pdBox_pd hB hD)).continuousWithinAt) + continuousOn_const + have heq : {D | D ∈ pdBox B ∧ ∀t, ShortcutDual.boundaryAverage b O t D ≤ K}= + pdBox B ∩ ⋂t, {D | D ∈ pdBox B ∧ ShortcutDual.boundaryAverage b O t D ≤ K} := by + ext D + simp only [Set.mem_ofPred_eq,Set.mem_inter_iff,Set.mem_iInter] + constructor + · exact fun h => ⟨h.1,fun t => ⟨h.1,h.2 t⟩⟩ + · exact fun h => ⟨h.1,fun t => (h.2 t).2⟩ + rw [heq] + exact (pdBox_closed B).inter (isClosed_iInter ht) + +section Cone +variable [Fintype T] + +theorem metric_shortcut_of_trace_bound (hn : 0 < n) + (b : E → Fin n → ℝ) (O : T → Finset E) + (B : Matrix (Fin n) (Fin n) ℝ) (hB : B.PosDef) {K : ℝ} (hK : 0 < K) + (hbound : ∀Z : Matrix (Fin n) (Fin n) ℝ, Test Z → + ∀lam : T → ℝ, (∀t, 0 ≤ lam t) → (∑t, lam t)=1 → + (CFC.sqrt (CFC.sqrt Z*ShortcutDual.objectiveMatrix b O lam*CFC.sqrt Z)).trace^2 ≤ K*(B*Z).trace) : + ∃D : Matrix (Fin n) (Fin n) ℝ, D.PosDef ∧ + (∀t, ShortcutDual.boundaryAverage b O t D ≤ 2*K) ∧ + (∀Z : Matrix (Fin n) (Fin n) ℝ, Test Z → (D*Z).trace ≤ (B*Z).trace) := by + let C := {D | D ∈ pdBox B ∧ ∀t, ShortcutDual.boundaryAverage b O t D ≤ 2*K} + have hC : IsCompact C := (pdBox_compact hB).of_isClosed_subset + (pdBox_objective_closed b O hB (2*K)) (fun _ h => h.1) + let I := {Z : Matrix (Fin n) (Fin n) ℝ // Test Z} + let A : I → Set (Matrix (Fin n) (Fin n) ℝ) := fun Z => {D | (D*Z.val).trace ≤ (B*Z.val).trace} + have hA : ∀Z, IsClosed (A Z) := fun Z => isClosed_le (trace_pairing_continuous Z.val) continuous_const + have hfinite : ∀s : Finset I, (C ∩ ⋂Z ∈ s, A Z).Nonempty := by + intro s + have h1 : (1 : Matrix (Fin n) (Fin n) ℝ) ≠ 0 := by + intro he + have hh := congrFun (congrFun he ⟨0,hn⟩) ⟨0,hn⟩ + norm_num at hh + let s' : Finset I := (insert ⟨1,test_one⟩ s).filter fun Z => Z.val ≠ 0 + have hbnd : ∀lam : T → ℝ, ∀y : s' → ℝ, + (∀t, 0 ≤ lam t) → (∑t, lam t)=1 → (∀j, 0 ≤ y j) → + (CFC.sqrt (CFC.sqrt (∑j, y j • j.val.val)*ShortcutDual.objectiveMatrix b O lam* + CFC.sqrt (∑j, y j • j.val.val))).trace^2 ≤ K*∑j, y j*(B*j.val.val).trace := by + intro lam y hlam hsum hy + have ht : Test (∑j : s', y j • j.val.val) := test_sum univ _ + (fun j _ => test_smul j.val.property (hy j)) + simpa only [mul_sum,mul_smul_comm,trace_sum,trace_smul,smul_eq_mul] using hbound _ ht lam hlam hsum + obtain ⟨D,hD,hobj,htr⟩ := finite_shortcut_of_trace_bound b O (fun j : s' => j.val.val) + (fun j => j.val.property.1) (fun j => (B*j.val.val).trace) + (fun j => trace_pairing_pos hB j.val.property.1 ((mem_filter.mp j.property).2)) + hK.le hbnd (eta := K/2) (by positivity) + let F : Matrix (Fin n) (Fin n) ℝ := (3/4:ℝ) • D+(1/4:ℝ) • B + have hF : F.PosDef := (hD.smul (by norm_num : (0:ℝ)<3/4)).add_posSemidef + (hB.posSemidef.smul (by norm_num : (0:ℝ)≤1/4)) + have hFB : (1/4:ℝ) • B ≤ F := by + apply Matrix.le_iff.mpr + simpa only [F,add_sub_cancel_right] using hD.posSemidef.smul (show (0:ℝ)≤3/4 by norm_num) + have hFD : (3/4:ℝ) • D ≤ F := by + apply Matrix.le_iff.mpr + simpa only [F,add_sub_cancel_left] using hB.posSemidef.smul (show (0:ℝ)≤1/4 by norm_num) + have hfbound (t : T) : ShortcutDual.boundaryAverage b O t F ≤ 2*K := by + have hh := average_antitone b O t (hD.smul (show (0:ℝ)<3/4 by norm_num)) hF hFD + rw [average_smul b O t hD (by norm_num : (0:ℝ)<3/4)] at hh + norm_num at hh + linarith only [hh,hobj t] + have hFtr (Z : I) (hZ : Z ∈ insert ⟨1,test_one⟩ s) : (F*Z.val).trace ≤ (B*Z.val).trace := by + by_cases hZ0 : Z.val=0 + · simp [hZ0] + have hh := htr ⟨Z,mem_filter.mpr ⟨hZ,hZ0⟩⟩ + dsimp [F] + simp only [add_mul,smul_mul_assoc,trace_add,trace_smul,smul_eq_mul] + linarith only [hh] + have hFt : F.trace ≤ B.trace := by + simpa only [mul_one] using hFtr ⟨1,test_one⟩ (mem_insert_self _ _) + refine ⟨F,⟨⟨hFB,hFt⟩,hfbound⟩,?_⟩ + simp only [Set.mem_iInter] + intro Z hZ + exact hFtr Z (mem_insert_of_mem hZ) + obtain ⟨D,hDC,hDA⟩ := hC.inter_iInter_nonempty A hA hfinite + refine ⟨D,pdBox_pd hB hDC.1,hDC.2,?_⟩ + intro Z hZ + exact Set.mem_iInter.mp hDA ⟨Z,hZ⟩ + +end Cone +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/ConeRepresentation.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/ConeRepresentation.lean new file mode 100644 index 0000000000000000000000000000000000000000..9885871d78a3dacb2c7e9c1a04c2db1bae4b9f42 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/ConeRepresentation.lean @@ -0,0 +1,334 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.CenteredDomain + +namespace OAI + +/-! Metric cone representation. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder Matrix.Norms.Elementwise Topology +open Filter + +section Representation +variable {n : ℕ} {J : Type*} [Fintype J] + +def coneImage (W : J → Matrix (Fin n) (Fin n) ℝ) : Set (Matrix (Fin n) (Fin n) ℝ) := + {A | ∃P : Matrix (Fin n) (Fin n) ℝ, ∃lam : J → ℝ, + P.PosSemidef ∧ (∀j, 0 ≤ lam j) ∧ A=P+∑j, lam j • W j} + +lemma continuous_trace : Continuous (fun P : Matrix (Fin n) (Fin n) ℝ => P.trace) := by + simpa only [mul_one] using trace_pairing_continuous (1 : Matrix (Fin n) (Fin n) ℝ) + +lemma psd_trace_compact {c : ℝ} (hc : 0 ≤ c) : + IsCompact {P : Matrix (Fin n) (Fin n) ℝ | P.PosSemidef ∧ P.trace ≤ c} := by + apply Metric.isCompact_iff_isClosed_bounded.mpr + refine ⟨isClosed_psd.inter (isClosed_le continuous_trace continuous_const),?_⟩ + apply isBounded_iff_forall_norm_le.mpr + refine ⟨c,fun P hP => ?_⟩ + have hd : ∀i, P i i ≤ c := fun i => + (single_le_sum (fun j _ => hP.1.diag_nonneg (i:=j)) (mem_univ i)).trans hP.2 + apply (pi_norm_le_iff_of_nonneg hc).mpr + intro i + apply (pi_norm_le_iff_of_nonneg hc).mpr + intro j + simpa only [Real.norm_eq_abs] using psd_entry_bound hP.1 hc hd i j + +lemma coneImage_trace_bound (W : J → Matrix (Fin n) (Fin n) ℝ) + (hW : ∀j, (W j).trace=2) (P : Matrix (Fin n) (Fin n) ℝ) (lam : J → ℝ) + (hP : P.PosSemidef) (hlam : ∀j, 0 ≤ lam j) {c : ℝ} + (ht : (P+∑j, lam j • W j).trace ≤ c) : + P.trace ≤ c ∧ ∀j, lam j ≤ c := by + simp only [trace_add,trace_sum,trace_smul,smul_eq_mul,hW,←sum_mul] at ht + have hsum : 0 ≤ ∑j, lam j := sum_nonneg (fun j _ => hlam j) + refine ⟨by linarith only [hsum,ht],?_⟩ + intro j + have hj := single_le_sum (fun i _ => hlam i) (mem_univ j) + have hp := hP.trace_nonneg + linarith only [ht,hp,hlam j,hj] + +lemma coneImage_closed (W : J → Matrix (Fin n) (Fin n) ℝ) + (hW : ∀j, (W j).trace=2) : IsClosed (coneImage W) := by + let : FirstCountableTopology (Matrix (Fin n) (Fin n) ℝ) := + inferInstanceAs (FirstCountableTopology (Fin n → Fin n → ℝ)) + apply IsSeqClosed.isClosed + intro A L hA hlim + choose P lam hP hlam he using hA + have htr : Tendsto (fun k => (A k).trace) atTop (𝓝 L.trace) := continuous_trace.tendsto L |>.comp hlim + obtain ⟨c,hc⟩ := (htr.cauchySeq.isBounded_range).exists_norm_le + let d := max c 0 + have hd : 0 ≤ d := le_max_right _ _ + let K := {P : Matrix (Fin n) (Fin n) ℝ | P.PosSemidef ∧ P.trace ≤ d} ×ˢ + Set.Icc (0 : J → ℝ) (fun _ => d) + have hK : IsCompact K := (psd_trace_compact hd).prod isCompact_Icc + have hw : ∀k, (P k,lam k) ∈ K := by + intro k + have hle : (P k+∑j, lam k j • W j).trace ≤ d := by + rw [←he k] + exact (le_abs_self _).trans ((hc _ (Set.mem_range_self k)).trans (le_max_left _ _)) + have hb := coneImage_trace_bound W hW (P k) (lam k) (hP k) (hlam k) hle + exact ⟨⟨hP k,hb.1⟩,hlam k,hb.2⟩ + obtain ⟨p,hp,φ,hφ,hseq⟩ := hK.tendsto_subseq hw + have hcont : Continuous (fun p : Matrix (Fin n) (Fin n) ℝ × (J → ℝ) => + p.1+∑j, p.2 j • W j) := by fun_prop + have hi := (hcont.tendsto p).comp hseq + have hi' : Tendsto (fun k => P (φ k)+∑j, lam (φ k) j • W j) atTop (𝓝 L) := by + simpa only [Function.comp_def,←he] using hlim.comp hφ.tendsto_atTop + exact ⟨p.1,p.2,hp.1.1,hp.2.1,(tendsto_nhds_unique hi' hi)⟩ + +lemma coneImage_zero (W : J → Matrix (Fin n) (Fin n) ℝ) : 0 ∈ coneImage W := by + exact ⟨0,fun _ => 0,PosSemidef.zero,fun _ => le_refl _,by simp⟩ + +lemma coneImage_add (W : J → Matrix (Fin n) (Fin n) ℝ) + {A B : Matrix (Fin n) (Fin n) ℝ} (hA : A ∈ coneImage W) (hB : B ∈ coneImage W) : + A+B ∈ coneImage W := by + obtain ⟨P,lam,hP,hlam,rfl⟩ := hA + obtain ⟨Q,γ,hQ,hγ,rfl⟩ := hB + refine ⟨P+Q,lam+γ,hP.add hQ,fun j => add_nonneg (hlam j) (hγ j),?_⟩ + simp only [Pi.add_apply,add_smul,sum_add_distrib] + abel + +lemma coneImage_smul (W : J → Matrix (Fin n) (Fin n) ℝ) + {A : Matrix (Fin n) (Fin n) ℝ} (hA : A ∈ coneImage W) {a : ℝ} (ha : 0 ≤ a) : + a • A ∈ coneImage W := by + obtain ⟨P,lam,hP,hlam,rfl⟩ := hA + refine ⟨a • P,fun j => a*lam j,hP.smul ha,fun j => mul_nonneg ha (hlam j),?_⟩ + simp only [smul_add,smul_sum,smul_smul] + +def representedCone (W : J → Matrix (Fin n) (Fin n) ℝ) (hW : ∀j, (W j).trace=2) : + ProperCone ℝ (Matrix (Fin n) (Fin n) ℝ) where + carrier := coneImage W + zero_mem' := coneImage_zero W + add_mem' := coneImage_add W + smul_mem' := fun a _ hA => coneImage_smul W hA a.property + isClosed' := coneImage_closed W hW + +lemma psd_mem_coneImage (W : J → Matrix (Fin n) (Fin n) ℝ) + {P : Matrix (Fin n) (Fin n) ℝ} (hP : P.PosSemidef) : P ∈ coneImage W := by + exact ⟨P,fun _ => 0,hP,fun _ => le_refl _,by simp⟩ + +lemma generator_mem_coneImage (W : J → Matrix (Fin n) (Fin n) ℝ) (j : J) : + W j ∈ coneImage W := by + refine ⟨0,Pi.single j 1,PosSemidef.zero,?_,?_⟩ + · intro i + simp only [Pi.single_apply] + split_ifs <;> norm_num + · simp [Pi.single_apply] + +end Representation +section TraceDual +variable {n : ℕ} + +def linearTraceMatrix (f : Matrix (Fin n) (Fin n) ℝ →ₗ[ℝ] ℝ) : + Matrix (Fin n) (Fin n) ℝ := fun i j => f (Matrix.single j i 1) + +lemma linearTraceMatrix_pairing (f : Matrix (Fin n) (Fin n) ℝ →ₗ[ℝ] ℝ) + (X : Matrix (Fin n) (Fin n) ℝ) : (X*linearTraceMatrix f).trace=f X := by + have hf : f X = ∑i, ∑j, X i j*f (Matrix.single i j 1) := by + nth_rw 1 [matrix_eq_sum_single X] + simp only [map_sum] + apply sum_congr rfl + intro i _ + apply sum_congr rfl + intro j _ + rw [show Matrix.single i j (X i j)=(X i j) • Matrix.single i j (1 : ℝ) by + simp only [smul_single,smul_eq_mul,mul_one]] + simp only [map_smul,smul_eq_mul] + simpa only [Matrix.trace,diag_apply,mul_apply,linearTraceMatrix] using hf.symm + +lemma trace_pairing_transpose_right {X : Matrix (Fin n) (Fin n) ℝ} + (hX : X.IsHermitian) (Z : Matrix (Fin n) (Fin n) ℝ) : + (X*Zᵀ).trace=(X*Z).trace := by + rw [←trace_transpose (X*Zᵀ),transpose_mul,transpose_transpose, + (isHermitian_iff_isSymm.mp hX).eq,trace_mul_comm] + +def symmetricTraceMatrix (f : Matrix (Fin n) (Fin n) ℝ →ₗ[ℝ] ℝ) : + Matrix (Fin n) (Fin n) ℝ := (1/2 : ℝ) • (linearTraceMatrix f+(linearTraceMatrix f)ᵀ) + +lemma symmetricTraceMatrix_hermitian (f : Matrix (Fin n) (Fin n) ℝ →ₗ[ℝ] ℝ) : + (symmetricTraceMatrix f).IsHermitian := by + apply isHermitian_iff_isSymm.mpr + simp only [IsSymm,symmetricTraceMatrix,transpose_smul,transpose_add,transpose_transpose] + rw [add_comm] + +lemma symmetricTraceMatrix_pairing (f : Matrix (Fin n) (Fin n) ℝ →ₗ[ℝ] ℝ) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : X.IsHermitian) : + (X*symmetricTraceMatrix f).trace=f X := by + rw [symmetricTraceMatrix,mul_smul_comm,mul_add,trace_smul,trace_add, + trace_pairing_transpose_right hX,linearTraceMatrix_pairing] + simp only [smul_eq_mul] + ring + +lemma symmetricTraceMatrix_psd (f : Matrix (Fin n) (Fin n) ℝ →ₗ[ℝ] ℝ) + (hf : ∀ P : Matrix (Fin n) (Fin n) ℝ, P.PosSemidef → 0 ≤ f P) : + (symmetricTraceMatrix f).PosSemidef := by + apply PosSemidef.of_dotProduct_mulVec_nonneg (symmetricTraceMatrix_hermitian f) + intro x + simpa only [star_trivial,←ShortcutDual.trace_outer_mul, + symmetricTraceMatrix_pairing f (ShortcutDual.outer_posSemidef x).isHermitian] + using hf (vecMulVec x x) (ShortcutDual.outer_posSemidef x) + +abbrev DistinctTriple (n : ℕ) := + {ijk : Fin n × Fin n × Fin n // ijk.1 ≠ ijk.2.1 ∧ ijk.2.1 ≠ ijk.2.2 ∧ ijk.1 ≠ ijk.2.2} + +def triangleMatrix (u v w : Fin n) : Matrix (Fin n) (Fin n) ℝ := + vecMulVec (difference u v) (difference u v)+ + vecMulVec (difference v w) (difference v w)- + vecMulVec (difference u w) (difference u w) + +def triangleGenerator (ijk : DistinctTriple n) : Matrix (Fin n) (Fin n) ℝ := + triangleMatrix ijk.1.1 ijk.1.2.1 ijk.1.2.2 + +lemma triangleMatrix_hermitian (u v w : Fin n) : (triangleMatrix u v w).IsHermitian := + ((ShortcutDual.outer_posSemidef _).isHermitian.add + (ShortcutDual.outer_posSemidef _).isHermitian).sub (ShortcutDual.outer_posSemidef _).isHermitian + +lemma difference_norm_sq {u v : Fin n} (huv : u ≠ v) : + difference u v ⬝ᵥ difference u v=2 := by + norm_num [difference,point,sub_dotProduct,dotProduct_sub,huv,huv.symm] + +lemma triangleGenerator_trace (ijk : DistinctTriple n) : (triangleGenerator ijk).trace=2 := by + simp only [triangleGenerator,triangleMatrix,trace_sub,trace_add,trace_vecMulVec, + difference_norm_sq ijk.property.1,difference_norm_sq ijk.property.2.1, + difference_norm_sq ijk.property.2.2] + norm_num + +lemma triangleMatrix_ones (u v w : Fin n) : triangleMatrix u v w *ᵥ ones n=0 := by + have h (a b : Fin n) : vecMulVec (difference a b) (difference a b) *ᵥ ones n=0 := by + rw [vecMulVec_mulVec,dotProduct_comm,ones_dot,difference_sum,MulOpposite.op_zero,zero_smul] + simp only [triangleMatrix,sub_mulVec,add_mulVec,h,zero_add,sub_zero] + +lemma triangleMatrix_pairing (u v w : Fin n) (Z : Matrix (Fin n) (Fin n) ℝ) : + (triangleMatrix u v w*Z).trace= + qform Z (difference u v)+qform Z (difference v w)-qform Z (difference u w) := by + simp only [triangleMatrix,sub_mul,add_mul,trace_add,trace_sub,ShortcutDual.trace_outer_mul,qform] + +lemma test_iff_generators (Z : Matrix (Fin n) (Fin n) ℝ) : + Test Z ↔ Z.PosSemidef ∧ ∀ijk : DistinctTriple n, 0 ≤ (triangleGenerator ijk*Z).trace := by + refine ⟨fun hZ => ⟨hZ.1,fun ijk => ?_⟩,fun hZ => ⟨hZ.1,fun u v w => ?_⟩⟩ + · simpa only [triangleGenerator,triangleMatrix_pairing,sub_nonneg] using hZ.2 _ _ _ + · by_cases huv : u=v + · subst v + simp [difference,qform] + by_cases hvw : v=w + · subst w + simp [difference,qform] + by_cases huw : u=w + · subst w + simpa only [difference,sub_self,mulVec_zero,dotProduct_zero,qform] + using add_nonneg (qform_nonneg hZ.1 (difference u v)) (qform_nonneg hZ.1 (difference v u)) + have hh := hZ.2 ⟨(u,v,w),huv,hvw,huw⟩ + simpa only [triangleGenerator,triangleMatrix_pairing,sub_nonneg] using hh + +theorem metric_dual_representation {A : Matrix (Fin n) (Fin n) ℝ} + (hA : A.IsHermitian) : + (∀Z, Test Z → 0 ≤ (A*Z).trace) ↔ A ∈ coneImage (triangleGenerator (n:=n)) := by + constructor + · intro hdual + by_contra hn + let : LocallyConvexSpace ℝ (Matrix (Fin n) (Fin n) ℝ) := + inferInstanceAs (LocallyConvexSpace ℝ (Fin n → Fin n → ℝ)) + obtain ⟨f,hf,hfA⟩ := (representedCone triangleGenerator triangleGenerator_trace).hyperplane_separation_point hn + have hfP : ∀P : Matrix (Fin n) (Fin n) ℝ, P.PosSemidef → 0 ≤ f P := + fun P hP => hf P (psd_mem_coneImage triangleGenerator hP) + let Z := symmetricTraceMatrix f.toLinearMap + have hZ : Test Z := by + apply (test_iff_generators Z).mpr + refine ⟨symmetricTraceMatrix_psd f.toLinearMap hfP,fun ijk => ?_⟩ + change 0 ≤ (triangleGenerator ijk*symmetricTraceMatrix f.toLinearMap).trace + have hi : (triangleGenerator ijk).IsHermitian := triangleMatrix_hermitian _ _ _ + rw [symmetricTraceMatrix_pairing f.toLinearMap hi] + exact hf _ (generator_mem_coneImage triangleGenerator ijk) + have hz := hdual Z hZ + rw [symmetricTraceMatrix_pairing f.toLinearMap hA] at hz + exact (not_lt_of_ge hz) hfA + · rintro ⟨P,lam,hP,hlam,rfl⟩ Z hZ + simp only [add_mul,sum_mul,smul_mul_assoc,trace_add,trace_sum,trace_smul,smul_eq_mul] + exact add_nonneg (trace_pairing_nonneg hP hZ.1) + (sum_nonneg fun ijk _ => mul_nonneg (hlam ijk) (((test_iff_generators Z).mp hZ).2 ijk)) + +lemma trace_centered_right {A : Matrix (Fin n) (Fin n) ℝ} + (hA : A.IsHermitian) (hA0 : A *ᵥ ones n=0) (Z : Matrix (Fin n) (Fin n) ℝ) : + (A*centered Z).trace=(A*Z).trace := by + calc + (A*centered Z).trace=((A*centering n)*Z*centering n).trace := by + simp only [centered,mul_assoc] + _ = (A*Z*centering n).trace := by rw [mul_centering_of_ones hA0] + _ = (centering n*(A*Z)).trace := trace_mul_comm _ _ + _ = (A*Z).trace := by rw [←mul_assoc,centering_mul_of_ones hA hA0] + +theorem centered_metric_dual_representation (hn : 0 < n) + {A : Matrix (Fin n) (Fin n) ℝ} (hA : A.IsHermitian) (hA0 : A *ᵥ ones n=0) : + (∀Z, CenteredTest Z → 0 ≤ (A*Z).trace) ↔ + ∃P : Matrix (Fin n) (Fin n) ℝ, ∃lam : DistinctTriple n → ℝ, + P.PosSemidef ∧ P *ᵥ ones n=0 ∧ (∀ijk, 0 ≤ lam ijk) ∧ + A=P+∑ijk, lam ijk • triangleGenerator ijk := by + constructor + · intro hdual + have hd : ∀Z, Test Z → 0 ≤ (A*Z).trace := fun Z hZ => by + have h := hdual _ (test_centered hn hZ) + rwa [trace_centered_right hA hA0] at h + obtain ⟨P,lam,hP,hlam,he⟩ := (metric_dual_representation hA).mp hd + refine ⟨P,lam,hP,?_,hlam,he⟩ + rw [he,add_mulVec] at hA0 + simpa only [sum_mulVec,smul_mulVec,triangleGenerator,triangleMatrix_ones, + smul_zero,sum_const_zero,add_zero] using hA0 + · rintro ⟨P,lam,hP,_,hlam,he⟩ Z hZ + exact (metric_dual_representation hA).mpr ⟨P,lam,hP,hlam,he⟩ Z hZ.1 + +theorem metricDomain_iff_lmi {m : ℕ} (G : MultiGraph n m) (hn : 0 < n) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : X.IsHermitian) (hX0 : X *ᵥ ones n=0) : + X ∈ metricDomain G ↔ G.laplacian univ ≤ X ∧ + ∃lam : DistinctTriple n → ℝ, (∀ijk, 0 ≤ lam ijk) ∧ + ((3:ℝ) • G.laplacian univ-X-∑ijk, lam ijk • triangleGenerator ijk).PosSemidef := by + have hA : ((3:ℝ) • G.laplacian univ-X).IsHermitian := + ((G.laplacian_psd univ).smul (by norm_num : (0:ℝ) ≤ 3)).isHermitian.sub hX + have hA0 : ((3:ℝ) • G.laplacian univ-X) *ᵥ ones n=0 := by + simp only [sub_mulVec,smul_mulVec,laplacian_ones,hX0,smul_zero,sub_self] + constructor + · intro h + refine ⟨h.2.2.1,?_⟩ + obtain ⟨P,lam,hP,_,hlam,he⟩ := (centered_metric_dual_representation hn hA hA0).mp + (fun Z hZ => by + simpa only [sub_mul,smul_mul_assoc,trace_sub,trace_smul,smul_eq_mul,sub_nonneg] + using h.2.2.2 Z hZ) + refine ⟨lam,hlam,?_⟩ + rwa [he,add_sub_cancel_right] + · rintro ⟨hLX,lam,hlam,hP⟩ + refine ⟨hX,hX0,hLX,fun Z hZ => ?_⟩ + have h := (metric_dual_representation hA).mpr + ⟨_,lam,hP,hlam,by abel⟩ Z hZ.1 + simpa only [sub_mul,smul_mul_assoc,trace_sub,trace_smul,smul_eq_mul,sub_nonneg] using h + +lemma laplacian_trace {m : ℕ} (G : MultiGraph n m) : (G.laplacian univ).trace=2*m := by + simp only [laplacian,trace_sum,trace_vecMulVec] + have he (e : Fin m) : G.incidence e ⬝ᵥ G.incidence e=2 := difference_norm_sq (G.loopless e) + simp only [he,sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul] + ring + +lemma domain_trace_size {m : ℕ} (G : MultiGraph n m) (hn : 0 < n) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : X ∈ metricDomain G) : X.trace ≤ 6*m := by + have h := domain_trace_bound G hn hX + rw [laplacian_trace G] at h + linarith only [h] + +lemma domain_multiplier_bound {m : ℕ} (G : MultiGraph n m) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : X.PosSemidef) + (lam : DistinctTriple n → ℝ) + (hP : ((3:ℝ) • G.laplacian univ-X-∑ijk, lam ijk • triangleGenerator ijk).PosSemidef) : + (∑ijk, lam ijk) ≤ 3*m := by + have h := hP.trace_nonneg + simp only [trace_sub,trace_smul,smul_eq_mul,trace_sum,triangleGenerator_trace,←sum_mul, + laplacian_trace G] at h + linarith only [h,hX.trace_nonneg] + +end TraceDual + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/ConicDuality.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/ConicDuality.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c8595bcda03c8ddfa396d25b0943b52077e7319 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/ConicDuality.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.MatrixBound + +namespace OAI + +/-! Metric conic duality. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree +open scoped Classical MatrixOrder Topology +open Filter + +section GeneralFinite +variable {V E T J : Type*} [Fintype V] [DecidableEq V] [Fintype T] [Fintype J] + +omit [DecidableEq V] in +lemma trace_pairing_continuous (Z : Matrix V V ℝ) : + Continuous (fun D : Matrix V V ℝ => (D*Z).trace) := by + simp only [Matrix.trace,Matrix.diag,Matrix.mul_apply] + fun_prop + +lemma trace_pairing_convex (Z : Matrix V V ℝ) (d : ℝ) : + ConvexOn ℝ {D : Matrix V V ℝ | D.PosDef} (fun D => (D*Z).trace-d) := by + refine ⟨MatrixDual.posDef_convex,?_⟩ + intro X _ Y _ a b _ _ hab + simp only [add_mul,smul_mul_assoc,trace_add,trace_smul,smul_eq_mul] + nlinarith only [congrArg (fun v : ℝ => v*d) hab] + +lemma trace_test_slater (Z : J → Matrix V V ℝ) {d : J → ℝ} (hd : ∀j, 0 < d j) : + ∃D : Matrix V V ℝ, D.PosDef ∧ ∀j, (D*Z j).trace-d j < 0 := by + have hlim (j : J) : Tendsto (fun t : ℝ => t*(Z j).trace) (𝓝[>] 0) (𝓝 0) := by + have hc : Continuous (fun t : ℝ => t*(Z j).trace) := by fun_prop + simpa using (hc.tendsto 0).mono_left nhdsWithin_le_nhds + have he : ∀ᶠ t : ℝ in 𝓝[>] 0, ∀j, t*(Z j).trace < d j := + eventually_all.mpr (fun j => (hlim j).eventually_lt_const (hd j)) + have hp : ∀ᶠ t : ℝ in 𝓝[>] 0, 0 < t := eventually_mem_nhdsWithin + obtain ⟨t,ht,htp⟩ := (he.and hp).exists + refine ⟨t • (1 : Matrix V V ℝ),Matrix.PosDef.one.smul htp,?_⟩ + intro j + simpa only [smul_mul_assoc,one_mul,trace_smul,smul_eq_mul,sub_lt_zero] using ht j + +lemma trace_weighted_tests (Z : J → Matrix V V ℝ) (y d : J → ℝ) (D : Matrix V V ℝ) : + ((∑j, y j • Z j)*D).trace-∑j, y j*d j = ∑j, y j*((D*Z j).trace-d j) := by + simp only [sum_mul,smul_mul_assoc,trace_sum,trace_smul,smul_eq_mul,mul_sub,sum_sub_distrib] + congr 1 + apply sum_congr rfl + intro j _ + rw [trace_mul_comm] + +lemma finite_shortcut_of_trace_bound (b : E → V → ℝ) (O : T → Finset E) + (Z : J → Matrix V V ℝ) (hZ : ∀j, (Z j).PosSemidef) (d : J → ℝ) + (hd : ∀j, 0 < d j) {K : ℝ} (hK : 0 ≤ K) + (hbound : ∀lam : T → ℝ, ∀y : J → ℝ, (∀t, 0 ≤ lam t) → (∑t, lam t)=1 → + (∀j, 0 ≤ y j) → + (CFC.sqrt (CFC.sqrt (∑j, y j • Z j) * ShortcutDual.objectiveMatrix b O lam * + CFC.sqrt (∑j, y j • Z j))).trace^2 ≤ K * ∑j, y j*d j) + {eta : ℝ} (heta : 0 < eta) : + ∃D : Matrix V V ℝ, D.PosDef ∧ + (∀t, ShortcutDual.boundaryAverage b O t D < K+eta) ∧ + (∀j, (D*Z j).trace < d j) := by + have hs := Duality.strict_feasible_of_dual_bound {D : Matrix V V ℝ | D.PosDef} + MatrixDual.posDef_convex (ShortcutDual.boundaryAverage b O) (fun j D => (D*Z j).trace-d j) + (ShortcutDual.boundaryAverage_convex b O) (fun j => trace_pairing_convex (Z j) (d j)) + (trace_test_slater Z hd) (K+eta) + obtain ⟨D,hD,hf,hg⟩ := hs (by + intro lam y hlam hlams hy + let A := ShortcutDual.objectiveMatrix b O lam + let W := ∑j, y j • Z j + let N := (CFC.sqrt (CFC.sqrt W*A*CFC.sqrt W)).trace + let v := ∑j, y j*d j + have hv : 0 ≤ v := sum_nonneg (fun j _ => mul_nonneg (hy j) (hd j).le) + have hN : 0 ≤ N := (CFC.sqrt_nonneg _).posSemidef.trace_nonneg + have hb : N^2 ≤ K*v := hbound lam y hlam hlams hy + have hNv : 2*N ≤ K+v := by nlinarith only [hb,hK,hv,hN,sq_nonneg (K-v)] + have hW : W.PosSemidef := Matrix.posSemidef_sum _ (fun j _ => (hZ j).smul (hy j)) + obtain ⟨D,hD,hval⟩ := MatrixDual.trace_objective_approx + (ShortcutDual.objectiveMatrix_posSemidef b O hlam) hW + (show 2*N < K+eta+v by linarith only [hNv,heta]) + refine ⟨D,hD,?_⟩ + have htr := trace_weighted_tests Z y d D + rw [ShortcutDual.trace_objectiveMatrix] at hval + change (∑t,lam t*ShortcutDual.boundaryAverage b O t D) + (W*D).trace < K+eta+v at hval + linarith only [hval,htr]) + exact ⟨D,hD,hf,fun j => sub_neg.mp (hg j)⟩ + +end GeneralFinite + +section Pairing +variable {n : ℕ} + +lemma trace_gram_pairing (B X : Matrix (Fin n) (Fin n) ℝ) : + (B*(Xᵀ*X)).trace=∑i, qform B (X i) := by + rw [←mul_assoc,trace_mul_cycle] + apply sum_congr rfl + intro i _ + simp only [diag_apply,mul_apply,transpose_apply,qform,mulVec,dotProduct] + simp only [sum_mul,mul_sum] + rw [sum_comm] + apply sum_congr rfl + intro j _ + apply sum_congr rfl + intro k _ + ring + +lemma trace_pairing_nonneg {B Z : Matrix (Fin n) (Fin n) ℝ} + (hB : B.PosSemidef) (hZ : Z.PosSemidef) : 0 ≤ (B*Z).trace := by + conv_rhs => rw [←sqrt_gram hZ] + rw [trace_gram_pairing] + exact sum_nonneg (fun i _ => qform_nonneg hB _) + +lemma trace_pairing_pos {B Z : Matrix (Fin n) (Fin n) ℝ} + (hB : B.PosDef) (hZ : Z.PosSemidef) (hZ0 : Z ≠ 0) : 0 < (B*Z).trace := by + have hX : CFC.sqrt Z ≠ 0 := by + intro he + have hh := sqrt_gram hZ + rw [he,transpose_zero,zero_mul] at hh + exact hZ0 hh.symm + have hi : ∃i, CFC.sqrt Z i ≠ 0 := by + by_contra hh + push Not at hh + exact hX (funext hh) + obtain ⟨i,hi⟩ := hi + rw [←sqrt_gram hZ,trace_gram_pairing] + apply sum_pos' + · intro j _ + exact qform_nonneg hB.posSemidef _ + · exact ⟨i,mem_univ i,by simpa only [qform,star_trivial] using hB.dotProduct_mulVec_pos hi⟩ + +lemma trace_pairing_mono {B D Z : Matrix (Fin n) (Fin n) ℝ} + (hBD : B ≤ D) (hZ : Z.PosSemidef) : (B*Z).trace ≤ (D*Z).trace := by + have hh := trace_pairing_nonneg (Matrix.le_iff.mp hBD) hZ + simpa only [sub_mul,trace_sub,sub_nonneg] using hh + +lemma test_one : Test (1 : Matrix (Fin n) (Fin n) ℝ) := by + refine ⟨Matrix.PosSemidef.one,?_⟩ + intro u v w + have heq (a b : Fin n) : qform (1 : Matrix (Fin n) (Fin n) ℝ) (difference a b)= + if a=b then 0 else 2 := by + by_cases hab : a=b + · simp [hab,difference,qform] + · norm_num [qform,difference,MultiGraph.point,sub_dotProduct,dotProduct_sub,hab,Ne.symm hab] + simp only [heq] + split_ifs <;> try norm_num + all_goals simp_all + +end Pairing +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/Hierarchy.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/Hierarchy.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed29617b478c2834c92e5fc53d4da9475310f806 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/Hierarchy.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.CenteredMatrices +import OAI.Combinatorics.ThinTrees.Metric.CompactDuality + +namespace OAI + +/-! Metric hierarchy. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder + +variable {n m : ℕ} + +def resistance (G : MultiGraph n m) (D : Matrix (Fin n) (Fin n) ℝ) (e : Fin m) : ℝ := + qform (inverseOnZeroSum D) (G.incidence e) + +def boundaryResistance (G : MultiGraph n m) (H : Hierarchy n) + (D : Matrix (Fin n) (Fin n) ℝ) (A : Finset (Fin n)) : ℝ := + ((H.parentBoundary G A).card : ℝ)⁻¹ * ∑e ∈ H.parentBoundary G A, resistance G D e + +lemma incidence_sum (G : MultiGraph n m) (e : Fin m) : ∑i, G.incidence e i=0 := + (mem_zeroSumSpace _).mp (G.incidence_zeroSum e) + +lemma connected_of_edgeConnected {G : MultiGraph n m} {q : ℕ} + (hq : 0 < q) (hc : G.EdgeConnected q) : G.Connected univ := by + intro S hS hS' + exact card_pos.mp (hq.trans_le (hc S hS hS')) + +theorem metric_hierarchy_bound : + ∃h0 : ℕ, 2 ≤ h0 ∧ ∀h : ℕ, h0 ≤ h → + ∀(n m : ℕ) (G : MultiGraph n m) (H : Hierarchy n), 2 ≤ n → + H.LocallyConnectedReal G h → + ∀M : Finset (Finset (Fin n)), M ⊆ H.nodes → + (∀A ∈ M, A ≠ univ) → + (∀A ∈ M, ((G.cut univ A).card : ℝ)/h ≤ (H.parentBoundary G A).card) → + ∃D : Matrix (Fin n) (Fin n) ℝ, CenteredPositive D ∧ + (∀Z : Matrix (Fin n) (Fin n) ℝ, CenteredTest Z → (D*Z).trace ≤ (G.laplacian univ*Z).trace) ∧ + (∀A ∈ M, boundaryResistance G H D A ≤ (h:ℝ)^(-31/40:ℝ)) := by + obtain ⟨h0,hh0,hbound⟩ := polynomial_nuclear_bound + refine ⟨h0,hh0,?_⟩ + intro h hh n m G H hn hconn M hM hroot hratio + have hn' : 0 < n := by omega + have hh' : 0 < h := by omega + have hhp : (0:ℝ) < h := Nat.cast_pos.mpr hh' + let B := regularize (G.laplacian univ) + have hB : B.PosDef := laplacian_regularize_pd G hn' + (connected_of_edgeConnected hh' (Hierarchy.edgeConnected_of_locally hconn)) + let K : ℝ := (h:ℝ)^(-31/40:ℝ)/2 + have hK : 0 < K := div_pos (Real.rpow_pos_of_pos hhp _) (by norm_num) + have hb : ∀Z : Matrix (Fin n) (Fin n) ℝ, Test Z → + ∀lam : M → ℝ, (∀A, 0 ≤ lam A) → (∑A, lam A)=1 → + (CFC.sqrt (CFC.sqrt Z*ShortcutDual.objectiveMatrix G.incidence + (fun A : M => H.parentBoundary G A) lam*CFC.sqrt Z)).trace^2 ≤ K*(B*Z).trace := by + intro Z hZ lam hlam hsum + have hle : (G.laplacian univ*Z).trace ≤ (B*Z).trace := by + dsimp [B,regularize] + rw [add_mul,trace_add] + exact le_add_of_nonneg_right (trace_pairing_nonneg constantProjection_psd hZ.1) + exact (hbound h hh n m G H hconn M hM hroot hratio Z hZ lam hlam hsum).trans + (mul_le_mul_of_nonneg_left hle hK.le) + obtain ⟨D,hD,havg,htr⟩ := metric_shortcut_of_trace_bound hn' G.incidence + (fun A : M => H.parentBoundary G A) B hB hK hb + refine ⟨centered D,centered_positive hn' hD,?_,?_⟩ + · intro Z hZ + rw [centered_trace D hZ] + have hh := htr Z hZ.1 + rwa [regularize_trace (G.laplacian univ) hZ] at hh + · intro A hA + have hc : boundaryResistance G H (centered D) A ≤ + ShortcutDual.boundaryAverage G.incidence (fun A : M => H.parentBoundary G A) ⟨A,hA⟩ D := by + unfold boundaryResistance ShortcutDual.boundaryAverage + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr (Nat.cast_nonneg _)) + exact sum_le_sum (fun e _ => inverse_centered_le hn' hD (incidence_sum G e)) + have ht : 2*K=(h:ℝ)^(-31/40:ℝ) := by dsimp [K]; ring + exact ht ▸ hc.trans (havg ⟨A,hA⟩) + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/MatrixBound.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/MatrixBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..b90de542cffb369c5638124791bde67d0d6183d8 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/MatrixBound.lean @@ -0,0 +1,152 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.Numerator + +namespace OAI + +/-! Metric matrix bound. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder + +variable {n m d : ℕ} + +def difference (u v : Fin n) : Fin n → ℝ := point u-point v + +def Test (Z : Matrix (Fin n) (Fin n) ℝ) : Prop := + Z.PosSemidef ∧ ∀u v w, qform Z (difference u w) ≤ + qform Z (difference u v)+qform Z (difference v w) + +def CenteredTest (Z : Matrix (Fin n) (Fin n) ℝ) : Prop := + Test Z ∧ Z *ᵥ (fun _ => 1)=0 + +lemma test_zero : Test (0 : Matrix (Fin n) (Fin n) ℝ) := by + refine ⟨Matrix.PosSemidef.zero,?_⟩ + intro u v w + simp [qform] + +lemma test_add {X Y : Matrix (Fin n) (Fin n) ℝ} (hX : Test X) (hY : Test Y) : + Test (X+Y) := by + refine ⟨hX.1.add hY.1,?_⟩ + intro u v w + simp only [qform_add] + linarith only [hX.2 u v w,hY.2 u v w] + +lemma test_smul {X : Matrix (Fin n) (Fin n) ℝ} (hX : Test X) {a : ℝ} (ha : 0 ≤ a) : + Test (a • X) := by + refine ⟨hX.1.smul ha,?_⟩ + intro u v w + simpa only [qform_smul,mul_add] using mul_le_mul_of_nonneg_left (hX.2 u v w) ha + +lemma test_sum {I : Type*} (S : Finset I) (X : I → Matrix (Fin n) (Fin n) ℝ) + (hX : ∀i ∈ S, Test (X i)) : Test (∑i ∈ S, X i) := by + induction S using Finset.induction_on with + | empty => simpa using test_zero (n := n) + | @insert i S hi ih => + rw [sum_insert hi] + exact test_add (hX i (mem_insert_self _ _)) (ih (fun j hj => hX j (mem_insert_of_mem hj))) + +lemma test_convex : Convex ℝ {Z : Matrix (Fin n) (Fin n) ℝ | Test Z} := by + intro X hX Y hY a b ha hb _ + exact test_add (test_smul hX ha) (test_smul hY hb) + +lemma test_closed : IsClosed {Z : Matrix (Fin n) (Fin n) ℝ | Test Z} := by + simp only [Test,Set.ofPred_and,Set.ofPred_forall] + exact isClosed_psd.inter (isClosed_iInter fun u => isClosed_iInter fun v => + isClosed_iInter fun w => isClosed_le (qform_continuous _) ((qform_continuous _).add (qform_continuous _))) + +def columnPoints (X : Matrix (Fin d) (Fin n) ℝ) : Fin n → EuclideanSpace ℝ (Fin d) := + fun v => WithLp.toLp 2 (fun i => X i v) + +lemma eval_difference (x : Fin n → ℝ) (u v : Fin n) : + x ⬝ᵥ difference u v=x u-x v := by + simp [difference,point,dotProduct_sub] + +lemma gram_distance (X : Matrix (Fin d) (Fin n) ℝ) (u v : Fin n) : + ‖columnPoints X u-columnPoints X v‖^2=qform (Xᵀ*X) (difference u v) := by + have hnorm (x : Fin d → ℝ) : ‖(WithLp.toLp 2 x : EuclideanSpace ℝ (Fin d))‖^2=x ⬝ᵥ x := by + simp [EuclideanSpace.norm_sq_eq,dotProduct,←pow_two] + have hv : X *ᵥ difference u v=(fun i => X i u-X i v) := by + ext i + exact eval_difference (fun j => X i j) u v + have hq : qform (Xᵀ*X) (difference u v)=(X *ᵥ difference u v) ⬝ᵥ (X *ᵥ difference u v) := by + rw [qform,←mulVec_mulVec,dotProduct_mulVec,vecMul_transpose] + rw [hq,hv,←hnorm] + rfl + +lemma sqrt_gram {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : Z.PosSemidef) : + (CFC.sqrt Z)ᵀ*CFC.sqrt Z=Z := by + rw [isHermitian_iff_isSymm.mp (CFC.sqrt_nonneg Z).posSemidef.isHermitian] + exact CFC.sqrt_mul_sqrt_self Z hZ.nonneg + +lemma sqrt_columns_metric {Z : Matrix (Fin n) (Fin n) ℝ} (hZ : Test Z) : + MetricProfiles.SquaredTriangle (columnPoints (CFC.sqrt Z)) := by + intro u v w + simpa only [gram_distance,sqrt_gram hZ.1] using hZ.2 u v w + +lemma contraction (X : Matrix (Fin d) (Fin n) ℝ) (U : Matrix (Fin m) (Fin d) ℝ) + (hU : Uᵀ*U ≤ 1) : + let Y : Fin n → EuclideanSpace ℝ (Fin m) := fun v => WithLp.toLp 2 (U *ᵥ (fun i => X i v)) + ∀u v, ‖Y u-Y v‖^2 ≤ ‖columnPoints X u-columnPoints X v‖^2 := by + intro Y u v + have hh := StrongThinTree.Polar.norm_sq_mulVec_le hU (fun i => X i u-X i v) + have heq : Y u-Y v=WithLp.toLp 2 (U *ᵥ (fun i => X i u-X i v)) := by + dsimp [Y] + rw [show (fun i => X i u-X i v)=(fun i => X i u)-(fun i => X i v) from rfl,mulVec_sub] + rfl + rw [heq] + simpa [EuclideanSpace.norm_sq_eq,dotProduct,columnPoints,←pow_two] using hh + +lemma laplacian_pairing (G : MultiGraph n m) (Z : Matrix (Fin n) (Fin n) ℝ) : + (G.laplacian univ*Z).trace=∑e, qform Z (G.incidence e) := by + simp only [laplacian,sum_mul,trace_sum,ShortcutDual.trace_outer_mul,qform] + +lemma column_edge_energy (G : MultiGraph n m) (X : Matrix (Fin d) (Fin n) ℝ) : + (∑e, ‖columnPoints X (G.left e)-columnPoints X (G.right e)‖^2)= + (G.laplacian univ*(Xᵀ*X)).trace := by + rw [laplacian_pairing] + apply sum_congr rfl + intro e _ + exact gram_distance X (G.left e) (G.right e) + +theorem polynomial_nuclear_bound : + ∃ qH : ℕ, 2 ≤ qH ∧ ∀ q : ℕ, qH ≤ q → + ∀ (n m : ℕ) (G : MultiGraph n m) (H : Hierarchy n), + H.LocallyConnectedReal G q → + ∀ M : Finset (Finset (Fin n)), M ⊆ H.nodes → + (∀t ∈ M, t ≠ univ) → + (∀t ∈ M, ((G.cut univ t).card : ℝ)/q ≤ (H.parentBoundary G t).card) → + ∀ (Z : Matrix (Fin n) (Fin n) ℝ), Test Z → + ∀ (lam : M → ℝ), (∀t, 0 ≤ lam t) → (∑t, lam t)=1 → + (CFC.sqrt (CFC.sqrt Z*ShortcutDual.objectiveMatrix G.incidence + (fun t : M => H.parentBoundary G t) lam*CFC.sqrt Z)).trace^2 ≤ + ((q:ℝ)^(-31/40:ℝ)/2)*(G.laplacian univ*Z).trace := by + obtain ⟨qH,hqH,hbound⟩ := MetricProfiles.polynomial_metric_numerator + refine ⟨qH,hqH,?_⟩ + intro q hq n m G H hconn M hM hroot hratio Z hZ lam hlam hsum + let X := CFC.sqrt Z + have hn := ShortcutDual.nuclear_bound_of_embedding_bound G.incidence + (fun t : M => H.parentBoundary G t) X (K := ((q:ℝ)^(-31/40:ℝ)/2)*(G.laplacian univ*Z).trace) ?_ hlam hsum + · simpa only [X,sqrt_gram hZ.1] using hn + intro U hU hpos + let Y : Fin n → EuclideanSpace ℝ (Fin m) := fun v => WithLp.toLp 2 (U *ᵥ (fun i => X i v)) + have he := hbound q hq n m G H hconn M hM hroot hratio n (columnPoints X) + (sqrt_columns_metric hZ) Y (contraction X U hU) + (fun e => by simpa only [Y,G.contraction_edge_diag] using hpos e) + rw [sum_coe_sort M (fun t => (∑e ∈ H.parentBoundary G t, + (U*(X*Matrix.of (fun v e => G.incidence e v))) e e)^2 / + ((H.parentBoundary G t).card : ℝ))] + dsimp only [Y] at he + simp only [G.contraction_edge_diag] at he + change (∑t ∈ M, _) ≤ _ at he + rw [column_edge_energy,show Xᵀ*X=Z from sqrt_gram hZ.1] at he + exact he + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/Numerator.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/Numerator.lean new file mode 100644 index 0000000000000000000000000000000000000000..993744021b1b170cd2d7caf27ddce44a15823669 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/Numerator.lean @@ -0,0 +1,284 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.ScaleCharging +import OAI.Combinatorics.ThinTrees.Metric.SpectralMetricBridge + +namespace OAI + +/-! Metric numerator. -/ + +section + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (truncationBins truncationGain truncationGain_pos) +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open scoped Classical +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] + {H : Hierarchy n} {G : MultiGraph n m} {X : Fin n → Doubled Coord → ℝ} + +omit [PseudoMetricSpace Coord] in +lemma diagonal_sq_le (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ normDistance (X u) (X v)) (e : Fin m) : + ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ normDistance (X (G.left e)) (X (G.right e)) := by + have hh := pow_le_pow_left₀ (norm_nonneg _) (PiLp.norm_apply_le (Y (G.left e)-Y (G.right e)) e) 2 + have he : ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ ‖Y (G.left e)-Y (G.right e)‖^2 := by + simpa only [Real.norm_eq_abs,sq_abs] using hh + exact he.trans (hcontract _ _) + +lemma positive_bad_bound {q L R : ℕ} (hq : 0 < q) (hL : 0 < L) (hR : 0 < R) + (hk : G.EdgeConnected q) (hX : ∀v, isProfile (X v)) + (hconn : LocallyConnectedReal H G q) + (T : Finset (Finset (Fin n))) (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + {α ε ρ : ℝ} (hα : 0 < α) (hα1 : α ≤ 1) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ normDistance (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hpos : ∀t ∈ T, 0 < ∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e) + (hbad : ∀t ∈ T, α*((parentBoundary H G t).card : ℝ)* + (∑e ∈ parentBoundary H G t, normDistance (X (G.left e)) (X (G.right e))) ≤ + (∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hsmall : (α*truncationGain α/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*truncationGain α/32)^(1+2*ε)) + (hratio : ∀t ∈ T, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (parentBoundary H G t).card) + (hlogL : Real.logb 2 (16/(α*truncationGain α))+1 < L) + (hlogR : Real.logb 2 (24/(ρ*(α*truncationGain α/32)^2)) < R) : + let γ := truncationGain α + let s := α*γ/32 + let N := ∑t ∈ T, (∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((parentBoundary H G t).card : ℝ) + ((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2)))*(γ*N/(L:ℝ)) ≤ + 2*R*(∑e : Fin m, normDistance (X (G.left e)) (X (G.right e))) := by + let γ := truncationGain α + let s := α*γ/32 + let a : Fin m → ℝ := fun e => (Y (G.left e)-Y (G.right e)).ofLp e + let d : Fin m → ℝ := fun e => normDistance (X (G.left e)) (X (G.right e)) + let O := parentBoundary H G + have hγ : 0 < γ := truncationGain_pos α + have hs : 0 < s := by dsimp [s]; positivity + have hex : ∀t : Finset (Fin n), ∃B : Finset (Fin m), ∃i : ℤ, ∃o : Fin L, + t ∈ T → B.Nonempty ∧ B ⊆ O t ∧ γ*(∑e ∈ O t, a e)^2 ≤ (∑e ∈ B, a e)^2 ∧ + (∀e ∈ B, 2^(i:ℝ) ≤ (a e)^2) ∧ + (∀e ∈ B, (a e)^2 ≤ 4*2^(i:ℝ)) ∧ + (∀e ∈ B, 2^((i:ℝ)+o.val) ≤ d e) ∧ + (∀e ∈ B, d e ≤ 4*2^((i:ℝ)+o.val)) := by + intro t + by_cases ht : t ∈ T + · have hOn : (O t).Nonempty := by + by_contra hh + have heq : O t=∅ := not_nonempty_iff_eq_empty.mp hh + have hp := hpos t ht + change 0 < ∑e ∈ O t, a e at hp + simp only [heq,sum_empty,lt_self_iff_false] at hp + obtain ⟨B,i,o,hB⟩ := Truncation.scaled_subset (O t) a d hα hα1 hOn + (fun e _ => hpositive e) (fun e _ => diagonal_sq_le Y hcontract e) (hpos t ht) (hbad t ht) hlogL + exact ⟨B,i,o,fun _ => hB⟩ + · exact ⟨∅,0,⟨0,hL⟩,fun hh => (ht hh).elim⟩ + choose F idx off hf using hex + have hh := homogeneous_scale_bound hq hL hR hk hX hconn T F idx off Y hT hroot + (fun t ht => (hf t ht).2.1) (fun t ht => (hf t ht).1) hα hγ he he1 hρ hρsmall + hcontract hpositive (fun t ht => (hf t ht).2.2.2.1) + (fun t ht => (hf t ht).2.2.2.2.1) (fun t ht => (hf t ht).2.2.2.2.2.1) + (fun t ht => (hf t ht).2.2.2.2.2.2) hbad (fun t ht => (hf t ht).2.2.1) + hsmall hassign hratio hlogR + have hsum : γ*(∑t ∈ T, (∑e ∈ O t, a e)^2/((O t).card:ℝ)) ≤ + ∑t ∈ T, (∑e ∈ F t, a e)^2/((O t).card:ℝ) := by + rw [mul_sum] + apply sum_le_sum + intro t ht + rw [←mul_div_assoc] + exact div_le_div_of_nonneg_right (hf t ht).2.2.1 (Nat.cast_nonneg _) + have hgain := div_le_div_of_nonneg_right hsum (Nat.cast_nonneg L : (0:ℝ)≤L) + have hc : 0 ≤ ((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2))) := by positivity + exact (mul_le_mul_of_nonneg_left hgain hc).trans hh +lemma weighted_boundary_sum (M : Finset (Finset (Fin n))) + (hM : M ⊆ H.nodes) (hroot : ∀t ∈ M, t ≠ univ) + (d : Fin m → ℝ) (hd : ∀e, 0 ≤ d e) : + (∑t ∈ M, ∑e ∈ parentBoundary H G t, d e) ≤ 2*∑e, d e := by + have heq : (∑t ∈ M, ∑e ∈ parentBoundary H G t, d e) = + ∑e, ((M.filter (fun t => e ∈ parentBoundary H G t)).card : ℝ)*d e := by + calc + _ = ∑t ∈ M, ∑e : Fin m, if e ∈ parentBoundary H G t then d e else 0 := by + apply sum_congr rfl + intro t ht + rw [←sum_filter] + simp + _ = ∑e : Fin m, ∑t ∈ M, if e ∈ parentBoundary H G t then d e else 0 := sum_comm + _ = _ := by + apply sum_congr rfl + intro e he + rw [←sum_filter, sum_const,nsmul_eq_mul] + rw [heq,mul_sum] + apply sum_le_sum + intro e _ + apply mul_le_mul_of_nonneg_right _ (hd e) + exact_mod_cast H.parentBoundary_multiplicity G M hM hroot e + +lemma hierarchy_numerator_bound {q L R : ℕ} (hq : 0 < q) (hL : 0 < L) (hR : 0 < R) + (hk : G.EdgeConnected q) (hX : ∀v, isProfile (X v)) + (hconn : LocallyConnectedReal H G q) + (M : Finset (Finset (Fin n))) (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hM : M ⊆ H.nodes) (hroot : ∀t ∈ M, t ≠ univ) + {α ε ρ : ℝ} (hα : 0 < α) (hα1 : α ≤ 1) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ normDistance (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hsmall : (α*truncationGain α/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*truncationGain α/32)^(1+2*ε)) + (hratio : ∀t ∈ M, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (parentBoundary H G t).card) + (hlogL : Real.logb 2 (16/(α*truncationGain α))+1 < L) + (hlogR : Real.logb 2 (24/(ρ*(α*truncationGain α/32)^2)) < R) : + let γ := truncationGain α + let s := α*γ/32 + (∑t ∈ M, (∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((parentBoundary H G t).card : ℝ)) ≤ + (2*α+2*(R:ℝ)*(L:ℝ)/(((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2)))*γ))* + (∑e : Fin m, normDistance (X (G.left e)) (X (G.right e))) := by + let O := parentBoundary H G + let a : Fin m → ℝ := fun e => (Y (G.left e)-Y (G.right e)).ofLp e + let d : Fin m → ℝ := fun e => normDistance (X (G.left e)) (X (G.right e)) + let N : Finset (Fin n) → ℝ := fun t => (∑e ∈ O t, a e)^2/((O t).card:ℝ) + let T := M.filter (fun t => 0 < ∑e ∈ O t, a e ∧ + α*((O t).card:ℝ)*(∑e ∈ O t, d e) ≤ (∑e ∈ O t, a e)^2) + have hTM : T ⊆ M := filter_subset _ _ + have hgood : ∀t ∈ M\T, N t ≤ α*∑e ∈ O t, d e := by + intro t ht + have htM := (mem_sdiff.mp ht).1 + have htT := (mem_sdiff.mp ht).2 + have hd : 0 ≤ α*∑e ∈ O t, d e := mul_nonneg hα.le (sum_nonneg (fun e _ => normDistance_nonneg _ _)) + by_cases hp : 0 < ∑e ∈ O t, a e + · have hn : ¬α*((O t).card:ℝ)*(∑e ∈ O t, d e) ≤ (∑e ∈ O t, a e)^2 := by + intro hh; exact htT (mem_filter.mpr ⟨htM,hp,hh⟩) + have hc : 0 < ((O t).card:ℝ) := by + by_contra h + have hz : (O t).card=0 := by exact_mod_cast le_antisymm (le_of_not_gt h) (Nat.cast_nonneg _) + have hz' : O t=∅ := card_eq_zero.mp hz + simp [hz'] at hp + apply (div_le_iff₀ hc).mpr + nlinarith only [lt_of_not_ge hn] + · have hz : ∑e ∈ O t, a e=0 := le_antisymm (le_of_not_gt hp) (sum_nonneg (fun e _ => hpositive e)) + simpa [N,hz] using hd + have hg : (∑t ∈ M\T, N t) ≤ 2*α*∑e, d e := by + calc + (∑t ∈ M\T, N t) ≤ ∑t ∈ M\T, α*∑e ∈ O t, d e := sum_le_sum hgood + _ = α*∑t ∈ M\T, ∑e ∈ O t, d e := (mul_sum _ _ _).symm + _ ≤ α*(2*∑e, d e) := mul_le_mul_of_nonneg_left + (weighted_boundary_sum (M\T) (fun _ ht => hM (mem_sdiff.mp ht).1) + (fun t ht => hroot t (mem_sdiff.mp ht).1) d (fun _ => normDistance_nonneg _ _)) hα.le + _ = 2*α*∑e, d e := by ring + have hb := positive_bad_bound hq hL hR hk hX hconn T Y (hTM.trans hM) + (fun t ht => hroot t (hTM ht)) hα hα1 he he1 hρ hρsmall hcontract hpositive + (fun t ht => (mem_filter.mp ht).2.1) (fun t ht => (mem_filter.mp ht).2.2) + hsmall hassign (fun t ht => hratio t (hTM ht)) hlogL hlogR + let γ := truncationGain α + let s := α*γ/32 + let c := ((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2)))*γ + have hγ : 0 < γ := truncationGain_pos α + have hs : 0 < s := by dsimp [s]; positivity + have hc : 0 < c := by dsimp [c]; positivity + have hL' : 0 < (L:ℝ) := Nat.cast_pos.mpr hL + have hb' : (∑t ∈ T, N t) ≤ (2*(R:ℝ)*(L:ℝ)/c)*(∑e, d e) := by + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ hc).mpr + have hh := (div_le_iff₀ hL').mp (show c*(∑t ∈ T, N t)/L ≤ 2*(R:ℝ)*∑e, d e by + convert hb using 1 ; dsimp [c,N,γ,s,O,a,d] ; ring) + nlinarith only [hh] + change (∑t ∈ M, N t) ≤ (2*α+2*(R:ℝ)*(L:ℝ)/c)*(∑e, d e) + rw [←sum_sdiff hTM] + nlinarith only [hg,hb'] +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open StrongThinTree.MultiGraph.Hierarchy (truncationGain shortcutCoefficient) +open AssignedGeometry CompactGeometry +open scoped Classical +variable {n m : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +omit [InnerProductSpace ℝ E] in +lemma squared_euclidean_numerator_bound {q L R : ℕ} (hq : 0 < q) + (hL : 0 < L) (hR : 0 < R) (hk : G.EdgeConnected q) + (hconn : LocallyConnectedReal H G q) + (M : Finset (Finset (Fin n))) (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hM : M ⊆ H.nodes) (hroot : ∀t ∈ M, t ≠ univ) + {α ε ρ : ℝ} (hα : 0 < α) (hα1 : α ≤ 1) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (p : Fin n → E) (ht : SquaredTriangle p) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ ‖p u-p v‖^2) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hsmall : (α*truncationGain α/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*truncationGain α/32)^(1+2*ε)) + (hratio : ∀t ∈ M, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (parentBoundary H G t).card) + (hlogL : Real.logb 2 (16/(α*truncationGain α))+1 < L) + (hlogR : Real.logb 2 (24/(ρ*(α*truncationGain α/32)^2)) < R) : + (∑t ∈ M, (∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((parentBoundary H G t).card : ℝ)) ≤ + shortcutCoefficient q L R α ε * (∑e : Fin m, ‖p (G.left e)-p (G.right e)‖^2) := by + let := squaredPseudoMetric p ht + have hd (u v : Fin n) : dist u v = ‖p u-p v‖^2 := rfl + have hc : ∀u v, ‖Y u-Y v‖^2 ≤ normDistance (profile (plus u)) (profile (plus v)) := by + intro u v + simpa only [normDistance,profile_norm_sub,dist_plus,hd] using hcontract u v + have hh := AssignedGeometry.hierarchy_numerator_bound hq hL hR hk + (fun v : Fin n => (show isProfile (profile (plus v)) from ⟨plus v,rfl⟩)) + hconn M Y hM hroot hα hα1 he he1 hρ hρsmall hc hpositive + hsmall hassign hratio hlogL hlogR + simpa only [normDistance,profile_norm_sub,dist_plus,hd,shortcutCoefficient] using hh + +theorem polynomial_metric_numerator : + ∃ qH : ℕ, 2 ≤ qH ∧ ∀ q : ℕ, qH ≤ q → + ∀ (n m : ℕ) (G : MultiGraph n m) (H : Hierarchy n), + LocallyConnectedReal H G q → + ∀ M : Finset (Finset (Fin n)), M ⊆ H.nodes → + (∀t ∈ M, t ≠ univ) → + (∀t ∈ M, ((G.cut univ t).card : ℝ)/q ≤ (parentBoundary H G t).card) → + ∀ (d : ℕ) (p : Fin n → EuclideanSpace ℝ (Fin d)), SquaredTriangle p → + ∀ (Y : Fin n → EuclideanSpace ℝ (Fin m)), + (∀u v, ‖Y u-Y v‖^2 ≤ ‖p u-p v‖^2) → + (∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) → + (∑t ∈ M, (∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((parentBoundary H G t).card : ℝ)) ≤ + ((q:ℝ)^(-31/40:ℝ)/2)*(∑e : Fin m, ‖p (G.left e)-p (G.right e)‖^2) := by + obtain ⟨qH,hqH,hgood⟩ := ShortcutNumeric.exists_cutoff + refine ⟨qH,hqH,?_⟩ + intro q hq n m G H hconn M hM hroot hratio d p ht Y hcontract hpositive + have hg := hgood q hq + have hqpos : 0 < q := lt_of_lt_of_le (by omega : 0 < qH) hq + have hqp : (0:ℝ) < q := Nat.cast_pos.mpr hqpos + have hq1 : (1:ℝ) ≤ q := le_trans (by norm_num) hg.large + have hα : 0 < ShortcutNumeric.alpha q := Real.rpow_pos_of_pos hqp _ + have hα1 : ShortcutNumeric.alpha q ≤ 1 := + Real.rpow_le_one_of_one_le_of_nonpos hq1 (by norm_num) + have hρ : 0 < ShortcutNumeric.rho q := by dsimp [ShortcutNumeric.rho]; positivity + have hr : ∀t ∈ M, (q:ℝ)*ShortcutNumeric.rho q*((G.cut univ t).card : ℝ) ≤ + (parentBoundary H G t).card := by + intro t ht + have heq : (q:ℝ)*ShortcutNumeric.rho q*((G.cut univ t).card : ℝ)= + ((G.cut univ t).card : ℝ)/q/2 := by + unfold ShortcutNumeric.rho + field_simp + rw [heq] + have hp : (0:ℝ) ≤ ((G.cut univ t).card : ℝ)/q := div_nonneg (Nat.cast_nonneg _) hqp.le + exact (by linarith : ((G.cut univ t).card : ℝ)/q/2 ≤ + ((G.cut univ t).card : ℝ)/q).trans (hratio t ht) + have hb := squared_euclidean_numerator_bound hqpos + (ShortcutNumeric.count_pos hqp) (ShortcutNumeric.count_pos hqp) + (Hierarchy.edgeConnected_of_locally hconn) hconn M Y hM hroot hα hα1 + (by norm_num : (0:ℝ)<1/10) (by norm_num : (1/10:ℝ)<1/3) + hρ hg.rho_small p ht hcontract hpositive + hg.small hg.assignment hr hg.log_left hg.log_right + have hcoef : shortcutCoefficient q (ShortcutNumeric.count q) (ShortcutNumeric.count q) + (ShortcutNumeric.alpha q) (1/10)=ShortcutNumeric.coefficient q := rfl + rw [hcoef] at hb + exact hb.trans (mul_le_mul_of_nonneg_right hg.coefficient_small + (sum_nonneg (fun e _ => sq_nonneg _))) + +end +end AlgorithmicThinTrees.MetricProfiles +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/Profiles.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/Profiles.lean new file mode 100644 index 0000000000000000000000000000000000000000..ae1b90d99b85c8e7589f7668323517d69e499193 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/Profiles.lean @@ -0,0 +1,422 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Potential.LightPoint +import OAI.Analysis.MatrixSigning.Realization.NaturalRealization +import OAI.Analysis.MatrixSigning.Realization.ScalarRealization +import OAI.Combinatorics.ThinTrees.ShortcutDuality + +namespace OAI + +/-! Metric profiles. -/ + +section + +noncomputable section + +namespace AlgorithmicThinTrees.MetricProfiles + +open Finset Set + +section Profiles + +variable {V : Type*} [Fintype V] [PseudoMetricSpace V] + +def profile (x : V) : V → ℝ := fun z => dist x z + +def polytope : Set (V → ℝ) := convexHull ℝ (Set.range (profile (V := V))) + +omit [Fintype V] in +lemma profile_mem (x : V) : profile x ∈ polytope := + subset_convexHull ℝ _ (Set.mem_range_self x) + +omit [Fintype V] in +lemma polytope_convex : Convex ℝ (polytope (V := V)) := convex_convexHull ℝ _ + +lemma polytope_compact : IsCompact (polytope (V := V)) := + (Set.finite_range (profile (V := V))).isCompact_convexHull ℝ + +lemma profile_norm_sub (x y : V) : ‖profile x - profile y‖ = dist x y := by + apply le_antisymm + · apply (pi_norm_le_iff_of_nonneg dist_nonneg).2 + intro z + simp only [Pi.sub_apply, profile, Real.norm_eq_abs] + apply abs_sub_le_iff.2 + constructor + · linarith [dist_triangle x y z] + · have h := dist_triangle y x z + rw [dist_comm y x] at h + linarith + · have h := norm_le_pi_norm (profile x - profile y) y + simpa [profile, Real.norm_eq_abs, abs_of_nonneg dist_nonneg] using h + +lemma profile_isometry : Isometry (profile (V := V)) := + Isometry.of_dist_eq fun x y => by rw [dist_eq_norm, profile_norm_sub] + +omit [PseudoMetricSpace V] in +lemma norm_coordinate_convex (c : V → ℝ) (i : V) : + Convex ℝ {x : V → ℝ | ‖x - c‖ ≤ x i} := by + intro x hx y hy a b ha hb hab + change ‖a • x + b • y - c‖ ≤ (a • x + b • y) i + have heq : a • x + b • y - c = a • (x - c) + b • (y - c) := by + ext j + simp only [Pi.sub_apply, Pi.add_apply, Pi.smul_apply, smul_eq_mul] + linear_combination c j * hab + rw [heq] + calc + ‖a • (x - c) + b • (y - c)‖ ≤ ‖a • (x - c)‖ + ‖b • (y - c)‖ := norm_add_le _ _ + _ = a * ‖x - c‖ + b * ‖y - c‖ := by + rw [norm_smul, norm_smul, Real.norm_eq_abs, Real.norm_eq_abs, + abs_of_nonneg ha, abs_of_nonneg hb] + _ ≤ a * x i + b * y i := add_le_add (mul_le_mul_of_nonneg_left hx ha) + (mul_le_mul_of_nonneg_left hy hb) + _ = (a • x + b • y) i := rfl + +theorem radius_eq_coordinate {q : V → ℝ} (hq : q ∈ polytope) (x : V) : + ‖q - profile x‖ = q x := by + have hupper : ‖q - profile x‖ ≤ q x := by + apply convexHull_min (t := {y : V → ℝ | ‖y - profile x‖ ≤ y x}) ?_ + (norm_coordinate_convex (profile x) x) hq + rintro _ ⟨y, rfl⟩ + exact (profile_norm_sub y x).le + have hlower : q x ≤ ‖q - profile x‖ := by + have h := norm_le_pi_norm (q - profile x) x + simp only [Pi.sub_apply, profile, dist_self, sub_zero, Real.norm_eq_abs] at h + exact (le_abs_self _).trans h + exact le_antisymm hupper hlower + +lemma coordinate_nonneg {q : V → ℝ} (hq : q ∈ polytope) (x : V) : 0 ≤ q x := by + rw [← radius_eq_coordinate hq x] + exact norm_nonneg _ + +end Profiles + +section Double + +variable (V : Type*) [Fintype V] [PseudoMetricSpace V] + +def commonRadius : ℝ := 1 + 2 * ∑ x : V, ∑ y : V, dist x y + +lemma commonRadius_pos : 0 < commonRadius V := by + have h : 0 ≤ ∑ x : V, ∑ y : V, dist x y := + sum_nonneg fun _ _ => sum_nonneg fun _ _ => dist_nonneg + unfold commonRadius + linarith + +lemma twice_dist_lt_commonRadius (x y : V) : 2 * dist x y < commonRadius V := by + have h₁ : dist x y ≤ ∑ z : V, dist x z := + single_le_sum (fun z _ => (dist_nonneg : (0 : ℝ) ≤ dist x z)) (mem_univ y) + have h₂ : (∑ z : V, dist x z) ≤ ∑ u : V, ∑ z : V, dist u z := + single_le_sum (fun u _ => sum_nonneg fun z _ => + (dist_nonneg : (0 : ℝ) ≤ dist u z)) (mem_univ x) + unfold commonRadius + linarith + +@[ext] +structure Doubled where + sign : Bool + point : V + deriving Fintype + +variable {V} + +def doubledDist (a b : Doubled V) : ℝ := + if a.sign = b.sign then dist a.point b.point + else commonRadius V - dist a.point b.point + +lemma doubledDist_self (a : Doubled V) : doubledDist a a = 0 := by + simp [doubledDist] + +lemma doubledDist_comm (a b : Doubled V) : doubledDist a b = doubledDist b a := by + simp only [doubledDist, eq_comm, dist_comm] + +lemma doubledDist_triangle (a b c : Doubled V) : + doubledDist a c ≤ doubledDist a b + doubledDist b c := by + have hab := twice_dist_lt_commonRadius V a.point b.point + have hbc := twice_dist_lt_commonRadius V b.point c.point + have hac := twice_dist_lt_commonRadius V a.point c.point + have hR := commonRadius_pos V + have h₁ := dist_triangle a.point b.point c.point + have h₂ := dist_triangle a.point c.point b.point + have h₃ := dist_triangle b.point a.point c.point + rw [dist_comm c.point b.point] at h₂ + rw [dist_comm b.point a.point] at h₃ + rcases a with ⟨a, x⟩ + rcases b with ⟨b, y⟩ + rcases c with ⟨c, z⟩ + cases a <;> cases b <;> cases c <;> + simp_all only [doubledDist, Bool.false_eq_true, Bool.true_eq_false, + ↓reduceIte] <;> linarith + +instance : PseudoMetricSpace (Doubled V) where + dist := doubledDist + dist_self := doubledDist_self + dist_comm := doubledDist_comm + dist_triangle := doubledDist_triangle + +def plus (x : V) : Doubled V := ⟨true, x⟩ +def minus (x : V) : Doubled V := ⟨false, x⟩ + +lemma dist_plus (x y : V) : dist (plus x) (plus y) = dist x y := by + change doubledDist _ _ = _ + simp [doubledDist, plus] + +lemma dist_minus (x y : V) : dist (minus x) (minus y) = dist x y := by + change doubledDist _ _ = _ + simp [doubledDist, minus] + +lemma opposite_dist (x : V) : dist (plus x) (minus x) = commonRadius V := by + change doubledDist _ _ = _ + simp [doubledDist, plus, minus] + +lemma profile_opposite_sum (x : V) (a : Doubled V) : + profile a (plus x) + profile a (minus x) = commonRadius V := by + change doubledDist a _ + doubledDist a _ = _ + rcases a with ⟨s, y⟩ + cases s <;> simp [doubledDist, plus, minus] + +lemma opposite_coordinate_sum {q : Doubled V → ℝ} + (hq : q ∈ polytope) (x : V) : q (plus x) + q (minus x) = commonRadius V := by + have hconv : Convex ℝ {q : Doubled V → ℝ | + q (plus x) + q (minus x) = commonRadius V} := by + intro q hq r hr a b _ _ hab + change (a • q + b • r) (plus x) + (a • q + b • r) (minus x) = _ + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul] + change q (plus x) + q (minus x) = commonRadius V at hq + change r (plus x) + r (minus x) = commonRadius V at hr + calc + _ = a * (q (plus x) + q (minus x)) + + b * (r (plus x) + r (minus x)) := by ring + _ = a * commonRadius V + b * commonRadius V := by rw [hq, hr] + _ = commonRadius V := by rw [← add_mul, hab, one_mul] + exact convexHull_min (by rintro _ ⟨a, rfl⟩; exact profile_opposite_sum x a) hconv hq + +theorem opposite_radii {q : Doubled V → ℝ} (hq : q ∈ polytope) (x : V) : + ‖q - profile (plus x)‖ + ‖q - profile (minus x)‖ = commonRadius V := by + rw [radius_eq_coordinate hq, radius_eq_coordinate hq] + exact opposite_coordinate_sum hq x + +theorem original_isometry : Isometry (fun x : V => profile (plus x)) := + Isometry.of_dist_eq fun x y => by rw [dist_eq_norm, profile_norm_sub, dist_plus] + +end Double + +section Segments + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +def mix (q r : E) (t : ℝ) : E := (1 - t) • q + t • r + +@[simp] lemma mix_zero (q r : E) : mix q r 0 = q := by simp [mix] +@[simp] lemma mix_one (q r : E) : mix q r 1 = r := by simp [mix] + +lemma mix_sub_mix (q r : E) (t s : ℝ) : + mix q r t - mix q r s = (t - s) • (r - q) := by + unfold mix + module + +lemma segment_distance (q r : E) (t s : ℝ) : + ‖mix q r t - mix q r s‖ = |t - s| * ‖r - q‖ := by + rw [mix_sub_mix, norm_smul, Real.norm_eq_abs] + +theorem segment_subdivision_length (q r : E) (N : ℕ) (t : ℕ → ℝ) + (ht : ∀ i < N, t i ≤ t (i + 1)) (hzero : t 0 = 0) (hone : t N = 1) : + ∑ i ∈ Finset.range N, ‖mix q r (t (i + 1)) - mix q r (t i)‖ = ‖r - q‖ := by + have hsum : (∑ i ∈ Finset.range N, (t (i + 1) - t i)) = 1 := by + rw [Finset.sum_range_sub, hone, hzero, sub_zero] + calc + _ = ∑ i ∈ Finset.range N, (t (i + 1) - t i) * ‖r - q‖ := by + apply Finset.sum_congr rfl + intro i hi + rw [segment_distance, abs_of_nonneg (sub_nonneg.mpr (ht i (mem_range.mp hi)))] + _ = (∑ i ∈ Finset.range N, (t (i + 1) - t i)) * ‖r - q‖ := + (Finset.sum_mul _ _ _).symm + _ = ‖r - q‖ := by rw [hsum, one_mul] + +end Segments + +section RadialMotion + +variable {V : Type*} [Fintype V] [PseudoMetricSpace V] + +lemma mix_mem {q r : V → ℝ} (hq : q ∈ polytope) (hr : r ∈ polytope) + {t : ℝ} (ht : t ∈ Set.Icc (0 : ℝ) 1) : mix q r t ∈ polytope := + polytope_convex hq hr (sub_nonneg.mpr ht.2) ht.1 (by ring) + +lemma radius_mix {q r : V → ℝ} (hq : q ∈ polytope) (hr : r ∈ polytope) + (x : V) {t : ℝ} (ht : t ∈ Set.Icc (0 : ℝ) 1) : + ‖mix q r t - profile x‖ = (1 - t) * ‖q - profile x‖ + t * ‖r - profile x‖ := by + rw [radius_eq_coordinate (mix_mem hq hr ht), radius_eq_coordinate hq, + radius_eq_coordinate hr] + rfl + +lemma inward_radius {q : Doubled V → ℝ} (hq : q ∈ polytope) + (x : V) {t : ℝ} (ht : t ∈ Set.Icc (0 : ℝ) 1) : + ‖mix q (profile (plus x)) t - profile (plus x)‖ = + (1 - t) * ‖q - profile (plus x)‖ := by + rw [radius_mix hq (profile_mem _) _ ht] + simp + +lemma inward_distance (q : Doubled V → ℝ) (x : V) {t : ℝ} (ht : 0 ≤ t) : + ‖mix q (profile (plus x)) t - q‖ = t * ‖q - profile (plus x)‖ := by + simpa only [mix_zero, sub_zero, abs_of_nonneg ht, norm_sub_rev (profile (plus x)) q] + using segment_distance q (profile (plus x)) t 0 + +lemma outward_radius {q : Doubled V → ℝ} (hq : q ∈ polytope) + (x : V) {t : ℝ} (ht : t ∈ Set.Icc (0 : ℝ) 1) : + ‖mix q (profile (minus x)) t - profile (plus x)‖ = + ‖q - profile (plus x)‖ + t * (commonRadius V - ‖q - profile (plus x)‖) := by + rw [radius_mix hq (profile_mem _) _ ht, profile_norm_sub, dist_comm, opposite_dist] + ring + +lemma outward_distance {q : Doubled V → ℝ} (hq : q ∈ polytope) + (x : V) {t : ℝ} (ht : 0 ≤ t) : + ‖mix q (profile (minus x)) t - q‖ = + t * (commonRadius V - ‖q - profile (plus x)‖) := by + have h : ‖q - profile (minus x)‖ = commonRadius V - ‖q - profile (plus x)‖ := by + linarith [opposite_radii hq x] + have hm := segment_distance q (profile (minus x)) t 0 + simpa only [mix_zero, sub_zero, abs_of_nonneg ht, norm_sub_rev (profile (minus x)) q, h] + using hm + +theorem radial_motion {q : Doubled V → ℝ} (hq : q ∈ polytope) + (x : V) {u : ℝ} (hu : u ∈ Set.Icc (0 : ℝ) (commonRadius V)) : + ∃ z ∈ polytope, ‖z - profile (plus x)‖ = u ∧ + ‖z - q‖ = |u - ‖q - profile (plus x)‖| := by + let ρ := ‖q - profile (plus x)‖ + have hρ : 0 ≤ ρ := norm_nonneg _ + by_cases h : u ≤ ρ + · by_cases hz : ρ = 0 + · have hu0 : u = 0 := le_antisymm (hz ▸ h) hu.1 + refine ⟨q, hq, ?_, ?_⟩ + · exact hz.trans hu0.symm + · simp only [sub_self, norm_zero] + change 0 = |u - ρ| + simp [hz, hu0] + · have hpos : 0 < ρ := lt_of_le_of_ne hρ (Ne.symm hz) + let t := (ρ - u) / ρ + have ht0 : 0 ≤ t := div_nonneg (sub_nonneg.mpr h) hρ + have ht1 : t ≤ 1 := (div_le_one hpos).2 (by linarith [hu.1]) + have htr : t * ρ = ρ - u := div_mul_cancel₀ _ hz + refine ⟨mix q (profile (plus x)) t, mix_mem hq (profile_mem _) ⟨ht0, ht1⟩, ?_, ?_⟩ + · rw [inward_radius hq x ⟨ht0, ht1⟩] + change (1 - t) * ρ = u + nlinarith + · rw [inward_distance q x ht0] + change t * ρ = |u - ρ| + rw [htr, abs_of_nonpos (sub_nonpos.mpr h)] + ring + · have hlt : ρ < u := lt_of_not_ge h + have hpos : 0 < commonRadius V - ρ := by linarith [hu.2] + let t := (u - ρ) / (commonRadius V - ρ) + have ht0 : 0 ≤ t := div_nonneg (sub_pos.mpr hlt).le hpos.le + have ht1 : t ≤ 1 := (div_le_one hpos).2 (by linarith [hu.2]) + have htr : t * (commonRadius V - ρ) = u - ρ := + div_mul_cancel₀ _ (ne_of_gt hpos) + refine ⟨mix q (profile (minus x)) t, mix_mem hq (profile_mem _) ⟨ht0, ht1⟩, ?_, ?_⟩ + · rw [outward_radius hq x ⟨ht0, ht1⟩] + change ρ + t * (commonRadius V - ρ) = u + rw [htr] + ring + · rw [outward_distance hq x ht0] + change t * (commonRadius V - ρ) = |u - ρ| + rw [htr, abs_of_nonneg (sub_nonneg.mpr hlt.le)] + +theorem ball_intersects_shell {q : Doubled V → ℝ} (hq : q ∈ polytope) (x : V) + {a b δ : ℝ} (ha : 0 ≤ a) (hab : a < b) (hb : b ≤ commonRadius V) + (hδ : 0 < δ) (hl : a - δ < ‖q - profile (plus x)‖) + (hu : ‖q - profile (plus x)‖ < b + δ) : + ∃ z ∈ polytope, ‖z - q‖ < δ ∧ + a < ‖z - profile (plus x)‖ ∧ ‖z - profile (plus x)‖ < b := by + let ρ := ‖q - profile (plus x)‖ + have hgap : max a (ρ - δ) < min b (ρ + δ) := by + apply max_lt + · exact lt_min hab (by dsimp [ρ]; linarith) + · exact lt_min (by dsimp [ρ]; linarith) (by linarith) + obtain ⟨u, hlu, huu⟩ := exists_between hgap + have hal : a < u := (le_max_left _ _).trans_lt hlu + have hbu : u < b := huu.trans_le (min_le_left _ _) + have hρl : ρ - δ < u := (le_max_right _ _).trans_lt hlu + have hρu : u < ρ + δ := huu.trans_le (min_le_right _ _) + obtain ⟨z, hz, hrad, hdist⟩ := radial_motion hq x ⟨ha.trans hal.le, hbu.le.trans hb⟩ + refine ⟨z, hz, ?_, ?_, ?_⟩ + · rw [hdist] + change |u - ρ| < δ + exact abs_lt.mpr ⟨by linarith, by linarith⟩ + · rwa [hrad] + · rwa [hrad] + +end RadialMotion + +section PiecewiseAffine + +def PiecewiseAffineOn (s : Set ℝ) (f : ℝ → ℝ) : Prop := + ∃ (N : ℕ) (pieces : Fin N → Set ℝ) (slopes intercepts : Fin N → ℝ), + (∀ i, Convex ℝ (pieces i)) ∧ (∀ t ∈ s, ∃ i, t ∈ pieces i) ∧ + ∀ i t, t ∈ s → t ∈ pieces i → f t = slopes i * t + intercepts i + +lemma PiecewiseAffineOn.mono {s t : Set ℝ} {f : ℝ → ℝ} + (h : PiecewiseAffineOn s f) (ht : t ⊆ s) : PiecewiseAffineOn t f := by + obtain ⟨N, pieces, slopes, intercepts, hc, hcover, heq⟩ := h + exact ⟨N, pieces, slopes, intercepts, hc, fun u hu => hcover u (ht hu), + fun i u hu hp => heq i u (ht hu) hp⟩ + +lemma PiecewiseAffineOn.congr {s : Set ℝ} {f g : ℝ → ℝ} + (h : PiecewiseAffineOn s f) (hfg : ∀ t ∈ s, f t = g t) : PiecewiseAffineOn s g := by + obtain ⟨N, pieces, slopes, intercepts, hc, hcover, heq⟩ := h + exact ⟨N, pieces, slopes, intercepts, hc, hcover, + fun i t ht hp => (hfg t ht).symm.trans (heq i t ht hp)⟩ + +lemma clamped_affine_piecewise {a b : ℝ} (hab : a ≤ b) (x y : ℝ) : + PiecewiseAffineOn Set.univ (fun t : ℝ => + min b (max a ((1 - t) * x + t * y))) := by + let f : ℝ →ᵃ[ℝ] ℝ := AffineMap.lineMap x y + refine ⟨3, ![f ⁻¹' Set.Iic a, f ⁻¹' Set.Icc a b, f ⁻¹' Set.Ici b], + ![0, y - x, 0], ![a, x, b], ?_, ?_, ?_⟩ + · intro i + fin_cases i + · exact Convex.affine_preimage f (convex_Iic a) + · exact Convex.affine_preimage f (convex_Icc a b) + · exact Convex.affine_preimage f (convex_Ici b) + · intro t _ + by_cases ha : f t ≤ a + · exact ⟨0, ha⟩ + · by_cases hb : f t ≤ b + · exact ⟨1, (lt_of_not_ge ha).le, hb⟩ + · exact ⟨2, (lt_of_not_ge hb).le⟩ + · intro i t _ hp + fin_cases i + · change f t ≤ a at hp + have hp' : (1 - t) * x + t * y ≤ a := by + simpa only [f, AffineMap.lineMap_apply_ring] using hp + change min b (max a ((1 - t) * x + t * y)) = 0 * t + a + rw [max_eq_left hp', min_eq_right hab, zero_mul, zero_add] + · change a ≤ f t ∧ f t ≤ b at hp + have hp' : a ≤ (1 - t) * x + t * y ∧ (1 - t) * x + t * y ≤ b := by + simpa only [f, AffineMap.lineMap_apply_ring] using hp + change min b (max a ((1 - t) * x + t * y)) = (y - x) * t + x + rw [max_eq_right hp'.1, min_eq_right hp'.2] + ring + · change b ≤ f t at hp + have hp' : b ≤ (1 - t) * x + t * y := by + simpa only [f, AffineMap.lineMap_apply_ring] using hp + change min b (max a ((1 - t) * x + t * y)) = 0 * t + b + rw [max_eq_right (hab.trans hp'), min_eq_left hp', zero_mul, zero_add] + +theorem clamped_radius_piecewise {V : Type*} [Fintype V] [PseudoMetricSpace V] + {q r : V → ℝ} (hq : q ∈ polytope) (hr : r ∈ polytope) (x : V) + {a b : ℝ} (hab : a ≤ b) : + PiecewiseAffineOn (Set.Icc (0 : ℝ) 1) + (fun t => min b (max a ‖mix q r t - profile x‖)) := by + have h := (clamped_affine_piecewise hab ‖q - profile x‖ ‖r - profile x‖).mono + (Set.subset_univ (Set.Icc (0 : ℝ) 1)) + apply h.congr + intro t ht + rw [radius_mix hq hr x ht] + +end PiecewiseAffine + +end AlgorithmicThinTrees.MetricProfiles + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/Response.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/Response.lean new file mode 100644 index 0000000000000000000000000000000000000000..63c27b61b94a47d0bd974d39bb2db3b659d33648 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/Response.lean @@ -0,0 +1,228 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.CenteredDomain +import OAI.Combinatorics.ThinTrees.Restriction + +namespace OAI + +/-! Metric response. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests +noncomputable section +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open scoped Classical MatrixOrder + +variable {n m m' : ℕ} + +lemma laplacian_mono (G : MultiGraph n m) {F B : Finset (Fin m)} (hFB : F ⊆ B) : + G.laplacian F ≤ G.laplacian B := by + unfold MultiGraph.laplacian + apply sum_le_sum_of_subset_of_nonneg hFB + intro e _ _ + exact Matrix.nonneg_iff_posSemidef.mpr (by + simpa only [star_trivial] using posSemidef_vecMulVec_self_star (G.incidence e)) + +lemma restrict_laplacian (H : MultiGraph n m') (F : Finset (Fin m')) : + (H.restrict F).laplacian univ=H.laplacian F := by + conv_rhs => rw [←lift_univ F] + simp only [MultiGraph.laplacian,liftEdges,sum_map] + rfl + +lemma restrict_laplacian_le (H : MultiGraph n m') (F : Finset (Fin m')) : + (H.restrict F).laplacian univ ≤ H.laplacian univ := by + rw [restrict_laplacian] + exact laplacian_mono H (subset_univ _) + +lemma metric_shortcut_response (G : MultiGraph n m) (H : MultiGraph n m') + (hn : 0 < n) (hGH : G.laplacian univ ≤ H.laplacian univ) + {J : Hierarchy n} {h : ℕ} (hh : 0 < h) {a t : ℝ} + (ha : 0 ≤ a) (ht : 0 < t) + {D : Matrix (Fin n) (Fin n) ℝ} (hD : CenteredPositive D) + (htr : ∀Z, CenteredTest Z → (D*Z).trace ≤ (G.laplacian univ*Z).trace) + (havg : ∀A ∈ J.nodes, A ≠ univ → + ((G.cut univ A).card:ℝ)/h ≤ (J.parentBoundary G A).card → + boundaryResistance G J D A ≤ a) : + ∃Y ∈ metricDomain H, CenteredPositive Y ∧ ∀A ∈ J.nodes, + (((univ.filter (fun e => t < resistance G Y e)) ∩ J.parentBoundary G A).card:ℝ) ≤ + (a/t+1/(h:ℝ))*(G.cut univ A).card := by + let Y := H.laplacian univ+D + have hY : CenteredPositive Y := by + rw [show Y=D+H.laplacian univ by dsimp [Y]; ac_rfl] + exact centeredPositive_add_psd hD (H.laplacian_psd univ) (laplacian_ones H) + have hRY (e : Fin m) : resistance G Y e ≤ resistance G D e := by + apply centered_inverse_antitone hn hD hY + exact le_add_of_nonneg_left (Matrix.nonneg_iff_posSemidef.mpr (H.laplacian_psd univ)) + have hcoeff : 0 ≤ a/t := div_nonneg ha ht.le + have hhR : (0:ℝ) < h := Nat.cast_pos.mpr hh + refine ⟨Y,shortcut_add_mem_domain G H hn hGH hD htr,hY,fun A hA => ?_⟩ + have hsub := G.parentBoundary_sub J A + have hcard : ((J.parentBoundary G A).card:ℝ) ≤ (G.cut univ A).card := by + exact_mod_cast card_le_card hsub + have hbadsub : (univ.filter (fun e => t < resistance G Y e)) ∩ J.parentBoundary G A ⊆ + (J.parentBoundary G A).filter (fun e => t < resistance G D e) := by + intro e he + obtain ⟨hb,heA⟩ := mem_inter.mp he + exact mem_filter.mpr ⟨heA,(mem_filter.mp hb).2.trans_le (hRY e)⟩ + by_cases hroot : A=univ + · subst A + have he : G.cut univ univ=∅ := by ext e; simp [cut] + have ho : J.parentBoundary G univ=∅ := subset_empty.mp (he ▸ hsub) + simp [ho,he] + by_cases hmark : ((G.cut univ A).card:ℝ)/h ≤ (J.parentBoundary G A).card + · have hm := finite_markov (J.parentBoundary G A) (resistance G D) + (fun e _ => centered_resistance_nonneg G hn hD e) ht (havg A hA hroot hmark) + calc + _ ≤ (((J.parentBoundary G A).filter (fun e => t < resistance G D e)).card:ℝ) := by + exact_mod_cast card_le_card hbadsub + _ ≤ a/t*(J.parentBoundary G A).card := hm + _ ≤ a/t*(G.cut univ A).card := mul_le_mul_of_nonneg_left hcard hcoeff + _ ≤ _ := by + have hnon : 0 ≤ 1/(h:ℝ)*(G.cut univ A).card := by positivity + nlinarith + · have hb : (((univ.filter (fun e => t < resistance G Y e)) ∩ J.parentBoundary G A).card:ℝ) ≤ + (J.parentBoundary G A).card := by exact_mod_cast card_le_card inter_subset_right + have hm := (lt_of_not_ge hmark).le + have hnon : 0 ≤ a/t*(G.cut univ A).card := mul_nonneg hcoeff (Nat.cast_nonneg _) + calc + _ ≤ ((J.parentBoundary G A).card:ℝ) := hb + _ ≤ ((G.cut univ A).card:ℝ)/h := hm + _ ≤ _ := by + nlinarith [show ((G.cut univ A).card:ℝ)/h=(1/(h:ℝ))*(G.cut univ A).card by ring] + +theorem simultaneous_metric_response_bound : + ∃ h0 : ℕ, 2 ≤ h0 ∧ ∀h : ℕ, h0 ≤ h → + ∀(n m m' : ℕ) (G : MultiGraph n m) (H : MultiGraph n m'), 2 ≤ n → + G.laplacian univ ≤ H.laplacian univ → + ∀(P : PartitionChain n) (z : ℕ), P.parts z={univ} → + (∀i ≤ z, ∀A ∈ P.parts i, G.EdgeConnectedReal A h) → + ∀t : ℝ, 0 < t → ∃Y ∈ metricDomain H, CenteredPositive Y ∧ + ∀i ≤ z, (((univ.filter (fun e => t < resistance G Y e)) ∩ P.crossing G i).card:ℝ) ≤ + 16*((h:ℝ)^(-31/40:ℝ)/t+1/(h:ℝ))*(P.crossing G i).card := by + obtain ⟨h0,hh0,hshortcut⟩ := metric_hierarchy_bound + refine ⟨h0,hh0,?_⟩ + intro h hh n m m' G H hn hGH P z hz hlocal t ht + let I := insert z (Dyadic.selected (fun j => (P.crossing G j).card) z) + obtain ⟨J,hJ⟩ := P.exists_hierarchy I ⟨z,mem_insert_self _ _,hz ▸ mem_singleton_self _⟩ + have hloc : J.LocallyConnectedReal G h := by + apply G.chain_locally P I J hJ + intro i hi A hA + have hiz : i ≤ z := by + rcases mem_insert.mp hi with rfl | hi + · exact le_rfl + · exact (Dyadic.selected_spec hi).1 + exact hlocal i hiz A hA + let M := J.nodes.filter (fun A => A ≠ univ ∧ + ((G.cut univ A).card:ℝ)/h ≤ (J.parentBoundary G A).card) + obtain ⟨D,hD,htr,havg⟩ := hshortcut h hh n m G J hn hloc M (filter_subset _ _) + (fun A hA => (mem_filter.mp hA).2.1) (fun A hA => (mem_filter.mp hA).2.2) + obtain ⟨Y,hYm,hY,hnode⟩ := metric_shortcut_response G H (by omega) hGH (by omega : 0 < h) + (Real.rpow_nonneg (Nat.cast_nonneg h) _) ht hD htr + (fun A hA hA' hr => havg A (mem_filter.mpr ⟨hA,hA',hr⟩)) + refine ⟨Y,hYm,hY,?_⟩ + intro i hiz + exact P.simultaneous_bad_bound G hz hJ (univ.filter (fun e => t < resistance G Y e)) + (by positivity : 0 ≤ (h:ℝ)^(-31/40:ℝ)/t+1/(h:ℝ)) hnode i hiz + +lemma quarter_negative_power {x y : ℝ} (hx : 0 < x) (hxy : x/4 ≤ y) : + y^(-31/40:ℝ) ≤ 4*x^(-31/40:ℝ) := by + have hh := Real.rpow_le_rpow_of_nonpos (by positivity : 0 < x/4) hxy + (by norm_num : (-31/40:ℝ) ≤ 0) + have hp : (4:ℝ)^(31/40:ℝ) ≤ 4 := + Real.rpow_le_self_of_one_le (by norm_num) (by norm_num) + have heq : (x/4)^(-31/40:ℝ)=x^(-31/40:ℝ)*(4:ℝ)^(31/40:ℝ) := by + rw [Real.div_rpow hx.le (by norm_num),div_eq_mul_inv, + ←Real.rpow_neg (by norm_num : (0:ℝ) ≤ 4)] + norm_num + rw [heq] at hh + exact hh.trans (by nlinarith [Real.rpow_nonneg hx.le (-31/40:ℝ)]) + +lemma response_fraction_cutoff : + ∃r0 : ℕ, 2 ≤ r0 ∧ ∀r : ℕ, r0 ≤ r → ∀s : ℝ, + 0 < s → s ≤ (r:ℝ)^(1/4:ℝ) → + 16*(((r/2:ℕ):ℝ)^(-31/40:ℝ)/(1/(6*s))+1/((r/2:ℕ):ℝ)) ≤ (r:ℝ)^(-1/3:ℝ) := by + open Filter in + have he : ∀ᶠ x : ℝ in atTop, + 128*x^(-1:ℝ) ≤ x^(-1/3:ℝ) ∧ 768*x^(-21/40:ℝ) ≤ x^(-1/3:ℝ) := by + exact (ShortcutNumeric.eventually_const_mul_rpow_le_rpow 128 (by norm_num)).and + (ShortcutNumeric.eventually_const_mul_rpow_le_rpow 768 (by norm_num)) + open Filter in + have heN : ∀ᶠ r : ℕ in atTop, + 128*(r:ℝ)^(-1:ℝ) ≤ (r:ℝ)^(-1/3:ℝ) ∧ + 768*(r:ℝ)^(-21/40:ℝ) ≤ (r:ℝ)^(-1/3:ℝ) := + (tendsto_natCast_atTop_atTop : Tendsto (fun r : ℕ => (r:ℝ)) atTop atTop).eventually he + obtain ⟨r0,hr0⟩ := heN.exists_forall_of_atTop + refine ⟨max 2 r0,le_max_left _ _,?_⟩ + intro r hr s hs hsR + have hr2 : 2 ≤ r := (le_max_left _ _).trans hr + have hlarge := hr0 r ((le_max_right _ _).trans hr) + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr (by omega) + have hrh : (r:ℝ)/4 ≤ ((r/2:ℕ):ℝ) := by + have hnn : r ≤ 4*(r/2) := by omega + have hrr : (r:ℝ) ≤ 4*((r/2:ℕ):ℝ) := by exact_mod_cast hnn + linarith + have hhR : (0:ℝ) < ((r/2:ℕ):ℝ) := lt_of_lt_of_le (by positivity) hrh + have hpow := quarter_negative_power hrR hrh + have hprod : (r:ℝ)^(1/4:ℝ)*(r:ℝ)^(-31/40:ℝ)=(r:ℝ)^(-21/40:ℝ) := by + rw [←Real.rpow_add hrR] + norm_num + have hp := mul_le_mul hsR hpow (Real.rpow_nonneg hhR.le _) (Real.rpow_nonneg hrR.le _) + have hp' : s*((r/2:ℕ):ℝ)^(-31/40:ℝ) ≤ 4*(r:ℝ)^(-21/40:ℝ) := by + nlinarith only [hp,hprod] + have hi : 1/((r/2:ℕ):ℝ) ≤ 4/(r:ℝ) := by + apply (div_le_div_iff₀ hhR hrR).mpr + linarith + have ht : ((r/2:ℕ):ℝ)^(-31/40:ℝ)/(1/(6*s))= + 6*(s*((r/2:ℕ):ℝ)^(-31/40:ℝ)) := by + simp only [one_div,div_inv_eq_mul] + ring + rw [ht] + have hl1 := hlarge.1 + rw [Real.rpow_neg_one] at hl1 + have hl2 := hlarge.2 + nlinarith [show 4/(r:ℝ)=4*(r:ℝ)⁻¹ by ring] + +theorem simultaneous_metric_response : + ∃r0 : ℕ, 2 ≤ r0 ∧ ∀r : ℕ, r0 ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.Connected univ → + ∀(F : Finset (Fin m)) (P : PartitionChain n) (z : ℕ), P.parts z={univ} → + (∀i ≤ z, ∀A ∈ P.parts i, (H.restrict F).EdgeConnectedReal A (r/2:ℕ)) → + ∀s : ℝ, 0 < s → s ≤ (r:ℝ)^(1/4:ℝ) → + ∃Y ∈ metricDomain H, CenteredPositive Y ∧ ∀i ≤ z, + (((P.crossing (H.restrict F) i).filter (fun e => + ¬ (6*s) • vecMulVec ((H.restrict F).incidence e) ((H.restrict F).incidence e) ≤ Y)).card:ℝ) ≤ + (r:ℝ)^(-1/3:ℝ)*(P.crossing (H.restrict F) i).card := by + obtain ⟨h0,hh0,hresp⟩ := simultaneous_metric_response_bound + obtain ⟨r1,hr1,hfrac⟩ := response_fraction_cutoff + refine ⟨max (2*h0) r1,hr1.trans (le_max_right _ _),?_⟩ + intro r hr n m H hn _ F P z hz hlocal s hs hsR + have hrh : h0 ≤ r/2 := by have := (le_max_left _ _).trans hr; omega + have hrr : r1 ≤ r := (le_max_right _ _).trans hr + have ht : 0 < 1/(6*s) := by positivity + obtain ⟨Y,hYm,hY,hbad⟩ := hresp (r/2) hrh n F.card m (H.restrict F) H hn + (restrict_laplacian_le H F) P z hz hlocal (1/(6*s)) ht + refine ⟨Y,hYm,hY,?_⟩ + intro i hi + have heq : (P.crossing (H.restrict F) i).filter (fun e => + ¬ (6*s) • vecMulVec ((H.restrict F).incidence e) ((H.restrict F).incidence e) ≤ Y) = + (univ.filter (fun e => 1/(6*s) < resistance (H.restrict F) Y e)) ∩ + P.crossing (H.restrict F) i := by + ext e + simp only [mem_filter,mem_inter,mem_univ,true_and] + have hor := centered_resistance_order (by omega : 0 < n) hY + (incidence_sum (H.restrict F) e) (by positivity : 0 < 6*s) + rw [Matrix.le_iff,hor,not_le] + have he : 1 < 6*s*qform (inverseOnZeroSum Y) ((H.restrict F).incidence e) ↔ + 1/(6*s) < resistance (H.restrict F) Y e := by + unfold resistance + rw [div_lt_iff₀ (by positivity : 0 < 6*s)] + rw [mul_comm] + rw [he,and_comm] + rw [heq] + exact (hbad i hi).trans (mul_le_mul_of_nonneg_right (hfrac r hrr s hs hsR) (Nat.cast_nonneg _)) + +end +end AlgorithmicThinTrees.MetricTests +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/ScaleCharging.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/ScaleCharging.lean new file mode 100644 index 0000000000000000000000000000000000000000..8b343bda781f518eca287b7fc3e958950cad6ddd --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/ScaleCharging.lean @@ -0,0 +1,482 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.BagExtraction + +namespace OAI + +/-! Metric scale charging. -/ + +section + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +open scoped Classical + +structure CompactPackage {n : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] (X : Fin n → Doubled Coord → ℝ) where + radius : ℝ + diameter : ℝ + family : CompactFamily X radius diameter + +namespace CompactPackage +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {G : MultiGraph n m} {X : Fin n → Doubled Coord → ℝ} +def mass (F : CompactPackage X) : ℝ := F.radius*(∑D ∈ F.family.bags, (D.card : ℝ)) + +lemma finite_bound {k : ℕ} (hk : G.EdgeConnected k) (hX : ∀v, isProfile (X v)) + {q : ℕ} (F : Fin q → CompactPackage X) + (hnext : ∀i j : Fin q, i.val+1=j.val → (F j).diameter ≤ (F i).radius/12) : + (k:ℝ)/4*(∑i, (F i).mass) ≤ ∑e : Fin m, normDistance (X (G.left e)) (X (G.right e)) := by + by_cases hq : q=0 + · subst q + simp only [Finset.univ_eq_empty,Finset.sum_empty,mul_zero] + exact sum_nonneg (fun e _ => normDistance_nonneg _ _) + · have hq' : 0 < q := Nat.pos_of_ne_zero hq + let ind : ℕ → Fin q := fun i => ⟨i%q,Nat.mod_lt _ hq'⟩ + have hh := metric_compact_bound G hk X hX q + (fun i => (F (ind i)).radius) (fun i => (F (ind i)).diameter) + (fun i => (F (ind i)).family) (by + intro i hi + apply hnext + simp only [ind,Nat.mod_eq_of_lt hi,Nat.mod_eq_of_lt (show i F (f i)) (by + intro i j hij + apply hgeo + change (e j.rev).val < (e i.rev).val + exact e.strictMono (Fin.rev_lt_rev.mpr (show i (F i).mass)] at hh + exact hh +end CompactPackage + +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} {X : Fin n → Doubled Coord → ℝ} + +namespace AssignedBag +variable {δ η η' : ℝ} +def weaken (A : AssignedBag H G X δ η) (hη : η' ≤ η) : AssignedBag H G X δ η' := + { A with assignment := (mul_le_mul_of_nonneg_right hη (Nat.cast_nonneg _)).trans A.assignment } +end AssignedBag + +namespace AssignedFamily +variable {η η' : ℝ} +def weaken (F : AssignedFamily H G X η) (hη : η' ≤ η) : AssignedFamily H G X η' where + radius := F.radius + positive := F.positive + count := F.count + bag := fun i => (F.bag i).weaken hη + owner_injective := F.owner_injective + separated := F.separated +end AssignedFamily + +namespace AssignedSequence +variable {η q ρ : ℝ} + +lemma mass_eq (L : List (AssignedFamily H G X η)) : mass L = (L.map AssignedFamily.mass).sum := by + induction L with + | nil => rfl + | cons F L ih => simpa only [mass,List.map_cons,List.sum_cons] using congrArg (F.mass+·) ih + +lemma geometric_of_pairwise (hρ : 0 ≤ ρ) (L : List (AssignedFamily H G X η)) + (hL : L.Pairwise (fun F F' => F'.radius ≤ ρ*F.radius)) : GeometricAt ρ L := by + induction L with + | nil => trivial + | cons F L ih => + refine ⟨?_,ih (List.pairwise_cons.mp hL).2⟩ + cases L with + | nil => exact mul_nonneg hρ F.positive.le + | cons F' L => exact (List.pairwise_cons.mp hL).1 F' (by simp) + +lemma ratios_of_mem (L : List (AssignedFamily H G X (6144/q))) + (hL : ∀F ∈ L, F.BoundaryRatio ρ) : Ratios ρ L := by + induction L with + | nil => trivial + | cons F L ih => exact ⟨hL F (by simp),ih (fun F' hF' => hL F' (by simp [hF']))⟩ + +lemma fresh_of_pairwise (L : List (AssignedFamily H G X (6144/q))) + (hL : L.Pairwise (fun F F' => Disjoint F.owners F'.owners)) + (E : Finset (Finset (Fin n))) (hE : ∀F ∈ L, Disjoint E F.owners) : Fresh E L := by + induction L generalizing E with + | nil => trivial + | cons F L ih => + refine ⟨hE F (by simp),ih (List.pairwise_cons.mp hL).2 _ ?_⟩ + intro F' hF' + exact disjoint_union_left.mpr ⟨hE F' (by simp [hF']), (List.pairwise_cons.mp hL).1 F' hF'⟩ + +lemma finite_bound (hX : ∀v, isProfile (X v)) (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + {r : ℕ} (F : Fin r → AssignedFamily H G X (6144/q)) + (hgeo : ∀i j, i F (f i)) (by + intro i j hij + apply hgeo + change (e j.rev).val < (e i.rev).val + exact e.strictMono (Fin.rev_lt_rev.mpr hij)) + (fun i => hR (f i)) (fun i j hij => hdis _ _ (f.injective.ne hij.ne)) + rw [f.sum_comp (fun i => (F i).mass)] at hh + exact hh +end AssignedSequence +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +open scoped Classical +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} {X : Fin n → Doubled Coord → ℝ} + +abbrev CapturedFamily (H : Hierarchy n) (G : MultiGraph n m) (X : Fin n → Doubled Coord → ℝ) (η : ℝ) := + Sum (CompactPackage X) (AssignedFamily H G X η) + +namespace CapturedFamily +variable {η : ℝ} +def radius : CapturedFamily H G X η → ℝ + | .inl F => F.radius + | .inr F => F.radius +def upper : CapturedFamily H G X η → ℝ + | .inl F => F.diameter + | .inr F => F.radius +def mass : CapturedFamily H G X η → ℝ + | .inl F => F.mass + | .inr F => F.mass +def owners : CapturedFamily H G X η → Finset (Finset (Fin n)) + | .inl _ => ∅ + | .inr F => F.owners + +def Ratio {q : ℝ} (F : CapturedFamily H G X (6144/q)) (ρ : ℝ) : Prop := + match F with + | .inl _ => True + | .inr F => F.BoundaryRatio ρ + +lemma mass_nonneg (F : CapturedFamily H G X η) : 0 ≤ F.mass := by + cases F with + | inl F => exact mul_nonneg F.family.radius_pos.le (sum_nonneg (fun D _ => Nat.cast_nonneg _)) + | inr F => exact mul_nonneg (sum_nonneg (fun i _ => Nat.cast_nonneg _)) F.positive.le + +lemma mixed_bound {J : Type*} [LinearOrder J] {q : ℕ} + (hq : 0 < q) (hk : G.EdgeConnected q) (hX : ∀v, isProfile (X v)) + (hconn : LocallyConnectedReal H G q) {ρ : ℝ} (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (S : Finset J) (F : S → CapturedFamily H G X (6144/q)) + (hgeo : ∀i j : S, j.val < i.val → (F j).upper ≤ ρ*(F i).radius) + (hR : ∀i, (F i).Ratio ρ) + (hdis : ∀i j : S, i≠j → Disjoint (F i).owners (F j).owners) : + ((q:ℝ)/8192)*(∑i, (F i).mass) ≤ 2*∑e : Fin m, normDistance (X (G.left e)) (X (G.right e)) := by + let C : Finset S := univ.filter (fun i => ∃P, F i=Sum.inl P) + let A : Finset S := univ\C + have hexC : ∀i : C, ∃P, F i.val=Sum.inl P := fun i => (mem_filter.mp i.property).2 + have hexA : ∀i : A, ∃P, F i.val=Sum.inr P := by + intro i + cases hh : F i.val with + | inl P => + have hi : i.val ∉ C := (mem_sdiff.mp i.property).2 + exact (hi (mem_filter.mpr ⟨mem_univ _,⟨P,hh⟩⟩)).elim + | inr P => exact ⟨P,rfl⟩ + let FC : C → CompactPackage X := fun i => Classical.choose (hexC i) + let FA : A → AssignedFamily H G X (6144/q) := fun i => Classical.choose (hexA i) + have hFC : ∀i : C, F i.val=Sum.inl (FC i) := fun i => Classical.choose_spec (hexC i) + have hFA : ∀i : A, F i.val=Sum.inr (FA i) := fun i => Classical.choose_spec (hexA i) + have hC := CompactPackage.ordered_bound hk hX C FC (by + intro i j hij + have hh := hgeo i.val j.val hij + rw [hFC i,hFC j] at hh + change (FC j).diameter ≤ ρ*(FC i).radius at hh + have hr : ρ ≤ 1/12 := hρsmall.trans (by norm_num) + have hm := mul_le_mul_of_nonneg_right hr (FC i).family.radius_pos.le + exact hh.trans (by nlinarith only [hm])) + have hA := AssignedSequence.ordered_bound hX (show (0:ℝ) (F i).mass)] + apply sum_congr rfl + intro i hi + rw [hFC i] + rfl + have hsumA : (∑i : A, (FA i).mass) = ∑i ∈ A, (F i).mass := by + rw [←sum_coe_sort A (fun i => (F i).mass)] + apply sum_congr rfl + intro i hi + rw [hFA i] + rfl + rw [hsumC] at hC + rw [hsumA] at hA + have hCn : 0 ≤ ∑i ∈ C, (F i).mass := sum_nonneg (fun i _ => mass_nonneg (F i)) + have hcoef : (q:ℝ)/8192 ≤ (q:ℝ)/4 := by + have hh : (0:ℝ) ≤ q := Nat.cast_nonneg _ + linarith + have hC' := (mul_le_mul_of_nonneg_right hcoef hCn).trans hC + have he : (∑i ∈ A, (F i).mass)+(∑i ∈ C, (F i).mass) = ∑i : S, (F i).mass := + sum_sdiff (subset_univ C) + rw [←he,mul_add] + linarith only [hA,hC'] +end CapturedFamily +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +open scoped Classical +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} +namespace CapturedFamily +lemma scale_bound {q : ℕ} (hq : 0 < q) (hk : G.EdgeConnected q) + (hX : ∀v, isProfile (X v)) (hconn : LocallyConnectedReal H G q) + {ρ s : ℝ} (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) (hs : 0 < s) + {R : ℕ} (hR : 0 < R) (hlog : Real.logb 2 (24/(ρ*s^2)) < R) + (S : Finset ℤ) (F : S → CapturedFamily H G X (6144/q)) + (hlow : ∀i : S, s*2^(i.val:ℝ) ≤ (F i).radius) + (hupp : ∀i : S, (F i).upper ≤ 24*2^(i.val:ℝ)/s) + (hratio : ∀i, (F i).Ratio ρ) + (hdis : ∀i j : S, i≠j → Disjoint (F i).owners (F j).owners) : + ((q:ℝ)/8192)*(∑i, (F i).mass) ≤ + 2*R*(∑e : Fin m, normDistance (X (G.left e)) (X (G.right e))) := by + let residue : ℤ → Fin R := fun i => ⟨(i%R).toNat, by + have hn := Int.emod_nonneg i (show (R:ℤ)≠0 by omega) + have hh := Int.emod_lt_of_pos i (show (0:ℤ) univ.filter (fun i => residue i.val=r) + have hbound : ∀r : Fin R, ((q:ℝ)/8192)*(∑i ∈ C r, (F i).mass) ≤ + 2*∑e : Fin m, normDistance (X (G.left e)) (X (G.right e)) := by + intro r + have hh := mixed_bound hq hk hX hconn hρ hρsmall (C r) (fun i => F i.val) (by + intro i j hij + have hi := (mem_filter.mp i.property).2 + have hj := (mem_filter.mp j.property).2 + have hmod : j.val.val%R=i.val.val%R := by + have he := congrArg Fin.val (hj.trans hi.symm) + dsimp [residue] at he + have hn1 := Int.emod_nonneg i.val.val (show (R:ℤ)≠0 by omega) + have hn2 := Int.emod_nonneg j.val.val (show (R:ℤ)≠0 by omega) + omega + have hsep := ScaleSelection.separated_scales hs hρ hlog + (ScaleSelection.residue_spacing hR hij hmod) + exact (hupp j.val).trans (hsep.le.trans (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_left (hlow i.val) hρ.le))) + (fun i => hratio i.val) + (fun i j hij => hdis i.val j.val (Subtype.val_injective.ne hij)) + rw [←sum_coe_sort (C r) (fun i => (F i).mass)] + exact hh + have hh := sum_le_sum (s := univ) (fun r (_ : r ∈ univ) => hbound r) + rw [←mul_sum] at hh + have he : (∑r : Fin R, ∑i ∈ C r, (F i).mass) = ∑i : S, (F i).mass := by + exact sum_fiberwise_of_maps_to (fun _ _ => mem_univ _) (fun i => (F i).mass) + rw [he] at hh + simpa only [sum_const,card_univ,Fintype.card_fin,nsmul_eq_mul,mul_assoc,mul_left_comm] using hh +end CapturedFamily +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +open scoped Classical +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} + +lemma capturePackage (T : Finset (Finset (Fin n))) (F : Finset (Fin n) → Finset (Fin m)) + (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hTne : T.Nonempty) (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hF : ∀t ∈ T, F t ⊆ parentBoundary H G t) (hFn : ∀t ∈ T, (F t).Nonempty) + {α γ ε c₁ c₂ : ℝ} (hα : 0 < α) (hγ : 0 < γ) + (he : 0 < ε) (he1 : ε < 1/3) (hc₁ : 0 < c₁) (hc₂ : 0 < c₂) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ normDistance (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hmin : ∀t ∈ T, ∀e ∈ F t, c₁ ≤ ((Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hmax : ∀t ∈ T, ∀e ∈ F t, ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ 4*c₁) + (hdmin : ∀t ∈ T, ∀e ∈ F t, c₂/4 ≤ normDistance (X (G.left e)) (X (G.right e))) + (hdmax : ∀t ∈ T, ∀e ∈ F t, normDistance (X (G.left e)) (X (G.right e)) ≤ c₂) + (hbad : ∀t ∈ T, α*((parentBoundary H G t).card : ℝ)* + (∑e ∈ parentBoundary H G t, normDistance (X (G.left e)) (X (G.right e))) ≤ + (∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hdom : ∀t ∈ T, γ*(∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ + (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hsmall : (α*γ/32)^ε ≤ 1/(1728*(1024/ε^2))) + {q : ℕ} {ρ : ℝ} + (hassign : (6144:ℝ)/q ≤ (α*γ/32)^(1+2*ε)) + (hratio : ∀t ∈ T, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (parentBoundary H G t).card) : + let s := α*γ/32 + let R := ∑t ∈ T, (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((parentBoundary H G t).card : ℝ) + ∃B : CapturedFamily H G X (6144/q), B.owners ⊆ T ∧ B.Ratio ρ ∧ + s*c₁ ≤ B.radius ∧ B.upper ≤ 12*c₁/s ∧ s^ε*R/(6912*(1024/ε^2)) ≤ B.mass := by + obtain hC | hA := homogeneous_family T F Y hTne hT hroot hF hFn hα hγ he he1 hc₁ hc₂ + hcontract hpositive hmin hmax hdmin hdmax hbad hdom hsmall + · obtain ⟨δ,Δ,B,hl,hu,hg⟩ := hC + exact ⟨.inl ⟨δ,Δ,B⟩,empty_subset _,trivial,hl,hu,hg⟩ + · obtain ⟨B,hBT,hl,hu,hg⟩ := hA + refine ⟨.inr (B.weaken hassign),hBT,?_,hl,hu,hg⟩ + intro i + apply hratio + apply hBT + exact mem_image.mpr ⟨i,mem_univ _,rfl⟩ + +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +namespace AlgorithmicThinTrees.MetricProfiles.AssignedGeometry +noncomputable section +open Finset StrongThinTree StrongThinTree.MultiGraph +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry +open AlgorithmicThinTrees.MetricProfiles.CompactGeometry.RadialShell +open scoped Classical +variable {n m : ℕ} {Coord : Type*} [Fintype Coord] [PseudoMetricSpace Coord] {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Doubled Coord → ℝ} + +lemma homogeneous_scale_bound {q L R : ℕ} (hq : 0 < q) (hL : 0 < L) (hR : 0 < R) + (hk : G.EdgeConnected q) (hX : ∀v, isProfile (X v)) + (hconn : LocallyConnectedReal H G q) + (T : Finset (Finset (Fin n))) (F : Finset (Fin n) → Finset (Fin m)) + (idx : Finset (Fin n) → ℤ) (off : Finset (Fin n) → Fin L) + (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + (hF : ∀t ∈ T, F t ⊆ parentBoundary H G t) (hFn : ∀t ∈ T, (F t).Nonempty) + {α γ ε ρ : ℝ} (hα : 0 < α) (hγ : 0 < γ) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ normDistance (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hmin : ∀t ∈ T, ∀e ∈ F t, 2^(idx t:ℝ) ≤ ((Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hmax : ∀t ∈ T, ∀e ∈ F t, ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ 4*2^(idx t:ℝ)) + (hdmin : ∀t ∈ T, ∀e ∈ F t, 2^((idx t:ℝ)+(off t).val) ≤ normDistance (X (G.left e)) (X (G.right e))) + (hdmax : ∀t ∈ T, ∀e ∈ F t, normDistance (X (G.left e)) (X (G.right e)) ≤ 4*2^((idx t:ℝ)+(off t).val)) + (hbad : ∀t ∈ T, α*((parentBoundary H G t).card : ℝ)* + (∑e ∈ parentBoundary H G t, normDistance (X (G.left e)) (X (G.right e))) ≤ + (∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hdom : ∀t ∈ T, γ*(∑e ∈ parentBoundary H G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ + (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hsmall : (α*γ/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*γ/32)^(1+2*ε)) + (hratio : ∀t ∈ T, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (parentBoundary H G t).card) + (hlog : Real.logb 2 (24/(ρ*(α*γ/32)^2)) < R) : + let s := α*γ/32 + let W := ∑t ∈ T, (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((parentBoundary H G t).card : ℝ) + ((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2)))*(W/(L:ℝ)) ≤ + 2*R*(∑e : Fin m, normDistance (X (G.left e)) (X (G.right e))) := by + let : NeZero L := ⟨Nat.ne_of_gt hL⟩ + let s := α*γ/32 + let w : Finset (Fin n) → ℝ := fun t => + (∑e ∈ F t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/((parentBoundary H G t).card : ℝ) + let c := s^ε/(6912*(1024/ε^2)) + have hs : 0 < s := by dsimp [s]; positivity + have hc : 0 ≤ c := by dsimp [c]; positivity + obtain ⟨choice,hchoice⟩ := ScaleSelection.select_fibers T idx off w + simp only [Fintype.card_fin] at hchoice + let U := T.filter (fun t => off t=choice (idx t)) + let S := U.image idx + let B : S → Finset (Finset (Fin n)) := fun i => U.filter (fun t => idx t=i.val) + have hBT : ∀i : S, B i ⊆ T := fun i => (filter_subset _ _).trans (filter_subset _ _) + have hBn : ∀i : S, (B i).Nonempty := by + intro i + obtain ⟨t,ht,heq⟩ := mem_image.mp i.property + exact ⟨t,mem_filter.mpr ⟨ht,heq⟩⟩ + have hi : ∀i : S, ∀t ∈ B i, idx t=i.val := fun i t ht => (mem_filter.mp ht).2 + have hoff : ∀i : S, ∀t ∈ B i, off t=choice i.val := by + intro i t ht + have hh := (mem_filter.mp (mem_filter.mp ht).1).2 + change off t=choice (idx t) at hh + rw [hi i t ht] at hh + exact hh + have hex : ∀i : S, ∃P : CapturedFamily H G X (6144/q), + P.owners ⊆ B i ∧ P.Ratio ρ ∧ s*2^(i.val:ℝ) ≤ P.radius ∧ + P.upper ≤ 12*2^(i.val:ℝ)/s ∧ c*(∑t ∈ B i, w t) ≤ P.mass := by + intro i + have hp1 : (0:ℝ) < 2^(i.val:ℝ) := Real.rpow_pos_of_pos (by norm_num) _ + have hp2 : (0:ℝ) < 4*2^((i.val:ℝ)+(choice i.val).val) := by positivity + obtain ⟨P,hP⟩ := capturePackage (B i) F Y (hBn i) ((hBT i).trans hT) + (fun t ht => hroot t (hBT i ht)) (fun t ht => hF t (hBT i ht)) + (fun t ht => hFn t (hBT i ht)) hα hγ he he1 hp1 hp2 hcontract hpositive + (by intro t ht e he; simpa only [hi i t ht] using hmin t (hBT i ht) e he) + (by intro t ht e he; simpa only [hi i t ht] using hmax t (hBT i ht) e he) + (by + intro t ht e he + have hh := hdmin t (hBT i ht) e he + rw [hi i t ht,hoff i t ht] at hh + simpa only [mul_div_cancel_left₀ _ (by norm_num : (4:ℝ)≠0)] using hh) + (by intro t ht e he; simpa only [hi i t ht,hoff i t ht] using hdmax t (hBT i ht) e he) + (fun t ht => hbad t (hBT i ht)) (fun t ht => hdom t (hBT i ht)) hsmall hassign + (fun t ht => hratio t (hBT i ht)) + refine ⟨P,hP.1,hP.2.1,hP.2.2.1,hP.2.2.2.1,?_⟩ + simpa only [c,w,div_mul_eq_mul_div] using hP.2.2.2.2 + let P : S → CapturedFamily H G X (6144/q) := fun i => Classical.choose (hex i) + have hP := fun i => Classical.choose_spec (hex i) + have hbound := CapturedFamily.scale_bound hq hk hX hconn hρ hρsmall hs hR hlog S P + (fun i => (hP i).2.2.1) + (by + intro i + apply (hP i).2.2.2.1.trans + apply div_le_div_of_nonneg_right _ hs.le + exact mul_le_mul_of_nonneg_right (by norm_num : (12:ℝ)≤24) (Real.rpow_nonneg (by norm_num) _)) + (fun i => (hP i).2.1) + (by + intro i j hij + apply Finset.disjoint_left.mpr + intro t hti htj + have he := (hi i t ((hP i).1 hti)).symm.trans (hi j t ((hP j).1 htj)) + exact hij (Subtype.ext he)) + have hfiber : (∑i : S, ∑t ∈ B i, w t) = ∑t ∈ U, w t := by + rw [sum_coe_sort S (fun i => ∑t ∈ U.filter (fun t => idx t=i), w t)] + exact sum_fiberwise_of_maps_to (fun t ht => mem_image_of_mem idx ht) w + have hsum : c*(∑t ∈ U, w t) ≤ ∑i : S, (P i).mass := by + have hh := sum_le_sum (s := univ) (fun i (_ : i ∈ univ) => (hP i).2.2.2.2) + rw [←mul_sum,hfiber] at hh + exact hh + have hgain := (mul_le_mul_of_nonneg_left hchoice hc).trans hsum + have hq0 : 0 ≤ (q:ℝ)/8192 := by positivity + have hh := (mul_le_mul_of_nonneg_left hgain hq0).trans hbound + simpa only [mul_assoc] using hh +end +end AlgorithmicThinTrees.MetricProfiles.AssignedGeometry + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/ShellCharging.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/ShellCharging.lean new file mode 100644 index 0000000000000000000000000000000000000000..636e82f361ef79219240568c9f814514cff9ff6c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/ShellCharging.lean @@ -0,0 +1,190 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Realization.FaceQueryRealization +import OAI.Combinatorics.ThinTrees.Metric.Profiles + +namespace OAI + +/-! Metric shell charging. -/ + +section + +noncomputable section + +namespace AlgorithmicThinTrees.MetricProfiles + +open Finset Set StrongThinTree.Geometry + +variable {V I : Type*} [Fintype V] [PseudoMetricSpace V] + +def relativeBall (c : V → ℝ) (δ : ℝ) : Set (V → ℝ) := + {q | q ∈ polytope ∧ ‖q - c‖ < δ} + +def relativeShell (c : V → ℝ) (a b : ℝ) : Set (V → ℝ) := + {q | q ∈ polytope ∧ a < ‖q - c‖ ∧ ‖q - c‖ < b} + +omit [PseudoMetricSpace V] in +lemma radius_reverse_triangle (q r c : V → ℝ) : + |‖r - c‖ - ‖q - c‖| ≤ ‖r - q‖ := by + have h := abs_norm_sub_norm_le (r - c) (q - c) + simpa only [sub_sub_sub_cancel_right] using h + +theorem disjoint_relative_balls_iff {q r : V → ℝ} + (hq : q ∈ polytope) (hr : r ∈ polytope) {δ : ℝ} : + Disjoint (relativeBall q δ) (relativeBall r δ) ↔ 2 * δ ≤ ‖q - r‖ := by + constructor + · intro hdis + by_contra h + have hdist : ‖r - q‖ < 2 * δ := by + rw [norm_sub_rev] + exact lt_of_not_ge h + have ht : (1 / 2 : ℝ) ∈ Set.Icc (0 : ℝ) 1 := by norm_num + have hm := mix_mem hq hr ht + have hl : ‖mix q r (1 / 2) - q‖ = 1 / 2 * ‖r - q‖ := by + simpa only [mix_zero, sub_zero, abs_of_nonneg (show (0 : ℝ) ≤ 1 / 2 by norm_num)] + using segment_distance q r (1 / 2) 0 + have hr' : ‖mix q r (1 / 2) - r‖ = 1 / 2 * ‖r - q‖ := by + have h := segment_distance q r (1 / 2) 1 + norm_num only [mix_one, show |(1 / 2 : ℝ) - 1| = 1 / 2 by norm_num] at h + exact h + exact Set.disjoint_left.mp hdis ⟨hm, by rw [hl]; linarith⟩ + ⟨hm, by rw [hr']; linarith⟩ + · intro hdist + apply Set.disjoint_left.mpr + rintro s ⟨_, hs⟩ ⟨_, hs'⟩ + have h := dist_triangle q s r + simp only [dist_eq_norm] at h + rw [norm_sub_rev q s] at h + linarith + +theorem ball_shell_intersection_iff {q : Doubled V → ℝ} (hq : q ∈ polytope) + (x : V) {a b δ : ℝ} (ha : 0 ≤ a) (hab : a < b) + (hb : b ≤ commonRadius V) (hδ : 0 < δ) : + (relativeBall q δ ∩ relativeShell (profile (plus x)) a b).Nonempty ↔ + a - δ < ‖q - profile (plus x)‖ ∧ ‖q - profile (plus x)‖ < b + δ := by + constructor + · rintro ⟨z, ⟨_, hzδ⟩, _, hza, hzb⟩ + have h := abs_sub_le_iff.mp (radius_reverse_triangle q z (profile (plus x))) + constructor <;> linarith [h.1, h.2] + · rintro ⟨ha', hb'⟩ + obtain ⟨z, hz, hzδ, hza, hzb⟩ := ball_intersects_shell hq x ha hab hb hδ ha' hb' + exact ⟨z, ⟨hz, hzδ⟩, hz, hza, hzb⟩ + +theorem shell_segment_length_bound [Fintype I] (c : I → V) (a b : I → ℝ) + (hab : ∀ i, a i ≤ b i) + (hdis : Pairwise (fun i j => Disjoint + (relativeShell (profile (c i)) (a i) (b i)) + (relativeShell (profile (c j)) (a j) (b j)))) + {q r : V → ℝ} (hq : q ∈ polytope) (hr : r ∈ polytope) : + ∑ i, |clamp (a i) (b i) ‖q - profile (c i)‖ - + clamp (a i) (b i) ‖r - profile (c i)‖| ≤ ‖r - q‖ := by + apply clamped_affine_disjoint_sum a b + (fun i => ‖q - profile (c i)‖) (fun i => ‖r - profile (c i)‖) + (norm_nonneg _) hab (fun i => radius_reverse_triangle q r (profile (c i))) + rintro i j hij t ht ⟨hia, hib, hja, hjb⟩ + have ht' : t ∈ Set.Icc (0 : ℝ) 1 := ⟨ht.1.le, ht.2.le⟩ + have hrad (s : V) : ‖mix q r t - profile s‖ = + ‖q - profile s‖ + t * (‖r - profile s‖ - ‖q - profile s‖) := by + rw [radius_mix hq hr s ht'] + ring + apply Set.disjoint_left.mp (hdis hij) (mix_mem hq hr ht' |> fun hm => + show mix q r t ∈ relativeShell (profile (c i)) (a i) (b i) from + ⟨hm, by rwa [hrad], by rwa [hrad]⟩) + exact ⟨mix_mem hq hr ht', by rwa [hrad], by rwa [hrad]⟩ + +theorem shell_length_bound {n m k : ℕ} (G : StrongThinTree.MultiGraph n m) + (hk : G.EdgeConnected k) (X : Fin n → V) [Fintype I] + (c : I → V) (a b : I → ℝ) (hab : ∀ i, a i ≤ b i) + (hinner : ∀ i, ∃ u, dist (X u) (c i) ≤ a i) + (houter : ∀ i, ∃ v, b i ≤ dist (X v) (c i)) + (hdis : Pairwise (fun i j => Disjoint + (relativeShell (profile (c i)) (a i) (b i)) + (relativeShell (profile (c j)) (a j) (b j)))) : + (k : ℝ) * ∑ i, (b i - a i) ≤ + ∑ e : Fin m, dist (X (G.left e)) (X (G.right e)) := by + calc + _ = ∑ i, (k : ℝ) * (b i - a i) := Finset.mul_sum _ _ _ + _ ≤ ∑ i, ∑ e : Fin m, + |clamp (a i) (b i) (dist (X (G.left e)) (c i)) - + clamp (a i) (b i) (dist (X (G.right e)) (c i))| := by + exact Finset.sum_le_sum fun i _ => G.clamped_variation_lower hk + (fun u => dist (X u) (c i)) (hab i) (hinner i) (houter i) + _ = ∑ e : Fin m, ∑ i, + |clamp (a i) (b i) (dist (X (G.left e)) (c i)) - + clamp (a i) (b i) (dist (X (G.right e)) (c i))| := Finset.sum_comm + _ ≤ ∑ e : Fin m, dist (X (G.left e)) (X (G.right e)) := by + apply Finset.sum_le_sum + intro e _ + have h := shell_segment_length_bound c a b hab hdis + (profile_mem (X (G.left e))) (profile_mem (X (G.right e))) + simpa only [profile_norm_sub, dist_comm (X (G.right e)) (X (G.left e))] using h + +theorem routed_shell_length_bound {n m : ℕ} (G : StrongThinTree.MultiGraph n m) + (X : Fin n → V) [Fintype I] (c : I → V) (a b : I → ℝ) + (R L : I → Finset (Fin n)) (q : ℝ) + (hab : ∀ i, a i ≤ b i) (hconn : ∀ i, G.EdgeConnectedReal (R i) q) + (hinner : ∀ i, ∃ u ∈ R i, u ∈ L i ∧ dist (X u) (c i) ≤ a i) + (houter : ∀ i, ∃ v ∈ R i, b i ≤ dist (X v) (c i)) + (hprotect : ∀ i e, e ∈ G.inducedEdges (R i) → + ((G.left e ∈ L i ∧ G.right e ∉ L i) ∨ + (G.right e ∈ L i ∧ G.left e ∉ L i)) → + b i ≤ dist (X (G.left e)) (c i) ∧ b i ≤ dist (X (G.right e)) (c i)) + (hdis : ∀ i j, i ≠ j → ¬ Disjoint (L i) (L j) → Disjoint + (relativeShell (profile (c i)) (a i) (b i)) + (relativeShell (profile (c j)) (a j) (b j))) : + q * ∑ i, (b i - a i) ≤ + ∑ e : Fin m, dist (X (G.left e)) (X (G.right e)) := by + classical + let f (i : I) (e : Fin m) : ℝ := + |clamp (a i) (b i) (dist (X (G.left e)) (c i)) - + clamp (a i) (b i) (dist (X (G.right e)) (c i))| + calc + _ = ∑ i, q * (b i - a i) := Finset.mul_sum _ _ _ + _ ≤ ∑ i, ∑ e ∈ G.inducedEdges (L i), f i e := by + apply Finset.sum_le_sum + intro i _ + exact G.routed_variation_lower (fun u => dist (X u) (c i)) (hab i) + (hconn i) (hinner i) (houter i) (hprotect i) + _ = ∑ e : Fin m, ∑ i ∈ univ.filter (fun i => e ∈ G.inducedEdges (L i)), f i e := by + simp only [StrongThinTree.MultiGraph.inducedEdges, Finset.sum_filter, Finset.mem_filter, + Finset.mem_univ, true_and] + rw [Finset.sum_comm] + _ ≤ ∑ e : Fin m, dist (X (G.left e)) (X (G.right e)) := by + apply Finset.sum_le_sum + intro e _ + let W := univ.filter (fun i => e ∈ G.inducedEdges (L i)) + change ∑ i ∈ W, f i e ≤ _ + rw [← Finset.sum_coe_sort] + have hdis' : Pairwise (fun i j : W => Disjoint + (relativeShell (profile (c i)) (a i) (b i)) + (relativeShell (profile (c j)) (a j) (b j))) := by + intro i j hij + apply hdis i j (fun h => hij (Subtype.ext h)) + intro hL + exact Finset.disjoint_left.mp hL + ((G.mem_inducedEdges _ _).mp (mem_filter.mp i.property).2).1 + ((G.mem_inducedEdges _ _).mp (mem_filter.mp j.property).2).1 + have h := shell_segment_length_bound (fun i : W => c i) + (fun i : W => a i) (fun i : W => b i) (fun i => hab i) hdis' + (profile_mem (X (G.left e))) (profile_mem (X (G.right e))) + simpa only [f, profile_norm_sub, dist_comm (X (G.right e)) (X (G.left e))] using h + +theorem doubled_shell_length_bound {n m k : ℕ} (G : StrongThinTree.MultiGraph n m) + (hk : G.EdgeConnected k) (X : Fin n → V) [Fintype I] + (c : I → V) (a b : I → ℝ) (hab : ∀ i, a i ≤ b i) + (hinner : ∀ i, ∃ u, dist (X u) (c i) ≤ a i) + (houter : ∀ i, ∃ v, b i ≤ dist (X v) (c i)) + (hdis : Pairwise (fun i j => Disjoint + (relativeShell (profile (plus (c i))) (a i) (b i)) + (relativeShell (profile (plus (c j))) (a j) (b j)))) : + (k : ℝ) * ∑ i, (b i - a i) ≤ + ∑ e : Fin m, dist (X (G.left e)) (X (G.right e)) := by + simpa only [dist_plus] using shell_length_bound G hk (fun u => plus (X u)) + (fun i => plus (c i)) a b hab (by simpa only [dist_plus]) + (by simpa only [dist_plus]) hdis + +end AlgorithmicThinTrees.MetricProfiles + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Metric/SpectralMetricBridge.lean b/lean/OAI/Combinatorics/ThinTrees/Metric/SpectralMetricBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..4bcb258336c3f9c04c4c5b0454bd71cbaa107fa1 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Metric/SpectralMetricBridge.lean @@ -0,0 +1,101 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Metric.AssignedCharging + +namespace OAI + +/-! Spectral metric bridge. -/ + +section + +namespace AlgorithmicThinTrees.MetricProfiles +noncomputable section +open Finset + +variable {V E F : Type*} [Fintype V] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [NormedAddCommGroup F] [InnerProductSpace ℝ F] + +def SquaredTriangle (p : V → E) : Prop := + ∀ u v w, ‖p u-p w‖^2 ≤ ‖p u-p v‖^2+‖p v-p w‖^2 + +@[instance_reducible] def squaredPseudoMetric (p : V → E) (ht : SquaredTriangle p) : PseudoMetricSpace V where + dist u v := ‖p u-p v‖^2 + dist_self u := by simp + dist_comm u v := by rw [norm_sub_rev] + dist_triangle := ht + +def spectralProfile (p : V → E) (ht : SquaredTriangle p) (v : V) : Doubled V → ℝ := + letI := squaredPseudoMetric p ht + profile (plus v) + +def spectralPolytope (p : V → E) (ht : SquaredTriangle p) : Set (Doubled V → ℝ) := + letI := squaredPseudoMetric p ht + polytope + +omit [InnerProductSpace ℝ E] in +lemma spectral_profile_length (p : V → E) (ht : SquaredTriangle p) (u v : V) : + ‖spectralProfile p ht u-spectralProfile p ht v‖ = ‖p u-p v‖^2 := by + let := squaredPseudoMetric p ht + change ‖profile (plus u)-profile (plus v)‖ = _ + rw [profile_norm_sub,dist_plus] + rfl + +omit [InnerProductSpace ℝ E] in +lemma spectral_profile_mem (p : V → E) (ht : SquaredTriangle p) (u : V) : + spectralProfile p ht u ∈ spectralPolytope p ht := by + let := squaredPseudoMetric p ht + exact profile_mem (plus u) + +omit [InnerProductSpace ℝ E] in +lemma spectral_polytope_convex (p : V → E) (ht : SquaredTriangle p) : + Convex ℝ (spectralPolytope p ht) := by + let := squaredPseudoMetric p ht + exact polytope_convex + +lemma contraction_to_profile (p : V → E) (ht : SquaredTriangle p) + (U : E →L[ℝ] F) (hU : ‖U‖ ≤ 1) (u v : V) : + ‖U (p u)-U (p v)‖^2 ≤ ‖spectralProfile p ht u-spectralProfile p ht v‖ := by + rw [spectral_profile_length,←map_sub] + have h := U.le_opNorm (p u-p v) + have hmul := mul_le_mul_of_nonneg_right hU (norm_nonneg (p u-p v)) + have hn : ‖U (p u-p v)‖ ≤ ‖p u-p v‖ := by linarith + nlinarith [norm_nonneg (U (p u-p v)),norm_nonneg (p u-p v)] + +omit [InnerProductSpace ℝ E] in +lemma squared_euclidean_compact_charge {n m : ℕ} (G : StrongThinTree.MultiGraph n m) + {k : ℕ} (hk : G.EdgeConnected k) (p : Fin n → E) (ht : SquaredTriangle p) : + letI := squaredPseudoMetric p ht + ∀ (q : ℕ) (δ Δ : ℕ → ℝ) + (bags : ∀ i, CompactGeometry.RadialShell.CompactFamily + (fun v : Fin n => profile (plus v)) (δ i) (Δ i)), + (∀ i, i+1 < q → Δ (i+1) ≤ δ i/12) → + (k:ℝ)/4*(∑i ∈ range q, δ i*(∑D ∈ (bags i).bags, (D.card : ℝ))) ≤ + ∑e : Fin m, ‖p (G.left e)-p (G.right e)‖^2 := by + let := squaredPseudoMetric p ht + intro q δ Δ bags hnext + exact CompactGeometry.doubled_compact_bound G hk id q δ Δ bags hnext + +open AssignedGeometry AssignedGeometry.AssignedSequence + +omit [InnerProductSpace ℝ E] in +lemma squared_euclidean_assigned_charge {n m : ℕ} + (H : StrongThinTree.MultiGraph.Hierarchy n) (G : StrongThinTree.MultiGraph n m) + (p : Fin n → E) (ht : SquaredTriangle p) {q : ℝ} (hq : 0 < q) + (hconn : LocallyConnectedReal H G q) : + letI := squaredPseudoMetric p ht + ∀ (ρ : ℝ), 0 < ρ → ρ ≤ 1/1536 → + ∀ (bags : List (AssignedFamily H G (fun v : Fin n => profile (plus v)) (6144/q))), + GeometricAt ρ bags → Ratios ρ bags → Fresh ∅ bags → + (q/8192)*mass bags ≤ ∑e : Fin m, ‖p (G.left e)-p (G.right e)‖^2 := by + let := squaredPseudoMetric p ht + intro ρ hρ hρsmall bags hgeo hR hfresh + have h := assigned_bound (fun v : Fin n => ⟨plus v,rfl⟩) hq hconn hρ hρsmall + bags hgeo hR hfresh + have hd (u v : Fin n) : dist u v = ‖p u-p v‖^2 := rfl + simpa only [CompactGeometry.normDistance,profile_norm_sub,dist_plus,hd] using h + +end +end AlgorithmicThinTrees.MetricProfiles +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/MixedPolynomial.lean b/lean/OAI/Combinatorics/ThinTrees/MixedPolynomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..d0674ef41749fc3687ba610ee788270124a46f45 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/MixedPolynomial.lean @@ -0,0 +1,97 @@ +import OAI.Combinatorics.ThinTrees.DeterminantCalculus + +namespace OAI + +universe uI uD uR + +section + +noncomputable section +open Matrix Polynomial Finset +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [CommRing R] + +def diffProduct (dirs : List I) : MvPolynomial I R →ₗ[R] MvPolynomial I R := + dirs.foldr (fun j f => f.comp (LinearMap.id-(MvPolynomial.pderiv j).toLinearMap)) LinearMap.id + +omit [Fintype I] [Fintype D] [DecidableEq D] in +omit [DecidableEq I] in +@[simp] lemma diffProduct_nil (p : MvPolynomial I R) : diffProduct [] p=p := rfl + +omit [Fintype I] [Fintype D] [DecidableEq D] in +omit [DecidableEq I] in +@[simp] lemma diffProduct_cons (j : I) (dirs : List I) (p : MvPolynomial I R) : + diffProduct (j::dirs) p=diffProduct dirs (p-MvPolynomial.pderiv j p) := rfl + +omit [Fintype I] [Fintype D] [DecidableEq D] in +omit [DecidableEq I] in +lemma diffProduct_foldl (dirs : List I) (p : MvPolynomial I R) : + diffProduct dirs p=dirs.foldl (fun q j => q-MvPolynomial.pderiv j q) p := by + induction dirs generalizing p with + | nil => rfl + | cons j dirs ih => exact ih _ + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma diffProduct_perm {s t : List I} (h : s.Perm t) (p : MvPolynomial I R) : + diffProduct s p=diffProduct t p := by + induction h generalizing p with + | nil => rfl + | cons j h ih => simpa only [diffProduct_cons] using ih _ + | swap i j s => + simp only [diffProduct_cons] + apply congrArg (diffProduct s) + simp only [map_sub] + rw [pderiv_commute p i j] + abel + | trans h₁ h₂ ih₁ ih₂ => exact (ih₁ p).trans (ih₂ p) + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma eval_zero_zeroSub (j : I) (p : MvPolynomial I R) : + MvPolynomial.eval (fun _ => 0) (zeroSub j p)=MvPolynomial.eval (fun _ => 0) p := by + induction p using MvPolynomial.induction_on with + | C r => simp + | add p q hp hq => simpa only [map_add] using congrArg₂ (·+·) hp hq + | mul_X p i hp => + by_cases hi : i=j + · subst i; simp + · simp [hi] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma zeroSub_pderiv {j i : I} (h : i ≠ j) (p : MvPolynomial I R) : + zeroSub j (MvPolynomial.pderiv i p)=MvPolynomial.pderiv i (zeroSub j p) := by + induction p using MvPolynomial.induction_on with + | C r => simp + | add p q hp hq => simp [hp,hq] + | mul_X p k hp => + by_cases hk : k=j + · subst k; simp [Ne.symm h] + · by_cases hki : k=i + · subst k; simp [h,hp] + · simp [hk,hki,hp] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma diffProduct_zeroSub (j : I) (dirs : List I) (h : j ∉ dirs) (p : MvPolynomial I R) : + diffProduct dirs (zeroSub j p)=zeroSub j (diffProduct dirs p) := by + induction dirs generalizing p with + | nil => rfl + | cons i dirs ih => + have hi : i ≠ j := fun he => h (by simp [he]) + have hj : j ∉ dirs := fun hj => h (List.mem_cons_of_mem _ hj) + simp only [diffProduct_cons] + rw [←zeroSub_pderiv hi,←map_sub,ih hj] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma eval_zero_diffProduct_cons (j : I) (dirs : List I) (h : j ∉ dirs) (p : MvPolynomial I R) : + MvPolynomial.eval (fun _ => 0) (diffProduct (j::dirs) p)= + MvPolynomial.eval (fun _ => 0) (diffProduct dirs (zeroDiff j p)) := by + rw [diffProduct_cons,zeroDiff,diffProduct_zeroSub j dirs h,eval_zero_zeroSub] + +def mixedEval (dirs : List I) (M : Matrix D D R) (A : I → Matrix D D R) : R := + MvPolynomial.eval (fun _ => 0) (diffProduct dirs (basePencil M A)) + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Model.lean b/lean/OAI/Combinatorics/ThinTrees/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..d2bf462ca55bef2f0bf1bd0f7aece038c1864866 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Model.lean @@ -0,0 +1,40 @@ +import Mathlib + +namespace OAI + +namespace StrongThinTree + +structure MultiGraph (n m : ℕ) where + left : Fin m → Fin n + right : Fin m → Fin n + loopless : ∀ e, left e ≠ right e + +namespace MultiGraph + +def cut {n m : ℕ} (G : MultiGraph n m) (T : Finset (Fin m)) + (S : Finset (Fin n)) : Finset (Fin m) := + T.filter fun e => (G.left e ∈ S ∧ G.right e ∉ S) ∨ + (G.right e ∈ S ∧ G.left e ∉ S) + +def Connected {n m : ℕ} (G : MultiGraph n m) (T : Finset (Fin m)) : Prop := + ∀ S : Finset (Fin n), S.Nonempty → S ≠ Finset.univ → (G.cut T S).Nonempty + +def SpanningTree {n m : ℕ} (G : MultiGraph n m) (T : Finset (Fin m)) : Prop := + G.Connected T ∧ ∀ e ∈ T, ¬ G.Connected (T.erase e) + +def EdgeConnected {n m : ℕ} (G : MultiGraph n m) (k : ℕ) : Prop := + ∀ S : Finset (Fin n), S.Nonempty → S ≠ Finset.univ → + k ≤ (G.cut Finset.univ S).card + +end MultiGraph + +def MainStatement : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ (k : ℕ), 1 ≤ k → ∀ (n m : ℕ), 2 ≤ n → + ∀ G : MultiGraph n m, G.EdgeConnected k → + ∃ T : Finset (Fin m), G.SpanningTree T ∧ + ∀ S : Finset (Fin n), S.Nonempty → S ≠ Finset.univ → + ((G.cut T S).card : ℝ) ≤ (C / (k : ℝ)) * (G.cut Finset.univ S).card + +end StrongThinTree + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Monicity.lean b/lean/OAI/Combinatorics/ThinTrees/Monicity.lean new file mode 100644 index 0000000000000000000000000000000000000000..bd69b6e4e358da05dc5b6ef1c243e422eb9d9d3b --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Monicity.lean @@ -0,0 +1,56 @@ +import OAI.Combinatorics.ThinTrees.Characteristic + +namespace OAI + +universe uI uD uO + +section + +noncomputable section +open Matrix Polynomial Finset +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {O : Type uO} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [Fintype O] + +lemma mixedChar_mean (j : I) (A : I → Matrix D D ℝ) (w : O → ℝ) + (B : O → Matrix D D ℝ) (hw : ∑o, w o=1) : + mixedChar (Function.update A j (∑o, w o • B o))= + ∑o, w o • mixedChar (Function.update A j (B o)) := by + simpa only [Polynomial.smul_eq_C_mul] using mixedChar_affine j A w B hw + +lemma mixedChar_monic_partial (s : Finset I) (A : I → Matrix D D ℝ) + (w : I → O → ℝ) (u v : I → O → D → ℝ) (hw : ∀i, ∑o, w i o=1) + (hA : ∀i ∈ s, A i=∑o, w i o • Matrix.vecMulVec (u i o) (v i o)) + (hfixed : ∀i, i ∉ s → ∃a b, A i=Matrix.vecMulVec a b) : + (mixedChar A).IsMonicOfDegree (Fintype.card D) := by + induction s using Finset.induction_on generalizing A with + | empty => + rw [mixedChar_rankOne A (fun i => hfixed i (by simp))] + exact ⟨Matrix.charpoly_natDegree_eq_dim _,Matrix.charpoly_monic _⟩ + | @insert j s hj ih => + let B : O → Matrix D D ℝ := fun o => Matrix.vecMulVec (u j o) (v j o) + have hAj : A j=∑o, w j o • B o := hA j (by simp) + have he : mixedChar A=∑o, w j o • mixedChar (Function.update A j (B o)) := by + rw [←mixedChar_mean j A (w j) B (hw j)] + congr 1 + rw [←hAj] + simp + rw [he] + apply Selection.monic_mean _ _ (w j) (hw j) + intro o + apply ih + · intro i hi + rw [Function.update_of_ne (show i ≠ j from fun he => hj (he ▸ hi))] + exact hA i (Finset.mem_insert_of_mem hi) + · intro i hi + by_cases hij : i=j + · subst i + exact ⟨u j o,v j o,by simp [B]⟩ + · rw [Function.update_of_ne hij] + exact hfixed i (by simp [hij,hi]) + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Normalization.lean b/lean/OAI/Combinatorics/ThinTrees/Normalization.lean new file mode 100644 index 0000000000000000000000000000000000000000..41689fbbf082e6bcb5f7d2f99dffd76d1222a547 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Normalization.lean @@ -0,0 +1,79 @@ +import OAI.Combinatorics.ThinTrees.Representation + +namespace OAI + +universe uD + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree +variable {D : Type uD} [Fintype D] [DecidableEq D] +omit [DecidableEq D] in +lemma symmetric_transform_dot (M : Matrix D D ℝ) (hM : Mᵀ=M) (x y : D → ℝ) : + x ⬝ᵥ (M *ᵥ y)=(M *ᵥ x) ⬝ᵥ y := by + rw [dotProduct_mulVec,←mulVec_transpose,hM] +omit [DecidableEq D] in +lemma qform_square (S : Matrix D D ℝ) (hS : Sᵀ=S) (x : D → ℝ) : + qform (S*S) x=(S*ᵥx) ⬝ᵥ (S*ᵥx) := by + rw [qform,←mulVec_mulVec,symmetric_transform_dot S hS] +namespace MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) +lemma laplacian_le_base : G.laplacian univ ≤ G.baseMatrix := by + apply le_add_of_nonneg_right + exact (Matrix.PosSemidef.one.smul (by positivity : (0:ℝ) ≤ (n:ℝ)⁻¹)).nonneg + +lemma normalized_vectors (hn : 0 < n) {X : Matrix (Fin n) (Fin n) ℝ} + (hX : X ∈ G.matrixDomain) (B : Finset (Fin m)) : + ∃a : Fin m → Fin n → ℝ, + (∀x : Fin n → ℝ, (∑e ∈ B, (x ⬝ᵥ a e)^2) ≤ x ⬝ᵥ x) ∧ + (∀e, a e ⬝ᵥ a e=G.resistance X e) ∧ + (∀v : Fin n → ℝ, ∃x : Fin n → ℝ, x ⬝ᵥ x=qform X v ∧ + ∀e, x ⬝ᵥ a e=v ⬝ᵥ G.incidence e) := by + classical + obtain ⟨S,hSH,hSU,hSS⟩ := posDef_sqrt_factors (G.domain_pd hn hX) + let M := S⁻¹ + have hST : Sᵀ=S := by simpa only [conjTranspose_eq_transpose_of_trivial] using hSH.eq + have hMT : Mᵀ=M := by simpa only [M,conjTranspose_eq_transpose_of_trivial] using hSH.inv.eq + have hMS : M*S=1 := Matrix.nonsing_inv_mul S ((Matrix.isUnit_iff_isUnit_det S).mp hSU) + have hSM : S*M=1 := Matrix.mul_nonsing_inv S ((Matrix.isUnit_iff_isUnit_det S).mp hSU) + have hMM : M*M=X⁻¹ := by + apply Eq.symm + apply Matrix.inv_eq_left_inv + rw [←hSS,mul_assoc,←mul_assoc M S S,hMS,one_mul,hMS] + let a : Fin m → Fin n → ℝ := fun e => M*ᵥG.incidence e + refine ⟨a,?_,?_,?_⟩ + · intro x + have he : ∀e, x ⬝ᵥ a e=(M*ᵥx) ⬝ᵥ G.incidence e := fun e => symmetric_transform_dot M hMT x _ + simp_rw [he] + have hb : (∑e ∈ B, ((M*ᵥx) ⬝ᵥ G.incidence e)^2) ≤ + ∑e : Fin m, ((M*ᵥx) ⬝ᵥ G.incidence e)^2 := by + exact sum_le_sum_of_subset_of_nonneg (subset_univ B) (fun _ _ _ => sq_nonneg _) + have heL : (∑e : Fin m, ((M*ᵥx) ⬝ᵥ G.incidence e)^2)=qform (G.laplacian univ) (M*ᵥx) := by + rw [G.laplacian_qform] + apply sum_congr rfl + intro e _ + congr 1 + exact G.eval_incidence (M*ᵥx) e + rw [heL] at hb + have hh := hb.trans (qform_mono (G.laplacian_le_base.trans hX.1) (M*ᵥx)) + rw [←hSS,qform_square S hST,mulVec_mulVec,hSM,one_mulVec] at hh + exact hh + · intro e + change (M*ᵥG.incidence e) ⬝ᵥ (M*ᵥG.incidence e)=qform X⁻¹ (G.incidence e) + rw [←hMM,qform_square M hMT] + · intro v + refine ⟨S*ᵥv,?_,?_⟩ + · rw [←hSS,qform_square S hST] + · intro e + change (S*ᵥv) ⬝ᵥ (M*ᵥG.incidence e)=_ + rw [symmetric_transform_dot M hMT,mulVec_mulVec,hMS,one_mulVec] +end MultiGraph +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Normalization/Algorithm.lean b/lean/OAI/Combinatorics/ThinTrees/Normalization/Algorithm.lean new file mode 100644 index 0000000000000000000000000000000000000000..a924703b8cb7401f9fbbfc2499ff5e8992f0bb7f --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Normalization/Algorithm.lean @@ -0,0 +1,208 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.StoredBits +import OAI.Combinatorics.ThinTrees.Normalization.Packing + +namespace OAI + +/-! Normalization algorithm. -/ + +section + +namespace AlgorithmicThinTrees.Normalization +open Matrix Finset StrongThinTree +open scoped MatrixOrder +variable {m d : ℕ} + +def realColumns (v : Fin m → Fin d → ℚ) : Fin m → Fin d → ℝ := fun e i => (v e i : ℝ) +def weights (s : Fin m → ℚ) : Fin m → ℚ := fun e => (s e)^2 +noncomputable def realWeights (s : Fin m → ℚ) : Fin m → ℝ := fun e => (s e : ℝ)^2 + +def decrement (t : ℚ) : ℚ := 1-t^2 +def threshold (q : ℕ) (t : ℚ) : ℚ := 1/q+4*decrement t + +def testMatrix (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) + (s : Fin m → ℚ) (e : Fin m) : Matrix (Fin d) (Fin d) ℚ := + threshold q t • covariance v (weights s)-(s e)^2 • vecMulVec (v e) (v e) + +def heavy (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) + (s : Fin m → ℚ) : Option (Fin m) := + (List.finRange m).find? (fun e => (KS.W17.rationalNegativeWitness d (testMatrix q t v s e)).isSome) + +def advance (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) + (s : Fin m → ℚ) : Fin m → ℚ := + (heavy q t v s).elim s (fun e => Function.update s e (t*s e)) + +def scalesAt (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) (k : ℕ) : Fin m → ℚ := + (advance q t v)^[k] (fun _ => 1) + +lemma scalesAt_zero (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) : + scalesAt q t v 0=(fun _ => 1) := rfl + +lemma realWeights_one : realWeights (fun _ : Fin m => 1)=(fun _ => (1:ℝ)) := by + funext e + simp only [realWeights,Rat.cast_one,one_pow] + +lemma testMatrix_symm (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) + (s : Fin m → ℚ) (e : Fin m) : (testMatrix q t v s e).IsSymm := by + change (testMatrix q t v s e)ᵀ=testMatrix q t v s e + simp only [testMatrix,covariance,Matrix.transpose_sub,Matrix.transpose_smul, + Matrix.transpose_sum,Matrix.transpose_vecMulVec] + +lemma testMatrix_cast (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) + (s : Fin m → ℚ) (e : Fin m) : + (testMatrix q t v s e).map (fun x : ℚ => (x:ℝ)) = + (threshold q t:ℝ) • covariance (realColumns v) (realWeights s)- + (s e:ℝ)^2 • vecMulVec (realColumns v e) (realColumns v e) := by + ext i j + simp only [testMatrix,covariance,weights,realWeights,realColumns, + Matrix.map_apply,Matrix.sub_apply,Matrix.smul_apply,Matrix.sum_apply, + Matrix.vecMulVec_apply,smul_eq_mul,Rat.cast_sub,Rat.cast_mul,Rat.cast_pow,Rat.cast_sum] + +lemma heavy_none (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) + (s : Fin m → ℚ) (hs : ∀e, 0 < s e) + (hA : (covariance (realColumns v) (realWeights s)).PosDef) + (ht : 0 < threshold q t) : + heavy q t v s=none ↔ ∀e, leverage (realColumns v) (realWeights s) e ≤ (threshold q t:ℝ) := by + rw [heavy,List.find?_eq_none] + simp only [List.mem_finRange,forall_const,Option.isSome_iff_ne_none,not_not] + apply forall_congr' + intro e + rw [KS.W17.rationalNegativeWitness_none_iff_psd _ _ (testMatrix_symm ..),testMatrix_cast] + exact (leverage_test (realColumns v) (realWeights s) e hA + (sq_pos_of_pos (by exact_mod_cast hs e)) (by exact_mod_cast ht)).symm + +lemma heavy_some (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) + (s : Fin m → ℚ) (hs : ∀e, 0 < s e) + (hA : (covariance (realColumns v) (realWeights s)).PosDef) + (ht : 0 < threshold q t) {e : Fin m} (he : heavy q t v s=some e) : + (threshold q t:ℝ) < leverage (realColumns v) (realWeights s) e := by + have hh := List.find?_some he + rw [Option.isSome_iff_ne_none] at hh + simp only [ne_eq, KS.W17.rationalNegativeWitness_none_iff_psd _ _ (testMatrix_symm ..),testMatrix_cast] at hh + exact lt_of_not_ge (fun hc => hh ((leverage_test (realColumns v) (realWeights s) e hA + (sq_pos_of_pos (by exact_mod_cast hs e)) (by exact_mod_cast ht)).mp hc)) + +lemma update_realWeights (s : Fin m → ℚ) (t : ℚ) (e : Fin m) : + realWeights (Function.update s e (t*s e))=shrink (decrement t:ℝ) (realWeights s) e := by + funext f + by_cases h : f=e + · subst f + simp only [realWeights,shrink,Function.update_self,decrement,Rat.cast_sub,Rat.cast_one,Rat.cast_pow,Rat.cast_mul] + ring + · simp only [realWeights,shrink,Function.update_of_ne h] + +lemma advance_box (q : ℕ) {t : ℚ} (ht : 0 < t) (ht1 : t ≤ 1) + (v : Fin m → Fin d → ℚ) (s : Fin m → ℚ) + (hs : ∀e, 0 < s e ∧ s e ≤ 1) : ∀e, 0 < advance q t v s e ∧ advance q t v s e ≤ 1 := by + unfold advance + cases he : heavy q t v s with + | none => simpa only [Option.elim_none] using hs + | some f => + intro e + simp only [Option.elim_some] + by_cases h : e=f + · subst e + simp only [Function.update_self] + exact ⟨mul_pos ht (hs f).1,(mul_le_of_le_one_left (hs f).1.le ht1).trans (hs f).2⟩ + · simpa only [Function.update_of_ne h] using hs e + +lemma scalesAt_box (q : ℕ) {t : ℚ} (ht : 0 < t) (ht1 : t ≤ 1) + (v : Fin m → Fin d → ℚ) (k : ℕ) : ∀e, 0 < scalesAt q t v k e ∧ scalesAt q t v k e ≤ 1 := by + induction k with + | zero => simp [scalesAt] + | succ k ih => + change ∀e, 0 < ((advance q t v)^[k+1] (fun _ => 1)) e ∧ + ((advance q t v)^[k+1] (fun _ => 1)) e ≤ 1 + rw [Function.iterate_succ_apply'] + exact advance_box q ht ht1 v _ ih + +lemma realWeights_box {s : Fin m → ℚ} (hs : ∀e, 0 < s e ∧ s e ≤ 1) : + (∀e, 0 < realWeights s e) ∧ (∀e, realWeights s e ≤ 1) := by + have hr (e : Fin m) : (0:ℝ) < s e ∧ (s e:ℝ) ≤ 1 := by exact_mod_cast hs e + constructor + · intro e;exact sq_pos_of_pos (hr e).1 + · intro e;exact pow_le_one₀ (hr e).1.le (hr e).2 + +lemma scalesAt_terminates (q : ℕ) {t : ℚ} (ht : 0 < t) (ht1 : t < 1) + (hδ : 0 < decrement t) (hδ1 : decrement t ≤ 1/2) + (v : Fin m → Fin d → ℚ) (B : ContainedPacking (realColumns v) q) + (hsize : ∀e, realColumns v e ⬝ᵥ realColumns v e ≤ 2) (N : ℕ) + (hN : 2*(m:ℝ) < N*(decrement t:ℝ)^2) : + heavy q t v (scalesAt q t v N)=none := by + have hq : 1 ≤ q := B.positive + have hth : 0 < threshold q t := by + unfold threshold + have hq0 : (0:ℚ) + right + rw [scalesAt_zero,realWeights_one] + simpa only [Nat.cast_zero,zero_mul,sub_zero,Fintype.card_fin] using B.initial_gap hsize + | succ k ih => + have heq : scalesAt q t v (k+1)=advance q t v (scalesAt q t v k) := + Function.iterate_succ_apply' _ _ _ + cases hh : heavy q t v (scalesAt q t v k) with + | none => + left + rw [heq,advance,hh,Option.elim_none,hh] + | some e => + right + have hi := ih.resolve_left (by rw [hh];simp) + have hp := B.covariance_posDef _ (hbox k).1 + have hheavy := heavy_some q t v _ (fun e => (scalesAt_box q ht ht1.le v k e).1) hp hth hh + have hstep : scalesAt q t v (k+1)=Function.update (scalesAt q t v k) e + (t*scalesAt q t v k e) := by rw [heq,advance,hh,Option.elim_some] + have hweights : realWeights (scalesAt q t v (k+1)) = + shrink (decrement t:ℝ) (realWeights (scalesAt q t v k)) e := by + rw [hstep,update_realWeights] + have hp' := B.covariance_posDef _ (hbox (k+1)).1 + rw [hweights] at hp' + have hd := objective_drop q hq (realColumns v) _ (hbox k).1 e (decrement t:ℝ) + (by exact_mod_cast hδ) (by + have hh : (decrement t:ℝ) ≤ (((1:ℚ)/2:ℚ):ℝ) := Rat.cast_le.mpr hδ1 + norm_num at hh ⊢ + exact hh) hp hp' (by + simpa only [threshold,Rat.cast_add,Rat.cast_div,Rat.cast_one,Rat.cast_natCast, + Rat.cast_mul,Rat.cast_ofNat] using hheavy) + rw [hweights] + push_cast + nlinarith only [hi,hd] + rcases hbound N with h|h + · exact h + · have h0 := B.objective_nonneg _ (hbox N).1 (hbox N).2 + linarith only [h,h0,hN] + +lemma scalesAt_parts (q : ℕ) (t : ℚ) (v : Fin m → Fin d → ℚ) + {b : ℕ} (ht : CurrentKS.RationalBits.Parts b t) (k : ℕ) : + ∀e, CurrentKS.RationalBits.Parts (k*b) (scalesAt q t v k e) := by + induction k with + | zero => intro e;norm_num [scalesAt,CurrentKS.RationalBits.Parts] + | succ k ih => + intro e + change CurrentKS.RationalBits.Parts ((k+1)*b) (((advance q t v)^[k+1] (fun _ => 1)) e) + rw [Function.iterate_succ_apply'] + change CurrentKS.RationalBits.Parts ((k+1)*b) (advance q t v (scalesAt q t v k) e) + unfold advance + cases hh : heavy q t v (scalesAt q t v k) with + | none => exact (ih e).mono (Nat.mul_le_mul_right b (Nat.le_succ k)) + | some f => + simp only [Option.elim_some] + by_cases h : e=f + · subst e + simpa only [Function.update_self,Nat.add_mul,Nat.one_mul,Nat.add_comm] using ht.mul (ih f) + · simpa only [Function.update_of_ne h] using (ih e).mono (Nat.mul_le_mul_right b (Nat.le_succ k)) + +def multiplier (r : ℕ) : ℚ := 1-1/(16*(r:ℚ)^2) +def normalizationLength (m r : ℕ) : ℕ := (2*m+1)*256*r^4 +def normalizedScales (q r : ℕ) (v : Fin m → Fin d → ℚ) : Fin m → ℚ := + scalesAt q (multiplier r) v (normalizationLength m r) + +end AlgorithmicThinTrees.Normalization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Normalization/Descent.lean b/lean/OAI/Combinatorics/ThinTrees/Normalization/Descent.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d019ef5ffe1f94abefe96a17d9d64879df63ee7 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Normalization/Descent.lean @@ -0,0 +1,218 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Encoding.DenseCanonicalParser +import OAI.Analysis.MatrixSigning.Optimization.Coordinates +import OAI.Analysis.MatrixSigning.Realization.FaceQueryRealization +import OAI.Combinatorics.ThinTrees.Representation + +namespace OAI + +/-! Normalization descent. -/ + +section + +namespace AlgorithmicThinTrees.Normalization +open Matrix Finset StrongThinTree +open scoped MatrixOrder + +section Covariance +variable {E I : Type*} [normalizationFintypeE : Fintype E] + [normalizationDecidableEqE : DecidableEq E] [normalizationFintypeI : Fintype I] + [normalizationDecidableEqI : DecidableEq I] + +def covariance {K : Type*} [Field K] (v : E → I → K) (a : E → K) : Matrix I I K := + ∑e, a e • vecMulVec (v e) (v e) + +noncomputable def leverage (v : E → I → ℝ) (a : E → ℝ) (e : E) : ℝ := + a e * (v e ⬝ᵥ ((covariance v a)⁻¹ *ᵥ v e)) + +noncomputable def objective (q : ℕ) (v : E → I → ℝ) (a : E → ℝ) : ℝ := + Real.log (covariance v a).det-(∑e, Real.log (a e))/q + +def shrink {K : Type*} [Field K] (δ : K) (a : E → K) (e : E) : E → K := + Function.update a e ((1-δ)*a e) + +omit normalizationFintypeE in +lemma shrink_pos [_shrinkFintypeE : Fintype E] {δ : ℝ} (hδ : δ < 1) + {a : E → ℝ} (ha : ∀e, 0 < a e) (e : E) : + ∀f, 0 < shrink δ a e f := by + intro f + by_cases h : f=e + · subst f + simpa [shrink] using mul_pos (sub_pos.mpr hδ) (ha e) + · simpa only [shrink,Function.update_of_ne h] using ha f + +omit normalizationFintypeI normalizationDecidableEqI in +lemma covariance_shrink [_covarianceShrinkFintypeI : Fintype I] + [_covarianceShrinkDecidableEqI : DecidableEq I] {K : Type*} [Field K] (v : E → I → K) + (a : E → K) (e : E) (δ : K) : + covariance v (shrink δ a e) = covariance v a - (δ*a e) • vecMulVec (v e) (v e) := by + classical + have h : (fun f => shrink δ a e f • vecMulVec (v f) (v f)) = + Function.update (fun f => a f • vecMulVec (v f) (v f)) e + (((1-δ)*a e) • vecMulVec (v e) (v e)) := by + funext f + by_cases he : f=e + · subst f; simp [shrink] + · simp only [shrink,Function.update_of_ne he] + unfold covariance + rw [h,Finset.sum_update_of_mem (mem_univ e),sdiff_singleton_eq_erase] + rw [←Finset.add_sum_erase univ (fun f => a f • vecMulVec (v f) (v f)) (mem_univ e)] + module + +lemma log_shrink_sum {δ : ℝ} (hδ : δ < 1) {a : E → ℝ} (ha : ∀e, 0 < a e) (e : E) : + (∑f, Real.log (shrink δ a e f)) = (∑f, Real.log (a f))+Real.log (1-δ) := by + have h : (fun f => Real.log (shrink δ a e f)) = + Function.update (fun f => Real.log (a f)) e (Real.log ((1-δ)*a e)) := by + funext f + by_cases he : f=e + · subst f; simp [shrink] + · simp only [shrink,Function.update_of_ne he] + rw [h,Finset.sum_update_of_mem (mem_univ e),sdiff_singleton_eq_erase, + Real.log_mul (sub_pos.mpr hδ).ne' (ha e).ne'] + rw [←Finset.add_sum_erase univ (fun f => Real.log (a f)) (mem_univ e)] + ring + +lemma det_rank_one (A : Matrix I I ℝ) (hA : A.PosDef) (v : I → ℝ) (c : ℝ) : + (A+c • vecMulVec v v).det=A.det*(1+c*(v ⬝ᵥ (A⁻¹ *ᵥ v))) := by + have he : (Matrix.replicateCol Unit (c • v) * Matrix.replicateRow Unit v)=c • vecMulVec v v := by + ext i j + simp [Matrix.mul_apply,smul_eq_mul,Matrix.vecMulVec_apply] + ring + rw [←he,Matrix.det_add_replicateCol_mul_replicateRow + ((Matrix.isUnit_iff_isUnit_det A).mp hA.isUnit),Matrix.det_unique (n := Unit)] + congr 1 + simp only [Matrix.add_apply,Matrix.one_apply_eq] + change 1+(v ᵥ* A⁻¹) ⬝ᵥ (c • v) = 1+c*(v ⬝ᵥ (A⁻¹ *ᵥ v)) + rw [dotProduct_smul,←Matrix.dotProduct_mulVec,smul_eq_mul] + +lemma det_shrink (v : E → I → ℝ) (a : E → ℝ) (e : E) (δ : ℝ) + (hA : (covariance v a).PosDef) : + (covariance v (shrink δ a e)).det=(covariance v a).det*(1-δ*leverage v a e) := by + rw [covariance_shrink,sub_eq_add_neg,←neg_smul, + det_rank_one _ hA (v e) (-(δ*a e)),leverage] + ring + +omit normalizationDecidableEqE in +lemma leverage_test [_leverageTestDecidableEqE : DecidableEq E] + (v : E → I → ℝ) (a : E → ℝ) (e : E) + (hA : (covariance v a).PosDef) (ha : 0 < a e) {t : ℝ} (ht : 0 < t) : + leverage v a e ≤ t ↔ (t • covariance v a - a e • vecMulVec (v e) (v e)).PosSemidef := by + have h := resistance_order hA (Real.sqrt (a e) • v e) ht + have hs : Real.sqrt (a e)*Real.sqrt (a e)=a e := Real.mul_self_sqrt ha.le + simpa only [leverage,Matrix.mulVec_smul,smul_dotProduct,dotProduct_smul,smul_eq_mul, + ←mul_assoc,hs,Matrix.smul_vecMulVec,Matrix.vecMulVec_smul,smul_smul] using h + +lemma neg_log_one_sub {δ : ℝ} (_hδ : 0 ≤ δ) (hδ1 : δ ≤ 1/2) : + -Real.log (1-δ) ≤ δ+2*δ^2 := by + have hp : 0 < 1-δ := by linarith only [hδ1] + have hh := Real.log_le_sub_one_of_pos (inv_pos.mpr hp) + rw [Real.log_inv] at hh + have hfrac : (1-δ)⁻¹-1 ≤ δ+2*δ^2 := by + rw [inv_eq_one_div,div_sub_one hp.ne',div_le_iff₀ hp] + nlinarith [sq_nonneg δ,mul_nonneg (sq_nonneg δ) (show 0 ≤ 1-2*δ by linarith)] + exact hh.trans hfrac + +lemma objective_drop (q : ℕ) (hq : 1 ≤ q) (v : E → I → ℝ) + (a : E → ℝ) (ha : ∀e, 0 < a e) (e : E) (δ : ℝ) + (hδ : 0 < δ) (hδ1 : δ ≤ 1/2) + (hA : (covariance v a).PosDef) (hA' : (covariance v (shrink δ a e)).PosDef) + (he : 1/(q:ℝ)+4*δ < leverage v a e) : + objective q v (shrink δ a e) ≤ objective q v a-δ^2 := by + have hδlt : δ < 1 := by linarith only [hδ1] + have hd := det_shrink v a e δ hA + have hp : 0 < 1-δ*leverage v a e := by + have hh := hA'.det_pos + rw [hd] at hh + exact (mul_pos_iff_of_pos_left hA.det_pos).mp hh + have hlog := Real.log_le_sub_one_of_pos hp + have hneg := neg_log_one_sub hδ.le hδ1 + have hqR : (1:ℝ) ≤ q := by exact_mod_cast hq + have hq0 : (0:ℝ) < q := by linarith only [hqR] + have hqinv : 1/(q:ℝ) ≤ 1 := (div_le_one hq0).mpr hqR + have hobj : objective q v (shrink δ a e) = objective q v a+ + Real.log (1-δ*leverage v a e)-Real.log (1-δ)/q := by + unfold objective + rw [hd,Real.log_mul hA.det_pos.ne' hp.ne',log_shrink_sum hδlt ha e] + ring + rw [hobj] + have hmain := mul_lt_mul_of_pos_left he hδ + have hdiv := div_le_div_of_nonneg_right hneg hq0.le + have hrem : (δ+2*δ^2)/(q:ℝ) ≤ δ/q+2*δ^2 := by + rw [add_div] + apply add_le_add_right + exact (div_le_self (by positivity) hqR) + have hcancel : δ*(1/(q:ℝ))=δ/q := by ring + rw [neg_div] at hdiv + rw [mul_add,hcancel] at hmain + nlinarith only [hmain,hlog,hdiv,hrem,sq_nonneg δ] + +lemma logdet_le_trace {A : Matrix I I ℝ} (hA : A.PosDef) : Real.log A.det ≤ A.trace := by + rw [hA.isHermitian.det_eq_prod_eigenvalues,hA.isHermitian.trace_eq_sum_eigenvalues] + simp only [RCLike.ofReal_real_eq_id, id_eq] + rw [Real.log_prod (fun i _ => (hA.eigenvalues_pos i).ne')] + apply sum_le_sum + intro i _ + exact (Real.log_le_sub_one_of_pos (hA.eigenvalues_pos i)).trans (by linarith) + +end Covariance + +section Bases +variable {E : Type*} [Fintype E] [basisPackingDecidableEqE : DecidableEq E] {q d : ℕ} + +structure BasisPacking (v : E → Fin d → ℝ) (q : ℕ) where + positive : 0 < q + edges : (Fin q × Fin d) ≃ E + invertible : ∀t, IsUnit (Matrix.of (fun i j => v (edges (t,j)) i)) + determinant : ∀t, 1 ≤ (Matrix.det (fun i j => v (edges (t,j)) i))^2 + +namespace BasisPacking +variable {v : E → Fin d → ℝ} (B : BasisPacking v q) +noncomputable def matrices (t : Fin q) : Matrix (Fin d) (Fin d) ℝ := fun i j => v (B.edges (t,j)) i +noncomputable def logWeights (a : E → ℝ) : EuclideanSpace ℝ (Fin q × Fin d) := + WithLp.toLp 2 (fun e => Real.log (a (B.edges e))) + +omit basisPackingDecidableEqE in +lemma covariance_eq [_covarianceEqDecidableEqE : DecidableEq E] + (a : E → ℝ) (ha : ∀e, 0 < a e) : + covariance v a=packingCov B.matrices (B.logWeights a) := by + rw [packingCov_eq_sum,covariance,←B.edges.sum_comp] + apply sum_congr rfl + intro e _ + simp only [logWeights,PiLp.toLp_apply,Real.exp_log (ha _),matrices] + +include B + +lemma covariance_posDef (a : E → ℝ) (ha : ∀e, 0 < a e) : (covariance v a).PosDef := by + have : Nonempty (Fin q) := Fin.pos_iff_nonempty.mp B.positive + rw [B.covariance_eq a ha] + exact packingCov_posDef B.matrices B.invertible _ + +lemma objective_nonneg (a : E → ℝ) (ha : ∀e, 0 < a e) : 0 ≤ objective q v a := by + have : Nonempty (Fin q) := Fin.pos_iff_nonempty.mp B.positive + have hn : ∀t, 0 ≤ Real.log ((B.matrices t).det^2) := + fun t => Real.log_nonneg (B.determinant t) + have hb := packingObjective_bddBelow B.matrices B.invertible (B.logWeights a) + have h0 : 0 ≤ (∑t, Real.log ((B.matrices t).det^2))/(Fintype.card (Fin q):ℝ) := + div_nonneg (sum_nonneg (fun t _ => hn t)) (Nat.cast_nonneg _) + apply (h0.trans hb).trans_eq + unfold packingObjective objective + rw [←B.covariance_eq a ha,Fintype.card_fin] + congr 2 + exact B.edges.sum_comp (fun e => Real.log (a e)) + +lemma initial_gap (hsize : ∀e, v e ⬝ᵥ v e ≤ 2) : + objective q v (fun _ => 1) ≤ 2*Fintype.card E := by + have hh := logdet_le_trace (B.covariance_posDef (fun _ => 1) (by simp)) + simp only [objective,Real.log_one,sum_const_zero,zero_div,sub_zero] + apply hh.trans + simp only [covariance,one_smul,Matrix.trace_sum,Matrix.trace_vecMulVec] + calc + _ ≤ ∑_e : E, (2:ℝ) := sum_le_sum (fun e _ => hsize e) + _ = _ := by simp [mul_comm] + +end BasisPacking +end Bases +end AlgorithmicThinTrees.Normalization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Normalization/Packing.lean b/lean/OAI/Combinatorics/ThinTrees/Normalization/Packing.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c3b07447c3dc87262a9aa0ac803d407fb1c2a15 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Normalization/Packing.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Normalization.Descent + +namespace OAI + +/-! Normalization packing. -/ + +section + +namespace AlgorithmicThinTrees.Normalization +open Matrix Finset StrongThinTree +open scoped MatrixOrder + +lemma covariance_posSemidef {E I : Type*} [Fintype E] [Fintype I] + (v : E → I → ℝ) (a : E → ℝ) (ha : ∀e, 0 ≤ a e) : (covariance v a).PosSemidef := by + apply Matrix.posSemidef_sum + intro e _ + have h : (vecMulVec (v e) (v e)).PosSemidef := by + simpa only [star_trivial] using Matrix.posSemidef_vecMulVec_self_star (v e) + exact h.smul (ha e) + +lemma covariance_embedding {E J I : Type*} [Fintype E] [DecidableEq E] + [Fintype J] [DecidableEq J] [Fintype I] + (f : J ↪ E) (v : E → I → ℝ) (a : E → ℝ) : + covariance v a=covariance (v ∘ f) (a ∘ f)+ + ∑e ∈ univ \ univ.map f, a e • vecMulVec (v e) (v e) := by + unfold covariance + simp only [Function.comp_apply] + rw [←Finset.sum_map (f := fun e => a e • vecMulVec (v e) (v e))] + exact (Finset.sum_sdiff (f := fun e => a e • vecMulVec (v e) (v e)) (subset_univ (univ.map f))).symm.trans (add_comm ..) + +structure ContainedPacking {E : Type*} {d : ℕ} (v : E → Fin d → ℝ) (q : ℕ) where + positive : 0 < q + edges : (Fin q × Fin d) ↪ E + invertible : ∀t, IsUnit (Matrix.of (fun i j => v (edges (t,j)) i)) + determinant : ∀t, 1 ≤ (Matrix.det (fun i j => v (edges (t,j)) i))^2 + +namespace ContainedPacking +variable {E : Type*} [Fintype E] [DecidableEq E] {q d : ℕ} +variable {v : E → Fin d → ℝ} (B : ContainedPacking v q) + +noncomputable def full : BasisPacking (v ∘ B.edges) q := + ⟨B.positive,Equiv.refl _,B.invertible,B.determinant⟩ + +include B +lemma extra_posSemidef (a : E → ℝ) (ha : ∀e, 0 ≤ a e) : + (∑e ∈ univ \ univ.map B.edges, a e • vecMulVec (v e) (v e)).PosSemidef := by + apply Matrix.posSemidef_sum + intro e _ + have h : (vecMulVec (v e) (v e)).PosSemidef := by + simpa only [star_trivial] using Matrix.posSemidef_vecMulVec_self_star (v e) + exact h.smul (ha e) + +lemma covariance_posDef (a : E → ℝ) (ha : ∀e, 0 < a e) : (covariance v a).PosDef := by + rw [covariance_embedding B.edges v a] + exact (B.full.covariance_posDef (a ∘ B.edges) (fun e => ha _)).add_posSemidef + (B.extra_posSemidef a (fun e => (ha e).le)) + +lemma objective_nonneg (a : E → ℝ) (ha : ∀e, 0 < a e) (ha1 : ∀e, a e ≤ 1) : + 0 ≤ objective q v a := by + have hb := B.full.objective_nonneg (a ∘ B.edges) (fun e => ha _) + have hpd := B.full.covariance_posDef (a ∘ B.edges) (fun e => ha _) + have hd : (covariance (v ∘ B.edges) (a ∘ B.edges)).det ≤ (covariance v a).det := by + rw [covariance_embedding B.edges v a] + exact det_le_det_add_of_posSemidef hpd (B.extra_posSemidef a (fun e => (ha e).le)) + have hl := Real.log_le_log hpd.det_pos hd + have hlogs : (∑e, Real.log (a e)) ≤ ∑j, Real.log (a (B.edges j)) := by + rw [←Finset.sum_map (f := fun e => Real.log (a e))] + have hsum := Finset.sum_sdiff (f := fun e => Real.log (a e)) (subset_univ (univ.map B.edges)) + have hnonpos : ∑e ∈ univ \ univ.map B.edges, Real.log (a e) ≤ 0 := + sum_nonpos (fun e _ => Real.log_nonpos (ha e).le (ha1 e)) + linarith only [hsum,hnonpos] + have hdiv := div_le_div_of_nonneg_right hlogs (Nat.cast_nonneg q : (0:ℝ)≤q) + unfold objective at hb ⊢ + exact hb.trans (sub_le_sub hl hdiv) + +lemma initial_gap (hsize : ∀e, v e ⬝ᵥ v e ≤ 2) : + objective q v (fun _ => 1) ≤ 2*Fintype.card E := by + have hh := logdet_le_trace (B.covariance_posDef (fun _ => 1) (by simp)) + simp only [objective,Real.log_one,sum_const_zero,zero_div,sub_zero] + apply hh.trans + simp only [covariance,one_smul,Matrix.trace_sum,Matrix.trace_vecMulVec] + calc + _ ≤ ∑_e : E, (2:ℝ) := sum_le_sum (fun e _ => hsize e) + _ = _ := by simp [mul_comm] + +end ContainedPacking +end AlgorithmicThinTrees.Normalization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Normalization/Parameters.lean b/lean/OAI/Combinatorics/ThinTrees/Normalization/Parameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a8970a823e9d420d94b27074f9ad6526d9dc6ca --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Normalization/Parameters.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Normalization.Algorithm + +namespace OAI + +/-! Normalization parameters. -/ + +section + +namespace AlgorithmicThinTrees.Normalization +open Matrix Finset StrongThinTree +open scoped MatrixOrder + +lemma multiplier_bounds (r : ℕ) (hr : 1 ≤ r) : + 0 < multiplier r ∧ multiplier r < 1 ∧ + 0 < decrement (multiplier r) ∧ decrement (multiplier r) ≤ 1/2 ∧ + 1/(16*(r:ℚ)^2) ≤ decrement (multiplier r) ∧ + decrement (multiplier r) ≤ 1/(8*(r:ℚ)^2) := by + have hr1 : (1:ℚ) ≤ r := by exact_mod_cast hr + have hr2 : (1:ℚ) ≤ (r:ℚ)^2 := one_le_pow₀ hr1 + have hd : (0:ℚ) < 16*(r:ℚ)^2 := by positivity + have hx : (0:ℚ) < 1/(16*(r:ℚ)^2) := div_pos zero_lt_one hd + have hx1 : (1:ℚ)/(16*(r:ℚ)^2) ≤ 1/16 := by + rw [div_le_div_iff₀ hd (by norm_num : (0:ℚ)<16)] + linarith only [hr2] + have he : 1/(8*(r:ℚ)^2)=2*(1/(16*(r:ℚ)^2)) := by ring + unfold multiplier decrement + rw [he] + refine ⟨?_,?_,?_,?_,?_,?_⟩ <;> nlinarith [sq_nonneg (1/(16*(r:ℚ)^2))] + +lemma normalizationLength_suffices (m r : ℕ) (hr : 1 ≤ r) : + 2*(m:ℝ) < (normalizationLength m r:ℝ)*(decrement (multiplier r):ℝ)^2 := by + have hr0 : (0:ℝ) < r := by exact_mod_cast (show 0 < r by omega) + have hδ := (multiplier_bounds r hr).2.2.2.2.1 + have hδR : 1/(16*(r:ℝ)^2) ≤ (decrement (multiplier r):ℝ) := by + have hh := (Rat.cast_le (K := ℝ)).mpr hδ + simpa only [Rat.cast_div,Rat.cast_mul,Rat.cast_ofNat,Rat.cast_pow, + Rat.cast_natCast,Rat.cast_one] using hh + have hsq := pow_le_pow_left₀ (by positivity : (0:ℝ) ≤ 1/(16*(r:ℝ)^2)) hδR 2 + have hN : (normalizationLength m r:ℝ)=(2*(m:ℝ)+1)*256*(r:ℝ)^4 := by + simp only [normalizationLength,Nat.cast_mul,Nat.cast_add,Nat.cast_ofNat,Nat.cast_one,Nat.cast_pow] + have he : (normalizationLength m r:ℝ)*(1/(16*(r:ℝ)^2))^2=2*(m:ℝ)+1 := by + rw [hN] + field_simp [ne_of_gt hr0] + ring + have hh := mul_le_mul_of_nonneg_left hsq (Nat.cast_nonneg (normalizationLength m r) : (0:ℝ) ≤ _) + rw [he] at hh + linarith only [hh] + +lemma threshold_le (q r : ℕ) (hq : 0 < q) (hqr : q ≤ r) : + (threshold q (multiplier r):ℝ) ≤ (1+4/(r:ℝ))/(q:ℝ) := by + have hr : 1 ≤ r := Nat.le_trans hq hqr + have hqR : (0:ℝ) < q := by exact_mod_cast hq + have hrR : (0:ℝ) < r := by exact_mod_cast (show 0 < r by omega) + have hqrR : (q:ℝ) ≤ r := by exact_mod_cast hqr + have hδ := (multiplier_bounds r hr).2.2.2.2.2 + have hδR : (decrement (multiplier r):ℝ) ≤ 1/(8*(r:ℝ)^2) := by + have hh := (Rat.cast_le (K := ℝ)).mpr hδ + simpa only [Rat.cast_div,Rat.cast_mul,Rat.cast_ofNat,Rat.cast_pow, + Rat.cast_natCast,Rat.cast_one] using hh + have hh : 4*(decrement (multiplier r):ℝ) ≤ 4/((r:ℝ)*q) := by + apply (mul_le_mul_of_nonneg_left hδR (by norm_num : (0:ℝ) ≤ 4)).trans + have hc : (r:ℝ)*q ≤ 8*(r:ℝ)^2 := by nlinarith only [mul_le_mul_of_nonneg_left hqrR hrR.le,sq_nonneg (r:ℝ)] + have hi := one_div_le_one_div_of_le (mul_pos hrR hqR) hc + calc + 4*(1/(8*(r:ℝ)^2)) ≤ 4*(1/((r:ℝ)*q)) := mul_le_mul_of_nonneg_left hi (by norm_num) + _ = _ := by ring + simp only [threshold,Rat.cast_add,Rat.cast_div,Rat.cast_one,Rat.cast_natCast, + Rat.cast_mul,Rat.cast_ofNat] + have he : (1+4/(r:ℝ))/(q:ℝ)=1/(q:ℝ)+4/((r:ℝ)*q) := by ring + rw [he] + linarith only [hh] + +lemma multiplier_parts (r : ℕ) : + CurrentKS.RationalBits.Parts (5+2*r.size) (multiplier r) := by + have hr := CurrentKS.RationalBits.natCast_parts r + have h16 : CurrentKS.RationalBits.Parts 4 (16:ℚ) := by norm_num [CurrentKS.RationalBits.Parts] + have hh := CurrentKS.RationalBits.parts_one.add ((h16.mul (hr.mul hr)).inv.neg) + convert hh using 1 + · omega + · simp only [multiplier,sub_eq_add_neg,one_div,pow_two] + +theorem normalizedScales_correct {m d q r : ℕ} (v : Fin m → Fin d → ℚ) + (B : ContainedPacking (realColumns v) q) (hqr : q ≤ r) + (hsize : ∀e, realColumns v e ⬝ᵥ realColumns v e ≤ 2) : + let s := normalizedScales q r v + (∀e, 0 < s e ∧ s e ≤ 1) ∧ + (∀e, leverage (realColumns v) (realWeights s) e ≤ (1+4/(r:ℝ))/(q:ℝ)) ∧ + (∀e, CurrentKS.RationalBits.Parts (normalizationLength m r*(5+2*r.size)) (s e)) := by + have hr : 1 ≤ r := B.positive.trans_le hqr + obtain ⟨ht,ht1,hδ,hδ1,hδlower,hδupper⟩ := multiplier_bounds r hr + have hbox := scalesAt_box q ht ht1.le v (normalizationLength m r) + have hA := B.covariance_posDef _ (realWeights_box hbox).1 + have hq0 : (0:ℚ) < q := by exact_mod_cast B.positive + have hth : 0 < threshold q (multiplier r) := by unfold threshold; positivity + have hN := scalesAt_terminates q ht ht1 hδ hδ1 v B hsize + (normalizationLength m r) (normalizationLength_suffices m r hr) + refine ⟨hbox,?_,scalesAt_parts q _ v (multiplier_parts r) _⟩ + intro e + exact (((heavy_none q (multiplier r) v _ (fun e => (hbox e).1) hA hth).mp hN) e).trans + (threshold_le q r B.positive hqr) + +end AlgorithmicThinTrees.Normalization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Normalization/Realization.lean b/lean/OAI/Combinatorics/ThinTrees/Normalization/Realization.lean new file mode 100644 index 0000000000000000000000000000000000000000..59c2409765f344ac4bba6a7998ae73eab846bb1e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Normalization/Realization.lean @@ -0,0 +1,351 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialCurvature +import OAI.Analysis.MatrixSigning.Complexity.PolynomialExplicit +import OAI.Analysis.MatrixSigning.Complexity.PolynomialFind +import OAI.Analysis.MatrixSigning.Complexity.PolynomialMatrixFold +import OAI.Analysis.MatrixSigning.Complexity.PolynomialValueQuery +import OAI.Analysis.MatrixSigning.Realization.VarianceRealization +import OAI.Combinatorics.ThinTrees.Normalization.Algorithm + +namespace OAI + +/-! Normalization realization. -/ + +section + + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 + +variable {β : Type*} + +def selectFlagged (eb : β → Word) : + Realizes (prodCode eb (listCode (prodCode boolCode eb))) eb + (fun p => (p.2.find? Prod.fst).elim p.1 Prod.snd) := + let ec := prodCode boolCode eb + let ctx := first eb (listCode ec) + let test := (second eb ec).then (first boolCode eb) + let value := (second eb ec).then (second boolCode eb) + ((ctx.both (identity (prodCode eb (listCode ec)))).then + (test.findValue value)).congr (fun _ => rfl) + +instance poly_selectFlagged (eb : β → Word) : PolyTime (selectFlagged eb) := by + unfold selectFlagged + infer_instance + +lemma find_map_flagged {α β : Type*} (xs : List α) (p : α → Bool) + (f : α → β) (b : β) : + (((xs.map fun a => (p a,f a)).find? Prod.fst).elim b Prod.snd)= + (xs.find? p).elim b f := by + induction xs with + | nil => rfl + | cons a xs ih => + simp only [List.map_cons,List.find?_cons] + cases h : p a <;> simp_all +end CurrentKS.Realization + +namespace AlgorithmicThinTrees.Normalization.Stack +open CurrentKS CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 +open Matrix +local notation "X" => NaturalPolynomial.variable + +structure Params where + d : ℕ + m : ℕ + q : ℕ + t : ℚ + v : Fin m → Fin d → ℚ + +abbrev paramsDataCode := + prodCode natCode (prodCode natCode (prodCode ratCode matrixCode)) +def Params.data (p : Params) := (p.d,(p.q,(p.t,matrixData p.v))) +def paramsCode (p : Params) : Word := paramsDataCode p.data +abbrev view : Realizes paramsCode paramsDataCode Params.data := + (identity paramsDataCode).reindex paramsCode Params.data (fun _ => rfl) +private instance poly_view : PolyTime view := by + unfold view + apply poly_reindex + +abbrev dim := view.then (first natCode (prodCode natCode (prodCode ratCode matrixCode))) +abbrev rest := view.then (second natCode (prodCode natCode (prodCode ratCode matrixCode))) +abbrev count := rest.then (first natCode (prodCode ratCode matrixCode)) +abbrev tail := rest.then (second natCode (prodCode ratCode matrixCode)) +abbrev factor := tail.then (first ratCode matrixCode) +abbrev columns := tail.then (second ratCode matrixCode) +def numColumns : Realizes paramsCode natCode Params.m := + (columns.then (lengthList vectorCode)).congr (by + intro p + exact List.length_ofFn) +instance poly_numColumns : PolyTime numColumns := by + unfold numColumns + apply poly_congr + +def outer : Realizes vectorCode matrixCode + (fun xs : List ℚ => xs.map (fun q => xs.map (fun r => q*r))) := + let one := ((second vectorCode ratCode).both (first vectorCode ratCode)).then vectorScale + ((identity vectorCode).both (identity vectorCode)).then one.mapCtx +instance poly_outer : PolyTime outer := by + unfold outer + infer_instance +lemma outer_data {d : ℕ} (v : Fin d → ℚ) : + (List.ofFn v).map (fun q => (List.ofFn v).map (fun r => q*r))= + matrixData (vecMulVec v v) := by + simp only [List.map_ofFn,Function.comp_def,matrixData] + rfl + +structure State where + params : Params + scales : Fin params.m → ℚ + +def stateCode (s : State) : Word := + prodCode paramsCode vectorCode (s.params,List.ofFn s.scales) +abbrev stateView : Realizes stateCode (prodCode paramsCode vectorCode) + (fun s => (s.params,List.ofFn s.scales)) := + (identity (prodCode paramsCode vectorCode)).reindex stateCode + (fun s => (s.params,List.ofFn s.scales)) (fun _ => rfl) +private instance poly_stateView : PolyTime stateView := by + unfold stateView + apply poly_reindex + +abbrev params := stateView.then (first paramsCode vectorCode) +abbrev scales := stateView.then (second paramsCode vectorCode) + +def gram : Realizes stateCode matrixCode + (fun s => matrixData (covariance s.params.v (weights s.scales))) := + (((params.then dim).both + ((scales.then ((identity ratCode).pow 2).map).both + ((params.then columns).then outer.map))).then weightedSum).congr (by + intro s + change weightedSumData (s.params.d, + ((List.ofFn s.scales).map (fun q => q^2), + (matrixData s.params.v).map (fun xs => xs.map (fun q => xs.map (fun r => q*r)))))=_ + simp only [matrixData,List.map_ofFn,Function.comp_def] + change weightedSumData (s.params.d, + (List.ofFn (weights s.scales),List.ofFn (fun e => matrixData (vecMulVec (s.params.v e) (s.params.v e)))))=_ + exact weightedSum_data _ _) +instance poly_gram : PolyTime gram := by + unfold gram + infer_instance + +abbrev Column := Σ s : State, Fin s.params.m +abbrev columnCode := finFamilyCode stateCode (fun s : State => s.params.m) +abbrev colState : Realizes columnCode stateCode (fun x : Column => x.1) := familyFirst +abbrev colIndex : Realizes columnCode natCode (fun x : Column => x.2.val) := familyIndex +abbrev colParams := colState.then params + +def column : Realizes columnCode vectorCode (fun x => List.ofFn (x.1.params.v x.2)) := + ((colIndex.both (colParams.then columns)).then (getD vectorCode [])).congr (by + intro x + exact getD_ofFn _ _ _) +def scale : Realizes columnCode ratCode (fun x => x.1.scales x.2) := + ((colIndex.both (colState.then scales)).then (getD ratCode 0)).congr (by + intro x + exact getD_ofFn _ _ _) +instance poly_column : PolyTime column := by unfold column; apply poly_congr +instance poly_scale : PolyTime scale := by unfold scale; infer_instance + +def thresholdProgram : Realizes paramsCode ratCode (fun p => threshold p.q p.t) := + let c (q : ℚ) := constant paramsCode ratCode q + ((c 1).div (count.then natToRat)).add + ((c 4).mul ((c 1).sub (factor.pow 2))) +instance poly_thresholdProgram : PolyTime thresholdProgram := by + have hfactor : PolyTime factor := by + unfold factor + apply poly_then + unfold thresholdProgram + refine @poly_add _ _ _ _ _ _ ?_ ?_ + · infer_instance + · refine @poly_mul _ _ _ _ _ _ ?_ ?_ + · infer_instance + · refine @poly_sub _ _ _ _ _ _ ?_ ?_ + · infer_instance + · exact hfactor.pow 2 + +def testProgram : Realizes columnCode matrixObjectCode + (fun x => ⟨x.1.params.d,testMatrix x.1.params.q x.1.params.t + x.1.params.v x.1.scales x.2⟩) := + let firstPart := (((colParams.then thresholdProgram).both (colState.then gram)).then matrixScale) + let secondPart := (((scale.pow 2).both (column.then outer)).then matrixScale) + ((colParams.then dim).both ((firstPart.both secondPart).then matrixSub)).changeOutput + matrixObjectCode (fun x => ⟨x.1.params.d,testMatrix x.1.params.q x.1.params.t + x.1.params.v x.1.scales x.2⟩) (by + intro x + simp only [matrixScale_data,outer_data] + change prodCode natCode matrixCode (x.1.params.d, + matrixSubData + (matrixData (threshold x.1.params.q x.1.params.t • + covariance x.1.params.v (weights x.1.scales)), + matrixData ((x.1.scales x.2)^2 • vecMulVec (x.1.params.v x.2) (x.1.params.v x.2))))=_ + rw [matrixSub_data] + rfl) +instance poly_testProgram : PolyTime testProgram := by + unfold testProgram + infer_instance + +def isHeavy : Realizes columnCode boolCode + (fun x => (KS.W17.rationalNegativeWitness x.1.params.d + (testMatrix x.1.params.q x.1.params.t x.1.params.v x.1.scales x.2)).isSome) := + ((testProgram.then isPSD).ite (constant columnCode boolCode false) + (constant columnCode boolCode true)).congr (by + intro x + cases h : KS.W17.rationalNegativeWitness x.1.params.d + (testMatrix x.1.params.q x.1.params.t x.1.params.v x.1.scales x.2) <;> simp) +instance poly_isHeavy : PolyTime isHeavy := by unfold isHeavy; infer_instance + +def updated : Realizes columnCode vectorCode + (fun x => List.ofFn (Function.update x.1.scales x.2 (x.1.params.t*x.1.scales x.2))) := + (((colState.then scales).both (colIndex.both ((colParams.then factor).mul scale))).then + updateVector).congr (fun _ => update_data _ _ _) +instance poly_updated : PolyTime updated := by unfold updated; apply poly_congr + +def newScales : Realizes stateCode vectorCode + (fun s => List.ofFn (advance s.params.q s.params.t s.params.v s.scales)) := + ((scales.both ((isHeavy.both updated).tabulateFin (params.then numColumns))).then + (selectFlagged vectorCode)).congr (by + intro s + dsimp only + rw [List.ofFn_eq_map (f := fun e => + ((KS.W17.rationalNegativeWitness s.params.d + (testMatrix s.params.q s.params.t s.params.v s.scales e)).isSome, + List.ofFn (Function.update s.scales e (s.params.t*s.scales e)))),find_map_flagged] + unfold advance heavy + cases h : (List.finRange s.params.m).find? (fun e => + (KS.W17.rationalNegativeWitness s.params.d + (testMatrix s.params.q s.params.t s.params.v s.scales e)).isSome) <;> rfl) +instance poly_newScales : PolyTime newScales := by unfold newScales; infer_instance + +def State.next (s : State) : State := + ⟨s.params,advance s.params.q s.params.t s.params.v s.scales⟩ +def step : Realizes stateCode stateCode State.next := + (params.both newScales).changeOutput stateCode State.next (fun _ => rfl) +instance poly_step : PolyTime step := by unfold step; apply poly_changeOutput + +lemma next_iterate (s : State) (n : ℕ) : + State.next^[n] s=⟨s.params,(advance s.params.q s.params.t s.params.v)^[n] s.scales⟩ := by + induction n with + | zero => rfl + | succ n ih => + rw [Function.iterate_succ_apply',ih] + change State.mk s.params (advance _ _ _ _) = State.mk s.params _ + rw [Function.iterate_succ_apply'] + +lemma advance_iterate_parts (p : Params) (s : Fin p.m → ℚ) {b : ℕ} + (ht : QParts b p.t) (hs : ∀i,QParts b (s i)) (k : ℕ) : + ∀i,QParts (b+k*b) ((advance p.q p.t p.v)^[k] s i) := by + induction k with + | zero => simpa using hs + | succ k ih => + intro i + rw [Function.iterate_succ_apply'] + rw [advance] + cases hh : heavy p.q p.t p.v ((advance p.q p.t p.v)^[k] s) with + | none => + exact (ih i).mono (show b+k*b ≤ b+(k+1)*b by simp only [Nat.add_mul,Nat.one_mul]; omega) + | some j => + simp only [Option.elim_some] + by_cases h : i=j + · subst i + simpa only [Function.update_self,Nat.add_mul,Nat.one_mul,Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using ht.mul (ih j) + · simpa only [Function.update_of_ne h] using + (ih i).mono (show b+k*b ≤ b+(k+1)*b by simp only [Nat.add_mul,Nat.one_mul]; omega) + +instance size_step : IterateSize step := by + refine ⟨⟨100*(X+1)^3,?_⟩⟩ + intro s k + let L := (stateCode s).length + have hp : (paramsCode s.params).length≤L := le_prodCode_left (s.params,List.ofFn s.scales) + have hy : (vectorCode (List.ofFn s.scales)).length≤L := le_prodCode_right (s.params,List.ofFn s.scales) + have ht : QParts L s.params.t := (qparts_length _).mono + (((le_prodCode_left (s.params.t,matrixData s.params.v)).trans + (le_prodCode_right (s.params.q,(s.params.t,matrixData s.params.v)))).trans + ((le_prodCode_right s.params.data).trans hp)) + have hs : ∀i,QParts L (s.scales i) := by + intro i + exact (qparts_length _).mono + ((mem_length_le_code (List.ofFn s.scales) (List.mem_ofFn.mpr ⟨i,rfl⟩)).trans hy) + have hm : s.params.m≤L := by + simpa only [List.length_ofFn] using (list_length_le_code ratCode (List.ofFn s.scales)).trans hy + have hlen := listCode_length_bound + (List.ofFn ((advance s.params.q s.params.t s.params.v)^[k] s.scales)) (4*(L+k*L)+7) (by + intro q hq + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hq + exact (advance_iterate_parts s.params s.scales ht hs k i).length) + rw [List.length_ofFn] at hlen + have hlen' := hlen.trans (Nat.mul_le_mul_right _ hm) + change (stateCode (State.next^[k] s)).length≤100*(L+k+1)^3 + rw [next_iterate] + change (prodCode paramsCode vectorCode + (s.params,List.ofFn ((advance s.params.q s.params.t s.params.v)^[k] s.scales))).length≤_ + rw [prodCode_length] + dsimp only + change (vectorCode (List.ofFn ((advance s.params.q s.params.t s.params.v)^[k] s.scales))).length≤_ at hlen' + have hL : L≤L+k+1 := by omega + have hk : k≤L+k+1 := by omega + have hLL := Nat.mul_le_mul hL hL + have hkLL := Nat.mul_le_mul hk hLL + nlinarith + +def initial : Realizes paramsCode stateCode (fun p => ⟨p,fun _ => 1⟩) := + ((identity paramsCode).both + (((constant paramsCode ratCode 1).both numColumns).then (replicateList ratCode))).changeOutput + stateCode (fun p => ⟨p,fun _ => 1⟩) (by + intro p + change prodCode paramsCode vectorCode (p,List.replicate p.m 1)= + prodCode paramsCode vectorCode (p,List.ofFn (fun _ : Fin p.m => (1:ℚ))) + rw [List.ofFn_const]) +instance poly_initial : PolyTime initial := by unfold initial; infer_instance + +def run : Realizes (prodCode natCode paramsCode) vectorCode + (fun a => List.ofFn (scalesAt a.2.q a.2.t a.2.v a.1)) := + ((((first natCode paramsCode).both ((second natCode paramsCode).then initial)).then + step.iterate).then scales).congr (by + intro a + rw [next_iterate] + rfl) +instance poly_run : PolyTime run := by unfold run; infer_instance + +def unaryPow (k : ℕ) : Realizes natCode natCode (fun n => n^k) := + match k with + | 0 => (constant natCode natCode 1).congr (fun _ => rfl) + | k+1 => (((unaryPow k).both (identity natCode)).then natMul).congr + (fun _ => (pow_succ _ _).symm) +instance poly_unaryPow (k : ℕ) : PolyTime (unaryPow k) := by + induction k with + | zero => unfold unaryPow; apply poly_congr + | succ k ih => unfold unaryPow; infer_instance + +abbrev fixedCode := prodCode paramsCode natCode +abbrev fixedParams := first paramsCode natCode +abbrev fixedR := second paramsCode natCode + +def multiplierProgram : Realizes natCode ratCode multiplier := + let c (q : ℚ) := constant natCode ratCode q + (c 1).sub ((c 1).div ((c 16).mul (natToRat.pow 2))) +instance poly_multiplierProgram : PolyTime multiplierProgram := by + unfold multiplierProgram; apply poly_sub + +def fixedStepParams (a : Params×ℕ) : Params := + ⟨a.1.d,a.1.m,a.1.q,multiplier a.2,a.1.v⟩ +def fixedStep : Realizes fixedCode paramsCode fixedStepParams := + ((fixedParams.then dim).both ((fixedParams.then count).both + ((fixedR.then multiplierProgram).both (fixedParams.then columns)))).changeOutput + paramsCode fixedStepParams (fun _ => rfl) +instance poly_fixedStep : PolyTime fixedStep := by unfold fixedStep; apply poly_changeOutput + +def lengthProgram : Realizes fixedCode natCode + (fun a => normalizationLength a.1.m a.2) := + let c (n : ℕ) := constant fixedCode natCode n + let m := fixedParams.then numColumns + ((((((c 2).both m).then natMul).then natSucc).both (c 256)).then natMul).both + (fixedR.then (unaryPow 4)) |>.then natMul +instance poly_lengthProgram : PolyTime lengthProgram := by unfold lengthProgram; apply poly_then + +def normalized : Realizes fixedCode vectorCode + (fun a => List.ofFn (normalizedScales a.1.q a.2 a.1.v)) := + (lengthProgram.both fixedStep).then run +instance poly_normalized : PolyTime normalized := by unfold normalized; apply poly_then + +end AlgorithmicThinTrees.Normalization.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/OptionalDirections.lean b/lean/OAI/Combinatorics/ThinTrees/OptionalDirections.lean new file mode 100644 index 0000000000000000000000000000000000000000..77b11b894e54febecd6635aff25050dcb93456ab --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/OptionalDirections.lean @@ -0,0 +1,98 @@ +import OAI.Combinatorics.ThinTrees.RootBound + +namespace OAI + +universe uI uD uR uS + +section + +noncomputable section +open Matrix Polynomial Finset +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} {S : Type uS} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] + [CommRing R] [CommRing S] + +def coefficientX : MvPolynomial (Option I) R →+* MvPolynomial I R[X] := + MvPolynomial.eval₂Hom (MvPolynomial.C.comp Polynomial.C) + (fun o => o.elim (MvPolynomial.C Polynomial.X) MvPolynomial.X) + +def uniSlice : MvPolynomial (Option I) R →+* R[X] := + MvPolynomial.eval₂Hom Polynomial.C (fun o => o.elim Polynomial.X (fun _ => 0)) + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +@[simp] lemma coefficientX_C (r : R) : coefficientX (I := I) (MvPolynomial.C r)= + MvPolynomial.C (Polynomial.C r) := by simp [coefficientX] + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +@[simp] lemma coefficientX_X (i : Option I) : coefficientX (R := R) (MvPolynomial.X i)= + i.elim (MvPolynomial.C Polynomial.X) MvPolynomial.X := by simp [coefficientX] + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +@[simp] lemma uniSlice_C (r : R) : uniSlice (I := I) (MvPolynomial.C r)=Polynomial.C r := by + simp [uniSlice] + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +@[simp] lemma uniSlice_X (i : Option I) : uniSlice (R := R) (MvPolynomial.X i)= + i.elim Polynomial.X (fun _ => 0) := by simp [uniSlice] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma coefficientX_pderiv (i : I) (p : MvPolynomial (Option I) R) : + coefficientX (MvPolynomial.pderiv (some i) p)=MvPolynomial.pderiv i (coefficientX p) := by + induction p using MvPolynomial.induction_on with + | C r => simp + | add p q hp hq => simp [hp,hq] + | mul_X p k hp => + rw [MvPolynomial.pderiv_mul,map_add,map_mul,map_mul,map_mul,MvPolynomial.pderiv_mul,hp] + cases k with + | none => simp + | some k => by_cases hk : k=i <;> simp [hk] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma coefficientX_diffProduct (dirs : List I) (p : MvPolynomial (Option I) R) : + coefficientX (diffProduct (dirs.map some) p)=diffProduct dirs (coefficientX p) := by + induction dirs generalizing p with + | nil => rfl + | cons i dirs ih => + simp only [List.map_cons,diffProduct_cons,ih,map_sub,coefficientX_pderiv] + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +lemma eval_zero_coefficientX (p : MvPolynomial (Option I) R) : + MvPolynomial.eval (fun _ => 0) (coefficientX p)=uniSlice p := by + induction p using MvPolynomial.induction_on with + | C r => simp + | add p q hp hq => simpa only [map_add] using congrArg₂ (·+·) hp hq + | mul_X p k hp => + cases k <;> simp only [map_mul,coefficientX_X,uniSlice_X,Option.elim, + MvPolynomial.eval_C,MvPolynomial.eval_X,mul_zero,hp] + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +lemma uniSlice_map (f : R →+* S) (p : MvPolynomial (Option I) R) : + uniSlice (p.map f)=(uniSlice p).map f := by + induction p using MvPolynomial.induction_on with + | C r => simp + | add p q hp hq => simp [hp,hq] + | mul_X p k hp => cases k <;> simp [hp] + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +lemma diffProduct_map (f : R →+* S) (dirs : List I) (p : MvPolynomial I R) : + diffProduct dirs (p.map f)=(diffProduct dirs p).map f := by + induction dirs generalizing p with + | nil => rfl + | cons i dirs ih => + simp only [diffProduct_cons,MvPolynomial.pderiv_map,←map_sub,ih] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma uniSlice_eq_slice (p : MvPolynomial (Option I) ℂ) : + uniSlice p=slice p (fun _ => 0) none := by + change MvPolynomial.eval₂ Polynomial.C (fun o : Option I => o.elim X (fun _ => 0)) p = _ + unfold slice + apply congrArg (fun z => MvPolynomial.eval₂ Polynomial.C z p) + funext i + cases i <;> simp + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Padding.lean b/lean/OAI/Combinatorics/ThinTrees/Padding.lean new file mode 100644 index 0000000000000000000000000000000000000000..35add24901af9849fba21d459ed097139c1d2c77 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Padding.lean @@ -0,0 +1,76 @@ +import OAI.Combinatorics.ThinTrees.IndependentVectors + +namespace OAI + +universe uD + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree.MSS +variable {D : Type uD} [Fintype D] [DecidableEq D] + +omit [Fintype D] [DecidableEq D] in +lemma rankOne_smul (c : ℝ) (v : D → ℝ) : + Matrix.vecMulVec (c • v) (c • v)=c^2 • Matrix.vecMulVec v v := by + apply Matrix.ext + intro a b + simp [Matrix.vecMulVec,Matrix.smul_apply,Pi.smul_apply] + ring + +omit [DecidableEq D] in +lemma sum_column_rankOne (M : Matrix D D ℝ) : + ∑d, Matrix.vecMulVec (fun a => M a d) (fun a => M a d)=M*Mᵀ := by + apply Matrix.ext + intro a b + simp [Matrix.sum_apply,Matrix.mul_apply,Matrix.vecMulVec,Matrix.transpose_apply] + +omit [DecidableEq D] in +lemma rankOne_trace_nonneg (v : D → ℝ) : 0 ≤ (Matrix.vecMulVec v v).trace := by + exact (rankOne_posSemidef v).trace_nonneg + +lemma deterministic_padding (R : Matrix D D ℝ) (hR : R.PosSemidef) {ε : ℝ} (hε : 0 < ε) : + ∃N : ℕ, ∃u : Fin N × D → D → ℝ, + (∑p, Matrix.vecMulVec (u p) (u p))=R ∧ + ∀p, (Matrix.vecMulVec (u p) (u p)).trace ≤ ε := by + let S := CFC.sqrt R + have hS : S.IsHermitian := (CFC.sqrt_nonneg R).posSemidef.isHermitian + have hsum : (∑d, Matrix.vecMulVec (fun a => S a d) (fun a => S a d))=R := by + rw [sum_column_rankOne] + have ht : Sᵀ=S := by simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using hS.eq + rw [ht] + exact CFC.sqrt_mul_sqrt_self R hR.nonneg + have htr : ∀d, (Matrix.vecMulVec (fun a => S a d) (fun a => S a d)).trace ≤ R.trace := by + intro d + rw [←hsum,Matrix.trace_sum] + exact Finset.single_le_sum (fun e _ => rankOne_trace_nonneg (fun a => S a e)) (Finset.mem_univ d) + obtain ⟨N,hN⟩ := exists_nat_gt (max 0 (R.trace/ε)) + have hNpos : 0 < (N : ℝ) := (le_max_left _ _).trans_lt hN + have hNε : R.trace/(N : ℝ) ≤ ε := by + have hh : R.trace/ε ≤ N := (le_max_right _ _).trans hN.le + apply (div_le_iff₀ hNpos).mpr + simpa only [mul_comm] using (div_le_iff₀ hε).mp hh + let c : ℝ := Real.sqrt (1/(N : ℝ)) + have hc : c^2=1/(N : ℝ) := Real.sq_sqrt (by positivity) + let u : Fin N × D → D → ℝ := fun p => c • (fun a => S a p.2) + refine ⟨N,u,?_,?_⟩ + · simp only [u,rankOne_smul,hc,Fintype.sum_prod_type,←Finset.smul_sum,hsum] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin] + rw [←Nat.cast_smul_eq_nsmul ℝ, smul_smul] + simp [hNpos.ne'] + · intro p + simp only [u,rankOne_smul,hc,Matrix.trace_smul,smul_eq_mul] + calc + (1/(N : ℝ)) * (Matrix.vecMulVec (fun a => S a p.2) (fun a => S a p.2)).trace + ≤ (1/(N : ℝ))*R.trace := mul_le_mul_of_nonneg_left (htr p.2) (by positivity) + _ = R.trace/(N : ℝ) := by ring + _ ≤ ε := hNε + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/PartialFractions.lean b/lean/OAI/Combinatorics/ThinTrees/PartialFractions.lean new file mode 100644 index 0000000000000000000000000000000000000000..a22c783a45c5bddd2ab936ba6a485a2f5ecbff02 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/PartialFractions.lean @@ -0,0 +1,413 @@ +import OAI.Combinatorics.ThinTrees.Stability + +namespace OAI + +section + +noncomputable section +open Polynomial Filter Finset +open scoped Topology +namespace StrongThinTree.MSS.Rational + +lemma upper_root_I {k : ℕ} (hk : 0 < k) : + ∃w : ℂ, 0 < w.im ∧ w^k=Complex.I := by + let θ : ℝ := Real.pi/(2*k) + let w := Complex.exp ((θ:ℂ)*Complex.I) + have hkp : (0:ℝ) cval a ((x:ℂ)+r*w)/(w^k*cval b ((x:ℂ)+r*w))) + (𝓝[>] 0) (𝓝 (((a.eval x/b.eval x:ℝ):ℂ)/w^k)) := by + have hc : ContinuousAt (fun r : ℝ => (x:ℂ)+(r:ℂ)*w) 0 := by fun_prop + have hta := (continuous_cval a).continuousAt.comp hc + have htb := (continuous_cval b).continuousAt.comp hc + have htt := hta.tendsto.div (htb.tendsto.const_mul (w^k)) (by simpa using hd) + dsimp only [Function.comp_apply,Pi.div_apply] at htt + simp only [Complex.ofReal_zero] at htt + have heq : cval a ((x:ℂ)+(0:ℂ)*w)/(w^k*cval b ((x:ℂ)+(0:ℂ)*w))= + ((a.eval x/b.eval x:ℝ):ℂ)/w^k := by simp only [zero_mul,add_zero,cval_real,Complex.ofReal_div]; ring + rw [heq] at htt + exact htt.mono_left nhdsWithin_le_nhds + have him := Complex.continuous_im.continuousAt.tendsto.comp ht + apply le_of_tendsto him + filter_upwards [self_mem_nhdsWithin] with r hr + have hrp : 0 < r := hr + have hrc : (r:ℂ) ≠ 0 := by exact_mod_cast hrp.ne' + have hzr : 0 < ((x:ℂ)+(r:ℂ)*w).im := by simpa using mul_pos hrp hw + have hh := h _ hzr + have heq : cval a ((x:ℂ)+r*w)/(w^k*cval b ((x:ℂ)+r*w))= + (r:ℂ)^k * (cval a ((x:ℂ)+r*w)/(((x:ℂ)+r*w-x)^k*cval b ((x:ℂ)+r*w))) := by + rw [add_sub_cancel_left,mul_pow] + field_simp [hrc] + dsimp only [Function.comp_apply] + rw [heq,←Complex.ofReal_pow,Complex.mul_im] + simp only [Complex.ofReal_re,Complex.ofReal_im,zero_mul,add_zero] + exact mul_nonpos_of_nonneg_of_nonpos (pow_nonneg hrp.le _) hh + +@[simp] lemma cval_mul (p q : ℝ[X]) (z : ℂ) : cval (p*q) z=cval p z*cval q z := by + simp [cval] +@[simp] lemma cval_pow (p : ℝ[X]) (n : ℕ) (z : ℂ) : cval (p^n) z=(cval p z)^n := by + simp [cval] +@[simp] lemma cval_X_sub_C (x : ℝ) (z : ℂ) : cval (X-C x) z=z-x := by + simp [cval] + +lemma simple_roots (a b : ℝ[X]) (hb : b ≠ 0) (hab : IsCoprime a b) + (h : ∀z : ℂ, 0 < z.im → (cval a z/cval b z).im ≤ 0) : b.roots.Nodup := by + classical + apply Multiset.nodup_iff_count_le_one.mpr + intro x + rw [count_roots] + by_cases hx : b.IsRoot x + · have ha : a.eval x ≠ 0 := by + have ht := aeval_ne_zero_of_isCoprime hab x + simpa [aeval_def,eval₂_at_apply,hx.eq_zero] using ht + obtain ⟨q,hq,hq0⟩ := exists_eq_pow_rootMultiplicity_mul_and_not_dvd b hb x + have hqx : q.eval x ≠ 0 := by simpa [dvd_iff_isRoot,IsRoot] using hq0 + have hh := pole_test a q ((rootMultiplicity_pos hb).mpr hx) ha hqx + (fun z hz => by + have he := congrArg (fun p => cval p z) hq + simp only [cval_mul,cval_pow,cval_X_sub_C] at he + rw [←he] + exact h z hz) + omega + · have hh : rootMultiplicity x b = 0 := by + exact Nat.eq_zero_of_not_pos (fun hp => hx ((rootMultiplicity_pos hb).mp hp)) + omega + +lemma cval_ray (p : ℝ[X]) {w r : ℂ} (hw : w ≠ 0) (hr : r ≠ 0) : + cval p (w/r) = cval p.reverse (r/w)*(w/r)^p.natDegree := by + let : Invertible (w/r) := invertibleOfNonzero (div_ne_zero hw hr) + have h := eval₂_reverse_mul_pow (algebraMap ℝ ℂ) (w/r) p + simpa only [cval,eval_map,←eval₂_eq_eval_map,invOf_eq_inv,inv_div] using h.symm + +lemma reverse_at_zero (p : ℝ[X]) : cval p.reverse 0=((p.leadingCoeff:ℝ):ℂ) := by + simp [cval,eval_map,coeff_reverse] + +lemma ray_limit (a b : ℝ[X]) (hb : b ≠ 0) (hdeg : b.natDegree ≤ a.natDegree) + {w : ℂ} (hw : w ≠ 0) : + Tendsto (fun r : ℝ => (r:ℂ)^(a.natDegree-b.natDegree)* + (cval a (w/r)/cval b (w/r))) (𝓝[>] 0) + (𝓝 (((a.leadingCoeff/b.leadingCoeff:ℝ):ℂ)*w^(a.natDegree-b.natDegree))) := by + have hc : ContinuousAt (fun r : ℝ => (r:ℂ)/w) 0 := by fun_prop + have ha := (continuous_cval a.reverse).continuousAt.comp hc + have hb' := (continuous_cval b.reverse).continuousAt.comp hc + have hlc : cval b.reverse ((0:ℂ)/w) ≠ 0 := by + simp only [zero_div,reverse_at_zero,ne_eq,Complex.ofReal_eq_zero] + exact leadingCoeff_ne_zero.mpr hb + have ht := (ha.tendsto.div hb'.tendsto hlc).mul_const (w^(a.natDegree-b.natDegree)) + simp only [Function.comp_apply,zero_div,Complex.ofReal_zero,reverse_at_zero,←Complex.ofReal_div] at ht + apply (ht.mono_left nhdsWithin_le_nhds).congr' + filter_upwards [self_mem_nhdsWithin] with r hr + have hr0 : (r:ℂ) ≠ 0 := by exact_mod_cast (show r ≠ 0 from ne_of_gt hr) + rw [cval_ray a hw hr0,cval_ray b hw hr0] + rw [show a.natDegree=b.natDegree+(a.natDegree-b.natDegree) from (Nat.add_sub_of_le hdeg).symm] + simp only [Nat.add_sub_cancel_left,pow_add,div_pow] + field_simp + rfl + +lemma degree_le (a b : ℝ[X]) (hb : b ≠ 0) + (h : ∀z : ℂ, 0 < z.im → (cval a z/cval b z).im ≤ 0) + (hpos : ∀t : ℝ, 0 ≤ t → 0 ≤ a.eval t/b.eval t) : a.natDegree ≤ b.natDegree := by + by_contra hdeg + have hlt : b.natDegree < a.natDegree := Nat.lt_of_not_ge hdeg + have ha : a ≠ 0 := by intro hh; simp [hh] at hlt + have hc : a.leadingCoeff/b.leadingCoeff ≠ 0 := + div_ne_zero (leadingCoeff_ne_zero.mpr ha) (leadingCoeff_ne_zero.mpr hb) + have ht := polynomial_part_order hc (Nat.sub_pos_of_lt hlt) (by + intro w hw + have hw0 : w ≠ 0 := by intro hh; simp [hh] at hw + have hh := Complex.continuous_im.continuousAt.tendsto.comp (ray_limit a b hb hlt.le hw0) + apply le_of_tendsto hh + filter_upwards [self_mem_nhdsWithin] with r hr + have hrp : 0 < r := hr + have hz : 0 < (w/(r:ℂ)).im := by + simpa [Complex.div_ofReal_im] using div_pos hw hrp + have hi := h _ hz + dsimp only [Function.comp_apply] + simp only [←Complex.ofReal_pow,Complex.mul_im,Complex.ofReal_re,Complex.ofReal_im,zero_mul,add_zero] + exact mul_nonpos_of_nonneg_of_nonpos (pow_nonneg hrp.le _) hi) + have hc0 : 0 ≤ a.leadingCoeff/b.leadingCoeff := by + have hh := Complex.continuous_re.continuousAt.tendsto.comp (ray_limit a b hb hlt.le (one_ne_zero : (1:ℂ)≠0)) + simp only [one_pow,mul_one,Complex.ofReal_re] at hh + apply ge_of_tendsto hh + filter_upwards [self_mem_nhdsWithin] with r hr + have hrp : 0 < r := hr + dsimp only [Function.comp_apply] + have he : (1:ℂ)/(r:ℂ)=((1/r:ℝ):ℂ) := by push_cast; rfl + rw [he,cval_real,cval_real,←Complex.ofReal_div,←Complex.ofReal_pow,←Complex.ofReal_mul,Complex.ofReal_re] + exact mul_nonneg (pow_nonneg hrp.le _) (hpos _ (by positivity)) + linarith [ht.2] + +lemma monic_eq_prod_roots (b : ℝ[X]) (hm : b.Monic) (hs : b.Splits) + (hn : b.roots.Nodup) : b=∏x ∈ b.roots.toFinset, (X-C x) := by + classical + conv_lhs => rw [hs.eq_prod_roots,hm.leadingCoeff,C_1,one_mul,Finset.prod_multiset_map_count] + apply Finset.prod_congr rfl + intro x hx + rw [Multiset.count_eq_one_of_mem hn (Multiset.mem_toFinset.mp hx),pow_one] + +lemma simple_decomposition (a b : ℝ[X]) (hm : b.Monic) (hs : b.Splits) + (hn : b.roots.Nodup) (hd : a.natDegree ≤ b.natDegree) : + ∃c : ℝ, ∃d : ℝ → ℝ, a=C c*b+∑x ∈ b.roots.toFinset, C (d x)*∏y ∈ b.roots.toFinset.erase x, (X-C y) := by + classical + let s := b.roots.toFinset + have hb : b=∏x ∈ s, (X-C x) := monic_eq_prod_roots b hm hs hn + obtain ⟨q,r,hr,he⟩ := eq_quo_mul_prod_add_sum_rem_mul_prod (s:=s) a + (g:=fun x : ℝ => X-C x) (fun _ _ => monic_X_sub_C _) + (fun _ _ _ _ hxy => isCoprime_X_sub_C_of_isUnit_sub (isUnit_iff_ne_zero.mpr (sub_ne_zero.mpr hxy))) + have hrC : ∀x ∈ s, r x=C ((r x).coeff 0) := by + intro x hx + by_cases h0 : r x=0 + · simp [h0] + apply eq_C_of_natDegree_eq_zero + have hh := hr x hx + rw [degree_X_sub_C,degree_eq_natDegree h0] at hh + have hh' : (r x).natDegree < 1 := WithBot.coe_lt_coe.mp hh + omega + have hR : (∑x ∈ s, r x * ∏y ∈ s.erase x, (X-C y)).degree < b.degree := by + apply (degree_sum_le _ _).trans_lt + apply Finset.sup_lt_iff (by simpa only [bot_lt_iff_ne_bot,degree_ne_bot] using hm.ne_zero) |>.mpr + intro x hx + rw [hb,←Finset.mul_prod_erase s (fun x : ℝ => X-C x) hx] + rw [degree_mul,degree_mul] + apply WithBot.add_lt_add_right + · rw [degree_ne_bot] + exact (monic_prod_of_monic (s.erase x) _ (fun y _ => monic_X_sub_C y)).ne_zero + · exact hr x hx + have hq : q.natDegree=0 := by + by_contra hq + have hqp : 0 < q.degree := natDegree_pos_iff_degree_pos.mp (Nat.pos_of_ne_zero hq) + have hqb : b.degree < (q*b).degree := by + rw [degree_mul] + simpa using WithBot.add_lt_add_right (by simpa [degree_ne_bot] using hm.ne_zero) hqp + have hda : a.degree ≤ b.degree := by + exact degree_le_of_natDegree_le hd |>.trans (le_of_eq (degree_eq_natDegree hm.ne_zero).symm) + have he' : a=q*b+∑x ∈ s, r x*∏y ∈ s.erase x, (X-C y) := by simpa only [←hb] using he + rw [he',degree_add_eq_left_of_degree_lt (hR.trans hqb)] at hda + exact (not_le_of_gt hqb) hda + refine ⟨q.coeff 0,fun x => (r x).coeff 0,?_⟩ + calc + a=q*b+∑x ∈ s, r x*∏y ∈ s.erase x, (X-C y) := by simpa only [←hb] using he + _=C (q.coeff 0)*b+∑x ∈ s, C ((r x).coeff 0)*∏y ∈ s.erase x, (X-C y) := by + apply congrArg₂ (·+·) + · exact congrArg (·*b) (eq_C_of_natDegree_eq_zero hq) + · exact Finset.sum_congr rfl (fun x hx => congrArg (·*∏y ∈ s.erase x, (X-C y)) (hrC x hx)) + +lemma decomposition_value (a b : ℝ[X]) (s : Finset ℝ) (c : ℝ) (d : ℝ → ℝ) + (hb : b=∏x ∈ s, (X-C x)) + (he : a=C c*b+∑x ∈ s, C (d x)*∏y ∈ s.erase x, (X-C y)) + {t : ℝ} (ht : ∀x ∈ s, t ≠ x) : + a.eval t/b.eval t=c+∑x ∈ s, d x/(t-x) := by + classical + have hb0 : b.eval t ≠ 0 := by + rw [hb,eval_prod] + simp only [eval_sub,eval_X,eval_C] + exact Finset.prod_ne_zero_iff.mpr (fun x hx => sub_ne_zero.mpr (ht x hx)) + have he' := congrArg (fun p : ℝ[X] => p.eval t) he + simp only [eval_add,eval_mul,eval_C,eval_finsetSum,eval_prod,eval_sub,eval_X] at he' + rw [he',add_div,mul_div_cancel_right₀ _ hb0,Finset.sum_div] + congr 1 + apply Finset.sum_congr rfl + intro x hx + have hh := congrArg (fun p : ℝ[X] => p.eval t) (hb.trans (Finset.mul_prod_erase s (fun y : ℝ => X-C y) hx).symm) + simp only [eval_mul,eval_sub,eval_X,eval_C,eval_prod] at hh + have hpr : (∏y ∈ s.erase x, (t-y)) ≠ 0 := by + exact Finset.prod_ne_zero_iff.mpr (fun y hy => sub_ne_zero.mpr (ht y (mem_of_mem_erase hy))) + rw [hh] + field_simp + +lemma residue_value (a b : ℝ[X]) (s : Finset ℝ) (c : ℝ) (d : ℝ → ℝ) + (hb : b=∏x ∈ s, (X-C x)) + (he : a=C c*b+∑x ∈ s, C (d x)*∏y ∈ s.erase x, (X-C y)) + {x : ℝ} (hx : x ∈ s) : + a.eval x/(∏y ∈ s.erase x, (X-C y)).eval x=d x := by + classical + have hb0 : b.eval x=0 := by + rw [hb,eval_prod] + exact Finset.prod_eq_zero hx (by simp) + have he' := congrArg (fun p : ℝ[X] => p.eval x) he + simp only [eval_add,eval_mul,eval_C,eval_finsetSum,hb0,mul_zero,zero_add] at he' + rw [Finset.sum_eq_single x] at he' + · rw [he',mul_div_cancel_right₀] + rw [eval_prod] + simp only [eval_sub,eval_X,eval_C] + apply Finset.prod_ne_zero_iff.mpr + intro y hy + exact sub_ne_zero.mpr (mem_erase.mp hy).1.symm + · intro y hy hxy + suffices h0 : (∏z ∈ s.erase y, (X-C z)).eval x=0 by rw [h0,mul_zero] + rw [eval_prod] + exact Finset.prod_eq_zero (mem_erase.mpr ⟨hxy.symm,hx⟩) (by simp) + · exact fun hn => (hn hx).elim + +lemma positive_decomposition_monic (a b : ℝ[X]) (hm : b.Monic) (hs : b.Splits) + (hn : ∀x ∈ b.roots, x < 0) (hab : IsCoprime a b) + (h : ∀z : ℂ, 0 < z.im → (cval a z/cval b z).im ≤ 0) + (hpos : ∀t : ℝ, 0 ≤ t → 0 ≤ a.eval t/b.eval t) : + ∃c : ℝ, ∃d : ℝ → ℝ, 0 ≤ c ∧ (∀x ∈ b.roots.toFinset, 0 < d x) ∧ + ∀t : ℝ, 0 ≤ t → a.eval t/b.eval t=c+∑x ∈ b.roots.toFinset, d x/(t-x) := by + classical + have hnodup := simple_roots a b hm.ne_zero hab h + obtain ⟨c,d,he⟩ := simple_decomposition a b hm hs hnodup (degree_le a b hm.ne_zero h hpos) + let s := b.roots.toFinset + have hb : b=∏x ∈ s, (X-C x) := monic_eq_prod_roots b hm hs hnodup + have hv : ∀t : ℝ, 0 ≤ t → a.eval t/b.eval t=c+∑x ∈ s, d x/(t-x) := by + intro t ht + exact decomposition_value a b s c d hb he (fun x hx => ne_of_gt ((hn x (Multiset.mem_toFinset.mp hx)).trans_le ht)) + have hd : ∀x ∈ s, 0 < d x := by + intro x hx + have hx0 : b.eval x=0 := (mem_roots hm.ne_zero).mp (Multiset.mem_toFinset.mp hx) + have ha : a.eval x ≠ 0 := by + simpa [aeval_def,eval₂_at_apply,hx0] using aeval_ne_zero_of_isCoprime hab x + let q : ℝ[X] := ∏y ∈ s.erase x, (X-C y) + have hqx : q.eval x ≠ 0 := by + dsimp [q] + rw [eval_prod] + simp only [eval_sub,eval_X,eval_C] + exact Finset.prod_ne_zero_iff.mpr (fun y hy => sub_ne_zero.mpr (mem_erase.mp hy).1.symm) + have hbe : b=(X-C x)*q := hb.trans (Finset.mul_prod_erase s (fun y : ℝ => X-C y) hx).symm + have hp := pole_test a q (k:=1) (by omega) ha hqx (by + intro z hz + simpa only [hbe,cval_mul,cval_X_sub_C,pow_one] using h z hz) + have hr := residue_value a b s c d hb he hx + exact hr ▸ hp.2 + have hc : 0 ≤ c := by + have hlim : Tendsto (fun t : ℝ => c+∑x ∈ s, d x/(t-x)) atTop (𝓝 c) := by + simpa using tendsto_const_nhds.add (tendsto_finsetSum s (fun x _ => + (tendsto_const_nhds : Tendsto (fun _ : ℝ => d x) atTop (𝓝 (d x))).div_atTop (by simpa only [sub_eq_add_neg,id_eq] using tendsto_atTop_add_const_right atTop (-x) tendsto_id))) + apply ge_of_tendsto hlim + filter_upwards [eventually_ge_atTop (0:ℝ)] with t ht + rw [←hv t ht] + exact hpos t ht + exact ⟨c,d,hc,hd,hv⟩ + +lemma positive_decomposition (a b : ℝ[X]) (hb : b ≠ 0) (hs : b.Splits) + (hreal : ∀t : ℝ, 0 ≤ t → b.eval t ≠ 0) + (hupper : ∀z : ℂ, 0 < z.im → cval b z ≠ 0) + (h : ∀z : ℂ, 0 < z.im → (cval a z/cval b z).im ≤ 0) + (hpos : ∀t : ℝ, 0 ≤ t → 0 ≤ a.eval t/b.eval t) : + ∃s : Finset ℝ, ∃c : ℝ, ∃d : ℝ → ℝ, 0 ≤ c ∧ + (∀x ∈ s, x < 0 ∧ 0 < d x) ∧ + ∀t : ℝ, 0 ≤ t → a.eval t/b.eval t=c+∑x ∈ s, d x/(t-x) := by + classical + let f : RatFunc ℝ := algebraMap ℝ[X] (RatFunc ℝ) a/algebraMap ℝ[X] (RatFunc ℝ) b + have hf : f.num*b=a*f.denom := (RatFunc.num_mul_eq_mul_denom_iff hb).mpr rfl + obtain ⟨g,hg⟩ := RatFunc.denom_div_dvd a b + change b=f.denom*g at hg + have hcf (z : ℂ) (hz : cval b z ≠ 0) : cval f.num z/cval f.denom z=cval a z/cval b z := by + have hd : cval f.denom z ≠ 0 := by + rw [hg,cval_mul] at hz + exact (mul_ne_zero_iff.mp hz).1 + apply (div_eq_div_iff hd hz).mpr + simpa only [cval_mul] using congrArg (fun p => cval p z) hf + have hrf (t : ℝ) (ht : b.eval t ≠ 0) : f.num.eval t/f.denom.eval t=a.eval t/b.eval t := by + have hh := hcf (t:ℂ) (by simpa using ht) + simpa only [cval_real,←Complex.ofReal_div,Complex.ofReal_inj] using hh + have hds : f.denom.Splits := hs.of_dvd hb ⟨g,hg⟩ + have hdn : ∀x ∈ f.denom.roots, x < 0 := by + intro x hx + by_contra hx0 + have hd0 : f.denom.eval x=0 := (mem_roots (RatFunc.denom_ne_zero f)).mp hx + have hb0 : b.eval x=0 := by rw [hg,eval_mul,hd0,zero_mul] + exact hreal x (le_of_not_gt hx0) hb0 + have hdh : ∀z : ℂ, 0 < z.im → (cval f.num z/cval f.denom z).im ≤ 0 := by + intro z hz + rw [hcf z (hupper z hz)] + exact h z hz + have hdp : ∀t : ℝ, 0 ≤ t → 0 ≤ f.num.eval t/f.denom.eval t := by + intro t ht + rw [hrf t (hreal t ht)] + exact hpos t ht + obtain ⟨c,d,hc,hd,hrep⟩ := positive_decomposition_monic f.num f.denom (RatFunc.monic_denom f) + hds hdn (RatFunc.isCoprime_num_denom f) hdh hdp + refine ⟨f.denom.roots.toFinset,c,d,hc,fun x hx => ⟨hdn x (Multiset.mem_toFinset.mp hx),hd x hx⟩,?_⟩ + intro t ht + rw [←hrf t (hreal t ht)] + exact hrep t ht + +end StrongThinTree.MSS.Rational + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/PartitionHierarchy.lean b/lean/OAI/Combinatorics/ThinTrees/PartitionHierarchy.lean new file mode 100644 index 0000000000000000000000000000000000000000..81d0b6c0c28a0953cff9e7f6b474f15b5b1e4e80 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/PartitionHierarchy.lean @@ -0,0 +1,99 @@ +import OAI.Combinatorics.ThinTrees.ChainEdges + +namespace OAI + +section + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset +variable {n m : ℕ} (G : MultiGraph n m) + +lemma connectedOn_cut {A S : Finset (Fin n)} {T : Finset (Fin m)} + (hc : G.ConnectedOn A T) (hS : S.Nonempty) (hSA : S ⊂ A) : (G.cut T S).Nonempty := by + classical + by_contra hcut + have hempty : G.cut T S=∅ := not_nonempty_iff_eq_empty.mp hcut + let f : (Fin n → ℝ) →ₗ[ℝ] ℝ := ∑u ∈ S, LinearMap.proj u + have hker : G.edgeSpan T ≤ LinearMap.ker f := by + apply (Packing.span_le_iff G.incidence).mpr + intro e he + have hiff : G.left e ∈ S ↔ G.right e ∈ S := by + have hh : ¬((G.left e ∈ S ∧ G.right e ∉ S) ∨ (G.right e ∈ S ∧ G.left e ∉ S)) := by + intro h + have hm : e ∈ G.cut T S := mem_filter.mpr ⟨he,h⟩ + simp [hempty] at hm + tauto + change f (G.incidence e)=0 + rw [incidence,map_sub] + change (∑u ∈ S, LinearMap.proj u : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point (G.left e)) - + (∑u ∈ S, LinearMap.proj u : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point (G.right e))=0 + simp only [sumOn_point,hiff,sub_self] + obtain ⟨u,hu⟩ := hS + have hv : (A \ S).Nonempty := sdiff_nonempty.mpr (not_subset.mpr (by + by_contra h + push Not at h + exact (not_ssubset_of_subset h) hSA)) + obtain ⟨v,hv⟩ := hv + obtain ⟨hvA,hvS⟩ := mem_sdiff.mp hv + have hz := hker (hc u (hSA.subset hu) v hvA) + change f (point u-point v)=0 at hz + rw [map_sub] at hz + change (∑w ∈ S, LinearMap.proj w : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point u) - + (∑w ∈ S, LinearMap.proj w : (Fin n → ℝ) →ₗ[ℝ] ℝ) (point v)=0 at hz + simp [sumOn_point,hu,hvS] at hz + +lemma packableOn_edgeConnectedReal {F : Finset (Fin m)} {q : ℕ} {A : Finset (Fin n)} + (hp : G.PackableOn F q A) : G.EdgeConnectedReal A q := by + classical + obtain ⟨T,hT,hd⟩ := hp + intro S hS hSA + have hne (i : Fin q) := G.connectedOn_cut (hT i).2 hS hSA + have hdis : (↑(univ : Finset (Fin q)) : Set (Fin q)).PairwiseDisjoint (fun i => G.cut (T i) S) := by + intro i _ j _ hij + exact disjoint_of_subset_left (filter_subset _ _) (disjoint_of_subset_right (filter_subset _ _) (hd hij)) + have hsub : univ.biUnion (fun i : Fin q => G.cut (T i) S) ⊆ G.cut (G.inducedEdges A) S := by + apply biUnion_subset.mpr + intro i _ e he + obtain ⟨het,hes⟩ := mem_filter.mp he + have hh := (mem_filter.mp ((hT i).1 het)).2 + exact mem_filter.mpr ⟨(G.mem_inducedEdges A e).mpr hh,hes⟩ + have hh := card_le_card hsub + rw [card_biUnion hdis] at hh + have hl : q ≤ ∑i : Fin q, (G.cut (T i) S).card := by + simpa using sum_le_sum (s := (univ : Finset (Fin q))) (f := fun _ => 1) + (g := fun i => (G.cut (T i) S).card) (fun i _ => card_pos.mpr (hne i)) + exact_mod_cast hl.trans hh + +lemma packingParts_vertexPartition (F : Finset (Fin m)) (q : ℕ) : + VertexPartition univ (G.packingParts F q) := by + obtain ⟨hn,hd,hc⟩ := G.packingParts_partition F q + exact ⟨fun A hA => ⟨(hn A hA).1,subset_univ _⟩,hd,hc⟩ + +lemma packingParts_local (F : Finset (Fin m)) (q : ℕ) : + ∀A ∈ G.packingParts F q, G.EdgeConnectedReal A q := by + intro A hA + exact G.packableOn_edgeConnectedReal ((G.packingParts_partition F q).1 A hA).2 + +lemma packingParts_eq_root {F : Finset (Fin m)} {q : ℕ} (hn : 0 < n) + (hp : G.TreePackable F q) : G.packingParts F q={univ} := by + classical + have hu : (univ : Finset (Fin n)).Nonempty := ⟨⟨0,hn⟩,mem_univ _⟩ + have hmax : G.MaxPackable F q univ := ⟨hu,(G.packableOn_univ F q).mpr hp, + fun B hB _ => (Subset.antisymm (subset_univ _) hB)⟩ + have hr : univ ∈ G.packingParts F q := mem_filter.mpr ⟨mem_univ _,hmax⟩ + apply Subset.antisymm + · intro A hA + apply mem_singleton.mpr + rcases G.maxPackable_disjoint (mem_filter.mp hA).2 hmax with h | h + · exact h + · obtain ⟨v,hv⟩ := ((G.packingParts_partition F q).1 A hA).1 + exact False.elim (disjoint_left.mp h hv (mem_univ _)) + · exact singleton_subset_iff.mpr hr + +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/PartitionRank.lean b/lean/OAI/Combinatorics/ThinTrees/PartitionRank.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a52a6c764fb46936431fda6c7102fdba32e6c57 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/PartitionRank.lean @@ -0,0 +1,642 @@ +import OAI.Combinatorics.ThinTrees.BasePacking + +namespace OAI + +universe uE uI uV uE2 uV2 + +section + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset Submodule +variable {n m : ℕ} (G : MultiGraph n m) + +def internal (F : Finset (Fin m)) (A : Finset (Fin n)) : Finset (Fin m) := + F.filter (fun e => G.left e ∈ A ∧ G.right e ∈ A) + +def ConnectedOn (A : Finset (Fin n)) (F : Finset (Fin m)) : Prop := + ∀ u ∈ A, ∀ v ∈ A, G.Same F u v + +def TreeOn (A : Finset (Fin n)) (F : Finset (Fin m)) : Prop := + F ⊆ G.internal univ A ∧ G.ConnectedOn A F ∧ LinearIndepOn ℝ G.incidence (F : Set (Fin m)) + +def PackableOn (F : Finset (Fin m)) (q : ℕ) (A : Finset (Fin n)) : Prop := + ∃ T : Fin q → Finset (Fin m), + (∀ i, T i ⊆ G.internal F A ∧ G.ConnectedOn A (T i)) ∧ + ∀ ⦃i j⦄, i ≠ j → Disjoint (T i) (T j) + +lemma connectedOn_mono_span {A : Finset (Fin n)} {F T : Finset (Fin m)} + (h : G.edgeSpan F ≤ G.edgeSpan T) (hc : G.ConnectedOn A F) : G.ConnectedOn A T := by + intro u hu v hv + exact h (hc u hu v hv) + +lemma connectedOn_mono {A : Finset (Fin n)} {F T : Finset (Fin m)} + (h : F ⊆ T) (hc : G.ConnectedOn A F) : G.ConnectedOn A T := + G.connectedOn_mono_span (Packing.span_mono G.incidence h) hc + +lemma independent_spanning_subset (F : Finset (Fin m)) : + ∃ T ⊆ F, LinearIndepOn ℝ G.incidence (T : Set (Fin m)) ∧ G.edgeSpan T = G.edgeSpan F := by + classical + let h : LinearIndepOn ℝ G.incidence (∅ : Set (Fin m)) := linearIndepOn_empty ℝ G.incidence + let U := h.extend (Set.empty_subset (F : Set (Fin m))) + refine ⟨U.toFinset, ?_, ?_, ?_⟩ + · intro e he + exact h.extend_subset (Set.empty_subset (F : Set (Fin m))) (Set.mem_toFinset.mp he) + · simpa only [Set.coe_toFinset] using h.linearIndepOn_extend (Set.empty_subset (F : Set (Fin m))) + · simpa only [edgeSpan, Packing.span, Set.coe_toFinset] using + h.span_image_extend_eq_span_image (Set.empty_subset (F : Set (Fin m))) + +lemma packableOn_iff_trees (F : Finset (Fin m)) (q : ℕ) (A : Finset (Fin n)) : + G.PackableOn F q A ↔ ∃ T : Fin q → Finset (Fin m), + (∀ i, T i ⊆ F ∧ G.TreeOn A (T i)) ∧ + ∀ ⦃i j⦄, i ≠ j → Disjoint (T i) (T j) := by + classical + constructor + · rintro ⟨T, hT, hd⟩ + choose U hU hi hs using fun i => G.independent_spanning_subset (T i) + refine ⟨U, fun i => ⟨?_, ?_, ?_, hi i⟩, fun i j hij => + disjoint_of_subset_left (hU i) (disjoint_of_subset_right (hU j) (hd hij))⟩ + · exact (hU i).trans ((hT i).1.trans (filter_subset _ _)) + · intro e he + exact mem_filter.mpr ⟨mem_univ _, (mem_filter.mp ((hT i).1 (hU i he))).2⟩ + · exact G.connectedOn_mono_span (le_of_eq (hs i).symm) (hT i).2 + · rintro ⟨T, hT, hd⟩ + refine ⟨T, fun i => ⟨?_, (hT i).2.2.1⟩, hd⟩ + intro e he + exact mem_filter.mpr ⟨(hT i).1 he, (mem_filter.mp ((hT i).2.1 he)).2⟩ + +lemma packableOn_singleton (F : Finset (Fin m)) (q : ℕ) (u : Fin n) : + G.PackableOn F q {u} := by + refine ⟨fun _ => ∅, fun i => ⟨empty_subset _, ?_⟩, fun _ _ _ => disjoint_empty_left _⟩ + intro v hv w hw + simp only [mem_singleton] at hv hw + subst v; subst w + exact G.same_refl _ _ + +lemma packableOn_mono_edges {F F' : Finset (Fin m)} {q : ℕ} {A : Finset (Fin n)} + (h : F ⊆ F') (hp : G.PackableOn F q A) : G.PackableOn F' q A := by + obtain ⟨T, hT, hd⟩ := hp + exact ⟨T, fun i => ⟨(hT i).1.trans (filter_subset_filter _ h), (hT i).2⟩, hd⟩ + +lemma splice_span {A : Finset (Fin n)} {T U : Finset (Fin m)} + (hT : G.ConnectedOn A T) : G.edgeSpan U ≤ G.edgeSpan (T ∪ (U \ G.internal univ A)) := by + apply (Packing.span_le_iff G.incidence).mpr + intro e he + by_cases ha : e ∈ G.internal univ A + · have heA := (mem_filter.mp ha).2 + exact Packing.span_mono G.incidence subset_union_left (hT _ heA.1 _ heA.2) + · exact Packing.mem_span_self G.incidence (mem_union_right _ (mem_sdiff.mpr ⟨he, ha⟩)) + +theorem packableOn_union {F : Finset (Fin m)} {q : ℕ} {A B : Finset (Fin n)} + (hA : G.PackableOn F q A) (hB : G.PackableOn F q B) (hAB : (A ∩ B).Nonempty) : + G.PackableOn F q (A ∪ B) := by + classical + obtain ⟨T, hT, hdT⟩ := hA + obtain ⟨U, hU, hdU⟩ := hB + obtain ⟨w, hw⟩ := hAB + obtain ⟨hwA, hwB⟩ := mem_inter.mp hw + let W := fun i => T i ∪ (U i \ G.internal univ A) + have hconn (i : Fin q) : G.ConnectedOn (A ∪ B) (W i) := by + have h1 : G.ConnectedOn A (W i) := G.connectedOn_mono subset_union_left (hT i).2 + have h2 : G.ConnectedOn B (W i) := G.connectedOn_mono_span (G.splice_span (hT i).2) (hU i).2 + have hs : ∀ v ∈ A ∪ B, G.Same (W i) v w := by + intro v hv + rcases mem_union.mp hv with hv | hv + · exact h1 v hv w hwA + · exact h2 v hv w hwB + intro u hu v hv + exact G.same_trans (hs u hu) (G.same_symm (hs v hv)) + refine ⟨W, fun i => ⟨?_, hconn i⟩, ?_⟩ + · intro e he + rcases mem_union.mp he with he | he + · obtain ⟨heF, hl, hr⟩ := mem_filter.mp ((hT i).1 he) + exact mem_filter.mpr ⟨heF, mem_union_left _ hl, mem_union_left _ hr⟩ + · obtain ⟨heF, hl, hr⟩ := mem_filter.mp ((hU i).1 (mem_sdiff.mp he).1) + exact mem_filter.mpr ⟨heF, mem_union_right _ hl, mem_union_right _ hr⟩ + · intro i j hij + apply disjoint_left.mpr + intro e he hi + rcases mem_union.mp he with he | he <;> rcases mem_union.mp hi with hi | hi + · exact disjoint_left.mp (hdT hij) he hi + · exact (mem_sdiff.mp hi).2 (mem_filter.mpr ⟨mem_univ _, (mem_filter.mp ((hT i).1 he)).2⟩) + · exact (mem_sdiff.mp he).2 (mem_filter.mpr ⟨mem_univ _, (mem_filter.mp ((hT j).1 hi)).2⟩) + · exact disjoint_left.mp (hdU hij) (mem_sdiff.mp he).1 (mem_sdiff.mp hi).1 + +def MaxPackable (F : Finset (Fin m)) (q : ℕ) (A : Finset (Fin n)) : Prop := + A.Nonempty ∧ G.PackableOn F q A ∧ + ∀ B, A ⊆ B → G.PackableOn F q B → B = A + +def packingParts (F : Finset (Fin m)) (q : ℕ) : Finset (Finset (Fin n)) := + by classical exact univ.filter (G.MaxPackable F q) + +lemma exists_maxPackable {F : Finset (Fin m)} {q : ℕ} {A : Finset (Fin n)} + (hA : A.Nonempty) (hp : G.PackableOn F q A) : + ∃ B, A ⊆ B ∧ G.MaxPackable F q B := by + classical + let C : Finset (Finset (Fin n)) := univ.filter (fun B => A ⊆ B ∧ G.PackableOn F q B) + have hC : A ∈ C := by simp [C, hp] + obtain ⟨B, hB, hmax⟩ := exists_max_image C card ⟨A, hC⟩ + obtain ⟨hAB, hpB⟩ := (mem_filter.mp hB).2 + refine ⟨B, hAB, hA.mono hAB, hpB, ?_⟩ + intro D hBD hpD + have hD : D ∈ C := mem_filter.mpr ⟨mem_univ _, hAB.trans hBD, hpD⟩ + exact (eq_of_subset_of_card_le hBD (hmax D hD)).symm + +lemma maxPackable_disjoint {F : Finset (Fin m)} {q : ℕ} {A B : Finset (Fin n)} + (hA : G.MaxPackable F q A) (hB : G.MaxPackable F q B) : A = B ∨ Disjoint A B := by + classical + by_cases h : Disjoint A B + · exact Or.inr h + · have hne : (A ∩ B).Nonempty := not_disjoint_iff_nonempty_inter.mp h + have hp := G.packableOn_union hA.2.1 hB.2.1 hne + exact Or.inl ((hA.2.2 _ subset_union_left hp).symm.trans (hB.2.2 _ subset_union_right hp)) + +lemma maxPackable_contains {F : Finset (Fin m)} {q : ℕ} {A B : Finset (Fin n)} + (hA : G.MaxPackable F q A) (hB : G.PackableOn F q B) (hAB : (A ∩ B).Nonempty) : B ⊆ A := by + have heq := hA.2.2 _ subset_union_left (G.packableOn_union hA.2.1 hB hAB) + exact heq ▸ subset_union_right + +theorem packingParts_partition (F : Finset (Fin m)) (q : ℕ) : + (∀ A ∈ G.packingParts F q, A.Nonempty ∧ G.PackableOn F q A) ∧ + ((G.packingParts F q : Finset (Finset (Fin n))) : Set (Finset (Fin n))).Pairwise Disjoint ∧ + (G.packingParts F q).biUnion id = univ := by + classical + refine ⟨?_, ?_, ?_⟩ + · intro A hA + exact ⟨(mem_filter.mp hA).2.1, (mem_filter.mp hA).2.2.1⟩ + · intro A hA B hB hne + exact (G.maxPackable_disjoint (mem_filter.mp hA).2 (mem_filter.mp hB).2).resolve_left hne + · apply eq_univ_of_forall + intro v + obtain ⟨B, hvB, hB⟩ := G.exists_maxPackable (singleton_nonempty v) (G.packableOn_singleton F q v) + exact mem_biUnion.mpr ⟨B, mem_filter.mpr ⟨mem_univ _, hB⟩, hvB (mem_singleton_self v)⟩ + +theorem packingParts_coarsens {F F' : Finset (Fin m)} {q : ℕ} (h : F ⊆ F') : + ∀ A ∈ G.packingParts F q, ∃ B ∈ G.packingParts F' q, A ⊆ B := by + classical + intro A hA + obtain ⟨hne, hp, hmax⟩ := (mem_filter.mp hA).2 + obtain ⟨B, hAB, hB⟩ := G.exists_maxPackable hne (G.packableOn_mono_edges h hp) + exact ⟨B, mem_filter.mpr ⟨mem_univ _, hB⟩, hAB⟩ + +lemma connectedOn_univ (T : Finset (Fin m)) : G.ConnectedOn univ T ↔ G.Connected T := by + rw [G.connected_iff_same] + simp only [ConnectedOn, mem_univ, forall_const] + +lemma packableOn_univ (F : Finset (Fin m)) (q : ℕ) : + G.PackableOn F q univ ↔ G.TreePackable F q := by + rw [G.packableOn_iff_trees] + constructor + · rintro ⟨T, hT, hd⟩ + refine ⟨T, fun i => ⟨(hT i).1, ?_⟩, hd⟩ + exact (G.spanningTree_iff_independent _).mpr + ⟨(G.connectedOn_univ _).mp (hT i).2.2.1, (hT i).2.2.2⟩ + · rintro ⟨T, hT, hd⟩ + refine ⟨T, fun i => ⟨(hT i).1, ?_, ?_, ?_⟩, hd⟩ + · simp [internal] + · exact (G.connectedOn_univ _).mpr (hT i).2.1 + · exact ((G.spanningTree_iff_independent _).mp (hT i).2).2 + +def vertexProjection (A : Finset (Fin n)) : (Fin n → ℝ) →ₗ[ℝ] (Fin n → ℝ) where + toFun x v := if v ∈ A then x v else 0 + map_add' x y := by ext v; by_cases hv : v ∈ A <;> simp [hv] + map_smul' c x := by ext v; by_cases hv : v ∈ A <;> simp [hv] + +lemma vertexProjection_point (A : Finset (Fin n)) (u : Fin n) : + vertexProjection A (point u) = if u ∈ A then point u else 0 := by + ext v + by_cases hu : u ∈ A <;> by_cases hv : v ∈ A <;> by_cases h : v = u <;> + simp_all [vertexProjection, point] + +lemma restrict_span {F : Finset (Fin m)} {A : Finset (Fin n)} + (h : ∀ e ∈ F, G.left e ∈ A ↔ G.right e ∈ A) {x : Fin n → ℝ} + (hx : x ∈ G.edgeSpan F) : vertexProjection A x ∈ G.edgeSpan (G.internal F A) := by + induction hx using Submodule.span_induction with + | mem x hx => + obtain ⟨e, he, rfl⟩ := hx + have he' : e ∈ F := he + rw [incidence, map_sub, vertexProjection_point, vertexProjection_point] + by_cases hl : G.left e ∈ A + · simp only [ite_eq_left hl, ite_eq_left ((h e he').mp hl)] + exact Packing.mem_span_self G.incidence (mem_filter.mpr ⟨he', hl, (h e he').mp hl⟩) + · simp [hl, not_congr (h e he') |>.mp hl] + | zero => simp + | add x y hx hy ihx ihy => simpa only [map_add] using add_mem ihx ihy + | smul c x hx ih => simpa only [map_smul] using smul_mem _ c ih + +lemma restrict_same {F : Finset (Fin m)} {A : Finset (Fin n)} + (h : ∀ e ∈ F, G.left e ∈ A ↔ G.right e ∈ A) {u v : Fin n} + (hu : u ∈ A) (hv : v ∈ A) (hs : G.Same F u v) : G.Same (G.internal F A) u v := by + have hp := G.restrict_span h hs + change point u - point v ∈ G.edgeSpan (G.internal F A) + simpa only [map_sub, vertexProjection_point, ite_eq_left hu, ite_eq_left hv] using hp + +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.Packing +noncomputable section +open Finset Submodule +variable {E : Type uE} {I : Type uI} {V : Type uV} [Fintype E] [DecidableEq E] [Fintype I] [DecidableEq I] + [AddCommGroup V] [Module ℝ V] [FiniteDimensional ℝ V] + +omit [FiniteDimensional ℝ V] in + +theorem packing_certificate_on (v : E → V) (T : Finset E) : + ∃ (F : I → Finset E) (U : Finset E), Valid v F ∧ + (∀ i, F i ⊆ T) ∧ U ⊆ T ∧ + (∀ i, span v U = span v (F i ∩ U)) ∧ + (∑ i, (F i).card) = (T \ U).card + Fintype.card I * Module.finrank ℝ (span v U) := by + classical + let w : E → V := fun e => if e ∈ T then v e else 0 + obtain ⟨F, hF⟩ := exists_maximal_state (I := I) w + have hsub (i : I) : F.1 i ⊆ T := by + intro e he + have hz := (F.2.1 i).ne_zero he + by_contra h + exact hz (by simp [w, h]) + let U := recycled F ∩ T + have hout {e : E} (he : e ∉ T) : e ∈ recycled F := by + apply mem_recycled.mpr + refine ⟨F, Relation.ReflTransGen.refl, ?_⟩ + intro i hi + exact he (hsub i hi) + have hdiff : univ \ recycled F = T \ U := by + ext e + simp only [mem_sdiff, mem_univ, true_and, U, mem_inter] + constructor + · intro h; exact ⟨by_contra (fun he => h (hout he)), fun he => h he.1⟩ + · rintro ⟨hT, h⟩ hr; exact h ⟨hr, hT⟩ + refine ⟨F.1, U, ⟨?_, F.2.2⟩, hsub, inter_subset_right, ?_, ?_⟩ + · intro i + apply (F.2.1 i).congr + intro e he; simp [w, hsub i he] + · intro i + have hs := span_recycled_eq hF i + change span v (recycled F ∩ T) = span v (F.1 i ∩ (recycled F ∩ T)) + rw [← inter_assoc] + simpa only [w, masked_span] using hs + · have hc := cost_decomposition hF + rw [hdiff] at hc + change cost F = (T \ U).card + Fintype.card I * + Module.finrank ℝ (span (fun e => if e ∈ T then v e else 0) (recycled F)) at hc + rw [masked_span] at hc + exact hc + +end +end StrongThinTree.Packing + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset Submodule +variable {n m : ℕ} (G : MultiGraph n m) + +lemma component_packable_of_certificate {F U : Finset (Fin m)} {q : ℕ} + {T : Fin q → Finset (Fin m)} (hT : ∀ i, T i ⊆ F) + (hd : ∀ ⦃i j⦄, i ≠ j → Disjoint (T i) (T j)) + (hs : ∀ i, G.edgeSpan U = G.edgeSpan (T i ∩ U)) (v : Fin n) : + G.PackableOn F q (univ.filter (fun w => G.rep U w = G.rep U v)) := by + let A := univ.filter (fun w => G.rep U w = G.rep U v) + refine ⟨fun i => G.internal (T i ∩ U) A, fun i => ⟨?_, ?_⟩, ?_⟩ + · exact filter_subset_filter _ (inter_subset_left.trans (hT i)) + · intro u hu w hw + have hu' : G.rep U u = G.rep U v := (mem_filter.mp hu).2 + have hw' : G.rep U w = G.rep U v := (mem_filter.mp hw).2 + have hh : G.Same (T i ∩ U) u w := by + rw [Same, ← hs i] + exact (G.rep_eq_iff U u w).mp (hu'.trans hw'.symm) + refine G.restrict_same ?_ hu hw hh + intro e he + simp only [A, mem_filter, mem_univ, true_and, G.rep_endpoints (mem_inter.mp he).2] + · intro i j hij + exact disjoint_of_subset_left (filter_subset _ _ |>.trans inter_subset_left) + (disjoint_of_subset_right (filter_subset _ _ |>.trans inter_subset_left) (hd hij)) + +def partOf (F : Finset (Fin m)) (q : ℕ) (v : Fin n) : Finset (Fin n) := + Classical.choose (G.exists_maxPackable (singleton_nonempty v) (G.packableOn_singleton F q v)) + +lemma partOf_spec (F : Finset (Fin m)) (q : ℕ) (v : Fin n) : + v ∈ G.partOf F q v ∧ G.MaxPackable F q (G.partOf F q v) := by + have h := Classical.choose_spec (G.exists_maxPackable (singleton_nonempty v) (G.packableOn_singleton F q v)) + exact ⟨h.1 (mem_singleton_self _), h.2⟩ + +lemma partOf_eq_iff (F : Finset (Fin m)) (q : ℕ) (u v : Fin n) : + G.partOf F q u = G.partOf F q v ↔ u ∈ G.partOf F q v := by + constructor + · intro h; rw [← h]; exact (G.partOf_spec F q u).1 + · intro h + rcases G.maxPackable_disjoint (G.partOf_spec F q u).2 (G.partOf_spec F q v).2 with heq | hd + · exact heq + · exact False.elim (disjoint_left.mp hd (G.partOf_spec F q u).1 h) + +lemma partOf_eq_of_mem {F : Finset (Fin m)} {q : ℕ} {A : Finset (Fin n)} + (hA : G.MaxPackable F q A) {v : Fin n} (hv : v ∈ A) : G.partOf F q v = A := by + rcases G.maxPackable_disjoint (G.partOf_spec F q v).2 hA with heq | hd + · exact heq + · exact False.elim (disjoint_left.mp hd (G.partOf_spec F q v).1 hv) + +def partLabel (F : Finset (Fin m)) (q : ℕ) (v : Fin n) : Fin n := + (G.partOf F q v).min' (G.partOf_spec F q v).2.1 + +lemma partLabel_mem (F : Finset (Fin m)) (q : ℕ) (v : Fin n) : + G.partLabel F q v ∈ G.partOf F q v := min'_mem _ _ + +lemma partLabel_eq_iff (F : Finset (Fin m)) (q : ℕ) (u v : Fin n) : + G.partLabel F q u = G.partLabel F q v ↔ G.partOf F q u = G.partOf F q v := by + constructor + · intro h + rcases G.maxPackable_disjoint (G.partOf_spec F q u).2 (G.partOf_spec F q v).2 with heq | hd + · exact heq + · exact False.elim (disjoint_left.mp hd (G.partLabel_mem F q u) (h ▸ G.partLabel_mem F q v)) + · intro h + unfold partLabel + congr 1 + +lemma partLabel_idempotent (F : Finset (Fin m)) (q : ℕ) (v : Fin n) : + G.partLabel F q (G.partLabel F q v) = G.partLabel F q v := by + apply (G.partLabel_eq_iff F q _ _).mpr + exact (G.partOf_eq_iff F q _ _).mpr (G.partLabel_mem F q v) + +lemma partLabel_size (F : Finset (Fin m)) (q : ℕ) : + partitionSize (G.partLabel F q) = (G.packingParts F q).card := by + classical + apply card_bij (fun v _ => G.partOf F q v) + · intro v hv + exact mem_filter.mpr ⟨mem_univ _, (G.partOf_spec F q v).2⟩ + · intro u hu v hv heq + obtain ⟨a, ha, rfl⟩ := mem_image.mp hu + obtain ⟨b, hb, rfl⟩ := mem_image.mp hv + have h := (G.partLabel_eq_iff F q _ _).mpr heq + simpa only [G.partLabel_idempotent] using h + · intro A hA + have hm : G.MaxPackable F q A := (mem_filter.mp hA).2 + obtain ⟨v, hv⟩ := hm.1 + refine ⟨G.partLabel F q v, mem_image.mpr ⟨v, mem_univ _, rfl⟩, ?_⟩ + have heq := G.partOf_eq_of_mem hm hv + exact (G.partOf_eq_iff F q _ _).mpr (G.partLabel_mem F q v) |>.trans heq + +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.Packing +noncomputable section +open Finset Submodule +variable {E : Type uE2} {V : Type uV2} [Fintype E] [DecidableEq E] + [AddCommGroup V] [Module ℝ V] [FiniteDimensional ℝ V] + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] in +lemma span_rank_le_card (v : E → V) (T : Finset E) : + Module.finrank ℝ (span v T) ≤ T.card := by + classical + have h := finrank_span_finset_le_card (R := ℝ) (T.image v) + rw [coe_image] at h + exact h.trans card_image_le + +omit [Fintype E] in +lemma rank_le_sdiff_card_add (v : E → V) (T U : Finset E) : + Module.finrank ℝ (span v T) ≤ (T \ U).card + Module.finrank ℝ (span v U) := by + have hsub : span v T ≤ span v (T \ U) ⊔ span v U := by + apply (span_le_iff v).mpr + intro e he + by_cases h : e ∈ U + · exact (show span v U ≤ span v (T \ U) ⊔ span v U from le_sup_right) (mem_span_self v h) + · exact (show span v (T \ U) ≤ span v (T \ U) ⊔ span v U from le_sup_left) (mem_span_self v (mem_sdiff.mpr ⟨he, h⟩)) + exact (Submodule.finrank_mono hsub).trans + ((show Module.finrank ℝ (span v (T \ U) ⊔ span v U : Submodule ℝ V) ≤ + Module.finrank ℝ (span v (T \ U)) + Module.finrank ℝ (span v U) by + have h := Submodule.finrank_sup_add_finrank_inf_eq (span v (T \ U)) (span v U) + omega).trans (Nat.add_le_add_right (span_rank_le_card v _) _)) + +end +end StrongThinTree.Packing + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset Submodule +variable {n m : ℕ} (G : MultiGraph n m) + +def withinParts (F : Finset (Fin m)) (q : ℕ) : Finset (Fin m) := + F.filter (fun e => G.partLabel F q (G.left e) = G.partLabel F q (G.right e)) + +lemma internal_subset_withinParts {F : Finset (Fin m)} {q : ℕ} {A : Finset (Fin n)} + (hA : G.MaxPackable F q A) : G.internal F A ⊆ G.withinParts F q := by + intro e he + obtain ⟨heF, hl, hr⟩ := mem_filter.mp he + exact mem_filter.mpr ⟨heF, (G.partLabel_eq_iff F q _ _).mpr + ((G.partOf_eq_of_mem hA hl).trans (G.partOf_eq_of_mem hA hr).symm)⟩ + +lemma same_withinParts {F : Finset (Fin m)} {q : ℕ} (hq : 0 < q) (u v : Fin n) : + G.Same (G.withinParts F q) u v ↔ G.partLabel F q u = G.partLabel F q v := by + constructor + · exact G.same_preserves_label (fun e he => (mem_filter.mp he).2) + · intro h + let A := G.partOf F q u + have hA : G.MaxPackable F q A := (G.partOf_spec F q u).2 + have hu : u ∈ A := (G.partOf_spec F q u).1 + have hv : v ∈ A := by + change v ∈ G.partOf F q u + rw [(G.partLabel_eq_iff F q u v).mp h] + exact (G.partOf_spec F q v).1 + obtain ⟨T, hT, hd⟩ := hA.2.1 + let i : Fin q := ⟨0, hq⟩ + exact Packing.span_mono G.incidence + ((hT i).1.trans (G.internal_subset_withinParts hA)) ((hT i).2 u hu v hv) + +lemma componentCount_eq_partitionSize {T : Finset (Fin m)} {p : Fin n → Fin n} + (h : ∀ u v, G.Same T u v ↔ p u = p v) : G.componentCount T = partitionSize p := by + classical + apply card_bij (fun v _ => p v) + · intro v hv; exact mem_image.mpr ⟨v, mem_univ _, rfl⟩ + · intro u hu v hv hp + have hr := (G.rep_eq_iff T u v).mpr ((h u v).mpr hp) + obtain ⟨a, ha, rfl⟩ := mem_image.mp hu + obtain ⟨b, hb, rfl⟩ := mem_image.mp hv + simpa only [G.rep_idempotent] using hr + · intro c hc + obtain ⟨v, hv, rfl⟩ := mem_image.mp hc + exact ⟨G.rep T v, mem_image.mpr ⟨v, mem_univ _, rfl⟩, + (h _ _).mp (G.rep_same T v)⟩ + +lemma withinParts_rank {F : Finset (Fin m)} {q : ℕ} (hq : 0 < q) : + Module.finrank ℝ (G.edgeSpan (G.withinParts F q)) = + n - (G.packingParts F q).card := by + rw [G.incidence_rank, G.componentCount_eq_partitionSize (G.same_withinParts hq), G.partLabel_size] + +lemma withinParts_spanning_packing (F : Finset (Fin m)) (q : ℕ) : + ∃ S : Fin q → Finset (Fin m), + (∀ i, S i ⊆ G.withinParts F q ∧ G.edgeSpan (S i) = G.edgeSpan (G.withinParts F q)) ∧ + ∀ ⦃i j⦄, i ≠ j → Disjoint (S i) (S j) := by + classical + let P := G.packingParts F q + have hp (A : ↥P) : G.PackableOn F q A.val := (mem_filter.mp A.property).2.2.1 + choose T hT hd using hp + let S := fun i => univ.biUnion (fun A : ↥P => T A i) + have hmax (A : ↥P) : G.MaxPackable F q A.val := (mem_filter.mp A.property).2 + have hsub (i : Fin q) : S i ⊆ G.withinParts F q := by + apply biUnion_subset.mpr + intro A hA + exact (hT A i).1.trans (G.internal_subset_withinParts (hmax A)) + refine ⟨S, fun i => ⟨hsub i, ?_⟩, ?_⟩ + · apply le_antisymm (Packing.span_mono G.incidence (hsub i)) + apply (Packing.span_le_iff G.incidence).mpr + intro e he + have heq := (G.partLabel_eq_iff F q _ _).mp (mem_filter.mp he).2 + let A : ↥P := ⟨G.partOf F q (G.left e), mem_filter.mpr ⟨mem_univ _, (G.partOf_spec F q _).2⟩⟩ + have hl : G.left e ∈ A.val := (G.partOf_spec F q _).1 + have hr : G.right e ∈ A.val := by + change G.right e ∈ G.partOf F q (G.left e) + rw [heq] + exact (G.partOf_spec F q _).1 + exact Packing.span_mono G.incidence (subset_biUnion_of_mem (fun A : ↥P => T A i) (mem_univ A)) + ((hT A i).2 _ hl _ hr) + · intro i j hij + apply disjoint_left.mpr + intro e he hi + obtain ⟨A, hA, heA⟩ := mem_biUnion.mp he + obtain ⟨B, hB, heB⟩ := mem_biUnion.mp hi + have hlA := (mem_filter.mp ((hT A i).1 heA)).2.1 + have hlB := (mem_filter.mp ((hT B j).1 heB)).2.1 + have hab : A = B := by + apply Subtype.ext + rcases G.maxPackable_disjoint (hmax A) (hmax B) with heq | hd + · exact heq + · exact False.elim (disjoint_left.mp hd hlA hlB) + subst B + exact disjoint_left.mp (hd A hij) heA heB + +lemma recycled_subset_withinParts {F U : Finset (Fin m)} {q : ℕ} + {T : Fin q → Finset (Fin m)} (hT : ∀ i, T i ⊆ F) (hUF : U ⊆ F) + (hd : ∀ ⦃i j⦄, i ≠ j → Disjoint (T i) (T j)) + (hs : ∀ i, G.edgeSpan U = G.edgeSpan (T i ∩ U)) : U ⊆ G.withinParts F q := by + intro e he + let A := G.partOf F q (G.left e) + let B := univ.filter (fun w => G.rep U w = G.rep U (G.left e)) + have hpB : G.PackableOn F q B := G.component_packable_of_certificate hT hd hs (G.left e) + have hsub := G.maxPackable_contains (G.partOf_spec F q (G.left e)).2 hpB + (show (A ∩ B).Nonempty from ⟨G.left e, mem_inter.mpr ⟨(G.partOf_spec F q _).1, by simp [B]⟩⟩) + have hr : G.right e ∈ A := hsub (by simp only [B, mem_filter, mem_univ, true_and]; exact (G.rep_endpoints he).symm) + have hlabel := (G.partLabel_eq_iff F q (G.right e) (G.left e)).mpr ((G.partOf_eq_iff F q _ _).mpr hr) + exact mem_filter.mpr ⟨hUF he, hlabel.symm⟩ + +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset Submodule +variable {n m : ℕ} (G : MultiGraph n m) + +lemma not_packable_of_parts {F : Finset (Fin m)} {q : ℕ} + (hparts : 1 < (G.packingParts F q).card) : ¬G.TreePackable F q := by + classical + intro hp + have hull := (G.packableOn_univ F q).mpr hp + have hsub : G.packingParts F q ⊆ {univ} := by + intro A hA + have hm : G.MaxPackable F q A := (mem_filter.mp hA).2 + exact mem_singleton.mpr (hm.2.2 _ (subset_univ _) hull).symm + have hc := card_le_card hsub + simp only [card_singleton] at hc + omega + +lemma forest_card_le {T : Finset (Fin m)} (hn : 0 < n) + (hi : LinearIndepOn ℝ G.incidence (T : Set (Fin m))) : T.card ≤ n - 1 := by + have hr := Packing.indep_rank G.incidence hi + change Module.finrank ℝ (G.edgeSpan T) = T.card at hr + rw [G.incidence_rank] at hr + have hp := G.componentCount_pos hn T + omega + +lemma packing_cost_lt {F : Finset (Fin m)} {q : ℕ} (hn : 0 < n) + (hp : ¬G.TreePackable F q) {T : Fin q → Finset (Fin m)} + (hv : Packing.Valid G.incidence T) (hs : ∀ i, T i ⊆ F) : + (∑ i, (T i).card) < q * (n - 1) := by + classical + have hle (i : Fin q) : (T i).card ≤ n - 1 := G.forest_card_le hn (hv.1 i) + have ht : (∑ i, (T i).card) ≤ q * (n - 1) := by + calc + _ ≤ ∑ _i : Fin q, (n - 1) := sum_le_sum (fun i _ => hle i) + _ = _ := by simp + by_contra h + have heq : (∑ i, (T i).card) = ∑ _i : Fin q, (n - 1) := by simpa using (Nat.le_antisymm ht (by omega)) + have hi := (sum_eq_sum_iff_of_le (fun i (_ : i ∈ (univ : Finset (Fin q))) => hle i)).mp heq + apply hp + refine ⟨T, fun i => ⟨hs i, (G.spanningTree_iff_independent _).mpr ⟨?_, hv.1 i⟩⟩, hv.2⟩ + apply G.connected_of_componentCount_eq_one + have hc := hi i (mem_univ i) + have hr := Packing.indep_rank G.incidence (hv.1 i) + change Module.finrank ℝ (G.edgeSpan (T i)) = (T i).card at hr + rw [G.incidence_rank, hc] at hr + have hp := G.componentCount_pos hn (T i) + have hnz : 0 < n := hn + have hcn := G.componentCount_le (T i) + omega + +lemma withinParts_rank_count {F U : Finset (Fin m)} {q : ℕ} : + q * Module.finrank ℝ (G.edgeSpan (G.withinParts F q)) ≤ + (G.withinParts F q \ U).card + q * Module.finrank ℝ (G.edgeSpan U) := by + classical + obtain ⟨S, hS, hd⟩ := G.withinParts_spanning_packing F q + have hi (i : Fin q) : Module.finrank ℝ (G.edgeSpan (G.withinParts F q)) ≤ + (S i \ U).card + Module.finrank ℝ (G.edgeSpan U) := by + rw [← (hS i).2] + exact Packing.rank_le_sdiff_card_add G.incidence (S i) U + have hsum := sum_le_sum (fun i (_ : i ∈ (univ : Finset (Fin q))) => hi i) + simp only [sum_add_distrib, sum_const, card_univ, Fintype.card_fin, smul_eq_mul] at hsum + have hcard : (∑ i, (S i \ U).card) ≤ (G.withinParts F q \ U).card := by + rw [← card_biUnion] + · apply card_le_card + intro e he + obtain ⟨i, hi, he⟩ := mem_biUnion.mp he + exact mem_sdiff.mpr ⟨(hS i).1 (mem_sdiff.mp he).1, (mem_sdiff.mp he).2⟩ + · intro i hi j hj hij + exact disjoint_of_subset_left sdiff_subset (disjoint_of_subset_right sdiff_subset (hd hij)) + exact hsum.trans (Nat.add_le_add_right hcard _) + +theorem packingParts_crossing_lt {F : Finset (Fin m)} {q : ℕ} (hq : 0 < q) + (hparts : 1 < (G.packingParts F q).card) : + (G.crossing F (G.partLabel F q)).card < q * ((G.packingParts F q).card - 1) := by + classical + have hn : 0 < n := by + have hsz := G.partLabel_size F q + have hc : partitionSize (G.partLabel F q) ≤ n := + card_image_le.trans_eq (card_univ.trans (Fintype.card_fin n)) + omega + obtain ⟨T, U, hv, hs, hUF, heq, hcost⟩ := + Packing.packing_certificate_on (I := Fin q) G.incidence F + simp only [Fintype.card_fin] at hcost + have hlt := G.packing_cost_lt hn (G.not_packable_of_parts hparts) hv hs + have hUJ := G.recycled_subset_withinParts hs hUF hv.2 heq + have hJ := G.withinParts_rank_count (F := F) (U := U) (q := q) + rw [G.withinParts_rank hq] at hJ + have hd : (G.withinParts F q \ U).card + (G.crossing F (G.partLabel F q)).card = (F \ U).card := by + have hdis : Disjoint (G.withinParts F q \ U) (G.crossing F (G.partLabel F q)) := by + apply disjoint_left.mpr + intro e he hc + exact (mem_filter.mp hc).2 (mem_filter.mp (mem_sdiff.mp he).1).2 + rw [← card_union_of_disjoint hdis] + congr 1 + ext e + simp only [mem_union, mem_sdiff, withinParts, crossing, mem_filter] + constructor + · rintro (⟨⟨heF, hp⟩, heU⟩ | ⟨heF, hp⟩) + · exact ⟨heF, heU⟩ + · exact ⟨heF, fun heU => hp (mem_filter.mp (hUJ heU)).2⟩ + · rintro ⟨heF, heU⟩ + by_cases hp : G.partLabel F q (G.left e) = G.partLabel F q (G.right e) + · exact Or.inl ⟨⟨heF, hp⟩, heU⟩ + · exact Or.inr ⟨heF, hp⟩ + have hsz : (G.packingParts F q).card ≤ n := by + rw [← G.partLabel_size F q] + exact card_image_le.trans_eq (card_univ.trans (Fintype.card_fin n)) + have hid : n - 1 = (n - (G.packingParts F q).card) + ((G.packingParts F q).card - 1) := by omega + rw [hid, Nat.mul_add, hcost, ← hd] at hlt + change q * (n - (G.packingParts F q).card) ≤ _ + q * Module.finrank ℝ (Packing.span G.incidence U) at hJ + omega + +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Partitions.lean b/lean/OAI/Combinatorics/ThinTrees/Partitions.lean new file mode 100644 index 0000000000000000000000000000000000000000..1b615a0c3ff8dbf89d5abaef39aa69622489cac7 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Partitions.lean @@ -0,0 +1,370 @@ +import OAI.Combinatorics.ThinTrees.Records + +namespace OAI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (H : Hierarchy n) + +lemma predecessor_dichotomy {A t : Finset (Fin n)} {P : Finset (Finset (Fin n))} + (ht : t ∈ H.domain A P) (hP : ∀S ∈ P, S ∈ H.nodes) + {S : Finset (Fin n)} (hS : S ∈ P) : S ⊂ t ∨ Disjoint S t := by + obtain ⟨htn,hta,htP⟩ := H.mem_domain.mp ht + rcases H.laminar S (hP S hS) t htn with hSt | htS | hdis + · left + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨hSt,?_⟩ + intro heq + exact htP S hS (heq ▸ Subset.refl _) + · exact (htP S hS htS).elim + · exact Or.inr hdis + +lemma domain_descendant_partition {A t : Finset (Fin n)} {P : Finset (Finset (Fin n))} + (ht : t ∈ H.domain A P) (hP : ∀S ∈ P, S ∈ H.nodes) : + H.domain t (P.filter (fun S => S ⊂ t)) = + (H.domain A P).filter (fun C => C ⊆ t) := by + obtain ⟨htn,htA,htP⟩ := H.mem_domain.mp ht + ext C + simp only [mem_filter,mem_domain] + constructor + · rintro ⟨hCn,hCt,hCP⟩ + refine ⟨⟨hCn,hCt.trans htA,?_⟩,hCt⟩ + intro S hS hCS + rcases H.predecessor_dichotomy ht hP hS with hSt | hdis + · exact hCP S ⟨hS,hSt⟩ hCS + · obtain ⟨v,hv⟩ := H.nonempty C hCn + exact Finset.disjoint_left.mp hdis (hCS hv) (hCt hv) + · rintro ⟨⟨hCn,hCA,hCP⟩,hCt⟩ + exact ⟨hCn,hCt,fun S hS => hCP S hS.1⟩ + +lemma domain_avoid_partition (A t : Finset (Fin n)) (P : Finset (Finset (Fin n))) : + H.domain A (insert t P) = (H.domain A P).filter (fun C => ¬C ⊆ t) := by + ext C + simp only [mem_domain,mem_filter,mem_insert] + constructor + · rintro ⟨hCn,hCA,hCP⟩ + exact ⟨⟨hCn,hCA,fun S hS => hCP S (Or.inr hS)⟩,hCP t (Or.inl rfl)⟩ + · rintro ⟨⟨hCn,hCA,hCP⟩,hCt⟩ + exact ⟨hCn,hCA,fun S hS => by rcases hS with rfl | hS; exact hCt; exact hCP S hS⟩ + +namespace Record +variable (G : MultiGraph n m) (X : Fin n → Fin h → ℝ) + +def innerRecord (B : Record n) (t : Finset (Fin n)) (a b : ℝ) : Record n := + ⟨RadialShell.hollow B.shell.center a b,t,B.predecessors.filter (fun S => S ⊂ t),none⟩ +def outsideRecord (B : Record n) (t : Finset (Fin n)) (a b : ℝ) : Record n := + ⟨RadialShell.hollow B.shell.center a b,B.owner,B.predecessors,some t⟩ + +lemma central_conflict {B : Record n} (hshape : B.Shape H) (hno : B.avoided = none) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) (a b c d : ℝ) : + (B.innerRecord t a b).conflict H = (B.conflict H).filter (fun C => C ⊆ t) ∧ + (B.outsideRecord t c d).conflict H = (B.conflict H).filter (fun C => ¬C ⊆ t) := by + have heq : B.excluded = B.predecessors := by simp [excluded,hno] + have hP : ∀S ∈ B.predecessors, S ∈ H.nodes := fun S hS => (hshape.2 S (heq.symm ▸ hS)).1 + have ht' : t ∈ H.domain B.owner B.predecessors := by simpa only [conflict,heq] using ht + constructor + · simpa only [conflict,innerRecord,excluded,Option.toFinset_none,union_empty,hno] using + H.domain_descendant_partition ht' hP + · simpa only [conflict,outsideRecord,excluded,Option.toFinset_some,union_singleton,hno,Option.toFinset_none,union_empty] using + H.domain_avoid_partition B.owner t B.predecessors + +lemma central_domain_disjoint {B : Record n} (hshape : B.Shape H) (hno : B.avoided = none) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) (a b c d : ℝ) : + Disjoint ((B.innerRecord t a b).conflict H) ((B.outsideRecord t c d).conflict H) := by + obtain ⟨h1,h2⟩ := central_conflict H hshape hno ht a b c d + rw [h1,h2,Finset.disjoint_left] + intro C hC hD + exact (mem_filter.mp hD).2 (mem_filter.mp hC).2 + +lemma protected_same_side {B : Record n} (hB : B.Protected G X) + {u v : Fin n} {e : Fin m} + (he : (G.left e = u ∧ G.right e = v) ∨ (G.left e = v ∧ G.right e = u)) + (hu : l1dist (X u) (X B.shell.center) < B.shell.outer) : + ∀S ∈ B.predecessors, u ∈ S ↔ v ∈ S := by + intro S hS + have hn : e ∉ G.cut univ S := by + intro hc + have hh := hB S hS e hc + rcases he with he | he + · rw [he.1] at hh + linarith [hh.1] + · rw [he.2] at hh + linarith [hh.2] + simp only [cut,mem_filter,mem_univ,true_and] at hn + rcases he with he | he <;> simp only [he.1,he.2] at hn <;> tauto + +lemma central_valid {q a b δ : ℝ} {B : Record n} + (hB : B.Valid H G X (q/4)) (hno : B.avoided = none) + (hq : 0 ≤ q) (hconn : H.LocallyConnectedReal G q) + {t : Finset (Fin n)} (ht : t ∈ B.conflict H) (htstrict : t ⊂ B.owner) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) + (hδ : 0 < δ) (hab : a+δ < b-δ) + {R : Finset (Fin n)} (hR : R ⊆ H.parent t \ t) + (hRc : G.EdgeConnectedReal R (q/4)) + {u₁ u₂ v₁ v₂ : Fin n} (hu₁ : u₁ ∈ t) (hu₂ : u₂ ∈ t) + (hv₁ : v₁ ∈ R) (hv₂ : v₂ ∈ R) + (hu₁rad : l1dist (X u₁) (X B.shell.center) ≤ a+δ) + (hu₂rad : b-δ ≤ l1dist (X u₂) (X B.shell.center)) + (hv₁rad : l1dist (X v₁) (X B.shell.center) ≤ a) + (hv₂rad : b ≤ l1dist (X v₂) (X B.shell.center)) + {e : Fin m} (he : (G.left e = u₁ ∧ G.right e = v₁) ∨ + (G.left e = v₁ ∧ G.right e = u₁)) : + (B.innerRecord t (a+δ) (b-δ)).Valid H G X (q/4) ∧ + (B.outsideRecord t a b).Valid H G X (q/4) := by + have htn := (H.mem_domain.mp ht).1 + have htne : t ≠ univ := by + intro hh + have := htstrict.not_subset (by simp [hh]) + exact this + have hparent : H.parent t ⊆ B.owner := + H.parent_minimal t htn htne B.owner hB.1.1 htstrict + have hp : ∀S ∈ B.predecessors, S ∈ H.nodes ∧ S ⊂ B.owner := + fun S hS => hB.1.2 S (mem_union_left _ hS) + have htex : t ∈ H.domain B.owner B.predecessors := by + simpa only [conflict,excluded,hno,Option.toFinset_none,union_empty] using ht + have hv₁out : v₁ ∉ t := (mem_sdiff.mp (hR hv₁)).2 + have hsame : ∀S ∈ B.predecessors, u₁ ∈ S ↔ v₁ ∈ S := + protected_same_side G X hB.2.1 he (by linarith) + have huvavoid : ∀S ∈ B.predecessors, u₁ ∉ S ∧ v₁ ∉ S := by + intro S hS + rcases H.predecessor_dichotomy htex (fun S hS => (hp S hS).1) hS with hSt | hdis + · have hvS : v₁ ∉ S := fun hh => hv₁out (hSt.subset hh) + exact ⟨fun hh => hvS ((hsame S hS).mp hh),hvS⟩ + · have huS : u₁ ∉ S := fun hh => Finset.disjoint_left.mp hdis hh hu₁ + exact ⟨huS,fun hh => huS ((hsame S hS).mpr hh)⟩ + constructor + · refine ⟨?_,?_,?_,?_⟩ + · refine ⟨htn,?_⟩ + intro S hS + have hS' : S ∈ B.predecessors ∧ S ⊂ t := by + simpa [excluded,innerRecord] using hS + exact ⟨(hp S hS'.1).1,hS'.2⟩ + · intro S hS e he + have hS' : S ∈ B.predecessors := (mem_filter.mp hS).1 + have hh := hB.2.1 S hS' e he + exact ⟨(by dsimp [innerRecord,RadialShell.hollow]; linarith [hh.1]), + (by dsimp [innerRecord,RadialShell.hollow]; linarith [hh.2])⟩ + · refine ⟨?_,hab,by simp [innerRecord,RadialShell.hollow],⟨u₁,hu₁rad⟩,⟨u₂,hu₂rad⟩⟩ + dsimp [innerRecord,RadialShell.hollow] + linarith [hB.2.2.1.1] + · refine ⟨t,?_,?_,⟨u₁,hu₁,?_,hu₁rad⟩,⟨u₂,hu₂,hu₂rad⟩⟩ + · simp [routing,innerRecord] + · intro S hSn hSt + exact (by linarith : q/4 ≤ q).trans (hconn t htn S hSn hSt) + · apply (mem_leafSet H).mpr + refine ⟨hu₁,?_⟩ + intro S hS + have hS' : S ∈ B.predecessors ∧ S ⊂ t := by + simpa [excluded,innerRecord] using hS + exact (huvavoid S hS'.1).1 + · refine ⟨?_,?_,?_,?_⟩ + · refine ⟨hB.1.1,?_⟩ + intro S hS + have hS' : S ∈ B.predecessors ∨ S = t := by + simpa [excluded,outsideRecord,or_comm] using hS + rcases hS' with hS | rfl + · exact hp S hS + · exact ⟨htn,htstrict⟩ + · intro S hS e he + have hh := hB.2.1 S hS e he + exact ⟨hb.trans hh.1,hb.trans hh.2⟩ + · refine ⟨?_,?_,by simp [outsideRecord,RadialShell.hollow],⟨v₁,hv₁rad⟩,⟨v₂,hv₂rad⟩⟩ + · exact hB.2.2.1.1.trans ha + · dsimp [outsideRecord,RadialShell.hollow] + linarith + · refine ⟨R,?_,hRc,⟨v₁,hv₁,?_,hv₁rad⟩,⟨v₂,hv₂,hv₂rad⟩⟩ + · intro v hv + obtain ⟨hvA,hvt⟩ := mem_sdiff.mp (hR hv) + exact mem_sdiff.mpr ⟨hparent hvA,hvt⟩ + · apply (mem_leafSet H).mpr + refine ⟨hparent (mem_sdiff.mp (hR hv₁)).1,?_⟩ + intro S hS + have hS' : S ∈ B.predecessors ∨ S = t := by + simpa [excluded,outsideRecord,or_comm] using hS + rcases hS' with hS | rfl + · exact (huvavoid S hS).2 + · exact hv₁out + +end Record +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) + +namespace Record + +def Compatible (B D : Record n) : Prop := + Disjoint (B.shell.support X) (D.shell.support X) ∨ Disjoint (B.conflict H) (D.conflict H) + +lemma compatible_symm {B D : Record n} (h : B.Compatible H X D) : D.Compatible H X B := + h.elim (fun h => Or.inl h.symm) (fun h => Or.inr h.symm) + +lemma compatible_self_iff (B : Record n) (hX : ∀v, binary (X v)) + (hshape : B.Shape H) (hvalid : B.shell.Valid X) : ¬B.Compatible H X B := by + intro hh + rcases hh with hh | hh + · obtain ⟨w,hw⟩ := RadialShell.valid_support_nonempty hX hvalid + exact Set.disjoint_left.mp hh hw hw + · exact Finset.disjoint_left.mp hh (B.root_mem H hshape) (B.root_mem H hshape) + +lemma compatible_heredity {B D C : Record n} (hBD : B.Compatible H X D) + (hCB : C.shell.support X ⊆ B.shell.support X) (hCC : C.conflict H ⊆ B.conflict H) : + C.Compatible H X D := by + rcases hBD with hBD | hBD + · exact Or.inl (hBD.mono_left hCB) + · exact Or.inr (hBD.mono_left hCC) + +lemma candidate_ancestor {A B : Record n} (hA : A.Shape H) (hB : B.Shape H) + (horder : B.owner ⊂ A.owner → B.owner ∈ A.excluded) + (hinter : (A.conflict H ∩ B.conflict H).Nonempty) : A.owner ∈ B.conflict H := by + have hroots := (H.domain_root_test hA.1 hB.1 + (fun S hS => (hA.2 S hS).2) (fun S hS => (hB.2 S hS).2)).mp hinter + rcases hroots with hh | hh + · exact hh + · have hba := (H.mem_domain.mp hh).2.1 + by_cases heq : B.owner = A.owner + · exact heq ▸ B.root_mem H hB + · have hs := horder (Finset.ssubset_iff_subset_ne.mpr ⟨hba,heq⟩) + exact ((H.mem_domain.mp hh).2.2 B.owner hs (Subset.refl _)).elim + +lemma insert_compatible {q : ℝ} {Z : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) {A B D : Record n} + (hA : A.Shape H) (hB : B ∈ Z) (hD : D ∈ Z) (hne : B ≠ D) + (hBA : A.owner ∈ B.conflict H) + (horder : ∀F ∈ Z, F.owner ⊂ A.owner → F.owner ∈ A.excluded) + (hAB : A.shell.support X ⊆ B.shell.support X) : A.Compatible H X D := by + by_cases hgeo : Disjoint (A.shell.support X) (D.shell.support X) + · exact Or.inl hgeo + right + by_contra hh + have hinter : (A.conflict H ∩ D.conflict H).Nonempty := by + apply Finset.nonempty_iff_ne_empty.mpr + intro hempty + exact hh (Finset.disjoint_iff_inter_eq_empty.mpr hempty) + have hDA := candidate_ancestor H hA (hZ.1 D hD).1 (horder D hD) hinter + have hBD : ¬Disjoint (B.shell.support X) (D.shell.support X) := + fun hd => hgeo (hd.mono_left hAB) + exact Finset.disjoint_left.mp (hZ.2 hB hD hne hBD) hBA hDA + +def Interior (C δ : ℝ) (A B : Record n) : Prop := + (A.conflict H ∩ B.conflict H).Nonempty ∧ + B.shell.inner+C*δ < l1dist (X A.shell.center) (X B.shell.center) ∧ + l1dist (X A.shell.center) (X B.shell.center) < B.shell.outer-C*δ + +lemma interior_restriction {C δ : ℝ} {A B D : Record n} + (hcenter : D.shell.center = B.shell.center) + (ha : B.shell.inner ≤ D.shell.inner) (hb : D.shell.outer ≤ B.shell.outer) + (hdom : D.conflict H ⊆ B.conflict H) (hh : A.Interior H X C δ D) : + A.Interior H X C δ B := by + obtain ⟨⟨S,hS⟩,hl,hr⟩ := hh + rw [hcenter] at hl hr + exact ⟨⟨S,mem_inter.mpr ⟨(mem_inter.mp hS).1,hdom (mem_inter.mp hS).2⟩⟩, + by linarith,by linarith⟩ + +lemma not_interior_ball {C δ : ℝ} (hC : 1 ≤ C) (hδ : 0 ≤ δ) + (A B : Record n) (hw : B.shell.width ≤ δ) : ¬A.Interior H X C δ B := by + rintro ⟨_,hl,hr⟩ + unfold RadialShell.width at hw + have := mul_le_mul_of_nonneg_right hC hδ + nlinarith + +end Record + +lemma labeled_empty (q : ℝ) : H.LabeledArrangement G X q ∅ := by simp [LabeledArrangement] + +lemma labeled_subset {q : ℝ} {Z W : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) (hW : W ⊆ Z) : + H.LabeledArrangement G X q W := + ⟨fun B hB => hZ.1 B (hW hB),fun _ hB _ hD hne => hZ.2 (hW hB) (hW hD) hne⟩ + +lemma labeled_pair {q : ℝ} {Z : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) {B D : Record n} + (hB : B ∈ Z) (hD : D ∈ Z) (hne : B ≠ D) : B.Compatible H X D := by + by_cases hh : Disjoint (B.shell.support X) (D.shell.support X) + · exact Or.inl hh + · exact Or.inr (hZ.2 hB hD hne hh) + +lemma labeled_union {q : ℝ} {Z W : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) (hW : H.LabeledArrangement G X q W) + (hZW : ∀B ∈ Z, ∀D ∈ W, B.Compatible H X D) : + H.LabeledArrangement G X q (Z∪W) := by + constructor + · intro B hB + exact (mem_union.mp hB).elim (hZ.1 B) (hW.1 B) + · intro B hB D hD hne hgeo + rcases mem_union.mp hB with hB | hB <;> rcases mem_union.mp hD with hD | hD + · exact hZ.2 hB hD hne hgeo + · exact (hZW B hB D hD).resolve_left hgeo + · exact (Record.compatible_symm H X (hZW D hD B hB)).resolve_left hgeo + · exact hW.2 hB hD hne hgeo + +lemma labeled_sets_disjoint (hX : ∀v, binary (X v)) {q : ℝ} {Z W : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) + (hZW : ∀B ∈ Z, ∀D ∈ W, B.Compatible H X D) : Disjoint Z W := by + rw [Finset.disjoint_left] + intro B hB hBW + exact B.compatible_self_iff H X hX (hZ.1 B hB).1 (hZ.1 B hB).2.2.1 (hZW B hB B hBW) + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) + +namespace Record + +def restriction (B : Record n) (a b : ℝ) : Record n := + {B with shell := RadialShell.hollow B.shell.center a b} + +def Refines (D B : Record n) : Prop := + D.shell.support X ⊆ B.shell.support X ∧ D.conflict H ⊆ B.conflict H + +lemma restriction_refines (B : Record n) {a b : ℝ} + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) : + (B.restriction a b).Refines H X B := + ⟨RadialShell.restriction_subset X B.shell ha hb,Subset.refl _⟩ + +lemma compatible_refinements {A B C D : Record n} + (hBD : B.Compatible H X D) (hAB : A.Refines H X B) (hCD : C.Refines H X D) : + A.Compatible H X C := by + have hh := compatible_heredity H X hBD hAB.1 hAB.2 + have hh' := compatible_heredity H X (compatible_symm H X hh) hCD.1 hCD.2 + exact compatible_symm H X hh' + +end Record + +lemma labeled_replace {q : ℝ} {Z W : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) (hW : H.LabeledArrangement G X q W) + (B : Record n) (hcompat : ∀D ∈ Z.erase B, ∀A ∈ W, D.Compatible H X A) : + H.LabeledArrangement G X q (Z.erase B∪W) := + H.labeled_union G X (H.labeled_subset G X hZ (erase_subset _ _)) hW hcompat + +lemma replacement_credit (hX : ∀v, binary (X v)) {q : ℝ} {Z W : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) {B : Record n} (hB : B ∈ Z) + (hcompat : ∀D ∈ Z.erase B, ∀A ∈ W, D.Compatible H X A) + (p : Record n → ℝ) {c : ℝ} (hcredit : p B+c ≤ ∑A ∈ W, p A) : + (∑D ∈ Z, p D)+c ≤ ∑D ∈ Z.erase B∪W, p D := by + have hdis := H.labeled_sets_disjoint G X hX + (H.labeled_subset G X hZ (erase_subset B Z)) hcompat + rw [sum_union hdis] + have hh := sum_erase_add Z p hB + linarith + +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/AffinePencil.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/AffinePencil.lean new file mode 100644 index 0000000000000000000000000000000000000000..2bd99a4ff288e64114307e76e3f78c62bf354842 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/AffinePencil.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Grid + +namespace OAI + +/-! Affine pencil. -/ + +section + +namespace AlgorithmicThinTrees.RationalForms +open Matrix Finset +open scoped BigOperators + +abbrev Affine (d : ℕ) := ℚ × (Fin d → ℚ) + +namespace Affine +variable {d : ℕ} + +def cst (q : ℚ) : Affine d := (q,0) +def coord (i : Fin d) : Affine d := (0,Pi.single i 1) + +noncomputable def real (z : Fin d → ℝ) (a : Affine d) : ℝ := + (a.1:ℝ)+∑i, (a.2 i:ℝ)*z i + +@[simp] lemma real_cst (z : Fin d → ℝ) (q : ℚ) : real z (cst q)=(q:ℝ) := by + simp [real,cst] +@[simp] lemma real_coord (z : Fin d → ℝ) (i : Fin d) : real z (coord i)=z i := by + simp [real,coord,Pi.single_apply,apply_ite,ite_mul] +@[simp] lemma real_zero (z : Fin d → ℝ) : real z (0 : Affine d)=0 := by + simp [real] +@[simp] lemma real_add (z : Fin d → ℝ) (a b : Affine d) : real z (a+b)=real z a+real z b := by + simp [real,add_mul,sum_add_distrib] + ring +@[simp] lemma real_sub (z : Fin d → ℝ) (a b : Affine d) : real z (a-b)=real z a-real z b := by + simp [real,sub_mul,sum_sub_distrib] + ring +@[simp] lemma real_smul (z : Fin d → ℝ) (q : ℚ) (a : Affine d) : + real z (q • a)=(q:ℝ)*real z a := by + simp [real,mul_add,mul_assoc,mul_sum] +@[simp] lemma real_sum {I : Type*} (s : Finset I) (f : I → Affine d) (z : Fin d → ℝ) : + real z (∑i ∈ s,f i)=∑i ∈ s,real z (f i) := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => simp [hi,ih] + +lemma ext_real {a b : Affine d} (h : ∀z : Fin d → ℝ,real z a=real z b) : a=b := by + have hc : a.1=b.1 := by + have hh := h 0 + simp only [real,Pi.zero_apply,mul_zero,sum_const_zero,add_zero] at hh + exact_mod_cast hh + apply Prod.ext hc + funext i + have hh := h (Pi.single i 1) + simp only [real,hc,Pi.single_apply,mul_ite,mul_one,mul_zero,sum_ite_eq',mem_univ, + ite_true,add_right_inj] at hh + exact_mod_cast hh + +end Affine + +def pencil {d N : ℕ} (A : Matrix (Fin N) (Fin N) (Affine d)) (hA : A.IsSymm) : + CurrentKS.RationalSDP.Pencil d N where + constant i j := (A i j).1 + coeff k i j := (A i j).2 k + symmetric_constant := IsSymm.ext fun i j => congrArg Prod.fst (hA.apply i j) + symmetric_coeff k := IsSymm.ext fun i j => congrArg (fun a => a.2 k) (hA.apply i j) + +lemma pencil_realEval {d N : ℕ} (A : Matrix (Fin N) (Fin N) (Affine d)) + (hA : A.IsSymm) (z : Fin d → ℝ) : + (pencil A hA).realEval z=A.map (Affine.real z) := by + ext i j + simp only [CurrentKS.RationalSDP.Pencil.realEval,pencil,Matrix.add_apply,Matrix.map_apply, + Matrix.sum_apply,Matrix.smul_apply,smul_eq_mul,Affine.real] + congr 1 + apply sum_congr rfl + intro k _ + change z k * (((A i j).2 k) : ℝ) = (((A i j).2 k) : ℝ) * z k + ring + +lemma symmetric_of_real {I : Type*} {d : ℕ} (A : Matrix I I (Affine d)) + (h : ∀z, (A.map (Affine.real z)).IsSymm) : A.IsSymm := + IsSymm.ext fun i j => Affine.ext_real (fun z => (h z).apply i j) + +lemma blockDiagonal_psd {I J : Type*} [Fintype I] [Fintype J] [DecidableEq J] + (M : J → Matrix I I ℝ) : (Matrix.blockDiagonal M).PosSemidef ↔ ∀j, (M j).PosSemidef := by + constructor + · intro h j + convert h.submatrix (fun i : I => (i,j)) using 1 + ext i k + simp [Matrix.blockDiagonal] + · intro h + apply PosSemidef.of_dotProduct_mulVec_nonneg + · apply isHermitian_iff_isSymm.mpr + apply IsSymm.ext + intro i k + simp only [Matrix.blockDiagonal,Matrix.of_apply] + by_cases he : i.2=k.2 + · simp only [he,ite_true] + exact (isHermitian_iff_isSymm.mp (h k.2).isHermitian).apply _ _ + · simp only [he,Ne.symm he,ite_false] + · intro v + have hn := sum_nonneg (s:=univ) (fun j _ => (h j).dotProduct_mulVec_nonneg (fun i => v (i,j))) + change 0 ≤ ∑ j, ∑ i, v (i,j)*(∑ k, M j i k*v (k,j)) at hn + rw [sum_comm] at hn + simpa only [dotProduct,Matrix.mulVec,Matrix.blockDiagonal,Matrix.of_apply,Fintype.sum_prod_type, + Pi.star_apply,star_trivial,ite_mul,zero_mul,sum_ite_eq,mem_univ,ite_true] using hn + +lemma blockDiagonal_map {I J : Type*} [DecidableEq J] {d : ℕ} + (M : J → Matrix I I (Affine d)) (z : Fin d → ℝ) : + (Matrix.blockDiagonal M).map (Affine.real z)=Matrix.blockDiagonal (fun j => (M j).map (Affine.real z)) := by + ext i j + simp only [Matrix.blockDiagonal,Matrix.map_apply,Matrix.of_apply] + split_ifs <;> simp + +lemma diagonal_map {I : Type*} [DecidableEq I] {d : ℕ} + (f : I → Affine d) (z : Fin d → ℝ) : + (Matrix.diagonal f).map (Affine.real z)=Matrix.diagonal (fun i => Affine.real z (f i)) := by + ext i j + simp only [Matrix.diagonal,Matrix.map_apply,Matrix.of_apply] + split_ifs <;> simp + +lemma fromBlocks_map {I J : Type*} {d : ℕ} + (A : Matrix I I (Affine d)) (B : Matrix J J (Affine d)) (z : Fin d → ℝ) : + (Matrix.fromBlocks A 0 0 B).map (Affine.real z)= + Matrix.fromBlocks (A.map (Affine.real z)) 0 0 (B.map (Affine.real z)) := by + ext i j + cases i <;> cases j <;> simp + +lemma fromBlocks_psd {I J : Type*} [Fintype I] [Fintype J] + (A : Matrix I I ℝ) (B : Matrix J J ℝ) : + (Matrix.fromBlocks A 0 0 B).PosSemidef ↔ A.PosSemidef ∧ B.PosSemidef := by + constructor + · intro h + exact ⟨h.submatrix Sum.inl,h.submatrix Sum.inr⟩ + · rintro ⟨ha,hb⟩ + apply PosSemidef.of_dotProduct_mulVec_nonneg + · exact Matrix.isHermitian_fromBlocks_iff.mpr ⟨ha.isHermitian,by simp,by simp,hb.isHermitian⟩ + · intro v + simpa only [dotProduct,Fintype.sum_sum_type,Matrix.fromBlocks_mulVec, + Matrix.zero_mulVec,add_zero,zero_add,Sum.elim_inl,Sum.elim_inr, + Pi.star_apply,star_trivial,Function.comp_def] using + add_nonneg (ha.dotProduct_mulVec_nonneg (v ∘ Sum.inl)) + (hb.dotProduct_mulVec_nonneg (v ∘ Sum.inr)) + +lemma submatrix_equiv_psd {I J : Type*} [Fintype I] [Fintype J] + (A : Matrix I I ℝ) (e : J ≃ I) : + (A.submatrix e e).PosSemidef ↔ A.PosSemidef := by + constructor + · intro h + have hh := h.submatrix e.symm + have he : (A.submatrix e e).submatrix e.symm e.symm = A := by ext i j; simp + rw [he] at hh + exact hh + · exact fun h => h.submatrix e + +end AlgorithmicThinTrees.RationalForms +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/BlockAssembly.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/BlockAssembly.lean new file mode 100644 index 0000000000000000000000000000000000000000..aca5fb1349446ecea1ed984566c5681ea5f9c39d --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/BlockAssembly.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Arithmetic.UnaryArithmetic +import OAI.Combinatorics.ThinTrees.Continuation.Interior + +namespace OAI + +/-! Block assembly. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine Matrix KS.W23 + +abbrev BlocksData := ℕ × (List MatrixData × List ℚ) +abbrev blocksCode := prodCode natCode (prodCode (listCode matrixCode) vectorCode) +def stitchEntry (p : (BlocksData×ℕ)×ℕ) : ℚ := + let k := p.1.1.2.1.length + let cut := p.1.1.1*k + if p.1.2 + (List.range (a.1*a.2.1.length+a.2.2.length)).map (fun j => stitchEntry ((a,i),j))) + +abbrev stitchCode := prodCode (prodCode blocksCode natCode) natCode +abbrev stFirst := first (prodCode blocksCode natCode) natCode +abbrev stBlocks := stFirst.then (first blocksCode natCode) +abbrev stI := stFirst.then (second blocksCode natCode) +abbrev stJ := second (prodCode blocksCode natCode) natCode +abbrev stN := stBlocks.then (first natCode (prodCode (listCode matrixCode) vectorCode)) +abbrev stTail := stBlocks.then (second natCode (prodCode (listCode matrixCode) vectorCode)) +abbrev stMatrices := stTail.then (first (listCode matrixCode) vectorCode) +abbrev stScalars := stTail.then (second (listCode matrixCode) vectorCode) +def stK := stMatrices.then (lengthList matrixCode) +instance poly_stK : PolyTime stK := by unfold stK;infer_instance +def stCut := stN.nmul stK +instance poly_stCut : PolyTime stCut := by unfold stCut;infer_instance + +def stitchedMatrixEntry := + let block := ((stI.nmod stK).both stMatrices).then (getD matrixCode []) + (block.both ((stI.ndiv stK).both (stJ.ndiv stK))).then matrixEntry +instance poly_stitchedMatrixEntry : PolyTime stitchedMatrixEntry := by + have : PolyTime stI := by infer_instance + have : PolyTime stJ := by infer_instance + have : PolyTime stMatrices := by infer_instance + unfold stitchedMatrixEntry;infer_instance + +def stitchProgramEntry : Realizes stitchCode ratCode stitchEntry := + let zero := constant stitchCode ratCode 0 + let diag := ((stI.nsub stCut).both stScalars).then (getD ratCode 0) + ((stI.nlt stCut).ite + ((stJ.nlt stCut).ite (((stI.nmod stK).neq (stJ.nmod stK)).ite stitchedMatrixEntry zero) zero) + ((stI.neq stJ).ite diag zero)).congr (by intro p;simp [stitchEntry]) +instance poly_stitchProgramEntry : PolyTime stitchProgramEntry := by + have : PolyTime stI := by infer_instance + have : PolyTime stJ := by infer_instance + have : PolyTime stScalars := by infer_instance + unfold stitchProgramEntry;infer_instance + +def stitchProgram : Realizes blocksCode matrixCode stitchData := + let tail := second natCode (prodCode (listCode matrixCode) vectorCode) + let n := first natCode (prodCode (listCode matrixCode) vectorCode) + let k := tail.then (first (listCode matrixCode) vectorCode) |>.then (lengthList matrixCode) + let l := tail.then (second (listCode matrixCode) vectorCode) |>.then (lengthList ratCode) + let dim := (n.nmul k).nadd l + (((identity blocksCode).both dim).both dim).then stitchProgramEntry.matrixTabulate +instance poly_stitchProgram : PolyTime stitchProgram := by + unfold stitchProgram + apply poly_then + +variable {n k l : ℕ} +lemma stitch_top (B : Fin k → Matrix (Fin n) (Fin n) ℚ) (D : Fin l → ℚ) + (i j : Fin n) (b c : Fin k) : + stitchEntry (((n,(List.ofFn (fun b => matrixData (B b)),List.ofFn D)),b.val+k*i.val),c.val+k*j.val)= + if b=c then B b i j else 0 := by + have hi := (finProdFinEquiv (i,b)).isLt + have hj := (finProdFinEquiv (j,c)).isLt + change b.val+k*i.val matrixData (B b)),List.ofFn D)),b.val+k*i.val),n*k+s.val)=0 := by + have hi := (finProdFinEquiv (i,b)).isLt + change b.val+k*i.val matrixData (B b)),List.ofFn D)),n*k+s.val),c.val+k*j.val)=0 := by + have hj := (finProdFinEquiv (j,c)).isLt + change c.val+k*j.val matrixData (B b)),List.ofFn D)),n*k+s.val),n*k+t.val)= + if s=t then D s else 0 := by + have hnot : ¬ n*k+s.val matrixData (B (eb.symm i))),List.ofFn (fun i => D (es.symm i))))= + matrixData ((Matrix.fromBlocks (Matrix.blockDiagonal B) 0 0 (Matrix.diagonal D)).submatrix + (blockRowEquiv eb es).symm (blockRowEquiv eb es).symm) := by + simp only [stitchData,List.length_ofFn,range_map_fin] + conv_rhs => unfold matrixData + apply congrArg List.ofFn + funext i + apply congrArg List.ofFn + funext j + obtain ⟨i,rfl⟩ := (blockRowEquiv eb es).surjective i + obtain ⟨j,rfl⟩ := (blockRowEquiv eb es).surjective j + simp only [Matrix.submatrix_apply,Equiv.symm_apply_apply] + rcases i with ⟨i,b⟩ | s <;> rcases j with ⟨j,c⟩ | t + · simp only [blockRowEquiv_left] + rw [stitch_top] + simp [Matrix.blockDiagonal,eb.injective.eq_iff] + · simp only [blockRowEquiv_left,blockRowEquiv_right] + rw [stitch_top_bottom] + rfl + · simp only [blockRowEquiv_left,blockRowEquiv_right] + rw [stitch_bottom_top] + rfl + · simp only [blockRowEquiv_right] + rw [stitch_bottom] + simp [Matrix.diagonal_apply,es.injective.eq_iff] +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/FiniteFamilies.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/FiniteFamilies.lean new file mode 100644 index 0000000000000000000000000000000000000000..75b264b05661dc1f81c5ae1d524ae8cf74086e3f --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/FiniteFamilies.lean @@ -0,0 +1,226 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialBranchFamilies +import OAI.Combinatorics.ThinTrees.Arithmetic.UnaryArithmetic +import OAI.Combinatorics.ThinTrees.Continuation.Interior + +namespace OAI + +/-! Finite families. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 + +instance poly_dite {α β : Type*} {ea : α → Word} {eb : β → Word} + {P : α → Prop} [DecidablePred P] + {f : {a // P a} → β} {g : {a // ¬P a} → β} + (test : Realizes ea boolCode (fun a => decide (P a))) + (r : Realizes (fun a : {a // P a} => ea a.val) eb f) + (s : Realizes (fun a : {a // ¬P a} => ea a.val) eb g) + [PolyTime test] [PolyTime r] [PolyTime s] : PolyTime (test.dite r s) := by + refine ⟨?_⟩ + exact (RunsPoly.dite_families + (RunsPoly.of_poly test id (isPoly_self (fun a => (ea a).length))) + (RunsPoly.of_poly r id (isPoly_self (fun a : {a // P a} => (ea a.val).length))) + (RunsPoly.of_poly s id (isPoly_self (fun a : {a // ¬P a} => (ea a.val).length)))).cost + +variable {α β : Type*} {ea : α → Word} {eb : β → Word} +variable {I J : α → Type*} {n m : α → ℕ} + +def indexedCode (ea : α → Word) (e : (a : α) → I a ≃ Fin (n a)) (p : Σ a,I a) : Word := + prodCode ea natCode (p.1,(e p.1 p.2).val) + +def indexedFirst (e : (a : α) → I a ≃ Fin (n a)) : + Realizes (indexedCode ea e) ea (fun p => p.1) := + (first ea natCode).reindex (indexedCode ea e) (fun p => (p.1,(e p.1 p.2).val)) + (fun _ => rfl) +def indexedIndex (e : (a : α) → I a ≃ Fin (n a)) : + Realizes (indexedCode ea e) natCode (fun p => (e p.1 p.2).val) := + (second ea natCode).reindex (indexedCode ea e) (fun p => (p.1,(e p.1 p.2).val)) + (fun _ => rfl) +instance poly_indexedFirst (e : (a : α) → I a ≃ Fin (n a)) : + PolyTime (indexedFirst (ea:=ea) e) := by unfold indexedFirst;apply poly_reindex +instance poly_indexedIndex (e : (a : α) → I a ≃ Fin (n a)) : + PolyTime (indexedIndex (ea:=ea) e) := by unfold indexedIndex;apply poly_reindex + +def Realizes.tabulateIndexed {e : (a : α) → I a ≃ Fin (n a)} {f : (Σ a,I a) → β} + (r : Realizes (indexedCode ea e) eb f) (rn : Realizes ea natCode n) : + Realizes ea (listCode eb) (fun a => List.ofFn (fun i => f ⟨a,(e a).symm i⟩)) := + (r.reindex (finFamilyCode ea n) (fun p => ⟨p.1,(e p.1).symm p.2⟩) + (fun p => by simp only [indexedCode,finFamilyCode,Equiv.apply_symm_apply])).tabulateFin rn +instance poly_tabulateIndexed {e : (a : α) → I a ≃ Fin (n a)} {f : (Σ a,I a) → β} + (r : Realizes (indexedCode ea e) eb f) (rn : Realizes ea natCode n) + [PolyTime r] [PolyTime rn] : PolyTime (r.tabulateIndexed rn) := by + unfold Realizes.tabulateIndexed + refine @poly_tabulateFin _ _ _ _ _ _ _ _ ?_ ?_ + · apply poly_reindex + · infer_instance + +def sumEquiv (e : (a : α) → I a ≃ Fin (n a)) (e' : (a : α) → J a ≃ Fin (m a)) + (a : α) : I a ⊕ J a ≃ Fin (n a+m a) := + ((e a).sumCongr (e' a)).trans finSumFinEquiv + +def sumLeft (_e : (a : α) → I a ≃ Fin (n a)) (_e' : (a : α) → J a ≃ Fin (m a)) + (p : {p : Σ a,I a ⊕ J a // p.2.isLeft=true}) : Σ a,I a := + ⟨p.val.1,p.val.2.getLeft p.property⟩ +def sumRight (_e : (a : α) → I a ≃ Fin (n a)) (_e' : (a : α) → J a ≃ Fin (m a)) + (p : {p : Σ a,I a ⊕ J a // ¬p.2.isLeft=true}) : Σ a,J a := + ⟨p.val.1,p.val.2.getRight (by have hp := p.property; cases h : p.val.2 <;> simp_all)⟩ + +lemma sumLeft_code (e : (a : α) → I a ≃ Fin (n a)) (e' : (a : α) → J a ≃ Fin (m a)) + (p : {p : Σ a,I a ⊕ J a // p.2.isLeft=true}) : + indexedCode ea (sumEquiv e e') p.val=indexedCode ea e (sumLeft e e' p) := by + rcases p with ⟨⟨a,i|j⟩,h⟩ + · rfl + · simp at h + +lemma sumRight_index (e : (a : α) → I a ≃ Fin (n a)) (e' : (a : α) → J a ≃ Fin (m a)) + (p : {p : Σ a,I a ⊕ J a // ¬p.2.isLeft=true}) : + (sumEquiv e e' p.val.1 p.val.2).val-n p.val.1= + (e' (sumRight e e' p).1 (sumRight e e' p).2).val := by + rcases p with ⟨⟨a,i|j⟩,h⟩ + · simp at h + · change n a+(e' a j).val-n a=(e' a j).val + omega + +def indexedSumTest (e : (a : α) → I a ≃ Fin (n a)) (e' : (a : α) → J a ≃ Fin (m a)) + (rn : Realizes ea natCode n) : + Realizes (indexedCode ea (sumEquiv e e')) boolCode + (fun p => decide (p.2.isLeft=true)) := + ((indexedIndex (sumEquiv e e')).nlt ((indexedFirst (sumEquiv e e')).then rn)).congr (by + rintro ⟨a,i|j⟩ + · change decide ((e a i).val + indexedCode ea (sumEquiv e e') p.val) (indexedCode ea e') (sumRight e e') := + let view := (identity (indexedCode ea (sumEquiv e e'))).reindex + (fun p : {p : Σ a,I a ⊕ J a // ¬p.2.isLeft=true} => indexedCode ea (sumEquiv e e') p.val) + Subtype.val (fun _ => rfl) + let a := view.then (indexedFirst (sumEquiv e e')) + let i := view.then (indexedIndex (sumEquiv e e')) + (a.both (i.nsub (a.then rn))).changeOutput (indexedCode ea e') (sumRight e e') (by + intro p + change prodCode ea natCode (p.val.1,(sumEquiv e e' p.val.1 p.val.2).val-n p.val.1) = + prodCode ea natCode ((sumRight e e' p).1,(e' (sumRight e e' p).1 (sumRight e e' p).2).val) + rw [sumRight_index] + rfl) +instance poly_indexedSumRight (e : (a : α) → I a ≃ Fin (n a)) + (e' : (a : α) → J a ≃ Fin (m a)) (rn : Realizes ea natCode n) [PolyTime rn] : + PolyTime (indexedSumRight e e' rn) := by unfold indexedSumRight;infer_instance + +def Realizes.sumCases {e : (a : α) → I a ≃ Fin (n a)} + {e' : (a : α) → J a ≃ Fin (m a)} {f : (Σ a,I a) → β} {g : (Σ a,J a) → β} + (r : Realizes (indexedCode ea e) eb f) (s : Realizes (indexedCode ea e') eb g) + (rn : Realizes ea natCode n) : + Realizes (indexedCode ea (sumEquiv e e')) eb + (fun p => p.2.elim (fun i => f ⟨p.1,i⟩) (fun j => g ⟨p.1,j⟩)) := + ((indexedSumTest e e' rn).dite + (r.reindex (fun p : {p : Σ a,I a ⊕ J a // p.2.isLeft=true} => + indexedCode ea (sumEquiv e e') p.val) (sumLeft e e') (sumLeft_code e e')) + ((indexedSumRight e e' rn).then s)).congr (by + rintro ⟨a,i|j⟩ <;> simp [sumLeft,sumRight]) +instance poly_sumCases {e : (a : α) → I a ≃ Fin (n a)} + {e' : (a : α) → J a ≃ Fin (m a)} {f : (Σ a,I a) → β} {g : (Σ a,J a) → β} + (r : Realizes (indexedCode ea e) eb f) (s : Realizes (indexedCode ea e') eb g) + (rn : Realizes ea natCode n) [PolyTime r] [PolyTime s] [PolyTime rn] : + PolyTime (r.sumCases s rn) := by unfold Realizes.sumCases;infer_instance + +def prodEquiv (e : (a : α) → I a ≃ Fin (n a)) (e' : (a : α) → J a ≃ Fin (m a)) + (a : α) : I a × J a ≃ Fin (n a*m a) := + ((e a).prodCongr (e' a)).trans finProdFinEquiv + +def splitProduct (e : (a : α) → I a ≃ Fin (n a)) (e' : (a : α) → J a ≃ Fin (m a)) + (rm : Realizes ea natCode m) : + Realizes (indexedCode ea (prodEquiv e e')) + (indexedCode (indexedCode ea e) (fun p : Σ a,I a => e' p.1)) + (fun p => ⟨⟨p.1,p.2.1⟩,p.2.2⟩) := + let a := indexedFirst (ea:=ea) (prodEquiv e e') + let i := indexedIndex (ea:=ea) (prodEquiv e e') + (((a.both (i.ndiv (a.then rm))).both (i.nmod (a.then rm)))).changeOutput + (indexedCode (indexedCode ea e) (fun p : Σ a,I a => e' p.1)) + (fun p => ⟨⟨p.1,p.2.1⟩,p.2.2⟩) (by + rintro ⟨a,i,j⟩ + have hj := (e' a j).isLt + have hm : 0 < m a := by omega + change prodCode (prodCode ea natCode) natCode + ((a,((e' a j).val+m a*(e a i).val)/m a), + ((e' a j).val+m a*(e a i).val)%m a)= + prodCode (prodCode ea natCode) natCode ((a,(e a i).val),(e' a j).val) + simp [Nat.add_mul_div_left _ _ hm,Nat.add_mod,Nat.div_eq_of_lt hj,Nat.mod_eq_of_lt hj]) +instance poly_splitProduct (e : (a : α) → I a ≃ Fin (n a)) + (e' : (a : α) → J a ≃ Fin (m a)) (rm : Realizes ea natCode m) [PolyTime rm] : + PolyTime (splitProduct e e' rm) := by unfold splitProduct;infer_instance + +def Realizes.prodCases {e : (a : α) → I a ≃ Fin (n a)} + {e' : (a : α) → J a ≃ Fin (m a)} {f : (Σ p : (Σ a,I a),J p.1) → β} + (r : Realizes (indexedCode (indexedCode ea e) (fun p : Σ a,I a => e' p.1)) eb f) + (rm : Realizes ea natCode m) : + Realizes (indexedCode ea (prodEquiv e e')) eb (fun p => f ⟨⟨p.1,p.2.1⟩,p.2.2⟩) := + (splitProduct e e' rm).then r +instance poly_prodCases {e : (a : α) → I a ≃ Fin (n a)} + {e' : (a : α) → J a ≃ Fin (m a)} {f : (Σ p : (Σ a,I a),J p.1) → β} + (r : Realizes (indexedCode (indexedCode ea e) (fun p : Σ a,I a => e' p.1)) eb f) + (rm : Realizes ea natCode m) [PolyTime r] [PolyTime rm] : + PolyTime (r.prodCases rm) := by unfold Realizes.prodCases;infer_instance + +def indexedProductLeft (e : (a : α) → I a ≃ Fin (n a)) + (e' : (a : α) → J a ≃ Fin (m a)) (rm : Realizes ea natCode m) : + Realizes (indexedCode ea (prodEquiv e e')) (indexedCode ea e) + (fun p => ⟨p.1,p.2.1⟩) := + (splitProduct e e' rm).then (indexedFirst (fun p : Σ a,I a => e' p.1)) +instance poly_indexedProductLeft (e : (a : α) → I a ≃ Fin (n a)) + (e' : (a : α) → J a ≃ Fin (m a)) (rm : Realizes ea natCode m) [PolyTime rm] : + PolyTime (indexedProductLeft e e' rm) := by unfold indexedProductLeft;infer_instance + +def indexedProductRight (e : (a : α) → I a ≃ Fin (n a)) + (e' : (a : α) → J a ≃ Fin (m a)) (rm : Realizes ea natCode m) : + Realizes (indexedCode ea (prodEquiv e e')) (indexedCode ea e') + (fun p => ⟨p.1,p.2.2⟩) := + let s := splitProduct e e' rm + let a := s.then (indexedFirst (fun p : Σ a,I a => e' p.1)) |>.then (indexedFirst e) + let i := s.then (indexedIndex (fun p : Σ a,I a => e' p.1)) + (a.both i).changeOutput (indexedCode ea e') (fun p => ⟨p.1,p.2.2⟩) (fun _ => rfl) +instance poly_indexedProductRight (e : (a : α) → I a ≃ Fin (n a)) + (e' : (a : α) → J a ≃ Fin (m a)) (rm : Realizes ea natCode m) [PolyTime rm] : + PolyTime (indexedProductRight e e' rm) := by unfold indexedProductRight;apply poly_changeOutput + +def Realizes.not {P : α → Prop} [DecidablePred P] + (r : Realizes ea boolCode (fun a => decide (P a))) : + Realizes ea boolCode (fun a => decide (¬ P a)) := + (r.ite (constant ea boolCode false) (constant ea boolCode true)).congr (by intro a;simp) +instance poly_not {P : α → Prop} [DecidablePred P] + (r : Realizes ea boolCode (fun a => decide (P a))) [PolyTime r] : PolyTime r.not := by + unfold Realizes.not;infer_instance + +def Realizes.and {P Q : α → Prop} [DecidablePred P] [DecidablePred Q] + (r : Realizes ea boolCode (fun a => decide (P a))) + (s : Realizes ea boolCode (fun a => decide (Q a))) : + Realizes ea boolCode (fun a => decide (P a ∧ Q a)) := + (r.ite s (constant ea boolCode false)).congr (by intro a;simp) +instance poly_and {P Q : α → Prop} [DecidablePred P] [DecidablePred Q] + (r : Realizes ea boolCode (fun a => decide (P a))) + (s : Realizes ea boolCode (fun a => decide (Q a))) [PolyTime r] [PolyTime s] : PolyTime (r.and s) := by + unfold Realizes.and;infer_instance + +def Realizes.finEq {n : α → ℕ} {f g : (a : α) → Fin (n a)} + (r : Realizes ea natCode (fun a => (f a).val)) + (s : Realizes ea natCode (fun a => (g a).val)) : + Realizes ea boolCode (fun a => decide (f a=g a)) := + (r.neq s).congr (by intro a;simp only [Fin.ext_iff]) +instance poly_finEq {n : α → ℕ} {f g : (a : α) → Fin (n a)} + (r : Realizes ea natCode (fun a => (f a).val)) + (s : Realizes ea natCode (fun a => (g a).val)) [PolyTime r] [PolyTime s] : + PolyTime (r.finEq s) := by unfold Realizes.finEq;infer_instance +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/MatrixConstraintRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/MatrixConstraintRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..c649924ae3eef508be018faa17224f5a5ce4525e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/MatrixConstraintRealization.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Arithmetic.ArraySums +import OAI.Combinatorics.ThinTrees.Pencil.PointPrograms +import OAI.Combinatorics.ThinTrees.Pencil.RationalAffineEval + +namespace OAI + +/-! Matrix constraint realization. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine Matrix +open scoped BigOperators +variable {α : Type*} {ea : α → Word} {I : α → Type*} [∀a,Fintype (I a)] +def Realizes.sumIndexedMatrices {n d : α → ℕ} {e : (a : α) → I a ≃ Fin (n a)} + {A : (a : α) → I a → Matrix (Fin (d a)) (Fin (d a)) ℚ} + (r : Realizes (indexedCode ea e) matrixCode (fun a => matrixData (A a.1 a.2))) + (rn : Realizes ea natCode n) (rd : Realizes ea natCode d) : + Realizes ea matrixCode (fun a => matrixData (∑i,A a i)) := + ((rd.both (r.tabulateIndexed rn)).then matrixSum).congr (by + intro a + rw [matrixSum_data] + exact congrArg matrixData ((e a).symm.sum_comp (A a))) +instance poly_sumIndexedMatrices {n d : α → ℕ} {e : (a : α) → I a ≃ Fin (n a)} + {A : (a : α) → I a → Matrix (Fin (d a)) (Fin (d a)) ℚ} + (r : Realizes (indexedCode ea e) matrixCode (fun a => matrixData (A a.1 a.2))) + (rn : Realizes ea natCode n) (rd : Realizes ea natCode d) + [PolyTime r] [PolyTime rn] [PolyTime rd] : PolyTime (r.sumIndexedMatrices rn rd) := by + unfold Realizes.sumIndexedMatrices;infer_instance +end CurrentKS.Realization + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree RationalForms +open AlgorithmicThinTrees.GraphStack +open scoped BigOperators + +lemma rat_matrixForm {n m : ℕ} (v : Fin (dimension n m) → ℚ) (i j : Fin n) : + Affine.rat v (matrixForm i j)=qresponse (rawMatrix v) i j := by + simp only [matrixForm,Affine.rat_sum,Affine.rat_smul,Affine.rat_add,Affine.rat_coord] + simp only [qresponse,Matrix.mul_apply,Matrix.smul_apply,Matrix.add_apply, + Matrix.transpose_apply,rawMatrix,smul_eq_mul,Finset.sum_mul] + apply Finset.sum_congr rfl + intro b _ + apply Finset.sum_congr rfl + intro a _ + ring + +namespace Stack + +def triangleAt {n : ℕ} (t : Triple n) : Matrix (Fin n) (Fin n) ℚ := + vecMulVec (qdiff t.1 t.2.1) (qdiff t.1 t.2.1)+ + vecMulVec (qdiff t.2.1 t.2.2) (qdiff t.2.1 t.2.2)- + vecMulVec (qdiff t.1 t.2.2) (qdiff t.1 t.2.2) + +def triangleMatrixProgram : Realizes tripleCode matrixCode (fun p => matrixData (triangleAt p.2)) := + let n := triplePoint.then pointN + let ij := (differenceVector n (fun p => p.2.1) (fun p => p.2.2.1) tripleI tripleJ).then + Normalization.Stack.outer + let jk := (differenceVector n (fun p => p.2.2.1) (fun p => p.2.2.2) tripleJ tripleK).then + Normalization.Stack.outer + let ik := (differenceVector n (fun p => p.2.1) (fun p => p.2.2.2) tripleI tripleK).then + Normalization.Stack.outer + (((ij.both jk).then matrixAdd).both ik).then matrixSub |>.congr (by + intro a + dsimp only [KS.W13.ExpressionMachine.BinaryOp.eval] + rw [Normalization.Stack.outer_data,Normalization.Stack.outer_data,Normalization.Stack.outer_data, + matrixAdd_data,matrixSub_data] + rfl) +instance poly_triangleMatrixProgram : PolyTime triangleMatrixProgram := by + have hi : PolyTime tripleI := by infer_instance + have hj : PolyTime tripleJ := by infer_instance + have hk : PolyTime tripleK := by infer_instance + have hn : PolyTime (triplePoint.then pointN) := by infer_instance + have hij : PolyTime ((differenceVector (triplePoint.then pointN) + (fun p => p.2.1) (fun p => p.2.2.1) tripleI tripleJ).then Normalization.Stack.outer) := by + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · exact @poly_differenceVector _ _ _ _ _ _ _ _ hn hi hj + · infer_instance + have hjk : PolyTime ((differenceVector (triplePoint.then pointN) + (fun p => p.2.2.1) (fun p => p.2.2.2) tripleJ tripleK).then Normalization.Stack.outer) := by + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · exact @poly_differenceVector _ _ _ _ _ _ _ _ hn hj hk + · infer_instance + have hik : PolyTime ((differenceVector (triplePoint.then pointN) + (fun p => p.2.1) (fun p => p.2.2.2) tripleI tripleK).then Normalization.Stack.outer) := by + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · exact @poly_differenceVector _ _ _ _ _ _ _ _ hn hi hk + · infer_instance + unfold triangleMatrixProgram + refine @poly_congr _ _ _ _ _ _ _ _ ?_ + apply poly_then + +def weightedTriangle (a : Point) (t : Triple a.p.graph.n) : Matrix (Fin a.p.graph.n) (Fin a.p.graph.n) ℚ := + if t.1≠t.2.1 ∧ t.2.1≠t.2.2 ∧ t.1≠t.2.2 then a.v (mulIndex t) • triangleAt t else 0 + +def weightedTriangleProgram : Realizes tripleCode matrixCode (fun a => matrixData (weightedTriangle a.1 a.2)) := + let val := tripleCoordinate.scaleMatrix triangleMatrixProgram + (tripleDistinct.ite val (triplePoint.then pointN |>.then zeroMatrix)).congr (by + intro a + simp only [weightedTriangle,decide_eq_true_eq] + split_ifs + · exact matrixScale_data _ _ + · rfl) +instance poly_weightedTriangleProgram : PolyTime weightedTriangleProgram := by + unfold weightedTriangleProgram;infer_instance + +lemma weightedTriangle_sum (a : Point) : + ∑t,weightedTriangle a t = ∑t : DistinctTriple a.p.graph.n,a.v (mulIndex t.val) • qtriangle t := by + classical + let P (t : Triple a.p.graph.n) := t.1≠t.2.1 ∧ t.2.1≠t.2.2 ∧ t.1≠t.2.2 + rw [←Fintype.sum_subtype_add_sum_subtype P (weightedTriangle a)] + have hz : ∑ t : {t // ¬ P t}, weightedTriangle a t.val = 0 := by + apply Finset.sum_eq_zero + intro t _ + exact ite_eq_right t.property + rw [hz,add_zero] + apply Finset.sum_congr rfl + intro t _ + unfold weightedTriangle + rw [ite_eq_left t.property] + rfl + +def triangleSum : Realizes pointCode matrixCode (fun a => + matrixData (∑t : DistinctTriple a.p.graph.n,a.v (mulIndex t.val) • qtriangle t)) := + (weightedTriangleProgram.sumIndexedMatrices (A:=weightedTriangle) (pointN.nmul (pointN.nmul pointN)) pointN).congr (by + intro a + rw [weightedTriangle_sum]) +instance poly_triangleSum : PolyTime triangleSum := by unfold triangleSum;infer_instance + +def lowerMatrix : Realizes pointCode matrixCode (fun a => matrixData ((lowerForm a.p.graph.G).map (Affine.rat a.v))) := + ((responsePoint.both lapPoint).then matrixSub).congr (by + intro a + rw [matrixSub_data] + congr 1 + ext i j + simp [lowerForm,rat_matrixForm,Matrix.sub_apply]) +instance poly_lowerMatrix : PolyTime lowerMatrix := by unfold lowerMatrix;infer_instance + +def upperMatrix : Realizes pointCode matrixCode (fun a => matrixData ((upperForm a.p.graph.G).map (Affine.rat a.v))) := + (((((constant pointCode ratCode 3).scaleMatrix lapPoint).both responsePoint).then matrixSub).both triangleSum).then + matrixSub |>.congr (by + intro a + rw [matrixScale_data,matrixSub_data,matrixSub_data] + congr 1 + ext i j + simp only [Matrix.map_apply,upperForm,Affine.rat_sub,Affine.rat_cst,Affine.rat_sum, + Affine.rat_smul,Affine.rat_coord,rat_matrixForm,Matrix.sub_apply,Matrix.smul_apply, + smul_eq_mul,Matrix.sum_apply] + congr 1 + apply Finset.sum_congr rfl + intro t _ + ring) +instance poly_upperMatrix : PolyTime upperMatrix := by unfold upperMatrix;infer_instance + +def edgeMatrix : Realizes (indexedCode pointCode eEquiv) matrixCode (fun a => + matrixData ((matrixBlocks a.1.p.graph.G a.1.p.s a.1.p.u (.inr a.2)).map (Affine.rat a.1.v))) := + let p := indexedFirst (ea:=pointCode) eEquiv + let e := indexedIndex (ea:=pointCode) eEquiv + let isActive := (constant _ ratCode 0).lt (storedU p (fun a => a.2) e) + let atom := ((graphEdge p (fun a => a.2) e).then GraphStack.incidence).then Normalization.Stack.outer + let factor := ((constant _ ratCode 6).mul (p.then pointS)).mul (edgeCoord 0 p (fun a => a.2) e) + let response := ((p.then responsePoint).both (factor.scaleMatrix atom)).then matrixSub + (isActive.ite response (p.then pointN |>.then zeroMatrix)).congr (by + intro a + simp only [decide_eq_true_eq,matrixBlocks] + split_ifs + · rw [Normalization.Stack.outer_data,matrixScale_data,matrixSub_data] + congr 1 + ext i j + simp [edgeForm,rat_matrixForm,Matrix.sub_apply,smul_eq_mul,Matrix.vecMulVec_apply] + ring + · congr 1 + ext i j + simp) +instance poly_edgeMatrix : PolyTime edgeMatrix := by + have hp : PolyTime (indexedFirst (ea:=pointCode) eEquiv) := by infer_instance + have he : PolyTime (indexedIndex (ea:=pointCode) eEquiv) := by infer_instance + unfold edgeMatrix + refine @poly_congr _ _ _ _ _ _ _ _ ?_ + refine @poly_ite _ _ _ _ _ _ _ _ _ _ ?_ ?_ ?_ + · refine @poly_lt _ _ _ _ _ _ ?_ ?_ + · infer_instance + · exact @poly_storedU _ _ _ _ _ _ hp he + · refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · refine @poly_both _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · apply poly_then + · refine @poly_scaleMatrix _ _ _ _ _ _ ?_ ?_ + · refine @poly_mul _ _ _ _ _ _ ?_ ?_ + · refine @poly_mul _ _ _ _ _ _ ?_ ?_ + · infer_instance + · refine @poly_then _ _ _ _ _ _ _ _ _ _ hp ?_ + unfold pointS paramsS + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · infer_instance + · apply poly_paramsField + · exact @poly_edgeCoord _ _ _ _ _ _ _ hp he + · refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · exact @poly_graphEdge _ _ _ _ _ _ hp he + · infer_instance + · infer_instance + · infer_instance + · infer_instance + +abbrev matrixBlockEquiv := sumEquiv (fun _ : Point => Equiv.refl (Fin 2)) eEquiv + +def specialMatrix : Realizes (indexedCode pointCode (fun _ : Point => Equiv.refl (Fin 2))) matrixCode + (fun a => matrixData ((matrixBlocks a.1.p.graph.G a.1.p.s a.1.p.u (.inl a.2)).map (Affine.rat a.1.v))) := + let p := indexedFirst (ea:=pointCode) (fun _ : Point => Equiv.refl (Fin 2)) + let i := indexedIndex (ea:=pointCode) (fun _ : Point => Equiv.refl (Fin 2)) + ((i.finEq (constant _ natCode (0 : Fin 2).val)).ite (p.then lowerMatrix) (p.then upperMatrix)).congr (by + intro a + change (if decide (a.2 = 0) = true then + matrixData ((lowerForm a.1.p.graph.G).map (Affine.rat a.1.v)) else + matrixData ((upperForm a.1.p.graph.G).map (Affine.rat a.1.v))) = + matrixData ((if a.2 = 0 then lowerForm a.1.p.graph.G else + upperForm a.1.p.graph.G).map (Affine.rat a.1.v)) + simp only [decide_eq_true_eq] + split_ifs <;> rfl) +instance poly_specialMatrix : PolyTime specialMatrix := by unfold specialMatrix;infer_instance + +def matrixConstraints : Realizes (indexedCode pointCode matrixBlockEquiv) matrixCode + (fun a => matrixData ((matrixBlocks a.1.p.graph.G a.1.p.s a.1.p.u a.2).map (Affine.rat a.1.v))) := + (specialMatrix.sumCases edgeMatrix (constant pointCode natCode 2)).congr (by + rintro ⟨a,b|e⟩ <;> rfl) +instance poly_matrixConstraints : PolyTime matrixConstraints := by unfold matrixConstraints;infer_instance +end Stack +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/Parameters.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/Parameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..566c09ba9f76491fb9dc33e9a3d9d0118263bf6d --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/Parameters.lean @@ -0,0 +1,166 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.GraphRealization + +namespace OAI + +/-! Pencil parameters. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree +open AlgorithmicThinTrees.GraphStack +open scoped BigOperators + +structure Params where + graph : Graph + s : ℚ + κ : ℚ + t : ℚ + q : ℚ + ε : ℚ + u : Fin graph.m → ℚ + +def Params.pencil (p : Params) := continuationPencil p.graph.G p.s p.κ p.t p.q p.ε p.u +abbrev paramsDataCode := prodCode graphCode (prodCode vectorCode vectorCode) +def Params.data (p : Params) := (p.graph,([p.s,p.κ,p.t,p.q,p.ε],List.ofFn p.u)) +def paramsCode (p : Params) : Word := paramsDataCode p.data +abbrev paramsView : Realizes paramsCode paramsDataCode Params.data := + (identity paramsDataCode).reindex paramsCode Params.data (fun _ => rfl) +private instance poly_paramsView : PolyTime paramsView := by + unfold paramsView + apply poly_reindex + +abbrev paramsGraph : Realizes paramsCode graphCode Params.graph := paramsView.then (first graphCode (prodCode vectorCode vectorCode)) +private instance poly_paramsGraph : PolyTime paramsGraph := by + unfold paramsGraph + apply poly_then + +abbrev paramsTail := paramsView.then (second graphCode (prodCode vectorCode vectorCode)) +abbrev paramsFields := paramsTail.then (first vectorCode vectorCode) +abbrev paramsU := paramsTail.then (second vectorCode vectorCode) +abbrev paramsN : Realizes paramsCode natCode (fun p => p.graph.n) := paramsGraph.then numVertices +abbrev paramsM : Realizes paramsCode natCode (fun p => p.graph.m) := paramsGraph.then numEdges +private instance poly_paramsN : PolyTime paramsN := by + unfold paramsN + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · infer_instance + · unfold numVertices + apply poly_then + +private instance poly_paramsM : PolyTime paramsM := by + unfold paramsM + apply poly_then + +def paramsField (k : ℕ) := ((constant paramsCode natCode k).both paramsFields).then (getD ratCode 0) +instance poly_paramsField (k : ℕ) : PolyTime (paramsField k) := by unfold paramsField;apply poly_then +abbrev paramsS : Realizes paramsCode ratCode Params.s := paramsField 0 +abbrev paramsK : Realizes paramsCode ratCode Params.κ := paramsField 1 +abbrev paramsT : Realizes paramsCode ratCode Params.t := paramsField 2 +abbrev paramsQ : Realizes paramsCode ratCode Params.q := paramsField 3 +abbrev paramsE : Realizes paramsCode ratCode Params.ε := paramsField 4 +abbrev paramsDim := (paramsN.both paramsM).then dimensionProgram + +structure Point where + p : Params + v : Fin (dimension p.graph.n p.graph.m) → ℚ + +def Point.data (a : Point) := (a.p,List.ofFn a.v) +def pointCode (a : Point) : Word := prodCode paramsCode vectorCode a.data +abbrev pointView : Realizes pointCode (prodCode paramsCode vectorCode) Point.data := + (identity (prodCode paramsCode vectorCode)).reindex pointCode Point.data (fun _ => rfl) +private instance poly_pointView : PolyTime pointView := by + unfold pointView + apply poly_reindex + +abbrev pointParams : Realizes pointCode paramsCode Point.p := pointView.then (first paramsCode vectorCode) +private instance poly_pointParams : PolyTime pointParams := by + unfold pointParams + apply poly_then + +abbrev pointVector := pointView.then (second paramsCode vectorCode) +abbrev pointGraph : Realizes pointCode graphCode (fun a => a.p.graph) := pointParams.then paramsGraph +abbrev pointN : Realizes pointCode natCode (fun a => a.p.graph.n) := pointParams.then paramsN +abbrev pointM : Realizes pointCode natCode (fun a => a.p.graph.m) := pointParams.then paramsM +abbrev pointS : Realizes pointCode ratCode (fun a => a.p.s) := pointParams.then paramsS +abbrev pointK : Realizes pointCode ratCode (fun a => a.p.κ) := pointParams.then paramsK +abbrev pointT : Realizes pointCode ratCode (fun a => a.p.t) := pointParams.then paramsT +abbrev pointQ : Realizes pointCode ratCode (fun a => a.p.q) := pointParams.then paramsQ +abbrev pointE : Realizes pointCode ratCode (fun a => a.p.ε) := pointParams.then paramsE +abbrev pointU := pointParams.then paramsU +abbrev pointDim := pointParams.then paramsDim + +def parsePoint (a : Params×List ℚ) : Point := ⟨a.1,fun i => a.2.getD i.val 0⟩ +def pointParser : Realizes (prodCode paramsCode vectorCode) pointCode parsePoint := + let a := first paramsCode vectorCode + let vs := second paramsCode vectorCode + let base := first (prodCode paramsCode vectorCode) natCode + let idx := second (prodCode paramsCode vectorCode) natCode + let val := (idx.both (base.then vs)).then (getD ratCode 0) + (a.both ((((identity (prodCode paramsCode vectorCode)).both (a.then paramsDim)).then val.tabulate))).changeOutput + pointCode parsePoint (by + intro a + change prodCode paramsCode vectorCode (a.1,(List.range _).map _)= + prodCode paramsCode vectorCode (a.1,List.ofFn _) + rw [range_map_fin] + rfl) +instance poly_pointParser : PolyTime pointParser := by + have : PolyTime paramsDim := by unfold paramsDim; apply poly_then + unfold pointParser + apply poly_changeOutput +lemma parsePoint_ofFn (p : Params) (v : Fin (dimension p.graph.n p.graph.m) → ℚ) : + parsePoint (p,List.ofFn v)=⟨p,v⟩ := by + unfold parsePoint + congr 1 + funext i + exact getD_ofFn v i 0 + +variable {α : Type*} {ea : α → Word} {p : α → Point} +def coordinate (rp : Realizes ea pointCode p) + (i : (a : α) → Fin (dimension (p a).p.graph.n (p a).p.graph.m)) + (ri : Realizes ea natCode (fun a => (i a).val)) : + Realizes ea ratCode (fun a => (p a).v (i a)) := + ((ri.both (rp.then pointVector)).then (getD ratCode 0)).congr + (fun a => getD_ofFn (p a).v (i a) 0) +instance poly_coordinate (rp : Realizes ea pointCode p) + (i : (a : α) → Fin (dimension (p a).p.graph.n (p a).p.graph.m)) + (ri : Realizes ea natCode (fun a => (i a).val)) [PolyTime rp] [PolyTime ri] : + PolyTime (coordinate rp i ri) := by unfold coordinate;apply poly_congr + +def rawPoint : Realizes pointCode matrixObjectCode + (fun a => ⟨a.p.graph.n,rawMatrix a.v⟩) := + (pointN.both ((((pointN.both pointM).both pointVector).then raw))).changeOutput + matrixObjectCode (fun a => ⟨a.p.graph.n,rawMatrix a.v⟩) (by + intro a + change prodCode natCode matrixCode (a.p.graph.n, + (List.range a.p.graph.n).map (fun i => (List.range a.p.graph.n).map + (fun j => (List.ofFn a.v).getD (j+a.p.graph.n*i) 0)))=_ + rw [raw_data] + rfl) +instance poly_rawPoint : PolyTime rawPoint := by + have : PolyTime pointN := by unfold pointN; apply poly_then + have : PolyTime pointM := by unfold pointM; apply poly_then + unfold rawPoint + apply poly_changeOutput +abbrev responsePoint := rawPoint.then GraphStack.response +abbrev lapPoint := pointGraph.then laplacian + +def differenceVector {α : Type*} {ea : α → Word} {d : α → ℕ} + (rn : Realizes ea natCode d) (i j : (a : α) → Fin (d a)) + (ri : Realizes ea natCode (fun a => (i a).val)) + (rj : Realizes ea natCode (fun a => (j a).val)) : + Realizes ea vectorCode (fun a => List.ofFn (qdiff (i a) (j a))) := + ((((rn.both ri).then basisVector).both ((rn.both rj).then basisVector)).then vectorSub).congr (by + intro a + rw [basis_data,basis_data] + exact vectorSub_data _ _) +instance poly_differenceVector {α : Type*} {ea : α → Word} {d : α → ℕ} + (rn : Realizes ea natCode d) (i j : (a : α) → Fin (d a)) + (ri : Realizes ea natCode (fun a => (i a).val)) + (rj : Realizes ea natCode (fun a => (j a).val)) + [PolyTime rn] [PolyTime ri] [PolyTime rj] : PolyTime (differenceVector rn i j ri rj) := by + unfold differenceVector;infer_instance +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/PointPrograms.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/PointPrograms.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f0e8b270df751b62aa67550915965f0baeb015a --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/PointPrograms.lean @@ -0,0 +1,180 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Pencil.FiniteFamilies +import OAI.Combinatorics.ThinTrees.Pencil.Parameters + +namespace OAI + +/-! Point programs. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine +variable {α β : Type*} {ea : α → Word} {eb : β → Word} +def Realizes.cons {f : α → β} {g : α → List β} + (r : Realizes ea eb f) (s : Realizes ea (listCode eb) g) : + Realizes ea (listCode eb) (fun a => f a :: g a) := (r.both s).then (consList eb) +instance poly_cons {f : α → β} {g : α → List β} + (r : Realizes ea eb f) (s : Realizes ea (listCode eb) g) [PolyTime r] [PolyTime s] : + PolyTime (r.cons s) := by unfold Realizes.cons;infer_instance + +def select3 {i : α → Fin 3} (ri : Realizes ea natCode (fun a => (i a).val)) + {f g h : α → ℚ} (r : Realizes ea ratCode f) (s : Realizes ea ratCode g) + (t : Realizes ea ratCode h) : Realizes ea ratCode (fun a => ![f a,g a,h a] (i a)) := + ((ri.both (r.cons (s.cons (t.then (singleton ratCode))))).then (getD ratCode 0)).congr (by + intro a + exact getD_ofFn ![f a,g a,h a] (i a) 0) +instance poly_select3 {i : α → Fin 3} (ri : Realizes ea natCode (fun a => (i a).val)) + {f g h : α → ℚ} (r : Realizes ea ratCode f) (s : Realizes ea ratCode g) + (t : Realizes ea ratCode h) [PolyTime ri] [PolyTime r] [PolyTime s] [PolyTime t] : + PolyTime (select3 ri r s t) := by unfold select3;apply poly_congr + +def select7 {i : α → Fin 7} (ri : Realizes ea natCode (fun a => (i a).val)) + {f₀ f₁ f₂ f₃ f₄ f₅ f₆ : α → ℚ} + (r₀ : Realizes ea ratCode f₀) (r₁ : Realizes ea ratCode f₁) (r₂ : Realizes ea ratCode f₂) + (r₃ : Realizes ea ratCode f₃) (r₄ : Realizes ea ratCode f₄) (r₅ : Realizes ea ratCode f₅) + (r₆ : Realizes ea ratCode f₆) : + Realizes ea ratCode (fun a => ![f₀ a,f₁ a,f₂ a,f₃ a,f₄ a,f₅ a,f₆ a] (i a)) := + ((ri.both (r₀.cons (r₁.cons (r₂.cons (r₃.cons (r₄.cons (r₅.cons + (r₆.then (singleton ratCode))))))))).then (getD ratCode 0)).congr (by + intro a + exact getD_ofFn ![f₀ a,f₁ a,f₂ a,f₃ a,f₄ a,f₅ a,f₆ a] (i a) 0) +instance poly_select7 {i : α → Fin 7} (ri : Realizes ea natCode (fun a => (i a).val)) + {f₀ f₁ f₂ f₃ f₄ f₅ f₆ : α → ℚ} + (r₀ : Realizes ea ratCode f₀) (r₁ : Realizes ea ratCode f₁) (r₂ : Realizes ea ratCode f₂) + (r₃ : Realizes ea ratCode f₃) (r₄ : Realizes ea ratCode f₄) (r₅ : Realizes ea ratCode f₅) + (r₆ : Realizes ea ratCode f₆) [PolyTime ri] [PolyTime r₀] [PolyTime r₁] [PolyTime r₂] + [PolyTime r₃] [PolyTime r₄] [PolyTime r₅] [PolyTime r₆] : + PolyTime (select7 ri r₀ r₁ r₂ r₃ r₄ r₅ r₆) := by unfold select7;apply poly_congr +end CurrentKS.Realization + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree +open AlgorithmicThinTrees.GraphStack +open scoped BigOperators +variable {α : Type*} {ea : α → Word} {a : α → Point} + +private theorem poly_nadd_explicit {f g : α → ℕ} + {r : Realizes ea natCode f} {s : Realizes ea natCode g} + (hr : PolyTime r) (hs : PolyTime s) : PolyTime (r.nadd s) := by + have := hr + have := hs + infer_instance + +private theorem poly_nmul_explicit {f g : α → ℕ} + {r : Realizes ea natCode f} {s : Realizes ea natCode g} + (hr : PolyTime r) (hs : PolyTime s) : PolyTime (r.nmul s) := by + have := hr + have := hs + infer_instance + +def edgeCoord (p : Fin 3) (r : Realizes ea pointCode a) + (e : (b : α) → Fin (a b).p.graph.m) (re : Realizes ea natCode (fun b => (e b).val)) : + Realizes ea ratCode (fun b => (a b).v (edgeIndex p (e b))) := + let n := r.then pointN + let m := r.then pointM + coordinate r (fun b => edgeIndex p (e b)) + ((n.nmul n).nadd ((n.nmul (n.nmul n)).nadd (re.nadd (m.nmul (constant ea natCode p.val))))) +instance poly_edgeCoord (p : Fin 3) (r : Realizes ea pointCode a) + (e : (b : α) → Fin (a b).p.graph.m) (re : Realizes ea natCode (fun b => (e b).val)) + [PolyTime r] [PolyTime re] : PolyTime (edgeCoord p r e re) := by + have hn : PolyTime (r.then pointN) := by infer_instance + have hm : PolyTime (r.then pointM) := by infer_instance + unfold edgeCoord + refine @poly_coordinate _ _ _ _ _ _ ?_ ?_ + · infer_instance + · exact poly_nadd_explicit (poly_nmul_explicit hn hn) + (poly_nadd_explicit (poly_nmul_explicit hn (poly_nmul_explicit hn hn)) + (poly_nadd_explicit ‹PolyTime re› + (poly_nmul_explicit hm (poly_constant ea natCode p.val)))) + +def flowCoord (p : Fin 2) (r : Realizes ea pointCode a) + (v : (b : α) → Fin (a b).p.graph.n) (e : (b : α) → Fin (a b).p.graph.m) + (rv : Realizes ea natCode (fun b => (v b).val)) (re : Realizes ea natCode (fun b => (e b).val)) : + Realizes ea ratCode (fun b => (a b).v (flowIndex p (v b) (e b))) := + let n := r.then pointN + let m := r.then pointM + coordinate r (fun b => flowIndex p (v b) (e b)) + ((n.nmul n).nadd ((n.nmul (n.nmul n)).nadd + (((constant ea natCode 3).nmul m).nadd + ((re.nadd (m.nmul rv)).nadd ((n.nmul m).nmul (constant ea natCode p.val)))))) +instance poly_flowCoord (p : Fin 2) (r : Realizes ea pointCode a) + (v : (b : α) → Fin (a b).p.graph.n) (e : (b : α) → Fin (a b).p.graph.m) + (rv : Realizes ea natCode (fun b => (v b).val)) (re : Realizes ea natCode (fun b => (e b).val)) + [PolyTime r] [PolyTime rv] [PolyTime re] : PolyTime (flowCoord p r v e rv re) := by + have hn : PolyTime (r.then pointN) := by infer_instance + have hm : PolyTime (r.then pointM) := by infer_instance + unfold flowCoord + refine @poly_coordinate _ _ _ _ _ _ ?_ ?_ + · infer_instance + · exact poly_nadd_explicit (poly_nmul_explicit hn hn) + (poly_nadd_explicit (poly_nmul_explicit hn (poly_nmul_explicit hn hn)) + (poly_nadd_explicit (poly_nmul_explicit (poly_constant ea natCode 3) hm) + (poly_nadd_explicit (poly_nadd_explicit ‹PolyTime re› (poly_nmul_explicit hm ‹PolyTime rv›)) + (poly_nmul_explicit (poly_nmul_explicit hn hm) (poly_constant ea natCode p.val))))) + +def storedU (r : Realizes ea pointCode a) + (e : (b : α) → Fin (a b).p.graph.m) (re : Realizes ea natCode (fun b => (e b).val)) : + Realizes ea ratCode (fun b => (a b).p.u (e b)) := + ((re.both (r.then pointU)).then (getD ratCode 0)).congr (fun b => getD_ofFn _ (e b) 0) +instance poly_storedU (r : Realizes ea pointCode a) + (e : (b : α) → Fin (a b).p.graph.m) (re : Realizes ea natCode (fun b => (e b).val)) + [PolyTime r] [PolyTime re] : PolyTime (storedU r e re) := by unfold storedU;apply poly_congr + +def graphEdge (r : Realizes ea pointCode a) + (e : (b : α) → Fin (a b).p.graph.m) (re : Realizes ea natCode (fun b => (e b).val)) : + Realizes ea GraphStack.edgeCode (fun b => ⟨(a b).p.graph,e b⟩) := + ((r.then pointGraph).both re).changeOutput GraphStack.edgeCode (fun b => ⟨(a b).p.graph,e b⟩) + (fun _ => rfl) +instance poly_graphEdge (r : Realizes ea pointCode a) + (e : (b : α) → Fin (a b).p.graph.m) (re : Realizes ea natCode (fun b => (e b).val)) + [PolyTime r] [PolyTime re] : PolyTime (graphEdge r e re) := by unfold graphEdge;apply poly_changeOutput + +abbrev vEquiv (a : Point) := Equiv.refl (Fin a.p.graph.n) +abbrev eEquiv (a : Point) := Equiv.refl (Fin a.p.graph.m) +abbrev pairEquiv := prodEquiv vEquiv vEquiv +abbrev tripleEquiv := prodEquiv vEquiv pairEquiv +abbrev tripleCode := indexedCode pointCode tripleEquiv +abbrev triplePoint := indexedFirst (ea:=pointCode) tripleEquiv +abbrev tripleHead := indexedProductLeft (ea:=pointCode) vEquiv pairEquiv (pointN.nmul pointN) +abbrev tripleTail := indexedProductRight (ea:=pointCode) vEquiv pairEquiv (pointN.nmul pointN) +abbrev pairHead := indexedProductLeft (ea:=pointCode) vEquiv vEquiv pointN +abbrev pairTail := indexedProductRight (ea:=pointCode) vEquiv vEquiv pointN +abbrev tripleI := tripleHead.then (indexedIndex vEquiv) +abbrev tripleJ := tripleTail.then pairHead |>.then (indexedIndex vEquiv) +abbrev tripleK := tripleTail.then pairTail |>.then (indexedIndex vEquiv) + +def tripleCoordinate : Realizes tripleCode ratCode (fun p => p.1.v (mulIndex p.2)) := + let n := triplePoint.then pointN + coordinate triplePoint (fun p => mulIndex p.2) + ((n.nmul n).nadd ((tripleK.nadd (n.nmul tripleJ)).nadd ((n.nmul n).nmul tripleI))) +instance poly_tripleCoordinate : PolyTime tripleCoordinate := by + have hi : PolyTime tripleI := by infer_instance + have hj : PolyTime tripleJ := by infer_instance + have hk : PolyTime tripleK := by infer_instance + have hn : PolyTime (triplePoint.then pointN) := by infer_instance + unfold tripleCoordinate + refine @poly_coordinate _ _ _ _ _ _ ?_ ?_ + · infer_instance + · exact poly_nadd_explicit (poly_nmul_explicit hn hn) + (poly_nadd_explicit (poly_nadd_explicit hk (poly_nmul_explicit hn hj)) + (poly_nmul_explicit (poly_nmul_explicit hn hn) hi)) + +def tripleDistinct : Realizes tripleCode boolCode + (fun p => decide (p.2.1≠p.2.2.1 ∧ p.2.2.1≠p.2.2.2 ∧ p.2.1≠p.2.2.2)) := + (tripleI.finEq tripleJ).not.and ((tripleJ.finEq tripleK).not.and (tripleI.finEq tripleK).not) +instance poly_tripleDistinct : PolyTime tripleDistinct := by + have : PolyTime tripleI := by infer_instance + have : PolyTime tripleJ := by infer_instance + have : PolyTime tripleK := by infer_instance + unfold tripleDistinct + refine @poly_and _ _ _ _ _ _ _ _ ?_ ?_ + · infer_instance + · refine @poly_and _ _ _ _ _ _ _ _ ?_ ?_ + · infer_instance + · apply poly_not + +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/RationalAffineEval.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/RationalAffineEval.lean new file mode 100644 index 0000000000000000000000000000000000000000..85394e873f2ed9c40157db16fc6c848000bafb9c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/RationalAffineEval.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Pencil.AffinePencil + +namespace OAI + +/-! Rational affine eval. -/ + +section + + +namespace AlgorithmicThinTrees.RationalForms +open Matrix Finset +open scoped BigOperators +namespace Affine +variable {d : ℕ} +def rat (v : Fin d → ℚ) (a : Affine d) : ℚ := a.1+∑i,a.2 i*v i +@[simp] lemma rat_cst (v : Fin d → ℚ) (q : ℚ) : rat v (cst q)=q := by simp [rat,cst] +@[simp] lemma rat_coord (v : Fin d → ℚ) (i : Fin d) : rat v (coord i)=v i := by + simp [rat,coord,Pi.single_apply,ite_mul] +@[simp] lemma rat_zero (v : Fin d → ℚ) : rat v (0 : Affine d)=0 := by simp [rat] +@[simp] lemma rat_add (v : Fin d → ℚ) (a b : Affine d) : rat v (a+b)=rat v a+rat v b := by + simp [rat,add_mul,sum_add_distrib];ring +@[simp] lemma rat_sub (v : Fin d → ℚ) (a b : Affine d) : rat v (a-b)=rat v a-rat v b := by + simp [rat,sub_mul,sum_sub_distrib];ring +@[simp] lemma rat_smul (v : Fin d → ℚ) (q : ℚ) (a : Affine d) : rat v (q • a)=q*rat v a := by + simp [rat,mul_add,mul_assoc,mul_sum] +@[simp] lemma rat_sum {I : Type*} (s : Finset I) (f : I → Affine d) (v : Fin d → ℚ) : + rat v (∑i ∈ s,f i)=∑i ∈ s,rat v (f i) := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => simp [hi,ih] +lemma cast_rat (v : Fin d → ℚ) (a : Affine d) : + (rat v a : ℝ)=real (fun i => (v i:ℝ)) a := by simp [rat,real] +end Affine +lemma pencil_eval {d N : ℕ} (A : Matrix (Fin N) (Fin N) (Affine d)) (hA : A.IsSymm) + (v : Fin d → ℚ) : (pencil A hA).eval v=A.map (Affine.rat v) := by + ext i j + simp only [CurrentKS.RationalSDP.Pencil.eval,pencil,Matrix.map_apply,Affine.rat] + erw [Matrix.add_apply,Matrix.sum_apply] + congr 1 + apply sum_congr rfl + intro k _ + change v k * (A i j).2 k = (A i j).2 k * v k + ring +end AlgorithmicThinTrees.RationalForms +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/Realization.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/Realization.lean new file mode 100644 index 0000000000000000000000000000000000000000..a97e4716dd30cf3520283946da1711c153861047 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/Realization.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Pencil.BlockAssembly +import OAI.Combinatorics.ThinTrees.Pencil.MatrixConstraintRealization +import OAI.Combinatorics.ThinTrees.Pencil.ScalarConstraintRealization + +namespace OAI + +/-! Pencil realization. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree RationalForms +open AlgorithmicThinTrees.GraphStack + +abbrev matrixCount := (constant pointCode natCode 2).nadd pointM +abbrev scalarCount := (pointN.nmul (pointN.nmul pointN)).nadd + (((constant pointCode natCode 7).nmul pointM).nadd + (((constant pointCode natCode 3).nmul (pointN.nmul pointM)).nadd + ((pointN.nmul pointN).nadd (constant pointCode natCode 1)))) + +instance poly_matrixCount : PolyTime matrixCount := by unfold matrixCount;infer_instance +instance poly_scalarCount : PolyTime scalarCount := by unfold scalarCount;infer_instance + +lemma rowIndex_blocks (a : Point) : + blockRowEquiv (n:=a.p.graph.n) (matrixBlockEquiv a) (scalarEquiv a)= + rowIndex a.p.graph.n a.p.graph.m := by + apply Equiv.ext + intro i + rcases i with ⟨i,b|e⟩ | (t | (e | (f | (v | u)))) <;> rfl + +lemma affineMatrix_rat (a : Point) : + (affineMatrix a.p.graph.G a.p.s a.p.κ a.p.t a.p.q a.p.ε a.p.u).map (Affine.rat a.v)= + (Matrix.fromBlocks + (Matrix.blockDiagonal (fun b => (matrixBlocks a.p.graph.G a.p.s a.p.u b).map (Affine.rat a.v))) + 0 0 (Matrix.diagonal (scalarValue a))).submatrix + (rowIndex a.p.graph.n a.p.graph.m).symm (rowIndex a.p.graph.n a.p.graph.m).symm := by + ext i j + obtain ⟨i,rfl⟩ := (rowIndex a.p.graph.n a.p.graph.m).surjective i + obtain ⟨j,rfl⟩ := (rowIndex a.p.graph.n a.p.graph.m).surjective j + simp only [affineMatrix,Matrix.map_apply,Matrix.submatrix_apply,Equiv.symm_apply_apply] + rcases i with ⟨i,b⟩ | s <;> rcases j with ⟨j,c⟩ | t + · simp only [Matrix.fromBlocks_apply₁₁,Matrix.blockDiagonal,Matrix.of_apply] + split_ifs <;> simp + · simp + · simp + · by_cases h : s=t <;> simp [scalarValue,h] + +def affinePoint : Realizes pointCode matrixCode (fun a => + matrixData ((affineMatrix a.p.graph.G a.p.s a.p.κ a.p.t a.p.q a.p.ε a.p.u).map (Affine.rat a.v))) := + ((pointN.both ((matrixConstraints.tabulateIndexed matrixCount).both + (scalarConstraints.tabulateIndexed scalarCount))).then stitchProgram).congr (by + intro a + have h := stitch_data (n:=a.p.graph.n) (matrixBlockEquiv a) (scalarEquiv a) + (fun b => (matrixBlocks a.p.graph.G a.p.s a.p.u b).map (Affine.rat a.v)) (scalarValue a) + rw [rowIndex_blocks] at h + exact h.trans (congrArg matrixData (affineMatrix_rat a)).symm) +instance poly_affinePoint : PolyTime affinePoint := by + have : PolyTime pointN := by infer_instance + unfold affinePoint;infer_instance + +def pencilEval := pointParser.then affinePoint +instance poly_pencilEval : PolyTime pencilEval := by unfold pencilEval;infer_instance + +lemma pencilEval_data (p : Params) (v : Fin (dimension p.graph.n p.graph.m) → ℚ) : + matrixData ((affineMatrix (parsePoint (p,List.ofFn v)).p.graph.G + (parsePoint (p,List.ofFn v)).p.s (parsePoint (p,List.ofFn v)).p.κ + (parsePoint (p,List.ofFn v)).p.t (parsePoint (p,List.ofFn v)).p.q + (parsePoint (p,List.ofFn v)).p.ε (parsePoint (p,List.ofFn v)).p.u).map + (Affine.rat (parsePoint (p,List.ofFn v)).v)) = matrixData (p.pencil.eval v) := by + rw [parsePoint_ofFn] + unfold Params.pencil continuationPencil + rw [pencil_eval] + +def buildPencil : Realizes paramsCode pencilCode (fun p => pencilData p.pencil) := + (((identity paramsCode).both paramsDim).then pencilEval.pencilFromEval).congr (by + intro p + apply pencilFromEval_data + exact pencilEval_data p) +instance poly_buildPencil : PolyTime buildPencil := by unfold buildPencil;infer_instance +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/ScalarConstraintRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/ScalarConstraintRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..d1fa2ca30c1ce58f209216cf0b1ffeab7255e12a --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/ScalarConstraintRealization.lean @@ -0,0 +1,262 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Arithmetic.ArraySums +import OAI.Combinatorics.ThinTrees.Pencil.PointPrograms +import OAI.Combinatorics.ThinTrees.Pencil.RationalAffineEval + +namespace OAI + +/-! Scalar constraint realization. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree RationalForms +open AlgorithmicThinTrees.GraphStack +open scoped BigOperators + +private theorem scalar_poly_pointField (k : ℕ) : PolyTime (pointParams.then (paramsField k)) := by + apply poly_then + +def scalarValue (a : Point) (b : ScalarBlock a.p.graph.n a.p.graph.m) : ℚ := + Affine.rat a.v (scalarForms a.p.graph.G a.p.κ a.p.t a.p.q a.p.ε a.p.u b) + +def scalarTriple : Realizes tripleCode ratCode (fun p => scalarValue p.1 (.inl p.2)) := + (tripleDistinct.ite tripleCoordinate (constant tripleCode ratCode 0)).congr (by + intro p + simp only [decide_eq_true_eq,scalarValue,scalarForms] + split_ifs <;> simp) +instance poly_scalarTriple : PolyTime scalarTriple := by unfold scalarTriple;infer_instance + +abbrev edgeScalarEquiv := prodEquiv (fun _ : Point => Equiv.refl (Fin 7)) eEquiv +abbrev edgeScalarCode := indexedCode pointCode edgeScalarEquiv +abbrev esPoint := indexedFirst (ea:=pointCode) edgeScalarEquiv +abbrev esP := (indexedProductLeft (ea:=pointCode) (fun _ : Point => Equiv.refl (Fin 7)) + eEquiv pointM).then (indexedIndex (fun _ : Point => Equiv.refl (Fin 7))) +abbrev esEdge := indexedProductRight (ea:=pointCode) (fun _ : Point => Equiv.refl (Fin 7)) eEquiv pointM +abbrev esE := esEdge.then (indexedIndex eEquiv) +private theorem poly_esE : PolyTime esE := by + unfold esE + apply poly_then + +def esY := edgeCoord 0 esPoint (fun p => p.2.2) esE +def esZ := edgeCoord 1 esPoint (fun p => p.2.2) esE +def esX := edgeCoord 2 esPoint (fun p => p.2.2) esE +def esU := storedU esPoint (fun p => p.2.2) esE +instance poly_esY : PolyTime esY := by + unfold esY + refine @poly_edgeCoord _ _ _ _ _ _ _ ?_ poly_esE + infer_instance +instance poly_esZ : PolyTime esZ := by + unfold esZ + refine @poly_edgeCoord _ _ _ _ _ _ _ ?_ poly_esE + infer_instance +instance poly_esX : PolyTime esX := by + unfold esX + refine @poly_edgeCoord _ _ _ _ _ _ _ ?_ poly_esE + infer_instance +instance poly_esU : PolyTime esU := by + unfold esU + refine @poly_storedU _ _ _ _ _ _ ?_ poly_esE + infer_instance +abbrev esK := esPoint.then pointK +abbrev esT := esPoint.then pointT + +def esActive := (constant edgeScalarCode ratCode 0).lt esU +instance poly_esActive : PolyTime esActive := by unfold esActive;infer_instance + +def esCapacityRate : Realizes edgeScalarCode ratCode (fun a => + if 0 + if 0 scalarValue a.1 (.inr (.inl a.2))) := + (select7 esP esY ((constant _ ratCode 1).sub esY) esZ + ((esK.add (constant _ ratCode 1)).sub esZ) esCapacityRate esX (esCapacity.sub esX)).congr (by + rintro ⟨a,p,e⟩ + change ![a.v (edgeIndex 0 e),1-a.v (edgeIndex 0 e),a.v (edgeIndex 1 e), + a.p.κ+1-a.v (edgeIndex 1 e), + if 0 by_cases hu : 0 simp [scalarValue,scalarForms,capacityForm,hu]) +instance poly_scalarEdge : PolyTime scalarEdge := by + have : PolyTime esP := by infer_instance + have hk : PolyTime pointK := scalar_poly_pointField 1 + have : PolyTime esK := by unfold esK; apply poly_then + unfold scalarEdge;infer_instance + +abbrev rootEdgeEquiv := prodEquiv vEquiv eEquiv +abbrev rootEdgeCode := indexedCode pointCode rootEdgeEquiv +abbrev rePoint := indexedFirst (ea:=pointCode) rootEdgeEquiv +abbrev reR := (indexedProductLeft (ea:=pointCode) vEquiv eEquiv pointM).then (indexedIndex vEquiv) +abbrev reE := (indexedProductRight (ea:=pointCode) vEquiv eEquiv pointM).then (indexedIndex eEquiv) +private theorem poly_reR : PolyTime reR := by + unfold reR + apply poly_then + +private theorem poly_reE : PolyTime reE := by + unfold reE + apply poly_then + +def reA := flowCoord 0 rePoint (fun a => a.2.1) (fun a => a.2.2) reR reE +def reB := flowCoord 1 rePoint (fun a => a.2.1) (fun a => a.2.2) reR reE +def reX := edgeCoord 2 rePoint (fun a => a.2.2) reE +instance poly_reA : PolyTime reA := by + unfold reA + refine @poly_flowCoord _ _ _ _ _ _ _ _ _ ?_ poly_reR poly_reE + infer_instance +instance poly_reB : PolyTime reB := by + unfold reB + refine @poly_flowCoord _ _ _ _ _ _ _ _ _ ?_ poly_reR poly_reE + infer_instance +instance poly_reX : PolyTime reX := by + unfold reX + refine @poly_edgeCoord _ _ _ _ _ _ _ ?_ poly_reE + infer_instance + +abbrev flowScalarEquiv := prodEquiv (fun _ : Point => Equiv.refl (Fin 3)) rootEdgeEquiv +abbrev flowScalarCode := indexedCode pointCode flowScalarEquiv +abbrev fsRE := indexedProductRight (ea:=pointCode) (fun _ : Point => Equiv.refl (Fin 3)) rootEdgeEquiv + (pointN.nmul pointM) +abbrev fsP := (indexedProductLeft (ea:=pointCode) (fun _ : Point => Equiv.refl (Fin 3)) rootEdgeEquiv + (pointN.nmul pointM)).then (indexedIndex (fun _ : Point => Equiv.refl (Fin 3))) + +def scalarFlow : Realizes flowScalarCode ratCode + (fun a => scalarValue a.1 (.inr (.inr (.inl a.2)))) := + (select3 fsP (fsRE.then reA) (fsRE.then reB) + (((fsRE.then reA).add (fsRE.then reB)).sub (fsRE.then reX))).congr (by + rintro ⟨a,p,r,e⟩ + change ![a.v (flowIndex 0 r e),a.v (flowIndex 1 r e), + a.v (flowIndex 0 r e)+a.v (flowIndex 1 r e)-a.v (edgeIndex 2 e)] p = _ + fin_cases p <;> simp [scalarValue,scalarForms]) +instance poly_scalarFlow : PolyTime scalarFlow := by + have : PolyTime fsP := by infer_instance + have : PolyTime fsRE := by infer_instance + unfold scalarFlow;infer_instance + +abbrev budgetCode := indexedCode pointCode pairEquiv +abbrev bsPoint := indexedFirst (ea:=pointCode) pairEquiv +abbrev bsR := pairHead.then (indexedIndex vEquiv) +abbrev bsV := pairTail.then (indexedIndex vEquiv) +abbrev budgetEdgeCode := finFamilyCode budgetCode (fun a => a.1.p.graph.m) +abbrev beBudget : Realizes budgetEdgeCode budgetCode (fun a => a.1) := familyFirst +abbrev beE : Realizes budgetEdgeCode natCode (fun a => a.2.val) := familyIndex +abbrev bePoint := beBudget.then bsPoint +abbrev beR := beBudget.then bsR +abbrev beV := beBudget.then bsV +abbrev beGraphEdge := graphEdge bePoint (fun a => a.2) beE +def beA := flowCoord 0 bePoint (fun a => a.1.2.1) (fun a => a.2) beR beE +def beB := flowCoord 1 bePoint (fun a => a.1.2.1) (fun a => a.2) beR beE +instance poly_beA : PolyTime beA := by + have hr : PolyTime beR := by infer_instance + unfold beA + refine @poly_flowCoord _ _ _ _ _ _ _ _ _ ?_ hr ?_ + all_goals infer_instance +instance poly_beB : PolyTime beB := by + have hr : PolyTime beR := by infer_instance + unfold beB + refine @poly_flowCoord _ _ _ _ _ _ _ _ _ ?_ hr ?_ + all_goals infer_instance + +def budgetEdge : Realizes budgetEdgeCode ratCode (fun a => + (if a.1.1.p.graph.G.left a.2=a.1.2.2 then a.1.1.v (flowIndex 0 a.1.2.1 a.2) else 0)+ + (if a.1.1.p.graph.G.right a.2=a.1.2.2 then a.1.1.v (flowIndex 1 a.1.2.1 a.2) else 0)) := + ((((beGraphEdge.then GraphStack.edgeLeft).finEq beV).ite beA (constant _ ratCode 0)).add + (((beGraphEdge.then GraphStack.edgeRight).finEq beV).ite beB (constant _ ratCode 0))).congr + (by + intro a + change ((if decide (a.1.1.p.graph.G.left a.2 = a.1.2.2) = true then + a.1.1.v (flowIndex 0 a.1.2.1 a.2) else 0) + + (if decide (a.1.1.p.graph.G.right a.2 = a.1.2.2) = true then + a.1.1.v (flowIndex 1 a.1.2.1 a.2) else 0)) = _ + simp only [decide_eq_true_eq]) +instance poly_budgetEdge : PolyTime budgetEdge := by + have : PolyTime beGraphEdge := by infer_instance + have : PolyTime beV := by infer_instance + unfold budgetEdge;infer_instance + +def budgetIncoming := budgetEdge.sumFin (n:=fun a : Σ b : Point,Fin b.p.graph.n × Fin b.p.graph.n => a.1.p.graph.m) + (f:=fun a e => (if a.1.p.graph.G.left e=a.2.2 then a.1.v (flowIndex 0 a.2.1 e) else 0)+ + (if a.1.p.graph.G.right e=a.2.2 then a.1.v (flowIndex 1 a.2.1 e) else 0)) (bsPoint.then pointM) +instance poly_budgetIncoming : PolyTime budgetIncoming := by unfold budgetIncoming;infer_instance + +def scalarBudget : Realizes budgetCode ratCode + (fun a => scalarValue a.1 (.inr (.inr (.inr (.inl a.2))))) := + ((((bsV.finEq bsR).ite (bsPoint.then pointE) (bsPoint.then pointQ)).sub budgetIncoming)).congr (by + rintro ⟨a,r,v⟩ + simp only [scalarValue,scalarForms,Affine.rat_sub,Affine.rat_cst,Affine.rat_sum,Affine.rat_add, + decide_eq_true_eq] + congr 1 + apply Finset.sum_congr rfl + intro e _ + split_ifs <;> simp) +instance poly_scalarBudget : PolyTime scalarBudget := by + have : PolyTime bsV := by infer_instance + have : PolyTime bsR := by infer_instance + have hq : PolyTime pointQ := scalar_poly_pointField 3 + have he : PolyTime pointE := scalar_poly_pointField 4 + unfold scalarBudget + apply poly_congr + +abbrev xePoint : Realizes (finFamilyCode pointCode (fun a => a.p.graph.m)) pointCode (fun a => a.1) := familyFirst +abbrev xeE : Realizes (finFamilyCode pointCode (fun a => a.p.graph.m)) natCode (fun a => a.2.val) := familyIndex +def edgeTotal := (edgeCoord 2 xePoint (fun a => a.2) xeE).sumFin (n:=fun a : Point => a.p.graph.m) + (f:=fun a e => a.v (edgeIndex 2 e)) pointM +instance poly_edgeTotal : PolyTime edgeTotal := by unfold edgeTotal;infer_instance + +def scalarTotalBase : Realizes pointCode ratCode (fun a => scalarValue a (.inr (.inr (.inr (.inr 0))))) := + (edgeTotal.sub ((pointQ.mul ((pointN.then natToRat).sub (constant _ ratCode 1))).sub pointE)).congr (by + intro a + simp only [scalarValue,scalarForms,Affine.rat_sub,Affine.rat_cst,Affine.rat_sum,Affine.rat_coord]) +instance poly_scalarTotalBase : PolyTime scalarTotalBase := by + have hq : PolyTime pointQ := scalar_poly_pointField 3 + have he : PolyTime pointE := scalar_poly_pointField 4 + unfold scalarTotalBase + apply poly_congr + +def scalarTotal : Realizes (indexedCode pointCode (fun _ : Point => Equiv.refl (Fin 1))) ratCode + (fun a => scalarValue a.1 (.inr (.inr (.inr (.inr a.2))))) := + ((indexedFirst (fun _ : Point => Equiv.refl (Fin 1))).then scalarTotalBase).congr (fun _ => rfl) +instance poly_scalarTotal : PolyTime scalarTotal := by unfold scalarTotal; apply poly_congr + +abbrev scalarEquiv := sumEquiv tripleEquiv (sumEquiv edgeScalarEquiv + (sumEquiv flowScalarEquiv (sumEquiv pairEquiv (fun _ : Point => Equiv.refl (Fin 1))))) +abbrev scalarCode := indexedCode pointCode scalarEquiv + +def scalarConstraints : Realizes scalarCode ratCode (fun a => scalarValue a.1 a.2) := + (scalarTriple.sumCases (scalarEdge.sumCases (scalarFlow.sumCases + (scalarBudget.sumCases scalarTotal (pointN.nmul pointN)) + ((constant _ natCode 3).nmul (pointN.nmul pointM))) + ((constant _ natCode 7).nmul pointM)) (pointN.nmul (pointN.nmul pointN))).congr (by + rintro ⟨a,b⟩ + rcases b with t | b + · rfl + rcases b with e | b + · rfl + rcases b with f | b + · rfl + rcases b with v | b <;> rfl) +instance poly_scalarConstraints : PolyTime scalarConstraints := by unfold scalarConstraints;infer_instance + +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Pencil/SearchRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Pencil/SearchRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..1dc725ed1d759cee7de402e91b3d626e85bcdf2d --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Pencil/SearchRealization.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialVariance +import OAI.Combinatorics.ThinTrees.Pencil.Parameters +import OAI.Combinatorics.ThinTrees.Pencil.Realization + +namespace OAI + +/-! Search realization. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree +open AlgorithmicThinTrees.GraphStack + +abbrev graphDim := (numVertices.both numEdges).then dimensionProgram +abbrev graphSizeProgram := ((numVertices.then natToRat).add (numEdges.then natToRat)).add + (constant graphCode ratCode 2) +def graphRadius : Realizes graphCode ratCode (fun G => radiusQ G.n G.m) := + ((constant graphCode ratCode 1).div (graphSizeProgram.pow 50)).congr (by + intro G; simp only [radiusQ,_root_.zpow_neg,one_div];rfl) +instance poly_graphRadius : PolyTime graphRadius := by unfold graphRadius;infer_instance + +def graphBound : Realizes graphCode ratCode (fun G => boundQ G.n G.m) := + ((constant graphCode ratCode 6).mul graphSizeProgram).mul + ((graphDim.then natToRat).add (constant graphCode ratCode 1)) +instance poly_graphBound : PolyTime graphBound := by + unfold graphBound + refine @poly_mul _ _ _ _ _ _ ?_ ?_ + · infer_instance + · refine @poly_add _ _ _ _ _ _ ?_ ?_ + · apply poly_then + · infer_instance + +def graphZeros : Realizes graphCode vectorCode (fun G => List.ofFn (0 : Fin (dimension G.n G.m) → ℚ)) := + (((constant graphCode ratCode 0).both graphDim).then (replicateList ratCode)).congr + (by + intro G + change List.replicate (dimension G.n G.m) 0 = List.ofFn (fun _ : Fin (dimension G.n G.m) => (0 : ℚ)) + rw [List.ofFn_const]) +instance poly_graphZeros : PolyTime graphZeros := by unfold graphZeros;infer_instance + +def Params.searchState (p : Params) : SearchState := + ⟨dimension p.graph.n p.graph.m,order p.graph.n p.graph.m,p.pencil, + radiusQ p.graph.n p.graph.m,boundQ p.graph.n p.graph.m,0⟩ + +def initializeSearch : Realizes paramsCode searchStateCode Params.searchState := + (buildPencil.both + (((paramsGraph.then graphRadius).both (paramsGraph.then graphBound)).both + (paramsGraph.then graphZeros))).changeOutput searchStateCode Params.searchState (fun _ => rfl) +instance poly_initializeSearch : PolyTime initializeSearch := by unfold initializeSearch; apply poly_changeOutput + +def solvePencil : Realizes paramsCode vectorCode (fun p => + List.ofFn (p.pencil.search (radiusQ p.graph.n p.graph.m) (boundQ p.graph.n p.graph.m) 0)) := + initializeSearch.then CurrentKS.Realization.search + +lemma isPoly_graph_n : IsPoly (fun G => (graphCode G).length) Graph.n := by + have h := (RunsPoly.of_poly numVertices id (isPoly_self (fun G => (graphCode G).length))).output + simpa only [id_eq,natCode,List.length_replicate,Graph.data] using h +lemma isPoly_graph_m : IsPoly (fun G => (graphCode G).length) Graph.m := by + have h := (RunsPoly.of_poly numEdges id (isPoly_self (fun G => (graphCode G).length))).output + simpa only [id_eq,natCode,List.length_replicate,Graph.data] using h +lemma isPoly_graph_fuel : IsPoly (fun G => (graphCode G).length) + (fun G => CurrentKS.RationalSDP.searchFuel (dimension G.n G.m) (radiusQ G.n G.m) (boundQ G.n G.m)) := by + have hP := (isPoly_graph_n.add isPoly_graph_m).add (isPoly_const _ 2) + exact (((isPoly_const _ 2304).mul (hP.pow 114)).add (isPoly_const _ 1)).mono + (fun G => search_fuel_bound G.n G.m) + +instance poly_solvePencil : PolyTime solvePencil := by + let L := fun p => (paramsCode p).length + have hi := RunsPoly.of_poly initializeSearch id (isPoly_self L) + have hg := RunsPoly.of_poly paramsGraph id (isPoly_self L) + obtain ⟨q,hq⟩ := isPoly_graph_fuel + have hf := (hg.output.eval q).mono (fun p => hq p.graph) + exact ⟨(hi.then (runsPoly_search Params.searchState hi.output hf)).cost⟩ + +def gridStep := graphRadius.div ((graphDim.then natToRat).add (constant graphCode ratCode 1)) +instance poly_gridStep : PolyTime gridStep := by unfold gridStep;infer_instance + +def gridMesh := (gridStep.pow 2).div + (((constant graphCode ratCode 16).mul ((graphDim.then natToRat).add (constant graphCode ratCode 1))).mul + ((graphBound.add gridStep).add (constant graphCode ratCode 1))) +instance poly_gridMesh : PolyTime gridMesh := by unfold gridMesh;infer_instance + +lemma search_parts_bound : ∃q : NaturalPolynomial, ∀p : Params, ∀i, + QParts (q.eval (graphCode p.graph).length) + (p.pencil.search (radiusQ p.graph.n p.graph.m) (boundQ p.graph.n p.graph.m) 0 i) := by + have hc := (RunsPoly.of_poly (gridStep.both gridMesh) id + (isPoly_self (fun G => (graphCode G).length))).output + obtain ⟨b,hb⟩ := hc + obtain ⟨f,hf⟩ := isPoly_graph_fuel + refine ⟨3*b+f+1,?_⟩ + intro p i + let H := b.eval (graphCode p.graph).length + have hstep : QParts H (CurrentKS.RationalSDP.searchStep (dimension p.graph.n p.graph.m) (radiusQ p.graph.n p.graph.m)) := + (qparts_length _).mono ((le_prodCode_left _).trans (hb p.graph)) + have hmesh : QParts H (CurrentKS.RationalSDP.searchMesh (dimension p.graph.n p.graph.m) (radiusQ p.graph.n p.graph.m) (boundQ p.graph.n p.graph.m)) := + (qparts_length _).mono ((le_prodCode_right _).trans (hb p.graph)) + apply (pencil_iterate_parts p.pencil _ _ 0 hstep hmesh (fun _ => qparts_zero H) _ i).mono + change 3*H+_+1 ≤ 3*H+f.eval _+1 + exact Nat.add_le_add_right (Nat.add_le_add_left (hf p.graph) _) _ + +lemma search_output_bound : ∃q : NaturalPolynomial, ∀p : Params, + (vectorCode (List.ofFn (p.pencil.search (radiusQ p.graph.n p.graph.m) (boundQ p.graph.n p.graph.m) 0))).length ≤ + q.eval (graphCode p.graph).length := by + obtain ⟨b,hb⟩ := search_parts_bound + obtain ⟨d,hd⟩ := (RunsPoly.of_poly graphDim id + (isPoly_self (fun G => (graphCode G).length))).output + refine ⟨d*(2*(4*b+7)+1),?_⟩ + intro p + have h := listCode_length_bound (List.ofFn + (p.pencil.search (radiusQ p.graph.n p.graph.m) (boundQ p.graph.n p.graph.m) 0)) + (4*b.eval (graphCode p.graph).length+7) (by + intro q hq; obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hq;exact (hb p i).length) + rw [List.length_ofFn] at h + exact h.trans (Nat.mul_le_mul_right _ (by simpa only [id_eq,natCode,List.length_replicate,Graph.data] using hd p.graph)) +end AlgorithmicThinTrees.MetricTests.RationalStep.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Phases.lean b/lean/OAI/Combinatorics/ThinTrees/Phases.lean new file mode 100644 index 0000000000000000000000000000000000000000..b4ae6dd1a4be361c1eb4540c58050336b05c42ce --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Phases.lean @@ -0,0 +1,353 @@ +import OAI.Combinatorics.ThinTrees.BagConstruction + +namespace OAI + +universe uι uι2 + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +lemma border_transition (hX : ∀v, binary (X v)) {q δ ε : ℝ} + (hδ : 0 < δ) (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) + {F Z K : Finset (Record n)} + (hF : ∀B ∈ F, B.shell.ordinary = true ∧ B.shell.width = δ ∧ B.avoided = none) + (hFball : ∀B ∈ F, B.shell = RadialShell.ball B.shell.center δ) + (hFgeo : ∀A ∈ F, ∀B ∈ F, A ≠ B → Disjoint (A.shell.support X) (B.shell.support X)) + (hFvalid : H.LabeledArrangement G X q F) + (hZ : H.LabeledArrangement G X q Z) (hKF : K ⊆ F) (hKZ : Disjoint K Z) + (hbor : ∀A ∈ K, ¬A.InteriorTo (H := H) (X := X) δ Z) : + ∃Z' : Finset (Record n), H.LabeledArrangement G X q Z' ∧ + (∑B ∈ Z, B.phaseToken F δ ε)+AssignedAccounting.theta*(K.card : ℝ)*δ ≤ + ∑B ∈ Z', B.baseToken ε ∧ + (∀D ∈ Z', D ∈ K ∨ ∃B ∈ Z, D.owner = B.owner) := by + let p := ∑B ∈ Z, B.phaseToken F δ ε + let q' := ∑B ∈ Z, B.baseToken ε + have hw : ∀B ∈ F, B.shell.width = δ ∧ B.avoided = none := + fun B hB => (hF B hB).2 + by_cases hex : AssignedAccounting.theta*(K.card : ℝ)*δ ≤ q'-p + · exact ⟨Z,hZ,by dsimp [p,q'] at *; linarith,fun D hD => Or.inr ⟨D,hD,rfl⟩⟩ + let W := shrinkFamily F Z δ + have hW : H.LabeledArrangement G X q W := shrinkFamily_valid hδ.le hZ + have hK := H.labeled_subset G X hFvalid hKF + have hKW : ∀A ∈ K, ∀B ∈ W, A.Compatible H X B := by + intro A hA D hD + obtain ⟨B,hB,rfl⟩ := mem_image.mp hD + have hBZ : B ∈ Z := (mem_filter.mp hB).1 + exact Record.border_shrink_compatible hδ.le hFgeo (hKF hA) + (fun heq => Finset.disjoint_left.mp hKZ hA (heq.symm ▸ hBZ)) + (hFball A (hKF hA)) (fun hh => hbor A hA ⟨B,hBZ,hh⟩) + have hdis : Disjoint K W := H.labeled_sets_disjoint G X hX hK hKW + have hsum : ∑B ∈ W, B.baseToken ε = ∑B ∈ Z, B.shrinkValue F δ ε := + shrinkFamily_sum hX hδ hε hscale hw hZ + have hkSum : ∑B ∈ K, B.baseToken ε = (K.card : ℝ)*AssignedAccounting.fresh δ ε := by + calc + ∑B ∈ K, B.baseToken ε = ∑B ∈ K, AssignedAccounting.fresh δ ε := + sum_congr rfl (fun B hB => Record.fresh_base hδ.le hscale (hw B (hKF hB)).1 (hw B (hKF hB)).2) + _ = _ := by simp + have hcost : p-(∑B ∈ W, B.baseToken ε) ≤ 256*(q'-p) := by + rw [hsum] + dsimp [p,q'] + rw [←sum_sub_distrib,←sum_sub_distrib,Finset.mul_sum] + exact sum_le_sum (fun B hB => (Record.shrink_cost hδ.le hε hscale hw B).2) + have hdef : p-(∑B ∈ W, B.baseToken ε) ≤ (K.card : ℝ)*δ/2 := by + have hh := not_le.mp hex + dsimp [AssignedAccounting.theta] at hh + linarith + have hpay := AssignedAccounting.border_payment hδ.le hscale + (Nat.cast_nonneg K.card : (0:ℝ) ≤ _) hdef + refine ⟨K∪W,H.labeled_union G X hK hW hKW,?_,?_⟩ + · rw [sum_union hdis,hkSum] + dsimp [p] at hpay + linarith + · intro D hD + rcases mem_union.mp hD with hD | hD + · exact Or.inl hD + · obtain ⟨B,hB,rfl⟩ := mem_image.mp hD + refine Or.inr ⟨B,(mem_filter.mp hB).1,?_⟩ + dsimp [Record.shrinkRecord] + split_ifs <;> rfl + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} +namespace AssignedBag + +lemma loop_with_border_debt (A : H.AssignedBag G X δ η) (hX : ∀v, binary (X v)) + {q ε : ℝ} (hq : 0 < q) (hconn : H.LocallyConnectedReal G q) + (hη : 3072/q ≤ η) (hε : ε ≤ δ/1536) {P : Finset (Finset (Fin n))} + {F Z : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (hAF : ∀u ∈ A.centers, A.input P u ∈ F) + (hvalid : ∀u ∈ A.centers, (A.input P u).Valid H G X (q/4)) + (hZ : H.LabeledArrangement G X (q/4) Z) + (horder : ∀D ∈ Z, D.owner ⊂ A.owner → D.owner ∈ P) + (howner : ∀D ∈ Z, D.owner ≠ A.owner) : + ∃(Z' K : Finset (Record n)), H.LabeledArrangement G X (q/4) Z' ∧ + K ⊆ A.centers.image (A.input P) ∧ Disjoint K Z' ∧ + (∀B ∈ K, ¬B.InteriorTo (H := H) (X := X) δ Z') ∧ + (∑D ∈ Z, D.phaseToken F δ ε)+ + (AssignedAccounting.theta/2)*(A.centers.card : ℝ)*δ ≤ + (∑D ∈ Z', D.phaseToken F δ ε)+AssignedAccounting.theta*(K.card : ℝ)*δ ∧ + (∀B : Record n, B.InteriorTo (H := H) (X := X) δ Z' → + B.InteriorTo (H := H) (X := X) δ Z) ∧ + OwnerEvolution A.owner Z Z' ∧ + (∀D ∈ Z', D ∈ F → D ∈ Z ∨ ∃u ∈ A.centers, D = A.input P u) := by + obtain ⟨V,Z',hVA,hZ',hstop,hcredit,hinter,howners,hfresh,_⟩ := + A.interior_loop hX hq hconn hη hε hF hAF hvalid A.centers (Subset.refl _) Z hZ horder + (fun u hu hint B hB hh => (howner B hB hh).elim) + let I := V.filter (fun u => (A.input P u).InteriorTo (H := H) (X := X) δ Z') + let B := V.filter (fun u => ¬(A.input P u).InteriorTo (H := H) (X := X) δ Z') + let K := B.image (A.input P) + have hKV : ∀D ∈ K, ∃u ∈ V, D = A.input P u ∧ + ¬D.InteriorTo (H := H) (X := X) δ Z' := by + intro D hD + obtain ⟨u,hu,rfl⟩ := mem_image.mp hD + exact ⟨u,(mem_filter.mp hu).1,rfl,(mem_filter.mp hu).2⟩ + have hKcard : K.card = B.card := card_image_of_injective _ (A.input_injective P) + have hcards : (I.card : ℝ)+(K.card : ℝ) = (V.card : ℝ) := by + rw [hKcard] + exact_mod_cast card_filter_add_card_filter_not (s := V) + (p := fun u => (A.input P u).InteriorTo (H := H) (X := X) δ Z') + have hI : 2*(I.card : ℝ) < A.centers.card := by exact_mod_cast hstop + have hcount : (A.centers.card : ℝ)/2 ≤ (A.centers.card : ℝ)-(V.card : ℝ)+(K.card : ℝ) := by + linarith + have hnum := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hcount (by norm_num [AssignedAccounting.theta] : + (0:ℝ) ≤ AssignedAccounting.theta)) A.radius_pos.le + refine ⟨Z',K,hZ',?_,?_,fun D hD => (hKV D hD).choose_spec.2.2,?_,hinter,howners,?_⟩ + · intro D hD + obtain ⟨u,hu,rfl,_⟩ := hKV D hD + exact mem_image.mpr ⟨u,hVA hu,rfl⟩ + · rw [Finset.disjoint_left] + intro D hD hDZ + obtain ⟨u,hu,rfl,_⟩ := hKV D hD + rcases hfresh _ hDZ (hAF u (hVA hu)) with hh | ⟨v,hv,heq⟩ + · exact howner _ hh rfl + · have he : u = v := A.input_injective P heq + exact (mem_sdiff.mp hv).2 (he ▸ hu) + · dsimp [AssignedAccounting.theta] at hnum hcredit ⊢ + nlinarith + · intro D hD hDF + rcases hfresh D hD hDF with hh | ⟨u,hu,heq⟩ + · exact Or.inl hh + · exact Or.inr ⟨u,(mem_sdiff.mp hu).1,heq⟩ + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} + +lemma phase_loops {ι : Type uι} [DecidableEq ι] + (A : ι → H.AssignedBag G X δ η) (P : ι → Finset (Finset (Fin n))) + (hX : ∀v, binary (X v)) {q ε : ℝ} (hq : 0 < q) + (hconn : H.LocallyConnectedReal G q) (hη : 3072/q ≤ η) (hε : ε ≤ δ/1536) + {F : Finset (Record n)} + (hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none) + (J : Finset ι) (hAi : Set.InjOn (fun i => (A i).owner) J) + (hAF : ∀i ∈ J, ∀u ∈ (A i).centers, (A i).input (P i) u ∈ F) + (hvalid : ∀i ∈ J, ∀u ∈ (A i).centers, ((A i).input (P i) u).Valid H G X (q/4)) + (Z : Finset (Record n)) (hZ : H.LabeledArrangement G X (q/4) Z) + (horder : ∀i ∈ J, ∀D ∈ Z, D.owner ⊂ (A i).owner → D.owner ∈ P i) + (howner : ∀i ∈ J, ∀D ∈ Z, D.owner ≠ (A i).owner) : + ∃(Z' K : Finset (Record n)), H.LabeledArrangement G X (q/4) Z' ∧ K ⊆ F ∧ + (∀D ∈ K, ∃i ∈ J, D.owner = (A i).owner) ∧ Disjoint K Z' ∧ + (∀B ∈ K, ¬B.InteriorTo (H := H) (X := X) δ Z') ∧ + (∑D ∈ Z, D.phaseToken F δ ε)+ + (AssignedAccounting.theta/2)*(∑i ∈ J, ((A i).centers.card : ℝ))*δ ≤ + (∑D ∈ Z', D.phaseToken F δ ε)+AssignedAccounting.theta*(K.card : ℝ)*δ ∧ + (∀B : Record n, B.InteriorTo (H := H) (X := X) δ Z' → + B.InteriorTo (H := H) (X := X) δ Z) ∧ + (∀D ∈ Z', (∃i ∈ J, D.owner = (A i).owner) ∨ ∃B ∈ Z, D.owner = B.owner) ∧ + (∀D ∈ Z', D ∈ F → D ∈ Z ∨ ∃i ∈ J, ∃u ∈ (A i).centers, D = (A i).input (P i) u) := by + induction J using Finset.strongInduction generalizing Z with + | H J ih => + by_cases hn : J.Nonempty + · obtain ⟨j,hj,hmax⟩ := J.exists_max_image (fun i => (A i).owner.card) hn + obtain ⟨Z₁,K₁,hZ₁,hKA,hKZ₁,hbor₁,hcredit₁,hint₁,hown₁,hfresh₁⟩ := + (A j).loop_with_border_debt hX hq hconn hη hε hF (hAF j hj) (hvalid j hj) + hZ (horder j hj) (howner j hj) + have hKi : ∀D ∈ K₁, ∃u ∈ (A j).centers, D = (A j).input (P j) u := by + intro D hD + obtain ⟨u,hu,heq⟩ := mem_image.mp (hKA hD) + exact ⟨u,hu,heq.symm⟩ + have hKown : ∀D ∈ K₁, D.owner = (A j).owner := by + intro D hD + obtain ⟨u,hu,rfl⟩ := hKi D hD + rfl + have hKAf : K₁ ⊆ F := by + intro D hD + obtain ⟨u,hu,rfl⟩ := hKi D hD + exact hAF j hj u hu + have hInj : Set.InjOn (fun i => (A i).owner) (J.erase j) := hAi.mono (erase_subset _ _) + have horder₁ : ∀i ∈ J.erase j, ∀D ∈ Z₁, D.owner ⊂ (A i).owner → D.owner ∈ P i := by + intro i hi D hD hs + rcases hown₁ D hD with hh | ⟨B,hB,hh⟩ + · rw [hh] at hs + have hcard := card_lt_card hs + have hmax := hmax i (mem_of_mem_erase hi) + omega + · rw [hh] at hs ⊢ + exact horder i (mem_of_mem_erase hi) B hB hs + have howner₁ : ∀i ∈ J.erase j, ∀D ∈ Z₁, D.owner ≠ (A i).owner := by + intro i hi D hD heq + rcases hown₁ D hD with hh | ⟨B,hB,hh⟩ + · exact (mem_erase.mp hi).1 (hAi (mem_of_mem_erase hi) hj (heq.symm.trans hh)) + · exact howner i (mem_of_mem_erase hi) B hB (hh.symm.trans heq) + obtain ⟨Z₂,K₂,hZ₂,hKF₂,hKown₂,hKZ₂,hbor₂,hcredit₂,hint₂,hown₂,hfresh₂⟩ := + ih (J.erase j) (erase_ssubset hj) hInj + (fun i hi => hAF i (mem_of_mem_erase hi)) + (fun i hi => hvalid i (mem_of_mem_erase hi)) Z₁ hZ₁ horder₁ howner₁ + have hdis : Disjoint K₁ K₂ := by + rw [Finset.disjoint_left] + intro D hD hD₂ + obtain ⟨i,hi,heq⟩ := hKown₂ D hD₂ + exact (mem_erase.mp hi).1 (hAi (mem_of_mem_erase hi) hj (heq.symm.trans (hKown D hD))) + have hKZ : Disjoint K₁ Z₂ := by + rw [Finset.disjoint_left] + intro D hD hDZ + rcases hfresh₂ D hDZ (hKAf hD) with hD₁ | ⟨i,hi,u,hu,heq⟩ + · exact Finset.disjoint_left.mp hKZ₁ hD hD₁ + · have hoi : D.owner = (A i).owner := congrArg Record.owner heq + exact (mem_erase.mp hi).1 (hAi (mem_of_mem_erase hi) hj (hoi.symm.trans (hKown D hD))) + refine ⟨Z₂,K₁∪K₂,hZ₂,union_subset hKAf hKF₂,?_,disjoint_union_left.mpr ⟨hKZ,hKZ₂⟩, + ?_,?_,fun B hh => hint₁ B (hint₂ B hh),?_,?_⟩ + · intro D hD + rcases mem_union.mp hD with hD | hD + · exact ⟨j,hj,hKown D hD⟩ + · obtain ⟨i,hi,hh⟩ := hKown₂ D hD + exact ⟨i,mem_of_mem_erase hi,hh⟩ + · intro D hD hint + rcases mem_union.mp hD with hD | hD + · exact hbor₁ D hD (hint₂ D hint) + · exact hbor₂ D hD hint + · have hsum := sum_erase_add J (fun i => ((A i).centers.card : ℝ)) hj + have hcard : ((K₁∪K₂).card : ℝ) = (K₁.card : ℝ)+(K₂.card : ℝ) := by + exact_mod_cast card_union_of_disjoint hdis + rw [hcard,←hsum] + dsimp [AssignedAccounting.theta] at hcredit₁ hcredit₂ ⊢ + nlinarith + · intro D hD + rcases hown₂ D hD with ⟨i,hi,hh⟩ | ⟨B,hB,hh⟩ + · exact Or.inl ⟨i,mem_of_mem_erase hi,hh⟩ + · rcases hown₁ B hB with heq | ⟨C,hC,heq⟩ + · exact Or.inl ⟨j,hj,hh.trans heq⟩ + · exact Or.inr ⟨C,hC,hh.trans heq⟩ + · intro D hD hDF + rcases hfresh₂ D hD hDF with hD | ⟨i,hi,u,hu,heq⟩ + · rcases hfresh₁ D hD hDF with hD | ⟨u,hu,heq⟩ + · exact Or.inl hD + · exact Or.inr ⟨j,hj,u,hu,heq⟩ + · exact Or.inr ⟨i,mem_of_mem_erase hi,u,hu,heq⟩ + · have he : J = ∅ := not_nonempty_iff_eq_empty.mp hn + subst J + refine ⟨Z,∅,hZ,empty_subset _,?_,disjoint_empty_left _,?_,?_,fun _ hh => hh,?_,?_⟩ + · simp + · simp + · simp + · intro D hD + exact Or.inr ⟨D,hD,rfl⟩ + · intro D hD _ + exact Or.inl hD + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} {δ η : ℝ} + +lemma assigned_phase {ι : Type uι2} [DecidableEq ι] + (A : ι → H.AssignedBag G X δ η) (P : ι → Finset (Finset (Fin n))) + (hX : ∀v, binary (X v)) {q ε : ℝ} (hq : 0 < q) + (hconn : H.LocallyConnectedReal G q) (hη : 3072/q ≤ η) + (hδ : 0 < δ) (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) + (J : Finset ι) (hAi : Set.InjOn (fun i => (A i).owner) J) + (hvalid : ∀i ∈ J, ∀u ∈ (A i).centers, ((A i).input (P i) u).Valid H G X (q/4)) + (hgeo : ∀i ∈ J, ∀u ∈ (A i).centers, ∀j ∈ J, ∀v ∈ (A j).centers, + ((A i).input (P i) u) ≠ ((A j).input (P j) v) → + Disjoint ((RadialShell.ball u δ).support X) ((RadialShell.ball v δ).support X)) + (Z : Finset (Record n)) (hZ : H.LabeledArrangement G X (q/4) Z) + (horder : ∀i ∈ J, ∀D ∈ Z, D.owner ⊂ (A i).owner → D.owner ∈ P i) + (howner : ∀i ∈ J, ∀D ∈ Z, D.owner ≠ (A i).owner) : + ∃Z' : Finset (Record n), H.LabeledArrangement G X (q/4) Z' ∧ + (∑D ∈ Z, D.baseToken δ)+(AssignedAccounting.theta/2)* + (∑i ∈ J, ((A i).centers.card : ℝ))*δ ≤ ∑D ∈ Z', D.baseToken ε ∧ + (∀D ∈ Z', (∃i ∈ J, D.owner = (A i).owner) ∨ ∃B ∈ Z, D.owner = B.owner) := by + let F := J.biUnion (fun i => ((A i).centers.image ((A i).input (P i)))) + have hFmem : ∀D : Record n, D ∈ F ↔ ∃i ∈ J, ∃u ∈ (A i).centers, D = (A i).input (P i) u := by + intro D + simp only [F,mem_biUnion,mem_image] + constructor + · rintro ⟨i,hi,u,hu,heq⟩ + exact ⟨i,hi,u,hu,heq.symm⟩ + · rintro ⟨i,hi,u,hu,heq⟩ + exact ⟨i,hi,u,hu,heq.symm⟩ + have hF : ∀D ∈ F, D.shell.ordinary = true ∧ D.shell.width = δ ∧ D.avoided = none := by + intro D hD + obtain ⟨i,hi,u,hu,rfl⟩ := (hFmem D).mp hD + simp [AssignedBag.input,RadialShell.ball,RadialShell.width] + have hFball : ∀B ∈ F, B.shell = RadialShell.ball B.shell.center δ := by + intro D hD + obtain ⟨i,hi,u,hu,rfl⟩ := (hFmem D).mp hD + rfl + have hFg : ∀B ∈ F, ∀D ∈ F, B ≠ D → Disjoint (B.shell.support X) (D.shell.support X) := by + intro B hB D hD hne + obtain ⟨i,hi,u,hu,rfl⟩ := (hFmem B).mp hB + obtain ⟨j,hj,v,hv,rfl⟩ := (hFmem D).mp hD + exact hgeo i hi u hu j hj v hv hne + have hFv : H.LabeledArrangement G X (q/4) F := by + refine ⟨?_,?_⟩ + · intro D hD + obtain ⟨i,hi,u,hu,rfl⟩ := (hFmem D).mp hD + exact hvalid i hi u hu + · intro B hB D hD hne hh + exact (hh (hFg B hB D hD hne)).elim + have hAF : ∀i ∈ J, ∀u ∈ (A i).centers, (A i).input (P i) u ∈ F := + fun i hi u hu => (hFmem _).mpr ⟨i,hi,u,hu,rfl⟩ + obtain ⟨Z₁,K,hZ₁,hKF,hKo,hKZ,hbor,hcredit,hint,hown,hfresh⟩ := + phase_loops A P hX hq hconn hη hscale hF J hAi hAF hvalid Z hZ horder howner + obtain ⟨Z₂,hZ₂,hcredit₂,hown₂⟩ := + border_transition hX hδ hε hscale hF hFball hFg hFv hZ₁ hKF hKZ hbor + have hsum : ∑D ∈ Z, D.phaseToken F δ ε = ∑D ∈ Z, D.baseToken δ := by + apply sum_congr rfl + intro D hD + have hn : D ∉ F := by + intro hf + obtain ⟨i,hi,u,hu,heq⟩ := (hFmem D).mp hf + exact howner i hi D hD (congrArg Record.owner heq) + simp only [Record.phaseToken,ite_eq_right hn,Record.baseToken] + refine ⟨Z₂,hZ₂,?_,?_⟩ + · rw [hsum] at hcredit + linarith + · intro D hD + rcases hown₂ D hD with hDK | ⟨B,hB,heq⟩ + · exact Or.inl (hKo D hDK) + · rcases hown B hB with ⟨i,hi,hoi⟩ | ⟨C,hC,hoi⟩ + · exact Or.inl ⟨i,hi,heq.trans hoi⟩ + · exact Or.inr ⟨C,hC,heq.trans hoi⟩ + +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RankOne.lean b/lean/OAI/Combinatorics/ThinTrees/RankOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..0661f296f6a8bddcd64f4e368badbc7bde0e92bc --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RankOne.lean @@ -0,0 +1,91 @@ +import OAI.Combinatorics.ThinTrees.Affine + +namespace OAI + +universe uI uD uR + +section + +noncomputable section +open Matrix Polynomial Finset +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [CommRing R] + +lemma det_sub_rankOne (M : Matrix D D R) (u v : D → R) : + (M-Matrix.vecMulVec u v).det=M.det-detLinear M (Matrix.vecMulVec u v) := by + simpa only [Matrix.neg_vecMulVec,sub_eq_add_neg,map_neg] using det_add_rankOne M (-u) v + +omit [Fintype D] [DecidableEq D] in +lemma sum_pencil_update_zero (A : I → Matrix D D R) (j : I) : + ∑i, (MvPolynomial.X i : MvPolynomial I R) • ((Function.update A j 0) i).map (MvPolynomial.C : R →+* MvPolynomial I R)= + ∑i ∈ Finset.univ.erase j, (MvPolynomial.X i : MvPolynomial I R) • (A i).map (MvPolynomial.C : R →+* MvPolynomial I R) := by + rw [←Finset.add_sum_erase Finset.univ _ (Finset.mem_univ j)] + simp only [Function.update_self,Matrix.map_zero,map_zero,smul_zero,zero_add] + apply Finset.sum_congr rfl + intro i hi + rw [Function.update_of_ne (Finset.mem_erase.mp hi).1] + +lemma zeroDiff_rankOne (M : Matrix D D R) (A : I → Matrix D D R) (j : I) + (u v : D → R) (h : A j=Matrix.vecMulVec u v) : + zeroDiff j (basePencil M A)=basePencil (M-A j) (Function.update A j 0) := by + rw [zeroDiff_basePencil,basePencil,sum_pencil_update_zero] + have hm : (A j).map (MvPolynomial.C : R →+* MvPolynomial I R)= + Matrix.vecMulVec (fun a => MvPolynomial.C (u a)) (fun a => MvPolynomial.C (v a)) := by + rw [h] + apply Matrix.ext + intro a b + simp [Matrix.vecMulVec,Matrix.map_apply] + rw [hm,←det_sub_rankOne] + apply congrArg Matrix.det + rw [←hm] + apply Matrix.ext + intro a b + simp only [Matrix.sub_apply,Matrix.map_apply,Matrix.add_apply,map_sub] + abel + +omit [DecidableEq I] in +lemma basePencil_eval (M : Matrix D D R) (A : I → Matrix D D R) (z : I → R) : + MvPolynomial.eval z (basePencil M A)=(M+∑i, z i • A i).det := by + unfold basePencil + rw [(MvPolynomial.eval z).map_det] + apply congrArg Matrix.det + apply Matrix.ext + intro a b + change MvPolynomial.eval z ((M.map (MvPolynomial.C : R →+* MvPolynomial I R) + ∑i, + (MvPolynomial.X i : MvPolynomial I R) • (A i).map (MvPolynomial.C : R →+* MvPolynomial I R)) a b)=_ + simp [Matrix.map_apply,Matrix.add_apply,Matrix.sum_apply,Matrix.smul_apply] + +omit [DecidableEq I] in +lemma mixedEval_nil (M : Matrix D D R) (A : I → Matrix D D R) : mixedEval [] M A=M.det := by + rw [mixedEval,diffProduct_nil,basePencil_eval] + simp + +lemma mixedEval_rankOne (dirs : List I) (hd : dirs.Nodup) (M : Matrix D D R) + (A : I → Matrix D D R) (hA : ∀i ∈ dirs, ∃u v, A i=Matrix.vecMulVec u v) : + mixedEval dirs M A=(M-(dirs.map A).sum).det := by + induction dirs generalizing M A with + | nil => simp [mixedEval_nil] + | cons j dirs ih => + have hj : j ∉ dirs := (List.nodup_cons.mp hd).1 + obtain ⟨u,v,hjv⟩ := hA j (List.mem_cons_self) + have he : mixedEval (j::dirs) M A=mixedEval dirs (M-A j) (Function.update A j 0) := by + rw [mixedEval,eval_zero_diffProduct_cons j dirs hj,zeroDiff_rankOne M A j u v hjv] + rfl + rw [he,ih (List.nodup_cons.mp hd).2] + · have hu : dirs.map (Function.update A j 0)=dirs.map A := by + apply List.map_congr_left + intro i hi + exact Function.update_of_ne (show i ≠ j from fun he => hj (he ▸ hi)) _ _ + rw [hu,List.map_cons,List.sum_cons] + apply congrArg Matrix.det + abel + · intro i hi + rw [Function.update_of_ne (show i ≠ j from fun he => hj (he ▸ hi))] + exact hA i (List.mem_cons_of_mem _ hi) + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Gram.lean b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Gram.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f749bd42e8375edcfbee654cd071a0e911dc11a --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Gram.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.RationalMatrix.Squares + +namespace OAI + +/-! Rational gram. -/ + +section + +namespace AlgorithmicThinTrees.RationalGram +open Matrix CurrentKS.RationalBits +variable {n : ℕ} + +def factorColumns : (n : ℕ) → Matrix (Fin n) (Fin n) ℚ → List (Fin n → ℚ) + | 0,_ => [] + | n+1,A => (scalarFactors (A 0 0)⁻¹).map (fun a i => a*A i 0) ++ + (factorColumns n (KS.W17.schurTail A)).map (Fin.cons 0) + +lemma sum_scaled_outer (L : List ℚ) (u : Fin n → ℚ) (i j : Fin n) : + (L.map (fun a => (a*u i)*(a*u j))).sum = + (L.map (fun a => a^2)).sum*(u i*u j) := by + rw [← List.sum_map_mul_right] + congr 2 + funext a + ring + +lemma zero_pivot_row {A : Matrix (Fin n) (Fin n) ℚ} + (hA : (A.map (fun q : ℚ => (q:ℝ))).PosSemidef) (i j : Fin n) + (hi : A i i=0) : A i j=0 := by + have h := CurrentKS.Covariance.entry_eq_zero_of_diag_eq_zero hA i j (by simp [hi]) + simpa only [Matrix.map_apply,Rat.cast_eq_zero] using h + +lemma factorColumns_correct : ∀ (n : ℕ) (A : Matrix (Fin n) (Fin n) ℚ), + (A.map (fun q : ℚ => (q:ℝ))).PosSemidef → ∀ i j, + ((factorColumns n A).map (fun v => v i*v j)).sum=A i j := by + intro n + induction n with + | zero => intro A hA i;exact Fin.elim0 i + | succ n ih => + intro A hA i j + have hsym := KS.W07.rational_isSymm_of_cast_posSemidef hA + have hdiag : 0 ≤ A 0 0 := by + have hh := hA.diag_nonneg (i:=0) + simp only [Matrix.map_apply] at hh + exact_mod_cast hh + have hp := scalarFactors_sum (A 0 0)⁻¹ (inv_nonneg.mpr hdiag) + have ht := ih (KS.W17.schurTail A) (KS.W07.fin_schurTail_posSemidef A hA) + simp only [factorColumns,List.map_append,List.sum_append,List.map_map,Function.comp_def] + rw [sum_scaled_outer (u := fun i => A i 0),hp] + refine Fin.cases ?_ (fun i => ?_) i + · refine Fin.cases ?_ (fun j => ?_) j + · simp only [Fin.cons_zero,mul_zero,List.map_const',List.sum_replicate,nsmul_zero,add_zero] + by_cases hz : A 0 0=0 + · simp [hz] + · field_simp + · simp only [Fin.cons_zero,zero_mul,List.map_const',List.sum_replicate,nsmul_zero,add_zero] + by_cases hz : A 0 0=0 + · simp [hz,zero_pivot_row hA 0 j.succ hz] + · rw [show A j.succ 0=A 0 j.succ from hsym.apply _ _] + field_simp + · refine Fin.cases ?_ (fun j => ?_) j + · simp only [Fin.cons_zero,mul_zero,List.map_const',List.sum_replicate,nsmul_zero,add_zero] + by_cases hz : A 0 0=0 + · have hrow := zero_pivot_row hA 0 i.succ hz + rw [←hsym.apply 0 i.succ] at hrow + simp [hz,hrow] + · field_simp + · simp only [Fin.cons_succ] + rw [ht,KS.W17.schurTail,show A j.succ 0=A 0 j.succ from hsym.apply _ _] + ring + +def factorMatrix (A : Matrix (Fin n) (Fin n) ℚ) : + Matrix (Fin n) (Fin (factorColumns n A).length) ℚ := + fun i j => (factorColumns n A).get j i + +lemma factorMatrix_correct (A : Matrix (Fin n) (Fin n) ℚ) + (hA : (A.map (fun q : ℚ => (q:ℝ))).PosSemidef) : + factorMatrix A*(factorMatrix A)ᵀ=A := by + ext i j + rw [Matrix.mul_apply] + change (∑k, (factorColumns n A).get k i*(factorColumns n A).get k j)=A i j + rw [← List.sum_ofFn] + have hh : (List.ofFn fun k => (factorColumns n A).get k i*(factorColumns n A).get k j) = + (factorColumns n A).map (fun v => v i*v j) := by + change List.ofFn ((fun (v : Fin n → ℚ) => v i*v j) ∘ (factorColumns n A).get) = _ + rw [← List.map_ofFn,List.ofFn_get] + rw [hh] + exact factorColumns_correct n A hA i j + +lemma trace_parts {N k t : ℕ} {M : Matrix (Fin N) (Fin N) ℚ} + {p : Fin k → Fin N} {r : Fin t → Fin N} {S : Matrix (Fin t) (Fin t) ℚ} + (h : KS.W07.PivotTrace M p r S) {b : ℕ} (hM : ∀ i j, Parts b (M i j)) : + ∀ i j, Parts (KS.W30.inverseBitBound N b) (S i j) := by + intro i j + have hh := h.entry_parts_size_le b (fun i j => (hM i j).1) (fun i j => (hM i j).2) i j + exact ⟨(Nat.lt_size_self _).le.trans (Nat.pow_le_pow_right (by decide) hh.1), + (Nat.lt_size_self _).le.trans (Nat.pow_le_pow_right (by decide) hh.2)⟩ + +lemma trace_factor_bounds {N : ℕ} (M : Matrix (Fin N) (Fin N) ℚ) + (hPSD : (M.map (fun q : ℚ => (q:ℝ))).PosSemidef) + {b : ℕ} (hM : ∀ i j, Parts b (M i j)) : + ∀ {t k : ℕ} {p : Fin k → Fin N} {r : Fin t → Fin N} + {S : Matrix (Fin t) (Fin t) ℚ}, KS.W07.PivotTrace M p r S → + (factorColumns t S).length ≤ 3*t*(2*KS.W30.inverseBitBound N b+1) ∧ + ∀ v ∈ factorColumns t S, ∀ i, Parts (4*KS.W30.inverseBitBound N b+1) (v i) := by + intro t + induction t with + | zero => intro k p r S h; simp [factorColumns] + | succ t ih => + intro k p r S h + let B := KS.W30.inverseBitBound N b + have hp := h.state_posSemidef hPSD + have hd : 0 ≤ S 0 0 := by + have hh := hp.diag_nonneg (i:=0) + simp only [Matrix.map_apply] at hh + exact_mod_cast hh + have hs : ∃k', ∃p' : Fin k' → Fin N, + KS.W07.PivotTrace M p' (fun i => r i.succ) (KS.W17.schurTail S) := by + by_cases hz : S 0 0=0 + · exact ⟨k,p,h.zero hz⟩ + · exact ⟨k+1,Fin.snoc p (r 0),h.positive (lt_of_le_of_ne hd (Ne.symm hz))⟩ + obtain ⟨k',p',hs⟩ := hs + obtain ⟨hlen,hparts⟩ := ih hs + have hS := trace_parts h hM + have hb : Parts B (S 0 0)⁻¹ := (hS 0 0).inv + have hlen' := scalarFactors_length hb + constructor + · simp only [factorColumns,List.length_append,List.length_map] + change (scalarFactors (S 0 0)⁻¹).length+(factorColumns t (KS.W17.schurTail S)).length ≤ + 3*(t+1)*(2*B+1) + change (factorColumns t (KS.W17.schurTail S)).length ≤ 3*t*(2*B+1) at hlen + nlinarith only [hlen,hlen'] + · intro v hv i + simp only [factorColumns,List.mem_append,List.mem_map] at hv + rcases hv with ⟨a,ha,rfl⟩|⟨u,hu,rfl⟩ + · have hq := (scalarFactors_parts hb ha).mul (hS i 0) + change Parts (4*B+1) (a*S i 0) + convert hq using 1 + omega + · refine Fin.cases ?_ (fun j => hparts u hu j) i + change Parts (4*B+1) 0 + simp [Parts,Nat.one_le_two_pow] + +lemma factorColumns_bounds (A : Matrix (Fin n) (Fin n) ℚ) + (hA : (A.map (fun q : ℚ => (q:ℝ))).PosSemidef) + {b : ℕ} (hb : ∀ i j, Parts b (A i j)) : + (factorColumns n A).length ≤ 3*n*(2*KS.W30.inverseBitBound n b+1) ∧ + ∀ v ∈ factorColumns n A, ∀ i, Parts (4*KS.W30.inverseBitBound n b+1) (v i) := + trace_factor_bounds A hA hb KS.W07.PivotTrace.initial + +end AlgorithmicThinTrees.RationalGram +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Inverse.lean b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Inverse.lean new file mode 100644 index 0000000000000000000000000000000000000000..0151101255e59f8dc34971e0eeb205146d47262f --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Inverse.lean @@ -0,0 +1,114 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Realization.FaceQueryRealization + +namespace OAI + +/-! Rational inverse. -/ + +section + + +namespace AlgorithmicThinTrees.RationalInverse +open Matrix Finset +variable {n : ℕ} + +lemma posDef_of_cast (A : Matrix (Fin n) (Fin n) ℚ) + (hA : (A.map (fun q : ℚ => (q:ℝ))).PosDef) : A.PosDef := by + apply PosDef.of_dotProduct_mulVec_pos + · exact (isHermitian_iff_isSymm.mpr (KS.W07.rational_isSymm_of_cast_posSemidef hA.posSemidef)) + · intro x hx + have hx' : (fun i => (x i:ℝ)) ≠ 0 := by + intro he + apply hx + funext i + have hh := congrFun he i + change (x i:ℝ)=0 at hh + change x i=0 + exact_mod_cast hh + have hh := hA.dotProduct_mulVec_pos hx' + simp only [star_trivial,dotProduct,mulVec,map_apply] at hh ⊢ + exact_mod_cast hh + +lemma schur_posDef (A : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) + (hA : A.PosDef) : (KS.W17.schurTail A).PosDef := by + have hs : A.IsSymm := isHermitian_iff_isSymm.mp hA.isHermitian + apply PosDef.of_dotProduct_mulVec_pos + · exact isHermitian_iff_isSymm.mpr (KS.W17.schurTail_isSymm A hs) + · intro x hx + have hlift : KS.W17.schurWitnessLift A x ≠ 0 := by + intro h + apply hx + funext i + exact congrFun h i.succ + simpa only [star_trivial,KS.W07.fin_schurWitnessLift_quadratic A hs hA.diag_pos.ne'] using + hA.dotProduct_mulVec_pos hlift + +def liftSolve (A : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) + (B : Matrix (Fin n) (Fin n) ℚ) (b : Fin (n+1) → ℚ) : Fin (n+1) → ℚ := + let y := B*ᵥ(fun i => b i.succ-A i.succ 0*(b 0/A 0 0)) + Fin.cons ((b 0-(fun j => A 0 j.succ) ⬝ᵥ y)/A 0 0) y + +lemma liftSolve_correct (A : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) + (B : Matrix (Fin n) (Fin n) ℚ) (b : Fin (n+1) → ℚ) + (hp : A 0 0 ≠ 0) (hB : KS.W17.schurTail A*B=1) : + A*ᵥliftSolve A B b=b := by + let y := B*ᵥ(fun i => b i.succ-A i.succ 0*(b 0/A 0 0)) + have hy : KS.W17.schurTail A*ᵥy=(fun i => b i.succ-A i.succ 0*(b 0/A 0 0)) := by + rw [show y=B*ᵥ(fun i => b i.succ-A i.succ 0*(b 0/A 0 0)) from rfl, + Matrix.mulVec_mulVec,hB,Matrix.one_mulVec] + ext i + rw [mulVec,dotProduct,Fin.sum_univ_succ] + change A i 0*((b 0-(fun j => A 0 j.succ) ⬝ᵥ y)/A 0 0)+ + ∑j, A i j.succ*y j=b i + refine Fin.cases ?_ (fun i => ?_) i + · rw [mul_div_cancel₀ _ hp] + simp only [dotProduct] + ring + · have he := congrFun hy i + change (∑j, (A i.succ j.succ-A i.succ 0*A 0 j.succ/A 0 0)*y j)= + b i.succ-A i.succ 0*(b 0/A 0 0) at he + have he' : (∑j, A i.succ j.succ*y j)- + A i.succ 0*(A 0 0)⁻¹*((fun j => A 0 j.succ) ⬝ᵥ y)= + b i.succ-A i.succ 0*(b 0/A 0 0) := by + have hsum : (∑j, (A i.succ j.succ-A i.succ 0*A 0 j.succ/A 0 0)*y j)= + (∑j, A i.succ j.succ*y j)- + A i.succ 0*(A 0 0)⁻¹*((fun j => A 0 j.succ) ⬝ᵥ y) := by + simp only [dotProduct,mul_sum,←sum_sub_distrib] + apply sum_congr rfl + intro j hj + ring + rwa [hsum] at he + simp only [div_eq_mul_inv] + linear_combination he' + +def inverse : (n : ℕ) → Matrix (Fin n) (Fin n) ℚ → Matrix (Fin n) (Fin n) ℚ + | 0,_ => 1 + | n+1,A => + let B := inverse n (KS.W17.schurTail A) + fun i j => liftSolve A B (Pi.single j 1) i + +lemma inverse_mul_correct : ∀ (n : ℕ) (A : Matrix (Fin n) (Fin n) ℚ), + A.PosDef → A*inverse n A=1 := by + intro n + induction n with + | zero => intro A hA;ext i;exact Fin.elim0 i + | succ n ih => + intro A hA + have hB := ih (KS.W17.schurTail A) (schur_posDef A hA) + ext i j + have hh := congrFun (liftSolve_correct A (inverse n (KS.W17.schurTail A)) + (Pi.single j 1) hA.diag_pos.ne' hB) i + simpa only [inverse,Matrix.mul_apply,Matrix.mulVec,dotProduct,Pi.single_apply, + one_apply,eq_comm] using! hh + +lemma inverse_eq (A : Matrix (Fin n) (Fin n) ℚ) (hA : A.PosDef) : inverse n A=A⁻¹ := by + exact (inv_eq_right_inv (inverse_mul_correct n A hA)).symm + +lemma inverse_eq_of_cast (A : Matrix (Fin n) (Fin n) ℚ) + (hA : (A.map (fun q : ℚ => (q:ℝ))).PosDef) : inverse n A=A⁻¹ := + inverse_eq A (posDef_of_cast A hA) + +end AlgorithmicThinTrees.RationalInverse +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/InverseRealization.lean b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/InverseRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c5ede55398a0192f2ff930142c9477e89569fc9 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/InverseRealization.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.RationalMatrix.Inverse +import OAI.Combinatorics.ThinTrees.RationalMatrix.SchurHistory + +namespace OAI + +/-! Inverse realization. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 Matrix +open AlgorithmicThinTrees + +abbrev BackSolve := MatrixData×MatrixObject +abbrev backSolveCode := prodCode matrixCode matrixObjectCode +abbrev solveChild := first matrixCode matrixObjectCode +abbrev solveParent := second matrixCode matrixObjectCode +abbrev solveColumnCode := prodCode backSolveCode natCode +abbrev solveColumnBase := first backSolveCode natCode +abbrev solveColumnIndex := second backSolveCode natCode +abbrev solveColumnA := solveColumnBase.then solveParent +abbrev solveColumnB := solveColumnBase.then solveChild +abbrev solveColumnDim := solveColumnA.then matrixDim +abbrev solveColumnEntries := solveColumnA.then matrixEntries + +abbrev rhsCode := prodCode solveColumnCode natCode +abbrev rhsBase := first solveColumnCode natCode +abbrev rhsIndex := second solveColumnCode natCode + +def solveRhs : Realizes rhsCode ratCode + (fun p => + (if p.2+1=p.1.2 then 1 else 0)- + ((matrixData p.1.1.2.2).getD (p.2+1) []).getD 0 0 * + ((if 0=p.1.2 then 1 else 0)/((matrixData p.1.1.2.2).getD 0 []).getD 0 0)) := + let A := rhsBase.then solveColumnEntries + let i := rhsIndex.then natSucc + let j := rhsBase.then solveColumnIndex + let zero := constant rhsCode natCode 0 + let ij := (i.both j).then identityEntry + let zj := (zero.both j).then identityEntry + let iz := (A.both (i.both zero)).then matrixEntry + let zz := (A.both (zero.both zero)).then matrixEntry + ij.sub (iz.mul (zj.div zz)) +instance poly_solveRhs : PolyTime solveRhs := by unfold solveRhs;infer_instance + +def solveTopRow : Realizes rhsCode ratCode + (fun p => ((matrixData p.1.1.2.2).getD 0 []).getD (p.2+1) 0) := + let A := rhsBase.then solveColumnEntries + let i := rhsIndex.then natSucc + (A.both ((constant rhsCode natCode 0).both i)).then matrixEntry +instance poly_solveTopRow : PolyTime solveTopRow := by unfold solveTopRow;infer_instance + +def liftColumnData (p : BackSolve×ℕ) : List ℚ := + let A := matrixData p.1.2.2 + let r := (List.range p.1.2.1.pred).map (fun i => + (if i+1=p.2 then 1 else 0)-(A.getD (i+1) []).getD 0 0* + ((if 0=p.2 then 1 else 0)/(A.getD 0 []).getD 0 0)) + let y := matVecValue (p.1.1,r) + let row := (List.range p.1.2.1.pred).map (fun i => (A.getD 0 []).getD (i+1) 0) + ((if 0=p.2 then 1 else 0)-dotValue (row,y))/(A.getD 0 []).getD 0 0::y + +def liftColumn : Realizes solveColumnCode vectorCode liftColumnData := + let n := solveColumnDim.then natPred + let args := (identity solveColumnCode).both n + let y := (solveColumnB.both (args.then solveRhs.tabulate)).then matVec + let row := args.then solveTopRow.tabulate + let zero := constant solveColumnCode natCode 0 + let b := (zero.both solveColumnIndex).then identityEntry + let pivot := (solveColumnEntries.both (zero.both zero)).then matrixEntry + (((b.sub ((row.both y).then dot)).div pivot).both y).then (consList ratCode) +instance poly_liftColumn : PolyTime liftColumn := by + unfold liftColumn + apply poly_then + +lemma liftColumn_data {n : ℕ} (A : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) + (B : Matrix (Fin n) (Fin n) ℚ) (j : Fin (n+1)) : + liftColumnData ((matrixData B,⟨n+1,A⟩),j.val)= + List.ofFn (RationalInverse.liftSolve A B (Pi.single j (1 : ℚ))) := by + have rhs : ((List.range n).map (fun i => + (if i+1=j.val then 1 else 0)-((matrixData A).getD (i+1) []).getD 0 0* + ((if 0=j.val then 1 else 0)/((matrixData A).getD 0 []).getD 0 0)))= + List.ofFn (fun i : Fin n => (Pi.single j (1 : ℚ) : Fin (n+1) → ℚ) i.succ-A i.succ 0*((Pi.single j (1 : ℚ) : Fin (n+1) → ℚ) 0/A 0 0)) := by + rw [range_map_fin] + apply congrArg List.ofFn + funext i + change (if i.succ.val=j.val then 1 else 0)- + ((matrixData A).getD i.succ.val []).getD (0 : Fin (n+1)).val 0* + ((if (0 : Fin (n+1)).val=j.val then 1 else 0)/ + ((matrixData A).getD (0 : Fin (n+1)).val []).getD (0 : Fin (n+1)).val 0)=_ + rw [matrix_entry_data,matrix_entry_data] + simp only [Pi.single_apply,Fin.val_inj,eq_comm] + have row : ((List.range n).map (fun i => ((matrixData A).getD 0 []).getD (i+1) 0))= + List.ofFn (fun i : Fin n => A 0 i.succ) := by + rw [range_map_fin] + apply congrArg List.ofFn + funext i + exact matrix_entry_data A 0 i.succ + change ((if 0=j.val then 1 else 0)-dotValue (_,matVecValue (matrixData B,_)))/ + ((matrixData A).getD 0 []).getD 0 0::matVecValue (matrixData B,_)=_ + dsimp only + simp only [Nat.pred_succ] + have pivot : ((matrixData A).getD 0 []).getD 0 0=A 0 0 := by + simpa only [Fin.val_zero] using matrix_entry_data A 0 0 + rw [rhs,row,matVec_data,dot_ofFn,pivot] + simp only [RationalInverse.liftSolve,List.ofFn_succ,Fin.cons_zero,Fin.cons_succ] + congr 2 + simp only [Pi.single_apply,←Fin.val_inj,Fin.val_zero,eq_comm] + +def inverseLiftData (p : BackSolve) : MatrixData := + transposeData ((List.range p.2.1).map (fun j => liftColumnData (p,j))) + +def inverseLift : Realizes backSolveCode matrixCode inverseLiftData := + (((identity backSolveCode).both (solveParent.then matrixDim)).then liftColumn.tabulate).then transposeMatrix +instance poly_inverseLift : PolyTime inverseLift := by + unfold inverseLift + apply poly_then + +lemma inverseLift_data {n : ℕ} (A : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) + (B : Matrix (Fin n) (Fin n) ℚ) : + inverseLiftData (matrixData B,⟨n+1,A⟩)= + matrixData (fun i j => RationalInverse.liftSolve A B (Pi.single j (1 : ℚ)) i) := by + unfold inverseLiftData + rw [range_map_fin] + simp only [liftColumn_data] + change transposeData (matrixData (fun j i => RationalInverse.liftSolve A B (Pi.single j (1 : ℚ)) i))=_ + exact transpose_data _ + +lemma inverse_fold_correct (a : MatrixObject) : + (schurHistoryData a).foldl (fun B A => inverseLiftData (B,A)) []= + matrixData (RationalInverse.inverse a.1 a.2) := by + rcases a with ⟨n,A⟩ + induction n with + | zero => simp [schurHistoryData,RationalInverse.inverse,matrixData] + | succ n ih => + simp only [schurHistoryData,List.foldl_append,List.foldl_cons,List.foldl_nil] + rw [ih,inverseLift_data] + rfl + +def rationalInverseProgram : Realizes matrixObjectCode matrixObjectCode + (fun a => ⟨a.1,RationalInverse.inverse a.1 a.2⟩) := + (matrixDim.both (((constant matrixObjectCode matrixCode []).both schurHistory).then inverseLift.fold)).changeOutput + matrixObjectCode (fun a => ⟨a.1,RationalInverse.inverse a.1 a.2⟩) + (fun a => by rw [inverse_fold_correct];rfl) + +lemma inverse_take_history (a : MatrixObject) (k : ℕ) : + (schurHistoryData a |>.take k).foldl (fun B A => inverseLiftData (B,A)) []=[] ∨ + ∃b∈schurHistoryData a, + (schurHistoryData a |>.take k).foldl (fun B A => inverseLiftData (B,A)) []= + matrixData (RationalInverse.inverse b.1 b.2) := by + rcases a with ⟨n,A⟩ + induction n generalizing k with + | zero => simp [schurHistoryData] + | succ n ih => + by_cases hk : k ≤ n + · have he : (schurHistoryData ⟨n+1,A⟩).take k= + (schurHistoryData ⟨n,KS.W17.schurTail A⟩).take k := by + rw [schurHistoryData, List.take_append_of_le_length] + simpa only [schurHistory_length] using hk + rw [he] + rcases ih k (KS.W17.schurTail A) with h|⟨b,hb,he⟩ + · exact Or.inl h + · exact Or.inr ⟨b,by simp only [schurHistoryData,List.mem_append,List.mem_singleton]; exact Or.inl hb,he⟩ + · rw [List.take_of_length_le (by rw [schurHistory_length]; change n+1 ≤ k; omega),inverse_fold_correct] + exact Or.inr ⟨⟨n+1,A⟩,by simp [schurHistoryData],rfl⟩ + +lemma pivotTrace_posDef {N k t : ℕ} {A : Matrix (Fin N) (Fin N) ℚ} + {p : Fin k → Fin N} {r : Fin t → Fin N} {B : Matrix (Fin t) (Fin t) ℚ} + (h : KS.W07.PivotTrace A p r B) (hA : A.PosDef) : B.PosDef := by + induction h with + | initial => exact hA + | zero _ _ ih => exact RationalInverse.schur_posDef _ ih + | positive _ _ ih => exact RationalInverse.schur_posDef _ ih + +lemma SchurDesc.posDef {a b : MatrixObject} (h : SchurDesc a b) (hA : a.2.PosDef) : b.2.PosDef := by + obtain ⟨k,p,r,h⟩ := h + exact pivotTrace_posDef h hA + +lemma matrixInverse_parts {n b : ℕ} (A : Matrix (Fin n) (Fin n) ℚ) + (h : ∀i j,QParts b (A i j)) (hp : A.PosDef) : + ∀i j,QParts (KS.W30.inverseBitBound n b) (RationalInverse.inverse n A i j) := by + intro i j + rw [RationalInverse.inverse_eq A hp] + have hh := KS.W30.rational_inverse_parts_size_le A b (fun i j => (h i j).1) + (fun i j => (h i j).2) (isUnit_iff_ne_zero.mp ((Matrix.isUnit_iff_isUnit_det A).mp hp.isUnit)) i j + exact ⟨(Nat.size_le.mp hh.1).le,(Nat.size_le.mp hh.2).le⟩ + +lemma SchurDesc.inverse_wire {a b : MatrixObject} (h : SchurDesc a b) + (hA : a.2.PosDef) : + (matrixCode (matrixData (RationalInverse.inverse b.1 b.2))).length ≤ + a.1*(2*(a.1*(2*(4*(32*((matrixObjectCode a).length+1)^7)+7)+1))+1) := by + have hn := h.dim + have hp := h.posDef hA + obtain ⟨k,p,r,h⟩ := h + have he := matrixInverse_parts b.2 (RationalGram.trace_parts h (matrixObject_parts a)) hp + have hm := KS.W30.inverseBitBound_mono_dim (KS.W30.inverseBitBound a.1 (matrixObjectCode a).length) hn + have hm' := hm.trans (KS.W30.inverseBitBound_twice_le_input_polynomial (matrixObject_dim_le a) le_rfl) + have hb := matrixCode_parts_bound (RationalInverse.inverse b.1 b.2) (fun i j => (he i j).mono hm') + exact hb.trans (Nat.mul_le_mul hn (Nat.add_le_add_right + (Nat.mul_le_mul_left 2 (Nat.mul_le_mul_right _ hn)) 1)) + +lemma runsPoly_rationalInverse {ι : Type*} {L : ι → ℕ} (a : ι → MatrixObject) + (ha : IsPoly L (fun i => (matrixObjectCode (a i)).length)) + (hA : ∀i,((a i).2.map (fun q : ℚ => (q:ℝ))).PosDef) : + RunsPoly L rationalInverseProgram a := by + have hh := runsPoly_schurHistory a ha (fun i => (hA i).posSemidef) + have hh' := (RunsPoly.of_poly (constant matrixObjectCode matrixCode []) a ha).both hh + have hd : IsPoly L (fun i => (a i).1) := ha.mono (fun i => matrixObject_dim_le (a i)) + have hb := hd.mul (((isPoly_const L 2).mul (hd.mul (((isPoly_const L 2).mul + (((isPoly_const L 4).mul ((isPoly_const L 32).mul ((ha.add (isPoly_const L 1)).pow 7))).add + (isPoly_const L 7))).add (isPoly_const L 1)))).add (isPoly_const L 1)) + obtain ⟨p,hp⟩ := hb + have hfold := runsPoly_fold_of_poly inverseLift (fun i => ([],schurHistoryData (a i))) + hh'.output (show ∃p : NaturalPolynomial, _ from ⟨p,by + intro i ys zs he + have hy : ys=(schurHistoryData (a i)).take ys.length := by + dsimp only at he + rw [he,List.take_left] + rw [hy] + rcases inverse_take_history (a i) ys.length with hz|⟨b,hb,he⟩ + · rw [hz]; exact Nat.zero_le _ + · rw [he] + exact ((schurHistory_mem (a i) (hA i).posSemidef b hb).inverse_wire + (RationalInverse.posDef_of_cast _ (hA i))).trans (hp i)⟩) + unfold rationalInverseProgram + apply RunsPoly.changeOutput + exact (RunsPoly.of_poly matrixDim a ha).both (hh'.then hfold) + +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/MatrixRealization.lean b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/MatrixRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..2a389b8d218e9a363c5b839bd3869eae2427c147 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/MatrixRealization.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialExplicit +import OAI.Analysis.MatrixSigning.Complexity.PolynomialMatrixFold +import OAI.Analysis.MatrixSigning.Realization.FaceQueryRealization +import OAI.Combinatorics.ThinTrees.BasePacking + +namespace OAI + +/-! Matrix realization. -/ + +section + + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 Matrix +variable {ι α β : Type*} {L : ι → ℕ} {ea : α → Word} {eb : β → Word} + +lemma runsPoly_fold_of_poly {f : α×β → α} + (r : Realizes (prodCode ea eb) ea f) [PolyTime r] (a : ι → α×List β) + (ha : IsPoly L (fun i => (prodCode ea (listCode eb) (a i)).length)) + (hs : ∃q : NaturalPolynomial,∀i ys zs,(a i).2=ys++zs → + (ea (ys.foldl (fun s x => f (s,x)) (a i).1)).length≤q.eval (L i)) : + RunsPoly L r.fold a := by + obtain ⟨p,hp⟩ := ha + obtain ⟨q,hq⟩ := hs + obtain ⟨t,ht⟩ := PolyTime.bound (r:=r) + refine ⟨⟨p,hp⟩,⟨5*q+2*p+p*(3*p+10*q+t.comp (2*q+1+p)+12)+7,?_⟩⟩ + intro i + let E := p.eval (L i) + let S := q.eval (L i) + have he : (listCode eb (a i).2).length≤E := (le_prodCode_right (a i)).trans (hp i) + have hn := (list_length_le_code eb (a i).2).trans he + have h0 := hq i [] (a i).2 rfl + have hN := hq i (a i).2 [] (by simp) + have hc : ∀s x,(ea s).length≤S → (eb x).length≤E → r.cost (s,x)≤t.eval (2*S+1+E) := by + intro s x hs hx + apply (ht (s,x)).trans (t.eval_mono ?_) + rw [prodCode_length] + dsimp only + omega + have hscan := fold_scan_bound (ea:=ea) (eb:=eb) (fun s x => f (s,x)) r.cost (a i).1 + (a i).2 S E (t.eval (2*S+1+E)) (hq i) + (fun x hx => (mem_length_le_code (a i).2 hx).trans he) hc + have hscan' := hscan.trans (Nat.add_le_add_right (Nat.mul_le_mul_right _ hn) 1) + change FoldRoutine.ticks ea eb (fun s x => f (s,x)) r.cost (a i).1 (a i).2≤_ + simp only [FoldRoutine.ticks] + simp only [NaturalPolynomial.eval_add,NaturalPolynomial.eval_mul, + NaturalPolynomial.eval_comp] + change _≤5*S+2*E+E*(3*E+10*S+t.eval (2*S+1+E)+12)+7 + change (ea (a i).1).length≤S at h0 + change (ea ((a i).2.foldl (fun s x => f (s,x)) (a i).1)).length≤S at hN + change (FramedMapRoutine.tape eb (a i).2).length≤E at he + omega + +abbrev matrixView : Realizes matrixObjectCode (prodCode natCode matrixCode) + (fun a => (a.1,matrixData a.2)) := + (identity (prodCode natCode matrixCode)).reindex matrixObjectCode + (fun a => (a.1,matrixData a.2)) (fun _ => rfl) +private instance poly_matrixView : PolyTime matrixView := by + unfold matrixView + apply poly_reindex + +abbrev matrixDim := matrixView.then (first natCode matrixCode) +abbrev matrixEntries := matrixView.then (second natCode matrixCode) + +lemma matrix_entry_data {n m : ℕ} (A : Matrix (Fin n) (Fin m) ℚ) (i : Fin n) (j : Fin m) : + ((matrixData A).getD i.val []).getD j.val 0=A i j := by + rw [show matrixData A=List.ofFn (fun i => List.ofFn (A i)) from rfl, + getD_ofFn,getD_ofFn] + +lemma matrixCode_parts_bound {n m b : ℕ} (A : Matrix (Fin n) (Fin m) ℚ) + (h : ∀i j,QParts b (A i j)) : + (matrixCode (matrixData A)).length≤n*(2*(m*(2*(4*b+7)+1))+1) := by + apply (listCode_length_bound (matrixData A) (m*(2*(4*b+7)+1)) ?_).trans_eq + (by rw [show (matrixData A).length=n from List.length_ofFn]) + intro row hr + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hr + apply (listCode_length_bound (List.ofFn (A i)) (4*b+7) ?_).trans_eq + (by rw [List.length_ofFn]) + intro q hq + obtain ⟨j,rfl⟩ := List.mem_ofFn.mp hq + exact (h i j).length + +lemma matrixObject_dim_le (a : MatrixObject) : a.1≤(matrixObjectCode a).length := + by simpa only [prodCode, matrixObjectCode, natCode,List.length_replicate] using + (le_prodCode_left (ea:=natCode) (eb:=matrixCode) (a.1,matrixData a.2)) + +lemma matrixObject_parts (a : MatrixObject) : + ∀i j,QParts (matrixObjectCode a).length (a.2 i j) := by + intro i j + apply (qparts_length _).mono + exact ((mem_length_le_code (List.ofFn (a.2 i)) (List.mem_ofFn.mpr ⟨j,rfl⟩)).trans + (mem_length_le_code (matrixData a.2) (List.mem_ofFn.mpr ⟨i,rfl⟩))).trans + (le_prodCode_right (a.1,matrixData a.2)) + +lemma matrixObject_parts_bound (a : MatrixObject) {b N : ℕ} + (hn : a.1≤N) (h : ∀i j,QParts b (a.2 i j)) : + (matrixObjectCode a).length≤2*N+1+N*(2*(N*(2*(4*b+7)+1))+1) := by + have hb := matrixCode_parts_bound a.2 h + have hm := Nat.mul_le_mul hn (Nat.add_le_add_right + (Nat.mul_le_mul_left 2 (Nat.mul_le_mul_right (2*(4*b+7)+1) hn)) 1) + simp only [matrixObjectCode,prodCode_length,natCode,List.length_replicate] + change 2*a.1+1+(matrixCode (matrixData a.2)).length≤_ + omega + +def schurData (a : MatrixObject) : MatrixObject := + match a with + | ⟨0,A⟩ => ⟨0,A⟩ + | ⟨n+1,A⟩ => ⟨n,KS.W17.schurTail A⟩ + +abbrev entryCode := prodCode (prodCode matrixObjectCode natCode) natCode +abbrev entryBase := (first (prodCode matrixObjectCode natCode) natCode).then + (first matrixObjectCode natCode) +abbrev entryI := (first (prodCode matrixObjectCode natCode) natCode).then + (second matrixObjectCode natCode) +abbrev entryJ := second (prodCode matrixObjectCode natCode) natCode + +def schurEntry : Realizes entryCode ratCode + (fun p => + let A := matrixData p.1.1.2 + (A.getD (p.1.2+1) []).getD (p.2+1) 0 - + (A.getD (p.1.2+1) []).getD 0 0 * (A.getD 0 []).getD (p.2+1) 0 / + (A.getD 0 []).getD 0 0) := + let A := entryBase.then matrixEntries + let i := entryI.then natSucc + let j := entryJ.then natSucc + let z := constant entryCode natCode 0 + let e {f g : (MatrixObject×ℕ)×ℕ → ℕ} + (k : Realizes entryCode natCode f) (l : Realizes entryCode natCode g) := + (A.both (k.both l)).then matrixEntry + (e i j).sub (((e i z).mul (e z j)).div (e z z)) +instance poly_schurEntry : PolyTime schurEntry := by unfold schurEntry; apply poly_sub + +def schur : Realizes matrixObjectCode matrixObjectCode schurData := + let d := matrixDim.then natPred + let B := (((identity matrixObjectCode).both d).both d).then schurEntry.matrixTabulate + (d.both B).changeOutput matrixObjectCode schurData (by + intro a + rcases a with ⟨n,A⟩ + cases n with + | zero => simp [matrixObjectCode,schurData,matrixData] + | succ n => + change prodCode natCode matrixCode (n, + (List.range n).map (fun i => (List.range n).map (fun j => _)))=_ + simp only [range_map_fin, id_eq] + have he : (List.ofFn fun (i : Fin n) => List.ofFn fun (j : Fin n) => + ((matrixData A).getD (i.val+1) []).getD (j.val+1) 0 - + ((matrixData A).getD (i.val+1) []).getD 0 0 * + ((matrixData A).getD 0 []).getD (j.val+1) 0 / + ((matrixData A).getD 0 []).getD 0 0)=matrixData (KS.W17.schurTail A) := by + change List.ofFn _=List.ofFn _ + apply congrArg List.ofFn + funext i + apply congrArg List.ofFn + funext j + change ((matrixData A).getD i.succ.val []).getD j.succ.val 0 - + ((matrixData A).getD i.succ.val []).getD (0 : Fin (n+1)).val 0 * + ((matrixData A).getD (0 : Fin (n+1)).val []).getD j.succ.val 0 / + ((matrixData A).getD (0 : Fin (n+1)).val []).getD (0 : Fin (n+1)).val 0 = _ + rw [matrix_entry_data A i.succ j.succ,matrix_entry_data A i.succ 0, + matrix_entry_data A 0 j.succ,matrix_entry_data A 0 0] + rfl + rw [he] + rfl) +instance poly_schur : PolyTime schur := by unfold schur; apply poly_changeOutput + +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/SchurHistory.lean b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/SchurHistory.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab3342e6b13a80915839ede7bce1e06faea3f1c3 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/SchurHistory.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialIterateFamilies +import OAI.Analysis.MatrixSigning.Complexity.PolynomialOptimize +import OAI.Combinatorics.ThinTrees.Normalization.Realization +import OAI.Combinatorics.ThinTrees.RationalMatrix.Gram +import OAI.Combinatorics.ThinTrees.RationalMatrix.MatrixRealization + +namespace OAI + +/-! Schur history. -/ + +section + + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 Matrix +open AlgorithmicThinTrees + +def SchurDesc (a b : MatrixObject) : Prop := + ∃k, ∃p : Fin k → Fin a.1, ∃r : Fin b.1 → Fin a.1, + KS.W07.PivotTrace a.2 p r b.2 + +lemma SchurDesc.refl (a : MatrixObject) : SchurDesc a a := + ⟨0,(fun i => Fin.elim0 i),id,KS.W07.PivotTrace.initial⟩ + +lemma SchurDesc.dim {a b : MatrixObject} (h : SchurDesc a b) : b.1≤a.1 := by + obtain ⟨k,p,r,h⟩ := h + have hh := h.size_bound + omega + +lemma SchurDesc.psd {a b : MatrixObject} (h : SchurDesc a b) + (hA : (a.2.map (fun q : ℚ => (q:ℝ))).PosSemidef) : + (b.2.map (fun q : ℚ => (q:ℝ))).PosSemidef := by + obtain ⟨k,p,r,h⟩ := h + exact h.state_posSemidef hA + +lemma SchurDesc.schur {a b : MatrixObject} (h : SchurDesc a b) + (hA : (a.2.map (fun q : ℚ => (q:ℝ))).PosSemidef) : SchurDesc a (schurData b) := by + rcases b with ⟨d,B⟩ + cases d with + | zero => exact h + | succ d => + obtain ⟨k,p,r,h⟩ := h + by_cases hz : B 0 0=0 + · exact ⟨k,p,(fun i => r i.succ),h.zero hz⟩ + · have hh := (h.state_posSemidef hA).diag_nonneg (i:=0) + change (0 : ℝ) ≤ (B 0 0:ℝ) at hh + have hq : 0 ≤ B 0 0 := by exact_mod_cast hh + exact ⟨k+1,Fin.snoc p (r 0),(fun i => r i.succ),h.positive (lt_of_le_of_ne hq (Ne.symm hz))⟩ + +lemma SchurDesc.wire {a b : MatrixObject} (h : SchurDesc a b) : + (matrixObjectCode b).length ≤ + 2*a.1+1+a.1*(2*(a.1*(2*(4*KS.W30.inverseBitBound a.1 (matrixObjectCode a).length+7)+1))+1) := by + have hn := h.dim + obtain ⟨k,p,r,h⟩ := h + exact matrixObject_parts_bound b hn (RationalGram.trace_parts h (matrixObject_parts a)) + +abbrev SchurStack := MatrixObject×List MatrixObject +abbrev schurStackCode := prodCode matrixObjectCode (listCode matrixObjectCode) + +def schurNextData (s : SchurStack) : SchurStack := + if s.1.1=0 then s else (schurData s.1,s.1::s.2) + +abbrev schurCurrent := first matrixObjectCode (listCode matrixObjectCode) +abbrev schurOld := second matrixObjectCode (listCode matrixObjectCode) + +def schurNext : Realizes schurStackCode schurStackCode schurNextData := + let z := ((schurCurrent.then matrixDim).both (constant schurStackCode natCode 0)).then natEq + (z.ite (identity schurStackCode) + ((schurCurrent.then schur).both ((schurCurrent.both schurOld).then (consList matrixObjectCode)))).congr + (fun s => by simp only [schurNextData]; split_ifs <;> simp_all) +instance poly_schurNext : PolyTime schurNext := by unfold schurNext; infer_instance + +def schurHistoryData : MatrixObject → List MatrixObject + | ⟨0,_⟩ => [] + | ⟨d+1,A⟩ => schurHistoryData ⟨d,KS.W17.schurTail A⟩ ++ [⟨d+1,A⟩] +termination_by a => a.1 + +lemma schurHistory_length (a : MatrixObject) : (schurHistoryData a).length=a.1 := by + rcases a with ⟨d,A⟩ + induction d with + | zero => simp [schurHistoryData] + | succ d ih => simp [schurHistoryData,ih] + +lemma schurHistory_iterate (a : MatrixObject) (xs : List MatrixObject) : + ((schurNextData^[a.1]) (a,xs)).2=schurHistoryData a++xs := by + rcases a with ⟨d,A⟩ + induction d generalizing xs with + | zero => simp [schurHistoryData] + | succ d ih => + rw [Function.iterate_succ_apply] + change ((schurNextData^[d]) (⟨d,KS.W17.schurTail A⟩,⟨d+1,A⟩::xs)).2=_ + rw [ih] + simp only [schurHistoryData,List.append_assoc,List.singleton_append] + +def schurHistory : Realizes matrixObjectCode (listCode matrixObjectCode) schurHistoryData := + (((matrixDim.both ((identity matrixObjectCode).both + (constant matrixObjectCode (listCode matrixObjectCode) []))).then schurNext.iterate).then + schurOld).congr (fun a => by simpa only [List.append_nil,id_eq] using schurHistory_iterate a []) + +lemma schurNext_invariant (a : MatrixObject) + (hA : (a.2.map (fun q : ℚ => (q:ℝ))).PosSemidef) (j : ℕ) : + let s := schurNextData^[j] (a,[]) + SchurDesc a s.1 ∧ (∀b∈s.2,SchurDesc a b) ∧ s.2.length≤j := by + induction j with + | zero => exact ⟨SchurDesc.refl a,by simp,by simp⟩ + | succ j ih => + rw [Function.iterate_succ_apply'] + dsimp only + dsimp only at ih + generalize he : schurNextData^[j] (a,[])=s at ih ⊢ + unfold schurNextData + split_ifs with hz + · exact ⟨ih.1,ih.2.1,by omega⟩ + · refine ⟨ih.1.schur hA,?_,?_⟩ + · simpa only [List.mem_cons,forall_eq_or_imp] using And.intro ih.1 ih.2.1 + · simp only [List.length_cons];omega + +lemma schurHistory_mem (a : MatrixObject) + (hA : (a.2.map (fun q : ℚ => (q:ℝ))).PosSemidef) : + ∀b∈schurHistoryData a, SchurDesc a b := by + have h := (schurNext_invariant a hA a.1).2.1 + simpa only [schurHistory_iterate,List.append_nil] using h + +lemma runsPoly_schurHistory {ι : Type*} {L : ι → ℕ} (a : ι → MatrixObject) + (ha : IsPoly L (fun i => (matrixObjectCode (a i)).length)) + (hA : ∀i, ((a i).2.map (fun q : ℚ => (q:ℝ))).PosSemidef) : + RunsPoly L schurHistory a := by + let dim := fun i => (a i).1 + let bits := fun i => (matrixObjectCode (a i)).length + have hd : IsPoly L dim := ha.mono (fun i => matrixObject_dim_le (a i)) + have hi : IsPoly L (fun i => KS.W30.inverseBitBound (dim i) (bits i)) := by + apply (((isPoly_const L 6).mul (ha.add (isPoly_const L 1))).mul + ((hd.add (isPoly_const L 1)).pow 3)).mono + exact fun i => KS.W30.inverseBitBound_le_polynomial _ _ + have hb := (((isPoly_const L 2).mul hd).add (isPoly_const L 1)).add + (hd.mul (((isPoly_const L 2).mul (hd.mul (((isPoly_const L 2).mul + (((isPoly_const L 4).mul hi).add (isPoly_const L 7))).add (isPoly_const L 1)))).add (isPoly_const L 1))) + obtain ⟨p,hp⟩ := hb + have hs : IsPoly (fun s : {s : ι×ℕ // s.2<(a s.1).1} => L s.val.1) + (fun s => (schurStackCode (schurNextData^[s.val.2] (a s.val.1,[]))).length) := by + have hpoly := (((isPoly_const L 2).mul (show IsPoly L (fun i => p.eval (L i)) from ⟨p,fun _ => le_rfl⟩)).add (isPoly_const L 1)).add + (hd.mul (((isPoly_const L 2).mul (show IsPoly L (fun i => p.eval (L i)) from ⟨p,fun _ => le_rfl⟩)).add (isPoly_const L 1))) + apply (hpoly.reindex (fun s : {s : ι×ℕ // s.2<(a s.1).1} => s.val.1)).mono + intro s + obtain ⟨hc,ho,hl⟩ := schurNext_invariant (a s.val.1) (hA s.val.1) s.val.2 + have hb : ∀b, SchurDesc (a s.val.1) b → (matrixObjectCode b).length≤p.eval (L s.val.1) := + fun b h => h.wire.trans (hp s.val.1) + have hcur := hb _ hc + have hlist := listCode_length_bound _ (p.eval (L s.val.1)) (fun b h => hb b (ho b h)) + have hlen : (schurNextData^[s.val.2] (a s.val.1,[])).2.length≤dim s.val.1 := + hl.trans s.property.le + have hlist' := hlist.trans (Nat.mul_le_mul_right _ hlen) + dsimp only [dim] at hlist' + simp only [schurStackCode,prodCode_length] + dsimp only [Function.comp_apply,dim] + omega + unfold schurHistory + apply RunsPoly.congr + apply RunsPoly.then_poly + apply RunsPoly.then_with (RunsPoly.of_poly _ a ha) + intro hw + apply runsPoly_iterate _ _ hw + obtain ⟨q,hq⟩ := (RunsPoly.of_poly schurNext _ hs).cost + exact ⟨q,fun i j hj => hq ⟨(i,j),hj⟩⟩ + +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Squares.lean b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Squares.lean new file mode 100644 index 0000000000000000000000000000000000000000..9fa4c12bbf2e80106db1ea1ebebcc23a760c8ef4 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RationalMatrix/Squares.lean @@ -0,0 +1,117 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.BitSupport +import OAI.Analysis.MatrixSigning.Realization.FaceQueryRealization + +namespace OAI + +/-! Rational squares. -/ + +section + +namespace AlgorithmicThinTrees.RationalGram +open CurrentKS.RationalBits + +def base4Squares : ℕ → ℕ → List ℕ + | 0, _ => [] + | k+1,n => List.replicate (n%4) 1 ++ (base4Squares k (n/4)).map (2*·) + +lemma base4Squares_sum (k n : ℕ) (hn : n < 4^k) : + ((base4Squares k n).map (·^2)).sum = n := by + induction k generalizing n with + | zero => + have hz : n=0 := by simpa using hn + subst n + rfl + | succ k ih => + have hn' : n/4 < 4^k := (Nat.div_lt_iff_lt_mul (by decide)).mpr (by + simpa only [pow_succ] using hn) + have hsum : ((base4Squares k (n/4)).map (fun a => (2*a)^2)).sum = + 4*((base4Squares k (n/4)).map (fun a => a^2)).sum := by + rw [← List.sum_map_mul_left] + congr 2 + funext a + ring + simp only [base4Squares,List.map_append,List.map_replicate,one_pow, + List.map_map,Function.comp_def,List.sum_append,List.sum_replicate,nsmul_eq_mul,mul_one] + rw [hsum,ih _ hn'] + exact Nat.mod_add_div n 4 + +lemma base4Squares_length (k n : ℕ) : (base4Squares k n).length ≤ 3*k := by + induction k generalizing n with + | zero => simp [base4Squares] + | succ k ih => + simp only [base4Squares,List.length_append,List.length_replicate,List.length_map] + have hh := ih (n/4) + have hd := Nat.mod_lt n (by decide : 0<4) + omega + +lemma base4Squares_entry (k n a : ℕ) (ha : a ∈ base4Squares k n) : a ≤ 2^k := by + induction k generalizing n a with + | zero => simp [base4Squares] at ha + | succ k ih => + simp only [base4Squares,List.mem_append,List.mem_replicate,List.mem_map] at ha + rcases ha with ⟨_,rfl⟩|⟨v,hv,rfl⟩ + · exact Nat.one_le_two_pow + · rw [pow_succ] + simpa only [Nat.mul_comm] using Nat.mul_le_mul_left 2 (ih (n/4) v hv) + +def scalarFactors (q : ℚ) : List ℚ := + let n := q.num.natAbs*q.den + (base4Squares n.size n).map (fun a : ℕ => (a:ℚ)/q.den) + +lemma scalarFactors_zero : scalarFactors 0=[] := by simp [scalarFactors,base4Squares] + +lemma scalarFactors_sum (q : ℚ) (hq : 0 ≤ q) : + ((scalarFactors q).map (·^2)).sum=q := by + let n := q.num.natAbs*q.den + have hn : n < 4^n.size := (Nat.lt_size_self n).trans_le + (Nat.pow_le_pow_left (by decide : 2≤4) _) + have hh := base4Squares_sum n.size n hn + have hcast : ((base4Squares n.size n).map (fun a : ℕ => (a:ℚ)^2)).sum=(n:ℚ) := by + simpa only [Nat.cast_list_sum,List.map_map,Function.comp_def,Nat.cast_pow] using + congrArg (fun a : ℕ => (a:ℚ)) hh + have hden : (q.den:ℚ) ≠ 0 := Nat.cast_ne_zero.mpr q.den_ne_zero + have hnum : (q.num.natAbs:ℚ)=(q.num:ℚ) := by + simpa only [Int.cast_natCast] using + congrArg (fun a : ℤ => (a:ℚ)) (Int.natAbs_of_nonneg (Rat.num_nonneg.mpr hq)) + simp only [scalarFactors,List.map_map,Function.comp_def,div_pow] + change ((base4Squares n.size n).map (fun a : ℕ => (a:ℚ)^2/(q.den:ℚ)^2)).sum=q + simp_rw [div_eq_mul_inv] + rw [List.sum_map_mul_right,hcast,←div_eq_mul_inv] + dsimp [n] + push_cast + rw [hnum] + rw [show (q.num:ℚ)*(q.den:ℚ)/(q.den:ℚ)^2 = (q.num:ℚ)/q.den by field_simp] + exact Rat.num_div_den q + +lemma product_size {q : ℚ} {b : ℕ} (hq : Parts b q) : + (q.num.natAbs*q.den).size ≤ 2*b+1 := by + have h := Nat.mul_le_mul hq.1 hq.2 + rw [← pow_add] at h + simpa only [Nat.size_pow,two_mul] using Nat.size_le_size h + +lemma scalarFactors_length {q : ℚ} {b : ℕ} (hq : Parts b q) : + (scalarFactors q).length ≤ 3*(2*b+1) := by + rw [scalarFactors,List.length_map] + exact (base4Squares_length _ _).trans (Nat.mul_le_mul_left 3 (product_size hq)) + +lemma scalarFactors_parts {q : ℚ} {b : ℕ} (hq : Parts b q) + {v : ℚ} (hv : v ∈ scalarFactors q) : Parts (3*b+1) v := by + rcases List.mem_map.mp hv with ⟨a,ha,rfl⟩ + have hanum := base4Squares_entry _ _ a ha + have hb := product_size hq + have hp : Parts (2*b+1) (a:ℚ) := by + constructor + · simpa using hanum.trans (Nat.pow_le_pow_right (by decide) hb) + · simp [Nat.one_le_two_pow] + have hd : Parts b (q.den:ℚ) := by + constructor + · simpa using hq.2 + · simp [Nat.one_le_two_pow] + convert hp.div hd using 1 + omega + +end AlgorithmicThinTrees.RationalGram +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RealRoots.lean b/lean/OAI/Combinatorics/ThinTrees/RealRoots.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f04b52c6e396e429839542e55b3fdd32d37d42c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RealRoots.lean @@ -0,0 +1,85 @@ +import OAI.Combinatorics.ThinTrees.Monicity + +namespace OAI + +universe uI uD uR uS + +section + +noncomputable section +open Matrix Polynomial Finset +open scoped MatrixOrder ComplexOrder +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] [CommRing R] + +def fullPencil (A : I → Matrix D D R) : MvPolynomial (Option I) R := + pencil (fun o => o.elim 1 A) + +omit [DecidableEq I] in +lemma coefficientX_fullPencil (A : I → Matrix D D R) : + coefficientX (fullPencil A)=basePencil ((Polynomial.X : R[X]) • (1 : Matrix D D R[X])) + (fun i => (A i).map Polynomial.C) := by + let N : Matrix D D (MvPolynomial (Option I) R) := fun a b => + ∑i : Option I, MvPolynomial.X i * MvPolynomial.C ((i.elim (1 : Matrix D D R) A) a b) + change coefficientX N.det = _ + unfold basePencil + rw [(coefficientX (I := I) (R := R)).map_det N] + apply congrArg Matrix.det + apply Matrix.ext + intro a b + change coefficientX (∑i : Option I, MvPolynomial.X i * MvPolynomial.C ((i.elim 1 A) a b))=_ + simp only [Fintype.sum_option,Option.elim] + simp only [Matrix.add_apply,Matrix.sum_apply,Matrix.map_apply,Matrix.smul_apply,smul_eq_mul,map_mul] + by_cases h : a=b <;> simp [Matrix.one_apply,h] + +lemma mixedChar_uniSlice (A : I → Matrix D D R) : mixedChar A= + uniSlice (diffProduct ((Finset.univ.toList : List I).map some) (fullPencil A)) := by + rw [←eval_zero_coefficientX,coefficientX_diffProduct,coefficientX_fullPencil] + rfl + +omit [DecidableEq I] in +lemma fullPencil_map {S : Type uS} [CommRing S] (f : R →+* S) (A : I → Matrix D D R) : + (fullPencil A).map f=fullPencil (fun i => (A i).map f) := by + unfold fullPencil + rw [pencil_map] + congr 1 + funext i + cases i with + | none => simp + | some i => rfl + +omit [DecidableEq I] in +lemma fullPencil_stable (A : I → Matrix D D ℝ) (hA : ∀i, (A i).PosSemidef) : + RealStable (fullPencil A) := by + unfold RealStable + rw [fullPencil_map] + apply determinantPencil_stable + · intro i + cases i with + | none => exact Matrix.PosSemidef.one + | some i => exact posSemidef_complex (hA i) + · rw [Fintype.sum_option] + simpa only [Option.elim] using (Matrix.PosDef.one.add_posSemidef + (Matrix.posSemidef_sum Finset.univ (fun i _ => posSemidef_complex (hA i)))) + +lemma mixedChar_splits (A : I → Matrix D D ℝ) (hA : ∀i, (A i).PosSemidef) : + (mixedChar A).Splits := by + by_cases h0 : mixedChar A=0 + · rw [h0]; simp + apply splits_of_upper_half_plane + rw [mixedChar_uniSlice,←uniSlice_map,←diffProduct_map] + have hs : Stable (diffProduct ((Finset.univ.toList : List I).map some) + ((fullPencil A).map (algebraMap ℝ ℂ))) := by + rw [diffProduct_foldl] + exact (fullPencil_stable A hA).differentialProduct _ + rw [uniSlice_eq_slice] + apply hs.slice_boundary _ (by simp) none + rw [←uniSlice_eq_slice,diffProduct_map,uniSlice_map,←mixedChar_uniSlice] + exact Polynomial.map_ne_zero h0 + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Records.lean b/lean/OAI/Combinatorics/ThinTrees/Records.lean new file mode 100644 index 0000000000000000000000000000000000000000..116cbca041b677b32ceb915906fba5728d0ae581 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Records.lean @@ -0,0 +1,316 @@ +import OAI.Combinatorics.ThinTrees.Hierarchy + +namespace OAI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n h : ℕ} (H : Hierarchy n) + +def domain (A : Finset (Fin n)) (P : Finset (Finset (Fin n))) : Finset (Finset (Fin n)) := + H.nodes.filter (fun B => B ⊆ A ∧ ∀S ∈ P, ¬B ⊆ S) + +def leaves (_H : Hierarchy n) (A : Finset (Fin n)) (P : Finset (Finset (Fin n))) : Finset (Fin n) := + A\P.biUnion id + +lemma mem_domain {A B : Finset (Fin n)} {P : Finset (Finset (Fin n))} : + B ∈ H.domain A P ↔ B ∈ H.nodes ∧ B ⊆ A ∧ ∀S ∈ P, ¬B ⊆ S := by + simp [domain] + +lemma mem_leaves {A : Finset (Fin n)} {P : Finset (Finset (Fin n))} {v : Fin n} : + v ∈ H.leaves A P ↔ v ∈ A ∧ ∀S ∈ P, v ∉ S := by + simp [leaves] + +lemma root_mem_domain {A : Finset (Fin n)} {P : Finset (Finset (Fin n))} + (hA : A ∈ H.nodes) (hP : ∀S ∈ P, S ⊂ A) : A ∈ H.domain A P := by + apply H.mem_domain.mpr + refine ⟨hA,Subset.refl _,?_⟩ + intro S hS hh + have hs := hP S hS + exact (Finset.ssubset_iff_subset_ne.mp hs).2 (Subset.antisymm hs.subset hh) + +lemma singleton_domain_iff {A : Finset (Fin n)} {P : Finset (Finset (Fin n))} {v : Fin n} : + {v} ∈ H.domain A P ↔ v ∈ H.leaves A P := by + simp only [mem_domain,H.singletons,true_and,singleton_subset_iff,mem_leaves] + +lemma domain_root_test {A B : Finset (Fin n)} {P Q : Finset (Finset (Fin n))} + (hA : A ∈ H.nodes) (hB : B ∈ H.nodes) + (hP : ∀S ∈ P, S ⊂ A) (hQ : ∀S ∈ Q, S ⊂ B) : + (H.domain A P ∩ H.domain B Q).Nonempty ↔ + A ∈ H.domain B Q ∨ B ∈ H.domain A P := by + constructor + · rintro ⟨C,hC⟩ + obtain ⟨hCA,hCB⟩ := mem_inter.mp hC + obtain ⟨hCnode,hCA,hCP⟩ := H.mem_domain.mp hCA + obtain ⟨_,hCB,hCQ⟩ := H.mem_domain.mp hCB + rcases H.laminar A hA B hB with hAB | hBA | hdis + · left + apply H.mem_domain.mpr + exact ⟨hA,hAB,fun S hS hh => hCQ S hS (hCA.trans hh)⟩ + · right + apply H.mem_domain.mpr + exact ⟨hB,hBA,fun S hS hh => hCP S hS (hCB.trans hh)⟩ + · obtain ⟨v,hv⟩ := H.nonempty C hCnode + exact (Finset.disjoint_left.mp hdis (hCA hv) (hCB hv)).elim + · rintro (hAB | hBA) + · exact ⟨A,mem_inter.mpr ⟨H.root_mem_domain hA hP,hAB⟩⟩ + · exact ⟨B,mem_inter.mpr ⟨hBA,H.root_mem_domain hB hQ⟩⟩ + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry + +structure Record (n : ℕ) where + shell : RadialShell (Fin n) + owner : Finset (Fin n) + predecessors : Finset (Finset (Fin n)) + avoided : Option (Finset (Fin n)) + deriving DecidableEq + +namespace Record +variable {n m h : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) + +def excluded (B : Record n) : Finset (Finset (Fin n)) := + B.predecessors ∪ B.avoided.toFinset + +def conflict (B : Record n) := H.domain B.owner B.excluded +def leafSet (B : Record n) := H.leaves B.owner B.excluded +def routing (B : Record n) : Finset (Fin n) := B.owner\B.avoided.getD ∅ + +def Shape (B : Record n) : Prop := + B.owner ∈ H.nodes ∧ (∀S ∈ B.excluded, S ∈ H.nodes ∧ S ⊂ B.owner) + +def Protected (B : Record n) : Prop := + ∀S ∈ B.predecessors, ∀e ∈ G.cut univ S, + B.shell.outer ≤ l1dist (X (G.left e)) (X B.shell.center) ∧ + B.shell.outer ≤ l1dist (X (G.right e)) (X B.shell.center) + +def RoutingCertificate (q : ℝ) (B : Record n) : Prop := + ∃R : Finset (Fin n), R ⊆ B.routing ∧ G.EdgeConnectedReal R q ∧ + (∃u ∈ R, u ∈ B.leafSet H ∧ l1dist (X u) (X B.shell.center) ≤ B.shell.inner) ∧ + (∃v ∈ R, B.shell.outer ≤ l1dist (X v) (X B.shell.center)) + +def Valid (q : ℝ) (B : Record n) : Prop := + B.Shape H ∧ B.Protected G X ∧ B.shell.Valid X ∧ B.RoutingCertificate H G X q + +lemma root_mem {B : Record n} (hB : B.Shape H) : B.owner ∈ B.conflict H := + H.root_mem_domain hB.1 (fun S hS => (hB.2 S hS).2) + +lemma mem_leafSet {B : Record n} {v : Fin n} : + v ∈ B.leafSet H ↔ v ∈ B.owner ∧ ∀S ∈ B.excluded, v ∉ S := H.mem_leaves + +lemma mem_routing {B : Record n} {v : Fin n} : + v ∈ B.routing ↔ v ∈ B.owner ∧ ∀S ∈ B.avoided.toFinset, v ∉ S := by + cases heq : B.avoided <;> simp [routing,heq] + +lemma protected_routing_edges {B : Record n} (hB : B.Protected G X) + {R : Finset (Fin n)} (hR : R ⊆ B.routing) : + ∀e ∈ G.inducedEdges R, + ((G.left e ∈ B.leafSet H ∧ G.right e ∉ B.leafSet H) ∨ + (G.right e ∈ B.leafSet H ∧ G.left e ∉ B.leafSet H)) → + B.shell.outer ≤ l1dist (X (G.left e)) (X B.shell.center) ∧ + B.shell.outer ≤ l1dist (X (G.right e)) (X B.shell.center) := by + have hex {u v : Fin n} (hu : u ∈ B.leafSet H) (hv : v ∈ B.routing) + (hn : v ∉ B.leafSet H) : ∃S ∈ B.predecessors, u ∉ S ∧ v ∈ S := by + obtain ⟨hu,hup⟩ := (mem_leafSet H).mp hu + obtain ⟨hv,hva⟩ := mem_routing.mp hv + have : ∃S ∈ B.excluded, v ∈ S := by + by_contra hh + push Not at hh + exact hn ((mem_leafSet H).mpr ⟨hv,hh⟩) + obtain ⟨S,hS,hvS⟩ := this + have hSp : S ∈ B.predecessors := by + rcases mem_union.mp hS with hh | hh + · exact hh + · exact (hva S hh hvS).elim + exact ⟨S,hSp,hup S hS,hvS⟩ + intro e he hcross + obtain ⟨hlR,hrR⟩ := (G.mem_inducedEdges _ _).mp he + rcases hcross with hcross | hcross + · obtain ⟨S,hS,hl,hr⟩ := hex hcross.1 (hR hrR) hcross.2 + exact hB S hS e (mem_filter.mpr ⟨mem_univ _,Or.inr ⟨hr,hl⟩⟩) + · obtain ⟨S,hS,hr,hl⟩ := hex hcross.1 (hR hlR) hcross.2 + exact hB S hS e (mem_filter.mpr ⟨mem_univ _,Or.inl ⟨hl,hr⟩⟩) + +lemma variation_lower {q : ℝ} {B : Record n} (hB : B.Valid H G X q) : + q*B.shell.width ≤ ∑e ∈ G.inducedEdges (B.leafSet H), + |clamp B.shell.inner B.shell.outer (l1dist (X (G.left e)) (X B.shell.center))- + clamp B.shell.inner B.shell.outer (l1dist (X (G.right e)) (X B.shell.center))| := by + obtain ⟨R,hR,hconn,hu,hv⟩ := hB.2.2.2 + exact G.routed_variation_lower _ hB.2.2.1.2.1.le hconn hu hv + (protected_routing_edges H G X hB.2.1 hR) + +lemma restrict_valid {q a b : ℝ} {B : Record n} (hB : B.Valid H G X q) + (ha : B.shell.inner ≤ a) (hb : b ≤ B.shell.outer) (hab : a < b) : + ({B with shell := RadialShell.hollow B.shell.center a b}).Valid H G X q := by + refine ⟨hB.1,?_,?_,?_⟩ + · intro S hS e he + exact ⟨hb.trans (hB.2.1 S hS e he).1,hb.trans (hB.2.1 S hS e he).2⟩ + · obtain ⟨u,hu⟩ := hB.2.2.1.2.2.2.1 + obtain ⟨v,hv⟩ := hB.2.2.1.2.2.2.2 + exact ⟨hB.2.2.1.1.trans ha,hab,by simp [RadialShell.hollow],⟨u,hu.trans ha⟩,⟨v,hb.trans hv⟩⟩ + · obtain ⟨R,hR,hconn,⟨u,huR,huL,hu⟩,⟨v,hvR,hv⟩⟩ := hB.2.2.2 + exact ⟨R,hR,hconn,⟨u,huR,huL,hu.trans ha⟩,⟨v,hvR,hb.trans hv⟩⟩ + +end Record +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) + +def LabeledArrangement (q : ℝ) (Z : Finset (Record n)) : Prop := + (∀B ∈ Z, B.Valid H G X q) ∧ + (Z : Set (Record n)).Pairwise (fun B D => + ¬Disjoint (B.shell.support X) (D.shell.support X) → + Disjoint (B.conflict H) (D.conflict H)) + +lemma labeled_energy {q : ℝ} (hX : ∀v, binary (X v)) {Z : Finset (Record n)} + (hZ : H.LabeledArrangement G X q Z) : + q*(∑B ∈ Z, B.shell.width) ≤ ∑e : Fin m, l1dist (X (G.left e)) (X (G.right e)) := by + let f (B : Record n) (e : Fin m) := + |clamp B.shell.inner B.shell.outer (l1dist (X (G.left e)) (X B.shell.center))- + clamp B.shell.inner B.shell.outer (l1dist (X (G.right e)) (X B.shell.center))| + calc + _ = ∑B ∈ Z, q*B.shell.width := mul_sum _ _ _ + _ ≤ ∑B ∈ Z, ∑e ∈ G.inducedEdges (B.leafSet H), f B e := + sum_le_sum (fun B hB => B.variation_lower H G X (hZ.1 B hB)) + _ = ∑e : Fin m, ∑B ∈ Z.filter (fun B => e ∈ G.inducedEdges (B.leafSet H)), f B e := by + simp only [inducedEdges,sum_filter,mem_filter,mem_univ,true_and] + rw [sum_comm] + _ ≤ _ := by + apply sum_le_sum + intro e he + let W := Z.filter (fun B => e ∈ G.inducedEdges (B.leafSet H)) + rw [← Finset.sum_coe_sort] + apply binary_shell_edge_bound (binary_cube (hX _)) (binary_cube (hX _)) + (fun B : W => X B.val.shell.center) (fun B => hX _) _ _ + · intro B + exact (hZ.1 B.val (mem_filter.mp B.property).1).2.2.1.2.1.le + · intro B D hBD w hw hbad + have hB : B.val ∈ Z := (mem_filter.mp B.property).1 + have hD : D.val ∈ Z := (mem_filter.mp D.property).1 + have hinter : ¬Disjoint (B.val.shell.support X) (D.val.shell.support X) := by + intro hh + exact Set.disjoint_left.mp hh ⟨hw,hbad.2.1,Or.inr hbad.1⟩ + ⟨hw,hbad.2.2.2,Or.inr hbad.2.2.1⟩ + have hdis := hZ.2 hB hD (fun hh => hBD (Subtype.ext hh)) hinter + have hlB := ((G.mem_inducedEdges _ _).mp (mem_filter.mp B.property).2).1 + have hlD := ((G.mem_inducedEdges _ _).mp (mem_filter.mp D.property).2).1 + have hmB : {G.left e} ∈ B.val.conflict H := H.singleton_domain_iff.mpr hlB + have hmD : {G.left e} ∈ D.val.conflict H := H.singleton_domain_iff.mpr hlD + exact Finset.disjoint_left.mp hdis hmB hmD + +end +end StrongThinTree.MultiGraph.Hierarchy + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry +variable {n m h : ℕ} (H : Hierarchy n) (G : MultiGraph n m) + (X : Fin n → Fin h → ℝ) + +def parentBoundary (A : Finset (Fin n)) : Finset (Fin m) := + G.cut (G.inducedEdges (H.parent A)) A + +def LocallyConnectedReal (q : ℝ) : Prop := ∀A ∈ H.nodes, G.EdgeConnectedReal A q + +lemma parent_boundary_lower {q : ℝ} (hconn : H.LocallyConnectedReal G q) + {A : Finset (Fin n)} (hA : A ∈ H.nodes) (hne : A ≠ univ) : + q ≤ (H.parentBoundary G A).card := + hconn (H.parent A) (H.parent_mem A hA hne) A (H.nonempty A hA) + (H.parent_strict A hA hne) + +structure AssignedBag (δ η : ℝ) where + owner : Finset (Fin n) + owner_mem : owner ∈ H.nodes + nonroot : owner ≠ univ + centers : Finset (Fin n) + nonempty : centers.Nonempty + radius_pos : 0 < δ + disjoint : (centers : Set (Fin n)).Pairwise (fun u v => + Disjoint ((RadialShell.ball u δ).support X) ((RadialShell.ball v δ).support X)) + assignment : η*(H.parentBoundary G owner).card ≤ (centers.card : ℝ) + endpoint : ∀u ∈ centers, u ∈ owner ∧ ∃e ∈ H.parentBoundary G owner, + (G.left e = u ∨ G.right e = u) ∧ l1dist (X (G.left e)) (X (G.right e)) < δ + +namespace AssignedBag +variable {H G X} {δ η : ℝ} (A : H.AssignedBag G X δ η) + +def input (P : Finset (Finset (Fin n))) (u : Fin n) : Record n := + ⟨RadialShell.ball u δ,A.owner,P,none⟩ + +lemma input_leaf {P : Finset (Finset (Fin n))} (hP : ∀S ∈ P, S ⊂ A.owner) + {u : Fin n} (hu : u ∈ A.centers) (hins : (A.input P u).Protected G X) : + u ∈ (A.input P u).leafSet H := by + apply (Record.mem_leafSet H).mpr + refine ⟨(A.endpoint u hu).1,?_⟩ + intro S hS huS + have hSP : S ∈ P := by simpa [Record.excluded,input] using hS + obtain ⟨e,he,heu,hlen⟩ := (A.endpoint u hu).2 + have he' := (mem_filter.mp he).2 + have hcut : e ∈ G.cut univ S := by + apply mem_filter.mpr + refine ⟨mem_univ _,?_⟩ + rcases he' with hh | hh + · have hright : G.right e ∉ S := fun hs => hh.2 ((hP S hSP).subset hs) + rcases heu with heu | heu + · exact Or.inl ⟨heu.symm ▸ huS,hright⟩ + · exact (hright (heu.symm ▸ huS)).elim + · have hleft : G.left e ∉ S := fun hs => hh.2 ((hP S hSP).subset hs) + rcases heu with heu | heu + · exact (hleft (heu.symm ▸ huS)).elim + · exact Or.inr ⟨heu.symm ▸ huS,hleft⟩ + have hp := hins S hSP e hcut + rcases heu with heu | heu + · have hp := hp.1 + change δ ≤ l1dist (X (G.left e)) (X u) at hp + rw [heu,l1dist_self] at hp + linarith [A.radius_pos] + · have hp := hp.2 + change δ ≤ l1dist (X (G.right e)) (X u) at hp + rw [heu,l1dist_self] at hp + linarith [A.radius_pos] + +lemma input_valid (hX : ∀v, binary (X v)) {q : ℝ} (_hq : 0 ≤ q) + (hconn : H.LocallyConnectedReal G q) (hsize : 1 < A.centers.card) + {P : Finset (Finset (Fin n))} (hP : ∀S ∈ P, S ∈ H.nodes ∧ S ⊂ A.owner) + {u : Fin n} (hu : u ∈ A.centers) (hins : (A.input P u).Protected G X) : + (A.input P u).Valid H G X (q/4) := by + obtain ⟨v,hv,hvu⟩ := Finset.exists_mem_ne hsize u + have hdist := RadialShell.disjoint_balls_distance hX u v (A.disjoint hu hv hvu.symm) + have houter : δ ≤ l1dist (X v) (X u) := by + rw [l1dist_comm] + linarith [A.radius_pos] + refine ⟨?_,hins,?_,?_⟩ + · refine ⟨A.owner_mem,?_⟩ + intro S hS + exact hP S (by simpa [input,Record.excluded] using hS) + · exact ⟨le_refl 0,A.radius_pos,by simp [input,RadialShell.ball], + ⟨u,by simp [input,RadialShell.ball,l1dist_self]⟩,⟨v,houter⟩⟩ + · refine ⟨A.owner,?_,?_,⟨u,(A.endpoint u hu).1,A.input_leaf (fun S hS => (hP S hS).2) hu hins,?_⟩, + ⟨v,(A.endpoint v hv).1,houter⟩⟩ + · simp [input,Record.routing] + · intro S hS hSA + have hh := hconn A.owner A.owner_mem S hS hSA + linarith + · simp [input,RadialShell.ball,l1dist_self] + +end AssignedBag +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Representation.lean b/lean/OAI/Combinatorics/ThinTrees/Representation.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5b3dabaa5ed1e02c9b5bd3e92017c912187a891 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Representation.lean @@ -0,0 +1,786 @@ +import OAI.Combinatorics.ThinTrees.TwoSystems + +namespace OAI + +universe uι uE uT uI uE2 uE3 uV uE4 uV2 uW + +section + +open Matrix Finset +open scoped BigOperators MatrixOrder Matrix.Norms.Elementwise +namespace StrongThinTree +noncomputable section + +section Determinant +variable {ι : Type uι} [Fintype ι] [DecidableEq ι] + +lemma hasDerivAt_det_one_add_smul (M : Matrix ι ι ℝ) : + HasDerivAt (fun t : ℝ => (1 + t • M).det) M.trace 0 := by + let p : Polynomial ℝ := + (Matrix.det (1 + (Polynomial.X : Polynomial ℝ) • M.map Polynomial.C)).divX.divX + have hp := p.hasDerivAt (0 : ℝ) + have hid := hasDerivAt_id (0 : ℝ) + have h := ((hasDerivAt_const (0 : ℝ) (1 : ℝ)).add + (hid.const_mul M.trace)).add (hp.mul (hid.pow 2)) + have heq : (fun t : ℝ => (1 + t • M).det) = + (fun t : ℝ => 1 + M.trace * t + p.eval t * t ^ 2) := by + funext t + exact Matrix.det_one_add_smul t M + rw [heq] + simpa using! h + +lemma hasDerivAt_det_add_smul (A B : Matrix ι ι ℝ) (hA : IsUnit A) : + HasDerivAt (fun t : ℝ => (A + t • B).det) + (A.det * (A⁻¹ * B).trace) 0 := by + have hmul : A * A⁻¹ = 1 := Matrix.mul_nonsing_inv A + ((Matrix.isUnit_iff_isUnit_det A).mp hA) + have heq (t : ℝ) : A + t • B = A * (1 + t • (A⁻¹ * B)) := by + simp [mul_add, ← mul_assoc, hmul] + have heq' : (fun t : ℝ => (A + t • B).det) = + (fun t : ℝ => A.det * (1 + t • (A⁻¹ * B)).det) := by + funext t + rw [heq, Matrix.det_mul] + rw [heq'] + exact (hasDerivAt_det_one_add_smul (A⁻¹ * B)).const_mul A.det + +lemma differentiable_det : Differentiable ℝ (Matrix.det : Matrix ι ι ℝ → ℝ) := by + classical + change Differentiable ℝ (fun M : Matrix ι ι ℝ => M.det) + simp_rw [Matrix.det_apply] + fun_prop + +lemma fderiv_det_apply (A B : Matrix ι ι ℝ) (hA : IsUnit A) : + fderiv ℝ Matrix.det A B = A.det * (A⁻¹ * B).trace := by + have hc : HasDerivAt (fun t : ℝ => A + t • B) B 0 := by + simpa using! (hasDerivAt_const (0 : ℝ) A).add + ((hasDerivAt_id (0 : ℝ)).smul_const B) + have hd : HasFDerivAt Matrix.det (fderiv ℝ Matrix.det A) (A + (0 : ℝ) • B) := by + simpa using! (differentiable_det A).hasFDerivAt + have h := hd.comp_hasDerivAt (0 : ℝ) hc + exact h.unique (hasDerivAt_det_add_smul A B hA) + +lemma one_le_det_one_add {A : Matrix ι ι ℝ} (hA : A.PosSemidef) : + 1 ≤ (1 + A).det := by + let U := hA.isHermitian.eigenvectorUnitary + let D : Matrix ι ι ℝ := Matrix.diagonal hA.isHermitian.eigenvalues + have hspec : A = (U : Matrix ι ι ℝ) * D * star (U : Matrix ι ι ℝ) := by + simpa [D, U, Unitary.conjStarAlgAut_apply] using hA.isHermitian.spectral_theorem + have hconj : 1 + A = (U : Matrix ι ι ℝ) * (1 + D) * star (U : Matrix ι ι ℝ) := by + rw [hspec] + simp [mul_add, add_mul] + rw [hconj, Matrix.det_mul_comm, ← mul_assoc, Unitary.coe_star_mul_self, one_mul] + have hdiag : 1 + D = Matrix.diagonal (fun i => 1 + hA.isHermitian.eigenvalues i) := by + simp only [D, ← Matrix.diagonal_one, Matrix.diagonal_add] + rw [hdiag, Matrix.det_diagonal] + exact Finset.one_le_prod₀ (fun i _ => by linarith [hA.eigenvalues_nonneg i]) + +lemma posDef_sqrt_factors {A : Matrix ι ι ℝ} (hA : A.PosDef) : + ∃ S : Matrix ι ι ℝ, S.IsHermitian ∧ IsUnit S ∧ S * S = A := by + refine ⟨CFC.sqrt A, (CFC.sqrt_nonneg A).posSemidef.isHermitian, ?_, + CFC.sqrt_mul_sqrt_self A hA.posSemidef.nonneg⟩ + apply (isUnit_pow_iff (by decide : 2 ≠ 0)).mp + rw [CFC.sq_sqrt A hA.posSemidef.nonneg] + exact hA.isUnit + +lemma det_le_det_add_of_posSemidef {A B : Matrix ι ι ℝ} + (hA : A.PosDef) (hB : B.PosSemidef) : A.det ≤ (A + B).det := by + obtain ⟨S, hSH, hSU, hS⟩ := posDef_sqrt_factors hA + have hSi : S * S⁻¹ = 1 := Matrix.mul_nonsing_inv S + ((Matrix.isUnit_iff_isUnit_det S).mp hSU) + have hiS : S⁻¹ * S = 1 := Matrix.nonsing_inv_mul S + ((Matrix.isUnit_iff_isUnit_det S).mp hSU) + let Q := S⁻¹ * B * S⁻¹ + have hQ : Q.PosSemidef := by + simpa only [hSH.inv.eq] using hB.mul_mul_conjTranspose_same S⁻¹ + have hdecomp : A + B = S * (1 + Q) * S := by + dsimp [Q] + simp only [mul_add, add_mul, mul_one, ← mul_assoc, hS] + simp only [mul_assoc, hSi, hiS, one_mul, mul_one] + have hdetS : S.det * S.det = A.det := by rw [← Matrix.det_mul, hS] + have hdet : (A + B).det = A.det * (1 + Q).det := by + rw [hdecomp, Matrix.det_mul, Matrix.det_mul] + rw [← hdetS] + ring + rw [hdet] + exact le_mul_of_one_le_right hA.det_pos.le (one_le_det_one_add hQ) + +end Determinant +section Regularization +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] +open Filter + +lemma exists_fderiv_norm_lt_of_bddBelow (f : E → ℝ) (hf : Differentiable ℝ f) + (L : ℝ) (hb : ∀ x, L ≤ f x) {ε : ℝ} (hε : 0 < ε) : + ∃ x, ‖fderiv ℝ f x‖ < ε := by + let K : ℝ := f 0 - L + have hK : 0 ≤ K := sub_nonneg.mpr (hb 0) + let γ : ℝ := ε ^ 2 / (16 * (K + 1)) + have hγ : 0 < γ := div_pos (sq_pos_of_pos hε) (by positivity) + let g : E → ℝ := fun x => f x + γ * ‖x‖ ^ 2 + have hg : Continuous g := hf.continuous.add + (continuous_const.mul (continuous_norm.pow 2)) + have hcoerc : Tendsto (fun x : E => L + γ * ‖x‖ ^ 2) (cocompact E) atTop := by + have hn : Tendsto (fun x : E => ‖x‖ ^ 2) (cocompact E) atTop := by + simpa only [pow_two] using + tendsto_norm_cocompact_atTop.atTop_mul_atTop₀ + (tendsto_norm_cocompact_atTop (E := E)) + exact tendsto_const_nhds.add_atTop (hn.const_mul_atTop hγ) + have hcoercg : Tendsto g (cocompact E) atTop := + tendsto_atTop_mono (fun x => by dsimp [g]; linarith [hb x]) hcoerc + obtain ⟨x, hx⟩ := hg.exists_forall_le hcoercg + have hx0 := hx 0 + have hvalue : γ * ‖x‖ ^ 2 ≤ K := by + dsimp [g] at hx0 + simp only [norm_zero, zero_pow (by decide : 2 ≠ 0), mul_zero, add_zero] at hx0 + dsimp [K] + linarith [hb x] + have hmin : IsLocalMin g x := by + exact (show IsMinOn g Set.univ x from fun y _ => hx y).isLocalMin + (by simp) + have hder := hmin.hasFDerivAt_eq_zero + ((hf x).hasFDerivAt.add + ((hasStrictFDerivAt_norm_sq x).hasFDerivAt.const_mul γ)) + have hnorm : ‖fderiv ℝ f x‖ = 2 * γ * ‖x‖ := by + have hd : fderiv ℝ f x = -(γ • ((2 : ℝ) • innerSL ℝ x)) := by + apply eq_neg_of_add_eq_zero_left + simpa only [two_smul] using hder + rw [hd, norm_neg, norm_smul, norm_smul, innerSL_apply_norm] + simp only [Real.norm_eq_abs, abs_of_pos hγ, abs_of_pos (by norm_num : (0 : ℝ) < 2)] + ring + refine ⟨x, ?_⟩ + rw [hnorm] + have hγeq : γ * (16 * (K + 1)) = ε ^ 2 := by + dsimp [γ] + exact div_mul_cancel₀ _ (ne_of_gt (by positivity)) + have hbnd := mul_le_mul_of_nonneg_left hvalue (le_of_lt hγ) + have hγK : 4 * γ * K < ε ^ 2 := by + nlinarith + have hxnonneg : 0 ≤ 2 * γ * ‖x‖ := by positivity + nlinarith [sq_nonneg (2 * γ * ‖x‖)] + +end Regularization +section Covariance +variable {T : Type uT} {I : Type uI} [Fintype T] [DecidableEq T] [Nonempty T] + [Fintype I] [DecidableEq I] + +def basisCov (b : Matrix I I ℝ) (a : I → ℝ) : Matrix I I ℝ := + b * diagonal (fun j => Real.exp (a j)) * bᵀ + +def packingCov (b : T → Matrix I I ℝ) (a : EuclideanSpace ℝ (T × I)) : + Matrix I I ℝ := ∑ t, basisCov (b t) (fun j => a (t, j)) + +lemma basisCov_eq_sum (b : Matrix I I ℝ) (a : I → ℝ) : + basisCov b a = ∑ j, Real.exp (a j) • vecMulVec (fun i => b i j) (fun i => b i j) := by + apply Matrix.ext + intro k l + change (∑ j, (b * diagonal (fun j => Real.exp (a j))) k j * b l j) = _ + simp only [Matrix.mul_diagonal, Matrix.sum_apply, Matrix.smul_apply, smul_eq_mul, + Matrix.vecMulVec_apply] + apply Finset.sum_congr rfl + intro j _ + ring + +omit [DecidableEq T] [Nonempty T] in +lemma packingCov_eq_sum (b : T → Matrix I I ℝ) (a : EuclideanSpace ℝ (T × I)) : + packingCov b a = ∑ e : T × I, Real.exp (a e) • + vecMulVec (fun i => b e.1 i e.2) (fun i => b e.1 i e.2) := by + simp only [packingCov, basisCov_eq_sum, Fintype.sum_prod_type] + +omit [DecidableEq T] [Nonempty T] in +lemma differentiable_packingCov (b : T → Matrix I I ℝ) : + Differentiable ℝ (packingCov b) := by + have heq : packingCov b = fun a => ∑ e : T × I, Real.exp (a e) • + vecMulVec (fun i => b e.1 i e.2) (fun i => b e.1 i e.2) := + funext (packingCov_eq_sum b) + rw [heq] + exact Differentiable.fun_sum fun e _ => + ((EuclideanSpace.proj (𝕜 := ℝ) e).differentiable.exp).smul_const _ + +omit [Nonempty T] in +lemma fderiv_packingCov_single (b : T → Matrix I I ℝ) + (a : EuclideanSpace ℝ (T × I)) (e : T × I) : + fderiv ℝ (packingCov b) a (EuclideanSpace.single e 1) = + Real.exp (a e) • vecMulVec (fun i => b e.1 i e.2) (fun i => b e.1 i e.2) := by + have heq : packingCov b = fun a => ∑ e : T × I, Real.exp (a e) • + vecMulVec (fun i => b e.1 i e.2) (fun i => b e.1 i e.2) := + funext (packingCov_eq_sum b) + have hd : HasFDerivAt (packingCov b) + (∑ e : T × I, (Real.exp (a e) • EuclideanSpace.proj (𝕜 := ℝ) e).smulRight + (vecMulVec (fun i => b e.1 i e.2) (fun i => b e.1 i e.2))) a := by + rw [heq] + exact HasFDerivAt.fun_sum fun e _ => + ((EuclideanSpace.proj (𝕜 := ℝ) e).hasFDerivAt.exp).smul_const _ + rw [hd.fderiv] + simp + +lemma basisCov_posDef (b : Matrix I I ℝ) (hb : IsUnit b) (a : I → ℝ) : + (basisCov b a).PosDef := by + have hd : (diagonal (fun j => Real.exp (a j))).PosDef := + Matrix.PosDef.diagonal (fun j => Real.exp_pos _) + simpa [basisCov] using hd.mul_mul_conjTranspose_same + (Matrix.vecMul_injective_of_isUnit hb) + +omit [DecidableEq T] in +lemma packingCov_posDef (b : T → Matrix I I ℝ) (hb : ∀ t, IsUnit (b t)) + (a : EuclideanSpace ℝ (T × I)) : (packingCov b a).PosDef := by + exact Matrix.posDef_sum Finset.univ_nonempty + (fun t _ => basisCov_posDef (b t) (hb t) _) + +lemma det_basisCov (b : Matrix I I ℝ) (a : I → ℝ) : + (basisCov b a).det = b.det ^ 2 * Real.exp (∑ j, a j) := by + simp only [basisCov, Matrix.det_mul, Matrix.det_transpose, Matrix.det_diagonal] + rw [Real.exp_sum] + ring + +omit [Nonempty T] in +lemma det_basisCov_le_packingCov (b : T → Matrix I I ℝ) + (hb : ∀ t, IsUnit (b t)) (a : EuclideanSpace ℝ (T × I)) (t : T) : + (basisCov (b t) (fun j => a (t, j))).det ≤ (packingCov b a).det := by + have hsum : packingCov b a = basisCov (b t) (fun j => a (t, j)) + + ∑ u ∈ Finset.univ.erase t, basisCov (b u) (fun j => a (u, j)) := by + exact (Finset.add_sum_erase _ _ (Finset.mem_univ t)).symm + rw [hsum] + apply det_le_det_add_of_posSemidef (basisCov_posDef _ (hb t) _) + exact Matrix.posSemidef_sum _ (fun u _ => (basisCov_posDef _ (hb u) _).posSemidef) + +def packingObjective (b : T → Matrix I I ℝ) (a : EuclideanSpace ℝ (T × I)) : ℝ := + Real.log (packingCov b a).det - (∑ e, a e) / Fintype.card T + +lemma packingObjective_bddBelow (b : T → Matrix I I ℝ) (hb : ∀ t, IsUnit (b t)) : + ∀ a, (∑ t, Real.log ((b t).det ^ 2)) / Fintype.card T ≤ packingObjective b a := by + intro a + have ht (t : T) : Real.log ((b t).det ^ 2) + ∑ j, a (t, j) ≤ + Real.log (packingCov b a).det := by + have hd := (basisCov_posDef (b t) (hb t) (fun j => a (t, j))).det_pos + have hbd := det_basisCov_le_packingCov b hb a t + have he := Real.log_le_log hd hbd + rw [det_basisCov, Real.log_mul (by + have := (Matrix.isUnit_iff_isUnit_det _).mp (hb t) + exact pow_ne_zero 2 this.ne_zero) (ne_of_gt (Real.exp_pos _)), Real.log_exp] at he + exact he + have hs := Finset.sum_le_sum (fun t (_ : t ∈ Finset.univ) => ht t) + simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] at hs + have hq : (0 : ℝ) < Fintype.card T := Nat.cast_pos.mpr Fintype.card_pos + dsimp [packingObjective] + rw [le_sub_iff_add_le, ← add_div, div_le_iff₀ hq] + rw [mul_comm] at hs + simpa only [Fintype.sum_prod_type] using hs + +omit [DecidableEq T] in +lemma differentiable_packingObjective (b : T → Matrix I I ℝ) (hb : ∀ t, IsUnit (b t)) : + Differentiable ℝ (packingObjective b) := by + intro a + apply DifferentiableAt.sub + · exact ((differentiable_det _).comp a (differentiable_packingCov b a)).log + (ne_of_gt (packingCov_posDef b hb a).det_pos) + · have hs : DifferentiableAt ℝ (fun a : EuclideanSpace ℝ (T × I) => ∑ e, a e) a := + DifferentiableAt.fun_sum (fun e _ => (EuclideanSpace.proj (𝕜 := ℝ) e).differentiableAt) + simpa only [div_eq_mul_inv] using hs.mul_const ((Fintype.card T : ℝ)⁻¹) + +lemma fderiv_packingObjective_single (b : T → Matrix I I ℝ) (hb : ∀ t, IsUnit (b t)) + (a : EuclideanSpace ℝ (T × I)) (e : T × I) : + fderiv ℝ (packingObjective b) a (EuclideanSpace.single e 1) = + Real.exp (a e) * ((fun i => b e.1 i e.2) ⬝ᵥ + ((packingCov b a)⁻¹ *ᵥ (fun i => b e.1 i e.2))) - 1 / Fintype.card T := by + have hn := (differentiable_packingCov b a).hasFDerivAt + have hd := (differentiable_det (packingCov b a)).hasFDerivAt.comp a hn + have hpos := (packingCov_posDef b hb a).det_pos + have hl := hd.log (ne_of_gt hpos) + have hs : HasFDerivAt (fun a : EuclideanSpace ℝ (T × I) => ∑ e, a e) + (∑ e, EuclideanSpace.proj (𝕜 := ℝ) e) a := + HasFDerivAt.fun_sum (fun e _ => (EuclideanSpace.proj (𝕜 := ℝ) e).hasFDerivAt) + have hsq : HasFDerivAt (fun a : EuclideanSpace ℝ (T × I) => (∑ e, a e) / Fintype.card T) + ((Fintype.card T : ℝ)⁻¹ • ∑ e, EuclideanSpace.proj (𝕜 := ℝ) e) a := by + simpa only [div_eq_mul_inv, mul_comm] using hs.const_mul ((Fintype.card T : ℝ)⁻¹) + have ho := hl.sub hsq + have ho' : HasFDerivAt (packingObjective b) _ a := ho + rw [ho'.fderiv] + change (packingCov b a).det⁻¹ * + (fderiv ℝ Matrix.det (packingCov b a)) + ((fderiv ℝ (packingCov b) a) (EuclideanSpace.single e 1)) - + (Fintype.card T : ℝ)⁻¹ * (∑ j, EuclideanSpace.proj (𝕜 := ℝ) j) (EuclideanSpace.single e 1) = _ + rw [fderiv_packingCov_single] + rw [fderiv_det_apply _ _ (packingCov_posDef b hb a).isUnit] + simp only [Matrix.mul_smul, Matrix.trace_smul, smul_eq_mul, Matrix.mul_vecMulVec, + Matrix.trace_vecMulVec, dotProduct_comm] + simp + field_simp + +lemma exists_small_leverages (b : T → Matrix I I ℝ) (hb : ∀ t, IsUnit (b t)) + {ρ : ℝ} (hρ : 0 < ρ) : + ∃ a : EuclideanSpace ℝ (T × I), ∀ e : T × I, + Real.exp (a e) * ((fun i => b e.1 i e.2) ⬝ᵥ + ((packingCov b a)⁻¹ *ᵥ (fun i => b e.1 i e.2))) ≤ + (1 + ρ) / Fintype.card T := by + have hq : (0 : ℝ) < Fintype.card T := Nat.cast_pos.mpr Fintype.card_pos + obtain ⟨a, ha⟩ := exists_fderiv_norm_lt_of_bddBelow (packingObjective b) + (differentiable_packingObjective b hb) + ((∑ t, Real.log ((b t).det ^ 2)) / Fintype.card T) + (packingObjective_bddBelow b hb) (div_pos hρ hq) + refine ⟨a, fun e => ?_⟩ + have hv := (fderiv ℝ (packingObjective b) a).le_opNorm (EuclideanSpace.single e 1) + simp only [PiLp.norm_single, norm_one, mul_one, Real.norm_eq_abs] at hv + have hu := (le_abs_self (fderiv ℝ (packingObjective b) a (EuclideanSpace.single e 1))).trans hv + have hu' := lt_of_le_of_lt hu ha + rw [fderiv_packingObjective_single b hb a e] at hu' + rw [add_div] + linarith + +theorem isotropic_representation (b : T → Matrix I I ℝ) (hb : ∀ t, IsUnit (b t)) + {ρ : ℝ} (hρ : 0 < ρ) : + ∃ (M : Matrix I I ℝ) (s : T × I → ℝ), IsUnit M ∧ (∀ e, 0 < s e) ∧ + let z := fun e : T × I => s e • (M *ᵥ fun i => b e.1 i e.2) + (∑ e, vecMulVec (z e) (z e)) = 1 ∧ + (∀ e, z e ⬝ᵥ z e ≤ (1 + ρ) / Fintype.card T) := by + obtain ⟨a, ha⟩ := exists_small_leverages b hb hρ + obtain ⟨S, hSH, hSU, hS⟩ := posDef_sqrt_factors (packingCov_posDef b hb a) + let M := S⁻¹ + let s : T × I → ℝ := fun e => Real.exp (a e / 2) + have hMU : IsUnit M := Matrix.isUnit_nonsing_inv_iff.mpr hSU + have hMT : Mᵀ = M := by simpa [M] using hSH.inv.eq + have hMS : M * S = 1 := Matrix.nonsing_inv_mul S + ((Matrix.isUnit_iff_isUnit_det S).mp hSU) + have hSM : S * M = 1 := Matrix.mul_nonsing_inv S + ((Matrix.isUnit_iff_isUnit_det S).mp hSU) + have hMNM : M * packingCov b a * M = 1 := by + rw [← hS, ← mul_assoc, hMS, one_mul, hSM] + have hMM : M * M = (packingCov b a)⁻¹ := by + apply Eq.symm + apply Matrix.inv_eq_left_inv + rw [← hS, mul_assoc, ← mul_assoc M S S, hMS, one_mul, hMS] + have hs (e : T × I) : s e * s e = Real.exp (a e) := by + dsimp [s] + rw [← Real.exp_add] + congr 1 + ring + have houter (e : T × I) : + vecMulVec (s e • (M *ᵥ fun i => b e.1 i e.2)) + (s e • (M *ᵥ fun i => b e.1 i e.2)) = + M * (Real.exp (a e) • vecMulVec (fun i => b e.1 i e.2) (fun i => b e.1 i e.2)) * M := by + simp only [Matrix.smul_vecMulVec, Matrix.vecMulVec_smul, smul_smul, hs, + Matrix.mul_smul, Matrix.smul_mul, Matrix.mul_vecMulVec, Matrix.vecMulVec_mul] + rw [← Matrix.vecMul_transpose M, hMT] + have hnorm (e : T × I) : + (s e • (M *ᵥ fun i => b e.1 i e.2)) ⬝ᵥ (s e • (M *ᵥ fun i => b e.1 i e.2)) = + Real.exp (a e) * ((fun i => b e.1 i e.2) ⬝ᵥ + ((packingCov b a)⁻¹ *ᵥ fun i => b e.1 i e.2)) := by + simp only [smul_dotProduct, dotProduct_smul, smul_eq_mul, ← mul_assoc, hs] + congr 1 + rw [← hMM, ← Matrix.mulVec_mulVec, Matrix.dotProduct_mulVec, + ← Matrix.mulVec_transpose M, hMT] + exact dotProduct_comm _ _ + refine ⟨M, s, hMU, fun e => Real.exp_pos _, ?_, ?_⟩ + · simp_rw [houter] + rw [← Finset.sum_mul, ← Finset.mul_sum, ← packingCov_eq_sum, hMNM] + · intro e + rw [hnorm] + exact ha e + +end Covariance + +end +end StrongThinTree + +namespace StrongThinTree.Packing +noncomputable section +open Matrix Finset +open scoped BigOperators MatrixOrder Matrix.Norms.Elementwise + +variable {E : Type uE2} [Fintype E] [DecidableEq E] {q d : ℕ} + +omit [Fintype E] in + + theorem represented_packing (v : E → (Fin d → ℝ)) (F : Fin q → Finset E) + (hq : 0 < q) (hF : ∀ t, LinearIndepOn ℝ v (F t : Set E)) + (hcard : ∀ t, (F t).card = d) (hd : Pairwise (fun i j => Disjoint (F i) (F j))) + {ρ : ℝ} (hρ : 0 < ρ) : + ∃ (M : Matrix (Fin d) (Fin d) ℝ) (s : E → ℝ), + IsUnit M ∧ (∀ e, 0 < s e) ∧ + let z := fun e => s e • (M *ᵥ v e) + (∑ e ∈ Finset.univ.biUnion F, vecMulVec (z e) (z e)) = 1 ∧ + (∀ e ∈ Finset.univ.biUnion F, z e ⬝ᵥ z e ≤ (1 + ρ) / q) := by + classical + let : Nonempty (Fin q) := Fin.pos_iff_nonempty.mp hq + let B := Finset.univ.biUnion F + let en (t : Fin q) : Fin d ≃ ↥(F t) := + Fintype.equivOfCardEq (by simp [hcard]) + let b (t : Fin q) : Matrix (Fin d) (Fin d) ℝ := fun i j => v (en t j) i + have hb : ∀ t, IsUnit (b t) := by + intro t + apply Matrix.mulVec_injective_iff_isUnit.mp + apply Matrix.mulVec_injective_iff.mpr + exact (hF t).linearIndependent.comp (en t) (en t).injective + let f : Fin q × Fin d → ↥B := fun tj => ⟨en tj.1 tj.2, + Finset.mem_biUnion.mpr ⟨tj.1, Finset.mem_univ _, (en tj.1 tj.2).2⟩⟩ + have hf : Function.Bijective f := by + constructor + · rintro ⟨t, j⟩ ⟨t', j'⟩ heq + have hev : (en t j : E) = (en t' j' : E) := congrArg Subtype.val heq + have ht : t = t' := by + by_contra h + exact Finset.disjoint_left.mp (hd h) (en t j).2 (hev ▸ (en t' j').2) + subst t' + have hj : j = j' := (en t).injective (Subtype.ext hev) + subst j'; rfl + · intro e + obtain ⟨t, ht, he⟩ := Finset.mem_biUnion.mp e.2 + refine ⟨(t, (en t).symm ⟨e, he⟩), ?_⟩ + apply Subtype.ext + simp [f] + let eb := Equiv.ofBijective f hf + obtain ⟨M, s₀, hM, hs₀, hz, hnorm⟩ := isotropic_representation b hb hρ + let s : E → ℝ := fun e => if he : e ∈ B then s₀ (eb.symm ⟨e, he⟩) else 1 + have hs : ∀ e, 0 < s e := by + intro e + dsimp [s] + split_ifs + · exact hs₀ _ + · exact zero_lt_one + have hs_eq (tj : Fin q × Fin d) : s (eb tj) = s₀ tj := by + simp [s, (eb tj).2] + refine ⟨M, s, hM, hs, ?_, ?_⟩ + · rw [← Finset.sum_coe_sort] + rw [← eb.sum_comp] + convert hz using 1 + apply Finset.sum_congr rfl + intro tj htj + change vecMulVec (s (eb tj) • (M *ᵥ v (eb tj))) + (s (eb tj) • (M *ᵥ v (eb tj))) = _ + rw [hs_eq] + rfl + · intro e he + have hh := hnorm (eb.symm ⟨e, he⟩) + have hv : v e = fun i => b (eb.symm ⟨e, he⟩).1 i (eb.symm ⟨e, he⟩).2 := by + have hh : (en (eb.symm ⟨e, he⟩).1 (eb.symm ⟨e, he⟩).2 : E) = e := + congrArg Subtype.val (eb.apply_symm_apply ⟨e, he⟩) + simp [b, hh] + have heB : e ∈ B := he + have hsE : s e = s₀ (eb.symm ⟨e, he⟩) := by simp only [s, dite_eq_left heB] + change (s e • (M *ᵥ v e)) ⬝ᵥ (s e • (M *ᵥ v e)) ≤ _ + rw [hsE, hv] + simpa only [Fintype.card_fin] using hh + +end +end StrongThinTree.Packing + +namespace StrongThinTree.MultiGraph +noncomputable section +open Matrix Finset +open scoped BigOperators +variable {n m : ℕ} (G : MultiGraph n m) + +def zeroSumSpace (n : ℕ) : Submodule ℝ (Fin n → ℝ) := + LinearMap.ker (∑ u : Fin n, LinearMap.proj u) + +lemma mem_zeroSumSpace (x : Fin n → ℝ) : x ∈ zeroSumSpace n ↔ ∑ u, x u = 0 := by + simp [zeroSumSpace, LinearMap.mem_ker, LinearMap.sum_apply] + +lemma incidence_zeroSum (e : Fin m) : G.incidence e ∈ zeroSumSpace n := by + rw [mem_zeroSumSpace] + simp [incidence, point, Pi.sub_apply, Finset.sum_sub_distrib, Pi.single_apply, + Finset.sum_ite_eq'] + +lemma edgeSpan_le_zeroSum (T : Finset (Fin m)) : G.edgeSpan T ≤ zeroSumSpace n := + (Packing.span_le_iff G.incidence).mpr (fun e _he => G.incidence_zeroSum e) + +lemma connected_span_zeroSum {T : Finset (Fin m)} (hn : 0 < n) (hT : G.Connected T) : + G.edgeSpan T = zeroSumSpace n := by + apply le_antisymm (G.edgeSpan_le_zeroSum T) + intro x hx + have hx0 := (mem_zeroSumSpace x).mp hx + let u₀ : Fin n := ⟨0, hn⟩ + have hs : ∑ u, x u • (point u - point u₀) ∈ G.edgeSpan T := by + apply Submodule.sum_mem + intro u hu + exact Submodule.smul_mem _ _ ((G.connected_iff_same T).mp hT u u₀) + have heq : ∑ u, x u • (point u - point u₀) = x := by + simp only [smul_sub, Finset.sum_sub_distrib, ← Finset.sum_smul, hx0, zero_smul, sub_zero] + ext u + simp [point, Pi.single_apply, Finset.sum_apply, mul_ite] + rwa [heq] at hs + +lemma zeroSum_finrank {T : Finset (Fin m)} (hn : 0 < n) (hT : G.Connected T) : + Module.finrank ℝ (zeroSumSpace n) = n - 1 := by + rw [← G.connected_span_zeroSum hn hT] + exact G.connected_rank hn hT + +theorem graph_isotropic_representation {q : ℕ} (hq : 0 < q) (hn : 2 ≤ n) + (F : Fin q → Finset (Fin m)) (hF : ∀ t, G.SpanningTree (F t)) + (hd : Pairwise (fun i j => Disjoint (F i) (F j))) {ρ : ℝ} (hρ : 0 < ρ) : + ∃ (L : zeroSumSpace n ≃ₗ[ℝ] (Fin (n - 1) → ℝ)) (s : Fin m → ℝ), + (∀ e, 0 < s e) ∧ + let z := fun e => s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩ + (∑ e ∈ Finset.univ.biUnion F, vecMulVec (z e) (z e)) = 1 ∧ + (∀ e ∈ Finset.univ.biUnion F, z e ⬝ᵥ z e ≤ (1 + ρ) / q) := by + classical + have hn' : 0 < n := by omega + let L₀ : zeroSumSpace n ≃ₗ[ℝ] (Fin (n - 1) → ℝ) := + LinearEquiv.ofFinrankEq _ _ (by + rw [G.zeroSum_finrank hn' (hF ⟨0, hq⟩).1] + simp) + let v := fun e => L₀ ⟨G.incidence e, G.incidence_zeroSum e⟩ + have hvi (t : Fin q) : LinearIndepOn ℝ v (F t : Set (Fin m)) := by + have hi := ((G.spanningTree_iff_independent (F t)).mp (hF t)).2.linearIndependent + have hi' : LinearIndependent ℝ + (fun e : ↥(F t) => (⟨G.incidence e, G.incidence_zeroSum e⟩ : zeroSumSpace n)) := + hi.of_comp (zeroSumSpace n).subtype + exact hi'.map' L₀.toLinearMap L₀.ker + obtain ⟨M, s, hM, hs, hi, hb⟩ := Packing.represented_packing v F hq hvi + (fun t => G.spanningTree_card hn' (hF t)) hd hρ + let L := L₀.trans (Matrix.toLinearEquiv' M hM.invertible) + exact ⟨L, s, hs, hi, hb⟩ + +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.Packing +noncomputable section +open scoped BigOperators +open Finset +variable {E : Type uE3} {V : Type uV} [Fintype E] [DecidableEq E] + [NormedAddCommGroup V] [InnerProductSpace ℝ V] [FiniteDimensional ℝ V] + +omit [Fintype E] in + +lemma projected_trace_bound (v : E → V) (A U : Finset E) {c h : ℝ} + (_hU : U ⊆ A) (hn : ∀ e ∈ A, ‖v e‖ ^ 2 ≤ h) + (hlow : ∀ x : V, c * ‖x‖ ^ 2 ≤ ∑ e ∈ A, (inner ℝ x (v e)) ^ 2) : + c * (Module.finrank ℝ V - Module.finrank ℝ (span v U) : ℕ) ≤ + h * (A \ U).card := by + classical + let W := span v U + let b := stdOrthonormalBasis ℝ Wᗮ + let w := fun i : Fin (Module.finrank ℝ Wᗮ) => (b i : V) + have hw : Orthonormal ℝ w := by + rw [orthonormal_iff_ite] + intro i j + exact (orthonormal_iff_ite.mp b.orthonormal) i j + have hzero (i : Fin (Module.finrank ℝ Wᗮ)) (e : E) (he : e ∈ U) : + inner ℝ (w i) (v e) = 0 := + Submodule.inner_left_of_mem_orthogonal (mem_span_self v he) (b i).2 + have hlow' (i : Fin (Module.finrank ℝ Wᗮ)) : + c ≤ ∑ e ∈ A \ U, (inner ℝ (w i) (v e)) ^ 2 := by + have hi := hlow (w i) + rw [hw.norm_eq_one, one_pow, mul_one] at hi + have heq : ∑ e ∈ A \ U, (inner ℝ (w i) (v e)) ^ 2 = + ∑ e ∈ A, (inner ℝ (w i) (v e)) ^ 2 := by + apply Finset.sum_subset Finset.sdiff_subset + intro e he hne + have heU : e ∈ U := by simpa [he] using hne + simp [hzero i e heU] + rwa [heq] + have hs := Finset.sum_le_sum (s := Finset.univ) (fun i hi => hlow' i) + have hsb : (∑ i : Fin (Module.finrank ℝ Wᗮ), ∑ e ∈ A \ U, + (inner ℝ (w i) (v e)) ^ 2) ≤ ∑ e ∈ A \ U, h := by + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro e he + have hb := hw.sum_inner_products_le (s := Finset.univ) (v e) + simp only [Real.norm_eq_abs, sq_abs] at hb + exact hb.trans (hn e (Finset.mem_sdiff.mp he).1) + have ht := hs.trans hsb + have hdim := W.finrank_add_finrank_orthogonal + have heq : Module.finrank ℝ Wᗮ = Module.finrank ℝ V - Module.finrank ℝ W := by omega + simpa [heq, mul_comm, W] using ht + +omit [Fintype E] in +lemma lower_frame_span (v : E → V) (A : Finset E) {c h : ℝ} (hc : 0 < c) + (hn : ∀ e ∈ A, ‖v e‖ ^ 2 ≤ h) + (hlow : ∀ x : V, c * ‖x‖ ^ 2 ≤ ∑ e ∈ A, (inner ℝ x (v e)) ^ 2) : + span v A = ⊤ := by + have hb := projected_trace_bound v A A (Subset.refl _) hn hlow + simp only [Finset.sdiff_self, Finset.card_empty, Nat.cast_zero, mul_zero] at hb + have hzero : (Module.finrank ℝ V - Module.finrank ℝ (span v A) : ℕ) = 0 := by + have hh : ((Module.finrank ℝ V - Module.finrank ℝ (span v A) : ℕ) : ℝ) ≤ 0 := + by nlinarith + exact_mod_cast (le_antisymm hh (Nat.cast_nonneg _)) + apply Submodule.eq_top_of_finrank_eq + have hle := (span v A).finrank_le + omega + +theorem projected_trace_base_packing (v : E → V) (A : Finset E) + {r : ℕ} {c h : ℝ} (hc : 0 < c) (hh : 0 < h) (hr : (r : ℝ) * h ≤ c) + (hn : ∀ e ∈ A, ‖v e‖ ^ 2 ≤ h) + (hlow : ∀ x : V, c * ‖x‖ ^ 2 ≤ ∑ e ∈ A, (inner ℝ x (v e)) ^ 2) : + ∃ F : Fin r → Finset E, Valid v F ∧ + ∀ i, F i ⊆ A ∧ span v (F i) = ⊤ := by + have htop := lower_frame_span v A hc hn hlow + have hp : ∀ U : Finset E, U ⊆ A → + Fintype.card (Fin r) * Module.finrank ℝ (span v A) ≤ + (A \ U).card + Fintype.card (Fin r) * Module.finrank ℝ (span v U) := by + intro U hU + have ht := projected_trace_bound v A U hU hn hlow + have hdim := (span v U).finrank_le + have hdiff : (r : ℝ) * (Module.finrank ℝ V - Module.finrank ℝ (span v U) : ℕ) ≤ + (A \ U).card := by + have h₁ := mul_le_mul_of_nonneg_right hr + (Nat.cast_nonneg (Module.finrank ℝ V - Module.finrank ℝ (span v U))) + have h₂ : h * ((r : ℝ) * (Module.finrank ℝ V - Module.finrank ℝ (span v U) : ℕ)) ≤ + h * (A \ U).card := by nlinarith [h₁.trans ht] + exact (mul_le_mul_iff_right₀ hh).mp h₂ + have hdiffN : r * (Module.finrank ℝ V - Module.finrank ℝ (span v U)) ≤ + (A \ U).card := by exact_mod_cast hdiff + rw [htop, finrank_top, Fintype.card_fin] + have heq : Module.finrank ℝ V = + (Module.finrank ℝ V - Module.finrank ℝ (span v U)) + Module.finrank ℝ (span v U) := by omega + rw [heq, Nat.mul_add] + exact Nat.add_le_add_right hdiffN _ + obtain ⟨F, hF, hs⟩ := vector_base_packing_on v A hp + exact ⟨F, hF, fun i => ⟨(hs i).1, (hs i).2.trans htop⟩⟩ + +end +end StrongThinTree.Packing + +namespace StrongThinTree.Packing +noncomputable section +variable {E : Type uE4} {V : Type uV2} {W : Type uW} [Fintype E] [DecidableEq E] + [AddCommGroup V] [Module ℝ V] [FiniteDimensional ℝ V] + [AddCommGroup W] [Module ℝ W] [FiniteDimensional ℝ W] + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] in +lemma span_smul (v : E → V) (s : E → ℝ) (hs : ∀ e, s e ≠ 0) (U : Finset E) : + span (fun e => s e • v e) U = span v U := by + apply le_antisymm + · apply (span_le_iff _).mpr + intro e he + exact Submodule.smul_mem _ _ (mem_span_self v he) + · apply (span_le_iff _).mpr + intro e he + have h := Submodule.smul_mem (span (fun e => s e • v e) U) (s e)⁻¹ + (mem_span_self (fun e => s e • v e) he) + simpa only [smul_smul, inv_mul_cancel₀ (hs e), one_smul] using h + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] [FiniteDimensional ℝ W] in +lemma span_map (v : E → V) (L : V →ₗ[ℝ] W) (U : Finset E) : + span (fun e => L (v e)) U = (span v U).map L := by + rw [span, Submodule.map_span, ← Set.image_image] + +omit [Fintype E] [DecidableEq E] [FiniteDimensional ℝ V] [FiniteDimensional ℝ W] in +lemma rank_injective_map (v : E → V) (L : V →ₗ[ℝ] W) + (hL : Function.Injective L) (U : Finset E) : + Module.finrank ℝ (span (fun e => L (v e)) U) = Module.finrank ℝ (span v U) := by + rw [span_map] + exact (Submodule.equivMapOfInjective L hL (span v U)).finrank_eq.symm + +end +end StrongThinTree.Packing + +namespace StrongThinTree.MultiGraph +noncomputable section +open Matrix StrongThinTree.Packing +variable {n m : ℕ} (G : StrongThinTree.MultiGraph n m) + +lemma represented_rank (L : zeroSumSpace n ≃ₗ[ℝ] (Fin (n-1) → ℝ)) + (s : Fin m → ℝ) (hs : ∀ e, s e ≠ 0) (U : Finset (Fin m)) : + Module.finrank ℝ (Packing.span + (fun e => s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩) U) = + Module.finrank ℝ (G.edgeSpan U) := by + rw [Packing.span_smul _ s hs] + change Module.finrank ℝ (Packing.span + (fun e => L.toLinearMap (⟨G.incidence e, G.incidence_zeroSum e⟩ : zeroSumSpace n)) U) = _ + rw [Packing.rank_injective_map _ L.toLinearMap L.injective] + symm + exact Packing.rank_injective_map + (fun e => (⟨G.incidence e, G.incidence_zeroSum e⟩ : zeroSumSpace n)) + (zeroSumSpace n).subtype Subtype.val_injective U + +theorem represented_frame_treePackable (hn : 2 ≤ n) + (L : zeroSumSpace n ≃ₗ[ℝ] (Fin (n-1) → ℝ)) + (s : Fin m → ℝ) (hs : ∀ e, 0 < s e) (A : Finset (Fin m)) + {r : ℕ} {c h : ℝ} (hc : 0 < c) (hh : 0 < h) (hr : (r : ℝ) * h ≤ c) + (hnorm : ∀ e ∈ A, let z := s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩ + z ⬝ᵥ z ≤ h) + (hlow : ∀ x : Fin (n-1) → ℝ, c * (x ⬝ᵥ x) ≤ + ∑ e ∈ A, (x ⬝ᵥ (s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩)) ^ 2) : + G.TreePackable A r := by + classical + let z := fun e => s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩ + let J := (WithLp.linearEquiv 2 ℝ (Fin (n-1) → ℝ)).symm + let v := fun e => J (z e) + have hnorm' : ∀ e ∈ A, ‖v e‖ ^ 2 ≤ h := by + intro e he + rw [EuclideanSpace.real_norm_sq_eq] + simpa [v, J, z, dotProduct, pow_two] using hnorm e he + have hlow' : ∀ x : EuclideanSpace ℝ (Fin (n-1)), + c * ‖x‖ ^ 2 ≤ ∑ e ∈ A, (inner ℝ x (v e)) ^ 2 := by + intro x + rw [EuclideanSpace.real_norm_sq_eq] + simpa [EuclideanSpace.inner_eq_star_dotProduct, + v, J, z, dotProduct, pow_two, mul_comm] using hlow x.ofLp + have hrank (U : Finset (Fin m)) : + Module.finrank ℝ (Packing.span v U) = Module.finrank ℝ (G.edgeSpan U) := by + change Module.finrank ℝ (Packing.span (fun e => J.toLinearMap (z e)) U) = _ + rw [Packing.rank_injective_map z J.toLinearMap J.injective] + exact G.represented_rank L s (fun e => ne_of_gt (hs e)) U + have htop := Packing.lower_frame_span v A hc hnorm' hlow' + have hfull : Module.finrank ℝ (G.edgeSpan A) = n-1 := by + rw [← hrank, htop, finrank_top] + simp + obtain ⟨F, hF, hFA⟩ := Packing.projected_trace_base_packing v A hc hh hr hnorm' hlow' + refine ⟨F, ?_, hF.2⟩ + intro i + refine ⟨(hFA i).1, (G.spanningTree_iff_independent (F i)).mpr ⟨?_, ?_⟩⟩ + · have hdim : Module.finrank ℝ (G.edgeSpan (F i)) = n-1 := by + rw [← hrank, (hFA i).2, finrank_top] + simp + apply G.connected_of_componentCount_eq_one + have hcomp := G.incidence_rank (F i) + have hpos := G.componentCount_pos (by omega) (F i) + omega + · apply linearIndependent_iff_card_eq_finrank_span.mpr + have heq : Set.range (fun e : (F i : Set (Fin m)) => G.incidence e) = + G.incidence '' (F i : Set (Fin m)) := by ext x; simp + change Fintype.card ↥(F i : Set (Fin m)) = Module.finrank ℝ (Submodule.span ℝ _) + rw [heq] + simpa [← hrank] using (Packing.indep_rank v (hF.1 i)).symm + +end +end StrongThinTree.MultiGraph + +namespace StrongThinTree.MultiGraph +noncomputable section +open Matrix +variable {n m : ℕ} (G : StrongThinTree.MultiGraph n m) + +theorem projected_trace_treePackable (hn : 2 ≤ n) {q : ℕ} (hq : 0 < q) + {ρ c : ℝ} (hρ : 0 < ρ) (hc : 0 < c) + (L : zeroSumSpace n ≃ₗ[ℝ] (Fin (n-1) → ℝ)) (s : Fin m → ℝ) + (hs : ∀ e, 0 < s e) (A B : Finset (Fin m)) (hAB : A ⊆ B) + (hnorm : ∀ e ∈ B, let z := s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩ + z ⬝ᵥ z ≤ (1 + ρ) / q) + (hlow : (∑ e ∈ A, + vecMulVec (s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩) + (s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩) - + c • (1 : Matrix (Fin (n-1)) (Fin (n-1)) ℝ)).PosSemidef) : + G.TreePackable A ⌊c * q / (1 + ρ)⌋₊ := by + have hq' : (0 : ℝ) < q := by exact_mod_cast hq + have hp : 0 < 1 + ρ := by linarith + apply G.represented_frame_treePackable hn L s hs A hc (div_pos hp hq') + · have hf := Nat.floor_le (le_of_lt (div_pos (mul_pos hc hq') hp)) + apply (le_div_iff₀ (div_pos hp hq')).symm.mpr + convert hf using 1 ; field_simp + · intro e he + exact hnorm e (hAB he) + · intro x + have ht := hlow.dotProduct_mulVec_nonneg x + simp only [star_trivial, Matrix.sub_mulVec, dotProduct_sub, Matrix.smul_mulVec, + Matrix.one_mulVec, dotProduct_smul, Matrix.sum_mulVec, dotProduct_sum] at ht + suffices heq : (∑ e ∈ A, + x ⬝ᵥ (vecMulVec (s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩) + (s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩) *ᵥ x)) = + ∑ e ∈ A, (x ⬝ᵥ (s e • L ⟨G.incidence e, G.incidence_zeroSum e⟩)) ^ 2 by + rw [heq] at ht + simp only [smul_eq_mul] at ht + linarith + apply Finset.sum_congr rfl + intro e he + rw [Matrix.vecMulVec_mulVec] + simp [dotProduct, Finset.mul_sum, pow_two, mul_comm, mul_left_comm] + +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/ResponseBounds.lean b/lean/OAI/Combinatorics/ThinTrees/ResponseBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..33238159753f9669e880f3404c78be52ea0972f7 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/ResponseBounds.lean @@ -0,0 +1,134 @@ +import OAI.Combinatorics.ThinTrees.DyadicSelection + +namespace OAI + +section + +namespace StrongThinTree.MultiGraph.PartitionChain +noncomputable section +open Finset +variable {n m : ℕ} (P : PartitionChain n) (G : MultiGraph n m) + +def nextIndex (I : Finset ℕ) (i z : ℕ) : ℕ := + if h : (I.filter (fun j => i < j)).Nonempty then (I.filter (fun j => i < j)).min' h else z + +lemma nextIndex_spec {I : Finset ℕ} {i z : ℕ} (hz : z ∈ I) (hiz : i < z) : + nextIndex I i z ∈ I ∧ i < nextIndex I i z ∧ ∀j ∈ I, i < j → nextIndex I i z ≤ j := by + classical + have h : (I.filter (fun j => i < j)).Nonempty := ⟨z,mem_filter.mpr ⟨hz,hiz⟩⟩ + rw [nextIndex,dite_eq_left h] + have hm := min'_mem _ h + exact ⟨(mem_filter.mp hm).1,(mem_filter.mp hm).2,fun j hj hij => min'_le _ _ (mem_filter.mpr ⟨hj,hij⟩)⟩ + +lemma transition_bad_bound {I : Finset ℕ} {H : Hierarchy n} (hH : H.nodes=P.nodes I) + {i j : ℕ} (hi : i ∈ I) (hj : j ∈ I) (hij : i < j) + (hnext : ∀k ∈ I, i < k → j ≤ k) (Bad : Finset (Fin m)) {c : ℝ} (hc : 0 ≤ c) + (hnode : ∀A ∈ H.nodes, ((Bad ∩ H.parentBoundary G A).card : ℝ) ≤ c*(G.cut univ A).card) : + ((Bad ∩ (P.crossing G i \ P.crossing G j)).card : ℝ) ≤ 2*c*(P.crossing G i).card := by + classical + have hs : Bad ∩ (P.crossing G i \ P.crossing G j) ⊆ + (P.parts i).biUnion (fun A => Bad ∩ H.parentBoundary G A) := by + intro e he + obtain ⟨hBad,hc⟩ := mem_inter.mp he + obtain ⟨A,hA,heA⟩ := P.disappearing_in_parentBoundary G hH hi hj hij hnext hc + exact mem_biUnion.mpr ⟨A,hA,mem_inter.mpr ⟨hBad,heA⟩⟩ + have hh := (card_le_card hs).trans (card_biUnion_le) + calc + ((Bad ∩ (P.crossing G i \ P.crossing G j)).card : ℝ) ≤ + ∑A ∈ P.parts i, ((Bad ∩ H.parentBoundary G A).card : ℝ) := by exact_mod_cast hh + _ ≤ ∑A ∈ P.parts i, c*(G.cut univ A).card := by + apply sum_le_sum + intro A hA + exact hnode A (hH ▸ P.mem_nodes.mpr (Or.inl ⟨i,hi,hA⟩)) + _ = c*(∑A ∈ P.parts i, (G.cut univ A).card : ℕ) := by rw [Nat.cast_sum,mul_sum] + _ ≤ c*(2*(P.crossing G i).card) := by + apply mul_le_mul_of_nonneg_left _ hc + exact_mod_cast P.boundary_sum_le G i + _ = _ := by ring + +lemma selected_lt_end {z i : ℕ} (hz : P.parts z={univ}) + (hi : i ∈ Dyadic.selected (fun j => (P.crossing G j).card) z) : i < z := by + obtain ⟨hiz,hip,_⟩ := Dyadic.selected_spec hi + have hzero : (P.crossing G z).card=0 := by rw [P.crossing_root G hz,card_empty] + apply lt_of_le_of_ne hiz + intro he + subst i + omega + +lemma selected_tail_bad_bound {z : ℕ} (hz : P.parts z={univ}) + {H : Hierarchy n} + (hH : H.nodes=P.nodes (insert z (Dyadic.selected (fun j => (P.crossing G j).card) z))) + (Bad : Finset (Fin m)) {c : ℝ} (hc : 0 ≤ c) + (hnode : ∀A ∈ H.nodes, ((Bad ∩ H.parentBoundary G A).card : ℝ) ≤ c*(G.cut univ A).card) + {i : ℕ} (hi : i ∈ Dyadic.selected (fun j => (P.crossing G j).card) z) : + ((Bad ∩ P.crossing G i).card : ℝ) ≤ 8*c*(P.crossing G i).card := by + classical + let J := Dyadic.selected (fun j => (P.crossing G j).card) z + let I := insert z J + let K := J.filter (fun j => i ≤ j) + let nx := fun j => nextIndex I j z + have hn (j : ℕ) (hj : j ∈ J) : nx j ∈ I ∧ j < nx j ∧ ∀k ∈ I, j < k → nx j ≤ k := + nextIndex_spec (mem_insert_self _ _) (P.selected_lt_end G hz hj) + have hcover : Bad ∩ P.crossing G i ⊆ K.biUnion (fun j => Bad ∩ (P.crossing G j \ P.crossing G (nx j))) := by + intro e he + obtain ⟨hBad,hei⟩ := mem_inter.mp he + let E := J.filter (fun j => i ≤ j ∧ e ∈ P.crossing G j) + have hei' : i ∈ E := mem_filter.mpr ⟨hi,le_rfl,hei⟩ + let j := E.max' ⟨i,hei'⟩ + have hjE : j ∈ E := max'_mem _ _ + obtain ⟨hjJ,hij,hej⟩ := mem_filter.mp hjE + have hen : e ∉ P.crossing G (nx j) := by + intro hen + rcases mem_insert.mp (hn j hjJ).1 with hroot | hJ + · rw [hroot,P.crossing_root G hz] at hen + exact notMem_empty e hen + · have hnx : nx j ∈ E := mem_filter.mpr ⟨hJ,hij.trans (hn j hjJ).2.1.le,hen⟩ + have hmax := le_max' E (nx j) hnx + have hlt := (hn j hjJ).2.1 + omega + exact mem_biUnion.mpr ⟨j,mem_filter.mpr ⟨hjJ,hij⟩,mem_inter.mpr ⟨hBad,mem_sdiff.mpr ⟨hej,hen⟩⟩⟩ + have hcount := (card_le_card hcover).trans (card_biUnion_le) + calc + ((Bad ∩ P.crossing G i).card : ℝ) ≤ ∑j ∈ K, ((Bad ∩ (P.crossing G j \ P.crossing G (nx j))).card : ℝ) := by + exact_mod_cast hcount + _ ≤ ∑j ∈ K, 2*c*(P.crossing G j).card := by + apply sum_le_sum + intro j hj + have hjJ := (mem_filter.mp hj).1 + exact P.transition_bad_bound G hH (mem_insert_of_mem hjJ) (hn j hjJ).1 + (hn j hjJ).2.1 (hn j hjJ).2.2 Bad hc hnode + _ = 2*c*(∑j ∈ K, ((P.crossing G j).card : ℝ)) := by rw [mul_sum] + _ ≤ 2*c*(4*(P.crossing G i).card) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Dyadic.tail_bound (fun _ _ hij => card_le_card (P.crossing_antitone G hij)) hi + _ = _ := by ring + +lemma simultaneous_bad_bound {z : ℕ} (hz : P.parts z={univ}) + {H : Hierarchy n} + (hH : H.nodes=P.nodes (insert z (Dyadic.selected (fun j => (P.crossing G j).card) z))) + (Bad : Finset (Fin m)) {c : ℝ} (hc : 0 ≤ c) + (hnode : ∀A ∈ H.nodes, ((Bad ∩ H.parentBoundary G A).card : ℝ) ≤ c*(G.cut univ A).card) + (i : ℕ) (hiz : i ≤ z) : + ((Bad ∩ P.crossing G i).card : ℝ) ≤ 16*c*(P.crossing G i).card := by + classical + by_cases hzero : (P.crossing G i).card=0 + · have hz' : P.crossing G i=∅ := card_eq_zero.mp hzero + simp [hz'] + have hip : 0 < (P.crossing G i).card := Nat.pos_of_ne_zero hzero + obtain ⟨j,hj,hji,hlog⟩ := Dyadic.representative (M := fun j => (P.crossing G j).card) hiz hip + have hratio := Dyadic.same_bin_ratio hip hlog + calc + ((Bad ∩ P.crossing G i).card : ℝ) ≤ ((Bad ∩ P.crossing G j).card : ℝ) := by + exact_mod_cast card_le_card (inter_subset_inter_left (P.crossing_antitone G hji)) + _ ≤ 8*c*(P.crossing G j).card := P.selected_tail_bad_bound G hz hH Bad hc hnode hj + _ ≤ 8*c*(2*(P.crossing G i).card) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact_mod_cast hratio.le + _ = _ := by ring + +end +end StrongThinTree.MultiGraph.PartitionChain + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/ResponseFixedPoint.lean b/lean/OAI/Combinatorics/ThinTrees/ResponseFixedPoint.lean new file mode 100644 index 0000000000000000000000000000000000000000..d4bc44c8fc1ae16eecb91e2641dae4fc664f71ae --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/ResponseFixedPoint.lean @@ -0,0 +1,61 @@ +import OAI.Combinatorics.ThinTrees.FixedPoint + +namespace OAI + +universe uE + +section + +noncomputable section +open Finset +namespace StrongThinTree + +theorem response_fixed_point {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] + {K : Set E} (hK : IsCompact K) (hne : K.Nonempty) (hc : Convex ℝ K) + (R : K → K) {ε : ℝ} (hε : 0 < ε) : + ∃X : K, ∃C : Finset K, ∃w : K → ℝ, + (∀c ∈ C, 0 ≤ w c) ∧ (∑c ∈ C, w c)=1 ∧ + (∑c ∈ C, w c • (R c).val)=X.val ∧ + (∀c ∈ C, 0 < w c → dist c X < ε) := by + classical + let : CompactSpace K := isCompact_iff_compactSpace.mp hK + obtain ⟨U,_,hUfin,hUcover⟩ := (isCompact_univ : IsCompact (Set.univ : Set K)).finite_cover_balls hε + let C := hUfin.toFinset + have hcover (x : K) : ∃c ∈ C, dist x c < ε := by + obtain ⟨c,hc⟩ := Set.mem_iUnion.mp (hUcover (Set.mem_univ x)) + obtain ⟨hcU,hxc⟩ := Set.mem_iUnion.mp hc + exact ⟨c,hUfin.mem_toFinset.mpr hcU,hxc⟩ + let bump (x c : K) : ℝ := max 0 (ε-dist x c) + let total (x : K) : ℝ := ∑c ∈ C, bump x c + have hbump (x c : K) : 0 ≤ bump x c := le_max_left _ _ + have ht (x : K) : 0 < total x := by + obtain ⟨c,hc,hxc⟩ := hcover x + exact sum_pos' (fun c _ => hbump x c) ⟨c,hc,lt_of_lt_of_le (sub_pos.mpr hxc) (le_max_right _ _)⟩ + let w (x c : K) : ℝ := bump x c/total x + have hw (x c : K) : 0 ≤ w x c := div_nonneg (hbump x c) (ht x).le + have hw1 (x : K) : (∑c ∈ C, w x c)=1 := by + dsimp [w] + rw [←sum_div] + exact div_self (ht x).ne' + have cb (c : K) : Continuous (fun x => bump x c) := + continuous_const.max (continuous_const.sub (continuous_id.dist continuous_const)) + have ct : Continuous total := continuous_finsetSum _ (fun c _ => cb c) + have cw (c : K) : Continuous (fun x => w x c) := (cb c).div ct (fun x => (ht x).ne') + let F (x : K) : K := ⟨∑c ∈ C, w x c • (R c).val, + hc.sum_mem (fun c _ => hw x c) (hw1 x) (fun c _ => (R c).property)⟩ + have cF : Continuous F := by + apply Continuous.subtype_mk + exact continuous_finsetSum _ (fun c _ => (cw c).smul continuous_const) + obtain ⟨X,hX⟩ := FixedPoint.compact_convex_fixed_point hK hne hc F cF + refine ⟨X,C,w X,fun c _ => hw X c,hw1 X,congrArg Subtype.val hX,?_⟩ + intro c _ hpos + have hp : 0 < bump X c := (div_pos_iff_of_pos_right (ht X)).mp hpos + have hh : dist X c < ε := sub_pos.mp ((lt_max_iff.mp hp).resolve_left (lt_irrefl 0)) + simpa only [dist_comm] using hh + +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Restriction.lean b/lean/OAI/Combinatorics/ThinTrees/Restriction.lean new file mode 100644 index 0000000000000000000000000000000000000000..9cbd04c6f2918e51a640c96bebafe281eff334aa --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Restriction.lean @@ -0,0 +1,93 @@ +import OAI.Combinatorics.ThinTrees.Sparsification + +namespace OAI + +section + +noncomputable section +open Finset +namespace StrongThinTree.MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) + +def edgeEmbedding (F : Finset (Fin m)) : Fin F.card ↪ Fin m := + F.equivFin.symm.toEmbedding.trans ⟨Subtype.val,Subtype.val_injective⟩ +def restrict (F : Finset (Fin m)) : MultiGraph n F.card where + left e := G.left (edgeEmbedding F e) + right e := G.right (edgeEmbedding F e) + loopless e := G.loopless (edgeEmbedding F e) +def liftEdges (F : Finset (Fin m)) (T : Finset (Fin F.card)) : Finset (Fin m) := + T.map (edgeEmbedding F) +def lowerEdges (F T : Finset (Fin m)) : Finset (Fin F.card) := + T.preimage (edgeEmbedding F) (edgeEmbedding F).injective.injOn + +lemma embedding_mem (F : Finset (Fin m)) (e : Fin F.card) : edgeEmbedding F e ∈ F := + (F.equivFin.symm e).property +lemma embedding_surj (F : Finset (Fin m)) {e : Fin m} (he : e ∈ F) : + ∃i : Fin F.card, edgeEmbedding F i=e := by + refine ⟨F.equivFin ⟨e,he⟩,?_⟩ + change (F.equivFin.symm (F.equivFin ⟨e,he⟩)).val=e + simp +lemma lift_univ (F : Finset (Fin m)) : liftEdges F univ=F := by + ext e + simp only [liftEdges,mem_map,mem_univ,true_and] + exact ⟨fun ⟨i,hi⟩ => hi ▸ embedding_mem F i, embedding_surj F⟩ +lemma lift_lower (F T : Finset (Fin m)) (hT : T ⊆ F) : liftEdges F (lowerEdges F T)=T := by + ext e + simp only [liftEdges,lowerEdges,mem_map,mem_preimage] + refine ⟨fun ⟨i,hi,hie⟩ => hie ▸ hi,fun he => ?_⟩ + obtain ⟨i,rfl⟩ := embedding_surj F (hT he) + exact ⟨i,he,rfl⟩ +lemma restrict_cut (F : Finset (Fin m)) (T : Finset (Fin F.card)) (S : Finset (Fin n)) : + liftEdges F ((G.restrict F).cut T S)=G.cut (liftEdges F T) S := by + ext e + simp only [liftEdges,cut,mem_map,mem_filter] + constructor + · rintro ⟨i,⟨hi,hc⟩,rfl⟩ + exact ⟨⟨i,hi,rfl⟩,hc⟩ + · rintro ⟨⟨i,hi,rfl⟩,hc⟩ + exact ⟨i,⟨hi,hc⟩,rfl⟩ +lemma restrict_cut_card (F : Finset (Fin m)) (T : Finset (Fin F.card)) (S : Finset (Fin n)) : + ((G.restrict F).cut T S).card=(G.cut (liftEdges F T) S).card := by + rw [←G.restrict_cut] + exact (card_map _).symm +lemma restrict_connected (F : Finset (Fin m)) (T : Finset (Fin F.card)) : + (G.restrict F).Connected T ↔ G.Connected (liftEdges F T) := by + unfold Connected + constructor <;> intro h S hS hS' + · rw [←G.restrict_cut] + exact map_nonempty.mpr (h S hS hS') + · apply (map_nonempty (f := edgeEmbedding F)).mp + change (liftEdges F ((G.restrict F).cut T S)).Nonempty + rw [G.restrict_cut] + exact h S hS hS' +lemma restrict_spanningTree (F : Finset (Fin m)) (T : Finset (Fin F.card)) : + (G.restrict F).SpanningTree T ↔ G.SpanningTree (liftEdges F T) := by + constructor + · rintro ⟨hc,hmin⟩ + refine ⟨(G.restrict_connected F T).mp hc,?_⟩ + intro e he hh + obtain ⟨i,hi,rfl⟩ := mem_map.mp he + apply hmin i hi + apply (G.restrict_connected F (T.erase i)).mpr + simpa only [liftEdges,map_erase] using hh + · rintro ⟨hc,hmin⟩ + refine ⟨(G.restrict_connected F T).mpr hc,?_⟩ + intro e he hh + apply hmin (edgeEmbedding F e) (mem_map.mpr ⟨e,he,rfl⟩) + have hh' := (G.restrict_connected F (T.erase e)).mp hh + simpa only [liftEdges,map_erase] using hh' +lemma restrict_packable (F : Finset (Fin m)) {r : ℕ} (h : G.TreePackable F r) : + (G.restrict F).TreePackable univ r := by + obtain ⟨T,hT,hd⟩ := h + refine ⟨fun i => lowerEdges F (T i),fun i => ⟨subset_univ _,?_⟩,?_⟩ + · apply (G.restrict_spanningTree F _).mpr + rw [lift_lower F (T i) (hT i).1] + exact (hT i).2 + · intro i j hij + exact disjoint_preimage (hd hij) +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/RootBound.lean b/lean/OAI/Combinatorics/ThinTrees/RootBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..b14e9a95691b81eec97e44a7d4092337ba35d0b2 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/RootBound.lean @@ -0,0 +1,193 @@ +import OAI.Combinatorics.ThinTrees.RankOne + +namespace OAI + +universe uI uD uR uS + +section + +noncomputable section +open Polynomial Finset Matrix +open scoped MatrixOrder ComplexOrder +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] + +def pencil [CommRing R] (A : I → Matrix D D R) : MvPolynomial I R := + Matrix.det (fun a b => ∑i, MvPolynomial.X i*MvPolynomial.C (A i a b)) + +omit [DecidableEq I] in +lemma pencil_eval [CommRing R] (A : I → Matrix D D R) (z : I → R) : + MvPolynomial.eval z (pencil A)=(∑i, z i • A i).det := by + let M : Matrix D D (MvPolynomial I R) := fun a b => ∑i, MvPolynomial.X i*MvPolynomial.C (A i a b) + change (MvPolynomial.eval z) M.det = _ + rw [(MvPolynomial.eval z).map_det M] + congr 1 + ext a b + change (MvPolynomial.eval z) (∑i, MvPolynomial.X i*MvPolynomial.C (A i a b)) = _ + simp [Matrix.sum_apply,Matrix.smul_apply] + +omit [DecidableEq I] in +lemma pencil_map {S : Type uS} [CommRing R] [CommRing S] (f : R →+* S) (A : I → Matrix D D R) : + (pencil A).map f=pencil (fun i => (A i).map f) := by + let M : Matrix D D (MvPolynomial I R) := fun a b => ∑i, MvPolynomial.X i*MvPolynomial.C (A i a b) + change (MvPolynomial.map f) M.det = _ + rw [(MvPolynomial.map f).map_det M] + unfold pencil + congr 1 + apply Matrix.ext + intro a b + change (MvPolynomial.map f) (∑i, MvPolynomial.X i*MvPolynomial.C (A i a b)) = _ + simp [Matrix.map_apply] + +lemma posSemidef_complex {A : Matrix D D ℝ} (hA : A.PosSemidef) : + (A.map (algebraMap ℝ ℂ)).PosSemidef := by + let S := CFC.sqrt A + have hS : S.IsHermitian := (CFC.sqrt_nonneg A).posSemidef.isHermitian + have he : Sᴴ*S=A := by rw [hS.eq]; exact CFC.sqrt_mul_sqrt_self A hA.nonneg + rw [←he] + have hm : (Sᴴ*S).map (algebraMap ℝ ℂ)=(S.map (algebraMap ℝ ℂ))ᴴ*S.map (algebraMap ℝ ℂ) := by + rw [Matrix.map_mul] + congr 1 + ext i j + simp + rw [hm] + exact Matrix.posSemidef_conjTranspose_mul_self _ + +omit [DecidableEq I] in +lemma real_pencil_stable (A : I → Matrix D D ℝ) (hA : ∀i, (A i).PosSemidef) + (hsum : ∑i, A i=1) : RealStable (pencil A) := by + unfold RealStable + rw [pencil_map] + apply determinantPencil_stable _ (fun i => posSemidef_complex (hA i)) + have he : ∑i, (A i).map (algebraMap ℝ ℂ)=(1 : Matrix D D ℂ) := by + ext a b + simp only [Matrix.sum_apply,Matrix.map_apply] + rw [←map_sum] + rw [←Matrix.sum_apply,hsum] + simp [Matrix.one_apply] + rw [he] + exact Matrix.PosDef.one + +omit [DecidableEq I] in +lemma pencil_above (A : I → Matrix D D ℝ) (hA : ∀i, (A i).PosSemidef) + (hsum : ∑i, A i=1) {t : ℝ} (ht : 0 < t) : Above (pencil A) (fun _ => t) := by + intro s hs + rw [pencil_eval] + have he : ∑i, ((fun _ : I => t)+s) i • A i=t • (1 : Matrix D D ℝ)+∑i,s i • A i := by + simp only [Pi.add_apply,add_smul,Finset.sum_add_distrib,←Finset.smul_sum,hsum] + rw [he] + exact ((Matrix.PosDef.one.smul ht).add_posSemidef + (Matrix.posSemidef_sum _ (fun i _ => (hA i).smul (hs i)))).det_pos + +omit [Fintype D] [DecidableEq D] in +lemma sum_update_smul [CommRing R] (A : I → Matrix D D R) (z : I → R) (j : I) (u : R) : + ∑i, (Function.update z j (z j+u)) i • A i=(∑i, z i • A i)+u • A j := by + classical + have he : Function.update z j (z j+u)=z+Pi.single j u := by + ext i + by_cases hi : i=j + · subst i; simp + · simp [Function.update_of_ne hi,Pi.single_eq_of_ne hi] + rw [he] + simp only [Pi.add_apply,add_smul,Finset.sum_add_distrib] + congr 1 + rw [Finset.sum_eq_single j] + · simp + · intro i _ hi; simp [Pi.single_eq_of_ne hi] + · simp + +lemma ray_pencil_constant (A : I → Matrix D D ℝ) (hsum : ∑i, A i=1) (j : I) (t : ℝ) : + ray (pencil A) (fun _ => t) j=((C t : ℝ[X]) • (1 : Matrix D D ℝ[X])+(X : ℝ[X]) • (A j).map C).det := by + apply Polynomial.funext + intro u + rw [ray_eval,pencil_eval,sum_update_smul,←Finset.smul_sum,hsum] + rw [show Polynomial.eval u = Polynomial.evalRingHom u from rfl, (Polynomial.evalRingHom u).map_det] + congr 1 + ext a b + simp [Matrix.add_apply,Matrix.smul_apply,smul_eq_mul,Matrix.one_apply,apply_ite] + ring + +lemma ray_pencil_factor (A : I → Matrix D D ℝ) (hsum : ∑i, A i=1) (j : I) {t : ℝ} (ht : t ≠ 0) : + ray (pencil A) (fun _ => t) j=C (t^(Fintype.card D)) * (1+(X : ℝ[X]) • ((t⁻¹) • A j).map C).det := by + rw [ray_pencil_constant A hsum] + have he : (C t : ℝ[X]) • (1 : Matrix D D ℝ[X])+(X : ℝ[X]) • (A j).map C= + (C t : ℝ[X]) • (1+(X : ℝ[X]) • ((t⁻¹) • A j).map C) := by + ext a b + simp only [Matrix.add_apply,Matrix.smul_apply,Matrix.map_apply,smul_eq_mul,map_mul] + rw [mul_add] + congr 1 + rw [←mul_assoc,←mul_assoc,mul_comm (C t) X,mul_assoc X,←map_mul,mul_inv_cancel₀ ht,map_one,mul_one] + rw [he,Matrix.det_smul,map_pow] + +lemma pencil_barrier (A : I → Matrix D D ℝ) (hsum : ∑i, A i=1) (j : I) {t : ℝ} (ht : t ≠ 0) : + barrier (pencil A) (fun _ => t) j=(A j).trace/t := by + have hnum : MvPolynomial.eval (fun _ => t) (MvPolynomial.pderiv j (pencil A))= + t^(Fintype.card D)*((t⁻¹) • A j).trace := by + rw [←ray_zero,←ray_derivative,ray_pencil_factor A hsum j ht,Polynomial.derivative_mul] + simp only [Polynomial.derivative_C,zero_mul,zero_add,Polynomial.eval_mul,Polynomial.eval_C, + Matrix.derivative_det_one_add_X_smul] + have hden : MvPolynomial.eval (fun _ => t) (pencil A)=t^(Fintype.card D) := by + rw [pencil_eval,←Finset.smul_sum,hsum,Matrix.det_smul,Matrix.det_one,mul_one] + rw [barrier,hnum,hden,Matrix.trace_smul] + simp only [smul_eq_mul] + field_simp + +def realDifferentialProduct (dirs : List I) (p : MvPolynomial I ℝ) : MvPolynomial I ℝ := + dirs.foldl (fun q j => q-MvPolynomial.pderiv j q) p + +def shiftVector (dirs : List I) (δ : ℝ) : I → ℝ := + (dirs.map (fun j => Pi.single j δ)).sum + +omit [Fintype I] in +lemma shiftVector_cons (j : I) (dirs : List I) (δ : ℝ) : + shiftVector (j::dirs) δ=Pi.single j δ+shiftVector dirs δ := by + simp [shiftVector] + +lemma many_barrier_shifts {p : MvPolynomial I ℝ} (hp : RealStable p) {z : I → ℝ} + (hz : Above p z) {δ φ : ℝ} (hδ : 0 < δ) (hφ : φ+1/δ ≤ 1) + (hb : ∀i, barrier p z i ≤ φ) (dirs : List I) : + Above (realDifferentialProduct dirs p) (z+shiftVector dirs δ) ∧ + ∀i, barrier (realDifferentialProduct dirs p) (z+shiftVector dirs δ) i ≤ φ := by + induction dirs generalizing p z with + | nil => simpa [realDifferentialProduct,shiftVector] using And.intro hz hb + | cons j dirs ih => + obtain ⟨hw,hb'⟩ := barrier_shift hp hz j hδ (by linarith [hb j]) + have hh := ih (hp.sub_pderiv j) hw (fun i => (hb' i).trans (hb i)) + simpa only [realDifferentialProduct,List.foldl_cons,shiftVector_cons,update_add_single,add_assoc] using hh + +lemma shiftVector_univ (δ : ℝ) : shiftVector (Finset.univ.toList : List I) δ=fun _ => δ := by + ext i + simp [shiftVector,Finset.sum_apply,Pi.single_apply] + +lemma skew_root_bound (A : I → Matrix D D ℝ) (hA : ∀i, (A i).PosSemidef) + (hsum : ∑i, A i=1) {ε : ℝ} (hε : 0 < ε) (htr : ∀i, (A i).trace ≤ ε) : + Above (realDifferentialProduct Finset.univ.toList (pencil A)) (fun _ => (1+Real.sqrt ε)^2) := by + let t := ε+Real.sqrt ε + let δ := 1+Real.sqrt ε + have ht : 0 < t := add_pos_of_pos_of_nonneg hε (Real.sqrt_nonneg _) + have hδ : 0 < δ := add_pos_of_pos_of_nonneg zero_lt_one (Real.sqrt_nonneg _) + have hid : ε/t+1/δ=1 := by + have hsq := Real.sq_sqrt hε.le + dsimp [t,δ] at * + field_simp + nlinarith + have hb : ∀i, barrier (pencil A) (fun _ => t) i ≤ ε/t := by + intro i + rw [pencil_barrier A hsum i ht.ne'] + exact div_le_div_of_nonneg_right (htr i) ht.le + have hh := (many_barrier_shifts (real_pencil_stable A hA hsum) (pencil_above A hA hsum ht) + hδ hid.le hb (Finset.univ.toList : List I)).1 + rw [shiftVector_univ] at hh + have he : (fun _ : I => t)+(fun _ => δ)=fun _ => (1+Real.sqrt ε)^2 := by + ext i + simp only [Pi.add_apply] + dsimp [t,δ] + nlinarith [Real.sq_sqrt hε.le] + rwa [he] at hh + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Selection.lean b/lean/OAI/Combinatorics/ThinTrees/Selection.lean new file mode 100644 index 0000000000000000000000000000000000000000..663b5710c1a542568cafdc0cc1ed570a1566755b --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Selection.lean @@ -0,0 +1,313 @@ +import OAI.Combinatorics.ThinTrees.Partitions + +namespace OAI + +universe uV uU uI + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.Geometry +noncomputable section +open Finset +variable {h : ℕ} + +def antipode (x : Fin h → ℝ) : Fin h → ℝ := fun j => 1-x j + +lemma binary_antipode {x : Fin h → ℝ} (hx : binary x) : binary (antipode x) := by + intro j + rcases hx j with hh | hh <;> simp [antipode,hh] + +lemma radial_complement {x z : Fin h → ℝ} (hx : binary x) (hz : cube z) : + l1dist z x+l1dist z (antipode x) = h := by + rw [l1dist,l1dist,← sum_add_distrib] + calc + _ = ∑j : Fin h, (1:ℝ) := by + apply sum_congr rfl + intro j hj + rcases hx j with hh | hh + · simp only [hh,antipode,sub_zero,abs_of_nonneg (hz j).1, + abs_of_nonpos (by linarith [(hz j).2] : z j-1 ≤ 0)] + ring + · simp only [hh,antipode,sub_self,sub_zero,abs_of_nonneg (hz j).1, + abs_of_nonpos (by linarith [(hz j).2] : z j-1 ≤ 0)] + ring + _ = h := by simp + +lemma radial_max {x z : Fin h → ℝ} (hx : binary x) (hz : cube z) : + l1dist z x ≤ h := by + have hh := radial_complement hx hz + linarith [l1dist_nonneg z (antipode x)] + +lemma binary_radial_move {x z : Fin h → ℝ} (hx : binary x) (hz : binary z) + {r : ℝ} (hr : 0 ≤ r) (hrmax : r ≤ h) : + ∃w : Fin h → ℝ, cube w ∧ l1dist w x = r ∧ l1dist w z = |r-l1dist z x| := by + let R := l1dist z x + by_cases heq : r = R + · exact ⟨z,binary_cube hz,heq.symm,by rw [heq]; simp [R,l1dist_self]⟩ + rcases lt_or_gt_of_ne heq with hlo | hhi + · have hR : 0 < R := lt_of_le_of_lt hr hlo + let t := (R-r)/R + have ht : t ∈ Set.Icc (0:ℝ) 1 := + ⟨div_nonneg (by linarith) hR.le,(div_le_one hR).mpr (by linarith)⟩ + have hmul : t*R = R-r := div_mul_cancel₀ _ hR.ne' + let w := fun j => z j+t*(x j-z j) + refine ⟨w,cube_segment (binary_cube hz) (binary_cube hx) ht,?_,?_⟩ + · have hh := binary_radial_affine (binary_cube hz) (binary_cube hx) hx ht + rw [l1dist_self] at hh + dsimp [w] + rw [hh] + dsimp [R] at hmul + nlinarith + · have hh := binary_radial_affine (binary_cube hz) (binary_cube hx) hz ht + rw [l1dist_self,l1dist_comm x z] at hh + dsimp [w] + rw [hh,abs_of_neg (by linarith : r-l1dist z x < 0)] + dsimp [R] at hmul + nlinarith + · let y := antipode x + have hy := binary_antipode hx + have hcomp : R+l1dist y z = h := by + simpa only [R,l1dist_comm y z] using radial_complement hx (binary_cube hz) + have hyx : l1dist y x = h := by + have hh := radial_complement hx (binary_cube hy) + simpa only [y,l1dist_self,add_zero] using hh + let D := l1dist y z + have hD : 0 < D := by dsimp [D]; linarith + let t := (r-R)/D + have ht : t ∈ Set.Icc (0:ℝ) 1 := + ⟨div_nonneg (by linarith) hD.le,(div_le_one hD).mpr (by dsimp [D]; linarith)⟩ + have hmul : t*D = r-R := div_mul_cancel₀ _ hD.ne' + let w := fun j => z j+t*(y j-z j) + refine ⟨w,cube_segment (binary_cube hz) (binary_cube hy) ht,?_,?_⟩ + · have hh := binary_radial_affine (binary_cube hz) (binary_cube hy) hx ht + rw [hyx] at hh + dsimp [w] + rw [hh] + dsimp [R,D] at hmul hcomp + nlinarith + · have hh := binary_radial_affine (binary_cube hz) (binary_cube hy) hz ht + rw [l1dist_self] at hh + dsimp [w] + rw [hh,abs_of_pos (by exact sub_pos.mpr hhi)] + dsimp [R,D] at hmul + nlinarith + +namespace RadialShell +variable {V : Type uV} {X : V → Fin h → ℝ} + +lemma ball_meets_radial {B : RadialShell V} (hX : ∀v, binary (X v)) + (hB : B.Valid X) (z : V) {δ : ℝ} (hδ : 0 < δ) + (hlo : B.inner-δ < l1dist (X z) (X B.center)) + (hhi : l1dist (X z) (X B.center) < B.outer+δ) : + ¬Disjoint ((ball z δ).support X) (B.support X) := by + have hinterval : max B.inner (l1dist (X z) (X B.center)-δ) < + min B.outer (l1dist (X z) (X B.center)+δ) := by + rw [max_lt_iff,lt_min_iff,lt_min_iff] + exact ⟨⟨hB.2.1,by linarith⟩,⟨by linarith,by linarith⟩⟩ + obtain ⟨r,hl,hr⟩ := exists_between hinterval + have hlo' : B.inner < r := (le_max_left _ _).trans_lt hl + have hhi' : r < B.outer := hr.trans_le (min_le_left _ _) + have hradlo : l1dist (X z) (X B.center)-δ < r := (le_max_right _ _).trans_lt hl + have hradhi : r < l1dist (X z) (X B.center)+δ := hr.trans_le (min_le_right _ _) + obtain ⟨v,hv⟩ := hB.2.2.2.2 + have hmax : B.outer ≤ h := hv.trans (radial_max (hX _) (binary_cube (hX v))) + obtain ⟨w,hw,hwr,hwz⟩ := binary_radial_move (hX B.center) (hX z) + (hB.1.trans hlo'.le) (hhi'.le.trans hmax) + have hwA : w ∈ (ball z δ).support X := by + rw [support_ball] + refine ⟨hw,?_⟩ + rw [hwz,abs_lt] + constructor <;> linarith + have hwB : w ∈ B.support X := ⟨hw,hwr ▸ hhi',Or.inr (hwr ▸ hlo')⟩ + exact fun hdis => Set.disjoint_left.mp hdis hwA hwB + +end RadialShell +end +end StrongThinTree.Geometry + +namespace StrongThinTree.AssignedAccounting +noncomputable section + +def base (avoiding : Bool) (R δ : ℝ) : ℝ := + max (R-3*δ) 0 / (if avoiding then 10 else 1) + +def fresh (δ ε : ℝ) : ℝ := δ-3*ε + +def theta : ℝ := 1/512 + +lemma base_le_width (a : Bool) {R δ : ℝ} (hR : 0 ≤ R) (hδ : 0 ≤ δ) : + base a R δ ≤ R := by + have hh : max (R-3*δ) 0 ≤ R := max_le (by linarith) hR + cases a <;> simp only [base,Bool.false_eq_true,↓reduceIte,div_one] <;> linarith + +lemma base_discard (a : Bool) {R δ : ℝ} (hR : R ≤ 0) (hδ : 0 ≤ δ) : + base a R δ = 0 := by + have : max (R-3*δ) 0 = 0 := max_eq_right (by linarith) + simp [base,this] + +lemma fresh_lower {δ ε : ℝ} (hδ : 0 ≤ δ) (hε : ε ≤ δ/1536) : + (5/6:ℝ)*δ ≤ fresh δ ε := by dsimp [fresh]; linarith + +lemma avoiding_carve {δ ε R R₁ R₂ : ℝ} (hδ : 0 ≤ δ) (hε : ε ≤ δ/1536) + (hR : 512*δ ≤ R) (hsum : R₁+R₂ = R-2*δ) : + base true R δ + theta*δ ≤ base true R₁ δ+base true R₂ δ+fresh δ ε := by + have h1 := le_max_left (R₁-3*δ) 0 + have h2 := le_max_left (R₂-3*δ) 0 + have hf := fresh_lower hδ hε + have hr : max (R-3*δ) 0 = R-3*δ := max_eq_left (by linarith) + simp only [base,↓reduceIte,hr,theta] + linarith + +lemma dense_carve {δ ε R R₁ R₂ L M : ℝ} + (hδ : 0 ≤ δ) (hε : ε ≤ δ/1536) (hM : 0 ≤ M) + (hR : 512*δ ≤ R) (hsum : R₁+R₂ = R-L-4*δ) + (hdense : 3*L ≤ M*δ) (hcount : 765*δ ≤ M*δ) : + base false R δ+theta*M*δ ≤ + base false R₁ δ+base false R₂ δ+M*fresh δ ε := by + have h1 := le_max_left (R₁-3*δ) 0 + have h2 := le_max_left (R₂-3*δ) 0 + have hf := mul_le_mul_of_nonneg_left (fresh_lower hδ hε) hM + have hr : max (R-3*δ) 0 = R-3*δ := max_eq_left (by linarith) + simp only [base,Bool.false_eq_true,↓reduceIte,div_one,hr,theta] + nlinarith + +lemma sparse_carve {δ R R₁ R₂ L M : ℝ} + (hδ : 0 ≤ δ) (hR : 512*δ ≤ R) (hsum : R₁+R₂ = R-L) + (hwidth : 255*δ ≤ L) (hsparse : M*δ ≤ 3*L) : + base false R δ+theta*M*δ ≤ + base false R₁ δ+base false R₂ δ+base false (L-2*δ) δ+base true L δ := by + have h1 := le_max_left (R₁-3*δ) 0 + have h2 := le_max_left (R₂-3*δ) 0 + have h3 := le_max_left (L-2*δ-3*δ) 0 + have h4 := le_max_left (L-3*δ) 0 + have hr : max (R-3*δ) 0 = R-3*δ := max_eq_left (by linarith) + simp only [base,Bool.false_eq_true,↓reduceIte,div_one,hr,theta] + linarith + +lemma shrink_cost (a : Bool) {R δ ε : ℝ} (hδ : 0 ≤ δ) + (hε : 0 ≤ ε) (hscale : ε ≤ δ/1536) : + 0 ≤ base a R δ-base a (R-514*δ) ε ∧ + base a R δ-base a (R-514*δ) ε ≤ + 256*(base a R ε-base a R δ) := by + have hthreshold : R-514*δ-3*ε ≤ R-3*δ := by linarith + have hmono := max_le_max_right (0:ℝ) hthreshold + have hr : max (R-3*δ) 0-max (R-514*δ-3*ε) 0 ≤ + 256*(max (R-3*ε) 0-max (R-3*δ) 0) := by + by_cases hh : R ≤ 3*δ + · rw [max_eq_right (by linarith : R-3*δ ≤ 0)] + have h0 := le_max_right (R-514*δ-3*ε) 0 + have h1 := le_max_right (R-3*ε) 0 + linarith + · have hd : 3*δ ≤ R := (not_le.mp hh).le + rw [max_eq_left (by linarith : 0 ≤ R-3*δ), + max_eq_left (by linarith : 0 ≤ R-3*ε)] + have hlo := le_max_left (R-514*δ-3*ε) 0 + linarith + cases a <;> simp only [base,Bool.false_eq_true,↓reduceIte,div_one] <;> + constructor <;> linarith + +lemma border_payment {δ ε B D : ℝ} + (hδ : 0 ≤ δ) (hε : ε ≤ δ/1536) (hB : 0 ≤ B) + (hD : D ≤ B*δ/2) : theta*B*δ+D ≤ B*fresh δ ε := by + have hh := mul_le_mul_of_nonneg_left (fresh_lower hδ hε) hB + have hnon : 0 ≤ B*δ := mul_nonneg hB hδ + dsimp [theta] + nlinarith + +end +end StrongThinTree.AssignedAccounting + +namespace StrongThinTree.AssignedSelection +noncomputable section +open Finset + +lemma large_neighbor_class {U : Type uU} {I : Type uI} [DecidableEq U] [DecidableEq I] + (A : Finset U) (P : Finset I) (R : U → I → Prop) [DecidableRel R] + (hP : P.Nonempty) (hcover : ∀u ∈ A, ∃i ∈ P, R u i) + {q O : ℝ} (hq : 0 < q) (hO : 0 < O) + (hparts : q*(P.card : ℝ) ≤ 2*O) (hmany : 1536*O ≤ q*(A.card : ℝ)) : + ∃i ∈ P, 768 ≤ (A.filter (fun u => R u i)).card := by + obtain ⟨i,hi,hmax⟩ := P.exists_max_image (fun i => (A.filter (fun u => R u i)).card) hP + have hcover' : A = P.biUnion (fun i => A.filter (fun u => R u i)) := by + ext u + simp only [mem_biUnion,mem_filter] + constructor + · intro hu + obtain ⟨j,hj,hr⟩ := hcover u hu + exact ⟨j,hj,hu,hr⟩ + · rintro ⟨j,hj,hu,hr⟩ + exact hu + have hc : A.card ≤ P.card*(A.filter (fun u => R u i)).card := by + calc + A.card = (P.biUnion (fun i => A.filter (fun u => R u i))).card := congrArg card hcover' + _ ≤ ∑j ∈ P, (A.filter (fun u => R u j)).card := card_biUnion_le + _ ≤ ∑j ∈ P, (A.filter (fun u => R u i)).card := sum_le_sum (fun j hj => hmax j hj) + _ = _ := by simp + have hc' : (A.card : ℝ) ≤ (P.card : ℝ)*(A.filter (fun u => R u i)).card := by exact_mod_cast hc + have hm := mul_le_mul_of_nonneg_left hc' hq.le + have hp := mul_le_mul_of_nonneg_right hparts + (Nat.cast_nonneg (A.filter (fun u => R u i)).card : (0:ℝ) ≤ _) + have hn : (768:ℝ) ≤ (A.filter (fun u => R u i)).card := by nlinarith + exact ⟨i,hi,by exact_mod_cast hn⟩ + +lemma radial_range {r₁ r₂ p q s₀ u₀ s u δ : ℝ} + (hδ : 0 < δ) (hp0 : p ≤ s₀) (hq0 : s₀ ≤ q) + (hu₀lo : r₁+256*δ < u₀) (hu₀hi : u₀ < r₂-256*δ) + (hnear0 : |u₀-s₀| < δ) (hp : p ≤ s) (hq : s ≤ q) + (hnear : |u-s| < δ) + (hout : ¬(max r₁ p-δ < u ∧ u < min r₂ q+δ)) : + 255*δ ≤ min r₂ q-max r₁ p := by + obtain ⟨hn0a,hn0b⟩ := abs_lt.mp hnear0 + obtain ⟨hna,hnb⟩ := abs_lt.mp hnear + have hslo : r₁+255*δ < s₀ := by linarith + have hshi : s₀ < r₂-255*δ := by linarith + have ha : max r₁ p ≤ s₀ := max_le (by linarith) hp0 + have hb : s₀ ≤ min r₂ q := le_min (by linarith) hq0 + by_cases hul : max r₁ p-δ < u + · have huh : min r₂ q+δ ≤ u := le_of_not_gt (fun hh => hout ⟨hul,hh⟩) + have hclip : r₂ ≤ q := by + by_contra hh + rw [min_eq_right (not_le.mp hh).le] at huh + linarith + rw [min_eq_left hclip] + linarith + · have hul : u ≤ max r₁ p-δ := not_lt.mp hul + have hclip : p ≤ r₁ := by + by_contra hh + rw [max_eq_right (not_le.mp hh).le] at hul + linarith + rw [max_eq_left hclip] + linarith + +lemma interior_neighbor_in_range {r₁ r₂ p q s u δ : ℝ} + (hδ : 0 < δ) (hp : p ≤ s) (hq : s ≤ q) + (hulo : r₁+256*δ < u) (huhi : u < r₂-256*δ) + (hnear : |u-s| < δ) : + max r₁ p ≤ min r₂ q ∧ max r₁ p-δ < u ∧ u < min r₂ q+δ := by + obtain ⟨hna,hnb⟩ := abs_lt.mp hnear + have ha : max r₁ p ≤ s := max_le (by linarith) hp + have hb : s ≤ min r₂ q := le_min (by linarith) hq + exact ⟨ha.trans hb,by linarith,by linarith⟩ + +lemma dense_count {δ L M N : ℝ} (hδ : 0 ≤ δ) (hN : 768 ≤ N) + (hdich : N ≤ M ∨ 255*δ ≤ L) (hdense : 3*L ≤ M*δ) : 765*δ ≤ M*δ := by + rcases hdich with hh | hh + · have := mul_le_mul_of_nonneg_right hh hδ + nlinarith + · linarith + +lemma sparse_width {δ L M N : ℝ} (hδ : 0 ≤ δ) (hN : 768 ≤ N) + (hdich : N ≤ M ∨ 255*δ ≤ L) (hsparse : M*δ ≤ 3*L) : 255*δ ≤ L := by + rcases hdich with hh | hh + · have := mul_le_mul_of_nonneg_right hh hδ + nlinarith + · exact hh + +end +end StrongThinTree.AssignedSelection + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Shells.lean b/lean/OAI/Combinatorics/ThinTrees/Shells.lean new file mode 100644 index 0000000000000000000000000000000000000000..558574e0c07c69bef03f78e9c79a98e2ea651f15 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Shells.lean @@ -0,0 +1,682 @@ +import OAI.Combinatorics.ThinTrees.Coarea + +namespace OAI + +universe uV uV2 uV3 uV4 uV5 uV6 + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.Geometry +noncomputable section +open Finset + +lemma l1dist_self {h : ℕ} (x : Fin h → ℝ) : l1dist x x = 0 := by simp [l1dist] + +lemma l1dist_triangle {h : ℕ} (x y z : Fin h → ℝ) : + l1dist x z ≤ l1dist x y+l1dist y z := by + rw [l1dist, l1dist, l1dist, ← sum_add_distrib] + exact sum_le_sum (fun j _ => abs_sub_le (x j) (y j) (z j)) + +structure RadialShell (V : Type uV) where + center : V + inner : ℝ + outer : ℝ + ordinary : Bool + deriving DecidableEq + +namespace RadialShell +variable {V : Type uV2} {h : ℕ} + +def ball (v : V) (r : ℝ) : RadialShell V := ⟨v,0,r,true⟩ +def hollow (v : V) (a b : ℝ) : RadialShell V := ⟨v,a,b,false⟩ +def width (H : RadialShell V) : ℝ := H.outer-H.inner + +def support (X : V → Fin h → ℝ) (H : RadialShell V) : Set (Fin h → ℝ) := + {w | cube w ∧ l1dist w (X H.center) linarith [hH.2.1] + have hR : 0 < R := lt_of_lt_of_le (lt_of_le_of_lt hH.1 hH.2.1) hv + let t := q/R + have ht : t ∈ Set.Icc (0:ℝ) 1 := + ⟨div_nonneg (le_trans hH.1 hq.1.le) hR.le, + (div_le_one hR).mpr (le_trans hq.2.le hv)⟩ + let w := fun j => X H.center j+t*(X v j-X H.center j) + have hw : l1dist w (X H.center) = q := by + rw [binary_radial_affine (binary_cube (hX _)) (binary_cube (hX _)) (hX _) ht, + l1dist_self, sub_zero, zero_add] + exact div_mul_cancel₀ _ hR.ne' + exact ⟨w,cube_segment (binary_cube (hX _)) (binary_cube (hX _)) ht, + hw ▸ hq.2,Or.inr (hw ▸ hq.1)⟩ + +lemma restriction_valid {X : V → Fin h → ℝ} {H : RadialShell V} + (hH : H.Valid X) {a b : ℝ} (ha : H.inner ≤ a) (hb : b ≤ H.outer) (hab : a < b) : + (hollow H.center a b).Valid X := by + refine ⟨hH.1.trans ha,hab,by simp [hollow],?_,?_⟩ + · obtain ⟨u,hu⟩ := hH.2.2.2.1 + exact ⟨u,hu.trans ha⟩ + · obtain ⟨v,hv⟩ := hH.2.2.2.2 + exact ⟨v,hb.trans hv⟩ + +lemma restriction_subset (X : V → Fin h → ℝ) (H : RadialShell V) + {a b : ℝ} (ha : H.inner ≤ a) (hb : b ≤ H.outer) : + (hollow H.center a b).support X ⊆ H.support X := by + intro w hw + rw [support_hollow] at hw + exact ⟨hw.1,lt_of_lt_of_le hw.2.2 hb,Or.inr (lt_of_le_of_lt ha hw.2.1)⟩ + +lemma ball_subset_of_radial_margin (X : V → Fin h → ℝ) (H : RadialShell V) + (z : V) {δ : ℝ} (hlo : H.inner+δ ≤ l1dist (X z) (X H.center)) + (hhi : l1dist (X z) (X H.center) ≤ H.outer-δ) : + (ball z δ).support X ⊆ H.support X := by + intro w hw + rw [support_ball] at hw + have htri := l1dist_triangle w (X z) (X H.center) + have htri' := l1dist_triangle (X z) w (X H.center) + rw [l1dist_comm (X z) w] at htri' + exact ⟨hw.1,by linarith [hw.2],Or.inr (by linarith [hw.2])⟩ + +lemma ball_disjoint_hollow_lower (X : V → Fin h → ℝ) (x z : V) {δ q a : ℝ} + (hq : q+δ ≤ l1dist (X z) (X x)) : + Disjoint ((ball z δ).support X) ((hollow x a q).support X) := by + rw [Set.disjoint_left] + intro w hw hz + rw [support_ball] at hw + rw [support_hollow] at hz + have ht := l1dist_triangle (X z) w (X x) + rw [l1dist_comm (X z) w] at ht + linarith [hw.2,hz.2.2] + +lemma ball_disjoint_hollow_upper (X : V → Fin h → ℝ) (x z : V) {δ q b : ℝ} + (hq : l1dist (X z) (X x)+δ ≤ q) : + Disjoint ((ball z δ).support X) ((hollow x q b).support X) := by + rw [Set.disjoint_left] + intro w hw hz + rw [support_ball] at hw + rw [support_hollow] at hz + have ht := l1dist_triangle w (X z) (X x) + linarith [hw.2,hz.2.1] + +lemma concentric_disjoint (X : V → Fin h → ℝ) (x : V) {a b c d : ℝ} (hbc : b ≤ c) : + Disjoint ((hollow x a b).support X) ((hollow x c d).support X) := by + rw [Set.disjoint_left] + intro w hw hz + rw [support_hollow] at hw hz + linarith [hw.2.2,hz.2.1] + +lemma disjoint_balls_distance {X : V → Fin h → ℝ} (hX : ∀v, binary (X v)) + (u v : V) {δ : ℝ} (hd : Disjoint ((ball u δ).support X) ((ball v δ).support X)) : + 2*δ ≤ l1dist (X u) (X v) := by + by_contra hh + have hh := not_le.mp hh + let w := fun j => X u j+(1/2:ℝ)*(X v j-X u j) + have hw := cube_segment (binary_cube (hX u)) (binary_cube (hX v)) + (show (1/2:ℝ) ∈ Set.Icc (0:ℝ) 1 by norm_num) + have hu := binary_radial_affine (binary_cube (hX u)) (binary_cube (hX v)) (hX u) + (show (1/2:ℝ) ∈ Set.Icc (0:ℝ) 1 by norm_num) + have hv := binary_radial_affine (binary_cube (hX u)) (binary_cube (hX v)) (hX v) + (show (1/2:ℝ) ∈ Set.Icc (0:ℝ) 1 by norm_num) + simp only [l1dist_self,l1dist_comm (X v) (X u)] at hu hv + have hwu : w ∈ (ball u δ).support X := by + rw [support_ball]; exact ⟨hw,by dsimp [w]; linarith⟩ + have hwv : w ∈ (ball v δ).support X := by + rw [support_ball]; exact ⟨hw,by dsimp [w]; linarith⟩ + exact Set.disjoint_left.mp hd hwu hwv + +end RadialShell +end +end StrongThinTree.Geometry + +namespace StrongThinTree.Geometry.RadialShell +noncomputable section +open Finset +variable {V : Type uV3} [DecidableEq V] {h : ℕ} {X : V → Fin h → ℝ} + +def Arrangement (X : V → Fin h → ℝ) (O : Finset (RadialShell V)) : Prop := + (∀H ∈ O, H.Valid X) ∧ (O : Set (RadialShell V)).Pairwise (fun H K => Disjoint (H.support X) (K.support X)) + +omit [DecidableEq V] in +lemma arrangement_empty : Arrangement X ∅ := by simp [Arrangement] + +omit [DecidableEq V] in +lemma arrangement_subset {O P : Finset (RadialShell V)} (hO : Arrangement X O) (hPO : P ⊆ O) : + Arrangement X P := ⟨fun H hH => hO.1 H (hPO hH),hO.2.mono hPO⟩ + +omit [DecidableEq V] in +lemma arrangement_disjoint_finsets (hX : ∀v, binary (X v)) + {O P : Finset (RadialShell V)} (hO : Arrangement X O) + (hd : ∀H ∈ O, ∀K ∈ P, Disjoint (H.support X) (K.support X)) : Disjoint O P := by + rw [Finset.disjoint_left] + intro H hHO hHP + obtain ⟨w,hw⟩ := valid_support_nonempty hX (hO.1 H hHO) + exact Set.disjoint_left.mp (hd H hHO H hHP) hw hw + +lemma arrangement_union {O P : Finset (RadialShell V)} + (hO : Arrangement X O) (hP : Arrangement X P) + (hd : ∀H ∈ O, ∀K ∈ P, Disjoint (H.support X) (K.support X)) : Arrangement X (O ∪ P) := by + constructor + · intro H hH + rcases mem_union.mp hH with hH | hH + · exact hO.1 H hH + · exact hP.1 H hH + · intro H hH K hK hne + rcases mem_union.mp hH with hH | hH <;> rcases mem_union.mp hK with hK | hK + · exact hO.2 hH hK hne + · exact hd H hH K hK + · exact (hd K hK H hH).symm + · exact hP.2 hH hK hne + +lemma image_restriction_injective (hX : ∀v, binary (X v)) + {O : Finset (RadialShell V)} (hO : Arrangement X O) + (f : RadialShell V → RadialShell V) + (hf : ∀H ∈ O, (f H).Valid X ∧ (f H).support X ⊆ H.support X) : + Set.InjOn f (O : Set (RadialShell V)) := by + intro H hH K hK heq + by_contra hne + obtain ⟨w,hw⟩ := valid_support_nonempty hX (hf H hH).1 + exact Set.disjoint_left.mp (hO.2 hH hK hne) ((hf H hH).2 hw) + ((hf K hK).2 (heq ▸ hw)) + +lemma arrangement_image_restriction {O : Finset (RadialShell V)} (hO : Arrangement X O) + (f : RadialShell V → RadialShell V) + (hf : ∀H ∈ O, (f H).Valid X ∧ (f H).support X ⊆ H.support X) : + Arrangement X (O.image f) := by + constructor + · intro H hH + obtain ⟨K,hK,rfl⟩ := mem_image.mp hH + exact (hf K hK).1 + · intro H hH K hK hne + obtain ⟨H',hH',rfl⟩ := mem_image.mp hH + obtain ⟨K',hK',rfl⟩ := mem_image.mp hK + exact (hO.2 hH' hK' (by intro heq; exact hne (congrArg f heq))).mono + (hf H' hH').2 (hf K' hK').2 + +def capacity (Δ : ℝ) (H : RadialShell V) : ℝ := max (H.width-6*Δ) 0 + +def potential (Δ : ℝ) (O : Finset (RadialShell V)) : ℝ := ∑H ∈ O, capacity Δ H + +omit [DecidableEq V] in +lemma capacity_nonneg (Δ : ℝ) (H : RadialShell V) : 0 ≤ capacity Δ H := le_max_right _ _ +omit [DecidableEq V] in +lemma capacity_ge_formal (Δ : ℝ) (H : RadialShell V) : H.width-6*Δ ≤ capacity Δ H := le_max_left _ _ + +lemma potential_union {O P : Finset (RadialShell V)} (hOP : Disjoint O P) (Δ : ℝ) : + potential Δ (O ∪ P) = potential Δ O+potential Δ P := sum_union hOP + +lemma potential_erase {O : Finset (RadialShell V)} {H : RadialShell V} + (hH : H ∈ O) (Δ : ℝ) : potential Δ (O.erase H)+capacity Δ H = potential Δ O := + sum_erase_add _ _ hH + +lemma potential_image_restriction (hX : ∀v, binary (X v)) + {O : Finset (RadialShell V)} (hO : Arrangement X O) + (f : RadialShell V → RadialShell V) + (hf : ∀H ∈ O, (f H).Valid X ∧ (f H).support X ⊆ H.support X) (Δ : ℝ) : + potential Δ (O.image f) = ∑H ∈ O, capacity Δ (f H) := by + exact sum_image (fun H hH K hK heq => image_restriction_injective hX hO f hf hH hK heq) + +omit [DecidableEq V] in +lemma capacity_ball {δ Δ : ℝ} (h : 6*Δ ≤ δ) (v : V) : + capacity Δ (ball v δ) = δ-6*Δ := by + simp only [capacity,width,ball,sub_zero] + exact max_eq_left (sub_nonneg.mpr h) + +omit [DecidableEq V] in +lemma ball_injective (δ : ℝ) : Function.Injective (fun v : V => ball v δ) := by + intro u v heq + exact congrArg RadialShell.center heq + +lemma potential_balls {δ Δ : ℝ} (h : 6*Δ ≤ δ) (C : Finset V) : + potential Δ (C.image (fun v => ball v δ)) = (C.card : ℝ)*(δ-6*Δ) := by + rw [potential,sum_image (fun _ _ _ _ heq => ball_injective δ heq)] + simp only [capacity_ball h,sum_const,nsmul_eq_mul] + +end +end StrongThinTree.Geometry.RadialShell + +namespace StrongThinTree.Geometry.RadialShell +noncomputable section +open Finset +variable {V : Type uV4} [DecidableEq V] {h : ℕ} {X : V → Fin h → ℝ} + +omit [DecidableEq V] in +lemma potential_filter_width (O : Finset (RadialShell V)) {Δ : ℝ} (hΔ : 0 ≤ Δ) : + potential Δ (O.filter (fun H => 0 < H.width)) = potential Δ O := by + apply sum_subset (filter_subset _ _) + intro H hH hn + have hw : H.width ≤ 0 := le_of_not_gt (fun hh => hn (mem_filter.mpr ⟨hH,hh⟩)) + exact max_eq_right (by nlinarith) + +lemma arrangement_balls {U : Finset V} {δ : ℝ} + (hv : ∀u ∈ U, (ball u δ).Valid X) + (hd : (U : Set V).Pairwise (fun u v => Disjoint ((ball u δ).support X) ((ball v δ).support X))) : + Arrangement X (U.image (fun v => ball v δ)) := by + constructor + · intro H hH + obtain ⟨u,hu,rfl⟩ := mem_image.mp hH + exact hv u hu + · intro H hH K hK hne + obtain ⟨u,hu,rfl⟩ := mem_image.mp hH + obtain ⟨v,hv,rfl⟩ := mem_image.mp hK + exact hd hu hv (by intro heq; exact hne (congrArg (fun z => ball z δ) heq)) + +lemma split_shells (_hX : ∀v, binary (X v)) + {H : RadialShell V} (hH : H.Valid X) {L R δ Δ Δ' n : ℝ} + (hδ : 0 < δ) (hΔ : 2*δ ≤ Δ) (_hΔ' : 0 ≤ Δ') (hnext : 6*Δ' ≤ δ/2) + (hL : H.inner+δ ≤ L) (hR : R ≤ H.outer-δ) (hLR : L ≤ R) + (hspan : R-L ≤ Δ) (hn : 36*Δ ≤ n*δ) : + ∃P : Finset (RadialShell V), Arrangement X P ∧ + (∀K ∈ P, K.support X ⊆ H.support X) ∧ + (∀z, L ≤ l1dist (X z) (X H.center) → l1dist (X z) (X H.center) ≤ R → + ∀K ∈ P, Disjoint ((ball z δ).support X) (K.support X)) ∧ + capacity Δ H+n*δ/4 ≤ potential Δ P+n*(δ-6*Δ') := by + let A := hollow H.center H.inner (L-δ) + let B := hollow H.center (R+δ) H.outer + let P := ({A,B} : Finset (RadialShell V)).filter (fun K => 0 < K.width) + have hΔ0 : 0 ≤ Δ := by linarith + have hA : H.inner ≤ L-δ := by linarith + have hB : R+δ ≤ H.outer := by linarith + have hAB : A ≠ B := by + intro heq + have := congrArg RadialShell.inner heq + change H.inner = R+δ at this + linarith + have hpA : L-δ ≤ H.outer := by linarith + have hpB : H.inner ≤ R+δ := by linarith + have hdAB : Disjoint (A.support X) (B.support X) := concentric_disjoint X H.center (by linarith) + have hv : ∀K ∈ P, K.Valid X := by + intro K hK + obtain ⟨hK,hw⟩ := mem_filter.mp hK + rcases mem_insert.mp hK with rfl | hK + · exact restriction_valid hH le_rfl hpA (by exact sub_pos.mp hw) + · have heq := mem_singleton.mp hK + subst K + exact restriction_valid hH hpB le_rfl (by exact sub_pos.mp hw) + have hsub : ∀K ∈ P, K.support X ⊆ H.support X := by + intro K hK + have hK := (mem_filter.mp hK).1 + rcases mem_insert.mp hK with rfl | hK + · exact restriction_subset X H le_rfl hpA + · have heq := mem_singleton.mp hK + subst K + exact restriction_subset X H hpB le_rfl + have harr : Arrangement X P := by + refine ⟨hv,?_⟩ + intro J hJ K hK hne + have hJ := (mem_filter.mp hJ).1 + have hK := (mem_filter.mp hK).1 + simp only [mem_insert,mem_singleton] at hJ hK + rcases hJ with rfl | rfl <;> rcases hK with rfl | rfl + · exact (hne rfl).elim + · exact hdAB + · exact hdAB.symm + · exact (hne rfl).elim + refine ⟨P,harr,hsub,?_,?_⟩ + · intro z hzL hzR K hK + have hK := (mem_filter.mp hK).1 + rcases mem_insert.mp hK with rfl | hK + · exact ball_disjoint_hollow_lower X H.center z (by linarith) + · have heq := mem_singleton.mp hK + subst K + exact ball_disjoint_hollow_upper X H.center z (by linarith) + · have hp : potential Δ P = capacity Δ A+capacity Δ B := by + rw [show P = ({A,B} : Finset (RadialShell V)).filter (fun K => 0 < K.width) from rfl, + potential_filter_width _ hΔ0] + simp [potential,hAB] + rw [hp] + have hn0 : 0 ≤ n := by nlinarith + have hnew : n*δ/2 ≤ n*(δ-6*Δ') := by nlinarith + have hcapA := capacity_ge_formal Δ A + have hcapB := capacity_ge_formal Δ B + have hcapA0 := capacity_nonneg Δ A + have hcapB0 := capacity_nonneg Δ B + change L-δ-H.inner-6*Δ ≤ capacity Δ A at hcapA + change H.outer-(R+δ)-6*Δ ≤ capacity Δ B at hcapB + by_cases ht : H.width-6*Δ ≤ 0 + · rw [capacity,max_eq_right ht] + nlinarith + · rw [capacity,max_eq_left (le_of_not_ge ht)] + dsimp [width] + nlinarith + +lemma shrink_shells (hX : ∀v, binary (X v)) + {O : Finset (RadialShell V)} (hO : Arrangement X O) + {δ Δ Δ' : ℝ} (hδ : 0 < δ) (hΔ : 2*δ ≤ Δ) (_hΔ' : 0 ≤ Δ') (hnext : 6*Δ' ≤ δ/2) : + ∃P : Finset (RadialShell V), Arrangement X P ∧ + (∀K ∈ P, ∃H ∈ O, K.support X ⊆ H.support X) ∧ + (∀z, (∀H ∈ O, ¬(H.inner+δ+Δ ≤ l1dist (X z) (X H.center) ∧ + l1dist (X z) (X H.center) ≤ H.outer-δ-Δ)) → + ∀K ∈ P, Disjoint ((ball z δ).support X) (K.support X)) ∧ + potential Δ O ≤ potential Δ' P := by + let s := 2*δ+Δ + let f := fun H : RadialShell V => hollow H.center (H.inner+s) (H.outer-s) + let Q := O.filter (fun H => 2*s < H.width) + have hs : 0 ≤ s := by dsimp [s]; linarith + have hres : 2*s+6*Δ' ≤ 6*Δ := by dsimp [s]; linarith + have hQ : Arrangement X Q := arrangement_subset hO (filter_subset _ _) + have hf : ∀H ∈ Q, (f H).Valid X ∧ (f H).support X ⊆ H.support X := by + intro H hH + obtain ⟨hH,hw⟩ := mem_filter.mp hH + exact ⟨restriction_valid (hO.1 H hH) (by linarith) (by linarith) + (by dsimp [width] at hw; linarith),restriction_subset X H (by linarith) (by linarith)⟩ + refine ⟨Q.image f,arrangement_image_restriction hQ f hf,?_,?_,?_⟩ + · intro K hK + obtain ⟨H,hH,rfl⟩ := mem_image.mp hK + exact ⟨H,(mem_filter.mp hH).1,(hf H hH).2⟩ + · intro z hz K hK + obtain ⟨H,hH,rfl⟩ := mem_image.mp hK + have hz := hz H (mem_filter.mp hH).1 + by_cases hlo : H.inner+δ+Δ ≤ l1dist (X z) (X H.center) + · have hhi : H.outer-δ-Δ < l1dist (X z) (X H.center) := + lt_of_not_ge (fun hh => hz ⟨hlo,hh⟩) + exact ball_disjoint_hollow_lower X H.center z (by dsimp [s]; linarith) + · have hlo := lt_of_not_ge hlo + exact ball_disjoint_hollow_upper X H.center z (by dsimp [s]; linarith) + · rw [potential_image_restriction hX hQ f hf] + have heq : potential Δ O = potential Δ Q := by + symm + apply sum_subset (filter_subset _ _) + intro H hH hn + have hw : H.width ≤ 2*s := le_of_not_gt (fun hh => hn (mem_filter.mpr ⟨hH,hh⟩)) + exact max_eq_right (by linarith) + rw [heq] + apply sum_le_sum + intro H hH + apply max_le_max_right + dsimp [f,width,hollow] + linarith + +end +end StrongThinTree.Geometry.RadialShell + +namespace StrongThinTree.Geometry.RadialShell +noncomputable section +open Finset +variable {V : Type uV5} [DecidableEq V] {h : ℕ} {X : V → Fin h → ℝ} + +omit [DecidableEq V] in +lemma radial_span {D : Finset V} (hD : D.Nonempty) {Δ δ : ℝ} + (hdiam : ∀u ∈ D, ∀v ∈ D, l1dist (X u) (X v) ≤ Δ) + {H : RadialShell V} {z : V} (hz : z ∈ D) + (hint : H.inner+δ+Δ ≤ l1dist (X z) (X H.center) ∧ + l1dist (X z) (X H.center) ≤ H.outer-δ-Δ) : + ∃L R : ℝ, H.inner+δ ≤ L ∧ R ≤ H.outer-δ ∧ L ≤ R ∧ R-L ≤ Δ ∧ + (∀u ∈ D, L ≤ l1dist (X u) (X H.center) ∧ l1dist (X u) (X H.center) ≤ R) := by + obtain ⟨u,hu,humin⟩ := D.exists_min_image (fun v => l1dist (X v) (X H.center)) hD + obtain ⟨v,hv,hvmax⟩ := D.exists_max_image (fun v => l1dist (X v) (X H.center)) hD + refine ⟨l1dist (X u) (X H.center),l1dist (X v) (X H.center),?_,?_,?_,?_,?_⟩ + · have ht := l1dist_triangle (X z) (X u) (X H.center) + have hd := hdiam z hz u hu + linarith [hint.1] + · have ht := l1dist_triangle (X v) (X z) (X H.center) + have hd := hdiam v hv z hz + linarith [hint.2] + · exact humin v hv + · have ht := l1dist_triangle (X v) (X u) (X H.center) + linarith [hdiam v hv u hu] + · exact fun w hw => ⟨humin w hw,hvmax w hw⟩ + +lemma compact_phase (hX : ∀v, binary (X v)) + {δ Δ Δ' : ℝ} (hδ : 0 < δ) (hΔ : 2*δ ≤ Δ) (hΔ' : 0 ≤ Δ') (hnext : 6*Δ' ≤ δ/2) + (U : Finset V) (hUv : ∀u ∈ U, (ball u δ).Valid X) + (hUd : (U : Set V).Pairwise (fun u v => Disjoint ((ball u δ).support X) ((ball v δ).support X))) + (F : Finset (Finset V)) + (hFd : (F : Set (Finset V)).Pairwise Disjoint) + (hF : ∀D ∈ F, D ⊆ U ∧ D.Nonempty ∧ + (∀u ∈ D, ∀v ∈ D, l1dist (X u) (X v) ≤ Δ) ∧ 36*Δ ≤ (D.card : ℝ)*δ) + (O : Finset (RadialShell V)) (hO : Arrangement X O) + (C : Finset V) (hCU : C ⊆ U) (hCF : ∀D ∈ F, Disjoint C D) + (hOC : ∀H ∈ O, ∀z ∈ C, Disjoint (H.support X) ((ball z δ).support X)) : + ∃Z : Finset (RadialShell V), Arrangement X Z ∧ + potential Δ O+(C.card : ℝ)*(δ-6*Δ')+δ/4*∑D ∈ F, (D.card : ℝ) ≤ potential Δ' Z := by + induction F using Finset.strongInductionOn generalizing O C with + | _ F ih => + by_cases hinter : ∃D ∈ F, ∃z ∈ D, ∃H ∈ O, + H.inner+δ+Δ ≤ l1dist (X z) (X H.center) ∧ + l1dist (X z) (X H.center) ≤ H.outer-δ-Δ + · obtain ⟨D,hDF,z,hz,H,hHO,hint⟩ := hinter + obtain ⟨L,R,hL,hR,hLR,hspan,hbounds⟩ := + radial_span (hF D hDF).2.1 (hF D hDF).2.2.1 hz hint + obtain ⟨P,hP,hPH,hPD,hpot⟩ := split_shells hX (hO.1 H hHO) hδ hΔ hΔ' hnext + hL hR hLR hspan (hF D hDF).2.2.2 + have hballH : ∀u ∈ D, (ball u δ).support X ⊆ H.support X := by + intro u hu + exact ball_subset_of_radial_margin X H u (hL.trans (hbounds u hu).1) + ((hbounds u hu).2.trans hR) + have hcross : ∀K ∈ O.erase H, ∀J ∈ P, Disjoint (K.support X) (J.support X) := by + intro K hK J hJ + exact (hO.2 (mem_of_mem_erase hK) hHO (ne_of_mem_erase hK)).mono_right (hPH J hJ) + have hOE := arrangement_subset hO (erase_subset H O) + have hOP := arrangement_union hOE hP hcross + have hCUD : C ∪ D ⊆ U := union_subset hCU (hF D hDF).1 + have hCDE : ∀E ∈ F.erase D, Disjoint (C ∪ D) E := by + intro E hE + exact disjoint_union_left.mpr ⟨hCF E (mem_of_mem_erase hE), + hFd hDF (mem_of_mem_erase hE) (ne_of_mem_erase hE).symm⟩ + have hnewOC : ∀K ∈ O.erase H ∪ P, ∀u ∈ C ∪ D, + Disjoint (K.support X) ((ball u δ).support X) := by + intro K hK u hu + rcases mem_union.mp hK with hK | hK <;> rcases mem_union.mp hu with hu | hu + · exact hOC K (mem_of_mem_erase hK) u hu + · exact (hO.2 (mem_of_mem_erase hK) hHO (ne_of_mem_erase hK)).mono_right (hballH u hu) + · exact (hOC H hHO u hu).mono_left (hPH K hK) + · exact (hPD u (hbounds u hu).1 (hbounds u hu).2 K hK).symm + obtain ⟨Z,hZ,hZpot⟩ := ih (F.erase D) (erase_ssubset hDF) + (hFd.mono (erase_subset _ _)) (fun E hE => hF E (mem_of_mem_erase hE)) + (O.erase H ∪ P) hOP (C ∪ D) hCUD hCDE hnewOC + refine ⟨Z,hZ,?_⟩ + have hp := potential_union (arrangement_disjoint_finsets hX hOE hcross) Δ + have he := potential_erase hHO Δ + have hc := card_union_of_disjoint (hCF D hDF) + have hs := sum_erase_add F (fun E : Finset V => (E.card : ℝ)) hDF + have hc' : ((C ∪ D).card : ℝ) = (C.card : ℝ)+(D.card : ℝ) := by exact_mod_cast hc + rw [hp,hc'] at hZpot + nlinarith + · obtain ⟨P,hP,hPO,hPF,hpot⟩ := shrink_shells hX hO hδ hΔ hΔ' hnext + let W := C ∪ F.biUnion id + have hWU : W ⊆ U := by + intro u hu + rcases mem_union.mp hu with hu | hu + · exact hCU hu + · obtain ⟨D,hD,hu⟩ := mem_biUnion.mp hu + exact (hF D hD).1 hu + have hB : Arrangement X (W.image (fun u => ball u δ)) := + arrangement_balls (fun u hu => hUv u (hWU hu)) (hUd.mono hWU) + have hcross : ∀H ∈ P, ∀K ∈ W.image (fun u => ball u δ), + Disjoint (H.support X) (K.support X) := by + intro H hH K hK + obtain ⟨u,hu,rfl⟩ := mem_image.mp hK + rcases mem_union.mp hu with hu | hu + · obtain ⟨J,hJ,hsub⟩ := hPO H hH + exact (hOC J hJ u hu).mono_left hsub + · obtain ⟨D,hD,hu⟩ := mem_biUnion.mp hu + exact (hPF u (fun J hJ hh => hinter ⟨D,hD,u,hu,J,hJ,hh⟩) H hH).symm + refine ⟨P ∪ W.image (fun u => ball u δ),arrangement_union hP hB hcross,?_⟩ + rw [potential_union (arrangement_disjoint_finsets hX hP hcross), + potential_balls (show 6*Δ' ≤ δ by linarith)] + have hCW : Disjoint C (F.biUnion id) := by + rw [Finset.disjoint_left] + intro u hu hv + obtain ⟨D,hD,hv⟩ := mem_biUnion.mp hv + exact Finset.disjoint_left.mp (hCF D hD) hu hv + have hflat : (F.biUnion id).card = ∑D ∈ F, D.card := card_biUnion hFd + have hwcard : (W.card : ℝ) = (C.card : ℝ)+∑D ∈ F, (D.card : ℝ) := by + dsimp [W] + rw [card_union_of_disjoint hCW,hflat,Nat.cast_add,Nat.cast_sum] + rw [hwcard] + have hsum : 0 ≤ ∑D ∈ F, (D.card : ℝ) := sum_nonneg (fun D _ => Nat.cast_nonneg _) + have hmass : δ/4*(∑D ∈ F, (D.card : ℝ)) ≤ + (∑D ∈ F, (D.card : ℝ))*(δ-6*Δ') := by nlinarith + nlinarith + +end +end StrongThinTree.Geometry.RadialShell + +namespace StrongThinTree.Geometry.RadialShell +noncomputable section +open Finset +variable {V : Type uV6} [DecidableEq V] {h : ℕ} {X : V → Fin h → ℝ} + +lemma compact_arrangement (hX : ∀v, binary (X v)) + (q : ℕ) (δ Δ : ℕ → ℝ) (U : ℕ → Finset V) (F : ℕ → Finset (Finset V)) + (hδ : ∀i < q, 0 < δ i) (hΔ : ∀i < q, 2*δ i ≤ Δ i) + (hΔ0 : ∀i ≤ q, 0 ≤ Δ i) (hnext : ∀i < q, 6*Δ (i+1) ≤ δ i/2) + (hUv : ∀i < q, ∀u ∈ U i, (ball u (δ i)).Valid X) + (hUd : ∀i < q, (U i : Set V).Pairwise + (fun u v => Disjoint ((ball u (δ i)).support X) ((ball v (δ i)).support X))) + (hFd : ∀i < q, (F i : Set (Finset V)).Pairwise Disjoint) + (hF : ∀i < q, ∀D ∈ F i, D ⊆ U i ∧ D.Nonempty ∧ + (∀u ∈ D, ∀v ∈ D, l1dist (X u) (X v) ≤ Δ i) ∧ 36*Δ i ≤ (D.card : ℝ)*δ i) : + ∃Z : Finset (RadialShell V), Arrangement X Z ∧ + (∑i ∈ range q, δ i*(∑D ∈ F i, (D.card : ℝ)))/4 ≤ potential (Δ q) Z := by + have hex : ∀j ≤ q, ∃Z : Finset (RadialShell V), Arrangement X Z ∧ + (∑i ∈ range j, δ i*(∑D ∈ F i, (D.card : ℝ)))/4 ≤ potential (Δ j) Z := by + intro j + induction j with + | zero => + intro _ + exact ⟨∅,arrangement_empty,by simp [potential]⟩ + | succ j ih => + intro hj + have hjq : j < q := by omega + obtain ⟨O,hO,hpot⟩ := ih (by omega) + obtain ⟨Z,hZ,hZp⟩ := compact_phase hX (hδ j hjq) (hΔ j hjq) + (hΔ0 (j+1) hj) (hnext j hjq) (U j) (hUv j hjq) (hUd j hjq) + (F j) (hFd j hjq) (hF j hjq) O hO ∅ (empty_subset _) (by simp) (by simp) + refine ⟨Z,hZ,?_⟩ + simp only [card_empty,Nat.cast_zero,zero_mul,add_zero] at hZp + rw [sum_range_succ] + linarith + exact hex q le_rfl + +structure CompactFamily (X : V → Fin h → ℝ) (δ Δ : ℝ) where + bags : Finset (Finset V) + nonempty : bags.Nonempty + radius_pos : 0 < δ + bags_disjoint : (bags : Set (Finset V)).Pairwise Disjoint + balls_disjoint : (bags.biUnion id : Set V).Pairwise + (fun u v => Disjoint ((ball u δ).support X) ((ball v δ).support X)) + cardinal : ∀D ∈ bags, 2 ≤ D.card + diameter : ∀D ∈ bags, ∀u ∈ D, ∀v ∈ D, l1dist (X u) (X v) ≤ Δ + compact : ∀D ∈ bags, 36*Δ ≤ (D.card : ℝ)*δ + +lemma CompactFamily.ball_valid (hX : ∀v, binary (X v)) {δ Δ : ℝ} + (F : CompactFamily X δ Δ) {u : V} (hu : u ∈ F.bags.biUnion id) : + (ball u δ).Valid X := by + obtain ⟨D,hD,huD⟩ := mem_biUnion.mp hu + have hcard := F.cardinal D hD + obtain ⟨v,hv,hvu⟩ := Finset.exists_mem_ne (by omega : 1 < D.card) u + have hvU : v ∈ F.bags.biUnion id := mem_biUnion.mpr ⟨D,hD,hv⟩ + have hdist := disjoint_balls_distance hX u v (F.balls_disjoint hu hvU hvu.symm) + refine ⟨le_rfl,F.radius_pos,fun _ => rfl,⟨u,by simp [ball,l1dist_self]⟩,v,?_⟩ + change δ ≤ l1dist (X v) (X u) + rw [l1dist_comm] + linarith [F.radius_pos] + +lemma CompactFamily.scale (hX : ∀v, binary (X v)) {δ Δ : ℝ} + (F : CompactFamily X δ Δ) : 2*δ ≤ Δ := by + obtain ⟨D,hD⟩ := F.nonempty + have hcard := F.cardinal D hD + obtain ⟨u,hu⟩ := card_pos.mp (by omega : 0 < D.card) + obtain ⟨v,hv,hvu⟩ := Finset.exists_mem_ne (by omega : 1 < D.card) u + have huU : u ∈ F.bags.biUnion id := mem_biUnion.mpr ⟨D,hD,hu⟩ + have hvU : v ∈ F.bags.biUnion id := mem_biUnion.mpr ⟨D,hD,hv⟩ + exact (disjoint_balls_distance hX u v (F.balls_disjoint huU hvU hvu.symm)).trans + (F.diameter D hD u hu v hv) + +end +end StrongThinTree.Geometry.RadialShell + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset StrongThinTree.Geometry StrongThinTree.Geometry.RadialShell + +lemma arrangement_length_bound {n m h : ℕ} (G : MultiGraph n m) {k : ℕ} + (hk : G.EdgeConnected k) (X : Fin n → Fin h → ℝ) (hX : ∀v, binary (X v)) + {O : Finset (RadialShell (Fin n))} (hO : Arrangement X O) : + (k:ℝ)*potential 0 O ≤ ∑e : Fin m, l1dist (X (G.left e)) (X (G.right e)) := by + have hb := G.binary_shell_length_bound hk X (fun v => binary_cube (hX v)) + (fun H : O => X H.val.center) (fun H => hX H.val.center) + (fun H : O => H.val.inner) (fun H : O => H.val.outer) + (fun H => (hO.1 H.val H.property).2.1.le) + (fun H => (hO.1 H.val H.property).2.2.2.1) + (fun H => (hO.1 H.val H.property).2.2.2.2) ?_ + · convert hb using 2 + rw [potential,Finset.sum_coe_sort O (fun H : RadialShell (Fin n) => H.outer-H.inner)] + apply sum_congr rfl + intro H hH + simp only [capacity,mul_zero,sub_zero] + exact max_eq_left (valid_width_pos (hO.1 H hH)).le + · intro H K hne w hw hbad + exact Set.disjoint_left.mp (hO.2 H.property K.property (Subtype.val_injective.ne hne)) + ⟨hw,hbad.2.1,Or.inr hbad.1⟩ ⟨hw,hbad.2.2.2,Or.inr hbad.2.2.1⟩ + +lemma binary_compact_bound {n m h : ℕ} (G : MultiGraph n m) {k : ℕ} + (hk : G.EdgeConnected k) (X : Fin n → Fin h → ℝ) (hX : ∀v, binary (X v)) + (q : ℕ) (δ Δ : ℕ → ℝ) (F : ∀i, CompactFamily X (δ i) (Δ i)) + (hnext : ∀i, i+1 < q → Δ (i+1) ≤ δ i/12) : + (k:ℝ)/4*(∑i ∈ range q, δ i*(∑D ∈ (F i).bags, (D.card : ℝ))) ≤ + ∑e : Fin m, l1dist (X (G.left e)) (X (G.right e)) := by + let D := fun i => if i < q then Δ i else 0 + have hD0 : ∀i ≤ q, 0 ≤ D i := by + intro i hi + dsimp [D] + split_ifs with hh + · linarith [(F i).scale hX,(F i).radius_pos] + · exact le_rfl + obtain ⟨Z,hZ,hZp⟩ := compact_arrangement hX q δ D + (fun i => (F i).bags.biUnion id) (fun i => (F i).bags) + (fun i _ => (F i).radius_pos) + (fun i hi => by simpa [D,hi] using (F i).scale hX) hD0 + (by + intro i hi + dsimp [D] + split_ifs with hh + · linarith [hnext i hh] + · linarith [(F i).radius_pos]) + (fun i _ u hu => (F i).ball_valid hX hu) + (fun i _ => (F i).balls_disjoint) + (fun i _ => (F i).bags_disjoint) + (by + intro i hi S hS + refine ⟨?_,?_,?_,?_⟩ + · intro u hu; exact mem_biUnion.mpr ⟨S,hS,hu⟩ + · exact card_pos.mp (by have := (F i).cardinal S hS; omega) + · simpa [D,hi] using (F i).diameter S hS + · simpa [D,hi] using (F i).compact S hS) + simp only [D,lt_self_iff_false,ite_false] at hZp + have hmul := mul_le_mul_of_nonneg_left hZp (Nat.cast_nonneg k : (0:ℝ) ≤ k) + have hlength := G.arrangement_length_bound hk X hX hZ + nlinarith + +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/ShortcutDuality.lean b/lean/OAI/Combinatorics/ThinTrees/ShortcutDuality.lean new file mode 100644 index 0000000000000000000000000000000000000000..e4cde2a44c4b8a662e6f4218f0301684acabccd1 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/ShortcutDuality.lean @@ -0,0 +1,157 @@ +import OAI.Combinatorics.ThinTrees.Duality + +namespace OAI + +section + +namespace StrongThinTree.MultiGraph +noncomputable section +open Matrix Finset StrongThinTree.Geometry +open scoped Classical MatrixOrder Matrix.Norms.L2Operator +variable {n m h : ℕ} (G : MultiGraph n m) + +abbrev point (v : Fin n) : Fin n → ℝ := Pi.single v 1 + +def incidence (e : Fin m) : Fin n → ℝ := point (G.left e) - point (G.right e) + +lemma eval_incidence (x : Fin n → ℝ) (e : Fin m) : + (∑v, x v*G.incidence e v)=x (G.left e)-x (G.right e) := by + simp [incidence,point,Pi.sub_apply,mul_sub,sum_sub_distrib,Pi.single_apply,mul_ite] + +abbrev ProperCut (n : ℕ) := {S : Finset (Fin n) // S.Nonempty ∧ S ≠ univ} + +def cutIndicator (S : Finset (Fin n)) (v : Fin n) : ℝ := if v ∈ S then 1 else 0 + +lemma cutIndicator_binary (S : Finset (Fin n)) (v : Fin n) : + cutIndicator S v=0 ∨ cutIndicator S v=1 := by + by_cases hv : v ∈ S <;> simp [cutIndicator,hv] + +lemma cutIndicator_energy (S : Finset (Fin n)) : + (∑e, (∑v, cutIndicator S v*G.incidence e v)^2)=((G.cut univ S).card : ℝ) := by + simp only [G.eval_incidence] + simp only [cut,card_eq_sum_ones,Nat.cast_sum,sum_filter] + apply sum_congr rfl + intro e _ + by_cases hl : G.left e ∈ S <;> by_cases hr : G.right e ∈ S <;> + simp [cutIndicator,hl,hr] + +lemma binary_matrix_energy (X : Matrix (Fin h) (Fin n) ℝ) + (hX : ∀i v, X i v=0 ∨ X i v=1) : + (∑e, ∑i, (X*Matrix.of (fun v e => G.incidence e v)) i e ^2)= + ∑e, l1dist (fun i => X i (G.left e)) (fun i => X i (G.right e)) := by + apply sum_congr rfl + intro e _ + unfold l1dist + apply sum_congr rfl + intro i _ + change (∑v, X i v*G.incidence e v)^2 = |X i (G.left e)-X i (G.right e)| + rw [G.eval_incidence] + rcases hX i (G.left e) with hl | hl <;> rcases hX i (G.right e) with hr | hr <;> + simp [hl,hr] + +lemma contraction_embedding (X : Matrix (Fin h) (Fin n) ℝ) + (hX : ∀i v, X i v=0 ∨ X i v=1) (U : Matrix (Fin m) (Fin h) ℝ) + (hU : Uᵀ*U ≤ 1) : + let Y : Fin n → EuclideanSpace ℝ (Fin m) := fun v => WithLp.toLp 2 (U *ᵥ (fun i => X i v)) + ∀u v, ‖Y u-Y v‖^2 ≤ l1dist (fun i => X i u) (fun i => X i v) := by + dsimp + intro u v + have hh := Polar.norm_sq_mulVec_le hU (fun i => X i u-X i v) + have heq : (WithLp.toLp 2 (U *ᵥ (fun i => X i u)) : EuclideanSpace ℝ (Fin m)) - + WithLp.toLp 2 (U *ᵥ (fun i => X i v)) = + WithLp.toLp 2 (U *ᵥ (fun i => X i u-X i v)) := by + rw [show (fun i => X i u-X i v)=(fun i => X i u)-(fun i => X i v) from rfl,mulVec_sub] + rfl + rw [heq,EuclideanSpace.norm_sq_eq] + have hdist : (fun i => X i u-X i v) ⬝ᵥ (fun i => X i u-X i v)= + l1dist (fun i => X i u) (fun i => X i v) := by + unfold dotProduct l1dist + apply sum_congr rfl + intro i _ + rcases hX i u with hu | hu <;> rcases hX i v with hv | hv <;> simp [hu,hv] + rw [←hdist] + simpa only [dotProduct,PiLp.toLp_apply,Real.norm_eq_abs,←pow_two,sq_abs] using hh + +lemma contraction_edge_diag (X : Matrix (Fin h) (Fin n) ℝ) + (U : Matrix (Fin m) (Fin h) ℝ) (e : Fin m) : + let Y : Fin n → EuclideanSpace ℝ (Fin m) := fun v => WithLp.toLp 2 (U *ᵥ (fun i => X i v)) + (Y (G.left e)-Y (G.right e)).ofLp e = + (U*(X*Matrix.of (fun v e => G.incidence e v))) e e := by + change (∑i, U e i*X i (G.left e))-(∑i, U e i*X i (G.right e)) = _ + change (∑i, U e i*X i (G.left e))-(∑i, U e i*X i (G.right e)) = + ∑i, U e i*(∑v, X i v*G.incidence e v) + simp_rw [G.eval_incidence,mul_sub] + rw [sum_sub_distrib] + +namespace Hierarchy +variable {G : MultiGraph n m} {H : Hierarchy n} + +def shortcutCoefficient (q L R : ℕ) (α ε : ℝ) : ℝ := + 2*α+2*(R:ℝ)*(L:ℝ)/(((q:ℝ)/8192)*((α*truncationGain α/32)^ε/(6912*(1024/ε^2)))*truncationGain α) + +lemma shortcutCoefficient_nonneg (q L R : ℕ) {α ε : ℝ} (hα : 0 ≤ α) : + 0 ≤ shortcutCoefficient q L R α ε := by + unfold shortcutCoefficient + have hg := (truncationGain_pos α).le + positivity + +lemma binary_numerator_bound {q L R : ℕ} (hq : 0 < q) (hL : 0 < L) (hR : 0 < R) + (hk : G.EdgeConnected q) (hconn : H.LocallyConnectedReal G q) + (M : Finset (Finset (Fin n))) (hM : M ⊆ H.nodes) (hroot : ∀t ∈ M, t ≠ univ) + {α ε ρ : ℝ} (hα : 0 < α) (hα1 : α ≤ 1) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (hsmall : (α*truncationGain α/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*truncationGain α/32)^(1+2*ε)) + (hratio : ∀t ∈ M, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (H.parentBoundary G t).card) + (hlogL : Real.logb 2 (16/(α*truncationGain α))+1 < L) + (hlogR : Real.logb 2 (24/(ρ*(α*truncationGain α/32)^2)) < R) + (X : Matrix (Fin h) (Fin n) ℝ) (hX : ∀i v, X i v=0 ∨ X i v=1) + (U : Matrix (Fin m) (Fin h) ℝ) (hU : Uᵀ*U ≤ 1) + (hpositive : ∀e, 0 ≤ (U*(X*Matrix.of (fun v e => G.incidence e v))) e e) : + (∑t : M, (∑e ∈ H.parentBoundary G t, (U*(X*Matrix.of (fun v e => G.incidence e v))) e e)^2/ + ((H.parentBoundary G t).card : ℝ)) ≤ + shortcutCoefficient q L R α ε*(∑e, ∑i, (X*Matrix.of (fun v e => G.incidence e v)) i e ^2) := by + let Y : Fin n → EuclideanSpace ℝ (Fin m) := fun v => WithLp.toLp 2 (U *ᵥ (fun i => X i v)) + have hh := hierarchy_numerator_bound hq hL hR hk (fun v i => hX i v) hconn M Y hM hroot + hα hα1 he he1 hρ hρsmall (contraction_embedding X hX U hU) + (fun e => by simpa only [Y,G.contraction_edge_diag] using hpositive e) + hsmall hassign hratio hlogL hlogR + rw [sum_coe_sort M (fun t => (∑e ∈ H.parentBoundary G t, + (U*(X*Matrix.of (fun v e => G.incidence e v))) e e)^2/((H.parentBoundary G t).card:ℝ)), + G.binary_matrix_energy X hX] + simpa only [Y,G.contraction_edge_diag,shortcutCoefficient] using hh + +lemma exists_shortcut_explicit {q L R : ℕ} (hq : 0 < q) (hL : 0 < L) (hR : 0 < R) + (hk : G.EdgeConnected q) (hconn : H.LocallyConnectedReal G q) + (M : Finset (Finset (Fin n))) (hM : M ⊆ H.nodes) (hroot : ∀t ∈ M, t ≠ univ) + {α ε ρ : ℝ} (hα : 0 < α) (hα1 : α ≤ 1) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (hsmall : (α*truncationGain α/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*truncationGain α/32)^(1+2*ε)) + (hratio : ∀t ∈ M, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (H.parentBoundary G t).card) + (hlogL : Real.logb 2 (16/(α*truncationGain α))+1 < L) + (hlogR : Real.logb 2 (24/(ρ*(α*truncationGain α/32)^2)) < R) + {η : ℝ} (hη : 0 < η) : + ∃D : Matrix (Fin n) (Fin n) ℝ, D.PosDef ∧ + (∀t ∈ M, ShortcutDual.boundaryAverage G.incidence (H.parentBoundary G) t D < + shortcutCoefficient q L R α ε+η) ∧ + (∀S : Finset (Fin n), S.Nonempty → S ≠ univ → + cutIndicator S ⬝ᵥ (D *ᵥ cutIndicator S) < ((G.cut univ S).card : ℝ)) := by + have hd (S : ProperCut n) : 0 < ((G.cut univ S).card : ℝ) := + Nat.cast_pos.mpr (hq.trans_le (hk S.val S.property.1 S.property.2)) + obtain ⟨D,hD,hb,hc⟩ := ShortcutDual.shortcut_of_binary_bound G.incidence + (fun t : M => H.parentBoundary G t) (fun S : ProperCut n => cutIndicator S.val) + (fun S : ProperCut n => ((G.cut univ S.val).card : ℝ)) + (fun S v => cutIndicator_binary S.val v) hd (fun S => G.cutIndicator_energy S.val) + (shortcutCoefficient_nonneg q L R hα.le) + (fun _ X hX U hU hp => binary_numerator_bound hq hL hR hk hconn M hM hroot + hα hα1 he he1 hρ hρsmall hsmall hassign hratio hlogL hlogR X hX U hU hp) hη + exact ⟨D,hD,fun t ht => hb ⟨t,ht⟩,fun S hS hS' => hc ⟨S,hS,hS'⟩⟩ + +end Hierarchy +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Signing/FormSigning.lean b/lean/OAI/Combinatorics/ThinTrees/Signing/FormSigning.lean new file mode 100644 index 0000000000000000000000000000000000000000..57b5562b428089c4dd264c82a66729c2a05c7f7c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Signing/FormSigning.lean @@ -0,0 +1,78 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Signing.GramWhitening +import OAI.Combinatorics.ThinTrees.Signing.StackedSigning + +namespace OAI + +/-! Form signing. -/ + +section + +namespace AlgorithmicThinTrees.FormSigning +open Matrix Finset GramWhitening StackedSigning RationalSigning +open scoped MatrixOrder +variable {a b m : ℕ} + +def whiten (P : Matrix (Fin a) (Fin a) ℚ) (v : Fin m → Fin a → ℚ) := + fun e => (rationalFactor P)ᵀ*ᵥv e + +lemma whiten_cast (P : Matrix (Fin a) (Fin a) ℚ) (v : Fin m → Fin a → ℚ) (e : Fin m) : + realVec (whiten P v) e=((rationalFactor P).map (fun q : ℚ => (q:ℝ)))ᵀ*ᵥrealVec v e := by + ext i + simp only [whiten,realVec,mulVec,dotProduct,transpose_apply,map_apply,Rat.cast_sum,Rat.cast_mul] + +lemma whiten_covariance (P : Matrix (Fin a) (Fin a) ℚ) + (hP : (P.map (fun q : ℚ => (q:ℝ))).PosDef) (v : Fin m → Fin a → ℚ) + (hv : StackedSigning.gram (realVec v) univ ≤ P.map (fun q : ℚ => (q:ℝ))) : + StackedSigning.gram (realVec (whiten P v)) univ ≤ 1 := by + simpa only [StackedSigning.gram,whiten_cast] using + cov_bound _ hP _ (rationalFactor_correct P hP) (realVec v) hv + +lemma whiten_norm (P : Matrix (Fin a) (Fin a) ℚ) + (hP : (P.map (fun q : ℚ => (q:ℝ))).PosDef) (v : Fin m → Fin a → ℚ) (e : Fin m) : + realVec (whiten P v) e ⬝ᵥ realVec (whiten P v) e= + realVec v e ⬝ᵥ ((P.map (fun q : ℚ => (q:ℝ)))⁻¹*ᵥrealVec v e) := by + rw [whiten_cast,rectangular_norm,rationalFactor_correct P hP] + +def selected (P : Matrix (Fin a) (Fin a) ℚ) (Q : Matrix (Fin b) (Fin b) ℚ) + (u : Fin m → Fin a → ℚ) (v : Fin m → Fin b → ℚ) : Finset (Fin m) := + StackedSigning.selected (whiten P u) (whiten Q v) + +theorem simultaneous (P : Matrix (Fin a) (Fin a) ℚ) (Q : Matrix (Fin b) (Fin b) ℚ) + (hP : (P.map (fun q : ℚ => (q:ℝ))).PosDef) (hQ : (Q.map (fun q : ℚ => (q:ℝ))).PosDef) + (u : Fin m → Fin a → ℚ) (v : Fin m → Fin b → ℚ) {δ : ℝ} (hδ : 0 ≤ δ) + (hu : StackedSigning.gram (realVec u) univ ≤ P.map (fun q : ℚ => (q:ℝ))) + (hv : StackedSigning.gram (realVec v) univ ≤ Q.map (fun q : ℚ => (q:ℝ))) + (hnorm : ∀e, realVec u e ⬝ᵥ ((P.map (fun q : ℚ => (q:ℝ)))⁻¹*ᵥrealVec u e)+ + realVec v e ⬝ᵥ ((Q.map (fun q : ℚ => (q:ℝ)))⁻¹*ᵥrealVec v e) ≤ δ) : + let A := selected P Q u v + let ε := 20*Real.sqrt (2*δ) + (-(ε • P.map (fun q : ℚ => (q:ℝ))) ≤ + StackedSigning.gram (realVec u) A-(1/2:ℝ) • StackedSigning.gram (realVec u) univ ∧ + StackedSigning.gram (realVec u) A-(1/2:ℝ) • StackedSigning.gram (realVec u) univ ≤ ε • P.map (fun q : ℚ => (q:ℝ))) ∧ + (-(ε • Q.map (fun q : ℚ => (q:ℝ))) ≤ + StackedSigning.gram (realVec v) A-(1/2:ℝ) • StackedSigning.gram (realVec v) univ ∧ + StackedSigning.gram (realVec v) A-(1/2:ℝ) • StackedSigning.gram (realVec v) univ ≤ ε • Q.map (fun q : ℚ => (q:ℝ))) := by + have h := StackedSigning.simultaneous (whiten P u) (whiten Q v) hδ + (whiten_covariance P hP u hu) (whiten_covariance Q hQ v hv) + (fun e => by simpa only [whiten_norm P hP,whiten_norm Q hQ] using hnorm e) + constructor + · exact transfer _ hP _ (rationalFactor_correct P hP) (realVec u) (selected P Q u v) + (by simpa only [StackedSigning.gram,whiten_cast,selected] using h.1) + · exact transfer _ hQ _ (rationalFactor_correct Q hQ) (realVec v) (selected P Q u v) + (by simpa only [StackedSigning.gram,whiten_cast,selected] using h.2) + +lemma gram_restrict {d : ℕ} (v : Fin m → Fin d → ℝ) (B A : Finset (Fin m)) + (h : ∀e, e ∉ B → v e=0) : StackedSigning.gram v (A∩B)=StackedSigning.gram v A := by + unfold StackedSigning.gram + apply sum_subset_zero_on_sdiff inter_subset_left + · intro e he + obtain ⟨he,he'⟩ := mem_sdiff.mp he + have hb : e ∉ B := fun hb => he' (mem_inter.mpr ⟨he,hb⟩) + rw [h e hb,zero_vecMulVec] + · intros; rfl + +end AlgorithmicThinTrees.FormSigning +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Signing/GramRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Signing/GramRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..92fe72a39b7f5dc43b1e9a6273c362d256e4de33 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Signing/GramRealization.lean @@ -0,0 +1,222 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Arithmetic.ScalarRealization +import OAI.Combinatorics.ThinTrees.Pencil.PointPrograms +import OAI.Combinatorics.ThinTrees.RationalMatrix.InverseRealization +import OAI.Combinatorics.ThinTrees.Signing.GramWhitening + +namespace OAI + +/-! Gram realization. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 Matrix AlgorithmicThinTrees + +abbrev GramLift := MatrixData × MatrixObject +abbrev gramLiftCode := prodCode matrixCode matrixObjectCode +abbrev gramChild := first matrixCode matrixObjectCode +abbrev gramParent := second matrixCode matrixObjectCode + +def firstColumn : Realizes matrixCode vectorCode + (fun A : MatrixData => A.map (fun row => row.getD 0 0)) := + (((constant vectorCode natCode 0).both (identity vectorCode)).then (getD ratCode 0)).map +instance poly_firstColumn : PolyTime firstColumn := by unfold firstColumn;infer_instance + +lemma firstColumn_data {n m : ℕ} (A : Matrix (Fin n) (Fin (m+1)) ℚ) : + (matrixData A).map (fun row => row.getD 0 0)=List.ofFn (fun i => A i 0) := by + simp only [matrixData,List.map_ofFn,Function.comp_def] + apply congrArg List.ofFn + funext i + exact getD_ofFn (A i) 0 0 + +def gramLiftData (p : GramLift) : MatrixData := + (RationalGram.scalarFactors (((matrixData p.2.2).getD 0 []).getD 0 0)⁻¹).map + (fun a => ((matrixData p.2.2).map (fun row => row.getD 0 0)).map (fun q => a*q)) ++ + p.1.map (fun row => 0::row) + +def gramLift : Realizes gramLiftCode matrixCode gramLiftData := + let A := gramParent.then matrixEntries + let z := constant gramLiftCode natCode 0 + let pivot := (A.both (z.both z)).then matrixEntry + let factors := (((constant gramLiftCode ratCode 1).div pivot).then scalarFactorProgram) + let scale := ((second vectorCode ratCode).both (first vectorCode ratCode)).then vectorScale + let cap := ((A.then firstColumn).both factors).then scale.mapCtx + let lift := ((constant vectorCode ratCode 0).both (identity vectorCode)).then (consList ratCode) + ((cap.both (gramChild.then lift.map)).then (appendList vectorCode)).congr + (fun _ => by simp only [gramLiftData,one_div,id_eq]) +instance poly_gramLift : PolyTime gramLift := by + unfold gramLift + apply poly_congr + +lemma gramLift_data {n : ℕ} (A : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) + (xs : List (Fin n → ℚ)) : + gramLiftData (xs.map List.ofFn,⟨n+1,A⟩)= + ((RationalGram.scalarFactors (A 0 0)⁻¹).map (fun a i => a*A i 0) ++ + xs.map (Fin.cons 0)).map List.ofFn := by + unfold gramLiftData + have hp : ((matrixData A).getD 0 []).getD 0 0=A 0 0 := matrix_entry_data A 0 0 + rw [hp,firstColumn_data] + simp only [List.map_append,List.map_map,List.map_ofFn,Function.comp_def,List.ofFn_succ, + Fin.cons_zero,Fin.cons_succ,List.map_cons, List.map_ofFn] + +lemma gram_fold_correct (a : MatrixObject) : + (schurHistoryData a).foldl (fun B A => gramLiftData (B,A)) []= + (RationalGram.factorColumns a.1 a.2).map List.ofFn := by + rcases a with ⟨n,A⟩ + induction n with + | zero => simp [schurHistoryData,RationalGram.factorColumns] + | succ n ih => + simp only [schurHistoryData,List.foldl_append,List.foldl_cons,List.foldl_nil] + rw [ih,gramLift_data] + rfl + +def gramColumnsProgram : Realizes matrixObjectCode matrixCode + (fun a => (RationalGram.factorColumns a.1 a.2).map List.ofFn) := + (((constant matrixObjectCode matrixCode []).both schurHistory).then gramLift.fold).congr + gram_fold_correct + +lemma gram_take_history (a : MatrixObject) (k : ℕ) : + (schurHistoryData a |>.take k).foldl (fun B A => gramLiftData (B,A)) []=[] ∨ + ∃b∈schurHistoryData a, + (schurHistoryData a |>.take k).foldl (fun B A => gramLiftData (B,A)) []= + (RationalGram.factorColumns b.1 b.2).map List.ofFn := by + rcases a with ⟨n,A⟩ + induction n generalizing k with + | zero => simp [schurHistoryData] + | succ n ih => + by_cases hk : k ≤ n + · have he : (schurHistoryData ⟨n+1,A⟩).take k= + (schurHistoryData ⟨n,KS.W17.schurTail A⟩).take k := by + rw [schurHistoryData,List.take_append_of_le_length] + simpa only [schurHistory_length] using hk + rw [he] + rcases ih k (KS.W17.schurTail A) with h|⟨b,hb,he⟩ + · exact Or.inl h + · exact Or.inr ⟨b,by simp only [schurHistoryData,List.mem_append,List.mem_singleton]; exact Or.inl hb,he⟩ + · rw [List.take_of_length_le (by rw [schurHistory_length]; change n+1 ≤ k; omega),gram_fold_correct] + exact Or.inr ⟨⟨n+1,A⟩,by simp [schurHistoryData],rfl⟩ + +lemma SchurDesc.gram_wire {a b : MatrixObject} (h : SchurDesc a b) + (hA : (a.2.map (fun q : ℚ => (q:ℝ))).PosSemidef) : + (matrixCode ((RationalGram.factorColumns b.1 b.2).map List.ofFn)).length ≤ + (3*a.1*(2*KS.W30.inverseBitBound a.1 (matrixObjectCode a).length+1))* + (2*(a.1*(2*(4*(4*KS.W30.inverseBitBound a.1 (matrixObjectCode a).length+1)+7)+1))+1) := by + have hn := h.dim + obtain ⟨k,p,r,h⟩ := h + obtain ⟨hl,hv⟩ := RationalGram.trace_factor_bounds a.2 hA (matrixObject_parts a) h + let B := KS.W30.inverseBitBound a.1 (matrixObjectCode a).length + have hw : ∀v∈RationalGram.factorColumns b.1 b.2, + (vectorCode (List.ofFn v)).length≤a.1*(2*(4*(4*B+1)+7)+1) := by + intro v h + apply (listCode_length_bound (List.ofFn v) (4*(4*B+1)+7) ?_).trans + (by rw [List.length_ofFn]; exact Nat.mul_le_mul_right _ hn) + intro q hq + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hq + exact (show QParts (4*B+1) (v i) from hv v h i).length + apply (listCode_length_bound _ (a.1*(2*(4*(4*B+1)+7)+1)) ?_).trans ?_ + · intro row hr + obtain ⟨v,hv,rfl⟩ := List.mem_map.mp hr + exact hw v hv + · rw [List.length_map] + apply Nat.mul_le_mul_right _ + exact hl.trans (Nat.mul_le_mul_right _ (Nat.mul_le_mul_left _ hn)) + +lemma runsPoly_gramColumns {ι : Type*} {L : ι → ℕ} (a : ι → MatrixObject) + (ha : IsPoly L (fun i => (matrixObjectCode (a i)).length)) + (hA : ∀i,((a i).2.map (fun q : ℚ => (q:ℝ))).PosSemidef) : + RunsPoly L gramColumnsProgram a := by + have hh := runsPoly_schurHistory a ha hA + have hh' := (RunsPoly.of_poly (constant matrixObjectCode matrixCode []) a ha).both hh + have hd : IsPoly L (fun i => (a i).1) := ha.mono (fun i => matrixObject_dim_le (a i)) + have hi : IsPoly L (fun i => KS.W30.inverseBitBound (a i).1 (matrixObjectCode (a i)).length) := + ((((isPoly_const L 6).mul (ha.add (isPoly_const L 1))).mul + ((hd.add (isPoly_const L 1)).pow 3))).mono + (fun i => KS.W30.inverseBitBound_le_polynomial _ _) + have hb := (((isPoly_const L 3).mul hd).mul (((isPoly_const L 2).mul hi).add (isPoly_const L 1))).mul + (((isPoly_const L 2).mul (hd.mul (((isPoly_const L 2).mul + (((isPoly_const L 4).mul (((isPoly_const L 4).mul hi).add (isPoly_const L 1))).add + (isPoly_const L 7))).add (isPoly_const L 1)))).add (isPoly_const L 1)) + obtain ⟨p,hp⟩ := hb + have hfold := runsPoly_fold_of_poly gramLift (fun i => ([],schurHistoryData (a i))) + hh'.output (show ∃p : NaturalPolynomial, _ from ⟨p,by + intro i ys zs he + have hy : ys=(schurHistoryData (a i)).take ys.length := by + dsimp only at he + rw [he,List.take_left] + rw [hy] + rcases gram_take_history (a i) ys.length with hz|⟨b,hb,he⟩ + · rw [hz]; exact Nat.zero_le _ + · rw [he] + exact ((schurHistory_mem (a i) (hA i) b hb).gram_wire (hA i)).trans (hp i)⟩) + unfold gramColumnsProgram + exact (hh'.then hfold).congr _ + +def transposeRectData (p : ℕ×MatrixData) : MatrixData := + (List.range p.1).map (fun i => p.2.map (fun row => row.getD i 0)) + +def transposeRect : Realizes (prodCode natCode matrixCode) matrixCode transposeRectData := + let ec := prodCode natCode matrixCode + let base := first ec natCode + let rows := base.then (second natCode matrixCode) + let i := second ec natCode + let entry := (first natCode vectorCode).both (second natCode vectorCode) + let row := ((i.both rows).then (entry.then (getD ratCode 0)).mapCtx) + ((identity ec).both (first natCode matrixCode)).then row.tabulate +instance poly_transposeRect : PolyTime transposeRect := by + unfold transposeRect + apply poly_then + +lemma transposeRect_data {n m : ℕ} (A : Matrix (Fin n) (Fin m) ℚ) : + transposeRectData (m,matrixData A)=matrixData Aᵀ := by + simp only [transposeRectData,range_map_fin,matrixData,List.map_ofFn,Function.comp_def] + apply congrArg List.ofFn + funext i + apply congrArg List.ofFn + funext j + exact getD_ofFn (A j) i 0 + +lemma gramColumns_transpose (a : MatrixObject) : + transposeRectData (a.1,(RationalGram.factorColumns a.1 a.2).map List.ofFn)= + matrixData (RationalGram.factorMatrix a.2) := by + have hs : (RationalGram.factorColumns a.1 a.2).map List.ofFn= + matrixData (RationalGram.factorMatrix a.2)ᵀ := by + change (RationalGram.factorColumns a.1 a.2).map List.ofFn= + List.ofFn (fun j => List.ofFn ((RationalGram.factorColumns a.1 a.2).get j)) + have he : List.map List.ofFn (List.ofFn (RationalGram.factorColumns a.1 a.2).get)= + List.ofFn (List.ofFn ∘ (RationalGram.factorColumns a.1 a.2).get) := List.map_ofFn + simpa only [List.ofFn_get,Function.comp_def] using he + rw [hs,transposeRect_data,transpose_transpose] + +def gramMatrixProgram : Realizes matrixObjectCode matrixCode + (fun a => matrixData (RationalGram.factorMatrix a.2)) := + ((matrixDim.both gramColumnsProgram).then transposeRect).congr gramColumns_transpose + +lemma runsPoly_gramMatrix {ι : Type*} {L : ι → ℕ} (a : ι → MatrixObject) + (ha : IsPoly L (fun i => (matrixObjectCode (a i)).length)) + (hA : ∀i,((a i).2.map (fun q : ℚ => (q:ℝ))).PosSemidef) : + RunsPoly L gramMatrixProgram a := by + unfold gramMatrixProgram + apply RunsPoly.congr + exact ((RunsPoly.of_poly matrixDim a ha).both (runsPoly_gramColumns a ha hA)).then_poly transposeRect + +def whiteningProgram : Realizes matrixObjectCode matrixCode + (fun a => matrixData (GramWhitening.rationalFactor a.2)) := + rationalInverseProgram.then gramMatrixProgram + +lemma runsPoly_whitening {ι : Type*} {L : ι → ℕ} (a : ι → MatrixObject) + (ha : IsPoly L (fun i => (matrixObjectCode (a i)).length)) + (hA : ∀i,((a i).2.map (fun q : ℚ => (q:ℝ))).PosDef) : + RunsPoly L whiteningProgram a := by + have hi := runsPoly_rationalInverse a ha hA + unfold whiteningProgram + apply hi.then + apply runsPoly_gramMatrix _ hi.output + intro i + rw [RationalInverse.inverse_eq_of_cast _ (hA i),GramWhitening.cast_inverse] + exact (hA i).inv.posSemidef + +end CurrentKS.Realization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Signing/GramWhitening.lean b/lean/OAI/Combinatorics/ThinTrees/Signing/GramWhitening.lean new file mode 100644 index 0000000000000000000000000000000000000000..c387866f01d3f8690f949ad4c8a874abafc9ea60 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Signing/GramWhitening.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.RationalMatrix.Gram +import OAI.Combinatorics.ThinTrees.RationalMatrix.Inverse + +namespace OAI + +/-! Gram whitening. -/ + +section + +namespace AlgorithmicThinTrees.GramWhitening +open Matrix Finset +open scoped MatrixOrder +variable {n d m : ℕ} + +lemma congruence_mono {A B : Matrix (Fin n) (Fin n) ℝ} (h : A ≤ B) + (R : Matrix (Fin n) (Fin d) ℝ) : Rᵀ*A*R ≤ Rᵀ*B*R := by + rw [Matrix.le_iff] + have hh := (Matrix.le_iff.mp h).conjTranspose_mul_mul_same R + simpa only [conjTranspose_eq_transpose_of_trivial,Matrix.mul_sub,Matrix.sub_mul] using hh + +lemma symmetric_of_psd {A : Matrix (Fin n) (Fin n) ℝ} (hA : A.PosSemidef) : Aᵀ=A := + (isHermitian_iff_isSymm.mp hA.isHermitian).eq + +lemma projection_le_one {Q : Matrix (Fin d) (Fin d) ℝ} + (hQ : Qᵀ=Q) (hQQ : Q*Q=Q) : Q ≤ 1 := by + rw [Matrix.le_iff] + have hh := posSemidef_conjTranspose_mul_self (1-Q) + rw [conjTranspose_eq_transpose_of_trivial] at hh + have he : (1-Q)ᵀ*(1-Q) = 1-Q := by + rw [transpose_sub,transpose_one,hQ,Matrix.sub_mul,Matrix.mul_sub,Matrix.mul_sub,Matrix.one_mul,Matrix.one_mul,Matrix.mul_one,hQQ] + abel + rwa [he] at hh + +lemma normalized_covariance (P : Matrix (Fin n) (Fin n) ℝ) (hP : P.PosDef) + (R : Matrix (Fin n) (Fin d) ℝ) (hRR : R*Rᵀ=P⁻¹) : + Rᵀ*P*R ≤ 1 := by + have hPP : P⁻¹*P=1 := nonsing_inv_mul P ((isUnit_iff_isUnit_det P).mp hP.isUnit) + apply projection_le_one + · rw [transpose_mul,transpose_mul,transpose_transpose,symmetric_of_psd hP.posSemidef] + simp only [Matrix.mul_assoc] + · calc + Rᵀ*P*R*(Rᵀ*P*R) = Rᵀ*P*(R*Rᵀ)*P*R := by simp only [Matrix.mul_assoc] + _ = Rᵀ*P*R := by rw [hRR,Matrix.mul_assoc (Rᵀ*P) P⁻¹ P,hPP,Matrix.mul_one] + +lemma rectangular_norm (R : Matrix (Fin n) (Fin d) ℝ) (b : Fin n → ℝ) : + (Rᵀ*ᵥb) ⬝ᵥ (Rᵀ*ᵥb)=b ⬝ᵥ ((R*Rᵀ)*ᵥb) := by + rw [dotProduct_mulVec,vecMul_transpose,dotProduct_comm,←mulVec_mulVec,dotProduct_mulVec] + +lemma recover (P : Matrix (Fin n) (Fin n) ℝ) (hP : P.PosDef) + (R : Matrix (Fin n) (Fin d) ℝ) (hRR : R*Rᵀ=P⁻¹) : + P*R*Rᵀ=1 ∧ (P*R)*(P*R)ᵀ=P := by + have hPP : P*P⁻¹=1 := mul_nonsing_inv P ((isUnit_iff_isUnit_det P).mp hP.isUnit) + constructor + · rw [Matrix.mul_assoc,hRR,hPP] + · rw [transpose_mul,symmetric_of_psd hP.posSemidef,←Matrix.mul_assoc,Matrix.mul_assoc P R Rᵀ,hRR,hPP,Matrix.one_mul] + +lemma congruence_outer (R : Matrix (Fin n) (Fin d) ℝ) (b : Fin n → ℝ) : + vecMulVec (Rᵀ*ᵥb) (Rᵀ*ᵥb) = Rᵀ*vecMulVec b b*R := by + rw [mul_vecMulVec,vecMulVec_mul,←vecMul_transpose Rᵀ,transpose_transpose] + +lemma congruence_sum_outer (R : Matrix (Fin n) (Fin d) ℝ) + (b : Fin m → Fin n → ℝ) (A : Finset (Fin m)) : + (∑e∈A,vecMulVec (Rᵀ*ᵥb e) (Rᵀ*ᵥb e)) = Rᵀ*(∑e∈A,vecMulVec (b e) (b e))*R := by + simp only [congruence_outer,Matrix.mul_sum,Matrix.sum_mul] + +lemma cov_bound (P : Matrix (Fin n) (Fin n) ℝ) (hP : P.PosDef) + (R : Matrix (Fin n) (Fin d) ℝ) (hRR : R*Rᵀ=P⁻¹) + (b : Fin m → Fin n → ℝ) (hb : (∑e,vecMulVec (b e) (b e)) ≤ P) : + (∑e,vecMulVec (Rᵀ*ᵥb e) (Rᵀ*ᵥb e)) ≤ (1 : Matrix (Fin d) (Fin d) ℝ) := by + rw [congruence_sum_outer] + exact (congruence_mono hb R).trans (normalized_covariance P hP R hRR) + +lemma transfer (P : Matrix (Fin n) (Fin n) ℝ) (hP : P.PosDef) + (R : Matrix (Fin n) (Fin d) ℝ) (hRR : R*Rᵀ=P⁻¹) + (b : Fin m → Fin n → ℝ) (A : Finset (Fin m)) {ε : ℝ} + (h : -(ε • (1 : Matrix (Fin d) (Fin d) ℝ)) ≤ + (∑e∈A,vecMulVec (Rᵀ*ᵥb e) (Rᵀ*ᵥb e))-(1/2:ℝ) • (∑e,vecMulVec (Rᵀ*ᵥb e) (Rᵀ*ᵥb e)) ∧ + (∑e∈A,vecMulVec (Rᵀ*ᵥb e) (Rᵀ*ᵥb e))-(1/2:ℝ) • (∑e,vecMulVec (Rᵀ*ᵥb e) (Rᵀ*ᵥb e)) ≤ ε • 1) : + -(ε • P) ≤ (∑e∈A,vecMulVec (b e) (b e))-(1/2:ℝ) • (∑e,vecMulVec (b e) (b e)) ∧ + (∑e∈A,vecMulVec (b e) (b e))-(1/2:ℝ) • (∑e,vecMulVec (b e) (b e)) ≤ ε • P := by + let S := P*R + have hu := congruence_mono h.2 Sᵀ + have hl := congruence_mono h.1 Sᵀ + have hs : S*Rᵀ=1 := (recover P hP R hRR).1 + have hss : S*Sᵀ=P := (recover P hP R hRR).2 + have ht : R*Sᵀ=1 := by + have hh := congrArg transpose hs + simpa only [transpose_mul,transpose_transpose,transpose_one] using hh + have simplify (F : Matrix (Fin n) (Fin n) ℝ) : S*(Rᵀ*F*R)*Sᵀ=F := by + rw [Matrix.mul_assoc Rᵀ F R,←Matrix.mul_assoc S Rᵀ,hs,Matrix.one_mul,Matrix.mul_assoc,ht,Matrix.mul_one] + simp only [transpose_transpose,congruence_sum_outer,Matrix.mul_sub,Matrix.sub_mul,Matrix.mul_smul, + Matrix.smul_mul,Matrix.mul_one,simplify,hss,Matrix.mul_neg,Matrix.neg_mul] at hu hl + exact ⟨hl,hu⟩ + +def rationalFactor (P : Matrix (Fin n) (Fin n) ℚ) := + RationalGram.factorMatrix (RationalInverse.inverse n P) + +lemma cast_inverse (P : Matrix (Fin n) (Fin n) ℚ) : + (P⁻¹).map (fun q : ℚ => (q:ℝ)) = (P.map (fun q : ℚ => (q:ℝ)))⁻¹ := by + have hadj : P.adjugate.map (fun q : ℚ => (q:ℝ)) = + (P.map (fun q : ℚ => (q:ℝ))).adjugate := (Rat.castHom ℝ).map_adjugate P + rw [Matrix.inv_def,Matrix.inv_def,Ring.inverse_eq_inv,Ring.inverse_eq_inv] + ext i j + simp only [map_apply,Matrix.smul_apply,smul_eq_mul,Rat.cast_mul,Rat.cast_inv] + rw [←Rat.cast_det] + have hh := congrFun (congrFun hadj i) j + exact congrArg ((P.det:ℝ)⁻¹ * ·) hh + +lemma rationalFactor_correct (P : Matrix (Fin n) (Fin n) ℚ) + (hP : (P.map (fun q : ℚ => (q:ℝ))).PosDef) : + (rationalFactor P).map (fun q : ℚ => (q:ℝ)) * + ((rationalFactor P).map (fun q : ℚ => (q:ℝ)))ᵀ = (P.map (fun q : ℚ => (q:ℝ)))⁻¹ := by + unfold rationalFactor + rw [RationalInverse.inverse_eq_of_cast P hP] + have hInv : (P⁻¹.map (fun q : ℚ => (q:ℝ))).PosSemidef := by + rw [cast_inverse]; exact hP.inv.posSemidef + have hh := congrArg (fun M => M.map (fun q : ℚ => (q:ℝ))) + (RationalGram.factorMatrix_correct P⁻¹ hInv) + change (RationalGram.factorMatrix P⁻¹ * (RationalGram.factorMatrix P⁻¹)ᵀ).map + (Rat.castHom ℝ) = _ at hh + rw [Matrix.map_mul] at hh + exact hh.trans (cast_inverse P) + +end AlgorithmicThinTrees.GramWhitening +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Signing/RationalSigning.lean b/lean/OAI/Combinatorics/ThinTrees/Signing/RationalSigning.lean new file mode 100644 index 0000000000000000000000000000000000000000..62d8caa30129dadeaffd7245e4d5a54abd16d7a2 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Signing/RationalSigning.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Optimization.Outside +import OAI.Combinatorics.ThinTrees.Normalization.Realization +import OAI.Combinatorics.ThinTrees.Signing.RealMatrixBridge + +namespace OAI + +/-! Rational signing. -/ + +section + +namespace AlgorithmicThinTrees.RationalSigning +open Matrix Finset CurrentKS +open RealMatrixBridge +open scoped MatrixOrder ComplexOrder +variable {d m : ℕ} + +def entry (q : ℚ) : RationalEntry := ⟨q.num,q.den,q.den_pos⟩ + +lemma entry_value (q : ℚ) : (entry q).value=q := by + exact q.num_div_den + +def input (v : Fin m → Fin d → ℚ) : CurrentKS.Input where + d := d + N := m + entries e i j := (entry (v e i*v e j),entry 0) + +def selected (v : Fin m → Fin d → ℚ) : Finset (Fin m) := + univ.filter (fun e => (CurrentKS.RationalInput.signing (input v)).getD e.val false) + +def realVec (v : Fin m → Fin d → ℚ) : Fin m → Fin d → ℝ := fun e i => (v e i:ℝ) + +noncomputable def outer (v : Fin m → Fin d → ℚ) (e : Fin m) := + vecMulVec (realVec v e) (realVec v e) + +lemma input_matrix (v : Fin m → Fin d → ℚ) (e : Fin m) : + (input v).matrix e=complexMatrix (outer v e) := by + change (fun i j => CurrentKS.toComplex (entry (v e i*v e j),entry 0)) = + complexMatrix (outer v e) + ext i j + apply Complex.ext <;> + simp [CurrentKS.toComplex,entry_value,outer,realVec,complexMatrix,vecMulVec_apply] + +lemma complex_outer (u : Fin d → ℝ) : + complexMatrix (vecMulVec u u)=vecMulVec (fun i => (u i:ℂ)) (star (fun i => (u i:ℂ))) := by + ext i j + simp [complexMatrix,vecMulVec_apply] + +lemma input_admissible (v : Fin m → Fin d → ℚ) : CurrentKS.Admissible (input v) := by + intro e + change Fin m at e + rw [input_matrix,outer,complex_outer] + exact ⟨(posSemidef_vecMulVec_self_star _).isHermitian,rank_vecMulVec_le _ _⟩ + +lemma outer_psd (v : Fin m → Fin d → ℚ) (e : Fin m) : (outer v e).PosSemidef := by + simpa only [outer,star_trivial] using posSemidef_vecMulVec_self_star (realVec v e) + +lemma outer_square (v : Fin m → Fin d → ℚ) (e : Fin m) : + outer v e*outer v e=(realVec v e ⬝ᵥ realVec v e) • outer v e := by + rw [outer,vecMulVec_mul_vecMulVec] + ext i j + simp only [vecMulVec_apply,Pi.smul_apply,Matrix.smul_apply,smul_eq_mul] + ring + +lemma complexMatrix_sum {ι : Type*} (s : Finset ι) (A : ι → Matrix (Fin d) (Fin d) ℝ) : + complexMatrix (∑e∈s, A e)=∑e∈s, complexMatrix (A e) := by + ext i j + simp only [complexMatrix,map_apply,Matrix.sum_apply,Complex.ofReal_sum] + +lemma variance_eq (v : Fin m → Fin d → ℚ) : + variance (input v)=complexMatrix (∑e, (realVec v e ⬝ᵥ realVec v e) • outer v e) := by + have hm (e : Fin m) := input_matrix v e + dsimp only [input] at hm + simp only [variance,input] + simp only [hm] + change (∑e : Fin m, complexMatrix (outer v e)*complexMatrix (outer v e)) = _ + simp only [←complexMatrix_mul,outer_square,complexMatrix_sum] + +lemma scalar_order {A B : Matrix (Fin d) (Fin d) ℝ} (h : A ≤ B) {c : ℝ} (hc : 0 ≤ c) : + c • A ≤ c • B := by + rw [Matrix.le_iff,←smul_sub] + exact (Matrix.le_iff.mp h).smul hc + +lemma variance_bound (v : Fin m → Fin d → ℚ) {δ c : ℝ} (hδ : 0 ≤ δ) (hc : 0 ≤ c) + (hcov : (∑e, outer v e) ≤ c • (1 : Matrix (Fin d) (Fin d) ℝ)) + (hnorm : ∀e, realVec v e ⬝ᵥ realVec v e ≤ δ) : + opNorm (variance (input v)) ≤ c*δ := by + rw [variance_eq] + have hp : (∑e, (realVec v e ⬝ᵥ realVec v e) • outer v e).PosSemidef := by + refine Matrix.posSemidef_sum _ ?_ + intro e _ + exact (outer_psd v e).smul (by unfold dotProduct;exact sum_nonneg (fun e _ => mul_self_nonneg _)) + apply norm_le_of_psd_bound hp (mul_nonneg hc hδ) + have hle : (∑e, (realVec v e ⬝ᵥ realVec v e) • outer v e) ≤ δ • (∑e, outer v e) := by + rw [smul_sum] + apply sum_le_sum + intro e _ + rw [Matrix.le_iff,←sub_smul] + exact (outer_psd v e).smul (sub_nonneg.mpr (hnorm e)) + exact hle.trans ((scalar_order hcov hδ).trans_eq (by rw [smul_smul,mul_comm δ c])) + +lemma signed_eq (v : Fin m → Fin d → ℚ) (bits : List Bool) : + CurrentKS.signedSum (input v) bits=complexMatrix + (∑e, CurrentKS.signValue (bits.getD e.val false) • outer v e) := by + have hm (e : Fin m) := input_matrix v e + dsimp only [input] at hm + simp only [signedSum,input] + simp only [hm,complexMatrix_sum,complexMatrix_smul] + rfl + +lemma half_identity (v : Fin m → Fin d → ℚ) : + (∑e∈selected v, outer v e)-(1/2:ℝ) • (∑e,outer v e)= + (1/2:ℝ) • (∑e, CurrentKS.signValue + ((CurrentKS.RationalInput.signing (input v)).getD e.val false) • outer v e) := by + rw [selected,sum_filter,smul_sum,smul_sum,←sum_sub_distrib] + apply sum_congr rfl + intro e _ + cases (CurrentKS.RationalInput.signing (input v)).getD e.val false <;> + simp only [Bool.false_eq_true,ite_false,ite_true,signValue,smul_smul] <;> module + +theorem half_bounds (v : Fin m → Fin d → ℚ) {δ c : ℝ} (hδ : 0 ≤ δ) (hc : 0 ≤ c) + (hcov : (∑e,outer v e) ≤ c • (1 : Matrix (Fin d) (Fin d) ℝ)) + (hnorm : ∀e, realVec v e ⬝ᵥ realVec v e ≤ δ) : + let D := (∑e∈selected v,outer v e)-(1/2:ℝ) • (∑e,outer v e) + (-(20*Real.sqrt (c*δ))) • (1 : Matrix (Fin d) (Fin d) ℝ) ≤ D ∧ + D ≤ (20*Real.sqrt (c*δ)) • 1 := by + let bits := CurrentKS.RationalInput.signing (input v) + have hsign := (CurrentKS.RationalInput.signing_good (input v) (input_admissible v)).2 + have hvar := variance_bound v hδ hc hcov hnorm + have hnorm' : opNorm (complexMatrix (∑e,CurrentKS.signValue (bits.getD e.val false) • outer v e)) ≤ + 40*Real.sqrt (c*δ) := by + rw [←signed_eq] + exact hsign.trans (mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hvar) (by norm_num)) + have hH : (∑e,CurrentKS.signValue (bits.getD e.val false) • outer v e).IsHermitian := by + change (∑e,CurrentKS.signValue (bits.getD e.val false) • outer v e)ᴴ = _ + rw [conjTranspose_sum] + apply sum_congr rfl + intro e _ + exact (outer_psd v e).isHermitian.smul (isSelfAdjoint_iff.mpr (star_trivial _)) + obtain ⟨hl,hu⟩ := bounds_of_norm_le hH hnorm' + dsimp only + rw [half_identity] + have hhalf : (0:ℝ) ≤ 1/2 := by norm_num + constructor + · convert scalar_order hl hhalf using 1 + rw [smul_smul] + congr 1 + ring + · convert scalar_order hu hhalf using 1 + rw [smul_smul] + congr 1 + ring + +end AlgorithmicThinTrees.RationalSigning +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Signing/RealMatrixBridge.lean b/lean/OAI/Combinatorics/ThinTrees/Signing/RealMatrixBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..0326793db51d4bc349328599ca4719e0fa91cc61 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Signing/RealMatrixBridge.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Realization.FaceQueryRealization + +namespace OAI + +/-! Real matrix bridge. -/ + +section + +namespace AlgorithmicThinTrees.RealMatrixBridge +noncomputable section +open Matrix CurrentKS +open scoped MatrixOrder ComplexOrder Matrix.Norms.L2Operator +variable {n m d : ℕ} + +def complexMatrix (A : Matrix (Fin n) (Fin m) ℝ) : Matrix (Fin n) (Fin m) ℂ := + A.map Complex.ofReal + +lemma complexMatrix_one : complexMatrix (1 : Matrix (Fin n) (Fin n) ℝ)=1 := by + exact Matrix.map_one _ Complex.ofReal_zero Complex.ofReal_one + +lemma complexMatrix_add (A B : Matrix (Fin n) (Fin m) ℝ) : + complexMatrix (A+B)=complexMatrix A+complexMatrix B := by + ext i j;simp [complexMatrix] + +lemma complexMatrix_sub (A B : Matrix (Fin n) (Fin m) ℝ) : + complexMatrix (A-B)=complexMatrix A-complexMatrix B := by + ext i j;simp [complexMatrix] + +lemma complexMatrix_smul (r : ℝ) (A : Matrix (Fin n) (Fin m) ℝ) : + complexMatrix (r • A)=r • complexMatrix A := by + ext i j;simp [complexMatrix] + +lemma complexMatrix_mul (A : Matrix (Fin n) (Fin d) ℝ) (B : Matrix (Fin d) (Fin m) ℝ) : + complexMatrix (A*B)=complexMatrix A*complexMatrix B := by + exact Matrix.map_mul (f:=Complex.ofRealHom) + +lemma complexMatrix_transpose (A : Matrix (Fin n) (Fin m) ℝ) : + complexMatrix Aᵀ=(complexMatrix A)ᴴ := by + ext i j;simp [complexMatrix] + +lemma complexMatrix_hermitian {A : Matrix (Fin n) (Fin n) ℝ} (hA : A.IsHermitian) : + (complexMatrix A).IsHermitian := by + apply hA.map + intro r + simp + +lemma complexMatrix_psd {A : Matrix (Fin n) (Fin n) ℝ} (hA : A.PosSemidef) : + (complexMatrix A).PosSemidef := by + obtain ⟨B,hB⟩ := CStarAlgebra.nonneg_iff_eq_star_mul_self.mp hA.nonneg + rw [hB] + change (complexMatrix (Bᴴ*B)).PosSemidef + rw [conjTranspose_eq_transpose_of_trivial,complexMatrix_mul,complexMatrix_transpose] + exact posSemidef_conjTranspose_mul_self _ + +lemma of_complexMatrix_psd {A : Matrix (Fin n) (Fin n) ℝ} + (hA : (complexMatrix A).PosSemidef) : A.PosSemidef := by + apply PosSemidef.of_dotProduct_mulVec_nonneg + · apply isHermitian_iff_isSymm.mpr + ext i j + have hh := hA.isHermitian.apply i j + have hr := congrArg Complex.re hh + simpa [complexMatrix] using hr + · intro x + have hh := hA.dotProduct_mulVec_nonneg (fun i => (x i:ℂ)) + have he : star (fun i => (x i:ℂ)) ⬝ᵥ + (complexMatrix A *ᵥ (fun i => (x i:ℂ)))=((x ⬝ᵥ (A*ᵥx):ℝ):ℂ) := by + simp only [dotProduct,mulVec,complexMatrix,map_apply,Pi.star_apply, + Complex.star_def,Complex.conj_ofReal,Complex.ofReal_sum,Complex.ofReal_mul] + rw [he,Complex.zero_le_real] at hh + simpa only [star_trivial] using hh + +lemma complexMatrix_mono {A B : Matrix (Fin n) (Fin n) ℝ} (h : A ≤ B) : + complexMatrix A ≤ complexMatrix B := by + rw [Matrix.le_iff,←complexMatrix_sub] + exact complexMatrix_psd h + +lemma of_complexMatrix_le {A B : Matrix (Fin n) (Fin n) ℝ} + (h : complexMatrix A ≤ complexMatrix B) : A ≤ B := by + apply of_complexMatrix_psd + rw [complexMatrix_sub] + exact h + +lemma le_norm_identity {A : Matrix (Fin n) (Fin n) ℝ} (hh : A.IsHermitian) : + A ≤ opNorm (complexMatrix A) • (1 : Matrix (Fin n) (Fin n) ℝ) := by + apply of_complexMatrix_le + rw [complexMatrix_smul,complexMatrix_one] + exact Hermitian.le_operatorNorm_smul_one ⟨complexMatrix A,complexMatrix_hermitian hh⟩ + +lemma norm_le_of_psd_bound {A : Matrix (Fin n) (Fin n) ℝ} (hA : A.PosSemidef) + {r : ℝ} (hr : 0 ≤ r) (h : A ≤ r • (1 : Matrix (Fin n) (Fin n) ℝ)) : + opNorm (complexMatrix A) ≤ r := by + apply Hermitian.operatorNorm_le_of_psd_le (A:=⟨complexMatrix A,complexMatrix_hermitian hA.isHermitian⟩) + (complexMatrix_psd hA) hr + have hh := complexMatrix_mono h + rwa [complexMatrix_smul,complexMatrix_one] at hh + +lemma bounds_of_norm_le {A : Matrix (Fin n) (Fin n) ℝ} (hA : A.IsHermitian) + {r : ℝ} (h : opNorm (complexMatrix A) ≤ r) : + (-r) • (1 : Matrix (Fin n) (Fin n) ℝ) ≤ A ∧ A ≤ r • 1 := by + have hs {s t : ℝ} (hst : s ≤ t) : s • (1 : Matrix (Fin n) (Fin n) ℝ) ≤ t • 1 := by + rw [Matrix.le_iff,←sub_smul] + exact PosSemidef.one.smul (sub_nonneg.mpr hst) + constructor + · have hh := le_norm_identity hA.neg + have hn : opNorm (complexMatrix (-A))=opNorm (complexMatrix A) := by + have he : complexMatrix (-A)=-complexMatrix A := by ext i j;simp [complexMatrix] + rw [he,opNorm,map_neg,norm_neg] + rfl + rw [hn] at hh + have hu := hh.trans (hs h) + have hl := neg_le_neg hu + simpa only [neg_neg,neg_smul] using hl + · exact (le_norm_identity hA).trans (hs h) + +end +end AlgorithmicThinTrees.RealMatrixBridge +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Signing/Realization.lean b/lean/OAI/Combinatorics/ThinTrees/Signing/Realization.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d8ad3359a543b3a57c73fd2601ce0d25e1f0326 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Signing/Realization.lean @@ -0,0 +1,272 @@ +import Mathlib +import OAI.Analysis.MatrixSigning.Complexity.PolynomialOriginalSigning +import OAI.Combinatorics.ThinTrees.Signing.FormSigning +import OAI.Combinatorics.ThinTrees.Signing.GramRealization + +namespace OAI + +/-! Signing realization. -/ + +section + +namespace AlgorithmicThinTrees.Signing.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix + +structure Frame where + d : ℕ + m : ℕ + v : Fin m → Fin d → ℚ + +abbrev frameDataCode := prodCode natCode matrixCode +def Frame.data (a : Frame) := (a.d,matrixData a.v) +def frameCode (a : Frame) : Word := frameDataCode a.data +abbrev frameView : Realizes frameCode frameDataCode Frame.data := + (identity frameDataCode).reindex frameCode Frame.data (fun _ => rfl) +private instance poly_frameView : PolyTime frameView := by + unfold frameView + apply poly_reindex + +abbrev frameDim := frameView.then (first natCode matrixCode) +abbrev frameRows := frameView.then (second natCode matrixCode) +private instance poly_frameDim : PolyTime frameDim := by + unfold frameDim + apply poly_then + +private instance poly_frameRows : PolyTime frameRows := by + unfold frameRows + apply poly_then + +def complexField : Realizes ratCode vectorCode (fun q => [q,0]) := + ((identity ratCode).both (constant ratCode vectorCode [0])).then (consList ratCode) +instance poly_complexField : PolyTime complexField := by unfold complexField;infer_instance + +def outerFields : Realizes vectorCode vectorCode + (fun xs : List ℚ => (xs.map (fun q => + (xs.map (fun r => [q*r,0])).flatten)).flatten) := + ((Normalization.Stack.outer.then complexField.map.map).then (joinList vectorCode)).then + (joinList ratCode) |>.congr (by + intro xs + simp only [List.map_map,Function.comp_def,List.flatten_flatten]) +instance poly_outerFields : PolyTime outerFields := by unfold outerFields;infer_instance + +lemma outerFields_data {d m : ℕ} (v : Fin m → Fin d → ℚ) (e : Fin m) : + ((List.ofFn (v e)).map (fun q => + ((List.ofFn (v e)).map (fun r => [q*r,0])).flatten)).flatten= + fieldValues (RationalSigning.input v) e := by + refine Eq.trans ?_ (fieldValues_eq (RationalSigning.input v) e).symm + simp only [List.map_ofFn,Function.comp_def,RationalSigning.input,RationalSigning.entry_value] + +def signerInput : Realizes frameCode originalCode (fun a => RationalSigning.input a.v) := + (frameDim.both (frameRows.then outerFields.map)).changeOutput originalCode + (fun a => RationalSigning.input a.v) (by + intro a + change frameDataCode (a.d,_) = originalDataCode (originalData _) + congr 1 + change (a.d,_)=(a.d,List.ofFn (fieldValues (RationalSigning.input a.v))) + apply congrArg (fun xs => (a.d,xs)) + change (matrixData a.v).map _ = _ + change (List.ofFn (fun e => List.ofFn (a.v e))).map _ = _ + rw [List.map_ofFn] + exact congrArg List.ofFn (funext (outerFields_data a.v))) +instance poly_signerInput : PolyTime signerInput := by + unfold signerInput + apply poly_changeOutput + +def signs : Realizes frameCode (listCode boolCode) + (fun a => CurrentKS.RationalInput.signing (RationalSigning.input a.v)) := + signerInput.then originalSigningFramed + +lemma runsPoly_signs {ι : Type*} {L : ι → ℕ} (a : ι → Frame) + (ha : IsPoly L (fun i => (frameCode (a i)).length)) : RunsPoly L signs a := by + have hi := RunsPoly.of_poly signerInput a ha + exact hi.then (runsPoly_originalSigningFramed _ hi.output + (fun i => RationalSigning.input_admissible (a i).v)) + +structure FormFrame where + form : MatrixObject + m : ℕ + v : Fin m → Fin form.1 → ℚ + +abbrev formDataCode := prodCode matrixObjectCode matrixCode +def FormFrame.data (a : FormFrame) := (a.form,matrixData a.v) +def formCode (a : FormFrame) : Word := formDataCode a.data +abbrev formView : Realizes formCode formDataCode FormFrame.data := + (identity formDataCode).reindex formCode FormFrame.data (fun _ => rfl) +private instance poly_formView : PolyTime formView := by + unfold formView + apply poly_reindex + +abbrev formMatrix := formView.then (first matrixObjectCode matrixCode) +abbrev formRows := formView.then (second matrixObjectCode matrixCode) + +lemma factorColumns_data (a : MatrixObject) : + (RationalGram.factorColumns a.1 a.2).map List.ofFn= + matrixData (RationalGram.factorMatrix a.2)ᵀ := by + change (RationalGram.factorColumns a.1 a.2).map List.ofFn= + List.ofFn (fun i => List.ofFn ((RationalGram.factorColumns a.1 a.2).get i)) + have he : List.map List.ofFn (List.ofFn (RationalGram.factorColumns a.1 a.2).get)= + List.ofFn (List.ofFn ∘ (RationalGram.factorColumns a.1 a.2).get) := List.map_ofFn + simpa only [List.ofFn_get,Function.comp_def] using he + +def factorRows : Realizes matrixObjectCode matrixCode + (fun a => matrixData (GramWhitening.rationalFactor a.2)ᵀ) := + (rationalInverseProgram.then gramColumnsProgram).congr + (fun a => factorColumns_data ⟨a.1,RationalInverse.inverse a.1 a.2⟩) + +lemma runsPoly_factorRows {ι : Type*} {L : ι → ℕ} (a : ι → MatrixObject) + (ha : IsPoly L (fun i => (matrixObjectCode (a i)).length)) + (hA : ∀i,((a i).2.map (fun q : ℚ => (q:ℝ))).PosDef) : + RunsPoly L factorRows a := by + have hi := runsPoly_rationalInverse a ha hA + unfold factorRows + apply RunsPoly.congr + apply hi.then + apply runsPoly_gramColumns _ hi.output + intro i + rw [RationalInverse.inverse_eq_of_cast _ (hA i),GramWhitening.cast_inverse] + exact (hA i).inv.posSemidef + +def FormFrame.whiten (a : FormFrame) : Frame := + ⟨(RationalGram.factorColumns a.form.1 (RationalInverse.inverse a.form.1 a.form.2)).length, + a.m,FormSigning.whiten a.form.2 a.v⟩ + +def whiten : Realizes formCode frameCode FormFrame.whiten := + let R := formMatrix.then factorRows + let cols := (R.both formRows).then matVec.mapCtx + ((R.then (lengthList vectorCode)).both cols).changeOutput frameCode FormFrame.whiten (by + intro a + change frameDataCode (_,_) = frameDataCode (Frame.data _) + congr 1 + dsimp only [FormFrame.data,Frame.data,FormFrame.whiten] + refine Prod.ext (List.length_ofFn) ?_ + change List.map _ (List.ofFn (fun e => List.ofFn (a.v e)))=matrixData _ + rw [List.map_ofFn] + simp only [Function.comp_def,matVec_data] + rfl) + +lemma runsPoly_whiten {ι : Type*} {L : ι → ℕ} (a : ι → FormFrame) + (ha : IsPoly L (fun i => (formCode (a i)).length)) + (hA : ∀i,((a i).form.2.map (fun q : ℚ => (q:ℝ))).PosDef) : + RunsPoly L whiten a := by + have : PolyTime formMatrix := by + unfold formMatrix + apply poly_then + have : PolyTime formRows := by + unfold formRows + apply poly_then + have hf := RunsPoly.of_poly formMatrix a ha + have hr := hf.then (runsPoly_factorRows _ hf.output hA) + have hc := (hr.both (RunsPoly.of_poly formRows a ha)).then_poly matVec.mapCtx + unfold whiten + apply RunsPoly.changeOutput + exact (hr.then_poly (lengthList vectorCode)).both hc + +structure FramePair where + a : ℕ + b : ℕ + m : ℕ + u : Fin m → Fin a → ℚ + v : Fin m → Fin b → ℚ + +def FramePair.left (a : FramePair) : Frame := ⟨a.a,a.m,a.u⟩ +def FramePair.right (a : FramePair) : Frame := ⟨a.b,a.m,a.v⟩ +def FramePair.stack (a : FramePair) : Frame := + ⟨a.a+a.b,a.m,fun e => StackedSigning.stack (a.u e) (a.v e)⟩ +def pairCode (a : FramePair) : Word := prodCode frameCode frameCode (a.left,a.right) +abbrev pairView : Realizes pairCode (prodCode frameCode frameCode) + (fun a => (a.left,a.right)) := + (identity (prodCode frameCode frameCode)).reindex pairCode + (fun a => (a.left,a.right)) (fun _ => rfl) +private instance poly_pairView : PolyTime pairView := by + unfold pairView + apply poly_reindex + +abbrev pairLeft := pairView.then (first frameCode frameCode) +abbrev pairRight := pairView.then (second frameCode frameCode) + +lemma stack_data {a b : ℕ} (u : Fin a → ℚ) (v : Fin b → ℚ) : + List.ofFn u++List.ofFn v=List.ofFn (StackedSigning.stack u v) := by + rw [List.ofFn_add] + change List.ofFn u++List.ofFn v= + (List.ofFn (fun i => StackedSigning.stack u v (Fin.castAdd b i)))++ + (List.ofFn (fun i => StackedSigning.stack u v (Fin.natAdd a i))) + simp only [StackedSigning.stack_left,StackedSigning.stack_right] + +def stack : Realizes pairCode frameCode FramePair.stack := + let dims := ((pairLeft.then frameDim).both (pairRight.then frameDim)).then natAdd + let rows := ((pairLeft.then frameRows).both (pairRight.then frameRows)).then + ((appendList ratCode).zipWith [] []) + (dims.both rows).changeOutput frameCode FramePair.stack (by + intro a + change frameDataCode (_,_) = frameDataCode _ + congr 1 + change (a.a+a.b,zipDefault (fun p : List ℚ × List ℚ => p.1 ++ p.2) [] [] + (List.ofFn (fun i : Fin a.m => List.ofFn (a.u i)), + List.ofFn (fun i : Fin a.m => List.ofFn (a.v i)))) = + (a.a+a.b,List.ofFn (fun i : Fin a.m => List.ofFn (StackedSigning.stack (a.u i) (a.v i)))) + rw [zipDefault_ofFn] + simp only [stack_data]) +instance poly_stack : PolyTime stack := by + have : PolyTime pairLeft := by unfold pairLeft; apply poly_then + have : PolyTime pairRight := by unfold pairRight; apply poly_then + unfold stack + apply poly_changeOutput + +structure FormPair where + a : MatrixObject + b : MatrixObject + m : ℕ + u : Fin m → Fin a.1 → ℚ + v : Fin m → Fin b.1 → ℚ + +def FormPair.left (p : FormPair) : FormFrame := ⟨p.a,p.m,p.u⟩ +def FormPair.right (p : FormPair) : FormFrame := ⟨p.b,p.m,p.v⟩ +def FormPair.whiten (p : FormPair) : FramePair := + ⟨p.left.whiten.d,p.right.whiten.d,p.m,p.left.whiten.v,p.right.whiten.v⟩ +def formsCode (p : FormPair) : Word := prodCode formCode formCode (p.left,p.right) +abbrev formsView : Realizes formsCode (prodCode formCode formCode) + (fun p => (p.left,p.right)) := + (identity (prodCode formCode formCode)).reindex formsCode + (fun p => (p.left,p.right)) (fun _ => rfl) +private instance poly_formsView : PolyTime formsView := by + unfold formsView + apply poly_reindex + +abbrev formsLeft := formsView.then (first formCode formCode) +abbrev formsRight := formsView.then (second formCode formCode) + +def whitenPair : Realizes formsCode pairCode FormPair.whiten := + ((formsLeft.then whiten).both (formsRight.then whiten)).changeOutput + pairCode FormPair.whiten (fun _ => rfl) + +def simultaneousSigns : Realizes formsCode (listCode boolCode) + (fun p => CurrentKS.RationalInput.signing (RationalSigning.input + (fun e => StackedSigning.stack (FormSigning.whiten p.a.2 p.u e) + (FormSigning.whiten p.b.2 p.v e)))) := + whitenPair.then (stack.then signs) + +lemma runsPoly_simultaneousSigns {ι : Type*} {L : ι → ℕ} (a : ι → FormPair) + (ha : IsPoly L (fun i => (formsCode (a i)).length)) + (hA : ∀i,((a i).a.2.map (fun q : ℚ => (q:ℝ))).PosDef) + (hB : ∀i,((a i).b.2.map (fun q : ℚ => (q:ℝ))).PosDef) : + RunsPoly L simultaneousSigns a := by + have : PolyTime formsLeft := by + unfold formsLeft + apply poly_then + have : PolyTime formsRight := by + unfold formsRight + apply poly_then + have hu := RunsPoly.of_poly formsLeft a ha + have hv := RunsPoly.of_poly formsRight a ha + have hw : RunsPoly L whitenPair a := by + unfold whitenPair + apply RunsPoly.changeOutput + exact (hu.then (runsPoly_whiten _ hu.output hA)).both + (hv.then (runsPoly_whiten _ hv.output hB)) + have hs := hw.then_poly stack + exact hw.then ((RunsPoly.of_poly stack _ hw.output).then (runsPoly_signs _ hs.output)) + +end AlgorithmicThinTrees.Signing.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Signing/StackedSigning.lean b/lean/OAI/Combinatorics/ThinTrees/Signing/StackedSigning.lean new file mode 100644 index 0000000000000000000000000000000000000000..01f04d95e703ba891d22a484885cb5006bae693c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Signing/StackedSigning.lean @@ -0,0 +1,149 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Signing.RationalSigning + +namespace OAI + +/-! Stacked signing. -/ + +section + +namespace AlgorithmicThinTrees.StackedSigning +open Matrix Finset +open scoped MatrixOrder +variable {a b m : ℕ} + +def stack {K : Type*} (u : Fin a → K) (v : Fin b → K) : Fin (a+b) → K := + Fin.addCases u v + +@[simp] lemma stack_left {K : Type*} (u : Fin a → K) (v : Fin b → K) (i : Fin a) : + stack u v (Fin.castAdd b i)=u i := Fin.addCases_left i + +@[simp] lemma stack_right {K : Type*} (u : Fin a → K) (v : Fin b → K) (i : Fin b) : + stack u v (Fin.natAdd a i)=v i := Fin.addCases_right i + +lemma dot_stack (x : Fin (a+b) → ℝ) (u : Fin a → ℝ) (v : Fin b → ℝ) : + x ⬝ᵥ stack u v = (fun i => x (Fin.castAdd b i)) ⬝ᵥ u + + (fun i => x (Fin.natAdd a i)) ⬝ᵥ v := by + simp only [dotProduct,Fin.sum_univ_add,stack_left,stack_right] + +lemma stack_norm (u : Fin a → ℝ) (v : Fin b → ℝ) : + stack u v ⬝ᵥ stack u v=u ⬝ᵥ u+v ⬝ᵥ v := by + simp only [dot_stack,stack_left,stack_right] + +def gram {d : ℕ} (v : Fin m → Fin d → ℝ) (A : Finset (Fin m)) : Matrix (Fin d) (Fin d) ℝ := + ∑e∈A, vecMulVec (v e) (v e) + +lemma gram_psd {d : ℕ} (v : Fin m → Fin d → ℝ) (A : Finset (Fin m)) : + (gram v A).PosSemidef := by + apply Matrix.posSemidef_sum + intro e _ + simpa only [star_trivial] using posSemidef_vecMulVec_self_star (v e) + +lemma gram_eval {d : ℕ} (v : Fin m → Fin d → ℝ) (A : Finset (Fin m)) (x : Fin d → ℝ) : + x ⬝ᵥ (gram v A*ᵥx)=∑e∈A,(x ⬝ᵥ v e)^2 := by + simp only [gram,Matrix.sum_mulVec,dotProduct_sum,vecMulVec_mulVec,dotProduct_smul] + apply sum_congr rfl + intro e _ + rw [dotProduct_comm (v e) x,pow_two] + rfl + +lemma gram_eval_le {d : ℕ} (v : Fin m → Fin d → ℝ) (A : Finset (Fin m)) + {c : ℝ} (h : gram v A ≤ c • (1 : Matrix (Fin d) (Fin d) ℝ)) (x : Fin d → ℝ) : + (∑e∈A,(x ⬝ᵥ v e)^2) ≤ c*(x ⬝ᵥ x) := by + have hh := (Matrix.le_iff.mp h).dotProduct_mulVec_nonneg x + simp only [star_trivial,Matrix.sub_mulVec,dotProduct_sub,Matrix.smul_mulVec,Matrix.one_mulVec, + dotProduct_smul,smul_eq_mul,gram_eval] at hh + linarith only [hh] + +lemma stack_covariance (u : Fin m → Fin a → ℝ) (v : Fin m → Fin b → ℝ) + (hu : gram u univ ≤ 1) (hv : gram v univ ≤ 1) : + gram (fun e => stack (u e) (v e)) univ ≤ (2:ℝ) • 1 := by + rw [Matrix.le_iff] + apply PosSemidef.of_dotProduct_mulVec_nonneg + · exact (Matrix.PosSemidef.one.smul (by norm_num : (0:ℝ) ≤ 2)).isHermitian.sub + (gram_psd _ _).isHermitian + intro x + simp only [star_trivial,Matrix.sub_mulVec,dotProduct_sub,Matrix.smul_mulVec,Matrix.one_mulVec, + dotProduct_smul,smul_eq_mul,gram_eval] + have h1 := gram_eval_le u univ (c:=1) (by simpa only [one_smul] using hu) + (fun i => x (Fin.castAdd b i)) + have h2 := gram_eval_le v univ (c:=1) (by simpa only [one_smul] using hv) + (fun i => x (Fin.natAdd a i)) + have hs : (∑e : Fin m, (x ⬝ᵥ stack (u e) (v e))^2) ≤ + 2*(∑e : Fin m, ((fun i => x (Fin.castAdd b i)) ⬝ᵥ u e)^2)+ + 2*(∑e : Fin m, ((fun i => x (Fin.natAdd a i)) ⬝ᵥ v e)^2) := by + rw [mul_sum,mul_sum,←sum_add_distrib] + apply sum_le_sum + intro e _ + rw [dot_stack] + nlinarith only [sq_nonneg (((fun i => x (Fin.castAdd b i)) ⬝ᵥ u e)- + ((fun i => x (Fin.natAdd a i)) ⬝ᵥ v e))] + have hx : x ⬝ᵥ x=(fun i => x (Fin.castAdd b i)) ⬝ᵥ (fun i => x (Fin.castAdd b i))+ + (fun i => x (Fin.natAdd a i)) ⬝ᵥ (fun i => x (Fin.natAdd a i)) := by + exact Fin.sum_univ_add _ + nlinarith only [h1,h2,hs,hx] + +lemma submatrix_mono {d e : ℕ} {A B : Matrix (Fin d) (Fin d) ℝ} (h : A ≤ B) + (f : Fin e → Fin d) : A.submatrix f f ≤ B.submatrix f f := by + rw [Matrix.le_iff] + exact (Matrix.le_iff.mp h).submatrix f + +lemma gram_submatrix {d e : ℕ} (v : Fin m → Fin d → ℝ) (A : Finset (Fin m)) + (f : Fin e → Fin d) : + (gram v A).submatrix f f=gram (fun j i => v j (f i)) A := by + ext i j + simp only [gram,submatrix_apply,Matrix.sum_apply,vecMulVec_apply] + +lemma compress_half {d e : ℕ} (v : Fin m → Fin d → ℝ) (A : Finset (Fin m)) + (f : Fin e → Fin d) (hf : Function.Injective f) {ε : ℝ} + (h : -(ε • (1 : Matrix (Fin d) (Fin d) ℝ)) ≤ gram v A-(1/2:ℝ) • gram v univ ∧ + gram v A-(1/2:ℝ) • gram v univ ≤ ε • 1) : + -(ε • (1 : Matrix (Fin e) (Fin e) ℝ)) ≤ + gram (fun j i => v j (f i)) A-(1/2:ℝ) • gram (fun j i => v j (f i)) univ ∧ + gram (fun j i => v j (f i)) A-(1/2:ℝ) • gram (fun j i => v j (f i)) univ ≤ ε • 1 := by + have h1 := submatrix_mono h.1 f + have h2 := submatrix_mono h.2 f + change -(ε • (1 : Matrix (Fin d) (Fin d) ℝ).submatrix f f) ≤ + (gram v A).submatrix f f-(1/2:ℝ) • (gram v univ).submatrix f f at h1 + change (gram v A).submatrix f f-(1/2:ℝ) • (gram v univ).submatrix f f ≤ + ε • (1 : Matrix (Fin d) (Fin d) ℝ).submatrix f f at h2 + simpa only [submatrix_one f hf,gram_submatrix] using And.intro h1 h2 + +def selected (u : Fin m → Fin a → ℚ) (v : Fin m → Fin b → ℚ) : Finset (Fin m) := + RationalSigning.selected (fun e => stack (u e) (v e)) + +lemma real_stack (u : Fin m → Fin a → ℚ) (v : Fin m → Fin b → ℚ) (e : Fin m) : + RationalSigning.realVec (fun e => stack (u e) (v e)) e= + stack (RationalSigning.realVec u e) (RationalSigning.realVec v e) := by + funext i + refine Fin.addCases (fun j => ?_) (fun j => ?_) i <;> + simp only [RationalSigning.realVec,stack_left,stack_right] + +theorem simultaneous (u : Fin m → Fin a → ℚ) (v : Fin m → Fin b → ℚ) {δ : ℝ} + (hδ : 0 ≤ δ) + (hu : gram (RationalSigning.realVec u) univ ≤ 1) + (hv : gram (RationalSigning.realVec v) univ ≤ 1) + (hnorm : ∀e, RationalSigning.realVec u e ⬝ᵥ RationalSigning.realVec u e+ + RationalSigning.realVec v e ⬝ᵥ RationalSigning.realVec v e ≤ δ) : + let A := selected u v + let ε := 20*Real.sqrt (2*δ) + (-(ε • (1 : Matrix (Fin a) (Fin a) ℝ)) ≤ + gram (RationalSigning.realVec u) A-(1/2:ℝ) • gram (RationalSigning.realVec u) univ ∧ + gram (RationalSigning.realVec u) A-(1/2:ℝ) • gram (RationalSigning.realVec u) univ ≤ ε • 1) ∧ + (-(ε • (1 : Matrix (Fin b) (Fin b) ℝ)) ≤ + gram (RationalSigning.realVec v) A-(1/2:ℝ) • gram (RationalSigning.realVec v) univ ∧ + gram (RationalSigning.realVec v) A-(1/2:ℝ) • gram (RationalSigning.realVec v) univ ≤ ε • 1) := by + have hcov := stack_covariance (RationalSigning.realVec u) (RationalSigning.realVec v) hu hv + have hs := RationalSigning.half_bounds (fun e => stack (u e) (v e)) hδ (by norm_num : (0:ℝ) ≤ 2) + (by simpa only [RationalSigning.outer,real_stack,gram] using hcov) + (fun e => by simpa only [real_stack,stack_norm] using hnorm e) + change (-(20*Real.sqrt (2*δ))) • (1 : Matrix (Fin (a+b)) (Fin (a+b)) ℝ) ≤ _ ∧ _ at hs + simp only [neg_smul] at hs + have hl := compress_half _ (selected u v) (Fin.castAdd b) (Fin.castAdd_injective a b) hs + have hr := compress_half _ (selected u v) (Fin.natAdd a) (Fin.natAdd_injective b a) hs + simpa only [real_stack,stack_left,stack_right] using And.intro hl hr + +end AlgorithmicThinTrees.StackedSigning +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/SimultaneousResponse.lean b/lean/OAI/Combinatorics/ThinTrees/SimultaneousResponse.lean new file mode 100644 index 0000000000000000000000000000000000000000..280ae4bf2af3abc577cb3237029ee2ec755b8380 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/SimultaneousResponse.lean @@ -0,0 +1,47 @@ +import OAI.Combinatorics.ThinTrees.HierarchyResponse + +namespace OAI + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder Classical +namespace StrongThinTree.MultiGraph + +theorem simultaneous_response_exists : ∃qH : ℕ, 2 ≤ qH ∧ ∀q : ℕ, qH ≤ q → + ∀(n m : ℕ) (G : MultiGraph n m), 0 < n → G.TreePackable univ q → + ∀(R : Fin m → ℝ) (t : ℝ), 0 < t → ∃Y ∈ G.matrixDomain, ∀s : ℝ, + (((univ.filter (fun e => t < G.resistance Y e)) ∩ + G.crossing univ (G.partLabel (G.thresholdEdges R s) q)).card:ℝ) ≤ + 16*((q:ℝ)^(-31/40:ℝ)/t+1/(q:ℝ)) * + (G.crossing univ (G.partLabel (G.thresholdEdges R s) q)).card := by + obtain ⟨qH,hqH,hshortcut⟩ := Hierarchy.polynomial_shortcut + refine ⟨qH,hqH,?_⟩ + intro q hq n m G hn hpack R t ht + have hqp : 0 < q := by omega + let P := G.packingChain R q + let I := insert m (Dyadic.selected (fun j => (P.crossing G j).card) m) + have hroot : P.parts m={univ} := G.packingChain_root R hn hpack + obtain ⟨H,hH⟩ := P.exists_hierarchy I ⟨m,mem_insert_self _ _,hroot ▸ mem_singleton_self _⟩ + have hlocal : H.LocallyConnectedReal G q := G.chain_locally P I H hH (fun i _ => G.packingChain_local R q i) + let M := H.nodes.filter (fun A => A ≠ univ ∧ ((G.cut univ A).card:ℝ)/q ≤ (H.parentBoundary G A).card) + obtain ⟨D,hD,hcut,havg⟩ := hshortcut q hq n m G H hlocal M (filter_subset _ _) + (fun A hA => (mem_filter.mp hA).2.1) (fun A hA => (mem_filter.mp hA).2.2) + have hc : G.EdgeConnected 1 := fun S hS hS' => (by omega : 1 ≤ q).trans (Hierarchy.edgeConnected_of_locally hlocal S hS hS') + obtain ⟨Y,hYm,hnode⟩ := G.shortcut_response hqp hn hc (Real.rpow_nonneg (Nat.cast_nonneg q) _) ht D hD hcut + (fun A hA hA' hr => havg A (mem_filter.mpr ⟨hA,hA',hr⟩)) + refine ⟨Y,hYm,fun s => ?_⟩ + have hz : (G.thresholdEdges R s).card ≤ m := by simpa using card_le_univ (G.thresholdEdges R s) + have hh := P.simultaneous_bad_bound G hroot hH (univ.filter (fun e => t < G.resistance Y e)) + (by positivity : 0 ≤ (q:ℝ)^(-31/40:ℝ)/t+1/(q:ℝ)) hnode (G.thresholdEdges R s).card hz + have heq : P.crossing G (G.thresholdEdges R s).card=G.crossing univ (G.partLabel (G.thresholdEdges R s) q) := by + rw [G.packingChain_crossing,G.rankedEdges_threshold] + simpa only [heq] using hh + +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d0c2356fee6e292e290ff0477a82b3d2321fe7a --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification.lean @@ -0,0 +1,28 @@ +import OAI.Combinatorics.ThinTrees.SparsifyGeometry + +namespace OAI + +section + +noncomputable section +open Finset +namespace StrongThinTree.MultiGraph + +theorem sparsification : ∃R : ℕ, 4 ≤ R ∧ ∀r : ℕ, R ≤ r → StepNumeric r ∧ + ∀(n m : ℕ) (G : MultiGraph n m), 2 ≤ n → G.TreePackable univ r → + ∃A : Finset (Fin m), G.TreePackable A (stepCount r) ∧ + ∀S : Finset (Fin n), S.Nonempty → S ≠ univ → + ((G.cut A S).card:ℝ) ≤ (1/2+3*splitTau r)*(G.cut univ S).card := by + obtain ⟨RE,hRE,hE⟩ := extraction + obtain ⟨RN,hN⟩ := eventual_step_numeric + refine ⟨max RE RN,hRE.trans (le_max_left _ _),fun r hr => ?_⟩ + have hn := hN r ((le_max_right _ _).trans hr) + refine ⟨hn,fun n m G hn' hp => ?_⟩ + obtain ⟨X,hX,hpack⟩ := hE r ((le_max_left _ _).trans hr) n m G hn' hp + exact G.sparsify_from_extraction hn' hn hX hpack +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/ExplicitAlgorithm.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/ExplicitAlgorithm.lean new file mode 100644 index 0000000000000000000000000000000000000000..db3ba1aca3632679aa2174c0f38a2b684330df38 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/ExplicitAlgorithm.lean @@ -0,0 +1,59 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.Specification +import OAI.Combinatorics.ThinTrees.Sparsification.IterationRealization + +namespace OAI + +/-! Explicit algorithm. -/ + +section + +namespace AlgorithmicThinTrees.Iteration +open StrongThinTree Finset GraphicHalf MetricTests.RationalStep +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 +open GraphicHalf.Stack Stack + +lemma tree_bound {R : ℕ} (hR : 4 ≤ R) (hb : RoundBound R) + (d m k : ℕ) (G : MultiGraph (d+1) m) (hn : 2 ≤ d+1) (hk : 1 ≤ k) + (hc : G.EdgeConnected k) : + G.SpanningTree (tree R k G) ∧ ∀S : Finset (Fin (d+1)), + ((G.cut (tree R k G) S).card:ℝ) ≤ + (3*R*Real.exp lossB)/(k:ℝ)*(G.cut univ S).card := by + have hRR : (0:ℝ) < R := by exact_mod_cast (show 0 < R by omega) + obtain ⟨hT,hthin⟩ := iterate_bound hR hb (initialCount k) (initialCount k) d m G + (initialCount_pos k) le_rfl hn (initial_packable G (by omega) hk hc) + refine ⟨hT,fun S => (hthin S).trans ?_⟩ + apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) + have hrR : (0:ℝ) < initialCount k := by exact_mod_cast initialCount_pos k + have hkR : (0:ℝ) < k := by exact_mod_cast hk + rw [←mul_div_assoc] + apply (div_le_div_iff₀ hrR hkR).mpr + have hrk : (k:ℝ) ≤ 3*(initialCount k:ℝ) := by exact_mod_cast initialCount_lower k + have hx := mul_le_mul_of_nonneg_left (potential_le (initialCount k)) hRR.le + have hm := mul_le_mul_of_nonneg_left hrk (mul_pos hRR (Real.exp_pos lossB)).le + have hl := mul_le_mul_of_nonneg_right hx hkR.le + nlinarith only [hm,hl] + +theorem explicit_program : ∃R : ℕ, ∃C : ℝ, 0 < C ∧ + (∀p : Problem,2 ≤ p.d+1 → 1 ≤ p.r → p.G.EdgeConnected p.r → + ThinTree C p.r p.G (tree R p.r p.G)) ∧ + (∀{ι : Type} {L : ι → ℕ} (a : ι → Problem), + IsPoly L (fun i => (problemCode (a i)).length) → + (∀i,2 ≤ (a i).d+1 ∧ 1 ≤ (a i).r ∧ (a i).G.EdgeConnected (a i).r) → + RunsPoly L (treeProgram R) a) := by + obtain ⟨R,hR,hb⟩ := sparsification_correct + obtain ⟨T,_,ht⟩ := sparsify_program_polynomial + let R' := max R T + have hR' : 4 ≤ R' := hR.trans (le_max_left _ _) + have hb' : RoundBound R' := fun r hr => hb r ((le_max_left R T).trans hr) + have hpos : (0:ℝ) < R' := by exact_mod_cast (show 0 h.2 S⟩ + · exact fun a ha hp => runsPoly_tree hR' hb' (le_max_right R T) ht a ha hp + +end AlgorithmicThinTrees.Iteration +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphCertificates.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphCertificates.lean new file mode 100644 index 0000000000000000000000000000000000000000..904d82d7d2862bd8ec86cdb7e3b81748b37651b5 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphCertificates.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Sparsification.GraphicHalf + +namespace OAI + +/-! Graph certificates. -/ + +section + +namespace AlgorithmicThinTrees.GraphicHalf +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open MetricTests Normalization RationalSigning +open scoped MatrixOrder +variable {n d m : ℕ} + +lemma qform_outer (u x : Fin n → ℝ) : qform (vecMulVec u u) x=(u ⬝ᵥ x)^2 := by + rw [qform,vecMulVec_mulVec,dotProduct_smul,op_smul_eq_smul,smul_eq_mul,dotProduct_comm x u,pow_two] + +lemma cut_test (S : Finset (Fin n)) : Test (vecMulVec (cutIndicator S) (cutIndicator S)) := by + refine ⟨ShortcutDual.outer_posSemidef _,?_⟩ + intro u v w + simp only [qform_outer,eval_difference] + rcases cutIndicator_binary S u with hu|hu <;> + rcases cutIndicator_binary S v with hv|hv <;> + rcases cutIndicator_binary S w with hw|hw <;> norm_num [hu,hv,hw] + +lemma trace_mul_centered (D Z : Matrix (Fin n) (Fin n) ℝ) : + (D*centered Z).trace=(centered D*Z).trace := by + simp only [centered] + rw [←Matrix.mul_assoc,←Matrix.mul_assoc,trace_mul_comm (D*centering n*Z), + ←Matrix.mul_assoc (centering n)] + simp only [Matrix.mul_assoc] + +lemma centered_laplacian (G : MultiGraph n m) (A : Finset (Fin m)) : + centered (G.laplacian A)=G.laplacian A := by + apply centered_eq (G.laplacian_psd A).isHermitian + simp only [laplacian,Matrix.sum_mulVec] + apply sum_eq_zero + intro e _ + rw [vecMulVec_mulVec] + have he : G.incidence e ⬝ᵥ ones n=0 := by + simp only [dotProduct,ones,mul_one] + exact (mem_zeroSumSpace _).mp (G.incidence_zeroSum e) + simp only [he,op_smul_eq_smul,zero_smul] + +lemma centered_cut_trace (G : MultiGraph n m) (A : Finset (Fin m)) (S : Finset (Fin n)) : + (G.laplacian A*centered (vecMulVec (cutIndicator S) (cutIndicator S))).trace= + ((G.cut A S).card:ℝ) := by + rw [trace_mul_centered,centered_laplacian,trace_mul_comm,ShortcutDual.trace_outer_mul] + exact G.laplacian_cut A S + +lemma cut_bound (G : MultiGraph n m) (hn : 0 < n) (A B : Finset (Fin m)) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : X ∈ metricDomain G) + {ε : ℝ} (hε : 0 ≤ ε) + (hL : G.laplacian A ≤ (1/2:ℝ) • G.laplacian B+ε • regularize X) + (S : Finset (Fin n)) : + ((G.cut A S).card:ℝ) ≤ (1/2+3*ε)*(G.cut univ S).card := by + let Z := centered (vecMulVec (cutIndicator S) (cutIndicator S)) + have hZ : CenteredTest Z := test_centered hn (cut_test S) + have hh := trace_pairing_mono hL hZ.1.1 + simp only [Matrix.add_mul,Matrix.smul_mul,trace_add,trace_smul,smul_eq_mul, + regularize_trace _ hZ] at hh + have hx := hX.2.2.2 Z hZ + have hcut : ((G.cut B S).card:ℝ) ≤ (G.cut univ S).card := by + exact_mod_cast card_le_card (show G.cut B S ⊆ G.cut univ S from + fun e he => mem_filter.mpr ⟨mem_univ _,(mem_filter.mp he).2⟩) + simp only [Z,centered_cut_trace] at hx hh + have hm := mul_le_mul_of_nonneg_left hx hε + nlinarith only [hh,hm,hcut] + +lemma square_whitening {Q : Matrix (Fin d) (Fin d) ℝ} (hQ : Q.PosDef) : + ∃M : Matrix (Fin d) (Fin d) ℝ, IsUnit M ∧ Mᵀ=M ∧ M*M=Q⁻¹ ∧ M*Q*M=1 := by + obtain ⟨S,hS,hunit,hSS⟩ := posDef_sqrt_factors hQ + have hSi : S⁻¹*S=1 := nonsing_inv_mul S ((isUnit_iff_isUnit_det _).mp hunit) + have hiS : S*S⁻¹=1 := mul_nonsing_inv S ((isUnit_iff_isUnit_det _).mp hunit) + refine ⟨S⁻¹,by simpa only [isUnit_nonsing_inv_iff] using hunit,?_,?_,?_⟩ + · rw [transpose_nonsing_inv,(isHermitian_iff_isSymm.mp hS).eq] + · rw [←hSS,Matrix.mul_inv_rev] + · rw [←hSS,←Matrix.mul_assoc,hSi,Matrix.one_mul,hiS] + +lemma packing_bound (G : MultiGraph (d+1) m) (hn : 2 ≤ d+1) + (B A : Finset (Fin m)) (hAB : A ⊆ B) (s : Fin m → ℚ) + (hs : ∀e, 0 < s e) + (hQ : ((scaledForm G B s).map (fun q : ℚ => (q:ℝ))).PosDef) + {c h : ℝ} {r : ℕ} (hc : 0 < c) (hh : 0 < h) (hr : (r:ℝ)*h ≤ c) + (hnorm : ∀e ∈ B, leverage (realColumns (graphColumns G B)) (realWeights s) e ≤ h) + (hlow : c • ((scaledForm G B s).map (fun q : ℚ => (q:ℝ))) ≤ + StackedSigning.gram (realVec (scaledColumns G B s)) A) : G.TreePackable A r := by + let Q := (scaledForm G B s).map (fun q : ℚ => (q:ℝ)) + obtain ⟨M,hM,hMt,hMM,hMQ⟩ := square_whitening hQ + let L₀ := dropRoot d + let L := L₀.trans (Matrix.toLinearEquiv' M hM.invertible) + have hv (e : Fin m) (he : e ∈ B) : M*ᵥrealVec (scaledColumns G B s) e= + (s e:ℝ) • L ⟨G.incidence e,G.incidence_zeroSum e⟩ := by + rw [scaledColumns_cast,graphColumns_cast,ite_eq_left he,mulVec_smul] + rfl + have hvecnorm (e : Fin m) : (M*ᵥrealVec (scaledColumns G B s) e) ⬝ᵥ + (M*ᵥrealVec (scaledColumns G B s) e)= + leverage (realColumns (graphColumns G B)) (realWeights s) e := by + rw [←hMt,GramWhitening.rectangular_norm,hMt,hMM,scaledColumns_leverage] + have hLo := GramWhitening.congruence_mono hlow M + rw [hMt,Matrix.mul_smul,Matrix.smul_mul,hMQ] at hLo + have hGram : M*StackedSigning.gram (realVec (scaledColumns G B s)) A*M= + ∑e∈A,vecMulVec ((s e:ℝ) • L ⟨G.incidence e,G.incidence_zeroSum e⟩) + ((s e:ℝ) • L ⟨G.incidence e,G.incidence_zeroSum e⟩) := by + rw [StackedSigning.gram] + nth_rw 1 [←hMt] + rw [←GramWhitening.congruence_sum_outer,hMt] + apply sum_congr rfl + intro e he + rw [hv e (hAB he)] + rw [hGram] at hLo + apply G.represented_frame_treePackable hn L (fun e => (s e:ℝ)) + (fun e => by exact_mod_cast hs e) A hc hh hr + · intro e he + dsimp only + rw [←hv e (hAB he),hvecnorm] + exact hnorm e (hAB he) + · intro x + have hx := qform_mono hLo x + change qform (c • (1 : Matrix (Fin d) (Fin d) ℝ)) x ≤ qform _ x at hx + rw [qform_smul,qform_covariance] at hx + simpa only [qform,one_mulVec] using hx + +end AlgorithmicThinTrees.GraphicHalf +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphicHalf.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphicHalf.lean new file mode 100644 index 0000000000000000000000000000000000000000..4c6cf3ccad72d112414f1e0acc35c6f645547200 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphicHalf.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Sparsification.GraphicNormalization + +namespace OAI + +/-! Graphic half. -/ + +section + +namespace AlgorithmicThinTrees.GraphicHalf +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open MetricTests MetricTests.RationalStep Normalization RationalSigning +open scoped MatrixOrder +variable {n d m : ℕ} + +def fullColumns (G : MultiGraph n m) (B : Finset (Fin m)) : Fin m → Fin n → ℚ := + fun e => if e ∈ B then qdiff (G.left e) (G.right e) else 0 + +lemma fullColumns_cast (G : MultiGraph n m) (B : Finset (Fin m)) (e : Fin m) : + realVec (fullColumns G B) e=if e ∈ B then G.incidence e else 0 := by + ext i + by_cases he : e ∈ B + · simp only [realVec,fullColumns,ite_eq_left he,cast_qinc] + · simp only [fullColumns,he,ite_false,realVec,Pi.zero_apply,Rat.cast_zero] + +lemma fullColumns_gram (G : MultiGraph n m) (B A : Finset (Fin m)) : + StackedSigning.gram (realVec (fullColumns G B)) A=G.laplacian (A∩B) := by + simp only [StackedSigning.gram,fullColumns_cast] + rw [laplacian] + rw [show A∩B=A.filter (fun e => e ∈ B) by ext; simp] + rw [sum_filter] + apply sum_congr rfl + intro e he + split_ifs <;> simp only [zero_vecMulVec] + +def positiveForm (X : Matrix (Fin n) (Fin n) ℚ) : Matrix (Fin n) (Fin n) ℚ := + X+Matrix.of (fun _ _ => (n:ℚ)⁻¹) + +lemma positiveForm_cast (X : Matrix (Fin n) (Fin n) ℚ) : + (positiveForm X).map (fun q : ℚ => (q:ℝ))=regularize (X.map (fun q : ℚ => (q:ℝ))) := by + ext i j + simp only [positiveForm,map_apply,Matrix.add_apply,Rat.cast_add,Matrix.of_apply,Rat.cast_inv, + Rat.cast_natCast,regularize,constantProjection,Matrix.smul_apply,smul_eq_mul,vecMulVec,ones,mul_one] + +def scaledColumns (G : MultiGraph (d+1) m) (B : Finset (Fin m)) (s : Fin m → ℚ) : + Fin m → Fin d → ℚ := fun e => s e • graphColumns G B e + +def scaledForm (G : MultiGraph (d+1) m) (B : Finset (Fin m)) (s : Fin m → ℚ) := + covariance (graphColumns G B) (weights s) + +lemma scaledColumns_cast (G : MultiGraph (d+1) m) (B : Finset (Fin m)) + (s : Fin m → ℚ) (e : Fin m) : + realVec (scaledColumns G B s) e=(s e:ℝ) • realColumns (graphColumns G B) e := by + ext i + simp only [realVec,scaledColumns,Pi.smul_apply,smul_eq_mul,Rat.cast_mul,realColumns] + +lemma scaledForm_cast (G : MultiGraph (d+1) m) (B : Finset (Fin m)) (s : Fin m → ℚ) : + (scaledForm G B s).map (fun q : ℚ => (q:ℝ))= + covariance (realColumns (graphColumns G B)) (realWeights s) := by + ext i j + simp only [scaledForm,covariance,map_apply,Matrix.sum_apply,Matrix.smul_apply,smul_eq_mul, + vecMulVec,weights,realColumns,realWeights,Rat.cast_sum,Rat.cast_mul,Rat.cast_pow,Matrix.of_apply] + +lemma scaledColumns_gram (G : MultiGraph (d+1) m) (B : Finset (Fin m)) (s : Fin m → ℚ) : + StackedSigning.gram (realVec (scaledColumns G B s)) univ= + (scaledForm G B s).map (fun q : ℚ => (q:ℝ)) := by + rw [scaledForm_cast] + ext i j + simp only [StackedSigning.gram,scaledColumns_cast,covariance,realWeights, + Matrix.sum_apply,vecMulVec,Pi.smul_apply,smul_eq_mul,Matrix.smul_apply,Matrix.of_apply] + apply sum_congr rfl + intro e _ + ring + +lemma scaledColumns_zero (G : MultiGraph (d+1) m) (B : Finset (Fin m)) (s : Fin m → ℚ) + (e : Fin m) (he : e ∉ B) : realVec (scaledColumns G B s) e=0 := by + rw [scaledColumns_cast,graphColumns_cast,ite_eq_right he,smul_zero] + +lemma scaledColumns_leverage (G : MultiGraph (d+1) m) (B : Finset (Fin m)) + (s : Fin m → ℚ) (e : Fin m) : + realVec (scaledColumns G B s) e ⬝ᵥ + (((scaledForm G B s).map (fun q : ℚ => (q:ℝ)))⁻¹*ᵥrealVec (scaledColumns G B s) e)= + leverage (realColumns (graphColumns G B)) (realWeights s) e := by + rw [scaledColumns_cast,scaledForm_cast] + simp only [leverage,realWeights,mulVec_smul,smul_dotProduct,dotProduct_smul,smul_eq_mul] + ring + +def halfEdges (G : MultiGraph (d+1) m) (B : Finset (Fin m)) + (X : Matrix (Fin (d+1)) (Fin (d+1)) ℚ) (s : Fin m → ℚ) : Finset (Fin m) := + FormSigning.selected (positiveForm X) (scaledForm G B s) + (fullColumns G B) (scaledColumns G B s) ∩ B + +lemma laplacian_mono (G : MultiGraph n m) {A B : Finset (Fin m)} (h : A ⊆ B) : + G.laplacian A ≤ G.laplacian B := by + apply sum_le_sum_of_subset_of_nonneg h + intro e _ _ + exact Matrix.nonneg_iff_posSemidef.mpr (ShortcutDual.outer_posSemidef _) + +lemma fullColumns_covariance (G : MultiGraph n m) (B : Finset (Fin m)) + (X : Matrix (Fin n) (Fin n) ℚ) (hX : X.map (fun q : ℚ => (q:ℝ)) ∈ metricDomain G) : + StackedSigning.gram (realVec (fullColumns G B)) univ ≤ + (positiveForm X).map (fun q : ℚ => (q:ℝ)) := by + rw [fullColumns_gram,univ_inter,positiveForm_cast] + apply ((laplacian_mono G (subset_univ B)).trans hX.2.2.1).trans + exact le_add_of_nonneg_right (Matrix.nonneg_iff_posSemidef.mpr constantProjection_psd) + +theorem half_bounds (G : MultiGraph (d+1) m) (B : Finset (Fin m)) + (X : Matrix (Fin (d+1)) (Fin (d+1)) ℚ) (s : Fin m → ℚ) + (hconn : G.Connected univ) (hX : X.map (fun q : ℚ => (q:ℝ)) ∈ metricDomain G) + (hQ : ((scaledForm G B s).map (fun q : ℚ => (q:ℝ))).PosDef) + {δ : ℝ} (hδ : 0 ≤ δ) + (hnorm : ∀e, realVec (fullColumns G B) e ⬝ᵥ + (((positiveForm X).map (fun q : ℚ => (q:ℝ)))⁻¹*ᵥrealVec (fullColumns G B) e)+ + leverage (realColumns (graphColumns G B)) (realWeights s) e ≤ δ) : + let A := halfEdges G B X s + let ε := 20*Real.sqrt (2*δ) + G.laplacian A ≤ (1/2:ℝ) • G.laplacian B+ε • regularize (X.map (fun q : ℚ => (q:ℝ))) ∧ + (1/2-ε) • (scaledForm G B s).map (fun q : ℚ => (q:ℝ)) ≤ + StackedSigning.gram (realVec (scaledColumns G B s)) A := by + have hP : ((positiveForm X).map (fun q : ℚ => (q:ℝ))).PosDef := by + rw [positiveForm_cast] + exact regularize_pd (by omega) (domain_positive G (by omega) hconn hX) + obtain ⟨hu,hv⟩ := FormSigning.simultaneous (positiveForm X) (scaledForm G B s) hP hQ + (fullColumns G B) (scaledColumns G B s) hδ (fullColumns_covariance G B X hX) + (scaledColumns_gram G B s).le (by simpa only [scaledColumns_leverage] using hnorm) + simp only [fullColumns_gram,univ_inter,positiveForm_cast] at hu + rw [scaledColumns_gram] at hv + dsimp only + constructor + · exact (sub_le_iff_le_add.mp hu.2).trans_eq (add_comm _ _) + · rw [halfEdges,FormSigning.gram_restrict _ B _ (scaledColumns_zero G B s)] + rw [sub_smul] + have hh := (le_sub_iff_add_le.mp hv.1) + simpa only [add_comm,sub_eq_add_neg] using hh + +end AlgorithmicThinTrees.GraphicHalf +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphicNormalization.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphicNormalization.lean new file mode 100644 index 0000000000000000000000000000000000000000..dc82528004ae396474c7c6fbe6e375249e59640a --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/GraphicNormalization.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Normalization.Parameters +import OAI.Combinatorics.ThinTrees.Signing.Realization + +namespace OAI + +/-! Graphic normalization. -/ + +section + +namespace AlgorithmicThinTrees.Normalization +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +variable {d m q : ℕ} + +def dropRoot (d : ℕ) : zeroSumSpace (d+1) ≃ₗ[ℝ] (Fin d → ℝ) where + toFun x i := x.val i.succ + invFun y := ⟨Fin.cases (-(∑i, y i)) y,by + rw [mem_zeroSumSpace,Fin.sum_univ_succ] + simp only [Fin.cases_zero,Fin.cases_succ,neg_add_cancel]⟩ + left_inv x := by + apply Subtype.ext + funext i + refine Fin.cases ?_ (fun j => rfl) i + have hh := (mem_zeroSumSpace x.val).mp x.property + rw [Fin.sum_univ_succ] at hh + change -(∑i : Fin d, x.val i.succ)=x.val 0 + linarith only [hh] + right_inv y := rfl + map_add' x y := rfl + map_smul' c x := rfl + +def integerColumns (G : MultiGraph (d+1) m) (B : Finset (Fin m)) : Fin m → Fin d → ℤ := + fun e i => if e ∈ B then (if G.left e=i.succ then 1 else 0)-(if G.right e=i.succ then 1 else 0) else 0 + +def graphColumns (G : MultiGraph (d+1) m) (B : Finset (Fin m)) : Fin m → Fin d → ℚ := + fun e i => (integerColumns G B e i:ℚ) + +lemma graphColumns_cast (G : MultiGraph (d+1) m) (B : Finset (Fin m)) (e : Fin m) : + realColumns (graphColumns G B) e = if e ∈ B then + dropRoot d ⟨G.incidence e,G.incidence_zeroSum e⟩ else 0 := by + funext i + by_cases he : e ∈ B + · rw [ite_eq_left he] + change ((integerColumns G B e i : ℚ):ℝ) = G.incidence e i.succ + simp only [integerColumns,ite_eq_left he,Int.cast_sub,incidence, + point,Pi.sub_apply,Pi.single_apply,eq_comm (a:=i.succ)] + split_ifs <;> norm_num + · simp [he,realColumns,graphColumns,integerColumns] + +lemma graphColumns_norm (G : MultiGraph (d+1) m) (B : Finset (Fin m)) (e : Fin m) : + realColumns (graphColumns G B) e ⬝ᵥ realColumns (graphColumns G B) e ≤ 2 := by + rw [graphColumns_cast] + split_ifs with he + · have hh := G.eval_incidence (G.incidence e) e + have hnorm : G.incidence e ⬝ᵥ G.incidence e=2 := by + rw [dotProduct,hh] + norm_num [incidence,point,G.loopless e,Ne.symm (G.loopless e)] + rw [dotProduct,Fin.sum_univ_succ] at hnorm + change (∑i : Fin d, G.incidence e i.succ*G.incidence e i.succ) ≤ 2 + nlinarith only [hnorm,sq_nonneg (G.incidence e 0)] + · simp + +lemma integral_det_bound (v : Fin d → Fin d → ℤ) + (hv : IsUnit (Matrix.of (fun i j => (v i j:ℝ)))) : + 1 ≤ (Matrix.det (fun i j => (v i j:ℝ)))^2 := by + have hdet : (Matrix.of v).det ≠ 0 := by + intro hh + have hR : (Matrix.of (fun i j => (v i j:ℝ))).det=0 := by + have hc := (Int.cast_det (R := ℝ) (Matrix.of v)).symm + rw [hh,Int.cast_zero] at hc + exact hc + exact (isUnit_iff_ne_zero.mp ((Matrix.isUnit_iff_isUnit_det _).mp hv)) hR + have hpos : (0:ℤ) < (Matrix.of v).det^2 := sq_pos_of_ne_zero hdet + have h1 : (1:ℤ) ≤ (Matrix.of v).det^2 := by omega + have hR : (1:ℝ) ≤ ((Matrix.of v).det:ℝ)^2 := by exact_mod_cast h1 + rw [Int.cast_det] at hR + exact hR + +lemma integral_containedPacking {E : Type*} [DecidableEq E] + (v : E → Fin d → ℤ) (F : Fin q → Finset E) (hq : 0 < q) + (hF : ∀t, LinearIndepOn ℝ (fun e i => (v e i:ℝ)) (F t : Set E)) + (hc : ∀t, (F t).card=d) (hd : Pairwise (fun i j => Disjoint (F i) (F j))) : + Nonempty (ContainedPacking (fun e i => (v e i:ℝ)) q) := by + classical + let en (t : Fin q) : Fin d ≃ ↥(F t) := Fintype.equivOfCardEq (by simp [hc]) + let f : Fin q × Fin d → E :=fun x => en x.1 x.2 + have hinj : Function.Injective f := by + rintro ⟨t,i⟩ ⟨u,j⟩ hh + have hev : (en t i:E)=(en u j:E) := hh + have htu : t=u := by + by_contra h + exact Finset.disjoint_left.mp (hd h) (en t i).property (hev ▸ (en u j).property) + subst u + have hij := (en t).injective (Subtype.ext hev) + subst j + rfl + have hb (t : Fin q) : IsUnit (Matrix.of (fun i j => (v (en t j) i:ℝ))) := by + apply Matrix.mulVec_injective_iff_isUnit.mp + apply Matrix.mulVec_injective_iff.mpr + exact (hF t).linearIndependent.comp (en t) (en t).injective + exact ⟨⟨hq,⟨f,hinj⟩,hb,fun t => integral_det_bound (fun i j => v (en t j) i) (hb t)⟩⟩ + +lemma graph_containedPacking (G : MultiGraph (d+1) m) (B : Finset (Fin m)) + (hq : 0 < q) (hp : G.TreePackable B q) : + Nonempty (ContainedPacking (realColumns (graphColumns G B)) q) := by + obtain ⟨F,hF,hd⟩ := hp + have hv : realColumns (graphColumns G B) = + fun e i => (integerColumns G B e i:ℝ) := by + funext e i + simp only [realColumns,graphColumns,Rat.cast_intCast] + rw [hv] + apply integral_containedPacking _ F hq ?_ ?_ hd + · intro t + have hf := ((G.spanningTree_iff_independent (F t)).mp (hF t).2).2.linearIndependent + have hf' : LinearIndependent ℝ (fun e : ↥(F t) => + (⟨G.incidence e,G.incidence_zeroSum e⟩ : zeroSumSpace (d+1))) := + hf.of_comp (zeroSumSpace (d+1)).subtype + have hl := hf'.map' (dropRoot d).toLinearMap (dropRoot d).ker + change LinearIndependent ℝ (fun (e : ↥(F t)) (i : Fin d) => (integerColumns G B e i:ℝ)) + have hvec : (fun (e : ↥(F t)) (i : Fin d) => (integerColumns G B e i:ℝ)) = + (dropRoot d).toLinearMap ∘ (fun e : ↥(F t) => + (⟨G.incidence e,G.incidence_zeroSum e⟩ : zeroSumSpace (d+1))) := by + funext e i + have he := graphColumns_cast G B e.val + rw [hv,ite_eq_left ((hF t).1 e.property)] at he + exact congrFun he i + rw [hvec] + exact hl + · intro t + simpa only [Nat.add_sub_cancel] using G.spanningTree_card (by omega : 0 < d+1) (hF t).2 + +theorem graphic_normalization (G : MultiGraph (d+1) m) (B : Finset (Fin m)) + {q r : ℕ} (hq : 0 < q) (hqr : q ≤ r) (hp : G.TreePackable B q) : + let s := normalizedScales q r (graphColumns G B) + (∀e, 0 < s e ∧ s e ≤ 1) ∧ + (∀e, leverage (realColumns (graphColumns G B)) (realWeights s) e ≤ (1+4/(r:ℝ))/(q:ℝ)) ∧ + (∀e, CurrentKS.RationalBits.Parts (normalizationLength m r*(5+2*r.size)) (s e)) := by + obtain ⟨packing⟩ := graph_containedPacking G B hq hp + exact normalizedScales_correct _ packing hqr (graphColumns_norm G B) + +end AlgorithmicThinTrees.Normalization +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/HalfNumeric.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/HalfNumeric.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ea9caee495adcd3b7e779a8c6e87481d074f28e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/HalfNumeric.lean @@ -0,0 +1,180 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.IterationBounds +import OAI.Combinatorics.ThinTrees.Sparsification.ShortcutExtraction + +namespace OAI + +/-! Half numeric. -/ + +section + +namespace AlgorithmicThinTrees.GraphicHalf +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open MetricTests MetricTests.RationalStep Normalization RationalSigning Filter Topology +open scoped MatrixOrder + +def countError (r : ℕ) : ℚ := 1/(Nat.nthRoot 16 r:ℚ) + +def nextCount (r : ℕ) : ℕ := ⌊(1-16*countError r)*(r:ℚ)/2⌋₊ + +noncomputable def varianceBound (r : ℕ) : ℝ := 5*(r:ℝ)^(-1/4:ℝ) +noncomputable def halfError (r : ℕ) : ℝ := 20*Real.sqrt (2*varianceBound r) + +lemma countError_bounds (r : ℕ) (hr : 0 < r) : + errorU r ≤ (countError r:ℝ) ∧ (countError r:ℝ) ≤ 2*errorU r := by + have hroot := nthRoot_le_real_root 16 r (by norm_num) + have hr0 : 0 < (r:ℝ) := Nat.cast_pos.mpr hr + have hu1 : (1:ℝ) ≤ Nat.nthRoot 16 r := by exact_mod_cast nthRoot_pos 16 r (by norm_num) hr + have hup := real_root_lt_nthRoot_add 16 r (by norm_num) + have hp : 0 < (r:ℝ)^(1/16:ℝ) := Real.rpow_pos_of_pos hr0 _ + have he : errorU r=1/((r:ℝ)^(1/16:ℝ)) := by + simp only [errorU,show (-1/16:ℝ)= -(1/16:ℝ) by ring,Real.rpow_neg hr0.le,one_div] + simp only [Nat.cast_ofNat] at hroot hup + rw [he] + have hg : (countError r:ℝ)=1/(Nat.nthRoot 16 r:ℝ) := by simp [countError] + rw [hg] + constructor + · exact one_div_le_one_div_of_le (by linarith only [hu1]) hroot + · have hu0 : 0 < (Nat.nthRoot 16 r:ℝ) := by linarith only [hu1] + apply (div_le_iff₀ hu0).mpr + rw [show 2*(1/((r:ℝ)^(1/16:ℝ)))*(Nat.nthRoot 16 r:ℝ)= + (2*(Nat.nthRoot 16 r:ℝ))/((r:ℝ)^(1/16:ℝ)) by ring] + apply (le_div_iff₀ hp).mpr + linarith only [hu1,hup] + +lemma halfError_ratio (r : ℕ) (hr : 0 < r) : + halfError r=(20*Real.sqrt 10*errorU r)*errorU r := by + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hr + have hmul : errorU r*errorU r=(r:ℝ)^(-1/8:ℝ) := by + rw [errorU,←Real.rpow_add hrR] + norm_num + rw [mul_assoc,hmul] + unfold halfError varianceBound + rw [show 2*(5*(r:ℝ)^(-1/4:ℝ))=10*(r:ℝ)^(-1/4:ℝ) by ring, + Real.sqrt_mul (by norm_num),Real.sqrt_eq_rpow ((r:ℝ)^(-1/4:ℝ)),←Real.rpow_mul hrR.le] + norm_num only [mul_div_assoc,mul_one,div_mul_div_comm] + ring + +structure Numeric (r : ℕ) : Prop where + rlarge : 4 ≤ r + small : errorU r ≤ 1/128 + inverse : 4/(r:ℝ) ≤ errorU r + loss : halfError r ≤ errorU r + +lemma eventual_numeric : ∃R : ℕ, ∀r, R ≤ r → Numeric r := by + have hinv : Tendsto (fun r : ℕ => 4*(r:ℝ)^(-15/16:ℝ)) atTop (𝓝 0) := by + simpa [Function.comp_def,neg_div] using + ((tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<15/16)).const_mul 4).comp + tendsto_natCast_atTop_atTop + have heps : Tendsto (fun r : ℕ => 20*Real.sqrt 10*errorU r) atTop (𝓝 0) := by + simpa using tendsto_errorU.const_mul (20*Real.sqrt 10) + have hev : ∀ᶠ r : ℕ in atTop, 4 ≤ r ∧ errorU r ≤ 1/128 ∧ + 4*(r:ℝ)^(-15/16:ℝ) ≤ 1 ∧ 20*Real.sqrt 10*errorU r ≤ 1 := by + filter_upwards [eventually_ge_atTop 4, + tendsto_errorU.eventually_lt_const (by norm_num : (0:ℝ)<1/128), + hinv.eventually_lt_const (by norm_num : (0:ℝ)<1), + heps.eventually_lt_const (by norm_num : (0:ℝ)<1)] with r hr hu hi he + exact ⟨hr,hu.le,hi.le,he.le⟩ + obtain ⟨R,hR⟩ := eventually_atTop.mp hev + refine ⟨R,fun r hr => ?_⟩ + obtain ⟨hr4,hu,hi,he⟩ := hR r hr + have hr0 : 0 < r := by omega + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hr0 + refine ⟨hr4,hu,?_,?_⟩ + · have hpow : (r:ℝ)^(-15/16:ℝ)*errorU r=(r:ℝ)⁻¹ := by + rw [errorU,←Real.rpow_add hrR] + norm_num [Real.rpow_neg_one] + have hh := mul_le_mul_of_nonneg_right hi (errorU_nonneg r) + rw [mul_assoc,hpow,one_mul] at hh + simpa only [div_eq_mul_inv] using hh + · rw [halfError_ratio r hr0] + simpa only [one_mul] using mul_le_mul_of_nonneg_right he (errorU_nonneg r) + +lemma rounding_bounds {r : ℕ} (hn : Numeric r) : + ((1/2:ℝ)-17*errorU r)*r ≤ nextCount r ∧ + (nextCount r:ℝ) ≤ ((1/2:ℝ)-8*errorU r)*r := by + have hr0 : 0 < r := by have := hn.rlarge;omega + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hr0 + have hu := errorU_nonneg r + obtain ⟨hv,hv2⟩ := countError_bounds r hr0 + have hsmall := hn.small + have hnonneg : 0 ≤ (1-16*countError r)*(r:ℚ)/2 := by + have hh : (0:ℝ) ≤ (1-16*(countError r:ℝ))*(r:ℝ)/2 := by positivity [show 0 ≤ 1-16*(countError r:ℝ) by linarith only [hv2,hsmall]] + exact_mod_cast hh + have hlo := Nat.sub_one_lt_floor ((1-16*countError r)*(r:ℚ)/2) + have hhi := Nat.floor_le hnonneg + have hloR : (1-16*(countError r:ℝ))*(r:ℝ)/2-1 < (nextCount r:ℝ) := by exact_mod_cast hlo + have hhiR : (nextCount r:ℝ) ≤ (1-16*(countError r:ℝ))*(r:ℝ)/2 := by exact_mod_cast hhi + have hru := rounding_absorbed r (by omega) + change 1 ≤ errorU r*r at hru + constructor + · have hm := mul_le_mul_of_nonneg_right hv2 hrR.le + nlinarith only [hloR,hm,hru] + · have hm := mul_le_mul_of_nonneg_right hv hrR.le + nlinarith only [hhiR,hm] + +lemma nextCount_bounds {r : ℕ} (hn : Numeric r) : + (r:ℝ)/4 ≤ nextCount r ∧ (nextCount r:ℝ) ≤ (r:ℝ)/2 ∧ 0 < nextCount r := by + obtain ⟨hlo,hhi⟩ := rounding_bounds hn + have hu := errorU_nonneg r + have hsmall := hn.small + have hr0 : (0:ℝ) < r := by exact_mod_cast (show 0 < r by have := hn.rlarge;omega) + have hm := mul_le_mul_of_nonneg_right hsmall hr0.le + have hz := mul_nonneg hu hr0.le + have hpos : (0:ℝ) < nextCount r := by nlinarith only [hlo,hm,hr0] + exact ⟨by nlinarith only [hlo,hm],by nlinarith only [hhi,hz],by exact_mod_cast hpos⟩ + +lemma packing_numeric {r q : ℕ} (hn : Numeric r) (hq : 0 < q) + (hqr : (1-6*errorU r)*(r:ℝ) ≤ q) : + (nextCount r:ℝ)*((1+4/(r:ℝ))/(q:ℝ)) ≤ 1/2-halfError r := by + have hr0 : (0:ℝ) < r := by exact_mod_cast (show 0 < r by have := hn.rlarge;omega) + have hq0 : (0:ℝ) < q := Nat.cast_pos.mpr hq + have hu := errorU_nonneg r + have herror0 : 0 ≤ halfError r := by unfold halfError; positivity + have hc : 0 ≤ 1/2-halfError r := by linarith only [hn.loss,hn.small] + rw [←mul_div_assoc,div_le_iff₀ hq0] + have hupper := (rounding_bounds hn).2 + have hsize := mul_le_mul_of_nonneg_left hn.inverse (Nat.cast_nonneg (nextCount r) : (0:ℝ) ≤ _) + have htarg := mul_le_mul_of_nonneg_left hqr hc + have hm := mul_le_mul_of_nonneg_right hupper (by linarith only [hu] : 0 ≤ 1+errorU r) + have hp : 0 ≤ (1-6*errorU r)*(r:ℝ) := mul_nonneg (by linarith only [hn.small]) hr0.le + have hloss := mul_le_mul_of_nonneg_right hn.loss hp + have husq := mul_nonneg (sq_nonneg (errorU r)) hr0.le + have huR := mul_nonneg hu hr0.le + nlinarith only [hsize,htarg,hm,hloss,husq,huR] + +lemma half_ratio {r : ℕ} (hn : Numeric r) : + (1/2+3*halfError r)*(r:ℝ) ≤ (1+80*errorU r)*nextCount r := by + have hrR := (Nat.cast_nonneg r : (0:ℝ) ≤ r) + have hu := errorU_nonneg r + have hlo := (rounding_bounds hn).1 + have hB : 0 ≤ 20-1360*errorU r := by linarith only [hn.small] + have hpos := mul_nonneg (mul_nonneg hu hB) hrR + have hm := mul_le_mul_of_nonneg_left hlo (by linarith only [hu] : 0 ≤ 1+80*errorU r) + have he := mul_le_mul_of_nonneg_right hn.loss hrR + nlinarith only [hm,hpos,he] + +lemma normalized_size {r q : ℕ} (hn : Numeric r) + (hqr : (1-6*errorU r)*(r:ℝ) ≤ q) : + (1+4/(r:ℝ))/(q:ℝ) ≤ 4*(r:ℝ)^(-1/4:ℝ) := by + have hr0 : (0:ℝ) < r := by exact_mod_cast (show 0 < r by have := hn.rlarge;omega) + have hqR : (r:ℝ)/2 ≤ q := by + have hm := mul_le_mul_of_nonneg_right hn.small hr0.le + nlinarith only [hqr,hm] + have hq0 : (0:ℝ) < q := by linarith only [hqR,hr0] + have hi : (1+4/(r:ℝ))/(q:ℝ) ≤ 4/(r:ℝ) := by + have hupp : 1+4/(r:ℝ) ≤ 2 := by linarith only [hn.inverse,hn.small] + rw [div_le_div_iff₀ hq0 hr0] + have hm := mul_le_mul_of_nonneg_right hupp hr0.le + nlinarith only [hm,hqR] + have hpow := Real.rpow_le_rpow_of_exponent_le + (show (1:ℝ) ≤ r by exact_mod_cast (show 1 ≤ r by have := hn.rlarge;omega)) + (by norm_num : (-1:ℝ) ≤ -1/4) + simp only [Real.rpow_neg_one] at hpow + apply hi.trans + simpa only [div_eq_mul_inv] using mul_le_mul_of_nonneg_left hpow (by norm_num : (0:ℝ) ≤ 4) + +end AlgorithmicThinTrees.GraphicHalf +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/IterationPotential.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/IterationPotential.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e0e3e4b830a3b093662d86cf3abb89776cec30e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/IterationPotential.lean @@ -0,0 +1,68 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Sparsification.HalfNumeric + +namespace OAI + +/-! Iteration potential. -/ + +section + +noncomputable section +namespace AlgorithmicThinTrees.Iteration +open StrongThinTree + +def lossB : ℝ := 80 / ((2:ℝ)^(1/16:ℝ)-1) +def potential (r : ℕ) : ℝ := Real.exp (lossB*(1-errorU r)) + +lemma lossB_pos : 0 < lossB := by + unfold lossB + exact div_pos (by norm_num) (sub_pos.mpr (Real.one_lt_rpow (by norm_num) (by norm_num))) +lemma potential_pos (r : ℕ) : 0 < potential r := Real.exp_pos _ +lemma potential_one_le {r : ℕ} (hr : 1 ≤ r) : 1 ≤ potential r := by + exact Real.one_le_exp (mul_nonneg lossB_pos.le (sub_nonneg.mpr (errorU_le_one hr))) +lemma potential_le (r : ℕ) : potential r ≤ Real.exp lossB := by + apply Real.exp_le_exp.mpr + have := mul_nonneg lossB_pos.le (errorU_nonneg r) + nlinarith + +lemma potential_step {r s : ℕ} (hs : 0 < s) (hrs : (s:ℝ) ≤ (r:ℝ)/2) : + (1+80*errorU r)*potential s ≤ potential r := by + have hd : 0 < (2:ℝ)^(1/16:ℝ)-1 := + sub_pos.mpr (Real.one_lt_rpow (by norm_num) (by norm_num)) + have hm := mul_le_mul_of_nonneg_left (errorU_halving hs hrs) lossB_pos.le + have hB : lossB*((2:ℝ)^(1/16:ℝ)-1)=80 := by + unfold lossB + exact div_mul_cancel₀ _ (ne_of_gt hd) + have hdiff : 80*errorU r ≤ lossB*(errorU s-errorU r) := by + have hBu := congrArg (fun x : ℝ => x*errorU r) hB + nlinarith + have he : 1+80*errorU r ≤ Real.exp (80*errorU r) := by + simpa only [add_comm] using Real.add_one_le_exp (80*errorU r) + calc + _ ≤ Real.exp (80*errorU r)*potential s := + mul_le_mul_of_nonneg_right he (potential_pos s).le + _ = Real.exp (80*errorU r+lossB*(1-errorU s)) := by + rw [potential,Real.exp_add] + _ ≤ potential r := by + apply Real.exp_le_exp.mpr + linarith + +lemma coefficient_step {r s : ℕ} (hr : 0 < r) (hs : 0 < s) + (hhalf : (s:ℝ) ≤ (r:ℝ)/2) + (hratio : (1/2+3*GraphicHalf.halfError r)*(r:ℝ) ≤ (1+80*errorU r)*s) : + potential s/(s:ℝ)*(1/2+3*GraphicHalf.halfError r) ≤ potential r/(r:ℝ) := by + have hrR : (0:ℝ) < r := by exact_mod_cast hr + have hsR : (0:ℝ) < s := by exact_mod_cast hs + rw [div_mul_eq_mul_div] + apply (div_le_div_iff₀ hsR hrR).mpr + have hp := potential_step hs hhalf + have hm := mul_le_mul_of_nonneg_left hratio (potential_pos s).le + have hp' := mul_le_mul_of_nonneg_right hp hsR.le + nlinarith + +end AlgorithmicThinTrees.Iteration +end + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/IterationRealization.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/IterationRealization.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b815e5e1f86b146b8fd30dcacc36de1ed719e18 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/IterationRealization.lean @@ -0,0 +1,335 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.GreedyRealization +import OAI.Combinatorics.ThinTrees.Encoding.SelectionRealization +import OAI.Combinatorics.ThinTrees.Sparsification.RationalIteration + +namespace OAI + +/-! Iteration realization. -/ + +section + +namespace AlgorithmicThinTrees.Iteration.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 StrongThinTree Finset +open GraphStack GraphicHalf GraphicHalf.Stack MetricTests.RationalStep MetricTests.RationalStep.Stack OrderedGraph + +lemma nextCount_le (r : ℕ) : nextCount r ≤ r := by + unfold nextCount + apply (Nat.floor_mono (show (1-16*countError r)*(r:ℚ)/2 ≤ (r:ℚ) from ?_)).trans_eq + (Nat.floor_natCast r) + have : 0 ≤ countError r := by unfold countError; positivity + have : 0 ≤ countError r*(r:ℚ) := mul_nonneg this (Nat.cast_nonneg _) + nlinarith + +def nextCountBinary : Realizes natCode binaryNatCode nextCount := + ((((constant natCode ratCode 1).sub ((constant natCode ratCode 16).mul + ((constant natCode ratCode 1).div ((unaryRoot 16 (by decide)).then natToRat)))).mul natToRat).div + (constant natCode ratCode 2)).then ratNatFloorBinary +instance poly_nextCountBinary : PolyTime nextCountBinary := by + unfold nextCountBinary + apply poly_then + +def nextCountProgram : Realizes natCode natCode nextCount := nextCountBinary.then binaryToNat +instance poly_nextCountProgram : PolyTime nextCountProgram := by + apply PolyTime.mk + have hb := RunsPoly.of_poly nextCountBinary id (isPoly_self (fun r => (natCode r).length)) + have hn : IsPoly (fun r => (natCode r).length) nextCount := + (isPoly_self (fun r => (natCode r).length)).mono (fun r => by + simpa only [natCode,List.length_replicate] using nextCount_le r) + exact (hb.then (runsPoly_binaryToNat _ hb.output hn)).cost + +structure State where + problem : Problem + labels : Fin problem.m → ℕ + +def stateCode (s : State) : Word := prodCode problemCode indicesCode + (s.problem,List.ofFn s.labels) +abbrev stateView : Realizes stateCode (prodCode problemCode indicesCode) + (fun s => (s.problem,List.ofFn s.labels)) := + (identity (prodCode problemCode indicesCode)).reindex stateCode + (fun s => (s.problem,List.ofFn s.labels)) (fun _ => rfl) +private instance poly_stateView : PolyTime stateView := by + unfold stateView + apply poly_reindex + +abbrev problem := stateView.then (first problemCode indicesCode) +private instance poly_problem : PolyTime problem := by + unfold problem + apply poly_then + +abbrev labels := stateView.then (second problemCode indicesCode) +private instance poly_labels : PolyTime labels := by + unfold labels + apply poly_then + +abbrev graph := problem.then problemGraph +private instance poly_graph : PolyTime graph := by + unfold graph + apply poly_then + +abbrev count := problem.then problemCount +private instance poly_count : PolyTime count := by + unfold count + apply poly_then + +def State.restrict (s : State) (A : Finset (Fin s.problem.m)) : State := + ⟨⟨s.problem.d,A.card,nextCount s.problem.r,OrderedGraph.restrict s.problem.G A⟩, + fun e => s.labels (edgeEmbedding A e)⟩ +def halve (s : State) : State := s.restrict (sparsify s.problem.G s.problem.r) +def step (R : ℕ) (s : State) : State := if R ≤ s.problem.r then halve s else s + +def selectState : Realizes (prodCode stateCode boolsCode) stateCode + (fun p => p.1.restrict (univ.filter (fun e => p.2.getD e.val false))) := by + let a := first stateCode boolsCode + let b := second stateCode boolsCode + + let entry : Realizes (prodCode (prodCode stateCode boolsCode) natCode) boolCode + (fun q => q.1.2.getD q.2 false) := + ((second (prodCode stateCode boolsCode) natCode).both + ((first (prodCode stateCode boolsCode) natCode).then b)).then (getD boolCode false) + let bits := (((identity (prodCode stateCode boolsCode)).both + (a.then graph |>.then numEdges)).then entry.tabulate) + let ls := (bits.both (a.then graph |>.then lefts)).then (maskArray natCode 0) + let rs := (bits.both (a.then graph |>.then rights)).then (maskArray natCode 0) + let labs := (bits.both (a.then labels)).then (maskArray natCode 0) + let gg := (a.then graph |>.then numVertices).both (ls.both rs) + exact ((gg.both (a.then count |>.then nextCountProgram)).both labs).changeOutput stateCode + (fun p => p.1.restrict (univ.filter (fun e => p.2.getD e.val false))) (by + intro p + let A := univ.filter (fun e : Fin p.1.problem.m => p.2.getD e.val false) + have hb : (List.range p.1.problem.m).map (fun i => p.2.getD i false)= + List.ofFn (fun e => decide (e ∈ A)) := by + rw [range_map_fin] + simp [A] + change prodCode (prodCode graphDataCode natCode) indicesCode + ((_,_),_) = _ + dsimp only [id,Problem.graph,Graph.data] + rw [hb,maskArray_data,maskArray_data,maskArray_data] + rfl) +instance poly_selectState : PolyTime selectState := by + unfold selectState + dsimp only + refine @poly_changeOutput _ _ _ _ _ _ _ _ _ _ ?_ + refine @poly_both _ _ _ _ _ _ _ _ _ _ ?_ ?_ <;> infer_instance + +def halveProgram : Realizes stateCode stateCode halve := + (((identity stateCode).both (problem.then sparsifyProgram)).then selectState).congr (by + intro s + have he : univ.filter (fun e : Fin s.problem.m => + (List.ofFn (fun e => decide (e ∈ sparsify s.problem.G s.problem.r))).getD e.val false)= + sparsify s.problem.G s.problem.r := by + ext e + simp + change s.restrict _=s.restrict _ + exact congrArg (State.restrict s) he) + +def large (R : ℕ) : Realizes stateCode boolCode (fun s => decide (R ≤ s.problem.r)) := + ((constant stateCode natCode R).both count).then natLE +instance poly_large (R : ℕ) : PolyTime (large R) := by unfold large;apply poly_then + +def stepProgram (R : ℕ) : Realizes stateCode stateCode (step R) := + ((large R).ite halveProgram (identity stateCode)).congr (by intro s;simp [step]) + +def finishData (s : State) : List ℕ := + List.ofFn (fun e => s.labels (edgeEmbedding (GreedyTree.tree s.problem.G) e)) +def finish : Realizes stateCode indicesCode finishData := + ((((graph.then GreedyTree.Stack.treeProgram).both labels).then (maskArray natCode 0))).congr + (fun s => maskArray_data _ s.labels 0) +instance poly_finish : PolyTime finish := by unfold finish;apply poly_congr + +lemma restrict_length (s : State) (A : Finset (Fin s.problem.m)) : + (stateCode (s.restrict A)).length≤(stateCode s).length := by + have hl := listCode_selected_le natCode A (fun e => (s.problem.G.left e).val) + have hr := listCode_selected_le natCode A (fun e => (s.problem.G.right e).val) + have hlabels := listCode_selected_le natCode A s.labels + have hn := nextCount_le s.problem.r + simp only [stateCode,State.restrict,problemCode,extractionInputCode,Problem.graph,graphCode, + graphDataCode,Graph.data,prodCode_length,natCode,List.length_replicate, + OrderedGraph.restrict,indicesCode] at * + omega +lemma step_length (R : ℕ) (s : State) : (stateCode (step R s)).length≤(stateCode s).length := by + unfold step + split + · exact restrict_length _ _ + · rfl +lemma orbit_length (R t : ℕ) (s : State) : + (stateCode ((step R)^[t] s)).length≤(stateCode s).length := by + induction t with + | zero => rfl + | succ t ih => rw [Function.iterate_succ_apply'];exact (step_length _ _).trans ih + +lemma orbit_packed {R : ℕ} (_hR : 4 ≤ R) (hb : RoundBound R) (s : State) + (hn : 2 ≤ s.problem.d+1) (hp : s.problem.G.TreePackable univ s.problem.r) + (t : ℕ) : + 2 ≤ ((step R)^[t] s).problem.d+1 ∧ + ((step R)^[t] s).problem.G.TreePackable univ ((step R)^[t] s).problem.r := by + induction t with + | zero => exact ⟨hn,hp⟩ + | succ t ih => + rw [Function.iterate_succ_apply'] + by_cases hh : R ≤ ((step R)^[t] s).problem.r + · rw [step,ite_eq_left hh] + exact ⟨ih.1,OrderedGraph.restrict_packable _ _ + (hb _ hh _ _ _ ih.1 ih.2).2.2.2.1⟩ + · rw [step,ite_eq_right hh];exact ih + +lemma runsPoly_step {R T : ℕ} (hTR : T ≤ R) + (htime : ∀{ι : Type} {L : ι → ℕ} (a : ι → Problem), + IsPoly L (fun i => (problemCode (a i)).length) → + (∀i,T ≤ (a i).r ∧ 2 ≤ (a i).d+1 ∧ (a i).G.TreePackable univ (a i).r) → + RunsPoly L sparsifyProgram a) + {ι : Type} {L : ι → ℕ} (a : ι → State) + (ha : IsPoly L (fun i => (stateCode (a i)).length)) + (hp : ∀i,2 ≤ (a i).problem.d+1 ∧ (a i).problem.G.TreePackable univ (a i).problem.r) : + RunsPoly L (stepProgram R) a := by + unfold stepProgram + apply RunsPoly.congr + apply RunsPoly.ite_on (RunsPoly.of_poly _ a ha) + have hh : IsPoly (fun i : {i // R ≤ (a i).problem.r} => L i.val) + (fun i => halveProgram.cost (a i.val)) := by + have hi := RunsPoly.of_poly problem (fun i : {i // R ≤ (a i).problem.r} => a i.val) + (ha.reindex Subtype.val) + have hs := htime (fun i : {i // R ≤ (a i).problem.r} => (a i.val).problem) hi.output + (fun i => ⟨hTR.trans i.property,(hp i.val).1,(hp i.val).2⟩) + have hh := (RunsPoly.of_poly (identity stateCode) + (fun i : {i // R ≤ (a i).problem.r} => a i.val) (ha.reindex Subtype.val)).both + (hi.then hs) + have hz : RunsPoly (fun i : {i // R ≤ (a i).problem.r} => L i.val) + halveProgram (fun i => a i.val) := by + unfold halveProgram;apply RunsPoly.congr;exact hh.then_poly selectState + exact hz.cost + have hl := (RunsPoly.of_poly (identity stateCode) + (fun i : {i // ¬R ≤ (a i).problem.r} => a i.val) (ha.reindex Subtype.val)).cost + have hz := isPoly_dite (L:=L) (P:=fun i => R ≤ (a i).problem.r) + (f:=fun i _ => halveProgram.cost (a i)) + (g:=fun i _ => (identity stateCode).cost (a i)) hh hl + convert hz using 1 + funext i + simp only [decide_eq_true_eq] + split_ifs <;> rfl + +def run (R : ℕ) : Realizes (prodCode natCode stateCode) indicesCode + (fun p => finishData ((step R)^[p.1] p.2)) := (stepProgram R).iterate.then finish + +lemma runsPoly_run {R T : ℕ} (hR : 4 ≤ R) (hb : RoundBound R) (hTR : T ≤ R) + (htime : ∀{ι : Type} {L : ι → ℕ} (a : ι → Problem), + IsPoly L (fun i => (problemCode (a i)).length) → + (∀i,T ≤ (a i).r ∧ 2 ≤ (a i).d+1 ∧ (a i).G.TreePackable univ (a i).r) → + RunsPoly L sparsifyProgram a) + {ι : Type} {L : ι → ℕ} (a : ι → ℕ×State) + (ha : IsPoly L (fun i => (prodCode natCode stateCode (a i)).length)) + (hp : ∀i,2 ≤ (a i).2.problem.d+1 ∧ + (a i).2.problem.G.TreePackable univ (a i).2.problem.r) : RunsPoly L (run R) a := by + have hi : IsPoly L (fun i => (stateCode (a i).2).length) := + ha.mono (fun i => le_prodCode_right (ea:=natCode) (eb:=stateCode) (a i)) + have hs := runsPoly_step hTR htime (fun p : ι×ℕ => (step R)^[p.2] (a p.1).2) + ((hi.reindex Prod.fst).mono (fun p => orbit_length R p.2 (a p.1).2)) + (fun p => orbit_packed hR hb (a p.1).2 (hp p.1).1 (hp p.1).2 p.2) + apply (runsPoly_iterate _ a ha ?_).then_poly finish + obtain ⟨q,hq⟩ := hs.cost + exact ⟨q,fun i j _ => hq (i,j)⟩ + +end AlgorithmicThinTrees.Iteration.Stack + +namespace AlgorithmicThinTrees.OrderedGraph +open StrongThinTree Finset +lemma sorted_lift {m : ℕ} (A : Finset (Fin m)) (B : Finset (Fin A.card)) : + List.ofFn (edgeEmbedding (liftEdges A B)) = + List.ofFn (fun i => edgeEmbedding A (edgeEmbedding B i)) := by + have ha := List.sortedLT_ofFn_iff.mpr ((liftEdges A B).orderEmbOfFin rfl).strictMono + have hb := List.sortedLT_ofFn_iff.mpr + ((A.orderEmbOfFin rfl).strictMono.comp (B.orderEmbOfFin rfl).strictMono) + apply ha.eq_of_mem_iff hb + · intro e + simp only [List.mem_ofFn] + constructor + · rintro ⟨i,rfl⟩ + obtain ⟨j,hj,hji⟩ := mem_map.mp (embedding_mem (liftEdges A B) i) + obtain ⟨l,rfl⟩ := embedding_surj B hj + exact ⟨l,hji⟩ + · rintro ⟨i,rfl⟩ + exact embedding_surj (liftEdges A B) (mem_map.mpr ⟨_,embedding_mem B i,rfl⟩) + +lemma mapped_sorted_lift {m : ℕ} (A : Finset (Fin m)) (B : Finset (Fin A.card)) (f : Fin m → ℕ) : + List.ofFn (fun i => f (edgeEmbedding (liftEdges A B) i)) = + List.ofFn (fun i => f (edgeEmbedding A (edgeEmbedding B i))) := by + have h := congrArg (List.map f) (sorted_lift A B) + simpa only [List.map_ofFn,Function.comp_def] using h +end AlgorithmicThinTrees.OrderedGraph + +namespace AlgorithmicThinTrees.Iteration.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 StrongThinTree Finset +open GraphStack GraphicHalf GraphicHalf.Stack MetricTests.RationalStep OrderedGraph + +lemma run_data (R fuel : ℕ) (s : State) : + finishData ((step R)^[fuel] s)= + List.ofFn (fun e => s.labels (edgeEmbedding + (iterate R fuel s.problem.r s.problem.d s.problem.m s.problem.G) e)) := by + induction fuel generalizing s with + | zero => rfl + | succ t ih => + by_cases hh : R ≤ s.problem.r + · rw [Function.iterate_succ_apply,step,ite_eq_left hh,ih,iterate,ite_eq_left hh] + exact (mapped_sorted_lift (sparsify s.problem.G s.problem.r) + (iterate R t (nextCount s.problem.r) s.problem.d _ + (OrderedGraph.restrict s.problem.G (sparsify s.problem.G s.problem.r))) s.labels).symm + · have hfix : step R s=s := by rw [step,ite_eq_right hh] + have horb : (step R)^[t+1] s=s := Function.iterate_fixed hfix _ + rw [horb,iterate,ite_eq_right hh] + rfl + +def initialCountProgram : Realizes natCode natCode initialCount := + let h := (identity natCode).ndiv (constant natCode natCode 2) + (((constant natCode natCode 1).nlt h).ite h (constant natCode natCode 1)).congr (by + intro k + simp only [decide_eq_true_eq,initialCount,id_eq] + split_ifs with hh + · exact (max_eq_right (by omega)).symm + · exact (max_eq_left (by omega)).symm) +instance poly_initialCountProgram : PolyTime initialCountProgram := by + unfold initialCountProgram;infer_instance + +abbrev TreeProblem := Problem + +def start (p : TreeProblem) : ℕ×State := + (initialCount p.r,⟨⟨p.d,p.m,initialCount p.r,p.G⟩,fun e => e.val⟩) +def startProgram : Realizes problemCode (prodCode natCode stateCode) start := + let r := problemCount.then initialCountProgram + let lab := problemM.then CurrentKS.Realization.range + (r.both ((problemGraph.both r).both lab)).changeOutput + (prodCode natCode stateCode) start (by + intro p + change prodCode natCode (prodCode (prodCode graphCode natCode) indicesCode) + (_,(_,List.range p.m))=_ + have he : List.range p.m=List.ofFn (fun e : Fin p.m => e.val) := by + simpa only [List.map_id, id_eq] using (range_map_fin (n:=p.m) (f:=id)) + rw [he] + rfl) +instance poly_startProgram : PolyTime startProgram := by unfold startProgram;infer_instance + +def treeData (R : ℕ) (p : TreeProblem) : List ℕ := + List.ofFn (fun e => (edgeEmbedding (Iteration.tree R p.r p.G) e).val) +def treeProgram (R : ℕ) : Realizes problemCode indicesCode (treeData R) := + (startProgram.then (run R)).congr (fun p => run_data R (initialCount p.r) (start p).2) + +lemma runsPoly_tree {R T : ℕ} (hR : 4 ≤ R) (hb : RoundBound R) (hTR : T ≤ R) + (htime : ∀{ι : Type} {L : ι → ℕ} (a : ι → Problem), + IsPoly L (fun i => (problemCode (a i)).length) → + (∀i,T ≤ (a i).r ∧ 2 ≤ (a i).d+1 ∧ (a i).G.TreePackable univ (a i).r) → + RunsPoly L sparsifyProgram a) + {ι : Type} {L : ι → ℕ} (a : ι → Problem) + (ha : IsPoly L (fun i => (problemCode (a i)).length)) + (hp : ∀i,2 ≤ (a i).d+1 ∧ 1 ≤ (a i).r ∧ (a i).G.EdgeConnected (a i).r) : + RunsPoly L (treeProgram R) a := by + have hs := RunsPoly.of_poly startProgram a ha + unfold treeProgram + apply RunsPoly.congr + apply hs.then + apply runsPoly_run hR hb hTR htime _ hs.output + intro i + exact ⟨(hp i).1,initial_packable _ (by omega) (hp i).2.1 (hp i).2.2⟩ + +end AlgorithmicThinTrees.Iteration.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/RationalIteration.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/RationalIteration.lean new file mode 100644 index 0000000000000000000000000000000000000000..265a38c8b8ea18e2fe9e8f1bade528de4447ac5e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/RationalIteration.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Encoding.GreedyTree +import OAI.Combinatorics.ThinTrees.Encoding.OrderedGraph +import OAI.Combinatorics.ThinTrees.Iteration +import OAI.Combinatorics.ThinTrees.Sparsification.IterationPotential +import OAI.Combinatorics.ThinTrees.Sparsification.Step + +namespace OAI + +/-! Rational iteration. -/ + +section + +namespace AlgorithmicThinTrees.Iteration +open Finset StrongThinTree StrongThinTree.MultiGraph GraphicHalf +open MetricTests MetricTests.RationalStep + +def iterate (R : ℕ) : (fuel r d m : ℕ) → + MultiGraph (d+1) m → Finset (Fin m) + | 0,_,_,_,G => GreedyTree.tree G + | fuel+1,r,d,_,G => + if R ≤ r then + let A := sparsify G r + OrderedGraph.liftEdges A + (iterate R fuel (nextCount r) d A.card (OrderedGraph.restrict G A)) + else GreedyTree.tree G + +def RoundBound (R : ℕ) : Prop := ∀r : ℕ, R ≤ r → + ∀(d m : ℕ) (G : MultiGraph (d+1) m), 2 ≤ d+1 → G.TreePackable univ r → + (r:ℝ)/4 ≤ nextCount r ∧ (nextCount r:ℝ) ≤ (r:ℝ)/2 ∧ 0 < nextCount r ∧ + G.TreePackable (sparsify G r) (nextCount r) ∧ + (∀S : Finset (Fin (d+1)), ((G.cut (sparsify G r) S).card:ℝ) ≤ + (1/2+3*halfError r)*(G.cut univ S).card) ∧ + (1/2+3*halfError r)*(r:ℝ) ≤ (1+80*errorU r)*nextCount r + +lemma iterate_bound {R : ℕ} (hR : 4 ≤ R) (hround : RoundBound R) (fuel r d m : ℕ) + (G : MultiGraph (d+1) m) (hr : 1 ≤ r) (hfuel : r ≤ fuel) + (hn : 2 ≤ d+1) (hp : G.TreePackable univ r) : + G.SpanningTree (iterate R fuel r d m G) ∧ + ∀S : Finset (Fin (d+1)), ((G.cut (iterate R fuel r d m G) S).card:ℝ) ≤ + R*(potential r/(r:ℝ))*(G.cut univ S).card := by + induction fuel generalizing r m with + | zero => omega + | succ fuel ih => + have hrR : (0:ℝ) < r := by exact_mod_cast (show 0 < r by omega) + have hRR : (0:ℝ) < R := by exact_mod_cast (show 0 < R by omega) + by_cases hlarge : R ≤ r + · obtain ⟨_,hhalf,hpos,hpack,hcut,hratio⟩ := hround r hlarge d m G hn hp + have hlt : nextCount r < r := by + exact_mod_cast (show (nextCount r:ℝ)<(r:ℝ) by linarith only [hhalf,hrR]) + have ih' := ih (nextCount r) (sparsify G r).card (OrderedGraph.restrict G (sparsify G r)) + hpos (by omega) (OrderedGraph.restrict_packable G _ hpack) + rw [iterate,ite_eq_left hlarge] + refine ⟨(OrderedGraph.restrict_spanningTree G _ _).mp ih'.1,?_⟩ + intro S + have ht := ih'.2 S + rw [OrderedGraph.restrict_cut_card,OrderedGraph.restrict_cut_card,OrderedGraph.lift_univ] at ht + have hcoef : 0 ≤ R*(potential (nextCount r)/(nextCount r:ℝ)) := by + exact mul_nonneg hRR.le (div_nonneg (potential_pos _).le (Nat.cast_nonneg _)) + calc + _ ≤ R*(potential (nextCount r)/(nextCount r:ℝ))*(G.cut (sparsify G r) S).card := ht + _ ≤ R*(potential (nextCount r)/(nextCount r:ℝ))* + ((1/2+3*halfError r)*(G.cut univ S).card) := + mul_le_mul_of_nonneg_left (hcut S) hcoef + _ = R*(potential (nextCount r)/(nextCount r:ℝ)*(1/2+3*halfError r))* + (G.cut univ S).card := by ring + _ ≤ R*(potential r/(r:ℝ))*(G.cut univ S).card := + mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (coefficient_step (by omega) hpos hhalf hratio) hRR.le) + (Nat.cast_nonneg _) + · rw [iterate,ite_eq_right hlarge] + refine ⟨GreedyTree.tree_correct G (packing_connected G (by omega) hp),?_⟩ + intro S + have hrleR : (r:ℝ) ≤ R := by exact_mod_cast (show r ≤ R by omega) + have hcoef : 1 ≤ R*(potential r/(r:ℝ)) := by + rw [←mul_div_assoc] + apply (le_div_iff₀ hrR).mpr + have hh := mul_le_mul_of_nonneg_left (potential_one_le hr) hRR.le + nlinarith only [hh,hrleR] + have hc : ((G.cut (GreedyTree.tree G) S).card:ℝ) ≤ (G.cut univ S).card := by + exact_mod_cast G.cut_card_le_full (GreedyTree.tree G) S + exact hc.trans (le_mul_of_one_le_left (Nat.cast_nonneg _) hcoef) + +def initialCount (k : ℕ) : ℕ := max 1 (k/2) +lemma initialCount_pos (k : ℕ) : 1 ≤ initialCount k := le_max_left _ _ +lemma initialCount_lower (k : ℕ) : k ≤ 3*initialCount k := by + unfold initialCount + omega + +lemma initial_packable {n m k : ℕ} (G : MultiGraph n m) (hn : 0 < n) (hk : 1 ≤ k) + (hc : G.EdgeConnected k) : G.TreePackable univ (initialCount k) := by + by_cases hk2 : 2 ≤ k + · have hr : 0 < k/2 := Nat.div_pos hk2 (by norm_num) + have he : initialCount k=k/2 := max_eq_right hr + rw [he] + apply G.edgeConnected_treePackable hr hn + intro S hS hS' + exact (show 2*(k/2) ≤ k by omega).trans (hc S hS hS') + · have hconn : G.Connected univ := by + intro S hS hS' + apply card_pos.mp + exact hk.trans (hc S hS hS') + have he : initialCount k=1 := by unfold initialCount; omega + rw [he] + refine ⟨fun _ => GreedyTree.tree G,fun _ => ⟨subset_univ _,GreedyTree.tree_correct G hconn⟩,?_⟩ + intro i j hij + exact (hij (Subsingleton.elim i j)).elim + +def tree (R k : ℕ) {d m : ℕ} (G : MultiGraph (d+1) m) : Finset (Fin m) := + iterate R (initialCount k) (initialCount k) d m G + +theorem tree_correct : ∃R : ℕ, 4 ≤ R ∧ ∃C : ℝ, 0 < C ∧ + ∀(d m k : ℕ) (G : MultiGraph (d+1) m), 2 ≤ d+1 → 1 ≤ k → G.EdgeConnected k → + G.SpanningTree (tree R k G) ∧ + ∀S : Finset (Fin (d+1)), ((G.cut (tree R k G) S).card:ℝ) ≤ + C/(k:ℝ)*(G.cut univ S).card := by + obtain ⟨R,hR,hround⟩ := sparsification_correct + have hRR : (0:ℝ) < R := by exact_mod_cast (show 0 < R by omega) + let C : ℝ := 3*R*Real.exp lossB + have hC : 0 < C := by dsimp [C]; positivity + refine ⟨R,hR,C,hC,?_⟩ + intro d m k G hn hk hc + have hr := initialCount_pos k + obtain ⟨hT,hthin⟩ := iterate_bound hR hround (initialCount k) (initialCount k) d m G + hr le_rfl hn (initial_packable G (by omega) hk hc) + refine ⟨hT,fun S => (hthin S).trans ?_⟩ + apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) + have hrR : (0:ℝ) < initialCount k := by exact_mod_cast hr + have hkR : (0:ℝ) < k := by exact_mod_cast hk + rw [←mul_div_assoc] + apply (div_le_div_iff₀ hrR hkR).mpr + have hrk : (k:ℝ) ≤ 3*(initialCount k:ℝ) := by exact_mod_cast initialCount_lower k + have hx := mul_le_mul_of_nonneg_left (potential_le (initialCount k)) hRR.le + have hm := mul_le_mul_of_nonneg_left hrk (mul_pos hRR (Real.exp_pos lossB)).le + have hl := mul_le_mul_of_nonneg_right hx hkR.le + dsimp [C] + nlinarith only [hm,hl] + +end AlgorithmicThinTrees.Iteration +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/Realization.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/Realization.lean new file mode 100644 index 0000000000000000000000000000000000000000..dce6b036c8946e7672892daa626f5b11087b222c --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/Realization.lean @@ -0,0 +1,299 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Realization +import OAI.Combinatorics.ThinTrees.Continuation.BitBound +import OAI.Combinatorics.ThinTrees.Sparsification.Step + +namespace OAI + +/-! Sparsification realization. -/ + +section + +namespace CurrentKS.Realization +open CleanRoutine KS.W23 + +def ratNatFloorBinary : Realizes ratCode binaryNatCode (fun q => ⌊q⌋₊) := + ((((constant ratCode ratCode 0).max (identity ratCode)).then ratFloor).then + ratNumBinary).congr (by + intro q + have he : (⌊max 0 q⌋ : ℤ)=(⌊q⌋₊ : ℤ) := by + by_cases hq : 0 ≤ q + · rw [max_eq_right hq,Int.natCast_floor_eq_floor hq] + · rw [max_eq_left (le_of_not_ge hq),Int.floor_zero,Nat.floor_eq_zero.mpr (by linarith)] + rfl + change KS.W01.intPayload ⌊max 0 q⌋=⌊q⌋₊ + rw [he,intPayload_natCast]) +instance poly_ratNatFloorBinary : PolyTime ratNatFloorBinary := by + unfold ratNatFloorBinary;infer_instance + +lemma runsPoly_binaryToNat {ι : Type*} {L : ι → ℕ} (a : ι → ℕ) + (ha : IsPoly L (fun i => (binaryNatCode (a i)).length)) (hn : IsPoly L a) : + RunsPoly L binaryToNat a := by + refine ⟨ha,?_⟩ + exact (((isPoly_const L 6).mul hn).add ((isPoly_const L 4).mul ha)).add (isPoly_const L 4) + +end CurrentKS.Realization + +namespace AlgorithmicThinTrees.GraphicHalf.Stack +open CurrentKS.Realization CurrentKS.CleanRoutine KS.W23 Matrix StrongThinTree Finset +open MetricTests MetricTests.RationalStep Normalization GraphStack +open MetricTests.RationalStep.Stack + +structure Problem where + d : ℕ + m : ℕ + r : ℕ + G : MultiGraph (d+1) m + +def Problem.graph (p : Problem) : Graph := ⟨p.d+1,p.m,p.G⟩ +def problemCode (p : Problem) : Word := extractionInputCode (p.graph,p.r) +abbrev problemView : Realizes problemCode extractionInputCode (fun p => (p.graph,p.r)) := + (identity extractionInputCode).reindex problemCode (fun p => (p.graph,p.r)) (fun _ => rfl) +private instance poly_problemView : PolyTime problemView := by + unfold problemView + apply poly_reindex + +abbrev problemGraph := problemView.then extractionGraph +abbrev problemCount := problemView.then extractionCount +abbrev problemN := problemGraph.then numVertices +abbrev problemM := problemGraph.then numEdges + +private theorem poly_problemM : PolyTime problemM := by + unfold problemM + apply poly_then + +def problemD : Realizes problemCode natCode Problem.d := + (problemN.then natPred).congr (fun _ => rfl) +instance poly_problemD : PolyTime problemD := by unfold problemD; apply poly_congr + +def extraction : Realizes problemCode loopCode (fun p => ⟨p.graph,p.r,extractState p.G p.r⟩) := + problemView.then extract +instance poly_extraction : PolyTime extraction := by unfold extraction; apply poly_then +abbrev Problem.state (p : Problem) := extractState p.G p.r +abbrev Problem.active (p : Problem) := p.state.active +abbrev Problem.q (p : Problem) := p.state.packingTarget +abbrev Problem.scales (p : Problem) := normalizedScales p.q p.r (graphColumns p.G p.active) + +lemma packingTarget_le (p : Problem) : p.q ≤ p.r := by + have h := (stateAt_quality p.G p.r (scheduleLength p.m p.r)).2 + have hq : p.state.quality ≤ (p.r:ℚ) := by exact_mod_cast h + exact (Nat.floor_mono (show p.state.quality-1 ≤ (p.r:ℚ) by linarith)).trans_eq (Nat.floor_natCast _) + +def targetBinary : Realizes problemCode binaryNatCode Problem.q := + (((extraction.then loopQuality).sub (constant problemCode ratCode 1)).then ratNatFloorBinary) +instance poly_targetBinary : PolyTime targetBinary := by unfold targetBinary; apply poly_then + +def targetCount : Realizes problemCode natCode Problem.q := targetBinary.then binaryToNat +instance poly_targetCount : PolyTime targetCount := by + apply PolyTime.mk + have ht := RunsPoly.of_poly targetBinary id (isPoly_self (fun p => (problemCode p).length)) + have hn : IsPoly (fun p => (problemCode p).length) Problem.r := + ((RunsPoly.of_poly problemCount id (isPoly_self (fun p => (problemCode p).length))).output).mono + (fun p => by simp only [natCode,List.length_replicate];rfl) + exact (ht.then (runsPoly_binaryToNat _ ht.output (hn.mono packingTarget_le))).cost + +abbrev Edge := Σ p : Problem, Fin p.m +abbrev edgeCode := finFamilyCode problemCode Problem.m +abbrev context : Realizes edgeCode problemCode (fun p : Edge => p.1) := familyFirst +abbrev number : Realizes edgeCode natCode (fun p : Edge => p.2.val) := familyIndex + +def edgeGraphInput : Realizes edgeCode GraphStack.edgeCode (fun p => ⟨p.1.graph,p.2⟩) := + ((context.then problemGraph).both number).changeOutput GraphStack.edgeCode + (fun p => ⟨p.1.graph,p.2⟩) (fun _ => rfl) +instance poly_edgeGraphInput : PolyTime edgeGraphInput := by unfold edgeGraphInput; apply poly_changeOutput + +def edgeActive : Realizes edgeCode boolCode (fun p => decide (p.2 ∈ p.1.active)) := + ((constant edgeCode ratCode 0).lt + ((number.both (context.then extraction |>.then loopCapacity)).then (getD ratCode 0))).congr + (by + intro p + change decide ((0:ℚ) < (List.ofFn p.1.state.capacity).getD p.2.val 0)=_ + simp only [getD_ofFn,Problem.active,State.active,mem_filter,mem_univ,true_and]) +instance poly_edgeActive : PolyTime edgeActive := by unfold edgeActive;infer_instance + +def fullColumn : Realizes edgeCode vectorCode (fun p => List.ofFn (fullColumns p.1.G p.1.active p.2)) := + (edgeActive.ite (edgeGraphInput.then incidence) + (((constant edgeCode ratCode 0).both (context.then problemN)).then (replicateList ratCode))).congr + (by + intro p + simp only [decide_eq_true_eq] + split_ifs with h + · rw [fullColumns,ite_eq_left h];rfl + · rw [fullColumns,ite_eq_right h] + change List.replicate (p.1.d+1) (0:ℚ)=List.ofFn (fun _ : Fin (p.1.d+1) => (0:ℚ)) + exact (List.ofFn_const _ (0:ℚ)).symm) +instance poly_fullColumn : PolyTime fullColumn := by unfold fullColumn; apply poly_congr + +def fullRows : Realizes problemCode matrixCode (fun p => matrixData (fullColumns p.G p.active)) := + fullColumn.tabulateFin problemM +instance poly_fullRows : PolyTime fullRows := by + unfold fullRows + exact @poly_tabulateFin _ _ _ _ _ _ _ _ poly_fullColumn poly_problemM + +abbrev Coordinate := Σ e : Edge, Fin e.1.d +abbrev coordCode := finFamilyCode edgeCode (fun e : Edge => e.1.d) +abbrev coordEdge : Realizes coordCode edgeCode (fun x : Coordinate => x.1) := familyFirst +abbrev coordIndex : Realizes coordCode natCode (fun x : Coordinate => x.2.val) := familyIndex + +lemma graphColumns_drop (p : Problem) (e : Fin p.m) (i : Fin p.d) : + fullColumns p.G p.active e i.succ=graphColumns p.G p.active e i := by + simp only [fullColumns,graphColumns,integerColumns,qdiff] + by_cases h : e ∈ p.active + · simp only [ite_eq_left h,Pi.sub_apply] + simp [Pi.single_apply,eq_comm] + · simp only [ite_eq_right h,Pi.zero_apply,Int.cast_zero] + +def reducedEntry : Realizes coordCode ratCode + (fun x => graphColumns x.1.1.G x.1.1.active x.1.2 x.2) := + (((coordIndex.then natSucc).both (coordEdge.then fullColumn)).then (getD ratCode 0)).congr + (by + intro x + change (List.ofFn (fullColumns x.1.1.G x.1.1.active x.1.2)).getD x.2.succ.val 0=_ + rw [getD_ofFn];exact graphColumns_drop _ _ _) +instance poly_reducedEntry : PolyTime reducedEntry := by unfold reducedEntry;infer_instance + +def reducedColumn : Realizes edgeCode vectorCode (fun p => List.ofFn (graphColumns p.1.G p.1.active p.2)) := + reducedEntry.tabulateFin (context.then problemD) +instance poly_reducedColumn : PolyTime reducedColumn := by unfold reducedColumn;infer_instance + +def reducedRows : Realizes problemCode matrixCode (fun p => matrixData (graphColumns p.G p.active)) := + reducedColumn.tabulateFin problemM +instance poly_reducedRows : PolyTime reducedRows := by + unfold reducedRows + exact @poly_tabulateFin _ _ _ _ _ _ _ _ poly_reducedColumn poly_problemM + +def Problem.normalization (p : Problem) : Normalization.Stack.Params := + ⟨p.d,p.m,p.q,0,graphColumns p.G p.active⟩ + +def normalizationParams : Realizes problemCode Normalization.Stack.paramsCode Problem.normalization := + (problemD.both (targetCount.both ((constant problemCode ratCode 0).both reducedRows))).changeOutput + Normalization.Stack.paramsCode Problem.normalization (fun _ => rfl) +instance poly_normalizationParams : PolyTime normalizationParams := by unfold normalizationParams; apply poly_changeOutput + +def scales : Realizes problemCode vectorCode (fun p => List.ofFn p.scales) := + (normalizationParams.both problemCount).then Normalization.Stack.normalized +instance poly_scales : PolyTime scales := by unfold scales; apply poly_then + +def positiveMatrix : Realizes problemCode matrixCode (fun p => matrixData (positiveForm p.state.matrix)) := + ((extraction.then loopMatrix).both + ((problemN.both ((constant problemCode ratCode 1).div (problemN.then natToRat))).then + constantMatrix)).then matrixAdd |>.congr (by + intro p + change matrixAddData (matrixData p.state.matrix,matrixData (Matrix.of (fun (_ _ : Fin (p.d+1)) => 1/((p.d+1:ℕ):ℚ))))=_ + change zipDefault (zipDefault (fun p : ℚ×ℚ => p.1+p.2) 0 0) [] [] + (matrixData p.state.matrix,matrixData (Matrix.of (fun (_ _ : Fin (p.d+1)) => 1/((p.d+1:ℕ):ℚ))))=_ + rw [matrixAdd_data] + simp only [one_div] + rfl) +instance poly_positiveMatrix : PolyTime positiveMatrix := by unfold positiveMatrix; apply poly_congr + +def secondMatrix : Realizes problemCode matrixCode (fun p => matrixData (scaledForm p.G p.active p.scales)) := + let state := (normalizationParams.both scales).changeOutput Normalization.Stack.stateCode + (fun p : Problem => ⟨p.normalization,p.scales⟩) (fun _ => rfl) + state.then Normalization.Stack.gram +instance poly_secondMatrix : PolyTime secondMatrix := by + unfold secondMatrix + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ ?_ + · apply poly_changeOutput + · infer_instance + +def scaledRows : Realizes problemCode matrixCode (fun p => matrixData (scaledColumns p.G p.active p.scales)) := + ((scales.both reducedRows).then (vectorScale.zipWith 0 [])).congr (by + intro p + change zipDefault (fun p : ℚ×List ℚ => p.2.map (fun x => p.1*x)) 0 [] + (List.ofFn p.scales,List.ofFn (fun e => List.ofFn (graphColumns p.G p.active e)))=_ + rw [zipDefault_ofFn] + simp only [List.map_ofFn,Function.comp_def] + rfl) +instance poly_scaledRows : PolyTime scaledRows := by unfold scaledRows;infer_instance + +def Problem.forms (p : Problem) : Signing.Stack.FormPair := + ⟨⟨p.d+1,positiveForm p.state.matrix⟩,⟨p.d,scaledForm p.G p.active p.scales⟩, + p.m,fullColumns p.G p.active,scaledColumns p.G p.active p.scales⟩ + +def forms : Realizes problemCode Signing.Stack.formsCode Problem.forms := + (((problemN.both positiveMatrix).both fullRows).both + ((problemD.both secondMatrix).both scaledRows)).changeOutput Signing.Stack.formsCode + Problem.forms (fun _ => rfl) +instance poly_forms : PolyTime forms := by unfold forms; apply poly_changeOutput + +abbrev MaskInput := Problem × List Bool +abbrev maskCode := prodCode problemCode (listCode boolCode) +abbrev maskProblem := first problemCode (listCode boolCode) +abbrev maskSigns := second problemCode (listCode boolCode) +abbrev MaskEdge := Σ p : MaskInput, Fin p.1.m +abbrev maskEdgeCode := finFamilyCode maskCode (fun p : MaskInput => p.1.m) +abbrev maskContext : Realizes maskEdgeCode maskCode (fun p : MaskEdge => p.1) := familyFirst +abbrev maskIndex : Realizes maskEdgeCode natCode (fun p : MaskEdge => p.2.val) := familyIndex + +def maskEdgeInput : Realizes maskEdgeCode edgeCode (fun p => ⟨p.1.1,p.2⟩) := + ((maskContext.then maskProblem).both maskIndex).changeOutput edgeCode + (fun p => ⟨p.1.1,p.2⟩) (fun _ => rfl) +instance poly_maskEdgeInput : PolyTime maskEdgeInput := by unfold maskEdgeInput; apply poly_changeOutput + +def maskBit : Realizes maskEdgeCode boolCode + (fun p => if p.2 ∈ p.1.1.active then p.1.2.getD p.2.val false else false) := + ((maskEdgeInput.then edgeActive).ite + ((maskIndex.both (maskContext.then maskSigns)).then (getD boolCode false)) + (constant maskEdgeCode boolCode false)).congr (by intro p;simp only [decide_eq_true_eq]) +instance poly_maskBit : PolyTime maskBit := by unfold maskBit;infer_instance + +def mask : Realizes maskCode (listCode boolCode) + (fun p => List.ofFn (fun e : Fin p.1.m => + if e ∈ p.1.active then p.2.getD e.val false else false)) := + maskBit.tabulateFin (maskProblem.then problemM) +instance poly_mask : PolyTime mask := by + have hm : PolyTime (maskProblem.then problemM) := by + refine @poly_then _ _ _ _ _ _ _ _ _ _ ?_ poly_problemM + infer_instance + unfold mask + exact @poly_tabulateFin _ _ _ _ _ _ _ _ poly_maskBit hm + +def signsProgram := forms.then Signing.Stack.simultaneousSigns + +def sparsifyProgram : Realizes problemCode (listCode boolCode) + (fun p => List.ofFn (fun e => decide (e ∈ sparsify p.G p.r))) := + (((identity problemCode).both signsProgram).then mask).congr (by + intro p + apply congrArg List.ofFn + funext e + change (if e ∈ p.active then _ else false)=_ + simp only [sparsify,halfEdges,FormSigning.selected,StackedSigning.selected, + RationalSigning.selected,mem_inter,mem_filter,mem_univ,true_and] + by_cases h : e ∈ p.active + · simp [h,Problem.forms,Problem.active,Problem.state,Problem.scales,Problem.q] at * + · simp [h] at *) + +theorem sparsify_program_polynomial : ∃R : ℕ, 4 ≤ R ∧ ∀{ι : Type} {L : ι → ℕ} + (a : ι → Problem), IsPoly L (fun i => (problemCode (a i)).length) → + (∀i, R ≤ (a i).r ∧ 2 ≤ (a i).d+1 ∧ (a i).G.TreePackable univ (a i).r) → + RunsPoly L sparsifyProgram a := by + obtain ⟨R,hR,hstep⟩ := shortcut_correct + refine ⟨R,(by norm_num : 4 ≤ 64^16).trans hR,?_⟩ + intro ι L a ha hp + have hforms := RunsPoly.of_poly forms a ha + have hsigns : RunsPoly L signsProgram a := by + apply hforms.then + apply Signing.Stack.runsPoly_simultaneousSigns _ hforms.output + · intro i + obtain ⟨hX,_,_,_,_,_⟩ := hstep (a i).r (hp i).1 _ _ (a i).G (hp i).2.1 (hp i).2.2 + change ((positiveForm (a i).state.matrix).map (fun q : ℚ => (q:ℝ))).PosDef + rw [positiveForm_cast] + have hr : 0 < (a i).r := (by norm_num : 0 < 64^16).trans_le (hR.trans (hp i).1) + exact regularize_pd (by omega) (domain_positive (a i).G (by omega) + (packing_connected (a i).G hr (hp i).2.2) hX) + · intro i + obtain ⟨hX,hpack,hqpos,hqr,_,_⟩ := hstep (a i).r (hp i).1 _ _ (a i).G (hp i).2.1 (hp i).2.2 + obtain ⟨hs,_,_⟩ := graphic_normalization (a i).G (a i).active hqpos hqr hpack + change ((scaledForm (a i).G (a i).active (a i).scales).map (fun q : ℚ => (q:ℝ))).PosDef + rw [scaledForm_cast] + obtain ⟨F⟩ := graph_containedPacking (a i).G (a i).active hqpos hpack + exact F.covariance_posDef _ (realWeights_box hs).1 + unfold sparsifyProgram + apply RunsPoly.congr + exact ((RunsPoly.of_poly (identity problemCode) a ha).both hsigns).then_poly mask + +end AlgorithmicThinTrees.GraphicHalf.Stack +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/ShortcutExtraction.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/ShortcutExtraction.lean new file mode 100644 index 0000000000000000000000000000000000000000..796d5b2e74c00965b72674075de8e0ab349156cc --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/ShortcutExtraction.lean @@ -0,0 +1,160 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Continuation.Loop +import OAI.Combinatorics.ThinTrees.Signing.Realization + +namespace OAI + +/-! Shortcut extraction. -/ + +section + +namespace AlgorithmicThinTrees.MetricTests.RationalStep +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph Partitions +open scoped MatrixOrder +variable {n m : ℕ} + +def State.active (a : State n m) : Finset (Fin m) := univ.filter (fun e => 0 < a.capacity e) + +def State.packingTarget (a : State n m) : ℕ := ⌊a.quality-1⌋₊ + +lemma active_mem (a : State n m) (e : Fin m) : e ∈ a.active ↔ 0 < (a.capacity e:ℝ) := by + simp only [State.active,mem_filter,mem_univ,true_and] + exact_mod_cast Iff.rfl + +lemma baseline_total_lt_one (m : ℕ) : (m:ℝ)*continuationBaseline m < 1 := by + unfold continuationBaseline + rw [mul_one_div] + exact (div_lt_one (by positivity)).mpr (by linarith) + +lemma sum_capacity_le_active (H : MultiGraph n m) (a : State n m) + (hu : ∀e, 0 ≤ (a.capacity e:ℝ) ∧ (a.capacity e:ℝ) ≤ 1) + (p : Fin n → Fin n) : + capacity H.left H.right (fun e => (a.capacity e:ℝ)+continuationBaseline m) (Setoid.ker p) < + ((H.crossing a.active p).card:ℝ)+1 := by + classical + rw [capacity_eq_sum,Orientations.crossing_ker,sum_add_distrib] + have hmain : (∑e ∈ H.crossing univ p, (a.capacity e:ℝ)) ≤ (H.crossing a.active p).card := by + have he : H.crossing a.active p=(H.crossing univ p).filter (fun e => 0 < a.capacity e) := by + ext e + simp only [MultiGraph.crossing,State.active,mem_filter,mem_univ,true_and] + tauto + rw [he,←Finset.sum_boole] + apply sum_le_sum + intro e _ + by_cases h : 0 < a.capacity e + · simpa only [h,ite_true] using (hu e).2 + · have hh : ¬0 < (a.capacity e:ℝ) := by exact_mod_cast h + simpa only [h,ite_false] using not_lt.mp hh + have hcount : (H.crossing univ p).card ≤ m := (card_le_card (filter_subset _ _)).trans_eq (card_fin _) + have hbase : (∑_e ∈ H.crossing univ p, continuationBaseline m) < 1 := by + simp only [sum_const,nsmul_eq_mul] + exact (mul_le_mul_of_nonneg_right (by exact_mod_cast hcount) (continuation_parameters m).1.le).trans_lt + (baseline_total_lt_one m) + linarith only [hmain,hbase] + +lemma active_packable (H : MultiGraph n m) (hn : 0 < n) (a : State n m) + (ha : Invariant H a) {q : ℕ} (hq : 0 < q) (hqQ : (q:ℝ) ≤ (a.quality:ℝ)-1) : + H.TreePackable a.active q := by + apply H.partition_criterion_sufficient a.active hq hn + intro p + by_cases hp : partitionSize p ≤ 1 + · have he : partitionSize p-1=0 := by omega + simp only [he,mul_zero,Nat.zero_le] + · have hp2 : 2 ≤ partitionSize p := by omega + have hslack := ha.2.2.2 (Setoid.ker p) + rw [slack,sub_nonneg,Orientations.partCount_ker] at hslack + have hcap := sum_capacity_le_active H a (fun e => ⟨(ha.2.2.1 e).1,(ha.2.2.1 e).2.1⟩) p + have hd : (1:ℝ) ≤ (partitionSize p:ℝ)-1 := by + have hh : (2:ℝ) ≤ partitionSize p := by exact_mod_cast hp2 + linarith only [hh] + have hm := mul_le_mul_of_nonneg_right hqQ (by linarith : (0:ℝ) ≤ (partitionSize p:ℝ)-1) + have hnat : ((q*(partitionSize p-1):ℕ):ℝ)=(q:ℝ)*((partitionSize p:ℝ)-1) := by + rw [Nat.cast_mul,Nat.cast_sub (by omega : 1 ≤ partitionSize p),Nat.cast_one] + have hh : ((q*(partitionSize p-1):ℕ):ℝ) ≤ ((H.crossing a.active p).card:ℝ) := by + rw [hnat] + nlinarith only [hm,hcap,hslack,hd] + exact_mod_cast hh + +lemma packingTarget_lower (a : State n m) : + (a.quality:ℝ)-2 ≤ (a.packingTarget:ℝ) := by + have hh := Nat.lt_floor_add_one (a.quality-1) + have hc : (a.quality:ℝ)-1 < (a.packingTarget:ℝ)+1 := by + exact_mod_cast hh + linarith only [hc] + +lemma packingTarget_upper (a : State n m) (hq : 1 ≤ (a.quality:ℝ)) : + (a.packingTarget:ℝ) ≤ (a.quality:ℝ)-1 := by + have hi : (0:ℚ) ≤ a.quality-1 := by exact_mod_cast (sub_nonneg.mpr hq) + exact_mod_cast Nat.floor_le hi + +lemma packingTarget_pos (a : State n m) (hq : 2 ≤ (a.quality:ℝ)) : 0 < a.packingTarget := by + apply Nat.floor_pos.mpr + exact_mod_cast (show (1:ℝ) ≤ (a.quality:ℝ)-1 by linarith only [hq]) + +lemma active_resistance (H : MultiGraph n m) (hn : 0 < n) (hc : H.Connected univ) + (a : State n m) (ha : Invariant H a) (e : Fin m) (he : e ∈ a.active) : + resistance H a.realMatrix e < (a.scale:ℝ)⁻¹ := by + have hX := domain_positive H hn hc ha.2.1 + have hR := centered_resistance_pos H hn hX e + have hramp := (active_mem a e).mp he |>.trans_le (ha.2.2.1 e).2.2 + have hp := (ramp_active H hramp).1 + have hrec : 1 < ((a.scale:ℝ)*resistance H a.realMatrix e)⁻¹ := + hp.trans_le (min_le_right _ _) + have hprod := (inv_lt_inv₀ (by norm_num : (0:ℝ)<1) (mul_pos ha.1 hR)).mp + (by simpa using hrec) + rw [←one_div] + apply (lt_div_iff₀ ha.1).mpr + nlinarith only [hprod] + +lemma rounding_absorbed (r : ℕ) (hr : 1 ≤ r) : 1 ≤ (r:ℝ)^(-1/16:ℝ)*r := by + have hp : (0:ℝ) < r := by exact_mod_cast (show 0 < r by omega) + have he : (r:ℝ)^(-1/16:ℝ)*r=(r:ℝ)^(15/16:ℝ) := by + conv_lhs => arg 2; rw [←Real.rpow_one (r:ℝ)] + rw [←Real.rpow_add hp] + norm_num + rw [he] + exact Real.one_le_rpow (by exact_mod_cast hr) (by norm_num) + +theorem shortcut_correct : ∃R : ℕ, 64^16 ≤ R ∧ ∀r : ℕ, R ≤ r → + ∀(n m : ℕ) (H : MultiGraph n m), 2 ≤ n → H.TreePackable univ r → + let a := extractState H r + a.realMatrix ∈ metricDomain H ∧ H.TreePackable a.active a.packingTarget ∧ + 0 < a.packingTarget ∧ a.packingTarget ≤ r ∧ + (1-6*(r:ℝ)^(-1/16:ℝ))*r ≤ (a.packingTarget:ℝ) ∧ + ∀e ∈ a.active, resistance H a.realMatrix e ≤ (r:ℝ)^(-1/4:ℝ) := by + obtain ⟨R,hR,hcorrect⟩ := extractState_correct + refine ⟨R,hR,?_⟩ + intro r hr n m H hn hpack + dsimp only + have hrlarge : 64^16 ≤ r := hR.trans hr + have hr3 : 3 ≤ r := (by norm_num : 3 ≤ 64^16).trans hrlarge + have hr0 : 0 < r := by omega + have hconn := packing_connected H hr0 hpack + obtain ⟨ha,hscale,hlower,hupper⟩ := hcorrect r hr n m H hn hpack + have hQ : 2 ≤ ((extractState H r).quality:ℝ) := by + have hl := (running_quality_lower m r (scheduleLength m r) hrlarge le_rfl).trans + (stateAt_quality H r (scheduleLength m r)).1 + change 3*(r:ℝ)/4 ≤ ((extractState H r).quality:ℝ) at hl + have hrR : (3:ℝ) ≤ r := by exact_mod_cast hr3 + linarith only [hl,hrR] + have hqpos := packingTarget_pos (extractState H r) hQ + have hqupper := packingTarget_upper (extractState H r) (by linarith only [hQ]) + refine ⟨ha.2.1,active_packable H (by omega) (extractState H r) ha hqpos hqupper,hqpos,?_,?_,?_⟩ + · exact_mod_cast (show ((extractState H r).packingTarget:ℝ) ≤ r by linarith only [hqupper,hupper]) + · have hfloor := packingTarget_lower (extractState H r) + have hrnd := rounding_absorbed r (by omega) + nlinarith only [hfloor,hlower,hrnd] + · intro e he + have hres := active_resistance H (by omega) hconn (extractState H r) ha e he + have hpow : 0 < (r:ℝ)^(1/4:ℝ) := Real.rpow_pos_of_pos (by exact_mod_cast hr0) _ + have hrec := inv_anti₀ hpow hscale + have heq : ((r:ℝ)^(1/4:ℝ))⁻¹=(r:ℝ)^(-1/4:ℝ) := by + rw [←Real.rpow_neg (Nat.cast_nonneg r)] + congr 1 + norm_num + exact hres.le.trans (heq ▸ hrec) + +end AlgorithmicThinTrees.MetricTests.RationalStep +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Sparsification/Step.lean b/lean/OAI/Combinatorics/ThinTrees/Sparsification/Step.lean new file mode 100644 index 0000000000000000000000000000000000000000..297eb63bf76663c2da17521f56011cbc986e391e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Sparsification/Step.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Combinatorics.ThinTrees.Sparsification.GraphCertificates +import OAI.Combinatorics.ThinTrees.Sparsification.HalfNumeric + +namespace OAI + +/-! Sparsification step. -/ + +section + +namespace AlgorithmicThinTrees.GraphicHalf +open Matrix Finset StrongThinTree StrongThinTree.MultiGraph +open MetricTests MetricTests.RationalStep Normalization RationalSigning +open scoped MatrixOrder +variable {d m : ℕ} + +def sparsify (G : MultiGraph (d+1) m) (r : ℕ) : Finset (Fin m) := + let a := extractState G r + halfEdges G a.active a.matrix (normalizedScales a.packingTarget r (graphColumns G a.active)) + +theorem sparsification_correct : ∃R : ℕ, 4 ≤ R ∧ ∀r : ℕ, R ≤ r → + ∀(d m : ℕ) (G : MultiGraph (d+1) m), 2 ≤ d+1 → G.TreePackable univ r → + (r:ℝ)/4 ≤ nextCount r ∧ (nextCount r:ℝ) ≤ (r:ℝ)/2 ∧ 0 < nextCount r ∧ + G.TreePackable (sparsify G r) (nextCount r) ∧ + (∀S : Finset (Fin (d+1)), ((G.cut (sparsify G r) S).card:ℝ) ≤ + (1/2+3*halfError r)*(G.cut univ S).card) ∧ + (1/2+3*halfError r)*(r:ℝ) ≤ (1+80*errorU r)*nextCount r := by + obtain ⟨R₁,hR₁,hstep⟩ := shortcut_correct + obtain ⟨R₂,hnum⟩ := eventual_numeric + refine ⟨max R₁ R₂,?_,?_⟩ + · exact (by norm_num : 4 ≤ 64^16).trans (hR₁.trans (le_max_left _ _)) + intro r hr d m G hn hp + have hr₁ := (le_max_left _ _).trans hr + have hr₂ := (le_max_right _ _).trans hr + have hnumer := hnum r hr₂ + have hr0 : 0 < r := by have := hnumer.rlarge; omega + have hconn := packing_connected G hr0 hp + obtain ⟨hX,hpack,hqpos,hqr,hqbound,hres⟩ := hstep r hr₁ (d+1) m G hn hp + let a := extractState G r + let B := a.active + let q := a.packingTarget + let s := normalizedScales q r (graphColumns G B) + have hX' : a.realMatrix ∈ metricDomain G := hX + have hqr' : (1-6*errorU r)*(r:ℝ) ≤ q := hqbound + obtain ⟨hs,hleverage,hbits⟩ := graphic_normalization G B hqpos hqr hpack + change (∀e, 0 < s e ∧ s e ≤ 1) at hs + change (∀e, leverage (realColumns (graphColumns G B)) (realWeights s) e ≤ (1+4/(r:ℝ))/(q:ℝ)) at hleverage + have hQ : ((scaledForm G B s).map (fun x : ℚ => (x:ℝ))).PosDef := by + rw [scaledForm_cast] + obtain ⟨F⟩ := graph_containedPacking G B hqpos hpack + exact F.covariance_posDef _ (realWeights_box hs).1 + have hnorm : ∀e, realVec (fullColumns G B) e ⬝ᵥ + (((positiveForm a.matrix).map (fun x : ℚ => (x:ℝ)))⁻¹*ᵥrealVec (fullColumns G B) e)+ + leverage (realColumns (graphColumns G B)) (realWeights s) e ≤ varianceBound r := by + intro e + have hlev := (hleverage e).trans (normalized_size hnumer hqr') + have hfirst : realVec (fullColumns G B) e ⬝ᵥ + (((positiveForm a.matrix).map (fun x : ℚ => (x:ℝ)))⁻¹*ᵥrealVec (fullColumns G B) e) ≤ + (r:ℝ)^(-1/4:ℝ) := by + rw [fullColumns_cast,positiveForm_cast] + by_cases he : e ∈ B + · rw [ite_eq_left he] + exact hres e he + · rw [ite_eq_right he,zero_dotProduct] + exact Real.rpow_nonneg (Nat.cast_nonneg _) _ + unfold varianceBound + linarith only [hfirst,hlev] + obtain ⟨hlap,hframe⟩ := half_bounds G B a.matrix s hconn hX' hQ + (show 0 ≤ varianceBound r by unfold varianceBound; positivity) hnorm + change G.laplacian (sparsify G r) ≤ (1/2:ℝ) • G.laplacian B+ + halfError r • regularize a.realMatrix at hlap + change (1/2-halfError r) • (scaledForm G B s).map (fun x : ℚ => (x:ℝ)) ≤ + StackedSigning.gram (realVec (scaledColumns G B s)) (sparsify G r) at hframe + obtain ⟨hlo,hhi,hpos⟩ := nextCount_bounds hnumer + refine ⟨hlo,hhi,hpos,?_,?_,half_ratio hnumer⟩ + · apply packing_bound G hn B (sparsify G r) inter_subset_right s (fun e => (hs e).1) hQ + (c:=1/2-halfError r) (h:=(1+4/(r:ℝ))/(q:ℝ)) + · linarith only [hnumer.loss,hnumer.small] + · positivity + · exact packing_numeric hnumer hqpos hqr' + · intro e _; exact hleverage e + · exact hframe + · intro S + exact cut_bound G (by omega) (sparsify G r) B hX' + (by unfold halfError; positivity) hlap S + +end AlgorithmicThinTrees.GraphicHalf +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/SparsifyGeometry.lean b/lean/OAI/Combinatorics/ThinTrees/SparsifyGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a9a3166fc1b41c450dcc2c86253e53cb3c7d485 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/SparsifyGeometry.lean @@ -0,0 +1,98 @@ +import OAI.Combinatorics.ThinTrees.StepBounds + +namespace OAI + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree.MultiGraph +variable {n m : ℕ} (G : MultiGraph n m) +lemma laplacian_dot (B : Finset (Fin m)) (v : Fin n → ℝ) : + qform (G.laplacian B) v=∑e ∈ B, (v ⬝ᵥ G.incidence e)^2 := + qform_covariance G.incidence B v + +lemma sparsify_from_extraction (hn : 2 ≤ n) {r : ℕ} (hnum : StepNumeric r) + {X : Matrix (Fin n) (Fin n) ℝ} (hX : X ∈ G.matrixDomain) + (hp : G.TreePackable (G.thresholdEdges (G.resistance X) (4*resistanceT r)) (extractQ r)) : + ∃A : Finset (Fin m), G.TreePackable A (stepCount r) ∧ + ∀S : Finset (Fin n), S.Nonempty → S ≠ univ → + ((G.cut A S).card:ℝ) ≤ (1/2+3*splitTau r)*(G.cut univ S).card := by + classical + have hrp : 0 < r := by have := hnum.rlarge; omega + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hrp + have hu : 0 < errorU r := Real.rpow_pos_of_pos hrR _ + have ht : 0 < resistanceT r := Real.rpow_pos_of_pos hrR _ + have hε : 0 < splitEpsilon r := by unfold splitEpsilon; positivity + have hτ0 : 0 ≤ splitTau r := by unfold splitTau; positivity + have hc : 0 < 1/2-splitTau r := by have := hnum.usmall; have := hnum.tausmall; linarith + obtain ⟨F,hF,hd⟩ := hp + let B := univ.biUnion F + have hB : B ⊆ G.thresholdEdges (G.resistance X) (4*resistanceT r) := by + intro e he + obtain ⟨i,_,hei⟩ := mem_biUnion.mp he + exact (hF i).1 hei + obtain ⟨L,s,hs,hiso,hnorm⟩ := G.graph_isotropic_representation hnum.qpos hn F (fun i => (hF i).2) hd hu + let z : Fin m → Fin (n-1) → ℝ := fun e => s e • L ⟨G.incidence e,G.incidence_zeroSum e⟩ + change (∑e ∈ B, vecMulVec (z e) (z e))=1 at hiso + change ∀e ∈ B, z e ⬝ᵥ z e ≤ (1+errorU r)/(extractQ r:ℝ) at hnorm + obtain ⟨a,ha,haNorm,haTest⟩ := G.normalized_vectors (by omega) hX B + have hsum {V : Type} [AddCommMonoid V] (f : Fin m → V) : + (∑e : B, f e)=∑e ∈ B, f e := by + simpa only [attach_eq_univ] using sum_attach B f + have hnormB (e : B) : a e ⬝ᵥ a e+z e ⬝ᵥ z e ≤ splitEpsilon r := by + have hh := (mem_filter.mp (hB e.property)).2 + have hz := (hnorm e e.property).trans hnum.size + rw [haNorm] + unfold splitEpsilon + linarith + have haB (x : Fin n → ℝ) : (∑e : B, (x ⬝ᵥ a e)^2) ≤ x ⬝ᵥ x := by + rw [hsum (fun e => (x ⬝ᵥ a e)^2)]; exact ha x + have hzB (y : Fin (n-1) → ℝ) : (∑e : B, (y ⬝ᵥ z e)^2)=y ⬝ᵥ y := by + rw [hsum (fun e => (y ⬝ᵥ z e)^2),←qform_covariance,hiso,qform,one_mulVec] + obtain ⟨A₀,hAhi,hAlo⟩ := split_two_systems (fun e : B => a e) (fun e : B => z e) hε haB hzB hnormB + let A : Finset (Fin m) := A₀.image Subtype.val + have hAB : A ⊆ B := by + intro e he + obtain ⟨i,_,rfl⟩ := mem_image.mp he + exact i.property + have hsumA {V : Type} [AddCommMonoid V] (f : Fin m → V) : + (∑e ∈ A, f e)=∑e ∈ A₀, f e := by + exact sum_image (fun _ _ _ _ h => Subtype.ext h) + have hlow : ((∑e ∈ A, vecMulVec (z e) (z e))- + (1/2-splitTau r) • (1 : Matrix (Fin (n-1)) (Fin (n-1)) ℝ)).PosSemidef := by + apply Matrix.PosSemidef.of_dotProduct_mulVec_nonneg + ((Matrix.posSemidef_sum A (fun e _ => by + simpa only [star_trivial] using posSemidef_vecMulVec_self_star (z e))).isHermitian.sub + (Matrix.PosSemidef.one.smul hc.le).isHermitian) + intro y + have hh := hAlo y + change (1/2-splitTau r)*(y ⬝ᵥ y) ≤ ∑e ∈ A₀, (y ⬝ᵥ z e)^2 at hh + rw [←hsumA (fun e => (y ⬝ᵥ z e)^2)] at hh + change 0 ≤ qform _ y + rw [qform_sub,qform_covariance,qform_smul,qform,one_mulVec] + linarith + have hpack := G.projected_trace_treePackable hn hnum.qpos hu hc L s hs A B hAB hnorm hlow + refine ⟨A,G.treePackable_mono_count hnum.packing hpack,?_⟩ + intro S hS hS' + obtain ⟨x,hx,he⟩ := haTest (cutIndicator S) + have hh := hAhi x + change (∑e ∈ A₀, (x ⬝ᵥ a e)^2) ≤ + (1/2:ℝ)*(∑e : B, (x ⬝ᵥ a e)^2)+splitTau r*(x ⬝ᵥ x) at hh + rw [←hsumA (fun e => (x ⬝ᵥ a e)^2),hsum (fun e => (x ⬝ᵥ a e)^2),hx] at hh + simp_rw [he] at hh + rw [←G.laplacian_dot,←G.laplacian_dot,G.laplacian_cut,G.laplacian_cut] at hh + have hcutSub : G.cut B S ⊆ G.cut univ S := by + intro e he + exact mem_filter.mpr ⟨mem_univ _,(mem_filter.mp he).2⟩ + have hcut : ((G.cut B S).card:ℝ) ≤ (G.cut univ S).card := by exact_mod_cast card_le_card hcutSub + have hXcut := mul_le_mul_of_nonneg_left (hX.2 S hS hS') hτ0 + nlinarith + +end StrongThinTree.MultiGraph + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/SpectralPacking.lean b/lean/OAI/Combinatorics/ThinTrees/SpectralPacking.lean new file mode 100644 index 0000000000000000000000000000000000000000..849e94941fe7c1304daa7f6b4ca936db8cd22107 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/SpectralPacking.lean @@ -0,0 +1,805 @@ +import OAI.Combinatorics.ThinTrees.Shells + +namespace OAI + +universe uE uι uι2 uV uι3 uV2 uV3 uV4 uV5 uV6 uι4 uη + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.Spectral +noncomputable section +open Finset LinearMap +open scoped InnerProductSpace +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + +def frobSq (T : E →ₗ[ℝ] E) : ℝ := LinearMap.trace ℝ E (T.adjoint ∘ₗ T) + +lemma frobSq_eq_sum {ι : Type uι} [Fintype ι] (b : OrthonormalBasis ι ℝ E) (T : E →ₗ[ℝ] E) : + frobSq T = ∑i, ‖T (b i)‖ ^ 2 := by + rw [frobSq, LinearMap.trace_eq_sum_inner _ b] + simp only [LinearMap.comp_apply, LinearMap.adjoint_inner_right, real_inner_self_eq_norm_sq] + +lemma frobSq_nonneg (T : E →ₗ[ℝ] E) : 0 ≤ frobSq T := by + rw [frobSq_eq_sum (stdOrthonormalBasis ℝ E)] + positivity + +lemma frobSq_adjoint (T : E →ₗ[ℝ] E) : frobSq T.adjoint = frobSq T := by + rw [frobSq, adjoint_adjoint, LinearMap.trace_comp_comm', frobSq] + +omit [FiniteDimensional ℝ E] in +lemma trace_bound (T : E →ₗ[ℝ] E) {ι : Type uι2} [Fintype ι] (b : OrthonormalBasis ι ℝ E) : + |LinearMap.trace ℝ E T| ≤ ∑i, ‖T (b i)‖ := by + rw [LinearMap.trace_eq_sum_inner _ b] + apply (abs_sum_le_sum_abs _ _).trans + apply sum_le_sum + intro i hi + calc + |⟪b i, T (b i)⟫_ℝ| ≤ ‖b i‖ * ‖T (b i)‖ := abs_real_inner_le_norm _ _ + _ = ‖T (b i)‖ := by rw [b.orthonormal.norm_eq_one, one_mul] + +lemma norm_eigenvector (T : E →ₗ[ℝ] E) (i : Fin (Module.finrank ℝ E)) : + ‖T (T.isSymmetric_adjoint_comp_self.eigenvectorBasis rfl i)‖ = T.singularValues i := by + let h := T.isSymmetric_adjoint_comp_self + let b := h.eigenvectorBasis rfl + have he := h.apply_eigenvectorBasis rfl i + have he' := congrArg (fun x => ⟪b i, x⟫_ℝ) he + change ⟪b i, T.adjoint (T (b i))⟫_ℝ = ⟪b i, h.eigenvalues rfl i • b i⟫_ℝ at he' + rw [adjoint_inner_right, real_inner_self_eq_norm_sq, inner_smul_right, + real_inner_self_eq_norm_sq, b.orthonormal.norm_eq_one, one_pow, mul_one] at he' + rw [T.singularValues_fin rfl i, ← he', Real.sqrt_sq (norm_nonneg _)] + +lemma trace_le_singular_sum (T : E →ₗ[ℝ] E) : + |LinearMap.trace ℝ E T| ≤ ∑i : Fin (Module.finrank ℝ E), T.singularValues i := by + simpa only [norm_eigenvector] using trace_bound T (T.isSymmetric_adjoint_comp_self.eigenvectorBasis rfl) + +lemma frobSq_eq_singular_sum (T : E →ₗ[ℝ] E) : + frobSq T = ∑i : Fin (Module.finrank ℝ E), T.singularValues i ^ 2 := by + rw [frobSq_eq_sum (T.isSymmetric_adjoint_comp_self.eigenvectorBasis rfl)] + simp only [norm_eigenvector] + +lemma projection_symmetric (K : Submodule ℝ E) : K.starProjection.toLinearMap.IsSymmetric := by + intro u v + exact K.inner_starProjection_left_eq_right u v + +lemma projection_sq (K : Submodule ℝ E) : + K.starProjection.toLinearMap ∘ₗ K.starProjection.toLinearMap = K.starProjection.toLinearMap := by + ext v + exact K.starProjection_eq_self_iff.mpr (K.starProjection_apply_mem v) + +lemma projection_trace (K : Submodule ℝ E) : + LinearMap.trace ℝ E K.starProjection.toLinearMap = (Module.finrank ℝ K : ℝ) := by + exact (show LinearMap.IsProj K K.starProjection.toLinearMap from + ⟨K.starProjection_apply_mem, fun v hv => K.starProjection_eq_self_iff.mpr hv⟩).trace + +lemma projection_inner (K : Submodule ℝ E) (v : E) : + ⟪v, K.starProjection v⟫_ℝ = ‖K.starProjection v‖ ^ 2 := by + rw [real_inner_comm] + exact K.re_inner_starProjection_eq_normSq v + +lemma frobSq_projection_le (K : Submodule ℝ E) (T : E →ₗ[ℝ] E) : + frobSq (K.starProjection.toLinearMap ∘ₗ T) ≤ frobSq T := by + rw [frobSq_eq_sum (stdOrthonormalBasis ℝ E), frobSq_eq_sum (stdOrthonormalBasis ℝ E)] + apply sum_le_sum + intro i hi + exact pow_le_pow_left₀ (norm_nonneg _) (K.norm_starProjection_apply_le _) 2 + +lemma frobSq_projection (K : Submodule ℝ E) (T : E →ₗ[ℝ] E) : + frobSq (K.starProjection.toLinearMap ∘ₗ T) = + LinearMap.trace ℝ E ((T ∘ₗ T.adjoint) ∘ₗ K.starProjection.toLinearMap) := by + let P := K.starProjection.toLinearMap + have hP : P.adjoint = P := (projection_symmetric K).adjoint_eq + have hPP : P ∘ₗ P = P := projection_sq K + change LinearMap.trace ℝ E ((P ∘ₗ T).adjoint ∘ₗ (P ∘ₗ T)) = _ + have heq : (P ∘ₗ T).adjoint ∘ₗ (P ∘ₗ T) = T.adjoint ∘ₗ (P ∘ₗ T) := by + rw [adjoint_comp, hP] + ext v + change T.adjoint (P (P (T v))) = T.adjoint (P (T v)) + exact congrArg T.adjoint (congrArg (fun f : E →ₗ[ℝ] E => f (T v)) hPP) + rw [heq, LinearMap.trace_comp_comm', comp_assoc, LinearMap.trace_comp_comm'] + +lemma weighted_tail_le {d k : ℕ} (hk : k ≤ d) (s w : Fin d → ℝ) + (hs : Antitone s) (hn : ∀i, 0 ≤ s i) + (hw : ∀i, 0 ≤ w i ∧ w i ≤ 1) + (hsum : (d - k : ℕ) ≤ ∑i, w i) : + (∑i with k ≤ i.val, s i) ≤ ∑i, s i * w i := by + classical + by_cases hkd : k = d + · subst k + have hz : univ.filter (fun i : Fin d => d ≤ i.val) = ∅ := by + apply eq_empty_of_forall_notMem + intro i hi + exact (not_le_of_gt i.isLt) (mem_filter.mp hi).2 + rw [hz, sum_empty] + exact sum_nonneg (fun i _ => mul_nonneg (hn i) (hw i).1) + have hkd' : k < d := lt_of_le_of_ne hk hkd + let c := s ⟨k, hkd'⟩ + let L := univ.filter (fun i : Fin d => i.val < k) + let R := univ.filter (fun i : Fin d => k ≤ i.val) + have hc : 0 ≤ c := hn _ + have hRcard : R.card = d - k := by + suffices L.card = k by + have hcard := card_filter_add_card_filter_not (s := (univ : Finset (Fin d))) (p := fun i => i.val < k) + simp only [card_univ, Fintype.card_fin, not_lt] at hcard + change L.card + R.card = d at hcard + omega + change (univ.filter (fun i : Fin d => i.val < k)).card = k + calc + _ = (univ : Finset (Fin k)).card := by + apply card_bij (fun i hi => (⟨i.val, (mem_filter.mp hi).2⟩ : Fin k)) + · intro i hi; exact mem_univ _ + · intro i hi j hj he; exact Fin.ext (congrArg (fun x : Fin k => x.val) he) + · intro j hj + refine ⟨⟨j.val, j.isLt.trans_le hk⟩, mem_filter.mpr ⟨mem_univ _, j.isLt⟩, ?_⟩ + rfl + _ = k := by simp + have hsplit (f : Fin d → ℝ) : (∑i ∈ L, f i) + (∑i ∈ R, f i) = ∑i, f i := by + simpa only [L, R, not_lt] using (sum_filter_add_sum_filter_not univ (fun i : Fin d => i.val < k) f) + have hl : c * (∑i ∈ L, w i) ≤ ∑i ∈ L, s i * w i := by + rw [mul_sum] + apply sum_le_sum + intro i hi + apply mul_le_mul_of_nonneg_right (hs (by exact (mem_filter.mp hi).2.le)) (hw i).1 + have hr : (∑i ∈ R, s i) - ∑i ∈ R, s i * w i ≤ c * ((d - k : ℕ) - ∑i ∈ R, w i) := by + have hcard : (R.card : ℝ) = ∑i ∈ R, (1 : ℝ) := by simp + rw [← hRcard, hcard, ← sum_sub_distrib, ← sum_sub_distrib, mul_sum] + apply sum_le_sum + intro i hi + have hsic : s i ≤ c := hs (by exact (mem_filter.mp hi).2) + have h := mul_le_mul_of_nonneg_right hsic (sub_nonneg.mpr (hw i).2) + nlinarith + have hwc : c * ((d - k : ℕ) - ∑i ∈ R, w i) ≤ c * ∑i ∈ L, w i := by + apply mul_le_mul_of_nonneg_left _ hc + have hspl := hsplit w + linarith + have hspl := hsplit (fun i => s i * w i) + change (∑i ∈ R, s i) ≤ _ + linarith + +lemma eigenvalue_eq_singular_sq (T : E →ₗ[ℝ] E) (i : Fin (Module.finrank ℝ E)) : + T.isSymmetric_adjoint_comp_self.eigenvalues rfl i = T.singularValues i ^ 2 := by + let h := T.isSymmetric_adjoint_comp_self + let b := h.eigenvectorBasis rfl + have he' := congrArg (fun x => ⟪b i, x⟫_ℝ) (h.apply_eigenvectorBasis rfl i) + change ⟪b i, T.adjoint (T (b i))⟫_ℝ = ⟪b i, h.eigenvalues rfl i • b i⟫_ℝ at he' + rw [adjoint_inner_right, real_inner_self_eq_norm_sq, inner_smul_right, + real_inner_self_eq_norm_sq, b.orthonormal.norm_eq_one, one_pow, mul_one] at he' + rw [← he'] + exact congrArg (fun x : ℝ => x ^ 2) (norm_eigenvector T i) + +lemma trace_adjoint (T : E →ₗ[ℝ] E) : + LinearMap.trace ℝ E T.adjoint = LinearMap.trace ℝ E T := by + rw [LinearMap.trace_eq_sum_inner _ (stdOrthonormalBasis ℝ E), + LinearMap.trace_eq_sum_inner _ (stdOrthonormalBasis ℝ E)] + apply sum_congr rfl + intro i hi + rw [adjoint_inner_right, real_inner_comm] + +lemma frobSq_projection_eigenbasis (K : Submodule ℝ E) (T : E →ₗ[ℝ] E) : + frobSq (K.starProjection.toLinearMap ∘ₗ T) = + ∑i : Fin (Module.finrank ℝ E), T.adjoint.singularValues i ^ 2 * + ⟪T.adjoint.isSymmetric_adjoint_comp_self.eigenvectorBasis rfl i, + K.starProjection (T.adjoint.isSymmetric_adjoint_comp_self.eigenvectorBasis rfl i)⟫_ℝ := by + let h := T.adjoint.isSymmetric_adjoint_comp_self + let b := h.eigenvectorBasis rfl + rw [frobSq_projection, LinearMap.trace_eq_sum_inner _ b] + apply sum_congr rfl + intro i hi + have he : (T ∘ₗ T.adjoint) (b i) = h.eigenvalues rfl i • b i := by + calc + _ = (T.adjoint.adjoint ∘ₗ T.adjoint) (b i) := by rw [adjoint_adjoint] + _ = _ := h.apply_eigenvectorBasis rfl i + change ⟪b i, (T ∘ₗ T.adjoint) (K.starProjection (b i))⟫_ℝ = _ + rw [← T.isSymmetric_self_comp_adjoint, he, real_inner_smul_left, + eigenvalue_eq_singular_sq] + +lemma rank_approximation (T C : E →ₗ[ℝ] E) {k : ℕ} + (hk : k ≤ Module.finrank ℝ E) (hC : Module.finrank ℝ (LinearMap.range C) ≤ k) : + (∑i : Fin (Module.finrank ℝ E) with k ≤ i.val, T.adjoint.singularValues i ^ 2) ≤ + frobSq (T - C) := by + let K := (LinearMap.range C)ᗮ + let P := K.starProjection.toLinearMap + let b := T.adjoint.isSymmetric_adjoint_comp_self.eigenvectorBasis rfl + let w := fun i => ⟪b i, K.starProjection (b i)⟫_ℝ + have hw (i : Fin (Module.finrank ℝ E)) : 0 ≤ w i ∧ w i ≤ 1 := by + change 0 ≤ ⟪b i, K.starProjection (b i)⟫_ℝ ∧ _ + rw [projection_inner] + constructor + · positivity + · have hh := K.norm_starProjection_apply_le (b i) + rw [b.orthonormal.norm_eq_one] at hh + dsimp [w] + rw [projection_inner] + exact (pow_le_pow_left₀ (norm_nonneg _) hh 2).trans_eq (one_pow _) + have hsum : ((Module.finrank ℝ E - k : ℕ) : ℝ) ≤ ∑i, w i := by + have hh := (LinearMap.range C).finrank_add_finrank_orthogonal + have hd : Module.finrank ℝ E - k ≤ Module.finrank ℝ K := by dsimp [K]; omega + calc + _ ≤ (Module.finrank ℝ K : ℝ) := by exact_mod_cast hd + _ = ∑i, w i := by rw [← projection_trace, LinearMap.trace_eq_sum_inner _ b]; rfl + have hs : Antitone (fun i : Fin (Module.finrank ℝ E) => T.adjoint.singularValues i ^ 2) := by + intro i j hij + exact pow_le_pow_left₀ (T.adjoint.singularValues_nonneg _) (T.adjoint.singularValues_antitone hij) 2 + have hb := weighted_tail_le hk (fun i => T.adjoint.singularValues i ^ 2) w hs + (fun _ => sq_nonneg _) hw hsum + have hPC : P ∘ₗ C = 0 := by + ext x + change K.starProjection (C x) = 0 + apply K.starProjection_apply_eq_zero_iff.mpr + change C x ∈ (LinearMap.range C)ᗮᗮ + rw [Submodule.orthogonal_orthogonal] + exact LinearMap.mem_range_self C x + have heq : P ∘ₗ (T - C) = P ∘ₗ T := by rw [comp_sub, hPC, sub_zero] + calc + _ ≤ ∑i : Fin (Module.finrank ℝ E), T.adjoint.singularValues i ^ 2 * w i := hb + _ = frobSq (P ∘ₗ T) := (frobSq_projection_eigenbasis K T).symm + _ = frobSq (P ∘ₗ (T - C)) := congrArg frobSq heq.symm + _ ≤ frobSq (T - C) := frobSq_projection_le K (T - C) + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] in + +lemma separated_net {V : Type uV} [DecidableEq V] (F : Finset V) (hF : F.Nonempty) + (Y : V → E) {δ : ℝ} (hδ : 0 ≤ δ) : + ∃ S : Finset V, S ⊆ F ∧ S.Nonempty ∧ + (∀u ∈ S, ∀v ∈ S, u ≠ v → δ < ‖Y u - Y v‖) ∧ + ∀u ∈ F, ∃v ∈ S, ‖Y u - Y v‖ ≤ δ := by + classical + let sep : Finset V → Prop := fun S => ∀u ∈ S, ∀v ∈ S, u ≠ v → δ < ‖Y u - Y v‖ + let : DecidablePred sep := fun _ => Classical.propDecidable _ + let good := F.powerset.filter sep + have hgood : good.Nonempty := ⟨∅, mem_filter.mpr ⟨mem_powerset.mpr (empty_subset _), by simp [sep]⟩⟩ + obtain ⟨S, hS, hmax⟩ := exists_max_image good card hgood + obtain ⟨hSF, hsep⟩ := mem_filter.mp hS + have hcover : ∀u ∈ F, ∃v ∈ S, ‖Y u - Y v‖ ≤ δ := by + intro u hu + by_contra! hn + have huS : u ∉ S := by + intro huS + have h := hn u huS + simp only [sub_self, norm_zero] at h + linarith + have hnew : insert u S ∈ good := by + apply mem_filter.mpr + refine ⟨mem_powerset.mpr (insert_subset hu (mem_powerset.mp hSF)), ?_⟩ + intro x hx y hy hxy + rcases mem_insert.mp hx with hxU | hxS + · subst x + rcases mem_insert.mp hy with hyU | hyS + · exact (hxy hyU.symm).elim + · exact hn y hyS + · rcases mem_insert.mp hy with hyU | hyS + · subst y + rw [norm_sub_rev]; exact hn x hxS + · exact hsep x hxS y hyS hxy + have hh := hmax _ hnew + rw [card_insert_of_notMem huS] at hh + omega + refine ⟨S, mem_powerset.mp hSF, ?_, hsep, hcover⟩ + obtain ⟨u, hu⟩ := hF + obtain ⟨v, hv, _⟩ := hcover u hu + exact ⟨v, hv⟩ + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] in +lemma norm_sub_sq_le_twice (x y : E) : ‖x-y‖ ^ 2 ≤ 2 * (‖x‖ ^ 2 + ‖y‖ ^ 2) := by + have hn := norm_sub_le x y + have hx := norm_nonneg x + have hy := norm_nonneg y + have hh : ‖x-y‖ ^ 2 ≤ (‖x‖ + ‖y‖) ^ 2 := pow_le_pow_left₀ (norm_nonneg _) hn 2 + nlinarith [sq_nonneg (‖x‖ - ‖y‖)] + +omit [FiniteDimensional ℝ E] in +lemma range_le_of_basis {ι : Type uι3} [Fintype ι] (b : Module.Basis ι ℝ E) + (T : E →ₗ[ℝ] E) (K : Submodule ℝ E) (h : ∀i, T (b i) ∈ K) : + LinearMap.range T ≤ K := by + rintro _ ⟨x, rfl⟩ + rw [← b.sum_repr x, map_sum] + apply K.sum_mem + intro i hi + rw [map_smul] + exact K.smul_mem _ (h i) + +omit [FiniteDimensional ℝ E] in + +lemma difference_span_rank {V : Type uV2} [DecidableEq V] (S : Finset V) + (Y : V → E) {v₀ : V} (hv₀ : v₀ ∈ S) : + Module.finrank ℝ (Submodule.span ℝ + ((fun v => Y v - Y v₀) '' (S : Set V))) ≤ S.card - 1 := by + classical + let A := (S.erase v₀).image (fun v => Y v - Y v₀) + have heq : Submodule.span ℝ ((fun v => Y v - Y v₀) '' (S : Set V)) = + Submodule.span ℝ (A : Set E) := by + apply le_antisymm + · apply Submodule.span_le.mpr + rintro _ ⟨v, hv, rfl⟩ + by_cases heq : v = v₀ + · simp [heq] + · exact Submodule.subset_span (mem_image.mpr ⟨v, mem_erase.mpr ⟨heq, hv⟩, rfl⟩) + · apply Submodule.span_mono + intro x hx + obtain ⟨v, hv, rfl⟩ := mem_image.mp hx + exact ⟨v, mem_of_mem_erase hv, rfl⟩ + rw [heq] + exact (finrank_span_finset_le_card A).trans ((card_image_le).trans_eq (card_erase_of_mem hv₀)) + +lemma spectral_centers_at_radius {V : Type uV3} [DecidableEq V] + (Y : V → E) (u v : Fin (Module.finrank ℝ E) → V) + (b : OrthonormalBasis (Fin (Module.finrank ℝ E)) ℝ E) + (T : E →ₗ[ℝ] E) (hT : ∀i, T (b i) = Y (u i) - Y (v i)) + {p : ℕ} (hp : 1 ≤ p) (hpd : p ≤ Module.finrank ℝ E) + {r : ℝ} (hr : 0 < r) + (hrT : 32 * (Module.finrank ℝ E : ℝ) * r = + ∑i : Fin (Module.finrank ℝ E) with p - 1 ≤ i.val, T.adjoint.singularValues i ^ 2) : + ∃ S : Finset V, S ⊆ (univ.image u ∪ univ.image v) ∧ p < S.card ∧ + (∀x ∈ S, ∀y ∈ S, x ≠ y → 2 * Real.sqrt r < ‖Y x - Y y‖) := by + classical + let F := univ.image u ∪ univ.image v + have hd : 0 < Module.finrank ℝ E := lt_of_lt_of_le (by omega) hpd + have hF : F.Nonempty := ⟨u ⟨0, hd⟩, mem_union_left _ (mem_image.mpr ⟨⟨0, hd⟩, mem_univ _, rfl⟩)⟩ + obtain ⟨S, hSF, hSne, hsep, hcover⟩ := separated_net F hF Y (show 0 ≤ 2 * Real.sqrt r by positivity) + refine ⟨S, hSF, ?_, hsep⟩ + by_contra! hSp + obtain ⟨v₀, hv₀⟩ := hSne + let c : V → V := fun x => if hx : x ∈ F then Classical.choose (hcover x hx) else v₀ + have hcS (x : V) : c x ∈ S := by + dsimp [c] + split + · exact (Classical.choose_spec (hcover _ ‹_›)).1 + · exact hv₀ + have hcclose (x : V) (hx : x ∈ F) : ‖Y x - Y (c x)‖ ^ 2 ≤ 4 * r := by + have hh := (Classical.choose_spec (hcover x hx)).2 + have he : c x = Classical.choose (hcover x hx) := dite_eq_left hx + rw [he] + have hsq := pow_le_pow_left₀ (norm_nonneg _) hh 2 + nlinarith [Real.sq_sqrt hr.le] + have hu (i) : u i ∈ F := mem_union_left _ (mem_image.mpr ⟨i, mem_univ _, rfl⟩) + have hv (i) : v i ∈ F := mem_union_right _ (mem_image.mpr ⟨i, mem_univ _, rfl⟩) + let C := b.toBasis.constr ℝ (fun i => Y (c (u i)) - Y (c (v i))) + let K := Submodule.span ℝ ((fun x => Y x - Y v₀) '' (S : Set V)) + have hCK : LinearMap.range C ≤ K := by + apply range_le_of_basis b.toBasis + intro i + change C (b.toBasis i) ∈ K + rw [Module.Basis.constr_basis] + have huK : Y (c (u i)) - Y v₀ ∈ K := Submodule.subset_span ⟨_, hcS _, rfl⟩ + have hvK : Y (c (v i)) - Y v₀ ∈ K := Submodule.subset_span ⟨_, hcS _, rfl⟩ + convert K.sub_mem huK hvK using 1 ; abel + have hCrank : Module.finrank ℝ (LinearMap.range C) ≤ p - 1 := + (Submodule.finrank_mono hCK).trans ((difference_span_rank S Y hv₀).trans (Nat.sub_le_sub_right hSp 1)) + have hlow := rank_approximation T C ((Nat.sub_le p 1).trans hpd) hCrank + rw [← hrT] at hlow + have hupp : frobSq (T - C) ≤ 16 * (Module.finrank ℝ E : ℝ) * r := by + have hpoint (i : Fin (Module.finrank ℝ E)) : ‖(T - C) (b i)‖ ^ 2 ≤ 16 * r := by + rw [LinearMap.sub_apply, hT] + change ‖(Y (u i) - Y (v i)) - C (b.toBasis i)‖ ^ 2 ≤ _ + rw [Module.Basis.constr_basis] + have heq : (Y (u i) - Y (v i)) - (Y (c (u i)) - Y (c (v i))) = + (Y (u i) - Y (c (u i))) - (Y (v i) - Y (c (v i))) := by abel + rw [heq] + have hh := norm_sub_sq_le_twice (Y (u i) - Y (c (u i))) (Y (v i) - Y (c (v i))) + linarith [hcclose (u i) (hu i), hcclose (v i) (hv i)] + rw [frobSq_eq_sum b] + calc + _ ≤ ∑i : Fin (Module.finrank ℝ E), (16 * r) := sum_le_sum (fun i _ => hpoint i) + _ = _ := by simp; ring + have hdr : (0 : ℝ) < Module.finrank ℝ E := by exact_mod_cast hd + nlinarith [mul_pos hdr hr] + +private def tail {d : ℕ} (s : Fin d → ℝ) (p : ℕ) := ∑i with p ≤ i.val + 1, s i +private def block {d : ℕ} (s : Fin d → ℝ) (p : ℕ) := ∑i with p ≤ i.val + 1 ∧ i.val + 1 < 2*p, s i + +private lemma tail_split {d : ℕ} (s : Fin d → ℝ) (p : ℕ) : + tail s p = block s p + tail s (2*p) := by + classical + have hh := sum_filter_add_sum_filter_not (univ.filter (fun i : Fin d => p ≤ i.val + 1)) + (fun i => i.val + 1 < 2*p) s + have heq : (univ.filter (fun i : Fin d => p ≤ i.val+1)).filter (fun i => ¬i.val+1 < 2*p) = + univ.filter (fun i : Fin d => 2*p ≤ i.val+1) := by + ext i + simp only [mem_filter, mem_univ, true_and] + omega + rw [heq] at hh + simpa only [filter_filter, tail, block] using hh.symm + +private lemma block_sq_le {d : ℕ} (s : Fin d → ℝ) (p : ℕ) : + block s p ^ 2 ≤ (p : ℝ) * tail (fun i => s i ^ 2) p := by + classical + let B := univ.filter (fun i : Fin d => p ≤ i.val+1 ∧ i.val+1 < 2*p) + have hcard : B.card ≤ p := by + have hh : B.card ≤ (range p).card := by + apply card_le_card_of_injOn (fun i : Fin d => i.val+1-p) + · intro i hi + have h := (mem_filter.mp hi).2 + exact mem_range.mpr (by dsimp; omega) + · intro i hi j hj hij + have hi' := (mem_filter.mp hi).2 + have hj' := (mem_filter.mp hj).2 + apply Fin.ext + dsimp at hij + omega + simpa using hh + have hsum : (∑i ∈ B, s i ^ 2) ≤ tail (fun i => s i ^ 2) p := by + apply sum_le_sum_of_subset_of_nonneg + · intro i hi; exact mem_filter.mpr ⟨mem_univ _, (mem_filter.mp hi).2.1⟩ + · intro i hi hn; positivity + have hcs := sum_mul_sq_le_sq_mul_sq B s (fun _ => (1 : ℝ)) + simp only [mul_one, one_pow, sum_const, nsmul_eq_mul, mul_one] at hcs + calc + _ ≤ (∑i ∈ B, s i ^ 2) * (B.card : ℝ) := hcs + _ ≤ tail (fun i => s i ^ 2) p * (p : ℝ) := + mul_le_mul hsum (by exact_mod_cast hcard) (by positivity) + (sum_nonneg (fun _ _ => sq_nonneg _)) + _ = _ := mul_comm _ _ + +lemma dyadic_tail_selection {d p₀ L : ℕ} (s : Fin d → ℝ) + (hs : ∀i, 0 ≤ s i) (_hp₀ : 1 ≤ p₀) (hL : 0 < L) + (hcover : d < 2^L*p₀) (hpositive : 0 < tail s p₀) : + ∃ p : ℕ, p₀ ≤ p ∧ p ≤ d ∧ + tail s p₀ ^ 2 ≤ (L : ℝ)^2 * ((p : ℝ) * tail (fun i => s i ^ 2) p) := by + classical + let p : ℕ → ℕ := fun j => 2^j*p₀ + let M : ℕ → ℝ := fun j => (p j : ℝ) * tail (fun i => s i ^ 2) (p j) + obtain ⟨j, hj, hmax⟩ := exists_max_image (range L) M (nonempty_range_iff.mpr (ne_of_gt hL)) + have hM : 0 ≤ M j := mul_nonneg (Nat.cast_nonneg _) (sum_nonneg (fun _ _ => sq_nonneg _)) + have hzero : tail s (p L) = 0 := by + apply sum_eq_zero + intro i hi + have hh := (mem_filter.mp hi).2 + dsimp [p] at hh + omega + have hpnext (i : ℕ) : p (i+1) = 2*p i := by dsimp [p]; rw [pow_succ]; ring + have hsplit (i : ℕ) : tail s (p i) - tail s (p (i+1)) = block s (p i) := by + rw [hpnext, tail_split s (p i)] + ring + have hsum : (∑i ∈ range L, block s (p i)) = tail s p₀ := by + conv_lhs => enter [2, i]; rw [← hsplit] + rw [sum_range_sub', hzero] + simp [p] + have hbound (i : ℕ) (hi : i ∈ range L) : block s (p i) ≤ Real.sqrt (M j) := by + have hh := (block_sq_le s (p i)).trans (hmax i hi) + have hn : 0 ≤ block s (p i) := sum_nonneg (fun i _ => hs i) + nlinarith [Real.sq_sqrt hM, Real.sqrt_nonneg (M j)] + have htotal : tail s p₀ ≤ (L : ℝ) * Real.sqrt (M j) := by + rw [← hsum] + calc + _ ≤ ∑i ∈ range L, Real.sqrt (M j) := sum_le_sum hbound + _ = _ := by simp + have hsq : tail s p₀ ^ 2 ≤ (L : ℝ)^2 * M j := by + have hh := pow_le_pow_left₀ hpositive.le htotal 2 + rw [mul_pow, Real.sq_sqrt hM] at hh + exact hh + have hpd : p j ≤ d := by + by_contra! hpd + have hzero : tail (fun i => s i ^ 2) (p j) = 0 := by + apply sum_eq_zero + intro i hi + have hh := (mem_filter.mp hi).2 + omega + dsimp [M] at hsq + rw [hzero, mul_zero, mul_zero] at hsq + nlinarith + refine ⟨p j, ?_, hpd, hsq⟩ + have hpow : 1 ≤ 2^j := Nat.one_le_pow _ _ (by omega) + simpa only [one_mul, p] using (Nat.mul_le_mul_right p₀ hpow) + +lemma singular_tail_selection {d : ℕ} (hd : 0 < d) (s : Fin d → ℝ) + (hs : ∀i, 0 ≤ s i) {a τ : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) (hτ : 0 < τ) + (htrace : τ ≤ ∑i, s i) (hfrob : a * d * (∑i, s i ^ 2) ≤ τ ^ 2) : + ∃ p L : ℕ, a * d / 16 < p ∧ p ≤ d ∧ 0 < L ∧ + (L : ℝ) ≤ 5 + Real.logb 2 (1/a) ∧ + 9 * τ ^ 2 ≤ 16 * (L : ℝ)^2 * ((p : ℝ) * tail (fun i => s i ^ 2) p) := by + classical + let f := ⌊a * d / 16⌋₊ + let p₀ := f+1 + have hdr : (0 : ℝ) < d := by exact_mod_cast hd + have had : 0 ≤ a * d / 16 := by positivity + have hf : (f : ℝ) ≤ a * d / 16 := Nat.floor_le had + have hp₀ : a * d / 16 < (p₀ : ℝ) := by simpa only [p₀, Nat.cast_add, Nat.cast_one] using Nat.lt_floor_add_one (a*d/16) + have hp₀pos : 1 ≤ p₀ := by dsimp [p₀]; omega + have hp₀d : p₀ ≤ d := by + have hf' : (f : ℝ) < d := by nlinarith + have hfn : f < d := by exact_mod_cast hf' + dsimp [p₀]; omega + let I := univ.filter (fun i : Fin d => i.val < f) + have hcard : I.card ≤ f := by + have hh : I.card ≤ (range f).card := by + apply card_le_card_of_injOn (fun i : Fin d => i.val) + · intro i hi; exact mem_range.mpr (mem_filter.mp hi).2 + · intro i hi j hj hij; exact Fin.ext hij + simpa using hh + have hhead : ∑i ∈ I, s i ≤ τ/4 := by + have hcs := sum_mul_sq_le_sq_mul_sq I s (fun _ => (1 : ℝ)) + simp only [mul_one, one_pow, sum_const, nsmul_eq_mul, mul_one] at hcs + have hsum : (∑i ∈ I, s i ^ 2) ≤ ∑i, s i ^ 2 := + sum_le_sum_of_subset_of_nonneg (subset_univ _) (fun i hi hn => sq_nonneg _) + have hcard' : (I.card : ℝ) ≤ a*d/16 := (by exact_mod_cast hcard : (I.card : ℝ) ≤ f).trans hf + have hupp := mul_le_mul hsum hcard' (Nat.cast_nonneg _) (sum_nonneg (fun _ _ => sq_nonneg _)) + have hheadn : 0 ≤ ∑i ∈ I, s i := sum_nonneg (fun i _ => hs i) + nlinarith + have hsplit : (∑i ∈ I, s i) + tail s p₀ = ∑i, s i := by + have hh := sum_filter_add_sum_filter_not univ (fun i : Fin d => i.val < f) s + have heq : univ.filter (fun i : Fin d => ¬i.val < f) = + univ.filter (fun i : Fin d => p₀ ≤ i.val+1) := by + ext i + simp only [mem_filter, mem_univ, true_and] + dsimp [p₀] + omega + rw [heq] at hh + exact hh + have htail : 3*τ/4 ≤ tail s p₀ := by linarith + let q := d / p₀ + let L := q.log2 + 1 + have hq : q ≠ 0 := by + have hqp : 0 < q := Nat.div_pos hp₀d (by omega) + omega + have hL : 0 < L := by dsimp [L]; omega + have hcover : d < 2^L*p₀ := by + have hh : q < 2^L := (Nat.log2_lt hq).mp (by dsimp [L]; omega) + exact (Nat.div_lt_iff_lt_mul (by omega)).mp hh + have hp₀r : (0 : ℝ) < p₀ := by exact_mod_cast (show 0 < p₀ by omega) + have hqreal : (q : ℝ) ≤ 16/a := by + have hh : (q : ℝ) * p₀ ≤ d := by exact_mod_cast (Nat.div_mul_le_self d p₀) + have hqn : (0 : ℝ) ≤ q := Nat.cast_nonneg _ + apply (le_div_iff₀ ha).mpr + nlinarith + have hlog : (L : ℝ) ≤ 5 + Real.logb 2 (1/a) := by + have hqpos : (0 : ℝ) < q := by exact_mod_cast (Nat.pos_of_ne_zero hq) + have hmono := (Real.logb_le_logb (by norm_num : (1 : ℝ) < 2) hqpos (by positivity : (0 : ℝ) < 16/a)).mpr hqreal + have hlogq := Real.log2_le_logb q + have hlog16 : Real.logb 2 (16/a) = 4 + Real.logb 2 (1/a) := by + rw [show (16 : ℝ)/a = 2^4*(1/a) by ring, Real.logb_mul (by norm_num) (ne_of_gt (by positivity : (0 : ℝ) < 1/a)), Real.logb_pow] + norm_num + rw [hlog16] at hmono + dsimp [L] + push_cast + linarith + obtain ⟨p, hpp, hpd, hpbig⟩ := dyadic_tail_selection s hs hp₀pos hL hcover (by linarith) + refine ⟨p, L, hp₀.trans_le (by exact_mod_cast hpp), hpd, hL, hlog, ?_⟩ + have htailn : 0 ≤ tail s p₀ := by linarith + have hh := pow_le_pow_left₀ (by positivity : 0 ≤ 3*τ/4) htail 2 + nlinarith + +lemma trace_sq_le_frobSq (T : E →ₗ[ℝ] E) : + LinearMap.trace ℝ E T ^ 2 ≤ (Module.finrank ℝ E : ℝ) * frobSq T := by + let b := stdOrthonormalBasis ℝ E + have hh := trace_bound T b + have hn : 0 ≤ ∑i, ‖T (b i)‖ := sum_nonneg (fun _ _ => norm_nonneg _) + have hsq := pow_le_pow_left₀ (abs_nonneg _) hh 2 + have hcs := sum_mul_sq_le_sq_mul_sq univ (fun i => ‖T (b i)‖) (fun _ => (1 : ℝ)) + simp only [mul_one, one_pow, sum_const, card_univ, Fintype.card_fin, + nsmul_eq_mul, mul_one] at hcs + rw [← frobSq_eq_sum b] at hcs + rw [sq_abs] at hsq + exact hsq.trans (hcs.trans_eq (mul_comm _ _)) + +lemma spectral_packing_log {V : Type uV4} [DecidableEq V] + (Y : V → E) (u v : Fin (Module.finrank ℝ E) → V) + (b : OrthonormalBasis (Fin (Module.finrank ℝ E)) ℝ E) + (T : E →ₗ[ℝ] E) (hT : ∀i, T (b i) = Y (u i) - Y (v i)) + {a : ℝ} (ha : 0 < a) (htrace : 0 < |LinearMap.trace ℝ E T|) + (hassume : a * Module.finrank ℝ E * frobSq T ≤ LinearMap.trace ℝ E T ^ 2) : + a ≤ 1 ∧ ∃ S : Finset V, ∃ r : ℝ, 0 < r ∧ + S ⊆ (univ.image u ∪ univ.image v) ∧ 2 ≤ S.card ∧ + a * Module.finrank ℝ E / 16 ≤ S.card ∧ + 9 * LinearMap.trace ℝ E T ^ 2 ≤ + 512 * Module.finrank ℝ E * (5 + Real.logb 2 (1/a))^2 * (S.card * r) ∧ + (∀x ∈ S, ∀y ∈ S, x ≠ y → 2 * Real.sqrt r < ‖Y x - Y y‖) := by + classical + let d := Module.finrank ℝ E + let τ := |LinearMap.trace ℝ E T| + have htsq : τ ^ 2 = LinearMap.trace ℝ E T ^ 2 := sq_abs _ + have htpos : 0 < τ ^ 2 := sq_pos_of_pos htrace + have htraceF := trace_sq_le_frobSq T + have hdn : (0 : ℝ) < d := by + have hf := frobSq_nonneg T + dsimp [d] + by_contra! hn + have hz : (Module.finrank ℝ E : ℝ) = 0 := le_antisymm hn (Nat.cast_nonneg _) + rw [hz, zero_mul] at htraceF + nlinarith + have hd : 0 < d := by exact_mod_cast hdn + have hfpos : 0 < frobSq T := by nlinarith + have ha1 : a ≤ 1 := by + have hh : 0 < (d : ℝ) * frobSq T := mul_pos hdn hfpos + have hh' : a * ((d : ℝ) * frobSq T) ≤ (d : ℝ) * frobSq T := by + calc + _ = a * d * frobSq T := by ring + _ ≤ LinearMap.trace ℝ E T ^ 2 := hassume + _ ≤ _ := htraceF + exact (mul_le_mul_iff_left₀ hh).mp (by simpa only [mul_comm, one_mul] using hh') + let s := fun i : Fin d => T.adjoint.singularValues i + have hs (i : Fin d) : 0 ≤ s i := T.adjoint.singularValues_nonneg i + have hsum : τ ≤ ∑i, s i := by + simpa only [trace_adjoint] using trace_le_singular_sum T.adjoint + have hsq : a * d * (∑i, s i ^ 2) ≤ τ ^ 2 := by + rw [← frobSq_eq_singular_sum T.adjoint, frobSq_adjoint, htsq] + exact hassume + obtain ⟨p, L, hpmin, hpd, hL, hlog, hpbig⟩ := singular_tail_selection hd s hs ha ha1 htrace hsum hsq + have hpp : 1 ≤ p := by + have hpp' : (0 : ℝ) < p := lt_of_le_of_lt (by positivity) hpmin + have : 0 < p := by exact_mod_cast hpp' + omega + let tailVal := tail (fun i => s i ^ 2) p + have htailpos : 0 < tailVal := by + have hn : 0 ≤ tailVal := sum_nonneg (fun _ _ => sq_nonneg _) + by_contra! hh + have hz : tailVal = 0 := le_antisymm hh hn + change 9*τ^2 ≤ 16*(L:ℝ)^2*((p:ℝ)*tailVal) at hpbig + rw [hz, mul_zero, mul_zero] at hpbig + nlinarith + let r := tailVal / (32*d) + have hr : 0 < r := div_pos htailpos (by positivity) + have hrt : 32*(d:ℝ)*r = tailVal := by dsimp [r]; field_simp + have heq : tailVal = + ∑i : Fin d with p-1 ≤ i.val, T.adjoint.singularValues i ^ 2 := by + unfold tailVal tail + apply sum_congr + · ext i + simp only [mem_filter, mem_univ, true_and] + omega + · intro i hi; rfl + obtain ⟨S, hSF, hpS, hsep⟩ := spectral_centers_at_radius Y u v b T hT hpp hpd hr (hrt.trans heq) + have hpSr : (p : ℝ) ≤ S.card := by exact_mod_cast hpS.le + have hSr : 0 ≤ (S.card : ℝ)*r := mul_nonneg (Nat.cast_nonneg _) hr.le + have hpr : (p : ℝ)*r ≤ S.card*r := mul_le_mul_of_nonneg_right hpSr hr.le + have hLr : (0 : ℝ) < L := by exact_mod_cast hL + have hlogn : 0 ≤ 5+Real.logb 2 (1/a) := hLr.le.trans hlog + have hLsq := pow_le_pow_left₀ hLr.le hlog 2 + refine ⟨ha1, S, r, hr, hSF, by omega, hpmin.le.trans hpSr, ?_, hsep⟩ + have hpbig' : 9*τ^2 ≤ 512*(d:ℝ)*(L:ℝ)^2*((p:ℝ)*r) := by + change 9*τ^2 ≤ 16*(L:ℝ)^2*((p:ℝ)*tailVal) at hpbig + rw [← hrt] at hpbig + convert hpbig using 1 ; ring + rw [← htsq] + calc + _ ≤ 512*(d:ℝ)*(L:ℝ)^2*((p:ℝ)*r) := hpbig' + _ ≤ 512*(d:ℝ)*(L:ℝ)^2*(S.card*r) := + mul_le_mul_of_nonneg_left hpr (by positivity) + _ ≤ _ := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hLsq (by positivity)) hSr + +lemma logarithmic_power_bound {a ε : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) + (hε : 0 < ε) (hε1 : ε < 1/3) : + ε^2 * a^ε * (5 + Real.logb 2 (1/a))^2 ≤ 16 := by + let t := Real.log (1/a) + have ht : 0 ≤ t := Real.log_nonneg (by exact (one_le_div ha).mpr ha1) + have htlog : t = - Real.log a := by dsimp [t]; rw [Real.log_div (by norm_num) ha.ne']; simp + have hlog2 : (1/2 : ℝ) ≤ Real.log 2 := by linarith [Real.log_two_gt_d9] + have hlog : 5+Real.logb 2 (1/a) ≤ 5+2*t := by + dsimp [Real.logb] + have hh : t / Real.log 2 ≤ 2*t := (div_le_iff₀ (by linarith : 0 < Real.log 2)).mpr (by nlinarith) + linarith + have hlogn : 0 ≤ 5+Real.logb 2 (1/a) := by + have hh := Real.logb_nonneg (by norm_num : (1:ℝ)<2) ((one_le_div ha).mpr ha1) + linarith + let z := ε*t/2 + have hz : 0 ≤ z := by dsimp [z]; positivity + have hexple : Real.exp (-z) ≤ 1 := by rw [← Real.exp_zero]; exact Real.exp_le_exp.mpr (by linarith) + have he1 : Real.exp (-1) ≤ 1/2 := by + rw [Real.exp_neg] + simpa only [one_div] using + (inv_anti₀ (by norm_num : (0:ℝ)<2) (by linarith [Real.add_one_le_exp 1] : (2:ℝ) ≤ Real.exp 1)) + have hzbound : z * Real.exp (-z) ≤ 1/2 := (Real.mul_exp_neg_le_exp_neg_one z).trans he1 + have hmain : ε*(5+Real.logb 2 (1/a))*Real.exp (-z) ≤ 4 := by + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hlog hε.le) (Real.exp_pos (-z)).le + have h5 := mul_le_mul_of_nonneg_left hexple (show 0 ≤ 5*ε by positivity) + dsimp [z] at hzbound + nlinarith + have heq : Real.exp (-z)^2 = a^ε := by + rw [← Real.exp_nat_mul, Real.rpow_def_of_pos ha] + congr 1 + dsimp [z] + rw [htlog] + ring + have hn : 0 ≤ ε*(5+Real.logb 2 (1/a))*Real.exp (-z) := by positivity + have hh := pow_le_pow_left₀ hn hmain 2 + rw [mul_pow, mul_pow, heq] at hh + nlinarith + +lemma spectral_packing_power {V : Type uV5} [DecidableEq V] + (Y : V → E) (u v : Fin (Module.finrank ℝ E) → V) + (b : OrthonormalBasis (Fin (Module.finrank ℝ E)) ℝ E) + (T : E →ₗ[ℝ] E) (hT : ∀i, T (b i) = Y (u i) - Y (v i)) + {a ε : ℝ} (ha : 0 < a) (htrace : 0 < |LinearMap.trace ℝ E T|) + (hassume : a * Module.finrank ℝ E * frobSq T ≤ LinearMap.trace ℝ E T ^ 2) + (hε : 0 < ε) (hε1 : ε < 1/3) : + a ≤ 1 ∧ ∃ S : Finset V, ∃ r : ℝ, 0 < r ∧ + S ⊆ (univ.image u ∪ univ.image v) ∧ 2 ≤ S.card ∧ + ε^2 * a * Module.finrank ℝ E ≤ 1024 * S.card ∧ + ε^2 * a^ε * LinearMap.trace ℝ E T ^ 2 ≤ + 1024 * Module.finrank ℝ E * (S.card * r) ∧ + (∀x ∈ S, ∀y ∈ S, x ≠ y → 2 * Real.sqrt r < ‖Y x - Y y‖) := by + obtain ⟨ha1, S, r, hr, hSF, hS2, hcard, hlog, hsep⟩ := + spectral_packing_log Y u v b T hT ha htrace hassume + have he2 : ε^2 ≤ 64 := by nlinarith + have hd : 0 ≤ (Module.finrank ℝ E : ℝ) := Nat.cast_nonneg _ + have hSr : 0 ≤ (S.card : ℝ)*r := mul_nonneg (Nat.cast_nonneg _) hr.le + have hpow : 0 ≤ ε^2 * a^ε := mul_nonneg (sq_nonneg _) (Real.rpow_nonneg ha.le _) + have hh := mul_le_mul_of_nonneg_left hlog hpow + have hb := mul_le_mul_of_nonneg_right (logarithmic_power_bound ha ha1 hε hε1) + (show 0 ≤ 512*(Module.finrank ℝ E : ℝ)*(S.card*r) by positivity) + refine ⟨ha1, S, r, hr, hSF, hS2, ?_, ?_, hsep⟩ + · have hc : a * Module.finrank ℝ E ≤ 16 * S.card := by linarith + have hh := mul_le_mul_of_nonneg_left hc (sq_nonneg ε) + have hb := mul_le_mul_of_nonneg_right he2 (show 0 ≤ 16*(S.card:ℝ) by positivity) + nlinarith + · have h9 : 9 * (ε^2 * a^ε * LinearMap.trace ℝ E T ^ 2) ≤ + 8192 * Module.finrank ℝ E * (S.card * r) := by + calc + _ ≤ ε^2 * a^ε * + (512 * Module.finrank ℝ E * (5 + Real.logb 2 (1/a))^2 * (S.card*r)) := by + nlinarith only [hh] + _ = (ε^2 * a^ε * (5 + Real.logb 2 (1/a))^2) * + (512 * Module.finrank ℝ E * (S.card*r)) := by ring + _ ≤ _ := by nlinarith only [hb] + have hn : 0 ≤ (Module.finrank ℝ E : ℝ) * (S.card*r) := mul_nonneg hd hSr + nlinarith + +theorem spectral_packing_coordinates {V : Type uV6} {ι : Type uι4} {η : Type uη} [DecidableEq V] + [Fintype ι] [Fintype η] [DecidableEq ι] [DecidableEq η] + (Y : V → EuclideanSpace ℝ η) (u v : ι → V) + (j : ι → η) (hj : Function.Injective j) {a ε : ℝ} + (ha : 0 < a) (hε : 0 < ε) (hε1 : ε < 1/3) + (hpos : 0 < (∑i, (Y (u i) - Y (v i)).ofLp (j i))^2) + (hbound : a * Fintype.card ι * (∑i, ‖Y (u i)-Y (v i)‖^2) ≤ + (∑i, (Y (u i)-Y (v i)).ofLp (j i))^2) : + a ≤ 1 ∧ ∃ S : Finset V, ∃ r : ℝ, 0 < r ∧ + S ⊆ (univ.image u ∪ univ.image v) ∧ 2 ≤ S.card ∧ + ε^2 * a * Fintype.card ι ≤ 1024 * S.card ∧ + ε^2 * a^ε * (∑i, (Y (u i)-Y (v i)).ofLp (j i))^2 ≤ + 1024 * Fintype.card ι * (S.card*r) ∧ + (∀x ∈ S, ∀y ∈ S, x ≠ y → 2 * Real.sqrt r < ‖Y x-Y y‖) := by + classical + let Y' : V → EuclideanSpace ℝ ι := fun x => WithLp.toLp 2 (fun i => (Y x).ofLp (j i)) + let b₀ := EuclideanSpace.basisFun ι ℝ + let T := b₀.toBasis.constr ℝ (fun i => Y' (u i)-Y' (v i)) + have hT₀ (i : ι) : T (b₀ i) = Y' (u i)-Y' (v i) := + b₀.toBasis.constr_basis ℝ _ i + have htr : LinearMap.trace ℝ (EuclideanSpace ℝ ι) T = + ∑i, (Y (u i)-Y (v i)).ofLp (j i) := by + rw [LinearMap.trace_eq_sum_inner _ b₀] + apply sum_congr rfl + intro i hi + rw [hT₀, EuclideanSpace.basisFun_inner] + rfl + have hn (x y : V) : ‖Y' x-Y' y‖^2 ≤ ‖Y x-Y y‖^2 := by + simp only [EuclideanSpace.norm_sq_eq] + change (∑i, ‖(Y x-Y y).ofLp (j i)‖^2) ≤ ∑i, ‖(Y x-Y y).ofLp i‖^2 + rw [← sum_image (f := fun i => ‖(Y x-Y y).ofLp i‖^2) hj.injOn] + exact sum_le_sum_of_subset_of_nonneg (subset_univ _) (by intros; positivity) + have hf : frobSq T ≤ ∑i, ‖Y (u i)-Y (v i)‖^2 := by + rw [frobSq_eq_sum b₀] + exact sum_le_sum (fun i _ => by rw [hT₀]; exact hn _ _) + let e : Fin (Module.finrank ℝ (EuclideanSpace ℝ ι)) ≃ ι := + (finCongr finrank_euclideanSpace).trans (Fintype.equivFin ι).symm + let b := b₀.reindex e.symm + have hT : ∀i, T (b i) = Y' (u (e i))-Y' (v (e i)) := by + intro i + simpa only [b, OrthonormalBasis.reindex_apply, Equiv.symm_symm] using hT₀ (e i) + have hassume : a * Module.finrank ℝ (EuclideanSpace ℝ ι) * frobSq T ≤ + LinearMap.trace ℝ (EuclideanSpace ℝ ι) T ^ 2 := by + rw [htr, finrank_euclideanSpace] + exact (mul_le_mul_of_nonneg_left hf (by positivity)).trans hbound + have htrace : 0 < |LinearMap.trace ℝ (EuclideanSpace ℝ ι) T| := by + rw [htr] + exact abs_pos.mpr (sq_pos_iff.mp hpos) + obtain ⟨ha1, S, r, hr, hSF, hS2, hcard, hmass, hsep⟩ := + spectral_packing_power Y' (u ∘ e) (v ∘ e) b T hT ha htrace hassume hε hε1 + rw [htr, finrank_euclideanSpace] at hmass + rw [finrank_euclideanSpace] at hcard + refine ⟨ha1, S, r, hr, ?_, hS2, hcard, hmass, ?_⟩ + · intro x hx + rcases mem_union.mp (hSF hx) with hh | hh + · obtain ⟨i, hi, rfl⟩ := mem_image.mp hh + exact mem_union_left _ (mem_image.mpr ⟨e i, mem_univ _, rfl⟩) + · obtain ⟨i, hi, rfl⟩ := mem_image.mp hh + exact mem_union_right _ (mem_image.mpr ⟨e i, mem_univ _, rfl⟩) + · intro x hx y hy hxy + exact (hsep x hx y hy hxy).trans_le ((sq_le_sq₀ (norm_nonneg _) (norm_nonneg _)).mp (hn x y)) + +end +end StrongThinTree.Spectral + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/SpectralSplit.lean b/lean/OAI/Combinatorics/ThinTrees/SpectralSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..c45cd5eb55bfafe50a8007341df2884f79dcee1e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/SpectralSplit.lean @@ -0,0 +1,83 @@ +import OAI.Combinatorics.ThinTrees.Blocks + +namespace OAI + +universe uI uD + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} [Fintype I] [DecidableEq I] [Fintype D] [DecidableEq D] + +omit [DecidableEq I] in + +theorem two_sided_split (w : I → D → ℝ) {ε : ℝ} (hε : 0 < ε) + (hiso : (∑i, Matrix.vecMulVec (w i) (w i)) ≤ (2 : ℝ) • (1 : Matrix D D ℝ)) + (hsize : ∀i, (Matrix.vecMulVec (w i) (w i)).trace ≤ ε) : + ∃A : Finset I, + (1/2 : ℝ) • (∑i, Matrix.vecMulVec (w i) (w i)) - + (2*Real.sqrt ε+ε) • (1 : Matrix D D ℝ) ≤ ∑i ∈ A, Matrix.vecMulVec (w i) (w i) ∧ + (∑i ∈ A, Matrix.vecMulVec (w i) (w i)) ≤ + (1/2 : ℝ) • (∑i, Matrix.vecMulVec (w i) (w i)) + + (2*Real.sqrt ε+ε) • (1 : Matrix D D ℝ) := by + let Smat := ∑i, Matrix.vecMulVec (w i) (w i) + let τ := 2*Real.sqrt ε+ε + have hhalf : (1/2 : ℝ) • Smat ≤ (1 : Matrix D D ℝ) := by + have hh := smul_le_smul_of_nonneg_left hiso (by norm_num : (0:ℝ) ≤ 1/2) + simpa only [smul_smul,show (1/2:ℝ)*2=1 by norm_num,one_smul] using hh + have hmean : (∑i, ∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (blockEmbed (w i) b) (blockEmbed (w i) b))= + Matrix.blockDiagonal (fun _ : Bool => (1/2 : ℝ) • Smat) := by + simp_rw [blockEmbed_mean] + rw [←blockDiagonal_sum] + simp only [Smat,Finset.smul_sum] + have hmiso : (∑i, ∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (blockEmbed (w i) b) (blockEmbed (w i) b)) ≤ 1 := by + rw [hmean] + simpa only [Matrix.blockDiagonal_one] using blockDiagonal_mono + (fun _ : Bool => (1/2 : ℝ) • Smat) (1 : Bool → Matrix D D ℝ) (fun _ => hhalf) + have hmsize : ∀i, (∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (blockEmbed (w i) b) (blockEmbed (w i) b)).trace ≤ ε := by + intro i + rw [Fintype.sum_bool, Matrix.trace_add] + simp only [Matrix.trace_smul,smul_eq_mul,blockEmbed_trace] + linarith [hsize i] + obtain ⟨f,hf⟩ := subisotropic_binary (fun i b => blockEmbed (w i) b) hε hmiso hmsize + rw [hmean] at hf + have hb (b : Bool) : (∑i, if f i=b then Matrix.vecMulVec (w i) (w i) else 0) ≤ + (1/2 : ℝ) • Smat+τ • (1 : Matrix D D ℝ) := by + have hh := blockDiag_mono hf b + simpa only [blockDiag_sum,blockEmbed_blockDiag,Matrix.blockDiag_add,Pi.add_apply, + Matrix.blockDiag_blockDiagonal,Matrix.blockDiag_smul,Pi.smul_apply,Matrix.blockDiag_one,Pi.one_apply] using hh + let A : Finset I := Finset.univ.filter (fun i => f i=true) + have hA : (∑i ∈ A, Matrix.vecMulVec (w i) (w i))= + ∑i, if f i=true then Matrix.vecMulVec (w i) (w i) else 0 := by + simp only [A,Finset.sum_filter] + have hcomp : (∑i, if f i=true then Matrix.vecMulVec (w i) (w i) else 0)+ + (∑i, if f i=false then Matrix.vecMulVec (w i) (w i) else 0)=Smat := by + rw [←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + cases f i <;> simp + refine ⟨A,?_,?_⟩ + · rw [hA] + have hh := hb false + rw [add_comm ((1/2 : ℝ) • Smat), ←sub_le_iff_le_add] at hh + have he : (∑i, if f i=false then Matrix.vecMulVec (w i) (w i) else 0) - + (1/2 : ℝ) • Smat = (1/2 : ℝ) • Smat - (∑i, if f i=true then Matrix.vecMulVec (w i) (w i) else 0) := by + have hc : (∑i, if f i=false then Matrix.vecMulVec (w i) (w i) else 0)= + Smat-(∑i, if f i=true then Matrix.vecMulVec (w i) (w i) else 0) := by + rw [←hcomp]; abel + rw [hc] + module + rw [he] at hh + exact (sub_le_comm.mp hh) + · rw [hA] + exact hb true + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Stability.lean b/lean/OAI/Combinatorics/ThinTrees/Stability.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c7989702439b630d3d19f8128033f9e30f3fff3 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Stability.lean @@ -0,0 +1,351 @@ +import OAI.Combinatorics.ThinTrees.Expectation + +namespace OAI + +universe uI uI2 uA uD uI3 uD2 + +section + +namespace StrongThinTree.MSS +noncomputable section +open Finset Polynomial +open scoped Classical ComplexOrder + +def Stable {I : Type uI} (p : MvPolynomial I ℂ) : Prop := + ∀z : I → ℂ, (∀i, 0 < (z i).im) → MvPolynomial.eval z p ≠ 0 + +variable {I : Type uI2} [DecidableEq I] + +def slice (p : MvPolynomial I ℂ) (z : I → ℂ) (i : I) : Polynomial ℂ := + MvPolynomial.eval₂ Polynomial.C (fun j => if j=i then Polynomial.X else Polynomial.C (z j)) p + +lemma slice_eval (p : MvPolynomial I ℂ) (z : I → ℂ) (i : I) (w : ℂ) : + (slice p z i).eval w = MvPolynomial.eval (Function.update z i w) p := by + induction p using MvPolynomial.induction_on with + | C a => simp [slice] + | add p q hp hq => simpa [slice,MvPolynomial.eval₂_add] using congrArg₂ (·+·) hp hq + | mul_X p j hp => + simp only [slice] at hp + by_cases hji : j=i + · subst j + simp [slice,MvPolynomial.eval₂_mul,hp] + · simp [slice,MvPolynomial.eval₂_mul,hji,hp] + +lemma slice_derivative (p : MvPolynomial I ℂ) (z : I → ℂ) (i : I) : + (slice p z i).derivative = slice (MvPolynomial.pderiv i p) z i := by + induction p using MvPolynomial.induction_on with + | C a => simp [slice] + | add p q hp hq => + simp only [slice] at hp hq + simp [slice,MvPolynomial.eval₂_add,hp,hq] + | mul_X p j hp => + simp only [slice] at hp + rw [MvPolynomial.pderiv_mul] + by_cases hji : j=i + · subst j + simp [slice,MvPolynomial.eval₂_mul,MvPolynomial.eval₂_add,Polynomial.derivative_mul,hp] + · simp [slice,MvPolynomial.eval₂_mul,Polynomial.derivative_mul, + MvPolynomial.pderiv_X,hji,hp] + +lemma slice_eval_self (p : MvPolynomial I ℂ) (z : I → ℂ) (i : I) : + (slice p z i).eval (z i) = MvPolynomial.eval z p := by + simpa using slice_eval p z i (z i) + +lemma slice_derivative_eval_self (p : MvPolynomial I ℂ) (z : I → ℂ) (i : I) : + (slice p z i).derivative.eval (z i) = MvPolynomial.eval z (MvPolynomial.pderiv i p) := by + rw [slice_derivative,slice_eval_self] + +lemma inverse_difference_im_neg {z a : ℂ} (hz : 0 < z.im) (ha : a.im ≤ 0) : + (1/(z-a)).im < 0 := by + have hd : 0 < (z-a).im := by simp only [Complex.sub_im]; linarith + have hd0 : z-a ≠ 0 := fun h => by simpa [h] using hd.ne' + simp only [one_div,Complex.inv_im] + exact div_neg_of_neg_of_pos (neg_neg_of_pos hd) (Complex.normSq_pos.mpr hd0) + +lemma polynomial_log_derivative {p : Polynomial ℂ} {z : ℂ} + (hz : 0 < z.im) (hp : ∀w : ℂ, 0 < w.im → p.eval w ≠ 0) : + p.derivative.eval z / p.eval z = 0 ∨ (p.derivative.eval z / p.eval z).im < 0 := by + have hp0 : p ≠ 0 := fun h => by simpa [h] using hp z hz + have hr : ∀a ∈ p.roots, a.im ≤ 0 := by + intro a ha + by_contra h + exact hp a (lt_of_not_ge h) ((Polynomial.mem_roots hp0).mp ha) + rw [(IsAlgClosed.splits p).eval_derivative_div_eval_of_ne_zero (hp z hz)] + by_cases hempty : p.roots = 0 + · left + simp [hempty] + · right + have hsum : ∀s : Multiset ℂ, (∀a ∈ s, a.im ≤ 0) → s ≠ 0 → + ((s.map (fun a => 1/(z-a))).sum).im < 0 := by + intro s + induction s using Multiset.induction_on with + | empty => simp + | @cons a s ih => + intro hs _ + have ha := inverse_difference_im_neg hz (hs a (by simp)) + have hsn : ∀b ∈ s, b.im ≤ 0 := fun b hb => hs b (by simp [hb]) + by_cases he : s=0 + · simp only [he,Multiset.map_cons,Multiset.map_zero,Multiset.sum_cons,Multiset.sum_zero,add_zero] + exact ha + · have hh := ih hsn he + simp only [Multiset.map_cons,Multiset.sum_cons,Complex.add_im] + linarith + exact hsum _ hr hempty + +lemma Stable.sub_pderiv {p : MvPolynomial I ℂ} (hp : Stable p) (i : I) : + Stable (p-MvPolynomial.pderiv i p) := by + intro z hz + have hslice : ∀w : ℂ, 0 < w.im → (slice p z i).eval w ≠ 0 := by + intro w hw + rw [slice_eval] + apply hp + intro j + by_cases hji : j=i + · subst j + simpa using hw + · simpa [Function.update_of_ne hji] using hz j + have hh := polynomial_log_derivative (hz i) hslice + rw [slice_derivative_eval_self,slice_eval_self] at hh + intro heq + have heq' : MvPolynomial.eval z (MvPolynomial.pderiv i p) = MvPolynomial.eval z p := by + exact (sub_eq_zero.mp (by simpa only [MvPolynomial.eval_sub] using heq)).symm + rw [heq',div_self (hp z hz)] at hh + rcases hh with hh | hh + · exact one_ne_zero hh + · simp at hh + +lemma factor_norm_bound {z a r : ℂ} (hz : 0 < z.im) (hr : r.im ≤ 0) : + ‖a-r‖ ≤ (1+‖a-z‖/z.im)*‖z-r‖ := by + have hzr : z.im ≤ ‖z-r‖ := by + have hh := Complex.abs_im_le_norm (z-r) + have hh' := le_abs_self (z-r).im + simp only [Complex.sub_im] at hh hh' + linarith + have htriangle : ‖a-r‖ ≤ ‖a-z‖+‖z-r‖ := by + simpa only [sub_add_sub_cancel] using norm_add_le (a-z) (z-r) + have hh := mul_le_mul_of_nonneg_left hzr (div_nonneg (norm_nonneg (a-z)) hz.le) + have he : (‖a-z‖/z.im)*z.im = ‖a-z‖ := div_mul_cancel₀ _ hz.ne' + nlinarith only [hh,he,htriangle] + +lemma stable_eval_norm_bound {p : Polynomial ℂ} {z : ℂ} (hz : 0 < z.im) + (hp : ∀w : ℂ, 0 < w.im → p.eval w ≠ 0) (a : ℂ) {D : ℕ} + (hD : p.natDegree ≤ D) : + ‖p.eval a‖ ≤ ‖p.eval z‖*(1+‖a-z‖/z.im)^D := by + have hp0 : p ≠ 0 := fun h => by simpa [h] using hp z hz + have hr : ∀r ∈ p.roots, r.im ≤ 0 := by + intro r hr + by_contra hh + exact hp r (lt_of_not_ge hh) ((Polynomial.mem_roots hp0).mp hr) + let C := 1+‖a-z‖/z.im + have hC : 1 ≤ C := le_add_of_nonneg_right (div_nonneg (norm_nonneg _) hz.le) + have hg : ∀s : Multiset ℂ, (∀r ∈ s, r.im ≤ 0) → + ‖(s.map (fun r => a-r)).prod‖ ≤ C^s.card*‖(s.map (fun r => z-r)).prod‖ := by + intro s + induction s using Multiset.induction_on with + | empty => simp + | @cons r s ih => + intro hrs + have h1 := factor_norm_bound (a := a) hz (hrs r (by simp)) + have h2 := ih (fun u hu => hrs u (by simp [hu])) + have hm := mul_le_mul h1 h2 (norm_nonneg _) (mul_nonneg (zero_le_one.trans hC) (norm_nonneg _)) + simpa only [Multiset.map_cons,Multiset.prod_cons,Multiset.card_cons,norm_mul,pow_succ, + mul_assoc,mul_left_comm,mul_comm] using hm + have hroot := hg p.roots hr + have hdeg : C^p.roots.card ≤ C^D := by + rw [←(IsAlgClosed.splits p).natDegree_eq_card_roots] + exact pow_le_pow_right₀ hC hD + rw [(IsAlgClosed.splits p).eval_eq_prod_roots a,(IsAlgClosed.splits p).eval_eq_prod_roots z] + simp only [norm_mul] + have h1 := mul_le_mul_of_nonneg_left hroot (norm_nonneg p.leadingCoeff) + have h2 := mul_le_mul_of_nonneg_left hdeg + (mul_nonneg (norm_nonneg p.leadingCoeff) (norm_nonneg ((p.roots.map (fun r => z-r)).prod))) + nlinarith only [h1,h2] + +lemma polynomial_stability_limit {A : Type uA} {L : Filter A} [L.NeBot] + (f : A → Polynomial ℂ) (p : Polynomial ℂ) {D : ℕ} + (hD : ∀ᶠa in L, (f a).natDegree ≤ D) + (hf : ∀ᶠa in L, ∀z : ℂ, 0 < z.im → (f a).eval z ≠ 0) + (hlim : ∀z : ℂ, Filter.Tendsto (fun a => (f a).eval z) L (nhds (p.eval z))) + (hp : p ≠ 0) : ∀z : ℂ, 0 < z.im → p.eval z ≠ 0 := by + intro z hz hzero + have hvanish : ∀w : ℂ, 0 < w.im → p.eval w = 0 := by + intro w hw + have hb : ‖p.eval w‖ ≤ ‖p.eval z‖*(1+‖w-z‖/z.im)^D := + le_of_tendsto_of_tendsto (hlim w).norm ((hlim z).norm.mul_const _) (by + filter_upwards [hD,hf] with a hDa hfa + exact stable_eval_norm_bound hz hfa w hDa) + rw [hzero,norm_zero,zero_mul] at hb + exact norm_eq_zero.mp (le_antisymm hb (norm_nonneg _)) + have hinj : Function.Injective (fun k : ℕ => (k:ℂ)+Complex.I) := by + intro k l h + have hh := congrArg Complex.re h + simpa only [Complex.add_re,Complex.natCast_re,Complex.I_re,add_zero,Nat.cast_inj] using hh + have hinf := Set.infinite_range_of_injective hinj + have hroots : Set.range (fun k : ℕ => (k:ℂ)+Complex.I) ⊆ {w | p.IsRoot w} := by + rintro w ⟨k,rfl⟩ + exact hvanish _ (by simp) + exact hp (p.eq_zero_of_infinite_isRoot (hinf.mono hroots)) + +lemma slice_degree_bound (p : MvPolynomial I ℂ) : + ∃D : ℕ, ∀z i, (slice p z i).natDegree ≤ D := by + induction p using MvPolynomial.induction_on with + | C a => exact ⟨0,fun z i => by simp [slice]⟩ + | add p q hp hq => + obtain ⟨P,hP⟩ := hp + obtain ⟨Q,hQ⟩ := hq + refine ⟨max P Q,fun z i => ?_⟩ + have he : slice (p+q) z i = slice p z i+slice q z i := by simp [slice,MvPolynomial.eval₂_add] + rw [he] + exact (Polynomial.natDegree_add_le _ _).trans (max_le_max (hP z i) (hQ z i)) + | mul_X p j hp => + obtain ⟨P,hP⟩ := hp + refine ⟨P+1,fun z i => ?_⟩ + have he : slice (p*MvPolynomial.X j) z i = slice p z i * (if j=i then Polynomial.X else Polynomial.C (z j)) := by + simp [slice,MvPolynomial.eval₂_mul] + rw [he] + calc + _ ≤ (slice p z i).natDegree+(if j=i then Polynomial.X else Polynomial.C (z j)).natDegree := Polynomial.natDegree_mul_le + _ ≤ P+1 := by have hh := hP z i; split_ifs <;> simp only [Polynomial.natDegree_X,Polynomial.natDegree_C] <;> omega + +lemma Stable.slice_boundary {p : MvPolynomial I ℂ} (hp : Stable p) + (z : I → ℂ) (hz : ∀j, 0 ≤ (z j).im) (i : I) + (h0 : slice p z i ≠ 0) : + ∀w : ℂ, 0 < w.im → (slice p z i).eval w ≠ 0 := by + obtain ⟨D,hD⟩ := slice_degree_bound p + let f : ℝ → Polynomial ℂ := fun t => slice p (fun j => z j+(t:ℂ)*Complex.I) i + apply polynomial_stability_limit (L := nhdsWithin (0:ℝ) (Set.Ioi 0)) f (slice p z i) + (D := D) (Filter.Eventually.of_forall (fun t => hD _ _)) _ _ h0 + · filter_upwards [self_mem_nhdsWithin] with t ht + intro w hw + rw [slice_eval] + apply hp + intro j + by_cases hji : j=i + · subst j + simpa using hw + · simp only [Function.update_of_ne hji,Complex.add_im,Complex.mul_im, + Complex.ofReal_re,Complex.I_im,mul_one,Complex.ofReal_im, + Complex.I_re,mul_zero,add_zero] + exact add_pos_of_nonneg_of_pos (hz j) ht + · intro w + have hc : Continuous (fun t : ℝ => + MvPolynomial.eval (Function.update (fun j => z j+(t:ℂ)*Complex.I) i w) p) := by + apply (MvPolynomial.continuous_eval p).comp + apply continuous_pi + intro j + by_cases hji : j=i + · subst j + simpa using (continuous_const : Continuous (fun _ : ℝ => w)) + · simp only [Function.update_of_ne hji] + fun_prop + have hh := (hc.tendsto 0).mono_left (nhdsWithin_le_nhds (s := Set.Ioi 0)) + simpa only [f,slice_eval,Complex.ofReal_zero,zero_mul,add_zero] using hh + +lemma splits_of_upper_half_plane (p : Polynomial ℝ) + (hp : ∀w : ℂ, 0 < w.im → (p.map (algebraMap ℝ ℂ)).eval w ≠ 0) : p.Splits := by + apply Polynomial.Splits.of_splits_map (algebraMap ℝ ℂ) (IsAlgClosed.splits _) + intro a ha + have hroot := Polynomial.isRoot_of_mem_roots ha + have haeval : Polynomial.aeval a p=0 := by + simpa only [Polynomial.IsRoot,Polynomial.eval_map,Polynomial.aeval_def] using hroot + have hle : a.im ≤ 0 := by + by_contra hh + exact hp a (lt_of_not_ge hh) hroot + have hge : 0 ≤ a.im := by + by_contra hh + have hconj : (p.map (algebraMap ℝ ℂ)).eval (starRingEnd ℂ a)=0 := by + simp only [Polynomial.eval_map,←Polynomial.aeval_def,Polynomial.aeval_conj,haeval,map_zero] + exact hp _ (by simpa only [Complex.conj_im] using neg_pos.mpr (lt_of_not_ge hh)) hconj + refine ⟨a.re,?_⟩ + apply Complex.ext + · rfl + · change 0 = a.im + exact (le_antisymm hle hge).symm + +section Determinant +open Matrix +variable {D : Type uD} [Fintype D] [DecidableEq D] [Fintype I] + +omit [DecidableEq I] in +lemma stable_matrix_pencil (A : I → Matrix D D ℂ) + (hA : ∀i, (A i).PosSemidef) (hSum : (∑i, A i).PosDef) (z : I → ℂ) + (hz : ∀i, 0 < (z i).im) : (∑i, z i • A i).det ≠ 0 := by + let M := ∑i, z i • A i + have hker : ∀x : D → ℂ, M*ᵥx=0 → x=0 := by + intro x hx + by_contra hx0 + let a : I → ℂ := fun i => star x ⬝ᵥ (A i)*ᵥx + have ha : ∀i, 0 ≤ a i := fun i => (hA i).dotProduct_mulVec_nonneg x + have haR : ∀i, 0 ≤ (a i).re := fun i => (Complex.nonneg_iff.mp (ha i)).1 + have haI : ∀i, (a i).im=0 := fun i => (Complex.nonneg_iff.mp (ha i)).2.symm + have hs : 0 < ∑i, (a i).re := by + have hh := (Complex.pos_iff.mp (hSum.dotProduct_mulVec_pos hx0)).1 + simpa only [sum_mulVec,dotProduct_sum,Complex.re_sum] using hh + obtain ⟨j,hj,hjpos⟩ := (sum_pos_iff_of_nonneg (fun i _ => haR i)).mp hs + have hpos : 0 < ∑i, (z i).im*(a i).re := + (sum_pos_iff_of_nonneg (fun i _ => mul_nonneg (hz i).le (haR i))).mpr + ⟨j,mem_univ _,mul_pos (hz j) hjpos⟩ + have hzero : ∑i, z i*a i=0 := by + have hh := congrArg (fun y => star x ⬝ᵥ y) hx + simpa only [M,sum_mulVec,smul_mulVec,dotProduct_sum,dotProduct_smul, + smul_eq_mul,dotProduct_zero] using hh + have him : (∑i, (z i).im*(a i).re)=0 := by + have hh := congrArg Complex.im hzero + simpa only [Complex.im_sum,Complex.mul_im,haI,mul_zero,zero_add,Complex.zero_im] using hh + linarith only [hpos,him] + have hinj : Function.Injective M.mulVec := by + intro x y hxy + apply sub_eq_zero.mp + apply hker + rw [mulVec_sub,hxy,sub_self] + exact isUnit_iff_ne_zero.mp ((isUnit_iff_isUnit_det M).mp (mulVec_injective_iff_isUnit.mp hinj)) + +def determinantPencil (A : I → Matrix D D ℂ) : MvPolynomial I ℂ := + Matrix.det (fun a b => ∑i, MvPolynomial.X i*MvPolynomial.C (A i a b)) + +omit [DecidableEq I] in +lemma determinantPencil_eval (A : I → Matrix D D ℂ) (z : I → ℂ) : + MvPolynomial.eval z (determinantPencil A) = (∑i, z i • A i).det := by + let M : Matrix D D (MvPolynomial I ℂ) := fun a b => ∑i, MvPolynomial.X i*MvPolynomial.C (A i a b) + change (MvPolynomial.eval z) M.det = _ + rw [(MvPolynomial.eval z).map_det M] + congr 1 + ext a b + change (MvPolynomial.eval z) (∑i, MvPolynomial.X i*MvPolynomial.C (A i a b)) = _ + simp [Matrix.sum_apply,Matrix.smul_apply] + +omit [DecidableEq I] in +lemma determinantPencil_stable (A : I → Matrix D D ℂ) + (hA : ∀i, (A i).PosSemidef) (hSum : (∑i, A i).PosDef) : Stable (determinantPencil A) := by + intro z hz + rw [determinantPencil_eval] + exact stable_matrix_pencil A hA hSum z hz +end Determinant + +end +end StrongThinTree.MSS + +namespace StrongThinTree.MSS +noncomputable section +open Finset Polynomial +open scoped Classical ComplexOrder +variable {I : Type uI3} [DecidableEq I] + +def differentialProduct (dirs : List I) (p : MvPolynomial I ℂ) : MvPolynomial I ℂ := + dirs.foldl (fun q i => q-MvPolynomial.pderiv i q) p + +lemma Stable.differentialProduct {p : MvPolynomial I ℂ} (hp : Stable p) (dirs : List I) : + Stable (differentialProduct dirs p) := by + induction dirs generalizing p with + | nil => exact hp + | cons i dirs ih => exact ih (hp.sub_pderiv i) + +open Matrix +variable {D : Type uD2} [Fintype D] [DecidableEq D] [Fintype I] + +end +end StrongThinTree.MSS + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/StepBounds.lean b/lean/OAI/Combinatorics/ThinTrees/StepBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e80f124565b568c0f7eb9b0dae0dd859184e6b9 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/StepBounds.lean @@ -0,0 +1,136 @@ +import OAI.Combinatorics.ThinTrees.Normalization + +namespace OAI + +section + +noncomputable section +open Filter +open scoped Topology +namespace StrongThinTree + +def splitEpsilon (r : ℕ) : ℝ := 6*resistanceT r +def splitTau (r : ℕ) : ℝ := 2*Real.sqrt (splitEpsilon r)+splitEpsilon r +def stepCount (r : ℕ) : ℕ := ⌊(1-4*errorU r)*r/2⌋₊ + +lemma tendsto_errorU : Tendsto errorU atTop (𝓝 0) := by + change Tendsto (fun r : ℕ => errorU r) atTop (𝓝 0) + simpa [errorU,Function.comp_def,neg_div] using + (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ) < 1/16)).comp tendsto_natCast_atTop_atTop +lemma tendsto_resistanceT : Tendsto resistanceT atTop (𝓝 0) := by + change Tendsto (fun r : ℕ => resistanceT r) atTop (𝓝 0) + simpa [resistanceT,Function.comp_def,neg_div] using + (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ) < 1/2)).comp tendsto_natCast_atTop_atTop +lemma resistanceT_sq {r : ℕ} (hr : 0 < r) : resistanceT r^2=1/(r:ℝ) := by + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hr + unfold resistanceT + rw [pow_two,←Real.rpow_add hrR] + norm_num [Real.rpow_neg_one] +lemma splitTau_ratio {r : ℕ} (hr : 0 < r) : + splitTau r=(2*Real.sqrt 6*(r:ℝ)^(-3/16:ℝ)+6*(r:ℝ)^(-7/16:ℝ))*errorU r := by + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hr + have hs : Real.sqrt (splitEpsilon r)=Real.sqrt 6*(r:ℝ)^(-1/4:ℝ) := by + rw [splitEpsilon,resistanceT,Real.sqrt_mul (by norm_num),Real.sqrt_eq_rpow ((r:ℝ)^(-1/2:ℝ)),←Real.rpow_mul hrR.le] + norm_num + rw [splitTau,hs,splitEpsilon,resistanceT,errorU,add_mul] + have h1 : (r:ℝ)^(-3/16:ℝ)*(r:ℝ)^(-1/16:ℝ)=(r:ℝ)^(-1/4:ℝ) := by + rw [←Real.rpow_add hrR]; norm_num + have h2 : (r:ℝ)^(-7/16:ℝ)*(r:ℝ)^(-1/16:ℝ)=(r:ℝ)^(-1/2:ℝ) := by + rw [←Real.rpow_add hrR]; norm_num + calc + _ = 2*Real.sqrt 6*((r:ℝ)^(-3/16:ℝ)*(r:ℝ)^(-1/16:ℝ))+ + 6*((r:ℝ)^(-7/16:ℝ)*(r:ℝ)^(-1/16:ℝ)) := by rw [h1,h2]; ring + _ = _ := by ring + +lemma inverse_le_errorU {r : ℕ} (hr : 1 ≤ r) : 1/(r:ℝ) ≤ errorU r := by + have hh := Real.rpow_le_rpow_of_exponent_le + (show (1:ℝ) ≤ r by exact_mod_cast hr) (by norm_num : (-1:ℝ) ≤ -1/16) + simpa only [Real.rpow_neg_one,one_div,errorU] using hh + +lemma step_rounding {r : ℕ} (hr : 4 ≤ r) (hu : errorU r ≤ 1/16) + (hτ : splitTau r ≤ errorU r/2) : + stepCount r ≤ ⌊(1/2-splitTau r)*(extractQ r:ℝ)/(1+errorU r)⌋₊ ∧ + (5/16:ℝ)*r ≤ stepCount r ∧ (stepCount r:ℝ) ≤ (r:ℝ)/2 ∧ + (1/2+3*splitTau r)*(r:ℝ) ≤ (1+15*errorU r)*stepCount r := by + have hrR : (4:ℝ) ≤ r := by exact_mod_cast hr + have hrp : (0:ℝ) < r := by linarith + have hu0 : 0 ≤ errorU r := Real.rpow_nonneg hrp.le _ + have ht0 : 0 ≤ splitTau r := by unfold splitTau splitEpsilon resistanceT; positivity + have hc : 0 ≤ 1/2-splitTau r := by linarith + have hinv := inverse_le_errorU (by omega : 1 ≤ r) + have hru : 1 ≤ errorU r*r := (div_le_iff₀ hrp).mp hinv + obtain ⟨_,_,_,hq⟩ := extractQ_bounds hrR (by linarith) + have hab : 0 ≤ (1-errorU r)*r-1 := by nlinarith + have hm := mul_le_mul_of_nonneg_left hq hc + have hτm := mul_le_mul_of_nonneg_right hτ hab + have hur2 : 0 ≤ (r:ℝ)*(errorU r)^2 := mul_nonneg hrp.le (sq_nonneg _) + have hpack : (1-4*errorU r)*r/2 ≤ (1/2-splitTau r)*(extractQ r:ℝ)/(1+errorU r) := by + apply (le_div_iff₀ (by linarith : 0 < 1+errorU r)).mpr + nlinarith + have hfloorLo := Nat.sub_one_lt_floor ((1-4*errorU r)*r/2) + have hfloorHi := Nat.floor_le (show 0 ≤ (1-4*errorU r)*r/2 by positivity [show 0 ≤ 1-4*errorU r by linarith]) + change (1-4*errorU r)*r/2-1 < (stepCount r:ℝ) at hfloorLo + change (stepCount r:ℝ) ≤ (1-4*errorU r)*r/2 at hfloorHi + have hcountLo : (1/2-3*errorU r)*r ≤ (stepCount r:ℝ) := by nlinarith + have hcountPos : 0 ≤ (stepCount r:ℝ) := Nat.cast_nonneg _ + have hul := mul_le_mul_of_nonneg_right hu hrp.le + have hum := mul_nonneg hu0 (show 0 ≤ 3-45*errorU r by linarith) + have humr := mul_nonneg hrp.le hum + have hproduct := mul_le_mul_of_nonneg_left hcountLo (show 0 ≤ 1+15*errorU r by positivity) + refine ⟨Nat.floor_le_floor hpack,by nlinarith,by nlinarith,?_⟩ + have hτr := mul_le_mul_of_nonneg_right hτ hrp.le + nlinarith + +structure StepNumeric (r : ℕ) : Prop where + rlarge : 4 ≤ r + usmall : errorU r ≤ 1/16 + qpos : 0 < extractQ r + size : (1+errorU r)/(extractQ r:ℝ) ≤ 2*resistanceT r + tausmall : splitTau r ≤ errorU r/2 + packing : stepCount r ≤ ⌊(1/2-splitTau r)*(extractQ r:ℝ)/(1+errorU r)⌋₊ + lower : (5/16:ℝ)*r ≤ stepCount r + upper : (stepCount r:ℝ) ≤ (r:ℝ)/2 + ratio : (1/2+3*splitTau r)*(r:ℝ) ≤ (1+15*errorU r)*stepCount r + +lemma eventual_step_numeric : ∃R : ℕ, ∀r : ℕ, R ≤ r → StepNumeric r := by + have htau : Tendsto (fun r : ℕ => 2*Real.sqrt 6*(r:ℝ)^(-3/16:ℝ)+6*(r:ℝ)^(-7/16:ℝ)) atTop (𝓝 0) := by + simpa [Function.comp_def,neg_div] using + (((tendsto_rpow_neg_atTop (by norm_num : (0:ℝ) < 3/16)).const_mul (2*Real.sqrt 6)).add + ((tendsto_rpow_neg_atTop (by norm_num : (0:ℝ) < 7/16)).const_mul 6)).comp tendsto_natCast_atTop_atTop + have hev : ∀ᶠ r : ℕ in atTop, 4 ≤ r ∧ errorU r ≤ 1/16 ∧ resistanceT r ≤ 1/2 ∧ + 2*Real.sqrt 6*(r:ℝ)^(-3/16:ℝ)+6*(r:ℝ)^(-7/16:ℝ) ≤ 1/2 := by + filter_upwards [eventually_ge_atTop 4, + tendsto_errorU.eventually_lt_const (by norm_num : (0:ℝ) < 1/16), + tendsto_resistanceT.eventually_lt_const (by norm_num : (0:ℝ) < 1/2), + htau.eventually_lt_const (by norm_num : (0:ℝ) < 1/2)] with r hr hu ht hτ + exact ⟨hr,hu.le,ht.le,hτ.le⟩ + obtain ⟨R,hR⟩ := eventually_atTop.mp hev + refine ⟨R,fun r hr => ?_⟩ + obtain ⟨hr4,hu,ht,hτ⟩ := hR r hr + have hrp : 0 < r := by omega + have hrR : (0:ℝ) < r := Nat.cast_pos.mpr hrp + have hu0 : 0 ≤ errorU r := Real.rpow_nonneg hrR.le _ + have hτsmall : splitTau r ≤ errorU r/2 := by + rw [splitTau_ratio hrp] + have hh := mul_le_mul_of_nonneg_right hτ hu0 + linarith + obtain ⟨hpack,hlo,hhi,hratio⟩ := step_rounding hr4 hu hτsmall + obtain ⟨hqlo,_,_,_⟩ := extractQ_bounds (by exact_mod_cast hr4) (by linarith) + have hqp : (0:ℝ) < extractQ r := by linarith + have htpos : 0 < resistanceT r := Real.rpow_pos_of_pos hrR _ + have hinv : 4/(r:ℝ) ≤ 2*resistanceT r := by + have hh := resistanceT_sq hrp + have hmul := mul_le_mul_of_nonneg_left ht htpos.le + rw [show 4/(r:ℝ)=4*(resistanceT r)^2 by rw [hh]; ring] + nlinarith + have hsize : (1+errorU r)/(extractQ r:ℝ) ≤ 2*resistanceT r := by + apply le_trans _ hinv + apply (div_le_div_iff₀ hqp hrR).mpr + nlinarith + exact ⟨hr4,hu,by exact_mod_cast hqp,hsize,hτsmall,hpack,hlo,hhi,hratio⟩ +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Subisotropic.lean b/lean/OAI/Combinatorics/ThinTrees/Subisotropic.lean new file mode 100644 index 0000000000000000000000000000000000000000..1bfe6a104d18e88b0ff2290f03d771a71a13d335 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Subisotropic.lean @@ -0,0 +1,66 @@ +import OAI.Combinatorics.ThinTrees.Padding + +namespace OAI + +universe uI uD + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} [Fintype I] [Fintype D] [DecidableEq D] + +theorem subisotropic_binary (v : I → Bool → D → ℝ) {ε : ℝ} (hε : 0 < ε) + (hiso : (∑i, ∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (v i b) (v i b)) ≤ 1) + (hsize : ∀i, (∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (v i b) (v i b)).trace ≤ ε) : + ∃f : I → Bool, (∑i, Matrix.vecMulVec (v i (f i)) (v i (f i))) ≤ + (∑i, ∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (v i b) (v i b)) + + (2*Real.sqrt ε+ε) • (1 : Matrix D D ℝ) := by + classical + let M := ∑i, ∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (v i b) (v i b) + have hR : (1-M).PosSemidef := (sub_nonneg.mpr hiso).posSemidef + obtain ⟨N,u,hu,hutr⟩ := deterministic_padding (1-M) hR hε + let V : I ⊕ (Fin N × D) → Bool → D → ℝ := Sum.elim v (fun p _ => u p) + have hprob : ∀i : I ⊕ (Fin N × D), ∑_b : Bool, (1/2 : ℝ)=1 := by + intro i + norm_num [Fintype.sum_bool] + have hdet (p : Fin N × D) : + (∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (V (.inr p) b) (V (.inr p) b))= + Matrix.vecMulVec (u p) (u p) := by + simp only [V,Sum.elim_inr,Fintype.sum_bool,←add_smul] + norm_num + have hiso' : (∑i, ∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (V i b) (V i b))=1 := by + rw [Fintype.sum_sum_type] + simp only [hdet,V,Sum.elim_inl] + change M+(∑p, Matrix.vecMulVec (u p) (u p))=1 + rw [hu] + abel + have hsize' : ∀i, (∑b : Bool, (1/2 : ℝ) • Matrix.vecMulVec (V i b) (V i b)).trace ≤ ε := by + intro i + cases i with + | inl i => exact hsize i + | inr p => rw [hdet]; exact hutr p + obtain ⟨f,hf⟩ := small_vectors (fun _ _ => (1/2 : ℝ)) V (by intros; norm_num) hprob hiso' hε hsize' + rw [Fintype.sum_sum_type] at hf + simp only [V,Sum.elim_inl,Sum.elim_inr] at hf + rw [hu] at hf + refine ⟨fun i => f (.inl i),?_⟩ + change (∑i, Matrix.vecMulVec (v i (f (.inl i))) (v i (f (.inl i)))) ≤ + M+(2*Real.sqrt ε+ε) • (1 : Matrix D D ℝ) + have hβ : (1+Real.sqrt ε)^2=1+(2*Real.sqrt ε+ε) := by + nlinarith [Real.sq_sqrt hε.le] + have he : (1+Real.sqrt ε)^2 • (1 : Matrix D D ℝ) = + (M+(2*Real.sqrt ε+ε) • (1 : Matrix D D ℝ))+(1-M) := by + rw [hβ,add_smul,one_smul] + abel + rw [he] at hf + exact (add_le_add_iff_right (1-M)).mp hf + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/ThresholdChain.lean b/lean/OAI/Combinatorics/ThinTrees/ThresholdChain.lean new file mode 100644 index 0000000000000000000000000000000000000000..70b122b9771054b487a41beb8e2f1a1e4371eaa5 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/ThresholdChain.lean @@ -0,0 +1,83 @@ +import OAI.Combinatorics.ThinTrees.PartitionHierarchy + +namespace OAI + +section + +namespace StrongThinTree.MultiGraph +noncomputable section +open Finset +variable {n m : ℕ} (G : MultiGraph n m) + +def thresholdEdges (_G : MultiGraph n m) (R : Fin m → ℝ) (s : ℝ) : Finset (Fin m) := univ.filter (fun e => R e ≤ s) +def rankedEdges (R : Fin m → ℝ) (i : ℕ) : Finset (Fin m) := univ.filter (fun e => (G.thresholdEdges R (R e)).card ≤ i) +lemma rankedEdges_mono (R : Fin m → ℝ) : Monotone (G.rankedEdges R) := by + intro i j hij e he + exact mem_filter.mpr ⟨mem_univ _,(mem_filter.mp he).2.trans hij⟩ +lemma rankedEdges_full (R : Fin m → ℝ) : G.rankedEdges R m=univ := by + ext e + simp only [rankedEdges,mem_filter,mem_univ,true_and,iff_true] + exact (card_le_card (subset_univ _)).trans_eq (by simp) +lemma rankedEdges_threshold (R : Fin m → ℝ) (s : ℝ) : + G.rankedEdges R (G.thresholdEdges R s).card=G.thresholdEdges R s := by + ext e + change (e ∈ univ.filter (fun f => (univ.filter (fun g => R g ≤ R f)).card ≤ (univ.filter (fun g => R g ≤ s)).card)) ↔ e ∈ univ.filter (fun f => R f ≤ s) + simp only [mem_filter,mem_univ,true_and] + constructor + · intro h + by_contra he + have hlt : s < R e := lt_of_not_ge he + have hsub : (univ.filter (fun f => R f ≤ s)) ⊂ (univ.filter (fun f => R f ≤ R e)) := by + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨(by intro f hf; exact mem_filter.mpr ⟨mem_univ _, (mem_filter.mp hf).2.trans hlt.le⟩),?_⟩ + intro hh + have he' : e ∈ univ.filter (fun f => R f ≤ s) := hh ▸ mem_filter.mpr ⟨mem_univ _,le_rfl⟩ + exact he (mem_filter.mp he').2 + have hh := card_lt_card hsub + omega + · intro he + exact card_le_card ((by intro f hf; exact mem_filter.mpr ⟨mem_univ _, (mem_filter.mp hf).2.trans he⟩)) + +def packingChain (R : Fin m → ℝ) (q : ℕ) : PartitionChain n where + parts i := G.packingParts (G.rankedEdges R i) q + partition _i := G.packingParts_vertexPartition _ q + coarsens _i _j hij := G.packingParts_coarsens (G.rankedEdges_mono R hij) + +lemma packingChain_local (R : Fin m → ℝ) (q : ℕ) (i : ℕ) : + ∀A ∈ (G.packingChain R q).parts i, G.EdgeConnectedReal A q := G.packingParts_local _ q + +lemma packingChain_crossing (R : Fin m → ℝ) (q i : ℕ) : + (G.packingChain R q).crossing G i=G.crossing univ (G.partLabel (G.rankedEdges R i) q) := by + classical + ext e + rw [PartitionChain.mem_crossing] + simp only [MultiGraph.crossing,mem_filter,mem_univ,true_and] + rw [Ne,Ne,G.partLabel_eq_iff] + have he (v : Fin n) : (G.packingChain R q).block i v=G.partOf (G.rankedEdges R i) q v := by + apply (G.packingChain R q).block_eq_of_mem + · exact mem_filter.mpr ⟨mem_univ _,(G.partOf_spec _ q v).2⟩ + · exact (G.partOf_spec _ q v).1 + rw [he,he] + +lemma treePackable_mono_edges {F F' : Finset (Fin m)} {q : ℕ} + (h : F ⊆ F') (hp : G.TreePackable F q) : G.TreePackable F' q := by + obtain ⟨T,hT,hd⟩ := hp + exact ⟨T,fun i => ⟨(hT i).1.trans h,(hT i).2⟩,hd⟩ + +lemma treePackable_mono_count {F : Finset (Fin m)} {q r : ℕ} + (h : q ≤ r) (hp : G.TreePackable F r) : G.TreePackable F q := by + obtain ⟨T,hT,hd⟩ := hp + exact ⟨fun i => T (Fin.castLE h i),fun i => hT _,fun i j hij => hd (fun he => hij (Fin.castLE_injective h he))⟩ + +lemma packingChain_root (R : Fin m → ℝ) {q : ℕ} (hn : 0 < n) (hp : G.TreePackable univ q) : + (G.packingChain R q).parts m={univ} := by + change G.packingParts (G.rankedEdges R m) q={univ} + rw [G.rankedEdges_full] + exact G.packingParts_eq_root hn hp + +end +end StrongThinTree.MultiGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Translation.lean b/lean/OAI/Combinatorics/ThinTrees/Translation.lean new file mode 100644 index 0000000000000000000000000000000000000000..cadccd6b5e81726ade3b53bd9bef2a75f22e89ea --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Translation.lean @@ -0,0 +1,135 @@ +import OAI.Combinatorics.ThinTrees.FiniteSelection + +namespace OAI + +universe uI uD uR uS + +section + +noncomputable section +open Matrix Polynomial Finset +namespace StrongThinTree.MSS +variable {I : Type uI} {D : Type uD} {R : Type uR} {S : Type uS} [DecidableEq I] [Fintype I] [Fintype D] [DecidableEq D] + [CommRing R] [CommRing S] + +omit [DecidableEq I] in +lemma basePencil_map (f : R →+* S) (M : Matrix D D R) (A : I → Matrix D D R) : + (basePencil M A).map f=basePencil (M.map f) (fun i => (A i).map f) := by + unfold basePencil + rw [(MvPolynomial.map f).map_det] + apply congrArg Matrix.det + apply Matrix.ext + intro a b + simp [Matrix.map_apply,Matrix.add_apply,Matrix.sum_apply,Matrix.smul_apply] + +omit [DecidableEq I] [Fintype I] in +lemma eval_zero_map (f : R →+* S) (p : MvPolynomial I R) : + MvPolynomial.eval (fun _ => 0) (p.map f)=f (MvPolynomial.eval (fun _ => 0) p) := by + induction p using MvPolynomial.induction_on with + | C r => simp + | add p q hp hq => simp [] + | mul_X p k hp => simp + +omit [DecidableEq I] in +lemma mixedEval_map (f : R →+* S) (dirs : List I) (M : Matrix D D R) (A : I → Matrix D D R) : + f (mixedEval dirs M A)=mixedEval dirs (M.map f) (fun i => (A i).map f) := by + unfold mixedEval + rw [←eval_zero_map,←diffProduct_map,basePencil_map] + +omit [DecidableEq I] in +lemma mixedChar_eval (A : I → Matrix D D R) (x : R) : + (mixedChar A).eval x=mixedEval Finset.univ.toList (x • (1 : Matrix D D R)) A := by + unfold mixedChar + change Polynomial.evalRingHom x (mixedEval _ _ _) = _ + rw [mixedEval_map] + congr 1 + · apply Matrix.ext + intro a b + by_cases h : a=b <;> simp [Matrix.map_apply,Matrix.smul_apply,h] + · funext i + apply Matrix.ext + intro a b + simp [Matrix.map_apply] + +def translate (x : R) : MvPolynomial I R →+* MvPolynomial I R := + MvPolynomial.eval₂Hom MvPolynomial.C (fun i => MvPolynomial.X i+MvPolynomial.C x) + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +@[simp] lemma translate_C (x r : R) : translate (I := I) x (MvPolynomial.C r)=MvPolynomial.C r := by + simp [translate] + +omit [Fintype I] [Fintype D] [DecidableEq D] [DecidableEq I] in +@[simp] lemma translate_X (x : R) (i : I) : translate x (MvPolynomial.X i)= + MvPolynomial.X i+MvPolynomial.C x := by + simp [translate] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma translate_pderiv (x : R) (i : I) (p : MvPolynomial I R) : + translate x (MvPolynomial.pderiv i p)=MvPolynomial.pderiv i (translate x p) := by + induction p using MvPolynomial.induction_on with + | C r => simp [translate] + | add p q hp hq => simpa only [map_add] using congrArg₂ (·+·) hp hq + | mul_X p k hp => + by_cases hk : k=i + · subst k + simp only [MvPolynomial.pderiv_mul,map_add,map_mul,MvPolynomial.pderiv_X_self, + mul_one,hp] + simp [translate] + · simp only [MvPolynomial.pderiv_mul,map_mul,MvPolynomial.pderiv_X_of_ne hk, + mul_zero,add_zero,hp] + simp [translate,hk] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +lemma translate_diffProduct (x : R) (dirs : List I) (p : MvPolynomial I R) : + translate x (diffProduct dirs p)=diffProduct dirs (translate x p) := by + induction dirs generalizing p with + | nil => rfl + | cons i dirs ih => simp only [diffProduct_cons,ih,map_sub,translate_pderiv] + +omit [Fintype I] [Fintype D] [DecidableEq D] in +omit [DecidableEq I] in +lemma eval_zero_translate (x : R) (p : MvPolynomial I R) : + MvPolynomial.eval (fun _ => 0) (translate x p)=MvPolynomial.eval (fun _ => x) p := by + induction p using MvPolynomial.induction_on with + | C r => simp [translate] + | add p q hp hq => simpa only [map_add] using congrArg₂ (·+·) hp hq + | mul_X p k hp => simpa only [map_mul,translate_X, + MvPolynomial.eval_add,MvPolynomial.eval_X,MvPolynomial.eval_C,zero_add] using congrArg (·*x) hp + +omit [Fintype D] [DecidableEq D] in +omit [DecidableEq I] in +lemma translate_linear_sum (a : I → R) (x : R) : + translate x (∑i, MvPolynomial.X i * MvPolynomial.C (a i))= + (∑i, MvPolynomial.X i * MvPolynomial.C (a i))+MvPolynomial.C x*MvPolynomial.C (∑i, a i) := by + simp only [map_sum,map_mul,translate_X,translate_C,add_mul,Finset.sum_add_distrib] + rw [←Finset.mul_sum,←map_sum] + +omit [DecidableEq I] in +lemma translate_pencil (A : I → Matrix D D R) (hsum : ∑i, A i=1) (x : R) : + translate x (pencil A)=basePencil (x • (1 : Matrix D D R)) A := by + let N : Matrix D D (MvPolynomial I R) := fun a b => ∑i, MvPolynomial.X i*MvPolynomial.C (A i a b) + change translate x N.det = _ + rw [(translate x).map_det] + unfold basePencil + apply congrArg Matrix.det + apply Matrix.ext + intro a b + change translate x (∑i, MvPolynomial.X i*MvPolynomial.C (A i a b)) = _ + rw [translate_linear_sum] + + have hab := congrArg (fun M : Matrix D D R => M a b) hsum + simp only [Matrix.sum_apply] at hab + rw [hab] + simp only [Matrix.add_apply,Matrix.map_apply,Matrix.sum_apply,Matrix.smul_apply,smul_eq_mul,map_mul] + exact add_comm _ _ + +lemma mixedChar_eval_diagonal (A : I → Matrix D D R) (hsum : ∑i, A i=1) (x : R) : + (mixedChar A).eval x=MvPolynomial.eval (fun _ => x) (diffProduct Finset.univ.toList (pencil A)) := by + rw [mixedChar_eval,mixedEval,←translate_pencil A hsum x,←translate_diffProduct,eval_zero_translate] + +end StrongThinTree.MSS + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/Truncation.lean b/lean/OAI/Combinatorics/ThinTrees/Truncation.lean new file mode 100644 index 0000000000000000000000000000000000000000..06ed47bb86db99366b9d261e9e431769521ce05e --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/Truncation.lean @@ -0,0 +1,505 @@ +import OAI.Combinatorics.ThinTrees.CompactPacking + +namespace OAI + +universe uE uE2 uE3 uE4 + +section +open scoped Classical +open Matrix + +namespace StrongThinTree.Truncation +noncomputable section +open Finset +open scoped Classical +variable {E : Type uE} [DecidableEq E] + +omit [DecidableEq E] in + +lemma sum_sq_le_card_mul_sum_sq (S : Finset E) (a : E → ℝ) : + (∑e ∈ S, a e)^2 ≤ (S.card : ℝ)*(∑e ∈ S, (a e)^2) := by + simpa using Finset.sum_mul_sq_le_sq_mul_sq S (fun _ => (1:ℝ)) a + +lemma two_truncations (S : Finset E) (a d : E → ℝ) {α : ℝ} + (hα : 0 < α) (_hα1 : α ≤ 1) (hS : S.Nonempty) + (ha : ∀e ∈ S, 0 ≤ a e) (hsq : ∀e ∈ S, (a e)^2 ≤ d e) + (hpos : 0 < ∑e ∈ S, a e) + (hbad : α*(S.card : ℝ)*(∑e ∈ S, d e) ≤ (∑e ∈ S, a e)^2) : + let μ := (∑e ∈ S, a e)/(S.card : ℝ) + ∃R : Finset E, R ⊆ S ∧ + (∑e ∈ S, a e)/2 ≤ ∑e ∈ R, a e ∧ + ∀e ∈ R, μ^2/16 ≤ (a e)^2 ∧ (a e)^2 ≤ d e ∧ d e ≤ 16*μ^2/α^2 := by + let M : ℝ := S.card + let A : ℝ := ∑e ∈ S, a e + let μ := A/M + have hM : 0 < M := by dsimp [M]; exact_mod_cast card_pos.mpr hS + have hA : 0 < A := hpos + have hμ : 0 < μ := div_pos hA hM + have hμM : μ*M = A := div_mul_cancel₀ _ hM.ne' + have hbad' : α*(∑e ∈ S, d e) ≤ M*μ^2 := by + apply (mul_le_mul_iff_right₀ hM).mp + change α*M*(∑e ∈ S, d e) ≤ A^2 at hbad + nlinarith [sq_nonneg (μ*M-A)] + let L := S.filter (fun e => a e < μ/4) + let H := S.filter (fun e => 16*μ^2/α^2 < d e) + let R := S\(L∪H) + have hd : ∀e ∈ S, 0 ≤ d e := fun e he => (sq_nonneg _).trans (hsq e he) + have hLsum : (∑e ∈ L, a e) ≤ A/4 := by + calc + _ ≤ ∑_e ∈ L, μ/4 := sum_le_sum (fun e he => (mem_filter.mp he).2.le) + _ = (L.card : ℝ)*μ/4 := by simp; ring + _ ≤ M*μ/4 := by + have hh : (L.card : ℝ) ≤ M := by + change (L.card : ℝ) ≤ (S.card : ℝ) + exact_mod_cast card_le_card (show L ⊆ S from filter_subset _ _) + nlinarith + _ = A/4 := by rw [mul_comm M,hμM] + have hHmass : (H.card : ℝ)*(16*μ^2/α^2) ≤ ∑e ∈ S, d e := by + calc + _ = ∑_e ∈ H, 16*μ^2/α^2 := by simp + _ ≤ ∑e ∈ H, d e := sum_le_sum (fun e he => (mem_filter.mp he).2.le) + _ ≤ ∑e ∈ S, d e := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun e he _ => hd e he) + have hHcard : (H.card : ℝ) ≤ α*M/16 := by + have hc := mul_le_mul_of_nonneg_left hHmass hα.le + have hμ2 : 0 < μ^2 := sq_pos_of_pos hμ + have heq : α*(H.card : ℝ)*(16*μ^2/α^2) = (H.card : ℝ)*16*μ^2/α := by field_simp + have hh : (H.card : ℝ)*16*μ^2/α ≤ M*μ^2 := by + calc + _ = α*((H.card : ℝ)*(16*μ^2/α^2)) := by rw [←mul_assoc,heq] + _ ≤ α*(∑e ∈ S, d e) := hc + _ ≤ M*μ^2 := hbad' + have hh' := (div_le_iff₀ hα).mp hh + nlinarith + have hHsq : (∑e ∈ H, a e)^2 ≤ (A/4)^2 := by + have hcs := sum_sq_le_card_mul_sum_sq H a + have hs : ∑e ∈ H, (a e)^2 ≤ ∑e ∈ S, d e := + (sum_le_sum (fun e he => hsq e (mem_filter.mp he).1)).trans + (sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun e he _ => hd e he)) + have hD0 : 0 ≤ ∑e ∈ S, d e := sum_nonneg hd + have hh := mul_le_mul_of_nonneg_right hHcard hD0 + have hh' := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg H.card : (0:ℝ) ≤ _) + have hb := mul_le_mul_of_nonneg_left hbad' hM.le + nlinarith [sq_nonneg (μ*M-A)] + have hHsum : (∑e ∈ H, a e) ≤ A/4 := by nlinarith [sum_nonneg (s := H) (fun e he => ha e (mem_filter.mp he).1)] + have hU : L∪H ⊆ S := union_subset (filter_subset _ _) (filter_subset _ _) + have hsum : ∑e ∈ S, a e = (∑e ∈ R, a e)+(∑e ∈ L∪H, a e) := (sum_sdiff hU).symm + have hUH : ∑e ∈ L∪H, a e ≤ (∑e ∈ L, a e)+(∑e ∈ H, a e) := by + have he := sum_union_inter (s₁ := L) (s₂ := H) (f := a) + have hi : 0 ≤ ∑e ∈ L∩H, a e := sum_nonneg (fun e he => ha e (hU (mem_union_left _ (mem_inter.mp he).1))) + linarith + refine ⟨R,sdiff_subset,?_,?_⟩ + · change A/2 ≤ _ + change A = _ at hsum + linarith + · intro e he + obtain ⟨heS,heU⟩ := mem_sdiff.mp he + have hle : μ/4 ≤ a e := le_of_not_gt (fun hh => heU (mem_union_left _ (mem_filter.mpr ⟨heS,hh⟩))) + have hde : d e ≤ 16*μ^2/α^2 := le_of_not_gt (fun hh => heU (mem_union_right _ (mem_filter.mpr ⟨heS,hh⟩))) + exact ⟨by change μ^2/16 ≤ _; nlinarith [ha e heS],hsq e heS,hde⟩ + +end +end StrongThinTree.Truncation + +namespace StrongThinTree.Truncation +noncomputable section +open Finset +open scoped Classical +variable {E : Type uE2} [DecidableEq E] + +def dyadicIndex (L x : ℝ) : ℕ := ⌊Real.logb 2 (x/L)⌋₊ + +lemma dyadic_interval {L x : ℝ} (hL : 0 < L) (hx : L ≤ x) : + (2:ℝ)^(dyadicIndex L x : ℝ)*L ≤ x ∧ + x < 2*((2:ℝ)^(dyadicIndex L x : ℝ)*L) := by + have hratio : 1 ≤ x/L := (le_div_iff₀ hL).mpr (by simpa) + have hp : 0 < x/L := lt_of_lt_of_le zero_lt_one hratio + have hg : 0 ≤ Real.logb 2 (x/L) := Real.logb_nonneg (by norm_num) hratio + constructor + · exact (le_div_iff₀ hL).mp ((Real.le_logb_iff_rpow_le (by norm_num) hp).mp (Nat.floor_le hg)) + · have hh := (Real.logb_lt_iff_lt_rpow (by norm_num) hp).mp (Nat.lt_floor_add_one (Real.logb 2 (x/L))) + rw [Real.rpow_add (by norm_num),Real.rpow_one] at hh + have hh' := (div_lt_iff₀ hL).mp hh + dsimp [dyadicIndex] + nlinarith + +lemma dyadicIndex_lt {L U x : ℝ} {J : ℕ} (hL : 0 < L) (hx : L ≤ x) (hU : x ≤ U) + (hJ : Real.logb 2 (U/L) < J) : dyadicIndex L x < J := by + have hr : 1 ≤ x/L := (le_div_iff₀ hL).mpr (by simpa) + apply (Nat.floor_lt (Real.logb_nonneg (by norm_num) hr)).mpr + exact (Real.logb_le_logb_of_le (by norm_num) (lt_of_lt_of_le zero_lt_one hr) + ((div_le_div_iff_of_pos_right hL).mpr hU)).trans_lt hJ + +lemma same_dyadic_ratio {L x y : ℝ} (hL : 0 < L) (hx : L ≤ x) (hy : L ≤ y) + (heq : dyadicIndex L x = dyadicIndex L y) : x < 2*y := by + have hh := (dyadic_interval hL hx).2 + rw [heq] at hh + exact hh.trans_le (mul_le_mul_of_nonneg_left (dyadic_interval hL hy).1 (by norm_num)) + +omit [DecidableEq E] in + +lemma dyadic_pair (R : Finset E) (a b w : E → ℝ) {L U : ℝ} {J : ℕ} + (hL : 0 < L) (hJ : 0 < J) (hj : Real.logb 2 (U/L) < J) + (ha : ∀e ∈ R, L ≤ a e ∧ a e ≤ U) (hb : ∀e ∈ R, L ≤ b e ∧ b e ≤ U) + (hpos : 0 < ∑e ∈ R, w e) : + ∃B : Finset E, B.Nonempty ∧ B ⊆ R ∧ + (∑e ∈ R, w e)/(J:ℝ)^2 ≤ ∑e ∈ B, w e ∧ + ∀e ∈ B, ∀f ∈ B, a e < 2*a f ∧ b e < 2*b f := by + let f := fun e => (dyadicIndex L (a e),dyadicIndex L (b e)) + let T := (range J)×ˢ(range J) + have hT : T.Nonempty := ⟨(0,0),mem_product.mpr ⟨mem_range.mpr hJ,mem_range.mpr hJ⟩⟩ + have hf : ∀e ∈ R, f e ∈ T := by + intro e he + exact mem_product.mpr ⟨mem_range.mpr (dyadicIndex_lt hL (ha e he).1 (ha e he).2 hj), + mem_range.mpr (dyadicIndex_lt hL (hb e he).1 (hb e he).2 hj)⟩ + have hJ0 : (0:ℝ) < J := by exact_mod_cast hJ + obtain ⟨i,hi,hgain⟩ := exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum (w := w) hf hT + (b := (∑e ∈ R, w e)/(J:ℝ)^2) (by + have hh : (T.card : ℝ) = (J:ℝ)^2 := by simp [T,pow_two] + rw [nsmul_eq_mul,hh,mul_div_cancel₀ _ (ne_of_gt (sq_pos_of_pos hJ0))]) + refine ⟨R.filter (fun e => f e=i),?_,filter_subset _ _,hgain,?_⟩ + · apply card_pos.mp + by_contra hh + have he : (R.filter (fun e => f e=i)) = ∅ := card_eq_zero.mp (by omega) + rw [he,sum_empty] at hgain + exact (not_le_of_gt (div_pos hpos (sq_pos_of_pos hJ0))) hgain + · intro e he g hg + obtain ⟨he,hfe⟩ := mem_filter.mp he + obtain ⟨hg,hfg⟩ := mem_filter.mp hg + have heq := hfe.trans hfg.symm + exact ⟨same_dyadic_ratio hL (ha e he).1 (ha g hg).1 (congrArg Prod.fst heq), + same_dyadic_ratio hL (hb e he).1 (hb g hg).1 (congrArg Prod.snd heq)⟩ + +end +end StrongThinTree.Truncation + +namespace StrongThinTree.Truncation +noncomputable section +open Finset +open scoped Classical +variable {E : Type uE3} [DecidableEq E] + +lemma homogeneous_subset (S : Finset E) (a d : E → ℝ) {α : ℝ} + (hα : 0 < α) (hα1 : α ≤ 1) (hS : S.Nonempty) + (ha : ∀e ∈ S, 0 ≤ a e) (hsq : ∀e ∈ S, (a e)^2 ≤ d e) + (hpos : 0 < ∑e ∈ S, a e) + (hbad : α*(S.card : ℝ)*(∑e ∈ S, d e) ≤ (∑e ∈ S, a e)^2) : + let J := 1+⌈Real.logb 2 (256/α^2)⌉₊ + ∃B : Finset E, B.Nonempty ∧ B ⊆ S ∧ + (∑e ∈ S, a e)^2/(4*(J:ℝ)^4) ≤ (∑e ∈ B, a e)^2 ∧ + (∀e ∈ B, 0 < (a e)^2) ∧ + ∀e ∈ B, ∀f ∈ B, (a e)^2 < 2*(a f)^2 ∧ d e < 2*d f := by + let J := 1+⌈Real.logb 2 (256/α^2)⌉₊ + let A := ∑e ∈ S, a e + let μ := A/(S.card : ℝ) + have hM : (0:ℝ) < S.card := by exact_mod_cast card_pos.mpr hS + have hμ : 0 < μ := div_pos hpos hM + obtain ⟨R,hRS,hRsum,hR⟩ := two_truncations S a d hα hα1 hS ha hsq hpos hbad + have hRpos : 0 < ∑e ∈ R, a e := by linarith + have hJ : 0 < J := by dsimp [J]; omega + have hJr : (0:ℝ) < J := by exact_mod_cast hJ + have hj : Real.logb 2 ((16*μ^2/α^2)/(μ^2/16)) < J := by + have he : (16*μ^2/α^2)/(μ^2/16) = 256/α^2 := by field_simp; ring + rw [he] + have hh := Nat.le_ceil (Real.logb 2 (256/α^2)) + dsimp [J] + push_cast + linarith + obtain ⟨B,hB,hBR,hgain,hratio⟩ := dyadic_pair R (fun e => (a e)^2) d a + (show 0 < μ^2/16 by positivity) hJ hj + (fun e he => ⟨(hR e he).1,(hR e he).2.1.trans (hR e he).2.2⟩) + (fun e he => ⟨(hR e he).1.trans (hR e he).2.1,(hR e he).2.2⟩) hRpos + refine ⟨B,hB,hBR.trans hRS,?_,?_,hratio⟩ + · change A^2/(4*(J:ℝ)^4) ≤ _ + have hbound : A/(2*(J:ℝ)^2) ≤ ∑e ∈ B, a e := by + have hh := div_le_div_of_nonneg_right hRsum (sq_nonneg (J:ℝ)) + have he : (A/2)/(J:ℝ)^2 = A/(2*(J:ℝ)^2) := by ring + change (A/2)/(J:ℝ)^2 ≤ _ at hh + rw [he] at hh + exact hh.trans hgain + have hA : 0 < A := hpos + have hnonneg : 0 ≤ A/(2*(J:ℝ)^2) := by positivity + have hh := pow_le_pow_left₀ hnonneg hbound 2 + have he : (A/(2*(J:ℝ)^2))^2 = A^2/(4*(J:ℝ)^4) := by ring + rw [he] at hh + exact hh + · intro e he + exact lt_of_lt_of_le (by positivity : 0 < μ^2/16) (hR e (hBR he)).1 + +end +end StrongThinTree.Truncation + +namespace StrongThinTree.Truncation +noncomputable section +open Finset +open scoped Classical +variable {E : Type uE4} [DecidableEq E] + +lemma scaled_subset (O : Finset E) (a d : E → ℝ) {α : ℝ} + (hα : 0 < α) (hα1 : α ≤ 1) (hO : O.Nonempty) + (ha : ∀e ∈ O, 0 ≤ a e) (hsq : ∀e ∈ O, (a e)^2 ≤ d e) + (hpos : 0 < ∑e ∈ O, a e) + (hbad : α*(O.card : ℝ)*(∑e ∈ O, d e) ≤ (∑e ∈ O, a e)^2) + {L : ℕ} (hL : Real.logb 2 (16/(α*(1/(4*((1+⌈Real.logb 2 (256/α^2)⌉₊:ℕ):ℝ)^4))))+1 < L) : + let J := 1+⌈Real.logb 2 (256/α^2)⌉₊ + let γ := 1/(4*(J:ℝ)^4) + ∃B : Finset E, ∃idx : ℤ, ∃off : Fin L, + B.Nonempty ∧ B ⊆ O ∧ γ*(∑e ∈ O, a e)^2 ≤ (∑e ∈ B, a e)^2 ∧ + (∀e ∈ B, 2^(idx:ℝ) ≤ (a e)^2) ∧ + (∀e ∈ B, (a e)^2 ≤ 4*2^(idx:ℝ)) ∧ + (∀e ∈ B, 2^((idx:ℝ)+off.val) ≤ d e) ∧ + (∀e ∈ B, d e ≤ 4*2^((idx:ℝ)+off.val)) := by + let J := 1+⌈Real.logb 2 (256/α^2)⌉₊ + let γ := 1/(4*(J:ℝ)^4) + have hJ : (0:ℝ) < J := by dsimp [J]; positivity + have hγ : 0 < γ := by dsimp [γ]; positivity + obtain ⟨B,hBn,hBO,hgain,hapos,hratio⟩ := homogeneous_subset O a d hα hα1 hO ha hsq hpos hbad + obtain ⟨e₀,he₀,hmin₁⟩ := exists_min_image B (fun e => (a e)^2) hBn + obtain ⟨f₀,hf₀,hmin₂⟩ := exists_min_image B d hBn + let c₁ := (a e₀)^2 + let c₂ := d f₀ + have hc₁ : 0 < c₁ := hapos e₀ he₀ + have hc₁₂ : c₁ ≤ c₂ := (hmin₁ f₀ hf₀).trans (hsq f₀ (hBO hf₀)) + have hc₂ : 0 < c₂ := hc₁.trans_le hc₁₂ + have hdom : γ*(∑e ∈ O, a e)^2 ≤ (∑e ∈ B, a e)^2 := by + simpa only [γ,one_div,inv_mul_eq_div] using hgain + have hmax₁ : ∀e ∈ B, (a e)^2 ≤ 4*c₁ := by + intro e he + have hh := (hratio e he e₀ he₀).1.le + dsimp [c₁] + nlinarith only [hh,sq_nonneg (a e₀)] + have hmin₂' : ∀e ∈ B, c₂/4 ≤ d e := by + intro e he + have hh : c₂ ≤ d e := hmin₂ e he + linarith only [hh,hc₂] + have hden := BagDensity.local_density O B a d hBO hBn hα hγ + (fun e he => (sq_nonneg (a e)).trans (hsq e he)) hmax₁ hmin₂' hbad hdom + have hcard : (B.card:ℝ) ≤ O.card := by exact_mod_cast card_le_card hBO + have hOpos : (0:ℝ) < O.card := by exact_mod_cast card_pos.mpr hO + have hscale : c₂ ≤ (16/(α*γ))*c₁ := by + have hm := mul_le_mul_of_nonneg_left hcard (show 0 ≤ 16*c₁ by positivity) + have hh : α*γ*c₂ ≤ 16*c₁ := by + apply (mul_le_mul_iff_right₀ hOpos).mp + nlinarith only [hden,hm] + calc + c₂ ≤ 16*c₁/(α*γ) := (le_div_iff₀ (mul_pos hα hγ)).mpr (by nlinarith only [hh]) + _ = (16/(α*γ))*c₁ := by ring + let i := ⌊Real.logb 2 c₁⌋ + let j := ⌊Real.logb 2 c₂⌋ + have hoff := ScaleSelection.integer_scale_offset hc₁ hc₁₂ hscale hL + let o : Fin L := ⟨(j-i).toNat, by dsimp [i,j] at *; omega⟩ + have hj : ((j:ℤ):ℝ)=(i:ℝ)+(o.val:ℝ) := by + have hh : (o.val:ℤ)=j-i := Int.toNat_of_nonneg hoff.1 + have hh' := congrArg (fun x : ℤ => (x:ℝ)) hh + push_cast at hh' + linarith only [hh'] + have hi := ScaleSelection.integer_dyadic hc₁ + have hj' := ScaleSelection.integer_dyadic hc₂ + refine ⟨B,i,o,hBn,hBO,hdom,?_,?_,?_,?_⟩ + · intro e he + exact hi.1.trans (hmin₁ e he) + · intro e he + have hh := (hratio e he e₀ he₀).1 + have hh' : (a e)^2 < 2*c₁ := hh + have hhi : c₁ < 2*2^(i:ℝ) := hi.2 + nlinarith only [hh',hhi] + · intro e he + rw [←hj] + exact hj'.1.trans (hmin₂ e he) + · intro e he + rw [←hj] + have hh := (hratio e he f₀ hf₀).2 + have hh' : d e < 2*c₂ := hh + have hjj : c₂ < 2*2^(j:ℝ) := hj'.2 + nlinarith only [hh',hjj] +end +end StrongThinTree.Truncation + +namespace StrongThinTree.MultiGraph.Hierarchy +noncomputable section +open Finset StrongThinTree.Geometry StrongThinTree.Geometry.RadialShell +open scoped Classical +variable {n m h : ℕ} {H : Hierarchy n} {G : MultiGraph n m} + {X : Fin n → Fin h → ℝ} + +def truncationBins (α : ℝ) : ℕ := 1+⌈Real.logb 2 (256/α^2)⌉₊ +def truncationGain (α : ℝ) : ℝ := 1/(4*(truncationBins α:ℝ)^4) + +lemma truncationGain_pos (α : ℝ) : 0 < truncationGain α := by + dsimp [truncationGain,truncationBins] + positivity + +lemma diagonal_sq_le (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ l1dist (X u) (X v)) (e : Fin m) : + ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ l1dist (X (G.left e)) (X (G.right e)) := by + have hh := pow_le_pow_left₀ (norm_nonneg _) (PiLp.norm_apply_le (Y (G.left e)-Y (G.right e)) e) 2 + have he : ((Y (G.left e)-Y (G.right e)).ofLp e)^2 ≤ ‖Y (G.left e)-Y (G.right e)‖^2 := by + simpa only [Real.norm_eq_abs,sq_abs] using hh + exact he.trans (hcontract _ _) + +lemma positive_bad_bound {q L R : ℕ} (hq : 0 < q) (hL : 0 < L) (hR : 0 < R) + (hk : G.EdgeConnected q) (hX : ∀v, binary (X v)) + (hconn : H.LocallyConnectedReal G q) + (T : Finset (Finset (Fin n))) (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hT : T ⊆ H.nodes) (hroot : ∀t ∈ T, t ≠ univ) + {α ε ρ : ℝ} (hα : 0 < α) (hα1 : α ≤ 1) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ l1dist (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hpos : ∀t ∈ T, 0 < ∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e) + (hbad : ∀t ∈ T, α*((H.parentBoundary G t).card : ℝ)* + (∑e ∈ H.parentBoundary G t, l1dist (X (G.left e)) (X (G.right e))) ≤ + (∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2) + (hsmall : (α*truncationGain α/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*truncationGain α/32)^(1+2*ε)) + (hratio : ∀t ∈ T, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (H.parentBoundary G t).card) + (hlogL : Real.logb 2 (16/(α*truncationGain α))+1 < L) + (hlogR : Real.logb 2 (24/(ρ*(α*truncationGain α/32)^2)) < R) : + let γ := truncationGain α + let s := α*γ/32 + let N := ∑t ∈ T, (∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((H.parentBoundary G t).card : ℝ) + ((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2)))*(γ*N/(L:ℝ)) ≤ + 2*R*(∑e : Fin m, l1dist (X (G.left e)) (X (G.right e))) := by + let γ := truncationGain α + let s := α*γ/32 + let a : Fin m → ℝ := fun e => (Y (G.left e)-Y (G.right e)).ofLp e + let d : Fin m → ℝ := fun e => l1dist (X (G.left e)) (X (G.right e)) + let O := H.parentBoundary G + have hγ : 0 < γ := truncationGain_pos α + have hs : 0 < s := by dsimp [s]; positivity + have hex : ∀t : Finset (Fin n), ∃B : Finset (Fin m), ∃i : ℤ, ∃o : Fin L, + t ∈ T → B.Nonempty ∧ B ⊆ O t ∧ γ*(∑e ∈ O t, a e)^2 ≤ (∑e ∈ B, a e)^2 ∧ + (∀e ∈ B, 2^(i:ℝ) ≤ (a e)^2) ∧ + (∀e ∈ B, (a e)^2 ≤ 4*2^(i:ℝ)) ∧ + (∀e ∈ B, 2^((i:ℝ)+o.val) ≤ d e) ∧ + (∀e ∈ B, d e ≤ 4*2^((i:ℝ)+o.val)) := by + intro t + by_cases ht : t ∈ T + · have hOn : (O t).Nonempty := by + by_contra hh + have heq : O t=∅ := not_nonempty_iff_eq_empty.mp hh + have hp := hpos t ht + change 0 < ∑e ∈ O t, a e at hp + simp only [heq,sum_empty,lt_self_iff_false] at hp + obtain ⟨B,i,o,hB⟩ := Truncation.scaled_subset (O t) a d hα hα1 hOn + (fun e _ => hpositive e) (fun e _ => diagonal_sq_le Y hcontract e) (hpos t ht) (hbad t ht) hlogL + exact ⟨B,i,o,fun _ => hB⟩ + · exact ⟨∅,0,⟨0,hL⟩,fun hh => (ht hh).elim⟩ + choose F idx off hf using hex + have hh := homogeneous_scale_bound hq hL hR hk hX hconn T F idx off Y hT hroot + (fun t ht => (hf t ht).2.1) (fun t ht => (hf t ht).1) hα hγ he he1 hρ hρsmall + hcontract hpositive (fun t ht => (hf t ht).2.2.2.1) + (fun t ht => (hf t ht).2.2.2.2.1) (fun t ht => (hf t ht).2.2.2.2.2.1) + (fun t ht => (hf t ht).2.2.2.2.2.2) hbad (fun t ht => (hf t ht).2.2.1) + hsmall hassign hratio hlogR + have hsum : γ*(∑t ∈ T, (∑e ∈ O t, a e)^2/((O t).card:ℝ)) ≤ + ∑t ∈ T, (∑e ∈ F t, a e)^2/((O t).card:ℝ) := by + rw [mul_sum] + apply sum_le_sum + intro t ht + rw [←mul_div_assoc] + exact div_le_div_of_nonneg_right (hf t ht).2.2.1 (Nat.cast_nonneg _) + have hgain := div_le_div_of_nonneg_right hsum (Nat.cast_nonneg L : (0:ℝ)≤L) + have hc : 0 ≤ ((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2))) := by positivity + exact (mul_le_mul_of_nonneg_left hgain hc).trans hh +lemma weighted_boundary_sum (M : Finset (Finset (Fin n))) + (hM : M ⊆ H.nodes) (hroot : ∀t ∈ M, t ≠ univ) + (d : Fin m → ℝ) (hd : ∀e, 0 ≤ d e) : + (∑t ∈ M, ∑e ∈ H.parentBoundary G t, d e) ≤ 2*∑e, d e := by + have heq : (∑t ∈ M, ∑e ∈ H.parentBoundary G t, d e) = + ∑e, ((M.filter (fun t => e ∈ H.parentBoundary G t)).card : ℝ)*d e := by + calc + _ = ∑t ∈ M, ∑e : Fin m, if e ∈ H.parentBoundary G t then d e else 0 := by + apply sum_congr rfl + intro t ht + rw [←sum_filter] + simp + _ = ∑e : Fin m, ∑t ∈ M, if e ∈ H.parentBoundary G t then d e else 0 := sum_comm + _ = _ := by + apply sum_congr rfl + intro e he + rw [←sum_filter, sum_const,nsmul_eq_mul] + rw [heq,mul_sum] + apply sum_le_sum + intro e _ + apply mul_le_mul_of_nonneg_right _ (hd e) + exact_mod_cast H.parentBoundary_multiplicity G M hM hroot e + +lemma hierarchy_numerator_bound {q L R : ℕ} (hq : 0 < q) (hL : 0 < L) (hR : 0 < R) + (hk : G.EdgeConnected q) (hX : ∀v, binary (X v)) + (hconn : H.LocallyConnectedReal G q) + (M : Finset (Finset (Fin n))) (Y : Fin n → EuclideanSpace ℝ (Fin m)) + (hM : M ⊆ H.nodes) (hroot : ∀t ∈ M, t ≠ univ) + {α ε ρ : ℝ} (hα : 0 < α) (hα1 : α ≤ 1) (he : 0 < ε) (he1 : ε < 1/3) + (hρ : 0 < ρ) (hρsmall : ρ ≤ 1/1536) + (hcontract : ∀u v, ‖Y u-Y v‖^2 ≤ l1dist (X u) (X v)) + (hpositive : ∀e, 0 ≤ (Y (G.left e)-Y (G.right e)).ofLp e) + (hsmall : (α*truncationGain α/32)^ε ≤ 1/(1728*(1024/ε^2))) + (hassign : (6144:ℝ)/q ≤ (α*truncationGain α/32)^(1+2*ε)) + (hratio : ∀t ∈ M, (q:ℝ)*ρ*((G.cut univ t).card : ℝ) ≤ (H.parentBoundary G t).card) + (hlogL : Real.logb 2 (16/(α*truncationGain α))+1 < L) + (hlogR : Real.logb 2 (24/(ρ*(α*truncationGain α/32)^2)) < R) : + let γ := truncationGain α + let s := α*γ/32 + (∑t ∈ M, (∑e ∈ H.parentBoundary G t, (Y (G.left e)-Y (G.right e)).ofLp e)^2/ + ((H.parentBoundary G t).card : ℝ)) ≤ + (2*α+2*(R:ℝ)*(L:ℝ)/(((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2)))*γ))* + (∑e : Fin m, l1dist (X (G.left e)) (X (G.right e))) := by + let O := H.parentBoundary G + let a : Fin m → ℝ := fun e => (Y (G.left e)-Y (G.right e)).ofLp e + let d : Fin m → ℝ := fun e => l1dist (X (G.left e)) (X (G.right e)) + let N : Finset (Fin n) → ℝ := fun t => (∑e ∈ O t, a e)^2/((O t).card:ℝ) + let T := M.filter (fun t => 0 < ∑e ∈ O t, a e ∧ + α*((O t).card:ℝ)*(∑e ∈ O t, d e) ≤ (∑e ∈ O t, a e)^2) + have hTM : T ⊆ M := filter_subset _ _ + have hgood : ∀t ∈ M\T, N t ≤ α*∑e ∈ O t, d e := by + intro t ht + have htM := (mem_sdiff.mp ht).1 + have htT := (mem_sdiff.mp ht).2 + have hd : 0 ≤ α*∑e ∈ O t, d e := mul_nonneg hα.le (sum_nonneg (fun e _ => l1dist_nonneg _ _)) + by_cases hp : 0 < ∑e ∈ O t, a e + · have hn : ¬α*((O t).card:ℝ)*(∑e ∈ O t, d e) ≤ (∑e ∈ O t, a e)^2 := by + intro hh; exact htT (mem_filter.mpr ⟨htM,hp,hh⟩) + have hc : 0 < ((O t).card:ℝ) := by + by_contra h + have hz : (O t).card=0 := by exact_mod_cast le_antisymm (le_of_not_gt h) (Nat.cast_nonneg _) + have hz' : O t=∅ := card_eq_zero.mp hz + simp [hz'] at hp + apply (div_le_iff₀ hc).mpr + nlinarith only [lt_of_not_ge hn] + · have hz : ∑e ∈ O t, a e=0 := le_antisymm (le_of_not_gt hp) (sum_nonneg (fun e _ => hpositive e)) + simpa [N,hz] using hd + have hg : (∑t ∈ M\T, N t) ≤ 2*α*∑e, d e := by + calc + (∑t ∈ M\T, N t) ≤ ∑t ∈ M\T, α*∑e ∈ O t, d e := sum_le_sum hgood + _ = α*∑t ∈ M\T, ∑e ∈ O t, d e := (mul_sum _ _ _).symm + _ ≤ α*(2*∑e, d e) := mul_le_mul_of_nonneg_left + (weighted_boundary_sum (M\T) (fun _ ht => hM (mem_sdiff.mp ht).1) + (fun t ht => hroot t (mem_sdiff.mp ht).1) d (fun _ => l1dist_nonneg _ _)) hα.le + _ = 2*α*∑e, d e := by ring + have hb := positive_bad_bound hq hL hR hk hX hconn T Y (hTM.trans hM) + (fun t ht => hroot t (hTM ht)) hα hα1 he he1 hρ hρsmall hcontract hpositive + (fun t ht => (mem_filter.mp ht).2.1) (fun t ht => (mem_filter.mp ht).2.2) + hsmall hassign (fun t ht => hratio t (hTM ht)) hlogL hlogR + let γ := truncationGain α + let s := α*γ/32 + let c := ((q:ℝ)/8192)*(s^ε/(6912*(1024/ε^2)))*γ + have hγ : 0 < γ := truncationGain_pos α + have hs : 0 < s := by dsimp [s]; positivity + have hc : 0 < c := by dsimp [c]; positivity + have hL' : 0 < (L:ℝ) := Nat.cast_pos.mpr hL + have hb' : (∑t ∈ T, N t) ≤ (2*(R:ℝ)*(L:ℝ)/c)*(∑e, d e) := by + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ hc).mpr + have hh := (div_le_iff₀ hL').mp (show c*(∑t ∈ T, N t)/L ≤ 2*(R:ℝ)*∑e, d e by + convert hb using 1 ; dsimp [c,N,γ,s,O,a,d] ; ring) + nlinarith only [hh] + change (∑t ∈ M, N t) ≤ (2*α+2*(R:ℝ)*(L:ℝ)/c)*(∑e, d e) + rw [←sum_sdiff hTM] + nlinarith only [hg,hb'] +end +end StrongThinTree.MultiGraph.Hierarchy + +end + +end OAI diff --git a/lean/OAI/Combinatorics/ThinTrees/TwoSystems.lean b/lean/OAI/Combinatorics/ThinTrees/TwoSystems.lean new file mode 100644 index 0000000000000000000000000000000000000000..ff4773baefcd7633d21b8811f5bda515855a5e16 --- /dev/null +++ b/lean/OAI/Combinatorics/ThinTrees/TwoSystems.lean @@ -0,0 +1,94 @@ +import OAI.Combinatorics.ThinTrees.SpectralSplit + +namespace OAI + +universe uI uD uE + +section + +noncomputable section +open Matrix Finset +open scoped MatrixOrder +namespace StrongThinTree +variable {I : Type uI} {D : Type uD} {E : Type uE} [Fintype I] [Fintype D] [Fintype E] + [DecidableEq I] [DecidableEq D] [DecidableEq E] + +omit [Fintype I] [DecidableEq I] [DecidableEq D] [Fintype E] [DecidableEq E] in +lemma qform_covariance (v : I → D → ℝ) (A : Finset I) (x : D → ℝ) : + qform (∑i ∈ A, vecMulVec (v i) (v i)) x=∑i ∈ A, (x ⬝ᵥ v i)^2 := by + simp only [qform,sum_mulVec,dotProduct_sum] + apply sum_congr rfl + intro i _ + rw [vecMulVec_mulVec,dotProduct_smul,dotProduct_comm (v i) x] + simp [pow_two] + +omit [Fintype I] [DecidableEq I] [DecidableEq D] [DecidableEq E] in +lemma dotProduct_sum_elim (a x : D → ℝ) (b y : E → ℝ) : + (Sum.elim a b) ⬝ᵥ (Sum.elim x y)=a ⬝ᵥ x+b ⬝ᵥ y := by + simp [dotProduct,Fintype.sum_sum_type] + +omit [DecidableEq I] in + +theorem split_two_systems (a : I → D → ℝ) (z : I → E → ℝ) {ε : ℝ} + (hε : 0 < ε) + (ha : ∀x : D → ℝ, (∑i, (x ⬝ᵥ a i)^2) ≤ x ⬝ᵥ x) + (hz : ∀y : E → ℝ, (∑i, (y ⬝ᵥ z i)^2) = y ⬝ᵥ y) + (hsize : ∀i, a i ⬝ᵥ a i+z i ⬝ᵥ z i ≤ ε) : + ∃A : Finset I, + (∀x : D → ℝ, (∑i ∈ A, (x ⬝ᵥ a i)^2) ≤ + (1/2:ℝ)*(∑i, (x ⬝ᵥ a i)^2)+(2*Real.sqrt ε+ε)*(x ⬝ᵥ x)) ∧ + (∀y : E → ℝ, (1/2-(2*Real.sqrt ε+ε))*(y ⬝ᵥ y) ≤ + ∑i ∈ A, (y ⬝ᵥ z i)^2) := by + let w : I → D ⊕ E → ℝ := fun i => Sum.elim (a i) (z i) + let C : Matrix (D ⊕ E) (D ⊕ E) ℝ := ∑i, vecMulVec (w i) (w i) + have hC : C.PosSemidef := Matrix.posSemidef_sum _ (fun i _ => by + simpa only [star_trivial] using posSemidef_vecMulVec_self_star (w i)) + have hcov : C ≤ (2:ℝ) • (1 : Matrix (D ⊕ E) (D ⊕ E) ℝ) := by + apply Matrix.le_iff.mpr + apply Matrix.PosSemidef.of_dotProduct_mulVec_nonneg + ((Matrix.PosSemidef.one.smul (by norm_num : (0:ℝ) ≤ 2)).isHermitian.sub hC.isHermitian) + intro v + have hv : v=Sum.elim (fun i => v (.inl i)) (fun j => v (.inr j)) := by ext i; cases i <;> rfl + rw [show star v=v by rfl] + change 0 ≤ qform ((2:ℝ) • (1 : Matrix (D ⊕ E) (D ⊕ E) ℝ)-C) v + rw [qform_sub,qform_smul] + have hc : qform C v=∑i, (v ⬝ᵥ w i)^2 := qform_covariance w univ v + rw [hc] + have hterm := Finset.sum_le_sum (s:=univ) (fun i (_ : i ∈ (univ : Finset I)) => + show (v ⬝ᵥ w i)^2 ≤ 2*((fun j => v (.inl j)) ⬝ᵥ a i)^2+ + 2*((fun j => v (.inr j)) ⬝ᵥ z i)^2 by + rw [hv] + simp only [w,dotProduct_sum_elim,Sum.elim_inl,Sum.elim_inr] + nlinarith [sq_nonneg (((fun j => v (.inl j)) ⬝ᵥ a i)-((fun j => v (.inr j)) ⬝ᵥ z i))]) + rw [sum_add_distrib,←mul_sum,←mul_sum,hz] at hterm + have hh := ha (fun j => v (.inl j)) + have hn : qform (1 : Matrix (D ⊕ E) (D ⊕ E) ℝ) v = + ((fun j => v (.inl j)) ⬝ᵥ (fun j => v (.inl j)))+ + ((fun j => v (.inr j)) ⬝ᵥ (fun j => v (.inr j))) := by + rw [qform,one_mulVec,hv,dotProduct_sum_elim] + rfl + rw [hn] + linarith + have hwsize : ∀i, (vecMulVec (w i) (w i)).trace ≤ ε := by + intro i + simpa only [trace_vecMulVec,w,dotProduct_sum_elim] using hsize i + obtain ⟨A,hlo,hhi⟩ := MSS.two_sided_split w hε hcov hwsize + have heq (x : D → ℝ) (y : E → ℝ) : + qform (1 : Matrix (D ⊕ E) (D ⊕ E) ℝ) (Sum.elim x y)=x ⬝ᵥ x+y ⬝ᵥ y := by + rw [qform,one_mulVec,dotProduct_sum_elim] + refine ⟨A,?_,?_⟩ + · intro x + have hh := qform_mono hhi (Sum.elim x (0:E → ℝ)) + simp only [qform_add,qform_smul,qform_covariance,heq,w,dotProduct_sum_elim,zero_dotProduct,add_zero] at hh + exact hh + · intro y + have hh := qform_mono hlo (Sum.elim (0:D → ℝ) y) + simp only [qform_sub,qform_smul,qform_covariance,heq,w,dotProduct_sum_elim,zero_dotProduct,zero_add,hz] at hh + nlinarith + +end StrongThinTree + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/Alignments.lean b/lean/OAI/Combinatorics/TreeEdit/Alignments.lean new file mode 100644 index 0000000000000000000000000000000000000000..c3b2b6f015a9fbe6a2811c318de3edfafb64b751 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/Alignments.lean @@ -0,0 +1,254 @@ +import OAI.Combinatorics.TreeEdit.EditMetric + +namespace OAI + +namespace TreeEdit + +universe u + +variable {α : Type u} {x y z : List α} + +structure Alignment (x y : List α) (n : ℕ) where + left : Fin n ↪o Fin x.length + right : Fin n ↪o Fin y.length + agree : ∀ i, x.get (left i) = y.get (right i) + +namespace Alignment + +variable {n : ℕ} + +theorem le_lcs (a : Alignment x y n) : n ≤ lcs x y := by + let z := List.ofFn (fun i => x.get (a.left i)) + have hz : z.length = n := List.length_ofFn + have hl : z.Sublist x := by + apply List.sublist_iff_exists_fin_orderEmbedding_get_eq.mpr + refine ⟨(Fin.castOrderIso hz).toOrderEmbedding.comp a.left, ?_⟩ + intro i + simp [z, Fin.cast] + have hr : z.Sublist y := by + apply List.sublist_iff_exists_fin_orderEmbedding_get_eq.mpr + refine ⟨(Fin.castOrderIso hz).toOrderEmbedding.comp a.right, ?_⟩ + intro i + simpa [z, Fin.cast] using a.agree (Fin.cast hz i) + exact hz ▸ length_le_lcs hl hr + +def restrict (a : Alignment x y n) {k : ℕ} (f : Fin k ↪o Fin n) : Alignment x y k where + left := f.comp a.left + right := f.comp a.right + agree i := a.agree (f i) + +end Alignment + +theorem exists_lcs_alignment (x y : List α) : Nonempty (Alignment x y (lcs x y)) := by + obtain ⟨z, hx, hy, hz⟩ := exists_lcs x y + obtain ⟨f, hf⟩ := List.sublist_iff_exists_fin_orderEmbedding_get_eq.mp hx + obtain ⟨g, hg⟩ := List.sublist_iff_exists_fin_orderEmbedding_get_eq.mp hy + refine ⟨⟨(Fin.castOrderIso hz.symm).toOrderEmbedding.comp f, + (Fin.castOrderIso hz.symm).toOrderEmbedding.comp g, ?_⟩⟩ + intro i + exact (hf (Fin.cast hz.symm i)).symm.trans (hg (Fin.cast hz.symm i)) + +theorem strictMono_fin_gap {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) + (i j : Fin n) (hij : i ≤ j) : f i + (j.val - i.val) ≤ f j := by + have aux : ∀ (b d : ℕ) (h : b + d < n), + f ⟨b, by omega⟩ + d ≤ f ⟨b + d, h⟩ := by + intro b d + induction d with + | zero => intro h; simp + | succ d ih => + intro h + have hi := ih (by omega) + have hh : f ⟨b + d, by omega⟩ < f ⟨b + (d + 1), h⟩ := hf (by simp) + omega + have he : i.val + (j.val - i.val) = j.val := Nat.add_sub_of_le hij + simpa only [he] using aux i.val (j.val - i.val) (by omega) + +theorem div_strict_of_equal_residue {n P : ℕ} (hP : 0 < P) + (f : Fin n → ℕ) (hf : StrictMono f) {i j : Fin n} + (hij : i < j) (hmod : i.val % P = j.val % P) : f i / P < f j / P := by + have hid := Nat.mod_add_div i.val P + have hjd := Nat.mod_add_div j.val P + have hq : i.val / P < j.val / P := by + by_contra hn + have hmul := Nat.mul_le_mul_left P (Nat.le_of_not_gt hn) + have : j.val ≤ i.val := by omega + exact (not_le_of_gt hij) this + have hmul := Nat.mul_le_mul_left P (Nat.succ_le_of_lt hq) + have hgap : P ≤ j.val - i.val := by + rw [Nat.mul_succ] at hmul + omega + have hg := strictMono_fin_gap f hf i j (le_of_lt hij) + have h : f i + P ≤ f j := by omega + have hd := Nat.div_le_div_right (c := P) h + rw [Nat.add_div_right _ hP] at hd + omega + +def blockIndex {M P : ℕ} (hP : 0 < P) (i : Fin (M * P)) : Fin M := + ⟨i.val / P, (Nat.div_lt_iff_lt_mul hP).mpr i.isLt⟩ + +theorem equal_label_alignment_bound {M P N : ℕ} (hP : 0 < P) + (x y : Word α M) (f g : Fin N ↪o Fin (M * P)) + (heq : ∀ i, x.val.get (Fin.cast x.property.symm (blockIndex hP (f i))) = + y.val.get (Fin.cast y.property.symm (blockIndex hP (g i)))) : + N ≤ P * lcs x.val y.val := by + classical + let residue : Fin N → Fin P := fun i => ⟨i.val % P, Nat.mod_lt _ hP⟩ + have hclass : ∀ r : Fin P, + (Finset.univ.filter (fun i : Fin N => residue i = r)).card ≤ lcs x.val y.val := by + intro r + let s := Finset.univ.filter (fun i : Fin N => residue i = r) + let e := s.orderEmbOfFin rfl + have hm (i : Fin s.card) : residue (e i) = r := + (Finset.mem_filter.mp (s.orderEmbOfFin_mem rfl i)).2 + have hleft : StrictMono (fun i : Fin s.card => + Fin.cast x.property.symm (blockIndex hP (f (e i)))) := by + intro i j hij + change (f (e i)).val / P < (f (e j)).val / P + apply div_strict_of_equal_residue hP (fun i => (f i).val) + (Fin.val_strictMono.comp f.strictMono) (e.strictMono hij) + exact congrArg Fin.val ((hm i).trans (hm j).symm) + have hright : StrictMono (fun i : Fin s.card => + Fin.cast y.property.symm (blockIndex hP (g (e i)))) := by + intro i j hij + change (g (e i)).val / P < (g (e j)).val / P + apply div_strict_of_equal_residue hP (fun i => (g i).val) + (Fin.val_strictMono.comp g.strictMono) (e.strictMono hij) + exact congrArg Fin.val ((hm i).trans (hm j).symm) + exact Alignment.le_lcs ⟨OrderEmbedding.ofStrictMono _ hleft, + OrderEmbedding.ofStrictMono _ hright, fun i => heq (e i)⟩ + have hpartition : N = ∑ r : Fin P, (Finset.univ.filter + (fun i : Fin N => residue i = r)).card := by + simpa using (Finset.card_eq_sum_card_fiberwise + (s := Finset.univ) (t := Finset.univ) (f := residue) (by simp)) + rw [hpartition] + calc + _ ≤ ∑ _r : Fin P, lcs x.val y.val := Finset.sum_le_sum (fun r _ => hclass r) + _ = P * lcs x.val y.val := by simp + +noncomputable def indexSpan {N L : ℕ} (f : Fin N ↪o Fin L) (s : Finset (Fin N)) : + Finset (Fin L) := + if h : s.Nonempty then Finset.Icc (f (s.min' h)) (f (s.max' h)) else ∅ + +@[simp] theorem indexSpan_empty {N L : ℕ} (f : Fin N ↪o Fin L) : + indexSpan f ∅ = ∅ := by simp [indexSpan] + +theorem mem_indexSpan {N L : ℕ} (f : Fin N ↪o Fin L) {s : Finset (Fin N)} + {i : Fin N} (hi : i ∈ s) : f i ∈ indexSpan f s := by + have hs : s.Nonempty := ⟨i, hi⟩ + simp only [indexSpan, dite_eq_left hs, Finset.mem_Icc] + exact ⟨f.monotone (s.min'_le i hi), f.monotone (s.le_max' i hi)⟩ + +theorem card_le_indexSpan {N L : ℕ} (f : Fin N ↪o Fin L) (s : Finset (Fin N)) : + s.card ≤ (indexSpan f s).card := by + exact Finset.card_le_card_of_injOn f (fun _ hi => mem_indexSpan f hi) f.injective.injOn + +theorem indexSpan_disjoint {N L K : ℕ} (f : Fin N ↪o Fin L) + (key : Fin N → Fin K) (hk : Monotone key) {a b : Fin K} (hab : a ≠ b) : + Disjoint (indexSpan f (Finset.univ.filter (fun i => key i = a))) + (indexSpan f (Finset.univ.filter (fun i => key i = b))) := by + classical + let sa := Finset.univ.filter (fun i => key i = a) + let sb := Finset.univ.filter (fun i => key i = b) + change Disjoint (indexSpan f sa) (indexSpan f sb) + by_cases ha : sa.Nonempty + · by_cases hb : sb.Nonempty + · have hamin : key (sa.min' ha) = a := + (Finset.mem_filter.mp (sa.min'_mem ha)).2 + have hamax : key (sa.max' ha) = a := + (Finset.mem_filter.mp (sa.max'_mem ha)).2 + have hbmin : key (sb.min' hb) = b := + (Finset.mem_filter.mp (sb.min'_mem hb)).2 + have hbmax : key (sb.max' hb) = b := + (Finset.mem_filter.mp (sb.max'_mem hb)).2 + refine Finset.disjoint_left.mpr ?_ + intro p hp hq + simp only [indexSpan, dite_eq_left ha, dite_eq_left hb, Finset.mem_Icc] at hp hq + rcases lt_or_gt_of_ne hab with hab | hba + · have hh : sa.max' ha < sb.min' hb := by + by_contra hn + have := hk (le_of_not_gt hn) + rw [hbmin, hamax] at this + exact (not_le_of_gt hab) this + exact (not_le_of_gt (f.strictMono hh)) (hq.1.trans hp.2) + · have hh : sb.max' hb < sa.min' ha := by + by_contra hn + have := hk (le_of_not_gt hn) + rw [hamin, hbmax] at this + exact (not_le_of_gt hba) this + exact (not_le_of_gt (f.strictMono hh)) (hp.1.trans hq.2) + · simp [indexSpan, hb] + · simp [indexSpan, ha] + +theorem sum_span_card_le {N L K : ℕ} (f : Fin N ↪o Fin L) + (key : Fin N → Fin K) (hk : Monotone key) : + (∑ k : Fin K, (indexSpan f (Finset.univ.filter (fun i => key i = k))).card) ≤ L := by + have hd : ((Finset.univ : Finset (Fin K)) : Set (Fin K)).PairwiseDisjoint + (fun k => indexSpan f (Finset.univ.filter (fun i => key i = k))) := by + intro a _ b _ hab + exact indexSpan_disjoint f key hk hab + rw [← Finset.card_biUnion hd] + simpa using Finset.card_le_univ + (Finset.univ.biUnion (fun k => indexSpan f (Finset.univ.filter (fun i => key i = k)))) + +theorem sum_span_gaps_le {N L K : ℕ} (f : Fin N ↪o Fin L) + (key : Fin N → Fin K) (hk : Monotone key) : + (∑ k : Fin K, ((indexSpan f (Finset.univ.filter (fun i => key i = k))).card - + (Finset.univ.filter (fun i => key i = k)).card)) ≤ L - N := by + rw [Finset.sum_tsub_distrib _ (fun _ _ => card_le_indexSpan f _)] + have he : (∑ k : Fin K, (Finset.univ.filter (fun i => key i = k)).card) = N := by + simpa using (Finset.card_eq_sum_card_fiberwise + (s := Finset.univ) (t := Finset.univ) (f := key) (by simp)).symm + rw [he] + exact Nat.sub_le_sub_right (sum_span_card_le f key hk) N + +def blockPairKey {M P N : ℕ} (hP : 0 < P) (f g : Fin N ↪o Fin (M * P)) + (i : Fin N) : Fin (2 * M) := + ⟨(blockIndex hP (f i)).val + (blockIndex hP (g i)).val, by + have := (blockIndex hP (f i)).isLt + have := (blockIndex hP (g i)).isLt + omega⟩ + +theorem blockPairKey_monotone {M P N : ℕ} (hP : 0 < P) + (f g : Fin N ↪o Fin (M * P)) : Monotone (blockPairKey hP f g) := by + intro i j hij + change (f i).val / P + (g i).val / P ≤ (f j).val / P + (g j).val / P + exact Nat.add_le_add (Nat.div_le_div_right (f.monotone hij)) + (Nat.div_le_div_right (g.monotone hij)) + +theorem blockPairKey_eq_iff {M P N : ℕ} (hP : 0 < P) + (f g : Fin N ↪o Fin (M * P)) (i j : Fin N) : + blockPairKey hP f g i = blockPairKey hP f g j ↔ + blockIndex hP (f i) = blockIndex hP (f j) ∧ + blockIndex hP (g i) = blockIndex hP (g j) := by + constructor + · intro h + have he := congrArg Fin.val h + dsimp [blockPairKey] at he + rcases le_total i j with hij | hji + · have hfl := Nat.div_le_div_right (c := P) (f.monotone hij) + have hgl := Nat.div_le_div_right (c := P) (g.monotone hij) + constructor <;> apply Fin.ext <;> dsimp [blockIndex] at * <;> omega + · have hfl := Nat.div_le_div_right (c := P) (f.monotone hji) + have hgl := Nat.div_le_div_right (c := P) (g.monotone hji) + constructor <;> apply Fin.ext <;> dsimp [blockIndex] at * <;> omega + · rintro ⟨hf, hg⟩ + apply Fin.ext + dsimp [blockPairKey] + rw [hf, hg] + +theorem block_span_gap_budget {M P N : ℕ} (hP : 0 < P) + (f g : Fin N ↪o Fin (M * P)) : + (∑ k : Fin (2 * M), + ((indexSpan f (Finset.univ.filter (fun i => blockPairKey hP f g i = k))).card - + (Finset.univ.filter (fun i => blockPairKey hP f g i = k)).card + + ((indexSpan g (Finset.univ.filter (fun i => blockPairKey hP f g i = k))).card - + (Finset.univ.filter (fun i => blockPairKey hP f g i = k)).card))) ≤ + 2 * (M * P - N) := by + rw [Finset.sum_add_distrib] + have hl := sum_span_gaps_le f _ (blockPairKey_monotone hP f g) + have hr := sum_span_gaps_le g _ (blockPairKey_monotone hP f g) + omega + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/CapInversion.lean b/lean/OAI/Combinatorics/TreeEdit/CapInversion.lean new file mode 100644 index 0000000000000000000000000000000000000000..c2afbf4b18e82432ebfeaa537b440733d841f7b3 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/CapInversion.lean @@ -0,0 +1,134 @@ +import OAI.Combinatorics.TreeEdit.Model + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +lemma sqrt_log_cap {A k d : ℝ} (hA : 1 ≤ A) (hk : 8 * A ≤ k) (hd : 1 < d) + (hcap : Real.log d ≤ A * (k + 1) ^ 2 * Real.log (k + 1)) : + Real.sqrt (Real.log d * Real.log (Real.log d)) ≤ 8 * A * (k * Real.log k) := by + have hk2 : 2 ≤ k := by linarith + have hkp : 0 < k := by linarith + have hAp : 0 < A := by linarith + have hlogk : 0 < Real.log k := Real.log_pos (by linarith) + have hlogd : 0 < Real.log d := Real.log_pos hd + have hlk : Real.log (k + 1) ≤ 2 * Real.log k := by + calc + _ ≤ Real.log (2 * k) := Real.log_le_log (by positivity) (by linarith) + _ = Real.log 2 + Real.log k := Real.log_mul (by norm_num) (by positivity) + _ ≤ _ := by linarith [Real.log_le_log (by norm_num : (0 : ℝ) < 2) hk2] + have hlk0 : 0 ≤ Real.log (k + 1) := Real.log_nonneg (by linarith) + have hL : Real.log d ≤ 8 * A * k ^ 2 * Real.log k := by + calc + _ ≤ A * (k + 1) ^ 2 * Real.log (k + 1) := hcap + _ ≤ A * (2 * k) ^ 2 * (2 * Real.log k) := by gcongr; linarith + _ = _ := by ring + have hll : Real.log (Real.log d) ≤ 4 * Real.log k := by + calc + _ ≤ Real.log (8 * A * k ^ 2 * Real.log k) := Real.log_le_log hlogd hL + _ = Real.log (8 * A) + 2 * Real.log k + Real.log (Real.log k) := by + rw [Real.log_mul (by positivity) (by positivity), + Real.log_mul (by positivity) (by positivity), Real.log_pow] + ring + _ ≤ Real.log k + 2 * Real.log k + Real.log k := by + have ha := Real.log_le_log (by positivity : (0 : ℝ) < 8 * A) hk + have hb := Real.log_le_log hlogk (show Real.log k ≤ k from by linarith [Real.log_le_sub_one_of_pos hkp]) + linarith + _ = _ := by ring + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · have hh : Real.log d * Real.log (Real.log d) ≤ + (8 * A * k ^ 2 * Real.log k) * (4 * Real.log k) := by + exact (mul_le_mul_of_nonneg_left hll hlogd.le).trans + (mul_le_mul_of_nonneg_right hL (by positivity)) + have hAA : 32 * A ≤ (8 * A) ^ 2 := by nlinarith + calc + _ ≤ _ := hh + _ = (32 * A) * (k * Real.log k) ^ 2 := by ring + _ ≤ (8 * A) ^ 2 * (k * Real.log k) ^ 2 := mul_le_mul_of_nonneg_right hAA (sq_nonneg _) + _ = _ := by ring + +lemma near_cap {N : ℕ → ℕ} {k₀ d : ℕ} (hN : ∀ k, k₀ ≤ k → k ≤ N k) + (hd : N k₀ ≤ d) : ∃ k, k₀ ≤ k ∧ N k ≤ d ∧ d < N (k + 1) := by + classical + have hex : ∃ t : ℕ, d < N (k₀ + t) := by + refine ⟨d + 1, ?_⟩ + exact (by omega : d < k₀ + (d + 1)).trans_le (hN _ (by omega)) + let t := Nat.find hex + have ht : d < N (k₀ + t) := Nat.find_spec hex + have ht0 : 0 < t := by + by_contra hn + have he : t = 0 := by omega + simp only [he, add_zero] at ht + omega + refine ⟨k₀ + (t - 1), by omega, ?_, ?_⟩ + · have hh := Nat.find_min hex (show t - 1 < Nat.find hex by dsimp [t] at ht0 ⊢; omega) + exact Nat.le_of_not_gt hh + · convert ht using 1 + congr 1 + omega + +theorem all_caps_of_witnesses {N : ℕ → ℕ} {A : ℝ} (hA : 1 ≤ A) + (h : ∀ᶠ k : ℕ in Filter.atTop, + k ≤ N k ∧ Real.log (N k : ℝ) ≤ A * (k : ℝ) ^ 2 * Real.log k ∧ + ∃ W : Finset (List Bool), 2 ≤ W.card ∧ (∀ w ∈ W, w.length = N k) ∧ + Real.exp ((k : ℝ) * Real.log k / 2) ≤ c1 W) : BinaryLowerBound := by + obtain ⟨k₀, hk₀⟩ := Filter.eventually_atTop.mp h + let K := max k₀ ⌈8 * A⌉₊ + 2 + have hK0 : k₀ ≤ K := by dsimp [K]; omega + have hK2 : 2 ≤ K := by dsimp [K]; omega + have hKA : 8 * A ≤ (K : ℝ) := by + exact (Nat.le_ceil (8 * A)).trans (by exact_mod_cast (show ⌈8 * A⌉₊ ≤ K by dsimp [K]; omega)) + refine ⟨1 / (16 * A), by positivity, N K, ?_⟩ + intro d hd + have hdr : 1 < (d : ℝ) := by + have hKd : K ≤ d := (hk₀ K hK0).1.trans hd + exact_mod_cast (by omega : 1 < d) + obtain ⟨k, hkK, hkd, hdk⟩ := near_cap (k₀ := K) + (fun j hj => (hk₀ j (hK0.trans hj)).1) hd + obtain ⟨hNk, hlogk, W, hW, hlen, hdist⟩ := hk₀ k (hK0.trans hkK) + have hlog : Real.log (d : ℝ) ≤ A * ((k : ℝ) + 1) ^ 2 * Real.log ((k : ℝ) + 1) := by + calc + _ ≤ Real.log (N (k + 1) : ℝ) := Real.log_le_log (by positivity) (by exact_mod_cast hdk.le) + _ ≤ _ := by simpa only [Nat.cast_add, Nat.cast_one] using (hk₀ (k + 1) (by omega)).2.1 + have hb := sqrt_log_cap hA (hKA.trans (by exact_mod_cast hkK)) hdr hlog + have hexp : Real.exp ((1 / (16 * A)) * Real.sqrt (Real.log (d : ℝ) * Real.log (Real.log (d : ℝ)))) ≤ + Real.exp ((k : ℝ) * Real.log k / 2) := by + apply Real.exp_le_exp.mpr + calc + _ ≤ (1 / (16 * A)) * (8 * A * ((k : ℝ) * Real.log k)) := + mul_le_mul_of_nonneg_left hb (by positivity) + _ = _ := by field_simp; ring + exact ⟨N k, hkd, W, hW, hlen, hexp.trans hdist⟩ + +lemma eventually_exponential_lower {b C : ℝ} (hb : 1 ≤ b) (hC : 1 ≤ C) (r : ℕ) : + ∀ᶠ k : ℕ in Filter.atTop, + Real.exp ((k : ℝ) * Real.log k / 2) ≤ ((k : ℝ) / b) ^ k / (C * (k : ℝ) ^ r) := by + have ht : Filter.Tendsto (fun k : ℕ => Real.log (k : ℝ)) Filter.atTop Filter.atTop := + Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop + filter_upwards [ht.eventually_ge_atTop (4 * (Real.log b + Real.log C)), + Filter.eventually_ge_atTop (max 2 (4 * r))] with k hl hk + have hkpos : (0 : ℝ) < k := by exact_mod_cast (by omega : 0 < k) + have hk1 : (1 : ℝ) ≤ k := by exact_mod_cast (by omega : 1 ≤ k) + have hkr : 4 * (r : ℝ) ≤ k := by exact_mod_cast (by omega : 4 * r ≤ k) + have hl0 : 0 ≤ Real.log (k : ℝ) := Real.log_nonneg hk1 + have hbpos : 0 < b := by linarith + have hCpos : 0 < C := by linarith + have hlC : 0 ≤ Real.log C := Real.log_nonneg hC + rw [← Real.exp_log (by positivity : 0 < ((k : ℝ) / b) ^ k / (C * (k : ℝ) ^ r))] + apply Real.exp_le_exp.mpr + rw [Real.log_div (by positivity) (by positivity), Real.log_pow, + Real.log_div (by positivity) (by positivity), Real.log_mul (by positivity) (by positivity), Real.log_pow] + have hh1 := mul_le_mul_of_nonneg_left hl hkpos.le + have hh2 := mul_le_mul_of_nonneg_right hkr hl0 + have hh3 := mul_le_mul_of_nonneg_right hk1 hlC + nlinarith + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/CircleFourier.lean b/lean/OAI/Combinatorics/TreeEdit/CircleFourier.lean new file mode 100644 index 0000000000000000000000000000000000000000..ddfc9812cc03694bfebb37f197f648185dd3dcfa --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/CircleFourier.lean @@ -0,0 +1,304 @@ +import OAI.Combinatorics.TreeEdit.RandomCircle +import OAI.Combinatorics.TreeEdit.FiniteFourier + +namespace OAI + +namespace TreeEdit.TorusFourier +open scoped BigOperators +open Classical + +noncomputable def frequency {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) : ZMod M := + AddChar.zmodAddEquiv.symm χ + +lemma character_apply {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) (a : ZMod M) : + χ a = ZMod.stdAddChar (frequency χ * a) := by + have hh := AddChar.zmodAddEquiv.apply_symm_apply χ + change AddChar.zmodAddEquiv (frequency χ) = χ at hh + calc + χ a = (AddChar.zmodAddEquiv (frequency χ)) a := congrArg (fun η : AddChar (ZMod M) ℂ => η a) hh.symm + _ = _ := rfl + +lemma frequency_eq_zero {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) : + frequency χ = 0 ↔ χ = 0 := by + change AddChar.zmodAddEquiv.symm χ = 0 ↔ χ = 0 + exact (AddChar.zmodAddEquiv (n := M)).symm.map_eq_zero_iff + +lemma frequency_add {M : ℕ} [NeZero M] (χ η : AddChar (ZMod M) ℂ) : + frequency (χ + η) = frequency χ + frequency η := map_add _ _ _ + +noncomputable def centered {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) : ℤ := + (frequency χ).valMinAbs + +lemma centered_cast {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) : + (centered χ : ZMod M) = frequency χ := ZMod.coe_valMinAbs _ + +lemma centered_bound {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) : + |(centered χ : ℝ)| * 2 ≤ M := by + have hh := (frequency χ).valMinAbs_mem_Ioc + rw [← abs_of_pos (by norm_num : (0 : ℝ) < 2), ← abs_mul, abs_le] + constructor + · exact_mod_cast hh.1.le + · exact_mod_cast hh.2 + +lemma centered_eq_zero {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) : + centered χ = 0 ↔ χ = 0 := by + rw [centered, ZMod.valMinAbs_eq_zero, frequency_eq_zero] + +lemma chord_lower {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) : + 4 * |(centered χ : ℝ)| / M ≤ ‖1 - χ 1‖ := by + have hM : (0 : ℝ) < M := by exact_mod_cast NeZero.pos M + have hb := centered_bound χ + rw [character_apply χ 1, mul_one, ← centered_cast χ, ZMod.stdAddChar_coe, + norm_sub_rev] + have he : 2 * (Real.pi : ℂ) * Complex.I * (centered χ : ℂ) / (M : ℂ) = + Complex.I * ((2 * Real.pi * (centered χ : ℝ) / M : ℝ) : ℂ) := by push_cast; ring + rw [he, Complex.norm_exp_I_mul_ofReal_sub_one] + have hh := Real.mul_le_sin (x := Real.pi * |(centered χ : ℝ)| / M) + (by positivity) (by rw [div_le_iff₀ hM]; nlinarith [Real.pi_pos]) + have habs : |Real.sin (2 * Real.pi * (centered χ : ℝ) / M / 2)| = + Real.sin (Real.pi * |(centered χ : ℝ)| / M) := by + rw [show 2 * Real.pi * (centered χ : ℝ) / M / 2 = Real.pi * (centered χ : ℝ) / M by ring] + have hab : |Real.pi * (centered χ : ℝ) / M| = Real.pi * |(centered χ : ℝ)| / M := by + simp only [abs_div, abs_mul, abs_of_pos Real.pi_pos, abs_of_pos hM] + rw [Real.abs_sin_eq_sin_abs_of_abs_le_pi (by rw [hab, div_le_iff₀ hM]; nlinarith [Real.pi_pos]), hab] + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (by norm_num : (0 : ℝ) < 2), habs] + have heq : 2 / Real.pi * (Real.pi * |(centered χ : ℝ)| / M) = 2 * |(centered χ : ℝ)| / M := by + field_simp + rw [heq] at hh + calc + 4 * |(centered χ : ℝ)| / M = 2 * (2 * |(centered χ : ℝ)| / M) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by norm_num) + +lemma sum_chord_detect {M Q J : ℕ} [NeZero M] (hQ : 0 < Q) (hM : M = J * Q) + (χ : AddChar (ZMod M) ℂ) (hχ : (Q : ℝ) ≤ |(centered χ : ℝ)|) : + (J : ℝ) ≤ ∑ a ∈ Finset.range J, (2 - 2 * (χ (a + 1)).re) := by + have hMr : (0 : ℝ) < M := by exact_mod_cast NeZero.pos M + have hJ : 0 < J := by have := NeZero.pos M; nlinarith + have hJr : (0 : ℝ) < J := by exact_mod_cast hJ + have hleft : 4 ≤ (J : ℝ) * ‖1 - χ 1‖ := by + have hh := chord_lower χ + have he : (M : ℝ) = (J : ℝ) * Q := by exact_mod_cast hM + rw [div_le_iff₀ hMr] at hh + have hQr : (0 : ℝ) < Q := by exact_mod_cast hQ + nlinarith + let S : ℂ := ∑ a ∈ Finset.range J, (χ 1) ^ (a + 1) + have hgeom : S * ((χ 1) - 1) = (χ 1) * ((χ 1) ^ J - 1) := by + dsimp [S] + simp only [pow_succ, ← Finset.sum_mul] + rw [mul_right_comm, geom_sum_mul] + ring + have hnorm : ‖S‖ * ‖1 - χ 1‖ ≤ 2 := by + rw [norm_sub_rev, ← norm_mul, hgeom, norm_mul, χ.norm_apply, one_mul] + have hh := norm_sub_le ((χ 1) ^ J) (1 : ℂ) + simpa only [norm_pow, χ.norm_apply, one_pow, norm_one, one_add_one_eq_two] using hh + have hs : 2 * S.re ≤ J := by + have hn := norm_nonneg S + have hc := norm_nonneg (1 - χ 1) + have hr := Complex.re_le_norm S + nlinarith [mul_le_mul_of_nonneg_left hleft hn, mul_le_mul_of_nonneg_right hr hc] + have he (a : ℕ) : χ ((a + 1 : ℕ) : ZMod M) = (χ 1) ^ (a + 1) := by + rw [show ((a + 1 : ℕ) : ZMod M) = (a + 1) • (1 : ZMod M) by simp [nsmul_eq_mul], AddChar.map_nsmul_eq_pow] + have hre : ∑ a ∈ Finset.range J, (χ (a + 1)).re = S.re := by + simp only [Nat.cast_add, Nat.cast_one] at he + simp_rw [he] + simp only [S, Complex.re_sum] + simp only [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_range, nsmul_eq_mul, ← Finset.mul_sum, hre] + linarith + +end TreeEdit.TorusFourier + +namespace TreeEdit.TorusFourier +open scoped BigOperators +open Classical +open TorusTree + +lemma char_sum {A ι : Type*} [AddCommMonoid A] (χ : AddChar A ℂ) (s : Finset ι) (f : ι → A) : + χ (∑ i ∈ s, f i) = ∏ i ∈ s, χ (f i) := by + induction s using Finset.induction_on with + | empty => simp only [Finset.sum_empty, Finset.prod_empty, AddChar.map_zero_eq_one] + | @insert a s ha ih => rw [Finset.sum_insert ha, Finset.prod_insert ha, AddChar.map_add_eq_mul, ih] + +lemma natAbs_real (a : ℤ) : (a.natAbs : ℝ) = |(a : ℝ)| := by + have hh := congrArg (fun z : ℤ => (z : ℝ)) (Int.natCast_natAbs a) + simpa only [Int.cast_natCast, Int.cast_abs] using hh + +lemma character_one {M : ℕ} [NeZero M] (χ : AddChar (ZMod M) ℂ) : χ 1 = 1 ↔ χ = 0 := by + constructor + · intro h + ext x + rw [← ZMod.natCast_zmod_val x, + show (x.val : ZMod M) = x.val • (1 : ZMod M) by simp [nsmul_eq_mul], + AddChar.map_nsmul_eq_pow, h, one_pow] + rfl + · rintro rfl + rfl + +noncomputable def summary {M m : ℕ} [NeZero M] (h : ℕ) (χ : AddChar (State (ZMod M) m h) ℂ) : AddChar (ZMod M) ℂ := + χ.compAddMonoidHom (diagonal (A := ZMod M) (m := m) h) + +lemma summary_add {M m : ℕ} [NeZero M] (h : ℕ) (χ : AddChar (State (ZMod M) m (h+1)) ℂ) : + summary (h+1) χ = ∑ i : Fin m, summary h (χ.compAddMonoidHom (child (A := ZMod M) h i)) := by + ext a + change χ (diagonal (A := ZMod M) (m := m) (h+1) a) = _ + rw [AddChar.sum_apply] + have he : diagonal (A := ZMod M) (m := m) (h+1) a = + ∑ i : Fin m, child (A := ZMod M) h i (diagonal (A := ZMod M) (m := m) h a) := by + change (fun _ : Fin m => diagonal (A := ZMod M) (m := m) h a) = ∑ i, Pi.single i _ + exact (Finset.univ_sum_single _).symm + rw [he, char_sum] + rfl + +lemma centered_summary_add {M m Q : ℕ} [NeZero M] (h : ℕ) + (χ : AddChar (State (ZMod M) m (h+1)) ℂ) (hM : (m+1)*Q < M) + (hp : |(centered (summary (h+1) χ) : ℝ)| < Q) + (hc : ∀ i : Fin m, |(centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i))) : ℝ)| < Q) : + centered (summary (h+1) χ) = ∑ i : Fin m, centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i))) := by + let a := centered (summary (h+1) χ) + let b (i : Fin m) := centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i))) + have he : ((a - ∑ i, b i : ℤ) : ZMod M) = 0 := by + simp only [Int.cast_sub, Int.cast_sum, a, b, centered_cast] + rw [summary_add] + exact sub_eq_zero.mpr (map_sum (AddChar.zmodAddEquiv.symm) _ _) + have hd : (M : ℤ) ∣ a - ∑ i, b i := (ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mp he + have hb : |((∑ i, b i : ℤ) : ℝ)| ≤ (m : ℝ) * Q := by + rw [Int.cast_sum] + calc + _ ≤ ∑ i : Fin m, |(b i : ℝ)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _i : Fin m, (Q : ℝ) := Finset.sum_le_sum fun i _ => (hc i).le + _ = _ := by simp + have hab : |((a - ∑ i, b i : ℤ) : ℝ)| < M := by + rw [Int.cast_sub] + have hh := abs_sub (a : ℝ) ((∑ i, b i : ℤ) : ℝ) + have hMr : ((m : ℝ)+1)*Q < M := by exact_mod_cast hM + dsimp only [a] at hh ⊢ + nlinarith + have hz : a - ∑ i, b i = 0 := Int.eq_zero_of_dvd_of_natAbs_lt_natAbs hd (by + rw [Int.natAbs_natCast] + exact_mod_cast (show ((a - ∑ i, b i : ℤ).natAbs : ℝ) < M by rw [natAbs_real]; exact hab)) + exact sub_eq_zero.mp hz + +lemma outside_coefficient_dvd {I : Type} {g s L : ℕ} (r : I → ℕ) + (hr : ∀ i, 0 < r i) (j : Fin g → I) (σ : Equiv.Perm I) + (z : ZMod L) (i : Fin (g*s)) (v : Fin g) (hvi : v ≠ group i) : + (r (σ (j v)) : ℤ) ∣ (coefficient r j σ z i : ℤ) - 1 := by + have hquot : period r j σ / r (σ (j (group i))) = ∏ a ∈ Finset.univ.erase (group i), r (σ (j a)) := by + unfold period + rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ (group i)), Nat.mul_div_cancel_left _ (hr _)] + have hd : r (σ (j v)) ∣ period r j σ / r (σ (j (group i))) := by + rw [hquot] + exact Finset.dvd_prod_of_mem _ (Finset.mem_erase.mpr ⟨hvi, Finset.mem_univ _⟩) + have hdz : (r (σ (j v)) : ℤ) ∣ ((period r j σ / r (σ (j (group i))) : ℕ) : ℤ) := by exact_mod_cast hd + simpa only [coefficient, Nat.cast_add, Nat.cast_one, Nat.cast_mul, add_sub_cancel_left] using dvd_mul_of_dvd_right hdz (((z.val % r (σ (j (group i)))) : ℕ) : ℤ) + +lemma branch_integer {I : Type} {g s L b e K Q : ℕ} (r : I → ℕ) + (hr : ∀ i, Nat.Prime (r i)) (hinj : Function.Injective r) + (j : Fin g ↪ I) (σ : Equiv.Perm I) (z : Fin (g*s) → ZMod L) + (hb : 1 ≤ b) (hlower : ∀ i, b ≤ r i) (hQ : Q ≤ b^e) (hg : e + K ≤ g) + (a : ℤ) (t : Fin (g*s) → ℤ) (ha : a ≠ 0) (habs : a.natAbs < Q) + (hsum : a = ∑ i, t i) + (hcong : (period r j σ : ℤ) ∣ ∑ i, (coefficient r j σ (z i) i : ℤ) * t i) : + K ≤ (Finset.univ.filter (fun i => t i ≠ 0)).card := by + let S := Finset.univ.filter (fun i => t i ≠ 0) + let O := S.image (group (g := g) (s := s)) + let E := Finset.univ \ O + have hdiv (v : Fin g) (hv : v ∈ E) : (r (σ (j v)) : ℤ) ∣ a := by + have hvo : v ∉ O := (Finset.mem_sdiff.mp hv).2 + have he (i : Fin (g*s)) : (r (σ (j v)) : ℤ) ∣ ((coefficient r j σ (z i) i : ℤ) - 1) * t i := by + by_cases hi : group i = v + · have ht : t i = 0 := by + by_contra hn + exact hvo (Finset.mem_image.mpr ⟨i, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hn⟩, hi⟩) + rw [ht, mul_zero] + exact dvd_zero _ + · exact dvd_mul_of_dvd_left (outside_coefficient_dvd r (fun i => (hr i).pos) j σ (z i) i v (Ne.symm hi)) _ + have hdiff : (r (σ (j v)) : ℤ) ∣ (∑ i, (coefficient r j σ (z i) i : ℤ) * t i) - a := by + rw [hsum, ← Finset.sum_sub_distrib] + simp_rw [sub_mul, one_mul] at he + exact Finset.dvd_sum (fun i _ => he i) + have hdP : (r (σ (j v)) : ℤ) ∣ (period r j σ : ℤ) := by exact_mod_cast group_prime_dvd r j σ v + exact (dvd_sub (hdP.trans hcong) hdiff) |> (by simpa only [sub_sub_cancel] using ·) + have hcount := FiniteTree.few_prime_divisors (fun v : Fin g => r (σ (j v))) + (fun v => hr _) (hinj.comp (σ.injective.comp j.injective)) hb (fun v => hlower _) hQ a ha habs + have he : E.card < e := lt_of_le_of_lt (Finset.card_le_card (by + intro v hv + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, hdiv v hv⟩)) hcount + have ho : O.card ≤ S.card := Finset.card_image_le + have hpartition : E.card + O.card = g := by + have hh := Finset.card_sdiff_add_card_eq_card (show O ⊆ Finset.univ from Finset.subset_univ O) + simpa only [E, Finset.card_univ, Fintype.card_fin] using hh + change K ≤ S.card + omega + +end TreeEdit.TorusFourier + +namespace TreeEdit.TorusFourier +open scoped BigOperators +open Classical TorusTree + +lemma character_state {A : Type} [AddCommGroup A] {m h : ℕ} + (χ : AddChar (State A m (h+1)) ℂ) (x : State A m (h+1)) : + χ x = ∏ i : Fin m, (χ.compAddMonoidHom (child (A := A) h i)) (x i) := by + have he : x = ∑ i : Fin m, child (A := A) h i (x i) := (Finset.univ_sum_single x).symm + conv_lhs => rw [he, char_sum] + rfl + +lemma cycle_congruence {I : Type} {g s L M : ℕ} [NeZero M] (r : I → ℕ) + (j : Fin g → I) (hr : ∀ i, 0 < r i) (h : ℕ) (C : Config I L (g*s) (h+1)) + (hPM : period r j C.1 ∣ M) (χ : AddChar (State (ZMod M) (g*s) (h+1)) ℂ) + (hχ : χ (cycle (M := M) r j h C) = 1) : + (period r j C.1 : ℤ) ∣ ∑ i : Fin (g*s), (coefficient r j C.1 (C.2 i).1 i : ℤ) * + centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i))) := by + let t (i : Fin (g*s)) := centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i))) + let S : ℤ := ∑ i : Fin (g*s), (coefficient r j C.1 (C.2 i).1 i : ℤ) * t i + let P := period r j C.1 + have he : χ (cycle (M := M) r j h C) = ZMod.stdAddChar ((S : ZMod M) * (M/P : ZMod M)) := by + rw [character_state] + change (∏ i : Fin (g*s), summary h (χ.compAddMonoidHom (child (A := ZMod M) h i)) + ((coefficient r j C.1 (C.2 i).1 i) • (M/P : ZMod M))) = _ + dsimp only [S] + rw [Int.cast_sum, Finset.sum_mul, char_sum] + apply Finset.prod_congr rfl + intro i _ + rw [character_apply, nsmul_eq_mul, ← centered_cast] + congr 1 + simp only [Int.cast_mul, Int.cast_natCast, t] + ring + have hzero : (S : ZMod M) * (M/P : ZMod M) = 0 := by + apply ZMod.injective_stdAddChar + rw [← he, hχ, AddChar.map_zero_eq_one] + have hd : (M : ℤ) ∣ S * ((M/P : ℕ) : ℤ) := by + apply (ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mp + simpa only [Int.cast_mul, Int.cast_natCast] using hzero + have hMP : 0 < M/P := Nat.div_pos (Nat.le_of_dvd (NeZero.pos M) hPM) (period_pos hr j C.1) + have hemp : (M : ℤ) = (P : ℤ) * ((M/P : ℕ) : ℤ) := by + exact_mod_cast (Nat.mul_div_cancel' hPM).symm + rw [hemp] at hd + exact (Int.mul_dvd_mul_iff_right (by exact_mod_cast hMP.ne' : ((M/P : ℕ) : ℤ) ≠ 0)).mp hd + +lemma branch_summaries {I : Type} {g s L M b e K Q : ℕ} [NeZero M] (r : I → ℕ) + (hr : ∀ i, Nat.Prime (r i)) (hinj : Function.Injective r) (j : Fin g ↪ I) + (hb : 1 ≤ b) (hlower : ∀ i, b ≤ r i) (hQ : Q ≤ b^e) (hg : e+K ≤ g) + (hM : (g*s+1)*Q < M) (h : ℕ) (C : Config I L (g*s) (h+1)) + (hPM : period r j C.1 ∣ M) (χ : AddChar (State (ZMod M) (g*s) (h+1)) ℂ) + (hp : |(centered (summary (h+1) χ) : ℝ)| < Q) + (hc : ∀ i : Fin (g*s), |(centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i))) : ℝ)| < Q) + (hχ : χ (cycle (M := M) r j h C) = 1) (hn : summary (h+1) χ ≠ 0) : + K ≤ (Finset.univ.filter (fun i : Fin (g*s) => summary h (χ.compAddMonoidHom (child (A := ZMod M) h i)) ≠ 0)).card := by + have hh := branch_integer r hr hinj j C.1 (fun i => (C.2 i).1) hb hlower hQ hg + (centered (summary (h+1) χ)) + (fun i => centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i)))) + ((centered_eq_zero _).not.mpr hn) + (by exact_mod_cast (show ((centered (summary (h+1) χ)).natAbs : ℝ) < Q by rw [natAbs_real]; exact hp)) + (centered_summary_add h χ hM hp hc) + (cycle_congruence r j (fun i => (hr i).pos) h C hPM χ hχ) + have he : (Finset.univ.filter (fun i : Fin (g*s) => centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i))) ≠ 0)) = + (Finset.univ.filter (fun i : Fin (g*s) => summary h (χ.compAddMonoidHom (child (A := ZMod M) h i)) ≠ 0)) := by + apply Finset.filter_congr + intro i _ + exact (centered_eq_zero _).not + rw [he] at hh + exact hh + +end TreeEdit.TorusFourier + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/CircleObstruction.lean b/lean/OAI/Combinatorics/TreeEdit/CircleObstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..3911a2baf62dcfb3112280c83f4936b306522e48 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/CircleObstruction.lean @@ -0,0 +1,244 @@ +import OAI.Combinatorics.TreeEdit.SampledSpectrum +import OAI.Combinatorics.TreeEdit.PrimeSupply + +namespace OAI + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical Filter FiniteProbability + +def branching (k : ℕ) : ℕ := 16 * k * k ^ 2 +def resolution (k : ℕ) : ℕ := k ^ (8 * k) +def cutoff (k : ℕ) : ℕ := k ^ (12 * k) +def repetitions (k : ℕ) : ℕ := k ^ (52 * k) +noncomputable def Pool (k : ℕ) := {p // p ∈ PrimeSupply.band k 2} +noncomputable instance poolFintype (k : ℕ) : Fintype (Pool k) := inferInstanceAs (Fintype {p // p ∈ PrimeSupply.band k 2}) +noncomputable def poolPrime {k : ℕ} (p : Pool k) : ℕ := p.val +noncomputable def residueModulus (k : ℕ) : ℕ := ∏ p : Pool k, poolPrime p + +lemma pool_properties {k : ℕ} (p : Pool k) : Nat.Prime (poolPrime p) ∧ k ^ 2 < poolPrime p ∧ poolPrime p ≤ k ^ 3 := + PrimeSupply.mem_band p.property + +lemma residueModulus_pos (k : ℕ) : 0 < residueModulus k := + product_positive _ (fun p => (pool_properties p).1.pos) + +noncomputable instance residueModulus_neZero (k : ℕ) : NeZero (residueModulus k) := ⟨(residueModulus_pos k).ne'⟩ + +lemma parameter_spacing {k : ℕ} (hk : 2 ≤ k) : + 2 * ((k ^ 3) ^ k) ^ 2 < resolution k := by + have hp : 2 < k ^ (2 * k) := by + calc + 2 < (2 : ℕ) ^ 4 := by norm_num + _ ≤ k ^ 4 := Nat.pow_le_pow_left hk 4 + _ ≤ k ^ (2 * k) := pow_le_pow_right₀ (by omega) (by omega) + have hkpos : 0 < k ^ (6 * k) := pow_pos (by omega) _ + calc + 2 * ((k ^ 3) ^ k) ^ 2 = 2 * k ^ (6 * k) := by + rw [← pow_mul, ← pow_mul] + congr 2 + omega + _ < k ^ (2 * k) * k ^ (6 * k) := Nat.mul_lt_mul_of_pos_right hp hkpos + _ = resolution k := by rw [← pow_add]; congr 1; omega + +lemma probability_error_eventually : ∀ᶠ k : ℕ in atTop, + (16 * k : ℝ) / (k ^ 2 : ℕ) + ((k ^ 3 : ℕ) : ℝ) ^ (16 * k) * (4 / 5 : ℝ) ^ (k * k ^ 2) ≤ 1 / 10 := by + have ht := (tendsto_pow_const_mul_const_pow_of_lt_one 48 (by norm_num : (0 : ℝ) ≤ 4 / 5) (by norm_num : (4 / 5 : ℝ) < 1)).eventually_lt_const (by norm_num : (0 : ℝ) < 1 / 20) + filter_upwards [ht, eventually_ge_atTop 320] with k ht hk + have hkreal : (320 : ℝ) ≤ k := by exact_mod_cast hk + have hka : 1 ≤ k := by omega + have hksq : k ≤ k ^ 2 := by simpa only [pow_one] using pow_le_pow_right₀ hka (show 1 ≤ 2 by omega) + have hb : (k : ℝ) ^ 48 * (4 / 5 : ℝ) ^ (k ^ 2) ≤ 1 / 20 := by + calc + _ ≤ (k : ℝ) ^ 48 * (4 / 5 : ℝ) ^ k := mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one (by norm_num) (by norm_num) hksq) (by positivity) + _ ≤ _ := ht.le + have hpow : ((k ^ 3 : ℕ) : ℝ) ^ (16 * k) * (4 / 5 : ℝ) ^ (k * k ^ 2) ≤ 1 / 20 := by + calc + _ = ((k : ℝ) ^ 48 * (4 / 5 : ℝ) ^ (k ^ 2)) ^ k := by + push_cast + rw [mul_pow, ← pow_mul, ← pow_mul, ← pow_mul] + congr 1 <;> congr 1 <;> ring + _ ≤ (1 / 20 : ℝ) ^ k := pow_le_pow_left₀ (by positivity) hb _ + _ ≤ (1 / 20 : ℝ) ^ 1 := pow_le_pow_of_le_one (by norm_num) (by norm_num) hka + _ = _ := pow_one _ + have hfrac : (16 * k : ℝ) / (k ^ 2 : ℕ) ≤ 1 / 20 := by + push_cast + apply (div_le_iff₀ (by positivity : (0 : ℝ) < (k : ℝ) ^ 2)).mpr + nlinarith + linarith + +lemma torus_parameters_eventually : ∀ᶠ k : ℕ in atTop, + 2 ≤ k ∧ ∃ _ : Fin (16 * k) ↪ Pool k, + (∀ p : Pool k, 10 ≤ poolPrime p) ∧ + (∀ p : Pool k, 2 * (resolution k : ℝ)⁻¹ * poolPrime p < 1) ∧ + 2 * (resolution k : ℝ)⁻¹ * (((k ^ 3) ^ k : ℕ) : ℝ) ^ 2 < 1 ∧ + (16 * k : ℝ) / Fintype.card (Pool k) + ((k ^ 3 : ℕ) : ℝ) ^ (16 * k) * (4 / 5 : ℝ) ^ (k * k ^ 2) ≤ 1 / 10 := by + filter_upwards [PrimeSupply.eventually_band_card 2 (by omega), probability_error_eventually, + eventually_ge_atTop 320] with k hcard herr hk + have hk2 : 2 ≤ k := by omega + have hcard' : k ^ 2 ≤ Fintype.card (Pool k) := by + rw [show Fintype.card (Pool k) = (PrimeSupply.band k 2).card from Fintype.card_coe (PrimeSupply.band k 2)] + exact hcard + have h16 : 16 * k ≤ Fintype.card (Pool k) := by nlinarith + obtain ⟨j⟩ := Function.Embedding.nonempty_of_card_le (show Fintype.card (Fin (16 * k)) ≤ Fintype.card (Pool k) by simpa using h16) + have hR : 0 < resolution k := pow_pos (by omega) _ + have hRr : (0 : ℝ) < resolution k := by exact_mod_cast hR + have hε : 2 * (resolution k : ℝ)⁻¹ * (((k ^ 3) ^ k : ℕ) : ℝ) ^ 2 < 1 := by + have hh : (2 : ℝ) * ((((k ^ 3) ^ k) ^ 2 : ℕ) : ℝ) < resolution k := by exact_mod_cast parameter_spacing hk2 + push_cast at hh ⊢ + field_simp + nlinarith + refine ⟨hk2, j, ?_, ?_, hε, ?_⟩ + · intro p + have hp := (pool_properties p).2.1 + nlinarith + · intro p + have hp := (pool_properties p).2.2 + have hu : k ^ 3 ≤ ((k ^ 3) ^ k) ^ 2 := by + calc + _ = (k ^ 3) ^ 1 := by simp + _ ≤ (k ^ 3) ^ (k * 2) := pow_le_pow_right₀ (one_le_pow₀ (by omega)) (by omega) + _ = _ := pow_mul .. + have hh : (poolPrime p : ℝ) ≤ (((k ^ 3) ^ k : ℕ) : ℝ) ^ 2 := by exact_mod_cast hp.trans hu + exact (mul_le_mul_of_nonneg_left hh (by positivity)).trans_lt hε + · apply le_trans _ herr + gcongr + +lemma good_halfturn_eventually : ∀ᶠ k : ℕ in atTop, 2 ≤ k ∧ + ∃ (j : Fin (16 * k) ↪ Pool k) (C : Config (Pool k) (residueModulus k) (branching k) k), + Good (resolution k : ℝ)⁻¹ poolPrime j k C (point 2) := by + filter_upwards [torus_parameters_eventually] with k hk + obtain ⟨hk2, j, hr10, hgrid, hε, herr⟩ := hk + refine ⟨hk2, j, ?_⟩ + have hhalf : (resolution k : ℝ)⁻¹ ≤ ‖point 2‖ := by + have hR : 2 ≤ resolution k := by + calc + 2 ≤ k := hk2 + _ = k ^ 1 := by simp + _ ≤ resolution k := pow_le_pow_right₀ (by omega) (by omega) + have hn : ‖point 2‖ = (1 / 2 : ℝ) := by + dsimp [point] + simpa using AddCircle.norm_half_period_eq (1 : ℝ) + rw [hn] + simpa only [one_div] using inv_anti₀ (by norm_num : (0 : ℝ) < 2) (by exact_mod_cast hR : (2 : ℝ) ≤ resolution k) + have hh := good_probability (L := residueModulus k) poolPrime (fun p => (pool_properties p).1) Subtype.val_injective + hr10 (show 1 ≤ k ^ 3 from one_le_pow₀ (by omega)) (fun p => (pool_properties p).2.2) + (fun p => Finset.dvd_prod_of_mem _ (Finset.mem_univ p)) j hgrid hε herr k (point 2) hhalf + have hex := probability_exists (lt_of_lt_of_le (by norm_num : (0 : ℝ) < 9 / 10) hh) + exact hex + +end TreeEdit.TorusTree + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical Filter + +noncomputable def allPeriods {k : ℕ} (j : Fin (16*k) ↪ Pool k) : ℕ := + ∏ σ : Equiv.Perm (Pool k), period poolPrime j σ + +lemma allPeriods_pos {k : ℕ} (j : Fin (16*k) ↪ Pool k) : 0 < allPeriods j := + product_positive _ (fun σ => period_pos (fun p => (pool_properties p).1.pos) j σ) + +noncomputable def fineModulus {k : ℕ} (j : Fin (16*k) ↪ Pool k) : ℕ := + resolution k * (2 * cutoff k * ((branching k+1)*cutoff k+1) * allPeriods j) + +lemma fine_parameters {k : ℕ} (hk : 2 ≤ k) (j : Fin (16*k) ↪ Pool k) : + 0 < fineModulus j ∧ 2 ∣ fineModulus j ∧ + (∀ σ : Equiv.Perm (Pool k), period poolPrime j σ ∣ fineModulus j) ∧ + (branching k+1)*cutoff k < fineModulus j ∧ + ∃ D J : ℕ, 0 < D ∧ fineModulus j = resolution k*D ∧ fineModulus j = J*cutoff k := by + have hR : 0 < resolution k := pow_pos (by omega) _ + have hQ : 0 < cutoff k := pow_pos (by omega) _ + have hP := allPeriods_pos j + have hM : 0 < fineModulus j := by unfold fineModulus; positivity + refine ⟨hM, ?_, ?_, ?_, ?_⟩ + · unfold fineModulus + exact dvd_mul_of_dvd_right (dvd_mul_of_dvd_left (dvd_mul_of_dvd_left (dvd_mul_right 2 _) _) _) _ + · intro σ + have hd : period poolPrime j σ ∣ allPeriods j := Finset.dvd_prod_of_mem _ (Finset.mem_univ σ) + exact dvd_mul_of_dvd_right (dvd_mul_of_dvd_right hd _) _ + · have he : fineModulus j = ((branching k+1)*cutoff k+1) * (resolution k*2*cutoff k*allPeriods j) := by unfold fineModulus; ring + rw [he] + have hh : 0 < resolution k*2*cutoff k*allPeriods j := by positivity + exact lt_of_lt_of_le (Nat.lt_succ_self _) (Nat.le_mul_of_pos_right _ hh) + · refine ⟨2*cutoff k*((branching k+1)*cutoff k+1)*allPeriods j, + resolution k*2*((branching k+1)*cutoff k+1)*allPeriods j, by positivity, rfl, ?_⟩ + unfold fineModulus; ring + +lemma period_upper {k : ℕ} (j : Fin (16*k) ↪ Pool k) (σ : Equiv.Perm (Pool k)) : + period poolPrime j σ ≤ k^(48*k) := by + calc + _ ≤ ∏ _i : Fin (16*k), k^3 := Finset.prod_le_prod (fun i _ => (pool_properties (σ (j i))).2.2) + _ = k^(48*k) := by simp only [Finset.prod_const, Finset.card_univ, Fintype.card_fin, ← pow_mul]; congr 1; omega + +lemma spectrum_error {k : ℕ} (hk : 2 ≤ k) : + 4*((k : ℝ)⁻¹^k+k*(2*(resolution k : ℝ)/cutoff k+2*(k^(48*k) : ℕ)/repetitions k)) ≤ + 20*(k : ℝ)⁻¹^k := by + have hkr : (1 : ℝ) ≤ k := by exact_mod_cast (show 1 ≤ k by omega) + have hkpos : (0 : ℝ) < k := by linarith + have hr : (resolution k : ℝ)/cutoff k = (k : ℝ)⁻¹^(4*k) := by + dsimp only [resolution, cutoff] + have he : 12*k = 8*k+4*k := by omega + rw [Nat.cast_pow, Nat.cast_pow, he, pow_add, div_mul_eq_div_div, div_self (pow_ne_zero _ hkpos.ne'), one_div, inv_pow] + have ht : ((k^(48*k) : ℕ) : ℝ)/repetitions k = (k : ℝ)⁻¹^(4*k) := by + dsimp only [repetitions] + have he : 52*k = 48*k+4*k := by omega + rw [Nat.cast_pow, Nat.cast_pow, he, pow_add, div_mul_eq_div_div, div_self (pow_ne_zero _ hkpos.ne'), one_div, inv_pow] + have hi : (k : ℝ)*(k : ℝ)⁻¹^(4*k) ≤ (k : ℝ)⁻¹^k := by + have hpow : (k : ℝ)^(k+1) ≤ (k : ℝ)^(4*k) := pow_le_pow_right₀ hkr (by omega) + have hn : (k : ℝ)^k ≠ 0 := pow_ne_zero _ hkpos.ne' + rw [inv_pow, inv_pow] + apply (mul_le_mul_iff_left₀ (pow_pos hkpos k)).mp + apply (mul_le_mul_iff_left₀ (pow_pos hkpos (4*k))).mp + simpa only [mul_assoc, inv_mul_cancel₀ hn, mul_one, mul_inv_cancel₀ (pow_ne_zero _ hkpos.ne'), pow_succ, mul_left_comm, mul_comm] using hpow + rw [mul_div_assoc, mul_div_assoc, hr, ht] + nlinarith + +theorem concrete_displacement {k : ℕ} (hk : 2 ≤ k) (j : Fin (16*k) ↪ Pool k) + (C : Config (Pool k) (residueModulus k) (branching k) k) + [NeZero (fineModulus j)] [NeZero (resolution k)] + (F : State (ZMod (fineModulus j)) (branching k) k → RealL1) (a : ℝ) (ha : 0 ≤ a) + (hlip : ∀ x y, dist (F x) (F y) ≤ a * ed (sampledWord poolPrime j (repetitions k) (resolution k) k C x).val + (sampledWord poolPrime j (repetitions k) (resolution k) k C y).val) : + FiniteFourier.average (fun x => dist (F x) (F (x + diagonal (A := ZMod (fineModulus j)) (m := branching k) k (fineModulus j/2 : ℕ)))) ≤ + a * FiniteTree.length (branching k) (repetitions k) k * (20*(k : ℝ)⁻¹^k) := by + obtain ⟨_, _, hPM, hM, D, J, hD, hMR, hMQ⟩ := fine_parameters hk j + have hQ : 0 < cutoff k := pow_pos (by omega) _ + have ht : k^(48*k) ≤ repetitions k := pow_le_pow_right₀ (by omega) (by omega) + have hpow : cutoff k ≤ (k^2)^(6*k) := by dsimp only [cutoff]; rw [← pow_mul, show 2*(6*k) = 12*k by omega] + have hh := TorusFourier.displacement_bound poolPrime j (fun i => (pool_properties i).1) Subtype.val_injective + hPM (period_upper j) ht hD hQ hMR hMQ (one_le_pow₀ (by omega : 1 ≤ k) : 1 ≤ k^2) + (fun i => (pool_properties i).2.1.le) hpow (by omega : 6*k+k ≤ 16*k) (by omega : 1 ≤ k) hM C + (fineModulus j/2 : ℕ) F a ha hlip + exact hh.trans (mul_le_mul_of_nonneg_left (spectrum_error hk) (mul_nonneg ha (Nat.cast_nonneg _))) + +lemma sampled_separation {k : ℕ} (hk : 2 ≤ k) (j : Fin (16*k) ↪ Pool k) + (C : Config (Pool k) (residueModulus k) (branching k) k) + [NeZero (fineModulus j)] [NeZero (resolution k)] + (hgood : Good (resolution k : ℝ)⁻¹ poolPrime j k C (point 2)) + (x : State (ZMod (fineModulus j)) (branching k) k) : + FiniteTree.length (branching k) (repetitions k) k ≤ 128^k * deficit + (sampledWord poolPrime j (repetitions k) (resolution k) k C x).val + (sampledWord poolPrime j (repetitions k) (resolution k) k C + (x + diagonal (A := ZMod (fineModulus j)) (m := branching k) k (fineModulus j/2 : ℕ))).val := by + have hm : 4 ≤ branching k := by dsimp [branching]; nlinarith [sq_nonneg (k : ℤ)] + have ht : 0 < repetitions k := pow_pos (by omega) _ + have hh := separation (fun p => (pool_properties p).1.pos) hm ht C (sample (M := fineModulus j) (m := branching k) k x) (point 2) hgood + have hs : sample (M := fineModulus j) (m := branching k) k + (x + diagonal (A := ZMod (fineModulus j)) (m := branching k) k (fineModulus j/2 : ℕ)) = + sample (M := fineModulus j) (m := branching k) k x + diagonal (A := UnitAddCircle) (m := branching k) k (point 2) := by + dsimp only [sample] + rw [map_add, mapState_diagonal, point_grid (M := fineModulus j) (by norm_num : 0 < 2) (fine_parameters hk j).2.1] + have hhNat : FiniteTree.length (branching k) (repetitions k) k ≤ 128^k * deficit + (word poolPrime j (repetitions k) (resolution k) k C (sample (M := fineModulus j) (m := branching k) k x)).val + (word poolPrime j (repetitions k) (resolution k) k C (sample (M := fineModulus j) (m := branching k) k x + diagonal (A := UnitAddCircle) (m := branching k) k (point 2))).val := by + exact_mod_cast hh + have hyw : (sampledWord poolPrime j (repetitions k) (resolution k) k C + (x + diagonal (A := ZMod (fineModulus j)) (m := branching k) k (fineModulus j/2 : ℕ))).val = + (word poolPrime j (repetitions k) (resolution k) k C (sample (M := fineModulus j) (m := branching k) k x + diagonal (A := UnitAddCircle) (m := branching k) k (point 2))).val := + congrArg (fun z : State UnitAddCircle (branching k) k => (word poolPrime j (repetitions k) (resolution k) k C z).val) hs + rw [hyw] + exact hhNat + +end TreeEdit.TorusTree + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/CircleParameters.lean b/lean/OAI/Combinatorics/TreeEdit/CircleParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..eab2dc2ab4ab7e885d116af54643fc708c0be599 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/CircleParameters.lean @@ -0,0 +1,77 @@ +import OAI.Combinatorics.TreeEdit.CircleObstruction + +namespace OAI + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical Filter + +def wordLength (k : ℕ) : ℕ := (branching k * repetitions k)^k +def alphabetSize (k : ℕ) : ℕ := branching k^k * resolution k +def binaryWidth (k : ℕ) : ℕ := 2*Nat.clog 2 (alphabetSize k)+3 +def binaryLength (k : ℕ) : ℕ := wordLength k*binaryWidth k + +lemma wordLength_ge {k : ℕ} (hk : 2 ≤ k) : k ≤ wordLength k := by + have hT : 1 ≤ repetitions k := one_le_pow₀ (by omega) + have hm : k ≤ branching k := by + dsimp [branching] + have hk2 : 1 ≤ k^2 := one_le_pow₀ (by omega) + nlinarith + have hbase : 1 ≤ branching k * repetitions k := (show 1 ≤ branching k by omega).trans (Nat.le_mul_of_pos_right _ hT) + exact (hm.trans (Nat.le_mul_of_pos_right _ hT)).trans (le_self_pow₀ hbase (by omega)) + +lemma binaryLength_ge {k : ℕ} (hk : 2 ≤ k) : k ≤ binaryLength k := + (wordLength_ge hk).trans (Nat.le_mul_of_pos_right _ (by dsimp [binaryWidth]; omega)) + +lemma binaryWidth_le {k : ℕ} (hk : 2 ≤ k) : binaryWidth k ≤ 40*k^2 := by + have hkpow : k ≤ 2^k := (Nat.lt_two_pow_self).le + have hm : branching k ≤ 2^(4+3*k) := by + calc + _ = 16*k^3 := by dsimp [branching]; ring + _ ≤ 2^4*(2^k)^3 := Nat.mul_le_mul (by norm_num) (Nat.pow_le_pow_left hkpow 3) + _ = _ := by rw [← pow_mul, ← pow_add]; congr 1; omega + have hr : resolution k ≤ 2^(8*k^2) := by + calc + _ ≤ (2^k)^(8*k) := Nat.pow_le_pow_left hkpow _ + _ = _ := by rw [← pow_mul]; congr 1; ring + have ha : alphabetSize k ≤ 2^(13*k^2) := by + calc + _ ≤ (2^(4+3*k))^k * 2^(8*k^2) := Nat.mul_le_mul (Nat.pow_le_pow_left hm k) hr + _ = 2^((4+3*k)*k+8*k^2) := by rw [← pow_mul, ← pow_add] + _ ≤ _ := Nat.pow_le_pow_right (by norm_num) (by nlinarith) + have hc := Nat.clog_le_of_le_pow ha + change Nat.clog 2 (alphabetSize k) ≤ 13*k^2 at hc + dsimp only [binaryWidth] + nlinarith + +lemma branching_le_power {k : ℕ} (hk : 2 ≤ k) : branching k ≤ k^7 := by + have h16 : 16 ≤ k^4 := by simpa using Nat.pow_le_pow_left hk 4 + calc + _ = 16*k^3 := by dsimp [branching]; ring + _ ≤ k^4*k^3 := Nat.mul_le_mul_right _ h16 + _ = _ := by rw [← pow_add] + +lemma binaryLength_le_power {k : ℕ} (hk : 2 ≤ k) : binaryLength k ≤ k^(60*k^2) := by + have hm := branching_le_power hk + have hW : binaryWidth k ≤ k^8 := by + have h40 : 40 ≤ k^6 := by have hh := Nat.pow_le_pow_left hk 6; norm_num at hh; omega + exact (binaryWidth_le hk).trans ((Nat.mul_le_mul_right (k^2) h40).trans_eq (by rw [← pow_add])) + have hN : wordLength k ≤ k^((7+52*k)*k) := by + calc + _ ≤ (k^7 * k^(52*k))^k := Nat.pow_le_pow_left (Nat.mul_le_mul_right _ hm) k + _ = _ := by rw [← pow_add, ← pow_mul] + calc + _ ≤ k^((7+52*k)*k)*k^8 := Nat.mul_le_mul hN hW + _ = k^((7+52*k)*k+8) := by rw [← pow_add] + _ ≤ _ := Nat.pow_le_pow_right (by omega) (by nlinarith) + +lemma length_log_bound {k : ℕ} (hk : 2 ≤ k) : + Real.log (binaryLength k : ℝ) ≤ 60*(k : ℝ)^2*Real.log k := by + have hN : 0 < binaryLength k := lt_of_lt_of_le (by omega : 0 < k) (binaryLength_ge hk) + calc + _ ≤ Real.log ((k^(60*k^2) : ℕ) : ℝ) := Real.log_le_log (by exact_mod_cast hN) (by exact_mod_cast binaryLength_le_power hk) + _ = _ := by rw [Nat.cast_pow, Real.log_pow]; push_cast; ring + +end TreeEdit.TorusTree + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/CircleSeparation.lean b/lean/OAI/Combinatorics/TreeEdit/CircleSeparation.lean new file mode 100644 index 0000000000000000000000000000000000000000..42e1f720fa9869b0c86bc8ec7e3ba6992ee5734c --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/CircleSeparation.lean @@ -0,0 +1,181 @@ +import OAI.Combinatorics.TreeEdit.CircleTree + +namespace OAI + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical + +private instance onePositive : Fact (0 < (1 : ℝ)) := ⟨by norm_num⟩ + +noncomputable def representative (t : UnitAddCircle) : ℝ := (AddCircle.equivIco 1 0 t).val + +lemma representative_mem (t : UnitAddCircle) : 0 ≤ representative t ∧ representative t < 1 := by + simpa only [representative, Set.mem_Ico, zero_add] using (AddCircle.equivIco 1 0 t).property + +lemma representative_coe (t : UnitAddCircle) : (representative t : UnitAddCircle) = t := + AddCircle.coe_equivIco + +noncomputable def bin (R : ℕ) [NeZero R] (t : UnitAddCircle) : Fin R := + ⟨⌊(R : ℝ) * representative t⌋₊, (Nat.floor_lt (mul_nonneg (Nat.cast_nonneg R) (representative_mem t).1)).mpr + (by simpa only [mul_one] using mul_lt_mul_of_pos_left (representative_mem t).2 (by exact_mod_cast NeZero.pos R : (0 : ℝ) < R))⟩ + +lemma bin_equal_close {R : ℕ} [NeZero R] {x y : UnitAddCircle} (hxy : bin R x = bin R y) : + ‖y - x‖ < (R : ℝ)⁻¹ := by + have he : ⌊(R : ℝ) * representative x⌋₊ = ⌊(R : ℝ) * representative y⌋₊ := congrArg Fin.val hxy + have hxlo := Nat.floor_le (mul_nonneg (Nat.cast_nonneg R) (representative_mem x).1) + have hylo := Nat.floor_le (mul_nonneg (Nat.cast_nonneg R) (representative_mem y).1) + have hxhi := Nat.lt_floor_add_one ((R : ℝ) * representative x) + have hyhi := Nat.lt_floor_add_one ((R : ℝ) * representative y) + rw [he] at hxlo hxhi + have hr : (0 : ℝ) < R := by exact_mod_cast NeZero.pos R + have ha : |representative y - representative x| < (R : ℝ)⁻¹ := by + apply (mul_lt_mul_iff_right₀ hr).mp + rw [mul_inv_cancel₀ hr.ne', ← abs_of_pos hr, ← abs_mul, abs_lt] + constructor <;> nlinarith + calc + ‖y - x‖ = ‖((representative y - representative x : ℝ) : UnitAddCircle)‖ := by + rw [AddCircle.coe_sub, representative_coe, representative_coe] + _ ≤ |representative y - representative x| := QuotientAddGroup.norm_mk_le_norm + _ < _ := ha + +@[reducible] def State (A : Type) (m : ℕ) : ℕ → Type + | 0 => A + | h + 1 => Fin m → State A m h + +noncomputable instance stateAddCommGroup {A : Type} [AddCommGroup A] (m h : ℕ) : AddCommGroup (State A m h) := by + induction h with + | zero => exact inferInstanceAs (AddCommGroup A) + | succ h ih => exact inferInstanceAs (AddCommGroup (Fin m → State A m h)) + +noncomputable instance stateFintype {A : Type} [Fintype A] (m h : ℕ) : Fintype (State A m h) := by + induction h with + | zero => exact inferInstanceAs (Fintype A) + | succ h ih => exact inferInstanceAs (Fintype (Fin m → State A m h)) + +noncomputable def diagonal {A : Type} [AddCommGroup A] {m : ℕ} : (h : ℕ) → A →+ State A m h + | 0 => AddMonoidHom.id A + | h + 1 => AddMonoidHom.pi (fun _ : Fin m => diagonal h) + +@[reducible] def Symbol (m R : ℕ) : ℕ → Type + | 0 => Fin R + | h + 1 => Σ _i : Fin m, Symbol m R h + +noncomputable instance symbolFintype (m R h : ℕ) : Fintype (Symbol m R h) := by + induction h with + | zero => exact inferInstanceAs (Fintype (Fin R)) + | succ h ih => exact inferInstanceAs (Fintype (Σ _i : Fin m, Symbol m R h)) + +lemma symbol_card (m R h : ℕ) : Fintype.card (Symbol m R h) = m ^ h * R := by + induction h with + | zero => simp [Symbol] + | succ h ih => simp only [Symbol, Fintype.card_sigma, ih, Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul, pow_succ]; ring + +noncomputable def word {I : Type} {g s L : ℕ} (r : I → ℕ) (j : Fin g → I) (T R : ℕ) [NeZero R] : + (h : ℕ) → Config I L (g * s) h → State UnitAddCircle (g * s) h → Word (Symbol (g * s) R h) (FiniteTree.length (g * s) T h) + | 0, _, x => Words.ofFn (fun _ => bin R x) + | h + 1, C, x => Words.cycles fun a i => word r j T R h (C.2 i).2 + (x i + diagonal (A := UnitAddCircle) (m := g * s) h ((a.val * coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1))) + +lemma good_children_int {I : Type} {g s L h : ℕ} {ε : ℝ} {r : I → ℕ} {j : Fin g → I} + (hr : ∀ i, 0 < r i) {C : Config I L (g * s) (h + 1)} {t : UnitAddCircle} + (ht : Good ε r j (h + 1) C t) (a : ℤ) : + g * s ≤ 64 * (Finset.univ.filter (fun i : Fin (g * s) => Good ε r j h (C.2 i).2 + (t + a • ((coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1))))).card := by + let P := period r j C.1 + have hP : 0 < P := period_pos hr j C.1 + let b : Fin P := ⟨(a % (P : ℤ)).toNat, by + have hz := Int.emod_nonneg a (by exact_mod_cast hP.ne' : (P : ℤ) ≠ 0) + have hl := Int.emod_lt_of_pos a (by exact_mod_cast hP : (0 : ℤ) < P) + exact (Int.toNat_lt_of_ne_zero hP.ne').mpr hl⟩ + have he (c : ℕ) : a • (c • point P) = (b.val * c) • point P := by + have hz : P • (c • point P) = 0 := by rw [smul_comm, point_period hP, smul_zero] + have hae : a • (c • point P) = (a % (P : ℤ)) • (c • point P) := by + conv_lhs => rw [← Int.emod_add_mul_ediv a (P : ℤ)] + rw [add_zsmul, mul_comm (P : ℤ), mul_smul, Nat.cast_smul_eq_nsmul ℤ, hz, smul_zero, add_zero] + rw [hae] + have hb : (b.val : ℤ) = a % (P : ℤ) := Int.toNat_of_nonneg (Int.emod_nonneg a (by exact_mod_cast hP.ne')) + rw [← hb, Nat.cast_smul_eq_nsmul ℤ, ← mul_smul] + dsimp [P] at he + simp_rw [he] + exact ht b + +theorem separation {I : Type} {g s L T R h : ℕ} [NeZero R] + {r : I → ℕ} {j : Fin g → I} (hr : ∀ i, 0 < r i) (hm : 4 ≤ g * s) (hT : 0 < T) + (C : Config I L (g * s) h) (x : State UnitAddCircle (g * s) h) (t : UnitAddCircle) + (ht : Good (R : ℝ)⁻¹ r j h C t) : + (FiniteTree.length (g * s) T h : ℝ) ≤ (128 : ℝ) ^ h * + (deficit (word r j T R h C x).val (word r j T R h C (x + diagonal (A := UnitAddCircle) (m := g * s) h t)).val : ℝ) := by + induction h generalizing t with + | zero => + have hne : bin R x ≠ bin R (x + t) := by + intro he + have hh := bin_equal_close he + rw [add_sub_cancel_left] at hh + exact hh.not_ge ht + have hw (z : State UnitAddCircle (g * s) 0) : (word r j T R 0 C z).val = [bin R z] := by + change List.ofFn (fun _ : Fin 1 => bin R z) = _ + simp [List.ofFn_succ] + rw [hw x, hw (x + diagonal (A := UnitAddCircle) (m := g * s) 0 t)] + change _ ≤ _ * (deficit [bin R x] [bin R (x + t)] : ℝ) + rw [deficit_singleton hne] + norm_num [FiniteTree.length] + | succ h ih => + let m := g * s + let B := FiniteTree.length m T h + have hB : 0 < B := by dsimp [B]; rw [FiniteTree.length_eq]; positivity + let X (a : Fin T) (i : Fin m) := word r j T R h (C.2 i).2 + (x i + diagonal (A := UnitAddCircle) (m := g * s) h ((a.val * coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1))) + let Y (a : Fin T) (i : Fin m) := word r j T R h (C.2 i).2 + ((x + diagonal (A := UnitAddCircle) (m := g * s) (h + 1) t) i + diagonal (A := UnitAddCircle) (m := g * s) h ((a.val * coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1))) + let δ : ℝ := (m : ℝ) * B / (64 * (128 : ℝ) ^ h) + have hpow : 0 < (128 : ℝ) ^ h := by positivity + have hpow1 : 1 ≤ (128 : ℝ) ^ h := one_le_pow₀ (by norm_num) + have hδ : δ ≤ ((m - 2) * B : ℕ) := by + have hm2 : (m : ℝ) ≤ 2 * (m - 2 : ℕ) := by exact_mod_cast (show m ≤ 2 * (m - 2) by omega) + dsimp [δ] + rw [div_le_iff₀ (by positivity)] + push_cast + nlinarith [(Nat.cast_nonneg (m - 2) : (0 : ℝ) ≤ (m - 2 : ℕ)), (Nat.cast_nonneg B : (0 : ℝ) ≤ B), + mul_le_mul_of_nonneg_right hm2 (Nat.cast_nonneg B), + mul_nonneg (show (0 : ℝ) ≤ (m - 2 : ℕ) * B by positivity) (show (0 : ℝ) ≤ 128 ^ h - 1 by linarith)] + have hblocks (a b : Fin T) : δ ≤ ∑ i : Fin m, (deficit (X a i).val (Y b i).val : ℝ) := by + let d : ℤ := (b.val : ℤ) - a.val + let good := Finset.univ.filter (fun i : Fin m => Good (R : ℝ)⁻¹ r j h (C.2 i).2 + (t + d • ((coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1)))) + have hg : m ≤ 64 * good.card := good_children_int hr ht d + have hlocal (i : Fin m) (hi : i ∈ good) : + (B : ℝ) ≤ (128 : ℝ) ^ h * (deficit (X a i).val (Y b i).val : ℝ) := by + have hh := ih (C.2 i).2 + (x i + diagonal (A := UnitAddCircle) (m := g * s) h ((a.val * coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1))) + _ (Finset.mem_filter.mp hi).2 + have he : (x + diagonal (A := UnitAddCircle) (m := g * s) (h + 1) t) i + diagonal (A := UnitAddCircle) (m := g * s) h ((b.val * coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1)) = + (x i + diagonal (A := UnitAddCircle) (m := g * s) h ((a.val * coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1))) + + diagonal (A := UnitAddCircle) (m := g * s) h (t + d • ((coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1))) := by + change x i + diagonal (A := UnitAddCircle) (m := g * s) h t + _ = _ + simp only [d, sub_zsmul, Nat.cast_smul_eq_nsmul ℤ, mul_smul, map_add, map_neg, map_nsmul] + abel + simpa only [X, Y, he] using hh + have hsum := Finset.sum_le_sum (s := good) hlocal + simp only [Finset.sum_const, nsmul_eq_mul, ← Finset.mul_sum] at hsum + have hsub : (∑ i ∈ good, (deficit (X a i).val (Y b i).val : ℝ)) ≤ + ∑ i : Fin m, (deficit (X a i).val (Y b i).val : ℝ) := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun _ _ _ => Nat.cast_nonneg _) + have hg' : (m : ℝ) ≤ 64 * good.card := by exact_mod_cast hg + apply (div_le_iff₀ (by positivity : 0 < 64 * (128 : ℝ) ^ h)).mpr + nlinarith [mul_le_mul_of_nonneg_right hg' (Nat.cast_nonneg B), + mul_le_mul_of_nonneg_left hsub hpow.le] + have hh := Words.cycles_deficit (by omega : 2 ≤ m) hB X Y δ hδ hblocks + change (T : ℝ) * δ ≤ 2 * (deficit (word r j T R (h + 1) C x).val + (word r j T R (h + 1) C (x + diagonal (A := UnitAddCircle) (m := g * s) (h + 1) t)).val : ℝ) at hh + have hh' := mul_le_mul_of_nonneg_right hh (by positivity : 0 ≤ 64 * (128 : ℝ) ^ h) + dsimp [δ] at hh' + rw [mul_assoc, div_mul_cancel₀ _ (by positivity : (64 * (128 : ℝ) ^ h) ≠ 0)] at hh' + simp only [FiniteTree.length, Nat.cast_mul, pow_succ] + dsimp [m, B] at hh' + push_cast at hh' + nlinarith only [hh'] + +end TreeEdit.TorusTree + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/CircleTree.lean b/lean/OAI/Combinatorics/TreeEdit/CircleTree.lean new file mode 100644 index 0000000000000000000000000000000000000000..12c31aca3b44d846fbfbfafba1a57a8964659e88 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/CircleTree.lean @@ -0,0 +1,462 @@ +import OAI.Combinatorics.TreeEdit.FiniteProbability +import OAI.Combinatorics.TreeEdit.CyclicWords +import OAI.Combinatorics.TreeEdit.TreeArithmetic + +namespace OAI + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical + +noncomputable def point (n : ℕ) : UnitAddCircle := ↑((n : ℝ)⁻¹) + +lemma point_period {n : ℕ} (hn : 0 < n) : n • point n = 0 := by + simp only [point, ← AddCircle.coe_nsmul, nsmul_eq_mul] + rw [mul_inv_cancel₀ (by exact_mod_cast hn.ne')] + exact AddCircle.coe_period (1 : ℝ) + +lemma point_mul {n d : ℕ} (hn : 0 < n) (hd : 0 < d) (h : d ∣ n) : + (n / d) • point n = point d := by + simp only [point, ← AddCircle.coe_nsmul, nsmul_eq_mul] + congr 1 + rw [Nat.cast_div h (by exact_mod_cast hd.ne')] + field_simp + +lemma nsmul_point_eq (n a : ℕ) : a • point n = ↑((a : ℝ) / n) := by + simp only [point, ← AddCircle.coe_nsmul, nsmul_eq_mul, div_eq_mul_inv] + +lemma point_toAddCircle {n : ℕ} [NeZero n] (a : ZMod n) : + a.val • point n = ZMod.toAddCircle a := by + rw [nsmul_point_eq, ZMod.toAddCircle_apply] + +lemma circle_period_lower {x : UnitAddCircle} {d : ℕ} (hd : 0 < d) + (hx : d • x = 0) (hx0 : x ≠ 0) : 1 ≤ (d : ℝ) * ‖x‖ := by + let : Fact (0 < (1 : ℝ)) := ⟨by norm_num⟩ + have hf : IsOfFinAddOrder x := isOfFinAddOrder_iff_nsmul_eq_zero.mpr ⟨d, hd, hx⟩ + have hh := AddCircle.le_add_order_smul_norm_of_isOfFinAddOrder hf hx0 + simp only [nsmul_eq_mul] at hh + exact hh.trans (mul_le_mul_of_nonneg_right (by exact_mod_cast addOrderOf_le_of_nsmul_eq_zero hd hx) (norm_nonneg _)) + +lemma nearby_unique {t x y : UnitAddCircle} {d e K : ℕ} {ε : ℝ} + (hd : 0 < d) (he : 0 < e) (hdK : d ≤ K) (heK : e ≤ K) + (hx : d • x = 0) (hy : e • y = 0) (hε : 2 * ε * (K : ℝ) ^ 2 < 1) + (htx : ‖t + x‖ < ε) (hty : ‖t + y‖ < ε) : x = y := by + by_contra hn + have hperiod : (d * e) • (x - y) = 0 := by + rw [nsmul_sub] + rw [show d * e = e * d by ring, mul_smul, hx, smul_zero, + show e * d = d * e by ring, mul_smul, hy, smul_zero, sub_self] + have hh := circle_period_lower (Nat.mul_pos hd he) hperiod (sub_ne_zero.mpr hn) + have hnorm : ‖x - y‖ < 2 * ε := by + calc + _ = ‖(t + x) - (t + y)‖ := by congr 1; abel + _ ≤ ‖t + x‖ + ‖t + y‖ := norm_sub_le _ _ + _ < _ := by linarith + have hK : 0 < (K : ℝ) := by exact_mod_cast hd.trans_le hdK + have hde : (d : ℝ) * e ≤ (K : ℝ) ^ 2 := by + have hd' : (d : ℝ) ≤ K := by exact_mod_cast hdK + have he' : (e : ℝ) ≤ K := by exact_mod_cast heK + nlinarith [(Nat.cast_nonneg d : (0 : ℝ) ≤ d), (Nat.cast_nonneg e : (0 : ℝ) ≤ e)] + push_cast at hh + have hh' := mul_le_mul_of_nonneg_right hde (norm_nonneg (x - y)) + have hh'' := mul_lt_mul_of_pos_left hnorm (sq_pos_of_pos hK) + nlinarith + +lemma grid_nearby_unique {r : ℕ} [NeZero r] {t : UnitAddCircle} {ε : ℝ} + (hε : 2 * ε * (r : ℝ) < 1) {a b : ZMod r} + (ha : ‖t + ZMod.toAddCircle a‖ < ε) (hb : ‖t + ZMod.toAddCircle b‖ < ε) : a = b := by + apply ZMod.toAddCircle_injective r + by_contra hn + have hp : r • (ZMod.toAddCircle a - ZMod.toAddCircle b) = 0 := by + rw [← map_sub, ← map_nsmul] + simp [nsmul_eq_mul] + have hh := circle_period_lower (NeZero.pos _) hp (sub_ne_zero.mpr hn) + have hnorm : ‖ZMod.toAddCircle a - ZMod.toAddCircle b‖ < 2 * ε := by + calc + _ = ‖(t + ZMod.toAddCircle a) - (t + ZMod.toAddCircle b)‖ := by congr 1; abel + _ ≤ ‖t + ZMod.toAddCircle a‖ + ‖t + ZMod.toAddCircle b‖ := norm_sub_le _ _ + _ < _ := by linarith + have hr : (0 : ℝ) < r := by exact_mod_cast NeZero.pos r + nlinarith + +lemma product_positive {I : Type*} [Fintype I] (r : I → ℕ) (hr : ∀ i, 0 < r i) : + 0 < ∏ i, r i := Finset.prod_pos (fun i _ => hr i) + +lemma sparse_order {I : Type*} [Fintype I] (r : I → ℕ) + (hr : ∀ i, Nat.Prime (r i)) (hinj : Function.Injective r) + {U k a : ℕ} (hU : 1 ≤ U) (hrU : ∀ i, r i ≤ U) + (hcard : (Finset.univ.filter (fun i => ¬ r i ∣ a)).card ≤ k) : + addOrderOf (a • point (∏ i, r i)) ≤ U ^ k := by + let s := Finset.univ.filter (fun i => ¬ r i ∣ a) + let t := Finset.univ.filter (fun i => r i ∣ a) + let D := ∏ i ∈ s, r i + let P := ∏ i, r i + have hP : 0 < P := product_positive r (fun i => (hr i).pos) + have hD : 0 < D := Finset.prod_pos (fun i _ => (hr i).pos) + have ht : (∏ i ∈ t, r i) ∣ a := by + have hcop : (↑t : Set I).Pairwise (fun i j => IsCoprime (r i : ℤ) (r j : ℤ)) := by + intro i _ j _ hij + exact ((Nat.coprime_primes (hr i) (hr j)).mpr (fun h => hij (hinj h))).isCoprime + have hd : (∏ i ∈ t, (r i : ℤ)) ∣ (a : ℤ) := Finset.prod_dvd_of_coprime hcop + (fun i hi => by exact_mod_cast (Finset.mem_filter.mp hi).2) + exact_mod_cast hd + have he : D * (∏ i ∈ t, r i) = P := by + simpa [D, s, t, P] using Finset.prod_filter_mul_prod_filter_not (s := Finset.univ) (p := fun i => ¬ r i ∣ a) r + have hPD : P ∣ D * a := by + obtain ⟨b, hb⟩ := ht + exact ⟨b, by rw [hb, ← he]; ring⟩ + have hz : D • (a • point P) = 0 := by + rw [← mul_smul] + obtain ⟨b, hb⟩ := hPD + rw [hb, mul_smul, smul_comm, point_period hP, smul_zero] + calc + _ ≤ D := addOrderOf_le_of_nsmul_eq_zero hD hz + _ ≤ U ^ s.card := by + calc + _ ≤ ∏ _i ∈ s, U := Finset.prod_le_prod (fun i _ => hrU i) + _ = _ := Finset.prod_const U + _ ≤ U ^ k := pow_le_pow_right₀ hU hcard + +lemma sparse_bad_prime {t : UnitAddCircle} {ε : ℝ} {U k : ℕ} + (ht : ε ≤ ‖t‖) (hε : 2 * ε * ((U ^ k : ℕ) : ℝ) ^ 2 < 1) : + ∃ p : ℕ, Nat.Prime p ∧ ∀ {I : Type*} [Fintype I] (r : I → ℕ), + (∀ i, Nat.Prime (r i)) → Function.Injective r → 1 ≤ U → (∀ i, r i ≤ U) → + ∀ a : ℕ, (Finset.univ.filter (fun i => ¬ r i ∣ a)).card ≤ k → + ‖t + a • point (∏ i, r i)‖ < ε → ∃ i, r i = p := by + let E (x : UnitAddCircle) := IsOfFinAddOrder x ∧ addOrderOf x ≤ U ^ k ∧ ‖t + x‖ < ε + by_cases hex : ∃ x, E x + · obtain ⟨x, hxfin, hxK, hxnorm⟩ := hex + have hx0 : x ≠ 0 := by intro hz; rw [hz, add_zero] at hxnorm; exact hxnorm.not_ge ht + have ho : addOrderOf x ≠ 1 := by simpa using hx0 + let p := (addOrderOf x).minFac + have hp : Nat.Prime p := Nat.minFac_prime ho + refine ⟨p, hp, ?_⟩ + intro I _ r hr hi hU hrU a hcard hbad + have hP : 0 < ∏ i, r i := product_positive r (fun i => (hr i).pos) + have hyper : (∏ i, r i) • (a • point (∏ i, r i)) = 0 := by + rw [smul_comm, point_period hP, smul_zero] + have hyfin : IsOfFinAddOrder (a • point (∏ i, r i)) := + isOfFinAddOrder_iff_nsmul_eq_zero.mpr ⟨_, hP, hyper⟩ + have hxy : x = a • point (∏ i, r i) := nearby_unique + (addOrderOf_pos_iff.mpr hxfin) (addOrderOf_pos_iff.mpr hyfin) + hxK (sparse_order r hr hi hU hrU hcard) + (addOrderOf_nsmul_eq_zero x) (addOrderOf_nsmul_eq_zero _) hε hxnorm hbad + have hdiv : p ∣ ∏ i, r i := (Nat.minFac_dvd _).trans + (by rw [hxy]; exact addOrderOf_dvd_iff_nsmul_eq_zero.mpr hyper) + obtain ⟨i, _, hpi⟩ := (hp.prime.dvd_finsetProd_iff r).mp hdiv + exact ⟨i, ((hr i).eq_one_or_self_of_dvd p hpi).resolve_left hp.ne_one |>.symm⟩ + · refine ⟨2, Nat.prime_two, ?_⟩ + intro I _ r hr hi hU hrU a hcard hbad + exfalso + apply hex + have hP : 0 < ∏ i, r i := product_positive r (fun i => (hr i).pos) + refine ⟨a • point (∏ i, r i), ?_, sparse_order r hr hi hU hrU hcard, hbad⟩ + exact isOfFinAddOrder_iff_nsmul_eq_zero.mpr ⟨_, hP, by rw [smul_comm, point_period hP, smul_zero]⟩ + +end TreeEdit.TorusTree + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical +open FiniteProbability + +lemma prime_list_event {I : Type*} [Fintype I] (r : I → ℕ) + (hr : ∀ i, Nat.Prime (r i)) (hi : Function.Injective r) + {U k g : ℕ} (hU : 1 ≤ U) (hrU : ∀ i, r i ≤ U) (j : Fin g ↪ I) + {t : UnitAddCircle} {ε : ℝ} (ht : ε ≤ ‖t‖) + (hε : 2 * ε * ((U ^ k : ℕ) : ℝ) ^ 2 < 1) : + probability (fun σ : Equiv.Perm I => ¬ ∀ a : ℕ, + (Finset.univ.filter (fun i => ¬ r (σ (j i)) ∣ a)).card ≤ k → + ε ≤ ‖t + a • point (∏ i : Fin g, r (σ (j i)))‖) ≤ + (g : ℝ) / Fintype.card I := by + obtain ⟨p, _, hp⟩ := sparse_bad_prime ht hε + have himpl (σ : Equiv.Perm I) (hbad : ¬ ∀ a : ℕ, + (Finset.univ.filter (fun i => ¬ r (σ (j i)) ∣ a)).card ≤ k → + ε ≤ ‖t + a • point (∏ i : Fin g, r (σ (j i)))‖) : + ∃ i : Fin g, r (σ (j i)) = p := by + push Not at hbad + obtain ⟨a, ha, hna⟩ := hbad + exact hp (fun i : Fin g => r (σ (j i))) (fun _ => hr _) (hi.comp (σ.injective.comp j.injective)) + hU (fun _ => hrU _) a ha hna + by_cases hex : ∃ v, r v = p + · obtain ⟨v, hv⟩ := hex + calc + _ ≤ probability (fun σ : Equiv.Perm I => ∃ i : Fin g, σ (j i) = v) := probability_mono (by + intro σ hσ + obtain ⟨i, hh⟩ := himpl σ hσ + exact ⟨i, hi (hh.trans hv.symm)⟩) + _ ≤ _ := by simpa using permutation_avoidance j v + · have hz : probability (fun σ : Equiv.Perm I => ¬ ∀ a : ℕ, + (Finset.univ.filter (fun i => ¬ r (σ (j i)) ∣ a)).card ≤ k → + ε ≤ ‖t + a • point (∏ i : Fin g, r (σ (j i)))‖) = 0 := by + apply le_antisymm _ (probability_nonneg _) + calc + _ ≤ probability (fun _ : Equiv.Perm I => False) := probability_mono (by + intro σ hσ + obtain ⟨i, hh⟩ := himpl σ hσ + exact hex ⟨_, hh⟩) + _ = 0 := by simp [probability, mean] + rw [hz] + positivity + +lemma dense_grid_bad {L r a : ℕ} [NeZero L] [NeZero r] (hr : Nat.Prime r) (hrL : r ∣ L) + (ha : ¬ r ∣ a) {t : UnitAddCircle} {ε : ℝ} (hε : 2 * ε * r < 1) : + probability (fun z : ZMod L => + ‖t + ZMod.toAddCircle ((a : ZMod r) * ZMod.castHom hrL (ZMod r) z)‖ < ε) ≤ (r : ℝ)⁻¹ := by + let : Fact (Nat.Prime r) := ⟨hr⟩ + let f : ZMod L →+ ZMod r := (AddMonoidHom.mulLeft (a : ZMod r)).comp + (ZMod.castHom hrL (ZMod r)).toAddMonoidHom + have hf : Function.Surjective f := by + intro b + obtain ⟨z, hz⟩ := ZMod.castHom_surjective hrL ((a : ZMod r)⁻¹ * b) + refine ⟨z, ?_⟩ + change (a : ZMod r) * ZMod.castHom hrL (ZMod r) z = b + rw [hz, ← mul_assoc, mul_inv_cancel₀ ((ZMod.natCast_eq_zero_iff a r).not.mpr ha), one_mul] + calc + _ = probability (fun b : ZMod r => ‖t + ZMod.toAddCircle b‖ < ε) := + probability_comp_uniform f (hom_uniform f hf) _ + _ ≤ (Fintype.card (ZMod r) : ℝ)⁻¹ := probability_subsingleton _ (fun _ _ => grid_nearby_unique hε) + _ = _ := by rw [ZMod.card] + +lemma dense_grid_eligible {L r a : ℕ} [NeZero L] [NeZero r] (hr : Nat.Prime r) (hrL : r ∣ L) + (ha : ¬ r ∣ a) {t : UnitAddCircle} {ε : ℝ} (hε : 2 * ε * r < 1) + (hr10 : 10 ≤ r) : + 9 / 10 ≤ probability (fun z : ZMod L => + ε ≤ ‖t + ZMod.toAddCircle ((a : ZMod r) * ZMod.castHom hrL (ZMod r) z)‖) := by + have hh := dense_grid_bad (t := t) hr hrL ha hε + have hn := probability_not (fun z : ZMod L => + ‖t + ZMod.toAddCircle ((a : ZMod r) * ZMod.castHom hrL (ZMod r) z)‖ < ε) + simp only [not_lt] at hn + rw [hn] + have hi : (r : ℝ)⁻¹ ≤ (10 : ℝ)⁻¹ := inv_anti₀ (by norm_num) (by exact_mod_cast hr10) + norm_num at hi + linarith + +lemma coefficient_circle {P r : ℕ} [NeZero r] (hP : 0 < P) (hr : 0 < r) (hd : r ∣ P) + (a : ℕ) (z : ZMod r) : + (a * (1 + z.val * (P / r))) • point P = + a • point P + ZMod.toAddCircle ((a : ZMod r) * z) := by + rw [Nat.mul_add, Nat.mul_one, add_smul] + congr 1 + rw [mul_smul, mul_smul, point_mul hP hr hd, point_toAddCircle] + rw [← map_nsmul] + congr 1 + simp only [nsmul_eq_mul] + +end TreeEdit.TorusTree + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical +open FiniteProbability + +def group {g s : ℕ} (i : Fin (g * s)) : Fin g := (finProdFinEquiv.symm i).1 + +lemma group_card {g s : ℕ} (S : Finset (Fin g)) : + (Finset.univ.filter (fun i : Fin (g * s) => group i ∈ S)).card = S.card * s := by + rw [Finset.card_filter, ← (finProdFinEquiv (m := g) (n := s)).sum_comp] + simp only [group, Equiv.symm_apply_apply, Fintype.sum_prod_type] + calc + _ = ∑ x : Fin g, s * (if x ∈ S then 1 else 0) := by + apply Finset.sum_congr rfl + intro x _ + by_cases hx : x ∈ S <;> simp [hx] + _ = s * S.card := by rw [← Finset.mul_sum, Finset.sum_boole]; simp + _ = _ := Nat.mul_comm _ _ + +@[reducible] def Config (I : Type) (L m : ℕ) : ℕ → Type _ + | 0 => Unit + | h + 1 => Equiv.Perm I × (Fin m → ZMod L × Config I L m h) + +noncomputable instance configFintype {I : Type} [Fintype I] {L m : ℕ} [NeZero L] (h : ℕ) : + Fintype (Config I L m h) := by + induction h with + | zero => exact inferInstanceAs (Fintype Unit) + | succ h ih => exact inferInstanceAs (Fintype (Equiv.Perm I × (Fin m → ZMod L × Config I L m h))) + +instance configNonempty {I : Type} {L m : ℕ} (h : ℕ) : Nonempty (Config I L m h) := by + induction h with + | zero => exact inferInstanceAs (Nonempty Unit) + | succ h ih => exact inferInstanceAs (Nonempty (Equiv.Perm I × (Fin m → ZMod L × Config I L m h))) + +noncomputable def period {I : Type} {g : ℕ} (r : I → ℕ) (j : Fin g → I) (σ : Equiv.Perm I) : ℕ := + ∏ i, r (σ (j i)) + +noncomputable def coefficient {I : Type} {g s L : ℕ} (r : I → ℕ) (j : Fin g → I) + (σ : Equiv.Perm I) (z : ZMod L) (i : Fin (g * s)) : ℕ := + 1 + (z.val % r (σ (j (group i)))) * (period r j σ / r (σ (j (group i)))) + +noncomputable def Good {I : Type} {g s L : ℕ} (ε : ℝ) (r : I → ℕ) (j : Fin g → I) : + (h : ℕ) → Config I L (g * s) h → UnitAddCircle → Prop + | 0, _, t => ε ≤ ‖t‖ + | h + 1, C, t => ∀ a : Fin (period r j C.1), g * s ≤ 64 * + (Finset.univ.filter (fun i : Fin (g * s) => + Good ε r j h (C.2 i).2 (t + (a.val * coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1)))).card + +lemma period_pos {I : Type} {g : ℕ} {r : I → ℕ} (hr : ∀ i, 0 < r i) + (j : Fin g → I) (σ : Equiv.Perm I) : 0 < period r j σ := product_positive _ (fun _ => hr _) + +lemma group_prime_dvd {I : Type} {g : ℕ} (r : I → ℕ) (j : Fin g → I) + (σ : Equiv.Perm I) (v : Fin g) : r (σ (j v)) ∣ period r j σ := + Finset.dvd_prod_of_mem _ (Finset.mem_univ v) + +lemma cast_hom_val {L r : ℕ} [NeZero L] (hrL : r ∣ L) (z : ZMod L) : + ZMod.castHom hrL (ZMod r) z = (z.val : ZMod r) := by + conv_lhs => rw [← ZMod.natCast_zmod_val z] + simp only [map_natCast] + +lemma coefficient_shift {I : Type} [Fintype I] {g s : ℕ} (r : I → ℕ) + (hr : ∀ i, 0 < r i) (j : Fin g → I) (σ : Equiv.Perm I) + {L : ℕ} [NeZero L] (hL : ∀ i, r i ∣ L) (i : Fin (g * s)) + [NeZero (r (σ (j (group i))))] (a : ℕ) (z : ZMod L) : + (a * coefficient r j σ z i) • point (period r j σ) = + a • point (period r j σ) + + ZMod.toAddCircle ((a : ZMod (r (σ (j (group i))))) * + ZMod.castHom (hL _) (ZMod (r (σ (j (group i))))) z) := by + have hv : (ZMod.castHom (hL _) (ZMod (r (σ (j (group i))))) z).val = + z.val % r (σ (j (group i))) := by rw [cast_hom_val, ZMod.val_natCast] + change (a * (1 + _ * _)) • _ = _ + rw [← hv] + exact coefficient_circle (period_pos hr j σ) (hr _) (group_prime_dvd r j σ _) a _ + +end TreeEdit.TorusTree + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical +open FiniteProbability + +lemma fixed_residue_failure {I : Type} [Fintype I] {k s L h : ℕ} [NeZero L] + (r : I → ℕ) (hr : ∀ i, Nat.Prime (r i)) (hr10 : ∀ i, 10 ≤ r i) + (hL : ∀ i, r i ∣ L) (j : Fin (16 * k) ↪ I) + {ε : ℝ} (hgrid : ∀ i, 2 * ε * r i < 1) + (ih : ∀ t : UnitAddCircle, ε ≤ ‖t‖ → 9 / 10 ≤ + probability (fun C : Config I L (16 * k * s) h => Good ε r j h C t)) + (σ : Equiv.Perm I) (t : UnitAddCircle) + (hlist : ∀ a : ℕ, (Finset.univ.filter (fun v : Fin (16 * k) => ¬ r (σ (j v)) ∣ a)).card ≤ k → + ε ≤ ‖t + a • point (period r j σ)‖) (a : Fin (period r j σ)) : + probability (fun C : Fin (16 * k * s) → ZMod L × Config I L (16 * k * s) h => + ¬ 16 * k * s ≤ 64 * (Finset.univ.filter (fun i => + Good ε r j h (C i).2 (t + (a.val * coefficient r j σ (C i).1 i) • point (period r j σ)))).card) ≤ + (4 / 5 : ℝ) ^ (k * s) := by + let S := Finset.univ.filter (fun v : Fin (16 * k) => ¬ r (σ (j v)) ∣ a.val) + let V := if S.card ≤ k then Sᶜ else S + let J := Finset.univ.filter (fun i : Fin (16 * k * s) => group i ∈ V) + let E (i : Fin (16 * k * s)) (C : ZMod L × Config I L (16 * k * s) h) : Prop := + Good ε r j h C.2 (t + (a.val * coefficient r j σ C.1 i) • point (period r j σ)) + have hn : k * s ≤ J.card := by + have hv : k ≤ V.card := by + dsimp [V] + split_ifs with hs + · rw [Finset.card_compl, Fintype.card_fin] + omega + · omega + have hc := group_card (s := s) V + exact (Nat.mul_le_mul_right s hv).trans_eq hc.symm + have hE (i : Fin (16 * k * s)) (hi : i ∈ J) : 4 / 5 ≤ probability (E i) := by + let p := r (σ (j (group i))) + have hp : Nat.Prime p := hr _ + let : NeZero p := ⟨hp.ne_zero⟩ + have hg : group i ∈ V := (Finset.mem_filter.mp hi).2 + let sh (z : ZMod L) : UnitAddCircle := t + (a.val * coefficient r j σ z i) • point (period r j σ) + have hsh (z : ZMod L) : sh z = t + a.val • point (period r j σ) + + ZMod.toAddCircle ((a.val : ZMod p) * ZMod.castHom (hL _) (ZMod p) z) := by + dsimp [sh] + rw [coefficient_shift r (fun v => (hr v).pos) j σ hL i, ← add_assoc] + simp only [ZMod.castHom_apply] + have helig : 9 / 10 ≤ probability (fun z : ZMod L => ε ≤ ‖sh z‖) := by + by_cases hs : S.card ≤ k + · have hd : p ∣ a.val := by + have hnot : group i ∉ S := Finset.mem_compl.mp (by simpa [V, hs] using hg) + simpa [S, p] using hnot + have he : ∀ z : ZMod L, ε ≤ ‖sh z‖ := by + intro z + rw [hsh, (ZMod.natCast_eq_zero_iff a.val p).mpr hd, zero_mul, map_zero, add_zero] + exact hlist a.val hs + have hh : probability (fun z : ZMod L => ε ≤ ‖sh z‖) = 1 := by simp [probability, he, mean_const] + rw [hh] + norm_num + · have hd : ¬ p ∣ a.val := by + have hin : group i ∈ S := by simpa [V, hs] using hg + exact (Finset.mem_filter.mp hin).2 + have hh := dense_grid_eligible (t := t + a.val • point (period r j σ)) + hp (hL _) hd (hgrid _) (hr10 _) + simpa only [hsh] using hh + have hh := pair_success_lower (fun z : ZMod L => ε ≤ ‖sh z‖) + (fun z (C : Config I L (16 * k * s) h) => Good ε r j h C (sh z)) + (p := (9 : ℝ) / 10) (fun z hz => ih (sh z) hz) + change 9 / 10 * probability (fun z : ZMod L => ε ≤ ‖sh z‖) ≤ probability (E i) at hh + nlinarith + have hh := independent_lower_tail_subset E J hn hE + calc + _ ≤ probability (fun C : Fin (16 * k * s) → ZMod L × Config I L (16 * k * s) h => + 4 * (Finset.univ.filter (fun i => E i (C i))).card < k * s) := probability_mono (by + intro C hC + change ¬ 16 * k * s ≤ 64 * (Finset.univ.filter (fun i => E i (C i))).card at hC + have hh : 16 * k * s = 16 * (k * s) := by ring + omega) + _ ≤ _ := by + convert hh using 1 + congr 1 + exact Subsingleton.elim _ _ + +lemma conditional_good_failure {I : Type} [Fintype I] {k s L U h : ℕ} [NeZero L] + (r : I → ℕ) (hr : ∀ i, Nat.Prime (r i)) (hr10 : ∀ i, 10 ≤ r i) + (hrU : ∀ i, r i ≤ U) (hL : ∀ i, r i ∣ L) (j : Fin (16 * k) ↪ I) + {ε : ℝ} (hgrid : ∀ i, 2 * ε * r i < 1) + (ih : ∀ t : UnitAddCircle, ε ≤ ‖t‖ → 9 / 10 ≤ + probability (fun C : Config I L (16 * k * s) h => Good ε r j h C t)) + (σ : Equiv.Perm I) (t : UnitAddCircle) + (hlist : ∀ a : ℕ, (Finset.univ.filter (fun v : Fin (16 * k) => ¬ r (σ (j v)) ∣ a)).card ≤ k → + ε ≤ ‖t + a • point (period r j σ)‖) : + probability (fun C : Fin (16 * k * s) → ZMod L × Config I L (16 * k * s) h => + ¬ Good ε r j (h + 1) (σ, C) t) ≤ (U : ℝ) ^ (16 * k) * (4 / 5 : ℝ) ^ (k * s) := by + let E (a : Fin (period r j σ)) (C : Fin (16 * k * s) → ZMod L × Config I L (16 * k * s) h) := + ¬ 16 * k * s ≤ 64 * (Finset.univ.filter (fun i => + Good ε r j h (C i).2 (t + (a.val * coefficient r j σ (C i).1 i) • point (period r j σ)))).card + have he : (fun C : Fin (16 * k * s) → ZMod L × Config I L (16 * k * s) h => + ¬ Good ε r j (h + 1) (σ, C) t) = (fun C => ∃ a ∈ Finset.univ, E a C) := by + funext C + simp only [Good, E, Finset.mem_univ, true_and, not_forall] + rw [he] + calc + _ ≤ ∑ a, probability (E a) := probability_union_bound Finset.univ E + _ ≤ ∑ _a : Fin (period r j σ), (4 / 5 : ℝ) ^ (k * s) := Finset.sum_le_sum (fun a _ => + fixed_residue_failure r hr hr10 hL j hgrid ih σ t hlist a) + _ = (period r j σ : ℝ) * (4 / 5 : ℝ) ^ (k * s) := by simp + _ ≤ _ := by + apply mul_le_mul_of_nonneg_right _ (by positivity) + have hP : period r j σ ≤ U ^ (16 * k) := by + calc + _ ≤ ∏ _v : Fin (16 * k), U := Finset.prod_le_prod (fun _ _ => hrU _) + _ = _ := by simp + exact_mod_cast hP + +theorem good_probability {I : Type} [Fintype I] {k s L U : ℕ} [NeZero L] + (r : I → ℕ) (hr : ∀ i, Nat.Prime (r i)) (hi : Function.Injective r) + (hr10 : ∀ i, 10 ≤ r i) (hU : 1 ≤ U) (hrU : ∀ i, r i ≤ U) + (hL : ∀ i, r i ∣ L) (j : Fin (16 * k) ↪ I) + {ε : ℝ} (hgrid : ∀ i, 2 * ε * r i < 1) + (hε : 2 * ε * ((U ^ k : ℕ) : ℝ) ^ 2 < 1) + (herr : (16 * k : ℝ) / Fintype.card I + (U : ℝ) ^ (16 * k) * (4 / 5 : ℝ) ^ (k * s) ≤ 1 / 10) + (h : ℕ) (t : UnitAddCircle) (ht : ε ≤ ‖t‖) : + 9 / 10 ≤ probability (fun C : Config I L (16 * k * s) h => Good ε r j h C t) := by + induction h generalizing t with + | zero => norm_num [Good, ht, probability, mean_const] + | succ h ih => + let bad (σ : Equiv.Perm I) := ¬ ∀ a : ℕ, + (Finset.univ.filter (fun v : Fin (16 * k) => ¬ r (σ (j v)) ∣ a)).card ≤ k → + ε ≤ ‖t + a • point (period r j σ)‖ + have hbad : probability bad ≤ (16 * k : ℝ) / Fintype.card I := by + simpa only [Nat.cast_mul, Nat.cast_ofNat, bad, period] using prime_list_event r hr hi hU hrU j ht hε + have hh := pair_failure_bound bad (fun σ C => ¬ Good ε r j (h + 1) (σ, C) t) + (δ := (U : ℝ) ^ (16 * k) * (4 / 5 : ℝ) ^ (k * s)) (by positivity) + (fun σ hσ => conditional_good_failure r hr hr10 hrU hL j hgrid ih σ t (not_not.mp hσ)) + have he : probability (fun C : Config I L (16 * k * s) (h + 1) => ¬ Good ε r j (h + 1) C t) ≤ 1 / 10 := by + exact hh.trans (by linarith) + rw [probability_not] at he + linarith + +end TreeEdit.TorusTree + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/CycleCharging.lean b/lean/OAI/Combinatorics/TreeEdit/CycleCharging.lean new file mode 100644 index 0000000000000000000000000000000000000000..fc778fea4f78af1eae50984cd433a4b17ebb473e --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/CycleCharging.lean @@ -0,0 +1,210 @@ +import OAI.Combinatorics.TreeEdit.SegmentComparison + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +lemma cycle_coordinates (m B n : ℕ) : + n = n / (m * B) * (m * B) + (n / B % m) * B + n % B := by + have h₁ := Nat.mod_add_div n B + have h₂ := Nat.mod_add_div (n / B) m + have hd : n / B / m = n / (m * B) := by rw [Nat.div_div_eq_div_mul, Nat.mul_comm] + rw [hd] at h₂ + nlinarith + +lemma split_cycle_gap {m B p p' q q' : ℕ} (hm : 2 ≤ m) (hB : 0 < B) + (hp : p / (m * B) = p' / (m * B)) + (hq : q / (m * B) < q' / (m * B)) + (hc : p / B % m = q / B % m) (hc' : p' / B % m = q' / B % m) : + q + p' + (m - 2) * B ≤ q' + p := by + have hp0 := cycle_coordinates m B p + have hp1 := cycle_coordinates m B p' + have hq0 := cycle_coordinates m B q + have hq1 := cycle_coordinates m B q' + rw [hp, hc] at hp0 + rw [hc'] at hp1 + have hpm := Nat.mod_lt p hB + have hpm' := Nat.mod_lt p' hB + have hqm := Nat.mod_lt q hB + have hqm' := Nat.mod_lt q' hB + have ht := Nat.mul_le_mul_right (m * B) (Nat.succ_le_of_lt hq) + have hm' : (m - 2) * B + 2 * B = m * B := by + rw [← Nat.add_mul, Nat.sub_add_cancel hm] + simp only [Nat.succ_mul] at ht + omega + +lemma alignment_window_bound {β : Type*} {N : ℕ} (x y : List β) + (f : Fin N ↪o Fin x.length) (g : Fin N ↪o Fin y.length) + (hfg : ∀ i, x.get (f i) = y.get (g i)) + (s : Finset (Fin N)) {a b P Q : ℕ} + (ha : a + P ≤ x.length) (hb : b + Q ≤ y.length) + (hf : ∀ i ∈ s, a ≤ (f i).val ∧ (f i).val < a + P) + (hg : ∀ i ∈ s, b ≤ (g i).val ∧ (g i).val < b + Q) : + s.card ≤ lcs (segment x a P) (segment y b Q) := by + let e := s.orderEmbOfFin rfl + let X := segment x a P + let Y := segment y b Q + have hX : X.length = P := length_segment _ ha + have hY : Y.length = Q := length_segment _ hb + have hlo (i : Fin s.card) := hf (e i) (s.orderEmbOfFin_mem rfl i) + have hro (i : Fin s.card) := hg (e i) (s.orderEmbOfFin_mem rfl i) + let fl : Fin s.card → Fin X.length := fun i => + ⟨(f (e i)).val - a, by rw [hX]; have := hlo i; omega⟩ + let gr : Fin s.card → Fin Y.length := fun i => + ⟨(g (e i)).val - b, by rw [hY]; have := hro i; omega⟩ + have hfl : StrictMono fl := by + intro i j hij + have hi := hlo i + have hj := hlo j + have hh := f.strictMono (e.strictMono hij) + change (f (e i)).val - a < (f (e j)).val - a + omega + have hgr : StrictMono gr := by + intro i j hij + have hi := hro i + have hj := hro j + have hh := g.strictMono (e.strictMono hij) + change (g (e i)).val - b < (g (e j)).val - b + omega + apply Alignment.le_lcs (x := X) (y := Y) + ⟨OrderEmbedding.ofStrictMono fl hfl, OrderEmbedding.ofStrictMono gr hgr, ?_⟩ + intro i + change X.get (fl i) = Y.get (gr i) + simp only [List.get_eq_getElem, X, Y, fl, gr] + rw [segment_get, segment_get] + simpa only [Nat.add_sub_of_le (hlo i).1, Nat.add_sub_of_le (hro i).1, + List.get_eq_getElem] using hfg (e i) + +lemma blockIndex_monotone {M P N : ℕ} (hP : 0 < P) + (f : Fin N ↪o Fin (M * P)) : Monotone (fun i => blockIndex hP (f i)) := by + intro i j hij + exact Nat.div_le_div_right (f.monotone hij) + +lemma card_block_fiber {M P N : ℕ} (hP : 0 < P) + (f : Fin N ↪o Fin (M * P)) (a : Fin M) : + (Finset.univ.filter (fun i => blockIndex hP (f i) = a)).card ≤ P := by + classical + let r : Fin N → Fin P := fun i => ⟨(f i).val % P, Nat.mod_lt _ hP⟩ + have hi : Set.InjOn r ↑(Finset.univ.filter (fun i => blockIndex hP (f i) = a)) := by + intro i hi j hj he + have hi' := congrArg Fin.val (Finset.mem_filter.mp hi).2 + have hj' := congrArg Fin.val (Finset.mem_filter.mp hj).2 + have hr := congrArg Fin.val he + apply f.injective + apply Fin.ext + dsimp [blockIndex] at hi' hj' + dsimp [r] at hr + have hx := Nat.div_add_mod (f i).val P + have hy := Nat.div_add_mod (f j).val P + rw [hi'] at hx + rw [hj'] at hy + omega + simpa using Finset.card_le_card_of_injOn r (fun _ _ => Finset.mem_univ _) hi + +lemma blockIndex_window {M P : ℕ} (hP : 0 < P) {i : Fin (M * P)} {a : Fin M} + (h : blockIndex hP i = a) : a.val * P ≤ i.val ∧ i.val < a.val * P + P := by + have he := congrArg Fin.val h + dsimp [blockIndex] at he + have hm := Nat.mod_lt i.val hP + have hd := Nat.div_add_mod i.val P + rw [he, Nat.mul_comm P] at hd + constructor <;> omega + +lemma sum_block_losses {M P N : ℕ} (hP : 0 < P) + (f : Fin N ↪o Fin (M * P)) : + (∑ a : Fin M, (P - (Finset.univ.filter + (fun i => blockIndex hP (f i) = a)).card)) = M * P - N := by + rw [Finset.sum_tsub_distrib _ (fun a _ => card_block_fiber hP f a)] + have he : (∑ a : Fin M, (Finset.univ.filter + (fun i => blockIndex hP (f i) = a)).card) = N := by + simpa using (Finset.card_eq_sum_card_fiberwise + (s := Finset.univ) (t := Finset.univ) + (f := fun i => blockIndex hP (f i)) (by simp)).symm + simp [he] + +lemma split_cycle_span_gap {m B T N : ℕ} (hm : 2 ≤ m) (hB : 0 < B) + (f g : Fin N ↪o Fin (T * (m * B))) + (hc : ∀ i, (f i).val / B % m = (g i).val / B % m) + (a : Fin T) (hC : 0 < m * B) + (hs : (Finset.univ.filter (fun i => blockIndex hC (f i) = a)).Nonempty) + (hsp : blockIndex hC (g ((Finset.univ.filter + (fun i => blockIndex hC (f i) = a)).min' hs)) ≠ + blockIndex hC (g ((Finset.univ.filter + (fun i => blockIndex hC (f i) = a)).max' hs))) : + (m - 2) * B ≤ (indexSpan g (Finset.univ.filter + (fun i => blockIndex hC (f i) = a))).card - + (Finset.univ.filter (fun i => blockIndex hC (f i) = a)).card := by + let s := Finset.univ.filter (fun i => blockIndex hC (f i) = a) + let i := s.min' hs + let j := s.max' hs + have hi : blockIndex hC (f i) = a := (Finset.mem_filter.mp (s.min'_mem hs)).2 + have hj : blockIndex hC (f j) = a := (Finset.mem_filter.mp (s.max'_mem hs)).2 + have hij : i ≤ j := s.min'_le _ (s.max'_mem hs) + have hg : (g i).val / (m * B) < (g j).val / (m * B) := by + have hle := blockIndex_monotone hC g hij + have hne : (blockIndex hC (g i)) ≠ blockIndex hC (g j) := hsp + exact (show blockIndex hC (g i) < blockIndex hC (g j) from lt_of_le_of_ne hle hne) + have hp : (f i).val / (m * B) = (f j).val / (m * B) := + congrArg Fin.val (hi.trans hj.symm) + have hgap := split_cycle_gap hm hB hp hg (hc i) (hc j) + have hfcard := card_le_indexSpan f s + have hflen := span_length_formula f s hs + have hglen := span_length_formula g s hs + change (m - 2) * B ≤ (indexSpan g s).card - s.card + dsimp [i, j] at hgap + omega + +lemma cycle_charging {m B T N : ℕ} (hm : 2 ≤ m) (hB : 0 < B) + (f g : Fin N ↪o Fin (T * (m * B))) + (hc : ∀ i, (f i).val / B % m = (g i).val / B % m) + (δ : ℝ) (hδ : δ ≤ ((m - 2) * B : ℕ)) + (hsmall : ∀ (a b : Fin T), + (∀ i ∈ Finset.univ.filter (fun i => blockIndex (by positivity : 0 < m * B) (f i) = a), + blockIndex (by positivity : 0 < m * B) (g i) = b) → + δ ≤ ((m * B - (Finset.univ.filter + (fun i => blockIndex (by positivity : 0 < m * B) (f i) = a)).card : ℕ) : ℝ)) : + (T : ℝ) * δ ≤ 2 * ((T * (m * B) - N : ℕ) : ℝ) := by + classical + have hC : 0 < m * B := by positivity + let key := fun i => blockIndex hC (f i) + let s := fun a : Fin T => Finset.univ.filter (fun i => key i = a) + have hlocal (a : Fin T) : δ ≤ ((m * B - (s a).card : ℕ) : ℝ) + + (((indexSpan g (s a)).card - (s a).card : ℕ) : ℝ) := by + by_cases hs : (s a).Nonempty + · by_cases he : blockIndex hC (g ((s a).min' hs)) = + blockIndex hC (g ((s a).max' hs)) + · have hh := hsmall a (blockIndex hC (g ((s a).min' hs))) (by + intro i hi + have hl := blockIndex_monotone hC g ((s a).min'_le i hi) + have hr := blockIndex_monotone hC g ((s a).le_max' i hi) + change blockIndex hC (g i) ≤ blockIndex hC (g ((s a).max' hs)) at hr + rw [← he] at hr + exact le_antisymm hr hl) + exact hh.trans (le_add_of_nonneg_right (Nat.cast_nonneg _)) + · have hg := split_cycle_span_gap hm hB f g hc a hC hs he + have hh : δ ≤ (((indexSpan g (s a)).card - (s a).card : ℕ) : ℝ) := + hδ.trans (by exact_mod_cast hg) + exact hh.trans (le_add_of_nonneg_left (Nat.cast_nonneg _)) + · have he : s a = ∅ := Finset.not_nonempty_iff_eq_empty.mp hs + rw [he] + simp only [Finset.card_empty, Nat.sub_zero, indexSpan_empty, Nat.cast_zero, add_zero] + exact hδ.trans (by exact_mod_cast Nat.mul_le_mul_right B (Nat.sub_le m 2)) + have hsum := Finset.sum_le_sum (fun a (_ : a ∈ (Finset.univ : Finset (Fin T))) => hlocal a) + have htarget := sum_span_gaps_le g key (blockIndex_monotone hC f) + have hsource := sum_block_losses hC f + have htarget' : (∑ a : Fin T, (((indexSpan g (s a)).card - (s a).card : ℕ) : ℝ)) ≤ + ((T * (m * B) - N : ℕ) : ℝ) := by exact_mod_cast htarget + have hsource' : (∑ a : Fin T, ((m * B - (s a).card : ℕ) : ℝ)) = + ((T * (m * B) - N : ℕ) : ℝ) := by exact_mod_cast hsource + simp only [Finset.sum_add_distrib] at hsum + rw [hsource'] at hsum + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hsum + linarith + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/CyclicWords.lean b/lean/OAI/Combinatorics/TreeEdit/CyclicWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..8719de08ae4cfbab43cb9777bd9c1d5387f4c83a --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/CyclicWords.lean @@ -0,0 +1,193 @@ +import OAI.Combinatorics.TreeEdit.CycleCharging + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace Words + +variable {β : Type*} {n : ℕ} + +def get (x : Word β n) (i : Fin n) : β := x.val.get (Fin.cast x.property.symm i) + +def ofFn (x : Fin n → β) : Word β n := ⟨List.ofFn x, List.length_ofFn⟩ + +@[simp] lemma at_ofFn (x : Fin n → β) (i : Fin n) : get (ofFn x) i = x i := by + simp [get, ofFn, List.get_eq_getElem, Fin.cast] + +def map {γ : Type*} (f : β → γ) (x : Word β n) : Word γ n := + ⟨x.val.map f, by simp [x.property]⟩ + +@[simp] lemma at_map {γ : Type*} (f : β → γ) (x : Word β n) (i : Fin n) : + get (map f x) i = f (get x i) := by simp [get, map, List.get_eq_getElem, Fin.cast] + +lemma ext {x y : Word β n} (h : ∀ i, get x i = get y i) : x = y := by + apply Subtype.ext + apply List.ext_getElem + · exact x.property.trans y.property.symm + · intro i hi hj + simpa [get, List.get_eq_getElem] using h ⟨i, by rwa [x.property] at hi⟩ + +def cycles {m T B : ℕ} {β : Fin m → Type*} + (blocks : Fin T → ∀ i, Word (β i) B) : Word (Sigma β) (T * (m * B)) := + ofFn fun r => ⟨r.modNat.divNat, get (blocks r.divNat r.modNat.divNat) r.modNat.modNat⟩ + +@[simp] lemma at_cycles {m T B : ℕ} {β : Fin m → Type*} + (blocks : Fin T → ∀ i, Word (β i) B) (r : Fin (T * (m * B))) : + get (cycles blocks) r = + ⟨r.modNat.divNat, get (blocks r.divNat r.modNat.divNat) r.modNat.modNat⟩ := by + simp [cycles] + +lemma cycle_coordinates {m T B : ℕ} (r : Fin (T * (m * B))) : + r.val = r.divNat.val * (m * B) + r.modNat.divNat.val * B + + r.modNat.modNat.val := by + dsimp [Fin.divNat, Fin.modNat] + have h1 := Nat.mod_add_div r.val (m * B) + have h2 := Nat.mod_add_div (r.val % (m * B)) B + nlinarith + +lemma cycle_offset_strict {m T B : ℕ} {r s : Fin (T * (m * B))} + (ha : r.divNat = s.divNat) (hi : r.modNat.divNat = s.modNat.divNat) + (hrs : r < s) : r.modNat.modNat < s.modNat.modNat := by + have hr := cycle_coordinates r + have hs := cycle_coordinates s + rw [ha, hi] at hr + change r.modNat.modNat.val < s.modNat.modNat.val + change r.val < s.val at hrs + omega + +lemma cycle_block_alignment {m T B N : ℕ} {β : Fin m → Type*} + (x y : Fin T → ∀ i, Word (β i) B) + (f g : Fin N ↪o Fin (T * (m * B))) + (hfg : ∀ j, get (cycles x) (f j) = get (cycles y) (g j)) + (s : Finset (Fin N)) (a b : Fin T) (i : Fin m) + (hf : ∀ j ∈ s, (f j).divNat = a ∧ (f j).modNat.divNat = i) + (hg : ∀ j ∈ s, (g j).divNat = b ∧ (g j).modNat.divNat = i) : + s.card ≤ lcs (x a i).val (y b i).val := by + let e := s.orderEmbOfFin rfl + have hf' (j : Fin s.card) := hf (e j) (s.orderEmbOfFin_mem rfl j) + have hg' (j : Fin s.card) := hg (e j) (s.orderEmbOfFin_mem rfl j) + let fl : Fin s.card → Fin B := fun j => (f (e j)).modNat.modNat + let gr : Fin s.card → Fin B := fun j => (g (e j)).modNat.modNat + have hfl : StrictMono fl := by + intro j k hjk + exact cycle_offset_strict ((hf' j).1.trans (hf' k).1.symm) + ((hf' j).2.trans (hf' k).2.symm) (f.strictMono (e.strictMono hjk)) + have hgr : StrictMono gr := by + intro j k hjk + exact cycle_offset_strict ((hg' j).1.trans (hg' k).1.symm) + ((hg' j).2.trans (hg' k).2.symm) (g.strictMono (e.strictMono hjk)) + apply Alignment.le_lcs ⟨(OrderEmbedding.ofStrictMono fl hfl).comp + (Fin.castOrderIso (x a i).property.symm).toOrderEmbedding, + (OrderEmbedding.ofStrictMono gr hgr).comp + (Fin.castOrderIso (y b i).property.symm).toOrderEmbedding, ?_⟩ + intro j + have hh := hfg (e j) + simp only [at_cycles] at hh + have h1 := hf' j + have h2 := hg' j + rcases h1 with ⟨h1a, h1i⟩ + rcases h2 with ⟨h2a, h2i⟩ + rw [h1a, h1i, h2a, h2i] at hh + exact eq_of_heq (Sigma.mk.inj hh).2 + +lemma cycle_fiber_bound {m T B N : ℕ} {β : Fin m → Type*} + (x y : Fin T → ∀ i, Word (β i) B) + (f g : Fin N ↪o Fin (T * (m * B))) + (hfg : ∀ j, get (cycles x) (f j) = get (cycles y) (g j)) + (s : Finset (Fin N)) (a b : Fin T) + (hf : ∀ j ∈ s, (f j).divNat = a) + (hg : ∀ j ∈ s, (g j).divNat = b) : + s.card ≤ ∑ i : Fin m, lcs (x a i).val (y b i).val := by + classical + have he : s.card = ∑ i : Fin m, (s.filter (fun j => (f j).modNat.divNat = i)).card := by + simpa using Finset.card_eq_sum_card_fiberwise + (s := s) (t := Finset.univ) (f := fun j => (f j).modNat.divNat) (by simp) + rw [he] + apply Finset.sum_le_sum + intro i _ + apply cycle_block_alignment x y f g hfg _ a b i + · intro j hj + exact ⟨hf j (Finset.mem_filter.mp hj).1, (Finset.mem_filter.mp hj).2⟩ + · intro j hj + have heq := congrArg Sigma.fst (hfg j) + simp only [at_cycles] at heq + exact ⟨hg j (Finset.mem_filter.mp hj).1, heq.symm.trans (Finset.mem_filter.mp hj).2⟩ + +lemma cycles_deficit {m T B : ℕ} {β : Fin m → Type*} (hm : 2 ≤ m) (hB : 0 < B) + (x y : Fin T → ∀ i, Word (β i) B) (δ : ℝ) + (hδ : δ ≤ ((m - 2) * B : ℕ)) + (hblocks : ∀ a b, δ ≤ ∑ i : Fin m, (deficit (x a i).val (y b i).val : ℝ)) : + (T : ℝ) * δ ≤ 2 * (deficit (cycles x).val (cycles y).val : ℝ) := by + classical + obtain ⟨al⟩ := exists_lcs_alignment (cycles x).val (cycles y).val + let f := al.left.comp (Fin.castOrderIso (cycles x).property).toOrderEmbedding + let g := al.right.comp (Fin.castOrderIso (cycles y).property).toOrderEmbedding + have hfg (j) : get (cycles x) (f j) = get (cycles y) (g j) := al.agree j + have hC : 0 < m * B := by positivity + have hc (j) : (f j).val / B % m = (g j).val / B % m := by + have he := congrArg Sigma.fst (hfg j) + have hv := congrArg Fin.val he + simp only [at_cycles, Fin.divNat, Fin.modNat] at hv + simpa only [Nat.mul_comm m, Nat.mod_mul_right_div_self] using hv + have hh := cycle_charging hm hB f g hc δ hδ (by + intro a b hb + let s := Finset.univ.filter (fun j => blockIndex hC (f j) = a) + have hf' (j) (hj : j ∈ s) : (f j).divNat = a := (Finset.mem_filter.mp hj).2 + have hg' (j) (hj : j ∈ s) : (g j).divNat = b := hb j hj + have hn := cycle_fiber_bound x y f g hfg s a b hf' hg' + have hle (i : Fin m) : lcs (x a i).val (y b i).val ≤ B := by + simpa [(x a i).property] using lcs_le_length_left (x a i).val (y b i).val + have hs : (∑ i : Fin m, deficit (x a i).val (y b i).val) = + m * B - ∑ i : Fin m, lcs (x a i).val (y b i).val := by + simp only [deficit, (x a _).property] + rw [Finset.sum_tsub_distrib _ (fun i _ => hle i)] + simp + have hsum : (∑ i : Fin m, (deficit (x a i).val (y b i).val : ℝ)) = + ((m * B - ∑ i : Fin m, lcs (x a i).val (y b i).val : ℕ) : ℝ) := by + exact_mod_cast hs + have hb' := hblocks a b + rw [hsum] at hb' + exact hb'.trans (by exact_mod_cast Nat.sub_le_sub_left hn (m * B))) + simpa only [deficit, (cycles x).property] using hh + +end Words + +lemma lcs_map_of_injective {β γ : Type*} (f : β → γ) (hf : Function.Injective f) + (x y : List β) : lcs (x.map f) (y.map f) = lcs x y := by + apply Nat.le_antisymm + · obtain ⟨z, hz1, hz2, hz⟩ := exists_lcs (x.map f) (y.map f) + obtain ⟨z1, hz1, he1⟩ := List.sublist_map_iff.mp hz1 + obtain ⟨z2, hz2, he2⟩ := List.sublist_map_iff.mp hz2 + have he : z1 = z2 := hf.list_map (he1.symm.trans he2) + subst z2 + have hh := length_le_lcs hz1 hz2 + rw [← hz, he1, List.length_map] + exact hh + · obtain ⟨z, hz1, hz2, hz⟩ := exists_lcs x y + have hh := length_le_lcs (hz1.map f) (hz2.map f) + simpa [hz] using hh + +lemma deficit_singleton {β : Type*} {x y : β} (hxy : x ≠ y) : deficit [x] [y] = 1 := by + obtain ⟨z, hz1, hz2, hz⟩ := exists_lcs [x] [y] + have he : z = [] := by + rcases List.sublist_singleton.mp hz1 with he | he + · exact he + · subst z + simp [List.sublist_singleton, hxy] at hz2 + have hl : lcs [x] [y] = 0 := by simpa [he] using hz.symm + simp [deficit, hl] + +lemma translation_cycle {A : Type*} [AddCommGroup A] (x v : A) (a b R : ℕ) (t : ℤ) : + x + t • (R • v) + b • v = + (x + a • v) + ((b : ℤ) - a + t * R) • v := by + simp only [add_zsmul, sub_zsmul, mul_smul, Nat.cast_smul_eq_nsmul ℤ] + abel + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/Delimiter.lean b/lean/OAI/Combinatorics/TreeEdit/Delimiter.lean new file mode 100644 index 0000000000000000000000000000000000000000..c94ce3392ca5230ac2cc22319e746457a0209171 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/Delimiter.lean @@ -0,0 +1,282 @@ +import OAI.Combinatorics.TreeEdit.WordOperations + +namespace OAI + +namespace TreeEdit.Delimiter +open scoped BigOperators +open Classical + +lemma eq_of_full_lcs {α : Type*} {x y : List α} (hl : x.length = y.length) + (hc : x.length ≤ lcs x y) : x = y := by + obtain ⟨z, hx, hy, hz⟩ := exists_lcs x y + have hzx : z = x := hx.eq_of_length (by have := hx.length_le; omega) + have hzy : z = y := hy.eq_of_length (by have := hx.length_le; omega) + exact hzx.symm.trans hzy + +def Synchronizing {α : Type*} {B : ℕ} (c : α → Word Bool B) : Prop := + ∀ (x : List α) (a : α) (n : ℕ), n+B ≤ (encode c x).length → + segment (encode c x) n B = (c a).val → + ∃ i : Fin x.length, n = i.val*B ∧ x.get i = a + +lemma full_fiber {M B N : ℕ} (hB : 0 < B) (f : Fin N ↪o Fin (M*B)) + (a : Fin M) (hc : (Finset.univ.filter (fun i => blockIndex hB (f i) = a)).card = B) : + ∃ (hs : (Finset.univ.filter (fun i => blockIndex hB (f i) = a)).Nonempty), + (f ((Finset.univ.filter (fun i => blockIndex hB (f i) = a)).min' hs)).val = a.val*B ∧ + (indexSpan f (Finset.univ.filter (fun i => blockIndex hB (f i) = a))).card = B := by + let S := Finset.univ.filter (fun i => blockIndex hB (f i) = a) + have hs : S.Nonempty := Finset.card_pos.mp (by change S.card = B at hc; omega) + have hl : blockIndex hB (f (S.min' hs)) = a := (Finset.mem_filter.mp (S.min'_mem hs)).2 + have hu : blockIndex hB (f (S.max' hs)) = a := (Finset.mem_filter.mp (S.max'_mem hs)).2 + have hw := span_in_block hB f S hs (hl.trans hu.symm) + have hge := card_le_indexSpan f S + have he : (indexSpan f S).card = B := by change S.card = B at hc; omega + have hm : (f (S.min' hs)).val % B = 0 := by omega + have hd := Nat.div_add_mod (f (S.min' hs)).val B + have hq := congrArg Fin.val hl + change (f (S.min' hs)).val / B = a.val at hq + refine ⟨hs, ?_, he⟩ + rw [hq, hm, Nat.add_zero, Nat.mul_comm] at hd + exact hd.symm + +lemma good_fiber_matches {α : Type*} {M B N : ℕ} (hB : 0 < B) + (c : α → Word Bool B) (hc : Synchronizing c) (x y : Word α M) + (f g : Fin N ↪o Fin (M*B)) + (hfg : ∀ i, (encode c x.val).get (Fin.cast (by rw [length_encode, x.property]) (f i)) = + (encode c y.val).get (Fin.cast (by rw [length_encode, y.property]) (g i))) + (a : Fin M) (hfull : (Finset.univ.filter (fun i => blockIndex hB (f i) = a)).card = B) + (hgap : (indexSpan g (Finset.univ.filter (fun i => blockIndex hB (f i) = a))).card = B) : + ∃ (hs : (Finset.univ.filter (fun i => blockIndex hB (f i) = a)).Nonempty) (b : Fin M), + (g ((Finset.univ.filter (fun i => blockIndex hB (f i) = a)).min' hs)).val = b.val*B ∧ + x.val.get (Fin.cast x.property.symm a) = y.val.get (Fin.cast y.property.symm b) := by + let S := Finset.univ.filter (fun i => blockIndex hB (f i) = a) + obtain ⟨hs, hstart, hspan⟩ := full_fiber hB f a hfull + let f' := f.comp (Fin.castOrderIso (by rw [length_encode, x.property] : M*B = (encode c x.val).length)).toOrderEmbedding + let g' := g.comp (Fin.castOrderIso (by rw [length_encode, y.property] : M*B = (encode c y.val).length)).toOrderEmbedding + have hbase := span_card_le_lcs (encode c x.val) (encode c y.val) f' g' hfg S hs + have hfc : (indexSpan f' S).card = B := (indexSpan_card_cast _ f S).trans hspan + have hgc : (indexSpan g' S).card = B := (indexSpan_card_cast _ g S).trans hgap + have hxs : segment (encode c x.val) (f' (S.min' hs)).val B = (c (x.val.get (Fin.cast x.property.symm a))).val := by + change segment (encode c x.val) (f (S.min' hs)).val B = _ + rw [hstart] + have hh := segment_encode_block c x.val a.val 0 B (by rw [x.property]; exact a.isLt) (by omega) + simpa only [Nat.add_zero, segment, List.drop_zero, ← (c x.val[a.val]).property, List.take_length, List.get_eq_getElem, Fin.val_cast] using hh + have hgy : (g' (S.min' hs)).val+B ≤ (encode c y.val).length := by + simpa only [hgc] using span_bounds g' S hs + have hfx : (f' (S.min' hs)).val+B ≤ (encode c x.val).length := by + simpa only [hfc] using span_bounds f' S hs + have heq : segment (encode c y.val) (g' (S.min' hs)).val B = (c (x.val.get (Fin.cast x.property.symm a))).val := by + rw [hfc, hgc, hfull] at hbase + have he := eq_of_full_lcs (x := segment (encode c x.val) (f' (S.min' hs)).val B) (y := segment (encode c y.val) (g' (S.min' hs)).val B) (by rw [length_segment _ hfx, length_segment _ hgy]) + (by simpa only [length_segment _ hfx] using hbase) + exact he.symm.trans hxs + obtain ⟨b, hb, hlabel⟩ := hc y.val (x.val.get (Fin.cast x.property.symm a)) _ hgy heq + exact ⟨hs, Fin.cast y.property b, hb, hlabel.symm⟩ + +lemma alignment_bound {α : Type*} {M B N : ℕ} (hB : 0 < B) + (c : α → Word Bool B) (hc : Synchronizing c) (x y : Word α M) + (f g : Fin N ↪o Fin (M*B)) + (hfg : ∀ i, (encode c x.val).get (Fin.cast (by rw [length_encode, x.property]) (f i)) = + (encode c y.val).get (Fin.cast (by rw [length_encode, y.property]) (g i))) : + M ≤ lcs x.val y.val + 2*(M*B-N) := by + let S (a : Fin M) := Finset.univ.filter (fun i => blockIndex hB (f i) = a) + let G := Finset.univ.filter (fun a : Fin M => (S a).card = B ∧ (indexSpan g (S a)).card = B) + have hgood (a : Fin M) (ha : a ∈ G) := good_fiber_matches hB c hc x y f g hfg a + (Finset.mem_filter.mp ha).2.1 (Finset.mem_filter.mp ha).2.2 + let e := G.orderEmbOfFin rfl + have hem (i : Fin G.card) : e i ∈ G := G.orderEmbOfFin_mem rfl i + let minPos (i : Fin G.card) := (S (e i)).min' (hgood (e i) (hem i)).choose + let b (i : Fin G.card) := (hgood (e i) (hem i)).choose_spec.choose + have hb (i : Fin G.card) : (g (minPos i)).val = (b i).val*B := (hgood (e i) (hem i)).choose_spec.choose_spec.1 + have hl (i : Fin G.card) : x.val.get (Fin.cast x.property.symm (e i)) = y.val.get (Fin.cast y.property.symm (b i)) := + (hgood (e i) (hem i)).choose_spec.choose_spec.2 + have hsmin (i : Fin G.card) : blockIndex hB (f (minPos i)) = e i := + (Finset.mem_filter.mp ((S (e i)).min'_mem _)).2 + have hminmono : StrictMono minPos := by + intro i j hij + by_contra hn + have h := blockIndex_monotone hB f (le_of_not_gt hn) + dsimp only at h + rw [hsmin, hsmin] at h + exact not_le_of_gt (e.strictMono hij) h + have hbmono : StrictMono b := by + intro i j hij + have hh := g.strictMono (hminmono hij) + change (g (minPos i)).val < (g (minPos j)).val at hh + rw [hb, hb] at hh + exact (Nat.mul_lt_mul_right hB).mp hh + have hglcs : G.card ≤ lcs x.val y.val := Alignment.le_lcs + ⟨e.comp (Fin.castOrderIso x.property.symm).toOrderEmbedding, + (OrderEmbedding.ofStrictMono b hbmono).comp (Fin.castOrderIso y.property.symm).toOrderEmbedding, hl⟩ + have hbad : ∀ a : Fin M, (if a ∈ G then 0 else 1) ≤ + (B-(S a).card) + ((indexSpan g (S a)).card - (S a).card) := by + intro a + have hc' := card_block_fiber hB f a + have hs' := card_le_indexSpan g (S a) + split_ifs with ha + · omega + · have hn : ¬ ((S a).card = B ∧ (indexSpan g (S a)).card = B) := by simpa only [G, Finset.mem_filter, Finset.mem_univ, true_and] using ha + change (S a).card ≤ B at hc' + omega + have hsum := Finset.sum_le_sum (s := Finset.univ) (fun a _ => hbad a) + have hloss := sum_block_losses hB f + have hgap := sum_span_gaps_le g (fun i => blockIndex hB (f i)) (blockIndex_monotone hB f) + have hcount : (∑ a : Fin M, if a ∈ G then 0 else 1) = M-G.card := by + simpa only [ite_not, Finset.sum_boole, Finset.filter_not, Finset.filter_mem_eq_inter, Finset.univ_inter, + Finset.card_sdiff_of_subset (Finset.subset_univ G), Finset.card_univ, Fintype.card_fin, Nat.cast_id] using + (Finset.sum_boole (fun a : Fin M => a ∉ G) Finset.univ : (∑ a : Fin M, if a ∉ G then (1 : ℕ) else 0) = _) + rw [hcount, Finset.sum_add_distrib] at hsum + change (∑ a : Fin M, (B-(S a).card)) = M*B-N at hloss + change (∑ a : Fin M, ((indexSpan g (S a)).card-(S a).card)) ≤ M*B-N at hgap + rw [hloss] at hsum + have hcard : G.card ≤ M := by simpa using Finset.card_le_univ G + omega + +end TreeEdit.Delimiter + +namespace TreeEdit.Delimiter +open scoped BigOperators +open Classical + +lemma deficit_bound {α : Type*} {M B : ℕ} (hB : 0 < B) (c : α → Word Bool B) + (hc : Synchronizing c) (x y : Word α M) : + deficit x.val y.val ≤ 2*deficit (encode c x.val) (encode c y.val) := by + obtain ⟨A⟩ := exists_lcs_alignment (encode c x.val) (encode c y.val) + have hx : (encode c x.val).length = M*B := by rw [length_encode, x.property] + have hy : (encode c y.val).length = M*B := by rw [length_encode, y.property] + let f := A.left.comp (Fin.castOrderIso hx).toOrderEmbedding + let g := A.right.comp (Fin.castOrderIso hy).toOrderEmbedding + have hfg : ∀ i, (encode c x.val).get (Fin.cast hx.symm (f i)) = + (encode c y.val).get (Fin.cast hy.symm (g i)) := A.agree + have hh := alignment_bound hB c hc x y f g hfg + dsimp only [deficit] + rw [hx, x.property] + omega + +def bit {t : ℕ} (label : Fin t → Bool) (i : Fin (2*t+3)) : Bool := + if hi : i.val < 2 then true else + if h : i.val % 2 = 1 then label ⟨(i.val-3)/2, by have := i.isLt; omega⟩ else false + +def code {α : Type*} {t : ℕ} (label : α → (Fin t → Bool)) (a : α) : Word Bool (2*t+3) := + vectorWord (bit (label a)) + +lemma bit_true {t : ℕ} (label : Fin t → Bool) (i : Fin (2*t+3)) (h : bit label i = true) : + i.val = 0 ∨ i.val % 2 = 1 := by + unfold bit at h + split_ifs at h with hi hi + · omega + · exact Or.inr hi + +lemma bit_label {t : ℕ} (label : Fin t → Bool) (i : Fin t) : + bit label ⟨3+2*i.val, by have := i.isLt; omega⟩ = label i := by + have he : (3+2*i.val) % 2 = 1 := by omega + simp only [bit, show ¬ 3+2*i.val < 2 by omega, dite_false, he, dite_true] + congr 1 + apply Fin.ext + change (3+2*i.val-3)/2 = i.val + omega + +lemma code_injective {α : Type*} {t : ℕ} (label : α → (Fin t → Bool)) (hl : Function.Injective label) : + Function.Injective (code label) := by + intro a b hab + apply hl + funext i + have h := congrArg (fun w : Word Bool (2*t+3) => + w.val.get (Fin.cast w.property.symm ⟨3+2*i.val, by have := i.isLt; omega⟩)) hab + simp only [code, vectorWord, List.get_eq_getElem, List.getElem_ofFn] at h + change bit (label a) ⟨3+2*i.val, _⟩ = bit (label b) ⟨3+2*i.val, _⟩ at h + simpa only [bit_label] using h + +lemma get_position {α : Type*} {B : ℕ} (hB : 0 < B) (c : α → Word Bool B) (x : List α) + (p : ℕ) (hp : p < (encode c x).length) : + (encode c x)[p] = (c (x[p/B]'((Nat.div_lt_iff_lt_mul hB).mpr (by rwa [length_encode] at hp)))).val[p%B]'(by + rw [(c _).property]; exact Nat.mod_lt _ hB) := by + have hh := get_encode_block c x (p/B) (p%B) ((Nat.div_lt_iff_lt_mul hB).mpr (by rwa [length_encode] at hp)) (Nat.mod_lt p hB) + simpa only [Nat.mul_comm (p/B) B, Nat.div_add_mod] using hh + +lemma bit_position {α : Type*} {t : ℕ} (label : α → (Fin t → Bool)) (x : List α) + (p : ℕ) (hp : p < (encode (code label) x).length) : + (encode (code label) x)[p] = bit (label (x[p/(2*t+3)]'((Nat.div_lt_iff_lt_mul (by omega : 0 < 2*t+3)).mpr (by rwa [length_encode] at hp)))) + ⟨p%(2*t+3), Nat.mod_lt _ (by omega)⟩ := by + rw [get_position (by omega)] + simp only [code, vectorWord, List.getElem_ofFn] + +lemma marker {α : Type*} {t : ℕ} (label : α → (Fin t → Bool)) (x : List α) + (p : ℕ) (hp : p+1 < (encode (code label) x).length) + (h0 : (encode (code label) x)[p]'(by omega) = true) + (h1 : (encode (code label) x)[p+1] = true) : p%(2*t+3) = 0 := by + rw [bit_position] at h0 h1 + have h0' := bit_true _ _ h0 + have h1' := bit_true _ _ h1 + change p%(2*t+3) = 0 ∨ p%(2*t+3)%2 = 1 at h0' + change (p+1)%(2*t+3) = 0 ∨ (p+1)%(2*t+3)%2 = 1 at h1' + have hr := Nat.mod_lt p (by omega : 0 < 2*t+3) + have hr' := Nat.mod_lt (p+1) (by omega : 0 < 2*t+3) + by_contra hn + have ho : p%(2*t+3)%2 = 1 := h0'.resolve_left hn + have hend : p%(2*t+3)+1 < 2*t+3 := by omega + have he : (p+1)%(2*t+3) = p%(2*t+3)+1 := by + rw [Nat.add_mod, Nat.mod_eq_of_lt (by omega : 1 < 2*t+3), Nat.mod_eq_of_lt hend] + rw [he] at h1' + omega + +lemma code_synchronizing {α : Type*} {t : ℕ} (label : α → (Fin t → Bool)) (hl : Function.Injective label) : + Synchronizing (code label) := by + intro x a n hn he + have h0 : (encode (code label) x)[n]'(by omega) = true := by + have hh := congrArg (fun l : List Bool => l[0]?) he + have hbit : (code label a).val[0]'(by rw [(code label a).property]; omega) = true := by simp only [code, vectorWord, List.getElem_ofFn, bit]; norm_num + rw [List.getElem?_eq_getElem (by rw [length_segment _ hn]; omega), + List.getElem?_eq_getElem (by rw [(code label a).property]; omega)] at hh + simpa only [Option.some.injEq, segment_get, Nat.add_zero, hbit] using hh + have h1 : (encode (code label) x)[n+1]'(by omega) = true := by + have hh := congrArg (fun l : List Bool => l[1]?) he + have hbit : (code label a).val[1]'(by rw [(code label a).property]; omega) = true := by simp only [code, vectorWord, List.getElem_ofFn, bit]; norm_num + rw [List.getElem?_eq_getElem (by rw [length_segment _ hn]; omega), + List.getElem?_eq_getElem (by rw [(code label a).property]; omega)] at hh + simpa only [Option.some.injEq, segment_get, hbit] using hh + have hm := marker label x n (by omega) h0 h1 + have hbi : n/(2*t+3) < x.length := (Nat.div_lt_iff_lt_mul (by omega)).mpr (by rw [← length_encode (code label) x]; omega) + let b : Fin x.length := ⟨n/(2*t+3), hbi⟩ + have hstart : n = b.val*(2*t+3) := by + have hd := Nat.div_add_mod n (2*t+3) + rw [hm, Nat.add_zero, Nat.mul_comm] at hd + exact hd.symm + refine ⟨b, hstart, ?_⟩ + apply code_injective label hl + apply Subtype.ext + have hh := segment_encode_block (code label) x b.val 0 (2*t+3) b.isLt (by omega) + have hs : segment (encode (code label) x) n (2*t+3) = (code label (x.get b)).val := by + rw [hstart] + simpa only [Nat.add_zero, segment, List.drop_zero, ← (code label x[b.val]).property, List.take_length, List.get_eq_getElem] using hh + exact hs.symm.trans he + +def width (A : ℕ) : ℕ := 2*Nat.clog 2 A+3 + +lemma width_eq (A : ℕ) : width A = 2*⌈Real.log (A : ℝ)/Real.log 2⌉₊+3 := by + rw [width, ← Real.natCeil_logb_natCast 2 A] + rfl + +lemma exists_code (α : Type*) [Fintype α] : + ∃ c : α → Word Bool (width (Fintype.card α)), Synchronizing c := by + have hcard : Fintype.card α ≤ Fintype.card (Fin (Nat.clog 2 (Fintype.card α)) → Bool) := by + simpa only [Fintype.card_fun, Fintype.card_bool, Fintype.card_fin] using Nat.le_pow_clog (by norm_num : 1 < 2) (Fintype.card α) + let label := (Fintype.equivFin α).toEmbedding.trans ((Fin.castLEEmb hcard).trans (Fintype.equivFin (Fin (Nat.clog 2 (Fintype.card α)) → Bool)).symm.toEmbedding) + exact ⟨code label, code_synchronizing label label.injective⟩ + +theorem transfer (α : Type*) [Fintype α] : + ∃ c : α → Word Bool (width (Fintype.card α)), ∀ (n : ℕ) (x y : Word α n), + deficit x.val y.val ≤ 2*deficit (encode c x.val) (encode c y.val) ∧ + (deficit x.val y.val : ℝ)/2 ≤ ed (encode c x.val) (encode c y.val) ∧ + ed (encode c x.val) (encode c y.val) ≤ width (Fintype.card α)*ed x.val y.val := by + obtain ⟨c, hc⟩ := exists_code α + refine ⟨c, fun n x y => ?_⟩ + have hh := deficit_bound (by dsimp [width]; omega) c hc x y + refine ⟨hh, ?_, ed_encode_le c x.val y.val⟩ + have he := deficit_le_ed (encode c x.val) (encode c y.val) + have hhr : (deficit x.val y.val : ℝ) ≤ 2*deficit (encode c x.val) (encode c y.val) := by exact_mod_cast hh + have her : (deficit (encode c x.val) (encode c y.val) : ℝ) ≤ ed (encode c x.val) (encode c y.val) := by exact_mod_cast he + linarith + +end TreeEdit.Delimiter + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/DistortionTransfer.lean b/lean/OAI/Combinatorics/TreeEdit/DistortionTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..621fb5e9c6fdc2f3cc6c5e0a8b29c2ef4f31be76 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/DistortionTransfer.lean @@ -0,0 +1,142 @@ +import OAI.Combinatorics.TreeEdit.FiniteFourier + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +lemma ratio_set_finite {β : Type*} [Finite β] (f : β → β → ℝ) : + {r | ∃ x y, x ≠ y ∧ r = f x y}.Finite := by + apply (Set.finite_range (fun xy : β × β => f xy.1 xy.2)).subset + rintro r ⟨x, y, _, rfl⟩ + exact ⟨(x,y), rfl⟩ + +lemma exists_realL1_injective (β : Type*) [Fintype β] : ∃ f : β → RealL1, Function.Injective f := by + classical + refine ⟨fun x => lp.single 1 0 ((Fintype.equivFin β x).val : ℝ), ?_⟩ + intro x y h + have hh := congrArg (fun v : RealL1 => v 0) h + simp only [lp.single_apply, Pi.single_eq_same] at hh + exact (Fintype.equivFin β).injective (Fin.ext (Nat.cast_injective hh)) + +lemma c1_lower {W : Finset (List Bool)} {L : ℝ} + (h : ∀ f : W → RealL1, Function.Injective f → L ≤ distortion W f) : L ≤ c1 W := by + apply le_csInf + · obtain ⟨f, hf⟩ := exists_realL1_injective W + exact ⟨distortion W f, f, hf, rfl⟩ + · rintro D ⟨f, hf, rfl⟩ + exact h f hf + +noncomputable def stretch (W : Finset (List Bool)) (f : W → RealL1) : ℝ := + sSup {r : ℝ | ∃ x y : W, x ≠ y ∧ r = dist (f x) (f y) / (ed x.val y.val : ℝ)} + +noncomputable def contraction (W : Finset (List Bool)) (f : W → RealL1) : ℝ := + sSup {r : ℝ | ∃ x y : W, x ≠ y ∧ r = (ed x.val y.val : ℝ) / dist (f x) (f y)} + +lemma stretch_nonneg {W : Finset (List Bool)} (hW : 2 ≤ W.card) (f : W → RealL1) : 0 ≤ stretch W f := by + obtain ⟨x, hx, y, hy, hxy⟩ := Finset.one_lt_card.mp (by omega : 1 < W.card) + apply le_trans (div_nonneg (dist_nonneg (x := f ⟨x,hx⟩) (y := f ⟨y,hy⟩)) (Nat.cast_nonneg _)) + apply le_csSup (ratio_set_finite _).bddAbove + exact ⟨⟨x,hx⟩, ⟨y,hy⟩, fun h => hxy (congrArg Subtype.val h), rfl⟩ + +lemma contraction_nonneg {W : Finset (List Bool)} (hW : 2 ≤ W.card) (f : W → RealL1) : 0 ≤ contraction W f := by + obtain ⟨x, hx, y, hy, hxy⟩ := Finset.one_lt_card.mp (by omega : 1 < W.card) + apply le_trans (div_nonneg (Nat.cast_nonneg (ed x y)) (dist_nonneg (x := f ⟨x,hx⟩) (y := f ⟨y,hy⟩))) + apply le_csSup (ratio_set_finite _).bddAbove + exact ⟨⟨x,hx⟩, ⟨y,hy⟩, fun h => hxy (congrArg Subtype.val h), rfl⟩ + +lemma dist_le_stretch {W : Finset (List Bool)} (f : W → RealL1) (x y : W) : + dist (f x) (f y) ≤ stretch W f * ed x.val y.val := by + by_cases hxy : x = y + · subst y; simp + · have he : (0 : ℝ) < ed x.val y.val := by + exact_mod_cast Nat.pos_of_ne_zero (fun h => hxy (Subtype.ext (ed_eq_zero_iff.mp h))) + apply (div_le_iff₀ he).mp + exact le_csSup (ratio_set_finite _).bddAbove ⟨x, y, hxy, rfl⟩ + +lemma ed_le_contraction {W : Finset (List Bool)} (f : W → RealL1) (hf : Function.Injective f) (x y : W) : + (ed x.val y.val : ℝ) ≤ contraction W f * dist (f x) (f y) := by + by_cases hxy : x = y + · subst y; simp + · have hd : 0 < dist (f x) (f y) := dist_pos.mpr (fun h => hxy (hf h)) + apply (div_le_iff₀ hd).mp + exact le_csSup (ratio_set_finite _).bddAbove ⟨x, y, hxy, rfl⟩ + +theorem binary_transfer {A Γ : Type*} [Fintype A] [AddCommGroup A] [Fintype Γ] + {M P : ℕ} (hM : 0 < M) (hP : 0 < P) (w : A → Word Γ M) (z : A) + (c : Γ → Word Bool P) (a b : ℝ) (ha : 0 < a) (hb : 0 < b) + (hcode : ∀ x y : Word Γ M, + (P : ℝ) / 804 * ed x.val y.val ≤ ed (encode c x.val) (encode c y.val)) + (hsep : ∀ x, (M : ℝ) ≤ a * ed (w x).val (w (x + z)).val) + (hobs : ∀ (F : A → RealL1) (C : ℝ), 0 ≤ C → + (∀ x y, dist (F x) (F y) ≤ C * ed (w x).val (w y).val) → + FiniteFourier.average (fun x => dist (F x) (F (x + z))) ≤ C * M * b) : + ∃ W : Finset (List Bool), 2 ≤ W.card ∧ (∀ v ∈ W, v.length = M * P) ∧ + (804 * a * b)⁻¹ ≤ c1 W := by + classical + let enc (x : A) := encode c (w x).val + let W := Finset.univ.image enc + have hmem (x : A) : enc x ∈ W := Finset.mem_image.mpr ⟨x, Finset.mem_univ _, rfl⟩ + have hne (x : A) : enc x ≠ enc (x + z) := by + intro he + have hc := hcode (w x) (w (x + z)) + rw [← show enc x = encode c (w x).val from rfl, + ← show enc (x + z) = encode c (w (x + z)).val from rfl, he, ed_self] at hc + have he0 : (ed (w x).val (w (x + z)).val : ℝ) = 0 := by + have hp : (0 : ℝ) < P := by exact_mod_cast hP + nlinarith only [hc, hp, (Nat.cast_nonneg (ed (w x).val (w (x + z)).val) : (0 : ℝ) ≤ ed (w x).val (w (x + z)).val)] + have hh := hsep x + rw [he0, mul_zero] at hh + exact (not_le_of_gt (by exact_mod_cast hM : (0 : ℝ) < M)) hh + have hW : 2 ≤ W.card := by + have hh := Finset.one_lt_card.mpr ⟨enc 0, hmem 0, enc (0 + z), hmem _, hne 0⟩ + omega + refine ⟨W, hW, ?_, ?_⟩ + · intro v hv + obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp hv + simp [enc, length_encode, (w x).property] + · apply c1_lower + intro f hf + let F : A → RealL1 := fun x => f ⟨enc x, hmem x⟩ + let S := stretch W f + let D := contraction W f + have hS : 0 ≤ S := stretch_nonneg hW f + have hD : 0 ≤ D := contraction_nonneg hW f + have hlip (x y : A) : dist (F x) (F y) ≤ (S * P) * ed (w x).val (w y).val := by + calc + _ ≤ S * ed (enc x) (enc y) := dist_le_stretch (W := W) f ⟨enc x, hmem x⟩ ⟨enc y, hmem y⟩ + _ ≤ S * (P * (ed (w x).val (w y).val : ℝ)) := + mul_le_mul_of_nonneg_left (by exact_mod_cast ed_encode_le c (w x).val (w y).val) hS + _ = _ := by ring + have hu := hobs F (S * P) (mul_nonneg hS (Nat.cast_nonneg _)) hlip + have hl (x : A) : (P : ℝ) * M ≤ 804 * a * D * dist (F x) (F (x + z)) := by + have hc := hcode (w x) (w (x + z)) + have hd := ed_le_contraction f hf ⟨enc x, hmem x⟩ ⟨enc (x + z), hmem _⟩ + calc + _ ≤ P * (a * ed (w x).val (w (x + z)).val) := mul_le_mul_of_nonneg_left (hsep x) (by positivity) + _ = a * (P * ed (w x).val (w (x + z)).val) := by ring + _ ≤ a * (804 * ed (enc x) (enc (x + z))) := mul_le_mul_of_nonneg_left (by dsimp [enc]; linarith) ha.le + _ ≤ a * (804 * (D * dist (F x) (F (x + z)))) := by gcongr + _ = _ := by ring + have hav := FiniteFourier.average_mono hl + rw [FiniteFourier.average_const] at hav + have he : FiniteFourier.average (fun x => 804 * a * D * dist (F x) (F (x + z))) = + (804 * a * D) * FiniteFourier.average (fun x => dist (F x) (F (x + z))) := by + simp only [FiniteFourier.average, ← Finset.mul_sum] + ring + rw [he] at hav + have hh := hav.trans (mul_le_mul_of_nonneg_left hu (by positivity)) + have hPM : (0 : ℝ) < P * M := by positivity + have hd : 1 ≤ 804 * a * b * distortion W f := by + apply (mul_le_mul_iff_left₀ hPM).mp + change 1 * (P * M : ℝ) ≤ (804 * a * b * (S * D)) * (P * M) + convert hh using 1 <;> first | rfl | ring + rw [inv_eq_one_div] + exact (div_le_iff₀ (by positivity : (0 : ℝ) < 804 * a * b)).mpr (by simpa only [mul_comm] using hd) + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/EditMetric.lean b/lean/OAI/Combinatorics/TreeEdit/EditMetric.lean new file mode 100644 index 0000000000000000000000000000000000000000..24031a5817f1d74b9220ab82df083d55e298f4bb --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/EditMetric.lean @@ -0,0 +1,275 @@ +import OAI.Combinatorics.TreeEdit.Model + +namespace OAI + +namespace TreeEdit + +universe u v + +namespace EditStep + +variable {α : Type u} {x y : List α} + +protected theorem symm (h : EditStep x y) : EditStep y x := by + cases h with + | insert p q a => exact .delete p q a + | delete p q a => exact .insert p q a + | substitute p q a b => exact .substitute p q b a + +protected theorem append_left (h : EditStep x y) (p : List α) : + EditStep (p ++ x) (p ++ y) := by + cases h with + | insert q r a => simpa [List.append_assoc] using EditStep.insert (p ++ q) r a + | delete q r a => simpa [List.append_assoc] using EditStep.delete (p ++ q) r a + | substitute q r a b => + simpa [List.append_assoc] using EditStep.substitute (p ++ q) r a b + +protected theorem append_right (h : EditStep x y) (r : List α) : + EditStep (x ++ r) (y ++ r) := by + cases h with + | insert p q a => simpa [List.append_assoc] using EditStep.insert p (q ++ r) a + | delete p q a => simpa [List.append_assoc] using EditStep.delete p (q ++ r) a + | substitute p q a b => + simpa [List.append_assoc] using EditStep.substitute p (q ++ r) a b + +end EditStep + +namespace EditScript + +variable {α : Type u} {x y z : List α} {m n : ℕ} + +protected theorem trans (h : EditScript x y m) (g : EditScript y z n) : + EditScript x z (m + n) := by + induction h with + | nil => simpa using g + | cons h h' ih => simpa [Nat.add_right_comm] using EditScript.cons h (ih g) + +protected theorem one (h : EditStep x y) : EditScript x y 1 := + .cons h (.nil y) + +protected theorem symm (h : EditScript x y n) : EditScript y x n := by + induction h with + | nil => exact .nil _ + | cons h _ ih => exact ih.trans (.one h.symm) + +protected theorem append_left (h : EditScript x y n) (p : List α) : + EditScript (p ++ x) (p ++ y) n := by + induction h with + | nil => exact .nil _ + | cons h _ ih => exact .cons (h.append_left p) ih + +protected theorem append_right (h : EditScript x y n) (p : List α) : + EditScript (x ++ p) (y ++ p) n := by + induction h with + | nil => exact .nil _ + | cons h _ ih => exact .cons (h.append_right p) ih + +protected theorem erase (x : List α) : EditScript x [] x.length := by + induction x with + | nil => exact .nil [] + | cons a x ih => exact .cons (.delete [] x a) ih + +theorem exists_length (x y : List α) : ∃ n, EditScript x y n := + ⟨_, (EditScript.erase x).trans (EditScript.erase y).symm⟩ + +theorem zero_iff : EditScript x y 0 ↔ x = y := by + constructor + · intro h; cases h; rfl + · rintro rfl; exact .nil _ + +end EditScript + +variable {α : Type u} {x y z : List α} + +theorem ed_script (x y : List α) : EditScript x y (ed x y) := + Nat.sInf_mem (EditScript.exists_length x y) + +theorem ed_le_of_script {n : ℕ} (h : EditScript x y n) : ed x y ≤ n := Nat.sInf_le h + +@[simp] theorem ed_self (x : List α) : ed x x = 0 := + Nat.eq_zero_of_le_zero (ed_le_of_script (.nil x)) + +@[simp] theorem ed_eq_zero_iff : ed x y = 0 ↔ x = y := by + constructor + · intro h + have := ed_script x y + rw [h] at this + exact EditScript.zero_iff.mp this + · rintro rfl; exact ed_self _ + +theorem ed_comm (x y : List α) : ed x y = ed y x := by + apply Nat.le_antisymm + · exact ed_le_of_script (ed_script y x).symm + · exact ed_le_of_script (ed_script x y).symm + +theorem ed_triangle (x y z : List α) : ed x z ≤ ed x y + ed y z := + ed_le_of_script ((ed_script x y).trans (ed_script y z)) + +theorem ed_append (x y x' y' : List α) : + ed (x ++ x') (y ++ y') ≤ ed x y + ed x' y' := by + exact ed_le_of_script + (((ed_script x y).append_right x').trans ((ed_script x' y').append_left y)) + +theorem common_lengths_nonempty (x y : List α) : + Set.Nonempty {n : ℕ | ∃ z : List α, z.Sublist x ∧ z.Sublist y ∧ z.length = n} := + ⟨0, [], List.nil_sublist _, List.nil_sublist _, rfl⟩ + +theorem common_lengths_bounded (x y : List α) : + BddAbove {n : ℕ | ∃ z : List α, z.Sublist x ∧ z.Sublist y ∧ z.length = n} := by + refine ⟨x.length, ?_⟩ + rintro n ⟨z, hx, _, rfl⟩ + exact hx.length_le + +theorem exists_lcs (x y : List α) : + ∃ z : List α, z.Sublist x ∧ z.Sublist y ∧ z.length = lcs x y := + Nat.sSup_mem (common_lengths_nonempty x y) (common_lengths_bounded x y) + +theorem length_le_lcs (hx : z.Sublist x) (hy : z.Sublist y) : z.length ≤ lcs x y := + le_csSup (common_lengths_bounded x y) ⟨z, hx, hy, rfl⟩ + +theorem lcs_le_length_left (x y : List α) : lcs x y ≤ x.length := by + obtain ⟨z, hx, _, hz⟩ := exists_lcs x y + exact hz ▸ hx.length_le + +theorem lcs_comm (x y : List α) : lcs x y = lcs y x := by + apply congrArg sSup + ext n + constructor <;> rintro ⟨z, hx, hy, hz⟩ <;> exact ⟨z, hy, hx, hz⟩ + +theorem lcs_le_length_right (x y : List α) : lcs x y ≤ y.length := by + rw [lcs_comm]; exact lcs_le_length_left _ _ + +@[simp] theorem lcs_self (x : List α) : lcs x x = x.length := by + exact Nat.le_antisymm (lcs_le_length_left x x) + (length_le_lcs (List.Sublist.refl x) (List.Sublist.refl x)) + +@[simp] theorem deficit_self (x : List α) : deficit x x = 0 := by simp [deficit] + +theorem deficit_pos_of_ne (h : x.length = y.length) (hne : x ≠ y) : + 1 ≤ deficit x y := by + obtain ⟨z, hx, hy, hz⟩ := exists_lcs x y + have hl := hx.length_le + have hn : z.length ≠ x.length := by + intro hh + exact hne ((hx.eq_of_length hh).symm.trans (hy.eq_of_length (hh.trans h))) + simp only [deficit] + omega + +theorem sublist_erase_one {a : α} {p q z : List α} (h : z.Sublist (p ++ a :: q)) : + ∃ z' : List α, z'.Sublist z ∧ z'.Sublist (p ++ q) ∧ z.length ≤ z'.length + 1 := by + obtain ⟨z₁, z₂, rfl, h₁, h₂⟩ := List.sublist_append_iff.mp h + rcases List.sublist_cons_iff.mp h₂ with h₂ | ⟨r, rfl, hr⟩ + · exact ⟨z₁ ++ z₂, List.Sublist.refl _, h₁.append h₂, Nat.le_succ _⟩ + · refine ⟨z₁ ++ r, (List.Sublist.refl z₁).append ((List.Sublist.refl r).cons a), + h₁.append hr, ?_⟩ + simp only [List.length_append, List.length_cons] + omega + +theorem lcs_step_loss (z : List α) (h : EditStep x y) : lcs z x ≤ lcs z y + 1 := by + obtain ⟨s, hz, hx, hs⟩ := exists_lcs z x + cases h with + | insert p q a => + have hxy : (p ++ q).Sublist (p ++ a :: q) := + (List.Sublist.refl p).append ((List.Sublist.refl q).cons a) + have hh := length_le_lcs hz (hx.trans hxy) + omega + | delete p q a => + obtain ⟨s', hss, hp, hh⟩ := sublist_erase_one hx + have := length_le_lcs (hss.trans hz) hp + omega + | substitute p q a b => + obtain ⟨s', hss, hp, hh⟩ := sublist_erase_one hx + have hpq : (p ++ q).Sublist (p ++ b :: q) := + (List.Sublist.refl p).append ((List.Sublist.refl q).cons b) + have := length_le_lcs (hss.trans hz) (hp.trans hpq) + omega + +theorem lcs_script_loss (z : List α) {n : ℕ} (h : EditScript x y n) : + lcs z x ≤ lcs z y + n := by + induction h with + | nil => simp + | cons h _ ih => have hh := lcs_step_loss z h; omega + +theorem deficit_le_ed (x y : List α) : deficit x y ≤ ed x y := by + have h := lcs_script_loss x (ed_script x y) + simp only [lcs_self] at h + dsimp [deficit] + omega + +theorem sublist_script (h : z.Sublist x) : EditScript x z (x.length - z.length) := by + induction h with + | slnil => exact .nil [] + | @cons l₁ l₂ a h ih => + have hl := h.length_le + have he : (a :: l₂).length - l₁.length = (l₂.length - l₁.length) + 1 := by + simp only [List.length_cons]; omega + rw [he] + exact .cons (.delete [] l₂ a) ih + | cons_cons a h ih => + simpa using ih.append_left [a] + +theorem ed_le_deficits (x y : List α) : + ed x y ≤ (x.length - lcs x y) + (y.length - lcs x y) := by + obtain ⟨z, hx, hy, hz⟩ := exists_lcs x y + simpa [hz] using ed_le_of_script ((sublist_script hx).trans (sublist_script hy).symm) + +theorem ed_le_twice_deficit (h : x.length = y.length) : ed x y ≤ 2 * deficit x y := by + have := ed_le_deficits x y + dsimp [deficit] + omega + +theorem length_encode {P : ℕ} {β : Type v} (c : α → Word β P) (x : List α) : + (encode c x).length = x.length * P := by + induction x with + | nil => simp [encode] + | cons a x ih => + change ((c a).val ++ encode c x).length = (x.length + 1) * P + rw [List.length_append, (c a).property, ih] + ring + +theorem substitution_script (h : x.length = y.length) : EditScript x y x.length := by + induction x generalizing y with + | nil => + have : y = [] := List.length_eq_zero_iff.mp h.symm + subst y; exact .nil [] + | cons a x ih => + cases y with + | nil => simp at h + | cons b y => + have hh : x.length = y.length := by simpa using h + exact .cons (.substitute [] x a b) (by simpa using (ih hh).append_left [b]) + +@[simp] theorem encode_append {P : ℕ} {β : Type v} (c : α → Word β P) (x y : List α) : + encode c (x ++ y) = encode c x ++ encode c y := by simp [encode] + +@[simp] theorem encode_cons {P : ℕ} {β : Type v} (c : α → Word β P) (a : α) (x : List α) : + encode c (a :: x) = (c a).val ++ encode c x := by simp [encode] + +theorem encode_step {P : ℕ} {β : Type v} (c : α → Word β P) (h : EditStep x y) : + EditScript (encode c x) (encode c y) P := by + cases h with + | insert p q a => + simpa [List.append_assoc, (c a).property] using + (((EditScript.erase (c a).val).symm.append_right (encode c q)).append_left (encode c p)) + | delete p q a => + simpa [List.append_assoc, (c a).property] using + (((EditScript.erase (c a).val).append_right (encode c q)).append_left (encode c p)) + | substitute p q a b => + have hh := substitution_script ((c a).property.trans (c b).property.symm) + simpa [List.append_assoc, (c a).property] using + ((hh.append_right (encode c q)).append_left (encode c p)) + +theorem encode_script {P n : ℕ} {β : Type v} (c : α → Word β P) (h : EditScript x y n) : + EditScript (encode c x) (encode c y) (P * n) := by + induction h with + | nil => simpa using EditScript.nil (encode c _) + | cons h _ ih => + simpa [Nat.mul_add, Nat.add_comm] using (encode_step c h).trans ih + +theorem ed_encode_le {P : ℕ} {β : Type v} (c : α → Word β P) (x y : List α) : + ed (encode c x) (encode c y) ≤ P * ed x y := + ed_le_of_script (encode_script c (ed_script x y)) + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/FiniteFourier.lean b/lean/OAI/Combinatorics/TreeEdit/FiniteFourier.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d8bdac40eb931baf597986ef90737390777b80b --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/FiniteFourier.lean @@ -0,0 +1,472 @@ +import OAI.Combinatorics.TreeEdit.EditMetric + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace FiniteFourier + +open scoped ComplexConjugate +open RCLike + +variable {A : Type*} [Fintype A] [AddCommGroup A] + +noncomputable def coefficient (f : A → ℂ) (χ : AddChar A ℂ) : ℂ := + (AddChar.complexBasis A).repr f χ + +lemma expansion (f : A → ℂ) (x : A) : + ∑ χ : AddChar A ℂ, coefficient f χ * χ x = f x := by + simpa [coefficient, AddChar.complexBasis_apply, Pi.smul_apply, smul_eq_mul] + using congr_fun ((AddChar.complexBasis A).sum_repr f) x + +omit [AddCommGroup A] in +lemma weighted_sum_right {ι : Type*} (s : Finset ι) (f : A → ℂ) (g : ι → A → ℂ) : + ⟪f, ∑ i ∈ s, g i⟫ₙ_[ℂ] = ∑ i ∈ s, ⟪f, g i⟫ₙ_[ℂ] := by + simp only [wInner, Finset.sum_apply, inner_sum, Finset.smul_sum] + exact Finset.sum_comm + +omit [AddCommGroup A] in +lemma weighted_sum_left {ι : Type*} (s : Finset ι) (f : ι → A → ℂ) (g : A → ℂ) : + ⟪∑ i ∈ s, f i, g⟫ₙ_[ℂ] = ∑ i ∈ s, ⟪f i, g⟫ₙ_[ℂ] := by + simp only [wInner, Finset.sum_apply, sum_inner, Finset.smul_sum] + exact Finset.sum_comm + +lemma coefficient_inner (f : A → ℂ) (χ : AddChar A ℂ) : + coefficient f χ = ⟪(χ : A → ℂ), f⟫ₙ_[ℂ] := by + classical + conv_rhs => rw [← (AddChar.complexBasis A).sum_repr f] + simp only [weighted_sum_right, AddChar.complexBasis_apply, + wInner_smul_right, smul_eq_mul, AddChar.wInner_cWeight_eq_boole] + simp [coefficient] + +lemma parseval_complex (f : A → ℂ) : + ⟪f, f⟫ₙ_[ℂ] = ∑ χ : AddChar A ℂ, + conj (coefficient f χ) * coefficient f χ := by + conv_lhs => lhs; rw [← (AddChar.complexBasis A).sum_repr f] + simp only [weighted_sum_left, AddChar.complexBasis_apply, wInner_smul_left, + smul_eq_mul, ← coefficient_inner, starRingEnd_apply, coefficient] + +lemma coefficient_translate (f : A → ℂ) (z : A) (χ : AddChar A ℂ) : + coefficient (fun x => f (x + z) - f x) χ = coefficient f χ * (χ z - 1) := by + classical + have hexp : (fun x => f (x + z) - f x) = + ∑ ψ : AddChar A ℂ, (coefficient f ψ * (ψ z - 1)) • (ψ : A → ℂ) := by + funext x + simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + rw [← expansion f (x + z), ← expansion f x, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro ψ _ + rw [AddChar.map_add_eq_mul] + ring + rw [hexp, coefficient_inner, weighted_sum_right] + simp only [wInner_smul_right, smul_eq_mul, AddChar.wInner_cWeight_eq_boole] + simp + +lemma parseval (f : A → ℂ) : + (Fintype.card A : ℝ)⁻¹ * ∑ x, ‖f x‖ ^ 2 = + ∑ χ : AddChar A ℂ, ‖coefficient f χ‖ ^ 2 := by + have h := congr_arg Complex.re (parseval_complex f) + have hn (z : ℂ) : (conj z * z).re = ‖z‖ ^ 2 := by + simp [Complex.mul_re, Complex.sq_norm, Complex.normSq_apply] + simpa only [wInner, cWeight, Function.const_apply, map_sum, Complex.re_sum, + Complex.real_smul, Complex.mul_re, Complex.ofReal_re, Complex.ofReal_im, + zero_mul, sub_zero, inner_self_eq_norm_sq_to_K, RCLike.ofReal_real_eq_id, + id_eq, RCLike.ofReal_eq_complex_ofReal, ← Complex.ofReal_pow, Complex.ofReal_re, ← Finset.mul_sum, hn] using h + +lemma displacement_parseval (f : A → ℂ) (z : A) : + (Fintype.card A : ℝ)⁻¹ * ∑ x, ‖f (x + z) - f x‖ ^ 2 = + ∑ χ : AddChar A ℂ, ‖1 - χ z‖ ^ 2 * ‖coefficient f χ‖ ^ 2 := by + rw [parseval] + apply Finset.sum_congr rfl + intro χ _ + rw [coefficient_translate, norm_mul, mul_pow, norm_sub_rev] + ring + +noncomputable def multiplier (χ : AddChar A ℂ) (z : A) : ℝ := ‖1 - χ z‖ ^ 2 + +omit [Fintype A] in +@[simp] lemma multiplier_zero (z : A) : multiplier (0 : AddChar A ℂ) z = 0 := by + simp [multiplier] + +omit [Fintype A] in +lemma multiplier_nonneg (χ : AddChar A ℂ) (z : A) : 0 ≤ multiplier χ z := sq_nonneg _ + +noncomputable def average (f : A → ℝ) : ℝ := (Fintype.card A : ℝ)⁻¹ * ∑ x, f x + +def HasSpectrum (V : A → ℝ) : Prop := + ∃ H : AddChar A ℂ → ℝ, (∀ χ, 0 ≤ H χ) ∧ H 0 = 0 ∧ + ∀ z, V z = ∑ χ, multiplier χ z * H χ + +lemma spectrum_zero : HasSpectrum (fun _ : A => 0) := by + exact ⟨fun _ => 0, by simp, rfl, by simp⟩ + +lemma HasSpectrum.add {V W : A → ℝ} (hV : HasSpectrum V) (hW : HasSpectrum W) : + HasSpectrum (fun z => V z + W z) := by + obtain ⟨H, hH, hH0, heH⟩ := hV + obtain ⟨K, hK, hK0, heK⟩ := hW + refine ⟨fun χ => H χ + K χ, fun χ => add_nonneg (hH χ) (hK χ), by simp [hH0, hK0], ?_⟩ + intro z + simp [heH, heK, mul_add, Finset.sum_add_distrib] + +lemma HasSpectrum.mul {V : A → ℝ} (hV : HasSpectrum V) {c : ℝ} (hc : 0 ≤ c) : + HasSpectrum (fun z => c * V z) := by + obtain ⟨H, hH, hH0, heH⟩ := hV + refine ⟨fun χ => c * H χ, fun χ => mul_nonneg hc (hH χ), by simp [hH0], ?_⟩ + intro z + simp only [heH, Finset.mul_sum] + apply Finset.sum_congr rfl + intro χ _ + ring + +lemma cut_spectrum (U : A → Bool) : + HasSpectrum (fun z => average (fun x => |(if U (x + z) then 1 else 0 : ℝ) - + (if U x then 1 else 0)|)) := by + classical + let f : A → ℂ := fun x => if U x then 1 else 0 + refine ⟨fun χ => if χ = 0 then 0 else ‖coefficient f χ‖ ^ 2, ?_, by simp, ?_⟩ + · intro χ; dsimp; split_ifs <;> positivity + · intro z + have hd (x : A) : |(if U (x + z) then 1 else 0 : ℝ) - (if U x then 1 else 0)| = + ‖f (x + z) - f x‖ ^ 2 := by + dsimp [f] + cases U (x + z) <;> cases U x <;> norm_num + simp only [average, hd] + rw [displacement_parseval] + apply Finset.sum_congr rfl + intro χ _ + by_cases h : χ = 0 + · subst χ; simp [multiplier] + · simp [h, multiplier] + +lemma scalar_spectrum_aux (s : Finset ℝ) : + ∀ g : A → ℝ, (∀ x, g x ∈ s) → + HasSpectrum (fun z => average (fun x => |g (x + z) - g x|)) := by + classical + induction s using Finset.induction_on_min with + | empty => + intro g hg + simpa using hg 0 + | insert a s hmin ih => + intro g hg + by_cases hs : s.Nonempty + · let b := s.min' hs + have hb : b ∈ s := s.min'_mem hs + have hab : a < b := hmin b hb + let g' : A → ℝ := fun x => if g x = a then b else g x + let U : A → Bool := fun x => decide (g x ≠ a) + have hg' (x : A) : g' x ∈ s := by + dsimp [g'] + split_ifs with h + · exact hb + · exact (Finset.mem_insert.mp (hg x)).resolve_left h + have hlow (x : A) (hx : g x ≠ a) : b ≤ g x := + s.min'_le _ ((Finset.mem_insert.mp (hg x)).resolve_left hx) + have hid (x y : A) : |g x - g y| = |g' x - g' y| + + (b - a) * |(if U x then 1 else 0 : ℝ) - (if U y then 1 else 0)| := by + by_cases hx : g x = a <;> by_cases hy : g y = a + · simp [g', U, hx, hy] + · have hby := hlow y hy + simp only [g', U, hx, hy, ↓reduceIte, ne_eq, decide_eq_true_eq, + not_true_eq_false, not_false_eq_true, + zero_sub, abs_neg, abs_one, mul_one] + rw [abs_of_nonpos (by linarith), abs_of_nonpos (by linarith)] + ring + · have hbx := hlow x hx + simp only [g', U, hy, hx, ↓reduceIte, ne_eq, decide_eq_true_eq, + not_true_eq_false, not_false_eq_true, sub_zero, abs_one, mul_one] + rw [abs_of_nonneg (by linarith), abs_of_nonneg (by linarith)] + ring + · simp [g', U, hx, hy] + have hspec := (ih g' hg').add ((cut_spectrum U).mul (sub_nonneg.mpr hab.le)) + convert hspec using 1 + funext z + simp only [average, hid, Finset.sum_add_distrib, ← Finset.mul_sum] + ring + · have he : s = ∅ := Finset.not_nonempty_iff_eq_empty.mp hs + have hc (x : A) : g x = a := by simpa [he] using hg x + simpa [hc, average] using (spectrum_zero (A := A)) + +lemma scalar_spectrum (g : A → ℝ) : + HasSpectrum (fun z => average (fun x => |g (x + z) - g x|)) := by + classical + apply scalar_spectrum_aux (Finset.univ.image g) + intro x + exact Finset.mem_image.mpr ⟨x, Finset.mem_univ _, rfl⟩ + +lemma multiplier_eq (χ : AddChar A ℂ) (z : A) : + multiplier χ z = 2 - 2 * (χ z).re := by + rw [multiplier, Complex.sq_norm, Complex.normSq_sub] + norm_num [Complex.normSq_eq_norm_sq, χ.norm_apply] + +lemma average_const (c : ℝ) : average (fun _ : A => c) = c := by + have hn : (Fintype.card A : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + simp [average, hn] + +lemma average_nonneg {f : A → ℝ} (hf : ∀ x, 0 ≤ f x) : 0 ≤ average f := by + exact mul_nonneg (by positivity) (Finset.sum_nonneg fun x _ => hf x) + +lemma average_le_const {f : A → ℝ} {c : ℝ} (hf : ∀ x, f x ≤ c) : average f ≤ c := by + rw [← average_const (A := A) c] + exact mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun x _ => hf x) (by positivity) + +lemma average_multiplier (χ : AddChar A ℂ) : + average (multiplier χ) = if χ = 0 then 0 else 2 := by + classical + by_cases hχ : χ = 0 + · subst χ; simp [average] + · have hs : ∑ z, (χ z).re = 0 := by + simpa [Complex.re_sum, hχ] using congr_arg Complex.re (χ.sum_eq_ite) + have hn : (Fintype.card A : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + simp [average, multiplier_eq, Finset.sum_sub_distrib, ← Finset.mul_sum, hs, hχ, hn] + +lemma spectrum_total {V : A → ℝ} {H : AddChar A ℂ → ℝ} + (hH0 : H 0 = 0) (he : ∀ z, V z = ∑ χ, multiplier χ z * H χ) : + average V = 2 * ∑ χ, H χ := by + classical + calc + average V = ∑ χ, average (multiplier χ) * H χ := by + simp only [average, he, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro χ _ + simp only [Finset.sum_mul] + apply Finset.sum_congr rfl + intro x _ + ring + _ = 2 * ∑ χ, H χ := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro χ _ + rw [average_multiplier] + split_ifs with h + · subst χ; simp [hH0] + · rfl + +lemma scalar_spectrum_bounded (g : A → ℝ) : + ∃ H : AddChar A ℂ → ℝ, (∀ χ, 0 ≤ H χ) ∧ H 0 = 0 ∧ + (∀ χ, H χ ≤ ∑ x, |g x|) ∧ + ∀ z, average (fun x => |g (x + z) - g x|) = ∑ χ, multiplier χ z * H χ := by + obtain ⟨H, hH, hH0, he⟩ := scalar_spectrum g + refine ⟨H, hH, hH0, ?_, he⟩ + have hle : average (fun z => average (fun x => |g (x + z) - g x|)) ≤ 2 * ∑ x, |g x| := by + apply average_le_const + intro z + apply average_le_const + intro x + have h1 : |g (x + z)| ≤ ∑ y, |g y| := + Finset.single_le_sum (fun y _ => abs_nonneg (g y)) (Finset.mem_univ _) + have h2 : |g x| ≤ ∑ y, |g y| := + Finset.single_le_sum (fun y _ => abs_nonneg (g y)) (Finset.mem_univ _) + have htri := abs_sub (g (x + z)) (g x) + linarith + rw [spectrum_total hH0 he] at hle + intro χ + have hsingle : H χ ≤ ∑ ψ, H ψ := + Finset.single_le_sum (fun ψ _ => hH ψ) (Finset.mem_univ _) + linarith + +omit [Fintype A] [AddCommGroup A] in +lemma l1_distance_series (v w : RealL1) : + dist v w = ∑' j : ℕ, |v j - w j| := by + rw [dist_eq_norm, lp.norm_eq_tsum_rpow (by norm_num : (0 : ℝ) < (1 : ENNReal).toReal)] + simp [Real.norm_eq_abs] + +omit [Fintype A] [AddCommGroup A] in +lemma l1_coordinate_summable (v : RealL1) : Summable (fun j : ℕ => |v j|) := by + simpa [Real.norm_eq_abs] using (lp.memℓp v).summable (by norm_num : (0 : ℝ) < (1 : ENNReal).toReal) + +omit [Fintype A] [AddCommGroup A] in +lemma l1_distance_summable (v w : RealL1) : Summable (fun j : ℕ => |v j - w j|) := by + simpa [lp.coeFn_sub] using l1_coordinate_summable (v - w) + +theorem l1_displacement_spectrum (F : A → RealL1) : + HasSpectrum (fun z => average (fun x => dist (F (x + z)) (F x))) := by + classical + choose H hH hH0 hHb he using fun j : ℕ => scalar_spectrum_bounded (fun x => F x j) + have hs : Summable (fun j : ℕ => ∑ x, |F x j|) := + summable_sum fun x _ => l1_coordinate_summable (F x) + have hHs (χ : AddChar A ℂ) : Summable (fun j : ℕ => H j χ) := + Summable.of_nonneg_of_le (fun j => hH j χ) (fun j => hHb j χ) hs + refine ⟨fun χ => ∑' j, H j χ, fun χ => tsum_nonneg (fun j => hH j χ), by simp [hH0], ?_⟩ + intro z + have hd (x : A) : Summable (fun j : ℕ => |F (x + z) j - F x j|) := + l1_distance_summable _ _ + calc + average (fun x => dist (F (x + z)) (F x)) = + ∑' j : ℕ, average (fun x => |F (x + z) j - F x j|) := by + simp only [average, l1_distance_series] + rw [Summable.tsum_mul_left _ (summable_sum fun x _ => hd x), + Summable.tsum_finsetSum (fun x _ => hd x)] + _ = ∑' j : ℕ, ∑ χ, multiplier χ z * H j χ := by simp only [he] + _ = ∑ χ, multiplier χ z * ∑' j : ℕ, H j χ := by + rw [Summable.tsum_finsetSum (fun χ _ => (hHs χ).mul_left _)] + simp only [Summable.tsum_mul_left _ (hHs _)] + +end FiniteFourier + +namespace FiniteFourier + +variable {A B : Type*} [Fintype A] [Fintype B] [AddCommGroup A] [AddCommGroup B] + +noncomputable def energy (H : AddChar A ℂ → ℝ) (z : A) : ℝ := + ∑ χ, multiplier χ z * H χ + +lemma multiplier_le_four (χ : AddChar A ℂ) (z : A) : multiplier χ z ≤ 4 := by + have hn : ‖1 - χ z‖ ≤ 2 := by + have hh := norm_sub_le (1 : ℂ) (χ z) + rw [norm_one, χ.norm_apply] at hh + norm_num at hh + exact hh + dsimp [multiplier] + nlinarith [norm_nonneg (1 - χ z)] + +lemma energy_nonneg {H : AddChar A ℂ → ℝ} (hH : ∀ χ, 0 ≤ H χ) (z : A) : + 0 ≤ energy H z := Finset.sum_nonneg fun χ _ => mul_nonneg (multiplier_nonneg χ z) (hH χ) + +noncomputable def pushSpectrum (H : AddChar A ℂ → ℝ) (f : B →+ A) (η : AddChar B ℂ) : ℝ := + ∑ χ, if χ.compAddMonoidHom f = η then H χ else 0 + +omit [Fintype B] in +lemma pushSpectrum_nonneg {H : AddChar A ℂ → ℝ} (hH : ∀ χ, 0 ≤ H χ) (f : B →+ A) : + ∀ η, 0 ≤ pushSpectrum H f η := by + classical + intro η + exact Finset.sum_nonneg fun χ _ => by split_ifs; exact hH χ; rfl + +lemma pushSpectrum_sum (H : AddChar A ℂ → ℝ) (f : B →+ A) (g : AddChar B ℂ → ℝ) : + ∑ η, g η * pushSpectrum H f η = ∑ χ, g (χ.compAddMonoidHom f) * H χ := by + classical + simp only [pushSpectrum, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro χ _ + rw [Finset.sum_eq_single (χ.compAddMonoidHom f)] + · simp + · intro η _ hη; simp [Ne.symm hη] + · simp + +lemma energy_push (H : AddChar A ℂ → ℝ) (f : B →+ A) (z : B) : + energy (pushSpectrum H f) z = energy H (f z) := by + rw [energy, pushSpectrum_sum] + rfl + +lemma average_energy (H : AddChar A ℂ → ℝ) : + average (energy H) = 2 * ∑ χ, if χ = 0 then 0 else H χ := by + classical + calc + _ = ∑ χ, average (multiplier χ) * H χ := by + simp only [average, energy, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro χ _ + simp only [Finset.sum_mul] + apply Finset.sum_congr rfl + intro x _ + ring + _ = _ := by + simp only [average_multiplier, Finset.mul_sum] + apply Finset.sum_congr rfl + intro χ _ + split_ifs <;> ring + +lemma sum_multiplier_period (χ : AddChar A ℂ) (v : A) (n : ℕ) + (hne : χ v ≠ 1) (hper : (χ v) ^ n = 1) : + ∑ s ∈ Finset.range n, multiplier χ ((s + 1) • v) = 2 * n := by + have hs : ∑ s ∈ Finset.range n, (χ v) ^ s = 0 := by + have hh := geom_sum_mul (χ v) n + rw [hper, sub_self] at hh + exact (mul_eq_zero.mp hh).resolve_right (sub_ne_zero.mpr hne) + have hs' : ∑ s ∈ Finset.range n, χ ((s + 1) • v) = 0 := by + simp only [AddChar.map_nsmul_eq_pow, pow_succ, ← Finset.sum_mul, hs, zero_mul] + have hr : ∑ s ∈ Finset.range n, (χ ((s + 1) • v)).re = 0 := by + simpa only [Complex.re_sum, Complex.zero_re] using congrArg Complex.re hs' + simp only [multiplier_eq, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_range, + nsmul_eq_mul, ← Finset.mul_sum, hr, mul_zero, sub_zero] + ring + +lemma period_detect (χ : AddChar A ℂ) (v : A) {n J : ℕ} + (hn : 0 < n) (hJ : 2 * n ≤ J) (hne : χ v ≠ 1) (hper : (χ v) ^ n = 1) : + (J : ℝ) ≤ ∑ s ∈ Finset.range J, multiplier χ ((s + 1) • v) := by + let N := n * (J / n) + have hN : N ≤ J := Nat.mul_div_le J n + have hcount : J ≤ 2 * N := by + have hm := Nat.mod_lt J hn + have he := Nat.mod_add_div J n + dsimp [N] + omega + have hperN : (χ v) ^ N = 1 := by simp [N, pow_mul, hper] + calc + (J : ℝ) ≤ 2 * N := by exact_mod_cast hcount + _ = ∑ s ∈ Finset.range N, multiplier χ ((s + 1) • v) := + (sum_multiplier_period χ v N hne hperN).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono hN) + (fun s _ _ => multiplier_nonneg χ ((s + 1) • v)) + +end FiniteFourier + +namespace FiniteFourier + +variable {A B : Type*} [Fintype A] [Fintype B] [AddCommGroup A] [AddCommGroup B] + +noncomputable def active (χ : AddChar A ℂ) (v : A) : ℝ := if χ v = 1 then 0 else 1 + +noncomputable def activeMass (H : AddChar A ℂ → ℝ) (v : A) : ℝ := + ∑ χ, active χ v * H χ + +omit [Fintype A] in +lemma active_nonneg (χ : AddChar A ℂ) (v : A) : 0 ≤ active χ v := by + unfold active; split_ifs <;> norm_num + +lemma activeMass_nonneg {H : AddChar A ℂ → ℝ} (hH : ∀ χ, 0 ≤ H χ) (v : A) : + 0 ≤ activeMass H v := Finset.sum_nonneg fun χ _ => mul_nonneg (active_nonneg χ v) (hH χ) + +lemma activeMass_push (H : AddChar A ℂ → ℝ) (f : B →+ A) (v : B) : + activeMass (pushSpectrum H f) v = ∑ χ, active χ (f v) * H χ := by + rw [activeMass, pushSpectrum_sum] + rfl + +lemma energy_le_mass {H : AddChar A ℂ → ℝ} (hH : ∀ χ, 0 ≤ H χ) (v : A) : + energy H v ≤ 4 * activeMass H v := by + classical + rw [energy, activeMass, Finset.mul_sum] + apply Finset.sum_le_sum + intro χ _ + by_cases hv : χ v = 1 + · simp [multiplier, active, hv] + · have hh := mul_le_mul_of_nonneg_right (multiplier_le_four χ v) (hH χ) + simpa [active, hv] using hh + +lemma twice_activeMass_le_average {H : AddChar A ℂ → ℝ} (hH : ∀ χ, 0 ≤ H χ) (v : A) : + 2 * activeMass H v ≤ average (energy H) := by + classical + rw [average_energy, activeMass] + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Finset.sum_le_sum + intro χ _ + by_cases hχ : χ = 0 + · subst χ; simp [active] + · by_cases hv : χ v = 1 + · simpa [active, hv, hχ] using hH χ + · simp [active, hv, hχ] + +end FiniteFourier + +namespace FiniteFourier + +variable {A : Type*} [Fintype A] [AddCommGroup A] + +lemma average_mono {f g : A → ℝ} (h : ∀ x, f x ≤ g x) : average f ≤ average g := by + exact mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun x _ => h x) (by positivity) + +lemma average_le {f : A → ℝ} {C : ℝ} (h : ∀ x, f x ≤ C) : average f ≤ C := + (average_mono h).trans_eq (average_const C) + +end FiniteFourier + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/FiniteLowerBound.lean b/lean/OAI/Combinatorics/TreeEdit/FiniteLowerBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..42a806977916330df493feca161cce68ac15d9ca --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/FiniteLowerBound.lean @@ -0,0 +1,55 @@ +import OAI.Combinatorics.TreeEdit.FiniteParameters +import OAI.Combinatorics.TreeEdit.CapInversion + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace FiniteTree + +lemma length_log_bound {k : ℕ} (hk : 20 ≤ k) : + Real.log (binaryLength k : ℝ) ≤ 100 * (k : ℝ) ^ 2 * Real.log k := by + have hkpos : (0 : ℝ) < k := by exact_mod_cast (by omega : 0 < k) + have hk1 : (1 : ℝ) ≤ k := by exact_mod_cast (by omega : 1 ≤ k) + have hl0 : 0 ≤ Real.log (k : ℝ) := Real.log_nonneg hk1 + have hl20 : Real.log 20 ≤ Real.log (k : ℝ) := Real.log_le_log (by norm_num) (by exact_mod_cast hk) + simp only [binaryLength, wordLength, branching, repetitions, Nat.cast_pow, Nat.cast_mul, + Nat.cast_ofNat, Real.log_pow] + rw [Real.log_mul (by positivity) (by positivity), Real.log_mul (by norm_num) (by positivity), + Real.log_pow] + push_cast + calc + _ ≤ 3 * ((k : ℝ) * (Real.log k + Real.log k + (20 * k) * Real.log k)) := by + gcongr + _ = (6 * k + 60 * (k : ℝ) ^ 2) * Real.log k := by ring + _ ≤ _ := by + apply mul_le_mul_of_nonneg_right _ hl0 + nlinarith + +lemma binaryLength_ge {k : ℕ} (hk : 2 ≤ k) : k ≤ binaryLength k := by + have hM := wordLength_upper_start hk + calc + k ≤ wordLength k := hM + _ = wordLength k ^ 1 := by simp + _ ≤ binaryLength k := pow_le_pow_right₀ (by omega) (by omega) + +end FiniteTree + +theorem binary_finite : BinaryLowerBound := by + apply all_caps_of_witnesses (N := FiniteTree.binaryLength) (A := 100) (by norm_num) + filter_upwards [FiniteTree.witnesses_eventually, + eventually_exponential_lower (b := 4) (C := 32160) (by norm_num) (by norm_num) 0, + Filter.eventually_ge_atTop 20] with k hw he hk + obtain ⟨W, hW, hlen, hD⟩ := hw + refine ⟨FiniteTree.binaryLength_ge (by omega), FiniteTree.length_log_bound hk, + W, hW, hlen, ?_⟩ + simp only [pow_zero, mul_one] at he + exact he.trans hD + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/FiniteParameters.lean b/lean/OAI/Combinatorics/TreeEdit/FiniteParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..92bb699ac585b9c0fe468ac5ac57f6db0199a1f1 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/FiniteParameters.lean @@ -0,0 +1,205 @@ +import OAI.Combinatorics.TreeEdit.FinitePrimes +import OAI.Combinatorics.TreeEdit.FiniteSpectrum +import OAI.Combinatorics.TreeEdit.DistortionTransfer +import OAI.Combinatorics.TreeEdit.RandomCode + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace FiniteTree + +variable {m : ℕ} {p : ℕ → Fin m → ℕ} [∀ j i, NeZero (p j i)] + +lemma symbol_card_bound {h q U : ℕ} [NeZero q] + (hp : ∀ j, j < h → ∀ i, p j i ≤ U) : + Fintype.card (Symbol m p h q) ≤ m ^ h * q * U ^ h := by + induction h generalizing q with + | zero => simp [Symbol, ZMod.card] + | succ h ih => + change Fintype.card (Σ i : Fin m, Symbol m p h (q * p h i)) ≤ _ + rw [Fintype.card_sigma] + calc + _ ≤ ∑ _i : Fin m, m ^ h * (q * U) * U ^ h := by + apply Finset.sum_le_sum + intro i _ + calc + _ ≤ m ^ h * (q * p h i) * U ^ h := ih (fun j hj => hp j (by omega)) + _ ≤ _ := by gcongr; exact hp h (by omega) i + _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, Nat.cast_id, pow_succ]; ring + +omit [∀ j i, NeZero (p j i)] in +lemma symbol_nonempty {h q : ℕ} (hm : 0 < m) : Nonempty (Symbol m p h q) := by + induction h generalizing q with + | zero => exact ⟨0⟩ + | succ h ih => exact ⟨⟨⟨0, hm⟩, Classical.choice (ih (q := q * p h ⟨0, hm⟩))⟩⟩ + +theorem displacement_bound {T h q K U Qcap J : ℕ} [NeZero q] + (hK : 1 ≤ K) (hU : 1 ≤ U) (hp : ∀ j, j < h → ∀ i, p j i ≤ U) + (hq : q * U ^ h ≤ Qcap) (hJ : 2 * (Qcap * U ^ K) ≤ J) + (hJT : J ≤ T) (hJpos : 0 < J) + (F : State m p h q → RealL1) (C : ℝ) (hC : 0 ≤ C) + (hlip : ∀ x y, dist (F x) (F y) ≤ C * ed (word p T h q x).val (word p T h q y).val) : + FiniteFourier.average (fun x => dist (F x) (F (x + w p h q))) ≤ + C * length m T h * (4 * ((K : ℝ)⁻¹ ^ h + 2 * h * J / T)) := by + obtain ⟨H, hH, _, he⟩ := FiniteFourier.l1_displacement_spectrum F + have hbound : SpectralBound T h q H C := by + intro z b hb + rw [FiniteFourier.energy, ← he] + apply FiniteFourier.average_le + intro x + rw [dist_comm] + exact (hlip x (x + z)).trans (mul_le_mul_of_nonneg_left (hb x) hC) + have hh := mass_bound hH hC hbound hK hU hp hq hJ hJT hJpos + calc + _ = FiniteFourier.energy H (w p h q) := by simpa only [dist_comm, FiniteFourier.energy] using he (w p h q) + _ ≤ 4 * FiniteFourier.activeMass H (w p h q) := FiniteFourier.energy_le_mass hH _ + _ ≤ 4 * (C * length m T h * ((K : ℝ)⁻¹ ^ h + 2 * h * J / T)) := by gcongr + _ = _ := by ring + +end FiniteTree + +namespace FiniteTree + +def branching (k : ℕ) : ℕ := 20 * k +def repetitions (k : ℕ) : ℕ := k ^ (20 * k) +def wordLength (k : ℕ) : ℕ := (branching k * repetitions k) ^ k +def binaryLength (k : ℕ) : ℕ := wordLength k ^ 3 + +lemma wordLength_upper_start {k : ℕ} (hk : 2 ≤ k) : k ≤ wordLength k := by + have hT : 1 ≤ repetitions k := Nat.one_le_pow _ _ (by omega) + have hbase : k ≤ branching k * repetitions k := by + exact (show k ≤ branching k by dsimp [branching]; omega).trans (Nat.le_mul_of_pos_right _ hT) + calc + k ≤ branching k * repetitions k := hbase + _ = (branching k * repetitions k) ^ 1 := by simp + _ ≤ wordLength k := pow_le_pow_right₀ (by omega) (by omega) + +lemma parameter_gap {k : ℕ} (hk : 2 ≤ k) : + 4 * k ^ (10 * k) ≤ repetitions k ∧ 2 * k ^ 5 ≤ repetitions k := by + have hk1 : 1 ≤ k := by omega + have h4 : 4 ≤ k ^ (10 * k) := by + calc + 4 ≤ k ^ 2 := by nlinarith + _ ≤ k ^ (10 * k) := pow_le_pow_right₀ hk1 (by omega) + have hpow : repetitions k = k ^ (10 * k) * k ^ (10 * k) := by + rw [repetitions, ← pow_add] + congr 1 + omega + constructor + · rw [hpow] + exact Nat.mul_le_mul_right _ h4 + · calc + 2 * k ^ 5 ≤ k * k ^ 5 := Nat.mul_le_mul_right _ hk + _ = k ^ 6 := by ring + _ ≤ repetitions k := pow_le_pow_right₀ hk1 (by omega) + +lemma spectral_coefficient {k : ℕ} (hk : 2 ≤ k) : + 4 * ((k : ℝ)⁻¹ ^ k + 2 * k * (4 * k ^ (10 * k)) / k ^ (20 * k)) ≤ + 40 * (k : ℝ)⁻¹ ^ k := by + have hk1 : (1 : ℝ) ≤ k := by exact_mod_cast (by omega : 1 ≤ k) + have hkpos : (0 : ℝ) < k := by exact_mod_cast (by omega : 0 < k) + have hp : (k : ℝ) ^ (k + 1) ≤ (k : ℝ) ^ (10 * k) := pow_le_pow_right₀ hk1 (by omega) + have hp20 : (k : ℝ) ^ (20 * k) = (k : ℝ) ^ (10 * k) * (k : ℝ) ^ (10 * k) := by + rw [← pow_add] + congr 1 + omega + have he : 2 * (k : ℝ) * (4 * k ^ (10 * k)) / k ^ (20 * k) = 8 * k / k ^ (10 * k) := by + rw [hp20] + field_simp + ring + rw [he] + have hh : 8 * (k : ℝ) / k ^ (10 * k) ≤ 8 * (k : ℝ)⁻¹ ^ k := by + rw [inv_pow, ← div_eq_mul_inv] + apply (div_le_div_iff₀ (by positivity) (by positivity)).mpr + rw [pow_succ] at hp + nlinarith + have hh0 : 0 ≤ (k : ℝ)⁻¹ ^ k := by positivity + linarith + +theorem witnesses_eventually : ∀ᶠ k : ℕ in Filter.atTop, + ∃ W : Finset (List Bool), 2 ≤ W.card ∧ (∀ w ∈ W, w.length = binaryLength k) ∧ + ((k : ℝ) / 4) ^ k / 32160 ≤ c1 W := by + obtain ⟨M₀, hconvert⟩ := binary_conversion + filter_upwards [PrimeSupply.finite_lists_eventually, Filter.eventually_ge_atTop 2, + Filter.eventually_ge_atTop M₀] with k hprimes hk hkM + obtain ⟨p, hp0, ha, hp⟩ := hprimes + have : ∀ (j : ℕ) (i : Fin (20 * k)), NeZero (p j i) := fun j i => ⟨ne_of_gt (hp0 j i)⟩ + let : Fintype (Symbol (20 * k) p k 2) := symbolFintype p hp0 k 2 (by omega) + let : Fintype (State (20 * k) p k 2) := stateFintype p hp0 k 2 (by omega) + let T := repetitions k + let M := length (20 * k) T k + have hM : M = wordLength k := length_eq (20 * k) T k + have hm : 0 < 20 * k := by omega + have hT : 0 < T := pow_pos (by omega) _ + have hkp : 0 < k := by omega + have hMge : k ≤ M := hM ▸ wordLength_upper_start hk + have hMpos : 0 < M := hkp.trans_le hMge + have hcardpos : 1 ≤ Fintype.card (Symbol (20 * k) p k 2) := by + exact Nat.one_le_iff_ne_zero.mpr (ne_of_gt (Fintype.card_pos_iff.mpr (symbol_nonempty hm))) + have hcard : Fintype.card (Symbol (20 * k) p k 2) ≤ M := by + calc + _ ≤ (20 * k) ^ k * 2 * (k ^ 5) ^ k := symbol_card_bound hp + _ ≤ (20 * k) ^ k * (2 ^ k * (k ^ 5) ^ k) := by + have hh : 2 ≤ 2 ^ k := by + calc 2 = 2 ^ 1 := by norm_num + _ ≤ 2 ^ k := pow_le_pow_right₀ (by omega) (by omega) + calc + _ = (20 * k) ^ k * (2 * (k ^ 5) ^ k) := by ring + _ ≤ _ := by gcongr + _ = (20 * k) ^ k * (2 * k ^ 5) ^ k := by simp only [mul_pow, mul_assoc] + _ ≤ (20 * k) ^ k * T ^ k := by gcongr; exact (parameter_gap hk).2 + _ = M := by + change (20 * k) ^ k * T ^ k = length (20 * k) T k + simp only [length_eq, mul_pow, mul_assoc] + obtain ⟨c, hc⟩ := hconvert M (hkM.trans hMge) (Symbol (20 * k) p k 2) hcardpos hcard + have hsep (x : State (20 * k) p k 2) : (Nat.cast M : ℝ) ≤ (4 : ℝ) ^ k * + ed (word p T k 2 x).val (word p T k 2 (x + w p k 2)).val := by + have hTbound : T ≤ (k ^ 4) ^ (10 * k) := by + change k ^ (20 * k) ≤ (k ^ 4) ^ (10 * k) + rw [← pow_mul] + exact pow_le_pow_right₀ (by omega) (by omega) + have hh := separation (m := 20 * k) (s := 10 * k) (T := T) + (by omega) (by omega) hT (Nat.one_le_pow _ _ (by omega)) hTbound ha x 1 (by norm_num) + simp only [one_zsmul] at hh + exact hh.trans (mul_le_mul_of_nonneg_left (by exact_mod_cast deficit_le_ed _ _) (by positivity)) + have hobs (F : State (20 * k) p k 2 → RealL1) (C : ℝ) (hC : 0 ≤ C) + (hlip : ∀ x y, dist (F x) (F y) ≤ C * ed (word p T k 2 x).val (word p T k 2 y).val) : + FiniteFourier.average (fun x => dist (F x) (F (x + w p k 2))) ≤ + C * (Nat.cast M : ℝ) * (40 * (k : ℝ)⁻¹ ^ k) := by + have hJ : 2 * ((2 * (k ^ 5) ^ k) * (k ^ 5) ^ k) ≤ 4 * k ^ (10 * k) := by + have he : (k ^ 5) ^ k * (k ^ 5) ^ k = k ^ (10 * k) := by + rw [← pow_add, ← pow_mul] + congr 1 + omega + calc + _ = 4 * ((k ^ 5) ^ k * (k ^ 5) ^ k) := by ring + _ ≤ _ := by rw [he] + have hh := displacement_bound (p := p) (h := k) (q := 2) (T := T) + (K := k) (U := k ^ 5) (Qcap := 2 * (k ^ 5) ^ k) (J := 4 * k ^ (10 * k)) + (by omega) (Nat.one_le_pow _ _ (by omega)) hp le_rfl hJ (parameter_gap hk).1 (by positivity) F C hC hlip + apply hh.trans + apply mul_le_mul_of_nonneg_left _ (mul_nonneg hC (Nat.cast_nonneg _)) + simpa only [Nat.cast_mul, Nat.cast_pow, Nat.cast_ofNat, T, repetitions] using spectral_coefficient hk + obtain ⟨W, hW, hl, hd⟩ := binary_transfer hMpos (pow_pos hMpos _) (word p T k 2) (w p k 2) c + ((4 : ℝ) ^ k) (40 * (k : ℝ)⁻¹ ^ k) (by positivity) (by positivity) + (fun x y => (hc x y).2.2.1) hsep hobs + refine ⟨W, hW, ?_, ?_⟩ + · intro v hv + rw [hl v hv, binaryLength, ← hM] + ring + · have he : (804 * (4 : ℝ) ^ k * (40 * (k : ℝ)⁻¹ ^ k))⁻¹ = ((k : ℝ) / 4) ^ k / 32160 := by + rw [div_pow, inv_pow] + field_simp + ring + exact he ▸ hd + +end FiniteTree + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/FinitePrimes.lean b/lean/OAI/Combinatorics/TreeEdit/FinitePrimes.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea673ead4625273d690adca1fc24b5878e69f81d --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/FinitePrimes.lean @@ -0,0 +1,55 @@ +import OAI.Combinatorics.TreeEdit.PrimeSupply +import OAI.Combinatorics.TreeEdit.FiniteTree + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace PrimeSupply + +lemma finite_lists_eventually : ∀ᶠ k : ℕ in Filter.atTop, + ∃ p : ℕ → Fin (20 * k) → ℕ, + (∀ j i, 0 < p j i) ∧ FiniteTree.Admissible p (k ^ 4) k 2 ∧ + (∀ j, j < k → ∀ i, p j i ≤ k ^ 5) := by + filter_upwards [eventually_band_card 4 (by omega), Filter.eventually_ge_atTop 5] with k hk hk5 + have hcard : Fintype.card (Fin k × Fin (20 * k)) ≤ Fintype.card {p // p ∈ band k 4} := by + simp only [Fintype.card_prod, Fintype.card_fin, Fintype.card_coe] + have hk2 : 20 ≤ k ^ 2 := by nlinarith + have hpow : k * (20 * k) ≤ k ^ 4 := by + calc + k * (20 * k) = 20 * k ^ 2 := by ring + _ ≤ k ^ 2 * k ^ 2 := Nat.mul_le_mul_right _ hk2 + _ = k ^ 4 := by ring + exact hpow.trans hk + obtain ⟨e⟩ := Function.Embedding.nonempty_of_card_le hcard + let p : ℕ → Fin (20 * k) → ℕ := fun j i => if hj : j < k then (e (⟨j, hj⟩, i)).val else 2 + have hp (j : ℕ) (hj : j < k) (i : Fin (20 * k)) : + Nat.Prime (p j i) ∧ k ^ 4 < p j i ∧ p j i ≤ k ^ 5 := by + simpa only [p, dite_eq_left hj] using mem_band (e (⟨j, hj⟩, i)).property + refine ⟨p, ?_, ?_, fun j hj i => (hp j hj i).2.2⟩ + · intro j i + by_cases hj : j < k + · exact (hp j hj i).1.pos + · simp [p, hj] + · refine ⟨fun j hj i => (hp j hj i).1, fun j hj i => (hp j hj i).2.1.le, ?_, ?_⟩ + · intro j hj l hl i i' he + have he' : e (⟨j, hj⟩, i) = e (⟨l, hl⟩, i') := by + apply Subtype.ext + simpa only [p, dite_eq_left hj, dite_eq_left hl] using he + have hh := e.injective he' + exact ⟨congrArg (fun x : Fin k × Fin (20 * k) => x.1.val) hh, congrArg Prod.snd hh⟩ + · intro j hj i + apply (Nat.coprime_primes Nat.prime_two (hp j hj i).1).mpr + have hkl : 2 < k ^ 4 := by nlinarith [show 5 ^ 4 ≤ k ^ 4 from Nat.pow_le_pow_left hk5 4] + have hi := (hp j hj i).2.1 + omega + +end PrimeSupply + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/FiniteProbability.lean b/lean/OAI/Combinatorics/TreeEdit/FiniteProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..85c22ad32804db6a1f50aceeb1db006d9f21f43c --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/FiniteProbability.lean @@ -0,0 +1,321 @@ +import OAI.Combinatorics.TreeEdit.Model + +namespace OAI + +namespace TreeEdit.FiniteProbability +open scoped BigOperators +open Classical + +noncomputable def mean {A : Type*} [Fintype A] (f : A → ℝ) : ℝ := + (Fintype.card A : ℝ)⁻¹ * ∑ a, f a + +lemma mean_nonneg {A : Type*} [Fintype A] {f : A → ℝ} (hf : ∀ a, 0 ≤ f a) : + 0 ≤ mean f := mul_nonneg (inv_nonneg.mpr (Nat.cast_nonneg _)) (Finset.sum_nonneg (fun a _ => hf a)) + +lemma mean_le {A : Type*} [Fintype A] {f g : A → ℝ} (h : ∀ a, f a ≤ g a) : + mean f ≤ mean g := mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun a _ => h a)) (by positivity) + +lemma mean_const {A : Type*} [Fintype A] [Nonempty A] (c : ℝ) : mean (fun _ : A => c) = c := by + simp only [mean, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + rw [← mul_assoc, inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero), one_mul] + +lemma mean_add {A : Type*} [Fintype A] (f g : A → ℝ) : + mean (fun a => f a + g a) = mean f + mean g := by simp [mean, Finset.sum_add_distrib, mul_add] + +lemma mean_mul_const {A : Type*} [Fintype A] (f : A → ℝ) (c : ℝ) : + mean (fun a => f a * c) = mean f * c := by simp [mean, Finset.sum_mul, mul_assoc] + +lemma mean_sum {A I : Type*} [Fintype A] (s : Finset I) (f : I → A → ℝ) : + mean (fun a => ∑ i ∈ s, f i a) = ∑ i ∈ s, mean (f i) := by + simp only [mean, Finset.mul_sum] + rw [Finset.sum_comm] + +lemma mean_prod {I : Type*} [Fintype I] {A : I → Type*} [∀ i, Fintype (A i)] + (f : ∀ i, A i → ℝ) : + mean (fun a : ∀ i, A i => ∏ i, f i (a i)) = ∏ i, mean (f i) := by + classical + simp only [mean, Fintype.card_pi, Nat.cast_prod, Finset.prod_inv_distrib, Finset.prod_mul_distrib] + congr 1 + exact (Fintype.prod_sum f).symm + +noncomputable def probability {A : Type*} [Fintype A] (E : A → Prop) : ℝ := + mean (fun a => if E a then 1 else 0) + +lemma probability_nonneg {A : Type*} [Fintype A] (E : A → Prop) : 0 ≤ probability E := by + classical + exact mean_nonneg (fun _ => by split_ifs <;> norm_num) + +lemma probability_le_one {A : Type*} [Fintype A] [Nonempty A] (E : A → Prop) : + probability E ≤ 1 := by + classical + exact (mean_le (fun a => show (if E a then (1 : ℝ) else 0) ≤ 1 by split_ifs <;> norm_num)).trans_eq (mean_const 1) + +lemma probability_not {A : Type*} [Fintype A] [Nonempty A] (E : A → Prop) : + probability (fun a => ¬ E a) = 1 - probability E := by + classical + have hh : probability E + probability (fun a => ¬ E a) = 1 := by + rw [probability, probability, ← mean_add] + calc + _ = mean (fun _ : A => (1 : ℝ)) := by + apply congrArg mean + funext a + by_cases h : E a <;> simp [h] + _ = 1 := mean_const 1 + linarith + +lemma probability_mono {A : Type*} [Fintype A] {E F : A → Prop} (h : ∀ a, E a → F a) : + probability E ≤ probability F := by + classical + apply mean_le + intro a + by_cases he : E a <;> by_cases hf : F a <;> simp_all + +lemma probability_union_bound {A I : Type*} [Fintype A] (s : Finset I) (E : I → A → Prop) : + probability (fun a => ∃ i ∈ s, E i a) ≤ ∑ i ∈ s, probability (E i) := by + classical + simp only [probability] + rw [← mean_sum] + apply mean_le + intro a + split_ifs with h + · obtain ⟨i, hi, he⟩ := h + calc + (1 : ℝ) = (if E i a then (1 : ℝ) else 0) := by simp [he] + _ ≤ ∑ j ∈ s, (if E j a then (1 : ℝ) else 0) := + Finset.single_le_sum (f := fun j => if E j a then (1 : ℝ) else 0) (fun j _ => by split_ifs <;> norm_num) hi + · exact Finset.sum_nonneg (fun j _ => by split_ifs <;> norm_num) + +lemma probability_exists {A : Type*} [Fintype A] {E : A → Prop} (h : 0 < probability E) : ∃ a, E a := by + classical + by_contra hn + have hz : probability E = 0 := by simp [probability, mean, not_exists.mp hn] + linarith + +lemma mean_equiv {A B : Type*} [Fintype A] [Fintype B] (e : A ≃ B) (f : B → ℝ) : + mean (fun a => f (e a)) = mean f := by + simp only [mean, Fintype.card_congr e] + congr 1 + exact e.sum_comp f + +lemma mean_pair {A B : Type*} [Fintype A] [Fintype B] (f : A × B → ℝ) : + mean f = mean (fun a => mean (fun b => f (a, b))) := by + simp only [mean, Fintype.card_prod, Nat.cast_mul, mul_inv_rev, + Fintype.sum_prod_type, Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + ring + +lemma probability_eq {A : Type*} [Fintype A] (a : A) : + probability (· = a) = (Fintype.card A : ℝ)⁻¹ := by + simp [probability, mean] + +lemma probability_eq_of_uniform {A B : Type*} [Fintype A] [Fintype B] [Nonempty A] + (f : A → B) (hf : ∀ b c, probability (fun a => f a = b) = probability (fun a => f a = c)) + (b : B) : probability (fun a => f a = b) = (Fintype.card B : ℝ)⁻¹ := by + have hB : Nonempty B := ⟨f (Classical.arbitrary A)⟩ + have hs : (∑ c : B, probability (fun a => f a = c)) = 1 := by + simp only [probability] + rw [← mean_sum] + simpa using mean_const (A := A) (1 : ℝ) + have he : (∑ c : B, probability (fun a => f a = c)) = + (Fintype.card B : ℝ) * probability (fun a => f a = b) := by + conv_lhs => arg 2; ext c; rw [hf c b] + simp + rw [he] at hs + apply mul_left_cancel₀ (show (Fintype.card B : ℝ) ≠ 0 by exact_mod_cast Fintype.card_ne_zero) + rw [hs, mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero)] + +lemma perm_eval_probability {A : Type*} [Fintype A] (a b : A) : + probability (fun σ : Equiv.Perm A => σ a = b) = (Fintype.card A : ℝ)⁻¹ := by + apply probability_eq_of_uniform + intro b c + let τ := Equiv.swap b c + let e : Equiv.Perm A ≃ Equiv.Perm A := Equiv.mulLeft τ + have he (σ : Equiv.Perm A) : e σ a = c ↔ σ a = b := by + change τ (σ a) = c ↔ σ a = b + rw [← Equiv.swap_apply_left b c] + exact τ.injective.eq_iff + have hh := mean_equiv e (fun σ : Equiv.Perm A => if σ a = c then (1 : ℝ) else 0) + simpa only [he, probability] using hh + +lemma permutation_avoidance {A I : Type*} [Fintype A] [Fintype I] + (f : I → A) (a : A) : + probability (fun σ : Equiv.Perm A => ∃ i, σ (f i) = a) ≤ + (Fintype.card I : ℝ) / Fintype.card A := by + calc + _ ≤ ∑ i : I, probability (fun σ : Equiv.Perm A => σ (f i) = a) := by + simpa using probability_union_bound Finset.univ (fun (i : I) (σ : Equiv.Perm A) => σ (f i) = a) + _ = _ := by simp [perm_eval_probability, div_eq_mul_inv] + +lemma markov {A : Type*} [Fintype A] {E : A → Prop} {f : A → ℝ} {c : ℝ} + (hc : 0 < c) (hf : ∀ a, 0 ≤ f a) (hE : ∀ a, E a → c ≤ f a) : + probability E ≤ mean f / c := by + apply (le_div_iff₀ hc).mpr + rw [probability, ← mean_mul_const] + apply mean_le + intro a + by_cases h : E a + · simpa [h] using hE a h + · simpa [h] using hf a + +lemma independent_lower_tail {I : Type*} [Fintype I] {A : I → Type*} + [∀ i, Fintype (A i)] [∀ i, Nonempty (A i)] (E : ∀ i, A i → Prop) + (hE : ∀ i, (4 : ℝ) / 5 ≤ probability (E i)) : + probability (fun a : ∀ i, A i => + 4 * (Finset.univ.filter (fun i => E i (a i))).card < Fintype.card I) ≤ + (4 / 5 : ℝ) ^ Fintype.card I := by + let f : ∀ i, A i → ℝ := fun i a => if E i a then 1 else 4 + have hf (i : I) : mean (f i) ≤ 8 / 5 := by + have hh : mean (f i) + 3 * probability (E i) = 4 := by + rw [probability] + have hm := mean_mul_const (fun a => if E i a then (1 : ℝ) else 0) 3 + rw [mul_comm 3, ← hm, ← mean_add] + calc + _ = mean (fun _ : A i => (4 : ℝ)) := by + apply congrArg mean + funext a + dsimp [f] + by_cases h : E i a <;> norm_num [h] + _ = _ := mean_const 4 + linarith [hE i] + have hprod (a : ∀ i, A i) : + ∏ i, f i (a i) = (4 : ℝ) ^ (Finset.univ.filter (fun i => ¬ E i (a i))).card := by + simp only [f, Finset.prod_ite, Finset.prod_const_one, one_mul, Finset.prod_const] + have hd (a : ∀ i, A i) (ha : 4 * (Finset.univ.filter (fun i => E i (a i))).card < Fintype.card I) : + (2 : ℝ) ^ Fintype.card I ≤ ∏ i, f i (a i) := by + have hh := Finset.card_filter_add_card_filter_not (s := Finset.univ) (p := fun i => E i (a i)) + simp only [Finset.card_univ] at hh + rw [hprod, show (4 : ℝ) = 2 ^ 2 by norm_num, ← pow_mul] + exact pow_le_pow_right₀ (by norm_num) (by omega) + have hh := markov (f := fun a : ∀ i, A i => ∏ i, f i (a i)) (by positivity : 0 < (2 : ℝ) ^ Fintype.card I) + (fun a => Finset.prod_nonneg (fun i _ => by dsimp [f]; split_ifs <;> norm_num)) hd + calc + _ ≤ mean (fun a : ∀ i, A i => ∏ i, f i (a i)) / (2 : ℝ) ^ Fintype.card I := hh + _ = (∏ i, mean (f i)) / (2 : ℝ) ^ Fintype.card I := by rw [mean_prod] + _ ≤ (8 / 5 : ℝ) ^ Fintype.card I / (2 : ℝ) ^ Fintype.card I := by + apply div_le_div_of_nonneg_right _ (by positivity) + calc + _ ≤ ∏ i : I, (8 / 5 : ℝ) := Finset.prod_le_prod₀ (fun i _ => mean_nonneg (fun a => by dsimp [f]; split_ifs <;> norm_num)) (fun i _ => hf i) + _ = _ := by simp only [Finset.prod_const, Finset.card_univ] + _ = _ := by rw [← div_pow]; norm_num + +lemma mean_fiberwise {A B : Type*} [Fintype A] [Fintype B] (f : A → B) (g : B → ℝ) : + mean (fun a => g (f a)) = ∑ b : B, probability (fun a => f a = b) * g b := by + have he (a : A) : g (f a) = ∑ b : B, (if f a = b then (1 : ℝ) else 0) * g b := by simp + simp_rw [probability, ← mean_mul_const] + rw [← mean_sum] + apply congrArg mean + funext a + exact he a + +lemma probability_comp_uniform {A B : Type*} [Fintype A] [Fintype B] (f : A → B) + (hf : ∀ b, probability (fun a => f a = b) = (Fintype.card B : ℝ)⁻¹) (E : B → Prop) : + probability (fun a => E (f a)) = probability E := by + rw [probability, mean_fiberwise f (fun b => if E b then (1 : ℝ) else 0)] + simp_rw [hf] + simp only [probability, mean, Finset.mul_sum] + +lemma probability_subsingleton {A : Type*} [Fintype A] (E : A → Prop) + (hE : ∀ a b, E a → E b → a = b) : probability E ≤ (Fintype.card A : ℝ)⁻¹ := by + by_cases h : ∃ a, E a + · obtain ⟨a, ha⟩ := h + exact (probability_mono (fun b hb => hE b a hb ha)).trans_eq (probability_eq a) + · have hz : probability E = 0 := by simp [probability, mean, not_exists.mp h] + rw [hz] + positivity + +lemma hom_uniform {A B : Type*} [AddGroup A] [AddGroup B] [Fintype A] [Fintype B] + (f : A →+ B) (hf : Function.Surjective f) (b : B) : + probability (fun a => f a = b) = (Fintype.card B : ℝ)⁻¹ := by + apply probability_eq_of_uniform + intro b c + obtain ⟨x, hx⟩ := hf (c - b) + let e : A ≃ A := Equiv.addLeft x + have he (a : A) : f (e a) = c ↔ f a = b := by + change f (x + a) = c ↔ f a = b + rw [map_add, hx] + constructor <;> intro h + · exact add_left_cancel (h.trans (sub_add_cancel c b).symm) + · rw [h, sub_add_cancel] + have hh := mean_equiv e (fun a => if f a = c then (1 : ℝ) else 0) + simpa only [he, probability] using hh + +lemma probability_pair {A B : Type*} [Fintype A] [Fintype B] (E : A × B → Prop) : + probability E = mean (fun a => probability (fun b => E (a, b))) := mean_pair _ + +lemma independent_lower_tail_subset {I : Type*} [Fintype I] {A : I → Type*} + [∀ i, Fintype (A i)] [∀ i, Nonempty (A i)] (E : ∀ i, A i → Prop) + (s : Finset I) {n : ℕ} (hn : n ≤ s.card) + (hE : ∀ i ∈ s, (4 : ℝ) / 5 ≤ probability (E i)) : + probability (fun a : ∀ i, A i => + 4 * (Finset.univ.filter (fun i => E i (a i))).card < n) ≤ (4 / 5 : ℝ) ^ n := by + let f : ∀ i, A i → ℝ := fun i a => if i ∈ s then (if E i a then 1 else 4) else 1 + have hf (i : I) : mean (f i) ≤ if i ∈ s then 8 / 5 else 1 := by + by_cases hi : i ∈ s + · simp only [hi, ↓reduceIte] + have hh : mean (f i) + 3 * probability (E i) = 4 := by + rw [probability] + rw [mul_comm 3, ← mean_mul_const, ← mean_add] + calc + _ = mean (fun _ : A i => (4 : ℝ)) := by + apply congrArg mean + funext a + dsimp [f] + by_cases h : E i a <;> norm_num [h, hi] + _ = _ := mean_const 4 + linarith [hE i hi] + · simp only [f, hi, ↓reduceIte, mean_const, le_refl] + have hprod (a : ∀ i, A i) : + ∏ i, f i (a i) = (4 : ℝ) ^ (s.filter (fun i => ¬ E i (a i))).card := by + simp only [f, Finset.prod_ite, Finset.prod_const_one, mul_one, one_mul, + Finset.filter_mem_eq_inter, Finset.univ_inter, Finset.prod_const] + have hd (a : ∀ i, A i) (ha : 4 * (Finset.univ.filter (fun i => E i (a i))).card < n) : + (2 : ℝ) ^ s.card ≤ ∏ i, f i (a i) := by + have hh := Finset.card_filter_add_card_filter_not (s := s) (p := fun i => E i (a i)) + have hsub : (s.filter (fun i => E i (a i))).card ≤ + (Finset.univ.filter (fun i => E i (a i))).card := Finset.card_le_card (by intro j hj; simpa using (Finset.mem_filter.mp hj).2) + rw [hprod, show (4 : ℝ) = 2 ^ 2 by norm_num, ← pow_mul] + exact pow_le_pow_right₀ (by norm_num) (by omega) + have hh := markov (f := fun a : ∀ i, A i => ∏ i, f i (a i)) (by positivity : 0 < (2 : ℝ) ^ s.card) + (fun a => Finset.prod_nonneg (fun i _ => by dsimp [f]; split_ifs <;> norm_num)) hd + calc + _ ≤ mean (fun a : ∀ i, A i => ∏ i, f i (a i)) / (2 : ℝ) ^ s.card := hh + _ = (∏ i, mean (f i)) / (2 : ℝ) ^ s.card := by rw [mean_prod] + _ ≤ (8 / 5 : ℝ) ^ s.card / (2 : ℝ) ^ s.card := by + apply div_le_div_of_nonneg_right _ (by positivity) + calc + _ ≤ ∏ i : I, (if i ∈ s then (8 / 5 : ℝ) else 1) := Finset.prod_le_prod₀ (fun i _ => mean_nonneg (fun a => by dsimp [f]; split_ifs <;> norm_num)) (fun i _ => hf i) + _ = _ := by simp [div_pow] + _ = (4 / 5 : ℝ) ^ s.card := by rw [← div_pow]; norm_num + _ ≤ _ := pow_le_pow_of_le_one (by norm_num) (by norm_num) hn + +lemma pair_success_lower {A Z : Type*} [Fintype A] [Fintype Z] + (E : Z → Prop) (F : Z → A → Prop) {p : ℝ} + (h : ∀ z, E z → p ≤ probability (F z)) : + p * probability E ≤ probability (fun a : Z × A => F a.1 a.2) := by + rw [probability_pair, mul_comm p, probability, ← mean_mul_const] + apply mean_le + intro z + by_cases hz : E z + · simpa [hz] using h z hz + · simpa [hz] using probability_nonneg (F z) + +lemma pair_failure_bound {A B : Type*} [Fintype A] [Fintype B] [Nonempty A] [Nonempty B] + (E : A → Prop) (F : A → B → Prop) {δ : ℝ} (hδ : 0 ≤ δ) + (h : ∀ a, ¬ E a → probability (F a) ≤ δ) : + probability (fun x : A × B => F x.1 x.2) ≤ probability E + δ := by + rw [probability_pair] + calc + _ ≤ mean (fun a => (if E a then (1 : ℝ) else 0) + δ) := mean_le (by + intro a + by_cases ha : E a + · simp only [ha, ↓reduceIte] + exact (probability_le_one (F a)).trans (by linarith) + · simpa [ha] using h a ha) + _ = _ := by rw [mean_add, mean_const]; rfl + +end TreeEdit.FiniteProbability + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/FiniteShifts.lean b/lean/OAI/Combinatorics/TreeEdit/FiniteShifts.lean new file mode 100644 index 0000000000000000000000000000000000000000..4c3f1cb612dee51eaf28cdbb1d6ad5dca6ea08a2 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/FiniteShifts.lean @@ -0,0 +1,85 @@ +import OAI.Combinatorics.TreeEdit.FiniteTree +import OAI.Combinatorics.TreeEdit.WordOperations + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace FiniteTree + +lemma w_period {m : ℕ} (p : ℕ → Fin m → ℕ) (h q : ℕ) : q • w p h q = 0 := by + induction h generalizing q with + | zero => + change q • (1 : ZMod q) = 0 + simp [nsmul_eq_mul] + | succ h ih => + apply funext + intro i + change q • ((∏ j, p h j) • w p h (q * p h i)) = 0 + obtain ⟨c, hc⟩ := Finset.dvd_prod_of_mem (p h) (Finset.mem_univ i) + calc + _ = c • ((q * p h i) • w p h (q * p h i)) := by + simp only [← mul_smul, hc] + congr 1 + ring + _ = 0 := by rw [ih]; simp + +lemma cycle_cost {m T h q s : ℕ} {p : ℕ → Fin m → ℕ} (hs : s ≤ T) + (x : State m p (h + 1) q) : + ed (word p T (h + 1) q x).val (word p T (h + 1) q (x + s • u p h q)).val ≤ + 2 * s * (m * length m T h) := by + apply Words.ed_cycles_shift hs + intro a i + apply congrArg (word p T h (q * p h i)) + change x i + (a.val + s) • w p h (q * p h i) = + (x i + s • w p h (q * p h i)) + a.val • w p h (q * p h i) + rw [add_nsmul] + abel + +noncomputable def embedChild {m : ℕ} (p : ℕ → Fin m → ℕ) (h q : ℕ) (i : Fin m) : + State m p h (q * p h i) →+ State m p (h + 1) q := + AddMonoidHom.single (fun i => State m p h (q * p h i)) i + +lemma child_cost {m T h q : ℕ} {p : ℕ → Fin m → ℕ} (i : Fin m) + (z : State m p h (q * p h i)) (C : ℝ) + (hC : ∀ y, (ed (word p T h (q * p h i) y).val + (word p T h (q * p h i) (y + z)).val : ℝ) ≤ C) + (x : State m p (h + 1) q) : + (ed (word p T (h + 1) q x).val + (word p T (h + 1) q (x + embedChild p h q i z)).val : ℝ) ≤ T * C := by + classical + have hh := Words.ed_cycles + (fun (a : Fin T) j => word p T h (q * p h j) (x j + a.val • w p h (q * p h j))) + (fun a j => word p T h (q * p h j) ((x + embedChild p h q i z) j + a.val • w p h (q * p h j))) + have hh' : (ed (word p T (h + 1) q x).val + (word p T (h + 1) q (x + embedChild p h q i z)).val : ℝ) ≤ + ∑ a : Fin T, ∑ j : Fin m, (ed + (word p T h (q * p h j) (x j + a.val • w p h (q * p h j))).val + (word p T h (q * p h j) ((x + embedChild p h q i z) j + a.val • w p h (q * p h j))).val : ℝ) := by + exact_mod_cast hh + apply hh'.trans + calc + _ ≤ ∑ _a : Fin T, C := by + apply Finset.sum_le_sum + intro a _ + rw [Finset.sum_eq_single i] + · simp only [Pi.add_apply, embedChild, AddMonoidHom.single_apply, Pi.single_eq_same] + change (ed (word p T h (q * p h i) (x i + a.val • w p h (q * p h i))).val + (word p T h (q * p h i) ((x i + z) + a.val • w p h (q * p h i))).val : ℝ) ≤ C + rw [add_right_comm (x i) z] + exact hC _ + · intro j _ hji + have he : embedChild p h q i z j = 0 := by simp [embedChild, hji] + simp only [Pi.add_apply, he, add_zero, ed_self, Nat.cast_zero] + · simp + _ = T * C := by simp + +end FiniteTree + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/FiniteSpectrum.lean b/lean/OAI/Combinatorics/TreeEdit/FiniteSpectrum.lean new file mode 100644 index 0000000000000000000000000000000000000000..6286710867de4cf95a67d0287028031f2e5f0634 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/FiniteSpectrum.lean @@ -0,0 +1,247 @@ +import OAI.Combinatorics.TreeEdit.FiniteShifts +import OAI.Combinatorics.TreeEdit.FiniteFourier + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace FiniteTree + +noncomputable instance instStateFintype {m : ℕ} (p : ℕ → Fin m → ℕ) + [∀ j i, NeZero (p j i)] (h q : ℕ) [NeZero q] : Fintype (State m p h q) := + stateFintype p (fun j i => Nat.pos_of_ne_zero (NeZero.ne (p j i))) h q + (Nat.pos_of_ne_zero (NeZero.ne q)) + +noncomputable instance instSymbolFintype {m : ℕ} (p : ℕ → Fin m → ℕ) + [∀ j i, NeZero (p j i)] (h q : ℕ) [NeZero q] : Fintype (Symbol m p h q) := + symbolFintype p (fun j i => Nat.pos_of_ne_zero (NeZero.ne (p j i))) h q + (Nat.pos_of_ne_zero (NeZero.ne q)) + +open FiniteFourier + +variable {m : ℕ} {p : ℕ → Fin m → ℕ} [∀ j i, NeZero (p j i)] + +def SpectralBound (T h q : ℕ) [NeZero q] (H : AddChar (State m p h q) ℂ → ℝ) (C : ℝ) : Prop := + ∀ z b, (∀ x, (ed (word p T h q x).val (word p T h q (x + z)).val : ℝ) ≤ b) → + energy H z ≤ C * b + +lemma SpectralBound.child {T h q : ℕ} [NeZero q] + {H : AddChar (State m p (h + 1) q) ℂ → ℝ} {C : ℝ} + (hH : SpectralBound T (h + 1) q H C) (i : Fin m) : + SpectralBound T h (q * p h i) (pushSpectrum H (embedChild p h q i)) (C * T) := by + intro z b hb + rw [energy_push] + have hh := hH (embedChild p h q i z) (T * b) (child_cost i z b hb) + simpa only [mul_assoc] using hh + +noncomputable def activeChildren {h q : ℕ} (χ : AddChar (State m p (h + 1) q) ℂ) : Finset (Fin m) := + Finset.univ.filter (fun i => χ (embedChild p h q i (w p h (q * p h i))) ≠ 1) + +omit [∀ j i, NeZero (p j i)] in +lemma chi_u {h q : ℕ} (χ : AddChar (State m p (h + 1) q) ℂ) : + χ (u p h q) = ∏ i, χ (embedChild p h q i (w p h (q * p h i))) := by + have he : u p h q = ∑ i, embedChild p h q i (w p h (q * p h i)) := by + exact (Finset.univ_sum_single _).symm + rw [he] + have hs : ∀ (s : Finset (Fin m)), + χ (∑ i ∈ s, embedChild p h q i (w p h (q * p h i))) = + ∏ i ∈ s, χ (embedChild p h q i (w p h (q * p h i))) := by + intro s + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => simp [ha, AddChar.map_add_eq_mul, ih] + exact hs _ + +omit [∀ j i, NeZero (p j i)] in +lemma active_period {h q : ℕ} (χ : AddChar (State m p (h + 1) q) ℂ) : + (χ (u p h q)) ^ (q * ∏ i ∈ activeChildren χ, p h i) = 1 := by + classical + rw [chi_u, ← Finset.prod_pow] + apply Finset.prod_eq_one + intro i _ + by_cases hi : i ∈ activeChildren χ + · obtain ⟨c, hc⟩ := Finset.dvd_prod_of_mem (p h) hi + have hp := w_period p h (q * p h i) + have he : (χ (embedChild p h q i (w p h (q * p h i)))) ^ (q * p h i) = 1 := by + rw [← AddChar.map_nsmul_eq_pow, ← map_nsmul, hp, map_zero, AddChar.map_zero_eq_one] + rw [hc, ← mul_assoc, pow_mul, he, one_pow] + · have he : χ (embedChild p h q i (w p h (q * p h i))) = 1 := by + simpa [activeChildren] using hi + simp [he] + +omit [∀ j i, NeZero (p j i)] in +lemma active_u_ne_one {h q : ℕ} (χ : AddChar (State m p (h + 1) q) ℂ) + (hχ : χ (w p (h + 1) q) ≠ 1) : χ (u p h q) ≠ 1 := by + intro he + apply hχ + change χ ((∏ i, p h i) • u p h q) = 1 + rw [AddChar.map_nsmul_eq_pow, he, one_pow] + +omit [∀ j i, NeZero (p j i)] in +lemma sparse_period_bound {h q K U Qcap : ℕ} [NeZero q] + (χ : AddChar (State m p (h + 1) q) ℂ) + (hU : 1 ≤ U) (hp : ∀ i, p h i ≤ U) + (hq : q * U ^ (h + 1) ≤ Qcap) (hsp : (activeChildren χ).card < K) : + q * (∏ i ∈ activeChildren χ, p h i) ≤ Qcap * U ^ K := by + have hq' : q ≤ Qcap := (Nat.le_mul_of_pos_right q (by positivity : 0 < U ^ (h + 1))).trans hq + have hprod : (∏ i ∈ activeChildren χ, p h i) ≤ U ^ K := by + calc + _ ≤ ∏ _i ∈ activeChildren χ, U := Finset.prod_le_prod (fun i _ => hp i) + _ = U ^ (activeChildren χ).card := by simp + _ ≤ U ^ K := pow_le_pow_right₀ hU (le_of_lt hsp) + exact Nat.mul_le_mul hq' hprod + +end FiniteTree + +namespace FiniteTree + +open FiniteFourier +variable {m : ℕ} {p : ℕ → Fin m → ℕ} [∀ j i, NeZero (p j i)] + +noncomputable def sparse {h q : ℕ} (K : ℕ) (χ : AddChar (State m p (h + 1) q) ℂ) : ℝ := + if χ (w p (h + 1) q) ≠ 1 ∧ (activeChildren χ).card < K then 1 else 0 + +noncomputable def sparseMass {h q : ℕ} [NeZero q] + (K : ℕ) (H : AddChar (State m p (h + 1) q) ℂ → ℝ) : ℝ := ∑ χ, sparse K χ * H χ + +omit [∀ j i, NeZero (p j i)] in +lemma sum_activeChildren {h q : ℕ} (χ : AddChar (State m p (h + 1) q) ℂ) : + ∑ i, active χ (embedChild p h q i (w p h (q * p h i))) = (activeChildren χ).card := by + classical + simp only [active, activeChildren, ← Finset.sum_boole] + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> norm_num + contradiction + +omit [∀ j i, NeZero (p j i)] in +lemma branch_pointwise {h q : ℕ} (K : ℕ) (χ : AddChar (State m p (h + 1) q) ℂ) : + (K : ℝ) * active χ (w p (h + 1) q) ≤ + ∑ i, active χ (embedChild p h q i (w p h (q * p h i))) + K * sparse K χ := by + rw [sum_activeChildren] + by_cases hw : χ (w p (h + 1) q) = 1 + · simp [active, sparse, hw] + · by_cases hc : (activeChildren χ).card < K + · simp [active, sparse, hw, hc] + · simpa [active, sparse, hw, hc] using (show (K : ℝ) ≤ (activeChildren χ).card by exact_mod_cast Nat.le_of_not_gt hc) + +lemma branch_mass {h q : ℕ} [NeZero q] (K : ℕ) + {H : AddChar (State m p (h + 1) q) ℂ → ℝ} (hH : ∀ χ, 0 ≤ H χ) : + (K : ℝ) * activeMass H (w p (h + 1) q) ≤ + (∑ i, activeMass (pushSpectrum H (embedChild p h q i)) (w p h (q * p h i))) + K * sparseMass K H := by + classical + have hh := Finset.sum_le_sum (s := Finset.univ) (fun χ _ => + mul_le_mul_of_nonneg_right (branch_pointwise K χ) (hH χ)) + have he : (∑ χ, (∑ i, active χ (embedChild p h q i (w p h (q * p h i)))) * H χ) = + ∑ i, activeMass (pushSpectrum H (embedChild p h q i)) (w p h (q * p h i)) := by + simp only [Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + rw [activeMass_push] + simp only [add_mul, Finset.sum_add_distrib, he, mul_assoc, ← Finset.mul_sum] at hh + exact hh + +lemma sparse_estimate {T h q K U Qcap J : ℕ} [NeZero q] + {H : AddChar (State m p (h + 1) q) ℂ → ℝ} {C : ℝ} + (hH : ∀ χ, 0 ≤ H χ) (hbound : SpectralBound T (h + 1) q H C) + (hU : 1 ≤ U) (hp : ∀ i, p h i ≤ U) (hq : q * U ^ (h + 1) ≤ Qcap) + (hJ : 2 * (Qcap * U ^ K) ≤ J) (hJT : J ≤ T) (hJpos : 0 < J) : + sparseMass K H ≤ C * (2 * J * (m * length m T h)) := by + classical + have hdetect (χ : AddChar (State m p (h + 1) q) ℂ) : + (J : ℝ) * sparse K χ ≤ ∑ s ∈ Finset.range J, multiplier χ ((s + 1) • u p h q) := by + by_cases hs : χ (w p (h + 1) q) ≠ 1 ∧ (activeChildren χ).card < K + · rw [sparse, ite_eq_left hs, mul_one] + apply period_detect χ (u p h q) (n := q * ∏ i ∈ activeChildren χ, p h i) + · exact Nat.mul_pos (NeZero.pos q) (Finset.prod_pos (fun i _ => NeZero.pos (p h i))) + · exact (Nat.mul_le_mul_left 2 (sparse_period_bound χ hU hp hq hs.2)).trans hJ + · exact active_u_ne_one χ hs.1 + · exact active_period χ + · simp only [sparse, ite_eq_right hs, mul_zero] + exact Finset.sum_nonneg fun s _ => multiplier_nonneg χ _ + have hcost (s : ℕ) (hs : s ∈ Finset.range J) : + energy H ((s + 1) • u p h q) ≤ C * (2 * J * (m * length m T h)) := by + have hsJ : s + 1 ≤ J := Finset.mem_range.mp hs + apply hbound + intro x + have hc := cycle_cost (hsJ.trans hJT) x (p := p) + have hh := hc.trans (Nat.mul_le_mul_right (m * length m T h) (Nat.mul_le_mul_left 2 hsJ)) + exact_mod_cast hh + have hh : (J : ℝ) * sparseMass K H ≤ J * (C * (2 * J * (m * length m T h))) := by + calc + _ ≤ ∑ χ, (∑ s ∈ Finset.range J, multiplier χ ((s + 1) • u p h q)) * H χ := by + rw [sparseMass, Finset.mul_sum] + exact Finset.sum_le_sum fun χ _ => by + simpa only [mul_assoc] using mul_le_mul_of_nonneg_right (hdetect χ) (hH χ) + _ = ∑ s ∈ Finset.range J, energy H ((s + 1) • u p h q) := by + simp only [energy, Finset.sum_mul] + rw [Finset.sum_comm] + _ ≤ ∑ _s ∈ Finset.range J, C * (2 * J * (m * length m T h)) := Finset.sum_le_sum hcost + _ = _ := by simp + exact (mul_le_mul_iff_right₀ (by exact_mod_cast hJpos : (0 : ℝ) < J)).mp hh + +theorem mass_bound {T h q K U Qcap J : ℕ} [NeZero q] + {H : AddChar (State m p h q) ℂ → ℝ} {C : ℝ} + (hH : ∀ χ, 0 ≤ H χ) (hC : 0 ≤ C) (hbound : SpectralBound T h q H C) + (hK : 1 ≤ K) (hU : 1 ≤ U) (hp : ∀ j, j < h → ∀ i, p j i ≤ U) + (hq : q * U ^ h ≤ Qcap) (hJ : 2 * (Qcap * U ^ K) ≤ J) + (hJT : J ≤ T) (hJpos : 0 < J) : + activeMass H (w p h q) ≤ C * length m T h * ((K : ℝ)⁻¹ ^ h + 2 * h * J / T) := by + have hTpos : 0 < T := hJpos.trans_le hJT + have hKr : (1 : ℝ) ≤ K := by exact_mod_cast hK + have hTr : (0 : ℝ) < T := by exact_mod_cast hTpos + induction h generalizing q C with + | zero => + have hb (z : State m p 0 q) : energy H z ≤ C := by + have hh := hbound z 1 (fun x => by + have hh := ed_le_of_script (substitution_script + (x := (word p T 0 q x).val) (y := (word p T 0 q (x + z)).val) + (by simp [(word p T 0 q x).property, (word p T 0 q (x + z)).property])) + simpa [(word p T 0 q x).property, length] using hh) + simpa using hh + have hh := (twice_activeMass_le_average hH (w p 0 q)).trans (average_le hb) + simpa [length] using (show activeMass H (w p 0 q) ≤ C by linarith [activeMass_nonneg hH (w p 0 q)]) + | succ h ih => + have hchild (i : Fin m) : + activeMass (pushSpectrum H (embedChild p h q i)) (w p h (q * p h i)) ≤ + (C * T) * length m T h * ((K : ℝ)⁻¹ ^ h + 2 * h * J / T) := by + apply ih (pushSpectrum_nonneg hH _) (mul_nonneg hC (Nat.cast_nonneg _)) (hbound.child i) + (fun j hj => hp j (by omega)) + calc + (q * p h i) * U ^ h = q * (p h i * U ^ h) := by ring + _ ≤ q * (U * U ^ h) := Nat.mul_le_mul_left q (Nat.mul_le_mul_right _ (hp h (by omega) i)) + _ = q * U ^ (h + 1) := by rw [pow_succ]; ring + _ ≤ Qcap := hq + have hsp := sparse_estimate hH hbound hU (hp h (by omega)) hq hJ hJT hJpos + have hb := branch_mass K hH + have hc := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hchild i) + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hc + have hmain : (K : ℝ) * activeMass H (w p (h + 1) q) ≤ + C * length m T (h + 1) * ((K : ℝ)⁻¹ ^ h + 2 * h * J / T) + + K * (C * (2 * J * (m * length m T h))) := by + calc + _ ≤ _ := hb.trans (add_le_add hc (mul_le_mul_of_nonneg_left hsp (by positivity))) + _ = _ := by simp only [length, Nat.cast_mul]; ring + have he : (K : ℝ) * (C * length m T (h + 1) * + ((K : ℝ)⁻¹ ^ (h + 1) + 2 * (h + 1) * J / T)) - + (C * length m T (h + 1) * ((K : ℝ)⁻¹ ^ h + 2 * h * J / T) + + K * (C * (2 * J * (m * length m T h)))) = + C * (m * length m T h) * (2 * h * J) * (K - 1) := by + simp only [length, Nat.cast_mul, pow_succ] + field_simp + ring + have hn : 0 ≤ C * (m * length m T h) * (2 * (h : ℝ) * J) * ((K : ℝ) - 1) := by positivity + have hf : (K : ℝ) * activeMass H (w p (h + 1) q) ≤ + K * (C * length m T (h + 1) * ((K : ℝ)⁻¹ ^ (h + 1) + 2 * (h + 1) * J / T)) := by linarith + exact (mul_le_mul_iff_right₀ (by linarith : (0 : ℝ) < K)).mp (by simpa using hf) + +end FiniteTree + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/FiniteTree.lean b/lean/OAI/Combinatorics/TreeEdit/FiniteTree.lean new file mode 100644 index 0000000000000000000000000000000000000000..b11205f331dadbcf5a56f10862dd03c00958d597 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/FiniteTree.lean @@ -0,0 +1,227 @@ +import OAI.Combinatorics.TreeEdit.CyclicWords +import OAI.Combinatorics.TreeEdit.TreeArithmetic + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace FiniteTree + +@[reducible] def State (m : ℕ) (p : ℕ → Fin m → ℕ) : ℕ → ℕ → Type + | 0, q => ZMod q + | h + 1, q => ∀ i : Fin m, State m p h (q * p h i) + +noncomputable instance stateAddCommGroup (m : ℕ) (p : ℕ → Fin m → ℕ) (h q : ℕ) : + AddCommGroup (State m p h q) := by + induction h generalizing q with + | zero => exact inferInstanceAs (AddCommGroup (ZMod q)) + | succ h ih => + letI : ∀ i : Fin m, AddCommGroup (State m p h (q * p h i)) := fun i => ih _ + exact inferInstanceAs (AddCommGroup (∀ i : Fin m, State m p h (q * p h i))) + +@[reducible] def Symbol (m : ℕ) (p : ℕ → Fin m → ℕ) : ℕ → ℕ → Type + | 0, q => ZMod q + | h + 1, q => Σ i : Fin m, Symbol m p h (q * p h i) + +@[instance_reducible] noncomputable def stateFintype {m : ℕ} (p : ℕ → Fin m → ℕ) (hp : ∀ h i, 0 < p h i) + (h q : ℕ) (hq : 0 < q) : Fintype (State m p h q) := by + induction h generalizing q with + | zero => + letI : NeZero q := ⟨ne_of_gt hq⟩ + exact inferInstanceAs (Fintype (ZMod q)) + | succ h ih => + letI : ∀ i : Fin m, Fintype (State m p h (q * p h i)) := fun i => + ih _ (Nat.mul_pos hq (hp h i)) + exact inferInstanceAs (Fintype (∀ i : Fin m, State m p h (q * p h i))) + +@[instance_reducible] noncomputable def symbolFintype {m : ℕ} (p : ℕ → Fin m → ℕ) (hp : ∀ h i, 0 < p h i) + (h q : ℕ) (hq : 0 < q) : Fintype (Symbol m p h q) := by + induction h generalizing q with + | zero => + letI : NeZero q := ⟨ne_of_gt hq⟩ + exact inferInstanceAs (Fintype (ZMod q)) + | succ h ih => + letI : ∀ i : Fin m, Fintype (Symbol m p h (q * p h i)) := fun i => + ih _ (Nat.mul_pos hq (hp h i)) + exact inferInstanceAs (Fintype (Σ i : Fin m, Symbol m p h (q * p h i))) + +noncomputable def w {m : ℕ} (p : ℕ → Fin m → ℕ) : (h q : ℕ) → State m p h q + | 0, q => (1 : ZMod q) + | h + 1, q => (∏ i : Fin m, p h i) • (fun i => w p h (q * p h i)) + +noncomputable def u {m : ℕ} (p : ℕ → Fin m → ℕ) (h q : ℕ) : State m p (h + 1) q := + fun i => w p h (q * p h i) + +noncomputable def word {m : ℕ} (p : ℕ → Fin m → ℕ) (T : ℕ) : + (h q : ℕ) → State m p h q → Word (Symbol m p h q) (length m T h) + | 0, _, x => Words.ofFn (fun _ => x) + | h + 1, q, x => Words.cycles fun a i => + word p T h (q * p h i) (x i + a.val • w p h (q * p h i)) + +lemma many_shifted_children {m b s T q : ℕ} (p : Fin m → ℕ) + (hp : ∀ i, Nat.Prime (p i)) (hinj : Function.Injective p) + (hb : 1 ≤ b) (hpb : ∀ i, b ≤ p i) (hT : T ≤ b ^ s) (hsm : 2 * s ≤ m) + (hcop : Nat.Coprime q (∏ i, p i)) + (t d : ℤ) (ht : ¬ (q : ℤ) ∣ t) (hdT : d.natAbs < T) : + s ≤ (Finset.univ.filter (fun i => ¬ ((q * p i : ℕ) : ℤ) ∣ + d + t * (∏ j, p j : ℕ))).card := by + classical + let R := ∏ j, p j + let bad := Finset.univ.filter (fun i => ((q * p i : ℕ) : ℤ) ∣ d + t * R) + have hpartition := Finset.card_filter_add_card_filter_not + (s := (Finset.univ : Finset (Fin m))) (fun i => ((q * p i : ℕ) : ℤ) ∣ d + t * R) + simp only [Finset.card_univ, Fintype.card_fin] at hpartition + by_cases hd : d = 0 + · have he : bad = ∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro i hi + have hh := (Finset.mem_filter.mp hi).2 + have hq : (q : ℤ) ∣ t * R := by + apply dvd_trans (show (q : ℤ) ∣ ((q * p i : ℕ) : ℤ) by + exact_mod_cast dvd_mul_right q (p i)) + simpa only [hd, zero_add] using hh + exact ht (hcop.isCoprime.dvd_of_dvd_mul_right hq) + have hz : bad.card = 0 := by rw [he]; rfl + change bad.card + _ = m at hpartition + change s ≤ (Finset.univ.filter (fun i => ¬ ((q * p i : ℕ) : ℤ) ∣ d + t * R)).card + omega + · have hsub : bad ⊆ Finset.univ.filter (fun i => (p i : ℤ) ∣ d) := by + intro i hi + have hpR : (p i : ℤ) ∣ (R : ℤ) := by + exact_mod_cast Finset.dvd_prod_of_mem p (Finset.mem_univ i) + have hh : (p i : ℤ) ∣ d + t * R := by + apply dvd_trans (show (p i : ℤ) ∣ ((q * p i : ℕ) : ℤ) by + exact_mod_cast dvd_mul_left (p i) q) + exact (Finset.mem_filter.mp hi).2 + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, + by simpa using dvd_sub hh (dvd_mul_of_dvd_right hpR t)⟩ + have hlt := (Finset.card_le_card hsub).trans_lt (few_prime_divisors p hp hinj hb hpb hT d hd hdT) + change bad.card + _ = m at hpartition + change s ≤ (Finset.univ.filter (fun i => ¬ ((q * p i : ℕ) : ℤ) ∣ d + t * R)).card + omega + +structure Admissible {m : ℕ} (p : ℕ → Fin m → ℕ) (b h q : ℕ) : Prop where + prime : ∀ j, j < h → ∀ i, Nat.Prime (p j i) + lower : ∀ j, j < h → ∀ i, b ≤ p j i + distinct : ∀ j, j < h → ∀ l, l < h → ∀ i i', + p j i = p l i' → j = l ∧ i = i' + coprime : ∀ j, j < h → ∀ i, Nat.Coprime q (p j i) + +lemma Admissible.child {m b h q : ℕ} {p : ℕ → Fin m → ℕ} + (H : Admissible p b (h + 1) q) (i : Fin m) : Admissible p b h (q * p h i) where + prime j hj := H.prime j (by omega) + lower j hj := H.lower j (by omega) + distinct j hj l hl := H.distinct j (by omega) l (by omega) + coprime j hj i' := (H.coprime j (by omega) i').mul_left + ((Nat.coprime_primes (H.prime h (by omega) i) (H.prime j (by omega) i')).mpr (by + intro he + have hh := (H.distinct h (by omega) j (by omega) i i' he).1 + omega)) + +lemma Admissible.many {m b h q s T : ℕ} {p : ℕ → Fin m → ℕ} + (H : Admissible p b (h + 1) q) + (hb : 1 ≤ b) (hT : T ≤ b ^ s) (hsm : 2 * s ≤ m) + (t : ℤ) (ht : ¬ (q : ℤ) ∣ t) (a a' : Fin T) : + s ≤ (Finset.univ.filter (fun i => ¬ ((q * p h i : ℕ) : ℤ) ∣ + (a'.val : ℤ) - a.val + t * (∏ j, p h j : ℕ))).card := by + apply many_shifted_children (p h) (H.prime h (by omega)) + (fun i j he => (H.distinct h (by omega) h (by omega) i j he).2) + hb (H.lower h (by omega)) hT hsm + (Nat.Coprime.prod_right (fun i _ => H.coprime h (by omega) i)) t _ ht + rw [← Int.ofNat_lt] + rw [Int.natCast_natAbs] + have ha := a.isLt + have ha' := a'.isLt + rw [abs_lt] + constructor <;> omega + +theorem separation {m T b s h q : ℕ} {p : ℕ → Fin m → ℕ} + (hm : m = 2 * s) (hs : 2 ≤ s) (hT0 : 0 < T) (hb : 1 ≤ b) + (hT : T ≤ b ^ s) (H : Admissible p b h q) + (x : State m p h q) (t : ℤ) (ht : ¬ (q : ℤ) ∣ t) : + (length m T h : ℝ) ≤ (4 : ℝ) ^ h * + (deficit (word p T h q x).val (word p T h q (x + t • w p h q)).val : ℝ) := by + induction h generalizing q t with + | zero => + let y : ZMod q := x + have hne : y ≠ y + t • (1 : ZMod q) := by + intro he + have hz : t • (1 : ZMod q) = 0 := add_left_cancel (he.symm.trans (add_zero y).symm) + have hh : (t : ZMod q) = 0 := by simpa only [zsmul_eq_mul, mul_one] using hz + exact ht ((ZMod.intCast_zmod_eq_zero_iff_dvd t q).mp hh) + have hw (z : State m p 0 q) : (word p T 0 q z).val = [z] := by + change List.ofFn (fun _ : Fin 1 => z) = [z] + simp [List.ofFn_succ] + have hne' : x ≠ x + t • w p 0 q := hne + rw [hw x, hw (x + t • w p 0 q), deficit_singleton hne'] + norm_num [length] + | succ h ih => + have hm4 : 4 ≤ m := by omega + let B := length m T h + have hB : 0 < B := by dsimp [B]; rw [length_eq]; positivity + let X : Fin T → ∀ i : Fin m, Word (Symbol m p h (q * p h i)) B := + fun a i => word p T h (q * p h i) (x i + a.val • w p h (q * p h i)) + let Y : Fin T → ∀ i : Fin m, Word (Symbol m p h (q * p h i)) B := + fun a i => word p T h (q * p h i) ((x + t • w p (h + 1) q) i + + a.val • w p h (q * p h i)) + let δ : ℝ := (s : ℝ) * B / (4 : ℝ) ^ h + have hpow : 0 < (4 : ℝ) ^ h := by positivity + have hpow1 : 1 ≤ (4 : ℝ) ^ h := one_le_pow₀ (by norm_num) + have hδ : δ ≤ ((m - 2) * B : ℕ) := by + have hs' : (s : ℝ) ≤ (m - 2 : ℕ) := by exact_mod_cast (show s ≤ m - 2 by omega) + have hB' : (0 : ℝ) ≤ B := Nat.cast_nonneg _ + dsimp [δ] + rw [div_le_iff₀ hpow] + push_cast + calc + (s : ℝ) * B ≤ (m - 2 : ℕ) * (B : ℝ) := mul_le_mul_of_nonneg_right hs' hB' + _ ≤ ((m - 2 : ℕ) : ℝ) * B * 4 ^ h := le_mul_of_one_le_right (by positivity) hpow1 + have hblocks (a a' : Fin T) : δ ≤ ∑ i : Fin m, (deficit (X a i).val (Y a' i).val : ℝ) := by + let d : ℤ := (a'.val : ℤ) - a.val + t * (∏ j, p h j : ℕ) + let good := Finset.univ.filter (fun i : Fin m => ¬ ((q * p h i : ℕ) : ℤ) ∣ d) + have hgood : s ≤ good.card := H.many hb hT (by omega) t ht a a' + have hlocal (i : Fin m) (hi : i ∈ good) : + (B : ℝ) ≤ (4 : ℝ) ^ h * (deficit (X a i).val (Y a' i).val : ℝ) := by + have hi' : ¬ ((q * p h i : ℕ) : ℤ) ∣ d := (Finset.mem_filter.mp hi).2 + have hh := ih (H.child i) (x i + a.val • w p h (q * p h i)) d hi' + have he : (x + t • w p (h + 1) q) i + a'.val • w p h (q * p h i) = + (x i + a.val • w p h (q * p h i)) + d • w p h (q * p h i) := by + change x i + t • ((∏ j, p h j) • w p h (q * p h i)) + + a'.val • w p h (q * p h i) = _ + exact translation_cycle _ _ _ _ _ _ + change (B : ℝ) ≤ (4 : ℝ) ^ h * (deficit + (word p T h (q * p h i) (x i + a.val • w p h (q * p h i))).val + (word p T h (q * p h i) ((x + t • w p (h + 1) q) i + + a'.val • w p h (q * p h i))).val : ℝ) + rw [he] + exact hh + have hsum := Finset.sum_le_sum (s := good) hlocal + simp only [Finset.sum_const, nsmul_eq_mul, ← Finset.mul_sum] at hsum + have hsub : (∑ i ∈ good, (deficit (X a i).val (Y a' i).val : ℝ)) ≤ + ∑ i : Fin m, (deficit (X a i).val (Y a' i).val : ℝ) := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun _ _ _ => Nat.cast_nonneg _) + have hgood' : (s : ℝ) ≤ good.card := by exact_mod_cast hgood + apply (div_le_iff₀ hpow).mpr + nlinarith [mul_le_mul_of_nonneg_right hgood' (Nat.cast_nonneg B), + mul_le_mul_of_nonneg_left hsub (le_of_lt hpow)] + have hh := Words.cycles_deficit (by omega) hB X Y δ hδ hblocks + change (T : ℝ) * δ ≤ 2 * + (deficit (word p T (h + 1) q x).val (word p T (h + 1) q (x + t • w p (h + 1) q)).val : ℝ) at hh + have hh' := mul_le_mul_of_nonneg_right hh (le_of_lt hpow) + dsimp [δ] at hh' + rw [mul_assoc, div_mul_cancel₀ _ (ne_of_gt hpow)] at hh' + simp only [length, Nat.cast_mul, pow_succ] + have hm' : (m : ℝ) = 2 * s := by exact_mod_cast hm + change (T : ℝ) * ((m : ℝ) * B) ≤ _ + rw [hm'] + nlinarith only [hh'] + +end FiniteTree + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/Main.lean b/lean/OAI/Combinatorics/TreeEdit/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..86c81b0c1efb9c86d17889eb78bdaf87b4e97879 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/Main.lean @@ -0,0 +1,12 @@ +import OAI.Combinatorics.TreeEdit.FiniteLowerBound +import OAI.Combinatorics.TreeEdit.TorusLowerBound +import OAI.Combinatorics.TreeEdit.RandomCode + +/-! +# Binary edit-distance distortion + +The nested finite-period and circle-tree constructions independently give the same +lower bound for every sufficiently large length cap, in the unrestricted real ℓ₁ +space. The fixed-length conversion theorem applies to all words over any finite +alphabet within the cardinality bound, with width `M ^ 2` and length `M ^ 3`. +-/ diff --git a/lean/OAI/Combinatorics/TreeEdit/Model.lean b/lean/OAI/Combinatorics/TreeEdit/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..406c519d0b708ccea5d76ca60fe6b18187e0fa94 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/Model.lean @@ -0,0 +1,79 @@ +import Mathlib + +namespace OAI + +namespace TreeEdit + +universe u v + +/-- A single unit-cost insertion, deletion or substitution, at any position. -/ +inductive EditStep {α : Type u} : List α → List α → Prop + | insert (p q : List α) (a : α) : EditStep (p ++ q) (p ++ a :: q) + | delete (p q : List α) (a : α) : EditStep (p ++ a :: q) (p ++ q) + | substitute (p q : List α) (a b : α) : EditStep (p ++ a :: q) (p ++ b :: q) + +/-- A script of precisely `n` edits. There is no restriction on its intermediate lengths. -/ +inductive EditScript {α : Type u} : List α → List α → ℕ → Prop + | nil (x : List α) : EditScript x x 0 + | cons {x y z : List α} {n : ℕ} : + EditStep x y → EditScript y z n → EditScript x z (n + 1) + +/-- Ordinary unit-cost edit distance. The set is nonempty (delete then insert). -/ +noncomputable def ed {α : Type u} (x y : List α) : ℕ := + sInf {n | EditScript x y n} + +/-- The full infinite-dimensional real ℓ₁ space. -/ +abbrev RealL1 := lp (fun _ : ℕ => ℝ) 1 + +/-- Product of the two maximal pairwise distance ratios. -/ +noncomputable def distortion (W : Finset (List Bool)) (f : W → RealL1) : ℝ := + sSup {r : ℝ | ∃ x y : W, x ≠ y ∧ + r = dist (f x) (f y) / (ed x.val y.val : ℝ)} * + sSup {r : ℝ | ∃ x y : W, x ≠ y ∧ + r = (ed x.val y.val : ℝ) / dist (f x) (f y)} + +/-- Infimum over all injective ℓ₁ maps, used on finite sets with at least two points. -/ +noncomputable def c1 (W : Finset (List Bool)) : ℝ := + sInf {D : ℝ | ∃ f : W → RealL1, Function.Injective f ∧ distortion W f = D} + +/-- The binary main endpoint, for every sufficiently large cap (natural logarithms). -/ +def BinaryLowerBound : Prop := + ∃ c : ℝ, 0 < c ∧ ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → + ∃ n : ℕ, n ≤ d ∧ ∃ W : Finset (List Bool), + 2 ≤ W.card ∧ (∀ w ∈ W, w.length = n) ∧ + Real.exp (c * Real.sqrt (Real.log (d : ℝ) * Real.log (Real.log (d : ℝ)))) ≤ c1 W + +/-- The length of a longest arbitrary common subsequence. -/ +noncomputable def lcs {α : Type u} (x y : List α) : ℕ := + sSup {n | ∃ z : List α, z.Sublist x ∧ z.Sublist y ∧ z.length = n} + +/-- One-sided deficit; used below only when the two lengths agree. -/ +noncomputable def deficit {α : Type u} (x y : List α) : ℕ := x.length - lcs x y + +/-- Fixed-length words, with symbols at every position arbitrary. -/ +abbrev Word (α : Type u) (n : ℕ) := {x : List α // x.length = n} + +/-- The concatenation extension of a fixed-width symbol code, on *all* finite words. -/ +def encode {α : Type u} {β : Type v} {P : ℕ} (c : α → Word β P) (x : List α) : List β := + x.flatMap (fun a => (c a).val) + +/-- Exact polynomial-width code endpoint, including the stronger deficit inequality. -/ +def FixedLengthBinaryConversion : Prop := + ∃ M₀ : ℕ, ∀ M : ℕ, M₀ ≤ M → ∀ (Γ : Type u) [Fintype Γ], + 1 ≤ Fintype.card Γ → Fintype.card Γ ≤ M → + ∃ c : Γ → Word Bool (M ^ 2), ∀ x y : Word Γ M, + (encode c x.val).length = M ^ 3 ∧ + (encode c y.val).length = M ^ 3 ∧ + ((M ^ 2 : ℕ) : ℝ) / 804 * (ed x.val y.val : ℝ) ≤ + (ed (encode c x.val) (encode c y.val) : ℝ) ∧ + (ed (encode c x.val) (encode c y.val) : ℝ) ≤ + ((M ^ 2 : ℕ) : ℝ) * (ed x.val y.val : ℝ) ∧ + ((M ^ 2 : ℕ) : ℝ) / 402 * (deficit x.val y.val : ℝ) ≤ + (deficit (encode c x.val) (encode c y.val) : ℝ) + +def vectorWord {P : ℕ} (v : Fin P → Bool) : Word Bool P := + ⟨List.ofFn v, List.length_ofFn⟩ + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/PrimeSupply.lean b/lean/OAI/Combinatorics/TreeEdit/PrimeSupply.lean new file mode 100644 index 0000000000000000000000000000000000000000..53da52d9b20efcc233f161242fa0fe1f3db3af13 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/PrimeSupply.lean @@ -0,0 +1,92 @@ +import OAI.Combinatorics.TreeEdit.Model + +namespace OAI + +namespace TreeEdit + +universe u + +attribute [local instance] Classical.propDecidable + +namespace PrimeSupply +open Filter + +lemma primeCounting_le (n : ℕ) : n.primeCounting ≤ n := by + rw [← Nat.primesLE_card_eq_primeCounting] + have hh : n.primesLE ⊆ Finset.Icc 1 n := by + intro p hp + exact Finset.mem_Icc.mpr ⟨(Nat.mem_primesLE.mp hp).2.one_lt.le, (Nat.mem_primesLE.mp hp).1⟩ + simpa using Finset.card_le_card hh + +lemma eventually_pi_power (a : ℕ) (ha : 1 ≤ a) : + ∀ᶠ k : ℕ in atTop, 2 * k ^ a ≤ (k ^ (a + 1)).primeCounting := by + have ht : Tendsto (fun k : ℕ => Real.log (k : ℝ) / k) atTop (nhds 0) := by + simpa only [Function.comp_def, pow_one, one_mul, add_zero] using (Real.tendsto_pow_log_div_mul_add_atTop 1 0 1 one_ne_zero).comp tendsto_natCast_atTop_atTop + have hev := ht.eventually_lt_const (show (0 : ℝ) < 1 / (8 * (a + 1)) by positivity) + filter_upwards [hev, eventually_ge_atTop (8 * (a + 2))] with k hk hlarge + have hkp : (0 : ℝ) < k := by exact_mod_cast (by omega : 0 < k) + have hka : (8 : ℝ) * (a + 2) ≤ k := by exact_mod_cast hlarge + have hsmall : ((a : ℝ) + 1) * Real.log k ≤ (k : ℝ) / 8 := by + have hh := (div_lt_iff₀ hkp).mp hk + have hann : (0 : ℝ) < 8 * (a + 1) := by positivity + have hh' := (lt_div_iff₀ hann).mp (show Real.log k < (k : ℝ) / (8 * (a + 1)) by simpa only [one_div, div_eq_mul_inv, mul_comm, one_mul] using hh) + linarith + have hkn : (1 : ℝ) ≤ k := by linarith + have hn : (k : ℝ) ^ 2 ≤ (k : ℝ) ^ (a + 1) := pow_le_pow_right₀ hkn (by omega) + have hn1 : (1 : ℝ) ≤ (k : ℝ) ^ (a + 1) := one_le_pow₀ hkn + have hlog : Real.log ((k : ℝ) ^ (a + 1) + 1) ≤ (k : ℝ) ^ (a + 1) / 4 := by + calc + _ ≤ Real.log (2 * (k : ℝ) ^ (a + 1)) := Real.log_le_log (by positivity) (by linarith) + _ = Real.log 2 + ((a : ℝ) + 1) * Real.log k := by + rw [Real.log_mul (by norm_num) (by positivity), Real.log_pow]; norm_num + _ ≤ 1 + ((a : ℝ) + 1) * ((k : ℝ) - 1) := by + gcongr + · have hh := Real.log_le_sub_one_of_pos (by norm_num : (0 : ℝ) < 2) + norm_num at hh + exact hh + · exact Real.log_le_sub_one_of_pos hkp + _ ≤ _ := by nlinarith [mul_nonneg (show (0 : ℝ) ≤ k - 8 * (a + 2) by linarith) hkp.le] + have hhalf : (1 / 2 : ℝ) ≤ Real.log 2 := by linarith [Real.log_two_gt_d9] + have hden : 0 < Real.log ((k : ℝ) ^ (a + 1)) := by + apply Real.log_pos + exact_mod_cast (one_lt_pow₀ (by omega : 1 < k) (by omega : a + 1 ≠ 0)) + have hlo : (2 * k ^ a : ℕ) ≤ ((k : ℝ) ^ (a + 1) * Real.log 2 - Real.log ((k : ℝ) ^ (a + 1) + 1)) / + Real.log ((k : ℝ) ^ (a + 1)) := by + apply (le_div_iff₀ hden).mpr + push_cast + rw [Real.log_pow] + push_cast + have hm := mul_le_mul_of_nonneg_left hsmall (by positivity : (0 : ℝ) ≤ 2 * (k : ℝ) ^ a) + have hh := mul_le_mul_of_nonneg_left hhalf (by positivity : (0 : ℝ) ≤ (k : ℝ) ^ (a + 1)) + rw [pow_succ] at hh hlog ⊢ + nlinarith + have hp := Chebyshev.pi_ge (k ^ (a + 1)) + push_cast at hp + exact_mod_cast hlo.trans hp + +noncomputable def band (k a : ℕ) := (k ^ (a + 1)).primesLE \ (k ^ a).primesLE + +lemma eventually_band_card (a : ℕ) (ha : 1 ≤ a) : + ∀ᶠ k : ℕ in atTop, k ^ a ≤ (band k a).card := by + filter_upwards [eventually_pi_power a ha, eventually_ge_atTop 1] with k hk hk1 + have hsub : (k ^ a).primesLE ⊆ (k ^ (a + 1)).primesLE := by + intro p hp + obtain ⟨hpk, hpp⟩ := Nat.mem_primesLE.mp hp + exact Nat.mem_primesLE.mpr ⟨hpk.trans (pow_le_pow_right₀ hk1 (by omega)), hpp⟩ + rw [band, Finset.card_sdiff_of_subset hsub, Nat.primesLE_card_eq_primeCounting, + Nat.primesLE_card_eq_primeCounting] + have hh := primeCounting_le (k ^ a) + omega + +lemma mem_band {k a p : ℕ} (hp : p ∈ band k a) : Nat.Prime p ∧ k ^ a < p ∧ p ≤ k ^ (a + 1) := by + obtain ⟨hp, hlo⟩ := Finset.mem_sdiff.mp hp + obtain ⟨hup, hprime⟩ := Nat.mem_primesLE.mp hp + refine ⟨hprime, ?_, hup⟩ + by_contra hn + exact hlo (Nat.mem_primesLE.mpr ⟨Nat.le_of_not_gt hn, hprime⟩) + +end PrimeSupply + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/RandomCircle.lean b/lean/OAI/Combinatorics/TreeEdit/RandomCircle.lean new file mode 100644 index 0000000000000000000000000000000000000000..d91682a0f62b201ab5300e7f7f46a9c9e4d6d707 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/RandomCircle.lean @@ -0,0 +1,345 @@ +import OAI.Combinatorics.TreeEdit.CircleSeparation +import OAI.Combinatorics.TreeEdit.WordOperations + +namespace OAI + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical FiniteProbability + +lemma representative_toAddCircle {M : ℕ} [NeZero M] (a : ZMod M) : + representative (ZMod.toAddCircle a) = (a.val : ℝ) / M := by + have hM : (0 : ℝ) < M := by exact_mod_cast NeZero.pos M + have hm : (a.val : ℝ) / M ∈ Set.Ico (0 : ℝ) 1 := + ⟨by positivity, (div_lt_one hM).mpr (by exact_mod_cast a.val_lt)⟩ + have he : (representative (ZMod.toAddCircle a) : UnitAddCircle) = ((a.val : ℝ) / M : ℝ) := + (representative_coe _).trans (ZMod.toAddCircle_apply a) + exact (AddCircle.coe_eq_coe_iff_of_mem_Ico (p := (1 : ℝ)) (a := (0 : ℝ)) (by simpa only [Set.mem_Ico, zero_add] using representative_mem (ZMod.toAddCircle a)) (by simpa only [zero_add] using hm)).mp he + +lemma bin_grid {M R D : ℕ} [NeZero M] [NeZero R] (hD : 0 < D) (hM : M = R * D) (a : ZMod M) : + (bin R (ZMod.toAddCircle a)).val = a.val / D := by + have hR : (R : ℝ) ≠ 0 := by exact_mod_cast (NeZero.ne R) + have hDr : (D : ℝ) ≠ 0 := by exact_mod_cast hD.ne' + change ⌊(R : ℝ) * representative (ZMod.toAddCircle a)⌋₊ = _ + rw [representative_toAddCircle] + have he : (R : ℝ) * ((a.val : ℝ) / M) = (a.val : ℝ) / D := by + have hMr : (M : ℝ) = (R : ℝ) * D := by exact_mod_cast hM + rw [hMr]; field_simp + rw [he] + have hh := Nat.mul_cast_floor_div_cancel (R := ℝ) hD.ne' ((a.val : ℝ) / D) + rw [div_mul_cancel₀ _ hDr, Nat.floor_natCast] at hh + exact hh.symm + +lemma bin_grid_step {M R D : ℕ} [NeZero M] [NeZero R] (hD : 0 < D) (hM : M = R * D) (a : ZMod M) + (ha : a.val % D ≠ D - 1) : bin R (ZMod.toAddCircle a) = bin R (ZMod.toAddCircle (a + 1)) := by + apply Fin.ext + rw [bin_grid hD hM, bin_grid hD hM] + have hval : (a + 1).val = a.val + 1 := by + have hm : a.val + 1 < M := by + by_contra hn + have he : a.val = M - 1 := by have := a.val_lt; omega + have hmod : (M - 1) % D = D - 1 := by + have hR := NeZero.pos R + have he : M - 1 = (R - 1) * D + (D - 1) := by + have := Nat.sub_add_cancel (show 1 ≤ R from hR) + have := Nat.sub_add_cancel (show 1 ≤ D from hD) + have : M - 1 + 1 = M := Nat.sub_add_cancel (NeZero.pos M) + nlinarith + rw [he] + simp only [Nat.add_mod, Nat.mul_mod_left, zero_add, Nat.mod_eq_of_lt (by omega : D - 1 < D)] + exact ha (he ▸ hmod) + have hm1 : 1 < M := by omega + let : Fact (1 < M) := ⟨hm1⟩ + rw [ZMod.val_add, ZMod.val_one, Nat.mod_eq_of_lt hm] + rw [hval] + symm + apply Nat.div_eq_of_lt_le + · exact (Nat.div_mul_le_self a.val D).trans (by omega) + · have hh := Nat.div_add_mod a.val D + have hr := Nat.mod_lt a.val hD + have hr' : a.val % D + 1 < D := by omega + nlinarith + +lemma mean_comp_hom {A B : Type*} [Fintype A] [Fintype B] [AddGroup A] [AddGroup B] + (f : A →+ B) (hf : Function.Surjective f) (g : B → ℝ) : mean (g ∘ f) = mean g := by + change mean (fun a => g (f a)) = mean g + rw [mean_fiberwise] + simp_rw [hom_uniform f hf] + rw [mean, Finset.mul_sum] + +lemma mean_translate {A : Type*} [Fintype A] [AddGroup A] (y : A) (f : A → ℝ) : + mean (fun x => f (x + y)) = mean f := mean_equiv (Equiv.addRight y) f + +noncomputable def mapState {A B : Type} [AddCommGroup A] [AddCommGroup B] {m : ℕ} + (f : A →+ B) : (h : ℕ) → State A m h →+ State B m h + | 0 => f + | h + 1 => AddMonoidHom.pi (fun i : Fin m => (mapState f h).comp (Pi.evalAddMonoidHom _ i)) + +lemma mapState_diagonal {A B : Type} [AddCommGroup A] [AddCommGroup B] {m : ℕ} + (f : A →+ B) (h : ℕ) (a : A) : + mapState (m := m) f h (diagonal (A := A) (m := m) h a) = diagonal (A := B) (m := m) h (f a) := by + induction h with + | zero => rfl + | succ h ih => exact funext fun _ => ih + +noncomputable def sample {M m : ℕ} [NeZero M] (h : ℕ) : State (ZMod M) m h →+ State UnitAddCircle m h := + mapState ZMod.toAddCircle h + +noncomputable def child {A : Type} [AddCommGroup A] {m : ℕ} (h : ℕ) (i : Fin m) : + State A m h →+ State A m (h + 1) := AddMonoidHom.single (fun _ : Fin m => State A m h) i + +noncomputable def sampledWord {I : Type} {g s L M : ℕ} [NeZero M] + (r : I → ℕ) (j : Fin g → I) (T R : ℕ) [NeZero R] + (h : ℕ) (C : Config I L (g * s) h) (x : State (ZMod M) (g * s) h) := + word r j T R h C (sample (M := M) (m := g * s) h x) + +lemma point_grid {M P : ℕ} [NeZero M] (hP : 0 < P) (hPM : P ∣ M) : + ZMod.toAddCircle (M / P : ZMod M) = point P := by + rw [ZMod.toAddCircle_natCast] + dsimp [point] + congr 1 + have hMr : (M : ℝ) ≠ 0 := by exact_mod_cast (NeZero.ne M) + have hPr : (P : ℝ) ≠ 0 := by exact_mod_cast hP.ne' + have he : ((M / P : ℕ) : ℝ) * P = M := by exact_mod_cast Nat.div_mul_cancel hPM + field_simp + linarith + +lemma bin_step_mean {M R D : ℕ} [NeZero M] [NeZero R] (hD : 0 < D) (hM : M = R * D) : + mean (fun a : ZMod M => (ed [bin R (ZMod.toAddCircle a)] [bin R (ZMod.toAddCircle (a + 1))] : ℝ)) ≤ (D : ℝ)⁻¹ := by + classical + let : NeZero D := ⟨hD.ne'⟩ + have hDM : D ∣ M := by rw [hM]; exact dvd_mul_left _ _ + let f : ZMod M →+ ZMod D := (ZMod.castHom hDM (ZMod D)).toAddMonoidHom + have he (a : ZMod M) : a.val % D = D - 1 ↔ f a = (D - 1 : ℕ) := by + apply Iff.trans _ (ZMod.val_injective (n := D)).eq_iff + change a.val % D = D - 1 ↔ (ZMod.castHom hDM (ZMod D) a).val = ((D-1 : ℕ) : ZMod D).val + rw [cast_hom_val hDM, ZMod.val_natCast, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega : D - 1 < D)] + have hh := mean_le (fun a : ZMod M => show + (ed [bin R (ZMod.toAddCircle a)] [bin R (ZMod.toAddCircle (a + 1))] : ℝ) ≤ + (if f a = (D - 1 : ℕ) then 1 else 0) from by + by_cases ha : f a = (D - 1 : ℕ) + · simp only [ha, ↓reduceIte] + have hh : ed [bin R (ZMod.toAddCircle a)] [bin R (ZMod.toAddCircle (a + 1))] ≤ 1 := + ed_le_of_script (EditScript.cons (EditStep.substitute [] [] _ _) (EditScript.nil _)) + exact_mod_cast hh + · simp only [ha, ↓reduceIte] + rw [bin_grid_step hD hM a (fun hz => ha ((he a).mp hz)), ed_self] + norm_num) + have hp := hom_uniform f (ZMod.castHom_surjective hDM) (D - 1 : ℕ) + apply hh.trans_eq + calc + _ = probability (fun a : ZMod M => f a = ((D-1 : ℕ) : ZMod D)) := by + unfold probability + congr 1 + funext a + split_ifs <;> rfl + _ = _ := by simpa only [ZMod.card] using hp + +lemma mean_eval {A : Type*} [Fintype A] [AddCommGroup A] + {m : ℕ} (i : Fin m) (f : A → ℝ) : + mean (fun x : Fin m → A => f (x i)) = mean f := by + exact mean_comp_hom (Pi.evalAddMonoidHom _ i) (fun a => ⟨fun _ => a, rfl⟩) f + +noncomputable def cycle {I : Type} {g s L M : ℕ} [NeZero M] + (r : I → ℕ) (j : Fin g → I) (h : ℕ) (C : Config I L (g * s) (h + 1)) : + State (ZMod M) (g * s) (h + 1) := fun i => diagonal (A := ZMod M) (m := g * s) h + ((coefficient r j C.1 (C.2 i).1 i) • (M / period r j C.1 : ZMod M)) + +lemma sampledWord_succ {I : Type} {g s L M T R : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g → I) (hr : ∀ i, 0 < r i) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) + (h : ℕ) (C : Config I L (g * s) (h + 1)) (x : State (ZMod M) (g * s) (h + 1)) : + sampledWord r j T R (h+1) C x = Words.cycles (fun a i => + sampledWord r j T R h (C.2 i).2 (x i + a.val • cycle (M := M) r j h C i)) := by + unfold sampledWord + simp only [word] + congr 1 + funext a i + apply congrArg (word r j T R h (C.2 i).2) + dsimp [cycle, sample] + change sample (M := M) (m := g*s) h (x i) + + diagonal (A := UnitAddCircle) (m := g*s) h ((a.val * coefficient r j C.1 (C.2 i).1 i) • point (period r j C.1)) = _ + dsimp only [sample] + simp only [map_add, map_nsmul, mapState_diagonal, point_grid (period_pos hr j C.1) (hPM C.1), mul_smul] + +lemma sampledWord_diagonal_step {I : Type} {g s L M T R D : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g → I) (hr : ∀ i, 0 < r i) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) + (hD : 0 < D) (hM : M = R * D) + (h : ℕ) (C : Config I L (g * s) h) : + mean (fun x : State (ZMod M) (g * s) h => + (ed (sampledWord r j T R h C x).val + (sampledWord r j T R h C (x + diagonal (A := ZMod M) (m := g * s) h 1)).val : ℝ)) ≤ + (FiniteTree.length (g * s) T h : ℝ) / D := by + induction h with + | zero => + have hw (x : ZMod M) : (sampledWord r j T R 0 C x).val = [bin R (ZMod.toAddCircle x)] := by + change List.ofFn (fun _ : Fin 1 => bin R (ZMod.toAddCircle x)) = _ + simp [List.ofFn_succ] + simp only [hw] + exact (bin_step_mean hD hM).trans_eq (by simp [FiniteTree.length, one_div]) + | succ h ih => + let f (i : Fin (g*s)) (x : State (ZMod M) (g*s) h) := + (ed (sampledWord r j T R h (C.2 i).2 x).val + (sampledWord r j T R h (C.2 i).2 (x + diagonal (A := ZMod M) (m := g*s) h 1)).val : ℝ) + have hp (x : State (ZMod M) (g*s) (h+1)) : + (ed (sampledWord r j T R (h+1) C x).val + (sampledWord r j T R (h+1) C (x + diagonal (A := ZMod M) (m := g*s) (h+1) 1)).val : ℝ) ≤ + ∑ a : Fin T, ∑ i : Fin (g*s), f i (x i + a.val • cycle (M := M) r j h C i) := by + rw [sampledWord_succ r j hr hPM, sampledWord_succ r j hr hPM] + have hh := Words.ed_cycles (T := T) + (fun a i => sampledWord r j T R h (C.2 i).2 (x i + a.val • cycle (M := M) r j h C i)) + (fun a i => sampledWord r j T R h (C.2 i).2 ((x + diagonal (A := ZMod M) (m := g*s) (h+1) 1) i + a.val • cycle (M := M) r j h C i)) + have he (a : Fin T) (i : Fin (g*s)) : + (x + diagonal (A := ZMod M) (m := g*s) (h+1) 1) i + a.val • cycle (M := M) r j h C i = + (x i + a.val • cycle (M := M) r j h C i) + diagonal (A := ZMod M) (m := g*s) h 1 := by + change x i + diagonal (A := ZMod M) (m := g*s) h 1 + _ = _ + abel + simpa only [he, Nat.cast_sum] using (Nat.cast_le (α := ℝ)).mpr hh + apply (mean_le hp).trans + rw [mean_sum] + calc + _ = ∑ a : Fin T, ∑ i : Fin (g*s), mean (f i) := by + apply Finset.sum_congr rfl + intro a _ + rw [mean_sum] + apply Finset.sum_congr rfl + intro i _ + exact (mean_eval i (fun y => f i (y + a.val • cycle (M := M) r j h C i))).trans + (mean_translate _ (f i)) + _ ≤ ∑ _a : Fin T, ∑ _i : Fin (g*s), (FiniteTree.length (g*s) T h : ℝ) / D := by + apply Finset.sum_le_sum + intro a _ + exact Finset.sum_le_sum fun i _ => ih (C.2 i).2 + _ = _ := by simp [FiniteTree.length, Finset.sum_const, Finset.card_univ]; ring + +end TreeEdit.TorusTree + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical FiniteProbability + +lemma mean_ed_add {A β : Type*} [Fintype A] [AddCommGroup A] (f : A → List β) (u v : A) : + mean (fun x => (ed (f x) (f (x + (u + v))) : ℝ)) ≤ + mean (fun x => (ed (f x) (f (x + u)) : ℝ)) + mean (fun x => (ed (f x) (f (x + v)) : ℝ)) := by + have hh := mean_le (fun x => (Nat.cast_le (α := ℝ)).mpr (ed_triangle (f x) (f (x+u)) (f (x+(u+v))))) + simp only [Nat.cast_add, ← add_assoc] at hh + rw [mean_add, mean_translate u (fun x => (ed (f x) (f (x+v)) : ℝ))] at hh + simpa only [add_assoc] using hh + +lemma mean_ed_nsmul {A β : Type*} [Fintype A] [AddCommGroup A] (f : A → List β) (u : A) (a : ℕ) : + mean (fun x => (ed (f x) (f (x + a • u)) : ℝ)) ≤ + a * mean (fun x => (ed (f x) (f (x + u)) : ℝ)) := by + induction a with + | zero => simp [ed_self, mean] + | succ a ih => + rw [succ_nsmul] + apply (mean_ed_add f _ _).trans + calc + _ ≤ (a : ℝ) * mean (fun x => (ed (f x) (f (x+u)) : ℝ)) + mean (fun x => (ed (f x) (f (x+u)) : ℝ)) := add_le_add ih (le_refl _) + _ = _ := by push_cast; ring + +lemma sampledWord_tiny {I : Type} {g s L M T R D Q J : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g → I) (hr : ∀ i, 0 < r i) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) + (hD : 0 < D) (hQ : 0 < Q) (hMR : M = R * D) (hMQ : M = J * Q) + (h : ℕ) (C : Config I L (g*s) h) (a : ℕ) (ha : a ≤ J) : + mean (fun x : State (ZMod M) (g*s) h => + (ed (sampledWord r j T R h C x).val + (sampledWord r j T R h C (x + diagonal (A := ZMod M) (m := g*s) h (a : ZMod M))).val : ℝ)) ≤ + (FiniteTree.length (g*s) T h : ℝ) * R / Q := by + have he : diagonal (A := ZMod M) (m := g*s) h (a : ZMod M) = a • diagonal (A := ZMod M) (m := g*s) h 1 := by + rw [← map_nsmul]; simp [nsmul_eq_mul] + rw [he] + calc + _ ≤ a * mean (fun x => (ed (sampledWord r j T R h C x).val + (sampledWord r j T R h C (x + diagonal (A := ZMod M) (m := g*s) h 1)).val : ℝ)) := mean_ed_nsmul _ _ _ + _ ≤ (a : ℝ) * ((FiniteTree.length (g*s) T h : ℝ) / D) := + mul_le_mul_of_nonneg_left (sampledWord_diagonal_step r j hr hPM hD hMR h C) (by positivity) + _ ≤ (J : ℝ) * ((FiniteTree.length (g*s) T h : ℝ) / D) := mul_le_mul_of_nonneg_right (by exact_mod_cast ha) (by positivity) + _ = _ := by + have hDr : (D : ℝ) ≠ 0 := by exact_mod_cast hD.ne' + have hQr : (Q : ℝ) ≠ 0 := by exact_mod_cast hQ.ne' + have he : (R : ℝ) * D = (J : ℝ) * Q := by exact_mod_cast hMR.symm.trans hMQ + field_simp + nlinarith + +lemma sampledWord_cycle_cost {I : Type} {g s L M T R : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g → I) (hr : ∀ i, 0 < r i) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) + (h : ℕ) (C : Config I L (g*s) (h+1)) (x : State (ZMod M) (g*s) (h+1)) + (a : ℕ) (ha : a ≤ T) : + ed (sampledWord r j T R (h+1) C x).val + (sampledWord r j T R (h+1) C (x + a • cycle (M := M) r j h C)).val ≤ + 2 * a * ((g*s) * FiniteTree.length (g*s) T h) := by + rw [sampledWord_succ r j hr hPM, sampledWord_succ r j hr hPM] + apply Words.ed_cycles_shift ha + intro b i + apply congrArg (sampledWord r j T R h (C.2 i).2) + change x i + (b.val + a) • cycle (M := M) r j h C i = + (x i + a • cycle (M := M) r j h C i) + b.val • cycle (M := M) r j h C i + rw [add_nsmul] + abel + +lemma cycle_period {I : Type} {g s L M : ℕ} [NeZero M] + (r : I → ℕ) (j : Fin g → I) (h : ℕ) (C : Config I L (g*s) (h+1)) + (hPM : period r j C.1 ∣ M) : period r j C.1 • cycle (M := M) r j h C = 0 := by + funext i + change period r j C.1 • diagonal (A := ZMod M) (m := g*s) h + ((coefficient r j C.1 (C.2 i).1 i) • (M / period r j C.1 : ZMod M)) = 0 + rw [← map_nsmul, smul_comm] + have he : period r j C.1 • (M / period r j C.1 : ZMod M) = 0 := by + rw [nsmul_eq_mul, ← Nat.cast_mul, Nat.mul_div_cancel' hPM] + exact ZMod.natCast_self M + rw [he, smul_zero, map_zero] + +end TreeEdit.TorusTree + +namespace TreeEdit.TorusTree +open scoped BigOperators +open Classical FiniteProbability + +lemma sampledWord_child_mean {I : Type} {g s L M T R : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g → I) (hr : ∀ i, 0 < r i) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) + (h : ℕ) (C : Config I L (g*s) (h+1)) (i : Fin (g*s)) (z : State (ZMod M) (g*s) h) : + mean (fun x : State (ZMod M) (g*s) (h+1) => + (ed (sampledWord r j T R (h+1) C x).val + (sampledWord r j T R (h+1) C (x + child (A := ZMod M) h i z)).val : ℝ)) ≤ + T * mean (fun x : State (ZMod M) (g*s) h => + (ed (sampledWord r j T R h (C.2 i).2 x).val + (sampledWord r j T R h (C.2 i).2 (x + z)).val : ℝ)) := by + let f (x : State (ZMod M) (g*s) h) := + (ed (sampledWord r j T R h (C.2 i).2 x).val + (sampledWord r j T R h (C.2 i).2 (x + z)).val : ℝ) + have hp (x : State (ZMod M) (g*s) (h+1)) : + (ed (sampledWord r j T R (h+1) C x).val + (sampledWord r j T R (h+1) C (x + child (A := ZMod M) h i z)).val : ℝ) ≤ + ∑ a : Fin T, f (x i + a.val • cycle (M := M) r j h C i) := by + rw [sampledWord_succ r j hr hPM, sampledWord_succ r j hr hPM] + have hh := Words.ed_cycles (T := T) + (fun a v => sampledWord r j T R h (C.2 v).2 (x v + a.val • cycle (M := M) r j h C v)) + (fun a v => sampledWord r j T R h (C.2 v).2 ((x + child (A := ZMod M) h i z) v + a.val • cycle (M := M) r j h C v)) + apply (Nat.cast_le (α := ℝ)).mpr hh |>.trans + simp only [Nat.cast_sum] + apply Finset.sum_le_sum + intro a _ + rw [Finset.sum_eq_single i] + · simp only [child, Pi.add_apply, AddMonoidHom.single_apply, Pi.single_eq_same] + change (ed _ (sampledWord r j T R h (C.2 i).2 ((x i + z) + a.val • cycle (M := M) r j h C i)).val : ℝ) ≤ _ + rw [add_right_comm (x i) z] + · intro v _ hvi + simp [child, hvi, ed_self] + · simp + apply (mean_le hp).trans_eq + rw [mean_sum] + calc + _ = ∑ _a : Fin T, mean f := by + apply Finset.sum_congr rfl + intro a _ + exact (mean_eval i (fun y => f (y + a.val • cycle (M := M) r j h C i))).trans (mean_translate _ f) + _ = _ := by simp [f] + +end TreeEdit.TorusTree + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/RandomCode.lean b/lean/OAI/Combinatorics/TreeEdit/RandomCode.lean new file mode 100644 index 0000000000000000000000000000000000000000..0aae0d104b43515874145cb7a5055338772e08ee --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/RandomCode.lean @@ -0,0 +1,390 @@ +import OAI.Combinatorics.TreeEdit.SegmentComparison + +namespace OAI + +namespace TreeEdit + +universe u + +variable {α : Type u} {x y z : List α} + +theorem card_orderEmb_le_choose (a s : ℕ) : + Fintype.card (Fin s ↪o Fin a) ≤ a.choose s := by + classical + let rangeSet : (Fin s ↪o Fin a) → Finset (Fin a) := + fun f => Finset.univ.image f + have hcard (f : Fin s ↪o Fin a) : (rangeSet f).card = s := by + simp [rangeSet, Finset.card_image_of_injective _ f.injective] + let F : (Fin s ↪o Fin a) → (Finset.univ : Finset (Fin a)).powersetCard s := + fun f => ⟨rangeSet f, Finset.mem_powersetCard.mpr ⟨Finset.subset_univ _, hcard f⟩⟩ + have hF : Function.Injective F := by + intro f g hfg + have he : rangeSet f = rangeSet g := congrArg Subtype.val hfg + have hf := Finset.orderEmbOfFin_unique' (hcard f) + (f := f) (fun i => Finset.mem_image.mpr ⟨i, Finset.mem_univ i, rfl⟩) + have hg := Finset.orderEmbOfFin_unique' (hcard f) + (f := g) (fun i => by rw [he]; exact Finset.mem_image.mpr ⟨i, Finset.mem_univ i, rfl⟩) + exact hf.trans hg.symm + simpa using Fintype.card_le_of_injective F hF + +theorem card_prescribed_bits {P : ℕ} (s : Finset (Fin P)) (pattern : Fin P → Bool) : + (Finset.univ.filter (fun w : Fin P → Bool => ∀ i ∈ s, w i = pattern i)).card ≤ + 2 ^ (P - s.card) := by + classical + let T := Finset.univ.filter (fun w : Fin P → Bool => ∀ i ∈ s, w i = pattern i) + let F : T → (↥(sᶜ) → Bool) := fun w i => w.val i.val + have hF : Function.Injective F := by + intro v w hvw + apply Subtype.ext + funext i + by_cases hi : i ∈ s + · exact ((Finset.mem_filter.mp v.property).2 i hi).trans + ((Finset.mem_filter.mp w.property).2 i hi).symm + · exact congrFun hvw ⟨i, Finset.mem_compl.mpr hi⟩ + have hh := Fintype.card_le_of_injective F hF + simpa only [Fintype.card_coe, Fintype.card_fun, Fintype.card_bool, + Finset.card_compl, Fintype.card_fin, T] using hh + +theorem choose_weight_bound (a s : ℕ) (hs : s ≤ a) : + a.choose s * 16 ^ s ≤ 17 ^ a := by + have hh := Finset.single_le_sum (f := fun j => 16 ^ j * 1 ^ (a - j) * a.choose j) + (s := Finset.range (a + 1)) (fun _ _ => Nat.zero_le _) (Finset.mem_range.mpr (by omega : s < a + 1)) + have hp : (17 : ℕ) ^ a = ∑ j ∈ Finset.range (a + 1), 16 ^ j * 1 ^ (a - j) * a.choose j := by + simpa using (add_pow (16 : ℕ) 1 a) + rw [← hp] at hh + simpa [Nat.mul_comm] using hh + +theorem choose_matching_bound (a s t : ℕ) (hs : s ≤ a) + (hdense : 99 * a ≤ 100 * s) (ht : 4 * t ≤ a) : + (a.choose s) ^ 2 * 2 ^ t ≤ 2 ^ s := by + have hweight := choose_weight_bound a s hs + have hon : (17 : ℕ) ^ 4 ≤ 2 ^ 17 := by norm_num + have hp : (a.choose s) ^ 4 * 2 ^ (16 * s) ≤ 2 ^ (17 * a) := by + calc + _ = (a.choose s * 16 ^ s) ^ 4 := by + rw [Nat.mul_pow, ← Nat.pow_mul] + have h16 : (16 : ℕ) = 2 ^ 4 := by norm_num + rw [h16, ← Nat.pow_mul] + norm_num only [Nat.reducePow] + congr 2; omega + _ ≤ (17 ^ a) ^ 4 := Nat.pow_le_pow_left hweight 4 + _ = (17 ^ 4) ^ a := by rw [← Nat.pow_mul, ← Nat.pow_mul]; congr 1; omega + _ ≤ (2 ^ 17) ^ a := Nat.pow_le_pow_left hon a + _ = 2 ^ (17 * a) := by rw [← Nat.pow_mul] + have hexp : 17 * a + 2 * t ≤ 18 * s := by omega + have hpow := Nat.mul_le_mul_right (2 ^ (2 * t)) hp + have hbig : (a.choose s) ^ 4 * 2 ^ (2 * t) * 2 ^ (16 * s) ≤ + 2 ^ (2 * s) * 2 ^ (16 * s) := by + calc + _ = ((a.choose s) ^ 4 * 2 ^ (16 * s)) * 2 ^ (2 * t) := by ring + _ ≤ 2 ^ (17 * a) * 2 ^ (2 * t) := hpow + _ = 2 ^ (17 * a + 2 * t) := (Nat.pow_add _ _ _).symm + _ ≤ 2 ^ (18 * s) := Nat.pow_le_pow_right (by decide) hexp + _ = 2 ^ (2 * s) * 2 ^ (16 * s) := by rw [← Nat.pow_add]; congr 1; omega + have hc : (a.choose s) ^ 4 * 2 ^ (2 * t) ≤ 2 ^ (2 * s) := + Nat.le_of_mul_le_mul_right hbig (by positivity) + have hsq : ((a.choose s) ^ 2 * 2 ^ t) ^ 2 ≤ (2 ^ s) ^ 2 := by + simpa only [Nat.mul_pow, ← Nat.pow_mul, Nat.mul_comm t 2, + Nat.mul_comm s 2, Nat.reduceMul] using hc + exact (Nat.pow_le_pow_iff_left (by decide : 2 ≠ 0)).mp hsq + +theorem card_agreement_embedding {P s : ℕ} (f : Fin s ↪ Fin P) (bits : Fin s → Bool) : + (Finset.univ.filter (fun w : Fin P → Bool => ∀ i, w (f i) = bits i)).card ≤ + 2 ^ (P - s) := by + classical + let S := Finset.univ.image f + let T := Finset.univ.filter (fun w : Fin P → Bool => ∀ i, w (f i) = bits i) + let F : T → (↥(Sᶜ) → Bool) := fun w i => w.val i.val + have hF : Function.Injective F := by + intro v w hvw + apply Subtype.ext + funext j + by_cases hj : j ∈ S + · obtain ⟨i, _, rfl⟩ := Finset.mem_image.mp hj + exact ((Finset.mem_filter.mp v.property).2 i).trans + ((Finset.mem_filter.mp w.property).2 i).symm + · exact congrFun hvw ⟨j, Finset.mem_compl.mpr hj⟩ + have hS : S.card = s := by simp [S, Finset.card_image_of_injective _ f.injective] + have hh := Fintype.card_le_of_injective F hF + simpa only [Fintype.card_coe, Fintype.card_fun, Fintype.card_bool, + Finset.card_compl, Fintype.card_fin, T, hS] using hh + +def segmentPositions {P a : ℕ} (p : ℕ) (hp : p + a ≤ P) : Fin a ↪o Fin P := + OrderEmbedding.ofStrictMono (fun i => ⟨p + i.val, by omega⟩) + (by intro i j hij; change p + i.val < p + j.val; omega) + +theorem card_matched_segments {P a s : ℕ} (v : Fin P → Bool) + (p q : ℕ) (hp : p + a ≤ P) (hq : q + a ≤ P) : + (Finset.univ.filter (fun w : Fin P → Bool => + ∃ f g : Fin s ↪o Fin a, ∀ i, + w (segmentPositions q hq (g i)) = v (segmentPositions p hp (f i)))).card ≤ + (a.choose s) ^ 2 * 2 ^ (P - s) := by + classical + let T := fun fg : (Fin s ↪o Fin a) × (Fin s ↪o Fin a) => + Finset.univ.filter (fun w : Fin P → Bool => ∀ i, + w (segmentPositions q hq (fg.2 i)) = v (segmentPositions p hp (fg.1 i))) + have hT (fg) : (T fg).card ≤ 2 ^ (P - s) := + card_agreement_embedding (fg.2.comp (segmentPositions q hq)).toEmbedding _ + have he : Finset.univ.filter (fun w : Fin P → Bool => + ∃ f g : Fin s ↪o Fin a, ∀ i, + w (segmentPositions q hq (g i)) = v (segmentPositions p hp (f i))) = + Finset.univ.biUnion T := by + ext w + simp only [Finset.mem_filter, Finset.mem_univ, true_and, + Finset.mem_biUnion, T, Prod.exists] + rw [he] + calc + _ ≤ ∑ fg ∈ Finset.univ, (T fg).card := Finset.card_biUnion_le + _ ≤ ∑ _fg : (Fin s ↪o Fin a) × (Fin s ↪o Fin a), 2 ^ (P - s) := + Finset.sum_le_sum (fun fg _ => hT fg) + _ = (Fintype.card (Fin s ↪o Fin a)) ^ 2 * 2 ^ (P - s) := by simp [sq] + _ ≤ (a.choose s) ^ 2 * 2 ^ (P - s) := + Nat.mul_le_mul_right _ (Nat.pow_le_pow_left (card_orderEmb_le_choose a s) 2) + +theorem large_lcs_segment_witness {P a s : ℕ} (v w : Fin P → Bool) + (p q : ℕ) (hp : p + a ≤ P) (hq : q + a ≤ P) + (hs : s ≤ lcs (segment (vectorWord v).val p a) (segment (vectorWord w).val q a)) : + ∃ f g : Fin s ↪o Fin a, ∀ i, + w (segmentPositions q hq (g i)) = v (segmentPositions p hp (f i)) := by + let X := segment (vectorWord v).val p a + let Y := segment (vectorWord w).val q a + have hX : X.length = a := length_segment _ (by simpa only [vectorWord, List.length_ofFn] using hp) + have hY : Y.length = a := length_segment _ (by simpa only [vectorWord, List.length_ofFn] using hq) + obtain ⟨A⟩ := exists_lcs_alignment X Y + let e := Fin.castLEOrderEmb hs + let f := (e.comp A.left).comp (Fin.castOrderIso hX).toOrderEmbedding + let g := (e.comp A.right).comp (Fin.castOrderIso hY).toOrderEmbedding + refine ⟨f, g, ?_⟩ + intro i + have h := A.agree (e i) + simp only [X, Y, List.get_eq_getElem] at h + rw [segment_get, segment_get] at h + change w ⟨q + (A.right (e i)).val, _⟩ = v ⟨p + (A.left (e i)).val, _⟩ + simp only [vectorWord, List.getElem_ofFn] at h + convert h.symm using 2 + +theorem card_bad_segment {P a t : ℕ} (v : Fin P → Bool) + (p q : ℕ) (hp : p + a ≤ P) (hq : q + a ≤ P) (ht : 4 * t ≤ a) : + (Finset.univ.filter (fun w : Fin P → Bool => + 99 * a < 100 * lcs (segment (vectorWord v).val p a) + (segment (vectorWord w).val q a))).card * 2 ^ t ≤ 2 ^ P := by + classical + let s := a - a / 100 + have hsa : s ≤ a := Nat.sub_le _ _ + have hdense : 99 * a ≤ 100 * s := by dsimp [s]; omega + have hsub : Finset.univ.filter (fun w : Fin P → Bool => + 99 * a < 100 * lcs (segment (vectorWord v).val p a) + (segment (vectorWord w).val q a)) ⊆ + Finset.univ.filter (fun w : Fin P → Bool => + ∃ f g : Fin s ↪o Fin a, ∀ i, + w (segmentPositions q hq (g i)) = v (segmentPositions p hp (f i))) := by + intro w hw + have hw' := (Finset.mem_filter.mp hw).2 + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ w, large_lcs_segment_witness v w p q hp hq ?_⟩ + dsimp [s] + omega + have hc := (Finset.card_le_card hsub).trans (card_matched_segments v p q hp hq) + have hentropy := choose_matching_bound a s t hsa hdense ht + calc + _ ≤ ((a.choose s) ^ 2 * 2 ^ (P - s)) * 2 ^ t := Nat.mul_le_mul_right _ hc + _ = ((a.choose s) ^ 2 * 2 ^ t) * 2 ^ (P - s) := by ring + _ ≤ 2 ^ s * 2 ^ (P - s) := Nat.mul_le_mul_right _ hentropy + _ = 2 ^ P := by + rw [← Nat.pow_add, Nat.add_sub_of_le (hsa.trans (by omega : a ≤ P))] + +def VectorSeparated {P : ℕ} (cutoff : ℕ) (v w : Fin P → Bool) : Prop := + ∀ p q a : ℕ, cutoff ≤ a → p + a ≤ P → q + a ≤ P → + 100 * lcs (segment (vectorWord v).val p a) (segment (vectorWord w).val q a) ≤ 99 * a + +theorem VectorSeparated.symm {P cutoff : ℕ} {v w : Fin P → Bool} + (h : VectorSeparated cutoff v w) : VectorSeparated cutoff w v := by + intro p q a ha hp hq + rw [lcs_comm] + exact h q p a ha hq hp + +attribute [local instance] Classical.propDecidable + +theorem card_bad_vector {P cutoff t : ℕ} (v : Fin P → Bool) (ht : 4 * t ≤ cutoff) : + (Finset.univ.filter (fun w : Fin P → Bool => ¬ VectorSeparated cutoff v w)).card * 2 ^ t ≤ + (P + 1) ^ 3 * 2 ^ P := by + classical + let I := Fin (P + 1) × Fin (P + 1) × Fin (P + 1) + let valid := fun j : I => cutoff ≤ j.2.2.val ∧ + j.1.val + j.2.2.val ≤ P ∧ j.2.1.val + j.2.2.val ≤ P + let T := fun j : I => if valid j then + Finset.univ.filter (fun w : Fin P → Bool => + 99 * j.2.2.val < 100 * lcs (segment (vectorWord v).val j.1.val j.2.2.val) + (segment (vectorWord w).val j.2.1.val j.2.2.val)) else ∅ + have hT (j : I) : (T j).card * 2 ^ t ≤ 2 ^ P := by + by_cases hj : valid j + · simp only [T, ite_eq_left hj] + exact card_bad_segment v _ _ hj.2.1 hj.2.2 (ht.trans hj.1) + · simp [T, hj] + have hsub : Finset.univ.filter (fun w : Fin P → Bool => ¬ VectorSeparated cutoff v w) ⊆ + Finset.univ.biUnion T := by + intro w hw + have hh := (Finset.mem_filter.mp hw).2 + simp only [VectorSeparated, not_forall, not_le] at hh + obtain ⟨p, q, a, ha, hp, hq, hbad⟩ := hh + let j : I := (⟨p, by omega⟩, ⟨q, by omega⟩, ⟨a, by omega⟩) + have hj : valid j := ⟨ha, hp, hq⟩ + apply Finset.mem_biUnion.mpr + refine ⟨j, Finset.mem_univ j, ?_⟩ + simp only [T, ite_eq_left hj] + exact Finset.mem_filter.mpr ⟨Finset.mem_univ w, hbad⟩ + calc + _ ≤ (Finset.univ.biUnion T).card * 2 ^ t := + Nat.mul_le_mul_right _ (Finset.card_le_card hsub) + _ ≤ (∑ j : I, (T j).card) * 2 ^ t := Nat.mul_le_mul_right _ Finset.card_biUnion_le + _ = ∑ j : I, ((T j).card * 2 ^ t) := Finset.sum_mul _ _ _ + _ ≤ ∑ _j : I, 2 ^ P := Finset.sum_le_sum (fun j _ => hT j) + _ = (P + 1) ^ 3 * 2 ^ P := by simp only [Finset.sum_const, Finset.card_univ, + Fintype.card_prod, Fintype.card_fin, smul_eq_mul, I]; ring + +theorem exists_separated_vectors (P cutoff t K : ℕ) (ht : 4 * t ≤ cutoff) + (hcount : K * (P + 1) ^ 3 < 2 ^ t) : + ∃ c : Fin K → (Fin P → Bool), ∀ i j, i ≠ j → VectorSeparated cutoff (c i) (c j) := by + classical + induction K with + | zero => exact ⟨Fin.elim0, fun i => Fin.elim0 i⟩ + | succ K ih => + have hK : K * (P + 1) ^ 3 < 2 ^ t := lt_of_le_of_lt + (Nat.mul_le_mul_right _ (Nat.le_succ K)) hcount + obtain ⟨c, hc⟩ := ih hK + let B := Finset.univ.biUnion (fun i : Fin K => + Finset.univ.filter (fun w : Fin P → Bool => ¬ VectorSeparated cutoff (c i) w)) + have hB : B.card * 2 ^ t ≤ K * (P + 1) ^ 3 * 2 ^ P := by + calc + _ ≤ (∑ i : Fin K, (Finset.univ.filter (fun w : Fin P → Bool => + ¬ VectorSeparated cutoff (c i) w)).card) * 2 ^ t := + Nat.mul_le_mul_right _ Finset.card_biUnion_le + _ = ∑ i : Fin K, ((Finset.univ.filter (fun w : Fin P → Bool => + ¬ VectorSeparated cutoff (c i) w)).card * 2 ^ t) := Finset.sum_mul _ _ _ + _ ≤ ∑ _i : Fin K, ((P + 1) ^ 3 * 2 ^ P) := + Finset.sum_le_sum (fun i _ => card_bad_vector (c i) ht) + _ = K * (P + 1) ^ 3 * 2 ^ P := by simp [Nat.mul_assoc] + have hlt : B.card < (Finset.univ : Finset (Fin P → Bool)).card := by + have hh : B.card * 2 ^ t < 2 ^ t * 2 ^ P := + hB.trans_lt (Nat.mul_lt_mul_of_pos_right hK (by positivity)) + rw [Nat.mul_comm (2 ^ t)] at hh + have hh' := Nat.lt_of_mul_lt_mul_right hh + simpa using hh' + have hnot : ¬ (Finset.univ : Finset (Fin P → Bool)) ⊆ B := by + intro hsub + exact (not_le_of_gt hlt) (Finset.card_le_card hsub) + obtain ⟨w, _, hw⟩ := Finset.not_subset.mp hnot + have hwc (i : Fin K) : VectorSeparated cutoff (c i) w := by + by_contra hn + apply hw + exact Finset.mem_biUnion.mpr ⟨i, Finset.mem_univ i, + Finset.mem_filter.mpr ⟨Finset.mem_univ w, hn⟩⟩ + refine ⟨Fin.cons w c, ?_⟩ + intro i j + refine Fin.cases ?_ (fun i => ?_) i + · refine Fin.cases ?_ (fun j => ?_) j + · intro hij; exact (hij rfl).elim + · intro _; exact (hwc j).symm + · refine Fin.cases ?_ (fun j => ?_) j + · intro _; exact hwc i + · intro hij; exact hc i j (by intro h; exact hij (congrArg Fin.succ h)) + +theorem exists_segment_code {Γ : Type u} [Fintype Γ] (P cutoff t : ℕ) + (ht : 4 * t ≤ cutoff) (hcount : Fintype.card Γ * (P + 1) ^ 3 < 2 ^ t) : + ∃ c : Γ → Word Bool P, SegmentCode c cutoff := by + obtain ⟨c, hc⟩ := exists_separated_vectors P cutoff t (Fintype.card Γ) ht hcount + let e := Fintype.equivFin Γ + refine ⟨fun a => vectorWord (c (e a)), ?_⟩ + intro a b hab p q len hlen hp hq + exact hc (e a) (e b) (fun h => hab (e.injective h)) p q len hlen hp hq + +noncomputable def sourceCodeCutoff (M : ℕ) : ℕ := + ⌈120 * (Real.log (M : ℝ) / Real.log 2)⌉₊ + +theorem sourceCodeCutoff_bounds {M : ℕ} (hM : 2 ≤ M) : + 120 * Nat.log 2 M ≤ sourceCodeCutoff M ∧ + sourceCodeCutoff M ≤ 120 * (Nat.log 2 M + 1) := by + have hM0 : M ≠ 0 := by omega + have hlog : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hp := Nat.pow_log_le_self 2 hM0 + have hq := Nat.lt_pow_succ_log_self (by decide : 1 < 2) M + have hp' : (2 : ℝ) ^ Nat.log 2 M ≤ (M : ℝ) := by exact_mod_cast hp + have hq' : (M : ℝ) < (2 : ℝ) ^ (Nat.log 2 M + 1) := by exact_mod_cast hq + have hl := Real.log_le_log (by positivity : (0 : ℝ) < 2 ^ Nat.log 2 M) hp' + have hu := Real.log_lt_log (by exact_mod_cast (by omega : 0 < M)) hq' + rw [Real.log_pow] at hl hu + have hlo : (Nat.log 2 M : ℝ) ≤ Real.log (M : ℝ) / Real.log 2 := + (le_div_iff₀ hlog).mpr hl + have hup : Real.log (M : ℝ) / Real.log 2 ≤ (Nat.log 2 M + 1 : ℕ) := + (div_le_iff₀ hlog).mpr hu.le + constructor + · have hh := Nat.le_ceil (120 * (Real.log (M : ℝ) / Real.log 2)) + have hc : (120 : ℝ) * (Nat.log 2 M : ℝ) ≤ (sourceCodeCutoff M : ℝ) := by + exact (mul_le_mul_of_nonneg_left hlo (by norm_num)).trans hh + exact_mod_cast hc + · apply Nat.ceil_le.mpr + have hh := mul_le_mul_of_nonneg_left hup (by norm_num : (0 : ℝ) ≤ 120) + exact_mod_cast hh + +theorem cutoff_dyadic_domination {n : ℕ} (hn : 16 ≤ n) : + 480 * (n + 1) ≤ 2 ^ n := by + induction n, hn using Nat.le_induction with + | base => norm_num + | succ n hn ih => + rw [Nat.pow_succ] + omega + +theorem sourceCodeCutoff_absorb {M : ℕ} (hM : 2 ^ 16 ≤ M) : + 4 * M * sourceCodeCutoff M ≤ M ^ 2 := by + have hM2 : 2 ≤ M := by norm_num at hM; omega + have hn : 16 ≤ Nat.log 2 M := Nat.le_log_of_pow_le (by decide) hM + have hdom := (cutoff_dyadic_domination hn).trans (Nat.pow_log_le_self 2 (by omega : M ≠ 0)) + have hc := (sourceCodeCutoff_bounds hM2).2 + calc + _ ≤ 4 * M * (120 * (Nat.log 2 M + 1)) := Nat.mul_le_mul_left _ hc + _ = M * (480 * (Nat.log 2 M + 1)) := by ring + _ ≤ M * M := Nat.mul_le_mul_left M hdom + _ = M ^ 2 := (sq M).symm + +theorem polynomial_code_count {M : ℕ} (hM : 2 ≤ M) : + M * (M ^ 2 + 1) ^ 3 < 2 ^ (8 * (Nat.log 2 M + 1) + 4) := by + have hsq : M ^ 2 + 1 ≤ 2 * M ^ 2 := by nlinarith + have hpow : M ≤ 2 ^ (Nat.log 2 M + 1) := (Nat.lt_pow_succ_log_self (by decide : 1 < 2) M).le + calc + _ ≤ M * (2 * M ^ 2) ^ 3 := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left hsq 3) + _ = 8 * M ^ 7 := by ring + _ ≤ 8 * (2 ^ (Nat.log 2 M + 1)) ^ 7 := + Nat.mul_le_mul_left _ (Nat.pow_le_pow_left hpow 7) + _ = 2 ^ ((Nat.log 2 M + 1) * 7 + 3) := by + rw [Nat.pow_add 2 ((Nat.log 2 M + 1) * 7) 3, Nat.pow_mul] + norm_num + ring + _ < 2 ^ (8 * (Nat.log 2 M + 1) + 4) := + Nat.pow_lt_pow_right (by decide) (by omega) + +theorem source_segment_code_exists {Γ : Type u} [Fintype Γ] {M : ℕ} + (hM : 2 ≤ M) (hK : Fintype.card Γ ≤ M) : + ∃ c : Γ → Word Bool (M ^ 2), SegmentCode c (sourceCodeCutoff M) := by + let t := 8 * (Nat.log 2 M + 1) + 4 + have hn : 1 ≤ Nat.log 2 M := Nat.log_pos (by decide) hM + have hcut := (sourceCodeCutoff_bounds hM).1 + have ht : 4 * t ≤ sourceCodeCutoff M := by dsimp [t]; omega + apply exists_segment_code (M ^ 2) (sourceCodeCutoff M) t ht + exact (Nat.mul_le_mul_right _ hK).trans_lt (polynomial_code_count hM) + +theorem binary_conversion : FixedLengthBinaryConversion.{u} := by + refine ⟨2 ^ 16, ?_⟩ + intro M hM Γ inst hK₁ hK + have hM2 : 2 ≤ M := by norm_num at hM; omega + obtain ⟨c, hc⟩ := source_segment_code_exists hM2 hK + refine ⟨c, ?_⟩ + intro x y + have hlen (z : Word Γ M) : (encode c z.val).length = M ^ 3 := by + rw [length_encode, z.property] + ring + refine ⟨hlen x, hlen y, ?_⟩ + exact code_edit_comparison (by positivity : 0 < M ^ 2) (sourceCodeCutoff_absorb hM) c hc x y + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/SampledSpectrum.lean b/lean/OAI/Combinatorics/TreeEdit/SampledSpectrum.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f989b0473f24d3bf95cf5ef1ec601fc271963e3 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/SampledSpectrum.lean @@ -0,0 +1,299 @@ +import OAI.Combinatorics.TreeEdit.CircleFourier + +namespace OAI + +namespace TreeEdit.TorusFourier +open scoped BigOperators +open Classical TorusTree FiniteFourier FiniteProbability + +noncomputable def high {M m : ℕ} [NeZero M] (h Q : ℕ) (χ : AddChar (State (ZMod M) m h) ℂ) : ℝ := + if (Q : ℝ) ≤ |(centered (summary h χ) : ℝ)| then 1 else 0 + +noncomputable def highMass {M m : ℕ} [NeZero M] (h Q : ℕ) (H : AddChar (State (ZMod M) m h) ℂ → ℝ) : ℝ := + ∑ χ, high h Q χ * H χ + +lemma high_nonneg {M m : ℕ} [NeZero M] (h Q : ℕ) (χ : AddChar (State (ZMod M) m h) ℂ) : 0 ≤ high h Q χ := by + unfold high; split_ifs <;> norm_num + +lemma active_summary {M m : ℕ} [NeZero M] (h : ℕ) (χ : AddChar (State (ZMod M) m h) ℂ) : + active χ (diagonal (A := ZMod M) (m := m) h 1) = if summary h χ = 0 then 0 else 1 := by + have he : χ (diagonal (A := ZMod M) (m := m) h 1) = 1 ↔ summary h χ = 0 := character_one (summary h χ) + unfold active + simp only [he] + +lemma branch_multiplier {I : Type} {g s L M b e K Q : ℕ} [NeZero M] (r : I → ℕ) + (hr : ∀ i, Nat.Prime (r i)) (hinj : Function.Injective r) (j : Fin g ↪ I) + (hb : 1 ≤ b) (hlower : ∀ i, b ≤ r i) (hQ : Q ≤ b^e) (hg : e+K ≤ g) + (hM : (g*s+1)*Q < M) (h : ℕ) (C : Config I L (g*s) (h+1)) + (hPM : period r j C.1 ∣ M) (χ : AddChar (State (ZMod M) (g*s) (h+1)) ℂ) : + (K : ℝ) * active χ (diagonal (A := ZMod M) (m := g*s) (h+1) 1) ≤ + (∑ i : Fin (g*s), active (χ.compAddMonoidHom (child (A := ZMod M) h i)) (diagonal (A := ZMod M) (m := g*s) h 1)) + + K * (high (h+1) Q χ + (∑ i : Fin (g*s), high h Q (χ.compAddMonoidHom (child (A := ZMod M) h i))) + + active χ (cycle (M := M) r j h C)) := by + let S := ∑ i : Fin (g*s), active (χ.compAddMonoidHom (child (A := ZMod M) h i)) (diagonal (A := ZMod M) (m := g*s) h 1) + let E := ∑ i : Fin (g*s), high h Q (χ.compAddMonoidHom (child (A := ZMod M) h i)) + have hS : 0 ≤ S := Finset.sum_nonneg fun i _ => active_nonneg _ _ + have hE : 0 ≤ E := Finset.sum_nonneg fun i _ => high_nonneg _ _ _ + have hA := active_nonneg χ (cycle (M := M) r j h C) + have hH := high_nonneg (h+1) Q χ + change _ ≤ S + K * (high (h+1) Q χ + E + active χ (cycle (M := M) r j h C)) + rw [active_summary] + split_ifs with hn + · simp only [mul_zero] + exact add_nonneg hS (mul_nonneg (Nat.cast_nonneg (α := ℝ) K) (add_nonneg (add_nonneg hH hE) hA)) + · simp only [mul_one] + by_cases hp : (Q : ℝ) ≤ |(centered (summary (h+1) χ) : ℝ)| + · rw [high, ite_eq_left hp] + nlinarith [Nat.cast_nonneg (α := ℝ) K] + by_cases hc : ∃ i : Fin (g*s), (Q : ℝ) ≤ |(centered (summary h (χ.compAddMonoidHom (child (A := ZMod M) h i))) : ℝ)| + · obtain ⟨i, hi⟩ := hc + have hei : 1 ≤ E := by + calc + 1 = high h Q (χ.compAddMonoidHom (child (A := ZMod M) h i)) := by simp only [high, ite_eq_left hi] + _ ≤ E := Finset.single_le_sum (f := fun v => high h Q (χ.compAddMonoidHom (child (A := ZMod M) h v))) (fun v _ => high_nonneg _ _ _) (Finset.mem_univ i) + nlinarith [Nat.cast_nonneg (α := ℝ) K] + by_cases hχ : χ (cycle (M := M) r j h C) = 1 + · have hh := branch_summaries r hr hinj j hb hlower hQ hg hM h C hPM χ (lt_of_not_ge hp) + (fun i => lt_of_not_ge (fun hi => hc ⟨i,hi⟩)) hχ hn + have hs : (K : ℝ) ≤ S := by + dsimp [S] + simp_rw [active_summary] + have he : (∑ i : Fin (g*s), if summary h (χ.compAddMonoidHom (child (A := ZMod M) h i)) = 0 then (0 : ℝ) else 1) = + ((Finset.univ.filter (fun i : Fin (g*s) => summary h (χ.compAddMonoidHom (child (A := ZMod M) h i)) ≠ 0)).card : ℝ) := by + simpa only [ite_not] using (Finset.sum_boole (fun i : Fin (g*s) => summary h (χ.compAddMonoidHom (child (A := ZMod M) h i)) ≠ 0) Finset.univ) + rw [he] + exact_mod_cast hh + nlinarith [Nat.cast_nonneg (α := ℝ) K] + · rw [active, ite_eq_right hχ] + nlinarith [Nat.cast_nonneg (α := ℝ) K] + +lemma branch_mass {I : Type} {g s L M b e K Q : ℕ} [NeZero M] (r : I → ℕ) + (hr : ∀ i, Nat.Prime (r i)) (hinj : Function.Injective r) (j : Fin g ↪ I) + (hb : 1 ≤ b) (hlower : ∀ i, b ≤ r i) (hQ : Q ≤ b^e) (hg : e+K ≤ g) + (hM : (g*s+1)*Q < M) (h : ℕ) (C : Config I L (g*s) (h+1)) + (hPM : period r j C.1 ∣ M) (H : AddChar (State (ZMod M) (g*s) (h+1)) ℂ → ℝ) (hH : ∀ χ, 0 ≤ H χ) : + (K : ℝ) * activeMass H (diagonal (A := ZMod M) (m := g*s) (h+1) 1) ≤ + (∑ i : Fin (g*s), activeMass (pushSpectrum H (child (A := ZMod M) h i)) (diagonal (A := ZMod M) (m := g*s) h 1)) + + K * (highMass (h+1) Q H + (∑ i : Fin (g*s), highMass h Q (pushSpectrum H (child (A := ZMod M) h i))) + + activeMass H (cycle (M := M) r j h C)) := by + have hh := Finset.sum_le_sum (s := Finset.univ) (fun χ _ => mul_le_mul_of_nonneg_right + (branch_multiplier r hr hinj j hb hlower hQ hg hM h C hPM χ) (hH χ)) + simp only [activeMass, highMass, pushSpectrum_sum] at hh ⊢ + simp only [add_mul, Finset.sum_add_distrib, Finset.sum_mul, mul_assoc, ← Finset.mul_sum] at hh + rw [Finset.sum_comm, Finset.sum_comm (f := fun χ i => high h Q (χ.compAddMonoidHom (child (A := ZMod M) h i)) * H χ)] at hh + exact hh + +def SpectralBound {I : Type} {g s L M R : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g → I) (T h : ℕ) (C : Config I L (g*s) h) + (H : AddChar (State (ZMod M) (g*s) h) ℂ → ℝ) (D : ℝ) : Prop := ∀ z, + energy H z ≤ D * mean (fun x : State (ZMod M) (g*s) h => + (ed (sampledWord r j T R h C x).val (sampledWord r j T R h C (x+z)).val : ℝ)) + +lemma SpectralBound.child {I : Type} {g s L M T R h : ℕ} [NeZero M] [NeZero R] + {r : I → ℕ} {j : Fin g → I} (hr : ∀ i, 0 < r i) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) + {C : Config I L (g*s) (h+1)} {H : AddChar (State (ZMod M) (g*s) (h+1)) ℂ → ℝ} {D : ℝ} + (hD : 0 ≤ D) (hb : SpectralBound (R := R) r j T (h+1) C H D) (i : Fin (g*s)) : + SpectralBound (R := R) r j T h (C.2 i).2 (pushSpectrum H (child (A := ZMod M) h i)) (D*T) := by + intro z + rw [energy_push] + exact (hb _).trans ((mul_le_mul_of_nonneg_left (sampledWord_child_mean r j hr hPM h C i z) hD).trans_eq (by ring)) + +lemma high_estimate {I : Type} {g s L M T R D Q J h : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g → I) (hr : ∀ i, 0 < r i) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) + (hD : 0 < D) (hQ : 0 < Q) (hMR : M = R*D) (hMQ : M = J*Q) + (C : Config I L (g*s) h) (H : AddChar (State (ZMod M) (g*s) h) ℂ → ℝ) (a : ℝ) + (hH : ∀ χ, 0 ≤ H χ) (ha : 0 ≤ a) (hb : SpectralBound (R := R) r j T h C H a) : + highMass h Q H ≤ a * FiniteTree.length (g*s) T h * R / Q := by + have hJ : 0 < J := by have := NeZero.pos M; nlinarith + have hd (χ : AddChar (State (ZMod M) (g*s) h) ℂ) : + (J : ℝ) * high h Q χ ≤ ∑ n ∈ Finset.range J, multiplier χ (diagonal (A := ZMod M) (m := g*s) h (n+1)) := by + unfold high + split_ifs with hc + · simpa only [mul_one, multiplier_eq, summary, AddChar.compAddMonoidHom_apply] using sum_chord_detect hQ hMQ (summary h χ) hc + · simp only [mul_zero] + exact Finset.sum_nonneg fun n _ => multiplier_nonneg χ _ + have hcost (n : ℕ) (hn : n ∈ Finset.range J) : + energy H (diagonal (A := ZMod M) (m := g*s) h (n+1)) ≤ a * FiniteTree.length (g*s) T h * R / Q := by + apply (hb _).trans + have ht := sampledWord_tiny (T := T) r j hr hPM hD hQ hMR hMQ h C (n+1) (Finset.mem_range.mp hn) + exact (mul_le_mul_of_nonneg_left (by simpa only [Nat.cast_add, Nat.cast_one] using ht) ha).trans_eq (by ring) + have hh : (J : ℝ) * highMass h Q H ≤ J * (a * FiniteTree.length (g*s) T h * R / Q) := by + calc + _ ≤ ∑ χ, (∑ n ∈ Finset.range J, multiplier χ (diagonal (A := ZMod M) (m := g*s) h (n+1))) * H χ := by + rw [highMass, Finset.mul_sum] + exact Finset.sum_le_sum fun χ _ => by simpa only [mul_assoc] using mul_le_mul_of_nonneg_right (hd χ) (hH χ) + _ = ∑ n ∈ Finset.range J, energy H (diagonal (A := ZMod M) (m := g*s) h (n+1)) := by + simp only [energy, Finset.sum_mul] + rw [Finset.sum_comm] + _ ≤ ∑ _n ∈ Finset.range J, (a * FiniteTree.length (g*s) T h * R / Q) := Finset.sum_le_sum hcost + _ = _ := by simp + exact (mul_le_mul_iff_right₀ (by exact_mod_cast hJ : (0 : ℝ) < J)).mp hh + +end TreeEdit.TorusFourier + +namespace TreeEdit.TorusFourier +open scoped BigOperators +open Classical TorusTree FiniteFourier FiniteProbability + +lemma cycle_estimate {I : Type} {g s L M T R V h : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g → I) (hr : ∀ i, 0 < r i) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) (hPV : ∀ σ : Equiv.Perm I, period r j σ ≤ V) (hVT : V ≤ T) + (C : Config I L (g*s) (h+1)) (H : AddChar (State (ZMod M) (g*s) (h+1)) ℂ → ℝ) (a : ℝ) + (hH : ∀ χ, 0 ≤ H χ) (ha : 0 ≤ a) (hb : SpectralBound (R := R) r j T (h+1) C H a) : + activeMass H (cycle (M := M) r j h C) ≤ a * FiniteTree.length (g*s) T (h+1) * (2 * V) / T := by + let P := period r j C.1 + let v := cycle (M := M) r j h C + have hP : 0 < P := period_pos hr j C.1 + have hT : 0 < T := hP.trans_le ((hPV C.1).trans hVT) + have hd (χ : AddChar (State (ZMod M) (g*s) (h+1)) ℂ) : + (P : ℝ) * active χ v ≤ ∑ n ∈ Finset.range P, multiplier χ ((n+1) • v) := by + by_cases hc : χ v = 1 + · simp only [active, ite_eq_left hc, mul_zero] + exact Finset.sum_nonneg fun n _ => multiplier_nonneg χ _ + · have hper : (χ v)^P = 1 := by + rw [← AddChar.map_nsmul_eq_pow, cycle_period r j h C (hPM C.1), AddChar.map_zero_eq_one] + rw [sum_multiplier_period χ v P hc hper, active, ite_eq_right hc] + nlinarith [Nat.cast_nonneg (α := ℝ) P] + have hcost (n : ℕ) (hn : n ∈ Finset.range P) : energy H ((n+1) • v) ≤ a * (2 * V * ((g*s) * FiniteTree.length (g*s) T h)) := by + apply (hb _).trans + apply mul_le_mul_of_nonneg_left _ ha + apply (mean_le (fun x => show + (ed (sampledWord r j T R (h+1) C x).val (sampledWord r j T R (h+1) C (x+(n+1) • v)).val : ℝ) ≤ + (2 * V * ((g*s) * FiniteTree.length (g*s) T h) : ℝ) from by + have hnV : n+1 ≤ V := (Finset.mem_range.mp hn).trans_le (hPV C.1) + have hh := sampledWord_cycle_cost (R := R) (T := T) r j hr hPM h C x (n+1) (hnV.trans hVT) + exact_mod_cast hh.trans (Nat.mul_le_mul_right _ (Nat.mul_le_mul_left 2 hnV)))).trans_eq + exact mean_const _ + have hh : (P : ℝ) * activeMass H v ≤ P * (a * (2 * V * ((g*s) * FiniteTree.length (g*s) T h))) := by + calc + _ ≤ ∑ χ, (∑ n ∈ Finset.range P, multiplier χ ((n+1) • v)) * H χ := by + rw [activeMass, Finset.mul_sum] + exact Finset.sum_le_sum fun χ _ => by simpa only [mul_assoc] using mul_le_mul_of_nonneg_right (hd χ) (hH χ) + _ = ∑ n ∈ Finset.range P, energy H ((n+1) • v) := by + simp only [energy, Finset.sum_mul] + rw [Finset.sum_comm] + _ ≤ ∑ _n ∈ Finset.range P, a * (2 * V * ((g*s) * FiniteTree.length (g*s) T h)) := Finset.sum_le_sum hcost + _ = _ := by simp + have hc := (mul_le_mul_iff_right₀ (by exact_mod_cast hP : (0 : ℝ) < P)).mp hh + apply hc.trans_eq + simp only [FiniteTree.length, Nat.cast_mul] + have hTr : (T : ℝ) ≠ 0 := by exact_mod_cast hT.ne' + field_simp + +lemma mass_bound {I : Type} {g s L M T R D Q J V b e K h : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g ↪ I) (hr : ∀ i, Nat.Prime (r i)) (hinj : Function.Injective r) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) (hPV : ∀ σ : Equiv.Perm I, period r j σ ≤ V) (hVT : V ≤ T) + (hD : 0 < D) (hQ : 0 < Q) (hMR : M = R*D) (hMQ : M = J*Q) + (hb : 1 ≤ b) (hlower : ∀ i, b ≤ r i) (hQpow : Q ≤ b^e) (hg : e+K ≤ g) (hK : 1 ≤ K) + (hM : (g*s+1)*Q < M) + (C : Config I L (g*s) h) (H : AddChar (State (ZMod M) (g*s) h) ℂ → ℝ) (a : ℝ) + (hH : ∀ χ, 0 ≤ H χ) (ha : 0 ≤ a) (hbound : SpectralBound (R := R) r j T h C H a) : + activeMass H (diagonal (A := ZMod M) (m := g*s) h 1) ≤ + a * FiniteTree.length (g*s) T h * ((K : ℝ)⁻¹^h + h * (2*(R : ℝ)/Q + 2*(V : ℝ)/T)) := by + have hKr : (1 : ℝ) ≤ K := by exact_mod_cast hK + have hKpos : (0 : ℝ) < K := by linarith + have herr : 0 ≤ 2*(R : ℝ)/Q + 2*(V : ℝ)/T := by positivity + induction h generalizing a with + | zero => + have hc (z : State (ZMod M) (g*s) 0) : energy H z ≤ a := by + apply (hbound z).trans + have hm : mean (fun x : State (ZMod M) (g*s) 0 => + (ed (sampledWord r j T R 0 C x).val (sampledWord r j T R 0 C (x+z)).val : ℝ)) ≤ 1 := by + apply (mean_le (fun x => show + (ed (sampledWord r j T R 0 C x).val (sampledWord r j T R 0 C (x+z)).val : ℝ) ≤ 1 from by + have hh := ed_le_of_script (substitution_script + (x := (sampledWord r j T R 0 C x).val) (y := (sampledWord r j T R 0 C (x+z)).val) + (by simp [(sampledWord r j T R 0 C x).property, (sampledWord r j T R 0 C (x+z)).property])) + simpa [(sampledWord r j T R 0 C x).property, FiniteTree.length] using (Nat.cast_le (α := ℝ)).mpr hh)).trans_eq + exact mean_const 1 + simpa only [mul_one] using mul_le_mul_of_nonneg_left hm ha + have hh := (twice_activeMass_le_average hH (diagonal (A := ZMod M) (m := g*s) 0 1)).trans (average_le hc) + simpa only [FiniteTree.length, Nat.cast_one, mul_one, pow_zero, Nat.cast_zero, zero_mul, add_zero] using + (show activeMass H (diagonal (A := ZMod M) (m := g*s) 0 1) ≤ a by linarith [activeMass_nonneg hH (diagonal (A := ZMod M) (m := g*s) 0 1)]) + | succ h ih => + have hchild (i : Fin (g*s)) := ih (C.2 i).2 (pushSpectrum H (child (A := ZMod M) h i)) (a*T) + (pushSpectrum_nonneg hH _) (mul_nonneg ha (Nat.cast_nonneg _)) (hbound.child (fun i => (hr i).pos) hPM ha i) + have hs : (∑ i : Fin (g*s), activeMass (pushSpectrum H (child (A := ZMod M) h i)) + (diagonal (A := ZMod M) (m := g*s) h 1)) ≤ + a * FiniteTree.length (g*s) T (h+1) * ((K : ℝ)⁻¹^h + h * (2*(R : ℝ)/Q + 2*(V : ℝ)/T)) := by + apply (Finset.sum_le_sum fun i _ => hchild i).trans_eq + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, FiniteTree.length, Nat.cast_mul] + ring + have hhi := high_estimate r j (fun i => (hr i).pos) hPM hD hQ hMR hMQ C H a hH ha hbound + have hhis (i : Fin (g*s)) := high_estimate r j (fun i => (hr i).pos) hPM hD hQ hMR hMQ + (C.2 i).2 (pushSpectrum H (child (A := ZMod M) h i)) (a*T) (pushSpectrum_nonneg hH _) + (mul_nonneg ha (Nat.cast_nonneg _)) (hbound.child (fun i => (hr i).pos) hPM ha i) + have hhs : (∑ i : Fin (g*s), highMass h Q (pushSpectrum H (child (A := ZMod M) h i))) ≤ + a * FiniteTree.length (g*s) T (h+1) * R / Q := by + apply (Finset.sum_le_sum fun i _ => hhis i).trans_eq + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, FiniteTree.length, Nat.cast_mul] + ring + have hcy := cycle_estimate r j (fun i => (hr i).pos) hPM hPV hVT C H a hH ha hbound + have hbr := branch_mass r hr hinj j hb hlower hQpow hg hM h C (hPM C.1) H hH + have herror : highMass (h+1) Q H + (∑ i : Fin (g*s), highMass h Q (pushSpectrum H (child (A := ZMod M) h i))) + + activeMass H (cycle (M := M) r j h C) ≤ + a * FiniteTree.length (g*s) T (h+1) * (2*(R : ℝ)/Q + 2*(V : ℝ)/T) := by + calc + _ ≤ a * FiniteTree.length (g*s) T (h+1) * R/Q + a * FiniteTree.length (g*s) T (h+1) * R/Q + + a * FiniteTree.length (g*s) T (h+1) * (2*V)/T := add_le_add (add_le_add hhi hhs) hcy + _ = _ := by ring + have hmain := hbr.trans (add_le_add hs (mul_le_mul_of_nonneg_left herror hKpos.le)) + have hkn : 0 ≤ a * (FiniteTree.length (g*s) T (h+1) : ℝ) * h * (2*(R : ℝ)/Q + 2*(V : ℝ)/T) * ((K : ℝ)-1) := by positivity + have he : (K : ℝ) * (a * FiniteTree.length (g*s) T (h+1) * ((K : ℝ)⁻¹^(h+1) + (h+1) * (2*(R : ℝ)/Q + 2*(V : ℝ)/T))) = + (a * FiniteTree.length (g*s) T (h+1) * ((K : ℝ)⁻¹^h + h * (2*(R : ℝ)/Q + 2*(V : ℝ)/T)) + + K * (a * FiniteTree.length (g*s) T (h+1) * (2*(R : ℝ)/Q + 2*(V : ℝ)/T))) + + a * FiniteTree.length (g*s) T (h+1) * h * (2*(R : ℝ)/Q + 2*(V : ℝ)/T) * ((K : ℝ)-1) := by + rw [pow_succ] + field_simp + ring + apply (mul_le_mul_iff_right₀ hKpos).mp + simp only [Nat.cast_add, Nat.cast_one] + rw [he] + linarith + +lemma energy_diagonal_le_mass {M m h : ℕ} [NeZero M] + (H : AddChar (State (ZMod M) m h) ℂ → ℝ) (hH : ∀ χ, 0 ≤ H χ) (a : ZMod M) : + energy H (diagonal (A := ZMod M) (m := m) h a) ≤ 4 * activeMass H (diagonal (A := ZMod M) (m := m) h 1) := by + rw [energy, activeMass, Finset.mul_sum] + apply Finset.sum_le_sum + intro χ _ + rw [active_summary] + split_ifs with hc + · have he : χ (diagonal (A := ZMod M) (m := m) h a) = 1 := congrArg (fun η : AddChar (ZMod M) ℂ => η a) hc + simp only [multiplier, he, sub_self, norm_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, zero_mul, mul_zero, le_refl] + · simpa only [one_mul, mul_assoc] using mul_le_mul_of_nonneg_right (multiplier_le_four χ _) (hH χ) + +end TreeEdit.TorusFourier + +namespace TreeEdit.TorusFourier +open scoped BigOperators +open Classical TorusTree FiniteFourier FiniteProbability + +theorem displacement_bound {I : Type} {g s L M T R D Q J V b e K h : ℕ} [NeZero M] [NeZero R] + (r : I → ℕ) (j : Fin g ↪ I) (hr : ∀ i, Nat.Prime (r i)) (hinj : Function.Injective r) + (hPM : ∀ σ : Equiv.Perm I, period r j σ ∣ M) (hPV : ∀ σ : Equiv.Perm I, period r j σ ≤ V) (hVT : V ≤ T) + (hD : 0 < D) (hQ : 0 < Q) (hMR : M = R*D) (hMQ : M = J*Q) + (hb : 1 ≤ b) (hlower : ∀ i, b ≤ r i) (hQpow : Q ≤ b^e) (hg : e+K ≤ g) (hK : 1 ≤ K) + (hM : (g*s+1)*Q < M) (C : Config I L (g*s) h) (t : ZMod M) + (F : State (ZMod M) (g*s) h → RealL1) (a : ℝ) (ha : 0 ≤ a) + (hlip : ∀ x y, dist (F x) (F y) ≤ a * ed (sampledWord r j T R h C x).val (sampledWord r j T R h C y).val) : + average (fun x => dist (F x) (F (x + diagonal (A := ZMod M) (m := g*s) h t))) ≤ + a * FiniteTree.length (g*s) T h * (4*((K : ℝ)⁻¹^h + h*(2*(R : ℝ)/Q + 2*(V : ℝ)/T))) := by + obtain ⟨H, hH, _, he⟩ := l1_displacement_spectrum F + have hbound : SpectralBound (R := R) r j T h C H a := by + intro z + rw [energy, ← he] + have hh := average_mono (fun x => hlip x (x+z)) + simpa only [dist_comm, average, mean, ← Finset.mul_sum, mul_assoc, mul_left_comm] using hh + have hh := mass_bound r j hr hinj hPM hPV hVT hD hQ hMR hMQ hb hlower hQpow hg hK hM C H a hH ha hbound + calc + _ = energy H (diagonal (A := ZMod M) (m := g*s) h t) := by simpa only [dist_comm, energy] using he (diagonal (A := ZMod M) (m := g*s) h t) + _ ≤ 4*activeMass H (diagonal (A := ZMod M) (m := g*s) h 1) := energy_diagonal_le_mass H hH t + _ ≤ 4*(a * FiniteTree.length (g*s) T h * ((K : ℝ)⁻¹^h + h*(2*(R : ℝ)/Q + 2*(V : ℝ)/T))) := by gcongr + _ = _ := by ring + +end TreeEdit.TorusFourier + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/SegmentComparison.lean b/lean/OAI/Combinatorics/TreeEdit/SegmentComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..704dc7a95369118a8b701f707f5fd64f2b7b4ad4 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/SegmentComparison.lean @@ -0,0 +1,360 @@ +import OAI.Combinatorics.TreeEdit.Alignments + +namespace OAI + +namespace TreeEdit + +universe u + +variable {α : Type u} {x y z : List α} + +def segment {β : Type*} (x : List β) (start len : ℕ) : List β := + (x.drop start).take len + +theorem length_segment {β : Type*} (x : List β) {start len : ℕ} + (h : start + len ≤ x.length) : (segment x start len).length = len := by + simp only [segment, List.length_take, List.length_drop] + omega + +theorem segment_get {β : Type*} (x : List β) (start len i : ℕ) + (hi : i < (segment x start len).length) : + (segment x start len)[i] = x[start + i]'(by + simp only [segment, List.length_take, List.length_drop] at hi + omega) := by + simp only [segment, List.getElem_take, List.getElem_drop] + +theorem take_segment {β : Type*} (x : List β) (start len a : ℕ) (ha : a ≤ len) : + (segment x start len).take a = segment x start a := by + simp [segment, List.take_take, Nat.min_eq_left ha] + +theorem lcs_le_take_left (x y : List α) (a : ℕ) : + lcs x y ≤ lcs (x.take a) y + (x.length - a) := by + have h := lcs_script_loss y (sublist_script (List.take_sublist a x)) + rw [lcs_comm y x, lcs_comm y (x.take a)] at h + simp only [List.length_take] at h + have he : x.length - min a x.length = x.length - a := by omega + rwa [he] at h + +theorem lcs_le_take_both (x y : List α) (a : ℕ) : + lcs x y ≤ lcs (x.take a) (y.take a) + (x.length - a) + (y.length - a) := by + have hl := lcs_le_take_left x y a + have hr := lcs_le_take_left y (x.take a) a + rw [lcs_comm y (x.take a), lcs_comm (y.take a) (x.take a)] at hr + omega + +theorem get_encode_block {P : ℕ} (c : α → Word Bool P) (x : List α) + (i r : ℕ) (hi : i < x.length) (hr : r < P) : + (encode c x)[i * P + r]'(by + rw [length_encode] + have hh := Nat.mul_le_mul_right P (Nat.succ_le_of_lt hi) + rw [Nat.succ_mul] at hh + omega) = (c x[i]).val[r]'(by rw [(c x[i]).property]; exact hr) := by + induction x generalizing i with + | nil => simp at hi + | cons a x ih => + simp only [encode_cons] + cases i with + | zero => + simpa using List.getElem_append_left (as := (c a).val) (bs := encode c x) + (i := r) (by rw [(c a).property]; exact hr) + | succ i => + rw [List.getElem_append_right (by rw [(c a).property, Nat.add_mul]; omega)] + have he : (i + 1) * P + r - (c a).val.length = i * P + r := by + rw [(c a).property, Nat.add_mul]; omega + simpa only [he, List.getElem_cons_succ] using ih i (by simpa using hi) + +theorem segment_encode_block {P : ℕ} (c : α → Word Bool P) (x : List α) + (i start len : ℕ) (hi : i < x.length) (hseg : start + len ≤ P) : + segment (encode c x) (i * P + start) len = segment (c x[i]).val start len := by + have hb : i * P + start + len ≤ (encode c x).length := by + rw [length_encode] + have hh := Nat.mul_le_mul_right P (Nat.succ_le_of_lt hi) + rw [Nat.succ_mul] at hh + omega + have hc : start + len ≤ (c x[i]).val.length := by rwa [(c x[i]).property] + apply List.ext_getElem + · rw [length_segment _ hb, length_segment _ hc] + · intro j hj hj' + rw [segment_get, segment_get] + have hjl : j < len := by rwa [length_segment _ hb] at hj + simpa only [Nat.add_assoc] using get_encode_block c x i (start + j) hi (by omega) + +theorem span_bounds {N L : ℕ} (f : Fin N ↪o Fin L) (s : Finset (Fin N)) + (hs : s.Nonempty) : + (f (s.min' hs)).val + (indexSpan f s).card ≤ L := by + rw [indexSpan, dite_eq_left hs, Fin.card_Icc] + have hle := f.monotone (s.min'_le_max' hs) + have hlt := (f (s.max' hs)).isLt + omega + +theorem span_length_formula {N L : ℕ} (f : Fin N ↪o Fin L) (s : Finset (Fin N)) + (hs : s.Nonempty) : + (f (s.min' hs)).val + (indexSpan f s).card = (f (s.max' hs)).val + 1 := by + rw [indexSpan, dite_eq_left hs, Fin.card_Icc] + have hle := f.monotone (s.min'_le_max' hs) + omega + +theorem span_card_le_lcs {β : Type*} {N : ℕ} (x y : List β) + (f : Fin N ↪o Fin x.length) (g : Fin N ↪o Fin y.length) + (hfg : ∀ i, x.get (f i) = y.get (g i)) + (s : Finset (Fin N)) (hs : s.Nonempty) : + s.card ≤ lcs (segment x (f (s.min' hs)).val (indexSpan f s).card) + (segment y (g (s.min' hs)).val (indexSpan g s).card) := by + let e := s.orderEmbOfFin rfl + let a := (f (s.min' hs)).val + let b := (g (s.min' hs)).val + let X := segment x a (indexSpan f s).card + let Y := segment y b (indexSpan g s).card + have hX : X.length = (indexSpan f s).card := length_segment _ (span_bounds f s hs) + have hY : Y.length = (indexSpan g s).card := length_segment _ (span_bounds g s hs) + have hlo (i : Fin s.card) : a ≤ (f (e i)).val := + f.monotone (s.min'_le _ (s.orderEmbOfFin_mem rfl i)) + have hro (i : Fin s.card) : b ≤ (g (e i)).val := + g.monotone (s.min'_le _ (s.orderEmbOfFin_mem rfl i)) + have hli (i : Fin s.card) : (f (e i)).val - a < X.length := by + rw [hX] + have hu := f.monotone (s.le_max' _ (s.orderEmbOfFin_mem rfl i)) + have hf := span_length_formula f s hs + have hl := hlo i + dsimp [a, e] at * + omega + have hri (i : Fin s.card) : (g (e i)).val - b < Y.length := by + rw [hY] + have hu := g.monotone (s.le_max' _ (s.orderEmbOfFin_mem rfl i)) + have hf := span_length_formula g s hs + have hl := hro i + dsimp [b, e] at * + omega + let fl : Fin s.card → Fin X.length := fun i => ⟨(f (e i)).val - a, hli i⟩ + let gr : Fin s.card → Fin Y.length := fun i => ⟨(g (e i)).val - b, hri i⟩ + have hfl : StrictMono fl := by + intro i j hij + have hi := hlo i + have hj := hlo j + have hh := f.strictMono (e.strictMono hij) + change (f (e i)).val - a < (f (e j)).val - a + omega + have hgr : StrictMono gr := by + intro i j hij + have hi := hro i + have hj := hro j + have hh := g.strictMono (e.strictMono hij) + change (g (e i)).val - b < (g (e j)).val - b + omega + apply Alignment.le_lcs (x := X) (y := Y) + ⟨OrderEmbedding.ofStrictMono fl hfl, OrderEmbedding.ofStrictMono gr hgr, ?_⟩ + intro i + change X.get (fl i) = Y.get (gr i) + simp only [List.get_eq_getElem, X, Y, fl, gr] + rw [segment_get, segment_get] + simpa only [Nat.add_sub_of_le (hlo i), Nat.add_sub_of_le (hro i), + List.get_eq_getElem] using hfg (e i) + +def SegmentCode {P : ℕ} (c : α → Word Bool P) (a₀ : ℕ) : Prop := + ∀ a b : α, a ≠ b → ∀ start stop len : ℕ, a₀ ≤ len → + start + len ≤ P → stop + len ≤ P → + 100 * lcs (segment (c a).val start len) (segment (c b).val stop len) ≤ 99 * len + +theorem indexSpan_card_cast {N L L' : ℕ} (h : L = L') + (f : Fin N ↪o Fin L) (s : Finset (Fin N)) : + (indexSpan (f.comp (Fin.castOrderIso h).toOrderEmbedding) s).card = + (indexSpan f s).card := by + subst L' + rfl + +theorem span_in_block {M P N : ℕ} (hP : 0 < P) + (f : Fin N ↪o Fin (M * P)) (s : Finset (Fin N)) (hs : s.Nonempty) + (hb : blockIndex hP (f (s.min' hs)) = blockIndex hP (f (s.max' hs))) : + (f (s.min' hs)).val % P + (indexSpan f s).card ≤ P := by + have he := congrArg Fin.val hb + change (f (s.min' hs)).val / P = (f (s.max' hs)).val / P at he + have hl := span_length_formula f s hs + have hmin := Nat.mod_add_div (f (s.min' hs)).val P + have hmax := Nat.mod_add_div (f (s.max' hs)).val P + have hmod := Nat.mod_lt (f (s.max' hs)).val hP + rw [he] at hmin + omega + +theorem span_encode_eq {M P N : ℕ} (hP : 0 < P) (c : α → Word Bool P) + (x : Word α M) (f : Fin N ↪o Fin (M * P)) + (s : Finset (Fin N)) (hs : s.Nonempty) + (hb : blockIndex hP (f (s.min' hs)) = blockIndex hP (f (s.max' hs))) : + segment (encode c x.val) (f (s.min' hs)).val (indexSpan f s).card = + segment (c (x.val.get (Fin.cast x.property.symm + (blockIndex hP (f (s.min' hs)))))).val + ((f (s.min' hs)).val % P) (indexSpan f s).card := by + have hr := span_in_block hP f s hs hb + have hh := segment_encode_block c x.val + ((f (s.min' hs)).val / P) ((f (s.min' hs)).val % P) + (indexSpan f s).card (by + rw [x.property] + exact (blockIndex hP (f (s.min' hs))).isLt) hr + simpa only [Nat.mul_comm ((f (s.min' hs)).val / P) P, Nat.div_add_mod, + List.get_eq_getElem, blockIndex, Fin.cast_mk] using hh + +theorem unequal_pair_bound {M P N a₀ : ℕ} (hP : 0 < P) + (c : α → Word Bool P) (hc : SegmentCode c a₀) (x y : Word α M) + (f g : Fin N ↪o Fin (M * P)) + (hfg : ∀ i, + (encode c x.val).get (Fin.cast (by rw [length_encode, x.property]) (f i)) = + (encode c y.val).get (Fin.cast (by rw [length_encode, y.property]) (g i))) + (s : Finset (Fin N)) (hs : s.Nonempty) + (hf : blockIndex hP (f (s.min' hs)) = blockIndex hP (f (s.max' hs))) + (hg : blockIndex hP (g (s.min' hs)) = blockIndex hP (g (s.max' hs))) + (hne : x.val.get (Fin.cast x.property.symm (blockIndex hP (f (s.min' hs)))) ≠ + y.val.get (Fin.cast y.property.symm (blockIndex hP (g (s.min' hs))))) : + s.card ≤ 100 * ((indexSpan f s).card - s.card + + ((indexSpan g s).card - s.card)) + a₀ := by + by_cases ha : a₀ ≤ s.card + · let f' := f.comp (Fin.castOrderIso (by rw [length_encode, x.property] : + M * P = (encode c x.val).length)).toOrderEmbedding + let g' := g.comp (Fin.castOrderIso (by rw [length_encode, y.property] : + M * P = (encode c y.val).length)).toOrderEmbedding + have hbase := span_card_le_lcs (encode c x.val) (encode c y.val) f' g' hfg s hs + have hfc : (indexSpan f' s).card = (indexSpan f s).card := indexSpan_card_cast _ f s + have hgc : (indexSpan g' s).card = (indexSpan g s).card := indexSpan_card_cast _ g s + rw [hfc, hgc] at hbase + change s.card ≤ lcs + (segment (encode c x.val) (f (s.min' hs)).val (indexSpan f s).card) + (segment (encode c y.val) (g (s.min' hs)).val (indexSpan g s).card) at hbase + rw [span_encode_eq hP c x f s hs hf, span_encode_eq hP c y g s hs hg] at hbase + have hl := card_le_indexSpan f s + have hr := card_le_indexSpan g s + have hfb := span_in_block hP f s hs hf + have hgb := span_in_block hP g s hs hg + have htrim := lcs_le_take_both + (segment (c (x.val.get (Fin.cast x.property.symm + (blockIndex hP (f (s.min' hs)))))).val + ((f (s.min' hs)).val % P) (indexSpan f s).card) + (segment (c (y.val.get (Fin.cast y.property.symm + (blockIndex hP (g (s.min' hs)))))).val + ((g (s.min' hs)).val % P) (indexSpan g s).card) s.card + rw [take_segment _ _ _ _ hl, take_segment _ _ _ _ hr] at htrim + rw [length_segment _ (by rw [(c _).property]; exact hfb), + length_segment _ (by rw [(c _).property]; exact hgb)] at htrim + have hc' := hc _ _ hne ((f (s.min' hs)).val % P) + ((g (s.min' hs)).val % P) s.card ha (by omega) (by omega) + omega + · omega + +theorem code_alignment_additive {M P N a₀ : ℕ} (hP : 0 < P) + (c : α → Word Bool P) (hc : SegmentCode c a₀) (x y : Word α M) + (f g : Fin N ↪o Fin (M * P)) + (hfg : ∀ i, + (encode c x.val).get (Fin.cast (by rw [length_encode, x.property]) (f i)) = + (encode c y.val).get (Fin.cast (by rw [length_encode, y.property]) (g i))) : + P * deficit x.val y.val ≤ 201 * (M * P - N) + 2 * M * a₀ := by + classical + let E : Fin N → Prop := fun i => + x.val.get (Fin.cast x.property.symm (blockIndex hP (f i))) = + y.val.get (Fin.cast y.property.symm (blockIndex hP (g i))) + let good := Finset.univ.filter E + let bad := Finset.univ.filter (fun i => ¬ E i) + let key := blockPairKey hP f g + let fiber := fun k => Finset.univ.filter (fun i => key i = k) + let gap := fun k => (indexSpan f (fiber k)).card - (fiber k).card + + ((indexSpan g (fiber k)).card - (fiber k).card) + have hsame {i j : Fin N} (h : key i = key j) : E i ↔ E j := by + obtain ⟨hf, hg⟩ := (blockPairKey_eq_iff hP f g i j).mp h + simp only [E, hf, hg] + have hgood : good.card ≤ P * lcs x.val y.val := by + let e := good.orderEmbOfFin rfl + apply equal_label_alignment_bound hP x y (e.comp f) (e.comp g) + intro i + exact (Finset.mem_filter.mp (good.orderEmbOfFin_mem rfl i)).2 + have hone (k : Fin (2 * M)) : + (bad.filter (fun i => key i = k)).card ≤ 100 * gap k + a₀ := by + by_cases hb : (bad.filter (fun i => key i = k)).Nonempty + · obtain ⟨i, hi⟩ := hb + obtain ⟨hib, hik⟩ := Finset.mem_filter.mp hi + have hine : ¬ E i := (Finset.mem_filter.mp hib).2 + have hsi : i ∈ fiber k := by simp only [fiber, Finset.mem_filter, + Finset.mem_univ, true_and]; exact hik + have hs : (fiber k).Nonempty := ⟨i, hsi⟩ + have hmin : key ((fiber k).min' hs) = k := + (Finset.mem_filter.mp ((fiber k).min'_mem hs)).2 + have hmax : key ((fiber k).max' hs) = k := + (Finset.mem_filter.mp ((fiber k).max'_mem hs)).2 + obtain ⟨hf, hg⟩ := (blockPairKey_eq_iff hP f g _ _).mp (hmin.trans hmax.symm) + have hne : ¬ E ((fiber k).min' hs) := fun h => + hine ((hsame (hmin.trans hik.symm)).mp h) + have hbound := unequal_pair_bound hP c hc x y f g hfg (fiber k) hs hf hg hne + have hsub : bad.filter (fun i => key i = k) ⊆ fiber k := by + intro j hj + exact Finset.mem_filter.mpr ⟨Finset.mem_univ j, (Finset.mem_filter.mp hj).2⟩ + exact (Finset.card_le_card hsub).trans hbound + · rw [Finset.not_nonempty_iff_eq_empty.mp hb] + simp + have hbad : bad.card ≤ 200 * (M * P - N) + 2 * M * a₀ := by + have he := Finset.card_eq_sum_card_fiberwise + (s := bad) (t := Finset.univ) (f := key) (by simp) + rw [he] + calc + _ ≤ ∑ k : Fin (2 * M), (100 * gap k + a₀) := + Finset.sum_le_sum (fun k _ => hone k) + _ = 100 * (∑ k : Fin (2 * M), gap k) + 2 * M * a₀ := by + rw [Finset.sum_add_distrib, ← Finset.mul_sum] + simp + _ ≤ 200 * (M * P - N) + 2 * M * a₀ := by + have hg : (∑ k : Fin (2 * M), gap k) ≤ 2 * (M * P - N) := + block_span_gap_budget hP f g + omega + have hsplit : good.card + bad.card = N := by + simpa only [good, bad, Finset.card_univ, Fintype.card_fin] using + Finset.card_filter_add_card_filter_not (s := Finset.univ) E + have hN : N ≤ M * P := by + simpa only [Fintype.card_fin] using Fintype.card_le_of_injective _ f.injective + have hsum : P * deficit x.val y.val + P * lcs x.val y.val = M * P := by + rw [← Nat.mul_add, deficit, Nat.sub_add_cancel (lcs_le_length_left _ _), x.property] + exact Nat.mul_comm _ _ + omega + +theorem code_deficit_comparison {M P a₀ : ℕ} (hP : 0 < P) + (hthreshold : 4 * M * a₀ ≤ P) (c : α → Word Bool P) + (hc : SegmentCode c a₀) (x y : Word α M) : + P * deficit x.val y.val ≤ 402 * deficit (encode c x.val) (encode c y.val) := by + obtain ⟨A⟩ := exists_lcs_alignment (encode c x.val) (encode c y.val) + have hx : (encode c x.val).length = M * P := by rw [length_encode, x.property] + have hy : (encode c y.val).length = M * P := by rw [length_encode, y.property] + let f := A.left.comp (Fin.castOrderIso hx).toOrderEmbedding + let g := A.right.comp (Fin.castOrderIso hy).toOrderEmbedding + have hfg : ∀ i, + (encode c x.val).get (Fin.cast hx.symm (f i)) = + (encode c y.val).get (Fin.cast hy.symm (g i)) := by + intro i + exact A.agree i + have hadd := code_alignment_additive hP c hc x y f g hfg + have hδ : deficit (encode c x.val) (encode c y.val) = + M * P - lcs (encode c x.val) (encode c y.val) := by rw [deficit, hx] + rw [← hδ] at hadd + by_cases hr : deficit x.val y.val = 0 + · simp [hr] + · have hmul : P ≤ P * deficit x.val y.val := Nat.le_mul_of_pos_right P (by omega) + simp only [Nat.mul_assoc] at hthreshold hadd + omega + +theorem code_edit_comparison {M P a₀ : ℕ} (hP : 0 < P) + (hthreshold : 4 * M * a₀ ≤ P) (c : α → Word Bool P) + (hc : SegmentCode c a₀) (x y : Word α M) : + (P : ℝ) / 804 * (ed x.val y.val : ℝ) ≤ + (ed (encode c x.val) (encode c y.val) : ℝ) ∧ + (ed (encode c x.val) (encode c y.val) : ℝ) ≤ (P : ℝ) * (ed x.val y.val : ℝ) ∧ + (P : ℝ) / 402 * (deficit x.val y.val : ℝ) ≤ + (deficit (encode c x.val) (encode c y.val) : ℝ) := by + have hδ := code_deficit_comparison hP hthreshold c hc x y + have hE := ed_le_twice_deficit (x.property.trans y.property.symm) + have hδE := deficit_le_ed (encode c x.val) (encode c y.val) + have hE' : (ed x.val y.val : ℝ) ≤ 2 * (deficit x.val y.val : ℝ) := by exact_mod_cast hE + have hδ' : (P : ℝ) * (deficit x.val y.val : ℝ) ≤ + 402 * (deficit (encode c x.val) (encode c y.val) : ℝ) := by exact_mod_cast hδ + have hδE' : (deficit (encode c x.val) (encode c y.val) : ℝ) ≤ + (ed (encode c x.val) (encode c y.val) : ℝ) := by exact_mod_cast hδE + refine ⟨?_, ?_, ?_⟩ + · have hP' : (0 : ℝ) ≤ P := Nat.cast_nonneg _ + nlinarith + · exact_mod_cast ed_encode_le c x.val y.val + · linarith + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/TorusLowerBound.lean b/lean/OAI/Combinatorics/TreeEdit/TorusLowerBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..649f62466d9c857adaa4a53017e2d7a34931b838 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/TorusLowerBound.lean @@ -0,0 +1,117 @@ +import OAI.Combinatorics.TreeEdit.CircleParameters +import OAI.Combinatorics.TreeEdit.Delimiter +import OAI.Combinatorics.TreeEdit.DistortionTransfer +import OAI.Combinatorics.TreeEdit.CapInversion + +namespace OAI + +namespace TreeEdit + +def singletonCode (a : Bool) : Word Bool 1 := ⟨[a], rfl⟩ + +lemma encode_singletonCode (x : List Bool) : encode singletonCode x = x := by + induction x with + | nil => rfl + | cons a x ih => simpa only [encode, List.flatMap_cons, singletonCode, List.singleton_append] using congrArg (List.cons a) ih + +namespace TorusTree +open scoped BigOperators +open Classical Filter + +theorem binary_witness {k : ℕ} (hk : 2 ≤ k) (j : Fin (16*k) ↪ Pool k) + (C : Config (Pool k) (residueModulus k) (branching k) k) + (hgood : Good (resolution k : ℝ)⁻¹ poolPrime j k C (point 2)) : + ∃ W : Finset (List Bool), 2 ≤ W.card ∧ (∀ v ∈ W, v.length = binaryLength k) ∧ + ((k : ℝ)/128)^k / (1286400*(k : ℝ)^2) ≤ c1 W := by + let : NeZero (fineModulus j) := ⟨(fine_parameters hk j).1.ne'⟩ + let : NeZero (resolution k) := ⟨(pow_pos (by omega : 0 < k) (8*k)).ne'⟩ + let A := State (ZMod (fineModulus j)) (branching k) k + let Γ := Symbol (branching k) (resolution k) k + let N := FiniteTree.length (branching k) (repetitions k) k + let B := Delimiter.width (Fintype.card Γ) + have hN : N = wordLength k := FiniteTree.length_eq _ _ _ + have hB : B = binaryWidth k := by + dsimp only [B, Γ, Delimiter.width, binaryWidth, alphabetSize] + rw [symbol_card] + have hNp : 0 < N := lt_of_lt_of_le (by omega : 0 < k) (hN ▸ wordLength_ge hk) + have hBp : 0 < B := by dsimp [B, Delimiter.width]; omega + let w : A → Word Γ N := sampledWord poolPrime j (repetitions k) (resolution k) k C + let z : A := diagonal (A := ZMod (fineModulus j)) (m := branching k) k (fineModulus j/2 : ℕ) + obtain ⟨c, hc⟩ := Delimiter.transfer Γ + let instG : AddCommGroup A := stateAddCommGroup (A := ZMod (fineModulus j)) (branching k) k + let instF : Fintype A := stateFintype (A := ZMod (fineModulus j)) (branching k) k + let wb (x : A) : Word Bool (N*B) := + ⟨encode c (w x).val, by rw [length_encode, (w x).property]⟩ + let hadd : HAdd A A A := ⟨@Add.add A instG.toAdd⟩ + have hsep (x : A) : (N*B : ℝ) ≤ (2*B*(128 : ℝ)^k) * ed (wb x).val (wb (@HAdd.hAdd A A A hadd x z)).val := by + have hh : (N : ℝ) ≤ (128 : ℝ)^k * deficit (w x).val (w (@HAdd.hAdd A A A hadd x z)).val := by + exact_mod_cast sampled_separation hk j C hgood x + have he := (hc N (w x) (w (@HAdd.hAdd A A A hadd x z))).2.1 + calc + _ ≤ B * ((128 : ℝ)^k * deficit (w x).val (w (@HAdd.hAdd A A A hadd x z)).val) := by nlinarith only [mul_le_mul_of_nonneg_left hh (Nat.cast_nonneg B)] + _ ≤ B * ((128 : ℝ)^k * (2 * ed (wb x).val (wb (@HAdd.hAdd A A A hadd x z)).val)) := by + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg B) + apply mul_le_mul_of_nonneg_left _ (pow_nonneg (by norm_num) _) + dsimp only [wb] + linarith + _ = _ := by ring + have hobs (F : A → RealL1) (a : ℝ) (ha : 0 ≤ a) + (hlip : ∀ x y, dist (F x) (F y) ≤ a * ed (wb x).val (wb y).val) : + @FiniteFourier.average A instF (fun x => dist (F x) (F (@HAdd.hAdd A A A hadd x z))) ≤ + a * (N*B : ℕ) * (20*(k : ℝ)⁻¹^k) := by + have hlip' (x y : A) : dist (F x) (F y) ≤ (a*B) * ed (w x).val (w y).val := by + calc + _ ≤ a * ed (wb x).val (wb y).val := hlip x y + _ ≤ a * (B * (ed (w x).val (w y).val : ℝ)) := + mul_le_mul_of_nonneg_left (by exact_mod_cast (hc N (w x) (w y)).2.2) ha + _ = _ := by ring + have hh := concrete_displacement hk j C F (a*B) (mul_nonneg ha (Nat.cast_nonneg B)) hlip' + convert hh using 1 + push_cast + ring + obtain ⟨W, hW, hlen, hdist⟩ := @binary_transfer A Bool instF instG inferInstance (N*B) 1 (Nat.mul_pos hNp hBp) (by norm_num : 0 < 1) + wb z singletonCode (2*B*(128 : ℝ)^k) (20*(k : ℝ)⁻¹^k) + (by positivity) (by + have hkreal : (0 : ℝ) < k := by exact_mod_cast (show 0 < k by omega) + exact mul_pos (by norm_num) (pow_pos (inv_pos.mpr hkreal) _)) + (fun x y => by + rw [encode_singletonCode, encode_singletonCode] + exact mul_le_of_le_one_left (Nat.cast_nonneg _) (by norm_num)) + (fun x => by simpa only [Nat.cast_mul] using hsep x) hobs + refine ⟨W, hW, ?_, ?_⟩ + · intro v hv + simpa only [mul_one, hN, hB, binaryLength] using hlen v hv + · have hkreal : (0 : ℝ) < k := by exact_mod_cast (show 0 < k by omega) + have hBreal : (0 : ℝ) < B := by exact_mod_cast hBp + have hwidth : (B : ℝ) ≤ 40*(k : ℝ)^2 := by rw [hB]; exact_mod_cast binaryWidth_le hk + have heq : (804*(2*B*(128 : ℝ)^k)*(20*(k : ℝ)⁻¹^k))⁻¹ = + ((k : ℝ)/128)^k / (32160*B) := by + rw [div_pow, inv_pow] + field_simp + ring + rw [heq] at hdist + apply le_trans _ hdist + apply div_le_div_of_nonneg_left (pow_nonneg (by positivity) _) (by positivity) + nlinarith + +lemma witnesses_eventually : ∀ᶠ k : ℕ in atTop, + ∃ W : Finset (List Bool), 2 ≤ W.card ∧ (∀ v ∈ W, v.length = binaryLength k) ∧ + ((k : ℝ)/128)^k / (1286400*(k : ℝ)^2) ≤ c1 W := by + filter_upwards [good_halfturn_eventually] with k hk + obtain ⟨hk2, j, C, hgood⟩ := hk + exact binary_witness hk2 j C hgood + +end TorusTree + +theorem binary_torus : BinaryLowerBound := by + apply all_caps_of_witnesses (N := TorusTree.binaryLength) (A := 60) (by norm_num) + filter_upwards [TorusTree.witnesses_eventually, + eventually_exponential_lower (b := 128) (C := 1286400) (by norm_num) (by norm_num) 2, + Filter.eventually_ge_atTop 2] with k hw he hk + obtain ⟨W, hW, hlen, hD⟩ := hw + exact ⟨TorusTree.binaryLength_ge hk, TorusTree.length_log_bound hk, + W, hW, hlen, he.trans hD⟩ + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/TreeArithmetic.lean b/lean/OAI/Combinatorics/TreeEdit/TreeArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6e693a53455daa56cf022d7ddd6209f7a74a36b --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/TreeArithmetic.lean @@ -0,0 +1,44 @@ +import OAI.Combinatorics.TreeEdit.Model + +namespace OAI + +namespace TreeEdit.FiniteTree + +universe u + +attribute [local instance] Classical.propDecidable + +@[reducible] def length (m T : ℕ) : ℕ → ℕ + | 0 => 1 + | h + 1 => T * (m * length m T h) + +lemma length_eq (m T h : ℕ) : length m T h = (m * T) ^ h := by + induction h with + | zero => rfl + | succ h ih => simp only [length, ih, pow_succ]; ring + +lemma few_prime_divisors {m b s T : ℕ} (p : Fin m → ℕ) + (hp : ∀ i, Nat.Prime (p i)) (hinj : Function.Injective p) + (hb : 1 ≤ b) (hpb : ∀ i, b ≤ p i) (hT : T ≤ b ^ s) + (d : ℤ) (hd : d ≠ 0) (hdT : d.natAbs < T) : + (Finset.univ.filter (fun i => (p i : ℤ) ∣ d)).card < s := by + classical + let S := Finset.univ.filter (fun i => (p i : ℤ) ∣ d) + have hcop : (↑S : Set (Fin m)).Pairwise (fun i j => IsCoprime (p i : ℤ) (p j : ℤ)) := by + intro i _ j _ hij + exact ((Nat.coprime_primes (hp i) (hp j)).mpr (fun h => hij (hinj h))).isCoprime + have hprod : (∏ i ∈ S, (p i : ℤ)) ∣ d := + Finset.prod_dvd_of_coprime hcop (fun i hi => (Finset.mem_filter.mp hi).2) + have hprod' : (∏ i ∈ S, p i) ∣ d.natAbs := Int.natCast_dvd.mp (by simpa using hprod) + have hle : b ^ S.card ≤ d.natAbs := by + calc + _ = ∏ _i ∈ S, b := (Finset.prod_const b).symm + _ ≤ ∏ i ∈ S, p i := Finset.prod_le_prod (fun i _ => hpb i) + _ ≤ d.natAbs := Nat.le_of_dvd (Int.natAbs_pos.mpr hd) hprod' + by_contra hn + have hh := pow_le_pow_right₀ hb (Nat.le_of_not_gt hn) + exact (not_le_of_gt hdT) (hT.trans (hh.trans hle)) + +end TreeEdit.FiniteTree + +end OAI diff --git a/lean/OAI/Combinatorics/TreeEdit/WordOperations.lean b/lean/OAI/Combinatorics/TreeEdit/WordOperations.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ea5181ce08256852f7ab6bb1a7527cdbc41e013 --- /dev/null +++ b/lean/OAI/Combinatorics/TreeEdit/WordOperations.lean @@ -0,0 +1,171 @@ +import OAI.Combinatorics.TreeEdit.CyclicWords + +namespace OAI + +namespace TreeEdit + +universe u v + +variable {α : Type u} {x y z : List α} + +attribute [local instance] Classical.propDecidable + +namespace EditStep + +protected lemma map {β : Type*} (f : α → β) (h : EditStep x y) : + EditStep (x.map f) (y.map f) := by + cases h with + | insert p q a => simpa using EditStep.insert (p.map f) (q.map f) (f a) + | delete p q a => simpa using EditStep.delete (p.map f) (q.map f) (f a) + | substitute p q a b => simpa using EditStep.substitute (p.map f) (q.map f) (f a) (f b) + +end EditStep + +namespace EditScript + +protected lemma map {β : Type*} (f : α → β) {n : ℕ} (h : EditScript x y n) : + EditScript (x.map f) (y.map f) n := by + induction h with + | nil => exact .nil _ + | cons h _ ih => exact .cons (h.map f) ih + +end EditScript + +lemma ed_map {β : Type*} (f : α → β) (x y : List α) : ed (x.map f) (y.map f) ≤ ed x y := + ed_le_of_script ((ed_script x y).map f) + +lemma ed_flatten_ofFn {n : ℕ} (x y : Fin n → List α) : + ed (List.ofFn x).flatten (List.ofFn y).flatten ≤ ∑ i, ed (x i) (y i) := by + induction n with + | zero => simp + | succ n ih => + simp only [List.ofFn_succ, List.flatten_cons, Fin.sum_univ_succ] + exact (ed_append _ _ _ _).trans (Nat.add_le_add_left (ih _ _) _) + +namespace Words + +variable {β : Type v} {n : ℕ} + +lemma ofFn_get (x : Word β n) : List.ofFn (get x) = x.val := by + rcases x with ⟨x, rfl⟩ + exact List.ofFn_get x + +lemma cycles_val {m T B : ℕ} {β : Fin m → Type*} + (x : Fin T → ∀ i, Word (β i) B) : + (cycles x).val = (List.ofFn fun a => + (List.ofFn fun i => ((x a i).val.map (Sigma.mk i))).flatten).flatten := by + change List.ofFn _ = _ + rw [List.ofFn_mul] + congr 1 + apply congrArg List.ofFn + funext a + rw [List.ofFn_mul] + congr 1 + apply congrArg List.ofFn + funext i + rw [← ofFn_get (x a i), List.map_ofFn] + apply congrArg List.ofFn + funext j + have hB : 0 < B := lt_of_le_of_lt (Nat.zero_le j.val) j.isLt + have hm : 0 < m := lt_of_le_of_lt (Nat.zero_le i.val) i.isLt + have hmB : 0 < m * B := Nat.mul_pos hm hB + have hi : i.val * B + j.val < m * B := by nlinarith [i.isLt, j.isLt] + have hd₁ : (a.val * (m * B) + (i.val * B + j.val)) / (m * B) = a.val := by + rw [Nat.mul_comm a.val, Nat.mul_add_div hmB, Nat.div_eq_of_lt hi, add_zero] + have hr₁ : (a.val * (m * B) + (i.val * B + j.val)) % (m * B) = i.val * B + j.val := by + simp [Nat.add_mod, Nat.mod_eq_of_lt hi] + have hd₂ : (i.val * B + j.val) / B = i.val := by + rw [Nat.mul_comm i.val, Nat.mul_add_div hB, Nat.div_eq_of_lt j.isLt, add_zero] + have hr₂ : (i.val * B + j.val) % B = j.val := by + simp [Nat.add_mod, Nat.mod_eq_of_lt j.isLt] + let r : Fin (T * (m * B)) := ⟨a.val * (m * B) + (i.val * B + j.val), by + nlinarith [a.isLt]⟩ + have hra : r.divNat = a := Fin.ext hd₁ + have hri : r.modNat.divNat = i := by + apply Fin.ext + change (a.val * (m * B) + (i.val * B + j.val)) % (m * B) / B = i.val + rw [hr₁, hd₂] + have hrj : r.modNat.modNat = j := by + apply Fin.ext + change (a.val * (m * B) + (i.val * B + j.val)) % (m * B) % B = j.val + rw [hr₁, hr₂] + change Sigma.mk r.modNat.divNat (get (x r.divNat r.modNat.divNat) r.modNat.modNat) = + Sigma.mk i (get (x a i) j) + rw [hra, hri, hrj] + +lemma ed_cycles {m T B : ℕ} {β : Fin m → Type*} + (x y : Fin T → ∀ i, Word (β i) B) : + ed (cycles x).val (cycles y).val ≤ ∑ a : Fin T, ∑ i : Fin m, + ed (x a i).val (y a i).val := by + rw [cycles_val, cycles_val] + apply (ed_flatten_ofFn _ _).trans + apply Finset.sum_le_sum + intro a _ + apply (ed_flatten_ofFn _ _).trans + exact Finset.sum_le_sum fun i _ => ed_map (Sigma.mk i) _ _ + +end Words + +lemma sublist_ofFn_embedding {n N : ℕ} (f : Fin N → α) (e : Fin n ↪o Fin N) : + (List.ofFn (fun i => f (e i))).Sublist (List.ofFn f) := by + apply List.sublist_iff_exists_fin_orderEmbedding_get_eq.mpr + refine ⟨((Fin.castOrderIso List.length_ofFn).toOrderEmbedding.comp e).comp + (Fin.castOrderIso List.length_ofFn.symm).toOrderEmbedding, ?_⟩ + intro i + simp [List.get_eq_getElem, Fin.cast] + +lemma length_flatten_ofFn {n C : ℕ} (x : Fin n → List α) (hx : ∀ i, (x i).length = C) : + (List.ofFn x).flatten.length = n * C := by + simp [List.length_flatten, List.map_ofFn, Function.comp_def, hx] + +lemma ed_shifted_flatten {T C s : ℕ} (hs : s ≤ T) (x y : Fin T → List α) + (hx : ∀ i, (x i).length = C) (hy : ∀ i, (y i).length = C) + (he : ∀ a : Fin (T - s), x ⟨a.val + s, by have := a.isLt; omega⟩ = + y ⟨a.val, by have := a.isLt; omega⟩) : + ed (List.ofFn x).flatten (List.ofFn y).flatten ≤ 2 * s * C := by + let f : Fin (T - s) ↪o Fin T := OrderEmbedding.ofStrictMono + (fun a => ⟨a.val + s, by have := a.isLt; omega⟩) (by intro a b hab; simpa using hab) + let g : Fin (T - s) ↪o Fin T := OrderEmbedding.ofStrictMono + (fun a => ⟨a.val, by have := a.isLt; omega⟩) (by intro a b hab; exact hab) + have hl := (sublist_ofFn_embedding x f).flatten + have hr := (sublist_ofFn_embedding y g).flatten + have he' : (fun a => x (f a)) = (fun a => y (g a)) := funext he + rw [← he'] at hr + have hlen := length_flatten_ofFn (fun a => x (f a)) (fun a => hx (f a)) + have hh := length_le_lcs hl hr + rw [hlen] at hh + have hc := ed_le_twice_deficit (x := (List.ofFn x).flatten) (y := (List.ofFn y).flatten) + ((length_flatten_ofFn x hx).trans (length_flatten_ofFn y hy).symm) + simp only [deficit, length_flatten_ofFn x hx] at hc + have hmul : (T - s) * C + s * C = T * C := by rw [← Nat.add_mul, Nat.sub_add_cancel hs] + have hdef : T * C - lcs (List.ofFn x).flatten (List.ofFn y).flatten ≤ s * C := by omega + calc + _ ≤ 2 * (T * C - lcs (List.ofFn x).flatten (List.ofFn y).flatten) := hc + _ ≤ 2 * (s * C) := Nat.mul_le_mul_left 2 hdef + _ = 2 * s * C := by ring + +namespace Words + +variable {β : Type v} {n : ℕ} + +lemma ed_cycles_shift {m T B s : ℕ} {β : Fin m → Type*} (hs : s ≤ T) + (x y : Fin T → ∀ i, Word (β i) B) + (he : ∀ a : Fin (T - s), ∀ i, + x ⟨a.val + s, by have := a.isLt; omega⟩ i = + y ⟨a.val, by have := a.isLt; omega⟩ i) : + ed (cycles x).val (cycles y).val ≤ 2 * s * (m * B) := by + rw [cycles_val, cycles_val] + apply ed_shifted_flatten hs + · intro a; exact length_flatten_ofFn _ (fun i => by simp [(x a i).property]) + · intro a; exact length_flatten_ofFn _ (fun i => by simp [(y a i).property]) + · intro a + congr 1 + apply congrArg List.ofFn + funext i + rw [he a i] + +end Words + +end TreeEdit + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/AnchorEmbedding.lean b/lean/OAI/Combinatorics/TreewidthL1/AnchorEmbedding.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d3e449bba1218997dd76ea9142c4e8eb779bacc --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/AnchorEmbedding.lean @@ -0,0 +1,294 @@ +import OAI.Combinatorics.TreewidthL1.AnchorGeometry + +namespace OAI + +namespace BoundedTreewidthL1.AnchorExperiment +open MeasureTheory LaunchNoise AnchorTreeParticles TreeCache AnchorCache +open BoundedTreewidthL1.RootedTree +attribute [local instance 2000] Classical.decEq +attribute [local instance] Classical.propDecidable +noncomputable section +variable {V : Type*} [Fintype V] [MetricSpace V] {n : ℕ} +variable {T : SimpleGraph (Fin (n+1))} {hT : T.IsTree} {root : Fin (n+1)} + {B : Fin (n+1) → Finset V} {D : Fin (n+1) → V → ℝ} {k : ℕ} {J α π η : ℝ} + {seed : (i : Fin (n+1)) → OrdinarySeed (D i) α π η} + {cover : ∀ v, ∃ i, v ∈ B i} {run : ∀ v, (T.induce {i | v ∈ B i}).Preconnected} + (P : Model T hT root B D k J α π η seed cover run) + +noncomputable def graphPath (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (hdist : ∀ u v, dist u v = shortestPathDistance G ℓ u v) + (hne : ∀ i, (B i).Nonempty) + (hD : ∀ i, D i = bagDistance G ℓ (B i) (hne i)) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Connected) + (hbag : ∀ i, (B i).card ≤ k) (hbound : ∀ i v, D i v ≤ P.Δ) + (X Y : Fin (n+1)) (x y : V) (hx : x ∈ B X) (hy : y ∈ B Y) (s : ℕ) + (hsx : s ≤ (forest T hT root).depth X) (hsy : s ≤ (forest T hT root).depth Y) + (hs : (downPath T hT root X).getVert s = (downPath T hT root Y).getVert s) + (hmax : ∀ a b, a ≤ (forest T hT root).depth X → b ≤ (forest T hT root).depth Y → + (downPath T hT root X).getVert a = (downPath T hT root Y).getVert b → a = b ∧ a ≤ s) + (hpos : 0 < D ((downPath T hT root X).getVert s) x) : PathGeometry P := by + let q := downPath T hT root X + have hgeo (a t : ℕ) (hat : a ≤ t) : + D (q.getVert t) x ≤ D (q.getVert a) x ∧ + ∃ v ∈ B (q.getVert t), D (q.getVert a) v+dist x v = D (q.getVert a) x := by + have hp : q.getVert t ∈ (q.drop a).support := by + simpa only [SimpleGraph.Walk.drop_getVert,Nat.add_sub_of_le hat] using (q.drop a).getVert_mem_support (t-a) + have hh := separator_bag_geometry G ℓ hG hℓ T B hne hT hedge hrun (q.drop a) + ((downPath_isPath T hT root X).drop a) hp hx + rw [hD,hD] + refine ⟨hh.1,?_⟩ + obtain ⟨v,hv,hhv⟩ := hh.2 + refine ⟨v,hv,?_⟩ + rw [hdist,shortestPathDistance_comm G ℓ hG (fun e => (hℓ e).le) x v] + exact hhv + refine { + X := X, Y := Y, x := x, y := y, start := s, start_le := hsx, hx := hx, hy := hy, + positive := hpos, bounded := hbound, bag_bound := hbag + nonneg := ?_, lipschitz := ?_, zero := ?_, monotone := ?_, near := ?_, geodesic := ?_, suffix := ?_ } + · intro i v + rw [hD] + exact bagDistance_nonneg G ℓ hG (fun e => (hℓ e).le) (B i) (hne i) v + · intro i u v + rw [hD,hdist] + exact bagDistance_lipschitz G ℓ hG (fun e => (hℓ e).le) (B i) (hne i) u v + · intro i v hv + rw [hD] + apply le_antisymm + · have hh := bagDistance_le G ℓ (B i) (hne i) v hv + rw [shortestPathDistance_self G ℓ hG (fun e => (hℓ e).le)] at hh + exact hh + · exact bagDistance_nonneg G ℓ hG (fun e => (hℓ e).le) (B i) (hne i) v + · intro a t hat + exact (hgeo a t hat).1 + · intro t + obtain ⟨p,hp,hpdist⟩ := bagDistance_attained G ℓ (B (q.getVert t)) (hne _) x + exact ⟨p,hp,by rw [hD,hdist]; exact hpdist.symm⟩ + · intro a t hat ht + exact (hgeo a t hat).2 + · intro e hse he + exact ⟨(forest T hT root).depth Y-s,join_prefix_data T hT root X Y s hsx hsy hs hmax e hse he⟩ + +namespace PathGeometry +variable {P} (A : PathGeometry P) +noncomputable def track {H Q : ℝ} (C : TestParameters k α π η H Q) + (R : ReservationPath) (hR : R.last = (forest T hT root).depth A.X) + (hcache : ∀ t ≤ R.last, R.inclusive t = inclusiveCache k (bags T hT root B A.X) dist + (heights T hT root D A.X) J t) + (hsize : ∀ t, (R.inclusive t).card ≤ cacheBound k+1) + (hprotect : ∀ t, t < R.last → ∀ b ∈ protectedEntries (B (A.node t)) (R.inclusive t) dist + (fun p a => D (A.node a) p) J, t < R.finish b) : + GeometricTrack V (cacheBound k+1) (upper k) J H Q where + path := R + start := A.start + start_le := by rw [hR]; exact A.start_le + delta := A.δ + antitone := A.monotone + nonneg := fun t => A.nonneg _ _ + start_pos := A.positive + end_zero := by + change D ((downPath T hT root A.X).getVert R.last) A.x = 0 + rw [hR,← downPath_length,SimpleGraph.Walk.getVert_length] + exact A.zero A.X A.x A.hx + error := A.err + error_nonneg := norm_nonneg _ + size := hsize + B := fun t => B (A.node t) + D := fun t => D (A.node t) + x := A.x + at_x := fun _ => rfl + lipschitz := fun a => A.lipschitz (A.node a) + launch := by + intro a e he ha hs + rw [hcache e he] at ha + exact A.launch a e (by rwa [← hR]) ha hs + small := by + intro a e he ha hs hd + rw [hcache e he] at ha + exact A.small C a e (by rwa [← hR]) ha hs hd + obstruction := by + intro a e t he ha hs hst hte hg + rw [hcache e he] at ha + exact A.obstruction C a e t (by rwa [← hR]) ha hs hst hte hg + protect_rule := hprotect + +lemma lower_of_track {H Q : ℝ} (C : TestParameters k α π η H Q) + (hJ : J = 10*(upper k+4)) (hH : 10^5*J < H) + (c : ℝ) (hc : ∀ CC : CacheControl (cacheBound k+1) Q H, c ≤ CC.error) + (R : ReservationPath) (hR : R.last = (forest T hT root).depth A.X) + (hcache : ∀ t ≤ R.last, R.inclusive t = inclusiveCache k (bags T hT root B A.X) dist + (heights T hT root D A.X) J t) + (hsize : ∀ t, (R.inclusive t).card ≤ cacheBound k+1) + (hprotect : ∀ t, t < R.last → ∀ b ∈ protectedEntries (B (A.node t)) (R.inclusive t) dist + (fun p a => D (A.node a) p) J, t < R.finish b) : + c*A.δ A.start ≤ A.err := by + let QP := A.track C R hR hcache hsize hprotect + have hh := hc (QP.control (upper_pos k).le hJ hH C.qlarge) + change c ≤ A.err/A.δ A.start at hh + exact (le_div_iff₀ A.positive).mp hh +end PathGeometry +end +end BoundedTreewidthL1.AnchorExperiment + +namespace BoundedTreewidthL1.AnchorExperiment +noncomputable section + +theorem test_parameters_exist (k : ℕ) (α π : ℝ) (hα : 0 < α) (hα1 : α ≤ 1/8) + (hπ : 0 < π) (hπ1 : π ≤ 1) : + ∃ J H η Q : ℝ, J = 10*(upper k+4) ∧ 10^5*J < H ∧ + Nonempty (TestParameters k α π η H Q) := by + let J := 10*(upper k+4) + let H := 10^5*J+1 + have hU := upper_pos k + have hL := particleLip_pos k + have hJ : 0 < J := by dsimp [J]; positivity + have hH : 1 < H := by dsimp [H]; nlinarith + let η := 1/(16*H) + have hη : 0 < η := by dsimp [η]; positivity + have hη4 : η < 1/4 := by + dsimp [η]; apply (div_lt_div_iff₀ (by positivity) (by norm_num)).mpr; nlinarith + have hr : 4*η*H < 1 := by + have hH0 : H ≠ 0 := by linarith + dsimp [η]; field_simp; norm_num + let c := α/8*η + have hc : 0 < c := by dsimp [c]; positivity + have hc2 : c ≤ 1/2 := by + have hαη := mul_le_mul_of_nonneg_right hα1 hη.le + dsimp [c]; nlinarith + let b := c/(8*((k:ℝ)+1)) + have hb : 0 < b := by dsimp [b]; positivity + have hb1 : b ≤ 1 := by + dsimp [b]; apply (div_le_iff₀ (by positivity)).mpr + nlinarith [(Nat.cast_nonneg k : (0:ℝ) ≤ k)] + let w := π/8*b + have hw : 0 < w := by dsimp [w]; positivity + let Q := (1+upper k+particleLip k)/w+(upper k+1) + have hQ : upper k+1 ≤ Q := by + dsimp [Q]; have hh : 0 ≤ (1+upper k+particleLip k)/w := by positivity + linarith + have hbound : 1+upper k+particleLip k ≤ (π/8*b)*Q := by + have hh : w*((1+upper k+particleLip k)/w) = 1+upper k+particleLip k := + mul_div_cancel₀ _ hw.ne' + change _ ≤ w*Q + dsimp only [Q] + nlinarith [mul_nonneg hw.le (show 0 ≤ upper k+1 by positivity)] + refine ⟨J,H,η,Q,rfl,by dsimp [H]; linarith,⟨?_⟩⟩ + exact { + c := c, b := b, c_eq := rfl, c_pos := hc, c_half := hc2, + b_eq := rfl, b_pos := hb, b_one := hb1, eta_pos := hη, eta_small := hη4, + pi_pos := hπ, pi_one := hπ1, radius := hr, qbound := hbound, qlarge := hQ } +end +end BoundedTreewidthL1.AnchorExperiment + +namespace BoundedTreewidthL1.AnchorExperiment +open MeasureTheory LaunchNoise AnchorTreeParticles TreeCache AnchorCache +open BoundedTreewidthL1.RootedTree +attribute [local instance 2000] Classical.decEq +attribute [local instance] Classical.propDecidable +noncomputable section +variable {V : Type*} [Fintype V] [MetricSpace V] {n : ℕ} +variable {T : SimpleGraph (Fin (n+1))} {hT : T.IsTree} {root : Fin (n+1)} + {B : Fin (n+1) → Finset V} {D : Fin (n+1) → V → ℝ} {k : ℕ} {J α π η : ℝ} + {seed : (i : Fin (n+1)) → OrdinarySeed (D i) α π η} + {cover : ∀ v, ∃ i, v ∈ B i} {run : ∀ v, (T.induce {i | v ∈ B i}).Preconnected} + (P : Model T hT root B D k J α π η seed cover run) + +lemma Model.join_lower (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (hdist : ∀ u v, dist u v = shortestPathDistance G ℓ u v) + (hne : ∀ i, (B i).Nonempty) + (hD : ∀ i, D i = bagDistance G ℓ (B i) (hne i)) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Connected) + (hbag : ∀ i, (B i).card ≤ k) (hbound : ∀ i v, D i v ≤ P.Δ) + {H Q : ℝ} (C : TestParameters k α π η H Q) + (hJ : J = 10*(upper k+4)) (hH : 10^5*J < H) + (c : ℝ) (hc0 : 0 ≤ c) (hc : ∀ CC : CacheControl (cacheBound k+1) Q H, c ≤ CC.error) + (X Y : Fin (n+1)) (x y : V) (hx : x ∈ B X) (hy : y ∈ B Y) (s : ℕ) + (hsx : s ≤ (forest T hT root).depth X) (hsy : s ≤ (forest T hT root).depth Y) + (hs : (downPath T hT root X).getVert s = (downPath T hT root Y).getVert s) + (hmax : ∀ a b, a ≤ (forest T hT root).depth X → b ≤ (forest T hT root).depth Y → + (downPath T hT root X).getVert a = (downPath T hT root Y).getVert b → a = b ∧ a ≤ s) : + c*D ((downPath T hT root X).getVert s) x ≤ ‖P.map x-P.map y‖ := by + by_cases hp : 0 < D ((downPath T hT root X).getVert s) x + · let A := graphPath P G hG ℓ hℓ hdist hne hD hedge hrun hbag hbound X Y x y hx hy s hsx hsy hs hmax hp + obtain ⟨R,hR,hcache,hsize,hprotect⟩ := graph_cache_realizes G ℓ hG hℓ T B hne hT hedge hrun k hbag J + (downPath T hT root X) (downPath_isPath T hT root X) + have hR' : R.last = (forest T hT root).depth A.X := hR.trans (downPath_length T hT root X) + have hdF : dist = shortestPathDistance G ℓ := funext (fun u => funext (hdist u)) + have hDF : D = fun i => bagDistance G ℓ (B i) (hne i) := funext hD + have hcache' : ∀ t ≤ R.last, R.inclusive t = inclusiveCache k (bags T hT root B A.X) dist + (heights T hT root D A.X) J t := by + intro t ht + change R.inclusive t = inclusiveCache k (bags T hT root B X) dist (heights T hT root D X) J t + rw [hdF,hDF] + exact hcache t (by rwa [← hR]) + have hprotect' : ∀ t, t < R.last → ∀ b ∈ protectedEntries (B (A.node t)) (R.inclusive t) dist + (fun p a => D (A.node a) p) J, t < R.finish b := by + intro t ht b hb + apply hprotect t (by rwa [← hR]) b + rw [hcache' t ht.le] at hb + change b ∈ protectedEntries (B ((downPath T hT root X).getVert t)) + (inclusiveCache k (bags T hT root B X) dist (heights T hT root D X) J t) dist + (fun p a => D ((downPath T hT root X).getVert a) p) J at hb + rw [hdF,hDF] at hb + exact hb + exact A.lower_of_track C hJ hH c hc R hR' hcache' hsize hprotect' + · exact (mul_nonpos_of_nonneg_of_nonpos hc0 (le_of_not_gt hp)).trans (norm_nonneg _) + +/-- The constructed anchor ensemble controls BOTH distances to one actual common +bag. This is enough for all-pairs lower comparison when combined with co-bag +separation, and involves no assumed contraction/Markov-flow theorem. -/ +theorem anchor_common_bag_embedding (k : ℕ) (hk : 2 ≤ k) : + ∃ U c : ℝ, 0 < U ∧ 0 < c ∧ + ∀ (V : Type) [Fintype V] [DecidableEq V] [Nontrivial V] + (G : SimpleGraph V) (_ : G.Connected) (ℓ : G.edgeSet → ℝ) (_ : ∀ e, 0 < ℓ e) + (n : ℕ) (T : SimpleGraph (Fin (n+1))) (_ : T.IsTree) (_ : Fin (n+1)) + (B : Fin (n+1) → Finset V) (hne : ∀ i, (B i).Nonempty) + (_ : ∀ v, ∃ i, v ∈ B i) + (_ : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (_ : ∀ v, (T.induce {i | v ∈ B i}).Connected) + (_ : ∀ i, (B i).card ≤ k), + ∃ m : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin m => ℝ), + (∀ x y, ‖Φ x-Φ y‖ ≤ U*shortestPathDistance G ℓ x y) ∧ + ∀ x y, ∃ i, c*bagDistance G ℓ (B i) (hne i) x ≤ ‖Φ x-Φ y‖ ∧ + c*bagDistance G ℓ (B i) (hne i) y ≤ ‖Φ x-Φ y‖ := by + obtain ⟨α,π,hα,hα8,hπ,hπ1,hsampler⟩ := graph_ordinary_noise k hk + obtain ⟨J,H,η,Q,hJ,hH,⟨C⟩⟩ := test_parameters_exist k α π hα hα8 hπ hπ1 + have hQ : 0 < Q := by linarith [C.qlarge,upper_pos k] + obtain ⟨c,hc,hccontrol⟩ := CacheControl.uniform_lower (cacheBound k+1) Q H hQ + refine ⟨upper k,c,upper_pos k,hc,?_⟩ + intro V _ _ _ G hG ℓ hℓ n T hT root B hne hcover hedge hrun hbag + let := weightedMetricSpace G ℓ hG hℓ + let D := fun i => bagDistance G ℓ (B i) (hne i) + have hdec : HasTreeDecomposition G k := ⟨n+1,T,B,hT,hcover,hedge,hrun,hbag⟩ + have hnoise (i : Fin (n+1)) : HasOrdinaryNoise (D i) α π η := by + have hn := hsampler V G hG hdec ℓ hℓ (B i : Set V) (hne i) η C.eta_pos C.eta_small + have heq : D i = fun x => Metric.infDist x (B i : Set V) := by + funext x + exact bagDistance_eq_infDist G hG ℓ hℓ (B i) (hne i) x + rw [heq] + exact hn + let seed : (i : Fin (n+1)) → OrdinarySeed (D i) α π η := + fun i => Classical.choice (OrdinarySeed.exists_of_has (hnoise i)) + obtain ⟨P,hbound⟩ := model_exists G hG ℓ hℓ T hT root B hne hcover hedge hrun k hbag J α π η seed + refine ⟨P.dim,P.map,P.upper_bound,?_⟩ + intro x y + obtain ⟨X,hx⟩ := hcover x + obtain ⟨Y,hy⟩ := hcover y + obtain ⟨s,hsx,hsy,hs,hmax⟩ := exists_join_index T hT root X Y + refine ⟨(downPath T hT root X).getVert s,?_,?_⟩ + · exact P.join_lower G hG ℓ hℓ (fun _ _ => rfl) hne (fun _ => rfl) hedge hrun hbag hbound + C hJ hH c hc.le hccontrol X Y x y hx hy s hsx hsy hs hmax + · have hm : ∀ a b, a ≤ (forest T hT root).depth Y → b ≤ (forest T hT root).depth X → + (downPath T hT root Y).getVert a = (downPath T hT root X).getVert b → a = b ∧ a ≤ s := by + intro a b ha hb he + obtain ⟨hab,hbs⟩ := hmax b a hb ha he.symm + exact ⟨hab.symm,hab ▸ hbs⟩ + have hh := P.join_lower G hG ℓ hℓ (fun _ _ => rfl) hne (fun _ => rfl) hedge hrun hbag hbound + C hJ hH c hc.le hccontrol Y X y x hy hx s hsy hsx hs.symm hm + rw [norm_sub_rev,← hs] at hh + exact hh +end +end BoundedTreewidthL1.AnchorExperiment + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/AnchorExperiment.lean b/lean/OAI/Combinatorics/TreewidthL1/AnchorExperiment.lean new file mode 100644 index 0000000000000000000000000000000000000000..dfa51f70cab8354c5ffb90cafb30d784caea4057 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/AnchorExperiment.lean @@ -0,0 +1,322 @@ +import OAI.Combinatorics.TreewidthL1.CachedEnsemble + +namespace OAI + +namespace BoundedTreewidthL1.AnchorExperiment +open MeasureTheory LaunchNoise AnchorTreeParticles _root_.OAI.BoundedTreewidthL1.RootedTree TreeCache AnchorCache ParticleBatch ExpandedConstruction +open scoped ENNReal +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable +noncomputable section + +def count (k : ℕ) : ℕ := 2*(cacheBound k+1)+ k.factorial+2 +instance count_neZero (k : ℕ) : NeZero (count k) := ⟨by dsimp [count]; omega⟩ +def particleLip (k : ℕ) : ℝ := 3*((count k:ℝ)-1) +def upper (k : ℕ) : ℝ := (count k:ℝ)*particleLip k +lemma count_ge (k : ℕ) : 2 ≤ count k := by dsimp [count]; omega +lemma particleLip_pos (k : ℕ) : 0 < particleLip k := by + have hh : (2:ℝ) ≤ count k := by exact_mod_cast count_ge k + dsimp [particleLip]; linarith +lemma upper_pos (k : ℕ) : 0 < upper k := by + have hh : 0 < count k := lt_of_lt_of_le (by omega) (count_ge k) + exact mul_pos (by exact_mod_cast hh) (particleLip_pos k) + +attribute [local instance 2000] Classical.decEq +variable {V : Type*} [Fintype V] [MetricSpace V] {n : ℕ} +variable (T : SimpleGraph (Fin (n+1))) (hT : T.IsTree) (root : Fin (n+1)) + (B : Fin (n+1) → Finset V) (D : Fin (n+1) → V → ℝ) (k : ℕ) (J α π η : ℝ) + (seed : (i : Fin (n+1)) → OrdinarySeed (D i) α π η) +variable {D α π η} +abbrev Space := (i : Fin (n+1)) → NoiseSpace (seed i).n (seed i).m +noncomputable def measure : Measure (Space seed) := Measure.pi (fun i => noiseLaw (seed i).m (seed i).mass) +instance probability : IsProbabilityMeasure (measure seed) := by + let (i : Fin (n+1)) := (seed i).probability + exact inferInstanceAs (IsProbabilityMeasure (Measure.pi _)) +variable (D α π η) +noncomputable def noise (ω : Space seed) (i : Fin (n+1)) (_ : Fin (n+1)) (v : V) : ℝ := noiseG (D i) (seed i).bump (ω i) v +noncomputable def states (ω : Space seed) := state (ι := Fin (count k)) (forest T hT root) B + (active T hT root B D k dist J) (noise D α π η seed ω) +noncomputable def raw (cover : ∀ v, ∃ i, v ∈ B i) (H Δ : ℝ) (ω : Space seed) (x y : V) : ℝ := + cutDistance (ExpandedAnchor.law (ι := Fin (count k)) T hT root B (active T hT root B D k dist J) + (noise D α π η seed ω) (H*((count k:ℝ)-1)+2*Δ)) + (ExpandedTree.assemble (fun i => (B i : Set V)) cover (ExpandedParticleLaw.label (ι := Fin (count k)))) x y + +structure Model (cover : ∀ v, ∃ i, v ∈ B i) (run : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) where + H : ℝ + Δ : ℝ + H_pos : 0 < H + Δ_pos : 0 < Δ + reach : ∀ ω i, FunctionParticleReachable dist 3 H (states T hT root B D k J α π η seed ω i).1 + trace : ∀ ω i p, (forest T hT root).parent i = some p → + particleTrace (H*((count k:ℝ)-1)+2*Δ) (states T hT root B D k J α π η seed ω i).1 (B i) = + particleTrace (H*((count k:ℝ)-1)+2*Δ) (states T hT root B D k J α π η seed ω p).1 (B i) + pairs : ∀ ω i p, (forest T hT root).parent i = some p → ∀ a ∈ + active T hT root B D k dist J i ∩ active T hT root B D k dist J p, + (states T hT root B D k J α π η seed ω i).2 a = (states T hT root B D k J α π η seed ω p).2 a ∧ + (states T hT root B D k J α π η seed ω i).1 ((states T hT root B D k J α π η seed ω i).2 a).1 = + (states T hT root B D k J α π η seed ω p).1 ((states T hT root B D k J α π η seed ω p).2 a).1 ∧ + (states T hT root B D k J α π η seed ω i).1 ((states T hT root B D k J α π η seed ω i).2 a).2 = + (states T hT root B D k J α π η seed ω p).1 ((states T hT root B D k J α π η seed ω p).2 a).2 + unique : ∀ ω i, PairUnique (active T hT root B D k dist J i) (states T hT root B D k J α π η seed ω i).2 + gap : ∀ ω i v, + (states T hT root B D k J α π η seed ω i).1 ((states T hT root B D k J α π η seed ω i).2 i).1 v- + (states T hT root B D k J α π η seed ω i).1 ((states T hT root B D k J α π η seed ω i).2 i).2 v = + 2*noise D α π η seed ω i i v + nonneg : ∀ ω x y, 0 ≤ raw T hT root B D k J α π η seed cover H Δ ω x y + integrable : ∀ x y, Integrable (fun ω => raw T hT root B D k J α π η seed cover H Δ ω x y) (measure seed) + dim : ℕ + map : V → PiLp (1 : ENNReal) (fun _ : Fin dim => ℝ) + average : ∀ x y, ‖map x-map y‖ = ∫ ω, raw T hT root B D k J α π η seed cover H Δ ω x y ∂measure seed + upper_bound : ∀ x y, ‖map x-map y‖ ≤ upper k*dist x y + +namespace Model +variable {T hT root B D k J α π η seed} {cover : ∀ v, ∃ i, v ∈ B i} + {run : ∀ v, (T.induce {i | v ∈ B i}).Preconnected} + (P : Model T hT root B D k J α π η seed cover run) +noncomputable def datum (ω : Space seed) := + CachedEnsemble.data T hT root B cover run D k dist J (states T hT root B D k J α π η seed ω) + (P.H*((count k:ℝ)-1)+2*P.Δ) (P.pairs ω) (P.trace ω) +lemma datum_dist (ω : Space seed) (x y : V) : + (P.datum ω).dist x y = raw T hT root B D k J α π η seed cover P.H P.Δ ω x y := rfl +lemma M_pos : 0 < P.H*((count k:ℝ)-1)+2*P.Δ := by + have hh : (2:ℝ) ≤ count k := by exact_mod_cast count_ge k + nlinarith [P.H_pos,P.Δ_pos] +lemma height (ω : Space seed) (i : Fin (n+1)) (r : Fin (count k)) (x : V) : + |(states T hT root B D k J α π η seed ω i).1 r x| ≤ P.H*((count k:ℝ)-1) := by + simpa only [Fintype.card_fin] using function_particles_height_bound P.H_pos (P.reach ω i) r x +include P +lemma lipschitz (ω : Space seed) (i : Fin (n+1)) (r : Fin (count k)) (x z : V) : + |(states T hT root B D k J α π η seed ω i).1 r x- + (states T hT root B D k J α π η seed ω i).1 r z| ≤ particleLip k*dist x z := by + simpa only [Fintype.card_fin,particleLip] using function_particles_metric_bound (by norm_num : (0:ℝ)<3) (P.reach ω i) r x z +lemma pair_distinct (ω : Space seed) (i : Fin (n+1)) : + ((states T hT root B D k J α π η seed ω i).2 i).1 ≠ + ((states T hT root B D k J α π η seed ω i).2 i).2 := by + intro hh + have hb := (P.unique ω i i (active_self T hT root B D k dist J i) + i (active_self T hT root B D k dist J i) false true hh).2 + cases hb + +lemma gap_probability (a : Fin (n+1)) (x : V) (C : Finset V) + (t β γ : ℝ) (ht : 0 ≤ t) (hβ : 0 < β) (hγ : 0 < γ) (hπ : 0 ≤ π) (hx : 0 < D a x) + (hamp : ∀ loc, GoodBump (D a) α η ((seed a).bump loc) x → ∀ s ∈ C, + β ≤ |D a x-D a s| ∨ ∃ j, γ ≤ |(seed a).bump loc j x-(seed a).bump loc j s|) + (hbudget : (C.card : ℝ)*(2*t/β+2*t/γ) ≤ 1/2) : + ENNReal.ofReal (π/4) ≤ measure seed {ω : Space seed | ∀ s ∈ C, t ≤ + |positive (ι := Fin (count k)) (forest T hT root) B (active T hT root B D k dist J) + (noise D α π η seed ω) a x- + positive (ι := Fin (count k)) (forest T hT root) B (active T hT root B D k dist J) + (noise D α π η seed ω) a s|} := by + let (i : Fin (n+1)) := (seed i).probability + let (i : Fin (n+1)) : Nonempty (NoiseSpace (seed i).n (seed i).m) := + nonempty_of_isProbabilityMeasure (noiseLaw (seed i).m (seed i).mass) + apply NoiseCube.node_gap D α π η seed a x C _ _ _ t β γ ht hβ hγ hπ hx hamp hbudget + · intro v + apply measurable_positive + intro i b v + exact ((measurable_pi_apply v).comp (seed i).measurable).comp (measurable_pi_apply i) + · exact positive_affine (forest T hT root) B (active T hT root B D k dist J) + (fun i u => noiseG (D i) (seed i).bump u) a + (TreeCache.fresh_eq_singleton T hT root B D k dist J a) (fun ω => P.pair_distinct ω a) + +lemma height_test (X Y : Fin (n+1)) (x y z : V) (hy : y ∈ B Y) (s e l a t : ℕ) + (he : e ≤ (forest T hT root).depth X) (hst : s ≤ t) (hte : t < e) (hat : a < t) + (ha : a ∈ inclusiveCache k (bags T hT root B X) dist (heights T hT root D X) J e) + (hz : z ∈ B ((downPath T hT root X).getVert e)) + (hlen : (forest T hT Y).depth ((downPath T hT root X).getVert e) = l+(e-s)) + (hpath : ∀ b, s ≤ b → b ≤ e → + (downPath T hT Y ((downPath T hT root X).getVert e)).getVert (l+(b-s)) = (downPath T hT root X).getVert b) + (τ β γ : ℝ) (hτ : 0 ≤ τ) (hτΔ : τ ≤ 2*P.Δ) (hβ : 0 < β) (hγ : 0 < γ) (hπ : 0 ≤ π) + (hx : 0 < D ((downPath T hT root X).getVert a) x) + (hamp : ∀ loc, GoodBump (D ((downPath T hT root X).getVert a)) α η + ((seed ((downPath T hT root X).getVert a)).bump loc) x → + ∀ v ∈ B ((downPath T hT root X).getVert t), + β ≤ |D ((downPath T hT root X).getVert a) x-D ((downPath T hT root X).getVert a) v| ∨ + ∃ j, γ ≤ |(seed ((downPath T hT root X).getVert a)).bump loc j x- + (seed ((downPath T hT root X).getVert a)).bump loc j v|) + (hbudget : ((B ((downPath T hT root X).getVert t)).card : ℝ)*(2*τ/β+2*τ/γ) ≤ 1/2) : + (π/8)*(τ-particleLip k*dist x z) ≤ ‖P.map y-P.map z‖ := by + let v := (downPath T hT root X).getVert + let F := fun (ω : Space seed) => positive (ι := Fin (count k)) (forest T hT root) B + (active T hT root B D k dist J) (noise D α π η seed ω) (v a) + let E := {ω : Space seed | ∀ b ∈ B (v t), τ ≤ |F ω x-F ω b|} + have hmeas (b : V) : Measurable (fun ω => F ω b) := by + apply measurable_positive + intro i c b + exact ((measurable_pi_apply b).comp (seed i).measurable).comp (measurable_pi_apply i) + have hE : MeasurableSet E := by + simp only [E,Set.ofPred_forall] + exact MeasurableSet.iInter (fun b => MeasurableSet.iInter (fun _ => + measurableSet_le measurable_const ((hmeas x).sub (hmeas b)).abs)) + have hprob : ENNReal.ofReal (π/4) ≤ measure seed E := + P.gap_probability (v a) x (B (v t)) τ β γ hτ hβ hγ hπ hx hamp hbudget + have hlower (ω : Space seed) (hω : ω ∈ E) : + (τ-particleLip k*dist x z)/2 ≤ raw T hT root B D k J α π η seed cover P.H P.Δ ω y z := by + rw [← P.datum_dist] + apply CachedEnsemble.height T hT root B cover run D k dist J + (states T hT root B D k J α π η seed ω) _ (P.pairs ω) (P.trace ω) + P.M_pos (P.unique ω) X Y y z hy s e l a t he hst hte hat ha hz hlen hpath false + (τ-particleLip k*dist x z) + · intro b + change |F ω b| ≤ _ + exact (P.height ω (v a) _ b).trans (by linarith [P.Δ_pos]) + · have hh := (abs_le.mp (P.height ω (v a) ((states T hT root B D k J α π η seed ω (v a)).2 (v a)).1 z)).1 + have hn := mul_nonneg (particleLip_pos k).le (dist_nonneg (x := x) (y := z)) + simp only [pairIndex, Bool.false_eq_true, ite_false] + change τ-particleLip k*dist x z ≤ _ + linarith + · have hh := (abs_le.mp (P.height ω (v a) ((states T hT root B D k J α π η seed ω (v a)).2 (v a)).1 z)).2 + have hn := mul_nonneg (particleLip_pos k).le (dist_nonneg (x := x) (y := z)) + simp only [pairIndex, Bool.false_eq_true, ite_false] + change τ-particleLip k*dist x z ≤ _ + linarith + · exact gap_proxy dist (F ω) x z (B (v t)) (particleLip k) τ + (P.lipschitz ω (v a) _ x z) hω + have hh := event_lower_integral (measure seed) _ (P.integrable y z) (fun ω => P.nonneg ω y z) + E hE (π/4) ((τ-particleLip k*dist x z)/2) (by positivity) hprob hlower + rw [P.average] + convert hh using 1 ; ring + +lemma launch_test (hzero : ∀ i v, v ∈ B i → D i v = 0) + (X Y : Fin (n+1)) (y z : V) (hy : y ∈ B Y) (s e l a : ℕ) + (he : e ≤ (forest T hT root).depth X) (hsa : s ≤ a) (hae : a < e) + (ha : a ∈ inclusiveCache k (bags T hT root B X) dist (heights T hT root D X) J e) + (hz : z ∈ B ((downPath T hT root X).getVert e)) + (hlen : (forest T hT Y).depth ((downPath T hT root X).getVert e) = l+(e-s)) + (hpath : ∀ b, s ≤ b → b ≤ e → + (downPath T hT Y ((downPath T hT root X).getVert e)).getVert (l+(b-s)) = (downPath T hT root X).getVert b) : + D ((downPath T hT root X).getVert a) z ≤ ‖P.map y-P.map z‖ := by + let v := (downPath T hT root X).getVert + have hp (ω : Space seed) : D (v a) z ≤ raw T hT root B D k J α π η seed cover P.H P.Δ ω y z := by + have ht := CachedEnsemble.launch T hT root B cover run D k dist J + (states T hT root B D k J α π η seed ω) _ (P.pairs ω) (P.trace ω) + P.M_pos (P.unique ω) X Y y z hy s e l a he hsa hae ha hz hlen hpath + have hbag : ∀ b ∈ B (v a), + (states T hT root B D k J α π η seed ω (v a)).1 ((states T hT root B D k J α π η seed ω (v a)).2 (v a)).1 b = + (states T hT root B D k J α π η seed ω (v a)).1 ((states T hT root B D k J α π η seed ω (v a)).2 (v a)).2 b := by + intro b hb + have hh := ((seed (v a)).bounds (ω (v a))).2.2.2 b + rw [hzero _ _ hb] at hh + have hg := P.gap ω (v a) b + change _ = 2*noiseG (D (v a)) (seed (v a)).bump (ω (v a)) b at hg + linarith + specialize ht hbag (fun i r b => (P.height ω i r b).trans (by linarith [P.Δ_pos])) + change |_ - _|/2 ≤ (P.datum ω).dist y z at ht + rw [P.gap ω (v a) z,P.datum_dist] at ht + have hh := ((seed (v a)).bounds (ω (v a))).2.2.2 z + have ha := le_abs_self (2*noise D α π η seed ω (v a) (v a) z) + change D (v a) z ≤ noise D α π η seed ω (v a) (v a) z ∧ _ at hh + linarith + rw [P.average] + have hh := integral_mono (integrable_const (D (v a) z)) (P.integrable y z) hp + simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using hh + +end Model +end +end BoundedTreewidthL1.AnchorExperiment + +namespace BoundedTreewidthL1.AnchorExperiment +open MeasureTheory LaunchNoise AnchorTreeParticles _root_.OAI.BoundedTreewidthL1.RootedTree TreeCache AnchorCache ParticleBatch ExpandedConstruction +attribute [local instance 2000] Classical.decEq +attribute [local instance] Classical.propDecidable +noncomputable section + +/-- Every chosen actual finite ordinary seed produces the ensemble; no consistency +or global lower comparison is an assumption. -/ +theorem model_exists {V : Type*} [Fintype V] [DecidableEq V] {n : ℕ} + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph (Fin (n+1))) (hT : T.IsTree) (root : Fin (n+1)) + (B : Fin (n+1) → Finset V) (hne : ∀ i, (B i).Nonempty) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Connected) + (k : ℕ) (hbag : ∀ i, (B i).card ≤ k) (J α π η : ℝ) : + let := weightedMetricSpace G ℓ hG hℓ + let D := fun i => bagDistance G ℓ (B i) (hne i) + ∀ seed : (i : Fin (n+1)) → OrdinarySeed (D i) α π η, + ∃ P : Model T hT root B D k J α π η seed hcover (fun v => (hrun v).preconnected), + ∀ i v, D i v ≤ P.Δ := by + let := weightedMetricSpace G ℓ hG hℓ + let D := fun i => bagDistance G ℓ (B i) (hne i) + dsimp only + intro seed + let A := active T hT root B D k dist J + let q := cacheBound k+1 + let R := forest T hT root + let g := noise D α π η seed + let S := states T hT root B D k J α π η seed + let H : ℝ := 1+3*∑ i, ∑ v, D i v + let Δ : ℝ := 1+∑ i, ∑ v, D i v + have hD : ∀ i v, 0 ≤ D i v := fun i v => + bagDistance_nonneg G ℓ hG (fun e => (hℓ e).le) (B i) (hne i) v + have hsum : 0 ≤ ∑ i, ∑ v, D i v := + Finset.sum_nonneg (fun i _ => Finset.sum_nonneg (fun v _ => hD i v)) + have hH : 0 < H := by dsimp [H]; positivity + have hΔ : 0 < Δ := by dsimp [Δ]; positivity + have hdSum (i : Fin (n+1)) (v : V) : D i v ≤ ∑ j, ∑ x, D j x := by + apply (Finset.single_le_sum (fun x (_ : x ∈ (Finset.univ : Finset V)) => hD i x) (Finset.mem_univ v)).trans + exact Finset.single_le_sum (fun j (_ : j ∈ (Finset.univ : Finset (Fin (n+1)))) => + Finset.sum_nonneg (fun x _ => hD j x)) (Finset.mem_univ i) + have hdH (i : Fin (n+1)) (v : V) : (5/2)*D i v ≤ H := by + dsimp [H]; linarith [hdSum i v,hD i v] + have hg : ∀ i a v, Measurable (fun ω => g ω i a v) := by + intro i a v + exact ((measurable_pi_apply v).comp (seed i).measurable).comp (measurable_pi_apply i) + have hLip : ∀ ω i a u v, |g ω i a u-g ω i a v| ≤ 3*shortestPathDistance G ℓ u v := by + intro ω i a u v + exact ((seed i).bounds (ω i)).2.2.1.dist_le_mul u v + have hHeight : ∀ ω i a v, |g ω i a v| ≤ H := by + intro ω i a v + have hb := ((seed i).bounds (ω i)).2.2.2 v + change |noiseG (D i) (seed i).bump (ω i) v| ≤ H + rw [abs_of_nonneg ((hD i v).trans hb.1)] + exact hb.2.trans (hdH i v) + have hz : ∀ ω i a v, v ∈ B i → g ω i a v = 0 := by + intro ω i a v hv + have hb := ((seed i).bounds (ω i)).2.2.2 v + have he : D i v = 0 := by + rw [show D i v = Metric.infDist v (B i : Set V) from + bagDistance_eq_infDist G hG ℓ hℓ (B i) (hne i) v] + exact Metric.infDist_zero_of_mem hv + change D i v ≤ g ω i a v ∧ g ω i a v ≤ (5/2)*D i v at hb + rw [he] at hb + exact le_antisymm (by simpa only [mul_zero] using hb.2) hb.1 + have hA : ∀ i, (A i).card ≤ q := + graph_active_bound G ℓ hG hℓ T B hne hT root hedge hrun k hbag J + have hN : Fintype.card (Fin (count k)) = 2*q+k.factorial+2 := by exact Fintype.card_fin _ + have hf (ω : Space seed) := forest_particle_realization (ι := Fin (count k)) R B A k q hbag hA + hN dist 3 H Δ hH hΔ (g ω) (hLip ω) (hHeight ω) (hz ω) + obtain ⟨hwn,hwt,hwi,m,Φ,hΦ,hup,hco⟩ := ExpandedAnchor.realization (ι := Fin (count k)) + G hG ℓ hℓ T hT root B hcover hedge (fun v => (hrun v).preconnected) A k q hbag hA hN + (measure seed) 3 H Δ (by norm_num) hH hΔ g hg hLip hHeight hz + let P : Model T hT root B D k J α π η seed hcover (fun v => (hrun v).preconnected) := { + H := H, Δ := Δ, H_pos := hH, Δ_pos := hΔ + reach := fun ω i => (hf ω).1 i + trace := fun ω i p hp => by simpa only [states,R,A,g,Fintype.card_fin] using (hf ω).2.1 i p hp + pairs := fun ω i p hp a ha => (hf ω).2.2.1 i p hp a (by simpa only [Finset.mem_inter] using ha) + unique := fun ω => state_unique R B A (g ω) k q hN hbag hA + gap := fun ω i v => by + apply ((hf ω).2.2.2 i i ?_).2 v + rw [show fresh R A i = {i} from fresh_eq_singleton T hT root B D k dist J i] + exact Finset.mem_singleton_self i + nonneg := fun ω x y => Finset.sum_nonneg (fun c _ => by split_ifs; exact le_rfl; simpa only [Fintype.card_fin] using hwn ω c) + integrable := fun x y => by + apply integrable_finsetSum + intro c _ + split_ifs + · exact integrable_zero _ _ _ + · simpa only [Fintype.card_fin] using hwi c + dim := m + map := Φ + average := fun x y => by simpa only [raw,A,g,Fintype.card_fin] using hΦ x y + upper_bound := fun x y => by + change ‖Φ x-Φ y‖ ≤ upper k*shortestPathDistance G ℓ x y + convert hup x y using 1 ; simp only [Fintype.card_fin,upper,particleLip] ; ring } + refine ⟨P,?_⟩ + intro i v + change D i v ≤ Δ + dsimp [Δ]; linarith [hdSum i v] +end +end BoundedTreewidthL1.AnchorExperiment + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/AnchorGeometry.lean b/lean/OAI/Combinatorics/TreewidthL1/AnchorGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..f443a47ce7e85fa82bf20a81c4f6ad4ecbad6225 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/AnchorGeometry.lean @@ -0,0 +1,211 @@ +import OAI.Combinatorics.TreewidthL1.CacheControl + +namespace OAI + +namespace BoundedTreewidthL1.AnchorExperiment +open MeasureTheory LaunchNoise AnchorTreeParticles TreeCache AnchorCache +open BoundedTreewidthL1.RootedTree +attribute [local instance 2000] Classical.decEq +attribute [local instance] Classical.propDecidable +noncomputable section + +structure TestParameters (k : ℕ) (α π η H Q : ℝ) where + c : ℝ + b : ℝ + c_eq : c = α/8*η + c_pos : 0 < c + c_half : c ≤ 1/2 + b_eq : b = c/(8*((k:ℝ)+1)) + b_pos : 0 < b + b_one : b ≤ 1 + eta_pos : 0 < η + eta_small : η < 1/4 + pi_pos : 0 < π + pi_one : π ≤ 1 + radius : 4*η*H < 1 + qbound : 1+upper k+particleLip k ≤ (π/8*b)*Q + qlarge : upper k+1 ≤ Q + +variable {V : Type*} [Fintype V] [MetricSpace V] {n : ℕ} +variable {T : SimpleGraph (Fin (n+1))} {hT : T.IsTree} {root : Fin (n+1)} + {B : Fin (n+1) → Finset V} {D : Fin (n+1) → V → ℝ} {k : ℕ} {J α π η : ℝ} + {seed : (i : Fin (n+1)) → OrdinarySeed (D i) α π η} + {cover : ∀ v, ∃ i, v ∈ B i} {run : ∀ v, (T.induce {i | v ∈ B i}).Preconnected} + (P : Model T hT root B D k J α π η seed cover run) + +/-- All properties here are literal shortest-path/bag geometry. -/ +structure PathGeometry where + X : Fin (n+1) + Y : Fin (n+1) + x : V + y : V + start : ℕ + start_le : start ≤ (forest T hT root).depth X + hx : x ∈ B X + hy : y ∈ B Y + positive : 0 < D ((downPath T hT root X).getVert start) x + nonneg : ∀ i v, 0 ≤ D i v + lipschitz : ∀ i u v, |D i u-D i v| ≤ dist u v + zero : ∀ i v, v ∈ B i → D i v = 0 + bounded : ∀ i v, D i v ≤ P.Δ + bag_bound : ∀ i, (B i).card ≤ k + monotone : Antitone (fun t => D ((downPath T hT root X).getVert t) x) + near : ∀ t, ∃ p ∈ B ((downPath T hT root X).getVert t), + dist x p = D ((downPath T hT root X).getVert t) x + geodesic : ∀ a t, a ≤ t → t ≤ (forest T hT root).depth X → + ∃ v ∈ B ((downPath T hT root X).getVert t), + D ((downPath T hT root X).getVert a) v + dist x v = D ((downPath T hT root X).getVert a) x + suffix : ∀ e, start ≤ e → e ≤ (forest T hT root).depth X → ∃ l, + (forest T hT Y).depth ((downPath T hT root X).getVert e) = l+(e-start) ∧ + ∀ b, start ≤ b → b ≤ e → + (downPath T hT Y ((downPath T hT root X).getVert e)).getVert (l+(b-start)) = + (downPath T hT root X).getVert b + +namespace PathGeometry +variable {P} (A : PathGeometry P) +abbrev node (t : ℕ) := (downPath T hT root A.X).getVert t +abbrev δ (t : ℕ) := D (A.node t) A.x +abbrev err := ‖P.map A.x-P.map A.y‖ +abbrev cached (a e : ℕ) := a ∈ inclusiveCache k (bags T hT root B A.X) dist (heights T hT root D A.X) J e +lemma lower_near (t : ℕ) (v : V) (hv : v ∈ B (A.node t)) : A.δ t ≤ dist A.x v := by + have hh := A.lipschitz (A.node t) A.x v + rw [A.zero _ _ hv,sub_zero,abs_of_nonneg (A.nonneg _ _)] at hh + exact hh +lemma proxy_upper (z : V) : ‖P.map A.y-P.map z‖ ≤ A.err+upper k*dist A.x z := by + have hh := dist_triangle (P.map A.y) (P.map A.x) (P.map z) + simp only [dist_eq_norm] at hh + rw [norm_sub_rev (P.map A.y) (P.map A.x)] at hh + have hu := P.upper_bound A.x z + change ‖P.map A.y-P.map z‖ ≤ ‖P.map A.x-P.map A.y‖+upper k*dist A.x z + linarith + +lemma numerical_test {H Q : ℝ} (C : TestParameters k α π η H Q) + (v d : ℝ) (hd : 0 ≤ d) + (ht : (π/8)*(C.b*v-particleLip k*d) ≤ A.err+upper k*d) : + v ≤ Q*(A.err+d) := by + have hp : 0 < π/8*C.b := mul_pos (by linarith [C.pi_pos]) C.b_pos + have hπ : 0 ≤ π/8 := by linarith [C.pi_pos] + have hπ1 : π/8 ≤ 1 := by linarith [C.pi_one] + have hL := particleLip_pos k + have hU := upper_pos k + have hE : 0 ≤ A.err := norm_nonneg _ + have hLπ : (π/8)*particleLip k ≤ particleLip k := mul_le_of_le_one_left hL.le hπ1 + have hm := mul_le_mul_of_nonneg_right C.qbound (add_nonneg hE hd) + have he := mul_nonneg (add_nonneg hU.le hL.le) hE + have hld := mul_le_mul_of_nonneg_right hLπ hd + nlinarith + +lemma trivial_test {H Q : ℝ} (C : TestParameters k α π η H Q) (e : ℕ) (he : e ≤ A.start) : + A.δ A.start ≤ Q*(A.err+A.δ e) := by + have hq : 1 ≤ Q := by linarith [C.qlarge,upper_pos k] + have hm := mul_le_mul_of_nonneg_right hq (add_nonneg (norm_nonneg (P.map A.x-P.map A.y)) (A.nonneg (A.node e) A.x)) + have hd := A.monotone he + nlinarith [norm_nonneg (P.map A.x-P.map A.y)] + +lemma launch (a e : ℕ) (he : e ≤ (forest T hT root).depth A.X) (ha : A.cached a e) + (hsa : A.start ≤ a) : A.δ a ≤ A.err+(upper k+1)*A.δ e := by + have hae : a ≤ e := inclusive_age k _ _ _ _ e a ha + by_cases heq : a = e + · subst a + nlinarith [A.nonneg (A.node e) A.x, norm_nonneg (P.map A.x-P.map A.y),upper_pos k] + obtain ⟨l,hlen,hpath⟩ := A.suffix e (hsa.trans hae) he + obtain ⟨z,hz,hzdist⟩ := A.near e + have ht := P.launch_test A.zero A.X A.Y A.y z A.hy A.start e l a he hsa (lt_of_le_of_ne hae heq) ha hz hlen hpath + have hl := (abs_le.mp (A.lipschitz (A.node a) A.x z)).2 + have hu := A.proxy_upper z + rw [hzdist] at hl hu + change A.δ a-_ ≤ _ at hl + linarith + +lemma budget {H Q : ℝ} (C : TestParameters k α π η H Q) + (v β γ : ℝ) (hv : 0 ≤ v) (hβ : 0 < β) (hγ : 0 < γ) + (hvb : C.c*v ≤ β) (hvg : C.c*v ≤ γ) (t : ℕ) : + ((B (A.node t)).card:ℝ)*(2*(C.b*v)/β+2*(C.b*v)/γ) ≤ 1/2 := by + have hh := gap_budget k β γ (C.c*v) hβ hγ (mul_nonneg C.c_pos.le hv) hvb hvg + have heq : C.c*v/(8*((k:ℝ)+1)) = C.b*v := by rw [C.b_eq]; ring + rw [heq] at hh + apply le_trans _ hh + exact mul_le_mul_of_nonneg_right (by exact_mod_cast A.bag_bound (A.node t)) (by positivity [C.b_pos]) + +lemma bounded_tau {H Q : ℝ} (C : TestParameters k α π η H Q) (t : ℕ) : C.b*A.δ t ≤ 2*P.Δ := by + have hh := mul_le_mul_of_nonneg_right C.b_one (A.nonneg (A.node t) A.x) + have hb := A.bounded (A.node t) A.x + nlinarith [P.Δ_pos] + +lemma small {H Q : ℝ} (C : TestParameters k α π η H Q) + (a e : ℕ) (he : e ≤ (forest T hT root).depth A.X) (ha : A.cached a e) + (has : a < A.start) (hDa : A.δ a ≤ H*A.δ A.start) : + A.δ A.start ≤ Q*(A.err+A.δ e) := by + by_cases hes : e ≤ A.start + · exact A.trivial_test C e hes + have hse : A.start < e := lt_of_not_ge hes + obtain ⟨l,hlen,hpath⟩ := A.suffix e hse.le he + obtain ⟨z,hz,hzdist⟩ := A.near e + have hAa : A.δ A.start ≤ A.δ a := A.monotone has.le + have hapos : 0 < A.δ a := A.positive.trans_le hAa + have hrad : 4*η*A.δ a < A.δ A.start := by + have hm := mul_le_mul_of_nonneg_left hDa (show 0 ≤ 4*η by positivity [C.eta_pos]) + have hh := mul_lt_mul_of_pos_right C.radius A.positive + nlinarith + have hamp : ∀ loc, GoodBump (D (A.node a)) α η ((seed (A.node a)).bump loc) A.x → + ∀ v ∈ B (A.node A.start), A.δ A.start ≤ |D (A.node a) A.x-D (A.node a) v| ∨ + ∃ j, C.c*A.δ a ≤ |(seed (A.node a)).bump loc j A.x-(seed (A.node a)).bump loc j v| := by + intro loc hg v hv + obtain ⟨j,hj,hn,hzero⟩ := hg + right + refine ⟨j,?_⟩ + rw [hzero v (hrad.trans_le (A.lower_near A.start v hv)),sub_zero,abs_of_nonneg (hn A.x)] + simpa only [C.c_eq,mul_assoc] using hj + have ht := P.height_test A.X A.Y A.x A.y z A.hy A.start e l a A.start he le_rfl hse has ha hz hlen hpath + (C.b*A.δ A.start) (A.δ A.start) (C.c*A.δ a) (by positivity [C.b_pos,A.positive]) + (A.bounded_tau C A.start) A.positive (mul_pos C.c_pos hapos) C.pi_pos.le hapos hamp + (A.budget C (A.δ A.start) (A.δ A.start) (C.c*A.δ a) A.positive.le A.positive (mul_pos C.c_pos hapos) + (by nlinarith [C.c_half,A.positive]) (mul_le_mul_of_nonneg_left hAa C.c_pos.le) A.start) + have hu := A.proxy_upper z + rw [hzdist] at ht hu + exact A.numerical_test C (A.δ A.start) (A.δ e) (A.nonneg _ _) (ht.trans hu) + +lemma obstruction {H Q : ℝ} (C : TestParameters k α π η H Q) + (a e t : ℕ) (he : e ≤ (forest T hT root).depth A.X) (ha : A.cached a e) + (has : a < A.start) (hst : A.start ≤ t) (hte : t < e) + (hgap : Q*(A.err+A.δ e) < A.δ t) : + ∃ p ∈ B (A.node t), ∃ q ∈ B (A.node t), dist A.x p = A.δ t ∧ + A.δ t/4 ≤ dist p q ∧ dist p q ≤ 10*A.δ a := by + have hQ : 0 < Q := by linarith [C.qlarge,upper_pos k] + have hδ : 0 < A.δ t := lt_of_le_of_lt (mul_nonneg hQ.le (add_nonneg (norm_nonneg (P.map A.x-P.map A.y)) (A.nonneg _ _))) hgap + have hDa : A.δ t ≤ A.δ a := A.monotone (has.le.trans hst) + have hapos : 0 < A.δ a := hδ.trans_le hDa + obtain ⟨p,hp,hpdist⟩ := A.near t + by_contra hno + have hno' : ∀ q ∈ B (A.node t), ¬(A.δ t/4 ≤ dist p q ∧ dist p q ≤ 10*A.δ a) := by + intro q hq hh + exact hno ⟨p,hp,q,hq,hpdist,hh⟩ + obtain ⟨v₀,hv₀,hgeo⟩ := A.geodesic a t (has.le.trans hst) (hte.le.trans he) + have hamp : ∀ loc, GoodBump (D (A.node a)) α η ((seed (A.node a)).bump loc) A.x → + ∀ v ∈ B (A.node t), A.δ t/2 ≤ |D (A.node a) A.x-D (A.node a) v| ∨ + ∃ j, C.c*A.δ a ≤ |(seed (A.node a)).bump loc j A.x-(seed (A.node a)).bump loc j v| := by + intro loc hg v hv + obtain ⟨j,hj,hn,hzero⟩ := hg + have hj' : C.c*A.δ a ≤ (seed (A.node a)).bump loc j A.x := by simpa only [C.c_eq,mul_assoc] using hj + have hr : 4*η*A.δ a < 9*A.δ a := by nlinarith [C.eta_small] + have hh := near_far_scaled (B (A.node t)) A.x p v₀ (D (A.node a)) + ((seed (A.node a)).bump loc j) (A.δ t) (A.δ a) (4*η*A.δ a) (C.c*A.δ a) + hδ hDa hpdist hv₀ (A.lower_near t) (A.lipschitz (A.node a)) rfl hgeo (A.nonneg _ _) + hno' hr (mul_pos C.c_pos hapos) hj' hzero v hv + exact hh.imp id (fun h => ⟨j,h⟩) + obtain ⟨l,hlen,hpath⟩ := A.suffix e (hst.trans hte.le) he + obtain ⟨z,hz,hzdist⟩ := A.near e + have ht := P.height_test A.X A.Y A.x A.y z A.hy A.start e l a t he hst hte (has.trans_le hst) ha hz hlen hpath + (C.b*A.δ t) (A.δ t/2) (C.c*A.δ a) (by positivity [C.b_pos]) + (A.bounded_tau C t) (by positivity) (mul_pos C.c_pos hapos) C.pi_pos.le hapos hamp + (A.budget C (A.δ t) (A.δ t/2) (C.c*A.δ a) hδ.le (by positivity) (mul_pos C.c_pos hapos) + (by nlinarith [C.c_half]) (mul_le_mul_of_nonneg_left hDa C.c_pos.le) t) + have hu := A.proxy_upper z + rw [hzdist] at ht hu + exact (not_le_of_gt hgap) (A.numerical_test C (A.δ t) (A.δ e) (A.nonneg _ _) (ht.trans hu)) + +end PathGeometry +end +end BoundedTreewidthL1.AnchorExperiment + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/Anchors.lean b/lean/OAI/Combinatorics/TreewidthL1/Anchors.lean new file mode 100644 index 0000000000000000000000000000000000000000..e1876a312ec133608a6234b92884d66d5f2ccb78 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/Anchors.lean @@ -0,0 +1,1142 @@ +import OAI.Combinatorics.TreewidthL1.ParticleLaws + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 treewidthLevel4 + +namespace BoundedTreewidthL1.AnchorTreeParticles +open MeasureTheory ParticleSchedule ParticleBatch +variable {I V ι J : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] [DecidableEq J] + +noncomputable def retained (R : RootedForest I) (A : I → Finset J) (i : I) : Finset J := + (R.parent i).elim ∅ (fun p => A i ∩ A p) +noncomputable def fresh (R : RootedForest I) (A : I → Finset J) (i : I) : Finset J := + A i \ retained R A i +noncomputable def seed : (ι → V → ℝ) × (J → ι × ι) := + (fun _ _ => 0, fun _ => (Classical.choice inferInstance, Classical.choice inferInstance)) +noncomputable def step (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (i : I) (S : (ι → V → ℝ) × (J → ι × ι)) := + launchBatch (bag i) (fresh R A i).toList (retained R A i) S.1 S.2 (g i) +noncomputable def state (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (i : I) : (ι → V → ℝ) × (J → ι × ι) := + R.run seed (step R bag A g) i + +lemma retained_subset (R : RootedForest I) (A : I → Finset J) (i : I) : + retained R A i ⊆ A i := by + unfold retained + cases R.parent i with + | none => exact Finset.empty_subset _ + | some p => exact Finset.inter_subset_left + +lemma batch_data (R : RootedForest I) (A : I → Finset J) (i : I) + {q : ℕ} (hA : (A i).card ≤ q) : + (fresh R A i).toList.Nodup ∧ + (∀ a ∈ (fresh R A i).toList, a ∉ retained R A i) ∧ + (retained R A i ∪ (fresh R A i).toList.toFinset).card ≤ q := by + classical + refine ⟨Finset.nodup_toList _, ?_, ?_⟩ + · intro a ha + exact (Finset.mem_sdiff.mp (Finset.mem_toList.mp ha)).2 + · simpa only [Finset.toList_toFinset, fresh, + Finset.union_sdiff_of_subset (retained_subset R A i)] using hA + +lemma state_eq + {I : Type treewidthLevel1} {V : Type treewidthLevel2} {ι : Type treewidthLevel3} + {J : Type treewidthLevel4} [Fintype V] [Fintype ι] [Nonempty ι] [DecidableEq ι] [DecidableEq J] + (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (i : I) : + state (ι := ι) R bag A g i = step R bag A g i + ((R.parent i).elim seed (state R bag A g)) := RootedForest.run_eq _ _ _ _ +/-- Actual branching preparation for anchor keys, launched at their own bag. Children use their own +copies of the parent's list; no consistency assumption on sampled bag laws. -/ +theorem forest_particle_realization (R : RootedForest I) (bag : I → Finset V) + (A : I → Finset J) (k q : ℕ) (hbag : ∀ i, (bag i).card ≤ k) + (hA : ∀ i, (A i).card ≤ q) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (d : V → V → ℝ) (L H Δ : ℝ) (hH : 0 < H) (hΔ : 0 < Δ) + (g : I → J → V → ℝ) + (hLip : ∀ i a, ∀ u v, |g i a u - g i a v| ≤ L*d u v) + (hHeight : ∀ i a v, |g i a v| ≤ H) + (hzero : ∀ i a, ∀ v ∈ bag i, g i a v = 0) : + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + let S := state (ι := ι) R bag A g + (∀ i, FunctionParticleReachable d L H (S i).1) ∧ + (∀ i p, R.parent i = some p → + particleTrace M (S i).1 (bag i) = particleTrace M (S p).1 (bag i)) ∧ + (∀ i p, R.parent i = some p → ∀ a ∈ A i ∩ A p, + (S i).2 a = (S p).2 a ∧ + (S i).1 ((S i).2 a).1 = (S p).1 ((S p).2 a).1 ∧ + (S i).1 ((S i).2 a).2 = (S p).1 ((S p).2 a).2) ∧ + (∀ i a, a ∈ fresh R A i → + ((S i).2 a).1 ≠ ((S i).2 a).2 ∧ + ∀ v, (S i).1 ((S i).2 a).1 v - (S i).1 ((S i).2 a).2 v = 2*g i a v) := by + classical + dsimp only + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + let S := state (ι := ι) R bag A g + have hstep (i : I) (F : ι → V → ℝ) (p : J → ι × ι) + (hF : FunctionParticleReachable d L H F) := + launchBatch_correct k q hN (bag i) (hbag i) + (fresh R A i).toList (retained R A i) + (batch_data R A i (hA i)).1 (batch_data R A i (hA i)).2.1 + (batch_data R A i (hA i)).2.2 d L H Δ hH hΔ F p hF (g i) + (fun a _ => hLip i a) (fun a _ => hHeight i a) (fun a _ => hzero i a) + have hreach : ∀ i, FunctionParticleReachable d L H (S i).1 := by + apply R.run_invariant seed (step R bag A g) (fun S => FunctionParticleReachable d L H S.1) + · exact FunctionParticleReachable.zero + · intro i F hF + exact (hstep i F.1 F.2 hF).1 + have hinput (i : I) : FunctionParticleReachable d L H + ((R.parent i).elim seed S).1 := by + cases hp : R.parent i with + | none => exact FunctionParticleReachable.zero + | some p => exact hreach p + have hstate (i : I) : + launchBatch (bag i) (fresh R A i).toList (retained R A i) + ((R.parent i).elim seed S).1 ((R.parent i).elim seed S).2 (g i) = S i := + (state_eq R bag A g i).symm + refine ⟨hreach, ?_, ?_, ?_⟩ + · intro i p hp + have hj := (hstep i ((R.parent i).elim seed S).1 + ((R.parent i).elim seed S).2 (hinput i)).2.1 + rw [hstate] at hj + simpa only [hp, Option.elim_some] using hj + · intro i p hp a ha + have hj := hstep i ((R.parent i).elim seed S).1 + ((R.parent i).elim seed S).2 (hinput i) + dsimp only at hj + rw [hstate] at hj + have hm : a ∈ retained R A i := by simpa only [retained, hp, Option.elim_some] using ha + have he := hj.2.2.1 a hm + have hleft := hj.2.2.2.1 _ (first_mem_used hm ((R.parent i).elim seed S).2) + have hright := hj.2.2.2.1 _ (second_mem_used hm ((R.parent i).elim seed S).2) + have he' : (S i).2 a = (S p).2 a := by + simpa only [hp, Option.elim_some] using he + refine ⟨he', ?_, ?_⟩ + · rw [he'] + simpa only [hp, Option.elim_some] using hleft + · rw [he'] + simpa only [hp, Option.elim_some] using hright + · intro i a ha + have hj := (hstep i ((R.parent i).elim seed S).1 + ((R.parent i).elim seed S).2 (hinput i)).2.2.2.2 a (Finset.mem_toList.mpr ha) + rw [hstate] at hj + exact hj +end BoundedTreewidthL1.AnchorTreeParticles + +namespace BoundedTreewidthL1.AnchorTreeParticles +open MeasureTheory ParticleSchedule ParticleBatch +variable {I V ι J Ω : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] [DecidableEq J] [Fintype J] [MeasurableSpace Ω] + [MeasurableSpace ι] [MeasurableSingletonClass ι] + +/-- Measurability of the actual branching preparation, with all randomness +sampled beforehand. No measurable-choice assumption about the particle lists. -/ +theorem measurable_state (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : Ω → I → J → V → ℝ) + (hg : ∀ i a v, Measurable (fun ω => g ω i a v)) (i : I) : + Measurable (fun ω => state (ι := ι) R bag A (g ω) i) := by + apply R.run_measurable (fun _ => seed) (fun j ω S => step R bag A (g ω) j S) + measurable_const + intro j f hf + exact measurable_launchBatch (bag j) (fresh R A j).toList (retained R A j) + (fun ω => (f ω).1) (fun ω => (f ω).2) (fun ω => g ω j) + (fun a v => (measurable_pi_apply v).comp ((measurable_pi_apply a).comp hf.fst)) + (fun a => (measurable_pi_apply a).comp hf.snd) (hg j) + +end BoundedTreewidthL1.AnchorTreeParticles + +namespace BoundedTreewidthL1.AnchorTreeParticles +variable {I J X : Type*} [DecidableEq J] +attribute [local instance] Classical.propDecidable + +/-- The discrete launch location depends only on the rooted decomposition and +active keys. In particular it does not consult any preparatory randomness. -/ +noncomputable def origin (R : RootedForest I) (A : I → Finset J) (root : I) : I → J → I := + R.run (fun _ => root) (fun i old a => if a ∈ retained R A i then old a else i) + +lemma origin_eq (R : RootedForest I) (A : I → Finset J) (root i : I) (a : J) : + origin R A root i a = if a ∈ retained R A i then + ((R.parent i).elim (fun _ => root) (origin R A root)) a else i := by + unfold origin + rw [RootedForest.run_eq] + +lemma origin_fresh (R : RootedForest I) (A : I → Finset J) (root i : I) + (a : J) (ha : a ∈ A i) : a ∈ fresh R A (origin R A root i a) := by + induction hn : R.depth i using Nat.strong_induction_on generalizing i with + | h n ih => + rw [origin_eq] + by_cases hk : a ∈ retained R A i + · rw [ite_eq_left hk] + cases hp : R.parent i with + | none => simp [retained,hp] at hk + | some p => + simp only [Option.elim_some] + have hap : a ∈ A p := (Finset.mem_inter.mp (by simpa [retained,hp] using hk)).2 + exact ih (R.depth p) (by rw [← hn]; exact R.decreases i p hp) p hap rfl + · rw [ite_eq_right hk] + exact Finset.mem_sdiff.mpr ⟨ha,hk⟩ + +lemma origin_transport (R : RootedForest I) (A : I → Finset J) (root : I) + (E : I → J → X) + (hkeep : ∀ i p, R.parent i = some p → ∀ a ∈ A i ∩ A p, E i a = E p a) + (i : I) (a : J) (ha : a ∈ A i) : E i a = E (origin R A root i a) a := by + induction hn : R.depth i using Nat.strong_induction_on generalizing i with + | h n ih => + rw [origin_eq] + by_cases hk : a ∈ retained R A i + · rw [ite_eq_left hk] + cases hp : R.parent i with + | none => simp [retained,hp] at hk + | some p => + simp only [Option.elim_some] + have hap : a ∈ A i ∩ A p := by simpa [retained,hp] using hk + exact (hkeep i p hp a hap).trans + (ih (R.depth p) (by rw [← hn]; exact R.decreases i p hp) p + (Finset.mem_inter.mp hap).2 rfl) + · rw [ite_eq_right hk] +end BoundedTreewidthL1.AnchorTreeParticles + +namespace BoundedTreewidthL1.AnchorTreeParticles +open scoped BigOperators +variable {I V ι J : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] [DecidableEq J] + +lemma two_particle_difference + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] + (F : ι → V → ℝ) (a b : ι) (hab : a ≠ b) + (g : V → ℝ) (hgap : ∀ v, F a v - F b v = 2*g v) (u v : V) : + 2*|g u-g v| ≤ ∑ t, |F t u-F t v| := by + have hs : (∑ t ∈ ({a,b} : Finset ι), |F t u-F t v|) ≤ ∑ t, |F t u-F t v| := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun t _ _ => abs_nonneg _) + simp only [Finset.sum_pair hab] at hs + have he : (F a u-F a v)-(F b u-F b v) = 2*(g u-g v) := by + linarith [hgap u,hgap v] + have ha := abs_sub (F a u-F a v) (F b u-F b v) + rw [he,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] at ha + exact ha.trans hs + +/-- The actual active pair at any descendant supplies the original launch +separation. The origin is deterministic, so no conditioning on the particle +scheduler or sampled coefficients is required. -/ +theorem origin_particle_gap (R : RootedForest I) (root : I) (bag : I → Finset V) + (A : I → Finset J) (k q : ℕ) (hbag : ∀ i, (bag i).card ≤ k) + (hA : ∀ i, (A i).card ≤ q) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (d : V → V → ℝ) (L H Δ : ℝ) (hH : 0 < H) (hΔ : 0 < Δ) + (g : I → J → V → ℝ) + (hLip : ∀ i a, ∀ u v, |g i a u - g i a v| ≤ L*d u v) + (hHeight : ∀ i a v, |g i a v| ≤ H) + (hzero : ∀ i a, ∀ v ∈ bag i, g i a v = 0) + (i : I) (a : J) (ha : a ∈ A i) (u v : V) : + 2*|g (origin R A root i a) a u - g (origin R A root i a) a v| ≤ + ∑ t, |(state (ι := ι) R bag A g i).1 t u - + (state (ι := ι) R bag A g i).1 t v| := by + let S := state (ι := ι) R bag A g + let o := origin R A root i a + obtain ⟨hreach,htrace,hkeep,hnew⟩ := forest_particle_realization R bag A k q + hbag hA hN d L H Δ hH hΔ g hLip hHeight hzero + have hp : (S i).2 a = (S o).2 a := + origin_transport R A root (fun i a => (S i).2 a) + (fun i p hip a ha => (hkeep i p hip a ha).1) i a ha + have hl : (S i).1 ((S i).2 a).1 = (S o).1 ((S o).2 a).1 := + origin_transport R A root (fun i a => (S i).1 ((S i).2 a).1) + (fun i p hip a ha => (hkeep i p hip a ha).2.1) i a ha + have hr : (S i).1 ((S i).2 a).2 = (S o).1 ((S o).2 a).2 := + origin_transport R A root (fun i a => (S i).1 ((S i).2 a).2) + (fun i p hip a ha => (hkeep i p hip a ha).2.2) i a ha + have hn := hnew o a (origin_fresh R A root i a ha) + apply two_particle_difference (S i).1 ((S i).2 a).1 ((S i).2 a).2 + (by rw [hp]; exact hn.1) (g o a) ?_ u v + intro x + rw [hl,hr] + exact hn.2 x +end BoundedTreewidthL1.AnchorTreeParticles +namespace BoundedTreewidthL1.AnchorTreeParticles +open MeasureTheory ParticleLaws +open scoped BigOperators ENNReal +variable {I V ι J Ω : Type*} [Fintype I] [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq V] [DecidableEq ι] [DecidableEq J] [Fintype J] [MeasurableSpace Ω] + +/-- Actual global averaged L1 realization of the branching preparation, with +an unconditional integral lower bound from each deterministic active origin. -/ +theorem averaged_origin_realization + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (hT : T.IsTree) (root : I) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (A : I → Finset J) (k q : ℕ) (hbag : ∀ i, (B i).card ≤ k) + (hA : ∀ i, (A i).card ≤ q) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (ν : Measure Ω) [IsProbabilityMeasure ν] + (L H Δ : ℝ) (hL : 0 < L) (hH : 0 < H) (hΔ : 0 < Δ) + (g : Ω → I → J → V → ℝ) (hmeas : ∀ i a v, Measurable (fun ω => g ω i a v)) + (hLip : ∀ ω i a, ∀ u v, |g ω i a u - g ω i a v| ≤ L*shortestPathDistance G ℓ u v) + (hHeight : ∀ ω i a v, |g ω i a v| ≤ H) + (hzero : ∀ ω i a, ∀ v ∈ B i, g ω i a v = 0) : + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ ≤ + (Fintype.card ι : ℝ)*L*((Fintype.card ι : ℝ)-1)*shortestPathDistance G ℓ u v) ∧ + ∀ i (a : J), a ∈ A i → ∀ (u v : B i), + 2*(∫ ω, |g ω (origin (RootedTree.forest T hT root) A root i a) a u - + g ω (origin (RootedTree.forest T hT root) A root i a) a v| ∂ν) ≤ + ‖Φ u.val - Φ v.val‖ := by + classical + let : MeasurableSpace ι := ⊤ + let : MeasurableSingletonClass ι := ⟨fun _ => trivial⟩ + let R := RootedTree.forest T hT root + let S := fun ω => state (ι := ι) R B A (g ω) + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + have hreach : ∀ ω i, FunctionParticleReachable (shortestPathDistance G ℓ) L H (S ω i).1 := by + intro ω + exact (forest_particle_realization R B A k q hbag hA hN + (shortestPathDistance G ℓ) L H Δ hH hΔ (g ω) (hLip ω) (hHeight ω) (hzero ω)).1 + have hsmeas : ∀ i t v, Measurable (fun ω => (S ω i).1 t v) := by + intro i t v + exact (measurable_pi_apply v).comp ((measurable_pi_apply t).comp + (measurable_state R B A g hmeas i).fst) + have hcons : ∀ ω i j, T.Adj i j → + particleTrace M (S ω i).1 (B i ∩ B j) = particleTrace M (S ω j).1 (B i ∩ B j) := by + intro ω i j hij + have ht := (forest_particle_realization R B A k q hbag hA hN + (shortestPathDistance G ℓ) L H Δ hH hΔ (g ω) (hLip ω) (hHeight ω) (hzero ω)).2.1 + rcases RootedTree.edge_orientation T hT root hij with hp | hp + · exact trace_eq_of_subset M _ _ (B i) _ Finset.inter_subset_left (ht i j hp) + · exact (trace_eq_of_subset M _ _ (B j) _ Finset.inter_subset_right (ht j i hp)).symm + obtain ⟨n,Φ,hup,heq⟩ := averaged_particle_realization G hG ℓ hℓ T hT B hcover hedge hrun + ν L H Δ hL hH hΔ (by omega : 1 ≤ Fintype.card ι) (fun ω i => (S ω i).1) + hsmeas (by + have hd : (Classical.decEq ι) = (inferInstance : DecidableEq ι) := Subsingleton.elim _ _ + rw [hd] + exact hreach) hcons + refine ⟨n,Φ,hup,?_⟩ + intro i a ha u v + rw [heq i u v,← integral_const_mul] + apply integral_mono + · apply Integrable.const_mul + apply Integrable.of_bound ((hmeas _ a u).sub (hmeas _ a v)).abs.aestronglyMeasurable (2*H) + apply Filter.Eventually.of_forall + intro ω + rw [Real.norm_eq_abs,abs_abs] + have hu := hHeight ω (origin R A root i a) a u + have hv := hHeight ω (origin R A root i a) a v + exact (abs_sub _ _).trans (by linarith) + · apply integrable_finsetSum + intro t ht + apply Integrable.of_bound ((hsmeas i t u).sub (hsmeas i t v)).abs.aestronglyMeasurable + (2*H*((Fintype.card ι : ℝ)-1)) + apply Filter.Eventually.of_forall + intro ω + rw [Real.norm_eq_abs,abs_abs] + have hu := function_particles_height_bound hH (hreach ω i) t u + have hv := function_particles_height_bound hH (hreach ω i) t v + exact (abs_sub _ _).trans (by linarith) + · intro ω + exact origin_particle_gap R root B A k q hbag hA hN (shortestPathDistance G ℓ) + L H Δ hH hΔ (g ω) (hLip ω) (hHeight ω) (hzero ω) i a ha u v +end BoundedTreewidthL1.AnchorTreeParticles + +namespace BoundedTreewidthL1 + +lemma tree_path_mem_connected {I : Type*} (T : SimpleGraph I) (hT : T.IsTree) + {S : Set I} (hS : (T.induce S).Connected) {A B P : I} + (hA : A ∈ S) (hB : B ∈ S) (q : T.Walk A B) (hq : q.IsPath) + (hP : P ∈ q.support) : P ∈ S := by + obtain ⟨p, hp⟩ := hS.exists_isPath ⟨A, hA⟩ ⟨B, hB⟩ + let f := (SimpleGraph.Embedding.induce (G := T) S).toHom + have hp' : (p.map f).IsPath := hp.map Subtype.val_injective + have heq : p.map f = q := congrArg Subtype.val + ((hT.isAcyclic.subsingleton_path A B).elim ⟨p.map f, hp'⟩ ⟨q, hq⟩) + have hmem : P ∈ (p.map f).support := heq.symm ▸ hP + rw [SimpleGraph.Walk.support_map] at hmem + obtain ⟨z, _, hz⟩ := List.mem_map.mp hmem + exact hz ▸ z.property + +/-- The bags touched by the vertices of a graph walk form a connected subtree. +No bounded-width assumption is needed for this purely combinatorial fact. -/ +lemma touched_bags_connected {V I : Type*} [DecidableEq V] + (G : SimpleGraph V) (T : SimpleGraph I) (bag : I → Finset V) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) + (hocc : ∀ v, (T.induce {t | v ∈ bag t}).Connected) + {u v : V} (p : G.Walk u v) : + (T.induce {t | ∃ z ∈ p.support, z ∈ bag t}).Connected := by + induction p with + | @nil u => + have hset : {t | ∃ z ∈ ([u] : List V), z ∈ bag t} = {t | u ∈ bag t} := by + ext t + simp + change (T.induce {t | ∃ z ∈ ([u] : List V), z ∈ bag t}).Connected + rw [hset] + exact hocc u + | @cons u v w huv p ih => + have hset : {t | ∃ z ∈ (p.cons huv).support, z ∈ bag t} = + {t | u ∈ bag t} ∪ {t | ∃ z ∈ p.support, z ∈ bag t} := by + ext t + simp only [SimpleGraph.Walk.support_cons, List.mem_cons, Set.mem_ofPred_eq, + Set.mem_union] + constructor + · rintro ⟨z, rfl | hz, hb⟩ + · exact Or.inl hb + · exact Or.inr ⟨z, hz, hb⟩ + · rintro (h | ⟨z, hz, hb⟩) + · exact ⟨u, Or.inl rfl, h⟩ + · exact ⟨z, Or.inr hz, hb⟩ + rw [hset] + apply SimpleGraph.induce_union_connected (hocc u).preconnected ih.preconnected + obtain ⟨t, hut, hvt⟩ := hedge u v huv + exact ⟨t, hut, v, p.start_mem_support, hvt⟩ + +theorem bag_separator {V I : Type*} [DecidableEq V] + (G : SimpleGraph V) (T : SimpleGraph I) (bag : I → Finset V) + (hT : T.IsTree) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) + (hocc : ∀ v, (T.induce {t | v ∈ bag t}).Connected) + {A B P : I} (q : T.Walk A B) (hq : q.IsPath) (hP : P ∈ q.support) + {u v : V} (hu : u ∈ bag A) (hv : v ∈ bag B) (p : G.Walk u v) : + ∃ z, z ∈ p.support ∧ z ∈ bag P := by + exact tree_path_mem_connected T hT (touched_bags_connected G T bag hedge hocc p) + ⟨u, p.start_mem_support, hu⟩ ⟨v, p.end_mem_support, hv⟩ q hq hP + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 + +/-- Exact finite minimum distance to a nonempty bag in the original weighted metric. -/ +noncomputable def bagDistance {V : Type*} (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + (A : Finset V) (hA : A.Nonempty) (x : V) : ℝ := + A.inf' hA (shortestPathDistance G ℓ x) + +lemma bagDistance_attained {V : Type*} (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + (A : Finset V) (hA : A.Nonempty) (x : V) : + ∃ a ∈ A, bagDistance G ℓ A hA x = shortestPathDistance G ℓ x a := + Finset.exists_mem_eq_inf' hA _ + +lemma bagDistance_le {V : Type*} (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + (A : Finset V) (hA : A.Nonempty) (x : V) {a : V} (ha : a ∈ A) : + bagDistance G ℓ A hA x ≤ shortestPathDistance G ℓ x a := + Finset.inf'_le _ ha + +lemma bagDistance_nonneg {V : Type*} (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) (A : Finset V) (hA : A.Nonempty) (x : V) : + 0 ≤ bagDistance G ℓ A hA x := + Finset.le_inf' hA _ (fun a _ => shortestPathDistance_nonneg G ℓ hG hℓ x a) + +lemma bagDistance_triangle {V : Type*} [Fintype V] + (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) + (A : Finset V) (hA : A.Nonempty) (x y : V) : + bagDistance G ℓ A hA x ≤ shortestPathDistance G ℓ x y + bagDistance G ℓ A hA y := by + obtain ⟨a,ha,heq⟩ := bagDistance_attained G ℓ A hA y + rw [heq] + exact (bagDistance_le G ℓ A hA x ha).trans (shortestPathDistance_triangle G ℓ hG hℓ x y a) + +lemma bagDistance_lipschitz {V : Type*} [Fintype V] + (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) + (A : Finset V) (hA : A.Nonempty) (x y : V) : + |bagDistance G ℓ A hA x - bagDistance G ℓ A hA y| ≤ shortestPathDistance G ℓ x y := by + have hxy := bagDistance_triangle G ℓ hG hℓ A hA x y + have hyx := bagDistance_triangle G ℓ hG hℓ A hA y x + rw [shortestPathDistance_comm G ℓ hG hℓ y x] at hyx + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +lemma geodesic_split {V : Type*} [Fintype V] [DecidableEq V] + (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) + {a b z : V} (p : G.Walk a b) (hmin : walkLength G ℓ p = shortestPathDistance G ℓ a b) + (hz : z ∈ p.support) : + shortestPathDistance G ℓ a z + shortestPathDistance G ℓ z b = shortestPathDistance G ℓ a b := by + have heq : walkLength G ℓ (p.takeUntil z hz) + walkLength G ℓ (p.dropUntil z hz) = + shortestPathDistance G ℓ a b := by + rw [← walkLength_append,SimpleGraph.Walk.take_spec,hmin] + have h1 := shortestPathDistance_le_walkLength G ℓ hℓ (p.takeUntil z hz) + have h2 := shortestPathDistance_le_walkLength G ℓ hℓ (p.dropUntil z hz) + have h3 := shortestPathDistance_triangle G ℓ hG hℓ a z b + linarith + +theorem separator_bag_geometry {V I : Type*} [Fintype V] [DecidableEq V] + (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) (hG : G.Connected) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (bag : I → Finset V) (hne : ∀ i, (bag i).Nonempty) + (hT : T.IsTree) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) + (hocc : ∀ v, (T.induce {t | v ∈ bag t}).Connected) + {A B P : I} (q : T.Walk A B) (hq : q.IsPath) (hP : P ∈ q.support) + {x : V} (hx : x ∈ bag B) : + bagDistance G ℓ (bag P) (hne P) x ≤ bagDistance G ℓ (bag A) (hne A) x ∧ + ∃ z ∈ bag P, bagDistance G ℓ (bag A) (hne A) z + shortestPathDistance G ℓ z x = + bagDistance G ℓ (bag A) (hne A) x + := by + have hnn : ∀ e, 0 ≤ ℓ e := fun e => (hℓ e).le + obtain ⟨a,ha,haeq⟩ := bagDistance_attained G ℓ (bag A) (hne A) x + obtain ⟨p,hp,hmin⟩ := shortestPathDistance_attained G ℓ hG a x + obtain ⟨z,hzp,hzP⟩ := bag_separator G T bag hT hedge hocc q hq hP ha hx p + have hsplit := geodesic_split G ℓ hG hnn p hmin hzp + have hsym := shortestPathDistance_comm G ℓ hG hnn a x + have hnear := bagDistance_le G ℓ (bag A) (hne A) z ha + rw [shortestPathDistance_comm G ℓ hG hnn z a] at hnear + have htri := bagDistance_triangle G ℓ hG hnn (bag A) (hne A) x z + rw [shortestPathDistance_comm G ℓ hG hnn x z] at htri + have hgeod : bagDistance G ℓ (bag A) (hne A) z + shortestPathDistance G ℓ z x = + bagDistance G ℓ (bag A) (hne A) x := by linarith + refine ⟨?_,z,hzP,hgeod⟩ + have hznonneg := bagDistance_nonneg G ℓ hG hnn (bag A) (hne A) z + have hm := bagDistance_le G ℓ (bag P) (hne P) x hzP + rw [shortestPathDistance_comm G ℓ hG hnn x z] at hm + linarith +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.AnchorCache +variable {V : Type*} [DecidableEq V] + +/-- Immediately follows a strict-to-weak threshold drop in the age-ordered list. -/ +def Drop (C : Finset ℕ) (v : ℕ → ℝ) (τ : ℝ) (a : ℕ) : Prop := + a ∈ C ∧ v a ≤ τ ∧ ∃ b ∈ C, b < a ∧ τ < v b ∧ + ∀ c ∈ C, b < c → a ≤ c + +noncomputable def protectedEntries (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) : Finset ℕ := by + classical + exact (P.product P).biUnion fun pq => if pq.1 = pq.2 then ∅ else + (Finset.univ : Finset Bool).biUnion fun b => C.filter + (Drop C (v pq.1) (if b then J*d pq.1 pq.2 else d pq.1 pq.2/100)) + +def cacheBound (k : ℕ) : ℕ := 2*k^2+2 + +noncomputable def eligible (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) : Finset ℕ := by + classical + exact C.filter (fun a => a ≠ 0 ∧ a ∉ protectedEntries P C d v J) + +/-- Retain the inclusive list if space remains; otherwise evict its oldest +unprotected nonroot entry. The fallback is unreachable on admissible input. -/ +noncomputable def trim (k : ℕ) (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) : Finset ℕ := by + classical + exact if cacheBound k < C.card then + if h : (eligible P C d v J).Nonempty then C.erase ((eligible P C d v J).min' h) + else C + else C + +lemma drop_unique {C : Finset ℕ} {v : ℕ → ℝ} {τ : ℝ} + (hmono : ∀ a ∈ C, ∀ b ∈ C, a ≤ b → v b ≤ v a) + {a b : ℕ} (ha : Drop C v τ a) (hb : Drop C v τ b) : a = b := by + have le_of_drop {a b : ℕ} (ha : Drop C v τ a) (hb : Drop C v τ b) : a ≤ b := by + obtain ⟨haC,haτ,c,hcC,hca,hcτ,hnext⟩ := ha + by_cases hcb : c < b + · exact hnext b hb.1 hcb + · have hbc : b ≤ c := Nat.le_of_not_gt hcb + have hval := hmono b hb.1 c hcC hbc + linarith [hb.2.1] + exact Nat.le_antisymm (le_of_drop ha hb) (le_of_drop hb ha) + +lemma drop_card_le {C : Finset ℕ} {v : ℕ → ℝ} {τ : ℝ} + [DecidablePred (Drop C v τ)] + (hmono : ∀ a ∈ C, ∀ b ∈ C, a ≤ b → v b ≤ v a) : + (C.filter (Drop C v τ)).card ≤ 1 := by + classical + apply Finset.card_le_one.mpr + intro a ha b hb + exact drop_unique hmono (Finset.mem_filter.mp ha).2 (Finset.mem_filter.mp hb).2 + +lemma protected_subset (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) : + protectedEntries P C d v J ⊆ C := by + classical + intro a ha + simp only [protectedEntries, Finset.mem_biUnion] at ha + obtain ⟨⟨p,q⟩,hpq,h⟩ := ha + split_ifs at h with hpq' + · simp at h + · simp only [Finset.mem_biUnion] at h + obtain ⟨b,hb,hd⟩ := h + exact (Finset.mem_filter.mp hd).1 + +lemma protected_card (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) + (hmono : ∀ p ∈ P, ∀ a ∈ C, ∀ b ∈ C, a ≤ b → v p b ≤ v p a) : + (protectedEntries P C d v J).card ≤ 2*P.card^2 := by + classical + unfold protectedEntries + calc + _ ≤ ∑ pq ∈ P.product P, (if pq.1 = pq.2 then (∅ : Finset ℕ) else + (Finset.univ : Finset Bool).biUnion fun b => C.filter + (Drop C (v pq.1) (if b then J*d pq.1 pq.2 else d pq.1 pq.2/100))).card := + Finset.card_biUnion_le + _ ≤ ∑ _pq ∈ P.product P, 2 := by + apply Finset.sum_le_sum + intro pq hpq + split_ifs with heq + · simp + · calc + _ ≤ ∑ b : Bool, (C.filter (Drop C (v pq.1) + (if b then J*d pq.1 pq.2 else d pq.1 pq.2/100))).card := + Finset.card_biUnion_le + _ ≤ ∑ _b : Bool, 1 := Finset.sum_le_sum fun b _ => + drop_card_le (hmono pq.1 (Finset.mem_product.mp hpq).1) + _ = 2 := by decide + _ = _ := by simp [pow_two, Nat.mul_comm] + +lemma eligible_nonempty (k : ℕ) (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) + (hP : P.card ≤ k) (hfull : cacheBound k < C.card) + (hmono : ∀ p ∈ P, ∀ a ∈ C, ∀ b ∈ C, a ≤ b → v p b ≤ v p a) : + (eligible P C d v J).Nonempty := by + classical + by_contra h + have hempty : eligible P C d v J = ∅ := Finset.not_nonempty_iff_eq_empty.mp h + have hsub : C ⊆ insert 0 (protectedEntries P C d v J) := by + intro a ha + by_cases ha0 : a = 0 + · simp [ha0] + · have hmem : a ∈ protectedEntries P C d v J := by + by_contra hn + have : a ∈ eligible P C d v J := by simp [eligible,ha,ha0,hn] + simp [hempty] at this + exact Finset.mem_insert_of_mem hmem + have hcard := (Finset.card_le_card hsub).trans (Finset.card_insert_le _ _) + have hp := protected_card P C d v J hmono + have hsq : P.card^2 ≤ k^2 := Nat.pow_le_pow_left hP 2 + unfold cacheBound at hfull + omega + +theorem deterministic_cache_step (k : ℕ) (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) + (hP : P.card ≤ k) (hC : C.card ≤ cacheBound k + 1) (hroot : 0 ∈ C) + (hmono : ∀ p ∈ P, ∀ a ∈ C, ∀ b ∈ C, a ≤ b → v p b ≤ v p a) : + (trim k P C d v J).card ≤ cacheBound k ∧ + 0 ∈ trim k P C d v J ∧ trim k P C d v J ⊆ C ∧ + (∀ a ∈ protectedEntries P C d v J, a ∈ trim k P C d v J) ∧ + (cacheBound k < C.card → ∃ e ∈ eligible P C d v J, + (∀ a ∈ eligible P C d v J, e ≤ a) ∧ trim k P C d v J = C.erase e) + := by + classical + by_cases hfull : cacheBound k < C.card + · have he := eligible_nonempty k P C d v J hP hfull hmono + let e := (eligible P C d v J).min' he + have hem : e ∈ eligible P C d v J := Finset.min'_mem _ _ + have heC : e ∈ C := (Finset.mem_filter.mp hem).1 + have he0 : e ≠ 0 := (Finset.mem_filter.mp hem).2.1 + have heprot : e ∉ protectedEntries P C d v J := (Finset.mem_filter.mp hem).2.2 + have htrim : trim k P C d v J = C.erase e := by simp only [trim,hfull,↓reduceIte,he]; rfl + rw [htrim] + refine ⟨?_, ?_, Finset.erase_subset _ _, ?_, ?_⟩ + · rw [Finset.card_erase_of_mem heC] + omega + · simp [hroot, he0.symm] + · intro a ha + exact Finset.mem_erase.mpr ⟨by intro h; subst a; exact heprot ha, + protected_subset P C d v J ha⟩ + · intro _ + exact ⟨e,hem,(fun a ha => Finset.min'_le _ _ ha),rfl⟩ + · have htrim : trim k P C d v J = C := by simp only [trim,hfull,↓reduceIte] + rw [htrim] + exact ⟨Nat.le_of_not_gt hfull, hroot, Finset.Subset.refl _, + (fun _ h => protected_subset P C d v J h), (fun h => (hfull h).elim)⟩ +end BoundedTreewidthL1.AnchorCache +namespace BoundedTreewidthL1.AnchorCache +variable {V : Type*} [DecidableEq V] + +noncomputable def memory (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) : ℕ → Finset ℕ + | 0 => {0} + | t+1 => trim k (P (t+1)) (insert (t+1) (memory k P d v J t)) d (v (t+1)) J + +/-- Incoming cache plus current proposal, before the release at this bag. -/ +noncomputable def inclusiveCache (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) : ℕ → Finset ℕ + | 0 => {0} + | t+1 => insert (t+1) (memory k P d v J t) + +def ValidInput (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last : ℕ) : Prop := + ∀ t ≤ last, (P t).card ≤ k ∧ ∀ p ∈ P t, + ∀ a ∈ inclusiveCache k P d v J t, ∀ b ∈ inclusiveCache k P d v J t, + a ≤ b → v t p b ≤ v t p a + +lemma trim_subset (k : ℕ) (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) : trim k P C d v J ⊆ C := by + classical + unfold trim + split_ifs <;> first | exact Finset.Subset.refl _ | exact Finset.erase_subset _ _ + +lemma trim_removed_unique (k : ℕ) (P : Finset V) (C : Finset ℕ) + (d : V → V → ℝ) (v : V → ℕ → ℝ) (J : ℝ) + {a b : ℕ} (ha : a ∈ C) (hb : b ∈ C) + (ha' : a ∉ trim k P C d v J) (hb' : b ∉ trim k P C d v J) : a = b := by + classical + unfold trim at ha' hb' + split_ifs at ha' hb' with hc he + · have hae : a = (eligible P C d v J).min' he := by + by_contra h; exact ha' (Finset.mem_erase.mpr ⟨h,ha⟩) + have hbe : b = (eligible P C d v J).min' he := by + by_contra h; exact hb' (Finset.mem_erase.mpr ⟨h,hb⟩) + exact hae.trans hbe.symm + all_goals exact (ha' ha).elim + +lemma memory_subset (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (t : ℕ) : + memory k P d v J t ⊆ inclusiveCache k P d v J t := by + cases t with + | zero => exact Finset.Subset.refl _ + | succ t => exact trim_subset .. + +lemma inclusive_self (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (t : ℕ) : t ∈ inclusiveCache k P d v J t := by + cases t <;> simp [inclusiveCache] + +lemma inclusive_age (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (t : ℕ) : + ∀ a ∈ inclusiveCache k P d v J t, a ≤ t := by + induction t with + | zero => intro a ha; simpa [inclusiveCache] using ha + | succ t ih => + intro a ha + simp only [inclusiveCache,Finset.mem_insert] at ha + rcases ha with rfl | ha + · exact le_rfl + · exact (ih a (memory_subset k P d v J t ha)).trans (Nat.le_succ t) + +lemma inclusive_backwards (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) {a t u : ℕ} + (hatu : a ≤ t) (htu : t ≤ u) (ha : a ∈ inclusiveCache k P d v J u) : + a ∈ inclusiveCache k P d v J t := by + induction u with + | zero => + have ht : t = 0 := by omega + simpa [ht] using ha + | succ u ih => + by_cases h : t = u+1 + · simpa [h] using ha + · have htu' : t ≤ u := by omega + simp only [inclusiveCache,Finset.mem_insert] at ha + rcases ha with he | hm + · omega + · exact ih htu' (memory_subset k P d v J u hm) + +lemma memory_invariant (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last : ℕ) + (hvalid : ValidInput k P d v J last) (t : ℕ) (ht : t ≤ last) : + (memory k P d v J t).card ≤ cacheBound k ∧ 0 ∈ memory k P d v J t := by + induction t with + | zero => simp [memory,cacheBound] + | succ t ih => + have hprev := ih (by omega) + have hinput := hvalid (t+1) ht + have hcard : (insert (t+1) (memory k P d v J t)).card ≤ cacheBound k + 1 := + (Finset.card_insert_le _ _).trans (Nat.add_le_add_right hprev.1 1) + have hroot : 0 ∈ insert (t+1) (memory k P d v J t) := Finset.mem_insert_of_mem hprev.2 + have hstep := deterministic_cache_step k (P (t+1)) + (insert (t+1) (memory k P d v J t)) d (v (t+1)) J hinput.1 hcard hroot hinput.2 + exact ⟨hstep.1,hstep.2.1⟩ + +lemma inclusive_invariant (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last : ℕ) + (hvalid : ValidInput k P d v J last) (t : ℕ) (ht : t ≤ last) : + (inclusiveCache k P d v J t).card ≤ cacheBound k + 1 ∧ + 0 ∈ inclusiveCache k P d v J t := by + cases t with + | zero => simp [inclusiveCache,cacheBound] + | succ t => + have hmem := memory_invariant k P d v J last hvalid t (by omega) + exact ⟨(Finset.card_insert_le _ _).trans (Nat.add_le_add_right hmem.1 1), + Finset.mem_insert_of_mem hmem.2⟩ + +lemma memory_protected (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last : ℕ) + (hvalid : ValidInput k P d v J last) (t : ℕ) (ht : t ≤ last) : + protectedEntries (P t) (inclusiveCache k P d v J t) d (v t) J ⊆ memory k P d v J t := by + cases t with + | zero => exact protected_subset .. + | succ t => + have hh := inclusive_invariant k P d v J last hvalid (t+1) ht + have hin := hvalid (t+1) ht + exact (deterministic_cache_step k (P (t+1)) (inclusiveCache k P d v J (t+1)) + d (v (t+1)) J hin.1 hh.1 hh.2 hin.2).2.2.2.1 + +noncomputable def activeTimes (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last a : ℕ) : Finset ℕ := by + classical + exact (Finset.range (last+1)).filter (fun t => a ∈ inclusiveCache k P d v J t) + +noncomputable def lastActive (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last a : ℕ) : ℕ := by + classical + exact if h : (activeTimes k P d v J last a).Nonempty then + (activeTimes k P d v J last a).max' h else a + +lemma active_self (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last a : ℕ) (ha : a ≤ last) : + a ∈ activeTimes k P d v J last a := by + classical + simp [activeTimes,ha,inclusive_self] + +lemma lastActive_mem (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last a : ℕ) (ha : a ≤ last) : + lastActive k P d v J last a ∈ activeTimes k P d v J last a := by + classical + have hn : (activeTimes k P d v J last a).Nonempty := ⟨a,active_self k P d v J last a ha⟩ + simp only [lastActive,hn,↓reduceDIte] + exact Finset.max'_mem _ _ + +lemma le_lastActive (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last a t : ℕ) + (ht : t ∈ activeTimes k P d v J last a) : t ≤ lastActive k P d v J last a := by + classical + have hn : (activeTimes k P d v J last a).Nonempty := ⟨t,ht⟩ + simp only [lastActive,hn,↓reduceDIte] + exact Finset.le_max' _ _ ht + +lemma inclusive_iff_interval (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last a t : ℕ) (ha : a ≤ last) (ht : t ≤ last) : + a ∈ inclusiveCache k P d v J t ↔ a ≤ t ∧ t ≤ lastActive k P d v J last a := by + classical + constructor + · intro hh + refine ⟨inclusive_age k P d v J t a hh, le_lastActive k P d v J last a t ?_⟩ + simp [activeTimes,ht,hh] + · rintro ⟨hat,htf⟩ + have hfm := lastActive_mem k P d v J last a ha + simp only [activeTimes,Finset.mem_filter] at hfm + exact inclusive_backwards k P d v J hat htf hfm.2 +/-- Realizes the deterministic cache as the inclusive reservation path +needed by the youngest-crossing argument. -/ +theorem cache_program_realizes (k : ℕ) (P : ℕ → Finset V) (d : V → V → ℝ) + (v : ℕ → V → ℕ → ℝ) (J : ℝ) (last : ℕ) + (hvalid : ValidInput k P d v J last) : + ∃ R : BoundedTreewidthL1.ReservationPath, R.last = last ∧ + (∀ t ≤ last, R.inclusive t = inclusiveCache k P d v J t) ∧ + (∀ t, (R.inclusive t).card ≤ cacheBound k + 1) ∧ + (∀ t < last, ∀ a ∈ protectedEntries (P t) (inclusiveCache k P d v J t) d (v t) J, + t < R.finish a) + := by + classical + let f := lastActive k P d v J last + have hfl (a : ℕ) (ha : a ≤ last) : a ≤ f a := + le_lastActive k P d v J last a a (active_self k P d v J last a ha) + have hfu (a : ℕ) (ha : a ≤ last) : f a ≤ last := by + have h := (Finset.mem_filter.mp (lastActive_mem k P d v J last a ha)).1 + exact Nat.le_of_lt_succ (Finset.mem_range.mp h) + have hroot : f 0 = last := by + apply Nat.le_antisymm (hfu 0 (Nat.zero_le _)) + apply le_lastActive + simp only [activeTimes,Finset.mem_filter,Finset.mem_range,Nat.lt_succ_self,true_and] + exact (inclusive_invariant k P d v J last hvalid last le_rfl).2 + have hretained {a t : ℕ} (ht : t < last) (ha : a ∈ memory k P d v J t) : t < f a := by + have hin : a ∈ inclusiveCache k P d v J (t+1) := Finset.mem_insert_of_mem ha + have haage := inclusive_age k P d v J (t+1) a hin + have happ := (inclusive_iff_interval k P d v J last a (t+1) (by omega) (by omega)).mp hin + change a ≤ t+1 ∧ t+1 ≤ f a at happ + exact (Nat.lt_succ_self t).trans_le happ.2 + have hrelease (a b t : ℕ) (hat : a ≤ t) (hbt : b ≤ t) (ht : t < last) + (haf : f a = t) (hbf : f b = t) : a = b := by + have ham := (inclusive_iff_interval k P d v J last a t (by omega) (by omega)).mpr ⟨hat,haf.ge⟩ + have hbm := (inclusive_iff_interval k P d v J last b t (by omega) (by omega)).mpr ⟨hbt,hbf.ge⟩ + have han : a ∉ memory k P d v J t := by intro h; have := hretained ht h; omega + have hbn : b ∉ memory k P d v J t := by intro h; have := hretained ht h; omega + cases t with + | zero => exact (han ham).elim + | succ t => + exact trim_removed_unique k (P (t+1)) (inclusiveCache k P d v J (t+1)) + d (v (t+1)) J ham hbm han hbn + let R : BoundedTreewidthL1.ReservationPath := ⟨last,f,hfl,hfu,hrelease,hroot⟩ + have heq (t : ℕ) (ht : t ≤ last) : R.inclusive t = inclusiveCache k P d v J t := by + ext a + simp only [ReservationPath.inclusive,show R.last = last from rfl,ht,↓reduceIte, + Finset.mem_filter,Finset.mem_range,Nat.lt_succ_iff] + change (a ≤ t ∧ t ≤ f a) ↔ _ + by_cases ha : a ≤ last + · exact (inclusive_iff_interval k P d v J last a t ha ht).symm + · have hn : ¬a ≤ t := by omega + have hm : a ∉ inclusiveCache k P d v J t := by + intro h; exact hn (inclusive_age k P d v J t a h) + simp [hn,hm] + refine ⟨R,rfl,heq,?_,?_⟩ + · intro t + by_cases ht : t ≤ last + · rw [heq t ht] + exact (inclusive_invariant k P d v J last hvalid t ht).1 + · simp [ReservationPath.inclusive,show R.last = last from rfl,ht] + · intro t ht a ha + exact hretained ht (memory_protected k P d v J last hvalid t ht.le ha) +end BoundedTreewidthL1.AnchorCache + +namespace BoundedTreewidthL1.AnchorCache + +theorem graph_cache_realizes {V I : Type*} [Fintype V] [DecidableEq V] + (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) (hG : G.Connected) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (bag : I → Finset V) (hne : ∀ i, (bag i).Nonempty) + (hT : T.IsTree) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) + (hocc : ∀ v, (T.induce {t | v ∈ bag t}).Connected) + (k : ℕ) (hcard : ∀ i, (bag i).card ≤ k) (J : ℝ) + {root endBag : I} (q : T.Walk root endBag) (hq : q.IsPath) : + let P := fun t => bag (q.getVert t) + let d := shortestPathDistance G ℓ + let v := fun (_ : ℕ) (p : V) a => bagDistance G ℓ (bag (q.getVert a)) (hne _) p + ∃ R : ReservationPath, R.last = q.length ∧ + (∀ t ≤ q.length, R.inclusive t = inclusiveCache k P d v J t) ∧ + (∀ t, (R.inclusive t).card ≤ cacheBound k + 1) ∧ + (∀ t < q.length, ∀ a ∈ protectedEntries (P t) (inclusiveCache k P d v J t) d (v t) J, + t < R.finish a) := by + classical + dsimp only + apply cache_program_realizes + intro t ht + refine ⟨hcard _,?_⟩ + intro p hp a ha b hb hab + have hbt := inclusive_age k (fun t => bag (q.getVert t)) (shortestPathDistance G ℓ) + (fun (_ : ℕ) (p : V) a => bagDistance G ℓ (bag (q.getVert a)) (hne _) p) J t b hb + have hat : a ≤ t := hab.trans hbt + have hsup : q.getVert b ∈ ((q.take t).drop a).support := by + have hh := ((q.take t).drop a).getVert_mem_support (b-a) + simpa only [SimpleGraph.Walk.drop_getVert,SimpleGraph.Walk.take_getVert, + Nat.add_sub_of_le hab,inf_eq_right.mpr hbt] using hh + have hgeo := separator_bag_geometry G ℓ hG hℓ T bag hne hT hedge hocc + ((q.take t).drop a) ((hq.take t).drop a) hsup hp + simpa only [SimpleGraph.Walk.take_getVert,inf_eq_right.mpr hat] using hgeo.1 +end BoundedTreewidthL1.AnchorCache +namespace BoundedTreewidthL1.AnchorCache +variable {V : Type*} [DecidableEq V] + +lemma drop_congr_on (C : Finset ℕ) (v w : ℕ → ℝ) (τ : ℝ) + (hvw : ∀ a ∈ C, v a = w a) (a : ℕ) : Drop C v τ a ↔ Drop C w τ a := by + constructor + · rintro ⟨ha,hva,b,hb,hba,hτ,hnext⟩ + exact ⟨ha,by rw [← hvw a ha]; exact hva,b,hb,hba, + by rw [← hvw b hb]; exact hτ,hnext⟩ + · rintro ⟨ha,hva,b,hb,hba,hτ,hnext⟩ + exact ⟨ha,by rw [hvw a ha]; exact hva,b,hb,hba, + by rw [hvw b hb]; exact hτ,hnext⟩ + +lemma protected_congr_on (P : Finset V) (C : Finset ℕ) (d : V → V → ℝ) + (v w : V → ℕ → ℝ) (J : ℝ) (hvw : ∀ x ∈ P, ∀ a ∈ C, v x a = w x a) : + protectedEntries P C d v J = protectedEntries P C d w J := by + classical + unfold protectedEntries + apply Finset.biUnion_congr rfl + intro xy hxy + split_ifs with he + · rfl + · apply Finset.biUnion_congr rfl + intro b hb + apply Finset.filter_congr + intro a ha + exact drop_congr_on C (v xy.1) (w xy.1) _ + (hvw xy.1 (Finset.mem_product.mp hxy).1) a + +lemma trim_congr_on (k : ℕ) (P : Finset V) (C : Finset ℕ) (d : V → V → ℝ) + (v w : V → ℕ → ℝ) (J : ℝ) (hvw : ∀ x ∈ P, ∀ a ∈ C, v x a = w x a) : + trim k P C d v J = trim k P C d w J := by + classical + have he : eligible P C d v J = eligible P C d w J := by + simp only [eligible, protected_congr_on P C d v w J hvw] + simp only [trim, he] + +lemma memory_prefix (k : ℕ) (P Q : ℕ → Finset V) (d : V → V → ℝ) + (v w : ℕ → V → ℕ → ℝ) (J : ℝ) (l : ℕ) + (hP : ∀ t < l, P t = Q t) + (hv : ∀ t < l, ∀ x a, a ≤ t → v t x a = w t x a) : + ∀ t < l, memory k P d v J t = memory k Q d w J t := by + intro t + induction t with + | zero => intro ht; rfl + | succ t ih => + intro ht + rw [memory, memory, hP (t+1) ht, ih (by omega)] + apply trim_congr_on + intro x hx a ha + exact hv (t+1) ht x a (inclusive_age k Q d w J (t+1) a ha) + +lemma inclusiveCache_prefix (k : ℕ) (P Q : ℕ → Finset V) (d : V → V → ℝ) + (v w : ℕ → V → ℕ → ℝ) (J : ℝ) (l : ℕ) + (hP : ∀ t < l, P t = Q t) + (hv : ∀ t < l, ∀ x a, a ≤ t → v t x a = w t x a) : + ∀ t < l, inclusiveCache k P d v J t = inclusiveCache k Q d w J t := by + intro t ht + cases t with + | zero => rfl + | succ t => + simp only [inclusiveCache, memory_prefix k P Q d v w J l hP hv t (by omega)] + +end BoundedTreewidthL1.AnchorCache + +namespace BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.propDecidable +variable {I : Type*} (T : SimpleGraph I) (hT : T.IsTree) (root : I) + +noncomputable def downPath (i : I) : T.Walk root i := (path T hT root i).reverse +lemma downPath_isPath (i : I) : (downPath T hT root i).IsPath := + (path_isPath T hT root i).reverse +lemma downPath_length (i : I) : (downPath T hT root i).length = (forest T hT root).depth i := by + simp only [downPath, SimpleGraph.Walk.length_reverse, path_length, forest] + +lemma depth_parent {i p : I} (hp : (forest T hT root).parent i = some p) : + (forest T hT root).depth i = (forest T hT root).depth p + 1 := by + have hd := hT.dist_eq_dist_add_one_of_adj root (parent_adj T hT root hp) + rw [SimpleGraph.dist_comm (u := root) (v := i), + SimpleGraph.dist_comm (u := root) (v := p)] at hd + have hlt := (forest T hT root).decreases i p hp + change T.dist p root < T.dist i root at hlt + change T.dist i root = T.dist p root + 1 + omega + +lemma path_parent {i p : I} (hp : (forest T hT root).parent i = some p) : + path T hT root i = (path T hT root p).cons (parent_adj T hT root hp) := by + have hd := depth_parent T hT root hp + have hlen : ((path T hT root p).cons (parent_adj T hT root hp)).length = T.dist i root := by + simpa only [SimpleGraph.Walk.length_cons, path_length, forest] using hd.symm + exact congrArg Subtype.val ((hT.isAcyclic.subsingleton_path i root).elim + ⟨_, path_isPath T hT root i⟩ ⟨_, SimpleGraph.Walk.isPath_of_length_eq_dist _ hlen⟩) + +lemma downPath_parent_getVert {i p : I} (hp : (forest T hT root).parent i = some p) + (t : ℕ) (ht : t ≤ (forest T hT root).depth p) : + (downPath T hT root i).getVert t = (downPath T hT root p).getVert t := by + unfold downPath + rw [path_parent T hT root hp, SimpleGraph.Walk.reverse_cons] + rw [SimpleGraph.Walk.getVert_append'] + rw [SimpleGraph.Walk.length_reverse, path_length] + exact ite_eq_left (show t ≤ T.dist p root from ht) + +end BoundedTreewidthL1.RootedTree + +namespace BoundedTreewidthL1.TreeCache +open AnchorCache _root_.OAI.BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V : Type*} + +noncomputable def bags (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (i : I) (t : ℕ) := B ((downPath T hT root i).getVert t) +noncomputable def heights (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (D : I → V → ℝ) (i : I) (_ : ℕ) (v : V) (a : ℕ) := D ((downPath T hT root i).getVert a) v +noncomputable def inclusive (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (i : I) := + inclusiveCache k (bags T hT root B i) d (heights T hT root D i) J ((forest T hT root).depth i) +noncomputable def released (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (i : I) := + memory k (bags T hT root B i) d (heights T hT root D i) J ((forest T hT root).depth i) +noncomputable def active (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (i : I) := + (inclusive T hT root B D k d J i).image (downPath T hT root i).getVert +noncomputable def retained (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (i : I) := + (released T hT root B D k d J i).image (downPath T hT root i).getVert + +lemma inclusive_parent (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) + {i p : I} (hp : (forest T hT root).parent i = some p) : + inclusive T hT root B D k d J i = + insert ((forest T hT root).depth i) (released T hT root B D k d J p) := by + have hb (t : ℕ) (ht : t < (forest T hT root).depth p + 1) : + bags T hT root B i t = bags T hT root B p t := by + unfold bags + rw [downPath_parent_getVert T hT root hp t (by omega)] + have hv (t : ℕ) (ht : t < (forest T hT root).depth p + 1) (x : V) (a : ℕ) + (ha : a ≤ t) : heights T hT root D i t x a = heights T hT root D p t x a := by + unfold heights + rw [downPath_parent_getVert T hT root hp a (by omega)] + unfold inclusive released + rw [depth_parent T hT root hp, inclusiveCache, + memory_prefix k _ _ d _ _ J ((forest T hT root).depth p+1) hb hv _ (by omega)] + +lemma active_parent (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) + {i p : I} (hp : (forest T hT root).parent i = some p) : + active T hT root B D k d J i = insert i (retained T hT root B D k d J p) := by + unfold active + rw [inclusive_parent T hT root B D k d J hp, Finset.image_insert] + have he : (downPath T hT root i).getVert ((forest T hT root).depth i) = i := by + rw [← downPath_length, SimpleGraph.Walk.getVert_length] + rw [he] + congr 1 + apply Finset.image_congr + intro a ha + have hage : a ≤ (forest T hT root).depth p := inclusive_age k _ d _ J _ a + (memory_subset k _ d _ J _ ha) + exact downPath_parent_getVert T hT root hp a hage + +lemma retained_subset (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (i : I) : + retained T hT root B D k d J i ⊆ active T hT root B D k d J i := + Finset.image_subset_image (memory_subset k _ d _ J _) + +lemma child_not_active (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) + {i p : I} (hp : (forest T hT root).parent i = some p) : + i ∉ active T hT root B D k d J p := by + intro h + obtain ⟨a,ha,hai⟩ := Finset.mem_image.mp h + have hage : a ≤ (forest T hT root).depth p := inclusive_age k _ d _ J _ a ha + have he : (downPath T hT root i).getVert a = + (downPath T hT root i).getVert ((forest T hT root).depth i) := by + rw [downPath_parent_getVert T hT root hp a hage, ← downPath_length, + SimpleGraph.Walk.getVert_length] + exact hai + have hh := (downPath_isPath T hT root i).getVert_injOn + (by simp only [Set.mem_ofPred_eq,downPath_length]; have := depth_parent T hT root hp; omega) + (by simp only [Set.mem_ofPred_eq,downPath_length,le_refl]) he + have hd := depth_parent T hT root hp + omega + +end BoundedTreewidthL1.TreeCache + +namespace BoundedTreewidthL1.TreeCache +open AnchorCache +open BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V : Type*} + +lemma active_root (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) : + active T hT root B D k d J root = {root} := by + simp only [active, inclusive, forest, SimpleGraph.dist_self, inclusiveCache, + Finset.image_singleton, SimpleGraph.Walk.getVert_zero] + +lemma active_inter_parent (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) + {i p : I} (hp : (forest T hT root).parent i = some p) : + active T hT root B D k d J i ∩ active T hT root B D k d J p = + retained T hT root B D k d J p := by + rw [active_parent T hT root B D k d J hp] + ext a + simp only [Finset.mem_inter, Finset.mem_insert] + constructor + · rintro ⟨rfl | h,hp'⟩ + · exact False.elim (child_not_active T hT root B D k d J hp hp') + · exact h + · intro h + exact ⟨Or.inr h, retained_subset T hT root B D k d J p h⟩ + +lemma active_sdiff_parent (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) + {i p : I} (hp : (forest T hT root).parent i = some p) : + active T hT root B D k d J i \ active T hT root B D k d J p = {i} := by + rw [active_parent T hT root B D k d J hp] + ext a + simp only [Finset.mem_sdiff, Finset.mem_insert, Finset.mem_singleton] + constructor + · rintro ⟨rfl | h,hp'⟩ + · rfl + · exact False.elim (hp' (retained_subset T hT root B D k d J p h)) + · rintro rfl + exact ⟨Or.inl rfl, child_not_active T hT root B D k d J hp⟩ + +/-- Width-only cache capacity on the actual root-to-node paths. -/ +theorem graph_active_bound [Fintype V] [DecidableEq V] + (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) (hG : G.Connected) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (B : I → Finset V) (hne : ∀ i, (B i).Nonempty) + (hT : T.IsTree) (root : I) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ B t ∧ v ∈ B t) + (hocc : ∀ v, (T.induce {t | v ∈ B t}).Connected) + (k : ℕ) (hcard : ∀ i, (B i).card ≤ k) (J : ℝ) (i : I) : + (active T hT root B (fun a => bagDistance G ℓ (B a) (hne a)) k + (shortestPathDistance G ℓ) J i).card ≤ cacheBound k + 1 := by + let : DecidableEq V := Classical.decEq V + obtain ⟨R,hR,heq,hbound,hprot⟩ := graph_cache_realizes G ℓ hG hℓ T B hne hT + hedge hocc k hcard J (downPath T hT root i) (downPath_isPath T hT root i) + apply (Finset.card_image_le).trans + change (inclusiveCache k (bags T hT root B i) (shortestPathDistance G ℓ) + (heights T hT root (fun a => bagDistance G ℓ (B a) (hne a)) i) J + ((forest T hT root).depth i)).card ≤ _ + rw [← downPath_length] + exact (heq _ le_rfl) ▸ hbound _ +end BoundedTreewidthL1.TreeCache + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/Annulus.lean b/lean/OAI/Combinatorics/TreewidthL1/Annulus.lean new file mode 100644 index 0000000000000000000000000000000000000000..a1103bafe2e46cc88050098c09fb60f63e8b20dc --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/Annulus.lean @@ -0,0 +1,1225 @@ +import OAI.Combinatorics.TreewidthL1.Anchors + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1 + +section ReachableWeightedPaths +variable {V : Type*} (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + +lemma path_length_set_nonempty_of_reachable {u v : V} (hr : G.Reachable u v) : + {r : ℝ | ∃ p : G.Walk u v, p.IsPath ∧ walkLength G ℓ p = r}.Nonempty := by + classical + obtain ⟨p⟩ := hr + exact ⟨walkLength G ℓ p.toPath.val, p.toPath.val, p.toPath.property, rfl⟩ + +lemma shortestPathDistance_attained_of_reachable [Fintype V] {u v : V} + (hr : G.Reachable u v) : + ∃ p : G.Walk u v, p.IsPath ∧ walkLength G ℓ p = shortestPathDistance G ℓ u v := + (path_length_set_nonempty_of_reachable G ℓ hr).csInf_mem (path_length_set_finite G ℓ u v) + +lemma shortestPathDistance_nonneg_of_reachable (hℓ : ∀ e, 0 ≤ ℓ e) + {u v : V} (hr : G.Reachable u v) : 0 ≤ shortestPathDistance G ℓ u v := by + apply le_csInf (path_length_set_nonempty_of_reachable G ℓ hr) + rintro r ⟨p, _, rfl⟩ + exact walkLength_nonneg G ℓ hℓ p + +lemma shortestPathDistance_self_of_nonneg (hℓ : ∀ e, 0 ≤ ℓ e) (u : V) : + shortestPathDistance G ℓ u u = 0 := + le_antisymm (shortestPathDistance_le_walkLength G ℓ hℓ .nil) + (shortestPathDistance_nonneg_of_reachable G ℓ hℓ .rfl) + +lemma shortestPathDistance_comm_of_reachable [Fintype V] (hℓ : ∀ e, 0 ≤ ℓ e) + {u v : V} (hr : G.Reachable u v) : + shortestPathDistance G ℓ u v = shortestPathDistance G ℓ v u := by + have hle {a b : V} (hab : G.Reachable a b) : + shortestPathDistance G ℓ a b ≤ shortestPathDistance G ℓ b a := by + obtain ⟨p, hp, heq⟩ := shortestPathDistance_attained_of_reachable G ℓ hab.symm + rw [← heq, ← walkLength_reverse G ℓ p] + exact shortestPathDistance_le_pathLength G ℓ hℓ p.reverse hp.reverse + exact le_antisymm (hle hr) (hle hr.symm) + +lemma shortestPathDistance_triangle_of_reachable [Fintype V] (hℓ : ∀ e, 0 ≤ ℓ e) + {u v w : V} (huv : G.Reachable u v) (hvw : G.Reachable v w) : + shortestPathDistance G ℓ u w ≤ shortestPathDistance G ℓ u v + shortestPathDistance G ℓ v w := by + obtain ⟨p, _, hp⟩ := shortestPathDistance_attained_of_reachable G ℓ huv + obtain ⟨q, _, hq⟩ := shortestPathDistance_attained_of_reachable G ℓ hvw + rw [← hp, ← hq, ← walkLength_append G ℓ p q] + exact shortestPathDistance_le_walkLength G ℓ hℓ (p.append q) + +lemma walkLength_takeUntil_le [DecidableEq V] (hℓ : ∀ e, 0 ≤ ℓ e) + {u v z : V} (p : G.Walk u v) (hz : z ∈ p.support) : + walkLength G ℓ (p.takeUntil z hz) ≤ walkLength G ℓ p := by + have h := walkLength_nonneg G ℓ hℓ (p.dropUntil z hz) + have heq := walkLength_append G ℓ (p.takeUntil z hz) (p.dropUntil z hz) + rw [SimpleGraph.Walk.take_spec] at heq + linarith + +lemma geodesic_split_of_reachable [Fintype V] [DecidableEq V] + (hℓ : ∀ e, 0 ≤ ℓ e) {a b z : V} (p : G.Walk a b) + (hmin : walkLength G ℓ p = shortestPathDistance G ℓ a b) (hz : z ∈ p.support) : + shortestPathDistance G ℓ a z + shortestPathDistance G ℓ z b = shortestPathDistance G ℓ a b := by + have heq : walkLength G ℓ (p.takeUntil z hz) + walkLength G ℓ (p.dropUntil z hz) = + shortestPathDistance G ℓ a b := by + rw [← walkLength_append, SimpleGraph.Walk.take_spec, hmin] + have h1 := shortestPathDistance_le_walkLength G ℓ hℓ (p.takeUntil z hz) + have h2 := shortestPathDistance_le_walkLength G ℓ hℓ (p.dropUntil z hz) + have h3 := shortestPathDistance_triangle_of_reachable G ℓ hℓ + (p.takeUntil z hz).reachable (p.dropUntil z hz).reachable + linarith + +/-- Intrinsic balls are connected even when the ambient graph is disconnected; +reachability is explicit, so the empty-infimum convention never adds vertices. -/ +lemma reachable_openBall_connected [Fintype V] [DecidableEq V] + (hℓ : ∀ e, 0 ≤ ℓ e) (u : V) {r : ℝ} (hr : 0 < r) : + (G.induce {v | G.Reachable u v ∧ shortestPathDistance G ℓ u v < r}).Connected := by + let S := {v | G.Reachable u v ∧ shortestPathDistance G ℓ u v < r} + have hu : u ∈ S := ⟨.rfl, by simpa [shortestPathDistance_self_of_nonneg G ℓ hℓ] using hr⟩ + rw [SimpleGraph.connected_iff_exists_forall_reachable] + refine ⟨⟨u, hu⟩, ?_⟩ + rintro ⟨v, hv⟩ + obtain ⟨p, _, hp⟩ := shortestPathDistance_attained_of_reachable G ℓ hv.1 + have hsupp : ∀ z ∈ p.support, z ∈ S := by + intro z hz + refine ⟨(p.takeUntil z hz).reachable, ?_⟩ + calc + shortestPathDistance G ℓ u z ≤ walkLength G ℓ (p.takeUntil z hz) := + shortestPathDistance_le_walkLength G ℓ hℓ _ + _ ≤ walkLength G ℓ p := walkLength_takeUntil_le G ℓ hℓ p hz + _ < r := hp ▸ hv.2 + exact ⟨(p.induce S hsupp).copy (Subtype.ext rfl) (Subtype.ext rfl)⟩ + +lemma reachable_closedBall_connected [Fintype V] [DecidableEq V] + (hℓ : ∀ e, 0 ≤ ℓ e) (u : V) {r : ℝ} (hr : 0 ≤ r) : + (G.induce {v | G.Reachable u v ∧ shortestPathDistance G ℓ u v ≤ r}).Connected := by + let S := {v | G.Reachable u v ∧ shortestPathDistance G ℓ u v ≤ r} + have hu : u ∈ S := ⟨.rfl, by simpa [shortestPathDistance_self_of_nonneg G ℓ hℓ] using hr⟩ + rw [SimpleGraph.connected_iff_exists_forall_reachable] + refine ⟨⟨u, hu⟩, ?_⟩ + rintro ⟨v, hv⟩ + obtain ⟨p, _, hp⟩ := shortestPathDistance_attained_of_reachable G ℓ hv.1 + have hsupp : ∀ z ∈ p.support, z ∈ S := by + intro z hz + refine ⟨(p.takeUntil z hz).reachable, ?_⟩ + calc + shortestPathDistance G ℓ u z ≤ walkLength G ℓ (p.takeUntil z hz) := + shortestPathDistance_le_walkLength G ℓ hℓ _ + _ ≤ walkLength G ℓ p := walkLength_takeUntil_le G ℓ hℓ p hz + _ ≤ r := hp ▸ hv.2 + exact ⟨(p.induce S hsupp).copy (Subtype.ext rfl) (Subtype.ext rfl)⟩ + +lemma shortest_closedBall_connected [Fintype V] [DecidableEq V] + (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) (u : V) {r : ℝ} (hr : 0 ≤ r) : + (G.induce {v | shortestPathDistance G ℓ u v ≤ r}).Connected := by + have heq : {v | G.Reachable u v ∧ shortestPathDistance G ℓ u v ≤ r} = + {v | shortestPathDistance G ℓ u v ≤ r} := by + ext v + simp [hG u v] + rw [← heq] + exact reachable_closedBall_connected G ℓ hℓ u hr + +end ReachableWeightedPaths + +@[instance_reducible] +noncomputable def weightedMetricSpace {V : Type*} [Fintype V] + (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + (hG : G.Connected) (hℓ : ∀ e, 0 < ℓ e) : MetricSpace V where + dist := shortestPathDistance G ℓ + dist_self := shortestPathDistance_self G ℓ hG (fun e => (hℓ e).le) + dist_comm := shortestPathDistance_comm G ℓ hG (fun e => (hℓ e).le) + dist_triangle := shortestPathDistance_triangle G ℓ hG (fun e => (hℓ e).le) + eq_of_dist_eq_zero := fun {_ _} h => (shortestPathDistance_metric G ℓ hG hℓ).2.2.2.2.1 _ _ h + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.Annulus + +variable {V : Type*} + +abbrev weights (H : SimpleGraph V) (w : Sym2 V → ℝ) : H.edgeSet → ℝ := fun e => w e.val + +noncomputable def distance (H : SimpleGraph V) (w : Sym2 V → ℝ) : V → V → ℝ := + shortestPathDistance H (weights H w) + +noncomputable def root (H : SimpleGraph V) (x : V) : V := + Quot.out (H.connectedComponentMk x) + +lemma root_reachable (H : SimpleGraph V) (x : V) : H.Reachable (root H x) x := + SimpleGraph.ConnectedComponent.exact (Quot.out_eq _) + +lemma root_eq {H : SimpleGraph V} {x y : V} (h : H.Reachable x y) : + root H x = root H y := congrArg Quot.out (SimpleGraph.ConnectedComponent.sound h) + +lemma root_idem (H : SimpleGraph V) (x : V) : root H (root H x) = root H x := + root_eq (root_reachable H x) + +noncomputable def height (H : SimpleGraph V) (w : Sym2 V → ℝ) (x : V) : ℝ := + distance H w (root H x) x + +lemma walkLength_weights {H : SimpleGraph V} (w : Sym2 V → ℝ) + {u v : V} (p : H.Walk u v) : + walkLength H (weights H w) p = (p.edges.map w).sum := by + induction p with + | nil => rfl + | cons h p ih => simp only [walkLength, SimpleGraph.Walk.edges_cons, + List.map_cons, List.sum_cons, weights, ih] + +lemma walkLength_transfer {H G : SimpleGraph V} (w : Sym2 V → ℝ) + {u v : V} (p : H.Walk u v) (hp : ∀ e ∈ p.edges, e ∈ G.edgeSet) : + walkLength G (weights G w) (p.transfer G hp) = walkLength H (weights H w) p := by + simp only [walkLength_weights, SimpleGraph.Walk.edges_transfer] + +lemma walkLength_mono_map {H G : SimpleGraph V} (hHG : H ≤ G) (w : Sym2 V → ℝ) + {u v : V} (p : H.Walk u v) : + walkLength G (weights G w) (p.map (.ofLE hHG)) = walkLength H (weights H w) p := by + induction p with + | nil => rfl + | @cons u v z h p ih => simpa only [SimpleGraph.Walk.map_cons, walkLength, + SimpleGraph.Hom.ofLE_apply, weights] using congrArg (fun r => w s(u,v) + r) ih + +lemma distance_mono [Fintype V] {H G : SimpleGraph V} (hHG : H ≤ G) + (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) {u v : V} (huv : H.Reachable u v) : + distance G w u v ≤ distance H w u v := by + obtain ⟨p, _, hp⟩ := shortestPathDistance_attained_of_reachable H (weights H w) huv + change shortestPathDistance G (weights G w) u v ≤ shortestPathDistance H (weights H w) u v + rw [← hp, ← walkLength_mono_map hHG w p] + exact shortestPathDistance_le_walkLength G (weights G w) (fun e => hw e.val) _ + +lemma distance_edge (H : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + {u v : V} (huv : H.Adj u v) : distance H w u v ≤ w s(u,v) := by + simpa [distance, walkLength, weights] using + shortestPathDistance_le_walkLength H (weights H w) (fun e => hw e.val) huv.toWalk + +lemma height_nonneg (H : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + (x : V) : 0 ≤ height H w x := + shortestPathDistance_nonneg_of_reachable H (weights H w) (fun e => hw e.val) + (root_reachable H x) + +lemma height_root (H : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + (x : V) : height H w (root H x) = 0 := by + simp only [height, root_idem, distance] + exact shortestPathDistance_self_of_nonneg H (weights H w) (fun e => hw e.val) _ + +lemma height_eq_of_reachable {H : SimpleGraph V} (w : Sym2 V → ℝ) {x y : V} + (hxy : H.Reachable x y) : height H w y = distance H w (root H x) y := by + simp only [height, root_eq hxy] + +lemma height_le_add_distance [Fintype V] (H : SimpleGraph V) (w : Sym2 V → ℝ) + (hw : ∀ e, 0 ≤ w e) {x y : V} (hxy : H.Reachable x y) : + height H w y ≤ height H w x + distance H w x y := by + rw [height_eq_of_reachable w hxy] + exact shortestPathDistance_triangle_of_reachable H (weights H w) (fun e => hw e.val) + (root_reachable H x) hxy + +lemma height_edge [Fintype V] (H : SimpleGraph V) (w : Sym2 V → ℝ) + (hw : ∀ e, 0 ≤ w e) {x y : V} (hxy : H.Adj x y) : + height H w y ≤ height H w x + w s(x,y) := by + have h1 := height_le_add_distance H w hw hxy.reachable + have h2 := distance_edge H w hw hxy + linarith + +/-- The predecessor of a first height crossing is strictly inside the ball. -/ +lemma walk_crossing_below (H : SimpleGraph V) (f : V → ℝ) {ε t : ℝ} + (hstep : ∀ a b, H.Adj a b → f b ≤ f a + ε) + {u v : V} (p : H.Walk u v) (hu : f u < t) (hv : t ≤ f v) : + ∃ z ∈ p.support, t - ε ≤ f z ∧ f z < t := by + induction p with + | nil => exact (not_lt_of_ge hv hu).elim + | @cons a b c hab p ih => + by_cases hb : f b < t + · obtain ⟨z, hz, hlo, hhi⟩ := ih hb hv + exact ⟨z, by simp [hz], hlo, hhi⟩ + · have hs := hstep a b hab + exact ⟨a, by simp, by linarith, hu⟩ + +/-- The strict intrinsic inner ball, with reachability explicitly imposed. -/ +def inner (H : SimpleGraph V) (w : Sym2 V → ℝ) (x : V) (t : ℝ) : Set V := + {z | H.Reachable (root H x) z ∧ distance H w (root H x) z < t} + +lemma inner_connected [Fintype V] [DecidableEq V] (H : SimpleGraph V) + (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) (x : V) {t : ℝ} (ht : 0 < t) : + (H.induce (inner H w x t)).Connected := + reachable_openBall_connected H (weights H w) (fun e => hw e.val) (root H x) ht + +lemma inner_reachable {H : SimpleGraph V} {w : Sym2 V → ℝ} {x z : V} {t : ℝ} + (hz : z ∈ inner H w x t) : H.Reachable x z := + (root_reachable H x).symm.trans hz.1 + +lemma inner_height {H : SimpleGraph V} {w : Sym2 V → ℝ} {x z : V} {t : ℝ} + (hz : z ∈ inner H w x t) : height H w z < t := by + rw [height_eq_of_reachable w (inner_reachable hz)] + exact hz.2 + +lemma inner_dominates [Fintype V] [DecidableEq V] + (H : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + {ε : ℝ} (hmesh : ∀ u v, H.Adj u v → w s(u,v) ≤ ε) + (x c : V) (hxc : H.Reachable x c) {t R : ℝ} + (ht : 0 < t) (hlo : t ≤ height H w c) (hhi : height H w c ≤ t + R) : + ∃ z ∈ inner H w x t, distance H w c z ≤ R + ε := by + have hrc := (root_reachable H x).trans hxc + obtain ⟨p, _, hp⟩ := shortestPathDistance_attained_of_reachable H (weights H w) hrc + have hstep : ∀ a b, H.Adj a b → height H w b ≤ height H w a + ε := by + intro a b hab + have h1 := height_edge H w hw hab + have h2 := hmesh a b hab + linarith + obtain ⟨z, hz, hzlo, hzhi⟩ := walk_crossing_below H (height H w) hstep p + (by simpa [height_root H w hw] using ht) hlo + have hrz := (p.takeUntil z hz).reachable + have hxz := (root_reachable H x).symm.trans hrz + have hzheight := height_eq_of_reachable w hxz + have hcHeight := height_eq_of_reachable w hxc + refine ⟨z, ⟨hrz, by rwa [← hzheight]⟩, ?_⟩ + have hsplit := geodesic_split_of_reachable H (weights H w) (fun e => hw e.val) p hp hz + have hsym := shortestPathDistance_comm_of_reachable H (weights H w) (fun e => hw e.val) + (p.dropUntil z hz).reachable + change distance H w (root H x) z + distance H w z c = distance H w (root H x) c at hsplit + change distance H w z c = distance H w c z at hsym + rw [← hzheight, ← hcHeight, hsym] at hsplit + linarith + +noncomputable def band (H : SimpleGraph V) (w : Sym2 V → ℝ) (R a : ℝ) (x : V) : ℤ := + ⌊(height H w x + a) / R⌋ + +noncomputable def cut (H : SimpleGraph V) (w : Sym2 V → ℝ) (R a : ℝ) : SimpleGraph V where + Adj u v := H.Adj u v ∧ band H w R a u = band H w R a v + symm := ⟨fun _ _ h => ⟨h.1.symm, h.2.symm⟩⟩ + loopless := ⟨fun _ h => H.irrefl h.1⟩ + +lemma cut_le (H : SimpleGraph V) (w : Sym2 V → ℝ) (R a : ℝ) : cut H w R a ≤ H := + fun _ _ h => h.1 + +lemma band_eq_of_cut_reachable {H : SimpleGraph V} {w : Sym2 V → ℝ} {R a : ℝ} + {x y : V} (h : (cut H w R a).Reachable x y) : band H w R a x = band H w R a y := by + obtain ⟨p⟩ := h + induction p with + | nil => rfl + | cons h p ih => exact h.2.trans ih + +lemma band_bounds (H : SimpleGraph V) (w : Sym2 V → ℝ) {R : ℝ} (hR : 0 < R) + (a : ℝ) (x : V) : + (band H w R a x : ℝ) * R - a ≤ height H w x ∧ + height H w x < (band H w R a x : ℝ) * R - a + R := by + have hlo := Int.floor_le ((height H w x + a) / R) + have hhi := Int.lt_floor_add_one ((height H w x + a) / R) + have hlo' := (le_div_iff₀ hR).mp hlo + have hhi' := (div_lt_iff₀ hR).mp hhi + change (band H w R a x : ℝ) * R ≤ height H w x + a at hlo' + change height H w x + a < ((band H w R a x : ℝ) + 1) * R at hhi' + constructor <;> nlinarith + +lemma band_nonneg (H : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + {R a : ℝ} (hR : 0 < R) (ha : 0 ≤ a) (x : V) : 0 ≤ band H w R a x := + Int.floor_nonneg.mpr (div_nonneg (add_nonneg (height_nonneg H w hw x) ha) hR.le) + +/-- A single annulus either is close to its root, or has a connected inner +ball deleted from its component and uniformly close to all of that component. -/ +theorem cut_component_alternative [Fintype V] [DecidableEq V] + (G H : SimpleGraph V) (hHG : H ≤ G) + (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + {R a ε : ℝ} (hR : 0 < R) (ha0 : 0 ≤ a) (haR : a < R) + (hmesh : ∀ u v, H.Adj u v → w s(u,v) ≤ ε) (x : V) : + (∀ y z, (cut H w R a).Reachable x y → (cut H w R a).Reachable x z → + distance G w y z ≤ 2 * R) ∨ + ∃ B : Set V, (G.induce B).Connected ∧ + (∀ z ∈ B, H.Reachable x z) ∧ + (∀ z ∈ B, ¬(cut H w R a).Reachable x z) ∧ + ∀ c, (cut H w R a).Reachable x c → ∃ z ∈ B, distance G w c z ≤ R + ε := by + let n := band H w R a x + have hn : 0 ≤ n := band_nonneg H w hw hR ha0 x + by_cases hn0 : n = 0 + · left + intro y z hxy hxz + have hy := (band_bounds H w hR a y).2 + have hz := (band_bounds H w hR a z).2 + have hby : band H w R a y = 0 := (band_eq_of_cut_reachable hxy).symm.trans hn0 + have hbz : band H w R a z = 0 := (band_eq_of_cut_reachable hxz).symm.trans hn0 + rw [hby] at hy + rw [hbz] at hz + have hyR : height H w y ≤ R := by simp only [Int.cast_zero, zero_mul, zero_sub] at hy; linarith + have hzR : height H w z ≤ R := by simp only [Int.cast_zero, zero_mul, zero_sub] at hz; linarith + have hHy := hxy.mono (cut_le H w R a) + have hHz := hxz.mono (cut_le H w R a) + have hry := (root_reachable H x).trans hHy + have hrz := (root_reachable H x).trans hHz + have hm := distance_mono hHG w hw (hHy.symm.trans hHz) + have ht := shortestPathDistance_triangle_of_reachable H (weights H w) (fun e => hw e.val) + hry.symm hrz + have hs := shortestPathDistance_comm_of_reachable H (weights H w) (fun e => hw e.val) hry + change distance H w y z ≤ distance H w y (root H x) + distance H w (root H x) z at ht + change distance H w (root H x) y = distance H w y (root H x) at hs + rw [← hs, ← height_eq_of_reachable w hHy, ← height_eq_of_reachable w hHz] at ht + linarith + · right + have hn1 : (1 : ℤ) ≤ n := by omega + have hn1r : (1 : ℝ) ≤ n := by exact_mod_cast hn1 + let t : ℝ := (n : ℝ) * R - a + have ht : 0 < t := by dsimp [t]; nlinarith + refine ⟨inner H w x t, (inner_connected H w hw x ht).mono (fun _ _ h => hHG h), + fun _ hz => inner_reachable hz, ?_, ?_⟩ + · intro z hz hcz + have hzb := (band_eq_of_cut_reachable hcz).symm + have hzlo := (band_bounds H w hR a z).1 + rw [hzb] at hzlo + exact (inner_height hz).not_ge hzlo + · intro c hxc + have hHxc := hxc.mono (cut_le H w R a) + have hcb := (band_eq_of_cut_reachable hxc).symm + have hc := band_bounds H w hR a c + rw [hcb] at hc + obtain ⟨z, hz, hnear⟩ := inner_dominates H w hw hmesh x c hHxc ht hc.1 hc.2.le + refine ⟨z, hz, (distance_mono hHG w hw ?_).trans hnear⟩ + exact hHxc.symm.trans (inner_reachable hz) + +variable {A : Type*} + +/-- Successive annulus cuts, with one finite random choice at each round. -/ +noncomputable def run (w : Sym2 V → ℝ) (R : ℝ) (offset : A → ℝ) : + (n : ℕ) → SimpleGraph V → (Fin n → A) → SimpleGraph V + | 0, H, _ => H + | n + 1, H, σ => run w R offset n (cut H w R (offset (σ 0))) (fun i => σ i.succ) + +lemma run_le (w : Sym2 V → ℝ) (R : ℝ) (offset : A → ℝ) + (n : ℕ) (H : SimpleGraph V) (σ : Fin n → A) : run w R offset n H σ ≤ H := by + induction n generalizing H with + | zero => exact le_rfl + | succ n ih => exact (ih _ _).trans (cut_le H w R _) + +/-- Connected barriers around a final component. The inside/outside fields are +what permit nested cuts to add one more *disjoint* barrier at each round. -/ +structure BarrierFamily (G H F : SimpleGraph V) (w : Sym2 V → ℝ) + (ρ : ℝ) (x : V) (n : ℕ) where + sets : Fin n → Set V + connected : ∀ i, (G.induce (sets i)).Connected + inside : ∀ i z, z ∈ sets i → H.Reachable x z + outside : ∀ i z, z ∈ sets i → ¬F.Reachable x z + separated : Pairwise (fun i j => Disjoint (sets i) (sets j)) + dominates : ∀ i c, F.Reachable x c → ∃ z ∈ sets i, distance G w c z ≤ ρ + +/-- Deterministic invariant of the annulus recursion. A large component has +one genuinely connected, disjoint nearby barrier for every cut round. -/ +theorem run_component_alternative [Fintype V] [DecidableEq V] + (G : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + {R ε : ℝ} (hR : 0 < R) (offset : A → ℝ) + (hoff0 : ∀ a, 0 ≤ offset a) (hoffR : ∀ a, offset a < R) + (n : ℕ) (H : SimpleGraph V) (hHG : H ≤ G) + (hmesh : ∀ u v, H.Adj u v → w s(u,v) ≤ ε) (σ : Fin n → A) (x : V) : + (∀ y z, (run w R offset n H σ).Reachable x y → + (run w R offset n H σ).Reachable x z → distance G w y z ≤ 2 * R) ∨ + Nonempty (BarrierFamily G H (run w R offset n H σ) w (R + ε) x n) := by + induction n generalizing H with + | zero => + right + exact ⟨{ sets := Fin.elim0 + connected := fun i => Fin.elim0 i + inside := fun i => Fin.elim0 i + outside := fun i => Fin.elim0 i + separated := fun i => Fin.elim0 i + dominates := fun i => Fin.elim0 i }⟩ + | succ n ih => + let H' := cut H w R (offset (σ 0)) + let τ : Fin n → A := fun i => σ i.succ + let F := run w R offset n H' τ + have hF : run w R offset (n + 1) H σ = F := rfl + rw [hF] + have hH'H : H' ≤ H := cut_le H w R _ + have hFH' : F ≤ H' := run_le w R offset n H' τ + have halt := cut_component_alternative G H hHG w hw hR (hoff0 (σ 0)) + (hoffR (σ 0)) hmesh x + rcases halt with hsmall | ⟨B, hB, hBin, hBout, hBdom⟩ + · left + exact fun y z hy hz => hsmall y z (hy.mono hFH') (hz.mono hFH') + · have hH'G := hH'H.trans hHG + have hmesh' : ∀ u v, H'.Adj u v → w s(u,v) ≤ ε := fun u v h => hmesh u v (hH'H h) + rcases ih H' hH'G hmesh' τ with hsmall | hex + · exact Or.inl hsmall + · obtain ⟨D⟩ := hex + right + refine ⟨{ + sets := Fin.cons B D.sets + connected := ?_ + inside := ?_ + outside := ?_ + separated := ?_ + dominates := ?_ }⟩ + · intro i + refine Fin.cases hB (fun j => D.connected j) i + · intro i + refine Fin.cases hBin ?_ i + intro j z hz + exact (D.inside j z hz).mono hH'H + · intro i + refine Fin.cases ?_ (fun j => D.outside j) i + intro z hz hFz + exact hBout z hz (hFz.mono hFH') + · intro i j + refine Fin.cases ?_ ?_ i + · refine Fin.cases ?_ ?_ j + · intro hij; exact (hij rfl).elim + · intro l _ + apply Set.disjoint_left.mpr + intro z hzB hzD + exact hBout z hzB (D.inside l z hzD) + · intro l + refine Fin.cases ?_ ?_ j + · intro _; apply Set.disjoint_left.mpr + intro z hzD hzB + exact hBout z hzB (D.inside l z hzD) + · intro m hij + exact D.separated (fun hlm => hij (congrArg Fin.succ hlm)) + · intro i + refine Fin.cases ?_ (fun j => D.dominates j) i + intro c hc + exact hBdom c (hc.mono hFH') + +lemma reachable_set_connected [DecidableEq V] (H : SimpleGraph V) (x : V) : + (H.induce {z | H.Reachable x z}).Connected := by + rw [SimpleGraph.connected_iff_exists_forall_reachable] + refine ⟨⟨x, .rfl⟩, ?_⟩ + rintro ⟨z, hz⟩ + obtain ⟨p⟩ := hz + have hsupp : ∀ y ∈ p.support, H.Reachable x y := fun y hy => (p.takeUntil y hy).reachable + exact ⟨(p.induce {z | H.Reachable x z} hsupp).copy (Subtype.ext rfl) (Subtype.ext rfl)⟩ + +end BoundedTreewidthL1.Annulus + +namespace BoundedTreewidthL1 + +/-- Convexity with respect to the unique simple paths in a tree. -/ +def TreePathClosed {I : Type*} (T : SimpleGraph I) (S : Set I) : Prop := + ∀ ⦃u v : I⦄, u ∈ S → v ∈ S → ∀ (p : T.Walk u v), p.IsPath → + ∀ z ∈ p.support, z ∈ S + +private theorem tree_helly_aux (n : ℕ) : + ∀ {I J : Type*} [Fintype I], Fintype.card I ≤ n → + ∀ (T : SimpleGraph I), T.IsTree → ∀ (S : J → Set I), + (∀ j, (S j).Nonempty) → (∀ j, TreePathClosed T (S j)) → + (∀ i j, (S i ∩ S j).Nonempty) → ∃ v, ∀ j, v ∈ S j := by + classical + induction n using Nat.strong_induction_on with + | h n ih => + intro I J _ hn T hT S hne hconv hpair + have : Nonempty I := hT.connected.nonempty + by_cases hsub : Subsingleton I + · let := hsub + refine ⟨Classical.choice (inferInstance : Nonempty I), ?_⟩ + intro j + obtain ⟨z, hz⟩ := hne j + simpa only [Subsingleton.elim (Classical.choice (inferInstance : Nonempty I)) z] using hz + · let : Nontrivial I := not_subsingleton_iff_nontrivial.mp hsub + obtain ⟨v, hv⟩ := hT.exists_vert_degree_one_of_nontrivial + obtain ⟨u, hvu, huniq⟩ := SimpleGraph.degree_eq_one_iff_existsUnique_adj.mp hv + by_cases hsingle : ∃ j, S j = {v} + · obtain ⟨j, hj⟩ := hsingle + refine ⟨v, fun i => ?_⟩ + obtain ⟨z, hzj, hzi⟩ := hpair j i + have hzv : z = v := by simpa [hj] using hzj + exact hzv ▸ hzi + · have hneighbor : ∀ j, v ∈ S j → u ∈ S j := by + intro j hvj + have hex : ∃ w ∈ S j, w ≠ v := by + by_contra! hh + apply hsingle + refine ⟨j, Set.Subset.antisymm ?_ ?_⟩ + · intro w hw + exact Set.mem_singleton_iff.mpr (hh w hw) + · simpa only [Set.singleton_subset_iff] using hvj + obtain ⟨w, hw, hwv⟩ := hex + obtain ⟨p, hp⟩ := hT.connected.exists_isPath v w + have hnil : ¬p.Nil := SimpleGraph.Walk.not_nil_of_ne hwv.symm + have hsu : p.snd = u := huniq _ (p.adj_snd hnil) + exact hsu ▸ hconv j hvj hw p hp _ (p.getVert_mem_support 1) + let I' := {x : I // x ∈ ({v} : Set I)ᶜ} + let T' : SimpleGraph I' := T.induce {v}ᶜ + let S' : J → Set I' := fun j => {x | x.val ∈ S j} + have hunv : u ∈ ({v} : Set I)ᶜ := by + simpa only [Set.mem_compl_iff, Set.mem_singleton_iff] using hvu.ne' + have hT' : T'.IsTree := + ⟨hT.connected.induce_compl_singleton_of_degree_eq_one hv, + hT.isAcyclic.induce _⟩ + have hne' : ∀ j, (S' j).Nonempty := by + intro j + obtain ⟨z, hz⟩ := hne j + by_cases hzv : z = v + · exact ⟨⟨u, hunv⟩, hneighbor j (hzv ▸ hz)⟩ + · exact ⟨⟨z, by simpa using hzv⟩, hz⟩ + have hconv' : ∀ j, TreePathClosed T' (S' j) := by + intro j a b ha hb p hp z hz + let f := (SimpleGraph.Embedding.induce (G := T) ({v} : Set I)ᶜ).toHom + have hp' : (p.map f).IsPath := hp.map Subtype.val_injective + have hmem : f z ∈ (p.map f).support := by + rw [SimpleGraph.Walk.support_map] + exact List.mem_map.mpr ⟨z, hz, rfl⟩ + exact hconv j ha hb (p.map f) hp' (f z) hmem + have hpair' : ∀ i j, (S' i ∩ S' j).Nonempty := by + intro i j + obtain ⟨z, hzi, hzj⟩ := hpair i j + by_cases hzv : z = v + · exact ⟨⟨u, hunv⟩, hneighbor i (hzv ▸ hzi), hneighbor j (hzv ▸ hzj)⟩ + · exact ⟨⟨z, by simpa using hzv⟩, hzi, hzj⟩ + have hcard : Fintype.card I' < Fintype.card I := + Fintype.card_subtype_lt (x := v) (by simp) + obtain ⟨z, hz⟩ := ih (Fintype.card I') (lt_of_lt_of_le hcard hn) + (le_refl _) T' hT' S' hne' hconv' hpair' + exact ⟨z.val, hz⟩ + +/-- Finite trees have the Helly property for connected vertex sets. The index +family need not be finite. This is the exact combinatorial input for the +bounded-treewidth padded-partition construction, not a main theorem claim. -/ +theorem tree_subtree_helly {I J : Type*} [Fintype I] + (T : SimpleGraph I) (hT : T.IsTree) (S : J → Set I) + (hS : ∀ j, (T.induce (S j)).Connected) + (hpair : ∀ i j, (S i ∩ S j).Nonempty) : + ∃ v, ∀ j, v ∈ S j := by + have hne : ∀ j, (S j).Nonempty := fun j => (Set.nonempty_coe_sort.mp (hS j).nonempty) + have hconv : ∀ j, TreePathClosed T (S j) := by + intro j u v hu hv p hp z hz + exact tree_path_mem_connected T hT (hS j) hu hv p hp hz + exact tree_helly_aux (Fintype.card I) (le_refl _) T hT S hne hconv hpair + +/-- An arbitrary nonempty connected vertex set touches a connected set of bags. -/ +lemma touched_bags_connected_set {V I : Type*} [DecidableEq V] + (G : SimpleGraph V) (T : SimpleGraph I) (bag : I → Finset V) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) + (hocc : ∀ v, (T.induce {t | v ∈ bag t}).Connected) + (S : Set V) (hS : (G.induce S).Connected) : + (T.induce {t | ∃ z ∈ S, z ∈ bag t}).Connected := by + obtain ⟨u, hu⟩ := hS.nonempty + obtain ⟨A, hA⟩ := (hocc u).nonempty + apply T.induce_connected_of_patches (s := {t | ∃ z ∈ S, z ∈ bag t}) A ⟨u, hu, hA⟩ + rintro B ⟨v, hv, hB⟩ + obtain ⟨p⟩ := hS ⟨u, hu⟩ ⟨v, hv⟩ + let f := (SimpleGraph.Embedding.induce (G := G) S).toHom + let q := p.map f + refine ⟨{t | ∃ z ∈ q.support, z ∈ bag t}, ?_, + ⟨u, q.start_mem_support, hA⟩, ⟨v, q.end_mem_support, hB⟩, ?_⟩ + · rintro t ⟨z, hz, hzt⟩ + have hzS : z ∈ S := by + change z ∈ (p.map f).support at hz + rw [SimpleGraph.Walk.support_map] at hz + obtain ⟨a, _, rfl⟩ := List.mem_map.mp hz + exact a.property + exact ⟨z, hzS, hzt⟩ + · exact touched_bags_connected G T bag hedge hocc q _ _ + +lemma card_le_of_pairwise_disjoint_hits {V A : Type*} [DecidableEq V] [Fintype A] + (bag : Finset V) (X : A → Set V) + (hdis : Pairwise (fun i j => Disjoint (X i) (X j))) + (hhit : ∀ i, ∃ v ∈ X i, v ∈ bag) : Fintype.card A ≤ bag.card := by + classical + choose f hfX hfb using hhit + let g : A → ↥bag := fun i => ⟨f i, hfb i⟩ + have hinj : Function.Injective g := by + intro i j hij + by_contra hne + have hf : f i = f j := congrArg Subtype.val hij + exact Set.disjoint_left.mp (hdis hne) (hfX i) (hf.symm ▸ hfX j) + simpa using Fintype.card_le_of_injective g hinj + +/-- A crossbar of two internally disjoint families of connected sets forces +a bag meeting every member of one family. Consequently its size is at least +the smaller family cardinality. This is the deterministic width obstruction +used by iterated annulus partitions. -/ +theorem tree_decomposition_crossbar {V I A B : Type*} [DecidableEq V] + [Fintype I] [Fintype A] [Fintype B] + (G : SimpleGraph V) (T : SimpleGraph I) (bag : I → Finset V) + (hT : T.IsTree) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) + (hocc : ∀ v, (T.induce {t | v ∈ bag t}).Connected) + (X : A → Set V) (Y : B → Set V) + (hX : ∀ i, (G.induce (X i)).Connected) + (hY : ∀ j, (G.induce (Y j)).Connected) + (hdisX : Pairwise (fun i j => Disjoint (X i) (X j))) + (hdisY : Pairwise (fun i j => Disjoint (Y i) (Y j))) + (hcross : ∀ i j, (X i ∩ Y j).Nonempty) : + ∃ t, min (Fintype.card A) (Fintype.card B) ≤ (bag t).card := by + classical + let S : A × B → Set I := fun p => {t | ∃ z ∈ X p.1 ∪ Y p.2, z ∈ bag t} + have hS : ∀ p, (T.induce (S p)).Connected := by + intro p + exact touched_bags_connected_set G T bag hedge hocc _ + (SimpleGraph.induce_union_connected (hX p.1).preconnected (hY p.2).preconnected + (hcross p.1 p.2)) + have hpair : ∀ p q, (S p ∩ S q).Nonempty := by + intro p q + obtain ⟨z, hzX, hzY⟩ := hcross p.1 q.2 + obtain ⟨t, ht⟩ := (hocc z).nonempty + exact ⟨t, ⟨z, Or.inl hzX, ht⟩, ⟨z, Or.inr hzY, ht⟩⟩ + obtain ⟨t, ht⟩ := tree_subtree_helly T hT S hS hpair + refine ⟨t, ?_⟩ + by_cases hall : ∀ i, ∃ z ∈ X i, z ∈ bag t + · exact le_trans (min_le_left _ _) (card_le_of_pairwise_disjoint_hits (bag t) X hdisX hall) + · push Not at hall + obtain ⟨i, hi⟩ := hall + have hYhit : ∀ j, ∃ z ∈ Y j, z ∈ bag t := by + intro j + obtain ⟨z, hzX | hzY, hzt⟩ := ht (i, j) + · exact (hi z hzX hzt).elim + · exact ⟨z, hzY, hzt⟩ + exact le_trans (min_le_right _ _) (card_le_of_pairwise_disjoint_hits (bag t) Y hdisY hYhit) + +/-- A discrete intermediate-value bound with an explicit mesh error. -/ +lemma walk_crossing_window {V : Type*} (H : SimpleGraph V) (f : V → ℝ) + {ε t : ℝ} (hε : 0 ≤ ε) + (hstep : ∀ a b, H.Adj a b → f b ≤ f a + ε) + {u v : V} (p : H.Walk u v) (hu : f u ≤ t) (hv : t ≤ f v) : + ∃ z ∈ p.support, t ≤ f z ∧ f z ≤ t + ε := by + induction p with + | @nil x => exact ⟨x, by simp, hv, by linarith⟩ + | @cons a b c hab p ih => + by_cases hb : f b ≤ t + · obtain ⟨z, hz, ht, he⟩ := ih hb hv + exact ⟨z, by simp [hz], ht, he⟩ + · refine ⟨b, ?_, le_of_lt (lt_of_not_ge hb), ?_⟩ + · simp only [SimpleGraph.Walk.support_cons, List.mem_cons] + exact Or.inr p.start_mem_support + · exact (hstep a b hab).trans (by linarith : f a + ε ≤ t + ε) + +/-- The deterministic diameter obstruction behind the annulus algorithm. +The radius balls are in the original metric; only the connectivity walk in C +uses the small-edge subgraph H. No intrinsic diameter replaces weak diameter. -/ +theorem connected_multidomination_diameter {V I : Type*} [MetricSpace V] + [DecidableEq V] [Fintype I] + (G H : SimpleGraph V) (hHG : H ≤ G) + (T : SimpleGraph I) (bag : I → Finset V) (k : ℕ) + (hT : T.IsTree) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) + (hocc : ∀ v, (T.induce {t | v ∈ bag t}).Connected) + (hwidth : ∀ t, (bag t).card ≤ k) + {R ε : ℝ} (hR : 0 ≤ R) (hε : 0 < ε) + (hmesh : ∀ u v, H.Adj u v → dist u v ≤ ε) + (hballs : ∀ c, (G.induce {z | dist c z ≤ R}).Connected) + (C : Set V) (hC : (H.induce C).Connected) + (B : Fin k → Set V) (hB : ∀ i, (G.induce (B i)).Connected) + (hdisB : Pairwise (fun i j => Disjoint (B i) (B j))) + (hdisC : ∀ i, Disjoint C (B i)) + (hdom : ∀ i c, c ∈ C → ∃ z ∈ B i, dist c z ≤ R) : + ∀ u ∈ C, ∀ v ∈ C, dist u v ≤ (k : ℝ) * (2 * R + 2 * ε) := by + classical + intro u hu v hv + by_contra hle + have hfar : (k : ℝ) * (2 * R + 2 * ε) < dist u v := lt_of_not_ge hle + obtain ⟨p⟩ := hC ⟨u, hu⟩ ⟨v, hv⟩ + let a : ℝ := 2 * R + 2 * ε + have ha : 0 < a := by dsimp [a]; positivity + have hstep : ∀ x y : C, (H.induce C).Adj x y → dist u y.val ≤ dist u x.val + ε := by + intro x y hxy + have hm := hmesh x.val y.val hxy + have ht := dist_triangle u x.val y.val + linarith + have hex : ∀ i : Fin (k + 1), ∃ c : C, + (i.val : ℝ) * a ≤ dist u c.val ∧ dist u c.val ≤ (i.val : ℝ) * a + ε := by + intro i + have hstart : dist u (⟨u, hu⟩ : C).val ≤ (i.val : ℝ) * a := by + simp only [dist_self] + positivity + have hend : (i.val : ℝ) * a ≤ dist u (⟨v, hv⟩ : C).val := by + have hi : (i.val : ℝ) ≤ k := by exact_mod_cast (Nat.le_of_lt_succ i.isLt) + exact (mul_le_mul_of_nonneg_right hi ha.le).trans hfar.le + obtain ⟨c, _, hc⟩ := walk_crossing_window (H.induce C) (fun x : C => dist u x.val) + hε.le hstep p hstart hend + exact ⟨c, hc⟩ + choose c hclo hchi using hex + have hsep : ∀ i j : Fin (k + 1), i.val < j.val → 2 * R < dist (c i).val (c j).val := by + intro i j hij + have hijr : (i.val : ℝ) + 1 ≤ j.val := by exact_mod_cast (Nat.succ_le_iff.mpr hij) + have hm := mul_le_mul_of_nonneg_right hijr ha.le + have ht := dist_triangle u (c i).val (c j).val + have hlo := hclo j + have hhi := hchi i + dsimp [a] at * + nlinarith + let Y : Fin (k + 1) → Set V := fun i => {z | dist (c i).val z ≤ R} + have hY : ∀ i, (G.induce (Y i)).Connected := fun i => hballs _ + have hdisY : Pairwise (fun i j => Disjoint (Y i) (Y j)) := by + intro i j hij + apply Set.disjoint_left.mpr + intro z hzi hzj + have hnear : dist (c i).val (c j).val ≤ 2 * R := by + have ht := dist_triangle (c i).val z (c j).val + have hzj' : dist z (c j).val ≤ R := by simpa [Y, dist_comm] using hzj + change dist (c i).val z ≤ R at hzi + linarith + have hvne : i.val ≠ j.val := fun h => hij (Fin.ext h) + rcases lt_or_gt_of_ne hvne with hlt | hgt + · exact (hsep i j hlt).not_ge hnear + · exact (hsep j i hgt).not_ge (by simpa [dist_comm] using hnear) + let X : Option (Fin k) → Set V := fun i => i.elim C B + have hCG : (G.induce C).Connected := hC.mono (fun _ _ h => hHG h) + have hX : ∀ i, (G.induce (X i)).Connected := by + intro i + cases i with + | none => exact hCG + | some i => exact hB i + have hdisX : Pairwise (fun i j => Disjoint (X i) (X j)) := by + intro i j hij + cases i with + | none => + cases j with + | none => exact (hij rfl).elim + | some j => exact hdisC j + | some i => + cases j with + | none => exact (hdisC i).symm + | some j => exact hdisB (fun h => hij (congrArg some h)) + have hcross : ∀ i j, (X i ∩ Y j).Nonempty := by + intro i j + cases i with + | none => exact ⟨(c j).val, (c j).property, by simpa [Y] using hR⟩ + | some i => exact hdom i (c j).val (c j).property + obtain ⟨t, ht⟩ := tree_decomposition_crossbar G T bag hT hedge hocc X Y hX hY hdisX hdisY hcross + have ht' : k + 1 ≤ (bag t).card := by simpa using ht + have := hwidth t + omega + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.Annulus + +/-- The finite-round annulus decomposition has weak diameter bounded solely +by the width and scale. The metric here remains the original graph metric. -/ +theorem run_diameter {V I A : Type*} [Fintype V] [DecidableEq V] [MetricSpace V] + [Fintype I] (G H : SimpleGraph V) (hHG : H ≤ G) + (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + (hdist : ∀ u v, dist u v = distance G w u v) + (T : SimpleGraph I) (bag : I → Finset V) (k : ℕ) (hk : 1 ≤ k) + (hT : T.IsTree) + (hedge : ∀ u v, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) + (hocc : ∀ v, (T.induce {t | v ∈ bag t}).Connected) + (hwidth : ∀ t, (bag t).card ≤ k) + {R ε : ℝ} (hR : 0 < R) (hε : 0 < ε) + (hmesh : ∀ u v, H.Adj u v → w s(u,v) ≤ ε) + (hballs : ∀ c, (G.induce {z | dist c z ≤ R + ε}).Connected) + (offset : A → ℝ) (hoff0 : ∀ a, 0 ≤ offset a) (hoffR : ∀ a, offset a < R) + (σ : Fin k → A) (u v : V) (huv : (run w R offset k H σ).Reachable u v) : + dist u v ≤ (k : ℝ) * (2 * R + 4 * ε) := by + have hkr : (1 : ℝ) ≤ k := by exact_mod_cast hk + rcases run_component_alternative G w hw hR offset hoff0 hoffR k H hHG hmesh σ u with hsmall | hex + · have hs := hsmall u v .rfl huv + rw [hdist] + have hfac : 0 ≤ 2 * R + 4 * ε := by positivity + have hmul := mul_le_mul_of_nonneg_right hkr hfac + nlinarith + · obtain ⟨B⟩ := hex + let F := run w R offset k H σ + have hFH : F ≤ H := run_le w R offset k H σ + have hFG := hFH.trans hHG + let C : Set V := {z | F.Reachable u z} + have hC : (F.induce C).Connected := reachable_set_connected F u + have hCdis : ∀ i, Disjoint C (B.sets i) := by + intro i + apply Set.disjoint_left.mpr + intro z hzC hzB + exact B.outside i z hzB hzC + have hdom : ∀ i c, c ∈ C → ∃ z ∈ B.sets i, dist c z ≤ R + ε := by + intro i c hc + obtain ⟨z, hz, hnear⟩ := B.dominates i c hc + exact ⟨z, hz, by rwa [hdist]⟩ + have hFmesh : ∀ a b, F.Adj a b → dist a b ≤ ε := by + intro a b hab + rw [hdist] + exact (distance_edge G w hw (hFG hab)).trans (hmesh a b (hFH hab)) + have hb := connected_multidomination_diameter G F hFG T bag k hT hedge hocc hwidth + (add_nonneg hR.le hε.le) hε hFmesh hballs C hC B.sets B.connected B.separated hCdis hdom + u (.rfl) v huv + convert hb using 1 ; ring + +end BoundedTreewidthL1.Annulus + +namespace BoundedTreewidthL1.Annulus +variable {V : Type*} +lemma floor_ne_boundary {x y : ℝ} (hxy : x ≤ y) (hne : ⌊x⌋ ≠ ⌊y⌋) : + ∃ n : ℤ, x < n ∧ (n : ℝ) ≤ y := by + refine ⟨⌊x⌋ + 1, ?_, ?_⟩ + · simp + · have hle : ⌊x⌋ < ⌊y⌋ := lt_of_le_of_ne (Int.floor_mono hxy) hne + have hn : ⌊x⌋ + 1 ≤ ⌊y⌋ := by omega + exact (by exact_mod_cast hn : ((⌊x⌋ + 1 : ℤ) : ℝ) ≤ ⌊y⌋).trans (Int.floor_le y) + +/-- A random finite grid incurs at most one bad offset at any prescribed +height. No minimum positive edge length enters this count. -/ +theorem grid_bad_subsingleton (M : ℕ) (hM : 0 < M) (t β : ℝ) + (hβ : 0 ≤ β) (hsep : 2 * (M : ℝ) * β < 1) : + {j : Fin M | ⌊t + (j.val : ℝ) / M - β⌋ ≠ ⌊t + (j.val : ℝ) / M + β⌋}.Subsingleton := by + intro j hj l hl + obtain ⟨nj, hjlo, hjhi⟩ := floor_ne_boundary (by linarith) hj + obtain ⟨nl, hllo, hlhi⟩ := floor_ne_boundary (by linarith) hl + have hMr : (0 : ℝ) < M := by exact_mod_cast hM + let qj : ℤ := (M : ℤ) * nj - j.val + let ql : ℤ := (M : ℤ) * nl - l.val + have hjdiv : (j.val : ℝ) / M * M = j.val := div_mul_cancel₀ _ hMr.ne' + have hldiv : (l.val : ℝ) / M * M = l.val := div_mul_cancel₀ _ hMr.ne' + have hjlo' := mul_lt_mul_of_pos_right hjlo hMr + have hjhi' := mul_le_mul_of_nonneg_right hjhi hMr.le + have hllo' := mul_lt_mul_of_pos_right hllo hMr + have hlhi' := mul_le_mul_of_nonneg_right hlhi hMr.le + have hqjl : (qj : ℝ) < (ql : ℝ) + 1 := by + dsimp [qj, ql] + push_cast + nlinarith + have hqlj : (ql : ℝ) < (qj : ℝ) + 1 := by + dsimp [qj, ql] + push_cast + nlinarith + have hqjli : qj < ql + 1 := by exact_mod_cast hqjl + have hqlji : ql < qj + 1 := by exact_mod_cast hqlj + have hqeq : qj = ql := by omega + have hqeqr : (qj : ℝ) = ql := by exact_mod_cast hqeq + have hjlt : (j.val : ℝ) < M := by exact_mod_cast j.isLt + have hllt : (l.val : ℝ) < M := by exact_mod_cast l.isLt + have hjge : (0 : ℝ) ≤ j.val := by positivity + have hlge : (0 : ℝ) ≤ l.val := by positivity + have hneq : nj = nl := by + by_contra hn + rcases lt_or_gt_of_ne hn with hnlt | hngt + · have hnle : nj + 1 ≤ nl := by omega + have hnler : (nj : ℝ) + 1 ≤ nl := by exact_mod_cast hnle + dsimp [qj, ql] at hqeqr + push_cast at hqeqr + nlinarith + · have hnle : nl + 1 ≤ nj := by omega + have hnler : (nl : ℝ) + 1 ≤ nj := by exact_mod_cast hnle + dsimp [qj, ql] at hqeqr + push_cast at hqeqr + nlinarith + have hval : j.val = l.val := by + dsimp [qj, ql] at hqeq + rw [hneq] at hqeq + omega + exact Fin.ext hval + +lemma floor_eq_of_window {t s β : ℝ} (hlo : t - β ≤ s) (hhi : s ≤ t + β) + (hgood : ⌊t - β⌋ = ⌊t + β⌋) : ⌊s⌋ = ⌊t⌋ := by + have hβ : 0 ≤ β := by linarith + have h1 := Int.floor_mono hlo + have h2 := Int.floor_mono hhi + have h3 := Int.floor_mono (by linarith : t - β ≤ t) + have h4 := Int.floor_mono (by linarith : t ≤ t + β) + omega + +lemma walkLength_edge_le {H : SimpleGraph V} (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + {u v : V} (p : H.Walk u v) {e : Sym2 V} (he : e ∈ p.edges) : + w e ≤ walkLength H (weights H w) p := by + induction p with + | nil => simp at he + | @cons u v z h p ih => + simp only [SimpleGraph.Walk.edges_cons, List.mem_cons] at he + rcases he with rfl | he + · have hn := walkLength_nonneg H (weights H w) (fun e => hw e.val) p + change w s(u,v) ≤ w s(u,v) + _ + linarith + · have hle := ih he + have hn := hw s(u,v) + change w e ≤ w s(u,v) + _ + linarith + +noncomputable def smallEdges (G : SimpleGraph V) (w : Sym2 V → ℝ) (ε : ℝ) : SimpleGraph V where + Adj u v := G.Adj u v ∧ w s(u,v) ≤ ε + symm := ⟨fun u v h => ⟨h.1.symm, by simpa only [Sym2.eq_swap] using h.2⟩⟩ + loopless := ⟨fun _ h => G.irrefl h.1⟩ + +lemma smallEdges_le (G : SimpleGraph V) (w : Sym2 V → ℝ) (ε : ℝ) : smallEdges G w ε ≤ G := + fun _ _ h => h.1 + +lemma smallEdges_mesh (G : SimpleGraph V) (w : Sym2 V → ℝ) (ε : ℝ) : + ∀ u v, (smallEdges G w ε).Adj u v → w s(u,v) ≤ ε := fun _ _ h => h.2 + +lemma smallEdges_mem_iff (G : SimpleGraph V) (w : Sym2 V → ℝ) (ε : ℝ) (e : Sym2 V) : + e ∈ (smallEdges G w ε).edgeSet ↔ e ∈ G.edgeSet ∧ w e ≤ ε := by + induction e using Sym2.inductionOn with + | _ u v => rfl + +/-- The ball is preserved with its actual original shortest paths, not only +with unquantified reachability. This is the induction invariant for padding. -/ +def PreservesBall (G H : SimpleGraph V) (w : Sym2 V → ℝ) (ε : ℝ) (x : V) : Prop := + ∀ y, distance G w x y ≤ ε → + ∃ p : H.Walk x y, walkLength H (weights H w) p = distance G w x y + +lemma smallEdges_preserves [Fintype V] (G : SimpleGraph V) (w : Sym2 V → ℝ) + (hw : ∀ e, 0 ≤ w e) (hG : G.Connected) (ε : ℝ) (x : V) : + PreservesBall G (smallEdges G w ε) w ε x := by + intro y hy + obtain ⟨p, _, hp⟩ := shortestPathDistance_attained_of_reachable G (weights G w) (hG x y) + have hedges : ∀ e ∈ p.edges, e ∈ (smallEdges G w ε).edgeSet := by + intro e he + rw [smallEdges_mem_iff] + refine ⟨p.edges_subset_edgeSet he, ?_⟩ + exact (walkLength_edge_le w hw p he).trans (hp ▸ hy) + exact ⟨p.transfer _ hedges, (walkLength_transfer w p hedges).trans hp⟩ + +lemma walk_height_window [Fintype V] [DecidableEq V] + (H : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + {x y z : V} (p : H.Walk x y) (hz : z ∈ p.support) {ε : ℝ} + (hp : walkLength H (weights H w) p ≤ ε) : + height H w x - ε ≤ height H w z ∧ height H w z ≤ height H w x + ε := by + let q := p.takeUntil z hz + have hq : walkLength H (weights H w) q ≤ ε := + (walkLength_takeUntil_le H (weights H w) (fun e => hw e.val) p hz).trans hp + have hd : distance H w x z ≤ ε := + (shortestPathDistance_le_walkLength H (weights H w) (fun e => hw e.val) q).trans hq + have hds : distance H w z x ≤ ε := by + have heq := walkLength_reverse H (weights H w) q + exact (shortestPathDistance_le_walkLength H (weights H w) (fun e => hw e.val) q.reverse).trans + (heq ▸ hq) + have h1 := height_le_add_distance H w hw q.reachable + have h2 := height_le_add_distance H w hw q.reachable.symm + constructor <;> linarith + +lemma band_eq_of_height_window (H : SimpleGraph V) (w : Sym2 V → ℝ) + {R ε a : ℝ} (hR : 0 < R) (hε : 0 ≤ ε) {x z : V} + (hlo : height H w x - ε ≤ height H w z) + (hhi : height H w z ≤ height H w x + ε) + (hgood : ⌊(height H w x + a - ε) / R⌋ = ⌊(height H w x + a + ε) / R⌋) : + band H w R a z = band H w R a x := by + have hzlo := Int.floor_mono (div_le_div_of_nonneg_right (by linarith : + height H w x + a - ε ≤ height H w z + a) hR.le) + have hzhi := Int.floor_mono (div_le_div_of_nonneg_right (by linarith : + height H w z + a ≤ height H w x + a + ε) hR.le) + have hxlo := Int.floor_mono (div_le_div_of_nonneg_right (by linarith : + height H w x + a - ε ≤ height H w x + a) hR.le) + have hxhi := Int.floor_mono (div_le_div_of_nonneg_right (by linarith : + height H w x + a ≤ height H w x + a + ε) hR.le) + unfold band + omega + +lemma preservesBall_cut [Fintype V] [DecidableEq V] + (G H : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + {R ε a : ℝ} (hR : 0 < R) (hε : 0 ≤ ε) (x : V) + (hpres : PreservesBall G H w ε x) + (hgood : ⌊(height H w x + a - ε) / R⌋ = ⌊(height H w x + a + ε) / R⌋) : + PreservesBall G (cut H w R a) w ε x := by + intro y hy + obtain ⟨p, hp⟩ := hpres y hy + have hlen : walkLength H (weights H w) p ≤ ε := hp ▸ hy + have hband : ∀ z ∈ p.support, band H w R a z = band H w R a x := by + intro z hz + obtain ⟨hlo, hhi⟩ := walk_height_window H w hw p hz hlen + exact band_eq_of_height_window H w hR hε hlo hhi hgood + have hedges : ∀ e ∈ p.edges, e ∈ (cut H w R a).edgeSet := by + intro e + induction e using Sym2.inductionOn with + | _ u v => + intro he + exact ⟨p.edges_subset_edgeSet he, + (hband u (p.fst_mem_support_of_mem_edges he)).trans + (hband v (p.snd_mem_support_of_mem_edges he)).symm⟩ + exact ⟨p.transfer _ hedges, (walkLength_transfer w p hedges).trans hp⟩ + +noncomputable def gridOffset (M : ℕ) (R : ℝ) (a : Fin M) : ℝ := R * ((a.val : ℝ) / M) + +lemma gridOffset_nonneg {M : ℕ} {R : ℝ} (hR : 0 ≤ R) (a : Fin M) : + 0 ≤ gridOffset M R a := by unfold gridOffset; positivity + +lemma gridOffset_lt {M : ℕ} {R : ℝ} (hR : 0 < R) (a : Fin M) : + gridOffset M R a < R := by + have hM : (0 : ℝ) < M := by exact_mod_cast (Nat.zero_lt_of_lt a.isLt) + have ha : (a.val : ℝ) < M := by exact_mod_cast a.isLt + have haf : (a.val : ℝ) / M < 1 := by rwa [div_lt_one hM] + exact (mul_lt_mul_of_pos_left haf hR).trans_eq (mul_one R) + +lemma grid_window_eq {M : ℕ} {R ε t : ℝ} (hR : 0 < R) (a : Fin M) : + (⌊(t + gridOffset M R a - ε) / R⌋ = ⌊(t + gridOffset M R a + ε) / R⌋) ↔ + (⌊t / R + (a.val : ℝ) / M - ε / R⌋ = ⌊t / R + (a.val : ℝ) / M + ε / R⌋) := by + have hcancel : gridOffset M R a / R = (a.val : ℝ) / M := by + dsimp [gridOffset] + exact mul_div_cancel_left₀ _ hR.ne' + simp only [sub_div, add_div, hcancel] + +end BoundedTreewidthL1.Annulus + +/-! Finite adaptive random iteration. No independence assumptions on an +intermediate state: every fresh coordinate is independently enumerated. -/ +namespace FiniteRandomIteration + +variable {S : Type*} {A : Type*} + +def run (step : S → A → S) : (n : ℕ) → S → (Fin n → A) → S + | 0, s, _ => s + | n + 1, s, σ => run step n (step s (σ 0)) (Fin.tail σ) + +noncomputable def count [Fintype A] (step : S → A → S) (P : S → Prop) + (n : ℕ) (s : S) : ℝ := by + classical + exact ∑ σ : Fin n → A, if P (run step n s σ) then 1 else 0 + +lemma count_nonneg [Fintype A] (step : S → A → S) (P : S → Prop) + (n : ℕ) (s : S) : 0 ≤ count step P n s := by + classical + exact Finset.sum_nonneg fun σ _ => by split <;> norm_num + +lemma count_succ [Fintype A] (step : S → A → S) (P : S → Prop) + (n : ℕ) (s : S) : + count step P (n+1) s = ∑ a : A, count step P n (step s a) := by + classical + unfold count + rw [← (Fin.consEquiv (fun _ : Fin (n+1) => A)).sum_comp] + rw [Fintype.sum_prod_type] + congr 1 + +lemma count_lower [Fintype A] [Nonempty A] + (step : S → A → S) (P : S → Prop) + (hbad : ∀ s, P s → {a : A | ¬ P (step s a)}.Subsingleton) + (n : ℕ) (s : S) (hs : P s) : + ((Fintype.card A : ℝ) - 1)^n ≤ count step P n s := by + classical + have hc : (0 : ℝ) ≤ Fintype.card A - 1 := by + have h : (1 : ℝ) ≤ Fintype.card A := by exact_mod_cast Fintype.card_pos (α := A) + linarith + induction n generalizing s with + | zero => simp [count, run, hs] + | succ n ih => + rw [count_succ] + have hgood : (Fintype.card A : ℝ) - 1 ≤ + ∑ a : A, if P (step s a) then (1 : ℝ) else 0 := by + rw [Finset.sum_boole] + have hb : (Finset.univ.filter fun a : A => ¬ P (step s a)).card ≤ 1 := by + rw [Finset.card_le_one_iff] + intro a b ha hb + exact hbad s hs (Finset.mem_filter.mp ha).2 (Finset.mem_filter.mp hb).2 + have heq := Finset.card_filter_add_card_filter_not (s := Finset.univ) (p := fun a : A => P (step s a)) + have hcard : Fintype.card A ≤ (Finset.univ.filter fun a => P (step s a)).card + 1 := by + simp only [Finset.card_univ] at heq + omega + have hcR : (Fintype.card A : ℝ) ≤ (Finset.univ.filter fun a => P (step s a)).card + 1 := by exact_mod_cast hcard + linarith + calc + ((Fintype.card A : ℝ) - 1)^(n+1) = + ((Fintype.card A : ℝ) - 1) * ((Fintype.card A : ℝ) - 1)^n := by rw [pow_succ']; + _ ≤ (∑ a : A, if P (step s a) then (1 : ℝ) else 0) * + ((Fintype.card A : ℝ) - 1)^n := mul_le_mul_of_nonneg_right hgood (pow_nonneg hc n) + _ = ∑ a : A, if P (step s a) then ((Fintype.card A : ℝ) - 1)^n else 0 := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro a _ + split <;> simp + _ ≤ ∑ a : A, count step P n (step s a) := by + apply Finset.sum_le_sum + intro a _ + split_ifs with ha + · exact ih (step s a) ha + · exact count_nonneg step P n (step s a) + +lemma fraction_lower [Fintype A] [Nonempty A] + (step : S → A → S) (P : S → Prop) + (hbad : ∀ s, P s → {a : A | ¬ P (step s a)}.Subsingleton) + (n : ℕ) (s : S) (hs : P s) : + 1 - (n : ℝ) / Fintype.card A ≤ + count step P n s / (Fintype.card A : ℝ)^n := by + have hM : (0 : ℝ) < Fintype.card A := by exact_mod_cast Fintype.card_pos (α := A) + have hM1 : (1 : ℝ) ≤ Fintype.card A := by exact_mod_cast Fintype.card_pos (α := A) + have ha : (-2 : ℝ) ≤ -(1 / (Fintype.card A : ℝ)) := by + have hh : 1 / (Fintype.card A : ℝ) ≤ 1 := (div_le_one hM).mpr hM1 + linarith + have hbern := one_add_mul_le_pow ha n + calc + 1 - (n : ℝ) / Fintype.card A ≤ (1 - 1 / (Fintype.card A : ℝ))^n := by + simpa only [sub_eq_add_neg, mul_neg, mul_one_div] using hbern + _ = (((Fintype.card A : ℝ) - 1)^n) / (Fintype.card A : ℝ)^n := by + rw [← div_pow] + congr 1 + field_simp + _ ≤ count step P n s / (Fintype.card A : ℝ)^n := + div_le_div_of_nonneg_right (count_lower step P hbad n s hs) (pow_nonneg hM.le n) + +end FiniteRandomIteration + +namespace BoundedTreewidthL1.Annulus +variable {V A : Type*} + +lemma run_eq_iteration (w : Sym2 V → ℝ) (R : ℝ) (offset : A → ℝ) + (n : ℕ) (H : SimpleGraph V) (σ : Fin n → A) : + run w R offset n H σ = + FiniteRandomIteration.run (fun H a => cut H w R (offset a)) n H σ := by + induction n generalizing H with + | zero => rfl + | succ n ih => exact ih _ _ + +lemma preserves_bad_subsingleton [Fintype V] [DecidableEq V] + (G H : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + (M : ℕ) (hM : 0 < M) {R ε : ℝ} (hR : 0 < R) (hε : 0 ≤ ε) + (hsep : 2 * (M : ℝ) * (ε / R) < 1) (x : V) + (hpres : PreservesBall G H w ε x) : + {a : Fin M | ¬ PreservesBall G (cut H w R (gridOffset M R a)) w ε x}.Subsingleton := by + have hgrid := grid_bad_subsingleton M hM (height H w x / R) (ε / R) + (div_nonneg hε hR.le) hsep + have hbadfloor : ∀ a : Fin M, ¬ PreservesBall G (cut H w R (gridOffset M R a)) w ε x → + ⌊height H w x / R + (a.val : ℝ) / M - ε / R⌋ ≠ + ⌊height H w x / R + (a.val : ℝ) / M + ε / R⌋ := by + intro a ha hg + exact ha (preservesBall_cut G H w hw hR hε x hpres ((grid_window_eq hR a).mpr hg)) + intro a ha b hb + exact hgrid (hbadfloor a ha) (hbadfloor b hb) + +attribute [local instance] Classical.propDecidable +lemma preserves_fraction [Fintype V] [DecidableEq V] + (G : SimpleGraph V) (w : Sym2 V → ℝ) (hw : ∀ e, 0 ≤ w e) + (hG : G.Connected) (M : ℕ) (hM : 0 < M) {R ε : ℝ} + (hR : 0 < R) (hε : 0 ≤ ε) (hsep : 2 * (M : ℝ) * (ε / R) < 1) + (n : ℕ) (x : V) : + 1 - (n : ℝ) / M ≤ + (∑ σ : Fin n → Fin M, + if PreservesBall G (run w R (gridOffset M R) n (smallEdges G w ε) σ) w ε x + then (1 : ℝ) else 0) / (M : ℝ)^n := by + classical + let : Nonempty (Fin M) := ⟨⟨0, hM⟩⟩ + have hh := FiniteRandomIteration.fraction_lower (fun H a => cut H w R (gridOffset M R a)) + (fun H => PreservesBall G H w ε x) + (fun H hp => preserves_bad_subsingleton G H w hw M hM hR hε hsep x hp) + n (smallEdges G w ε) (smallEdges_preserves G w hw hG ε x) + simpa only [FiniteRandomIteration.count, ← run_eq_iteration, Fintype.card_fin] using hh + +end BoundedTreewidthL1.Annulus + +namespace FiniteLawPush +attribute [local instance] Classical.propDecidable +variable {Ω B : Type*} [Fintype Ω] [Fintype B] + +noncomputable def law (f : Ω → B) (b : B) : ℝ := by + classical + exact ∑ ω, if f ω = b then 1 / Fintype.card Ω else 0 + +lemma nonneg + {Ω : Type treewidthLevel1} {B : Type treewidthLevel2} [Fintype Ω] [Fintype B] + (f : Ω → B) (b : B) : 0 ≤ law f b := by + classical + exact Finset.sum_nonneg fun ω _ => by split <;> positivity + +lemma total [Nonempty Ω] (f : Ω → B) : (∑ b, law f b) = 1 := by + classical + unfold law + rw [Finset.sum_comm] + simp only [Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte, Finset.sum_const, + Finset.card_univ, nsmul_eq_mul] + exact mul_one_div_cancel (by exact_mod_cast Fintype.card_ne_zero (α := Ω)) + +lemma supported + {Ω : Type treewidthLevel1} {B : Type treewidthLevel2} [Fintype Ω] [Fintype B] + (f : Ω → B) (b : B) (hb : 0 < law f b) : ∃ ω, f ω = b := by + classical + by_contra! hh + have hz : law f b = 0 := by simp [law, hh] + linarith + +lemma event (f : Ω → B) (Q : B → Prop) : + (∑ b, if Q b then law f b else 0) = + (∑ ω, if Q (f ω) then (1 : ℝ) else 0) / Fintype.card Ω := by + classical + unfold law + calc + (∑ b, if Q b then (∑ ω, if f ω = b then 1 / (Fintype.card Ω : ℝ) else 0) else 0) = + ∑ b, ∑ ω, if f ω = b then (if Q b then 1 / (Fintype.card Ω : ℝ) else 0) else 0 := by + apply Finset.sum_congr rfl + intro b _ + by_cases hb : Q b <;> simp [hb] + _ = ∑ ω, ∑ b, if f ω = b then (if Q b then 1 / (Fintype.card Ω : ℝ) else 0) else 0 := Finset.sum_comm + _ = (∑ ω, if Q (f ω) then (1 : ℝ) else 0) / Fintype.card Ω := by + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + simp only [Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte] + split <;> simp_all +end FiniteLawPush + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/BagLabels.lean b/lean/OAI/Combinatorics/TreewidthL1/BagLabels.lean new file mode 100644 index 0000000000000000000000000000000000000000..0eeee2c67bc707b481d2c1f2faeb9ef0971300af --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/BagLabels.lean @@ -0,0 +1,557 @@ +import OAI.Combinatorics.TreewidthL1.TreeMarkov + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1.BagLabels +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I : Type*} [Fintype V] [Fintype I] +abbrev Local (B : I → Set V) := (i : I) → B i → Bool +noncomputable def assemble (B : I → Set V) (hcover : ∀ v, ∃ i, v ∈ B i) + (x : Local B) : V → Bool := fun v => + x (Classical.choose (hcover v)) ⟨v,Classical.choose_spec (hcover v)⟩ +noncomputable def restrict (B : I → Set V) (ω : V → Bool) : Local B := + fun _ v => ω v +noncomputable def globalMass (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (μ : (i : I) → (B i → Bool) → ℝ) + (R : (i j : I) → (B i → Bool) → (B j → Bool) → ℝ) + (hs : TreeMarkov.Symmetric (fun i => B i → Bool) R) (ω : V → Bool) : ℝ := + ∑ x : Local B, if assemble B hcover x = ω then TreeMarkov.density + (fun i => B i → Bool) T μ R hs x else 0 + +lemma coherent_equal + {V : Type treewidthLevel1} {I : Type treewidthLevel2} [Fintype V] [Fintype I] + (T : SimpleGraph I) (B : I → Set V) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) (x : Local B) + (hx : ∀ i j, T.Adj i j → ∀ v hi hj, x i ⟨v,hi⟩ = x j ⟨v,hj⟩) + (i j : I) (v : V) (hi : v ∈ B i) (hj : v ∈ B j) : + x i ⟨v,hi⟩ = x j ⟨v,hj⟩ := by + obtain ⟨p⟩ := hrun v ⟨i,hi⟩ ⟨j,hj⟩ + let val : {i | v ∈ B i} → Bool := fun a => x a ⟨v,a.2⟩ + change val ⟨i,hi⟩ = val ⟨j,hj⟩ + have he : ∀ {a b : {i | v ∈ B i}} (q : (T.induce {i | v ∈ B i}).Walk a b), val a = val b := by + intro a b q + induction q with + | nil => rfl + | @cons a b c hab q ih => + exact (hx a b hab v a.2 b.2).trans ih + exact he p + +lemma assemble_on_support (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (μ : (i : I) → (B i → Bool) → ℝ) + (R : (i j : I) → (B i → Bool) → (B j → Bool) → ℝ) + (hs : TreeMarkov.Symmetric (fun i => B i → Bool) R) + (hcomp : ∀ i j, T.Adj i j → ∀ a b, R i j a b ≠ 0 → + ∀ v hi hj, a ⟨v,hi⟩ = b ⟨v,hj⟩) + (x : Local B) (hx : TreeMarkov.density (fun i => B i → Bool) T μ R hs x ≠ 0) : + restrict B (assemble B hcover x) = x := by + have he : ∀ i j, T.Adj i j → R i j (x i) (x j) ≠ 0 := by + intro i j hij + have hprod := (mul_ne_zero_iff.mp hx).2 + have hmem : s(i,j) ∈ T.edgeFinset := by simpa using hij + exact Finset.prod_ne_zero_iff.mp hprod _ hmem + have hco : ∀ i j, T.Adj i j → ∀ v hi hj, x i ⟨v,hi⟩ = x j ⟨v,hj⟩ := + fun i j hij => hcomp i j hij (x i) (x j) (he i j hij) + funext i v + exact coherent_equal T B hrun x hco _ i v _ v.2 + +lemma expectation_global (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (μ : (i : I) → (B i → Bool) → ℝ) + (R : (i j : I) → (B i → Bool) → (B j → Bool) → ℝ) + (hs : TreeMarkov.Symmetric (fun i => B i → Bool) R) (f : (V → Bool) → ℝ) : + (∑ ω : V → Bool, globalMass T B hcover μ R hs ω * f ω) = + ∑ x : Local B, TreeMarkov.density (fun i => B i → Bool) T μ R hs x * + f (assemble B hcover x) := by + simp only [globalMass, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x hx + simp only [ite_mul,zero_mul] + simp + +lemma expectation_local (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (μ : (i : I) → (B i → Bool) → ℝ) + (R : (i j : I) → (B i → Bool) → (B j → Bool) → ℝ) + (hs : TreeMarkov.Symmetric (fun i => B i → Bool) R) + (hcomp : ∀ i j, T.Adj i j → ∀ a b, R i j a b ≠ 0 → + ∀ v hi hj, a ⟨v,hi⟩ = b ⟨v,hj⟩) (f : Local B → ℝ) : + (∑ ω : V → Bool, globalMass T B hcover μ R hs ω * f (restrict B ω)) = + ∑ x : Local B, TreeMarkov.density (fun i => B i → Bool) T μ R hs x * f x := by + rw [expectation_global] + apply Finset.sum_congr rfl + intro x hx + by_cases hz : TreeMarkov.density (fun i => B i → Bool) T μ R hs x = 0 + · simp [hz] + · rw [assemble_on_support T B hcover hrun μ R hs hcomp x hz] + +/-- The canonical junction law is a genuine measure on global vertex labels, +with exact connected-subtree marginals. Compatibility is enforced by the local +edge support, never assumed for independently sampled bag states. -/ +theorem global_bag_law (T : SimpleGraph I) (hT : T.IsTree) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (μ : (i : I) → (B i → Bool) → ℝ) + (R : (i j : I) → (B i → Bool) → (B j → Bool) → ℝ) + (hs : TreeMarkov.Symmetric (fun i => B i → Bool) R) + (hn : TreeMarkov.Normalized (fun i => B i → Bool) T μ R) + (hcomp : ∀ i j, T.Adj i j → ∀ a b, R i j a b ≠ 0 → + ∀ v hi hj, a ⟨v,hi⟩ = b ⟨v,hj⟩) : + let ρ := globalMass T B hcover μ R hs + (∀ ω, 0 ≤ ρ ω) ∧ (∑ ω, ρ ω) = 1 ∧ + (∀ i a, (∑ ω : V → Bool, if restrict B ω i = a then ρ ω else 0) = μ i a) ∧ + ∀ {K : Type*} [Fintype K] (e : K ↪ I), (T.comap e).Connected → + ∀ (f : ((j : K) → B (e j) → Bool) → ℝ), + (∑ ω : V → Bool, ρ ω * f (fun j => restrict B ω (e j))) = + ∑ x, TreeMarkov.density (fun j => B (e j) → Bool) (T.comap e) + (fun j => μ (e j)) (fun j k => R (e j) (e k)) + (fun j k => hs (e j) (e k)) x * f x := by + dsimp only + obtain ⟨hnon,hprob,hmarg⟩ := TreeMarkov.tree_density (fun i => B i → Bool) T hT μ R hs hn + refine ⟨?_,?_,?_,?_⟩ + · intro ω + apply Finset.sum_nonneg + intro x hx + split_ifs + · exact hnon x + · exact le_rfl + · have he := expectation_global T B hcover μ R hs (fun _ => 1) + simpa using he.trans (by simpa using hprob) + · intro i a + have he := expectation_local T B hcover hrun μ R hs hcomp + (fun x => if x i = a then 1 else 0) + simp only [mul_ite,mul_one,mul_zero] at he + apply he.trans + convert hmarg i a using 1 + apply Finset.sum_congr rfl + intro x hx + split_ifs <;> rfl + · intro K _ e hc f + exact (expectation_local T B hcover hrun μ R hs hcomp + (fun x => f (fun j => x (e j)))).trans + (TreeMarkov.expectation_comap (fun i => B i → Bool) T hT μ R hs hn e hc f) +end BoundedTreewidthL1.BagLabels + +namespace BoundedTreewidthL1 + +/-- Pushforward mass at a point, for a finite real nonnegative measure. -/ +noncomputable def marginal {A C : Type*} [Fintype A] + (f : A → C) (μ : A → ℝ) (c : C) : ℝ := by + classical + exact ∑ a, if f a = c then μ a else 0 + +/-- The two-part conditional product, with zero denominator interpreted as zero. +Only compatible pairs receive mass. -/ +noncomputable def glueWeights {A B C : Type*} [Fintype A] + (f : A → C) (g : B → C) (μ : A → ℝ) (ν : B → ℝ) (a : A) (b : B) : ℝ := by + classical + exact if f a = g b then μ a * ν b / marginal f μ (f a) else 0 + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 + +lemma marginal_nonneg {A C : Type*} [Fintype A] + (f : A → C) (μ : A → ℝ) (hμ : ∀ a, 0 ≤ μ a) (c : C) : + 0 ≤ marginal f μ c := by + classical + exact Finset.sum_nonneg (fun a _ => by split_ifs <;> simp_all) + +lemma le_marginal {A C : Type*} [Fintype A] + (f : A → C) (μ : A → ℝ) (hμ : ∀ a, 0 ≤ μ a) (a : A) : + μ a ≤ marginal f μ (f a) := by + classical + unfold marginal + have := Finset.single_le_sum + (s := Finset.univ) (f := fun b => if f b = f a then μ b else 0) + (fun b _ => by split_ifs <;> simp_all) (Finset.mem_univ a) + simpa using this + +lemma weight_eq_zero_of_marginal_eq_zero {A C : Type*} [Fintype A] + (f : A → C) (μ : A → ℝ) (hμ : ∀ a, 0 ≤ μ a) (a : A) + (hzero : marginal f μ (f a) = 0) : μ a = 0 := by + have := le_marginal f μ hμ a + exact le_antisymm (hzero ▸ this) (hμ a) + +lemma glueWeights_nonneg {A B C : Type*} [Fintype A] + (f : A → C) (g : B → C) (μ : A → ℝ) (ν : B → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hν : ∀ b, 0 ≤ ν b) (a : A) (b : B) : + 0 ≤ glueWeights f g μ ν a b := by + classical + unfold glueWeights + split_ifs + · exact div_nonneg (mul_nonneg (hμ a) (hν b)) (marginal_nonneg f μ hμ _) + · exact le_rfl + +lemma glueWeights_row {A B C : Type*} [Fintype A] [Fintype B] + (f : A → C) (g : B → C) (μ : A → ℝ) (ν : B → ℝ) + (hμ : ∀ a, 0 ≤ μ a) + (hconsistent : ∀ c, marginal f μ c = marginal g ν c) (a : A) : + (∑ b, glueWeights f g μ ν a b) = μ a := by + classical + have hform : (∑ b, glueWeights f g μ ν a b) = + μ a * marginal g ν (f a) / marginal f μ (f a) := by + simp only [marginal, Finset.mul_sum, Finset.sum_div] + apply Finset.sum_congr rfl + intro b _ + unfold glueWeights marginal + by_cases h : f a = g b + · simp only [h, ↓reduceIte] + · simp [h, Ne.symm h] + rw [hform, ← hconsistent] + by_cases h : marginal f μ (f a) = 0 + · rw [h, weight_eq_zero_of_marginal_eq_zero f μ hμ a h] + simp + · exact mul_div_cancel_right₀ (μ a) h + +lemma glueWeights_swap {A B C : Type*} [Fintype A] [Fintype B] + (f : A → C) (g : B → C) (μ : A → ℝ) (ν : B → ℝ) + (hconsistent : ∀ c, marginal f μ c = marginal g ν c) (a : A) (b : B) : + glueWeights f g μ ν a b = glueWeights g f ν μ b a := by + classical + unfold glueWeights + by_cases h : f a = g b + · simp [h, ← hconsistent, mul_comm] + · simp [h, Ne.symm h] + +theorem glueWeights_marginals {A B C : Type*} [Fintype A] [Fintype B] + (f : A → C) (g : B → C) (μ : A → ℝ) (ν : B → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hν : ∀ b, 0 ≤ ν b) + (hconsistent : ∀ c, marginal f μ c = marginal g ν c) : + (∀ a b, 0 ≤ glueWeights f g μ ν a b) ∧ + (∀ a, (∑ b, glueWeights f g μ ν a b) = μ a) ∧ + (∀ b, (∑ a, glueWeights f g μ ν a b) = ν b) := by + refine ⟨glueWeights_nonneg f g μ ν hμ hν, glueWeights_row f g μ ν hμ hconsistent, ?_⟩ + intro b + simp_rw [glueWeights_swap f g μ ν hconsistent] + exact glueWeights_row g f ν μ hν (fun c => (hconsistent c).symm) b + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.BagLabels +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I : Type*} [Fintype V] [Fintype I] +noncomputable def leftTrace (B : I → Set V) (i j : I) (a : B i → Bool) : ↥(B i ∩ B j) → Bool := + fun v => a ⟨v,v.2.1⟩ +noncomputable def rightTrace (B : I → Set V) (i j : I) (b : B j → Bool) : ↥(B i ∩ B j) → Bool := + fun v => b ⟨v,v.2.2⟩ +noncomputable def pairMass (T : SimpleGraph I) (B : I → Set V) + (μ : (i : I) → (B i → Bool) → ℝ) (i j : I) (a : B i → Bool) (b : B j → Bool) : ℝ := + if T.Adj i j then glueWeights (leftTrace B i j) (rightTrace B i j) (μ i) (μ j) a b else 0 + +lemma glueWeights_map {A B C D : Type*} [Fintype A] + (f : A → C) (g : B → C) (E : C → D) (hE : Function.Injective E) + (μ : A → ℝ) (ν : B → ℝ) (a : A) (b : B) : + glueWeights (E ∘ f) (E ∘ g) μ ν a b = glueWeights f g μ ν a b := by + simp [glueWeights,marginal,hE.eq_iff] + +noncomputable def overlapSwap (B : I → Set V) (i j : I) : + (↥(B i ∩ B j) → Bool) ≃ (↥(B j ∩ B i) → Bool) where + toFun f v := f ⟨v,⟨v.2.2,v.2.1⟩⟩ + invFun f v := f ⟨v,⟨v.2.2,v.2.1⟩⟩ + left_inv _ := rfl + right_inv _ := rfl + +lemma pairMass_symmetric + {V : Type treewidthLevel1} {I : Type treewidthLevel2} [Fintype V] [Fintype I] + (T : SimpleGraph I) (B : I → Set V) + (μ : (i : I) → (B i → Bool) → ℝ) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (μ i) c = marginal (rightTrace B i j) (μ j) c) : + TreeMarkov.Symmetric (fun i => B i → Bool) (pairMass T B μ) := by + intro i j a b + by_cases hij : T.Adj i j + · simp only [pairMass,hij,T.adj_symm hij,↓reduceIte] + rw [glueWeights_swap _ _ _ _ (hcons i j hij)] + exact (glueWeights_map (rightTrace B i j) (leftTrace B i j) + (overlapSwap B i j) (overlapSwap B i j).injective (μ j) (μ i) b a).symm + · have hji : ¬T.Adj j i := fun h => hij h.symm + simp [pairMass,hij,hji] + +lemma pairMass_row + {V : Type treewidthLevel1} {I : Type treewidthLevel2} [Fintype V] [Fintype I] + (T : SimpleGraph I) (B : I → Set V) + (μ : (i : I) → (B i → Bool) → ℝ) (hμ : ∀ i a, 0 ≤ μ i a) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (μ i) c = marginal (rightTrace B i j) (μ j) c) + (i j : I) (hij : T.Adj i j) (a : B i → Bool) : + (∑ b, pairMass T B μ i j a b) = μ i a := by + simp only [pairMass,hij,↓reduceIte] + exact glueWeights_row _ _ _ _ (hμ i) (hcons i j hij) a + +theorem bag_couplings (T : SimpleGraph I) (B : I → Set V) + (μ : (i : I) → (B i → Bool) → ℝ) + (hμ : ∀ i a, 0 ≤ μ i a) (hμ₁ : ∀ i, (∑ a, μ i a) = 1) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (μ i) c = marginal (rightTrace B i j) (μ j) c) : + let R := TreeMarkov.interaction (fun i => B i → Bool) μ (pairMass T B μ) + ∃ _ : TreeMarkov.Symmetric (fun i => B i → Bool) R, + TreeMarkov.Normalized (fun i => B i → Bool) T μ R ∧ + ∀ i j, T.Adj i j → ∀ a b, R i j a b ≠ 0 → + ∀ v hi hj, a ⟨v,hi⟩ = b ⟨v,hj⟩ := by + dsimp only + have hs := pairMass_symmetric T B μ hcons + have hJ : ∀ i j, T.Adj i j → ∀ a b, 0 ≤ pairMass T B μ i j a b := by + intro i j hij a b + simp only [pairMass,hij,↓reduceIte] + exact glueWeights_nonneg _ _ _ _ (hμ i) (hμ j) a b + refine ⟨TreeMarkov.interaction_symmetric (fun i => B i → Bool) μ _ hs, + TreeMarkov.interaction_normalized (fun i => B i → Bool) T μ _ hμ hμ₁ hs hJ + (pairMass_row T B μ hμ hcons),?_⟩ + intro i j hij a b hn v hi hj + have he : leftTrace B i j a = rightTrace B i j b := by + by_contra he + apply hn + simp [TreeMarkov.interaction,pairMass,hij,glueWeights,he] + exact congrFun he ⟨v,hi,hj⟩ +end BoundedTreewidthL1.BagLabels + +namespace BoundedTreewidthL1.BagLabels +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I : Type*} [Fintype V] [Fintype I] + +def flip (A : Type*) : (A → Bool) ≃ (A → Bool) where + toFun x := fun a => !(x a) + invFun x := fun a => !(x a) + left_inv x := by funext a; simp + right_inv x := by funext a; simp + +noncomputable def flipLocal (B : I → Set V) : Local B ≃ Local B where + toFun x := fun i => flip (B i) (x i) + invFun x := fun i => flip (B i) (x i) + left_inv x := by funext i v; simp [flip] + right_inv x := by funext i v; simp [flip] + +lemma marginal_equivariant {A C : Type*} [Fintype A] + (e : A ≃ A) (d : C ≃ C) (f : A → C) (μ : A → ℝ) + (hμ : ∀ a, μ (e a) = μ a) (hf : ∀ a, f (e a) = d (f a)) (c : C) : + marginal f μ (d c) = marginal f μ c := by + unfold marginal + rw [← e.sum_comp] + apply Finset.sum_congr rfl + intro a ha + simp only [hf, hμ, d.injective.eq_iff] + +lemma pairMass_flip + {V : Type treewidthLevel1} {I : Type treewidthLevel2} [Fintype V] [Fintype I] + (T : SimpleGraph I) (B : I → Set V) + (μ : (i : I) → (B i → Bool) → ℝ) + (hflip : ∀ i a, μ i (flip (B i) a) = μ i a) + (i j : I) (a : B i → Bool) (b : B j → Bool) : + pairMass T B μ i j (flip (B i) a) (flip (B j) b) = pairMass T B μ i j a b := by + have hl : ∀ a, leftTrace B i j (flip (B i) a) = flip ↥(B i ∩ B j) (leftTrace B i j a) := fun _ => rfl + have hr : rightTrace B i j (flip (B j) b) = flip ↥(B i ∩ B j) (rightTrace B i j b) := rfl + simp only [pairMass, glueWeights, hl, hr, (flip ↥(B i ∩ B j)).injective.eq_iff, hflip, + marginal_equivariant (flip (B i)) (flip ↥(B i ∩ B j)) (leftTrace B i j) (μ i) (hflip i) hl] + split_ifs <;> rfl + +lemma density_flip (T : SimpleGraph I) (B : I → Set V) + (μ : (i : I) → (B i → Bool) → ℝ) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (μ i) c = marginal (rightTrace B i j) (μ j) c) + (hflip : ∀ i a, μ i (flip (B i) a) = μ i a) (x : Local B) : + let R := TreeMarkov.interaction (fun i => B i → Bool) μ (pairMass T B μ) + let hs := TreeMarkov.interaction_symmetric (fun i => B i → Bool) μ _ + (pairMass_symmetric T B μ hcons) + TreeMarkov.density (fun i => B i → Bool) T μ R hs (flipLocal B x) = + TreeMarkov.density (fun i => B i → Bool) T μ R hs x := by + dsimp only + unfold TreeMarkov.density + congr 1 + · apply Finset.prod_congr rfl + intro i hi + exact hflip i (x i) + · apply Finset.prod_congr rfl + intro e he + induction e using Sym2.ind with + | _ i j => + change pairMass T B μ i j (flip (B i) (x i)) (flip (B j) (x j)) / + (μ i (flip (B i) (x i)) * μ j (flip (B j) (x j))) = + pairMass T B μ i j (x i) (x j) / (μ i (x i) * μ j (x j)) + rw [pairMass_flip T B μ hflip, hflip, hflip] + +theorem canonical_symmetric (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (μ : (i : I) → (B i → Bool) → ℝ) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (μ i) c = marginal (rightTrace B i j) (μ j) c) + (hflip : ∀ i a, μ i (flip (B i) a) = μ i a) : + let R := TreeMarkov.interaction (fun i => B i → Bool) μ (pairMass T B μ) + let hs := TreeMarkov.interaction_symmetric (fun i => B i → Bool) μ _ + (pairMass_symmetric T B μ hcons) + ∀ ω, globalMass T B hcover μ R hs (flip V ω) = + globalMass T B hcover μ R hs ω := by + dsimp only + intro ω + unfold globalMass + rw [← (flipLocal B).sum_comp] + apply Finset.sum_congr rfl + intro x hx + have he : assemble B hcover (flipLocal B x) = flip V (assemble B hcover x) := rfl + simp only [he, (flip V).injective.eq_iff, density_flip T B μ hcons hflip] +end BoundedTreewidthL1.BagLabels + +namespace BoundedTreewidthL1 + +noncomputable def cutDistance {V ι : Type*} [Fintype ι] + (w : ι → ℝ) (cut : ι → V → Bool) (u v : V) : ℝ := + ∑ a, if cut a u = cut a v then 0 else w a + +/-- The coordinate function of a vertex in the finite weighted cut space. -/ +noncomputable def finiteCutMap {V ι : Type*} (w : ι → ℝ) + (cut : ι → V → Bool) (v : V) : PiLp (1 : ENNReal) (fun _ : ι => ℝ) := + WithLp.toLp 1 (fun a => if cut a v then w a else 0) + +lemma finiteCutMap_norm_sub {V ι : Type*} [Fintype ι] + (w : ι → ℝ) (cut : ι → V → Bool) (hw : ∀ a, 0 ≤ w a) (u v : V) : + ‖finiteCutMap w cut u - finiteCutMap w cut v‖ = cutDistance w cut u v := by + rw [PiLp.norm_eq_of_L1] + unfold cutDistance + apply Finset.sum_congr rfl + intro a _ + simp only [PiLp.sub_apply, finiteCutMap, Real.norm_eq_abs] + cases hcu : cut a u <;> cases hcv : cut a v <;> simp [hw a, abs_of_nonneg, abs_neg] + +theorem finite_cut_realization {V ι : Type*} [Fintype ι] + (w : ι → ℝ) (cut : ι → V → Bool) (hw : ∀ a, 0 ≤ w a) : + ∃ m : ℕ, ∃ F : V → PiLp (1 : ENNReal) (fun _ : Fin m => ℝ), + ∀ u v, ‖F u - F v‖ = cutDistance w cut u v := by + let e := LinearIsometryEquiv.piLpCongrLeft (1 : ENNReal) ℝ ℝ (Fintype.equivFin ι) + refine ⟨Fintype.card ι, fun v => e (finiteCutMap w cut v), ?_⟩ + intro u v + rw [← e.map_sub, e.norm_map] + exact finiteCutMap_norm_sub w cut hw u v + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.BagLabels +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I : Type*} [Fintype V] [Fintype I] + +lemma marginal_div {A C : Type*} [Fintype A] + (f : A → C) (μ : A → ℝ) (m : ℝ) (c : C) : + marginal f (fun a => μ a / m) c = marginal f μ c / m := by + unfold marginal + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro a ha + split_ifs <;> simp + +lemma marginal_mul {A C : Type*} [Fintype A] + (f : A → C) (μ : A → ℝ) (m : ℝ) (c : C) : + marginal f (fun a => m * μ a) c = m * marginal f μ c := by + unfold marginal + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + split_ifs <;> simp + +lemma global_path (T : SimpleGraph I) (hT : T.IsTree) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (μ : (i : I) → (B i → Bool) → ℝ) + (R : (i j : I) → (B i → Bool) → (B j → Bool) → ℝ) + (hs : TreeMarkov.Symmetric (fun i => B i → Bool) R) + (hn : TreeMarkov.Normalized (fun i => B i → Bool) T μ R) + (hcomp : ∀ i j, T.Adj i j → ∀ a b, R i j a b ≠ 0 → + ∀ v hi hj, a ⟨v,hi⟩ = b ⟨v,hj⟩) + (r : ℕ) (e : Fin (r+1) ↪ I) (he : T.comap e = SimpleGraph.pathGraph (r+1)) : + MarkovFlow.IsMarkovLaw (fun j => B (e j) → Bool) + (marginal (fun ω j => restrict B ω (e j)) (globalMass T B hcover μ R hs)) := by + have hc : (T.comap e).Connected := he ▸ SimpleGraph.pathGraph_connected r + have hsub := (global_bag_law T hT B hcover hrun μ R hs hn hcomp).2.2.2 e hc + have hd : marginal (fun ω j => restrict B ω (e j)) (globalMass T B hcover μ R hs) = + TreeMarkov.density (fun j => B (e j) → Bool) (T.comap e) + (fun j => μ (e j)) (fun j k => R (e j) (e k)) (fun j k => hs (e j) (e k)) := by + funext x + have hh := hsub (fun y => if y = x then 1 else 0) + simp only [mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, + ↓reduceIte] at hh + apply Eq.trans ?_ hh + unfold marginal + apply Finset.sum_congr rfl + intro ω hω + split_ifs <;> rfl + rw [hd] + have hn' : TreeMarkov.Normalized (fun j => B (e j) → Bool) (T.comap e) + (fun j => μ (e j)) (fun j k => R (e j) (e k)) := by + exact ⟨fun j => hn.1 (e j), fun j => hn.2.1 (e j), + fun j k h => hn.2.2.1 (e j) (e k) h, + fun j k h => hn.2.2.2 (e j) (e k) h⟩ + rw [he] at hn' ⊢ + exact TreeMarkov.path_markov _ _ _ _ hn' + +/-- Exact common-positive-mass gluing and genuine finite real L1 realization, +from the actual local bag masses. The path assertion concerns full bag states; +separator-only projection is a further required transport obligation. -/ +theorem canonical_gluing (T : SimpleGraph I) (hT : T.IsTree) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (μ : (i : I) → (B i → Bool) → ℝ) (m : ℝ) (hm : 0 < m) + (hμ : ∀ i a, 0 ≤ μ i a) (hmass : ∀ i, (∑ a, μ i a) = m) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (μ i) c = marginal (rightTrace B i j) (μ j) c) + (hflip : ∀ i a, μ i (flip (B i) a) = μ i a) : + ∃ ρ : (V → Bool) → ℝ, + (∀ ω, 0 ≤ ρ ω) ∧ (∑ ω, ρ ω) = m ∧ + (∀ ω, ρ (flip V ω) = ρ ω) ∧ + (∀ i a, marginal (fun ω => restrict B ω i) ρ a = μ i a) ∧ + (∀ (r : ℕ) (e : Fin (r+1) ↪ I), T.comap e = SimpleGraph.pathGraph (r+1) → + MarkovFlow.IsMarkovLaw (fun j => B (e j) → Bool) + (marginal (fun ω j => restrict B ω (e j)) (fun ω => ρ ω / m))) ∧ + ∃ n : ℕ, ∃ F : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + ∀ u v, ‖F u - F v‖ = cutDistance ρ (fun ω => ω) u v := by + let p : (i : I) → (B i → Bool) → ℝ := fun i a => μ i a / m + have hp : ∀ i a, 0 ≤ p i a := fun i a => div_nonneg (hμ i a) hm.le + have hp₁ : ∀ i, (∑ a, p i a) = 1 := by + intro i + simp only [p,← Finset.sum_div,hmass,div_self hm.ne'] + have hpcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (p i) c = marginal (rightTrace B i j) (p j) c := by + intro i j h c + dsimp only [p] + rw [marginal_div,marginal_div,hcons i j h] + have hpflip : ∀ i a, p i (flip (B i) a) = p i a := by + intro i a + dsimp only [p] + rw [hflip] + let R := TreeMarkov.interaction (fun i => B i → Bool) p (pairMass T B p) + let hs := TreeMarkov.interaction_symmetric (fun i => B i → Bool) p _ + (pairMass_symmetric T B p hpcons) + obtain ⟨hs',hn,hcomp⟩ := bag_couplings T B p hp hp₁ hpcons + let q := globalMass T B hcover p R hs + obtain ⟨hq,hq₁,hqmarg,hqsub⟩ := global_bag_law.{_,_,0} T hT B hcover hrun p R hs hn hcomp + have hqflip : ∀ ω, q (flip V ω) = q ω := canonical_symmetric T B hcover p hpcons hpflip + let ρ := fun ω => m * q ω + have hρ : ∀ ω, 0 ≤ ρ ω := fun ω => mul_nonneg hm.le (hq ω) + refine ⟨ρ,hρ,?_,?_,?_,?_,finite_cut_realization ρ (fun ω => ω) hρ⟩ + · change (∑ ω, m * q ω) = m + rw [← Finset.mul_sum,hq₁,mul_one] + · intro ω + exact congrArg (m * ·) (hqflip ω) + · intro i a + change marginal _ (fun ω => m * q ω) a = _ + rw [marginal_mul] + have hh : marginal (fun ω => restrict B ω i) q a = p i a := by + apply Eq.trans ?_ (hqmarg i a) + unfold marginal + apply Finset.sum_congr rfl + intro ω hω + split_ifs <;> rfl + rw [hh] + exact mul_div_cancel₀ (μ i a) hm.ne' + · intro r e he + have hscale : (fun ω => ρ ω / m) = q := by + funext ω + exact mul_div_cancel_left₀ (q ω) hm.ne' + rw [hscale] + exact global_path T hT B hcover hrun p R hs hn hcomp r e he +end BoundedTreewidthL1.BagLabels + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/CacheControl.lean b/lean/OAI/Combinatorics/TreewidthL1/CacheControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..b102da83fcbf6cc8ba2a85cc96c3e3e968c18a88 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/CacheControl.lean @@ -0,0 +1,196 @@ +import OAI.Combinatorics.TreewidthL1.YoungestCrossing + +namespace OAI + +namespace BoundedTreewidthL1 +open AnchorCache +attribute [local instance] Classical.decEq Classical.propDecidable +theorem near_far_scaled {V : Type*} [MetricSpace V] + (B : Finset V) (x p v₀ : V) (h φ : V → ℝ) + (δ D R a : ℝ) (hδ : 0 < δ) (hδD : δ ≤ D) + (hp : dist x p = δ) (hv : v₀ ∈ B) + (hnear : ∀ s ∈ B, δ ≤ dist x s) + (hh : ∀ u v, |h u - h v| ≤ dist u v) + (hheight : h x = D) (hgeo : h v₀ + dist x v₀ = D) + (hhnonneg : 0 ≤ h v₀) + (hno : ∀ q ∈ B, ¬(δ/4 ≤ dist p q ∧ dist p q ≤ 10*D)) + (hR : R < 9*D) (ha : 0 < a) (hφx : a ≤ φ x) + (hφ : ∀ s, R < dist x s → φ s = 0) : + ∀ s ∈ B, δ/2 ≤ |h x-h s| ∨ a ≤ |φ x-φ s| := by + have hvdist : dist p v₀ ≤ 2*D := by + have ht := dist_triangle p x v₀ + rw [dist_comm p x, hp] at ht + linarith + have hvclose : dist p v₀ < δ/4 := by + by_contra hn + exact hno v₀ hv ⟨le_of_not_gt hn, by linarith⟩ + intro s hs + by_cases hsclose : dist p s < δ/4 + · left + have hvs : dist v₀ s < δ/2 := by + have ht := dist_triangle v₀ p s + rw [dist_comm v₀ p] at ht + linarith + have hhvs := (abs_le.mp (hh v₀ s)).1 + have hmin := hnear v₀ hv + have hgap : δ/2 ≤ h x - h s := by rw [hheight]; linarith + exact hgap.trans (le_abs_self _) + · right + have hfar : 10*D < dist p s := by + by_contra hn + exact hno s hs ⟨le_of_not_gt hsclose, le_of_not_gt hn⟩ + have hxs : R < dist x s := by + have ht := dist_triangle p x s + rw [dist_comm p x, hp] at ht + linarith + rw [hφ s hxs, sub_zero, abs_of_nonneg (ha.le.trans hφx)] + exact hφx + +lemma protected_threshold_scaled (K J H D₀ δ A L older younger : ℝ) + (hK : 2 < K) (hJ : J = 10*(K+1)) (hH : 10^5*J < H) + (hA : 0 < A) (hD : H*A < D₀) (hδ : 0 < δ) (_ : δ ≤ A) + (hLlo : δ/4 ≤ L) (hLhi : L ≤ 10*D₀) + (hyδ : younger ≤ K*δ) (hy2 : younger ≤ 2*A) (holder : D₀-A ≤ older) : + ∃ τ ∈ ({L/100,J*L} : Set ℝ), younger ≤ τ ∧ τ < older := by + have hJpos : 0 < J := by linarith + have hHA : 10^5*J*A < H*A := mul_lt_mul_of_pos_right hH hA + by_cases hL : L ≤ 300*A + · refine ⟨J*L,by simp,?_,?_⟩ + · have hmul := mul_le_mul_of_nonneg_left hLlo hJpos.le + have hgap : K*δ < J*(δ/4) := by rw [hJ]; nlinarith + exact hyδ.trans (hgap.le.trans hmul) + · have hmul := mul_le_mul_of_nonneg_left hL hJpos.le + have hJA : 30*A < J*A := mul_lt_mul_of_pos_right (by linarith) hA + norm_num at hHA + nlinarith + · refine ⟨L/100,by simp,by linarith,?_⟩ + have hJA : 30*A < J*A := mul_lt_mul_of_pos_right (by linarith) hA + norm_num at hHA + nlinarith + +lemma protected_of_successor {V : Type*} [DecidableEq V] + (R : ReservationPath) (B : Finset V) (D : V → ℕ → ℝ) (d : V → V → ℝ) (J : ℝ) + (t a b : ℕ) (ht : t ≤ R.last) (hab : R.Successor a b t) + (p q : V) (hp : p ∈ B) (hq : q ∈ B) (hpq : p ≠ q) + (hw : ∃ τ ∈ ({d p q/100,J*d p q} : Set ℝ), D p b ≤ τ ∧ τ < D p a) : + b ∈ protectedEntries B (R.inclusive t) d D J := by + classical + obtain ⟨τ,hτ,hlo,hhi⟩ := hw + have hd : Drop (R.inclusive t) (D p) τ b := by + refine ⟨(R.mem_inclusive ht).mpr hab.2.1,hlo,a,(R.mem_inclusive ht).mpr hab.1,hab.2.2.1,hhi,?_⟩ + intro c hc hac + exact hab.2.2.2 c ((R.mem_inclusive ht).mp hc) hac + apply Finset.mem_biUnion.mpr + refine ⟨(p,q),Finset.mem_product.mpr ⟨hp,hq⟩,?_⟩ + simp only [ite_eq_right hpq] + simp only [Set.mem_insert_iff,Set.mem_singleton_iff] at hτ + rcases hτ with rfl | rfl + · exact Finset.mem_biUnion.mpr ⟨false,Finset.mem_univ _,Finset.mem_filter.mpr ⟨hd.1,hd⟩⟩ + · exact Finset.mem_biUnion.mpr ⟨true,Finset.mem_univ _,Finset.mem_filter.mpr ⟨hd.1,hd⟩⟩ + +/-- Physical, unnormalized data for a single actual root-to-endpoint cache. +The probabilistic tests are discharged from the constructed ensemble below. -/ +structure GeometricTrack (V : Type*) [MetricSpace V] (N : ℕ) (U J H Q : ℝ) where + path : ReservationPath + start : ℕ + start_le : start ≤ path.last + delta : ℕ → ℝ + antitone : Antitone delta + nonneg : ∀ t, 0 ≤ delta t + start_pos : 0 < delta start + end_zero : delta path.last = 0 + error : ℝ + error_nonneg : 0 ≤ error + size : ∀ t, (path.inclusive t).card ≤ N + B : ℕ → Finset V + D : ℕ → V → ℝ + x : V + at_x : ∀ t, D t x = delta t + lipschitz : ∀ a u v, |D a u-D a v| ≤ dist u v + launch : ∀ a e, e ≤ path.last → a ∈ path.inclusive e → start ≤ a → + delta a ≤ error+(U+1)*delta e + small : ∀ a e, e ≤ path.last → a ∈ path.inclusive e → a < start → + delta a ≤ H*delta start → delta start ≤ Q*(error+delta e) + obstruction : ∀ a e t, e ≤ path.last → a ∈ path.inclusive e → a < start → + start ≤ t → t < e → Q*(error+delta e) < delta t → + ∃ p ∈ B t, ∃ q ∈ B t, dist x p = delta t ∧ delta t/4 ≤ dist p q ∧ dist p q ≤ 10*delta a + protect_rule : ∀ t, t < path.last → ∀ b ∈ protectedEntries (B t) (path.inclusive t) dist + (fun p a => D a p) J, t < path.finish b + +namespace GeometricTrack +variable {V : Type*} [MetricSpace V] {N : ℕ} {U J H Q : ℝ} + (P : GeometricTrack V N U J H Q) + +lemma successor_protected (hU : 0 ≤ U) (hJ : J = 10*(U+4)) (hH : 10^5*J < H) (hQ : U+1 ≤ Q) + (a e t b : ℕ) (he : e ≤ P.path.last) (ha : a ∈ P.path.inclusive e) (has : a < P.start) + (hDa : H*P.delta P.start < P.delta a) (hst : P.start ≤ t) (hte : t < e) + (hsb : P.start ≤ b) (hab : P.path.Successor a b t) + (hgap : Q*(P.error+P.delta e) < P.delta t) : t < P.path.finish b := by + classical + have hQ1 : 1 ≤ Q := by linarith + have hQ0 : 0 < Q := by linarith + have hδ : 0 < P.delta t := lt_of_le_of_lt (mul_nonneg hQ0.le (add_nonneg P.error_nonneg (P.nonneg e))) hgap + have hE : P.error < P.delta t := by + have h1 := mul_le_mul_of_nonneg_right hQ1 (add_nonneg P.error_nonneg (P.nonneg e)) + nlinarith [P.nonneg e] + obtain ⟨p,hp,q,hq,hxp,hLlo,hLhi⟩ := P.obstruction a e t he ha has hst hte hgap + have hδA : P.delta t ≤ P.delta P.start := P.antitone hst + have hdb : P.delta b ≤ P.delta P.start := P.antitone hsb + have hbt : b ∈ P.path.inclusive t := (P.path.mem_inclusive (hte.le.trans he)).mpr hab.2.1 + have hl := P.launch b t (hte.le.trans he) hbt hsb + have hbp := P.lipschitz b P.x p + have hap := P.lipschitz a P.x p + rw [P.at_x,hxp] at hbp hap + have hbp' := (abs_le.mp hbp).1 + have hap' := (abs_le.mp hap).2 + have hyδ : P.D b p ≤ (U+3)*P.delta t := by nlinarith + have hyA : P.D b p ≤ 2*P.delta P.start := by linarith + have haA : P.delta a-P.delta P.start ≤ P.D a p := by linarith + have hw := protected_threshold_scaled (U+3) J H (P.delta a) (P.delta t) (P.delta P.start) + (dist p q) (P.D a p) (P.D b p) (by linarith) (by linarith) hH + P.start_pos hDa hδ hδA hLlo hLhi hyδ hyA haA + apply P.protect_rule t (hte.trans_le he) b + apply protected_of_successor P.path (P.B t) (fun p a => P.D a p) dist J t a b + (hte.le.trans he) hab p q hp hq _ hw + intro heq; subst q; rw [dist_self] at hLlo; linarith + +noncomputable def control (hU : 0 ≤ U) (hJ : J = 10*(U+4)) (hH : 10^5*J < H) (hQ : U+1 ≤ Q) : + CacheControl N Q H where + path := P.path + start := P.start + start_le := P.start_le + delta := fun t => P.delta t/P.delta P.start + antitone := fun _ _ h => div_le_div_of_nonneg_right (P.antitone h) P.start_pos.le + nonneg := fun t => div_nonneg (P.nonneg t) P.start_pos.le + at_start := div_self P.start_pos.ne' + at_end := by rw [P.end_zero,zero_div] + error := P.error/P.delta P.start + error_nonneg := div_nonneg P.error_nonneg P.start_pos.le + size := P.size + launch := by + intro a e he ha hs + have hh := P.launch a e he ha hs + have hq1 : 1 ≤ Q := by linarith + have hb : P.error+(U+1)*P.delta e ≤ Q*(P.error+P.delta e) := by + nlinarith [mul_nonneg (sub_nonneg.mpr hq1) P.error_nonneg, + mul_nonneg (sub_nonneg.mpr hQ) (P.nonneg e)] + have hd := div_le_div_of_nonneg_right (hh.trans hb) P.start_pos.le + simpa only [mul_div_assoc,add_div] using hd + distant := by + intro a e he ha hs hd + have hd' : P.delta a ≤ H*P.delta P.start := (div_le_iff₀ P.start_pos).mp hd + have hh := div_le_div_of_nonneg_right (P.small a e he ha hs hd') P.start_pos.le + rw [div_self P.start_pos.ne'] at hh + simpa only [mul_div_assoc,add_div] using hh + protect := by + intro a e t b he ha hs hd hst hte hsb hab hgap + have hd' : H*P.delta P.start < P.delta a := (lt_div_iff₀ P.start_pos).mp hd + have hg : Q*(P.error+P.delta e) < P.delta t := by + apply (div_lt_div_iff_of_pos_right P.start_pos).mp + simpa only [mul_div_assoc,add_div] using hgap + exact P.successor_protected hU hJ hH hQ a e t b he ha hs hd' hst hte hsb hab hg + +end GeometricTrack +end BoundedTreewidthL1 + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/CachedEnsemble.lean b/lean/OAI/Combinatorics/TreewidthL1/CachedEnsemble.lean new file mode 100644 index 0000000000000000000000000000000000000000..555fb1cffa91f4edbff53b9c0dab26ec8a8d4e6a --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/CachedEnsemble.lean @@ -0,0 +1,342 @@ +import OAI.Combinatorics.TreewidthL1.NoiseCube + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 + +namespace BoundedTreewidthL1.TreeCache +open _root_.OAI.BoundedTreewidthL1.RootedTree AnchorCache ParticleBatch +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V ι : Type*} [Fintype ι] [Nonempty ι] (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (X : I) + (S : I → (ι → V → ℝ) × (I → ι × ι)) + (hpairs : ∀ i p, (forest T hT root).parent i = some p → + ∀ a ∈ active T hT root B D k d J i ∩ active T hT root B D k d J p, + (S i).2 a = (S p).2 a ∧ + (S i).1 ((S i).2 a).1 = (S p).1 ((S p).2 a).1 ∧ + (S i).1 ((S i).2 a).2 = (S p).1 ((S p).2 a).2) +lemma index_transport + {I : Type treewidthLevel1} {V : Type treewidthLevel2} {ι : Type treewidthLevel3} [Fintype ι] + [Nonempty ι] (T : SimpleGraph I) (hT : T.IsTree) (root : I) (B : I → Finset V) (D : I → V → ℝ) + (k : ℕ) (d : V → V → ℝ) (J : ℝ) (X : I) (S : I → (ι → V → ℝ) × (I → ι × ι)) + (hpairs : ∀ (i p : I), (BoundedTreewidthL1.RootedTree.forest T hT root).parent i = some p → ∀ a + ∈ BoundedTreewidthL1.TreeCache.active T hT root B D k d J i ∩ + BoundedTreewidthL1.TreeCache.active T hT root B D k d J p, (S i).2 a = (S p).2 a ∧ (S i).1 ((S + i).2 a).1 = (S p).1 ((S p).2 a).1 ∧ (S i).1 ((S i).2 a).2 = (S p).1 ((S p).2 a).2) + (e a b : ℕ) (he : e ≤ (forest T hT root).depth X) + (ha : a ∈ inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J e) + (hab : a ≤ b) (hbe : b ≤ e) (u : Bool) : + let v := (downPath T hT root X).getVert + pairIndex (S (v b)).2 (v a) u = pairIndex (S (v a)).2 (v a) u ∧ + (S (v b)).1 (pairIndex (S (v a)).2 (v a) u) = (S (v a)).1 (pairIndex (S (v a)).2 (v a) u) := by + dsimp only + obtain ⟨h₁,h₂,h₃⟩ := pair_transport T hT root B D k d J X S hpairs e a b he ha hab hbe + constructor + · simp only [pairIndex,h₁] + · cases u + · simpa only [pairIndex,Bool.false_eq_true,ite_false,h₁] using h₂ + · simpa only [pairIndex,ite_true,h₁] using h₃ +include hpairs +lemma index_retained (e a b : ℕ) (he : e ≤ (forest T hT root).depth X) + (ha : a ∈ inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J e) + (hab : a ≤ b) (hbe : b < e) (u : Bool) : + let v := (downPath T hT root X).getVert + pairIndex (S (v a)).2 (v a) u ∈ usedPairs + (AnchorTreeParticles.retained (forest T hT root) (active T hT root B D k d J) (v (b+1))) (S (v (b+1))).2 := by + dsimp only + rw [← (index_transport T hT root B D k d J X S hpairs e a (b+1) he ha (by omega) (by omega) u).1] + apply pairIndex_mem + rw [AnchorTreeParticles.retained,parent_getVert T hT root X b (by omega)] + exact Finset.mem_inter.mpr ⟨active_on_path T hT root B D k d J X e a (b+1) he ha (by omega) (by omega), + active_on_path T hT root B D k d J X e a b he ha hab hbe.le⟩ +lemma index_avoids (huniq : ∀ i, PairUnique (active T hT root B D k d J i) (S i).2) + (e a b : ℕ) (he : e ≤ (forest T hT root).depth X) + (ha : a ∈ inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J e) + (hab : a < b) (hbe : b ≤ e) (u w : Bool) : + let v := (downPath T hT root X).getVert + pairIndex (S (v a)).2 (v a) u ≠ pairIndex (S (v b)).2 (v b) w := by + dsimp only + rw [← (index_transport T hT root B D k d J X S hpairs e a b he ha hab.le hbe u).1] + intro hh + have hn := (huniq _ _ (active_on_path T hT root B D k d J X e a b he ha hab.le hbe) + _ (active_self T hT root B D k d J _) u w hh).1 + exact path_ne T hT root X a b (by omega) (by omega) (by omega) hn +end BoundedTreewidthL1.TreeCache + +namespace BoundedTreewidthL1.CachedEnsemble +open _root_.OAI.BoundedTreewidthL1.RootedTree TreeCache AnchorCache ParticleBatch ExpandedConstruction +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V ι : Type*} [Fintype I] [Fintype V] [Fintype ι] [Nonempty ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + (T : SimpleGraph I) (hT : T.IsTree) (root : I) (B : I → Finset V) + (cover : ∀ v, ∃ i, v ∈ B i) (run : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) + (S : I → (ι → V → ℝ) × (I → ι × ι)) (M : ℝ) + (hpairs : ∀ i p, (forest T hT root).parent i = some p → + ∀ a ∈ active T hT root B D k d J i ∩ active T hT root B D k d J p, + (S i).2 a = (S p).2 a ∧ + (S i).1 ((S i).2 a).1 = (S p).1 ((S p).2 a).1 ∧ + (S i).1 ((S i).2 a).2 = (S p).1 ((S p).2 a).2) + (htrace : ∀ i p, (forest T hT root).parent i = some p → + particleTrace M (S i).1 (B i) = particleTrace M (S p).1 (B i)) +noncomputable def data : TreeData (V := V) (ι := ι) T M where + parent := (forest T hT root).parent + orient := fun _ _ h => edge_orientation T hT root h + anti := ExpandedAnchor.parent_antisymm (forest T hT root) + F := fun i => (S i).1 + B := B + cover := cover + run := run + fresh₁ := fun i => ((S i).2 i).1 + fresh₂ := fun i => ((S i).2 i).2 + C := fun i => usedPairs (AnchorTreeParticles.retained (forest T hT root) (active T hT root B D k d J) i) (S i).2 + retained := ExpandedAnchor.retained_functions _ _ S hpairs + trace := fun _ _ hi => (htrace _ _ hi).symm + +include hpairs htrace +lemma height (hM : 0 < M) + (huniq : ∀ i, PairUnique (active T hT root B D k d J i) (S i).2) + (X Y : I) (y z : V) (hy : y ∈ B Y) (s e l a t : ℕ) + (he : e ≤ (forest T hT root).depth X) (hst : s ≤ t) (hte : t < e) (hat : a < t) + (ha : a ∈ inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J e) + (hz : z ∈ B ((downPath T hT root X).getVert e)) + (hlen : (forest T hT Y).depth ((downPath T hT root X).getVert e) = l+(e-s)) + (hpath : ∀ b, s ≤ b → b ≤ e → + (downPath T hT Y ((downPath T hT root X).getVert e)).getVert (l+(b-s)) = (downPath T hT root X).getVert b) + (u : Bool) (ε : ℝ) + (hF : ∀ v, |(S ((downPath T hT root X).getVert a)).1 + (pairIndex (S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a) u) v| ≤ M) + (hlo : ε ≤ (S ((downPath T hT root X).getVert a)).1 + (pairIndex (S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a) u) z+M) + (hhi : ε ≤ M-(S ((downPath T hT root X).getVert a)).1 + (pairIndex (S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a) u) z) + (hgap : ∀ x ∈ B ((downPath T hT root X).getVert t), ε ≤ + |(S ((downPath T hT root X).getVert a)).1 + (pairIndex (S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a) u) z- + (S ((downPath T hT root X).getVert a)).1 + (pairIndex (S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a) u) x|) : + ε/2 ≤ (data T hT root B cover run D k d J S M hpairs htrace).dist y z := by + let v := (downPath T hT root X).getVert + let r := pairIndex (S (v a)).2 (v a) u + have hf (b : ℕ) (hab : a ≤ b) (hbe : b ≤ e) : (S (v b)).1 r = (S (v a)).1 r := + (index_transport T hT root B D k d J X S hpairs e a b he ha hab hbe u).2 + refine (data T hT root B cover run D k d J S M hpairs htrace).height_segment hT hM Fintype.card_pos + Y (v e) y z hy hz v s e l t hst hte hlen hpath ?_ r ?_ ?_ ?_ ε ?_ ?_ ?_ + · intro b htb hbe + exact parent_getVert T hT root X b (by omega) + · intro b htb hbe + exact (hf b (by omega) hbe).trans (hf t hat.le hte.le).symm + · intro b htb hbe + refine ⟨index_retained T hT root B D k d J X S hpairs e a b he ha (by omega) hbe u, ?_, ?_⟩ + · exact index_avoids T hT root B D k d J X S hpairs huniq e a b he ha (by omega) hbe.le u false + · exact index_avoids T hT root B D k d J X S hpairs huniq e a b he ha (by omega) hbe.le u true + · change ∀ x, -M ≤ (S (v t)).1 r x ∧ (S (v t)).1 r x ≤ M + rw [hf t hat.le hte.le]; exact fun x => abs_le.mp (hF x) + · change ε ≤ (S (v t)).1 r z+M + rw [hf t hat.le hte.le]; exact hlo + · change ε ≤ M-(S (v t)).1 r z + rw [hf t hat.le hte.le]; exact hhi + · change ∀ x ∈ B (v t), ε ≤ |(S (v t)).1 r z-(S (v t)).1 r x| + rw [hf t hat.le hte.le]; exact hgap + +lemma launch (hM : 0 < M) + (huniq : ∀ i, PairUnique (active T hT root B D k d J i) (S i).2) + (X Y : I) (y z : V) (hy : y ∈ B Y) (s e l a : ℕ) + (he : e ≤ (forest T hT root).depth X) (hsa : s ≤ a) (hae : a < e) + (ha : a ∈ inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J e) + (hz : z ∈ B ((downPath T hT root X).getVert e)) + (hlen : (forest T hT Y).depth ((downPath T hT root X).getVert e) = l+(e-s)) + (hpath : ∀ b, s ≤ b → b ≤ e → + (downPath T hT Y ((downPath T hT root X).getVert e)).getVert (l+(b-s)) = (downPath T hT root X).getVert b) + (hbag : ∀ x ∈ B ((downPath T hT root X).getVert a), + (S ((downPath T hT root X).getVert a)).1 ((S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a)).1 x = + (S ((downPath T hT root X).getVert a)).1 ((S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a)).2 x) + (hF : ∀ i r x, |(S i).1 r x| ≤ M) : + |(S ((downPath T hT root X).getVert a)).1 ((S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a)).1 z- + (S ((downPath T hT root X).getVert a)).1 ((S ((downPath T hT root X).getVert a)).2 ((downPath T hT root X).getVert a)).2 z|/2 ≤ + (data T hT root B cover run D k d J S M hpairs htrace).dist y z := by + let v := (downPath T hT root X).getVert + have hiu : ((S (v a)).2 (v a)).1 ≠ ((S (v a)).2 (v a)).2 := by + intro hh + have hb := (huniq (v a) _ (active_self T hT root B D k d J _) _ + (active_self T hT root B D k d J _) false true hh).2 + cases hb + have hr (r : ι) (hr : r ∈ ({((S (v a)).2 (v a)).1,((S (v a)).2 (v a)).2} : Finset ι)) : + ∃ u, r = pairIndex (S (v a)).2 (v a) u := by + simp only [Finset.mem_insert,Finset.mem_singleton] at hr + rcases hr with rfl | rfl + · exact ⟨false,rfl⟩ + · exact ⟨true,rfl⟩ + apply (data T hT root B cover run D k d J S M hpairs htrace).launch_segment hT hM Fintype.card_pos + Y (v e) y z hy hz v s e l a hsa hae hlen hpath + · intro b hab hbe; exact parent_getVert T hT root X b (by omega) + · exact hiu + · exact hbag + · intro r hmem b hab hbe + obtain ⟨u,rfl⟩ := hr r hmem + exact (index_transport T hT root B D k d J X S hpairs e a b he ha hab hbe u).2 + · exact ⟨index_retained T hT root B D k d J X S hpairs e a a he ha le_rfl hae false, + index_retained T hT root B D k d J X S hpairs e a a he ha le_rfl hae true⟩ + · intro r hmem b hab hbe + obtain ⟨u,rfl⟩ := hr r hmem + exact ⟨index_retained T hT root B D k d J X S hpairs e a b he ha (by omega) hbe u, + index_avoids T hT root B D k d J X S hpairs huniq e a b he ha (by omega) hbe.le u false, + index_avoids T hT root B D k d J X S hpairs huniq e a b he ha (by omega) hbe.le u true⟩ + · intro r _ x; exact abs_le.mp (hF _ r x) +end BoundedTreewidthL1.CachedEnsemble + +namespace BoundedTreewidthL1.NoiseCube +open MeasureTheory Set LaunchNoise +open scoped unitInterval ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +lemma OrdinarySeed.good_location {V : Type*} [MetricSpace V] {h : V → ℝ} {α π η : ℝ} + (seed : OrdinarySeed h α π η) (x : V) (hx : 0 < h x) : + ENNReal.ofReal (π/2) ≤ locationLaw seed.mass {a | GoodBump h α η (seed.bump a) x} := by + have hh := seed.good x hx + have he := Measure.map_apply (μ := noiseLaw seed.m seed.mass) + (measurable_fst.comp measurable_snd) (MeasurableSet.of_discrete (s := {a | GoodBump h α η (seed.bump a) x})) + change (Measure.map (fun ω : NoiseSpace seed.n seed.m => ω.2.1) (noiseLaw seed.m seed.mass)) _ = _ at he + rw [noise_locationLaw] at he + exact he.symm ▸ hh + +lemma node_gap {V : Type*} [MetricSpace V] [Fintype V] {n : ℕ} + (h : Fin (n+1) → V → ℝ) (α π η : ℝ) + (seed : (i : Fin (n+1)) → OrdinarySeed (h i) α π η) + (a : Fin (n+1)) (x : V) (B : Finset V) + (F : ((i : Fin (n+1)) → NoiseSpace (seed i).n (seed i).m) → V → ℝ) + (hF : ∀ v, Measurable (fun ω => F ω v)) + (haff : ∀ rest : (j : Fin n) → NoiseSpace (seed (a.succAbove j)).n (seed (a.succAbove j)).m, + ∃ f : V → ℝ, ∀ u v, F (Fin.insertNth a u rest) v = f v + noiseG (h a) (seed a).bump u v) + (t β γ : ℝ) (ht : 0 ≤ t) (hβ : 0 < β) (hγ : 0 < γ) (hπ : 0 ≤ π) (hx : 0 < h a x) + (hamp : ∀ loc, GoodBump (h a) α η ((seed a).bump loc) x → ∀ s ∈ B, + β ≤ |h a x-h a s| ∨ ∃ j, γ ≤ |(seed a).bump loc j x-(seed a).bump loc j s|) + (hbudget : (B.card : ℝ)*(2*t/β+2*t/γ) ≤ 1/2) : + ENNReal.ofReal (π/4) ≤ (Measure.pi (fun i => noiseLaw (seed i).m (seed i).mass)) + {ω | ∀ s ∈ B, t ≤ |F ω x-F ω s|} := by + let (i : Fin (n+1)) := (seed i).probability + apply pi_conditioned _ a _ + · simp_rw [ofPred_forall] + exact MeasurableSet.iInter (fun s => MeasurableSet.iInter (fun _ => measurableSet_le measurable_const ((hF x).sub (hF s)).abs)) + · intro rest + obtain ⟨f,hf⟩ := haff rest + have he : {u | ∀ s ∈ B, t ≤ |F (Fin.insertNth a u rest) x-F (Fin.insertNth a u rest) s|} = + {u | ∀ s : B, t ≤ |(f x-f s)+(h a x-h a s)*noiseXi u+ + ∑ j, (u.2.2 j : ℝ)*((seed a).bump u.2.1 j x-(seed a).bump u.2.1 j s)|} := by + ext u + simp only [mem_ofPred_eq,hf] + have hab (s : V) : f x+noiseG (h a) (seed a).bump u x-(f s+noiseG (h a) (seed a).bump u s) = + (f x-f s)+(h a x-h a s)*noiseXi u+ + ∑ j, (u.2.2 j : ℝ)*((seed a).bump u.2.1 j x-(seed a).bump u.2.1 j s) := by + simp only [noiseG,noiseV,Finset.sum_sub_distrib,mul_sub] + ring + simp_rw [hab] + constructor + · intro h s; exact h s s.property + · intro h s hs; exact h ⟨s,hs⟩ + change ENNReal.ofReal (π/4) ≤ (noiseLaw (seed a).m (seed a).mass) {u | ∀ s ∈ B, t ≤ |F (Fin.insertNth a u rest) x-F (Fin.insertNth a u rest) s|} + rw [he] + have hh := conditioned_gap (seed a).mass (seed a).mass_nonneg (seed a).mass_total + (fun s : B => f x-f s) (fun s : B => h a x-h a s) + (fun loc (s : B) j => (seed a).bump loc j x-(seed a).bump loc j s) + {loc | GoodBump (h a) α η ((seed a).bump loc) x} t β γ (π/2) ht hβ hγ (by positivity) + (OrdinarySeed.good_location (seed a) x hx) (fun loc hl s => hamp loc hl s s.property) + (by simpa only [Fintype.card_coe] using hbudget) + convert hh using 1 ; congr 1 ; ring +end BoundedTreewidthL1.NoiseCube + +namespace BoundedTreewidthL1 +open MeasureTheory Set +open scoped ENNReal +lemma event_lower_integral {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] + (f : Ω → ℝ) (hf : Integrable f μ) (hf0 : ∀ ω, 0 ≤ f ω) + (E : Set Ω) (hE : MeasurableSet E) (p t : ℝ) (hp : 0 ≤ p) + (hprob : ENNReal.ofReal p ≤ μ E) (hlower : ∀ ω ∈ E, t ≤ f ω) : + p*t ≤ ∫ ω, f ω ∂μ := by + by_cases ht : 0 ≤ t + · have hd : Integrable (E.indicator (fun _ => t)) μ := (integrable_const t).indicator hE + have hi := integral_mono hd hf (fun ω => by + by_cases hω : ω ∈ E + · simpa only [Set.indicator_of_mem hω] using hlower ω hω + · simpa only [Set.indicator_of_notMem hω] using hf0 ω) + have hpr : p ≤ μ.real E := by + rw [measureReal_def] + exact (ENNReal.ofReal_le_iff_le_toReal (measure_ne_top μ E)).mp hprob + rw [integral_indicator hE, setIntegral_const,smul_eq_mul] at hi + exact (mul_le_mul_of_nonneg_right hpr ht).trans hi + · exact (mul_nonpos_of_nonneg_of_nonpos hp (le_of_not_ge ht)).trans (integral_nonneg hf0) + +lemma gap_proxy {V : Type*} (d : V → V → ℝ) (F : V → ℝ) (x z : V) (B : Finset V) + (L ε : ℝ) (hL : |F x-F z| ≤ L*d x z) + (hgap : ∀ s ∈ B, ε ≤ |F x-F s|) : + ∀ s ∈ B, ε-L*d x z ≤ |F z-F s| := by + intro s hs + have hh := abs_sub_le (F x) (F z) (F s) + linarith [hgap s hs] + +lemma gap_budget (k : ℕ) (β γ δ : ℝ) (hβ : 0 < β) (hγ : 0 < γ) + (_ : 0 ≤ δ) (hδβ : δ ≤ β) (hδγ : δ ≤ γ) : + (k:ℝ)*(2*(δ/(8*((k:ℝ)+1)))/β+2*(δ/(8*((k:ℝ)+1)))/γ) ≤ 1/2 := by + have hk : 0 < (k:ℝ)+1 := by positivity + have h₁ : 2*(δ/(8*((k:ℝ)+1)))/β ≤ 1/(4*((k:ℝ)+1)) := by + apply (div_le_iff₀ hβ).mpr + have hh := mul_le_mul_of_nonneg_left hδβ (show 0 ≤ 1/(4*((k:ℝ)+1)) by positivity) + convert hh using 1 ; field_simp ; ring + have h₂ : 2*(δ/(8*((k:ℝ)+1)))/γ ≤ 1/(4*((k:ℝ)+1)) := by + apply (div_le_iff₀ hγ).mpr + have hh := mul_le_mul_of_nonneg_left hδγ (show 0 ≤ 1/(4*((k:ℝ)+1)) by positivity) + convert hh using 1 ; field_simp ; ring + have h := mul_le_mul_of_nonneg_left (add_le_add h₁ h₂) (Nat.cast_nonneg k : (0:ℝ) ≤ k) + apply h.trans + apply (le_div_iff₀ (by norm_num : (0:ℝ)<2)).mpr + field_simp + nlinarith +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.AnchorTreeParticles +open ParticleBatch ParticleSchedule +attribute [local instance 2000] Classical.decEq Classical.propDecidable +variable {V ι : Type*} [Fintype V] [Fintype ι] [Nonempty ι] +noncomputable def positive {I : Type*} (R : RootedForest I) (B : I → Finset V) (A : I → Finset I) + (g : I → I → V → ℝ) (a : I) : V → ℝ := + (state (ι := ι) R B A g a).1 ((state (ι := ι) R B A g a).2 a).1 +lemma positive_affine {n : ℕ} {Ω : Fin (n+1) → Type*} [∀ i, Nonempty (Ω i)] + (R : RootedForest (Fin (n+1))) (B : Fin (n+1) → Finset V) (A : Fin (n+1) → Finset (Fin (n+1))) + (H : (i : Fin (n+1)) → Ω i → V → ℝ) (a : Fin (n+1)) (hfresh : fresh R A a = {a}) + (hdistinct : ∀ ω : ∀ i, Ω i, + ((state (ι := ι) R B A (fun i _ => H i (ω i)) a).2 a).1 ≠ + ((state (ι := ι) R B A (fun i _ => H i (ω i)) a).2 a).2) : + ∀ rest : ∀ j : Fin n, Ω (a.succAbove j), ∃ f : V → ℝ, + ∀ u v, positive (ι := ι) R B A (fun i _ => H i ((Fin.insertNth a u rest) i)) a v = f v+H a u v := by + intro rest + let u₀ : Ω a := Classical.choice inferInstance + let ω₀ := Fin.insertNth a u₀ rest + let pre := (R.parent a).elim (seed (ι := ι) (V := V) (J := Fin (n+1))) + (state R B A (fun i _ => H i (ω₀ i))) + let p := pickPair (B a) (usedPairs (retained R A a) pre.2) pre.1 + refine ⟨fun v => (pre.1 p.1 v+pre.1 p.2 v)/2,?_⟩ + intro u v + have hpre := predecessor_congr_depth (ι := ι) R B A + (fun i _ => H i ((Fin.insertNth a u rest) i)) (fun i _ => H i (ω₀ i)) a (by + intro j hj + have hja : j ≠ a := by intro hh; subst j; exact (lt_irrefl _ hj) + obtain ⟨b,hb⟩ := Fin.exists_succAbove_eq hja + subst j + simp only [ω₀,Fin.insertNth_apply_succAbove]) + have hp := congrFun (singleton_positive (ι := ι) R B A + (fun i _ => H i ((Fin.insertNth a u rest) i)) a a (by convert! hfresh using 1) (hdistinct _)) v + rw [hpre] at hp + simpa only [positive,Fin.insertNth_apply_same] using hp + +lemma measurable_positive {I Ω : Type*} [Fintype I] [MeasurableSpace Ω] [MeasurableSpace ι] [MeasurableSingletonClass ι] + (R : RootedForest I) (B : I → Finset V) (A : I → Finset I) + (g : Ω → I → I → V → ℝ) (hg : ∀ i a v, Measurable (fun ω => g ω i a v)) (a : I) (v : V) : + Measurable (fun ω => positive (ι := ι) R B A (g ω) a v) := by + have hs := measurable_state (ι := ι) R B A g hg a + have hf (r : ι) : Measurable (fun ω => (state (ι := ι) R B A (g ω) a).1 r v) := + (measurable_pi_apply v).comp ((measurable_pi_apply r).comp hs.fst) + have hi : Measurable (fun ω => ((state (ι := ι) R B A (g ω) a).2 a).1) := + ((measurable_pi_apply a).comp hs.snd).fst + exact measurable_selected (fun ω r => (state (ι := ι) R B A (g ω) a).1 r v) + (fun ω => ((state (ι := ι) R B A (g ω) a).2 a).1) hf hi +end BoundedTreewidthL1.AnchorTreeParticles + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/CobagEmbedding.lean b/lean/OAI/Combinatorics/TreewidthL1/CobagEmbedding.lean new file mode 100644 index 0000000000000000000000000000000000000000..95e05bccc2b136f950df109746cd94dc40721d4a --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/CobagEmbedding.lean @@ -0,0 +1,141 @@ +import OAI.Combinatorics.TreewidthL1.CobagScales + +namespace OAI + +namespace BoundedTreewidthL1 +open MeasureTheory Metric TreeParticles LaunchNoise CobagScales +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable + +theorem cobag_embedding : + ∀ k : ℕ, 2 ≤ k → ∃ U c : ℝ, 0 < U ∧ 0 < c ∧ + ∀ (V : Type) [Fintype V] [DecidableEq V] [Nontrivial V] + (G : SimpleGraph V) (_ : G.Connected) + (ℓ : G.edgeSet → ℝ) (_ : ∀ e, 0 < ℓ e) + (m : ℕ) (T : SimpleGraph (Fin m)) (_ : T.IsTree) (_ : Fin m) + (B : Fin m → Finset V), + (∀ v, ∃ i, v ∈ B i) → + (∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) → + (∀ v, (T.induce {i | v ∈ B i}).Connected) → + (∀ i, (B i).card ≤ k) → + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ ≤ U*shortestPathDistance G ℓ u v) ∧ + ∀ i u v, u ∈ B i → v ∈ B i → + c*shortestPathDistance G ℓ u v ≤ ‖Φ u - Φ v‖ := by + classical + intro k hk + obtain ⟨α,π,hα,hα8,hπ,hπ1,hsampler⟩ := graph_cobag_sampler k hk + let q := 4*k.choose 2 + let N := 2*q + k.factorial + 2 + have hN : 2 ≤ N := by dsimp [N]; omega + have hNr : (2:ℝ) ≤ N := by exact_mod_cast hN + have hNm : 0 < (N:ℝ)-1 := by linarith + refine ⟨(N:ℝ)*((N:ℝ)-1),π*α/64,mul_pos (by linarith) hNm,by positivity,?_⟩ + intro V _ _ _ G hG ℓ hℓ m T hT root B hcover hedge hrun hbag + let : MetricSpace V := weightedMetricSpace G ℓ hG hℓ + let R := RootedTree.forest T hT root + let K : Finset ℤ := Finset.univ.biUnion (fun i => active dist (B i)) + let J := ↥K + let A : Fin m → Finset J := fun i => (active dist (B i)).subtype (fun j => j ∈ K) + have hA : ∀ i, (A i).card ≤ q := by + intro i + calc + (A i).card ≤ (active dist (B i)).card := by + rw [Finset.card_subtype] + exact Finset.card_filter_le _ _ + _ ≤ 4*(B i).card.choose 2 := active_card _ _ + _ ≤ q := Nat.mul_le_mul_left 4 (Nat.choose_le_choose 2 (hbag i)) + have hdec : HasTreeDecomposition G k := ⟨m,T,B,hT,hcover,hedge,hrun,hbag⟩ + have hs (p : Fin m × J) := hsampler V G hG hdec ℓ hℓ + (interface R B p.1 : Set V) ((2:ℝ)^p.2.val/16) (by positivity) + choose ν f hprob hf hprop hsep using hs + let (p : Fin m × J) : IsProbabilityMeasure (ν p) := hprob p + let Ω := (Fin m × J) → FiniteSampleSpace V + let law : Measure Ω := Measure.pi ν + let g : Ω → Fin m → J → V → ℝ := fun ω i a => f (i,a) (ω (i,a)) + let H : ℝ := 1 + ∑ a : J, (2:ℝ)^a.val + have hH : 0 < H := by + have hh : 0 ≤ ∑ a : J, (2:ℝ)^a.val := Finset.sum_nonneg (fun a _ => (zpow_pos (by norm_num) _).le) + dsimp [H]; linarith + have hh (a : J) : (2:ℝ)^a.val/16 ≤ H := by + have hh := Finset.single_le_sum (fun b (_ : b ∈ (Finset.univ : Finset J)) => + (zpow_pos (by norm_num : (0:ℝ)<2) b.val).le) (Finset.mem_univ a) + have hp := zpow_pos (by norm_num : (0:ℝ)<2) a.val + dsimp [H] + linarith + have hg : ∀ i a v, Measurable (fun ω : Ω => g ω i a v) := by + intro i a v + exact ((measurable_pi_apply v).comp (hf (i,a))).comp (measurable_pi_apply (i,a)) + have hLip : ∀ ω i a, ∀ u v, |g ω i a u-g ω i a v| ≤ 1*shortestPathDistance G ℓ u v := by + intro ω i a u v + change |f (i,a) (ω (i,a)) u-f (i,a) (ω (i,a)) v| ≤ 1*dist u v + exact (hprop (i,a) (ω (i,a))).1.dist_le_mul u v + have hHeight : ∀ ω i a v, |g ω i a v| ≤ H := by + intro ω i a v + rw [abs_of_nonneg ((hprop (i,a) (ω (i,a))).2.1 v).1] + exact ((hprop (i,a) (ω (i,a))).2.1 v).2.trans (hh a) + have hz : ∀ ω i a, ∀ v ∈ interface R B i, g ω i a v = 0 := by + intro ω i a v hv + exact (hprop (i,a) (ω (i,a))).2.2 v hv + obtain ⟨n,Φ,hup,hlo⟩ := averaged_origin_realization (ι := Fin N) G hG ℓ hℓ T hT root B + hcover hedge (fun v => (hrun v).preconnected) A k q hbag hA (by simp [N]) + law 1 H 1 (by norm_num) hH (by norm_num) g hg hLip hHeight hz + refine ⟨n,Φ,?_,?_⟩ + · simpa only [Fintype.card_fin,mul_one] using hup + · intro i u v hu hv + by_cases huv : u = v + · subst v + simp only [shortestPathDistance_self G ℓ hG (fun e => (hℓ e).le),mul_zero,sub_self,norm_zero,le_refl] + let j := bandIndex 1 (dist u v) + have hb : 0 < (2:ℝ)^j ∧ (2:ℝ)^j ≤ dist u v ∧ dist u v < 2*(2:ℝ)^j := by + simpa only [bandLower,one_mul] using band_bounds 1 (dist u v) (by norm_num) (dist_pos.mpr huv) + have haj : j ∈ active dist (B i) := small_scale_active (B i) u v hu hv huv + let a : J := ⟨j,Finset.mem_biUnion.mpr ⟨i,Finset.mem_univ i,haj⟩⟩ + have ha : a ∈ A i := Finset.mem_subtype.mpr haj + let o := origin R A root i a + have hof : a ∈ fresh R A o := origin_fresh R A root i a ha + have hge (x y : V) (hxy : (2:ℝ)^j/16 < dist x y) + (hcap : (interface R B o : Set V).Nonempty → + α*((2:ℝ)^j/16) ≤ infDist x (interface R B o : Set V)) : + π*α*((2:ℝ)^j/16)/4 ≤ ∫ ω : Ω, |g ω o a x-g ω o a y| ∂law := by + have heq := integral_comp_eval (μ := ν) (i := (o,a)) + (((measurable_pi_apply x).comp (hf (o,a))).sub + ((measurable_pi_apply y).comp (hf (o,a)))).abs.aestronglyMeasurable + change (∫ ω : Ω, |g ω o a x-g ω o a y| ∂law) = _ at heq + rw [heq] + exact hsep (o,a) x y hxy hcap + have hgap : π*α*((2:ℝ)^j/16)/4 ≤ ∫ ω : Ω, |g ω o a u-g ω o a v| ∂law := by + have hsmall : (2:ℝ)^j/16 < dist u v := by linarith [hb.1,hb.2.1] + have hscale : α*((2:ℝ)^j/16) ≤ (2:ℝ)^j/8 := by nlinarith [hb.1] + cases hp : R.parent o with + | none => + apply hge u v hsmall + simp only [interface,hp,Option.elim_none,Finset.coe_empty,Set.not_nonempty_empty,IsEmpty.forall_iff] + | some p => + have hn : j ∉ active dist (B p) := by + intro hj + have hap : a ∈ A p := Finset.mem_subtype.mpr hj + exact (Finset.mem_sdiff.mp hof).2 (by + simpa only [retained,hp,Option.elim_some,Finset.mem_inter] using + And.intro (Finset.mem_sdiff.mp hof).1 hap) + by_cases hne : (B p : Set V).Nonempty + · rcases inactive_far (B p) j u v hn hb.2.1 hb.2.2 hne with hfar | hfar + · apply hge u v hsmall + intro _ + simpa only [interface,hp,Option.elim_some] using hscale.trans hfar + · have he := hge v u (by simpa only [dist_comm] using hsmall) (by + intro _ + simpa only [interface,hp,Option.elim_some] using hscale.trans hfar) + apply he.trans_eq + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => abs_sub_comm _ _) + · apply hge u v hsmall + simpa only [interface,hp,Option.elim_some] using (fun h => False.elim (hne h)) + have hl := hlo i a ha ⟨u,hu⟩ ⟨v,hv⟩ + have hpos : 0 < π*α := mul_pos hπ hα + change 2*(∫ ω : Ω, |g ω o a u-g ω o a v| ∂law) ≤ ‖Φ u-Φ v‖ at hl + change π*α/64*dist u v ≤ ‖Φ u-Φ v‖ + nlinarith [hb.2.2] +end BoundedTreewidthL1 + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/CobagNoise.lean b/lean/OAI/Combinatorics/TreewidthL1/CobagNoise.lean new file mode 100644 index 0000000000000000000000000000000000000000..3fa863ffc66e4d5b3f089f251282a321c02ed636 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/CobagNoise.lean @@ -0,0 +1,614 @@ +import OAI.Combinatorics.TreewidthL1.AnchorEmbedding + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I J : Type*} [Fintype V] [Fintype I] [Fintype J] [DecidableEq V] + +end BoundedTreewidthL1.ParticleLaws + +namespace BoundedTreewidthL1.TreeParticles +variable {I J X : Type*} [DecidableEq J] +attribute [local instance] Classical.propDecidable + +/-- The discrete launch location depends only on the rooted decomposition and +active keys. In particular it does not consult any preparatory randomness. -/ +noncomputable def origin (R : RootedForest I) (A : I → Finset J) (root : I) : I → J → I := + R.run (fun _ => root) (fun i old a => if a ∈ retained R A i then old a else i) + +lemma origin_eq (R : RootedForest I) (A : I → Finset J) (root i : I) (a : J) : + origin R A root i a = if a ∈ retained R A i then + ((R.parent i).elim (fun _ => root) (origin R A root)) a else i := by + unfold origin + rw [RootedForest.run_eq] + +lemma origin_fresh (R : RootedForest I) (A : I → Finset J) (root i : I) + (a : J) (ha : a ∈ A i) : a ∈ fresh R A (origin R A root i a) := by + induction hn : R.depth i using Nat.strong_induction_on generalizing i with + | h n ih => + rw [origin_eq] + by_cases hk : a ∈ retained R A i + · rw [ite_eq_left hk] + cases hp : R.parent i with + | none => simp [retained,hp] at hk + | some p => + simp only [Option.elim_some] + have hap : a ∈ A p := (Finset.mem_inter.mp (by simpa [retained,hp] using hk)).2 + exact ih (R.depth p) (by rw [← hn]; exact R.decreases i p hp) p hap rfl + · rw [ite_eq_right hk] + exact Finset.mem_sdiff.mpr ⟨ha,hk⟩ + +lemma origin_transport (R : RootedForest I) (A : I → Finset J) (root : I) + (E : I → J → X) + (hkeep : ∀ i p, R.parent i = some p → ∀ a ∈ A i ∩ A p, E i a = E p a) + (i : I) (a : J) (ha : a ∈ A i) : E i a = E (origin R A root i a) a := by + induction hn : R.depth i using Nat.strong_induction_on generalizing i with + | h n ih => + rw [origin_eq] + by_cases hk : a ∈ retained R A i + · rw [ite_eq_left hk] + cases hp : R.parent i with + | none => simp [retained,hp] at hk + | some p => + simp only [Option.elim_some] + have hap : a ∈ A i ∩ A p := by simpa [retained,hp] using hk + exact (hkeep i p hp a hap).trans + (ih (R.depth p) (by rw [← hn]; exact R.decreases i p hp) p + (Finset.mem_inter.mp hap).2 rfl) + · rw [ite_eq_right hk] +end BoundedTreewidthL1.TreeParticles + +namespace BoundedTreewidthL1.TreeParticles +open scoped BigOperators +variable {I V ι J : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] [DecidableEq J] + +lemma two_particle_difference + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] + (F : ι → V → ℝ) (a b : ι) (hab : a ≠ b) + (g : V → ℝ) (hgap : ∀ v, F a v - F b v = 2*g v) (u v : V) : + 2*|g u-g v| ≤ ∑ t, |F t u-F t v| := by + have hs : (∑ t ∈ ({a,b} : Finset ι), |F t u-F t v|) ≤ ∑ t, |F t u-F t v| := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun t _ _ => abs_nonneg _) + simp only [Finset.sum_pair hab] at hs + have he : (F a u-F a v)-(F b u-F b v) = 2*(g u-g v) := by + linarith [hgap u,hgap v] + have ha := abs_sub (F a u-F a v) (F b u-F b v) + rw [he,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] at ha + exact ha.trans hs + +/-- The actual active pair at any descendant supplies the original launch +separation. The origin is deterministic, so no conditioning on the particle +scheduler or sampled coefficients is required. -/ +theorem origin_particle_gap (R : RootedForest I) (root : I) (bag : I → Finset V) + (A : I → Finset J) (k q : ℕ) (hbag : ∀ i, (bag i).card ≤ k) + (hA : ∀ i, (A i).card ≤ q) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (d : V → V → ℝ) (L H Δ : ℝ) (hH : 0 < H) (hΔ : 0 < Δ) + (g : I → J → V → ℝ) + (hLip : ∀ i a, ∀ u v, |g i a u - g i a v| ≤ L*d u v) + (hHeight : ∀ i a v, |g i a v| ≤ H) + (hzero : ∀ i a, ∀ v ∈ interface R bag i, g i a v = 0) + (i : I) (a : J) (ha : a ∈ A i) (u v : V) : + 2*|g (origin R A root i a) a u - g (origin R A root i a) a v| ≤ + ∑ t, |(state (ι := ι) R bag A g i).1 t u - + (state (ι := ι) R bag A g i).1 t v| := by + let S := state (ι := ι) R bag A g + let o := origin R A root i a + obtain ⟨hreach,htrace,hkeep,hnew⟩ := forest_particle_realization R bag A k q + hbag hA hN d L H Δ hH hΔ g hLip hHeight hzero + have hp : (S i).2 a = (S o).2 a := + origin_transport R A root (fun i a => (S i).2 a) + (fun i p hip a ha => (hkeep i p hip a ha).1) i a ha + have hl : (S i).1 ((S i).2 a).1 = (S o).1 ((S o).2 a).1 := + origin_transport R A root (fun i a => (S i).1 ((S i).2 a).1) + (fun i p hip a ha => (hkeep i p hip a ha).2.1) i a ha + have hr : (S i).1 ((S i).2 a).2 = (S o).1 ((S o).2 a).2 := + origin_transport R A root (fun i a => (S i).1 ((S i).2 a).2) + (fun i p hip a ha => (hkeep i p hip a ha).2.2) i a ha + have hn := hnew o a (origin_fresh R A root i a ha) + apply two_particle_difference (S i).1 ((S i).2 a).1 ((S i).2 a).2 + (by rw [hp]; exact hn.1) (g o a) ?_ u v + intro x + rw [hl,hr] + exact hn.2 x +end BoundedTreewidthL1.TreeParticles + +namespace BoundedTreewidthL1.TreeParticles +open MeasureTheory ParticleLaws +open scoped BigOperators ENNReal +variable {I V ι J Ω : Type*} [Fintype I] [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq V] [DecidableEq ι] [DecidableEq J] [Fintype J] [MeasurableSpace Ω] + +/-- Actual global averaged L1 realization of the branching preparation, with +an unconditional integral lower bound from each deterministic active origin. -/ +theorem averaged_origin_realization + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (hT : T.IsTree) (root : I) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (A : I → Finset J) (k q : ℕ) (hbag : ∀ i, (B i).card ≤ k) + (hA : ∀ i, (A i).card ≤ q) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (ν : Measure Ω) [IsProbabilityMeasure ν] + (L H Δ : ℝ) (hL : 0 < L) (hH : 0 < H) (hΔ : 0 < Δ) + (g : Ω → I → J → V → ℝ) (hmeas : ∀ i a v, Measurable (fun ω => g ω i a v)) + (hLip : ∀ ω i a, ∀ u v, |g ω i a u - g ω i a v| ≤ L*shortestPathDistance G ℓ u v) + (hHeight : ∀ ω i a v, |g ω i a v| ≤ H) + (hzero : ∀ ω i a, ∀ v ∈ interface (RootedTree.forest T hT root) B i, g ω i a v = 0) : + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ ≤ + (Fintype.card ι : ℝ)*L*((Fintype.card ι : ℝ)-1)*shortestPathDistance G ℓ u v) ∧ + ∀ i (a : J), a ∈ A i → ∀ (u v : B i), + 2*(∫ ω, |g ω (origin (RootedTree.forest T hT root) A root i a) a u - + g ω (origin (RootedTree.forest T hT root) A root i a) a v| ∂ν) ≤ + ‖Φ u.val - Φ v.val‖ := by + classical + let : MeasurableSpace ι := ⊤ + let : MeasurableSingletonClass ι := ⟨fun _ => trivial⟩ + let R := RootedTree.forest T hT root + let S := fun ω => state (ι := ι) R B A (g ω) + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + have hreach : ∀ ω i, FunctionParticleReachable (shortestPathDistance G ℓ) L H (S ω i).1 := by + intro ω + exact (forest_particle_realization R B A k q hbag hA hN + (shortestPathDistance G ℓ) L H Δ hH hΔ (g ω) (hLip ω) (hHeight ω) (hzero ω)).1 + have hsmeas : ∀ i t v, Measurable (fun ω => (S ω i).1 t v) := by + intro i t v + exact (measurable_pi_apply v).comp ((measurable_pi_apply t).comp + (measurable_state R B A g hmeas i).fst) + have hcons : ∀ ω i j, T.Adj i j → + particleTrace M (S ω i).1 (B i ∩ B j) = particleTrace M (S ω j).1 (B i ∩ B j) := by + intro ω i j hij + have ht := (forest_particle_realization R B A k q hbag hA hN + (shortestPathDistance G ℓ) L H Δ hH hΔ (g ω) (hLip ω) (hHeight ω) (hzero ω)).2.1 + rcases RootedTree.edge_orientation T hT root hij with hp | hp + · exact trace_eq_of_subset M _ _ (B j) _ Finset.inter_subset_right (ht i j hp) + · exact (trace_eq_of_subset M _ _ (B i) _ Finset.inter_subset_left (ht j i hp)).symm + obtain ⟨n,Φ,hup,heq⟩ := averaged_particle_realization G hG ℓ hℓ T hT B hcover hedge hrun + ν L H Δ hL hH hΔ (by omega : 1 ≤ Fintype.card ι) (fun ω i => (S ω i).1) + hsmeas (by + have hd : (Classical.decEq ι) = (inferInstance : DecidableEq ι) := Subsingleton.elim _ _ + rw [hd] + exact hreach) hcons + refine ⟨n,Φ,hup,?_⟩ + intro i a ha u v + rw [heq i u v,← integral_const_mul] + apply integral_mono + · apply Integrable.const_mul + apply Integrable.of_bound ((hmeas _ a u).sub (hmeas _ a v)).abs.aestronglyMeasurable (2*H) + apply Filter.Eventually.of_forall + intro ω + rw [Real.norm_eq_abs,abs_abs] + have hu := hHeight ω (origin R A root i a) a u + have hv := hHeight ω (origin R A root i a) a v + exact (abs_sub _ _).trans (by linarith) + · apply integrable_finsetSum + intro t ht + apply Integrable.of_bound ((hsmeas i t u).sub (hsmeas i t v)).abs.aestronglyMeasurable + (2*H*((Fintype.card ι : ℝ)-1)) + apply Filter.Eventually.of_forall + intro ω + rw [Real.norm_eq_abs,abs_abs] + have hu := function_particles_height_bound hH (hreach ω i) t u + have hv := function_particles_height_bound hH (hreach ω i) t v + exact (abs_sub _ _).trans (by linarith) + · intro ω + exact origin_particle_gap R root B A k q hbag hA hN (shortestPathDistance G ℓ) + L H Δ hH hΔ (g ω) (hLip ω) (hHeight ω) (hzero ω) i a ha u v +end BoundedTreewidthL1.TreeParticles + +namespace BoundedTreewidthL1.LaunchNoise +open MeasureTheory Set +open scoped unitInterval + +theorem uniform_coefficient_integral_lower (a b : ℝ) : + a/4 ≤ ∫ t : I, |a * (t : ℝ) - b| := by + rw [unitInterval.measurePreserving_coe.integral_comp + unitInterval.measurableEmbedding_coe (fun t : ℝ => |a*t-b|)] + change a/4 ≤ ∫ t in Icc (0:ℝ) 1, |a*t-b| + rw [integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le (by norm_num : (0:ℝ) ≤ 1)] + have hi : ∀ x y : ℝ, IntervalIntegrable (fun t : ℝ => |a*t-b|) volume x y := + fun _ _ => (by fun_prop : Continuous (fun t : ℝ => |a*t-b|)).intervalIntegrable _ _ + have hl := intervalIntegral.integral_mono_on (by norm_num : (0:ℝ) ≤ 1/2) + ((by fun_prop : Continuous (fun t : ℝ => b-a*t)).intervalIntegrable _ _) + (hi 0 (1/2)) (fun t _ => by simpa only [neg_sub] using neg_le_abs (a*t-b)) + have hr := intervalIntegral.integral_mono_on (by norm_num : (1/2:ℝ) ≤ 1) + ((by fun_prop : Continuous (fun t : ℝ => a*t-b)).intervalIntegrable _ _) + (hi (1/2) 1) (fun t _ => le_abs_self (a*t-b)) + have hs := intervalIntegral.integral_add_adjacent_intervals (hi 0 (1/2)) (hi (1/2) 1) + have hli : (∫ t : ℝ in (0:ℝ)..(1/2:ℝ), b-a*t) = b/2-a/8 := by + rw [intervalIntegral.integral_sub (continuous_const.intervalIntegrable _ _) + ((by fun_prop : Continuous (fun t : ℝ => a*t)).intervalIntegrable _ _), + intervalIntegral.integral_const_mul, integral_id] + simp + ring + have hri : (∫ t : ℝ in (1/2:ℝ)..1, a*t-b) = 3*a/8-b/2 := by + rw [intervalIntegral.integral_sub + ((by fun_prop : Continuous (fun t : ℝ => a*t)).intervalIntegrable _ _) + (continuous_const.intervalIntegrable _ _), + intervalIntegral.integral_const_mul, integral_id] + simp + ring + rw [hli] at hl + rw [hri] at hr + linarith +end BoundedTreewidthL1.LaunchNoise + +namespace BoundedTreewidthL1.LaunchNoise +open Metric MeasureTheory +open scoped unitInterval +variable {V J : Type*} [MetricSpace V] [Fintype J] + +noncomputable def cobagBump (A E : Set V) (r : ℝ) (x : V) : ℝ := by + classical + exact if A.Nonempty then min (infDist x A) (bump E r x) else bump E r x +noncomputable def cobagNoise (A : Set V) (E : J → Set V) (r : ℝ) + (U : J → ℝ) (x : V) : ℝ := ∑ i, U i * cobagBump A (E i) r x + +lemma cobagBump_eq_diff (A E : Set V) (r : ℝ) (x : V) : + cobagBump A E r x = bump (E \ A) r x := by + classical + by_cases hA : A.Nonempty + · have hd : (E \ A)ᶜ.Nonempty := by + obtain ⟨a, ha⟩ := hA + exact ⟨a, fun h => h.2 ha⟩ + by_cases hE : Eᶜ.Nonempty + · have hi : infDist x (E \ A)ᶜ = min (infDist x Eᶜ) (infDist x A) := by + have he : (E \ A)ᶜ = Eᶜ ∪ A := by ext z; simp; tauto + rw [he, infDist, infEDist_union, ENNReal.toReal_min (infEDist_ne_top hE) + (infEDist_ne_top hA)] + rfl + simp only [cobagBump, hA, ↓reduceIte, bump, hE, hd, hi] + simp only [min_left_comm, min_comm] + · have he : E = Set.univ := by + apply Set.eq_univ_of_forall + intro z + by_contra hz + exact hE ⟨z, hz⟩ + have hec : (Set.univ \ A : Set V)ᶜ = A := by ext z; simp + simp [cobagBump, hA, bump, he, hec, min_comm] + · have he : A = ∅ := Set.not_nonempty_iff_eq_empty.mp hA + simp [cobagBump, he] + +lemma cobagNoise_eq_diff (A : Set V) (E : J → Set V) (r : ℝ) (U : J → ℝ) : + cobagNoise A E r U = noise (fun i => E i \ A) (fun _ => r) U := by + funext x + simp [cobagNoise, noise, cobagBump_eq_diff] + +lemma cobag_diff_disjoint + {V : Type treewidthLevel1} {J : Type treewidthLevel2} [MetricSpace V] [Fintype J] + (A : Set V) (E : J → Set V) + (hE : Pairwise (fun i j => Disjoint (E i) (E j))) : + Pairwise (fun i j => Disjoint (E i \ A) (E j \ A)) := + fun _ _ hij => (hE hij).mono Set.sdiff_subset Set.sdiff_subset + +theorem cobag_partition_properties (A : Set V) (E : J → Set V) (r : ℝ) + (hr : 0 ≤ r) (hE : Pairwise (fun i j => Disjoint (E i) (E j))) + (hcover : ∀ x, ∃ i, x ∈ E i) (U : J → ℝ) (hU : ∀ i, 0 ≤ U i ∧ U i ≤ 1) : + LipschitzWith 1 (cobagNoise A E r U) ∧ + (∀ x, 0 ≤ cobagNoise A E r U x ∧ cobagNoise A E r U x ≤ r) ∧ + (∀ x ∈ A, cobagNoise A E r U x = 0) := by + rw [cobagNoise_eq_diff] + have h := disjoint_noise (fun i => E i \ A) (fun _ => r) U + (cobag_diff_disjoint A E hE) (fun _ => hr) hU + refine ⟨h.1, fun x => ⟨h.2.1 x, ?_⟩, ?_⟩ + · by_cases hx : x ∈ A + · rw [h.2.2.2 x (fun i h => h.2 hx)] + exact hr + · obtain ⟨i, hi⟩ := hcover x + exact h.2.2.1 i x ⟨hi,hx⟩ + · intro x hx + exact h.2.2.2 x (fun i h => h.2 hx) + +lemma cobagBump_bounds (A E : Set V) (r : ℝ) (hr : 0 ≤ r) (x : V) : + 0 ≤ cobagBump A E r x ∧ cobagBump A E r x ≤ r := by + rw [cobagBump_eq_diff] + exact bump_bounds _ _ hr _ + +lemma cobagBump_zero (A E : Set V) (r : ℝ) (hr : 0 ≤ r) (x : V) (hx : x ∉ E) : + cobagBump A E r x = 0 := by + rw [cobagBump_eq_diff] + exact bump_zero _ _ hr _ (fun h => hx h.1) + +lemma cobagBump_padding (A E : Set V) (r a : ℝ) (x : V) + (har : a ≤ r) (hball : ball x a ⊆ E) (hA : A.Nonempty → a ≤ infDist x A) : + a ≤ cobagBump A E r x := by + classical + unfold cobagBump + split_ifs with hne + · exact le_min (hA hne) (bump_padding E r x a har hball) + · exact bump_padding E r x a har hball + +lemma coefficient_affine_integral_lower {m : ℕ} (j : Fin (m+1)) + (a : Fin (m+1) → ℝ) : + a j / 4 ≤ ∫ U : Fin (m+1) → I, |∑ i, (U i:ℝ) * a i| := by + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (m+1) => I) j + let f : I × (Fin m → I) → ℝ := fun z => + |(z.1:ℝ)*a j + ∑ i, (z.2 i:ℝ)*a (j.succAbove i)| + have hc : Continuous f := by unfold f; fun_prop + have hi : Integrable f := hc.integrable_of_hasCompactSupport (.of_compactSpace _) + have he : (∫ U : Fin (m+1) → I, |∑ i, (U i:ℝ)*a i|) = ∫ z, f z := by + have hh := (volume_preserving_piFinSuccAbove (fun _ : Fin (m+1) => I) j).integral_comp + e.measurableEmbedding f + convert hh using 1 + apply integral_congr_ae + filter_upwards [] with U + congr 1 + exact Fin.sum_univ_succAbove (fun i => (U i:ℝ)*a i) j + rw [he] + change a j / 4 ≤ ∫ z, f z ∂(volume.prod volume) + rw [integral_prod_symm f hi] + have hb (U : Fin m → I) : a j/4 ≤ ∫ t : I, f (t,U) := by + convert uniform_coefficient_integral_lower (a j) + (-(∑ i, (U i:ℝ)*a (j.succAbove i))) using 1 + congr 1 + funext t + simp [f, mul_comm, sub_neg_eq_add] + have hm := integral_mono (integrable_const (a j/4)) hi.integral_prod_right hb + simpa using hm + +theorem cobag_partition_averaging {m : ℕ} (A : Set V) + (E : Fin (m+1) → Set V) (r α : ℝ) (hr : 0 < r) (_ : 0 < α) (hα1 : α ≤ 1) + (_ : Pairwise (fun i j => Disjoint (E i) (E j))) + (_ : ∀ x, ∃ i, x ∈ E i) (j : Fin (m+1)) (x y : V) + (hx : ball x (α*r) ⊆ E j) (hy : y ∉ E j) + (hA : A.Nonempty → α*r ≤ infDist x A) : + α*r/4 ≤ ∫ U : Fin (m+1) → I, + |cobagNoise A E r (fun i => (U i:ℝ)) x - + cobagNoise A E r (fun i => (U i:ℝ)) y| := by + classical + let a : Fin (m+1) → ℝ := fun i => cobagBump A (E i) r x - cobagBump A (E i) r y + have ha : α*r ≤ a j := by + dsimp [a] + rw [cobagBump_zero A (E j) r hr.le y hy, sub_zero] + apply cobagBump_padding A (E j) r (α*r) x _ hx hA + exact mul_le_of_le_one_left hr.le hα1 + have hsum (U : Fin (m+1) → I) : + cobagNoise A E r (fun i => (U i:ℝ)) x - + cobagNoise A E r (fun i => (U i:ℝ)) y = ∑ i, (U i:ℝ)*a i := by + simp only [cobagNoise, a, mul_sub, Finset.sum_sub_distrib] + simp_rw [hsum] + exact (div_le_div_of_nonneg_right ha (by norm_num)).trans + (coefficient_affine_integral_lower j a) +end BoundedTreewidthL1.LaunchNoise + +namespace BoundedTreewidthL1.LaunchNoise +open MeasureTheory Metric +open scoped unitInterval ENNReal +attribute [local instance] Classical.propDecidable +noncomputable def cobagLocationLaw {n : ℕ} (μ : Fin n → ℝ) : Measure (Fin n) := + ∑ a, ENNReal.ofReal (μ a) • Measure.dirac a +noncomputable def cobagLaw {n : ℕ} (m : ℕ) (μ : Fin n → ℝ) : + Measure (Fin n × (Fin (m+1) → I)) := (cobagLocationLaw μ).prod volume +noncomputable def cobagSample {V : Type*} [MetricSpace V] {n m : ℕ} + (A : Set V) (P : Fin n → V → Fin (m+1)) (r : ℝ) + (ω : Fin n × (Fin (m+1) → I)) (x : V) : ℝ := + cobagNoise A (fun j => {z | P ω.1 z = j}) r (fun j => (ω.2 j:ℝ)) x + +lemma cobagLocationLaw_probability {n : ℕ} (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) : + IsProbabilityMeasure (cobagLocationLaw μ) := by + classical + constructor + simp only [cobagLocationLaw, Measure.finsetSum_apply, + Measure.smul_apply, Measure.dirac_apply_of_mem (Set.mem_univ _), smul_eq_mul, mul_one] + rw [← ENNReal.ofReal_sum_of_nonneg (fun a _ => hμ a), hμ₁, ENNReal.ofReal_one] + +lemma cobagLocationLaw_integral {n : ℕ} (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (f : Fin n → ℝ) : + (∫ a, f a ∂cobagLocationLaw μ) = ∑ a, μ a * f a := by + classical + rw [cobagLocationLaw, integral_finsetSum_measure] + · apply Finset.sum_congr rfl + intro a _ + rw [integral_smul_measure, integral_dirac] + simp [ENNReal.toReal_ofReal (hμ a)] + · intro a _ + exact (integrable_dirac (f := f) (by simp)).smul_measure (by simp) + +lemma cobagSample_continuous {V : Type*} [MetricSpace V] {n m : ℕ} + (A : Set V) (P : Fin n → V → Fin (m+1)) (r : ℝ) (x : V) : + Continuous (fun ω => cobagSample A P r ω x) := by + unfold cobagSample cobagNoise + apply continuous_finsetSum + intro j _ + apply Continuous.mul + · fun_prop + · exact (continuous_of_discreteTopology (f := fun a : Fin n => + cobagBump A {z | P a z = j} r x)).comp continuous_fst + +lemma cobagSample_integral {V : Type*} [MetricSpace V] {n m : ℕ} + (A : Set V) (P : Fin n → V → Fin (m+1)) (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) (r : ℝ) (x y : V) : + (∫ ω, |cobagSample A P r ω x - cobagSample A P r ω y| ∂cobagLaw m μ) = + ∑ a, μ a * ∫ U : Fin (m+1) → I, + |cobagSample A P r (a,U) x - cobagSample A P r (a,U) y| := by + let := cobagLocationLaw_probability μ hμ hμ₁ + let : IsProbabilityMeasure (cobagLaw m μ) := by unfold cobagLaw; infer_instance + have hc := ((cobagSample_continuous A P r x).sub (cobagSample_continuous A P r y)).abs + have hi : Integrable (fun ω => |cobagSample A P r ω x - cobagSample A P r ω y|) + (cobagLaw m μ) := + hc.integrable_of_hasCompactSupport (.of_compactSpace _) + rw [cobagLaw, integral_prod _ hi, cobagLocationLaw_integral μ hμ] + +theorem cobag_sampler {V : Type*} [MetricSpace V] {n m : ℕ} + (A : Set V) (P : Fin n → V → Fin (m+1)) (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) + (r α π : ℝ) (hr : 0 < r) (hα : 0 < α) (hα1 : α ≤ 1) + (hdiam : ∀ a, 0 < μ a → ∀ x y, P a x = P a y → dist x y ≤ r) : + IsProbabilityMeasure (cobagLaw m μ) ∧ Measurable (cobagSample A P r) ∧ + (∀ ω, LipschitzWith 1 (cobagSample A P r ω) ∧ + (∀ x, 0 ≤ cobagSample A P r ω x ∧ cobagSample A P r ω x ≤ r) ∧ + (∀ x ∈ A, cobagSample A P r ω x = 0)) ∧ + ∀ x y, r < dist x y → (A.Nonempty → α*r ≤ infDist x A) → + (π ≤ ∑ a, if (∀ z, dist x z ≤ α*r → P a z = P a x) then μ a else 0) → + π*α*r/4 ≤ ∫ ω, |cobagSample A P r ω x - cobagSample A P r ω y| ∂cobagLaw m μ := by + classical + have hloc := cobagLocationLaw_probability μ hμ hμ₁ + let := hloc + have hlaw : IsProbabilityMeasure (cobagLaw m μ) := by unfold cobagLaw; infer_instance + refine ⟨hlaw, ?_, ?_, ?_⟩ + · exact Measurable.of_eval (fun x => (cobagSample_continuous A P r x).measurable) + · intro ω + have hdis : Pairwise (fun i j : Fin (m+1) => + Disjoint {z | P ω.1 z = i} {z | P ω.1 z = j}) := by + intro i j hij + exact Set.disjoint_left.mpr (fun z hi hj => hij (hi.symm.trans hj)) + exact cobag_partition_properties A (fun j => {z | P ω.1 z = j}) r hr.le + hdis (fun x => ⟨P ω.1 x, rfl⟩) (fun j => (ω.2 j:ℝ)) + (fun j => ⟨(ω.2 j).property.1, (ω.2 j).property.2⟩) + · intro x y hxy hA hpad + rw [cobagSample_integral A P μ hμ hμ₁] + let c : ℝ := α*r/4 + let q : Fin n → ℝ := fun a => + if (∀ z, dist x z ≤ α*r → P a z = P a x) then μ a else 0 + have hc : 0 ≤ c := by dsimp [c]; positivity + have hterm (a : Fin n) : c*q a ≤ μ a * ∫ U : Fin (m+1) → I, + |cobagSample A P r (a,U) x - cobagSample A P r (a,U) y| := by + have hnon : 0 ≤ ∫ U : Fin (m+1) → I, + |cobagSample A P r (a,U) x - cobagSample A P r (a,U) y| := + integral_nonneg (fun _ => abs_nonneg _) + by_cases hg : ∀ z, dist x z ≤ α*r → P a z = P a x + · have hq : q a = μ a := ite_eq_left hg + rw [hq] + rcases eq_or_lt_of_le (hμ a) with hz | hp + · rw [← hz]; simp + · have hdis : Pairwise (fun i j : Fin (m+1) => + Disjoint {z | P a z = i} {z | P a z = j}) := by + intro i j hij + exact Set.disjoint_left.mpr (fun z hi hj => hij (hi.symm.trans hj)) + have hav := cobag_partition_averaging A (fun j => {z | P a z = j}) + r α hr hα hα1 hdis (fun z => ⟨P a z, rfl⟩) (P a x) x y + (fun z hz => hg z (le_of_lt (by simpa [dist_comm] using hz))) + (fun hy => (not_le_of_gt hxy) (hdiam a hp x y hy.symm)) hA + exact (mul_comm c (μ a)).le.trans (mul_le_mul_of_nonneg_left hav (hμ a)) + · simp only [q, ite_eq_right hg, mul_zero] + exact mul_nonneg (hμ a) hnon + have hsum := Finset.sum_le_sum (fun a (_ : a ∈ Finset.univ) => hterm a) + rw [← Finset.mul_sum] at hsum + have hh : c*π ≤ c*∑ a, q a := mul_le_mul_of_nonneg_left hpad hc + calc + π*α*r/4 = c*π := by dsimp [c]; ring + _ ≤ c*∑ a, q a := hh + _ ≤ _ := hsum +end BoundedTreewidthL1.LaunchNoise + +namespace BoundedTreewidthL1.LaunchNoise +open MeasureTheory Metric +open scoped unitInterval + +attribute [local instance] Classical.propDecidable Classical.decEq + +abbrev FiniteSampleSpace (V : Type*) [Fintype V] := + Fin (Fintype.card (V → V)) × (Fin (Fintype.card V + 1) → I) + +/-- Convert a finite padded partition law into the actual common sampler +space, without selecting a partition or adding a separation assumption. -/ +theorem finite_padded_sampler {V : Type*} [Fintype V] [MetricSpace V] + (A : Set V) (μ : (V → V) → ℝ) (r α π : ℝ) + (hμ : ∀ P, 0 ≤ μ P) (hμ₁ : ∑ P, μ P = 1) + (hr : 0 < r) (hα : 0 < α) (hα1 : α ≤ 1) + (hdiam : ∀ P, 0 < μ P → ∀ x y, P x = P y → dist x y ≤ r) + (hpad : ∀ x, π ≤ ∑ P, if (∀ z, dist x z ≤ α*r → P z = P x) then μ P else 0) : + ∃ ν : Measure (FiniteSampleSpace V), ∃ g : FiniteSampleSpace V → V → ℝ, + IsProbabilityMeasure ν ∧ Measurable g ∧ + (∀ ω, LipschitzWith 1 (g ω) ∧ (∀ x, 0 ≤ g ω x ∧ g ω x ≤ r) ∧ + (∀ x ∈ A, g ω x = 0)) ∧ + ∀ x y, r < dist x y → (A.Nonempty → α*r ≤ infDist x A) → + π*α*r/4 ≤ ∫ ω, |g ω x - g ω y| ∂ν := by + classical + let e := Fintype.equivFin (V → V) + let v := Fintype.equivFin V + let P : Fin (Fintype.card (V → V)) → V → Fin (Fintype.card V + 1) := + fun a x => (v (e.symm a x)).castSucc + let μ' : Fin (Fintype.card (V → V)) → ℝ := fun a => μ (e.symm a) + have heq (a) (x y : V) : P a x = P a y ↔ e.symm a x = e.symm a y := by + simp only [P, Fin.castSucc_inj, Equiv.apply_eq_iff_eq] + have hsum : ∑ a, μ' a = 1 := by + rw [show (∑ a, μ' a) = ∑ f, μ f from e.symm.sum_comp μ] + exact hμ₁ + have hd : ∀ a, 0 < μ' a → ∀ x y, P a x = P a y → dist x y ≤ r := by + intro a ha x y hxy + exact hdiam (e.symm a) ha x y ((heq a x y).mp hxy) + have hp (x : V) : π ≤ ∑ a, if (∀ z, dist x z ≤ α*r → P a z = P a x) + then μ' a else 0 := by + simp only [heq] + change π ≤ ∑ a, (fun f : V → V => if (∀ z, dist x z ≤ α*r → f z = f x) + then μ f else 0) (e.symm a) + have he := e.symm.sum_comp (fun f : V → V => if (∀ z, dist x z ≤ α*r → f z = f x) + then μ f else 0) + convert (hpad x).trans_eq he.symm using 1 + obtain ⟨hν, hg, hprop, hgap⟩ := cobag_sampler A P μ' (fun a => hμ _) hsum + r α π hr hα hα1 hd + exact ⟨cobagLaw (Fintype.card V) μ', cobagSample A P r, hν, hg, hprop, + fun x y hxy hx => hgap x y hxy hx (by + convert hp x using 1 + apply Finset.sum_congr rfl + intro a ha + split_ifs <;> rfl)⟩ + +end BoundedTreewidthL1.LaunchNoise + +namespace BoundedTreewidthL1.LaunchNoise +open MeasureTheory Metric +attribute [local instance] Classical.propDecidable Classical.decEq + +/-- The required uniformly padded co-bag launch now has an unconditional +sampler in the original arbitrary-weight graph metric. -/ +theorem graph_cobag_sampler : + ∀ k : ℕ, 2 ≤ k → ∃ α π : ℝ, 0 < α ∧ α ≤ 1/8 ∧ 0 < π ∧ π ≤ 1 ∧ + ∀ (V : Type) [Fintype V] [DecidableEq V] [Nontrivial V] + (G : SimpleGraph V) (hG : G.Connected), HasTreeDecomposition G k → + ∀ (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e), + let : MetricSpace V := weightedMetricSpace G ℓ hG hℓ + ∀ (A : Set V) (r : ℝ), 0 < r → + ∃ ν : Measure (FiniteSampleSpace V), ∃ g : FiniteSampleSpace V → V → ℝ, + IsProbabilityMeasure ν ∧ Measurable g ∧ + (∀ ω, LipschitzWith 1 (g ω) ∧ (∀ x, 0 ≤ g ω x ∧ g ω x ≤ r) ∧ + (∀ x ∈ A, g ω x = 0)) ∧ + ∀ x y, r < shortestPathDistance G ℓ x y → + (A.Nonempty → α*r ≤ infDist x A) → + π*α*r/4 ≤ ∫ ω, |g ω x - g ω y| ∂ν := by + classical + intro k hk + obtain ⟨α,π,hα,hα8,hπ,hπ1,hpart⟩ := PaddedPartitions.uniform_padded_partitions k hk + refine ⟨α,π,hα,hα8,hπ,hπ1,?_⟩ + intro V _ _ _ G hG hdec ℓ hℓ metric + let _ : MetricSpace V := metric + intro A r hr + obtain ⟨μ,hμ,hμ1,hdiam,hpad⟩ := hpart V G hG hdec ℓ hℓ r hr + have hd : ∀ P, 0 < μ P → ∀ x y, P x = P y → dist x y ≤ r := by + intro P hP x y hxy + exact hdiam P hP x y hxy + have hp : ∀ x, π ≤ ∑ P, if (∀ z, dist x z ≤ α*r → P z = P x) then μ P else 0 := by + intro x + change π ≤ ∑ P, if (∀ z, shortestPathDistance G ℓ x z ≤ α*r → P z = P x) then μ P else 0 + have hx := hpad x + unfold PaddedPartitions.paddingProbability PaddedPartitions.PaddedAt at hx + convert! hx using 1 + apply Finset.sum_congr + · ext; simp only [Finset.mem_univ] + · intro P hP + split_ifs <;> rfl + refine finite_padded_sampler A μ r α π hμ ?_ hr hα (by linarith) hd ?_ + · convert! hμ1 using 1 + apply Finset.sum_congr + · ext; simp only [Finset.mem_univ] + · intro _ _; rfl + · intro x + convert! hp x using 1 + apply Finset.sum_congr + · ext; simp only [Finset.mem_univ] + · intro P hP + split_ifs <;> rfl + +end BoundedTreewidthL1.LaunchNoise + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/CobagScales.lean b/lean/OAI/Combinatorics/TreewidthL1/CobagScales.lean new file mode 100644 index 0000000000000000000000000000000000000000..0b8a1809f46e000b6a65bfeabd8eefd02fcec65d --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/CobagScales.lean @@ -0,0 +1,142 @@ +import OAI.Combinatorics.TreewidthL1.CobagNoise + +namespace OAI + +namespace BoundedTreewidthL1.CobagScales +open LaunchNoise +variable {V : Type*} [DecidableEq V] +attribute [local instance] Classical.propDecidable + +noncomputable def pairDistance (d : V → V → ℝ) (p : Finset V) : ℝ := + if h : p.card = 2 then + d (Finset.card_eq_two.mp h).choose (Finset.card_eq_two.mp h).choose_spec.choose + else 0 + +lemma pairDistance_witness (d : V → V → ℝ) (p : Finset V) (hp : p.card = 2) : + ∃ u v, u ≠ v ∧ p = {u,v} ∧ pairDistance d p = d u v := by + unfold pairDistance + rw [dite_eq_left hp] + exact ⟨_,_,(Finset.card_eq_two.mp hp).choose_spec.choose_spec.1, + (Finset.card_eq_two.mp hp).choose_spec.choose_spec.2,rfl⟩ + +lemma pairDistance_pair (d : V → V → ℝ) (hs : ∀ u v, d u v = d v u) + {u v : V} (huv : u ≠ v) : pairDistance d {u,v} = d u v := by + obtain ⟨a,b,hab,he,hd⟩ := pairDistance_witness d {u,v} (by simp [huv]) + have ha : a = u ∨ a = v := by + have hm : a ∈ ({u,v} : Finset V) := he.symm ▸ Finset.mem_insert_self a {b} + simpa only [Finset.mem_insert, Finset.mem_singleton] using hm + have hb : b = u ∨ b = v := by + have hm : b ∈ ({u,v} : Finset V) := he.symm ▸ Finset.mem_insert_of_mem (Finset.mem_singleton_self b) + simpa only [Finset.mem_insert, Finset.mem_singleton] using hm + rcases ha with rfl | rfl <;> rcases hb with rfl | rfl + · exact False.elim (hab rfl) + · exact hd + · exact hd.trans (hs _ _) + · exact False.elim (hab rfl) + +noncomputable def distanceScales (t : ℝ) : Finset ℤ := + (Finset.Icc (bandIndex 1 t - 2) (bandIndex 1 t + 1)).filter + (fun j => (2:ℝ)^j/2 ≤ t ∧ t ≤ 4*(2:ℝ)^j) + +lemma score_interval (t : ℝ) (ht : 0 < t) (j : ℤ) + (hl : (2:ℝ)^j/2 ≤ t) (hu : t ≤ 4*(2:ℝ)^j) : + bandIndex 1 t - 2 ≤ j ∧ j ≤ bandIndex 1 t + 1 := by + have hbase := band_bounds 1 t (by norm_num) ht + simp only [bandLower, one_mul] at hbase + have hpow (a : ℤ) : (2:ℝ)^(a+2) = 4*(2:ℝ)^a := by + rw [zpow_add₀ (by norm_num)] + norm_num + ring + have hpow' (a : ℤ) : (2:ℝ)^(a+1) = 2*(2:ℝ)^a := by + rw [zpow_add₀ (by norm_num)] + norm_num + ring + have hlo : bandIndex 1 t ≤ j+2 := by + apply (zpow_le_zpow_iff_right₀ (by norm_num : (1:ℝ)<2)).mp + rw [hpow] + exact hbase.2.1.trans hu + have hhi : j < bandIndex 1 t+2 := by + apply (zpow_lt_zpow_iff_right₀ (by norm_num : (1:ℝ)<2)).mp + rw [hpow] + nlinarith [hbase.2.2] + omega + +lemma mem_distanceScales (t : ℝ) (ht : 0 < t) (j : ℤ) : + j ∈ distanceScales t ↔ (2:ℝ)^j/2 ≤ t ∧ t ≤ 4*(2:ℝ)^j := by + simp only [distanceScales, Finset.mem_filter, Finset.mem_Icc] + exact ⟨fun h => h.2, fun h => ⟨score_interval t ht j h.1 h.2,h⟩⟩ + +lemma distanceScales_card (t : ℝ) : (distanceScales t).card ≤ 4 := by + apply (Finset.card_filter_le _ _).trans + rw [Int.card_Icc] + omega + +noncomputable def active (d : V → V → ℝ) (B : Finset V) : Finset ℤ := + (B.powersetCard 2).biUnion (fun p => distanceScales (pairDistance d p)) + +lemma mem_active (d : V → V → ℝ) (hs : ∀ u v, d u v = d v u) + (hp : ∀ u v, u ≠ v → 0 < d u v) (B : Finset V) (j : ℤ) : + j ∈ active d B ↔ ∃ u ∈ B, ∃ v ∈ B, u ≠ v ∧ + (2:ℝ)^j/2 ≤ d u v ∧ d u v ≤ 4*(2:ℝ)^j := by + constructor + · intro hj + obtain ⟨p,hpB,hj⟩ := Finset.mem_biUnion.mp hj + obtain ⟨hpB,hp₂⟩ := Finset.mem_powersetCard.mp hpB + obtain ⟨u,v,huv,he,hd⟩ := pairDistance_witness d p hp₂ + have hu : u ∈ B := hpB (he ▸ Finset.mem_insert_self u {v}) + have hv : v ∈ B := hpB (he ▸ Finset.mem_insert_of_mem (Finset.mem_singleton_self v)) + rw [hd] at hj + exact ⟨u,hu,v,hv,huv,(mem_distanceScales _ (hp u v huv) j).mp hj⟩ + · rintro ⟨u,hu,v,hv,huv,hl,hh⟩ + apply Finset.mem_biUnion.mpr + refine ⟨{u,v},Finset.mem_powersetCard.mpr ⟨?_,by simp [huv]⟩,?_⟩ + · simpa only [Finset.insert_subset_iff, Finset.singleton_subset_iff] using And.intro hu hv + · rw [pairDistance_pair d hs huv] + exact (mem_distanceScales _ (hp u v huv) j).mpr ⟨hl,hh⟩ + +theorem active_card (d : V → V → ℝ) (B : Finset V) : + (active d B).card ≤ 4 * B.card.choose 2 := by + calc + (active d B).card ≤ ∑ p ∈ B.powersetCard 2, (distanceScales (pairDistance d p)).card := + Finset.card_biUnion_le + _ ≤ ∑ _ ∈ B.powersetCard 2, 4 := Finset.sum_le_sum (fun p _ => distanceScales_card _) + _ = 4 * B.card.choose 2 := by simp [Finset.card_powersetCard, Nat.mul_comm] + +end BoundedTreewidthL1.CobagScales + +namespace BoundedTreewidthL1.CobagScales +open Metric +variable {V : Type*} [MetricSpace V] [DecidableEq V] + +theorem inactive_far (A : Finset V) (j : ℤ) (x y : V) + (hj : j ∉ active dist A) (hl : (2:ℝ)^j ≤ dist x y) + (hu : dist x y < 2*(2:ℝ)^j) (hA : (A : Set V).Nonempty) : + (2:ℝ)^j/8 ≤ infDist x (A : Set V) ∨ + (2:ℝ)^j/8 ≤ infDist y (A : Set V) := by + by_contra h + have hx : infDist x (A : Set V) < (2:ℝ)^j/8 := by + exact lt_of_not_ge (fun hx => h (Or.inl hx)) + have hy : infDist y (A : Set V) < (2:ℝ)^j/8 := by + exact lt_of_not_ge (fun hy => h (Or.inr hy)) + obtain ⟨a,ha,hxa⟩ := (infDist_lt_iff hA).mp hx + obtain ⟨b,hb,hyb⟩ := (infDist_lt_iff hA).mp hy + have hs : 0 < (2:ℝ)^j := zpow_pos (by norm_num) _ + have hxy := dist_triangle4 x a b y + have hab := dist_triangle4 a x y b + rw [dist_comm b y] at hxy + rw [dist_comm a x] at hab + have habpos : 0 < dist a b := by linarith + apply hj + apply (mem_active dist dist_comm (fun u v huv => dist_pos.mpr huv) A j).mpr + exact ⟨a,ha,b,hb,dist_pos.mp habpos,by linarith,by linarith⟩ + +lemma small_scale_active (A : Finset V) (x y : V) (hx : x ∈ A) (hy : y ∈ A) + (hxy : x ≠ y) : + LaunchNoise.bandIndex 1 (dist x y) ∈ active dist A := by + have hb := LaunchNoise.band_bounds 1 (dist x y) (by norm_num) (dist_pos.mpr hxy) + simp only [LaunchNoise.bandLower,one_mul] at hb + apply (mem_active dist dist_comm (fun u v huv => dist_pos.mpr huv) A _).mpr + exact ⟨x,hx,y,hy,hxy,by linarith,by linarith⟩ +end BoundedTreewidthL1.CobagScales + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/Construction.lean b/lean/OAI/Combinatorics/TreewidthL1/Construction.lean new file mode 100644 index 0000000000000000000000000000000000000000..92679929dcbe1a9315ddc6c4ad8967cb5c5e1fcc --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/Construction.lean @@ -0,0 +1,345 @@ +import OAI.Combinatorics.TreewidthL1.ExpandedTree + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 treewidthLevel4 + +namespace BoundedTreewidthL1.ExpandedConstruction +open MeasureTheory ExpandedParticleLaw ReservationCoupling ReservedKernel ReservedSuffix +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι I : Type*} [Fintype V] [Fintype ι] [Fintype I] + +lemma weight_total (M : ℝ) (hM : 0 ≤ M) (F : ι → V → ℝ) : + (∑ a : State ι V, weight M F a) = (Fintype.card ι : ℝ)*(2*M) := by + have he (i : ι) : (∑ ω : V → Bool, (sweep M (F i)).real {ω}) = 2*M := by + have h := OrderedReservation.total_weight M hM (F i) + unfold OrderedSweepFlow.total at h + rw [OrderedReservation.sum_carrier M (F i) (fun _ => 1)] at h + simpa only [mul_one] using h + simp only [Fintype.sum_prod_type, weight, ← Finset.sum_div, he] + simp + ; ring + +lemma edge_label (M : ℝ) (F H : ι → V → ℝ) (P Q : Finset V) (i j : ι) (C : Finset ι) + (hret : ∀ r ∈ C, F r = H r) (htrace : particleTrace M F Q = particleTrace M H Q) + (a b : State ι V) (hab : edge M F H P Q i j C a b ≠ 0) + (v : V) (hvP : v ∈ P) (hvQ : v ∈ Q) : label a v = label b v := by + by_contra hne + apply hab + apply ExpandedParticleKernel.compose_trace (weight M F) (departure M F P i j) + (incoming M F H Q C) (fun a => label a v) (fun a => label a v) (fun a => label a v) + · intro a b hne + apply (departure_coupling M F P i j).2.2.2.1 a b + intro he + exact hne (congrFun he ⟨v,hvP⟩) + · intro a b hne + apply (incoming_coupling M F H Q C hret htrace).2.2.2.1 a b + intro he + exact hne (congrFun he ⟨v,hvQ⟩) + · exact hne + +noncomputable def joints (parent : I → Option I) (M : ℝ) (F : I → ι → V → ℝ) + (B : I → Finset V) (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) + (i j : I) (a b : State ι V) : ℝ := + if parent j = some i then edge M (F i) (F j) (B i) (B j) (fresh₁ i) (fresh₂ i) (C j) a b + else if parent i = some j then edge M (F j) (F i) (B j) (B i) (fresh₁ j) (fresh₂ j) (C i) b a + else 0 + +lemma joints_symmetric + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} {I : Type treewidthLevel3} [Fintype V] + [Fintype ι] [Fintype I] + (parent : I → Option I) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (F : I → ι → V → ℝ) (B : I → Finset V) + (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) : + TreeMarkov.Symmetric (fun _ : I => State ι V) (joints parent M F B fresh₁ fresh₂ C) := by + intro i j a b + by_cases hij : parent j = some i + · simp [joints,hij,hanti j i hij] + · by_cases hji : parent i = some j <;> simp [joints,hij,hji] + +lemma joints_eq + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} {I : Type treewidthLevel3} [Fintype V] + [Fintype ι] [Fintype I] + (parent : I → Option I) (M : ℝ) (F : I → ι → V → ℝ) + (B : I → Finset V) (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) + (i j : I) (hp : parent j = some i) : + joints parent M F B fresh₁ fresh₂ C i j = + edge M (F i) (F j) (B i) (B j) (fresh₁ i) (fresh₂ i) (C j) := by + funext a b + simp [joints,hp] + +lemma joints_coupling (T : SimpleGraph I) (parent : I → Option I) + (horient : ∀ i j, T.Adj i j → parent i = some j ∨ parent j = some i) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (F : I → ι → V → ℝ) (B : I → Finset V) + (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) + (hret : ∀ i j, parent j = some i → ∀ r ∈ C j, F i r = F j r) + (htrace : ∀ i j, parent j = some i → particleTrace M (F i) (B j) = particleTrace M (F j) (B j)) + (i j : I) (hij : T.Adj i j) : + IsCoupling (weight M (F i)) (weight M (F j)) (joints parent M F B fresh₁ fresh₂ C i j) := by + rcases horient i j hij with hji | hij + · have he : joints parent M F B fresh₁ fresh₂ C i j = + fun a b => edge M (F j) (F i) (B j) (B i) (fresh₁ j) (fresh₂ j) (C i) b a := by + funext a b + simp [joints,hji,hanti i j hji] + rw [he] + exact (edge_coupling M (F j) (F i) (B j) (B i) (fresh₁ j) (fresh₂ j) (C i) + (hret j i hji) (htrace j i hji)).symm + · rw [joints_eq parent M F B fresh₁ fresh₂ C i j hij] + exact edge_coupling M (F i) (F j) (B i) (B j) (fresh₁ i) (fresh₂ i) (C j) + (hret i j hij) (htrace i j hij) + +lemma joints_label (T : SimpleGraph I) (parent : I → Option I) + (horient : ∀ i j, T.Adj i j → parent i = some j ∨ parent j = some i) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (F : I → ι → V → ℝ) (B : I → Finset V) + (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) + (hret : ∀ i j, parent j = some i → ∀ r ∈ C j, F i r = F j r) + (htrace : ∀ i j, parent j = some i → particleTrace M (F i) (B j) = particleTrace M (F j) (B j)) + (i j : I) (hij : T.Adj i j) (a b : State ι V) + (hab : joints parent M F B fresh₁ fresh₂ C i j a b ≠ 0) + (v : V) (hvi : v ∈ B i) (hvj : v ∈ B j) : label a v = label b v := by + rcases horient i j hij with hji | hij + · have he := joints_symmetric parent hanti M F B fresh₁ fresh₂ C i j a b + rw [he, joints_eq parent M F B fresh₁ fresh₂ C j i hji] at hab + exact (edge_label M (F j) (F i) (B j) (B i) (fresh₁ j) (fresh₂ j) (C i) + (hret j i hji) (htrace j i hji) b a hab v hvj hvi).symm + · rw [joints_eq parent M F B fresh₁ fresh₂ C i j hij] at hab + exact edge_label M (F i) (F j) (B i) (B j) (fresh₁ i) (fresh₂ i) (C j) + (hret i j hij) (htrace i j hij) a b hab v hvi hvj +end BoundedTreewidthL1.ExpandedConstruction + +namespace BoundedTreewidthL1.ExpandedConstruction +open MeasureTheory ExpandedParticleLaw ReservationCoupling ReservedKernel ReservedSuffix +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι I : Type*} [Fintype V] [Fintype ι] [Fintype I] + +lemma weight_separation (M : ℝ) (F : ι → V → ℝ) + (hF : ∀ i v, |F i v| ≤ M) (u v : V) : + cutDistance (weight M F) label u v = ∑ i, |F i u-F i v| := by + unfold cutDistance + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro i _ + rw [Fintype.sum_prod_type] + have he (b : Bool) : (∑ ω : V → Bool, + if label (i,b,ω) u = label (i,b,ω) v then 0 else weight M F (i,b,ω)) = + |F i u-F i v|/2 := by + have hs := OrderedReservation.sum_event M (F i) (fun ω => ω u ≠ ω v) + rw [← cutSeparation, sweep_separation M (F i) (hF i)] at hs + rw [← hs, Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + cases b <;> cases hu : ω u <;> cases hv : ω v <;> simp [label,weight,hu,hv] + simp_rw [he] + simp + ; ring + +noncomputable def ensemble (T : SimpleGraph I) (parent : I → Option I) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (F : I → ι → V → ℝ) (B : I → Finset V) + (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) : (I → State ι V) → ℝ := + ExpandedTree.law T ((Fintype.card ι : ℝ)*(2*M)) (fun i => weight M (F i)) + (joints parent M F B fresh₁ fresh₂ C) + (joints_symmetric parent hanti M F B fresh₁ fresh₂ C) + +lemma ensemble_data (T : SimpleGraph I) (hT : T.IsTree) (parent : I → Option I) + (horient : ∀ i j, T.Adj i j → parent i = some j ∨ parent j = some i) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (hM : 0 < M) (hι : 0 < Fintype.card ι) + (F : I → ι → V → ℝ) (B : I → Finset V) + (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) + (hret : ∀ i j, parent j = some i → ∀ r ∈ C j, F i r = F j r) + (htrace : ∀ i j, parent j = some i → particleTrace M (F i) (B j) = particleTrace M (F j) (B j)) : + (∀ x, 0 ≤ ensemble T parent hanti M F B fresh₁ fresh₂ C x) ∧ + (∑ x, ensemble T parent hanti M F B fresh₁ fresh₂ C x) = (Fintype.card ι : ℝ)*(2*M) ∧ + ∀ i a, (∑ x, if x i = a then ensemble T parent hanti M F B fresh₁ fresh₂ C x else 0) = + weight M (F i) a := by + have hmass : 0 < (Fintype.card ι : ℝ)*(2*M) := by positivity + obtain ⟨hn,ht,hm⟩ := ExpandedTree.law_marginals T hT _ hmass _ _ + (joints_symmetric parent hanti M F B fresh₁ fresh₂ C) + (fun i => weight_nonneg M (F i)) (fun i => weight_total M hM.le (F i)) + (fun i j hij => (joints_coupling T parent horient hanti M F B fresh₁ fresh₂ C hret htrace i j hij).nonneg) + (fun i j hij => (joints_coupling T parent horient hanti M F B fresh₁ fresh₂ C hret htrace i j hij).row) + refine ⟨hn,ht,?_⟩ + intro i a + convert hm i a using 1 + congr 1 + funext x + split_ifs <;> rfl + +lemma ensemble_labels (T : SimpleGraph I) (parent : I → Option I) + (horient : ∀ i j, T.Adj i j → parent i = some j ∨ parent j = some i) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (F : I → ι → V → ℝ) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) + (hret : ∀ i j, parent j = some i → ∀ r ∈ C j, F i r = F j r) + (htrace : ∀ i j, parent j = some i → particleTrace M (F i) (B j) = particleTrace M (F j) (B j)) + (x : I → State ι V) (hx : ensemble T parent hanti M F B fresh₁ fresh₂ C x ≠ 0) + (i : I) (v : V) (hv : v ∈ B i) : + ExpandedTree.assemble (fun i => (B i : Set V)) hcover label x v = label (x i) v := by + exact ExpandedTree.law_labels T (fun i => (B i : Set V)) hcover hrun _ _ _ _ label + (joints_label T parent horient hanti M F B fresh₁ fresh₂ C hret htrace) x hx i v hv + +/-- Every bag has the exact particle metric, while the inter-bag coupling is +chosen to retain the sweep order of each currently reserved particle. -/ +lemma ensemble_cobag (T : SimpleGraph I) (hT : T.IsTree) (parent : I → Option I) + (horient : ∀ i j, T.Adj i j → parent i = some j ∨ parent j = some i) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (hM : 0 < M) (hι : 0 < Fintype.card ι) + (F : I → ι → V → ℝ) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) + (hret : ∀ i j, parent j = some i → ∀ r ∈ C j, F i r = F j r) + (htrace : ∀ i j, parent j = some i → particleTrace M (F i) (B j) = particleTrace M (F j) (B j)) + (i : I) (hF : ∀ r v, |F i r v| ≤ M) (u v : V) (hu : u ∈ B i) (hv : v ∈ B i) : + cutDistance (ensemble T parent hanti M F B fresh₁ fresh₂ C) + (ExpandedTree.assemble (fun i => (B i : Set V)) hcover label) u v = + ∑ r, |F i r u-F i r v| := by + rw [← weight_separation M (F i) hF u v] + have hm := (ensemble_data T hT parent horient hanti M hM hι F B fresh₁ fresh₂ C hret htrace).2.2 i + unfold cutDistance + have he : (∑ x : I → State ι V, + if ExpandedTree.assemble (fun i => (B i : Set V)) hcover label x u = + ExpandedTree.assemble (fun i => (B i : Set V)) hcover label x v then 0 + else ensemble T parent hanti M F B fresh₁ fresh₂ C x) = + ∑ x : I → State ι V, ensemble T parent hanti M F B fresh₁ fresh₂ C x * + (if label (x i) u = label (x i) v then 0 else 1) := by + apply Finset.sum_congr rfl + intro x _ + by_cases hz : ensemble T parent hanti M F B fresh₁ fresh₂ C x = 0 + · simp [hz] + · rw [ensemble_labels T parent horient hanti M F B hcover hrun fresh₁ fresh₂ C hret htrace x hz i u hu, + ensemble_labels T parent horient hanti M F B hcover hrun fresh₁ fresh₂ C hret htrace x hz i v hv] + split_ifs <;> simp + rw [he, ExpandedChain.sum_fiber_mul (fun x : I → State ι V => x i) + (ensemble T parent hanti M F B fresh₁ fresh₂ C) + (fun a => if label a u = label a v then 0 else 1)] + apply Finset.sum_congr rfl + intro a _ + have hh : (∑ x : I → State ι V, if x i = a then + ensemble T parent hanti M F B fresh₁ fresh₂ C x else 0) = weight M (F i) a := by + convert hm a using 1 + have hh' : (∑ x : I → State ι V, if x i = a then + ensemble T parent hanti M F B fresh₁ fresh₂ C x else 0) * + (if label a u = label a v then (0:ℝ) else 1) = + (if label a u = label a v then 0 else weight M (F i) a) := by + rw [hh] + split_ifs <;> simp + convert hh' using 1 + congr 1 + apply Finset.sum_congr rfl + intro x _ + split_ifs <;> rfl +end BoundedTreewidthL1.ExpandedConstruction + +namespace BoundedTreewidthL1.ExpandedMeasurable +open MeasureTheory ExpandedParticleLaw ExpandedParticleKernel ExpandedConstruction ReservedSuffix +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {Ω V ι I : Type*} [MeasurableSpace Ω] [Fintype V] [Fintype ι] [Fintype I] + +lemma selected {A : Type*} [Fintype A] [MeasurableSpace A] [MeasurableSingletonClass A] + (f : Ω → A → ℝ) (a : Ω → A) + (hf : ∀ b, Measurable (fun ω => f ω b)) (ha : Measurable a) : + Measurable (fun ω => f ω (a ω)) := by + have he : (fun ω => f ω (a ω)) = (fun ω => ∑ b, if a ω = b then f ω b else 0) := by + funext ω + simp + rw [he] + exact Finset.measurable_sum _ (fun b _ => (hf b).ite (measurableSet_eq_fun ha measurable_const) measurable_const) + +lemma measurable_marginal {A C : Type*} [Fintype A] + (f : A → C) (μ : Ω → A → ℝ) (hμ : ∀ a, Measurable (fun ω => μ ω a)) (c : C) : + Measurable (fun ω => marginal f (μ ω) c) := by + unfold marginal + apply Finset.measurable_sum + intro a _ + by_cases h : f a = c <;> simp only [h, ↓reduceIte] + · exact hμ a + · exact measurable_const + +lemma measurable_glue {A B C : Type*} [Fintype A] [Fintype B] + (f : A → C) (g : B → C) (μ : Ω → A → ℝ) (ν : Ω → B → ℝ) + (hμ : ∀ a, Measurable (fun ω => μ ω a)) (hν : ∀ b, Measurable (fun ω => ν ω b)) (a : A) (b : B) : + Measurable (fun ω => glueWeights f g (μ ω) (ν ω) a b) := by + unfold glueWeights + by_cases h : f a = g b <;> simp only [h, ↓reduceIte] + · exact ((hμ a).mul (hν b)).div (measurable_marginal f μ hμ (g b)) + · exact measurable_const + +lemma measurable_edge_fixed (M : ℝ) (F H : Ω → ι → V → ℝ) + (hF : ∀ a, Measurable (fun ω => weight M (F ω) a)) + (hH : ∀ a, Measurable (fun ω => weight M (H ω) a)) + (P Q : Finset V) (i j : ι) (C : Finset ι) (a b : State ι V) : + Measurable (fun ω => edge M (F ω) (H ω) P Q i j C a b) := by + unfold edge compose + apply Finset.measurable_sum + intro c _ + exact ((measurable_glue _ _ _ _ hF hF a c).mul + (measurable_glue _ _ _ _ hF hH c b)).div (hF c) + +lemma measurable_edge [MeasurableSpace ι] [MeasurableSingletonClass ι] + (M : ℝ) (F H : Ω → ι → V → ℝ) + (hF : ∀ a, Measurable (fun ω => weight M (F ω) a)) + (hH : ∀ a, Measurable (fun ω => weight M (H ω) a)) + (P Q : Finset V) (i j : Ω → ι) (C : Ω → Finset ι) + (hi : Measurable i) (hj : Measurable j) (hC : Measurable C) (a b : State ι V) : + Measurable (fun ω => edge M (F ω) (H ω) P Q (i ω) (j ω) (C ω) a b) := by + exact selected (fun ω (c : ι × ι × Finset ι) => edge M (F ω) (H ω) P Q c.1 c.2.1 c.2.2 a b) + (fun ω => (i ω,j ω,C ω)) (fun c => measurable_edge_fixed M F H hF hH P Q c.1 c.2.1 c.2.2 a b) + (hi.prodMk (hj.prodMk hC)) + +lemma measurable_joints + {Ω : Type treewidthLevel1} {V : Type treewidthLevel2} {ι : Type treewidthLevel3} + {I : Type treewidthLevel4} [MeasurableSpace Ω] [Fintype V] [Fintype ι] [Fintype I] + [MeasurableSpace ι] [MeasurableSingletonClass ι] + (parent : I → Option I) (M : ℝ) (F : Ω → I → ι → V → ℝ) (B : I → Finset V) + (hF : ∀ i a, Measurable (fun ω => weight M (F ω i) a)) + (fresh₁ fresh₂ : Ω → I → ι) (C : Ω → I → Finset ι) + (h₁ : ∀ i, Measurable (fun ω => fresh₁ ω i)) (h₂ : ∀ i, Measurable (fun ω => fresh₂ ω i)) + (hC : ∀ i, Measurable (fun ω => C ω i)) (i j : I) (a b : State ι V) : + Measurable (fun ω => joints parent M (F ω) B (fresh₁ ω) (fresh₂ ω) (C ω) i j a b) := by + unfold joints + split_ifs + · exact measurable_edge M _ _ (hF i) (hF j) _ _ _ _ _ (h₁ i) (h₂ i) (hC j) a b + · exact measurable_edge M _ _ (hF j) (hF i) _ _ _ _ _ (h₁ j) (h₂ j) (hC i) b a + · exact measurable_const + +lemma measurable_law {A : Type*} [Fintype A] (T : SimpleGraph I) (M : ℝ) + (μ : Ω → I → A → ℝ) (J : Ω → I → I → A → A → ℝ) + (hs : ∀ ω, TreeMarkov.Symmetric (fun _ : I => A) (J ω)) + (hμ : ∀ i a, Measurable (fun ω => μ ω i a)) + (hJ : ∀ i j a b, Measurable (fun ω => J ω i j a b)) (x : I → A) : + Measurable (fun ω => ExpandedTree.law T M (μ ω) (J ω) (hs ω) x) := by + unfold ExpandedTree.law TreeMarkov.density + apply Measurable.const_mul + apply Measurable.mul + · exact Finset.measurable_prod _ (fun i _ => (hμ i (x i)).div_const M) + · apply Finset.measurable_prod + intro e _ + induction e using Sym2.ind with + | _ i j => + simp only [TreeMarkov.edgeFactor_mk, TreeMarkov.interaction, ExpandedTree.jointLaw, ExpandedTree.marginalLaw] + exact ((hJ i j (x i) (x j)).div_const M).div + (((hμ i (x i)).div_const M).mul ((hμ j (x j)).div_const M)) + +/-- Measurability of the actual expanded tree law, allowing the reservation +indices and free pools to depend on all the previously sampled noise. -/ +lemma measurable_ensemble [MeasurableSpace ι] [MeasurableSingletonClass ι] + (T : SimpleGraph I) (parent : I → Option I) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (F : Ω → I → ι → V → ℝ) (B : I → Finset V) + (hF : ∀ i a, Measurable (fun ω => weight M (F ω i) a)) + (fresh₁ fresh₂ : Ω → I → ι) (C : Ω → I → Finset ι) + (h₁ : ∀ i, Measurable (fun ω => fresh₁ ω i)) (h₂ : ∀ i, Measurable (fun ω => fresh₂ ω i)) + (hC : ∀ i, Measurable (fun ω => C ω i)) (x : I → State ι V) : + Measurable (fun ω => ensemble T parent hanti M (F ω) B (fresh₁ ω) (fresh₂ ω) (C ω) x) := by + exact measurable_law T _ _ _ _ hF (measurable_joints parent M F B hF fresh₁ fresh₂ C h₁ h₂ hC) x +end BoundedTreewidthL1.ExpandedMeasurable + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/Cuts.lean b/lean/OAI/Combinatorics/TreewidthL1/Cuts.lean new file mode 100644 index 0000000000000000000000000000000000000000..08de907a813c9ac77e4154fcc7413fed1f589156 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/Cuts.lean @@ -0,0 +1,544 @@ +import OAI.Combinatorics.TreewidthL1.WeightedPaths + +namespace OAI + +universe treewidthLevel1 + +namespace BoundedTreewidthL1 +open MeasureTheory Set +open scoped ENNReal + +variable {V : Type*} [Fintype V] + +noncomputable def thresholdLabels (F : V → ℝ) (t : ℝ) : V → Bool := + fun v => decide (t < F v) + +noncomputable def sweep (M : ℝ) (F : V → ℝ) : Measure (V → Bool) := + (volume.restrict (Icc (-M) M)).map (thresholdLabels F) + +def complementCut (ω : V → Bool) : V → Bool := fun v => !(ω v) + +noncomputable def symmetrizeCut (μ : Measure (V → Bool)) : Measure (V → Bool) := + (1 / 2 : ℝ≥0∞) • (μ + μ.map complementCut) + +def cutEvent (P : Finset V) (z : V) (b : P → Bool) (q : Bool) : Set (V → Bool) := + {ω | (∀ s : P, ω s = b s) ∧ ω z = q} + +noncomputable def cutUncertainty (μ : Measure (V → Bool)) (P : Finset V) (z : V) : ℝ := by + classical + exact ∑ b : P → Bool, min (μ.real (cutEvent P z b false)) (μ.real (cutEvent P z b true)) + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open MeasureTheory Set +open scoped ENNReal +variable {V : Type*} [Fintype V] + +lemma measurable_thresholdLabels + {V : Type treewidthLevel1} [Fintype V] + (F : V → ℝ) : Measurable (thresholdLabels F) := by + apply Measurable.of_eval + intro v + have h : Measurable (fun t : ℝ => if t < F v then true else false) := + Measurable.ite (measurableSet_lt measurable_id measurable_const) + measurable_const measurable_const + convert h using 1 + ext t + simp [thresholdLabels] + +instance sweep_finite (M : ℝ) (F : V → ℝ) : IsFiniteMeasure (sweep M F) := by + unfold sweep + infer_instance + +lemma cutEvent_measurable (P : Finset V) (z : V) (b : P → Bool) (q : Bool) : + MeasurableSet (cutEvent P z b q) := (Set.toFinite _).measurableSet + +lemma measurable_complementCut : Measurable (complementCut (V := V)) := + measurable_of_finite _ + +instance symmetrizeCut_finite (μ : Measure (V → Bool)) [IsFiniteMeasure μ] : + IsFiniteMeasure (symmetrizeCut μ) := by + constructor + change (1 / 2 : ℝ≥0∞) * (μ + μ.map complementCut) Set.univ < ⊤ + finiteness + +lemma complementCut_involutive + {V : Type treewidthLevel1} [Fintype V] : Function.Involutive (complementCut (V := V)) := by + intro ω + funext v + simp [complementCut] + +def complementEquiv (V : Type*) : (V → Bool) ≃ (V → Bool) where + toFun := complementCut + invFun := complementCut + left_inv := by intro ω; funext v; simp [complementCut] + right_inv := by intro ω; funext v; simp [complementCut] + +lemma complement_preimage_event + {V : Type treewidthLevel1} [Fintype V] + (P : Finset V) (z : V) (b : P → Bool) (q : Bool) : + complementCut ⁻¹' cutEvent P z b q = + cutEvent P z (complementCut b) (!q) := by + ext ω + simp only [Set.mem_preimage, cutEvent, Set.mem_ofPred_eq, complementCut] + constructor + · rintro ⟨h, hz⟩ + constructor + · intro s + have := congrArg Bool.not (h s) + simpa using this + · have := congrArg Bool.not hz + simpa using this + · rintro ⟨h, hz⟩ + constructor + · intro s + have := congrArg Bool.not (h s) + simpa using this + · have := congrArg Bool.not hz + simpa using this + +lemma uncertainty_nonneg + {V : Type treewidthLevel1} [Fintype V] + (μ : Measure (V → Bool)) (P : Finset V) (z : V) : + 0 ≤ cutUncertainty μ P z := + Finset.sum_nonneg (fun _ _ => le_min measureReal_nonneg measureReal_nonneg) + +lemma uncertainty_add + {V : Type treewidthLevel1} [Fintype V] + (μ ν : Measure (V → Bool)) [IsFiniteMeasure μ] + [IsFiniteMeasure ν] (P : Finset V) (z : V) : + cutUncertainty μ P z + cutUncertainty ν P z ≤ cutUncertainty (μ + ν) P z := by + classical + simp only [cutUncertainty, ← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro b _ + rw [measureReal_add_apply (by finiteness) (by finiteness), + measureReal_add_apply (by finiteness) (by finiteness)] + exact min_add_min_le_min_add_add + +lemma uncertainty_complement (μ : Measure (V → Bool)) (P : Finset V) (z : V) : + cutUncertainty (μ.map complementCut) P z = cutUncertainty μ P z := by + classical + simp only [cutUncertainty, map_measureReal_apply measurable_complementCut + (cutEvent_measurable _ _ _ _), complement_preimage_event, Bool.not_false, + Bool.not_true] + simp_rw [min_comm] + simpa only [complementEquiv, Equiv.coe_fn_mk] using (complementEquiv P).sum_comp + (fun b : P → Bool => min (μ.real (cutEvent P z b false)) + (μ.real (cutEvent P z b true))) + +lemma uncertainty_symmetrize (μ : Measure (V → Bool)) [IsFiniteMeasure μ] + (P : Finset V) (z : V) : + cutUncertainty μ P z ≤ cutUncertainty (symmetrizeCut μ) P z := by + classical + have h := uncertainty_add μ (μ.map complementCut) P z + rw [uncertainty_complement] at h + have heq : cutUncertainty (symmetrizeCut μ) P z = + cutUncertainty (μ + μ.map complementCut) P z / 2 := by + simp only [cutUncertainty, symmetrizeCut, measureReal_ennreal_smul_apply] + norm_num + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro b _ + simp only [one_div_mul_eq_div, min_div_div_right (by norm_num : (0 : ℝ) ≤ 2)] + rw [heq] + linarith + +lemma sweep_event (M : ℝ) (F : V → ℝ) (P : Finset V) (z : V) + (b : P → Bool) (q : Bool) : + (sweep M F).real (cutEvent P z b q) = + volume.real ((thresholdLabels F ⁻¹' cutEvent P z b q) ∩ Icc (-M) M) := by + rw [sweep, map_measureReal_apply (measurable_thresholdLabels F) (cutEvent_measurable ..), + measureReal_restrict_apply ((measurable_thresholdLabels F) (cutEvent_measurable ..))] + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open MeasureTheory Set +open scoped ENNReal +variable {V : Type*} [Fintype V] + +lemma thresholdLabels_constant_gap + {V : Type treewidthLevel1} [Fintype V] + (F : V → ℝ) (z s : V) (t a : ℝ) + (_ : 0 < t) (hs : t ≤ |F z - F s|) + (ha : F z - t < a ∧ a < F z + t) : + thresholdLabels F a s = thresholdLabels F (F z) s := by + by_cases h : F z < F s + · rw [abs_of_neg (sub_neg.mpr h)] at hs + have h' : a < F s := by linarith + simp [thresholdLabels, h, h'] + · rw [abs_of_nonneg (sub_nonneg.mpr (le_of_not_gt h))] at hs + have h' : ¬a < F s := by linarith + simp [thresholdLabels, h, h'] + +lemma sweep_height_gap_unsymmetrized (M : ℝ) (F : V → ℝ) (P : Finset V) + (z : V) (t : ℝ) (ht : 0 < t) (hm : -M ≤ F z - t ∧ F z + t ≤ M) + (hgap : ∀ s ∈ P, t ≤ |F z - F s|) : + t ≤ cutUncertainty (sweep M F) P z := by + classical + let b : P → Bool := fun s => thresholdLabels F (F z) s + have hfinite (q : Bool) : + volume ((thresholdLabels F ⁻¹' cutEvent P z b q) ∩ Icc (-M) M) ≠ ⊤ := + measure_ne_top_of_subset Set.inter_subset_right (by rw [Real.volume_Icc]; finiteness) + have hleft : Ioo (F z - t) (F z) ⊆ + (thresholdLabels F ⁻¹' cutEvent P z b true) ∩ Icc (-M) M := by + rintro a ⟨hal, har⟩ + refine ⟨⟨?_, ?_⟩, ?_⟩ + · intro s + exact thresholdLabels_constant_gap F z s t a ht (hgap s s.property) + ⟨hal, by linarith⟩ + · simp [thresholdLabels, har] + · constructor <;> linarith [hm.1, hm.2] + have hright : Ioo (F z) (F z + t) ⊆ + (thresholdLabels F ⁻¹' cutEvent P z b false) ∩ Icc (-M) M := by + rintro a ⟨hal, har⟩ + refine ⟨⟨?_, ?_⟩, ?_⟩ + · intro s + exact thresholdLabels_constant_gap F z s t a ht (hgap s s.property) + ⟨by linarith, har⟩ + · simp [thresholdLabels, show ¬a < F z by linarith] + · constructor <;> linarith [hm.1, hm.2] + have hl := measureReal_mono hleft (hfinite true) + have hr := measureReal_mono hright (hfinite false) + rw [Real.volume_real_Ioo_of_le (by linarith)] at hl + rw [Real.volume_real_Ioo_of_le (by linarith)] at hr + rw [← sweep_event] at hl hr + have hmin : t ≤ min ((sweep M F).real (cutEvent P z b false)) + ((sweep M F).real (cutEvent P z b true)) := by + apply le_min <;> linarith + exact hmin.trans (Finset.single_le_sum + (f := fun b : P → Bool => min ((sweep M F).real (cutEvent P z b false)) + ((sweep M F).real (cutEvent P z b true))) + (fun _ _ => le_min measureReal_nonneg measureReal_nonneg) (Finset.mem_univ b)) + +theorem sweep_height_gap (M : ℝ) (F : V → ℝ) (P : Finset V) (z : V) (t : ℝ) + (ht : 0 < t) (hm : -M ≤ F z - t ∧ F z + t ≤ M) + (hgap : ∀ s ∈ P, t ≤ |F z - F s|) : + t ≤ cutUncertainty (symmetrizeCut (sweep M F)) P z := + (sweep_height_gap_unsymmetrized M F P z t ht hm hgap).trans + (uncertainty_symmetrize (sweep M F) P z) + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open MeasureTheory Set +open scoped ENNReal +variable {V : Type*} [Fintype V] + +lemma symmetrizeCut_add (μ ν : Measure (V → Bool)) : + symmetrizeCut (μ + ν) = symmetrizeCut μ + symmetrizeCut ν := by + simp only [symmetrizeCut, Measure.map_add _ _ measurable_complementCut, smul_add] + ac_rfl + +lemma sweep_pair_gap_ordered (M : ℝ) (F H : V → ℝ) (A : Finset V) (z : V) + (hA : ∀ s ∈ A, F s = H s) (horder : F z ≤ H z) + (hm : -M ≤ F z ∧ H z ≤ M) : + H z - F z ≤ cutUncertainty (sweep M F + sweep M H) A z := by + classical + let E (b : A → Bool) : Set ℝ := Ioo (F z) (H z) ∩ + thresholdLabels F ⁻¹' {ω | ∀ s : A, ω s = b s} + have hEm (b : A → Bool) : MeasurableSet (E b) := + measurableSet_Ioo.inter + ((measurable_thresholdLabels F) (Set.toFinite _).measurableSet) + have hEF (b : A → Bool) : E b ⊆ + (thresholdLabels F ⁻¹' cutEvent A z b false) ∩ Icc (-M) M := by + rintro a ⟨⟨hal, har⟩, hb⟩ + refine ⟨⟨hb, ?_⟩, ?_⟩ + · simp [thresholdLabels, show ¬a < F z by linarith] + · constructor <;> linarith [hm.1, hm.2] + have hEH (b : A → Bool) : E b ⊆ + (thresholdLabels H ⁻¹' cutEvent A z b true) ∩ Icc (-M) M := by + rintro a ⟨⟨hal, har⟩, hb⟩ + refine ⟨⟨?_, ?_⟩, ?_⟩ + · intro s + change decide (a < H s) = b s + rw [← hA s s.property] + exact hb s + · simp [thresholdLabels, har] + · constructor <;> linarith [hm.1, hm.2] + have hfinF (b : A → Bool) : volume + ((thresholdLabels F ⁻¹' cutEvent A z b false) ∩ Icc (-M) M) ≠ ⊤ := + measure_ne_top_of_subset Set.inter_subset_right (by rw [Real.volume_Icc]; finiteness) + have hfinH (b : A → Bool) : volume + ((thresholdLabels H ⁻¹' cutEvent A z b true) ∩ Icc (-M) M) ≠ ⊤ := + measure_ne_top_of_subset Set.inter_subset_right (by rw [Real.volume_Icc]; finiteness) + have hfinE (b : A → Bool) : volume (E b) ≠ ⊤ := + measure_ne_top_of_subset (hEF b) (hfinF b) + have hdis : Pairwise (Function.onFun Disjoint E) := by + intro b c hbc + apply Set.disjoint_left.mpr + intro a hb hc + apply hbc + funext s + exact (hb.2 s).symm.trans (hc.2 s) + have hcover : (⋃ b : A → Bool, E b) = Ioo (F z) (H z) := by + ext a + constructor + · intro ha + obtain ⟨b, hb⟩ := Set.mem_iUnion.mp ha + exact hb.1 + · intro ha + exact Set.mem_iUnion.mpr ⟨fun s => thresholdLabels F a s, ha, fun _ => rfl⟩ + have hsum := measureReal_iUnion_fintype hdis hEm hfinE + rw [hcover, Real.volume_real_Ioo_of_le horder] at hsum + rw [hsum, cutUncertainty] + apply Finset.sum_le_sum + intro b _ + have hF := measureReal_mono (hEF b) (hfinF b) + have hH := measureReal_mono (hEH b) (hfinH b) + rw [← sweep_event] at hF hH + rw [measureReal_add_apply (by finiteness) (by finiteness), + measureReal_add_apply (by finiteness) (by finiteness)] + apply le_min + · exact hF.trans (le_add_of_nonneg_right measureReal_nonneg) + · exact hH.trans (le_add_of_nonneg_left measureReal_nonneg) + +theorem sweep_launch_gap (M : ℝ) (f g : V → ℝ) (A : Finset V) + (hg : ∀ s ∈ A, g s = 0) + (hm : ∀ v, |f v + g v| ≤ M ∧ |f v - g v| ≤ M) (z : V) : + 2 * |g z| ≤ cutUncertainty + (symmetrizeCut (sweep M (fun v => f v + g v)) + + symmetrizeCut (sweep M (fun v => f v - g v))) A z := by + classical + rw [← symmetrizeCut_add] + apply le_trans _ (uncertainty_symmetrize _ A z) + have hA : ∀ s ∈ A, f s - g s = f s + g s := by + intro s hs + rw [hg s hs] + ring + rcases le_total 0 (g z) with h | h + · have hgap := sweep_pair_gap_ordered M (fun v => f v - g v) + (fun v => f v + g v) A z hA (by linarith) + ⟨(abs_le.mp (hm z).2).1, (abs_le.mp (hm z).1).2⟩ + calc + 2 * |g z| = (f z + g z) - (f z - g z) := by rw [abs_of_nonneg h]; ring + _ ≤ _ := by + rw [add_comm (sweep M (fun v => f v + g v)) + (sweep M (fun v => f v - g v))] + exact hgap + · have hgap := sweep_pair_gap_ordered M (fun v => f v + g v) + (fun v => f v - g v) A z (fun s hs => (hA s hs).symm) (by linarith) + ⟨(abs_le.mp (hm z).1).1, (abs_le.mp (hm z).2).2⟩ + calc + 2 * |g z| = (f z - g z) - (f z + g z) := by rw [abs_of_nonpos h]; ring + _ ≤ _ := hgap + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open MeasureTheory Set +open scoped ENNReal +variable {V : Type*} [Fintype V] + +noncomputable def cutTrace (μ : Measure (V → Bool)) (P : Finset V) : Measure (P → Bool) := + μ.map (fun ω s => ω s) + +noncomputable def cutSeparation (μ : Measure (V → Bool)) (u v : V) : ℝ := + μ.real {ω | ω u ≠ ω v} + +def CommonWeakOrder (P : Finset V) (F H : V → ℝ) : Prop := + ∃ e : Fin P.card ≃ P, + Monotone (fun i => F (e i)) ∧ Monotone (fun i => H (e i)) + +def partialCutEvent (P Q : Finset V) : Set (V → Bool) := + {ω | (∀ p ∈ P, ω p = true) ∧ ∀ q ∈ Q, ω q = false} + +/-- On a finite Boolean cube, all-true conjunctions determine a finite measure. +The proof retains the total mass (the conjunction over the empty set). -/ +lemma cutMeasure_ext_all_true (μ ν : Measure (V → Bool)) [IsFiniteMeasure μ] + [IsFiniteMeasure ν] + (heq : ∀ P : Finset V, μ.real {ω | ∀ p ∈ P, ω p = true} = + ν.real {ω | ∀ p ∈ P, ω p = true}) : μ = ν := by + classical + have hpartial (Q : Finset V) : ∀ P : Finset V, + μ.real (partialCutEvent P Q) = ν.real (partialCutEvent P Q) := by + induction Q using Finset.induction_on with + | empty => + intro P + simpa [partialCutEvent] using heq P + | @insert a Q ha ih => + intro P + have hpart : partialCutEvent P Q = + partialCutEvent (insert a P) Q ∪ partialCutEvent P (insert a Q) := by + ext ω + simp only [partialCutEvent, Set.mem_ofPred_eq, Finset.mem_insert, + forall_eq_or_imp, Set.mem_union] + cases h : ω a <;> simp + have hdis : Disjoint (partialCutEvent (insert a P) Q) + (partialCutEvent P (insert a Q)) := by + apply Set.disjoint_left.mpr + intro ω h₁ h₂ + have ht := h₁.1 a (Finset.mem_insert_self a P) + have hf := h₂.2 a (Finset.mem_insert_self a Q) + simp_all + have hμ := measureReal_union hdis + (Set.toFinite (partialCutEvent P (insert a Q))).measurableSet + (μ := μ) + have hν := measureReal_union hdis + (Set.toFinite (partialCutEvent P (insert a Q))).measurableSet + (μ := ν) + rw [← hpart] at hμ hν + linarith [ih P, ih (insert a P)] + apply Measure.ext_of_singleton + intro ω + have hs : ({ω} : Set (V → Bool)) = partialCutEvent + (Finset.univ.filter fun v => ω v = true) + (Finset.univ.filter fun v => ω v = false) := by + ext η + simp only [Set.mem_singleton_iff, partialCutEvent, Set.mem_ofPred_eq, + Finset.mem_filter, Finset.mem_univ, true_and] + constructor + · rintro rfl + exact ⟨fun _ h => h, fun _ h => h⟩ + · rintro ⟨h₁, h₂⟩ + funext v + cases h : ω v + · exact h₂ v h + · exact h₁ v h + apply (measureReal_eq_measureReal_iff (by finiteness) (by finiteness)).mp + rw [hs] + exact hpartial _ _ + +lemma sweep_all_true_of_min (M : ℝ) (F : V → ℝ) (P : Finset V) + (a : V) (ha : a ∈ P) (hmin : ∀ p ∈ P, F a ≤ F p) + (hm : -M ≤ F a ∧ F a ≤ M) : + (sweep M F).real {ω | ∀ p ∈ P, ω p = true} = F a + M := by + rw [sweep, map_measureReal_apply (measurable_thresholdLabels F) + (Set.toFinite _).measurableSet, + measureReal_restrict_apply ((measurable_thresholdLabels F) (Set.toFinite _).measurableSet)] + have hset : (thresholdLabels F ⁻¹' {ω | ∀ p ∈ P, ω p = true}) ∩ Icc (-M) M = + Ico (-M) (F a) := by + ext t + constructor + · rintro ⟨h, hM⟩ + exact ⟨hM.1, of_decide_eq_true (h a ha)⟩ + · rintro ⟨hl, hr⟩ + refine ⟨?_, ⟨hl, le_trans hr.le hm.2⟩⟩ + intro p hp + exact decide_eq_true (hr.trans_le (hmin p hp)) + rw [hset, Real.volume_real_Ico_of_le hm.1] + ring + +lemma sweep_total_mass (M : ℝ) (hM : 0 ≤ M) (F : V → ℝ) : + (sweep M F).real Set.univ = 2 * M := by + rw [sweep, map_measureReal_apply (measurable_thresholdLabels F) MeasurableSet.univ] + simp only [Set.preimage_univ, measureReal_restrict_apply_univ] + rw [Real.volume_real_Icc_of_le (by linarith)] + ring + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open MeasureTheory Set +open scoped ENNReal +variable {V : Type*} [Fintype V] + +lemma sweep_affine_of_common_min (M : ℝ) (hM : 0 ≤ M) (F H : V → ℝ) + (hF : ∀ v, |F v| ≤ M) (hH : ∀ v, |H v| ≤ M) + (hmin : ∀ P : Finset V, P.Nonempty → + ∃ a ∈ P, ∀ p ∈ P, F a ≤ F p ∧ H a ≤ H p) : + sweep M F + sweep M H = + sweep M (fun v => (F v + H v) / 2) + sweep M (fun v => (F v + H v) / 2) := by + classical + apply cutMeasure_ext_all_true + intro P + rw [measureReal_add_apply (by finiteness) (by finiteness), + measureReal_add_apply (by finiteness) (by finiteness)] + by_cases hP : P.Nonempty + · obtain ⟨a, ha, ham⟩ := hmin P hP + have haF := abs_le.mp (hF a) + have haH := abs_le.mp (hH a) + rw [sweep_all_true_of_min M F P a ha (fun p hp => (ham p hp).1) haF, + sweep_all_true_of_min M H P a ha (fun p hp => (ham p hp).2) haH, + sweep_all_true_of_min M (fun v => (F v + H v) / 2) P a ha + (by intro p hp; linarith [(ham p hp).1, (ham p hp).2]) + (by constructor <;> linarith)] + ring + · have hPe : P = ∅ := Finset.not_nonempty_iff_eq_empty.mp hP + have hevent : {ω : V → Bool | ∀ p ∈ (∅ : Finset V), ω p = true} = univ := by + ext ω + simp + rw [hPe, hevent, sweep_total_mass M hM, sweep_total_mass M hM, sweep_total_mass M hM] + +lemma cutTrace_add (μ ν : Measure (V → Bool)) (P : Finset V) : + cutTrace (μ + ν) P = cutTrace μ P + cutTrace ν P := by + exact Measure.map_add _ _ (measurable_of_finite _) + +lemma cutTrace_sweep (M : ℝ) (F : V → ℝ) (P : Finset V) : + cutTrace (sweep M F) P = sweep M (fun p : P => F p) := by + rw [cutTrace, sweep, Measure.map_map (measurable_of_finite _) (measurable_thresholdLabels F)] + rfl + +theorem sweep_trace_update (M : ℝ) (hM : 0 < M) (F H g : V → ℝ) (P : Finset V) + (horder : CommonWeakOrder P F H) (hg : ∀ s ∈ P, g s = 0) + (hF : ∀ v, |F v| ≤ M) (hH : ∀ v, |H v| ≤ M) + (_ : ∀ v, |(F v + H v) / 2 + g v| ≤ M) + (_ : ∀ v, |(F v + H v) / 2 - g v| ≤ M) : + cutTrace (sweep M F + sweep M H) P = + cutTrace (sweep M (fun v => (F v + H v) / 2 + g v) + + sweep M (fun v => (F v + H v) / 2 - g v)) P := by + classical + simp only [cutTrace_add, cutTrace_sweep] + have hp' : (fun p : P => (F p + H p) / 2 + g p) = + (fun p : P => (F p + H p) / 2) := by + funext p + rw [hg p p.property, add_zero] + have hn' : (fun p : P => (F p + H p) / 2 - g p) = + (fun p : P => (F p + H p) / 2) := by + funext p + rw [hg p p.property, sub_zero] + rw [hp', hn'] + apply sweep_affine_of_common_min M hM.le (fun p : P => F p) (fun p : P => H p) + (fun p => hF p) (fun p => hH p) + intro S hS + obtain ⟨e, heF, heH⟩ := horder + obtain ⟨a, ha, hmina⟩ := Finset.exists_min_image S (fun p => e.symm p) hS + refine ⟨a, ha, ?_⟩ + intro p hp + simpa only [Equiv.apply_symm_apply] using + And.intro (heF (hmina p hp)) (heH (hmina p hp)) + +lemma sweep_separation_ordered (M : ℝ) (F : V → ℝ) (u v : V) + (h : F u ≤ F v) (hm : -M ≤ F u ∧ F v ≤ M) : + cutSeparation (sweep M F) u v = F v - F u := by + rw [cutSeparation, sweep, map_measureReal_apply (measurable_thresholdLabels F) + (Set.toFinite _).measurableSet, + measureReal_restrict_apply ((measurable_thresholdLabels F) (Set.toFinite _).measurableSet)] + have hset : (thresholdLabels F ⁻¹' {ω | ω u ≠ ω v}) ∩ Icc (-M) M = + Ico (F u) (F v) := by + ext t + constructor + · rintro ⟨hne, _⟩ + by_cases hu : t < F u + · have hv : t < F v := hu.trans_le h + simp [thresholdLabels, hu, hv] at hne + · have hv : t < F v := by + by_contra hv + simp [thresholdLabels, hu, hv] at hne + exact ⟨le_of_not_gt hu, hv⟩ + · rintro ⟨hu, hv⟩ + refine ⟨?_, ⟨hm.1.trans hu, hv.le.trans hm.2⟩⟩ + simp [thresholdLabels, show ¬t < F u from not_lt.mpr hu, hv] + rw [hset, Real.volume_real_Ico_of_le h] + +theorem sweep_separation (M : ℝ) (F : V → ℝ) (hF : ∀ v, |F v| ≤ M) (u v : V) : + cutSeparation (sweep M F) u v = |F u - F v| := by + rcases le_total (F u) (F v) with h | h + · rw [sweep_separation_ordered M F u v h + ⟨(abs_le.mp (hF u)).1, (abs_le.mp (hF v)).2⟩, + abs_of_nonpos (sub_nonpos.mpr h)] + ring + · have he : cutSeparation (sweep M F) u v = cutSeparation (sweep M F) v u := by + unfold cutSeparation + congr 1 + ext ω + exact ne_comm + rw [he, sweep_separation_ordered M F v u h + ⟨(abs_le.mp (hF v)).1, (abs_le.mp (hF u)).2⟩, + abs_of_nonneg (sub_nonneg.mpr h)] + +end BoundedTreewidthL1 + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/ExpandedAnchor.lean b/lean/OAI/Combinatorics/TreewidthL1/ExpandedAnchor.lean new file mode 100644 index 0000000000000000000000000000000000000000..cecc8f985114e67236fa69729a7d0225357b38e3 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/ExpandedAnchor.lean @@ -0,0 +1,294 @@ +import OAI.Combinatorics.TreewidthL1.Construction + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 + +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I J : Type*} [Fintype V] [Fintype I] [Fintype J] [DecidableEq V] + +end BoundedTreewidthL1.ParticleLaws + +namespace BoundedTreewidthL1.ParticleBatch +open ParticleSchedule +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι J : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + +def pairIndex (p : J → ι × ι) (a : J) (b : Bool) : ι := if b then (p a).2 else (p a).1 + +def PairUnique (C : Finset J) (p : J → ι × ι) : Prop := + ∀ a ∈ C, ∀ b ∈ C, ∀ u v : Bool, pairIndex p a u = pairIndex p b v → a = b ∧ u = v + +lemma pairIndex_mem {C : Finset J} (p : J → ι × ι) {a : J} (ha : a ∈ C) (b : Bool) : + pairIndex p a b ∈ usedPairs C p := by + cases b + · exact first_mem_used ha p + · exact second_mem_used ha p + +lemma PairUnique.mono + {ι : Type treewidthLevel1} {J : Type treewidthLevel2} [Fintype ι] [Nonempty ι] + {C D : Finset J} {p : J → ι × ι} (h : PairUnique D p) (hs : C ⊆ D) : + PairUnique C p := fun a ha b hb u v => h a (hs ha) b (hs hb) u v + +lemma PairUnique.empty + {ι : Type treewidthLevel1} {J : Type treewidthLevel2} [Fintype ι] [Nonempty ι] + (p : J → ι × ι) : PairUnique ∅ p := by + intro a ha + simp at ha + +lemma PairUnique.update {C : Finset J} {p : J → ι × ι} (hp : PairUnique C p) + (a : J) (ha : a ∉ C) (z : ι × ι) + (hz : z.1 ∉ usedPairs C p ∧ z.2 ∉ usedPairs C p ∧ z.1 ≠ z.2) : + PairUnique (insert a C) (Function.update p a z) := by + intro b hb c hc u v he + have hnew (w : Bool) : pairIndex (Function.update p a z) a w ∉ usedPairs C p := by + cases w + · simpa [pairIndex] using hz.1 + · simpa [pairIndex] using hz.2.1 + rcases Finset.mem_insert.mp hb with hba | hb + · subst b + rcases Finset.mem_insert.mp hc with hca | hc + · subst c + refine ⟨rfl,?_⟩ + cases u <;> cases v <;> simp_all [pairIndex] + · have hca : c ≠ a := fun h => ha (h ▸ hc) + have he' : pairIndex (Function.update p a z) a u = pairIndex p c v := by + simpa [pairIndex,Function.update_of_ne hca] using he + exact False.elim (hnew u (he'.symm ▸ pairIndex_mem p hc v)) + · have hba : b ≠ a := fun h => ha (h ▸ hb) + rcases Finset.mem_insert.mp hc with hca | hc + · subst c + have he' : pairIndex p b u = pairIndex (Function.update p a z) a v := by + simpa [pairIndex,Function.update_of_ne hba] using he + exact False.elim (hnew v (he' ▸ pairIndex_mem p hb u)) + · have hca : c ≠ a := fun h => ha (h ▸ hc) + apply hp b hb c hc u v + simpa [pairIndex,Function.update_of_ne hba,Function.update_of_ne hca] using he + +lemma launchBatch_unique (k q : ℕ) (hN : Fintype.card ι = 2*q + k.factorial+2) + (P : Finset V) (hP : P.card ≤ k) (l : List J) (C : Finset J) + (hl : l.Nodup) (hfresh : ∀ a ∈ l, a ∉ C) (hcount : (C ∪ l.toFinset).card ≤ q) + (F : ι → V → ℝ) (p : J → ι × ι) (hp : PairUnique C p) (g : J → V → ℝ) : + PairUnique (C ∪ l.toFinset) (launchBatch P l C F p g).2 := by + induction l generalizing C F p with + | nil => simpa [launchBatch] using hp + | cons a l ih => + have haC : a ∉ C := hfresh a (by simp) + let z := pickPair P (usedPairs C p) F + let F₁ := functionPairUpdate F z.1 z.2 (g a) + let p₁ := Function.update p a z + have hC : C.card ≤ q := (Finset.card_le_card Finset.subset_union_left).trans hcount + have hz : z.1 ∉ usedPairs C p ∧ z.2 ∉ usedPairs C p ∧ z.1 ≠ z.2 ∧ + CommonWeakOrder P (F z.1) (F z.2) := + pickPair_spec k q hN P hP _ ((usedPairs_card C p).trans (by omega)) F + have hnewCount : (insert a C ∪ l.toFinset).card ≤ q := by + simpa only [List.toFinset_cons, Finset.insert_union, Finset.union_insert] using hcount + have hnewFresh : ∀ b ∈ l, b ∉ insert a C := by + intro b hb h + rcases Finset.mem_insert.mp h with h | h + · subst b + exact (List.nodup_cons.mp hl).1 hb + · exact hfresh b (by simp [hb]) h + have hn : PairUnique (insert a C) p₁ := hp.update a haC z ⟨hz.1,hz.2.1,hz.2.2.1⟩ + have hres := ih (insert a C) hl.of_cons hnewFresh hnewCount F₁ p₁ hn + simpa only [List.toFinset_cons, Finset.insert_union, Finset.union_insert, launchBatch] using hres + +end BoundedTreewidthL1.ParticleBatch + +namespace BoundedTreewidthL1.AnchorTreeParticles +open ParticleBatch +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι I J : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + +/-- All simultaneously reserved pairs are disjoint in the ACTUAL depth-recursive +branching preparation. In particular every strictly older active reservation +avoids both indices reserved by the fresh own-bag launch. -/ +theorem state_unique (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (k q : ℕ) (hN : Fintype.card ι = 2*q+k.factorial+2) + (hbag : ∀ i, (bag i).card ≤ k) (hA : ∀ i, (A i).card ≤ q) : + ∀ i, PairUnique (A i) (state (ι := ι) R bag A g i).2 := by + intro i + induction hi : R.depth i using Nat.strong_induction_on generalizing i with + | h n ih => + let S := state (ι := ι) R bag A g + have hp : PairUnique (retained R A i) ((R.parent i).elim seed S).2 := by + cases he : R.parent i with + | none => simp [retained,he,PairUnique.empty] + | some p => + have hu := ih (R.depth p) (by have := R.decreases i p he; omega) p rfl + simpa only [retained,he,Option.elim_some] using hu.mono Finset.inter_subset_right + have hb := batch_data R A i (hA i) + have hr := launchBatch_unique k q hN (bag i) (hbag i) (fresh R A i).toList (retained R A i) + hb.1 hb.2.1 hb.2.2 ((R.parent i).elim seed S).1 ((R.parent i).elim seed S).2 hp (g i) + rw [state_eq] + simpa only [step,Finset.toList_toFinset,fresh,Finset.union_sdiff_of_subset (retained_subset R A i)] using hr +end BoundedTreewidthL1.AnchorTreeParticles + +namespace BoundedTreewidthL1.ExpandedAnchor +open MeasureTheory AnchorTreeParticles ParticleBatch ExpandedParticleLaw ExpandedConstruction +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I ι Ω : Type*} [Fintype V] [Fintype I] [Fintype ι] [Nonempty ι] + [MeasurableSpace Ω] [MeasurableSpace ι] [MeasurableSingletonClass ι] + +lemma parent_antisymm + {I : Type treewidthLevel1} [Fintype I] + (R : RootedForest I) (i j : I) + (h : R.parent i = some j) : R.parent j ≠ some i := by + intro h' + have := R.decreases i j h + have := R.decreases j i h' + omega + +noncomputable def law (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (A : I → Finset I) (g : I → I → V → ℝ) (M : ℝ) : + (I → State ι V) → ℝ := + let R := RootedTree.forest T hT root + let S := state (ι := ι) R B A g + ensemble T R.parent (parent_antisymm R) M (fun i => (S i).1) B + (fun i => ((S i).2 i).1) (fun i => ((S i).2 i).2) + (fun i => usedPairs (retained R A i) (S i).2) + +lemma retained_functions + {V : Type treewidthLevel1} {I : Type treewidthLevel2} {ι : Type treewidthLevel3} [Fintype V] + [Fintype I] [Fintype ι] [Nonempty ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + (R : RootedForest I) (A : I → Finset I) + (S : I → (ι → V → ℝ) × (I → ι × ι)) + (hpairs : ∀ i p, R.parent i = some p → ∀ a ∈ A i ∩ A p, + (S i).2 a = (S p).2 a ∧ + (S i).1 ((S i).2 a).1 = (S p).1 ((S p).2 a).1 ∧ + (S i).1 ((S i).2 a).2 = (S p).1 ((S p).2 a).2) : + ∀ p i, R.parent i = some p → ∀ r ∈ usedPairs (retained R A i) (S i).2, + (S p).1 r = (S i).1 r := by + intro p i hpi r hr + simp only [usedPairs,retained,hpi,Option.elim_some,Finset.mem_union,Finset.mem_image] at hr + rcases hr with ⟨a,ha,rfl⟩ | ⟨a,ha,rfl⟩ + · obtain ⟨he,hf,_⟩ := hpairs i p hpi a ha + simpa only [he] using hf.symm + · obtain ⟨he,_,hf⟩ := hpairs i p hpi a ha + simpa only [he] using hf.symm + +lemma measurable_law (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (A : I → Finset I) (g : Ω → I → I → V → ℝ) (M : ℝ) + (hg : ∀ i a v, Measurable (fun ω => g ω i a v)) (x : I → State ι V) : + Measurable (fun ω => law T hT root B A (g ω) M x) := by + let R := RootedTree.forest T hT root + let S := fun ω => state (ι := ι) R B A (g ω) + have hs (i : I) : Measurable (fun ω => S ω i) := measurable_state R B A g hg i + have hf (i : I) (r : ι) (v : V) : Measurable (fun ω => (S ω i).1 r v) := + (measurable_pi_apply v).comp ((measurable_pi_apply r).comp (hs i).fst) + have hp (i a : I) : Measurable (fun ω => (S ω i).2 a) := + (measurable_pi_apply a).comp (hs i).snd + apply ExpandedMeasurable.measurable_ensemble T R.parent (parent_antisymm R) M + (fun ω i => (S ω i).1) B _ + (fun ω i => ((S ω i).2 i).1) (fun ω i => ((S ω i).2 i).2) + (fun ω i => usedPairs (retained R A i) (S ω i).2) + (fun i => (hp i i).fst) (fun i => (hp i i).snd) _ x + · intro i a + exact (ParticleSchedule.measurable_sweep_real M (fun ω => (S ω i).1 a.1) + (hf i a.1) {a.2.2}).div_const 2 + · intro i + exact (Measurable.of_discrete (f := usedPairs (retained R A i))).comp (hs i).snd + +/-- Actual expanded-state law and its average L1 metric. No consistency or +measurable gluing choice is part of the hypotheses. -/ +theorem realization + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (hT : T.IsTree) (root : I) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (A : I → Finset I) (k q : ℕ) (hbag : ∀ i, (B i).card ≤ k) + (hA : ∀ i, (A i).card ≤ q) (hN : Fintype.card ι = 2*q+k.factorial+2) + (ν : Measure Ω) [IsProbabilityMeasure ν] + (L H Δ : ℝ) (hL : 0 < L) (hH : 0 < H) (hΔ : 0 < Δ) + (g : Ω → I → I → V → ℝ) + (hg : ∀ i a v, Measurable (fun ω => g ω i a v)) + (hLip : ∀ ω i a u v, |g ω i a u-g ω i a v| ≤ L*shortestPathDistance G ℓ u v) + (hHeight : ∀ ω i a v, |g ω i a v| ≤ H) + (hzero : ∀ ω i a v, v ∈ B i → g ω i a v = 0) : + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + let cut := ExpandedTree.assemble (fun i => (B i : Set V)) hcover (label (ι := ι)) + let w := fun ω => law (ι := ι) T hT root B A (g ω) M + (∀ ω x, 0 ≤ w ω x) ∧ + (∀ ω, ∑ x, w ω x = (Fintype.card ι : ℝ)*(2*M)) ∧ + (∀ x, Integrable (fun ω => w ω x) ν) ∧ + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ = ∫ ω, cutDistance (w ω) cut u v ∂ν) ∧ + (∀ u v, ‖Φ u - Φ v‖ ≤ (Fintype.card ι : ℝ)*L*((Fintype.card ι : ℝ)-1)*shortestPathDistance G ℓ u v) ∧ + ∀ i (u v : B i), ‖Φ u.val - Φ v.val‖ = + ∫ ω, ∑ r, |(state (ι := ι) (RootedTree.forest T hT root) B A (g ω) i).1 r u - + (state (ι := ι) (RootedTree.forest T hT root) B A (g ω) i).1 r v| ∂ν := by + let R := RootedTree.forest T hT root + let S := fun ω => state (ι := ι) R B A (g ω) + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + let cut := ExpandedTree.assemble (fun i => (B i : Set V)) hcover (label (ι := ι)) + let w := fun ω => law (ι := ι) T hT root B A (g ω) M + have hcard : (1:ℝ) ≤ Fintype.card ι := by exact_mod_cast Fintype.card_pos + have hM : 0 < M := by + have := mul_nonneg hH.le (sub_nonneg.mpr hcard) + dsimp [M]; linarith + have hs (ω : Ω) := forest_particle_realization (ι := ι) R B A k q hbag hA hN + (shortestPathDistance G ℓ) L H Δ hH hΔ (g ω) (hLip ω) (hHeight ω) (hzero ω) + have hret (ω : Ω) := retained_functions R A (S ω) (hs ω).2.2.1 + have ht (ω : Ω) : ∀ i j, R.parent j = some i → + particleTrace M (S ω i).1 (B j) = particleTrace M (S ω j).1 (B j) := + fun i j hj => ((hs ω).2.1 j i hj).symm + have hd (ω : Ω) := ensemble_data T hT R.parent + (fun _ _ hij => RootedTree.edge_orientation T hT root hij) + (parent_antisymm R) M hM Fintype.card_pos (fun i => (S ω i).1) B + (fun i => ((S ω i).2 i).1) (fun i => ((S ω i).2 i).2) + (fun i => usedPairs (retained R A i) (S ω i).2) (hret ω) (ht ω) + have hwn : ∀ ω x, 0 ≤ w ω x := fun ω => (hd ω).1 + have hwt : ∀ ω, ∑ x, w ω x = (Fintype.card ι : ℝ)*(2*M) := fun ω => (hd ω).2.1 + have hwi (x : I → State ι V) : Integrable (fun ω => w ω x) ν := by + apply Integrable.of_bound (measurable_law T hT root B A g M hg x).aestronglyMeasurable + ((Fintype.card ι : ℝ)*(2*M)) + filter_upwards [] with ω + rw [Real.norm_eq_abs,abs_of_nonneg (hwn ω x), ← hwt ω] + exact Finset.single_le_sum (fun y _ => hwn ω y) (Finset.mem_univ x) + obtain ⟨n,Φ,hΦ⟩ := averaged_cut_realization ν w cut hwn hwi + have hheight (ω : Ω) (i : I) : ∀ r v, |(S ω i).1 r v| ≤ M := by + intro r v + have := function_particles_height_bound hH ((hs ω).1 i) r v + dsimp [M]; linarith + have heq (i : I) (u v : B i) : ‖Φ u.val - Φ v.val‖ = + ∫ ω, ∑ r, |(S ω i).1 r u-(S ω i).1 r v| ∂ν := by + rw [hΦ] + apply integral_congr_ae + filter_upwards [] with ω + exact ensemble_cobag T hT R.parent + (fun _ _ hij => RootedTree.edge_orientation T hT root hij) (parent_antisymm R) + M hM Fintype.card_pos (fun i => (S ω i).1) B hcover hrun + (fun i => ((S ω i).2 i).1) (fun i => ((S ω i).2 i).2) + (fun i => usedPairs (retained R A i) (S ω i).2) (hret ω) (ht ω) + i (hheight ω i) u v u.property v.property + refine ⟨hwn,hwt,hwi,n,Φ,hΦ,?_,heq⟩ + apply ParticleLaws.norm_bound_from_edges G hG ℓ _ Φ + intro u v huv + obtain ⟨i,hu,hv⟩ := hedge u v huv + rw [heq i ⟨u,hu⟩ ⟨v,hv⟩] + have hsum (ω : Ω) : (∑ r, |(S ω i).1 r u-(S ω i).1 r v|) ≤ + (Fintype.card ι : ℝ)*L*((Fintype.card ι : ℝ)-1)*ℓ ⟨s(u,v),huv⟩ := by + have hd := shortestPathDistance_pos G ℓ hG hℓ huv.ne + calc + _ ≤ ∑ r : ι, L*((Fintype.card ι : ℝ)-1)*shortestPathDistance G ℓ u v := + Finset.sum_le_sum (fun r _ => function_particles_difference_bound hL ((hs ω).1 i) r u v hd) + _ = (Fintype.card ι : ℝ)*L*((Fintype.card ι : ℝ)-1)*shortestPathDistance G ℓ u v := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left ?_ (by positivity) + have he := shortestPathDistance_le_walkLength G ℓ (fun e => (hℓ e).le) huv.toWalk + simpa [SimpleGraph.Adj.toWalk,walkLength] using he + apply (le_abs_self _).trans + change ‖∫ ω, (∑ r, |(S ω i).1 r u-(S ω i).1 r v|) ∂ν‖ ≤ _ + have hb := norm_integral_le_of_norm_le_const (μ := ν) + (Filter.Eventually.of_forall (fun ω => show ‖∑ r, |(S ω i).1 r u-(S ω i).1 r v|‖ ≤ _ from by + rw [Real.norm_eq_abs,abs_of_nonneg (Finset.sum_nonneg (fun r _ => abs_nonneg _))] + exact hsum ω)) + simpa only [probReal_univ,mul_one] using hb +end BoundedTreewidthL1.ExpandedAnchor + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/ExpandedParticles.lean b/lean/OAI/Combinatorics/TreewidthL1/ExpandedParticles.lean new file mode 100644 index 0000000000000000000000000000000000000000..b9a78397bed70b468aab76a395862d5b0f0cc07a --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/ExpandedParticles.lean @@ -0,0 +1,515 @@ +import OAI.Combinatorics.TreewidthL1.LaunchNoise + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1 +open MeasureTheory LaunchNoise AnchorTreeParticles +attribute [local instance] Classical.decEq Classical.propDecidable + +theorem anchor_embedding_preparation (k : ℕ) (hk : 2 ≤ k) : + ∃ α π : ℝ, 0 < α ∧ α ≤ 1/8 ∧ 0 < π ∧ π ≤ 1 ∧ + ∀ (V : Type) [Fintype V] [DecidableEq V] [Nontrivial V] + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (m : ℕ) (T : SimpleGraph (Fin m)) (hT : T.IsTree) (root : Fin m) + (B : Fin m → Finset V) (hne : ∀ i, (B i).Nonempty) + (_ : ∀ v, ∃ i, v ∈ B i) + (_ : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (_ : ∀ v, (T.induce {i | v ∈ B i}).Connected) + (_ : ∀ i, (B i).card ≤ k) (J η : ℝ), 0 < η → η < 1/4 → + let := weightedMetricSpace G ℓ hG hℓ + let D := fun i => bagDistance G ℓ (B i) (hne i) + ∃ seed : (i : Fin m) → OrdinarySeed (D i) α π η, + let Ω := (i : Fin m) → NoiseSpace (seed i).n (seed i).m + let law : Measure Ω := Measure.pi (fun i => noiseLaw (seed i).m (seed i).mass) + let A := TreeCache.active T hT root B D k (shortestPathDistance G ℓ) J + let N := 2*(AnchorCache.cacheBound k+1) + k.factorial + 2 + let g : Ω → Fin m → Fin m → V → ℝ := + fun ω i _ => noiseG (D i) (seed i).bump (ω i) + let S := fun ω => state (ι := Fin N) (RootedTree.forest T hT root) B A (g ω) + ∃ H : ℝ, 0 < H ∧ IsProbabilityMeasure law ∧ + (∀ i a v, Measurable (fun ω => g ω i a v)) ∧ + (∀ ω i, FunctionParticleReachable (shortestPathDistance G ℓ) 3 H (S ω i).1) ∧ + (∀ ω i p, (RootedTree.forest T hT root).parent i = some p → + particleTrace (H*((N:ℝ)-1)+2) (S ω i).1 (B i) = + particleTrace (H*((N:ℝ)-1)+2) (S ω p).1 (B i)) ∧ + (∀ ω i p, (RootedTree.forest T hT root).parent i = some p → ∀ a ∈ A i ∩ A p, + (S ω i).2 a = (S ω p).2 a ∧ + (S ω i).1 ((S ω i).2 a).1 = (S ω p).1 ((S ω p).2 a).1 ∧ + (S ω i).1 ((S ω i).2 a).2 = (S ω p).1 ((S ω p).2 a).2) ∧ + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ ≤ 3*(N:ℝ)*((N:ℝ)-1)*shortestPathDistance G ℓ u v) ∧ + ∀ i a, a ∈ A i → ∀ (u v : B i), + 2*(∫ ω, |g ω a a u - g ω a a v| ∂law) ≤ ‖Φ u.val - Φ v.val‖ := by + classical + obtain ⟨α,π,hα,hα8,hπ,hπ1,hsampler⟩ := graph_ordinary_noise k hk + refine ⟨α,π,hα,hα8,hπ,hπ1,?_⟩ + intro V _ _ _ G hG ℓ hℓ m T hT root B hne hcover hedge hrun hbag J η hη hη4 + let := weightedMetricSpace G ℓ hG hℓ + let D := fun i => bagDistance G ℓ (B i) (hne i) + have hdec : HasTreeDecomposition G k := ⟨m,T,B,hT,hcover,hedge,hrun,hbag⟩ + have hnoise (i : Fin m) : HasOrdinaryNoise (D i) α π η := by + have hn := hsampler V G hG hdec ℓ hℓ (B i : Set V) (hne i) η hη hη4 + have heq : D i = fun x => Metric.infDist x (B i : Set V) := by + funext x + exact bagDistance_eq_infDist G hG ℓ hℓ (B i) (hne i) x + rw [heq] + exact hn + let seed : (i : Fin m) → OrdinarySeed (D i) α π η := + fun i => Classical.choice (OrdinarySeed.exists_of_has (hnoise i)) + refine ⟨seed,?_⟩ + let Ω := (i : Fin m) → NoiseSpace (seed i).n (seed i).m + let (i : Fin m) : IsProbabilityMeasure (noiseLaw (seed i).m (seed i).mass) := (seed i).probability + let law : Measure Ω := Measure.pi (fun i => noiseLaw (seed i).m (seed i).mass) + let A := TreeCache.active T hT root B D k (shortestPathDistance G ℓ) J + let q := AnchorCache.cacheBound k+1 + let N := 2*q+k.factorial+2 + have hN : 2 ≤ N := by dsimp [N]; omega + let g : Ω → Fin m → Fin m → V → ℝ := fun ω i _ => noiseG (D i) (seed i).bump (ω i) + let R := RootedTree.forest T hT root + let S := fun ω => state (ι := Fin N) R B A (g ω) + let H : ℝ := 1+3*∑ i, ∑ v, D i v + have hD : ∀ i v, 0 ≤ D i v := fun i v => + bagDistance_nonneg G ℓ hG (fun e => (hℓ e).le) (B i) (hne i) v + have hsum : 0 ≤ ∑ i, ∑ v, D i v := + Finset.sum_nonneg (fun i _ => Finset.sum_nonneg (fun v _ => hD i v)) + have hH : 0 < H := by dsimp [H]; positivity + have hdH (i : Fin m) (v : V) : (5/2)*D i v ≤ H := by + have hv := Finset.single_le_sum (fun x (_ : x ∈ (Finset.univ : Finset V)) => hD i x) + (Finset.mem_univ v) + have hi : (∑ x, D i x) ≤ ∑ j, ∑ x, D j x := + Finset.single_le_sum (fun j (_ : j ∈ (Finset.univ : Finset (Fin m))) => + Finset.sum_nonneg (fun x _ => hD j x)) (Finset.mem_univ i) + dsimp [H] + linarith [hD i v] + have hg : ∀ i a v, Measurable (fun ω : Ω => g ω i a v) := by + intro i a v + exact ((measurable_pi_apply v).comp (seed i).measurable).comp (measurable_pi_apply i) + have hLip : ∀ ω i a, ∀ u v, |g ω i a u-g ω i a v| ≤ 3*shortestPathDistance G ℓ u v := by + intro ω i a u v + exact ((seed i).bounds (ω i)).2.2.1.dist_le_mul u v + have hHeight : ∀ ω i a v, |g ω i a v| ≤ H := by + intro ω i a v + have hb := ((seed i).bounds (ω i)).2.2.2 v + rw [abs_of_nonneg ((hD i v).trans hb.1)] + exact hb.2.trans (hdH i v) + have hz : ∀ ω i a, ∀ v ∈ B i, g ω i a v = 0 := by + intro ω i a v hv + have hb := ((seed i).bounds (ω i)).2.2.2 v + have he : D i v = 0 := by + rw [show D i v = Metric.infDist v (B i : Set V) from + bagDistance_eq_infDist G hG ℓ hℓ (B i) (hne i) v] + exact Metric.infDist_zero_of_mem hv + rw [he] at hb + dsimp only [g] + linarith + have hA : ∀ i, (A i).card ≤ q := + TreeCache.graph_active_bound G ℓ hG hℓ T B hne hT root hedge hrun k hbag J + have hf (ω : Ω) := forest_particle_realization (ι := Fin N) R B A k q hbag hA + (by simp [N]) (shortestPathDistance G ℓ) 3 H 1 hH (by norm_num) + (g ω) (hLip ω) (hHeight ω) (hz ω) + refine ⟨H,hH,inferInstance,hg,?_,?_,?_,?_⟩ + · intro ω i + exact (hf ω).1 i + · intro ω i p hp + simpa only [Fintype.card_fin,mul_one] using (hf ω).2.1 i p hp + · intro ω i p hp a ha + exact (hf ω).2.2.1 i p hp a ha + · obtain ⟨n,Φ,hup,hlo⟩ := averaged_origin_realization (ι := Fin N) G hG ℓ hℓ T hT root B + hcover hedge (fun v => (hrun v).preconnected) A k q hbag hA (by simp [N]) + law 3 H 1 (by norm_num) hH (by norm_num) g hg hLip hHeight hz + refine ⟨n,Φ,?_,?_⟩ + · intro u v + simpa only [Fintype.card_fin,mul_comm (N:ℝ) 3] using hup u v + · intro i a ha u v + have hh := hlo i a ha u v + have ho : origin R A root i a = a := by + have hh := TreeCache.origin_self T hT root B D k (shortestPathDistance G ℓ) J i a ha + have hd : (Classical.decEq (Fin m)) = (instDecidableEqFin m) := Subsingleton.elim _ _ + rw [hd] at hh + exact hh + rwa [ho] at hh +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 + +lemma marginal_mono {A C : Type*} [Fintype A] + (f : A → C) {μ ν : A → ℝ} (h : ∀ a, μ a ≤ ν a) (c : C) : + marginal f μ c ≤ marginal f ν c := by + classical + apply Finset.sum_le_sum + intro a _ + split_ifs <;> simp_all + +lemma marginal_add {A C : Type*} [Fintype A] + (f : A → C) (μ ν : A → ℝ) (c : C) : + marginal f (μ + ν) c = marginal f μ c + marginal f ν c := by + classical + unfold marginal + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> simp + +lemma marginal_smul {A C : Type*} [Fintype A] + (f : A → C) (μ : A → ℝ) (r : ℝ) (c : C) : + marginal f (r • μ) c = r * marginal f μ c := by + classical + unfold marginal + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> simp + +lemma marginal_comp {A B C : Type*} [Fintype A] [Fintype B] + (f : A → B) (g : B → C) (μ : A → ℝ) (c : C) : + marginal g (marginal f μ) c = marginal (g ∘ f) μ c := by + classical + unfold marginal + have hexpand : (∑ b : B, if g b = c then ∑ a : A, if f a = b then μ a else 0 else 0) = + ∑ b : B, ∑ a : A, if g b = c then (if f a = b then μ a else 0) else 0 := by + apply Finset.sum_congr rfl + intro b _ + split_ifs <;> simp + rw [hexpand, Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + trans ∑ b : B, if f a = b then (if g b = c then μ a else 0) else 0 + · apply Finset.sum_congr rfl + intro b _ + split_ifs <;> rfl + · simp + +lemma marginal_total {A C : Type*} [Fintype A] [Fintype C] + (f : A → C) (μ : A → ℝ) : (∑ c, marginal f μ c) = ∑ a, μ a := by + classical + simp only [marginal] + rw [Finset.sum_comm] + simp + +lemma glueWeights_row_formula {A B C : Type*} [Fintype A] [Fintype B] + (f : A → C) (g : B → C) (μ : A → ℝ) (ν : B → ℝ) (a : A) : + (∑ b, glueWeights f g μ ν a b) = + μ a * marginal g ν (f a) / marginal f μ (f a) := by + classical + simp only [marginal, Finset.mul_sum, Finset.sum_div] + apply Finset.sum_congr rfl + intro b _ + unfold glueWeights marginal + by_cases h : f a = g b + · simp only [h, ↓reduceIte] + · simp [h, Ne.symm h] + +lemma glueWeights_col_formula {A B C : Type*} [Fintype A] [Fintype B] + (f : A → C) (g : B → C) (μ : A → ℝ) (ν : B → ℝ) (b : B) : + (∑ a, glueWeights f g μ ν a b) = + marginal f μ (g b) * ν b / marginal f μ (g b) := by + classical + rw [marginal, Finset.sum_mul, Finset.sum_div] + apply Finset.sum_congr rfl + intro a _ + unfold glueWeights + by_cases h : f a = g b + · simp [h, marginal] + · simp [h] + +theorem glueWeights_of_submarginal {A B C : Type*} [Fintype A] [Fintype B] + (f : A → C) (g : B → C) (μ : A → ℝ) (ν : B → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hν : ∀ b, 0 ≤ ν b) + (hdom : ∀ c, marginal g ν c ≤ marginal f μ c) : + (∀ a b, 0 ≤ glueWeights f g μ ν a b) ∧ + (∀ a, (∑ b, glueWeights f g μ ν a b) ≤ μ a) ∧ + (∀ b, (∑ a, glueWeights f g μ ν a b) = ν b) := by + refine ⟨glueWeights_nonneg f g μ ν hμ hν, ?_, ?_⟩ + · intro a + rw [glueWeights_row_formula] + by_cases hm : marginal f μ (f a) = 0 + · simp [hm, hμ a] + · apply (div_le_iff₀ (lt_of_le_of_ne (marginal_nonneg f μ hμ _) (Ne.symm hm))).mpr + exact mul_le_mul_of_nonneg_left (hdom _) (hμ a) + · intro b + rw [glueWeights_col_formula] + by_cases hm : marginal f μ (g b) = 0 + · have hn : ν b = 0 := by + have h1 := le_marginal g ν hν b + have h2 := hdom (g b) + rw [hm] at h2 + exact le_antisymm (h1.trans h2) (hν b) + simp [hm, hn] + · exact mul_div_cancel_left₀ (ν b) hm + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.ExpandedParticleKernel +open scoped BigOperators + +/-- A finite transition coupling. We compose couplings, not stochastic kernels, +so zero-mass states require no arbitrary probability distribution. -/ +noncomputable def compose {A B C : Type*} [Fintype B] + (μ : B → ℝ) (J : A → B → ℝ) (K : B → C → ℝ) (a : A) (c : C) : ℝ := + ∑ b, J a b * K b c / μ b + + theorem retained_or_free_marginal {A B C : Type*} [Fintype A] + (key : A → Option B) (trace : A → C) (μ ν : A → ℝ) + (hret : ∀ a, key a ≠ none → μ a = ν a) + (ht : ∀ c, marginal trace μ c = marginal trace ν c) : + ∀ z, marginal (fun a => (key a, trace a)) μ z = + marginal (fun a => (key a, trace a)) ν z := by + classical + rintro ⟨k, c⟩ + cases k with + | some b => + unfold marginal + apply Finset.sum_congr rfl + intro a _ + by_cases h : (key a, trace a) = (some b, c) + · have hk : key a = some b := congrArg Prod.fst h + have he := hret a (by simp [hk]) + simp only [h, ↓reduceIte, he] + · simp only [h, ↓reduceIte] + | none => + have he : (∑ a, if key a ≠ none ∧ trace a = c then μ a else 0) = + ∑ a, if key a ≠ none ∧ trace a = c then ν a else 0 := by + apply Finset.sum_congr rfl + intro a _ + split_ifs with h + · exact hret a h.1 + · rfl + have hs (ρ : A → ℝ) : marginal trace ρ c = + marginal (fun a => (key a, trace a)) ρ (none, c) + + ∑ a, if key a ≠ none ∧ trace a = c then ρ a else 0 := by + unfold marginal + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro a _ + by_cases hk : key a = none <;> by_cases ht : trace a = c <;> simp [hk, ht] + have ha := ht c + rw [hs μ, hs ν, he] at ha + exact add_right_cancel ha + + theorem compose_coupling {A B C : Type*} [Fintype A] [Fintype B] [Fintype C] + (μ : A → ℝ) (ν : B → ℝ) (ξ : C → ℝ) + (J : A → B → ℝ) (K : B → C → ℝ) + (_ : ∀ a, 0 ≤ μ a) (hν : ∀ b, 0 ≤ ν b) (_ : ∀ c, 0 ≤ ξ c) + (hJ : ∀ a b, 0 ≤ J a b) (hK : ∀ b c, 0 ≤ K b c) + (hrJ : ∀ a, ∑ b, J a b = μ a) (hcJ : ∀ b, ∑ a, J a b = ν b) + (hrK : ∀ b, ∑ c, K b c = ν b) (hcK : ∀ c, ∑ b, K b c = ξ c) : + (∀ a c, 0 ≤ compose ν J K a c) ∧ + (∀ a, ∑ c, compose ν J K a c = μ a) ∧ + (∀ c, ∑ a, compose ν J K a c = ξ c) := by + classical + have hJ0 (b : B) (hb : ν b = 0) : ∀ a, J a b = 0 := by + intro a + have h := Finset.single_le_sum (s := Finset.univ) (fun a _ => hJ a b) + (Finset.mem_univ a) + rw [hcJ, hb] at h + exact le_antisymm h (hJ a b) + have hK0 (b : B) (hb : ν b = 0) : ∀ c, K b c = 0 := by + intro c + have h := Finset.single_le_sum (s := Finset.univ) (fun c _ => hK b c) + (Finset.mem_univ c) + rw [hrK, hb] at h + exact le_antisymm h (hK b c) + refine ⟨fun a c => Finset.sum_nonneg (fun b _ => + div_nonneg (mul_nonneg (hJ a b) (hK b c)) (hν b)), ?_, ?_⟩ + · intro a + unfold compose + rw [Finset.sum_comm] + have he (b : B) : (∑ c, J a b * K b c / ν b) = J a b := by + rw [← Finset.sum_div, ← Finset.mul_sum, hrK] + by_cases hb : ν b = 0 + · simp [hb, hJ0 b hb a] + · exact mul_div_cancel_right₀ (J a b) hb + simp_rw [he] + exact hrJ a + · intro c + unfold compose + rw [Finset.sum_comm] + have he (b : B) : (∑ a, J a b * K b c / ν b) = K b c := by + rw [← Finset.sum_div, ← Finset.sum_mul, hcJ] + by_cases hb : ν b = 0 + · simp [hb, hK0 b hb c] + · exact mul_div_cancel_left₀ (K b c) hb + simp_rw [he] + exact hcK c + + theorem compose_trace {A B C D : Type*} [Fintype B] + (ν : B → ℝ) (J : A → B → ℝ) (K : B → C → ℝ) + (f : A → D) (g : B → D) (h : C → D) + (hJ : ∀ a b, f a ≠ g b → J a b = 0) + (hK : ∀ b c, g b ≠ h c → K b c = 0) + (a : A) (c : C) (hne : f a ≠ h c) : compose ν J K a c = 0 := by + classical + apply Finset.sum_eq_zero + intro b _ + by_cases hfg : f a = g b + · have hgh : g b ≠ h c := fun he => hne (hfg.trans he) + simp [hK b c hgh] + · simp [hJ a b hfg] + +end BoundedTreewidthL1.ExpandedParticleKernel + +namespace BoundedTreewidthL1.ExpandedParticleLaw +open MeasureTheory Set +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι : Type*} [Fintype V] [Fintype ι] + +abbrev State (ι V : Type*) := ι × Bool × (V → Bool) + +def label (a : State ι V) (v : V) : Bool := + if a.2.1 then !(a.2.2 v) else a.2.2 v + +noncomputable def weight (M : ℝ) (F : ι → V → ℝ) (a : State ι V) : ℝ := + (sweep M (F a.1)).real {a.2.2} / 2 + +def trace (P : Finset V) (a : State ι V) : P → Bool := fun v => label a v + +/-- At incoming updates, the entire state is retained on protected particles. +Every remaining state is pooled in one free class. -/ +noncomputable def incomingKey (C : Finset ι) (a : State ι V) : Option (State ι V) := + if a.1 ∈ C then some a else none + +/-- Departure reheats the fresh pair jointly and every other index separately. +Orientation is retained in either case. -/ +noncomputable def departureKey (a b : ι) (x : State ι V) : ι × Bool := + (if x.1 = b then a else x.1, x.2.1) + +noncomputable def incoming (M : ℝ) (F H : ι → V → ℝ) (P : Finset V) (C : Finset ι) := + glueWeights (fun a => (incomingKey C a, trace P a)) + (fun a => (incomingKey C a, trace P a)) (weight M F) (weight M H) + +noncomputable def departure (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (a b : ι) := + glueWeights (fun x => (departureKey a b x, trace P x)) + (fun x => (departureKey a b x, trace P x)) (weight M F) (weight M F) + +lemma weight_nonneg + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] + (M : ℝ) (F : ι → V → ℝ) (a : State ι V) : 0 ≤ weight M F a := + div_nonneg measureReal_nonneg (by norm_num) + +lemma finite_event {A : Type*} [Fintype A] [MeasurableSpace A] + [MeasurableSingletonClass A] (μ : Measure A) [IsFiniteMeasure μ] (p : A → Prop) : + (∑ a, if p a then μ.real {a} else 0) = μ.real {a | p a} := by + classical + have h := sum_measureReal_singleton (μ := μ) (Finset.univ.filter p) + simpa only [Finset.sum_filter, Finset.coe_filter, Finset.coe_univ, + Finset.mem_univ, true_and] using h + +lemma oriented_marginal (M : ℝ) (F : V → ℝ) (P : Finset V) (b : P → Bool) : + (∑ q : Bool, ∑ ω : V → Bool, + if (fun v : P => if q then !(ω v) else ω v) = b then + (sweep M F).real {ω}/2 else 0) = + (symmetrizeCut (sweep M F)).real {ω | (fun v : P => ω v) = b} := by + classical + rw [Fintype.sum_bool] + have ht : (∑ ω : V → Bool, + if (fun v : P => !(ω v)) = b then (sweep M F).real {ω}/2 else 0) = + (sweep M F).real {ω | (fun v : P => !(ω v)) = b}/2 := by + rw [← finite_event, Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> simp + have hf : (∑ ω : V → Bool, + if (fun v : P => ω v) = b then (sweep M F).real {ω}/2 else 0) = + (sweep M F).real {ω | (fun v : P => ω v) = b}/2 := by + rw [← finite_event, Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> simp + simp only [Bool.false_eq_true, ↓reduceIte] + rw [ht, hf, symmetrizeCut, measureReal_ennreal_smul_apply, + measureReal_add_apply (by finiteness) (by finiteness), + map_measureReal_apply measurable_complementCut (Set.toFinite _).measurableSet] + have he : complementCut ⁻¹' {ω : V → Bool | (fun v : P => ω v) = b} = + {ω : V → Bool | (fun v : P => !(ω v)) = b} := rfl + rw [he] + norm_num + ring + +/-- Exact original symmetric bag trace; no change of the prepared marginal. -/ + theorem trace_marginal (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (b : P → Bool) : + marginal (trace P) (weight M F) b = (particleTrace M F P).real {b} := by + classical + unfold marginal + simp only [Fintype.sum_prod_type] + have he (i : ι) : (∑ x : Bool, ∑ ω : V → Bool, + if trace P (i,x,ω) = b then weight M F (i,x,ω) else 0) = + (symmetrizeCut (sweep M (F i))).real {ω | (fun v : P => ω v) = b} := + oriented_marginal M (F i) P b + trans ∑ i, (symmetrizeCut (sweep M (F i))).real {ω | (fun v : P => ω v) = b} + · apply Finset.sum_congr rfl + intro i _ + convert he i using 1 + apply Finset.sum_congr rfl + intro q _ + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> rfl + rw [particleTrace, measureReal_def, Measure.finsetSum_apply, + ENNReal.toReal_sum (fun i _ => by unfold cutTrace; finiteness)] + apply Finset.sum_congr rfl + intro i _ + exact (map_measureReal_apply (measurable_of_finite _) (measurableSet_singleton b)).symm + + theorem incoming_coupling (M : ℝ) (F H : ι → V → ℝ) (P : Finset V) (C : Finset ι) + (hret : ∀ i ∈ C, F i = H i) (htrace : particleTrace M F P = particleTrace M H P) : + (∀ a b, 0 ≤ incoming M F H P C a b) ∧ + (∀ a, ∑ b, incoming M F H P C a b = weight M F a) ∧ + (∀ b, ∑ a, incoming M F H P C a b = weight M H b) ∧ + (∀ a b, trace P a ≠ trace P b → incoming M F H P C a b = 0) ∧ + (∀ a b, a.1 ∈ C → a ≠ b → incoming M F H P C a b = 0) := by + classical + have ht (b : P → Bool) : marginal (trace P) (weight M F) b = + marginal (trace P) (weight M H) b := by rw [trace_marginal, trace_marginal, htrace] + have hr (a : State ι V) (ha : incomingKey C a ≠ none) : weight M F a = weight M H a := by + have hc : a.1 ∈ C := by simpa [incomingKey] using ha + unfold weight + rw [hret a.1 hc] + have hcons := ExpandedParticleKernel.retained_or_free_marginal + (incomingKey C) (trace P) (weight M F) (weight M H) hr ht + refine ⟨glueWeights_nonneg _ _ _ _ (weight_nonneg M F) (weight_nonneg M H), + glueWeights_row _ _ _ _ (weight_nonneg M F) hcons, + (glueWeights_marginals _ _ _ _ (weight_nonneg M F) (weight_nonneg M H) hcons).2.2, ?_, ?_⟩ + · intro a b hab + unfold incoming glueWeights + have he : (incomingKey C a, trace P a) ≠ (incomingKey C b, trace P b) := + fun h => hab (congrArg Prod.snd h) + simp [he] + · intro a b ha hab + unfold incoming glueWeights + have he : (incomingKey C a, trace P a) ≠ (incomingKey C b, trace P b) := by + intro h + have hk : incomingKey C a = incomingKey C b := congrArg Prod.fst h + simp only [incomingKey, ha, ↓reduceIte] at hk + split_ifs at hk with hb + · exact hab (Option.some.inj hk) + simp [he] + + theorem departure_coupling (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (i j : ι) : + (∀ a b, 0 ≤ departure M F P i j a b) ∧ + (∀ a, ∑ b, departure M F P i j a b = weight M F a) ∧ + (∀ b, ∑ a, departure M F P i j a b = weight M F b) ∧ + (∀ a b, trace P a ≠ trace P b → departure M F P i j a b = 0) ∧ + (∀ a b, departureKey i j a ≠ departureKey i j b → departure M F P i j a b = 0) := by + classical + have hc : ∀ c, marginal (fun x => (departureKey i j x, trace P x)) (weight M F) c = + marginal (fun x => (departureKey i j x, trace P x)) (weight M F) c := fun _ => rfl + refine ⟨glueWeights_nonneg _ _ _ _ (weight_nonneg M F) (weight_nonneg M F), + glueWeights_row _ _ _ _ (weight_nonneg M F) hc, + (glueWeights_marginals _ _ _ _ (weight_nonneg M F) (weight_nonneg M F) hc).2.2, ?_, ?_⟩ + · intro a b hab + unfold departure glueWeights + have he : (departureKey i j a, trace P a) ≠ (departureKey i j b, trace P b) := + fun h => hab (congrArg Prod.snd h) + simp [he] + · intro a b hab + unfold departure glueWeights + have he : (departureKey i j a, trace P a) ≠ (departureKey i j b, trace P b) := + fun h => hab (congrArg Prod.fst h) + simp [he] + +end BoundedTreewidthL1.ExpandedParticleLaw + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/ExpandedPaths.lean b/lean/OAI/Combinatorics/TreewidthL1/ExpandedPaths.lean new file mode 100644 index 0000000000000000000000000000000000000000..6cb945f762724273e1e7f8172b175c6f87869438 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/ExpandedPaths.lean @@ -0,0 +1,374 @@ +import OAI.Combinatorics.TreewidthL1.MarkovProduct + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1.ExpandedChain +open scoped BigOperators +open ReservationCoupling +attribute [local instance] Classical.decEq Classical.propDecidable +variable {A : Type*} [Fintype A] + +noncomputable def past (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) (f : A → ℝ) : ℕ → A → ℝ + | 0 => f + | n+1 => action (μ (n+1)) (fun b a => Q n a b) (past μ Q f n) + +lemma past_bounds (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) + (hQ : ∀ n, IsCoupling (μ n) (μ (n+1)) (Q n)) (f : A → ℝ) + (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) (n : ℕ) : + ∀ a, 0 ≤ past μ Q f n a ∧ past μ Q f n a ≤ 1 := by + induction n with + | zero => exact hf + | succ n ih => exact action_bounds (hQ n).symm _ ih + +lemma sum_fiber_mul {B : Type*} [Fintype B] (k : A → B) (w : A → ℝ) (g : B → ℝ) : + (∑ a, w a * g (k a)) = ∑ b, (∑ a, if k a = b then w a else 0) * g b := by + simp only [Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + simp only [ite_mul, zero_mul] + simp + +/-- Conditional past means in the actual finite product law, not an assumed +Markov response. This identity includes all zero-mass states. -/ +lemma weighted_terminal (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) + (hQ : ∀ n, IsCoupling (μ n) (μ (n+1)) (Q n)) (f : A → ℝ) (n : ℕ) (b : A) : + (∑ x : MarkovProduct.History (fun _ => A) n, + if x (Fin.last n) = b then + MarkovProduct.weight (fun _ => A) (μ 0) (MarkovProduct.couplingKernel (fun _ => A) μ Q) n x * f (x 0) + else 0) = μ n b * past μ Q f n b := by + induction n generalizing b with + | zero => + let e : A ≃ (Fin 1 → A) := (Equiv.piUnique (fun _ : Fin 1 => A)).symm + rw [← e.sum_comp] + simp [e, MarkovProduct.weight, past, Equiv.piUnique, uniqueElim] + | succ n ih => + rw [MarkovProduct.sum_history_snoc (fun _ => A)] + simp only [Fin.snoc_last, MarkovProduct.weight_snoc] + have hzero (x : Fin (n+1) → A) (c : A) : + @Fin.snoc (n+1) (fun _ : Fin (n+2) => A) x c 0 = x 0 := by + exact @Fin.snoc_castSucc (n+1) (fun _ => A) c x 0 + simp only [hzero] + rw [Finset.sum_comm] + simp only [Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] + let w : (Fin (n+1) → A) → ℝ := fun x => + MarkovProduct.weight (fun _ => A) (μ 0) (MarkovProduct.couplingKernel (fun _ => A) μ Q) n x * f (x 0) + have he : (∑ x : Fin (n+1) → A, + MarkovProduct.weight (fun _ => A) (μ 0) (MarkovProduct.couplingKernel (fun _ => A) μ Q) n x * + MarkovProduct.couplingKernel (fun _ => A) μ Q n (x (Fin.last n)) b * f (x 0)) = + ∑ a, μ n a * past μ Q f n a * MarkovProduct.couplingKernel (fun _ => A) μ Q n a b := by + trans ∑ x, w x * MarkovProduct.couplingKernel (fun _ => A) μ Q n (x (Fin.last n)) b + · apply Finset.sum_congr rfl + intro x _ + dsimp [w] + ring + · rw [sum_fiber_mul (fun x : Fin (n+1) → A => x (Fin.last n)) w + (fun a => MarkovProduct.couplingKernel (fun _ => A) μ Q n a b)] + apply Finset.sum_congr rfl + intro a _ + rw [show (∑ x, if x (Fin.last n) = a then w x else 0) = μ n a * past μ Q f n a from ih a] + rw [he] + change _ = μ (n+1) b * action (μ (n+1)) (fun b a => Q n a b) (past μ Q f n) b + rw [weighted_action (hQ n).symm] + apply Finset.sum_congr rfl + intro a _ + rw [mul_right_comm, MarkovProduct.couplingKernel_balance (fun _ => A) μ Q + (fun n => (hQ n).nonneg) (fun n => (hQ n).row)] + +/-- Separation of endpoint labels in the genuine product density is precisely +its conditional-predictor defect. The identity holds for all bounded or unbounded +real endpoint observables; bounds are needed only for the subsequent tests. -/ +theorem endpoint_defect (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) + (hQ : ∀ n, IsCoupling (μ n) (μ (n+1)) (Q n)) (f g : A → ℝ) (n : ℕ) : + (∑ x : MarkovProduct.History (fun _ => A) n, + MarkovProduct.weight (fun _ => A) (μ 0) (MarkovProduct.couplingKernel (fun _ => A) μ Q) n x * + (f (x 0) + g (x (Fin.last n)) - 2*f (x 0)*g (x (Fin.last n)))) = + defect (μ n) g (past μ Q f n) := by + let w : (Fin (n+1) → A) → ℝ := MarkovProduct.weight (fun _ => A) (μ 0) + (MarkovProduct.couplingKernel (fun _ => A) μ Q) n + have hm (b : A) : (∑ x : Fin (n+1) → A, if x (Fin.last n) = b then w x else 0) = μ n b := by + exact (MarkovProduct.terminal_marginal (fun _ => A) (μ 0) + (MarkovProduct.couplingKernel (fun _ => A) μ Q) n b).trans + (MarkovProduct.coupling_forward (fun _ => A) μ Q + (fun n => (hQ n).nonneg) (fun n => (hQ n).row) (fun n => (hQ n).col) n b) + have hw (b : A) : (∑ x : Fin (n+1) → A, if x (Fin.last n) = b then w x * f (x 0) else 0) = + μ n b * past μ Q f n b := weighted_terminal μ Q hQ f n b + have he : (∑ x : Fin (n+1) → A, w x * f (x 0)) = + ∑ b, μ n b * past μ Q f n b := by + simpa only [mul_one, hw] using + (sum_fiber_mul (fun x : Fin (n+1) → A => x (Fin.last n)) (fun x => w x*f (x 0)) (fun _ => (1:ℝ))) + have hg : (∑ x : Fin (n+1) → A, w x * g (x (Fin.last n))) = ∑ b, μ n b*g b := by + simpa only [hm] using (sum_fiber_mul (fun x : Fin (n+1) → A => x (Fin.last n)) w g) + have hfg : (∑ x : Fin (n+1) → A, w x * f (x 0) * g (x (Fin.last n))) = + ∑ b, μ n b * past μ Q f n b * g b := by + simpa only [hw] using (sum_fiber_mul (fun x : Fin (n+1) → A => x (Fin.last n)) + (fun x => w x*f (x 0)) g) + change (∑ x, w x * _) = _ + calc + _ = (∑ x, w x*f (x 0)) + (∑ x, w x*g (x (Fin.last n))) - + 2*(∑ x, w x*f (x 0)*g (x (Fin.last n))) := by + simp only [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro x _ + ring + _ = _ := by + rw [he,hg,hfg] + unfold defect + simp only [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro b _ + ring + +lemma response_past (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) + (hQ : ∀ n, IsCoupling (μ n) (μ (n+1)) (Q n)) (f g : A → ℝ) (t n : ℕ) : + defect (μ t) (response μ Q t n g) (past μ Q f t) = + defect (μ (t+n)) g (past μ Q f (t+n)) := by + induction n generalizing t with + | zero => simp only [response, Nat.add_zero] + | succ n ih => + change defect (μ t) (action (μ t) (Q t) (response μ Q (t+1) n g)) (past μ Q f t) = _ + rw [transfer_defect (hQ t)] + change defect (μ (t+1)) (response μ Q (t+1) n g) (past μ Q f (t+1)) = _ + rw [ih, show (t+1)+n = t+(n+1) by omega] + +/-- One may test at ANY interior location: past and future are the honest +conditional responses of the already constructed product law. -/ +theorem endpoint_defect_at (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) + (hQ : ∀ n, IsCoupling (μ n) (μ (n+1)) (Q n)) (f g : A → ℝ) (t n : ℕ) (ht : t ≤ n) : + (∑ x : MarkovProduct.History (fun _ => A) n, + MarkovProduct.weight (fun _ => A) (μ 0) (MarkovProduct.couplingKernel (fun _ => A) μ Q) n x * + (f (x 0) + g (x (Fin.last n)) - 2*f (x 0)*g (x (Fin.last n)))) = + defect (μ t) (response μ Q t (n-t) g) (past μ Q f t) := by + rw [endpoint_defect μ Q hQ, response_past μ Q hQ, Nat.add_sub_of_le ht] +end BoundedTreewidthL1.ExpandedChain + +namespace BoundedTreewidthL1.ReservedSuffix +open ExpandedParticleLaw ReservationCoupling ReservedKernel +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι : Type*} [Fintype V] [Fintype ι] + +/-- Local version: the arbitrary past of the path is immaterial. Only the true +reserved suffix edges are prescribed. -/ +theorem response_restrict_local (M : ℝ) (F : ℕ → ι → V → ℝ) (P : ℕ → Finset V) + (fresh₁ fresh₂ : ℕ → ι) (C : ℕ → Finset ι) + (Q : ℕ → State ι V → State ι V → ℝ) + (t n : ℕ) (r : ι) (G : V → ℝ) + (hQ : ∀ s, t ≤ s → s < t+n → Q s = kernels M F P fresh₁ fresh₂ C s) + (hret : ∀ s, t ≤ s → s < t+n → ∀ r ∈ C s, F s r = F (s+1) r) + (htrace : ∀ s, t ≤ s → s < t+n → + particleTrace M (F s) (P (s+1)) = particleTrace M (F (s+1)) (P (s+1))) + (hfixed : ∀ s, t ≤ s → s ≤ t+n → F s r = G) + (hkeep : ∀ s, t ≤ s → s < t+n → r ∈ C s ∧ r ≠ fresh₁ s ∧ r ≠ fresh₂ s) + (z : V) (a : OrderedReservation.Carrier M G) : + response (fun s => weight M (F s)) Q t n + (fun b => if label b z then 1 else 0) (lift M G r a) = + OrderedSweepFlow.execute (OrderedReservation.weight M G) + ((bags P t n).map (OrderedReservation.traceRank M G)) + (OrderedSweepFlow.labelReal (fun b => b.val z)) a := by + induction n generalizing t a with + | zero => rfl + | succ n ih => + have ht : F t r = G := hfixed t le_rfl (by omega) + subst G + have hk := hkeep t le_rfl (by omega) + change action (weight M (F t)) (Q t) + (response (fun s => weight M (F s)) Q (t+1) n + (fun b => if label b z then 1 else 0)) (lift M (F t r) r a) = _ + rw [hQ t le_rfl (by omega)] + unfold kernels + rw [edge_restrict M (F t) (F (t+1)) (P t) (P (t+1)) (fresh₁ t) (fresh₂ t) r (C t) + hk.2.1 hk.2.2 hk.1 (hret t le_rfl (by omega)) (htrace t le_rfl (by omega))] + rw [bags_succ, List.map_cons, OrderedSweepFlow.execute] + congr 1 + funext b + apply ih (t+1) + · intro s hs hs'; exact hQ s (by omega) (by omega) + · intro s hs hs'; exact hret s (by omega) (by omega) + · intro s hs hs'; exact htrace s (by omega) (by omega) + · intro s hs hs'; exact hfixed s (by omega) (by omega) + · intro s hs hs'; exact hkeep s (by omega) (by omega) + +lemma ordered_mean + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] + (M : ℝ) (_ : 0 ≤ M) (G : V → ℝ) + (hG : ∀ v, -M ≤ G v ∧ G v ≤ M) (r : ι) (z : V) + (bags : List (Finset V)) (f : State ι V → ℝ) + (hres : ∀ a : OrderedReservation.Carrier M G, f (lift M G r a) = + OrderedSweepFlow.execute (OrderedReservation.weight M G) + (bags.map (OrderedReservation.traceRank M G)) + (OrderedSweepFlow.labelReal (fun a => a.val z)) a) : + (∑ ω : V → Bool, (sweep M G).real {ω}/2 * f (r,false,ω)) = (G z+M)/2 := by + have he := OrderedReservation.sum_carrier M G (fun ω => f (r,false,ω)) + have he' : (∑ a : OrderedReservation.Carrier M G, + OrderedReservation.weight M G a * f (lift M G r a)) = + ∑ ω : V → Bool, (sweep M G).real {ω}*f (r,false,ω) := he + have hr := congrArg (fun h : OrderedReservation.Carrier M G → ℝ => + ∑ a, OrderedReservation.weight M G a * h a) (funext hres) + rw [he'] at hr + change _ = OrderedSweepFlow.total (OrderedReservation.weight M G) + (OrderedSweepFlow.execute (OrderedReservation.weight M G) + (bags.map (OrderedReservation.traceRank M G)) + (OrderedSweepFlow.labelReal (fun a => a.val z))) at hr + rw [OrderedSweepFlow.execute_total _ (OrderedReservation.weight_pos M G), + OrderedReservation.label_mean M G z (hG z)] at hr + calc + _ = (∑ ω : V → Bool, (sweep M G).real {ω}*f (r,false,ω))/2 := by + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + ring + _ = _ := by rw [hr] +end BoundedTreewidthL1.ReservedSuffix + +namespace BoundedTreewidthL1.ReservedSuffix +open ExpandedParticleLaw ReservationCoupling ReservedKernel +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι : Type*} [Fintype V] [Fintype ι] + +lemma incoming_response_restrict (M : ℝ) (F : ℕ → ι → V → ℝ) (P : ℕ → Finset V) + (fresh₁ fresh₂ : ℕ → ι) (C : ℕ → Finset ι) + (Q : ℕ → State ι V → State ι V → ℝ) (t n : ℕ) (r : ι) + (hQ : ∀ s, t+1 ≤ s → s < t+1+n → Q s = kernels M F P fresh₁ fresh₂ C s) + (hret : ∀ s, t ≤ s → s < t+1+n → ∀ r ∈ C s, F s r = F (s+1) r) + (htrace : ∀ s, t ≤ s → s < t+1+n → + particleTrace M (F s) (P (s+1)) = particleTrace M (F (s+1)) (P (s+1))) + (hfixed : ∀ s, t ≤ s → s ≤ t+1+n → F s r = F t r) + (hr : r ∈ C t) + (hkeep : ∀ s, t+1 ≤ s → s < t+1+n → r ∈ C s ∧ r ≠ fresh₁ s ∧ r ≠ fresh₂ s) + (z : V) (a : OrderedReservation.Carrier M (F t r)) : + action (weight M (F t)) (incoming M (F t) (F (t+1)) (P (t+1)) (C t)) + (response (fun s => weight M (F s)) Q (t+1) n + (fun b => if label b z then 1 else 0)) (lift M (F t r) r a) = + OrderedSweepFlow.execute (OrderedReservation.weight M (F t r)) + ((bags P (t+1) n).map (OrderedReservation.traceRank M (F t r))) + (OrderedSweepFlow.labelReal (fun b => b.val z)) a := by + rw [incoming_action_retained M (F t) (F (t+1)) (P (t+1)) (C t) + (hret t le_rfl (by omega)) (htrace t le_rfl (by omega)) _ hr + (ne_of_gt (div_pos a.property (by norm_num)))] + apply response_restrict_local M F P fresh₁ fresh₂ C Q (t+1) n r (F t r) hQ + · intro s hs hs'; exact hret s (by omega) hs' + · intro s hs hs'; exact htrace s (by omega) hs' + · intro s hs hs'; exact hfixed s (by omega) hs' + · exact hkeep +end BoundedTreewidthL1.ReservedSuffix + +namespace BoundedTreewidthL1.ExpandedPathTests +open ExpandedParticleLaw ReservationCoupling ReservedKernel ReservedSuffix ExpandedChain +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι : Type*} [Fintype V] [Fintype ι] + +noncomputable def distance (M : ℝ) (F : ℕ → ι → V → ℝ) + (Q : ℕ → State ι V → State ι V → ℝ) (n : ℕ) (y z : V) : ℝ := + ∑ x : Fin (n+1) → State ι V, + MarkovProduct.weight (fun _ => State ι V) (weight M (F 0)) + (MarkovProduct.couplingKernel (fun _ => State ι V) (fun s => weight M (F s)) Q) n x * + (if label (x 0) y = label (x (Fin.last n)) z then 0 else 1) + +lemma distance_at (M : ℝ) (F : ℕ → ι → V → ℝ) + (Q : ℕ → State ι V → State ι V → ℝ) + (hQ : ∀ s, IsCoupling (weight M (F s)) (weight M (F (s+1))) (Q s)) + (t n : ℕ) (y z : V) : + distance M F Q (t+(n+1)) y z = + defect (weight M (F t)) (action (weight M (F t)) (Q t) + (response (fun s => weight M (F s)) Q (t+1) n (fun b => if label b z then 1 else 0))) + (past (fun s => weight M (F s)) Q (fun b => if label b y then 1 else 0) t) := by + have he := endpoint_defect_at (fun s => weight M (F s)) Q hQ + (fun b => if label b y then 1 else 0) (fun b => if label b z then 1 else 0) + t (t+(n+1)) (by omega) + rw [Nat.add_sub_cancel_left, response] at he + rw [← he] + unfold distance + apply Finset.sum_congr rfl + intro x _ + cases hy : label (x 0) y <;> cases hz : label (x (Fin.last (t+(n+1)))) z <;> norm_num [hy,hz] + +/-- Height test for the ACTUAL arbitrarily prefixed product path. All suffix +transport and both past/future responses are derived from its couplings. -/ +theorem height_test (M : ℝ) (hM : 0 ≤ M) (F : ℕ → ι → V → ℝ) (P : ℕ → Finset V) + (fresh₁ fresh₂ : ℕ → ι) (C : ℕ → Finset ι) + (Q : ℕ → State ι V → State ι V → ℝ) + (hQ : ∀ s, IsCoupling (weight M (F s)) (weight M (F (s+1))) (Q s)) + (t n : ℕ) (r : ι) + (hEq : ∀ s, t ≤ s → s < t+1+n → Q s = kernels M F P fresh₁ fresh₂ C s) + (hret : ∀ s, t ≤ s → s < t+1+n → ∀ r ∈ C s, F s r = F (s+1) r) + (htrace : ∀ s, t ≤ s → s < t+1+n → + particleTrace M (F s) (P (s+1)) = particleTrace M (F (s+1)) (P (s+1))) + (hfixed : ∀ s, t ≤ s → s ≤ t+1+n → F s r = F t r) + (hkeep : ∀ s, t ≤ s → s < t+1+n → r ∈ C s ∧ r ≠ fresh₁ s ∧ r ≠ fresh₂ s) + (hF : ∀ v, -M ≤ F t r v ∧ F t r v ≤ M) (y z : V) + (ε : ℝ) (hlo : ε ≤ F t r z + M) (hhi : ε ≤ M-F t r z) + (hgap : ∀ v ∈ P t, ε ≤ |F t r z-F t r v|) : + ε/2 ≤ distance M F Q (t+(n+1)) y z := by + rw [distance_at M F Q hQ t n y z, hEq t le_rfl (by omega)] + unfold kernels edge + rw [action_compose] + have hb (v : V) (a : State ι V) : 0 ≤ (if label a v then (1:ℝ) else 0) ∧ + (if label a v then (1:ℝ) else 0) ≤ 1 := by split_ifs <;> norm_num + have hin : IsCoupling (weight M (F t)) (weight M (F (t+1))) + (incoming M (F t) (F (t+1)) (P (t+1)) (C t)) := by + obtain ⟨hn,hr,hc,_,_⟩ := incoming_coupling M (F t) (F (t+1)) (P (t+1)) (C t) + (hret t le_rfl (by omega)) (htrace t le_rfl (by omega)) + exact ⟨hn,hr,hc⟩ + have hk := hkeep t le_rfl (by omega) + apply ReservedTests.height_test M hM (F t) (P t) (fresh₁ t) (fresh₂ t) r + hk.2.1 hk.2.2 hF z (bags P (t+1) n) + · exact action_bounds hin _ (response_bounds _ Q hQ (t+1) n _ (hb z)) + · exact past_bounds _ Q hQ _ (hb y) t + · intro a + apply incoming_response_restrict M F P fresh₁ fresh₂ C Q t n r + (fun s hs hs' => hEq s (by omega) hs') hret htrace hfixed hk.1 + (fun s hs hs' => hkeep s (by omega) hs') z a + · exact hlo + · exact hhi + · exact hgap +/-- Fresh-pair test on the actual product law with an arbitrary prefix. -/ +theorem launch_test (M : ℝ) (hM : 0 ≤ M) (F : ℕ → ι → V → ℝ) (P : ℕ → Finset V) + (fresh₁ fresh₂ : ℕ → ι) (C : ℕ → Finset ι) + (Q : ℕ → State ι V → State ι V → ℝ) + (hQ : ∀ s, IsCoupling (weight M (F s)) (weight M (F (s+1))) (Q s)) + (t n : ℕ) (hij : fresh₁ t ≠ fresh₂ t) + (hbag : ∀ v ∈ P t, F t (fresh₁ t) v = F t (fresh₂ t) v) + (hEq : ∀ s, t ≤ s → s < t+1+n → Q s = kernels M F P fresh₁ fresh₂ C s) + (hret : ∀ s, t ≤ s → s < t+1+n → ∀ r ∈ C s, F s r = F (s+1) r) + (htrace : ∀ s, t ≤ s → s < t+1+n → + particleTrace M (F s) (P (s+1)) = particleTrace M (F (s+1)) (P (s+1))) + (hfixed : ∀ r ∈ ({fresh₁ t, fresh₂ t} : Finset ι), + ∀ s, t ≤ s → s ≤ t+1+n → F s r = F t r) + (hinit : fresh₁ t ∈ C t ∧ fresh₂ t ∈ C t) + (hkeep : ∀ r ∈ ({fresh₁ t, fresh₂ t} : Finset ι), + ∀ s, t+1 ≤ s → s < t+1+n → r ∈ C s ∧ r ≠ fresh₁ s ∧ r ≠ fresh₂ s) + (hF : ∀ r ∈ ({fresh₁ t, fresh₂ t} : Finset ι), ∀ v, -M ≤ F t r v ∧ F t r v ≤ M) + (y z : V) : + |F t (fresh₁ t) z - F t (fresh₂ t) z|/2 ≤ distance M F Q (t+(n+1)) y z := by + rw [distance_at M F Q hQ t n y z, hEq t le_rfl (by omega)] + unfold kernels edge + rw [action_compose] + have hb (v : V) (a : State ι V) : 0 ≤ (if label a v then (1:ℝ) else 0) ∧ + (if label a v then (1:ℝ) else 0) ≤ 1 := by split_ifs <;> norm_num + have hin : IsCoupling (weight M (F t)) (weight M (F (t+1))) + (incoming M (F t) (F (t+1)) (P (t+1)) (C t)) := by + obtain ⟨hn,hr,hc,_,_⟩ := incoming_coupling M (F t) (F (t+1)) (P (t+1)) (C t) + (hret t le_rfl (by omega)) (htrace t le_rfl (by omega)) + exact ⟨hn,hr,hc⟩ + have hm (r : ι) (hr : r ∈ ({fresh₁ t, fresh₂ t} : Finset ι)) (hc : r ∈ C t) : + (∑ ω : V → Bool, weight M (F t) (r,false,ω) * + action (weight M (F t)) (incoming M (F t) (F (t+1)) (P (t+1)) (C t)) + (response (fun s => weight M (F s)) Q (t+1) n + (fun b => if label b z then 1 else 0)) (r,false,ω)) = (F t r z+M)/2 := by + apply ordered_mean M hM (F t r) (hF r hr) r z (bags P (t+1) n) + intro a + exact incoming_response_restrict M F P fresh₁ fresh₂ C Q t n r + (fun s hs hs' => hEq s (by omega) hs') hret htrace (hfixed r hr) hc (hkeep r hr) z a + apply ReservedTests.launch_test M (F t) (P t) (fresh₁ t) (fresh₂ t) hij hbag z + · exact action_bounds hin _ (response_bounds _ Q hQ (t+1) n _ (hb z)) + · exact past_bounds _ Q hQ _ (hb y) t + · exact hm _ (by simp) hinit.1 + · exact hm _ (by simp) hinit.2 +end BoundedTreewidthL1.ExpandedPathTests + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/ExpandedTree.lean b/lean/OAI/Combinatorics/TreewidthL1/ExpandedTree.lean new file mode 100644 index 0000000000000000000000000000000000000000..cbd7056b22e9581b3a0a6a697985d55db8f7bdb9 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/ExpandedTree.lean @@ -0,0 +1,208 @@ +import OAI.Combinatorics.TreewidthL1.ExpandedPaths + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 + +namespace BoundedTreewidthL1.ExpandedTree +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I A : Type*} [Fintype I] [Fintype A] + +noncomputable def marginalLaw (M : ℝ) (μ : I → A → ℝ) : I → A → ℝ := fun i a => μ i a/M +noncomputable def jointLaw (M : ℝ) (J : I → I → A → A → ℝ) := fun i j a b => J i j a b/M +lemma jointLaw_symm + {I : Type treewidthLevel1} {A : Type treewidthLevel2} [Fintype I] [Fintype A] + (M : ℝ) (J : I → I → A → A → ℝ) + (hs : TreeMarkov.Symmetric (fun _ : I => A) J) : + TreeMarkov.Symmetric (fun _ : I => A) (jointLaw M J) := by + intro i j a b + unfold jointLaw + rw [hs] +noncomputable def law (T : SimpleGraph I) (M : ℝ) (μ : I → A → ℝ) + (J : I → I → A → A → ℝ) (hs : TreeMarkov.Symmetric (fun _ : I => A) J) (x : I → A) : ℝ := + M * TreeMarkov.density (fun _ : I => A) T (marginalLaw M μ) + (TreeMarkov.interaction (fun _ : I => A) (marginalLaw M μ) (jointLaw M J)) + (TreeMarkov.interaction_symmetric (fun _ : I => A) (marginalLaw M μ) (jointLaw M J) (jointLaw_symm M J hs)) x + +lemma normalized (T : SimpleGraph I) (M : ℝ) (hM : 0 < M) (μ : I → A → ℝ) + (J : I → I → A → A → ℝ) (hs : TreeMarkov.Symmetric (fun _ : I => A) J) + (hμ : ∀ i a, 0 ≤ μ i a) (hmass : ∀ i, (∑ a, μ i a) = M) + (hJ : ∀ i j, T.Adj i j → ∀ a b, 0 ≤ J i j a b) + (hrow : ∀ i j, T.Adj i j → ∀ a, ∑ b, J i j a b = μ i a) : + TreeMarkov.Normalized (fun _ : I => A) T (marginalLaw M μ) + (TreeMarkov.interaction (fun _ : I => A) (marginalLaw M μ) (jointLaw M J)) := by + apply TreeMarkov.interaction_normalized + · intro i a + exact div_nonneg (hμ i a) hM.le + · intro i + simp only [marginalLaw, ← Finset.sum_div, hmass i, div_self (ne_of_gt hM)] + · exact jointLaw_symm M J hs + · intro i j hij a b + exact div_nonneg (hJ i j hij a b) hM.le + · intro i j hij a + simp only [jointLaw, marginalLaw, ← Finset.sum_div, hrow i j hij a] + +/-- The expanded-state law is an actual finite tree law of the original common +mass. All local state marginals are as prescribed; no gluing existence is assumed. -/ +theorem law_marginals (T : SimpleGraph I) (hT : T.IsTree) (M : ℝ) (hM : 0 < M) + (μ : I → A → ℝ) (J : I → I → A → A → ℝ) (hs : TreeMarkov.Symmetric (fun _ : I => A) J) + (hμ : ∀ i a, 0 ≤ μ i a) (hmass : ∀ i, (∑ a, μ i a) = M) + (hJ : ∀ i j, T.Adj i j → ∀ a b, 0 ≤ J i j a b) + (hrow : ∀ i j, T.Adj i j → ∀ a, ∑ b, J i j a b = μ i a) : + (∀ x, 0 ≤ law T M μ J hs x) ∧ (∑ x, law T M μ J hs x) = M ∧ + ∀ i a, (∑ x : I → A, if x i = a then law T M μ J hs x else 0) = μ i a := by + let ν := marginalLaw M μ + let R := TreeMarkov.interaction (fun _ : I => A) ν (jointLaw M J) + let hR := TreeMarkov.interaction_symmetric (fun _ : I => A) ν (jointLaw M J) (jointLaw_symm M J hs) + have hn := normalized T M hM μ J hs hμ hmass hJ hrow + obtain ⟨hw,ht,hm⟩ := TreeMarkov.tree_density (fun _ : I => A) T hT ν R hR hn + refine ⟨fun x => mul_nonneg hM.le (hw x), ?_, ?_⟩ + · simp only [law, ← Finset.mul_sum] + change M * (∑ x, TreeMarkov.density (fun _ : I => A) T ν R hR x) = M + rw [ht,mul_one] + · intro i a + have he : (∑ x : I → A, if x i = a then law T M μ J hs x else 0) = + M * (∑ x : I → A, if x i = a then TreeMarkov.density (fun _ : I => A) T ν R hR x else 0) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + split_ifs <;> simp [law,ν,R] + rw [he,hm] + exact mul_div_cancel₀ (μ i a) (ne_of_gt hM) + +lemma path_expectation (T : SimpleGraph I) (hT : T.IsTree) (M : ℝ) (hM : 0 < M) + (μ : I → A → ℝ) (J : I → I → A → A → ℝ) (hs : TreeMarkov.Symmetric (fun _ : I => A) J) + (hμ : ∀ i a, 0 ≤ μ i a) (hmass : ∀ i, (∑ a, μ i a) = M) + (hJ : ∀ i j, T.Adj i j → ∀ a b, 0 ≤ J i j a b) + (hrow : ∀ i j, T.Adj i j → ∀ a, ∑ b, J i j a b = μ i a) + {K : Type*} [Fintype K] (e : K ↪ I) (hc : (T.comap e).Connected) (f : (K → A) → ℝ) : + (∑ x : I → A, law T M μ J hs x * f (x ∘ e)) = + ∑ x : K → A, law (T.comap e) M (fun i => μ (e i)) (fun i j => J (e i) (e j)) + (fun i j => hs (e i) (e j)) x * f x := by + unfold law + simp_rw [mul_assoc, ← Finset.mul_sum] + congr 1 + exact TreeMarkov.expectation_comap (fun _ : I => A) T hT (marginalLaw M μ) _ _ + (normalized T M hM μ J hs hμ hmass hJ hrow) e hc f + +lemma support_joint (T : SimpleGraph I) (M : ℝ) (μ : I → A → ℝ) + (J : I → I → A → A → ℝ) (hs : TreeMarkov.Symmetric (fun _ : I => A) J) + (x : I → A) (hx : law T M μ J hs x ≠ 0) (i j : I) (hij : T.Adj i j) : + J i j (x i) (x j) ≠ 0 := by + have hp := (mul_ne_zero_iff.mp (mul_ne_zero_iff.mp hx).2).2 + have he : s(i,j) ∈ T.edgeFinset := by simpa using hij + have hz := Finset.prod_ne_zero_iff.mp hp _ he + change J i j (x i) (x j) / M / ((μ i (x i)/M)*(μ j (x j)/M)) ≠ 0 at hz + exact (div_ne_zero_iff.mp (div_ne_zero_iff.mp hz).1).1 + +/-- Gluing of GLOBAL state labels along the running-intersection bags. -/ +noncomputable def assemble {V : Type*} (B : I → Set V) (hcover : ∀ v, ∃ i, v ∈ B i) + (label : A → V → Bool) (x : I → A) : V → Bool := + fun v => label (x (Classical.choose (hcover v))) v + +lemma assembled_label + {I : Type treewidthLevel1} {A : Type treewidthLevel2} [Fintype I] [Fintype A] + {V : Type*} (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (label : A → V → Bool) (x : I → A) + (hx : ∀ i j, T.Adj i j → ∀ v, v ∈ B i → v ∈ B j → label (x i) v = label (x j) v) + (i : I) (v : V) (hv : v ∈ B i) : assemble B hcover label x v = label (x i) v := by + obtain ⟨p⟩ := hrun v ⟨Classical.choose (hcover v),Classical.choose_spec (hcover v)⟩ ⟨i,hv⟩ + have hc : ∀ {a b : {i | v ∈ B i}} (q : (T.induce {i | v ∈ B i}).Walk a b), + label (x a) v = label (x b) v := by + intro a b q + induction q with + | nil => rfl + | @cons a b c hab q ih => exact (hx a b hab v a.2 b.2).trans ih + exact hc p + +lemma law_labels {V : Type*} (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (M : ℝ) (μ : I → A → ℝ) (J : I → I → A → A → ℝ) + (hs : TreeMarkov.Symmetric (fun _ : I => A) J) (label : A → V → Bool) + (hcomp : ∀ i j, T.Adj i j → ∀ a b, J i j a b ≠ 0 → + ∀ v, v ∈ B i → v ∈ B j → label a v = label b v) + (x : I → A) (hx : law T M μ J hs x ≠ 0) (i : I) (v : V) (hv : v ∈ B i) : + assemble B hcover label x v = label (x i) v := by + exact assembled_label T B hcover hrun label x + (fun i j hij => hcomp i j hij (x i) (x j) (support_joint T M μ J hs x hx i j hij)) i v hv + +end BoundedTreewidthL1.ExpandedTree + +namespace BoundedTreewidthL1.ExpandedTree +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {A : Type*} [Fintype A] + +/-- On every actual bag-tree path, the law is the genuine product of the +prescribed expanded couplings, even though their common mass is not one. -/ +theorem law_path_product (M : ℝ) (hM : 0 < M) (μ : ℕ → A → ℝ) + (Q : ℕ → A → A → ℝ) + (hQ : ∀ n a b, 0 ≤ Q n a b) + (_ : ∀ n a, (∑ b, Q n a b) = μ n a) + (hcol : ∀ n b, (∑ a, Q n a b) = μ (n+1) b) + (n : ℕ) (J : Fin (n+1) → Fin (n+1) → A → A → ℝ) + (hs : TreeMarkov.Symmetric (fun _ : Fin (n+1) => A) J) + (hJ : ∀ (i : Fin n) a b, J i.castSucc i.succ a b = Q i.val a b) (x : Fin (n+1) → A) : + law (SimpleGraph.pathGraph (n+1)) M (fun i => μ i.val) J hs x = + MarkovProduct.weight (fun _ => A) (μ 0) (MarkovProduct.couplingKernel (fun _ => A) μ Q) n x := by + unfold law + rw [TreeMarkov.path_density] + let m : Fin (n+1) → ℝ := fun i => μ i.val (x i)/M + let q : Fin n → ℝ := fun i => + TreeMarkov.interaction (fun _ : Fin (n+1) => A) (marginalLaw M (fun i => μ i.val)) + (jointLaw M J) i.castSucc i.succ (x i.castSucc) (x i.succ) + let k : Fin n → ℝ := fun i => MarkovProduct.couplingKernel (fun _ => A) μ Q i.val + (x i.castSucc) (x i.succ) + have hk (i : Fin n) (hi : m i.castSucc ≠ 0) : k i = m i.succ * q i := by + have hi' : μ i.val (x i.castSucc) ≠ 0 := by + intro hz + exact hi (by simp [m,hz]) + by_cases hj : μ (i.val+1) (x i.succ) = 0 + · have hz : Q i.val (x i.castSucc) (x i.succ) = 0 := by + have hh := hcol i.val (x i.succ) + rw [hj] at hh + exact (Finset.sum_eq_zero_iff_of_nonneg (fun a _ => hQ i.val a (x i.succ))).mp hh _ (Finset.mem_univ _) + simp [k, MarkovProduct.couplingKernel,hi',hz,m,hj] + · dsimp [k,m,q] + simp only [MarkovProduct.couplingKernel, hi', ↓reduceIte, TreeMarkov.interaction, + marginalLaw, jointLaw, hJ, Fin.val_castSucc, Fin.val_succ] + field_simp [hi',hj,ne_of_gt hM] + have he := TreeMarkov.product_factorization n m q k hk + change M * ((∏ i, m i)*(∏ i, q i)) = _ + rw [he] + unfold MarkovProduct.weight + change M * ((μ 0 (x 0)/M) * ∏ i, k i) = μ 0 (x 0) * ∏ i, k i + rw [← mul_assoc, mul_div_cancel₀ _ (ne_of_gt hM)] +end BoundedTreewidthL1.ExpandedTree + +namespace BoundedTreewidthL1 +open MeasureTheory +open scoped ENNReal + +theorem averaged_cut_realization {Ω V A : Type*} [MeasurableSpace Ω] [Fintype A] + (μ : Measure Ω) (w : Ω → A → ℝ) (cut : A → V → Bool) + (hw : ∀ ω a, 0 ≤ w ω a) + (hint : ∀ a, Integrable (fun ω => w ω a) μ) : + ∃ n : ℕ, ∃ F : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + ∀ u v, ‖F u - F v‖ = ∫ ω, cutDistance (w ω) cut u v ∂μ := by + let W : A → ℝ := fun a => ∫ ω, w ω a ∂μ + have hW : ∀ a, 0 ≤ W a := fun a => integral_nonneg (fun ω => hw ω a) + obtain ⟨n,F,hF⟩ := finite_cut_realization W cut hW + refine ⟨n,F,?_⟩ + intro u v + rw [hF] + unfold cutDistance + rw [integral_finsetSum] + · apply Finset.sum_congr rfl + intro a ha + by_cases he : cut a u = cut a v <;> simp [he, W] + · intro a ha + by_cases he : cut a u = cut a v + · simp only [he, ite_true] + exact integrable_zero Ω ℝ μ + · simpa only [he, ite_false] using hint a +end BoundedTreewidthL1 + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/LaunchNoise.lean b/lean/OAI/Combinatorics/TreewidthL1/LaunchNoise.lean new file mode 100644 index 0000000000000000000000000000000000000000..30efdc1ad9424500332cfaca3e71649efa4d9cfd --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/LaunchNoise.lean @@ -0,0 +1,938 @@ +import OAI.Combinatorics.TreewidthL1.Padding + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1 +namespace LaunchNoise +open Metric +variable {V I : Type*} [MetricSpace V] [Fintype I] +noncomputable def bump (E : Set V) (r : ℝ) (x : V) : ℝ := + by + classical + exact if Eᶜ.Nonempty then min r (infDist x Eᶜ) else r +noncomputable def noise (E : I → Set V) (r U : I → ℝ) (x : V) : ℝ := + ∑ i, U i * bump (E i) (r i) x + +lemma bump_lipschitz (E : Set V) (r : ℝ) : LipschitzWith 1 (bump E r) := by + classical + apply LipschitzWith.of_dist_le_mul + intro x y + by_cases h : Eᶜ.Nonempty + · simpa only [bump, h, ↓reduceIte] using + ((lipschitz_infDist_pt (s := Eᶜ)).const_min r).dist_le_mul x y + · simp [bump, h] + +lemma bump_bounds (E : Set V) (r : ℝ) (hr : 0 ≤ r) (x : V) : + 0 ≤ bump E r x ∧ bump E r x ≤ r := by + classical + unfold bump + split_ifs + · exact ⟨le_min hr infDist_nonneg, min_le_left _ _⟩ + · exact ⟨hr, le_rfl⟩ + +lemma bump_zero (E : Set V) (r : ℝ) (hr : 0 ≤ r) (x : V) (hx : x ∉ E) : + bump E r x = 0 := by + have h : Eᶜ.Nonempty := ⟨x, hx⟩ + simp [bump, h, infDist_zero_of_mem (show x ∈ Eᶜ from hx), hr] + +lemma bump_le_dist (E : Set V) (r : ℝ) (x y : V) (hy : y ∉ E) : + bump E r x ≤ dist x y := by + have h : Eᶜ.Nonempty := ⟨y, hy⟩ + simp only [bump, h, ↓reduceIte] + exact (min_le_right _ _).trans (infDist_le_dist_of_mem (show y ∈ Eᶜ from hy)) + +lemma bump_padding (E : Set V) (r : ℝ) (x : V) (a : ℝ) + (har : a ≤ r) (hball : ball x a ⊆ E) : a ≤ bump E r x := by + classical + by_cases h : Eᶜ.Nonempty + · simp only [bump, h, ↓reduceIte, le_min_iff] + refine ⟨har, le_of_not_gt ?_⟩ + intro ht + obtain ⟨y, hy, hxy⟩ := (infDist_lt_iff h).mp ht + exact hy (hball (by simpa [mem_ball, dist_comm] using hxy)) + · simp [bump, h, har] + +theorem bump_properties (E : Set V) (r : ℝ) (hr : 0 ≤ r) : + LipschitzWith 1 (bump E r) ∧ + (∀ x, 0 ≤ bump E r x ∧ bump E r x ≤ r) ∧ + (∀ x, x ∉ E → bump E r x = 0) ∧ + (∀ x y, y ∉ E → bump E r x ≤ dist x y) ∧ + (∀ x a, a ≤ r → ball x a ⊆ E → a ≤ bump E r x) := + ⟨bump_lipschitz E r, bump_bounds E r hr, bump_zero E r hr, + bump_le_dist E r, bump_padding E r⟩ + +lemma noise_at (E : I → Set V) (r U : I → ℝ) + (hE : Pairwise (fun i j => Disjoint (E i) (E j))) (hr : ∀ i, 0 ≤ r i) + (i : I) (x : V) (hx : x ∈ E i) : + noise E r U x = U i * bump (E i) (r i) x := by + classical + unfold noise + apply Finset.sum_eq_single i + · intro j _ hji + have hxj : x ∉ E j := fun hxj => Set.disjoint_left.mp (hE hji) hxj hx + simp [bump_zero _ _ (hr j) _ hxj] + · simp + +lemma noise_zero (E : I → Set V) (r U : I → ℝ) (hr : ∀ i, 0 ≤ r i) + (x : V) (hx : ∀ i, x ∉ E i) : noise E r U x = 0 := by + simp [noise, fun i => bump_zero (E i) (r i) (hr i) x (hx i)] + +lemma noise_nonneg (E : I → Set V) (r U : I → ℝ) + (hr : ∀ i, 0 ≤ r i) (hU : ∀ i, 0 ≤ U i) (x : V) : + 0 ≤ noise E r U x := by + exact Finset.sum_nonneg fun i _ => mul_nonneg (hU i) (bump_bounds _ _ (hr i) x).1 + +lemma noise_upper (E : I → Set V) (r U : I → ℝ) + (hE : Pairwise (fun i j => Disjoint (E i) (E j))) (hr : ∀ i, 0 ≤ r i) + (hU : ∀ i, 0 ≤ U i ∧ U i ≤ 1) (i : I) (x : V) (hx : x ∈ E i) : + noise E r U x ≤ r i := by + rw [noise_at E r U hE hr i x hx] + exact (mul_le_of_le_one_left (bump_bounds _ _ (hr i) x).1 (hU i).2).trans + (bump_bounds _ _ (hr i) x).2 + +lemma noise_one_sided (E : I → Set V) (r U : I → ℝ) + (hE : Pairwise (fun i j => Disjoint (E i) (E j))) (hr : ∀ i, 0 ≤ r i) + (hU : ∀ i, 0 ≤ U i ∧ U i ≤ 1) (x y : V) : + noise E r U x - noise E r U y ≤ dist x y := by + classical + by_cases hx : ∃ i, x ∈ E i + · obtain ⟨i, hi⟩ := hx + rw [noise_at E r U hE hr i x hi] + by_cases hy : y ∈ E i + · rw [noise_at E r U hE hr i y hy, ← mul_sub] + have hb := (bump_lipschitz (E i) (r i)).dist_le_mul x y + simp only [Real.dist_eq, NNReal.coe_one, one_mul] at hb + have hsub := (le_abs_self (bump (E i) (r i) x - bump (E i) (r i) y)).trans hb + calc U i * (bump (E i) (r i) x - bump (E i) (r i) y) + ≤ U i * dist x y := mul_le_mul_of_nonneg_left hsub (hU i).1 + _ ≤ dist x y := mul_le_of_le_one_left dist_nonneg (hU i).2 + · have h1 := bump_le_dist (E i) (r i) x y hy + have h2 := noise_nonneg E r U hr (fun j => (hU j).1) y + have h3 := mul_le_of_le_one_left (bump_bounds (E i) (r i) (hr i) x).1 (hU i).2 + linarith + · have h0 := noise_zero E r U hr x (by simpa using hx) + have h1 := noise_nonneg E r U hr (fun i => (hU i).1) y + rw [h0] + linarith [dist_nonneg (x := x) (y := y)] + +theorem disjoint_noise (E : I → Set V) (r U : I → ℝ) + (hE : Pairwise (fun i j => Disjoint (E i) (E j))) (hr : ∀ i, 0 ≤ r i) + (hU : ∀ i, 0 ≤ U i ∧ U i ≤ 1) : + LipschitzWith 1 (noise E r U) ∧ + (∀ x, 0 ≤ noise E r U x) ∧ + (∀ i x, x ∈ E i → noise E r U x ≤ r i) ∧ + (∀ x, (∀ i, x ∉ E i) → noise E r U x = 0) := by + refine ⟨?_, noise_nonneg E r U hr (fun i => (hU i).1), + noise_upper E r U hE hr hU, noise_zero E r U hr⟩ + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq, NNReal.coe_one, one_mul, abs_le] + constructor + · have := noise_one_sided E r U hE hr hU y x + rw [dist_comm] at this + linarith + · exact noise_one_sided E r U hE hr hU x y +end LaunchNoise +end BoundedTreewidthL1 +/-! Two deterministic shifted dyadic grids. A fair choice has the same +one-half interior probability needed by ordinary launch noise. -/ +namespace BoundedTreewidthL1.LaunchNoise +noncomputable def bandIndex (a t : ℝ) : ℤ := ⌊Real.logb 2 (t/a)⌋ +noncomputable def bandLower (a t : ℝ) : ℝ := a * (2:ℝ) ^ bandIndex a t + +noncomputable def gridFactor (b : Bool) : ℝ := if b then 3/2 else 1 + +lemma band_bounds (a t : ℝ) (ha : 0 < a) (ht : 0 < t) : + 0 < bandLower a t ∧ bandLower a t ≤ t ∧ t < 2 * bandLower a t := by + have hp : 0 < t/a := div_pos ht ha + have hl := (Real.le_logb_iff_rpow_le (by norm_num : (1:ℝ)<2) hp).mp + (Int.floor_le (Real.logb 2 (t/a))) + have hu := (Real.logb_lt_iff_lt_rpow (by norm_num : (1:ℝ)<2) hp).mp + (Int.lt_floor_add_one (Real.logb 2 (t/a))) + simp only [Real.rpow_intCast] at hl + rw [Real.rpow_add (by norm_num : (0:ℝ)<2), Real.rpow_intCast, Real.rpow_one] at hu + dsimp [bandLower, bandIndex] + have hlow := (le_div_iff₀ ha).mp hl + have hupp := (div_lt_iff₀ ha).mp hu + exact ⟨mul_pos ha (zpow_pos (by norm_num) _), by nlinarith, by nlinarith⟩ + +lemma bandIndex_eq (a t : ℝ) (j : ℤ) (ha : 0 < a) (ht : 0 < t) + (hl : a * (2:ℝ)^j ≤ t) (hu : t < 2 * (a * (2:ℝ)^j)) : + bandIndex a t = j := by + apply Int.floor_eq_iff.mpr + have hp := div_pos ht ha + constructor + · apply (Real.le_logb_iff_rpow_le (by norm_num : (1:ℝ)<2) hp).mpr + rw [Real.rpow_intCast] + exact (le_div_iff₀ ha).mpr (by nlinarith) + · apply (Real.logb_lt_iff_lt_rpow (by norm_num : (1:ℝ)<2) hp).mpr + rw [Real.rpow_add (by norm_num : (0:ℝ)<2), Real.rpow_intCast, Real.rpow_one] + exact (div_lt_iff₀ ha).mpr (by nlinarith) + +lemma band_same (a t u : ℝ) (ha : 0 < a) (_ : 0 < t) (hu : 0 < u) + (hlo : bandLower a t ≤ u) (hhi : u < 2 * bandLower a t) : + bandIndex a u = bandIndex a t := + bandIndex_eq a u (bandIndex a t) ha hu hlo hhi + +lemma gridFactor_pos (b : Bool) : 0 < gridFactor b := by cases b <;> norm_num [gridFactor] + +/-- Every positive height lies well inside one of the two grids. -/ +theorem two_grid_margin (t : ℝ) (ht : 0 < t) : + ∃ b : Bool, t/8 ≤ t - bandLower (gridFactor b) t ∧ + t/8 ≤ 2 * bandLower (gridFactor b) t - t := by + let j := bandIndex 1 t + let L := bandLower 1 t + have hb := band_bounds 1 t (by norm_num) ht + change 0 < L ∧ L ≤ t ∧ t < 2*L at hb + have hL : L = (2:ℝ)^j := by simp [L, bandLower, j] + by_cases h₁ : t/8 ≤ t-L + · by_cases h₂ : t/8 ≤ 2*L-t + · exact ⟨false, by simpa [gridFactor, L] using h₁, + by simpa [gridFactor, L] using h₂⟩ + · have heq : bandIndex (3/2) t = j := by + apply bandIndex_eq _ _ _ (by norm_num) ht + · rw [← hL]; linarith + · rw [← hL]; linarith [hb.2.2] + refine ⟨true, ?_, ?_⟩ <;> simp only [gridFactor, ↓reduceIte, bandLower, heq, ← hL] + · linarith + · linarith [hb.2.2] + · have hp : (2:ℝ)^(j-1) = L/2 := by + rw [zpow_sub₀ (by norm_num : (2:ℝ) ≠ 0), zpow_one, hL] + have heq : bandIndex (3/2) t = j-1 := by + apply bandIndex_eq _ _ _ (by norm_num) ht + · rw [hp]; linarith [hb.2.1] + · rw [hp]; linarith + refine ⟨true, ?_, ?_⟩ <;> simp only [gridFactor, ↓reduceIte, bandLower, heq, hp] + · linarith [hb.2.1] + · linarith +end BoundedTreewidthL1.LaunchNoise +namespace BoundedTreewidthL1.FiniteProductLaw +variable {I A : Type*} [Fintype I] [Fintype A] [DecidableEq I] +noncomputable def mass (p : I → A → ℝ) (x : I → A) : ℝ := ∏ i, p i (x i) +lemma nonneg + {I : Type treewidthLevel1} {A : Type treewidthLevel2} [Fintype I] [Fintype A] [DecidableEq I] + (p : I → A → ℝ) (hp : ∀ i a, 0 ≤ p i a) (x : I → A) : + 0 ≤ mass p x := Finset.prod_nonneg (fun i _ => hp i (x i)) +lemma total (p : I → A → ℝ) (hp : ∀ i, (∑ a, p i a) = 1) : + (∑ x, mass p x) = 1 := by + classical + simp only [mass] + rw [← Fintype.prod_sum] + simp only [hp, Finset.prod_const_one] +lemma factor_pos + {I : Type treewidthLevel1} {A : Type treewidthLevel2} [Fintype I] [Fintype A] [DecidableEq I] + (p : I → A → ℝ) (hp : ∀ i a, 0 ≤ p i a) + (x : I → A) (hx : 0 < mass p x) (i : I) : 0 < p i (x i) := by + by_contra h + have hz : p i (x i) = 0 := le_antisymm (le_of_not_gt h) (hp _ _) + have hh : mass p x = 0 := Finset.prod_eq_zero (Finset.mem_univ i) hz + linarith +lemma event (p : I → A → ℝ) (hp : ∀ i, (∑ a, p i a) = 1) + (j : I) (E : A → Prop) [DecidablePred E] : + (∑ x, if E (x j) then mass p x else 0) = ∑ a, if E a then p j a else 0 := by + classical + let q : I → A → ℝ := fun i a => if i = j then (if E a then p i a else 0) else p i a + have heq (x : I → A) : (if E (x j) then mass p x else 0) = ∏ i, q i (x i) := by + by_cases hx : E (x j) + · simp only [hx, ↓reduceIte, mass] + apply Finset.prod_congr rfl + intro i _ + by_cases hij : i = j + · subst i; simp [q, hx] + · simp [q, hij] + · simp only [hx, ↓reduceIte] + symm + apply Finset.prod_eq_zero (Finset.mem_univ j) + simp [q, hx] + simp_rw [heq] + rw [← Fintype.prod_sum] + calc + _ = ∑ a, q j a := by + apply Finset.prod_eq_single j + · intro i _ hij + simpa [q, hij] using hp i + · simp + _ = _ := by simp [q] +end BoundedTreewidthL1.FiniteProductLaw + +namespace BoundedTreewidthL1.LaunchNoise +open Metric Classical + +def MetricPaddedSupply {V : Type*} [Fintype V] [DecidableEq V] [MetricSpace V] + (α π : ℝ) : Prop := + ∀ r : ℝ, 0 < r → ∃ μ : (V → V) → ℝ, + (∀ P, 0 ≤ μ P) ∧ (∑ P, μ P) = 1 ∧ + (∀ P, 0 < μ P → ∀ x y, P x = P y → dist x y ≤ r) ∧ + ∀ x, π ≤ ∑ P, if (∀ y, dist x y ≤ α*r → P y = P x) then μ P else 0 + +def GoodBump {V J : Type*} [MetricSpace V] + (h : V → ℝ) (α η : ℝ) (φ : J → V → ℝ) (x : V) : Prop := + ∃ j, α/8 * η * h x ≤ φ j x ∧ + (∀ y, 0 ≤ φ j y) ∧ (∀ y, 4*η*h x < dist x y → φ j y = 0) + +def HasOrdinaryBumps {V : Type*} [MetricSpace V] + (h : V → ℝ) (α π η : ℝ) : Prop := + ∃ n m : ℕ, ∃ μ : Fin n → ℝ, ∃ φ : Fin n → Fin m → V → ℝ, + (∀ a, 0 ≤ μ a) ∧ (∑ a, μ a) = 1 ∧ + (∀ a (U : Fin m → ℝ), (∀ j, 0 ≤ U j ∧ U j ≤ 1) → + LipschitzWith 1 (fun x => ∑ j, U j * φ a j x) ∧ + ∀ x, 0 ≤ (∑ j, U j * φ a j x) ∧ (∑ j, U j * φ a j x) ≤ η*h x/2) ∧ + ∀ x, 0 < h x → π/2 ≤ ∑ a, if GoodBump h α η (φ a) x then μ a else 0 +end BoundedTreewidthL1.LaunchNoise +namespace BoundedTreewidthL1.LaunchNoise +open Metric Classical +variable {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + +noncomputable def bandSet (h : V → ℝ) : Finset ℤ := + Finset.univ.image (fun bx : Bool × V => bandIndex (gridFactor bx.1) (h bx.2)) + +noncomputable def bandKey (h : V → ℝ) (b : Bool) (x : V) : ↥(bandSet h) := + ⟨bandIndex (gridFactor b) (h x), Finset.mem_image.mpr ⟨(b,x), Finset.mem_univ _, rfl⟩⟩ + +noncomputable def bandScale (b : Bool) (j : ℤ) (η : ℝ) : ℝ := + η * (gridFactor b * (2:ℝ)^j) / 2 + +noncomputable def locationSet (h : V → ℝ) (b : Bool) + (P : ↥(bandSet h) → V → V) (i : ↥(bandSet h) × V) : Set V := + {x | 0 < h x ∧ bandIndex (gridFactor b) (h x) = (i.1 : ℤ) ∧ P i.1 x = i.2} + +lemma locationSet_disjoint + {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + (h : V → ℝ) (b : Bool) (P : ↥(bandSet h) → V → V) : + Pairwise (fun i j => Disjoint (locationSet h b P i) (locationSet h b P j)) := by + intro i j hij + apply Set.disjoint_left.mpr + intro x hi hj + have heq : i.1 = j.1 := Subtype.ext (hi.2.1.symm.trans hj.2.1) + have hval : i.2 = j.2 := by rw [← hi.2.2, heq, hj.2.2] + exact hij (Prod.ext heq hval) + +lemma location_self + {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + (h : V → ℝ) (b : Bool) (P : ↥(bandSet h) → V → V) + (x : V) (hx : 0 < h x) : + x ∈ locationSet h b P (bandKey h b x, P (bandKey h b x) x) := ⟨hx,rfl,rfl⟩ + +lemma bandScale_pos (b : Bool) (j : ℤ) (η : ℝ) (hη : 0 < η) : + 0 < bandScale b j η := by + dsimp [bandScale] + exact div_pos (mul_pos hη (mul_pos (gridFactor_pos b) (zpow_pos (by norm_num) j))) + (by norm_num) + +lemma bandScale_at + {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + (h : V → ℝ) (b : Bool) (x : V) (η : ℝ) : + bandScale b (bandKey h b x) η = η * bandLower (gridFactor b) (h x) / 2 := rfl + +lemma bump_noise_bounds (h : V → ℝ) (h0 : ∀ x, 0 ≤ h x) + (b : Bool) (P : ↥(bandSet h) → V → V) (η : ℝ) (hη : 0 < η) + (U : ↥(bandSet h) × V → ℝ) (hU : ∀ i, 0 ≤ U i ∧ U i ≤ 1) : + LipschitzWith 1 (noise (locationSet h b P) (fun i => bandScale b i.1 η / 2) U) ∧ + ∀ x, 0 ≤ noise (locationSet h b P) (fun i => bandScale b i.1 η / 2) U x ∧ + noise (locationSet h b P) (fun i => bandScale b i.1 η / 2) U x ≤ η*h x/2 := by + have hr (i : ↥(bandSet h) × V) : 0 ≤ bandScale b i.1 η/2 := + (div_pos (bandScale_pos b i.1 η hη) (by norm_num)).le + have hh := disjoint_noise (locationSet h b P) (fun i => bandScale b i.1 η/2) U + (locationSet_disjoint h b P) hr hU + refine ⟨hh.1, fun x => ⟨hh.2.1 x, ?_⟩⟩ + by_cases hx : 0 < h x + · have hh' := hh.2.2.1 _ x (location_self h b P x hx) + have hB := (band_bounds (gridFactor b) (h x) (gridFactor_pos b) hx).2.1 + rw [bandScale_at] at hh' + have hmul := mul_le_mul_of_nonneg_left hB hη.le + nlinarith [h0 x, mul_nonneg hη.le (h0 x)] + · have hn : ∀ i, x ∉ locationSet h b P i := fun i hi => hx hi.1 + rw [hh.2.2.2 x hn] + exact div_nonneg (mul_nonneg hη.le (h0 x)) (by norm_num) + +lemma location_ball (h : V → ℝ) (hh : LipschitzWith 1 h) + (b : Bool) (P : ↥(bandSet h) → V → V) (α η : ℝ) + (hα : 0 < α) (hα8 : α ≤ 1/8) (hη : 0 < η) (hη4 : η < 1/4) + (x : V) (hx : 0 < h x) + (hmargin : h x/8 ≤ h x - bandLower (gridFactor b) (h x) ∧ + h x/8 ≤ 2*bandLower (gridFactor b) (h x) - h x) + (hpad : ∀ y, dist x y ≤ α*bandScale b (bandKey h b x) η → + P (bandKey h b x) y = P (bandKey h b x) x) : + ball x (α*bandScale b (bandKey h b x) η) ⊆ + locationSet h b P (bandKey h b x, P (bandKey h b x) x) := by + intro y hy + have hdist : dist x y < α*bandScale b (bandKey h b x) η := by + simpa [mem_ball, dist_comm] using hy + have hb := band_bounds (gridFactor b) (h x) (gridFactor_pos b) hx + have hscale : α*bandScale b (bandKey h b x) η < h x/8 := by + rw [bandScale_at] + have h₁ := mul_le_mul_of_nonneg_left hb.2.1 hη.le + have h₂ := mul_le_mul_of_nonneg_left h₁ hα.le + have h₃ := mul_le_mul_of_nonneg_right hα8 (mul_nonneg hη.le hx.le) + have h₄ := mul_lt_mul_of_pos_right hη4 hx + nlinarith + have hL := hh.dist_le_mul x y + simp only [Real.dist_eq, NNReal.coe_one, one_mul, abs_le] at hL + have hxy : 0 < h y := by linarith [hL.2] + refine ⟨hxy, ?_, hpad y hdist.le⟩ + exact band_same (gridFactor b) (h x) (h y) (gridFactor_pos b) hx hxy + (by linarith [hL.2, hmargin.1]) (by linarith [hL.1, hmargin.2]) + +lemma good_location (h : V → ℝ) (hh : LipschitzWith 1 h) + (b : Bool) (P : ↥(bandSet h) → V → V) (α η : ℝ) + (hα : 0 < α) (hα8 : α ≤ 1/8) (hη : 0 < η) (hη4 : η < 1/4) + (hdiam : ∀ j x y, P j x = P j y → dist x y ≤ bandScale b j η) + (x : V) (hx : 0 < h x) + (hmargin : h x/8 ≤ h x - bandLower (gridFactor b) (h x) ∧ + h x/8 ≤ 2*bandLower (gridFactor b) (h x) - h x) + (hpad : ∀ y, dist x y ≤ α*bandScale b (bandKey h b x) η → + P (bandKey h b x) y = P (bandKey h b x) x) : + GoodBump h α η (fun i => bump (locationSet h b P i) (bandScale b i.1 η/2)) x := by + let j := bandKey h b x + let i : ↥(bandSet h) × V := (j, P j x) + have hp := bandScale_pos b j η hη + have hb := band_bounds (gridFactor b) (h x) (gridFactor_pos b) hx + have hball := location_ball h hh b P α η hα hα8 hη hη4 x hx hmargin hpad + have hcap : α*bandScale b j η ≤ bandScale b j η/2 := by nlinarith + have hbump := bump_padding (locationSet h b P i) (bandScale b j η/2) + x (α*bandScale b j η) hcap hball + refine ⟨i, ?_, (fun y => (bump_bounds _ _ (by positivity) y).1), ?_⟩ + · dsimp [i] + apply le_trans _ hbump + change α/8*η*h x ≤ α*(η*bandLower (gridFactor b) (h x)/2) + have hmul := mul_lt_mul_of_pos_left hb.2.2 (mul_pos hα hη) + nlinarith [mul_pos (mul_pos hα hη) hx] + · intro y hy + apply bump_zero _ _ (by positivity) + intro hmem + have heq : P j x = P j y := hmem.2.2.symm + have hd := hdiam j x y heq + have hs : bandScale b j η ≤ η*h x/2 := by + change η*bandLower (gridFactor b) (h x)/2 ≤ η*h x/2 + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hb.2.1 hη.le) (by norm_num) + nlinarith [mul_pos hη hx] +end BoundedTreewidthL1.LaunchNoise +namespace BoundedTreewidthL1.LaunchNoise +open Classical Metric +variable {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + +lemma ordinary_bumps_reindex + {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + {J Ω : Type} [Fintype J] [Fintype Ω] + (h : V → ℝ) (α π η : ℝ) (μ : Ω → ℝ) (φ : Ω → J → V → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ1 : (∑ a, μ a) = 1) + (hb : ∀ a (U : J → ℝ), (∀ j, 0 ≤ U j ∧ U j ≤ 1) → + LipschitzWith 1 (fun x => ∑ j, U j * φ a j x) ∧ + ∀ x, 0 ≤ (∑ j, U j * φ a j x) ∧ (∑ j, U j * φ a j x) ≤ η*h x/2) + (hg : ∀ x, 0 < h x → π/2 ≤ ∑ a, if GoodBump h α η (φ a) x then μ a else 0) : + HasOrdinaryBumps h α π η := by + let e := (Fintype.equivFin J).symm + let d := (Fintype.equivFin Ω).symm + refine ⟨Fintype.card Ω, Fintype.card J, μ ∘ d, (fun a j => φ (d a) (e j)), + (fun a => hμ _), ?_, ?_, ?_⟩ + · simpa using (d.sum_comp μ).trans hμ1 + · intro a U hU + have hh := hb (d a) (U ∘ e.symm) (fun j => hU _) + have heq : (fun x => ∑ j, U j * φ (d a) (e j) x) = + (fun x => ∑ j, (U ∘ e.symm) j * φ (d a) j x) := by + funext x + simpa using e.sum_comp (fun j => (U ∘ e.symm) j * φ (d a) j x) + constructor + · rw [heq] + exact hh.1 + · intro x + rw [show (∑ j, U j * φ (d a) (e j) x) = + (∑ j, (U ∘ e.symm) j * φ (d a) j x) from congrFun heq x] + exact hh.2 x + · intro x hx + have heq (a : Fin (Fintype.card Ω)) : + GoodBump h α η (fun j => φ (d a) (e j)) x ↔ GoodBump h α η (φ (d a)) x := by + constructor + · rintro ⟨j,hj,hj0,hjS⟩; exact ⟨e j,hj,hj0,hjS⟩ + · rintro ⟨j,hj,hj0,hjS⟩ + refine ⟨e.symm j, ?_, ?_, ?_⟩ <;> simpa using ‹_› + simp_rw [heq] + have he := d.sum_comp (fun a => if GoodBump h α η (φ a) x then μ a else 0) + exact (hg x hx).trans he.ge + +noncomputable def locationMass (h : V → ℝ) + (p : Bool → ↥(bandSet h) → (V → V) → ℝ) + (a : Bool × (↥(bandSet h) → V → V)) : ℝ := + (1/2) * FiniteProductLaw.mass (p a.1) a.2 + +lemma locationMass_nonneg + {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + (h : V → ℝ) + (p : Bool → ↥(bandSet h) → (V → V) → ℝ) (hp : ∀ b j P, 0 ≤ p b j P) : + ∀ a, 0 ≤ locationMass h p a := by + intro a + exact mul_nonneg (by norm_num) (FiniteProductLaw.nonneg _ (hp a.1) _) + +lemma locationMass_total + {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + (h : V → ℝ) + (p : Bool → ↥(bandSet h) → (V → V) → ℝ) + (hp : ∀ b j, (∑ P, p b j P) = 1) : + (∑ a, locationMass h p a) = 1 := by + rw [Fintype.sum_prod_type] + simp only [locationMass, ← Finset.mul_sum, FiniteProductLaw.total _ (hp _)] + norm_num [Fintype.sum_bool] + +lemma locationMass_event + {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + (h : V → ℝ) + (p : Bool → ↥(bandSet h) → (V → V) → ℝ) + (hp : ∀ b j, (∑ P, p b j P) = 1) (b : Bool) (j : ↥(bandSet h)) + (E : (V → V) → Prop) : + (∑ a : Bool × (↥(bandSet h) → V → V), + if a.1 = b ∧ E (a.2 j) then locationMass h p a else 0) = + (1/2) * ∑ P, if E P then p b j P else 0 := by + classical + rw [Fintype.sum_prod_type] + have heq (b' : Bool) : + (∑ P, if b' = b ∧ E (P j) then locationMass h p (b',P) else 0) = + if b' = b then (1/2) * ∑ P, if E P then p b j P else 0 else 0 := by + by_cases he : b' = b + · subst b' + simp only [true_and, locationMass, ite_true] + have he (q : ↥(bandSet h) → V → V) : + (if E (q j) then (1/2:ℝ) * FiniteProductLaw.mass (p b) q else 0) = + (1/2) * (if E (q j) then FiniteProductLaw.mass (p b) q else 0) := by + split_ifs <;> ring + simp_rw [he] + rw [← Finset.mul_sum, FiniteProductLaw.event _ (hp b)] + · simp [he] + simp_rw [heq] + simp + +/-- Finite ordinary noise from a padded supply, which is available +unconditionally for the weighted graph metrics by `PaddedConstruction`. -/ +theorem finite_ordinary_bumps + (h : V → ℝ) (hh : LipschitzWith 1 h) (h0 : ∀ x, 0 ≤ h x) + (α π η : ℝ) (hα : 0 < α) (hα8 : α ≤ 1/8) (hη : 0 < η) (hη4 : η < 1/4) + (hsupply : MetricPaddedSupply (V := V) α π) : HasOrdinaryBumps h α π η := by + classical + have hs (b : Bool) (j : ↥(bandSet h)) := hsupply (bandScale b j η) (bandScale_pos b j η hη) + choose p hp hp1 hdiam hpad using hs + let φ : (Bool × (↥(bandSet h) → V → V)) → (↥(bandSet h) × V) → V → ℝ := + fun a i => bump (locationSet h a.1 a.2 i) (bandScale a.1 i.1 η/2) + apply ordinary_bumps_reindex h α π η (locationMass h p) φ + (locationMass_nonneg h p hp) (locationMass_total h p hp1) + · intro a U hU + exact bump_noise_bounds h h0 a.1 a.2 η hη U hU + · intro x hx + obtain ⟨b,hmargin⟩ := two_grid_margin (h x) hx + let j := bandKey h b x + let E : (V → V) → Prop := fun P => ∀ y, dist x y ≤ α*bandScale b j η → P y = P x + have hsum : (∑ a : Bool × (↥(bandSet h) → V → V), + if a.1 = b ∧ E (a.2 j) then locationMass h p a else 0) = + (1/2) * ∑ P, if E P then p b j P else 0 := by + convert locationMass_event h p hp1 b j E using 1 + · apply Finset.sum_congr (by ext; simp) + intro a _ + split_ifs <;> rfl + · congr 1 + apply Finset.sum_congr (by ext; simp) + intro P _ + split_ifs <;> rfl + have hle : (∑ a : Bool × (↥(bandSet h) → V → V), + if a.1 = b ∧ E (a.2 j) then locationMass h p a else 0) ≤ + ∑ a, if GoodBump h α η (φ a) x then locationMass h p a else 0 := by + apply Finset.sum_le_sum + intro a _ + have hnonneg := locationMass_nonneg h p hp a + by_cases ha : a.1 = b ∧ E (a.2 j) + · rw [ite_eq_left ha] + by_cases hpos : 0 < locationMass h p a + · have hprod : 0 < FiniteProductLaw.mass (p a.1) a.2 := by + dsimp [locationMass] at hpos + linarith + have hgood : GoodBump h α η (φ a) x := by + have hda : ∀ j x y, a.2 j x = a.2 j y → dist x y ≤ bandScale a.1 j η := by + intro j x y hxy + exact hdiam a.1 j (a.2 j) + (FiniteProductLaw.factor_pos _ (hp a.1) _ hprod j) x y hxy + apply good_location h hh a.1 a.2 α η hα hα8 hη hη4 hda x hx + · simpa [ha.1] using hmargin + · simpa [ha.1, j, E] using ha.2 + rw [ite_eq_left hgood] + · have hz : locationMass h p a = 0 := le_antisymm (le_of_not_gt hpos) hnonneg + simp [hz] + · rw [ite_eq_right ha] + split_ifs <;> positivity + have hle2 : (1/2) * (∑ P, if E P then p b j P else 0) ≤ + ∑ a, if GoodBump h α η (φ a) x then locationMass h p a else 0 := by + calc + _ = ∑ a : Bool × (↥(bandSet h) → V → V), + if a.1 = b ∧ E (a.2 j) then locationMass h p a else 0 := hsum.symm + _ ≤ _ := hle + have hpπ := hpad b j x + change π ≤ ∑ P, if E P then p b j P else 0 at hpπ + have hh' := mul_le_mul_of_nonneg_left hpπ (by norm_num : (0:ℝ) ≤ 1/2) + exact (by linarith : π/2 ≤ (1/2)*∑ P, if E P then p b j P else 0).trans hle2 +end BoundedTreewidthL1.LaunchNoise + +/-! The actual finite product probability space for the ordinary launch noise. +No random coefficient distribution or independence is supplied as an assumption. +-/ +namespace BoundedTreewidthL1.LaunchNoise +open MeasureTheory ProbabilityTheory +attribute [local instance] Classical.propDecidable +open scoped unitInterval ENNReal +noncomputable def locationLaw {n : ℕ} (μ : Fin n → ℝ) : Measure (Fin n) := + ∑ a, ENNReal.ofReal (μ a) • Measure.dirac a +abbrev CoeffCube (m : ℕ) := Fin m → I +abbrev NoiseSpace (n m : ℕ) := I × (Fin n × CoeffCube m) +noncomputable def noiseLaw {n : ℕ} (m : ℕ) (μ : Fin n → ℝ) : Measure (NoiseSpace n m) := + (volume : Measure I).prod ((locationLaw μ).prod volume) +def noiseXi {n m : ℕ} (ω : NoiseSpace n m) : ℝ := 1 + (ω.1 : ℝ) +noncomputable def noiseV {V : Type*} {n m : ℕ} (φ : Fin n → Fin m → V → ℝ) + (ω : NoiseSpace n m) (x : V) : ℝ := ∑ j, (ω.2.2 j : ℝ) * φ ω.2.1 j x +noncomputable def noiseG {V : Type*} {n m : ℕ} (h : V → ℝ) + (φ : Fin n → Fin m → V → ℝ) (ω : NoiseSpace n m) (x : V) : ℝ := + noiseXi ω * h x + noiseV φ ω x + +lemma locationLaw_apply {n : ℕ} (μ : Fin n → ℝ) (S : Set (Fin n)) : + locationLaw μ S = ∑ a, if a ∈ S then ENNReal.ofReal (μ a) else 0 := by + classical + simp [locationLaw, Set.indicator, apply_ite] + +lemma locationLaw_probability {n : ℕ} (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) : IsProbabilityMeasure (locationLaw μ) := by + constructor + rw [locationLaw_apply] + simp only [Set.mem_univ, ↓reduceIte] + rw [← ENNReal.ofReal_sum_of_nonneg (fun a _ => hμ a), hμ₁, ENNReal.ofReal_one] + +lemma noiseLaw_probability {n m : ℕ} (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) : IsProbabilityMeasure (noiseLaw m μ) := by + let := locationLaw_probability μ hμ hμ₁ + unfold noiseLaw + infer_instance + +lemma noise_locationLaw {n m : ℕ} (μ : Fin n → ℝ) : + Measure.map (fun ω : NoiseSpace n m => ω.2.1) (noiseLaw m μ) = locationLaw μ := by + unfold noiseLaw + change Measure.map (Prod.fst ∘ Prod.snd) _ = _ + rw [← Measure.map_map measurable_fst measurable_snd, Measure.map_snd_prod] + simp only [measure_univ, one_smul, Measure.map_fst_prod] + +lemma noise_goodProbability {n m : ℕ} (μ : Fin n → ℝ) (hμ : ∀ a, 0 ≤ μ a) + (E : Fin n → Prop) : + noiseLaw m μ {ω | E ω.2.1} = ENNReal.ofReal (∑ a, if E a then μ a else 0) := by + classical + have hm : MeasurableSet {a : Fin n | E a} := MeasurableSet.of_discrete + change noiseLaw m μ ((Prod.fst ∘ Prod.snd) ⁻¹' {a : Fin n | E a}) = _ + rw [← Measure.map_apply (measurable_fst.comp measurable_snd) hm] + change (Measure.map (fun ω : NoiseSpace n m => ω.2.1) (noiseLaw m μ)) {a | E a} = _ + rw [noise_locationLaw, locationLaw_apply] + rw [ENNReal.ofReal_sum_of_nonneg (fun a _ => by split_ifs <;> simp [hμ])] + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> simp_all + +lemma noiseXi_measurable {n m : ℕ} : Measurable (noiseXi (n := n) (m := m)) := by + unfold noiseXi + fun_prop + +lemma noiseV_measurable {V : Type*} {n m : ℕ} (φ : Fin n → Fin m → V → ℝ) : + Measurable (noiseV φ) := by + apply Measurable.of_eval + intro x + unfold noiseV + apply Finset.measurable_sum + intro j _ + have hu : Measurable (fun ω : NoiseSpace n m => (ω.2.2 j : ℝ)) := by fun_prop + have ha : Measurable (fun ω : NoiseSpace n m => φ ω.2.1 j x) := + (show Measurable (fun a : Fin n => φ a j x) from Measurable.of_discrete).comp + (measurable_fst.comp measurable_snd) + exact hu.mul ha + +lemma noiseG_measurable {V : Type*} {n m : ℕ} (h : V → ℝ) + (φ : Fin n → Fin m → V → ℝ) : Measurable (noiseG h φ) := by + apply Measurable.of_eval + intro x + exact (noiseXi_measurable.mul_const (h x)).add ((measurable_pi_apply x).comp (noiseV_measurable φ)) + +lemma noiseXi_uniform {n m : ℕ} (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) : + MeasurePreserving (fun ω : NoiseSpace n m => noiseXi ω - 1) + (noiseLaw m μ) (volume.restrict (Set.Icc (0:ℝ) 1)) := by + let := locationLaw_probability μ hμ hμ₁ + simpa [noiseLaw, noiseXi, Function.comp_def, unitInterval] using + (unitInterval.measurePreserving_coe.comp + (measurePreserving_fst (μ := (volume : Measure I)) + (ν := (locationLaw μ).prod (volume : Measure (CoeffCube m))))) + +lemma noiseXi_indep {V : Type*} {n m : ℕ} (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) + (φ : Fin n → Fin m → V → ℝ) : + IndepFun noiseXi (noiseV φ) (noiseLaw m μ) := by + let := locationLaw_probability μ hμ hμ₁ + exact indepFun_prod (X := fun t : I => 1 + (t : ℝ)) (by fun_prop) + (Y := fun ac : Fin n × CoeffCube m => fun x => ∑ j, (ac.2 j : ℝ) * φ ac.1 j x) + (by + apply Measurable.of_eval + intro x + apply Finset.measurable_sum + intro j _ + have hu : Measurable (fun ac : Fin n × CoeffCube m => (ac.2 j : ℝ)) := by fun_prop + have ha : Measurable (fun ac : Fin n × CoeffCube m => φ ac.1 j x) := + (show Measurable (fun a : Fin n => φ a j x) from Measurable.of_discrete).comp measurable_fst + exact hu.mul ha) + +lemma cube_uniform {m : ℕ} (j : Fin m) : + MeasurePreserving (fun U : CoeffCube m => (U j : ℝ)) volume + (volume.restrict (Set.Icc (0:ℝ) 1)) := + unitInterval.measurePreserving_coe.comp (measurePreserving_eval (fun _ : Fin m => (volume : Measure I)) j) + +lemma cube_independent (m : ℕ) : + iIndepFun (fun j (U : CoeffCube m) => (U j : ℝ)) volume := + iIndepFun_pi (fun _ => measurable_subtype_coe.aemeasurable) + +/-- Fresh independent randomness works with any previously constructed probability space. -/ +lemma fresh_noise {Ω : Type*} [MeasurableSpace Ω] (ν : Measure Ω) [IsProbabilityMeasure ν] + {V : Type*} {n m : ℕ} (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) + (h : V → ℝ) (φ : Fin n → Fin m → V → ℝ) : + IndepFun (fun ω : Ω × NoiseSpace n m => ω.1) + (fun ω => noiseG h φ ω.2) (ν.prod (noiseLaw m μ)) := by + let := noiseLaw_probability (m := m) μ hμ hμ₁ + exact indepFun_prod measurable_id (noiseG_measurable h φ) + +lemma noiseXi_uniform_interval {n m : ℕ} (μ : Fin n → ℝ) + (hμ : ∀ a, 0 ≤ μ a) (hμ₁ : ∑ a, μ a = 1) : + MeasurePreserving (noiseXi (n := n) (m := m)) (noiseLaw m μ) + (volume.restrict (Set.Icc (1:ℝ) 2)) := by + have he : (fun x : ℝ => 1 + x) ⁻¹' Set.Icc 1 2 = Set.Icc 0 1 := by + ext x + simp only [Set.mem_preimage, Set.mem_Icc] + constructor <;> rintro ⟨ha,hb⟩ <;> constructor <;> linarith + have ht := (measurePreserving_add_left (volume : Measure ℝ) 1).restrict_preimage + (s := Set.Icc 1 2) measurableSet_Icc + rw [he] at ht + simpa [Function.comp_def] using ht.comp (noiseXi_uniform (m := m) μ hμ hμ₁) + +lemma noise_deterministic {V : Type*} [MetricSpace V] {n m : ℕ} + (h : V → ℝ) (hh : LipschitzWith 1 h) (hhn : ∀ x, 0 ≤ h x) + (η : ℝ) (hη : η < 1/4) (φ : Fin n → Fin m → V → ℝ) + (hv : ∀ a (U : Fin m → ℝ), (∀ j, 0 ≤ U j ∧ U j ≤ 1) → + LipschitzWith 1 (fun x => ∑ j, U j * φ a j x) ∧ + ∀ x, 0 ≤ (∑ j, U j * φ a j x) ∧ (∑ j, U j * φ a j x) ≤ η*h x/2) + (ω : NoiseSpace n m) : + LipschitzWith 1 (noiseV φ ω) ∧ + (∀ x, 0 ≤ noiseV φ ω x ∧ noiseV φ ω x ≤ η * h x / 2) ∧ + LipschitzWith 3 (noiseG h φ ω) ∧ + ∀ x, h x ≤ noiseG h φ ω x ∧ noiseG h φ ω x ≤ (5/2) * h x := by + obtain ⟨hlip, hbound⟩ := hv ω.2.1 (fun j => (ω.2.2 j : ℝ)) (fun j => (ω.2.2 j).property) + change LipschitzWith 1 (noiseV φ ω) at hlip + change ∀ x, 0 ≤ noiseV φ ω x ∧ noiseV φ ω x ≤ η * h x / 2 at hbound + have hξ : 1 ≤ noiseXi ω ∧ noiseXi ω ≤ 2 := by + have hp := ω.1.property + dsimp [noiseXi] + constructor <;> linarith [hp.1, hp.2] + refine ⟨hlip, hbound, ?_, ?_⟩ + · apply LipschitzWith.of_dist_le_mul + intro x y + have hhl : |h x - h y| ≤ dist x y := by simpa [Real.dist_eq] using hh.dist_le_mul x y + have hvl : |noiseV φ ω x - noiseV φ ω y| ≤ dist x y := by + simpa [Real.dist_eq] using hlip.dist_le_mul x y + rw [Real.dist_eq] + calc + |noiseG h φ ω x - noiseG h φ ω y| = + |noiseXi ω * (h x - h y) + (noiseV φ ω x - noiseV φ ω y)| := by + congr 1 + dsimp [noiseG] + ring + _ ≤ |noiseXi ω * (h x - h y)| + |noiseV φ ω x - noiseV φ ω y| := abs_add_le _ _ + _ = noiseXi ω * |h x - h y| + |noiseV φ ω x - noiseV φ ω y| := by + rw [abs_mul, abs_of_nonneg (by linarith : 0 ≤ noiseXi ω)] + _ ≤ 2 * dist x y + dist x y := add_le_add + ((mul_le_mul_of_nonneg_left hhl (by linarith)).trans + (mul_le_mul_of_nonneg_right hξ.2 dist_nonneg)) hvl + _ = (3 : NNReal) * dist x y := by norm_num; ring + · intro x + have hz := hhn x + have hb := hbound x + dsimp [noiseG] + constructor + · nlinarith [mul_le_mul_of_nonneg_right hξ.1 hz] + · nlinarith [mul_le_mul_of_nonneg_right hξ.2 hz, mul_nonneg (le_of_lt (sub_pos.mpr hη)) hz] +end BoundedTreewidthL1.LaunchNoise + +namespace BoundedTreewidthL1.LaunchNoise +open MeasureTheory ProbabilityTheory +open scoped unitInterval ENNReal +attribute [local instance] Classical.propDecidable +/-- Complete finite ordinary-noise sampler; its law is the displayed product +of a fresh uniform xi, a finite location law, and independent uniform amplitudes. -/ +def HasOrdinaryNoise {V : Type*} [MetricSpace V] + (h : V → ℝ) (α π η : ℝ) : Prop := + ∃ n m : ℕ, ∃ μ : Fin n → ℝ, ∃ φ : Fin n → Fin m → V → ℝ, + (∀ a, 0 ≤ μ a) ∧ (∑ a, μ a) = 1 ∧ + IsProbabilityMeasure (noiseLaw m μ) ∧ + Measurable (noiseG h φ) ∧ + MeasurePreserving (noiseXi (n := n) (m := m)) (noiseLaw m μ) + (volume.restrict (Set.Icc (1:ℝ) 2)) ∧ + IndepFun noiseXi (noiseV φ) (noiseLaw m μ) ∧ + (∀ ω : NoiseSpace n m, + LipschitzWith 1 (noiseV φ ω) ∧ + (∀ x, 0 ≤ noiseV φ ω x ∧ noiseV φ ω x ≤ η * h x / 2) ∧ + LipschitzWith 3 (noiseG h φ ω) ∧ + ∀ x, h x ≤ noiseG h φ ω x ∧ noiseG h φ ω x ≤ (5/2) * h x) ∧ + (∀ x, 0 < h x → ENNReal.ofReal (π/2) ≤ + noiseLaw m μ {ω | GoodBump h α η (φ ω.2.1) x}) ∧ + (∀ j : Fin m, MeasurePreserving (fun U : CoeffCube m => (U j : ℝ)) volume + (volume.restrict (Set.Icc (0:ℝ) 1))) ∧ + iIndepFun (fun j (U : CoeffCube m) => (U j : ℝ)) volume + +end BoundedTreewidthL1.LaunchNoise + +namespace BoundedTreewidthL1.LaunchNoise +open MeasureTheory ProbabilityTheory +open scoped unitInterval ENNReal +attribute [local instance] Classical.propDecidable +variable {V : Type} [Fintype V] [DecidableEq V] [MetricSpace V] + +theorem metric_ordinary_noise + (h : V → ℝ) (hh : LipschitzWith 1 h) (h0 : ∀ x, 0 ≤ h x) + (α π η : ℝ) (hα : 0 < α) (hα8 : α ≤ 1/8) (_ : 0 < π) + (hη : 0 < η) (hη4 : η < 1/4) + (hsupply : MetricPaddedSupply (V := V) α π) : HasOrdinaryNoise h α π η := by + classical + obtain ⟨n,m,μ,φ,hμ,hμ₁,hv,hgood⟩ := + finite_ordinary_bumps h hh h0 α π η hα hα8 hη hη4 hsupply + refine ⟨n,m,μ,φ,hμ,hμ₁,noiseLaw_probability μ hμ hμ₁, + noiseG_measurable h φ,noiseXi_uniform_interval μ hμ hμ₁, + noiseXi_indep μ hμ hμ₁ φ,?_,?_,cube_uniform,cube_independent m⟩ + · exact noise_deterministic h hh h0 η hη4 φ hv + · intro x hx + rw [noise_goodProbability (m := m) μ hμ (fun a => GoodBump h α η (φ a) x)] + exact ENNReal.ofReal_le_ofReal (hgood x hx) +end BoundedTreewidthL1.LaunchNoise + +namespace BoundedTreewidthL1.LaunchNoise +/-- Uniform graph-metric input; the distance is definitionally the original +positive-weight shortest-path distance, with no edge-ratio restriction. -/ +theorem graph_ordinary_noise (k : ℕ) (hk : 2 ≤ k) : + ∃ α π : ℝ, 0 < α ∧ α ≤ 1/8 ∧ 0 < π ∧ π ≤ 1 ∧ + ∀ (V : Type) [Fintype V] [DecidableEq V] [Nontrivial V] + (G : SimpleGraph V) (hG : G.Connected) (_ : HasTreeDecomposition G k) + (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e), + let := weightedMetricSpace G ℓ hG hℓ + ∀ (A : Set V), A.Nonempty → ∀ η : ℝ, 0 < η → η < 1/4 → + HasOrdinaryNoise (fun x => Metric.infDist x A) α π η := by + classical + obtain ⟨α,π,hα,hα8,hπ,hπ1,hpad⟩ := PaddedPartitions.uniform_padded_partitions k hk + refine ⟨α,π,hα,hα8,hπ,hπ1,?_⟩ + intro V _ _ _ G hG hT ℓ hℓ metric + let _ : MetricSpace V := metric + intro A hA η hη hη4 + have hsupply : MetricPaddedSupply (V := V) α π := by + intro r hr + obtain ⟨μ,hμ,hμ1,hdiam,hprob⟩ := hpad V G hG hT ℓ hℓ r hr + refine ⟨μ,hμ,hμ1,hdiam,?_⟩ + intro x + apply le_trans (hprob x) + apply le_of_eq + unfold PaddedPartitions.paddingProbability + apply Finset.sum_congr (by ext; simp) + intro P _ + have hd (u v : V) : dist u v = shortestPathDistance G ℓ u v := rfl + simp only [PaddedPartitions.PaddedAt, hd] + exact congrArg (fun d : Decidable + (∀ y : V, shortestPathDistance G ℓ x y ≤ α * r → P y = P x) => + @ite ℝ _ d (μ P) 0) (Subsingleton.elim _ _) + exact metric_ordinary_noise (fun x => Metric.infDist x A) + (Metric.lipschitz_infDist_pt A) (fun x => Metric.infDist_nonneg) α π η hα hα8 hπ hη hη4 hsupply +end BoundedTreewidthL1.LaunchNoise + +namespace BoundedTreewidthL1.TreeCache +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V : Type*} + +lemma fresh_eq_singleton (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (i : I) : + AnchorTreeParticles.fresh (RootedTree.forest T hT root) + (active T hT root B D k d J) i = {i} := by + classical + unfold AnchorTreeParticles.fresh AnchorTreeParticles.retained + cases hp : (RootedTree.forest T hT root).parent i with + | none => + have hi : i = root := by + by_contra hi + simp [RootedTree.forest,hi] at hp + subst i + simp only [Option.elim_none,Finset.sdiff_empty] + exact active_root T hT root B D k d J + | some p => + simp only [Option.elim_some] + convert active_sdiff_parent T hT root B D k d J hp using 1 + ext a + simp only [Finset.mem_sdiff,Finset.mem_inter] + tauto + +lemma origin_self (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) + (i a : I) (ha : a ∈ active T hT root B D k d J i) : + AnchorTreeParticles.origin (RootedTree.forest T hT root) + (active T hT root B D k d J) root i a = a := by + have hf := AnchorTreeParticles.origin_fresh (RootedTree.forest T hT root) + (active T hT root B D k d J) root i a ha + rw [fresh_eq_singleton,Finset.mem_singleton] at hf + exact hf.symm +end BoundedTreewidthL1.TreeCache + +namespace BoundedTreewidthL1 +open MeasureTheory +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V : Type*} [Fintype V] + +lemma bagDistance_eq_infDist [DecidableEq V] + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (A : Finset V) (hA : A.Nonempty) (x : V) : + let := weightedMetricSpace G ℓ hG hℓ + bagDistance G ℓ A hA x = Metric.infDist x (A : Set V) := by + let := weightedMetricSpace G ℓ hG hℓ + apply le_antisymm + · apply (Metric.le_infDist (show (A : Set V).Nonempty from hA)).mpr + intro a ha + exact bagDistance_le G ℓ A hA x ha + · obtain ⟨a,ha,heq⟩ := bagDistance_attained G ℓ A hA x + rw [heq] + exact Metric.infDist_le_dist_of_mem ha +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.LaunchNoise +open MeasureTheory ProbabilityTheory +open scoped unitInterval ENNReal +/-- The complete finite launch data, retaining both independent uniform variables +and the random good-bump event required in the non-collapse argument. -/ +structure OrdinarySeed {V : Type*} [MetricSpace V] (h : V → ℝ) (α π η : ℝ) where + n : ℕ + m : ℕ + mass : Fin n → ℝ + bump : Fin n → Fin m → V → ℝ + mass_nonneg : ∀ a, 0 ≤ mass a + mass_total : (∑ a, mass a) = 1 + probability : IsProbabilityMeasure (noiseLaw m mass) + measurable : Measurable (noiseG h bump) + xi_uniform : MeasurePreserving (noiseXi (n := n) (m := m)) (noiseLaw m mass) + (volume.restrict (Set.Icc (1:ℝ) 2)) + xi_independent : IndepFun noiseXi (noiseV bump) (noiseLaw m mass) + bounds : ∀ ω : NoiseSpace n m, + LipschitzWith 1 (noiseV bump ω) ∧ + (∀ x, 0 ≤ noiseV bump ω x ∧ noiseV bump ω x ≤ η * h x / 2) ∧ + LipschitzWith 3 (noiseG h bump ω) ∧ + ∀ x, h x ≤ noiseG h bump ω x ∧ noiseG h bump ω x ≤ (5/2) * h x + good : ∀ x, 0 < h x → ENNReal.ofReal (π/2) ≤ + noiseLaw m mass {ω | GoodBump h α η (bump ω.2.1) x} + coefficients_uniform : ∀ j : Fin m, + MeasurePreserving (fun U : CoeffCube m => (U j : ℝ)) volume + (volume.restrict (Set.Icc (0:ℝ) 1)) + coefficients_independent : iIndepFun (fun j (U : CoeffCube m) => (U j : ℝ)) volume + +lemma OrdinarySeed.exists_of_has {V : Type*} [MetricSpace V] {h : V → ℝ} {α π η : ℝ} + (hN : HasOrdinaryNoise h α π η) : Nonempty (OrdinarySeed h α π η) := by + obtain ⟨n,m,μ,φ,hμ,hμ₁,hprob,hmeas,hxi,hind,hbound,hgood,huni,hindep⟩ := hN + exact ⟨⟨n,m,μ,φ,hμ,hμ₁,hprob,hmeas,hxi,hind,hbound,hgood,huni,hindep⟩⟩ +end BoundedTreewidthL1.LaunchNoise + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/Main.lean b/lean/OAI/Combinatorics/TreewidthL1/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..bc8b92a4b0aa73a24be359b4ef8f85448f544b22 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/Main.lean @@ -0,0 +1,188 @@ +import OAI.Combinatorics.TreewidthL1.CobagEmbedding + +namespace OAI + +namespace BoundedTreewidthL1 +variable {V : Type*} (G : SimpleGraph V) + +/-- Removing empty bags preserves the exact tree-decomposition hypotheses. +The graph is only required to be nonempty and connected; no extra metric +hypothesis enters this combinatorial reduction. -/ +theorem nonempty_tree_decomposition [Fintype V] [DecidableEq V] [Nonempty V] + (hG : G.Connected) (k : ℕ) (hdec : HasTreeDecomposition G k) : + ∃ n : ℕ, ∃ T : SimpleGraph (Fin n), ∃ bag : Fin n → Finset V, + T.IsTree ∧ + (∀ v : V, ∃ t, v ∈ bag t) ∧ + (∀ u v : V, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) ∧ + (∀ v : V, (T.induce {t | v ∈ bag t}).Connected) ∧ + (∀ t, (bag t).card ≤ k) ∧ (∀ t, (bag t).Nonempty) := by + classical + obtain ⟨n, T, B, hT, hcover, hedge, hocc, hsize⟩ := hdec + let S : Set (Fin n) := {i | (B i).Nonempty} + have hS : (T.induce S).Connected := by + have hc : (G.induce Set.univ).Connected := G.induceUnivIso.connected_iff.mpr hG + have := touched_bags_connected_set G T B hedge hocc Set.univ hc + have heq : {t | ∃ z ∈ (Set.univ : Set V), z ∈ B t} = S := by + ext t + simp [S, Finset.nonempty_def] + rw [heq] at this + exact this + let I := {i : Fin n // i ∈ S} + let e : Fin (Fintype.card I) ≃ I := (Fintype.equivFin I).symm + let T' : SimpleGraph (Fin (Fintype.card I)) := (T.induce S).comap e + let B' : Fin (Fintype.card I) → Finset V := fun i => B (e i).val + have hT' : T'.IsTree := + (SimpleGraph.Iso.comap e (T.induce S)).isTree_iff.mpr ⟨hS, hT.isAcyclic.induce S⟩ + refine ⟨Fintype.card I, T', B', hT', ?_, ?_, ?_, ?_, ?_⟩ + · intro v + obtain ⟨i, hi⟩ := hcover v + refine ⟨e.symm ⟨i, v, hi⟩, ?_⟩ + simpa [B'] using hi + · intro u v huv + obtain ⟨i, hui, hvi⟩ := hedge u v huv + refine ⟨e.symm ⟨i, u, hui⟩, ?_, ?_⟩ <;> simpa [B'] + · intro v + let f : {i : Fin n // v ∈ B i} → {j : Fin (Fintype.card I) // v ∈ B' j} := + fun i => ⟨e.symm ⟨i.val, v, i.property⟩, by simpa [B'] using i.property⟩ + let hf : (T.induce {i | v ∈ B i}) →g (T'.induce {j | v ∈ B' j}) := + ⟨f, by + intro i j hij + change T.Adj (e (f i).val).val (e (f j).val).val + simpa [f] using hij⟩ + apply (hocc v).map hf + intro j + refine ⟨⟨(e j.val).val, j.property⟩, ?_⟩ + apply Subtype.ext + change e.symm _ = j.val + rw [Equiv.symm_apply_eq] + · intro i + exact hsize _ + · intro i + exact (e i).property + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +noncomputable section + +/-- Direct sum of two finite real L1 vectors, with the sum norm (not the maximum +norm on an ordinary product). -/ +def l1Append {m n : ℕ} (x : PiLp (1 : ENNReal) (fun _ : Fin m => ℝ)) + (y : PiLp (1 : ENNReal) (fun _ : Fin n => ℝ)) : + PiLp (1 : ENNReal) (fun _ : Fin (m+n) => ℝ) := + WithLp.toLp 1 (Fin.append x.ofLp y.ofLp) + +lemma l1Append_norm_sub {m n : ℕ} (x x' : PiLp (1 : ENNReal) (fun _ : Fin m => ℝ)) + (y y' : PiLp (1 : ENNReal) (fun _ : Fin n => ℝ)) : + ‖l1Append x y-l1Append x' y'‖ = ‖x-x'‖+‖y-y'‖ := by + simp only [PiLp.norm_eq_sum (by simp : 0 < (1 : ENNReal).toReal), ENNReal.toReal_one, + Real.rpow_one, div_self (by norm_num : (1:ℝ) ≠ 0)] + rw [Fin.sum_univ_add] + simp [l1Append, PiLp.sub_apply] + +/-- The final purely metric bridge: a common-bag bound on both endpoints and +co-bag separation imply a global all-pairs lower comparison. -/ +lemma common_bag_comparison {V : Type*} [Fintype V] [DecidableEq V] + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + {I : Type*} (B : I → Finset V) (hne : ∀ i, (B i).Nonempty) + {m n : ℕ} (Φ : V → PiLp (1 : ENNReal) (fun _ : Fin m => ℝ)) + (Ψ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ)) + (U c a : ℝ) (hU : 0 ≤ U) (hc : 0 < c) (ha : 0 < a) + (hupper : ∀ x y, ‖Ψ x-Ψ y‖ ≤ U*shortestPathDistance G ℓ x y) + (hcobag : ∀ i x y, x ∈ B i → y ∈ B i → + c*shortestPathDistance G ℓ x y ≤ ‖Ψ x-Ψ y‖) + (hanchor : ∀ x y, ∃ i, a*bagDistance G ℓ (B i) (hne i) x ≤ ‖Φ x-Φ y‖ ∧ + a*bagDistance G ℓ (B i) (hne i) y ≤ ‖Φ x-Φ y‖) (x y : V) : + c*shortestPathDistance G ℓ x y ≤ + ‖Ψ x-Ψ y‖ + (2*(U+c)/a)*‖Φ x-Φ y‖ := by + obtain ⟨i,hix,hiy⟩ := hanchor x y + obtain ⟨p,hp,hpx⟩ := bagDistance_attained G ℓ (B i) (hne i) x + obtain ⟨q,hq,hqy⟩ := bagDistance_attained G ℓ (B i) (hne i) y + have hd := shortestPathDistance_triangle G ℓ hG (fun e => (hℓ e).le) x p y + have hd' := shortestPathDistance_triangle G ℓ hG (fun e => (hℓ e).le) p q y + have hs := shortestPathDistance_comm G ℓ hG (fun e => (hℓ e).le) q y + have hΨ := norm_sub_le_norm_sub_add_norm_sub (Ψ p) (Ψ x) (Ψ q) + have hΨ' := norm_sub_le_norm_sub_add_norm_sub (Ψ x) (Ψ y) (Ψ q) + have hxp := hupper x p + have hyq := hupper y q + rw [norm_sub_rev (Ψ p) (Ψ x)] at hΨ + have hco := hcobag i p q hp hq + rw [← hpx] at hd hxp + rw [hs,← hqy] at hd' + rw [← hqy] at hyq + have hda : a*(bagDistance G ℓ (B i) (hne i) x+bagDistance G ℓ (B i) (hne i) y) ≤ + 2*‖Φ x-Φ y‖ := by linarith + have hmain : c*shortestPathDistance G ℓ x y ≤ ‖Ψ x-Ψ y‖+ + (U+c)*(bagDistance G ℓ (B i) (hne i) x+bagDistance G ℓ (B i) (hne i) y) := by + nlinarith + have hsum : (U+c)*(bagDistance G ℓ (B i) (hne i) x+bagDistance G ℓ (B i) (hne i) y) ≤ + (2*(U+c)/a)*‖Φ x-Φ y‖ := by + apply (mul_le_mul_iff_right₀ ha).mp + have hh := mul_le_mul_of_nonneg_left hda (by linarith : 0 ≤ U+c) + calc + a*((U+c)*(bagDistance G ℓ (B i) (hne i) x+bagDistance G ℓ (B i) (hne i) y)) = + (U+c)*(a*(bagDistance G ℓ (B i) (hne i) x+bagDistance G ℓ (B i) (hne i) y)) := by ring + _ ≤ (U+c)*(2*‖Φ x-Φ y‖) := hh + _ = a*((2*(U+c)/a)*‖Φ x-Φ y‖) := by field_simp + exact hmain.trans (add_le_add le_rfl hsum) + +end +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +noncomputable section + +theorem main_theorem : MainStatement := by + classical + intro k hk + obtain ⟨Ua,ca,hUa,hca,hanchor⟩ := AnchorExperiment.anchor_common_bag_embedding k hk + obtain ⟨Ub,cb,hUb,hcb,hcobag⟩ := cobag_embedding k hk + let lam : ℝ := 2*(Ub+cb)/ca + have hlam : 0 < lam := by dsimp [lam]; positivity + let C : ℝ := max 1 ((lam*Ua+Ub)/cb) + refine ⟨C,le_max_left _ _,?_⟩ + intro V _ _ _ G hG hdec ℓ hℓ + rcases subsingleton_or_nontrivial V with hsub | hnontriv + · let := hsub + refine ⟨0,fun _ => 0,?_⟩ + intro x y + have hxy : x = y := Subsingleton.elim _ _ + subst y + simp [shortestPathDistance_self G ℓ hG (fun e => (hℓ e).le)] + · let := hnontriv + obtain ⟨n,T,B,hT,hcover,hedge,hrun,hbag,hne⟩ := nonempty_tree_decomposition G hG k hdec + cases n with + | zero => + obtain ⟨i,_⟩ := hcover (Classical.choice (inferInstance : Nonempty V)) + exact Fin.elim0 i + | succ n => + let root : Fin (n+1) := ⟨0,Nat.succ_pos n⟩ + obtain ⟨ma,Φ,hΦu,hΦa⟩ := hanchor V G hG ℓ hℓ n T hT root B hne hcover hedge hrun hbag + obtain ⟨mb,Ψ,hΨu,hΨb⟩ := hcobag V G hG ℓ hℓ (n+1) T hT root B hcover hedge hrun hbag + let F : V → PiLp (1 : ENNReal) (fun _ : Fin (ma+mb) => ℝ) := + fun x => cb⁻¹ • l1Append (lam • Φ x) (Ψ x) + refine ⟨ma+mb,F,?_⟩ + intro x y + have hnorm : ‖F x-F y‖ = cb⁻¹*(lam*‖Φ x-Φ y‖+‖Ψ x-Ψ y‖) := by + dsimp only [F] + rw [← smul_sub,norm_smul,Real.norm_eq_abs,abs_of_pos (inv_pos.mpr hcb), + l1Append_norm_sub,← smul_sub,norm_smul,Real.norm_eq_abs,abs_of_pos hlam] + rw [hnorm] + constructor + · have hh := common_bag_comparison G hG ℓ hℓ B hne Φ Ψ Ub cb ca hUb.le hcb hca + hΨu hΨb hΦa x y + have hh' := mul_le_mul_of_nonneg_left hh (inv_nonneg.mpr hcb.le) + simpa only [← mul_assoc, inv_mul_cancel₀ hcb.ne',one_mul,add_comm] using hh' + · calc + cb⁻¹*(lam*‖Φ x-Φ y‖+‖Ψ x-Ψ y‖) ≤ + cb⁻¹*(lam*(Ua*shortestPathDistance G ℓ x y)+Ub*shortestPathDistance G ℓ x y) := + mul_le_mul_of_nonneg_left (add_le_add + (mul_le_mul_of_nonneg_left (hΦu x y) hlam.le) (hΨu x y)) (inv_nonneg.mpr hcb.le) + _ = ((lam*Ua+Ub)/cb)*shortestPathDistance G ℓ x y := by ring + _ ≤ C*shortestPathDistance G ℓ x y := mul_le_mul_of_nonneg_right (le_max_right _ _) + (shortestPathDistance_nonneg G ℓ hG (fun e => (hℓ e).le) x y) + +end +end BoundedTreewidthL1 + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/MarkovProduct.lean b/lean/OAI/Combinatorics/TreewidthL1/MarkovProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..42b95c5c890d4f4d1a9721c0217e9ad5c5d54ec8 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/MarkovProduct.lean @@ -0,0 +1,263 @@ +import OAI.Combinatorics.TreewidthL1.ReservedTests + +namespace OAI + +universe treewidthLevel1 + +namespace BoundedTreewidthL1.MarkovProduct +attribute [local instance] Classical.decEq +variable (L : ℕ → Type*) [∀ i, Fintype (L i)] +abbrev History (n : ℕ) := (i : Fin (n+1)) → L i.val +noncomputable def weight (p : L 0 → ℝ) (K : (i : ℕ) → L i → L (i+1) → ℝ) + (n : ℕ) (x : History L n) : ℝ := + p (x 0) * ∏ i : Fin n, K i.val (x i.castSucc) (x i.succ) +noncomputable def forward (p : L 0 → ℝ) (K : (i : ℕ) → L i → L (i+1) → ℝ) : + (n : ℕ) → L n → ℝ + | 0 => p + | n+1 => fun b => ∑ a, forward p K n a * K n a b + +end BoundedTreewidthL1.MarkovProduct + +namespace BoundedTreewidthL1.MarkovProduct +attribute [local instance] Classical.decEq +variable (L : ℕ → Type*) [∀ i, Fintype (L i)] + +lemma weight_snoc + (L : ℕ → Type treewidthLevel1) [(i : ℕ) → Fintype (L i)] + (p : L 0 → ℝ) (K : (i : ℕ) → L i → L (i+1) → ℝ) + (n : ℕ) (x : History L n) (b : L (n+1)) : + weight L p K (n+1) (Fin.snoc x b) = weight L p K n x * K n (x (Fin.last n)) b := by + classical + unfold weight + rw [Fin.prod_univ_castSucc] + simp only [Fin.succ_last, Fin.snoc_last, ← Fin.castSucc_succ, + Fin.snoc_castSucc, Fin.val_castSucc, Fin.val_last] + change p (@Fin.snoc (n+1) (fun i : Fin (n+2) => L i.val) x b ((0 : Fin (n+1)).castSucc)) * _ = _ + rw [Fin.snoc_castSucc] + ring + +lemma sum_history_snoc (n : ℕ) (f : History L (n+1) → ℝ) : + (∑ x, f x) = ∑ b : L (n+1), ∑ x : History L n, f (Fin.snoc x b) := by + classical + rw [← (Fin.snocEquiv (fun i : Fin (n+2) => L i.val)).sum_comp f, + Fintype.sum_prod_type] + rfl + +lemma terminal_marginal (p : L 0 → ℝ) (K : (i : ℕ) → L i → L (i+1) → ℝ) + (n : ℕ) (b : L n) : + (∑ x : History L n, if x (Fin.last n) = b then weight L p K n x else 0) = + forward L p K n b := by + classical + induction n with + | zero => + let he : L 0 ≃ History L 0 := (Equiv.piUnique (fun i : Fin 1 => L i.val)).symm + rw [← he.sum_comp] + simp [he, weight, forward, Equiv.piUnique, uniqueElim] + | succ n ih => + rw [sum_history_snoc] + simp only [Fin.snoc_last, weight_snoc] + have h : (∑ c : L (n+1), ∑ x : History L n, + if c = b then weight L p K n x * K n (x (Fin.last n)) c else 0) = + ∑ x : History L n, weight L p K n x * K n (x (Fin.last n)) b := by simp + rw [h] + unfold forward + conv_rhs => + simp only [← ih, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + simp only [ite_mul, zero_mul] + simp + +lemma forward_total (p : L 0 → ℝ) (K : (i : ℕ) → L i → L (i+1) → ℝ) + (hK₁ : ∀ i a, (∑ b, K i a b) = 1) (n : ℕ) : + (∑ a, forward L p K n a) = ∑ a, p a := by + induction n with + | zero => rfl + | succ n ih => + simp only [forward] + rw [Finset.sum_comm] + simp only [← Finset.mul_sum, hK₁, mul_one] + exact ih + +/-- Normalization and the exact terminal marginal of the product measure. -/ +theorem product_law (p : L 0 → ℝ) (K : (i : ℕ) → L i → L (i+1) → ℝ) + (hp : ∀ a, 0 ≤ p a) (hp₁ : (∑ a, p a) = 1) + (hK : ∀ i a b, 0 ≤ K i a b) (hK₁ : ∀ i a, (∑ b, K i a b) = 1) (n : ℕ) : + (∀ x, 0 ≤ weight L p K n x) ∧ (∑ x, weight L p K n x) = 1 ∧ + ∀ b : L n, (∑ x : History L n, if x (Fin.last n) = b then weight L p K n x else 0) = + forward L p K n b := by + classical + refine ⟨fun x => mul_nonneg (hp _) (Finset.prod_nonneg fun _ _ => hK _ _ _), ?_, + terminal_marginal L p K n⟩ + have ht := forward_total L p K hK₁ n + simp_rw [← terminal_marginal L p K n] at ht + rw [Finset.sum_comm] at ht + simpa [hp₁] using ht + +/-- The product has its prescribed final adjacent-pair marginal, including +zero-probability states and transitions. -/ +theorem last_pair (p : L 0 → ℝ) (K : (i : ℕ) → L i → L (i+1) → ℝ) + (n : ℕ) (a : L n) (b : L (n+1)) : + (∑ x : History L (n+1), + if x (Fin.last n).castSucc = a ∧ x (Fin.last (n+1)) = b + then weight L p K (n+1) x else 0) = forward L p K n a * K n a b := by + classical + rw [sum_history_snoc] + simp only [Fin.snoc_castSucc, Fin.snoc_last, weight_snoc] + rw [Finset.sum_comm] + have hc (x : History L n) : + (∑ c : L (n+1), if x (Fin.last n) = a ∧ c = b + then weight L p K n x * K n (x (Fin.last n)) c else 0) = + (if x (Fin.last n) = a then weight L p K n x else 0) * K n a b := by + by_cases h : x (Fin.last n) = a <;> simp [h] + simp only [hc, ← Finset.sum_mul, terminal_marginal] + +end BoundedTreewidthL1.MarkovProduct + +namespace BoundedTreewidthL1.MarkovProduct +attribute [local instance] Classical.decEq +variable (L : ℕ → Type*) [∀ i, Fintype (L i)] + +/-- Transition obtained from a prescribed adjacent-pair marginal. A zero-mass +row is filled with the next marginal; the row is never visited. -/ +noncomputable def couplingKernel (μ : (i : ℕ) → L i → ℝ) + (J : (i : ℕ) → L i → L (i+1) → ℝ) + (i : ℕ) (a : L i) (b : L (i+1)) : ℝ := + if μ i a = 0 then μ (i+1) b else J i a b / μ i a + +noncomputable def historyPrefix (m n : ℕ) (h : m ≤ n) (x : History L n) : History L m := + fun i => x (i.castLE (Nat.succ_le_succ h)) + +end BoundedTreewidthL1.MarkovProduct + +namespace BoundedTreewidthL1.MarkovProduct +attribute [local instance] Classical.decEq +variable (L : ℕ → Type*) [∀ i, Fintype (L i)] + +lemma joint_zero_row (μ : (i : ℕ) → L i → ℝ) + (J : (i : ℕ) → L i → L (i+1) → ℝ) + (hJ : ∀ i a b, 0 ≤ J i a b) + (hrow : ∀ i a, (∑ b, J i a b) = μ i a) + (i : ℕ) (a : L i) (ha : μ i a = 0) (b : L (i+1)) : J i a b = 0 := by + have hle : J i a b ≤ ∑ c, J i a c := + Finset.single_le_sum (fun c _ => hJ i a c) (Finset.mem_univ b) + rw [hrow, ha] at hle + exact le_antisymm hle (hJ i a b) + +lemma couplingKernel_stochastic (μ : (i : ℕ) → L i → ℝ) + (J : (i : ℕ) → L i → L (i+1) → ℝ) + (hμ : ∀ i a, 0 ≤ μ i a) (hμ₁ : ∀ i, (∑ a, μ i a) = 1) + (hJ : ∀ i a b, 0 ≤ J i a b) + (hrow : ∀ i a, (∑ b, J i a b) = μ i a) : + (∀ i a b, 0 ≤ couplingKernel L μ J i a b) ∧ + ∀ i a, (∑ b, couplingKernel L μ J i a b) = 1 := by + constructor + · intro i a b + unfold couplingKernel + split + · exact hμ _ _ + · exact div_nonneg (hJ _ _ _) (hμ _ _) + · intro i a + by_cases ha : μ i a = 0 + · simp [couplingKernel, ha, hμ₁] + · simp [couplingKernel, ha, ← Finset.sum_div, hrow] + +lemma couplingKernel_balance (μ : (i : ℕ) → L i → ℝ) + (J : (i : ℕ) → L i → L (i+1) → ℝ) + (hJ : ∀ i a b, 0 ≤ J i a b) + (hrow : ∀ i a, (∑ b, J i a b) = μ i a) + (i : ℕ) (a : L i) (b : L (i+1)) : + μ i a * couplingKernel L μ J i a b = J i a b := by + by_cases ha : μ i a = 0 + · simp [couplingKernel, ha, joint_zero_row L μ J hJ hrow i a ha b] + · simp [couplingKernel, ha, field] + +lemma coupling_forward (μ : (i : ℕ) → L i → ℝ) + (J : (i : ℕ) → L i → L (i+1) → ℝ) + (hJ : ∀ i a b, 0 ≤ J i a b) + (hrow : ∀ i a, (∑ b, J i a b) = μ i a) + (hcol : ∀ i b, (∑ a, J i a b) = μ (i+1) b) : + ∀ n a, forward L (μ 0) (couplingKernel L μ J) n a = μ n a := by + intro n + induction n with + | zero => intro a; rfl + | succ n ih => + intro b + simp only [forward, ih, couplingKernel_balance L μ J hJ hrow] + exact hcol n b + +lemma prefix_snoc + (L : ℕ → Type treewidthLevel1) [(i : ℕ) → Fintype (L i)] + {m n : ℕ} (h : m ≤ n) (x : History L n) (b : L (n+1)) : + historyPrefix L m (n+1) (h.trans (Nat.le_succ n)) (Fin.snoc x b) = historyPrefix L m n h x := by + funext i + change (@Fin.snoc (n+1) (fun j : Fin (n+2) => L j.val) x b) + (Fin.castSucc (i.castLE (Nat.succ_le_succ h))) = _ + rw [Fin.snoc_castSucc] + rfl + +/-- Integrating out a stochastic suffix preserves the complete historyPrefix law, +not only one-coordinate marginals. -/ +lemma prefix_expectation (p : L 0 → ℝ) (K : (i : ℕ) → L i → L (i+1) → ℝ) + (hK₁ : ∀ i a, (∑ b, K i a b) = 1) + (m n : ℕ) (hmn : m ≤ n) (f : History L m → ℝ) : + (∑ x : History L n, weight L p K n x * f (historyPrefix L m n hmn x)) = + ∑ x : History L m, weight L p K m x * f x := by + induction n, hmn using Nat.le_induction with + | base => rfl + | succ n h ih => + rw [sum_history_snoc] + simp only [weight_snoc, prefix_snoc L h] + rw [Finset.sum_comm] + have hs (x : History L n) : + (∑ b : L (n+1), weight L p K n x * K n (x (Fin.last n)) b * + f (historyPrefix L m n h x)) = weight L p K n x * f (historyPrefix L m n h x) := by + simp_rw [mul_assoc, mul_comm (K n (x (Fin.last n)) _), ← mul_assoc] + rw [← Finset.mul_sum, hK₁, mul_one] + simp only [hs] + exact ih + +end BoundedTreewidthL1.MarkovProduct + +namespace BoundedTreewidthL1.MarkovProduct +attribute [local instance] Classical.decEq +variable (L : ℕ → Type*) [∀ i, Fintype (L i)] + +theorem coupling_chain (μ : (i : ℕ) → L i → ℝ) + (J : (i : ℕ) → L i → L (i+1) → ℝ) + (hμ : ∀ i a, 0 ≤ μ i a) (hμ₁ : ∀ i, (∑ a, μ i a) = 1) + (hJ : ∀ i a b, 0 ≤ J i a b) + (hrow : ∀ i a, (∑ b, J i a b) = μ i a) + (hcol : ∀ i b, (∑ a, J i a b) = μ (i+1) b) (n : ℕ) : + (∀ x, 0 ≤ weight L (μ 0) (couplingKernel L μ J) n x) ∧ + (∑ x, weight L (μ 0) (couplingKernel L μ J) n x) = 1 ∧ + ∀ i : Fin n, ∀ a : L i.val, ∀ b : L (i.val+1), + (∑ x : History L n, + if x i.castSucc = a ∧ x i.succ = b + then weight L (μ 0) (couplingKernel L μ J) n x else 0) = J i.val a b := by + have hK := couplingKernel_stochastic L μ J hμ hμ₁ hJ hrow + have hlaw := product_law L (μ 0) (couplingKernel L μ J) (hμ 0) (hμ₁ 0) hK.1 hK.2 n + refine ⟨hlaw.1, hlaw.2.1, ?_⟩ + intro i a b + let f : History L (i.val+1) → ℝ := fun x => + if x (Fin.last i.val).castSucc = a ∧ x (Fin.last (i.val+1)) = b then 1 else 0 + have he := prefix_expectation L (μ 0) (couplingKernel L μ J) hK.2 + (i.val+1) n i.isLt f + have he' : + (∑ x : History L n, if x i.castSucc = a ∧ x i.succ = b + then weight L (μ 0) (couplingKernel L μ J) n x else 0) = + ∑ x : History L (i.val+1), + if x (Fin.last i.val).castSucc = a ∧ x (Fin.last (i.val+1)) = b + then weight L (μ 0) (couplingKernel L μ J) (i.val+1) x else 0 := by + change (∑ x : History L n, weight L (μ 0) (couplingKernel L μ J) n x * + (if x i.castSucc = a ∧ x i.succ = b then 1 else 0)) = + (∑ x : History L (i.val+1), weight L (μ 0) (couplingKernel L μ J) (i.val+1) x * + (if x (Fin.last i.val).castSucc = a ∧ x (Fin.last (i.val+1)) = b then 1 else 0)) at he + simpa only [mul_ite, mul_one, mul_zero] using he + rw [he', last_pair, coupling_forward L μ J hJ hrow hcol] + exact couplingKernel_balance L μ J hJ hrow i.val a b + +end BoundedTreewidthL1.MarkovProduct + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/Model.lean b/lean/OAI/Combinatorics/TreewidthL1/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8c4fb178c3be84a84c3895ba3d3c59df52f059c --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/Model.lean @@ -0,0 +1,43 @@ +import Mathlib + +namespace OAI + +namespace BoundedTreewidthL1 + +universe u_1 + +variable {V : Type u_1} (G : SimpleGraph V) + +/-- Sum of the given positive real edge lengths along a graph walk. -/ +def walkLength (ℓ : G.edgeSet → ℝ) : {u v : V} → G.Walk u v → ℝ + | _, _, .nil => 0 + | u, _, .cons (v := v) h p => ℓ ⟨s(u, v), h⟩ + walkLength ℓ p + +noncomputable def shortestPathDistance (ℓ : G.edgeSet → ℝ) (u v : V) : ℝ := + sInf {r : ℝ | ∃ p : G.Walk u v, p.IsPath ∧ walkLength G ℓ p = r} + +def HasTreeDecomposition [DecidableEq V] (k : ℕ) : Prop := + ∃ n : ℕ, ∃ T : SimpleGraph (Fin n), ∃ bag : Fin n → Finset V, + T.IsTree ∧ + (∀ v : V, ∃ t, v ∈ bag t) ∧ + (∀ u v : V, G.Adj u v → ∃ t, u ∈ bag t ∧ v ∈ bag t) ∧ + (∀ v : V, (T.induce {t | v ∈ bag t}).Connected) ∧ + (∀ t, (bag t).card ≤ k) + +/-- A map to genuine finite-dimensional real ℓ₁, not just a cut pseudometric. -/ +def HasL1Embedding (ℓ : G.edgeSet → ℝ) (C : ℝ) : Prop := + ∃ m : ℕ, ∃ F : V → PiLp (1 : ENNReal) (fun _ : Fin m => ℝ), + ∀ u v : V, + shortestPathDistance G ℓ u v ≤ ‖F u - F v‖ ∧ + ‖F u - F v‖ ≤ C * shortestPathDistance G ℓ u v + +def MainStatement : Prop := + ∀ k : ℕ, 2 ≤ k → ∃ C : ℝ, 1 ≤ C ∧ + ∀ (V : Type) [Fintype V] [DecidableEq V] [Nonempty V] + (G : SimpleGraph V), + G.Connected → HasTreeDecomposition G k → + ∀ ℓ : G.edgeSet → ℝ, (∀ e, 0 < ℓ e) → HasL1Embedding G ℓ C + +end BoundedTreewidthL1 + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/NoiseCube.lean b/lean/OAI/Combinatorics/TreewidthL1/NoiseCube.lean new file mode 100644 index 0000000000000000000000000000000000000000..75295b29ccc1c80b4a79b487db71021aab7f76ef --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/NoiseCube.lean @@ -0,0 +1,317 @@ +import OAI.Combinatorics.TreewidthL1.TreeGeometry + +namespace OAI + +namespace BoundedTreewidthL1.NoiseCube +open MeasureTheory Set +open scoped unitInterval ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +theorem affine_interval_bound (A b t : ℝ) (hb : b ≠ 0) : + volume {x : ℝ | |A + b*x| < t} = ENNReal.ofReal (2*t/|b|) := by + have hset : {x : ℝ | |A + b*x| < t} = + (fun x : ℝ => b*x) ⁻¹' Ioo (-t-A) (t-A) := by + ext x + simp only [mem_ofPred_eq, mem_preimage, mem_Ioo, abs_lt] + constructor <;> rintro ⟨h₁,h₂⟩ <;> constructor <;> linarith + rw [hset, Real.volume_preimage_mul_left hb, Real.volume_Ioo, + ← ENNReal.ofReal_mul (abs_nonneg _)] + congr 1 + rw [abs_inv] + ring + +lemma unit_affine_bound (A b t β : ℝ) (ht : 0 ≤ t) (hβ : 0 < β) (hb : β ≤ |b|) : + volume {u : I | |A+b*(u:ℝ)| < t} ≤ ENNReal.ofReal (2*t/β) := by + have hbn : b ≠ 0 := by intro he; simp [he] at hb; linarith + have hm : MeasurableSet {u : ℝ | |A+b*u| < t} := measurableSet_lt (by fun_prop) measurable_const + have he := unitInterval.measurePreserving_coe.measure_preimage hm.nullMeasurableSet + change volume (Subtype.val ⁻¹' {u : ℝ | |A+b*u| < t}) ≤ _ + rw [he] + apply (Measure.restrict_le_self _).trans + rw [affine_interval_bound A b t hbn] + exact ENNReal.ofReal_le_ofReal (div_le_div_of_nonneg_left (by positivity) hβ hb) + +lemma cube_strip {m : ℕ} (j : Fin (m+1)) (c : Fin (m+1) → ℝ) + (A t γ : ℝ) (ht : 0 ≤ t) (hγ : 0 < γ) (hc : γ ≤ |c j|) : + volume {U : Fin (m+1) → I | |A+∑ i, (U i:ℝ)*c i| < t} ≤ ENNReal.ofReal (2*t/γ) := by + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (m+1) => I) j + let E : Set (I × (Fin m → I)) := {z | |A+(z.1:ℝ)*c j+∑ i, (z.2 i:ℝ)*c (j.succAbove i)| < t} + have he : {U : Fin (m+1) → I | |A+∑ i, (U i:ℝ)*c i| < t} = e ⁻¹' E := by + ext U + simp only [E,mem_ofPred_eq,mem_preimage] + have hh := Fin.sum_univ_succAbove (fun i => (U i:ℝ)*c i) j + change (|A+∑ i, (U i:ℝ)*c i| < t) ↔ + (|A+(U j:ℝ)*c j+∑ i, (U (j.succAbove i):ℝ)*c (j.succAbove i)| < t) + rw [hh, add_assoc] + rw [he,(volume_preserving_piFinSuccAbove (fun _ : Fin (m+1) => I) j).measure_preimage_equiv E] + change (volume.prod volume) E ≤ _ + rw [Measure.prod_apply_symm (measurableSet_lt (by fun_prop) measurable_const)] + calc + _ ≤ ∫⁻ U : Fin m → I, ENNReal.ofReal (2*t/γ) := by + apply lintegral_mono + intro U + have hs : (fun u : I => (u,U)) ⁻¹' E = + {u : I | |(A+∑ i, (U i:ℝ)*c (j.succAbove i)) + c j*(u:ℝ)| < t} := by + ext u + simp only [E, mem_preimage, mem_ofPred_eq] + ring_nf + dsimp only + rw [hs] + exact unit_affine_bound (A+∑ i, (U i:ℝ)*c (j.succAbove i)) (c j) t γ ht hγ hc + _ = _ := by simp + +lemma cube_strip_any {m : ℕ} (j : Fin m) (c : Fin m → ℝ) + (A t γ : ℝ) (ht : 0 ≤ t) (hγ : 0 < γ) (hc : γ ≤ |c j|) : + volume {U : Fin m → I | |A+∑ i, (U i:ℝ)*c i| < t} ≤ ENNReal.ofReal (2*t/γ) := by + cases m with + | zero => exact j.elim0 + | succ m => exact cube_strip j c A t γ ht hγ hc + +lemma product_strip_first {m : ℕ} (A b t β : ℝ) (c : Fin m → ℝ) + (ht : 0 ≤ t) (hβ : 0 < β) (hb : β ≤ |b|) : + (volume.prod volume) {z : I × (Fin m → I) | + |A+b*(1+(z.1:ℝ))+∑ i, (z.2 i:ℝ)*c i| < t} ≤ ENNReal.ofReal (2*t/β) := by + rw [Measure.prod_apply_symm (measurableSet_lt (by fun_prop) measurable_const)] + calc + _ ≤ ∫⁻ U : Fin m → I, ENNReal.ofReal (2*t/β) := by + apply lintegral_mono + intro U + have hs : (fun u : I => (u,U)) ⁻¹' + {z : I × (Fin m → I) | |A+b*(1+(z.1:ℝ))+∑ i, (z.2 i:ℝ)*c i| < t} = + {u : I | |(A+b+∑ i, (U i:ℝ)*c i) + b*(u:ℝ)| < t} := by + ext u + simp only [mem_preimage, mem_ofPred_eq] + ring_nf + dsimp only + rw [hs] + exact unit_affine_bound (A+b+∑ i, (U i:ℝ)*c i) b t β ht hβ hb + _ = _ := by simp + +lemma product_strip_second {m : ℕ} (j : Fin m) (A b t γ : ℝ) (c : Fin m → ℝ) + (ht : 0 ≤ t) (hγ : 0 < γ) (hc : γ ≤ |c j|) : + (volume.prod volume) {z : I × (Fin m → I) | + |A+b*(1+(z.1:ℝ))+∑ i, (z.2 i:ℝ)*c i| < t} ≤ ENNReal.ofReal (2*t/γ) := by + rw [Measure.prod_apply (measurableSet_lt (by fun_prop) measurable_const)] + calc + _ ≤ ∫⁻ u : I, ENNReal.ofReal (2*t/γ) := by + apply lintegral_mono + intro u + exact cube_strip_any j c (A+b*(1+(u:ℝ))) t γ ht hγ hc + _ = _ := by simp +theorem simultaneous_gap {S : Type*} [Fintype S] + (m : ℕ) (A b : S → ℝ) (c : S → Fin m → ℝ) (t β γ : ℝ) (ht : 0 ≤ t) + (hβ : 0 < β) (hγ : 0 < γ) + (hamp : ∀ s, β ≤ |b s| ∨ ∃ j, γ ≤ |c s j|) + (hbudget : (Fintype.card S : ℝ) * (2*t/β + 2*t/γ) ≤ 1/2) : + ENNReal.ofReal (1/2 : ℝ) ≤ + (volume.prod volume) {z : I × (Fin m → I) | ∀ s, t ≤ |A s + b s * (1+(z.1:ℝ)) + ∑ i, (z.2 i:ℝ)*c s i|} := by + classical + let E : Set (I × (Fin m → I)) := ⋃ s, {z : I × (Fin m → I) | |A s + b s*(1+(z.1:ℝ))+∑ i, (z.2 i:ℝ)*c s i| < t} + have hE : MeasurableSet E := MeasurableSet.iUnion fun s => measurableSet_lt (by fun_prop) measurable_const + have hnonneg : 0 ≤ 2*t/β + 2*t/γ := by positivity + have hmass : (volume.prod volume) E ≤ ENNReal.ofReal (1/2 : ℝ) := by + calc + _ ≤ ∑ s, (volume.prod volume) ({z : I × (Fin m → I) | |A s + b s*(1+(z.1:ℝ))+∑ i, (z.2 i:ℝ)*c s i| < t}) := measure_iUnion_fintype_le _ _ + _ ≤ ∑ _s : S, ENNReal.ofReal (2*t/β + 2*t/γ) := by + apply Finset.sum_le_sum + intro s _ + rcases hamp s with h | h + · exact (product_strip_first _ _ _ _ _ ht hβ h).trans + (ENNReal.ofReal_le_ofReal (le_add_of_nonneg_right (by positivity))) + · obtain ⟨j,hj⟩ := h + exact (product_strip_second j _ _ _ _ _ ht hγ hj).trans + (ENNReal.ofReal_le_ofReal (le_add_of_nonneg_left (by positivity))) + _ = ENNReal.ofReal ((Fintype.card S : ℝ)*(2*t/β + 2*t/γ)) := by + simp [ENNReal.ofReal_mul] + _ ≤ _ := ENNReal.ofReal_le_ofReal hbudget + have hfin : (volume.prod volume) E ≠ ⊤ := ne_top_of_le_ne_top ENNReal.ofReal_ne_top hmass + have hgood : {z : I × (Fin m → I) | ∀ s, t ≤ |A s + b s * (1+(z.1:ℝ)) + ∑ i, (z.2 i:ℝ)*c s i|} = Eᶜ := by + ext z + simp [E] + rw [hgood, measure_compl hE hfin] + simp only [measure_univ] + apply ENNReal.le_sub_of_add_le_right hfin + calc + _ ≤ ENNReal.ofReal (1/2 : ℝ) + ENNReal.ofReal (1/2 : ℝ) := add_le_add_right hmass _ + _ = 1 := by rw [← ENNReal.ofReal_add (by norm_num) (by norm_num)]; norm_num + +end BoundedTreewidthL1.NoiseCube + +namespace BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I : Type*} (T : SimpleGraph I) (hT : T.IsTree) (root X Y : I) +lemma join_prefix_data (s : ℕ) + (_ : s ≤ (forest T hT root).depth X) (hsy : s ≤ (forest T hT root).depth Y) + (hs : (downPath T hT root X).getVert s = (downPath T hT root Y).getVert s) + (hmax : ∀ a b, a ≤ (forest T hT root).depth X → b ≤ (forest T hT root).depth Y → + (downPath T hT root X).getVert a = (downPath T hT root Y).getVert b → a = b ∧ a ≤ s) + (e : ℕ) (hse : s ≤ e) (hex : e ≤ (forest T hT root).depth X) : + let v := (downPath T hT root X).getVert + let l := (forest T hT root).depth Y-s + (forest T hT Y).depth (v e) = l+(e-s) ∧ + ∀ b, s ≤ b → b ≤ e → (downPath T hT Y (v e)).getVert (l+(b-s)) = v b := by + dsimp only + have hedepth := depth_getVert T hT root X e hex + have hpref (b : ℕ) (hb : b ≤ e) : + (downPath T hT root ((downPath T hT root X).getVert e)).getVert b = + (downPath T hT root X).getVert b := by + rw [downPath_take,SimpleGraph.Walk.take_getVert,inf_eq_right.mpr hb] + have hse' : s ≤ (forest T hT root).depth ((downPath T hT root X).getVert e) := by omega + have hs' : (downPath T hT root ((downPath T hT root X).getVert e)).getVert s = + (downPath T hT root Y).getVert s := (hpref s hse).trans hs + have hm : ∀ a b, a ≤ (forest T hT root).depth ((downPath T hT root X).getVert e) → + b ≤ (forest T hT root).depth Y → + (downPath T hT root ((downPath T hT root X).getVert e)).getVert a = + (downPath T hT root Y).getVert b → a = b ∧ a ≤ s := by + intro a b ha hb he + rw [hedepth] at ha + rw [hpref a ha] at he + exact hmax a b (ha.trans hex) hb he + constructor + · simpa only [hedepth] using join_length T hT root ((downPath T hT root X).getVert e) Y s hse' hsy hs' hm + · intro b hsb hbe + have hh := join_suffix T hT root ((downPath T hT root X).getVert e) Y s hse' hsy hs' hm (b-s) + rw [Nat.add_sub_of_le hsb,hpref b hbe] at hh + exact hh +end BoundedTreewidthL1.RootedTree + +namespace BoundedTreewidthL1.ExpandedConstruction.TreeData +open _root_.OAI.BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V ι : Type*} [Fintype I] [Fintype V] [Fintype ι] + {T : SimpleGraph I} {M : ℝ} (D : TreeData (V := V) (ι := ι) T M) + +lemma height_segment (hT : T.IsTree) (hM : 0 < M) (hι : 0 < Fintype.card ι) + (Y Z : I) (y z : V) (hy : y ∈ D.B Y) (hz : z ∈ D.B Z) + (v : ℕ → I) (s e l t : ℕ) (hst : s ≤ t) (hte : t < e) + (hlen : (forest T hT Y).depth Z = l+(e-s)) + (hpath : ∀ b, s ≤ b → b ≤ e → (downPath T hT Y Z).getVert (l+(b-s)) = v b) + (hpar : ∀ b, t ≤ b → b < e → D.parent (v (b+1)) = some (v b)) + (r : ι) (hfixed : ∀ b, t ≤ b → b ≤ e → D.F (v b) r = D.F (v t) r) + (hkeep : ∀ b, t ≤ b → b < e → r ∈ D.C (v (b+1)) ∧ r ≠ D.fresh₁ (v b) ∧ r ≠ D.fresh₂ (v b)) + (hF : ∀ x, -M ≤ D.F (v t) r x ∧ D.F (v t) r x ≤ M) + (ε : ℝ) (hlo : ε ≤ D.F (v t) r z+M) (hhi : ε ≤ M-D.F (v t) r z) + (hgap : ∀ x ∈ D.B (v t), ε ≤ |D.F (v t) r z-D.F (v t) r x|) : + ε/2 ≤ D.dist y z := by + have hp (b : ℕ) (hb : l ≤ b) (hbe : b ≤ l+(e-s)) : + (downPath T hT Y Z).getVert b = v (s+(b-l)) := by + have hh := hpath (s+(b-l)) (by omega) (by omega) + simpa only [show l+(s+(b-l)-s) = b by omega] using hh + have htpath := hpath t hst hte.le + apply D.height_test hT hM hι Y Z y z hy hz (l+(t-s)) (by omega) r + · intro b htb hbe + rw [hp b (by omega) (by omega),hp (b+1) (by omega) (by omega)] + simpa only [show s+(b+1-l) = (s+(b-l))+1 by omega] using hpar (s+(b-l)) (by omega) (by omega) + · intro b htb hbe + rw [hp b (by omega) (by omega),htpath] + exact hfixed _ (by omega) (by omega) + · intro b htb hbe + rw [hp b (by omega) (by omega),hp (b+1) (by omega) (by omega)] + simpa only [show s+(b+1-l) = (s+(b-l))+1 by omega] using hkeep (s+(b-l)) (by omega) (by omega) + · simpa only [htpath] using hF + · simpa only [htpath] using hlo + · simpa only [htpath] using hhi + · simpa only [htpath] using hgap + +lemma launch_segment (hT : T.IsTree) (hM : 0 < M) (hι : 0 < Fintype.card ι) + (Y Z : I) (y z : V) (hy : y ∈ D.B Y) (hz : z ∈ D.B Z) + (v : ℕ → I) (s e l t : ℕ) (hst : s ≤ t) (hte : t < e) + (hlen : (forest T hT Y).depth Z = l+(e-s)) + (hpath : ∀ b, s ≤ b → b ≤ e → (downPath T hT Y Z).getVert (l+(b-s)) = v b) + (hpar : ∀ b, t ≤ b → b < e → D.parent (v (b+1)) = some (v b)) + (hij : D.fresh₁ (v t) ≠ D.fresh₂ (v t)) + (hbag : ∀ x ∈ D.B (v t), D.F (v t) (D.fresh₁ (v t)) x = D.F (v t) (D.fresh₂ (v t)) x) + (hfixed : ∀ r ∈ ({D.fresh₁ (v t),D.fresh₂ (v t)} : Finset ι), ∀ b, t ≤ b → b ≤ e → D.F (v b) r = D.F (v t) r) + (hinit : D.fresh₁ (v t) ∈ D.C (v (t+1)) ∧ D.fresh₂ (v t) ∈ D.C (v (t+1))) + (hkeep : ∀ r ∈ ({D.fresh₁ (v t),D.fresh₂ (v t)} : Finset ι), ∀ b, t+1 ≤ b → b < e → + r ∈ D.C (v (b+1)) ∧ r ≠ D.fresh₁ (v b) ∧ r ≠ D.fresh₂ (v b)) + (hF : ∀ r ∈ ({D.fresh₁ (v t),D.fresh₂ (v t)} : Finset ι), ∀ x, -M ≤ D.F (v t) r x ∧ D.F (v t) r x ≤ M) : + |D.F (v t) (D.fresh₁ (v t)) z-D.F (v t) (D.fresh₂ (v t)) z|/2 ≤ D.dist y z := by + have hp (b : ℕ) (hb : l ≤ b) (hbe : b ≤ l+(e-s)) : + (downPath T hT Y Z).getVert b = v (s+(b-l)) := by + have hh := hpath (s+(b-l)) (by omega) (by omega) + simpa only [show l+(s+(b-l)-s) = b by omega] using hh + have htpath := hpath t hst hte.le + rw [← htpath] + apply D.launch_test hT hM hι Y Z y z hy hz (l+(t-s)) (by omega) + · intro b htb hbe + rw [hp b (by omega) (by omega),hp (b+1) (by omega) (by omega)] + simpa only [show s+(b+1-l) = (s+(b-l))+1 by omega] using hpar (s+(b-l)) (by omega) (by omega) + · simpa only [htpath] using hij + · simpa only [htpath] using hbag + · rw [htpath] + intro r hr b htb hbe + rw [hp b (by omega) (by omega)] + exact hfixed r hr _ (by omega) (by omega) + · simpa only [htpath,show l+(t-s)+1 = l+(t+1-s) by omega,hpath (t+1) (by omega) (by omega)] using hinit + · rw [htpath] + intro r hr b htb hbe + rw [hp b (by omega) (by omega),hp (b+1) (by omega) (by omega)] + simpa only [show s+(b+1-l) = (s+(b-l))+1 by omega] using hkeep r hr (s+(b-l)) (by omega) (by omega) + · simpa only [htpath] using hF +end BoundedTreewidthL1.ExpandedConstruction.TreeData + +namespace BoundedTreewidthL1.NoiseCube +open MeasureTheory Set LaunchNoise +open scoped unitInterval ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +lemma flip_triple {A B C : Type*} [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace C] + (μ : Measure A) (ν : Measure B) (κ : Measure C) [SFinite μ] [SFinite ν] [SFinite κ] : + MeasurePreserving (fun z : A × (B × C) => (z.2.1,(z.1,z.2.2))) + (μ.prod (ν.prod κ)) (ν.prod (μ.prod κ)) := by + have h₁ := (measurePreserving_prodAssoc μ ν κ).symm + have h₂ := (Measure.measurePreserving_swap (μ := μ) (ν := ν)).prod (MeasurePreserving.id κ) + have h₃ := measurePreserving_prodAssoc ν μ κ + exact h₃.comp (h₂.comp h₁) + +lemma conditioned_gap {S : Type*} [Fintype S] {n m : ℕ} + (μ : Fin n → ℝ) (_ : ∀ a, 0 ≤ μ a) (_ : ∑ a, μ a = 1) + (A b : S → ℝ) (c : Fin n → S → Fin m → ℝ) (E : Set (Fin n)) + (t β γ ρ : ℝ) (ht : 0 ≤ t) (hβ : 0 < β) (hγ : 0 < γ) (_ : 0 ≤ ρ) + (hgood : ENNReal.ofReal ρ ≤ locationLaw μ E) + (hamp : ∀ a ∈ E, ∀ s, β ≤ |b s| ∨ ∃ j, γ ≤ |c a s j|) + (hbudget : (Fintype.card S : ℝ)*(2*t/β+2*t/γ) ≤ 1/2) : + ENNReal.ofReal (ρ/2) ≤ noiseLaw m μ {ω | ∀ s, + t ≤ |A s+b s*noiseXi ω+∑ j, (ω.2.2 j:ℝ)*c ω.2.1 s j|} := by + let Q : Set (Fin n × (I × (Fin m → I))) := {z | ∀ s, + t ≤ |A s+b s*(1+(z.2.1:ℝ))+∑ j, (z.2.2 j:ℝ)*c z.1 s j|} + have hQ : MeasurableSet Q := by + dsimp only [Q] + simp_rw [ofPred_forall] + apply MeasurableSet.iInter + intro s + apply measurableSet_le measurable_const + apply Measurable.abs + fun_prop + have he : {ω : NoiseSpace n m | ∀ s, + t ≤ |A s+b s*noiseXi ω+∑ j, (ω.2.2 j:ℝ)*c ω.2.1 s j|} = + (fun z : I × (Fin n × (Fin m → I)) => (z.2.1,(z.1,z.2.2))) ⁻¹' Q := rfl + rw [he,noiseLaw,(flip_triple volume (locationLaw μ) volume).measure_preimage hQ.nullMeasurableSet] + rw [Measure.prod_apply hQ] + calc + ENNReal.ofReal (ρ/2) = ENNReal.ofReal (1/2 : ℝ)*ENNReal.ofReal ρ := by + rw [← ENNReal.ofReal_mul (by norm_num)]; congr 1; ring + _ ≤ ENNReal.ofReal (1/2 : ℝ)*locationLaw μ E := mul_le_mul_right hgood _ + _ = ∫⁻ a, E.indicator (fun _ => ENNReal.ofReal (1/2 : ℝ)) a ∂locationLaw μ := + (lintegral_indicator_const MeasurableSet.of_discrete _).symm + _ ≤ _ := by + apply lintegral_mono + intro a + by_cases ha : a ∈ E + · rw [Set.indicator_of_mem ha] + exact simultaneous_gap m A b (c a) t β γ ht hβ hγ (hamp a ha) hbudget + · simp only [Set.indicator_of_notMem ha]; exact bot_le + +lemma pi_conditioned {n : ℕ} {Ω : Fin (n+1) → Type*} + [∀ i, MeasurableSpace (Ω i)] (μ : ∀ i, Measure (Ω i)) [∀ i, IsProbabilityMeasure (μ i)] + (a : Fin (n+1)) (E : Set (∀ i, Ω i)) (hE : MeasurableSet E) (p : ℝ≥0∞) + (hfiber : ∀ rest : ∀ j : Fin n, Ω (a.succAbove j), + p ≤ μ a {u | Fin.insertNth a u rest ∈ E}) : p ≤ Measure.pi μ E := by + let e := MeasurableEquiv.piFinSuccAbove Ω a + have he := (measurePreserving_piFinSuccAbove μ a).symm.measure_preimage_equiv E + rw [← he,Measure.prod_apply_symm (e.symm.measurable hE)] + calc + p = ∫⁻ rest : ∀ j : Fin n, Ω (a.succAbove j), p ∂Measure.pi (fun j => μ (a.succAbove j)) := by simp + _ ≤ _ := lintegral_mono (fun rest => hfiber rest) +end BoundedTreewidthL1.NoiseCube + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/OrderedSweep.lean b/lean/OAI/Combinatorics/TreewidthL1/OrderedSweep.lean new file mode 100644 index 0000000000000000000000000000000000000000..cced59c1cbd18ad6ae9a3fae3120de11e796cb08 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/OrderedSweep.lean @@ -0,0 +1,639 @@ +import OAI.Combinatorics.TreewidthL1.ExpandedParticles + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1.OrderedSweepFlow +open scoped BigOperators + +variable {α β : Type*} [Fintype α] [LinearOrder α] [LinearOrder β] + +noncomputable def fiber (b : α → β) (x : α) : Finset α := by + classical + exact Finset.univ.filter (fun y => b y = b x) + +noncomputable def mass (μ : α → ℝ) (b : α → β) (x : α) : ℝ := + ∑ y ∈ fiber b x, μ y + +noncomputable def bath (μ : α → ℝ) (b : α → β) (f : α → ℝ) (x : α) : ℝ := + (∑ y ∈ fiber b x, μ y * f y) / mass μ b x + +noncomputable def total (μ f : α → ℝ) : ℝ := ∑ x, μ x * f x + +noncomputable def risk (μ f : α → ℝ) (p : α → Bool) : ℝ := + ∑ x, μ x * (if p x then 1 - f x else f x) + +end BoundedTreewidthL1.OrderedSweepFlow + +namespace BoundedTreewidthL1.OrderedSweepFlow +variable {α β : Type*} [Fintype α] [LinearOrder α] [LinearOrder β] + +lemma mem_fiber + {α : Type treewidthLevel1} {β : Type treewidthLevel2} [Fintype α] [LinearOrder α] + [LinearOrder β] + (b : α → β) (x y : α) : y ∈ fiber b x ↔ b y = b x := by + classical + simp [fiber] + +lemma fiber_eq (b : α → β) {x y : α} (h : b x = b y) : fiber b x = fiber b y := by + classical + ext z + simp only [mem_fiber, h] + +lemma mass_pos (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) (b : α → β) (x : α) : + 0 < mass μ b x := by + classical + exact Finset.sum_pos (fun y _ => hμ y) ⟨x, (mem_fiber b x x).mpr rfl⟩ + +lemma bath_const_fiber (μ : α → ℝ) (b : α → β) (f : α → ℝ) {x y : α} + (h : b x = b y) : bath μ b f x = bath μ b f y := by + unfold bath mass + rw [fiber_eq b h] + +lemma bath_le (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) (b : α → β) + (f : α → ℝ) (x : α) (c : ℝ) (hc : ∀ y ∈ fiber b x, f y ≤ c) : + bath μ b f x ≤ c := by + rw [bath, div_le_iff₀ (mass_pos μ hμ b x)] + unfold mass + rw [Finset.mul_sum] + exact Finset.sum_le_sum (fun y hy => by nlinarith [hμ y, hc y hy]) + +lemma le_bath (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) (b : α → β) + (f : α → ℝ) (x : α) (c : ℝ) (hc : ∀ y ∈ fiber b x, c ≤ f y) : + c ≤ bath μ b f x := by + rw [bath, le_div_iff₀ (mass_pos μ hμ b x)] + unfold mass + rw [Finset.mul_sum] + exact Finset.sum_le_sum (fun y hy => by nlinarith [hμ y, hc y hy]) + +lemma fiber_lt (b : α → β) (hb : Monotone b) {x y s t : α} + (hxy : b x < b y) (hs : s ∈ fiber b x) (ht : t ∈ fiber b y) : s < t := by + have hs' := (mem_fiber b x s).mp hs + have ht' := (mem_fiber b y t).mp ht + by_contra h + have := hb (le_of_not_gt h) + rw [hs', ht'] at this + exact (not_le_of_gt hxy) this + +theorem bath_monotone (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (b : α → β) (hb : Monotone b) (f : α → ℝ) (hf : Monotone f) : + Monotone (bath μ b f) := by + intro x y hxy + rcases (hb hxy).eq_or_lt with h | h + · exact le_of_eq (bath_const_fiber μ b f h) + · apply le_bath μ hμ b f y + intro t ht + apply bath_le μ hμ b f x + intro s hs + exact hf (fiber_lt b hb h hs ht).le + +theorem bath_antitone (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (b : α → β) (hb : Monotone b) (f : α → ℝ) (hf : Antitone f) : + Antitone (bath μ b f) := by + intro x y hxy + rcases (hb hxy).eq_or_lt with h | h + · exact le_of_eq (bath_const_fiber μ b f h.symm) + · apply le_bath μ hμ b f x + intro s hs + apply bath_le μ hμ b f y + intro t ht + exact hf (fiber_lt b hb h hs ht).le + +lemma bath_bounds (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) (b : α → β) + (f : α → ℝ) (hf : ∀ x, 0 ≤ f x ∧ f x ≤ 1) (x : α) : + 0 ≤ bath μ b f x ∧ bath μ b f x ≤ 1 := + ⟨le_bath μ hμ b f x 0 (fun y _ => (hf y).1), + bath_le μ hμ b f x 1 (fun y _ => (hf y).2)⟩ + +lemma bath_expand + {α : Type treewidthLevel1} {β : Type treewidthLevel2} [Fintype α] [LinearOrder α] + [LinearOrder β] + (μ : α → ℝ) (b : α → β) (f : α → ℝ) (x : α) : + bath μ b f x = ∑ y, if b y = b x then μ y * f y / mass μ b x else 0 := by + classical + simp [bath, fiber, Finset.sum_filter, Finset.sum_div, ite_div] + +theorem bath_total (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (b : α → β) (f : α → ℝ) : total μ (bath μ b f) = total μ f := by + classical + unfold total + simp_rw [bath_expand, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro y _ + have he (x : α) : + μ x * (if b y = b x then μ y * f y / mass μ b x else 0) = + (if b x = b y then μ x else 0) * (μ y * f y / mass μ b y) := by + by_cases h : b x = b y + · have hm : mass μ b x = mass μ b y := by unfold mass; rw [fiber_eq b h] + simp [h, hm] + · simp [h, Ne.symm h] + simp_rw [he] + rw [← Finset.sum_mul] + have hm : (∑ x, if b x = b y then μ x else 0) = mass μ b y := by + simp [mass, fiber, Finset.sum_filter] + rw [hm] + field_simp [ne_of_gt (mass_pos μ hμ b y)] + +end BoundedTreewidthL1.OrderedSweepFlow + +namespace BoundedTreewidthL1.OrderedSweepFlow +variable {α β : Type*} [Fintype α] [LinearOrder α] [LinearOrder β] + +noncomputable def defect (μ f p : α → ℝ) : ℝ := + ∑ x, μ x * (f x + p x - 2 * f x * p x) + +noncomputable def optimal (μ : α → ℝ) (b : α → β) (f : α → ℝ) : α → Bool := + fun x => decide (1 / 2 < bath μ b f x) + +noncomputable def labelReal (p : α → Bool) : α → ℝ := + fun x => if p x then 1 else 0 + +end BoundedTreewidthL1.OrderedSweepFlow + +namespace BoundedTreewidthL1.OrderedSweepFlow +variable {α β : Type*} [Fintype α] [LinearOrder α] [LinearOrder β] + +lemma defect_eq + {α : Type treewidthLevel1} [Fintype α] [LinearOrder α] + (μ f p : α → ℝ) : + defect μ f p = total μ f + total μ p - 2 * total μ (fun x => f x * p x) := by + classical + simp only [defect, total, Finset.mul_sum, ← Finset.sum_add_distrib, + ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro x _ + ring + +lemma bath_mul (μ : α → ℝ) (b : α → β) (f p : α → ℝ) + (hp : ∀ x y, b x = b y → p x = p y) (x : α) : + bath μ b (fun y => f y * p y) x = bath μ b f x * p x := by + classical + unfold bath + have h : (∑ y ∈ fiber b x, μ y * (f y * p y)) = + (∑ y ∈ fiber b x, μ y * f y) * p x := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro y hy + rw [hp y x ((mem_fiber b x y).mp hy)] + ring + rw [h] + ring + +lemma defect_bath (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) (b : α → β) + (f p : α → ℝ) (hp : ∀ x y, b x = b y → p x = p y) : + defect μ (bath μ b f) p = defect μ f p := by + rw [defect_eq, defect_eq, bath_total μ hμ b f] + congr 1 + congr 1 + have h := bath_total μ hμ b (fun x => f x * p x) + have hh : bath μ b (fun x => f x * p x) = (fun x => bath μ b f x * p x) := + funext (bath_mul μ b f p hp) + rw [hh] at h + exact h + +lemma optimal_fiber (μ : α → ℝ) (b : α → β) (f : α → ℝ) + {x y : α} (h : b x = b y) : optimal μ b f x = optimal μ b f y := by + simp only [optimal, bath_const_fiber μ b f h] + +theorem optimal_monotone (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (b : α → β) (hb : Monotone b) (f : α → ℝ) (hf : Monotone f) : + Monotone (optimal μ b f) := by + intro x y hxy + have h := bath_monotone μ hμ b hb f hf hxy + simp only [optimal] + by_cases hx : 1 / 2 < bath μ b f x + · have hy : 1 / 2 < bath μ b f y := hx.trans_le h + simp only [hx, hy, decide_true, le_refl] + · simp only [hx, decide_false, Bool.false_le] + +theorem optimal_defect_le (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (b : α → β) (f p : α → ℝ) (hp : ∀ x, 0 ≤ p x ∧ p x ≤ 1) + (hpb : ∀ x y, b x = b y → p x = p y) : + defect μ f (labelReal (optimal μ b f)) ≤ defect μ f p := by + classical + have hc : ∀ x y, b x = b y → + labelReal (optimal μ b f) x = labelReal (optimal μ b f) y := by + intro x y h + simp only [labelReal, optimal_fiber μ b f h] + rw [← defect_bath μ hμ b f _ hc, ← defect_bath μ hμ b f p hpb] + apply Finset.sum_le_sum + intro x _ + apply mul_le_mul_of_nonneg_left _ (hμ x).le + dsimp [labelReal, optimal] + split_ifs with h + · have h' : 1 / 2 < bath μ b f x := of_decide_eq_true h + simp only [h, ↓reduceIte] + nlinarith [(hp x).2] + · have h' : ¬1 / 2 < bath μ b f x := by simpa only [decide_eq_true_eq] using h + simp only [h, Bool.false_eq_true, ↓reduceIte] + nlinarith [(hp x).1] + +lemma labelReal_bounds + {α : Type treewidthLevel1} [Fintype α] [LinearOrder α] + (p : α → Bool) (x : α) : + 0 ≤ labelReal p x ∧ labelReal p x ≤ 1 := by + simp only [labelReal] + split <;> norm_num + +lemma defect_mean_bound + {α : Type treewidthLevel1} [Fintype α] [LinearOrder α] + (μ f p : α → ℝ) (hμ : ∀ x, 0 ≤ μ x) + (hf : ∀ x, 0 ≤ f x ∧ f x ≤ 1) (hp : ∀ x, 0 ≤ p x ∧ p x ≤ 1) : + |total μ f - total μ p| ≤ defect μ f p := by + classical + have hl : total μ p - total μ f ≤ defect μ f p := by + unfold total defect + rw [← Finset.sum_sub_distrib] + exact Finset.sum_le_sum (fun x _ => by + nlinarith [mul_nonneg (hμ x) (mul_nonneg (hf x).1 (sub_nonneg.mpr (hp x).2))]) + have hr : total μ f - total μ p ≤ defect μ f p := by + unfold total defect + rw [← Finset.sum_sub_distrib] + exact Finset.sum_le_sum (fun x _ => by + nlinarith [mul_nonneg (hμ x) (mul_nonneg (hp x).1 (sub_nonneg.mpr (hf x).2))]) + exact abs_le.mpr ⟨by linarith, hr⟩ + +lemma pair_mean_bound (μ f g p : α → ℝ) (hμ : ∀ x, 0 ≤ μ x) + (hf : ∀ x, 0 ≤ f x ∧ f x ≤ 1) (hg : ∀ x, 0 ≤ g x ∧ g x ≤ 1) + (hp : ∀ x, 0 ≤ p x ∧ p x ≤ 1) : + |total μ f - total μ g| ≤ defect μ f p + defect μ g p := by + have h := abs_sub_le (total μ f) (total μ p) (total μ g) + rw [abs_sub_comm (total μ p)] at h + exact h.trans (add_le_add (defect_mean_bound μ f p hμ hf hp) + (defect_mean_bound μ g p hμ hg hp)) + +end BoundedTreewidthL1.OrderedSweepFlow + +namespace BoundedTreewidthL1.OrderedSweepFlow +variable {α β : Type*} [Fintype α] [LinearOrder α] [LinearOrder β] + +/-- On a chain of nested cuts, a monotone classifier determined by its trace +on a bag is either constant or evaluation at one of that bag's vertices. -/ +theorem monotone_classifier {P : Type*} (labels : α → P → Bool) + (hl : ∀ p, Monotone (fun x => labels x p)) (c : α → Bool) (hc : Monotone c) + (htrace : ∀ x y, (∀ p, labels x p = labels y p) → c x = c y) : + c = (fun _ => false) ∨ c = (fun _ => true) ∨ ∃ p, c = (fun x => labels x p) := by + classical + by_cases hf : ∀ x, c x = false + · exact Or.inl (funext hf) + by_cases ht : ∀ x, c x = true + · exact Or.inr (Or.inl (funext ht)) + push Not at hf ht + obtain ⟨a, ha⟩ := ht + obtain ⟨b, hb⟩ := hf + have ha' : c a = false := by cases h : c a <;> simp_all + have hb' : c b = true := by cases h : c b <;> simp_all + let lo := Finset.univ.filter (fun x => c x = false) + let hi := Finset.univ.filter (fun x => c x = true) + have hlo : lo.Nonempty := ⟨a, by simp [lo, ha']⟩ + have hhi : hi.Nonempty := ⟨b, by simp [hi, hb']⟩ + let u := lo.max' hlo + let v := hi.min' hhi + have hu : c u = false := by simpa [lo] using lo.max'_mem hlo + have hv : c v = true := by simpa [hi] using hi.min'_mem hhi + have huv : u ≤ v := by + by_contra h + have hh := hc (le_of_lt (lt_of_not_ge h)) + rw [hu, hv] at hh + contradiction + have hn : ¬∀ p, labels u p = labels v p := by + intro h + have := htrace u v h + rw [hu, hv] at this + contradiction + obtain ⟨p, hp⟩ := not_forall.mp hn + have hlp : labels u p ≤ labels v p := hl p huv + have hup : labels u p = false := by + cases h : labels u p <;> cases h' : labels v p <;> simp_all + exact Bool.noConfusion (hlp rfl) + have hvp : labels v p = true := by + cases h : labels u p <;> cases h' : labels v p <;> simp_all + refine Or.inr (Or.inr ⟨p, funext (fun x => ?_)⟩) + cases hx : c x with + | false => + have hxu : x ≤ u := lo.le_max' x (by simp [lo, hx]) + have h : labels x p ≤ labels u p := hl p hxu + rw [hup] at h + cases hx' : labels x p <;> simp_all + exact Bool.noConfusion (h rfl) + | true => + have hvx : v ≤ x := hi.min'_le x (by simp [hi, hx]) + have h : labels v p ≤ labels x p := hl p hvx + rw [hvp] at h + cases hx' : labels x p <;> simp_all + exact Bool.noConfusion (h rfl) + +/-- The height-gap transport estimate for a retained ordered sweep. `f` is the +backward endpoint response; interval heat baths keep it monotone and preserve +its mean. The comparison predictor may be arbitrarily randomized by the past. -/ +theorem height_transport {P : Type*} (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (b : α → β) (hb : Monotone b) (labels : α → P → Bool) + (hl : ∀ p, Monotone (fun x => labels x p)) + (htrace : ∀ x y, (∀ p, labels x p = labels y p) → b x = b y) + (f p : α → ℝ) (hf : Monotone f) (hfb : ∀ x, 0 ≤ f x ∧ f x ≤ 1) + (hp : ∀ x, 0 ≤ p x ∧ p x ≤ 1) + (hpb : ∀ x y, b x = b y → p x = p y) + (t : ℝ) (h0 : t ≤ total μ f) (h1 : t ≤ total μ (fun _ => 1) - total μ f) + (hgap : ∀ v, t ≤ |total μ f - total μ (labelReal (fun x => labels x v))|) : + t ≤ defect μ f p := by + let c := optimal μ b f + have hc := optimal_monotone μ hμ b hb f hf + have hcTrace : ∀ x y, (∀ v, labels x v = labels y v) → c x = c y := by + intro x y h + exact optimal_fiber μ b f (htrace x y h) + have ha := monotone_classifier labels hl c hc hcTrace + have hmin := optimal_defect_le μ hμ b f p hp hpb + have hmean := (defect_mean_bound μ f (labelReal c) (fun x => (hμ x).le) hfb + (labelReal_bounds c)).trans hmin + rcases ha with he | he | ⟨v, he⟩ + · have hm : total μ (labelReal c) = 0 := by simp [he, labelReal, total] + rw [hm, sub_zero] at hmean + have hn : 0 ≤ total μ f := Finset.sum_nonneg (fun x _ => mul_nonneg (hμ x).le (hfb x).1) + rw [abs_of_nonneg hn] at hmean + exact h0.trans hmean + · have hm : total μ (labelReal c) = total μ (fun _ => 1) := by simp [he, labelReal, total] + rw [hm] at hmean + have hn : total μ f ≤ total μ (fun _ => 1) := + Finset.sum_le_sum (fun x _ => mul_le_mul_of_nonneg_left (hfb x).2 (hμ x).le) + rw [abs_of_nonpos (sub_nonpos.mpr hn)] at hmean + exact h1.trans (by linarith) + · rw [he] at hmean + exact (hgap v).trans hmean + +end BoundedTreewidthL1.OrderedSweepFlow + +namespace BoundedTreewidthL1.OrderedSweepFlow +variable {α β : Type*} [Fintype α] [LinearOrder α] [LinearOrder β] + +noncomputable def execute (μ : α → ℝ) (bs : List (α → β)) (f : α → ℝ) : α → ℝ := + bs.foldr (fun b g => bath μ b g) f + +lemma execute_monotone (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (bs : List (α → β)) (hb : ∀ b ∈ bs, Monotone b) + (f : α → ℝ) (hf : Monotone f) : Monotone (execute μ bs f) := by + induction bs with + | nil => exact hf + | cons b bs ih => + exact bath_monotone μ hμ b (hb b (by simp)) _ + (ih (fun c hc => hb c (by simp [hc]))) + +lemma execute_total (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (bs : List (α → β)) (f : α → ℝ) : total μ (execute μ bs f) = total μ f := by + induction bs with + | nil => rfl + | cons b bs ih => + change total μ (bath μ b (execute μ bs f)) = _ + rw [bath_total μ hμ, ih] + +lemma execute_bounds (μ : α → ℝ) (hμ : ∀ x, 0 < μ x) + (bs : List (α → β)) (f : α → ℝ) (hf : ∀ x, 0 ≤ f x ∧ f x ≤ 1) : + ∀ x, 0 ≤ execute μ bs f x ∧ execute μ bs f x ≤ 1 := by + induction bs with + | nil => exact hf + | cons b bs ih => exact bath_bounds μ hμ b _ ih +end BoundedTreewidthL1.OrderedSweepFlow + +namespace BoundedTreewidthL1.OrderedReservation +attribute [local instance] Classical.decEq Classical.propDecidable +open MeasureTheory Set +open scoped BigOperators +variable {V : Type*} [Fintype V] + +noncomputable def trueSet (ω : V → Bool) : Finset V := by + classical + exact Finset.univ.filter (fun v => ω v = true) + +def Carrier (M : ℝ) (F : V → ℝ) := {ω : V → Bool // 0 < (sweep M F).real {ω}} + +noncomputable instance (M : ℝ) (F : V → ℝ) : Fintype (Carrier M F) := by + unfold Carrier + infer_instance + +noncomputable def weight (M : ℝ) (F : V → ℝ) (ω : Carrier M F) : ℝ := + (sweep M F).real {ω.val} + +lemma weight_pos + {V : Type treewidthLevel1} [Fintype V] + (M : ℝ) (F : V → ℝ) (ω : Carrier M F) : 0 < weight M F ω := ω.property + +lemma exists_threshold (M : ℝ) (F : V → ℝ) (ω : Carrier M F) : + ∃ t ∈ Icc (-M) M, thresholdLabels F t = ω.val := by + have hp : 0 < (sweep M F).real {ω.val} := ω.property + change 0 < ((volume.restrict (Icc (-M) M)).map (thresholdLabels F)).real {ω.val} at hp + rw [map_measureReal_apply (measurable_thresholdLabels F) (measurableSet_singleton ω.val), + measureReal_restrict_apply ((measurable_thresholdLabels F) (measurableSet_singleton ω.val))] at hp + have hn : ((thresholdLabels F ⁻¹' {ω.val}) ∩ Icc (-M) M).Nonempty := by + by_contra he + rw [Set.not_nonempty_iff_eq_empty.mp he, measureReal_empty] at hp + exact (lt_irrefl 0) hp + obtain ⟨t, ht, hm⟩ := hn + exact ⟨t, hm, ht⟩ + +lemma thresholds_nested (F : V → ℝ) (s t : ℝ) (hst : s ≤ t) : + trueSet (thresholdLabels F t) ⊆ trueSet (thresholdLabels F s) := by + classical + intro v hv + simp only [trueSet, Finset.mem_filter, Finset.mem_univ, true_and, + thresholdLabels, decide_eq_true_eq] at hv ⊢ + exact hst.trans_lt hv + +lemma carrier_nested (M : ℝ) (F : V → ℝ) (a b : Carrier M F) : + trueSet a.val ⊆ trueSet b.val ∨ trueSet b.val ⊆ trueSet a.val := by + obtain ⟨s, _, hs⟩ := exists_threshold M F a + obtain ⟨t, _, ht⟩ := exists_threshold M F b + rw [← hs, ← ht] + rcases le_total s t with h | h + · exact Or.inr (thresholds_nested F s t h) + · exact Or.inl (thresholds_nested F t s h) + +lemma trueSet_injective : Function.Injective (trueSet (V := V)) := by + classical + intro a b h + funext v + have he : v ∈ trueSet a ↔ v ∈ trueSet b := by rw [h] + simp only [trueSet, Finset.mem_filter, Finset.mem_univ, true_and] at he + cases ha : a v <;> cases hb : b v <;> simp_all + +lemma rank_injective (M : ℝ) (F : V → ℝ) : + Function.Injective (fun a : Carrier M F => (trueSet a.val).card) := by + intro a b h + apply Subtype.ext + apply trueSet_injective + rcases carrier_nested M F a b with hab | hba + · exact Finset.eq_of_subset_of_card_le hab h.ge + · exact (Finset.eq_of_subset_of_card_le hba h.le).symm + +noncomputable instance carrierOrder (M : ℝ) (F : V → ℝ) : LinearOrder (Carrier M F) := + LinearOrder.lift' (fun a => (trueSet a.val).card) (rank_injective M F) + +lemma labels_monotone (M : ℝ) (F : V → ℝ) (v : V) : + Monotone (fun a : Carrier M F => a.val v) := by + intro a b hab + change (trueSet a.val).card ≤ (trueSet b.val).card at hab + have hs : trueSet a.val ⊆ trueSet b.val := by + rcases carrier_nested M F a b with h | h + · exact h + · exact (Finset.eq_of_subset_of_card_le h hab).symm.subset + intro ha + have hm : v ∈ trueSet a.val := by simp [trueSet, ha] + simpa only [trueSet, Finset.mem_filter, Finset.mem_univ, true_and] using hs hm + +noncomputable def traceRank (M : ℝ) (F : V → ℝ) (P : Finset V) (ω : Carrier M F) : ℕ := + (P.filter (fun v => ω.val v = true)).card + +lemma traceRank_monotone (M : ℝ) (F : V → ℝ) (P : Finset V) : + Monotone (traceRank M F P) := by + classical + intro a b hab + apply Finset.card_le_card + intro v hv + simp only [Finset.mem_filter] at hv ⊢ + exact ⟨hv.1, labels_monotone M F v hab hv.2⟩ + +lemma traceRank_fiber (M : ℝ) (F : V → ℝ) (P : Finset V) + (a b : Carrier M F) : traceRank M F P a = traceRank M F P b ↔ + ∀ v : P, a.val v = b.val v := by + classical + constructor + · intro h + have hn : (P.filter (fun v => a.val v = true)) ⊆ (P.filter (fun v => b.val v = true)) ∨ + (P.filter (fun v => b.val v = true)) ⊆ (P.filter (fun v => a.val v = true)) := by + rcases le_total a b with hab | hba + · left; intro v hv; simp only [Finset.mem_filter] at hv ⊢ + exact ⟨hv.1, labels_monotone M F v hab hv.2⟩ + · right; intro v hv; simp only [Finset.mem_filter] at hv ⊢ + exact ⟨hv.1, labels_monotone M F v hba hv.2⟩ + have he : (P.filter (fun v => a.val v = true)) = (P.filter (fun v => b.val v = true)) := by + rcases hn with hab | hba + · exact Finset.eq_of_subset_of_card_le hab h.ge + · exact (Finset.eq_of_subset_of_card_le hba h.le).symm + intro v + have hv : v.val ∈ P.filter (fun v => a.val v = true) ↔ + v.val ∈ P.filter (fun v => b.val v = true) := by rw [he] + simp only [Finset.mem_filter, v.property, true_and] at hv + cases ha : a.val v <;> cases hb : b.val v <;> simp_all + · intro h + unfold traceRank + congr 1 + apply Finset.filter_congr + intro v hv + rw [h ⟨v,hv⟩] + +lemma sum_carrier (M : ℝ) (F : V → ℝ) (g : (V → Bool) → ℝ) : + (∑ a : Carrier M F, weight M F a * g a.val) = + ∑ a : V → Bool, (sweep M F).real {a} * g a := by + classical + have he := Fintype.sum_subtype_add_sum_subtype + (fun a : V → Bool => 0 < (sweep M F).real {a}) + (fun a => (sweep M F).real {a} * g a) + have hz : (∑ a : {a : V → Bool // ¬0 < (sweep M F).real {a}}, + (sweep M F).real {a.val} * g a.val) = 0 := by + apply Finset.sum_eq_zero + intro a _ + have ha : (sweep M F).real {a.val} = 0 := + le_antisymm (le_of_not_gt a.property) measureReal_nonneg + simp [ha] + rw [hz, add_zero] at he + exact he + +lemma sum_event (M : ℝ) (F : V → ℝ) (p : (V → Bool) → Prop) : + (∑ a : V → Bool, (sweep M F).real {a} * (if p a then 1 else 0)) = + (sweep M F).real {a | p a} := by + classical + have h := sum_measureReal_singleton (μ := sweep M F) (Finset.univ.filter p) + simpa only [Finset.sum_filter, Finset.coe_filter, Finset.coe_univ, + Set.ofPred_mem_eq, Set.mem_univ, Finset.mem_univ, true_and, mul_ite, mul_one, mul_zero] using h + +lemma label_mean (M : ℝ) (F : V → ℝ) (v : V) (hv : -M ≤ F v ∧ F v ≤ M) : + OrderedSweepFlow.total (weight M F) + (OrderedSweepFlow.labelReal (fun a : Carrier M F => a.val v)) = F v + M := by + classical + rw [OrderedSweepFlow.total] + change (∑ a : Carrier M F, weight M F a * (if a.val v then 1 else 0)) = _ + rw [sum_carrier M F (fun a => if a v then 1 else 0)] + trans (sweep M F).real {a | a v = true} + · convert sum_event M F (fun a => a v = true) using 1 + apply Finset.sum_congr rfl + intro a _ + congr 1 + split_ifs <;> rfl + · rw [sweep, map_measureReal_apply (measurable_thresholdLabels F) + ((Set.toFinite _).measurableSet), + measureReal_restrict_apply ((measurable_thresholdLabels F) ((Set.toFinite _).measurableSet))] + have he : (thresholdLabels F ⁻¹' {a | a v = true}) ∩ Icc (-M) M = Ico (-M) (F v) := by + ext t + simp only [Set.mem_inter_iff, Set.mem_preimage, Set.mem_ofPred_eq, + thresholdLabels, decide_eq_true_eq, Set.mem_Icc, Set.mem_Ico] + constructor + · rintro ⟨h, h₁, _⟩; exact ⟨h₁,h⟩ + · rintro ⟨h₁,h⟩; exact ⟨h,h₁,h.le.trans hv.2⟩ + rw [he, Real.volume_real_Ico_of_le hv.1] + ring + +end BoundedTreewidthL1.OrderedReservation + +namespace BoundedTreewidthL1.OrderedReservation +attribute [local instance] Classical.decEq Classical.propDecidable +open MeasureTheory Set OrderedSweepFlow +open scoped BigOperators +variable {V : Type*} [Fintype V] + +lemma total_weight (M : ℝ) (hM : 0 ≤ M) (F : V → ℝ) : + total (weight M F) (fun _ => 1) = 2*M := by + rw [total, sum_carrier M F (fun _ => 1)] + simp only [mul_one] + have he := sum_measureReal_singleton (μ := sweep M F) (Finset.univ : Finset (V → Bool)) + rw [he] + simp only [Finset.coe_univ] + rw [sweep, map_measureReal_apply (measurable_thresholdLabels F) MeasurableSet.univ] + simp only [Set.preimage_univ, measureReal_restrict_apply_univ] + rw [Real.volume_real_Icc_of_le (by linarith)] + ring + +/-- Explicit descending-reservation transport on the original sweep measure. +The chain may have any length, and testing and intermediate bags may repeat. +There is no width assumption or Markov-flow hypothesis. -/ +theorem sweep_height_transport (M : ℝ) (hM : 0 ≤ M) (F : V → ℝ) + (hF : ∀ v, -M ≤ F v ∧ F v ≤ M) (z : V) (P : Finset V) + (bags : List (Finset V)) (p : Carrier M F → ℝ) + (hp : ∀ a, 0 ≤ p a ∧ p a ≤ 1) + (hptrace : ∀ a b, (∀ v : P, a.val v = b.val v) → p a = p b) + (t : ℝ) (hlo : t ≤ F z + M) (hhi : t ≤ M - F z) + (hgap : ∀ v ∈ P, t ≤ |F z - F v|) : + t ≤ defect (weight M F) + (execute (weight M F) (bags.map (traceRank M F)) + (labelReal (fun a => a.val z))) p := by + let f := execute (weight M F) (bags.map (traceRank M F)) + (labelReal (fun a => a.val z)) + have hm : total (weight M F) f = F z + M := by + rw [execute_total _ (weight_pos M F), label_mean M F z (hF z)] + have hf : Monotone f := by + apply execute_monotone _ (weight_pos M F) + · intro b hb + obtain ⟨Q,_,rfl⟩ := List.mem_map.mp hb + exact traceRank_monotone M F Q + · intro a b hab + dsimp [labelReal] + have hl := labels_monotone M F z hab + by_cases ha : a.val z = true + · have hb : b.val z = true := hl ha + simp [ha, hb] + · simp [ha] + split_ifs <;> norm_num + apply height_transport (weight M F) (weight_pos M F) + (traceRank M F P) (traceRank_monotone M F P) + (fun a (v : P) => a.val v) (fun v => labels_monotone M F v) + (fun a b h => (traceRank_fiber M F P a b).mpr h) + f p hf (execute_bounds _ (weight_pos M F) _ _ (labelReal_bounds _)) hp + (fun a b h => hptrace a b ((traceRank_fiber M F P a b).mp h)) + · exact hm ▸ hlo + · rw [total_weight M hM F, hm] + linarith + · intro v + rw [hm, label_mean M F v (hF v)] + simpa using hgap v v.property +end BoundedTreewidthL1.OrderedReservation + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/Padding.lean b/lean/OAI/Combinatorics/TreewidthL1/Padding.lean new file mode 100644 index 0000000000000000000000000000000000000000..99018c251ff25cfb0cc1e20cda5544cbd0e80d00 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/Padding.lean @@ -0,0 +1,170 @@ +import OAI.Combinatorics.TreewidthL1.Annulus + +namespace OAI + +namespace BoundedTreewidthL1 +namespace PaddedPartitions + +/-- A partition is represented by its block-label map. The fibers are the +blocks; using vertices as labels represents every partition of a finite +nonempty vertex set. Unused labels impose no extra block condition. -/ +abbrev Partition (V : Type*) := V → V + +/-- Weak diameter, measured in the original weighted graph metric. -/ +def BoundedDiameter {V : Type*} (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + (r : ℝ) (P : Partition V) : Prop := + ∀ u v, P u = P v → shortestPathDistance G ℓ u v ≤ r + +/-- The closed metric ball is contained in the block containing x. -/ +def PaddedAt {V : Type*} (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + (s : ℝ) (P : Partition V) (x : V) : Prop := + ∀ y, shortestPathDistance G ℓ x y ≤ s → P y = P x + +noncomputable def paddingProbability {V : Type*} [Fintype V] + (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) (s : ℝ) + (μ : Partition V → ℝ) (x : V) : ℝ := by + classical + exact ∑ P, if PaddedAt G ℓ s P x then μ P else 0 + +def UniformPaddedPartitions : Prop := + ∀ k : ℕ, 2 ≤ k → ∃ α π : ℝ, + 0 < α ∧ α ≤ 1 / 8 ∧ 0 < π ∧ π ≤ 1 ∧ + ∀ (V : Type) [Fintype V] [DecidableEq V] [Nontrivial V] + (G : SimpleGraph V), G.Connected → HasTreeDecomposition G k → + ∀ ℓ : G.edgeSet → ℝ, (∀ e, 0 < ℓ e) → + ∀ r : ℝ, 0 < r → ∃ μ : Partition V → ℝ, + (∀ P, 0 ≤ μ P) ∧ (∑ P, μ P) = 1 ∧ + (∀ P, 0 < μ P → BoundedDiameter G ℓ r P) ∧ + ∀ x, π ≤ paddingProbability G ℓ (α * r) μ x + +end PaddedPartitions +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.PaddedPartitions +open Annulus + +theorem uniform_padded_partitions : UniformPaddedPartitions := by + classical + intro k hk + have hk0 : 0 < k := by omega + have hkR : (2 : ℝ) ≤ k := by exact_mod_cast hk + have hkR0 : (0 : ℝ) < k := by positivity + let α : ℝ := 1 / (64 * (k : ℝ)^2) + have hα : 0 < α := by dsimp [α]; positivity + have hα8 : α ≤ 1 / 8 := by + dsimp [α] + apply div_le_div_of_nonneg_left (by norm_num) (by norm_num) + nlinarith + refine ⟨α, 1/2, hα, hα8, by norm_num, by norm_num, ?_⟩ + intro V _ _ _ G hG hdec ℓ hℓ r hr + let w : Sym2 V → ℝ := fun e => if h : e ∈ G.edgeSet then ℓ ⟨e, h⟩ else 0 + have hw : ∀ e, 0 ≤ w e := by + intro e + dsimp [w] + split_ifs with h + · exact (hℓ ⟨e, h⟩).le + · exact le_rfl + have hweights : weights G w = ℓ := by + funext e + simp [weights, w, e.property] + let : MetricSpace V := weightedMetricSpace G ℓ hG hℓ + have hdist : ∀ u v, dist u v = distance G w u v := by + intro u v + change shortestPathDistance G ℓ u v = shortestPathDistance G (weights G w) u v + rw [hweights] + let M := 4 * k + have hM : 0 < M := by dsimp [M]; omega + have hMR : (0 : ℝ) < M := by exact_mod_cast hM + have hMR4 : (M : ℝ) = 4 * (k : ℝ) := by simp [M] + let R := r / (4 * (k : ℝ)) + have hR : 0 < R := by dsimp [R]; positivity + let ε := R / (4 * (M : ℝ)) + have hε : 0 < ε := by dsimp [ε]; positivity + have hεα : ε = α * r := by + dsimp [ε, R, α] + rw [hMR4] + field_simp + ; ring + have hsep : 2 * (M : ℝ) * (ε / R) < 1 := by + have heq : 2 * (M : ℝ) * (ε / R) = 1/2 := by + dsimp [ε] + field_simp + ; ring + rw [heq] + norm_num + have hdiam : (k : ℝ) * (2 * R + 4 * ε) ≤ r := by + have hMlarge : (1 : ℝ) ≤ M := by rw [hMR4]; nlinarith + have hεR : 4 * ε ≤ R := by + have heq : 4 * ε = R / (M : ℝ) := by + dsimp [ε] + field_simp + rw [heq] + apply (div_le_iff₀ hMR).mpr + nlinarith + have hkr : (k : ℝ) * R = r/4 := by dsimp [R]; field_simp [hkR0.ne'] + nlinarith + obtain ⟨d, T, bag, hT, hcover, hedge, hocc, hwidth⟩ := hdec + let H := smallEdges G w ε + let F : (Fin k → Fin M) → SimpleGraph V := run w R (gridOffset M R) k H + let P : (Fin k → Fin M) → Partition V := fun σ => root (F σ) + have hPdiam : ∀ σ, BoundedDiameter G ℓ r (P σ) := by + intro σ u v huv + have hreach : (F σ).Reachable u v := by + have hu := root_reachable (F σ) u + have hv := root_reachable (F σ) v + change root (F σ) u = root (F σ) v at huv + rw [huv] at hu + exact hu.symm.trans hv + have hballs : ∀ c, (G.induce {z | dist c z ≤ R + ε}).Connected := by + intro c + exact shortest_closedBall_connected G ℓ hG (fun e => (hℓ e).le) c (by positivity) + have hd := run_diameter G H (smallEdges_le G w ε) w hw hdist T bag k + (by omega) hT hedge hocc hwidth hR hε (smallEdges_mesh G w ε) hballs + (gridOffset M R) (gridOffset_nonneg hR.le) (gridOffset_lt hR) σ u v hreach + exact hd.trans hdiam + let μ := FiniteLawPush.law P + let : Nonempty (Fin M) := ⟨⟨0, hM⟩⟩ + refine ⟨μ, FiniteLawPush.nonneg P, FiniteLawPush.total P, ?_, ?_⟩ + · intro Q hQ + obtain ⟨σ, rfl⟩ := FiniteLawPush.supported P Q hQ + exact hPdiam σ + · intro x + have hcount := preserves_fraction G w hw hG M hM hR hε.le hsep k x + have hgood : ∀ σ, PreservesBall G (F σ) w ε x → PaddedAt G ℓ (α*r) (P σ) x := by + intro σ hp y hy + have hdy : distance G w x y ≤ ε := by + dsimp [distance] + rw [hweights, hεα] + exact hy + obtain ⟨p, _⟩ := hp y hdy + exact root_eq p.reachable.symm + have hsum : (∑ σ : Fin k → Fin M, + if PreservesBall G (F σ) w ε x then (1 : ℝ) else 0) ≤ + ∑ σ : Fin k → Fin M, if PaddedAt G ℓ (α*r) (P σ) x then (1 : ℝ) else 0 := by + apply Finset.sum_le_sum + intro σ _ + by_cases hp : PreservesBall G (F σ) w ε x + · simp [hp, hgood σ hp] + · simp only [hp, ↓reduceIte] + split <;> norm_num + have hhalf : (1 : ℝ)/2 ≤ 1 - (k : ℝ)/M := by + rw [hMR4] + have hq : (k : ℝ) / (4 * (k : ℝ)) = 1/4 := by field_simp [hkR0.ne'] + rw [hq] + norm_num + calc + (1 : ℝ)/2 ≤ 1 - (k : ℝ)/M := hhalf + _ ≤ (∑ σ : Fin k → Fin M, + if PreservesBall G (F σ) w ε x then (1 : ℝ) else 0) / (M : ℝ)^k := hcount + _ ≤ (∑ σ : Fin k → Fin M, + if PaddedAt G ℓ (α*r) (P σ) x then (1 : ℝ) else 0) / (M : ℝ)^k := + div_le_div_of_nonneg_right hsum (pow_nonneg hMR.le k) + _ = paddingProbability G ℓ (α*r) μ x := by + let : DecidableEq V := Classical.decEq V + unfold paddingProbability + have hh := (FiniteLawPush.event P (fun Q => PaddedAt G ℓ (α*r) Q x)).symm + simpa only [Fintype.card_fun, Fintype.card_fin, Nat.cast_pow] using hh + +end BoundedTreewidthL1.PaddedPartitions + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/ParticleLaws.lean b/lean/OAI/Combinatorics/TreewidthL1/ParticleLaws.lean new file mode 100644 index 0000000000000000000000000000000000000000..43ddb85f2faa8627a78204e559eaed538ce7081c --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/ParticleLaws.lean @@ -0,0 +1,827 @@ +import OAI.Combinatorics.TreewidthL1.BagLabels + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 + +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory Set +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I J : Type*} [Fintype V] [Fintype I] [Fintype J] [DecidableEq V] + +lemma singleton_sum {A : Type*} [Fintype A] [MeasurableSpace A] + [MeasurableSingletonClass A] (μ : Measure A) [IsFiniteMeasure μ] (S : Set A) : + (∑ a, if a ∈ S then μ.real {a} else 0) = μ.real S := by + classical + rw [← Finset.sum_filter] + rw [sum_measureReal_singleton] + congr 1 + ext a + simp + +lemma measure_marginal {A D : Type*} [Fintype A] [MeasurableSpace A] + [MeasurableSingletonClass A] [MeasurableSpace D] [MeasurableSingletonClass D] + (μ : Measure A) [IsFiniteMeasure μ] (f : A → D) (c : D) : + marginal f (fun a => μ.real {a}) c = (μ.map f).real {c} := by + classical + unfold marginal + rw [show (∑ a, if f a = c then μ.real {a} else 0) = + μ.real {a | f a = c} from singleton_sum μ _] + rw [map_measureReal_apply (measurable_of_finite f) (measurableSet_singleton c)] + rfl + +lemma real_sum {A : Type*} [MeasurableSpace A] (μ : J → Measure A) + [∀ j, IsFiniteMeasure (μ j)] (S : Set A) : + (∑ j, μ j).real S = ∑ j, (μ j).real S := by + simp only [measureReal_def, Measure.finsetSum_apply] + exact ENNReal.toReal_sum (fun j _ => measure_ne_top _ _) + +lemma symmetrize_mass + {V : Type treewidthLevel1} [Fintype V] [DecidableEq V] + (μ : Measure (V → Bool)) [IsFiniteMeasure μ] : + (symmetrizeCut μ).real univ = μ.real univ := by + rw [measureReal_def, symmetrizeCut, Measure.smul_apply, Measure.add_apply, + Measure.map_apply measurable_complementCut MeasurableSet.univ] + simp only [preimage_univ, smul_eq_mul] + rw [ENNReal.toReal_mul, ENNReal.toReal_add (measure_ne_top _ _) (measure_ne_top _ _)] + norm_num [measureReal_def] + ring + +lemma symmetrize_flip + {V : Type treewidthLevel1} [Fintype V] [DecidableEq V] + (μ : Measure (V → Bool)) : + (symmetrizeCut μ).map complementCut = symmetrizeCut μ := by + unfold symmetrizeCut + rw [Measure.map_smul _ measurable_complementCut.aemeasurable, Measure.map_add _ _ measurable_complementCut, + Measure.map_map measurable_complementCut measurable_complementCut] + have h : complementCut ∘ complementCut = (id : (V → Bool) → _) := by + funext x + exact complementCut_involutive x + rw [h, Measure.map_id] + rw [add_comm] + +noncomputable def particleMeasure (M : ℝ) (F : J → V → ℝ) : Measure (V → Bool) := + ∑ j, symmetrizeCut (sweep M (F j)) + +instance particleMeasure_finite (M : ℝ) (F : J → V → ℝ) : + IsFiniteMeasure (particleMeasure M F) := by + unfold particleMeasure + infer_instance + +lemma particleTrace_eq + {V : Type treewidthLevel1} {J : Type treewidthLevel2} [Fintype V] [Fintype J] [DecidableEq V] + (M : ℝ) (F : J → V → ℝ) (P : Finset V) : + particleTrace M F P = (particleMeasure M F).map (fun ω => fun v : P => ω v) := by + unfold particleTrace particleMeasure cutTrace + rw [Measure.map_finset_sum (measurable_of_finite _).aemeasurable] + +instance particleTrace_finite (M : ℝ) (F : J → V → ℝ) (P : Finset V) : + IsFiniteMeasure (particleTrace M F P) := by + rw [particleTrace_eq] + infer_instance + +lemma particle_mass (M : ℝ) (hM : 0 ≤ M) (F : J → V → ℝ) : + (particleMeasure M F).real univ = 2*(Fintype.card J : ℝ)*M := by + rw [particleMeasure, real_sum] + simp only [symmetrize_mass, sweep_total_mass M hM, Finset.sum_const, + Finset.card_univ, nsmul_eq_mul] + ring + +lemma particle_flip (M : ℝ) (F : J → V → ℝ) : + (particleMeasure M F).map complementCut = particleMeasure M F := by + unfold particleMeasure + rw [Measure.map_finset_sum measurable_complementCut.aemeasurable] + simp only [symmetrize_flip] + +end BoundedTreewidthL1.ParticleLaws +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory Set +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I J : Type*} [Fintype V] [Fintype I] [Fintype J] [DecidableEq V] + +lemma symmetrize_separation + {V : Type treewidthLevel1} [Fintype V] [DecidableEq V] + (μ : Measure (V → Bool)) [IsFiniteMeasure μ] (u v : V) : + cutSeparation (symmetrizeCut μ) u v = cutSeparation μ u v := by + unfold cutSeparation symmetrizeCut + rw [measureReal_ennreal_smul_apply, measureReal_add_apply (by finiteness) (by finiteness), + map_measureReal_apply measurable_complementCut (Set.toFinite _).measurableSet] + have h : complementCut ⁻¹' {ω : V → Bool | ω u ≠ ω v} = {ω | ω u ≠ ω v} := by + ext ω + simp [complementCut] + rw [h] + norm_num + ring + +lemma particle_separation (M : ℝ) (F : J → V → ℝ) (hF : ∀ j v, |F j v| ≤ M) + (u v : V) : cutSeparation (particleMeasure M F) u v = ∑ j, |F j u - F j v| := by + unfold cutSeparation particleMeasure + rw [real_sum] + apply Finset.sum_congr rfl + intro j hj + exact (symmetrize_separation (sweep M (F j)) u v).trans (sweep_separation M (F j) (hF j) u v) + +lemma trace_mass (M : ℝ) (hM : 0 ≤ M) (F : J → V → ℝ) (P : Finset V) : + (particleTrace M F P).real univ = 2*(Fintype.card J : ℝ)*M := by + rw [particleTrace_eq, map_measureReal_apply (measurable_of_finite _) MeasurableSet.univ] + simpa only [preimage_univ] using particle_mass M hM F + +lemma trace_flip (M : ℝ) (F : J → V → ℝ) (P : Finset V) : + (particleTrace M F P).map complementCut = particleTrace M F P := by + rw [particleTrace_eq, Measure.map_map measurable_complementCut (measurable_of_finite _)] + have h : complementCut ∘ (fun ω : V → Bool => fun v : P => ω v) = + (fun ω : V → Bool => fun v : P => ω v) ∘ complementCut := rfl + rw [h, ← Measure.map_map (measurable_of_finite _) measurable_complementCut, particle_flip] + +lemma flip_point_mass + {V : Type treewidthLevel1} [Fintype V] [DecidableEq V] + (μ : Measure (V → Bool)) (hs : μ.map complementCut = μ) (ω : V → Bool) : + μ.real {complementCut ω} = μ.real {ω} := by + conv_lhs => rw [← hs] + rw [map_measureReal_apply measurable_complementCut (measurableSet_singleton _)] + congr 1 + ext a + simp only [mem_preimage, mem_singleton_iff] + exact complementCut_involutive.injective.eq_iff + +lemma marginal_test {A D : Type*} [Fintype A] [Fintype D] + (f : A → D) (μ : A → ℝ) (h : D → ℝ) : + (∑ c, marginal f μ c * h c) = ∑ a, μ a * h (f a) := by + classical + unfold marginal + simp_rw [Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a ha + simp only [ite_mul, zero_mul] + simp + +lemma separation_of_marginal (ρ : (V → Bool) → ℝ) (P : Finset V) + (μ : Measure (P → Bool)) [IsFiniteMeasure μ] + (h : ∀ a, marginal (fun ω : V → Bool => fun v : P => ω v) ρ a = μ.real {a}) + (u v : P) : cutDistance ρ (fun ω => ω) u.val v.val = cutSeparation μ u v := by + have ht := marginal_test (fun ω : V → Bool => fun v : P => ω v) ρ + (fun a => if a u = a v then 0 else 1) + simp only [h, mul_ite, mul_zero, mul_one] at ht + rw [cutDistance, ← ht] + unfold cutSeparation + have hs := singleton_sum μ {a | a u ≠ a v} + simp only [mem_ofPred_eq, Classical.ite_not] at hs + convert! hs using 1 + apply Finset.sum_congr rfl + intro label _ + split_ifs <;> rfl + +lemma trace_separation (M : ℝ) (F : J → V → ℝ) (P : Finset V) (u v : P) : + cutSeparation (particleTrace M F P) u v = cutSeparation (particleMeasure M F) u.val v.val := by + unfold cutSeparation + rw [particleTrace_eq, map_measureReal_apply (measurable_of_finite _) (Set.toFinite _).measurableSet] + rfl + +end BoundedTreewidthL1.ParticleLaws +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory Set +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I J : Type*} [Fintype V] [Fintype I] [Fintype J] [DecidableEq V] + +lemma overlapping_traces + {V : Type treewidthLevel1} {I : Type treewidthLevel2} {J : Type treewidthLevel3} [Fintype V] + [Fintype I] [Fintype J] [DecidableEq V] + (M : ℝ) (B : I → Finset V) (F : I → J → V → ℝ) (i j : I) + (h : particleTrace M (F i) (B i ∩ B j) = particleTrace M (F j) (B i ∩ B j)) : + ∀ c, marginal (BagLabels.leftTrace (fun i => (B i : Set V)) i j) + (fun a => (particleTrace M (F i) (B i)).real {a}) c = + marginal (BagLabels.rightTrace (fun i => (B i : Set V)) i j) + (fun a => (particleTrace M (F j) (B j)).real {a}) c := by + intro c + have hl : marginal (BagLabels.leftTrace (fun i => (B i : Set V)) i j) + (fun a => (particleTrace M (F i) (B i)).real {a}) c = + ((particleTrace M (F i) (B i)).map (BagLabels.leftTrace (fun i => (B i : Set V)) i j)).real {c} := by + convert! (measure_marginal (particleTrace M (F i) (B i)) + (BagLabels.leftTrace (fun i => (B i : Set V)) i j) c) using 1 + have hr : marginal (BagLabels.rightTrace (fun i => (B i : Set V)) i j) + (fun a => (particleTrace M (F j) (B j)).real {a}) c = + ((particleTrace M (F j) (B j)).map (BagLabels.rightTrace (fun i => (B i : Set V)) i j)).real {c} := by + convert! (measure_marginal (particleTrace M (F j) (B j)) + (BagLabels.rightTrace (fun i => (B i : Set V)) i j) c) using 1 + rw [hl,hr] + let E : ((B i ∩ B j : Finset V) → Bool) → (↥((B i : Set V) ∩ (B j : Set V)) → Bool) := + fun a v => a ⟨v.val, Finset.mem_inter.mpr v.property⟩ + have he (A : J → V → ℝ) : + (particleTrace M A (B i ∩ B j)).map E = + (particleMeasure M A).map (fun ω => fun v : ↥((B i : Set V) ∩ (B j : Set V)) => ω v) := by + rw [particleTrace_eq, Measure.map_map (measurable_of_finite _) (measurable_of_finite _)] + rfl + have hh := congrArg (fun μ => μ.map E) h + rw [he, he] at hh + rw [particleTrace_eq, particleTrace_eq, + Measure.map_map (measurable_of_finite _) (measurable_of_finite _), + Measure.map_map (measurable_of_finite _) (measurable_of_finite _)] + exact congrArg (fun μ => μ.real {c}) hh + +lemma norm_bound_from_edges + {V : Type treewidthLevel1} [Fintype V] [DecidableEq V] + {E : Type*} [NormedAddCommGroup E] + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) + (U : ℝ) (Φ : V → E) + (he : ∀ u v (h : G.Adj u v), ‖Φ u - Φ v‖ ≤ U * ℓ ⟨s(u,v),h⟩) : + ∀ u v, ‖Φ u - Φ v‖ ≤ U * shortestPathDistance G ℓ u v := by + have hw {u v : V} (p : G.Walk u v) : ‖Φ u - Φ v‖ ≤ U * walkLength G ℓ p := by + induction p with + | nil => simp [walkLength] + | @cons u v w huv p ih => + calc + ‖Φ u - Φ w‖ ≤ ‖Φ u - Φ v‖ + ‖Φ v - Φ w‖ := norm_sub_le_norm_sub_add_norm_sub _ _ _ + _ ≤ U * ℓ ⟨s(u,v),huv⟩ + U * walkLength G ℓ p := add_le_add (he u v huv) ih + _ = U * walkLength G ℓ (.cons huv p) := by rw [walkLength, mul_add] + intro u v + obtain ⟨p,hp,hlen⟩ := shortestPathDistance_attained G ℓ hG u v + rw [← hlen] + exact hw p + +end BoundedTreewidthL1.ParticleLaws + +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I J : Type*} [Fintype V] [Fintype I] [Fintype J] [DecidableEq V] + +end BoundedTreewidthL1.ParticleLaws +namespace BoundedTreewidthL1.ParticleLaws +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I : Type*} [Fintype V] [Fintype I] + +lemma gluing_without_path (T : SimpleGraph I) (hT : T.IsTree) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (μ : (i : I) → (B i → Bool) → ℝ) (m : ℝ) (hm : 0 < m) + (hμ : ∀ i a, 0 ≤ μ i a) (hmass : ∀ i, (∑ a, μ i a) = m) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (BagLabels.leftTrace B i j) (μ i) c = marginal (BagLabels.rightTrace B i j) (μ j) c) + (hflip : ∀ i a, μ i (BagLabels.flip (B i) a) = μ i a) : + ∃ ρ : (V → Bool) → ℝ, + (∀ ω, 0 ≤ ρ ω) ∧ (∑ ω, ρ ω) = m ∧ + (∀ ω, ρ (complementCut ω) = ρ ω) ∧ + (∀ i a, marginal (fun ω => BagLabels.restrict B ω i) ρ a = μ i a) ∧ + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + ∀ u v, ‖Φ u - Φ v‖ = cutDistance ρ (fun ω => ω) u v := by + obtain ⟨ρ,hρ,hρmass,hρflip,hρlocal,hρpath,n,Φ,hΦ⟩ := + BagLabels.canonical_gluing T hT B hcover hrun μ m hm hμ + (by intro i; convert! hmass i using 1) + (by intro i j hij c; convert! hcons i j hij c using 1) hflip + exact ⟨ρ,hρ,hρmass,hρflip,hρlocal,n,Φ,hΦ⟩ + +end BoundedTreewidthL1.ParticleLaws +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I J : Type*} [Fintype V] [Fintype I] [Fintype J] [DecidableEq V] + +lemma glue_particle_measures (T : SimpleGraph I) (hT : T.IsTree) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (M : ℝ) (hM : 0 < M) (hN : 1 ≤ Fintype.card J) (F : I → J → V → ℝ) + (hcons : ∀ i j, T.Adj i j → particleTrace M (F i) (B i ∩ B j) = + particleTrace M (F j) (B i ∩ B j)) : + ∃ ρ : (V → Bool) → ℝ, + (∀ ω, 0 ≤ ρ ω) ∧ (∑ ω, ρ ω) = 2*(Fintype.card J : ℝ)*M ∧ + (∀ ω, ρ (complementCut ω) = ρ ω) ∧ + (∀ i a, marginal (fun ω : V → Bool => fun v : B i => ω v) ρ a = + (particleTrace M (F i) (B i)).real {a}) ∧ + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + ∀ u v, ‖Φ u - Φ v‖ = cutDistance ρ (fun ω => ω) u v := by + let μ : (i : I) → (B i → Bool) → ℝ := + fun i a => (particleTrace M (F i) (B i)).real {a} + have hn : (1 : ℝ) ≤ Fintype.card J := by exact_mod_cast hN + have hm : 0 < 2*(Fintype.card J : ℝ)*M := by positivity + have hmass : ∀ i, (∑ a, μ i a) = 2*(Fintype.card J : ℝ)*M := by + intro i + change (∑ a, (particleTrace M (F i) (B i)).real {a}) = _ + rw [sum_measureReal_singleton] + simpa using trace_mass M hM.le (F i) (B i) + have hcompat : ∀ i j, T.Adj i j → ∀ c, + marginal (BagLabels.leftTrace (fun i => (B i : Set V)) i j) (μ i) c = + marginal (BagLabels.rightTrace (fun i => (B i : Set V)) i j) (μ j) c := by + intro i j hij + exact overlapping_traces M B F i j (hcons i j hij) + have hflip : ∀ i a, μ i (BagLabels.flip (B i) a) = μ i a := by + intro i a + exact flip_point_mass (particleTrace M (F i) (B i)) (trace_flip M (F i) (B i)) a + have hn_set : ∀ i, (∑ a : ↥((fun i => (B i : Set V)) i) → Bool, μ i a) = + 2*(Fintype.card J : ℝ)*M := by + intro i + convert! hmass i using 1 + have hμ : ∀ i a, 0 ≤ μ i a := by + intro i a + exact measureReal_nonneg + generalize hdef : μ = μ' at hμ hmass hcompat hflip hn_set + obtain ⟨ρ,hρ,hρmass,hρflip,hρlocal,n,Φ,hΦ⟩ := + gluing_without_path T hT (fun i => (B i : Set V)) hcover hrun + μ' (2*(Fintype.card J : ℝ)*M) hm hμ + (by intro i; convert! hn_set i using 1 ; congr 1 ; first | exact Subsingleton.elim _ _ | (ext; simp only [Finset.mem_univ])) + (by intro i j hij c; convert! hcompat i j hij c using 1 <;> congr 1 <;> exact Subsingleton.elim _ _) hflip + refine ⟨ρ,hρ,?_,hρflip,?_,n,Φ,?_⟩ + · convert! hρmass using 1 ; congr 1 ; first | exact Subsingleton.elim _ _ | (ext; simp only [Finset.mem_univ]) + · intro i a + rw [← hdef] at hρlocal + convert! hρlocal i a using 1 ; congr 1 ; exact Subsingleton.elim _ _ + · intro u v + convert! hΦ u v using 1 ; congr 1 ; exact Subsingleton.elim _ _ + +theorem particle_law_realization + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (hT : T.IsTree) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (L H Δ : ℝ) (hL : 0 < L) (hH : 0 < H) (hΔ : 0 < Δ) + (hN : 1 ≤ Fintype.card J) (F : I → J → V → ℝ) + (hF : ∀ i, FunctionParticleReachable (shortestPathDistance G ℓ) L H (F i)) + (hcons : ∀ i j, T.Adj i j → + particleTrace (H*((Fintype.card J : ℝ)-1)+2*Δ) (F i) (B i ∩ B j) = + particleTrace (H*((Fintype.card J : ℝ)-1)+2*Δ) (F j) (B i ∩ B j)) : + let M := H*((Fintype.card J : ℝ)-1)+2*Δ + ∃ ρ : (V → Bool) → ℝ, + (∀ ω, 0 ≤ ρ ω) ∧ (∑ ω, ρ ω) = 2*(Fintype.card J : ℝ)*M ∧ + (∀ ω, ρ (complementCut ω) = ρ ω) ∧ + (∀ i a, marginal (fun ω : V → Bool => fun v : B i => ω v) ρ a = + (particleTrace M (F i) (B i)).real {a}) ∧ + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ = cutDistance ρ (fun ω => ω) u v) ∧ + ∀ u v, ‖Φ u - Φ v‖ ≤ + (Fintype.card J : ℝ)*L*((Fintype.card J : ℝ)-1)*shortestPathDistance G ℓ u v := by + dsimp only + let M := H*((Fintype.card J : ℝ)-1)+2*Δ + have hn : (1 : ℝ) ≤ Fintype.card J := by exact_mod_cast hN + have hM : 0 < M := by + dsimp [M] + have := mul_nonneg hH.le (sub_nonneg.mpr hn) + linarith + obtain ⟨ρ,hρ,hρmass,hρflip,hρlocal,n,Φ,hΦ⟩ := + glue_particle_measures T hT B hcover hrun M hM hN F hcons + refine ⟨ρ,hρ,hρmass,hρflip,hρlocal,n,Φ,hΦ,?_⟩ + apply norm_bound_from_edges G hG ℓ _ Φ + intro u v huv + obtain ⟨i,hu,hv⟩ := hedge u v huv + have hh : ∀ j x, |F i j x| ≤ M := by + intro j x + have := function_particles_height_bound hH (hF i) j x + dsimp [M] + linarith + have hd := shortestPathDistance_pos G ℓ hG hℓ huv.ne + have hsep : ‖Φ u - Φ v‖ = ∑ j, |F i j u - F i j v| := by + rw [hΦ, separation_of_marginal ρ (B i) (particleTrace M (F i) (B i)) + (hρlocal i) ⟨u,hu⟩ ⟨v,hv⟩, trace_separation, particle_separation M (F i) hh] + rw [hsep] + have hsum : (∑ j, |F i j u - F i j v|) ≤ + (Fintype.card J : ℝ)*L*((Fintype.card J : ℝ)-1)*shortestPathDistance G ℓ u v := by + calc + (∑ j, |F i j u - F i j v|) ≤ + ∑ _ : J, L*((Fintype.card J : ℝ)-1)*shortestPathDistance G ℓ u v := + Finset.sum_le_sum (fun j _ => function_particles_difference_bound hL (hF i) j u v hd) + _ = _ := by simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]; ring + apply hsum.trans + apply mul_le_mul_of_nonneg_left ?_ (by positivity) + have he := shortestPathDistance_le_walkLength G ℓ (fun e => (hℓ e).le) (huv.toWalk) + simpa [SimpleGraph.Adj.toWalk, walkLength] using he +end BoundedTreewidthL1.ParticleLaws +namespace BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.propDecidable +variable {I : Type*} (T : SimpleGraph I) (hT : T.IsTree) (root : I) + +noncomputable def path (i : I) : T.Walk i root := + (hT.connected.exists_path_of_dist i root).choose +lemma path_isPath (i : I) : (path T hT root i).IsPath := + (hT.connected.exists_path_of_dist i root).choose_spec.1 +lemma path_length (i : I) : (path T hT root i).length = T.dist i root := + (hT.connected.exists_path_of_dist i root).choose_spec.2 + +lemma snd_closer {i : I} (hi : i ≠ root) : + T.dist (path T hT root i).snd root < T.dist i root := by + have hlen := (path T hT root i).length_tail_add_one + (SimpleGraph.Walk.not_nil_of_ne hi) + have hdist := SimpleGraph.dist_le (path T hT root i).tail + rw [path_length] at hlen + omega + +noncomputable def forest : RootedForest I where + parent i := if i = root then none else some (path T hT root i).snd + depth i := T.dist i root + decreases := by + classical + intro i p hp + by_cases hi : i = root + · simp only [hi, ite_eq_left] at hp + contradiction + · simp only [hi, ite_false, Option.some.injEq] at hp + subst p + exact snd_closer T hT root hi + +lemma parent_adj {i p : I} (hp : (forest T hT root).parent i = some p) : T.Adj i p := by + classical + change (if i = root then none else some (path T hT root i).snd) = some p at hp + by_cases hi : i = root + · simp only [ite_eq_left hi] at hp + contradiction + · simp only [ite_eq_right hi] at hp + cases Option.some.inj hp + exact SimpleGraph.Walk.adj_snd (SimpleGraph.Walk.not_nil_of_ne hi) + +lemma parent_of_closer {i j : I} (hij : T.Adj i j) + (hd : T.dist j root + 1 = T.dist i root) : + (forest T hT root).parent i = some j := by + classical + have hi : i ≠ root := by + intro he; subst i + simp only [SimpleGraph.dist_self] at hd + omega + let q : T.Walk i root := (path T hT root j).cons hij + have hq : q.length = T.dist i root := by + simpa only [q, SimpleGraph.Walk.length_cons, path_length, Nat.add_comm] using hd + have he : q = path T hT root i := + congrArg Subtype.val ((hT.isAcyclic.subsingleton_path i root).elim + ⟨q,q.isPath_of_length_eq_dist hq⟩ ⟨_,path_isPath T hT root i⟩) + change (if i = root then none else some (path T hT root i).snd) = some j + rw [ite_eq_right hi, ← he] + simp only [q, SimpleGraph.Walk.snd_cons] + +/-- Every actual tree edge is a parent-child edge of the depth-certified forest. -/ +theorem edge_orientation {i j : I} (hij : T.Adj i j) : + (forest T hT root).parent i = some j ∨ (forest T hT root).parent j = some i := by + have hd := hT.dist_eq_dist_add_one_of_adj root hij + rw [SimpleGraph.dist_comm (u := root) (v := i), + SimpleGraph.dist_comm (u := root) (v := j)] at hd + rcases hd with hd | hd + · exact Or.inl (parent_of_closer T hT root hij hd.symm) + · exact Or.inr (parent_of_closer T hT root hij.symm hd.symm) + +end BoundedTreewidthL1.RootedTree +namespace BoundedTreewidthL1.BagLabels +open MeasureTheory +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {Ω V I : Type*} [MeasurableSpace Ω] [Fintype V] [Fintype I] + +/-- Explicit prepared law: the pushforward of the normalized tree density, +using the actual overlap couplings, with the convention 0/0 = 0. -/ +noncomputable def canonicalLaw (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (p : (i : I) → (B i → Bool) → ℝ) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (p i) c = marginal (rightTrace B i j) (p j) c) : + (V → Bool) → ℝ := + globalMass T B hcover p + (TreeMarkov.interaction (fun i => B i → Bool) p (pairMass T B p)) + (TreeMarkov.interaction_symmetric (fun i => B i → Bool) p _ + (pairMass_symmetric T B p hcons)) + +lemma marginal_measurable {A C : Type*} [Fintype A] + (f : A → C) (p : Ω → A → ℝ) (hp : ∀ a, Measurable (fun ξ => p ξ a)) (c : C) : + Measurable (fun ξ => marginal f (p ξ) c) := by + unfold marginal + apply Finset.measurable_sum + intro a ha + by_cases he : f a = c + · simpa only [he, ite_true] using hp a + · simp only [he, ite_false] + exact measurable_const + +lemma pairMass_measurable + {Ω : Type treewidthLevel1} {V : Type treewidthLevel2} {I : Type treewidthLevel3} + [MeasurableSpace Ω] [Fintype V] [Fintype I] + (T : SimpleGraph I) (B : I → Set V) + (p : Ω → (i : I) → (B i → Bool) → ℝ) + (hp : ∀ i a, Measurable (fun ξ => p ξ i a)) + (i j : I) (a : B i → Bool) (b : B j → Bool) : + Measurable (fun ξ => pairMass T B (p ξ) i j a b) := by + unfold pairMass glueWeights + by_cases hij : T.Adj i j + · simp only [hij, ite_true] + by_cases hab : leftTrace B i j a = rightTrace B i j b + · simp only [hab, ite_true] + exact ((hp i a).mul (hp j b)).div + (marginal_measurable (leftTrace B i j) (fun ξ => p ξ i) (hp i) _) + · simp only [hab, ite_false] + exact measurable_const + · simp only [hij, ite_false] + exact measurable_const + +lemma canonicalLaw_measurable (T : SimpleGraph I) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (p : Ω → (i : I) → (B i → Bool) → ℝ) + (hcons : ∀ ξ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (p ξ i) c = marginal (rightTrace B i j) (p ξ j) c) + (hp : ∀ i a, Measurable (fun ξ => p ξ i a)) (ω : V → Bool) : + Measurable (fun ξ => canonicalLaw T B hcover (p ξ) (hcons ξ) ω) := by + unfold canonicalLaw globalMass + apply Finset.measurable_sum + intro x hx + by_cases he : assemble B hcover x = ω + · simp only [he, ite_true, TreeMarkov.density] + apply Measurable.mul + · exact Finset.measurable_prod _ (fun i hi => hp i (x i)) + · apply Finset.measurable_prod + intro e he + induction e using Sym2.ind with + | _ i j => + simp only [TreeMarkov.edgeFactor_mk, TreeMarkov.interaction] + exact (pairMass_measurable T B p hp i j (x i) (x j)).div + ((hp i (x i)).mul (hp j (x j))) + · simp only [he, ite_false] + exact measurable_const + +lemma canonicalLaw_normalized (T : SimpleGraph I) (hT : T.IsTree) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (p : (i : I) → (B i → Bool) → ℝ) + (hp : ∀ i a, 0 ≤ p i a) (hp₁ : ∀ i, (∑ a, p i a) = 1) + (hcons : ∀ i j, T.Adj i j → ∀ c, + marginal (leftTrace B i j) (p i) c = marginal (rightTrace B i j) (p j) c) : + (∀ ω, 0 ≤ canonicalLaw T B hcover p hcons ω) ∧ + (∑ ω, canonicalLaw T B hcover p hcons ω) = 1 := by + obtain ⟨hs,hn,hcomp⟩ := bag_couplings T B p hp hp₁ hcons + have hh := global_bag_law.{_,_,0} T hT B hcover hrun p + (TreeMarkov.interaction (fun i => B i → Bool) p (pairMass T B p)) + (TreeMarkov.interaction_symmetric (fun i => B i → Bool) p _ + (pairMass_symmetric T B p hcons)) hn hcomp + exact ⟨hh.1, hh.2.1⟩ + +end BoundedTreewidthL1.BagLabels + +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory +variable {V ι : Type*} [Fintype V] [Fintype ι] [DecidableEq V] + +lemma trace_restrict (M : ℝ) (F : ι → V → ℝ) (P Q : Finset V) (h : Q ⊆ P) : + (particleTrace M F P).map (fun a : P → Bool => fun v : Q => a ⟨v,h v.property⟩) = + particleTrace M F Q := by + rw [particleTrace_eq, Measure.map_map (measurable_of_finite _) (measurable_of_finite _), + particleTrace_eq] + rfl + +lemma trace_eq_of_subset (M : ℝ) (F H : ι → V → ℝ) (P Q : Finset V) (h : Q ⊆ P) + (he : particleTrace M F P = particleTrace M H P) : + particleTrace M F Q = particleTrace M H Q := by + rw [← trace_restrict M F P Q h, he, trace_restrict] +end BoundedTreewidthL1.ParticleLaws + +namespace BoundedTreewidthL1.TreeParticles +open ParticleLaws +variable {I V ι J : Type*} [Fintype I] [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq V] [DecidableEq ι] [DecidableEq J] + +/-- The active-key preparation produces actual compatible global cut laws, +without assuming consistency of any sampled bag laws. -/ +theorem tree_particle_realization + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (hT : T.IsTree) (root : I) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (A : I → Finset J) (k q : ℕ) (hbag : ∀ i, (B i).card ≤ k) + (hA : ∀ i, (A i).card ≤ q) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (L H Δ : ℝ) (hL : 0 < L) (hH : 0 < H) (hΔ : 0 < Δ) + (g : I → J → V → ℝ) + (hLip : ∀ i a, ∀ u v, |g i a u - g i a v| ≤ L*shortestPathDistance G ℓ u v) + (hHeight : ∀ i a v, |g i a v| ≤ H) + (hzero : ∀ i a, ∀ v ∈ interface (RootedTree.forest T hT root) B i, g i a v = 0) : + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + let S := state (ι := ι) (RootedTree.forest T hT root) B A g + ∃ ρ : (V → Bool) → ℝ, + (∀ ω, 0 ≤ ρ ω) ∧ (∑ ω, ρ ω) = 2*(Fintype.card ι : ℝ)*M ∧ + (∀ ω, ρ (complementCut ω) = ρ ω) ∧ + (∀ i a, marginal (fun ω : V → Bool => fun v : B i => ω v) ρ a = + (particleTrace M (S i).1 (B i)).real {a}) ∧ + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ = cutDistance ρ (fun ω => ω) u v) ∧ + ∀ u v, ‖Φ u - Φ v‖ ≤ + (Fintype.card ι : ℝ)*L*((Fintype.card ι : ℝ)-1)*shortestPathDistance G ℓ u v := by + classical + dsimp only + let R := RootedTree.forest T hT root + let S := state (ι := ι) R B A g + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + obtain ⟨hreach,htrace,-,-⟩ := forest_particle_realization R B A k q hbag hA hN + (shortestPathDistance G ℓ) L H Δ hH hΔ g hLip hHeight hzero + have hcons (i j : I) (hij : T.Adj i j) : + particleTrace M (S i).1 (B i ∩ B j) = particleTrace M (S j).1 (B i ∩ B j) := by + rcases RootedTree.edge_orientation T hT root hij with hp | hp + · exact trace_eq_of_subset M _ _ (B j) _ Finset.inter_subset_right (htrace i j hp) + · exact (trace_eq_of_subset M _ _ (B i) _ Finset.inter_subset_left (htrace j i hp)).symm + have hN' : 1 ≤ Fintype.card ι := by omega + exact particle_law_realization G hG ℓ hℓ T hT B hcover hedge hrun L H Δ hL hH hΔ + hN' (fun i => (S i).1) (by + have hd : (Classical.decEq ι) = (inferInstance : DecidableEq ι) := Subsingleton.elim _ _ + rw [hd] + exact hreach) hcons +end BoundedTreewidthL1.TreeParticles + +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I Ω : Type*} [Fintype V] [Fintype I] [MeasurableSpace Ω] + +lemma marginal_integral {A D : Type*} [Fintype A] [Fintype D] + (ν : Measure Ω) (f : A → D) (μ : Ω → A → ℝ) + (h : ∀ a, Integrable (fun ω => μ ω a) ν) (b : D) : + marginal f (fun a => ∫ ω, μ ω a ∂ν) b = ∫ ω, marginal f (μ ω) b ∂ν := by + unfold marginal + rw [integral_finsetSum _ (fun a _ => if hfa : f a = b then + by simpa only [hfa,↓reduceIte] using h a else + by simp only [hfa,↓reduceIte]; exact integrable_zero Ω ℝ ν)] + apply Finset.sum_congr rfl + intro a ha + split_ifs <;> simp + +/-- Averaging local laws first preserves exactly the co-bag metric and produces +an actual Markov-glued global law, not a measurable choice of random globals. -/ +theorem averaged_bag_realization (T : SimpleGraph I) (hT : T.IsTree) (B : I → Set V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (ν : Measure Ω) [IsProbabilityMeasure ν] + (μ : Ω → (i : I) → (B i → Bool) → ℝ) (m : ℝ) (hm : 0 < m) + (hμ : ∀ ω i a, 0 ≤ μ ω i a) (hmass : ∀ ω i, (∑ a, μ ω i a) = m) + (hint : ∀ i a, Integrable (fun ω => μ ω i a) ν) + (hcons : ∀ ω i j, T.Adj i j → ∀ c, + marginal (BagLabels.leftTrace B i j) (μ ω i) c = + marginal (BagLabels.rightTrace B i j) (μ ω j) c) + (hflip : ∀ ω i a, μ ω i (BagLabels.flip (B i) a) = μ ω i a) : + ∃ ρ : (V → Bool) → ℝ, + (∀ a, 0 ≤ ρ a) ∧ (∑ a, ρ a) = m ∧ + (∀ a, ρ (complementCut a) = ρ a) ∧ + (∀ i a, marginal (fun ω => BagLabels.restrict B ω i) ρ a = ∫ ω, μ ω i a ∂ν) ∧ + (∀ (r : ℕ) (e : Fin (r+1) ↪ I), T.comap e = SimpleGraph.pathGraph (r+1) → + MarkovFlow.IsMarkovLaw (fun j => B (e j) → Bool) + (marginal (fun ω j => BagLabels.restrict B ω (e j)) (fun ω => ρ ω / m))) ∧ + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ = cutDistance ρ (fun ω => ω) u v) ∧ + ∀ i (u v : B i), ‖Φ u.val - Φ v.val‖ = + ∫ ω, (∑ a, if a u = a v then 0 else μ ω i a) ∂ν := by + let μ' : (i : I) → (B i → Bool) → ℝ := fun i a => ∫ ω, μ ω i a ∂ν + have hμ' : ∀ i a, 0 ≤ μ' i a := fun i a => integral_nonneg (fun ω => hμ ω i a) + have hm' : ∀ i, (∑ a, μ' i a) = m := by + intro i + dsimp only [μ'] + rw [← integral_finsetSum _ (fun a _ => hint i a)] + simp only [hmass,integral_const,probReal_univ,one_smul] + have hc' : ∀ i j, T.Adj i j → ∀ c, + marginal (BagLabels.leftTrace B i j) (μ' i) c = + marginal (BagLabels.rightTrace B i j) (μ' j) c := by + intro i j hij c + rw [marginal_integral ν _ _ (hint i),marginal_integral ν _ _ (hint j)] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => hcons ω i j hij c) + have hf' : ∀ i a, μ' i (BagLabels.flip (B i) a) = μ' i a := by + intro i a + exact integral_congr_ae (Filter.Eventually.of_forall (fun ω => hflip ω i a)) + obtain ⟨ρ,hρ,hρmass,hρflip,hρlocal,hρpath,n,Φ,hΦ⟩ := + BagLabels.canonical_gluing T hT B hcover hrun μ' m hm hμ' hm' hc' hf' + refine ⟨ρ,hρ,hρmass,hρflip,hρlocal,hρpath,n,Φ,hΦ,?_⟩ + intro i u v + rw [hΦ] + have ht := marginal_test (fun ω => BagLabels.restrict B ω i) ρ + (fun a => if a u = a v then (0:ℝ) else 1) + simp only [hρlocal,mul_ite,mul_zero,mul_one] at ht + have he : cutDistance ρ (fun ω => ω) u.val v.val = + ∑ a, if a u = a v then 0 else μ' i a := by + rw [ht] + rfl + rw [he] + rw [integral_finsetSum _ (fun a _ => if hab : a u = a v then + by simp only [hab,↓reduceIte]; exact integrable_const 0 else + by simpa only [hab,↓reduceIte] using hint i a)] + apply Finset.sum_congr rfl + intro a ha + split_ifs <;> simp [μ'] + +end BoundedTreewidthL1.ParticleLaws + +namespace BoundedTreewidthL1.ParticleLaws +open MeasureTheory Set +open scoped BigOperators ENNReal +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I J Ω : Type*} [Fintype V] [Fintype I] [Fintype J] + [DecidableEq V] [MeasurableSpace Ω] + +/-- Realization of the averaged prepared particle laws, with exact local +average gaps. Neither global random-law choice nor global consistency is +postulated. This interface applies to the actual measurable tree preparation. -/ +theorem averaged_particle_realization + (G : SimpleGraph V) (hG : G.Connected) (ℓ : G.edgeSet → ℝ) (hℓ : ∀ e, 0 < ℓ e) + (T : SimpleGraph I) (hT : T.IsTree) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) + (hedge : ∀ u v, G.Adj u v → ∃ i, u ∈ B i ∧ v ∈ B i) + (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (ν : Measure Ω) [IsProbabilityMeasure ν] + (L H Δ : ℝ) (hL : 0 < L) (hH : 0 < H) (hΔ : 0 < Δ) + (hN : 1 ≤ Fintype.card J) (F : Ω → I → J → V → ℝ) + (hmeas : ∀ i j v, Measurable (fun ω => F ω i j v)) + (hF : ∀ ω i, FunctionParticleReachable (shortestPathDistance G ℓ) L H (F ω i)) + (hcons : ∀ ω i j, T.Adj i j → + particleTrace (H*((Fintype.card J : ℝ)-1)+2*Δ) (F ω i) (B i ∩ B j) = + particleTrace (H*((Fintype.card J : ℝ)-1)+2*Δ) (F ω j) (B i ∩ B j)) : + ∃ n : ℕ, ∃ Φ : V → PiLp (1 : ENNReal) (fun _ : Fin n => ℝ), + (∀ u v, ‖Φ u - Φ v‖ ≤ + (Fintype.card J : ℝ)*L*((Fintype.card J : ℝ)-1)*shortestPathDistance G ℓ u v) ∧ + ∀ i (u v : B i), ‖Φ u.val - Φ v.val‖ = ∫ ω, (∑ j, |F ω i j u - F ω i j v|) ∂ν := by + let : Nonempty J := Fintype.card_pos_iff.mp (by omega) + let : MeasurableSpace J := ⊤ + let : MeasurableSingletonClass J := ⟨fun _ => trivial⟩ + let M := H*((Fintype.card J : ℝ)-1)+2*Δ + have hn : (1 : ℝ) ≤ Fintype.card J := by exact_mod_cast hN + have hM : 0 < M := by + dsimp [M] + have := mul_nonneg hH.le (sub_nonneg.mpr hn) + linarith + let μ : Ω → (i : I) → (B i → Bool) → ℝ := + fun ω i a => (particleTrace M (F ω i) (B i)).real {a} + have hm : 0 < 2*(Fintype.card J : ℝ)*M := by positivity + have hmass : ∀ ω i, (∑ a, μ ω i a) = 2*(Fintype.card J : ℝ)*M := by + intro ω i + dsimp only [μ] + rw [sum_measureReal_singleton] + simpa only [Finset.coe_univ] using trace_mass M hM.le (F ω i) (B i) + have hi : ∀ i a, Integrable (fun ω => μ ω i a) ν := by + intro i a + exact ParticleSchedule.integrable_particleTrace_real M hM.le (fun ω => F ω i) (hmeas i) (B i) {a} ν + have hc : ∀ ω i j, T.Adj i j → ∀ c, + marginal (BagLabels.leftTrace (fun i => (B i : Set V)) i j) (μ ω i) c = + marginal (BagLabels.rightTrace (fun i => (B i : Set V)) i j) (μ ω j) c := by + intro ω i j hij + exact overlapping_traces M B (F ω) i j (hcons ω i j hij) + have hf : ∀ ω i a, μ ω i (BagLabels.flip (B i) a) = μ ω i a := by + intro ω i a + exact flip_point_mass (particleTrace M (F ω i) (B i)) (trace_flip M (F ω i) (B i)) a + have hn_set : ∀ ω i, (∑ a : ↥((fun i => (B i : Set V)) i) → Bool, μ ω i a) = + 2*(Fintype.card J : ℝ)*M := by + intro ω i + convert! hmass ω i using 1 + have hμ : ∀ ω i a, 0 ≤ μ ω i a := by intro ω i a; exact measureReal_nonneg + generalize hdef : μ = μ' at hμ hmass hc hf hi hn_set + obtain ⟨ρ,hρ,hρmass,hρflip,hρlocal,hρpath,n,Φ,hΦ,hlocal⟩ := + averaged_bag_realization T hT (fun i => (B i : Set V)) hcover hrun ν μ' + (2*(Fintype.card J : ℝ)*M) hm hμ + (by intro ω i; convert! hn_set ω i using 1 ; congr 1 ; first | exact Subsingleton.elim _ _ | (ext; simp only [Finset.mem_univ])) + hi (by intro ω i j hij c; convert! hc ω i j hij c using 1 <;> congr 1 <;> exact Subsingleton.elim _ _) hf + have hheight (ω : Ω) (i : I) (j : J) (v : V) : |F ω i j v| ≤ M := by + have := function_particles_height_bound hH (hF ω i) j v + dsimp [M] + linarith + have heq : ∀ i (u v : B i), ‖Φ u.val - Φ v.val‖ = + ∫ ω, (∑ j, |F ω i j u - F ω i j v|) ∂ν := by + intro i u v + rw [hlocal,← hdef] + apply integral_congr_ae + apply Filter.Eventually.of_forall + intro ω + dsimp only [μ] + have hx : (∑ a : B i → Bool, + if a u = a v then 0 else (particleTrace M (F ω i) (B i)).real {a}) = + ∑ j, |F ω i j u - F ω i j v| := by + have hs := singleton_sum (particleTrace M (F ω i) (B i)) {a | a u ≠ a v} + simp only [Set.mem_ofPred_eq, Classical.ite_not] at hs + have heq : (∑ a : B i → Bool, + if a u = a v then 0 else (particleTrace M (F ω i) (B i)).real {a}) = + (particleTrace M (F ω i) (B i)).real {a | a u ≠ a v} := by + convert! hs using 1 + apply Finset.sum_congr rfl + intro label _ + split_ifs <;> rfl + rw [heq] + change cutSeparation (particleTrace M (F ω i) (B i)) u v = _ + rw [trace_separation,particle_separation M (F ω i) (hheight ω i)] + convert! hx using 1 ; congr 1 ; first | exact Subsingleton.elim _ _ | (ext; simp only [Finset.mem_univ]) + refine ⟨n,Φ,?_,heq⟩ + apply norm_bound_from_edges G hG ℓ _ Φ + intro u v huv + obtain ⟨i,hu,hv⟩ := hedge u v huv + rw [heq i ⟨u,hu⟩ ⟨v,hv⟩] + have hsum (ω : Ω) : (∑ j, |F ω i j u - F ω i j v|) ≤ + (Fintype.card J : ℝ)*L*((Fintype.card J : ℝ)-1)*ℓ ⟨s(u,v),huv⟩ := by + have hd := shortestPathDistance_pos G ℓ hG hℓ huv.ne + calc + (∑ j, |F ω i j u - F ω i j v|) ≤ + ∑ j : J, L*((Fintype.card J : ℝ)-1)*shortestPathDistance G ℓ u v := + Finset.sum_le_sum (fun j _ => function_particles_difference_bound hL (hF ω i) j u v hd) + _ = (Fintype.card J : ℝ)*L*((Fintype.card J : ℝ)-1)*shortestPathDistance G ℓ u v := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left ?_ (by positivity) + have he := shortestPathDistance_le_walkLength G ℓ (fun e => (hℓ e).le) huv.toWalk + simpa [SimpleGraph.Adj.toWalk,walkLength] using he + apply (le_abs_self _).trans + change ‖∫ ω, (∑ j, |F ω i j u - F ω i j v|) ∂ν‖ ≤ _ + have hb := norm_integral_le_of_norm_le_const (μ := ν) + (Filter.Eventually.of_forall (fun ω => show ‖∑ j, |F ω i j u - F ω i j v|‖ ≤ _ from by + rw [Real.norm_eq_abs,abs_of_nonneg (Finset.sum_nonneg (fun j _ => abs_nonneg _))] + exact hsum ω)) + simpa only [probReal_univ,mul_one] using hb +end BoundedTreewidthL1.ParticleLaws + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/Particles.lean b/lean/OAI/Combinatorics/TreewidthL1/Particles.lean new file mode 100644 index 0000000000000000000000000000000000000000..05258bd1797a4162b936f4843c3051bf80e91ce3 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/Particles.lean @@ -0,0 +1,1209 @@ +import OAI.Combinatorics.TreewidthL1.Cuts + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 + +namespace BoundedTreewidthL1 + +section ParticleInvariant + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def pairUpdate (a : ι → ℝ) (i j : ι) (e : ℝ) (x : ι) : ℝ := + a x + (if x = i then (a i + a j) / 2 + e - a i else 0) + + (if x = j then (a i + a j) / 2 - e - a j else 0) + +/-- Finite update histories; there is no bound on the number of updates. -/ +inductive ParticleReachable : (ι → ℝ) → Prop + | zero : ParticleReachable (fun _ => 0) + | step {a : ι → ℝ} (ha : ParticleReachable a) + (i j : ι) (hij : i ≠ j) (e : ℝ) (he : |e| ≤ 1) : + ParticleReachable (pairUpdate a i j e) + +/-- The quadratic subset-sum invariant controlling particle bounds. +Subtractions are real. In particular the bound at the full set is exactly zero. -/ +def ParticleInvariant (a : ι → ℝ) : Prop := + (∑ i, a i) = 0 ∧ ∀ I : Finset ι, + (∑ i ∈ I, a i) ≤ (I.card : ℝ) * ((Fintype.card ι : ℝ) - I.card) + +end ParticleInvariant + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 + +section ParticleInvariantProof + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma sum_pairUpdate + {ι : Type treewidthLevel1} [Fintype ι] [DecidableEq ι] + (a : ι → ℝ) (i j : ι) (e : ℝ) (I : Finset ι) : + (∑ x ∈ I, pairUpdate a i j e x) = + (∑ x ∈ I, a x) + + (if i ∈ I then (a i + a j) / 2 + e - a i else 0) + + (if j ∈ I then (a i + a j) / 2 - e - a j else 0) := by + simp [pairUpdate, Finset.sum_add_distrib] + +lemma pairUpdate_swap + {ι : Type treewidthLevel1} [Fintype ι] [DecidableEq ι] + (a : ι → ℝ) (i j : ι) (e : ℝ) : + pairUpdate a i j e = pairUpdate a j i (-e) := by + funext x + simp only [pairUpdate] + split_ifs <;> ring + +lemma ParticleInvariant.zero + {ι : Type treewidthLevel1} [Fintype ι] [DecidableEq ι] : ParticleInvariant (fun _ : ι => 0) := by + constructor + · simp + · intro I + simp only [Finset.sum_const_zero] + exact mul_nonneg (Nat.cast_nonneg _) + (sub_nonneg.mpr (by exact_mod_cast Finset.card_le_univ I)) + +lemma ParticleInvariant.update_one {a : ι → ℝ} (ha : ParticleInvariant a) + (i j : ι) (e : ℝ) (he : e ≤ 1) (I : Finset ι) + (hi : i ∈ I) (hj : j ∉ I) : + (∑ x ∈ I, pairUpdate a i j e x) ≤ + (I.card : ℝ) * ((Fintype.card ι : ℝ) - I.card) := by + have hsmall := ha.2 (I.erase i) + have hlarge := ha.2 (insert j I) + have hsumsmall := Finset.sum_erase_add I a hi + have hsumlarge := Finset.sum_insert (f := a) hj + have hcsmall : ((I.erase i).card : ℝ) = (I.card : ℝ) - 1 := by + have hc := Finset.card_erase_add_one hi + have hcast : ((I.erase i).card : ℝ) + 1 = (I.card : ℝ) := by exact_mod_cast hc + linarith + have hclarge : ((insert j I).card : ℝ) = (I.card : ℝ) + 1 := by + rw [Finset.card_insert_of_notMem hj] + norm_cast + rw [hcsmall] at hsmall + rw [hclarge] at hlarge + rw [sum_pairUpdate, ite_eq_left hi, ite_eq_right hj] + nlinarith + +lemma ParticleInvariant.update {a : ι → ℝ} (ha : ParticleInvariant a) + (i j : ι) (_ : i ≠ j) (e : ℝ) (he : |e| ≤ 1) : + ParticleInvariant (pairUpdate a i j e) := by + constructor + · rw [sum_pairUpdate] + simp only [Finset.mem_univ, ↓reduceIte, ha.1] + ring + · intro I + by_cases hi : i ∈ I + · by_cases hj : j ∈ I + · rw [sum_pairUpdate, ite_eq_left hi, ite_eq_left hj] + have hI := ha.2 I + linarith + · exact ha.update_one i j e (abs_le.mp he).2 I hi hj + · by_cases hj : j ∈ I + · rw [pairUpdate_swap] + exact ha.update_one j i (-e) (by have := (abs_le.mp he).1; linarith) I hj hi + · simpa [sum_pairUpdate, hi, hj] using ha.2 I + +theorem particle_reachable_invariant {a : ι → ℝ} (ha : ParticleReachable a) : + ParticleInvariant a := by + induction ha with + | zero => exact ParticleInvariant.zero + | step ha i j hij e he ih => exact ih.update i j hij e he + +/-- Exact scalar bound used for the slopes AND absolute heights of particles. -/ +theorem particle_reachable_abs_le {a : ι → ℝ} (ha : ParticleReachable a) (i : ι) : + |a i| ≤ (Fintype.card ι : ℝ) - 1 := by + have h := particle_reachable_invariant ha + have hi := h.2 {i} + have hc := h.2 (Finset.univ.erase i) + have hsum := Finset.sum_erase_add Finset.univ a (Finset.mem_univ i) + have hcard : ((Finset.univ.erase i).card : ℝ) = (Fintype.card ι : ℝ) - 1 := by + have ht := Finset.card_erase_add_one (Finset.mem_univ i) + simp only [Finset.card_univ] at ht + have hcast : ((Finset.univ.erase i).card : ℝ) + 1 = (Fintype.card ι : ℝ) := by + exact_mod_cast ht + linarith + simp only [Finset.sum_singleton, Finset.card_singleton, Nat.cast_one, one_mul] at hi + rw [hcard] at hc + rw [h.1] at hsum + exact abs_le.mpr ⟨by nlinarith, hi⟩ + +end ParticleInvariantProof + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 + +section FunctionParticles + +variable {ι V : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def functionPairUpdate (F : ι → V → ℝ) (i j : ι) (g : V → ℝ) : + ι → V → ℝ := + fun x v => pairUpdate (fun t => F t v) i j (g v) x + +inductive FunctionParticleReachable (d : V → V → ℝ) (L H : ℝ) : + (ι → V → ℝ) → Prop + | zero : FunctionParticleReachable d L H (fun _ _ => 0) + | step {F : ι → V → ℝ} (hF : FunctionParticleReachable d L H F) + (i j : ι) (hij : i ≠ j) (g : V → ℝ) + (hLip : ∀ u v, |g u - g v| ≤ L * d u v) + (hHeight : ∀ v, |g v| ≤ H) : + FunctionParticleReachable d L H (functionPairUpdate F i j g) + +lemma functionPairUpdate_left + {ι : Type treewidthLevel1} {V : Type treewidthLevel2} [Fintype ι] [DecidableEq ι] + (F : ι → V → ℝ) (i j : ι) (hij : i ≠ j) + (g : V → ℝ) (v : V) : + functionPairUpdate F i j g i v = (F i v + F j v) / 2 + g v := by + simp [functionPairUpdate, pairUpdate, hij] + +lemma functionPairUpdate_right + {ι : Type treewidthLevel1} {V : Type treewidthLevel2} [Fintype ι] [DecidableEq ι] + (F : ι → V → ℝ) (i j : ι) (hij : i ≠ j) + (g : V → ℝ) (v : V) : + functionPairUpdate F i j g j v = (F i v + F j v) / 2 - g v := by + simp [functionPairUpdate, pairUpdate, Ne.symm hij] + +lemma functionPairUpdate_other + {ι : Type treewidthLevel1} {V : Type treewidthLevel2} [Fintype ι] [DecidableEq ι] + (F : ι → V → ℝ) (i j x : ι) + (hxi : x ≠ i) (hxj : x ≠ j) (g : V → ℝ) (v : V) : + functionPairUpdate F i j g x v = F x v := by + simp [functionPairUpdate, pairUpdate, hxi, hxj] + +lemma functionPairUpdate_value_normalized + {ι : Type treewidthLevel1} {V : Type treewidthLevel2} [Fintype ι] [DecidableEq ι] + (F : ι → V → ℝ) (i j : ι) + (g : V → ℝ) (v : V) (R : ℝ) : + (fun x => functionPairUpdate F i j g x v / R) = + pairUpdate (fun x => F x v / R) i j (g v / R) := by + funext x + simp only [functionPairUpdate, pairUpdate] + split_ifs <;> ring + +lemma functionPairUpdate_difference_normalized + {ι : Type treewidthLevel1} {V : Type treewidthLevel2} [Fintype ι] [DecidableEq ι] + (F : ι → V → ℝ) (i j : ι) + (g : V → ℝ) (u v : V) (R : ℝ) : + (fun x => (functionPairUpdate F i j g x u - + functionPairUpdate F i j g x v) / R) = + pairUpdate (fun x => (F x u - F x v) / R) i j ((g u - g v) / R) := by + funext x + simp only [functionPairUpdate, pairUpdate] + split_ifs <;> ring + +lemma function_particles_normalized_values {d : V → V → ℝ} {L H : ℝ} + (hH : 0 < H) {F : ι → V → ℝ} (hF : FunctionParticleReachable d L H F) + (v : V) : ParticleReachable (fun x => F x v / H) := by + induction hF with + | zero => simpa using (ParticleReachable.zero (ι := ι)) + | step hF i j hij g hLip hHeight ih => + rw [functionPairUpdate_value_normalized] + apply ParticleReachable.step ih i j hij + rw [abs_div, abs_of_pos hH] + exact (div_le_one hH).mpr (hHeight v) + +lemma function_particles_normalized_differences {d : V → V → ℝ} {L H : ℝ} + {F : ι → V → ℝ} (hF : FunctionParticleReachable d L H F) + (u v : V) (hR : 0 < L * d u v) : + ParticleReachable (fun x => (F x u - F x v) / (L * d u v)) := by + induction hF with + | zero => simpa using (ParticleReachable.zero (ι := ι)) + | step hF i j hij g hLip hHeight ih => + rw [functionPairUpdate_difference_normalized] + apply ParticleReachable.step ih i j hij + rw [abs_div, abs_of_pos hR] + exact (div_le_one hR).mpr (hLip u v) + +theorem function_particles_height_bound {d : V → V → ℝ} {L H : ℝ} + (hH : 0 < H) {F : ι → V → ℝ} (hF : FunctionParticleReachable d L H F) + (i : ι) (v : V) : |F i v| ≤ H * ((Fintype.card ι : ℝ) - 1) := by + have hb := particle_reachable_abs_le (function_particles_normalized_values hH hF v) i + rw [abs_div, abs_of_pos hH] at hb + simpa [mul_comm] using (div_le_iff₀ hH).mp hb + +theorem function_particles_difference_bound {d : V → V → ℝ} {L H : ℝ} + (hL : 0 < L) {F : ι → V → ℝ} (hF : FunctionParticleReachable d L H F) + (i : ι) (u v : V) (hd : 0 < d u v) : + |F i u - F i v| ≤ L * ((Fintype.card ι : ℝ) - 1) * d u v := by + have hR := mul_pos hL hd + have hb := particle_reachable_abs_le (function_particles_normalized_differences hF u v hR) i + rw [abs_div, abs_of_pos hR] at hb + simpa [mul_assoc, mul_comm, mul_left_comm] using (div_le_iff₀ hR).mp hb + +theorem function_particles_metric_bound [MetricSpace V] {L H : ℝ} + (hL : 0 < L) {F : ι → V → ℝ} (hF : FunctionParticleReachable dist L H F) + (i : ι) (u v : V) : + |F i u - F i v| ≤ L * ((Fintype.card ι : ℝ) - 1) * dist u v := by + by_cases huv : u = v + · simp [huv] + · exact function_particles_difference_bound hL hF i u v (dist_pos.mpr huv) + +end FunctionParticles + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open MeasureTheory +open scoped ENNReal +variable {V ι : Type*} [Fintype V] [Fintype ι] [DecidableEq ι] + +/-- The exact zero-error combined symmetric trace carried by a particle list. -/ +noncomputable def particleTrace (M : ℝ) (F : ι → V → ℝ) (P : Finset V) : + Measure (P → Bool) := ∑ i, cutTrace (symmetrizeCut (sweep M (F i))) P + +/-- Any reservation set of size at most `2q` +leaves two particles with a common weak order, and the actual affine update +preserves the complete bag law and every reserved function. The pair is chosen +before the perturbation; the universal quantifier on g expresses that fact. -/ +lemma exists_weak_order + {V : Type treewidthLevel1} [Fintype V] + (P : Finset V) (F : V → ℝ) : + ∃ e : Fin P.card ≃ P, Monotone (fun i => F (e i)) := by + classical + let code := Fintype.equivFin P + let enc : P → Lex (ℝ × Fin (Fintype.card P)) := fun p => toLex (F p, code p) + have hinj : Function.Injective enc := by + intro p q h + exact code.injective (congrArg (fun z : Lex (ℝ × Fin (Fintype.card P)) => (ofLex z).2) h) + let : LinearOrder P := LinearOrder.lift' enc hinj + let e := Fintype.orderIsoFinOfCardEq P (by simp : Fintype.card P = P.card) + refine ⟨e.toEquiv, ?_⟩ + intro i j hij + have h := e.monotone hij + change enc (e i) ≤ enc (e j) at h + rcases Prod.Lex.le_iff.mp h with h | ⟨h, _⟩ + · exact h.le + · exact h.le + +lemma free_common_order (k q : ℕ) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (P : Finset V) (hP : P.card ≤ k) (R : Finset ι) (hR : R.card ≤ 2*q) + (F : ι → V → ℝ) : + ∃ i j : ι, i ∉ R ∧ j ∉ R ∧ i ≠ j ∧ CommonWeakOrder P (F i) (F j) := by + classical + let S := Finset.univ \ R + have hc : k.factorial < S.card := by + have hs : S.card + R.card = Fintype.card ι := by + simpa [S] using Finset.card_sdiff_add_card_inter Finset.univ R + omega + choose order horder using fun i : S => exists_weak_order P (F i) + have hcard : Fintype.card (Fin P.card ≃ P) < Fintype.card S := by + rw [Fintype.card_equiv (Fintype.equivOfCardEq (by simp) : Fin P.card ≃ P)] + simpa using (Nat.factorial_le hP).trans_lt hc + obtain ⟨i, j, hij, heq⟩ := Fintype.exists_ne_map_eq_of_card_lt order hcard + refine ⟨i, j, (Finset.mem_sdiff.mp i.property).2, + (Finset.mem_sdiff.mp j.property).2, ?_, order i, horder i, ?_⟩ + · exact fun h => hij (Subtype.ext h) + · rw [heq] + exact horder j + +lemma cutTrace_symmetrize (μ : Measure (V → Bool)) (P : Finset V) : + cutTrace (symmetrizeCut μ) P = symmetrizeCut (cutTrace μ P) := by + classical + unfold cutTrace symmetrizeCut + rw [Measure.map_smul _ (measurable_of_finite _).aemeasurable, Measure.map_add _ _ (measurable_of_finite _), + Measure.map_map (measurable_of_finite _) measurable_complementCut, + Measure.map_map measurable_complementCut (measurable_of_finite _)] + rfl + +lemma symmetrize_add (μ ν : Measure (V → Bool)) : + symmetrizeCut (μ + ν) = symmetrizeCut μ + symmetrizeCut ν := by + unfold symmetrizeCut + rw [Measure.map_add _ _ measurable_complementCut] + simp [smul_add, add_assoc, add_left_comm] + +lemma sum_eq_of_pair {A : Type*} [AddCommMonoid A] (a b : ι → A) + (i j : ι) (hij : i ≠ j) (hpair : a i + a j = b i + b j) + (hother : ∀ r, r ≠ i → r ≠ j → a r = b r) : (∑ r, a r) = ∑ r, b r := by + classical + let S : Finset ι := {i,j} + have hs : (∑ r ∈ S, a r) = ∑ r ∈ S, b r := by + simpa [S, hij] using hpair + have ht : (∑ r ∈ Sᶜ, a r) = ∑ r ∈ Sᶜ, b r := by + apply Finset.sum_congr rfl + intro r hr + have hr' : r ≠ i ∧ r ≠ j := by simpa [S] using hr + exact hother r hr'.1 hr'.2 + rw [← Finset.sum_add_sum_compl S a, ←Finset.sum_add_sum_compl S b, hs, ht] + +lemma particleTrace_update (M : ℝ) (hM : 0 < M) (F : ι → V → ℝ) + (i j : ι) (hij : i ≠ j) (g : V → ℝ) (P : Finset V) + (horder : CommonWeakOrder P (F i) (F j)) (hg : ∀ s ∈ P, g s = 0) + (hF : ∀ r v, |F r v| ≤ M) + (hF' : ∀ r v, |functionPairUpdate F i j g r v| ≤ M) : + particleTrace M F P = particleTrace M (functionPairUpdate F i j g) P := by + apply sum_eq_of_pair _ _ i j hij + · simp only [cutTrace_symmetrize, ←symmetrize_add, ←cutTrace_add] + apply congrArg symmetrizeCut + have hi : functionPairUpdate F i j g i = fun v => (F i v + F j v)/2 + g v := by + funext v; exact functionPairUpdate_left F i j hij g v + have hj : functionPairUpdate F i j g j = fun v => (F i v + F j v)/2 - g v := by + funext v; exact functionPairUpdate_right F i j hij g v + rw [hi, hj] + exact sweep_trace_update M hM (F i) (F j) g P horder hg (hF i) (hF j) + (by simpa only [hi] using hF' i) (by simpa only [hj] using hF' j) + · intro r hri hrj + have hr : functionPairUpdate F i j g r = F r := by + funext v; exact functionPairUpdate_other F i j r hri hrj g v + rw [hr] + +theorem particle_step_realization (k q : ℕ) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (P : Finset V) (hP : P.card ≤ k) (R : Finset ι) (hR : R.card ≤ 2*q) + (d : V → V → ℝ) (L H Δ : ℝ) (hH : 0 < H) (hΔ : 0 < Δ) + (F : ι → V → ℝ) (hF : FunctionParticleReachable d L H F) : + ∃ i j : ι, i ∉ R ∧ j ∉ R ∧ i ≠ j ∧ CommonWeakOrder P (F i) (F j) ∧ + ∀ g : V → ℝ, (∀ u v, |g u - g v| ≤ L * d u v) → + (∀ v, |g v| ≤ H) → (∀ s ∈ P, g s = 0) → + let F' := functionPairUpdate F i j g + let M := H * ((Fintype.card ι : ℝ)-1) + 2*Δ + FunctionParticleReachable d L H F' ∧ + (∀ r ∈ R, F' r = F r) ∧ + particleTrace M F P = particleTrace M F' P ∧ + (∀ r v, |F' r v| + 2*Δ ≤ M) := by + classical + obtain ⟨i, j, hi, hj, hij, ho⟩ := free_common_order k q hN P hP R hR F + refine ⟨i, j, hi, hj, hij, ho, ?_⟩ + intro g hLip hHeight hg + dsimp only + have hF' := FunctionParticleReachable.step hF i j hij g hLip hHeight + have hmarg : ∀ r v, |functionPairUpdate F i j g r v| + 2*Δ ≤ + H * ((Fintype.card ι : ℝ)-1) + 2*Δ := by + intro r v + have := function_particles_height_bound hH hF' r v + linarith + refine ⟨hF', ?_, ?_, hmarg⟩ + · intro r hr + funext v + exact functionPairUpdate_other F i j r (fun h => hi (h ▸ hr)) + (fun h => hj (h ▸ hr)) g v + · have hcard : (1 : ℝ) ≤ Fintype.card ι := by + have hn : 1 ≤ Fintype.card ι := by omega + exact_mod_cast hn + have hM : 0 < H * ((Fintype.card ι : ℝ)-1) + 2*Δ := by + have := mul_nonneg hH.le (sub_nonneg.mpr hcard) + linarith + apply particleTrace_update _ hM F i j hij g P ho hg + · intro r v + have := function_particles_height_bound hH hF r v + linarith + · intro r v + have := function_particles_height_bound hH hF' r v + linarith +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 + +structure ReservationPath where + last : ℕ + finish : ℕ → ℕ + launch_le_finish : ∀ a, a ≤ last → a ≤ finish a + finish_le_last : ∀ a, a ≤ last → finish a ≤ last + one_release : ∀ a b t, a ≤ t → b ≤ t → t < last → + finish a = t → finish b = t → a = b + root_permanent : finish 0 = last +namespace ReservationPath +noncomputable def inclusive (P : ReservationPath) (t : ℕ) : Finset ℕ := by + classical + exact if t ≤ P.last then (Finset.range (t + 1)).filter (fun a => t ≤ P.finish a) else ∅ +end ReservationPath +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.ParticleSchedule +open MeasureTheory +variable {V ι : Type*} [Fintype V] [Fintype ι] [DecidableEq ι] [Nonempty ι] + +noncomputable def before (R : ReservationPath) (t : ℕ) : Finset ℕ := + (R.inclusive t).filter (fun a => a < t) + +noncomputable def occupied (C : Finset ℕ) (p : ℕ → ι × ι) : Finset ι := by + classical + exact C.image (fun a => (p a).1) ∪ C.image (fun a => (p a).2) + +/-- A deterministic pair selection using only pre-launch data. Classical choice +here is a fixed function of the finite eligible-pair set, not of the fresh noise. -/ +noncomputable def pickPair (P : Finset V) (C : Finset ι) (F : ι → V → ℝ) : ι × ι := by + classical + exact if h : ∃ p : ι × ι, p.1 ∉ C ∧ p.2 ∉ C ∧ p.1 ≠ p.2 ∧ + CommonWeakOrder P (F p.1) (F p.2) then h.choose + else (Classical.choice inferInstance, Classical.choice inferInstance) + +def RunEquations (R : ReservationPath) (P : ℕ → Finset V) (g : ℕ → V → ℝ) + (n : ℕ) (F : ℕ → ι → V → ℝ) (p : ℕ → ι × ι) : Prop := + F 0 = (fun _ _ => 0) ∧ ∀ t < n, + p t = pickPair (P t) (occupied (before R t) p) (F t) ∧ + F (t+1) = functionPairUpdate (F t) (p t).1 (p t).2 (g t) + +lemma occupied_card + {ι : Type treewidthLevel1} [Fintype ι] [DecidableEq ι] [Nonempty ι] + (C : Finset ℕ) (p : ℕ → ι × ι) : + (occupied C p).card ≤ 2*C.card := by + classical + exact (Finset.card_union_le _ _).trans (by + have h1 := Finset.card_image_le (s := C) (f := fun a => (p a).1) + have h2 := Finset.card_image_le (s := C) (f := fun a => (p a).2) + omega) + +lemma occupied_update + {ι : Type treewidthLevel1} [Fintype ι] [DecidableEq ι] [Nonempty ι] + {C : Finset ℕ} (p : ℕ → ι × ι) (n : ℕ) (z : ι × ι) + (hn : ∀ a ∈ C, a < n) : occupied C (Function.update p n z) = occupied C p := by + classical + unfold occupied + congr 1 <;> apply Finset.image_congr <;> intro a ha <;> + simp [Function.update_of_ne (ne_of_lt (hn a ha))] + +lemma pickPair_spec (k q : ℕ) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (P : Finset V) (hP : P.card ≤ k) (C : Finset ι) (hC : C.card ≤ 2*q) + (F : ι → V → ℝ) : + let z := pickPair P C F + z.1 ∉ C ∧ z.2 ∉ C ∧ z.1 ≠ z.2 ∧ CommonWeakOrder P (F z.1) (F z.2) := by + classical + obtain ⟨i,j,hi,hj,hij,ho⟩ := free_common_order k q hN P hP C hC F + have hex : ∃ p : ι × ι, p.1 ∉ C ∧ p.2 ∉ C ∧ p.1 ≠ p.2 ∧ + CommonWeakOrder P (F p.1) (F p.2) := ⟨(i,j),hi,hj,hij,ho⟩ + simpa only [pickPair,dite_eq_left hex] using hex.choose_spec + +lemma finite_run + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] [DecidableEq ι] + [Nonempty ι] + (R : ReservationPath) (P : ℕ → Finset V) (g : ℕ → V → ℝ) (n : ℕ) : + ∃ F : ℕ → ι → V → ℝ, ∃ p : ℕ → ι × ι, RunEquations R P g n F p := by + classical + induction n with + | zero => + exact ⟨fun _ _ _ => 0, fun _ => (Classical.choice inferInstance,Classical.choice inferInstance), + rfl,fun t ht => (Nat.not_lt_zero t ht).elim⟩ + | succ n ih => + obtain ⟨F,p,hzero,hsteps⟩ := ih + let z := pickPair (P n) (occupied (before R n) p) (F n) + let p' := Function.update p n z + let F' := Function.update F (n+1) (functionPairUpdate (F n) z.1 z.2 (g n)) + refine ⟨F',p',?_,?_⟩ + · simpa [F'] using hzero + · intro t ht + have htn : t ≤ n := Nat.le_of_lt_succ ht + have hoc : occupied (before R t) p' = occupied (before R t) p := by + apply occupied_update + intro a ha + exact (Finset.mem_filter.mp ha).2.trans_le htn + rw [hoc] + by_cases hte : t = n + · subst t + simp [p',F',z] + · have htn' : t < n := lt_of_le_of_ne htn hte + have hne₁ : t ≠ n+1 := by omega + have hne₂ : t+1 ≠ n+1 := by omega + simpa only [p',F',Function.update_of_ne hte,Function.update_of_ne hne₁, + Function.update_of_ne hne₂] using hsteps t htn' + +theorem scheduled_particle_realization (R : ReservationPath) + (k q : ℕ) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (P : ℕ → Finset V) (hP : ∀ t ≤ R.last, (P t).card ≤ k) + (hsize : ∀ t, (R.inclusive t).card ≤ q) + (d : V → V → ℝ) (L H Δ : ℝ) (hH : 0 < H) (hΔ : 0 < Δ) + (g : ℕ → V → ℝ) + (hLip : ∀ t ≤ R.last, ∀ u v, |g t u - g t v| ≤ L * d u v) + (hHeight : ∀ t ≤ R.last, ∀ v, |g t v| ≤ H) + (hvanish : ∀ t ≤ R.last, ∀ v ∈ P t, g t v = 0) : + ∃ F : ℕ → ι → V → ℝ, ∃ p : ℕ → ι × ι, + RunEquations R P g (R.last+1) F p ∧ + (∀ t ≤ R.last+1, FunctionParticleReachable d L H (F t)) ∧ + (∀ t ≤ R.last, (p t).1 ≠ (p t).2 ∧ + particleTrace (H * ((Fintype.card ι : ℝ)-1) + 2*Δ) (F t) (P t) = + particleTrace (H * ((Fintype.card ι : ℝ)-1) + 2*Δ) (F (t+1)) (P t)) ∧ + (∀ t ≤ R.last, ∀ a ∈ R.inclusive t, + F (t+1) (p a).1 = F (a+1) (p a).1 ∧ + F (t+1) (p a).2 = F (a+1) (p a).2) := by + classical + obtain ⟨F,p,hrun⟩ := finite_run (ι := ι) R P g (R.last+1) + have hs (t : ℕ) (ht : t ≤ R.last) : + (p t).1 ∉ occupied (before R t) p ∧ (p t).2 ∉ occupied (before R t) p ∧ + (p t).1 ≠ (p t).2 ∧ CommonWeakOrder (P t) (F t (p t).1) (F t (p t).2) := by + have hc : (occupied (before R t) p).card ≤ 2*q := by + have h1 := occupied_card (before R t) p + have h2 : (before R t).card ≤ (R.inclusive t).card := Finset.card_filter_le _ _ + have h3 := hsize t + omega + have hh := pickPair_spec k q hN (P t) (hP t ht) (occupied (before R t) p) hc (F t) + dsimp only at hh + rw [← (hrun.2 t (by omega)).1] at hh + exact hh + have hreach : ∀ t ≤ R.last+1, FunctionParticleReachable d L H (F t) := by + intro t + induction t with + | zero => intro _; rw [hrun.1]; exact .zero + | succ t ih => + intro ht + have htL : t ≤ R.last := by omega + rw [(hrun.2 t (by omega)).2] + exact .step (ih (by omega)) _ _ (hs t htL).2.2.1 (g t) (hLip t htL) (hHeight t htL) + have hretain (t : ℕ) (ht : t ≤ R.last) (a : ℕ) (ha : a ∈ R.inclusive t) (hat : a < t) : + F (t+1) (p a).1 = F t (p a).1 ∧ F (t+1) (p a).2 = F t (p a).2 := by + have hab : a ∈ before R t := Finset.mem_filter.mpr ⟨ha,hat⟩ + have h1 : (p a).1 ∈ occupied (before R t) p := + Finset.mem_union_left _ (Finset.mem_image.mpr ⟨a,hab,rfl⟩) + have h2 : (p a).2 ∈ occupied (before R t) p := + Finset.mem_union_right _ (Finset.mem_image.mpr ⟨a,hab,rfl⟩) + have hei (r : ι) (hr : r ∈ occupied (before R t) p) : r ≠ (p t).1 ∧ r ≠ (p t).2 := by + constructor + · intro he; exact (hs t ht).1 (he ▸ hr) + · intro he; exact (hs t ht).2.1 (he ▸ hr) + rw [(hrun.2 t (by omega)).2] + constructor <;> funext x + · exact functionPairUpdate_other _ _ _ _ (hei _ h1).1 (hei _ h1).2 _ x + · exact functionPairUpdate_other _ _ _ _ (hei _ h2).1 (hei _ h2).2 _ x + refine ⟨F,p,hrun,hreach,?_,?_⟩ + · intro t ht + refine ⟨(hs t ht).2.2.1,?_⟩ + have hc : (1 : ℝ) ≤ Fintype.card ι := by + have hh : 1 ≤ Fintype.card ι := by omega + exact_mod_cast hh + have hM : 0 < H * ((Fintype.card ι : ℝ)-1) + 2*Δ := by + have hh := mul_nonneg hH.le (sub_nonneg.mpr hc) + linarith + have hb (s : ℕ) (hsl : s ≤ R.last+1) : ∀ r x, + |F s r x| ≤ H * ((Fintype.card ι : ℝ)-1) + 2*Δ := by + intro r x + have hh := function_particles_height_bound hH (hreach s hsl) r x + linarith + rw [(hrun.2 t (by omega)).2] + apply particleTrace_update _ hM _ _ _ (hs t ht).2.2.1 _ _ (hs t ht).2.2.2 + (hvanish t ht) (hb t (by omega)) + rw [← (hrun.2 t (by omega)).2] + exact hb (t+1) (by omega) + · intro t + induction t with + | zero => + intro ht a ha + have ha0 : a = 0 := by + simpa [ReservationPath.inclusive,ht] using (Finset.mem_filter.mp + (show a ∈ (Finset.range 1).filter (fun a => 0 ≤ R.finish a) by + simpa [ReservationPath.inclusive,ht] using ha)).1 + subst a + exact ⟨rfl,rfl⟩ + | succ t ih => + intro ht a ha + have hmem : a ≤ t+1 ∧ t+1 ≤ R.finish a := by + simpa [ReservationPath.inclusive,ht,Nat.lt_succ_iff] using ha + by_cases he : a = t+1 + · subst a; exact ⟨rfl,rfl⟩ + · have hat : a < t+1 := by omega + have ht' : t ≤ R.last := by omega + have ha' : a ∈ R.inclusive t := by + simp [ReservationPath.inclusive,ht'] + omega + have hh := hretain (t+1) ht a ha hat + exact ⟨hh.1.trans (ih ht' a ha').1,hh.2.trans (ih ht' a ha').2⟩ +end BoundedTreewidthL1.ParticleSchedule + +namespace BoundedTreewidthL1.ParticleSchedule +open MeasureTheory +variable {V ι Ω : Type*} [Fintype V] [Fintype ι] [DecidableEq ι] [Nonempty ι] + [MeasurableSpace Ω] [MeasurableSpace ι] [MeasurableSingletonClass ι] + +lemma measurable_weak_order + {V : Type treewidthLevel1} {Ω : Type treewidthLevel2} [Fintype V] [MeasurableSpace Ω] + (P : Finset V) (F H : Ω → V → ℝ) + (hF : ∀ v, Measurable (fun ω => F ω v)) + (hH : ∀ v, Measurable (fun ω => H ω v)) : + MeasurableSet {ω | CommonWeakOrder P (F ω) (H ω)} := by + classical + simp only [CommonWeakOrder, Set.ofPred_exists, Set.ofPred_and] + apply MeasurableSet.iUnion + intro e + have hmono (A : Ω → V → ℝ) (hA : ∀ v, Measurable (fun ω => A ω v)) : + MeasurableSet {ω | Monotone (fun i : Fin P.card => A ω (e i))} := by + simp only [Monotone, Set.ofPred_forall] + exact MeasurableSet.iInter fun i => MeasurableSet.iInter fun j => + MeasurableSet.iInter fun _ => measurableSet_le (hA _) (hA _) + exact (hmono F hF).inter (hmono H hH) + +noncomputable def selectEligible (Q : ι × ι → Prop) : ι × ι := by + classical + exact if h : ∃ p, Q p then h.choose else + (Classical.choice inferInstance, Classical.choice inferInstance) + +lemma measurable_selectEligible + {ι : Type treewidthLevel1} [Fintype ι] [DecidableEq ι] [Nonempty ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] : Measurable (selectEligible (ι := ι)) := + measurable_of_finite _ + +lemma measurable_eligibility + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} {Ω : Type treewidthLevel3} [Fintype V] + [Fintype ι] [DecidableEq ι] [Nonempty ι] [MeasurableSpace Ω] [MeasurableSpace ι] + [MeasurableSingletonClass ι] + (P : Finset V) (C : Ω → Finset ι) (F : Ω → ι → V → ℝ) + (hC : Measurable C) (hF : ∀ i v, Measurable (fun ω => F ω i v)) : + Measurable (fun ω => fun p : ι × ι => + p.1 ∉ C ω ∧ p.2 ∉ C ω ∧ p.1 ≠ p.2 ∧ + CommonWeakOrder P (F ω p.1) (F ω p.2)) := by + classical + apply measurable_pi_iff.mpr + intro p + apply measurableSet_setOfPred.mp + have hmem (i : ι) : MeasurableSet {ω | i ∈ C ω} := + measurableSet_setOfPred.mpr ((measurable_finset_mem i).comp hC) + have hneq : MeasurableSet {ω : Ω | p.1 ≠ p.2} := by + by_cases h : p.1 = p.2 <;> simp [h] + exact (hmem p.1).compl.inter ((hmem p.2).compl.inter + (hneq.inter (measurable_weak_order P _ _ (hF p.1) (hF p.2)))) + +lemma pickPair_eq_selectEligible + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] [DecidableEq ι] + [Nonempty ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + (P : Finset V) (C : Finset ι) (F : ι → V → ℝ) : + pickPair P C F = selectEligible (fun p : ι × ι => + p.1 ∉ C ∧ p.2 ∉ C ∧ p.1 ≠ p.2 ∧ CommonWeakOrder P (F p.1) (F p.2)) := by + classical + unfold pickPair selectEligible + split_ifs <;> rfl + +lemma measurable_pickPair (P : Finset V) (C : Ω → Finset ι) (F : Ω → ι → V → ℝ) + (hC : Measurable C) (hF : ∀ i v, Measurable (fun ω => F ω i v)) : + Measurable (fun ω => pickPair P (C ω) (F ω)) := by + simp_rw [pickPair_eq_selectEligible] + exact measurable_selectEligible.comp (measurable_eligibility P C F hC hF) + +lemma measurable_occupied + {ι : Type treewidthLevel1} {Ω : Type treewidthLevel2} [Fintype ι] [DecidableEq ι] [Nonempty ι] + [MeasurableSpace Ω] [MeasurableSpace ι] [MeasurableSingletonClass ι] + (C : Finset ℕ) (p : Ω → ℕ → ι × ι) + (hp : ∀ a ∈ C, Measurable (fun ω => p ω a)) : + Measurable (fun ω => occupied C (p ω)) := by + classical + apply measurable_finset_iff.mpr + intro i + apply measurableSet_setOfPred.mp + simp only [occupied, Finset.mem_union, Finset.mem_image, Set.ofPred_or, + Set.ofPred_exists, Set.ofPred_and] + apply MeasurableSet.union + all_goals + apply MeasurableSet.iUnion + intro a + by_cases ha : a ∈ C + · simp only [ha, Set.ofPred_true, Set.univ_inter] + first | exact measurableSet_eq_fun (hp a ha).fst measurable_const + | exact measurableSet_eq_fun (hp a ha).snd measurable_const + · simp [ha] + +lemma measurable_selected + {ι : Type treewidthLevel1} {Ω : Type treewidthLevel2} [Fintype ι] [DecidableEq ι] [Nonempty ι] + [MeasurableSpace Ω] [MeasurableSpace ι] [MeasurableSingletonClass ι] + (F : Ω → ι → ℝ) (q : Ω → ι) + (hF : ∀ i, Measurable (fun ω => F ω i)) (hq : Measurable q) : + Measurable (fun ω => F ω (q ω)) := by + classical + have heq : (fun ω => F ω (q ω)) = + (fun ω => ∑ i : ι, if q ω = i then F ω i else 0) := by + funext ω + simp + rw [heq] + apply Finset.measurable_sum + intro i _ + exact (hF i).ite (measurableSet_eq_fun hq measurable_const) measurable_const + +lemma measurable_pairUpdate + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} {Ω : Type treewidthLevel3} [Fintype V] + [Fintype ι] [DecidableEq ι] [Nonempty ι] [MeasurableSpace Ω] [MeasurableSpace ι] + [MeasurableSingletonClass ι] + (F : Ω → ι → V → ℝ) (p : Ω → ι × ι) + (g : Ω → V → ℝ) (hF : ∀ i v, Measurable (fun ω => F ω i v)) + (hp : Measurable p) (hg : ∀ v, Measurable (fun ω => g ω v)) (i : ι) (v : V) : + Measurable (fun ω => functionPairUpdate (F ω) (p ω).1 (p ω).2 (g ω) i v) := by + classical + have hleft := measurable_selected (fun ω j => F ω j v) (fun ω => (p ω).1) + (fun j => hF j v) hp.fst + have hright := measurable_selected (fun ω j => F ω j v) (fun ω => (p ω).2) + (fun j => hF j v) hp.snd + have hmean := (hleft.add hright).div_const 2 + dsimp only [functionPairUpdate, pairUpdate] + exact ((hF i v).add (((hmean.add (hg v)).sub hleft).ite + (measurableSet_eq_fun measurable_const hp.fst) measurable_const)).add + (((hmean.sub (hg v)).sub hright).ite + (measurableSet_eq_fun measurable_const hp.snd) measurable_const) + +/-- Measurability follows from the deterministic causal equations, for EVERY +pointwise realization. There is no assertion that an arbitrary choice operator +on an infinite real-valued space is measurable. -/ +lemma run_measurable (R : ReservationPath) (P : ℕ → Finset V) + (g : Ω → ℕ → V → ℝ) (hg : ∀ t v, Measurable (fun ω => g ω t v)) (n : ℕ) + (F : Ω → ℕ → ι → V → ℝ) (p : Ω → ℕ → ι × ι) + (hrun : ∀ ω, RunEquations R P (g ω) n (F ω) (p ω)) : + (∀ t ≤ n, ∀ i v, Measurable (fun ω => F ω t i v)) ∧ + (∀ t < n, Measurable (fun ω => p ω t)) := by + classical + have hi : ∀ t ≤ n, + (∀ i v, Measurable (fun ω => F ω t i v)) ∧ + (∀ a < t, Measurable (fun ω => p ω a)) := by + intro t + induction t with + | zero => + intro _ + constructor + · intro i v + have heq : (fun ω => F ω 0 i v) = (fun _ => 0) := by + funext ω + rw [(hrun ω).1] + rw [heq] + exact measurable_const + · intro a ha + omega + | succ t ih => + intro ht + obtain ⟨hF, hp⟩ := ih (by omega) + have htn : t < n := by omega + have hcurrent : Measurable (fun ω => p ω t) := by + have heq : (fun ω => p ω t) = + (fun ω => pickPair (P t) (occupied (before R t) (p ω)) (F ω t)) := by + funext ω + exact ((hrun ω).2 t htn).1 + rw [heq] + apply measurable_pickPair _ _ _ _ hF + apply measurable_occupied + intro a ha + exact hp a (Finset.mem_filter.mp ha).2 + constructor + · intro i v + have heq : (fun ω => F ω (t+1) i v) = + (fun ω => functionPairUpdate (F ω t) (p ω t).1 (p ω t).2 (g ω t) i v) := by + funext ω + rw [((hrun ω).2 t htn).2] + rw [heq] + exact measurable_pairUpdate _ _ _ hF hcurrent (hg t) i v + · intro a ha + rcases Nat.lt_or_eq_of_le (Nat.le_of_lt_succ ha) with h | h + · exact hp a h + · simpa [h] using hcurrent + exact ⟨fun t ht => (hi t ht).1, fun t ht => (hi n le_rfl).2 t ht⟩ + +theorem measurable_particle_run (R : ReservationPath) (P : ℕ → Finset V) + (g : Ω → ℕ → V → ℝ) (hg : ∀ t v, Measurable (fun ω => g ω t v)) (n : ℕ) : + ∃ F : Ω → ℕ → ι → V → ℝ, ∃ p : Ω → ℕ → ι × ι, + (∀ ω, RunEquations R P (g ω) n (F ω) (p ω)) ∧ + (∀ t ≤ n, ∀ i v, Measurable (fun ω => F ω t i v)) ∧ + (∀ t < n, Measurable (fun ω => p ω t)) := by + classical + choose F p hrun using (fun ω => finite_run (ι := ι) R P (g ω) n) + exact ⟨F, p, hrun, run_measurable R P g hg n F p hrun⟩ +end BoundedTreewidthL1.ParticleSchedule + +namespace BoundedTreewidthL1.ParticleSchedule +open MeasureTheory Set +variable {V ι Ω : Type*} [Fintype V] [Fintype ι] [DecidableEq ι] [Nonempty ι] + [MeasurableSpace Ω] [MeasurableSpace ι] [MeasurableSingletonClass ι] + +lemma measurable_threshold_joint + {V : Type treewidthLevel1} {Ω : Type treewidthLevel2} [Fintype V] [MeasurableSpace Ω] + (F : Ω → V → ℝ) + (hF : ∀ v, Measurable (fun ω => F ω v)) : + Measurable (fun z : Ω × ℝ => thresholdLabels (F z.1) z.2) := by + classical + apply measurable_pi_iff.mpr + intro v + have h : Measurable (fun z : Ω × ℝ => if z.2 < F z.1 v then true else false) := + measurable_const.ite (measurableSet_lt measurable_snd ((hF v).comp measurable_fst)) + measurable_const + convert h using 1 + ext z + simp [thresholdLabels] + +lemma measurable_sweep_real (M : ℝ) (F : Ω → V → ℝ) + (hF : ∀ v, Measurable (fun ω => F ω v)) (S : Set (V → Bool)) : + Measurable (fun ω => (sweep M (F ω)).real S) := by + have hs := (measurable_threshold_joint F hF) ((Set.toFinite S).measurableSet) + have hm := measurable_measure_prodMk_left + (ν := volume.restrict (Icc (-M) M)) hs + convert hm.ennreal_toReal using 1 + funext ω + rw [sweep, map_measureReal_apply (measurable_thresholdLabels _) (Set.toFinite S).measurableSet] + rfl + +lemma measurable_symmetrize_sweep_real (M : ℝ) (F : Ω → V → ℝ) + (hF : ∀ v, Measurable (fun ω => F ω v)) (S : Set (V → Bool)) : + Measurable (fun ω => (symmetrizeCut (sweep M (F ω))).real S) := by + have heq (ω : Ω) : (symmetrizeCut (sweep M (F ω))).real S = + (1/2 : ℝ) * ((sweep M (F ω)).real S + + (sweep M (F ω)).real (complementCut ⁻¹' S)) := by + rw [symmetrizeCut, measureReal_ennreal_smul_apply, + measureReal_add_apply (by finiteness) (by finiteness), + map_measureReal_apply measurable_complementCut (Set.toFinite S).measurableSet] + norm_num + simp_rw [heq] + exact ((measurable_sweep_real M F hF S).add + (measurable_sweep_real M F hF _)).const_mul _ + +instance finite_cutTrace (μ : Measure (V → Bool)) [IsFiniteMeasure μ] (P : Finset V) : + IsFiniteMeasure (cutTrace μ P) := by + unfold cutTrace + infer_instance + +instance finite_particleTrace (M : ℝ) (F : ι → V → ℝ) (P : Finset V) : + IsFiniteMeasure (particleTrace M F P) := by + unfold particleTrace cutTrace + infer_instance + +lemma particle_real_sum + {ι : Type treewidthLevel1} [Fintype ι] [DecidableEq ι] [Nonempty ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] + {A : Type*} [MeasurableSpace A] (μ : ι → Measure A) + [∀ i, IsFiniteMeasure (μ i)] (S : Set A) : + (∑ i, μ i).real S = ∑ i, (μ i).real S := by + simp only [measureReal_def, Measure.finsetSum_apply] + exact ENNReal.toReal_sum (fun i _ => measure_ne_top _ _) + +lemma measurable_particleTrace_real (M : ℝ) (F : Ω → ι → V → ℝ) + (hF : ∀ i v, Measurable (fun ω => F ω i v)) + (P : Finset V) (S : Set (P → Bool)) : + Measurable (fun ω => (particleTrace M (F ω) P).real S) := by + have heq (ω : Ω) : (particleTrace M (F ω) P).real S = + ∑ i, (symmetrizeCut (sweep M (F ω i))).real + ((fun a : V → Bool => fun v : P => a v) ⁻¹' S) := by + rw [particleTrace, particle_real_sum] + apply Finset.sum_congr rfl + intro i hi + exact map_measureReal_apply (measurable_of_finite _) (Set.toFinite S).measurableSet + simp_rw [heq] + apply Finset.measurable_sum + intro i hi + exact measurable_symmetrize_sweep_real M (fun ω => F ω i) (hF i) _ + +lemma symmetrize_sweep_mass (M : ℝ) (hM : 0 ≤ M) (F : V → ℝ) : + (symmetrizeCut (sweep M F)).real univ = 2*M := by + rw [symmetrizeCut, measureReal_ennreal_smul_apply, + measureReal_add_apply (by finiteness) (by finiteness), + map_measureReal_apply measurable_complementCut MeasurableSet.univ] + simp only [preimage_univ, sweep_total_mass M hM] + norm_num + ring + +lemma particleTrace_mass (M : ℝ) (hM : 0 ≤ M) (F : ι → V → ℝ) (P : Finset V) : + (particleTrace M F P).real univ = 2*(Fintype.card ι : ℝ)*M := by + rw [particleTrace, particle_real_sum] + have heq (i : ι) : (cutTrace (symmetrizeCut (sweep M (F i))) P).real univ = 2*M := by + rw [cutTrace, map_measureReal_apply (measurable_of_finite _) MeasurableSet.univ] + simpa only [preimage_univ] using symmetrize_sweep_mass M hM (F i) + simp_rw [heq] + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + ring + +lemma integrable_particleTrace_real (M : ℝ) (hM : 0 ≤ M) (F : Ω → ι → V → ℝ) + (hF : ∀ i v, Measurable (fun ω => F ω i v)) + (P : Finset V) (S : Set (P → Bool)) (ν : Measure Ω) [IsFiniteMeasure ν] : + Integrable (fun ω => (particleTrace M (F ω) P).real S) ν := by + apply (integrable_const (2*(Fintype.card ι : ℝ)*M)).mono' + (measurable_particleTrace_real M F hF P S).aestronglyMeasurable + apply Filter.Eventually.of_forall + intro ω + rw [Real.norm_eq_abs, abs_of_nonneg (measureReal_nonneg)] + exact (measureReal_mono (subset_univ S)).trans_eq (particleTrace_mass M hM (F ω) P) + +theorem measurable_branch_cut_laws (R : ReservationPath) (P : ℕ → Finset V) + (g : Ω → ℕ → V → ℝ) (hg : ∀ t v, Measurable (fun ω => g ω t v)) (n : ℕ) + (M : ℝ) (hM : 0 ≤ M) (ν : Measure Ω) [IsFiniteMeasure ν] : + ∃ F : Ω → ℕ → ι → V → ℝ, ∃ p : Ω → ℕ → ι × ι, + (∀ ω, RunEquations R P (g ω) n (F ω) (p ω)) ∧ + (∀ t ≤ n, ∀ B : Finset V, ∀ b : B → Bool, + Measurable (fun ω => (particleTrace M (F ω t) B).real {b}) ∧ + Integrable (fun ω => (particleTrace M (F ω t) B).real {b}) ν) ∧ + (∀ ω t, (particleTrace M (F ω t) (P t)).real Set.univ = + 2*(Fintype.card ι : ℝ)*M) := by + obtain ⟨F,p,hrun,hF,hp⟩ := measurable_particle_run (ι := ι) R P g hg n + refine ⟨F,p,hrun,?_,?_⟩ + · intro t ht B b + exact ⟨measurable_particleTrace_real M (fun ω => F ω t) (hF t ht) B {b}, + integrable_particleTrace_real M hM (fun ω => F ω t) (hF t ht) B {b} ν⟩ + · intro ω t + exact particleTrace_mass M hM (F ω t) (P t) +end BoundedTreewidthL1.ParticleSchedule + +namespace BoundedTreewidthL1.ParticleSchedule +open MeasureTheory +open scoped ENNReal +variable {V ι Ω : Type*} [Fintype V] [DecidableEq V] [Fintype ι] [DecidableEq ι] + [Nonempty ι] [MeasurableSpace Ω] + +/-- Literal restriction of a bag assignment to a smaller bag. -/ +def restrictBagCut (P Q : Finset V) (h : Q ⊆ P) (a : P → Bool) : Q → Bool := + fun x => a ⟨x,h x.property⟩ + +lemma particleTrace_restrict + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [DecidableEq V] [Fintype ι] + [DecidableEq ι] [Nonempty ι] + (M : ℝ) (F : ι → V → ℝ) + (P Q : Finset V) (h : Q ⊆ P) : + (particleTrace M F P).map (restrictBagCut P Q h) = particleTrace M F Q := by + classical + rw [particleTrace, Measure.map_finset_sum' (measurable_of_finite _).aemeasurable] + unfold particleTrace + apply Finset.sum_congr rfl + intro i _ + rw [cutTrace, Measure.map_map (measurable_of_finite _) (measurable_of_finite _)] + rfl + +theorem compatible_measurable_branch (R : ReservationPath) + (k q : ℕ) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (P : ℕ → Finset V) (hP : ∀ t ≤ R.last, (P t).card ≤ k) + (hsize : ∀ t, (R.inclusive t).card ≤ q) + (d : V → V → ℝ) (L H Δ : ℝ) (hH : 0 < H) (hΔ : 0 < Δ) + (g : Ω → ℕ → V → ℝ) (hg : ∀ t v, Measurable (fun ω => g ω t v)) + (hLip : ∀ ω t, t ≤ R.last → ∀ u v, |g ω t u - g ω t v| ≤ L * d u v) + (hHeight : ∀ ω t, t ≤ R.last → ∀ v, |g ω t v| ≤ H) + (hvanish : ∀ ω t, t ≤ R.last → ∀ v ∈ P t, g ω t v = 0) + (ν : Measure Ω) [IsFiniteMeasure ν] : + let M := H * ((Fintype.card ι : ℝ)-1) + 2*Δ + ∃ F : Ω → ℕ → ι → V → ℝ, ∃ p : Ω → ℕ → ι × ι, + (∀ ω, RunEquations R P (g ω) (R.last+1) (F ω) (p ω)) ∧ + (∀ ω t, t ≤ R.last+1 → FunctionParticleReachable d L H (F ω t)) ∧ + (∀ t ≤ R.last, ∀ b : P t → Bool, + Measurable (fun ω => (particleTrace M (F ω (t+1)) (P t)).real {b}) ∧ + Integrable (fun ω => (particleTrace M (F ω (t+1)) (P t)).real {b}) ν) ∧ + (∀ ω t, (particleTrace M (F ω (t+1)) (P t)).real Set.univ = + 2*(Fintype.card ι : ℝ)*M) ∧ + (∀ ω t, t < R.last → + (particleTrace M (F ω (t+1)) (P t)).map + (restrictBagCut (P t) (P t ∩ P (t+1)) Finset.inter_subset_left) = + (particleTrace M (F ω (t+2)) (P (t+1))).map + (restrictBagCut (P (t+1)) (P t ∩ P (t+1)) Finset.inter_subset_right)) ∧ + (∀ ω t, t ≤ R.last → ∀ a ∈ R.inclusive t, + F ω (t+1) (p ω a).1 = F ω (a+1) (p ω a).1 ∧ + F ω (t+1) (p ω a).2 = F ω (a+1) (p ω a).2) := by + classical + let : MeasurableSpace ι := ⊤ + let : MeasurableSingletonClass ι := ⟨fun _ => trivial⟩ + dsimp only + choose F p hrun hreach htrace hretain using + fun ω => scheduled_particle_realization (ι := ι) R k q hN P hP hsize d L H Δ hH hΔ + (g ω) (hLip ω) (hHeight ω) (hvanish ω) + have hmeas := (run_measurable R P g hg (R.last+1) F p hrun).1 + have hc : (1 : ℝ) ≤ Fintype.card ι := by + have hn : 1 ≤ Fintype.card ι := Fintype.card_pos + exact_mod_cast hn + have hM : 0 ≤ H * ((Fintype.card ι : ℝ)-1) + 2*Δ := by + positivity + refine ⟨F,p,hrun,hreach,?_,?_,?_,hretain⟩ + · intro t ht b + exact ⟨measurable_particleTrace_real _ (fun ω => F ω (t+1)) + (hmeas (t+1) (by omega)) (P t) {b}, + integrable_particleTrace_real _ hM (fun ω => F ω (t+1)) + (hmeas (t+1) (by omega)) (P t) {b} ν⟩ + · intro ω t + exact particleTrace_mass _ hM _ _ + · intro ω t ht + rw [particleTrace_restrict, particleTrace_restrict] + have heq := congrArg (fun μ => μ.map (restrictBagCut (P (t+1)) + (P t ∩ P (t+1)) Finset.inter_subset_right)) + (htrace ω (t+1) (by omega)).2 + simpa only [particleTrace_restrict, Nat.add_assoc] using heq +end BoundedTreewidthL1.ParticleSchedule + +namespace BoundedTreewidthL1.ParticleBatch +open MeasureTheory ParticleSchedule +variable {V ι J : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] [DecidableEq J] + +noncomputable def usedPairs (C : Finset J) (p : J → ι × ι) : Finset ι := + (C.image (fun a => (p a).1)) ∪ (C.image (fun a => (p a).2)) + +/-- Launch all new active keys at one interface, reserving a pair immediately +before proceeding to the next key. Retained keys are supplied in C. -/ +noncomputable def launchBatch (P : Finset V) : (l : List J) → (C : Finset J) → + (F : ι → V → ℝ) → (p : J → ι × ι) → (g : J → V → ℝ) → + (ι → V → ℝ) × (J → ι × ι) + | [], _, F, p, _ => (F,p) + | a :: l, C, F, p, g => + let z := pickPair P (usedPairs C p) F + launchBatch P l (insert a C) (functionPairUpdate F z.1 z.2 (g a)) + (Function.update p a z) g + +lemma usedPairs_card + {ι : Type treewidthLevel1} {J : Type treewidthLevel2} [Fintype ι] [Nonempty ι] [DecidableEq ι] + [DecidableEq J] + (C : Finset J) (p : J → ι × ι) : + (usedPairs C p).card ≤ 2*C.card := by + unfold usedPairs + have h := Finset.card_union_le (C.image (fun a => (p a).1)) (C.image (fun a => (p a).2)) + have h₁ := Finset.card_image_le (s := C) (f := fun a => (p a).1) + have h₂ := Finset.card_image_le (s := C) (f := fun a => (p a).2) + omega + +lemma usedPairs_mono + {ι : Type treewidthLevel1} {J : Type treewidthLevel2} [Fintype ι] [Nonempty ι] [DecidableEq ι] + [DecidableEq J] + {C D : Finset J} (h : C ⊆ D) (p : J → ι × ι) : + usedPairs C p ⊆ usedPairs D p := + Finset.union_subset_union (Finset.image_subset_image h) (Finset.image_subset_image h) + +lemma usedPairs_update + {ι : Type treewidthLevel1} {J : Type treewidthLevel2} [Fintype ι] [Nonempty ι] [DecidableEq ι] + [DecidableEq J] + {C : Finset J} {a : J} (ha : a ∉ C) + (p : J → ι × ι) (z : ι × ι) : usedPairs C (Function.update p a z) = usedPairs C p := by + unfold usedPairs + congr 1 <;> apply Finset.image_congr <;> intro b hb <;> + simp only [Function.update_of_ne (show b ≠ a from fun h => ha (h ▸ hb))] + +lemma first_mem_used + {ι : Type treewidthLevel1} {J : Type treewidthLevel2} [Fintype ι] [Nonempty ι] [DecidableEq ι] + [DecidableEq J] + {C : Finset J} {a : J} (ha : a ∈ C) (p : J → ι × ι) : + (p a).1 ∈ usedPairs C p := + Finset.mem_union_left _ (Finset.mem_image_of_mem _ ha) +lemma second_mem_used + {ι : Type treewidthLevel1} {J : Type treewidthLevel2} [Fintype ι] [Nonempty ι] [DecidableEq ι] + [DecidableEq J] + {C : Finset J} {a : J} (ha : a ∈ C) (p : J → ι × ι) : + (p a).2 ∈ usedPairs C p := + Finset.mem_union_right _ (Finset.mem_image_of_mem _ ha) + +/-- The reservation-preserving finite batch required by the co-bag active-scale +construction. No bound on the total number of updates is imposed. -/ +theorem launchBatch_correct (k q : ℕ) + (hN : Fintype.card ι = 2*q + k.factorial + 2) + (P : Finset V) (hP : P.card ≤ k) (l : List J) (C : Finset J) + (hl : l.Nodup) (hfresh : ∀ a ∈ l, a ∉ C) + (hcount : (C ∪ l.toFinset).card ≤ q) + (d : V → V → ℝ) (L H Δ : ℝ) (hH : 0 < H) (hΔ : 0 < Δ) + (F : ι → V → ℝ) (p : J → ι × ι) + (hF : FunctionParticleReachable d L H F) (g : J → V → ℝ) + (hLip : ∀ a ∈ l, ∀ u v, |g a u - g a v| ≤ L*d u v) + (hHeight : ∀ a ∈ l, ∀ v, |g a v| ≤ H) + (hzero : ∀ a ∈ l, ∀ v ∈ P, g a v = 0) : + let out := launchBatch P l C F p g + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + FunctionParticleReachable d L H out.1 ∧ + particleTrace M out.1 P = particleTrace M F P ∧ + (∀ a ∈ C, out.2 a = p a) ∧ + (∀ i ∈ usedPairs C p, out.1 i = F i) ∧ + (∀ a ∈ l, (out.2 a).1 ≠ (out.2 a).2 ∧ + ∀ v, out.1 (out.2 a).1 v - out.1 (out.2 a).2 v = 2*g a v) := by + classical + induction l generalizing C F p with + | nil => + simpa [launchBatch] using hF + | cons a l ih => + have haC : a ∉ C := hfresh a (by simp) + let z := pickPair P (usedPairs C p) F + let F₁ := functionPairUpdate F z.1 z.2 (g a) + let p₁ := Function.update p a z + have hC : C.card ≤ q := (Finset.card_le_card Finset.subset_union_left).trans hcount + have hz : z.1 ∉ usedPairs C p ∧ z.2 ∉ usedPairs C p ∧ z.1 ≠ z.2 ∧ + CommonWeakOrder P (F z.1) (F z.2) := + pickPair_spec k q hN P hP _ ((usedPairs_card C p).trans (by omega)) F + have hF₁ : FunctionParticleReachable d L H F₁ := + FunctionParticleReachable.step hF z.1 z.2 hz.2.2.1 (g a) + (hLip a (by simp)) (hHeight a (by simp)) + have hnewCount : (insert a C ∪ l.toFinset).card ≤ q := by + simpa only [List.toFinset_cons, Finset.insert_union, Finset.union_insert] using hcount + have hnewFresh : ∀ b ∈ l, b ∉ insert a C := by + intro b hb h + rcases Finset.mem_insert.mp h with h | h + · subst b + exact (List.nodup_cons.mp hl).1 hb + · exact hfresh b (by simp [hb]) h + have hresult := ih (insert a C) hl.of_cons hnewFresh hnewCount F₁ p₁ hF₁ + (fun b hb => hLip b (by simp [hb])) (fun b hb => hHeight b (by simp [hb])) + (fun b hb => hzero b (by simp [hb])) + dsimp only at hresult ⊢ + change _ ∧ _ ∧ _ ∧ _ ∧ _ + dsimp only [launchBatch] + change FunctionParticleReachable d L H (launchBatch P l (insert a C) F₁ p₁ g).1 ∧ + particleTrace (H*((Fintype.card ι : ℝ)-1)+2*Δ) + (launchBatch P l (insert a C) F₁ p₁ g).1 P = particleTrace + (H*((Fintype.card ι : ℝ)-1)+2*Δ) F P ∧ + (∀ b ∈ C, (launchBatch P l (insert a C) F₁ p₁ g).2 b = p b) ∧ + (∀ i ∈ usedPairs C p, (launchBatch P l (insert a C) F₁ p₁ g).1 i = F i) ∧ + (∀ b ∈ a :: l, + ((launchBatch P l (insert a C) F₁ p₁ g).2 b).1 ≠ + ((launchBatch P l (insert a C) F₁ p₁ g).2 b).2 ∧ + ∀ v, (launchBatch P l (insert a C) F₁ p₁ g).1 + ((launchBatch P l (insert a C) F₁ p₁ g).2 b).1 v - + (launchBatch P l (insert a C) F₁ p₁ g).1 + ((launchBatch P l (insert a C) F₁ p₁ g).2 b).2 v = 2*g b v) + refine ⟨hresult.1, ?_, ?_, ?_, ?_⟩ + · have hc : (1:ℝ) ≤ Fintype.card ι := by + exact_mod_cast (Fintype.card_pos : 0 < Fintype.card ι) + have hM : 0 < H*((Fintype.card ι : ℝ)-1)+2*Δ := by + have := mul_nonneg hH.le (sub_nonneg.mpr hc) + linarith + have htrace := particleTrace_update _ hM F z.1 z.2 hz.2.2.1 (g a) P hz.2.2.2 + (hzero a (by simp)) + (fun i v => (function_particles_height_bound hH hF i v).trans (by linarith)) + (fun i v => (function_particles_height_bound hH hF₁ i v).trans (by linarith)) + exact hresult.2.1.trans htrace.symm + · intro b hb + rw [hresult.2.2.1 b (Finset.mem_insert_of_mem hb)] + exact Function.update_of_ne (show b ≠ a from fun h => haC (h ▸ hb)) _ _ + · intro i hi + have hi₁ : i ∈ usedPairs (insert a C) p₁ := by + apply usedPairs_mono (Finset.subset_insert a C) p₁ + rwa [usedPairs_update haC] + rw [hresult.2.2.2.1 i hi₁] + funext v + exact functionPairUpdate_other F z.1 z.2 i + (fun h => hz.1 (h ▸ hi)) (fun h => hz.2.1 (h ▸ hi)) (g a) v + · intro b hb + rcases List.mem_cons.mp hb with h | hb + · subst b + have hpz : (launchBatch P l (insert a C) F₁ p₁ g).2 a = z := by + simpa [p₁] using hresult.2.2.1 a (Finset.mem_insert_self a C) + change ((launchBatch P l (insert a C) F₁ p₁ g).2 a).1 ≠ _ ∧ _ + rw [hpz] + refine ⟨hz.2.2.1, ?_⟩ + intro v + have hz₁ : z.1 ∈ usedPairs (insert a C) p₁ := by + simpa [p₁] using first_mem_used (Finset.mem_insert_self a C) p₁ + have hz₂ : z.2 ∈ usedPairs (insert a C) p₁ := by + simpa [p₁] using second_mem_used (Finset.mem_insert_self a C) p₁ + rw [hresult.2.2.2.1 z.1 hz₁, hresult.2.2.2.1 z.2 hz₂] + dsimp [F₁] + rw [functionPairUpdate_left F z.1 z.2 hz.2.2.1, + functionPairUpdate_right F z.1 z.2 hz.2.2.1] + ring + · exact hresult.2.2.2.2 b hb +end BoundedTreewidthL1.ParticleBatch + +namespace BoundedTreewidthL1.ParticleBatch +open MeasureTheory ParticleSchedule +variable {V ι J Ω : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] [DecidableEq J] [Fintype J] + [MeasurableSpace Ω] [MeasurableSpace ι] [MeasurableSingletonClass ι] + +lemma measurable_usedPairs + {ι : Type treewidthLevel1} {J : Type treewidthLevel2} {Ω : Type treewidthLevel3} [Fintype ι] + [Nonempty ι] [DecidableEq ι] [DecidableEq J] [Fintype J] [MeasurableSpace Ω] [MeasurableSpace ι] + [MeasurableSingletonClass ι] + (C : Finset J) (p : Ω → J → ι × ι) + (hp : ∀ a, Measurable (fun ω => p ω a)) : + Measurable (fun ω => usedPairs C (p ω)) := by + have hp' : Measurable p := measurable_pi_iff.mpr hp + exact (measurable_of_finite (fun p : J → ι × ι => usedPairs C p)).comp hp' + +/-- The exact finite multi-launch scheduler is measurable; all pair choice is +finite deterministic selection, not choice on the real sample space. -/ +theorem measurable_launchBatch (P : Finset V) (l : List J) (C : Finset J) + (F : Ω → ι → V → ℝ) (p : Ω → J → ι × ι) (g : Ω → J → V → ℝ) + (hF : ∀ i v, Measurable (fun ω => F ω i v)) + (hp : ∀ a, Measurable (fun ω => p ω a)) + (hg : ∀ a v, Measurable (fun ω => g ω a v)) : + Measurable (fun ω => launchBatch P l C (F ω) (p ω) (g ω)) := by + classical + induction l generalizing C F p with + | nil => + exact (measurable_pi_iff.mpr fun i => measurable_pi_iff.mpr (hF i)).prodMk + (measurable_pi_iff.mpr hp) + | cons a l ih => + let z : Ω → ι × ι := fun ω => pickPair P (usedPairs C (p ω)) (F ω) + have hz : Measurable z := measurable_pickPair P _ F (measurable_usedPairs C p hp) hF + have hF₁ : ∀ i v, Measurable (fun ω => + functionPairUpdate (F ω) (z ω).1 (z ω).2 (g ω a) i v) := + measurable_pairUpdate F z (fun ω => g ω a) hF hz (hg a) + have hp₁ : ∀ b, Measurable (fun ω => Function.update (p ω) a (z ω) b) := by + intro b + by_cases h : b = a + · subst b + simpa only [Function.update_self] using hz + · simpa only [Function.update_of_ne h] using hp b + exact ih (insert a C) _ _ hF₁ hp₁ +end BoundedTreewidthL1.ParticleBatch + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/ReservedCoupling.lean b/lean/OAI/Combinatorics/TreewidthL1/ReservedCoupling.lean new file mode 100644 index 0000000000000000000000000000000000000000..4b3f40d1a9346fea4593e0005a50cf51510d5a22 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/ReservedCoupling.lean @@ -0,0 +1,315 @@ +import OAI.Combinatorics.TreewidthL1.OrderedSweep + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1.ReservationCoupling +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {A B C : Type*} [Fintype A] [Fintype B] [Fintype C] + +structure IsCoupling (μ : A → ℝ) (ν : B → ℝ) (Q : A → B → ℝ) : Prop where + nonneg : ∀ a b, 0 ≤ Q a b + row : ∀ a, ∑ b, Q a b = μ a + col : ∀ b, ∑ a, Q a b = ν b + +noncomputable def action (μ : A → ℝ) (Q : A → B → ℝ) (f : B → ℝ) (a : A) : ℝ := + (∑ b, Q a b * f b) / μ a + +noncomputable def total (μ f : A → ℝ) : ℝ := ∑ a, μ a * f a +noncomputable def defect (μ f p : A → ℝ) : ℝ := + ∑ a, μ a * (f a + p a - 2*f a*p a) + +lemma IsCoupling.symm {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) : IsCoupling ν μ (fun b a => Q a b) := + ⟨fun b a => h.nonneg a b, h.col, h.row⟩ + +lemma IsCoupling.left_nonneg {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) (a : A) : 0 ≤ μ a := by + rw [← h.row] + exact Finset.sum_nonneg (fun b _ => h.nonneg a b) + +lemma IsCoupling.right_nonneg {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) (b : B) : 0 ≤ ν b := h.symm.left_nonneg b + +lemma IsCoupling.row_zero {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) (a : A) (ha : μ a = 0) (b : B) : Q a b = 0 := by + have hr := h.row a + rw [ha] at hr + exact (Finset.sum_eq_zero_iff_of_nonneg (fun x _ => h.nonneg a x)).mp hr b (Finset.mem_univ _) + +lemma weighted_action {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) (f : B → ℝ) (a : A) : + μ a * action μ Q f a = ∑ b, Q a b * f b := by + by_cases ha : μ a = 0 + · simp [action, ha, h.row_zero a ha] + · unfold action + field_simp + +lemma action_bounds {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) (f : B → ℝ) (hf : ∀ b, 0 ≤ f b ∧ f b ≤ 1) (a : A) : + 0 ≤ action μ Q f a ∧ action μ Q f a ≤ 1 := by + have hn : 0 ≤ ∑ b, Q a b * f b := + Finset.sum_nonneg (fun b _ => mul_nonneg (h.nonneg a b) (hf b).1) + have hl : (∑ b, Q a b * f b) ≤ μ a := by + rw [← h.row a] + apply Finset.sum_le_sum + intro b _ + simpa using mul_le_mul_of_nonneg_left (hf b).2 (h.nonneg a b) + refine ⟨div_nonneg hn (h.left_nonneg a), ?_⟩ + by_cases ha : μ a = 0 + · simp [action, ha] + · exact (div_le_one (lt_of_le_of_ne (h.left_nonneg a) (Ne.symm ha))).mpr hl + +lemma action_total {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) (f : B → ℝ) : total μ (action μ Q f) = total ν f := by + unfold total + simp_rw [weighted_action h] + rw [Finset.sum_comm] + simp_rw [← Finset.sum_mul, h.col] + +lemma action_adjoint {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) (f : B → ℝ) (p : A → ℝ) : + total μ (fun a => p a * action μ Q f a) = + total ν (fun b => f b * action ν (fun b a => Q a b) p b) := by + unfold total + conv_lhs => + arg 2; ext a + rw [← mul_assoc, mul_right_comm, weighted_action h, Finset.sum_mul] + conv_rhs => + arg 2; ext b + rw [← mul_assoc, mul_right_comm, weighted_action h.symm, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + apply Finset.sum_congr rfl + intro a _ + ring + +lemma defect_form (μ f p : A → ℝ) : + defect μ f p = total μ f + total μ p - 2*total μ (fun a => p a*f a) := by + unfold defect total + simp only [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro a _ + ring + +lemma defect_nonneg (μ f p : A → ℝ) (hμ : ∀ a, 0 ≤ μ a) + (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) (hp : ∀ a, 0 ≤ p a ∧ p a ≤ 1) : + 0 ≤ defect μ f p := by + apply Finset.sum_nonneg + intro a _ + apply mul_nonneg (hμ a) + have h₁ := mul_nonneg (hf a).1 (sub_nonneg.mpr (hp a).2) + have h₂ := mul_nonneg (hp a).1 (sub_nonneg.mpr (hf a).2) + nlinarith + +/-- Move one true finite Markov transition from the endpoint response to the +past predictor. This does not lose any mass, even with zero-probability states. -/ +theorem transfer_defect {μ : A → ℝ} {ν : B → ℝ} {Q : A → B → ℝ} + (h : IsCoupling μ ν Q) (f : B → ℝ) (p : A → ℝ) : + defect μ (action μ Q f) p = defect ν f (action ν (fun b a => Q a b) p) := by + rw [defect_form, defect_form, action_total h, action_total h.symm, + action_adjoint h f p] + congr 1 + congr 1 + unfold total + apply Finset.sum_congr rfl + intro b _ + ring + +/-- Responses through a constant finite state space, with time-dependent laws. -/ +noncomputable def response (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) + (t : ℕ) : ℕ → (A → ℝ) → (A → ℝ) + | 0, f => f + | n+1, f => action (μ t) (Q t) (response μ Q (t+1) n f) + +lemma response_bounds (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) + (hQ : ∀ t, IsCoupling (μ t) (μ (t+1)) (Q t)) (t n : ℕ) (f : A → ℝ) + (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) : + ∀ a, 0 ≤ response μ Q t n f a ∧ response μ Q t n f a ≤ 1 := by + induction n generalizing t with + | zero => exact hf + | succ n ih => exact action_bounds (hQ t) _ (ih (t+1)) + +lemma response_total (μ : ℕ → A → ℝ) (Q : ℕ → A → A → ℝ) + (hQ : ∀ t, IsCoupling (μ t) (μ (t+1)) (Q t)) (t n : ℕ) (f : A → ℝ) : + total (μ t) (response μ Q t n f) = total (μ (t+n)) f := by + induction n generalizing t with + | zero => simp [response] + | succ n ih => + change total (μ t) (action (μ t) (Q t) _) = _ + rw [action_total (hQ t), ih] + congr 2 + omega +end BoundedTreewidthL1.ReservationCoupling + +namespace BoundedTreewidthL1.ReservedKernel +open MeasureTheory ExpandedParticleLaw ReservationCoupling +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι : Type*} [Fintype V] [Fintype ι] + +noncomputable def lift (M : ℝ) (F : V → ℝ) (i : ι) (a : OrderedReservation.Carrier M F) : State ι V := + (i,false,a.val) + +lemma glue_action {A B C : Type*} [Fintype A] [Fintype B] + (key : A → C) (key' : B → C) (μ : A → ℝ) (ν : B → ℝ) (f : B → ℝ) + (a : A) (ha : μ a ≠ 0) : + action μ (glueWeights key key' μ ν) f a = + (∑ b, if key' b = key a then ν b*f b else 0) / marginal key μ (key a) := by + unfold action + have he : (∑ b, glueWeights key key' μ ν a b * f b) = + μ a * (∑ b, if key' b = key a then ν b*f b else 0) / marginal key μ (key a) := by + rw [Finset.mul_sum, Finset.sum_div] + apply Finset.sum_congr rfl + intro b _ + unfold glueWeights + by_cases h : key' b = key a + · simp only [h, ↓reduceIte] + ring + · simp [h, Ne.symm h] + rw [he] + field_simp + +lemma old_key + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] + (i j r : ι) (q : Bool) (hir : r ≠ i) (hjr : r ≠ j) + (x : State ι V) : departureKey i j x = (r,q) ↔ x.1 = r ∧ x.2.1 = q := by + unfold departureKey + simp only [Prod.mk.injEq] + by_cases hx : x.1 = j + · simp [hx, Ne.symm hir, Ne.symm hjr] + · simp [hx] + +lemma sum_old_key (i j r : ι) (q : Bool) (hir : r ≠ i) (hjr : r ≠ j) + (f : State ι V → ℝ) : + (∑ x, if departureKey i j x = (r,q) then f x else 0) = + ∑ ω : V → Bool, f (r,q,ω) := by + simp_rw [old_key i j r q hir hjr] + simp only [Fintype.sum_prod_type] + cases q <;> simp [ite_and] + +lemma positive_trace_sum (M : ℝ) (F : V → ℝ) (P : Finset V) + (a : OrderedReservation.Carrier M F) (g : (V → Bool) → ℝ) : + (∑ ω : V → Bool, if (fun v : P => ω v) = (fun v : P => a.val v) then + (sweep M F).real {ω} * g ω else 0) = + ∑ b : OrderedReservation.Carrier M F, + if OrderedReservation.traceRank M F P b = OrderedReservation.traceRank M F P a then + OrderedReservation.weight M F b * g b.val else 0 := by + have he := OrderedReservation.sum_carrier M F + (fun ω => if (fun v : P => ω v) = (fun v : P => a.val v) then g ω else 0) + simp only [mul_ite,mul_zero] at he + rw [← he] + apply Finset.sum_congr rfl + intro b _ + have hb : ((fun v : P => b.val v) = (fun v : P => a.val v)) ↔ + OrderedReservation.traceRank M F P b = OrderedReservation.traceRank M F P a := by + rw [OrderedReservation.traceRank_fiber] + exact funext_iff + simp only [hb] + +lemma departure_old_numerator (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (i j r : ι) + (hir : r ≠ i) (hjr : r ≠ j) (a : OrderedReservation.Carrier M (F r)) + (f : State ι V → ℝ) : + (∑ b, if (departureKey i j b, trace P b) = + (departureKey i j (lift M (F r) r a), trace P (lift M (F r) r a)) then + weight M F b * f b else 0) = + (∑ b : OrderedReservation.Carrier M (F r), + if OrderedReservation.traceRank M (F r) P b = OrderedReservation.traceRank M (F r) P a then + OrderedReservation.weight M (F r) b * f (lift M (F r) r b) else 0)/2 := by + have hk : departureKey i j (lift M (F r) r a) = (r,false) := by simp [departureKey,lift,hjr] + simp only [hk, Prod.mk.injEq, ite_and] + rw [sum_old_key i j r false hir hjr] + change (∑ ω : V → Bool, if (fun v : P => ω v) = (fun v : P => a.val v) then + (sweep M (F r)).real {ω} / 2 * f (r,false,ω) else 0) = _ + have he := positive_trace_sum M (F r) P a (fun ω => f (r,false,ω)) + erw [← he, Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> ring + +/-- Restrict the ACTUAL departure kernel to an old retained particle: it is +exactly the monotone interval heat bath, not an arbitrary common submeasure. -/ +theorem departure_action_old (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (i j r : ι) + (hir : r ≠ i) (hjr : r ≠ j) (a : OrderedReservation.Carrier M (F r)) + (f : State ι V → ℝ) : + action (weight M F) (departure M F P i j) f (lift M (F r) r a) = + OrderedSweepFlow.bath (OrderedReservation.weight M (F r)) + (OrderedReservation.traceRank M (F r) P) (fun b => f (lift M (F r) r b)) a := by + have hpos : 0 < weight M F (lift M (F r) r a) := + div_pos a.property (by norm_num) + unfold departure + rw [glue_action _ _ _ _ _ _ hpos.ne'] + trans ((∑ b : OrderedReservation.Carrier M (F r), + if OrderedReservation.traceRank M (F r) P b = OrderedReservation.traceRank M (F r) P a then + OrderedReservation.weight M (F r) b * f (lift M (F r) r b) else 0)/2) / + marginal (fun x => (departureKey i j x, trace P x)) (weight M F) + (departureKey i j (lift M (F r) r a), trace P (lift M (F r) r a)) + · congr 1 + convert departure_old_numerator M F P i j r hir hjr a f using 1 + apply Finset.sum_congr rfl + intro b _ + split_ifs <;> rfl + have hd := departure_old_numerator M F P i j r hir hjr a (fun _ => 1) + simp only [mul_one] at hd + have hd' : marginal (fun x : State ι V => (departureKey i j x, trace P x)) (weight M F) + (departureKey i j (lift M (F r) r a), trace P (lift M (F r) r a)) = + (∑ b : OrderedReservation.Carrier M (F r), + if OrderedReservation.traceRank M (F r) P b = OrderedReservation.traceRank M (F r) P a then + OrderedReservation.weight M (F r) b else 0)/2 := by + unfold marginal + convert hd using 1 + apply Finset.sum_congr rfl + intro b _ + split_ifs <;> rfl + rw [hd'] + unfold OrderedSweepFlow.bath OrderedSweepFlow.mass OrderedSweepFlow.fiber + simp only [Finset.sum_filter] + ring + +/-- A retained incoming particle is copied exactly, as a whole global cut. -/ +lemma incoming_action_retained (M : ℝ) (F H : ι → V → ℝ) (P : Finset V) (C : Finset ι) + (hret : ∀ i ∈ C, F i = H i) (htrace : particleTrace M F P = particleTrace M H P) + (a : State ι V) (ha : a.1 ∈ C) (hpos : weight M F a ≠ 0) (f : State ι V → ℝ) : + action (weight M F) (incoming M F H P C) f a = f a := by + obtain ⟨hn, hr, hc, ht, hs⟩ := incoming_coupling M F H P C hret htrace + unfold action + have he : (∑ b, incoming M F H P C a b * f b) = weight M F a * f a := by + rw [← hr a, Finset.sum_mul] + apply Finset.sum_congr rfl + intro b _ + by_cases hb : a = b + · rw [← hb] + · rw [hs a b ha hb, zero_mul, zero_mul] + rw [he, mul_div_cancel_left₀ _ hpos] + +lemma action_compose {A B C : Type*} [Fintype A] [Fintype B] [Fintype C] + (μ : A → ℝ) (ν : B → ℝ) (J : A → B → ℝ) (K : B → C → ℝ) (f : C → ℝ) : + action μ (ExpandedParticleKernel.compose ν J K) f = action μ J (action ν K f) := by + funext a + unfold action ExpandedParticleKernel.compose + congr 1 + simp_rw [Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + rw [← mul_div_assoc, Finset.mul_sum, Finset.sum_div] + apply Finset.sum_congr rfl + intro c _ + ring + +/-- Departure is symmetric: predictors are reheated by the same kernel. -/ +lemma departure_symmetric (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (i j : ι) : + ∀ a b, departure M F P i j a b = departure M F P i j b a := by + intro a b + unfold departure glueWeights + by_cases h : (departureKey i j a, trace P a) = (departureKey i j b, trace P b) + · simp only [h, ↓reduceIte] + ring + · simp [h, Ne.symm h] + +end BoundedTreewidthL1.ReservedKernel + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/ReservedTests.lean b/lean/OAI/Combinatorics/TreewidthL1/ReservedTests.lean new file mode 100644 index 0000000000000000000000000000000000000000..938383268d4de91b310d369767834959062684fe --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/ReservedTests.lean @@ -0,0 +1,352 @@ +import OAI.Combinatorics.TreewidthL1.ReservedCoupling + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1.ReservedTests +open MeasureTheory ExpandedParticleLaw ReservationCoupling ReservedKernel +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι : Type*} [Fintype V] [Fintype ι] + +noncomputable def part (M : ℝ) (F : ι → V → ℝ) (i : ι) (q : Bool) + (f p : State ι V → ℝ) : ℝ := + ∑ ω : V → Bool, weight M F (i,q,ω) * + (f (i,q,ω)+p (i,q,ω)-2*f (i,q,ω)*p (i,q,ω)) + +lemma part_nonneg (M : ℝ) (F : ι → V → ℝ) (i : ι) (q : Bool) + (f p : State ι V → ℝ) (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) + (hp : ∀ a, 0 ≤ p a ∧ p a ≤ 1) : 0 ≤ part M F i q f p := by + apply Finset.sum_nonneg + intro ω _ + apply mul_nonneg (weight_nonneg _ _ _) + have h₁ := mul_nonneg (hf (i,q,ω)).1 (sub_nonneg.mpr (hp (i,q,ω)).2) + have h₂ := mul_nonneg (hp (i,q,ω)).1 (sub_nonneg.mpr (hf (i,q,ω)).2) + nlinarith + +lemma sum_part (M : ℝ) (F : ι → V → ℝ) (f p : State ι V → ℝ) : + (∑ i, ∑ q, part M F i q f p) = defect (weight M F) f p := by + simp only [defect, part, Fintype.sum_prod_type] + +lemma part_le (M : ℝ) (F : ι → V → ℝ) (i : ι) (q : Bool) + (f p : State ι V → ℝ) (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) + (hp : ∀ a, 0 ≤ p a ∧ p a ≤ 1) : part M F i q f p ≤ defect (weight M F) f p := by + rw [← sum_part] + exact (Finset.single_le_sum (fun b _ => part_nonneg M F i b f p hf hp) + (Finset.mem_univ q)).trans (Finset.single_le_sum + (fun j _ => Finset.sum_nonneg (fun b _ => part_nonneg M F j b f p hf hp)) (Finset.mem_univ i)) + +lemma pair_part_le (M : ℝ) (F : ι → V → ℝ) (i j : ι) (hij : i ≠ j) + (f p : State ι V → ℝ) (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) + (hp : ∀ a, 0 ≤ p a ∧ p a ≤ 1) : + part M F i false f p + part M F j false f p ≤ defect (weight M F) f p := by + rw [← sum_part] + have hb k : part M F k false f p ≤ ∑ q, part M F k q f p := + Finset.single_le_sum (fun b _ => part_nonneg M F k b f p hf hp) (Finset.mem_univ _) + apply (add_le_add (hb i) (hb j)).trans + have he : (∑ k ∈ ({i,j} : Finset ι), ∑ q, part M F k q f p) = + (∑ q, part M F i q f p) + ∑ q, part M F j q f p := by simp [hij] + rw [← he] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun k _ _ => Finset.sum_nonneg (fun q _ => part_nonneg M F k q f p hf hp)) + +lemma part_eq + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] + (M : ℝ) (F : ι → V → ℝ) (i : ι) (f p : State ι V → ℝ) : + part M F i false f p = + OrderedSweepFlow.defect (OrderedReservation.weight M (F i)) + (fun a => f (lift M (F i) i a)) (fun a => p (lift M (F i) i a)) / 2 := by + unfold part OrderedSweepFlow.defect + have he := OrderedReservation.sum_carrier M (F i) + (fun ω => f (i,false,ω)+p (i,false,ω)-2*f (i,false,ω)*p (i,false,ω)) + change (∑ ω : V → Bool, (sweep M (F i)).real {ω}/2 * + (f (i,false,ω)+p (i,false,ω)-2*f (i,false,ω)*p (i,false,ω))) = _ + trans (∑ ω : V → Bool, (sweep M (F i)).real {ω} * + (f (i,false,ω)+p (i,false,ω)-2*f (i,false,ω)*p (i,false,ω)))/2 + · rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + ring + · rw [← he] + rfl + +lemma departure_isCoupling (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (i j : ι) : + IsCoupling (weight M F) (weight M F) (departure M F P i j) := by + obtain ⟨hn,hr,hc,ht,hk⟩ := departure_coupling M F P i j + exact ⟨hn,hr,hc⟩ + +/-- The exact single OLD-particle height test for the real expanded departure +coupling. The suffix is the proved interval-resampling response. -/ +theorem height_test (M : ℝ) (hM : 0 ≤ M) (F : ι → V → ℝ) (P : Finset V) + (i j r : ι) (hir : r ≠ i) (hjr : r ≠ j) + (hF : ∀ v, -M ≤ F r v ∧ F r v ≤ M) (z : V) (bags : List (Finset V)) + (f p : State ι V → ℝ) (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) (hp : ∀ a, 0 ≤ p a ∧ p a ≤ 1) + (hresponse : ∀ a : OrderedReservation.Carrier M (F r), + f (lift M (F r) r a) = OrderedSweepFlow.execute (OrderedReservation.weight M (F r)) + (bags.map (OrderedReservation.traceRank M (F r))) + (OrderedSweepFlow.labelReal (fun a => a.val z)) a) + (t : ℝ) (hlo : t ≤ F r z + M) (hhi : t ≤ M - F r z) + (hgap : ∀ v ∈ P, t ≤ |F r z - F r v|) : + t/2 ≤ defect (weight M F) (action (weight M F) (departure M F P i j) f) p := by + let q := action (weight M F) (departure M F P i j) p + have hQ := departure_isCoupling M F P i j + have hq (a : State ι V) : 0 ≤ q a ∧ q a ≤ 1 := action_bounds hQ p hp a + have ht : ∀ a b : OrderedReservation.Carrier M (F r), + (∀ v : P, a.val v = b.val v) → q (lift M (F r) r a) = q (lift M (F r) r b) := by + intro a b hab + dsimp [q] + rw [departure_action_old M F P i j r hir hjr, departure_action_old M F P i j r hir hjr] + apply OrderedSweepFlow.bath_const_fiber + exact (OrderedReservation.traceRank_fiber M (F r) P a b).mpr hab + have hl := OrderedReservation.sweep_height_transport M hM (F r) hF z P bags + (fun a => q (lift M (F r) r a)) (fun a => hq _) ht t hlo hhi hgap + have he : (fun a : OrderedReservation.Carrier M (F r) => f (lift M (F r) r a)) = + OrderedSweepFlow.execute (OrderedReservation.weight M (F r)) + (bags.map (OrderedReservation.traceRank M (F r))) + (OrderedSweepFlow.labelReal (fun a => a.val z)) := funext hresponse + rw [transfer_defect hQ] + have hs : (fun b a => departure M F P i j a b) = departure M F P i j := by + funext b a + exact departure_symmetric M F P i j a b + rw [hs] + apply le_trans _ (part_le M F r false f q hf hq) + rw [part_eq, he] + exact div_le_div_of_nonneg_right hl (by norm_num) + +lemma sum_marginal_eval {A C : Type*} [Fintype A] [Fintype C] + (key : A → C) (μ : A → ℝ) (g : C → ℝ) : + (∑ a, μ a * g (key a)) = ∑ c, marginal key μ c * g c := by + unfold marginal + simp_rw [Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + simp + +lemma sweep_trace_marginal_eq (M : ℝ) (F H : V → ℝ) (P : Finset V) + (h : ∀ v ∈ P, F v = H v) (b : P → Bool) : + marginal (fun ω : V → Bool => fun v : P => ω v) (fun ω => (sweep M F).real {ω}) b = + marginal (fun ω : V → Bool => fun v : P => ω v) (fun ω => (sweep M H).real {ω}) b := by + unfold marginal + rw [finite_event, finite_event] + rw [sweep, sweep, map_measureReal_apply (measurable_thresholdLabels _) (Set.toFinite _).measurableSet, + map_measureReal_apply (measurable_thresholdLabels _) (Set.toFinite _).measurableSet] + congr 1 + ext t + have he : (fun v : P => thresholdLabels F t v) = (fun v : P => thresholdLabels H t v) := by + funext v + simp [thresholdLabels, h v v.property] + change ((fun v : P => thresholdLabels F t v) = b) ↔ ((fun v : P => thresholdLabels H t v) = b) + rw [he] + +noncomputable def traceAverage (M : ℝ) (F : ι → V → ℝ) (P : Finset V) + (i j : ι) (p : State ι V → ℝ) (c : (ι × Bool) × (P → Bool)) : ℝ := + (∑ b, if (departureKey i j b, trace P b) = c then weight M F b * p b else 0) / + marginal (fun a => (departureKey i j a, trace P a)) (weight M F) c + +lemma action_average (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (i j : ι) + (p : State ι V → ℝ) (a : State ι V) (ha : weight M F a ≠ 0) : + action (weight M F) (departure M F P i j) p a = + traceAverage M F P i j p (departureKey i j a,trace P a) := by + unfold departure + rw [glue_action _ _ _ _ _ _ ha] + unfold traceAverage + congr 1 + apply Finset.sum_congr rfl + intro b _ + split_ifs <;> rfl + +lemma fresh_keys + {V : Type treewidthLevel1} {ι : Type treewidthLevel2} [Fintype V] [Fintype ι] + (i j : ι) (hij : i ≠ j) (q : Bool) (ω : V → Bool) : + departureKey i j (i,q,ω) = (i,q) ∧ departureKey i j (j,q,ω) = (i,q) := by + simp [departureKey, hij] + +lemma fresh_predictor_mean (M : ℝ) (F : ι → V → ℝ) (P : Finset V) + (i j : ι) (hij : i ≠ j) (hbag : ∀ v ∈ P, F i v = F j v) + (p : State ι V → ℝ) : + (∑ ω : V → Bool, weight M F (i,false,ω) * + action (weight M F) (departure M F P i j) p (i,false,ω)) = + ∑ ω : V → Bool, weight M F (j,false,ω) * + action (weight M F) (departure M F P i j) p (j,false,ω) := by + let h (b : P → Bool) := traceAverage M F P i j p ((i,false),b) + have he (r : ι) (hr : r = i ∨ r = j) : + (∑ ω : V → Bool, weight M F (r,false,ω) * + action (weight M F) (departure M F P i j) p (r,false,ω)) = + (∑ ω : V → Bool, (sweep M (F r)).real {ω} * h (fun v : P => ω v))/2 := by + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + by_cases hz : weight M F (r,false,ω) = 0 + · have hz' : (sweep M (F r)).real {ω} = 0 := by simpa [weight] using hz + simp [hz, hz'] + · rw [action_average M F P i j p _ hz] + have hk : departureKey i j (r,false,ω) = (i,false) := by + rcases hr with hr | hr + · rw [hr] + exact (fresh_keys i j hij _ ω).1 + · rw [hr] + exact (fresh_keys i j hij _ ω).2 + simp only [hk, ] + change ((sweep M (F r)).real {ω}/2) * h (fun v : P => ω v) = _ + ring + rw [he i (Or.inl rfl), he j (Or.inr rfl)] + congr 1 + rw [sum_marginal_eval (fun ω : V → Bool => fun v : P => ω v) + (fun ω => (sweep M (F i)).real {ω}) h, + sum_marginal_eval (fun ω : V → Bool => fun v : P => ω v) + (fun ω => (sweep M (F j)).real {ω}) h] + apply Finset.sum_congr rfl + intro b _ + rw [sweep_trace_marginal_eq M (F i) (F j) P hbag] + +lemma part_mean_bound (M : ℝ) (F : ι → V → ℝ) (i : ι) + (f p : State ι V → ℝ) (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) (hp : ∀ a, 0 ≤ p a ∧ p a ≤ 1) : + |(∑ ω : V → Bool, weight M F (i,false,ω)*f (i,false,ω)) - + ∑ ω : V → Bool, weight M F (i,false,ω)*p (i,false,ω)| ≤ part M F i false f p := by + have hl : (∑ ω : V → Bool, weight M F (i,false,ω)*p (i,false,ω)) - + (∑ ω : V → Bool, weight M F (i,false,ω)*f (i,false,ω)) ≤ part M F i false f p := by + rw [← Finset.sum_sub_distrib] + apply Finset.sum_le_sum + intro ω _ + have h := mul_nonneg (weight_nonneg M F (i,false,ω)) + (mul_nonneg (hf (i,false,ω)).1 (sub_nonneg.mpr (hp (i,false,ω)).2)) + nlinarith + have hr : (∑ ω : V → Bool, weight M F (i,false,ω)*f (i,false,ω)) - + (∑ ω : V → Bool, weight M F (i,false,ω)*p (i,false,ω)) ≤ part M F i false f p := by + rw [← Finset.sum_sub_distrib] + apply Finset.sum_le_sum + intro ω _ + have h := mul_nonneg (weight_nonneg M F (i,false,ω)) + (mul_nonneg (hp (i,false,ω)).1 (sub_nonneg.mpr (hf (i,false,ω)).2)) + nlinarith + exact abs_le.mpr ⟨by linarith,hr⟩ + +/-- EXACT fresh pair departure test. Only equal bag values, distinct reserved +indices and the true per-particle suffix means are required. -/ +theorem launch_test (M : ℝ) (F : ι → V → ℝ) (P : Finset V) (i j : ι) + (hij : i ≠ j) (hbag : ∀ v ∈ P, F i v = F j v) (z : V) + (f p : State ι V → ℝ) (hf : ∀ a, 0 ≤ f a ∧ f a ≤ 1) (hp : ∀ a, 0 ≤ p a ∧ p a ≤ 1) + (hi : (∑ ω : V → Bool, weight M F (i,false,ω)*f (i,false,ω)) = (F i z + M)/2) + (hj : (∑ ω : V → Bool, weight M F (j,false,ω)*f (j,false,ω)) = (F j z + M)/2) : + |F i z - F j z|/2 ≤ defect (weight M F) (action (weight M F) (departure M F P i j) f) p := by + let q := action (weight M F) (departure M F P i j) p + have hQ := departure_isCoupling M F P i j + have hq (a : State ι V) : 0 ≤ q a ∧ q a ≤ 1 := action_bounds hQ p hp a + have hm := fresh_predictor_mean M F P i j hij hbag p + have h₁ := part_mean_bound M F i f q hf hq + have h₂ := part_mean_bound M F j f q hf hq + rw [hi] at h₁ + rw [hj] at h₂ + have ha := abs_sub_le ((F i z + M)/2) + (∑ ω : V → Bool, weight M F (i,false,ω)*q (i,false,ω)) ((F j z+M)/2) + rw [abs_sub_comm (∑ ω : V → Bool, weight M F (i,false,ω)*q (i,false,ω))] at ha + change (∑ ω : V → Bool, weight M F (i,false,ω)*q (i,false,ω)) = + (∑ ω : V → Bool, weight M F (j,false,ω)*q (j,false,ω)) at hm + rw [← hm] at h₂ + have hab : |F i z - F j z|/2 ≤ part M F i false f q + part M F j false f q := by + have he : (F i z+M)/2 - (F j z+M)/2 = (F i z-F j z)/2 := by ring + rw [he, abs_div, abs_of_pos (by norm_num : (0:ℝ)<2)] at ha + exact ha.trans (add_le_add h₁ h₂) + rw [transfer_defect hQ] + have hs : (fun b a => departure M F P i j a b) = departure M F P i j := by + funext b a + exact departure_symmetric M F P i j a b + rw [hs] + exact hab.trans (pair_part_le M F i j hij f q hf hq) + +end BoundedTreewidthL1.ReservedTests + +namespace BoundedTreewidthL1.ReservedSuffix +open ExpandedParticleLaw ReservationCoupling ReservedKernel +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V ι : Type*} [Fintype V] [Fintype ι] + +/-- The actual parent departure followed by the actual child incoming update. -/ +noncomputable def edge (M : ℝ) (F H : ι → V → ℝ) (P Q : Finset V) + (i j : ι) (C : Finset ι) : State ι V → State ι V → ℝ := + ExpandedParticleKernel.compose (weight M F) (departure M F P i j) (incoming M F H Q C) + +lemma edge_coupling (M : ℝ) (F H : ι → V → ℝ) (P Q : Finset V) (i j : ι) (C : Finset ι) + (hret : ∀ r ∈ C, F r = H r) (htrace : particleTrace M F Q = particleTrace M H Q) : + IsCoupling (weight M F) (weight M H) (edge M F H P Q i j C) := by + obtain ⟨hd, hdr, hdc, _, _⟩ := departure_coupling M F P i j + obtain ⟨hi, hir, hic, _, _⟩ := incoming_coupling M F H Q C hret htrace + obtain ⟨hn,hr,hc⟩ := ExpandedParticleKernel.compose_coupling (weight M F) (weight M F) + (weight M H) (departure M F P i j) (incoming M F H Q C) + (weight_nonneg M F) (weight_nonneg M F) (weight_nonneg M H) hd hi hdr hdc hir hic + exact ⟨hn,hr,hc⟩ + +lemma edge_restrict (M : ℝ) (F H : ι → V → ℝ) (P Q : Finset V) (i j r : ι) (C : Finset ι) + (hir : r ≠ i) (hjr : r ≠ j) (hrC : r ∈ C) + (hret : ∀ r ∈ C, F r = H r) (htrace : particleTrace M F Q = particleTrace M H Q) + (a : OrderedReservation.Carrier M (F r)) (f : State ι V → ℝ) : + action (weight M F) (edge M F H P Q i j C) f (lift M (F r) r a) = + OrderedSweepFlow.bath (OrderedReservation.weight M (F r)) + (OrderedReservation.traceRank M (F r) P) (fun b => f (lift M (F r) r b)) a := by + rw [edge, action_compose, departure_action_old M F P i j r hir hjr] + congr 1 + funext b + exact incoming_action_retained M F H Q C hret htrace _ hrC + (ne_of_gt (div_pos b.property (by norm_num))) f + +noncomputable def kernels (M : ℝ) (F : ℕ → ι → V → ℝ) (P : ℕ → Finset V) + (fresh₁ fresh₂ : ℕ → ι) (C : ℕ → Finset ι) (t : ℕ) := + edge M (F t) (F (t+1)) (P t) (P (t+1)) (fresh₁ t) (fresh₂ t) (C t) + +noncomputable def bags (P : ℕ → Finset V) (t n : ℕ) : List (Finset V) := + (List.range n).map (fun s => P (t+s)) + +lemma bags_succ + {V : Type treewidthLevel1} [Fintype V] + (P : ℕ → Finset V) (t n : ℕ) : + bags P t (n+1) = P t :: bags P (t+1) n := by + simp only [bags, List.range_succ_eq_map, List.map_cons, Nat.add_zero, List.map_map] + congr 2 + funext s + simp only [Function.comp_apply] + congr 1 + omega + +/-- A reserved old particle's true suffix response is exactly a sequence of +ordered interval heat baths. All transitions are the expanded preparation ones. -/ +theorem response_restrict (M : ℝ) (F : ℕ → ι → V → ℝ) (P : ℕ → Finset V) + (fresh₁ fresh₂ : ℕ → ι) (C : ℕ → Finset ι) + (hret : ∀ s r, r ∈ C s → F s r = F (s+1) r) + (htrace : ∀ s, particleTrace M (F s) (P (s+1)) = particleTrace M (F (s+1)) (P (s+1))) + (t n : ℕ) (r : ι) (G : V → ℝ) + (hfixed : ∀ s, t ≤ s → s ≤ t+n → F s r = G) + (hkeep : ∀ s, t ≤ s → s < t+n → r ∈ C s ∧ r ≠ fresh₁ s ∧ r ≠ fresh₂ s) + (z : V) (a : OrderedReservation.Carrier M G) : + response (fun s => weight M (F s)) (kernels M F P fresh₁ fresh₂ C) t n + (fun b => if label b z then 1 else 0) (lift M G r a) = + OrderedSweepFlow.execute (OrderedReservation.weight M G) + ((bags P t n).map (OrderedReservation.traceRank M G)) + (OrderedSweepFlow.labelReal (fun b => b.val z)) a := by + induction n generalizing t a with + | zero => rfl + | succ n ih => + have ht : F t r = G := hfixed t le_rfl (by omega) + subst G + have hk := hkeep t le_rfl (by omega) + change action (weight M (F t)) (kernels M F P fresh₁ fresh₂ C t) + (response (fun s => weight M (F s)) (kernels M F P fresh₁ fresh₂ C) (t+1) n + (fun b => if label b z then 1 else 0)) (lift M (F t r) r a) = _ + unfold kernels + rw [edge_restrict M (F t) (F (t+1)) (P t) (P (t+1)) (fresh₁ t) (fresh₂ t) r (C t) + hk.2.1 hk.2.2 hk.1 (hret t) (htrace t)] + have hfixed' : ∀ s, t+1 ≤ s → s ≤ (t+1)+n → F s r = F t r := by + intro s hs hs' + exact hfixed s (by omega) (by omega) + have hkeep' : ∀ s, t+1 ≤ s → s < (t+1)+n → r ∈ C s ∧ r ≠ fresh₁ s ∧ r ≠ fresh₂ s := by + intro s hs hs' + exact hkeep s (by omega) (by omega) + rw [bags_succ, List.map_cons, OrderedSweepFlow.execute] + congr 1 + funext b + exact ih (t+1) hfixed' hkeep' b +end BoundedTreewidthL1.ReservedSuffix + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/TreeGeometry.lean b/lean/OAI/Combinatorics/TreewidthL1/TreeGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ac3c2a229e081f598387537404d23af46c72b3b --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/TreeGeometry.lean @@ -0,0 +1,555 @@ +import OAI.Combinatorics.TreewidthL1.ExpandedAnchor + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 + +namespace BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I : Type*} (T : SimpleGraph I) (hT : T.IsTree) (root X : I) +lemma downPath_take (t : ℕ) : + downPath T hT root ((downPath T hT root X).getVert t) = + (downPath T hT root X).take t := by + exact congrArg Subtype.val ((hT.isAcyclic.subsingleton_path _ _).elim + ⟨_, downPath_isPath T hT root _⟩ ⟨_, (downPath_isPath T hT root X).take t⟩) +lemma depth_getVert (t : ℕ) (ht : t ≤ (forest T hT root).depth X) : + (forest T hT root).depth ((downPath T hT root X).getVert t) = t := by + rw [← downPath_length, downPath_take, SimpleGraph.Walk.take_length,downPath_length] + exact min_eq_left ht +lemma downPath_getVert_getVert (t a : ℕ) (ha : a ≤ t) : + (downPath T hT root ((downPath T hT root X).getVert t)).getVert a = + (downPath T hT root X).getVert a := by + rw [downPath_take,SimpleGraph.Walk.take_getVert,inf_eq_right.mpr ha] +lemma parent_getVert (t : ℕ) (ht : t < (forest T hT root).depth X) : + (forest T hT root).parent ((downPath T hT root X).getVert (t+1)) = + some ((downPath T hT root X).getVert t) := by + have hadj : T.Adj ((downPath T hT root X).getVert t) + ((downPath T hT root X).getVert (t+1)) := + (downPath T hT root X).adj_getVert_succ (by simpa [downPath_length] using ht) + rcases edge_orientation T hT root hadj with h | h + · have hdec := (forest T hT root).decreases _ _ h + rw [depth_getVert T hT root X t (by omega),depth_getVert T hT root X (t+1) (by omega)] at hdec + omega + · exact h +end BoundedTreewidthL1.RootedTree + +namespace BoundedTreewidthL1.TreeCache +open AnchorCache _root_.OAI.BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V : Type*} (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (X : I) +lemma inclusive_getVert (t : ℕ) (ht : t ≤ (forest T hT root).depth X) : + inclusive T hT root B D k d J ((downPath T hT root X).getVert t) = + inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J t := by + unfold inclusive + rw [depth_getVert T hT root X t ht] + apply inclusiveCache_prefix (l := t+1) + · intro a ha + unfold bags + rw [downPath_getVert_getVert T hT root X t a (by omega)] + · intro a ha v b hb + unfold heights + rw [downPath_getVert_getVert T hT root X t b (by omega)] + · omega +lemma active_getVert (t : ℕ) (ht : t ≤ (forest T hT root).depth X) : + active T hT root B D k d J ((downPath T hT root X).getVert t) = + (inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J t).image + (downPath T hT root X).getVert := by + unfold active + rw [inclusive_getVert T hT root B D k d J X t ht] + apply Finset.image_congr + intro a ha + exact downPath_getVert_getVert T hT root X t a (inclusive_age _ _ _ _ _ t a ha) +end BoundedTreewidthL1.TreeCache + +namespace BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I : Type*} (T : SimpleGraph I) (hT : T.IsTree) (Y Z : I) +noncomputable def pathIndex : Fin ((forest T hT Y).depth Z + 1) ↪ I where + toFun t := (downPath T hT Y Z).getVert t.val + inj' := by + intro a b he + apply Fin.ext + have ha := depth_getVert T hT Y Z a.val (by omega) + have hb := depth_getVert T hT Y Z b.val (by omega) + dsimp only at he + rw [he] at ha + omega +lemma pathIndex_comap : T.comap (pathIndex T hT Y Z) = + SimpleGraph.pathGraph ((forest T hT Y).depth Z + 1) := by + ext i j + rw [SimpleGraph.pathGraph_adj] + constructor + · intro hij + have hd := hT.dist_eq_dist_add_one_of_adj Y hij + have hi := depth_getVert T hT Y Z i.val (by omega) + have hj := depth_getVert T hT Y Z j.val (by omega) + change T.dist ((downPath T hT Y Z).getVert i.val) Y = i.val at hi + change T.dist ((downPath T hT Y Z).getVert j.val) Y = j.val at hj + change T.dist Y ((downPath T hT Y Z).getVert i.val) = + T.dist Y ((downPath T hT Y Z).getVert j.val) + 1 ∨ + T.dist Y ((downPath T hT Y Z).getVert j.val) = + T.dist Y ((downPath T hT Y Z).getVert i.val) + 1 at hd + rw [SimpleGraph.dist_comm (u := Y),SimpleGraph.dist_comm (u := Y),hi,hj] at hd + omega + · rintro (h | h) + · change T.Adj ((downPath T hT Y Z).getVert i.val) ((downPath T hT Y Z).getVert j.val) + rw [← h] + exact (downPath T hT Y Z).adj_getVert_succ (by rw [downPath_length]; omega) + · change T.Adj ((downPath T hT Y Z).getVert i.val) ((downPath T hT Y Z).getVert j.val) + rw [← h] + exact ((downPath T hT Y Z).adj_getVert_succ (by rw [downPath_length]; omega)).symm +end BoundedTreewidthL1.RootedTree + +namespace BoundedTreewidthL1.ExpandedTree +open ReservationCoupling +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I A : Type*} [Fintype I] [Fintype A] +noncomputable def pathJoint (T : SimpleGraph I) (μ : I → A → ℝ) + (J : I → I → A → A → ℝ) {Y Z : I} (p : T.Walk Y Z) (s : ℕ) (a b : A) : ℝ := + if s < p.length then J (p.getVert s) (p.getVert (s+1)) a b + else if a = b then μ (p.getVert s) a else 0 +lemma pathJoint_coupling + {I : Type treewidthLevel1} {A : Type treewidthLevel2} [Fintype I] [Fintype A] + (T : SimpleGraph I) (μ : I → A → ℝ) + (J : I → I → A → A → ℝ) (hμ : ∀ i a, 0 ≤ μ i a) + (hJ : ∀ i j, T.Adj i j → IsCoupling (μ i) (μ j) (J i j)) + {Y Z : I} (p : T.Walk Y Z) (s : ℕ) : + IsCoupling (μ (p.getVert s)) (μ (p.getVert (s+1))) (pathJoint T μ J p s) := by + by_cases hs : s < p.length + · change IsCoupling _ _ (fun a b => if s < p.length then _ else _) + simp only [ite_eq_left hs] + exact hJ _ _ (p.adj_getVert_succ hs) + · have he : p.getVert (s+1) = p.getVert s := by + rw [p.getVert_of_length_le (by omega),p.getVert_of_length_le (by omega)] + rw [he] + refine ⟨?_,?_,?_⟩ + · intro a b; simp only [pathJoint,ite_eq_right hs]; split_ifs <;> first | exact hμ _ _ | exact le_rfl + · intro a; simp [pathJoint,hs] + · intro b; simp [pathJoint,hs] + +/-- Restriction of an actual tree law to its unique endpoint path, in the +un-normalized coupling-product convention used by the reservation tests. -/ +lemma endpoint_path_product (T : SimpleGraph I) (hT : T.IsTree) (M : ℝ) (hM : 0 < M) + (μ : I → A → ℝ) (J : I → I → A → A → ℝ) (hs : TreeMarkov.Symmetric (fun _ : I => A) J) + (hμ : ∀ i a, 0 ≤ μ i a) (hmass : ∀ i, (∑ a, μ i a) = M) + (hJ : ∀ i j, T.Adj i j → IsCoupling (μ i) (μ j) (J i j)) + (Y Z : I) (f : A → A → ℝ) : + (∑ x : I → A, law T M μ J hs x * f (x Y) (x Z)) = + ∑ x : Fin ((RootedTree.forest T hT Y).depth Z + 1) → A, + MarkovProduct.weight (fun _ => A) (μ Y) + (MarkovProduct.couplingKernel (fun _ => A) + (fun s => μ ((RootedTree.downPath T hT Y Z).getVert s)) + (pathJoint T μ J (RootedTree.downPath T hT Y Z))) + ((RootedTree.forest T hT Y).depth Z) x * + f (x 0) (x (Fin.last ((RootedTree.forest T hT Y).depth Z))) := by + let p := RootedTree.downPath T hT Y Z + let n := (RootedTree.forest T hT Y).depth Z + let e := RootedTree.pathIndex T hT Y Z + have he := RootedTree.pathIndex_comap T hT Y Z + have hep : e 0 = Y := p.getVert_zero + have hez : e (Fin.last n) = Z := by + change p.getVert ((RootedTree.forest T hT Y).depth Z) = Z + rw [← RootedTree.downPath_length T hT Y Z] + exact p.getVert_length + have hc : (T.comap e).Connected := he ▸ SimpleGraph.pathGraph_connected n + have hpath := path_expectation T hT M hM μ J hs hμ hmass + (fun i j hij => (hJ i j hij).nonneg) (fun i j hij => (hJ i j hij).row) + e hc (fun x => f (x 0) (x (Fin.last n))) + simp only [Function.comp_apply,hep,hez] at hpath + rw [hpath] + apply Finset.sum_congr (by ext x; simp) + intro x _ + congr 1 + rw [he] + have hq := pathJoint_coupling T μ J hμ hJ p + have hp := law_path_product M hM (fun s => μ (p.getVert s)) (pathJoint T μ J p) + (fun s => (hq s).nonneg) (fun s => (hq s).row) (fun s => (hq s).col) n + (fun i j => J (e i) (e j)) (fun i j => hs (e i) (e j)) + (by + intro i a b + simp only [pathJoint] + rw [ite_eq_left (show i.val < p.length by rw [RootedTree.downPath_length]; exact i.isLt)] + rfl) x + convert hp using 1 + · congr 1 + · simp only [p,SimpleGraph.Walk.getVert_zero]; congr 1 +end BoundedTreewidthL1.ExpandedTree + +namespace BoundedTreewidthL1.ExpandedConstruction +open ExpandedParticleLaw ReservationCoupling +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V ι : Type*} [Fintype I] [Fintype V] [Fintype ι] +lemma ensemble_endpoint (T : SimpleGraph I) (hT : T.IsTree) (parent : I → Option I) + (horient : ∀ i j, T.Adj i j → parent i = some j ∨ parent j = some i) + (hanti : ∀ i j, parent i = some j → parent j ≠ some i) + (M : ℝ) (hM : 0 < M) (hι : 0 < Fintype.card ι) + (F : I → ι → V → ℝ) (B : I → Finset V) + (hcover : ∀ v, ∃ i, v ∈ B i) (hrun : ∀ v, (T.induce {i | v ∈ B i}).Preconnected) + (fresh₁ fresh₂ : I → ι) (C : I → Finset ι) + (hret : ∀ i j, parent j = some i → ∀ r ∈ C j, F i r = F j r) + (htrace : ∀ i j, parent j = some i → particleTrace M (F i) (B j) = particleTrace M (F j) (B j)) + (Y Z : I) (y z : V) (hy : y ∈ B Y) (hz : z ∈ B Z) : + cutDistance (ensemble T parent hanti M F B fresh₁ fresh₂ C) + (ExpandedTree.assemble (fun i => (B i : Set V)) hcover label) y z = + ExpandedPathTests.distance M (fun s => F ((RootedTree.downPath T hT Y Z).getVert s)) + (ExpandedTree.pathJoint T (fun i => weight M (F i)) + (joints parent M F B fresh₁ fresh₂ C) (RootedTree.downPath T hT Y Z)) + ((RootedTree.forest T hT Y).depth Z) y z := by + have hm : 0 < (Fintype.card ι : ℝ)*(2*M) := mul_pos (by exact_mod_cast hι) (by positivity) + have he : cutDistance (ensemble T parent hanti M F B fresh₁ fresh₂ C) + (ExpandedTree.assemble (fun i => (B i : Set V)) hcover label) y z = + ∑ x : I → State ι V, ensemble T parent hanti M F B fresh₁ fresh₂ C x * + (if label (x Y) y = label (x Z) z then 0 else 1) := by + unfold cutDistance + apply Finset.sum_congr rfl + intro x _ + by_cases hx : ensemble T parent hanti M F B fresh₁ fresh₂ C x = 0 + · simp [hx] + · rw [ensemble_labels T parent horient hanti M F B hcover hrun fresh₁ fresh₂ C hret htrace x hx Y y hy, + ensemble_labels T parent horient hanti M F B hcover hrun fresh₁ fresh₂ C hret htrace x hx Z z hz] + split_ifs <;> simp + rw [he] + have hp := ExpandedTree.endpoint_path_product T hT _ hm (fun i => weight M (F i)) + (joints parent M F B fresh₁ fresh₂ C) (joints_symmetric parent hanti M F B fresh₁ fresh₂ C) + (fun i => weight_nonneg M (F i)) (fun i => weight_total M hM.le (F i)) + (joints_coupling T parent horient hanti M F B fresh₁ fresh₂ C hret htrace) Y Z + (fun a b => if label a y = label b z then 0 else 1) + simpa only [ensemble,ExpandedPathTests.distance,SimpleGraph.Walk.getVert_zero] using hp +end BoundedTreewidthL1.ExpandedConstruction + +namespace BoundedTreewidthL1.RootedTree +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I : Type*} (T : SimpleGraph I) (hT : T.IsTree) (root X Y : I) +lemma append_path {u v w : I} (p : T.Walk u v) (q : T.Walk v w) + (hp : p.IsPath) (hq : q.IsPath) + (hcommon : ∀ z, z ∈ p.support → z ∈ q.support → z = v) : (p.append q).IsPath := by + rw [SimpleGraph.Walk.isPath_def,SimpleGraph.Walk.support_append,List.nodup_append] + refine ⟨hp.support_nodup,hq.support_nodup.tail,?_⟩ + intro z hz w hzq heq + subst w + have he := hcommon z hz (List.mem_of_mem_tail hzq) + subst z + have hn := hq.support_nodup + rw [← q.cons_tail_support,List.nodup_cons] at hn + exact hn.1 hzq + +/-- The common root prefixes terminate at one finite, deterministic index. -/ +lemma exists_join_index : ∃ s : ℕ, + s ≤ (forest T hT root).depth X ∧ s ≤ (forest T hT root).depth Y ∧ + (downPath T hT root X).getVert s = (downPath T hT root Y).getVert s ∧ + ∀ a b, a ≤ (forest T hT root).depth X → b ≤ (forest T hT root).depth Y → + (downPath T hT root X).getVert a = (downPath T hT root Y).getVert b → a = b ∧ a ≤ s := by + let C := (Finset.range ((forest T hT root).depth X+1)).filter (fun a => + a ≤ (forest T hT root).depth Y ∧ + (downPath T hT root X).getVert a = (downPath T hT root Y).getVert a) + have h0 : 0 ∈ C := by simp [C] + let s := C.max' ⟨0,h0⟩ + have hs : s ∈ C := Finset.max'_mem C ⟨0,h0⟩ + have hsm := Finset.mem_filter.mp hs + refine ⟨s,by simpa only [Finset.mem_range,Nat.lt_succ_iff] using hsm.1,hsm.2.1,hsm.2.2,?_⟩ + intro a b ha hb he + have hda := depth_getVert T hT root X a ha + have hdb := depth_getVert T hT root Y b hb + have hab : a = b := by rw [he] at hda; omega + refine ⟨hab,?_⟩ + apply Finset.le_max' + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_range.mpr (by omega),?_⟩ + subst b + exact ⟨hb,he⟩ + +/-- At the meet, the two descending arms form exactly the unique Y--X path. -/ +lemma path_at_join (s : ℕ) + (hsx : s ≤ (forest T hT root).depth X) (hsy : s ≤ (forest T hT root).depth Y) + (hs : (downPath T hT root X).getVert s = (downPath T hT root Y).getVert s) + (hmax : ∀ a b, a ≤ (forest T hT root).depth X → b ≤ (forest T hT root).depth Y → + (downPath T hT root X).getVert a = (downPath T hT root Y).getVert b → a = b ∧ a ≤ s) : + downPath T hT Y X = + (((downPath T hT root Y).drop s).reverse.copy rfl hs.symm).append + ((downPath T hT root X).drop s) := by + apply congrArg Subtype.val ((hT.isAcyclic.subsingleton_path Y X).elim + ⟨_,downPath_isPath T hT Y X⟩ ⟨_,?_⟩) + apply append_path + · simpa only [SimpleGraph.Walk.isPath_copy] using ((downPath_isPath T hT root Y).drop s).reverse + · exact (downPath_isPath T hT root X).drop s + · intro z hzy hzx + simp only [SimpleGraph.Walk.support_copy,SimpleGraph.Walk.support_reverse,List.mem_reverse] at hzy + obtain ⟨a,hae,hal⟩ := SimpleGraph.Walk.mem_support_iff_exists_getVert.mp hzx + obtain ⟨b,hbe,hbl⟩ := SimpleGraph.Walk.mem_support_iff_exists_getVert.mp hzy + rw [SimpleGraph.Walk.drop_getVert] at hae hbe + have ha : s+a ≤ (forest T hT root).depth X := by + rw [SimpleGraph.Walk.drop_length,downPath_length] at hal; omega + have hb : s+b ≤ (forest T hT root).depth Y := by + rw [SimpleGraph.Walk.drop_length,downPath_length] at hbl; omega + have hab := hmax (s+a) (s+b) ha hb (hae.trans hbe.symm) + have haz : a = 0 := by omega + subst a + simpa only [Nat.add_zero] using hae.symm + +lemma join_suffix (s : ℕ) + (hsx : s ≤ (forest T hT root).depth X) (hsy : s ≤ (forest T hT root).depth Y) + (hs : (downPath T hT root X).getVert s = (downPath T hT root Y).getVert s) + (hmax : ∀ a b, a ≤ (forest T hT root).depth X → b ≤ (forest T hT root).depth Y → + (downPath T hT root X).getVert a = (downPath T hT root Y).getVert b → a = b ∧ a ≤ s) + (a : ℕ) : + (downPath T hT Y X).getVert ((forest T hT root).depth Y-s+a) = + (downPath T hT root X).getVert (s+a) := by + rw [path_at_join T hT root X Y s hsx hsy hs hmax, + SimpleGraph.Walk.getVert_append,SimpleGraph.Walk.length_copy, + SimpleGraph.Walk.length_reverse,SimpleGraph.Walk.drop_length,downPath_length] + rw [ite_eq_right (by omega),Nat.add_sub_cancel_left,SimpleGraph.Walk.drop_getVert] + +lemma join_length (s : ℕ) + (hsx : s ≤ (forest T hT root).depth X) (hsy : s ≤ (forest T hT root).depth Y) + (hs : (downPath T hT root X).getVert s = (downPath T hT root Y).getVert s) + (hmax : ∀ a b, a ≤ (forest T hT root).depth X → b ≤ (forest T hT root).depth Y → + (downPath T hT root X).getVert a = (downPath T hT root Y).getVert b → a = b ∧ a ≤ s) : + (forest T hT Y).depth X = (forest T hT root).depth Y-s + ((forest T hT root).depth X-s) := by + rw [← downPath_length,path_at_join T hT root X Y s hsx hsy hs hmax] + simp only [SimpleGraph.Walk.length_append,SimpleGraph.Walk.length_copy, + SimpleGraph.Walk.length_reverse,SimpleGraph.Walk.drop_length,downPath_length] +end BoundedTreewidthL1.RootedTree + +namespace BoundedTreewidthL1.ExpandedConstruction +open ExpandedParticleLaw ReservationCoupling ReservedSuffix +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V ι : Type*} [Fintype I] [Fintype V] [Fintype ι] +/-- Data of the actual constructed ensemble. Retention and trace identities +are verified by the particle recursion, not axioms about its endpoint map. -/ +structure TreeData (T : SimpleGraph I) (M : ℝ) where + parent : I → Option I + orient : ∀ i j, T.Adj i j → parent i = some j ∨ parent j = some i + anti : ∀ i j, parent i = some j → parent j ≠ some i + F : I → ι → V → ℝ + B : I → Finset V + cover : ∀ v, ∃ i, v ∈ B i + run : ∀ v, (T.induce {i | v ∈ B i}).Preconnected + fresh₁ : I → ι + fresh₂ : I → ι + C : I → Finset ι + retained : ∀ i j, parent j = some i → ∀ r ∈ C j, F i r = F j r + trace : ∀ i j, parent j = some i → particleTrace M (F i) (B j) = particleTrace M (F j) (B j) +namespace TreeData +variable {T : SimpleGraph I} {M : ℝ} (D : TreeData (V := V) (ι := ι) T M) +noncomputable def dist (y z : V) : ℝ := + cutDistance (ensemble T D.parent D.anti M D.F D.B D.fresh₁ D.fresh₂ D.C) + (ExpandedTree.assemble (fun i => (D.B i : Set V)) D.cover label) y z +noncomputable def chain (hT : T.IsTree) (Y Z : I) := + ExpandedTree.pathJoint T (fun i => weight M (D.F i)) + (joints D.parent M D.F D.B D.fresh₁ D.fresh₂ D.C) (RootedTree.downPath T hT Y Z) +lemma chain_coupling (hT : T.IsTree) (Y Z : I) (s : ℕ) : + IsCoupling (weight M (D.F ((RootedTree.downPath T hT Y Z).getVert s))) + (weight M (D.F ((RootedTree.downPath T hT Y Z).getVert (s+1)))) (D.chain hT Y Z s) := + ExpandedTree.pathJoint_coupling T _ _ (fun i => weight_nonneg M (D.F i)) + (joints_coupling T D.parent D.orient D.anti M D.F D.B D.fresh₁ D.fresh₂ D.C D.retained D.trace) _ s +lemma chain_eq (hT : T.IsTree) (Y Z : I) (s : ℕ) + (hs : s < (RootedTree.forest T hT Y).depth Z) + (hp : D.parent ((RootedTree.downPath T hT Y Z).getVert (s+1)) = + some ((RootedTree.downPath T hT Y Z).getVert s)) : + D.chain hT Y Z s = kernels M + (fun s => D.F ((RootedTree.downPath T hT Y Z).getVert s)) + (fun s => D.B ((RootedTree.downPath T hT Y Z).getVert s)) + (fun s => D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert s)) + (fun s => D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert s)) + (fun s => D.C ((RootedTree.downPath T hT Y Z).getVert (s+1))) s := by + funext a b + simp only [chain, ExpandedTree.pathJoint, RootedTree.downPath_length, ite_eq_left hs, kernels] + exact congrFun (congrFun (joints_eq D.parent M D.F D.B D.fresh₁ D.fresh₂ D.C _ _ hp) a) b +lemma height_test (hT : T.IsTree) (hM : 0 < M) (hι : 0 < Fintype.card ι) + (Y Z : I) (y z : V) (hy : y ∈ D.B Y) (hz : z ∈ D.B Z) + (t : ℕ) (ht : t < (RootedTree.forest T hT Y).depth Z) (r : ι) + (hdown : ∀ s, t ≤ s → s < (RootedTree.forest T hT Y).depth Z → + D.parent ((RootedTree.downPath T hT Y Z).getVert (s+1)) = + some ((RootedTree.downPath T hT Y Z).getVert s)) + (hfixed : ∀ s, t ≤ s → s ≤ (RootedTree.forest T hT Y).depth Z → + D.F ((RootedTree.downPath T hT Y Z).getVert s) r = D.F ((RootedTree.downPath T hT Y Z).getVert t) r) + (hkeep : ∀ s, t ≤ s → s < (RootedTree.forest T hT Y).depth Z → + r ∈ D.C ((RootedTree.downPath T hT Y Z).getVert (s+1)) ∧ + r ≠ D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert s) ∧ + r ≠ D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert s)) + (hF : ∀ v, -M ≤ D.F ((RootedTree.downPath T hT Y Z).getVert t) r v ∧ + D.F ((RootedTree.downPath T hT Y Z).getVert t) r v ≤ M) + (ε : ℝ) (hlo : ε ≤ D.F ((RootedTree.downPath T hT Y Z).getVert t) r z+M) + (hhi : ε ≤ M-D.F ((RootedTree.downPath T hT Y Z).getVert t) r z) + (hgap : ∀ v ∈ D.B ((RootedTree.downPath T hT Y Z).getVert t), + ε ≤ |D.F ((RootedTree.downPath T hT Y Z).getVert t) r z- + D.F ((RootedTree.downPath T hT Y Z).getVert t) r v|) : ε/2 ≤ D.dist y z := by + rw [dist, ensemble_endpoint T hT D.parent D.orient D.anti M hM hι D.F D.B D.cover D.run + D.fresh₁ D.fresh₂ D.C D.retained D.trace Y Z y z hy hz] + let N := (RootedTree.forest T hT Y).depth Z + have he : N = t+((N-t-1)+1) := by omega + nth_rw 1 [show (RootedTree.forest T hT Y).depth Z = t+((N-t-1)+1) from he] + apply ExpandedPathTests.height_test M hM.le _ _ _ _ _ _ (D.chain_coupling hT Y Z) + t (N-t-1) r + · intro s hs hs'; exact D.chain_eq hT Y Z s (by omega) (hdown s hs (by omega)) + · intro s hs hs'; exact D.retained _ _ (hdown s hs (by omega)) + · intro s hs hs'; exact D.trace _ _ (hdown s hs (by omega)) + · intro s hs hs'; exact hfixed s hs (by omega) + · intro s hs hs'; exact hkeep s hs (by omega) + · exact hF + · exact hlo + · exact hhi + · exact hgap +lemma launch_test (hT : T.IsTree) (hM : 0 < M) (hι : 0 < Fintype.card ι) + (Y Z : I) (y z : V) (hy : y ∈ D.B Y) (hz : z ∈ D.B Z) + (t : ℕ) (ht : t < (RootedTree.forest T hT Y).depth Z) + (hdown : ∀ s, t ≤ s → s < (RootedTree.forest T hT Y).depth Z → + D.parent ((RootedTree.downPath T hT Y Z).getVert (s+1)) = + some ((RootedTree.downPath T hT Y Z).getVert s)) + (hij : D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert t) ≠ D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert t)) + (hbag : ∀ v ∈ D.B ((RootedTree.downPath T hT Y Z).getVert t), + D.F ((RootedTree.downPath T hT Y Z).getVert t) (D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert t)) v = + D.F ((RootedTree.downPath T hT Y Z).getVert t) (D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert t)) v) + (hfixed : ∀ r ∈ ({D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert t), + D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert t)} : Finset ι), + ∀ s, t ≤ s → s ≤ (RootedTree.forest T hT Y).depth Z → + D.F ((RootedTree.downPath T hT Y Z).getVert s) r = D.F ((RootedTree.downPath T hT Y Z).getVert t) r) + (hinit : D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert t) ∈ D.C ((RootedTree.downPath T hT Y Z).getVert (t+1)) ∧ + D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert t) ∈ D.C ((RootedTree.downPath T hT Y Z).getVert (t+1))) + (hkeep : ∀ r ∈ ({D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert t), + D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert t)} : Finset ι), + ∀ s, t+1 ≤ s → s < (RootedTree.forest T hT Y).depth Z → + r ∈ D.C ((RootedTree.downPath T hT Y Z).getVert (s+1)) ∧ + r ≠ D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert s) ∧ + r ≠ D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert s)) + (hF : ∀ r ∈ ({D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert t), + D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert t)} : Finset ι), ∀ v, + -M ≤ D.F ((RootedTree.downPath T hT Y Z).getVert t) r v ∧ D.F ((RootedTree.downPath T hT Y Z).getVert t) r v ≤ M) : + |D.F ((RootedTree.downPath T hT Y Z).getVert t) (D.fresh₁ ((RootedTree.downPath T hT Y Z).getVert t)) z - + D.F ((RootedTree.downPath T hT Y Z).getVert t) (D.fresh₂ ((RootedTree.downPath T hT Y Z).getVert t)) z|/2 ≤ D.dist y z := by + rw [dist, ensemble_endpoint T hT D.parent D.orient D.anti M hM hι D.F D.B D.cover D.run + D.fresh₁ D.fresh₂ D.C D.retained D.trace Y Z y z hy hz] + let N := (RootedTree.forest T hT Y).depth Z + have he : N = t+((N-t-1)+1) := by omega + nth_rw 1 [show (RootedTree.forest T hT Y).depth Z = t+((N-t-1)+1) from he] + apply ExpandedPathTests.launch_test M hM.le _ + (fun s => D.B ((RootedTree.downPath T hT Y Z).getVert s)) _ _ + (fun s => D.C ((RootedTree.downPath T hT Y Z).getVert (s+1))) _ (D.chain_coupling hT Y Z) + t (N-t-1) hij hbag + · intro s hs hs'; exact D.chain_eq hT Y Z s (by omega) (hdown s hs (by omega)) + · intro s hs hs'; exact D.retained _ _ (hdown s hs (by omega)) + · intro s hs hs'; exact D.trace _ _ (hdown s hs (by omega)) + · intro r hr s hs hs'; exact hfixed r hr s hs (by omega) + · exact hinit + · intro r hr s hs hs'; exact hkeep r hr s hs (by omega) + · exact hF +end TreeData +end BoundedTreewidthL1.ExpandedConstruction + +namespace BoundedTreewidthL1.TreeCache +open _root_.OAI.BoundedTreewidthL1.RootedTree AnchorCache ParticleBatch +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I V ι : Type*} (T : SimpleGraph I) (hT : T.IsTree) (root : I) + (B : I → Finset V) (D : I → V → ℝ) (k : ℕ) (d : V → V → ℝ) (J : ℝ) (X : I) +lemma active_on_path (e a t : ℕ) (he : e ≤ (forest T hT root).depth X) + (ha : a ∈ inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J e) + (hat : a ≤ t) (hte : t ≤ e) : + (downPath T hT root X).getVert a ∈ + active T hT root B D k d J ((downPath T hT root X).getVert t) := by + rw [active_getVert T hT root B D k d J X t (hte.trans he)] + exact Finset.mem_image.mpr ⟨a, inclusive_backwards k _ d _ J hat hte ha, rfl⟩ +lemma active_self (i : I) : i ∈ active T hT root B D k d J i := by + unfold active + apply Finset.mem_image.mpr + refine ⟨(forest T hT root).depth i, inclusive_self k _ d _ J _, ?_⟩ + rw [← downPath_length] + exact SimpleGraph.Walk.getVert_length _ +lemma path_ne (a t : ℕ) (ha : a ≤ (forest T hT root).depth X) + (ht : t ≤ (forest T hT root).depth X) (hat : a ≠ t) : + (downPath T hT root X).getVert a ≠ (downPath T hT root X).getVert t := by + intro h + have hd := congrArg (forest T hT root).depth h + rw [depth_getVert T hT root X a ha,depth_getVert T hT root X t ht] at hd + exact hat hd +/-- The actual inclusive tree cache transports an anchor's entire function and +its indices throughout every interval up to its last active bag. -/ +lemma pair_transport (S : I → (ι → V → ℝ) × (I → ι × ι)) + (hpairs : ∀ i p, (forest T hT root).parent i = some p → + ∀ a ∈ active T hT root B D k d J i ∩ active T hT root B D k d J p, + (S i).2 a = (S p).2 a ∧ + (S i).1 ((S i).2 a).1 = (S p).1 ((S p).2 a).1 ∧ + (S i).1 ((S i).2 a).2 = (S p).1 ((S p).2 a).2) + (e a t : ℕ) (he : e ≤ (forest T hT root).depth X) + (ha : a ∈ inclusiveCache k (bags T hT root B X) d (heights T hT root D X) J e) + (hat : a ≤ t) (hte : t ≤ e) : + let v := (downPath T hT root X).getVert + (S (v t)).2 (v a) = (S (v a)).2 (v a) ∧ + (S (v t)).1 ((S (v t)).2 (v a)).1 = (S (v a)).1 ((S (v a)).2 (v a)).1 ∧ + (S (v t)).1 ((S (v t)).2 (v a)).2 = (S (v a)).1 ((S (v a)).2 (v a)).2 := by + dsimp only + induction t,hat using Nat.le_induction with + | base => exact ⟨rfl,rfl,rfl⟩ + | succ t hat ih => + have htp : t < (forest T hT root).depth X := by omega + have hact (b : ℕ) (hab : a ≤ b) (hbe : b ≤ e) := + active_on_path T hT root B D k d J X e a b he ha hab hbe + have hp := hpairs _ _ (parent_getVert T hT root X t htp) _ + (Finset.mem_inter.mpr ⟨hact (t+1) (by omega) hte,hact t hat (by omega)⟩) + obtain ⟨h₁,h₂,h₃⟩ := ih (by omega) + exact ⟨hp.1.trans h₁,hp.2.1.trans h₂,hp.2.2.trans h₃⟩ +end BoundedTreewidthL1.TreeCache + +namespace BoundedTreewidthL1.AnchorTreeParticles +open ParticleBatch ParticleSchedule +attribute [local instance] Classical.decEq Classical.propDecidable +variable {V I ι J : Type*} [Fintype V] [Fintype ι] [Nonempty ι] +lemma state_congr_depth (R : RootedForest I) (B : I → Finset V) (A : I → Finset J) + (g g' : I → J → V → ℝ) (i : I) + (heq : ∀ j, R.depth j ≤ R.depth i → g j = g' j) : + state (ι := ι) R B A g i = state R B A g' i := by + induction hn : R.depth i using Nat.strong_induction_on generalizing i with + | h n ih => + rw [state_eq,state_eq] + have hpre : (R.parent i).elim (seed (ι := ι) (V := V) (J := J)) (state R B A g) = + (R.parent i).elim seed (state R B A g') := by + cases hp : R.parent i with + | none => rfl + | some p => + simp only [Option.elim_some] + exact ih (R.depth p) (by rw [← hn]; exact R.decreases _ _ hp) p + (fun j hj => heq j (hj.trans (R.decreases _ _ hp).le)) rfl + rw [hpre] + unfold step + rw [heq i le_rfl] + +lemma predecessor_congr_depth (R : RootedForest I) (B : I → Finset V) (A : I → Finset J) + (g g' : I → J → V → ℝ) (i : I) + (heq : ∀ j, R.depth j < R.depth i → g j = g' j) : + (R.parent i).elim (seed (ι := ι) (V := V) (J := J)) (state R B A g) = + (R.parent i).elim seed (state R B A g') := by + cases hp : R.parent i with + | none => rfl + | some p => + simp only [Option.elim_some] + apply state_congr_depth + intro j hj + exact heq j (lt_of_le_of_lt hj (R.decreases _ _ hp)) + +lemma singleton_launch (R : RootedForest I) (B : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (i : I) (a : J) (hfresh : fresh R A i = {a}) : + let pre := (R.parent i).elim (seed (ι := ι) (V := V) (J := J)) (state R B A g) + let p := pickPair (B i) (usedPairs (retained R A i) pre.2) pre.1 + state (ι := ι) R B A g i = (functionPairUpdate pre.1 p.1 p.2 (g i a), Function.update pre.2 a p) := by + rw [state_eq] + unfold step + rw [hfresh,Finset.toList_singleton] + rfl + +/-- The frozen positive particle is an affine function of its OWN fresh noise; +its baseline is computed entirely before that node is processed. -/ +lemma singleton_positive (R : RootedForest I) (B : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (i : I) (a : J) (hfresh : fresh R A i = {a}) + (hdistinct : ((state (ι := ι) R B A g i).2 a).1 ≠ ((state R B A g i).2 a).2) : + let pre := (R.parent i).elim (seed (ι := ι) (V := V) (J := J)) (state R B A g) + let p := pickPair (B i) (usedPairs (retained R A i) pre.2) pre.1 + (state (ι := ι) R B A g i).1 ((state (ι := ι) R B A g i).2 a).1 = fun v => (pre.1 p.1 v + pre.1 p.2 v)/2 + g i a v := by + have he := singleton_launch (ι := ι) R B A g i a hfresh + dsimp only at he ⊢ + rw [he] at hdistinct ⊢ + simp only [Function.update_self] at hdistinct ⊢ + funext v + exact functionPairUpdate_left _ _ _ hdistinct _ v +end BoundedTreewidthL1.AnchorTreeParticles + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/TreeMarkov.lean b/lean/OAI/Combinatorics/TreewidthL1/TreeMarkov.lean new file mode 100644 index 0000000000000000000000000000000000000000..f70f3364e38238aec2f6dbfd6e378cf84122cc08 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/TreeMarkov.lean @@ -0,0 +1,667 @@ +import OAI.Combinatorics.TreewidthL1.TreeParticles + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 + +namespace BoundedTreewidthL1.TreeMarkov +open scoped BigOperators +attribute [local instance] Classical.decEq Classical.propDecidable + +variable {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + +/-- A symmetric edge interaction; nonedge values are irrelevant. -/ +abbrev Symmetric (R : (i j : I) → A i → A j → ℝ) : Prop := + ∀ i j a b, R i j a b = R j i b a + +noncomputable def edgeFactor (R : (i j : I) → A i → A j → ℝ) + (hs : Symmetric A R) (x : (i : I) → A i) : Sym2 I → ℝ := + Sym2.lift ⟨fun i j => R i j (x i) (x j), fun i j => hs i j (x i) (x j)⟩ + +noncomputable def density (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + (x : (i : I) → A i) : ℝ := + (∏ i, μ i (x i)) * ∏ e ∈ T.edgeFinset, edgeFactor A R hs x e + +/-- The exact local normalization needed for junction gluing. At zero-mass +states no conditional probability is required. -/ +def Normalized (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) : Prop := + (∀ i a, 0 ≤ μ i a) ∧ (∀ i, (∑ a, μ i a) = 1) ∧ + (∀ i j, T.Adj i j → ∀ a b, 0 ≤ R i j a b) ∧ + ∀ i j, T.Adj i j → ∀ a, μ i a ≠ 0 → + (∑ b, μ j b * R i j a b) = 1 + +end BoundedTreewidthL1.TreeMarkov + +namespace BoundedTreewidthL1.TreeMarkov +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + +@[simp] lemma edgeFactor_mk + {I : Type treewidthLevel1} [Fintype I] (A : I → Type treewidthLevel2) [(i : I) → Fintype (A i)] + (R : (i j : I) → A i → A j → ℝ) + (hs : Symmetric A R) (x : (i : I) → A i) (i j : I) : + edgeFactor A R hs x s(i,j) = R i j (x i) (x j) := rfl + +lemma density_nonneg (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + (hn : Normalized A T μ R) (x : (i : I) → A i) : + 0 ≤ density A T μ R hs x := by + apply mul_nonneg (Finset.prod_nonneg (fun i _ => hn.1 i (x i))) + apply Finset.prod_nonneg + intro e he + induction e using Sym2.ind with + | _ i j => exact hn.2.2.1 i j (by simpa using he) (x i) (x j) + +lemma density_zero + {I : Type treewidthLevel1} [Fintype I] (A : I → Type treewidthLevel2) [(i : I) → Fintype (A i)] + (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + (x : (i : I) → A i) (i : I) (hi : μ i (x i) = 0) : + density A T μ R hs x = 0 := by + have hz : (∏ j, μ j (x j)) = 0 := Finset.prod_eq_zero (Finset.mem_univ i) hi + simp [density, hz] + +lemma edgeFinset_leaf (T : SimpleGraph I) {l p : I} (hlp : T.Adj l p) + (hp : ∀ j, T.Adj l j → j = p) : + T.edgeFinset = insert s(l,p) + ((T.induce {i | i ≠ l}).edgeFinset.map + (Function.Embedding.subtype (fun i => i ≠ l)).sym2Map) := by + erw [SimpleGraph.map_edgeFinset_induce (s := {i | i ≠ l}) (G := T)] + ext e + induction e using Sym2.ind with + | _ i j => + simp only [Finset.mem_insert, Finset.mem_inter, SimpleGraph.mem_edgeFinset, + Finset.mk_mem_sym2_iff, Set.mem_toFinset, Set.mem_ofPred_eq] + constructor + · intro hij + by_cases hi : i = l + · subst i + left + rw [hp j hij] + · by_cases hj : j = l + · subst j + left + rw [hp i hij.symm, Sym2.eq_swap] + · exact Or.inr ⟨hij, hi, hj⟩ + · rintro (he | ⟨hij, _, _⟩) + · have : s(i,j) ∈ T.edgeSet := he ▸ hlp + exact this + · exact hij + +end BoundedTreewidthL1.TreeMarkov + +namespace BoundedTreewidthL1.TreeMarkov +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + +@[simp] lemma edgeFactor_induce + {I : Type treewidthLevel1} [Fintype I] (A : I → Type treewidthLevel2) [(i : I) → Fintype (A i)] + (S : Set I) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + (x : (i : I) → A i) (e : Sym2 S) : + edgeFactor A R hs x (Sym2.map Subtype.val e) = + edgeFactor (fun i : S => A i) (fun i j => R i j) + (fun i j => hs i j) (fun i => x i) e := by + induction e using Sym2.ind with + | _ i j => rfl + +lemma density_leaf (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + {l p : I} (hlp : T.Adj l p) (hp : ∀ j, T.Adj l j → j = p) + (x : (i : I) → A i) : + density A T μ R hs x = + density (fun i : {i // i ≠ l} => A i) (T.induce {i | i ≠ l}) + (fun i => μ i) (fun i j => R i j) (fun i j => hs i j) (fun i => x i) * + (μ l (x l) * R p l (x p) (x l)) := by + have hnot : s(l,p) ∉ ((T.induce {i | i ≠ l}).edgeFinset.map + (Function.Embedding.subtype (fun i => i ≠ l)).sym2Map) := by + erw [SimpleGraph.map_edgeFinset_induce (s := {i | i ≠ l}) (G := T)] + simp + unfold density + rw [Fintype.prod_eq_mul_prod_subtype_ne (fun i => μ i (x i)) l, + edgeFinset_leaf T hlp hp, Finset.prod_insert hnot, Finset.prod_map] + simp only [edgeFactor_mk] + have hm : (∏ e ∈ (T.induce {i | i ≠ l}).edgeFinset, + edgeFactor A R hs x ((Function.Embedding.subtype (fun i => i ≠ l)).sym2Map e)) = + ∏ e ∈ (T.induce {i | i ≠ l}).edgeFinset, + edgeFactor (fun i : {i // i ≠ l} => A i) (fun i j => R i j) + (fun i j => hs i j) (fun i => x i) e := by + apply Finset.prod_congr rfl + intro e _ + exact edgeFactor_induce A {i | i ≠ l} R hs x e + erw [hm] + rw [hs l p] + ring_nf + congr 1 + +@[simp] lemma splitAt_here + {I : Type treewidthLevel1} [Fintype I] (A : I → Type treewidthLevel2) [(i : I) → Fintype (A i)] + (l : I) (a : A l) (x : (i : {i // i ≠ l}) → A i) : + (Equiv.piSplitAt l A).symm (a,x) l = a := by + simp [Equiv.piSplitAt_symm_apply] + +@[simp] lemma splitAt_away + {I : Type treewidthLevel1} [Fintype I] (A : I → Type treewidthLevel2) [(i : I) → Fintype (A i)] + (l : I) (a : A l) (x : (i : {i // i ≠ l}) → A i) + (i : I) (hi : i ≠ l) : + (Equiv.piSplitAt l A).symm (a,x) i = x ⟨i,hi⟩ := by + simp [Equiv.piSplitAt_symm_apply, hi] + +lemma splitAt_restrict (l : I) (a : A l) (x : (i : {i // i ≠ l}) → A i) : + (fun i : {i // i ≠ l} => (Equiv.piSplitAt l A).symm (a,x) i) = x := by + funext i + exact splitAt_away A l a x i i.property + +lemma sum_leaf_density (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + (hn : Normalized A T μ R) + {l p : I} (hlp : T.Adj l p) (hp : ∀ j, T.Adj l j → j = p) + (x : (i : {i // i ≠ l}) → A i) : + (∑ a, density A T μ R hs ((Equiv.piSplitAt l A).symm (a,x))) = + density (fun i : {i // i ≠ l} => A i) (T.induce {i | i ≠ l}) + (fun i => μ i) (fun i j => R i j) (fun i j => hs i j) x := by + have hpne : p ≠ l := hlp.ne.symm + let p' : {i // i ≠ l} := ⟨p,hpne⟩ + simp_rw [density_leaf A T μ R hs hlp hp, splitAt_restrict, + splitAt_here, splitAt_away A l _ x p hpne] + rw [← Finset.mul_sum] + by_cases hz : μ p (x p') = 0 + · have hd := density_zero (fun i : {i // i ≠ l} => A i) (T.induce {i | i ≠ l}) + (fun i => μ i) (fun i j => R i j) (fun i j => hs i j) x p' hz + rw [hd, zero_mul] + · rw [hn.2.2.2 p l hlp.symm (x p') hz, mul_one] + +lemma expectation_leaf (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + (hn : Normalized A T μ R) + {l p : I} (hlp : T.Adj l p) (hp : ∀ j, T.Adj l j → j = p) + (f : ((i : {i // i ≠ l}) → A i) → ℝ) : + (∑ x, density A T μ R hs x * f (fun i : {i // i ≠ l} => x i)) = + ∑ x, density (fun i : {i // i ≠ l} => A i) (T.induce {i | i ≠ l}) + (fun i => μ i) (fun i j => R i j) (fun i j => hs i j) x * f x := by + rw [← (Equiv.piSplitAt l A).symm.sum_comp, Fintype.sum_prod_type, + Finset.sum_comm] + simp only [splitAt_restrict, ← Finset.sum_mul, + sum_leaf_density A T μ R hs hn hlp hp] + +end BoundedTreewidthL1.TreeMarkov + +namespace BoundedTreewidthL1.TreeMarkov +attribute [local instance] Classical.decEq Classical.propDecidable + +lemma Normalized.induce {I : Type*} [Fintype I] {A : I → Type*} [∀ i, Fintype (A i)] + {T : SimpleGraph I} {μ : (i : I) → A i → ℝ} + {R : (i j : I) → A i → A j → ℝ} (hn : Normalized A T μ R) (S : Set I) : + Normalized (fun i : S => A i) (T.induce S) (fun i => μ i) (fun i j => R i j) := by + exact ⟨fun i => hn.1 i, fun i => hn.2.1 i, + fun i j hij => hn.2.2.1 i j hij, fun i j hij => hn.2.2.2 i j hij⟩ + +private theorem node_marginal_card (n : ℕ) : + ∀ {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + (T : SimpleGraph I), Fintype.card I = n → T.IsTree → + ∀ (μ : (i : I) → A i → ℝ) (R : (i j : I) → A i → A j → ℝ) + (hs : Symmetric A R), Normalized A T μ R → + ∀ i a, (∑ x, if x i = a then density A T μ R hs x else 0) = μ i a := by + induction n using Nat.strong_induction_on with + | h n ih => + intro I _ A _ T hn hT μ R hs hnorm i a + by_cases hsmall : Fintype.card I ≤ 1 + · let : Subsingleton I := Fintype.card_le_one_iff_subsingleton.mp hsmall + let : Unique I := ⟨⟨i⟩, fun j => Subsingleton.elim j i⟩ + have hbot : T = ⊥ := Subsingleton.elim _ _ + have hd (x : (j : I) → A j) : density A T μ R hs x = μ i (x i) := by + have he : T.edgeFinset = ∅ := by + ext e + induction e using Sym2.ind with + | _ j k => + simp [Subsingleton.elim k j] + simp only [density, he, Finset.prod_empty, mul_one, Fintype.prod_unique] + rfl + rw [← (Equiv.piUnique A).symm.sum_comp] + simp [hd, Equiv.piUnique, uniqueElim] + · let : Nontrivial I := Fintype.one_lt_card_iff_nontrivial.mp (lt_of_not_ge hsmall) + obtain ⟨u,v,huv,hu,hv⟩ := hT.exists_ne_and_degree_eq_one + have hex : ∃ l : I, l ≠ i ∧ T.degree l = 1 := by + by_cases hui : u = i + · exact ⟨v, fun hvi => huv (hui.trans hvi.symm), hv⟩ + · exact ⟨u,hui,hu⟩ + obtain ⟨l,hli,hl⟩ := hex + obtain ⟨p,hlp,hp⟩ := SimpleGraph.degree_eq_one_iff_existsUnique_adj.mp hl + let S : Set I := {j | j ≠ l} + have hT' : (T.induce S).IsTree := + ⟨hT.connected.induce_compl_singleton_of_degree_eq_one hl, hT.isAcyclic.induce S⟩ + have hc : Fintype.card S < n := by + rw [← hn] + exact Fintype.card_subtype_lt (p := fun j => j ∈ S) (x := l) (by simp [S]) + let i' : S := ⟨i,hli.symm⟩ + have hi := ih (Fintype.card S) hc (fun j : S => A j) (T.induce S) rfl hT' + (fun j => μ j) (fun j k => R j k) (fun j k => hs j k) (hnorm.induce S) i' a + have he := expectation_leaf A T μ R hs hnorm hlp hp + (fun x => if x i' = a then (1:ℝ) else 0) + simp only [mul_ite, mul_one, mul_zero] at he + apply he.trans + convert hi using 1 + apply Finset.sum_congr (by ext; simp) + intro x hx + congr 1 + +variable {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + +/-- Canonical root-independent tree density and exact one-node marginals. +Zero-mass states, deterministic edges and arbitrary finite state spaces allowed. -/ +theorem tree_density (T : SimpleGraph I) (hT : T.IsTree) + (μ : (i : I) → A i → ℝ) (R : (i j : I) → A i → A j → ℝ) + (hs : Symmetric A R) (hn : Normalized A T μ R) : + (∀ x, 0 ≤ density A T μ R hs x) ∧ + (∑ x, density A T μ R hs x) = 1 ∧ + ∀ i a, (∑ x, if x i = a then density A T μ R hs x else 0) = μ i a := by + have hm := node_marginal_card (Fintype.card I) A T rfl hT μ R hs hn + refine ⟨density_nonneg A T μ R hs hn, ?_, hm⟩ + obtain ⟨i⟩ := hT.connected.nonempty + have ht : (∑ a : A i, ∑ x, if x i = a then density A T μ R hs x else 0) = + ∑ x, density A T μ R hs x := by + rw [Finset.sum_comm] + simp + rw [← ht] + simp only [hm] + exact hn.2.1 i + +end BoundedTreewidthL1.TreeMarkov + +namespace BoundedTreewidthL1.TreeMarkov +attribute [local instance] Classical.decEq Classical.propDecidable + +lemma tree_path_mem_connected {I : Type*} (T : SimpleGraph I) (hT : T.IsTree) + {S : Set I} (hS : (T.induce S).Connected) {a b v : I} + (ha : a ∈ S) (hb : b ∈ S) (q : T.Walk a b) (hq : q.IsPath) + (hv : v ∈ q.support) : v ∈ S := by + obtain ⟨p, hp⟩ := hS.exists_isPath ⟨a, ha⟩ ⟨b, hb⟩ + let f := (SimpleGraph.Embedding.induce (G := T) S).toHom + have hp' : (p.map f).IsPath := hp.map Subtype.val_injective + have heq : p.map f = q := congrArg Subtype.val + ((hT.isAcyclic.subsingleton_path a b).elim ⟨p.map f, hp'⟩ ⟨q, hq⟩) + have hmem : v ∈ (p.map f).support := heq.symm ▸ hv + rw [SimpleGraph.Walk.support_map] at hmem + obtain ⟨z, _, hz⟩ := List.mem_map.mp hmem + exact hz ▸ z.property + +/-- A proper connected subtree can be pruned from outside without altering it. -/ +lemma exists_leaf_outside {I : Type*} [Fintype I] (T : SimpleGraph I) (hT : T.IsTree) + (S : Set I) (hc : (T.induce S).Connected) (hproper : S ≠ Set.univ) : + ∃ l : I, l ∉ S ∧ T.degree l = 1 := by + obtain ⟨⟨r, hr⟩⟩ := hc.nonempty + obtain ⟨v, hv⟩ : ∃ v, v ∉ S := by + by_contra hn + apply hproper + ext v + simp only [Set.mem_univ, iff_true] + by_contra hv + exact hn ⟨v,hv⟩ + obtain ⟨p, hp⟩ := hT.connected.exists_isPath r v + let lengths : Set ℕ := {n | ∃ (l : I) (q : T.Walk r l), + q.IsPath ∧ v ∈ q.support ∧ q.length = n} + have hfin : lengths.Finite := Set.Finite.subset + (Set.finite_le_nat (Fintype.card I)) (fun n ⟨l,q,hq,_,heq⟩ => heq ▸ hq.length_lt.le) + obtain ⟨n, ⟨⟨l,q,hq,hvq,heq⟩, hmax⟩⟩ := hfin.exists_maximal + ⟨p.length, ⟨v,p,hp,p.end_mem_support,rfl⟩⟩ + have hl : l ∉ S := fun hls => hv (tree_path_mem_connected T hT hc hr hls q hq hvq) + have hnil : ¬ q.Nil := by + intro hnil + exact hl (hq.nil_iff_eq.mp hnil ▸ hr) + refine ⟨l,hl,SimpleGraph.degree_eq_one_iff_existsUnique_adj.mpr + ⟨q.penultimate, (q.adj_penultimate hnil).symm, ?_⟩⟩ + intro w hadj + apply hT.isAcyclic.eq_penultimate_of_adj_end hq hadj + by_contra hn + have hqc : (q.concat hadj).IsPath := hq.concat hn hadj + have hvc : v ∈ (q.concat hadj).support := by + simp only [SimpleGraph.Walk.support_concat, List.mem_append, List.mem_singleton] + exact Or.inl hvq + have hm := hmax ⟨w,q.concat hadj,hqc,hvc,rfl⟩ + have he : (q.concat hadj).length = q.length + 1 := q.length_concat hadj + omega + +end BoundedTreewidthL1.TreeMarkov + +namespace BoundedTreewidthL1.TreeMarkov +attribute [local instance] Classical.decEq Classical.propDecidable + +lemma edgeFinset_comap_equiv {I J : Type*} [Fintype I] [Fintype J] + (T : SimpleGraph I) (e : J ≃ I) : + T.edgeFinset = (T.comap e).edgeFinset.map e.toEmbedding.sym2Map := by + have hg : (T.comap e).map e.toEmbedding = T := by + ext i j + simp only [SimpleGraph.map_adj] + constructor + · rintro ⟨a,b,hab,ha,hb⟩ + subst i + subst j + exact hab + · intro hij + exact ⟨e.symm i,e.symm j,by simpa using hij,e.apply_symm_apply i,e.apply_symm_apply j⟩ + have he := SimpleGraph.edgeFinset_map e.toEmbedding (T.comap e) + calc + T.edgeFinset = ((T.comap e).map e.toEmbedding).edgeFinset := by + ext z + simp only [SimpleGraph.mem_edgeFinset] + + rw [hg] + _ = _ := he + +variable {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + +lemma density_equiv + {I : Type treewidthLevel1} [Fintype I] (A : I → Type treewidthLevel2) [(i : I) → Fintype (A i)] + (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + {J : Type*} [Fintype J] (e : J ≃ I) (x : (i : I) → A i) : + density A T μ R hs x = + density (fun j => A (e j)) (T.comap e) (fun j => μ (e j)) + (fun j k => R (e j) (e k)) (fun j k => hs (e j) (e k)) (fun j => x (e j)) := by + unfold density + rw [← e.prod_comp (fun i => μ i (x i)), edgeFinset_comap_equiv T e, + Finset.prod_map] + congr 1 + apply Finset.prod_congr rfl + intro z hz + induction z using Sym2.ind with + | _ i j => rfl + +lemma expectation_surjective (T : SimpleGraph I) (μ : (i : I) → A i → ℝ) + (R : (i j : I) → A i → A j → ℝ) (hs : Symmetric A R) + {J : Type*} [Fintype J] (e : J ↪ I) (he : Function.Surjective e) + (f : ((j : J) → A (e j)) → ℝ) : + (∑ x, density A T μ R hs x * f (fun j => x (e j))) = + ∑ x, density (fun j => A (e j)) (T.comap e) (fun j => μ (e j)) + (fun j k => R (e j) (e k)) (fun j k => hs (e j) (e k)) x * f x := by + let E : J ≃ I := Equiv.ofBijective e ⟨e.injective,he⟩ + calc + _ = ∑ x : (i : I) → A i, density (fun j => A (e j)) (T.comap e) (fun j => μ (e j)) + (fun j k => R (e j) (e k)) (fun j k => hs (e j) (e k)) + (fun j => x (e j)) * f (fun j => x (e j)) := by + apply Finset.sum_congr rfl + intro x hx + rw [density_equiv A T μ R hs E x] + rfl + _ = _ := by + have hfun (x : (i : I) → A i) : + (Equiv.piCongrLeft A E).symm x = (fun j => x (e j)) := by + funext j + exact Equiv.piCongrLeft_symm_apply A E x j + have hv := (Equiv.piCongrLeft A E).symm.sum_comp + (fun x => density (fun j => A (e j)) (T.comap e) (fun j => μ (e j)) + (fun j k => R (e j) (e k)) (fun j k => hs (e j) (e k)) x * f x) + simp_rw [hfun] at hv + convert hv using 1 ; apply Finset.sum_congr + (by ext x; constructor <;> intro _ <;> exact Finset.mem_univ _) ; + intro x hx ; rfl + +end BoundedTreewidthL1.TreeMarkov + +namespace BoundedTreewidthL1.TreeMarkov +attribute [local instance] Classical.decEq Classical.propDecidable + +private theorem expectation_comap_card (n : ℕ) : + ∀ {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + (T : SimpleGraph I), Fintype.card I = n → T.IsTree → + ∀ (μ : (i : I) → A i → ℝ) (R : (i j : I) → A i → A j → ℝ) + (hs : Symmetric A R), Normalized A T μ R → + ∀ {J : Type*} [Fintype J] (e : J ↪ I), (T.comap e).Connected → + ∀ (f : ((j : J) → A (e j)) → ℝ), + (∑ x, density A T μ R hs x * f (fun j => x (e j))) = + ∑ x, density (fun j => A (e j)) (T.comap e) (fun j => μ (e j)) + (fun j k => R (e j) (e k)) (fun j k => hs (e j) (e k)) x * f x := by + induction n using Nat.strong_induction_on with + | h n ih => + intro I _ A _ T hn hT μ R hs hnorm J _ e hc f + by_cases he : Function.Surjective e + · exact expectation_surjective A T μ R hs e he f + · have hc' : (T.induce (Set.range e)).Connected := by + let hom : T.comap e →g T.induce (Set.range e) := + ⟨fun j => ⟨e j, ⟨j,rfl⟩⟩, fun h => h⟩ + apply hc.map hom + rintro ⟨i,j,rfl⟩ + exact ⟨j,rfl⟩ + obtain ⟨l,hl,hd⟩ := exists_leaf_outside T hT (Set.range e) hc' + (fun h => he (Set.range_eq_univ.mp h)) + obtain ⟨p,hlp,hp⟩ := SimpleGraph.degree_eq_one_iff_existsUnique_adj.mp hd + let K : Type _ := {i : I // i ≠ l} + let e' : J ↪ K := ⟨fun j => ⟨e j, fun h => hl ⟨j,h⟩⟩, + fun _ _ h => e.injective (congrArg Subtype.val h)⟩ + have hT' : (T.induce {i | i ≠ l}).IsTree := + ⟨hT.connected.induce_compl_singleton_of_degree_eq_one hd, + hT.isAcyclic.induce _⟩ + have hcard : Fintype.card K < n := by + rw [← hn] + exact Fintype.card_subtype_lt (p := fun i => i ≠ l) (x := l) (by simp) + have hnew := ih (Fintype.card K) hcard (fun i : K => A i) + (T.induce {i | i ≠ l}) rfl hT' (fun i => μ i) (fun i j => R i j) + (fun i j => hs i j) (hnorm.induce _) e' hc f + have hold := expectation_leaf A T μ R hs hnorm hlp hp + (fun x => f (fun j => x (e' j))) + apply hold.trans + convert hnew using 1 <;> + apply Finset.sum_congr (by ext; simp) <;> + intro x hx <;> congr 1 + +variable {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + +/-- Exact connected-subtree marginal of the canonical junction law. In particular +this applies to a simple bag path, before projection to intersection assignments. -/ +theorem expectation_comap (T : SimpleGraph I) (hT : T.IsTree) + (μ : (i : I) → A i → ℝ) (R : (i j : I) → A i → A j → ℝ) + (hs : Symmetric A R) (hn : Normalized A T μ R) + {J : Type*} [Fintype J] (e : J ↪ I) (hc : (T.comap e).Connected) + (f : ((j : J) → A (e j)) → ℝ) : + (∑ x, density A T μ R hs x * f (fun j => x (e j))) = + ∑ x, density (fun j => A (e j)) (T.comap e) (fun j => μ (e j)) + (fun j k => R (e j) (e k)) (fun j k => hs (e j) (e k)) x * f x := by + exact expectation_comap_card (Fintype.card I) A T rfl hT μ R hs hn e hc f + +end BoundedTreewidthL1.TreeMarkov + +namespace BoundedTreewidthL1.TreeMarkov +attribute [local instance] Classical.decEq Classical.propDecidable +variable {I : Type*} [Fintype I] (A : I → Type*) [∀ i, Fintype (A i)] + +/-- Interaction constructed from the actual local pair mass, not assumed. -/ +noncomputable def interaction (μ : (i : I) → A i → ℝ) + (J : (i j : I) → A i → A j → ℝ) (i j : I) (a : A i) (b : A j) : ℝ := + J i j a b / (μ i a * μ j b) + +lemma interaction_symmetric + {I : Type treewidthLevel1} [Fintype I] (A : I → Type treewidthLevel2) [(i : I) → Fintype (A i)] + (μ : (i : I) → A i → ℝ) + (J : (i j : I) → A i → A j → ℝ) (hJ : Symmetric A J) : + Symmetric A (interaction A μ J) := by + intro i j a b + simp only [interaction, hJ i j a b, mul_comm] + +lemma interaction_normalized + {I : Type treewidthLevel1} [Fintype I] (A : I → Type treewidthLevel2) [(i : I) → Fintype (A i)] + (T : SimpleGraph I) + (μ : (i : I) → A i → ℝ) (J : (i j : I) → A i → A j → ℝ) + (hμ : ∀ i a, 0 ≤ μ i a) (hμ₁ : ∀ i, (∑ a, μ i a) = 1) + (hs : Symmetric A J) + (hJ : ∀ i j, T.Adj i j → ∀ a b, 0 ≤ J i j a b) + (hrow : ∀ i j, T.Adj i j → ∀ a, (∑ b, J i j a b) = μ i a) : + Normalized A T μ (interaction A μ J) := by + refine ⟨hμ,hμ₁,?_,?_⟩ + · intro i j hij a b + exact div_nonneg (hJ i j hij a b) (mul_nonneg (hμ i a) (hμ j b)) + · intro i j hij a ha + have hz (b : A j) (hb : μ j b = 0) : J i j a b = 0 := by + have he := hrow j i hij.symm b + rw [hb] at he + have hz' : J j i b a = 0 := (Finset.sum_eq_zero_iff_of_nonneg + (fun c _ => hJ j i hij.symm b c)).mp he a (Finset.mem_univ _) + rw [hs i j a b] + exact hz' + calc + _ = ∑ b, J i j a b / μ i a := by + apply Finset.sum_congr rfl + intro b hb + by_cases hb' : μ j b = 0 + · simp [interaction, hb', hz b hb'] + · dsimp [interaction] + field_simp + _ = (∑ b, J i j a b) / μ i a := (Finset.sum_div _ _ _).symm + _ = 1 := by rw [hrow i j hij a, div_self ha] + +/-- Canonical tree law from genuinely consistent adjacent pair distributions. +No positive lower bound on local state probabilities is imposed. -/ +theorem coupling_tree (T : SimpleGraph I) (hT : T.IsTree) + (μ : (i : I) → A i → ℝ) (J : (i j : I) → A i → A j → ℝ) + (hμ : ∀ i a, 0 ≤ μ i a) (hμ₁ : ∀ i, (∑ a, μ i a) = 1) + (hs : Symmetric A J) + (hJ : ∀ i j, T.Adj i j → ∀ a b, 0 ≤ J i j a b) + (hrow : ∀ i j, T.Adj i j → ∀ a, (∑ b, J i j a b) = μ i a) : + let R := interaction A μ J + let hR := interaction_symmetric A μ J hs + (∀ x, 0 ≤ density A T μ R hR x) ∧ + (∑ x, density A T μ R hR x) = 1 ∧ + (∀ i a, (∑ x, if x i = a then density A T μ R hR x else 0) = μ i a) ∧ + ∀ {K : Type*} [Fintype K] (e : K ↪ I), (T.comap e).Connected → + ∀ (f : ((j : K) → A (e j)) → ℝ), + (∑ x, density A T μ R hR x * f (fun j => x (e j))) = + ∑ x, density (fun j => A (e j)) (T.comap e) (fun j => μ (e j)) + (fun j k => R (e j) (e k)) (fun j k => hR (e j) (e k)) x * f x := by + dsimp only + have hn := interaction_normalized A T μ J hμ hμ₁ hs hJ hrow + obtain ⟨hnon,hprob,hmarg⟩ := tree_density A T hT μ (interaction A μ J) + (interaction_symmetric A μ J hs) hn + refine ⟨hnon,hprob,hmarg,?_⟩ + intro K _ e hc f + exact expectation_comap A T hT μ (interaction A μ J) + (interaction_symmetric A μ J hs) hn e hc f +end BoundedTreewidthL1.TreeMarkov + +namespace BoundedTreewidthL1.MarkovFlow +abbrev History {r : ℕ} (L : Fin (r + 1) → Type*) := (i : Fin (r + 1)) → L i +/-- Same finite stochastic-product definition as the exact CKR obligation. -/ +def IsMarkovLaw {r : ℕ} (L : Fin (r + 1) → Type*) [∀ i, Fintype (L i)] + (μ : History L → ℝ) : Prop := + ∃ p : L 0 → ℝ, ∃ K : (i : Fin r) → L i.castSucc → L i.succ → ℝ, + (∀ a, 0 ≤ p a) ∧ (∑ a, p a) = 1 ∧ + (∀ i a b, 0 ≤ K i a b) ∧ (∀ i a, (∑ b, K i a b) = 1) ∧ + ∀ x, μ x = p (x 0) * ∏ i : Fin r, K i (x i.castSucc) (x i.succ) +end BoundedTreewidthL1.MarkovFlow + +namespace BoundedTreewidthL1.TreeMarkov +attribute [local instance] Classical.decEq Classical.propDecidable +variable {r : ℕ} (A : Fin (r+1) → Type*) [∀ i, Fintype (A i)] + +def pathEdge (n : ℕ) : Fin n ↪ Sym2 (Fin (n+1)) where + toFun i := s(i.castSucc,i.succ) + inj' := by + intro i j he + rcases Sym2.eq_iff.mp he with h | h + · apply Fin.ext + exact congrArg (fun k : Fin (n+1) => k.val) h.1 + · have h₁ := congrArg Fin.val h.1 + have h₂ := congrArg Fin.val h.2 + simp only [Fin.val_castSucc, Fin.val_succ] at h₁ h₂ + omega + +lemma path_edges (n : ℕ) : + (SimpleGraph.pathGraph (n+1)).edgeFinset = Finset.univ.map (pathEdge n) := by + ext e + induction e using Sym2.ind with + | _ i j => + rw [SimpleGraph.mem_edgeFinset] + change (SimpleGraph.pathGraph (n+1)).Adj i j ↔ _ + rw [SimpleGraph.pathGraph_adj] + simp only [Finset.mem_map, Finset.mem_univ, true_and] + constructor + · intro h + rcases h with h | h + · refine ⟨⟨i.val,by omega⟩,?_⟩ + change s((⟨i.val,_⟩ : Fin (n+1)),(⟨i.val+1,_⟩ : Fin (n+1))) = s(i,j) + congr 1 + exact Fin.ext h + · refine ⟨⟨j.val,by omega⟩,?_⟩ + apply Sym2.eq_iff.mpr + right + exact ⟨Fin.ext rfl, Fin.ext h⟩ + · rintro ⟨k,hk⟩ + change s(k.castSucc,k.succ) = s(i,j) at hk + rcases Sym2.eq_iff.mp hk with hk | hk + · left + rw [← hk.1,← hk.2] + rfl + · right + rw [← hk.1,← hk.2] + rfl + +lemma path_density + {r : ℕ} (A : Fin (r + 1) → Type treewidthLevel1) [(i : Fin (r + 1)) → Fintype (A i)] + (μ : (i : Fin (r+1)) → A i → ℝ) + (R : (i j : Fin (r+1)) → A i → A j → ℝ) (hs : Symmetric A R) + (x : (i : Fin (r+1)) → A i) : + density A (SimpleGraph.pathGraph (r+1)) μ R hs x = + (∏ i, μ i (x i)) * ∏ i : Fin r, R i.castSucc i.succ (x i.castSucc) (x i.succ) := by + rw [density, path_edges, Finset.prod_map] + rfl + +lemma product_factorization (n : ℕ) (m : Fin (n+1) → ℝ) + (q k : Fin n → ℝ) + (hk : ∀ i, m i.castSucc ≠ 0 → k i = m i.succ * q i) : + (∏ i, m i) * (∏ i, q i) = m 0 * ∏ i, k i := by + induction n with + | zero => simp + | succ n ih => + let m' : Fin (n+1) → ℝ := fun i => m i.castSucc + let q' : Fin n → ℝ := fun i => q i.castSucc + let k' : Fin n → ℝ := fun i => k i.castSucc + have hk' : ∀ i, m' i.castSucc ≠ 0 → k' i = m' i.succ * q' i := by + intro i hi + exact hk i.castSucc hi + have hih := ih m' q' k' hk' + rw [Fin.prod_univ_castSucc m, Fin.prod_univ_castSucc q, Fin.prod_univ_castSucc k] + change ((∏ i, m' i) * m (Fin.last (n+1))) * ((∏ i, q' i) * q (Fin.last n)) = + m' 0 * ((∏ i, k' i) * k (Fin.last n)) + by_cases hz : m' (Fin.last n) = 0 + · have hprod : (∏ i, m' i) = 0 := Finset.prod_eq_zero (Finset.mem_univ _) hz + rw [hprod,zero_mul] at hih + calc + _ = 0 := by simp [hprod] + _ = (m' 0 * ∏ i, k' i) * k (Fin.last n) := by rw [← hih,zero_mul] + _ = _ := by ring + · have hl := hk (Fin.last n) hz + rw [hl] + change ((∏ i, m' i) * m (Fin.last (n+1))) * ((∏ i, q' i) * q (Fin.last n)) = + m' 0 * ((∏ i, k' i) * (m (Fin.last (n+1)) * q (Fin.last n))) + calc + _ = ((∏ i, m' i) * ∏ i, q' i) * (m (Fin.last (n+1)) * q (Fin.last n)) := by ring + _ = _ := by rw [hih]; ring + +/-- The canonical marginal on any simple bag-tree path is an actual Markov +product, not merely a collection of consistent adjacent marginals. -/ +theorem path_markov (μ : (i : Fin (r+1)) → A i → ℝ) + (R : (i j : Fin (r+1)) → A i → A j → ℝ) (hs : Symmetric A R) + (hn : Normalized A (SimpleGraph.pathGraph (r+1)) μ R) : + MarkovFlow.IsMarkovLaw A (density A (SimpleGraph.pathGraph (r+1)) μ R hs) := by + let K : (i : Fin r) → A i.castSucc → A i.succ → ℝ := fun i a b => + if μ i.castSucc a = 0 then μ i.succ b else μ i.succ b * R i.castSucc i.succ a b + have hadj (i : Fin r) : (SimpleGraph.pathGraph (r+1)).Adj i.castSucc i.succ := + SimpleGraph.pathGraph_adj.mpr (Or.inl rfl) + refine ⟨μ 0,K,hn.1 0,hn.2.1 0,?_,?_,?_⟩ + · intro i a b + dsimp [K] + split_ifs + · exact hn.1 _ _ + · exact mul_nonneg (hn.1 _ _) (hn.2.2.1 _ _ (hadj i) a b) + · intro i a + by_cases ha : μ i.castSucc a = 0 + · simpa [K,ha] using hn.2.1 i.succ + · simpa [K,ha] using hn.2.2.2 _ _ (hadj i) a ha + · intro x + rw [path_density] + apply product_factorization + intro i hi + simp [K,hi] +end BoundedTreewidthL1.TreeMarkov + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/TreeParticles.lean b/lean/OAI/Combinatorics/TreewidthL1/TreeParticles.lean new file mode 100644 index 0000000000000000000000000000000000000000..b1f3adc84be26c4aeedff8a2f41dcc319e4278a5 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/TreeParticles.lean @@ -0,0 +1,218 @@ +import OAI.Combinatorics.TreewidthL1.Particles + +namespace OAI + +universe treewidthLevel1 treewidthLevel2 treewidthLevel3 treewidthLevel4 + +/-! Deterministic causal recursion on a rooted finite tree. The depth certificate +is constructed from graph distance below; it is not an embedding hypothesis. -/ +namespace BoundedTreewidthL1 + +structure RootedForest (I : Type*) where + parent : I → Option I + depth : I → ℕ + decreases : ∀ i p, parent i = some p → depth p < depth i + +namespace RootedForest +variable {I A : Type*} + +noncomputable def run (R : RootedForest I) (seed : A) (step : I → A → A) (i : I) : A := + step i (match h : R.parent i with + | none => seed + | some p => + have : R.depth p < R.depth i := R.decreases i p h + R.run seed step p) +termination_by R.depth i +decreasing_by assumption + +lemma run_eq (R : RootedForest I) (seed : A) (step : I → A → A) (i : I) : + R.run seed step i = step i ((R.parent i).elim seed (R.run seed step)) := by + rw [run] + split <;> simp_all + +lemma run_invariant (R : RootedForest I) (seed : A) (step : I → A → A) + (Q : A → Prop) (hseed : Q seed) (hstep : ∀ i a, Q a → Q (step i a)) : + ∀ i, Q (R.run seed step i) := by + intro i + induction hn : R.depth i using Nat.strong_induction_on generalizing i with + | h n ih => + rw [run_eq] + apply hstep + cases hp : R.parent i with + | none => exact hseed + | some p => + apply ih (R.depth p) (by rw [← hn]; exact R.decreases i p hp) p rfl + +lemma run_measurable {Ω : Type*} [MeasurableSpace Ω] [MeasurableSpace A] + (R : RootedForest I) (seed : Ω → A) (step : I → Ω → A → A) + (hseed : Measurable seed) + (hstep : ∀ i f, Measurable f → Measurable (fun ω => step i ω (f ω))) : + ∀ i, Measurable (fun ω => R.run (seed ω) (fun j => step j ω) i) := by + intro i + induction hn : R.depth i using Nat.strong_induction_on generalizing i with + | h n ih => + simp_rw [run_eq] + cases hp : R.parent i with + | none => simpa only [hp, Option.elim_none] using hstep i seed hseed + | some p => + simpa only [hp, Option.elim_some] using hstep i _ + (ih (R.depth p) (by rw [← hn]; exact R.decreases i p hp) p rfl) +end RootedForest +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1.TreeParticles +open MeasureTheory ParticleSchedule ParticleBatch +variable {I V ι J : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] [DecidableEq J] + +noncomputable def interface (R : RootedForest I) (bag : I → Finset V) (i : I) : Finset V := + (R.parent i).elim ∅ bag +noncomputable def retained (R : RootedForest I) (A : I → Finset J) (i : I) : Finset J := + (R.parent i).elim ∅ (fun p => A i ∩ A p) +noncomputable def fresh (R : RootedForest I) (A : I → Finset J) (i : I) : Finset J := + A i \ retained R A i +noncomputable def seed : (ι → V → ℝ) × (J → ι × ι) := + (fun _ _ => 0, fun _ => (Classical.choice inferInstance, Classical.choice inferInstance)) +noncomputable def step (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (i : I) (S : (ι → V → ℝ) × (J → ι × ι)) := + launchBatch (interface R bag i) (fresh R A i).toList (retained R A i) S.1 S.2 (g i) +noncomputable def state (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (i : I) : (ι → V → ℝ) × (J → ι × ι) := + R.run seed (step R bag A g) i + +lemma retained_subset (R : RootedForest I) (A : I → Finset J) (i : I) : + retained R A i ⊆ A i := by + unfold retained + cases R.parent i with + | none => exact Finset.empty_subset _ + | some p => exact Finset.inter_subset_left + +lemma batch_data (R : RootedForest I) (A : I → Finset J) (i : I) + {q : ℕ} (hA : (A i).card ≤ q) : + (fresh R A i).toList.Nodup ∧ + (∀ a ∈ (fresh R A i).toList, a ∉ retained R A i) ∧ + (retained R A i ∪ (fresh R A i).toList.toFinset).card ≤ q := by + classical + refine ⟨Finset.nodup_toList _, ?_, ?_⟩ + · intro a ha + exact (Finset.mem_sdiff.mp (Finset.mem_toList.mp ha)).2 + · simpa only [Finset.toList_toFinset, fresh, + Finset.union_sdiff_of_subset (retained_subset R A i)] using hA + +lemma interface_card + {I : Type treewidthLevel1} {V : Type treewidthLevel2} [Fintype V] + (R : RootedForest I) (bag : I → Finset V) {k : ℕ} + (hbag : ∀ i, (bag i).card ≤ k) (i : I) : (interface R bag i).card ≤ k := by + unfold interface + cases R.parent i with + | none => exact Nat.zero_le _ + | some p => exact hbag p + +lemma state_eq + {I : Type treewidthLevel1} {V : Type treewidthLevel2} {ι : Type treewidthLevel3} + {J : Type treewidthLevel4} [Fintype V] [Fintype ι] [Nonempty ι] [DecidableEq ι] [DecidableEq J] + (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : I → J → V → ℝ) (i : I) : + state (ι := ι) R bag A g i = step R bag A g i + ((R.parent i).elim seed (state R bag A g)) := RootedForest.run_eq _ _ _ _ +/-- Actual branching preparation for active-scale keys. Children use their own +copies of the parent's list; no consistency assumption on sampled bag laws. -/ +theorem forest_particle_realization (R : RootedForest I) (bag : I → Finset V) + (A : I → Finset J) (k q : ℕ) (hbag : ∀ i, (bag i).card ≤ k) + (hA : ∀ i, (A i).card ≤ q) (hN : Fintype.card ι = 2*q + k.factorial + 2) + (d : V → V → ℝ) (L H Δ : ℝ) (hH : 0 < H) (hΔ : 0 < Δ) + (g : I → J → V → ℝ) + (hLip : ∀ i a, ∀ u v, |g i a u - g i a v| ≤ L*d u v) + (hHeight : ∀ i a v, |g i a v| ≤ H) + (hzero : ∀ i a, ∀ v ∈ interface R bag i, g i a v = 0) : + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + let S := state (ι := ι) R bag A g + (∀ i, FunctionParticleReachable d L H (S i).1) ∧ + (∀ i p, R.parent i = some p → + particleTrace M (S i).1 (bag p) = particleTrace M (S p).1 (bag p)) ∧ + (∀ i p, R.parent i = some p → ∀ a ∈ A i ∩ A p, + (S i).2 a = (S p).2 a ∧ + (S i).1 ((S i).2 a).1 = (S p).1 ((S p).2 a).1 ∧ + (S i).1 ((S i).2 a).2 = (S p).1 ((S p).2 a).2) ∧ + (∀ i a, a ∈ fresh R A i → + ((S i).2 a).1 ≠ ((S i).2 a).2 ∧ + ∀ v, (S i).1 ((S i).2 a).1 v - (S i).1 ((S i).2 a).2 v = 2*g i a v) := by + classical + dsimp only + let M := H*((Fintype.card ι : ℝ)-1)+2*Δ + let S := state (ι := ι) R bag A g + have hstep (i : I) (F : ι → V → ℝ) (p : J → ι × ι) + (hF : FunctionParticleReachable d L H F) := + launchBatch_correct k q hN (interface R bag i) (interface_card R bag hbag i) + (fresh R A i).toList (retained R A i) + (batch_data R A i (hA i)).1 (batch_data R A i (hA i)).2.1 + (batch_data R A i (hA i)).2.2 d L H Δ hH hΔ F p hF (g i) + (fun a _ => hLip i a) (fun a _ => hHeight i a) (fun a _ => hzero i a) + have hreach : ∀ i, FunctionParticleReachable d L H (S i).1 := by + apply R.run_invariant seed (step R bag A g) (fun S => FunctionParticleReachable d L H S.1) + · exact FunctionParticleReachable.zero + · intro i F hF + exact (hstep i F.1 F.2 hF).1 + have hinput (i : I) : FunctionParticleReachable d L H + ((R.parent i).elim seed S).1 := by + cases hp : R.parent i with + | none => exact FunctionParticleReachable.zero + | some p => exact hreach p + have hstate (i : I) : + launchBatch (interface R bag i) (fresh R A i).toList (retained R A i) + ((R.parent i).elim seed S).1 ((R.parent i).elim seed S).2 (g i) = S i := + (state_eq R bag A g i).symm + refine ⟨hreach, ?_, ?_, ?_⟩ + · intro i p hp + have hj := (hstep i ((R.parent i).elim seed S).1 + ((R.parent i).elim seed S).2 (hinput i)).2.1 + rw [hstate] at hj + unfold interface at hj + rw [hp] at hj + exact hj + · intro i p hp a ha + have hj := hstep i ((R.parent i).elim seed S).1 + ((R.parent i).elim seed S).2 (hinput i) + dsimp only at hj + rw [hstate] at hj + have hm : a ∈ retained R A i := by simpa only [retained, hp, Option.elim_some] using ha + have he := hj.2.2.1 a hm + have hleft := hj.2.2.2.1 _ (first_mem_used hm ((R.parent i).elim seed S).2) + have hright := hj.2.2.2.1 _ (second_mem_used hm ((R.parent i).elim seed S).2) + have he' : (S i).2 a = (S p).2 a := by + simpa only [hp, Option.elim_some] using he + refine ⟨he', ?_, ?_⟩ + · rw [he'] + simpa only [hp, Option.elim_some] using hleft + · rw [he'] + simpa only [hp, Option.elim_some] using hright + · intro i a ha + have hj := (hstep i ((R.parent i).elim seed S).1 + ((R.parent i).elim seed S).2 (hinput i)).2.2.2.2 a (Finset.mem_toList.mpr ha) + rw [hstate] at hj + exact hj +end BoundedTreewidthL1.TreeParticles + +namespace BoundedTreewidthL1.TreeParticles +open MeasureTheory ParticleSchedule ParticleBatch +variable {I V ι J Ω : Type*} [Fintype V] [Fintype ι] [Nonempty ι] + [DecidableEq ι] [DecidableEq J] [Fintype J] [MeasurableSpace Ω] + [MeasurableSpace ι] [MeasurableSingletonClass ι] + +/-- Measurability of the actual branching preparation, with all randomness +sampled beforehand. No measurable-choice assumption about the particle lists. -/ +theorem measurable_state (R : RootedForest I) (bag : I → Finset V) (A : I → Finset J) + (g : Ω → I → J → V → ℝ) + (hg : ∀ i a v, Measurable (fun ω => g ω i a v)) (i : I) : + Measurable (fun ω => state (ι := ι) R bag A (g ω) i) := by + apply R.run_measurable (fun _ => seed) (fun j ω S => step R bag A (g ω) j S) + measurable_const + intro j f hf + exact measurable_launchBatch (interface R bag j) (fresh R A j).toList (retained R A j) + (fun ω => (f ω).1) (fun ω => (f ω).2) (fun ω => g ω j) + (fun a v => (measurable_pi_apply v).comp ((measurable_pi_apply a).comp hf.fst)) + (fun a => (measurable_pi_apply a).comp hf.snd) (hg j) + +end BoundedTreewidthL1.TreeParticles + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/WeightedPaths.lean b/lean/OAI/Combinatorics/TreewidthL1/WeightedPaths.lean new file mode 100644 index 0000000000000000000000000000000000000000..ca8a7410ad65c10c102ae5c199d20cd77d362a49 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/WeightedPaths.lean @@ -0,0 +1,160 @@ +import OAI.Combinatorics.TreewidthL1.Model + +namespace OAI + +namespace BoundedTreewidthL1 + +section WeightedPaths + +variable {V : Type*} (G : SimpleGraph V) (ℓ : G.edgeSet → ℝ) + +/-- Extension by zero, only used to write the sum over `Walk.edges`. +It does not add edges or change any graph-walk length. -/ +noncomputable def edgeLength (e : Sym2 V) : ℝ := by + classical + exact if h : e ∈ G.edgeSet then ℓ ⟨e, h⟩ else 0 + +lemma edgeLength_of_mem {e : Sym2 V} (h : e ∈ G.edgeSet) : + edgeLength G ℓ e = ℓ ⟨e, h⟩ := by + simp [edgeLength, h] + +lemma edgeLength_nonneg (hℓ : ∀ e, 0 ≤ ℓ e) (e : Sym2 V) : + 0 ≤ edgeLength G ℓ e := by + unfold edgeLength + split_ifs with h + · exact hℓ _ + · exact le_rfl + +lemma walkLength_eq_sum_edges {u v : V} (p : G.Walk u v) : + walkLength G ℓ p = (p.edges.map (edgeLength G ℓ)).sum := by + induction p with + | nil => rfl + | @cons u v w h p ih => + simp only [walkLength, SimpleGraph.Walk.edges_cons, List.map_cons, List.sum_cons, ih] + rw [edgeLength_of_mem G ℓ (e := s(u, v)) h] + +lemma walkLength_nonneg (hℓ : ∀ e, 0 ≤ ℓ e) {u v : V} (p : G.Walk u v) : + 0 ≤ walkLength G ℓ p := by + induction p with + | nil => exact le_rfl + | cons h p ih => exact add_nonneg (hℓ _) ih + +lemma walkLength_pos (hℓ : ∀ e, 0 < ℓ e) {u v : V} + (huv : u ≠ v) (p : G.Walk u v) : 0 < walkLength G ℓ p := by + cases p with + | nil => exact (huv rfl).elim + | cons h p => + exact add_pos_of_pos_of_nonneg (hℓ _) (walkLength_nonneg G ℓ (fun e => (hℓ e).le) p) + +lemma walkLength_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : + walkLength G ℓ (p.append q) = walkLength G ℓ p + walkLength G ℓ q := by + simp only [walkLength_eq_sum_edges, SimpleGraph.Walk.edges_append, + List.map_append, List.sum_append] + +lemma walkLength_reverse {u v : V} (p : G.Walk u v) : + walkLength G ℓ p.reverse = walkLength G ℓ p := by + simp [walkLength_eq_sum_edges, SimpleGraph.Walk.edges_reverse] + +lemma walkLength_bypass_le [DecidableEq V] (hℓ : ∀ e, 0 ≤ ℓ e) + {u v : V} (p : G.Walk u v) : walkLength G ℓ p.bypass ≤ walkLength G ℓ p := by + rw [walkLength_eq_sum_edges, walkLength_eq_sum_edges] + apply (p.edges_bypass_sublist_edges.map (edgeLength G ℓ)).sum_le_sum + intro a ha + obtain ⟨e, _, rfl⟩ := List.mem_map.mp ha + exact edgeLength_nonneg G ℓ hℓ e + +lemma path_length_set_finite [Fintype V] (u v : V) : + {r : ℝ | ∃ p : G.Walk u v, p.IsPath ∧ walkLength G ℓ p = r}.Finite := by + classical + convert Set.finite_range (fun p : G.Path u v => walkLength G ℓ p.val) using 1 + ext r + constructor + · rintro ⟨p, hp, hr⟩ + exact ⟨⟨p, hp⟩, hr⟩ + · rintro ⟨p, hr⟩ + exact ⟨p.val, p.property, hr⟩ + +lemma path_length_set_nonempty (hG : G.Connected) (u v : V) : + {r : ℝ | ∃ p : G.Walk u v, p.IsPath ∧ walkLength G ℓ p = r}.Nonempty := by + obtain ⟨p, hp, _⟩ := hG.exists_path_of_dist u v + exact ⟨walkLength G ℓ p, p, hp, rfl⟩ + +lemma shortestPathDistance_attained [Fintype V] (hG : G.Connected) (u v : V) : + ∃ p : G.Walk u v, p.IsPath ∧ walkLength G ℓ p = shortestPathDistance G ℓ u v := + (path_length_set_nonempty G ℓ hG u v).csInf_mem (path_length_set_finite G ℓ u v) + +lemma shortestPathDistance_nonneg (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) + (u v : V) : 0 ≤ shortestPathDistance G ℓ u v := by + apply le_csInf (path_length_set_nonempty G ℓ hG u v) + rintro r ⟨p, _, rfl⟩ + exact walkLength_nonneg G ℓ hℓ p + +lemma shortestPathDistance_le_pathLength (hℓ : ∀ e, 0 ≤ ℓ e) + {u v : V} (p : G.Walk u v) (hp : p.IsPath) : + shortestPathDistance G ℓ u v ≤ walkLength G ℓ p := by + unfold shortestPathDistance + refine csInf_le ?_ ⟨p, hp, rfl⟩ + refine ⟨0, ?_⟩ + rintro r ⟨q, _, rfl⟩ + exact walkLength_nonneg G ℓ hℓ q + +lemma shortestPathDistance_le_walkLength (hℓ : ∀ e, 0 ≤ ℓ e) + {u v : V} (p : G.Walk u v) : + shortestPathDistance G ℓ u v ≤ walkLength G ℓ p := by + classical + exact (shortestPathDistance_le_pathLength G ℓ hℓ p.bypass p.bypass_isPath).trans + (walkLength_bypass_le G ℓ hℓ p) + +lemma shortestPathDistance_self (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) + (u : V) : shortestPathDistance G ℓ u u = 0 := + le_antisymm (shortestPathDistance_le_walkLength G ℓ hℓ .nil) + (shortestPathDistance_nonneg G ℓ hG hℓ u u) + +lemma shortestPathDistance_pos [Fintype V] (hG : G.Connected) (hℓ : ∀ e, 0 < ℓ e) + {u v : V} (huv : u ≠ v) : 0 < shortestPathDistance G ℓ u v := by + obtain ⟨p, _, hp⟩ := shortestPathDistance_attained G ℓ hG u v + rw [← hp] + exact walkLength_pos G ℓ hℓ huv p + +lemma shortestPathDistance_comm [Fintype V] (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) + (u v : V) : shortestPathDistance G ℓ u v = shortestPathDistance G ℓ v u := by + have hd (a b : V) : shortestPathDistance G ℓ a b ≤ shortestPathDistance G ℓ b a := by + obtain ⟨p, hp, heq⟩ := shortestPathDistance_attained G ℓ hG b a + rw [← heq, ← walkLength_reverse G ℓ p] + exact shortestPathDistance_le_pathLength G ℓ hℓ p.reverse hp.reverse + exact le_antisymm (hd u v) (hd v u) + +lemma shortestPathDistance_triangle [Fintype V] (hG : G.Connected) (hℓ : ∀ e, 0 ≤ ℓ e) + (u v w : V) : shortestPathDistance G ℓ u w ≤ + shortestPathDistance G ℓ u v + shortestPathDistance G ℓ v w := by + obtain ⟨p, _, hp⟩ := shortestPathDistance_attained G ℓ hG u v + obtain ⟨q, _, hq⟩ := shortestPathDistance_attained G ℓ hG v w + rw [← hp, ← hq, ← walkLength_append G ℓ p q] + exact shortestPathDistance_le_walkLength G ℓ hℓ (p.append q) + +theorem shortestPathDistance_metric [Fintype V] (hG : G.Connected) + (hℓ : ∀ e, 0 < ℓ e) : + (∀ u v, 0 ≤ shortestPathDistance G ℓ u v) ∧ + (∀ u, shortestPathDistance G ℓ u u = 0) ∧ + (∀ u v, shortestPathDistance G ℓ u v = shortestPathDistance G ℓ v u) ∧ + (∀ u v w, shortestPathDistance G ℓ u w ≤ + shortestPathDistance G ℓ u v + shortestPathDistance G ℓ v w) ∧ + (∀ u v, shortestPathDistance G ℓ u v = 0 → u = v) ∧ + (∀ u v, ∃ p : G.Walk u v, + p.IsPath ∧ walkLength G ℓ p = shortestPathDistance G ℓ u v) := by + have hnonneg : ∀ e, 0 ≤ ℓ e := fun e => (hℓ e).le + refine ⟨shortestPathDistance_nonneg G ℓ hG hnonneg, + shortestPathDistance_self G ℓ hG hnonneg, + shortestPathDistance_comm G ℓ hG hnonneg, + shortestPathDistance_triangle G ℓ hG hnonneg, ?_, + shortestPathDistance_attained G ℓ hG⟩ + intro u v hzero + by_contra huv + have hpos := shortestPathDistance_pos G ℓ hG hℓ huv + linarith + +end WeightedPaths + +end BoundedTreewidthL1 + +end OAI diff --git a/lean/OAI/Combinatorics/TreewidthL1/YoungestCrossing.lean b/lean/OAI/Combinatorics/TreewidthL1/YoungestCrossing.lean new file mode 100644 index 0000000000000000000000000000000000000000..8e5a7e0ec30d6920bb7b06908b26abed668956a3 --- /dev/null +++ b/lean/OAI/Combinatorics/TreewidthL1/YoungestCrossing.lean @@ -0,0 +1,586 @@ +import OAI.Combinatorics.TreewidthL1.AnchorExperiment + +namespace OAI + +namespace BoundedTreewidthL1 +open Filter + +def InfinitesimalAlong {I : Type*} (U : Ultrafilter I) (x : I → ℝ) : Prop := + ∀ ε : ℝ, 0 < ε → ∀ᶠ i in U, x i < ε + +/-- A reservation interval whose effective start is early and terminal time is +late. Validity is explicit; no anchor is created merely by taking a quotient. -/ +def CrossingSequence {I : Type*} (U : Ultrafilter I) + (valid : I → ℕ → Prop) (start finish : I → ℕ → ℕ) + (δ : I → ℕ → ℝ) (a : I → ℕ) : Prop := + (∀ᶠ i in U, valid i (a i)) ∧ + ¬InfinitesimalAlong U (fun i => δ i (start i (a i))) ∧ + InfinitesimalAlong U (fun i => δ i (finish i (a i))) + +/-- Crossing anchor sequences identified precisely when they agree eventually. -/ +def CrossingGerms {I : Type*} (U : Ultrafilter I) + (valid : I → ℕ → Prop) (start finish : I → ℕ → ℕ) (δ : I → ℕ → ℝ) : + Set (Germ (U : Filter I) ℕ) := + {x | ∃ a : I → ℕ, (a : Germ (U : Filter I) ℕ) = x ∧ + CrossingSequence U valid start finish δ a} + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open Filter + +lemma noninfinitesimal_iff {I : Type*} (U : Ultrafilter I) (x : I → ℝ) : + ¬InfinitesimalAlong U x ↔ ∃ ε : ℝ, 0 < ε ∧ ∀ᶠ i in U, ε ≤ x i := by + classical + simp only [InfinitesimalAlong, not_forall] + constructor + · rintro ⟨ε, hε, hn⟩ + refine ⟨ε, hε, ?_⟩ + simpa only [not_lt] using (Ultrafilter.eventually_not.mpr hn) + · rintro ⟨ε, hε, hx⟩ + refine ⟨ε, hε, ?_⟩ + intro h + obtain ⟨i, hi, hi'⟩ := (hx.and h).exists + exact (not_lt_of_ge hi) hi' + +lemma early_precedes_late {I : Type*} (U : Ultrafilter I) (δ : I → ℕ → ℝ) + (hmono : ∀ i, Antitone (δ i)) (s t : I → ℕ) + (hs : ¬InfinitesimalAlong U (fun i => δ i (s i))) + (ht : InfinitesimalAlong U (fun i => δ i (t i))) : + ∀ᶠ i in U, s i < t i := by + obtain ⟨ε, hε, he⟩ := (noninfinitesimal_iff U _).mp hs + filter_upwards [he, ht ε hε] with i hi hi' + by_contra h + have hm := hmono i (Nat.le_of_not_gt h) + exact (not_lt_of_ge (hi.trans hm)) hi' + +lemma germ_total {I : Type*} (U : Ultrafilter I) + (a b : Germ (U : Filter I) ℕ) : a ≤ b ∨ b ≤ a := by + induction a using Germ.inductionOn with + | h a => + induction b using Germ.inductionOn with + | h b => + exact Ultrafilter.eventually_or.mp (Eventually.of_forall (fun i => le_total (a i) (b i))) + +/-- Any fixed finite collection of pairwise distinct crossing reservations is +simultaneously present at the latest of its effective start times. -/ +theorem crossing_family_card_le {I J : Type*} [Fintype J] (U : Ultrafilter I) + (valid : I → ℕ → Prop) (start finish : I → ℕ → ℕ) (δ : I → ℕ → ℝ) + (cache : I → ℕ → Finset ℕ) (N : ℕ) + (hmono : ∀ i, Antitone (δ i)) + (hcache : ∀ i a t, valid i a → start i a ≤ t → t ≤ finish i a → a ∈ cache i t) + (hsize : ∀ i t, (cache i t).card ≤ N) + (a : J → I → ℕ) (ha : ∀ j, CrossingSequence U valid start finish δ (a j)) + (hdistinct : ∀ j k, j ≠ k → ∀ᶠ i in U, a j i ≠ a k i) : + Fintype.card J ≤ N := by + classical + let latest (i : I) := Finset.univ.sup (fun j => start i (a j i)) + have hva : ∀ᶠ i in U, ∀ j, valid i (a j i) := + eventually_all.mpr (fun j => (ha j).1) + have hbefore : ∀ᶠ i in U, ∀ j k, start i (a j i) < finish i (a k i) := by + apply eventually_all.mpr + intro j + apply eventually_all.mpr + intro k + exact early_precedes_late U δ hmono _ _ (ha j).2.1 (ha k).2.2 + have hinj : ∀ᶠ i in U, Function.Injective (fun j => a j i) := by + have hef : ∀ᶠ i in U, ∀ j k, j ≠ k → a j i ≠ a k i := by + apply eventually_all.mpr + intro j + apply eventually_all.mpr + intro k + by_cases h : j = k + · exact Eventually.of_forall (by simp [h]) + · exact (hdistinct j k h).mono (fun _ hi _ => hi) + exact hef.mono (fun i hi j k hjk => by_contra (fun hne => hi j k hne hjk)) + obtain ⟨i, hvi, hbi, hii⟩ := (hva.and (hbefore.and hinj)).exists + have hmem : ∀ j, a j i ∈ cache i (latest i) := by + intro j + apply hcache i (a j i) (latest i) (hvi j) + · exact Finset.le_sup (s := Finset.univ) (f := fun j => start i (a j i)) (Finset.mem_univ j) + · exact Finset.sup_le (fun k _ => (hbi k j).le) + let f : J → ↥(cache i (latest i)) := fun j => ⟨a j i, hmem j⟩ + have hf : Function.Injective f := by + intro j k h + exact hii (congrArg Subtype.val h) + have hc := Fintype.card_le_of_injective f hf + simp only [Fintype.card_coe] at hc + exact hc.trans (hsize i (latest i)) + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open Filter + +lemma crossing_finset_card_le {I : Type*} (U : Ultrafilter I) + (valid : I → ℕ → Prop) (start finish : I → ℕ → ℕ) (δ : I → ℕ → ℝ) + (cache : I → ℕ → Finset ℕ) (N : ℕ) + (hmono : ∀ i, Antitone (δ i)) + (hcache : ∀ i a t, valid i a → start i a ≤ t → t ≤ finish i a → a ∈ cache i t) + (hsize : ∀ i t, (cache i t).card ≤ N) + (s : Finset (Germ (U : Filter I) ℕ)) + (hs : ∀ x ∈ s, x ∈ CrossingGerms U valid start finish δ) : s.card ≤ N := by + classical + have hrep : ∀ j : ↥s, ∃ a : I → ℕ, + (a : Germ (U : Filter I) ℕ) = j.val ∧ CrossingSequence U valid start finish δ a := + fun j => hs j.val j.property + choose a heq ha using hrep + have hd : ∀ j k : ↥s, j ≠ k → ∀ᶠ i in U, a j i ≠ a k i := by + intro j k hjk + apply Ultrafilter.eventually_not.mpr + intro h + apply hjk + apply Subtype.ext + exact (heq j).symm.trans ((Germ.coe_eq.mpr h).trans (heq k)) + have hc := crossing_family_card_le U valid start finish δ cache N hmono hcache hsize a ha hd + simpa only [Fintype.card_coe] using hc + +/-- The youngest crossing, with the inclusive cache bound and monotone +normalized distances made explicit. -/ +theorem youngest_crossing {I : Type*} (U : Ultrafilter I) + (valid : I → ℕ → Prop) (start finish : I → ℕ → ℕ) (δ : I → ℕ → ℝ) + (cache : I → ℕ → Finset ℕ) (N : ℕ) + (hmono : ∀ i, Antitone (δ i)) + (hcache : ∀ i a t, valid i a → start i a ≤ t → t ≤ finish i a → a ∈ cache i t) + (hsize : ∀ i t, (cache i t).card ≤ N) + (hne : (CrossingGerms U valid start finish δ).Nonempty) : + (CrossingGerms U valid start finish δ).Finite ∧ + (CrossingGerms U valid start finish δ).ncard ≤ N ∧ + ∃ youngest ∈ CrossingGerms U valid start finish δ, + ∀ a ∈ CrossingGerms U valid start finish δ, a ≤ youngest := by + classical + let C := CrossingGerms U valid start finish δ + have hb : ∀ s : Finset (Germ (U : Filter I) ℕ), (∀ x ∈ s, x ∈ C) → s.card ≤ N := + crossing_finset_card_le U valid start finish δ cache N hmono hcache hsize + have hfin : C.Finite := by + by_contra h + obtain ⟨t, ht, htf, htc⟩ := Set.Infinite.exists_subset_ncard_eq h (N + 1) + have hbound := hb htf.toFinset (fun x hx => ht (htf.mem_toFinset.mp hx)) + have hc : htf.toFinset.card = t.ncard := (Set.ncard_eq_toFinset_card t htf).symm + rw [hc, htc] at hbound + omega + refine ⟨hfin, ?_, ?_⟩ + · have hbound := hb hfin.toFinset (fun x hx => hfin.mem_toFinset.mp hx) + rw [show CrossingGerms U valid start finish δ = C from rfl, Set.ncard_eq_toFinset_card C hfin] + exact hbound + · obtain ⟨a, ha, hmax⟩ := hfin.exists_maximal hne + refine ⟨a, ha, ?_⟩ + intro b hb + rcases germ_total U b a with hba | hab + · exact hba + · exact hmax hb hab + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 + +namespace ReservationPath + +def Present (P : ReservationPath) (a t : ℕ) : Prop := a ≤ t ∧ t ≤ P.finish a + +def Successor (P : ReservationPath) (a b t : ℕ) : Prop := + P.Present a t ∧ P.Present b t ∧ a < b ∧ + ∀ c, P.Present c t → a < c → b ≤ c + +lemma mem_inclusive (P : ReservationPath) {a t : ℕ} (ht : t ≤ P.last) : + a ∈ P.inclusive t ↔ P.Present a t := by + classical + simp only [inclusive, ht, ↓reduceIte, Finset.mem_filter, Finset.mem_range, Present] + omega + +lemma proposal_present (P : ReservationPath) (t : ℕ) (ht : t ≤ P.last) : + P.Present t t := ⟨le_rfl, P.launch_le_finish t ht⟩ + +lemma successor_exists (P : ReservationPath) (a t : ℕ) + (ht : t ≤ P.last) (ha : P.Present a t) (hat : a < t) : + ∃ b, P.Successor a b t := by + classical + let S := (P.inclusive t).filter (fun b => a < b) + have hS : S.Nonempty := ⟨t, Finset.mem_filter.mpr ⟨(P.mem_inclusive ht).mpr + (P.proposal_present t ht), hat⟩⟩ + refine ⟨S.min' hS, ha, ?_, ?_, ?_⟩ + · exact (P.mem_inclusive ht).mp (Finset.mem_filter.mp (Finset.min'_mem S hS)).1 + · exact (Finset.mem_filter.mp (Finset.min'_mem S hS)).2 + · intro c hc hac + exact Finset.min'_le S c (Finset.mem_filter.mpr ⟨(P.mem_inclusive ht).mpr hc, hac⟩) + +lemma proposal_retained_of_other_release (P : ReservationPath) (a t : ℕ) + (hat : a < t) (ht : t < P.last) (ha : P.finish a = t) : t < P.finish t := by + have hp := P.launch_le_finish t ht.le + by_contra h + have hft : P.finish t = t := Nat.le_antisymm (Nat.le_of_not_gt h) hp + have := P.one_release a t t hat.le le_rfl ht ha hft + omega + +/-- Once b immediately follows a after an eviction test, no subsequent insertion +can appear between them: new anchors have later launch times. -/ +lemma successor_at_later_test (P : ReservationPath) (a b t u : ℕ) + (hab : a < b) (hbt : b ≤ t) (htu : t < u) + (ha : P.Present a u) (hb : P.Present b u) + (hmin : ∀ c, a < c → c ≤ t → t < P.finish c → b ≤ c) : + P.Successor a b u := by + refine ⟨ha, hb, hab, ?_⟩ + intro c hc hac + by_cases hct : c ≤ t + · exact hmin c hac hct (htu.trans_le hc.2) + · exact hbt.trans (Nat.le_of_not_ge hct) + +/-- A surviving younger anchor exists after the last eviction of any younger +anchor launched above S. The only use of protection is for a successor already +launched at or after `S`. -/ +lemma retained_successor (P : ReservationPath) (a S t : ℕ) + (haS : a < S) (hSt : S ≤ t) (ht : t < P.last) + (ha : t < P.finish a) + (hold : ∀ c, a < c → c < S → P.finish c ≤ t) + (hprotect : ∀ b, S ≤ b → P.Successor a b t → t < P.finish b) : + ∃ b, a < b ∧ S ≤ b ∧ b ≤ t ∧ t < P.finish b ∧ + ∀ c, a < c → c ≤ t → t < P.finish c → b ≤ c := by + classical + obtain ⟨b, hb⟩ := P.successor_exists a t ht.le ⟨haS.le.trans hSt, ha.le⟩ + (haS.trans_le hSt) + have hex : ∃ c, a < c ∧ c ≤ t ∧ t < P.finish c := by + by_cases hSb : S ≤ b + · exact ⟨b, hb.2.2.1, hb.2.1.1, hprotect b hSb hb⟩ + · have hbS : b < S := Nat.lt_of_not_ge hSb + have hbf : P.finish b = t := (hold b hb.2.2.1 hbS).antisymm hb.2.1.2 + exact ⟨t, haS.trans_le hSt, le_rfl, + P.proposal_retained_of_other_release b t (hbS.trans_le hSt) ht hbf⟩ + let A := (Finset.range (t + 1)).filter (fun c => a < c ∧ t < P.finish c) + have hA : A.Nonempty := by + obtain ⟨c, hac, hct, hcf⟩ := hex + exact ⟨c, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), hac, hcf⟩⟩ + let b' := A.min' hA + have hb' : a < b' ∧ b' ≤ t ∧ t < P.finish b' := by + have hm := Finset.mem_filter.mp (Finset.min'_mem A hA) + exact ⟨hm.2.1, Nat.le_of_lt_succ (Finset.mem_range.mp hm.1), hm.2.2⟩ + refine ⟨b', hb'.1, ?_, hb'.2.1, hb'.2.2, ?_⟩ + · by_contra h + have := hold b' hb'.1 (Nat.lt_of_not_ge h) + omega + · intro c hac hct hcf + exact Finset.min'_le A c (Finset.mem_filter.mpr + ⟨Finset.mem_range.mpr (by omega), hac, hcf⟩) + +end ReservationPath +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open Filter + +def PathCrossing {I : Type*} (U : Ultrafilter I) (P : I → ReservationPath) + (S : I → ℕ) (δ : I → ℕ → ℝ) (a : I → ℕ) : Prop := + CrossingSequence U + (fun i b => b ≤ (P i).last ∧ S i ≤ (P i).finish b) + (fun i b => max (S i) b) (fun i => (P i).finish) δ a + +lemma infinitesimal_congr {I : Type*} (U : Ultrafilter I) {x y : I → ℝ} + (h : ∀ᶠ i in U, x i = y i) : InfinitesimalAlong U x ↔ InfinitesimalAlong U y := by + constructor + · intro hx ε hε + filter_upwards [h, hx ε hε] with i hi hi' + simpa only [← hi] using hi' + · intro hy ε hε + filter_upwards [h, hy ε hε] with i hi hi' + simpa only [hi] using hi' + +lemma infinitesimal_mono {I : Type*} (U : Ultrafilter I) {x y : I → ℝ} + (h : ∀ᶠ i in U, x i ≤ y i) (hy : InfinitesimalAlong U y) : + InfinitesimalAlong U x := by + intro ε hε + filter_upwards [h, hy ε hε] with i hi hi' + exact hi.trans_lt hi' + +lemma eventually_choose_nat {I : Type*} (U : Ultrafilter I) (p : I → ℕ → Prop) + (h : ∀ᶠ i in U, ∃ b, p i b) : ∃ b : I → ℕ, ∀ᶠ i in U, p i (b i) := by + classical + let b i := if h : ∃ a, p i a then Classical.choose h else 0 + refine ⟨b, h.mono ?_⟩ + intro i hi + simpa only [b, dite_eq_left hi] using Classical.choose_spec hi + +theorem younger_crossing {I : Type*} (U : Ultrafilter I) + (P : I → ReservationPath) (S : I → ℕ) (δ : I → ℕ → ℝ) + (hSL : ∀ i, S i ≤ (P i).last) (hmono : ∀ i, Antitone (δ i)) + (hSearly : ¬InfinitesimalAlong U (fun i => δ i (S i))) + (hXlate : InfinitesimalAlong U (fun i => δ i (P i).last)) + (a : I → ℕ) (ha : PathCrossing U P S δ a) + (haold : ∀ᶠ i in U, a i < S i) + (hprotect : ∀ t : I → ℕ, ¬InfinitesimalAlong U (fun i => δ i (t i)) → + ∀ᶠ i in U, ∀ b, S i ≤ b → (P i).Successor (a i) b (t i) → + t i < (P i).finish b) : + ∃ b : I → ℕ, PathCrossing U P S δ b ∧ ∀ᶠ i in U, a i < b i := by + classical + by_contra hno + have hnone : ∀ b : I → ℕ, PathCrossing U P S δ b → + ¬(∀ᶠ i in U, a i < b i) := by + intro b hb hab + exact hno ⟨b, hb, hab⟩ + let O (i : I) := (Finset.range (S i)).filter (fun b => a i < b) + let t (i : I) := max (S i) ((O i).sup (P i).finish) + have hSt : ∀ i, S i ≤ t i := fun i => le_max_left _ _ + have hold : ∀ i c, a i < c → c < S i → (P i).finish c ≤ t i := by + intro i c hac hcS + exact (Finset.le_sup (s := O i) (f := (P i).finish) + (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hcS, hac⟩)).trans (le_max_right _ _) + have htL : ∀ i, t i ≤ (P i).last := by + intro i + apply max_le (hSL i) + apply Finset.sup_le + intro b hb + have hbS := Finset.mem_range.mp (Finset.mem_filter.mp hb).1 + exact (P i).finish_le_last b (hbS.le.trans (hSL i)) + have hattain : ∀ i, S i < t i → + ∃ b, a i < b ∧ b < S i ∧ (P i).finish b = t i := by + intro i hi + have hsup : t i = (O i).sup (P i).finish := max_eq_right (by dsimp [t] at hi; omega) + have hO : (O i).Nonempty := by + by_contra hn + have he := Finset.not_nonempty_iff_eq_empty.mp hn + simp only [he, Finset.sup_empty, bot_eq_zero] at hsup + omega + obtain ⟨b, hb, he⟩ := Finset.exists_mem_eq_sup (O i) hO (P i).finish + exact ⟨b, (Finset.mem_filter.mp hb).2, + Finset.mem_range.mp (Finset.mem_filter.mp hb).1, he.symm.trans hsup.symm⟩ + have htearly : ¬InfinitesimalAlong U (fun i => δ i (t i)) := by + intro htlate + have hbefore := early_precedes_late U δ hmono S t hSearly htlate + obtain ⟨b, hb⟩ := eventually_choose_nat U + (fun i b => a i < b ∧ b < S i ∧ (P i).finish b = t i) + (hbefore.mono fun i hi => hattain i hi) + have hcross : PathCrossing U P S δ b := by + refine ⟨?_, ?_, ?_⟩ + · filter_upwards [hb] with i hi + exact ⟨hi.2.1.le.trans (hSL i), hi.2.2 ▸ hSt i⟩ + · have heq : ∀ᶠ i in U, δ i (max (S i) (b i)) = δ i (S i) := by + filter_upwards [hb] with i hi + rw [max_eq_left hi.2.1.le] + exact fun h => hSearly ((infinitesimal_congr U heq).mp h) + · have heq : ∀ᶠ i in U, δ i ((P i).finish (b i)) = δ i (t i) := + hb.mono (fun i hi => congrArg (δ i) hi.2.2) + exact (infinitesimal_congr U heq).mpr htlate + exact hnone b hcross (hb.mono (fun _ hi => hi.1)) + have hta := early_precedes_late U δ hmono t (fun i => (P i).finish (a i)) + htearly ha.2.2 + have htX := early_precedes_late U δ hmono t (fun i => (P i).last) htearly hXlate + have hprot := hprotect t htearly + have hex : ∀ᶠ i in U, ∃ b, a i < b ∧ S i ≤ b ∧ b ≤ t i ∧ + t i < (P i).finish b ∧ + ∀ c, a i < c → c ≤ t i → t i < (P i).finish c → b ≤ c := by + filter_upwards [haold, hta, htX, hprot] with i hai htai htXi hpi + exact (P i).retained_successor (a i) (S i) (t i) hai (hSt i) htXi htai + (hold i) hpi + obtain ⟨b, hb⟩ := eventually_choose_nat U _ hex + have hbearly : ¬InfinitesimalAlong U (fun i => δ i (max (S i) (b i))) := by + intro hblate + exact htearly (infinitesimal_mono U (hb.mono (fun i hi => + hmono i (max_le (hSt i) hi.2.2.1))) hblate) + have hbvalid : ∀ᶠ i in U, b i ≤ (P i).last ∧ S i ≤ (P i).finish (b i) := by + filter_upwards [hb] with i hi + exact ⟨hi.2.2.1.trans (htL i), (hSt i).trans hi.2.2.2.1.le⟩ + have hbendearly : ¬InfinitesimalAlong U (fun i => δ i ((P i).finish (b i))) := by + intro hlate + exact hnone b ⟨hbvalid, hbearly, hlate⟩ (hb.mono (fun _ hi => hi.1)) + let u i := (P i).finish (b i) + have hua := early_precedes_late U δ hmono u (fun i => (P i).finish (a i)) + hbendearly ha.2.2 + have huprot := hprotect u hbendearly + have hcontr : ∀ᶠ i : I in (U : Filter I), False := by + filter_upwards [hb, hbvalid, hua, huprot] with i hi hvi huai hpi + have hsucc : (P i).Successor (a i) (b i) (u i) := by + apply (P i).successor_at_later_test (a i) (b i) (t i) (u i) + hi.1 hi.2.2.1 hi.2.2.2.1 + · exact ⟨hi.1.le.trans ((P i).launch_le_finish (b i) hvi.1), huai.le⟩ + · exact ⟨(P i).launch_le_finish (b i) hvi.1, le_rfl⟩ + · exact hi.2.2.2.2 + have hbad := hpi (b i) hi.2.1 hsucc + exact (lt_irrefl (u i)) hbad + exact hcontr.exists.elim (fun _ h => h) + +theorem cache_no_failure {I : Type*} (U : Ultrafilter I) + (P : I → ReservationPath) (S : I → ℕ) (δ : I → ℕ → ℝ) (N : ℕ) + (hSL : ∀ i, S i ≤ (P i).last) (hmono : ∀ i, Antitone (δ i)) + (hSearly : ¬InfinitesimalAlong U (fun i => δ i (S i))) + (hXlate : InfinitesimalAlong U (fun i => δ i (P i).last)) + (hsize : ∀ i t, ((P i).inclusive t).card ≤ N) + (hold : ∀ a, PathCrossing U P S δ a → ∀ᶠ i in U, a i < S i) + (hprotect : ∀ a, PathCrossing U P S δ a → + ∀ t : I → ℕ, ¬InfinitesimalAlong U (fun i => δ i (t i)) → + ∀ᶠ i in U, ∀ b, S i ≤ b → (P i).Successor (a i) b (t i) → + t i < (P i).finish b) : False := by + classical + let valid i b := b ≤ (P i).last ∧ S i ≤ (P i).finish b + let start i b := max (S i) b + let finish i := (P i).finish + have hcache : ∀ i a t, valid i a → start i a ≤ t → t ≤ finish i a → + a ∈ (P i).inclusive t := by + intro i a t hv hst htf + have htL : t ≤ (P i).last := htf.trans ((P i).finish_le_last a hv.1) + exact ((P i).mem_inclusive htL).mpr ⟨(le_max_right _ _).trans hst, htf⟩ + have hroot : PathCrossing U P S δ (fun _ => 0) := by + refine ⟨Eventually.of_forall ?_, ?_, ?_⟩ + · intro i + exact ⟨Nat.zero_le _, (P i).root_permanent.symm ▸ hSL i⟩ + · simpa only [Nat.max_zero] using hSearly + · simpa only [ReservationPath.root_permanent] using hXlate + have hne : (CrossingGerms U valid start finish δ).Nonempty := + ⟨((fun _ : I => 0) : Germ (U : Filter I) ℕ), (fun _ => 0), rfl, hroot⟩ + obtain ⟨_, _, g, hg, hmax⟩ := youngest_crossing U valid start finish δ + (fun i => (P i).inclusive) N hmono hcache hsize hne + obtain ⟨a, heq, ha⟩ := hg + obtain ⟨b, hb, hab⟩ := younger_crossing U P S δ hSL hmono hSearly hXlate a + ha (hold a ha) (hprotect a ha) + have hbg : (b : Germ (U : Filter I) ℕ) ≤ g := hmax _ ⟨b, rfl, hb⟩ + rw [← heq] at hbg + have hba : ∀ᶠ i in U, b i ≤ a i := Germ.coe_le.mp hbg + obtain ⟨i, hi, hi'⟩ := (hab.and hba).exists + exact (not_lt_of_ge hi') hi + +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 +open Filter +/-- Numerical interface to the actual cached ensemble. The three tests below +are proved from that ensemble, rather than postulated in the embedding theorem. -/ +structure CacheControl (N : ℕ) (Q H : ℝ) where + path : ReservationPath + start : ℕ + start_le : start ≤ path.last + delta : ℕ → ℝ + antitone : Antitone delta + nonneg : ∀ t, 0 ≤ delta t + at_start : delta start = 1 + at_end : delta path.last = 0 + error : ℝ + error_nonneg : 0 ≤ error + size : ∀ t, (path.inclusive t).card ≤ N + launch : ∀ a e, e ≤ path.last → a ∈ path.inclusive e → start ≤ a → + delta a ≤ Q*(error+delta e) + distant : ∀ a e, e ≤ path.last → a ∈ path.inclusive e → a < start → + delta a ≤ H → 1 ≤ Q*(error+delta e) + protect : ∀ a e t b, e ≤ path.last → a ∈ path.inclusive e → a < start → + H < delta a → start ≤ t → t < e → start ≤ b → path.Successor a b t → + Q*(error+delta e) < delta t → t < path.finish b + +lemma infinitesimal_add_mul {I : Type*} (U : Ultrafilter I) (x y : I → ℝ) + (hx : InfinitesimalAlong U x) (hy : InfinitesimalAlong U y) (Q : ℝ) (hQ : 0 < Q) : + InfinitesimalAlong U (fun i => Q*(x i+y i)) := by + intro ε hε + have he : 0 < ε/(2*Q) := by positivity + filter_upwards [hx _ he,hy _ he] with i hxi hyi + have heq : ε/(2*Q)+ε/(2*Q) = ε/Q := by ring + have hh : x i+y i < ε/Q := by rw [← heq]; exact add_lt_add hxi hyi + simpa only [mul_comm] using (lt_div_iff₀ hQ).mp hh + +lemma CacheControl.no_failure {I : Type*} (U : Ultrafilter I) (N : ℕ) (Q H : ℝ) + (hQ : 0 < Q) (C : I → CacheControl N Q H) + (herror : InfinitesimalAlong U (fun i => (C i).error)) : False := by + have hear : ¬InfinitesimalAlong U (fun i => (C i).delta (C i).start) := by + intro hh + obtain ⟨i,hi⟩ := (hh 1 (by norm_num)).exists + change (C i).delta (C i).start < 1 at hi + rw [(C i).at_start] at hi + exact (lt_irrefl _ hi) + have hlate : InfinitesimalAlong U (fun i => (C i).delta (C i).path.last) := by + intro ε hε + exact Eventually.of_forall (fun i => by dsimp only; rw [(C i).at_end]; exact hε) + apply cache_no_failure U (fun i => (C i).path) (fun i => (C i).start) + (fun i => (C i).delta) N (fun i => (C i).start_le) + (fun i => (C i).antitone) hear hlate (fun i => (C i).size) + · intro a ha + have herr := infinitesimal_add_mul U _ _ herror ha.2.2 Q hQ + change ∀ᶠ i in U, a i < (C i).start + simp only [← not_le] + apply Ultrafilter.eventually_not.mpr + intro hnot + have haS : ∀ᶠ i in U, (C i).start ≤ a i := hnot.mono (fun _ hi => hi) + apply ha.2.1 + apply infinitesimal_mono U _ herr + filter_upwards [ha.1,haS] with i hi hiS + rw [max_eq_right hiS] + apply (C i).launch (a i) ((C i).path.finish (a i)) + ((C i).path.finish_le_last _ hi.1) _ hiS + exact ((C i).path.mem_inclusive ((C i).path.finish_le_last _ hi.1)).mpr + ⟨(C i).path.launch_le_finish _ hi.1,le_rfl⟩ + · intro a ha t ht + have herr := infinitesimal_add_mul U _ _ herror ha.2.2 Q hQ + have hold : ∀ᶠ i in U, a i < (C i).start := by + simp only [← not_le] + apply Ultrafilter.eventually_not.mpr + intro hnot + apply ha.2.1 + apply infinitesimal_mono U _ herr + filter_upwards [ha.1,hnot] with i hi hiS + rw [max_eq_right hiS] + apply (C i).launch (a i) ((C i).path.finish (a i)) + ((C i).path.finish_le_last _ hi.1) _ hiS + exact ((C i).path.mem_inclusive ((C i).path.finish_le_last _ hi.1)).mpr + ⟨(C i).path.launch_le_finish _ hi.1,le_rfl⟩ + have hdist : ∀ᶠ i in U, H < (C i).delta (a i) := by + filter_upwards [ha.1,hold,herr 1 (by norm_num)] with i hi hoi hei + by_contra hn + have hh := (C i).distant (a i) ((C i).path.finish (a i)) + ((C i).path.finish_le_last _ hi.1) + (((C i).path.mem_inclusive ((C i).path.finish_le_last _ hi.1)).mpr + ⟨(C i).path.launch_le_finish _ hi.1,le_rfl⟩) hoi (le_of_not_gt hn) + exact (not_lt_of_ge hh) hei + have hte := early_precedes_late U (fun i => (C i).delta) + (fun i => (C i).antitone) t (fun i => (C i).path.finish (a i)) ht ha.2.2 + obtain ⟨ε,hε,htearly⟩ := (noninfinitesimal_iff U _).mp ht + filter_upwards [ha.1,hold,hdist,hte,htearly,herr ε hε] with i hi hoi hdi hti het her + intro b hbS hsucc + apply (C i).protect (a i) ((C i).path.finish (a i)) (t i) b + ((C i).path.finish_le_last _ hi.1) + (((C i).path.mem_inclusive ((C i).path.finish_le_last _ hi.1)).mpr + ⟨(C i).path.launch_le_finish _ hi.1,le_rfl⟩) hoi hdi + (hbS.trans hsucc.2.1.1) hti hbS hsucc (her.trans_le het) + +/-- Compactness is used only on numerical cache data, not on random samplers or +on a bounded number of vertices. -/ +theorem CacheControl.uniform_lower (N : ℕ) (Q H : ℝ) (hQ : 0 < Q) : + ∃ c : ℝ, 0 < c ∧ ∀ C : CacheControl N Q H, c ≤ C.error := by + classical + by_contra hn + push Not at hn + have hex (n : ℕ) : ∃ C : CacheControl N Q H, C.error < 1/((n:ℝ)+1) := + hn _ (by positivity) + choose C hC using hex + let U := Ultrafilter.of (atTop : Filter ℕ) + apply CacheControl.no_failure U N Q H hQ C + intro ε hε + obtain ⟨n,hn⟩ := exists_nat_gt (1/ε) + apply (Ultrafilter.of_le atTop) (mem_atTop_sets.mpr ⟨n,?_⟩) + intro m hm + have hnm : (n:ℝ) ≤ m := by exact_mod_cast hm + have hmpos : 0 < (m:ℝ)+1 := by positivity + apply (hC m).trans + apply (div_lt_iff₀ hmpos).mpr + have hh := (div_lt_iff₀ hε).mp (hn.trans_le hnm) + nlinarith +end BoundedTreewidthL1 + +namespace BoundedTreewidthL1 + +theorem protected_threshold (K J H D₀ δ L older younger : ℝ) + (hK : 2 < K) (hJ : J = 10 * (K + 1)) (hH : 10 ^ 5 * J < H) + (hD : H < D₀) (hδ : 0 < δ) (_ : δ ≤ 1) + (hLlo : δ / 4 ≤ L) (hLhi : L ≤ 10 * D₀) + (hyδ : younger ≤ K * δ) (hy2 : younger ≤ 2) + (holder : D₀ - 1 ≤ older) : + ∃ τ ∈ ({L / 100, J * L} : Set ℝ), younger ≤ τ ∧ τ < older := by + have hJpos : 0 < J := by linarith + have hDlarge : 10 < D₀ := by norm_num at hH; linarith + by_cases hL : L ≤ 300 + · refine ⟨J * L, by simp, ?_, ?_⟩ + · have hmul := mul_le_mul_of_nonneg_left hLlo hJpos.le + have hgap : K * δ < J * (δ / 4) := by rw [hJ]; nlinarith + exact hyδ.trans (hgap.le.trans hmul) + · have hmul := mul_le_mul_of_nonneg_left hL hJpos.le + norm_num at hH + linarith + · refine ⟨L / 100, by simp, ?_, ?_⟩ + · linarith + · linarith + +end BoundedTreewidthL1 + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleFace/AffineMaps.lean b/lean/OAI/Combinatorics/TriangleFace/AffineMaps.lean new file mode 100644 index 0000000000000000000000000000000000000000..efb147d1b89d06e6b44b082f9847c93c4011b4ae --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleFace/AffineMaps.lean @@ -0,0 +1,26 @@ +import OAI.Combinatorics.TriangleFace.Model + +namespace OAI + +noncomputable section +open scoped BigOperators +open MatchingEntropyBounds MatchingEntropyBounds.Refined +namespace TriangleFace198 +universe uV uE +variable {V : Type uV} {E : Type uE} [instFintypeV : Fintype V] [Fintype E] [DecidableEq V] [instDecidableEqE : DecidableEq E] + +omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in +theorem restriction_extension (G : LooplessGraph V E) (c : E → Fin 3) (v : V) + (hc : LocalLabels G v c) (x : E → ℝ) : + oldRestriction (localExtension G c v hc x) = x := rfl + +omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in +theorem localExtension_injective (G : LooplessGraph V E) (c : E → Fin 3) (v : V) + (hc : LocalLabels G v c) : Function.Injective (localExtension G c v hc) := by + intro x y h + exact congrArg (oldRestriction : (E ⊕ Fin 3 → ℝ) →ₗ[ℝ] (E → ℝ)) h + +end TriangleFace198 +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleFace/Faces.lean b/lean/OAI/Combinatorics/TriangleFace/Faces.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d8ff1d4a3e9aaf613f0046f8549d32dc05e96b0 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleFace/Faces.lean @@ -0,0 +1,70 @@ +import OAI.Combinatorics.TriangleFace.Model + +namespace OAI + +namespace CanonicalFace198 + +variable {A B : Type*} [AddCommGroup A] [Module ℝ A] + [AddCommGroup B] [Module ℝ B] + +theorem self_mem (P : Set A) (x : A) : x ∈ minFace P x := by + apply Set.mem_sInter.mpr + intro F hF + exact hF.2.2 + +theorem least {P F : Set A} {x : A} (hF : Convex ℝ F) + (hPF : IsExtreme ℝ P F) (hxF : x ∈ F) : minFace P x ⊆ F := by + intro y hy + exact Set.mem_sInter.mp hy F ⟨hF, hPF, hxF⟩ + +theorem convex (P : Set A) (x : A) : Convex ℝ (minFace P x) := by + exact convex_sInter (fun _ hF => hF.1) + +theorem extreme {P : Set A} (hP : Convex ℝ P) {x : A} (hx : x ∈ P) : + IsExtreme ℝ P (minFace P x) := by + apply isExtreme_sInter + · exact ⟨P, hP, IsExtreme.refl ℝ P, hx⟩ + · intro F hF + exact hF.2.1 + +theorem subset {P : Set A} (hP : Convex ℝ P) {x : A} (hx : x ∈ P) : + minFace P x ⊆ P := (extreme hP hx).subset + +theorem extreme_affine_image (f : A →ᵃ[ℝ] B) (hf : Function.Injective f) + {P Q : Set A} (h : IsExtreme ℝ P Q) : IsExtreme ℝ (f '' P) (f '' Q) := by + refine ⟨Set.image_mono h.subset, ?_⟩ + rintro _ ⟨u,hu,rfl⟩ _ ⟨v,hv,rfl⟩ _ ⟨w,hw,rfl⟩ hseg + rw [← image_openSegment ℝ f] at hseg + obtain ⟨w',hw',he⟩ := hseg + have hww : w' = w := hf he + exact ⟨u, h.left_mem_of_mem_openSegment hu hv hw (hww ▸ hw'), rfl⟩ + +theorem extreme_affine_preimage (f : A →ᵃ[ℝ] B) {P : Set A} {Q R : Set B} + (hPQ : f '' P ⊆ Q) (hQR : IsExtreme ℝ Q R) : + IsExtreme ℝ P (P ∩ f ⁻¹' R) := by + refine ⟨Set.inter_subset_left, ?_⟩ + intro u hu v hv w hw hseg + refine ⟨hu, hQR.left_mem_of_mem_openSegment (hPQ ⟨u,hu,rfl⟩) + (hPQ ⟨v,hv,rfl⟩) hw.2 ?_⟩ + rw [← image_openSegment ℝ f] + exact ⟨w,hseg,rfl⟩ + +theorem image_minFace (f : A →ᵃ[ℝ] B) (hf : Function.Injective f) + {P : Set A} {K : Set B} (hP : Convex ℝ P) (hK : Convex ℝ K) + (hface : IsExtreme ℝ K (f '' P)) {x : A} (hx : x ∈ P) : + f '' minFace P x = minFace K (f x) := by + have hfx : f x ∈ K := hface.subset ⟨x, hx, rfl⟩ + apply Set.Subset.antisymm + · have hpreConvex : Convex ℝ (P ∩ f ⁻¹' minFace K (f x)) := + hP.inter ((convex K (f x)).affine_preimage f) + have hpreExtreme := extreme_affine_preimage f hface.subset (extreme hK hfx) + have hleast := least hpreConvex hpreExtreme ⟨hx, self_mem K (f x)⟩ + rintro _ ⟨y, hy, rfl⟩ + exact (hleast hy).2 + · apply least ((convex P x).affine_image f) + · exact hface.trans (extreme_affine_image f hf (extreme hP hx)) + · exact ⟨x, self_mem P x, rfl⟩ + +end CanonicalFace198 + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleFace/Labels.lean b/lean/OAI/Combinatorics/TriangleFace/Labels.lean new file mode 100644 index 0000000000000000000000000000000000000000..13d89320c3993e8986d21af61a4a480c94bf4507 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleFace/Labels.lean @@ -0,0 +1,42 @@ +import OAI.Combinatorics.TriangleFace.Model + +namespace OAI + +noncomputable section +open scoped BigOperators +open MatchingEntropyBounds MatchingEntropyBounds.Refined +namespace TriangleFace198 +universe uV uE +variable {V : Type uV} {E : Type uE} [instFintypeV : Fintype V] [Fintype E] [DecidableEq V] [instDecidableEqE : DecidableEq E] + +theorem labels_of_degree_three {V : Type uV} {E : Type uE} + [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] (G : LooplessGraph V E) (v : V) + (hdeg : Fintype.card {e : E // G.Incident v e} = 3) : + ∃ c : E → Fin 3, LocalLabels G v c := by + classical + let q : {e : E // G.Incident v e} ≃ Fin 3 := Fintype.equivFinOfCardEq hdeg + let c : E → Fin 3 := fun e => if h : G.Incident v e then q ⟨e,h⟩ else 0 + refine ⟨c, ?_⟩ + intro i + refine ⟨(q.symm i).val, ⟨(q.symm i).property, ?_⟩, ?_⟩ + · simp [c, (q.symm i).property] + · intro e he + have hq : q ⟨e,he.1⟩ = i := by simpa [c,he.1] using he.2 + exact congrArg Subtype.val (q.injective (hq.trans (q.apply_symm_apply i).symm)) + +omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in +theorem localEdge_spec (G : LooplessGraph V E) (c : E → Fin 3) (v : V) + (hc : LocalLabels G v c) (i : Fin 3) : + G.Incident v (localEdge G c v hc i) ∧ c (localEdge G c v hc i) = i := + (Classical.choose_spec (hc i)).1 + +omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in +theorem eq_localEdge (G : LooplessGraph V E) (c : E → Fin 3) (v : V) + (hc : LocalLabels G v c) {e : E} {i : Fin 3} + (he : G.Incident v e) (hi : c e = i) : e = localEdge G c v hc i := + (Classical.choose_spec (hc i)).2 e ⟨he,hi⟩ + +end TriangleFace198 +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleFace/Main.lean b/lean/OAI/Combinatorics/TriangleFace/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d1f9266dbd241a6c37d7b7622242abc1173e63d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleFace/Main.lean @@ -0,0 +1,73 @@ +import OAI.Combinatorics.TriangleFace.Faces +import OAI.Combinatorics.TriangleFace.MatchingImage + +namespace OAI + +noncomputable section +open scoped BigOperators +open MatchingEntropyBounds MatchingEntropyBounds.Refined +namespace TriangleFace198 +universe uV uE +variable {V : Type uV} {E : Type uE} [instFintypeV : Fintype V] [Fintype E] [DecidableEq V] [instDecidableEqE : DecidableEq E] + +theorem local_face {V : Type uV} {E : Type uE} + [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] (G : LooplessGraph V E) (c : E → Fin 3) (v : V) + (hc : LocalLabels G v c) : + let H := triangleExpansion G c v + let f := localExtension G c v hc + let Q := {y | y ∈ H.polytope ∧ H.cutMass y (triangleVertices v) = 1} + f '' G.polytope = Q ∧ + Convex ℝ Q ∧ IsExtreme ℝ H.polytope Q ∧ + (∀ x, oldRestriction (f x) = x) ∧ + (∀ y ∈ Q, f (oldRestriction y) = y) ∧ + (∀ x e, f x (Sum.inl e) = x e) ∧ + (∀ x i, f x (Sum.inr i) = x (localEdge G c v hc i)) ∧ + (∀ x, (∀ e, x e = (1/3 : ℝ)) → ∀ e, f x e = (1/3 : ℝ)) ∧ + (∀ x ∈ G.polytope, CanonicalFace198.minFace H.polytope (f x) = f '' CanonicalFace198.minFace G.polytope x) := by + dsimp only + have him := expansion_image_eq G c v hc + have hex := expansion_image_extreme G c v hc + refine ⟨him, ?_, ?_, restriction_extension G c v hc, ?_, ?_, ?_, ?_, ?_⟩ + · rw [← him] + exact (convex_convexHull ℝ (Set.range G.indicator)).linear_image (localExtension G c v hc) + · rwa [← him] + · intro y hy + obtain ⟨x, hx, rfl⟩ := him.symm ▸ hy + rfl + · intro x e + rfl + · intro x i + rfl + · intro x hx e + rcases e with e | i + · exact hx e + · exact hx (localEdge G c v hc i) + · intro x hx + exact (CanonicalFace198.image_minFace + (localExtension G c v hc).toAffineMap (localExtension_injective G c v hc) + (convex_convexHull ℝ (Set.range G.indicator)) + (convex_convexHull ℝ (Set.range (triangleExpansion G c v).indicator)) hex hx).symm + +theorem triangle_expansion_face {V : Type uV} {E : Type uE} + [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] (G : LooplessGraph V E) (v : V) + (hdeg : Fintype.card {e : E // G.Incident v e} = 3) + (_hmatching : Nonempty G.Matching) : + ∃ (c : E → Fin 3) (hc : LocalLabels G v c), + let H := triangleExpansion G c v + let f := localExtension G c v hc + let Q := {y | y ∈ H.polytope ∧ H.cutMass y (triangleVertices v) = 1} + f '' G.polytope = Q ∧ + Convex ℝ Q ∧ IsExtreme ℝ H.polytope Q ∧ + (∀ x, oldRestriction (f x) = x) ∧ + (∀ y ∈ Q, f (oldRestriction y) = y) ∧ + (∀ x e, f x (Sum.inl e) = x e) ∧ + (∀ x i, f x (Sum.inr i) = x (localEdge G c v hc i)) ∧ + (∀ x, (∀ e, x e = (1/3 : ℝ)) → ∀ e, f x e = (1/3 : ℝ)) ∧ + (∀ x ∈ G.polytope, CanonicalFace198.minFace H.polytope (f x) = f '' CanonicalFace198.minFace G.polytope x) := by + obtain ⟨c,hc⟩ := labels_of_degree_three G v hdeg + exact ⟨c,hc,local_face G c v hc⟩ + +end TriangleFace198 +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleFace/MatchingImage.lean b/lean/OAI/Combinatorics/TriangleFace/MatchingImage.lean new file mode 100644 index 0000000000000000000000000000000000000000..2a56c27c65320e45fea619a25d6fb1aa4893ec2f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleFace/MatchingImage.lean @@ -0,0 +1,89 @@ +import OAI.Combinatorics.TriangleFace.Labels +import OAI.Combinatorics.TriangleFace.AffineMaps + +namespace OAI + +noncomputable section +open scoped BigOperators +open MatchingEntropyBounds MatchingEntropyBounds.Refined +namespace TriangleFace198 +universe uV uE +variable {V : Type uV} {E : Type uE} [instFintypeV : Fintype V] [Fintype E] [DecidableEq V] [instDecidableEqE : DecidableEq E] + +omit [Fintype V] [Fintype E] in +theorem expandMatching_indicator (G : LooplessGraph V E) (c : E → Fin 3) + (v : V) (hc : LocalLabels G v c) (M : G.Matching) : + (triangleExpansion G c v).indicator (expandMatching G c v M) = localExtension G c v hc (G.indicator M) := by + ext e + rcases e with e | i + · simp [LooplessGraph.indicator,expandMatching,expandEdges,localExtension] + · have hh : c (incidentChoice G M v) = i ↔ localEdge G c v hc i ∈ M.val := by + constructor + · intro h + rw [← eq_localEdge G c v hc (incidentChoice_spec G M v).2 h] + exact (incidentChoice_spec G M v).1 + · intro h + rw [← eq_incidentChoice G M v h (localEdge_spec G c v hc i).1] + exact (localEdge_spec G c v hc i).2 + simp only [LooplessGraph.indicator,expandMatching,expandEdges,Finset.inr_mem_disjSum, + Finset.mem_singleton,localExtension,LinearMap.coe_mk,AddHom.coe_mk,Sum.elim_inr] + simp only [eq_comm (a := i) (b := c (incidentChoice G M v)),hh] + +theorem expanded_push_mean {V : Type uV} {E : Type uE} + [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] (G : LooplessGraph V E) (c : E → Fin 3) + (v : V) (hc : LocalLabels G v c) (q : G.Matching → ℝ) : + (triangleExpansion G c v).mean (fiberMass q (expandMatching G c v)) = + localExtension G c v hc (G.mean q) := by + ext e + rw [LooplessGraph.mean,fiberMass_expect] + simp_rw [expandMatching_indicator G c v hc] + rcases e with e | i <;> rfl + +theorem expanded_push_feasible (G : LooplessGraph V E) (c : E → Fin 3) + (v : V) (hc : LocalLabels G v c) {x : E → ℝ} {q : G.Matching → ℝ} + (hq : q ∈ G.feasibleLaws x) : + fiberMass q (expandMatching G c v) ∈ (triangleExpansion G c v).feasibleLaws (localExtension G c v hc x) := by + exact ⟨fiberMass_mem_simplex hq.1 _,by rw [expanded_push_mean G c v hc,hq.2]⟩ + +theorem expansion_image_eq (G : LooplessGraph V E) (c : E → Fin 3) + (v : V) (hc : LocalLabels G v c) : + localExtension G c v hc '' G.polytope = + {y | y ∈ (triangleExpansion G c v).polytope ∧ + (triangleExpansion G c v).cutMass y (triangleVertices v) = 1} := by + ext y + constructor + · rintro ⟨x,hx,rfl⟩ + obtain ⟨q,hq⟩ := (G.mem_polytope_iff x).mp hx + refine ⟨((triangleExpansion G c v).mem_polytope_iff _).mpr + ⟨_,expanded_push_feasible G c v hc hq⟩,?_⟩ + rw [expanded_cutMass] + exact (G.polytope_subset_constraintPolytope hx).2.1 v + · rintro ⟨hy,ht⟩ + obtain ⟨p,hp⟩ := ((triangleExpansion G c v).mem_polytope_iff y).mp hy + have ht' : (triangleExpansion G c v).cutMass ((triangleExpansion G c v).mean p) (triangleVertices v) = 1 := hp.2.symm ▸ ht + obtain ⟨heq,hq⟩ := expanded_pull_simplex G c v hp.1 ht' + refine ⟨_,G.mean_mem_polytope hq,?_⟩ + rw [← expanded_push_mean,← heq,hp.2] + +theorem expansion_image_extreme (G : LooplessGraph V E) (c : E → Fin 3) + (v : V) (hc : LocalLabels G v c) : + IsExtreme ℝ (triangleExpansion G c v).polytope (localExtension G c v hc '' G.polytope) := by + rw [expansion_image_eq] + refine ⟨fun _ h => h.1, ?_⟩ + intro y hy z hz w hw hseg + obtain ⟨a,b,ha,hb,hab,rfl⟩ := hseg + refine ⟨hy,?_⟩ + have heq := hw.2 + rw [LooplessGraph.cutMass_linear] at heq + have hyl := ((triangleExpansion G c v).polytope_subset_constraintPolytope hy).2.2 _ (triangleVertices_odd v) + have hzl := ((triangleExpansion G c v).polytope_subset_constraintPolytope hz).2.2 _ (triangleVertices_odd v) + apply le_antisymm _ hyl + by_contra! hn + have hpos := mul_pos ha (sub_pos.mpr hn) + have hnonneg := mul_nonneg hb.le (sub_nonneg.mpr hzl) + nlinarith + +end TriangleFace198 +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleFace/Model.lean b/lean/OAI/Combinatorics/TriangleFace/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..994fab25821ca09626c0403c087244b12ee7213b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleFace/Model.lean @@ -0,0 +1,44 @@ +import OAI.Combinatorics.MatchingEntropy.TriangleExpansion + +namespace OAI + +namespace CanonicalFace198 + +variable {A B : Type*} [AddCommGroup A] [Module ℝ A] + [AddCommGroup B] [Module ℝ B] + +def facesThrough (P : Set A) (x : A) : Set (Set A) := + {F | Convex ℝ F ∧ IsExtreme ℝ P F ∧ x ∈ F} + +def minFace (P : Set A) (x : A) : Set A := ⋂₀ facesThrough P x + +end CanonicalFace198 + +noncomputable section +open scoped BigOperators +open MatchingEntropyBounds MatchingEntropyBounds.Refined +namespace TriangleFace198 +variable {V E : Type*} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] + +def LocalLabels (G : LooplessGraph V E) (v : V) (c : E → Fin 3) : Prop := + ∀ i, ∃! e, G.Incident v e ∧ c e = i + +def localEdge (G : LooplessGraph V E) (c : E → Fin 3) (v : V) + (hc : LocalLabels G v c) (i : Fin 3) : E := Classical.choose (hc i) + +def localExtension (G : LooplessGraph V E) (c : E → Fin 3) (v : V) + (hc : LocalLabels G v c) : (E → ℝ) →ₗ[ℝ] (E ⊕ Fin 3 → ℝ) where + toFun x := Sum.elim x (fun i => x (localEdge G c v hc i)) + map_add' x y := by ext e; cases e <;> rfl + map_smul' a x := by ext e; cases e <;> rfl + +def oldRestriction : (E ⊕ Fin 3 → ℝ) →ₗ[ℝ] (E → ℝ) where + toFun y e := y (Sum.inl e) + map_add' _ _ := rfl + map_smul' _ _ := rfl + +end TriangleFace198 + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/ActiveL2Map.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/ActiveL2Map.lean new file mode 100644 index 0000000000000000000000000000000000000000..5bbf6d4c9fc870ce8d755397dc9613642d5ae08a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/ActiveL2Map.lean @@ -0,0 +1,342 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.MovingStarDegree + +namespace OAI + +section +noncomputable section +open scoped BigOperators + +namespace SharpTerminalLeave +open Classical + +noncomputable def activeL2Map {E : Type*} [Fintype E] (s : Finset E) : + (E → ℝ) →ₗ[ℝ] EuclideanSpace ℝ E where + toFun x := WithLp.toLp 2 (fun e => if e ∈ s then x e else 0) + map_add' x y := by ext e; by_cases he : e ∈ s <;> simp [he] + map_smul' c x := by ext e; by_cases he : e ∈ s <;> simp [he] + +noncomputable def activeL2 {E : Type*} [Fintype E] (s : Finset E) : Seminorm ℝ (E → ℝ) := + (normSeminorm ℝ (EuclideanSpace ℝ E)).comp (activeL2Map s) + +lemma activeL2_sq {E : Type*} [Fintype E] (s : Finset E) (x : E → ℝ) : + (activeL2 s x)^2 = ∑ e ∈ s, (x e)^2 := by + change ‖activeL2Map s x‖^2 = _ + rw [EuclideanSpace.real_norm_sq_eq] + simp [activeL2Map] + +lemma activeL2_congr {E : Type*} [Fintype E] (s : Finset E) {x y : E → ℝ} + (h : ∀ e ∈ s, x e = y e) : activeL2 s x = activeL2 s y := by + have hm : activeL2Map s x = activeL2Map s y := by + ext e + by_cases he : e ∈ s + · simp [activeL2Map,he,h e he] + · simp [activeL2Map,he] + change ‖activeL2Map s x‖ = ‖activeL2Map s y‖ + rw [hm] + +lemma activeL2_mono {E : Type*} [Fintype E] {s t : Finset E} (h : s ⊆ t) (x : E → ℝ) : + activeL2 s x ≤ activeL2 t x := by + have hs : (activeL2 s x)^2 ≤ (activeL2 t x)^2 := by + rw [activeL2_sq,activeL2_sq] + exact Finset.sum_le_sum_of_subset_of_nonneg h (fun _ _ _ => sq_nonneg _) + nlinarith [apply_nonneg (activeL2 s) x,apply_nonneg (activeL2 t) x] + +lemma activeL2_coordinate {E : Type*} [Fintype E] (s : Finset E) (x : E → ℝ) + {e : E} (he : e ∈ s) : |x e| ≤ activeL2 s x := by + have hs : (x e)^2 ≤ (activeL2 s x)^2 := by + rw [activeL2_sq] + exact Finset.single_le_sum (fun _ _ => sq_nonneg _) he + nlinarith [sq_abs (x e), abs_nonneg (x e),apply_nonneg (activeL2 s) x] + +lemma activeL2_of_bound {E : Type*} [Fintype E] (s : Finset E) (x : E → ℝ) + {R : ℝ} (hR : 0 ≤ R) (hx : ∀ e ∈ s, |x e| ≤ R) : + activeL2 s x ≤ (Fintype.card E : ℝ)*R := by + have hs : (activeL2 s x)^2 ≤ (s.card : ℝ)*R^2 := by + rw [activeL2_sq] + calc + _ ≤ ∑ _e ∈ s, R^2 := Finset.sum_le_sum (fun e he => by + have := hx e he + nlinarith [sq_abs (x e),abs_nonneg (x e)]) + _ = _ := by simp + have hn : (s.card : ℝ) ≤ Fintype.card E := by exact_mod_cast Finset.card_le_univ s + have hn2 : (Fintype.card E : ℝ) ≤ (Fintype.card E : ℝ)^2 := by + have := Nat.le_mul_self (Fintype.card E) + exact_mod_cast (by simpa only [pow_two] using this) + have hp := mul_le_mul_of_nonneg_right (hn.trans hn2) (sq_nonneg R) + have h0 : 0 ≤ (Fintype.card E : ℝ)*R := mul_nonneg (Nat.cast_nonneg _) hR + nlinarith [apply_nonneg (activeL2 s) x] + +lemma movingStar_euler_activeL2 {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2) + (s : Finset E) (x : E → ℝ) {a : ℝ} (ha : 0 ≤ a) (ha1 : a ≤ 1) : + activeL2 s (fun e => x e-a*movingStarLift ends (movingStarMean ends s x) e) ≤ activeL2 s x := by + have hs := movingStar_euler_energy_le ends hends s x ha ha1 + rw [← activeL2_sq,← activeL2_sq] at hs + nlinarith [apply_nonneg (activeL2 s) x, + apply_nonneg (activeL2 s) (fun e => x e-a*movingStarLift ends (movingStarMean ends s x) e)] + +lemma movingStar_activeL2_bound {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2) + (s : Finset E) (x : E → ℝ) : + activeL2 s (movingStarLift ends (movingStarMean ends s x)) ≤ 2*activeL2 s x := by + let P := movingStarLift ends (movingStarMean ends s x) + have hi : P = x-(x-P) := by funext e; simp + have he := movingStar_euler_activeL2 ends hends s x (a := 1) (by norm_num) le_rfl + simp only [one_mul] at he + calc + activeL2 s P = activeL2 s (x-(x-P)) := congrArg _ hi + _ ≤ activeL2 s x+activeL2 s (x-P) := map_sub_le_add _ _ _ + _ ≤ activeL2 s x+activeL2 s x := add_le_add le_rfl he + _ = _ := by ring + +lemma movingStarMean_add {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (s : Finset E) (x y : E → ℝ) (u : V) : + movingStarMean ends s (x+y) u = movingStarMean ends s x u+movingStarMean ends s y u := by + simp [movingStarMean,Pi.add_apply,Finset.sum_add_distrib,add_div] + +lemma movingStarLift_add {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (b c : V → ℝ) : + movingStarLift ends (b+c) = movingStarLift ends b+movingStarLift ends c := by + funext e + simp [movingStarLift,Pi.add_apply,Finset.sum_add_distrib] + +theorem movingStar_trajectory_l2_bound {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2) + (active : ℕ → Finset E) (a : ℕ → ℝ) (M x : ℕ → E → ℝ) (T : ℕ) + (hnest : ∀ k < T, active (k+1) ⊆ active k) + (hinit : ∀ e ∈ active 0, x 0 e = M 0 e) + (hstep : ∀ k < T, ∀ e ∈ active (k+1), x (k+1) e = x k e - + a k*movingStarLift ends (movingStarMean ends (active k) (x k)) e + (M (k+1) e-M k e)) + {R : ℝ} (_hR : 0 ≤ R) (ha : ∀ k < T, 0 ≤ a k ∧ a k ≤ 1) + (hM : ∀ k ≤ T, activeL2 (active k) (M k) ≤ R) : + activeL2 (active T) (x T) ≤ R*(1+2*∑ k ∈ Finset.range T, a k) := by + let z : ℕ → E → ℝ := fun k => x k-M k + have hz : ∀ t ≤ T, activeL2 (active t) (z t) ≤ 2*R*∑ k ∈ Finset.range t, a k := by + intro t ht + induction t with + | zero => + have he : activeL2 (active 0) (z 0) = 0 := by + trans activeL2 (active 0) 0 + · apply activeL2_congr + intro e he + simp [z,hinit e he] + · exact map_zero _ + simpa only [he, Finset.range_zero, Finset.sum_empty, mul_zero] using (le_refl (0 : ℝ)) + | succ t ih => + have htT : t < T := by omega + have hi := ih (by omega) + have hzstep : ∀ e ∈ active (t+1), z (t+1) e = + (z t e-a t*movingStarLift ends (movingStarMean ends (active t) (z t)) e)- + a t*movingStarLift ends (movingStarMean ends (active t) (M t)) e := by + intro e he + have hx : x t = z t+M t := by funext e; simp [z] + have hp := hstep t htT e he + rw [hx] at hp + have hm : movingStarMean ends (active t) (z t+M t) = + movingStarMean ends (active t) (z t)+movingStarMean ends (active t) (M t) := by + funext u + exact movingStarMean_add ends (active t) (z t) (M t) u + rw [hm,movingStarLift_add] at hp + change x (t+1) e-M (t+1) e = _ + simp only [Pi.add_apply] at hp + linarith only [hp] + calc + activeL2 (active (t+1)) (z (t+1)) = activeL2 (active (t+1)) + ((fun e => z t e-a t*movingStarLift ends (movingStarMean ends (active t) (z t)) e)- + a t • movingStarLift ends (movingStarMean ends (active t) (M t))) := + activeL2_congr _ hzstep + _ ≤ activeL2 (active t) + ((fun e => z t e-a t*movingStarLift ends (movingStarMean ends (active t) (z t)) e)- + a t • movingStarLift ends (movingStarMean ends (active t) (M t))) := + activeL2_mono (hnest t htT) _ + _ ≤ activeL2 (active t) + (fun e => z t e-a t*movingStarLift ends (movingStarMean ends (active t) (z t)) e)+ + activeL2 (active t) (a t • movingStarLift ends (movingStarMean ends (active t) (M t))) := + map_sub_le_add _ _ _ + _ ≤ activeL2 (active t) (z t)+a t*(2*activeL2 (active t) (M t)) := by + rw [map_smul_eq_mul,Real.norm_eq_abs,abs_of_nonneg (ha t htT).1] + exact add_le_add (movingStar_euler_activeL2 ends hends _ _ (ha t htT).1 (ha t htT).2) + (mul_le_mul_of_nonneg_left (movingStar_activeL2_bound ends hends _ _) (ha t htT).1) + _ ≤ 2*R*∑ k ∈ Finset.range t, a k+a t*(2*R) := by + exact add_le_add hi (mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (hM t (by omega)) (by norm_num)) (ha t htT).1) + _ = _ := by rw [Finset.sum_range_succ]; ring + have hx : x T = M T+z T := by funext e; simp [z] + calc + activeL2 (active T) (x T) = activeL2 (active T) (M T+z T) := congrArg _ hx + _ ≤ activeL2 (active T) (M T)+activeL2 (active T) (z T) := map_add_le_add _ _ _ + _ ≤ R+2*R*∑ k ∈ Finset.range T, a k := add_le_add (hM T le_rfl) (hz T le_rfl) + _ = _ := by ring + +noncomputable def activeLinf {E : Type*} [Fintype E] (s : Finset E) : Seminorm ℝ (E → ℝ) := + s.sup (fun e => (normSeminorm ℝ ℝ).comp (LinearMap.proj e)) + +lemma activeLinf_coordinate {E : Type*} [Fintype E] (s : Finset E) (x : E → ℝ) + {e : E} (he : e ∈ s) : |x e| ≤ activeLinf s x := by + exact Seminorm.le_finset_sup_apply (p := fun e => + (normSeminorm ℝ ℝ).comp (LinearMap.proj e)) (x := x) he + +lemma activeLinf_bound {E : Type*} [Fintype E] (s : Finset E) (x : E → ℝ) + {R : ℝ} (hR : 0 ≤ R) (hx : ∀ e ∈ s, |x e| ≤ R) : activeLinf s x ≤ R := by + exact Seminorm.finset_sup_apply_le hR hx + +lemma activeLinf_le_l2 {E : Type*} [Fintype E] (s : Finset E) (x : E → ℝ) : + activeLinf s x ≤ activeL2 s x := + activeLinf_bound s x (apply_nonneg _ _) (fun _ he => activeL2_coordinate s x he) + +lemma activeL2_le_card_linf {E : Type*} [Fintype E] (s : Finset E) (x : E → ℝ) : + activeL2 s x ≤ (Fintype.card E : ℝ)*activeLinf s x := + activeL2_of_bound s x (apply_nonneg _ _) (fun _ he => activeLinf_coordinate s x he) + +noncomputable def trajectorySeminorm {E : Type*} [Fintype E] + (P : ℕ → Seminorm ℝ (E → ℝ)) (T : ℕ) : Seminorm ℝ (ℕ → E → ℝ) := + (Finset.range (T+1)).sup (fun t => (P t).comp (LinearMap.proj t)) + +lemma trajectorySeminorm_at {E : Type*} [Fintype E] + (P : ℕ → Seminorm ℝ (E → ℝ)) (T : ℕ) (x : ℕ → E → ℝ) {t : ℕ} (ht : t ≤ T) : + P t (x t) ≤ trajectorySeminorm P T x := + Seminorm.le_finset_sup_apply (p := fun t => (P t).comp (LinearMap.proj t)) + (x := x) (Finset.mem_range.mpr (by omega)) + +lemma trajectorySeminorm_bound {E : Type*} [Fintype E] + (P : ℕ → Seminorm ℝ (E → ℝ)) (T : ℕ) (x : ℕ → E → ℝ) {R : ℝ} + (hR : 0 ≤ R) (hx : ∀ t ≤ T, P t (x t) ≤ R) : trajectorySeminorm P T x ≤ R := by + apply Seminorm.finset_sup_apply_le hR + intro t ht + exact hx t (by have := Finset.mem_range.mp ht; omega) + +lemma trajectory_mixed_seminorms {E : Type*} [Fintype E] + (active : ℕ → Finset E) (T : ℕ) (x : ℕ → E → ℝ) : + trajectorySeminorm (fun t => activeLinf (active t)) T x ≤ + trajectorySeminorm (fun t => activeL2 (active t)) T x ∧ + trajectorySeminorm (fun t => activeL2 (active t)) T x ≤ + (Fintype.card E : ℝ)*trajectorySeminorm (fun t => activeLinf (active t)) T x := by + constructor + · apply trajectorySeminorm_bound _ _ _ (apply_nonneg _ _) + intro t ht + exact (activeLinf_le_l2 _ _).trans (trajectorySeminorm_at (fun t => activeL2 (active t)) T x ht) + · apply trajectorySeminorm_bound _ _ _ (by positivity) + intro t ht + exact (activeL2_le_card_linf _ _).trans + (mul_le_mul_of_nonneg_left (trajectorySeminorm_at (fun t => activeLinf (active t)) T x ht) (Nat.cast_nonneg _)) + +noncomputable def movingStarSolve {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (active : ℕ → Finset E) (a : ℕ → ℝ) + (M : ℕ → E → ℝ) : ℕ → E → ℝ + | 0 => M 0 + | t+1 => fun e => movingStarSolve ends active a M t e- + a t*movingStarLift ends (movingStarMean ends (active t) (movingStarSolve ends active a M t)) e+ + (M (t+1) e-M t e) + +lemma movingStarMean_smul {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (s : Finset E) (c : ℝ) (x : E → ℝ) : + movingStarMean ends s (c • x) = c • movingStarMean ends s x := by + funext u + simp only [movingStarMean,Pi.smul_apply,smul_eq_mul,← Finset.mul_sum] + ring + +lemma movingStarLift_smul {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (c : ℝ) (b : V → ℝ) : + movingStarLift ends (c • b) = c • movingStarLift ends b := by + funext e + simp [movingStarLift,Pi.smul_apply,smul_eq_mul,Finset.mul_sum] + +lemma movingStarSolve_add {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (active : ℕ → Finset E) (a : ℕ → ℝ) + (M N : ℕ → E → ℝ) : + movingStarSolve ends active a (M+N) = movingStarSolve ends active a M+movingStarSolve ends active a N := by + funext t + induction t with + | zero => rfl + | succ t ih => + have hm : movingStarMean ends (active t) + (movingStarSolve ends active a M t+movingStarSolve ends active a N t) = + movingStarMean ends (active t) (movingStarSolve ends active a M t)+ + movingStarMean ends (active t) (movingStarSolve ends active a N t) := by + funext u + exact movingStarMean_add _ _ _ _ _ + simp only [movingStarSolve,ih,Pi.add_apply] at hm ⊢ + rw [hm,movingStarLift_add] + funext e + simp only [Pi.add_apply] + ring + +lemma movingStarSolve_smul {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (active : ℕ → Finset E) (a : ℕ → ℝ) + (c : ℝ) (M : ℕ → E → ℝ) : + movingStarSolve ends active a (c • M) = c • movingStarSolve ends active a M := by + funext t + induction t with + | zero => rfl + | succ t ih => + change (fun e => movingStarSolve ends active a (c • M) t e- + a t*movingStarLift ends (movingStarMean ends (active t) (movingStarSolve ends active a (c • M) t)) e+ + ((c • M) (t+1) e-(c • M) t e)) = c • movingStarSolve ends active a M (t+1) + rw [show movingStarSolve ends active a (c • M) t = c • movingStarSolve ends active a M t from ih, + movingStarMean_smul,movingStarLift_smul] + simp only [movingStarSolve] + funext e + simp only [Pi.smul_apply,smul_eq_mul] + ring + +noncomputable def movingStarResponse {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (active : ℕ → Finset E) (a : ℕ → ℝ) : + Module.End ℝ (ℕ → E → ℝ) where + toFun := movingStarSolve ends active a + map_add' := movingStarSolve_add ends active a + map_smul' := movingStarSolve_smul ends active a + +lemma movingStarResponse_linf {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2) + (active : ℕ → Finset E) (a : ℕ → ℝ) (T : ℕ) + (hnest : ∀ k < T, active (k+1) ⊆ active k) + (ha : ∀ k < T, 0 ≤ a k ∧ a k ≤ 1) (M : ℕ → E → ℝ) : + trajectorySeminorm (fun t => activeLinf (active t)) T (movingStarResponse ends active a M) ≤ + (1+2*∑ k ∈ Finset.range T, a k)*trajectorySeminorm (fun t => activeLinf (active t)) T M := by + let R := trajectorySeminorm (fun t => activeLinf (active t)) T M + have hR : 0 ≤ R := apply_nonneg _ _ + have hsum : ∀ t ≤ T, (∑ k ∈ Finset.range t, a k) ≤ ∑ k ∈ Finset.range T, a k := by + intro t ht + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono ht) + (fun k hk _ => (ha k (Finset.mem_range.mp hk)).1) + have hS : 0 ≤ ∑ k ∈ Finset.range T, a k := + Finset.sum_nonneg (fun k hk => (ha k (Finset.mem_range.mp hk)).1) + apply trajectorySeminorm_bound _ _ _ (by positivity) + intro t ht + apply activeLinf_bound _ _ (by positivity) + intro e he + have hb := movingStar_trajectory_bound ends hends active a M + (movingStarSolve ends active a M) t (fun k hk => hnest k (by omega)) + (fun _ _ => rfl) (fun _ _ _ _ => rfl) hR (fun k hk => ha k (by omega)) + (fun k hk f hf => (activeLinf_coordinate _ _ hf).trans (trajectorySeminorm_at (fun t => activeLinf (active t)) T M (by omega))) e he + exact hb.trans (by nlinarith [mul_le_mul_of_nonneg_left (hsum t ht) hR]) + +lemma movingStarResponse_l2 {E V : Type*} [Fintype E] [Fintype V] + (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2) + (active : ℕ → Finset E) (a : ℕ → ℝ) (T : ℕ) + (hnest : ∀ k < T, active (k+1) ⊆ active k) + (ha : ∀ k < T, 0 ≤ a k ∧ a k ≤ 1) (M : ℕ → E → ℝ) : + trajectorySeminorm (fun t => activeL2 (active t)) T (movingStarResponse ends active a M) ≤ + (1+2*∑ k ∈ Finset.range T, a k)*trajectorySeminorm (fun t => activeL2 (active t)) T M := by + let R := trajectorySeminorm (fun t => activeL2 (active t)) T M + have hR : 0 ≤ R := apply_nonneg _ _ + have hsum : ∀ t ≤ T, (∑ k ∈ Finset.range t, a k) ≤ ∑ k ∈ Finset.range T, a k := by + intro t ht + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono ht) + (fun k hk _ => (ha k (Finset.mem_range.mp hk)).1) + have hS : 0 ≤ ∑ k ∈ Finset.range T, a k := + Finset.sum_nonneg (fun k hk => (ha k (Finset.mem_range.mp hk)).1) + apply trajectorySeminorm_bound _ _ _ (by positivity) + intro t ht + have hb := movingStar_trajectory_l2_bound ends hends active a M + (movingStarSolve ends active a M) t (fun k hk => hnest k (by omega)) + (fun _ _ => rfl) (fun _ _ _ _ => rfl) hR (fun k hk => ha k (by omega)) + (fun k hk => trajectorySeminorm_at (fun t => activeL2 (active t)) T M (by omega)) + exact hb.trans (by nlinarith [mul_le_mul_of_nonneg_left (hsum t ht) hR]) + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityEdgeSafe.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityEdgeSafe.lean new file mode 100644 index 0000000000000000000000000000000000000000..e70f1c539148d376b77bc8bdcbf290b346b5645d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityEdgeSafe.lean @@ -0,0 +1,146 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TriangleDegreeMean +import OAI.Combinatorics.TriangleRemoval.Process.HistoryAlive +import OAI.Combinatorics.TriangleRemoval.Asymptotics.LogStepSandwich + +namespace OAI + +section +noncomputable section +open scoped BigOperators + +namespace SharpTerminalLeave +open Classical + +def densityEdgeSafe (n : ℕ) (p η : ℝ) (G : Graph n) : Prop := + G ⊆ completeGraph n ∧ (G.card : ℝ) = (n : ℝ)^2*p/2 ∧ + ∀ e ∈ G, |(triangleDegree G e : ℝ)-n*p^2| ≤ η*(n*p^2) + +lemma triangle_count_from_edge_degrees {n : ℕ} (G : Graph n) (D δ : ℝ) + (hd : ∀ e ∈ G, |(triangleDegree G e : ℝ)-D| ≤ δ) : + |3*(triangles G).card-(G.card : ℝ)*D| ≤ (G.card : ℝ)*δ := by + have he : 3*(triangles G).card-(G.card : ℝ)*D = + ∑ e ∈ G, ((triangleDegree G e : ℝ)-D) := by + rw [Finset.sum_sub_distrib,triangle_degree_sum] + simp + rw [he] + calc + _ ≤ ∑ e ∈ G, |(triangleDegree G e : ℝ)-D| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _e ∈ G, δ := Finset.sum_le_sum (fun e he => hd e he) + _ = _ := by simp + +lemma densityEdgeSafe_triangle_bounds {n : ℕ} {p η : ℝ} {G : Graph n} + (h : densityEdgeSafe n p η G) : + (n : ℝ)^3*p^3/6*(1-η) ≤ (triangles G).card ∧ + (triangles G).card ≤ (n : ℝ)^3*p^3/6*(1+η) := by + have hc := triangle_count_from_edge_degrees G (n*p^2) (η*(n*p^2)) h.2.2 + rw [h.2.1] at hc + obtain ⟨hl,hu⟩ := abs_le.mp hc + constructor <;> nlinarith only [hl,hu] + +lemma densityEdgeSafe_triangle_positive {n : ℕ} {p η : ℝ} {G : Graph n} + (hn : 0 < n) (hp : 0 < p) (hη : η ≤ 1/2) (h : densityEdgeSafe n p η G) : + (triangles G).Nonempty := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hq := (densityEdgeSafe_triangle_bounds h).1 + have hfac : 0 < 1-η := by linarith + have hpos : (0 : ℝ) < (triangles G).card := + lt_of_lt_of_le (by positivity) hq + exact Finset.card_pos.mp (by exact_mod_cast hpos) + +theorem densityEdgeSafe_intact_step {n : ℕ} {p η : ℝ} {G : Graph n} + (hn : 0 < n) (hp : 0 < p) (_hη : 0 ≤ η) (hη1 : η ≤ 1/2) + (h : densityEdgeSafe n p η G) (F : Graph n) : + pmfMean (step G) (intact F) ≤ Real.exp + (-((F.card : ℝ)*(6/(n : ℝ)^2/p))+2*(F.card : ℝ)*η*(6/(n : ℝ)^2/p)+ + (F.card : ℝ)^2*(2*(6/(n : ℝ)^2)/(n*p^3))) * intact F G := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hQ := densityEdgeSafe_triangle_positive hn hp hη1 h + have hq : (0 : ℝ) < (triangles G).card := by exact_mod_cast hQ.card_pos + obtain ⟨hlo,hhi⟩ := densityEdgeSafe_triangle_bounds h + let Q₀ : ℝ := (n : ℝ)^3*p^3/6 + let lam : ℝ := 6/(n : ℝ)^2/p + let D : ℝ := n*p^2 + have hQ₀ : 0 < Q₀ := by dsimp [Q₀]; positivity + have hlam : 0 < lam := by dsimp [lam]; positivity + have hD : 0 < D := by dsimp [D]; positivity + have hlamQ : lam*Q₀ = D := by dsimp [lam,Q₀,D]; field_simp + have hQl : Q₀/2 ≤ (triangles G).card := by + have hm := mul_le_mul_of_nonneg_left hη1 hQ₀.le + dsimp only [Q₀] at hm ⊢ + nlinarith only [hlo,hm] + have hrec : 1/(triangles G).card ≤ 2*(6/(n : ℝ)^2)/(n*p^3) := by + have hr : 1/(triangles G).card ≤ 2/Q₀ := by + apply (div_le_div_iff₀ hq hQ₀).mpr + linarith only [hQl] + have he : 2/Q₀ = 2*(6/(n : ℝ)^2)/(n*p^3) := by dsimp [Q₀]; field_simp + rwa [he] at hr + have hlin : lam*(1-2*η) ≤ D*(1-η)/(triangles G).card := by + apply (le_div_iff₀ hq).mpr + have hh : lam*(triangles G).card ≤ D*(1+η) := by + have hmul := mul_le_mul_of_nonneg_left hhi hlam.le + change lam*(triangles G).card ≤ lam*(Q₀*(1+η)) at hmul + rwa [← mul_assoc,hlamQ] at hmul + have hm := mul_le_mul_of_nonneg_right hh (show 0 ≤ 1-2*η by linarith) + have he : (1+η)*(1-2*η) ≤ 1-η := by nlinarith [sq_nonneg η] + have he' := mul_le_mul_of_nonneg_left he hD.le + nlinarith only [hm,he'] + have hexp : -((F.card : ℝ)*D-((F.card : ℝ)*(η*D)+(F.card : ℝ)^2))/(triangles G).card ≤ + -((F.card : ℝ)*lam)+2*(F.card : ℝ)*η*lam+ + (F.card : ℝ)^2*(2*(6/(n : ℝ)^2)/(n*p^3)) := by + have ha := mul_le_mul_of_nonneg_left hlin (Nat.cast_nonneg F.card) + have hb := mul_le_mul_of_nonneg_left hrec (sq_nonneg (F.card : ℝ)) + simp only [div_eq_mul_inv] at ha hb ⊢ + nlinarith only [ha,hb] + have hb := triangle_intact_exponential_bound G F D (η*D) hQ h.2.2 + exact hb.trans (mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr hexp) (intact_nonnegative F G)) + +theorem density_killed_survival {n : ℕ} (initial : PMF (Graph n)) + (p : ℕ → ℝ) (η : ℝ) (T j : ℕ) (hj : j ≤ T) (hn : 0 < n) + (hp : ∀ i ≤ T, 0 < p i) (hs : ∀ i < T, p i = p (i+1)+6/(n : ℝ)^2) + (hp0 : p 0 ≤ 1) (hη : 0 ≤ η) (hη1 : η ≤ 1/2) (F : Graph n) : + pmfMean (historyLaw initial (fun _ => step) T j) + (fun ω => if historyAlive (fun i => densityEdgeSafe n (p i) η) T j ω then + intact F (ω (historyIndex T j)) else 0) ≤ + p j^F.card * Real.exp + ((F.card : ℝ)*(1-p 0)/p 0+(F.card : ℝ)*(6/(n : ℝ)^2)/p j+ + 2*(F.card : ℝ)*η*(-Real.log (p j))+(F.card : ℝ)^2/(n*p j^2)) := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + let b : ℝ := F.card + let h : ℝ := 6/(n : ℝ)^2 + let rate : ℕ → ℝ := fun i => -b*(h/p i)+2*b*η*(h/p i)+b^2*(2*h/(n*p i^3)) + have hh : 0 ≤ h := by dsimp [h]; positivity + have hb : 0 ≤ b := Nat.cast_nonneg _ + have hk := triangle_killed_survival initial (fun i => densityEdgeSafe n (p i) η) F rate T j hj + (fun i hi G hG => by + simpa only [rate,b,h,neg_mul] using densityEdgeSafe_intact_step hn (hp i hi.le) hη hη1 hG F) + have hsumb := density_survival_exponent_bound p n h b η j hnR hh hb hη + (fun i hi => hp i (hi.trans hj)) (fun i hi => hs i (by omega)) hp0 + have hi : pmfMean initial (intact F) ≤ 1 := by + calc + _ ≤ pmfMean initial (fun _ => (1 : ℝ)) := by + apply pmfMean_mono + intro G _ + unfold intact + split_ifs <;> norm_num + _ = 1 := pmfMean_const _ _ + apply hk.trans + calc + _ ≤ Real.exp (∑ i ∈ Finset.range j, rate i) := by + nlinarith only [mul_le_mul_of_nonneg_left hi (Real.exp_pos (∑ i ∈ Finset.range j, rate i)).le] + _ ≤ Real.exp (b*Real.log (p j)+b*(1-p 0)/p 0+b*h/p j+ + 2*b*η*(-Real.log (p j))+b^2/(n*p j^2)) := Real.exp_le_exp.mpr hsumb + _ = _ := by + have he : Real.exp (b*Real.log (p j)) = p j^F.card := by + dsimp only [b] + rw [Real.exp_nat_mul,Real.exp_log (hp j hj)] + rw [show b*Real.log (p j)+b*(1-p 0)/p 0+b*h/p j+ + 2*b*η*(-Real.log (p j))+b^2/(n*p j^2) = + b*Real.log (p j)+(b*(1-p 0)/p 0+b*h/p j+ + 2*b*η*(-Real.log (p j))+b^2/(n*p j^2)) by ring,Real.exp_add,he] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityEdgeSafeTriangle.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityEdgeSafeTriangle.lean new file mode 100644 index 0000000000000000000000000000000000000000..68b8da5277bc9e295decca4f7a0dc0403f72b3b9 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityEdgeSafeTriangle.lean @@ -0,0 +1,225 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PowerEulerError +import OAI.Combinatorics.TriangleRemoval.Process.TriangleIndex + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +theorem densityEdgeSafe_triangle_euler_error {n : ℕ} {p η : ℝ} {G : Graph n} + (hn : 0 < n) (hp : 0 < p) (hη : 0 ≤ η) (hη1 : η ≤ 1/2) + (h : densityEdgeSafe n p η G) : + |pmfMean (step G) (fun H => ((triangles H).card : ℝ))-(triangles G).card+ + 3*(6/(n : ℝ)^2/p)*(triangles G).card| ≤ 6*η^2*((n : ℝ)*p^2)+2 := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have ht := densityEdgeSafe_triangle_positive hn hp hη1 h + have hq : (0 : ℝ) < (triangles G).card := by exact_mod_cast ht.card_pos + have hm : (0 : ℝ) < G.card := by exact_mod_cast (graph_nonempty_of_triangles ht).card_pos + have he : 9/(G.card : ℝ) = 3*(6/(n : ℝ)^2/p) := by + rw [h.2.1] + field_simp + ring + have hv := triangle_degree_variance_le (graph_nonempty_of_triangles ht) ((n : ℝ)*p^2) + (η*((n : ℝ)*p^2)) (by positivity) h.2.2 + have hlo := (densityEdgeSafe_triangle_bounds h).1 + have hhalf : (n : ℝ)^3*p^3/12 ≤ (triangles G).card := by + have hh := mul_le_mul_of_nonneg_left hη1 (show 0 ≤ (n : ℝ)^3*p^3/6 by positivity) + nlinarith only [hlo,hh] + have hVbound : triangleDegreeVariance G/(triangles G).card ≤ 6*η^2*((n : ℝ)*p^2) := by + apply (div_le_iff₀ hq).mpr + have hh := mul_le_mul_of_nonneg_left hhalf (show 0 ≤ 6*η^2*((n : ℝ)*p^2) by positivity) + rw [h.2.1] at hv + nlinarith only [hv,hh] + have hVnonneg : 0 ≤ triangleDegreeVariance G/(triangles G).card := + div_nonneg (triangleDegreeVariance_nonneg G) hq.le + rw [step_mean_triangle_count_centered ht] + have he' : 9*(triangles G).card/(G.card : ℝ) = 3*(6/(n : ℝ)^2/p)*(triangles G).card := by + rw [mul_div_right_comm,he] + rw [he'] + apply abs_le.mpr + constructor <;> linarith only [hVbound,hVnonneg] + +lemma relative_power_absolute_drift_bound {X Y s t r a B : ℝ} {b : ℕ} + (hX : 0 ≤ X) (hs : 0 < s) (ht : 0 < t) (hr : 0 ≤ r) (hr1 : r ≤ 1) + (hscale : t = s*(1-r)^b) (hratio : s ≤ 2*t) (hcap : X ≤ B*s) + (ha : 0 ≤ a) (h : |Y-X+(b : ℝ)*r*X| ≤ a*s) : + |Y/t-X/s| ≤ 2*(a+B*(b : ℝ)^2*r^2) := by + have hpow := power_euler_error b hr hr1 + have he : Y/t-X/s = ((Y-X+(b : ℝ)*r*X)-X*((1-r)^b-1+(b : ℝ)*r))/t := by + apply (eq_div_iff ht.ne').mpr + field_simp [hs.ne'] + rw [hscale] + ring + have hB : 0 ≤ B := (mul_nonneg_iff_of_pos_right hs).mp (hX.trans hcap) + have hnum : |(Y-X+(b : ℝ)*r*X)-X*((1-r)^b-1+(b : ℝ)*r)| ≤ + (a+B*(b : ℝ)^2*r^2)*s := by + calc + _ ≤ |Y-X+(b : ℝ)*r*X|+|X*((1-r)^b-1+(b : ℝ)*r)| := abs_sub _ _ + _ ≤ a*s+X*((b : ℝ)^2*r^2) := by + apply add_le_add h + rw [abs_mul,abs_of_nonneg hX] + exact mul_le_mul_of_nonneg_left hpow hX + _ ≤ a*s+(B*s)*((b : ℝ)^2*r^2) := add_le_add le_rfl + (mul_le_mul_of_nonneg_right hcap (by positivity)) + _ = _ := by ring + rw [he,abs_div,abs_of_pos ht] + apply (div_le_iff₀ ht).mpr + have hm := mul_le_mul_of_nonneg_left hratio (show 0 ≤ a+B*(b : ℝ)^2*r^2 by positivity) + exact hnum.trans (by nlinarith only [hm]) + +lemma early_triangle_drift_single {n : ℕ} {i : ℕ} {G : Graph n} {η : ℝ} + (hn : 0 < n) (hp : 1/(n : ℝ) ≤ prefixDensity n) (hi : i < prefixTime n) + (hη : 0 ≤ η) (hη1 : η ≤ 1/2) + (hreg : earlyTriangleScale n i ≤ 2*earlyTriangleScale n (i+1)) + (h : densityEdgeSafe n (earlyDensity n i) η G) : + |pmfMean (step G) (fun H => ((triangles H).card : ℝ))/earlyTriangleScale n (i+1)- + (triangles G).card/earlyTriangleScale n i| ≤ + 12*η^2*(6/(n : ℝ)^2/earlyDensity n i)+ + 4*(6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2)+ + 36*(6/(n : ℝ)^2/earlyDensity n i)^2 := by + let p := earlyDensity n i + let lam := 6/(n : ℝ)^2/p + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hp0 : 0 < p := early_density_positive hn hp hi.le + have hp1 := early_density_positive hn hp (show i+1 ≤ prefixTime n by omega) + have hstep := earlyDensity_succ n i + have hl : 0 ≤ lam := by dsimp [lam]; positivity + have hl1 : lam ≤ 1 := by + apply (div_le_iff₀ hp0).mpr + dsimp only [p] at hp0 ⊢ + linarith only [hstep,hp1] + have hs : 0 < earlyTriangleScale n i := by unfold earlyTriangleScale earlyTemplateScale; change 0 < (n : ℝ)^3*p^3/6; positivity + have ht : 0 < earlyTriangleScale n (i+1) := by unfold earlyTriangleScale earlyTemplateScale; positivity + have hscale : earlyTriangleScale n (i+1) = earlyTriangleScale n i*(1-lam)^3 := by + have he : earlyDensity n (i+1) = p*(1-lam) := by + have he : earlyDensity n (i+1) = p-6/(n : ℝ)^2 := by dsimp [p]; linarith only [hstep] + rw [he] + dsimp [lam] + field_simp + unfold earlyTriangleScale earlyTemplateScale + rw [he,mul_pow] + dsimp [p] + ring + have hcap : ((triangles G).card : ℝ) ≤ 2*earlyTriangleScale n i := by + have hu := (densityEdgeSafe_triangle_bounds h).2 + have hh := mul_le_mul_of_nonneg_left (show 1+η ≤ 2 by linarith) hs.le + exact hu.trans (by dsimp only [earlyTriangleScale,earlyTemplateScale] at hh ⊢; nlinarith only [hh]) + have hd := densityEdgeSafe_triangle_euler_error hn hp0 hη hη1 h + have he : (6*η^2*lam+2*lam/((n : ℝ)*p^2))*earlyTriangleScale n i = 6*η^2*((n : ℝ)*p^2)+2 := by + dsimp [lam,earlyTriangleScale,earlyTemplateScale] + change (6*η^2*(6/(n : ℝ)^2/p)+2*(6/(n : ℝ)^2/p)/((n : ℝ)*p^2))*((n : ℝ)^3*p^3/6) = _ + field_simp + rw [← he] at hd + have hh := relative_power_absolute_drift_bound (Nat.cast_nonneg (triangles G).card) hs ht hl hl1 + hscale hreg hcap (by positivity : 0 ≤ 6*η^2*lam+2*lam/((n : ℝ)*p^2)) hd + norm_num only [Nat.cast_ofNat] at hh + dsimp only [lam,p] at hh + convert hh using 1 + ring + +lemma early_grid_sum_bounds {n : ℕ} (hn : 0 < n) + (hp : 1/(n : ℝ) ≤ prefixDensity n) (j : ℕ) (hj : j ≤ prefixTime n) : + (∑ i ∈ Finset.range j, 6/(n : ℝ)^2/earlyDensity n i) ≤ Real.log n ∧ + (∑ i ∈ Finset.range j, (6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2)) ≤ 1/(2*prefixD n) ∧ + (∑ i ∈ Finset.range j, (6/(n : ℝ)^2/earlyDensity n i)^2) ≤ 6/(n : ℝ)*Real.log n := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + let p := earlyDensity n + let h : ℝ := 6/(n : ℝ)^2 + let lam : ℕ → ℝ := fun i => h/p i + have hpos : ∀ i ≤ prefixTime n, 0 < p i := fun i hi => early_density_positive hn hp hi + have hstep : ∀ i, p i = p (i+1)+h := fun i => earlyDensity_succ n i + have hlog : (∑ i ∈ Finset.range j, lam i) ≤ Real.log n := by + have hh := (density_log_sum_bounds p h j (fun i hi => hpos i (hi.trans hj)) + (fun i _ => hstep i)).1 + have hp0 := Real.log_nonpos (hpos 0 (Nat.zero_le _)).le (earlyDensity_le_one n 0) + have hln := early_density_log_bound hn hp hj + dsimp only [lam] at hh ⊢ + linarith only [hh,hp0,hln] + have hlD : (∑ i ∈ Finset.range j, lam i/((n : ℝ)*p i^2)) ≤ 1/(2*prefixD n) := by + have hh := inverse_square_grid_sum p (n : ℝ) h j hnR (by dsimp [h]; positivity) + (fun i hi => hpos i (hi.trans hj)) (fun i _ => hstep i) + have he : (∑ i ∈ Finset.range j, 2*h/((n : ℝ)*p i^3)) = + 2*(∑ i ∈ Finset.range j, lam i/((n : ℝ)*p i^2)) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + have := hpos i ((Finset.mem_range.mp hi).le.trans hj) + dsimp only [lam] + field_simp + rw [he] at hh + have hDj := earlyCodegreeScale_ge_prefixD n j hj (le_trans (by positivity) hp) + have hD : 0 < prefixD n := by unfold prefixD; have := early_density_positive hn hp (show prefixTime n ≤ prefixTime n by rfl); rw [earlyDensity_prefix] at this; positivity + have hDj' : prefixD n ≤ (n : ℝ)*p j^2 := by simpa only [earlyTemplateScale,pow_one] using hDj + have hr := one_div_le_one_div_of_le hD hDj' + have ht : 0 ≤ 1/((n : ℝ)*p 0^2) := by positivity + have he' : 1/prefixD n = 2*(1/(2*prefixD n)) := by ring + rw [he'] at hr + linarith only [hh,hr,ht] + have hsq : (∑ i ∈ Finset.range j, (lam i)^2) ≤ 6/(n : ℝ)*Real.log n := by + have hlmax (i : ℕ) (hi : i < j) : lam i ≤ 6/(n : ℝ) := by + have hp' := hp.trans (earlyDensity_antitone n (hi.le.trans hj)) + change 1/(n : ℝ) ≤ p i at hp' + apply (div_le_iff₀ (hpos i (hi.le.trans hj))).mpr + dsimp only [h] + have hm := mul_le_mul_of_nonneg_left hp' (show 0 ≤ 6/(n : ℝ) by positivity) + convert hm using 1 + field_simp + calc + _ ≤ ∑ i ∈ Finset.range j, (6/(n : ℝ))*lam i := by + apply Finset.sum_le_sum + intro i hi + have hli : 0 ≤ lam i := by dsimp [lam,h]; exact div_nonneg (by positivity) (hpos i ((Finset.mem_range.mp hi).le.trans hj)).le + nlinarith only [mul_le_mul_of_nonneg_right (hlmax i (Finset.mem_range.mp hi)) hli] + _ = 6/(n : ℝ)*(∑ i ∈ Finset.range j, lam i) := (Finset.mul_sum _ _ _).symm + _ ≤ _ := mul_le_mul_of_nonneg_left hlog (by positivity) + exact ⟨hlog,hlD,hsq⟩ + +theorem early_triangle_drift_bound {n : ℕ} (η : ℝ) (hn : 0 < n) + (hp : 1/(n : ℝ) ≤ prefixDensity n) (hη : 0 ≤ η) (hη1 : η ≤ 1/2) + (hreg : ∀ i < prefixTime n, earlyTriangleScale n i ≤ 2*earlyTriangleScale n (i+1)) + (j : ℕ) (hj : j ≤ prefixTime n) (ω : History (Graph n) (prefixTime n)) + (hsafe : ∀ i < j, densityEdgeSafe n (earlyDensity n i) η (ω (historyIndex (prefixTime n) i))) : + |(triangles (ω (historyIndex (prefixTime n) j))).card/earlyTriangleScale n j- + (triangles (ω (historyIndex (prefixTime n) 0))).card/earlyTriangleScale n 0- + historyNoise (fun _ => step) (fun i G => (triangles G).card/earlyTriangleScale n i) + (prefixTime n) j ω| ≤ 12*η^2*Real.log n+2/prefixD n+216*Real.log n/(n : ℝ) := by + have hb := early_grid_sum_bounds hn hp j hj + rw [history_relative_drift_sum (fun _ => step) (fun G : Graph n => ((triangles G).card : ℝ)) + (earlyTriangleScale n) (prefixTime n) j hj ω] + calc + _ ≤ ∑ i ∈ Finset.range j, + |pmfMean (step (ω (historyIndex (prefixTime n) i))) (fun G => ((triangles G).card : ℝ))/earlyTriangleScale n (i+1)- + (triangles (ω (historyIndex (prefixTime n) i))).card/earlyTriangleScale n i| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i ∈ Finset.range j, + (12*η^2*(6/(n : ℝ)^2/earlyDensity n i)+ + 4*(6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2)+ + 36*(6/(n : ℝ)^2/earlyDensity n i)^2) := by + apply Finset.sum_le_sum + intro i hi + have hij := Finset.mem_range.mp hi + exact early_triangle_drift_single hn hp (by omega) hη hη1 (hreg i (by omega)) (hsafe i hij) + _ = 12*η^2*(∑ i ∈ Finset.range j, 6/(n : ℝ)^2/earlyDensity n i)+ + 4*(∑ i ∈ Finset.range j, (6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2))+ + 36*(∑ i ∈ Finset.range j, (6/(n : ℝ)^2/earlyDensity n i)^2) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + _ ≤ _ := by + have h₁ := mul_le_mul_of_nonneg_left hb.1 (show 0 ≤ 12*η^2 by positivity) + have h₂ := mul_le_mul_of_nonneg_left hb.2.1 (by norm_num : (0 : ℝ) ≤ 4) + have h₃ := mul_le_mul_of_nonneg_left hb.2.2 (by norm_num : (0 : ℝ) ≤ 36) + simp only [div_eq_mul_inv,mul_inv_rev] at h₁ h₂ h₃ ⊢ + norm_num only [invOf_eq_inv,inv_div,inv_one] at h₂ + nlinarith only [h₁,h₂,h₃] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityGlobalInfty.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityGlobalInfty.lean new file mode 100644 index 0000000000000000000000000000000000000000..ddcb7a23b2e206a7fa60ac54b64732511596c293 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/DensityGlobalInfty.lean @@ -0,0 +1,60 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.AveragingProjectorInftyOne + +namespace OAI + +section +noncomputable section +open scoped BigOperators Matrix.Norms.Operator +open Classical Matrix + +namespace SharpTerminalLeave + +theorem density_global_infty {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (D : ℝ) (hD0 : 0 < D) + (hrow : ∀ u v : Fin n, {u,v} ∈ G → (currentCodegree G u v : ℝ) ≤ 2*D) : + ‖D⁻¹ • globalLinkAdjacency G hG‖ ≤ 4 := by + have hlocal : ∀ u, ‖(D)⁻¹ • linkStarMatrix G hG u‖ ≤ 2 := by + intro u + change ‖Matrix.reindex (neighborEdgeEquiv G hG u) (neighborEdgeEquiv G hG u) + ((D)⁻¹ • (linkSimpleGraph G hG u).adjMatrix ℝ)‖ ≤ 2 + apply (infty_reindex_norm_le _ _).trans + apply matrix_norm_le_of_row_abs_sum_le _ _ (by norm_num) + intro v + have hdeg : ((Finset.univ.filter ((linkSimpleGraph G hG u).Adj v)).card : ℝ) ≤ 2*D := by + rw [link_degree_eq G hG u v] + exact hrow u v.val (Finset.mem_filter.mp v.property).2 + have heq : ∑ j : neighbors G u, + |((D)⁻¹ • (linkSimpleGraph G hG u).adjMatrix ℝ) v j| = + (D)⁻¹ * ((Finset.univ.filter ((linkSimpleGraph G hG u).Adj v)).card : ℝ) := by + simp only [Matrix.smul_apply,smul_eq_mul,abs_mul,abs_of_pos (inv_pos.mpr hD0)] + rw [← Finset.mul_sum] + congr 1 + simp only [SimpleGraph.adjMatrix_apply] + simp only [apply_ite abs,abs_one,abs_zero,Finset.sum_boole] + rw [heq] + calc + _ ≤ (D)⁻¹ * (2 * D) := + mul_le_mul_of_nonneg_left hdeg (inv_nonneg.mpr hD0.le) + _ = 2 := by field_simp + have hsplit : (D)⁻¹ • globalLinkAdjacency G hG = + ∑ u, extendStar (edgeStar G u) ((D)⁻¹ • linkStarMatrix G hG u) := by + simp [globalLinkAdjacency,Finset.smul_sum,extendStar,Matrix.smul_mul,Matrix.mul_smul] + rw [hsplit] + simpa only [show (2 : ℝ)*2 = 4 by norm_num] using + sum_star_infty_norm_bound (edgeStar G) _ 2 2 (by norm_num) (by norm_num) hlocal + (fun e => by rw [edgeStar_exact_overlap G hG e]; norm_num) + +lemma density_residual_infty {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (D : ℝ) (hD0 : 0 < D) + (hrow : ∀ u v : Fin n, {u,v} ∈ G → (currentCodegree G u v : ℝ) ≤ 2*D) : + ‖D⁻¹ • globalLinkAdjacency G hG-globalStarAverage G‖ ≤ 6 := by + have ha := density_global_infty G hG D hD0 hrow + have hp := globalStarAverage_infty_le_two G hG + exact (norm_sub_le _ _).trans (by linarith only [ha,hp]) + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EarlyDensity.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EarlyDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a3cb373284dbe31282410c0498d55465fb40334 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EarlyDensity.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Asymptotics.OneAddLogRpow +import OAI.Combinatorics.TriangleRemoval.Asymptotics.RelativeScaleBudgetLog + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +noncomputable def earlyDensity (n i : ℕ) : ℝ := + 1-1/(n : ℝ)-6*(i : ℝ)/(n : ℝ)^2 + +@[simp] lemma earlyDensity_prefix (n : ℕ) : + earlyDensity n (prefixTime n) = prefixDensity n := rfl + +lemma earlyDensity_antitone (n : ℕ) : Antitone (earlyDensity n) := by + intro i j hij + unfold earlyDensity + have hh : (i : ℝ) ≤ j := by exact_mod_cast hij + exact sub_le_sub_left (div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left hh (by norm_num)) (sq_nonneg (n : ℝ))) _ + +lemma earlyDensity_succ (n i : ℕ) : + earlyDensity n i = earlyDensity n (i+1)+6/(n : ℝ)^2 := by + unfold earlyDensity + push_cast + ring + +lemma prefixDensity_eventually_inverse_lower : ∀ᶠ n : ℕ in atTop, + 1/(n : ℝ) ≤ prefixDensity n := by + filter_upwards [prefixDensity_eventual_envelope,eventually_ge_atTop (1 : ℕ)] with n hn hn1 + apply le_trans _ hn.1 + rw [one_div,← Real.rpow_neg_one] + exact Real.rpow_le_rpow_of_exponent_le (by exact_mod_cast hn1) (by norm_num) + +noncomputable def earlyTemplateScale (a b n i : ℕ) : ℝ := + (n : ℝ)^a * earlyDensity n i ^ b + +theorem earlyTemplateScale_regular (a b : ℕ) : ∀ᶠ n : ℕ in atTop, + (∀ i ≤ prefixTime n, 0 < earlyTemplateScale a b n i) ∧ + (∀ i < prefixTime n, earlyTemplateScale a b n (i+1) ≤ earlyTemplateScale a b n i) ∧ + (∀ i < prefixTime n, earlyTemplateScale a b n i ≤ 2*earlyTemplateScale a b n (i+1)) := by + have hi : Tendsto (fun n : ℕ => 6/(n : ℝ)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop + have hlim : Tendsto (fun n : ℕ => (1+6/(n : ℝ))^b) atTop (𝓝 1) := by + simpa only [add_zero,one_pow] using ((tendsto_const_nhds (x := (1 : ℝ))).add hi).pow b + filter_upwards [prefixDensity_eventually_inverse_lower, + hlim.eventually_le_const (by norm_num : (1 : ℝ) < 2), + eventually_ge_atTop (1 : ℕ)] with n hp hratio hn + have hn0 : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n) + have hlow : ∀ i ≤ prefixTime n, 1/(n : ℝ) ≤ earlyDensity n i := by + intro i hi + exact hp.trans (earlyDensity_antitone n hi) + have hpos : ∀ i ≤ prefixTime n, 0 < earlyDensity n i := by + intro i hi + exact lt_of_lt_of_le (by positivity) (hlow i hi) + refine ⟨?_,?_,?_⟩ + · intro i hi + exact mul_pos (pow_pos hn0 _) (pow_pos (hpos i hi) _) + · intro i hi + exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (hpos (i+1) (by omega)).le + (earlyDensity_antitone n (Nat.le_succ i)) b) (by positivity) + · intro i hi + have hp1 : 0 < earlyDensity n (i+1) := hpos (i+1) (by omega) + have hstep : earlyDensity n i ≤ earlyDensity n (i+1)*(1+6/(n : ℝ)) := by + rw [earlyDensity_succ n i] + have hh := hlow (i+1) (by omega) + have hhmul := mul_le_mul_of_nonneg_left hh (show 0 ≤ 6/(n : ℝ) by positivity) + have he : (6/(n : ℝ))*(1/(n : ℝ)) = 6/(n : ℝ)^2 := by ring + rw [he] at hhmul + nlinarith only [hhmul] + have hpw := pow_le_pow_left₀ (hpos i (by omega)).le hstep b + rw [mul_pow] at hpw + unfold earlyTemplateScale + calc + _ ≤ (n : ℝ)^a * (earlyDensity n (i+1)^b*(1+6/(n : ℝ))^b) := + mul_le_mul_of_nonneg_left hpw (by positivity) + _ ≤ (n : ℝ)^a * (earlyDensity n (i+1)^b*2) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hratio (by positivity)) + (by positivity) + _ = _ := by ring + +theorem earlyTemplateScale_log_budget (a b : ℕ) : ∀ᶠ n : ℕ in atTop, + relativeScaleBudget (earlyTemplateScale a b n) (prefixTime n) ≤ + 2*(b : ℝ)*Real.log n := by + filter_upwards [earlyTemplateScale_regular a b,prefixDensity_eventually_inverse_lower, + eventually_ge_atTop (1 : ℕ)] with n hreg hlow hn + have hn0 : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n) + have hp : 0 < prefixDensity n := lt_of_lt_of_le (by positivity) hlow + have hscale : earlyTemplateScale a b n 0/earlyTemplateScale a b n (prefixTime n) ≤ + (n : ℝ)^b := by + unfold earlyTemplateScale + rw [earlyDensity_prefix,mul_div_mul_left _ _ (ne_of_gt (pow_pos hn0 a)),← div_pow] + apply pow_le_pow_left₀ (div_nonneg (by + have hh := (earlyDensity_antitone n (Nat.zero_le (prefixTime n))) + change prefixDensity n ≤ earlyDensity n 0 at hh + linarith) hp.le) + apply (div_le_iff₀ hp).mpr + have hp' := (div_le_iff₀ hn0).mp hlow + have hzero : earlyDensity n 0 ≤ 1 := by unfold earlyDensity; simp + nlinarith only [hp',hzero] + have hlog := Real.log_le_log + (div_pos (hreg.1 0 (Nat.zero_le _)) (hreg.1 (prefixTime n) le_rfl)) hscale + rw [Real.log_pow] at hlog + exact (relativeScaleBudget_le_log (earlyTemplateScale a b n) (prefixTime n) + hreg.1 hreg.2.1 hreg.2.2).trans (by nlinarith only [hlog]) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EarlyDensityOne.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EarlyDensityOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..f84d4bb22327b11bebb085c50d4a2fa6cbe4a675 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EarlyDensityOne.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Asymptotics.EarlyDensity + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma earlyDensity_le_one (n i : ℕ) : earlyDensity n i ≤ 1 := by + unfold earlyDensity + have h₁ : 0 ≤ 1/(n : ℝ) := by positivity + have h₂ : 0 ≤ 6*(i : ℝ)/(n : ℝ)^2 := by positivity + linarith + +theorem earlyTemplateScale_balanced_lower (a b : ℕ) (hb : b ≤ 2*a) : + ∀ᶠ n : ℕ in atTop, ∀ i ≤ prefixTime n, + (n : ℝ)^((a : ℝ)/1000) ≤ earlyTemplateScale a b n i := by + filter_upwards [prefixD_eventual_envelope, prefixDensity_eventually_inverse_lower, + eventually_ge_atTop (1 : ℕ)] with n hD hp hn + intro i hi + have hn0 : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n) + have hpp : 0 < prefixDensity n := lt_of_lt_of_le (by positivity) hp + have hpi : prefixDensity n ≤ earlyDensity n i := earlyDensity_antitone n hi + have hp0 : 0 ≤ earlyDensity n i := (hpp.trans_le hpi).le + have hDi : prefixD n ≤ (n : ℝ)*earlyDensity n i^2 := by + exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ hpp.le hpi 2) hn0.le + have hh := pow_le_pow_left₀ (Real.rpow_nonneg hn0.le (1/1000 : ℝ)) + (hD.1.trans hDi) a + have he : ((n : ℝ)^(1/1000 : ℝ))^a = (n : ℝ)^((a : ℝ)/1000) := by + rw [← Real.rpow_natCast, ← Real.rpow_mul hn0.le] + congr 1 + ring + rw [he,mul_pow] at hh + apply hh.trans + unfold earlyTemplateScale + apply mul_le_mul_of_nonneg_left _ (by positivity) + rw [← pow_mul] + exact pow_le_pow_of_le_one hp0 (earlyDensity_le_one n i) hb + +theorem earlyTemplateScale_balanced_uniform_lower : ∀ᶠ n : ℕ in atTop, + ∀ a b : ℕ, 1 ≤ a → b ≤ 2*a → ∀ i ≤ prefixTime n, + (n : ℝ)^(1/1000 : ℝ) ≤ earlyTemplateScale a b n i := by + filter_upwards [prefixD_eventual_envelope, prefixDensity_eventually_inverse_lower, + eventually_ge_atTop (1 : ℕ)] with n hD hp hn + intro a b ha hb i hi + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn + have hn0 : (0 : ℝ) < n := lt_of_lt_of_le zero_lt_one hn1 + have hpp : 0 < prefixDensity n := lt_of_lt_of_le (by positivity) hp + have hpi : prefixDensity n ≤ earlyDensity n i := earlyDensity_antitone n hi + have hp0 : 0 ≤ earlyDensity n i := (hpp.trans_le hpi).le + have hx : (n : ℝ)^(1/1000 : ℝ) ≤ (n : ℝ)*earlyDensity n i^2 := + hD.1.trans (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ hpp.le hpi 2) hn0.le) + have hx1 : 1 ≤ (n : ℝ)*earlyDensity n i^2 := + (Real.one_le_rpow hn1 (by norm_num : (0 : ℝ) ≤ 1/1000)).trans hx + apply hx.trans + calc + _ ≤ ((n : ℝ)*earlyDensity n i^2)^a := by + simpa only [pow_one] using (pow_le_pow_right₀ hx1 ha) + _ ≤ earlyTemplateScale a b n i := by + rw [mul_pow,← pow_mul] + unfold earlyTemplateScale + exact mul_le_mul_of_nonneg_left + (pow_le_pow_of_le_one hp0 (earlyDensity_le_one n i) hb) (by positivity) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EndpointMarksExponential.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EndpointMarksExponential.lean new file mode 100644 index 0000000000000000000000000000000000000000..e05ddc0dab8143d2daf7963c1d9a604f3c423613 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/EndpointMarksExponential.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.WitnessMu + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +lemma endpoint_marks_exponential (s : ℕ) : + ((s : ℝ)+4)^2 ≤ 32*(5/4 : ℝ)^s := by + induction s with + | zero => norm_num + | succ s ih => + by_cases hs : s < 5 + · interval_cases s <;> norm_num + · have hn : (5 : ℝ) ≤ s := by exact_mod_cast Nat.le_of_not_gt hs + have hstep : ((s : ℝ)+5)^2 ≤ (5/4 : ℝ)*((s : ℝ)+4)^2 := by + nlinarith [sq_nonneg ((s : ℝ)-5)] + have hh := mul_le_mul_of_nonneg_left ih (by norm_num : (0 : ℝ) ≤ 5/4) + simp only [Nat.cast_add,Nat.cast_one,pow_succ] + nlinarith + +lemma pattern_marks_exponential {R s : ℕ} (hR : R ≤ 4) : + (((R+s)^2 * 6^s : ℕ) : ℝ) ≤ 32*(15/2 : ℝ)^s := by + have hr : (R : ℝ) ≤ 4 := by exact_mod_cast hR + have hp : ((R : ℝ)+(s : ℝ))^2 ≤ ((s : ℝ)+4)^2 := by + exact pow_le_pow_left₀ (by positivity) (by linarith : (R : ℝ)+(s : ℝ) ≤ (s : ℝ)+4) 2 + push_cast + calc + _ ≤ (((s : ℝ)+4)^2)*(6 : ℝ)^s := + mul_le_mul_of_nonneg_right hp (by positivity) + _ ≤ (32*(5/4 : ℝ)^s)*(6 : ℝ)^s := + mul_le_mul_of_nonneg_right (endpoint_marks_exponential s) (by positivity) + _ = 32*(15/2 : ℝ)^s := by rw [mul_assoc,← mul_pow]; norm_num + +theorem generous_witness_length_sum {D : ℝ} (hD : 0 < D) : + (1 + 2*D)^3 * (∑' h : ℕ, ∑' a : ℕ, ∑' b : ℕ, + (30*D*witnessMu D)^(h+a+b) / + ((h.factorial : ℝ)*(a.factorial : ℝ)*(b.factorial : ℝ))) = + (1+2*D)^48 := by + rw [three_segment_series] + have he : 3*(30*D*witnessMu D) = 45*Real.log (1+2*D) := by + unfold witnessMu + field_simp + ring + rw [he,show (45 : ℝ) = (45 : ℕ) by norm_num,Real.exp_nat_mul, + Real.exp_log (by linarith : 0 < 1+2*D)] + rw [← pow_add] + +theorem generous_witness_power_bound {D : ℝ} (hD : 1 ≤ D) : + 32*(1+2*D)^48 / D^50 ≤ 32*(3 : ℝ)^48 / D^2 := by + have hpos : 0 < D := lt_of_lt_of_le zero_lt_one hD + have hm : (1+2*D)^48 ≤ (3*D)^48 := + pow_le_pow_left₀ (by positivity) (by linarith) _ + have hh := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left hm (by norm_num : (0 : ℝ) ≤ 32)) + (le_of_lt (pow_pos hpos 50)) + apply hh.trans_eq + rw [mul_pow,show 50=48+2 by norm_num,pow_add] + field_simp + +theorem generous_witness_scaled_tendsto : + Tendsto (fun D : ℝ => D*(32*(1+2*D)^48/D^50)) atTop (𝓝 0) := by + have hupper : Tendsto (fun D : ℝ => 32*(3 : ℝ)^48 / D) atTop (𝓝 0) := by + have ht := (tendsto_inv_atTop_zero : Tendsto (fun D : ℝ => D⁻¹) atTop (𝓝 0)).const_mul + (32*(3 : ℝ)^48) + simpa only [mul_zero,div_eq_mul_inv] using ht + apply squeeze_zero' _ _ hupper + · filter_upwards [eventually_ge_atTop (1 : ℝ)] with D hD + positivity + · filter_upwards [eventually_ge_atTop (1 : ℝ)] with D hD + have hpos : 0 < D := lt_of_lt_of_le zero_lt_one hD + have hh := mul_le_mul_of_nonneg_left (generous_witness_power_bound hD) hpos.le + apply hh.trans_eq + field_simp + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/FreshLog.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/FreshLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..31fd993dd656c8600af703e97810a38dbbc966c2 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/FreshLog.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.TreeBind + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave.ExposureTree +open scoped BigOperators + +variable {K V O P : Type*} + +noncomputable def freshLog (ν : K → PMF V) : ExposureTree K V O → PMF (O × List K) + | .done o => PMF.pure (o, []) + | .ask k f => (ν k).bind (fun v => + (freshLog ν (f v)).map (fun z => (z.1, k :: z.2))) + +def repeats [DecidableEq K] : Finset K → List K → Bool + | _, [] => false + | seen, k :: ks => decide (k ∈ seen) || repeats (insert k seen) ks + +@[simp] theorem repeats_cons [DecidableEq K] (seen : Finset K) (k : K) (ks : List K) : + repeats seen (k :: ks) = (decide (k ∈ seen) || repeats (insert k seen) ks) := rfl + +theorem repeats_false_iff [DecidableEq K] (seen : Finset K) (ks : List K) : + repeats seen ks = false ↔ ks.Nodup ∧ ∀ k ∈ ks, k ∉ seen := by + induction ks generalizing seen with + | nil => simp [repeats] + | cons k ks ih => + simp only [repeats_cons, Bool.or_eq_false_iff, decide_eq_false_iff_not, + ih, List.nodup_cons, List.mem_cons, Finset.mem_insert, not_or] + constructor + · rintro ⟨hk, hnd, hh⟩ + refine ⟨⟨?_, hnd⟩, ?_⟩ + · intro hmem + exact (hh k hmem).1 rfl + · intro a ha + rcases ha with rfl | ha + · exact hk + · exact (hh a ha).2 + · rintro ⟨⟨hkm,hnd⟩, hh⟩ + refine ⟨hh k (Or.inl rfl), hnd, ?_⟩ + intro a ha + refine ⟨?_, hh a (Or.inr ha)⟩ + intro hak + exact hkm (hak ▸ ha) + +@[simp] theorem repeats_empty_false_iff [DecidableEq K] (ks : List K) : + repeats ∅ ks = false ↔ ks.Nodup := by simp [repeats_false_iff] + +@[simp] theorem freshLog_outcome (ν : K → PMF V) (A : ExposureTree K V O) : + (freshLog ν A).map Prod.fst = fresh ν A := by + induction A with + | done o => simp [freshLog, fresh, PMF.pure_map] + | ask k f ih => + simp only [freshLog, PMF.map_bind, PMF.map_comp, fresh] + congr 1 + funext v + exact ih v + +theorem freshRecorded_eq_log [DecidableEq K] (ν : K → PMF V) + (A : ExposureTree K V O) (seen : Finset K) : + freshRecorded ν A seen = + (freshLog ν A).map (fun z => (z.1, repeats seen z.2)) := by + induction A generalizing seen with + | done o => simp [freshRecorded, freshLog, repeats, PMF.pure_map] + | ask k f ih => + simp only [freshRecorded, freshLog, PMF.map_bind, PMF.map_comp] + congr 1 + funext v + by_cases hk : k ∈ seen + · simp only [ite_eq_left hk, ih, PMF.map_comp] + congr 1 + funext z + simp [repeats, hk] + · simp only [ite_eq_right hk, ih] + congr 1 + funext z + simp [repeats, hk] + +theorem freshLog_bind (ν : K → PMF V) (A : ExposureTree K V O) + (f : O → ExposureTree K V P) : + freshLog ν (bind A f) = + (freshLog ν A).bind (fun z => + (freshLog ν (f z.1)).map (fun y => (y.1, z.2 ++ y.2))) := by + induction A with + | done o => + simp only [bind, freshLog, PMF.pure_bind, List.nil_append] + exact (PMF.map_id _).symm + | ask k g ih => + simp only [bind, freshLog, ih, PMF.bind_bind, PMF.map_bind, PMF.bind_map, + PMF.map_comp] + congr 1 + +end SharpTerminalLeave.ExposureTree + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/FreshLogExposeLabeled.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/FreshLogExposeLabeled.lean new file mode 100644 index 0000000000000000000000000000000000000000..d5a80d702dbd9d4f3b28f14345668e0a3788d03f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/FreshLogExposeLabeled.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.MapOutput + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave.ExposureTree +variable {K V O R A : Type*} + +theorem freshLog_exposeLabeled_support (ν : K → PMF V) (key : A → K) (as : List A) + {z : List (A × V) × List K} + (hz : z ∈ (freshLog ν (exposeLabeled key as)).support) : + z.1.map Prod.fst = as ∧ z.2 = as.map key := by + induction as generalizing z with + | nil => + have heq : z = ([],[]) := by simpa [exposeLabeled, freshLog] using hz + simp [heq] + | cons a as ih => + simp only [exposeLabeled, freshLog, PMF.mem_support_bind_iff] at hz + obtain ⟨v,_,hv⟩ := hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hv + rw [freshLog_bind] at hy + obtain ⟨w,hw,hy⟩ := (PMF.mem_support_bind_iff _ _ _).mp hy + have heq : y = ((a,v)::w.1,w.2) := by + simpa [freshLog, PMF.pure_map, List.append_nil] using hy + obtain ⟨hvals,hkeys⟩ := ih hw + simp [heq,hvals,hkeys] + +theorem freshLog_checkNoneTrace_support (ν : K → PMF V) (keys : R → List K) + (as : List (ExposureTree K V (Bool × List R))) + (ha : ∀ A ∈ as, ∀ z ∈ (freshLog ν A).support, z.2 = z.1.2.flatMap keys) + {z : (Bool × List R) × List K} + (hz : z ∈ (freshLog ν (checkNoneTrace as)).support) : + z.2 = z.1.2.flatMap keys := by + induction as generalizing z with + | nil => + have heq : z = ((true,[]),[]) := by simpa [checkNoneTrace,freshLog] using hz + simp [heq] + | cons A as ih => + rw [checkNoneTrace, freshLog_bind] at hz + obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + have hxlog := ha A (by simp) x hx + have has (B) (hB : B ∈ as) := ha B (by simp [hB]) + cases hb : x.1.1 + · simp only [hb, Bool.false_eq_true, ↓reduceIte, freshLog_mapOutput] at hy + obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy + simp only [List.flatMap_append, hxlog, ih has hw] + · simp only [hb, ↓reduceIte, freshLog, PMF.mem_support_pure_iff] at hy + subst y + simp [hxlog] + +end SharpTerminalLeave.ExposureTree + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/LogStepSandwich.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/LogStepSandwich.lean new file mode 100644 index 0000000000000000000000000000000000000000..3aea1191f6e81c5f70b900310f5a251595066016 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/LogStepSandwich.lean @@ -0,0 +1,99 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma log_step_sandwich {p q h : ℝ} (hp : 0 < p) (hq : 0 < q) (hs : p = q+h) : + h/p ≤ Real.log p-Real.log q ∧ Real.log p-Real.log q ≤ h/q := by + have hl := Real.log_le_sub_one_of_pos (div_pos hq hp) + have hu := Real.log_le_sub_one_of_pos (div_pos hp hq) + rw [Real.log_div (ne_of_gt hq) (ne_of_gt hp)] at hl + rw [Real.log_div (ne_of_gt hp) (ne_of_gt hq)] at hu + have he₁ : q/p-1 = -(h/p) := by field_simp; linarith only [hs] + have he₂ : p/q-1 = h/q := by field_simp; linarith only [hs] + rw [he₁] at hl + rw [he₂] at hu + exact ⟨by linarith only [hl],hu⟩ + +theorem density_log_sum_bounds (p : ℕ → ℝ) (h : ℝ) (T : ℕ) + (hp : ∀ i ≤ T, 0 < p i) (hs : ∀ i < T, p i = p (i+1)+h) : + (∑ i ∈ Finset.range T, h/p i) ≤ Real.log (p 0)-Real.log (p T) ∧ + Real.log (p 0)-Real.log (p T) ≤ + (∑ i ∈ Finset.range T, h/p i)+(h/p T-h/p 0) := by + induction T with + | zero => simp + | succ T ih => + obtain ⟨hl,hu⟩ := ih (fun i hi => hp i (by omega)) (fun i hi => hs i (by omega)) + obtain ⟨sl,su⟩ := log_step_sandwich (hp T (by omega)) (hp (T+1) le_rfl) (hs T (by omega)) + rw [Finset.sum_range_succ] + constructor <;> linarith only [hl,hu,sl,su] + +lemma inverse_square_grid_step {a p q h : ℝ} (ha : 0 < a) (hp : 0 < p) (hq : 0 < q) + (hh : 0 ≤ h) (hs : p = q+h) : + 2*h/(a*p^3) ≤ 1/(a*q^2)-1/(a*p^2) := by + have hpq : q ≤ p := by linarith only [hs,hh] + have hc : 2*q^2 ≤ p*(p+q) := by nlinarith [mul_nonneg (sub_nonneg.mpr hpq) (by linarith : 0 ≤ p+2*q)] + have hm := mul_le_mul_of_nonneg_left hc hh + have he : p^2-q^2 = h*(p+q) := by rw [hs]; ring + apply (div_le_iff₀ (mul_pos ha (pow_pos hp 3))).mpr + have hd : (1/(a*q^2)-1/(a*p^2))*(a*p^3) = (p^2-q^2)*p/q^2 := by + field_simp + rw [hd,he] + apply (le_div_iff₀ (pow_pos hq 2)).mpr + nlinarith only [hm] + +theorem inverse_square_grid_sum (p : ℕ → ℝ) (a h : ℝ) (T : ℕ) + (ha : 0 < a) (hh : 0 ≤ h) (hp : ∀ i ≤ T, 0 < p i) + (hs : ∀ i < T, p i = p (i+1)+h) : + (∑ i ∈ Finset.range T, 2*h/(a*p i^3)) ≤ 1/(a*p T^2)-1/(a*p 0^2) := by + induction T with + | zero => simp + | succ T ih => + have hi := ih (fun i hi => hp i (by omega)) (fun i hi => hs i (by omega)) + have hstep := inverse_square_grid_step ha (hp T (by omega)) (hp (T+1) le_rfl) hh (hs T (by omega)) + rw [Finset.sum_range_succ] + linarith only [hi,hstep] + +theorem density_survival_exponent_bound (p : ℕ → ℝ) (a h b η : ℝ) (T : ℕ) + (ha : 0 < a) (hh : 0 ≤ h) (hb : 0 ≤ b) (hη : 0 ≤ η) + (hp : ∀ i ≤ T, 0 < p i) (hs : ∀ i < T, p i = p (i+1)+h) + (hp0 : p 0 ≤ 1) : + (∑ i ∈ Finset.range T, (-b*(h/p i)+2*b*η*(h/p i)+b^2*(2*h/(a*p i^3)))) ≤ + b*Real.log (p T)+b*(1-p 0)/p 0+b*h/p T+ + 2*b*η*(-Real.log (p T))+b^2/(a*p T^2) := by + obtain ⟨hloglo,hloghi⟩ := density_log_sum_bounds p h T hp hs + have hinv := inverse_square_grid_sum p a h T ha hh hp hs + have hln0 : Real.log (p 0) ≤ 0 := Real.log_nonpos (hp 0 (Nat.zero_le _)).le hp0 + have hlninit : -Real.log (p 0) ≤ (1-p 0)/p 0 := by + have hi := Real.log_le_sub_one_of_pos (inv_pos.mpr (hp 0 (Nat.zero_le _))) + rw [Real.log_inv] at hi + have he : (p 0)⁻¹-1 = (1-p 0)/p 0 := by + field_simp [ne_of_gt (hp 0 (Nat.zero_le _))] + rwa [he] at hi + have h₁ := mul_le_mul_of_nonneg_left hloghi hb + have h₂ := mul_le_mul_of_nonneg_left hloglo (show 0 ≤ 2*b*η by positivity) + have h₃ := mul_le_mul_of_nonneg_left hinv (sq_nonneg b) + have h₄ := mul_le_mul_of_nonneg_left hlninit hb + have h₅ := mul_nonpos_of_nonneg_of_nonpos (show 0 ≤ 2*b*η by positivity) hln0 + have hpzero := hp 0 (Nat.zero_le _) + have h₆ : 0 ≤ b*h/p 0 := by positivity + have h₇ : 0 ≤ b^2/(a*p 0^2) := by positivity + have he : (∑ i ∈ Finset.range T, (-b*(h/p i)+2*b*η*(h/p i)+b^2*(2*h/(a*p i^3)))) = + -b*(∑ i ∈ Finset.range T, h/p i)+2*b*η*(∑ i ∈ Finset.range T, h/p i)+ + b^2*(∑ i ∈ Finset.range T, 2*h/(a*p i^3)) := by + simp only [Finset.sum_add_distrib,← Finset.mul_sum] + rw [he] + simp only [mul_sub,mul_add] at h₁ h₂ h₃ + simp only [div_eq_mul_inv] at h₁ h₂ h₃ h₄ h₆ h₇ ⊢ + nlinarith only [h₁,h₂,h₃,h₄,h₅,h₆,h₇] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/OneAddLogRpow.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/OneAddLogRpow.lean new file mode 100644 index 0000000000000000000000000000000000000000..e502d178d11e8420ab18404d133b20df6649245b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/OneAddLogRpow.lean @@ -0,0 +1,212 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEpsilon + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +open Asymptotics + +lemma one_add_log_rpow_isLittleO (C : ℝ) {δ : ℝ} (hδ : 0 < δ) : + (fun x : ℝ => (1 + Real.log x) ^ C) =o[atTop] fun x => x ^ δ := by + let C' := max C 1 + have hC' : 0 < C' := lt_max_iff.mpr (Or.inr zero_lt_one) + have hq : 0 < δ / C' := div_pos hδ hC' + have hc : (fun _ : ℝ => (1 : ℝ)) =o[atTop] fun x => x ^ (δ / C') := by + apply (isLittleO_const_left_of_ne one_ne_zero).mpr + apply (tendsto_rpow_atTop hq).congr' + filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hx + exact (Real.norm_of_nonneg (Real.rpow_nonneg hx _)).symm + have hs := hc.add (isLittleO_log_rpow_atTop hq) + calc + (fun x : ℝ => (1 + Real.log x) ^ C) =O[atTop] + fun x => (1 + Real.log x) ^ C' := by + apply IsBigO.of_norm_eventuallyLE + filter_upwards [Real.tendsto_log_atTop.eventually_ge_atTop 0] with x hx + simp only [Real.norm_of_nonneg (Real.rpow_nonneg (by linarith : 0 ≤ 1 + Real.log x) C)] + exact Real.rpow_le_rpow_of_exponent_le (by linarith) (le_max_left _ _) + _ =o[atTop] fun x => (x ^ (δ / C')) ^ C' := + hs.rpow hC' ((eventually_ge_atTop (0 : ℝ)).mono fun x hx => Real.rpow_nonneg hx _) + _ =ᶠ[atTop] fun x => x ^ δ := by + filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hx + rw [← Real.rpow_mul hx,div_mul_cancel₀ _ hC'.ne'] + + theorem prefixTemplateFactor_subpower (C : ℝ) {δ b : ℝ} (hδ : 0 < δ) (hb : 0 < b) : + ∀ᶠ n : ℕ in atTop, prefixTemplateFactor n C ≤ b * (n : ℝ) ^ δ := by + have h := ((one_add_log_rpow_isLittleO C hδ).comp_tendsto + (tendsto_natCast_atTop_atTop (R := ℝ))).bound hb + filter_upwards [h,eventually_ge_atTop (1 : ℕ)] with n hn hn1 + have hnR : (1 : ℝ) ≤ n := by exact_mod_cast hn1 + have hl : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg hnR + have hb0 : 0 ≤ 1 + Real.log (n : ℝ) := by linarith + simpa only [Function.comp_apply,Real.norm_of_nonneg (Real.rpow_nonneg hb0 C), + Real.norm_of_nonneg (Real.rpow_nonneg (Nat.cast_nonneg n) δ),prefixTemplateFactor] using hn + +lemma prefixTargetDensity_eq (n : ℕ) : + prefixTargetDensity n = (n : ℝ) ^ (-(999 / 2000 : ℝ)) := by + unfold prefixTargetDensity prefixEpsilon + congr 1 + norm_num + +lemma prefixTargetDensity_tendsto : Tendsto prefixTargetDensity atTop (𝓝 0) := by + change Tendsto (fun n : ℕ => prefixTargetDensity n) atTop (𝓝 0) + simp_rw [prefixTargetDensity_eq] + exact (tendsto_rpow_neg_atTop (by norm_num : (0 : ℝ) < 999 / 2000)).comp + tendsto_natCast_atTop_atTop + +lemma prefixTargetTime_eventually_nonneg : ∀ᶠ n : ℕ in atTop, 0 ≤ prefixTargetTime n := by + have hi : Tendsto (fun n : ℕ => 1 / (n : ℝ)) atTop (𝓝 0) := by + simpa only [one_div,Function.comp_def] using (tendsto_inv_atTop_zero.comp + (tendsto_natCast_atTop_atTop (R := ℝ))) + filter_upwards [prefixTargetDensity_tendsto.eventually_le_const (by norm_num : (0 : ℝ) < 1/2), + hi.eventually_le_const (by norm_num : (0 : ℝ) < 1/2)] with n hp hi + unfold prefixTargetTime + exact mul_nonneg (by positivity) (by linarith) + +theorem prefixDensity_eventual_envelope : ∀ᶠ n : ℕ in atTop, + (n : ℝ) ^ (-(999 / 2000 : ℝ)) ≤ prefixDensity n ∧ + prefixDensity n ≤ 2 * (n : ℝ) ^ (-(999 / 2000 : ℝ)) := by + filter_upwards [prefixTargetTime_eventually_nonneg,eventually_ge_atTop (6 : ℕ)] with n ht hn + have hnR : (6 : ℝ) ≤ n := by exact_mod_cast hn + have hn0 : (0 : ℝ) < n := by linarith + obtain ⟨hl,hu⟩ := prefixDensity_bounds n (by omega) ht + rw [prefixTargetDensity_eq] at hl hu + refine ⟨hl,?_⟩ + have h1 : 6 / (n : ℝ)^2 ≤ 1 / (n : ℝ) := by + apply (div_le_div_iff₀ (by positivity : (0 : ℝ) < (n : ℝ)^2) hn0).mpr + nlinarith + have h2 : 1 / (n : ℝ) ≤ (n : ℝ) ^ (-(999 / 2000 : ℝ)) := by + rw [one_div,← Real.rpow_neg_one] + exact Real.rpow_le_rpow_of_exponent_le (by linarith) (by norm_num) + linarith + +lemma prefix_target_D_identity (n : ℕ) (hn : 0 < n) : + (n : ℝ) * ((n : ℝ) ^ (-(999 / 2000 : ℝ))) ^ 2 = + (n : ℝ) ^ (1 / 1000 : ℝ) := by + have hnR : (0 : ℝ) < n := Nat.cast_pos.mpr hn + rw [← Real.rpow_natCast,← Real.rpow_mul hnR.le] + conv_lhs => lhs; rw [← Real.rpow_one (n : ℝ)] + rw [← Real.rpow_add hnR] + congr 1 + norm_num + +theorem prefixD_eventual_envelope : ∀ᶠ n : ℕ in atTop, + (n : ℝ) ^ (1 / 1000 : ℝ) ≤ prefixD n ∧ + prefixD n ≤ 4 * (n : ℝ) ^ (1 / 1000 : ℝ) := by + filter_upwards [prefixDensity_eventual_envelope,eventually_ge_atTop (1 : ℕ)] with n hp hn + have hn0 : 0 < n := by omega + have hq : 0 ≤ (n : ℝ) ^ (-(999 / 2000 : ℝ)) := Real.rpow_nonneg (Nat.cast_nonneg n) _ + have hpl : 0 ≤ prefixDensity n := hq.trans hp.1 + rw [← prefix_target_D_identity n hn0] + unfold prefixD + constructor + · exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ hq hp.1 2) (Nat.cast_nonneg n) + · have hsq := pow_le_pow_left₀ hpl hp.2 2 + nlinarith [mul_nonneg (Nat.cast_nonneg n) (sub_nonneg.mpr hsq)] + +lemma prefixDensity_le_one (n : ℕ) : prefixDensity n ≤ 1 := by + have h₁ : 0 ≤ 1 / (n : ℝ) := by positivity + have h₂ : 0 ≤ 6 * (prefixTime n : ℝ) / (n : ℝ)^2 := by positivity + unfold prefixDensity + linarith + +lemma prefix_scales_eventually_pos : ∀ᶠ n : ℕ in atTop, + 0 < prefixDensity n ∧ 1 ≤ prefixD n := by + filter_upwards [prefixDensity_eventual_envelope,prefixD_eventual_envelope, + eventually_ge_atTop (1 : ℕ)] with n hp hD hn + have hnR : (1 : ℝ) ≤ n := by exact_mod_cast hn + exact ⟨(Real.rpow_pos_of_pos (by linarith : (0 : ℝ) < n) _).trans_le hp.1, + (Real.one_le_rpow hnR (by norm_num : (0 : ℝ) ≤ 1/1000)).trans hD.1⟩ + +lemma prefix_mixed_power_envelope (k : ℕ) : ∀ᶠ n : ℕ in atTop, + prefixDensity n * prefixD n ^ k ≤ + (2 * 4 ^ k) * (n : ℝ) ^ (-(999 / 2000 : ℝ) + (k : ℝ) / 1000) := by + filter_upwards [prefixDensity_eventual_envelope,prefixD_eventual_envelope, + prefix_scales_eventually_pos,eventually_ge_atTop (1 : ℕ)] with n hp hD hpos hn + have hnR : (0 : ℝ) < n := Nat.cast_pos.mpr (by omega) + have hD0 : 0 ≤ prefixD n := by linarith [hpos.2] + calc + _ ≤ (2 * (n : ℝ) ^ (-(999 / 2000 : ℝ))) * + (4 * (n : ℝ) ^ (1/1000 : ℝ)) ^ k := + mul_le_mul hp.2 (pow_le_pow_left₀ hD0 hD.2 k) (pow_nonneg hD0 k) (by positivity) + _ = _ := by + rw [mul_pow,← Real.rpow_natCast ((n : ℝ) ^ (1/1000 : ℝ)) k,← Real.rpow_mul hnR.le] + have he : (1/1000 : ℝ) * k = (k : ℝ) / 1000 := by ring + rw [he,Real.rpow_add hnR] + ring + +theorem prefixTemplateFactor_mixed_gain (C : ℝ) (k : ℕ) + (hk : (k : ℝ) / 1000 < 999 / 2000) : + ∀ᶠ n : ℕ in atTop, prefixTemplateFactor n C * + (prefixDensity n * prefixD n ^ k) ≤ 1 := by + let δ : ℝ := 999/2000 - (k : ℝ)/1000 + have hδ : 0 < δ := sub_pos.mpr hk + have hK : (0 : ℝ) < 2 * 4 ^ k := by positivity + filter_upwards [prefixTemplateFactor_subpower C hδ (inv_pos.mpr hK), + prefix_mixed_power_envelope k,prefix_scales_eventually_pos, + eventually_ge_atTop (1 : ℕ)] with n hκ hmix hpos hn + have hnR : (0 : ℝ) < n := Nat.cast_pos.mpr (by omega) + have hb : 0 ≤ prefixDensity n * prefixD n ^ k := + mul_nonneg hpos.1.le (pow_nonneg (by linarith [hpos.2]) k) + calc + _ ≤ ((2 * 4 ^ k)⁻¹ * (n : ℝ) ^ δ) * + ((2 * 4 ^ k) * (n : ℝ) ^ (-(999/2000 : ℝ) + (k : ℝ)/1000)) := + mul_le_mul hκ hmix hb (by positivity) + _ = 1 := by + rw [mul_mul_mul_comm,inv_mul_cancel₀ hK.ne',one_mul,← Real.rpow_add hnR] + have he : δ + (-(999/2000 : ℝ) + (k : ℝ)/1000) = 0 := by dsimp [δ]; ring + rw [he,Real.rpow_zero] + +theorem prefix_short_suppression (C : ℝ) : ∀ᶠ n : ℕ in atTop, + prefixTemplateFactor n C * prefixDensity n ≤ (prefixD n ^ 50)⁻¹ := by + filter_upwards [prefixTemplateFactor_mixed_gain C 50 (by norm_num), + prefix_scales_eventually_pos] with n hm hp + have hD : 0 < prefixD n ^ 50 := pow_pos (by linarith [hp.2]) _ + rw [← one_div,(le_div_iff₀ hD)] + simpa only [mul_assoc] using hm + +theorem prefix_suffix_scaling : ∀ᶠ n : ℕ in atTop, + (n : ℝ)^100 * prefixDensity n ^ 201 ≤ 1 := by + filter_upwards [prefixTemplateFactor_mixed_gain 0 100 (by norm_num)] with n hn + simpa only [prefixTemplateFactor,Real.rpow_zero,one_mul,prefixD,mul_pow, + ← pow_mul,show 201 = 1 + 2 * 100 from rfl,pow_add,pow_one,mul_left_comm] using hn + +lemma prefixTemplateFactor_le_D_power (C : ℝ) (k : ℕ) (hk : 0 < k) : + ∀ᶠ n : ℕ in atTop, prefixTemplateFactor n C ≤ prefixD n ^ k := by + have he : 0 < (k : ℝ) / 1000 := div_pos (Nat.cast_pos.mpr hk) (by norm_num) + filter_upwards [prefixTemplateFactor_subpower C he zero_lt_one, + prefixD_eventual_envelope,eventually_ge_atTop (1 : ℕ)] with n hκ hD hn + have hn0 : 0 ≤ (n : ℝ) := Nat.cast_nonneg n + have hm : ((n : ℝ) ^ (1/1000 : ℝ))^k ≤ prefixD n ^ k := + pow_le_pow_left₀ (Real.rpow_nonneg hn0 _) hD.1 _ + have hid : ((n : ℝ) ^ (1/1000 : ℝ))^k = (n : ℝ) ^ ((k : ℝ)/1000) := by + rw [← Real.rpow_natCast,← Real.rpow_mul hn0] + congr 1 + ring + rw [hid] at hm + apply le_trans _ hm + simpa only [one_mul] using hκ + +theorem prefix_long_suppression (C : ℝ) : ∀ᶠ n : ℕ in atTop, + prefixTemplateFactor n C ≤ (2 * prefixD n)^100 / prefixD n^50 := by + filter_upwards [prefixTemplateFactor_le_D_power C 50 (by norm_num), + prefix_scales_eventually_pos] with n hκ hp + have hD : 0 < prefixD n := by linarith [hp.2] + apply (le_div_iff₀ (pow_pos hD 50)).mpr + calc + _ ≤ prefixD n^50 * prefixD n^50 := mul_le_mul_of_nonneg_right hκ (by positivity) + _ = prefixD n^100 := by rw [← pow_add] + _ ≤ (2 * prefixD n)^100 := + pow_le_pow_left₀ hD.le (by linarith) _ + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/RelativeScaleBudgetLog.lean b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/RelativeScaleBudgetLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..e7cd8cd1e7ccf3e6d4ca00b25d822bf4df619ccc --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Asymptotics/RelativeScaleBudgetLog.lean @@ -0,0 +1,53 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.RelativeScaleBudget + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem relativeScaleBudget_le_log (s : ℕ → ℝ) (T : ℕ) + (hs : ∀ k ≤ T, 0 < s k) + (hdec : ∀ k < T, s (k+1) ≤ s k) + (hratio : ∀ k < T, s k ≤ 2*s (k+1)) : + relativeScaleBudget s T ≤ 2*Real.log (s 0/s T) := by + have hsingle {r : ℝ} (h1 : 1 ≤ r) (h2 : r ≤ 2) : r-1 ≤ 2*Real.log r := by + have hr : 0 < r := lt_of_lt_of_le zero_lt_one h1 + have hi : 0 ≤ 1-r⁻¹ := sub_nonneg.mpr ((inv_le_one₀ hr).mpr h1) + calc + r-1 = r*(1-r⁻¹) := by field_simp + _ ≤ 2*(1-r⁻¹) := mul_le_mul_of_nonneg_right h2 hi + _ ≤ 2*Real.log r := mul_le_mul_of_nonneg_left + (Real.one_sub_inv_le_log_of_pos hr) (by norm_num) + have htel : (∑ k ∈ Finset.range T, Real.log (s k/s (k+1))) = + Real.log (s 0/s T) := by + calc + _ = ∑ k ∈ Finset.range T, (Real.log (s k)-Real.log (s (k+1))) := by + apply Finset.sum_congr rfl + intro k hk + have hkT := Finset.mem_range.mp hk + exact Real.log_div (ne_of_gt (hs k (by omega))) + (ne_of_gt (hs (k+1) (by omega))) + _ = Real.log (s 0)-Real.log (s T) := by rw [Finset.sum_range_sub'] + _ = Real.log (s 0/s T) := (Real.log_div + (ne_of_gt (hs 0 (Nat.zero_le T))) (ne_of_gt (hs T le_rfl))).symm + rw [← htel,Finset.mul_sum] + apply Finset.sum_le_sum + intro k hk + have hkT := Finset.mem_range.mp hk + exact hsingle ((one_le_div (hs (k+1) (by omega))).mpr (hdec k hkT)) + ((div_le_iff₀ (hs (k+1) (by omega))).mpr (hratio k hkT)) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/ClockOrder.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/ClockOrder.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a8bef8fdcdf2934877593ae052b53896f9808dc --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/ClockOrder.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.TrueProbabilityMap +import OAI.Combinatorics.TriangleRemoval.Coupling.OrderLaw + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators +open scoped BigOperators ENNReal Classical + +namespace SharpTerminalLeave +section ClockOrders +variable {K V : Type*} [Fintype K] [DecidableEq K] [Fintype V] [DecidableEq V] + +theorem iid_table_relabel (ν : PMF V) (σ : Equiv.Perm K) : + (productPMF (fun _ : K => ν)).map (fun ω => ω ∘ σ.symm) = + productPMF (fun _ : K => ν) := by + ext ω + rw [PMF.map_apply, tsum_fintype] + have he : ∀ θ : K → V, ω = θ ∘ σ.symm ↔ θ = ω ∘ σ := by + intro θ + constructor + · intro h + funext k + simpa only [Function.comp_apply, σ.symm_apply_apply] using (congrFun h (σ k)).symm + · rintro rfl + funext k + simp + simp only [he, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, + productPMF_apply, Function.comp_apply] + exact Equiv.prod_comp σ (fun k => ν (ω k)) + +noncomputable def clockOrder (ω : K → ℕ) : List K := + Finset.univ.toList.mergeSort (fun a b => ω a ≤ ω b) + +theorem clockOrder_enumerates (ω : K → ℕ) : + Enumerates Finset.univ (clockOrder ω) := by + have hp := List.mergeSort_perm Finset.univ.toList (fun a b => ω a ≤ ω b) + refine ⟨hp.nodup_iff.mpr (Finset.nodup_toList _), ?_⟩ + apply Finset.eq_univ_of_forall + intro k + simp only [List.mem_toFinset] + exact hp.mem_iff.mpr (Finset.mem_toList.mpr (Finset.mem_univ _)) + +omit [DecidableEq K] in +theorem clockOrder_pairwise (ω : K → ℕ) : + (clockOrder ω).Pairwise (fun a b => ω a ≤ ω b) := by + let : Std.Total (fun a b : K => ω a ≤ ω b) := ⟨fun a b => le_total _ _⟩ + let : IsTrans K (fun a b : K => ω a ≤ ω b) := ⟨fun _ _ _ => le_trans⟩ + exact List.pairwise_mergeSort' _ _ + +theorem clockOrder_relabel (ω : K → ℕ) (hω : Function.Injective ω) + (σ : Equiv.Perm K) : clockOrder (ω ∘ σ.symm) = (clockOrder ω).map σ := by + let ρ := ω ∘ σ.symm + let : Std.Antisymm (fun a b : K => ρ a ≤ ρ b) := + ⟨fun a b hab hba => σ.symm.injective (hω (le_antisymm hab hba))⟩ + have ha := clockOrder_enumerates ρ + have hb := enumerates_map_perm (clockOrder_enumerates ω) σ + have hp : (clockOrder ρ).Perm ((clockOrder ω).map σ) := + List.perm_of_nodup_nodup_toFinset_eq ha.1 hb.1 (ha.2.trans hb.2.symm) + apply hp.eq_of_pairwise' (clockOrder_pairwise ρ) + rw [List.pairwise_map] + simpa only [ρ, Function.comp_apply, σ.symm_apply_apply] using clockOrder_pairwise ω + +theorem iid_random_relabel (ν : PMF V) : + (productPMF (fun _ : K => ν)).bind (fun ω => + (PMF.uniformOfFintype (Equiv.Perm K)).map (fun σ : Equiv.Perm K => ω ∘ σ.symm)) = + productPMF (fun _ : K => ν) := by + change (productPMF (fun _ : K => ν)).bind (fun ω => + (PMF.uniformOfFintype (Equiv.Perm K)).bind + (fun σ => PMF.pure (ω ∘ σ.symm))) = _ + rw [PMF.bind_comm] + change (PMF.uniformOfFintype (Equiv.Perm K)).bind (fun σ => + (productPMF (fun _ : K => ν)).map (fun ω => ω ∘ σ.symm)) = _ + simp only [iid_table_relabel, PMF.bind_const] + +theorem clock_order_error (N : ℕ) [NeZero N] (F : List K → Bool) : + |trueProbability ((productPMF (gridPriorities (τ := K) N)).map + (fun ω => F (clockOrder (fun k => (ω k).val)))) - + trueProbability ((orderLaw (Fintype.card K) Finset.univ).map F)| ≤ + (Fintype.card K : ℝ) ^ 2 / N := by + classical + let p := productPMF (gridPriorities (τ := K) N) + let u := PMF.uniformOfFintype (Equiv.Perm K) + let q := p.bind (fun ω => u.map (fun σ => (ω, σ))) + let b₁ : (K → Fin N) × Equiv.Perm K → Bool := + fun z => F (clockOrder (fun k => (z.1 (z.2.symm k)).val)) + let b₂ : (K → Fin N) × Equiv.Perm K → Bool := + fun z => F ((clockOrder (fun k => (z.1 k).val)).map z.2) + let bad : (K → Fin N) × Equiv.Perm K → Bool := + fun z => decide (¬Function.Injective z.1) + have hagrees : ∀ z ∈ q.support, bad z = false → b₁ z = b₂ z := by + intro z _ hz + have hinj : Function.Injective z.1 := by simpa [bad] using hz + have hinj' : Function.Injective (fun k => (z.1 k).val) := + Fin.val_injective.comp hinj + exact congrArg F (clockOrder_relabel _ hinj' z.2) + have h₁ : q.map b₁ = p.map (fun ω => F (clockOrder (fun k => (ω k).val))) := by + have hh := congrArg (fun r : PMF (K → Fin N) => + r.map (fun ω => F (clockOrder (fun k => (ω k).val)))) + (iid_random_relabel (K := K) (PMF.uniformOfFintype (Fin N))) + simp only [q, PMF.map_bind, PMF.map_comp, b₁, Function.comp_def] + change (p.bind (fun ω => u.map (fun σ : Equiv.Perm K => + F (clockOrder (fun k => (ω (σ.symm k)).val))))) = + p.map (fun ω => F (clockOrder (fun k => (ω k).val))) + rw [show p = productPMF (fun _ : K => PMF.uniformOfFintype (Fin N)) from rfl] + simpa only [PMF.map_bind, PMF.map_comp, Function.comp_def, u] using hh + have h₂ : q.map b₂ = (orderLaw (Fintype.card K) Finset.univ).map F := by + have hh : ∀ ω : K → Fin N, + u.map (fun σ : Equiv.Perm K => (clockOrder (fun k => (ω k).val)).map σ) = + orderLaw (Fintype.card K) Finset.univ := by + intro ω + exact uniform_relabel_eq_orderLaw _ le_rfl _ (clockOrder_enumerates _) + simp only [q, PMF.map_bind, PMF.map_comp, b₂, Function.comp_def] + have hr : ∀ ω : K → Fin N, + u.map (fun σ : Equiv.Perm K => F ((clockOrder (fun k => (ω k).val)).map σ)) = + (orderLaw (Fintype.card K) Finset.univ).map F := by + intro ω + simpa only [PMF.map_comp, Function.comp_def] using congrArg (fun r => r.map F) (hh ω) + simp only [hr, PMF.bind_const] + have hb : q.map bad = p.map (fun ω => decide (¬Function.Injective ω)) := by + simp only [q, PMF.map_bind, PMF.map_comp, bad, Function.comp_def] + change p.bind (fun ω => u.bind (fun _ => PMF.pure (decide (¬Function.Injective ω)))) = _ + simp only [PMF.bind_const] + rfl + have hle := boolean_coupling_bound q b₁ b₂ bad hagrees + rw [h₁, h₂, hb] at hle + exact hle.trans (grid_table_ties_bound N) + +end ClockOrders +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/GridUniformError.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/GridUniformError.lean new file mode 100644 index 0000000000000000000000000000000000000000..f031666841966b93f27b1006b15636f880d5281a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/GridUniformError.lean @@ -0,0 +1,102 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Stability.GridCavityError + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave +section GridRowBounds +variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def gridUniformError (_H : τ → Finset ι) : ℝ := + ((Fintype.card τ : ℝ)^2 * Fintype.card ι) * + Real.exp ((Fintype.card τ : ℝ) * Fintype.card ι) + +omit [DecidableEq ι] [DecidableEq τ] in +lemma gridUniformError_nonneg (H : τ → Finset ι) : 0 ≤ gridUniformError H := by + unfold gridUniformError + positivity + +lemma gridMessage_uniform_error (H : τ → Finset ι) (N : ℕ) [NeZero N] + (k : ℕ) (hk : k ≤ N) (e : ι) (p : Option τ) : + |gridMessage H N N k e p - cavityLimit H e p ((k : ℝ)/N)| ≤ + gridUniformError H / N := by + have h := (gridCavityError_coord H N k e p).trans (gridCavityError_bound H N k hk) + simpa only [gridUniformError,div_eq_mul_inv,mul_assoc,mul_comm,mul_left_comm] using h + +noncomputable def gridCandidateFailure (H : τ → Finset ι) (N : ℕ) [NeZero N] + (k : ℕ) (e : ι) (T : τ) : ℝ := + 1 - (1/(N : ℝ)) * ∑ j ∈ Finset.range k, + ∏ f ∈ (H T).erase e, gridMessage H N N j f (some T) + +lemma gridCandidateFailure_error (H : τ → Finset ι) (N : ℕ) [NeZero N] + (k : ℕ) (hk : k ≤ N) (e : ι) (T : τ) : + |gridCandidateFailure H N k e T - + (1-messageIntegral H (cavityLimit H) e T ((k : ℝ)/N))| ≤ + ((Fintype.card ι : ℝ)*gridUniformError H + + (Fintype.card ι : ℝ)*Fintype.card τ)/N := by + have hN : (0 : ℝ) < N := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne N) + have hE : 0 ≤ gridUniformError H / N := div_nonneg (gridUniformError_nonneg H) hN.le + have hs : (∑ j ∈ Finset.range k, gridCavityError H N j) ≤ gridUniformError H := by + calc + _ ≤ ∑ _j ∈ Finset.range k, gridUniformError H / N := by + apply Finset.sum_le_sum + intro j hj + have hh := gridCavityError_bound H N j ((Finset.mem_range.mp hj).le.trans hk) + simpa only [gridUniformError,div_eq_mul_inv,mul_assoc,mul_comm,mul_left_comm] using hh + _ = (k : ℝ) * (gridUniformError H / N) := by simp + _ ≤ (N : ℝ) * (gridUniformError H / N) := + mul_le_mul_of_nonneg_right (by exact_mod_cast hk) hE + _ = gridUniformError H := by field_simp + unfold gridCandidateFailure + rw [sub_sub_sub_cancel_left,abs_sub_comm] + calc + _ ≤ ((Fintype.card ι : ℝ)/N) * ∑ j ∈ Finset.range k, gridCavityError H N j + + ((Fintype.card ι : ℝ)*Fintype.card τ)/N := + grid_message_integral_error H N k hk e T + _ ≤ ((Fintype.card ι : ℝ)/N)*gridUniformError H + + ((Fintype.card ι : ℝ)*Fintype.card τ)/N := by gcongr + _ = _ := by ring + +lemma gridAnswer_uniform_error (H : τ → Finset ι) (N : ℕ) [NeZero N] + (k : ℕ) (hk : k ≤ N) (focus : Finset ι) (p : Option τ) : + |gridAnswerProbability H N N k focus p - + ∏ e ∈ focus, cavityLimit H e p ((k : ℝ)/N)| ≤ + (focus.card : ℝ)*gridUniformError H/N := by + rw [gridAnswerProbability_factor] + calc + _ ≤ ∑ e ∈ focus, |gridMessage H N N k e p - cavityLimit H e p ((k : ℝ)/N)| := + abs_prod_sub_prod_le_sum _ _ _ (fun e _ => gridMessage_mem_unit H N N k e p) + (fun e _ => cavityLimit_mem_unit H e p _) + _ ≤ ∑ _e ∈ focus, gridUniformError H/N := + Finset.sum_le_sum (fun e _ => gridMessage_uniform_error H N k hk e p) + _ = _ := by simp; ring + +omit [Fintype ι] in +lemma gridCandidateFailure_product (H : τ → Finset ι) (N : ℕ) [NeZero N] + (k : ℕ) (hk : k ≤ N) (focus : Finset ι) (p : Option τ) : + (∏ a : gridCandidates H focus p, gridCandidateFailure H N k a.val.1 a.val.2) = + gridAnswerProbability H N N k focus p := by + change (∏ a : gridCandidates H focus p, + (fun a : ι × τ => gridCandidateFailure H N k a.1 a.2) a.val) = _ + rw [Finset.prod_coe_sort (gridCandidates H focus p) + (fun a : ι × τ => gridCandidateFailure H N k a.1 a.2), + prod_gridCandidates,gridAnswerProbability_factor] + apply Finset.prod_congr rfl + intro e _ + exact (gridMessage_exact_range H N k hk e p).symm + +end GridRowBounds +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/HyperScanAction.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/HyperScanAction.lean new file mode 100644 index 0000000000000000000000000000000000000000..9049a217a14e90ca141e664c8ef762e896aa9580 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/HyperScanAction.lean @@ -0,0 +1,132 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Coupling.ClockOrder +import OAI.Combinatorics.TriangleRemoval.Process.LevelDeletes + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators +open scoped BigOperators ENNReal Classical + +namespace SharpTerminalLeave +section GenericClockScan +variable {ι τ : Type*} [DecidableEq ι] [Fintype τ] [DecidableEq τ] + +def hyperScanAction (H : τ → Finset ι) (G : Finset ι) (T : τ) : Finset ι := + if H T ⊆ G then G \ H T else G + +def hyperScan (H : τ → Finset ι) (G : Finset ι) (as : List τ) : Finset ι := + as.foldl (hyperScanAction H) G + +omit [Fintype τ] [DecidableEq τ] in +theorem hyperScan_append (H : τ → Finset ι) (G : Finset ι) (as bs : List τ) : + hyperScan H G (as ++ bs) = hyperScan H (hyperScan H G as) bs := + List.foldl_append + +omit [Fintype τ] [DecidableEq τ] in +@[simp] theorem hyperScan_singleton (H : τ → Finset ι) (G : Finset ι) (T : τ) : + hyperScan H G [T] = hyperScanAction H G T := rfl + +omit [Fintype τ] [DecidableEq τ] in +theorem hyperScanAction_subset (H : τ → Finset ι) (G : Finset ι) (T : τ) : + hyperScanAction H G T ⊆ G := by + unfold hyperScanAction + split_ifs + · exact Finset.sdiff_subset + · exact Finset.Subset.refl G + +omit [DecidableEq ι] [Fintype τ] [DecidableEq τ] in +theorem sorted_filter_lt_succ (ω : τ → ℕ) (as : List τ) + (hs : as.Pairwise (fun a b => ω a ≤ ω b)) (k : ℕ) : + as.filter (fun a => ω a < k + 1) = + as.filter (fun a => ω a < k) ++ as.filter (fun a => ω a = k) := by + induction as with + | nil => rfl + | cons a as ih => + obtain ⟨hle, hs⟩ := List.pairwise_cons.mp hs + by_cases hlt : ω a < k + · have hne : ω a ≠ k := by omega + have hlt' : ω a < k + 1 := by omega + simp only [List.filter_cons, decide_eq_true hlt, decide_eq_true hlt', + decide_eq_false hne, Bool.false_eq_true, ↓reduceIte, List.cons_append, ih hs] + · by_cases heq : ω a = k + · have hn : as.filter (fun b => ω b < k) = [] := by + apply List.filter_eq_nil_iff.mpr + intro b hb + have h := hle b hb + simpa only [Bool.decide_iff] using (show ¬ω b < k by omega) + simp only [List.filter_cons, decide_eq_false hlt, decide_eq_true heq, + show decide (ω a < k + 1) = true by simp [heq], Bool.false_eq_true, ↓reduceIte, + ih hs, hn, List.nil_append] + · have hn : ¬ω a < k + 1 := by omega + simp only [List.filter_cons, decide_eq_false hlt, decide_eq_false heq, + decide_eq_false hn, Bool.false_eq_true, ↓reduceIte, ih hs] + +omit [DecidableEq ι] in +theorem clockOrder_level_singleton (ω : τ → ℕ) (hω : Function.Injective ω) (T : τ) : + (clockOrder ω).filter (fun a => ω a = ω T) = [T] := by + have hd := (clockOrder_enumerates ω).1.filter (fun a => decide (ω a = ω T)) + apply List.perm_singleton.mp + apply List.perm_of_nodup_nodup_toFinset_eq hd (by simp) + ext a + simp only [List.mem_toFinset, List.mem_filter, Bool.decide_iff, + List.mem_singleton, hω.eq_iff] + constructor + · exact And.right + · intro ha + exact ⟨(enumerates_mem (clockOrder_enumerates ω) a).mpr (Finset.mem_univ _), ha⟩ + +omit [DecidableEq τ] in +theorem levelDeletes_one (H : τ → Finset ι) (ω : τ → ℕ) + (hω : Function.Injective ω) (G : Finset ι) (T : τ) : + levelDeletes H ω G (ω T) = if H T ⊆ G then H T else ∅ := by + ext e + simp only [mem_levelDeletes, hω.eq_iff, exists_eq_left] + by_cases hs : H T ⊆ G <;> simp [hs] + +theorem timeScan_eq_hyperScan_prefix (H : τ → Finset ι) (ω : τ → ℕ) + (hω : Function.Injective ω) (E : Finset ι) (k : ℕ) : + timeScan H ω E k = + hyperScan H E ((clockOrder ω).filter (fun T => ω T < k)) := by + induction k with + | zero => simp [timeScan, hyperScan] + | succ k ih => + rw [timeScan, ih, sorted_filter_lt_succ ω _ (clockOrder_pairwise ω) k] + by_cases he : ∃ T, ω T = k + · obtain ⟨T, rfl⟩ := he + rw [clockOrder_level_singleton ω hω T, levelDeletes_one H ω hω] + rw [hyperScan_append, hyperScan_singleton] + unfold hyperScanAction + split_ifs <;> simp + · have hn : (clockOrder ω).filter (fun T => ω T = k) = [] := by + apply List.filter_eq_nil_iff.mpr + intro T _ + simpa only [Bool.decide_iff] using (show ¬ω T = k from fun h => he ⟨T,h⟩) + have hd : ∀ G : Finset ι, levelDeletes H ω G k = ∅ := by + intro G + ext e + simp only [mem_levelDeletes, Finset.notMem_empty, iff_false, not_exists, + not_and] + intro T hT + exact False.elim (he ⟨T, hT⟩) + rw [hn, List.append_nil, hd, Finset.sdiff_empty] + +theorem timeScan_eq_hyperScan (H : τ → Finset ι) (ω : τ → ℕ) + (hω : Function.Injective ω) (E : Finset ι) (N : ℕ) (hN : ∀ T, ω T < N) : + timeScan H ω E N = hyperScan H E (clockOrder ω) := by + rw [timeScan_eq_hyperScan_prefix H ω hω E N] + congr 1 + apply List.filter_eq_self.mpr + intro T _ + exact decide_eq_true (hN T) + +end GenericClockScan +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/InitialAssignmentSetBound.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/InitialAssignmentSetBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..a575cc1ec30509a1881f3ef3ebed48bd1632d8ce --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/InitialAssignmentSetBound.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Embeddings.RestrictLabel +import OAI.Combinatorics.TriangleRemoval.Embeddings.SuffixTemplate +import OAI.Combinatorics.TriangleRemoval.Process.InitialAssignmentSet +import OAI.Combinatorics.TriangleRemoval.Process.RootClosers +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEmbeddingsAfterRoots +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraphDegree + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N n : ℕ} (B : BirthGraph N) + +theorem initialAssignmentSet_bound_unordered {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (hsmall : (n : ℝ)^(-c) ≤ 1) + (hp : 0 ≤ prefixDensity n) (r k : ℕ) (hrk : 2*r ≤ k) (hk : k ≤ N) + (hroot : (B.rootClosers (2*r)).card = r) + (hborn : ∀ v : Fin N, 2*r ≤ v.val → (B.older v).card = 2) : + ((B.initialAssignmentSet G k hk).card : ℝ) ≤ + (4 * prefixM n)^r * (2 * prefixD n)^(k-2*r) := by + classical + have hD0 : 0 ≤ 2 * prefixD n := by unfold prefixD; positivity + have hΔ0 : 0 ≤ 2 * (n : ℝ) * prefixDensity n := by positivity + have hgrow := prefixEmbeddings_after_roots B.graph (lookupGraph G) (2*r) k hrk hk + (2 * prefixD n) hD0 (goodPrefix_codegree_bound hGood hsmall) + (fun i hi hN => B.two_preceding_neighbors (2*r) hborn i hi hN) + have hroots := B.prefixEmbeddings_unordered_roots (lookupGraph G) (2*r) (hrk.trans hk) + (2 * ((n : ℝ) * prefixDensity n)) (by nlinarith) + (goodPrefix_degree_bound hGood hsmall hp) + have hid : (n : ℝ) * (2 * ((n : ℝ) * prefixDensity n)) = 4 * prefixM n := by + unfold prefixM + ring + have hrsub : 2*r-r = r := by omega + simp only [Fintype.card_fin,hroot,hrsub] at hroots + rw [← mul_pow,hid] at hroots + exact (Nat.cast_le.mpr (B.initialAssignmentSet_card G k hk)).trans + (hgrow.trans (mul_le_mul_of_nonneg_right hroots (pow_nonneg hD0 _))) + +theorem long_witness_count_unordered {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (hsmall : (n : ℝ)^(-c) ≤ 1) + (r k : ℕ) (hrk : 2*r ≤ k) (hk : k ≤ N) + (hroot : (B.rootClosers (2*r)).card = r) + (hborn : ∀ v : Fin N, 2*r ≤ v.val → (B.older v).card = 2) + {a b : Fin N} (hab : a ≠ b) (hne : ¬ B.graph.Adj a b) + (hmark : k ≤ a.val ∨ k ≤ b.val) + (hc : B.Covered (Finset.univ.filter (fun x => k ≤ x.val)) a b) + (hcap : 3 * (N-k) + 1 ≤ prefixTemplateCap) + (hp : 0 ≤ prefixDensity n) (hp1 : prefixDensity n ≤ 1) (hD : 1 ≤ prefixD n) + (hscale : (n : ℝ)^(N-k) * prefixDensity n ^ (2*(N-k)+1) ≤ 1) : + ((graphEmbeddingSet (insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ)) G).card : ℝ) ≤ + prefixTemplateFactor n C * ((4 * prefixM n)^r * (2 * prefixD n)^(k-2*r)) := by + classical + let Z : Finset (Fin N) := Finset.univ.filter (fun x => k ≤ x.val) + have hZ : Z.card = N-k := by + have heq : Z = Finset.univ \ (Finset.univ.filter (fun x : Fin N => x.val < k)) := by + ext x + simp only [Z,Finset.mem_filter,Finset.mem_sdiff,Finset.mem_univ,true_and,not_lt] + rw [heq,Finset.card_sdiff_of_subset (Finset.filter_subset _ _),Finset.card_univ, + Fintype.card_fin,Fin.card_filter_val_lt,Nat.min_eq_right hk] + have hm : a ∈ Z ∨ b ∈ Z := by simpa only [Z,Finset.mem_filter,Finset.mem_univ,true_and] using hmark + have hb : ∀ v ∈ Z, (B.older v).card = 2 := by + intro v hv + exact hborn v (hrk.trans (Finset.mem_filter.mp hv).2) + have hIP : B.suffixBoundary Z a b ⊆ initialVertices N k := by + intro x hx + have hnZ := (B.mem_suffixBoundary Z a b x).mp hx |>.2 + simp only [Z,Finset.mem_filter,Finset.mem_univ,true_and,not_le] at hnZ + exact (mem_initialVertices N k x).mpr hnZ + have hcover : initialVertices N k ∪ B.suffixVertices Z a b = Finset.univ := by + apply Finset.eq_univ_iff_forall.mpr + intro x + by_cases hx : x.val < k + · exact Finset.mem_union_left _ ((mem_initialVertices N k x).mpr hx) + · exact Finset.mem_union_right _ (Finset.mem_union_left _ + (Finset.mem_filter.mpr ⟨Finset.mem_univ _,by omega⟩)) + have hEF : B.suffixEdges Z a b ⊆ + insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ) := by + apply Finset.insert_subset_insert + exact Finset.biUnion_subset_biUnion_of_subset_left _ (Finset.subset_univ Z) + have hf := graphEmbeddingSet_count_glue (B.suffixVertices Z a b) (B.suffixBoundary Z a b) + (initialVertices N k) (B.suffixEdges Z a b) _ G B.suffixEdges_subset_vertices + (B.suffixEdges_simple hab) (B.suffixBoundary_independent hm) hIP hcover hEF + (B.initialAssignmentSet G k hk) (fun φ hφ => B.initialLabel_mem G hφ k hk) + (prefixTemplateFactor n C) (by + intro ξ _ + exact B.suffixTemplate_count hGood hab hm hb hne hc (hZ ▸ hcap) hp hp1 hD + (hZ ▸ hscale) _) + have hκ : 0 ≤ prefixTemplateFactor n C := by + unfold prefixTemplateFactor + positivity + exact hf.trans (mul_le_mul_of_nonneg_left + (B.initialAssignmentSet_bound_unordered hGood hsmall hp r k hrk hk hroot hborn) hκ) + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderEmbRank.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderEmbRank.lean new file mode 100644 index 0000000000000000000000000000000000000000..a825dfdee870bfd13a5b9b8a3aec73cace2921ad --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderEmbRank.lean @@ -0,0 +1,83 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma orderEmb_rank {N : ℕ} (s : Finset (Fin N)) (i : Fin s.card) : + (s.filter (fun x => x < s.orderEmbOfFin rfl i)).card = i.val := by + have he : s.filter (fun x => x < s.orderEmbOfFin rfl i) = + (Finset.Iio i).image (s.orderEmbOfFin rfl) := by + ext x + simp only [Finset.mem_filter,Finset.mem_image,Finset.mem_Iio] + constructor + · rintro ⟨hx,hxi⟩ + obtain ⟨j,hj⟩ := (s.orderIsoOfFin rfl).surjective ⟨x,hx⟩ + have he : s.orderEmbOfFin rfl j = x := congrArg Subtype.val hj + exact ⟨j,(s.orderEmbOfFin rfl).lt_iff_lt.mp (he ▸ hxi),he⟩ + · rintro ⟨j,hji,rfl⟩ + exact ⟨s.orderEmbOfFin_mem rfl j,(s.orderEmbOfFin rfl).strictMono hji⟩ + rw [he,Finset.card_image_of_injective _ (s.orderEmbOfFin rfl).injective,Fin.card_Iio] + +lemma initial_rank {N R : ℕ} (s : Finset (Fin N)) + (hroot : ∀ x : Fin N, x.val < R → x ∈ s) (x : Fin N) (hx : x.val < R) : + ((s.orderIsoOfFin rfl).symm ⟨x,hroot x hx⟩).val = x.val := by + let i := (s.orderIsoOfFin rfl).symm ⟨x,hroot x hx⟩ + have he : s.orderEmbOfFin rfl i = x := + congrArg Subtype.val ((s.orderIsoOfFin rfl).apply_symm_apply ⟨x,hroot x hx⟩) + have hr := orderEmb_rank s i + rw [he] at hr + have hf : s.filter (fun z => z < x) = Finset.univ.filter (fun z : Fin N => z.val < x.val) := by + ext z + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + exact ⟨fun h => h.2,fun h => ⟨hroot z (h.trans hx),h⟩⟩ + rw [hf,Fin.card_filter_val_lt,Nat.min_eq_right x.isLt.le] at hr + exact hr.symm + +lemma roots_le_card {N R : ℕ} (s : Finset (Fin N)) (hR : R ≤ N) + (hroot : ∀ x : Fin N, x.val < R → x ∈ s) : R ≤ s.card := by + have hsub : Finset.univ.filter (fun z : Fin N => z.val < R) ⊆ s := by + intro z hz + exact hroot z (Finset.mem_filter.mp hz).2 + have h := Finset.card_le_card hsub + rwa [Fin.card_filter_val_lt,Nat.min_eq_right hR] at h + +lemma orderEmb_initial {N R : ℕ} (s : Finset (Fin N)) (hR : R ≤ N) + (hroot : ∀ x : Fin N, x.val < R → x ∈ s) + (i : Fin s.card) (hi : i.val < R) : (s.orderEmbOfFin rfl i).val = i.val := by + let x : Fin N := ⟨i.val,hi.trans_le hR⟩ + let j := (s.orderIsoOfFin rfl).symm ⟨x,hroot x hi⟩ + have hj : j = i := Fin.ext (initial_rank s hroot x hi) + have he := congrArg Subtype.val ((s.orderIsoOfFin rfl).apply_symm_apply ⟨x,hroot x hi⟩) + change s.orderEmbOfFin rfl j = x at he + rw [hj] at he + exact congrArg Fin.val he + +lemma orderEmb_nonroot {N R : ℕ} (s : Finset (Fin N)) + (hroot : ∀ x : Fin N, x.val < R → x ∈ s) + (i : Fin s.card) (hi : R ≤ i.val) : R ≤ (s.orderEmbOfFin rfl i).val := by + by_contra hn + have hx : (s.orderEmbOfFin rfl i).val < R := Nat.lt_of_not_ge hn + have hr := initial_rank s hroot (s.orderEmbOfFin rfl i) hx + have he : (s.orderIsoOfFin rfl).symm + ⟨s.orderEmbOfFin rfl i,hroot (s.orderEmbOfFin rfl i) hx⟩ = i := by + apply (s.orderIsoOfFin rfl).injective + simpa only [OrderIso.apply_symm_apply] using (show + (⟨s.orderEmbOfFin rfl i,hroot (s.orderEmbOfFin rfl i) hx⟩ : s) = s.orderIsoOfFin rfl i from rfl) + rw [he] at hr + omega + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderLaw.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b01b878a4a3e70d9bc23759e410aa83192a632e --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderLaw.lean @@ -0,0 +1,168 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators +open scoped BigOperators ENNReal Classical + +namespace SharpTerminalLeave +section RandomOrder +variable {K : Type*} [Fintype K] [DecidableEq K] + +noncomputable def orderLaw : ℕ → Finset K → PMF (List K) + | 0, _ => PMF.pure [] + | d + 1, C => + if h : C.Nonempty then + (PMF.uniformOfFinset C h).bind + (fun a => (orderLaw d (C.erase a)).map (List.cons a)) + else PMF.pure [] + +omit [Fintype K] in +@[simp] theorem pmf_map_cons_apply (p : PMF (List K)) (a b : K) (bs : List K) : + (p.map (List.cons a)) (b :: bs) = if a = b then p bs else 0 := by + by_cases hab : a = b + · subst b + simp [PMF.map_apply] + · simp [PMF.map_apply, hab, Ne.symm hab] + +omit [Fintype K] [DecidableEq K] in +@[simp] theorem pmf_map_cons_nil (p : PMF (List K)) (a : K) : + (p.map (List.cons a)) [] = 0 := by simp [PMF.map_apply] + +theorem orderLaw_apply_cons (d : ℕ) (C : Finset K) (hC : C.Nonempty) + (a : K) (as : List K) : + orderLaw (d + 1) C (a :: as) = + (PMF.uniformOfFinset C hC a) * orderLaw d (C.erase a) as := by + simp only [orderLaw, dite_eq_left hC, PMF.bind_apply, tsum_fintype, pmf_map_cons_apply, + mul_ite, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] + +theorem orderLaw_apply_nil (d : ℕ) (C : Finset K) (hC : C.Nonempty) : + orderLaw (d + 1) C [] = 0 := by + simp [orderLaw, hC, PMF.bind_apply] + +def Enumerates (C : Finset K) (as : List K) : Prop := as.Nodup ∧ as.toFinset = C + +omit [Fintype K] in +@[simp] theorem enumerates_nil (C : Finset K) : Enumerates C [] ↔ C = ∅ := by + simp [Enumerates, eq_comm] + +omit [Fintype K] in +@[simp] theorem enumerates_cons (C : Finset K) (a : K) (as : List K) : + Enumerates C (a :: as) ↔ a ∈ C ∧ Enumerates (C.erase a) as := by + constructor + · rintro ⟨hn, hc⟩ + have ha : a ∉ as.toFinset := by simpa using (List.nodup_cons.mp hn).1 + simp only [List.toFinset_cons] at hc + refine ⟨hc ▸ Finset.mem_insert_self _ _, (List.nodup_cons.mp hn).2, ?_⟩ + rw [← hc, Finset.erase_insert ha] + · rintro ⟨ha, hn, hc⟩ + have han : a ∉ as := by + simpa only [← List.mem_toFinset] using (hc ▸ Finset.notMem_erase a C) + refine ⟨List.nodup_cons.mpr ⟨han, hn⟩, ?_⟩ + simp only [List.toFinset_cons, hc, Finset.insert_erase ha] + +theorem orderLaw_apply (d : ℕ) (C : Finset K) (hd : C.card ≤ d) (as : List K) : + orderLaw d C as = if Enumerates C as then ((C.card.factorial : ℕ) : ℝ≥0∞)⁻¹ else 0 := by + induction d generalizing C as with + | zero => + have hC : C = ∅ := Finset.card_eq_zero.mp (by omega) + subst C + cases as with + | nil => simp [orderLaw, Enumerates] + | cons a as => simp [orderLaw, enumerates_cons] + | succ d ih => + by_cases hC : C.Nonempty + · cases as with + | nil => simp [orderLaw_apply_nil d C hC, hC.ne_empty] + | cons a as => + rw [orderLaw_apply_cons d C hC] + by_cases ha : a ∈ C + · have hcard : C.card = (C.erase a).card + 1 := (Finset.card_erase_add_one ha).symm + have hde : (C.erase a).card ≤ d := by omega + rw [ih (C.erase a) hde as, PMF.uniformOfFinset_apply_of_mem hC ha, enumerates_cons] + simp only [ha, true_and] + split_ifs with he + · rw [hcard, Nat.factorial_succ, Nat.cast_mul] + rw [ENNReal.mul_inv (Or.inr (by finiteness)) (Or.inl (by finiteness))] + · simp + · rw [PMF.uniformOfFinset_apply_of_notMem hC ha] + simp only [zero_mul, enumerates_cons, ha, false_and, ↓reduceIte] + · have hE : C = ∅ := Finset.not_nonempty_iff_eq_empty.mp hC + subst C + cases as with + | nil => simp [orderLaw, Enumerates] + | cons a as => simp [orderLaw, enumerates_cons] + +omit [Fintype K] in +theorem enumerates_mem {C : Finset K} {as : List K} (h : Enumerates C as) (a : K) : + a ∈ as ↔ a ∈ C := by rw [← List.mem_toFinset, h.2] + +omit [Fintype K] in +theorem enumerates_length {C : Finset K} {as : List K} (h : Enumerates C as) : + as.length = C.card := by rw [← h.2, List.toFinset_card_of_nodup h.1] + +theorem enumerates_map_perm {as : List K} (h : Enumerates Finset.univ as) + (σ : Equiv.Perm K) : Enumerates Finset.univ (as.map σ) := by + refine ⟨h.1.map σ.injective, ?_⟩ + apply Finset.eq_univ_of_forall + intro x + simp only [List.mem_toFinset, List.mem_map] + exact ⟨σ.symm x, (enumerates_mem h _).mpr (Finset.mem_univ _), σ.apply_symm_apply x⟩ + +theorem relabel_injective {as : List K} (h : Enumerates Finset.univ as) : + Function.Injective (fun σ : Equiv.Perm K => as.map σ) := by + intro σ ρ he + apply Equiv.ext + intro a + exact List.map_inj_left.mp he a ((enumerates_mem h _).mpr (Finset.mem_univ _)) + +theorem exists_relabel {as bs : List K} (ha : Enumerates Finset.univ as) + (hb : Enumerates Finset.univ bs) : ∃ σ : Equiv.Perm K, as.map σ = bs := by + let ea := ha.1.getEquivOfForallMemList as (fun x => + (enumerates_mem ha x).mpr (Finset.mem_univ x)) + let eb := hb.1.getEquivOfForallMemList bs (fun x => + (enumerates_mem hb x).mpr (Finset.mem_univ x)) + have hel : as.length = bs.length := (enumerates_length ha).trans (enumerates_length hb).symm + let σ := ea.symm.trans ((finCongr hel).trans eb) + refine ⟨σ, ?_⟩ + apply List.ext_get (by simpa using hel) + intro i hi hj + simp only [List.get_eq_getElem, List.getElem_map] + change σ (as.get ⟨i, by simpa using hi⟩) = bs.get ⟨i, hj⟩ + change eb (finCongr hel (ea.symm (ea ⟨i, by simpa using hi⟩))) = _ + simp only [Equiv.symm_apply_apply] + rfl + +theorem uniform_relabel_eq_orderLaw (d : ℕ) (hd : Fintype.card K ≤ d) + (as : List K) (ha : Enumerates Finset.univ as) : + (PMF.uniformOfFintype (Equiv.Perm K)).map (fun σ : Equiv.Perm K => as.map σ) = + orderLaw d Finset.univ := by + classical + apply PMF.ext + intro bs + rw [orderLaw_apply d Finset.univ (by simpa using hd) bs, PMF.map_apply, tsum_fintype] + by_cases hb : Enumerates Finset.univ bs + · obtain ⟨σ, rfl⟩ := exists_relabel ha hb + have he : ∀ ρ : Equiv.Perm K, as.map σ = as.map ρ ↔ ρ = σ := by + intro ρ + exact ⟨fun h => (relabel_injective ha h).symm, fun h => h ▸ rfl⟩ + simp only [he, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, + PMF.uniformOfFintype_apply, Fintype.card_perm, hb, Finset.card_univ] + · have he : ∀ ρ : Equiv.Perm K, bs ≠ as.map ρ := by + intro ρ hρ + apply hb + rw [hρ] + exact enumerates_map_perm ha ρ + simp only [he, ↓reduceIte, Finset.sum_const_zero, hb] + +end RandomOrder +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderedSuffix.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderedSuffix.lean new file mode 100644 index 0000000000000000000000000000000000000000..236ebde05dffb1e490ad9cccb052e55530076121 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderedSuffix.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Coupling.OrderEmbRank + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def orderedSuffix {N : ℕ} (S : Finset (Fin N)) (R : ℕ) : Finset (Fin N) := + S.filter (fun x => R ≤ x.val) + +lemma prefix_suffix_card {N R : ℕ} (S : Finset (Fin N)) (hR : R ≤ N) + (hroot : ∀ x : Fin N, x.val < R → x ∈ S) : + S.card = R + (orderedSuffix S R).card := by + have he : S.filter (fun x => x.val < R) = Finset.univ.filter (fun x => x.val < R) := by + ext x + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + exact ⟨And.right,fun hx => ⟨hroot x hx,hx⟩⟩ + have hh := Finset.card_filter_add_card_filter_not (s := S) (fun x => x.val < R) + rw [he,Fin.card_filter_val_lt,Nat.min_eq_right hR] at hh + simpa only [orderedSuffix,Nat.not_lt] using hh.symm + +lemma suffix_full_rank {N R : ℕ} (S : Finset (Fin N)) (hR : R ≤ N) + (hroot : ∀ x : Fin N, x.val < R → x ∈ S) + (i : Fin (orderedSuffix S R).card) : + ((S.orderIsoOfFin rfl).symm + ⟨(orderedSuffix S R).orderEmbOfFin rfl i, + (Finset.mem_filter.mp ((orderedSuffix S R).orderEmbOfFin_mem rfl i)).1⟩).val = R+i.val := by + let T := orderedSuffix S R + let v := T.orderEmbOfFin rfl i + have hvT : v ∈ T := T.orderEmbOfFin_mem rfl i + have hvR : R ≤ v.val := (Finset.mem_filter.mp hvT).2 + have hvS : v ∈ S := (Finset.mem_filter.mp hvT).1 + let j := (S.orderIsoOfFin rfl).symm ⟨v,hvS⟩ + have hj : S.orderEmbOfFin rfl j = v := + congrArg Subtype.val ((S.orderIsoOfFin rfl).apply_symm_apply _) + have hr := orderEmb_rank S j + rw [hj] at hr + have he : (S.filter (fun x => x < v)).filter (fun x => x.val < R) = + Finset.univ.filter (fun x => x.val < R) := by + ext x + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + constructor + · exact And.right + · intro hx + exact ⟨⟨hroot x hx,(show x.val < v.val from lt_of_lt_of_le hx hvR)⟩,hx⟩ + have hn : (S.filter (fun x => x < v)).filter (fun x => ¬ x.val < R) = + T.filter (fun x => x < v) := by + ext x + simp only [T,orderedSuffix,Finset.mem_filter,Nat.not_lt] + exact ⟨fun h => ⟨⟨h.1.1,h.2⟩,h.1.2⟩,fun h => ⟨⟨h.1.1,h.2⟩,h.1.2⟩⟩ + have hh := Finset.card_filter_add_card_filter_not + (s := S.filter (fun x => x < v)) (fun x => x.val < R) + rw [he,hn,Fin.card_filter_val_lt,Nat.min_eq_right hR,hr] at hh + have ht := orderEmb_rank T i + change (T.filter (fun x => x < v)).card = i.val at ht + rw [ht] at hh + exact hh.symm + +def suffixFullIndex {N R : ℕ} (S : Finset (Fin N)) (hR : R ≤ N) + (hroot : ∀ x : Fin N, x.val < R → x ∈ S) + (i : Fin (orderedSuffix S R).card) : Fin S.card := + ⟨R+i.val,by rw [prefix_suffix_card S hR hroot]; omega⟩ + +lemma suffix_full_embedding {N R : ℕ} (S : Finset (Fin N)) (hR : R ≤ N) + (hroot : ∀ x : Fin N, x.val < R → x ∈ S) + (i : Fin (orderedSuffix S R).card) : + S.orderEmbOfFin rfl (suffixFullIndex S hR hroot i) = + (orderedSuffix S R).orderEmbOfFin rfl i := by + have hh := suffix_full_rank S hR hroot i + have he : (S.orderIsoOfFin rfl).symm + ⟨(orderedSuffix S R).orderEmbOfFin rfl i, + (Finset.mem_filter.mp ((orderedSuffix S R).orderEmbOfFin_mem rfl i)).1⟩ = + suffixFullIndex S hR hroot i := Fin.ext hh + rw [← he] + exact congrArg Subtype.val ((S.orderIsoOfFin rfl).apply_symm_apply _) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderedWeightMono.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderedWeightMono.lean new file mode 100644 index 0000000000000000000000000000000000000000..bcfee56538a2136b1c1db41b79835d7a0f49ce64 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/OrderedWeightMono.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PairRequired + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma orderedWeight_mono {w : ℕ → ℝ} (hw : ∀ t, 0 ≤ w t) (j : ℕ) : + Monotone (orderedWeight w j) := by + cases j with + | zero => intro a b _; rfl + | succ j => + intro a b hab + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono hab) + (fun t _ _ => mul_nonneg (hw t) (orderedWeight_nonneg hw _ _)) + +lemma pairRequired_common_shift {A : Type*} [DecidableEq A] (a : A) + (p q address : List A) : + pairRequired (a :: p) (a :: q) (address ++ [a]) = pairRequired p q address := by + simp only [pairRequired,pathRequired_shift] + +section SpineVisitation +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +lemma pair_common_required_candidates (H : τ → Finset ι) (focus : Finset ι) + (parent : Option τ) (a : gridCandidates H focus parent) (p q : List (ι × τ)) : + requiredCandidates H (pairRequired (a.val :: p) (a.val :: q)) [] focus parent = {a} := by + rw [pair_required_candidates] + exact Finset.pair_eq_singleton a + +lemma marked_pair_common_child (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d : ℕ) (focus : Finset ι) (parent : Option τ) + (a : gridCandidates H focus parent) (p q : List (ι × τ)) (u : Fin N) : + markedChildKernel H N (pairRequired (a.val :: p) (a.val :: q)) d [] focus parent a u = + ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N (pairRequired p q) d u.val [] + ((H a.val.2).erase a.val.1) (some a.val.2)) := by + unfold markedChildKernel + change ExposureTree.fresh _ (markedGridQueryDepth H N _ d u.val ([] ++ [a.val]) _ _) = _ + rw [markedGridQueryDepth_readdress] + have he : (fun l => pairRequired (a.val :: p) (a.val :: q) (l ++ [a.val])) = + pairRequired p q := by + funext l + exact pairRequired_common_shift _ _ _ _ + rw [he] + +theorem pairVisitProbability_spine (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 0 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (spine : List (ι × τ)) (a b' : ι × τ) (hab : a ≠ b') (as bs : List (ι × τ)) + (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) + (e : ι) (T : τ) (he : e ∈ H T) + (ha : LegalQueryPath H ((H T).erase e) (some T) (spine ++ a :: as)) + (hb' : LegalQueryPath H ((H T).erase e) (some T) (spine ++ b' :: bs)) + (halen : spine.length + (as.length+1) ≤ d) (hblen : spine.length + (bs.length+1) ≤ d) : + pairVisitProbability H N d k ((H T).erase e) (some T) + (spine ++ a :: as) (spine ++ b' :: bs) ≤ + C * orderedWeight (fun t => (2/(N : ℝ))*b t) spine.length k * + orderedWeight (fun t => (2/(N : ℝ))*b t) (as.length+1) k * + orderedWeight (fun t => (2/(N : ℝ))*b t) (bs.length+1) k := by + have hw : ∀ t, 0 ≤ (2/(N : ℝ))*b t := fun t => mul_nonneg (by positivity) (hb t) + induction spine generalizing d k e T with + | nil => + cases d with + | zero => simp only [List.length_nil] at halen; omega + | succ d => + obtain ⟨ha,hat⟩ := ha + obtain ⟨hb',hbt⟩ := hb' + let aa : gridCandidates H ((H T).erase e) (some T) := ⟨a,ha⟩ + let bb : gridCandidates H ((H T).erase e) (some T) := ⟨b',hb'⟩ + have hne : aa ≠ bb := fun h => hab (congrArg Subtype.val h) + simpa only [List.nil_append,List.length_nil,orderedWeight,mul_one] using + pairVisitProbability_fork H N b hb hq C hC hlower d k hkd hkN e T he aa bb hne as bs + hat hbt (by simp only [List.length_nil] at halen; omega) + (by simp only [List.length_nil] at hblen; omega) + | cons z zs ih => + cases d with + | zero => simp only [List.length_cons] at halen; omega + | succ d => + obtain ⟨hz,haz⟩ := ha + obtain ⟨_,hbz⟩ := hb' + let zz : gridCandidates H ((H T).erase e) (some T) := ⟨z,hz⟩ + have hzc := (Finset.mem_filter.mp hz).2.1 + have hs := markedQuery_single_path H N + (pairRequired (z :: (zs ++ a :: as)) (z :: (zs ++ b' :: bs))) d k hkd hkN [] + ((H T).erase e) (some T) zz (pair_common_required_candidates H _ _ zz _ _) b + (fun t ht => hq.1 t (by omega)) (fun t ht => hq.2 t (by omega) e T he) + let A := orderedWeight (fun t => (2/(N : ℝ))*b t) (as.length+1) k + let B := orderedWeight (fun t => (2/(N : ℝ))*b t) (bs.length+1) k + have hA : 0 ≤ A := orderedWeight_nonneg hw _ _ + have hB : 0 ≤ B := orderedWeight_nonneg hw _ _ + calc + _ ≤ (1/(N : ℝ))*∑ u : Fin N, if u.val < k then + markedGood (markedChildKernel H N + (pairRequired (z :: (zs ++ a :: as)) (z :: (zs ++ b' :: bs))) d [] + ((H T).erase e) (some T) zz u)*(2*b u.val) else 0 := hs + _ ≤ (1/(N : ℝ))*∑ u : Fin N, if u.val < k then + (C*orderedWeight (fun t => (2/(N : ℝ))*b t) zs.length u.val*A*B)*(2*b u.val) + else 0 := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro u _ + by_cases hu : u.val < k + · simp only [hu,↓reduceIte] + apply mul_le_mul_of_nonneg_right _ (mul_nonneg (by norm_num) (hb _)) + rw [marked_pair_common_child H N d _ _ zz _ _ u] + have hi := ih d u.val (by omega) u.isLt.le z.1 z.2 hzc haz hbz + (by simp only [List.length_cons] at halen; omega) + (by simp only [List.length_cons] at hblen; omega) + apply hi.trans + apply mul_le_mul + · apply mul_le_mul_of_nonneg_left + · exact orderedWeight_mono hw _ hu.le + · exact mul_nonneg hC (orderedWeight_nonneg hw _ _) + · exact orderedWeight_mono hw _ hu.le + · exact orderedWeight_nonneg hw _ _ + · exact mul_nonneg (mul_nonneg hC (orderedWeight_nonneg hw _ _)) hA + · simp only [hu,↓reduceIte,le_refl] + _ = C*((1/(N : ℝ))*∑ u : Fin N, if u.val < k then + orderedWeight (fun t => (2/(N : ℝ))*b t) zs.length u.val*(2*b u.val) else 0)*A*B := by + simp only [Finset.mul_sum,Finset.sum_mul] + apply Finset.sum_congr rfl + intro u _ + by_cases hu : u.val < k <;> simp only [hu,↓reduceIte] <;> ring + _ = _ := by + rw [discrete_ordered_step N k hkN b zs.length] + rfl + +end SpineVisitation +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/ScanList.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/ScanList.lean new file mode 100644 index 0000000000000000000000000000000000000000..af1101ed794a90e8143345e0ad244fd2e0a875f2 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/ScanList.lean @@ -0,0 +1,42 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Coupling.OrderLaw +import OAI.Combinatorics.TriangleRemoval.Process.Finish + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators +open scoped BigOperators ENNReal Classical + +namespace SharpTerminalLeave + +def scanList {n : ℕ} (G : Graph n) (as : List (Finset (Fin n))) : Graph n := + as.foldl scanAction G + +theorem orderLaw_scanList_eq_scanLaw {n : ℕ} (d : ℕ) (G : Graph n) + (C : Finset (Finset (Fin n))) : + (orderLaw d C).map (scanList G) = scanLaw d G C := by + induction d generalizing G C with + | zero => simp [orderLaw, scanLaw, scanList, PMF.pure_map] + | succ d ih => + by_cases hC : C.Nonempty + · simp only [orderLaw, scanLaw, dite_eq_left hC, PMF.map_bind, PMF.map_comp] + congr 1 + funext t + exact ih (scanAction G t) (C.erase t) + · simp [orderLaw, scanLaw, hC, scanList, PMF.pure_map] + +theorem uniform_order_scan_eq_finish {n : ℕ} (G : Graph n) + (C : Finset (Finset (Fin n))) (hall : triangles G ⊆ C) : + (orderLaw C.card C).map (scanList G) = finish G := by + rw [orderLaw_scanList_eq_scanLaw, scanLaw_eq_finish _ _ _ le_rfl hall] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/SelectedClockLawPair.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/SelectedClockLawPair.lean new file mode 100644 index 0000000000000000000000000000000000000000..65566610156788a89f2772f308a96ab7c8580c2e --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/SelectedClockLawPair.lean @@ -0,0 +1,127 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.OrderedMarkedRowUnweighted + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +theorem selectedClockLaw_pair {K : Type*} [DecidableEq K] + (N : ℕ) [NeZero N] (a b : K) (hab : a ≠ b) (u v : Fin N) : + selectedClockLaw N {a,b} (Function.update (fun _ => v) a u) = + Function.update (Function.update (fun _ : K => PMF.uniformOfFintype (Fin N)) + a (PMF.pure u)) b (PMF.pure v) := by + funext k + by_cases hka : k = a + · subst k + simp [selectedClockLaw,hab] + · by_cases hkb : k = b + · subst k + simp [selectedClockLaw,hka] + · simp [selectedClockLaw,hka,hkb] + +theorem productPMF_split_two_uniform {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (a b : K) (hab : a ≠ b) : + productPMF (fun _ : K => PMF.uniformOfFintype (Fin N)) = + (PMF.uniformOfFintype (Fin N)).bind (fun u => + (PMF.uniformOfFintype (Fin N)).bind (fun v => + productPMF (selectedClockLaw N {a,b} (Function.update (fun _ => v) a u)))) := by + rw [productPMF_split (fun _ : K => PMF.uniformOfFintype (Fin N)) a] + congr 1 + funext u + rw [productPMF_split (Function.update (fun _ : K => PMF.uniformOfFintype (Fin N)) + a (PMF.pure u)) b,Function.update_of_ne hab.symm] + congr 1 + funext v + rw [selectedClockLaw_pair N a b hab u v] + +theorem marked_row_two_paths {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (order : List K) (horder : order.Perm Finset.univ.toList) + (a b : K) (hab : a ≠ b) (p : K → Fin N → PMF (Bool × Bool)) + (q : K → Fin N → ℝ) (deadline : ℕ) (w : ℕ → ℝ) + (hmarg : ∀ k ∉ ({a,b} : Finset K), ∀ u, markedSuccess (p k u) = q k u) + (hfactor : ∀ t < deadline, ∀ k, (7 / 8 : ℝ) ≤ prospectiveFailure N t (q k)) + (hfull : ∀ t < deadline, ∏ k, prospectiveFailure N t (q k) ≤ (9 / 8 : ℝ) * w t) : + markedGood ((productPMF (fun _ : K => PMF.uniformOfFintype (Fin N))).bind + (fun ω => markedCheck (orderedMarkedRow order {a,b} p deadline ω))) ≤ + (1 / (N : ℝ)) * ∑ u : Fin N, (1 / (N : ℝ)) * ∑ v : Fin N, + if u.val < deadline ∧ v.val < deadline then + (markedGood (p a u) * markedGood (p b v)) * (2 * w (max u.val v.val)) + else 0 := by + rw [productPMF_split_two_uniform N a b hab,PMF.bind_bind,markedGood_bind] + have hpoint : ∀ u v : Fin N, + markedGood ((productPMF (selectedClockLaw N {a,b} + (Function.update (fun _ => v) a u))).bind + (fun ω => markedCheck (orderedMarkedRow order {a,b} p deadline ω))) ≤ + if u.val < deadline ∧ v.val < deadline then + (markedGood (p a u) * markedGood (p b v)) * (2 * w (max u.val v.val)) else 0 := by + intro u v + let σ : K → Fin N := Function.update (fun _ => v) a u + have hσa : σ a = u := Function.update_self .. + have hσb : σ b = v := Function.update_of_ne hab.symm .. + by_cases huv : u.val < deadline ∧ v.val < deadline + · rw [ite_eq_left huv] + have htd : max u.val v.val < deadline := max_lt huv.1 huv.2 + have hsel : ∀ k ∈ ({a,b} : Finset K), (σ k).val < deadline := by + intro k hk + rcases Finset.mem_insert.mp hk with rfl | hk + · simpa only [hσa] using huv.1 + · have he : k = b := Finset.mem_singleton.mp hk + simpa only [he,hσb] using huv.2 + have ht : ∃ k ∈ ({a,b} : Finset K), max u.val v.val ≤ (σ k).val := by + by_cases h : u.val ≤ v.val + · exact ⟨b,by simp,by simp only [hσb,max_eq_right h,le_refl]⟩ + · exact ⟨a,by simp,by simp only [hσa,max_eq_left (le_of_not_ge h),le_refl]⟩ + have hh := orderedMarkedRow_cavity_bound N order horder {a,b} σ p q deadline + (max u.val v.val) (Nat.le_of_lt htd) hsel ht (by simp [hab]) hmarg + (w (max u.val v.val)) (hfactor _ htd) (hfull _ htd) + simpa only [Finset.prod_pair hab,hσa,hσb] using hh + · rw [ite_eq_right huv] + rw [markedGood_bind] + apply le_trans (pmfMean_mono _ (g := fun _ => 0) ?_) (by simp) + intro ω hω + have hsa := selectedClockLaw_support N {a,b} σ ω hω a (by simp) + have hsb := selectedClockLaw_support N {a,b} σ ω hω b (by simp) + by_cases hu : u.val < deadline + · have hv : deadline ≤ v.val := by omega + rw [orderedMarkedRow_forbidden order horder {a,b} p deadline ω b (by simp) + (by simpa only [hsb,hσb] using hv)] + · rw [orderedMarkedRow_forbidden order horder {a,b} p deadline ω a (by simp) + (by simpa only [hsa,hσa] using Nat.le_of_not_gt hu)] + calc + _ ≤ pmfMean (PMF.uniformOfFintype (Fin N)) (fun u => + pmfMean (PMF.uniformOfFintype (Fin N)) (fun v => + if u.val < deadline ∧ v.val < deadline then + (markedGood (p a u) * markedGood (p b v)) * (2 * w (max u.val v.val)) else 0)) := by + apply pmfMean_mono + intro u _ + rw [PMF.bind_bind,markedGood_bind] + exact pmfMean_mono _ (fun v _ => hpoint u v) + _ = _ := by + simp only [pmfMean,PMF.uniformOfFintype_apply,ENNReal.toReal_inv, + ENNReal.toReal_natCast,Fintype.card_fin,one_div,Finset.mul_sum] + +theorem max_weight_separate (w : ℕ → ℝ) (C : ℝ) + (hw : ∀ t, 0 ≤ w t) (hC : ∀ t, 1 ≤ C * w t) (u v : ℕ) : + w (max u v) ≤ C * (w u * w v) := by + rcases le_total u v with h | h + · rw [max_eq_right h] + have hh := mul_le_mul_of_nonneg_right (hC u) (hw v) + nlinarith + · rw [max_eq_left h] + have hh := mul_le_mul_of_nonneg_right (hC v) (hw u) + nlinarith + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/UniformRootAtom.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/UniformRootAtom.lean new file mode 100644 index 0000000000000000000000000000000000000000..8707eb2601aac655758e4b65f652df59ff0c0895 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/UniformRootAtom.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.FiniteMean + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +section FixedRoots +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma uniform_root_atom (G : Finset α) (hne : G.Nonempty) (e : α) : + pmfMean (PMF.uniformOfFinset G hne) (fun x => if x = e then 1 else 0) = + if e ∈ G then 1/(G.card : ℝ) else 0 := by + rw [pmfMean_uniformOfFinset] + by_cases he : e ∈ G + · simp only [he,ite_true] + rw [Finset.sum_ite_eq'] + simp [he] + · simp [he] + +lemma uniform_ordered_root_atoms (G : Finset α) (hne : G.Nonempty) (e f : α) : + pmfMean (PMF.uniformOfFinset G hne) (fun x => + pmfMean (PMF.uniformOfFinset G hne) (fun y => if x = e ∧ y = f then 1 else 0)) = + if e ∈ G ∧ f ∈ G then 1/(G.card : ℝ)^2 else 0 := by + have h (x : α) : + pmfMean (PMF.uniformOfFinset G hne) (fun y => if x = e ∧ y = f then 1 else 0) = + (if x = e then 1 else 0)*(if f ∈ G then 1/(G.card : ℝ) else 0) := by + by_cases hx : x = e + · simp only [hx,true_and,ite_true,one_mul] + exact uniform_root_atom G hne f + · simp [hx] + simp_rw [h] + rw [pmfMean_mul_const,uniform_root_atom] + by_cases he : e ∈ G <;> by_cases hf : f ∈ G <;> simp only [he,hf,ite_true,ite_false,true_and,false_and,zero_mul,mul_zero] + ring + +theorem uniform_root_set_probability_le (G : Finset α) (hne : G.Nonempty) + (E : Finset α) (hE : E.card = 2) : + pmfMean (PMF.uniformOfFinset G hne) (fun x => + pmfMean (PMF.uniformOfFinset G hne) (fun y => if ({x,y} : Finset α) = E then 1 else 0)) ≤ + 2/(G.card : ℝ)^2 := by + obtain ⟨e,f,hef,rfl⟩ := Finset.card_eq_two.mp hE + have hpt (x y : α) : (if ({x,y} : Finset α) = {e,f} then (1 : ℝ) else 0) ≤ + (if x=e ∧ y=f then 1 else 0) + (if x=f ∧ y=e then 1 else 0) := by + by_cases h : ({x,y} : Finset α) = {e,f} + · have hm : x ∈ ({e,f} : Finset α) := h ▸ Finset.mem_insert_self _ _ + have hn : y ∈ ({e,f} : Finset α) := h ▸ Finset.mem_insert_of_mem (Finset.mem_singleton_self _) + have hxy : x ≠ y := by + intro heq + subst y + have hh := congrArg Finset.card h + simp only [Finset.insert_eq_of_mem (Finset.mem_singleton_self _),Finset.card_singleton, + Finset.card_pair hef] at hh + omega + have hx : x = e ∨ x = f := by simpa only [Finset.mem_insert,Finset.mem_singleton] using hm + have hy : y = e ∨ y = f := by simpa only [Finset.mem_insert,Finset.mem_singleton] using hn + rcases hx with hx | hx <;> rcases hy with hy | hy + · exact False.elim (hxy (hx.trans hy.symm)) + · simp [hx,hy,hef] + · simp [hx,hy,hef,Finset.pair_comm] + · exact False.elim (hxy (hx.trans hy.symm)) + · simp only [h,ite_false] + split_ifs <;> norm_num + have hh : pmfMean (PMF.uniformOfFinset G hne) (fun x => + pmfMean (PMF.uniformOfFinset G hne) (fun y => if ({x,y} : Finset α) = {e,f} then 1 else 0)) ≤ + pmfMean (PMF.uniformOfFinset G hne) (fun x => + pmfMean (PMF.uniformOfFinset G hne) (fun y => + (if x=e ∧ y=f then 1 else 0)+(if x=f ∧ y=e then 1 else 0))) := by + apply pmfMean_mono + intro x _ + apply pmfMean_mono + intro y _ + exact hpt x y + simp_rw [pmfMean_add] at hh + rw [uniform_ordered_root_atoms,uniform_ordered_root_atoms] at hh + have hnon : 0 ≤ 1/(G.card : ℝ)^2 := by positivity + have htwo : 2/(G.card : ℝ)^2 = 2*(1/(G.card : ℝ)^2) := by ring + exact hh.trans (by rw [htwo]; split_ifs <;> linarith) + +end FixedRoots +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Coupling/UnitTime.lean b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/UnitTime.lean new file mode 100644 index 0000000000000000000000000000000000000000..2516530865a7c0fb3868e7ba64552e6a00596fdd --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Coupling/UnitTime.lean @@ -0,0 +1,623 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +section +open Filter MeasureTheory +open scoped BigOperators Topology BoundedContinuousFunction + +namespace SharpTerminalLeave + +def unitTime (t : ℝ) : ℝ := max 0 (min 1 t) + +theorem unitTime_nonneg (t : ℝ) : 0 ≤ unitTime t := le_max_left _ _ +theorem unitTime_le_one (t : ℝ) : unitTime t ≤ 1 := + max_le (by norm_num) (min_le_left _ _) +theorem unitTime_of_mem {t : ℝ} (ht : t ∈ Set.Icc (0 : ℝ) 1) : unitTime t = t := by + simp [unitTime, min_eq_right ht.2, max_eq_right ht.1] +theorem continuous_unitTime : Continuous unitTime := + continuous_const.max (continuous_const.min continuous_id) + +theorem abs_prod_sub_prod_le_sum {α : Type*} (s : Finset α) (f g : α → ℝ) + (hf : ∀ a ∈ s, f a ∈ Set.Icc (0 : ℝ) 1) + (hg : ∀ a ∈ s, g a ∈ Set.Icc (0 : ℝ) 1) : + |(∏ a ∈ s, f a) - ∏ a ∈ s, g a| ≤ ∑ a ∈ s, |f a - g a| := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => + have hfa := hf a (Finset.mem_insert_self _ _) + have hga := hg a (Finset.mem_insert_self _ _) + have hfs := fun a (ha : a ∈ s) => hf a (Finset.mem_insert_of_mem ha) + have hgs := fun a (ha : a ∈ s) => hg a (Finset.mem_insert_of_mem ha) + have hp : |∏ i ∈ s, f i| ≤ 1 := by + rw [abs_of_nonneg (Finset.prod_nonneg fun i hi => (hfs i hi).1)] + exact Finset.prod_le_one₀ (fun index hindex => (hfs index hindex).1) + (fun index hindex => (hfs index hindex).2) + rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.sum_insert ha] + calc + _ = |(f a - g a) * (∏ i ∈ s, f i) + + g a * ((∏ i ∈ s, f i) - ∏ i ∈ s, g i)| := by congr 1; ring + _ ≤ |f a - g a| * |∏ i ∈ s, f i| + + |g a| * |(∏ i ∈ s, f i) - ∏ i ∈ s, g i| := by + simpa only [abs_mul] using abs_add_le + ((f a - g a) * (∏ i ∈ s, f i)) + (g a * ((∏ i ∈ s, f i) - ∏ i ∈ s, g i)) + _ ≤ |f a - g a| * 1 + 1 * (∑ i ∈ s, |f i - g i|) := by + apply add_le_add + · exact mul_le_mul_of_nonneg_left hp (abs_nonneg _) + · exact mul_le_mul (by simpa only [abs_of_nonneg hga.1] using hga.2) + (ih hfs hgs) (abs_nonneg _) zero_le_one + _ = _ := by ring + +section Cavity +variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +def messageCandidates (H : τ → Finset ι) (e : ι) (parent : Option τ) : Finset τ := + Finset.univ.filter (fun T => e ∈ H T ∧ some T ≠ parent) + +noncomputable def messageIntegral (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (e : ι) (T : τ) (t : ℝ) : ℝ := + ∫ s in (0 : ℝ)..unitTime t, ∏ f ∈ (H T).erase e, q f (some T) s + +noncomputable def cavityOperator (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (e : ι) (parent : Option τ) (t : ℝ) : ℝ := + ∏ T ∈ messageCandidates H e parent, (1 - messageIntegral H q e T t) + +noncomputable def cavityDepth (H : τ → Finset ι) : ℕ → ι → Option τ → ℝ → ℝ + | 0 => fun _ _ _ => 1 + | k + 1 => cavityOperator H (cavityDepth H k) + +omit [Fintype ι] [Fintype τ] [DecidableEq τ] in +theorem continuous_message_integrand (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (hq : ∀ e p, Continuous (q e p)) (e : ι) (T : τ) : + Continuous (fun s => ∏ f ∈ (H T).erase e, q f (some T) s) := by + exact continuous_finsetProd _ (fun f _ => hq f (some T)) + +omit [Fintype ι] [Fintype τ] [DecidableEq τ] in +theorem continuous_messageIntegral (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (hq : ∀ e p, Continuous (q e p)) (e : ι) (T : τ) : + Continuous (messageIntegral H q e T) := by + exact (intervalIntegral.continuous_primitive + (fun a b => (continuous_message_integrand H q hq e T).intervalIntegrable a b) 0).comp + continuous_unitTime + +omit [Fintype ι] in +theorem continuous_cavityOperator (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (hq : ∀ e p, Continuous (q e p)) (e : ι) (p : Option τ) : + Continuous (cavityOperator H q e p) := by + exact continuous_finsetProd _ (fun T _ => + continuous_const.sub (continuous_messageIntegral H q hq e T)) + +omit [Fintype ι] in +theorem continuous_cavityDepth (H : τ → Finset ι) (k : ℕ) (e : ι) (p : Option τ) : + Continuous (cavityDepth H k e p) := by + induction k generalizing e p with + | zero => exact continuous_const + | succ k ih => exact continuous_cavityOperator H _ ih e p + +omit [Fintype ι] [Fintype τ] [DecidableEq τ] in +theorem messageIntegral_mem_unit (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (hc : ∀ e p, Continuous (q e p)) + (hq : ∀ e p t, q e p t ∈ Set.Icc (0 : ℝ) 1) (e : ι) (T : τ) (t : ℝ) : + messageIntegral H q e T t ∈ Set.Icc (0 : ℝ) 1 := by + have ha : ∀ s, 0 ≤ ∏ f ∈ (H T).erase e, q f (some T) s := fun s => + Finset.prod_nonneg fun f _ => (hq f (some T) s).1 + have hb : ∀ s, (∏ f ∈ (H T).erase e, q f (some T) s) ≤ 1 := fun s => + Finset.prod_le_one₀ (fun edge _ => (hq edge (some T) s).1) + (fun edge _ => (hq edge (some T) s).2) + refine ⟨intervalIntegral.integral_nonneg_of_forall (unitTime_nonneg t) ha, ?_⟩ + have hu := intervalIntegral.integral_mono_on (μ := volume) (unitTime_nonneg t) + ((continuous_message_integrand H q hc e T).intervalIntegrable 0 (unitTime t)) + (continuous_const.intervalIntegrable 0 (unitTime t)) (fun s _ => hb s) + have : messageIntegral H q e T t ≤ unitTime t := by simpa [messageIntegral] using hu + exact this.trans (unitTime_le_one t) + +omit [Fintype ι] in +theorem cavityOperator_mem_unit (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (hc : ∀ e p, Continuous (q e p)) + (hq : ∀ e p t, q e p t ∈ Set.Icc (0 : ℝ) 1) (e : ι) (p : Option τ) (t : ℝ) : + cavityOperator H q e p t ∈ Set.Icc (0 : ℝ) 1 := by + have hh : ∀ T, 1 - messageIntegral H q e T t ∈ Set.Icc (0 : ℝ) 1 := by + intro T + have h := messageIntegral_mem_unit H q hc hq e T t + constructor <;> linarith [h.1, h.2] + exact ⟨Finset.prod_nonneg (fun T _ => (hh T).1), + Finset.prod_le_one₀ (fun triangle _ => (hh triangle).1) + (fun triangle _ => (hh triangle).2)⟩ + +omit [Fintype ι] in +theorem cavityDepth_mem_unit (H : τ → Finset ι) (k : ℕ) (e : ι) (p : Option τ) (t : ℝ) : + cavityDepth H k e p t ∈ Set.Icc (0 : ℝ) 1 := by + induction k generalizing e p t with + | zero => exact ⟨zero_le_one, le_rfl⟩ + | succ k ih => exact cavityOperator_mem_unit H _ (continuous_cavityDepth H k) ih e p t + +def cavityBranching : ℝ := (Fintype.card τ : ℝ) * Fintype.card ι + +omit [DecidableEq ι] [DecidableEq τ] in +theorem cavityBranching_nonneg : 0 ≤ cavityBranching (ι := ι) (τ := τ) := by + unfold cavityBranching + positivity + +theorem cavityOperator_lipschitz (H : τ → Finset ι) + (q r : ι → Option τ → ℝ → ℝ) + (hqc : ∀ e p, Continuous (q e p)) (hrc : ∀ e p, Continuous (r e p)) + (hq : ∀ e p t, q e p t ∈ Set.Icc (0 : ℝ) 1) + (hr : ∀ e p t, r e p t ∈ Set.Icc (0 : ℝ) 1) + (b : ℝ → ℝ) (hbc : Continuous b) (hb : ∀ s ∈ Set.Icc (0 : ℝ) 1, 0 ≤ b s) + (hqr : ∀ e p s, s ∈ Set.Icc (0 : ℝ) 1 → |q e p s - r e p s| ≤ b s) + (e : ι) (p : Option τ) (t : ℝ) : + |cavityOperator H q e p t - cavityOperator H r e p t| ≤ + cavityBranching (ι := ι) (τ := τ) * ∫ s in (0 : ℝ)..unitTime t, b s := by + have ht : ∀ s ∈ Set.Icc (0 : ℝ) (unitTime t), s ∈ Set.Icc (0 : ℝ) 1 := + fun s hs => ⟨hs.1, hs.2.trans (unitTime_le_one t)⟩ + have hbi : 0 ≤ ∫ s in (0 : ℝ)..unitTime t, b s := by + have h := intervalIntegral.integral_mono_on (μ := volume) (unitTime_nonneg t) + (continuous_const.intervalIntegrable 0 (unitTime t)) + (hbc.intervalIntegrable 0 (unitTime t)) (fun s hs => hb s (ht s hs)) + simpa using h + have hinner : ∀ T s, s ∈ Set.Icc (0 : ℝ) (unitTime t) → + |(∏ f ∈ (H T).erase e, q f (some T) s) - + ∏ f ∈ (H T).erase e, r f (some T) s| ≤ (Fintype.card ι : ℝ) * b s := by + intro T s hs + calc + _ ≤ ∑ f ∈ (H T).erase e, |q f (some T) s - r f (some T) s| := + abs_prod_sub_prod_le_sum _ _ _ (fun f _ => hq f (some T) s) (fun f _ => hr f (some T) s) + _ ≤ ∑ _f ∈ (H T).erase e, b s := + Finset.sum_le_sum fun f _ => hqr f (some T) s (ht s hs) + _ = (((H T).erase e).card : ℝ) * b s := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast Finset.card_le_univ ((H T).erase e)) + (hb s (ht s hs)) + have hint : ∀ T, |messageIntegral H q e T t - messageIntegral H r e T t| ≤ + (Fintype.card ι : ℝ) * ∫ s in (0 : ℝ)..unitTime t, b s := by + intro T + have hqint := (continuous_message_integrand H q hqc e T).intervalIntegrable (μ := volume) 0 (unitTime t) + have hrint := (continuous_message_integrand H r hrc e T).intervalIntegrable (μ := volume) 0 (unitTime t) + rw [messageIntegral, messageIntegral, ← intervalIntegral.integral_sub hqint hrint] + calc + _ ≤ ∫ s in (0 : ℝ)..unitTime t, + |(∏ f ∈ (H T).erase e, q f (some T) s) - + ∏ f ∈ (H T).erase e, r f (some T) s| := + intervalIntegral.abs_integral_le_integral_abs (unitTime_nonneg t) + _ ≤ ∫ s in (0 : ℝ)..unitTime t, (Fintype.card ι : ℝ) * b s := by + apply intervalIntegral.integral_mono_on (unitTime_nonneg t) + (((continuous_message_integrand H q hqc e T).sub + (continuous_message_integrand H r hrc e T)).abs.intervalIntegrable 0 (unitTime t)) + ((continuous_const.mul hbc).intervalIntegrable 0 (unitTime t)) + exact hinner T + _ = _ := intervalIntegral.integral_const_mul _ _ + have hqf : ∀ T ∈ messageCandidates H e p, + 1 - messageIntegral H q e T t ∈ Set.Icc (0 : ℝ) 1 := by + intro T _ + have h := messageIntegral_mem_unit H q hqc hq e T t + constructor <;> linarith [h.1, h.2] + have hrf : ∀ T ∈ messageCandidates H e p, + 1 - messageIntegral H r e T t ∈ Set.Icc (0 : ℝ) 1 := by + intro T _ + have h := messageIntegral_mem_unit H r hrc hr e T t + constructor <;> linarith [h.1, h.2] + calc + _ ≤ ∑ T ∈ messageCandidates H e p, + |(1 - messageIntegral H q e T t) - (1 - messageIntegral H r e T t)| := + abs_prod_sub_prod_le_sum _ _ _ hqf hrf + _ ≤ ∑ _T ∈ messageCandidates H e p, + (Fintype.card ι : ℝ) * ∫ s in (0 : ℝ)..unitTime t, b s := by + apply Finset.sum_le_sum + intro T _ + simpa only [sub_sub_sub_cancel_left, abs_sub_comm] using hint T + _ = ((messageCandidates H e p).card : ℝ) * + ((Fintype.card ι : ℝ) * ∫ s in (0 : ℝ)..unitTime t, b s) := by simp + _ ≤ (Fintype.card τ : ℝ) * + ((Fintype.card ι : ℝ) * ∫ s in (0 : ℝ)..unitTime t, b s) := by + apply mul_le_mul_of_nonneg_right + · exact_mod_cast Finset.card_le_univ (messageCandidates H e p) + · positivity + _ = _ := by rw [cavityBranching]; ring + +theorem cavityDepth_succ_diff (H : τ → Finset ι) (k : ℕ) (e : ι) (p : Option τ) (t : ℝ) : + |cavityDepth H (k + 1) e p t - cavityDepth H k e p t| ≤ + cavityBranching (ι := ι) (τ := τ) ^ k * (unitTime t) ^ k / k.factorial := by + let M := cavityBranching (ι := ι) (τ := τ) + have hM : 0 ≤ M := cavityBranching_nonneg + induction k generalizing e p t with + | zero => + have h := cavityDepth_mem_unit H 1 e p t + simp only [pow_zero, Nat.factorial_zero, Nat.cast_one, one_mul, div_one] + change |cavityDepth H 1 e p t - 1| ≤ 1 + exact abs_le.mpr ⟨by linarith [h.1], by linarith [h.2]⟩ + | succ k ih => + let b : ℝ → ℝ := fun s => M ^ k / (k.factorial : ℝ) * s ^ k + have hbc : Continuous b := continuous_const.mul (continuous_id.pow k) + have hb : ∀ s ∈ Set.Icc (0 : ℝ) 1, 0 ≤ b s := by + intro s hs + exact mul_nonneg (div_nonneg (pow_nonneg hM _) (Nat.cast_nonneg _)) + (pow_nonneg hs.1 _) + have hd : ∀ e p s, s ∈ Set.Icc (0 : ℝ) 1 → + |cavityDepth H (k + 1) e p s - cavityDepth H k e p s| ≤ b s := by + intro e p s hs + have h := ih e p s + rw [unitTime_of_mem hs] at h + simpa only [b, M, div_mul_eq_mul_div] using h + have h := cavityOperator_lipschitz H (cavityDepth H (k + 1)) (cavityDepth H k) + (continuous_cavityDepth H (k + 1)) (continuous_cavityDepth H k) + (cavityDepth_mem_unit H (k + 1)) (cavityDepth_mem_unit H k) + b hbc hb hd e p t + change |cavityOperator H (cavityDepth H (k + 1)) e p t - + cavityOperator H (cavityDepth H k) e p t| ≤ _ + apply h.trans_eq + simp only [b, intervalIntegral.integral_const_mul, integral_pow, zero_pow (Nat.succ_ne_zero k), + sub_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, pow_succ] + dsimp [M] + simp only [div_eq_mul_inv, mul_inv_rev] + ring + +abbrev CavitySpace (ι τ : Type*) := ι → Option τ → (ℝ →ᵇ ℝ) + +noncomputable def cavityDepthBCF (H : τ → Finset ι) (k : ℕ) : CavitySpace ι τ := + fun e p => BoundedContinuousFunction.mkOfBound + ⟨cavityDepth H k e p, continuous_cavityDepth H k e p⟩ 1 (by + intro x y + change |cavityDepth H k e p x - cavityDepth H k e p y| ≤ 1 + have hx := cavityDepth_mem_unit H k e p x + have hy := cavityDepth_mem_unit H k e p y + exact abs_le.mpr ⟨by linarith [hx.1, hy.2], by linarith [hx.2, hy.1]⟩) + +omit [Fintype ι] in +@[simp] theorem cavityDepthBCF_apply (H : τ → Finset ι) (k : ℕ) (e : ι) (p : Option τ) (t : ℝ) : + cavityDepthBCF H k e p t = cavityDepth H k e p t := rfl + +theorem cavityDepthBCF_succ_dist (H : τ → Finset ι) (k : ℕ) : + dist (cavityDepthBCF H k) (cavityDepthBCF H (k + 1)) ≤ + cavityBranching (ι := ι) (τ := τ) ^ k / k.factorial := by + have hb : 0 ≤ cavityBranching (ι := ι) (τ := τ) ^ k / (k.factorial : ℝ) := + div_nonneg (pow_nonneg cavityBranching_nonneg _) (Nat.cast_nonneg _) + rw [dist_comm, dist_eq_norm] + apply (pi_norm_le_iff_of_nonneg hb).mpr + intro e + apply (pi_norm_le_iff_of_nonneg hb).mpr + intro p + apply (BoundedContinuousFunction.norm_le hb).mpr + intro t + change |cavityDepth H (k + 1) e p t - cavityDepth H k e p t| ≤ _ + apply (cavityDepth_succ_diff H k e p t).trans + calc + _ = (cavityBranching (ι := ι) (τ := τ) ^ k / k.factorial) * (unitTime t) ^ k := by ring + _ ≤ (cavityBranching (ι := ι) (τ := τ) ^ k / k.factorial) * 1 := + mul_le_mul_of_nonneg_left (pow_le_one₀ (unitTime_nonneg t) (unitTime_le_one t)) hb + _ = _ := mul_one _ + +theorem cavityDepthBCF_cauchy (H : τ → Finset ι) : CauchySeq (cavityDepthBCF H) := + cauchySeq_of_dist_le_of_summable _ (cavityDepthBCF_succ_dist H) + (Real.summable_pow_div_factorial _) + +noncomputable def cavityLimitBCF (H : τ → Finset ι) : CavitySpace ι τ := + (cauchySeq_tendsto_of_complete (cavityDepthBCF_cauchy H)).choose + +theorem tendsto_cavityDepthBCF (H : τ → Finset ι) : + Tendsto (cavityDepthBCF H) atTop (𝓝 (cavityLimitBCF H)) := + (cauchySeq_tendsto_of_complete (cavityDepthBCF_cauchy H)).choose_spec + +noncomputable def cavityLimit (H : τ → Finset ι) (e : ι) (p : Option τ) (t : ℝ) : ℝ := + cavityLimitBCF H e p t + +theorem continuous_cavityLimit (H : τ → Finset ι) (e : ι) (p : Option τ) : + Continuous (cavityLimit H e p) := (cavityLimitBCF H e p).continuous + +theorem tendsto_cavityDepth (H : τ → Finset ι) (e : ι) (p : Option τ) (t : ℝ) : + Tendsto (fun k => cavityDepth H k e p t) atTop (𝓝 (cavityLimit H e p t)) := by + have h := ((tendsto_pi_nhds.mp (tendsto_cavityDepthBCF H)) e) + have h' := (tendsto_pi_nhds.mp h) p + exact ((BoundedContinuousFunction.lipschitz_eval_const t).continuous.tendsto + (cavityLimitBCF H e p)).comp h' + +theorem cavityLimit_mem_unit (H : τ → Finset ι) (e : ι) (p : Option τ) (t : ℝ) : + cavityLimit H e p t ∈ Set.Icc (0 : ℝ) 1 := + isClosed_Icc.mem_of_tendsto (tendsto_cavityDepth H e p t) + (Eventually.of_forall fun k => cavityDepth_mem_unit H k e p t) + +omit [DecidableEq ι] [DecidableEq τ] in + +theorem cavitySpace_eval_sub_le (q r : CavitySpace ι τ) (e : ι) (p : Option τ) (t : ℝ) : + |q e p t - r e p t| ≤ ‖q - r‖ := by + exact ((BoundedContinuousFunction.norm_coe_le_norm (q e p - r e p) t).trans + (norm_le_pi_norm ((q - r) e) p)).trans (norm_le_pi_norm (q - r) e) + +theorem cavityLimit_product (H : τ → Finset ι) (e : ι) (p : Option τ) (t : ℝ) : + cavityLimit H e p t = cavityOperator H (cavityLimit H) e p t := by + let d : ℕ → ℝ := fun k => ‖cavityDepthBCF H k - cavityLimitBCF H‖ + have hd : Tendsto d atTop (𝓝 0) := by + simpa only [sub_self, norm_zero] using + ((tendsto_cavityDepthBCF H).sub (tendsto_const_nhds (x := cavityLimitBCF H))).norm + have hbound : ∀ k, + |cavityDepth H (k + 1) e p t - cavityOperator H (cavityLimit H) e p t| ≤ + cavityBranching (ι := ι) (τ := τ) * (unitTime t * d k) := by + intro k + have h := cavityOperator_lipschitz H (cavityDepth H k) (cavityLimit H) + (continuous_cavityDepth H k) (continuous_cavityLimit H) + (cavityDepth_mem_unit H k) (cavityLimit_mem_unit H) + (fun _ => d k) continuous_const (fun _ _ => norm_nonneg _) + (fun f o s _ => cavitySpace_eval_sub_le (cavityDepthBCF H k) (cavityLimitBCF H) f o s) + e p t + simpa only [cavityDepth, intervalIntegral.integral_const, sub_zero, smul_eq_mul] using h + have herr : Tendsto (fun k => + |cavityDepth H (k + 1) e p t - cavityOperator H (cavityLimit H) e p t|) atTop (𝓝 0) := by + apply squeeze_zero (fun _ => abs_nonneg _) hbound + simpa only [mul_zero] using tendsto_const_nhds.mul (tendsto_const_nhds.mul hd) + have hop : Tendsto (fun k => cavityDepth H (k + 1) e p t) atTop + (𝓝 (cavityOperator H (cavityLimit H) e p t)) := by + apply (tendsto_iff_dist_tendsto_zero).mpr + simpa only [Real.dist_eq] using herr + exact tendsto_nhds_unique ((tendsto_cavityDepth H e p t).comp + (tendsto_add_atTop_nat 1)) hop + +omit [Fintype ι] in +@[simp] theorem cavityDepth_zero_time (H : τ → Finset ι) (k : ℕ) (e : ι) (p : Option τ) : + cavityDepth H k e p 0 = 1 := by + cases k <;> simp [cavityDepth, cavityOperator, messageIntegral, unitTime] + +@[simp] theorem cavityLimit_zero_time (H : τ → Finset ι) (e : ι) (p : Option τ) : + cavityLimit H e p 0 = 1 := by + apply tendsto_nhds_unique (tendsto_cavityDepth H e p 0) + simpa only [cavityDepth_zero_time] using (tendsto_const_nhds : Tendsto (fun _ : ℕ => (1 : ℝ)) + atTop (𝓝 1)) + +omit [Fintype ι] in +theorem messageCandidates_omission (H : τ → Finset ι) (e : ι) (T : τ) : + messageCandidates H e (some T) = (messageCandidates H e none).erase T := by + ext U + simp [messageCandidates, and_comm] + +theorem cavityLimit_omission (H : τ → Finset ι) (e : ι) (T : τ) + (he : e ∈ H T) (t : ℝ) : + cavityLimit H e none t = cavityLimit H e (some T) t * + (1 - messageIntegral H (cavityLimit H) e T t) := by + rw [cavityLimit_product H e none t, cavityLimit_product H e (some T) t] + unfold cavityOperator + rw [messageCandidates_omission] + exact (Finset.prod_erase_mul _ _ (by simp [messageCandidates, he])).symm + +omit [Fintype ι] [Fintype τ] [DecidableEq τ] in +theorem messageIntegral_le_time (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (hc : ∀ e p, Continuous (q e p)) + (hq : ∀ e p t, q e p t ∈ Set.Icc (0 : ℝ) 1) (e : ι) (T : τ) (t : ℝ) : + messageIntegral H q e T t ≤ unitTime t := by + have hu := intervalIntegral.integral_mono_on (μ := volume) (unitTime_nonneg t) + ((continuous_message_integrand H q hc e T).intervalIntegrable 0 (unitTime t)) + (continuous_const.intervalIntegrable 0 (unitTime t)) (fun s _ => + Finset.prod_le_one₀ (fun edge _ => (hq edge (some T) s).1) + (fun edge _ => (hq edge (some T) s).2)) + simpa [messageIntegral] using hu + +theorem cavityLimit_factor_pos (H : τ → Finset ι) (e : ι) (T : τ) + {t : ℝ} (ht : t < 1) : + 0 < 1 - messageIntegral H (cavityLimit H) e T t := by + have hb := messageIntegral_le_time H (cavityLimit H) (continuous_cavityLimit H) + (cavityLimit_mem_unit H) e T t + have htime : unitTime t < 1 := by + exact max_lt zero_lt_one ((min_le_right 1 t).trans_lt ht) + linarith + +theorem cavityLimit_pos (H : τ → Finset ι) (e : ι) (p : Option τ) + {t : ℝ} (ht : t < 1) : 0 < cavityLimit H e p t := by + rw [cavityLimit_product] + exact Finset.prod_pos (fun T _ => cavityLimit_factor_pos H e T ht) + +omit [Fintype ι] [Fintype τ] [DecidableEq τ] in +theorem messageIntegral_hasDerivAt (H : τ → Finset ι) + (q : ι → Option τ → ℝ → ℝ) (hc : ∀ e p, Continuous (q e p)) + (e : ι) (T : τ) {t : ℝ} (ht : t ∈ Set.Ioo (0 : ℝ) 1) : + HasDerivAt (messageIntegral H q e T) + (∏ f ∈ (H T).erase e, q f (some T) t) t := by + have hcont := continuous_message_integrand H q hc e T + have hd := intervalIntegral.integral_hasDerivAt_right + (hcont.intervalIntegrable 0 t) hcont.stronglyMeasurable.stronglyMeasurableAtFilter + hcont.continuousAt + apply hd.congr_of_eventuallyEq + filter_upwards [Ioo_mem_nhds ht.1 ht.2] with x hx + simp only [messageIntegral, unitTime_of_mem ⟨le_of_lt hx.1, le_of_lt hx.2⟩] + +theorem cavityLimit_hasDerivAt (H : τ → Finset ι) (e : ι) (p : Option τ) + {t : ℝ} (ht : t ∈ Set.Ioo (0 : ℝ) 1) : + HasDerivAt (cavityLimit H e p) + (-cavityLimit H e p t * + ∑ T ∈ messageCandidates H e p, + (∏ f ∈ (H T).erase e, cavityLimit H f (some T) t) / + (1 - messageIntegral H (cavityLimit H) e T t)) t := by + let F : τ → ℝ → ℝ := fun T s => 1 - messageIntegral H (cavityLimit H) e T s + let J : τ → ℝ := fun T => ∏ f ∈ (H T).erase e, cavityLimit H f (some T) t + have hF : ∀ T, HasDerivAt (F T) (-J T) t := by + intro T + convert (hasDerivAt_const t (1 : ℝ)).sub + (messageIntegral_hasDerivAt H (cavityLimit H) (continuous_cavityLimit H) e T ht) using 1 + simp only [J, zero_sub] + have hd := HasDerivAt.finsetProd (u := messageCandidates H e p) (fun T _ => hF T) + have heq : (∏ T ∈ messageCandidates H e p, F T) = cavityLimit H e p := by + funext s + simpa only [Finset.prod_apply, cavityOperator, F] using (cavityLimit_product H e p s).symm + rw [heq] at hd + convert hd using 1 + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro T hT + have hc : cavityLimit H e p t = + (∏ U ∈ (messageCandidates H e p).erase T, F U t) * F T t := by + rw [cavityLimit_product] + exact (Finset.prod_erase_mul _ _ hT).symm + have hp : F T t ≠ 0 := ne_of_gt (cavityLimit_factor_pos H e T ht.2) + simp only [smul_eq_mul] + change -cavityLimit H e p t * (J T / F T t) = _ + rw [hc] + field_simp + +noncomputable def cavityTime (D s : ℝ) : ℝ := (Real.exp (2 * s) - 1) / (2 * D) + +noncomputable def cavityLog (H : τ → Finset ι) (D : ℝ) (e : ι) (s : ℝ) : ℝ := + Real.log (cavityLimit H e none (cavityTime D s)) + s + +noncomputable def cavityMessage (H : τ → Finset ι) (D : ℝ) (e : ι) (T : τ) (s : ℝ) : ℝ := + messageIntegral H (cavityLimit H) e T (cavityTime D s) + +omit [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] in +theorem cavityTime_hasDerivAt (D s : ℝ) : + HasDerivAt (cavityTime D) (Real.exp (2 * s) / D) s := by + have hh := (((hasDerivAt_id s).const_mul 2).exp.sub_const 1).div_const (2 * D) + convert hh using 1 <;> (try rfl) + simp only [id_eq, mul_one] + ring + +omit [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] in +@[simp] theorem cavityTime_zero (D : ℝ) : cavityTime D 0 = 0 := by + simp [cavityTime] + +theorem cavityLog_zero (H : τ → Finset ι) (D : ℝ) (e : ι) : cavityLog H D e 0 = 0 := by + simp [cavityLog, cavityTime, cavityLimit_zero_time] + +theorem cavityLog_exp (H : τ → Finset ι) (D : ℝ) (e : ι) {s : ℝ} + (ht : cavityTime D s < 1) : + cavityLimit H e none (cavityTime D s) = Real.exp (cavityLog H D e s - s) := by + simp only [cavityLog, add_sub_cancel_right] + exact (Real.exp_log (cavityLimit_pos H e none ht)).symm + +theorem cavityLog_parent (H : τ → Finset ι) (D : ℝ) (e : ι) (T : τ) + (he : e ∈ H T) {s : ℝ} (ht : cavityTime D s < 1) : + cavityLimit H e (some T) (cavityTime D s) = + Real.exp (cavityLog H D e s - s) / (1 - cavityMessage H D e T s) := by + apply (eq_div_iff (ne_of_gt (cavityLimit_factor_pos H e T ht))).mpr + simpa only [cavityMessage, cavityLog_exp H D e ht] using + (cavityLimit_omission H e T he (cavityTime D s)).symm + +theorem cavityLog_hasDerivAt (H : τ → Finset ι) (D : ℝ) (e : ι) + {s : ℝ} (ht : cavityTime D s ∈ Set.Ioo (0 : ℝ) 1) : + HasDerivAt (cavityLog H D e) + (1 - Real.exp (2 * s) / D * + ∑ T ∈ messageCandidates H e none, + (∏ f ∈ (H T).erase e, cavityLimit H f (some T) (cavityTime D s)) / + (1 - cavityMessage H D e T s)) s := by + have hp := cavityLimit_pos H e none ht.2 + have hh := ((cavityLimit_hasDerivAt H e none ht).comp s (cavityTime_hasDerivAt D s)).log hp.ne' + have hh' := hh.add (hasDerivAt_id s) + convert hh' using 1 <;> try rfl + dsimp only [Function.comp_apply, cavityMessage] + field_simp + ring + +theorem cavityMessage_hasDerivAt (H : τ → Finset ι) (D : ℝ) (e : ι) (T : τ) + {s : ℝ} (ht : cavityTime D s ∈ Set.Ioo (0 : ℝ) 1) : + HasDerivAt (cavityMessage H D e T) + (Real.exp (2 * s) / D * + ∏ f ∈ (H T).erase e, cavityLimit H f (some T) (cavityTime D s)) s := by + convert (messageIntegral_hasDerivAt H (cavityLimit H) (continuous_cavityLimit H) e T ht).comp s + (cavityTime_hasDerivAt D s) using 1 <;> try rfl + ring + +omit [Fintype ι] [Fintype τ] [DecidableEq τ] in + +theorem triangle_children {H : τ → Finset ι} {e : ι} {T : τ} + (hcard : (H T).card = 3) (he : e ∈ H T) : + ∃ f g, f ≠ g ∧ (H T).erase e = {f, g} ∧ f ∈ H T ∧ g ∈ H T := by + have hh : ((H T).erase e).card = 2 := by + rw [Finset.card_erase_of_mem he, hcard] + rcases Finset.card_eq_two.mp hh with ⟨f, g, hfg, hset⟩ + refine ⟨f, g, hfg, hset, ?_, ?_⟩ + · have hm : f ∈ (H T).erase e := by rw [hset]; simp + exact Finset.mem_of_mem_erase hm + · have hm : g ∈ (H T).erase e := by rw [hset]; simp + exact Finset.mem_of_mem_erase hm + +theorem cavity_triangle_summand (H : τ → Finset ι) (D : ℝ) (e : ι) (T : τ) + {f g : ι} (hfg : f ≠ g) (hchildren : (H T).erase e = {f, g}) + (hf : f ∈ H T) (hg : g ∈ H T) {s : ℝ} (ht : cavityTime D s < 1) : + Real.exp (2 * s) * + ((∏ u ∈ (H T).erase e, cavityLimit H u (some T) (cavityTime D s)) / + (1 - cavityMessage H D e T s)) = + Real.exp (cavityLog H D f s + cavityLog H D g s) / + ((1 - cavityMessage H D e T s) * (1 - cavityMessage H D f T s) * + (1 - cavityMessage H D g T s)) := by + have he0 := (cavityLimit_factor_pos H e T ht).ne' + have hf0 := (cavityLimit_factor_pos H f T ht).ne' + have hg0 := (cavityLimit_factor_pos H g T ht).ne' + rw [hchildren, Finset.prod_pair hfg, cavityLog_parent H D f T hf ht, + cavityLog_parent H D g T hg ht] + have heq : Real.exp (2 * s) * (Real.exp (cavityLog H D f s - s) * + Real.exp (cavityLog H D g s - s)) = + Real.exp (cavityLog H D f s + cavityLog H D g s) := by + rw [← Real.exp_add, ← Real.exp_add] + congr 1 + ring + dsimp only [cavityMessage] at * + field_simp + nlinarith [heq] + +theorem cavity_triangle_message_summand (H : τ → Finset ι) (D : ℝ) (e : ι) (T : τ) + {f g : ι} (hfg : f ≠ g) (hchildren : (H T).erase e = {f, g}) + (hf : f ∈ H T) (hg : g ∈ H T) {s : ℝ} (ht : cavityTime D s < 1) : + Real.exp (2 * s) * + (∏ u ∈ (H T).erase e, cavityLimit H u (some T) (cavityTime D s)) = + Real.exp (cavityLog H D f s + cavityLog H D g s) / + ((1 - cavityMessage H D f T s) * (1 - cavityMessage H D g T s)) := by + have hf0 := (cavityLimit_factor_pos H f T ht).ne' + have hg0 := (cavityLimit_factor_pos H g T ht).ne' + rw [hchildren, Finset.prod_pair hfg, cavityLog_parent H D f T hf ht, + cavityLog_parent H D g T hg ht] + have heq : Real.exp (2 * s) * (Real.exp (cavityLog H D f s - s) * + Real.exp (cavityLog H D g s - s)) = + Real.exp (cavityLog H D f s + cavityLog H D g s) := by + rw [← Real.exp_add, ← Real.exp_add] + congr 1 + ring + dsimp only [cavityMessage] at * + field_simp + nlinarith [heq] + +omit [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] in +theorem continuous_cavityTime (D : ℝ) : Continuous (cavityTime D) := + (Real.continuous_exp.comp (continuous_const.mul continuous_id)).sub continuous_const |>.div_const _ + +omit [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] in +theorem cavityTime_mono {D : ℝ} (hD : 0 < D) : Monotone (cavityTime D) := by + intro s t hst + apply div_le_div_of_nonneg_right _ (by positivity) + exact sub_le_sub_right (Real.exp_le_exp.mpr (by linarith)) _ + +omit [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] in +theorem cavityTime_pos {D s : ℝ} (hD : 0 < D) (hs : 0 < s) : 0 < cavityTime D s := by + apply div_pos _ (by positivity) + exact sub_pos.mpr (Real.one_lt_exp_iff.mpr (by linarith)) + +theorem continuous_cavityMessage (H : τ → Finset ι) (D : ℝ) (e : ι) (T : τ) : + Continuous (cavityMessage H D e T) := + (continuous_messageIntegral H (cavityLimit H) (continuous_cavityLimit H) e T).comp + (continuous_cavityTime D) + +@[simp] theorem cavityMessage_zero (H : τ → Finset ι) (D : ℝ) (e : ι) (T : τ) : + cavityMessage H D e T 0 = 0 := by + simp [cavityMessage, messageIntegral, unitTime] + +theorem cavityMessage_nonneg (H : τ → Finset ι) (D : ℝ) (e : ι) (T : τ) (s : ℝ) : + 0 ≤ cavityMessage H D e T s := + (messageIntegral_mem_unit H (cavityLimit H) (continuous_cavityLimit H) + (cavityLimit_mem_unit H) e T (cavityTime D s)).1 + +theorem continuousOn_cavityLog (H : τ → Finset ι) {D S : ℝ} + (hD : 0 < D) (hS : cavityTime D S < 1) (e : ι) : + ContinuousOn (cavityLog H D e) (Set.Icc 0 S) := by + apply ContinuousOn.add _ continuousOn_id + exact ((continuous_cavityLimit H e none).comp (continuous_cavityTime D)).continuousOn.log + (fun s hs => (cavityLimit_pos H e none ((cavityTime_mono hD hs.2).trans_lt hS)).ne') + +end Cavity +end SharpTerminalLeave + +open scoped BigOperators + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/BirthGraph.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/BirthGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..deaeb92ab4a068021c8c8552a16f90e60eafdfda --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/BirthGraph.lean @@ -0,0 +1,240 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +structure BirthGraph (N : ℕ) where + older : Fin N → Finset (Fin N) + older_lt : ∀ v, ∀ u ∈ older v, u < v + older_card : ∀ v, (older v).card ≤ 2 + +namespace BirthGraph +variable {N : ℕ} (B : BirthGraph N) + +def graph : SimpleGraph (Fin N) where + Adj u v := u ∈ B.older v ∨ v ∈ B.older u + symm := ⟨fun _ _ h => Or.symm h⟩ + loopless := ⟨fun v h => by + rcases h with h | h <;> exact (lt_irrefl v) (B.older_lt v v h)⟩ + +@[simp] theorem graph_adj (u v : Fin N) : + B.graph.Adj u v ↔ u ∈ B.older v ∨ v ∈ B.older u := Iff.rfl + +theorem graph_adj_of_lt {u v : Fin N} (huv : u < v) : + B.graph.Adj u v ↔ u ∈ B.older v := by + constructor + · intro h + rcases h with h | h + · exact h + · exact False.elim ((not_lt_of_gt huv) (B.older_lt u v h)) + · exact Or.inl + +def parentVertices (v : Fin N) : Finset (Fin N) := insert v (B.older v) + +@[simp] theorem self_not_mem_older (v : Fin N) : v ∉ B.older v := by + intro hv + exact (lt_irrefl v) (B.older_lt v v hv) + +theorem older_eq_pair {a b v : Fin N} (hab : a ≠ b) + (ha : a ∈ B.older v) (hb : b ∈ B.older v) : B.older v = {a, b} := by + symm + apply Finset.eq_of_subset_of_card_le + · simpa only [Finset.insert_subset_iff, Finset.singleton_subset_iff] using And.intro ha hb + · simpa only [Finset.card_pair hab] using B.older_card v + +theorem sorted_triangle {a b c : Fin N} (hab : a < b) (hbc : b < c) + (hac : B.graph.Adj a c) (hbc' : B.graph.Adj b c) : + B.parentVertices c = {a, b, c} := by + have ho := B.older_eq_pair (ne_of_lt hab) + ((B.graph_adj_of_lt (hab.trans hbc)).mp hac) ((B.graph_adj_of_lt hbc).mp hbc') + simp only [parentVertices, ho] + ext x + simp only [Finset.mem_insert, Finset.mem_singleton] + tauto + +section Labels +variable {V : Type*} [DecidableEq V] (G : SimpleGraph V) (label : Fin N → V) + +def parentType (v : Fin N) : Finset V := (B.parentVertices v).image label + +def IsTriangle (T : Finset V) : Prop := + T.card = 3 ∧ ∀ x ∈ T, ∀ y ∈ T, x ≠ y → G.Adj x y + +def ExposedAt (v : Fin N) (T : Finset V) : Prop := + IsTriangle G T ∧ + (∃ u ∈ B.older v, label u ∈ T ∧ label v ∈ T) ∧ + ((B.older v).card = 2 → T ≠ B.parentType label v) + +def ExtraEdge (a b : Fin N) : Prop := + a ≠ b ∧ ¬ B.graph.Adj a b ∧ G.Adj (label a) (label b) + +theorem no_repeated_exposure (hinj : Function.Injective label) + (hno : ∀ a b, ¬ B.ExtraEdge G label a b) + {v w : Fin N} (hvw : v ≠ w) {T : Finset V} + (hv : B.ExposedAt G label v T) (hw : B.ExposedAt G label w T) : False := by + wlog hlt : w < v generalizing v w + · exact this (Ne.symm hvw) hw hv (lt_of_le_of_ne (le_of_not_gt hlt) hvw) + obtain ⟨k, hk, hkT, hwT⟩ := hw.2.1 + have hkw := B.older_lt w k hk + have hvT := hv.2.1.choose_spec.2.2 + have hkv : k < v := hkw.trans hlt + have hlabels : ({label k, label w, label v} : Finset V).card = 3 := by + simp [hinj.ne (ne_of_lt hkw), hinj.ne (ne_of_lt hkv), hinj.ne (ne_of_lt hlt)] + have hT : T = {label k, label w, label v} := by + symm + apply Finset.eq_of_subset_of_card_le + · simp only [Finset.insert_subset_iff, Finset.singleton_subset_iff] + exact ⟨hkT, hwT, hvT⟩ + · rw [hlabels, hv.1.1] + have hcv (u : Fin N) (hu : u < v) (huT : label u ∈ T) : u ∈ B.older v := by + have hG : G.Adj (label u) (label v) := hv.1.2 _ huT _ hvT (hinj.ne (ne_of_lt hu)) + have hh : B.graph.Adj u v := by + by_contra hn + exact hno u v ⟨ne_of_lt hu, hn, hG⟩ + exact (B.graph_adj_of_lt hu).mp hh + have hold := B.older_eq_pair (ne_of_lt hkw) (hcv k hkv hkT) (hcv w hlt hwT) + have hcard : (B.older v).card = 2 := by rw [hold, Finset.card_pair (ne_of_lt hkw)] + apply hv.2.2 hcard + rw [parentType, parentVertices, hold, hT] + ext x + simp only [Finset.mem_image, Finset.mem_insert, Finset.mem_singleton] + aesop + +structure SpawnRules : Prop where + edge_labels : ∀ a b, B.graph.Adj a b → G.Adj (label a) (label b) + attachment : ∀ v, (B.older v).card = 2 → + ∀ a ∈ B.older v, ∀ b ∈ B.older v, a ≠ b → B.graph.Adj a b + omit_parent : ∀ v p, p ∈ B.older v → (∀ a ∈ B.older v, a ≤ p) → + (B.older p).card = 2 → B.parentType label v ≠ B.parentType label p + distinct_siblings : ∀ v w, (B.older v).card = 2 → B.older v = B.older w → + label v = label w → v = w + +theorem older_sorted_pair {v : Fin N} (hv : (B.older v).card = 2) : + ∃ x y : Fin N, x < y ∧ B.older v = {x, y} := by + obtain ⟨x, y, hxy, hset⟩ := Finset.card_eq_two.mp hv + rcases lt_or_gt_of_ne hxy with hlt | hgt + · exact ⟨x, y, hlt, hset⟩ + · exact ⟨y, x, hgt, hset.trans (Finset.pair_comm x y)⟩ + +theorem first_label_repeat_extra (hrules : B.SpawnRules G label) + {v w : Fin N} (hv : (B.older v).card = 2) (hw : w < v) + (hvw : label v = label w) : + ∃ a b : Fin N, a < v ∧ b < v ∧ B.ExtraEdge G label a b := by + by_contra hextra + have hno (a b : Fin N) (ha : a < v) (hb : b < v) + (hne : a ≠ b) (hedge : G.Adj (label a) (label b)) : B.graph.Adj a b := by + by_contra hn + exact hextra ⟨a, b, ha, hb, hne, hn, hedge⟩ + obtain ⟨x, y, hxy, hset⟩ := B.older_sorted_pair hv + have hx : x ∈ B.older v := by rw [hset]; simp + have hy : y ∈ B.older v := by rw [hset]; simp + have hxv := B.older_lt v x hx + have hyv := B.older_lt v y hy + have hxwG : G.Adj (label x) (label w) := by + rw [← hvw] + exact hrules.edge_labels x v (Or.inl hx) + have hywG : G.Adj (label y) (label w) := by + rw [← hvw] + exact hrules.edge_labels y v (Or.inl hy) + have hxw : x ≠ w := fun hh => hxwG.ne (congrArg label hh) + have hyw : y ≠ w := fun hh => hywG.ne (congrArg label hh) + have hxwB := hno x w hxv hw hxw hxwG + have hywB := hno y w hyv hw hyw hywG + have hxyB := hrules.attachment v hv x hx y hy (ne_of_lt hxy) + rcases lt_or_gt_of_ne (Ne.symm hyw) with hwy | hyw' + · have hold := B.older_eq_pair hxw ((B.graph_adj_of_lt hxy).mp hxyB) + ((B.graph_adj_of_lt hwy).mp hywB.symm) + have hcard : (B.older y).card = 2 := by rw [hold, Finset.card_pair hxw] + have hmax : ∀ a ∈ B.older v, a ≤ y := by + intro a ha + rw [hset] at ha + simp only [Finset.mem_insert, Finset.mem_singleton] at ha + rcases ha with rfl | rfl + · exact le_of_lt hxy + · exact le_rfl + apply hrules.omit_parent v y hy hmax hcard + simp only [parentType, parentVertices, hset, hold, Finset.image_insert, + Finset.image_singleton, hvw] + ext z + simp only [Finset.mem_insert, Finset.mem_singleton] + tauto + · have hold := B.older_eq_pair (ne_of_lt hxy) + ((B.graph_adj_of_lt (hxy.trans hyw')).mp hxwB) + ((B.graph_adj_of_lt hyw').mp hywB) + have heq := hrules.distinct_siblings v w hv (hset.trans hold.symm) hvw + exact (ne_of_lt hw) heq.symm + +theorem first_label_repeat_injective_extra (hrules : B.SpawnRules G label) + {v w : Fin N} (hv : (B.older v).card = 2) (hw : w < v) + (hvw : label v = label w) + (hinj : Set.InjOn label {u | u < v}) : + ∃ a b : Fin N, a < v ∧ b < v ∧ B.ExtraEdge G label a b ∧ + Set.InjOn label {u | u < v} := by + obtain ⟨a, b, ha, hb, he⟩ := B.first_label_repeat_extra G label hrules hv hw hvw + exact ⟨a, b, ha, hb, he, hinj⟩ + +theorem exists_first_repeat (h : ¬ Function.Injective label) : + ∃ v w : Fin N, w < v ∧ label v = label w ∧ Set.InjOn label (Set.Iio v) := by + classical + let bad : Finset (Fin N) := Finset.univ.filter (fun v => ∃ w < v, label v = label w) + have hbad (v : Fin N) : v ∈ bad ↔ ∃ w < v, label v = label w := by + simp only [bad, Finset.mem_filter, Finset.mem_univ, true_and] + have hne : bad.Nonempty := by + obtain ⟨a, b, hab, hne⟩ := Function.not_injective_iff.mp h + rcases lt_or_gt_of_ne hne with hlt | hgt + · exact ⟨b, (hbad b).mpr ⟨a, hlt, hab.symm⟩⟩ + · exact ⟨a, (hbad a).mpr ⟨b, hgt, hab⟩⟩ + let v := bad.min' hne + obtain ⟨w, hw, hvw⟩ := (hbad v).mp (Finset.min'_mem bad hne) + refine ⟨v, w, hw, hvw, ?_⟩ + intro a ha b hb hab + by_contra hne + rcases lt_or_gt_of_ne hne with hlt | hgt + · have hm := Finset.min'_le bad b ((hbad b).mpr ⟨a, hlt, hab.symm⟩) + exact (not_le_of_gt hb) hm + · have hm := Finset.min'_le bad a ((hbad a).mpr ⟨b, hgt, hab⟩) + exact (not_le_of_gt ha) hm + +theorem exposed_collision_witness (hrules : B.SpawnRules G label) + (R : ℕ) (hroots : Set.InjOn label {v : Fin N | v.val < R}) + (hnonroot : ∀ v : Fin N, R ≤ v.val → (B.older v).card = 2) + {v w : Fin N} (hne : v ≠ w) {T : Finset V} + (hv : B.ExposedAt G label v T) (hw : B.ExposedAt G label w T) : + ∃ S : Set (Fin N), IsLowerSet S ∧ Set.InjOn label S ∧ + ∃ a ∈ S, ∃ b ∈ S, B.ExtraEdge G label a b := by + classical + by_cases hinj : Function.Injective label + · have hex : ∃ a b, B.ExtraEdge G label a b := by + by_contra hn + have hno : ∀ a b, ¬ B.ExtraEdge G label a b := by simpa only [not_exists] using hn + exact B.no_repeated_exposure G label hinj hno hne hv hw + obtain ⟨a, b, he⟩ := hex + exact ⟨Set.univ, isLowerSet_univ, hinj.injOn, a, Set.mem_univ _, b, Set.mem_univ _, he⟩ + · obtain ⟨z, u, huz, hzu, hpre⟩ := exists_first_repeat label hinj + have hz : R ≤ z.val := by + by_contra hn + have hzR : z.val < R := Nat.lt_of_not_ge hn + have huR : u.val < R := lt_trans huz hzR + have hueq := hroots hzR huR hzu + exact (ne_of_lt huz) hueq.symm + obtain ⟨a, b, ha, hb, he⟩ := + B.first_label_repeat_extra G label hrules (hnonroot z hz) huz hzu + exact ⟨Set.Iio z, isLowerSet_Iio z, hpre, a, ha, b, hb, he⟩ + +end Labels +end BirthGraph +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/DegreeTemplate.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/DegreeTemplate.lean new file mode 100644 index 0000000000000000000000000000000000000000..d03398c7e4fb4128148eb062bea96c92675118e1 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/DegreeTemplate.lean @@ -0,0 +1,92 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.RerootTemplate + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +def degreeTemplate : RootedTemplate 2 where + edges := {{0,1}} + roots := {0} + simple := by decide + independent := by decide + +lemma degreeTemplate_balanced : RootedTwoBalanced degreeTemplate := by + unfold RootedTwoBalanced degreeTemplate + decide + +def degreeRoot {n : ℕ} (u : Fin n) : {v // v ∈ degreeTemplate.roots} ↪ Fin n where + toFun := fun _ => u + inj' := by + intro a b _ + apply Subtype.ext + exact (Finset.mem_singleton.mp a.property).trans (Finset.mem_singleton.mp b.property).symm + +lemma degree_rooted_zero {n : ℕ} (u : Fin n) (φ : RootedInjection degreeTemplate (degreeRoot u)) : + φ.val 0 = u := φ.property ⟨0,by decide⟩ + +lemma degree_image_subset {n : ℕ} (u : Fin n) (φ : RootedInjection degreeTemplate (degreeRoot u)) + (G : Graph n) : imageEdges degreeTemplate φ.val ⊆ G ↔ {u,φ.val 1} ∈ G := by + simp [imageEdges,degreeTemplate,degree_rooted_zero u φ] + +lemma degree_restrict_injective {n : ℕ} (u : Fin n) : + Function.Injective (fun φ : RootedInjection degreeTemplate (degreeRoot u) => φ.val 1) := by + intro φ χ h + apply Subtype.ext + apply Function.Embedding.ext + intro i + fin_cases i + · exact (degree_rooted_zero u φ).trans (degree_rooted_zero u χ).symm + · exact h + +lemma degree_restrict_surj {n : ℕ} (u v : Fin n) (hne : u ≠ v) : + ∃ φ : RootedInjection degreeTemplate (degreeRoot u), φ.val 1 = v := by + let f : Fin 2 → Fin n := ![u,v] + have hf : Function.Injective f := by + intro a b h + fin_cases a <;> fin_cases b <;> simp_all [f] + refine ⟨⟨⟨f,hf⟩,?_⟩,rfl⟩ + intro r + have hr : r.val = 0 := Finset.mem_singleton.mp r.property + change f r.val = u + rw [hr] + rfl + +theorem degree_rootedCount {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) : + rootedCount degreeTemplate (degreeRoot u) G = currentDegree G u := by + let A := Finset.univ.filter (fun φ : RootedInjection degreeTemplate (degreeRoot u) => + imageEdges degreeTemplate φ.val ⊆ G) + have hA : rootedCount degreeTemplate (degreeRoot u) G = (A.card : ℝ) := by + simp [rootedCount,copyCount,intact,A] + rw [hA] + unfold currentDegree + congr 1 + apply Finset.card_bij (fun φ _ => φ.val 1) + · intro φ hφ + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,(degree_image_subset u φ G).mp (Finset.mem_filter.mp hφ).2⟩ + · intro φ _ χ _ h + exact degree_restrict_injective u h + · intro v hv + have hv' := (Finset.mem_filter.mp hv).2 + have hne : u ≠ v := by + intro h + have hh := mem_completeGraph.mp (hG hv') + simp [h] at hh + obtain ⟨φ,hφ⟩ := degree_restrict_surj u v hne + refine ⟨φ,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩,hφ⟩ + exact (degree_image_subset u φ G).mpr (hφ.symm ▸ hv') + +@[simp] theorem degree_rootedScaling (n : ℕ) (p : ℝ) : + rootedScaling degreeTemplate n p = (n : ℝ)*p := by + simp [rootedScaling,degreeTemplate] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmbeddedWitnessPathSize.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmbeddedWitnessPathSize.lean new file mode 100644 index 0000000000000000000000000000000000000000..5bf61cb70290eeac08a32d2a13743318451753d1 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmbeddedWitnessPathSize.lean @@ -0,0 +1,104 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.LegalCollisionPairs +import OAI.Combinatorics.TriangleRemoval.Process.WitnessDimensions +import OAI.Combinatorics.TriangleRemoval.Queries.AddressHead +import OAI.Combinatorics.TriangleRemoval.Process.IndexedAttachmentOlder +import OAI.Combinatorics.TriangleRemoval.Process.ThreeChooseBound + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma embeddedWitness_path_size {n R d : ℕ} {G : Graph n} + (W : BoundedEmbeddedWitness G R d) : + let p := (embeddedWitnessPaths W).1 + let q := (embeddedWitnessPaths W).2 + (splitQueryPaths p q).1.length + (splitQueryPaths p q).2.1.length + + (splitQueryPaths p q).2.2.length = W.1.val.2.val := by + let q := W.1 + let w := W.2.2.1 + let ψ := W.2.2.2.val + let key := indexedTriangleKey (dimensionBirth q) w.2.2.val ψ + have hk : Function.Injective key := indexed_triangle_key_injective (fun _ => rfl) + W.2.1.property w.2.1.val w.2.2.val w.2.2.property ψ + exact w.2.1.val.two_mark_exact_size hk _ _ w.2.1.property + +lemma embeddedWitness_factorial_weight {n R d : ℕ} {G : Graph n} + (W : BoundedEmbeddedWitness G R d) {x : ℝ} (hx : 0 ≤ x) : + pairFactorialWeight x (embeddedWitnessPaths W).1 (embeddedWitnessPaths W).2 ≤ + (3*x)^W.1.val.2.val / (W.1.val.2.val.factorial : ℝ) := by + unfold pairFactorialWeight + have hh := total_three_segment_weight_le hx + (splitQueryPaths (embeddedWitnessPaths W).1 (embeddedWitnessPaths W).2).1.length + (splitQueryPaths (embeddedWitnessPaths W).1 (embeddedWitnessPaths W).2).2.1.length + (splitQueryPaths (embeddedWitnessPaths W).1 (embeddedWitnessPaths W).2).2.2.length + dsimp only + rw [embeddedWitness_path_size W] at hh ⊢ + exact hh + +section AnyPaths +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +lemma actualPairVisitProbability_zero_of_illegal (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (p q : List (ι × τ)) + (hbad : ¬ (p ∈ legalPaths H d focus parent ∧ q ∈ legalPaths H d focus parent)) : + actualPairVisitProbability H N d k focus parent p q = 0 := by + classical + rw [← log_pair_probability] + let P := ExposureTree.freshLog (gridPriorities N) (tracedGridQuery H N d k ⟨[],focus,parent⟩) + let ev := fun (z : (Bool × List (QueryCall ι τ)) × List τ) => + z.1.2.any (fun c => decide (c.address = p.reverse)) && + z.1.2.any (fun c => decide (c.address = q.reverse)) + have hnone : ∀ z ∈ P.support, ev z = false := by + intro z hz + apply Bool.eq_false_iff.mpr + intro he + obtain ⟨hp,hq⟩ := Bool.and_eq_true_iff.mp he + have hlegal (path : List (ι × τ)) (h : z.1.2.any (fun c => decide (c.address = path.reverse)) = true) : + path ∈ legalPaths H d focus parent := by + obtain ⟨a,ha,heq⟩ := List.any_eq_true.mp h + have haeq : a.address = path.reverse := of_decide_eq_true heq + obtain ⟨path',hp',ha'⟩ := tracedGridQuery_legal_path H N d k ⟨[],focus,parent⟩ + (gridPriorities N) hz a ha + rw [ha',callAtPath_address,List.append_nil] at haeq + have hh : path' = path := List.reverse_injective haeq + exact hh ▸ hp' + exact hbad ⟨hlegal p hp,hlegal q hq⟩ + have heq := pmf_map_congr_support P ev (fun _ => false) hnone + change ((P.map ev) true).toReal = 0 + rw [heq] + change ((P.map (Function.const _ false)) true).toReal = 0 + rw [PMF.map_const] + simp + +theorem actualPairVisitProbability_weight_any (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 1 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) (focus : Finset ι) (parent : Option τ) + (p q : List (ι × τ)) : + actualPairVisitProbability H N d k focus parent p q ≤ + C^3 * pairFactorialWeight (prefixWeight (fun t => (2/(N : ℝ))*b t) k) p q := by + by_cases h : p ∈ legalPaths H d focus parent ∧ q ∈ legalPaths H d focus parent + · exact actualPairVisitProbability_weight H N b hb hq C hC hlower d k hkd hkN focus parent p q h.1 h.2 + · rw [actualPairVisitProbability_zero_of_illegal H N d k focus parent p q h] + apply mul_nonneg (pow_nonneg (by linarith) _) + apply pairFactorialWeight_nonneg + apply Finset.sum_nonneg + intro t _ + exact mul_nonneg (by positivity) (hb t) + +end AnyPaths +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmbeddedWitnessRoots.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmbeddedWitnessRoots.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f9ccf5a370facb77703d985fb9fbd9578700b49 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmbeddedWitnessRoots.lean @@ -0,0 +1,92 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.MatchingSeedEdgeRoots +import OAI.Combinatorics.TriangleRemoval.Process.WitnessDimensions + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma matchingSeed_full_image {V : Type*} [DecidableEq V] {N R : ℕ} + (label : Fin N → V) (E : Finset (Finset V)) (hE : EdgeMatching E) + (hi : Set.InjOn label {v | v.val < R}) + (hc : ∀ e ∈ E, ∀ x ∈ e, ∃ v : Fin N, v.val < R ∧ label v = x) : + ((matchingSeed label E hE hi).backEdges (Finset.univ.filter (fun v => v.val < R))).image + (Finset.image label) = E := by + classical + apply Finset.Subset.antisymm + · intro e he + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he + exact matchingSeed_edge_image label E hE hi _ hf + · intro e he + obtain ⟨x,y,hx,hy,hxy,rfl⟩ := matchingSeed_covers label E hE hi hc e he + have hp : ({x,y} : Finset (Fin N)) ∈ + (matchingSeed label E hE hi).backEdges (Finset.univ.filter (fun v => v.val < R)) := by + rcases hxy with hxy | hyx + · exact Finset.mem_biUnion.mpr ⟨y,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hy⟩, + Finset.mem_image.mpr ⟨x,hxy,rfl⟩⟩ + · have hh : ({y,x} : Finset (Fin N)) ∈ + (matchingSeed label E hE hi).backEdges (Finset.univ.filter (fun v => v.val < R)) := + Finset.mem_biUnion.mpr ⟨x,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hx⟩, + Finset.mem_image.mpr ⟨y,hyx,rfl⟩⟩ + simpa only [Finset.pair_comm] using hh + exact Finset.mem_image.mpr ⟨{x,y},hp,by simp only [Finset.image_insert,Finset.image_singleton]⟩ + +namespace TriangleGrowth +variable {n N R : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N R) + +lemma pathRootEdges_image (a b : Fin N) (hi : Set.InjOn A.label (A.pathUnion a b)) : + (A.pathRootEdges a b).image (Finset.image (A.pathAssignment a b hi)) = + (A.seed.backEdges A.roots).image (Finset.image A.label) := by + classical + unfold pathRootEdges + rw [Finset.image_image] + apply Finset.image_congr + intro e he + have hs : e ⊆ A.pathUnion a b := by + obtain ⟨v,hv,u,hu,rfl⟩ := A.seed.backEdges_mem_pair he + have hvR : v.val < R := (Finset.mem_filter.mp hv).2 + have hul : u.val < v.val := A.seed.older_lt v u hu + have huR : u.val < R := hul.trans hvR + intro x hx + rcases Finset.mem_insert.mp hx with hx | hx + · subst x + exact (A.mem_pathUnion a b u).mpr (Or.inl huR) + · have hx' := Finset.mem_singleton.mp hx + subst x + exact (A.mem_pathUnion a b v).mpr (Or.inl hvR) + change (reindexSet (A.pathUnion a b) e).image + (fun i => A.label ((A.pathUnion a b).orderEmbOfFin rfl i)) = e.image A.label + change (reindexSet (A.pathUnion a b) e).image + (A.label ∘ (A.pathUnion a b).orderEmbOfFin rfl) = e.image A.label + rw [← Finset.image_image,image_reindexSet hs] + +end TriangleGrowth +namespace RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) + +lemma growth_seed_image (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) : + ((F.toTriangleGrowth hM hG).seed.backEdges (F.toTriangleGrowth hM hG).roots).image + (Finset.image (F.toTriangleGrowth hM hG).label) = c.focus := + matchingSeed_full_image F.vertexLabel c.focus hM F.vertexLabel_injective_roots F.vertexLabel_covers + +end RecordedCallForest + +noncomputable def embeddedWitnessRoots {n R d : ℕ} {G : Graph n} + (W : BoundedEmbeddedWitness G R d) : Graph n := + W.2.1.val.image (fun e => e.image W.2.2.2.val) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmptyRootInjection.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmptyRootInjection.lean new file mode 100644 index 0000000000000000000000000000000000000000..67087fb83b592a8240c84637c7e22de9bd7bcf33 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/EmptyRootInjection.lean @@ -0,0 +1,67 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.SparseScalingOne +import OAI.Combinatorics.TriangleRemoval.Embeddings.RestrictLabel + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +noncomputable def emptyRootInjection {k n : ℕ} (T : RootedTemplate k) (hT : T.roots = ∅) : + {x // x ∈ T.roots} ↪ Fin n where + toFun x := False.elim (by simpa [hT] using x.property) + inj' := by intro x; exact False.elim (by simpa [hT] using x.property) + +theorem rootedCount_empty_roots {k n : ℕ} (T : RootedTemplate k) (hT : T.roots = ∅) + (ψ : {x // x ∈ T.roots} ↪ Fin n) (G : Graph n) : + rootedCount T ψ G = ((graphEmbeddingSet T.edges G).card : ℝ) := by + classical + let e : RootedInjection T ψ ≃ (Fin k ↪ Fin n) := + { toFun := Subtype.val + invFun := fun φ => ⟨φ,fun x => False.elim (by simpa [hT] using x.property)⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + unfold rootedCount copyCount + calc + _ = ∑ φ : Fin k ↪ Fin n, intact (T.edges.image (fun e => e.map φ)) G := + Fintype.sum_equiv e _ _ (fun _ => rfl) + _ = _ := by simp [graphEmbeddingSet,intact] + +def unrootedTemplate {N : ℕ} (E : Graph N) (hE : ∀ e ∈ E, e.card = 2) : RootedTemplate N where + edges := E + roots := ∅ + simple := hE + independent := by + intro e he hemp + have hz : e = ∅ := Finset.subset_empty.mp hemp + have hh := hE e he + rw [hz,Finset.card_empty] at hh + omega + +theorem graphEmbeddingSet_large_count {n N : ℕ} {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (E : Graph N) (hE : ∀ e ∈ E, e.card = 2) + (hcap : N ≤ prefixTemplateCap) + (hsparse : ∀ U : Finset (Fin N), (E.filter (· ⊆ U)).card ≤ 2 * U.card) + (hp : 0 ≤ prefixDensity n) (hp1 : prefixDensity n ≤ 1) (hD : 1 ≤ prefixD n) : + ((graphEmbeddingSet E G).card : ℝ) ≤ + prefixTemplateFactor n C * ((n : ℝ)^N * prefixDensity n ^ E.card) := by + let T := unrootedTemplate E hE + let ψ := emptyRootInjection (n := n) T rfl + have h := (hGood.2.2.2.2.2 N hcap T ψ).1 + (largeTemplateEligible_of_sparse T rfl (prefixDensity n) hp hp1 hD hsparse) + rw [rootedCount_empty_roots T rfl ψ G] at h + simpa only [T,unrootedTemplate,rootedScaling,Finset.card_empty,Nat.sub_zero] using h + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/FixedEndpointPairInjective.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/FixedEndpointPairInjective.lean new file mode 100644 index 0000000000000000000000000000000000000000..26e0467ebe10affa4acc38b8cb6ad94b2ffc364b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/FixedEndpointPairInjective.lean @@ -0,0 +1,74 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.RelativeSafeCopyIncrement + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma fixedEndpoint_pair_injective {n : ℕ} (u : Fin n) : + Function.Injective (fun w : Fin n => ({u,w} : Finset (Fin n))) := by + intro a b h + change ({u,a} : Finset (Fin n)) = {u,b} at h + have ha : a = u ∨ a = b := by + have hh : a ∈ ({u,b} : Finset (Fin n)) := by rw [← h]; simp + simpa only [Finset.mem_insert,Finset.mem_singleton] using hh + have hb : b = u ∨ b = a := by + have hh : b ∈ ({u,a} : Finset (Fin n)) := by rw [h]; simp + simpa only [Finset.mem_insert,Finset.mem_singleton] using hh + aesop + +theorem wedge_copyEdgeLoad_le_two {n : ℕ} (u v : Fin n) (G : Graph n) + (e : Finset (Fin n)) : copyEdgeLoad (wedgeEdges u v) G e ≤ 2 := by + classical + let A (x : Fin n) := Finset.univ.filter (fun w : Fin n => e = ({x,w} : Finset (Fin n))) + have hA (x : Fin n) : (A x).card ≤ 1 := by + apply Finset.card_le_one.mpr + intro a ha b hb + apply fixedEndpoint_pair_injective x + exact ((Finset.mem_filter.mp ha).2).symm.trans (Finset.mem_filter.mp hb).2 + have hf : Finset.univ.filter (fun w : Fin n => e ∈ wedgeEdges u v w) = A u ∪ A v := by + ext w + simp [A,wedgeEdges] + have hc : (Finset.univ.filter (fun w : Fin n => e ∈ wedgeEdges u v w)).card ≤ 2 := by + rw [hf] + exact (Finset.card_union_le _ _).trans (by have := hA u; have := hA v; omega) + unfold copyEdgeLoad + calc + _ ≤ ∑ w : Fin n, if e ∈ wedgeEdges u v w then (1 : ℝ) else 0 := by + apply Finset.sum_le_sum + intro w _ + by_cases h : e ∈ wedgeEdges u v w + · rw [ite_eq_left h,ite_eq_left h] + unfold intact + split <;> norm_num + · rw [ite_eq_right h,ite_eq_right h] + _ = ((Finset.univ.filter (fun w : Fin n => e ∈ wedgeEdges u v w)).card : ℝ) := by + rw [← Finset.sum_filter] + simp + _ ≤ 2 := by exact_mod_cast hc + +lemma wedge_copyLoadSafe {n : ℕ} (u v : Fin n) (G : Graph n) : + copyLoadSafe (wedgeEdges u v) 2 G := by + intro e _ + exact wedge_copyEdgeLoad_le_two u v G e + +lemma wedge_pastRelativeCopyLoadsSafe {n : ℕ} (u v : Fin n) (T j : ℕ) + (ω : History (Graph n) T) : + pastRelativeCopyLoadsSafe (wedgeEdges u v) (fun _ => 2) T j ω := by + intro k _ + exact wedge_copyLoadSafe u v _ + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/GraphEmbeddings.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/GraphEmbeddings.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f04975fe4b6aedfd9e8a96bccd629a11e18427b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/GraphEmbeddings.lean @@ -0,0 +1,146 @@ +import Mathlib + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators NNReal +open Matrix +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix InnerProductSpace +open scoped BigOperators + +namespace SharpTerminalLeave + +section RootExtension +variable {A V : Type*} [Fintype A] [DecidableEq A] [Fintype V] [DecidableEq V] +variable (H : SimpleGraph A) (G : SimpleGraph V) + +noncomputable def graphEmbeddings : Finset (A ↪ V) := by + classical + exact Finset.univ.filter (fun f => ∀ a b, H.Adj a b → G.Adj (f a) (f b)) + +noncomputable def rootedEmbeddingFiber (S : Finset A) (ψ : A → V) : Finset (A ↪ V) := by + classical + exact (graphEmbeddings H G).filter (fun f => ∀ a ∈ S, f a = ψ a) + +variable {H G} + +omit [DecidableEq A] [DecidableEq V] in +lemma mem_graphEmbeddings (f : A ↪ V) : + f ∈ graphEmbeddings H G ↔ ∀ a b, H.Adj a b → G.Adj (f a) (f b) := by + classical + simp only [graphEmbeddings, Finset.mem_filter, Finset.mem_univ, true_and] + +lemma mem_rootedEmbeddingFiber (S : Finset A) (ψ : A → V) (f : A ↪ V) : + f ∈ rootedEmbeddingFiber H G S ψ ↔ + f ∈ graphEmbeddings H G ∧ ∀ a ∈ S, f a = ψ a := by + classical + simp only [rootedEmbeddingFiber, Finset.mem_filter] + +omit [Fintype A] in + +lemma walk_crosses_finset {a b : A} (p : H.Walk a b) (S : Finset A) + (ha : a ∈ S) (hb : b ∉ S) : + ∃ x ∈ S, ∃ y ∉ S, H.Adj x y := by + induction p with + | nil => exact False.elim (hb ha) + | @cons a c b hac p ih => + by_cases hc : c ∈ S + · exact ih hc hb + · exact ⟨a, ha, c, hc, hac⟩ + +lemma connected_crosses_finset (hH : H.Preconnected) (S : Finset A) + (hS : S.Nonempty) (hSc : Sᶜ.Nonempty) : + ∃ x ∈ S, ∃ y ∉ S, H.Adj x y := by + obtain ⟨a, ha⟩ := hS + obtain ⟨b, hb⟩ := hSc + obtain ⟨p⟩ := hH a b + exact walk_crosses_finset p S ha (Finset.mem_compl.mp hb) + +lemma root_fiber_fix_one (S : Finset A) (ψ : A → V) (v : A) (hv : v ∉ S) (z : V) : + ((rootedEmbeddingFiber H G S ψ).filter (fun f => f v = z)) = + rootedEmbeddingFiber H G (insert v S) (Function.update ψ v z) := by + classical + ext f + simp only [Finset.mem_filter, mem_rootedEmbeddingFiber] + constructor + · rintro ⟨⟨hf, hψ⟩, hz⟩ + refine ⟨hf, ?_⟩ + intro a ha + rcases Finset.mem_insert.mp ha with rfl | ha + · simpa using hz + · rw [Function.update_of_ne (ne_of_mem_of_not_mem ha hv)] + exact hψ a ha + · rintro ⟨hf, hψ⟩ + refine ⟨⟨hf, ?_⟩, ?_⟩ + · intro a ha + have hh := hψ a (Finset.mem_insert_of_mem ha) + simpa [Function.update_of_ne (ne_of_mem_of_not_mem ha hv)] using hh + · simpa using hψ v (Finset.mem_insert_self _ _) + +variable [DecidableRel G.Adj] + +theorem rootedEmbeddingFiber_le (hH : H.Preconnected) (Δ : ℕ) + (hΔ : ∀ x : V, (Finset.univ.filter (G.Adj x)).card ≤ Δ) + (S : Finset A) (hS : S.Nonempty) (ψ : A → V) : + (rootedEmbeddingFiber H G S ψ).card ≤ Δ ^ Sᶜ.card := by + classical + induction hm : Sᶜ.card using Nat.strong_induction_on generalizing S ψ with + | h m ih => + rw [← hm] + by_cases hzero : Sᶜ.card = 0 + · have hSuniv : S = Finset.univ := by + apply Finset.eq_univ_iff_forall.mpr + intro a + by_contra ha + have : a ∈ Sᶜ := Finset.mem_compl.mpr ha + rw [Finset.card_eq_zero.mp hzero] at this + exact Finset.notMem_empty a this + rw [hzero, pow_zero] + apply Finset.card_le_one.mpr + intro f hf g hg + apply Function.Embedding.ext + intro a + have hf' := (mem_rootedEmbeddingFiber S ψ f).mp hf + have hg' := (mem_rootedEmbeddingFiber S ψ g).mp hg + rw [hf'.2 a (by simp [hSuniv]), hg'.2 a (by simp [hSuniv])] + · have hSc : Sᶜ.Nonempty := Finset.card_pos.mp (Nat.pos_of_ne_zero hzero) + obtain ⟨u, hu, v, hv, huv⟩ := connected_crosses_finset hH S hS hSc + let t : Finset V := Finset.univ.filter (G.Adj (ψ u)) + have ht : ∀ f ∈ rootedEmbeddingFiber H G S ψ, f v ∈ t := by + intro f hf + obtain ⟨hf, hr⟩ := (mem_rootedEmbeddingFiber S ψ f).mp hf + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _, ?_⟩ + rw [← hr u hu] + exact (mem_graphEmbeddings f).mp hf u v huv + have hcard : (insert v S)ᶜ.card + 1 = Sᶜ.card := by + rw [Finset.compl_insert, Finset.card_erase_of_mem (Finset.mem_compl.mpr hv)] + exact Nat.sub_add_cancel (Finset.card_pos.mpr hSc) + have hfib : ∀ z ∈ t, + ((rootedEmbeddingFiber H G S ψ).filter (fun f => f v = z)).card ≤ + Δ ^ (insert v S)ᶜ.card := by + intro z _ + rw [root_fiber_fix_one S ψ v hv z] + exact ih (insert v S)ᶜ.card (by omega) (insert v S) + (Finset.insert_nonempty _ _) (Function.update ψ v z) rfl + calc + _ = ∑ z ∈ t, ((rootedEmbeddingFiber H G S ψ).filter (fun f => f v = z)).card := + Finset.card_eq_sum_card_fiberwise ht + _ ≤ ∑ _z ∈ t, Δ ^ (insert v S)ᶜ.card := Finset.sum_le_sum hfib + _ = t.card * Δ ^ (insert v S)ᶜ.card := by simp + _ ≤ Δ * Δ ^ (insert v S)ᶜ.card := Nat.mul_le_mul_right _ (hΔ (ψ u)) + _ = Δ ^ Sᶜ.card := by rw [← hcard, pow_succ'] + +end RootExtension +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/GraphEmbeddingsRestriction.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/GraphEmbeddingsRestriction.lean new file mode 100644 index 0000000000000000000000000000000000000000..953410f6a49cd4556515743c56591490c451850a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/GraphEmbeddingsRestriction.lean @@ -0,0 +1,113 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.GraphEmbeddings + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators NNReal +open Matrix +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix InnerProductSpace +open scoped BigOperators + +namespace SharpTerminalLeave +section EmbeddingCyclicSeed +variable {A B V : Type*} [Fintype A] [DecidableEq A] [Fintype B] [DecidableEq B] + [Fintype V] [DecidableEq V] +variable (H : SimpleGraph A) (G : SimpleGraph V) [DecidableRel G.Adj] + +omit [DecidableEq B] in + +theorem graphEmbeddings_restriction_le (hH : H.Preconnected) (Δ : ℕ) + (hΔ : ∀ x : V, (Finset.univ.filter (G.Adj x)).card ≤ Δ) + (c : B ↪ A) (hB : Nonempty B) (t : Finset (B ↪ V)) + (ht : ∀ f ∈ graphEmbeddings H G, c.trans f ∈ t) : + (graphEmbeddings H G).card ≤ t.card * Δ ^ (Fintype.card A - Fintype.card B) := by + classical + let S : Finset A := Finset.univ.map c + have hS : S.Nonempty := by + obtain ⟨b⟩ := hB + exact ⟨c b, Finset.mem_map.mpr ⟨b, Finset.mem_univ _, rfl⟩⟩ + have hSc : Sᶜ.card = Fintype.card A - Fintype.card B := by + simp [S, Finset.card_compl] + have hfib : ∀ χ ∈ t, + ((graphEmbeddings H G).filter (fun f => c.trans f = χ)).card ≤ + Δ ^ (Fintype.card A - Fintype.card B) := by + intro χ _ + let sf := (graphEmbeddings H G).filter (fun f => c.trans f = χ) + by_cases hs : sf.Nonempty + · obtain ⟨f₀, hf₀⟩ := hs + have hcomp := (Finset.mem_filter.mp hf₀).2 + have heq : sf = rootedEmbeddingFiber H G S f₀ := by + ext f + simp only [sf, Finset.mem_filter, mem_rootedEmbeddingFiber] + constructor + · rintro ⟨hf, he⟩ + refine ⟨hf, ?_⟩ + intro a ha + obtain ⟨b, _, rfl⟩ := Finset.mem_map.mp ha + have hh := congrArg (fun χ : B ↪ V => χ b) (he.trans hcomp.symm) + exact hh + · rintro ⟨hf, he⟩ + refine ⟨hf, ?_⟩ + rw [← hcomp] + apply Function.Embedding.ext + intro b + exact he (c b) (Finset.mem_map.mpr ⟨b, Finset.mem_univ _, rfl⟩) + change sf.card ≤ _ + rw [heq, ← hSc] + exact rootedEmbeddingFiber_le hH Δ hΔ S hS f₀ + · have he : sf = ∅ := Finset.not_nonempty_iff_eq_empty.mp hs + change sf.card ≤ _ + rw [he, Finset.card_empty] + exact Nat.zero_le _ + calc + _ = ∑ χ ∈ t, ((graphEmbeddings H G).filter (fun f => c.trans f = χ)).card := + Finset.card_eq_sum_card_fiberwise ht + _ ≤ ∑ _χ ∈ t, Δ ^ (Fintype.card A - Fintype.card B) := Finset.sum_le_sum hfib + _ = _ := by simp + +theorem connected_embedding_count (hH : H.Preconnected) (a : A) (Δ : ℕ) + (hΔ : ∀ x : V, (Finset.univ.filter (G.Adj x)).card ≤ Δ) : + (graphEmbeddings H G).card ≤ Fintype.card V * Δ ^ (Fintype.card A - 1) := by + classical + let c : Unit ↪ A := ⟨fun _ => a, fun _ _ _ => Subsingleton.elim _ _⟩ + have hh := graphEmbeddings_restriction_le H G hH Δ hΔ c inferInstance + Finset.univ (fun _ _ => Finset.mem_univ _) + have hunit : Fintype.card (Unit ↪ V) = Fintype.card V := by + let e : (Unit ↪ V) ≃ V := + { toFun := fun f => f () + invFun := fun v => ⟨fun _ => v, fun _ _ _ => Subsingleton.elim _ _⟩ + left_inv := by intro f; ext x; cases x; rfl + right_inv := fun _ => rfl } + exact Fintype.card_congr e + simpa only [Finset.card_univ, Fintype.card_unit, hunit] using hh + +omit [DecidableEq B] in + +theorem cyclic_seed_embedding_count (hH : H.Preconnected) (K : SimpleGraph B) + (c : B ↪ A) (hB : Nonempty B) + (hc : ∀ b b', K.Adj b b' → H.Adj (c b) (c b')) (Δ : ℕ) + (hΔ : ∀ x : V, (Finset.univ.filter (G.Adj x)).card ≤ Δ) : + (graphEmbeddings H G).card ≤ + (graphEmbeddings K G).card * Δ ^ (Fintype.card A - Fintype.card B) := by + apply graphEmbeddings_restriction_le H G hH Δ hΔ c hB (graphEmbeddings K G) + intro f hf + apply (mem_graphEmbeddings (c.trans f)).mpr + intro b b' hb + exact (mem_graphEmbeddings f).mp hf _ _ (hc b b' hb) + +end EmbeddingCyclicSeed +end SharpTerminalLeave + +open scoped BigOperators + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/PathBirthIndex.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/PathBirthIndex.lean new file mode 100644 index 0000000000000000000000000000000000000000..1652c67d9fa1b4569c745c740f310a73315fdd87 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/PathBirthIndex.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Process.NonrootForest +import OAI.Combinatorics.TriangleRemoval.Process.PathPattern +import OAI.Combinatorics.TriangleRemoval.Process.ValidIndexedAttachments +import OAI.Combinatorics.TriangleRemoval.Coupling.OrderedSuffix + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma reindexSet_pair {N : ℕ} (S : Finset (Fin N)) (x y : Fin N) + (hx : x ∈ S) (hy : y ∈ S) : + reindexSet S {x,y} = {PathForest.index S x hx,PathForest.index S y hy} := by + ext i + simp only [mem_reindexSet,Finset.mem_insert,Finset.mem_singleton] + have hxi : S.orderEmbOfFin rfl i = x ↔ i = PathForest.index S x hx := by + simpa only [PathForest.embed_index] using + ((S.orderEmbOfFin rfl).injective.eq_iff (a := i) (b := PathForest.index S x hx)) + have hyi : S.orderEmbOfFin rfl i = y ↔ i = PathForest.index S y hy := by + simpa only [PathForest.embed_index] using + ((S.orderEmbOfFin rfl).injective.eq_iff (a := i) (b := PathForest.index S y hy)) + rw [hxi,hyi] + +lemma PathForest.restrict_parent_none {s : ℕ} (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) (i : Fin S.card) : + (F.restrict S hS).parent i = none ↔ F.parent (S.orderEmbOfFin rfl i) = none := by + classical + change F.restrictedParent S hS i = none ↔ _ + unfold PathForest.restrictedParent + split <;> simp_all + +namespace TriangleGrowth +variable {n N R : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N R) + +lemma suffix_eq_ordered (a b : Fin N) : A.pathSuffix a b R = orderedSuffix (A.pathUnion a b) R := rfl + +noncomputable def pathBirthIndex (a b : Fin N) (hR : R ≤ N) + (i : Fin (A.pathSuffix a b R).card) : Fin (A.pathUnion a b).card := + suffixFullIndex (A.pathUnion a b) hR + (fun x hx => (A.mem_pathUnion a b x).mpr (Or.inl hx)) i + +@[simp] lemma pathBirthIndex_val (a b : Fin N) (hR : R ≤ N) + (i : Fin (A.pathSuffix a b R).card) : (A.pathBirthIndex a b hR i).val = R+i.val := rfl + +@[simp] lemma pathBirthIndex_embedding (a b : Fin N) (hR : R ≤ N) + (i : Fin (A.pathSuffix a b R).card) : + (A.pathUnion a b).orderEmbOfFin rfl (A.pathBirthIndex a b hR i) = + (A.pathSuffix a b R).orderEmbOfFin rfl i := + suffix_full_embedding _ hR _ i + +noncomputable def pathAttachments (a b : Fin N) (hR : R ≤ N) + (i : Fin (A.pathSuffix a b R).card) : Finset (Fin (A.pathUnion a b).card) := + (A.pathPattern a b).older (A.pathBirthIndex a b hR i) + +lemma pathAttachments_eq (a b : Fin N) (hR : R ≤ N) + (i : Fin (A.pathSuffix a b R).card) : + A.pathAttachments a b hR i = reindexSet (A.pathUnion a b) + (A.older ((A.pathSuffix a b R).orderEmbOfFin rfl i)) := by + change reindexSet _ (A.older ((A.pathUnion a b).orderEmbOfFin rfl _)) = _ + rw [A.pathBirthIndex_embedding] + +noncomputable def pathRootEdges (a b : Fin N) : Finset (Finset (Fin (A.pathUnion a b).card)) := + (A.seed.backEdges A.roots).image (reindexSet (A.pathUnion a b)) + +lemma pathForest_parent_some (a b : Fin N) (i j : Fin (A.pathSuffix a b R).card) : + (A.pathForest a b).parent i = some j ↔ + A.parent ((A.pathSuffix a b R).orderEmbOfFin rfl i) = + some ((A.pathSuffix a b R).orderEmbOfFin rfl j) := by + rw [pathForest,PathForest.restrict_parent_some] + change (if R ≤ _ then _ else none) = _ ↔ _ + rw [ite_eq_left ((A.mem_pathSuffix a b _ R).mp + ((A.pathSuffix a b R).orderEmbOfFin_mem rfl i)).2] + +lemma pathForest_parent_none (a b : Fin N) (i : Fin (A.pathSuffix a b R).card) : + (A.pathForest a b).parent i = none ↔ + A.parent ((A.pathSuffix a b R).orderEmbOfFin rfl i) = none := by + rw [pathForest,PathForest.restrict_parent_none] + change (if R ≤ _ then _ else none) = _ ↔ _ + rw [ite_eq_left ((A.mem_pathSuffix a b _ R).mp + ((A.pathSuffix a b R).orderEmbOfFin_mem rfl i)).2] + +theorem pathAttachments_valid (a b : Fin N) (hR : R ≤ N) : + ValidIndexedAttachments (A.pathRootEdges a b) (A.pathBirthIndex a b hR) + (A.pathForest a b) (A.pathAttachments a b hR) := by + classical + constructor + · intro i + exact le_of_eq (A.pathPattern_nonroot a b _ (by simp only [pathBirthIndex_val]; omega)) + · intro i + have hiv := (A.pathSuffix a b R).orderEmbOfFin_mem rfl i + have hiR := ((A.mem_pathSuffix a b _ R).mp hiv).2 + cases hp : (A.pathForest a b).parent i with + | none => + have hpar := (A.pathForest_parent_none a b i).mp hp + obtain ⟨x,y,hx,hy,hxy,he⟩ := A.older_pair_of_root hiR hpar + have hem : ({x,y} : Finset (Fin N)) ∈ A.seed.backEdges A.roots := by + rcases hxy with hxy | hyx + · exact Finset.mem_biUnion.mpr ⟨y,(A.mem_roots y).mpr hy, + Finset.mem_image.mpr ⟨x,hxy,rfl⟩⟩ + · have hh : ({y,x} : Finset (Fin N)) ∈ A.seed.backEdges A.roots := + Finset.mem_biUnion.mpr ⟨x,(A.mem_roots x).mpr hx, + Finset.mem_image.mpr ⟨y,hyx,rfl⟩⟩ + simpa only [Finset.pair_comm] using hh + change A.pathAttachments a b hR i ∈ A.pathRootEdges a b + rw [A.pathAttachments_eq,he] + exact Finset.mem_image.mpr ⟨{x,y},hem,rfl⟩ + | some j => + have hpar := (A.pathForest_parent_some a b i j).mp hp + obtain ⟨u,hu,he⟩ := A.older_focus hiR hpar + have hjP := ((A.mem_pathSuffix a b _ R).mp + ((A.pathSuffix a b R).orderEmbOfFin_mem rfl j)).1 + have huP := A.pathUnion_older_closed hjP hu + let k := PathForest.index (A.pathUnion a b) u huP + refine ⟨k,?_,?_⟩ + · rw [A.pathAttachments_eq] + apply (mem_reindexSet _ _ _).mpr + simpa only [k,PathForest.embed_index] using hu + · rw [A.pathAttachments_eq,he,reindexSet_pair _ _ _ hjP huP] + have hj : PathForest.index (A.pathUnion a b) + ((A.pathSuffix a b R).orderEmbOfFin rfl j) hjP = A.pathBirthIndex a b hR j := by + apply (A.pathUnion a b).orderEmbOfFin rfl |>.injective + rw [PathForest.embed_index,A.pathBirthIndex_embedding] + rw [hj] + +end TriangleGrowth +end SharpTerminalLeave + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/ReindexEmbedding.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/ReindexEmbedding.lean new file mode 100644 index 0000000000000000000000000000000000000000..32b3d5611c690ddfa7c90c330d5fae572ebd19a7 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/ReindexEmbedding.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ReindexSet + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def reindexEmbedding {N n : ℕ} (s : Finset (Fin N)) (φ : Fin N ↪ Fin n) : + Fin s.card ↪ Fin n := (s.orderEmbOfFin rfl).toEmbedding.trans φ + +@[simp] lemma reindexEmbedding_apply {N n : ℕ} (s : Finset (Fin N)) + (φ : Fin N ↪ Fin n) (i : Fin s.card) : + reindexEmbedding s φ i = φ (s.orderEmbOfFin rfl i) := rfl + +lemma reindexEdges_map {N n : ℕ} {s e : Finset (Fin N)} (he : e ⊆ s) + (φ : Fin N ↪ Fin n) : + (reindexSet s e).map (reindexEmbedding s φ) = e.map φ := by + ext x + simp only [Finset.mem_map] + constructor + · rintro ⟨i,hi,rfl⟩ + exact ⟨s.orderEmbOfFin rfl i,(mem_reindexSet s e i).mp hi,rfl⟩ + · rintro ⟨v,hv,rfl⟩ + rw [← image_reindexSet he] at hv + obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp hv + exact ⟨i,hi,rfl⟩ + +def boundaryInjection {N n : ℕ} (s I P : Finset (Fin N)) (hIP : I ⊆ P) + (ξ : {x // x ∈ P} ↪ Fin n) : {i // i ∈ reindexSet s I} ↪ Fin n where + toFun i := ξ ⟨s.orderEmbOfFin rfl i, hIP ((mem_reindexSet s I i).mp i.property)⟩ + inj' := by + intro i j hij + apply Subtype.ext + exact (s.orderEmbOfFin rfl).injective + (congrArg (fun x : {x // x ∈ P} => x.val) (ξ.injective hij)) + +theorem graphEmbedding_fiber_le_rootedCount {N n : ℕ} + (s I P : Finset (Fin N)) (E F : Graph N) (G : Graph n) + (hE : ∀ e ∈ E, e ⊆ s) (hsimple : ∀ e ∈ E, e.card = 2) + (hind : ∀ e ∈ E, ¬ e ⊆ I) (hIP : I ⊆ P) + (hcover : P ∪ s = Finset.univ) (hEF : E ⊆ F) + (ξ : {x // x ∈ P} ↪ Fin n) : + (((Finset.univ.filter (fun φ : Fin N ↪ Fin n => + (∀ x : {x // x ∈ P}, φ x = ξ x) ∧ F.image (fun e => e.map φ) ⊆ G)).card : ℕ) : ℝ) ≤ + rootedCount (reindexTemplate s E I hE hsimple hind) + (boundaryInjection s I P hIP ξ) G := by + classical + let T := reindexTemplate s E I hE hsimple hind + let ψ := boundaryInjection s I P hIP ξ + let A := Finset.univ.filter (fun φ : Fin N ↪ Fin n => + (∀ x : {x // x ∈ P}, φ x = ξ x) ∧ F.image (fun e => e.map φ) ⊆ G) + let B := Finset.univ.filter (fun φ : RootedInjection T ψ => imageEdges T φ.val ⊆ G) + have hf (φ : Fin N ↪ Fin n) (hφ : φ ∈ A) : + ∀ i : {i // i ∈ T.roots}, reindexEmbedding s φ i = ψ i := by + intro i + exact (Finset.mem_filter.mp hφ).2.1 + ⟨s.orderEmbOfFin rfl i,hIP ((mem_reindexSet s I i).mp i.property)⟩ + let f (φ : {φ // φ ∈ A}) : RootedInjection T ψ := + ⟨reindexEmbedding s φ.val,hf φ.val φ.property⟩ + have hfmem (φ : {φ // φ ∈ A}) : f φ ∈ B := by + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _,?_⟩ + intro e he + obtain ⟨es,hes,rfl⟩ := Finset.mem_image.mp he + change es ∈ E.image (reindexSet s) at hes + obtain ⟨ef,hef,rfl⟩ := Finset.mem_image.mp hes + change (reindexSet s ef).map (reindexEmbedding s φ.val) ∈ G + rw [reindexEdges_map (hE ef hef)] + exact (Finset.mem_filter.mp φ.property).2.2 + (Finset.mem_image.mpr ⟨ef,hEF hef,rfl⟩) + have hfinj : Function.Injective f := by + intro φ χ heq + apply Subtype.ext + apply Function.Embedding.ext + intro x + have hx : x ∈ P ∪ s := by rw [hcover]; exact Finset.mem_univ _ + rcases Finset.mem_union.mp hx with hxP | hxs + · exact ((Finset.mem_filter.mp φ.property).2.1 ⟨x,hxP⟩).trans + ((Finset.mem_filter.mp χ.property).2.1 ⟨x,hxP⟩).symm + · obtain ⟨i,hi⟩ := (s.orderIsoOfFin rfl).surjective ⟨x,hxs⟩ + have hix : s.orderEmbOfFin rfl i = x := congrArg Subtype.val hi + have hh := congrArg (fun y : RootedInjection T ψ => y.val i) heq + change φ.val (s.orderEmbOfFin rfl i) = χ.val (s.orderEmbOfFin rfl i) at hh + rwa [hix] at hh + have hcard : A.card ≤ B.card := by + simpa only [Fintype.card_coe] using Fintype.card_le_of_injective + (fun φ : {φ // φ ∈ A} => (⟨f φ,hfmem φ⟩ : {χ // χ ∈ B})) + (fun φ χ h => hfinj (congrArg Subtype.val h)) + have hcount : rootedCount T ψ G = (B.card : ℝ) := by + simp [rootedCount,copyCount,intact,B] + change (A.card : ℝ) ≤ rootedCount T ψ G + rw [hcount] + exact_mod_cast hcard + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RerootTemplate.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RerootTemplate.lean new file mode 100644 index 0000000000000000000000000000000000000000..09d259668151cb023f0d8688b0b26d524bffc267 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RerootTemplate.lean @@ -0,0 +1,228 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.RootedCompletionMax + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Classical Filter + +namespace SharpTerminalLeave + +def rerootTemplate {k : ℕ} (T : RootedTemplate k) (J : Finset (Fin k)) : RootedTemplate k where + edges := T.edges.filter (fun e => ¬ e ⊆ J) + roots := J + simple := fun e he => T.simple e (Finset.mem_filter.mp he).1 + independent := fun _e he => (Finset.mem_filter.mp he).2 + +lemma rerootTemplate_image_subset {k n : ℕ} (T : RootedTemplate k) + (J : Finset (Fin k)) (φ : Fin k ↪ Fin n) : + imageEdges (rerootTemplate T J) φ ⊆ imageEdges T φ := by + exact Finset.image_subset_image (Finset.filter_subset _ _) + +lemma rerootTemplate_remaining {k : ℕ} (T : RootedTemplate k) + (J K : Finset (Fin k)) (hJK : J ⊆ K) : + (rerootTemplate T J).edges.card- + ((rerootTemplate T J).edges.filter (· ⊆ K)).card = + T.edges.card-(T.edges.filter (· ⊆ K)).card := by + rw [← Finset.card_sdiff_of_subset (Finset.filter_subset _ _), + ← Finset.card_sdiff_of_subset (Finset.filter_subset _ _)] + congr 1 + ext e + simp only [rerootTemplate,Finset.mem_sdiff,Finset.mem_filter] + constructor + · rintro ⟨⟨he,hJ⟩,hK⟩ + exact ⟨he,fun hk => hK ⟨⟨he,hJ⟩,hk.2⟩⟩ + · rintro ⟨he,hK⟩ + have hnK : ¬ e ⊆ K := fun hk => hK ⟨he,hk⟩ + exact ⟨⟨he,fun hj => hnK (hj.trans hJK)⟩,fun hk => hnK hk.2⟩ + +def RootedTwoBalanced {k : ℕ} (T : RootedTemplate k) : Prop := + ∀ J : Finset (Fin k), T.roots ⊆ J → + (T.edges.filter (· ⊆ J)).card ≤ 2*(J.card-T.roots.card) + +lemma balanced_overlap_scale {k n : ℕ} (T : RootedTemplate k) + (hT : RootedTwoBalanced T) {p : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) + (J : Finset (Fin k)) (hJ : T.roots ⊆ J) : + ((n : ℝ)*p^2)^(J.card-T.roots.card) ≤ + (n : ℝ)^(J.card-T.roots.card)*p^(T.edges.filter (· ⊆ J)).card := by + rw [mul_pow,← pow_mul] + exact mul_le_mul_of_nonneg_left + (pow_le_pow_of_le_one hp hp1 (hT J hJ)) (by positivity) + +lemma balanced_completion_bound {k n : ℕ} (T : RootedTemplate k) + (hT : RootedTwoBalanced T) {p : ℝ} (hp : 0 < p) (hp1 : p ≤ 1) + (hD : 1 ≤ (n : ℝ)*p^2) (J : Finset (Fin k)) + (hJ : T.roots ⊆ J) (hJ' : T.roots.card < J.card) : + (n : ℝ)^(k-J.card)*p^(T.edges.card-(T.edges.filter (· ⊆ J)).card) ≤ + rootedScaling T n p/((n : ℝ)*p^2) := by + have hD0 : 0 < (n : ℝ)*p^2 := lt_of_lt_of_le zero_lt_one hD + apply (le_div_iff₀ hD0).mpr + rw [← rooted_completion_factorization T J hJ p] + have hl : (n : ℝ)*p^2 ≤ + (n : ℝ)^(J.card-T.roots.card)*p^(T.edges.filter (· ⊆ J)).card := by + apply le_trans _ (balanced_overlap_scale T hT hp.le hp1 J hJ) + simpa only [pow_one] using (pow_le_pow_right₀ hD (show 1 ≤ J.card-T.roots.card by omega)) + exact (mul_le_mul_of_nonneg_left hl (by positivity)).trans_eq (mul_comm _ _) + +theorem balanced_reroot_completion_bound {k n : ℕ} (T : RootedTemplate k) + (hT : RootedTwoBalanced T) {p : ℝ} (hp : 0 < p) (hp1 : p ≤ 1) + (hD : 1 ≤ (n : ℝ)*p^2) (J : Finset (Fin k)) + (hJ : T.roots ⊆ J) (hJ' : T.roots.card < J.card) : + rootedCompletionMax (rerootTemplate T J) n p ≤ rootedScaling T n p/((n : ℝ)*p^2) := by + have h1 : 1 ≤ rootedScaling T n p/((n : ℝ)*p^2) := by + have hk : T.roots.card < (Finset.univ : Finset (Fin k)).card := + lt_of_lt_of_le hJ' (Finset.card_le_card (Finset.subset_univ J)) + simpa using balanced_completion_bound T hT hp hp1 hD Finset.univ (Finset.subset_univ _) hk + apply Finset.sup'_le + intro K _ + split_ifs with hK + · change J ⊆ K at hK + rw [rerootTemplate_remaining T J K hK] + exact balanced_completion_bound T hT hp hp1 hD K (hJ.trans hK) + (hJ'.trans_le (Finset.card_le_card hK)) + · exact h1 + +lemma fintype_sum_le_injection {α β : Type*} [Fintype α] [Fintype β] + (e : α → β) (he : Function.Injective e) (f : α → ℝ) (g : β → ℝ) + (hfg : ∀ a, f a ≤ g (e a)) (hg : ∀ b, 0 ≤ g b) : + ∑ a, f a ≤ ∑ b, g b := by + calc + _ ≤ ∑ a, g (e a) := Finset.sum_le_sum (fun a _ => hfg a) + _ = ∑ b ∈ Finset.univ.image e, g b := (Finset.sum_image (fun a _ b _ h => he h)).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun b _ _ => hg b) + +abbrev RootedEdgePin {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (f : Finset (Fin k)) (e : Finset (Fin n)) := + {ξ : {v // v ∈ T.roots ∪ f} ↪ Fin n // + (∀ r : {v // v ∈ T.roots}, ξ ⟨r.val,Finset.mem_union_left _ r.property⟩ = ψ r) ∧ + ∀ v : {v // v ∈ f}, ξ ⟨v.val,Finset.mem_union_right _ v.property⟩ ∈ e} + +lemma rootedEdgePin_card {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (f : Finset (Fin k)) (e : Finset (Fin n)) : + Fintype.card (RootedEdgePin T ψ f e) ≤ e.card^f.card := by + let enc : RootedEdgePin T ψ f e → (f → e) := fun ξ v => + ⟨ξ.val ⟨v.val,Finset.mem_union_right _ v.property⟩,ξ.property.2 v⟩ + have hinj : Function.Injective enc := by + intro ξ χ hh + apply Subtype.ext + apply DFunLike.ext + intro v + rcases Finset.mem_union.mp v.property with hv | hv + · exact (ξ.property.1 ⟨v.val,hv⟩).trans (χ.property.1 ⟨v.val,hv⟩).symm + · exact congrArg Subtype.val (congrFun hh ⟨v.val,hv⟩) + simpa only [Fintype.card_fun,Fintype.card_coe] using Fintype.card_le_of_injective enc hinj + +def rootedEdgeFiberEncoding {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (f : Finset (Fin k)) (e : Finset (Fin n)) + (φ : {φ : RootedInjection T ψ // f.map φ.val = e}) : + Σ ξ : RootedEdgePin T ψ f e, RootedInjection (rerootTemplate T (T.roots ∪ f)) ξ.val := by + let ξ : {v // v ∈ T.roots ∪ f} ↪ Fin n := + ⟨fun v => φ.val.val v,fun _ _ h => Subtype.ext (φ.val.val.injective h)⟩ + have hξ : (∀ r : {v // v ∈ T.roots}, ξ ⟨r.val,Finset.mem_union_left _ r.property⟩ = ψ r) ∧ + ∀ v : {v // v ∈ f}, ξ ⟨v.val,Finset.mem_union_right _ v.property⟩ ∈ e := by + refine ⟨fun r => φ.val.property r,?_⟩ + intro v + rw [← φ.property] + exact Finset.mem_map.mpr ⟨v.val,v.property,rfl⟩ + exact ⟨⟨ξ,hξ⟩,φ.val.val,fun _ => rfl⟩ + +lemma rootedEdgeFiberEncoding_injective {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (f : Finset (Fin k)) (e : Finset (Fin n)) : + Function.Injective (rootedEdgeFiberEncoding T ψ f e) := by + intro φ χ hh + have he := congrArg (fun z : Σ ξ : RootedEdgePin T ψ f e, + RootedInjection (rerootTemplate T (T.roots ∪ f)) ξ.val => z.2.val) hh + exact Subtype.ext (Subtype.ext he) + +lemma intact_antitone_required {n : ℕ} {F J : Graph n} (hF : F ⊆ J) (G : Graph n) : + intact J G ≤ intact F G := by + unfold intact + split_ifs with hJ hFG hFG + · exact le_rfl + · exact False.elim (hFG (hF.trans hJ)) + · norm_num + · norm_num + +lemma rooted_edge_fiber_load {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (f : Finset (Fin k)) (e : Finset (Fin n)) + (G : Graph n) (L : ℝ) (hL : 0 ≤ L) + (hcounts : ∀ ξ : {v // v ∈ T.roots ∪ f} ↪ Fin n, + rootedCount (rerootTemplate T (T.roots ∪ f)) ξ G ≤ L) : + (∑ φ : {φ : RootedInjection T ψ // f.map φ.val = e}, intact (imageEdges T φ.val.val) G) ≤ + (e.card : ℝ)^f.card*L := by + have hh := fintype_sum_le_injection (rootedEdgeFiberEncoding T ψ f e) + (rootedEdgeFiberEncoding_injective T ψ f e) + (fun φ => intact (imageEdges T φ.val.val) G) + (fun z => intact (imageEdges (rerootTemplate T (T.roots ∪ f)) z.2.val) G) + (fun φ => intact_antitone_required (rerootTemplate_image_subset T (T.roots ∪ f) φ.val.val) G) + (fun a => intact_nonnegative _ _) + apply hh.trans + rw [Fintype.sum_sigma] + calc + _ ≤ ∑ _ξ : RootedEdgePin T ψ f e, L := Finset.sum_le_sum (fun ξ _ => hcounts ξ.val) + _ = (Fintype.card (RootedEdgePin T ψ f e) : ℝ)*L := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast rootedEdgePin_card T ψ f e) hL + +theorem rooted_copyEdgeLoad_from_reroots {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (G : Graph n) (e : Finset (Fin n)) + (he : e.card = 2) (L : ℝ) (hL : 0 ≤ L) + (hcounts : ∀ f ∈ T.edges, ∀ ξ : {v // v ∈ T.roots ∪ f} ↪ Fin n, + rootedCount (rerootTemplate T (T.roots ∪ f)) ξ G ≤ L) : + copyEdgeLoad (fun φ : RootedInjection T ψ => imageEdges T φ.val) G e ≤ + 4*(T.edges.card : ℝ)*L := by + let A := {φ : RootedInjection T ψ // e ∈ imageEdges T φ.val} + let B := Σ f : T.edges, {φ : RootedInjection T ψ // f.val.map φ.val = e} + have hex (φ : A) : ∃ f ∈ T.edges, f.map φ.val.val = e := Finset.mem_image.mp φ.property + let enc : A → B := fun φ => + ⟨⟨(hex φ).choose,(hex φ).choose_spec.1⟩,φ.val,(hex φ).choose_spec.2⟩ + have hinj : Function.Injective enc := by + intro φ χ h + exact Subtype.ext (congrArg (fun z : B => z.2.val) h) + rw [copyEdgeLoad_eq_subfamily,copyCount] + have hh := fintype_sum_le_injection enc hinj + (fun φ : A => intact (imageEdges T φ.val.val) G) + (fun z : B => intact (imageEdges T z.2.val.val) G) + (fun _ => le_refl _) (fun _ => intact_nonnegative _ _) + apply hh.trans + rw [Fintype.sum_sigma] + calc + _ ≤ ∑ _f : T.edges, 4*L := by + apply Finset.sum_le_sum + intro f _ + have hh := rooted_edge_fiber_load T ψ f.val e G L hL (hcounts f.val f.property) + simpa only [he,T.simple f.val f.property,Nat.cast_ofNat,show (2 : ℝ)^2 = 4 by norm_num] using hh + _ = _ := by simp; ring + +theorem balanced_rooted_load_bound {H k n : ℕ} (T : RootedTemplate k) + (hk : k ≤ H) (hT : RootedTwoBalanced T) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (G : Graph n) (hG : G ⊆ completeGraph n) + {p B : ℝ} (hp : 0 < p) (hp1 : p ≤ 1) (hB : 0 ≤ B) (hD : 1 ≤ (n : ℝ)*p^2) + (hupper : ∀ k ≤ H, ∀ U : RootedTemplate k, ∀ ξ : {v // v ∈ U.roots} ↪ Fin n, + rootedCount U ξ G ≤ B*rootedCompletionMax U n p) : + copyLoadSafe (fun φ : RootedInjection T ψ => imageEdges T φ.val) + (4*(T.edges.card : ℝ)*B*rootedScaling T n p/((n : ℝ)*p^2)) G := by + intro e he + have hnonneg : 0 ≤ B*(rootedScaling T n p/((n : ℝ)*p^2)) := by + unfold rootedScaling; positivity + have hmain := rooted_copyEdgeLoad_from_reroots T ψ G e (mem_completeGraph.mp (hG he)) + (B*(rootedScaling T n p/((n : ℝ)*p^2))) hnonneg ?_ + · convert hmain using 1; ring + intro f hf ξ + have hproper : T.roots.card < (T.roots ∪ f).card := by + apply Finset.card_lt_card + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨Finset.subset_union_left,?_⟩ + intro hh + exact T.independent f hf (hh ▸ Finset.subset_union_right) + exact (hupper k hk (rerootTemplate T (T.roots ∪ f)) ξ).trans + (mul_le_mul_of_nonneg_left (balanced_reroot_completion_bound T hT hp hp1 hD + (T.roots ∪ f) Finset.subset_union_left hproper) hB) + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RestrictLabel.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RestrictLabel.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f39613bf9d02d3e266bd060a9dc1ca3c1ff3b60 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RestrictLabel.lean @@ -0,0 +1,54 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.ReindexEmbedding +import OAI.Combinatorics.TriangleRemoval.Process.RealCardFiberBound + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def restrictLabel {N n : ℕ} (P : Finset (Fin N)) (φ : Fin N ↪ Fin n) : + {x // x ∈ P} ↪ Fin n := (Function.Embedding.subtype _).trans φ + +@[simp] lemma restrictLabel_apply {N n : ℕ} (P : Finset (Fin N)) + (φ : Fin N ↪ Fin n) (x : {x // x ∈ P}) : restrictLabel P φ x = φ x := rfl + +noncomputable def graphEmbeddingSet {N n : ℕ} (F : Graph N) (G : Graph n) : + Finset (Fin N ↪ Fin n) := Finset.univ.filter (fun φ => F.image (fun e => e.map φ) ⊆ G) + +theorem graphEmbeddingSet_count_glue {N n : ℕ} + (s I P : Finset (Fin N)) (E F : Graph N) (G : Graph n) + (hE : ∀ e ∈ E, e ⊆ s) (hsimple : ∀ e ∈ E, e.card = 2) + (hind : ∀ e ∈ E, ¬ e ⊆ I) (hIP : I ⊆ P) + (hcover : P ∪ s = Finset.univ) (hEF : E ⊆ F) + (A : Finset ({x // x ∈ P} ↪ Fin n)) + (hA : ∀ φ ∈ graphEmbeddingSet F G, restrictLabel P φ ∈ A) + (κ : ℝ) (hκ : ∀ ξ ∈ A, rootedCount (reindexTemplate s E I hE hsimple hind) + (boundaryInjection s I P hIP ξ) G ≤ κ) : + ((graphEmbeddingSet F G).card : ℝ) ≤ κ * A.card := by + classical + apply real_card_le_fiber_bound _ A (restrictLabel P) hA κ + intro ξ hξ + have heq : (graphEmbeddingSet F G).filter (fun φ => restrictLabel P φ = ξ) = + Finset.univ.filter (fun φ : Fin N ↪ Fin n => + (∀ x : {x // x ∈ P}, φ x = ξ x) ∧ F.image (fun e => e.map φ) ⊆ G) := by + ext φ + simp only [graphEmbeddingSet,Finset.mem_filter,Finset.mem_univ,true_and, + Function.Embedding.ext_iff,restrictLabel_apply,and_comm] + rw [heq] + exact (graphEmbedding_fiber_le_rootedCount s I P E F G hE hsimple hind hIP hcover hEF ξ).trans + (hκ ξ hξ) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RootedTemplates.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RootedTemplates.lean new file mode 100644 index 0000000000000000000000000000000000000000..ff0edebee37cb119711eb645746a906b02019567 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/RootedTemplates.lean @@ -0,0 +1,60 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +structure RootedTemplate (k : ℕ) where + edges : Graph k + roots : Finset (Fin k) + simple : ∀ e ∈ edges, e.card = 2 + independent : ∀ e ∈ edges, ¬ e ⊆ roots + +abbrev RootedInjection {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) := + {φ : Fin k ↪ Fin n // ∀ v : {v // v ∈ T.roots}, φ v = ψ v} + +def imageEdges {k n : ℕ} (T : RootedTemplate k) (φ : Fin k ↪ Fin n) : Graph n := + T.edges.image (fun e => e.map φ) + +@[simp] theorem imageEdges_card {k n : ℕ} (T : RootedTemplate k) (φ : Fin k ↪ Fin n) : + (imageEdges T φ).card = T.edges.card := by + apply Finset.card_image_of_injective + intro e f h + exact Finset.map_injective φ h + +theorem imageEdges_simple {k n : ℕ} (T : RootedTemplate k) (φ : Fin k ↪ Fin n) + {e : Finset (Fin n)} (he : e ∈ imageEdges T φ) : e.card = 2 := by + obtain ⟨f, hf, rfl⟩ := Finset.mem_image.mp he + simpa using T.simple f hf + +noncomputable def rootedCount {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (G : Graph n) : ℝ := + copyCount (fun φ : RootedInjection T ψ => imageEdges T φ.val) G + +noncomputable def rootedScaling {k : ℕ} (T : RootedTemplate k) (n : ℕ) (p : ℝ) : ℝ := + (n : ℝ) ^ (k - T.roots.card) * p ^ T.edges.card + +theorem rootedCount_drift {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (G : Graph n) (D δ : ℝ) + (hdeg : ∀ e ∈ G, |(triangleDegree G e : ℝ) - D| ≤ δ) + (hG : (triangles G).Nonempty) : + |pmfMean (step G) (rootedCount T ψ) - rootedCount T ψ G + + ((T.edges.card : ℝ) * D / (triangles G).card) * rootedCount T ψ G| ≤ + (((T.edges.card : ℝ) * δ + (T.edges.card : ℝ) ^ 2) / (triangles G).card) * + rootedCount T ψ G := by + exact copyCount_drift_error (fun φ : RootedInjection T ψ => imageEdges T φ.val) + G T.edges.card D δ (fun φ => imageEdges_card T φ.val) hdeg hG + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/SuffixTemplate.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/SuffixTemplate.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c26f043519f6aaac5f7b1ab4fbc51a45a1e2ff0 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/SuffixTemplate.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ReindexSetImage +import OAI.Combinatorics.TriangleRemoval.Process.SparseScalingOne +import OAI.Combinatorics.TriangleRemoval.Process.SuffixBoundary +import OAI.Combinatorics.TriangleRemoval.Process.Within +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N : ℕ} (B : BirthGraph N) + +def suffixTemplate (Z : Finset (Fin N)) (a b : Fin N) (hab : a ≠ b) + (hmark : a ∈ Z ∨ b ∈ Z) : RootedTemplate (B.suffixVertices Z a b).card := + reindexTemplate (B.suffixVertices Z a b) (B.suffixEdges Z a b) (B.suffixBoundary Z a b) + B.suffixEdges_subset_vertices (B.suffixEdges_simple hab) (B.suffixBoundary_independent hmark) + +lemma suffixTemplate_free_card (Z : Finset (Fin N)) (a b : Fin N) (hab : a ≠ b) + (hmark : a ∈ Z ∨ b ∈ Z) : + (B.suffixVertices Z a b).card - (B.suffixTemplate Z a b hab hmark).roots.card = Z.card := + reindexTemplate_free_card Z _ _ _ _ _ (B.suffixBoundary_disjoint Z a b).symm + +lemma suffixTemplate_edges_card {Z : Finset (Fin N)} {a b : Fin N} (hab : a ≠ b) + (hmark : a ∈ Z ∨ b ∈ Z) (hborn : ∀ v ∈ Z, (B.older v).card = 2) + (hne : ¬ B.graph.Adj a b) : + (B.suffixTemplate Z a b hab hmark).edges.card = 2 * Z.card + 1 := by + rw [suffixTemplate,reindexTemplate_edges_card] + exact B.suffix_edges_card hborn hne + +theorem suffixTemplate_eligible {Z : Finset (Fin N)} {a b : Fin N} (hab : a ≠ b) + (hmark : a ∈ Z ∨ b ∈ Z) (hborn : ∀ v ∈ Z, (B.older v).card = 2) + (hne : ¬ B.graph.Adj a b) (hc : B.Covered Z a b) + (n : ℕ) (p : ℝ) (hp : 0 ≤ p) (hp1 : p ≤ 1) (hD : 1 ≤ (n : ℝ) * p ^ 2) + (hsmall : (n : ℝ) ^ Z.card * p ^ (2 * Z.card + 1) ≤ 1) : + smallTemplateEligible (B.suffixTemplate Z a b hab hmark) n p := by + apply smallTemplateEligible_of_sparse _ p hp hp1 hD + · rw [B.suffixTemplate_free_card,B.suffixTemplate_edges_card hab hmark hborn hne] + exact hsmall + · apply reindexTemplate_sparse_transfer Z (B.suffixBoundary Z a b) + (B.suffixEdges Z a b) _ _ _ (B.suffixBoundary_disjoint Z a b).symm + intro U hU hproper + exact B.proper_suffix_sparse (B.suffixBoundary_disjoint Z a b) hU hproper hborn hc + +theorem suffixTemplate_count {n : ℕ} {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) {Z : Finset (Fin N)} {a b : Fin N} + (hab : a ≠ b) (hmark : a ∈ Z ∨ b ∈ Z) + (hborn : ∀ v ∈ Z, (B.older v).card = 2) (hne : ¬ B.graph.Adj a b) + (hc : B.Covered Z a b) (hcap : 3 * Z.card + 1 ≤ prefixTemplateCap) + (hp : 0 ≤ prefixDensity n) (hp1 : prefixDensity n ≤ 1) (hD : 1 ≤ prefixD n) + (hsmall : (n : ℝ) ^ Z.card * prefixDensity n ^ (2 * Z.card + 1) ≤ 1) + (ψ : {v // v ∈ (B.suffixTemplate Z a b hab hmark).roots} ↪ Fin n) : + rootedCount (B.suffixTemplate Z a b hab hmark) ψ G ≤ prefixTemplateFactor n C := by + have horder := (B.suffixVertices_card hmark).trans hcap + have ht := (hGood.2.2.2.2.2 _ horder (B.suffixTemplate Z a b hab hmark) ψ).2 + exact ht (B.suffixTemplate_eligible hab hmark hborn hne hc n (prefixDensity n) hp hp1 hD hsmall) + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/TriangleGrowth.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/TriangleGrowth.lean new file mode 100644 index 0000000000000000000000000000000000000000..b629b15a1af98850bed408de5691596daf5bacf1 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/TriangleGrowth.lean @@ -0,0 +1,174 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +structure TriangleGrowth {V : Type*} [DecidableEq V] (G : SimpleGraph V) + (N R : ℕ) where + label : Fin N → V + seed : BirthGraph N + seed_small : ∀ v, v.val < R → (seed.older v).card ≤ 1 + seed_root : ∀ v, ∀ u ∈ seed.older v, v.val < R → u.val < R + seed_labels : ∀ v, v.val < R → ∀ u ∈ seed.older v, G.Adj (label u) (label v) + roots_injective : Set.InjOn label {v | v.val < R} + attach : Fin N → Finset V + parent : Fin N → Option (Fin N) + parent_lt : ∀ v p, R ≤ v.val → parent v = some p → p < v + parent_nonroot : ∀ v p, R ≤ v.val → parent v = some p → R ≤ p.val + attach_card : ∀ v, R ≤ v.val → (attach v).card = 2 + new_label : ∀ v, R ≤ v.val → label v ∉ attach v + triangle : ∀ v, R ≤ v.val → BirthGraph.IsTriangle G (insert (label v) (attach v)) + root_attach : ∀ v, R ≤ v.val → parent v = none → + ∃ x y : Fin N, x.val < R ∧ y.val < R ∧ seed.graph.Adj x y ∧ + attach v = {label x, label y} + child_attach : ∀ v p, R ≤ v.val → parent v = some p → + attach v ⊆ insert (label p) (attach p) ∧ attach v ≠ attach p + omission : ∀ v p, R ≤ v.val → parent v = some p → + insert (label v) (attach v) ≠ insert (label p) (attach p) + distinct_children : ∀ v w, R ≤ v.val → R ≤ w.val → parent v = parent w → + attach v = attach w → label v = label w → v = w + +namespace TriangleGrowth +variable {V : Type*} [DecidableEq V] {G : SimpleGraph V} {N R : ℕ} +variable (A : TriangleGrowth G N R) + +noncomputable def roots (_A : TriangleGrowth G N R) : Finset (Fin N) := Finset.univ.filter (fun v => v.val < R) + +@[simp] theorem mem_roots (v : Fin N) : v ∈ A.roots ↔ v.val < R := by + simp [roots] + +noncomputable def older (A : TriangleGrowth G N R) (v : Fin N) : Finset (Fin N) := + if _hv : R ≤ v.val then + match _hp : A.parent v with + | none => A.roots.filter (fun x => A.label x ∈ A.attach v) + | some p => (insert p (A.older p)).filter (fun x => A.label x ∈ A.attach v) + else A.seed.older v +termination_by v.val +decreasing_by exact A.parent_lt v p _hv _hp + +lemma lifted_image {α β : Type*} [DecidableEq α] [DecidableEq β] + (f : α → β) (s : Finset α) (t : Finset β) + (ht : t ⊆ s.image f) : (s.filter (fun x => f x ∈ t)).image f = t := by + ext y + constructor + · rintro h + obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h + exact (Finset.mem_filter.mp hx).2 + · intro hy + obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp (ht hy) + exact Finset.mem_image.mpr ⟨x,Finset.mem_filter.mpr ⟨hx,hy⟩,rfl⟩ + +lemma lifted_card {α β : Type*} [DecidableEq α] [DecidableEq β] + (f : α → β) (s : Finset α) (t : Finset β) + (hi : Set.InjOn f s) (ht : t ⊆ s.image f) : + (s.filter (fun x => f x ∈ t)).card = t.card := by + have hi' : Set.InjOn f (s.filter (fun x => f x ∈ t)) := + hi.mono (by intro x hx; exact (Finset.mem_filter.mp hx).1) + have hc : ((s.filter (fun x => f x ∈ t)).image f).card = + (s.filter (fun x => f x ∈ t)).card := Finset.card_image_iff.mpr hi' + rw [lifted_image f s t ht] at hc + exact hc.symm + +theorem older_invariants (v : Fin N) : + (∀ x ∈ A.older v, x < v) ∧ + (R ≤ v.val → (A.older v).card = 2 ∧ (A.older v).image A.label = A.attach v ∧ + Set.InjOn A.label (insert v (A.older v) : Finset (Fin N))) := by + induction v using (measure (fun v : Fin N => v.val)).wf.induction with + | h v ih => + by_cases hv : R ≤ v.val + · have main : + (∀ x ∈ A.older v, x < v) ∧ (A.older v).card = 2 ∧ + (A.older v).image A.label = A.attach v ∧ Set.InjOn A.label (A.older v) := by + cases hp : A.parent v with + | none => + obtain ⟨x,y,hx,hy,_,hat⟩ := A.root_attach v hv hp + have hs : A.attach v ⊆ A.roots.image A.label := by + rw [hat] + intro z hz + simp only [Finset.mem_insert,Finset.mem_singleton] at hz + rcases hz with rfl | rfl + · exact Finset.mem_image.mpr ⟨x,A.mem_roots x |>.mpr hx,rfl⟩ + · exact Finset.mem_image.mpr ⟨y,A.mem_roots y |>.mpr hy,rfl⟩ + have hi : Set.InjOn A.label A.roots := by + intro x hx y hy he + exact A.roots_injective ((A.mem_roots x).mp hx) ((A.mem_roots y).mp hy) he + rw [older,dite_eq_left hv,hp] + refine ⟨?_,?_,lifted_image _ _ _ hs,?_⟩ + · intro z hz + have hzR := (A.mem_roots z).mp (Finset.mem_filter.mp hz).1 + change z.val < v.val + exact lt_of_lt_of_le hzR hv + · rw [lifted_card _ _ _ hi hs,A.attach_card v hv] + · exact hi.mono (by intro z hz; exact (Finset.mem_filter.mp hz).1) + | some p => + have hpv := A.parent_lt v p hv hp + have hpR := A.parent_nonroot v p hv hp + have hind := ih p hpv + have hpim : (insert p (A.older p)).image A.label = + insert (A.label p) (A.attach p) := by + rw [Finset.image_insert,(hind.2 hpR).2.1] + have hs : A.attach v ⊆ (insert p (A.older p)).image A.label := by + rw [hpim] + exact (A.child_attach v p hv hp).1 + have hi := (hind.2 hpR).2.2 + rw [older,dite_eq_left hv,hp] + refine ⟨?_,?_,lifted_image _ _ _ hs,?_⟩ + · intro z hz + rcases Finset.mem_insert.mp (Finset.mem_filter.mp hz).1 with rfl | hz + · exact hpv + · exact (hind.1 z hz).trans hpv + · rw [lifted_card _ _ _ hi hs,A.attach_card v hv] + · exact hi.mono (by intro z hz; exact (Finset.mem_filter.mp hz).1) + refine ⟨main.1,fun _ => ⟨main.2.1,main.2.2.1,?_⟩⟩ + intro x hx y hy he + by_cases hxv : x = v <;> by_cases hyv : y = v + · exact hxv.trans hyv.symm + · subst x + have hy' := (Finset.mem_insert.mp hy).resolve_left hyv + have hm : A.label y ∈ A.attach v := by + rw [← main.2.2.1] + exact Finset.mem_image.mpr ⟨y,hy',rfl⟩ + exact False.elim (A.new_label v hv (he.symm ▸ hm)) + · subst y + have hx' := (Finset.mem_insert.mp hx).resolve_left hxv + have hm : A.label x ∈ A.attach v := by + rw [← main.2.2.1] + exact Finset.mem_image.mpr ⟨x,hx',rfl⟩ + exact False.elim (A.new_label v hv (he ▸ hm)) + · exact main.2.2.2 ((Finset.mem_insert.mp hx).resolve_left hxv) + ((Finset.mem_insert.mp hy).resolve_left hyv) he + · rw [older,dite_eq_right hv] + exact ⟨A.seed.older_lt v,fun h => False.elim (hv h)⟩ + +noncomputable def birthGraph : BirthGraph N where + older := A.older + older_lt := fun v => (A.older_invariants v).1 + older_card := by + intro v + by_cases hv : R ≤ v.val + · exact le_of_eq ((A.older_invariants v).2 hv).1 + · rw [older,dite_eq_right hv] + exact (A.seed_small v (Nat.lt_of_not_ge hv)).trans (by omega) + +@[simp] theorem parentType_eq (v : Fin N) (hv : R ≤ v.val) : + A.birthGraph.parentType A.label v = insert (A.label v) (A.attach v) := by + change (insert v (A.older v)).image A.label = _ + rw [Finset.image_insert,((A.older_invariants v).2 hv).2.1] + +end TriangleGrowth +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/TriangleGrowth2.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/TriangleGrowth2.lean new file mode 100644 index 0000000000000000000000000000000000000000..d88f9a8bc1a41df96d62fff0dbe0261a05f68cc7 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/TriangleGrowth2.lean @@ -0,0 +1,92 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.Attachment +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching +import OAI.Combinatorics.TriangleRemoval.Process.OlderSeed + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) + +lemma root_edges_adj (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) : + ∀ e ∈ c.focus, ∀ x ∈ e, ∀ y ∈ e, x ≠ y → (lookupGraph G).Adj x y := by + intro e he x hx y hy hne + refine ⟨hne,?_⟩ + have hp : ({x,y} : Finset (Fin n)) = e := Finset.eq_of_subset_of_card_le + (by simpa only [Finset.insert_subset_iff,Finset.singleton_subset_iff] using And.intro hx hy) + (by rw [hM.1 e he,Finset.card_pair hne]) + rw [hp] + exact hG he + +noncomputable def toTriangleGrowth (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) : + TriangleGrowth (lookupGraph G) F.vertexCount F.rootCount where + label := F.vertexLabel + seed := matchingSeed F.vertexLabel c.focus hM F.vertexLabel_injective_roots + seed_small := fun v _ => matchingSeed_small _ _ _ _ v + seed_root := fun v u hu _ => matchingSeed_root _ _ _ _ v u hu + seed_labels := fun v _ u hu => matchingSeed_labels _ _ _ _ (lookupGraph G) + (root_edges_adj hM hG) v u hu + roots_injective := F.vertexLabel_injective_roots + attach := F.attachment + parent := F.birthParent + parent_lt := by + intro v p hv hp + obtain ⟨hh,rfl⟩ := F.birthParent_some v p hv hp + have ht := F.birthIndex_lt _ _ hh (F.callIndex_nonroot v hv) + (F.parent_lt (F.callIndex v hv) (F.callIndex_nonroot v hv)) + simpa only [F.birthIndex_callIndex] using ht + parent_nonroot := by + intro v p hv hp + obtain ⟨hh,rfl⟩ := F.birthParent_some v p hv hp + exact F.birthIndex_nonroot _ hh + attach_card := by + intro v hv + rw [F.attachment_nonroot v hv] + exact F.incoming_card _ _ + new_label := by + intro v hv + rw [F.attachment_nonroot v hv,F.vertexLabel_nonroot v hv] + exact (F.newVertex_spec _ _).1 + triangle := by + intro v hv + rw [F.newTriangle v hv] + exact lookupGraph_triangle (F.incoming_graph _ _).2.1 + root_attach := by + intro v hv hp + have hm := (F.incoming_graph (F.callIndex v hv) (F.callIndex_nonroot v hv)).1 + rw [F.birthParent_none v hv hp,F.root_eq] at hm + rw [F.attachment_nonroot v hv] + exact matchingSeed_covers _ _ _ _ (F.vertexLabel_covers) _ hm + child_attach := by + intro v p hv hp + obtain ⟨hh,rfl⟩ := F.birthParent_some v p hv hp + rw [F.attachment_nonroot v hv,F.vertexLabel_birth,F.attachment_birth] + exact ⟨(F.incoming_of_nonroot_parent _ _ hh).1, + (F.incoming_of_nonroot_parent _ _ hh).2.1⟩ + omission := by + intro v p hv hp + obtain ⟨hh,rfl⟩ := F.birthParent_some v p hv hp + rw [F.newTriangle v hv,F.vertexLabel_birth,F.attachment_birth, + ← (F.newVertex_spec _ hh).2] + exact (F.incoming_of_nonroot_parent _ _ hh).2.2 + distinct_children := F.attachments_distinct + +theorem toTriangleGrowth_spawnRules (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) : + (F.toTriangleGrowth hM hG).birthGraph.SpawnRules (lookupGraph G) F.vertexLabel := + (F.toTriangleGrowth hM hG).spawnRules + +end SharpTerminalLeave.RecordedCallForest + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/WitnessEmbeddingBound.lean b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/WitnessEmbeddingBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..d6b5b0244ff5005703e71f24c95e5d150a2acc4a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Embeddings/WitnessEmbeddingBound.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.WitnessDimensions +import OAI.Combinatorics.TriangleRemoval.Process.WitnessCountEventually + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +def WitnessEmbeddingBound {n R d : ℕ} {G : Graph n} + (r : ℕ) (W : BoundedEmbeddedWitness G R d) : Prop := + ((graphEmbeddingSet (decodeWitnessPattern W.2.2.1).2 G).card : ℝ) ≤ + (4*prefixM n)^r * (2*prefixD n)^W.1.val.2.val / prefixD n^50 + +lemma actual_witness_count_roots_eventually (c C : ℝ) (hc : 0 < c) : + ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c C G → + ∀ r : ℕ, r ≤ 2 → ∀ N R : ℕ, ∀ (A : TriangleGrowth (lookupGraph G) N R), + R ≤ N → R = 2*r → (A.seed.backEdges A.roots).card = r → + ∀ a b : Fin N, A.birthGraph.ExtraEdge (lookupGraph G) A.label a b → + ((graphEmbeddingSet (insert ({A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)} : Finset _) + ((A.pathPattern a b).backEdges Finset.univ)) G).card : ℝ) ≤ + (4*prefixM n)^r * (2*prefixD n)^(A.pathSuffix a b R).card / prefixD n^50 := by + filter_upwards [actual_witness_count_eventually c C hc] with n hn + intro G hG r hr N R A hR hRr hseed a b he + subst R + exact hn G hG r hr N A hR hseed a b he + +theorem counted_traced_repeat_cover (c₀ C₀ : ℝ) (hc₀ : 0 < c₀) : + ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c₀ C₀ G → + ∀ (focus : Graph n) + (parent : Option (Finset (Fin n))) (_hM : EdgeMatching focus) (_hG : focus ⊆ G) + (_hr : focus.card ≤ 2) + (_hc : (QueryCall.mk [] focus parent).Separated (triangleHypergraph G)) + (N d k : ℕ) (ν : Finset (Fin n) → PMF (Fin N)) + (z : (Bool × List (QueryCall (Finset (Fin n)) (Finset (Fin n)))) × List (Finset (Fin n))) + (_hz : z ∈ (ExposureTree.freshLog ν + (tracedGridQuery (triangleHypergraph G) N d k ⟨[],focus,parent⟩)).support) + (_hrep : ExposureTree.repeats ∅ z.2 = true), + ∃ W : BoundedEmbeddedWitness G (focus.biUnion id).card d, + WitnessEmbeddingBound focus.card W ∧ + (∃ a ∈ z.1.2, a.address = (embeddedWitnessPaths W).1.reverse) ∧ + (∃ b ∈ z.1.2, b.address = (embeddedWitnessPaths W).2.reverse) := by + classical + filter_upwards [actual_witness_count_roots_eventually c₀ C₀ hc₀] with n hn + intro G hGood focus parent hM hG hr hc N d k ν z hz hrep + let c : QueryCall (Finset (Fin n)) (Finset (Fin n)) := ⟨[],focus,parent⟩ + let F := extractCallForest (triangleHypergraph G) N d k c ν z hz + let A := F.toTriangleGrowth hM hG + have hR : F.rootCount ≤ F.vertexCount := Nat.le_add_right _ _ + obtain ⟨a,b,he,hi⟩ := traced_graph_path_collision_witness G N d k c hM hG hc ν z hz hrep + have hdepth (i : Fin F.size) : (F.call i).address.length ≤ d := by + obtain ⟨p,hp,he⟩ := tracedGridQuery_legal_path (triangleHypergraph G) N d k c ν hz + (F.call i) (List.get_mem z.1.2 i) + rw [he,callAtPath_address] + simpa only [c,List.append_nil,List.length_reverse] using + (mem_legalPaths (triangleHypergraph G) d focus parent p).mp hp |>.2 + let key := indexedTriangleKey (A.pathBirthIndex a b hR) (A.pathAttachments a b hR) + (A.pathAssignment a b hi) + have hs : (A.pathSuffix a b F.rootCount).card ≤ 2*d := by + have h := (A.pathForest a b).two_mark_size key + (suffixProjection (A.path_card_split a b hR) (A.pathIndex a b a (A.left_mem_pathUnion a b))) + (suffixProjection (A.path_card_split a b hR) (A.pathIndex a b b (A.right_mem_pathUnion a b))) + (A.pathWitnessCode a b hR).2.1.property + rw [F.decoded_mark_address hM hG rfl a b hR hi a (A.left_mem_pathUnion a b), + F.decoded_mark_address hM hG rfl a b hR hi b (A.right_mem_pathUnion a b)] at h + have ha := hdepth (F.vertexCall a) + have hb := hdepth (F.vertexCall b) + omega + let q : WitnessDimensions F.rootCount d := + ⟨(⟨(A.pathUnion a b).card,by rw [A.path_card_split a b hR]; omega⟩, + ⟨(A.pathSuffix a b F.rootCount).card,by omega⟩),A.path_card_split a b hR⟩ + have hseed : (A.seed.backEdges A.roots).card ≤ 2 := by + rw [F.growth_seed_card hM hG] + exact hr + let E : {E : Graph (A.pathUnion a b).card // E ∈ seedPatternChoices (A.pathUnion a b).card F.rootCount} := + ⟨A.pathRootEdges a b,A.pathRootEdges_mem_seedPatternChoices a b hR hseed⟩ + let W : BoundedEmbeddedWitness G F.rootCount d := + ⟨q,E,A.pathWitnessCode a b hR,A.pathAssignment a b hi,A.pathAssignment_mem_decoded hR hi he⟩ + have hleft : (embeddedWitnessPaths W).1.reverse = (F.call (F.vertexCall a)).address := by + change (((suffixProjection (A.path_card_split a b hR) + (A.pathIndex a b a (A.left_mem_pathUnion a b))).elim [] + ((A.pathForest a b).address key)).reverse).reverse = _ + rw [List.reverse_reverse] + exact F.decoded_mark_address hM hG rfl a b hR hi a (A.left_mem_pathUnion a b) + have hright : (embeddedWitnessPaths W).2.reverse = (F.call (F.vertexCall b)).address := by + change (((suffixProjection (A.path_card_split a b hR) + (A.pathIndex a b b (A.right_mem_pathUnion a b))).elim [] + ((A.pathForest a b).address key)).reverse).reverse = _ + rw [List.reverse_reverse] + exact F.decoded_mark_address hM hG rfl a b hR hi b (A.right_mem_pathUnion a b) + have hbound : WitnessEmbeddingBound focus.card W := by + have hh := hn G hGood focus.card hr F.vertexCount F.rootCount A hR + (F.rootCount_focus_card hM) (F.growth_seed_card hM hG) a b he + change ((graphEmbeddingSet (decodeWitnessPattern (A.pathWitnessCode a b hR)).2 G).card : ℝ) ≤ + (4*prefixM n)^focus.card*(2*prefixD n)^(A.pathSuffix a b F.rootCount).card/prefixD n^50 + change ((graphEmbeddingSet (insert {A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)} + (indexedPatternEdges (A.pathRootEdges a b) (A.pathBirthIndex a b hR) + (A.pathAttachments a b hR))) G).card : ℝ) ≤ _ + rw [← A.pathPattern_edges a b hR] + exact hh + exact ⟨W,hbound,⟨F.call (F.vertexCall a),List.get_mem z.1.2 _,hleft.symm⟩, + ⟨F.call (F.vertexCall b),List.get_mem z.1.2 _,hright.symm⟩⟩ + +end SharpTerminalLeave + +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +noncomputable instance instFintypeIndexedWitnessCodeEmbeddingBound {K s : ℕ} + (E : Graph K) (birth : Fin s → Fin K) + (mark : Fin K → Option (Fin s)) : Fintype (IndexedWitnessCode E birth mark) := by + classical + unfold IndexedWitnessCode + infer_instance + +end SharpTerminalLeave + +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Main.lean b/lean/OAI/Combinatorics/TriangleRemoval/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..50f00a4be348e0d01a72cd55d57b09f2e8ddd12a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Main.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.RootedInjectionEquiv +import OAI.Combinatorics.TriangleRemoval.Process.OlderSeed +import OAI.Combinatorics.TriangleRemoval.Tracking.RootedExposedCollisionWitness +import OAI.Combinatorics.TriangleRemoval.Process.SuffixBoundary +import OAI.Combinatorics.TriangleRemoval.Embeddings.SuffixTemplate +import OAI.Combinatorics.TriangleRemoval.Process.InitialAssignmentSet +import OAI.Combinatorics.TriangleRemoval.Process.InitialAssignmentSetBound +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEmbeddingsEdgeCover +import OAI.Combinatorics.TriangleRemoval.Process.InitialAssignmentSetMatching +import OAI.Combinatorics.TriangleRemoval.Process.LongWitnessMatchingCount +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth2 +import OAI.Combinatorics.TriangleRemoval.Process.FreshMemSelected +import OAI.Combinatorics.TriangleRemoval.Queries.KeyCandidate +import OAI.Combinatorics.TriangleRemoval.Probability.TriangleSafeTemplateFreedman +import OAI.Combinatorics.TriangleRemoval.Process.MatchingSeedFullEdge +import OAI.Combinatorics.TriangleRemoval.Process.RootClosers +import OAI.Combinatorics.TriangleRemoval.Process.SeedEdgeSubsetPath +import OAI.Combinatorics.TriangleRemoval.Queries.VertexCall +import OAI.Combinatorics.TriangleRemoval.Process.FilteredSigmaWeightBound +import OAI.Combinatorics.TriangleRemoval.Stability.RelativeTemplateResidual +import OAI.Combinatorics.TriangleRemoval.Probability.MainProbabilityPrefixFailure +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixFailureEnvelopeSuperpolynomial +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixCodegreeErrorExit +import OAI.Combinatorics.TriangleRemoval.Tracking.NormalizedTrackingAbsolute + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology +open Filter Classical + +namespace SharpTerminalLeave + +theorem sharp_terminal_leave_l2 : + Tendsto (fun n => expectation n (fun G => + (normalizedLeave n G-sharpConstant)^2)) atTop (𝓝 0) := by + obtain ⟨c,hc,C,hprefix⟩ := uniform_prefix_obligation + apply tendsto_order.mpr + constructor + · intro a ha + exact Eventually.of_forall (fun n => ha.trans_le + (pmfMean_nonneg (terminalLaw n) (fun G _ => sq_nonneg (normalizedLeave n G-sharpConstant)))) + · intro b hb + have hb2 : 0 < b/2 := by linarith + filter_upwards [hprefix,main_l2_prefix_failure_bound c C hc (b/2) hb2, + (tendsto_order.mp prefix_failure_l2_envelope_tendsto).2 (b/2) hb2] with n hpre hmain htail + have hh := mul_le_mul_of_nonneg_left hpre (by positivity : 0 ≤ 2*(n : ℝ)+1) + linarith only [hmain,hh,htail] + +theorem sharp_terminal_leave_probability (ε : ℝ) (hε : 0 < ε) : + Tendsto (fun n => probability n (fun G => + ε < |normalizedLeave n G-sharpConstant|)) atTop (𝓝 0) := by + apply squeeze_zero + · intro n + apply pmfMean_nonneg (terminalLaw n) + intro G _ + split_ifs <;> norm_num + · intro n + exact pmfMean_markov_sq (terminalLaw n) (fun G => normalizedLeave n G-sharpConstant) ε hε + · simpa only [zero_div,expectation,pmfMean] using sharp_terminal_leave_l2.div_const (ε^2) + +theorem sharp_terminal_leave_expectation : + Tendsto (fun n => expectation n (fun G => (G.card : ℝ))/normalization n) + atTop (𝓝 sharpConstant) := by + have hmean : Tendsto (fun n => expectation n (normalizedLeave n)) atTop (𝓝 sharpConstant) := by + apply Metric.tendsto_nhds.mpr + intro ε hε + filter_upwards [(tendsto_order.mp sharp_terminal_leave_l2).2 (ε^2) (sq_pos_of_pos hε)] with n hn + have hh := pmfMean_sq_le (terminalLaw n) (fun G => normalizedLeave n G-sharpConstant) + rw [pmfMean_sub,pmfMean_const] at hh + rw [Real.dist_eq] + apply (sq_lt_sq₀ (abs_nonneg _) hε.le).mp + rw [sq_abs] + exact hh.trans_lt hn + simpa only [expectation_normalizedLeave] using hmean + +theorem sharp_terminal_leave : + Tendsto (fun n => expectation n (fun G => + (normalizedLeave n G - sharpConstant) ^ 2)) atTop (𝓝 0) ∧ + (∀ ε : ℝ, 0 < ε → + Tendsto (fun n => probability n (fun G => + ε < |normalizedLeave n G - sharpConstant|)) atTop (𝓝 0)) ∧ + Tendsto (fun n => expectation n (fun G => (G.card : ℝ)) / normalization n) + atTop (𝓝 sharpConstant) := + ⟨sharp_terminal_leave_l2,sharp_terminal_leave_probability,sharp_terminal_leave_expectation⟩ + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Model.lean b/lean/OAI/Combinatorics/TriangleRemoval/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..a98449e69fed6a929088f3fbda47db24839b1e31 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Model.lean @@ -0,0 +1,50 @@ +import Mathlib + +namespace OAI + +section +section + +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +abbrev Graph (n : ℕ) := Finset (Finset (Fin n)) + +def completeGraph (n : ℕ) : Graph n := Finset.univ.powersetCard 2 + +def triangles {n : ℕ} (G : Graph n) : Finset (Finset (Fin n)) := + (Finset.univ.powersetCard 3).filter (fun t => t.powersetCard 2 ⊆ G) + +noncomputable def step {n : ℕ} (G : Graph n) : PMF (Graph n) := + if h : (triangles G).Nonempty then + (PMF.uniformOfFinset (triangles G) h).map (fun t => G \ t.powersetCard 2) + else PMF.pure G + +noncomputable def evolve {n : ℕ} (G : Graph n) : ℕ → PMF (Graph n) + | 0 => PMF.pure G + | k + 1 => (evolve G k).bind step + +noncomputable def terminalLaw (n : ℕ) : PMF (Graph n) := + evolve (completeGraph n) (n.choose 2) + +noncomputable def expectation (n : ℕ) (f : Graph n → ℝ) : ℝ := + ∑ G, (terminalLaw n G).toReal * f G + +noncomputable def probability (n : ℕ) (P : Graph n → Prop) : ℝ := by + classical + exact expectation n (fun G => if P G then 1 else 0) + +noncomputable def normalization (n : ℕ) : ℝ := (n : ℝ) ^ (3 / 2 : ℝ) + +noncomputable def normalizedLeave (n : ℕ) (G : Graph n) : ℝ := + (G.card : ℝ) / normalization n + +noncomputable def sharpConstant : ℝ := 1 / (2 * Real.sqrt 2) + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/AbsPmfMean.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/AbsPmfMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..881eb16446855135805f7b1734731b5b7dfcddb6 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/AbsPmfMean.lean @@ -0,0 +1,124 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Stability.CavityReference +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraphReindex + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma abs_pmfMean_le {α : Type*} [Fintype α] (P : PMF α) (f : α → ℝ) : + |pmfMean P f| ≤ pmfMean P (fun a => |f a|) := by + unfold pmfMean + apply (Finset.abs_sum_le_sum_abs _ _).trans_eq + apply Finset.sum_congr rfl + intro a _ + rw [abs_mul,abs_of_nonneg ENNReal.toReal_nonneg] + +lemma pmfMean_swap {α β : Type*} [Fintype α] [Fintype β] + (P : PMF α) (Q : PMF β) (f : α → β → ℝ) : + pmfMean P (fun a => pmfMean Q (f a)) = + pmfMean Q (fun b => pmfMean P (fun a => f a b)) := by + unfold pmfMean + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + apply Finset.sum_congr rfl + intro a _ + ring + +lemma pmfMean_common_error {α : Type*} [Fintype α] (P : PMF α) + (f err : α → ℝ) (r : ℝ) (h : ∀ a ∈ P.support, |f a-r| ≤ err a) : + |pmfMean P f-r| ≤ pmfMean P err := by + rw [← pmfMean_const P r,← pmfMean_sub] + exact (abs_pmfMean_le P _).trans (pmfMean_mono P h) + +lemma relative_error_absolute {a r ε : ℝ} (hr : 0 < r) + (h : |a/r-1| ≤ ε) : |a-r| ≤ ε*r := by + have heq : (a/r-1)*r = a-r := by field_simp + calc + _ = |(a/r-1)*r| := congrArg abs heq.symm + _ = |a/r-1| *r := by rw [abs_mul,abs_of_pos hr] + _ ≤ _ := mul_le_mul_of_nonneg_right h hr.le + +lemma product_relative_error {a b r ε : ℝ} (hr : 0 ≤ r) (hb : 0 ≤ b) + (haerr : |a-r| ≤ ε*r) (hberr : |b-r| ≤ ε*r) (hε : 0 ≤ ε) : + |a*b-r^2| ≤ (2*ε+ε^2)*r^2 := by + have hbup : b ≤ (1+ε)*r := by + have := (abs_le.mp hberr).2 + nlinarith + calc + _ = |(a-r)*b+r*(b-r)| := by congr 1; ring + _ ≤ |(a-r)*b|+|r*(b-r)| := abs_add_le _ _ + _ = |a-r| *b+r*|b-r| := by rw [abs_mul,abs_mul,abs_of_nonneg hb,abs_of_nonneg hr] + _ ≤ (ε*r)*((1+ε)*r)+r*(ε*r) := add_le_add + (mul_le_mul haerr hbup hb (mul_nonneg hε hr)) + (mul_le_mul_of_nonneg_left hberr hr) + _ = _ := by ring + +lemma focusSurvival_mem_unit {n : ℕ} (G focus : Graph n) : + focusSurvival G focus ∈ Set.Icc (0 : ℝ) 1 := + ⟨trueProbability_nonneg _,trueProbability_le_one _⟩ + +lemma cavityReference_le_one {D t : ℝ} (hD : 0 < D) (ht : 0 ≤ t) : + cavityReference D t ≤ 1 := by + unfold cavityReference + exact Real.rpow_le_one_of_one_le_of_nonpos (by nlinarith : 1 ≤ 1+2*D*t) + (by norm_num) + +theorem singleton_survival_error {n : ℕ} (G : Graph n) (D ε : ℝ) + (hD : 0 < D) + (hrel : ∀ e : G, |cavityLimit (activeHypergraph G) e none 1 / + cavityReference D 1 - 1| ≤ ε) + (e : Finset (Fin n)) (he : e ∈ G) : + |focusSurvival G {e}-cavityReference D 1| ≤ + collisionCost (triangleHypergraph G) {e} none+ε*cavityReference D 1 := by + classical + have hc := graph_cavity_error G {e} (Finset.singleton_subset_iff.mpr he) + rw [Finset.prod_singleton] at hc + have heq := active_cavity_eq G ⟨e,he⟩ none 1 + simp only [Option.map_none] at heq + have habs := relative_error_absolute (cavityReference_pos hD (by norm_num)) (hrel ⟨e,he⟩) + rw [← heq] at habs + exact (abs_sub_le _ _ _).trans (add_le_add hc habs) + +theorem pair_survival_error {n : ℕ} (G : Graph n) (D ε : ℝ) + (hD : 0 < D) (hε : 0 ≤ ε) + (hrel : ∀ e : G, |cavityLimit (activeHypergraph G) e none 1 / + cavityReference D 1 - 1| ≤ ε) + (e f : Finset (Fin n)) (he : e ∈ G) (hf : f ∈ G) (hef : e ≠ f) : + |focusSurvival G {e,f}-(cavityReference D 1)^2| ≤ + collisionCost (triangleHypergraph G) {e,f} none+ + (2*ε+ε^2)*(cavityReference D 1)^2 := by + classical + have hc := graph_cavity_error G {e,f} + (by intro a ha; simp only [Finset.mem_insert,Finset.mem_singleton] at ha + rcases ha with rfl | rfl <;> assumption) + rw [Finset.prod_pair hef] at hc + have heq := active_cavity_eq G ⟨e,he⟩ none 1 + have hfq := active_cavity_eq G ⟨f,hf⟩ none 1 + simp only [Option.map_none] at heq hfq + have hr := cavityReference_pos hD (by norm_num : (0 : ℝ) ≤ 1) + have hea := relative_error_absolute hr (hrel ⟨e,he⟩) + have hfa := relative_error_absolute hr (hrel ⟨f,hf⟩) + rw [← heq] at hea + rw [← hfq] at hfa + have hh := product_relative_error hr.le + (cavityLimit_mem_unit (triangleHypergraph G) f none 1).1 + hea hfa hε + exact (abs_sub_le _ _ _).trans (add_le_add hc hh) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/FiniteMean.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/FiniteMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..f001acb221d75bd0451cdf6a541a29da657cc143 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/FiniteMean.lean @@ -0,0 +1,132 @@ +import Mathlib + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +noncomputable def pmfMean {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) : ℝ := + ∑ a, (p a).toReal * f a + +theorem pmf_weight_sum {α : Type*} [Fintype α] (p : PMF α) : + ∑ a, (p a).toReal = 1 := by + rw [← ENNReal.toReal_sum (fun a _ => p.apply_ne_top a)] + have h : ∑ a, p a = 1 := by simpa only [tsum_fintype] using p.tsum_coe + rw [h, ENNReal.toReal_one] + +@[simp] theorem pmfMean_const {α : Type*} [Fintype α] (p : PMF α) (c : ℝ) : + pmfMean p (fun _ => c) = c := by + simp only [pmfMean, ← Finset.sum_mul, pmf_weight_sum, one_mul] + +theorem pmfMean_congr {α : Type*} [Fintype α] (p : PMF α) {f g : α → ℝ} + (h : ∀ a ∈ p.support, f a = g a) : pmfMean p f = pmfMean p g := by + apply Finset.sum_congr rfl + intro a _ + by_cases ha : a ∈ p.support + · rw [h a ha] + · have hz : p a = 0 := by simpa only [PMF.mem_support_iff, not_not] using ha + simp [hz] + +theorem pmfMean_add {α : Type*} [Fintype α] (p : PMF α) (f g : α → ℝ) : + pmfMean p (fun a => f a + g a) = pmfMean p f + pmfMean p g := by + simp only [pmfMean, mul_add, Finset.sum_add_distrib] + +theorem pmfMean_sub {α : Type*} [Fintype α] (p : PMF α) (f g : α → ℝ) : + pmfMean p (fun a => f a - g a) = pmfMean p f - pmfMean p g := by + simp only [pmfMean, mul_sub, Finset.sum_sub_distrib] + +theorem pmfMean_mul_const {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) (c : ℝ) : + pmfMean p (fun a => f a * c) = pmfMean p f * c := by + simp only [pmfMean, ← mul_assoc, ← Finset.sum_mul] + +theorem pmfMean_const_mul {α : Type*} [Fintype α] (p : PMF α) (c : ℝ) (f : α → ℝ) : + pmfMean p (fun a => c * f a) = c * pmfMean p f := by + simpa only [mul_comm] using pmfMean_mul_const p f c + +theorem pmfMean_nonneg {α : Type*} [Fintype α] (p : PMF α) {f : α → ℝ} + (h : ∀ a ∈ p.support, 0 ≤ f a) : 0 ≤ pmfMean p f := by + apply Finset.sum_nonneg + intro a _ + by_cases ha : a ∈ p.support + · exact mul_nonneg ENNReal.toReal_nonneg (h a ha) + · have hz : p a = 0 := by simpa only [PMF.mem_support_iff, not_not] using ha + simp [hz] + +theorem pmfMean_mono {α : Type*} [Fintype α] (p : PMF α) {f g : α → ℝ} + (h : ∀ a ∈ p.support, f a ≤ g a) : pmfMean p f ≤ pmfMean p g := by + have hh := pmfMean_nonneg p (fun a ha => sub_nonneg.mpr (h a ha)) + rwa [pmfMean_sub, sub_nonneg] at hh + +theorem pmfMean_sq_sub {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) (c : ℝ) : + pmfMean p (fun a => (f a - c) ^ 2) = + pmfMean p (fun a => f a ^ 2) - 2 * c * pmfMean p f + c ^ 2 := by + have hpoly : (fun a => (f a - c) ^ 2) = + (fun a => (f a ^ 2 - (2 * c) * f a) + c ^ 2) := by + funext a + ring + rw [hpoly, pmfMean_add, pmfMean_sub, pmfMean_const_mul, pmfMean_const] + +theorem pmfMean_sq_le {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) : + (pmfMean p f) ^ 2 ≤ pmfMean p (fun a => f a ^ 2) := by + have h := pmfMean_nonneg p + (fun a (_ : a ∈ p.support) => sq_nonneg (f a - pmfMean p f)) + rw [pmfMean_sq_sub] at h + nlinarith + +theorem pmfMean_markov_sq {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) + (ε : ℝ) (hε : 0 < ε) : + pmfMean p (fun a => if ε < |f a| then 1 else 0) ≤ + pmfMean p (fun a => f a ^ 2) / ε ^ 2 := by + classical + apply (le_div_iff₀ (sq_pos_of_pos hε)).mpr + rw [← pmfMean_mul_const] + apply pmfMean_mono + intro a _ + split_ifs with ha + · simp only [one_mul] + exact sq_le_sq.mpr (by rw [abs_of_pos hε]; exact le_of_lt ha) + · simp only [zero_mul] + exact sq_nonneg _ + +@[simp] theorem pmfMean_pure {α : Type*} [Fintype α] (a : α) (f : α → ℝ) : + pmfMean (PMF.pure a) f = f a := by + classical + simp [pmfMean, PMF.pure_apply, apply_ite] + +theorem pmfMean_bind {α β : Type*} [Fintype α] [Fintype β] + (p : PMF α) (q : α → PMF β) (f : β → ℝ) : + pmfMean (p.bind q) f = pmfMean p (fun a => pmfMean (q a) f) := by + classical + simp only [pmfMean, PMF.bind_apply, tsum_fintype] + have hfin (b : β) (a : α) : p a * q a b ≠ ⊤ := + ENNReal.mul_ne_top (p.apply_ne_top a) ((q a).apply_ne_top b) + simp_rw [ENNReal.toReal_sum (fun a _ => hfin _ a), Finset.sum_mul, + ENNReal.toReal_mul, Finset.mul_sum, mul_assoc] + exact Finset.sum_comm + +@[simp] theorem pmfMean_map {α β : Type*} [Fintype α] [Fintype β] + (p : PMF α) (g : α → β) (f : β → ℝ) : + pmfMean (p.map g) f = pmfMean p (fun a => f (g a)) := by + rw [← PMF.bind_pure_comp, pmfMean_bind] + simp + +theorem pmfMean_uniformOfFinset {α : Type*} [Fintype α] + (s : Finset α) (hs : s.Nonempty) (f : α → ℝ) : + pmfMean (PMF.uniformOfFinset s hs) f = (∑ a ∈ s, f a) / (s.card : ℝ) := by + classical + simp only [pmfMean, PMF.uniformOfFinset_apply] + simp_rw [apply_ite ENNReal.toReal, ENNReal.toReal_inv, ENNReal.toReal_natCast, + ENNReal.toReal_zero, ite_mul, zero_mul] + rw [← Finset.sum_filter] + simp only [Finset.filter_univ_mem] + simp only [div_eq_mul_inv, mul_comm, Finset.sum_mul] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/HistoryLawPastMean.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/HistoryLawPastMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..2eb0242d0679b84b4cf1683e4044362a978a7f45 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/HistoryLawPastMean.lean @@ -0,0 +1,147 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.History + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem historyLaw_past_mean {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) (T j k : ℕ) (hjk : j ≤ k) + (f : History α T → ℝ) + (hf : ∀ ω π, (∀ i : Fin (T+1), i.val ≤ min j T → ω i = π i) → f ω = f π) : + pmfMean (historyLaw initial K T k) f = + pmfMean (historyLaw initial K T j) f := by + classical + induction k, hjk using Nat.le_induction with + | base => rfl + | @succ k hjk ih => + change pmfMean ((historyLaw initial K T k).bind (historyKernel K T k)) f = _ + rw [pmfMean_bind] + have he (ω : History α T) : pmfMean (historyKernel K T k ω) f = f ω := by + by_cases hk : k < T + · rw [historyKernel,ite_eq_left hk,pmfMean_map] + have hu (b : α) : f (Function.update ω (historyIndex T (k+1)) b) = f ω := by + apply hf + intro i hi + apply Function.update_of_ne + intro hh + have hval := congrArg Fin.val hh + simp only [historyIndex,Nat.min_eq_left (by omega : k+1 ≤ T)] at hval + have : i.val ≤ j := hi.trans (Nat.min_le_left _ _) + omega + simp_rw [hu] + exact pmfMean_const _ _ + · rw [historyKernel,ite_eq_right hk,pmfMean_pure] + simp_rw [he] + exact ih + +lemma historyNoise_past {α : Type*} [Fintype α] (K : ℕ → α → PMF α) + (f : ℕ → α → ℝ) (T j : ℕ) (ω π : History α T) + (h : ∀ i : Fin (T+1), i.val ≤ min j T → ω i = π i) : + historyNoise K f T j ω = historyNoise K f T j π := by + unfold historyNoise + apply Finset.sum_congr rfl + intro s hs + have hs' : s < min j T := Finset.mem_range.mp hs + have hsc : (historyIndex T s).val ≤ min j T := by + simp only [historyIndex] + exact (Nat.min_le_left _ _).trans (Nat.le_of_lt hs') + have hsn : (historyIndex T (s+1)).val ≤ min j T := by + simp only [historyIndex] + exact (Nat.min_le_left _ _).trans (by omega) + simp only [historyIncrement,h _ hsc,h _ hsn] + +lemma historyCounter_past {α : Type*} (v : ℕ → α → ℝ) + (T j : ℕ) (ω π : History α T) + (h : ∀ i : Fin (T+1), i.val ≤ min j T → ω i = π i) : + historyCounter v T j ω = historyCounter v T j π := by + unfold historyCounter + apply Finset.sum_congr rfl + intro s hs + have hs' : s < min j T := Finset.mem_range.mp hs + have hsc : (historyIndex T s).val ≤ min j T := by + simp only [historyIndex] + exact (Nat.min_le_left _ _).trans (Nat.le_of_lt hs') + rw [h _ hsc] + +lemma pmfMean_finset_sum {α J : Type*} [Fintype α] (p : PMF α) + (s : Finset J) (f : J → α → ℝ) : + pmfMean p (fun a => ∑ j ∈ s, f j a) = ∑ j ∈ s, pmfMean p (f j) := by + simp only [pmfMean,Finset.mul_sum] + exact Finset.sum_comm + +open Classical in + +theorem pmfMean_event_union {α J : Type*} [Fintype α] (p : PMF α) + (s : Finset J) (P : J → α → Prop) : + pmfMean p (fun a => if ∃ j ∈ s, P j a then 1 else 0) ≤ + ∑ j ∈ s, pmfMean p (fun a => if P j a then 1 else 0) := by + classical + rw [← pmfMean_finset_sum] + apply pmfMean_mono + intro a _ + by_cases h : ∃ j ∈ s, P j a + · obtain ⟨j,hj,hP⟩ := h + rw [ite_eq_left ⟨j,hj,hP⟩] + have hh := Finset.single_le_sum (f := fun j => (if P j a then (1 : ℝ) else 0)) + (fun _ _ => by positivity) hj + simpa only [ite_eq_left hP] using hh + · rw [ite_eq_right h] + positivity + +theorem history_noise_freedman_maximal {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) (f v : ℕ → α → ℝ) + (T : ℕ) (c : ℝ) (hc : 0 < c) + (hbounded : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + ∀ b ∈ (K k a).support, + |f (k+1) b - pmfMean (K k a) (f (k+1))| ≤ c) + (hvar : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + pmfMean (K k a) (fun b => + (f (k+1) b - pmfMean (K k a) (f (k+1)))^2) ≤ v k a) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw initial K T T) + (fun ω => if ∃ j ≤ T, r ≤ historyNoise K f T j ω ∧ + historyCounter v T j ω ≤ V then 1 else 0) ≤ + (T+1 : ℝ) * Real.exp (-r^2/(4*(V+c*r))) := by + classical + have hcov := pmfMean_event_union (historyLaw initial K T T) (Finset.range (T+1)) + (fun j ω => r ≤ historyNoise K f T j ω ∧ historyCounter v T j ω ≤ V) + have hsum : (∑ j ∈ Finset.range (T+1), + pmfMean (historyLaw initial K T T) + (fun ω => if r ≤ historyNoise K f T j ω ∧ historyCounter v T j ω ≤ V + then 1 else 0)) ≤ (T+1 : ℝ)*Real.exp (-r^2/(4*(V+c*r))) := by + calc + _ ≤ ∑ _j ∈ Finset.range (T+1), Real.exp (-r^2/(4*(V+c*r))) := by + apply Finset.sum_le_sum + intro j hj + have hjT : j ≤ T := by have := Finset.mem_range.mp hj; omega + rw [historyLaw_past_mean initial K T j T hjT _ (by + intro ω π h + rw [historyNoise_past K f T j ω π h,historyCounter_past v T j ω π h])] + exact history_noise_freedman initial K f v T c hc hbounded hvar j r V hr hV + _ = _ := by simp + apply le_trans _ hsum + convert hcov using 1 <;> try rfl + · apply congrArg (pmfMean (historyLaw initial K T T)) + funext ω + simp only [Finset.mem_range,Nat.lt_succ_iff] + · apply Finset.sum_congr rfl + intro j _ + apply congrArg (pmfMean (historyLaw initial K T T)) + funext ω + split_ifs <;> rfl + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/HistoryLawPathSupport.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/HistoryLawPathSupport.lean new file mode 100644 index 0000000000000000000000000000000000000000..8dcfff21ed1a7c8360b90669b98de2ff0a2ba7a3 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/HistoryLawPathSupport.lean @@ -0,0 +1,66 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift +import OAI.Combinatorics.TriangleRemoval.Process.History + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem historyLaw_path_support {α : Type*} (initial : PMF α) + (K : ℕ → α → PMF α) (T k : ℕ) (hk : k ≤ T) + (ω : History α T) (hω : ω ∈ (historyLaw initial K T k).support) : + ω (historyIndex T 0) ∈ initial.support ∧ + ∀ j < k, ω (historyIndex T (j+1)) ∈ (K j (ω (historyIndex T j))).support := by + induction k generalizing ω with + | zero => + obtain ⟨a,ha,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hω + exact ⟨ha,fun _ h => (Nat.not_lt_zero _ h).elim⟩ + | succ k ih => + have hkt : k < T := by omega + obtain ⟨π,hπ,hω⟩ := (PMF.mem_support_bind_iff _ _ _).mp hω + rw [historyKernel,ite_eq_left hkt] at hω + obtain ⟨b,hb,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hω + obtain ⟨hinit,hpath⟩ := ih (by omega) π hπ + constructor + · rw [Function.update_of_ne (historyIndex_ne_succ (Nat.zero_le k) hkt)] + exact hinit + · intro j hj + by_cases he : j = k + · subst j + rw [Function.update_self, + Function.update_of_ne (historyIndex_ne_succ le_rfl hkt)] + exact hb + · have hjk : j < k := by omega + rw [Function.update_of_ne (historyIndex_ne_succ (by omega : j+1 ≤ k) hkt), + Function.update_of_ne (historyIndex_ne_succ hjk.le hkt)] + exact hpath j hjk + +theorem copyCount_nonneg {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) : 0 ≤ copyCount required G := by + apply Finset.sum_nonneg + intro a _ + unfold intact + split <;> norm_num + +theorem historyNoise_succ_same {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : ℕ → α → ℝ) + (T j : ℕ) (hj : j < T) (ω : History α T) : + historyNoise K f T (j+1) ω = + historyNoise K f T j ω + historyIncrement K f T j ω := by + simp only [historyNoise,Nat.min_eq_left (by omega : j+1 ≤ T), + Nat.min_eq_left hj.le,Finset.sum_range_succ] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/MainProbabilityPrefixFailure.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/MainProbabilityPrefixFailure.lean new file mode 100644 index 0000000000000000000000000000000000000000..27248b183f8074234e4085e4b0679e4c373fd485 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/MainProbabilityPrefixFailure.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.EvolveBindFinish + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem main_probability_prefix_failure_bound (c C : ℝ) (hc : 0 < c) + (ε : ℝ) (hε : 0 < ε) : ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, + probability n (fun H => ε < |normalizedLeave n H-sharpConstant|) ≤ + (δ+(2*(n : ℝ)+1)*prefixFailure n c C)/ε^2 := by + classical + intro δ hδ + filter_upwards [main_l2_prefix_failure_bound c C hc δ hδ] with n hn + have hh := pmfMean_markov_sq (terminalLaw n) + (fun H => normalizedLeave n H-sharpConstant) ε hε + exact hh.trans (div_le_div_of_nonneg_right hn (sq_nonneg ε)) + +theorem main_expectation_prefix_failure_bound (c C : ℝ) (hc : 0 < c) : + ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, + (expectation n (normalizedLeave n)-sharpConstant)^2 ≤ + δ+(2*(n : ℝ)+1)*prefixFailure n c C := by + intro δ hδ + filter_upwards [main_l2_prefix_failure_bound c C hc δ hδ] with n hn + have hh := pmfMean_sq_le (terminalLaw n) (fun H => normalizedLeave n H-sharpConstant) + rw [pmfMean_sub,pmfMean_const] at hh + exact hh.trans hn + +lemma expectation_normalizedLeave (n : ℕ) : + expectation n (normalizedLeave n) = + expectation n (fun H => (H.card : ℝ))/normalization n := by + change pmfMean (terminalLaw n) (fun graph => (graph.card : ℝ)/normalization n) = + pmfMean (terminalLaw n) (fun graph => (graph.card : ℝ))/normalization n + simp only [div_eq_mul_inv,pmfMean_mul_const] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/MarkedSuccessTrueProbability.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/MarkedSuccessTrueProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3ea01d27d450d24b00b2317665f09c961adc39d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/MarkedSuccessTrueProbability.lean @@ -0,0 +1,54 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.FinsetCandidateOrder + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +lemma markedSuccess_eq_trueProbability_fst (p : PMF (Bool × Bool)) : + markedSuccess p = trueProbability (p.map Prod.fst) := by + have hp := pmfMean_map p Prod.fst (fun b : Bool => if b then (1:ℝ) else 0) + rw [← markedSuccess] at hp + rw [← hp] + simp [pmfMean,trueProbability] + +section CandidateMarginal +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem markedChildKernel_success (H : τ → Finset ι) (N : ℕ) [NeZero N] + (required : List (ι × τ) → Bool) (d : ℕ) (address : List (ι × τ)) + (focus : Finset ι) (parent : Option τ) + (a : gridCandidates H focus parent) (u : Fin N) : + markedSuccess (markedChildKernel H N required d address focus parent a u) = + gridAnswerProbability H N d u.val ((H a.val.2).erase a.val.1) (some a.val.2) := by + rw [markedSuccess_eq_trueProbability_fst] + unfold markedChildKernel + rw [← ExposureTree.fresh_mapOutput,markedGridQueryDepth_outcome] + rfl + +theorem markedChildKernel_success_complete (H : τ → Finset ι) (N : ℕ) [NeZero N] + (required : List (ι × τ) → Bool) (d : ℕ) (address : List (ι × τ)) + (focus : Finset ι) (parent : Option τ) + (a : gridCandidates H focus parent) (u : Fin N) (hu : u.val ≤ d) : + markedSuccess (markedChildKernel H N required d address focus parent a u) = + ∏ f ∈ (H a.val.2).erase a.val.1, gridMessage H N N u.val f (some a.val.2) := by + rw [markedChildKernel_success,gridAnswerProbability_factor] + apply Finset.prod_congr rfl + intro f _ + exact gridMessage_stable H N u.val d N hu u.isLt.le f (some a.val.2) + +end CandidateMarginal +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/MarkovLaw.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/MarkovLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b9ab46d823fc4def4301fc01cb7f93a30240c88 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/MarkovLaw.lean @@ -0,0 +1,178 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.FiniteMean + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem pmfMean_exp_le {α : Type*} [Fintype α] (p : PMF α) + (X : α → ℝ) (c v lam : ℝ) (hlam : 0 ≤ lam) (hclam : lam * c ≤ 1) + (hbounded : ∀ a ∈ p.support, |X a| ≤ c) + (hmean : pmfMean p X ≤ 0) (hvar : pmfMean p (fun a => X a ^ 2) ≤ v) : + pmfMean p (fun a => Real.exp (lam * X a)) ≤ Real.exp (lam ^ 2 * v) := by + have hpt (a : α) (ha : a ∈ p.support) : + Real.exp (lam * X a) ≤ 1 + lam * X a + lam ^ 2 * X a ^ 2 := by + have hb : |lam * X a| ≤ 1 := by + rw [abs_mul, abs_of_nonneg hlam] + exact (mul_le_mul_of_nonneg_left (hbounded a ha) hlam).trans hclam + have h := (abs_le.mp (Real.abs_exp_sub_one_sub_id_le hb)).2 + nlinarith + calc + _ ≤ pmfMean p (fun a => (1 + lam * X a) + lam ^ 2 * X a ^ 2) := + pmfMean_mono p hpt + _ = 1 + lam * pmfMean p X + lam ^ 2 * pmfMean p (fun a => X a ^ 2) := by + rw [pmfMean_add, pmfMean_add, pmfMean_const, pmfMean_const_mul, + pmfMean_const_mul] + _ ≤ 1 + lam ^ 2 * v := by + have hs := mul_le_mul_of_nonneg_left hmean hlam + have hv := mul_le_mul_of_nonneg_left hvar (sq_nonneg lam) + nlinarith + _ ≤ _ := by simpa only [add_comm] using Real.add_one_le_exp (lam ^ 2 * v) + +noncomputable def markovLaw {α : Type*} (initial : PMF α) (K : ℕ → α → PMF α) : ℕ → PMF α + | 0 => initial + | k + 1 => (markovLaw initial K k).bind (K k) + +theorem markovMean_potential_le {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) (Z : ℕ → α → ℝ) + (hstep : ∀ k a, a ∈ (markovLaw initial K k).support → + pmfMean (K k a) (Z (k + 1)) ≤ Z k a) (k : ℕ) : + pmfMean (markovLaw initial K k) (Z k) ≤ pmfMean initial (Z 0) := by + induction k with + | zero => exact le_rfl + | succ k ih => + rw [markovLaw, pmfMean_bind] + exact (pmfMean_mono _ (hstep k)).trans ih + +theorem markovMean_exp_compensated_le {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) + (X V incrementVar : ℕ → α → ℝ) (c lam : ℝ) + (hlam : 0 ≤ lam) (hclam : lam * c ≤ 1) + (hbounded : ∀ k a, a ∈ (markovLaw initial K k).support → + ∀ b ∈ (K k a).support, |X (k + 1) b - X k a| ≤ c) + (hmean : ∀ k a, a ∈ (markovLaw initial K k).support → + pmfMean (K k a) (fun b => X (k + 1) b - X k a) ≤ 0) + (hvar : ∀ k a, a ∈ (markovLaw initial K k).support → + pmfMean (K k a) (fun b => (X (k + 1) b - X k a) ^ 2) ≤ incrementVar k a) + (hcounter : ∀ k a, a ∈ (markovLaw initial K k).support → + ∀ b ∈ (K k a).support, V (k + 1) b = V k a + incrementVar k a) + (k : ℕ) : + pmfMean (markovLaw initial K k) + (fun a => Real.exp (lam * X k a - lam ^ 2 * V k a)) ≤ + pmfMean initial (fun a => Real.exp (lam * X 0 a - lam ^ 2 * V 0 a)) := by + apply markovMean_potential_le initial K + (fun k a => Real.exp (lam * X k a - lam ^ 2 * V k a)) + intro j a ha + have hmgf := pmfMean_exp_le (K j a) (fun b => X (j + 1) b - X j a) + c (incrementVar j a) lam hlam hclam (hbounded j a ha) (hmean j a ha) (hvar j a ha) + have heq : pmfMean (K j a) (fun b => Real.exp (lam * X (j + 1) b - lam ^ 2 * V (j + 1) b)) = + Real.exp (lam * X j a - lam ^ 2 * V j a - lam ^ 2 * incrementVar j a) * + pmfMean (K j a) (fun b => Real.exp (lam * (X (j + 1) b - X j a))) := by + rw [← pmfMean_const_mul] + apply pmfMean_congr + intro b hb + rw [hcounter j a ha b hb, ← Real.exp_add] + congr 1 + ring + rw [heq] + calc + _ ≤ Real.exp (lam * X j a - lam ^ 2 * V j a - lam ^ 2 * incrementVar j a) * + Real.exp (lam ^ 2 * incrementVar j a) := + mul_le_mul_of_nonneg_left hmgf (Real.exp_pos _).le + _ = _ := by rw [← Real.exp_add]; congr 1; ring + +theorem pmfMean_compensated_tail {α : Type*} [Fintype α] (p : PMF α) + (X V : α → ℝ) (lam r v : ℝ) (hlam : 0 ≤ lam) + (hmgf : pmfMean p (fun a => Real.exp (lam * X a - lam ^ 2 * V a)) ≤ 1) : + pmfMean p (fun a => if r ≤ X a ∧ V a ≤ v then 1 else 0) ≤ + Real.exp (-lam * r + lam ^ 2 * v) := by + classical + have hevent (a : α) : + (if r ≤ X a ∧ V a ≤ v then (1 : ℝ) else 0) ≤ + Real.exp (lam * X a - lam ^ 2 * V a) * Real.exp (-lam * r + lam ^ 2 * v) := by + split_ifs with ha + · rw [← Real.exp_add, Real.one_le_exp_iff] + have hx := mul_le_mul_of_nonneg_left ha.1 hlam + have hv := mul_le_mul_of_nonneg_left ha.2 (sq_nonneg lam) + linarith + · positivity + calc + _ ≤ pmfMean p (fun a => + Real.exp (lam * X a - lam ^ 2 * V a) * Real.exp (-lam * r + lam ^ 2 * v)) := + pmfMean_mono p (fun a _ => hevent a) + _ = pmfMean p (fun a => Real.exp (lam * X a - lam ^ 2 * V a)) * + Real.exp (-lam * r + lam ^ 2 * v) := pmfMean_mul_const _ _ _ + _ ≤ 1 * Real.exp (-lam * r + lam ^ 2 * v) := + mul_le_mul_of_nonneg_right hmgf (Real.exp_pos _).le + _ = _ := one_mul _ + +theorem finite_freedman {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) + (X V incrementVar : ℕ → α → ℝ) (c : ℝ) (hc : 0 < c) + (hinitial : ∀ a ∈ initial.support, X 0 a ≤ 0 ∧ 0 ≤ V 0 a) + (hbounded : ∀ k a, a ∈ (markovLaw initial K k).support → + ∀ b ∈ (K k a).support, |X (k + 1) b - X k a| ≤ c) + (hmean : ∀ k a, a ∈ (markovLaw initial K k).support → + pmfMean (K k a) (fun b => X (k + 1) b - X k a) ≤ 0) + (hvar : ∀ k a, a ∈ (markovLaw initial K k).support → + pmfMean (K k a) (fun b => (X (k + 1) b - X k a) ^ 2) ≤ incrementVar k a) + (hcounter : ∀ k a, a ∈ (markovLaw initial K k).support → + ∀ b ∈ (K k a).support, V (k + 1) b = V k a + incrementVar k a) + (k : ℕ) (r v : ℝ) (hr : 0 < r) (hv : 0 ≤ v) : + pmfMean (markovLaw initial K k) + (fun a => if r ≤ X k a ∧ V k a ≤ v then 1 else 0) ≤ + Real.exp (-r ^ 2 / (4 * (v + c * r))) := by + classical + let A : ℝ := v + c * r + have hA : 0 < A := by dsimp [A]; positivity + let lam : ℝ := r / (2 * A) + have hlam : 0 ≤ lam := by dsimp [lam]; positivity + have hclam : lam * c ≤ 1 := by + dsimp [lam] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ (by positivity : (0 : ℝ) < 2 * A)).mpr + dsimp [A] + nlinarith [mul_pos hc hr] + have hmgf := markovMean_exp_compensated_le initial K X V incrementVar c lam hlam hclam + hbounded hmean hvar hcounter k + have hi : pmfMean initial (fun a => Real.exp (lam * X 0 a - lam ^ 2 * V 0 a)) ≤ 1 := by + rw [← pmfMean_const initial 1] + apply pmfMean_mono + intro a ha + apply Real.exp_le_one_iff.mpr + obtain ⟨hx, hv⟩ := hinitial a ha + have hx' := mul_le_mul_of_nonneg_left hx hlam + have hv' := mul_nonneg (sq_nonneg lam) hv + linarith + have hhalf : lam * v ≤ r / 2 := by + dsimp [lam] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ (by positivity : (0 : ℝ) < 2 * A)).mpr + dsimp [A] + nlinarith [mul_nonneg hc.le (sq_nonneg r)] + have hexponent : -lam * r + lam ^ 2 * v ≤ -r ^ 2 / (4 * (v + c * r)) := by + have hmul := mul_le_mul_of_nonneg_left hhalf hlam + calc + _ ≤ -lam * r / 2 := by nlinarith + _ = _ := by + dsimp [lam] + change -(r / (2 * A)) * r / 2 = -r ^ 2 / (4 * A) + field_simp + ring + exact (pmfMean_compensated_tail _ (X k) (V k) lam r v hlam (hmgf.trans hi)).trans + (Real.exp_le_exp.mpr hexponent) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/PairVisitProbability.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PairVisitProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..31ec6f51e3cd7a57b4336231f034899b36cf19a5 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PairVisitProbability.lean @@ -0,0 +1,57 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.PathVisitProbability +import OAI.Combinatorics.TriangleRemoval.Queries.JointMarkedQueryPair + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave +section TracePairProbability +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def actualPairVisitProbability (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) + (path₁ path₂ : List (ι × τ)) : ℝ := + (((ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (tracedGridQuery H N d k ⟨[],focus,parent⟩)).map + (fun z => z.2.any (fun c => decide (c.address = path₁.reverse)) && + z.2.any (fun c => decide (c.address = path₂.reverse)))) true).toReal + +theorem actualPairVisitProbability_le_marked (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (path₁ path₂ : List (ι × τ)) : + actualPairVisitProbability H N d k focus parent path₁ path₂ ≤ + pairVisitProbability H N d k focus parent path₁ path₂ := by + let c : QueryCall ι τ := ⟨[],focus,parent⟩ + let ν := fun _ : τ => PMF.uniformOfFintype (Fin N) + let P := ExposureTree.fresh ν (jointMarkedQuery H N (pairRequired path₁ path₂) d k c) + have ht : P.map (fun z => (z.1,z.2.2)) = + ExposureTree.fresh ν (tracedGridQuery H N d k c) := by + rw [← ExposureTree.fresh_mapOutput,jointMarkedQuery_trace] + have hm : P.map (fun z => (z.1,z.2.1)) = + ExposureTree.fresh ν (markedGridQueryDepth H N (pairRequired path₁ path₂) d k [] focus parent) := by + rw [← ExposureTree.fresh_mapOutput,jointMarkedQuery_marked] + unfold actualPairVisitProbability pairVisitProbability + rw [markedGood_map_true,← ht,← hm,PMF.map_comp,PMF.map_comp] + apply pmf_boolean_map_le + intro z hz hh + obtain ⟨hp,hq⟩ := Bool.and_eq_true_iff.mp hh + obtain ⟨a,ha,hea⟩ := List.any_eq_true.mp hp + obtain ⟨b,hb,heb⟩ := List.any_eq_true.mp hq + apply jointMarkedQuery_pair_hit H N d k c path₁ path₂ ν hz + · exact ⟨a,ha,by simpa only [c,List.append_nil] using of_decide_eq_true hea⟩ + · exact ⟨b,hb,by simpa only [c,List.append_nil] using of_decide_eq_true heb⟩ + +end TracePairProbability +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/PathVisitProbability.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PathVisitProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..245cb83506296e80c34c5ef6f0ea934c90276487 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PathVisitProbability.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PathRequiredBaseChild + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma pmf_boolean_map_le {A : Type*} (P : PMF A) (f g : A → Bool) + (h : ∀ a ∈ P.support, f a = true → g a = true) : + ((P.map f) true).toReal ≤ ((P.map g) true).toReal := by + apply ENNReal.toReal_mono (PMF.apply_ne_top _ _) + simp only [PMF.map_apply] + apply ENNReal.tsum_le_tsum + intro a + by_cases ha : P a = 0 + · simp only [ha,ite_self,le_refl] + · by_cases hf : f a = true + · have hg := h a ((PMF.mem_support_iff _ _).mpr ha) hf + simp only [hf,hg,↓reduceIte,le_refl] + · simp only [Ne.symm hf,↓reduceIte,zero_le] + +lemma markedGood_map_true (p : PMF (Bool × Bool)) : + markedGood p = ((p.map Prod.snd) true).toReal := by + unfold markedGood + rw [← pmfMean_map p Prod.snd (fun b => if b then 1 else 0)] + simp [pmfMean] + +section TracePathProbability +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def actualPathVisitProbability (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (path : List (ι × τ)) : ℝ := + (((ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (tracedGridQuery H N d k ⟨[],focus,parent⟩)).map + (fun z => z.2.any (fun c => decide (c.address = path.reverse)))) true).toReal + +theorem actualPathVisitProbability_le_marked (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (path : List (ι × τ)) : + actualPathVisitProbability H N d k focus parent path ≤ + pathVisitProbability H N d k focus parent path := by + let c : QueryCall ι τ := ⟨[],focus,parent⟩ + let ν := fun _ : τ => PMF.uniformOfFintype (Fin N) + let P := ExposureTree.fresh ν (jointMarkedQuery H N (pathRequired path) d k c) + have ht : P.map (fun z => (z.1,z.2.2)) = + ExposureTree.fresh ν (tracedGridQuery H N d k c) := by + rw [← ExposureTree.fresh_mapOutput,jointMarkedQuery_trace] + have hm : P.map (fun z => (z.1,z.2.1)) = + ExposureTree.fresh ν (markedGridQueryDepth H N (pathRequired path) d k [] focus parent) := by + rw [← ExposureTree.fresh_mapOutput,jointMarkedQuery_marked] + unfold actualPathVisitProbability pathVisitProbability + rw [markedGood_map_true] + rw [← ht,← hm,PMF.map_comp,PMF.map_comp] + apply pmf_boolean_map_le + intro z hz hh + obtain ⟨a,ha,hea⟩ := List.any_eq_true.mp hh + have hit : ∃ a ∈ z.2.2, a.address = path.reverse ++ c.address := by + exact ⟨a,ha,by simpa only [c,List.append_nil] using of_decide_eq_true hea⟩ + exact jointMarkedQuery_hit H N d k c path ν hz hit + +theorem actualPathVisitProbability_factorial (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (path : List (ι × τ)) (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) + (hlen : path.length ≤ d) (e : ι) (T : τ) (he : e ∈ H T) + (hpath : LegalQueryPath H ((H T).erase e) (some T) path) : + actualPathVisitProbability H N d k ((H T).erase e) (some T) path ≤ + prefixWeight (fun t => (2/(N : ℝ))*b t) k ^ path.length / + (path.length.factorial : ℝ) := + (actualPathVisitProbability_le_marked H N d k _ _ path).trans + (pathVisitProbability_factorial H N b hb hq path d k hkd hkN hlen e T he hpath) + +end TracePathProbability +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanAffineSq.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanAffineSq.lean new file mode 100644 index 0000000000000000000000000000000000000000..dbb3559531d736f7577a894d519487653ff6fb0d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanAffineSq.lean @@ -0,0 +1,72 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.ContinuationCollisionRemainderTendsto + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma pmfMean_affine_sq_bound {α : Type*} [Fintype α] (P : PMF α) + (f : α → ℝ) (a b : ℝ) : + pmfMean P (fun x => (a*f x+b)^2) ≤ 2*a^2*pmfMean P (fun x => (f x)^2)+2*b^2 := by + calc + _ ≤ pmfMean P (fun x => (2*a^2)*(f x)^2+2*b^2) := by + apply pmfMean_mono + intro x _ + nlinarith [sq_nonneg (a*f x-b)] + _ = _ := by rw [pmfMean_add,pmfMean_const_mul,pmfMean_const] + +theorem goodPrefix_normalized_l2 (c C : ℝ) (hc : 0 < c) : + ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, + ∀ (G : Graph n), GoodPrefixGraph n c C G → + pmfMean (finish G) (fun H => (normalizedLeave n H-sharpConstant)^2) < δ := by + intro δ hδ + let s : ℕ → ℝ := fun n => prefixM n*cavityReference (prefixD n) 1/normalization n + have hs : Tendsto s atTop (𝓝 sharpConstant) := prefix_terminal_scale_tendsto + have hs2 : ∀ᶠ n : ℕ in atTop, s n ^ 2 ≤ 1 := by + have hh := hs.pow 2 + rw [sharpConstant_sq] at hh + exact (hh.eventually (gt_mem_nhds (by norm_num : (1/8 : ℝ) < 1))).mono (fun _ h => h.le) + have hbias : Tendsto (fun n => 2*(s n-sharpConstant)^2) atTop (𝓝 (0 : ℝ)) := by + simpa using ((hs.sub_const sharpConstant).pow 2).const_mul (2 : ℝ) + filter_upwards [goodPrefix_relative_l2 c C hc (δ/4) (by positivity),hs2, + hbias.eventually (gt_mem_nhds (by linarith : (0 : ℝ) < δ/2)), + prefix_scales_eventually_pos,eventually_ge_atTop (1 : ℕ)] with n hr hsqr hb hp hn + intro G hG + have hn0 : 0 < n := by omega + have hnorm : 0 < normalization n := normalization_pos hn0 + have hm0 : 0 < (G.card : ℝ) := by rw [hG.2.1]; unfold prefixM; have := hp.1; positivity + have hq : 0 < cavityReference (prefixD n) 1 := + cavityReference_pos (by linarith [hp.2]) (by norm_num) + let f : Graph n → ℝ := fun H => (H.card : ℝ)/((G.card : ℝ)*cavityReference (prefixD n) 1)-1 + have heq : (fun H => (normalizedLeave n H-sharpConstant)^2) = + (fun H => (s n*f H+(s n-sharpConstant))^2) := by + funext H + congr 1 + dsimp only [s,f,normalizedLeave] + rw [← hG.2.1] + field_simp [ne_of_gt hm0, ne_of_gt hq, ne_of_gt hnorm] + ring + have hnon : 0 ≤ pmfMean (finish G) (fun H => f H^2) := pmfMean_nonneg _ (fun _ _ => sq_nonneg _) + rw [heq] + calc + _ ≤ 2*(s n)^2*pmfMean (finish G) (fun H => f H^2)+2*(s n-sharpConstant)^2 := + pmfMean_affine_sq_bound _ f _ _ + _ ≤ 2*pmfMean (finish G) (fun H => f H^2)+2*(s n-sharpConstant)^2 := by + have hh := mul_le_mul_of_nonneg_right hsqr hnon + nlinarith + _ < δ := by have hh := hr G hG; change pmfMean (finish G) (fun H => f H^2) < δ/4 at hh; linarith + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanLiminfTendsto.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanLiminfTendsto.lean new file mode 100644 index 0000000000000000000000000000000000000000..e8b5e32f61f98c72c4268b301bb884a58205a9cd --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanLiminfTendsto.lean @@ -0,0 +1,43 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.FiniteMean + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem pmfMean_liminf_le_of_tendsto_upper {α : Type*} [Fintype α] + (p : PMF α) (f : α → ℕ → ℝ) (hbound : ∀ a j, 0 ≤ f a j) + (g : ℕ → ℝ) {L : ℝ} (hg : Tendsto g atTop (𝓝 L)) + (hupper : ∀ᶠ j : ℕ in atTop, pmfMean p (fun a => f a j) ≤ g j) : + pmfMean p (fun a => Filter.liminf (f a) atTop) ≤ L := by + apply le_of_forall_pos_le_add + intro ε hε + have hevent (a : α) : ∀ᶠ j : ℕ in atTop, + Filter.liminf (f a) atTop - ε ≤ f a j := by + have hl : atTop.IsBoundedUnder (· ≥ ·) (f a) := + Filter.isBoundedUnder_of ⟨0, fun j => hbound a j⟩ + exact (Filter.eventually_lt_of_lt_liminf (sub_lt_self _ hε) hl).mono (fun _ h => h.le) + have hall : ∀ᶠ j : ℕ in atTop, ∀ a, Filter.liminf (f a) atTop - ε ≤ f a j := + Filter.eventually_all.mpr hevent + have hle : pmfMean p (fun a => Filter.liminf (f a) atTop) - ε ≤ L := by + apply le_of_tendsto_of_tendsto tendsto_const_nhds hg + filter_upwards [hall,hupper] with j hj hU + have hh := pmfMean_mono p (fun a _ => hj a) + rw [pmfMean_sub,pmfMean_const] at hh + exact hh.trans hU + linarith + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanNeg.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanNeg.lean new file mode 100644 index 0000000000000000000000000000000000000000..140bd3d1166c219af45ef02a4cf7e75cbf76ff95 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/PmfMeanNeg.lean @@ -0,0 +1,79 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.HistoryAdditive + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma pmfMean_neg {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) : + pmfMean p (fun a => -f a) = -pmfMean p f := by + simp only [pmfMean,mul_neg,Finset.sum_neg_distrib] + +lemma historyAdditive_neg {α : Type*} (g : ℕ → α → α → ℝ) + (T j : ℕ) (ω : History α T) : + historyAdditive (fun k a b => -g k a b) T j ω = -historyAdditive g T j ω := by + simp only [historyAdditive,Finset.sum_neg_distrib] + +theorem history_additive_freedman_two_sided {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) (g : ℕ → α → α → ℝ) (v : ℕ → α → ℝ) + (T : ℕ) (c : ℝ) (hc : 0 < c) + (hbounded : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + ∀ b ∈ (K k a).support, |g k a b| ≤ c) + (hmean : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, pmfMean (K k a) (g k a) = 0) + (hvar : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + pmfMean (K k a) (fun b => (g k a b)^2) ≤ v k a) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw initial K T T) + (fun ω => if ∃ j ≤ T, r ≤ |historyAdditive g T j ω| ∧ + historyCounter v T j ω ≤ V then 1 else 0) ≤ + 2*(T+1 : ℝ)*Real.exp (-r^2/(4*(V+c*r))) := by + classical + have hp := history_additive_freedman_maximal initial K g v T c hc hbounded hmean hvar r V hr hV + have hn := history_additive_freedman_maximal initial K (fun k a b => -g k a b) v T c hc + (by intro k hk a ha b hb; simpa only [abs_neg] using hbounded k hk a ha b hb) + (by intro k hk a ha; rw [pmfMean_neg,hmean k hk a ha,neg_zero]) + (by intro k hk a ha; simpa only [neg_sq] using hvar k hk a ha) r V hr hV + have hcov : pmfMean (historyLaw initial K T T) + (fun ω => if ∃ j ≤ T, r ≤ |historyAdditive g T j ω| ∧ historyCounter v T j ω ≤ V + then 1 else 0) ≤ + pmfMean (historyLaw initial K T T) + (fun ω => if ∃ j ≤ T, r ≤ historyAdditive g T j ω ∧ historyCounter v T j ω ≤ V + then 1 else 0) + + pmfMean (historyLaw initial K T T) + (fun ω => if ∃ j ≤ T, r ≤ historyAdditive (fun k a b => -g k a b) T j ω ∧ + historyCounter v T j ω ≤ V then 1 else 0) := by + rw [← pmfMean_add] + apply pmfMean_mono + intro ω _ + by_cases h : ∃ j ≤ T, r ≤ |historyAdditive g T j ω| ∧ historyCounter v T j ω ≤ V + · obtain ⟨j,hj,hx,hv⟩ := h + rw [ite_eq_left ⟨j,hj,hx,hv⟩] + rcases le_total 0 (historyAdditive g T j ω) with hx0 | hx0 + · rw [abs_of_nonneg hx0] at hx + rw [ite_eq_left ⟨j,hj,hx,hv⟩] + split_ifs <;> norm_num + · rw [abs_of_nonpos hx0] at hx + have hneg : r ≤ historyAdditive (fun k a b => -g k a b) T j ω := by + rwa [historyAdditive_neg] + have hnegE : ∃ j ≤ T, r ≤ historyAdditive (fun k a b => -g k a b) T j ω ∧ + historyCounter v T j ω ≤ V := ⟨j,hj,hneg,hv⟩ + rw [ite_eq_left hnegE] + split_ifs <;> norm_num + · rw [ite_eq_right h] + split_ifs <;> norm_num + exact hcov.trans (by nlinarith [hp,hn]) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/ProductPMF.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/ProductPMF.lean new file mode 100644 index 0000000000000000000000000000000000000000..66453edd8e5012b452d1efe268ce8fafece594e5 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/ProductPMF.lean @@ -0,0 +1,216 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +noncomputable def productPMF {K V : Type*} [Fintype K] [DecidableEq K] [Fintype V] + (ρ : K → PMF V) : PMF (K → V) := + PMF.ofFintype (fun ω => ∏ k, ρ k (ω k)) (by + calc + (∑ ω : K → V, ∏ k, ρ k (ω k)) = ∏ k, ∑ v, ρ k v := + (Fintype.prod_sum (fun (k : K) (v : V) => ρ k v)).symm + _ = 1 := by + apply Finset.prod_eq_one + intro k _ + simpa only [tsum_fintype] using (ρ k).tsum_coe) + +@[simp] theorem productPMF_apply {K V : Type*} [Fintype K] [DecidableEq K] [Fintype V] + (ρ : K → PMF V) (ω : K → V) : productPMF ρ ω = ∏ k, ρ k (ω k) := rfl + +@[simp] theorem productPMF_support {K V : Type*} [Fintype K] [DecidableEq K] [Fintype V] + (ρ : K → PMF V) (ω : K → V) : + ω ∈ (productPMF ρ).support ↔ ∀ k, ω k ∈ (ρ k).support := by + simp [PMF.mem_support_iff, Finset.prod_ne_zero_iff] + +theorem productPMF_update_apply {K V : Type*} [Fintype K] [DecidableEq K] + [Fintype V] [DecidableEq V] (ρ : K → PMF V) (k : K) (v : V) (ω : K → V) : + productPMF (Function.update ρ k (PMF.pure v)) ω = + (if ω k = v then 1 else 0) * ∏ j ∈ Finset.univ.erase k, ρ j (ω j) := by + rw [productPMF_apply, ← Finset.prod_erase_mul _ _ (Finset.mem_univ k)] + have hh : (∏ j ∈ Finset.univ.erase k, Function.update ρ k (PMF.pure v) j (ω j)) = + ∏ j ∈ Finset.univ.erase k, ρ j (ω j) := by + apply Finset.prod_congr rfl + intro j hj + rw [Function.update_of_ne (Finset.mem_erase.mp hj).1] + rw [hh, Function.update_self] + simp only [PMF.pure_apply, eq_comm] + exact mul_comm _ _ + +theorem productPMF_split {K V : Type*} [Fintype K] [DecidableEq K] + [Fintype V] [DecidableEq V] (ρ : K → PMF V) (k : K) : + productPMF ρ = (ρ k).bind (fun v => productPMF (Function.update ρ k (PMF.pure v))) := by + ext ω + rw [PMF.bind_apply, tsum_fintype] + simp only [productPMF_update_apply] + rw [Finset.sum_eq_single (ω k)] + · simp only [ite_true, one_mul] + rw [productPMF_apply, ← Finset.prod_erase_mul _ _ (Finset.mem_univ k)] + exact mul_comm _ _ + · intro v _ hv + simp only [ite_eq_right (Ne.symm hv), zero_mul, mul_zero] + · simp + +inductive ExposureTree (K V O : Type*) where + | done : O → ExposureTree K V O + | ask : K → (V → ExposureTree K V O) → ExposureTree K V O + +namespace ExposureTree +variable {K V O : Type*} + +def evaluate (ω : K → V) : ExposureTree K V O → O + | .done o => o + | .ask k f => evaluate ω (f (ω k)) + +noncomputable def fresh (ν : K → PMF V) : ExposureTree K V O → PMF O + | .done o => PMF.pure o + | .ask k f => (ν k).bind (fun v => fresh ν (f v)) + +noncomputable def coupled [DecidableEq K] (ν : K → PMF V) (ω : K → V) : + ExposureTree K V O → Finset K → PMF (O × Bool) + | .done o, _ => PMF.pure (o, false) + | .ask k f, seen => + if k ∈ seen then + (ν k).bind (fun v => (coupled ν ω (f v) seen).map (fun z => (z.1, true))) + else coupled ν ω (f (ω k)) (insert k seen) + +theorem coupled_agrees [DecidableEq K] (ν : K → PMF V) (ω : K → V) + (P : ExposureTree K V O) (seen : Finset K) (o : O) + (ho : (o, false) ∈ (coupled ν ω P seen).support) : evaluate ω P = o := by + induction P generalizing seen with + | done a => + have hh : (o, false) = (a, false) := by simpa [coupled] using ho + exact (congrArg Prod.fst hh).symm + | ask k f ih => + by_cases hk : k ∈ seen + · simp only [coupled, ite_eq_left hk, PMF.mem_support_bind_iff] at ho + obtain ⟨v, _, hv⟩ := ho + rcases (PMF.mem_support_map_iff _ _ _).mp hv with ⟨z, _, hz⟩ + exact False.elim (by simpa using congrArg Prod.snd hz) + · exact ih (ω k) (insert k seen) (by simpa [coupled, hk] using ho) + +noncomputable def freshRecorded [DecidableEq K] (ν : K → PMF V) : + ExposureTree K V O → Finset K → PMF (O × Bool) + | .done o, _ => PMF.pure (o, false) + | .ask k f, seen => + (ν k).bind (fun v => if k ∈ seen then + (freshRecorded ν (f v) seen).map (fun z => (z.1, true)) + else freshRecorded ν (f v) (insert k seen)) + +theorem freshRecorded_outcome [DecidableEq K] (ν : K → PMF V) + (P : ExposureTree K V O) (seen : Finset K) : + (freshRecorded ν P seen).map Prod.fst = fresh ν P := by + induction P generalizing seen with + | done o => simp [freshRecorded, fresh, PMF.pure_map] + | ask k f ih => + simp only [freshRecorded, PMF.map_bind, fresh] + congr 1 + funext v + by_cases hk : k ∈ seen + · simp only [ite_eq_left hk, PMF.map_comp] + exact ih v seen + · simp only [ite_eq_right hk] + exact ih v (insert k seen) + +end ExposureTree + +theorem pmf_bind_congr_on_support {α β : Type*} (p : PMF α) (f g : α → PMF β) + (h : ∀ a ∈ p.support, f a = g a) : p.bind f = p.bind g := by + ext b + simp only [PMF.bind_apply] + apply tsum_congr + intro a + by_cases ha : p a = 0 + · simp only [ha, zero_mul] + · rw [h a ha] + +namespace ExposureTree +variable {K V O : Type*} [Fintype K] [DecidableEq K] [Fintype V] [DecidableEq V] + +theorem coupled_independent_law (ν : K → PMF V) (P : ExposureTree K V O) + (seen : Finset K) (ρ : K → PMF V) (hρ : ∀ k ∉ seen, ρ k = ν k) : + (productPMF ρ).bind (fun ω => coupled ν ω P seen) = freshRecorded ν P seen := by + induction P generalizing seen ρ with + | done o => simp [coupled, freshRecorded, PMF.bind_const] + | ask k f ih => + by_cases hk : k ∈ seen + · simp only [coupled, ite_eq_left hk, freshRecorded] + rw [PMF.bind_comm] + congr 1 + funext v + rw [← PMF.map_bind] + exact congrArg (fun p : PMF (O × Bool) => p.map (fun z => (z.1, true))) + (ih v seen ρ hρ) + · simp only [coupled, ite_eq_right hk, freshRecorded] + rw [productPMF_split ρ k, PMF.bind_bind, hρ k hk] + congr 1 + funext v + let ρ' : K → PMF V := Function.update ρ k (PMF.pure v) + have hv : ∀ ω ∈ (productPMF ρ').support, ω k = v := by + intro ω hω + have hh := (productPMF_support ρ' ω).mp hω k + simpa only [ρ', Function.update_self, PMF.mem_support_pure_iff] using hh + calc + _ = (productPMF ρ').bind + (fun ω => coupled ν ω (f v) (insert k seen)) := by + apply pmf_bind_congr_on_support + intro ω hω + rw [hv ω hω] + _ = freshRecorded ν (f v) (insert k seen) := by + apply ih v (insert k seen) ρ' + intro j hj + have hjs : j ∉ seen := fun h => hj (Finset.mem_insert_of_mem h) + have hjk : j ≠ k := fun h => hj (h ▸ Finset.mem_insert_self _ _) + simp only [ρ', Function.update_of_ne hjk, hρ j hjs] + +theorem coupled_independent_law_empty (ν : K → PMF V) (P : ExposureTree K V O) : + (productPMF ν).bind (fun ω => coupled ν ω P ∅) = freshRecorded ν P ∅ := + coupled_independent_law ν P ∅ ν (fun _ _ => rfl) + +noncomputable def jointLaw (ν : K → PMF V) (P : ExposureTree K V O) : + PMF (O × (O × Bool)) := + (productPMF ν).bind (fun ω => + (coupled ν ω P ∅).map (fun z => (evaluate ω P, z))) + +omit [DecidableEq V] in + +theorem jointLaw_fixed (ν : K → PMF V) (P : ExposureTree K V O) : + (jointLaw ν P).map Prod.fst = (productPMF ν).map (fun ω => evaluate ω P) := by + simp only [jointLaw, PMF.map_bind, PMF.map_comp] + change (productPMF ν).bind (fun ω => + (coupled ν ω P ∅).map (Function.const (O × Bool) (evaluate ω P))) = _ + simp only [PMF.map_const] + rfl + +theorem jointLaw_fresh (ν : K → PMF V) (P : ExposureTree K V O) : + (jointLaw ν P).map Prod.snd = freshRecorded ν P ∅ := by + simp only [jointLaw, PMF.map_bind, PMF.map_comp] + change (productPMF ν).bind (fun ω => (coupled ν ω P ∅).map id) = _ + simp only [PMF.map_id] + exact coupled_independent_law_empty ν P + +omit [DecidableEq V] in + +theorem jointLaw_agrees (ν : K → PMF V) (P : ExposureTree K V O) + (z : O × (O × Bool)) (hz : z ∈ (jointLaw ν P).support) (hf : z.2.2 = false) : + z.1 = z.2.1 := by + rcases (PMF.mem_support_bind_iff _ _ _).mp hz with ⟨ω, _, hω⟩ + rcases (PMF.mem_support_map_iff _ _ _).mp hω with ⟨o, ho, hzo⟩ + subst z + have he : o = (o.1, false) := Prod.ext rfl hf + rw [he] at ho + exact coupled_agrees ν ω P ∅ o.1 ho + +end ExposureTree +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/ProductPMFMeanProduct.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/ProductPMFMeanProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..c36c4c1097ac0a386cd0bd3a5f5d98783c76ab69 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/ProductPMFMeanProduct.lean @@ -0,0 +1,75 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.FiniteMean +import OAI.Combinatorics.TriangleRemoval.Probability.ProductPMF + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +theorem productPMF_mean_product {K V : Type*} [Fintype K] [DecidableEq K] [Fintype V] + (ρ : K → PMF V) (w : K → V → ℝ) : + pmfMean (productPMF ρ) (fun ω => ∏ k, w k (ω k)) = + ∏ k, pmfMean (ρ k) (w k) := by + simp only [pmfMean, productPMF_apply, ENNReal.toReal_prod, ← Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun k v => (ρ k v).toReal * w k v)).symm + +theorem prospective_block_product {X K V : Type*} [Fintype X] [Fintype K] + [DecidableEq K] [Fintype V] (π : PMF X) (ρ : K → PMF V) + (F : X → ℝ) (w : K → X → V → ℝ) : + pmfMean π (fun x => pmfMean (productPMF ρ) + (fun ω => F x * ∏ k, w k x (ω k))) = + pmfMean π (fun x => F x * ∏ k, pmfMean (ρ k) (w k x)) := by + apply pmfMean_congr + intro x _ + rw [pmfMean_const_mul, productPMF_mean_product] + +theorem uniform_prospective_failure (N : ℕ) [NeZero N] (t : ℕ) (q : Fin N → ℝ) : + pmfMean (PMF.uniformOfFintype (Fin N)) + (fun u => if u.val < t then 1 - q u else 1) = + 1 - (∑ u : Fin N, if u.val < t then q u else 0) / (N : ℝ) := by + have hpt : (fun u : Fin N => if u.val < t then 1 - q u else 1) = + (fun u : Fin N => 1 - (if u.val < t then q u else 0)) := by + funext u + split_ifs <;> simp + rw [hpt, pmfMean_sub, pmfMean_const] + congr 1 + simp only [pmfMean, PMF.uniformOfFintype_apply, ENNReal.toReal_inv, + ENNReal.toReal_natCast, Fintype.card_fin, ← Finset.mul_sum, div_eq_mul_inv, mul_comm] + +theorem offpattern_product_bound {K : Type*} [DecidableEq K] + (C S : Finset K) (hSC : S ⊆ C) (hS : S.card ≤ 2) (f : K → ℝ) (b : ℝ) + (hf : ∀ k ∈ C, (7 / 8 : ℝ) ≤ f k) (hfull : ∏ k ∈ C, f k ≤ (9 / 8 : ℝ) * b) : + ∏ k ∈ C \ S, f k ≤ 2 * b := by + have hn : ∀ k ∈ C, 0 ≤ f k := fun k hk => le_trans (by norm_num) (hf k hk) + have hp : (7 / 8 : ℝ) ^ S.card ≤ ∏ k ∈ S, f k := by + simpa only [Finset.prod_const] using Finset.prod_le_prod₀ + (fun k (_ : k ∈ S) => by norm_num : ∀ k ∈ S, (0 : ℝ) ≤ 7 / 8) + (fun k hk => hf k (hSC hk)) + have hp' : (49 / 64 : ℝ) ≤ ∏ k ∈ S, f k := by + have hc : S.card = 0 ∨ S.card = 1 ∨ S.card = 2 := by omega + rcases hc with h | h | h <;> rw [h] at hp <;> norm_num at hp ⊢ <;> linarith + have ho : 0 ≤ ∏ k ∈ C \ S, f k := Finset.prod_nonneg + (fun k hk => hn k (Finset.mem_sdiff.mp hk).1) + have he : (∏ k ∈ S, f k) * (∏ k ∈ C \ S, f k) = ∏ k ∈ C, f k := by + rw [mul_comm, Finset.prod_sdiff hSC] + have hb : 0 ≤ b := by + have hh : 0 ≤ ∏ k ∈ C, f k := Finset.prod_nonneg hn + linarith + have hm := mul_le_mul_of_nonneg_right hp' ho + rw [he] at hm + linarith + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPairVisitProbability.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPairVisitProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..8e8f63ab4f9571438902d31d830dfbc3fa58ad0e --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPairVisitProbability.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PairRequired + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave +section RootForkVisitation +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem rootPairVisitProbability_fork (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 0 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (hkd : k ≤ d+1) (hkN : k ≤ N) + (focus : Finset ι) (parent : Option τ) + (a b' : gridCandidates H focus parent) (hab : a ≠ b') + (as bs : List (ι × τ)) (ha : LegalQueryPath H ((H a.val.2).erase a.val.1) (some a.val.2) as) + (hb' : LegalQueryPath H ((H b'.val.2).erase b'.val.1) (some b'.val.2) bs) + (halen : as.length ≤ d) (hblen : bs.length ≤ d) : + pairVisitProbability H N (d+1) k focus parent (a.val :: as) (b'.val :: bs) ≤ + C^2 * orderedWeight (fun t => (2/(N : ℝ))*b t) (as.length+1) k * + orderedWeight (fun t => (2/(N : ℝ))*b t) (bs.length+1) k := by + let A := fun t => orderedWeight (fun t => (2/(N : ℝ))*b t) as.length t + let B := fun t => orderedWeight (fun t => (2/(N : ℝ))*b t) bs.length t + have hA : ∀ t, 0 ≤ A t := fun t => orderedWeight_nonneg (fun t => mul_nonneg (by positivity) (hb t)) _ t + have hB : ∀ t, 0 ≤ B t := fun t => orderedWeight_nonneg (fun t => mul_nonneg (by positivity) (hb t)) _ t + have hstep := markedQuery_two_paths H N (pairRequired (a.val :: as) (b'.val :: bs)) d k hkd hkN [] + focus parent a b' hab (pair_required_candidates H _ _ a b' as bs) (fun _ => 1) + (fun t ht => hq.1 t (by omega)) + (fun t _ => (gridAnswerProbability_mem_unit H N N t focus parent).2.trans (by norm_num)) + have hac := (Finset.mem_filter.mp a.property).2.1 + have hbc := (Finset.mem_filter.mp b'.property).2.1 + calc + _ ≤ (1/(N : ℝ))*∑ u : Fin N, (1/(N : ℝ))*∑ v : Fin N, + if u.val < k ∧ v.val < k then + (markedGood (markedChildKernel H N (pairRequired (a.val :: as) (b'.val :: bs)) d [] + focus parent a u)* + markedGood (markedChildKernel H N (pairRequired (a.val :: as) (b'.val :: bs)) d [] + focus parent b' v))*(2*1) else 0 := hstep + _ ≤ (1/(N : ℝ))*∑ u : Fin N, (1/(N : ℝ))*∑ v : Fin N, + C^2*((if u.val < k then A u.val*(2*b u.val) else 0)* + (if v.val < k then B v.val*(2*b v.val) else 0)) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro u _ + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro v _ + by_cases hu : u.val < k <;> by_cases hv : v.val < k + · simp only [hu,hv,and_self,↓reduceIte] + rw [marked_pair_child_left H N d _ _ a b' hab as bs u, + marked_pair_child_right H N d _ _ a b' hab as bs v] + have hau := pathVisitProbability_ordered H N b hb hq as d u.val (by omega) u.isLt.le + halen a.val.1 a.val.2 hac ha + have hbv := pathVisitProbability_ordered H N b hb hq bs d v.val (by omega) v.isLt.le + hblen b'.val.1 b'.val.2 hbc hb' + have hp := mul_le_mul hau hbv (markedGood_nonneg _) (hA _) + dsimp only [pathVisitProbability] at hp + have hm : 1 ≤ C^2*(b u.val*b v.val) := by + have hh := mul_le_mul (hlower u.val u.isLt.le) (hlower v.val v.isLt.le) + (by norm_num : (0 : ℝ) ≤ 1) (mul_nonneg hC (hb _)) + nlinarith + have hw := mul_le_mul_of_nonneg_left hm (mul_nonneg (hA u.val) (hB v.val)) + have hab0 := mul_nonneg (hA u.val) (hB v.val) + nlinarith + · simp only [hu,hv,and_false,↓reduceIte,mul_zero,le_refl] + · simp only [hu,hv,false_and,↓reduceIte,zero_mul,mul_zero,le_refl] + · simp only [hu,hv,false_and,↓reduceIte,mul_zero,le_refl] + _ = C^2*((1/(N : ℝ))*∑ u : Fin N, if u.val < k then A u.val*(2*b u.val) else 0)* + ((1/(N : ℝ))*∑ v : Fin N, if v.val < k then B v.val*(2*b v.val) else 0) := by + simp only [← Finset.mul_sum,← Finset.sum_mul] + ring + _ = _ := by + rw [discrete_ordered_step N k hkN b as.length,discrete_ordered_step N k hkN b bs.length] + +end RootForkVisitation +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPairVisitProbability2.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPairVisitProbability2.lean new file mode 100644 index 0000000000000000000000000000000000000000..c07a92943adbcf8cb91e1aed8e69060edb357bd8 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPairVisitProbability2.lean @@ -0,0 +1,116 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Coupling.OrderedWeightMono +import OAI.Combinatorics.TriangleRemoval.Probability.RootPairVisitProbability + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave +section RootSpineVisitation +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem rootPairVisitProbability_spine (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 0 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (spine : List (ι × τ)) (a b' : ι × τ) (hab : a ≠ b') (as bs : List (ι × τ)) + (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) + (focus : Finset ι) (parent : Option τ) + (ha : LegalQueryPath H focus parent (spine ++ a :: as)) + (hb' : LegalQueryPath H focus parent (spine ++ b' :: bs)) + (halen : spine.length + (as.length+1) ≤ d) (hblen : spine.length + (bs.length+1) ≤ d) : + pairVisitProbability H N d k focus parent + (spine ++ a :: as) (spine ++ b' :: bs) ≤ + C^2 * orderedWeight (fun t => (2/(N : ℝ))*b t) spine.length k * + orderedWeight (fun t => (2/(N : ℝ))*b t) (as.length+1) k * + orderedWeight (fun t => (2/(N : ℝ))*b t) (bs.length+1) k := by + have hw : ∀ t, 0 ≤ (2/(N : ℝ))*b t := fun t => mul_nonneg (by positivity) (hb t) + cases spine with + | nil => + cases d with + | zero => simp only [List.length_nil] at halen; omega + | succ d => + obtain ⟨ha,hat⟩ := ha + obtain ⟨hb',hbt⟩ := hb' + let aa : gridCandidates H focus parent := ⟨a,ha⟩ + let bb : gridCandidates H focus parent := ⟨b',hb'⟩ + have hne : aa ≠ bb := fun h => hab (congrArg Subtype.val h) + simpa only [List.nil_append,List.length_nil,orderedWeight,mul_one] using + rootPairVisitProbability_fork H N b hb hq C hC hlower d k hkd hkN focus parent aa bb hne as bs + hat hbt (by simp only [List.length_nil] at halen; omega) + (by simp only [List.length_nil] at hblen; omega) + | cons z zs => + cases d with + | zero => simp only [List.length_cons] at halen; omega + | succ d => + obtain ⟨hz,haz⟩ := ha + obtain ⟨_,hbz⟩ := hb' + let zz : gridCandidates H focus parent := ⟨z,hz⟩ + have hzc := (Finset.mem_filter.mp hz).2.1 + have hs := markedQuery_single_path H N + (pairRequired (z :: (zs ++ a :: as)) (z :: (zs ++ b' :: bs))) d k hkd hkN [] + focus parent zz (pair_common_required_candidates H _ _ zz _ _) (fun _ => 1) + (fun t ht => hq.1 t (by omega)) + (fun t _ => (gridAnswerProbability_mem_unit H N N t focus parent).2.trans (by norm_num)) + let A := orderedWeight (fun t => (2/(N : ℝ))*b t) (as.length+1) k + let B := orderedWeight (fun t => (2/(N : ℝ))*b t) (bs.length+1) k + have hA : 0 ≤ A := orderedWeight_nonneg hw _ _ + have hB : 0 ≤ B := orderedWeight_nonneg hw _ _ + calc + _ ≤ (1/(N : ℝ))*∑ u : Fin N, if u.val < k then + markedGood (markedChildKernel H N + (pairRequired (z :: (zs ++ a :: as)) (z :: (zs ++ b' :: bs))) d [] + focus parent zz u)*(2*1) else 0 := hs + _ ≤ (1/(N : ℝ))*∑ u : Fin N, if u.val < k then + (C^2*orderedWeight (fun t => (2/(N : ℝ))*b t) zs.length u.val*A*B)*(2*b u.val) + else 0 := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro u _ + by_cases hu : u.val < k + · simp only [hu,↓reduceIte] + rw [marked_pair_common_child H N d _ _ zz _ _ u] + have hi := pairVisitProbability_spine H N b hb hq C hC hlower zs a b' hab as bs + d u.val (by omega) u.isLt.le z.1 z.2 hzc haz hbz + (by simp only [List.length_cons] at halen; omega) + (by simp only [List.length_cons] at hblen; omega) + have hj : pairVisitProbability H N d u.val ((H z.2).erase z.1) (some z.2) + (zs ++ a :: as) (zs ++ b' :: bs) ≤ + C*orderedWeight (fun t => (2/(N : ℝ))*b t) zs.length u.val*A*B := by + apply hi.trans + apply mul_le_mul + · apply mul_le_mul_of_nonneg_left + · exact orderedWeight_mono hw _ hu.le + · exact mul_nonneg hC (orderedWeight_nonneg hw _ _) + · exact orderedWeight_mono hw _ hu.le + · exact orderedWeight_nonneg hw _ _ + · exact mul_nonneg (mul_nonneg hC (orderedWeight_nonneg hw _ _)) hA + have hz0 := orderedWeight_nonneg hw zs.length u.val + have hcharge := mul_le_mul_of_nonneg_left (hlower u.val u.isLt.le) + (mul_nonneg (mul_nonneg (mul_nonneg hC hz0) hA) hB) + dsimp only [pairVisitProbability] at hj + nlinarith + · simp only [hu,↓reduceIte,le_refl] + _ = C^2*((1/(N : ℝ))*∑ u : Fin N, if u.val < k then + orderedWeight (fun t => (2/(N : ℝ))*b t) zs.length u.val*(2*b u.val) else 0)*A*B := by + simp only [Finset.mul_sum,Finset.sum_mul] + apply Finset.sum_congr rfl + intro u _ + by_cases hu : u.val < k <;> simp only [hu,↓reduceIte] <;> ring + _ = _ := by + rw [discrete_ordered_step N k hkN b zs.length] + rfl + +end RootSpineVisitation +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPathVisitProbability.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPathVisitProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f1e30fef6708a6f125176a551c0f637d51edc76 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/RootPathVisitProbability.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.PathVisitProbability +import OAI.Combinatorics.TriangleRemoval.Process.PairRequired + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave +section RootPathVisitation +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem rootPathVisitProbability_ordered (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 1 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (path : List (ι × τ)) (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) + (hlen : path.length ≤ d) (focus : Finset ι) (parent : Option τ) + (hpath : LegalQueryPath H focus parent path) : + pathVisitProbability H N d k focus parent path ≤ + C*orderedWeight (fun t => (2/(N : ℝ))*b t) path.length k := by + cases path with + | nil => + simpa only [List.length_nil,orderedWeight,mul_one,pathVisitProbability] using + (markedGood_le_one (ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N (pathRequired []) d k [] focus parent))).trans hC + | cons a as => + cases d with + | zero => simp only [List.length_cons] at hlen; omega + | succ d => + obtain ⟨ha,htail⟩ := hpath + let aa : gridCandidates H focus parent := ⟨a,ha⟩ + have haT : a.1 ∈ H a.2 := (Finset.mem_filter.mp ha).2.1 + have hstep := markedQuery_single_path H N (pathRequired (a :: as)) d k hkd hkN [] + focus parent aa (path_required_candidates H _ _ aa as) (fun _ => 1) + (fun t ht => hq.1 t (by omega)) + (fun t _ => (gridAnswerProbability_mem_unit H N N t focus parent).2.trans (by norm_num)) + change pathVisitProbability H N (d+1) k focus parent (a :: as) ≤ _ at hstep + calc + _ ≤ (1/(N : ℝ))*∑ u : Fin N, if u.val < k then + markedGood (markedChildKernel H N (pathRequired (a :: as)) d [] + focus parent aa u)*(2*1) else 0 := hstep + _ ≤ C*((1/(N : ℝ))*∑ u : Fin N, if u.val < k then + orderedWeight (fun t => (2/(N : ℝ))*b t) as.length u.val*(2*b u.val) + else 0) := by + rw [mul_left_comm C (1/(N : ℝ))] + apply mul_le_mul_of_nonneg_left _ (by positivity) + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro u _ + by_cases hu : u.val < k + · simp only [hu,↓reduceIte] + rw [marked_path_child H N d focus parent aa as u] + have hi := pathVisitProbability_ordered H N b hb hq as d u.val (by omega) + u.isLt.le (by simp only [List.length_cons] at hlen; omega) a.1 a.2 haT htail + have ho := orderedWeight_nonneg (fun t => mul_nonneg (by positivity : (0 : ℝ) ≤ 2/(N : ℝ)) (hb t)) as.length u.val + have hl := hlower u.val u.isLt.le + change pathVisitProbability H N d u.val ((H a.2).erase a.1) (some a.2) as * (2*1) ≤ _ + nlinarith [mul_nonneg ho (sub_nonneg.mpr hl)] + · simp only [hu,↓reduceIte,mul_zero,le_refl] + _ = _ := by + rw [discrete_ordered_step N k hkN b as.length] + rfl + +theorem actualRootPathVisitProbability_factorial (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 1 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (path : List (ι × τ)) (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) + (hlen : path.length ≤ d) (focus : Finset ι) (parent : Option τ) + (hpath : LegalQueryPath H focus parent path) : + actualPathVisitProbability H N d k focus parent path ≤ + C*(prefixWeight (fun t => (2/(N : ℝ))*b t) k ^ path.length / + (path.length.factorial : ℝ)) := by + apply (actualPathVisitProbability_le_marked H N d k focus parent path).trans + apply (rootPathVisitProbability_ordered H N b hb hq C hC hlower path d k hkd hkN hlen + focus parent hpath).trans + exact mul_le_mul_of_nonneg_left + (orderedWeight_le (fun t => mul_nonneg (by positivity) (hb t)) _ _) (by linarith) + +end RootPathVisitation +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/TriangleSafeTemplateFreedman.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/TriangleSafeTemplateFreedman.lean new file mode 100644 index 0000000000000000000000000000000000000000..dfff5be02f1128770dc949553f6a75f9f40ee949 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/TriangleSafeTemplateFreedman.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching +import OAI.Combinatorics.TriangleRemoval.Process.CopyLoadSafe +import OAI.Combinatorics.TriangleRemoval.Probability.PmfMeanNeg + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem triangle_safe_template_freedman_two_sided {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L : ℝ) (hL : 0 < L) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ j ≤ T, + r ≤ |historyAdditive (safeCopyIncrement required L) T j ω| ∧ + historyCounter (safeCopyVarianceRate required L) T j ω ≤ V then 1 else 0) ≤ + 2*(T+1 : ℝ)*Real.exp (-r^2/(4*(V+(3*L)*r))) := by + classical + apply history_additive_freedman_two_sided (PMF.pure G) (fun _ => step) + (safeCopyIncrement required L) (safeCopyVarianceRate required L) T (3*L) (by positivity) + · intro j _ H _ J hJ + by_cases hs : copyLoadSafe required L H + · simp only [safeCopyIncrement,ite_eq_left hs] + exact pmf_centered_of_loss_range (step H) (copyCount required) (copyCount required H) + (3*L) (fun A hA => copyCount_step_loss_range required H A L hL.le hs hA) J hJ + · simp only [safeCopyIncrement,ite_eq_right hs,abs_zero] + positivity + · intro j _ H _ + change pmfMean (step H) (fun J => safeCopyIncrement required L j H J) = 0 + by_cases hs : copyLoadSafe required L H + · simp only [safeCopyIncrement,ite_eq_left hs] + rw [pmfMean_sub,pmfMean_const,sub_self] + · simp only [safeCopyIncrement,ite_eq_right hs,pmfMean_const] + · intro j _ H _ + by_cases hs : copyLoadSafe required L H + · simp only [safeCopyIncrement,safeCopyVarianceRate,ite_eq_left hs] + exact pmf_variance_of_loss_range (step H) (copyCount required) (copyCount required H) + (3*L) (fun A hA => copyCount_step_loss_range required H A L hL.le hs hA) + · simp only [safeCopyIncrement,safeCopyVarianceRate,ite_eq_right hs,zero_pow (by decide : 2 ≠ 0), + pmfMean_const,le_refl] + · exact hr + · exact hV + +open Classical in + +theorem triangle_template_before_load_exit_two_sided {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L : ℝ) (hL : 0 < L) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ j ≤ T, pastCopyLoadsSafe required L T j ω ∧ + r ≤ |historyNoise (fun _ => step) (fun _ => copyCount required) T j ω| ∧ + historyCounter (copyVarianceRate required L) T j ω ≤ V then 1 else 0) ≤ + 2*(T+1 : ℝ)*Real.exp (-r^2/(4*(V+(3*L)*r))) := by + apply le_trans _ (triangle_safe_template_freedman_two_sided required G T L hL r V hr hV) + apply pmfMean_mono + intro ω _ + by_cases h : ∃ j ≤ T, pastCopyLoadsSafe required L T j ω ∧ + r ≤ |historyNoise (fun _ => step) (fun _ => copyCount required) T j ω| ∧ + historyCounter (copyVarianceRate required L) T j ω ≤ V + · obtain ⟨j,hj,hs,hn,hc⟩ := h + have h' : ∃ j ≤ T, r ≤ |historyAdditive (safeCopyIncrement required L) T j ω| ∧ + historyCounter (safeCopyVarianceRate required L) T j ω ≤ V := by + refine ⟨j,hj,?_,?_⟩ + · rwa [safeCopyNoise_eq required L T j ω hs] + · rwa [safeCopyCounter_eq required L T j ω hs] + rw [ite_eq_left ⟨j,hj,hs,hn,hc⟩,ite_eq_left h'] + · rw [ite_eq_right h] + split <;> norm_num + +end SharpTerminalLeave + +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/TrueProbabilityMap.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/TrueProbabilityMap.lean new file mode 100644 index 0000000000000000000000000000000000000000..b831c72b75952329245135e7c7bf6c6aab397c87 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/TrueProbabilityMap.lean @@ -0,0 +1,187 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.TreeBind + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave +open scoped BigOperators + +theorem trueProbability_map {A : Type*} [Fintype A] (p : PMF A) (b : A → Bool) : + trueProbability (p.map b) = ∑ x, (p x).toReal * (if b x then 1 else 0) := by + change trueProbability (p.bind (fun x => PMF.pure (b x))) = _ + simp only [trueProbability_bind, trueProbability_pure] + +theorem boolean_coupling_bound {A : Type*} [Fintype A] (p : PMF A) + (b₁ b₂ bad : A → Bool) + (hagrees : ∀ x ∈ p.support, bad x = false → b₁ x = b₂ x) : + |trueProbability (p.map b₁) - trueProbability (p.map b₂)| ≤ + trueProbability (p.map bad) := by + rw [trueProbability_map, trueProbability_map, trueProbability_map, + ← Finset.sum_sub_distrib] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro x _ + by_cases hx : p x = 0 + · simp only [hx, ENNReal.toReal_zero, zero_mul, sub_self, abs_zero, le_refl] + · have hs : x ∈ p.support := hx + have ha := hagrees x hs + rw [← mul_sub, abs_mul, abs_of_nonneg ENNReal.toReal_nonneg] + apply mul_le_mul_of_nonneg_left _ ENNReal.toReal_nonneg + cases h₁ : b₁ x <;> cases h₂ : b₂ x <;> cases hb : bad x <;> + simp_all + +namespace ExposureTree +variable {K V : Type*} [Fintype K] [DecidableEq K] [Fintype V] [DecidableEq V] + +theorem independent_exposure_error (ν : K → PMF V) (P : ExposureTree K V Bool) : + |trueProbability ((productPMF ν).map (fun ω => evaluate ω P)) - + trueProbability (fresh ν P)| ≤ + trueProbability ((freshRecorded ν P ∅).map Prod.snd) := by + have hh := boolean_coupling_bound (jointLaw ν P) Prod.fst (fun x => x.2.1) + (fun x => x.2.2) (fun x hx hb => jointLaw_agrees ν P x hx hb) + have hfst : (jointLaw ν P).map Prod.fst = + (productPMF ν).map (fun ω => evaluate ω P) := jointLaw_fixed ν P + have hsnd : (jointLaw ν P).map (fun x => x.2.1) = fresh ν P := by + change (jointLaw ν P).map (Prod.fst ∘ Prod.snd) = _ + rw [← PMF.map_comp, jointLaw_fresh, freshRecorded_outcome] + have hbad : (jointLaw ν P).map (fun x => x.2.2) = + (freshRecorded ν P ∅).map Prod.snd := by + change (jointLaw ν P).map (Prod.snd ∘ Prod.snd) = _ + rw [← PMF.map_comp, jointLaw_fresh] + simpa only [hfst, hsnd, hbad] using hh + +end ExposureTree + +theorem pmf_map_congr_support {A B : Type*} (p : PMF A) (f g : A → B) + (h : ∀ x ∈ p.support, f x = g x) : p.map f = p.map g := by + unfold PMF.map + apply pmf_bind_congr_on_support + intro x hx + rw [Function.comp_apply, Function.comp_apply, h x hx] + +theorem productPMF_coord {K V : Type*} [Fintype K] [DecidableEq K] + [Fintype V] [DecidableEq V] (ν : K → PMF V) (k : K) : + (productPMF ν).map (fun ω => ω k) = ν k := by + rw [productPMF_split ν k, PMF.map_bind] + have hconst : ∀ v, (productPMF (Function.update ν k (PMF.pure v))).map (fun ω => ω k) = + PMF.pure v := by + intro v + conv_rhs => rw [← PMF.map_const (p := productPMF (Function.update ν k (PMF.pure v)))] + apply pmf_map_congr_support + intro ω hω + have hh := (productPMF_support _ _).mp hω k + simpa only [Function.update_self, PMF.mem_support_pure_iff, Function.const_apply] using hh + simp only [hconst, PMF.bind_pure] + +theorem productPMF_pair {K V : Type*} [Fintype K] [DecidableEq K] + [Fintype V] [DecidableEq V] (ν : K → PMF V) (a b : K) (hab : a ≠ b) : + (productPMF ν).map (fun ω => (ω a, ω b)) = + (ν a).bind (fun v => (ν b).map (fun w => (v, w))) := by + rw [productPMF_split ν a, PMF.map_bind] + congr 1 + funext v + have hm : (productPMF (Function.update ν a (PMF.pure v))).map (fun ω => (ω a, ω b)) = + (productPMF (Function.update ν a (PMF.pure v))).map (fun ω => (v, ω b)) := by + apply pmf_map_congr_support + intro ω hω + have hh := (productPMF_support _ _).mp hω a + have ha : ω a = v := by simpa only [Function.update_self, PMF.mem_support_pure_iff] using hh + rw [ha] + rw [hm] + change (productPMF (Function.update ν a (PMF.pure v))).map + ((fun w => (v, w)) ∘ (fun ω => ω b)) = _ + rw [← PMF.map_comp, productPMF_coord, Function.update_of_ne (Ne.symm hab)] + +theorem boolean_union_bound {A I : Type*} [Fintype A] [Fintype I] + (p : PMF A) (bad : A → Bool) (events : I → A → Bool) + (hcover : ∀ x ∈ p.support, bad x = true → ∃ i, events i x = true) : + trueProbability (p.map bad) ≤ ∑ i, trueProbability (p.map (events i)) := by + classical + simp only [trueProbability_map] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro x _ + rw [← Finset.mul_sum] + by_cases hx : p x = 0 + · simp [hx] + apply mul_le_mul_of_nonneg_left _ ENNReal.toReal_nonneg + by_cases hb : bad x = true + · obtain ⟨i, hi⟩ := hcover x hx hb + simp only [hb, ↓reduceIte] + have him : (if events i x then (1 : ℝ) else 0) = 1 := by simp [hi] + calc + (1 : ℝ) = (if events i x then 1 else 0) := him.symm + _ ≤ ∑ j, (if events j x then (1 : ℝ) else 0) := + Finset.single_le_sum (f := fun j => if events j x then (1 : ℝ) else 0) + (fun j _ => by split <;> positivity) (Finset.mem_univ i) + · simp only [hb, Bool.false_eq_true, ↓reduceIte] + exact Finset.sum_nonneg (fun i _ => by split <;> positivity) + +theorem grid_table_pair_tie {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (a b : K) (hab : a ≠ b) : + trueProbability ((productPMF (gridPriorities (τ := K) N)).map + (fun ω => decide (ω a = ω b))) = 1 / (N : ℝ) := by + have hpair := productPMF_pair (gridPriorities (τ := K) N) a b hab + have hh := congrArg (fun q : PMF (Fin N × Fin N) => + q.map (fun z => decide (z.1 = z.2))) hpair + simp only [PMF.map_comp, PMF.map_bind] at hh + change (productPMF (gridPriorities (τ := K) N)).map (fun ω => decide (ω a = ω b)) = + (gridPriorities N a).bind (fun v => (gridPriorities N b).map (fun w => decide (v = w))) at hh + rw [hh, trueProbability_bind] + simp only [trueProbability_map, gridPriorities, PMF.uniformOfFintype_apply, + ENNReal.toReal_inv, ENNReal.toReal_natCast, Fintype.card_fin, Bool.decide_iff] + simp only [mul_ite, mul_one, mul_zero, Finset.sum_ite_eq, Finset.mem_univ, + ↓reduceIte, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + have hn : (N : ℝ) ≠ 0 := by exact_mod_cast (NeZero.ne N) + field_simp + +theorem grid_table_ties_bound {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] : + trueProbability ((productPMF (gridPriorities (τ := K) N)).map + (fun ω => decide (¬Function.Injective ω))) ≤ + (Fintype.card K : ℝ) ^ 2 / N := by + classical + let p := productPMF (gridPriorities (τ := K) N) + let events : K × K → (K → Fin N) → Bool := + fun ab ω => decide (ab.1 ≠ ab.2 ∧ ω ab.1 = ω ab.2) + have hc : ∀ ω ∈ p.support, decide (¬Function.Injective ω) = true → + ∃ ab, events ab ω = true := by + intro ω _ hω + simp only [Bool.decide_iff, Function.Injective, not_forall] at hω + obtain ⟨a, b, h⟩ := hω + push Not at h + exact ⟨(a, b), by simpa [events] using And.intro h.2 h.1⟩ + have hle := boolean_union_bound p (fun ω => decide (¬Function.Injective ω)) events hc + calc + _ ≤ ∑ ab, trueProbability (p.map (events ab)) := hle + _ ≤ ∑ _ab : K × K, (1 / (N : ℝ)) := by + apply Finset.sum_le_sum + intro ab _ + by_cases hab : ab.1 = ab.2 + · have he : events ab = Function.const (K → Fin N) false := by + funext ω + simp [events, hab] + rw [he, PMF.map_const, trueProbability_pure] + simp only [Bool.false_eq_true, ↓reduceIte] + positivity + · have he : events ab = fun ω => decide (ω ab.1 = ω ab.2) := by + funext ω + simp [events, hab] + rw [he] + exact le_of_eq (grid_table_pair_tie N ab.1 ab.2 hab) + _ = _ := by simp [Fintype.card_prod, pow_two, Nat.cast_mul, div_eq_mul_inv] + +end SharpTerminalLeave + +open scoped BigOperators ENNReal Classical + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/UniformDistinctRootSet.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/UniformDistinctRootSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..dcddb5898c7345ba9356302a71e13aa841914d79 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/UniformDistinctRootSet.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift +import OAI.Combinatorics.TriangleRemoval.Coupling.UniformRootAtom + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +section RootAverage +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] + +lemma uniform_distinct_root_set_probability_le (G : Finset α) (hne : G.Nonempty) + (E : Finset α) : + pmfMean (PMF.uniformOfFinset G hne) (fun x => + pmfMean (PMF.uniformOfFinset G hne) (fun y => + if x ≠ y ∧ ({x,y} : Finset α) = E then 1 else 0)) ≤ + 2/(G.card : ℝ)^2 := by + by_cases hE : E.card = 2 + · apply le_trans _ (uniform_root_set_probability_le G hne E hE) + apply pmfMean_mono + intro x _ + apply pmfMean_mono + intro y _ + by_cases h : x ≠ y ∧ ({x,y} : Finset α) = E + · simp [h] + · simp only [h,ite_false] + split_ifs <;> norm_num + · have hz (x y : α) : ¬ (x ≠ y ∧ ({x,y} : Finset α) = E) := by + rintro ⟨hxy,h⟩ + apply hE + rw [← h,Finset.card_pair hxy] + simp only [hz,ite_false,pmfMean_const] + positivity + +theorem uniform_two_root_weighted_sum (G : Finset α) (hne : G.Nonempty) + (roots : ι → Finset α) (w : ι → ℝ) (hw : ∀ i, 0 ≤ w i) : + pmfMean (PMF.uniformOfFinset G hne) (fun x => + pmfMean (PMF.uniformOfFinset G hne) (fun y => + ∑ i, if x ≠ y ∧ roots i = ({x,y} : Finset α) then w i else 0)) ≤ + (2/(G.card : ℝ)^2) * ∑ i, w i := by + let p := PMF.uniformOfFinset G hne + have hpt (x y : α) (i : ι) : + (if x ≠ y ∧ roots i = ({x,y} : Finset α) then w i else 0) = + (if x ≠ y ∧ ({x,y} : Finset α) = roots i then 1 else 0)*w i := by + simp only [eq_comm (a := roots i)] + split_ifs <;> simp + simp_rw [hpt,pmfMean_sum,pmfMean_mul_const] + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + exact mul_le_mul_of_nonneg_right (uniform_distinct_root_set_probability_le G hne (roots i)) (hw i) + +theorem uniform_one_root_weighted_sum (G : Finset α) (hne : G.Nonempty) + (root : ι → α) (w : ι → ℝ) (hw : ∀ i, 0 ≤ w i) : + pmfMean (PMF.uniformOfFinset G hne) (fun x => + ∑ i, if root i = x then w i else 0) ≤ + (1/(G.card : ℝ)) * ∑ i, w i := by + have hpt (x : α) (i : ι) : (if root i = x then w i else 0) = + (if x = root i then 1 else 0)*w i := by + simp only [eq_comm (a := root i)] + split_ifs <;> simp + simp_rw [hpt,pmfMean_sum,pmfMean_mul_const,uniform_root_atom] + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + apply mul_le_mul_of_nonneg_right _ (hw i) + split_ifs <;> first | rfl | positivity + +end RootAverage +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Probability/UniformSingletonRootSet.lean b/lean/OAI/Combinatorics/TriangleRemoval/Probability/UniformSingletonRootSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..557cb9deed284e4cd51f3b8849b8653f70a15c27 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Probability/UniformSingletonRootSet.lean @@ -0,0 +1,58 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift +import OAI.Combinatorics.TriangleRemoval.Coupling.UniformRootAtom + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +section +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] + +lemma uniform_singleton_root_set_probability_le (G : Finset α) (hne : G.Nonempty) + (S : Finset α) : + pmfMean (PMF.uniformOfFinset G hne) (fun e => if S = {e} then 1 else 0) ≤ + 1/(G.card : ℝ) := by + classical + by_cases hs : S.card = 1 + · obtain ⟨a, rfl⟩ := Finset.card_eq_one.mp hs + have he : (fun e : α => if ({a} : Finset α) = {e} then (1 : ℝ) else 0) = + (fun e => if e = a then 1 else 0) := by + funext e + simp only [Finset.singleton_inj,eq_comm] + rw [he,uniform_root_atom] + split_ifs <;> first | rfl | positivity + · have he (e : α) : S ≠ {e} := by + rintro rfl + simp at hs + simp only [he,ite_false,pmfMean_const] + positivity + +theorem uniform_singleton_root_weighted_sum (G : Finset α) (hne : G.Nonempty) + (roots : ι → Finset α) (w : ι → ℝ) (hw : ∀ i, 0 ≤ w i) : + pmfMean (PMF.uniformOfFinset G hne) (fun x => + ∑ i, if roots i = {x} then w i else 0) ≤ + (1/(G.card : ℝ)) * ∑ i, w i := by + have hpt (x : α) (i : ι) : (if roots i = {x} then w i else 0) = + (if roots i = {x} then 1 else 0)*w i := by + split_ifs <;> simp + simp_rw [hpt,pmfMean_sum,pmfMean_mul_const] + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + exact mul_le_mul_of_nonneg_right (uniform_singleton_root_set_probability_le G hne (roots i)) (hw i) + +end +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ActiveHypergraph.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ActiveHypergraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..83f7ed86c50af9be1893eb7f695ed6bce40e08d1 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ActiveHypergraph.lean @@ -0,0 +1,46 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TerminalLaw + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +def activeHypergraph {n : ℕ} (G : Graph n) (T : ↥(triangles G)) : Finset ↥G := + Finset.univ.filter (fun e => e.val ∈ T.val.powersetCard 2) + +def edgeEmbedding {n : ℕ} (G : Graph n) : ↥G ↪ Finset (Fin n) := + ⟨Subtype.val, Subtype.val_injective⟩ + +def triangleEmbedding {n : ℕ} (G : Graph n) : ↥(triangles G) ↪ Finset (Fin n) := + ⟨Subtype.val, Subtype.val_injective⟩ + +@[simp] theorem activeHypergraph_mem {n : ℕ} (G : Graph n) + (T : ↥(triangles G)) (e : ↥G) : e ∈ activeHypergraph G T ↔ e.val ∈ T.val.powersetCard 2 := by + simp only [activeHypergraph, Finset.mem_filter, Finset.mem_univ, true_and] + +theorem activeHypergraph_map {n : ℕ} (G : Graph n) (T : ↥(triangles G)) : + (activeHypergraph G T).map (edgeEmbedding G) = T.val.powersetCard 2 := by + ext e + simp only [Finset.mem_map, activeHypergraph_mem, edgeEmbedding, Function.Embedding.coeFn_mk] + constructor + · rintro ⟨f, hf, rfl⟩ + exact hf + · intro he + exact ⟨⟨e, (mem_triangles.mp T.property).2 he⟩, he, rfl⟩ + +@[simp] theorem activeHypergraph_card {n : ℕ} (G : Graph n) (T : ↥(triangles G)) : + (activeHypergraph G T).card = 3 := by + have hh := congrArg Finset.card (activeHypergraph_map G T) + simpa only [Finset.card_map, triangle_edge_card T.property] using hh + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ActivePairMembership.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ActivePairMembership.lean new file mode 100644 index 0000000000000000000000000000000000000000..09c124bea4aee5e660e2f652ebdc380d336ac122 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ActivePairMembership.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.GraphCardSqrt +import OAI.Combinatorics.TriangleRemoval.Process.EdgePairNe +import OAI.Combinatorics.TriangleRemoval.Stability.CavityGenerator +import OAI.Combinatorics.TriangleRemoval.Spectral.MatrixInfinityAlgHom +import OAI.Combinatorics.TriangleRemoval.Process.ActiveHypergraph + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma active_pair_membership {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + (e f : G) (T : triangles G) : + e ∈ activeHypergraph G T ∧ f ∈ (activeHypergraph G T).erase e ↔ + e ≠ f ∧ T.val = e.val ∪ f.val := by + classical + have he := mem_completeGraph.mp (hG e.property) + have hf := mem_completeGraph.mp (hG f.property) + have hT := (mem_triangles.mp T.property).1 + simp only [activeHypergraph_mem,Finset.mem_erase,Finset.mem_powersetCard] + constructor + · rintro ⟨⟨het,_⟩,hne,hft,_⟩ + have hne' : e.val ≠ f.val := fun h => hne (Subtype.ext h.symm) + have h3 := three_le_card_union he hf hne' + exact ⟨Ne.symm hne,(Finset.eq_of_subset_of_card_le + (Finset.union_subset het hft) (by omega)).symm⟩ + · rintro ⟨hne,hEq⟩ + exact ⟨⟨hEq ▸ Finset.subset_union_left,he⟩,Ne.symm hne, + hEq ▸ Finset.subset_union_right,hf⟩ + +lemma active_pair_sum {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + (e f : G) (x : ℝ) : + (∑ T : triangles G, if e ∈ activeHypergraph G T ∧ + f ∈ (activeHypergraph G T).erase e then x else 0) = + if e ≠ f ∧ e.val ∪ f.val ∈ triangles G then x else 0 := by + classical + simp only [active_pair_membership hG] + by_cases hh : e ≠ f ∧ e.val ∪ f.val ∈ triangles G + · rw [ite_eq_left hh] + let T : triangles G := ⟨e.val ∪ f.val,hh.2⟩ + have hs := Finset.sum_eq_single T (s := Finset.univ) + (f := fun U : triangles G => if e ≠ f ∧ U.val = e.val ∪ f.val then x else 0) + (fun U _ hne => ite_eq_right (fun hu => hne (Subtype.ext hu.2))) + (by simp) + exact hs.trans (ite_eq_left ⟨hh.1,rfl⟩) + · rw [ite_eq_right hh] + apply Finset.sum_eq_zero + intro T _ + apply ite_eq_right + rintro ⟨hne,hT⟩ + exact hh ⟨hne,hT ▸ T.property⟩ + +lemma sum_finset_as_univ {I : Type*} [Fintype I] [DecidableEq I] (S : Finset I) (z : I → ℝ) : + (∑ i ∈ S, z i) = ∑ i, if i ∈ S then z i else 0 := by + classical + rw [← Finset.sum_filter] + congr 1 + ext i; simp + +theorem active_cavityGenerator {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (D : ℝ) : + cavityGenerator (activeHypergraph G) D = + matrixInfinityAlgHom (D⁻¹ • globalLinkAdjacency G hG) := by + classical + apply ContinuousLinearMap.ext + intro z + funext e + rw [cavityGenerator_apply,matrixInfinityAlgHom_apply] + simp only [Matrix.smul_apply,smul_eq_mul,one_div,mul_assoc,← Finset.mul_sum] + congr 1 + calc + _ = ∑ T : triangles G, ∑ f : G, if e ∈ activeHypergraph G T ∧ + f ∈ (activeHypergraph G T).erase e then z f else 0 := by + simp only [messageCandidates,ne_eq,reduceCtorEq,not_false_eq_true,and_true, + Finset.sum_filter] + apply Finset.sum_congr rfl + intro T _ + rw [sum_finset_as_univ] + by_cases he : e ∈ activeHypergraph G T + · simp only [he,ite_true,true_and] + · simp only [he,ite_false,false_and,Finset.sum_const_zero] + _ = ∑ f : G, globalLinkAdjacency G hG e f * z f := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro f _ + rw [active_pair_sum hG,globalLinkAdjacency_entry] + split_ifs <;> simp + +lemma active_messageCandidates_card {n : ℕ} (G : Graph n) (e : G) : + (messageCandidates (activeHypergraph G) e none).card = triangleDegree G e.val := by + classical + have hm : (messageCandidates (activeHypergraph G) e none).map (triangleEmbedding G) = + incidentTriangles G e.val := by + ext T + simp only [Finset.mem_map,messageCandidates,Finset.mem_filter,Finset.mem_univ, + true_and,activeHypergraph_mem,ne_eq,reduceCtorEq,not_false_eq_true,and_true, + triangleEmbedding,Function.Embedding.coeFn_mk,incidentTriangles] + constructor + · rintro ⟨U,hu,rfl⟩ + exact ⟨U.property,hu⟩ + · rintro ⟨hT,he⟩ + exact ⟨⟨T,hT⟩,he,rfl⟩ + have hh := congrArg Finset.card hm + simpa only [Finset.card_map,triangleDegree] using hh + +theorem goodPrefix_cavity_semigroup {c : ℝ} (hc : 0 < c) : + ∃ C₁ : ℝ, 0 < C₁ ∧ ∃ J : ℕ, ∀ᶠ n : ℕ in Filter.atTop, + ∀ (C : ℝ) (G : Graph n) (_h : GoodPrefixGraph n c C G), + ∀ s ∈ Set.Icc (0 : ℝ) (Real.log n), + ‖NormedSpace.exp ((-s) • cavityGenerator (activeHypergraph G) (prefixD n))‖ ≤ + C₁*(1+Real.log n)^J := by + obtain ⟨C₁,hC,J,hb⟩ := goodPrefix_uniform_semigroup hc + refine ⟨C₁,hC,J,hb.mono ?_⟩ + intro n hn C G h s hs + rw [active_cavityGenerator G h.1,matrixInfinityAlgHom_exp_norm] + exact hn C G h s hs +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/Attachment.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/Attachment.lean new file mode 100644 index 0000000000000000000000000000000000000000..599ef99bc673a2c43c2205ea0d4f7d4d3e0f0e1c --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/Attachment.lean @@ -0,0 +1,114 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Process.RootSet + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma lookupGraph_triangle {n : ℕ} {G : Graph n} {T : Finset (Fin n)} + (hT : T ∈ triangles G) : BirthGraph.IsTriangle (lookupGraph G) T := by + have ht := mem_triangles.mp hT + refine ⟨ht.1,?_⟩ + intro x hx y hy hne + refine ⟨hne,ht.2 ?_⟩ + exact Finset.mem_powersetCard.mpr ⟨by + simpa only [Finset.insert_subset_iff,Finset.singleton_subset_iff] using And.intro hx hy, + Finset.card_pair hne⟩ + +namespace RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) + +noncomputable def attachment (v : Fin F.vertexCount) : Finset (Fin n) := + if hv : F.rootCount ≤ v.val then + (F.incoming (F.callIndex v hv) (F.callIndex_nonroot v hv)).1 else ∅ + +noncomputable def birthParent (v : Fin F.vertexCount) : Option (Fin F.vertexCount) := + if hv : F.rootCount ≤ v.val then + let i := F.callIndex v hv + let hi := F.callIndex_nonroot v hv + if hp : F.parent i hi ≠ F.root then some (F.birthIndex (F.parent i hi) hp) else none + else none + +lemma vertexLabel_nonroot (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + F.vertexLabel v = F.newVertex (F.callIndex v hv) (F.callIndex_nonroot v hv) := by + rw [vertexLabel,dite_eq_right (Nat.not_lt.mpr hv)] + +lemma attachment_nonroot (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + F.attachment v = (F.incoming (F.callIndex v hv) (F.callIndex_nonroot v hv)).1 := dite_eq_left hv + +lemma attachment_birth (i : Fin F.size) (hi : i ≠ F.root) : + F.attachment (F.birthIndex i hi) = (F.incoming i hi).1 := by + rw [F.attachment_nonroot _ (F.birthIndex_nonroot i hi)] + simp only [F.callIndex_birthIndex] + +lemma birthParent_nonroot (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + F.birthParent v = + if hp : F.parent (F.callIndex v hv) (F.callIndex_nonroot v hv) ≠ F.root then + some (F.birthIndex _ hp) else none := dite_eq_left hv + +lemma birthParent_some (v p : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) + (hp : F.birthParent v = some p) : + ∃ h : F.parent (F.callIndex v hv) (F.callIndex_nonroot v hv) ≠ F.root, + p = F.birthIndex _ h := by + rw [F.birthParent_nonroot v hv] at hp + split_ifs at hp with hh + exact ⟨hh,(Option.some.inj hp).symm⟩ + +lemma birthParent_none (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) + (hp : F.birthParent v = none) : + F.parent (F.callIndex v hv) (F.callIndex_nonroot v hv) = F.root := by + rw [F.birthParent_nonroot v hv] at hp + split_ifs at hp with hh + exact not_ne_iff.mp hh + +lemma birthParent_eq (v w : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) + (hw : F.rootCount ≤ w.val) (hp : F.birthParent v = F.birthParent w) : + F.parent (F.callIndex v hv) (F.callIndex_nonroot v hv) = + F.parent (F.callIndex w hw) (F.callIndex_nonroot w hw) := by + cases hh : F.birthParent w with + | none => + exact (F.birthParent_none v hv (hp.trans hh)).trans (F.birthParent_none w hw hh).symm + | some p => + obtain ⟨hv',hpv⟩ := F.birthParent_some v p hv (hp.trans hh) + obtain ⟨hw',hpw⟩ := F.birthParent_some w p hw hh + exact F.birthIndex_injective _ _ hv' hw' (hpv.symm.trans hpw) + +lemma newTriangle (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + insert (F.vertexLabel v) (F.attachment v) = + (F.incoming (F.callIndex v hv) (F.callIndex_nonroot v hv)).2 := by + rw [F.vertexLabel_nonroot v hv,F.attachment_nonroot v hv] + exact (F.newVertex_spec _ _).2.symm + +lemma attachments_distinct (v w : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) + (hw : F.rootCount ≤ w.val) (hp : F.birthParent v = F.birthParent w) + (ha : F.attachment v = F.attachment w) (hl : F.vertexLabel v = F.vertexLabel w) : v = w := by + have hpa := F.birthParent_eq v w hv hw hp + have he : F.incoming (F.callIndex v hv) (F.callIndex_nonroot v hv) = + F.incoming (F.callIndex w hw) (F.callIndex_nonroot w hw) := by + apply Prod.ext + · simpa only [F.attachment_nonroot v hv,F.attachment_nonroot w hw] using ha + · rw [← F.newTriangle v hv,← F.newTriangle w hw,ha,hl] + have hi := F.incoming_unique _ _ (F.callIndex_nonroot v hv) (F.callIndex_nonroot w hw) hpa he + have hvw : F.birthIndex (F.callIndex v hv) (F.callIndex_nonroot v hv) = + F.birthIndex (F.callIndex w hw) (F.callIndex_nonroot w hw) := by + congr 1 + simpa only [F.birthIndex_callIndex] using hvw + +end RecordedCallForest +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/AveragedSingletonSurvivalError.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/AveragedSingletonSurvivalError.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad079dccb9fbde89d6336d3acbcb6cfb42717eb3 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/AveragedSingletonSurvivalError.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.EdgeFamilyDegree +import OAI.Combinatorics.TriangleRemoval.Process.CardBiUnion +import OAI.Combinatorics.TriangleRemoval.Probability.AbsPmfMean + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem averaged_singleton_survival_error {n : ℕ} (G : Graph n) (hne : G.Nonempty) + (D ε : ℝ) (hD : 0 < D) + (hrel : ∀ e : G, |cavityLimit (activeHypergraph G) e none 1 / + cavityReference D 1 - 1| ≤ ε) : + |pmfMean (PMF.uniformOfFinset G hne) (fun e => focusSurvival G {e})- + cavityReference D 1| ≤ + pmfMean (PMF.uniformOfFinset G hne) (fun e => + collisionCost (triangleHypergraph G) {e} none)+ε*cavityReference D 1 := by + let P := PMF.uniformOfFinset G hne + have hh := pmfMean_common_error P (fun e => focusSurvival G {e}) + (fun e => collisionCost (triangleHypergraph G) {e} none+ε*cavityReference D 1) + (cavityReference D 1) (fun e he => singleton_survival_error G D ε hD hrel e + ((PMF.mem_support_uniformOfFinset_iff hne e).mp he)) + simpa only [pmfMean_add,pmfMean_const,P] using hh + +theorem averaged_pair_survival_error {n : ℕ} (G : Graph n) (hne : G.Nonempty) + (hG : G ⊆ completeGraph n) (D ε : ℝ) (hD : 0 < D) (hε : 0 ≤ ε) + (hrel : ∀ e : G, |cavityLimit (activeHypergraph G) e none 1 / + cavityReference D 1 - 1| ≤ ε) : + |pmfMean (PMF.uniformOfFinset G hne) (fun e => + pmfMean (PMF.uniformOfFinset G hne) (fun f => focusSurvival G {e,f}))- + (cavityReference D 1)^2| ≤ + pmfMean (PMF.uniformOfFinset G hne) (fun e => + pmfMean (PMF.uniformOfFinset G hne) (fun f => if Disjoint e f then + collisionCost (triangleHypergraph G) {e,f} none else 0))+ + rootOverlap G hne+(2*ε+ε^2)*(cavityReference D 1)^2 := by + classical + let P := PMF.uniformOfFinset G hne + let A := (2*ε+ε^2)*(cavityReference D 1)^2 + have hA : 0 ≤ A := by dsimp only [A]; positivity + let err := fun e f : Finset (Fin n) => + (if Disjoint e f then collisionCost (triangleHypergraph G) {e,f} none else 0)+ + (if ¬Disjoint e f then 1 else 0)+A + have ht (e f : Finset (Fin n)) (he : e ∈ P.support) (hf : f ∈ P.support) : + |focusSurvival G {e,f}-(cavityReference D 1)^2| ≤ err e f := by + have heG := (PMF.mem_support_uniformOfFinset_iff hne e).mp he + have hfG := (PMF.mem_support_uniformOfFinset_iff hne f).mp hf + by_cases hd : Disjoint e f + · have hh := pair_survival_error G D ε hD hε hrel e f heG hfG + (disjoint_valid_edge_ne (mem_completeGraph.mp (hG heG)) hd) + simpa only [err,hd,not_true_eq_false,ite_true,ite_false,add_zero,A] using hh + · have hsu := focusSurvival_mem_unit G {e,f} + have hr := (cavityReference_pos hD (by norm_num : (0 : ℝ) ≤ 1)).le + have hru := cavityReference_le_one hD (by norm_num : (0 : ℝ) ≤ 1) + have hsq : (cavityReference D 1)^2 ≤ 1 := by nlinarith + have hh : |focusSurvival G {e,f}-(cavityReference D 1)^2| ≤ 1 := by + apply abs_le.mpr + constructor <;> nlinarith [hsu.1,hsu.2,sq_nonneg (cavityReference D 1)] + simpa only [err,hd,not_false_eq_true,ite_true,ite_false,zero_add] using + hh.trans (le_add_of_nonneg_right hA) + have hh := pmfMean_common_error P + (fun e => pmfMean P (fun f => focusSurvival G {e,f})) + (fun e => pmfMean P (err e)) ((cavityReference D 1)^2) + (fun e he => pmfMean_common_error P (fun f => focusSurvival G {e,f}) + (err e) ((cavityReference D 1)^2) (fun f hf => ht e f he hf)) + simpa only [err,pmfMean_add,pmfMean_const,A,P,rootOverlap] using hh + +lemma currentDegree_eq_edgeFamilyDegree {n : ℕ} (G : Graph n) + (hG : G ⊆ completeGraph n) (u : Fin n) : + currentDegree G u = edgeFamilyDegree G u := by + classical + unfold currentDegree edgeFamilyDegree + apply Finset.card_bij (fun v _ => ({u,v} : Finset (Fin n))) + · intro v hv + exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hv).2,by simp⟩ + · intro v _ w _ h + by_cases huv : u = v + · subst v + have hw' : w ∈ ({u,u} : Finset (Fin n)) := by rw [h]; simp + have hwu : w = u := by simpa using hw' + exact hwu.symm + · have hv' : v ∈ ({u,w} : Finset (Fin n)) := by rw [← h]; simp + simp only [Finset.mem_insert,Finset.mem_singleton] at hv' + rcases hv' with h' | h' + · exact False.elim (huv h'.symm) + · exact h' + · intro e he + obtain ⟨heG,hue⟩ := Finset.mem_filter.mp he + obtain ⟨a,b,_,heq⟩ := Finset.card_eq_two.mp (mem_completeGraph.mp (hG heG)) + subst e + simp only [Finset.mem_insert,Finset.mem_singleton] at hue + rcases hue with rfl | rfl + · exact ⟨b,Finset.mem_filter.mpr ⟨Finset.mem_univ _,heG⟩,rfl⟩ + · refine ⟨a,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩,?_⟩ + · simpa only [Finset.pair_comm] using heG + · exact Finset.pair_comm _ _ + +theorem goodPrefix_rootOverlap {c : ℝ} (hc : 0 < c) : + ∀ᶠ n : ℕ in atTop, ∀ (C : ℝ) (G : Graph n), GoodPrefixGraph n c C G → + ∀ hne : G.Nonempty, rootOverlap G hne ≤ 8/(n : ℝ) := by + have hδ : Tendsto (fun n : ℕ => (n : ℝ)^(-c)) atTop (𝓝 0) := + (tendsto_rpow_neg_atTop hc).comp (tendsto_natCast_atTop_atTop (R := ℝ)) + filter_upwards [hδ.eventually_le_const zero_lt_one,prefixDensity_eventual_envelope, + eventually_ge_atTop (1 : ℕ)] with n hδ hp hn + intro C G hG hne + have hn0 : (0 : ℝ) < n := by exact_mod_cast (show 0 < n by omega) + have hp0 : 0 < prefixDensity n := + (Real.rpow_pos_of_pos hn0 _).trans_le hp.1 + have hdeg (v : Fin n) : (edgeFamilyDegree G v : ℝ) ≤ 2*(n : ℝ)*prefixDensity n := by + have hh := (abs_le.mp (hG.2.2.1 v)).2 + have hmul := mul_le_mul_of_nonneg_right hδ (mul_nonneg hn0.le hp0.le) + rw [← currentDegree_eq_edgeFamilyDegree G hG.1 v] + nlinarith + apply (rootOverlap_le_maxDegree G hne + (fun e he => mem_completeGraph.mp (hG.1 he)) (2*(n : ℝ)*prefixDensity n) hdeg).trans_eq + rw [hG.2.1,prefixM] + field_simp [ne_of_gt hn0,ne_of_gt hp0] + ring + +end SharpTerminalLeave + +open Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/AveragingProjectorInftyOne.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/AveragingProjectorInftyOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..e214fbf89f1eb752233438fde99d42acffe88b90 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/AveragingProjectorInftyOne.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.LinkStarMatrix +import OAI.Combinatorics.TriangleRemoval.Spectral.MatrixRowAbsSum + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators NNReal +open Matrix InnerProductSpace +open scoped BigOperators +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix +open scoped BigOperators Topology NNReal Matrix.Norms.Operator +open MeasureTheory + +namespace SharpTerminalLeave +open scoped Matrix.Norms.Operator + +theorem averagingProjector_infty_le_one {I : Type*} [Fintype I] : + ‖(averagingProjector : Matrix I I ℝ)‖ ≤ 1 := by + apply matrix_norm_le_of_row_abs_sum_le _ _ zero_le_one + intro i + have hcard : (0 : ℝ) < Fintype.card I := by + exact_mod_cast Fintype.card_pos_iff.mpr ⟨i⟩ + simp [averagingProjector,abs_of_pos (inv_pos.mpr hcard),ne_of_gt hcard] + +theorem globalStarAverage_infty_le_two {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) : + ‖globalStarAverage G‖ ≤ 2 := by + have h := sum_star_infty_norm_bound (edgeStar G) (fun _ => averagingProjector) + 1 2 (by norm_num) (by norm_num) (fun _ => averagingProjector_infty_le_one) + (fun e => by rw [edgeStar_exact_overlap G hG e]; norm_num) + simpa only [globalStarAverage,mul_one] using h + +theorem goodPrefix_global_infty {n : ℕ} {G : Graph n} {c C : ℝ} + (h : GoodPrefixGraph n c C G) (hD : 1 ≤ prefixD n) (hδ : (n : ℝ)^(-c) ≤ 1) : + ‖(prefixD n)⁻¹ • globalLinkAdjacency G h.1‖ ≤ 4 := by + have hD0 : 0 < prefixD n := lt_of_lt_of_le zero_lt_one hD + have hlocal : ∀ u, ‖(prefixD n)⁻¹ • linkStarMatrix G h.1 u‖ ≤ 2 := by + intro u + change ‖Matrix.reindex (neighborEdgeEquiv G h.1 u) (neighborEdgeEquiv G h.1 u) + ((prefixD n)⁻¹ • (linkSimpleGraph G h.1 u).adjMatrix ℝ)‖ ≤ 2 + apply (infty_reindex_norm_le _ _).trans + apply matrix_norm_le_of_row_abs_sum_le _ _ (by norm_num) + intro v + have hr := (abs_le.mp (goodPrefix_link_rows h u v)).2 + have hdeg : ((Finset.univ.filter ((linkSimpleGraph G h.1 u).Adj v)).card : ℝ) ≤ + 2 * prefixD n := by + nlinarith [mul_le_mul_of_nonneg_right hδ hD0.le] + have heq : ∑ j : neighbors G u, + |((prefixD n)⁻¹ • (linkSimpleGraph G h.1 u).adjMatrix ℝ) v j| = + (prefixD n)⁻¹ * ((Finset.univ.filter ((linkSimpleGraph G h.1 u).Adj v)).card : ℝ) := by + simp only [Matrix.smul_apply,smul_eq_mul,abs_mul,abs_of_pos (inv_pos.mpr hD0)] + rw [← Finset.mul_sum] + congr 1 + simp only [SimpleGraph.adjMatrix_apply] + simp only [apply_ite abs,abs_one,abs_zero,Finset.sum_boole] + rw [heq] + calc + _ ≤ (prefixD n)⁻¹ * (2 * prefixD n) := + mul_le_mul_of_nonneg_left hdeg (inv_nonneg.mpr hD0.le) + _ = 2 := by field_simp + have hsplit : (prefixD n)⁻¹ • globalLinkAdjacency G h.1 = + ∑ u, extendStar (edgeStar G u) ((prefixD n)⁻¹ • linkStarMatrix G h.1 u) := by + simp [globalLinkAdjacency,Finset.smul_sum,extendStar,Matrix.smul_mul,Matrix.mul_smul] + rw [hsplit] + simpa only [show (2 : ℝ)*2 = 4 by norm_num] using + sum_star_infty_norm_bound (edgeStar G) _ 2 2 (by norm_num) (by norm_num) hlocal + (fun e => by rw [edgeStar_exact_overlap G h.1 e]; norm_num) + +theorem goodPrefix_residual_infty {n : ℕ} {G : Graph n} {c C : ℝ} + (h : GoodPrefixGraph n c C G) (hD : 1 ≤ prefixD n) (hδ : (n : ℝ)^(-c) ≤ 1) : + ‖(prefixD n)⁻¹ • globalLinkAdjacency G h.1 - globalStarAverage G‖ ≤ 6 := by + have ha := goodPrefix_global_infty h hD hδ + have hp := globalStarAverage_infty_le_two G h.1 + exact (norm_sub_le _ _).trans (by linarith) + +end SharpTerminalLeave + +end + +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/BackEdgesCardSplit.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/BackEdgesCardSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..79362dd881b47256c1e01ac9b1b5de5a1fb36085 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/BackEdgesCardSplit.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.BornEdges +import OAI.Combinatorics.TriangleRemoval.Process.PlusEdgesSimple +import OAI.Combinatorics.TriangleRemoval.Coupling.OrderEmbRank +import OAI.Combinatorics.TriangleRemoval.Coupling.InitialAssignmentSetBound +import OAI.Combinatorics.TriangleRemoval.Process.SeedEdgeSubsetPath +import OAI.Combinatorics.TriangleRemoval.Process.SuffixProjection + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +namespace BirthGraph +variable {N : ℕ} (B : BirthGraph N) + +lemma backEdges_card_split (R : ℕ) (hR : R ≤ N) + (hborn : ∀ v : Fin N, R ≤ v.val → (B.older v).card = 2) : + (B.backEdges Finset.univ).card = + (B.backEdges (initialVertices N R)).card + 2*(N-R) := by + classical + rw [B.backEdges_card,B.backEdges_card] + have hsum := Finset.sum_filter_add_sum_filter_not (s := (Finset.univ : Finset (Fin N))) + (fun v => v.val < R) (fun v => (B.older v).card) + have hborn' : (∑ v ∈ Finset.univ.filter (fun v : Fin N => ¬v.val < R), (B.older v).card) = + 2*(N-R) := by + have he : (∑ v ∈ Finset.univ.filter (fun v : Fin N => ¬v.val < R), (B.older v).card) = + ∑ _v ∈ Finset.univ.filter (fun v : Fin N => ¬v.val < R), 2 := by + apply Finset.sum_congr rfl + intro v hv + exact hborn v (Nat.le_of_not_gt (Finset.mem_filter.mp hv).2) + rw [he,Finset.sum_const,smul_eq_mul] + have hc := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset (Fin N))) + (fun v => v.val < R) + rw [Fin.card_filter_val_lt,Nat.min_eq_right hR,Finset.card_univ,Fintype.card_fin] at hc + have hf : (Finset.univ.filter (fun v : Fin N => ¬v.val < R)).card = N-R := by omega + rw [hf,Nat.mul_comm] + rw [hborn'] at hsum + exact hsum.symm + +end BirthGraph + +lemma witness_scale_identity (n r s : ℕ) : + (n : ℝ)^(2*r+s) * prefixDensity n^(r+2*s+1) = + (2*prefixM n)^r * prefixD n^s * prefixDensity n := by + unfold prefixM prefixD + have he : 2*((n : ℝ)^2 * prefixDensity n / 2) = (n : ℝ)^2 * prefixDensity n := by ring + rw [he,pow_add,pow_add,pow_add,mul_pow,mul_pow] + rw [pow_mul,pow_mul] + ring + +namespace TriangleGrowth +variable {n N r : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N (2*r)) + +lemma pathPattern_edge_card (a b : Fin N) (hR : 2*r ≤ N) + (hseed : (A.seed.backEdges A.roots).card = r) : + ((A.pathPattern a b).backEdges Finset.univ).card = r+2*(A.pathSuffix a b (2*r)).card := by + rw [(A.pathPattern a b).backEdges_card_split (2*r) + (roots_le_card _ hR (fun x hx => (A.mem_pathUnion a b x).mpr (Or.inl hx))) + (A.pathPattern_nonroot a b)] + rw [A.pathPattern_rootEdges a b hR,A.pathRootEdges_card,hseed,A.path_card_split a b hR] + omega + +theorem actual_short_witness_count {c C : ℝ} (hGood : GoodPrefixGraph n c C G) + (a b : Fin N) (hR : 2*r ≤ N) (hseed : (A.seed.backEdges A.roots).card = r) + (he : A.birthGraph.ExtraEdge (lookupGraph G) A.label a b) + (hcap : (A.pathUnion a b).card ≤ prefixTemplateCap) + (hp : 0 ≤ prefixDensity n) (hp1 : prefixDensity n ≤ 1) (hD : 1 ≤ prefixD n) : + ((graphEmbeddingSet (insert ({A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)} : Finset _) + ((A.pathPattern a b).backEdges Finset.univ)) G).card : ℝ) ≤ + prefixTemplateFactor n C * ((2*prefixM n)^r * + prefixD n^(A.pathSuffix a b (2*r)).card * prefixDensity n) := by + have hex := A.pathPattern_extra he + have h := (A.pathPattern a b).short_witness_count hGood hex.1 hex.2 hcap hp hp1 hD + rw [A.pathPattern_edge_card a b hR hseed] at h + conv at h => rhs; rw [A.path_card_split a b hR,witness_scale_identity] + exact h + +theorem actual_long_witness_count {c C : ℝ} (hGood : GoodPrefixGraph n c C G) + (hsmall : (n : ℝ)^(-c) ≤ 1) (a b : Fin N) (hR : 2*r ≤ N) + (hseed : (A.seed.backEdges A.roots).card = r) + (he : A.birthGraph.ExtraEdge (lookupGraph G) A.label a b) + (k : ℕ) (hrk : 2*r ≤ k) (hk : k < (A.pathUnion a b).card) + (hcap : 3*((A.pathUnion a b).card-k)+1 ≤ prefixTemplateCap) + (hp : 0 ≤ prefixDensity n) (hp1 : prefixDensity n ≤ 1) (hD : 1 ≤ prefixD n) + (hscale : (n : ℝ)^((A.pathUnion a b).card-k) * + prefixDensity n^(2*((A.pathUnion a b).card-k)+1) ≤ 1) : + ((graphEmbeddingSet (insert ({A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)} : Finset _) + ((A.pathPattern a b).backEdges Finset.univ)) G).card : ℝ) ≤ + prefixTemplateFactor n C * ((4*prefixM n)^r * (2*prefixD n)^(k-2*r)) := by + have hex := A.pathPattern_extra he + apply (A.pathPattern a b).long_witness_count_unordered hGood hsmall r k hrk hk.le + · rw [A.pathPattern_rootClosers a b hR,hseed] + · exact A.pathPattern_nonroot a b + · exact hex.1 + · exact hex.2 + · exact A.path_mark_reaches_suffix a b k hrk hk + · exact A.pathPattern_covered a b k hrk hk + · exact hcap + · exact hp + · exact hp1 + · exact hD + · exact hscale + +end TriangleGrowth +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/BornEdges.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/BornEdges.lean new file mode 100644 index 0000000000000000000000000000000000000000..039a0c352f79db0708657c8626f261921b04b061 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/BornEdges.lean @@ -0,0 +1,165 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +open scoped BigOperators + +variable {N : ℕ} (B : BirthGraph N) + +def bornEdges (v : Fin N) : Finset (Finset (Fin N)) := + (B.older v).image (fun u => {u, v}) + +def backEdges (Z : Finset (Fin N)) : Finset (Finset (Fin N)) := + Z.biUnion B.bornEdges + +theorem pair_injective_on_older (v : Fin N) : + Set.InjOn (fun u : Fin N => ({u, v} : Finset (Fin N))) (B.older v) := by + intro a ha b hb hab + have hm : a ∈ ({b, v} : Finset (Fin N)) := by + change ({a, v} : Finset (Fin N)) = {b, v} at hab + rw [← hab] + simp + simp only [Finset.mem_insert, Finset.mem_singleton] at hm + rcases hm with hm | hm + · exact hm + · exact False.elim ((ne_of_lt (B.older_lt v a ha)) hm) + +@[simp] theorem bornEdges_card (v : Fin N) : (B.bornEdges v).card = (B.older v).card := + Finset.card_image_of_injOn (B.pair_injective_on_older v) + +theorem bornEdges_disjoint {v w : Fin N} (hvw : v ≠ w) : + Disjoint (B.bornEdges v) (B.bornEdges w) := by + apply Finset.disjoint_left.mpr + intro e he hf + obtain ⟨a, ha, rfl⟩ := Finset.mem_image.mp he + obtain ⟨b, hb, hbe⟩ := Finset.mem_image.mp hf + have hv : v ∈ ({b, w} : Finset (Fin N)) := hbe.symm ▸ (by simp) + have hw : w ∈ ({a, v} : Finset (Fin N)) := hbe ▸ (by simp) + simp only [Finset.mem_insert, Finset.mem_singleton] at hv hw + have hvb : v = b := hv.resolve_right hvw + have hwa : w = a := hw.resolve_right hvw.symm + have hlt := B.older_lt v a ha + have hlt' := B.older_lt w b hb + subst a b + exact (not_lt_of_gt hlt) hlt' + +theorem backEdges_card (Z : Finset (Fin N)) : + (B.backEdges Z).card = ∑ v ∈ Z, (B.older v).card := by + rw [backEdges, Finset.card_biUnion] + · simp only [bornEdges_card] + · intro a _ b _ hab + exact B.bornEdges_disjoint hab + +theorem backEdges_mem_pair {Z : Finset (Fin N)} {e : Finset (Fin N)} + (he : e ∈ B.backEdges Z) : + ∃ v ∈ Z, ∃ u ∈ B.older v, e = {u, v} := by + obtain ⟨v, hv, he⟩ := Finset.mem_biUnion.mp he + obtain ⟨u, hu, rfl⟩ := Finset.mem_image.mp he + exact ⟨v, hv, u, hu, rfl⟩ + +theorem backEdges_card_le (Z : Finset (Fin N)) : (B.backEdges Z).card ≤ 2 * Z.card := by + rw [backEdges_card] + calc + _ ≤ ∑ _v ∈ Z, 2 := Finset.sum_le_sum (fun v _ => B.older_card v) + _ = _ := by simp [mul_comm] + +theorem backEdges_card_eq (Z : Finset (Fin N)) (h : ∀ v ∈ Z, (B.older v).card = 2) : + (B.backEdges Z).card = 2 * Z.card := by + rw [backEdges_card] + simp only [Finset.sum_congr rfl h, Finset.sum_const, smul_eq_mul, mul_comm] + +def inducedEdges (U : Finset (Fin N)) : Finset (Finset (Fin N)) := + (B.backEdges U).filter (fun e => e ⊆ U) + +theorem inducedEdges_eq (U : Finset (Fin N)) : B.inducedEdges U = + U.biUnion (fun v => ((B.older v) ∩ U).image (fun u => {u, v})) := by + ext e + simp only [inducedEdges, backEdges, bornEdges, Finset.mem_filter, Finset.mem_biUnion, + Finset.mem_image, Finset.mem_inter] + constructor + · rintro ⟨⟨v, hv, u, hu, rfl⟩, hs⟩ + exact ⟨v, hv, u, ⟨hu, hs (by simp)⟩, rfl⟩ + · rintro ⟨v, hv, u, ⟨hu, huU⟩, rfl⟩ + refine ⟨⟨v, hv, u, hu, rfl⟩, ?_⟩ + simp only [Finset.insert_subset_iff, Finset.singleton_subset_iff] + exact ⟨huU, hv⟩ + +theorem inducedEdges_card_le (U : Finset (Fin N)) : + (B.inducedEdges U).card ≤ ∑ v ∈ U, ((B.older v) ∩ U).card := by + rw [inducedEdges_eq] + refine Finset.card_biUnion_le.trans (Finset.sum_le_sum ?_) + intro v _ + exact Finset.card_image_le + +theorem inducedEdges_sparse (U : Finset (Fin N)) (hU : U.Nonempty) : + (B.inducedEdges U).card + 2 ≤ 2 * U.card := by + let v := U.min' hU + have hv : v ∈ U := Finset.min'_mem U hU + have hzero : (B.older v) ∩ U = ∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro u hu + have hu' := Finset.mem_inter.mp hu + exact (not_le_of_gt (B.older_lt v u hu'.1)) (Finset.min'_le U u hu'.2) + have hsum : (∑ x ∈ U, ((B.older x) ∩ U).card) ≤ 2 * (U.card - 1) := by + rw [← Finset.sum_erase_add _ _ hv, hzero, Finset.card_empty, add_zero] + calc + _ ≤ ∑ _x ∈ U.erase v, 2 := by + apply Finset.sum_le_sum + intro x _ + exact (Finset.card_le_card Finset.inter_subset_left).trans (B.older_card x) + _ = _ := by simp [Finset.card_erase_of_mem hv, mul_comm] + have hpos : 1 ≤ U.card := hU.card_pos + have hh := (B.inducedEdges_card_le U).trans hsum + omega + +theorem induced_plus_one_sparse (U : Finset (Fin N)) (a b : Fin N) : + ((insert ({a, b} : Finset (Fin N)) (B.backEdges Finset.univ)).filter + (fun e => e ⊆ U)).card ≤ 2 * U.card := by + by_cases hU : U.Nonempty + · have hs : ((insert ({a, b} : Finset (Fin N)) (B.backEdges Finset.univ)).filter + (fun e => e ⊆ U)) ⊆ insert {a, b} (B.inducedEdges U) := by + intro e he + obtain ⟨he, heU⟩ := Finset.mem_filter.mp he + rcases Finset.mem_insert.mp he with he | he + · exact Finset.mem_insert.mpr (Or.inl he) + · obtain ⟨v, _, u, hu, heu⟩ := B.backEdges_mem_pair he + apply Finset.mem_insert.mpr ∘ Or.inr + apply Finset.mem_filter.mpr + refine ⟨?_, heU⟩ + apply Finset.mem_biUnion.mpr + refine ⟨v, heU (by rw [heu]; simp), ?_⟩ + exact Finset.mem_image.mpr ⟨u, hu, heu.symm⟩ + have hcard := (Finset.card_le_card hs).trans (Finset.card_insert_le _ _) + have hsp := B.inducedEdges_sparse U hU + omega + · have hzero : U = ∅ := Finset.not_nonempty_iff_eq_empty.mp hU + subst U + have hempty : ((insert ({a, b} : Finset (Fin N)) (B.backEdges Finset.univ)).filter + (fun e => e ⊆ ∅)).card = 0 := by + rw [Finset.card_eq_zero] + apply Finset.eq_empty_iff_forall_notMem.mpr + intro e he + obtain ⟨he, hs⟩ := Finset.mem_filter.mp he + rcases Finset.mem_insert.mp he with rfl | he + · exact Finset.notMem_empty a (hs (by simp)) + · obtain ⟨v, _, u, _, heu⟩ := B.backEdges_mem_pair he + exact Finset.notMem_empty v (hs (by rw [heu]; simp)) + rw [hempty] + exact Nat.zero_le _ + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CardBiUnion.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CardBiUnion.lean new file mode 100644 index 0000000000000000000000000000000000000000..eee67d81cb4f6d4e963a710c5381988a7fbddd81 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CardBiUnion.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.CanonicalCollisionSum +import OAI.Combinatorics.TriangleRemoval.Process.IndexedWitnessCodeCard +import OAI.Combinatorics.TriangleRemoval.Process.WitnessDimensionEquiv +import OAI.Combinatorics.TriangleRemoval.Probability.UniformDistinctRootSet + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma EdgeMatching.card_biUnion {V : Type*} [DecidableEq V] + {E : Finset (Finset V)} (h : EdgeMatching E) : + (E.biUnion id).card = 2*E.card := by + change (E.biUnion (fun e => e)).card = _ + rw [Finset.card_biUnion h.2] + calc + _ = ∑ _e ∈ E, 2 := Finset.sum_congr rfl (fun e he => h.1 e he) + _ = _ := by simp only [Finset.sum_const,smul_eq_mul,Nat.mul_comm] + +lemma disjoint_valid_edge_ne {n : ℕ} {e f : Finset (Fin n)} + (he : e.card = 2) (hd : Disjoint e f) : e ≠ f := by + rintro rfl + have h : e = ∅ := disjoint_self.mp hd + rw [h,Finset.card_empty] at he + omega + +theorem canonical_collision_pair_sum (c₀ C₀ : ℝ) (hc₀ : 0 < c₀) : + ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c₀ C₀ G → + ∀ (e f : Finset (Fin n)), e ∈ G → f ∈ G → Disjoint e f → + ∀ (N : ℕ) [NeZero N] (b : ℕ → ℝ) (_hb : ∀ t, 0 ≤ b t) + (_hq : GridRowQuality (triangleHypergraph G) N b) + (C : ℝ) (_hC : 1 ≤ C) (_hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (_hkd : k ≤ d) (_hkN : k ≤ N), + tracedCollisionProbability (triangleHypergraph G) N d k {e,f} none ≤ + ∑ W : BoundedEmbeddedWitness G 4 d, + if WitnessEmbeddingBound 2 W ∧ embeddedWitnessRoots W = {e,f} then + C^3 * ((3*prefixWeight (fun t => (2/(N : ℝ))*b t) k)^W.1.val.2.val / + (W.1.val.2.val.factorial : ℝ)) else 0 := by + classical + filter_upwards [canonical_collision_sum c₀ C₀ hc₀] with n hn + intro G hGood e f he hf hd N _ b hb hq C hC hlower d k hkd hkN + have he2 := mem_completeGraph.mp (hGood.1 he) + have hf2 := mem_completeGraph.mp (hGood.1 hf) + have hm := EdgeMatching.pair e f he2 hf2 hd + have hef : e ≠ f := disjoint_valid_edge_ne he2 hd + have hcard : ({e,f} : Graph n).card = 2 := Finset.card_pair hef + have hbi : (({e,f} : Graph n).biUnion id).card = 4 := by + rw [hm.card_biUnion,hcard] + have hh := hn G hGood {e,f} none hm (by intro a ha; simp only [Finset.mem_insert,Finset.mem_singleton] at ha; rcases ha with rfl | rfl <;> assumption) + (by rw [hcard]) (triangleHypergraph_separated_disjoint_roots G e f hd) + N b hb hq C hC hlower d k hkd hkN + rw [hbi] at hh + simpa only [hcard] using hh + +lemma witness_total_weight_bound {n R d r : ℕ} (G : Graph n) (hR : R ≤ 4) + (hm : 0 ≤ prefixM n) {C x : ℝ} (hC : 0 ≤ C) (hx : 0 ≤ x) : + (∑ W : BoundedEmbeddedWitness G R d, if WitnessEmbeddingBound r W then + C^3*((3*x)^W.1.val.2.val/(W.1.val.2.val.factorial : ℝ)) else 0) ≤ + (2048*(4*prefixM n)^r*C^3/prefixD n^50)*Real.exp (45*prefixD n*x) := by + have hD : 0 ≤ prefixD n := by unfold prefixD; positivity + apply (boundedEmbeddedWitness_weight_sum G r hR hm + (fun q => C^3*((3*x)^q.val.2.val/(q.val.2.val.factorial : ℝ))) + (fun _ => by positivity)).trans + exact witness_dimensions_weight_sum hR hm hD hC hx + +theorem averaged_disjoint_grid_collision (c₀ C₀ : ℝ) (hc₀ : 0 < c₀) : + ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c₀ C₀ G → + ∀ (hne : G.Nonempty) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (_hb : ∀ t, 0 ≤ b t) (_hq : GridRowQuality (triangleHypergraph G) N b) + (C : ℝ) (_hC : 1 ≤ C) (_hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (_hkd : k ≤ d) (_hkN : k ≤ N), + pmfMean (PMF.uniformOfFinset G hne) (fun e => + pmfMean (PMF.uniformOfFinset G hne) (fun f => if Disjoint e f then + tracedCollisionProbability (triangleHypergraph G) N d k {e,f} none else 0)) ≤ + (65536*C^3/prefixD n^50)* + Real.exp (45*prefixD n*prefixWeight (fun t => (2/(N : ℝ))*b t) k) := by + classical + filter_upwards [canonical_collision_pair_sum c₀ C₀ hc₀] with n hn + intro G hGood hne N _ b hb hq C hC hlower d k hkd hkN + let x := prefixWeight (fun t => (2/(N : ℝ))*b t) k + have hx : 0 ≤ x := by + apply Finset.sum_nonneg + intro t _ + exact mul_nonneg (by positivity) (hb t) + let w (W : BoundedEmbeddedWitness G 4 d) : ℝ := + if WitnessEmbeddingBound 2 W then C^3*((3*x)^W.1.val.2.val/(W.1.val.2.val.factorial : ℝ)) else 0 + have hw (W : BoundedEmbeddedWitness G 4 d) : 0 ≤ w W := by + dsimp only [w] + split_ifs <;> positivity + have hcover : pmfMean (PMF.uniformOfFinset G hne) (fun e => + pmfMean (PMF.uniformOfFinset G hne) (fun f => if Disjoint e f then + tracedCollisionProbability (triangleHypergraph G) N d k {e,f} none else 0)) ≤ + pmfMean (PMF.uniformOfFinset G hne) (fun e => + pmfMean (PMF.uniformOfFinset G hne) (fun f => + ∑ W : BoundedEmbeddedWitness G 4 d, + if e ≠ f ∧ embeddedWitnessRoots W = {e,f} then w W else 0)) := by + apply pmfMean_mono + intro e he + apply pmfMean_mono + intro f hf + have heG := (PMF.mem_support_uniformOfFinset_iff hne e).mp he + have hfG := (PMF.mem_support_uniformOfFinset_iff hne f).mp hf + by_cases hd : Disjoint e f + · rw [ite_eq_left hd] + have hef : e ≠ f := disjoint_valid_edge_ne (mem_completeGraph.mp (hGood.1 heG)) hd + have hh := hn G hGood e f heG hfG hd N b hb hq C hC hlower d k hkd hkN + apply hh.trans_eq + apply Finset.sum_congr rfl + intro W _ + by_cases hW : WitnessEmbeddingBound 2 W <;> + by_cases hroot : embeddedWitnessRoots W = {e,f} <;> + simp [w,x,hef,hW,hroot] + · rw [ite_eq_right hd] + apply Finset.sum_nonneg + intro W _ + split_ifs <;> first | exact hw W | rfl + have hsample := uniform_two_root_weighted_sum G hne embeddedWitnessRoots w hw + have hm : 0 ≤ prefixM n := by rw [← hGood.2.1]; positivity + have hmpos : 0 < prefixM n := by rw [← hGood.2.1]; exact_mod_cast hne.card_pos + have hsum := witness_total_weight_bound (d := d) (r := 2) G (by norm_num : 4 ≤ 4) hm + (show 0 ≤ C by linarith) hx + apply (hcover.trans hsample).trans + change (2/(G.card : ℝ)^2)*(∑ W, w W) ≤ _ + apply (mul_le_mul_of_nonneg_left hsum (by positivity : 0 ≤ 2/(G.card : ℝ)^2)).trans_eq + rw [hGood.2.1] + dsimp only [x] + field_simp [ne_of_gt hmpos] + ring + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CenteredEdgeVectorTriangle.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CenteredEdgeVectorTriangle.lean new file mode 100644 index 0000000000000000000000000000000000000000..13b4bef26b1b3e0e3dcd1e31ab07d7b56fe31394 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CenteredEdgeVectorTriangle.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Stability.MovingResidualForcing +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEdgeResidualBounds + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +lemma centeredEdgeVector_eq_triangle {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (s : ℝ) (e : CompleteEdge n) (he : e.val ∈ G) : + centeredEdgeVector G s e = (triangleDegree G e.val : ℝ)/s-1 := by + exact congrFun (centeredEdgeVector_restrict G hG s) (⟨e.val,he⟩ : G) + +theorem prefix_edge_barrier_improvement : ∀ᶠ n : ℕ in atTop, + ∀ ω : History (Graph n) (prefixTime n), + ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support → + PrefixRootedUpper 8001 n ω → PrefixBalancedNoise 8001 n ω → + PrefixTriangleNoise n ω → PrefixCodegreeNoiseGood n ω → + ∀ j ≤ prefixTime n, + historyAlive (fun i => densityEdgeSafe n (earlyDensity n i) (prefixEdgeRadius n)) (prefixTime n) j ω → + trajectorySeminorm (fun t => activeLinf (graphActive (ω (historyIndex (prefixTime n) t)))) j + (prefixCenteredEdge ω) ≤ prefixEdgeRadius n/2 := by + obtain ⟨γ,hγ,hdec⟩ := prefixSpectralError_power_decay (by norm_num : (0 : ℝ) < 1/80000) + obtain ⟨K,hK0,hbudget⟩ := prefix_edge_stability_budget hγ + filter_upwards [hdec,hbudget,prefix_edge_residual_bounds,prefix_edge_forcing_bound, + prefix_edge_coefficient_bounds,earlyTemplateScale_regular 1 2] with n hdec hbudget hR hM ha hreg + intro ω hω hroot hbalanced htri hnoise j hj hsafe + let active (i : ℕ) := graphActive (ω (historyIndex (prefixTime n) i)) + let a := prefixEdgeRate ω + let R := prefixEdgeResidual ω hω + let M := prefixEdgeForcing ω + let x := prefixCenteredEdge ω + let S := ∑ i ∈ Finset.range j, a i + have hcb := ha ω hω htri j hj hsafe + have hS0 : 0 ≤ S := Finset.sum_nonneg (fun i hi => (hcb.1 i (Finset.mem_range.mp hi)).1) + have hS1 : S ≤ 4*Real.log n := hcb.2 + have hnest : ∀ i < j, active (i+1) ⊆ active i := by + intro i hi + apply graphActive_nested + exact history_graph_nested ω hω (Nat.le_succ i) (by omega) + have hinit : ∀ e ∈ active 0, x 0 e = M 0 e := by + intro e _ + rw [show M 0 = x 0 from prefixEdgeForcing_zero ω] + have hstep : ∀ i < j, ∀ e ∈ active (i+1), x (i+1) e = x i e- + a i*(movingStarLift (fun e : CompleteEdge n => e.val) + (movingStarMean (fun e : CompleteEdge n => e.val) (active i) (x i)) e+R i (x i) e)+ + (M (i+1) e-M i e) := by + intro i hi e he + exact prefix_centered_edge_recurrence ω hω (by omega) (hreg.1 i (by omega)).ne' e he + have hRinf : ∀ i < j, ∀ z, activeLinf (active i) (R i z) ≤ 6*activeLinf (active i) z := by + intro i hi z + exact (hR ω hω hroot hbalanced j hj hsafe i hi z).1 + have hR2 : ∀ i < j, ∀ z, activeL2 (active i) (R i z) ≤ (n : ℝ)^(-γ)*activeL2 (active i) z := by + intro i hi z + exact (hR ω hω hroot hbalanced j hj hsafe i hi z).2.trans + (mul_le_mul_of_nonneg_right hdec (apply_nonneg _ _)) + have hk : ((1+2*S)*S*(n : ℝ)^(-γ))^K*(Fintype.card (CompleteEdge n) : ℝ) ≤ 1/2 := by + have hc : (Fintype.card (CompleteEdge n) : ℝ) ≤ (n : ℝ)^2 := by exact_mod_cast graphActive_card_le (n := n) + exact (mul_le_mul_of_nonneg_left hc (by positivity)).trans (hbudget S hS0 hS1).1 + have hm := movingStar_mixed_stability (fun e : CompleteEdge n => e.val) + (fun e => mem_completeGraph.mp e.property) active a R M x j K hnest + (fun i hi => ⟨(hcb.1 i hi).1,(hcb.1 i hi).2.1⟩) hinit hstep + (by norm_num : (0 : ℝ) ≤ 6) (Real.rpow_nonneg (Nat.cast_nonneg n) (-γ)) hRinf hR2 hk + apply hm.trans + apply le_trans _ (hbudget S hS0 hS1).2 + apply mul_le_mul_of_nonneg_left (hM ω hω htri hnoise j hj hsafe) + have ha0 : ∀ i ∈ Finset.range j, 0 ≤ a i := fun i hi => (hcb.1 i (Finset.mem_range.mp hi)).1 + positivity + +lemma history_mass_of_alive {n : ℕ} (hn : 0 < n) + (hp : 1/(n : ℝ) ≤ prefixDensity n) (hη : prefixEdgeRadius n ≤ 1/2) + (ω : History (Graph n) (prefixTime n)) + (hω : ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support) + (j : ℕ) (hj : j ≤ prefixTime n) + (hsafe : historyAlive (fun i => densityEdgeSafe n (earlyDensity n i) (prefixEdgeRadius n)) (prefixTime n) j ω) : + ((ω (historyIndex (prefixTime n) j)).card : ℝ) = (n : ℝ)^2*earlyDensity n j/2 := by + obtain ⟨hinit,hpath⟩ := historyLaw_path_support (PMF.pure (completeGraph n)) (fun _ => step) + (prefixTime n) (prefixTime n) le_rfl ω hω + cases j with + | zero => + have hi : ω (historyIndex (prefixTime n) 0) = completeGraph n := by simpa using hinit + rw [hi] + exact completeGraph_early_mass hn + | succ i => + have hs := hsafe i (Nat.lt_succ_self i) + have hactive := densityEdgeSafe_triangle_positive hn (early_density_positive hn hp (by omega)) hη hs + have hc := step_card_of_active hactive (hpath i (by omega)) + have hcR : ((ω (historyIndex (prefixTime n) (i+1))).card : ℝ)+3 = (n : ℝ)^2*earlyDensity n i/2 := by + rw [← hs.2.1] + exact_mod_cast hc + rw [earlyDensity_succ n i] at hcR + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have he : (n : ℝ)^2*(earlyDensity n (i+1)+6/(n : ℝ)^2)/2 = + (n : ℝ)^2*earlyDensity n (i+1)/2+3 := by field_simp; ring + rw [he] at hcR + linarith only [hcR] + +theorem prefix_present_edge_closure : ∀ᶠ n : ℕ in atTop, + ∀ ω : History (Graph n) (prefixTime n), + ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support → + PrefixRootedUpper 8001 n ω → PrefixBalancedNoise 8001 n ω → + PrefixTriangleNoise n ω → PrefixCodegreeNoiseGood n ω → + ∀ j ≤ prefixTime n, densityEdgeSafe n (earlyDensity n j) (prefixEdgeRadius n) + (ω (historyIndex (prefixTime n) j)) := by + filter_upwards [prefix_edge_barrier_improvement,triangle_closure_budget, + prefixDensity_eventually_inverse_lower,earlyTemplateScale_regular 1 2, + eventually_ge_atTop (1 : ℕ)] with n hb hη hp hreg hn + intro ω hω hroot hbalanced htri hnoise j + induction j using Nat.strong_induction_on with + | h j ih => + intro hj + have hs : historyAlive (fun i => densityEdgeSafe n (earlyDensity n i) (prefixEdgeRadius n)) (prefixTime n) j ω := by + intro i hi + exact ih i hi (by omega) + have hbound := hb ω hω hroot hbalanced htri hnoise j hj hs + have hG := complete_history_valid ω hω j hj + refine ⟨hG,history_mass_of_alive (by omega) hp hη.2.1 ω hω j hj hs,?_⟩ + intro e he + let E : CompleteEdge n := ⟨e,hG he⟩ + have hEa : E ∈ graphActive (ω (historyIndex (prefixTime n) j)) := (mem_graphActive _ _).mpr he + have hx := (activeLinf_coordinate (graphActive (ω (historyIndex (prefixTime n) j))) + (prefixCenteredEdge ω j) hEa).trans ((trajectorySeminorm_at + (fun t => activeLinf (graphActive (ω (historyIndex (prefixTime n) t)))) j + (prefixCenteredEdge ω) le_rfl).trans hbound) + change |centeredEdgeVector _ _ E| ≤ _ at hx + rw [centeredEdgeVector_eq_triangle _ hG _ E he] at hx + have hpos := hreg.1 j hj + have heq : (triangleDegree (ω (historyIndex (prefixTime n) j)) e : ℝ)/earlyTemplateScale 1 2 n j-1 = + ((triangleDegree (ω (historyIndex (prefixTime n) j)) e : ℝ)-earlyTemplateScale 1 2 n j)/earlyTemplateScale 1 2 n j := by field_simp + change |(triangleDegree (ω (historyIndex (prefixTime n) j)) e : ℝ)/earlyTemplateScale 1 2 n j-1| ≤ _ at hx + rw [heq,abs_div,abs_of_pos hpos] at hx + have hh := (div_le_iff₀ hpos).mp hx + simpa only [earlyTemplateScale,pow_one] using hh.trans (mul_le_mul_of_nonneg_right (by linarith only [hη.1]) hpos.le) + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CenteredNeighborSumBound.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CenteredNeighborSumBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..fcef38061a44a6780172636c2948da18acd5bc2f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CenteredNeighborSumBound.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.HistoryGraphNested + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +lemma centered_neighbor_sum_bound {n : ℕ} {G : Graph n} (_hG : G ⊆ completeGraph n) + (u v : Fin n) {s η : ℝ} (_hη : 0 ≤ η) (_hs : 0 ≤ s) + (hrow : ∀ a b, {a,b} ∈ G → |(currentCodegree G a b : ℝ)-s| ≤ η*s) : + |centeredCodegreeNeighborSum G u v s| ≤ 2*η*s*(currentCodegree G u v : ℝ) := by + unfold centeredCodegreeNeighborSum + calc + _ ≤ ∑ w ∈ commonNeighbors G u v, + |(currentCodegree G u w : ℝ)+currentCodegree G v w-2*s| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _w ∈ commonNeighbors G u v, 2*η*s := by + apply Finset.sum_le_sum + intro w hw + obtain ⟨huw,hvw⟩ := (mem_commonNeighbors G u v w).mp hw + have hh := abs_add_le ((currentCodegree G u w : ℝ)-s) ((currentCodegree G v w : ℝ)-s) + have he : (currentCodegree G u w : ℝ)+currentCodegree G v w-2*s = + ((currentCodegree G u w : ℝ)-s)+((currentCodegree G v w : ℝ)-s) := by ring + rw [he] + linarith only [hh,hrow u w huw,hrow v w hvw] + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul,currentCodegree]; ring + +lemma normalized_pair_drift_factor {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + (u v : Fin n) (huv : u ≠ v) (s t : ℝ) (hs : s ≠ 0) : + pmfMean (step G) (fun H => (currentCodegree H u v : ℝ)/t)- + (currentCodegree G u v : ℝ)/s = + edgeStabilityScalar s t (triangles G).card (if {u,v} ∈ G then 1 else 0)* + ((currentCodegree G u v : ℝ)/s)- + centeredCodegreeNeighborSum G u v s/((triangles G).card*t) := by + rw [normalized_codegree_centered_drift hG u v huv] + unfold edgeStabilityScalar edgeStabilityRate + field_simp [hs] + ring + +lemma normalized_pair_drift_bound {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + (u v : Fin n) (huv : u ≠ v) {s t S lam r η : ℝ} + (hs : 0 < s) (ht : 0 < t) (hS : 0 < S) (hl : 0 ≤ lam) + (hscale : t = s*(1-lam)^2) (hratio : s ≤ 2*t) + (hident : s = lam*S) (hr : r ≤ 1/2) + (hQerr : |(triangles G).card/S-1| ≤ r) (hη : 0 ≤ η) + (hrow : ∀ a b, {a,b} ∈ G → |(currentCodegree G a b : ℝ)-s| ≤ η*s) + (hcap : (currentCodegree G u v : ℝ) ≤ 2*s) : + |pmfMean (step G) (fun H => (currentCodegree H u v : ℝ)/t)- + (currentCodegree G u v : ℝ)/s| ≤ + 16*r*lam+4*lam^2+8*lam/s+16*η*lam := by + have hκ0 : (0 : ℝ) ≤ if {u,v} ∈ G then 1 else 0 := by split_ifs <;> norm_num + have hκ1 : (if {u,v} ∈ G then (1 : ℝ) else 0) ≤ 1 := by split_ifs <;> norm_num + have hb := edge_stability_coefficients hs ht hS hl hscale hratio hident hr hQerr hκ0 hκ1 + have hQ := (triangle_relative_inverse_bound hS hr hQerr).1 + have hc : 0 ≤ (currentCodegree G u v : ℝ)/s := by positivity + have hc' : (currentCodegree G u v : ℝ)/s ≤ 2 := (div_le_iff₀ hs).mpr hcap + have hneigh : |centeredCodegreeNeighborSum G u v s| ≤ 4*η*s^2 := by + apply (centered_neighbor_sum_bound hG u v hη hs.le hrow).trans + exact (mul_le_mul_of_nonneg_left hcap (by positivity : 0 ≤ 2*η*s)).trans_eq (by ring) + have hquot : |centeredCodegreeNeighborSum G u v s/((triangles G).card*t)| ≤ 16*η*lam := by + rw [abs_div,abs_of_pos (mul_pos hQ ht)] + calc + _ ≤ (4*η*s^2)/((triangles G).card*t) := div_le_div_of_nonneg_right hneigh (mul_pos hQ ht).le + _ = 4*η*edgeStabilityRate s t (triangles G).card := by unfold edgeStabilityRate; ring + _ ≤ 4*η*(4*lam) := mul_le_mul_of_nonneg_left hb.1.2 (by positivity) + _ = _ := by ring + rw [normalized_pair_drift_factor hG u v huv s t hs.ne'] + calc + _ ≤ |edgeStabilityScalar s t (triangles G).card (if {u,v} ∈ G then 1 else 0)* + ((currentCodegree G u v : ℝ)/s)|+ + |centeredCodegreeNeighborSum G u v s/((triangles G).card*t)| := abs_sub _ _ + _ ≤ (8*r*lam+2*lam^2+4*lam/s)*2+16*η*lam := by + apply add_le_add _ hquot + rw [abs_mul,abs_of_nonneg hc] + exact (mul_le_mul_of_nonneg_left hc' (abs_nonneg _)).trans + (mul_le_mul_of_nonneg_right hb.2 (by norm_num)) + _ = _ := by ring + +theorem prefix_pair_compensator_bound : ∀ᶠ n : ℕ in atTop, + ∀ ω : History (Graph n) (prefixTime n), + ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support → + PrefixTriangleNoise n ω → ∀ j ≤ prefixTime n, + historyAlive (fun i => densityEdgeSafe n (earlyDensity n i) (prefixEdgeRadius n)) (prefixTime n) j ω → + ∀ u v : Fin n, u ≠ v → + (∀ i < j, (currentCodegree (ω (historyIndex (prefixTime n) i)) u v : ℝ) ≤ 2*earlyTemplateScale 1 2 n i) → + |historyCompensator (fun _ => step) (prefixNormalizedCodegree u v) (prefixTime n) j ω| ≤ + 16*prefixTriangleRadius n*Real.log n+4/prefixD n+24*Real.log n/(n : ℝ)+ + 16*prefixEdgeRadius n*Real.log n := by + filter_upwards [prefix_triangle_tracking,earlyTemplateScale_regular 1 2, + earlyTriangleScale_regular,prefix_triangle_radius_small,prefixDensity_eventually_inverse_lower, + eventually_ge_atTop (1 : ℕ)] with n htrack hreg htri hr hp hn + intro ω hω hnoise j hj hsafe u v huv hcap + have hn0 : 0 < n := by omega + have hη : 0 ≤ prefixEdgeRadius n := Real.rpow_nonneg (Nat.cast_nonneg _) _ + have hterm (i : ℕ) (hi : i < j) : + |pmfMean (step (ω (historyIndex (prefixTime n) i))) (prefixNormalizedCodegree u v (i+1))- + prefixNormalizedCodegree u v i (ω (historyIndex (prefixTime n) i))| ≤ + 16*prefixTriangleRadius n*(6/(n : ℝ)^2/earlyDensity n i)+ + 4*(6/(n : ℝ)^2/earlyDensity n i)^2+ + 8*(6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2)+ + 16*prefixEdgeRadius n*(6/(n : ℝ)^2/earlyDensity n i) := by + have hs := hsafe i hi + have hc := htrack ω hω hnoise i (by omega) (fun k hk => hsafe k (by omega)) + have hg := early_codegree_grid hn0 hp (by omega : i < prefixTime n) + have hrow (a b : Fin n) (he : {a,b} ∈ ω (historyIndex (prefixTime n) i)) : + |(currentCodegree (ω (historyIndex (prefixTime n) i)) a b : ℝ)-earlyTemplateScale 1 2 n i| ≤ + prefixEdgeRadius n*earlyTemplateScale 1 2 n i := by + have hh := hs.2.2 {a,b} he + rw [triangleDegree_eq_codegree hs.1 he] at hh + simpa only [earlyTemplateScale,pow_one] using hh + change |pmfMean (step (ω (historyIndex (prefixTime n) i))) (fun H => (currentCodegree H u v : ℝ)/earlyTemplateScale 1 2 n (i+1))- + (currentCodegree (ω (historyIndex (prefixTime n) i)) u v : ℝ)/earlyTemplateScale 1 2 n i| ≤ _ + simpa only [earlyTemplateScale,pow_one] using + normalized_pair_drift_bound hs.1 u v huv (hreg.1 i (by omega)) (hreg.1 (i+1) (by omega)) + (htri.1 i (by omega)) hg.2.2.1 hg.1 (hreg.2.2 i (by omega)) hg.2.1 hr.2 hc hη hrow (hcap i hi) + unfold historyCompensator historyCounter + rw [Nat.min_eq_left hj] + have hg := early_grid_sum_bounds hn0 hp j hj + calc + _ ≤ ∑ i ∈ Finset.range j, |pmfMean (step (ω (historyIndex (prefixTime n) i))) (prefixNormalizedCodegree u v (i+1))- + prefixNormalizedCodegree u v i (ω (historyIndex (prefixTime n) i))| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i ∈ Finset.range j, + (16*prefixTriangleRadius n*(6/(n : ℝ)^2/earlyDensity n i)+ + 4*(6/(n : ℝ)^2/earlyDensity n i)^2+ + 8*(6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2)+ + 16*prefixEdgeRadius n*(6/(n : ℝ)^2/earlyDensity n i)) := + Finset.sum_le_sum (fun i hi => hterm i (Finset.mem_range.mp hi)) + _ = 16*prefixTriangleRadius n*(∑ i ∈ Finset.range j, 6/(n : ℝ)^2/earlyDensity n i)+ + 4*(∑ i ∈ Finset.range j, (6/(n : ℝ)^2/earlyDensity n i)^2)+ + 8*(∑ i ∈ Finset.range j, (6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2))+ + 16*prefixEdgeRadius n*(∑ i ∈ Finset.range j, 6/(n : ℝ)^2/earlyDensity n i) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + _ ≤ _ := by + have h₁ := mul_le_mul_of_nonneg_left hg.1 (mul_nonneg (by norm_num : (0 : ℝ) ≤ 16) hr.1) + have h₂ := mul_le_mul_of_nonneg_left hg.2.2 (by norm_num : (0 : ℝ) ≤ 4) + have h₃ := mul_le_mul_of_nonneg_left hg.2.1 (by norm_num : (0 : ℝ) ≤ 8) + have h₄ := mul_le_mul_of_nonneg_left hg.1 (mul_nonneg (by norm_num : (0 : ℝ) ≤ 16) hη) + simp only [div_eq_mul_inv,mul_inv_rev] at h₁ h₂ h₃ h₄ ⊢ + norm_num at h₃ + nlinarith only [h₁,h₂,h₃,h₄] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ChargesCovered.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ChargesCovered.lean new file mode 100644 index 0000000000000000000000000000000000000000..dae32aac8584a956eb2a47954ceebceb7bd62c75 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ChargesCovered.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.MarkedChild + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +theorem markedFailure_le_one (p : PMF (Bool × Bool)) : markedFailure p ≤ 1 := by + rw [← pmfMean_const p 1] + apply pmfMean_mono + intro z _ + split <;> norm_num + +def ChargesCovered (charge : MarkedChild → Bool) (as : List MarkedChild) : Prop := + ∀ pre a post, as = pre ++ a :: post → + a.required = false → charge a = true → markedDemand post = true + +noncomputable def chargedFactor (charge : MarkedChild → Bool) (a : MarkedChild) : ℝ := + if a.required then markedGood a.law else if charge a then markedFailure a.law else 1 + +theorem chargedFactor_nonneg (c : MarkedChild → Bool) (a : MarkedChild) : + 0 ≤ chargedFactor c a := by + unfold chargedFactor + split + · exact markedGood_nonneg _ + · split + · exact markedFailure_nonneg _ + · exact zero_le_one + +theorem markedBound_le_charged (charge : MarkedChild → Bool) (as : List MarkedChild) + (hc : ChargesCovered charge as) : + markedBound as ≤ (as.map (chargedFactor charge)).prod := by + induction as with + | nil => exact le_refl _ + | cons a as ih => + have hc' : ChargesCovered charge as := by + intro pre b post hh hb hch + apply hc (a :: pre) b post + · simp only [List.cons_append, hh] + · exact hb + · exact hch + have hpoint : + (if a.required then markedGood a.law + else if markedDemand as then markedFailure a.law else 1) ≤ + chargedFactor charge a := by + by_cases hr : a.required = true + · simp [chargedFactor, hr] + · have hr' : a.required = false := Bool.eq_false_iff.mpr hr + by_cases hq : charge a = true + · have hd := hc [] a as rfl hr' hq + simp [chargedFactor, hr', hq, hd] + · simp only [chargedFactor, hr', Bool.false_eq_true, ↓reduceIte, hq] + split + · exact markedFailure_le_one _ + · exact le_refl _ + change _ * _ ≤ _ * _ + exact mul_le_mul hpoint (ih hc') (markedBound_nonneg as) (chargedFactor_nonneg _ _) + +theorem marked_visitation_charged (charge : MarkedChild → Bool) (as : List MarkedChild) + (hc : ChargesCovered charge as) : + markedGood (markedCheck as) ≤ (as.map (chargedFactor charge)).prod := + (marked_visitation_bound as).trans (markedBound_le_charged charge as hc) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighbors.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighbors.lean new file mode 100644 index 0000000000000000000000000000000000000000..e53e3cabe8aedf556d0444c37510f40b75548b7d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighbors.lean @@ -0,0 +1,132 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +def commonNeighbors {n : ℕ} (G : Graph n) (u v : Fin n) : Finset (Fin n) := + Finset.univ.filter (fun w => {u,w} ∈ G ∧ {v,w} ∈ G) + +def currentCodegree {n : ℕ} (G : Graph n) (u v : Fin n) : ℕ := + (commonNeighbors G u v).card + +def wedgeEdges {n : ℕ} (u v w : Fin n) : Graph n := {{u,w},{v,w}} + +@[simp] theorem mem_commonNeighbors {n : ℕ} (G : Graph n) (u v w : Fin n) : + w ∈ commonNeighbors G u v ↔ {u,w} ∈ G ∧ {v,w} ∈ G := by + simp [commonNeighbors] + +@[simp] theorem wedgeEdges_subset {n : ℕ} (G : Graph n) (u v w : Fin n) : + wedgeEdges u v w ⊆ G ↔ w ∈ commonNeighbors G u v := by + simp [wedgeEdges, Finset.insert_subset_iff, Finset.singleton_subset_iff] + +theorem commonNeighbors_ne {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + {u v w : Fin n} (hw : w ∈ commonNeighbors G u v) : u ≠ w ∧ v ≠ w := by + obtain ⟨hu,hv⟩ := (mem_commonNeighbors G u v w).mp hw + constructor + · intro h + have hc := mem_completeGraph.mp (hG hu) + simp [h] at hc + · intro h + have hc := mem_completeGraph.mp (hG hv) + simp [h] at hc + +theorem currentCodegree_copyCount {n : ℕ} (G : Graph n) (u v : Fin n) : + (currentCodegree G u v : ℝ) = copyCount (wedgeEdges u v) G := by + simp only [copyCount, intact, wedgeEdges_subset] + rw [← Finset.sum_filter] + simp [currentCodegree, commonNeighbors] + +theorem wedgeEdges_card {n : ℕ} {u v w : Fin n} (huv : u ≠ v) + (huw : u ≠ w) : (wedgeEdges u v w).card = 2 := by + have he : ({u,w} : Finset (Fin n)) ≠ {v,w} := by + intro heq + have hu : u ∈ ({v,w} : Finset (Fin n)) := heq ▸ (by simp) + simp only [Finset.mem_insert, Finset.mem_singleton] at hu + exact hu.elim huv huw + simp [wedgeEdges, he] + +theorem step_mean_codegree_hazard {n : ℕ} (G : Graph n) (u v : Fin n) + (hG : (triangles G).Nonempty) : + pmfMean (step G) (fun H => (currentCodegree H u v : ℝ)) = + (currentCodegree G u v : ℝ) - + (∑ w ∈ commonNeighbors G u v, + ((hittingTriangles G (wedgeEdges u v w)).card : ℝ)) / (triangles G).card := by + simp_rw [currentCodegree_copyCount] + rw [step_mean_copyCount _ G hG] + congr 2 + simp only [wedgeEdges_subset] + rw [← Finset.sum_filter] + simp [commonNeighbors] + +theorem hittingTriangles_wedge {n : ℕ} (G : Graph n) (u v w : Fin n) : + hittingTriangles G (wedgeEdges u v w) = + incidentTriangles G {u,w} ∪ incidentTriangles G {v,w} := by + rw [hittingTriangles_eq_biUnion] + simp [wedgeEdges] + +theorem wedge_incident_inter {n : ℕ} (G : Graph n) {u v w : Fin n} + (huv : u ≠ v) (huw : u ≠ w) (hvw : v ≠ w) : + incidentTriangles G {u,w} ∩ incidentTriangles G {v,w} = + if {u,v,w} ∈ triangles G then {{u,v,w}} else ∅ := by + ext t + simp only [Finset.mem_inter, incidentTriangles, Finset.mem_filter] + have hpairu : ({u,w} : Finset (Fin n)).card = 2 := Finset.card_pair huw + have hpairv : ({v,w} : Finset (Fin n)).card = 2 := Finset.card_pair hvw + have htriple : ({u,v,w} : Finset (Fin n)).card = 3 := by simp [huv,huw,hvw] + have hpt : ({u,w} : Finset (Fin n)) ⊆ {u,v,w} := by + simp [Finset.insert_subset_iff, Finset.singleton_subset_iff] + have hqt : ({v,w} : Finset (Fin n)) ⊆ {u,v,w} := by + simp + have hpq : ({u,w} : Finset (Fin n)) ≠ {v,w} := by + intro he + have hh : u ∈ ({v,w} : Finset (Fin n)) := he ▸ (by simp) + simp [huv,huw] at hh + constructor + · rintro ⟨⟨ht,he⟩,_,hf⟩ + have heq := triangle_eq_of_two_edges (mem_triangles.mp ht).1 htriple + hpairu hpairv hpq (Finset.mem_powersetCard.mp he).1 + (Finset.mem_powersetCard.mp hf).1 hpt hqt + subst t + simp [ht] + · intro hh + split_ifs at hh with ht + · have heq : t = {u,v,w} := Finset.mem_singleton.mp hh + subst t + exact ⟨⟨ht,Finset.mem_powersetCard.mpr ⟨hpt,hpairu⟩⟩, + ht,Finset.mem_powersetCard.mpr ⟨hqt,hpairv⟩⟩ + · exact False.elim (Finset.notMem_empty t hh) + +theorem wedge_hazard_exact {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + {u v w : Fin n} (huv : u ≠ v) (hw : w ∈ commonNeighbors G u v) : + ((hittingTriangles G (wedgeEdges u v w)).card : ℝ) = + (triangleDegree G {u,w} : ℝ) + (triangleDegree G {v,w} : ℝ) - + if {u,v,w} ∈ triangles G then 1 else 0 := by + obtain ⟨huw,hvw⟩ := commonNeighbors_ne hG hw + have hh := Finset.card_union_add_card_inter + (incidentTriangles G {u,w}) (incidentTriangles G {v,w}) + rw [wedge_incident_inter G huv huw hvw] at hh + rw [hittingTriangles_wedge] + unfold triangleDegree + split_ifs at hh ⊢ with ht <;> simp only [Finset.card_singleton, Finset.card_empty] at hh + all_goals + have hh' : ((incidentTriangles G {u,w} ∪ incidentTriangles G {v,w}).card : ℝ) + + (if {u,v,w} ∈ triangles G then 1 else 0) = + (incidentTriangles G {u,w}).card + (incidentTriangles G {v,w}).card := by + simp only [ht, ↓reduceIte] + exact_mod_cast hh + simp only [ht, ↓reduceIte] at hh' + linarith + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighborsComplete.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighborsComplete.lean new file mode 100644 index 0000000000000000000000000000000000000000..529e059a478195d4edd6e3c86af36b599409c226 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighborsComplete.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Asymptotics.EarlyDensity + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma commonNeighbors_complete {n : ℕ} (u v : Fin n) : + commonNeighbors (completeGraph n) u v = Finset.univ \ {u,v} := by + ext w + simp only [mem_commonNeighbors,mem_completeGraph,Finset.mem_sdiff, + Finset.mem_univ,Finset.mem_insert,Finset.mem_singleton,true_and] + by_cases hu : u = w <;> by_cases hv : v = w <;> + simp [hu,hv,eq_comm] + +lemma currentCodegree_complete {n : ℕ} (u v : Fin n) (huv : u ≠ v) : + currentCodegree (completeGraph n) u v = n-2 := by + rw [currentCodegree,commonNeighbors_complete] + rw [Finset.card_sdiff] + simp only [Finset.inter_univ] + simp only [Finset.card_univ,Fintype.card_fin,Finset.card_pair huv] + +theorem initial_normalized_codegree_error {n : ℕ} (hn : 2 ≤ n) + (u v : Fin n) (huv : u ≠ v) : + (currentCodegree (completeGraph n) u v : ℝ)/earlyTemplateScale 1 2 n 0-1 = + -1/((n : ℝ)-1)^2 := by + have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn + have hn0 : (n : ℝ) ≠ 0 := by linarith + have hn1 : (n : ℝ)-1 ≠ 0 := by linarith + rw [currentCodegree_complete u v huv,Nat.cast_sub hn,Nat.cast_ofNat] + unfold earlyTemplateScale earlyDensity + simp only [Nat.cast_zero,mul_zero,zero_div,sub_zero,pow_one] + field_simp + ring + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighborsMono.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighborsMono.lean new file mode 100644 index 0000000000000000000000000000000000000000..88bad8e29cfce185115fcf5a740e3d3c21b723cf --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CommonNeighborsMono.lean @@ -0,0 +1,74 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.CommonNeighbors + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem commonNeighbors_mono {n : ℕ} {G H : Graph n} (h : H ⊆ G) (u v : Fin n) : + commonNeighbors H u v ⊆ commonNeighbors G u v := by + intro w hw + exact (mem_commonNeighbors G u v w).mpr + ⟨h ((mem_commonNeighbors H u v w).mp hw).1, + h ((mem_commonNeighbors H u v w).mp hw).2⟩ + +theorem commonNeighbors_delete {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + (u v : Fin n) (t : Finset (Fin n)) : + commonNeighbors (G \ t.powersetCard 2) u v = + if u ∈ t ∨ v ∈ t then commonNeighbors G u v \ t else commonNeighbors G u v := by + ext w + by_cases hw : w ∈ commonNeighbors G u v + · obtain ⟨huw,hvw⟩ := commonNeighbors_ne hG hw + obtain ⟨he,hf⟩ := (mem_commonNeighbors G u v w).mp hw + simp only [mem_commonNeighbors, Finset.mem_sdiff, he, hf, true_and, + Finset.mem_powersetCard, Finset.insert_subset_iff, Finset.singleton_subset_iff, + Finset.card_pair huw, Finset.card_pair hvw, and_true] + split_ifs with ht <;> simp only [Finset.mem_sdiff, hw, true_and] + · tauto + · push Not at ht + simp [ht.1, ht.2] + · have hw' : w ∉ commonNeighbors (G \ t.powersetCard 2) u v := + fun hh => hw (commonNeighbors_mono Finset.sdiff_subset u v hh) + split_ifs <;> simp [hw, hw'] + +theorem codegree_delete_range {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + (u v : Fin n) {t : Finset (Fin n)} (ht : t ∈ triangles G) : + 0 ≤ (currentCodegree G u v : ℝ) - currentCodegree (G \ t.powersetCard 2) u v ∧ + (currentCodegree G u v : ℝ) - currentCodegree (G \ t.powersetCard 2) u v ≤ 2 := by + have hc : t.card = 3 := (mem_triangles.mp ht).1 + unfold currentCodegree + rw [commonNeighbors_delete hG u v t] + split_ifs with hp + · have hbound : ((commonNeighbors G u v) ∩ t).card ≤ 2 := by + rcases hp with hu | hv + · have hsub : (commonNeighbors G u v) ∩ t ⊆ t.erase u := by + intro w hw + obtain ⟨hw,hwt⟩ := Finset.mem_inter.mp hw + exact Finset.mem_erase.mpr ⟨(commonNeighbors_ne hG hw).1.symm,hwt⟩ + have hh := Finset.card_le_card hsub + simpa [Finset.card_erase_of_mem hu, hc] using hh + · have hsub : (commonNeighbors G u v) ∩ t ⊆ t.erase v := by + intro w hw + obtain ⟨hw,hwt⟩ := Finset.mem_inter.mp hw + exact Finset.mem_erase.mpr ⟨(commonNeighbors_ne hG hw).2.symm,hwt⟩ + have hh := Finset.card_le_card hsub + simpa [Finset.card_erase_of_mem hv, hc] using hh + have hid := Finset.card_sdiff_add_card_inter (commonNeighbors G u v) t + have hid' : ((commonNeighbors G u v \ t).card : ℝ) + + ((commonNeighbors G u v ∩ t).card : ℝ) = (commonNeighbors G u v).card := by + exact_mod_cast hid + have hbound' : (((commonNeighbors G u v) ∩ t).card : ℝ) ≤ 2 := by exact_mod_cast hbound + constructor <;> linarith [Nat.cast_nonneg (α := ℝ) ((commonNeighbors G u v ∩ t).card)] + · simp + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CompleteEdge.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CompleteEdge.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b6ba5b53541b701d352a3f314e7c005ade17486 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CompleteEdge.lean @@ -0,0 +1,109 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TerminalLaw +import OAI.Combinatorics.TriangleRemoval.Spectral.MatrixInfinityAlgHom +import OAI.Combinatorics.TriangleRemoval.Asymptotics.ActiveL2Map + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Classical Matrix + +namespace SharpTerminalLeave + +abbrev CompleteEdge (n : ℕ) := ↥(completeGraph n) + +def graphActive {n : ℕ} (G : Graph n) : Finset (CompleteEdge n) := + Finset.univ.filter (fun e => e.val ∈ G) + +@[simp] lemma mem_graphActive {n : ℕ} (G : Graph n) (e : CompleteEdge n) : + e ∈ graphActive G ↔ e.val ∈ G := by simp [graphActive] + +def graphEdgeEmbed {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) : G ↪ CompleteEdge n := + ⟨fun e => ⟨e.val,hG e.property⟩,fun _ _ h => Subtype.ext (congrArg (fun e : CompleteEdge n => e.val) h)⟩ + +lemma graphActive_sum {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (f : CompleteEdge n → ℝ) : + (∑ e ∈ graphActive G, f e) = ∑ e : G, f (graphEdgeEmbed G hG e) := by + apply Finset.sum_bij (fun e he => (⟨e.val,(mem_graphActive G e).mp he⟩ : G)) + · intro _ _; exact Finset.mem_univ _ + · intro a ha b hb he + exact Subtype.ext (congrArg (fun e : G => e.val) he) + · intro e _ + exact ⟨graphEdgeEmbed G hG e,by exact (mem_graphActive G _).mpr e.property,rfl⟩ + · intro _ _; rfl + +lemma graphActive_card_le {n : ℕ} : Fintype.card (CompleteEdge n) ≤ n^2 := by + rw [Fintype.card_coe,card_completeGraph] + exact (Nat.choose_le_pow n 2) + +lemma graphActive_nested {n : ℕ} {G H : Graph n} (h : H ⊆ G) : graphActive H ⊆ graphActive G := by + intro e he + exact (mem_graphActive G e).mpr (h ((mem_graphActive H e).mp he)) + +def graphRestrict {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) : + (CompleteEdge n → ℝ) →ₗ[ℝ] (G → ℝ) where + toFun x e := x (graphEdgeEmbed G hG e) + map_add' _ _ := rfl + map_smul' _ _ := rfl + +def graphExtend {n : ℕ} (G : Graph n) : (G → ℝ) →ₗ[ℝ] (CompleteEdge n → ℝ) where + toFun z e := if he : e.val ∈ G then z ⟨e.val,he⟩ else 0 + map_add' _ _ := by funext e; by_cases he : e.val ∈ G <;> simp [he] + map_smul' _ _ := by funext e; by_cases he : e.val ∈ G <;> simp [he] + +@[simp] lemma graphRestrict_extend {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (z : G → ℝ) : + graphRestrict G hG (graphExtend G z) = z := by + funext e + change (if he : e.val ∈ G then z ⟨e.val,he⟩ else 0) = z e + simp only [dite_eq_left e.property] + +lemma activeLinf_restrict {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (x : CompleteEdge n → ℝ) : + activeLinf (graphActive G) x = ‖graphRestrict G hG x‖ := by + apply le_antisymm + · apply activeLinf_bound _ _ (norm_nonneg _) + intro e he + have hh := norm_le_pi_norm (graphRestrict G hG x) (⟨e.val,(mem_graphActive G e).mp he⟩ : G) + exact hh + · apply (pi_norm_le_iff_of_nonneg (apply_nonneg _ _)).mpr + intro e + exact activeLinf_coordinate _ _ (e := graphEdgeEmbed G hG e) ((mem_graphActive _ _).mpr e.property) + +lemma activeL2_restrict {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (x : CompleteEdge n → ℝ) : + activeL2 (graphActive G) x = ‖WithLp.toLp 2 (graphRestrict G hG x)‖ := by + have hsq : (activeL2 (graphActive G) x)^2 = ‖WithLp.toLp 2 (graphRestrict G hG x)‖^2 := by + rw [activeL2_sq,EuclideanSpace.real_norm_sq_eq,graphActive_sum G hG] + rfl + nlinarith [apply_nonneg (activeL2 (graphActive G)) x,norm_nonneg (WithLp.toLp 2 (graphRestrict G hG x))] + +noncomputable def graphMatrixLift {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (M : Matrix G G ℝ) : Module.End ℝ (CompleteEdge n → ℝ) := + (graphExtend G).comp ((Matrix.toLin' M).comp (graphRestrict G hG)) + +@[simp] lemma graphMatrixLift_restrict {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (M : Matrix G G ℝ) (x : CompleteEdge n → ℝ) : + graphRestrict G hG (graphMatrixLift G hG M x) = M *ᵥ (graphRestrict G hG x) := by + simp [graphMatrixLift] + +open scoped Matrix.Norms.Operator in + +lemma graphMatrixLift_linf {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (M : Matrix G G ℝ) (x : CompleteEdge n → ℝ) : + activeLinf (graphActive G) (graphMatrixLift G hG M x) ≤ ‖M‖*activeLinf (graphActive G) x := by + rw [activeLinf_restrict G hG,graphMatrixLift_restrict,activeLinf_restrict G hG] + exact (matrixInfinityAlgHom M).le_opNorm _ |>.trans_eq (by rw [matrixInfinityAlgHom_norm]) + +open scoped Matrix.Norms.L2Operator in + +lemma graphMatrixLift_l2 {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (M : Matrix G G ℝ) (x : CompleteEdge n → ℝ) : + activeL2 (graphActive G) (graphMatrixLift G hG M x) ≤ ‖M‖*activeL2 (graphActive G) x := by + rw [activeL2_restrict G hG,graphMatrixLift_restrict,activeL2_restrict G hG] + have hh := (Matrix.toEuclideanCLM (n := G) (𝕜 := ℝ) M).le_opNorm (WithLp.toLp 2 (graphRestrict G hG x)) + simpa only [Matrix.toEuclideanCLM_toLp,← Matrix.l2_opNorm_toEuclideanCLM] using hh + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CompleteEdgePair.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CompleteEdgePair.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b98c37f1de9f5d4e6470b8c58ac8e75323875b0 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CompleteEdgePair.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixCodegreeDriftTerm +import OAI.Combinatorics.TriangleRemoval.Process.ExtendedLinkMulVec +import OAI.Combinatorics.TriangleRemoval.Stability.EdgeStabilityRate + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical Matrix + +namespace SharpTerminalLeave + +noncomputable def completeEdgePair {n : ℕ} (e : CompleteEdge n) : + {uv : Fin n × Fin n // uv.1 ≠ uv.2 ∧ e.val = {uv.1,uv.2}} := by + have h : ∃ uv : Fin n × Fin n, uv.1 ≠ uv.2 ∧ e.val = {uv.1,uv.2} := by + obtain ⟨u,v,huv,he⟩ := Finset.card_eq_two.mp (mem_completeGraph.mp e.property) + exact ⟨(u,v),huv,he⟩ + exact ⟨h.choose,h.choose_spec⟩ + +noncomputable def centeredEdgeVector {n : ℕ} (G : Graph n) (s : ℝ) (e : CompleteEdge n) : ℝ := + (currentCodegree G (completeEdgePair e).val.1 (completeEdgePair e).val.2 : ℝ)/s-1 + +lemma centeredEdgeVector_restrict {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (s : ℝ) : + graphRestrict G hG (centeredEdgeVector G s) = fun e : G => (triangleDegree G e.val : ℝ)/s-1 := by + funext e + let uv := completeEdgePair (graphEdgeEmbed G hG e) + have he : e.val = {uv.val.1,uv.val.2} := uv.property.2 + change (currentCodegree G uv.val.1 uv.val.2 : ℝ)/s-1 = _ + rw [he,triangleDegree_eq_codegree hG (he ▸ e.property)] + +lemma graphMatrixLift_apply {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (M : Matrix G G ℝ) (z : CompleteEdge n → ℝ) (e : CompleteEdge n) (he : e.val ∈ G) : + graphMatrixLift G hG M z e = (M *ᵥ graphRestrict G hG z) ⟨e.val,he⟩ := by + change (if he : e.val ∈ G then _ else 0) = _ + rw [dite_eq_left he] + rfl + +lemma graph_centered_normalized_operator {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (s : ℝ) (e : CompleteEdge n) (he : e.val ∈ G) : + graphMatrixLift G hG (s⁻¹ • globalLinkAdjacency G hG) (centeredEdgeVector G s) e = + centeredCodegreeNeighborSum G (completeEdgePair e).val.1 (completeEdgePair e).val.2 s/s^2 := by + by_cases hs : s = 0 + · subst s; simp [graphMatrixLift] + let uv := completeEdgePair e + have heq : e.val = {uv.val.1,uv.val.2} := uv.property.2 + rw [graphMatrixLift_apply _ _ _ _ _ he,centeredEdgeVector_restrict,Matrix.smul_mulVec] + simp only [Pi.smul_apply,smul_eq_mul] + have hp : {uv.val.1,uv.val.2} ∈ G := heq ▸ he + have hei : (⟨e.val,he⟩ : G) = ⟨{uv.val.1,uv.val.2},hp⟩ := Subtype.ext heq + rw [hei,global_link_codegree_action G hG _ _ hp s hs] + dsimp only [uv] + ring + +lemma graph_star_residual_sum {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (s : ℝ) (z : CompleteEdge n → ℝ) (e : CompleteEdge n) (he : e.val ∈ G) : + movingStarLift (fun e : CompleteEdge n => e.val) + (movingStarMean (fun e : CompleteEdge n => e.val) (graphActive G) z) e+ + graphMatrixLift G hG (s⁻¹ • globalLinkAdjacency G hG-globalStarAverage G) z e = + graphMatrixLift G hG (s⁻¹ • globalLinkAdjacency G hG) z e := by + rw [graph_movingStarLift G hG z e ((mem_graphActive _ _).mpr he)] + simp only [graphMatrixLift_apply G hG _ _ _ he,Matrix.sub_mulVec,Pi.sub_apply] + ring + +lemma centered_edge_operator_drift {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (s t : ℝ) (hs : s ≠ 0) (e : CompleteEdge n) (he : e.val ∈ G) : + pmfMean (step G) (fun H => (currentCodegree H (completeEdgePair e).val.1 (completeEdgePair e).val.2 : ℝ)/t)- + (centeredEdgeVector G s e+1) = + -edgeStabilityRate s t (triangles G).card* + (movingStarLift (fun e : CompleteEdge n => e.val) + (movingStarMean (fun e : CompleteEdge n => e.val) (graphActive G) (centeredEdgeVector G s)) e+ + graphMatrixLift G hG (s⁻¹ • globalLinkAdjacency G hG-globalStarAverage G) (centeredEdgeVector G s) e)+ + edgeStabilityScalar s t (triangles G).card 1*(centeredEdgeVector G s e+1) := by + rw [graph_star_residual_sum G hG s _ e he,graph_centered_normalized_operator G hG s e he] + let uv := completeEdgePair e + have huv := uv.property.1 + have hep : {uv.val.1,uv.val.2} ∈ G := uv.property.2 ▸ he + dsimp only [centeredEdgeVector] + simp only [sub_add_cancel] + rw [normalized_codegree_centered_drift hG _ _ huv s t,ite_eq_left hep] + unfold edgeStabilityScalar edgeStabilityRate + field_simp [hs] + ring + +lemma history_valid_all {n T : ℕ} (ω : History (Graph n) T) + (hω : ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) T T).support) (i : ℕ) : + ω (historyIndex T i) ⊆ completeGraph n := by + have hi : historyIndex T i = historyIndex T (min i T) := by simp [historyIndex] + rw [hi] + exact complete_history_valid ω hω _ (Nat.min_le_right _ _) + +noncomputable def prefixCenteredEdge {n : ℕ} (ω : History (Graph n) (prefixTime n)) + (i : ℕ) : CompleteEdge n → ℝ := + centeredEdgeVector (ω (historyIndex (prefixTime n) i)) (earlyTemplateScale 1 2 n i) + +noncomputable def prefixEdgeRate {n : ℕ} (ω : History (Graph n) (prefixTime n)) (i : ℕ) : ℝ := + edgeStabilityRate (earlyTemplateScale 1 2 n i) (earlyTemplateScale 1 2 n (i+1)) + (triangles (ω (historyIndex (prefixTime n) i))).card + +noncomputable def prefixEdgeScalar {n : ℕ} (ω : History (Graph n) (prefixTime n)) (i : ℕ) : ℝ := + edgeStabilityScalar (earlyTemplateScale 1 2 n i) (earlyTemplateScale 1 2 n (i+1)) + (triangles (ω (historyIndex (prefixTime n) i))).card 1 + +noncomputable def prefixEdgeResidual {n : ℕ} (ω : History (Graph n) (prefixTime n)) + (hω : ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support) + (i : ℕ) : Module.End ℝ (CompleteEdge n → ℝ) := + graphMatrixLift _ (history_valid_all ω hω i) + ((earlyTemplateScale 1 2 n i)⁻¹ • globalLinkAdjacency _ (history_valid_all ω hω i)-globalStarAverage _) + +noncomputable def prefixEdgeForcing {n : ℕ} (ω : History (Graph n) (prefixTime n)) + (i : ℕ) (e : CompleteEdge n) : ℝ := + prefixCenteredEdge ω 0 e+ + historyNoise (fun _ => step) + (fun k H => (currentCodegree H (completeEdgePair e).val.1 (completeEdgePair e).val.2 : ℝ)/earlyTemplateScale 1 2 n k) + (prefixTime n) i ω+ + ∑ k ∈ Finset.range i, prefixEdgeScalar ω k*(prefixCenteredEdge ω k e+1) + +lemma prefixEdgeForcing_zero {n : ℕ} (ω : History (Graph n) (prefixTime n)) : + prefixEdgeForcing ω 0 = prefixCenteredEdge ω 0 := by + funext e + simp [prefixEdgeForcing] + +lemma prefix_centered_edge_recurrence {n i : ℕ} (ω : History (Graph n) (prefixTime n)) + (hω : ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support) + (hi : i < prefixTime n) (hs : earlyTemplateScale 1 2 n i ≠ 0) + (e : CompleteEdge n) (he : e ∈ graphActive (ω (historyIndex (prefixTime n) (i+1)))) : + prefixCenteredEdge ω (i+1) e = prefixCenteredEdge ω i e- + prefixEdgeRate ω i*(movingStarLift (fun e : CompleteEdge n => e.val) + (movingStarMean (fun e : CompleteEdge n => e.val) + (graphActive (ω (historyIndex (prefixTime n) i))) (prefixCenteredEdge ω i)) e+ + prefixEdgeResidual ω hω i (prefixCenteredEdge ω i) e)+ + (prefixEdgeForcing ω (i+1) e-prefixEdgeForcing ω i e) := by + have hpath := (historyLaw_path_support (PMF.pure (completeGraph n)) (fun _ => step) + (prefixTime n) (prefixTime n) le_rfl ω hω).2 i hi + have he0 : e.val ∈ ω (historyIndex (prefixTime n) i) := step_support_subset hpath ((mem_graphActive _ _).mp he) + have hd := centered_edge_operator_drift _ (history_valid_all ω hω i) + (earlyTemplateScale 1 2 n i) (earlyTemplateScale 1 2 n (i+1)) hs e he0 + unfold prefixEdgeForcing + rw [historyNoise_succ_same _ _ _ _ hi,Finset.sum_range_succ] + simp only [historyIncrement] at * + change _ = _ at hd + dsimp only [prefixCenteredEdge,prefixEdgeRate,prefixEdgeScalar,prefixEdgeResidual] at * + dsimp only [centeredEdgeVector] at * + linarith only [hd] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CopyEdgeLoad.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CopyEdgeLoad.lean new file mode 100644 index 0000000000000000000000000000000000000000..f68ed138e03e102109c57029496af2a0a12001fa --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CopyEdgeLoad.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.CodegreeVarianceRate +import OAI.Combinatorics.TriangleRemoval.Probability.HistoryLawPastMean + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +noncomputable def copyEdgeLoad {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (e : Finset (Fin n)) : ℝ := + ∑ a, if e ∈ required a then intact (required a) G else 0 + +lemma intact_nonneg {n : ℕ} (F G : Graph n) : 0 ≤ intact F G := by + unfold intact + split <;> norm_num + +lemma intact_mono {n : ℕ} (F : Graph n) {G H : Graph n} (h : G ⊆ H) : + intact F G ≤ intact F H := by + unfold intact + by_cases hF : F ⊆ G + · rw [ite_eq_left hF,ite_eq_left (hF.trans h)] + · rw [ite_eq_right hF] + split <;> norm_num + +lemma copyEdgeLoad_nonneg {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (e : Finset (Fin n)) : + 0 ≤ copyEdgeLoad required G e := by + apply Finset.sum_nonneg + intro a _ + split + · exact intact_nonneg _ _ + · exact le_rfl + +lemma copyCount_mono {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) {G H : Graph n} (h : G ⊆ H) : + copyCount required G ≤ copyCount required H := by + apply Finset.sum_le_sum + intro a _ + exact intact_mono (required a) h + +lemma intact_deleted_loss_le {n : ℕ} (F G E : Graph n) : + intact F G - intact F (G \ E) ≤ + ∑ e ∈ E, if e ∈ F then intact F G else 0 := by + classical + by_cases hF : F ⊆ G + · by_cases hFE : F ⊆ G \ E + · rw [intact,ite_eq_left hF,intact,ite_eq_left hFE,sub_self] + apply Finset.sum_nonneg + intro e _ + split <;> positivity + · obtain ⟨e,heF,heGE⟩ := Finset.not_subset.mp hFE + have heE : e ∈ E := by + by_contra he + exact heGE (Finset.mem_sdiff.mpr ⟨hF heF,he⟩) + have hh := Finset.single_le_sum + (f := fun e => if e ∈ F then intact F G else 0) + (fun _ _ => by split; exact intact_nonneg _ _; exact le_rfl) heE + simpa only [ite_eq_left heF,intact,ite_eq_left hF,ite_eq_right hFE,sub_zero] using hh + · have hFE : ¬ F ⊆ G \ E := fun h => hF (h.trans Finset.sdiff_subset) + simp only [intact,ite_eq_right hF,ite_eq_right hFE,sub_self,ite_self,Finset.sum_const_zero,le_refl] + +theorem copyCount_deleted_loss_le {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G E : Graph n) : + copyCount required G - copyCount required (G \ E) ≤ + ∑ e ∈ E, copyEdgeLoad required G e := by + classical + unfold copyCount + rw [← Finset.sum_sub_distrib] + calc + _ ≤ ∑ a, ∑ e ∈ E, if e ∈ required a then intact (required a) G else 0 := by + apply Finset.sum_le_sum + intro a _ + exact intact_deleted_loss_le _ _ _ + _ = _ := Finset.sum_comm + +theorem copyCount_step_loss_range {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G H : Graph n) (L : ℝ) (hL : 0 ≤ L) + (hload : ∀ e ∈ G, copyEdgeLoad required G e ≤ L) + (hH : H ∈ (step G).support) : + 0 ≤ copyCount required G - copyCount required H ∧ + copyCount required G - copyCount required H ≤ 3*L := by + constructor + · exact sub_nonneg.mpr (copyCount_mono required (step_support_subset hH)) + · by_cases hG : (triangles G).Nonempty + · obtain ⟨t,ht,rfl⟩ := (step_support_active hG).mp hH + calc + _ ≤ ∑ e ∈ t.powersetCard 2, copyEdgeLoad required G e := + copyCount_deleted_loss_le required G _ + _ ≤ ∑ _e ∈ t.powersetCard 2, L := Finset.sum_le_sum + (fun e he => hload e ((mem_triangles.mp ht).2 he)) + _ = 3*L := by simp only [Finset.sum_const,nsmul_eq_mul,triangle_edge_card ht]; norm_num + · simp only [step,dite_eq_right hG,PMF.mem_support_pure_iff] at hH + subst H + simpa only [sub_self] using mul_nonneg (by norm_num : (0 : ℝ) ≤ 3) hL + +theorem pmf_centered_of_loss_range {α : Type*} [Fintype α] (p : PMF α) + (f : α → ℝ) (a R : ℝ) + (h : ∀ b ∈ p.support, 0 ≤ a-f b ∧ a-f b ≤ R) : + ∀ b ∈ p.support, |f b-pmfMean p f| ≤ R := by + have hlo : a-R ≤ pmfMean p f := by + rw [← pmfMean_const p (a-R)] + apply pmfMean_mono + intro b hb + have := (h b hb).2 + linarith + have hhi : pmfMean p f ≤ a := by + rw [← pmfMean_const p a] + apply pmfMean_mono + intro b hb + have := (h b hb).1 + linarith + intro b hb + obtain ⟨h₁,h₂⟩ := h b hb + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +theorem pmf_variance_of_loss_range {α : Type*} [Fintype α] (p : PMF α) + (f : α → ℝ) (a R : ℝ) + (h : ∀ b ∈ p.support, 0 ≤ a-f b ∧ a-f b ≤ R) : + pmfMean p (fun b => (f b-pmfMean p f)^2) ≤ R*(a-pmfMean p f) := by + apply (pmfMean_centered_sq_le p f a).trans + calc + _ ≤ pmfMean p (fun b => R*(a-f b)) := by + apply pmfMean_mono + intro b hb + obtain ⟨h₁,h₂⟩ := h b hb + nlinarith [mul_nonneg h₁ (sub_nonneg.mpr h₂)] + _ = _ := by rw [pmfMean_const_mul,pmfMean_sub,pmfMean_const] + +noncomputable def copyVarianceRate {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L : ℝ) (_k : ℕ) (G : Graph n) : ℝ := + 3*L*(copyCount required G - pmfMean (step G) (copyCount required)) + +theorem triangle_template_noise_freedman {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L : ℝ) (hL : 0 < L) + (hload : ∀ j < T, ∀ H ∈ (evolve G j).support, + ∀ e ∈ H, copyEdgeLoad required H e ≤ L) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ j ≤ T, + r ≤ historyNoise (fun _ => step) (fun _ => copyCount required) T j ω ∧ + historyCounter (copyVarianceRate required L) T j ω ≤ V then 1 else 0) ≤ + (T+1 : ℝ)*Real.exp (-r^2/(4*(V+(3*L)*r))) := by + apply history_noise_freedman_maximal (PMF.pure G) (fun _ => step) + (fun _ => copyCount required) (copyVarianceRate required L) T (3*L) (by positivity) + · intro j hj H hH J hJ + rw [markovLaw_triangle_step] at hH + exact pmf_centered_of_loss_range (step H) (copyCount required) (copyCount required H) + (3*L) (fun A hA => copyCount_step_loss_range required H A L hL.le (hload j hj H hH) hA) J hJ + · intro j hj H hH + rw [markovLaw_triangle_step] at hH + exact pmf_variance_of_loss_range (step H) (copyCount required) (copyCount required H) + (3*L) (fun A hA => copyCount_step_loss_range required H A L hL.le (hload j hj H hH) hA) + · exact hr + · exact hV + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/CopyLoadSafe.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/CopyLoadSafe.lean new file mode 100644 index 0000000000000000000000000000000000000000..057fcf29fe875d90764d95ad93cbf7083bb4632b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/CopyLoadSafe.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.CopyEdgeLoad +import OAI.Combinatorics.TriangleRemoval.Process.HistoryAdditive + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +def copyLoadSafe {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L : ℝ) (G : Graph n) : Prop := + ∀ e ∈ G, copyEdgeLoad required G e ≤ L + +noncomputable def safeCopyIncrement {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L : ℝ) (_j : ℕ) (G H : Graph n) : ℝ := by + classical + exact if copyLoadSafe required L G then + copyCount required H - pmfMean (step G) (copyCount required) else 0 + +noncomputable def safeCopyVarianceRate {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L : ℝ) (j : ℕ) (G : Graph n) : ℝ := by + classical + exact if copyLoadSafe required L G then copyVarianceRate required L j G else 0 + +theorem triangle_safe_template_freedman {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L : ℝ) (hL : 0 < L) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ j ≤ T, + r ≤ historyAdditive (safeCopyIncrement required L) T j ω ∧ + historyCounter (safeCopyVarianceRate required L) T j ω ≤ V then 1 else 0) ≤ + (T+1 : ℝ)*Real.exp (-r^2/(4*(V+(3*L)*r))) := by + classical + apply history_additive_freedman_maximal (PMF.pure G) (fun _ => step) + (safeCopyIncrement required L) (safeCopyVarianceRate required L) T (3*L) (by positivity) + · intro j _ H _ J hJ + by_cases hs : copyLoadSafe required L H + · simp only [safeCopyIncrement,ite_eq_left hs] + exact pmf_centered_of_loss_range (step H) (copyCount required) (copyCount required H) + (3*L) (fun A hA => copyCount_step_loss_range required H A L hL.le hs hA) J hJ + · simp only [safeCopyIncrement,ite_eq_right hs,abs_zero] + positivity + · intro j _ H _ + change pmfMean (step H) (fun J => safeCopyIncrement required L j H J) = 0 + by_cases hs : copyLoadSafe required L H + · simp only [safeCopyIncrement,ite_eq_left hs] + rw [pmfMean_sub,pmfMean_const,sub_self] + · simp only [safeCopyIncrement,ite_eq_right hs,pmfMean_const] + · intro j _ H _ + by_cases hs : copyLoadSafe required L H + · simp only [safeCopyIncrement,safeCopyVarianceRate,ite_eq_left hs] + exact pmf_variance_of_loss_range (step H) (copyCount required) (copyCount required H) + (3*L) (fun A hA => copyCount_step_loss_range required H A L hL.le hs hA) + · simp only [safeCopyIncrement,safeCopyVarianceRate,ite_eq_right hs,zero_pow (by decide : 2 ≠ 0), + pmfMean_const,le_refl] + · exact hr + · exact hV + +def pastCopyLoadsSafe {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L : ℝ) (T j : ℕ) (ω : History (Graph n) T) : Prop := + ∀ s < min j T, copyLoadSafe required L (ω (historyIndex T s)) + +lemma safeCopyNoise_eq {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L : ℝ) (T j : ℕ) (ω : History (Graph n) T) + (hs : pastCopyLoadsSafe required L T j ω) : + historyAdditive (safeCopyIncrement required L) T j ω = + historyNoise (fun _ => step) (fun _ => copyCount required) T j ω := by + classical + unfold historyAdditive historyNoise + apply Finset.sum_congr rfl + intro s hsm + simp only [historyIncrement,safeCopyIncrement,ite_eq_left (hs s (Finset.mem_range.mp hsm))] + +lemma safeCopyCounter_eq {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L : ℝ) (T j : ℕ) (ω : History (Graph n) T) + (hs : pastCopyLoadsSafe required L T j ω) : + historyCounter (safeCopyVarianceRate required L) T j ω = + historyCounter (copyVarianceRate required L) T j ω := by + classical + unfold historyCounter + apply Finset.sum_congr rfl + intro s hsm + simp only [safeCopyVarianceRate,ite_eq_left (hs s (Finset.mem_range.mp hsm))] + +open Classical in + +theorem triangle_template_before_load_exit {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L : ℝ) (hL : 0 < L) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ j ≤ T, pastCopyLoadsSafe required L T j ω ∧ + r ≤ historyNoise (fun _ => step) (fun _ => copyCount required) T j ω ∧ + historyCounter (copyVarianceRate required L) T j ω ≤ V then 1 else 0) ≤ + (T+1 : ℝ)*Real.exp (-r^2/(4*(V+(3*L)*r))) := by + apply le_trans _ (triangle_safe_template_freedman required G T L hL r V hr hV) + apply pmfMean_mono + intro ω _ + by_cases h : ∃ j ≤ T, pastCopyLoadsSafe required L T j ω ∧ + r ≤ historyNoise (fun _ => step) (fun _ => copyCount required) T j ω ∧ + historyCounter (copyVarianceRate required L) T j ω ≤ V + · obtain ⟨j,hj,hs,hn,hc⟩ := h + have h' : ∃ j ≤ T, r ≤ historyAdditive (safeCopyIncrement required L) T j ω ∧ + historyCounter (safeCopyVarianceRate required L) T j ω ≤ V := by + refine ⟨j,hj,?_,?_⟩ + · rwa [safeCopyNoise_eq required L T j ω hs] + · rwa [safeCopyCounter_eq required L T j ω hs] + rw [ite_eq_left ⟨j,hj,hs,hn,hc⟩,ite_eq_left h'] + · rw [ite_eq_right h] + split <;> norm_num + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/DivergentArms.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/DivergentArms.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a87b7ca038e8c840478a70bf24aad62a7d59f52 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/DivergentArms.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.PairVisitProbability +import OAI.Combinatorics.TriangleRemoval.Probability.RootPathVisitProbability +import OAI.Combinatorics.TriangleRemoval.Probability.RootPairVisitProbability2 + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma factorial_weight_add_le {x : ℝ} (hx : 0 ≤ x) (i j : ℕ) : + x^(i+j)/(Nat.factorial (i+j) : ℝ) ≤ + (x^i/(i.factorial : ℝ))*(x^j/(j.factorial : ℝ)) := by + have hf : (i.factorial : ℝ)*(j.factorial : ℝ) ≤ ((i+j).factorial : ℝ) := by + exact_mod_cast Nat.le_of_dvd (Nat.factorial_pos (i+j)) + (Nat.factorial_mul_factorial_dvd_factorial_add i j) + rw [pow_add,div_mul_div_comm] + exact div_le_div_of_nonneg_left (mul_nonneg (pow_nonneg hx _) (pow_nonneg hx _)) + (mul_pos (by positivity) (by positivity)) hf + +lemma cube_ge_self {C : ℝ} (hC : 1 ≤ C) : C ≤ C^3 := by nlinarith [sq_nonneg (C-1)] +lemma cube_ge_sq {C : ℝ} (hC : 1 ≤ C) : C^2 ≤ C^3 := by + have h := mul_le_mul_of_nonneg_left hC (sq_nonneg C) + nlinarith + +def DivergentArms {A : Type*} (p q : List A) : Prop := + match p,q with + | a :: _, b :: _ => a ≠ b + | _,_ => True + +section ActualPairFactorial +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +lemma actualPairVisitProbability_le_left (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (p q : List (ι × τ)) : + actualPairVisitProbability H N d k focus parent p q ≤ + actualPathVisitProbability H N d k focus parent p := by + unfold actualPairVisitProbability actualPathVisitProbability + apply pmf_boolean_map_le + intro z _ h + exact (Bool.and_eq_true_iff.mp h).1 + +lemma actualPairVisitProbability_le_right (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (p q : List (ι × τ)) : + actualPairVisitProbability H N d k focus parent p q ≤ + actualPathVisitProbability H N d k focus parent q := by + unfold actualPairVisitProbability actualPathVisitProbability + apply pmf_boolean_map_le + intro z _ h + exact (Bool.and_eq_true_iff.mp h).2 + +theorem actualPairVisitProbability_pattern_factorial (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 1 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (spine left right : List (ι × τ)) (hdiv : DivergentArms left right) + (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) + (focus : Finset ι) (parent : Option τ) + (ha : LegalQueryPath H focus parent (spine ++ left)) + (hb' : LegalQueryPath H focus parent (spine ++ right)) + (halen : (spine ++ left).length ≤ d) (hblen : (spine ++ right).length ≤ d) : + actualPairVisitProbability H N d k focus parent (spine ++ left) (spine ++ right) ≤ + C^3 * (prefixWeight (fun t => (2/(N : ℝ))*b t) k ^ + (spine.length+left.length+right.length) / + ((spine.length.factorial : ℝ)*(left.length.factorial : ℝ)*(right.length.factorial : ℝ))) := by + let w := fun t => (2/(N : ℝ))*b t + let x := prefixWeight w k + have hw : ∀ t, 0 ≤ w t := fun t => mul_nonneg (by positivity) (hb t) + have hx : 0 ≤ x := prefixWeight_nonneg hw k + have hc0 : 0 ≤ C := by linarith + have hc3 : 0 ≤ C^3 := pow_nonneg hc0 _ + cases left with + | nil => + have ht := (actualPairVisitProbability_le_right H N d k focus parent (spine ++ []) (spine ++ right)).trans + (actualRootPathVisitProbability_factorial H N b hb hq C hC hlower (spine ++ right) + d k hkd hkN hblen focus parent hb') + have hsplit := factorial_weight_add_le hx spine.length right.length + have hg := mul_le_mul_of_nonneg_left hsplit hc3 + have hf : C*(x^(spine.length+right.length)/((spine.length+right.length).factorial : ℝ)) ≤ + C^3*(x^(spine.length+right.length)/((spine.length+right.length).factorial : ℝ)) := + mul_le_mul_of_nonneg_right (cube_ge_self hC) (by positivity) + apply ht.trans + change C*(x^((spine ++ right).length)/(((spine ++ right).length).factorial : ℝ)) ≤ _ + simp only [List.length_append,List.length_nil,Nat.add_zero,Nat.factorial_zero,Nat.cast_one,mul_one] + apply hf.trans + simpa only [div_mul_div_comm,← pow_add] using hg + | cons a as => + cases right with + | nil => + have ht := (actualPairVisitProbability_le_left H N d k focus parent (spine ++ a :: as) (spine ++ [])).trans + (actualRootPathVisitProbability_factorial H N b hb hq C hC hlower (spine ++ a :: as) + d k hkd hkN halen focus parent ha) + have hsplit := factorial_weight_add_le hx spine.length (a :: as).length + have hg := mul_le_mul_of_nonneg_left hsplit hc3 + have hf : C*(x^(spine.length+(a :: as).length)/((spine.length+(a :: as).length).factorial : ℝ)) ≤ + C^3*(x^(spine.length+(a :: as).length)/((spine.length+(a :: as).length).factorial : ℝ)) := + mul_le_mul_of_nonneg_right (cube_ge_self hC) (by positivity) + apply ht.trans + change C*(x^((spine ++ a :: as).length)/(((spine ++ a :: as).length).factorial : ℝ)) ≤ _ + simp only [List.length_append,List.length_nil,Nat.add_zero,Nat.factorial_zero,Nat.cast_one,mul_one] + apply hf.trans + simpa only [div_mul_div_comm,← pow_add] using hg + | cons a' as' => + have ht := (actualPairVisitProbability_le_marked H N d k focus parent _ _).trans + (rootPairVisitProbability_spine H N b hb hq C hc0 hlower spine a a' hdiv as as' + d k hkd hkN focus parent ha hb' + (by simpa only [List.length_append,List.length_cons] using halen) + (by simpa only [List.length_append,List.length_cons] using hblen)) + have hs := three_segment_weight_le hw spine.length (as.length+1) (as'.length+1) k + have hp := mul_le_mul_of_nonneg_left hs (sq_nonneg C) + have he : C^2 * orderedWeight w spine.length k * orderedWeight w (as.length+1) k * + orderedWeight w (as'.length+1) k = + C^2*(orderedWeight w spine.length k * orderedWeight w (as.length+1) k * + orderedWeight w (as'.length+1) k) := by ring + apply ht.trans + change C^2 * orderedWeight w spine.length k * orderedWeight w (as.length+1) k * + orderedWeight w (as'.length+1) k ≤ _ + rw [he] + apply hp.trans + apply mul_le_mul_of_nonneg_right (cube_ge_sq hC) + exact div_nonneg (pow_nonneg (prefixWeight_nonneg hw k) _) (by positivity) + +end ActualPairFactorial +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeFamilyDegree.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeFamilyDegree.lean new file mode 100644 index 0000000000000000000000000000000000000000..95e55ba03e05cf6c109391ff37f25bc866c4ab51 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeFamilyDegree.lean @@ -0,0 +1,113 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +section RootOverlap +variable {V : Type*} [Fintype V] [DecidableEq V] + +def edgeFamilyDegree (G : Finset (Finset V)) (v : V) : ℕ := + (G.filter (fun e => v ∈ e)).card + +theorem sum_edgeFamilyDegree (G : Finset (Finset V)) + (hG : ∀ e ∈ G, e.card = 2) : ∑ v, edgeFamilyDegree G v = 2 * G.card := by + classical + calc + _ = ∑ v, ∑ e ∈ G, if v ∈ e then 1 else 0 := by + simp only [edgeFamilyDegree, Finset.card_filter] + _ = ∑ e ∈ G, ∑ v, if v ∈ e then 1 else 0 := Finset.sum_comm + _ = ∑ e ∈ G, e.card := by simp + _ = _ := by simp only [Finset.sum_congr rfl hG, Finset.sum_const, smul_eq_mul, mul_comm] + +theorem uniform_root_vertex (G : Finset (Finset V)) (hne : G.Nonempty) (v : V) : + pmfMean (PMF.uniformOfFinset G hne) (fun e => if v ∈ e then 1 else 0) = + (edgeFamilyDegree G v : ℝ) / G.card := by + rw [pmfMean_uniformOfFinset] + congr 1 + simp [edgeFamilyDegree] + +theorem uniform_root_pair_vertex (G : Finset (Finset V)) (hne : G.Nonempty) (v : V) : + pmfMean (PMF.uniformOfFinset G hne) (fun e => + pmfMean (PMF.uniformOfFinset G hne) (fun f => if v ∈ e ∧ v ∈ f then 1 else 0)) = + (edgeFamilyDegree G v : ℝ) ^ 2 / (G.card : ℝ) ^ 2 := by + have hi (e : Finset V) : + pmfMean (PMF.uniformOfFinset G hne) (fun f => if v ∈ e ∧ v ∈ f then 1 else 0) = + (if v ∈ e then 1 else 0) * ((edgeFamilyDegree G v : ℝ) / G.card) := by + by_cases he : v ∈ e + · simpa [he] using uniform_root_vertex G hne v + · simp [he] + simp_rw [hi] + rw [pmfMean_mul_const, uniform_root_vertex] + ring + +noncomputable def rootOverlap (G : Finset (Finset V)) (hne : G.Nonempty) : ℝ := by + classical + exact pmfMean (PMF.uniformOfFinset G hne) (fun e => + pmfMean (PMF.uniformOfFinset G hne) (fun f => if ¬Disjoint e f then 1 else 0)) + +theorem rootOverlap_le_degree_sum (G : Finset (Finset V)) (hne : G.Nonempty) : + rootOverlap G hne ≤ (∑ v, (edgeFamilyDegree G v : ℝ) ^ 2) / (G.card : ℝ) ^ 2 := by + classical + have hpt (e f : Finset V) : + (if ¬Disjoint e f then (1 : ℝ) else 0) ≤ + ∑ v : V, if v ∈ e ∧ v ∈ f then (1 : ℝ) else 0 := by + by_cases h : Disjoint e f + · simp only [h, not_true_eq_false, ite_false] + exact Finset.sum_nonneg (fun _ _ => by split_ifs <;> norm_num) + · obtain ⟨v, hv, hv'⟩ := Finset.not_disjoint_iff.mp h + simp only [h, not_false_eq_true, ite_true] + have hh := Finset.single_le_sum (f := fun x => if x ∈ e ∧ x ∈ f then (1 : ℝ) else 0) + (s := Finset.univ) (a := v) (fun _ _ => by split_ifs <;> norm_num) (Finset.mem_univ v) + simpa only [hv, hv', and_self, ite_true] using hh + calc + rootOverlap G hne ≤ pmfMean (PMF.uniformOfFinset G hne) (fun e => + pmfMean (PMF.uniformOfFinset G hne) (fun f => + ∑ v : V, if v ∈ e ∧ v ∈ f then (1 : ℝ) else 0)) := by + apply pmfMean_mono + intro e _ + apply pmfMean_mono + intro f _ + exact hpt e f + _ = _ := by + simp_rw [pmfMean_sum] + simp_rw [uniform_root_pair_vertex] + exact (Finset.sum_div _ _ _).symm + +theorem rootOverlap_le_maxDegree (G : Finset (Finset V)) (hne : G.Nonempty) + (hG : ∀ e ∈ G, e.card = 2) (Δ : ℝ) + (hΔ : ∀ v, (edgeFamilyDegree G v : ℝ) ≤ Δ) : + rootOverlap G hne ≤ 2 * Δ / G.card := by + have hm : (0 : ℝ) < G.card := Nat.cast_pos.mpr hne.card_pos + have hd : (∑ v, (edgeFamilyDegree G v : ℝ)) = 2 * (G.card : ℝ) := by + exact_mod_cast sum_edgeFamilyDegree G hG + have hs : (∑ v, (edgeFamilyDegree G v : ℝ) ^ 2) ≤ Δ * (2 * (G.card : ℝ)) := by + rw [← hd, Finset.mul_sum] + apply Finset.sum_le_sum + intro v _ + rw [pow_two] + exact mul_le_mul_of_nonneg_right (hΔ v) (show (0 : ℝ) ≤ edgeFamilyDegree G v by positivity) + calc + _ ≤ _ := rootOverlap_le_degree_sum G hne + _ ≤ Δ * (2 * (G.card : ℝ)) / (G.card : ℝ) ^ 2 := + div_le_div_of_nonneg_right hs (sq_nonneg _) + _ = _ := by field_simp + +end RootOverlap +end SharpTerminalLeave + +open Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeIncidence.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeIncidence.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0712718db8e1e6ce95eea0a1df8612d8b1c8efa --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeIncidence.lean @@ -0,0 +1,78 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.LinkStarMatrix +import OAI.Combinatorics.TriangleRemoval.Spectral.ExtendStarApply +import OAI.Combinatorics.TriangleRemoval.Process.IncidenceDegree + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators NNReal +open Matrix InnerProductSpace +open scoped BigOperators +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix +open scoped BigOperators Topology NNReal Matrix.Norms.Operator +open MeasureTheory + +namespace SharpTerminalLeave +open scoped Matrix.Norms.Operator + +noncomputable def edgeIncidence {n : ℕ} (G : Graph n) : Matrix G (Fin n) ℝ := + fun e u => if u ∈ e.val then 1 else 0 + +theorem edgeIncidence_nonneg {n : ℕ} (G : Graph n) (e : G) (u : Fin n) : + 0 ≤ edgeIncidence G e u := by simp [edgeIncidence]; split_ifs <;> norm_num + +theorem edgeIncidence_idem {n : ℕ} (G : Graph n) (e : G) (u : Fin n) : + edgeIncidence G e u * edgeIncidence G e u = edgeIncidence G e u := by + simp [edgeIncidence] + +theorem edgeIncidence_row {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (e : G) : + ∑ u, edgeIncidence G e u = 2 := by + simp only [edgeIncidence,Finset.sum_boole] + have hh : Finset.univ.filter (fun u => u ∈ e.val) = e.val := by ext; simp + rw [hh,mem_completeGraph.mp (hG e.property)] + norm_num + +theorem edgeIncidence_degree {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) : + incidenceDegree (edgeIncidence G) u = currentDegree G u := by + simp only [incidenceDegree,edgeIncidence,Finset.sum_boole] + change ((edgeStar G u).card : ℝ) = _ + rw [edgeStar_card G hG u] + +theorem globalStarAverage_factorization {n : ℕ} (G : Graph n) + (hG : G ⊆ completeGraph n) : + globalStarAverage G = edgeIncidence G * starAverage (edgeIncidence G) := by + ext e f + simp only [globalStarAverage,Matrix.sum_apply,Matrix.mul_apply] + apply Finset.sum_congr rfl + intro u _ + rw [extendStar_apply] + simp only [starAverage,edgeIncidence_degree G hG,edgeIncidence] + have hc : Fintype.card (edgeStar G u) = currentDegree G u := by + simpa only [Fintype.card_coe] using edgeStar_card G hG u + simp only [averagingProjector,hc] + by_cases he : u ∈ e.val <;> by_cases hf : u ∈ f.val <;> simp [he,hf,one_div] + +theorem graph_star_semigroup_bound {n : ℕ} [NeZero n] (G : Graph n) + [Nonempty G] (hG : G ⊆ completeGraph n) (hdeg : ∀ u, 0 < currentDegree G u) + (s : ℝ) (hs : 0 ≤ s) : + ‖NormedSpace.exp ((-s) • globalStarAverage G)‖ ≤ 1 + 2*s := by + rw [globalStarAverage_factorization G hG] + apply star_semigroup_bound _ (edgeIncidence_nonneg G) (edgeIncidence_idem G) + (edgeIncidence_row G hG) _ s hs + intro u + rw [edgeIncidence_degree G hG] + exact_mod_cast hdeg u + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeMatching.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeMatching.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d3dbff379410d636d5f9ea071a045bffbdbf7ad --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgeMatching.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def EdgeMatching {V : Type*} [DecidableEq V] (E : Finset (Finset V)) : Prop := + (∀ e ∈ E, e.card = 2) ∧ ∀ e ∈ E, ∀ f ∈ E, e ≠ f → Disjoint e f + +namespace EdgeMatching +variable {V : Type*} [DecidableEq V] {E : Finset (Finset V)} + +lemma singleton (e : Finset V) (he : e.card = 2) : EdgeMatching {e} := by + constructor + · intro f hf + simpa only [Finset.mem_singleton.mp hf] using he + · intro f hf g hg hfg + exact False.elim (hfg ((Finset.mem_singleton.mp hf).trans (Finset.mem_singleton.mp hg).symm)) + +lemma pair (e f : Finset V) (he : e.card = 2) (hf : f.card = 2) + (hd : Disjoint e f) : EdgeMatching {e,f} := by + constructor + · intro g hg + rcases Finset.mem_insert.mp hg with h | h + · simpa only [h] using he + · simpa only [Finset.mem_singleton.mp h] using hf + · intro a ha b hb hab + simp only [Finset.mem_insert,Finset.mem_singleton] at ha hb + rcases ha with rfl | rfl <;> rcases hb with rfl | rfl + · exact False.elim (hab rfl) + · exact hd + · exact hd.symm + · exact False.elim (hab rfl) + +lemma unique_neighbor (hE : EdgeMatching E) {x y z : V} + (hx : {x,z} ∈ E) (hy : {y,z} ∈ E) : x = y := by + have hxz : x ≠ z := by + intro he + have hc := hE.1 _ hx + simp [he] at hc + have he : ({x,z} : Finset V) = {y,z} := by + by_contra hn + exact (Finset.disjoint_left.mp (hE.2 _ hx _ hy hn) (show z ∈ ({x,z} : Finset V) by simp) + (show z ∈ ({y,z} : Finset V) by simp)) + have hm : x ∈ ({y,z} : Finset V) := he ▸ (by simp) + exact (Finset.mem_insert.mp hm).resolve_right (by simpa using hxz) + +end EdgeMatching + +noncomputable def matchingSeed {V : Type*} [DecidableEq V] {N R : ℕ} + (label : Fin N → V) (E : Finset (Finset V)) (hE : EdgeMatching E) + (hi : Set.InjOn label {v | v.val < R}) : BirthGraph N where + older v := Finset.univ.filter (fun u => v.val < R ∧ u < v ∧ {label u,label v} ∈ E) + older_lt := by + intro v u hu + exact (Finset.mem_filter.mp hu).2.2.1 + older_card := by + intro v + apply (Finset.card_le_one.mpr ?_).trans (show 1 ≤ 2 by omega) + intro x hx y hy + obtain ⟨_,hv,hxv,hxe⟩ := Finset.mem_filter.mp hx + obtain ⟨_,_,hyv,hye⟩ := Finset.mem_filter.mp hy + apply hi (show x.val < R by exact lt_trans hxv hv) + (show y.val < R by exact lt_trans hyv hv) + exact hE.unique_neighbor hxe hye + +section MatchingSeed +variable {V : Type*} [DecidableEq V] {N R : ℕ} +variable (label : Fin N → V) (E : Finset (Finset V)) (hE : EdgeMatching E) +variable (hi : Set.InjOn label {v | v.val < R}) + +@[simp] lemma matchingSeed_mem_older (v u : Fin N) : + u ∈ (matchingSeed label E hE hi).older v ↔ + v.val < R ∧ u < v ∧ {label u,label v} ∈ E := by + simp only [matchingSeed,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma matchingSeed_small (v : Fin N) : ((matchingSeed label E hE hi).older v).card ≤ 1 := by + apply Finset.card_le_one.mpr + intro x hx y hy + obtain ⟨hv,hxv,hxe⟩ := (matchingSeed_mem_older _ _ _ _ _ _).mp hx + obtain ⟨_,hyv,hye⟩ := (matchingSeed_mem_older _ _ _ _ _ _).mp hy + exact hi (show x.val < R by exact lt_trans hxv hv) + (show y.val < R by exact lt_trans hyv hv) (hE.unique_neighbor hxe hye) + +lemma matchingSeed_root (v u : Fin N) (hu : u ∈ (matchingSeed label E hE hi).older v) : + u.val < R := by + obtain ⟨hv,huv,_⟩ := (matchingSeed_mem_older _ _ _ _ _ _).mp hu + exact lt_trans huv hv + +lemma matchingSeed_labels (G : SimpleGraph V) + (hl : ∀ e ∈ E, ∀ x ∈ e, ∀ y ∈ e, x ≠ y → G.Adj x y) + (v u : Fin N) (hu : u ∈ (matchingSeed label E hE hi).older v) : + G.Adj (label u) (label v) := by + obtain ⟨hv,huv,he⟩ := (matchingSeed_mem_older _ _ _ _ _ _).mp hu + have hne : label u ≠ label v := fun h => (ne_of_lt huv) (hi (show u.val < R from lt_trans huv hv) hv h) + exact hl _ he _ (by simp) _ (by simp) hne + +lemma matchingSeed_covers + (hc : ∀ e ∈ E, ∀ x ∈ e, ∃ v : Fin N, v.val < R ∧ label v = x) + (e : Finset V) (he : e ∈ E) : + ∃ x y : Fin N, x.val < R ∧ y.val < R ∧ + (matchingSeed label E hE hi).graph.Adj x y ∧ e = {label x,label y} := by + obtain ⟨a,b,hab,rfl⟩ := Finset.card_eq_two.mp (hE.1 e he) + obtain ⟨x,hx,hxa⟩ := hc _ he a (by simp) + obtain ⟨y,hy,hyb⟩ := hc _ he b (by simp) + have hxy : x ≠ y := fun heq => hab ((hxa.symm.trans (congrArg label heq)).trans hyb) + refine ⟨x,y,hx,hy,?_,by rw [hxa,hyb]⟩ + rcases lt_or_gt_of_ne hxy with hlt | hgt + · exact Or.inl ((matchingSeed_mem_older _ _ _ _ _ _).mpr ⟨hy,hlt,by simpa [hxa,hyb] using he⟩) + · exact Or.inr ((matchingSeed_mem_older _ _ _ _ _ _).mpr ⟨hx,hgt,by + simpa [hxa,hyb,Finset.pair_comm] using he⟩) + +end MatchingSeed +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgePairNe.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgePairNe.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ba3a0a0fd83804803da4da93669e90fb8c1efe3 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/EdgePairNe.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PowersetCardTriple +import OAI.Combinatorics.TriangleRemoval.Spectral.LinkStarMatrix +import OAI.Combinatorics.TriangleRemoval.Spectral.ExtendStarApply + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma edge_pair_ne {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + {u v : Fin n} (h : {u,v} ∈ G) : u ≠ v := by + intro he + have hh := mem_completeGraph.mp (hG h) + simp [he] at hh + +lemma star_pair_triangle_iff {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + (u : Fin n) (v w : neighbors G u) : + ({u,v.val} : Finset (Fin n)) ≠ {u,w.val} ∧ + ({u,v.val} ∪ {u,w.val} : Finset (Fin n)) ∈ triangles G ↔ {v.val,w.val} ∈ G := by + have hv : ({u,v.val} : Finset (Fin n)) ∈ G := (Finset.mem_filter.mp v.property).2 + have hw : ({u,w.val} : Finset (Fin n)) ∈ G := (Finset.mem_filter.mp w.property).2 + have huv := edge_pair_ne hG hv + have huw := edge_pair_ne hG hw + have hu : ({u,v.val} ∪ {u,w.val} : Finset (Fin n)) = {u,v.val,w.val} := by + ext x; simp + rw [hu] + constructor + · rintro ⟨hne,ht⟩ + have hvw : v.val ≠ w.val := by intro he; exact hne (by rw [he]) + exact (mem_triangles.mp ht).2 (Finset.mem_powersetCard.mpr + ⟨by intro x hx; simp only [Finset.mem_insert,Finset.mem_singleton] at hx ⊢; tauto, + Finset.card_pair hvw⟩) + · intro hvw + constructor + · intro he + have hh : v.val = w.val := congrArg Subtype.val + (neighborEdge_injective G u (a₁ := v) (a₂ := w) (by + apply Subtype.ext; apply Subtype.ext; exact he)) + exact edge_pair_ne hG hvw hh + · exact (triangle_closure_iff hG huv + ((mem_commonNeighbors G u v.val w.val).mpr ⟨hw,hvw⟩)).mpr hv + +lemma extended_link_entry {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (u : Fin n) (e f : G) : + extendStar (edgeStar G u) (linkStarMatrix G hG u) e f = + if u ∈ e.val ∧ u ∈ f.val ∧ e ≠ f ∧ e.val ∪ f.val ∈ triangles G then 1 else 0 := by + classical + by_cases he : e ∈ edgeStar G u + · by_cases hf : f ∈ edgeStar G u + · let v := (neighborEdgeEquiv G hG u).symm ⟨e,he⟩ + let w := (neighborEdgeEquiv G hG u).symm ⟨f,hf⟩ + have hev : (neighborEdge G u v).val = e := by + exact congrArg Subtype.val ((neighborEdgeEquiv G hG u).apply_symm_apply ⟨e,he⟩) + have hfw : (neighborEdge G u w).val = f := by + exact congrArg Subtype.val ((neighborEdgeEquiv G hG u).apply_symm_apply ⟨f,hf⟩) + rw [extendStar_apply,dite_eq_left he,dite_eq_left hf] + change (if {v.val,w.val} ∈ G then (1 : ℝ) else 0) = _ + have her : u ∈ e.val := (mem_edgeStar _ _ _).mp he + have hfr : u ∈ f.val := (mem_edgeStar _ _ _).mp hf + simp only [her,hfr,true_and] + congr 1 + rw [← hev,← hfw] + apply propext + change ({v.val,w.val} ∈ G) ↔ + ((⟨{u,v.val},_⟩ : G) ≠ ⟨{u,w.val},_⟩ ∧ ({u,v.val} ∪ {u,w.val}) ∈ triangles G) + simpa only [ne_eq,Subtype.mk.injEq] using (star_pair_triangle_iff hG u v w).symm + · have hfr : u ∉ f.val := by simpa only [mem_edgeStar] using hf + simp [extendStar_apply,hf,hfr] + · have her : u ∉ e.val := by simpa only [mem_edgeStar] using he + simp [extendStar_apply,he,her] + +theorem globalLinkAdjacency_entry {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (e f : G) : globalLinkAdjacency G hG e f = + if e ≠ f ∧ e.val ∪ f.val ∈ triangles G then 1 else 0 := by + classical + simp only [globalLinkAdjacency,Matrix.sum_apply,extended_link_entry] + by_cases hh : e ≠ f ∧ e.val ∪ f.val ∈ triangles G + · have he := mem_completeGraph.mp (hG e.property) + have hf := mem_completeGraph.mp (hG f.property) + have hu := (mem_triangles.mp hh.2).1 + have hc := Finset.card_union_add_card_inter e.val f.val + have hi : (e.val ∩ f.val).card = 1 := by omega + have hs : ∑ u : Fin n, (if u ∈ e.val ∧ u ∈ f.val then (1 : ℝ) else 0) = 1 := by + simp only [← Finset.mem_inter,Finset.sum_boole] + have heq : Finset.univ.filter (fun u => u ∈ e.val ∩ f.val) = e.val ∩ f.val := by ext; simp + rw [heq,hi] + norm_num + simpa [hh.1,hh.2] using hs + · have hx : ∀ u, ¬(u ∈ e.val ∧ u ∈ f.val ∧ e ≠ f ∧ e.val ∪ f.val ∈ triangles G) := + fun _ h => hh h.2.2 + rw [ite_eq_right hh] + calc + _ = ∑ _u : Fin n, (0 : ℝ) := Finset.sum_congr rfl (fun u _ => ite_eq_right (hx u)) + _ = 0 := Finset.sum_const_zero + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/EigenProjector.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/EigenProjector.lean new file mode 100644 index 0000000000000000000000000000000000000000..f20137334f37f015846ff651bbe8d7ab49d069d7 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/EigenProjector.lean @@ -0,0 +1,81 @@ +import Mathlib + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix + +namespace SharpTerminalLeave + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +theorem hermitian_trace_pow (A : Matrix ι ι ℝ) (hA : A.IsHermitian) (r : ℕ) : + (A ^ r).trace = ∑ i, hA.eigenvalues i ^ r := by + conv_lhs => rw [hA.spectral_theorem] + rw [← map_pow, Unitary.conjStarAlgAut_apply] + rw [Matrix.trace_mul_cycle, Unitary.coe_star_mul_self, + Matrix.one_mul, Matrix.diagonal_pow, Matrix.trace_diagonal] + rfl + +theorem eigenvalue_tail_of_trace (A : Matrix ι ι ℝ) (hA : A.IsHermitian) + (i₀ : ι) (r : ℕ) (hr : Even r) (hr0 : r ≠ 0) (a θ : ℝ) + (ha : 0 ≤ a) (hθ : 0 ≤ θ) (hlead : a ≤ hA.eigenvalues i₀) + (htrace : (A ^ r).trace ≤ a ^ r + θ ^ r) : + ∀ i, i ≠ i₀ → |hA.eigenvalues i| ≤ θ := by + intro i hi + have heig : ∀ j, 0 ≤ hA.eigenvalues j ^ r := fun j => hr.pow_nonneg _ + have hsum : hA.eigenvalues i₀ ^ r + hA.eigenvalues i ^ r ≤ + ∑ j, hA.eigenvalues j ^ r := by + calc + _ = ∑ j ∈ ({i₀, i} : Finset ι), hA.eigenvalues j ^ r := by + simp [Ne.symm hi] + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun j _ _ => heig j) + have hpow : |hA.eigenvalues i| ^ r ≤ θ ^ r := by + rw [hr.pow_abs] + have hlead' := pow_le_pow_left₀ ha hlead r + rw [hermitian_trace_pow A hA r] at htrace + linarith + exact (pow_le_pow_iff_left₀ (abs_nonneg _) hθ hr0).mp hpow + +noncomputable def eigenProjector (A : Matrix ι ι ℝ) (hA : A.IsHermitian) (i : ι) : + Matrix ι ι ℝ := + Unitary.conjStarAlgAut ℝ _ hA.eigenvectorUnitary + (Matrix.diagonal (Pi.single i (1 : ℝ))) + +theorem eigenProjector_approximation (A : Matrix ι ι ℝ) (hA : A.IsHermitian) + (i₀ : ι) (θ : ℝ) (hθ : 0 ≤ θ) + (htail : ∀ i, i ≠ i₀ → |hA.eigenvalues i| ≤ θ) : + ‖A - hA.eigenvalues i₀ • eigenProjector A hA i₀‖ ≤ θ := by + have heq : A - hA.eigenvalues i₀ • eigenProjector A hA i₀ = + Unitary.conjStarAlgAut ℝ _ hA.eigenvectorUnitary + (Matrix.diagonal (fun i => if i = i₀ then 0 else hA.eigenvalues i)) := by + conv_lhs => lhs; rw [hA.spectral_theorem] + rw [eigenProjector, ← map_smul, ← map_sub, ← Matrix.diagonal_smul, + Matrix.diagonal_sub] + congr 2 + ext i + by_cases hi : i = i₀ <;> simp [hi] + rw [heq, Unitary.conjStarAlgAut_apply, ← Unitary.coe_star, CStarRing.norm_mul_coe_unitary, + CStarRing.norm_coe_unitary_mul, Matrix.l2_opNorm_diagonal] + apply (pi_norm_le_iff_of_nonneg hθ).mpr + intro i + by_cases hi : i = i₀ + · simp [hi, hθ] + · simpa [hi] using htail i hi + +end SharpTerminalLeave + +open scoped BigOperators NNReal +open Matrix + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/EigenvalueAbsRowsum.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/EigenvalueAbsRowsum.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab6b6728727e9b63c336f34131ea6712cd68c436 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/EigenvalueAbsRowsum.lean @@ -0,0 +1,87 @@ +import Mathlib + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators Matrix.Norms.L2Operator +open scoped BigOperators NNReal +open Matrix + +namespace SharpTerminalLeave + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + +open scoped Matrix.Norms.Operator in + +theorem eigenvalue_abs_le_rowsum (A : Matrix ι ι ℝ) (hA : A.IsHermitian) + (a : ℝ) (ha : 0 ≤ a) (hrow : ∀ i, ∑ j, |A i j| ≤ a) (i : ι) : + |hA.eigenvalues i| ≤ a := by + have hnorm : ‖A‖ ≤ a := by + rw [Matrix.linfty_opNorm_def] + have hh : (Finset.univ.sup fun i => ∑ j, ‖A i j‖₊) ≤ (⟨a, ha⟩ : ℝ≥0) := by + apply Finset.sup_le + intro i _ + apply NNReal.coe_le_coe.mp + change (↑(∑ j, ‖A i j‖₊) : ℝ) ≤ a + simpa only [NNReal.coe_sum, coe_nnnorm, Real.norm_eq_abs] using hrow i + exact_mod_cast hh + exact (spectrum.norm_le_norm_of_mem (hA.eigenvalues_mem_spectrum_real i)).trans hnorm + +omit [Nonempty ι] in + +theorem hermitian_upper_posSemidef (A : Matrix ι ι ℝ) (hA : A.IsHermitian) + (a : ℝ) (ha : ∀ i, hA.eigenvalues i ≤ a) : (a • 1 - A).PosSemidef := by + have hd : (Matrix.diagonal (fun i => a - hA.eigenvalues i)).PosSemidef := by + exact Matrix.posSemidef_diagonal_iff.mpr (fun i => sub_nonneg.mpr (ha i)) + have heq : a • 1 - A = + Unitary.conjStarAlgAut ℝ _ hA.eigenvectorUnitary + (Matrix.diagonal (fun i => a - hA.eigenvalues i)) := by + rw [← Matrix.diagonal_sub] + change _ = Unitary.conjStarAlgAut ℝ _ hA.eigenvectorUnitary + (Matrix.diagonal (fun _ => a) - Matrix.diagonal hA.eigenvalues) + rw [map_sub] + have hspec : A = Unitary.conjStarAlgAut ℝ _ hA.eigenvectorUnitary + (Matrix.diagonal hA.eigenvalues) := hA.spectral_theorem + rw [← hspec] + congr 1 + have hdia : Matrix.diagonal (fun _ : ι => a) = a • (1 : Matrix ι ι ℝ) := by + ext i j + simp [Matrix.diagonal_apply, Matrix.one_apply] + rw [hdia, map_smul, map_one] + rw [heq, Unitary.conjStarAlgAut_apply] + exact hd.mul_mul_conjTranspose_same _ + +theorem exists_leading_of_rowsums (A : Matrix ι ι ℝ) (hA : A.IsHermitian) + (a b : ℝ) (hb : 0 ≤ b) + (hlower : ∀ i, a ≤ ∑ j, A i j) (hupper : ∀ i, ∑ j, |A i j| ≤ b) : + ∃ i₀, a ≤ hA.eigenvalues i₀ ∧ |hA.eigenvalues i₀| ≤ b ∧ + ∀ i, hA.eigenvalues i ≤ hA.eigenvalues i₀ := by + obtain ⟨i₀, _, hi₀⟩ := Finset.exists_max_image Finset.univ hA.eigenvalues + Finset.univ_nonempty + have hm : ∀ i, hA.eigenvalues i ≤ hA.eigenvalues i₀ := fun i => hi₀ i (Finset.mem_univ i) + refine ⟨i₀, ?_, eigenvalue_abs_le_rowsum A hA b hb hupper i₀, hm⟩ + have hpos := (hermitian_upper_posSemidef A hA (hA.eigenvalues i₀) hm).dotProduct_mulVec_nonneg (fun _ => 1) + have heval : (star (fun _ : ι => (1 : ℝ))) ⬝ᵥ + ((hA.eigenvalues i₀ • 1 - A) *ᵥ fun _ => 1) = + (Fintype.card ι : ℝ) * hA.eigenvalues i₀ - ∑ i, ∑ j, A i j := by + simp [dotProduct, Finset.sum_sub_distrib, Matrix.mulVec, Matrix.one_apply] + rw [heval] at hpos + have hl := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hlower i) + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] at hl + have hn : 0 < (Fintype.card ι : ℝ) := Nat.cast_pos.mpr Fintype.card_pos + nlinarith + +end SharpTerminalLeave + +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix InnerProductSpace + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/EvolveBindFinish.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/EvolveBindFinish.lean new file mode 100644 index 0000000000000000000000000000000000000000..a55d6db2480b1a978ade19944c8030da73d8ee40 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/EvolveBindFinish.lean @@ -0,0 +1,88 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.PmfMeanAffineSq + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma evolve_bind_finish {n : ℕ} (G : Graph n) (k : ℕ) : + (evolve G k).bind finish = finish G := by + induction k with + | zero => simp only [evolve,PMF.pure_bind] + | succ k ih => + rw [evolve,PMF.bind_bind] + have hh : (fun H : Graph n => (step H).bind finish) = finish := by + funext H + exact (finish_harmonic H).symm + rw [hh,ih] + +lemma terminalLaw_prefix_disintegration (n : ℕ) : + terminalLaw n = (prefixLaw n).bind finish := by + rw [prefixLaw,evolve_bind_finish] + apply evolve_eq_finish + simp only [completeGraph,Finset.card_powersetCard,Finset.card_univ,Fintype.card_fin,le_refl] + +lemma normalizedLeave_error_envelope {n : ℕ} (hn : 0 < n) {H : Graph n} + (hH : H ⊆ completeGraph n) : + (normalizedLeave n H-sharpConstant)^2 ≤ 2*(n : ℝ)+1 := by + have hcard : (H.card : ℝ) ≤ (n : ℝ)^2 := by + have hh := (Finset.card_le_card hH).trans + (show (completeGraph n).card ≤ n^2 by + simpa only [completeGraph,Finset.card_powersetCard,Finset.card_univ,Fintype.card_fin] + using Nat.choose_le_pow n 2) + exact_mod_cast hh + have hn0 : (0 : ℝ) < n := Nat.cast_pos.mpr hn + have hnorm := normalization_pos hn + have hsq : (normalizedLeave n H)^2 ≤ (n : ℝ) := by + unfold normalizedLeave + rw [div_pow,normalization_sq] + calc + _ ≤ ((n : ℝ)^2)^2/(n : ℝ)^3 := div_le_div_of_nonneg_right + (pow_le_pow_left₀ (Nat.cast_nonneg H.card) hcard 2) (by positivity) + _ = _ := by field_simp + have ha := sharpConstant_sq + nlinarith [sq_nonneg (normalizedLeave n H+sharpConstant)] + +theorem main_l2_prefix_failure_bound (c C : ℝ) (hc : 0 < c) : + ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, + expectation n (fun H => (normalizedLeave n H-sharpConstant)^2) ≤ + δ+(2*(n : ℝ)+1)*prefixFailure n c C := by + classical + intro δ hδ + filter_upwards [goodPrefix_normalized_l2 c C hc δ hδ,eventually_ge_atTop (1 : ℕ)] with n hg hn + have hn0 : 0 < n := by omega + change pmfMean (terminalLaw n) (fun H => (normalizedLeave n H-sharpConstant)^2) ≤ _ + rw [terminalLaw_prefix_disintegration,pmfMean_bind] + calc + _ ≤ pmfMean (prefixLaw n) (fun G => δ+(2*(n : ℝ)+1)* + (if GoodPrefixGraph n c C G then 0 else 1)) := by + apply pmfMean_mono + intro G hG + by_cases hgood : GoodPrefixGraph n c C G + · simp only [ite_eq_left hgood,mul_zero,add_zero] + exact (hg G hgood).le + · simp only [ite_eq_right hgood,mul_one] + have hsub : G ⊆ completeGraph n := evolve_support_subset _ _ hG + have hh : pmfMean (finish G) (fun H => (normalizedLeave n H-sharpConstant)^2) ≤ + 2*(n : ℝ)+1 := by + rw [← pmfMean_const (finish G) (2*(n : ℝ)+1)] + apply pmfMean_mono + intro H hH + exact normalizedLeave_error_envelope hn0 ((finish_support_subset hH).trans hsub) + linarith + _ = _ := by rw [pmfMean_add,pmfMean_const,pmfMean_const_mul]; rfl + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ExtendedLinkMulVec.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ExtendedLinkMulVec.lean new file mode 100644 index 0000000000000000000000000000000000000000..9de96bab6017e0496188789f8ab165b2b0c82b61 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ExtendedLinkMulVec.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.CenteredCodegreeNeighborSum +import OAI.Combinatorics.TriangleRemoval.Spectral.ExtendStarMulVec + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Classical Matrix + +namespace SharpTerminalLeave + +lemma extended_link_mulVec_neighbor {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (u : Fin n) (v : neighbors G u) (z : G → ℝ) : + (extendStar (edgeStar G u) (linkStarMatrix G hG u) *ᵥ z) (neighborEdge G u v).val = + ∑ w : neighbors G u, if {v.val,w.val} ∈ G then z (neighborEdge G u w).val else 0 := by + rw [extendStar_mulVec_apply,dite_eq_left (neighborEdge G u v).property] + simp only [Matrix.mulVec,dotProduct,linkStarMatrix,Matrix.reindex_apply,Matrix.submatrix_apply] + rw [← Equiv.sum_comp (neighborEdgeEquiv G hG u)] + have hev : (⟨(neighborEdge G u v).val,(neighborEdge G u v).property⟩ : edgeStar G u) = + neighborEdgeEquiv G hG u v := rfl + rw [hev] + simp only [Equiv.symm_apply_apply,SimpleGraph.adjMatrix_apply,linkSimpleGraph_adj] + apply Finset.sum_congr rfl + intro w _ + split_ifs <;> simp only [one_mul,zero_mul] + rfl + +lemma neighbor_filtered_sum {n : ℕ} (G : Graph n) (u v : Fin n) (f : Fin n → ℝ) : + (∑ w : neighbors G u, if {v,w.val} ∈ G then f w.val else 0) = + ∑ w ∈ commonNeighbors G u v, f w := by + trans ∑ w ∈ neighbors G u, if {v,w} ∈ G then f w else 0 + · exact Finset.sum_coe_sort (neighbors G u) (fun w : Fin n => if {v,w} ∈ G then f w else 0) + rw [← Finset.sum_filter] + congr 1 + ext w + simp [neighbors,mem_commonNeighbors] + +lemma extended_link_codegree_action {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (u : Fin n) (v : neighbors G u) (s : ℝ) : + (extendStar (edgeStar G u) (linkStarMatrix G hG u) *ᵥ + (fun e : G => (triangleDegree G e.val : ℝ)/s-1)) (neighborEdge G u v).val = + ∑ w ∈ commonNeighbors G u v.val, ((currentCodegree G u w : ℝ)/s-1) := by + rw [extended_link_mulVec_neighbor] + have he : (fun w : neighbors G u => + if {v.val,w.val} ∈ G then (triangleDegree G (neighborEdge G u w).val.val : ℝ)/s-1 else 0) = + (fun w : neighbors G u => if {v.val,w.val} ∈ G then (currentCodegree G u w.val : ℝ)/s-1 else 0) := by + funext w + simp only [neighborEdge,triangleDegree_eq_codegree hG (Finset.mem_filter.mp w.property).2] + rw [he] + exact neighbor_filtered_sum G u v.val (fun w => (currentCodegree G u w : ℝ)/s-1) + +lemma global_link_codegree_action {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (u v : Fin n) (he : {u,v} ∈ G) (s : ℝ) (hs : s ≠ 0) : + (globalLinkAdjacency G hG *ᵥ (fun e : G => (triangleDegree G e.val : ℝ)/s-1)) ⟨{u,v},he⟩ = + centeredCodegreeNeighborSum G u v s/s := by + have huv := edge_pair_ne hG he + let z : G → ℝ := fun e => (triangleDegree G e.val : ℝ)/s-1 + have hz : ∀ a : Fin n, a ∉ ({u,v} : Finset (Fin n)) → + (extendStar (edgeStar G a) (linkStarMatrix G hG a) *ᵥ z) ⟨{u,v},he⟩ = 0 := by + intro a ha + rw [extendStar_mulVec_apply,dite_eq_right] + simpa only [mem_edgeStar] using ha + have heq : (globalLinkAdjacency G hG *ᵥ z) ⟨{u,v},he⟩ = + ∑ a ∈ ({u,v} : Finset (Fin n)), + (extendStar (edgeStar G a) (linkStarMatrix G hG a) *ᵥ z) ⟨{u,v},he⟩ := by + rw [globalLinkAdjacency,Matrix.sum_mulVec,Finset.sum_apply] + exact (Finset.sum_subset (Finset.subset_univ _) (fun a _ ha => hz a ha)).symm + change (globalLinkAdjacency G hG *ᵥ z) _ = _ + rw [heq,Finset.sum_pair huv] + have hvG : ({v,u} : Finset (Fin n)) ∈ G := by simpa only [Finset.pair_comm] using he + have huact := extended_link_codegree_action G hG u + (⟨v,Finset.mem_filter.mpr ⟨Finset.mem_univ _,he⟩⟩ : neighbors G u) s + have hvact := extended_link_codegree_action G hG v + (⟨u,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hvG⟩⟩ : neighbors G v) s + change (extendStar (edgeStar G u) (linkStarMatrix G hG u) *ᵥ z) ⟨{u,v},he⟩ = _ at huact + have hev : (⟨{v,u},hvG⟩ : G) = ⟨{u,v},he⟩ := Subtype.ext (Finset.pair_comm _ _) + change (extendStar (edgeStar G v) (linkStarMatrix G hG v) *ᵥ z) ⟨{v,u},hvG⟩ = _ at hvact + rw [hev] at hvact + rw [huact,hvact] + have hcn : commonNeighbors G v u = commonNeighbors G u v := by + ext w; simp [mem_commonNeighbors,and_comm] + rw [hcn,← Finset.sum_add_distrib,centeredCodegreeNeighborSum,Finset.sum_div] + apply Finset.sum_congr rfl + intro w _ + field_simp + ring + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/FilteredSigmaWeightBound.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/FilteredSigmaWeightBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..b80335aabaa34c973f018a9fc68ee0056f00dce2 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/FilteredSigmaWeightBound.lean @@ -0,0 +1,37 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma filtered_sigma_weight_bound {α : Type*} [Fintype α] {β : α → Type*} + [∀ a, Fintype (β a)] {B w : ℝ} (hB : 0 ≤ B) (hw : 0 ≤ w) : + (∑ z : Sigma β, if (Fintype.card (β z.1) : ℝ) ≤ B then w else 0) ≤ + (Fintype.card α : ℝ)*B*w := by + classical + rw [Fintype.sum_sigma] + calc + _ ≤ ∑ a : α, B*w := by + apply Finset.sum_le_sum + intro a _ + by_cases h : (Fintype.card (β a) : ℝ) ≤ B + · simp only [h,ite_true,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_le_mul_of_nonneg_right h hw + · simp only [h,ite_false,Finset.sum_const_zero] + exact mul_nonneg hB hw + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/Finish.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/Finish.lean new file mode 100644 index 0000000000000000000000000000000000000000..2c44c17757e94a6dda2dbdac356b0a840a140e65 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/Finish.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators +open scoped BigOperators ENNReal Classical + +namespace SharpTerminalLeave + +noncomputable def finish {n : ℕ} (G : Graph n) : PMF (Graph n) := + evolve G G.card + +theorem pmf_bind_congr_support {α β : Type*} (p : PMF α) (f g : α → PMF β) + (h : ∀ a ∈ p.support, f a = g a) : p.bind f = p.bind g := by + apply PMF.ext + intro b + simp only [PMF.bind_apply] + apply tsum_congr + intro a + by_cases ha : a ∈ p.support + · rw [h a ha] + · have hz : p a = 0 := by simpa only [PMF.mem_support_iff, not_not] using ha + simp [hz] + +theorem evolve_eq_finish {n : ℕ} (G : Graph n) (k : ℕ) (hk : G.card ≤ k) : + evolve G k = finish G := by + obtain ⟨l, rfl⟩ := Nat.exists_eq_add_of_le hk + exact evolve_stable G G.card l le_rfl + +theorem finish_absorbing {n : ℕ} (G : Graph n) (hG : triangles G = ∅) : + finish G = PMF.pure G := evolve_absorbing G hG G.card + +theorem finish_harmonic {n : ℕ} (G : Graph n) : + finish G = (step G).bind finish := by + have heq : evolve G (1 + G.card) = (step G).bind (fun H => evolve H G.card) := by + rw [evolve_add] + simp [evolve] + rw [evolve_eq_finish G _ (by omega)] at heq + rw [heq] + apply pmf_bind_congr_support + intro H hH + exact evolve_eq_finish H G.card (Finset.card_le_card (step_support_subset hH)) + +def scanAction {n : ℕ} (G : Graph n) (t : Finset (Fin n)) : Graph n := + if t ∈ triangles G then G \ t.powersetCard 2 else G + +noncomputable def scanLaw {n : ℕ} : ℕ → Graph n → Finset (Finset (Fin n)) → PMF (Graph n) + | 0, G, _ => PMF.pure G + | k + 1, G, C => + if h : C.Nonempty then + (PMF.uniformOfFinset C h).bind (fun t => scanLaw k (scanAction G t) (C.erase t)) + else PMF.pure G + +theorem scanAction_subset {n : ℕ} (G : Graph n) (t : Finset (Fin n)) : + scanAction G t ⊆ G := by + unfold scanAction + split_ifs + · exact Finset.sdiff_subset + · exact Finset.Subset.rfl + +theorem triangle_not_mem_delete {n : ℕ} (G : Graph n) (t : Finset (Fin n)) : + t ∉ triangles (G \ t.powersetCard 2) := by + intro ht + have hc : (t.powersetCard 2).card = 3 := by + simp [(mem_triangles.mp ht).1] + obtain ⟨e, he⟩ := Finset.card_pos.mp (by omega : 0 < (t.powersetCard 2).card) + exact (Finset.mem_sdiff.mp ((mem_triangles.mp ht).2 he)).2 he + +theorem triangles_scanAction_subset {n : ℕ} (G : Graph n) (C : Finset (Finset (Fin n))) + (hC : triangles G ⊆ C) (t : Finset (Fin n)) : + triangles (scanAction G t) ⊆ C.erase t := by + intro u hu + apply Finset.mem_erase.mpr + refine ⟨?_, hC (triangles_mono (scanAction_subset G t) hu)⟩ + intro heq + subst u + by_cases ht : t ∈ triangles G + · exact triangle_not_mem_delete G t (by simpa [scanAction, ht] using hu) + · exact ht (triangles_mono (scanAction_subset G t) hu) + +theorem finish_mean_uniform_candidates {n : ℕ} (G : Graph n) + (C : Finset (Finset (Fin n))) (hC : C.Nonempty) (hall : triangles G ⊆ C) + (f : Graph n → ℝ) : + pmfMean (PMF.uniformOfFinset C hC) (fun t => pmfMean (finish (scanAction G t)) f) = + pmfMean (finish G) f := by + classical + by_cases hG : (triangles G).Nonempty + · let w : ℝ := pmfMean (finish G) f + have hw : ∑ t ∈ triangles G, pmfMean (finish (G \ t.powersetCard 2)) f = + ((triangles G).card : ℝ) * w := by + have hh := congrArg (fun p => pmfMean p f) (finish_harmonic G) + rw [pmfMean_bind, step_mean G _ hG] at hh + have hpos : (0 : ℝ) < (triangles G).card := by exact_mod_cast hG.card_pos + have he := (div_eq_iff hpos.ne').mp hh.symm + simpa only [mul_comm] using he + rw [pmfMean_uniformOfFinset] + have hsplit : C = (triangles G) ∪ (C \ triangles G) := by + exact (Finset.union_sdiff_of_subset hall).symm + have hsum : ∑ t ∈ C, pmfMean (finish (scanAction G t)) f = (C.card : ℝ) * w := by + have hdisj : Disjoint (triangles G) (C \ triangles G) := by + exact Finset.disjoint_left.mpr fun t ht hdiff => (Finset.mem_sdiff.mp hdiff).2 ht + conv_lhs => rw [hsplit] + rw [Finset.sum_union hdisj] + have hfirst : ∑ t ∈ triangles G, pmfMean (finish (scanAction G t)) f = + ((triangles G).card : ℝ) * w := by + calc + _ = ∑ t ∈ triangles G, pmfMean (finish (G \ t.powersetCard 2)) f := by + apply Finset.sum_congr rfl + intro t ht + simp [scanAction, ht] + _ = _ := hw + rw [hfirst] + have hsecond : ∑ t ∈ C \ triangles G, pmfMean (finish (scanAction G t)) f = + ((C \ triangles G).card : ℝ) * w := by + calc + _ = ∑ _t ∈ C \ triangles G, w := Finset.sum_congr rfl fun t ht => by + simp [scanAction, (Finset.mem_sdiff.mp ht).2, w] + _ = _ := by simp + rw [hsecond, Finset.card_sdiff_of_subset hall, Nat.cast_sub (Finset.card_le_card hall)] + ring + rw [hsum] + exact mul_div_cancel_left₀ w (by exact_mod_cast hC.card_pos.ne') + · have ht : triangles G = ∅ := Finset.not_nonempty_iff_eq_empty.mp hG + have heq : (fun t => pmfMean (finish (scanAction G t)) f) = + (fun _ => pmfMean (finish G) f) := by + funext t + simp [scanAction, ht] + rw [heq, pmfMean_const] + +theorem pmf_ext_mean {α : Type*} [Fintype α] (p q : PMF α) + (h : ∀ f : α → ℝ, pmfMean p f = pmfMean q f) : p = q := by + classical + apply PMF.ext + intro a + apply (ENNReal.toReal_eq_toReal_iff' (p.apply_ne_top a) (q.apply_ne_top a)).mp + simpa [pmfMean] using h (fun b => if b = a then 1 else 0) + +theorem scan_mean_eq_finish {n : ℕ} (k : ℕ) (G : Graph n) + (C : Finset (Finset (Fin n))) (hk : C.card ≤ k) (hall : triangles G ⊆ C) + (f : Graph n → ℝ) : pmfMean (scanLaw k G C) f = pmfMean (finish G) f := by + classical + induction k generalizing G C with + | zero => + have hC : C = ∅ := Finset.card_eq_zero.mp (by omega) + have ht : triangles G = ∅ := Finset.subset_empty.mp (hC ▸ hall) + simp [scanLaw, finish_absorbing G ht] + | succ k ih => + by_cases hC : C.Nonempty + · rw [scanLaw, dite_eq_left hC, pmfMean_bind] + calc + _ = pmfMean (PMF.uniformOfFinset C hC) + (fun t => pmfMean (finish (scanAction G t)) f) := by + apply pmfMean_congr + intro t ht + have htC : t ∈ C := by simpa using ht + exact ih (scanAction G t) (C.erase t) + (by rw [Finset.card_erase_of_mem htC]; omega) + (triangles_scanAction_subset G C hall t) + _ = _ := finish_mean_uniform_candidates G C hC hall f + · have hCe : C = ∅ := Finset.not_nonempty_iff_eq_empty.mp hC + have ht : triangles G = ∅ := Finset.subset_empty.mp (hCe ▸ hall) + simp [scanLaw, hC, finish_absorbing G ht] + +theorem scanLaw_eq_finish {n : ℕ} (k : ℕ) (G : Graph n) + (C : Finset (Finset (Fin n))) (hk : C.card ≤ k) (hall : triangles G ⊆ C) : + scanLaw k G C = finish G := + pmf_ext_mean _ _ (scan_mean_eq_finish k G C hk hall) + +theorem scan_complete_eq_terminalLaw (n : ℕ) : + scanLaw (triangles (completeGraph n)).card (completeGraph n) + (triangles (completeGraph n)) = terminalLaw n := by + rw [scanLaw_eq_finish _ _ _ le_rfl (by rfl)] + simp [finish, terminalLaw] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/FinishSupportSubset.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/FinishSupportSubset.lean new file mode 100644 index 0000000000000000000000000000000000000000..3f83bcbaaae652183a8853f5003f9bcd348671d1 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/FinishSupportSubset.lean @@ -0,0 +1,112 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.Finish + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem finish_support_subset {n : ℕ} {G H : Graph n} + (hH : H ∈ (finish G).support) : H ⊆ G := + evolve_support_subset G G.card hH + +theorem uniform_edge_survival {n : ℕ} {G H : Graph n} + (hG : G.Nonempty) (hH : H ⊆ G) : + pmfMean (PMF.uniformOfFinset G hG) (fun e => if e ∈ H then 1 else 0) = + (H.card : ℝ) / G.card := by + classical + rw [pmfMean_uniformOfFinset] + congr 1 + rw [← Finset.sum_filter] + have heq : G.filter (fun e => e ∈ H) = H := Finset.filter_mem_eq_inter |>.trans + (Finset.inter_eq_right.mpr hH) + simp [heq] + +theorem uniform_two_edge_survival {n : ℕ} {G H : Graph n} + (hG : G.Nonempty) (hH : H ⊆ G) : + pmfMean (PMF.uniformOfFinset G hG) (fun e => + pmfMean (PMF.uniformOfFinset G hG) (fun f => + if e ∈ H ∧ f ∈ H then 1 else 0)) = + (H.card : ℝ) ^ 2 / (G.card : ℝ) ^ 2 := by + classical + have hm (e : Finset (Fin n)) : + pmfMean (PMF.uniformOfFinset G hG) + (fun f => if e ∈ H ∧ f ∈ H then 1 else 0) = + (if e ∈ H then 1 else 0) * ((H.card : ℝ) / G.card) := by + by_cases he : e ∈ H + · simpa [he] using uniform_edge_survival hG hH + · simp [he] + simp_rw [hm] + rw [pmfMean_mul_const, uniform_edge_survival hG hH] + ring + +theorem terminal_first_edge_moment {n : ℕ} (G : Graph n) (hG : G.Nonempty) : + pmfMean (finish G) (fun H => + pmfMean (PMF.uniformOfFinset G hG) (fun e => if e ∈ H then 1 else 0)) = + pmfMean (finish G) (fun H => (H.card : ℝ)) / G.card := by + classical + calc + _ = pmfMean (finish G) (fun H => (H.card : ℝ) / G.card) := by + apply pmfMean_congr + intro H hH + exact uniform_edge_survival hG (finish_support_subset hH) + _ = _ := by simp only [div_eq_mul_inv, pmfMean_mul_const] + +theorem terminal_second_edge_moment {n : ℕ} (G : Graph n) (hG : G.Nonempty) : + pmfMean (finish G) (fun H => + pmfMean (PMF.uniformOfFinset G hG) (fun e => + pmfMean (PMF.uniformOfFinset G hG) (fun f => + if e ∈ H ∧ f ∈ H then 1 else 0))) = + pmfMean (finish G) (fun H => (H.card : ℝ) ^ 2) / (G.card : ℝ) ^ 2 := by + classical + calc + _ = pmfMean (finish G) (fun H => (H.card : ℝ) ^ 2 / (G.card : ℝ) ^ 2) := by + apply pmfMean_congr + intro H hH + exact uniform_two_edge_survival hG (finish_support_subset hH) + _ = _ := by simp only [div_eq_mul_inv, pmfMean_mul_const] + +theorem finite_coupling_event_bound {α β : Type*} [Fintype α] [Fintype β] + (p : PMF (α × β)) (A : α → Prop) (B : β → Prop) + [DecidablePred A] [DecidablePred B] : + |pmfMean (p.map Prod.fst) (fun a => if A a then 1 else 0) - + pmfMean (p.map Prod.snd) (fun b => if B b then 1 else 0)| ≤ + pmfMean p (fun ab => if (A ab.1 ↔ B ab.2) then 0 else 1) := by + rw [pmfMean_map, pmfMean_map, ← pmfMean_sub] + apply abs_le.mpr + constructor + · have hh := pmfMean_mono p (f := fun ab => if (A ab.1 ↔ B ab.2) then 0 else 1) + (g := fun ab => -((if A ab.1 then 1 else 0) - (if B ab.2 then 1 else 0))) + have hmono : pmfMean p (fun ab => + -((if A ab.1 then 1 else 0) - (if B ab.2 then 1 else 0))) ≤ + pmfMean p (fun ab => if (A ab.1 ↔ B ab.2) then 0 else 1) := by + apply pmfMean_mono + intro ab _ + by_cases ha : A ab.1 <;> by_cases hb : B ab.2 <;> simp [ha, hb] + have heq : pmfMean p (fun ab => + -((if A ab.1 then 1 else 0) - (if B ab.2 then 1 else 0))) = + -pmfMean p (fun ab => (if A ab.1 then 1 else 0) - (if B ab.2 then 1 else 0)) := by + simpa only [neg_one_mul] using (pmfMean_const_mul p (-1) + (fun ab => (if A ab.1 then 1 else 0) - (if B ab.2 then 1 else 0))) + rw [heq] at hmono + linarith + · apply pmfMean_mono + intro ab _ + by_cases ha : A ab.1 <;> by_cases hb : B ab.2 <;> simp [ha, hb] + +end SharpTerminalLeave + +open Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/FreshMemSelected.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/FreshMemSelected.lean new file mode 100644 index 0000000000000000000000000000000000000000..4a581de6dfc2866ace8c4c9dc858af1359da6090 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/FreshMemSelected.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TriangleThird +import OAI.Combinatorics.TriangleRemoval.Process.Attachment +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth2 + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) +variable (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) + +lemma fresh_mem_selected {V : Type*} [DecidableEq V] {e a : Finset V} {x : V} + (he : e.card = 2) (ha : a.card = 2) (hs : e ⊆ insert x a) (hne : e ≠ a) : x ∈ e := by + by_contra hx + have hh : e ⊆ a := by + intro z hz + exact (Finset.mem_insert.mp (hs hz)).resolve_left (fun he => hx (he ▸ hz)) + exact hne (Finset.eq_of_subset_of_card_le hh (by rw [he,ha])) + +lemma pair_has_other {V : Type*} [DecidableEq V] {e : Finset V} (he : e.card = 2) (x : V) : + ∃ z ∈ e, z ≠ x := by + obtain ⟨a,b,hab,rfl⟩ := Finset.card_eq_two.mp he + by_cases ha : a = x + · exact ⟨b,by simp,ha ▸ hab.symm⟩ + · exact ⟨a,by simp,ha⟩ + +lemma candidate_nonroot_exposed (i : Fin F.size) (hi : i ≠ F.root) + (p : Finset (Fin n) × Finset (Fin n)) + (hp : p ∈ gridCandidates (triangleHypergraph G) (F.call i).focus (F.call i).parent) : + (F.toTriangleGrowth hM hG).birthGraph.ExposedAt (lookupGraph G) F.vertexLabel + (F.birthIndex i hi) p.2 := by + let A := F.toTriangleGrowth hM hG + have hc := (graphCandidate_iff G _ _ _).mp hp + have hf := hc.1 + rw [F.incoming_focus i hi] at hf + obtain ⟨hediff,hepow⟩ := Finset.mem_erase.mp hf + obtain ⟨hes,hec⟩ := Finset.mem_powersetCard.mp hepow + have hes' : p.1 ⊆ insert (F.newVertex i hi) (F.incoming i hi).1 := by + rw [← (F.newVertex_spec i hi).2] + exact hes + have hnew := fresh_mem_selected hec (F.incoming_card i hi) hes' hediff + obtain ⟨z,hze,hzn⟩ := pair_has_other hec (F.newVertex i hi) + have hza : z ∈ (F.incoming i hi).1 := (Finset.mem_insert.mp (hes' hze)).resolve_left hzn + have hv := F.birthIndex_nonroot i hi + have him : (A.older (F.birthIndex i hi)).image F.vertexLabel = (F.incoming i hi).1 := by + have hh := ((A.older_invariants (F.birthIndex i hi)).2 hv).2.1 + change (A.older (F.birthIndex i hi)).image F.vertexLabel = F.attachment (F.birthIndex i hi) at hh + exact hh.trans (F.attachment_birth i hi) + have hfT := (Finset.mem_powersetCard.mp hc.2.2.1).1 + obtain ⟨u,hum,huz⟩ := Finset.mem_image.mp (him.symm ▸ hza) + refine ⟨lookupGraph_triangle hc.2.1,⟨u,hum,?_,?_⟩,?_⟩ + · exact huz.symm ▸ hfT hze + · rw [F.vertexLabel_birth] + exact hfT hnew + · intro _ heq + have hpar := hc.2.2.2 + rw [F.incoming_parent i hi] at hpar + apply hpar + apply congrArg some + have hh := A.parentType_eq (F.birthIndex i hi) hv + change A.birthGraph.parentType F.vertexLabel (F.birthIndex i hi) = + insert (F.vertexLabel (F.birthIndex i hi)) (F.attachment (F.birthIndex i hi)) at hh + rw [F.vertexLabel_birth,F.attachment_birth,← (F.newVertex_spec i hi).2] at hh + exact heq.trans hh + +lemma candidate_root_exposed (p : Finset (Fin n) × Finset (Fin n)) + (hp : p ∈ gridCandidates (triangleHypergraph G) c.focus c.parent) : + ∃ v : Fin F.vertexCount, v.val < F.rootCount ∧ + (F.toTriangleGrowth hM hG).birthGraph.ExposedAt (lookupGraph G) F.vertexLabel v p.2 := by + let A := F.toTriangleGrowth hM hG + have hc := (graphCandidate_iff G _ _ _).mp hp + obtain ⟨x,y,hx,hy,hxy,he⟩ := matchingSeed_covers F.vertexLabel c.focus hM + F.vertexLabel_injective_roots (F.vertexLabel_covers) p.1 hc.1 + have hB : A.birthGraph.graph.Adj x y := (A.root_graph hx hy).mpr hxy + have hfT := (Finset.mem_powersetCard.mp hc.2.2.1).1 + have hxT : F.vertexLabel x ∈ p.2 := hfT (he ▸ by simp) + have hyT : F.vertexLabel y ∈ p.2 := hfT (he ▸ by simp) + have hsmall (v : Fin F.vertexCount) (hv : v.val < F.rootCount) : (A.older v).card ≤ 1 := by + rw [A.older_eq_seed hv] + exact A.seed_small v hv + rcases lt_or_gt_of_ne hB.ne with hlt | hgt + · refine ⟨y,hy,lookupGraph_triangle hc.2.1,⟨x,(A.birthGraph.graph_adj_of_lt hlt).mp hB,hxT,hyT⟩,?_⟩ + intro hc2 _ + have hh := hsmall y hy + change (A.older y).card = 2 at hc2 + omega + · refine ⟨x,hx,lookupGraph_triangle hc.2.1,⟨y,(A.birthGraph.graph_adj_of_lt hgt).mp hB.symm,hyT,hxT⟩,?_⟩ + intro hc2 _ + have hh := hsmall x hx + change (A.older x).card = 2 at hc2 + omega + +end SharpTerminalLeave.RecordedCallForest + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/GraphCardSqrt.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/GraphCardSqrt.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e0b6fff77154e01746a1c522e29c6083a8d4da2 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/GraphCardSqrt.lean @@ -0,0 +1,83 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.GlobalLinkAdjacencyHermitian +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixSpectralErrorPower +import OAI.Combinatorics.TriangleRemoval.Process.PerturbationPolynomialBound + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +open Filter +open scoped Matrix.Norms.Operator + +lemma graph_card_sqrt_le {n : ℕ} {G : Graph n} (h : G ⊆ completeGraph n) : + Real.sqrt G.card ≤ n := by + apply (Real.sqrt_le_left (Nat.cast_nonneg n)).mpr + have hh := Finset.card_le_card h + rw [card_completeGraph,Nat.choose_two_right] at hh + have h' : G.card ≤ n*n := hh.trans ((Nat.div_le_self _ _).trans + (Nat.mul_le_mul_left n (Nat.sub_le n 1))) + simpa only [Nat.cast_mul,pow_two] using (Nat.cast_le.mpr h' : (G.card : ℝ) ≤ (n*n : ℕ)) + +lemma goodPrefix_neighbors_nonempty {n : ℕ} (hn : 0 < n) {c C : ℝ} {G : Graph n} + (h : GoodPrefixGraph n c C G) (hp : 0 < prefixDensity n) + (hδ : (n : ℝ)^(-c) ≤ 1/2) : ∀ u, (neighbors G u).Nonempty := by + intro u + have hnp : 0 < (n : ℝ)*prefixDensity n := mul_pos (Nat.cast_pos.mpr hn) hp + have hl := (abs_le.mp (h.2.2.1 u)).1 + have hm := mul_le_mul_of_nonneg_right hδ hnp.le + have hd : (0 : ℝ) < (currentDegree G u : ℝ) := by linarith + apply Finset.card_pos.mp + exact_mod_cast hd + +theorem goodPrefix_uniform_semigroup {c : ℝ} (hc : 0 < c) : + ∃ C₁ : ℝ, 0 < C₁ ∧ ∃ J : ℕ, ∀ᶠ n : ℕ in atTop, + ∀ (C : ℝ) (G : Graph n) (h : GoodPrefixGraph n c C G), + ∀ s ∈ Set.Icc (0 : ℝ) (Real.log n), + ‖NormedSpace.exp ((-s) • ((prefixD n)⁻¹ • globalLinkAdjacency G h.1))‖ ≤ + C₁*(1+Real.log n)^J := by + obtain ⟨γ,hγ,hdec⟩ := prefixSpectralError_power_decay hc + obtain ⟨K,hK⟩ := exists_nat_gt (4/γ) + let A : ℝ := 2*(K : ℝ)*12^K + have hA : 0 ≤ A := by dsimp [A]; positivity + refine ⟨A+1,by linarith,2*K+1,?_⟩ + have hδ := ((tendsto_rpow_neg_atTop hc).comp + (tendsto_natCast_atTop_atTop (R := ℝ))).eventually_le_const + (by norm_num : (0 : ℝ) < 1/2) + filter_upwards [hdec,spectral_remainder_eventual hγ K hK.le, + prefix_scales_eventually_pos,hδ,eventually_ge_atTop (1 : ℕ)] with n hd hr hp hδ hn + intro C G h s hs + change (n : ℝ)^(-c) ≤ 1/2 at hδ + have hn0 : 0 < n := by omega + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn + have hlog : 0 ≤ Real.log n := Real.log_nonneg hn1 + have : NeZero n := ⟨by omega⟩ + have hne := goodPrefix_neighbors_nonempty hn0 h hp.1 hδ + have : Nonempty G := by + obtain ⟨v,hv⟩ := hne ⟨0,hn0⟩ + exact ⟨⟨{⟨0,hn0⟩,v},(Finset.mem_filter.mp hv).2⟩⟩ + have he0 : 0 ≤ 2*prefixSpectralError n c := mul_nonneg (by norm_num) + (prefixSpectralError_nonneg n c (by linarith [hp.2])) + have hrem : Real.sqrt G.card *((2*prefixSpectralError n c*Real.log n)^K * + Real.exp (Real.log n*(2*prefixSpectralError n c))) ≤ 1 := + (mul_le_mul_of_nonneg_right (graph_card_sqrt_le h.1) (by positivity)).trans + (hr _ he0 hd) + have hb := goodPrefix_semigroup_quantitative h hne hp.2 (by linarith) + (Real.log n) hlog K s hs + have hh := perturbation_polynomial_bound (Real.log n) hlog K + have h1 : (1 : ℝ) ≤ (1+Real.log n)^(2*K+1) := + one_le_pow₀ (by linarith) + calc + _ ≤ A*(1+Real.log n)^(2*K+1)+1 := by dsimp [A]; linarith + _ ≤ (A+1)*(1+Real.log n)^(2*K+1) := by nlinarith + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/History.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/History.lean new file mode 100644 index 0000000000000000000000000000000000000000..ee49b43d2c31fbe06fccf887e62bb756bf4f8141 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/History.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.MarkovLaw + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +abbrev History (α : Type*) (T : ℕ) := Fin (T + 1) → α + +def historyIndex (T k : ℕ) : Fin (T + 1) := ⟨min k T,by omega⟩ + +@[simp] theorem historyIndex_val (T k : ℕ) : (historyIndex T k).val = min k T := rfl + +noncomputable def historyInitial {α : Type*} (initial : PMF α) (T : ℕ) : PMF (History α T) := + initial.map (fun a => fun _ => a) + +noncomputable def historyKernel {α : Type*} (K : ℕ → α → PMF α) (T k : ℕ) + (ω : History α T) : PMF (History α T) := + if k < T then (K k (ω (historyIndex T k))).map + (fun b => Function.update ω (historyIndex T (k + 1)) b) else PMF.pure ω + +noncomputable def historyLaw {α : Type*} (initial : PMF α) (K : ℕ → α → PMF α) + (T k : ℕ) : PMF (History α T) := + markovLaw (historyInitial initial T) (historyKernel K T) k + +theorem historyIndex_ne_succ {T j k : ℕ} (hjk : j ≤ k) (hk : k < T) : + historyIndex T j ≠ historyIndex T (k + 1) := by + intro h + have he := congrArg Fin.val h + simp only [historyIndex_val] at he + omega + +theorem historyLaw_marginal {α : Type*} (initial : PMF α) (K : ℕ → α → PMF α) + (T k : ℕ) (hk : k ≤ T) : + (historyLaw initial K T k).map (fun ω => ω (historyIndex T k)) = + markovLaw initial K k := by + induction k with + | zero => + simp only [historyLaw,markovLaw,historyInitial,PMF.map_comp] + change initial.map id = initial + exact PMF.map_id initial + | succ k ih => + have hkt : k < T := by omega + have hkm : k ≤ T := by omega + simp only [historyLaw,markovLaw,PMF.map_bind] + have ih' := ih hkm + change (historyLaw initial K T k).bind _ = (markovLaw initial K k).bind (K k) + rw [← ih',PMF.bind_map] + congr 1 + funext ω + simp only [historyKernel,ite_eq_left hkt,PMF.map_comp,Function.comp_def, + Function.update_self] + exact PMF.map_id _ + +theorem historyLaw_invariant {α : Type*} (initial : PMF α) (K : ℕ → α → PMF α) + (P : α → Prop) (hinit : ∀ a ∈ initial.support, P a) + (hstep : ∀ k a, P a → ∀ b ∈ (K k a).support, P b) + (T k : ℕ) (ω : History α T) (hω : ω ∈ (historyLaw initial K T k).support) : + ∀ j, P (ω j) := by + induction k generalizing ω with + | zero => + obtain ⟨a,ha,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hω + exact fun _ => hinit a ha + | succ k ih => + obtain ⟨π,hπ,hω⟩ := (PMF.mem_support_bind_iff _ _ _).mp hω + have hp := ih π hπ + by_cases hk : k < T + · rw [historyKernel,ite_eq_left hk] at hω + obtain ⟨b,hb,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hω + intro j + by_cases hj : j = historyIndex T (k + 1) + · subst j + rw [Function.update_self] + exact hstep k _ (hp _) b hb + · rw [Function.update_of_ne hj] + exact hp j + · rw [historyKernel,ite_eq_right hk,PMF.mem_support_pure_iff] at hω + subst ω + exact hp + +noncomputable def historyIncrement {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : ℕ → α → ℝ) (T j : ℕ) (ω : History α T) : ℝ := + f (j + 1) (ω (historyIndex T (j + 1))) - + pmfMean (K j (ω (historyIndex T j))) (f (j + 1)) + +noncomputable def historyNoise {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : ℕ → α → ℝ) (T k : ℕ) (ω : History α T) : ℝ := + ∑ j ∈ Finset.range (min k T), historyIncrement K f T j ω + +noncomputable def historyCounter {α : Type*} (v : ℕ → α → ℝ) + (T k : ℕ) (ω : History α T) : ℝ := + ∑ j ∈ Finset.range (min k T), v j (ω (historyIndex T j)) + +noncomputable def historyCounterRate {α : Type*} (v : ℕ → α → ℝ) + (T k : ℕ) (ω : History α T) : ℝ := + if k < T then v k (ω (historyIndex T k)) else 0 + +theorem historyNoise_update {α : Type*} [Fintype α] (K : ℕ → α → PMF α) + (f : ℕ → α → ℝ) (T k : ℕ) (hk : k < T) (ω : History α T) (b : α) : + historyNoise K f T (k + 1) (Function.update ω (historyIndex T (k + 1)) b) = + historyNoise K f T k ω + f (k + 1) b - + pmfMean (K k (ω (historyIndex T k))) (f (k + 1)) := by + unfold historyNoise + rw [Nat.min_eq_left (by omega : k + 1 ≤ T),Nat.min_eq_left hk.le,Finset.sum_range_succ] + have hp : (∑ j ∈ Finset.range k, + historyIncrement K f T j (Function.update ω (historyIndex T (k + 1)) b)) = + ∑ j ∈ Finset.range k, historyIncrement K f T j ω := by + apply Finset.sum_congr rfl + intro j hj + have hjk := Finset.mem_range.mp hj + simp only [historyIncrement,Function.update_of_ne (historyIndex_ne_succ (by omega : j + 1 ≤ k) hk), + Function.update_of_ne (historyIndex_ne_succ hjk.le hk)] + rw [hp] + simp only [historyIncrement,Function.update_self, + Function.update_of_ne (historyIndex_ne_succ le_rfl hk)] + ring + +theorem historyCounter_update {α : Type*} (v : ℕ → α → ℝ) + (T k : ℕ) (hk : k < T) (ω : History α T) (b : α) : + historyCounter v T (k + 1) (Function.update ω (historyIndex T (k + 1)) b) = + historyCounter v T k ω + v k (ω (historyIndex T k)) := by + unfold historyCounter + rw [Nat.min_eq_left (by omega : k + 1 ≤ T),Nat.min_eq_left hk.le,Finset.sum_range_succ] + congr 1 + · apply Finset.sum_congr rfl + intro j hj + rw [Function.update_of_ne (historyIndex_ne_succ (Finset.mem_range.mp hj).le hk)] + · rw [Function.update_of_ne (historyIndex_ne_succ le_rfl hk)] + +@[simp] theorem historyNoise_zero {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : ℕ → α → ℝ) (T : ℕ) (ω : History α T) : + historyNoise K f T 0 ω = 0 := by simp [historyNoise] + +@[simp] theorem historyCounter_zero {α : Type*} (v : ℕ → α → ℝ) + (T : ℕ) (ω : History α T) : historyCounter v T 0 ω = 0 := by simp [historyCounter] + +theorem historyLaw_current_support {α : Type*} (initial : PMF α) + (K : ℕ → α → PMF α) (T k : ℕ) (hk : k ≤ T) + (ω : History α T) (hω : ω ∈ (historyLaw initial K T k).support) : + ω (historyIndex T k) ∈ (markovLaw initial K k).support := by + rw [← historyLaw_marginal initial K T k hk] + exact (PMF.mem_support_map_iff _ _ _).mpr ⟨ω,hω,rfl⟩ + +theorem historyNoise_frozen {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : ℕ → α → ℝ) (T k : ℕ) (hk : T ≤ k) + (ω : History α T) : historyNoise K f T (k + 1) ω = historyNoise K f T k ω := by + simp only [historyNoise,Nat.min_eq_right hk,Nat.min_eq_right (by omega : T ≤ k + 1)] + +theorem historyCounter_frozen {α : Type*} (v : ℕ → α → ℝ) (T k : ℕ) (hk : T ≤ k) + (ω : History α T) : historyCounter v T (k + 1) ω = historyCounter v T k ω := by + simp only [historyCounter,Nat.min_eq_right hk,Nat.min_eq_right (by omega : T ≤ k + 1)] + +theorem history_noise_freedman {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) (f v : ℕ → α → ℝ) + (T : ℕ) (c : ℝ) (hc : 0 < c) + (hbounded : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + ∀ b ∈ (K k a).support, + |f (k + 1) b - pmfMean (K k a) (f (k + 1))| ≤ c) + (hvar : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + pmfMean (K k a) (fun b => + (f (k + 1) b - pmfMean (K k a) (f (k + 1))) ^ 2) ≤ v k a) + (k : ℕ) (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw initial K T k) + (fun ω => if r ≤ historyNoise K f T k ω ∧ historyCounter v T k ω ≤ V + then 1 else 0) ≤ Real.exp (-r ^ 2 / (4 * (V + c * r))) := by + classical + apply finite_freedman (historyInitial initial T) (historyKernel K T) + (historyNoise K f T) (historyCounter v T) (historyCounterRate v T) c hc + · intro ω _ + simp only [historyNoise_zero,historyCounter_zero,le_refl,and_self] + · intro j ω hω π hπ + by_cases hj : j < T + · rw [historyKernel,ite_eq_left hj] at hπ + obtain ⟨b,hb,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hπ + rw [historyNoise_update K f T j hj] + have hb' := hbounded j hj _ (historyLaw_current_support initial K T j hj.le ω hω) b hb + convert hb' using 1; congr 1; ring + · rw [historyKernel,ite_eq_right hj,PMF.mem_support_pure_iff] at hπ + subst π + rw [historyNoise_frozen K f T j (Nat.le_of_not_gt hj),sub_self,abs_zero] + exact hc.le + · intro j ω hω + by_cases hj : j < T + · rw [historyKernel,ite_eq_left hj,pmfMean_map] + have he (b : α) : historyNoise K f T (j + 1) + (Function.update ω (historyIndex T (j + 1)) b) - historyNoise K f T j ω = + f (j + 1) b - pmfMean (K j (ω (historyIndex T j))) (f (j + 1)) := by + rw [historyNoise_update K f T j hj] + ring + simp_rw [he] + rw [pmfMean_sub,pmfMean_const,sub_self] + · rw [historyKernel,ite_eq_right hj,pmfMean_pure, + historyNoise_frozen K f T j (Nat.le_of_not_gt hj),sub_self] + · intro j ω hω + by_cases hj : j < T + · rw [historyKernel,ite_eq_left hj,pmfMean_map,historyCounterRate,ite_eq_left hj] + have he (b : α) : historyNoise K f T (j + 1) + (Function.update ω (historyIndex T (j + 1)) b) - historyNoise K f T j ω = + f (j + 1) b - pmfMean (K j (ω (historyIndex T j))) (f (j + 1)) := by + rw [historyNoise_update K f T j hj] + ring + simp_rw [he] + exact hvar j hj _ (historyLaw_current_support initial K T j hj.le ω hω) + · rw [historyKernel,ite_eq_right hj,pmfMean_pure, + historyNoise_frozen K f T j (Nat.le_of_not_gt hj),sub_self, + historyCounterRate,ite_eq_right hj,zero_pow (by decide : 2 ≠ 0)] + · intro j ω _ π hπ + by_cases hj : j < T + · rw [historyKernel,ite_eq_left hj] at hπ + obtain ⟨b,_,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hπ + rw [historyCounter_update v T j hj,historyCounterRate,ite_eq_left hj] + · rw [historyKernel,ite_eq_right hj,PMF.mem_support_pure_iff] at hπ + subst π + rw [historyCounter_frozen v T j (Nat.le_of_not_gt hj), + historyCounterRate,ite_eq_right hj,add_zero] + · exact hr + · exact hV + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryAdditive.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryAdditive.lean new file mode 100644 index 0000000000000000000000000000000000000000..939bca64b3ec63c8e636a9fb9d359df866251207 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryAdditive.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.HistoryLawPastMean + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +noncomputable def historyAdditive {α : Type*} (g : ℕ → α → α → ℝ) + (T k : ℕ) (ω : History α T) : ℝ := + ∑ j ∈ Finset.range (min k T), g j (ω (historyIndex T j)) (ω (historyIndex T (j+1))) + +lemma historyAdditive_update {α : Type*} (g : ℕ → α → α → ℝ) + (T k : ℕ) (hk : k < T) (ω : History α T) (b : α) : + historyAdditive g T (k+1) (Function.update ω (historyIndex T (k+1)) b) = + historyAdditive g T k ω + g k (ω (historyIndex T k)) b := by + unfold historyAdditive + rw [Nat.min_eq_left (by omega : k+1 ≤ T),Nat.min_eq_left hk.le,Finset.sum_range_succ] + congr 1 + · apply Finset.sum_congr rfl + intro j hj + have hjk := Finset.mem_range.mp hj + rw [Function.update_of_ne (historyIndex_ne_succ hjk.le hk), + Function.update_of_ne (historyIndex_ne_succ (by omega : j+1 ≤ k) hk)] + · rw [Function.update_self,Function.update_of_ne (historyIndex_ne_succ le_rfl hk)] + +@[simp] lemma historyAdditive_zero {α : Type*} (g : ℕ → α → α → ℝ) + (T : ℕ) (ω : History α T) : historyAdditive g T 0 ω = 0 := by + simp [historyAdditive] + +lemma historyAdditive_frozen {α : Type*} (g : ℕ → α → α → ℝ) + (T k : ℕ) (hk : T ≤ k) (ω : History α T) : + historyAdditive g T (k+1) ω = historyAdditive g T k ω := by + simp only [historyAdditive,Nat.min_eq_right hk,Nat.min_eq_right (by omega : T ≤ k+1)] + +theorem history_additive_freedman {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) (g : ℕ → α → α → ℝ) (v : ℕ → α → ℝ) + (T : ℕ) (c : ℝ) (hc : 0 < c) + (hbounded : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + ∀ b ∈ (K k a).support, |g k a b| ≤ c) + (hmean : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, pmfMean (K k a) (g k a) = 0) + (hvar : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + pmfMean (K k a) (fun b => (g k a b)^2) ≤ v k a) + (k : ℕ) (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw initial K T k) + (fun ω => if r ≤ historyAdditive g T k ω ∧ historyCounter v T k ω ≤ V + then 1 else 0) ≤ Real.exp (-r^2/(4*(V+c*r))) := by + classical + apply finite_freedman (historyInitial initial T) (historyKernel K T) + (historyAdditive g T) (historyCounter v T) (historyCounterRate v T) c hc + · intro ω _ + simp only [historyAdditive_zero,historyCounter_zero,le_refl,and_self] + · intro j ω hω π hπ + by_cases hj : j < T + · rw [historyKernel,ite_eq_left hj] at hπ + obtain ⟨b,hb,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hπ + rw [historyAdditive_update g T j hj,add_sub_cancel_left] + exact hbounded j hj _ (historyLaw_current_support initial K T j hj.le ω hω) b hb + · rw [historyKernel,ite_eq_right hj,PMF.mem_support_pure_iff] at hπ + subst π + rw [historyAdditive_frozen g T j (Nat.le_of_not_gt hj),sub_self,abs_zero] + exact hc.le + · intro j ω hω + by_cases hj : j < T + · rw [historyKernel,ite_eq_left hj,pmfMean_map] + simp_rw [historyAdditive_update g T j hj,add_sub_cancel_left] + exact (hmean j hj _ (historyLaw_current_support initial K T j hj.le ω hω)).le + · rw [historyKernel,ite_eq_right hj,pmfMean_pure, + historyAdditive_frozen g T j (Nat.le_of_not_gt hj),sub_self] + · intro j ω hω + by_cases hj : j < T + · rw [historyKernel,ite_eq_left hj,pmfMean_map,historyCounterRate,ite_eq_left hj] + simp_rw [historyAdditive_update g T j hj,add_sub_cancel_left] + exact hvar j hj _ (historyLaw_current_support initial K T j hj.le ω hω) + · rw [historyKernel,ite_eq_right hj,pmfMean_pure, + historyAdditive_frozen g T j (Nat.le_of_not_gt hj),sub_self, + historyCounterRate,ite_eq_right hj,zero_pow (by decide : 2 ≠ 0)] + · intro j ω _ π hπ + by_cases hj : j < T + · rw [historyKernel,ite_eq_left hj] at hπ + obtain ⟨b,_,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hπ + rw [historyCounter_update v T j hj,historyCounterRate,ite_eq_left hj] + · rw [historyKernel,ite_eq_right hj,PMF.mem_support_pure_iff] at hπ + subst π + rw [historyCounter_frozen v T j (Nat.le_of_not_gt hj), + historyCounterRate,ite_eq_right hj,add_zero] + · exact hr + · exact hV + +lemma historyAdditive_past {α : Type*} (g : ℕ → α → α → ℝ) + (T j : ℕ) (ω π : History α T) + (h : ∀ i : Fin (T+1), i.val ≤ min j T → ω i = π i) : + historyAdditive g T j ω = historyAdditive g T j π := by + unfold historyAdditive + apply Finset.sum_congr rfl + intro s hs + have hs' : s < min j T := Finset.mem_range.mp hs + have hsc : (historyIndex T s).val ≤ min j T := by + simp only [historyIndex] + exact (Nat.min_le_left _ _).trans (Nat.le_of_lt hs') + have hsn : (historyIndex T (s+1)).val ≤ min j T := by + simp only [historyIndex] + exact (Nat.min_le_left _ _).trans (by omega) + rw [h _ hsc,h _ hsn] + +theorem history_additive_freedman_maximal {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) (g : ℕ → α → α → ℝ) (v : ℕ → α → ℝ) + (T : ℕ) (c : ℝ) (hc : 0 < c) + (hbounded : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + ∀ b ∈ (K k a).support, |g k a b| ≤ c) + (hmean : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, pmfMean (K k a) (g k a) = 0) + (hvar : ∀ k < T, ∀ a ∈ (markovLaw initial K k).support, + pmfMean (K k a) (fun b => (g k a b)^2) ≤ v k a) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw initial K T T) + (fun ω => if ∃ j ≤ T, r ≤ historyAdditive g T j ω ∧ + historyCounter v T j ω ≤ V then 1 else 0) ≤ + (T+1 : ℝ)*Real.exp (-r^2/(4*(V+c*r))) := by + classical + have hcov := pmfMean_event_union (historyLaw initial K T T) (Finset.range (T+1)) + (fun j ω => r ≤ historyAdditive g T j ω ∧ historyCounter v T j ω ≤ V) + have hsum : (∑ j ∈ Finset.range (T+1), + pmfMean (historyLaw initial K T T) + (fun ω => if r ≤ historyAdditive g T j ω ∧ historyCounter v T j ω ≤ V + then 1 else 0)) ≤ (T+1 : ℝ)*Real.exp (-r^2/(4*(V+c*r))) := by + calc + _ ≤ ∑ _j ∈ Finset.range (T+1), Real.exp (-r^2/(4*(V+c*r))) := by + apply Finset.sum_le_sum + intro j hj + have hjT : j ≤ T := by have := Finset.mem_range.mp hj; omega + rw [historyLaw_past_mean initial K T j T hjT _ (by + intro ω π h + rw [historyAdditive_past g T j ω π h,historyCounter_past v T j ω π h])] + exact history_additive_freedman initial K g v T c hc hbounded hmean hvar j r V hr hV + _ = _ := by simp + apply le_trans _ hsum + convert hcov using 1 <;> try rfl + · apply congrArg (pmfMean (historyLaw initial K T T)) + funext ω + simp only [Finset.mem_range,Nat.lt_succ_iff] + · apply Finset.sum_congr rfl + intro j _ + apply congrArg (pmfMean (historyLaw initial K T T)) + funext ω + split_ifs <;> rfl + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryAlive.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryAlive.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f986b5c3f6e2e62653219e608a8f3fffc1e2342 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryAlive.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift +import OAI.Combinatorics.TriangleRemoval.Process.History + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +def historyAlive {α : Type*} (safe : ℕ → α → Prop) (T j : ℕ) + (ω : History α T) : Prop := ∀ i < j, safe i (ω (historyIndex T i)) + +lemma historyAlive_update {α : Type*} (safe : ℕ → α → Prop) (T j : ℕ) + (hj : j < T) (ω : History α T) (b : α) : + historyAlive safe T (j+1) (Function.update ω (historyIndex T (j+1)) b) ↔ + historyAlive safe T j ω ∧ safe j (ω (historyIndex T j)) := by + constructor + · intro h + constructor + · intro i hi + have hh := h i (by omega) + rwa [Function.update_of_ne (historyIndex_ne_succ hi.le hj)] at hh + · have hh := h j (by omega) + rwa [Function.update_of_ne (historyIndex_ne_succ le_rfl hj)] at hh + · rintro ⟨h,hj'⟩ i hi + rw [Function.update_of_ne (historyIndex_ne_succ (by omega) hj)] + rcases lt_or_eq_of_le (show i ≤ j by omega) with hi' | rfl + · exact h i hi' + · exact hj' + +theorem history_alive_mean_le {α : Type*} [Fintype α] + (initial : PMF α) (K : ℕ → α → PMF α) (safe : ℕ → α → Prop) + (f : α → ℝ) (hf : ∀ a, 0 ≤ f a) (r : ℕ → ℝ) (hr : ∀ i, 0 ≤ r i) + (T : ℕ) + (hstep : ∀ i < T, ∀ a, safe i a → pmfMean (K i a) f ≤ r i * f a) + (j : ℕ) (hj : j ≤ T) : + pmfMean (historyLaw initial K T j) + (fun ω => if historyAlive safe T j ω then f (ω (historyIndex T j)) else 0) ≤ + (∏ i ∈ Finset.range j, r i) * pmfMean initial f := by + classical + induction j with + | zero => + simp [historyLaw,markovLaw,historyInitial,pmfMean_map,historyAlive] + | succ j ih => + have hjT : j < T := by omega + have ih' := ih hjT.le + change pmfMean ((historyLaw initial K T j).bind (historyKernel K T j)) _ ≤ _ + rw [pmfMean_bind,Finset.prod_range_succ] + calc + _ ≤ pmfMean (historyLaw initial K T j) + (fun ω => r j * (if historyAlive safe T j ω then f (ω (historyIndex T j)) else 0)) := by + apply pmfMean_mono + intro ω _ + simp only [historyKernel,ite_eq_left hjT,pmfMean_map,historyAlive_update safe T j hjT, + Function.update_self] + by_cases ha : historyAlive safe T j ω + · by_cases hs : safe j (ω (historyIndex T j)) + · simp only [ha,hs,and_self,ite_true] + exact hstep j hjT _ hs + · simp only [ha,hs,and_false,ite_false,ite_true,pmfMean_const] + exact mul_nonneg (hr j) (hf _) + · simp only [ha,false_and,ite_false,pmfMean_const,mul_zero,le_refl] + _ = r j * pmfMean (historyLaw initial K T j) + (fun ω => if historyAlive safe T j ω then f (ω (historyIndex T j)) else 0) := + pmfMean_const_mul _ _ _ + _ ≤ r j * ((∏ i ∈ Finset.range j, r i) * pmfMean initial f) := + mul_le_mul_of_nonneg_left ih' (hr j) + _ = _ := by ring + +lemma intact_nonnegative {n : ℕ} (F G : Graph n) : 0 ≤ intact F G := by + classical + unfold intact + split_ifs <;> norm_num + +theorem triangle_intact_exponential_bound {n : ℕ} (G F : Graph n) (D δ : ℝ) + (hQ : (triangles G).Nonempty) + (hdeg : ∀ e ∈ G, |(triangleDegree G e : ℝ)-D| ≤ δ) : + pmfMean (step G) (intact F) ≤ + Real.exp (-((F.card : ℝ)*D-((F.card : ℝ)*δ+(F.card : ℝ)^2))/(triangles G).card) * + intact F G := by + classical + by_cases hF : F ⊆ G + · have he := hittingTriangles_degree_error G F D δ (fun e he => hdeg e (hF he)) + have hq : (0 : ℝ) < (triangles G).card := by exact_mod_cast hQ.card_pos + rw [step_mean_intact hF hQ] + simp only [intact,hF,ite_true,mul_one] + have hl : (F.card : ℝ)*D-((F.card : ℝ)*δ+(F.card : ℝ)^2) ≤ + (hittingTriangles G F).card := by linarith [(abs_le.mp he).1] + calc + _ ≤ 1-((F.card : ℝ)*D-((F.card : ℝ)*δ+(F.card : ℝ)^2))/(triangles G).card := + sub_le_sub_left (div_le_div_of_nonneg_right hl hq.le) 1 + _ ≤ _ := by + have hh := Real.add_one_le_exp + (-(((F.card : ℝ)*D-((F.card : ℝ)*δ+(F.card : ℝ)^2))/(triangles G).card)) + convert hh using 1 <;> congr 1 <;> ring + · rw [step_mean_intact_of_not_subset hF] + simp [intact,hF] + +theorem triangle_killed_survival {n : ℕ} (initial : PMF (Graph n)) + (safe : ℕ → Graph n → Prop) (F : Graph n) (rate : ℕ → ℝ) (T j : ℕ) (hj : j ≤ T) + (hstep : ∀ i < T, ∀ G, safe i G → + pmfMean (step G) (intact F) ≤ Real.exp (rate i) * intact F G) : + pmfMean (historyLaw initial (fun _ => step) T j) + (fun ω => if historyAlive safe T j ω then intact F (ω (historyIndex T j)) else 0) ≤ + Real.exp (∑ i ∈ Finset.range j, rate i) * pmfMean initial (intact F) := by + classical + have h := history_alive_mean_le initial (fun _ => step) safe (intact F) + (intact_nonnegative F) (fun i => Real.exp (rate i)) (fun i => (Real.exp_pos _).le) + T hstep j hj + simpa only [← Real.exp_sum] using h + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryCompensator.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryCompensator.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2212d47a6a362ed322a4d203d911f20c20d2fde --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryCompensator.lean @@ -0,0 +1,112 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixCodegreeNoiseExit + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +noncomputable def historyCompensator {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : ℕ → α → ℝ) (T j : ℕ) + (ω : History α T) : ℝ := + historyCounter (fun k a => pmfMean (K k a) (f (k+1))-f k a) T j ω + +theorem history_noise_compensator {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : ℕ → α → ℝ) (T j : ℕ) (hj : j ≤ T) + (ω : History α T) : + f j (ω (historyIndex T j)) = f 0 (ω (historyIndex T 0))+ + historyNoise K f T j ω+historyCompensator K f T j ω := by + unfold historyCompensator historyCounter historyNoise historyIncrement + simp only [Nat.min_eq_left hj] + rw [add_assoc,← Finset.sum_add_distrib] + have he : (∑ k ∈ Finset.range j, + (f (k+1) (ω (historyIndex T (k+1)))-pmfMean (K k (ω (historyIndex T k))) (f (k+1))+ + (pmfMean (K k (ω (historyIndex T k))) (f (k+1))-f k (ω (historyIndex T k))))) = + f j (ω (historyIndex T j))-f 0 (ω (historyIndex T 0)) := by + calc + _ = ∑ k ∈ Finset.range j, + (f (k+1) (ω (historyIndex T (k+1)))-f k (ω (historyIndex T k))) := by + apply Finset.sum_congr rfl + intro k _ + ring + _ = _ := Finset.sum_range_sub (fun k => f k (ω (historyIndex T k))) j + rw [he] + ring + +noncomputable def prefixNormalizedCodegree {n : ℕ} (u v : Fin n) + (k : ℕ) (G : Graph n) : ℝ := + (currentCodegree G u v : ℝ)/earlyTemplateScale 1 2 n k + +noncomputable def prefixCodegreePredictableError {n : ℕ} (u v : Fin n) + (j : ℕ) (ω : History (Graph n) (prefixTime n)) : ℝ := + prefixNormalizedCodegree u v 0 (ω (historyIndex (prefixTime n) 0))-1+ + historyCompensator (fun _ => step) (prefixNormalizedCodegree u v) (prefixTime n) j ω + +def PrefixCodegreeDriftExit {n : ℕ} (u v : Fin n) + (ω : History (Graph n) (prefixTime n)) : Prop := + ∃ j ≤ prefixTime n, + (∀ k < j, |prefixNormalizedCodegree u v k (ω (historyIndex (prefixTime n) k))-1| < + 2*codegreeNoiseRadius n) ∧ + codegreeNoiseRadius n ≤ |prefixCodegreePredictableError u v j ω| + +theorem codegree_first_exit_noise_or_drift {n : ℕ} (u v : Fin n) + (hs : ∀ k ≤ prefixTime n, 0 < earlyTemplateScale 1 2 n k) + (hr : codegreeNoiseRadius n ≤ 1/2) + (ω : History (Graph n) (prefixTime n)) + (hex : ∃ j ≤ prefixTime n, + 2*codegreeNoiseRadius n ≤ + |prefixNormalizedCodegree u v j (ω (historyIndex (prefixTime n) j))-1|) : + PrefixCodegreeNoiseExit u v ω ∨ PrefixCodegreeDriftExit u v ω := by + classical + let P : ℕ → Prop := fun j => j ≤ prefixTime n ∧ 2*codegreeNoiseRadius n ≤ + |prefixNormalizedCodegree u v j (ω (historyIndex (prefixTime n) j))-1| + have hex' : ∃ j, P j := hex + let j := Nat.find hex' + have hj : j ≤ prefixTime n := (Nat.find_spec hex').1 + have hcross := (Nat.find_spec hex').2 + have hbefore : ∀ k < j, |prefixNormalizedCodegree u v k (ω (historyIndex (prefixTime n) k))-1| < + 2*codegreeNoiseRadius n := by + intro k hk + have hh := Nat.find_min' hex' (m := k) + by_contra hn + have hp : P k := ⟨by omega,le_of_not_gt hn⟩ + have := hh hp + omega + have hcount : ∀ k < j, + (currentCodegree (ω (historyIndex (prefixTime n) k)) u v : ℝ) ≤ + 2*earlyTemplateScale 1 2 n k := by + intro k hk + have hh := (le_abs_self (prefixNormalizedCodegree u v k + (ω (historyIndex (prefixTime n) k))-1)).trans (hbefore k hk).le + have hq : prefixNormalizedCodegree u v k (ω (historyIndex (prefixTime n) k)) ≤ 2 := by linarith + exact (div_le_iff₀ (hs k (by omega))).mp hq + let noise := historyNoise (fun _ => step) (prefixNormalizedCodegree u v) (prefixTime n) j ω + by_cases hm : codegreeNoiseRadius n ≤ |noise| + · exact Or.inl ⟨j,hj,hcount,hm⟩ + · apply Or.inr + refine ⟨j,hj,hbefore,?_⟩ + have hid := history_noise_compensator (fun _ => step) (prefixNormalizedCodegree u v) + (prefixTime n) j hj ω + have he : prefixNormalizedCodegree u v j (ω (historyIndex (prefixTime n) j))-1 = + noise+prefixCodegreePredictableError u v j ω := by + unfold noise prefixCodegreePredictableError + linarith only [hid] + have htriangle := abs_add_le noise (prefixCodegreePredictableError u v j ω) + change 2*codegreeNoiseRadius n ≤ + |prefixNormalizedCodegree u v j (ω (historyIndex (prefixTime n) j))-1| at hcross + rw [he] at hcross + linarith only [hcross,htriangle,lt_of_not_ge hm] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryGraphNested.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryGraphNested.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3c25a0861575b5a7f421b1d31c953bb3751b585 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/HistoryGraphNested.lean @@ -0,0 +1,201 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixCodegreeNoiseGood +import OAI.Combinatorics.TriangleRemoval.Process.CompleteEdgePair +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEdgeForcingBound + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +lemma history_graph_nested {n T : ℕ} (ω : History (Graph n) T) + (hω : ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) T T).support) + {i j : ℕ} (hij : i ≤ j) (hj : j ≤ T) : + ω (historyIndex T j) ⊆ ω (historyIndex T i) := by + have hp := (historyLaw_path_support (PMF.pure (completeGraph n)) (fun _ => step) + T T le_rfl ω hω).2 + induction j, hij using Nat.le_induction with + | base => exact Finset.Subset.refl _ + | succ k hik ih => exact (step_support_subset (hp k (by omega))).trans (ih (by omega)) + +lemma densityEdgeSafe_centered_bound {n : ℕ} {p η : ℝ} {G : Graph n} + (hp : 0 < (n : ℝ)*p^2) (h : densityEdgeSafe n p η G) + (e : CompleteEdge n) (he : e.val ∈ G) : + |centeredEdgeVector G ((n : ℝ)*p^2) e| ≤ η := by + let uv := completeEdgePair e + have hep : {uv.val.1,uv.val.2} ∈ G := uv.property.2 ▸ he + have hh := h.2.2 e.val he + rw [uv.property.2,triangleDegree_eq_codegree h.1 hep] at hh + change |(currentCodegree G uv.val.1 uv.val.2 : ℝ)/((n : ℝ)*p^2)-1| ≤ η + rw [show (currentCodegree G uv.val.1 uv.val.2 : ℝ)/((n : ℝ)*p^2)-1 = + ((currentCodegree G uv.val.1 uv.val.2 : ℝ)-(n : ℝ)*p^2)/((n : ℝ)*p^2) by rw [sub_div,div_self hp.ne']] + rw [abs_div,abs_of_pos hp] + exact (div_le_iff₀ hp).mpr hh + +lemma densityEdgeSafe_pair_upper {n : ℕ} {p η : ℝ} {G : Graph n} + (hp : 0 ≤ (n : ℝ)*p^2) (hη : η ≤ 1) (h : densityEdgeSafe n p η G) + (u v : Fin n) (he : {u,v} ∈ G) : + (currentCodegree G u v : ℝ) ≤ 2*((n : ℝ)*p^2) := by + have hh := (abs_le.mp (h.2.2 {u,v} he)).2 + rw [triangleDegree_eq_codegree h.1 he] at hh + nlinarith only [hh,mul_le_mul_of_nonneg_right hη hp] + +lemma initial_centered_edge_bound {n : ℕ} (hn : 2 ≤ n) + (ω : History (Graph n) (prefixTime n)) + (hω : ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support) + (e : CompleteEdge n) : |prefixCenteredEdge ω 0 e| ≤ 4/(n : ℝ) := by + have hi := (historyLaw_path_support (PMF.pure (completeGraph n)) (fun _ => step) + (prefixTime n) (prefixTime n) le_rfl ω hω).1 + have hi' : ω (historyIndex (prefixTime n) 0) = completeGraph n := by simpa using hi + unfold prefixCenteredEdge centeredEdgeVector + rw [hi',initial_normalized_codegree_error hn _ _ (completeEdgePair e).property.1, + neg_div,abs_neg,abs_of_nonneg (by positivity : (0 : ℝ) ≤ 1/((n : ℝ)-1)^2)] + have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn + apply (div_le_div_iff₀ (sq_pos_of_ne_zero (by linarith)) (by linarith : (0 : ℝ) < n)).mpr + nlinarith + +lemma prefix_triangle_radius_small : ∀ᶠ n : ℕ in atTop, + 0 ≤ prefixTriangleRadius n ∧ prefixTriangleRadius n ≤ 1/2 := by + have hl : Tendsto prefixTriangleRadius atTop (nhds 0) := by + change Tendsto (fun n : ℕ => (n : ℝ)^(-3/80000 : ℝ)) atTop (nhds 0) + simpa only [Function.comp_def,neg_div] using (tendsto_rpow_neg_atTop + (by norm_num : (0 : ℝ) < 3/80000)).comp tendsto_natCast_atTop_atTop + filter_upwards [hl.eventually_le_const (by norm_num : (0 : ℝ) < 1/2)] with n hn + exact ⟨Real.rpow_nonneg (Nat.cast_nonneg _) _,hn⟩ + +theorem prefix_edge_coefficient_bounds : ∀ᶠ n : ℕ in atTop, + ∀ ω : History (Graph n) (prefixTime n), + ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support → + PrefixTriangleNoise n ω → ∀ j ≤ prefixTime n, + historyAlive (fun i => densityEdgeSafe n (earlyDensity n i) (prefixEdgeRadius n)) (prefixTime n) j ω → + (∀ i < j, 0 ≤ prefixEdgeRate ω i ∧ prefixEdgeRate ω i ≤ 1 ∧ + prefixEdgeRate ω i ≤ 4*(6/(n : ℝ)^2/earlyDensity n i) ∧ + |prefixEdgeScalar ω i| ≤ 8*prefixTriangleRadius n*(6/(n : ℝ)^2/earlyDensity n i)+ + 2*(6/(n : ℝ)^2/earlyDensity n i)^2+ + 4*(6/(n : ℝ)^2/earlyDensity n i)/earlyTemplateScale 1 2 n i) ∧ + (∑ i ∈ Finset.range j, prefixEdgeRate ω i) ≤ 4*Real.log n := by + filter_upwards [prefix_triangle_tracking,earlyTemplateScale_regular 1 2, + earlyTriangleScale_regular,prefix_triangle_radius_small,prefixDensity_eventually_inverse_lower, + eventually_ge_atTop (24 : ℕ)] with n htrack hreg htri hr hp hn + intro ω hω hnoise j hj hsafe + have hni : 0 < n := by omega + have hnR : (24 : ℝ) ≤ n := by exact_mod_cast hn + have hcoeff : ∀ i < j, 0 ≤ prefixEdgeRate ω i ∧ prefixEdgeRate ω i ≤ 1 ∧ + prefixEdgeRate ω i ≤ 4*(6/(n : ℝ)^2/earlyDensity n i) ∧ + |prefixEdgeScalar ω i| ≤ 8*prefixTriangleRadius n*(6/(n : ℝ)^2/earlyDensity n i)+ + 2*(6/(n : ℝ)^2/earlyDensity n i)^2+ + 4*(6/(n : ℝ)^2/earlyDensity n i)/earlyTemplateScale 1 2 n i := by + intro i hi + have hiT : i < prefixTime n := by omega + have hs := early_codegree_grid hni hp hiT + have hc := htrack ω hω hnoise i (by omega) (fun k hk => hsafe k (by omega)) + have hb := edge_stability_coefficients (hreg.1 i (by omega)) (hreg.1 (i+1) (by omega)) + (htri.1 i (by omega)) hs.2.2.1 hs.1 (hreg.2.2 i hiT) hs.2.1 hr.2 hc + (by norm_num : (0 : ℝ) ≤ 1) le_rfl + have hsmall : 4*(6/(n : ℝ)^2/earlyDensity n i) ≤ 1 := by + have hh := mul_le_mul_of_nonneg_left hs.2.2.2 (by norm_num : (0 : ℝ) ≤ 4) + have hi : 4*(6/(n : ℝ)) ≤ 1 := by + rw [← mul_div_assoc] + apply (div_le_iff₀ (by linarith : (0 : ℝ) < n)).mpr + linarith only [hnR] + exact hh.trans hi + exact ⟨hb.1.1,hb.1.2.trans hsmall,hb.1.2,hb.2⟩ + refine ⟨hcoeff,?_⟩ + calc + _ ≤ ∑ i ∈ Finset.range j, 4*(6/(n : ℝ)^2/earlyDensity n i) := + Finset.sum_le_sum (fun i hi => (hcoeff i (Finset.mem_range.mp hi)).2.2.1) + _ = 4*(∑ i ∈ Finset.range j, 6/(n : ℝ)^2/earlyDensity n i) := (Finset.mul_sum _ _ _).symm + _ ≤ _ := mul_le_mul_of_nonneg_left (early_grid_sum_bounds hni hp j hj).1 (by norm_num) + +theorem prefix_edge_forcing_bound : ∀ᶠ n : ℕ in atTop, + ∀ ω : History (Graph n) (prefixTime n), + ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support → + PrefixTriangleNoise n ω → PrefixCodegreeNoiseGood n ω → ∀ j ≤ prefixTime n, + historyAlive (fun i => densityEdgeSafe n (earlyDensity n i) (prefixEdgeRadius n)) (prefixTime n) j ω → + trajectorySeminorm (fun t => activeLinf (graphActive (ω (historyIndex (prefixTime n) t)))) j + (prefixEdgeForcing ω) ≤ prefixEdgeForcingBound n := by + filter_upwards [prefix_edge_coefficient_bounds,prefix_edge_forcing_power,triangle_closure_budget, + prefix_triangle_radius_small,prefixDensity_eventually_inverse_lower, + eventually_ge_atTop (2 : ℕ)] with n hcoeff hF hbud hr hp hn + intro ω hω htri hnoise j hj hsafe + have hn0 : 0 < n := by omega + have hnR : (0 : ℝ) < n := by exact_mod_cast hn0 + apply trajectorySeminorm_bound _ _ _ hF.1 + intro t ht + apply activeLinf_bound _ _ hF.1 + intro e he + have het : e.val ∈ ω (historyIndex (prefixTime n) t) := (mem_graphActive _ _).mp he + have hep (i : ℕ) (hi : i < t) : e.val ∈ ω (historyIndex (prefixTime n) i) := + history_graph_nested ω hω hi.le (ht.trans hj) het + have hc (i : ℕ) (hi : i < t) : + 0 ≤ prefixCenteredEdge ω i e+1 ∧ prefixCenteredEdge ω i e+1 ≤ 2 := by + have hpos : 0 < (n : ℝ)*earlyDensity n i^2 := mul_pos hnR (sq_pos_of_pos (early_density_positive hn0 hp (by omega))) + have hh := densityEdgeSafe_pair_upper hpos.le (show prefixEdgeRadius n ≤ 1 by linarith only [hbud.2.1]) + (hsafe i (by omega)) (completeEdgePair e).val.1 (completeEdgePair e).val.2 + ((completeEdgePair e).property.2 ▸ hep i hi) + change 0 ≤ (currentCodegree _ _ _ : ℝ)/earlyTemplateScale 1 2 n i-1+1 ∧ + (currentCodegree _ _ _ : ℝ)/earlyTemplateScale 1 2 n i-1+1 ≤ 2 + simp only [sub_add_cancel,earlyTemplateScale,pow_one] + exact ⟨by positivity,(div_le_iff₀ hpos).mpr hh⟩ + have hnse : |historyNoise (fun _ => step) + (fun k H => (currentCodegree H (completeEdgePair e).val.1 (completeEdgePair e).val.2 : ℝ)/earlyTemplateScale 1 2 n k) + (prefixTime n) t ω| < codegreeNoiseRadius n := by + apply lt_of_not_ge + intro hx + apply hnoise (completeEdgePair e).val.1 (completeEdgePair e).val.2 + refine ⟨t,by omega,?_,hx⟩ + intro i hi + have hpos := mul_pos hnR (sq_pos_of_pos (early_density_positive hn0 hp (by omega : i ≤ prefixTime n))) + have hh := (hc i hi).2 + change (currentCodegree _ _ _ : ℝ)/earlyTemplateScale 1 2 n i-1+1 ≤ 2 at hh + simp only [sub_add_cancel,earlyTemplateScale,pow_one] at hh + simpa only [earlyTemplateScale,pow_one] using (div_le_iff₀ hpos).mp hh + have hcb := (hcoeff ω hω htri j hj hsafe).1 + have hsumb : |∑ i ∈ Finset.range t, prefixEdgeScalar ω i*(prefixCenteredEdge ω i e+1)| ≤ + 16*prefixTriangleRadius n*Real.log n+4/prefixD n+24*Real.log n/(n : ℝ) := by + have hgrid := early_grid_sum_bounds hn0 hp t (by omega) + calc + _ ≤ ∑ i ∈ Finset.range t, |prefixEdgeScalar ω i*(prefixCenteredEdge ω i e+1)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i ∈ Finset.range t, + (16*prefixTriangleRadius n*(6/(n : ℝ)^2/earlyDensity n i)+ + 4*(6/(n : ℝ)^2/earlyDensity n i)^2+ + 8*(6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2)) := by + apply Finset.sum_le_sum + intro i hi + have hit := Finset.mem_range.mp hi + rw [abs_mul,abs_of_nonneg (hc i hit).1] + have hh := (mul_le_mul_of_nonneg_left (hc i hit).2 (abs_nonneg (prefixEdgeScalar ω i))).trans + (mul_le_mul_of_nonneg_right (hcb i (by omega)).2.2.2 (by norm_num : (0 : ℝ) ≤ 2)) + exact hh.trans_eq (by simp only [earlyTemplateScale,pow_one]; ring) + _ = 16*prefixTriangleRadius n*(∑ i ∈ Finset.range t, 6/(n : ℝ)^2/earlyDensity n i)+ + 4*(∑ i ∈ Finset.range t, (6/(n : ℝ)^2/earlyDensity n i)^2)+ + 8*(∑ i ∈ Finset.range t, (6/(n : ℝ)^2/earlyDensity n i)/((n : ℝ)*earlyDensity n i^2)) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + _ ≤ _ := by + have h₁ := mul_le_mul_of_nonneg_left hgrid.1 (show 0 ≤ 16*prefixTriangleRadius n by exact mul_nonneg (by norm_num) hr.1) + have h₂ := mul_le_mul_of_nonneg_left hgrid.2.2 (by norm_num : (0 : ℝ) ≤ 4) + have h₃ := mul_le_mul_of_nonneg_left hgrid.2.1 (by norm_num : (0 : ℝ) ≤ 8) + simp only [div_eq_mul_inv,mul_inv_rev] at h₁ h₂ h₃ ⊢ + norm_num at h₃ + nlinarith only [h₁,h₂,h₃] + have hi := initial_centered_edge_bound hn ω hω e + unfold prefixEdgeForcing prefixEdgeForcingBound + calc + _ ≤ |prefixCenteredEdge ω 0 e|+ + |historyNoise (fun _ => step) (fun k H => (currentCodegree H (completeEdgePair e).val.1 (completeEdgePair e).val.2 : ℝ)/earlyTemplateScale 1 2 n k) (prefixTime n) t ω|+ + |∑ k ∈ Finset.range t, prefixEdgeScalar ω k*(prefixCenteredEdge ω k e+1)| := + (abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl) + _ ≤ _ := by linarith only [hi,hnse,hsumb] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/IncidenceDegree.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/IncidenceDegree.lean new file mode 100644 index 0000000000000000000000000000000000000000..534298672d64ab894e76d223d59d4e9396449d38 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/IncidenceDegree.lean @@ -0,0 +1,240 @@ +import Mathlib + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators NNReal +open Matrix InnerProductSpace +open scoped BigOperators +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix +open scoped BigOperators Topology NNReal Matrix.Norms.Operator +open MeasureTheory + +namespace SharpTerminalLeave + +theorem algebra_norm_exp_le {A : Type*} [NormedRing A] [NormOneClass A] + [NormedAlgebra ℝ A] [CompleteSpace A] (x : A) : + ‖NormedSpace.exp x‖ ≤ Real.exp ‖x‖ := by + have hs := NormedSpace.norm_expSeries_summable' (𝕂 := ℝ) x + have ht := NormedSpace.expSeries_summable' (𝕂 := ℝ) (‖x‖ : ℝ) + rw [NormedSpace.exp_eq_tsum ℝ] + calc + _ ≤ ∑' k : ℕ, ‖((k.factorial : ℝ)⁻¹) • x ^ k‖ := norm_tsum_le_tsum_norm hs + _ ≤ ∑' k : ℕ, (k.factorial : ℝ)⁻¹ * ‖x‖ ^ k := by + apply hs.tsum_le_tsum _ ht + intro k + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg (inv_nonneg.mpr (Nat.cast_nonneg _))] + exact mul_le_mul_of_nonneg_left (norm_pow_le x k) (inv_nonneg.mpr (Nat.cast_nonneg _)) + _ = Real.exp ‖x‖ := by + rw [Real.exp_eq_exp_ℝ, NormedSpace.exp_eq_tsum ℝ] + rfl + +theorem rectangular_power_swap {ι κ : Type*} [Fintype ι] [Fintype κ] + [DecidableEq ι] [DecidableEq κ] (U : Matrix ι κ ℝ) (V : Matrix κ ι ℝ) (k : ℕ) : + (U * V) ^ k * U = U * (V * U) ^ k := by + induction k with + | zero => simp + | succ k ih => + rw [pow_succ', Matrix.mul_assoc, ih] + simp only [pow_succ', Matrix.mul_assoc] + +theorem averaging_shift_exp_bound {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + (W : Matrix ι ι ℝ) (hW : ‖W‖ ≤ 1) (s : ℝ) (hs : 0 ≤ s) : + ‖NormedSpace.exp ((-s) • (1 + W))‖ ≤ 1 := by + have hc : Commute ((-s) • (1 : Matrix ι ι ℝ)) ((-s) • W) := + (Commute.one_left W).smul_left (-s) |>.smul_right (-s) + rw [smul_add] + have hadd : NormedSpace.exp (((-s) • (1 : Matrix ι ι ℝ)) + (-s) • W) = + NormedSpace.exp ((-s) • (1 : Matrix ι ι ℝ)) * NormedSpace.exp ((-s) • W) := + Matrix.exp_add_of_commute _ _ hc + rw [hadd] + have he : NormedSpace.exp ((-s) • (1 : Matrix ι ι ℝ)) = + Real.exp (-s) • (1 : Matrix ι ι ℝ) := by + have hh := NormedSpace.algebraMap_exp_comm (𝔸 := Matrix ι ι ℝ) (-s) + change _ = _ at hh + convert hh.symm using 1 <;> simp [Algebra.algebraMap_eq_smul_one, Real.exp_eq_exp_ℝ] + rfl + rw [he, smul_mul_assoc, one_mul, norm_smul, Real.norm_eq_abs, + abs_of_pos (Real.exp_pos _)] + calc + _ ≤ Real.exp (-s) * Real.exp ‖(-s) • W‖ := + mul_le_mul_of_nonneg_left (algebra_norm_exp_le _) (Real.exp_pos _).le + _ ≤ Real.exp (-s) * Real.exp s := by + apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le + apply Real.exp_le_exp.mpr + rw [norm_smul, Real.norm_eq_abs, abs_neg, abs_of_nonneg hs] + simpa using mul_le_mul_of_nonneg_left hW hs + _ = 1 := by rw [← Real.exp_add]; simp + +theorem rectangular_exp_swap {ι κ : Type*} [Fintype ι] [Fintype κ] + [DecidableEq ι] [DecidableEq κ] (U : Matrix ι κ ℝ) (V : Matrix κ ι ℝ) (s : ℝ) : + NormedSpace.exp (s • (U * V)) * U = U * NormedSpace.exp (s • (V * U)) := by + let L := (mulLeftLinearMap κ ℝ U).toContinuousLinearMap + let R := (mulRightLinearMap ι ℝ U).toContinuousLinearMap + have hL := L.hasSum (NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) (s • (V * U))) + have hR := R.hasSum (NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) (s • (U * V))) + have heq : (fun k : ℕ => R ((k.factorial : ℝ)⁻¹ • (s • (U * V)) ^ k)) = + (fun k : ℕ => L ((k.factorial : ℝ)⁻¹ • (s • (V * U)) ^ k)) := by + funext k + change ((k.factorial : ℝ)⁻¹ • (s • (U * V)) ^ k) * U = + U * ((k.factorial : ℝ)⁻¹ • (s • (V * U)) ^ k) + simp only [smul_pow, Matrix.smul_mul, Matrix.mul_smul, rectangular_power_swap] + rw [heq] at hR + exact hR.unique hL + +theorem hasDerivAt_rectangular_exp {ι κ : Type*} [Fintype ι] [Fintype κ] + [DecidableEq ι] [DecidableEq κ] (U : Matrix ι κ ℝ) (V : Matrix κ ι ℝ) (s : ℝ) : + HasDerivAt (fun t : ℝ => NormedSpace.exp ((-t) • (U * V))) + (-(U * NormedSpace.exp ((-s) • (V * U)) * V)) s := by + have hh := (hasDerivAt_exp_smul_const (𝕂 := ℝ) (U * V) (-s)).scomp s + ((hasDerivAt_id s).neg) + have heq : -(U * NormedSpace.exp ((-s) • (V * U)) * V) = + (-1 : ℝ) • (NormedSpace.exp ((-s) • (U * V)) * (U * V)) := by + rw [neg_one_smul, ← Matrix.mul_assoc, rectangular_exp_swap] + rw [heq] + convert hh using 1 <;> rfl + +theorem rectangular_semigroup_bound {ι κ : Type*} [Fintype ι] [Fintype κ] + [DecidableEq ι] [DecidableEq κ] [Nonempty ι] [Nonempty κ] + (U : Matrix ι κ ℝ) (V : Matrix κ ι ℝ) (W : Matrix κ κ ℝ) + (hVU : V * U = 1 + W) (hW : ‖W‖ ≤ 1) (s : ℝ) (hs : 0 ≤ s) : + ‖NormedSpace.exp ((-s) • (U * V))‖ ≤ 1 + s * (‖U‖ * ‖V‖) := by + let f : ℝ → Matrix ι ι ℝ := fun t => NormedSpace.exp ((-t) • (U * V)) + let g : ℝ → Matrix ι ι ℝ := fun t => -(U * NormedSpace.exp ((-t) • (V * U)) * V) + have hd : ∀ t, HasDerivAt f (g t) t := fun t => hasDerivAt_rectangular_exp U V t + have hg : Continuous g := by + fun_prop + have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt + (a := 0) (b := s) (fun t _ => hd t) (hg.intervalIntegrable 0 s) + have hzero : f 0 = 1 := by simp [f, NormedSpace.exp_zero] + rw [hzero] at hi + have hn : ‖∫ t in (0 : ℝ)..s, g t‖ ≤ (‖U‖ * ‖V‖) * s := by + have hb : ∀ t ∈ Set.uIoc 0 s, ‖g t‖ ≤ ‖U‖ * ‖V‖ := by + intro t ht + have ht0 : 0 ≤ t := le_of_lt (Set.mem_Ioc.mp (Set.uIoc_of_le hs ▸ ht)).1 + have he := averaging_shift_exp_bound W hW t ht0 + rw [← hVU] at he + calc + ‖g t‖ = ‖U * NormedSpace.exp ((-t) • (V * U)) * V‖ := norm_neg _ + _ ≤ (‖U‖ * ‖NormedSpace.exp ((-t) • (V * U))‖) * ‖V‖ := + (Matrix.linfty_opNorm_mul _ _).trans + (mul_le_mul_of_nonneg_right (Matrix.linfty_opNorm_mul _ _) (norm_nonneg _)) + _ ≤ (‖U‖ * 1) * ‖V‖ := by gcongr + _ = ‖U‖ * ‖V‖ := by ring + simpa only [sub_zero, abs_of_nonneg hs] using + intervalIntegral.norm_integral_le_of_norm_le_const hb + have ht : f s = 1 + ∫ t in (0 : ℝ)..s, g t := by rw [hi]; abel + calc + ‖f s‖ = ‖1 + ∫ t in (0 : ℝ)..s, g t‖ := congrArg norm ht + _ ≤ ‖(1 : Matrix ι ι ℝ)‖ + ‖∫ t in (0 : ℝ)..s, g t‖ := norm_add_le _ _ + _ ≤ 1 + (‖U‖ * ‖V‖) * s := by rw [norm_one]; gcongr + _ = 1 + s * (‖U‖ * ‖V‖) := by ring + +theorem matrix_norm_le_of_row_abs_sum_le {ι κ : Type*} [Fintype ι] [Fintype κ] + (A : Matrix ι κ ℝ) (c : ℝ) (hc : 0 ≤ c) + (h : ∀ i, ∑ j, |A i j| ≤ c) : ‖A‖ ≤ c := by + rw [Matrix.linfty_opNorm_def] + have hh : (Finset.univ.sup fun i => ∑ j, ‖A i j‖₊) ≤ (⟨c, hc⟩ : ℝ≥0) := by + apply Finset.sup_le + intro i _ + apply NNReal.coe_le_coe.mp + change (↑(∑ j, ‖A i j‖₊) : ℝ) ≤ c + simpa only [NNReal.coe_sum, coe_nnnorm, Real.norm_eq_abs] using h i + exact_mod_cast hh + +def incidenceDegree {ι κ : Type*} [Fintype ι] (U : Matrix ι κ ℝ) (v : κ) : ℝ := + ∑ e, U e v + +noncomputable def starAverage {ι κ : Type*} [Fintype ι] (U : Matrix ι κ ℝ) : + Matrix κ ι ℝ := fun v e => U e v / incidenceDegree U v + +theorem incidence_norm_le_two {ι κ : Type*} [Fintype ι] [Fintype κ] + (U : Matrix ι κ ℝ) (hU : ∀ e v, 0 ≤ U e v) + (hrow : ∀ e, ∑ v, U e v = 2) : ‖U‖ ≤ 2 := by + apply matrix_norm_le_of_row_abs_sum_le U 2 (by norm_num) + intro e + simpa only [abs_of_nonneg (hU e _), hrow e] using le_refl (2 : ℝ) + +theorem starAverage_nonneg {ι κ : Type*} [Fintype ι] + (U : Matrix ι κ ℝ) (hU : ∀ e v, 0 ≤ U e v) (v : κ) (e : ι) : + 0 ≤ starAverage U v e := by + exact div_nonneg (hU e v) (Finset.sum_nonneg fun e _ => hU e v) + +theorem starAverage_row_sum {ι κ : Type*} [Fintype ι] + (U : Matrix ι κ ℝ) (hdeg : ∀ v, 0 < incidenceDegree U v) (v : κ) : + ∑ e, starAverage U v e = 1 := by + simp only [starAverage, ← Finset.sum_div] + change incidenceDegree U v / incidenceDegree U v = 1 + exact div_self (ne_of_gt (hdeg v)) + +theorem starAverage_norm_le_one {ι κ : Type*} [Fintype ι] [Fintype κ] + (U : Matrix ι κ ℝ) (hU : ∀ e v, 0 ≤ U e v) + (hdeg : ∀ v, 0 < incidenceDegree U v) : ‖starAverage U‖ ≤ 1 := by + apply matrix_norm_le_of_row_abs_sum_le _ 1 zero_le_one + intro v + simpa only [abs_of_nonneg (starAverage_nonneg U hU v _), starAverage_row_sum U hdeg] using le_refl (1 : ℝ) + +theorem starAverage_mul_diagonal {ι κ : Type*} [Fintype ι] [Fintype κ] + (U : Matrix ι κ ℝ) (hidem : ∀ e v, U e v * U e v = U e v) + (hdeg : ∀ v, 0 < incidenceDegree U v) (v : κ) : + (starAverage U * U) v v = 1 := by + simp only [Matrix.mul_apply, starAverage] + simp_rw [div_mul_eq_mul_div, hidem] + rw [← Finset.sum_div] + exact div_self (ne_of_gt (hdeg v)) + +theorem starAverage_neighbor_norm {ι κ : Type*} [Fintype ι] [Fintype κ] + [DecidableEq κ] (U : Matrix ι κ ℝ) (hU : ∀ e v, 0 ≤ U e v) + (hidem : ∀ e v, U e v * U e v = U e v) + (hrow : ∀ e, ∑ v, U e v = 2) + (hdeg : ∀ v, 0 < incidenceDegree U v) : ‖starAverage U * U - 1‖ ≤ 1 := by + apply matrix_norm_le_of_row_abs_sum_le _ 1 zero_le_one + intro v + have hnonneg : ∀ w, 0 ≤ (starAverage U * U - (1 : Matrix κ κ ℝ)) v w := by + intro w + by_cases hvw : v = w + · subst w + simp [starAverage_mul_diagonal U hidem hdeg] + · simp only [Matrix.sub_apply, Matrix.one_apply_ne hvw, sub_zero, Matrix.mul_apply] + exact Finset.sum_nonneg fun e _ => mul_nonneg (starAverage_nonneg U hU v e) (hU e w) + have htotal : ∑ w, (starAverage U * U) v w = 2 := by + simp only [Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [← Finset.mul_sum, hrow, ← Finset.sum_mul, starAverage_row_sum U hdeg, one_mul] + calc + ∑ j, |(starAverage U * U - (1 : Matrix κ κ ℝ)) v j| = ∑ j, (starAverage U * U - (1 : Matrix κ κ ℝ)) v j := by + apply Finset.sum_congr rfl + intro j _ + exact abs_of_nonneg (hnonneg j) + _ = 1 := by simp [Matrix.sub_apply, Finset.sum_sub_distrib, htotal, Matrix.one_apply]; norm_num + _ ≤ 1 := le_rfl + +theorem star_semigroup_bound {ι κ : Type*} [Fintype ι] [Fintype κ] + [DecidableEq ι] [DecidableEq κ] [Nonempty ι] [Nonempty κ] + (U : Matrix ι κ ℝ) (hU : ∀ e v, 0 ≤ U e v) + (hidem : ∀ e v, U e v * U e v = U e v) + (hrow : ∀ e, ∑ v, U e v = 2) + (hdeg : ∀ v, 0 < incidenceDegree U v) (s : ℝ) (hs : 0 ≤ s) : + ‖NormedSpace.exp ((-s) • (U * starAverage U))‖ ≤ 1 + 2 * s := by + have hb := rectangular_semigroup_bound U (starAverage U) (starAverage U * U - 1) + (by abel) (starAverage_neighbor_norm U hU hidem hrow hdeg) s hs + calc + _ ≤ 1 + s * (‖U‖ * ‖starAverage U‖) := hb + _ ≤ 1 + s * (2 * 1) := by + gcongr + · exact incidence_norm_le_two U hU hrow + · exact starAverage_norm_le_one U hU hdeg + _ = 1 + 2 * s := by ring + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/IncidentTriangleThird.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/IncidentTriangleThird.lean new file mode 100644 index 0000000000000000000000000000000000000000..060e433ffc1817cd44fa3055b9879928b81c6ea7 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/IncidentTriangleThird.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PowersetCardTriple + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma incidentTriangle_third {n : ℕ} {G : Graph n} {u v : Fin n} + (huv : u ≠ v) {t : Finset (Fin n)} (ht : t ∈ incidentTriangles G {u,v}) : + ∃ w ∈ commonNeighbors G u v, t = {u,v,w} ∧ u ≠ w ∧ v ≠ w := by + obtain ⟨ht,hpair⟩ := Finset.mem_filter.mp ht + obtain ⟨htcard,htG⟩ := mem_triangles.mp ht + have hsub : ({u,v} : Finset (Fin n)) ⊆ t := (Finset.mem_powersetCard.mp hpair).1 + have hc : (t \ {u,v}).card = 1 := by + rw [Finset.card_sdiff_of_subset hsub, htcard, Finset.card_pair huv] + obtain ⟨w,heq⟩ := Finset.card_eq_one.mp hc + have hw : w ∈ t \ {u,v} := by rw [heq]; simp + obtain ⟨hwt,hwuv⟩ := Finset.mem_sdiff.mp hw + have huw : u ≠ w := by intro h; apply hwuv; simp [h] + have hvw : v ≠ w := by intro h; apply hwuv; simp [h] + have htriple : t = {u,v,w} := by + have hu := Finset.sdiff_union_of_subset hsub + rw [heq] at hu + rw [← hu] + ext x + simp only [Finset.mem_union,Finset.mem_insert,Finset.mem_singleton] + tauto + have hcw : w ∈ commonNeighbors G u v := by + apply (mem_commonNeighbors G u v w).mpr + constructor + · apply htG + apply Finset.mem_powersetCard.mpr + exact ⟨by rw [htriple]; simp, Finset.card_pair huw⟩ + · apply htG + apply Finset.mem_powersetCard.mpr + exact ⟨by rw [htriple]; simp, Finset.card_pair hvw⟩ + exact ⟨w,hcw,htriple,huw,hvw⟩ + +lemma incidentTriangles_eq_image {n : ℕ} {G : Graph n} + (hG : G ⊆ completeGraph n) {u v : Fin n} (he : {u,v} ∈ G) : + incidentTriangles G {u,v} = (commonNeighbors G u v).image (fun w => {u,v,w}) := by + have huv : u ≠ v := by + intro h + have hh := mem_completeGraph.mp (hG he) + simp [h] at hh + ext t + constructor + · intro ht + obtain ⟨w,hw,rfl,_,_⟩ := incidentTriangle_third huv ht + exact Finset.mem_image.mpr ⟨w,hw,rfl⟩ + · intro ht + obtain ⟨w,hw,rfl⟩ := Finset.mem_image.mp ht + apply Finset.mem_filter.mpr + refine ⟨(triangle_closure_iff hG huv hw).mpr he,?_⟩ + exact Finset.mem_powersetCard.mpr ⟨by simp,Finset.card_pair huv⟩ + +theorem triangleDegree_eq_codegree {n : ℕ} {G : Graph n} + (hG : G ⊆ completeGraph n) {u v : Fin n} (he : {u,v} ∈ G) : + triangleDegree G {u,v} = currentCodegree G u v := by + unfold triangleDegree currentCodegree + rw [incidentTriangles_eq_image hG he] + apply Finset.card_image_of_injOn + intro a ha b _ hab + change ({u,v,a} : Finset (Fin n)) = {u,v,b} at hab + have ha' : a ∈ ({u,v,b} : Finset (Fin n)) := by rw [← hab]; simp + have hnea := commonNeighbors_ne hG ha + simpa [hnea.1.symm,hnea.2.symm] using ha' + +theorem step_mean_codegree {n : ℕ} {G : Graph n} + (hG : G ⊆ completeGraph n) (hQ : (triangles G).Nonempty) + (u v : Fin n) (huv : u ≠ v) : + pmfMean (step G) (fun H => (currentCodegree H u v : ℝ)) = + (currentCodegree G u v : ℝ) - + (∑ w ∈ commonNeighbors G u v, + ((currentCodegree G u w : ℝ) + currentCodegree G v w - + if {u,v} ∈ G then 1 else 0)) / (triangles G).card := by + rw [step_mean_codegree_hazard G u v hQ] + congr 2 + apply Finset.sum_congr rfl + intro w hw + rw [wedge_hazard_exact hG huv hw] + have hw' := (mem_commonNeighbors G u v w).mp hw + rw [triangleDegree_eq_codegree hG hw'.1, triangleDegree_eq_codegree hG hw'.2] + simp only [triangle_closure_iff hG huv hw] + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedAttachmentOlder.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedAttachmentOlder.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3af9f8b9ff638f0cec2d3a8e44356aac4083da3 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedAttachmentOlder.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.Address +import OAI.Combinatorics.TriangleRemoval.Process.IndexedWitnessCode + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma indexed_attachment_older {K s R : ℕ} {E : Graph K} + {birth : Fin s → Fin K} (hb : ∀ i, (birth i).val = R+i.val) + (hE : E ∈ seedPatternChoices K R) (F : PathForest s) + (f : Fin s → Finset (Fin K)) (hf : f ∈ indexedAttachmentFamily E birth F) : + ∀ i, ∀ x ∈ f i, x.val < (birth i).val := by + have hvalid := (mem_indexedAttachmentFamily E birth F f).mp hf + intro i + induction i using (measure (fun i : Fin s => i.val)).wf.induction with + | h i ih => + intro x hx + have hi := hvalid.2 i + cases hp : F.parent i with + | none => + rw [hp] at hi + have he : f i ∈ rootEdgeUniverse K R := (Finset.mem_powerset.mp (Finset.mem_filter.mp hE).1) hi + have hxr := (mem_initialVertices K R x).mp ((Finset.mem_powersetCard.mp he).1 hx) + rw [hb] + omega + | some p => + rw [hp] at hi + obtain ⟨u,hu,he⟩ := hi + rw [he] at hx + have hpi := F.property i p hp + have hu' := ih p hpi u hu + have hbirth : (birth p).val < (birth i).val := by + rw [hb p,hb i] + omega + rcases Finset.mem_insert.mp hx with rfl | hx + · exact hbirth + · have he := Finset.mem_singleton.mp hx + subst x + exact lt_trans hu' hbirth + +lemma indexed_triangle_key_injective {n K s R : ℕ} {E : Graph K} + {birth : Fin s → Fin K} (hb : ∀ i, (birth i).val = R+i.val) + (hE : E ∈ seedPatternChoices K R) (F : PathForest s) + (f : Fin s → Finset (Fin K)) (hf : f ∈ indexedAttachmentFamily E birth F) + (ψ : Fin K ↪ Fin n) : Function.Injective (indexedTriangleKey birth f ψ) := by + intro i j he + have hi : ψ (birth i) ∈ (indexedTriangleKey birth f ψ j).2 := by + rw [← he] + exact Finset.mem_insert_self _ _ + have hj : ψ (birth j) ∈ (indexedTriangleKey birth f ψ i).2 := by + rw [he] + exact Finset.mem_insert_self _ _ + have hle (a b : Fin s) (h : ψ (birth a) ∈ (indexedTriangleKey birth f ψ b).2) : + a.val ≤ b.val := by + change ψ (birth a) ∈ insert (ψ (birth b)) ((f b).image ψ) at h + rcases Finset.mem_insert.mp h with h | h + · have hh := congrArg Fin.val (ψ.injective h) + rw [hb a,hb b] at hh + omega + · obtain ⟨x,hx,hxe⟩ := Finset.mem_image.mp h + have hxe' := ψ.injective hxe + subst x + have hh := indexed_attachment_older hb hE F f hf b (birth a) hx + rw [hb a,hb b] at hh + omega + exact Fin.ext (Nat.le_antisymm (hle i j hi) (hle j i hj)) + +end SharpTerminalLeave + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedPatternEdges.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedPatternEdges.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f4a01209ff79f4eb403ddd07e9ee184bcefa019 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedPatternEdges.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.BornEdges +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching +import OAI.Combinatorics.TriangleRemoval.Embeddings.PathBirthIndex + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def indexedPatternEdges {K s : ℕ} (E : Finset (Finset (Fin K))) + (birth : Fin s → Fin K) (f : Fin s → Finset (Fin K)) : Finset (Finset (Fin K)) := + E ∪ Finset.univ.biUnion (fun i => (f i).image (fun u => {u,birth i})) + +namespace TriangleGrowth +variable {n N R : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N R) + +theorem pathPattern_edges (a b : Fin N) (hR : R ≤ N) : + (A.pathPattern a b).backEdges Finset.univ = + indexedPatternEdges (A.pathRootEdges a b) (A.pathBirthIndex a b hR) + (A.pathAttachments a b hR) := by + classical + let S := A.pathUnion a b + have hroot : ∀ x : Fin N, x.val < R → x ∈ S := + fun x hx => (A.mem_pathUnion a b x).mpr (Or.inl hx) + ext e + constructor + · intro he + obtain ⟨v,_,u,hu,rfl⟩ := (A.pathPattern a b).backEdges_mem_pair he + by_cases hv : v.val < R + · have hvR : (S.orderEmbOfFin rfl v).val < R := by + rw [orderEmb_initial S hR hroot v hv] + exact hv + have hu' : S.orderEmbOfFin rfl u ∈ A.seed.older (S.orderEmbOfFin rfl v) := by + change u ∈ reindexSet S (A.older (S.orderEmbOfFin rfl v)) at hu + rw [mem_reindexSet] at hu + rwa [A.older_eq_seed hvR] at hu + have hem : ({S.orderEmbOfFin rfl u,S.orderEmbOfFin rfl v} : Finset (Fin N)) ∈ + A.seed.backEdges A.roots := + Finset.mem_biUnion.mpr ⟨_,(A.mem_roots _).mpr hvR,Finset.mem_image.mpr ⟨_,hu',rfl⟩⟩ + apply Finset.mem_union_left + apply Finset.mem_image.mpr + refine ⟨_,hem,?_⟩ + rw [reindexSet_pair S _ _ (S.orderEmbOfFin_mem rfl u) (S.orderEmbOfFin_mem rfl v)] + simp only [PathForest.index_embed] + · have hs : (A.pathUnion a b).card = R + (A.pathSuffix a b R).card := + prefix_suffix_card S hR hroot + let j : Fin (A.pathSuffix a b R).card := ⟨v.val-R,by omega⟩ + have hj : A.pathBirthIndex a b hR j = v := by + apply Fin.ext + simp only [pathBirthIndex_val,j] + omega + apply Finset.mem_union_right + apply Finset.mem_biUnion.mpr + refine ⟨j,Finset.mem_univ _,Finset.mem_image.mpr ⟨u,?_,?_⟩⟩ + · change u ∈ (A.pathPattern a b).older (A.pathBirthIndex a b hR j) + rwa [hj] + · rw [hj] + · intro he + rcases Finset.mem_union.mp he with he | he + · obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he + obtain ⟨v,hv,u,hu,rfl⟩ := A.seed.backEdges_mem_pair hf + have hvR := (A.mem_roots v).mp hv + have huR := A.seed_root v u hu hvR + have hvP := hroot v hvR + have huP := hroot u huR + rw [reindexSet_pair S u v huP hvP] + apply Finset.mem_biUnion.mpr + refine ⟨PathForest.index S v hvP,Finset.mem_univ _,Finset.mem_image.mpr + ⟨PathForest.index S u huP,?_,rfl⟩⟩ + change PathForest.index S u huP ∈ + reindexSet S (A.older (S.orderEmbOfFin rfl (PathForest.index S v hvP))) + rw [mem_reindexSet] + rw [PathForest.embed_index,PathForest.embed_index,A.older_eq_seed hvR] + exact hu + · obtain ⟨i,_,he⟩ := Finset.mem_biUnion.mp he + obtain ⟨u,hu,rfl⟩ := Finset.mem_image.mp he + exact Finset.mem_biUnion.mpr ⟨A.pathBirthIndex a b hR i,Finset.mem_univ _, + Finset.mem_image.mpr ⟨u,hu,rfl⟩⟩ + +theorem pathAssignment_mem_decoded {a b : Fin N} (hR : R ≤ N) + (hi : Set.InjOn A.label (A.pathUnion a b)) + (he : A.birthGraph.ExtraEdge (lookupGraph G) A.label a b) : + A.pathAssignment a b hi ∈ graphEmbeddingSet + (insert ({A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)} : Finset _) + (indexedPatternEdges (A.pathRootEdges a b) (A.pathBirthIndex a b hR) + (A.pathAttachments a b hR))) G := by + rw [← A.pathPattern_edges a b hR] + exact A.pathAssignment_mem hi he + +end TriangleGrowth +end SharpTerminalLeave + +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedWitnessCode.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedWitnessCode.lean new file mode 100644 index 0000000000000000000000000000000000000000..472acc5a9029a3f74ceee40da0dbf8ee6437d720 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedWitnessCode.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.SuffixProjection +import OAI.Combinatorics.TriangleRemoval.Process.IndexedPatternEdges + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +abbrev IndexedWitnessCode {K s : ℕ} (E : Graph K) (birth : Fin s → Fin K) + (mark : Fin K → Option (Fin s)) := + Σ ab : Fin K × Fin K, + Σ F : {F : PathForest s // ∀ i, F.OnPath (mark ab.1) i ∨ F.OnPath (mark ab.2) i}, + {f // f ∈ indexedAttachmentFamily E birth F.val} + +noncomputable instance {K s : ℕ} (E : Graph K) (birth : Fin s → Fin K) + (mark : Fin K → Option (Fin s)) : Fintype (IndexedWitnessCode E birth mark) := by + classical + unfold IndexedWitnessCode + infer_instance + +def decodeWitnessPattern {K s : ℕ} {E : Graph K} {birth : Fin s → Fin K} + {mark : Fin K → Option (Fin s)} (w : IndexedWitnessCode E birth mark) : + (Fin K × Fin K) × Graph K := + (w.1,insert {w.1.1,w.1.2} (indexedPatternEdges E birth w.2.2.val)) + +noncomputable def decodedWitnessPatterns {K s : ℕ} (E : Graph K) (birth : Fin s → Fin K) + (mark : Fin K → Option (Fin s)) : Finset ((Fin K × Fin K) × Graph K) := by + classical + exact Finset.univ.image (decodeWitnessPattern (E := E) (birth := birth) (mark := mark)) + +lemma decodedWitnessPatterns_card {K s : ℕ} (E : Graph K) (birth : Fin s → Fin K) + (hE : E.card ≤ 2) (mark : Fin K → Option (Fin s)) : + (decodedWitnessPatterns E birth mark).card ≤ K^2*6^s := by + classical + apply (Finset.card_image_le).trans + rw [Finset.card_univ] + simpa only [Fintype.card_fin] using + all_marked_indexed_attachment_pattern_count E birth hE mark + +def rootEdgeUniverse (K R : ℕ) : Graph K := (initialVertices K R).powersetCard 2 + +def seedPatternChoices (K R : ℕ) : Finset (Graph K) := + (rootEdgeUniverse K R).powerset.filter (fun E => E.card ≤ 2) + +lemma seedPatternChoices_card {K R : ℕ} (hR : R ≤ K) (h4 : R ≤ 4) : + (seedPatternChoices K R).card ≤ 64 := by + have hc : (initialVertices K R).card = R := by + simp only [initialVertices,Fin.card_filter_val_lt,Nat.min_eq_right hR] + calc + _ ≤ ((rootEdgeUniverse K R).powerset).card := Finset.card_filter_le _ _ + _ = 2^(R.choose 2) := by rw [Finset.card_powerset,rootEdgeUniverse,Finset.card_powersetCard,hc] + _ ≤ 2^((4 : ℕ).choose 2) := Nat.pow_le_pow_right (by norm_num) (Nat.choose_le_choose 2 h4) + _ = 64 := by decide + +noncomputable def allDecodedWitnessPatterns {K s : ℕ} (R : ℕ) (birth : Fin s → Fin K) + (mark : Fin K → Option (Fin s)) : Finset ((Fin K × Fin K) × Graph K) := + (seedPatternChoices K R).biUnion (fun E => decodedWitnessPatterns E birth mark) + +lemma allDecodedWitnessPatterns_card {K s R : ℕ} (hR : R ≤ K) (h4 : R ≤ 4) + (birth : Fin s → Fin K) (mark : Fin K → Option (Fin s)) : + (allDecodedWitnessPatterns R birth mark).card ≤ 64*(K^2*6^s) := by + classical + apply (Finset.card_biUnion_le).trans + calc + _ ≤ ∑ _E ∈ seedPatternChoices K R, K^2*6^s := by + apply Finset.sum_le_sum + intro E hE + exact decodedWitnessPatterns_card E birth (Finset.mem_filter.mp hE).2 mark + _ = (seedPatternChoices K R).card * (K^2*6^s) := by simp only [Finset.sum_const,smul_eq_mul] + _ ≤ 64*(K^2*6^s) := Nat.mul_le_mul_right _ (seedPatternChoices_card hR h4) + +namespace TriangleGrowth +variable {n N R : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N R) + +lemma pathRootEdges_mem_seedPatternChoices (a b : Fin N) (hR : R ≤ N) + (hE : (A.seed.backEdges A.roots).card ≤ 2) : + A.pathRootEdges a b ∈ seedPatternChoices (A.pathUnion a b).card R := by + classical + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_powerset.mpr ?_,(A.pathRootEdges_count a b).trans hE⟩ + intro edge hedge + obtain ⟨seedEdge,hseedEdge,rfl⟩ := Finset.mem_image.mp hedge + obtain ⟨later,hlater,earlier,hearlier,rfl⟩ := A.seed.backEdges_mem_pair hseedEdge + have hlaterRoot := (A.mem_roots later).mp hlater + have hearlierRoot := A.seed_root later earlier hearlier hlaterRoot + have hroot : ∀ vertex : Fin N, vertex.val < R → vertex ∈ A.pathUnion a b := + fun vertex hvertex => (A.mem_pathUnion a b vertex).mpr (Or.inl hvertex) + have hsubset : ({earlier,later} : Finset (Fin N)) ⊆ A.pathUnion a b := by + intro vertex hvertex + simp only [Finset.mem_insert,Finset.mem_singleton] at hvertex + rcases hvertex with rfl | rfl + · exact hroot _ hearlierRoot + · exact hroot _ hlaterRoot + apply Finset.mem_powersetCard.mpr + refine ⟨?_,(reindexSet_card hsubset).trans + (Finset.card_pair (ne_of_lt (A.seed.older_lt later earlier hearlier)))⟩ + intro vertex hvertex + apply (mem_initialVertices _ _ _).mpr + have hembedded := (mem_reindexSet _ _ _).mp hvertex + have hembeddedRoot : ((A.pathUnion a b).orderEmbOfFin rfl vertex).val < R := by + simp only [Finset.mem_insert,Finset.mem_singleton] at hembedded + rcases hembedded with hearlierEq | hlaterEq + · simpa only [hearlierEq] using hearlierRoot + · simpa only [hlaterEq] using hlaterRoot + let rootIndex : Fin (A.pathUnion a b).card := + ⟨((A.pathUnion a b).orderEmbOfFin rfl vertex).val, + hembeddedRoot.trans_le (roots_le_card _ hR hroot)⟩ + have hequal : rootIndex = vertex := by + apply ((A.pathUnion a b).orderEmbOfFin rfl).injective + exact Fin.ext (orderEmb_initial _ hR hroot rootIndex hembeddedRoot) + rw [← hequal] + exact hembeddedRoot + +lemma actual_decoded_pattern_mem (a b : Fin N) (hR : R ≤ N) + (hE : (A.seed.backEdges A.roots).card ≤ 2) : + ((A.pathIndex a b a (A.left_mem_pathUnion a b),A.pathIndex a b b (A.right_mem_pathUnion a b)), + insert ({A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)} : Finset _) ((A.pathPattern a b).backEdges Finset.univ)) ∈ + allDecodedWitnessPatterns R (A.pathBirthIndex a b hR) (suffixProjection (A.path_card_split a b hR)) := by + classical + apply Finset.mem_biUnion.mpr + refine ⟨A.pathRootEdges a b,A.pathRootEdges_mem_seedPatternChoices a b hR hE,?_⟩ + apply Finset.mem_image.mpr + refine ⟨A.pathWitnessCode a b hR,Finset.mem_univ _,?_⟩ + apply Prod.ext + · rfl + · change insert _ (indexedPatternEdges _ _ _) = insert _ _ + rw [A.pathPattern_edges a b hR] + rfl + +end TriangleGrowth +end SharpTerminalLeave + +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedWitnessCodeCard.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedWitnessCodeCard.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a588ff8e2e61d45419025d8a0919a3561c530ce --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/IndexedWitnessCodeCard.lean @@ -0,0 +1,80 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.WitnessEmbeddingBound + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma indexedWitnessCode_card_bound {K s : ℕ} (E : Graph K) (birth : Fin s → Fin K) + (hE : E.card ≤ 2) (mark : Fin K → Option (Fin s)) : + Fintype.card (IndexedWitnessCode E birth mark) ≤ K^2*6^s := by + simpa only [Fintype.card_fin] using all_marked_indexed_attachment_pattern_count E birth hE mark + +lemma boundedEmbeddedWitness_weight_sum {n R d : ℕ} (G : Graph n) (r : ℕ) + (hR : R ≤ 4) (hm : 0 ≤ prefixM n) (v : WitnessDimensions R d → ℝ) + (hv : ∀ q, 0 ≤ v q) : + (∑ W : BoundedEmbeddedWitness G R d, if WitnessEmbeddingBound r W then v W.1 else 0) ≤ + ∑ q : WitnessDimensions R d, + 64*(q.val.1.val^2*6^q.val.2.val : ℕ) * + ((4*prefixM n)^r*(2*prefixD n)^q.val.2.val/prefixD n^50)*v q := by + classical + have hD : 0 ≤ prefixD n := by unfold prefixD; positivity + let B (q : WitnessDimensions R d) := + (4*prefixM n)^r*(2*prefixD n)^q.val.2.val/prefixD n^50 + have hB (q : WitnessDimensions R d) : 0 ≤ B q := by dsimp only [B]; positivity + rw [Fintype.sum_sigma] + apply Finset.sum_le_sum + intro q _ + rw [Fintype.sum_sigma] + have hqR : R ≤ q.val.1.val := by have h := q.property; omega + calc + _ ≤ ∑ E : {E : Graph q.val.1 // E ∈ seedPatternChoices q.val.1 R}, + (q.val.1.val^2*6^q.val.2.val : ℕ)*B q*v q := by + apply Finset.sum_le_sum + intro E _ + let Code := IndexedWitnessCode E.val (dimensionBirth q) (suffixProjection q.property) + have hc := indexedWitnessCode_card_bound E.val (dimensionBirth q) + (Finset.mem_filter.mp E.property).2 (suffixProjection q.property) + rw [Fintype.sum_sigma] + calc + _ ≤ ∑ _w : Code, B q*v q := by + apply Finset.sum_le_sum + intro w _ + change (∑ _ψ : {ψ : Fin q.val.1 ↪ Fin n // + ψ ∈ graphEmbeddingSet (decodeWitnessPattern w).2 G}, + if ((graphEmbeddingSet (decodeWitnessPattern w).2 G).card : ℝ) ≤ B q + then v q else 0) ≤ B q*v q + by_cases hh : ((graphEmbeddingSet (decodeWitnessPattern w).2 G).card : ℝ) ≤ B q + · simp only [hh,ite_true,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] + exact mul_le_mul_of_nonneg_right hh (hv q) + · simp only [hh,ite_false,Finset.sum_const_zero] + exact mul_nonneg (hB q) (hv q) + _ = (Fintype.card Code : ℝ)*B q*v q := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_assoc] + _ ≤ _ := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (Nat.cast_le.mpr hc) (hB q)) (hv q) + _ = (seedPatternChoices q.val.1 R).card * + ((q.val.1.val^2*6^q.val.2.val : ℕ)*B q*v q) := by + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] + _ ≤ 64*((q.val.1.val^2*6^q.val.2.val : ℕ)*B q*v q) := by + exact mul_le_mul_of_nonneg_right (Nat.cast_le.mpr (seedPatternChoices_card hqR hR)) + (mul_nonneg (mul_nonneg (by positivity) (hB q)) (hv q)) + _ = _ := by dsimp only [B]; ring + +end SharpTerminalLeave + +open scoped BigOperators Topology +open Filter + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSet.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..51c4fab0161ace2326ef3f5c499e263264b6a1c3 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSet.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Process.BornEdges +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEmbeddings +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N n : ℕ} (B : BirthGraph N) (G : Graph n) + +lemma graph_edge_mem {i j : Fin N} (hij : B.graph.Adj i j) : + ({i,j} : Finset (Fin N)) ∈ B.backEdges Finset.univ := by + rcases hij with h | h + · exact Finset.mem_biUnion.mpr ⟨j,Finset.mem_univ _,Finset.mem_image.mpr ⟨i,h,rfl⟩⟩ + · rw [Finset.pair_comm] + exact Finset.mem_biUnion.mpr ⟨i,Finset.mem_univ _,Finset.mem_image.mpr ⟨j,h,rfl⟩⟩ + +noncomputable def initialAssignmentSet (k : ℕ) (hk : k ≤ N) : + Finset ({x // x ∈ initialVertices N k} ↪ Fin n) := by + classical + exact (prefixEmbeddings B.graph (lookupGraph G) k hk).image initialSubtypeLabel + +open Classical in + +lemma initialAssignmentSet_card (k : ℕ) (hk : k ≤ N) : + (B.initialAssignmentSet G k hk).card ≤ + (prefixEmbeddings B.graph (lookupGraph G) k hk).card := by + classical + exact Finset.card_image_le + +theorem initialLabel_mem {a b : Fin N} {φ : Fin N ↪ Fin n} + (hφ : φ ∈ graphEmbeddingSet + (insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ)) G) + (k : ℕ) (hk : k ≤ N) : + restrictLabel (initialVertices N k) φ ∈ B.initialAssignmentSet G k hk := by + classical + refine Finset.mem_image.mpr ⟨initialLabel hk φ,?_,initialSubtypeLabel_initialLabel hk φ⟩ + apply (mem_prefixEmbeddings _).mpr + intro i j hij + refine ⟨φ.injective.ne (B.graph.ne_of_adj hij),?_⟩ + have he := B.graph_edge_mem hij + have hm := (Finset.mem_filter.mp hφ).2 (Finset.mem_image.mpr + ⟨_,Finset.mem_insert_of_mem he,rfl⟩) + change ({φ (Fin.castLE hk i), φ (Fin.castLE hk j)} : Finset (Fin n)) ∈ G + simpa only [Finset.map_insert,Finset.map_singleton] using hm + +theorem two_preceding_neighbors (R : ℕ) + (hb : ∀ v : Fin N, R ≤ v.val → (B.older v).card = 2) + (k : ℕ) (hR : R ≤ k) (hk : k+1 ≤ N) : + ∃ u v : Fin k, u ≠ v ∧ + B.graph.Adj (Fin.castLE (by omega) u) ⟨k,by omega⟩ ∧ + B.graph.Adj (Fin.castLE (by omega) v) ⟨k,by omega⟩ := by + obtain ⟨u,v,huv,he⟩ := Finset.card_eq_two.mp (hb ⟨k,by omega⟩ hR) + have hu : u ∈ B.older ⟨k,by omega⟩ := by rw [he]; simp + have hv : v ∈ B.older ⟨k,by omega⟩ := by rw [he]; simp + have huk : u.val < k := B.older_lt _ u hu + have hvk : v.val < k := B.older_lt _ v hv + refine ⟨⟨u.val,huk⟩,⟨v.val,hvk⟩,?_,Or.inl hu,Or.inl hv⟩ + intro hh + exact huv (Fin.ext (congrArg (fun z : Fin k => z.val) hh)) + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSetBound.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSetBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0730413fc7ea5c811f970f83d9704511c5b7acf --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSetBound.lean @@ -0,0 +1,104 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Embeddings.SuffixTemplate +import OAI.Combinatorics.TriangleRemoval.Process.InitialAssignmentSet +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEmbeddingsAfterRoots +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraphDegree + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N n : ℕ} (B : BirthGraph N) + +theorem initialAssignmentSet_bound {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (hsmall : (n : ℝ)^(-c) ≤ 1) + (hp : 0 ≤ prefixDensity n) (r k : ℕ) (hrk : 2*r ≤ k) (hk : k ≤ N) + (hroot : ∀ i (hi : i < r), B.graph.Adj ⟨2*i,by omega⟩ ⟨2*i+1,by omega⟩) + (hborn : ∀ v : Fin N, 2*r ≤ v.val → (B.older v).card = 2) : + ((B.initialAssignmentSet G k hk).card : ℝ) ≤ + (4 * prefixM n)^r * (2 * prefixD n)^(k-2*r) := by + classical + have hD0 : 0 ≤ 2 * prefixD n := by unfold prefixD; positivity + have hΔ0 : 0 ≤ 2 * (n : ℝ) * prefixDensity n := by positivity + have hgrow := prefixEmbeddings_after_roots B.graph (lookupGraph G) (2*r) k hrk hk + (2 * prefixD n) hD0 (goodPrefix_codegree_bound hGood hsmall) + (fun i hi hN => B.two_preceding_neighbors (2*r) hborn i hi hN) + have hroots := prefixEmbeddings_matching_roots B.graph (lookupGraph G) r (hrk.trans hk) + (2 * ((n : ℝ) * prefixDensity n)) (by nlinarith) + (goodPrefix_degree_bound hGood hsmall hp) hroot + have hid : (n : ℝ) * (2 * ((n : ℝ) * prefixDensity n)) = 4 * prefixM n := by + unfold prefixM + ring + simp only [Fintype.card_fin,hid] at hroots + exact (Nat.cast_le.mpr (B.initialAssignmentSet_card G k hk)).trans + (hgrow.trans (mul_le_mul_of_nonneg_right hroots (pow_nonneg hD0 _))) + +theorem long_witness_count {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (hsmall : (n : ℝ)^(-c) ≤ 1) + (r k : ℕ) (hrk : 2*r ≤ k) (hk : k ≤ N) + (hroot : ∀ i (hi : i < r), B.graph.Adj ⟨2*i,by omega⟩ ⟨2*i+1,by omega⟩) + (hborn : ∀ v : Fin N, 2*r ≤ v.val → (B.older v).card = 2) + {a b : Fin N} (hab : a ≠ b) (hne : ¬ B.graph.Adj a b) + (hmark : k ≤ a.val ∨ k ≤ b.val) + (hc : B.Covered (Finset.univ.filter (fun x => k ≤ x.val)) a b) + (hcap : 3 * (N-k) + 1 ≤ prefixTemplateCap) + (hp : 0 ≤ prefixDensity n) (hp1 : prefixDensity n ≤ 1) (hD : 1 ≤ prefixD n) + (hscale : (n : ℝ)^(N-k) * prefixDensity n ^ (2*(N-k)+1) ≤ 1) : + ((graphEmbeddingSet (insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ)) G).card : ℝ) ≤ + prefixTemplateFactor n C * ((4 * prefixM n)^r * (2 * prefixD n)^(k-2*r)) := by + classical + let Z : Finset (Fin N) := Finset.univ.filter (fun x => k ≤ x.val) + have hZ : Z.card = N-k := by + have heq : Z = Finset.univ \ (Finset.univ.filter (fun x : Fin N => x.val < k)) := by + ext x + simp only [Z,Finset.mem_filter,Finset.mem_sdiff,Finset.mem_univ,true_and,not_lt] + rw [heq,Finset.card_sdiff_of_subset (Finset.filter_subset _ _),Finset.card_univ, + Fintype.card_fin,Fin.card_filter_val_lt,Nat.min_eq_right hk] + have hm : a ∈ Z ∨ b ∈ Z := by simpa only [Z,Finset.mem_filter,Finset.mem_univ,true_and] using hmark + have hb : ∀ v ∈ Z, (B.older v).card = 2 := by + intro v hv + exact hborn v (hrk.trans (Finset.mem_filter.mp hv).2) + have hIP : B.suffixBoundary Z a b ⊆ initialVertices N k := by + intro x hx + have hnZ := (B.mem_suffixBoundary Z a b x).mp hx |>.2 + simp only [Z,Finset.mem_filter,Finset.mem_univ,true_and,not_le] at hnZ + exact (mem_initialVertices N k x).mpr hnZ + have hcover : initialVertices N k ∪ B.suffixVertices Z a b = Finset.univ := by + apply Finset.eq_univ_iff_forall.mpr + intro x + by_cases hx : x.val < k + · exact Finset.mem_union_left _ ((mem_initialVertices N k x).mpr hx) + · exact Finset.mem_union_right _ (Finset.mem_union_left _ + (Finset.mem_filter.mpr ⟨Finset.mem_univ _,by omega⟩)) + have hEF : B.suffixEdges Z a b ⊆ + insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ) := by + apply Finset.insert_subset_insert + exact Finset.biUnion_subset_biUnion_of_subset_left _ (Finset.subset_univ Z) + have hf := graphEmbeddingSet_count_glue (B.suffixVertices Z a b) (B.suffixBoundary Z a b) + (initialVertices N k) (B.suffixEdges Z a b) _ G B.suffixEdges_subset_vertices + (B.suffixEdges_simple hab) (B.suffixBoundary_independent hm) hIP hcover hEF + (B.initialAssignmentSet G k hk) (fun φ hφ => B.initialLabel_mem G hφ k hk) + (prefixTemplateFactor n C) (by + intro ξ _ + exact B.suffixTemplate_count hGood hab hm hb hne hc (hZ ▸ hcap) hp hp1 hD + (hZ ▸ hscale) _) + have hκ : 0 ≤ prefixTemplateFactor n C := by + unfold prefixTemplateFactor + positivity + exact hf.trans (mul_le_mul_of_nonneg_left + (B.initialAssignmentSet_bound hGood hsmall hp r k hrk hk hroot hborn) hκ) + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSetMatching.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSetMatching.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e1246e2aabd4ea304276c4966441ee35c161c0f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/InitialAssignmentSetMatching.lean @@ -0,0 +1,53 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Process.InitialAssignmentSet +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEmbeddingsAfterRoots +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraphDegree +import OAI.Combinatorics.TriangleRemoval.Process.OrientedEdges + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N n : ℕ} (B : BirthGraph N) + +theorem initialAssignmentSet_matching_bound {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (hsmall : (n : ℝ)^(-c) ≤ 1) + (r k : ℕ) (hrk : 2*r ≤ k) (hk : k ≤ N) + (u v : Fin r → Fin (2*r)) + (hcover : ∀ i : Fin (2*r), ∃ j, i = u j ∨ i = v j) + (hroot : ∀ j, B.graph.Adj (Fin.castLE (hrk.trans hk) (u j)) + (Fin.castLE (hrk.trans hk) (v j))) + (hborn : ∀ x : Fin N, 2*r ≤ x.val → (B.older x).card = 2) : + ((B.initialAssignmentSet G k hk).card : ℝ) ≤ + (2 * prefixM n)^r * (2 * prefixD n)^(k-2*r) := by + classical + have hD0 : 0 ≤ 2 * prefixD n := by unfold prefixD; positivity + have hsimple : ∀ e ∈ G, e.card = 2 := by + intro e he + exact (Finset.mem_powersetCard.mp (hGood.1 he)).2 + have hgrow := prefixEmbeddings_after_roots B.graph (lookupGraph G) (2*r) k hrk hk + (2 * prefixD n) hD0 (goodPrefix_codegree_bound hGood hsmall) + (fun i hi hN => B.two_preceding_neighbors (2*r) hborn i hi hN) + have hroots := prefixEmbeddings_root_cover B.graph G hsimple (hrk.trans hk) u v hcover hroot + have hrootsR : ((prefixEmbeddings B.graph (lookupGraph G) (2*r) (hrk.trans hk)).card : ℝ) ≤ + (2 * prefixM n)^r := by + have hh : ((prefixEmbeddings B.graph (lookupGraph G) (2*r) (hrk.trans hk)).card : ℝ) ≤ + (2 * (G.card : ℝ))^r := by exact_mod_cast hroots + rwa [hGood.2.1] at hh + exact (Nat.cast_le.mpr (B.initialAssignmentSet_card G k hk)).trans + (hgrow.trans (mul_le_mul_of_nonneg_right hrootsR (pow_nonneg hD0 _))) + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/LevelDeletes.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/LevelDeletes.lean new file mode 100644 index 0000000000000000000000000000000000000000..b91505b261e6b76ac86b9f37692ac247c1a3bc9d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/LevelDeletes.lean @@ -0,0 +1,149 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.TreeBind + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators +open scoped BigOperators ENNReal Classical + +namespace SharpTerminalLeave +namespace ExposureTree +variable {K V O A : Type*} + +@[simp] theorem evaluate_exposeLabeled (ω : K → V) (key : A → K) (as : List A) : + evaluate ω (exposeLabeled key as) = as.map (fun a => (a, ω (key a))) := by + induction as with + | nil => rfl + | cons a as ih => simp only [exposeLabeled, evaluate, evaluate_bind, ih, List.map_cons] + +@[simp] theorem evaluate_checkNone (ω : K → V) (as : List (ExposureTree K V Bool)) : + evaluate ω (checkNone as) = true ↔ ∀ A ∈ as, evaluate ω A = false := by + induction as with + | nil => simp [checkNone, evaluate] + | cons A as ih => + simp only [checkNone, evaluate_bind, List.mem_cons, forall_eq_or_imp] + cases h : evaluate ω A <;> simp [evaluate, ih] + +end ExposureTree + +section TimeScan +variable {ι τ : Type*} [DecidableEq ι] [Fintype τ] [DecidableEq τ] + +def levelDeletes (H : τ → Finset ι) (ω : τ → ℕ) (G : Finset ι) (k : ℕ) : Finset ι := + (Finset.univ.filter (fun T => ω T = k ∧ H T ⊆ G)).biUnion H + +def timeScan (H : τ → Finset ι) (ω : τ → ℕ) (E : Finset ι) : ℕ → Finset ι + | 0 => E + | k + 1 => timeScan H ω E k \ levelDeletes H ω (timeScan H ω E k) k + +omit [DecidableEq τ] in +@[simp] theorem mem_levelDeletes (H : τ → Finset ι) (ω : τ → ℕ) (G : Finset ι) (k : ℕ) + (e : ι) : e ∈ levelDeletes H ω G k ↔ ∃ T, ω T = k ∧ H T ⊆ G ∧ e ∈ H T := by + simp only [levelDeletes, Finset.mem_biUnion, Finset.mem_filter, Finset.mem_univ, + true_and] + aesop + +omit [DecidableEq τ] in +theorem timeScan_subset_initial (H : τ → Finset ι) (ω : τ → ℕ) (E : Finset ι) (k : ℕ) : + timeScan H ω E k ⊆ E := by + induction k with + | zero => exact Finset.Subset.refl E + | succ k ih => exact Finset.sdiff_subset.trans ih + +omit [DecidableEq τ] in + +theorem timeScan_mem_iff (H : τ → Finset ι) (ω : τ → ℕ) (E : Finset ι) (k : ℕ) (e : ι) : + e ∈ timeScan H ω E k ↔ e ∈ E ∧ + ∀ T, ω T < k → e ∈ H T → ¬ (H T).erase e ⊆ timeScan H ω E (ω T) := by + induction k with + | zero => simp [timeScan] + | succ k ih => + simp only [timeScan, Finset.mem_sdiff, mem_levelDeletes, not_exists, not_and] + constructor + · intro he + obtain ⟨heE, hePast⟩ := ih.mp he.1 + refine ⟨heE, fun T hTk heT hsub => ?_⟩ + by_cases hlt : ω T < k + · exact hePast T hlt heT hsub + · have ht : ω T = k := by omega + apply he.2 T ht + · intro f hf + by_cases hfe : f = e + · simpa [hfe] using he.1 + · exact (ht ▸ hsub) (Finset.mem_erase.mpr ⟨hfe, hf⟩) + · exact heT + · rintro ⟨heE, hePast⟩ + have hek : e ∈ timeScan H ω E k := ih.mpr ⟨heE, fun T hT => hePast T (by omega)⟩ + refine ⟨hek, fun T ht hsub heT => ?_⟩ + apply hePast T (by omega) heT + rw [ht] + exact (Finset.erase_subset e (H T)).trans hsub + +theorem evaluate_gridQueryDepth_succ (H : τ → Finset ι) (N d k : ℕ) + (ω : τ → Fin N) (focus : Finset ι) (parent : Option τ) : + ExposureTree.evaluate ω (gridQueryDepth H N (d + 1) k focus parent) = true ↔ + ∀ e ∈ focus, ∀ T, e ∈ H T → some T ≠ parent → (ω T).val < k → + ExposureTree.evaluate ω + (gridQueryDepth H N d (ω T).val ((H T).erase e) (some T)) = false := by + simp only [gridQueryDepth, ExposureTree.evaluate_bind, ExposureTree.evaluate_exposeLabeled, + ExposureTree.evaluate_checkNone, List.mem_map, forall_exists_index, and_imp, + forall_apply_eq_imp_iff₂, List.mem_mergeSort, Finset.mem_toList] + constructor + · intro h e he T heT hp ht + have hm : (e, T) ∈ gridCandidates H focus parent := by + simp [gridCandidates, he, heT, hp] + have hh := h (e, T) hm + simpa only [ht, ↓reduceIte] using hh + · intro h a ha + have ha' : a.1 ∈ focus ∧ a.1 ∈ H a.2 ∧ some a.2 ≠ parent := by + simpa [gridCandidates] using ha + by_cases ht : (ω a.2).val < k + · simpa only [ht, ↓reduceIte] using h a.1 ha'.1 a.2 ha'.2.1 ha'.2.2 ht + · simp [ht, ExposureTree.evaluate] + +theorem evaluate_gridQueryDepth_iff (H : τ → Finset ι) (N d k : ℕ) + (ω : τ → Fin N) (E focus : Finset ι) (parent : Option τ) + (hk : k ≤ d) (hfocus : focus ⊆ E) (hH : ∀ T, H T ⊆ E) + (hparent : ∀ T, some T = parent → k ≤ (ω T).val) : + ExposureTree.evaluate ω (gridQueryDepth H N d k focus parent) = true ↔ + focus ⊆ timeScan H (fun T => (ω T).val) E k := by + induction d generalizing k focus parent with + | zero => + have hk0 : k = 0 := by omega + subst k + simp only [gridQueryDepth, ExposureTree.evaluate_bind, ExposureTree.evaluate, + timeScan, true_iff] + exact hfocus + | succ d ih => + rw [evaluate_gridQueryDepth_succ] + constructor + · intro h e he + apply (timeScan_mem_iff H (fun T => (ω T).val) E k e).mpr + refine ⟨hfocus he, fun T hTk heT hsub => ?_⟩ + have hp : some T ≠ parent := by + intro hh + have := hparent T hh + omega + have hf := h e he T heT hp hTk + have ht := (ih (ω T).val ((H T).erase e) (some T) (by omega) + ((Finset.erase_subset e (H T)).trans (hH T)) (fun S hS => by cases Option.some.inj hS; rfl)).mpr hsub + rw [ht] at hf + contradiction + · intro hs e he T heT _ hTk + apply Bool.eq_false_iff.mpr + intro ht + have hsub := (ih (ω T).val ((H T).erase e) (some T) (by omega) + ((Finset.erase_subset e (H T)).trans (hH T)) (fun S hS => by cases Option.some.inj hS; rfl)).mp ht + exact ((timeScan_mem_iff H (fun T => (ω T).val) E k e).mp (hs he)).2 T hTk heT hsub + +end TimeScan +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/LinkSimpleGraph.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/LinkSimpleGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..07efabcfb9464081deb60b4fef4c78f6e46f6c79 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/LinkSimpleGraph.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEpsilon +import OAI.Combinatorics.TriangleRemoval.Embeddings.GraphEmbeddings + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators NNReal +open Matrix +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix InnerProductSpace +open scoped BigOperators + +namespace SharpTerminalLeave + +def linkSimpleGraph {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) : + SimpleGraph (neighbors G u) where + Adj x y := {x.val, y.val} ∈ G + symm := ⟨by intro x y h; simpa only [Finset.pair_comm] using h⟩ + loopless := ⟨by + intro x h + have hh := mem_completeGraph.mp (hG h) + simp at hh⟩ + +instance linkSimpleGraph_decidable {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) : + DecidableRel (linkSimpleGraph G hG u).Adj := fun _ _ => inferInstanceAs (Decidable (_ ∈ G)) + +@[simp] theorem linkSimpleGraph_adj {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (u : Fin n) (v w : neighbors G u) : + (linkSimpleGraph G hG u).Adj v w ↔ {v.val,w.val} ∈ G := Iff.rfl + +theorem cycleNext_eq_add_one {j : ℕ} (i : Fin (j+2)) : cycleNext i = i + 1 := by + apply Fin.ext + simp [cycleNext, Fin.add_def] + +theorem cycleGraph_adj_next {j : ℕ} (i k : Fin (j+2)) : + (SimpleGraph.cycleGraph (j+2)).Adj i k ↔ i = cycleNext k ∨ k = cycleNext i := by + rw [SimpleGraph.cycleGraph_adj] + simp only [cycleNext_eq_add_one, sub_eq_iff_eq_add, add_comm] + +theorem link_neighbor_map {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (u : Fin n) (v : neighbors G u) : + (Finset.univ.filter ((linkSimpleGraph G hG u).Adj v)).map + (Function.Embedding.subtype _) = commonNeighbors G u v.val := by + ext w + simp only [Finset.mem_map, Finset.mem_filter, Finset.mem_univ, true_and, + linkSimpleGraph_adj, mem_commonNeighbors, Function.Embedding.subtype_apply] + constructor + · rintro ⟨x,hx,rfl⟩ + exact ⟨(Finset.mem_filter.mp x.property).2,hx⟩ + · rintro ⟨hu,hv⟩ + exact ⟨⟨w,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hu⟩⟩,hv,rfl⟩ + +theorem link_degree_eq {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) + (u : Fin n) (v : neighbors G u) : + (Finset.univ.filter ((linkSimpleGraph G hG u).Adj v)).card = currentCodegree G u v.val := by + rw [← Finset.card_map (Function.Embedding.subtype _), link_neighbor_map] + rfl + +theorem linkCycleCount_eq_graphEmbeddings {n j : ℕ} (G : Graph n) + (hG : G ⊆ completeGraph n) (u : Fin n) : + linkCycleCount (j+2) G u = + ((graphEmbeddings (SimpleGraph.cycleGraph (j+2)) (linkSimpleGraph G hG u)).card : ℝ) := by + classical + let S : Finset (Fin (j+2) ↪ Fin n) := Finset.univ.filter (fun φ => + ∀ i, {u,φ i} ∈ G ∧ {φ i,φ (cycleNext i)} ∈ G) + have heq : linkCycleCount (j+2) G u = (S.card : ℝ) := by + simp [linkCycleCount,S,Finset.sum_boole] + rw [heq] + congr 1 + symm + apply Finset.card_bij (fun (f : Fin (j+2) ↪ neighbors G u) _ => + f.trans (Function.Embedding.subtype _)) + · intro f hf + have hf' := (mem_graphEmbeddings f).mp hf + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _,fun i => ⟨?_,?_⟩⟩ + · exact (Finset.mem_filter.mp (f i).property).2 + · exact hf' i (cycleNext i) ((cycleGraph_adj_next i (cycleNext i)).mpr (Or.inr rfl)) + · intro f hf g hg hfg + apply Function.Embedding.ext + intro i + apply Subtype.ext + exact congrArg (fun (e : Fin (j+2) ↪ Fin n) => e i) hfg + · intro φ hφ + have hφ' := (Finset.mem_filter.mp hφ).2 + let f : Fin (j+2) ↪ neighbors G u := + ⟨fun i => ⟨φ i,Finset.mem_filter.mpr ⟨Finset.mem_univ _,(hφ' i).1⟩⟩, + fun a b h => φ.injective (congrArg Subtype.val h)⟩ + refine ⟨f,?_,?_⟩ + · apply (mem_graphEmbeddings f).mpr + intro a b hab + rcases (cycleGraph_adj_next a b).mp hab with hab | hab + · change {φ a,φ b} ∈ G + rw [hab,Finset.pair_comm] + exact (hφ' b).2 + · change {φ a,φ b} ∈ G + rw [hab] + exact (hφ' a).2 + · rfl + +theorem goodPrefix_link_rows {n : ℕ} {G : Graph n} {c C : ℝ} + (h : GoodPrefixGraph n c C G) (u : Fin n) (v : neighbors G u) : + |(((Finset.univ.filter ((linkSimpleGraph G h.1 u).Adj v)).card : ℝ) - prefixD n)| ≤ + (n : ℝ)^(-c) * prefixD n := by + rw [link_degree_eq] + apply h.2.2.2.1 + intro heq + have hv : {u,v.val} ∈ G := (Finset.mem_filter.mp v.property).2 + have hh := mem_completeGraph.mp (h.1 hv) + simp [← heq] at hh + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/LocalChoiceRank.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/LocalChoiceRank.lean new file mode 100644 index 0000000000000000000000000000000000000000..b13605d586f3849d8581c36637b8affc1ec0e4ff --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/LocalChoiceRank.lean @@ -0,0 +1,93 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +noncomputable def localChoiceRank {α : Type*} (C : Finset α) (a : α) : ℕ := by + classical + exact if h : a ∈ C then ((Fintype.equivFin {a // a ∈ C}) ⟨a,h⟩).val else 0 + +lemma localChoiceRank_lt {α : Type*} (C : Finset α) (a : α) (ha : a ∈ C) : + localChoiceRank C a < C.card := by + classical + simp only [localChoiceRank,dite_eq_left ha] + simpa only [Fintype.card_coe] using (Fintype.equivFin {a // a ∈ C} ⟨a,ha⟩).isLt + +lemma localChoiceRank_injective {α : Type*} (C : Finset α) {a b : α} + (ha : a ∈ C) (hb : b ∈ C) (he : localChoiceRank C a = localChoiceRank C b) : a = b := by + classical + simp only [localChoiceRank,dite_eq_left ha,dite_eq_left hb] at he + have he' := (Fintype.equivFin {a // a ∈ C}).injective (Fin.ext he) + exact congrArg Subtype.val he' + +noncomputable def prefixChoiceValues {n : ℕ} {α : Type*} + (S : Finset (Fin n → α)) (f : Fin n → α) (i : Fin n) : Finset α := by + classical + exact (S.filter (fun g => ∀ j, j < i → g j = f j)).image (fun g => g i) + +lemma prefixChoiceValues_self {n : ℕ} {α : Type*} + (S : Finset (Fin n → α)) (f : Fin n → α) (hf : f ∈ S) (i : Fin n) : + f i ∈ prefixChoiceValues S f i := by + classical + exact Finset.mem_image.mpr ⟨f,Finset.mem_filter.mpr ⟨hf,fun _ _ => rfl⟩,rfl⟩ + +lemma prefixChoiceValues_eq {n : ℕ} {α : Type*} + (S : Finset (Fin n → α)) (f g : Fin n → α) (i : Fin n) + (he : ∀ j, j < i → f j = g j) : prefixChoiceValues S f i = prefixChoiceValues S g i := by + classical + unfold prefixChoiceValues + congr 1 + apply Finset.filter_congr + intro q _ + constructor <;> intro h j hj + · exact (h j hj).trans (he j hj) + · exact (h j hj).trans (he j hj).symm + +theorem finite_branching_family_bound {n : ℕ} {α : Type*} + (S : Finset (Fin n → α)) (b : ℕ) + (hb : ∀ f ∈ S, ∀ i, (prefixChoiceValues S f i).card ≤ b) : S.card ≤ b^n := by + classical + let code : {f // f ∈ S} → (Fin n → Fin b) := fun f i => + ⟨localChoiceRank (prefixChoiceValues S f.val i) (f.val i), + (localChoiceRank_lt _ _ (prefixChoiceValues_self S f.val f.property i)).trans_le + (hb f.val f.property i)⟩ + have hinj : Function.Injective code := by + intro f g hcode + apply Subtype.ext + funext i + have hrec : ∀ k, ∀ hk : k < n, f.val ⟨k,hk⟩ = g.val ⟨k,hk⟩ := by + intro k + induction k using Nat.strong_induction_on with + | h k ih => + intro hk + let i : Fin n := ⟨k,hk⟩ + have hprev : ∀ j, j < i → f.val j = g.val j := by + intro j hj + exact ih j.val hj j.isLt + have heC := prefixChoiceValues_eq S f.val g.val i hprev + have hval := congrArg Fin.val (congrFun hcode i) + change localChoiceRank (prefixChoiceValues S f.val i) (f.val i) = + localChoiceRank (prefixChoiceValues S g.val i) (g.val i) at hval + rw [← heC] at hval + apply localChoiceRank_injective _ (prefixChoiceValues_self S f.val f.property i) _ hval + rw [heC] + exact prefixChoiceValues_self S g.val g.property i + exact hrec i.val i.isLt + have h := Fintype.card_le_of_injective code hinj + simpa only [Fintype.card_coe,Fintype.card_fun,Fintype.card_fin] using h + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/LongWitnessMatchingCount.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/LongWitnessMatchingCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..a90062f5e3b5b36d71dd53abcc7b8d3218264a40 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/LongWitnessMatchingCount.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEpsilon +import OAI.Combinatorics.TriangleRemoval.Probability.ProductPMF +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Process.Within +import OAI.Combinatorics.TriangleRemoval.Process.SuffixBoundary +import OAI.Combinatorics.TriangleRemoval.Process.InitialAssignmentSet +import OAI.Combinatorics.TriangleRemoval.Process.InitialAssignmentSetMatching +import OAI.Combinatorics.TriangleRemoval.Embeddings.RestrictLabel +import OAI.Combinatorics.TriangleRemoval.Embeddings.SuffixTemplate + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N n : ℕ} (B : BirthGraph N) + +theorem long_witness_matching_count {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (hsmall : (n : ℝ)^(-c) ≤ 1) + (r k : ℕ) (hrk : 2*r ≤ k) (hk : k ≤ N) + (u v : Fin r → Fin (2*r)) + (hcoverRoots : ∀ i : Fin (2*r), ∃ j, i = u j ∨ i = v j) + (hroot : ∀ j, B.graph.Adj (Fin.castLE (hrk.trans hk) (u j)) + (Fin.castLE (hrk.trans hk) (v j))) + (hborn : ∀ v : Fin N, 2*r ≤ v.val → (B.older v).card = 2) + {a b : Fin N} (hab : a ≠ b) (hne : ¬ B.graph.Adj a b) + (hmark : k ≤ a.val ∨ k ≤ b.val) + (hc : B.Covered (Finset.univ.filter (fun x => k ≤ x.val)) a b) + (hcap : 3 * (N-k) + 1 ≤ prefixTemplateCap) + (hp : 0 ≤ prefixDensity n) (hp1 : prefixDensity n ≤ 1) (hD : 1 ≤ prefixD n) + (hscale : (n : ℝ)^(N-k) * prefixDensity n ^ (2*(N-k)+1) ≤ 1) : + ((graphEmbeddingSet (insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ)) G).card : ℝ) ≤ + prefixTemplateFactor n C * ((2 * prefixM n)^r * (2 * prefixD n)^(k-2*r)) := by + classical + let Z : Finset (Fin N) := Finset.univ.filter (fun x => k ≤ x.val) + have hZ : Z.card = N-k := by + have heq : Z = Finset.univ \ (Finset.univ.filter (fun x : Fin N => x.val < k)) := by + ext x + simp only [Z,Finset.mem_filter,Finset.mem_sdiff,Finset.mem_univ,true_and,not_lt] + rw [heq,Finset.card_sdiff_of_subset (Finset.filter_subset _ _),Finset.card_univ, + Fintype.card_fin,Fin.card_filter_val_lt,Nat.min_eq_right hk] + have hm : a ∈ Z ∨ b ∈ Z := by simpa only [Z,Finset.mem_filter,Finset.mem_univ,true_and] using hmark + have hb : ∀ v ∈ Z, (B.older v).card = 2 := by + intro v hv + exact hborn v (hrk.trans (Finset.mem_filter.mp hv).2) + have hIP : B.suffixBoundary Z a b ⊆ initialVertices N k := by + intro x hx + have hnZ := (B.mem_suffixBoundary Z a b x).mp hx |>.2 + simp only [Z,Finset.mem_filter,Finset.mem_univ,true_and,not_le] at hnZ + exact (mem_initialVertices N k x).mpr hnZ + have hcover : initialVertices N k ∪ B.suffixVertices Z a b = Finset.univ := by + apply Finset.eq_univ_iff_forall.mpr + intro x + by_cases hx : x.val < k + · exact Finset.mem_union_left _ ((mem_initialVertices N k x).mpr hx) + · exact Finset.mem_union_right _ (Finset.mem_union_left _ + (Finset.mem_filter.mpr ⟨Finset.mem_univ _,by omega⟩)) + have hEF : B.suffixEdges Z a b ⊆ + insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ) := by + apply Finset.insert_subset_insert + exact Finset.biUnion_subset_biUnion_of_subset_left _ (Finset.subset_univ Z) + have hf := graphEmbeddingSet_count_glue (B.suffixVertices Z a b) (B.suffixBoundary Z a b) + (initialVertices N k) (B.suffixEdges Z a b) _ G B.suffixEdges_subset_vertices + (B.suffixEdges_simple hab) (B.suffixBoundary_independent hm) hIP hcover hEF + (B.initialAssignmentSet G k hk) (fun φ hφ => B.initialLabel_mem G hφ k hk) + (prefixTemplateFactor n C) (by + intro ξ _ + exact B.suffixTemplate_count hGood hab hm hb hne hc (hZ ▸ hcap) hp hp1 hD + (hZ ▸ hscale) _) + have hκ : 0 ≤ prefixTemplateFactor n C := by + unfold prefixTemplateFactor + positivity + exact hf.trans (mul_le_mul_of_nonneg_left + (B.initialAssignmentSet_matching_bound hGood hsmall r k hrk hk u v hcoverRoots hroot hborn) hκ) + +end SharpTerminalLeave.BirthGraph + +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/LookupGraph.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/LookupGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..f67e84516335872a513221caa96029b8564f5ecc --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/LookupGraph.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.RestrictLabel + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def lookupGraph {n : ℕ} (G : Graph n) : SimpleGraph (Fin n) where + Adj x y := x ≠ y ∧ {x,y} ∈ G + symm := ⟨fun x y h => ⟨h.1.symm,by simpa only [Finset.pair_comm] using h.2⟩⟩ + loopless := ⟨fun _ h => h.1 rfl⟩ + +def initialVertices (N k : ℕ) : Finset (Fin N) := Finset.univ.filter (fun x => x.val < k) + +@[simp] lemma mem_initialVertices (N k : ℕ) (x : Fin N) : + x ∈ initialVertices N k ↔ x.val < k := by simp [initialVertices] + +def initialLabel {N n k : ℕ} (hk : k ≤ N) (φ : Fin N ↪ Fin n) : Fin k ↪ Fin n := + ⟨fun i => φ (Fin.castLE hk i),φ.injective.comp (Fin.castLE_injective hk)⟩ + +def initialSubtypeLabel {N n k : ℕ} (ψ : Fin k ↪ Fin n) : + {x // x ∈ initialVertices N k} ↪ Fin n where + toFun x := ψ ⟨x.val.val,(mem_initialVertices N k x.val).mp x.property⟩ + inj' := by + intro x y h + have he := congrArg Fin.val (ψ.injective h) + apply Subtype.ext + exact Fin.ext he + +@[simp] lemma initialSubtypeLabel_initialLabel {N n k : ℕ} (hk : k ≤ N) + (φ : Fin N ↪ Fin n) : initialSubtypeLabel (initialLabel hk φ) = + restrictLabel (initialVertices N k) φ := by + ext x + rfl + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/LookupGraphDegree.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/LookupGraphDegree.lean new file mode 100644 index 0000000000000000000000000000000000000000..9eeccde04e7e29325adda517dec03f2e1b49ddb4 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/LookupGraphDegree.lean @@ -0,0 +1,67 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEpsilon +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +open Classical in + +lemma lookupGraph_degree_le {n : ℕ} (G : Graph n) (x : Fin n) : + (Finset.univ.filter (fun z => (lookupGraph G).Adj x z)).card ≤ currentDegree G x := by + apply Finset.card_le_card + intro z hz + exact Finset.mem_filter.mpr ⟨Finset.mem_univ z,(Finset.mem_filter.mp hz).2.2⟩ + +open Classical in + +lemma lookupGraph_codegree_le {n : ℕ} (G : Graph n) (x y : Fin n) : + (Finset.univ.filter (fun z => (lookupGraph G).Adj x z ∧ (lookupGraph G).Adj y z)).card ≤ + currentCodegree G x y := by + apply Finset.card_le_card + intro z hz + have hh := (Finset.mem_filter.mp hz).2 + exact Finset.mem_filter.mpr ⟨Finset.mem_univ z,hh.1.2,hh.2.2⟩ + +open Classical in + +lemma goodPrefix_degree_bound {n : ℕ} {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (hc : (n : ℝ)^(-c) ≤ 1) + (hp : 0 ≤ prefixDensity n) (x : Fin n) : + ((Finset.univ.filter (fun z => (lookupGraph G).Adj x z)).card : ℝ) ≤ + 2 * (n * prefixDensity n) := by + have h := (abs_le.mp (hGood.2.2.1 x)).2 + have hm := mul_le_mul_of_nonneg_right hc (mul_nonneg (Nat.cast_nonneg n) hp) + have hl : ((Finset.univ.filter (fun z => (lookupGraph G).Adj x z)).card : ℝ) ≤ + currentDegree G x := by exact_mod_cast lookupGraph_degree_le G x + linarith + +open Classical in + +lemma goodPrefix_codegree_bound {n : ℕ} {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) (hc : (n : ℝ)^(-c) ≤ 1) + (x y : Fin n) (hxy : x ≠ y) : + ((Finset.univ.filter (fun z => (lookupGraph G).Adj x z ∧ (lookupGraph G).Adj y z)).card : ℝ) ≤ + 2 * prefixD n := by + have h := (abs_le.mp (hGood.2.2.2.1 x y hxy)).2 + have hD : 0 ≤ prefixD n := mul_nonneg (Nat.cast_nonneg n) (sq_nonneg _) + have hm := mul_le_mul_of_nonneg_right hc hD + have hl : ((Finset.univ.filter (fun z => (lookupGraph G).Adj x z ∧ (lookupGraph G).Adj y z)).card : ℝ) ≤ + currentCodegree G x y := by exact_mod_cast lookupGraph_codegree_le G x y + linarith + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/MapOutput.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/MapOutput.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce227d0a63941d00fe5ee83a077f395cf3882383 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/MapOutput.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Asymptotics.FreshLog + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave +namespace ExposureTree +variable {K V O P Q : Type*} + +def mapOutput (f : O → P) : ExposureTree K V O → ExposureTree K V P + | .done o => .done (f o) + | .ask k g => .ask k (fun v => mapOutput f (g v)) + +@[simp] theorem mapOutput_done (f : O → P) (o : O) : + mapOutput (K := K) (V := V) f (.done o) = .done (f o) := rfl + +@[simp] theorem mapOutput_bind (f : P → Q) (A : ExposureTree K V O) + (g : O → ExposureTree K V P) : + mapOutput f (bind A g) = bind A (fun o => mapOutput f (g o)) := by + induction A with + | done o => rfl + | ask k h ih => simp only [bind, mapOutput, ih] + +@[simp] theorem bind_mapOutput (f : O → P) (A : ExposureTree K V O) + (g : P → ExposureTree K V Q) : + bind (mapOutput f A) g = bind A (fun o => g (f o)) := by + induction A with + | done o => rfl + | ask k h ih => simp only [bind, mapOutput, ih] + +@[simp] theorem mapOutput_comp (f : P → Q) (g : O → P) (A : ExposureTree K V O) : + mapOutput f (mapOutput g A) = mapOutput (f ∘ g) A := by + induction A with + | done o => rfl + | ask k h ih => simp only [mapOutput, ih] + +@[simp] theorem mapOutput_id (A : ExposureTree K V O) : mapOutput id A = A := by + induction A with + | done o => rfl + | ask k h ih => simp only [mapOutput, ih] + +@[simp] theorem fresh_mapOutput (ν : K → PMF V) (f : O → P) (A : ExposureTree K V O) : + fresh ν (mapOutput f A) = (fresh ν A).map f := by + induction A with + | done o => simp [mapOutput, fresh, PMF.pure_map] + | ask k h ih => simp only [mapOutput, fresh, ih, PMF.map_bind] + +@[simp] theorem freshLog_mapOutput (ν : K → PMF V) (f : O → P) (A : ExposureTree K V O) : + freshLog ν (mapOutput f A) = (freshLog ν A).map (fun z => (f z.1, z.2)) := by + induction A with + | done o => simp [mapOutput, freshLog, PMF.pure_map] + | ask k h ih => + simp only [mapOutput, freshLog, ih, PMF.map_bind, PMF.map_comp] + rfl + +def checkNoneTrace {R : Type*} : + List (ExposureTree K V (Bool × List R)) → ExposureTree K V (Bool × List R) + | [] => .done (true, []) + | A :: As => bind A (fun z => + if z.1 then .done (false, z.2) + else mapOutput (fun y => (y.1, z.2 ++ y.2)) (checkNoneTrace As)) + +@[simp] theorem checkNoneTrace_outcome {R : Type*} + (as : List (ExposureTree K V (Bool × List R))) : + mapOutput Prod.fst (checkNoneTrace as) = + checkNone (as.map (mapOutput Prod.fst)) := by + induction as with + | nil => rfl + | cons A as ih => + simp only [checkNoneTrace, mapOutput_bind, List.map_cons, checkNone, + bind_mapOutput] + congr 1 + funext z + cases z.1 <;> simp only [Bool.false_eq_true, ↓reduceIte, mapOutput_done, + mapOutput_comp] + exact ih + +end ExposureTree + +section TraceQuery +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +structure QueryCall (ι τ : Type*) where + address : List (ι × τ) + focus : Finset ι + parent : Option τ + +noncomputable def QueryCall.keys (H : τ → Finset ι) (c : QueryCall ι τ) : List τ := + (gridCandidates H c.focus c.parent).toList.map Prod.snd + +noncomputable def tracedGridQuery (H : τ → Finset ι) (N : ℕ) : + ℕ → ℕ → QueryCall ι τ → ExposureTree τ (Fin N) (Bool × List (QueryCall ι τ)) + | 0, _, c => ExposureTree.bind + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H c.focus c.parent).toList) + (fun _ => .done (true, [c])) + | d+1, k, c => ExposureTree.bind + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H c.focus c.parent).toList) + (fun values => ExposureTree.mapOutput (fun y => (y.1, c :: y.2)) + (ExposureTree.checkNoneTrace + ((values.mergeSort (fun a b => a.2.val ≤ b.2.val)).map + (fun p => if p.2.val < k then + tracedGridQuery H N d p.2.val + ⟨p.1 :: c.address, (H p.1.2).erase p.1.1, some p.1.2⟩ + else .done (false, []))))) + +theorem tracedGridQuery_outcome (H : τ → Finset ι) (N d k : ℕ) (c : QueryCall ι τ) : + ExposureTree.mapOutput Prod.fst (tracedGridQuery H N d k c) = + gridQueryDepth H N d k c.focus c.parent := by + induction d generalizing k c with + | zero => simp only [tracedGridQuery, ExposureTree.mapOutput_bind, + ExposureTree.mapOutput_done, gridQueryDepth] + | succ d ih => + simp only [tracedGridQuery, ExposureTree.mapOutput_bind, ExposureTree.mapOutput_comp, + gridQueryDepth] + congr 1 + funext vals + change ExposureTree.mapOutput Prod.fst (ExposureTree.checkNoneTrace _) = _ + rw [ExposureTree.checkNoneTrace_outcome, List.map_map] + congr 1 + apply List.map_congr_left + intro p _ + simp only [Function.comp_apply] + split_ifs + · exact ih _ _ + · rfl + +end TraceQuery +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/MatchingSeedEdgeRoots.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/MatchingSeedEdgeRoots.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1f625493a755842bc408917dcbd02fb3425bfe7 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/MatchingSeedEdgeRoots.lean @@ -0,0 +1,81 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth2 +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraph +import OAI.Combinatorics.TriangleRemoval.Process.BornEdges +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +section MatchingSeedEdgeCount +variable {V : Type*} [DecidableEq V] {N R : ℕ} +variable (label : Fin N → V) (E : Finset (Finset V)) (hE : EdgeMatching E) +variable (hi : Set.InjOn label {v | v.val < R}) + +lemma matchingSeed_edge_roots (Z : Finset (Fin N)) {e : Finset (Fin N)} + (he : e ∈ (matchingSeed label E hE hi).backEdges Z) : + ∀ x ∈ e, x.val < R := by + obtain ⟨v,_,u,hu,rfl⟩ := BirthGraph.backEdges_mem_pair _ he + obtain ⟨hv,huv,_⟩ := (matchingSeed_mem_older label E hE hi v u).mp hu + intro x hx + rcases Finset.mem_insert.mp hx with rfl | hx + · exact lt_trans huv hv + · simpa only [Finset.mem_singleton] using (Finset.mem_singleton.mp hx ▸ hv) + +lemma matchingSeed_edge_image (Z : Finset (Fin N)) {e : Finset (Fin N)} + (he : e ∈ (matchingSeed label E hE hi).backEdges Z) : e.image label ∈ E := by + obtain ⟨v,_,u,hu,rfl⟩ := BirthGraph.backEdges_mem_pair _ he + simpa only [Finset.image_insert,Finset.image_singleton] using + ((matchingSeed_mem_older label E hE hi v u).mp hu).2.2 + +theorem matchingSeed_edge_count (Z : Finset (Fin N)) : + ((matchingSeed label E hE hi).backEdges Z).card ≤ E.card := by + classical + let S := (matchingSeed label E hE hi).backEdges Z + have hinj : Set.InjOn (Finset.image label) S := by + intro e he f hf hEq + have heR := matchingSeed_edge_roots label E hE hi Z he + have hfR := matchingSeed_edge_roots label E hE hi Z hf + apply Finset.Subset.antisymm + · intro x hx + have hxI : label x ∈ f.image label := hEq ▸ Finset.mem_image_of_mem label hx + obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp hxI + exact hi (hfR y hy) (heR x hx) hxy ▸ hy + · intro y hy + have hyI : label y ∈ e.image label := hEq.symm ▸ Finset.mem_image_of_mem label hy + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp hyI + exact hi (heR x hx) (hfR y hy) hxy ▸ hx + rw [← Finset.card_image_of_injOn hinj] + apply Finset.card_le_card + intro e he + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he + exact matchingSeed_edge_image label E hE hi Z hf + +end MatchingSeedEdgeCount + +namespace RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) + +lemma growth_seed_count (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) : + ((F.toTriangleGrowth hM hG).seed.backEdges (F.toTriangleGrowth hM hG).roots).card ≤ + c.focus.card := + matchingSeed_edge_count F.vertexLabel c.focus hM F.vertexLabel_injective_roots _ + +end RecordedCallForest +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/MatchingSeedFullEdge.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/MatchingSeedFullEdge.lean new file mode 100644 index 0000000000000000000000000000000000000000..c4d2fe59ca98d7ad7379143aba56efe501754aae --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/MatchingSeedFullEdge.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.RootSet +import OAI.Combinatorics.TriangleRemoval.Process.MatchingSeedEdgeRoots + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +theorem matchingSeed_full_edge_count {V : Type*} [DecidableEq V] {N R : ℕ} + (label : Fin N → V) (E : Finset (Finset V)) (hE : EdgeMatching E) + (hi : Set.InjOn label {v | v.val < R}) + (hc : ∀ e ∈ E, ∀ x ∈ e, ∃ v : Fin N, v.val < R ∧ label v = x) : + ((matchingSeed label E hE hi).backEdges (Finset.univ.filter (fun v => v.val < R))).card = E.card := by + classical + apply Nat.le_antisymm (matchingSeed_edge_count label E hE hi _) + let S := (matchingSeed label E hE hi).backEdges (Finset.univ.filter (fun v => v.val < R)) + have hsub : E ⊆ S.image (Finset.image label) := by + intro e he + obtain ⟨x,y,hx,hy,hxy,rfl⟩ := matchingSeed_covers label E hE hi hc e he + have hp : ({x,y} : Finset (Fin N)) ∈ S := by + rcases hxy with hxy | hyx + · exact Finset.mem_biUnion.mpr ⟨y,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hy⟩, + Finset.mem_image.mpr ⟨x,hxy,rfl⟩⟩ + · have hh : ({y,x} : Finset (Fin N)) ∈ S := Finset.mem_biUnion.mpr + ⟨x,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hx⟩,Finset.mem_image.mpr ⟨y,hyx,rfl⟩⟩ + simpa only [Finset.pair_comm] using hh + exact Finset.mem_image.mpr ⟨{x,y},hp,by simp only [Finset.image_insert,Finset.image_singleton]⟩ + exact (Finset.card_le_card hsub).trans Finset.card_image_le + +namespace RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) + +lemma growth_seed_card (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) : + ((F.toTriangleGrowth hM hG).seed.backEdges (F.toTriangleGrowth hM hG).roots).card = c.focus.card := + matchingSeed_full_edge_count F.vertexLabel c.focus hM F.vertexLabel_injective_roots F.vertexLabel_covers + +lemma rootCount_focus_card (hM : EdgeMatching c.focus) : F.rootCount = 2*c.focus.card := by + classical + rw [rootCount,rootSet,Finset.card_biUnion] + · calc + ∑ e ∈ c.focus, e.card = ∑ _e ∈ c.focus, 2 := Finset.sum_congr rfl (fun e he => hM.1 e he) + _ = 2*c.focus.card := by simp only [Finset.sum_const,smul_eq_mul,Nat.mul_comm] + · exact hM.2 + +end RecordedCallForest +end SharpTerminalLeave + +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/NonrootForest.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/NonrootForest.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc776a7863a29e7ac20f6c416860d8849d7dd0e7 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/NonrootForest.lean @@ -0,0 +1,95 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.PathSuffix +import OAI.Combinatorics.TriangleRemoval.Process.RestrictedParent + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.TriangleGrowth +variable {V : Type*} [DecidableEq V] {G : SimpleGraph V} {N R : ℕ} +variable (A : TriangleGrowth G N R) + +noncomputable def nonrootForest : PathForest N := by + refine ⟨fun v => if R ≤ v.val then A.parent v else none,?_⟩ + intro v p hp + change (if R ≤ v.val then A.parent v else none) = some p at hp + split_ifs at hp with hv + exact A.parent_lt v p hv hp + +lemma nonrootForest_step {x y : Fin N} (h : A.Parent x y) : + A.nonrootForest.Step x y := by + change (if R ≤ y.val then A.parent y else none) = some x + rw [ite_eq_left h.1] + exact h.2 + +lemma nonrootForest_ancestor {x y : Fin N} (h : A.Ancestor x y) : + A.nonrootForest.Ancestor x y := by + induction h with + | refl => exact Relation.ReflTransGen.refl + | @tail y z hxy hyz ih => + exact Relation.ReflTransGen.tail ih (A.nonrootForest_step hyz) + +lemma pathNonroots_parent_closed (a b : Fin N) : + ∀ v ∈ A.pathSuffix a b R, ∀ p, A.nonrootForest.parent v = some p → + p ∈ A.pathSuffix a b R := by + intro v hv p hp + obtain ⟨hvP,hvR⟩ := (A.mem_pathSuffix a b v R).mp hv + change (if R ≤ v.val then A.parent v else none) = some p at hp + rw [ite_eq_left hvR] at hp + exact (A.mem_pathSuffix a b p R).mpr + ⟨A.pathUnion_older_closed hvP (A.parent_mem_older hvR hp),A.parent_nonroot v p hvR hp⟩ + +lemma pathNonroots_cover (a b : Fin N) : + ∀ v ∈ A.pathSuffix a b R, + (a ∈ A.pathSuffix a b R ∧ A.nonrootForest.Ancestor v a) ∨ + (b ∈ A.pathSuffix a b R ∧ A.nonrootForest.Ancestor v b) := by + intro v hv + obtain ⟨hvP,hvR⟩ := (A.mem_pathSuffix a b v R).mp hv + rcases (A.mem_pathUnion a b v).mp hvP with hroot | ha | hb + · omega + · exact Or.inl ⟨(A.mem_pathSuffix a b a R).mpr + ⟨A.left_mem_pathUnion a b,hvR.trans (A.ancestor_le ha)⟩,A.nonrootForest_ancestor ha⟩ + · exact Or.inr ⟨(A.mem_pathSuffix a b b R).mpr + ⟨A.right_mem_pathUnion a b,hvR.trans (A.ancestor_le hb)⟩,A.nonrootForest_ancestor hb⟩ + +noncomputable def pathForest (a b : Fin N) : PathForest (A.pathSuffix a b R).card := + A.nonrootForest.restrict (A.pathSuffix a b R) (A.pathNonroots_parent_closed a b) + +theorem pathForest_two_path_cover (a b : Fin N) : + ∀ i, (A.pathForest a b).OnPath (PathForest.restrictMark (A.pathSuffix a b R) a) i ∨ + (A.pathForest a b).OnPath (PathForest.restrictMark (A.pathSuffix a b R) b) i := + A.nonrootForest.restrict_two_path_cover _ (A.pathNonroots_parent_closed a b) a b + (A.pathNonroots_cover a b) + +theorem older_focus {v p : Fin N} (hv : R ≤ v.val) (hp : A.parent v = some p) : + ∃ u ∈ A.older p, A.older v = {p,u} := by + classical + obtain ⟨x,y,hxy,hpair⟩ := Finset.card_eq_two.mp ((A.older_invariants v).2 hv).1 + have hpm := A.parent_mem_older hv hp + rw [hpair,Finset.mem_insert,Finset.mem_singleton] at hpm + have hsub : A.older v ⊆ insert p (A.older p) := by + rw [older,dite_eq_left hv,hp] + exact Finset.filter_subset _ _ + rcases hpm with rfl | rfl + · refine ⟨y,?_,hpair⟩ + exact (Finset.mem_insert.mp (hsub (by rw [hpair]; simp))).resolve_left (Ne.symm hxy) + · refine ⟨x,?_,?_⟩ + · exact (Finset.mem_insert.mp (hsub (by rw [hpair]; simp))).resolve_left hxy + · simpa only [Finset.pair_comm] using hpair + +end SharpTerminalLeave.TriangleGrowth + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/OlderSeed.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/OlderSeed.lean new file mode 100644 index 0000000000000000000000000000000000000000..25eda3cd5d7be7c4e0195c4ccb20842d0e2f7894 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/OlderSeed.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.TriangleGrowth +variable {V : Type*} [DecidableEq V] {G : SimpleGraph V} {N R : ℕ} +variable (A : TriangleGrowth G N R) + +lemma older_eq_seed {v : Fin N} (hv : v.val < R) : A.older v = A.seed.older v := by + rw [older,dite_eq_right (Nat.not_le_of_gt hv)] + +lemma nonroot_of_card_two {v : Fin N} (hv : (A.older v).card = 2) : R ≤ v.val := by + by_contra hn + have hh := A.seed_small v (Nat.lt_of_not_ge hn) + rw [← A.older_eq_seed (Nat.lt_of_not_ge hn),hv] at hh + omega + +lemma parent_label_mem {v p : Fin N} (hv : R ≤ v.val) (hp : A.parent v = some p) : + A.label p ∈ A.attach v := by + by_contra hn + have hs : A.attach v ⊆ A.attach p := by + intro x hx + exact (Finset.mem_insert.mp ((A.child_attach v p hv hp).1 hx)).resolve_left + (fun h => hn (h ▸ hx)) + have he : A.attach v = A.attach p := Finset.eq_of_subset_of_card_le hs (by + rw [A.attach_card v hv,A.attach_card p (A.parent_nonroot v p hv hp)]) + exact (A.child_attach v p hv hp).2 he + +lemma parent_mem_older {v p : Fin N} (hv : R ≤ v.val) (hp : A.parent v = some p) : + p ∈ A.older v := by + rw [older,dite_eq_left hv,hp] + exact Finset.mem_filter.mpr ⟨Finset.mem_insert_self _ _,A.parent_label_mem hv hp⟩ + +lemma older_le_parent {v p x : Fin N} (hv : R ≤ v.val) (hp : A.parent v = some p) + (hx : x ∈ A.older v) : x ≤ p := by + rw [older,dite_eq_left hv,hp] at hx + rcases Finset.mem_insert.mp (Finset.mem_filter.mp hx).1 with h | h + · exact le_of_eq h + · exact le_of_lt ((A.older_invariants p).1 x h) + +lemma older_root_of_none {v x : Fin N} (hv : R ≤ v.val) (hp : A.parent v = none) + (hx : x ∈ A.older v) : x.val < R := by + rw [older,dite_eq_left hv,hp] at hx + exact (A.mem_roots x).mp (Finset.mem_filter.mp hx).1 + +lemma parent_of_max {v p : Fin N} (hv : R ≤ v.val) (hp : R ≤ p.val) + (hpm : p ∈ A.older v) (hmax : ∀ x ∈ A.older v, x ≤ p) : A.parent v = some p := by + cases hpar : A.parent v with + | none => + have hh := A.older_root_of_none hv hpar hpm + omega + | some q => + have hq := hmax q (A.parent_mem_older hv hpar) + have hqp := A.older_le_parent hv hpar hpm + exact congrArg some (le_antisymm hq hqp) + +lemma root_graph {x y : Fin N} (hx : x.val < R) (hy : y.val < R) : + A.birthGraph.graph.Adj x y ↔ A.seed.graph.Adj x y := by + change (x ∈ A.older y ∨ y ∈ A.older x) ↔ _ + rw [A.older_eq_seed hx,A.older_eq_seed hy] + rfl + +lemma older_pair_of_root {v : Fin N} (hv : R ≤ v.val) (hp : A.parent v = none) : + ∃ x y : Fin N, x.val < R ∧ y.val < R ∧ A.seed.graph.Adj x y ∧ + A.older v = {x,y} := by + obtain ⟨x,y,hx,hy,hxy,hat⟩ := A.root_attach v hv hp + refine ⟨x,y,hx,hy,hxy,?_⟩ + have hxm : x ∈ A.older v := by + rw [older,dite_eq_left hv,hp] + exact Finset.mem_filter.mpr ⟨(A.mem_roots x).mpr hx,by rw [hat]; simp⟩ + have hym : y ∈ A.older v := by + rw [older,dite_eq_left hv,hp] + exact Finset.mem_filter.mpr ⟨(A.mem_roots y).mpr hy,by rw [hat]; simp⟩ + exact A.birthGraph.older_eq_pair hxy.ne hxm hym + +theorem spawnRules : A.birthGraph.SpawnRules G A.label := by + constructor + · have hold (u v : Fin N) (h : u ∈ A.older v) : G.Adj (A.label u) (A.label v) := by + by_cases hv : R ≤ v.val + · have hm : A.label u ∈ A.attach v := by + rw [← ((A.older_invariants v).2 hv).2.1] + exact Finset.mem_image.mpr ⟨u,h,rfl⟩ + exact (A.triangle v hv).2 _ (Finset.mem_insert_of_mem hm) _ + (Finset.mem_insert_self _ _) (fun he => A.new_label v hv (he ▸ hm)) + · rw [A.older_eq_seed (Nat.lt_of_not_ge hv)] at h + exact A.seed_labels v (Nat.lt_of_not_ge hv) u h + intro a b h + rcases h with h | h + · exact hold a b h + · exact (hold b a h).symm + · intro v hvc a ha b hb hab + have hv := A.nonroot_of_card_two hvc + cases hp : A.parent v with + | none => + obtain ⟨x,y,hx,hy,hxy,he⟩ := A.older_pair_of_root hv hp + have hg := (A.root_graph hx hy).mpr hxy + change a ∈ A.older v at ha + change b ∈ A.older v at hb + rw [he] at ha hb + simp only [Finset.mem_insert,Finset.mem_singleton] at ha hb + rcases ha with rfl | rfl <;> rcases hb with rfl | rfl + · exact False.elim (hab rfl) + · exact hg + · exact hg.symm + · exact False.elim (hab rfl) + | some p => + have he := A.birthGraph.older_eq_pair hab ha hb + have hpm := A.parent_mem_older hv hp + change p ∈ A.birthGraph.older v at hpm + rw [he] at hpm + simp only [Finset.mem_insert,Finset.mem_singleton] at hpm + have hsub : A.older v ⊆ insert p (A.older p) := by + rw [older,dite_eq_left hv,hp] + exact Finset.filter_subset _ _ + rcases hpm with hpa | hpb + · subst a + exact Or.inr ((Finset.mem_insert.mp (hsub hb)).resolve_left hab.symm) + · subst b + exact Or.inl ((Finset.mem_insert.mp (hsub ha)).resolve_left hab) + · intro v p hpm hmax hpc + have hp := A.nonroot_of_card_two hpc + have hv : R ≤ v.val := le_trans hp (le_of_lt (A.birthGraph.older_lt v p hpm)) + have hpar := A.parent_of_max hv hp hpm hmax + rw [A.parentType_eq v hv,A.parentType_eq p hp] + exact A.omission v p hv hpar + · intro v w hvc he hl + change A.older v = A.older w at he + change (A.older v).card = 2 at hvc + have hv := A.nonroot_of_card_two hvc + have hw := A.nonroot_of_card_two (he ▸ hvc) + have hp : A.parent v = A.parent w := by + cases hpv : A.parent v with + | none => + cases hpw : A.parent w with + | none => rfl + | some p => + have hm := A.parent_mem_older hw hpw + rw [← he] at hm + have hpr := A.older_root_of_none hv hpv hm + have hpn := A.parent_nonroot w p hw hpw + omega + | some p => + have hpm := A.parent_mem_older hv hpv + have hmax := fun x (hx : x ∈ A.older v) => A.older_le_parent hv hpv hx + have hpm' : p ∈ A.older w := he ▸ hpm + have hmax' : ∀ x ∈ A.older w, x ≤ p := by + intro x hx + exact hmax x (he.symm ▸ hx) + exact (A.parent_of_max hw (A.parent_nonroot v p hv hpv) hpm' hmax').symm + apply A.distinct_children v w hv hw hp _ hl + rw [← ((A.older_invariants v).2 hv).2.1,← ((A.older_invariants w).2 hw).2.1] + exact congrArg (Finset.image A.label) he + +end SharpTerminalLeave.TriangleGrowth + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/OrientedEdges.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/OrientedEdges.lean new file mode 100644 index 0000000000000000000000000000000000000000..e42ea5bc3236ddca555ea5eab8e873b7fd23f0da --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/OrientedEdges.lean @@ -0,0 +1,86 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEmbeddings +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def orientedEdges {n : ℕ} (G : Graph n) : Finset (Fin n × Fin n) := + G.biUnion (fun e => (e ×ˢ e).filter (fun z => z.1 ≠ z.2)) + +@[simp] lemma mem_orientedEdges {n : ℕ} {G : Graph n} + (hG : ∀ e ∈ G, e.card = 2) (x y : Fin n) : + (x,y) ∈ orientedEdges G ↔ (lookupGraph G).Adj x y := by + simp only [orientedEdges,Finset.mem_biUnion,Finset.mem_filter,Finset.mem_product] + constructor + · rintro ⟨e,he,⟨hx,hy⟩,hxy⟩ + refine ⟨hxy,?_⟩ + have heq : ({x,y} : Finset (Fin n)) = e := + Finset.eq_of_subset_of_card_le (by simpa only [Finset.insert_subset_iff,Finset.singleton_subset_iff] using And.intro hx hy) + (by rw [hG e he,Finset.card_pair hxy]) + exact heq.symm ▸ he + · rintro ⟨hxy,he⟩ + exact ⟨{x,y},he,⟨by simp,by simp⟩,hxy⟩ + +theorem orientedEdges_card_le {n : ℕ} {G : Graph n} (hG : ∀ e ∈ G, e.card = 2) : + (orientedEdges G).card ≤ 2 * G.card := by + unfold orientedEdges + calc + _ ≤ ∑ e ∈ G, ((e ×ˢ e).filter (fun z => z.1 ≠ z.2)).card := Finset.card_biUnion_le + _ = ∑ _e ∈ G, 2 := by + apply Finset.sum_congr rfl + intro e he + obtain ⟨x,y,hxy,rfl⟩ := Finset.card_eq_two.mp (hG e he) + have hh : (({x,y} : Finset (Fin n)) ×ˢ {x,y}).filter (fun z => z.1 ≠ z.2) = + {(x,y),(y,x)} := by + ext z + rcases z with ⟨u,v⟩ + simp only [Finset.mem_filter,Finset.mem_product,Finset.mem_insert, + Finset.mem_singleton,Prod.mk.injEq] + aesop + rw [hh,Finset.card_pair] + exact fun h => hxy (congrArg Prod.fst h) + _ = _ := by simp [mul_comm] + +open Classical in + +theorem prefixEmbeddings_root_cover {n N R r : ℕ} (J : SimpleGraph (Fin N)) + (G : Graph n) (hG : ∀ e ∈ G, e.card = 2) (hR : R ≤ N) + (u v : Fin r → Fin R) + (hcover : ∀ i : Fin R, ∃ j, i = u j ∨ i = v j) + (hedge : ∀ j, J.Adj (Fin.castLE hR (u j)) (Fin.castLE hR (v j))) : + (prefixEmbeddings J (lookupGraph G) R hR).card ≤ (2 * G.card)^r := by + classical + let s := prefixEmbeddings J (lookupGraph G) R hR + let f : s → (Fin r → ↥(orientedEdges G)) := fun φ j => + ⟨(φ.val (u j),φ.val (v j)),(mem_orientedEdges hG _ _).mpr + ((mem_prefixEmbeddings φ.val).mp φ.property _ _ (hedge j))⟩ + have hi : Function.Injective f := by + intro φ ψ he + apply Subtype.ext + apply Function.Embedding.ext + intro i + obtain ⟨j,hi | hi⟩ := hcover i + · subst i + exact congrArg (fun z : ↥(orientedEdges G) => z.val.1) (congrFun he j) + · subst i + exact congrArg (fun z : ↥(orientedEdges G) => z.val.2) (congrFun he j) + have hc := Fintype.card_le_of_injective f hi + simp only [Fintype.card_coe,Fintype.card_fun,Fintype.card_fin] at hc + exact hc.trans (Nat.pow_le_pow_left (orientedEdges_card_le hG) r) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/OverlapVertices.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/OverlapVertices.lean new file mode 100644 index 0000000000000000000000000000000000000000..3dfd049ff30c89d5ea39886c48fd1d023f19c76a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/OverlapVertices.lean @@ -0,0 +1,334 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEpsilon +import OAI.Combinatorics.TriangleRemoval.Process.TriangleLiftCount + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Classical + +namespace SharpTerminalLeave + +def overlapVertices {k n : ℕ} (W : Finset (Fin n)) (φ : Fin k ↪ Fin n) : Finset (Fin k) := + Finset.univ.filter (fun v => φ v ∈ W) + +@[simp] lemma mem_overlapVertices {k n : ℕ} (W : Finset (Fin n)) (φ : Fin k ↪ Fin n) (v : Fin k) : + v ∈ overlapVertices W φ ↔ φ v ∈ W := by simp [overlapVertices] + +lemma overlapVertices_contains_roots {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (W : Finset (Fin n)) + (hW : ∀ v, ψ v ∈ W) (φ : RootedInjection T ψ) : + T.roots ⊆ overlapVertices W φ.val := by + intro v hv + rw [mem_overlapVertices,φ.property ⟨v,hv⟩] + exact hW ⟨v,hv⟩ + +theorem rooted_overlap_fiber_card {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (W : Finset (Fin n)) (J : Finset (Fin k)) : + Fintype.card {φ : RootedInjection T ψ // overlapVertices W φ.val = J} ≤ + W.card^J.card * n^(k-J.card) := by + let encode : {φ : RootedInjection T ψ // overlapVertices W φ.val = J} → + (J → W) × ({v : Fin k // v ∉ J} → Fin n) := fun φ => + (fun v => ⟨φ.val.val v, by + have hv : v.val ∈ overlapVertices W φ.val.val := by rw [φ.property]; exact v.property + exact (mem_overlapVertices W φ.val.val v).mp hv⟩, + fun v => φ.val.val v) + have hinj : Function.Injective encode := by + intro φ χ he + apply Subtype.ext + apply Subtype.ext + apply DFunLike.ext + intro v + by_cases hv : v ∈ J + · exact congrArg Subtype.val (congrFun (congrArg Prod.fst he) ⟨v,hv⟩) + · exact congrFun (congrArg Prod.snd he) ⟨v,hv⟩ + have hc := Fintype.card_le_of_injective encode hinj + have hfree : Fintype.card {v : Fin k // v ∉ J} = k-J.card := by + simpa only [Fintype.card_fin,Fintype.card_coe] using + Fintype.card_subtype_compl (fun v : Fin k => v ∈ J) + simpa only [Fintype.card_prod,Fintype.card_fun,Fintype.card_coe,Fintype.card_fin,hfree] using hc + +lemma imageEdges_inter_subset_induced {k n : ℕ} (T : RootedTemplate k) + (φ : Fin k ↪ Fin n) (W : Finset (Fin n)) (F : Graph n) + (hF : ∀ e ∈ F, e ⊆ W) : + F ∩ imageEdges T φ ⊆ + (T.edges.filter (fun e => e ⊆ overlapVertices W φ)).image (fun e => e.map φ) := by + intro e he + obtain ⟨heF,heT⟩ := Finset.mem_inter.mp he + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp heT + apply Finset.mem_image.mpr + refine ⟨f,Finset.mem_filter.mpr ⟨hf,?_⟩,rfl⟩ + intro v hv + rw [mem_overlapVertices] + exact hF (f.map φ) heF (Finset.mem_map.mpr ⟨v,hv,rfl⟩) + +theorem rooted_new_edges_lower {k n : ℕ} (T : RootedTemplate k) + (φ : Fin k ↪ Fin n) (W : Finset (Fin n)) (F : Graph n) + (hF : ∀ e ∈ F, e ⊆ W) : + T.edges.card-(T.edges.filter (fun e => e ⊆ overlapVertices W φ)).card ≤ + (imageEdges T φ \ F).card := by + have hc := Finset.card_le_card (imageEdges_inter_subset_induced T φ W F hF) + have hm : ((T.edges.filter (fun e => e ⊆ overlapVertices W φ)).image (fun e => e.map φ)).card = + (T.edges.filter (fun e => e ⊆ overlapVertices W φ)).card := by + apply Finset.card_image_of_injective + exact fun _ _ h => Finset.map_injective φ h + rw [hm] at hc + rw [Finset.card_sdiff,imageEdges_card] + omega + +theorem rooted_weighted_extension_bound {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (W : Finset (Fin n)) (F : Graph n) + (hW : ∀ v, ψ v ∈ W) (hF : ∀ e ∈ F, e ⊆ W) + {p M : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) (hM : 0 ≤ M) + (hscale : ∀ J : Finset (Fin k), T.roots ⊆ J → + (n : ℝ)^(k-J.card)*p^(T.edges.card-(T.edges.filter (fun e => e ⊆ J)).card) ≤ M) : + (∑ φ : RootedInjection T ψ, p^(imageEdges T φ.val \ F).card) ≤ + (2*((W.card : ℝ)+1))^k*M := by + let b : Finset (Fin k) → ℕ := fun J => T.edges.card-(T.edges.filter (fun e => e ⊆ J)).card + have hfirst : (∑ φ : RootedInjection T ψ, p^(imageEdges T φ.val \ F).card) ≤ + ∑ φ : RootedInjection T ψ, p^(b (overlapVertices W φ.val)) := by + apply Finset.sum_le_sum + intro φ _ + exact pow_le_pow_of_le_one hp hp1 (rooted_new_edges_lower T φ.val W F hF) + have hgroup : (∑ φ : RootedInjection T ψ, p^(b (overlapVertices W φ.val))) = + ∑ J : Finset (Fin k), + (Fintype.card {φ : RootedInjection T ψ // overlapVertices W φ.val = J} : ℝ)*p^(b J) := by + rw [← Fintype.sum_fiberwise (fun φ : RootedInjection T ψ => overlapVertices W φ.val)] + apply Finset.sum_congr rfl + intro J _ + calc + _ = ∑ _φ : {φ : RootedInjection T ψ // overlapVertices W φ.val = J}, p^(b J) := by + apply Finset.sum_congr rfl + intro φ _ + rw [φ.property] + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + have hfiber (J : Finset (Fin k)) : + (Fintype.card {φ : RootedInjection T ψ // overlapVertices W φ.val = J} : ℝ)*p^(b J) ≤ + ((W.card : ℝ)+1)^k*M := by + by_cases hJ : T.roots ⊆ J + · have hjk : J.card ≤ k := by simpa only [Fintype.card_fin] using J.card_le_univ + have hc : (Fintype.card {φ : RootedInjection T ψ // overlapVertices W φ.val = J} : ℝ) ≤ + (W.card : ℝ)^J.card*(n : ℝ)^(k-J.card) := by + exact_mod_cast rooted_overlap_fiber_card T ψ W J + have hw : (W.card : ℝ)^J.card ≤ ((W.card : ℝ)+1)^k := by + calc + _ ≤ ((W.card : ℝ)+1)^J.card := pow_le_pow_left₀ (Nat.cast_nonneg _) (by linarith) _ + _ ≤ _ := pow_le_pow_right₀ (show (1 : ℝ) ≤ (W.card : ℝ)+1 by have hz : (0 : ℝ) ≤ W.card := Nat.cast_nonneg _; linarith) hjk + calc + _ ≤ ((W.card : ℝ)^J.card*(n : ℝ)^(k-J.card))*p^(b J) := + mul_le_mul_of_nonneg_right hc (pow_nonneg hp _) + _ = (W.card : ℝ)^J.card*((n : ℝ)^(k-J.card)*p^(b J)) := by ring + _ ≤ ((W.card : ℝ)+1)^k*M := + mul_le_mul hw (hscale J hJ) (by positivity) (by positivity) + · have he : IsEmpty {φ : RootedInjection T ψ // overlapVertices W φ.val = J} := by + refine ⟨fun φ => hJ ?_⟩ + rw [← φ.property] + exact overlapVertices_contains_roots T ψ W hW φ.val + have := he + simp only [Fintype.card_of_isEmpty,Nat.cast_zero,zero_mul] + positivity + calc + _ ≤ _ := hfirst + _ = _ := hgroup + _ ≤ ∑ _J : Finset (Fin k), ((W.card : ℝ)+1)^k*M := Finset.sum_le_sum (fun J _ => hfiber J) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_finset, + Fintype.card_fin,Nat.cast_pow,Nat.cast_ofNat,nsmul_eq_mul]; rw [mul_pow]; ring + +lemma rooted_completion_factorization {k n : ℕ} (T : RootedTemplate k) + (J : Finset (Fin k)) (hJ : T.roots ⊆ J) (p : ℝ) : + ((n : ℝ)^(J.card-T.roots.card)*p^(T.edges.filter (fun e => e ⊆ J)).card) * + ((n : ℝ)^(k-J.card)*p^(T.edges.card-(T.edges.filter (fun e => e ⊆ J)).card)) = + rootedScaling T n p := by + have hi := Finset.card_le_card hJ + have hj : J.card ≤ k := by simpa only [Fintype.card_fin] using J.card_le_univ + have he := Finset.card_le_card (Finset.filter_subset (fun e => e ⊆ J) T.edges) + unfold rootedScaling + calc + _ = (n : ℝ)^((J.card-T.roots.card)+(k-J.card))* + p^((T.edges.filter (fun e => e ⊆ J)).card+ + (T.edges.card-(T.edges.filter (fun e => e ⊆ J)).card)) := by rw [pow_add,pow_add]; ring + _ = _ := by congr 2 <;> omega + +theorem largeTemplate_completion_scale {k n : ℕ} (T : RootedTemplate k) + {p : ℝ} (hp : 0 ≤ p) (hT : largeTemplateEligible T n p) + (J : Finset (Fin k)) (hJ : T.roots ⊆ J) : + (n : ℝ)^(k-J.card)*p^(T.edges.card-(T.edges.filter (fun e => e ⊆ J)).card) ≤ + rootedScaling T n p := by + have hJscale := hT J hJ (T.edges.filter (fun e => e ⊆ J)) + (Finset.filter_subset _ _) (fun e he => (Finset.mem_filter.mp he).2) + rw [← rooted_completion_factorization T J hJ p] + exact le_mul_of_one_le_left (by positivity) hJscale + +def copyUnionSum {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) : ℕ → (Graph n → ℝ) → Graph n → ℝ + | 0,f,F => f F + | q+1,f,F => ∑ a, copyUnionSum required q f (F ∪ required a) + +lemma copyUnionSum_const_mul {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (q : ℕ) (f : Graph n → ℝ) (c : ℝ) (F : Graph n) : + copyUnionSum required q (fun J => c*f J) F = c*copyUnionSum required q f F := by + induction q generalizing F with + | zero => rfl + | succ q ih => simp only [copyUnionSum,ih,Finset.mul_sum] + +lemma copyUnionSum_mono_bounded {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (b N q : ℕ) (hsize : ∀ a, (required a).card ≤ b) + (f g : Graph n → ℝ) (hfg : ∀ F, F.card ≤ N → f F ≤ g F) + (F : Graph n) (hF : F.card+q*b ≤ N) : + copyUnionSum required q f F ≤ copyUnionSum required q g F := by + induction q generalizing F with + | zero => exact hfg F (by simpa using hF) + | succ q ih => + apply Finset.sum_le_sum + intro a _ + apply ih + have hc := Finset.card_union_le F (required a) + have hs := hsize a + have hm : (q+1)*b = q*b+b := by ring + omega + +lemma copyUnionSum_intact {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (q : ℕ) (G F : Graph n) : + copyUnionSum required q (fun J => intact J G) F = intact F G*(copyCount required G)^q := by + induction q generalizing F with + | zero => simp [copyUnionSum] + | succ q ih => + simp only [copyUnionSum,ih,intact_union] + rw [← Finset.sum_mul,← Finset.mul_sum] + change (intact F G*copyCount required G)*(copyCount required G)^q = _ + rw [pow_succ'] + ring + +lemma copyUnionSum_mean {n : ℕ} {α Ω : Type*} [Fintype α] [Fintype Ω] + (required : α → Graph n) (q : ℕ) (μ : PMF Ω) (f : Graph n → Ω → ℝ) (F : Graph n) : + copyUnionSum required q (fun J => pmfMean μ (f J)) F = + pmfMean μ (fun ω => copyUnionSum required q (fun J => f J ω) F) := by + induction q generalizing F with + | zero => rfl + | succ q ih => + simp only [copyUnionSum,ih] + exact (pmfMean_sum μ _).symm + +lemma rooted_image_vertices {k n : ℕ} (T : RootedTemplate k) (φ : Fin k ↪ Fin n) + {e : Finset (Fin n)} (he : e ∈ imageEdges T φ) : e ⊆ Finset.univ.map φ := by + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he + exact Finset.map_subset_map.mpr (Finset.subset_univ f) + +theorem rooted_union_moment_partition {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) {p M : ℝ} + (hp : 0 ≤ p) (hp1 : p ≤ 1) (hM : 0 ≤ M) + (hscale : ∀ J : Finset (Fin k), T.roots ⊆ J → + (n : ℝ)^(k-J.card)*p^(T.edges.card-(T.edges.filter (fun e => e ⊆ J)).card) ≤ M) + (N q : ℕ) (W : Finset (Fin n)) (F : Graph n) + (hW : ∀ v, ψ v ∈ W) (hF : ∀ e ∈ F, e ⊆ W) (hcap : W.card+q*k ≤ N) : + copyUnionSum (fun φ : RootedInjection T ψ => imageEdges T φ.val) + q (fun J => p^J.card) F ≤ + ((2*((N : ℝ)+1))^k*M)^q*p^F.card := by + let B : ℝ := (2*((N : ℝ)+1))^k*M + have hB : 0 ≤ B := by dsimp [B]; positivity + change _ ≤ B^q*p^F.card + induction q generalizing W F with + | zero => simp [copyUnionSum] + | succ q ih => + have hWcap : W.card ≤ N := by omega + have hWreal : (W.card : ℝ) ≤ N := by exact_mod_cast hWcap + have hb : (2*((W.card : ℝ)+1))^k*M ≤ B := by + apply mul_le_mul_of_nonneg_right _ hM + exact pow_le_pow_left₀ (by positivity) (by linarith) _ + have hext := (rooted_weighted_extension_bound T ψ W F hW hF hp hp1 hM hscale).trans hb + calc + _ ≤ ∑ φ : RootedInjection T ψ, B^q*p^(F ∪ imageEdges T φ.val).card := by + apply Finset.sum_le_sum + intro φ _ + apply ih (W := W ∪ Finset.univ.map φ.val) + · intro v + exact Finset.mem_union_left _ (hW v) + · intro e he + rcases Finset.mem_union.mp he with he | he + · exact (hF e he).trans Finset.subset_union_left + · exact (rooted_image_vertices T φ.val he).trans Finset.subset_union_right + · have hc := Finset.card_union_le W (Finset.univ.map φ.val) + have hm : (Finset.univ.map φ.val).card = k := by simp + have hq : (q+1)*k = q*k+k := by ring + omega + _ = B^q*p^F.card*(∑ φ : RootedInjection T ψ, p^(imageEdges T φ.val \ F).card) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro φ _ + have hc : (F ∪ imageEdges T φ.val).card = F.card+(imageEdges T φ.val \ F).card := by + have hu := Finset.card_union_add_card_inter F (imageEdges T φ.val) + have hs := Finset.card_sdiff (s := F) (t := imageEdges T φ.val) + have hl := Finset.card_le_card (Finset.inter_subset_right : F ∩ imageEdges T φ.val ⊆ imageEdges T φ.val) + omega + rw [hc,pow_add] + ring + _ ≤ B^q*p^F.card*B := mul_le_mul_of_nonneg_left hext (by positivity) + _ = _ := by rw [pow_succ]; ring + +theorem rooted_count_moment_from_survival {k n : ℕ} {Ω : Type*} [Fintype Ω] + (T : RootedTemplate k) (ψ : {v // v ∈ T.roots} ↪ Fin n) + (μ : PMF Ω) (state : Ω → Graph n) (A : Ω → Prop) + (q : ℕ) {p M U : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) (hM : 0 ≤ M) (hU : 0 ≤ U) + (hscale : ∀ J : Finset (Fin k), T.roots ⊆ J → + (n : ℝ)^(k-J.card)*p^(T.edges.card-(T.edges.filter (fun e => e ⊆ J)).card) ≤ M) + (hsurvive : ∀ F : Graph n, F.card ≤ q*T.edges.card → + pmfMean μ (fun ω => if A ω then intact F (state ω) else 0) ≤ U*p^F.card) : + pmfMean μ (fun ω => if A ω then (rootedCount T ψ (state ω))^q else 0) ≤ + U*((2*((((q+1)*k : ℕ) : ℝ)+1))^k*M)^q := by + let req : RootedInjection T ψ → Graph n := fun φ => imageEdges T φ.val + let f : Graph n → ℝ := fun F => pmfMean μ (fun ω => if A ω then intact F (state ω) else 0) + have he : copyUnionSum req q f ∅ = + pmfMean μ (fun ω => if A ω then (rootedCount T ψ (state ω))^q else 0) := by + rw [copyUnionSum_mean req q μ] + apply pmfMean_congr + intro ω _ + by_cases hA : A ω + · simp only [hA,ite_true] + rw [copyUnionSum_intact] + simp only [intact,Finset.empty_subset,ite_true,one_mul] + rfl + · simp only [hA,ite_false] + have hz := copyUnionSum_const_mul req q (fun _ => (1 : ℝ)) 0 ∅ + simpa only [zero_mul] using hz + let W : Finset (Fin n) := Finset.univ.map ψ + have hw : ∀ v, ψ v ∈ W := fun v => Finset.mem_map.mpr ⟨v,Finset.mem_univ _,rfl⟩ + have hWcard : W.card ≤ k := by + have he : W.card = T.roots.card := by simp [W] + rw [he] + simpa only [Fintype.card_fin] using T.roots.card_le_univ + have hb := rooted_union_moment_partition T ψ hp hp1 hM hscale ((q+1)*k) q W ∅ hw + (by simp) (by nlinarith) + simp only [Finset.card_empty,pow_zero,mul_one] at hb + calc + _ = copyUnionSum req q f ∅ := he.symm + _ ≤ copyUnionSum req q (fun F => U*p^F.card) ∅ := + copyUnionSum_mono_bounded req T.edges.card (q*T.edges.card) q + (fun φ => by simp only [req,imageEdges_card,le_refl]) f _ hsurvive ∅ (by simp) + _ = U*copyUnionSum req q (fun F => p^F.card) ∅ := copyUnionSum_const_mul req q _ U ∅ + _ ≤ _ := mul_le_mul_of_nonneg_left hb hU + +theorem pmfMean_stopped_power_tail {Ω : Type*} [Fintype Ω] + (μ : PMF Ω) (A : Ω → Prop) (X : Ω → ℝ) (hX : ∀ ω, 0 ≤ X ω) + (q : ℕ) {t B : ℝ} (ht : 0 < t) + (hmean : pmfMean μ (fun ω => if A ω then X ω^q else 0) ≤ B) : + pmfMean μ (fun ω => if A ω ∧ t ≤ X ω then 1 else 0) ≤ B/t^q := by + apply (le_div_iff₀ (pow_pos ht q)).mpr + rw [← pmfMean_mul_const] + apply le_trans _ hmean + apply pmfMean_mono + intro ω _ + by_cases hA : A ω + · by_cases htX : t ≤ X ω + · simp only [hA,htX,and_self,ite_true,one_mul] + exact pow_le_pow_left₀ ht.le htX q + · simp only [hA,htX,and_false,ite_false,ite_true,zero_mul] + exact pow_nonneg (hX ω) q + · simp [hA] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PairRequired.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PairRequired.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f3430200ee77bcd01ba4b740d4c83fe47e8e68f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PairRequired.lean @@ -0,0 +1,178 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PathRequired + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +def pairRequired {A : Type*} [DecidableEq A] (p q address : List A) : Bool := + pathRequired p address || pathRequired q address + +lemma pairRequired_shift_left {A : Type*} [DecidableEq A] (a b : A) + (as bs address : List A) (hab : a ≠ b) : + pairRequired (a :: as) (b :: bs) (address ++ [a]) = pathRequired as address := by + simp [pairRequired,pathRequired,List.reverse_append,List.cons_prefix_cons,hab] + +lemma pairRequired_shift_right {A : Type*} [DecidableEq A] (a b : A) + (as bs address : List A) (hab : a ≠ b) : + pairRequired (a :: as) (b :: bs) (address ++ [b]) = pathRequired bs address := by + simp [pairRequired,pathRequired,List.reverse_append,List.cons_prefix_cons,hab.symm] + +section ForkVisitation +variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +omit [Fintype ι] in +lemma pair_required_candidates (H : τ → Finset ι) (focus : Finset ι) (parent : Option τ) + (a b : gridCandidates H focus parent) (as bs : List (ι × τ)) : + requiredCandidates H (pairRequired (a.val :: as) (b.val :: bs)) [] focus parent = + {a,b} := by + ext c + simp only [requiredCandidates,Finset.mem_filter,Finset.mem_univ,true_and,pairRequired, + pathRequired_singleton,Bool.or_eq_true,decide_eq_true_eq,Finset.mem_insert, + Finset.mem_singleton,Subtype.val_injective.eq_iff] + +omit [Fintype ι] in +lemma marked_pair_child_left (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d : ℕ) (focus : Finset ι) (parent : Option τ) + (a b : gridCandidates H focus parent) (hab : a ≠ b) + (as bs : List (ι × τ)) (u : Fin N) : + markedChildKernel H N (pairRequired (a.val :: as) (b.val :: bs)) d [] focus parent a u = + ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N (pathRequired as) d u.val [] + ((H a.val.2).erase a.val.1) (some a.val.2)) := by + unfold markedChildKernel + change ExposureTree.fresh _ (markedGridQueryDepth H N _ d u.val ([] ++ [a.val]) _ _) = _ + rw [markedGridQueryDepth_readdress] + have he : (fun l => pairRequired (a.val :: as) (b.val :: bs) (l ++ [a.val])) = + pathRequired as := by + funext l + exact pairRequired_shift_left _ _ _ _ _ (fun h => hab (Subtype.ext h)) + rw [he] + +omit [Fintype ι] in +lemma marked_pair_child_right (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d : ℕ) (focus : Finset ι) (parent : Option τ) + (a b : gridCandidates H focus parent) (hab : a ≠ b) + (as bs : List (ι × τ)) (u : Fin N) : + markedChildKernel H N (pairRequired (a.val :: as) (b.val :: bs)) d [] focus parent b u = + ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N (pathRequired bs) d u.val [] + ((H b.val.2).erase b.val.1) (some b.val.2)) := by + unfold markedChildKernel + change ExposureTree.fresh _ (markedGridQueryDepth H N _ d u.val ([] ++ [b.val]) _ _) = _ + rw [markedGridQueryDepth_readdress] + have he : (fun l => pairRequired (a.val :: as) (b.val :: bs) (l ++ [b.val])) = + pathRequired bs := by + funext l + exact pairRequired_shift_right _ _ _ _ _ (fun h => hab (Subtype.ext h)) + rw [he] + +noncomputable def pairVisitProbability (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (p q : List (ι × τ)) : ℝ := + markedGood (ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N (pairRequired p q) d k [] focus parent)) + +lemma discrete_ordered_step (N k : ℕ) (hk : k ≤ N) (b : ℕ → ℝ) (j : ℕ) : + (1/(N : ℝ))*(∑ u : Fin N, if u.val < k then + orderedWeight (fun t => (2/(N : ℝ))*b t) j u.val*(2*b u.val) else 0) = + orderedWeight (fun t => (2/(N : ℝ))*b t) (j+1) k := by + rw [Finset.mul_sum,orderedWeight] + have hs := sum_fin_filter_lt_eq_range N k hk + (fun t => (2/(N : ℝ))*b t*orderedWeight (fun t => (2/(N : ℝ))*b t) j t) + rw [Finset.sum_filter] at hs + rw [← hs] + apply Finset.sum_congr rfl + intro u _ + by_cases hu : u.val < k <;> simp only [hu,↓reduceIte] <;> ring + +omit [Fintype ι] in + +theorem pairVisitProbability_fork (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 0 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (hkd : k ≤ d+1) (hkN : k ≤ N) + (e : ι) (T : τ) (he : e ∈ H T) + (a b' : gridCandidates H ((H T).erase e) (some T)) (hab : a ≠ b') + (as bs : List (ι × τ)) (ha : LegalQueryPath H ((H a.val.2).erase a.val.1) (some a.val.2) as) + (hb' : LegalQueryPath H ((H b'.val.2).erase b'.val.1) (some b'.val.2) bs) + (halen : as.length ≤ d) (hblen : bs.length ≤ d) : + pairVisitProbability H N (d+1) k ((H T).erase e) (some T) (a.val :: as) (b'.val :: bs) ≤ + C * orderedWeight (fun t => (2/(N : ℝ))*b t) (as.length+1) k * + orderedWeight (fun t => (2/(N : ℝ))*b t) (bs.length+1) k := by + let A := fun t => orderedWeight (fun t => (2/(N : ℝ))*b t) as.length t + let B := fun t => orderedWeight (fun t => (2/(N : ℝ))*b t) bs.length t + have hA : ∀ t, 0 ≤ A t := fun t => orderedWeight_nonneg (fun t => mul_nonneg (by positivity) (hb t)) _ t + have hB : ∀ t, 0 ≤ B t := fun t => orderedWeight_nonneg (fun t => mul_nonneg (by positivity) (hb t)) _ t + have hstep := markedQuery_two_paths H N (pairRequired (a.val :: as) (b'.val :: bs)) d k hkd hkN [] + ((H T).erase e) (some T) a b' hab (pair_required_candidates H _ _ a b' as bs) b + (fun t ht => hq.1 t (by omega)) (fun t ht => hq.2 t (by omega) e T he) + have hac := (Finset.mem_filter.mp a.property).2.1 + have hbc := (Finset.mem_filter.mp b'.property).2.1 + calc + _ ≤ (1/(N : ℝ))*∑ u : Fin N, (1/(N : ℝ))*∑ v : Fin N, + if u.val < k ∧ v.val < k then + (markedGood (markedChildKernel H N (pairRequired (a.val :: as) (b'.val :: bs)) d [] + ((H T).erase e) (some T) a u)* + markedGood (markedChildKernel H N (pairRequired (a.val :: as) (b'.val :: bs)) d [] + ((H T).erase e) (some T) b' v))*(2*b (max u.val v.val)) else 0 := hstep + _ ≤ (1/(N : ℝ))*∑ u : Fin N, (1/(N : ℝ))*∑ v : Fin N, + C*((if u.val < k then A u.val*(2*b u.val) else 0)* + (if v.val < k then B v.val*(2*b v.val) else 0)) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro u _ + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro v _ + by_cases hu : u.val < k <;> by_cases hv : v.val < k + · simp only [hu,hv,and_self,↓reduceIte] + rw [marked_pair_child_left H N d _ _ a b' hab as bs u, + marked_pair_child_right H N d _ _ a b' hab as bs v] + have hau := pathVisitProbability_ordered H N b hb hq as d u.val (by omega) u.isLt.le + halen a.val.1 a.val.2 hac ha + have hbv := pathVisitProbability_ordered H N b hb hq bs d v.val (by omega) v.isLt.le + hblen b'.val.1 b'.val.2 hbc hb' + have hm : b (max u.val v.val) ≤ C*(b u.val*b v.val) := by + rcases le_total u.val v.val with h | h + · rw [max_eq_right h] + simpa only [one_mul,mul_assoc] using + mul_le_mul_of_nonneg_right (hlower u.val u.isLt.le) (hb v.val) + · rw [max_eq_left h] + have hh := mul_le_mul_of_nonneg_right (hlower v.val v.isLt.le) (hb u.val) + nlinarith + have hp := mul_le_mul hau hbv (markedGood_nonneg _) (hA _) + have hprod := mul_le_mul_of_nonneg_right hp + (mul_nonneg (by norm_num : (0 : ℝ) ≤ 2) (hb (max u.val v.val))) + have hwm := mul_le_mul_of_nonneg_left hm (mul_nonneg (hA u.val) (hB v.val)) + dsimp only [pathVisitProbability] at hprod + calc + _ ≤ A u.val*B v.val*(2*b (max u.val v.val)) := hprod + _ ≤ _ := by + have hn := mul_nonneg (mul_nonneg (hA u.val) (hB v.val)) + (mul_nonneg hC (mul_nonneg (hb u.val) (hb v.val))) + nlinarith + · simp only [hu,hv,and_false,↓reduceIte,mul_zero,le_refl] + · simp only [hu,hv,false_and,↓reduceIte,zero_mul,mul_zero,le_refl] + · simp only [hu,hv,false_and,↓reduceIte,mul_zero,le_refl] + _ = C*((1/(N : ℝ))*∑ u : Fin N, if u.val < k then A u.val*(2*b u.val) else 0)* + ((1/(N : ℝ))*∑ v : Fin N, if v.val < k then B v.val*(2*b v.val) else 0) := by + simp only [← Finset.mul_sum,← Finset.sum_mul] + ring + _ = _ := by + rw [discrete_ordered_step N k hkN b as.length,discrete_ordered_step N k hkN b bs.length] + +end ForkVisitation +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/Parent.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/Parent.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8c76a1488056fedceda8e1b77ca09f809ba3ca0 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/Parent.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.OlderSeed + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.TriangleGrowth +variable {V : Type*} [DecidableEq V] {G : SimpleGraph V} {N R : ℕ} +variable (A : TriangleGrowth G N R) + +def Parent (x y : Fin N) : Prop := R ≤ y.val ∧ A.parent y = some x + +def Ancestor : Fin N → Fin N → Prop := Relation.ReflTransGen A.Parent + +lemma parent_older {x y : Fin N} (h : A.Parent x y) : x ∈ A.older y := + A.parent_mem_older h.1 h.2 + +lemma parent_le {x y : Fin N} (h : A.Parent x y) : x ≤ y := + le_of_lt (A.parent_lt y x h.1 h.2) + +lemma ancestor_le {x y : Fin N} (h : A.Ancestor x y) : x ≤ y := by + induction h with + | refl => exact le_rfl + | @tail y z _ hyz ih => exact ih.trans (A.parent_le hyz) + +lemma ancestor_trans {x y z : Fin N} (hxy : A.Ancestor x y) (hyz : A.Ancestor y z) : + A.Ancestor x z := hxy.trans hyz + +lemma older_ancestor (v : Fin N) : ∀ x ∈ A.older v, + x.val < R ∨ A.Ancestor x v := by + induction v using (measure (fun v : Fin N => v.val)).wf.induction with + | h v ih => + intro x hx + by_cases hv : R ≤ v.val + · cases hp : A.parent v with + | none => exact Or.inl (A.older_root_of_none hv hp hx) + | some p => + have hstep : A.Ancestor p v := Relation.ReflTransGen.single ⟨hv,hp⟩ + have hpv := A.parent_lt v p hv hp + rw [older,dite_eq_left hv,hp] at hx + rcases Finset.mem_insert.mp (Finset.mem_filter.mp hx).1 with rfl | hx + · exact Or.inr hstep + · exact (ih p hpv x hx).imp_right (fun h => h.trans hstep) + · rw [A.older_eq_seed (Nat.lt_of_not_ge hv)] at hx + exact Or.inl (A.seed_root v x hx (Nat.lt_of_not_ge hv)) + +noncomputable def pathUnion (a b : Fin N) : Finset (Fin N) := by + classical + exact Finset.univ.filter (fun x => x.val < R ∨ A.Ancestor x a ∨ A.Ancestor x b) + +@[simp] lemma mem_pathUnion (a b x : Fin N) : + x ∈ A.pathUnion a b ↔ x.val < R ∨ A.Ancestor x a ∨ A.Ancestor x b := by + classical + simp only [pathUnion,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma left_mem_pathUnion (a b : Fin N) : a ∈ A.pathUnion a b := + (A.mem_pathUnion a b a).mpr (Or.inr (Or.inl Relation.ReflTransGen.refl)) + +lemma right_mem_pathUnion (a b : Fin N) : b ∈ A.pathUnion a b := + (A.mem_pathUnion a b b).mpr (Or.inr (Or.inr Relation.ReflTransGen.refl)) + +lemma pathUnion_older_closed {a b v x : Fin N} (hv : v ∈ A.pathUnion a b) + (hx : x ∈ A.older v) : x ∈ A.pathUnion a b := by + apply (A.mem_pathUnion a b x).mpr + rcases A.older_ancestor v x hx with hroot | hanc + · exact Or.inl hroot + · rcases (A.mem_pathUnion a b v).mp hv with hroot | ha | hb + · exact Or.inl (lt_of_le_of_lt (A.ancestor_le hanc) hroot) + · exact Or.inr (Or.inl (hanc.trans ha)) + · exact Or.inr (Or.inr (hanc.trans hb)) + +lemma pathUnion_subset_lower {a b : Fin N} {S : Set (Fin N)} (hS : IsLowerSet S) + (hroots : ∀ x : Fin N, x.val < R → x ∈ S) (ha : a ∈ S) (hb : b ∈ S) : + ↑(A.pathUnion a b) ⊆ S := by + intro x hx + rcases (A.mem_pathUnion a b x).mp hx with hroot | hanc | hanc + · exact hroots x hroot + · exact hS (A.ancestor_le hanc) ha + · exact hS (A.ancestor_le hanc) hb + +end SharpTerminalLeave.TriangleGrowth + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PathForest.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathForest.lean new file mode 100644 index 0000000000000000000000000000000000000000..40e7d502415853e287e44ef52ff8c509959e5db7 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathForest.lean @@ -0,0 +1,170 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def PathForest (s : ℕ) := + {p : Fin s → Option (Fin s) // ∀ i j, p i = some j → j < i} + +namespace PathForest +variable {s : ℕ} + +noncomputable instance : Fintype (PathForest s) := by + classical + unfold PathForest + infer_instance +noncomputable instance : DecidableEq (PathForest s) := Classical.decEq _ + +def parent (F : PathForest s) : Fin s → Option (Fin s) := F.val + +def Step (F : PathForest s) (x y : Fin s) : Prop := F.parent y = some x + +def Ancestor (F : PathForest s) : Fin s → Fin s → Prop := Relation.ReflTransGen F.Step + +def OnPath (F : PathForest s) (a : Option (Fin s)) (v : Fin s) : Prop := + ∃ w, a = some w ∧ F.Ancestor v w + +lemma step_lt (F : PathForest s) {x y : Fin s} (h : F.Step x y) : x < y := F.property y x h + +lemma ancestor_le (F : PathForest s) {x y : Fin s} (h : F.Ancestor x y) : x ≤ y := by + induction h with + | refl => exact le_rfl + | tail _ hp ih => exact ih.trans (F.step_lt hp).le + +lemma predecessor_unique (F : PathForest s) {x y z : Fin s} + (hx : F.Step x z) (hy : F.Step y z) : x = y := Option.some.inj (hx.symm.trans hy) + +lemma ancestor_eq_or_predecessor (F : PathForest s) {x z : Fin s} + (h : F.Ancestor x z) : x = z ∨ ∃ y, F.Step y z ∧ F.Ancestor x y := by + cases h with + | refl => exact Or.inl rfl + | @tail y z hxy hyz => exact Or.inr ⟨y,hyz,hxy⟩ + +lemma ancestors_comparable (F : PathForest s) {x y z : Fin s} + (hx : F.Ancestor x z) (hy : F.Ancestor y z) : + F.Ancestor x y ∨ F.Ancestor y x := by + induction hx generalizing y with + | refl => exact Or.inr hy + | @tail v z hxv hvz ih => + rcases F.ancestor_eq_or_predecessor hy with rfl | ⟨w,hwz,hyw⟩ + · exact Or.inl (Relation.ReflTransGen.tail hxv hvz) + · have he := F.predecessor_unique hvz hwz + subst w + exact ih hyw + +lemma onPath_ancestor (F : PathForest s) {a : Option (Fin s)} {x y : Fin s} + (hx : F.Ancestor x y) (hy : F.OnPath a y) : F.OnPath a x := by + obtain ⟨w,rfl,hyw⟩ := hy + exact ⟨w,rfl,hx.trans hyw⟩ + +lemma onPath_comparable (F : PathForest s) {a : Option (Fin s)} {x y : Fin s} + (hx : F.OnPath a x) (hy : F.OnPath a y) : F.Ancestor x y ∨ F.Ancestor y x := by + obtain ⟨u,hu,hxu⟩ := hx + obtain ⟨v,hv,hyv⟩ := hy + have he := Option.some.inj (hu.symm.trans hv) + subst v + exact F.ancestors_comparable hxu hyv + +lemma onPath_before (F : PathForest s) {a : Option (Fin s)} {x y : Fin s} + (hx : F.OnPath a x) (hy : F.OnPath a y) (hxy : x < y) : F.Ancestor x y := by + rcases F.onPath_comparable hx hy with h | h + · exact h + · exact False.elim (not_le_of_gt hxy (F.ancestor_le h)) + +theorem parent_determined (F H : PathForest s) (a b : Option (Fin s)) + (hcover : ∀ v, F.OnPath a v ∨ F.OnPath b v) + (ha : ∀ v, F.OnPath a v ↔ H.OnPath a v) + (hb : ∀ v, F.OnPath b v ↔ H.OnPath b v) : F = H := by + have hone : ∀ (U W : PathForest s) (c : Option (Fin s)) (v p : Fin s), + (∀ i, U.OnPath c i ↔ W.OnPath c i) → U.OnPath c v → U.Step p v → + ∃ q, W.Step q v ∧ p ≤ q := by + intro U W c v p he hv hp + have hpc := U.onPath_ancestor (Relation.ReflTransGen.single hp) hv + have hbefore := W.onPath_before ((he p).mp hpc) ((he v).mp hv) (U.step_lt hp) + rcases W.ancestor_eq_or_predecessor hbefore with h | ⟨q,hq,hpq⟩ + · exact False.elim (ne_of_lt (U.step_lt hp) h) + · exact ⟨q,hq,W.ancestor_le hpq⟩ + apply Subtype.ext + funext v + change F.parent v = H.parent v + obtain ⟨c,hcv,he⟩ : ∃ c, F.OnPath c v ∧ ∀ i, F.OnPath c i ↔ H.OnPath c i := by + rcases hcover v with hv | hv + · exact ⟨a,hv,ha⟩ + · exact ⟨b,hv,hb⟩ + cases hF : F.parent v with + | none => + cases hH : H.parent v with + | none => rfl + | some q => + obtain ⟨p,hp,_⟩ := hone H F c v q (fun i => (he i).symm) ((he v).mp hcv) hH + change F.parent v = some p at hp + rw [hF] at hp + contradiction + | some p => + obtain ⟨q,hq,hpq⟩ := hone F H c v p he hcv hF + obtain ⟨p',hp',hqp'⟩ := hone H F c v q (fun i => (he i).symm) ((he v).mp hcv) hq + have hpp' : p = p' := F.predecessor_unique hF hp' + have hpq' : p = q := le_antisymm hpq (hpp' ▸ hqp') + rw [show H.parent v = some q from hq,hpq'] + +inductive PathColor + | left | right | both + deriving DecidableEq + +instance : Fintype PathColor where + elems := {.left,.right,.both} + complete := by intro x; cases x <;> simp + +noncomputable def color (F : PathForest s) (a b : Option (Fin s)) (v : Fin s) : PathColor := by + classical + exact if F.OnPath a v then if F.OnPath b v then .both else .left else .right + +lemma color_left_iff (F : PathForest s) (a b : Option (Fin s)) (v : Fin s) : + F.color a b v ≠ .right ↔ F.OnPath a v := by + classical + simp only [color] + split_ifs <;> simp_all + +lemma color_right_iff (F : PathForest s) (a b : Option (Fin s)) (v : Fin s) + (hc : F.OnPath a v ∨ F.OnPath b v) : + F.color a b v ≠ .left ↔ F.OnPath b v := by + classical + simp only [color] + split_ifs <;> simp_all + +open Classical in + +theorem two_path_forest_count (a b : Option (Fin s)) : + Fintype.card {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v} ≤ 3^s := by + classical + let f : {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v} → (Fin s → PathColor) := + fun F => F.val.color a b + have hf : Function.Injective f := by + intro F H h + apply Subtype.ext + apply parent_determined F.val H.val a b F.property + · intro v + rw [← color_left_iff,← color_left_iff] + exact congrArg (fun z => z ≠ PathColor.right) (congrFun h v) |>.to_iff + · intro v + rw [← color_right_iff _ _ _ _ (F.property v),← color_right_iff _ _ _ _ (H.property v)] + exact congrArg (fun z => z ≠ PathColor.left) (congrFun h v) |>.to_iff + have hh := Fintype.card_le_of_injective f hf + simpa [Fintype.card_fun,show Fintype.card PathColor = 3 from rfl] using hh + +end PathForest +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PathPattern.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathPattern.lean new file mode 100644 index 0000000000000000000000000000000000000000..a680982d690404d9367c8d995b163e60d0842785 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathPattern.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Process.PathSuffix +import OAI.Combinatorics.TriangleRemoval.Coupling.OrderEmbRank +import OAI.Combinatorics.TriangleRemoval.Process.Restrict + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.TriangleGrowth +variable {n N R : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N R) + +noncomputable def pathPattern (a b : Fin N) : BirthGraph (A.pathUnion a b).card := + A.birthGraph.restrict (A.pathUnion a b) + (fun _ hv _ hx => A.pathUnion_older_closed hv hx) + +noncomputable def pathIndex (a b x : Fin N) (hx : x ∈ A.pathUnion a b) : + Fin (A.pathUnion a b).card := (A.pathUnion a b).orderIsoOfFin rfl |>.symm ⟨x,hx⟩ + +@[simp] lemma pathIndex_image (a b x : Fin N) (hx : x ∈ A.pathUnion a b) : + (A.pathUnion a b).orderEmbOfFin rfl (A.pathIndex a b x hx) = x := + congrArg Subtype.val ((A.pathUnion a b).orderIsoOfFin rfl |>.apply_symm_apply ⟨x,hx⟩) + +noncomputable def pathAssignment (a b : Fin N) + (hi : Set.InjOn A.label (A.pathUnion a b)) : Fin (A.pathUnion a b).card ↪ Fin n where + toFun i := A.label ((A.pathUnion a b).orderEmbOfFin rfl i) + inj' := by + intro i j he + apply (A.pathUnion a b).orderEmbOfFin rfl |>.injective + exact hi ((A.pathUnion a b).orderEmbOfFin_mem rfl i) + ((A.pathUnion a b).orderEmbOfFin_mem rfl j) he + +@[simp] lemma pathAssignment_index (a b x : Fin N) (hx : x ∈ A.pathUnion a b) + (hi : Set.InjOn A.label (A.pathUnion a b)) : + A.pathAssignment a b hi (A.pathIndex a b x hx) = A.label x := by + change A.label ((A.pathUnion a b).orderEmbOfFin rfl (A.pathIndex a b x hx)) = A.label x + rw [A.pathIndex_image] + +theorem pathPattern_nonroot (a b : Fin N) (i : Fin (A.pathUnion a b).card) + (hi : R ≤ i.val) : ((A.pathPattern a b).older i).card = 2 := by + rw [pathPattern,BirthGraph.restrict_older_card] + exact ((A.older_invariants _).2 (orderEmb_nonroot _ + (fun x hx => (A.mem_pathUnion a b x).mpr (Or.inl hx)) i hi)).1 + +theorem pathAssignment_mem {a b : Fin N} + (hi : Set.InjOn A.label (A.pathUnion a b)) + (he : A.birthGraph.ExtraEdge (lookupGraph G) A.label a b) : + A.pathAssignment a b hi ∈ graphEmbeddingSet + (insert ({A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)} : Finset _) + ((A.pathPattern a b).backEdges Finset.univ)) G := by + classical + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _,?_⟩ + intro e he' + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he' + rcases Finset.mem_insert.mp hf with rfl | hf + · simpa only [Finset.map_insert,Finset.map_singleton,A.pathAssignment_index] using he.2.2.2 + · obtain ⟨v,_,u,hu,rfl⟩ := (A.pathPattern a b).backEdges_mem_pair hf + have hAdj : A.birthGraph.graph.Adj ((A.pathUnion a b).orderEmbOfFin rfl u) + ((A.pathUnion a b).orderEmbOfFin rfl v) := by + exact (BirthGraph.restrict_graph_adj _ _ _ _ _).mp (Or.inl hu) + have h := A.spawnRules.edge_labels _ _ hAdj + simp only [Finset.map_insert,Finset.map_singleton] + change ({A.label ((A.pathUnion a b).orderEmbOfFin rfl u), + A.label ((A.pathUnion a b).orderEmbOfFin rfl v)} : Finset (Fin n)) ∈ G + exact h.2 + +lemma pathPattern_extra {a b : Fin N} + (he : A.birthGraph.ExtraEdge (lookupGraph G) A.label a b) : + let a' := A.pathIndex a b a (A.left_mem_pathUnion a b) + let b' := A.pathIndex a b b (A.right_mem_pathUnion a b) + a' ≠ b' ∧ ¬ (A.pathPattern a b).graph.Adj a' b' := by + dsimp only + constructor + · intro h + have hh := congrArg ((A.pathUnion a b).orderEmbOfFin rfl) h + apply he.1 + simpa only [A.pathIndex_image] using hh + · intro h + have hh := (BirthGraph.restrict_graph_adj _ _ _ _ _).mp h + apply he.2.1 + simpa only [A.pathIndex_image] using hh + +theorem pathPattern_covered (a b : Fin N) (k : ℕ) + (hR : R ≤ k) (hk : k < (A.pathUnion a b).card) : + (A.pathPattern a b).Covered (Finset.univ.filter (fun x => k ≤ x.val)) + (A.pathIndex a b a (A.left_mem_pathUnion a b)) + (A.pathIndex a b b (A.right_mem_pathUnion a b)) := by + classical + let s := A.pathUnion a b + let y := s.orderEmbOfFin rfl ⟨k,hk⟩ + have hRy : R ≤ y.val := orderEmb_nonroot s + (fun x hx => (A.mem_pathUnion a b x).mpr (Or.inl hx)) ⟨k,hk⟩ hR + have hZ : A.pathSuffix a b y.val ⊆ s := by + intro x hx + exact ((A.mem_pathSuffix a b x y.val).mp hx).1 + have heq : reindexSet s (A.pathSuffix a b y.val) = + Finset.univ.filter (fun x => k ≤ x.val) := by + ext i + simp only [mem_reindexSet,A.mem_pathSuffix,Finset.mem_filter,Finset.mem_univ,true_and] + have him := s.orderEmbOfFin_mem rfl i + have hiff : y ≤ s.orderEmbOfFin rfl i ↔ (⟨k,hk⟩ : Fin s.card) ≤ i := + (s.orderEmbOfFin rfl).le_iff_le + exact ⟨fun h => hiff.mp h.2,fun h => ⟨him,hiff.mpr h⟩⟩ + have h := A.birthGraph.restrict_covered s + (fun _ hv _ hx => A.pathUnion_older_closed hv hx) + (A.pathSuffix a b y.val) hZ (A.left_mem_pathUnion a b) (A.right_mem_pathUnion a b) + (A.pathSuffix_covered a b y.val hRy) + rw [heq] at h + exact h + +end SharpTerminalLeave.TriangleGrowth + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequired.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequired.lean new file mode 100644 index 0000000000000000000000000000000000000000..7055af65bbdda42214bbe96557600f6b83c8faab --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequired.lean @@ -0,0 +1,164 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.MarkedChildKernelProspective +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixWeight + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +def pathRequired {A : Type*} [DecidableEq A] (path address : List A) : Bool := + decide (address.reverse <+: path) + +lemma pathRequired_singleton {A : Type*} [DecidableEq A] (a b : A) (as : List A) : + pathRequired (a :: as) [b] = decide (b = a) := by + simp [pathRequired,List.cons_prefix_cons] + +lemma pathRequired_shift {A : Type*} [DecidableEq A] (a : A) (as address : List A) : + pathRequired (a :: as) (address ++ [a]) = pathRequired as address := by + simp [pathRequired,List.reverse_append] + +section PathVisitation +variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +def LegalQueryPath (H : τ → Finset ι) : Finset ι → Option τ → List (ι × τ) → Prop + | _, _, [] => True + | focus, parent, a :: as => a ∈ gridCandidates H focus parent ∧ + LegalQueryPath H ((H a.2).erase a.1) (some a.2) as + +omit [Fintype ι] in +lemma path_required_candidates (H : τ → Finset ι) (focus : Finset ι) (parent : Option τ) + (a : gridCandidates H focus parent) (as : List (ι × τ)) : + requiredCandidates H (pathRequired (a.val :: as)) [] focus parent = {a} := by + ext b + simp only [requiredCandidates,Finset.mem_filter,Finset.mem_univ,true_and, + pathRequired_singleton,decide_eq_true_eq,Finset.mem_singleton] + exact Subtype.val_injective.eq_iff + +omit [Fintype ι] in + +lemma markedGridQueryDepth_readdress (H : τ → Finset ι) (N : ℕ) + (required : List (ι × τ) → Bool) (d k : ℕ) + (address base : List (ι × τ)) (focus : Finset ι) (parent : Option τ) : + markedGridQueryDepth H N required d k (address ++ base) focus parent = + markedGridQueryDepth H N (fun l => required (l ++ base)) d k address focus parent := by + induction d generalizing k address focus parent with + | zero => rfl + | succ d ih => + simp only [markedGridQueryDepth] + congr 1 + funext values + congr 1 + apply List.map_congr_left + intro p _ + congr 1 + split + · simpa only [List.cons_append] using + ih p.2.val (p.1 :: address) ((H p.1.2).erase p.1.1) (some p.1.2) + · rfl + +omit [Fintype ι] in +lemma marked_path_child (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d : ℕ) (focus : Finset ι) (parent : Option τ) + (a : gridCandidates H focus parent) (as : List (ι × τ)) (u : Fin N) : + markedChildKernel H N (pathRequired (a.val :: as)) d [] focus parent a u = + ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N (pathRequired as) d u.val [] + ((H a.val.2).erase a.val.1) (some a.val.2)) := by + unfold markedChildKernel + change ExposureTree.fresh _ (markedGridQueryDepth H N _ d u.val ([] ++ [a.val]) _ _) = _ + rw [markedGridQueryDepth_readdress] + have he : (fun l => pathRequired (a.val :: as) (l ++ [a.val])) = pathRequired as := by + funext l + exact pathRequired_shift _ _ _ + rw [he] + +noncomputable def pathVisitProbability (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (path : List (ι × τ)) : ℝ := + markedGood (ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N (pathRequired path) d k [] focus parent)) + +def GridRowQuality (H : τ → Finset ι) (N : ℕ) [NeZero N] (b : ℕ → ℝ) : Prop := + (∀ t ≤ N, ∀ (e : ι) (T : τ), e ∈ H T → + (7/8 : ℝ) ≤ gridCandidateFailure H N t e T) ∧ + (∀ t ≤ N, ∀ (e : ι) (T : τ), e ∈ H T → + gridAnswerProbability H N N t ((H T).erase e) (some T) ≤ (9/8 : ℝ)*b t) + +omit [Fintype ι] in + +theorem pathVisitProbability_ordered (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (path : List (ι × τ)) (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) + (hlen : path.length ≤ d) (e : ι) (T : τ) (he : e ∈ H T) + (hpath : LegalQueryPath H ((H T).erase e) (some T) path) : + pathVisitProbability H N d k ((H T).erase e) (some T) path ≤ + orderedWeight (fun t => (2/(N : ℝ))*b t) path.length k := by + induction path generalizing d k e T with + | nil => + simpa only [List.length_nil,orderedWeight,pathVisitProbability] using markedGood_le_one _ + | cons a as ih => + cases d with + | zero => simp only [List.length_cons] at hlen; omega + | succ d => + obtain ⟨ha,htail⟩ := hpath + let a' : gridCandidates H ((H T).erase e) (some T) := ⟨a,ha⟩ + have haT : a.1 ∈ H a.2 := (Finset.mem_filter.mp ha).2.1 + have hstep := markedQuery_single_path H N (pathRequired (a :: as)) d k hkd hkN [] + ((H T).erase e) (some T) a' (path_required_candidates H _ _ a' as) b + (fun t ht => hq.1 t (by omega)) + (fun t ht => hq.2 t (by omega) e T he) + change pathVisitProbability H N (d+1) k ((H T).erase e) (some T) (a :: as) ≤ _ at hstep + calc + _ ≤ (1/(N : ℝ))*∑ u : Fin N, if u.val < k then + markedGood (markedChildKernel H N (pathRequired (a :: as)) d [] + ((H T).erase e) (some T) a' u)*(2*b u.val) else 0 := hstep + _ ≤ (1/(N : ℝ))*∑ u : Fin N, if u.val < k then + orderedWeight (fun t => (2/(N : ℝ))*b t) as.length u.val*(2*b u.val) else 0 := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro u _ + by_cases hu : u.val < k + · simp only [hu,↓reduceIte] + apply mul_le_mul_of_nonneg_right _ (mul_nonneg (by norm_num) (hb _)) + rw [marked_path_child H N d ((H T).erase e) (some T) a' as u] + apply ih d u.val (by omega) u.isLt.le (by simpa only [List.length_cons] using Nat.le_of_succ_le_succ hlen) + a.1 a.2 haT htail + · simp only [hu,↓reduceIte,le_refl] + _ = _ := by + rw [Finset.mul_sum] + simp only [List.length_cons,orderedWeight] + have hsum := sum_fin_filter_lt_eq_range N k hkN + (fun j => (2/(N : ℝ))*b j*orderedWeight (fun t => (2/(N : ℝ))*b t) as.length j) + rw [Finset.sum_filter] at hsum + rw [← hsum] + apply Finset.sum_congr rfl + intro u _ + by_cases hu : u.val < k <;> simp only [hu,↓reduceIte] <;> ring + +omit [Fintype ι] in + +theorem pathVisitProbability_factorial (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (path : List (ι × τ)) (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) + (hlen : path.length ≤ d) (e : ι) (T : τ) (he : e ∈ H T) + (hpath : LegalQueryPath H ((H T).erase e) (some T) path) : + pathVisitProbability H N d k ((H T).erase e) (some T) path ≤ + prefixWeight (fun t => (2/(N : ℝ))*b t) k ^ path.length / + (path.length.factorial : ℝ) := + (pathVisitProbability_ordered H N b hb hq path d k hkd hkN hlen e T he hpath).trans + (orderedWeight_le (fun t => mul_nonneg (by positivity) (hb t)) _ _) + +end PathVisitation +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequiredBaseAppend.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequiredBaseAppend.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b4a7b4af0a05edebc3063e55865392aa9e8536d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequiredBaseAppend.lean @@ -0,0 +1,117 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PathRequiredBaseChild +import OAI.Combinatorics.TriangleRemoval.Process.PairRequired + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma pathRequired_base_append {A : Type*} [DecidableEq A] + (base path ex : List A) : + pathRequired (base.reverse ++ path) (ex ++ base) = pathRequired path ex := by + simp [pathRequired,List.reverse_append,List.prefix_append_right_inj] + +lemma pairRequired_base_child {A : Type*} [DecidableEq A] + (base : List A) (a b p : A) (as bs : List A) : + pairRequired (base.reverse ++ a :: as) (base.reverse ++ b :: bs) (p :: base) = + decide (p = a ∨ p = b) := by + simp only [pairRequired,pathRequired_base_child] + by_cases ha : p = a <;> by_cases hb : p = b <;> simp [ha,hb] + +section JointPairHelpers +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem jointMarkedQuery_congr_required (H : τ → Finset ι) (N d k : ℕ) + (c : QueryCall ι τ) (r s : List (ι × τ) → Bool) + (hrs : ∀ ex : List (ι × τ), ex ≠ [] → r (ex ++ c.address) = s (ex ++ c.address)) : + jointMarkedQuery H N r d k c = jointMarkedQuery H N s d k c := by + induction d generalizing k c with + | zero => rfl + | succ d ih => + simp only [jointMarkedQuery] + congr 1 + funext values + congr 2 + apply List.map_congr_left + intro p _ + have he := hrs [p.1] (by simp) + simp only [List.singleton_append] at he + rw [he] + congr 1 + split + · apply ih + intro ex hex + simpa only [List.append_assoc,List.singleton_append] using + hrs (ex ++ [p.1]) (by simp) + · rfl + +theorem jointMarkedQuery_pair_nil (H : τ → Finset ι) (N d k : ℕ) + (c : QueryCall ι τ) (path : List (ι × τ)) : + jointMarkedQuery H N (pairRequired c.address.reverse (c.address.reverse ++ path)) d k c = + jointMarkedQuery H N (pathRequired (c.address.reverse ++ path)) d k c := by + apply jointMarkedQuery_congr_required + intro ex hex + have hh : pathRequired c.address.reverse (ex ++ c.address) = false := by + have he := pathRequired_base_append c.address [] ex + simp only [List.append_nil] at he + rw [he] + simp [pathRequired,hex] + simp only [pairRequired,hh,Bool.false_or] + +theorem jointMarkedQuery_pair_child (H : τ → Finset ι) (N d k : ℕ) + (base : List (ι × τ)) (a b : ι × τ) (as bs : List (ι × τ)) (hab : a ≠ b) + (focus : Finset ι) (parent : Option τ) : + jointMarkedQuery H N + (pairRequired (base.reverse ++ a :: as) (base.reverse ++ b :: bs)) + d k ⟨a :: base,focus,parent⟩ = + jointMarkedQuery H N (pathRequired ((a :: base).reverse ++ as)) + d k ⟨a :: base,focus,parent⟩ := by + apply jointMarkedQuery_congr_required + intro ex _ + simp [pairRequired,pathRequired,List.reverse_append,List.reverse_cons, + List.append_assoc,List.prefix_append_right_inj,List.cons_prefix_cons,hab] + +theorem jointMarkedQuery_hit_head (H : τ → Finset ι) (N d k : ℕ) + (r : List (ι × τ) → Bool) (ν : τ → PMF (Fin N)) + (base : List (ι × τ)) (p a : ι × τ) (as : List (ι × τ)) + (focus : Finset ι) (parent : Option τ) + {z : Bool × Bool × List (QueryCall ι τ)} + (hz : z ∈ (ExposureTree.fresh ν + (jointMarkedQuery H N r d k ⟨p :: base,focus,parent⟩)).support) + (hh : ∃ q ∈ z.2.2, q.address = (a :: as).reverse ++ base) : p = a := by + obtain ⟨q,hq,he⟩ := hh + have had := jointMarkedQuery_address H N r d k ⟨p :: base,focus,parent⟩ ν hz q hq + rw [he] at had + have haa : a :: base <:+ (a :: as).reverse ++ base := by + simp only [List.reverse_cons,List.append_assoc,List.singleton_append] + exact List.suffix_append _ _ + exact (List.cons.inj + ((List.suffix_of_suffix_length_le had haa (by simp)).eq_of_length (by simp))).1 + +omit [Fintype τ] in +lemma query_trace_cons_hit_tail (c : QueryCall ι τ) (l : List (QueryCall ι τ)) + (a : ι × τ) (as : List (ι × τ)) + (h : ∃ q ∈ c :: l, q.address = (a :: as).reverse ++ c.address) : + ∃ q ∈ l, q.address = (a :: as).reverse ++ c.address := by + obtain ⟨q,hq,he⟩ := h + rcases List.mem_cons.mp hq with rfl | hq + · have hl := congrArg List.length he + simp only [List.length_append,List.length_reverse,List.length_cons] at hl + omega + · exact ⟨q,hq,he⟩ + +end JointPairHelpers +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequiredBaseChild.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequiredBaseChild.lean new file mode 100644 index 0000000000000000000000000000000000000000..644e8cab1b4e3a25aeba883d3b73b4f57ac927e4 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathRequiredBaseChild.lean @@ -0,0 +1,116 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PathRequired +import OAI.Combinatorics.TriangleRemoval.Queries.JointMarkedQuery + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma pathRequired_base_child {A : Type*} [DecidableEq A] + (base : List A) (a p : A) (as : List A) : + pathRequired (base.reverse ++ a :: as) (p :: base) = decide (p = a) := by + simp [pathRequired,List.reverse_cons,List.prefix_append_right_inj] + +lemma pathRequired_base_nil {A : Type*} [DecidableEq A] + (base : List A) (p : A) : pathRequired base.reverse (p :: base) = false := by + simp only [pathRequired,decide_eq_false_iff_not] + intro h + have hl := h.length_le + simp only [List.length_reverse,List.length_cons] at hl + omega + +section MarkedTraceHit +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem jointMarkedQuery_hit (H : τ → Finset ι) (N d k : ℕ) + (c : QueryCall ι τ) (path : List (ι × τ)) (ν : τ → PMF (Fin N)) + {z : Bool × Bool × List (QueryCall ι τ)} + (hz : z ∈ (ExposureTree.fresh ν + (jointMarkedQuery H N (pathRequired (c.address.reverse ++ path)) d k c)).support) + (hhit : ∃ a ∈ z.2.2, a.address = path.reverse ++ c.address) : z.2.1 = true := by + induction d generalizing k c path z with + | zero => + rw [jointMarkedQuery,ExposureTree.fresh_bind] at hz + obtain ⟨_,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + have he : z = (true,true,[c]) := by + simpa only [ExposureTree.fresh,PMF.mem_support_pure_iff] using hz + rw [he] + | succ d ih => + rw [jointMarkedQuery,ExposureTree.fresh_bind] at hz + obtain ⟨values,hvalues,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + rw [ExposureTree.fresh_mapOutput] at hz + obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + cases path with + | nil => + apply ExposureTree.checkMarkedTrace_no_demands ν _ _ hw + apply List.any_eq_false.mpr + intro x hx + obtain ⟨p,_,rfl⟩ := List.mem_map.mp hx + simp only [List.append_nil,pathRequired_base_nil,Bool.false_eq_true,not_false_eq_true] + | cons a as => + have hhit' : ∃ q ∈ w.2.2, q.address = (a :: as).reverse ++ c.address := by + obtain ⟨q,hq,he⟩ := hhit + rcases List.mem_cons.mp hq with rfl | hq + · have hl := congrArg List.length he + simp only [List.length_append,List.length_reverse,List.length_cons] at hl + omega + · exact ⟨q,hq,he⟩ + have hvals : (values.map Prod.fst).Nodup := by + rw [← ExposureTree.freshLog_outcome] at hvalues + obtain ⟨x,hx,hxe⟩ := (PMF.mem_support_map_iff _ _ _).mp hvalues + have he := (ExposureTree.freshLog_exposeLabeled_support ν Prod.snd _ hx).1 + rw [hxe] at he + rw [he] + exact Finset.nodup_toList _ + have hsorted := ((List.mergeSort_perm values + (fun a b => a.2.val ≤ b.2.val)).map Prod.fst).nodup_iff.mpr hvals + have hpair : (values.mergeSort (fun a b => a.2.val ≤ b.2.val)).Pairwise + (fun p q => p.1 ≠ q.1) := by + simpa only [List.Nodup,List.pairwise_map] using hsorted + apply (ExposureTree.checkMarkedTrace_one_hit ν + (fun q : QueryCall ι τ => q.address = (a :: as).reverse ++ c.address) _ _ _ hw hhit').2 + · apply List.pairwise_map.mpr + apply hpair.imp + intro p q hpq hp + simp only [pathRequired_base_child,decide_eq_true_eq] at hp + simp only [pathRequired_base_child,decide_eq_false_iff_not] + exact fun hq => hpq (hp.trans hq.symm) + · intro child hchild y hy hhit + obtain ⟨p,_,rfl⟩ := List.mem_map.mp hchild + split_ifs at hy with hp + · obtain ⟨q,hq,he⟩ := hhit + have had := jointMarkedQuery_address H N _ d p.2.val + ⟨p.1 :: c.address,(H p.1.2).erase p.1.1,some p.1.2⟩ ν hy q hq + rw [he] at had + have haa : a :: c.address <:+ (a :: as).reverse ++ c.address := by + simp only [List.reverse_cons,List.append_assoc,List.singleton_append] + exact List.suffix_append _ _ + have hpa : p.1 = a := List.cons.inj + ((List.suffix_of_suffix_length_le had haa (by simp)).eq_of_length (by simp)) |>.1 + refine ⟨?_,?_⟩ + · simp only [pathRequired_base_child,hpa,decide_true] + · have hi := ih p.2.val + ⟨p.1 :: c.address,(H p.1.2).erase p.1.1,some p.1.2⟩ as + (by simpa only [List.reverse_cons,List.append_assoc,List.singleton_append,hpa] using hy) + (by simpa only [List.reverse_cons,List.append_assoc,List.singleton_append,hpa] using + (show ∃ q ∈ y.2.2, q.address = (a :: as).reverse ++ c.address from ⟨q,hq,he⟩)) + exact hi + · have he : y = (false,false,[]) := by + simpa only [ExposureTree.fresh,PMF.mem_support_pure_iff] using hy + simp only [he,List.not_mem_nil,false_and,exists_false] at hhit + +end MarkedTraceHit +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PathSuffix.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathSuffix.lean new file mode 100644 index 0000000000000000000000000000000000000000..8688677b1c8b86609501b224fd02c412c53af0a9 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PathSuffix.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.Parent +import OAI.Combinatorics.TriangleRemoval.Process.Within +import OAI.Combinatorics.TriangleRemoval.Tracking.RootedExposedCollisionWitness + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.TriangleGrowth +variable {V : Type*} [DecidableEq V] {G : SimpleGraph V} {N R : ℕ} +variable (A : TriangleGrowth G N R) + +lemma pathUnion_ancestor_closed {a b x y : Fin N} (hxy : A.Ancestor x y) + (hy : y ∈ A.pathUnion a b) : x ∈ A.pathUnion a b := by + apply (A.mem_pathUnion a b x).mpr + rcases (A.mem_pathUnion a b y).mp hy with hroot | ha | hb + · exact Or.inl (lt_of_le_of_lt (A.ancestor_le hxy) hroot) + · exact Or.inr (Or.inl (hxy.trans ha)) + · exact Or.inr (Or.inr (hxy.trans hb)) + +noncomputable def pathSuffix (a b : Fin N) (cut : ℕ) : Finset (Fin N) := + (A.pathUnion a b).filter (fun x => cut ≤ x.val) + +@[simp] lemma mem_pathSuffix (a b x : Fin N) (cut : ℕ) : + x ∈ A.pathSuffix a b cut ↔ x ∈ A.pathUnion a b ∧ cut ≤ x.val := by + simp only [pathSuffix,Finset.mem_filter] + +lemma within_pathSuffix {a b x y : Fin N} {cut : ℕ} (hxy : A.Ancestor x y) + (hy : y ∈ A.pathUnion a b) (hx : cut ≤ x.val) : + A.birthGraph.Within (A.pathSuffix a b cut) x y := by + induction hxy using Relation.ReflTransGen.head_induction_on with + | refl => exact Relation.ReflTransGen.refl + | @head x c hxc hcy ih => + have hc : cut ≤ c.val := hx.trans (A.parent_le hxc) + have hxP : x ∈ A.pathUnion a b := A.pathUnion_ancestor_closed + (Relation.ReflTransGen.head hxc hcy) hy + have hcP : c ∈ A.pathUnion a b := A.pathUnion_ancestor_closed hcy hy + exact Relation.ReflTransGen.head + ⟨(A.mem_pathSuffix a b x cut).mpr ⟨hxP,hx⟩, + (A.mem_pathSuffix a b c cut).mpr ⟨hcP,hc⟩,A.parent_older hxc⟩ (ih hc) + +theorem pathSuffix_covered (a b : Fin N) (cut : ℕ) (hcut : R ≤ cut) : + A.birthGraph.Covered (A.pathSuffix a b cut) a b := by + intro x hx + obtain ⟨hxP,hxc⟩ := (A.mem_pathSuffix a b x cut).mp hx + rcases (A.mem_pathUnion a b x).mp hxP with hroot | ha | hb + · exact False.elim ((Nat.not_le_of_gt hroot) (hcut.trans hxc)) + · refine Or.inl ⟨?_,A.within_pathSuffix ha (A.left_mem_pathUnion a b) hxc⟩ + exact (A.mem_pathSuffix a b a cut).mpr + ⟨A.left_mem_pathUnion a b,hxc.trans (A.ancestor_le ha)⟩ + · refine Or.inr ⟨?_,A.within_pathSuffix hb (A.right_mem_pathUnion a b) hxc⟩ + exact (A.mem_pathSuffix a b b cut).mpr + ⟨A.right_mem_pathUnion a b,hxc.trans (A.ancestor_le hb)⟩ + +lemma pathSuffix_mark {a b : Fin N} {cut : ℕ} (hcut : R ≤ cut) + (hne : (A.pathSuffix a b cut).Nonempty) : + a ∈ A.pathSuffix a b cut ∨ b ∈ A.pathSuffix a b cut := by + obtain ⟨x,hx⟩ := hne + exact (A.pathSuffix_covered a b cut hcut x hx).imp And.left And.left + +theorem pathSuffix_sparse {a b : Fin N} {cut : ℕ} (hcut : R ≤ cut) + {I U : Finset (Fin N)} (hI : Disjoint I (A.pathSuffix a b cut)) + (hU : U ⊆ A.pathSuffix a b cut) (hproper : U ≠ A.pathSuffix a b cut) : + ((insert ({a,b} : Finset (Fin N)) (A.birthGraph.backEdges (A.pathSuffix a b cut))).filter + (fun e => e ⊆ I ∪ U)).card ≤ 2 * U.card := by + apply A.birthGraph.proper_suffix_sparse hI hU hproper + · intro v hv + exact ((A.older_invariants v).2 (hcut.trans ((A.mem_pathSuffix a b v cut).mp hv).2)).1 + · exact A.pathSuffix_covered a b cut hcut + +theorem injective_path_collision {v w : Fin N} (hne : v ≠ w) {T : Finset V} + (hv : A.birthGraph.ExposedAt G A.label v T) + (hw : A.birthGraph.ExposedAt G A.label w T) : + ∃ a b : Fin N, A.birthGraph.ExtraEdge G A.label a b ∧ + Set.InjOn A.label (A.pathUnion a b) := by + obtain ⟨S,hS,hi,hroots,a,ha,b,hb,he⟩ := + A.birthGraph.rooted_exposed_collision_witness G A.label A.spawnRules R A.roots_injective + (fun z hz => ((A.older_invariants z).2 hz).1) hne hv hw + exact ⟨a,b,he,hi.mono (A.pathUnion_subset_lower hS hroots ha hb)⟩ + +end SharpTerminalLeave.TriangleGrowth + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PerturbationPolynomialBound.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PerturbationPolynomialBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..b5f35688cec75503f0bbdd5d7c9356b548259e2d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PerturbationPolynomialBound.lean @@ -0,0 +1,78 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +open Filter +open scoped BigOperators + +lemma perturbation_polynomial_bound (T : ℝ) (hT : 0 ≤ T) (K : ℕ) : + (∑ j ∈ Finset.range K, ((1+2*T)*6*T)^j*(1+2*T)) ≤ + (2*(K : ℝ)*12^K)*(1+T)^(2*K+1) := by + have hH : 1 ≤ 1+T := by linarith + have hb : (1+2*T)*6*T ≤ 12*(1+T)^2 := by nlinarith + have hb1 : 1 ≤ (12 : ℝ)*(1+T)^2 := by nlinarith [sq_nonneg T] + have hsum := Finset.sum_le_card_nsmul (Finset.range K) + (fun j => ((1+2*T)*6*T)^j*(1+2*T)) ((12*(1+T)^2)^K*(2*(1+T))) (by + intro j hj + have hjK : j ≤ K := (Finset.mem_range.mp hj).le + have hp := (pow_le_pow_left₀ (by positivity) hb j).trans (pow_le_pow_right₀ hb1 hjK) + exact mul_le_mul hp (by linarith) (by positivity) (by positivity)) + simp only [Finset.card_range,nsmul_eq_mul] at hsum + refine hsum.trans_eq ?_ + rw [mul_pow,← pow_mul,pow_add,pow_one] + ring + +lemma spectral_remainder_eventual {γ : ℝ} (hγ : 0 < γ) (K : ℕ) + (hK : 4/γ ≤ (K : ℝ)) : + ∀ᶠ n : ℕ in atTop, ∀ ε : ℝ, 0 ≤ ε → ε ≤ (n : ℝ)^(-γ) → + (n : ℝ)*((ε*Real.log n)^K * Real.exp (Real.log n*ε)) ≤ 1 := by + have hγ2 : 0 < γ/2 := by positivity + have hlog := ((isLittleO_log_rpow_atTop hγ2).comp_tendsto + (tendsto_natCast_atTop_atTop (R := ℝ))).bound zero_lt_one + have hnexp : ∀ᶠ n : ℕ in atTop, Real.exp 1 ≤ (n : ℝ) := + (tendsto_natCast_atTop_atTop (R := ℝ)).eventually_ge_atTop _ + filter_upwards [hlog,hnexp,eventually_ge_atTop (1 : ℕ)] with n hl hnE hn ε hε hεn + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn + have hn0 : (0 : ℝ) < n := by linarith + have hlog0 : 0 ≤ Real.log n := Real.log_nonneg hn1 + have hl' : Real.log n ≤ (n : ℝ)^(γ/2) := by + simpa only [Function.comp_apply,one_mul,Real.norm_eq_abs,abs_of_nonneg hlog0, + abs_of_nonneg (Real.rpow_nonneg hn0.le _)] using hl + have hεlog : ε*Real.log n ≤ (n : ℝ)^(-(γ/2)) := by + calc + _ ≤ (n : ℝ)^(-γ)*(n : ℝ)^(γ/2) := + mul_le_mul hεn hl' hlog0 (by positivity) + _ = _ := by rw [← Real.rpow_add hn0]; congr 1; ring + have hεlog1 : Real.log n*ε ≤ 1 := by + rw [mul_comm] + exact hεlog.trans (Real.rpow_le_one_of_one_le_of_nonpos hn1 (by linarith)) + have hpower : (ε*Real.log n)^K ≤ (n : ℝ)^(-(2 : ℝ)) := by + have hKg : 4 ≤ (K : ℝ)*γ := (div_le_iff₀ hγ).mp hK + calc + _ ≤ ((n : ℝ)^(-(γ/2)))^K := pow_le_pow_left₀ (by positivity) hεlog _ + _ = (n : ℝ)^(-(γ/2)*(K : ℝ)) := by rw [Real.rpow_mul hn0.le,Real.rpow_natCast] + _ ≤ _ := Real.rpow_le_rpow_of_exponent_le hn1 (by nlinarith) + calc + _ ≤ (n : ℝ)*((n : ℝ)^(-(2 : ℝ))*Real.exp 1) := by + gcongr + _ = (n : ℝ)⁻¹*Real.exp 1 := by + have hh : (n : ℝ)*(n : ℝ)^(-(2 : ℝ)) = (n : ℝ)⁻¹ := by + conv_lhs => lhs; rw [← Real.rpow_one (n : ℝ)] + rw [← Real.rpow_add hn0] + norm_num [Real.rpow_neg_one] + rw [← mul_assoc,hh] + _ ≤ (n : ℝ)⁻¹*(n : ℝ) := mul_le_mul_of_nonneg_left hnE (by positivity) + _ = 1 := inv_mul_cancel₀ hn0.ne' + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PlusEdgesSimple.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PlusEdgesSimple.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d468a050a608bca85f164dc9c909d83186ae973 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PlusEdgesSimple.lean @@ -0,0 +1,66 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Embeddings.EmptyRootInjection +import OAI.Combinatorics.TriangleRemoval.Process.BornEdges + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N : ℕ} (B : BirthGraph N) + +lemma plusEdges_simple {a b : Fin N} (hab : a ≠ b) : + ∀ e ∈ insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ), e.card = 2 := by + intro e he + rcases Finset.mem_insert.mp he with rfl | he + · exact Finset.card_pair hab + · obtain ⟨v,_,u,hu,rfl⟩ := B.backEdges_mem_pair he + exact Finset.card_pair (ne_of_lt (B.older_lt v u hu)) + +lemma extra_not_mem_backEdges {a b : Fin N} (hne : ¬ B.graph.Adj a b) : + ({a,b} : Finset (Fin N)) ∉ B.backEdges Finset.univ := by + intro he + obtain ⟨v,_,u,hu,he⟩ := B.backEdges_mem_pair he + have ha : a = u ∨ a = v := by + have hm : a ∈ ({u,v} : Finset (Fin N)) := he ▸ (by simp) + simpa only [Finset.mem_insert,Finset.mem_singleton] using hm + have hb : b = u ∨ b = v := by + have hm : b ∈ ({u,v} : Finset (Fin N)) := he ▸ (by simp) + simpa only [Finset.mem_insert,Finset.mem_singleton] using hm + have hc := congrArg Finset.card he + have hab : a ≠ b := by + intro hh + rw [hh,Finset.pair_eq_singleton,Finset.card_singleton, + Finset.card_pair (ne_of_lt (B.older_lt v u hu))] at hc + omega + rcases ha with rfl | rfl <;> rcases hb with rfl | rfl + · exact hab rfl + · exact hne (Or.inl hu) + · exact hne (Or.inr hu) + · exact hab rfl + +theorem short_witness_count {n : ℕ} {G : Graph n} {c C : ℝ} + (hGood : GoodPrefixGraph n c C G) {a b : Fin N} (hab : a ≠ b) + (hne : ¬ B.graph.Adj a b) (hcap : N ≤ prefixTemplateCap) + (hp : 0 ≤ prefixDensity n) (hp1 : prefixDensity n ≤ 1) (hD : 1 ≤ prefixD n) : + ((graphEmbeddingSet (insert ({a,b} : Finset (Fin N)) (B.backEdges Finset.univ)) G).card : ℝ) ≤ + prefixTemplateFactor n C * ((n : ℝ)^N * + prefixDensity n ^ ((B.backEdges Finset.univ).card + 1)) := by + have h := graphEmbeddingSet_large_count hGood _ (B.plusEdges_simple hab) hcap + (fun U => B.induced_plus_one_sparse U a b) hp hp1 hD + rw [Finset.card_insert_of_notMem (B.extra_not_mem_backEdges hne)] at h + exact h + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PowerEulerError.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PowerEulerError.lean new file mode 100644 index 0000000000000000000000000000000000000000..536d83706fee1779053f779046310608c7ea51f9 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PowerEulerError.lean @@ -0,0 +1,283 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.CodegreeVertexCount +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEdgeRadius + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +lemma power_euler_error (b : ℕ) {r : ℝ} (hr : 0 ≤ r) (hr1 : r ≤ 1) : + |(1-r)^b-1+(b : ℝ)*r| ≤ (b : ℝ)^2*r^2 := by + have hber : ∀ b : ℕ, 0 ≤ (1-r)^b-1+(b : ℝ)*r := by + intro b + have hh := one_add_mul_le_pow (show -2 ≤ -r by linarith) b + simp only [← sub_eq_add_neg,mul_neg] at hh + linarith only [hh] + have hupper : ∀ b : ℕ, (1-r)^b-1+(b : ℝ)*r ≤ (b : ℝ)^2*r^2 := by + intro b + induction b with + | zero => simp + | succ b ih => + have hm := mul_le_mul_of_nonneg_left ih (show 0 ≤ 1-r by linarith) + have hn : 0 ≤ (b : ℝ) := Nat.cast_nonneg _ + have hcube : 0 ≤ (b : ℝ)^2*r^3 := by positivity + rw [pow_succ,Nat.cast_add,Nat.cast_one] + nlinarith only [hm,hcube,mul_nonneg hn (sq_nonneg r),sq_nonneg r] + rw [abs_of_nonneg (hber b)] + exact hupper b + +lemma densityEdgeSafe_rate_error {n : ℕ} {p η : ℝ} {G : Graph n} + (hn : 0 < n) (hp : 0 < p) (hη : 0 ≤ η) (hη1 : η ≤ 1/2) + (h : densityEdgeSafe n p η G) : + |(n : ℝ)*p^2/(triangles G).card-6/(n : ℝ)^2/p| ≤ + 2*η*(6/(n : ℝ)^2/p) ∧ + 1/(triangles G).card ≤ 2*(6/(n : ℝ)^2/p)/((n : ℝ)*p^2) := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hQ := densityEdgeSafe_triangle_positive hn hp hη1 h + have hq : (0 : ℝ) < (triangles G).card := by exact_mod_cast hQ.card_pos + let Q₀ : ℝ := (n : ℝ)^3*p^3/6 + let lam : ℝ := 6/(n : ℝ)^2/p + have hQ₀ : 0 < Q₀ := by dsimp [Q₀]; positivity + have hlam : 0 < lam := by dsimp [lam]; positivity + have hD : 0 < (n : ℝ)*p^2 := by positivity + have hid : lam*Q₀ = (n : ℝ)*p^2 := by dsimp [lam,Q₀]; field_simp + obtain ⟨hlo,hhi⟩ := densityEdgeSafe_triangle_bounds h + change Q₀*(1-η) ≤ _ at hlo + change _ ≤ Q₀*(1+η) at hhi + have hhalf : Q₀/2 ≤ (triangles G).card := by nlinarith [mul_le_mul_of_nonneg_left hη1 hQ₀.le] + have habs : |Q₀-(triangles G).card| ≤ η*Q₀ := by apply abs_le.mpr; constructor <;> nlinarith only [hlo,hhi] + constructor + · have he : (n : ℝ)*p^2/(triangles G).card-lam = lam*(Q₀-(triangles G).card)/(triangles G).card := by rw [← hid]; field_simp + change |(n : ℝ)*p^2/(triangles G).card-lam| ≤ 2*η*lam + rw [he,abs_div,abs_mul,abs_of_pos hlam,abs_of_pos hq] + apply (div_le_iff₀ hq).mpr + have hm := mul_le_mul_of_nonneg_left habs hlam.le + have hh := mul_le_mul_of_nonneg_left hhalf (show 0 ≤ 2*η*lam by positivity) + nlinarith only [hm,hh] + · apply (div_le_div_iff₀ hq hD).mpr + have hh := mul_le_mul_of_nonneg_left hhalf (show 0 ≤ 2*lam by positivity) + dsimp only [lam] at hid hh + nlinarith only [hid,hh] + +theorem densityEdgeSafe_copy_euler_error {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (b : ℕ) (hsize : ∀ a, (required a).card = b) + {p η : ℝ} {G : Graph n} (hn : 0 < n) (hp : 0 < p) + (hη : 0 ≤ η) (hη1 : η ≤ 1/2) (h : densityEdgeSafe n p η G) : + |pmfMean (step G) (copyCount required)-copyCount required G+ + (b : ℝ)*(6/(n : ℝ)^2/p)*copyCount required G| ≤ + (4*(b : ℝ)*η*(6/(n : ℝ)^2/p)+ + 2*(b : ℝ)^2*(6/(n : ℝ)^2/p)/((n : ℝ)*p^2))*copyCount required G := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hQ := densityEdgeSafe_triangle_positive hn hp hη1 h + have hq : (0 : ℝ) < (triangles G).card := by exact_mod_cast hQ.card_pos + have hX := copyCount_nonneg required G + have hD : 0 < (n : ℝ)*p^2 := by positivity + have hr := densityEdgeSafe_rate_error hn hp hη hη1 h + have hd := copyCount_drift_error required G b (n*p^2) (η*(n*p^2)) hsize h.2.2 hQ + let lam := 6/(n : ℝ)^2/p + have hlam : 0 ≤ lam := by dsimp [lam]; positivity + have hrate : (n : ℝ)*p^2/(triangles G).card ≤ 2*lam := by + have hh := mul_le_mul_of_nonneg_left hr.2 hD.le + have he : ((n : ℝ)*p^2)*(1/(triangles G).card) = (n : ℝ)*p^2/(triangles G).card := by ring + rw [he,mul_div_cancel₀ _ hD.ne'] at hh + exact hh + have hcoef : ((b : ℝ)*(η*(n*p^2))+(b : ℝ)^2)/(triangles G).card ≤ + 2*(b : ℝ)*η*lam+2*(b : ℝ)^2*lam/((n : ℝ)*p^2) := by + have h₁ := mul_le_mul_of_nonneg_left hrate (show 0 ≤ (b : ℝ)*η by positivity) + have h₂ := mul_le_mul_of_nonneg_left hr.2 (sq_nonneg (b : ℝ)) + dsimp only [lam] at h₁ ⊢ + simp only [div_eq_mul_inv] at h₁ h₂ ⊢ + nlinarith only [h₁,h₂] + calc + _ ≤ |pmfMean (step G) (copyCount required)-copyCount required G+ + ((b : ℝ)*(n*p^2)/(triangles G).card)*copyCount required G|+ + |((b : ℝ)*(lam-(n*p^2)/(triangles G).card))*copyCount required G| := by + convert abs_add_le (pmfMean (step G) (copyCount required)-copyCount required G+ + ((b : ℝ)*(n*p^2)/(triangles G).card)*copyCount required G) + (((b : ℝ)*(lam-(n*p^2)/(triangles G).card))*copyCount required G) using 1 + congr 1 + dsimp only [lam] + ring + _ ≤ (2*(b : ℝ)*η*lam+2*(b : ℝ)^2*lam/((n : ℝ)*p^2))*copyCount required G+ + (b : ℝ)*(2*η*lam)*copyCount required G := by + apply add_le_add (hd.trans (mul_le_mul_of_nonneg_right hcoef hX)) + rw [abs_mul,abs_mul,abs_of_nonneg (Nat.cast_nonneg b),abs_sub_comm, + abs_of_nonneg hX] + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hr.1 (Nat.cast_nonneg b)) hX + _ = _ := by dsimp [lam]; ring + +lemma relative_power_drift_bound {X Y s t r a B : ℝ} {b : ℕ} + (hX : 0 ≤ X) (hs : 0 < s) (ht : 0 < t) (hr : 0 ≤ r) (hr1 : r ≤ 1) + (hscale : t = s*(1-r)^b) (hratio : s ≤ 2*t) (hcap : X ≤ B*s) + (ha : 0 ≤ a) (h : |Y-X+(b : ℝ)*r*X| ≤ a*X) : + |Y/t-X/s| ≤ 2*B*(a+(b : ℝ)^2*r^2) := by + have hpow := power_euler_error b hr hr1 + have he : Y/t-X/s = ((Y-X+(b : ℝ)*r*X)-X*((1-r)^b-1+(b : ℝ)*r))/t := by + apply (eq_div_iff ht.ne').mpr + field_simp [hs.ne'] + rw [hscale] + ring + have hnum : |(Y-X+(b : ℝ)*r*X)-X*((1-r)^b-1+(b : ℝ)*r)| ≤ + (a+(b : ℝ)^2*r^2)*X := by + calc + _ ≤ |Y-X+(b : ℝ)*r*X|+|X*((1-r)^b-1+(b : ℝ)*r)| := abs_sub _ _ + _ ≤ a*X+X*((b : ℝ)^2*r^2) := by + apply add_le_add h + rw [abs_mul,abs_of_nonneg hX] + exact mul_le_mul_of_nonneg_left hpow hX + _ = _ := by ring + have hB : 0 ≤ B := (mul_nonneg_iff_of_pos_right hs).mp (hX.trans hcap) + have hX' : X ≤ 2*B*t := hcap.trans (by nlinarith only [mul_le_mul_of_nonneg_left hratio hB]) + rw [he,abs_div,abs_of_pos ht] + apply (div_le_iff₀ ht).mpr + exact hnum.trans (by nlinarith only [mul_le_mul_of_nonneg_left hX' (show 0 ≤ a+(b : ℝ)^2*r^2 by positivity)]) + +lemma history_relative_drift_sum {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : α → ℝ) (s : ℕ → ℝ) + (T j : ℕ) (hj : j ≤ T) (ω : History α T) : + f (ω (historyIndex T j))/s j-f (ω (historyIndex T 0))/s 0- + historyNoise K (fun k a => f a/s k) T j ω = + ∑ k ∈ Finset.range j, + (pmfMean (K k (ω (historyIndex T k))) f/s (k+1)-f (ω (historyIndex T k))/s k) := by + unfold historyNoise historyIncrement + simp only [Nat.min_eq_left hj,div_eq_mul_inv,pmfMean_mul_const] + have he := Finset.sum_range_sub' (fun k => f (ω (historyIndex T k))*(s k)⁻¹) j + have hh : (∑ k ∈ Finset.range j, + (f (ω (historyIndex T k))*(s k)⁻¹-f (ω (historyIndex T (k+1)))*(s (k+1))⁻¹))+ + (∑ k ∈ Finset.range j, + (f (ω (historyIndex T (k+1)))*(s (k+1))⁻¹- + pmfMean (K k (ω (historyIndex T k))) f*(s (k+1))⁻¹)) = + -(∑ k ∈ Finset.range j, + (pmfMean (K k (ω (historyIndex T k))) f*(s (k+1))⁻¹- + f (ω (historyIndex T k))*(s k)⁻¹)) := by + rw [← Finset.sum_add_distrib,← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + rw [he] at hh + linarith only [hh] + +theorem early_relative_drift_bound {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (a b : ℕ) (hsize : ∀ x, (required x).card = b) + (η : ℝ) (hn : 0 < n) (hp : 1/(n : ℝ) ≤ prefixDensity n) + (hη : 0 ≤ η) (hη1 : η ≤ 1/2) + (hreg : ∀ i < prefixTime n, earlyTemplateScale a b n i ≤ 2*earlyTemplateScale a b n (i+1)) + (j : ℕ) (hj : j ≤ prefixTime n) (ω : History (Graph n) (prefixTime n)) + (hsafe : ∀ i < j, densityEdgeSafe n (earlyDensity n i) η (ω (historyIndex (prefixTime n) i))) + (hcap : ∀ i < j, copyCount required (ω (historyIndex (prefixTime n) i)) ≤ + 2*earlyTemplateScale a b n i) : + |copyCount required (ω (historyIndex (prefixTime n) j))/earlyTemplateScale a b n j- + copyCount required (ω (historyIndex (prefixTime n) 0))/earlyTemplateScale a b n 0- + historyNoise (fun _ => step) (fun i G => copyCount required G/earlyTemplateScale a b n i) + (prefixTime n) j ω| ≤ + 16*(b : ℝ)*η*Real.log n+4*(b : ℝ)^2/prefixD n+ + 24*(b : ℝ)^2*Real.log n/(n : ℝ) := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + let p := earlyDensity n + let h : ℝ := 6/(n : ℝ)^2 + let lam : ℕ → ℝ := fun i => h/p i + have hpos : ∀ i ≤ prefixTime n, 0 < p i := fun i hi => early_density_positive hn hp hi + have hstep : ∀ i, p i = p (i+1)+h := fun i => earlyDensity_succ n i + have hspos : ∀ i ≤ prefixTime n, 0 < earlyTemplateScale a b n i := by + intro i hi + dsimp [earlyTemplateScale] + have := hpos i hi + positivity + have hsingle (i : ℕ) (hi : i < j) : + |pmfMean (step (ω (historyIndex (prefixTime n) i))) (copyCount required)/ + earlyTemplateScale a b n (i+1)- + copyCount required (ω (historyIndex (prefixTime n) i))/earlyTemplateScale a b n i| ≤ + 4*(4*(b : ℝ)*η*lam i+2*(b : ℝ)^2*lam i/((n : ℝ)*p i^2)+(b : ℝ)^2*(lam i)^2) := by + have hiT : i < prefixTime n := hi.trans_le hj + have hp0 := hpos i hiT.le + have hp1 := hpos (i+1) (by omega) + have hl : 0 ≤ lam i := by dsimp [lam,h]; positivity + have hl1 : lam i ≤ 1 := by + apply (div_le_iff₀ hp0).mpr + have hh := hstep i + linarith only [hh,hp1] + have hscale : earlyTemplateScale a b n (i+1) = earlyTemplateScale a b n i*(1-lam i)^b := by + have he : p (i+1) = p i*(1-lam i) := by dsimp [lam]; field_simp; linarith only [hstep i] + change (n : ℝ)^a*p (i+1)^b = ((n : ℝ)^a*p i^b)*(1-lam i)^b + rw [he,mul_pow]; ring + have hd := densityEdgeSafe_copy_euler_error required b hsize hn hp0 hη hη1 (hsafe i hi) + simpa only [lam,h,show (2 : ℝ)*2 = 4 by norm_num] using relative_power_drift_bound (copyCount_nonneg _ _) + (hspos i hiT.le) (hspos (i+1) (by omega)) hl hl1 hscale (hreg i hiT) (hcap i hi) + (by positivity) hd + have hlog : (∑ i ∈ Finset.range j, lam i) ≤ Real.log n := by + have hh := (density_log_sum_bounds p h j (fun i hi => hpos i (hi.trans hj)) + (fun i _ => hstep i)).1 + have hp0 := Real.log_nonpos (hpos 0 (Nat.zero_le _)).le (earlyDensity_le_one n 0) + have hln := early_density_log_bound hn hp hj + dsimp only [lam] at hh ⊢ + linarith only [hh,hp0,hln] + have hlD : (∑ i ∈ Finset.range j, lam i/((n : ℝ)*p i^2)) ≤ 1/(2*prefixD n) := by + have hh := inverse_square_grid_sum p (n : ℝ) h j hnR (by dsimp [h]; positivity) + (fun i hi => hpos i (hi.trans hj)) (fun i _ => hstep i) + have he : (∑ i ∈ Finset.range j, 2*h/((n : ℝ)*p i^3)) = + 2*(∑ i ∈ Finset.range j, lam i/((n : ℝ)*p i^2)) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + have := hpos i ((Finset.mem_range.mp hi).le.trans hj) + dsimp only [lam] + field_simp + rw [he] at hh + have hDj := earlyCodegreeScale_ge_prefixD n j hj (le_trans (by positivity) hp) + have hD : 0 < prefixD n := by unfold prefixD; have := early_density_positive hn hp (show prefixTime n ≤ prefixTime n by rfl); rw [earlyDensity_prefix] at this; positivity + have hDj' : prefixD n ≤ (n : ℝ)*p j^2 := by simpa only [earlyTemplateScale,pow_one] using hDj + have hr := one_div_le_one_div_of_le hD hDj' + have ht : 0 ≤ 1/((n : ℝ)*p 0^2) := by positivity + have he' : 1/prefixD n = 2*(1/(2*prefixD n)) := by ring + rw [he'] at hr + linarith only [hh,hr,ht] + have hsq : (∑ i ∈ Finset.range j, (lam i)^2) ≤ 6/(n : ℝ)*Real.log n := by + have hlmax (i : ℕ) (hi : i < j) : lam i ≤ 6/(n : ℝ) := by + have hp' := hp.trans (earlyDensity_antitone n (hi.le.trans hj)) + change 1/(n : ℝ) ≤ p i at hp' + apply (div_le_iff₀ (hpos i (hi.le.trans hj))).mpr + dsimp only [h] + have hm := mul_le_mul_of_nonneg_left hp' (show 0 ≤ 6/(n : ℝ) by positivity) + convert hm using 1 + field_simp + calc + _ ≤ ∑ i ∈ Finset.range j, (6/(n : ℝ))*lam i := by + apply Finset.sum_le_sum + intro i hi + have hli : 0 ≤ lam i := by dsimp [lam,h]; exact div_nonneg (by positivity) (hpos i ((Finset.mem_range.mp hi).le.trans hj)).le + nlinarith only [mul_le_mul_of_nonneg_right (hlmax i (Finset.mem_range.mp hi)) hli] + _ = 6/(n : ℝ)*(∑ i ∈ Finset.range j, lam i) := (Finset.mul_sum _ _ _).symm + _ ≤ _ := mul_le_mul_of_nonneg_left hlog (by positivity) + rw [history_relative_drift_sum _ _ _ _ _ hj] + calc + _ ≤ ∑ i ∈ Finset.range j, + |pmfMean (step (ω (historyIndex (prefixTime n) i))) (copyCount required)/earlyTemplateScale a b n (i+1)- + copyCount required (ω (historyIndex (prefixTime n) i))/earlyTemplateScale a b n i| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i ∈ Finset.range j, + 4*(4*(b : ℝ)*η*lam i+2*(b : ℝ)^2*lam i/((n : ℝ)*p i^2)+(b : ℝ)^2*(lam i)^2) := + Finset.sum_le_sum (fun i hi => hsingle i (Finset.mem_range.mp hi)) + _ = 16*(b : ℝ)*η*(∑ i ∈ Finset.range j, lam i)+ + 8*(b : ℝ)^2*(∑ i ∈ Finset.range j, lam i/((n : ℝ)*p i^2))+ + 4*(b : ℝ)^2*(∑ i ∈ Finset.range j, (lam i)^2) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + _ ≤ _ := by + have h₁ := mul_le_mul_of_nonneg_left hlog (show 0 ≤ 16*(b : ℝ)*η by positivity) + have h₂ := mul_le_mul_of_nonneg_left hlD (show 0 ≤ 8*(b : ℝ)^2 by positivity) + have h₃ := mul_le_mul_of_nonneg_left hsq (show 0 ≤ 4*(b : ℝ)^2 by positivity) + simp only [div_eq_mul_inv,mul_inv_rev] at h₂ h₃ ⊢ + norm_num only [invOf_eq_inv,inv_div,inv_one] at h₂ + nlinarith only [h₁,h₂,h₃] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/PowersetCardTriple.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/PowersetCardTriple.lean new file mode 100644 index 0000000000000000000000000000000000000000..b45e4fbeb2ffdcd8be2d7d80627ae4f69e7edf97 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/PowersetCardTriple.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.CommonNeighborsMono + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma powersetCard_triple {α : Type*} [DecidableEq α] {u v w : α} + (huv : u ≠ v) (huw : u ≠ w) (hvw : v ≠ w) : + ({u,v,w} : Finset α).powersetCard 2 = {{u,v},{u,w},{v,w}} := by + have h2 : ({v,w}:Finset α).powersetCard 2 = {{v,w}} := by + rw [← Finset.card_pair hvw] + exact Finset.powersetCard_self _ + rw [Finset.powersetCard_succ_insert (by simp [huv,huw]) 1, h2] + simp only [Finset.powersetCard_one, Finset.map_insert, Finset.map_singleton, Finset.image_insert, + Finset.image_singleton, Function.Embedding.coeFn_mk] + ext s + simp only [Finset.mem_union, Finset.mem_insert, Finset.mem_singleton] + tauto + +lemma triangle_closure_iff {n : ℕ} {G : Graph n} (hG : G ⊆ completeGraph n) + {u v w : Fin n} (huv : u ≠ v) (hw : w ∈ commonNeighbors G u v) : + {u,v,w} ∈ triangles G ↔ {u,v} ∈ G := by + obtain ⟨huw,hvw⟩ := commonNeighbors_ne hG hw + obtain ⟨huwG,hvwG⟩ := (mem_commonNeighbors G u v w).mp hw + rw [mem_triangles, powersetCard_triple huv huw hvw] + simp [huv,huw,hvw,Finset.insert_subset_iff,Finset.singleton_subset_iff,huwG,hvwG] + +theorem codegree_step_range {n : ℕ} {G H : Graph n} (hG : G ⊆ completeGraph n) + (u v : Fin n) (hH : H ∈ (step G).support) : + 0 ≤ (currentCodegree G u v : ℝ) - currentCodegree H u v ∧ + (currentCodegree G u v : ℝ) - currentCodegree H u v ≤ 2 := by + by_cases h : (triangles G).Nonempty + · obtain ⟨t,ht,rfl⟩ := (step_support_active h).mp hH + exact codegree_delete_range hG u v ht + · rw [step, dite_eq_right h, PMF.mem_support_pure_iff] at hH + subst H + norm_num + +theorem codegree_step_second_moment {n : ℕ} {G : Graph n} + (hG : G ⊆ completeGraph n) (u v : Fin n) : + pmfMean (step G) (fun H => + ((currentCodegree H u v : ℝ) - currentCodegree G u v)^2) ≤ + 2 * ((currentCodegree G u v : ℝ) - + pmfMean (step G) (fun H => (currentCodegree H u v : ℝ))) := by + calc + _ ≤ pmfMean (step G) (fun H => + 2 * ((currentCodegree G u v : ℝ) - currentCodegree H u v)) := by + apply pmfMean_mono + intro H hH + obtain ⟨hlo,hhi⟩ := codegree_step_range hG u v hH + nlinarith + _ = _ := by rw [pmfMean_const_mul, pmfMean_sub, pmfMean_const] + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ProgramDemand.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ProgramDemand.lean new file mode 100644 index 0000000000000000000000000000000000000000..68143aab6813b5c3a00fd0257aee74519416a6f8 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ProgramDemand.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.MapOutput +import OAI.Combinatorics.TriangleRemoval.Queries.MarkedChild + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave +namespace ExposureTree +variable {K V O A : Type*} + +def programDemand : List (Bool × ExposureTree K V (Bool × Bool)) → Bool + | [] => false + | a :: as => a.1 || programDemand as + +def checkMarked : List (Bool × ExposureTree K V (Bool × Bool)) → + ExposureTree K V (Bool × Bool) + | [] => .done (true,true) + | a :: as => bind a.2 (fun z => + if z.1 then .done (false, ((!a.1) || z.2) && !programDemand as) + else mapOutput (fun y => (y.1, ((!a.1) || z.2) && y.2)) (checkMarked as)) + +@[simp] theorem programDemand_law (ν : K → PMF V) + (as : List (Bool × ExposureTree K V (Bool × Bool))) : + markedDemand (as.map (fun a => (⟨a.1,fresh ν a.2,0⟩ : MarkedChild))) = + programDemand as := by + induction as with + | nil => rfl + | cons a as ih => simp only [List.map_cons,markedDemand,programDemand,ih] + +theorem fresh_checkMarked (ν : K → PMF V) + (as : List (Bool × ExposureTree K V (Bool × Bool))) : + fresh ν (checkMarked as) = + markedCheck (as.map (fun a => (⟨a.1,fresh ν a.2,0⟩ : MarkedChild))) := by + induction as with + | nil => rfl + | cons a as ih => + simp only [checkMarked,fresh_bind,List.map_cons,markedCheck] + congr 1 + funext z + cases z.1 <;> simp only [Bool.false_eq_true,↓reduceIte,fresh,fresh_mapOutput, + ih,programDemand_law] + +theorem checkMarked_outcome + (as : List (Bool × ExposureTree K V (Bool × Bool))) : + mapOutput Prod.fst (checkMarked as) = + checkNone (as.map (fun a => mapOutput Prod.fst a.2)) := by + induction as with + | nil => rfl + | cons a as ih => + simp only [checkMarked,mapOutput_bind,List.map_cons,checkNone,bind_mapOutput] + congr 1 + funext z + cases z.1 <;> simp only [Bool.false_eq_true,↓reduceIte,mapOutput_done,mapOutput_comp] + exact ih + +theorem exposeLabeled_table [Fintype A] [DecidableEq A] [Fintype V] [DecidableEq V] + (ν : K → PMF V) (key : A → K) (as : List A) (ha : as.Nodup) + (ρ : A → PMF V) (hρ : ∀ a ∈ as, ρ a = ν (key a)) : + (productPMF ρ).map (fun ω => as.map (fun a => (a,ω a))) = + fresh ν (exposeLabeled key as) := by + induction as generalizing ρ with + | nil => exact PMF.map_const (productPMF ρ) [] + | cons a as ih => + obtain ⟨hna,hn⟩ := List.nodup_cons.mp ha + rw [productPMF_split ρ a,PMF.map_bind,hρ a (List.mem_cons_self)] + simp only [exposeLabeled,fresh,fresh_bind] + congr 1 + funext v + have hx : (productPMF (Function.update ρ a (PMF.pure v))).map + (fun ω => (a,ω a) :: as.map (fun b => (b,ω b))) = + (productPMF (Function.update ρ a (PMF.pure v))).map + (fun ω => (a,v) :: as.map (fun b => (b,ω b))) := by + apply pmf_bind_congr_on_support + intro ω hω + have hw := (productPMF_support _ ω).mp hω a + have hv : ω a = v := by simpa using hw + dsimp only [Function.comp_def] + rw [hv] + change (productPMF (Function.update ρ a (PMF.pure v))).map + (fun ω => (a,ω a) :: as.map (fun b => (b,ω b))) = _ + rw [hx] + have hh := ih hn (Function.update ρ a (PMF.pure v)) (by + intro b hb + have hba : b ≠ a := fun he => hna (he ▸ hb) + rw [Function.update_of_ne hba] + exact hρ b (List.mem_cons_of_mem _ hb)) + change (productPMF (Function.update ρ a (PMF.pure v))).map + ((fun xs => (a,v) :: xs) ∘ (fun ω => as.map (fun b => (b,ω b)))) = _ + rw [← PMF.map_comp,hh] + rfl + +end ExposureTree + +section MarkedGrid +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def markedGridQueryDepth (H : τ → Finset ι) (N : ℕ) + (required : List (ι × τ) → Bool) : + ℕ → ℕ → List (ι × τ) → Finset ι → Option τ → ExposureTree τ (Fin N) (Bool × Bool) + | 0, _, _, focus, parent => ExposureTree.bind + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H focus parent).toList) + (fun _ => .done (true,true)) + | d+1, k, address, focus, parent => ExposureTree.bind + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H focus parent).toList) + (fun values => ExposureTree.checkMarked + ((values.mergeSort (fun a b => a.2.val ≤ b.2.val)).map + (fun p => (required (p.1 :: address), if p.2.val < k then + markedGridQueryDepth H N required d p.2.val (p.1 :: address) + ((H p.1.2).erase p.1.1) (some p.1.2) + else .done (false,false))))) + +theorem markedGridQueryDepth_outcome (H : τ → Finset ι) (N : ℕ) + (required : List (ι × τ) → Bool) (d k : ℕ) (address : List (ι × τ)) + (focus : Finset ι) (parent : Option τ) : + ExposureTree.mapOutput Prod.fst + (markedGridQueryDepth H N required d k address focus parent) = + gridQueryDepth H N d k focus parent := by + induction d generalizing k address focus parent with + | zero => simp only [markedGridQueryDepth,gridQueryDepth,ExposureTree.mapOutput_bind, + ExposureTree.mapOutput_done] + | succ d ih => + simp only [markedGridQueryDepth,gridQueryDepth,ExposureTree.mapOutput_bind] + congr 1 + funext values + rw [ExposureTree.checkMarked_outcome,List.map_map] + congr 1 + apply List.map_congr_left + intro p _ + dsimp only [Function.comp_def] + split + · exact ih _ _ _ _ + · rfl + +end MarkedGrid +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ProspectiveFailure.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ProspectiveFailure.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ae23aae453a8955b5ad40b94c8bd229cad52007 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ProspectiveFailure.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.MarkedSuccess + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +@[simp] theorem markedGood_bind {α : Type*} [Fintype α] (π : PMF α) + (p : α → PMF (Bool × Bool)) : + markedGood (π.bind p) = pmfMean π (fun a => markedGood (p a)) := + pmfMean_bind π p _ + +noncomputable def prospectiveFailure (N : ℕ) [NeZero N] (t : ℕ) (q : Fin N → ℝ) : ℝ := + 1 - (∑ u : Fin N, if u.val < t then q u else 0) / (N : ℝ) + +theorem markedRow_cavity_bound {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (S : Finset K) (σ : K → Fin N) + (p : K → Fin N → PMF (Bool × Bool)) (q : K → Fin N → ℝ) + (deadline t : ℕ) (htd : t ≤ deadline) (hsel : ∀ k ∈ S, (σ k).val < deadline) + (ht : ∃ k ∈ S, t ≤ (σ k).val) (hS : S.card ≤ 2) + (hmarg : ∀ k ∉ S, ∀ u, markedSuccess (p k u) = q k u) + (b : ℝ) (hfactor : ∀ k, (7 / 8 : ℝ) ≤ prospectiveFailure N t (q k)) + (hfull : ∏ k, prospectiveFailure N t (q k) ≤ (9 / 8 : ℝ) * b) : + markedGood ((productPMF (selectedClockLaw N S σ)).bind + (fun ω => markedCheck (markedRow S p deadline ω))) ≤ + (∏ k ∈ S, markedGood (p k (σ k))) * (2 * b) := by + rw [markedGood_bind] + have h := markedRow_integrated N S σ p deadline t htd hsel ht + let f : K → ℝ := fun k => prospectiveFailure N t (q k) + have he : (∏ k, if k ∈ S then markedGood (p k (σ k)) else + 1 - (∑ u : Fin N, if u.val < t then markedSuccess (p k u) else 0) / (N : ℝ)) = + (∏ k ∈ S, markedGood (p k (σ k))) * (∏ k ∈ Finset.univ \ S, f k) := by + have hp : (fun k => if k ∈ S then markedGood (p k (σ k)) else + 1 - (∑ u : Fin N, if u.val < t then markedSuccess (p k u) else 0) / (N : ℝ)) = + (fun k => if k ∈ S then markedGood (p k (σ k)) else f k) := by + funext k + by_cases hk : k ∈ S + · simp only [hk,↓reduceIte] + · simp only [hk,↓reduceIte,f,prospectiveFailure,hmarg k hk] + rw [hp,Finset.prod_ite] + congr 1 + · congr 1 + ext k + simp + · congr 1 + ext k + simp + rw [he] at h + have hf := offpattern_product_bound Finset.univ S (Finset.subset_univ S) hS f b + (fun k _ => hfactor k) hfull + exact h.trans (mul_le_mul_of_nonneg_left hf (Finset.prod_nonneg + (fun k _ => markedGood_nonneg (p k (σ k))))) + +@[simp] theorem markedGood_no_marks (p : PMF Bool) : + markedGood (p.map (fun b => (b,true))) = 1 := by + rw [markedGood,pmfMean_map] + simp only [↓reduceIte,pmfMean_const] + +@[simp] theorem markedSuccess_no_marks (p : PMF Bool) : + markedSuccess (p.map (fun b => (b,true))) = (p true).toReal := by + rw [markedSuccess,pmfMean_map] + simp [pmfMean] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/RealCardFiberBound.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/RealCardFiberBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..8389a9c07806153f9405404ef27735c5cacc738d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/RealCardFiberBound.lean @@ -0,0 +1,36 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +section FiberCount +variable {α β : Type*} [DecidableEq α] [DecidableEq β] + +omit [DecidableEq α] in +lemma real_card_le_fiber_bound (s : Finset α) (t : Finset β) (f : α → β) + (hf : ∀ a ∈ s, f a ∈ t) (b : ℝ) + (hb : ∀ y ∈ t, ((s.filter (fun a => f a = y)).card : ℝ) ≤ b) : + (s.card : ℝ) ≤ b * t.card := by + have he : s.card = ∑ y ∈ t, (s.filter (fun a => f a = y)).card := + Finset.card_eq_sum_card_fiberwise hf + rw [he,Nat.cast_sum] + calc + _ ≤ ∑ _y ∈ t, b := Finset.sum_le_sum hb + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul]; ring + +end FiberCount +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexQuadratic.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexQuadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea65771e5e5957069d42046e49a17096343f9f55 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexQuadratic.lean @@ -0,0 +1,51 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.StarInclusion + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace +open scoped BigOperators NNReal +open Matrix InnerProductSpace +open scoped BigOperators +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix + +namespace SharpTerminalLeave +open scoped Matrix.Norms.L2Operator + +variable {I J : Type*} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] + +omit [DecidableEq I] [DecidableEq J] in +theorem reindex_quadratic (e : I ≃ J) (M : Matrix I I ℝ) (x : J → ℝ) : + x ⬝ᵥ (Matrix.reindex e e M *ᵥ x) = + (fun i => x (e i)) ⬝ᵥ (M *ᵥ fun i => x (e i)) := by + simp only [dotProduct,Matrix.mulVec,Matrix.reindex_apply,Matrix.submatrix_apply] + rw [← Equiv.sum_comp e] + simp only [Equiv.symm_apply_apply] + apply Finset.sum_congr rfl + intro i _ + congr 1 + rw [← Equiv.sum_comp e] + simp only [Equiv.symm_apply_apply] + +theorem hermitian_reindex_norm_le (e : I ≃ J) (M : Matrix I I ℝ) (hM : M.IsHermitian) : + ‖Matrix.reindex e e M‖ ≤ ‖M‖ := by + apply hermitian_norm_le_of_quadratic _ ((Matrix.isHermitian_reindex_iff e).mpr hM) + ‖M‖ (norm_nonneg _) + intro x + rw [reindex_quadratic] + have h := matrix_quadratic_abs M (fun i => x (e i)) + rw [show (∑ i, (x (e i))^2) = ∑ j, (x j)^2 from Equiv.sum_comp e (fun j => (x j)^2)] at h + exact h + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexSet.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..d232a93073a5babf801d841c1011464b6719c88b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexSet.lean @@ -0,0 +1,110 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.RootedTemplates + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +def reindexSet {N : ℕ} (s e : Finset (Fin N)) : Finset (Fin s.card) := + Finset.univ.filter (fun i => s.orderEmbOfFin rfl i ∈ e) + +@[simp] lemma mem_reindexSet {N : ℕ} (s e : Finset (Fin N)) (i : Fin s.card) : + i ∈ reindexSet s e ↔ s.orderEmbOfFin rfl i ∈ e := by + simp only [reindexSet,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma image_reindexSet {N : ℕ} {s e : Finset (Fin N)} (he : e ⊆ s) : + (reindexSet s e).image (s.orderEmbOfFin rfl) = e := by + ext x + constructor + · rintro h + obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp h + exact (mem_reindexSet s e i).mp hi + · intro hx + let i := (s.orderIsoOfFin rfl).symm ⟨x,he hx⟩ + have hi : s.orderEmbOfFin rfl i = x := + congrArg Subtype.val ((s.orderIsoOfFin rfl).apply_symm_apply ⟨x,he hx⟩) + exact Finset.mem_image.mpr ⟨i,(mem_reindexSet s e i).mpr (by rwa [hi]),hi⟩ + +lemma reindexSet_card {N : ℕ} {s e : Finset (Fin N)} (he : e ⊆ s) : + (reindexSet s e).card = e.card := by + have hc := Finset.card_image_of_injective (reindexSet s e) (s.orderEmbOfFin rfl).injective + rw [image_reindexSet he] at hc + exact hc.symm + +lemma reindexSet_inj {N : ℕ} {s e f : Finset (Fin N)} (he : e ⊆ s) (hf : f ⊆ s) + (h : reindexSet s e = reindexSet s f) : e = f := by + rw [← image_reindexSet he,← image_reindexSet hf,h] + +lemma reindexSet_subset_iff {N : ℕ} {s e f : Finset (Fin N)} (he : e ⊆ s) : + reindexSet s e ⊆ reindexSet s f ↔ e ⊆ f := by + constructor + · intro h x hx + rw [← image_reindexSet he] at hx + obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp hx + exact (mem_reindexSet s f i).mp (h hi) + · intro h i hi + exact (mem_reindexSet s f i).mpr (h ((mem_reindexSet s e i).mp hi)) + +lemma reindexSet_union {N : ℕ} (s e f : Finset (Fin N)) : + reindexSet s (e ∪ f) = reindexSet s e ∪ reindexSet s f := by + ext i + simp only [mem_reindexSet,Finset.mem_union] + +def reindexTemplate {N : ℕ} (s : Finset (Fin N)) (E : Graph N) (I : Finset (Fin N)) + (hE : ∀ e ∈ E, e ⊆ s) (hsimple : ∀ e ∈ E, e.card = 2) + (hind : ∀ e ∈ E, ¬ e ⊆ I) : RootedTemplate s.card where + edges := E.image (reindexSet s) + roots := reindexSet s I + simple := by + intro e he + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he + rw [reindexSet_card (hE f hf),hsimple f hf] + independent := by + intro e he hs + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he + exact hind f hf ((reindexSet_subset_iff (hE f hf)).mp hs) + +lemma reindexTemplate_edges_card {N : ℕ} (s : Finset (Fin N)) (E : Graph N) + (I : Finset (Fin N)) (hE : ∀ e ∈ E, e ⊆ s) (hsimple : ∀ e ∈ E, e.card = 2) + (hind : ∀ e ∈ E, ¬ e ⊆ I) : + (reindexTemplate s E I hE hsimple hind).edges.card = E.card := by + exact Finset.card_image_of_injOn (fun e he f hf h => reindexSet_inj (hE e he) (hE f hf) h) + +lemma reindexTemplate_roots_card {N : ℕ} (s : Finset (Fin N)) (E : Graph N) + (I : Finset (Fin N)) (hE : ∀ e ∈ E, e ⊆ s) (hsimple : ∀ e ∈ E, e.card = 2) + (hind : ∀ e ∈ E, ¬ e ⊆ I) (hI : I ⊆ s) : + (reindexTemplate s E I hE hsimple hind).roots.card = I.card := reindexSet_card hI + +lemma reindexTemplate_induced_card {N : ℕ} (s : Finset (Fin N)) (E : Graph N) + (I : Finset (Fin N)) (hE : ∀ e ∈ E, e ⊆ s) (hsimple : ∀ e ∈ E, e.card = 2) + (hind : ∀ e ∈ E, ¬ e ⊆ I) (U : Finset (Fin N)) : + (((reindexTemplate s E I hE hsimple hind).edges).filter + (fun e => e ⊆ reindexSet s U)).card = (E.filter (fun e => e ⊆ U)).card := by + have heq : ((E.image (reindexSet s)).filter (fun e => e ⊆ reindexSet s U)) = + (E.filter (fun e => e ⊆ U)).image (reindexSet s) := by + ext e + simp only [Finset.mem_filter,Finset.mem_image] + constructor + · rintro ⟨⟨f,hf,rfl⟩,hs⟩ + exact ⟨f,⟨hf,(reindexSet_subset_iff (hE f hf)).mp hs⟩,rfl⟩ + · rintro ⟨f,⟨hf,hs⟩,rfl⟩ + exact ⟨⟨f,hf,rfl⟩,(reindexSet_subset_iff (hE f hf)).mpr hs⟩ + change ((E.image (reindexSet s)).filter _).card = _ + rw [heq] + exact Finset.card_image_of_injOn (fun e he f hf h => + reindexSet_inj (hE e (Finset.mem_filter.mp he).1) (hE f (Finset.mem_filter.mp hf).1) h) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexSetImage.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexSetImage.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d78ac33332a08c6b4ecc0613716fd221da4eb61 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ReindexSetImage.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ReindexSet + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +@[simp] lemma reindexSet_image {N : ℕ} (s : Finset (Fin N)) (J : Finset (Fin s.card)) : + reindexSet s (J.image (s.orderEmbOfFin rfl)) = J := by + ext i + simp only [mem_reindexSet,Finset.mem_image] + constructor + · rintro ⟨j,hj,he⟩ + exact (s.orderEmbOfFin rfl).injective he ▸ hj + · intro hi + exact ⟨i,hi,rfl⟩ + +lemma reindexTemplate_free_card {N : ℕ} (Z I : Finset (Fin N)) (E : Graph N) + (hE : ∀ e ∈ E, e ⊆ Z ∪ I) (hsimple : ∀ e ∈ E, e.card = 2) + (hind : ∀ e ∈ E, ¬ e ⊆ I) (hd : Disjoint Z I) : + (Z ∪ I).card - (reindexTemplate (Z ∪ I) E I hE hsimple hind).roots.card = Z.card := by + rw [reindexTemplate_roots_card _ _ _ _ _ _ Finset.subset_union_right, + Finset.card_union_of_disjoint hd] + omega + +theorem reindexTemplate_sparse_transfer {N : ℕ} (Z I : Finset (Fin N)) (E : Graph N) + (hE : ∀ e ∈ E, e ⊆ Z ∪ I) (hsimple : ∀ e ∈ E, e.card = 2) + (hind : ∀ e ∈ E, ¬ e ⊆ I) (hd : Disjoint Z I) + (hsparse : ∀ U ⊆ Z, U ≠ Z → (E.filter (fun e => e ⊆ I ∪ U)).card ≤ 2 * U.card) : + let T := reindexTemplate (Z ∪ I) E I hE hsimple hind + ∀ J : Finset (Fin (Z ∪ I).card), T.roots ⊆ J → J ≠ Finset.univ → + (T.edges.filter (· ⊆ J)).card ≤ 2 * (J.card - T.roots.card) := by + intro T J hJ hproper + let s := Z ∪ I + let f := s.orderEmbOfFin rfl + let Js := J.image f + let U := Js ∩ Z + have hJs : Js ⊆ s := by + intro x hx + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx + exact s.orderEmbOfFin_mem rfl i + have hI : I ⊆ Js := by + intro x hx + rw [← image_reindexSet (s := s) (e := I) Finset.subset_union_right] at hx + obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp hx + exact Finset.mem_image.mpr ⟨i,hJ hi,rfl⟩ + have hU : U ⊆ Z := Finset.inter_subset_right + have hUnion : I ∪ U = Js := by + apply Finset.Subset.antisymm + · exact Finset.union_subset hI Finset.inter_subset_left + · intro x hx + rcases Finset.mem_union.mp (hJs hx) with hxZ | hxI + · exact Finset.mem_union_right I (Finset.mem_inter.mpr ⟨hx,hxZ⟩) + · exact Finset.mem_union_left U hxI + have hUne : U ≠ Z := by + intro he + have hJall : Js = s := by rw [← hUnion,he]; exact Finset.union_comm _ _ + apply hproper + apply Finset.eq_univ_of_forall + intro i + have hm : f i ∈ Js := by + rw [hJall] + exact s.orderEmbOfFin_mem rfl i + obtain ⟨j,hj,he⟩ := Finset.mem_image.mp hm + exact f.injective he ▸ hj + have hcardJs : Js.card = J.card := Finset.card_image_of_injective _ f.injective + have hdis : Disjoint I U := hd.symm.mono_right hU + have hcard : J.card - T.roots.card = U.card := by + have hh := Finset.card_union_of_disjoint hdis + rw [hUnion,hcardJs] at hh + have hroot : T.roots.card = I.card := reindexTemplate_roots_card _ _ _ _ _ _ + Finset.subset_union_right + rw [hroot] + omega + have hinduced : (T.edges.filter (· ⊆ J)).card = (E.filter (· ⊆ I ∪ U)).card := by + have hh := reindexTemplate_induced_card s E I hE hsimple hind Js + rw [reindexSet_image] at hh + rw [hUnion] + exact hh + rw [hinduced,hcard] + exact hsparse U hU hUne + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeCopyNoiseFirst.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeCopyNoiseFirst.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ffe8dce0000b24e507111080fecc87b9c54819a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeCopyNoiseFirst.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.RelativeScaleBudget + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem relativeCopyNoise_first_crossing {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L s : ℕ → ℝ) + (c B : ℝ) (hc : 0 < c) (hB : 0 ≤ B) + (hs : ∀ k ≤ T, 0 < s k) (hdec : ∀ k < T, s (k+1) ≤ s k) + (hL : ∀ k < T, 0 ≤ L k) (hjump : ∀ k < T, 3*L k/s (k+1) ≤ c) + (r : ℝ) (hr : 0 < r) (ω : History (Graph n) T) + (hω : ω ∈ (historyLaw (PMF.pure G) (fun _ => step) T T).support) + (j : ℕ) (hj : j ≤ T) (hloads : pastRelativeCopyLoadsSafe required L T j ω) + (hcounts : ∀ k < j, copyCount required (ω (historyIndex T k)) ≤ B*s k) + (hcross : r ≤ |historyNoise (fun _ => step) + (fun k H => copyCount required H/s k) T j ω|) : + ∃ m ≤ T, pastRelativeCopyLoadsSafe required L T m ω ∧ + r ≤ |historyNoise (fun _ => step) (fun k H => copyCount required H/s k) T m ω| ∧ + historyCounter (relativeCopyVarianceRate required L s) T m ω ≤ + c*(copyCount required G/s 0+B*relativeScaleBudget s T+r+c) := by + classical + let f := fun k H => copyCount required H/s k + let P : ℕ → Prop := fun m => r ≤ |historyNoise (fun _ => step) f T m ω| + have hex : ∃ m, P m := ⟨j,hcross⟩ + let m := Nat.find hex + have hmj : m ≤ j := Nat.find_min' hex hcross + have hmT : m ≤ T := hmj.trans hj + have hm : P m := Nat.find_spec hex + have hmpos : 0 < m := by + by_contra h + have he : m = 0 := by omega + have : r ≤ (0 : ℝ) := by simpa [P,he] using hm + linarith + obtain ⟨k,he⟩ := Nat.exists_eq_succ_of_ne_zero (Nat.ne_of_gt hmpos) + have hkm : k < m := by omega + have hkT : k < T := hkm.trans_le hmT + have hprev : |historyNoise (fun _ => step) f T k ω| < r := by + exact lt_of_not_ge (Nat.find_min hex hkm) + have hsafe : pastRelativeCopyLoadsSafe required L T m ω := by + intro a ha + apply hloads a + exact lt_of_lt_of_le ha (min_le_min_right T hmj) + obtain ⟨hinit,hpath⟩ := historyLaw_path_support (PMF.pure G) (fun _ => step) T T le_rfl ω hω + have hG : ω (historyIndex T 0) = G := by + simpa only [PMF.mem_support_pure_iff] using hinit + have hload : copyLoadSafe required (L k) (ω (historyIndex T k)) := by + apply hsafe k + simpa [Nat.min_eq_left hmT] using hkm + have hinc : |historyIncrement (fun _ => step) f T k ω| ≤ c := by + unfold historyIncrement + simp only [f,div_eq_mul_inv,pmfMean_mul_const,← sub_mul,abs_mul, + abs_of_pos (inv_pos.mpr (hs (k+1) (by omega)))] + have hh := pmf_centered_of_loss_range (step (ω (historyIndex T k))) (copyCount required) + (copyCount required (ω (historyIndex T k))) (3*L k) + (fun H hH => copyCount_step_loss_range required _ H (L k) (hL k hkT) hload hH) + _ (hpath k hkT) + exact (mul_le_mul_of_nonneg_right hh (inv_nonneg.mpr (hs (k+1) (by omega)).le)).trans + (by simpa only [div_eq_mul_inv] using hjump k hkT) + have hM : historyNoise (fun _ => step) f T m ω ≤ r+c := by + rw [he,historyNoise_succ_same _ _ T k hkT] + have hp := le_abs_self (historyNoise (fun _ => step) f T k ω) + have hi := le_abs_self (historyIncrement (fun _ => step) f T k ω) + linarith + refine ⟨m,hmT,hsafe,hm,?_⟩ + have hv := relativeCopyCounter_le required T m hmT L s c B hc.le hB hs hdec hjump ω + (fun a ha => hcounts a (ha.trans_le hmj)) + rw [hG] at hv + exact hv.trans (mul_le_mul_of_nonneg_left (by dsimp [f] at hM; linarith) hc.le) + +open Classical in + +theorem triangle_relative_template_self_bounded_tail {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L s : ℕ → ℝ) + (c B : ℝ) (hc : 0 < c) (hB : 0 ≤ B) + (hs : ∀ k ≤ T, 0 < s k) (hdec : ∀ k < T, s (k+1) ≤ s k) + (hL : ∀ k < T, 0 ≤ L k) (hjump : ∀ k < T, 3*L k/s (k+1) ≤ c) + (r : ℝ) (hr : 0 < r) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ j ≤ T, pastRelativeCopyLoadsSafe required L T j ω ∧ + (∀ k < j, copyCount required (ω (historyIndex T k)) ≤ B*s k) ∧ + r ≤ |historyNoise (fun _ => step) (fun k H => copyCount required H/s k) T j ω| + then 1 else 0) ≤ + 2*(T+1 : ℝ)*Real.exp + (-r^2/(4*(c*(copyCount required G/s 0+B*relativeScaleBudget s T+r+c)+c*r))) := by + have hs' : ∀ k < T, 0 < s (k+1) := fun k hk => hs (k+1) (by omega) + have hV : 0 ≤ c*(copyCount required G/s 0+B*relativeScaleBudget s T+r+c) := by + have hz := hs 0 (Nat.zero_le T) + have hn := copyCount_nonneg required G + have hb := relativeScaleBudget_nonneg s T hs hdec + positivity + apply le_trans _ (triangle_relative_template_before_load_exit required G T L s c hc hs' hL + hjump r (c*(copyCount required G/s 0+B*relativeScaleBudget s T+r+c)) hr hV) + apply pmfMean_mono + intro ω hω + by_cases hex : ∃ j ≤ T, pastRelativeCopyLoadsSafe required L T j ω ∧ + (∀ k < j, copyCount required (ω (historyIndex T k)) ≤ B*s k) ∧ + r ≤ |historyNoise (fun _ => step) (fun k H => copyCount required H/s k) T j ω| + · obtain ⟨j,hj,hloads,hcounts,hcross⟩ := hex + have hh := relativeCopyNoise_first_crossing required G T L s c B hc hB hs hdec hL hjump + r hr ω hω j hj hloads hcounts hcross + rw [ite_eq_left ⟨j,hj,hloads,hcounts,hcross⟩,ite_eq_left hh] + · rw [ite_eq_right hex] + split <;> norm_num + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeNoiseExit.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeNoiseExit.lean new file mode 100644 index 0000000000000000000000000000000000000000..66b692dffa5ec989c174d6b16a3a9c0c8e333c39 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeNoiseExit.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.RelativeCopyNoiseFirst + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +def RelativeNoiseExit {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L s : ℕ → ℝ) (B r : ℝ) + (T : ℕ) (ω : History (Graph n) T) : Prop := + ∃ j ≤ T, pastRelativeCopyLoadsSafe required L T j ω ∧ + (∀ k < j, copyCount required (ω (historyIndex T k)) ≤ B*s k) ∧ + r ≤ |historyNoise (fun _ => step) (fun k H => copyCount required H/s k) T j ω| + +open Classical in + +theorem simultaneous_relative_template_tail {n : ℕ} {I : Type*} [Fintype I] + {α : I → Type*} [∀ i, Fintype (α i)] + (required : ∀ i, α i → Graph n) (G : Graph n) (T : ℕ) + (L s : I → ℕ → ℝ) (c B r : I → ℝ) + (hc : ∀ i, 0 < c i) (hB : ∀ i, 0 ≤ B i) + (hs : ∀ i k, k ≤ T → 0 < s i k) + (hdec : ∀ i k, k < T → s i (k+1) ≤ s i k) + (hL : ∀ i k, k < T → 0 ≤ L i k) + (hjump : ∀ i k, k < T → 3*L i k/s i (k+1) ≤ c i) + (hr : ∀ i, 0 < r i) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ i, RelativeNoiseExit (required i) (L i) (s i) (B i) (r i) T ω + then 1 else 0) ≤ + ∑ i, 2*(T+1 : ℝ)*Real.exp + (-(r i)^2/(4*(c i*(copyCount (required i) G/s i 0+ + B i*relativeScaleBudget (s i) T+r i+c i)+c i*r i))) := by + classical + have hh := pmfMean_event_union (historyLaw (PMF.pure G) (fun _ => step) T T) + (Finset.univ : Finset I) + (fun i ω => RelativeNoiseExit (required i) (L i) (s i) (B i) (r i) T ω) + simp only [Finset.mem_univ,true_and] at hh + apply hh.trans + apply Finset.sum_le_sum + intro i _ + have ht := triangle_relative_template_self_bounded_tail (required i) G T (L i) (s i) + (c i) (B i) (hc i) (hB i) (hs i) (hdec i) (hL i) (hjump i) (r i) (hr i) + convert ht using 1 + apply congrArg (pmfMean _) + funext ω + simp only [RelativeNoiseExit] + congr 1 + +open Classical in + +theorem simultaneous_relative_template_common_tail {n : ℕ} {I : Type*} [Fintype I] + {α : I → Type*} [∀ i, Fintype (α i)] + (required : ∀ i, α i → Graph n) (G : Graph n) (T : ℕ) + (L s : I → ℕ → ℝ) (c B r : I → ℝ) + (hc : ∀ i, 0 < c i) (hB : ∀ i, 0 ≤ B i) + (hs : ∀ i k, k ≤ T → 0 < s i k) + (hdec : ∀ i k, k < T → s i (k+1) ≤ s i k) + (hL : ∀ i k, k < T → 0 ≤ L i k) + (hjump : ∀ i k, k < T → 3*L i k/s i (k+1) ≤ c i) + (hr : ∀ i, 0 < r i) (A : ℝ) + (hbudget : ∀ i, A ≤ (r i)^2/(4*(c i*(copyCount (required i) G/s i 0+ + B i*relativeScaleBudget (s i) T+r i+c i)+c i*r i))) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ i, RelativeNoiseExit (required i) (L i) (s i) (B i) (r i) T ω + then 1 else 0) ≤ + (Fintype.card I : ℝ)*2*(T+1)*Real.exp (-A) := by + apply (simultaneous_relative_template_tail required G T L s c B r hc hB hs hdec hL hjump hr).trans + calc + _ ≤ ∑ _i : I, 2*(T+1 : ℝ)*Real.exp (-A) := by + apply Finset.sum_le_sum + intro i _ + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Real.exp_le_exp.mpr + rw [neg_div] + exact neg_le_neg (hbudget i) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeSafeCopyIncrement.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeSafeCopyIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b7ece7e19048bade76645102a61c6da1ed8c97a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeSafeCopyIncrement.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.CopyLoadSafe +import OAI.Combinatorics.TriangleRemoval.Probability.PmfMeanNeg + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +noncomputable def relativeSafeCopyIncrement {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L s : ℕ → ℝ) (j : ℕ) (G H : Graph n) : ℝ := by + classical + exact if copyLoadSafe required (L j) G then + (copyCount required H - pmfMean (step G) (copyCount required)) / s (j+1) else 0 + +noncomputable def relativeCopyVarianceRate {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L s : ℕ → ℝ) (j : ℕ) (G : Graph n) : ℝ := + copyVarianceRate required (L j) j G / (s (j+1))^2 + +noncomputable def relativeSafeCopyVarianceRate {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L s : ℕ → ℝ) (j : ℕ) (G : Graph n) : ℝ := by + classical + exact if copyLoadSafe required (L j) G then relativeCopyVarianceRate required L s j G + else 0 + +theorem triangle_relative_safe_template_freedman {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L s : ℕ → ℝ) + (c : ℝ) (hc : 0 < c) + (hs : ∀ j < T, 0 < s (j+1)) (hL : ∀ j < T, 0 ≤ L j) + (hjump : ∀ j < T, 3*L j / s (j+1) ≤ c) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ j ≤ T, + r ≤ |historyAdditive (relativeSafeCopyIncrement required L s) T j ω| ∧ + historyCounter (relativeSafeCopyVarianceRate required L s) T j ω ≤ V + then 1 else 0) ≤ + 2*(T+1 : ℝ)*Real.exp (-r^2/(4*(V+c*r))) := by + classical + apply history_additive_freedman_two_sided (PMF.pure G) (fun _ => step) + (relativeSafeCopyIncrement required L s) (relativeSafeCopyVarianceRate required L s) + T c hc + · intro j hj H _ J hJ + by_cases hsafe : copyLoadSafe required (L j) H + · simp only [relativeSafeCopyIncrement,ite_eq_left hsafe,abs_div,abs_of_pos (hs j hj)] + exact (div_le_div_of_nonneg_right + (pmf_centered_of_loss_range (step H) (copyCount required) (copyCount required H) + (3*L j) (fun A hA => copyCount_step_loss_range required H A (L j) + (hL j hj) hsafe hA) J hJ) (hs j hj).le).trans (hjump j hj) + · simp only [relativeSafeCopyIncrement,ite_eq_right hsafe,abs_zero] + exact hc.le + · intro j _ H _ + change pmfMean (step H) (fun J => relativeSafeCopyIncrement required L s j H J) = 0 + by_cases hsafe : copyLoadSafe required (L j) H + · simp only [relativeSafeCopyIncrement,ite_eq_left hsafe,div_eq_mul_inv] + rw [pmfMean_mul_const,pmfMean_sub,pmfMean_const,sub_self,zero_mul] + · simp only [relativeSafeCopyIncrement,ite_eq_right hsafe,pmfMean_const] + · intro j hj H _ + by_cases hsafe : copyLoadSafe required (L j) H + · simp only [relativeSafeCopyIncrement,relativeSafeCopyVarianceRate,ite_eq_left hsafe, + div_eq_mul_inv,mul_pow,inv_pow] + rw [pmfMean_mul_const] + change _ ≤ (3*L j*(copyCount required H - pmfMean (step H) (copyCount required))) * + ((s (j+1))^2)⁻¹ + exact mul_le_mul_of_nonneg_right + (pmf_variance_of_loss_range (step H) (copyCount required) (copyCount required H) + (3*L j) (fun A hA => copyCount_step_loss_range required H A (L j) + (hL j hj) hsafe hA)) (inv_nonneg.mpr (sq_nonneg _)) + · simp only [relativeSafeCopyIncrement,relativeSafeCopyVarianceRate,ite_eq_right hsafe, + zero_pow (by decide : 2 ≠ 0),pmfMean_const,le_refl] + · exact hr + · exact hV + +def pastRelativeCopyLoadsSafe {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L : ℕ → ℝ) (T j : ℕ) (ω : History (Graph n) T) : Prop := + ∀ k < min j T, copyLoadSafe required (L k) (ω (historyIndex T k)) + +lemma relativeSafeCopyNoise_eq {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L s : ℕ → ℝ) (T j : ℕ) (ω : History (Graph n) T) + (hsafe : pastRelativeCopyLoadsSafe required L T j ω) : + historyAdditive (relativeSafeCopyIncrement required L s) T j ω = + historyNoise (fun _ => step) (fun k H => copyCount required H / s k) T j ω := by + classical + unfold historyAdditive historyNoise + apply Finset.sum_congr rfl + intro k hk + simp only [historyIncrement,relativeSafeCopyIncrement, + ite_eq_left (hsafe k (Finset.mem_range.mp hk)),div_eq_mul_inv,pmfMean_mul_const,sub_mul] + +lemma relativeSafeCopyCounter_eq {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (L s : ℕ → ℝ) (T j : ℕ) (ω : History (Graph n) T) + (hsafe : pastRelativeCopyLoadsSafe required L T j ω) : + historyCounter (relativeSafeCopyVarianceRate required L s) T j ω = + historyCounter (relativeCopyVarianceRate required L s) T j ω := by + classical + unfold historyCounter + apply Finset.sum_congr rfl + intro k hk + simp only [relativeSafeCopyVarianceRate,ite_eq_left (hsafe k (Finset.mem_range.mp hk))] + +open Classical in + +theorem triangle_relative_template_before_load_exit {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (T : ℕ) (L s : ℕ → ℝ) + (c : ℝ) (hc : 0 < c) + (hs : ∀ j < T, 0 < s (j+1)) (hL : ∀ j < T, 0 ≤ L j) + (hjump : ∀ j < T, 3*L j / s (j+1) ≤ c) + (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) : + pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T) + (fun ω => if ∃ j ≤ T, pastRelativeCopyLoadsSafe required L T j ω ∧ + r ≤ |historyNoise (fun _ => step) (fun k H => copyCount required H / s k) T j ω| ∧ + historyCounter (relativeCopyVarianceRate required L s) T j ω ≤ V then 1 else 0) ≤ + 2*(T+1 : ℝ)*Real.exp (-r^2/(4*(V+c*r))) := by + apply le_trans _ (triangle_relative_safe_template_freedman required G T L s c hc hs hL + hjump r V hr hV) + apply pmfMean_mono + intro ω _ + by_cases h : ∃ j ≤ T, pastRelativeCopyLoadsSafe required L T j ω ∧ + r ≤ |historyNoise (fun _ => step) (fun k H => copyCount required H / s k) T j ω| ∧ + historyCounter (relativeCopyVarianceRate required L s) T j ω ≤ V + · obtain ⟨j,hj,hsafe,hn,hv⟩ := h + have h' : ∃ j ≤ T, + r ≤ |historyAdditive (relativeSafeCopyIncrement required L s) T j ω| ∧ + historyCounter (relativeSafeCopyVarianceRate required L s) T j ω ≤ V := by + refine ⟨j,hj,?_,?_⟩ + · rwa [relativeSafeCopyNoise_eq required L s T j ω hsafe] + · rwa [relativeSafeCopyCounter_eq required L s T j ω hsafe] + rw [ite_eq_left ⟨j,hj,hsafe,hn,hv⟩,ite_eq_left h'] + · rw [ite_eq_right h] + split <;> norm_num + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeScaleBudget.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeScaleBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..b24e629cfe2ef2b5ef4d9967c1fa1312ec94f842 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/RelativeScaleBudget.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.HistoryLawPathSupport +import OAI.Combinatorics.TriangleRemoval.Process.RelativeSafeCopyIncrement + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +noncomputable def relativeScaleBudget (s : ℕ → ℝ) (j : ℕ) : ℝ := + ∑ k ∈ Finset.range j, (s k / s (k+1) - 1) + +theorem history_relative_loss_counter {α : Type*} [Fintype α] + (K : ℕ → α → PMF α) (f : α → ℝ) (s : ℕ → ℝ) + (T j : ℕ) (hj : j ≤ T) (ω : History α T) : + historyCounter (fun k a => (f a-pmfMean (K k a) f)/s (k+1)) T j ω = + f (ω (historyIndex T 0))/s 0 - f (ω (historyIndex T j))/s j + + (∑ k ∈ Finset.range j, f (ω (historyIndex T k)) * (1/s (k+1)-1/s k)) + + historyNoise K (fun k a => f a/s k) T j ω := by + unfold historyCounter historyNoise historyIncrement + simp only [Nat.min_eq_left hj,div_eq_mul_inv,pmfMean_mul_const] + have he : (∑ k ∈ Finset.range j, + (f (ω (historyIndex T k))-pmfMean (K k (ω (historyIndex T k))) f) * (s (k+1))⁻¹) = + (∑ k ∈ Finset.range j, + (f (ω (historyIndex T k)) * (s k)⁻¹- + f (ω (historyIndex T (k+1))) * (s (k+1))⁻¹)) + + (∑ k ∈ Finset.range j, + f (ω (historyIndex T k)) * (1*(s (k+1))⁻¹-1*(s k)⁻¹)) + + (∑ k ∈ Finset.range j, + (f (ω (historyIndex T (k+1))) * (s (k+1))⁻¹- + pmfMean (K k (ω (historyIndex T k))) f * (s (k+1))⁻¹)) := by + rw [← Finset.sum_add_distrib,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + rw [he,Finset.sum_range_sub'] + +lemma relativeScaleBudget_nonneg (s : ℕ → ℝ) (T : ℕ) + (hs : ∀ j ≤ T, 0 < s j) (hdec : ∀ j < T, s (j+1) ≤ s j) : + 0 ≤ relativeScaleBudget s T := by + apply Finset.sum_nonneg + intro j hj + have hjT := Finset.mem_range.mp hj + exact sub_nonneg.mpr ((one_le_div (hs (j+1) (by omega))).mpr + (hdec j (Finset.mem_range.mp hj))) + +lemma relativeScaleBudget_mono (s : ℕ → ℝ) (T : ℕ) + (hs : ∀ j ≤ T, 0 < s j) (hdec : ∀ j < T, s (j+1) ≤ s j) + {j : ℕ} (hj : j ≤ T) : relativeScaleBudget s j ≤ relativeScaleBudget s T := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono hj) + intro k hk _ + exact sub_nonneg.mpr ((one_le_div (hs (k+1) (by have := Finset.mem_range.mp hk; omega))).mpr + (hdec k (Finset.mem_range.mp hk))) + +theorem relativeCopyCounter_le {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (T j : ℕ) (hj : j ≤ T) (L s : ℕ → ℝ) + (c B : ℝ) (hc : 0 ≤ c) (hB : 0 ≤ B) + (hs : ∀ k ≤ T, 0 < s k) (hdec : ∀ k < T, s (k+1) ≤ s k) + (hjump : ∀ k < T, 3*L k/s (k+1) ≤ c) + (ω : History (Graph n) T) + (hcount : ∀ k < j, copyCount required (ω (historyIndex T k)) ≤ B*s k) : + historyCounter (relativeCopyVarianceRate required L s) T j ω ≤ + c*(copyCount required (ω (historyIndex T 0))/s 0 + B*relativeScaleBudget s T + + historyNoise (fun _ => step) (fun k H => copyCount required H/s k) T j ω) := by + have hsum : historyCounter (relativeCopyVarianceRate required L s) T j ω ≤ + c*historyCounter (fun k H => + (copyCount required H-pmfMean (step H) (copyCount required))/s (k+1)) T j ω := by + unfold historyCounter + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro k hk + have hkj : k < j := by simpa only [Nat.min_eq_left hj,Finset.mem_range] using hk + have hkT : k < T := hkj.trans_le hj + have ht : 0 ≤ copyCount required (ω (historyIndex T k))- + pmfMean (step (ω (historyIndex T k))) (copyCount required) := by + apply sub_nonneg.mpr + rw [← pmfMean_const (step (ω (historyIndex T k))) + (copyCount required (ω (historyIndex T k)))] + apply pmfMean_mono + intro H hH + exact copyCount_mono required (step_support_subset hH) + calc + _ = (3*L k/s (k+1))* + ((copyCount required (ω (historyIndex T k))- + pmfMean (step (ω (historyIndex T k))) (copyCount required))/s (k+1)) := by + unfold relativeCopyVarianceRate copyVarianceRate + ring + _ ≤ _ := mul_le_mul_of_nonneg_right (hjump k hkT) + (div_nonneg ht (hs (k+1) (by omega)).le) + apply hsum.trans + rw [history_relative_loss_counter _ _ _ _ _ hj] + apply mul_le_mul_of_nonneg_left _ hc + have hnon : 0 ≤ copyCount required (ω (historyIndex T j))/s j := + div_nonneg (copyCount_nonneg _ _) (hs j hj).le + have hbudget : (∑ k ∈ Finset.range j, + copyCount required (ω (historyIndex T k)) * (1/s (k+1)-1/s k)) ≤ + B*relativeScaleBudget s T := by + calc + _ ≤ B*relativeScaleBudget s j := by + unfold relativeScaleBudget + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro k hk + have hkj := Finset.mem_range.mp hk + have hkT : k < T := hkj.trans_le hj + have hsk := hs k (by omega) + have hsk1 := hs (k+1) (by omega) + calc + _ ≤ (B*s k)*(1/s (k+1)-1/s k) := by + apply mul_le_mul_of_nonneg_right (hcount k hkj) + exact sub_nonneg.mpr (one_div_le_one_div_of_le hsk1 (hdec k hkT)) + _ = _ := by field_simp + _ ≤ _ := mul_le_mul_of_nonneg_left (relativeScaleBudget_mono s T hs hdec hj) hB + linarith + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/Restrict.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/Restrict.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a91231cdc49042a0f4c11c69259ca9f1d51441f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/Restrict.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ReindexSet +import OAI.Combinatorics.TriangleRemoval.Process.Within + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N : ℕ} (B : BirthGraph N) + +def restrict (s : Finset (Fin N)) + (hclosed : ∀ v ∈ s, B.older v ⊆ s) : BirthGraph s.card where + older v := reindexSet s (B.older (s.orderEmbOfFin rfl v)) + older_lt v u hu := (s.orderEmbOfFin rfl).lt_iff_lt.mp + (B.older_lt _ _ ((mem_reindexSet _ _ _).mp hu)) + older_card v := by + rw [reindexSet_card (hclosed _ (s.orderEmbOfFin_mem rfl v))] + exact B.older_card _ + +@[simp] lemma restrict_older_mem (s : Finset (Fin N)) + (hclosed : ∀ v ∈ s, B.older v ⊆ s) (u v : Fin s.card) : + u ∈ (B.restrict s hclosed).older v ↔ + s.orderEmbOfFin rfl u ∈ B.older (s.orderEmbOfFin rfl v) := + mem_reindexSet _ _ _ + +@[simp] lemma restrict_graph_adj (s : Finset (Fin N)) + (hclosed : ∀ v ∈ s, B.older v ⊆ s) (u v : Fin s.card) : + (B.restrict s hclosed).graph.Adj u v ↔ + B.graph.Adj (s.orderEmbOfFin rfl u) (s.orderEmbOfFin rfl v) := by + simp only [graph_adj,restrict_older_mem] + +lemma restrict_older_card (s : Finset (Fin N)) + (hclosed : ∀ v ∈ s, B.older v ⊆ s) (v : Fin s.card) : + ((B.restrict s hclosed).older v).card = (B.older (s.orderEmbOfFin rfl v)).card := + reindexSet_card (hclosed _ (s.orderEmbOfFin_mem rfl v)) + +lemma restrict_within (s : Finset (Fin N)) + (hclosed : ∀ v ∈ s, B.older v ⊆ s) (Z : Finset (Fin N)) (hZ : Z ⊆ s) + {x y : Fin N} (h : B.Within Z x y) (hx : x ∈ s) (hy : y ∈ s) : + (B.restrict s hclosed).Within (reindexSet s Z) + ((s.orderIsoOfFin rfl).symm ⟨x,hx⟩) ((s.orderIsoOfFin rfl).symm ⟨y,hy⟩) := by + induction h using Relation.ReflTransGen.head_induction_on with + | refl => exact Relation.ReflTransGen.refl + | @head x z hxz _ ih => + have hz : z ∈ s := hZ hxz.2.1 + apply Relation.ReflTransGen.head (b := (s.orderIsoOfFin rfl).symm ⟨z,hz⟩) _ (ih hz) + have hex : s.orderEmbOfFin rfl ((s.orderIsoOfFin rfl).symm ⟨x,hx⟩) = x := + congrArg Subtype.val ((s.orderIsoOfFin rfl).apply_symm_apply ⟨x,hx⟩) + have hez : s.orderEmbOfFin rfl ((s.orderIsoOfFin rfl).symm ⟨z,hz⟩) = z := + congrArg Subtype.val ((s.orderIsoOfFin rfl).apply_symm_apply ⟨z,hz⟩) + simpa only [mem_reindexSet,restrict_older_mem,hex,hez] using hxz + +lemma restrict_covered (s : Finset (Fin N)) + (hclosed : ∀ v ∈ s, B.older v ⊆ s) (Z : Finset (Fin N)) (hZ : Z ⊆ s) + {a b : Fin N} (ha : a ∈ s) (hb : b ∈ s) (hc : B.Covered Z a b) : + (B.restrict s hclosed).Covered (reindexSet s Z) + ((s.orderIsoOfFin rfl).symm ⟨a,ha⟩) ((s.orderIsoOfFin rfl).symm ⟨b,hb⟩) := by + intro i hi + have hfi := (mem_reindexSet s Z i).mp hi + have ha' : s.orderEmbOfFin rfl ((s.orderIsoOfFin rfl).symm ⟨a,ha⟩) = a := + congrArg Subtype.val ((s.orderIsoOfFin rfl).apply_symm_apply ⟨a,ha⟩) + have hb' : s.orderEmbOfFin rfl ((s.orderIsoOfFin rfl).symm ⟨b,hb⟩) = b := + congrArg Subtype.val ((s.orderIsoOfFin rfl).apply_symm_apply ⟨b,hb⟩) + have hi' : (s.orderIsoOfFin rfl).symm ⟨s.orderEmbOfFin rfl i,hZ hfi⟩ = i := by + exact (s.orderIsoOfFin rfl).symm_apply_apply i + rcases hc _ hfi with ⟨haZ,hh⟩ | ⟨hbZ,hh⟩ + · refine Or.inl ⟨(mem_reindexSet s Z _).mpr (by rw [ha']; exact haZ),?_⟩ + simpa only [hi'] using B.restrict_within s hclosed Z hZ hh (hZ hfi) ha + · refine Or.inr ⟨(mem_reindexSet s Z _).mpr (by rw [hb']; exact hbZ),?_⟩ + simpa only [hi'] using B.restrict_within s hclosed Z hZ hh (hZ hfi) hb + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/RestrictedParent.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/RestrictedParent.lean new file mode 100644 index 0000000000000000000000000000000000000000..76d450fa23d82c88ccd7402289c28aca6847d57e --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/RestrictedParent.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PathForest + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.PathForest +variable {s : ℕ} + +noncomputable def restrictedParent (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) + (i : Fin S.card) : Option (Fin S.card) := + match hp : F.parent (S.orderEmbOfFin rfl i) with + | none => none + | some p => some ((S.orderIsoOfFin rfl).symm + ⟨p,hS _ (S.orderEmbOfFin_mem rfl i) p hp⟩) + +noncomputable def restrict (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) : PathForest S.card := by + refine ⟨F.restrictedParent S hS,?_⟩ + intro i j hij + unfold restrictedParent at hij + split at hij + · contradiction + · rename_i p hp + have hj := Option.some.inj hij + subst j + apply (S.orderEmbOfFin rfl).lt_iff_lt.mp + have he : S.orderEmbOfFin rfl ((S.orderIsoOfFin rfl).symm + ⟨p,hS _ (S.orderEmbOfFin_mem rfl i) p hp⟩) = p := + congrArg Subtype.val ((S.orderIsoOfFin rfl).apply_symm_apply _) + rw [he] + exact F.property _ _ hp + +noncomputable def index (S : Finset (Fin s)) (v : Fin s) (hv : v ∈ S) : Fin S.card := + (S.orderIsoOfFin rfl).symm ⟨v,hv⟩ + +@[simp] lemma embed_index (S : Finset (Fin s)) (v : Fin s) (hv : v ∈ S) : + S.orderEmbOfFin rfl (index S v hv) = v := + congrArg Subtype.val ((S.orderIsoOfFin rfl).apply_symm_apply _) + +@[simp] lemma index_embed (S : Finset (Fin s)) (i : Fin S.card) : + index S (S.orderEmbOfFin rfl i) (S.orderEmbOfFin_mem rfl i) = i := + (S.orderIsoOfFin rfl).symm_apply_apply i + +lemma restrict_parent_some (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) (i j : Fin S.card) : + (F.restrict S hS).parent i = some j ↔ + F.parent (S.orderEmbOfFin rfl i) = some (S.orderEmbOfFin rfl j) := by + change F.restrictedParent S hS i = some j ↔ _ + unfold restrictedParent + split + · rename_i he + rw [he] + simp + · rename_i p hp + simp only [hp,Option.some.injEq] + change index S p (hS _ (S.orderEmbOfFin_mem rfl i) p hp) = j ↔ _ + constructor + · intro he + rw [← he,embed_index] + · intro he + subst p + exact index_embed S j + +lemma restrict_step_iff (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) (i j : Fin S.card) : + (F.restrict S hS).Step i j ↔ + F.Step (S.orderEmbOfFin rfl i) (S.orderEmbOfFin rfl j) := + restrict_parent_some F S hS j i + +lemma restrict_ancestor (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) + {x y : Fin s} (hx : x ∈ S) (hy : y ∈ S) (h : F.Ancestor x y) : + (F.restrict S hS).Ancestor (index S x hx) (index S y hy) := by + induction h with + | refl => exact Relation.ReflTransGen.refl + | @tail y z hxy hyz ih => + have hym : y ∈ S := hS z hy y hyz + apply Relation.ReflTransGen.tail (ih hym) + apply (F.restrict_step_iff S hS _ _).mpr + simpa only [embed_index] using hyz + +lemma original_ancestor (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) + {i j : Fin S.card} (h : (F.restrict S hS).Ancestor i j) : + F.Ancestor (S.orderEmbOfFin rfl i) (S.orderEmbOfFin rfl j) := by + induction h with + | refl => exact Relation.ReflTransGen.refl + | @tail i j hij hjk ih => + exact Relation.ReflTransGen.tail ih ((F.restrict_step_iff S hS _ _).mp hjk) + +noncomputable def restrictMark (S : Finset (Fin s)) (a : Fin s) : Option (Fin S.card) := by + classical + exact if ha : a ∈ S then some (index S a ha) else none + +lemma restrict_onPath (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) + {x a : Fin s} (hx : x ∈ S) (ha : a ∈ S) (h : F.Ancestor x a) : + (F.restrict S hS).OnPath (restrictMark S a) (index S x hx) := by + classical + refine ⟨index S a ha,?_,F.restrict_ancestor S hS hx ha h⟩ + simp only [restrictMark,dite_eq_left ha] + +theorem restrict_two_path_cover (F : PathForest s) (S : Finset (Fin s)) + (hS : ∀ v ∈ S, ∀ p, F.parent v = some p → p ∈ S) (a b : Fin s) + (hc : ∀ v ∈ S, (a ∈ S ∧ F.Ancestor v a) ∨ (b ∈ S ∧ F.Ancestor v b)) : + ∀ i, (F.restrict S hS).OnPath (restrictMark S a) i ∨ + (F.restrict S hS).OnPath (restrictMark S b) i := by + intro i + have hi := S.orderEmbOfFin_mem rfl i + rcases hc _ hi with ⟨ha,hva⟩ | ⟨hb,hvb⟩ + · exact Or.inl (by simpa only [index_embed] using F.restrict_onPath S hS hi ha hva) + · exact Or.inr (by simpa only [index_embed] using F.restrict_onPath S hS hi hb hvb) + +end SharpTerminalLeave.PathForest + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/RootClosers.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/RootClosers.lean new file mode 100644 index 0000000000000000000000000000000000000000..46ae129445f995cf41e66a2ff0497b61d09d4437 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/RootClosers.lean @@ -0,0 +1,101 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEmbeddings +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Process.BornEdges + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma product_two_values (R : ℕ) (T : Finset ℕ) (hT : T ⊆ Finset.range R) (x y : ℝ) : + (∏ i ∈ Finset.range R, if i ∈ T then x else y) = x^T.card * y^(R-T.card) := by + classical + have ht : (Finset.range R).filter (fun i => i ∈ T) = T := by + ext i + simp only [Finset.mem_filter] + exact ⟨And.right,fun hi => ⟨hT hi,hi⟩⟩ + have hc := Finset.card_filter_add_card_filter_not (s := Finset.range R) (fun i => i ∈ T) + rw [ht,Finset.card_range] at hc + have hn : ((Finset.range R).filter (fun i => i ∉ T)).card = R-T.card := by omega + rw [Finset.prod_ite] + simp only [Finset.prod_const,ht,hn] + +namespace BirthGraph +variable {N : ℕ} (B : BirthGraph N) + +noncomputable def rootClosers (R : ℕ) : Finset ℕ := + ((initialVertices N R).filter (fun v => (B.older v).Nonempty)).image Fin.val + +lemma rootClosers_subset (R : ℕ) : B.rootClosers R ⊆ Finset.range R := by + intro i hi + obtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp hi + exact Finset.mem_range.mpr ((mem_initialVertices N R v).mp (Finset.mem_filter.mp hv).1) + +lemma rootClosers_card (R : ℕ) + (hs : ∀ v : Fin N, v.val < R → (B.older v).card ≤ 1) : + (B.rootClosers R).card = (B.backEdges (initialVertices N R)).card := by + classical + rw [rootClosers,Finset.card_image_of_injective _ Fin.val_injective, + B.backEdges_card,Finset.card_filter] + apply Finset.sum_congr rfl + intro v hv + have hs' := hs v ((mem_initialVertices N R v).mp hv) + by_cases hn : (B.older v).Nonempty + · rw [ite_eq_left hn] + have hp := Finset.card_pos.mpr hn + omega + · rw [ite_eq_right hn,Finset.not_nonempty_iff_eq_empty.mp hn,Finset.card_empty] + +lemma rootClosers_predecessor (R : ℕ) (i : ℕ) (hi : i ∈ B.rootClosers R) + (hN : i+1 ≤ N) : ∃ u : Fin i, + B.graph.Adj (Fin.castLE (show i ≤ N by omega) u) ⟨i,by omega⟩ := by + obtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp hi + obtain ⟨u,hu⟩ := (Finset.mem_filter.mp hv).2 + have hlt := B.older_lt v u hu + refine ⟨⟨u.val,hlt⟩,?_⟩ + exact Or.inl hu + +theorem prefixEmbeddings_unordered_roots {V : Type*} [Fintype V] [DecidableEq V] + (G : SimpleGraph V) [DecidableRel G.Adj] (R : ℕ) (hR : R ≤ N) (Δ : ℝ) + (hΔ0 : 0 ≤ Δ) + (hΔ : ∀ x : V, ((Finset.univ.filter (G.Adj x)).card : ℝ) ≤ Δ) : + letI : DecidableRel B.graph.Adj := Classical.decRel _ + ((prefixEmbeddings B.graph G R hR).card : ℝ) ≤ + (Fintype.card V : ℝ)^(R-(B.rootClosers R).card) * Δ^(B.rootClosers R).card := by + classical + let b : ℕ → ℝ := fun i => if i ∈ B.rootClosers R then Δ else Fintype.card V + have hb0 : ∀ i < N, 0 ≤ b i := by + intro i _ + dsimp only [b] + split_ifs <;> first | exact hΔ0 | positivity + have hb : ∀ i (hi : i+1 ≤ N), ∀ ψ ∈ prefixEmbeddings B.graph G i (by omega), + ((compatibleNext B.graph G hi ψ).card : ℝ) ≤ b i := by + intro i hi ψ _ + dsimp only [b] + by_cases hclose : i ∈ B.rootClosers R + · rw [ite_eq_left hclose] + obtain ⟨u,hu⟩ := B.rootClosers_predecessor R i hclose hi + exact compatibleNext_le_degree hi ψ u hu Δ hΔ + · rw [ite_eq_right hclose] + exact_mod_cast compatibleNext_le_order hi ψ + have h := prefixEmbeddings_product_bound (J := B.graph) (G := G) b hb0 hb R hR + change _ ≤ ∏ i ∈ Finset.range R, if i ∈ B.rootClosers R then Δ else (Fintype.card V : ℝ) at h + rw [product_two_values R (B.rootClosers R) (B.rootClosers_subset R)] at h + simpa only [mul_comm] using h + +end BirthGraph +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/RootSet.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/RootSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..428fd2db5bb9d54f75cce1429378cc3142506357 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/RootSet.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraph +import OAI.Combinatorics.TriangleRemoval.Process.TriangleThird +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave.RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) + +def rootSet (_F : RecordedCallForest (triangleHypergraph G) c) : Finset (Fin n) := c.focus.biUnion id + +def rootCount : ℕ := F.rootSet.card + +def vertexCount : ℕ := F.rootCount + (F.size - 1) + +lemma size_pos : 0 < F.size := lt_of_le_of_lt (Nat.zero_le _) F.root.isLt + +lemma nonroot_pos (i : Fin F.size) (hi : i ≠ F.root) : 0 < i.val := by + have hr := F.root_val + have hn : i.val ≠ F.root.val := (Fin.ne_iff_vne _ _).mp hi + omega + +def birthIndex (i : Fin F.size) (hi : i ≠ F.root) : Fin F.vertexCount := + ⟨F.rootCount + (i.val - 1), by + have his := i.isLt + have hs := F.size_pos + have hip := F.nonroot_pos i hi + unfold vertexCount + omega⟩ + +lemma birthIndex_nonroot (i : Fin F.size) (hi : i ≠ F.root) : + F.rootCount ≤ (F.birthIndex i hi).val := Nat.le_add_right _ _ + +lemma birthIndex_injective (i j : Fin F.size) (hi : i ≠ F.root) (hj : j ≠ F.root) + (he : F.birthIndex i hi = F.birthIndex j hj) : i = j := by + have hi0 := F.nonroot_pos i hi + have hj0 := F.nonroot_pos j hj + have hh := congrArg Fin.val he + change F.rootCount + (i.val - 1) = F.rootCount + (j.val - 1) at hh + apply Fin.ext + omega + +lemma birthIndex_lt (i j : Fin F.size) (hi : i ≠ F.root) (hj : j ≠ F.root) + (hij : i < j) : F.birthIndex i hi < F.birthIndex j hj := by + have hi0 := F.nonroot_pos i hi + change F.rootCount + (i.val - 1) < F.rootCount + (j.val - 1) + change i.val < j.val at hij + omega + +def callIndex (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : Fin F.size := + ⟨v.val - F.rootCount + 1, by + have hs := F.size_pos + have hvs := v.isLt + unfold vertexCount at hvs + omega⟩ + +lemma callIndex_nonroot (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + F.callIndex v hv ≠ F.root := by + intro he + have hh := congrArg Fin.val he + change v.val - F.rootCount + 1 = F.root.val at hh + rw [F.root_val] at hh + omega + +@[simp] lemma callIndex_birthIndex (i : Fin F.size) (hi : i ≠ F.root) : + F.callIndex (F.birthIndex i hi) (F.birthIndex_nonroot i hi) = i := by + apply Fin.ext + change F.rootCount + (i.val - 1) - F.rootCount + 1 = i.val + have hi0 := F.nonroot_pos i hi + omega + +@[simp] lemma birthIndex_callIndex (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + F.birthIndex (F.callIndex v hv) (F.callIndex_nonroot v hv) = v := by + apply Fin.ext + change F.rootCount + (v.val - F.rootCount + 1 - 1) = v.val + omega + +noncomputable def rootLabel (i : Fin F.rootCount) : Fin n := + ((F.rootSet.equivFin).symm i).val + +lemma rootLabel_mem (i : Fin F.rootCount) : F.rootLabel i ∈ F.rootSet := + ((F.rootSet.equivFin).symm i).property + +lemma rootLabel_injective : Function.Injective F.rootLabel := by + intro i j he + have hs : (F.rootSet.equivFin).symm i = (F.rootSet.equivFin).symm j := Subtype.ext he + exact (F.rootSet.equivFin).symm.injective hs + +lemma rootLabel_covers (x : Fin n) (hx : x ∈ F.rootSet) : + ∃ i : Fin F.rootCount, F.rootLabel i = x := by + refine ⟨F.rootSet.equivFin ⟨x,hx⟩,?_⟩ + exact congrArg Subtype.val (F.rootSet.equivFin.symm_apply_apply ⟨x,hx⟩) + +noncomputable def vertexLabel (v : Fin F.vertexCount) : Fin n := + if hv : v.val < F.rootCount then F.rootLabel ⟨v.val,hv⟩ + else F.newVertex (F.callIndex v (Nat.le_of_not_gt hv)) (F.callIndex_nonroot v _) + +lemma vertexLabel_root (v : Fin F.vertexCount) (hv : v.val < F.rootCount) : + F.vertexLabel v = F.rootLabel ⟨v.val,hv⟩ := dite_eq_left hv + +lemma vertexLabel_birth (i : Fin F.size) (hi : i ≠ F.root) : + F.vertexLabel (F.birthIndex i hi) = F.newVertex i hi := by + rw [vertexLabel,dite_eq_right (Nat.not_lt.mpr (F.birthIndex_nonroot i hi))] + simp only [callIndex_birthIndex] + +lemma vertexLabel_injective_roots : Set.InjOn F.vertexLabel {v | v.val < F.rootCount} := by + intro v hv w hw he + rw [F.vertexLabel_root v hv,F.vertexLabel_root w hw] at he + exact Fin.ext (congrArg (fun i : Fin F.rootCount => i.val) (F.rootLabel_injective he)) + +lemma vertexLabel_covers (e : Finset (Fin n)) (he : e ∈ c.focus) (x : Fin n) (hx : x ∈ e) : + ∃ v : Fin F.vertexCount, v.val < F.rootCount ∧ F.vertexLabel v = x := by + have hxr : x ∈ F.rootSet := Finset.mem_biUnion.mpr ⟨e,he,hx⟩ + obtain ⟨i,hi⟩ := F.rootLabel_covers x hxr + have hib : i.val < F.vertexCount := by + have hh := i.isLt + unfold vertexCount + omega + refine ⟨⟨i.val,hib⟩,i.isLt,?_⟩ + rw [F.vertexLabel_root _ i.isLt] + exact hi + +end SharpTerminalLeave.RecordedCallForest + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/SeedEdgeSubsetPath.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/SeedEdgeSubsetPath.lean new file mode 100644 index 0000000000000000000000000000000000000000..8276fc5bd5c32101db15233be2bce77d89e77f8c --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/SeedEdgeSubsetPath.lean @@ -0,0 +1,117 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PathPattern +import OAI.Combinatorics.TriangleRemoval.Embeddings.PathBirthIndex +import OAI.Combinatorics.TriangleRemoval.Process.RootClosers + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.TriangleGrowth +variable {n N R : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N R) + +lemma seed_edge_subset_pathUnion (a b : Fin N) {e : Finset (Fin N)} + (he : e ∈ A.seed.backEdges A.roots) : e ⊆ A.pathUnion a b := by + obtain ⟨v,hv,u,hu,rfl⟩ := A.seed.backEdges_mem_pair he + have hvR := (A.mem_roots v).mp hv + have huR := A.seed_root v u hu hvR + intro x hx + rcases Finset.mem_insert.mp hx with rfl | hx + · exact (A.mem_pathUnion a b x).mpr (Or.inl huR) + · have h := Finset.mem_singleton.mp hx + subst x + exact (A.mem_pathUnion a b v).mpr (Or.inl hvR) + +lemma pathRootEdges_card (a b : Fin N) : + (A.pathRootEdges a b).card = (A.seed.backEdges A.roots).card := by + classical + apply Finset.card_image_of_injOn + intro e he f hf h + exact reindexSet_inj (A.seed_edge_subset_pathUnion a b he) + (A.seed_edge_subset_pathUnion a b hf) h + +lemma pathPattern_rootEdges (a b : Fin N) (hR : R ≤ N) : + (A.pathPattern a b).backEdges (initialVertices (A.pathUnion a b).card R) = + A.pathRootEdges a b := by + classical + let S := A.pathUnion a b + have hroot : ∀ x : Fin N, x.val < R → x ∈ S := + fun x hx => (A.mem_pathUnion a b x).mpr (Or.inl hx) + ext e + constructor + · intro he + obtain ⟨v,hv,u,hu,rfl⟩ := (A.pathPattern a b).backEdges_mem_pair he + have hv' := (mem_initialVertices _ _ _).mp hv + have hvR : (S.orderEmbOfFin rfl v).val < R := by + rw [orderEmb_initial S hR hroot v hv'] + exact hv' + have hu' : S.orderEmbOfFin rfl u ∈ A.seed.older (S.orderEmbOfFin rfl v) := by + change u ∈ reindexSet S (A.older (S.orderEmbOfFin rfl v)) at hu + rw [mem_reindexSet] at hu + rwa [A.older_eq_seed hvR] at hu + have hem : ({S.orderEmbOfFin rfl u,S.orderEmbOfFin rfl v} : Finset (Fin N)) ∈ + A.seed.backEdges A.roots := + Finset.mem_biUnion.mpr ⟨_,(A.mem_roots _).mpr hvR,Finset.mem_image.mpr ⟨_,hu',rfl⟩⟩ + apply Finset.mem_image.mpr + refine ⟨_,hem,?_⟩ + rw [reindexSet_pair S _ _ (S.orderEmbOfFin_mem rfl u) (S.orderEmbOfFin_mem rfl v)] + simp only [PathForest.index_embed] + · intro he + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he + obtain ⟨v,hv,u,hu,rfl⟩ := A.seed.backEdges_mem_pair hf + have hvR := (A.mem_roots v).mp hv + have huR := A.seed_root v u hu hvR + have hvP := hroot v hvR + have huP := hroot u huR + rw [reindexSet_pair S u v huP hvP] + apply Finset.mem_biUnion.mpr + refine ⟨PathForest.index S v hvP,?_,Finset.mem_image.mpr + ⟨PathForest.index S u huP,?_,rfl⟩⟩ + · apply (mem_initialVertices _ _ _).mpr + change ((S.orderIsoOfFin rfl).symm ⟨v,hvP⟩).val < R + rw [initial_rank S hroot v hvR] + exact hvR + · change PathForest.index S u huP ∈ + reindexSet S (A.older (S.orderEmbOfFin rfl (PathForest.index S v hvP))) + rw [mem_reindexSet] + rw [PathForest.embed_index,PathForest.embed_index,A.older_eq_seed hvR] + exact hu + +lemma pathPattern_root_small (a b : Fin N) (hR : R ≤ N) + (v : Fin (A.pathUnion a b).card) (hv : v.val < R) : + ((A.pathPattern a b).older v).card ≤ 1 := by + rw [pathPattern,BirthGraph.restrict_older_card] + have hvR : ((A.pathUnion a b).orderEmbOfFin rfl v).val < R := by + rw [orderEmb_initial _ hR (fun x hx => (A.mem_pathUnion a b x).mpr (Or.inl hx)) v hv] + exact hv + change (A.older _).card ≤ 1 + rw [A.older_eq_seed hvR] + exact A.seed_small _ hvR + +lemma pathPattern_rootClosers (a b : Fin N) (hR : R ≤ N) : + ((A.pathPattern a b).rootClosers R).card = (A.seed.backEdges A.roots).card := by + rw [(A.pathPattern a b).rootClosers_card R (A.pathPattern_root_small a b hR), + A.pathPattern_rootEdges a b hR,A.pathRootEdges_card] + +lemma path_mark_reaches_suffix (a b : Fin N) (k : ℕ) + (hR : R ≤ k) (hk : k < (A.pathUnion a b).card) : + k ≤ (A.pathIndex a b a (A.left_mem_pathUnion a b)).val ∨ + k ≤ (A.pathIndex a b b (A.right_mem_pathUnion a b)).val := by + have hc := A.pathPattern_covered a b k hR hk ⟨k,hk⟩ + (Finset.mem_filter.mpr ⟨Finset.mem_univ _,le_refl _⟩) + rcases hc with ⟨ha,_⟩ | ⟨hb,_⟩ + · exact Or.inl (Finset.mem_filter.mp ha).2 + · exact Or.inr (Finset.mem_filter.mp hb).2 + +end SharpTerminalLeave.TriangleGrowth + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/SparseScalingOne.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/SparseScalingOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..a499ef1d18f37794c86bff31e0d020891b487f09 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/SparseScalingOne.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEpsilon + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma sparse_scaling_ge_one (n : ℕ) (p : ℝ) (hp : 0 ≤ p) (hp1 : p ≤ 1) + (hD : 1 ≤ (n : ℝ) * p ^ 2) (v e : ℕ) (he : e ≤ 2 * v) : + 1 ≤ (n : ℝ) ^ v * p ^ e := by + calc + 1 ≤ ((n : ℝ) * p ^ 2) ^ v := one_le_pow₀ hD + _ = (n : ℝ) ^ v * p ^ (2 * v) := by rw [mul_pow,pow_mul] + _ ≤ _ := mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one hp hp1 he) (by positivity) + +theorem largeTemplateEligible_of_sparse {k n : ℕ} (T : RootedTemplate k) + (hroots : T.roots = ∅) (p : ℝ) (hp : 0 ≤ p) (hp1 : p ≤ 1) + (hD : 1 ≤ (n : ℝ) * p ^ 2) + (hs : ∀ W : Finset (Fin k), (T.edges.filter (· ⊆ W)).card ≤ 2 * W.card) : + largeTemplateEligible T n p := by + intro W _ F hF hFW + have hsub : F ⊆ T.edges.filter (· ⊆ W) := by + intro e he + exact Finset.mem_filter.mpr ⟨hF he,hFW e he⟩ + have hcount := (Finset.card_le_card hsub).trans (hs W) + simpa only [hroots,Finset.card_empty,Nat.sub_zero] using + sparse_scaling_ge_one n p hp hp1 hD W.card F.card hcount + +theorem smallTemplateEligible_of_sparse {k n : ℕ} (T : RootedTemplate k) (p : ℝ) + (hp : 0 ≤ p) (hp1 : p ≤ 1) (hD : 1 ≤ (n : ℝ) * p ^ 2) + (htotal : (n : ℝ) ^ (k - T.roots.card) * p ^ T.edges.card ≤ 1) + (hs : ∀ J : Finset (Fin k), T.roots ⊆ J → J ≠ Finset.univ → + (T.edges.filter (· ⊆ J)).card ≤ 2 * (J.card - T.roots.card)) : + smallTemplateEligible T n p := by + intro J hJ + by_cases hfull : J = Finset.univ + · subst J + simp only [Finset.subset_univ,Finset.filter_true,Finset.card_univ,Fintype.card_fin, + Nat.sub_self,pow_zero,mul_one,le_refl] + · have hI : T.roots.card ≤ J.card := Finset.card_le_card hJ + have hJk : J.card ≤ k := by simpa only [Fintype.card_fin] using J.card_le_univ + have hE : (T.edges.filter (· ⊆ J)).card ≤ T.edges.card := + Finset.card_le_card (Finset.filter_subset _ _) + have hden := sparse_scaling_ge_one n p hp hp1 hD + (J.card - T.roots.card) (T.edges.filter (· ⊆ J)).card (hs J hJ hfull) + have hid : + ((n : ℝ) ^ (k - J.card) * p ^ (T.edges.card - (T.edges.filter (· ⊆ J)).card)) * + ((n : ℝ) ^ (J.card - T.roots.card) * p ^ (T.edges.filter (· ⊆ J)).card) = + (n : ℝ) ^ (k - T.roots.card) * p ^ T.edges.card := by + rw [mul_mul_mul_comm,← pow_add,← pow_add] + congr 2 <;> omega + have hnon : 0 ≤ (n : ℝ) ^ (k - J.card) * + p ^ (T.edges.card - (T.edges.filter (· ⊆ J)).card) := by positivity + calc + _ ≤ ((n : ℝ) ^ (k - J.card) * p ^ (T.edges.card - (T.edges.filter (· ⊆ J)).card)) * + ((n : ℝ) ^ (J.card - T.roots.card) * p ^ (T.edges.filter (· ⊆ J)).card) := + le_mul_of_one_le_right hnon hden + _ = _ := hid + _ ≤ 1 := htotal + +end SharpTerminalLeave + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/SuffixBoundary.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/SuffixBoundary.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e80828bbdf04f6cfd9cfc21d7c34ca5c4752ba2 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/SuffixBoundary.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Process.BornEdges + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N : ℕ} (B : BirthGraph N) + +def suffixBoundary (Z : Finset (Fin N)) (a b : Fin N) : Finset (Fin N) := + ((Z.biUnion B.older) ∪ {a,b}) \ Z + +def suffixVertices (Z : Finset (Fin N)) (a b : Fin N) : Finset (Fin N) := + Z ∪ B.suffixBoundary Z a b + +def suffixEdges (Z : Finset (Fin N)) (a b : Fin N) : Finset (Finset (Fin N)) := + insert {a,b} (B.backEdges Z) + +lemma suffixBoundary_disjoint (Z : Finset (Fin N)) (a b : Fin N) : + Disjoint (B.suffixBoundary Z a b) Z := Finset.sdiff_disjoint + +lemma mem_suffixBoundary (Z : Finset (Fin N)) (a b x : Fin N) : + x ∈ B.suffixBoundary Z a b ↔ + ((∃ v ∈ Z, x ∈ B.older v) ∨ x = a ∨ x = b) ∧ x ∉ Z := by + simp only [suffixBoundary,Finset.mem_sdiff,Finset.mem_union,Finset.mem_biUnion, + Finset.mem_insert,Finset.mem_singleton] + +lemma suffixBoundary_card {Z : Finset (Fin N)} {a b : Fin N} (hmark : a ∈ Z ∨ b ∈ Z) : + (B.suffixBoundary Z a b).card ≤ 2 * Z.card + 1 := by + have hbase : (Z.biUnion B.older).card ≤ 2 * Z.card := by + calc + _ ≤ ∑ v ∈ Z, (B.older v).card := Finset.card_biUnion_le + _ ≤ ∑ _v ∈ Z, 2 := Finset.sum_le_sum (fun v _ => B.older_card v) + _ = _ := by simp [mul_comm] + have hbound (x y : Fin N) (hx : x ∈ Z) : + (((Z.biUnion B.older) ∪ {x,y}) \ Z).card ≤ 2 * Z.card + 1 := by + have hs : ((Z.biUnion B.older) ∪ {x,y}) \ Z ⊆ insert y (Z.biUnion B.older) := by + intro z hz + obtain ⟨hz,hzn⟩ := Finset.mem_sdiff.mp hz + rcases Finset.mem_union.mp hz with hz | hz + · exact Finset.mem_insert_of_mem hz + · rcases Finset.mem_insert.mp hz with rfl | hz + · exact False.elim (hzn hx) + · exact Finset.mem_insert.mpr (Or.inl (Finset.mem_singleton.mp hz)) + exact (Finset.card_le_card hs).trans ((Finset.card_insert_le _ _).trans (Nat.add_le_add_right hbase 1)) + rcases hmark with ha | hb + · exact hbound a b ha + · simpa only [suffixBoundary,Finset.pair_comm a b] using hbound b a hb + +lemma suffixVertices_card {Z : Finset (Fin N)} {a b : Fin N} (hmark : a ∈ Z ∨ b ∈ Z) : + (B.suffixVertices Z a b).card ≤ 3 * Z.card + 1 := by + unfold suffixVertices + have hh := (Finset.card_union_le Z (B.suffixBoundary Z a b)).trans + (Nat.add_le_add_left (B.suffixBoundary_card hmark) Z.card) + omega + +lemma suffixEdges_simple {Z : Finset (Fin N)} {a b : Fin N} (hab : a ≠ b) : + ∀ e ∈ B.suffixEdges Z a b, e.card = 2 := by + intro e he + rcases Finset.mem_insert.mp he with rfl | he + · exact Finset.card_pair hab + · obtain ⟨v,_,u,hu,rfl⟩ := B.backEdges_mem_pair he + exact Finset.card_pair (ne_of_lt (B.older_lt v u hu)) + +lemma suffixEdges_subset_vertices {Z : Finset (Fin N)} {a b : Fin N} : + ∀ e ∈ B.suffixEdges Z a b, e ⊆ B.suffixVertices Z a b := by + intro e he x hx + apply Finset.mem_union.mpr + by_cases hxZ : x ∈ Z + · exact Or.inl hxZ + · apply Or.inr + apply (B.mem_suffixBoundary Z a b x).mpr + refine ⟨?_,hxZ⟩ + rcases Finset.mem_insert.mp he with rfl | he + · exact Or.inr (by simpa only [Finset.mem_insert,Finset.mem_singleton] using hx) + · obtain ⟨v,hv,u,hu,rfl⟩ := B.backEdges_mem_pair he + rcases Finset.mem_insert.mp hx with rfl | hx + · exact Or.inl ⟨v,hv,hu⟩ + · exact False.elim (hxZ (Finset.mem_singleton.mp hx ▸ hv)) + +lemma suffixEdges_touch {Z : Finset (Fin N)} {a b : Fin N} (hmark : a ∈ Z ∨ b ∈ Z) : + ∀ e ∈ B.suffixEdges Z a b, ∃ v ∈ e, v ∈ Z := by + intro e he + rcases Finset.mem_insert.mp he with rfl | he + · rcases hmark with ha | hb + · exact ⟨a,by simp,ha⟩ + · exact ⟨b,by simp,hb⟩ + · obtain ⟨v,hv,u,_,rfl⟩ := B.backEdges_mem_pair he + exact ⟨v,by simp,hv⟩ + +lemma suffixBoundary_independent {Z : Finset (Fin N)} {a b : Fin N} + (hmark : a ∈ Z ∨ b ∈ Z) : + ∀ e ∈ B.suffixEdges Z a b, ¬ e ⊆ B.suffixBoundary Z a b := by + intro e he hs + obtain ⟨v,hve,hvZ⟩ := B.suffixEdges_touch hmark e he + exact Finset.disjoint_left.mp (B.suffixBoundary_disjoint Z a b) (hs hve) hvZ + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/SuffixProjection.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/SuffixProjection.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c3e01fba88373d4f8018d6edc450f5e0ae4fe51 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/SuffixProjection.lean @@ -0,0 +1,102 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Process.RestrictedParent +import OAI.Combinatorics.TriangleRemoval.Coupling.OrderedSuffix +import OAI.Combinatorics.TriangleRemoval.Queries.MarkedIndexedAttachmentPattern +import OAI.Combinatorics.TriangleRemoval.Embeddings.PathBirthIndex + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def suffixProjection {K R s : ℕ} (hK : K = R+s) (i : Fin K) : Option (Fin s) := + if h : R ≤ i.val then some ⟨i.val-R,by omega⟩ else none + +lemma suffix_projection_embedding {N R : ℕ} (S : Finset (Fin N)) (hR : R ≤ N) + (hroot : ∀ x : Fin N, x.val < R → x ∈ S) (x : Fin N) (hx : x ∈ S) : + suffixProjection (prefix_suffix_card S hR hroot) (PathForest.index S x hx) = + PathForest.restrictMark (orderedSuffix S R) x := by + classical + by_cases hn : R ≤ x.val + · have hxT : x ∈ orderedSuffix S R := Finset.mem_filter.mpr ⟨hx,hn⟩ + let i := PathForest.index (orderedSuffix S R) x hxT + have hs : PathForest.index S x hx = suffixFullIndex S hR hroot i := by + apply (S.orderEmbOfFin rfl).injective + rw [PathForest.embed_index,suffix_full_embedding] + exact (PathForest.embed_index _ _ _).symm + have hiv : (PathForest.index S x hx).val = R+i.val := by rw [hs]; rfl + rw [PathForest.restrictMark,dite_eq_left hxT] + unfold suffixProjection + rw [dite_eq_left (show R ≤ (PathForest.index S x hx).val by omega)] + apply congrArg some + apply Fin.ext + simp only [hiv] + exact Nat.add_sub_cancel_left R i.val + · have hxT : x ∉ orderedSuffix S R := by simpa only [orderedSuffix,Finset.mem_filter,hx,true_and] using hn + have hiv : (PathForest.index S x hx).val = x.val := initial_rank S hroot x (by omega) + rw [PathForest.restrictMark,dite_eq_right hxT] + unfold suffixProjection + rw [dite_eq_right (show ¬ R ≤ (PathForest.index S x hx).val by omega)] + +namespace TriangleGrowth +variable {n N R : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N R) + +lemma path_card_split (a b : Fin N) (hR : R ≤ N) : + (A.pathUnion a b).card = R+(A.pathSuffix a b R).card := + prefix_suffix_card _ hR (fun x hx => (A.mem_pathUnion a b x).mpr (Or.inl hx)) + +lemma path_mark_projection (a b : Fin N) (hR : R ≤ N) + (x : Fin N) (hx : x ∈ A.pathUnion a b) : + suffixProjection (A.path_card_split a b hR) (A.pathIndex a b x hx) = + PathForest.restrictMark (A.pathSuffix a b R) x := + suffix_projection_embedding _ hR + (fun y hy => (A.mem_pathUnion a b y).mpr (Or.inl hy)) x hx + +open Classical in + +noncomputable def pathWitnessCode (a b : Fin N) (hR : R ≤ N) : + Σ ab : Fin (A.pathUnion a b).card × Fin (A.pathUnion a b).card, + Σ F : {F : PathForest (A.pathSuffix a b R).card // ∀ i, + F.OnPath (suffixProjection (A.path_card_split a b hR) ab.1) i ∨ + F.OnPath (suffixProjection (A.path_card_split a b hR) ab.2) i}, + {f // f ∈ indexedAttachmentFamily (A.pathRootEdges a b) (A.pathBirthIndex a b hR) F.val} := by + refine ⟨⟨A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)⟩,⟨A.pathForest a b,?_⟩, + A.pathAttachments a b hR,?_⟩ + · rw [A.path_mark_projection a b hR a (A.left_mem_pathUnion a b), + A.path_mark_projection a b hR b (A.right_mem_pathUnion a b)] + exact A.pathForest_two_path_cover a b + · exact (mem_indexedAttachmentFamily _ _ _ _).mpr (A.pathAttachments_valid a b hR) + +lemma pathRootEdges_count (a b : Fin N) : + (A.pathRootEdges a b).card ≤ (A.seed.backEdges A.roots).card := Finset.card_image_le + +open Classical in + +theorem path_witness_code_count (a b : Fin N) (hR : R ≤ N) + (hE : (A.seed.backEdges A.roots).card ≤ 2) : + Fintype.card (Σ ab : Fin (A.pathUnion a b).card × Fin (A.pathUnion a b).card, + Σ F : {F : PathForest (A.pathSuffix a b R).card // ∀ i, + F.OnPath (suffixProjection (A.path_card_split a b hR) ab.1) i ∨ + F.OnPath (suffixProjection (A.path_card_split a b hR) ab.2) i}, + {f // f ∈ indexedAttachmentFamily (A.pathRootEdges a b) (A.pathBirthIndex a b hR) F.val}) ≤ + (R+(A.pathSuffix a b R).card)^2 * 6^(A.pathSuffix a b R).card := by + simpa only [Fintype.card_fin,A.path_card_split a b hR] using + all_marked_indexed_attachment_pattern_count (A.pathRootEdges a b) (A.pathBirthIndex a b hR) + ((A.pathRootEdges_count a b).trans hE) (suffixProjection (A.path_card_split a b hR)) + +end TriangleGrowth +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TerminalLaw.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TerminalLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..736f2c2ccf882383748f67ee625fdbd4c4f48a68 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TerminalLaw.lean @@ -0,0 +1,174 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Model + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +@[simp] theorem card_completeGraph (n : ℕ) : (completeGraph n).card = n.choose 2 := by + simp [completeGraph, Finset.card_powersetCard] + +@[simp] theorem mem_completeGraph {n : ℕ} {e : Finset (Fin n)} : + e ∈ completeGraph n ↔ e.card = 2 := by + simp [completeGraph, Finset.mem_powersetCard] + +@[simp] theorem mem_triangles {n : ℕ} {G : Graph n} {t : Finset (Fin n)} : + t ∈ triangles G ↔ t.card = 3 ∧ t.powersetCard 2 ⊆ G := by + simp [triangles, Finset.mem_powersetCard] + +theorem triangles_mono {n : ℕ} {G H : Graph n} (h : H ⊆ G) : + triangles H ⊆ triangles G := by + intro t ht + obtain ⟨hc, he⟩ := mem_triangles.mp ht + exact mem_triangles.mpr ⟨hc, he.trans h⟩ + +theorem triangle_edge_card {n : ℕ} {G : Graph n} {t : Finset (Fin n)} + (ht : t ∈ triangles G) : (t.powersetCard 2).card = 3 := by + rw [Finset.card_powersetCard, (mem_triangles.mp ht).1] + decide + +theorem three_le_card_of_triangle {n : ℕ} {G : Graph n} + (h : (triangles G).Nonempty) : 3 ≤ G.card := by + obtain ⟨t, ht⟩ := h + have hc := Finset.card_le_card (mem_triangles.mp ht).2 + rwa [triangle_edge_card ht] at hc + +theorem step_support_active {n : ℕ} {G H : Graph n} + (h : (triangles G).Nonempty) : + H ∈ (step G).support ↔ ∃ t ∈ triangles G, G \ t.powersetCard 2 = H := by + simp only [step, dite_eq_left h, PMF.mem_support_map_iff, + PMF.mem_support_uniformOfFinset_iff] + +theorem step_absorbing {n : ℕ} {G : Graph n} (h : triangles G = ∅) : + step G = PMF.pure G := by + simp [step, h] + +theorem step_support_subset {n : ℕ} {G H : Graph n} (h : H ∈ (step G).support) : + H ⊆ G := by + by_cases hG : (triangles G).Nonempty + · obtain ⟨t, _, rfl⟩ := (step_support_active hG).mp h + exact Finset.sdiff_subset + · simp only [step, dite_eq_right hG, PMF.mem_support_pure_iff] at h + exact h ▸ Finset.Subset.refl G + +theorem step_card_of_active {n : ℕ} {G H : Graph n} + (hG : (triangles G).Nonempty) (h : H ∈ (step G).support) : + H.card + 3 = G.card := by + obtain ⟨t, ht, rfl⟩ := (step_support_active hG).mp h + have hc := Finset.card_sdiff_add_card_eq_card (mem_triangles.mp ht).2 + rwa [triangle_edge_card ht] at hc + +theorem evolve_support_subset {n : ℕ} (G : Graph n) (k : ℕ) {H : Graph n} + (h : H ∈ (evolve G k).support) : H ⊆ G := by + induction k generalizing H with + | zero => + simp only [evolve, PMF.mem_support_pure_iff] at h + exact h ▸ Finset.Subset.refl G + | succ k ih => + obtain ⟨J, hJ, hH⟩ := (PMF.mem_support_bind_iff _ _ _).mp h + exact (step_support_subset hH).trans (ih hJ) + +theorem evolve_card_of_active {n : ℕ} (G : Graph n) (k : ℕ) {H : Graph n} + (h : H ∈ (evolve G k).support) (hH : (triangles H).Nonempty) : + H.card + 3 * k = G.card := by + induction k generalizing H with + | zero => + simp only [evolve, PMF.mem_support_pure_iff] at h + simp [h] + | succ k ih => + obtain ⟨J, hJ, hstep⟩ := (PMF.mem_support_bind_iff _ _ _).mp h + have hJs : (triangles J).Nonempty := + hH.mono (triangles_mono (step_support_subset hstep)) + have hprev := ih hJ hJs + have hcard := step_card_of_active hJs hstep + omega + +theorem evolve_terminal {n : ℕ} (G : Graph n) (k : ℕ) (hk : G.card ≤ k) + {H : Graph n} (h : H ∈ (evolve G k).support) : triangles H = ∅ := by + apply Finset.not_nonempty_iff_eq_empty.mp + intro hH + have hcard := evolve_card_of_active G k h hH + have hthree := three_le_card_of_triangle hH + omega + +theorem terminal_support_subset {n : ℕ} {G : Graph n} + (h : G ∈ (terminalLaw n).support) : G ⊆ completeGraph n := + evolve_support_subset _ _ h + +theorem terminal_edges_have_two_vertices {n : ℕ} {G : Graph n} + (h : G ∈ (terminalLaw n).support) {e : Finset (Fin n)} (he : e ∈ G) : + e.card = 2 := + mem_completeGraph.mp (terminal_support_subset h he) + +theorem terminal_triangle_free {n : ℕ} {G : Graph n} + (h : G ∈ (terminalLaw n).support) : triangles G = ∅ := by + exact evolve_terminal (completeGraph n) (n.choose 2) (by simp) h + +theorem terminal_card_le {n : ℕ} {G : Graph n} + (h : G ∈ (terminalLaw n).support) : G.card ≤ n.choose 2 := by + simpa using Finset.card_le_card (terminal_support_subset h) + +theorem delete_triangle_injective {n : ℕ} {G : Graph n} + {t u : Finset (Fin n)} (ht : t ∈ triangles G) (hu : u ∈ triangles G) + (h : G \ t.powersetCard 2 = G \ u.powersetCard 2) : t = u := by + have hedges : t.powersetCard 2 = u.powersetCard 2 := by + simpa only [Finset.sdiff_sdiff_eq_self (mem_triangles.mp ht).2, + Finset.sdiff_sdiff_eq_self (mem_triangles.mp hu).2] using + congrArg (fun J => G \ J) h + exact Finset.eq_of_powersetCard_eq + ((mem_triangles.mp ht).1.trans (mem_triangles.mp hu).1.symm) + (by decide) (by rw [(mem_triangles.mp ht).1]; decide) hedges + +theorem step_uniform_triangle {n : ℕ} {G : Graph n} {t : Finset (Fin n)} + (ht : t ∈ triangles G) : + step G (G \ t.powersetCard 2) = ((triangles G).card : ENNReal)⁻¹ := by + classical + have hG : (triangles G).Nonempty := ⟨t, ht⟩ + rw [step, dite_eq_left hG, PMF.map_apply] + rw [tsum_eq_single t] + · simpa using PMF.uniformOfFinset_apply_of_mem hG ht + · intro u hut + by_cases hu : u ∈ triangles G + · have hne : G \ t.powersetCard 2 ≠ G \ u.powersetCard 2 := by + intro heq + exact hut (delete_triangle_injective ht hu heq).symm + simp [hne] + · simp only [PMF.uniformOfFinset_apply_of_notMem hG hu, ite_self] + +@[simp] theorem evolve_absorbing {n : ℕ} (G : Graph n) + (hG : triangles G = ∅) (k : ℕ) : evolve G k = PMF.pure G := by + induction k with + | zero => rfl + | succ k ih => simp [evolve, ih, step_absorbing hG] + +theorem evolve_add {n : ℕ} (G : Graph n) (k l : ℕ) : + evolve G (k + l) = (evolve G k).bind (fun H => evolve H l) := by + induction l with + | zero => simp [evolve] + | succ l ih => simp [evolve, ih, PMF.bind_bind] + +theorem evolve_stable {n : ℕ} (G : Graph n) (k l : ℕ) (hk : G.card ≤ k) : + evolve G (k + l) = evolve G k := by + rw [evolve_add] + conv_rhs => rw [← PMF.bind_pure (evolve G k)] + apply PMF.ext + intro H + simp only [PMF.bind_apply] + apply tsum_congr + intro J + by_cases hJ : J ∈ (evolve G k).support + · rw [evolve_absorbing J (evolve_terminal G k hk hJ)] + · have hz : evolve G k J = 0 := by + simpa only [PMF.mem_support_iff, not_not] using hJ + simp [hz] + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ThreeChooseBound.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ThreeChooseBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..05733d0a863ced71d9576b0f20cc71d2ec3254a9 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ThreeChooseBound.lean @@ -0,0 +1,62 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma three_choose_bound (h a b : ℕ) : + (h+a+b).choose h * (a+b).choose a ≤ 3^(h+a+b) := by + have hb := Nat.choose_le_two_pow (a+b) a + have hh := Nat.mul_le_mul_left ((h+a+b).choose h) hb + have ht := Finset.single_le_sum (s := Finset.range (h+a+b+1)) + (f := fun j => (1 : ℕ)^j*2^(h+a+b-j)*(h+a+b).choose j) + (fun _ _ => Nat.zero_le _) (Finset.mem_range.mpr (show h < h+a+b+1 by omega)) + have he : h+a+b-h = a+b := by omega + have hsum : (∑ j ∈ Finset.range (h+a+b+1), + (1 : ℕ)^j*2^(h+a+b-j)*(h+a+b).choose j) = 3^(h+a+b) := by + simpa only [Nat.cast_id] using (add_pow (1 : ℕ) 2 (h+a+b)).symm + rw [hsum,he] at ht + exact hh.trans (by simpa only [one_pow,one_mul,Nat.mul_comm] using ht) + +lemma three_factorial_bound (h a b : ℕ) : + (h+a+b).factorial ≤ 3^(h+a+b) * (h.factorial*a.factorial*b.factorial) := by + have hbc := Nat.choose_mul_factorial_mul_factorial (show a ≤ a+b by omega) + have hha := Nat.choose_mul_factorial_mul_factorial (show h ≤ h+a+b by omega) + have hsub1 : a+b-a = b := by omega + have hsub2 : h+a+b-h = a+b := by omega + rw [hsub1] at hbc + rw [hsub2] at hha + have hi : (h+a+b).choose h * (a+b).choose a * + (h.factorial*a.factorial*b.factorial) = (h+a+b).factorial := by + calc + _ = (h+a+b).choose h * h.factorial * + ((a+b).choose a * a.factorial * b.factorial) := by ring + _ = _ := by rw [hbc,hha] + rw [← hi] + exact Nat.mul_le_mul_right _ (three_choose_bound h a b) + +theorem total_three_segment_weight_le {x : ℝ} (hx : 0 ≤ x) (h a b : ℕ) : + x^(h+a+b) / ((h.factorial : ℝ)*(a.factorial : ℝ)*(b.factorial : ℝ)) ≤ + (3*x)^(h+a+b) / ((h+a+b).factorial : ℝ) := by + have hf : ((h+a+b).factorial : ℝ) ≤ + (3 : ℝ)^(h+a+b)*((h.factorial : ℝ)*(a.factorial : ℝ)*(b.factorial : ℝ)) := by + exact_mod_cast three_factorial_bound h a b + have hh := mul_le_mul_of_nonneg_left hf (pow_nonneg hx (h+a+b)) + apply (div_le_div_iff₀ (by positivity) (by positivity)).mpr + rw [mul_pow] + nlinarith only [hh] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleDegreeMean.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleDegreeMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c798b6543b8181dce00888ea8c7ca8770bb4d1f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleDegreeMean.lean @@ -0,0 +1,275 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.TriangleDrift + +namespace OAI + +section +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma triangles_delete_eq_sdiff_hitting {n : ℕ} (G : Graph n) (t : Finset (Fin n)) : + triangles (G \ t.powersetCard 2) = triangles G \ hittingTriangles G (t.powersetCard 2) := by + ext u + simp only [mem_triangles, hittingTriangles, Finset.mem_sdiff, Finset.mem_filter] + constructor + · rintro ⟨hu,hs⟩ + refine ⟨⟨hu, fun e he => (Finset.mem_sdiff.mp (hs he)).1⟩, ?_⟩ + rintro ⟨_,hd⟩ + apply hd + apply Finset.disjoint_left.mpr + intro e het heu + exact (Finset.mem_sdiff.mp (hs heu)).2 het + · rintro ⟨⟨hu,hs⟩,hn⟩ + refine ⟨hu, ?_⟩ + intro e he + refine Finset.mem_sdiff.mpr ⟨hs he, ?_⟩ + intro het + apply hn + refine ⟨⟨hu,hs⟩, ?_⟩ + exact fun hd => Finset.disjoint_left.mp hd het he + +lemma triangle_edge_inter_card_le_one {n : ℕ} {G : Graph n} + {t u : Finset (Fin n)} (ht : t ∈ triangles G) (hu : u ∈ triangles G) + (hne : t ≠ u) : (t.powersetCard 2 ∩ u.powersetCard 2).card ≤ 1 := by + apply Finset.card_le_one.mpr + intro e he f hf + by_contra hef + apply hne + have he' := Finset.mem_inter.mp he + have hf' := Finset.mem_inter.mp hf + exact triangle_eq_of_two_edges (mem_triangles.mp ht).1 (mem_triangles.mp hu).1 + (Finset.mem_powersetCard.mp he'.1).2 (Finset.mem_powersetCard.mp hf'.1).2 hef + (Finset.mem_powersetCard.mp he'.1).1 (Finset.mem_powersetCard.mp hf'.1).1 + (Finset.mem_powersetCard.mp he'.2).1 (Finset.mem_powersetCard.mp hf'.2).1 + +lemma triangle_incidence_swap {n : ℕ} (G : Graph n) (f : Finset (Fin n) → ℝ) : + (∑ t ∈ triangles G, ∑ e ∈ t.powersetCard 2, f e) = + ∑ e ∈ G, (triangleDegree G e : ℝ) * f e := by + classical + calc + _ = ∑ t ∈ triangles G, ∑ e ∈ G, if e ∈ t.powersetCard 2 then f e else 0 := by + apply Finset.sum_congr rfl + intro t ht + rw [← Finset.sum_filter] + congr 1 + ext e + simp only [Finset.mem_filter] + exact ⟨fun he => ⟨(mem_triangles.mp ht).2 he,he⟩, fun he => he.2⟩ + _ = ∑ e ∈ G, ∑ t ∈ triangles G, if e ∈ t.powersetCard 2 then f e else 0 := + Finset.sum_comm + _ = _ := by + apply Finset.sum_congr rfl + intro e he + rw [← Finset.sum_filter] + simp [triangleDegree, incidentTriangles, mul_comm] + +lemma triangle_degree_sum {n : ℕ} (G : Graph n) : + (∑ e ∈ G, (triangleDegree G e : ℝ)) = 3 * (triangles G).card := by + have h := triangle_incidence_swap G (fun _ => (1 : ℝ)) + simp only [mul_one, Finset.sum_const, nsmul_eq_mul] at h + calc + _ = ∑ t ∈ triangles G, ((t.powersetCard 2).card : ℝ) := h.symm + _ = ∑ _t ∈ triangles G, (3 : ℝ) := by + apply Finset.sum_congr rfl + intro t ht + rw [triangle_edge_card ht] + norm_num + _ = _ := by simp; ring + +lemma triangle_incidence_sum_on {n : ℕ} (G F : Graph n) : + (∑ e ∈ F, (triangleDegree G e : ℝ)) = + ∑ t ∈ triangles G, ((F ∩ t.powersetCard 2).card : ℝ) := by + classical + have he (e : Finset (Fin n)) : (triangleDegree G e : ℝ) = + ∑ t ∈ triangles G, if e ∈ t.powersetCard 2 then (1 : ℝ) else 0 := by + simp [triangleDegree, incidentTriangles, Finset.sum_boole] + simp_rw [he] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro t ht + simp only [Finset.sum_boole] + congr 1 + +lemma triangle_hit_multiplicity {n : ℕ} {G : Graph n} {t u : Finset (Fin n)} + (ht : t ∈ triangles G) (hu : u ∈ triangles G) : + ((t.powersetCard 2 ∩ u.powersetCard 2).card : ℝ) = + (if u ∈ hittingTriangles G (t.powersetCard 2) then 1 else 0) + + (if u = t then 2 else 0) := by + classical + by_cases hut : u = t + · subst u + have hhit : t ∈ hittingTriangles G (t.powersetCard 2) := by + apply Finset.mem_filter.mpr + refine ⟨ht, ?_⟩ + intro hd + have hzero : t.powersetCard 2 = ∅ := disjoint_self.mp hd + have hc := triangle_edge_card ht + rw [hzero,Finset.card_empty] at hc + omega + norm_num [hhit, triangle_edge_card ht] + · by_cases hhit : u ∈ hittingTriangles G (t.powersetCard 2) + · have hnon : (t.powersetCard 2 ∩ u.powersetCard 2).Nonempty := by + exact Finset.not_disjoint_iff_nonempty_inter.mp (Finset.mem_filter.mp hhit).2 + have hcard : (t.powersetCard 2 ∩ u.powersetCard 2).card = 1 := by + exact Nat.le_antisymm (triangle_edge_inter_card_le_one ht hu (Ne.symm hut)) + (Finset.one_le_card.mpr hnon) + simp [hhit,hut,hcard] + · have hd : Disjoint (t.powersetCard 2) (u.powersetCard 2) := by + by_contra hn + exact hhit (Finset.mem_filter.mpr ⟨hu,hn⟩) + simp [hhit,hut,Finset.disjoint_iff_inter_eq_empty.mp hd] + +theorem triangle_hitting_card_exact {n : ℕ} {G : Graph n} {t : Finset (Fin n)} + (ht : t ∈ triangles G) : + ((hittingTriangles G (t.powersetCard 2)).card : ℝ) = + (∑ e ∈ t.powersetCard 2, (triangleDegree G e : ℝ)) - 2 := by + classical + rw [triangle_incidence_sum_on] + have hm : (∑ u ∈ triangles G, ((t.powersetCard 2 ∩ u.powersetCard 2).card : ℝ)) = + ((hittingTriangles G (t.powersetCard 2)).card : ℝ) + 2 := by + calc + _ = ∑ u ∈ triangles G, + ((if u ∈ hittingTriangles G (t.powersetCard 2) then (1 : ℝ) else 0) + + (if u = t then 2 else 0)) := by + apply Finset.sum_congr rfl + exact fun u hu => triangle_hit_multiplicity ht hu + _ = _ := by + rw [Finset.sum_add_distrib] + simp only [Finset.sum_boole,Finset.sum_ite_eq',ht,ite_true] + have hf : (triangles G).filter (fun u => u ∈ hittingTriangles G (t.powersetCard 2)) = + hittingTriangles G (t.powersetCard 2) := by + ext u + simp only [hittingTriangles,Finset.mem_filter] + tauto + rw [hf] + linarith + +theorem triangle_count_delete {n : ℕ} {G : Graph n} {t : Finset (Fin n)} + (ht : t ∈ triangles G) : + ((triangles (G \ t.powersetCard 2)).card : ℝ) = + (triangles G).card - (∑ e ∈ t.powersetCard 2, (triangleDegree G e : ℝ)) + 2 := by + have hsub : hittingTriangles G (t.powersetCard 2) ⊆ triangles G := Finset.filter_subset _ _ + rw [triangles_delete_eq_sdiff_hitting,Finset.card_sdiff_of_subset hsub, + Nat.cast_sub (Finset.card_le_card hsub), triangle_hitting_card_exact ht] + ring + +theorem step_mean_triangle_count {n : ℕ} {G : Graph n} + (hQ : (triangles G).Nonempty) : + pmfMean (step G) (fun H => ((triangles H).card : ℝ)) = + (triangles G).card - (∑ e ∈ G, (triangleDegree G e : ℝ)^2) / + (triangles G).card + 2 := by + classical + rw [step_mean G _ hQ] + have he : (∑ t ∈ triangles G, ((triangles (G \ t.powersetCard 2)).card : ℝ)) = + (triangles G).card * ((triangles G).card + 2 : ℝ) - + ∑ e ∈ G, (triangleDegree G e : ℝ)^2 := by + calc + _ = ∑ t ∈ triangles G, (((triangles G).card : ℝ) + 2 - + ∑ e ∈ t.powersetCard 2, (triangleDegree G e : ℝ)) := by + apply Finset.sum_congr rfl + intro t ht + rw [triangle_count_delete ht] + ring + _ = _ := by + rw [Finset.sum_sub_distrib,triangle_incidence_swap] + simp only [Finset.sum_add_distrib, Finset.sum_const, nsmul_eq_mul, pow_two] + ring + rw [he] + have hq : ((triangles G).card : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hQ.card_pos + field_simp + ring + +noncomputable def triangleDegreeMean {n : ℕ} (G : Graph n) : ℝ := + 3 * (triangles G).card / G.card + +noncomputable def triangleDegreeVariance {n : ℕ} (G : Graph n) : ℝ := + ∑ e ∈ G, ((triangleDegree G e : ℝ) - triangleDegreeMean G)^2 + +lemma triangleDegreeVariance_nonneg {n : ℕ} (G : Graph n) : + 0 ≤ triangleDegreeVariance G := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +lemma triangleDegreeMean_mass {n : ℕ} {G : Graph n} (hG : G.Nonempty) : + (G.card : ℝ) * triangleDegreeMean G = 3 * (triangles G).card := by + have hm : (G.card : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hG.card_pos + unfold triangleDegreeMean + field_simp + +theorem triangle_degree_second_moment {n : ℕ} {G : Graph n} (hG : G.Nonempty) : + (∑ e ∈ G, (triangleDegree G e : ℝ)^2) = + triangleDegreeVariance G + (G.card : ℝ)*(triangleDegreeMean G)^2 := by + have hlin := triangle_degree_sum G + have hm := triangleDegreeMean_mass hG + have hv : triangleDegreeVariance G = + (∑ e ∈ G, (triangleDegree G e : ℝ)^2) - + 2*triangleDegreeMean G*(∑ e ∈ G, (triangleDegree G e : ℝ)) + + (G.card : ℝ)*(triangleDegreeMean G)^2 := by + unfold triangleDegreeVariance + calc + _ = ∑ e ∈ G, ((triangleDegree G e : ℝ)^2 - + 2*triangleDegreeMean G*(triangleDegree G e : ℝ) + (triangleDegreeMean G)^2) := by + apply Finset.sum_congr rfl + intro e _ + ring + _ = _ := by simp only [Finset.sum_add_distrib,Finset.sum_sub_distrib, + Finset.mul_sum,Finset.sum_const,nsmul_eq_mul] + rw [hlin, ← hm] at hv + nlinarith only [hv] + +lemma graph_nonempty_of_triangles {n : ℕ} {G : Graph n} (hQ : (triangles G).Nonempty) : + G.Nonempty := by + obtain ⟨t,ht⟩ := hQ + have hc := triangle_edge_card ht + have he : (t.powersetCard 2).Nonempty := Finset.card_pos.mp (by omega) + exact he.mono (mem_triangles.mp ht).2 + +theorem step_mean_triangle_count_centered {n : ℕ} {G : Graph n} + (hQ : (triangles G).Nonempty) : + pmfMean (step G) (fun H => ((triangles H).card : ℝ)) = + (triangles G).card - 9*(triangles G).card / G.card - + triangleDegreeVariance G / (triangles G).card + 2 := by + rw [step_mean_triangle_count hQ, triangle_degree_second_moment (graph_nonempty_of_triangles hQ)] + have hq : ((triangles G).card : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hQ.card_pos + have hm : (G.card : ℝ) ≠ 0 := by + exact_mod_cast Nat.ne_of_gt (graph_nonempty_of_triangles hQ).card_pos + unfold triangleDegreeMean + field_simp + ring + +lemma triangle_degree_variance_shift {n : ℕ} {G : Graph n} (hG : G.Nonempty) (d : ℝ) : + (∑ e ∈ G, ((triangleDegree G e : ℝ)-d)^2) = + triangleDegreeVariance G + (G.card : ℝ)*(triangleDegreeMean G-d)^2 := by + have hlin := triangle_degree_sum G + have hm := triangleDegreeMean_mass hG + have hsec := triangle_degree_second_moment hG + calc + _ = (∑ e ∈ G, (triangleDegree G e : ℝ)^2) - + 2*d*(∑ e ∈ G, (triangleDegree G e : ℝ))+(G.card : ℝ)*d^2 := by + calc + _ = ∑ e ∈ G, ((triangleDegree G e : ℝ)^2 - 2*d*(triangleDegree G e : ℝ) + d^2) := by + apply Finset.sum_congr rfl + intro e _ + ring + _ = _ := by simp only [Finset.sum_add_distrib,Finset.sum_sub_distrib, + Finset.mul_sum,Finset.sum_const,nsmul_eq_mul] + _ = _ := by rw [hsec,hlin,← hm]; ring + +lemma triangle_degree_variance_le {n : ℕ} {G : Graph n} (hG : G.Nonempty) + (d δ : ℝ) (hδ : 0 ≤ δ) (h : ∀ e ∈ G, |(triangleDegree G e : ℝ)-d| ≤ δ) : + triangleDegreeVariance G ≤ (G.card : ℝ)*δ^2 := by + have hv : triangleDegreeVariance G ≤ ∑ e ∈ G, ((triangleDegree G e : ℝ)-d)^2 := by + rw [triangle_degree_variance_shift hG d] + exact le_add_of_nonneg_right (mul_nonneg (Nat.cast_nonneg _) (sq_nonneg _)) + apply hv.trans + calc + _ ≤ ∑ _e ∈ G, δ^2 := by + apply Finset.sum_le_sum + intro e he + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hδ).mpr (h e he) + _ = _ := by simp + +end SharpTerminalLeave +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraph.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..c0c6ce3c15ecbfcb6cb5234cfe74f7b57888a548 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraph.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Coupling.HyperScanAction +import OAI.Combinatorics.TriangleRemoval.Coupling.ScanList + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators +open scoped BigOperators ENNReal Classical + +namespace SharpTerminalLeave + +def triangleHypergraph {n : ℕ} (G : Graph n) (T : Finset (Fin n)) : Graph n := + if T ∈ triangles G then T.powersetCard 2 else ∅ + +theorem triangleHypergraph_subset {n : ℕ} (G : Graph n) (T : Finset (Fin n)) : + triangleHypergraph G T ⊆ G := by + unfold triangleHypergraph + split_ifs with hT + · exact (mem_triangles.mp hT).2 + · exact Finset.empty_subset _ + +theorem triangle_hyperScanAction_eq {n : ℕ} (G E : Graph n) (hE : E ⊆ G) + (T : Finset (Fin n)) : + hyperScanAction (triangleHypergraph G) E T = scanAction E T := by + by_cases hT : T ∈ triangles G + · have hc := (mem_triangles.mp hT).1 + simp only [hyperScanAction, triangleHypergraph, hT, ite_true, scanAction, + mem_triangles, hc, true_and] + · have hn : T ∉ triangles E := fun ht => hT (triangles_mono hE ht) + simp [hyperScanAction, triangleHypergraph, hT, scanAction, hn] + +theorem triangle_hyperScan_eq {n : ℕ} (G E : Graph n) (hE : E ⊆ G) + (as : List (Finset (Fin n))) : + hyperScan (triangleHypergraph G) E as = scanList E as := by + induction as generalizing E with + | nil => rfl + | cons T as ih => + change hyperScan (triangleHypergraph G) + (hyperScanAction (triangleHypergraph G) E T) as = scanList (scanAction E T) as + rw [triangle_hyperScanAction_eq G E hE T] + exact ih _ ((scanAction_subset E T).trans hE) + +theorem graph_gridQuery_eq_scan {n : ℕ} (G focus : Graph n) (hf : focus ⊆ G) + (N : ℕ) (ω : Finset (Fin n) → Fin N) (hω : Function.Injective ω) : + ExposureTree.evaluate ω (gridQueryDepth (triangleHypergraph G) N N N focus none) = + decide (focus ⊆ scanList G (clockOrder (fun T => (ω T).val))) := by + have hs := evaluate_gridQueryDepth_iff (triangleHypergraph G) N N N ω G focus none + le_rfl hf (triangleHypergraph_subset G) (fun T h => by cases h) + rw [timeScan_eq_hyperScan (triangleHypergraph G) (fun T => (ω T).val) + (Fin.val_injective.comp hω) G N (fun T => (ω T).isLt), + triangle_hyperScan_eq G G (Finset.Subset.refl G)] at hs + apply Bool.eq_iff_iff.mpr + simpa only [Bool.decide_iff] using hs + +noncomputable def focusSurvival {n : ℕ} (G focus : Graph n) : ℝ := + trueProbability ((finish G).map (fun E => decide (focus ⊆ E))) + +theorem graph_grid_exposure_error {n : ℕ} (G focus : Graph n) (hf : focus ⊆ G) + (N : ℕ) [NeZero N] : + |focusSurvival G focus - gridAnswerProbability (triangleHypergraph G) N N N focus none| ≤ + 2 * (Fintype.card (Finset (Fin n)) : ℝ) ^ 2 / N + + trueProbability ((ExposureTree.freshRecorded (gridPriorities N) + (gridQueryDepth (triangleHypergraph G) N N N focus none) ∅).map Prod.snd) := by + classical + let H := triangleHypergraph G + let p := productPMF (gridPriorities (τ := Finset (Fin n)) N) + let b₁ := fun ω => ExposureTree.evaluate ω (gridQueryDepth H N N N focus none) + let b₂ := fun ω : Finset (Fin n) → Fin N => + decide (focus ⊆ scanList G (clockOrder (fun T => (ω T).val))) + let C : ℝ := (Fintype.card (Finset (Fin n)) : ℝ) ^ 2 / N + have h₁ : |trueProbability (p.map b₁) - trueProbability (p.map b₂)| ≤ C := by + apply (boolean_coupling_bound p b₁ b₂ + (fun ω => decide (¬Function.Injective ω)) ?_).trans (grid_table_ties_bound N) + intro ω _ hω + have hinj : Function.Injective ω := Classical.not_not.mp (of_decide_eq_false hω) + exact graph_gridQuery_eq_scan G focus hf N ω hinj + have h₂ : |trueProbability (p.map b₂) - focusSurvival G focus| ≤ C := by + have hh := clock_order_error N (fun as : List (Finset (Fin n)) => + decide (focus ⊆ scanList G as)) + have hl := uniform_order_scan_eq_finish G Finset.univ + (Finset.subset_univ (triangles G)) + have hh' := congrArg (fun r : PMF (Graph n) => + r.map (fun E => decide (focus ⊆ E))) hl + simp only [PMF.map_comp, Function.comp_def, Finset.card_univ] at hh' + rw [hh'] at hh + exact hh + have h₃ := ExposureTree.independent_exposure_error (gridPriorities N) + (gridQueryDepth H N N N focus none) + have h₁' : |trueProbability (p.map b₂) - trueProbability (p.map b₁)| ≤ C := by + rw [abs_sub_comm] + exact h₁ + have h₂' : |focusSurvival G focus - trueProbability (p.map b₂)| ≤ C := by + rw [abs_sub_comm] + exact h₂ + have hsum : |focusSurvival G focus - gridAnswerProbability H N N N focus none| ≤ + C + (C + trueProbability ((ExposureTree.freshRecorded (gridPriorities N) + (gridQueryDepth H N N N focus none) ∅).map Prod.snd)) := (abs_sub_le (focusSurvival G focus) (trueProbability (p.map b₂)) + (gridAnswerProbability H N N N focus none)).trans + (add_le_add h₂' + ((abs_sub_le (trueProbability (p.map b₂)) (trueProbability (p.map b₁)) + (gridAnswerProbability H N N N focus none)).trans + (add_le_add h₁' h₃))) + convert hsum using 1; ring + +end SharpTerminalLeave + +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraphLinear.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraphLinear.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac9bf14ca1dd0ca488a75cb8d3fa82a22a831632 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraphLinear.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraph +import OAI.Combinatorics.TriangleRemoval.Spectral.TracedGridQuerySeparated +import OAI.Combinatorics.TriangleRemoval.Spectral.TracedGridQueryAddress + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +theorem triangleHypergraph_linear {n : ℕ} (G : Graph n) + (T S : Finset (Fin n)) (hTS : T ≠ S) : + (triangleHypergraph G T ∩ triangleHypergraph G S).card ≤ 1 := by + by_cases hT : T ∈ triangles G + · by_cases hS : S ∈ triangles G + · simp only [triangleHypergraph, hT, hS, ↓reduceIte] + apply Finset.card_le_one.mpr + intro e he f hf + by_contra hef + obtain ⟨heT,heS⟩ := Finset.mem_inter.mp he + obtain ⟨hfT,hfS⟩ := Finset.mem_inter.mp hf + obtain ⟨heT,hce⟩ := Finset.mem_powersetCard.mp heT + obtain ⟨hfT,hcf⟩ := Finset.mem_powersetCard.mp hfT + have heS := (Finset.mem_powersetCard.mp heS).1 + have hfS := (Finset.mem_powersetCard.mp hfS).1 + exact hTS (triangle_eq_of_two_edges (mem_triangles.mp hT).1 + (mem_triangles.mp hS).1 hce hcf hef heT hfT heS hfS) + · simp [triangleHypergraph, hS] + · simp [triangleHypergraph, hT] + +lemma disjoint_edges_not_same_triangle {α : Type*} [DecidableEq α] + {T e f : Finset α} (hT : T.card = 3) + (he : e ∈ T.powersetCard 2) (hf : f ∈ T.powersetCard 2) + (hd : Disjoint e f) : False := by + obtain ⟨he,hce⟩ := Finset.mem_powersetCard.mp he + obtain ⟨hf,hcf⟩ := Finset.mem_powersetCard.mp hf + have hh := Finset.card_le_card (Finset.union_subset he hf) + rw [Finset.card_union_of_disjoint hd,hce,hcf,hT] at hh + omega + +theorem triangleHypergraph_separated_disjoint_roots {n : ℕ} (G : Graph n) + (e f : Finset (Fin n)) (hd : Disjoint e f) : + (QueryCall.mk [] {e,f} none).Separated (triangleHypergraph G) := by + intro T _ + by_cases hT : T ∈ triangles G + · change (triangleHypergraph G T ∩ {e,f}).card ≤ 1 + simp only [triangleHypergraph,hT,↓reduceIte] + apply Finset.card_le_one.mpr + intro a ha b hb + obtain ⟨haT,haR⟩ := Finset.mem_inter.mp ha + obtain ⟨hbT,hbR⟩ := Finset.mem_inter.mp hb + simp only [Finset.mem_insert,Finset.mem_singleton] at haR hbR + rcases haR with rfl | rfl <;> rcases hbR with rfl | rfl + · rfl + · exact False.elim (disjoint_edges_not_same_triangle (mem_triangles.mp hT).1 haT hbT hd) + · exact False.elim (disjoint_edges_not_same_triangle (mem_triangles.mp hT).1 hbT haT hd) + · rfl + · simp [triangleHypergraph,hT] + +theorem graph_query_repeat_addresses {n : ℕ} (G : Graph n) (N d k : ℕ) + (c : QueryCall (Finset (Fin n)) (Finset (Fin n))) + (hc : c.Separated (triangleHypergraph G)) + (ν : Finset (Fin n) → PMF (Fin N)) + {z : (Bool × List (QueryCall (Finset (Fin n)) (Finset (Fin n)))) × List (Finset (Fin n))} + (hz : z ∈ (ExposureTree.freshLog ν + (tracedGridQuery (triangleHypergraph G) N d k c)).support) + (hr : ExposureTree.repeats ∅ z.2 = true) : + ∃ a ∈ z.1.2, ∃ b ∈ z.1.2, a.address ≠ b.address ∧ ∃ T, + T ∈ a.keys (triangleHypergraph G) ∧ T ∈ b.keys (triangleHypergraph G) := by + obtain ⟨i,j,hij,T,hi,hj⟩ := tracedGridQuery_repeat_calls _ + (triangleHypergraph_linear G) N d k c hc ν hz hr + have hnd := tracedGridQuery_address_nodup _ N d k c ν hz + have hpair : z.1.2.Pairwise (fun a b => a.address ≠ b.address) := by + simpa only [List.Nodup,List.pairwise_map] using hnd + exact ⟨z.1.2.get i, List.get_mem _ _, z.1.2.get j, List.get_mem _ _, + List.pairwise_iff_get.mp hpair i j hij, T, hi, hj⟩ + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraphReindex.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraphReindex.lean new file mode 100644 index 0000000000000000000000000000000000000000..6437d7ab8944ebf495c4b1f2902ea1fca8de1a5d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleHypergraphReindex.lean @@ -0,0 +1,59 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ActiveHypergraph +import OAI.Combinatorics.TriangleRemoval.Queries.GridCollision +import OAI.Combinatorics.TriangleRemoval.Queries.MessageCandidatesReindex + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +theorem triangleHypergraph_reindex {n : ℕ} (G : Graph n) (T : ↥(triangles G)) : + triangleHypergraph G (triangleEmbedding G T) = + (activeHypergraph G T).map (edgeEmbedding G) := by + rw [activeHypergraph_map] + simp [triangleHypergraph, triangleEmbedding, T.property] + +theorem triangleHypergraph_active {n : ℕ} (G : Graph n) (e : ↥G) + (T : Finset (Fin n)) (he : edgeEmbedding G e ∈ triangleHypergraph G T) : + ∃ T' : ↥(triangles G), triangleEmbedding G T' = T := by + by_cases hT : T ∈ triangles G + · exact ⟨⟨T, hT⟩, rfl⟩ + · simp [triangleHypergraph, hT] at he + +theorem active_cavity_eq {n : ℕ} (G : Graph n) (e : ↥G) + (p : Option ↥(triangles G)) (t : ℝ) : + cavityLimit (triangleHypergraph G) e.val (p.map Subtype.val) t = + cavityLimit (activeHypergraph G) e p t := + cavityLimit_reindex _ _ (edgeEmbedding G) (triangleEmbedding G) + (triangleHypergraph_reindex G) (triangleHypergraph_active G) e p t + +theorem active_graph_cavity_error {n : ℕ} (G : Graph n) (focus : Finset ↥G) : + |focusSurvival G (focus.map (edgeEmbedding G)) - + ∏ e ∈ focus, cavityLimit (activeHypergraph G) e none 1| ≤ + collisionCost (triangleHypergraph G) (focus.map (edgeEmbedding G)) none := by + have hf : focus.map (edgeEmbedding G) ⊆ G := by + intro e he + obtain ⟨e', _, rfl⟩ := Finset.mem_map.mp he + exact e'.property + have hh := graph_cavity_error G (focus.map (edgeEmbedding G)) hf + rw [Finset.prod_map] at hh + convert hh using 1 + congr 2 + apply Finset.prod_congr rfl + intro e _ + exact (active_cavity_eq G e none 1).symm + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleIndex.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleIndex.lean new file mode 100644 index 0000000000000000000000000000000000000000..e744d94c5f89a1a21f9ace21a03d4c3986cb7580 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleIndex.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.RelativeNoiseExit +import OAI.Combinatorics.TriangleRemoval.Tracking.CodegreeNoiseRadius +import OAI.Combinatorics.TriangleRemoval.Process.CommonNeighborsComplete +import OAI.Combinatorics.TriangleRemoval.Asymptotics.DensityEdgeSafe + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +abbrev TriangleIndex (n : ℕ) := ↥((Finset.univ : Finset (Fin n)).powersetCard 3) +def triangleRequired {n : ℕ} (t : TriangleIndex n) : Graph n := t.val.powersetCard 2 + +@[simp] theorem triangle_copyCount {n : ℕ} (G : Graph n) : + copyCount (triangleRequired (n := n)) G = ((triangles G).card : ℝ) := by + unfold copyCount triangleRequired + rw [Finset.sum_coe_sort (Finset.univ.powersetCard 3 : Finset (Finset (Fin n))) (fun (t : Finset (Fin n)) => intact (t.powersetCard 2) G)] + simp [intact,triangles] + +@[simp] theorem triangle_copyEdgeLoad {n : ℕ} (G : Graph n) (e : Finset (Fin n)) : + copyEdgeLoad (triangleRequired (n := n)) G e = (triangleDegree G e : ℝ) := by + unfold copyEdgeLoad triangleRequired + rw [Finset.sum_coe_sort (Finset.univ.powersetCard 3 : Finset (Finset (Fin n))) (fun (t : Finset (Fin n)) => if e ∈ t.powersetCard 2 then intact (t.powersetCard 2) G else 0)] + simp only [triangleDegree,incidentTriangles,triangles,Finset.filter_filter] + rw [Finset.card_filter,Nat.cast_sum] + apply Finset.sum_congr rfl + intro t ht + unfold intact + split_ifs <;> simp_all + +noncomputable def earlyTriangleScale (n i : ℕ) : ℝ := earlyTemplateScale 3 3 n i/6 +noncomputable def triangleNoiseLoad (n i : ℕ) : ℝ := 2*earlyTemplateScale 1 2 n i + +def PrefixTriangleNoise (n : ℕ) (ω : History (Graph n) (prefixTime n)) : Prop := + ¬ RelativeNoiseExit (triangleRequired (n := n)) (triangleNoiseLoad n) + (earlyTriangleScale n) 2 (codegreeNoiseRadius n) (prefixTime n) ω + +lemma earlyTriangleScale_regular : ∀ᶠ n : ℕ in atTop, + (∀ i ≤ prefixTime n, 0 < earlyTriangleScale n i) ∧ + (∀ i < prefixTime n, earlyTriangleScale n (i+1) ≤ earlyTriangleScale n i) ∧ + (∀ i < prefixTime n, earlyTriangleScale n i ≤ 2*earlyTriangleScale n (i+1)) ∧ + relativeScaleBudget (earlyTriangleScale n) (prefixTime n) ≤ 6*Real.log n := by + filter_upwards [earlyTemplateScale_regular 3 3,earlyTemplateScale_log_budget 3 3] with n hr hb + refine ⟨fun i hi => div_pos (hr.1 i hi) (by norm_num),?_,?_,?_⟩ + · intro i hi + exact div_le_div_of_nonneg_right (hr.2.1 i hi) (by norm_num) + · intro i hi + have hh := div_le_div_of_nonneg_right (hr.2.2 i hi) (by norm_num : (0 : ℝ) ≤ 6) + simpa only [earlyTriangleScale,mul_div_assoc] using hh + · convert hb using 1 + · unfold relativeScaleBudget earlyTriangleScale + congr 1 + ext i + ring + · norm_num + +lemma completeGraph_early_mass {n : ℕ} (hn : 0 < n) : + ((completeGraph n).card : ℝ) = (n : ℝ)^2*earlyDensity n 0/2 := by + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast hn.ne' + rw [card_completeGraph,Nat.cast_choose_two] + simp only [earlyDensity,Nat.cast_zero,mul_zero,zero_div,sub_zero] + field_simp + +lemma triangleDegree_complete {n : ℕ} (e : Finset (Fin n)) (he : e ∈ completeGraph n) : + triangleDegree (completeGraph n) e = n-2 := by + obtain ⟨u,v,huv,rfl⟩ := Finset.card_eq_two.mp (mem_completeGraph.mp he) + rw [triangleDegree_eq_codegree (Finset.Subset.refl _) he,currentCodegree_complete u v huv] + +lemma triangleCount_complete_formula {n : ℕ} (hn : 2 ≤ n) : + ((triangles (completeGraph n)).card : ℝ) = (n : ℝ)*(n-1)*(n-2)/6 := by + have hh := triangle_degree_sum (completeGraph n) + have he : (∑ e ∈ completeGraph n, (triangleDegree (completeGraph n) e : ℝ)) = + ((completeGraph n).card : ℝ)*(n-2) := by + calc + _ = ∑ _e ∈ completeGraph n, ((n-2 : ℕ) : ℝ) := Finset.sum_congr rfl (fun e he => by rw [triangleDegree_complete e he]) + _ = _ := by simp [Nat.cast_sub hn]; ring + rw [he,card_completeGraph,Nat.cast_choose_two] at hh + nlinarith only [hh] + +lemma initial_triangle_relative_error {n : ℕ} (hn : 2 ≤ n) : + ((triangles (completeGraph n)).card : ℝ)/earlyTriangleScale n 0-1 = -1/((n : ℝ)-1)^2 := by + have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn + have hn0 : (n : ℝ) ≠ 0 := by linarith + have hn1 : (n : ℝ)-1 ≠ 0 := by linarith + have hs : earlyTriangleScale n 0 = ((n : ℝ)-1)^3/6 := by + unfold earlyTriangleScale earlyTemplateScale earlyDensity + simp only [Nat.cast_zero,mul_zero,zero_div,sub_zero] + field_simp + rw [triangleCount_complete_formula hn,hs] + field_simp + ring + +lemma initial_triangle_ratio_le_two {n : ℕ} (hn : 2 ≤ n) : + copyCount (triangleRequired (n := n)) (completeGraph n)/earlyTriangleScale n 0 ≤ 2 := by + rw [triangle_copyCount] + have hh := initial_triangle_relative_error hn + have hz : 0 ≤ 1/((n : ℝ)-1)^2 := by positivity + rw [neg_div] at hh + linarith + +lemma densityEdgeSafe_triangle_load {n : ℕ} {p η : ℝ} {G : Graph n} + (hp : 0 ≤ p) (hη : η ≤ 1) (h : densityEdgeSafe n p η G) : + copyLoadSafe (triangleRequired (n := n)) (2*((n : ℝ)*p^2)) G := by + intro e he + rw [triangle_copyEdgeLoad] + have hb := (abs_le.mp (h.2.2 e he)).2 + have hd : 0 ≤ (n : ℝ)*p^2 := mul_nonneg (Nat.cast_nonneg n) (pow_nonneg hp 2) + have hh := mul_le_mul_of_nonneg_right hη hd + linarith + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleLiftCount.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleLiftCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..af40bf7d73ceaae6e1caad296423931899ccc157 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleLiftCount.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.RootedTemplates +import OAI.Combinatorics.TriangleRemoval.Process.CopyEdgeLoad + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +noncomputable def triangleLiftCount {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) : ℝ := + ∑ a, intact (required a) G * ∑ e ∈ required a, (triangleDegree G e : ℝ) + +theorem copyCount_triangleLift_drift {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (b : ℕ) + (hsize : ∀ a, (required a).card ≤ b) (hG : (triangles G).Nonempty) : + 0 ≤ pmfMean (step G) (copyCount required) - copyCount required G + + triangleLiftCount required G/(triangles G).card ∧ + pmfMean (step G) (copyCount required) - copyCount required G + + triangleLiftCount required G/(triangles G).card ≤ + (b : ℝ)^2/(triangles G).card * copyCount required G := by + classical + let loss (a : α) : ℝ := + if required a ⊆ G then ((hittingTriangles G (required a)).card : ℝ) else 0 + have ha (a : α) : + 0 ≤ intact (required a) G * ∑ e ∈ required a, (triangleDegree G e : ℝ) - loss a ∧ + intact (required a) G * ∑ e ∈ required a, (triangleDegree G e : ℝ) - loss a ≤ + (b : ℝ)^2*intact (required a) G := by + by_cases hpres : required a ⊆ G + · simp only [intact,ite_eq_left hpres,one_mul,loss,mul_one] + have hl : ((hittingTriangles G (required a)).card : ℝ) ≤ + ∑ e ∈ required a, (triangleDegree G e : ℝ) := by + exact_mod_cast hittingTriangles_card_le_degree_sum G (required a) + have hu : (∑ e ∈ required a, (triangleDegree G e : ℝ)) ≤ + ((hittingTriangles G (required a)).card : ℝ)+(b : ℝ)^2 := by + have hh := degree_sum_le_hittingTriangles_add G (required a) + have hb : (required a).card^2 ≤ b^2 := Nat.pow_le_pow_left (hsize a) 2 + exact_mod_cast hh.trans (Nat.add_le_add_left hb _) + constructor <;> linarith + · simp only [intact,ite_eq_right hpres,loss,zero_mul,mul_zero,sub_self,le_refl,and_self] + have hsumlo : 0 ≤ triangleLiftCount required G-∑ a, loss a := by + rw [triangleLiftCount,← Finset.sum_sub_distrib] + exact Finset.sum_nonneg (fun a _ => (ha a).1) + have hsumhi : triangleLiftCount required G-∑ a, loss a ≤ + (b : ℝ)^2*copyCount required G := by + rw [triangleLiftCount,← Finset.sum_sub_distrib,copyCount,Finset.mul_sum] + exact Finset.sum_le_sum (fun a _ => (ha a).2) + have hQ : (0 : ℝ) < (triangles G).card := Nat.cast_pos.mpr hG.card_pos + have hid : pmfMean (step G) (copyCount required)-copyCount required G+ + triangleLiftCount required G/(triangles G).card = + (triangleLiftCount required G-∑ a, loss a)/(triangles G).card := by + rw [step_mean_copyCount required G hG] + change copyCount required G-(∑ a, loss a)/_ -copyCount required G+_ = _ + ring + rw [hid] + refine ⟨div_nonneg hsumlo hQ.le,?_⟩ + exact (div_le_div_of_nonneg_right hsumhi hQ.le).trans_eq (by ring) + +abbrev TriangleLiftIndex {n : ℕ} {α : Type*} (required : α → Graph n) := + {p : α × (Finset (Fin n) × Finset (Fin n)) // + p.2.1 ∈ required p.1 ∧ p.2.2.card = 3 ∧ p.2.1 ∈ p.2.2.powersetCard 2} + +def triangleLiftRequired {n : ℕ} {α : Type*} (required : α → Graph n) + (a : TriangleLiftIndex required) : Graph n := + required a.val.1 ∪ a.val.2.2.powersetCard 2 + +lemma intact_union {n : ℕ} (F E G : Graph n) : + intact (F ∪ E) G = intact F G * intact E G := by + classical + unfold intact + by_cases hF : F ⊆ G <;> by_cases hE : E ⊆ G <;> + simp [hF,hE,Finset.union_subset_iff] + +lemma triangleDegree_eq_intact_sum {n : ℕ} (G : Graph n) (e : Finset (Fin n)) : + (triangleDegree G e : ℝ) = + ∑ t : Finset (Fin n), if t.card = 3 ∧ e ∈ t.powersetCard 2 then + intact (t.powersetCard 2) G else 0 := by + classical + have ht : (triangleDegree G e : ℝ) = + ∑ t : Finset (Fin n), if t ∈ incidentTriangles G e then (1 : ℝ) else 0 := by + simp [triangleDegree] + rw [ht] + apply Finset.sum_congr rfl + intro t _ + simp only [incidentTriangles,Finset.mem_filter,mem_triangles,intact] + by_cases hc : t.card = 3 <;> by_cases he : e ∈ t.powersetCard 2 <;> + by_cases hG : t.powersetCard 2 ⊆ G <;> simp [hc,he,hG] + +theorem triangleLiftCount_eq_copyCount {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) : + triangleLiftCount required G = copyCount (triangleLiftRequired required) G := by + classical + let pred (p : α × (Finset (Fin n) × Finset (Fin n))) : Prop := + p.2.1 ∈ required p.1 ∧ p.2.2.card = 3 ∧ p.2.1 ∈ p.2.2.powersetCard 2 + have hh := Finset.sum_subtype (F := inferInstance) (Finset.univ.filter pred) + (by intro p; simp : ∀ p, p ∈ Finset.univ.filter pred ↔ pred p) + (fun p => intact (required p.1 ∪ p.2.2.powersetCard 2) G) + change triangleLiftCount required G = + ∑ a : {p // pred p}, intact (required a.val.1 ∪ a.val.2.2.powersetCard 2) G + rw [← hh,Finset.sum_filter] + simp only [Fintype.sum_prod_type] + unfold triangleLiftCount + apply Finset.sum_congr rfl + intro a _ + rw [Finset.mul_sum] + calc + _ = ∑ e : Finset (Fin n), if e ∈ required a then + intact (required a) G * (triangleDegree G e : ℝ) else 0 := by simp + _ = _ := by + apply Finset.sum_congr rfl + intro e _ + by_cases he : e ∈ required a + · simp only [ite_eq_left he,triangleDegree_eq_intact_sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro t _ + simp only [he,true_and,intact_union,mul_ite,mul_zero] + · simp only [he,false_and,ite_false,Finset.sum_const_zero] + +lemma triangleLiftRequired_card_le {n : ℕ} {α : Type*} + (required : α → Graph n) (a : TriangleLiftIndex required) : + (triangleLiftRequired required a).card ≤ (required a.val.1).card + 2 := by + classical + have htri : (a.val.2.2.powersetCard 2).card = 3 := by + rw [Finset.card_powersetCard,a.property.2.1] + decide + have hmeet : 1 ≤ ((required a.val.1) ∩ a.val.2.2.powersetCard 2).card := by + apply Nat.succ_le_iff.mpr + apply Finset.card_pos.mpr + exact ⟨a.val.2.1,Finset.mem_inter.mpr ⟨a.property.1,a.property.2.2⟩⟩ + have he := Finset.card_union_add_card_inter (required a.val.1) (a.val.2.2.powersetCard 2) + unfold triangleLiftRequired + omega + +lemma copyEdgeLoad_eq_subfamily {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (e : Finset (Fin n)) : + copyEdgeLoad required G e = + copyCount (fun a : {a // e ∈ required a} => required a.val) G := by + classical + rw [copyEdgeLoad,copyCount] + have hh := Finset.sum_subtype (F := inferInstance) + (Finset.univ.filter (fun a => e ∈ required a)) + (by intro a; simp : ∀ a, a ∈ Finset.univ.filter (fun a => e ∈ required a) ↔ + e ∈ required a) (fun a => intact (required a) G) + rw [← hh,Finset.sum_filter] + +theorem copyCount_triangleLift_drift_all {n : ℕ} {α : Type*} [Fintype α] + (required : α → Graph n) (G : Graph n) (b : ℕ) + (hsize : ∀ a, (required a).card ≤ b) : + 0 ≤ pmfMean (step G) (copyCount required) - copyCount required G + + triangleLiftCount required G/(triangles G).card ∧ + pmfMean (step G) (copyCount required) - copyCount required G + + triangleLiftCount required G/(triangles G).card ≤ + (b : ℝ)^2/(triangles G).card * copyCount required G := by + by_cases hG : (triangles G).Nonempty + · exact copyCount_triangleLift_drift required G b hsize hG + · have hG0 : triangles G = ∅ := Finset.not_nonempty_iff_eq_empty.mp hG + simp only [step_absorbing hG0,pmfMean_pure,sub_self,hG0,Finset.card_empty, + Nat.cast_zero,div_zero,zero_mul,add_zero,le_refl,and_self] + +lemma rootedCount_triangleLift_drift {k n : ℕ} (T : RootedTemplate k) + (ψ : {v // v ∈ T.roots} ↪ Fin n) (G : Graph n) : + 0 ≤ pmfMean (step G) (rootedCount T ψ) - rootedCount T ψ G + + triangleLiftCount (fun φ : RootedInjection T ψ => imageEdges T φ.val) G / + (triangles G).card ∧ + pmfMean (step G) (rootedCount T ψ) - rootedCount T ψ G + + triangleLiftCount (fun φ : RootedInjection T ψ => imageEdges T φ.val) G / + (triangles G).card ≤ + (T.edges.card : ℝ)^2/(triangles G).card * rootedCount T ψ G := by + exact copyCount_triangleLift_drift_all + (fun φ : RootedInjection T ψ => imageEdges T φ.val) G T.edges.card + (fun φ => (imageEdges_card T φ.val).le) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleNoiseJumpBudget.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleNoiseJumpBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..a50846468b6192e002ce355fccad716a34d7fa0f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleNoiseJumpBudget.lean @@ -0,0 +1,122 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.RootedCompletionMax +import OAI.Combinatorics.TriangleRemoval.Tracking.BalancedJump +import OAI.Combinatorics.TriangleRemoval.Process.TriangleIndex + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter Classical + +namespace SharpTerminalLeave + +lemma triangle_noise_jump_budget : ∀ᶠ n : ℕ in atTop, + ∀ i < prefixTime n, 3*triangleNoiseLoad n i/earlyTriangleScale n (i+1) ≤ balancedJump n := by + have hg : Tendsto (fun n : ℕ => (n : ℝ)^(1999/2000 : ℝ)) atTop atTop := + (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 1999/2000)).comp tendsto_natCast_atTop_atTop + filter_upwards [earlyTriangleScale_regular,prefixDensity_eventually_inverse_lower, + hg.eventually_ge_atTop 72,eventually_ge_atTop (1 : ℕ)] with n hr hp hg hn + intro i hi + have hn0 : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n) + have hp0 := early_density_positive (by omega) hp hi.le + have hmin : 1/(n : ℝ) ≤ earlyDensity n i := hp.trans (earlyDensity_antitone n hi.le) + have hratio := hr.2.2.1 i hi + have hS := hr.1 i hi.le + have hS' := hr.1 (i+1) (by omega) + have hD : 0 ≤ earlyTemplateScale 1 2 n i := by unfold earlyTemplateScale; positivity + have h₁ : 3*triangleNoiseLoad n i/earlyTriangleScale n (i+1) ≤ + 12*earlyTemplateScale 1 2 n i/earlyTriangleScale n i := by + apply (div_le_div_iff₀ hS' hS).mpr + have hh := mul_le_mul_of_nonneg_left hratio (show 0 ≤ 6*earlyTemplateScale 1 2 n i by positivity) + dsimp only [triangleNoiseLoad] + nlinarith only [hh] + have he : 12*earlyTemplateScale 1 2 n i/earlyTriangleScale n i = + 72/(n : ℝ)^2/earlyDensity n i := by + unfold earlyTemplateScale earlyTriangleScale earlyTemplateScale + field_simp + ring + rw [he] at h₁ + have h₂ : 72/(n : ℝ)^2/earlyDensity n i ≤ 72/(n : ℝ) := by + apply (div_le_iff₀ hp0).mpr + have hh := mul_le_mul_of_nonneg_left hmin (show 0 ≤ 72/(n : ℝ) by positivity) + convert hh using 1 + field_simp + have h₃ : 72/(n : ℝ) ≤ balancedJump n := by + have hh := div_le_div_of_nonneg_right hg hn0.le + apply hh.trans_eq + unfold balancedJump + calc + (n : ℝ)^(1999/2000 : ℝ)/(n : ℝ) = (n : ℝ)^(1999/2000 : ℝ)/(n : ℝ)^(1 : ℝ) := by rw [Real.rpow_one] + _ = (n : ℝ)^(-1/2000 : ℝ) := by rw [← Real.rpow_sub hn0]; norm_num + exact h₁.trans (h₂.trans h₃) + +theorem prefix_triangle_noise_single : ∀ᶠ n : ℕ in atTop, + pmfMean (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)) + (fun ω => if PrefixTriangleNoise n ω then 0 else 1) ≤ + 2*(prefixTime n+1 : ℝ)*Real.exp (-(Real.log (n : ℝ))^2/4) := by + filter_upwards [earlyTriangleScale_regular,triangle_noise_jump_budget, + balanced_noise_exponent_budget 3,prefixDensity_eventually_inverse_lower, + eventually_ge_atTop (2 : ℕ)] with n hr hj hexp hp hn + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast (by omega : 1 ≤ n) + have hn0 : (0 : ℝ) < n := lt_of_lt_of_le zero_lt_one hn1 + have hc : 0 < balancedJump n := Real.rpow_pos_of_pos hn0 _ + have hnoise : 0 < codegreeNoiseRadius n := Real.rpow_pos_of_pos hn0 _ + have hL : ∀ i < prefixTime n, 0 ≤ triangleNoiseLoad n i := by + intro i hi + unfold triangleNoiseLoad earlyTemplateScale + positivity + have ht := triangle_relative_template_self_bounded_tail (triangleRequired (n := n)) + (completeGraph n) (prefixTime n) (triangleNoiseLoad n) (earlyTriangleScale n) + (balancedJump n) 2 hc (by norm_num) hr.1 hr.2.1 hL hj (codegreeNoiseRadius n) hnoise + have ht' : pmfMean (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)) + (fun ω => if PrefixTriangleNoise n ω then 0 else 1) ≤ + 2*(prefixTime n+1 : ℝ)*Real.exp + (-codegreeNoiseRadius n^2/(4*(balancedJump n*(copyCount (triangleRequired (n := n)) + (completeGraph n)/earlyTriangleScale n 0+2*relativeScaleBudget (earlyTriangleScale n) (prefixTime n)+ + codegreeNoiseRadius n+balancedJump n)+balancedJump n*codegreeNoiseRadius n))) := by + convert ht using 1 + apply congrArg (pmfMean _) + funext ω + unfold PrefixTriangleNoise RelativeNoiseExit + split_ifs <;> simp_all + apply ht'.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Real.exp_le_exp.mpr + rw [neg_div,neg_div] + apply neg_le_neg + apply hexp.trans + apply div_le_div_of_nonneg_left (sq_nonneg _) + · have hscale : 0 ≤ copyCount (triangleRequired (n := n)) (completeGraph n)/earlyTriangleScale n 0 := + div_nonneg (copyCount_nonneg _ _) (hr.1 0 (Nat.zero_le _)).le + have hbudget := relativeScaleBudget_nonneg (earlyTriangleScale n) (prefixTime n) hr.1 hr.2.1 + positivity + · have hi := initial_triangle_ratio_le_two hn + have hbgt := hr.2.2.2 + have hh := mul_le_mul_of_nonneg_left (show copyCount (triangleRequired (n := n)) (completeGraph n)/earlyTriangleScale n 0+ + 2*relativeScaleBudget (earlyTriangleScale n) (prefixTime n)+codegreeNoiseRadius n+balancedJump n ≤ + 2+4*(3 : ℝ)^2*Real.log n+codegreeNoiseRadius n+balancedJump n by + nlinarith only [hi,hbgt,Real.log_nonneg hn1]) hc.le + norm_num only [Nat.cast_ofNat] at hexp ⊢ + linarith only [hh] + +theorem prefix_triangle_noise_failure : ∀ᶠ n : ℕ in atTop, + pmfMean (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)) + (fun ω => if PrefixTriangleNoise n ω then 0 else 1) ≤ + Real.exp (-2*(Real.log (n : ℝ))^(4/3 : ℝ)) := by + filter_upwards [prefix_triangle_noise_single,polynomial_logsquare_le_prefix_margin 4 2, + eventually_ge_atTop (1 : ℕ)] with n ht hb hn + apply ht.trans + have htime : 2*(prefixTime n+1 : ℝ) ≤ 4*(n : ℝ)^2 := by + have ht : (prefixTime n : ℝ) ≤ (n : ℝ)^2 := by exact_mod_cast prefixTime_le_square n + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn + nlinarith only [ht,hn1] + apply (mul_le_mul_of_nonneg_right htime (Real.exp_pos _).le).trans + simpa only [Real.rpow_two] using hb + +end SharpTerminalLeave +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleThird.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleThird.lean new file mode 100644 index 0000000000000000000000000000000000000000..1b3cce4614c2cfc6439b92ce6bdb64ea79f38717 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TriangleThird.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraph +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma graphCandidate_iff {n : ℕ} (G : Graph n) (focus : Graph n) + (parent : Option (Finset (Fin n))) (p : Finset (Fin n) × Finset (Fin n)) : + p ∈ gridCandidates (triangleHypergraph G) focus parent ↔ + p.1 ∈ focus ∧ p.2 ∈ triangles G ∧ p.1 ∈ p.2.powersetCard 2 ∧ some p.2 ≠ parent := by + rcases p with ⟨e,T⟩ + simp only [gridCandidates,Finset.mem_filter,Finset.product_eq_sprod,Finset.mem_product,Finset.mem_univ,and_true] + by_cases ht : T ∈ triangles G + · simp only [triangleHypergraph,ht,↓reduceIte,true_and] + · simp only [triangleHypergraph,ht,↓reduceIte,Finset.notMem_empty,false_and,and_false] + +lemma triangle_third_exists {α : Type*} [DecidableEq α] {T e : Finset α} + (hT : T.card = 3) (he : e ∈ T.powersetCard 2) : + ∃ x, x ∉ e ∧ T = insert x e := by + obtain ⟨heT,hce⟩ := Finset.mem_powersetCard.mp he + have hdiff : (T \ e).card = 1 := by + rw [Finset.card_sdiff,Finset.inter_eq_left.mpr heT,hT,hce] + obtain ⟨x,hx⟩ := Finset.card_eq_one.mp hdiff + have hxm : x ∈ T \ e := by rw [hx]; simp + refine ⟨x,(Finset.mem_sdiff.mp hxm).2,?_⟩ + have hh := Finset.sdiff_union_of_subset heT + rw [hx,Finset.singleton_union] at hh + exact hh.symm + +noncomputable def triangleThird {α : Type*} [DecidableEq α] (T e : Finset α) + (hT : T.card = 3) (he : e ∈ T.powersetCard 2) : α := + (triangle_third_exists hT he).choose + +lemma triangleThird_spec {α : Type*} [DecidableEq α] (T e : Finset α) + (hT : T.card = 3) (he : e ∈ T.powersetCard 2) : + triangleThird T e hT he ∉ e ∧ T = insert (triangleThird T e hT he) e := + (triangle_third_exists hT he).choose_spec + +namespace RecordedCallForest +section Incoming +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] +variable {H : τ → Finset ι} {c : QueryCall ι τ} (F : RecordedCallForest H c) + +noncomputable def incoming (i : Fin F.size) (hi : i ≠ F.root) : ι × τ := + (F.is_child i hi).choose + +theorem incoming_spec (i : Fin F.size) (hi : i ≠ F.root) : + F.incoming i hi ∈ gridCandidates H (F.call (F.parent i hi)).focus + (F.call (F.parent i hi)).parent ∧ + F.call i = ⟨F.incoming i hi :: (F.call (F.parent i hi)).address, + (H (F.incoming i hi).2).erase (F.incoming i hi).1,some (F.incoming i hi).2⟩ := + (F.is_child i hi).choose_spec + +theorem incoming_unique (i j : Fin F.size) (hi : i ≠ F.root) (hj : j ≠ F.root) + (hp : F.parent i hi = F.parent j hj) (he : F.incoming i hi = F.incoming j hj) : i = j := by + apply F.address_injective + change (F.call i).address = (F.call j).address + rw [(F.incoming_spec i hi).2,(F.incoming_spec j hj).2] + simp only [hp,he] + +end Incoming + +section GraphIncoming +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) + +lemma incoming_graph (i : Fin F.size) (hi : i ≠ F.root) : + (F.incoming i hi).1 ∈ (F.call (F.parent i hi)).focus ∧ + (F.incoming i hi).2 ∈ triangles G ∧ + (F.incoming i hi).1 ∈ (F.incoming i hi).2.powersetCard 2 ∧ + some (F.incoming i hi).2 ≠ (F.call (F.parent i hi)).parent := + (graphCandidate_iff G _ _ _).mp (F.incoming_spec i hi).1 + +noncomputable def newVertex (i : Fin F.size) (hi : i ≠ F.root) : Fin n := + triangleThird (F.incoming i hi).2 (F.incoming i hi).1 + (mem_triangles.mp (F.incoming_graph i hi).2.1).1 (F.incoming_graph i hi).2.2.1 + +lemma newVertex_spec (i : Fin F.size) (hi : i ≠ F.root) : + F.newVertex i hi ∉ (F.incoming i hi).1 ∧ + (F.incoming i hi).2 = insert (F.newVertex i hi) (F.incoming i hi).1 := + triangleThird_spec _ _ _ _ + +lemma incoming_card (i : Fin F.size) (hi : i ≠ F.root) : + (F.incoming i hi).1.card = 2 := + (Finset.mem_powersetCard.mp (F.incoming_graph i hi).2.2.1).2 + +lemma incoming_parent (i : Fin F.size) (hi : i ≠ F.root) : + (F.call i).parent = some (F.incoming i hi).2 := by + rw [(F.incoming_spec i hi).2] + +lemma incoming_focus (i : Fin F.size) (hi : i ≠ F.root) : + (F.call i).focus = ((F.incoming i hi).2.powersetCard 2).erase (F.incoming i hi).1 := by + rw [(F.incoming_spec i hi).2] + simp only [triangleHypergraph,(F.incoming_graph i hi).2.1,↓reduceIte] + +lemma incoming_of_nonroot_parent (i : Fin F.size) (hi : i ≠ F.root) + (hp : F.parent i hi ≠ F.root) : + (F.incoming i hi).1 ⊆ insert (F.newVertex (F.parent i hi) hp) + (F.incoming (F.parent i hi) hp).1 ∧ + (F.incoming i hi).1 ≠ (F.incoming (F.parent i hi) hp).1 ∧ + (F.incoming i hi).2 ≠ (F.incoming (F.parent i hi) hp).2 := by + have hc := F.incoming_graph i hi + rw [F.incoming_focus _ hp] at hc + obtain ⟨hediff,hepow⟩ := Finset.mem_erase.mp hc.1 + refine ⟨?_,hediff,?_⟩ + · rw [← (F.newVertex_spec _ hp).2] + exact (Finset.mem_powersetCard.mp hepow).1 + · rw [F.incoming_parent _ hp] at hc + exact fun he => hc.2.2.2 (congrArg some he) + +end GraphIncoming +end RecordedCallForest +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/TripleFactorBounds.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/TripleFactorBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..daa947481214b65579e4272d3768396c5b801d1b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/TripleFactorBounds.lean @@ -0,0 +1,130 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +section +open Filter MeasureTheory +open scoped BigOperators Topology BoundedContinuousFunction +open scoped BigOperators + +namespace SharpTerminalLeave + +theorem triple_factor_bounds {a b c ε : ℝ} + (hε : ε ≤ 1 / 2) (ha : a ∈ Set.Icc 0 ε) + (hb : b ∈ Set.Icc 0 ε) (hc : c ∈ Set.Icc 0 ε) : + 1 / 8 ≤ (1 - a) * (1 - b) * (1 - c) ∧ + (1 - a) * (1 - b) * (1 - c) ≤ 1 ∧ + |1 - (1 - a) * (1 - b) * (1 - c)| ≤ 3 * ε := by + have ha' : 1 / 2 ≤ 1 - a := by linarith [ha.2] + have hb' : 1 / 2 ≤ 1 - b := by linarith [hb.2] + have hc' : 1 / 2 ≤ 1 - c := by linarith [hc.2] + have hab : 1 / 4 ≤ (1 - a) * (1 - b) := by + nlinarith [mul_le_mul ha' hb' (by norm_num : (0 : ℝ) ≤ 1 / 2) (by linarith : 0 ≤ 1 - a)] + have hl : 1 / 8 ≤ (1 - a) * (1 - b) * (1 - c) := by + nlinarith [mul_le_mul hab hc' (by norm_num : (0 : ℝ) ≤ 1 / 2) + (by linarith : 0 ≤ (1 - a) * (1 - b))] + have hab1 : (1 - a) * (1 - b) ≤ 1 := by + nlinarith [mul_le_mul (by linarith [ha.1] : 1 - a ≤ 1) + (by linarith [hb.1] : 1 - b ≤ 1) (by linarith : 0 ≤ 1 - b) zero_le_one] + have hu : (1 - a) * (1 - b) * (1 - c) ≤ 1 := by + nlinarith [mul_le_mul hab1 (by linarith [hc.1] : 1 - c ≤ 1) + (by linarith : 0 ≤ 1 - c) zero_le_one] + refine ⟨hl, hu, ?_⟩ + rw [abs_of_nonneg (sub_nonneg.mpr hu)] + have hx : 0 ≤ a * b * (1 - c) := + mul_nonneg (mul_nonneg ha.1 hb.1) (by linarith) + have hy := mul_nonneg ha.1 hc.1 + have hz := mul_nonneg hb.1 hc.1 + nlinarith [ha.2, hb.2, hc.2] + +theorem cavity_summand_taylor {x y a b c δ ε : ℝ} + (hδ : δ ≤ 1 / 2) (hx : |x| ≤ δ) (hy : |y| ≤ δ) + (hε : ε ≤ 1 / 2) (ha : a ∈ Set.Icc 0 ε) + (hb : b ∈ Set.Icc 0 ε) (hc : c ∈ Set.Icc 0 ε) : + |Real.exp (x + y) / ((1 - a) * (1 - b) * (1 - c)) - 1 - x - y| ≤ + 32 * δ ^ 2 + 48 * ε := by + let P := (1 - a) * (1 - b) * (1 - c) + have hp := triple_factor_bounds hε ha hb hc + have hp0 : 0 < P := by dsimp [P]; linarith [hp.1] + have hδ0 : 0 ≤ δ := (abs_nonneg x).trans hx + have hε0 : 0 ≤ ε := ha.1.trans ha.2 + have hxy : |x + y| ≤ 2 * δ := (abs_add_le x y).trans (by linarith) + have he : |Real.exp (x + y) - 1 - (x + y)| ≤ 4 * δ ^ 2 := by + apply (Real.abs_exp_sub_one_sub_id_le (hxy.trans (by linarith))).trans + have hh := sq_le_sq.mpr (show |x + y| ≤ |2 * δ| by + rw [abs_mul, abs_of_pos (by norm_num : (0 : ℝ) < 2), abs_of_nonneg hδ0] + exact hxy) + nlinarith + have hlin : |1 + x + y| ≤ 2 := by + calc + _ = |1 + (x + y)| := by congr 1; ring + _ ≤ |(1 : ℝ)| + |x + y| := abs_add_le _ _ + _ ≤ 2 := by norm_num; linarith + have hPinv : P⁻¹ ≤ 8 := by + rw [← one_div] + apply (div_le_iff₀ hp0).mpr + dsimp [P] + linarith [hp.1] + have hPinv0 : 0 ≤ P⁻¹ := inv_nonneg.mpr hp0.le + calc + _ = |(Real.exp (x + y) - 1 - (x + y)) * P⁻¹ + + (1 + x + y) * ((1 - P) * P⁻¹)| := by + congr 1 + change Real.exp (x + y) / P - 1 - x - y = _ + field_simp [hp0.ne'] + ring + _ ≤ |Real.exp (x + y) - 1 - (x + y)| * P⁻¹ + + |1 + x + y| * (|1 - P| * P⁻¹) := by + simpa only [abs_mul, abs_of_nonneg hPinv0] using abs_add_le + ((Real.exp (x + y) - 1 - (x + y)) * P⁻¹) + ((1 + x + y) * ((1 - P) * P⁻¹)) + _ ≤ (4 * δ ^ 2) * 8 + 2 * ((3 * ε) * 8) := by + apply add_le_add + · exact mul_le_mul he hPinv hPinv0 (by positivity) + · exact mul_le_mul hlin + (mul_le_mul hp.2.2 hPinv hPinv0 (by positivity)) + (mul_nonneg (abs_nonneg _) hPinv0) (by norm_num) + _ = _ := by ring + +theorem cavity_row_error {τ : Type*} (S : Finset τ) (R L : τ → ℝ) + {D η B : ℝ} (hD : 0 < D) (hB : 0 ≤ B) + (hdegree : |(S.card : ℝ) / D - 1| ≤ η) + (hrow : (S.card : ℝ) / D ≤ 2) + (hterm : ∀ T ∈ S, |R T - 1 - L T| ≤ B) : + |1 - (1 / D) * (∑ T ∈ S, R T) + (1 / D) * (∑ T ∈ S, L T)| ≤ + η + 2 * B := by + have heq : 1 - (1 / D) * (∑ T ∈ S, R T) + (1 / D) * (∑ T ∈ S, L T) = + -(S.card / D - 1) - (1 / D) * (∑ T ∈ S, (R T - 1 - L T)) := by + simp only [Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul, mul_one] + ring + rw [heq] + calc + _ ≤ |(S.card : ℝ) / D - 1| + |(1 / D) * (∑ T ∈ S, (R T - 1 - L T))| := by + simpa only [sub_eq_add_neg, abs_neg] using abs_add_le (-(S.card / D - 1)) + (-((1 / D) * (∑ T ∈ S, (R T - 1 - L T)))) + _ ≤ η + (1 / D) * (S.card * B) := by + apply add_le_add hdegree + rw [abs_mul, abs_of_pos (one_div_pos.mpr hD)] + apply mul_le_mul_of_nonneg_left _ (one_div_nonneg.mpr hD.le) + exact (Finset.abs_sum_le_sum_abs _ _).trans (by + simpa only [Finset.sum_const, nsmul_eq_mul] using Finset.sum_le_sum hterm) + _ ≤ η + 2 * B := by + calc + _ = η + (S.card / D) * B := by ring + _ ≤ _ := by linarith [mul_le_mul_of_nonneg_right hrow hB] + +end SharpTerminalLeave + +open Filter MeasureTheory +open scoped Topology + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/UnitLineRemainder.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/UnitLineRemainder.lean new file mode 100644 index 0000000000000000000000000000000000000000..cd66c67447ac79346fd410359cde064637f1715c --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/UnitLineRemainder.lean @@ -0,0 +1,101 @@ +import Mathlib + +namespace OAI + +section +section +open Filter +open scoped BigOperators Topology +open InnerProductSpace +open scoped InnerProductSpace + +namespace SharpTerminalLeave + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +theorem unit_line_remainder (v j : E) (hv : ‖v‖ = 1) (hj : ‖j‖ = 1) : + ‖inner ℝ v j • v‖ ≤ 1 ∧ + ‖j - inner ℝ v j • v‖ ^ 2 = 1 - (inner ℝ v j) ^ 2 ∧ + ‖j - inner ℝ v j • v‖ ≤ 1 := by + have hb : |inner ℝ v j| ≤ 1 := by + simpa only [hv, hj, one_mul] using abs_real_inner_le_norm v j + have hs : ‖j - inner ℝ v j • v‖ ^ 2 = 1 - (inner ℝ v j) ^ 2 := by + rw [norm_sub_sq_real, inner_smul_right, real_inner_comm j v, norm_smul, + Real.norm_eq_abs, hv, hj] + rw [mul_one, one_pow, sq_abs] + ring + refine ⟨by simpa [norm_smul, hv, Real.norm_eq_abs] using hb, hs, ?_⟩ + have hn := norm_nonneg (j - inner ℝ v j • v) + nlinarith [sq_nonneg (inner ℝ v j)] + +theorem unit_projector_difference (v j : E) (hv : ‖v‖ = 1) (hj : ‖j‖ = 1) : + ‖rankOne ℝ j j - rankOne ℝ v v‖ ≤ 3 * ‖j - rankOne ℝ v v j‖ := by + let a : ℝ := inner ℝ v j + let p : E := a • v + have hp := unit_line_remainder v j hv hj + change ‖p‖ ≤ 1 ∧ ‖j - p‖ ^ 2 = 1 - a ^ 2 ∧ ‖j - p‖ ≤ 1 at hp + have heq : rankOne ℝ j j - rankOne ℝ v v = + rankOne ℝ (j - p) j + rankOne ℝ p (j - p) + + (a ^ 2 - 1) • rankOne ℝ v v := by + ext x + simp only [add_apply, sub_apply, + smul_apply, rankOne_apply, inner_sub_left, + real_inner_smul_left, p] + simp only [smul_sub, smul_smul] + module + have habs : |a ^ 2 - 1| = ‖j - p‖ ^ 2 := by + have ha : a ^ 2 ≤ 1 := by nlinarith [sq_nonneg ‖j - p‖, hp.2.1] + rw [abs_of_nonpos (sub_nonpos.mpr ha)] + linarith [hp.2.1] + change ‖rankOne ℝ j j - rankOne ℝ v v‖ ≤ 3 * ‖j - p‖ + rw [heq] + calc + _ ≤ ‖rankOne ℝ (j - p) j‖ + ‖rankOne ℝ p (j - p)‖ + + ‖(a ^ 2 - 1) • rankOne ℝ v v‖ := norm_add₃_le + _ = ‖j - p‖ + ‖p‖ * ‖j - p‖ + ‖j - p‖ ^ 2 := by + simp only [norm_rankOne, norm_smul, Real.norm_eq_abs, hj, hv, mul_one, habs] + _ ≤ 3 * ‖j - p‖ := by + have hmul := mul_le_mul_of_nonneg_right hp.1 (norm_nonneg (j - p)) + have hsq := mul_le_mul_of_nonneg_left hp.2.2 (norm_nonneg (j - p)) + nlinarith + +theorem projector_transfer (B : E →L[ℝ] E) (v j : E) + (hv : ‖v‖ = 1) (hj : ‖j‖ = 1) (lam θ δ ε : ℝ) + (hB : ‖B - lam • rankOne ℝ v v‖ ≤ θ) + (hlam : |lam - 1| ≤ δ) (hjB : ‖B j - j‖ ≤ ε) : + ‖B - rankOne ℝ j j‖ ≤ 4 * (θ + δ) + 3 * ε := by + let P : E →L[ℝ] E := rankOne ℝ v v + have hP : ‖P‖ = 1 := by simp [P, norm_rankOne, hv] + have hBP : ‖B - P‖ ≤ θ + δ := by + calc + _ = ‖(B - lam • P) + (lam - 1) • P‖ := by congr 1; module + _ ≤ ‖B - lam • P‖ + ‖(lam - 1) • P‖ := norm_add_le _ _ + _ ≤ θ + δ := by + simpa only [norm_smul, Real.norm_eq_abs, hP, mul_one] using (add_le_add hB hlam) + have hw : ‖j - P j‖ ≤ ε + θ + δ := by + calc + _ = ‖(j - B j) + (B - P) j‖ := by congr 1; simp + _ ≤ ‖j - B j‖ + ‖(B - P) j‖ := norm_add_le _ _ + _ ≤ ε + (θ + δ) * ‖j‖ := by + apply add_le_add + · simpa only [norm_sub_rev] using hjB + · exact ((B - P).le_opNorm j).trans + (mul_le_mul_of_nonneg_right hBP (norm_nonneg j)) + _ = ε + θ + δ := by rw [hj]; ring + have hPJ := unit_projector_difference v j hv hj + calc + _ = ‖(B - P) + (P - rankOne ℝ j j)‖ := by congr 1; abel + _ ≤ ‖B - P‖ + ‖P - rankOne ℝ j j‖ := norm_add_le _ _ + _ ≤ (θ + δ) + 3 * ‖j - P j‖ := add_le_add hBP (by + simpa only [norm_sub_rev] using hPJ) + _ ≤ 4 * (θ + δ) + 3 * ε := by linarith + +end SharpTerminalLeave + +open scoped BigOperators Matrix.Norms.L2Operator +open Matrix + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ValidAttachments.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ValidAttachments.lean new file mode 100644 index 0000000000000000000000000000000000000000..5d9e18d71c57bba27d525f37d470a804ce974dcc --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ValidAttachments.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.PathForest +import OAI.Combinatorics.TriangleRemoval.Process.LocalChoiceRank + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def ValidAttachments {R s : ℕ} (E : Finset (Finset (Fin (R+s)))) + (F : PathForest s) (f : Fin s → Finset (Fin (R+s))) : Prop := + (∀ i, (f i).card ≤ 2) ∧ ∀ i, + match F.parent i with + | none => f i ∈ E + | some p => ∃ u ∈ f p, f i = {⟨R+p.val,by omega⟩,u} + +noncomputable def attachmentFamily {R s : ℕ} (E : Finset (Finset (Fin (R+s)))) + (F : PathForest s) : Finset (Fin s → Finset (Fin (R+s))) := by + classical + exact Finset.univ.filter (ValidAttachments E F) + +@[simp] lemma mem_attachmentFamily {R s : ℕ} (E : Finset (Finset (Fin (R+s)))) + (F : PathForest s) (f : Fin s → Finset (Fin (R+s))) : + f ∈ attachmentFamily E F ↔ ValidAttachments E F f := by + classical + simp only [attachmentFamily,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma mem_prefixChoiceValues {n : ℕ} {α : Type*} + (S : Finset (Fin n → α)) (f : Fin n → α) (i : Fin n) (a : α) : + a ∈ prefixChoiceValues S f i ↔ ∃ g ∈ S, (∀ j, j < i → g j = f j) ∧ g i = a := by + classical + simp only [prefixChoiceValues,Finset.mem_image,Finset.mem_filter] + aesop + +lemma attachment_choices_le_two {R s : ℕ} (E : Finset (Finset (Fin (R+s)))) + (hE : E.card ≤ 2) (F : PathForest s) (f : Fin s → Finset (Fin (R+s))) + (hf : f ∈ attachmentFamily E F) (i : Fin s) : + (prefixChoiceValues (attachmentFamily E F) f i).card ≤ 2 := by + classical + have hf' : ValidAttachments E F f := (mem_attachmentFamily _ _ _).mp hf + cases hp : F.parent i with + | none => + apply (Finset.card_le_card (t := E) ?_).trans hE + intro e he + obtain ⟨g,hg,_,rfl⟩ := (mem_prefixChoiceValues _ _ _ _).mp he + have hvalid : ValidAttachments E F g := (mem_attachmentFamily _ _ _).mp hg + simpa only [hp] using hvalid.2 i + | some p => + let C : Finset (Finset (Fin (R+s))) := + (f p).image (fun u => {⟨R+p.val,by omega⟩,u}) + have hsub : prefixChoiceValues (attachmentFamily E F) f i ⊆ C := by + intro e he + obtain ⟨g,hgS,hprev,rfl⟩ := (mem_prefixChoiceValues _ _ _ _).mp he + have hvalid : ValidAttachments E F g := (mem_attachmentFamily _ _ _).mp hgS + have hgp : g p = f p := hprev p (F.property i p hp) + have hgi := hvalid.2 i + rw [hp] at hgi + obtain ⟨u,hu,heq⟩ := hgi + exact Finset.mem_image.mpr ⟨u,by simpa only [hgp] using hu,heq.symm⟩ + exact (Finset.card_le_card hsub).trans ((Finset.card_image_le).trans (hf'.1 p)) + +theorem fixed_forest_attachment_count {R s : ℕ} (E : Finset (Finset (Fin (R+s)))) + (hE : E.card ≤ 2) (F : PathForest s) : (attachmentFamily E F).card ≤ 2^s := + finite_branching_family_bound _ 2 (attachment_choices_le_two E hE F) + +open Classical in + +theorem marked_attachment_pattern_count {R s : ℕ} + (E : Finset (Finset (Fin (R+s)))) (hE : E.card ≤ 2) (a b : Option (Fin s)) : + Fintype.card (Σ F : {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v}, + {f // f ∈ attachmentFamily E F.val}) ≤ 6^s := by + classical + rw [Fintype.card_sigma] + calc + ∑ F : {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v}, + Fintype.card {f // f ∈ attachmentFamily E F.val} + ≤ ∑ _F : {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v}, 2^s := by + apply Finset.sum_le_sum + intro F _ + simpa only [Fintype.card_coe] using fixed_forest_attachment_count E hE F.val + _ = Fintype.card {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v} * 2^s := by + simp only [Finset.sum_const,Finset.card_univ,smul_eq_mul] + _ ≤ 3^s * 2^s := Nat.mul_le_mul_right _ (PathForest.two_path_forest_count a b) + _ = 6^s := by rw [← Nat.mul_pow] + +open Classical in + +theorem all_marked_attachment_pattern_count {R s : ℕ} {M : Type*} [Fintype M] + (E : Finset (Finset (Fin (R+s)))) (hE : E.card ≤ 2) (mark : M → Option (Fin s)) : + Fintype.card (Σ ab : M × M, + Σ F : {F : PathForest s // ∀ v, F.OnPath (mark ab.1) v ∨ F.OnPath (mark ab.2) v}, + {f // f ∈ attachmentFamily E F.val}) ≤ (Fintype.card M)^2 * 6^s := by + classical + rw [Fintype.card_sigma] + calc + _ ≤ ∑ _ab : M × M, 6^s := by + apply Finset.sum_le_sum + intro ab _ + exact marked_attachment_pattern_count E hE _ _ + _ = (Fintype.card M)^2 * 6^s := by + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_prod,smul_eq_mul,pow_two] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/ValidIndexedAttachments.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/ValidIndexedAttachments.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c095f1534a13f2fa9d089fda06499b0caa55ad6 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/ValidIndexedAttachments.lean @@ -0,0 +1,75 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.ValidAttachments + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +def ValidIndexedAttachments {K s : ℕ} (E : Finset (Finset (Fin K))) (birth : Fin s → Fin K) + (F : PathForest s) (f : Fin s → Finset (Fin K)) : Prop := + (∀ i, (f i).card ≤ 2) ∧ ∀ i, + match F.parent i with + | none => f i ∈ E + | some p => ∃ u ∈ f p, f i = {birth p,u} + +noncomputable def indexedAttachmentFamily {K s : ℕ} (E : Finset (Finset (Fin K))) (birth : Fin s → Fin K) + (F : PathForest s) : Finset (Fin s → Finset (Fin K)) := by + classical + exact Finset.univ.filter (ValidIndexedAttachments E birth F) + +@[simp] lemma mem_indexedAttachmentFamily {K s : ℕ} (E : Finset (Finset (Fin K))) (birth : Fin s → Fin K) + (F : PathForest s) (f : Fin s → Finset (Fin K)) : + f ∈ indexedAttachmentFamily E birth F ↔ ValidIndexedAttachments E birth F f := by + classical + simp only [indexedAttachmentFamily,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma indexed_attachment_choices_le_two {K s : ℕ} (E : Finset (Finset (Fin K))) (birth : Fin s → Fin K) + (hE : E.card ≤ 2) (F : PathForest s) (f : Fin s → Finset (Fin K)) + (hf : f ∈ indexedAttachmentFamily E birth F) (i : Fin s) : + (prefixChoiceValues (indexedAttachmentFamily E birth F) f i).card ≤ 2 := by + classical + have hf' : ValidIndexedAttachments E birth F f := (mem_indexedAttachmentFamily _ _ _ _).mp hf + cases hp : F.parent i with + | none => + apply (Finset.card_le_card (t := E) ?_).trans hE + intro e he + obtain ⟨g,hg,_,rfl⟩ := (mem_prefixChoiceValues _ _ _ _).mp he + have hvalid : ValidIndexedAttachments E birth F g := (mem_indexedAttachmentFamily _ _ _ _).mp hg + simpa only [hp] using hvalid.2 i + | some p => + let C : Finset (Finset (Fin K)) := + (f p).image (fun u => {birth p,u}) + have hsub : prefixChoiceValues (indexedAttachmentFamily E birth F) f i ⊆ C := by + intro e he + obtain ⟨g,hgS,hprev,rfl⟩ := (mem_prefixChoiceValues _ _ _ _).mp he + have hvalid : ValidIndexedAttachments E birth F g := (mem_indexedAttachmentFamily _ _ _ _).mp hgS + have hgp : g p = f p := hprev p (F.property i p hp) + have hgi := hvalid.2 i + rw [hp] at hgi + obtain ⟨u,hu,heq⟩ := hgi + exact Finset.mem_image.mpr ⟨u,by simpa only [hgp] using hu,heq.symm⟩ + exact (Finset.card_le_card hsub).trans ((Finset.card_image_le).trans (hf'.1 p)) + +theorem fixed_forest_indexed_attachment_count {K s : ℕ} (E : Finset (Finset (Fin K))) (birth : Fin s → Fin K) + (hE : E.card ≤ 2) (F : PathForest s) : (indexedAttachmentFamily E birth F).card ≤ 2^s := + finite_branching_family_bound _ 2 (indexed_attachment_choices_le_two E birth hE F) + +end SharpTerminalLeave + +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/VariationConstants.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/VariationConstants.lean new file mode 100644 index 0000000000000000000000000000000000000000..44ba08637e46b0f2455a58661445ee4b68c121b6 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/VariationConstants.lean @@ -0,0 +1,106 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology + +section +open scoped BigOperators Topology BoundedContinuousFunction +open scoped BigOperators +open Filter MeasureTheory +open scoped Topology + +namespace SharpTerminalLeave + +section Forcing +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + +theorem variation_of_constants (A : E →L[ℝ] E) (z f : ℝ → E) + {s : ℝ} (hs : 0 ≤ s) (hz : ContinuousOn z (Set.Icc 0 s)) + (hf : ContinuousOn f (Set.Icc 0 s)) + (hd : ∀ t ∈ Set.Ioo 0 s, HasDerivAt z (-A (z t) + f t) t) : + z s = NormedSpace.exp ((-s) • A) (z 0) + + ∫ t in (0 : ℝ)..s, NormedSpace.exp ((t - s) • A) (f t) := by + let w : ℝ → E := fun t => NormedSpace.exp ((t - s) • A) (z t) + let g : ℝ → E := fun t => NormedSpace.exp ((t - s) • A) (f t) + have he : Continuous (fun t : ℝ => NormedSpace.exp ((t - s) • A)) := + (differentiable_exp_smul_const ℝ A).continuous.comp + (continuous_id.sub continuous_const) + have hw : ContinuousOn w (Set.Icc 0 s) := he.continuousOn.clm_apply hz + have hg : ContinuousOn g (Set.Icc 0 s) := he.continuousOn.clm_apply hf + have hw' : ∀ t ∈ Set.Ioo 0 s, HasDerivAt w (g t) t := by + intro t ht + have he' := (hasDerivAt_exp_smul_const (𝕂 := ℝ) A (t - s)).scomp t + ((hasDerivAt_id t).sub_const s) + have hh := he'.clm_apply (hd t ht) + simp only [Function.comp_apply, id_eq, one_smul] at hh + convert hh using 1 + simp [g, map_add, map_neg] + have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hs hw hw' + (hg.intervalIntegrable_of_Icc hs) + simp only [w, sub_self, zero_smul, NormedSpace.exp_zero, + one_apply_eq_self, zero_sub] at hi + change z s = _ + ∫ t in (0 : ℝ)..s, g t + rw [hi] + abel + +theorem forcing_norm_bound (A : E →L[ℝ] E) (z f : ℝ → E) + {s K d : ℝ} (hs : 0 ≤ s) (hK : 0 ≤ K) + (hz : ContinuousOn z (Set.Icc 0 s)) (hf : ContinuousOn f (Set.Icc 0 s)) + (hz0 : z 0 = 0) + (hd : ∀ t ∈ Set.Ioo 0 s, HasDerivAt z (-A (z t) + f t) t) + (hsem : ∀ u ∈ Set.Icc 0 s, ‖NormedSpace.exp ((-u) • A)‖ ≤ K) + (hforce : ∀ t ∈ Set.Icc 0 s, ‖f t‖ ≤ d) : ‖z s‖ ≤ K * d * s := by + rw [variation_of_constants A z f hs hz hf hd, hz0, map_zero, zero_add] + have hh := intervalIntegral.norm_integral_le_of_norm_le_const + (a := 0) (b := s) (C := K * d) + (f := fun t => NormedSpace.exp ((t - s) • A) (f t)) (by + intro t ht + have ht0 : t ∈ Set.Ioc 0 s := by simpa only [Set.uIoc_of_le hs] using ht + have ht' : t ∈ Set.Icc 0 s := ⟨ht0.1.le, ht0.2⟩ + have hu : s - t ∈ Set.Icc 0 s := ⟨sub_nonneg.mpr ht'.2, by linarith [ht'.1]⟩ + have he : ‖NormedSpace.exp ((t - s) • A)‖ ≤ K := by + simpa only [neg_sub] using hsem (s - t) hu + exact (ContinuousLinearMap.le_opNorm _ _).trans + (mul_le_mul he (hforce t ht') (norm_nonneg _) hK)) + simpa only [sub_zero, abs_of_nonneg hs] using hh + +end Forcing + +theorem strict_bootstrap {Q : ℝ → ℝ} {S δ : ℝ} (hδ : 0 < δ) + (hQ : ContinuousOn Q (Set.Icc 0 S)) (hzero : Q 0 ≤ δ) + (himprove : ∀ t ∈ Set.Icc 0 S, + (∀ u ∈ Set.Icc 0 t, Q u ≤ δ) → Q t ≤ δ / 2) : + ∀ t ∈ Set.Icc 0 S, Q t ≤ δ / 2 := by + let B : Set ℝ := {t | Q t ≤ δ} + have hclosed : IsClosed (B ∩ Set.Icc 0 S) := by + simpa only [B, Set.preimage, Set.mem_Iic, Set.inter_comm] using + hQ.preimage_isClosed_of_isClosed isClosed_Icc isClosed_Iic + have hB : Set.Icc 0 S ⊆ B := by + apply hclosed.Icc_subset_of_forall_mem_nhdsGT_of_Icc_subset hzero + intro t ht hp + have ht' : t ∈ Set.Icc 0 S := ⟨ht.1, ht.2.le⟩ + have him : Q t < δ := lt_of_le_of_lt (himprove t ht' hp) (by linarith) + have hc := hQ t ht' + have hI : Set.Icc 0 S ∈ 𝓝[>] t := by + have hh : Set.Icc t S ∈ 𝓝[≥] t := Icc_mem_nhdsGE ht.2 + exact (nhdsWithin_mono t Set.Ioi_subset_Ici_self) + (Filter.mem_of_superset hh (Set.Icc_subset_Icc_left ht.1)) + have hc' : ContinuousWithinAt Q (Set.Ioi t) t := hc.mono_of_mem_nhdsWithin hI + have hsmall : ∀ᶠ u in 𝓝[>] t, Q u < δ := hc' (Iio_mem_nhds him) + exact hsmall.mono (fun _ hu => hu.le) + intro t ht + apply himprove t ht + intro u hu + exact hB ⟨hu.1, hu.2.trans ht.2⟩ + +end SharpTerminalLeave + +end +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/Within.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/Within.lean new file mode 100644 index 0000000000000000000000000000000000000000..822cf9f6f59cc704a42b811d7d6749a29b22f0a0 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/Within.lean @@ -0,0 +1,133 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.BirthGraph +import OAI.Combinatorics.TriangleRemoval.Process.BornEdges + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.BirthGraph +variable {N : ℕ} (B : BirthGraph N) + +def Within (Z : Finset (Fin N)) (x y : Fin N) : Prop := + Relation.ReflTransGen (fun x y => x ∈ Z ∧ y ∈ Z ∧ x ∈ B.older y) x y + +def Covered (Z : Finset (Fin N)) (a b : Fin N) : Prop := + ∀ z ∈ Z, (a ∈ Z ∧ B.Within Z z a) ∨ (b ∈ Z ∧ B.Within Z z b) + +theorem within_closed {Z U : Finset (Fin N)} {x y : Fin N} + (h : B.Within Z x y) + (hclosed : ∀ v ∈ U, ∀ u ∈ B.older v, u ∈ Z → u ∈ U) (hy : y ∈ U) : x ∈ U := by + induction h using Relation.ReflTransGen.head_induction_on with + | refl => exact hy + | @head x c hxc _ ih => exact hclosed c ih x hxc.2.2 hxc.1 + +theorem covered_closed {Z U : Finset (Fin N)} {a b : Fin N} + (hc : B.Covered Z a b) (ha : a ∈ Z → a ∈ U) (hb : b ∈ Z → b ∈ U) + (hclosed : ∀ v ∈ U, ∀ u ∈ B.older v, u ∈ Z → u ∈ U) : Z ⊆ U := by + intro z hz + rcases hc z hz with ⟨haZ, hza⟩ | ⟨hbZ, hzb⟩ + · exact B.within_closed hza hclosed (ha haZ) + · exact B.within_closed hzb hclosed (hb hbZ) + +theorem retained_backEdges_subset {Z I U : Finset (Fin N)} (hI : Disjoint I Z) : + ((B.backEdges Z).filter (fun e => e ⊆ I ∪ U)) ⊆ B.backEdges U := by + intro e he + obtain ⟨heZ, heIU⟩ := Finset.mem_filter.mp he + obtain ⟨v, hvZ, u, hu, rfl⟩ := B.backEdges_mem_pair heZ + have hvIU : v ∈ I ∪ U := heIU (by simp) + have hvU : v ∈ U := (Finset.mem_union.mp hvIU).resolve_left + (fun hvI => Finset.disjoint_left.mp hI hvI hvZ) + exact Finset.mem_biUnion.mpr ⟨v, hvU, Finset.mem_image.mpr ⟨u, hu, rfl⟩⟩ + +theorem proper_suffix_sparse {Z I U : Finset (Fin N)} {a b : Fin N} + (hI : Disjoint I Z) (hU : U ⊆ Z) (hproper : U ≠ Z) + (hborn : ∀ v ∈ Z, (B.older v).card = 2) (hc : B.Covered Z a b) : + ((insert ({a, b} : Finset (Fin N)) (B.backEdges Z)).filter + (fun e => e ⊆ I ∪ U)).card ≤ 2 * U.card := by + classical + let S := (B.backEdges Z).filter (fun e => e ⊆ I ∪ U) + let T := (insert ({a, b} : Finset (Fin N)) (B.backEdges Z)).filter + (fun e => e ⊆ I ∪ U) + have hS : S ⊆ B.backEdges U := B.retained_backEdges_subset hI + have hUcard : (B.backEdges U).card = 2 * U.card := + B.backEdges_card_eq U (fun v hv => hborn v (hU hv)) + have hST : T ⊆ insert {a, b} S := by + intro e he + obtain ⟨he, heIU⟩ := Finset.mem_filter.mp he + rcases Finset.mem_insert.mp he with rfl | he + · exact Finset.mem_insert_self _ _ + · exact Finset.mem_insert_of_mem (Finset.mem_filter.mpr ⟨he, heIU⟩) + by_contra hfail + have hbig : 2 * U.card < T.card := Nat.lt_of_not_ge hfail + have hmark : ({a, b} : Finset (Fin N)) ⊆ I ∪ U := by + by_contra hn + have hTS : T ⊆ S := by + intro e he + obtain ⟨he, heIU⟩ := Finset.mem_filter.mp he + rcases Finset.mem_insert.mp he with rfl | he + · exact False.elim (hn heIU) + · exact Finset.mem_filter.mpr ⟨he, heIU⟩ + have hh := (Finset.card_le_card hTS).trans (Finset.card_le_card hS) + rw [hUcard] at hh + exact (Nat.not_le_of_gt hbig) hh + have heq : S = B.backEdges U := by + apply Finset.eq_of_subset_of_card_le hS + have hh := (Finset.card_le_card hST).trans (Finset.card_insert_le _ _) + rw [hUcard] + omega + have hclosed : ∀ v ∈ U, ∀ u ∈ B.older v, u ∈ Z → u ∈ U := by + intro v hv u hu huZ + have heU : ({u, v} : Finset (Fin N)) ∈ B.backEdges U := + Finset.mem_biUnion.mpr ⟨v, hv, Finset.mem_image.mpr ⟨u, hu, rfl⟩⟩ + rw [← heq] at heU + have huIU : u ∈ I ∪ U := (Finset.mem_filter.mp heU).2 (by simp) + exact (Finset.mem_union.mp huIU).resolve_left + (fun huI => Finset.disjoint_left.mp hI huI huZ) + have haU : a ∈ Z → a ∈ U := by + intro haZ + exact (Finset.mem_union.mp (hmark (by simp))).resolve_left + (fun haI => Finset.disjoint_left.mp hI haI haZ) + have hbU : b ∈ Z → b ∈ U := by + intro hbZ + exact (Finset.mem_union.mp (hmark (by simp))).resolve_left + (fun hbI => Finset.disjoint_left.mp hI hbI hbZ) + exact hproper (Finset.Subset.antisymm hU (B.covered_closed hc haU hbU hclosed)) + +theorem suffix_edges_card {Z : Finset (Fin N)} {a b : Fin N} + (hborn : ∀ v ∈ Z, (B.older v).card = 2) + (hne : ¬ B.graph.Adj a b) : + (insert ({a, b} : Finset (Fin N)) (B.backEdges Z)).card = 2 * Z.card + 1 := by + have hn : ({a, b} : Finset (Fin N)) ∉ B.backEdges Z := by + intro he + obtain ⟨v, hv, u, hu, huv⟩ := B.backEdges_mem_pair he + have huvn : u ≠ v := ne_of_lt (B.older_lt v u hu) + have hab : a ≠ b := by + intro h + have hc := congrArg Finset.card huv + simp [h, huvn] at hc + have ha : a = u ∨ a = v := by + have hm : a ∈ ({u, v} : Finset (Fin N)) := by rw [← huv]; simp + simpa only [Finset.mem_insert, Finset.mem_singleton] using hm + have hb : b = u ∨ b = v := by + have hm : b ∈ ({u, v} : Finset (Fin N)) := by rw [← huv]; simp + simpa only [Finset.mem_insert, Finset.mem_singleton] using hm + rcases ha with rfl | rfl <;> rcases hb with rfl | rfl + · exact hab rfl + · exact hne (Or.inl hu) + · exact hne (Or.inr hu) + · exact hab rfl + rw [Finset.card_insert_of_notMem hn, B.backEdges_card_eq Z hborn] + +end SharpTerminalLeave.BirthGraph + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessCountEventually.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessCountEventually.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8c2ba133dcd4d0b169a8e9d85d8f3fb5e980fe1 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessCountEventually.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Asymptotics.OneAddLogRpow +import OAI.Combinatorics.TriangleRemoval.Process.Parent +import OAI.Combinatorics.TriangleRemoval.Process.SuffixProjection +import OAI.Combinatorics.TriangleRemoval.Process.BackEdgesCardSplit + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem actual_witness_count_eventually (c C : ℝ) (hc : 0 < c) : + ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c C G → + ∀ r : ℕ, r ≤ 2 → ∀ N : ℕ, ∀ (A : TriangleGrowth (lookupGraph G) N (2*r)), + 2*r ≤ N → (A.seed.backEdges A.roots).card = r → + ∀ a b : Fin N, A.birthGraph.ExtraEdge (lookupGraph G) A.label a b → + ((graphEmbeddingSet (insert ({A.pathIndex a b a (A.left_mem_pathUnion a b), + A.pathIndex a b b (A.right_mem_pathUnion a b)} : Finset _) + ((A.pathPattern a b).backEdges Finset.univ)) G).card : ℝ) ≤ + (4*prefixM n)^r * (2*prefixD n)^(A.pathSuffix a b (2*r)).card / prefixD n^50 := by + filter_upwards [prefix_short_suppression C,prefix_long_suppression C, + prefix_suffix_scaling,prefix_scales_eventually_pos,eventually_ge_atTop (1 : ℕ)] + with n hshort hlong hscale hpos hn + intro G hGood r hr N A hR hseed a b he + let s := (A.pathSuffix a b (2*r)).card + have hcard : (A.pathUnion a b).card = 2*r+s := A.path_card_split a b hR + have hm0 : 0 ≤ prefixM n := by + unfold prefixM + exact div_nonneg (mul_nonneg (sq_nonneg _) hpos.1.le) (by norm_num) + have hD0 : 0 < prefixD n := lt_of_lt_of_le zero_lt_one hpos.2 + have hden : 0 < prefixD n^50 := pow_pos hD0 _ + have hκ0 : 0 ≤ prefixTemplateFactor n C := by unfold prefixTemplateFactor; positivity + have hsmall : (n : ℝ)^(-c) ≤ 1 := + Real.rpow_le_one_of_one_le_of_nonpos (by exact_mod_cast hn) (neg_nonpos.mpr hc.le) + by_cases hs : s < 100 + · have hcap : (A.pathUnion a b).card ≤ prefixTemplateCap := by + rw [hcard] + unfold prefixTemplateCap + omega + have h := A.actual_short_witness_count hGood a b hR hseed he hcap hpos.1.le + (prefixDensity_le_one n) hpos.2 + change _ ≤ prefixTemplateFactor n C * ((2*prefixM n)^r * prefixD n^s * prefixDensity n) at h + have hbase : (2*prefixM n)^r * prefixD n^s ≤ (4*prefixM n)^r * (2*prefixD n)^s := + mul_le_mul (pow_le_pow_left₀ (by positivity) (by nlinarith) r) + (pow_le_pow_left₀ hD0.le (by linarith) s) (by positivity) (by positivity) + calc + _ ≤ prefixTemplateFactor n C * ((2*prefixM n)^r * prefixD n^s * prefixDensity n) := h + _ = (prefixTemplateFactor n C * prefixDensity n) * ((2*prefixM n)^r * prefixD n^s) := by ring + _ ≤ (prefixD n^50)⁻¹ * ((4*prefixM n)^r * (2*prefixD n)^s) := + mul_le_mul hshort hbase (by positivity) (by positivity) + _ = _ := by rw [div_eq_mul_inv]; ring + · have hs100 : 100 ≤ s := Nat.le_of_not_gt hs + let k := 2*r+(s-100) + have hkr : 2*r ≤ k := by dsimp [k]; omega + have hk : k < (A.pathUnion a b).card := by rw [hcard]; dsimp [k]; omega + have hdiff : (A.pathUnion a b).card-k = 100 := by rw [hcard]; dsimp [k]; omega + have hscale' : (n : ℝ)^((A.pathUnion a b).card-k) * + prefixDensity n^(2*((A.pathUnion a b).card-k)+1) ≤ 1 := by + simpa only [hdiff] using hscale + have h := A.actual_long_witness_count hGood hsmall a b hR hseed he k hkr hk + (by rw [hdiff]; norm_num [prefixTemplateCap]) hpos.1.le (prefixDensity_le_one n) hpos.2 hscale' + have hks : k-2*r = s-100 := by dsimp [k]; omega + rw [hks] at h + calc + _ ≤ prefixTemplateFactor n C * ((4*prefixM n)^r * (2*prefixD n)^(s-100)) := h + _ ≤ ((2*prefixD n)^100 / prefixD n^50) * ((4*prefixM n)^r * (2*prefixD n)^(s-100)) := + mul_le_mul_of_nonneg_right hlong (by positivity) + _ = _ := by + have hp : (2*prefixD n)^100 * (2*prefixD n)^(s-100) = (2*prefixD n)^s := by + rw [← pow_add,Nat.add_sub_of_le hs100] + rw [div_mul_eq_mul_div] + congr 1 + calc + _ = (4*prefixM n)^r * ((2*prefixD n)^100 * (2*prefixD n)^(s-100)) := by ring + _ = _ := by rw [hp] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessDimensionEquiv.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessDimensionEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..3131fe11b0f25035ed0614125becca05c224ce2f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessDimensionEquiv.lean @@ -0,0 +1,83 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.WitnessDimensions +import OAI.Combinatorics.TriangleRemoval.Asymptotics.EndpointMarksExponential + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +def witnessDimensionEquiv (R d : ℕ) : WitnessDimensions R d ≃ Fin (2*d+1) where + toFun q := q.val.2 + invFun s := ⟨(⟨R+s.val,by have h := s.isLt; omega⟩,s),rfl⟩ + left_inv q := by + apply Subtype.ext + apply Prod.ext + · apply Fin.ext + exact q.property.symm + · rfl + right_inv _ := rfl + +lemma witness_dimensions_sum {R d : ℕ} (f : ℕ → ℝ) : + (∑ q : WitnessDimensions R d, f q.val.2.val) = + ∑ s ∈ Finset.range (2*d+1), f s := by + rw [← Fin.sum_univ_eq_sum_range] + exact Fintype.sum_equiv (witnessDimensionEquiv R d) _ _ (fun _ => rfl) + +lemma finite_exp_series_le {x : ℝ} (hx : 0 ≤ x) (L : ℕ) : + (∑ s ∈ Finset.range L, x^s/(s.factorial : ℝ)) ≤ Real.exp x := by + exact sum_le_hasSum _ (fun s _ => by positivity) (witness_exp_series x) + +theorem witness_dimensions_weight_sum {R d r : ℕ} {m D C x : ℝ} + (hR : R ≤ 4) (hm : 0 ≤ m) (hD : 0 ≤ D) (hC : 0 ≤ C) (hx : 0 ≤ x) : + (∑ q : WitnessDimensions R d, + 64*(q.val.1.val^2*6^q.val.2.val : ℕ)* + ((4*m)^r*(2*D)^q.val.2.val/D^50)* + (C^3*((3*x)^q.val.2.val/(q.val.2.val.factorial : ℝ)))) ≤ + (2048*(4*m)^r*C^3/D^50)*Real.exp (45*D*x) := by + have hnon : 0 ≤ (2048*(4*m)^r*C^3/D^50) := by positivity + calc + _ ≤ ∑ q : WitnessDimensions R d, + (2048*(4*m)^r*C^3/D^50)*((45*D*x)^q.val.2.val/(q.val.2.val.factorial : ℝ)) := by + apply Finset.sum_le_sum + intro q _ + have hmark := pattern_marks_exponential (s := q.val.2.val) hR + rw [← q.property] at hmark + have hh := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hmark (by norm_num : (0 : ℝ) ≤ 64)) + (show 0 ≤ (4*m)^r*(2*D)^q.val.2.val/D^50 by positivity)) + (show 0 ≤ C^3*((3*x)^q.val.2.val/(q.val.2.val.factorial : ℝ)) by positivity) + apply hh.trans_eq + have hp : (15/2 : ℝ)^q.val.2.val*(2*D)^q.val.2.val*(3*x)^q.val.2.val = + (45*D*x)^q.val.2.val := by + rw [← mul_pow,← mul_pow] + congr 1 + ring + calc + _ = (2048*(4*m)^r*C^3/D^50)* + (((15/2 : ℝ)^q.val.2.val*(2*D)^q.val.2.val*(3*x)^q.val.2.val)/ + (q.val.2.val.factorial : ℝ)) := by ring + _ = _ := by rw [hp] + _ = (2048*(4*m)^r*C^3/D^50)* + (∑ s ∈ Finset.range (2*d+1), (45*D*x)^s/(s.factorial : ℝ)) := by + rw [← Finset.mul_sum, witness_dimensions_sum (R := R) (d := d) + (fun s => (45*D*x)^s/(s.factorial : ℝ))] + _ ≤ _ := mul_le_mul_of_nonneg_left (finite_exp_series_le (by positivity) _) hnon + +end SharpTerminalLeave + +open Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessDimensions.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessDimensions.lean new file mode 100644 index 0000000000000000000000000000000000000000..506a6364aed142c4f82e77eb2ef7bec637450320 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessDimensions.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.CallPath +import OAI.Combinatorics.TriangleRemoval.Queries.CallPathCollisionWitness +import OAI.Combinatorics.TriangleRemoval.Queries.Address +import OAI.Combinatorics.TriangleRemoval.Queries.MemAddressId +import OAI.Combinatorics.TriangleRemoval.Process.IndexedWitnessCode +import OAI.Combinatorics.TriangleRemoval.Process.MatchingSeedFullEdge +import OAI.Combinatorics.TriangleRemoval.Queries.VertexCall + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +abbrev WitnessDimensions (R d : ℕ) := + {q : Fin (R+2*d+1) × Fin (2*d+1) // q.1.val = R+q.2.val} + +def dimensionBirth {R d : ℕ} (q : WitnessDimensions R d) : Fin q.val.2 → Fin q.val.1 := + fun i => ⟨R+i.val,by have hi := i.isLt; have hq := q.property; omega⟩ + +abbrev BoundedEmbeddedWitness {n : ℕ} (G : Graph n) (R d : ℕ) := + Σ q : WitnessDimensions R d, + Σ E : {E : Graph q.val.1 // E ∈ seedPatternChoices q.val.1 R}, + Σ w : IndexedWitnessCode E.val (dimensionBirth q) (suffixProjection q.property), + {ψ : Fin q.val.1 ↪ Fin n // ψ ∈ graphEmbeddingSet (decodeWitnessPattern w).2 G} + +noncomputable instance {n : ℕ} (G : Graph n) (R d : ℕ) : + Fintype (BoundedEmbeddedWitness G R d) := by + classical + unfold BoundedEmbeddedWitness + infer_instance + +def embeddedWitnessPaths {n R d : ℕ} {G : Graph n} (W : BoundedEmbeddedWitness G R d) : + List (Finset (Fin n) × Finset (Fin n)) × List (Finset (Fin n) × Finset (Fin n)) := + let q := W.1 + let w := W.2.2.1 + let ψ := W.2.2.2.val + let key := indexedTriangleKey (dimensionBirth q) w.2.2.val ψ + ((suffixProjection q.property w.1.1).elim [] (w.2.1.val.address key) |>.reverse, + (suffixProjection q.property w.1.2).elim [] (w.2.1.val.address key) |>.reverse) + +theorem traced_repeat_canonical_cover {n : ℕ} (G focus : Graph n) + (parent : Option (Finset (Fin n))) (hM : EdgeMatching focus) (hG : focus ⊆ G) + (hr : focus.card ≤ 2) + (hc : (QueryCall.mk [] focus parent).Separated (triangleHypergraph G)) + (N d k : ℕ) (ν : Finset (Fin n) → PMF (Fin N)) + (z : (Bool × List (QueryCall (Finset (Fin n)) (Finset (Fin n)))) × List (Finset (Fin n))) + (hz : z ∈ (ExposureTree.freshLog ν + (tracedGridQuery (triangleHypergraph G) N d k ⟨[],focus,parent⟩)).support) + (hrep : ExposureTree.repeats ∅ z.2 = true) : + ∃ W : BoundedEmbeddedWitness G (focus.biUnion id).card d, + (∃ a ∈ z.1.2, a.address = (embeddedWitnessPaths W).1.reverse) ∧ + (∃ b ∈ z.1.2, b.address = (embeddedWitnessPaths W).2.reverse) := by + classical + let c : QueryCall (Finset (Fin n)) (Finset (Fin n)) := ⟨[],focus,parent⟩ + let F := extractCallForest (triangleHypergraph G) N d k c ν z hz + let A := F.toTriangleGrowth hM hG + have hR : F.rootCount ≤ F.vertexCount := Nat.le_add_right _ _ + obtain ⟨a,b,he,hi⟩ := traced_graph_path_collision_witness G N d k c hM hG hc ν z hz hrep + have hdepth (i : Fin F.size) : (F.call i).address.length ≤ d := by + obtain ⟨p,hp,he⟩ := tracedGridQuery_legal_path (triangleHypergraph G) N d k c ν hz + (F.call i) (List.get_mem z.1.2 i) + rw [he,callAtPath_address] + simpa only [c,List.append_nil,List.length_reverse] using + (mem_legalPaths (triangleHypergraph G) d focus parent p).mp hp |>.2 + let key := indexedTriangleKey (A.pathBirthIndex a b hR) (A.pathAttachments a b hR) + (A.pathAssignment a b hi) + have hs : (A.pathSuffix a b F.rootCount).card ≤ 2*d := by + have h := (A.pathForest a b).two_mark_size key + (suffixProjection (A.path_card_split a b hR) (A.pathIndex a b a (A.left_mem_pathUnion a b))) + (suffixProjection (A.path_card_split a b hR) (A.pathIndex a b b (A.right_mem_pathUnion a b))) + (A.pathWitnessCode a b hR).2.1.property + rw [F.decoded_mark_address hM hG rfl a b hR hi a (A.left_mem_pathUnion a b), + F.decoded_mark_address hM hG rfl a b hR hi b (A.right_mem_pathUnion a b)] at h + have ha := hdepth (F.vertexCall a) + have hb := hdepth (F.vertexCall b) + omega + let q : WitnessDimensions F.rootCount d := + ⟨(⟨(A.pathUnion a b).card,by rw [A.path_card_split a b hR]; omega⟩, + ⟨(A.pathSuffix a b F.rootCount).card,by omega⟩),A.path_card_split a b hR⟩ + have hseed : (A.seed.backEdges A.roots).card ≤ 2 := by + rw [F.growth_seed_card hM hG] + exact hr + let E : {E : Graph (A.pathUnion a b).card // E ∈ seedPatternChoices (A.pathUnion a b).card F.rootCount} := + ⟨A.pathRootEdges a b,A.pathRootEdges_mem_seedPatternChoices a b hR hseed⟩ + let W : BoundedEmbeddedWitness G F.rootCount d := + ⟨q,E,A.pathWitnessCode a b hR,A.pathAssignment a b hi,A.pathAssignment_mem_decoded hR hi he⟩ + have hleft : (embeddedWitnessPaths W).1.reverse = (F.call (F.vertexCall a)).address := by + change (((suffixProjection (A.path_card_split a b hR) + (A.pathIndex a b a (A.left_mem_pathUnion a b))).elim [] + ((A.pathForest a b).address key)).reverse).reverse = _ + rw [List.reverse_reverse] + exact F.decoded_mark_address hM hG rfl a b hR hi a (A.left_mem_pathUnion a b) + have hright : (embeddedWitnessPaths W).2.reverse = (F.call (F.vertexCall b)).address := by + change (((suffixProjection (A.path_card_split a b hR) + (A.pathIndex a b b (A.right_mem_pathUnion a b))).elim [] + ((A.pathForest a b).address key)).reverse).reverse = _ + rw [List.reverse_reverse] + exact F.decoded_mark_address hM hG rfl a b hR hi b (A.right_mem_pathUnion a b) + exact ⟨W,⟨F.call (F.vertexCall a),List.get_mem z.1.2 _,hleft.symm⟩, + ⟨F.call (F.vertexCall b),List.get_mem z.1.2 _,hright.symm⟩⟩ + +end SharpTerminalLeave + +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessMu.lean b/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessMu.lean new file mode 100644 index 0000000000000000000000000000000000000000..3afe028fc3acd32bce07662043dcf9b296cb1712 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Process/WitnessMu.lean @@ -0,0 +1,63 @@ +import Mathlib + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +theorem witness_exp_series (x : ℝ) : + HasSum (fun j : ℕ => x ^ j / (j.factorial : ℝ)) (Real.exp x) := by + rw [Real.exp_eq_exp_ℝ] + exact NormedSpace.expSeries_div_hasSum_exp x + +theorem three_segment_series (x : ℝ) : + (∑' h : ℕ, ∑' a : ℕ, ∑' b : ℕ, + x ^ (h + a + b) / + ((h.factorial : ℝ) * (a.factorial : ℝ) * (b.factorial : ℝ))) = Real.exp (3 * x) := by + simp_rw [pow_add, ← div_mul_div_comm, tsum_mul_left, tsum_mul_right, + (witness_exp_series x).tsum_eq] + simp only [tsum_mul_left, tsum_mul_right, (witness_exp_series x).tsum_eq] + rw [show (3 : ℝ) * x = x + x + x by ring, Real.exp_add, Real.exp_add] + +noncomputable def witnessMu (D : ℝ) : ℝ := Real.log (1 + 2 * D) / (2 * D) + +theorem witnessMu_nonneg {D : ℝ} (hD : 0 < D) : 0 ≤ witnessMu D := by + exact div_nonneg (Real.log_nonneg (by linarith)) (by positivity) + +theorem witness_length_sum {D : ℝ} (hD : 0 < D) : + (1 + 2 * D) ^ 3 * (∑' h : ℕ, ∑' a : ℕ, ∑' b : ℕ, + (8 * D * witnessMu D) ^ (h + a + b) / + ((h.factorial : ℝ) * (a.factorial : ℝ) * (b.factorial : ℝ))) = + (1 + 2 * D) ^ 15 := by + rw [three_segment_series] + have he : 3 * (8 * D * witnessMu D) = 12 * Real.log (1 + 2 * D) := by + unfold witnessMu + field_simp + ring + rw [he, show (12 : ℝ) = (12 : ℕ) by norm_num, Real.exp_nat_mul, + Real.exp_log (by linarith : 0 < 1 + 2 * D)] + rw [← pow_add] + +theorem witness_power_bound {D : ℝ} (hD : 1 ≤ D) : + (1 + 2 * D) ^ 15 / D ^ 50 ≤ (3 : ℝ) ^ 15 / D ^ 35 := by + have hpos : 0 < D := lt_of_lt_of_le zero_lt_one hD + have hm : (1 + 2 * D) ^ 15 ≤ (3 * D) ^ 15 := + pow_le_pow_left₀ (by positivity) (by linarith) _ + have hh := div_le_div_of_nonneg_right hm (le_of_lt (pow_pos hpos 50)) + apply hh.trans_eq + rw [mul_pow, show 50 = 15 + 35 by norm_num, pow_add] + field_simp + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/Address.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/Address.lean new file mode 100644 index 0000000000000000000000000000000000000000..aa4a13807606e4e68ce8b51298c92d86eb2a13d1 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/Address.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Embeddings.PathBirthIndex +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Process.PathForest +import OAI.Combinatorics.TriangleRemoval.Process.PathPattern + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave +namespace PathForest +variable {s : ℕ} {α : Type*} + +def address (F : PathForest s) (key : Fin s → α) (i : Fin s) : List α := + key i :: match _hp : F.parent i with + | none => [] + | some j => F.address key j +termination_by i.val +decreasing_by exact F.property i j _hp + +lemma address_none (F : PathForest s) (key : Fin s → α) (i : Fin s) + (hp : F.parent i = none) : F.address key i = [key i] := by + rw [address,hp] + +lemma address_some (F : PathForest s) (key : Fin s → α) (i j : Fin s) + (hp : F.parent i = some j) : F.address key i = key i :: F.address key j := by + rw [address,hp] + +lemma address_unique (F : PathForest s) (key : Fin s → α) (ρ : Fin s → List α) + (hρ : ∀ i, ρ i = key i :: (F.parent i).elim [] ρ) (i : Fin s) : + F.address key i = ρ i := by + induction i using (measure (fun i : Fin s => i.val)).wf.induction with + | h i ih => + cases hp : F.parent i with + | none => rw [F.address_none key i hp,hρ i,hp]; rfl + | some j => + rw [F.address_some key i j hp,ih j (F.property i j hp),hρ i,hp] + rfl + +end PathForest + +def indexedTriangleKey {K s n : ℕ} (birth : Fin s → Fin K) + (f : Fin s → Finset (Fin K)) (ψ : Fin K → Fin n) (i : Fin s) : + Finset (Fin n) × Finset (Fin n) := + ((f i).image ψ,insert (ψ (birth i)) ((f i).image ψ)) + +namespace TriangleGrowth +variable {n N R : ℕ} {G : Graph n} (A : TriangleGrowth (lookupGraph G) N R) + +lemma pathAttachments_image (a b : Fin N) (hR : R ≤ N) + (hi : Set.InjOn A.label (A.pathUnion a b)) (i : Fin (A.pathSuffix a b R).card) : + (A.pathAttachments a b hR i).image (A.pathAssignment a b hi) = + A.attach ((A.pathSuffix a b R).orderEmbOfFin rfl i) := by + rw [A.pathAttachments_eq] + change (reindexSet (A.pathUnion a b) _).image + (A.label ∘ (A.pathUnion a b).orderEmbOfFin rfl) = _ + rw [← Finset.image_image,image_reindexSet] + · exact ((A.older_invariants _).2 ((A.mem_pathSuffix a b _ R).mp + ((A.pathSuffix a b R).orderEmbOfFin_mem rfl i)).2).2.1 + · intro x hx + exact A.pathUnion_older_closed ((A.mem_pathSuffix a b _ R).mp + ((A.pathSuffix a b R).orderEmbOfFin_mem rfl i)).1 hx + +lemma indexedTriangleKey_actual (a b : Fin N) (hR : R ≤ N) + (hi : Set.InjOn A.label (A.pathUnion a b)) (i : Fin (A.pathSuffix a b R).card) : + indexedTriangleKey (A.pathBirthIndex a b hR) (A.pathAttachments a b hR) + (A.pathAssignment a b hi) i = + (A.attach ((A.pathSuffix a b R).orderEmbOfFin rfl i), + insert (A.label ((A.pathSuffix a b R).orderEmbOfFin rfl i)) + (A.attach ((A.pathSuffix a b R).orderEmbOfFin rfl i))) := by + unfold indexedTriangleKey + rw [A.pathAttachments_image] + change (_,insert (A.label ((A.pathUnion a b).orderEmbOfFin rfl _)) _) = _ + rw [A.pathBirthIndex_embedding] + +end TriangleGrowth +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/AddressHead.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/AddressHead.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ea65b1ddd064d11b91b09196378f1e2e111827a --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/AddressHead.lean @@ -0,0 +1,124 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.IndexedWitnessCode +import OAI.Combinatorics.TriangleRemoval.Queries.Address +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixCodeSet + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.PathForest +variable {s : ℕ} {α : Type*} [DecidableEq α] + +omit [DecidableEq α] in +lemma address_head (F : PathForest s) (key : Fin s → α) (i : Fin s) : + (F.address key i).head? = some (key i) := by + cases hp : F.parent i with + | none => rw [F.address_none key i hp]; rfl + | some j => rw [F.address_some key i j hp]; rfl + +omit [DecidableEq α] in +lemma address_injective (F : PathForest s) {key : Fin s → α} + (hk : Function.Injective key) : Function.Injective (F.address key) := by + intro i j h + apply hk + exact Option.some.inj (by simpa only [F.address_head] using congrArg List.head? h) + +lemma prefix_address_mem (F : PathForest s) (key : Fin s → α) (i : Fin s) (p : List α) : + p ∈ prefixCodeSet (F.address key i).reverse ↔ + ∃ j, F.Ancestor j i ∧ p = (F.address key j).reverse := by + induction i using (measure (fun i : Fin s => i.val)).wf.induction with + | h i ih => + cases hp : F.parent i with + | none => + rw [F.address_none key i hp] + simp only [List.reverse_singleton,prefixCodeSet,Finset.image_empty,Finset.mem_insert, + Finset.notMem_empty,or_false] + constructor + · intro h + exact ⟨i,Relation.ReflTransGen.refl,by rw [F.address_none key i hp]; exact h⟩ + · rintro ⟨j,hj,rfl⟩ + rcases F.ancestor_eq_or_predecessor hj with he | ⟨k,hk,_⟩ + · subst j + rw [F.address_none key i hp]; rfl + · exact False.elim (by change F.parent i = some k at hk; rw [hp] at hk; cases hk) + | some k => + have hi : (F.address key i).reverse = (F.address key k).reverse ++ [key i] := by + rw [F.address_some key i k hp,List.reverse_cons] + rw [hi,prefixCodeSet_append_singleton,Finset.mem_insert,ih k (F.property i k hp)] + constructor + · rintro (h | ⟨j,hj,h⟩) + · exact ⟨i,Relation.ReflTransGen.refl,h.trans hi.symm⟩ + · exact ⟨j,hj.tail hp,h⟩ + · rintro ⟨j,hj,rfl⟩ + rcases F.ancestor_eq_or_predecessor hj with rfl | ⟨l,hl,hjl⟩ + · exact Or.inl hi + · have he := F.predecessor_unique hl hp + subst l + exact Or.inr ⟨j,hjl,rfl⟩ + +lemma prefix_option_address_mem (F : PathForest s) (key : Fin s → α) + (a : Option (Fin s)) (p : List α) : + p ∈ prefixCodeSet (a.elim [] (F.address key)).reverse ↔ + ∃ j, F.OnPath a j ∧ p = (F.address key j).reverse := by + cases a with + | none => simp [prefixCodeSet,OnPath] + | some i => + simp only [Option.elim_some,F.prefix_address_mem,OnPath,Option.some.injEq] + constructor + · rintro ⟨j,hj,hp⟩ + exact ⟨j,⟨i,rfl,hj⟩,hp⟩ + · rintro ⟨j,⟨i',rfl,hj⟩,hp⟩ + exact ⟨j,hj,hp⟩ + +lemma two_mark_exact_size (F : PathForest s) {key : Fin s → α} + (hk : Function.Injective key) (a b : Option (Fin s)) + (hcover : ∀ i, F.OnPath a i ∨ F.OnPath b i) : + let p := (a.elim [] (F.address key)).reverse + let q := (b.elim [] (F.address key)).reverse + (splitQueryPaths p q).1.length + (splitQueryPaths p q).2.1.length + + (splitQueryPaths p q).2.2.length = s := by + dsimp only + rw [← prefixCodeSet_union_card] + have he : prefixCodeSet (a.elim [] (F.address key)).reverse ∪ + prefixCodeSet (b.elim [] (F.address key)).reverse = + Finset.univ.image (fun i => (F.address key i).reverse) := by + ext p + simp only [Finset.mem_union,F.prefix_option_address_mem,Finset.mem_image,Finset.mem_univ,true_and] + constructor + · rintro (⟨j,_,rfl⟩ | ⟨j,_,rfl⟩) <;> exact ⟨j,rfl⟩ + · rintro ⟨j,rfl⟩ + rcases hcover j with h | h + · exact Or.inl ⟨j,h,rfl⟩ + · exact Or.inr ⟨j,h,rfl⟩ + rw [he,Finset.card_image_of_injective] + · exact Finset.card_fin s + · exact List.reverse_injective.comp (F.address_injective hk) + +end SharpTerminalLeave.PathForest + +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +noncomputable instance indexedWitnessCodeAddressFintype {K s : ℕ} (E : Graph K) (birth : Fin s → Fin K) + (mark : Fin K → Option (Fin s)) : Fintype (IndexedWitnessCode E birth mark) := by + classical + unfold IndexedWitnessCode + infer_instance + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/CallPath.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/CallPath.lean new file mode 100644 index 0000000000000000000000000000000000000000..38887448ac8615e71659190e55451b011b67c32b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/CallPath.lean @@ -0,0 +1,107 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Asymptotics.FreshLogExposeLabeled +import OAI.Combinatorics.TriangleRemoval.Spectral.FreshLogCheckNone +import OAI.Combinatorics.TriangleRemoval.Process.PathRequired + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave +section LegalPathCover +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +def callAtPath (H : τ → Finset ι) : QueryCall ι τ → List (ι × τ) → QueryCall ι τ + | c, [] => c + | c, a :: as => callAtPath H ⟨a :: c.address,(H a.2).erase a.1,some a.2⟩ as + +omit [Fintype τ] [DecidableEq τ] in +lemma callAtPath_address (H : τ → Finset ι) (c : QueryCall ι τ) (p : List (ι × τ)) : + (callAtPath H c p).address = p.reverse ++ c.address := by + induction p generalizing c with + | nil => simp [callAtPath] + | cons a as ih => simp only [callAtPath,ih,List.reverse_cons,List.append_assoc,List.singleton_append] + +noncomputable def legalPaths (H : τ → Finset ι) : ℕ → Finset ι → Option τ → Finset (List (ι × τ)) + | 0, _, _ => {[]} + | d+1, focus, parent => insert [] ((gridCandidates H focus parent).biUnion + (fun a => (legalPaths H d ((H a.2).erase a.1) (some a.2)).image (List.cons a))) + +lemma mem_legalPaths (H : τ → Finset ι) (d : ℕ) (focus : Finset ι) (parent : Option τ) + (p : List (ι × τ)) : p ∈ legalPaths H d focus parent ↔ + LegalQueryPath H focus parent p ∧ p.length ≤ d := by + induction d generalizing focus parent p with + | zero => cases p <;> simp [legalPaths,LegalQueryPath] + | succ d ih => + cases p with + | nil => simp [legalPaths,LegalQueryPath] + | cons a as => + simp only [legalPaths,Finset.mem_insert,List.cons_ne_nil,Finset.mem_biUnion, + Finset.mem_image,false_or,List.cons.injEq,LegalQueryPath,List.length_cons] + constructor + · rintro ⟨b,hb,t,ht,hba,rfl⟩ + subst b + obtain ⟨hl,hn⟩ := (ih _ _ _).mp ht + exact ⟨⟨hb,hl⟩,by omega⟩ + · rintro ⟨⟨ha,hl⟩,hn⟩ + exact ⟨a,ha,as,(ih _ _ _).mpr ⟨hl,by omega⟩,rfl,rfl⟩ + +theorem tracedGridQuery_legal_path (H : τ → Finset ι) (N d k : ℕ) (c : QueryCall ι τ) + (ν : τ → PMF (Fin N)) {z : (Bool × List (QueryCall ι τ)) × List τ} + (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) : + ∀ a ∈ z.1.2, ∃ p ∈ legalPaths H d c.focus c.parent, a = callAtPath H c p := by + induction d generalizing k c z with + | zero => + rw [tracedGridQuery,ExposureTree.freshLog_bind] at hz + obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + have he : y = ((true,[c]),[]) := by simpa [ExposureTree.freshLog] using hy + subst y + intro a ha + have he : a = c := by simpa using ha + subst a + exact ⟨[],by simp [legalPaths],rfl⟩ + | succ d ih => + rw [tracedGridQuery,ExposureTree.freshLog_bind] at hz + obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + rw [ExposureTree.freshLog_mapOutput] at hy + obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy + have hxv := (ExposureTree.freshLog_exposeLabeled_support ν Prod.snd _ hx).1 + have hh := ExposureTree.freshLog_checkNoneTrace_forall ν + (fun a : QueryCall ι τ => ∃ p ∈ legalPaths H (d+1) c.focus c.parent, + a = callAtPath H c p) _ (by + intro A hA z hz + obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hA + have hq' : q ∈ x.1 := (List.mergeSort_perm _ _).mem_iff.mp hq + have hcand : q.1 ∈ gridCandidates H c.focus c.parent := by + have hm : q.1 ∈ x.1.map Prod.fst := List.mem_map.mpr ⟨q,hq',rfl⟩ + rw [hxv] at hm + exact Finset.mem_toList.mp hm + split_ifs at hz with hqk + · intro a ha + obtain ⟨p,hp,he⟩ := ih _ _ hz a ha + refine ⟨q.1 :: p,?_,he⟩ + apply Finset.mem_insert_of_mem + apply Finset.mem_biUnion.mpr + exact ⟨q.1,hcand,Finset.mem_image.mpr ⟨p,hp,rfl⟩⟩ + · have he : z = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using hz + simp [he]) hw + intro a ha + rcases List.mem_cons.mp ha with rfl | ha + · exact ⟨[],Finset.mem_insert_self _ _,rfl⟩ + · exact hh a ha + +end LegalPathCover +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/CallPathCollisionWitness.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/CallPathCollisionWitness.lean new file mode 100644 index 0000000000000000000000000000000000000000..43b4ad3cc17a4cdde753769fc4f898c4e37adbd0 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/CallPathCollisionWitness.lean @@ -0,0 +1,80 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraphLinear +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth2 +import OAI.Combinatorics.TriangleRemoval.Process.PathSuffix +import OAI.Combinatorics.TriangleRemoval.Queries.KeyCandidate + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +namespace RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) +variable (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) + +theorem call_path_collision_witness (i j : Fin F.size) (hne : i ≠ j) (T : Finset (Fin n)) + (hi : T ∈ (F.call i).keys (triangleHypergraph G)) + (hj : T ∈ (F.call j).keys (triangleHypergraph G)) : + ∃ a b : Fin F.vertexCount, + (F.toTriangleGrowth hM hG).birthGraph.ExtraEdge (lookupGraph G) F.vertexLabel a b ∧ + Set.InjOn F.vertexLabel ((F.toTriangleGrowth hM hG).pathUnion a b) := by + let A := F.toTriangleGrowth hM hG + obtain ⟨v,hv,hve⟩ := F.key_exposed hM hG i T hi + obtain ⟨w,hw,hwe⟩ := F.key_exposed hM hG j T hj + have hvw : v ≠ w := by + rcases hv with ⟨hiv,hvr⟩ | ⟨hiv,rfl⟩ <;> rcases hw with ⟨hjw,hwr⟩ | ⟨hjw,rfl⟩ + · exact False.elim (hne (hiv.trans hjw.symm)) + · intro he + have hh := F.birthIndex_nonroot j hjw + rw [← he] at hh + omega + · intro he + have hh := F.birthIndex_nonroot i hiv + rw [he] at hh + omega + · exact fun he => hne (F.birthIndex_injective i j hiv hjw he) + exact A.injective_path_collision hvw hve hwe + +end RecordedCallForest + +theorem traced_graph_path_collision_witness {n : ℕ} (G : Graph n) (N d k : ℕ) + (c : QueryCall (Finset (Fin n)) (Finset (Fin n))) + (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) + (hc : c.Separated (triangleHypergraph G)) + (ν : Finset (Fin n) → PMF (Fin N)) + (z : (Bool × List (QueryCall (Finset (Fin n)) (Finset (Fin n)))) × List (Finset (Fin n))) + (hz : z ∈ (ExposureTree.freshLog ν + (tracedGridQuery (triangleHypergraph G) N d k c)).support) + (hr : ExposureTree.repeats ∅ z.2 = true) : + let F := extractCallForest (triangleHypergraph G) N d k c ν z hz + ∃ a b : Fin F.vertexCount, + (F.toTriangleGrowth hM hG).birthGraph.ExtraEdge (lookupGraph G) F.vertexLabel a b ∧ + Set.InjOn F.vertexLabel ((F.toTriangleGrowth hM hG).pathUnion a b) := by + let F := extractCallForest (triangleHypergraph G) N d k c ν z hz + obtain ⟨a,ha,b,hb,hab,T,haT,hbT⟩ := graph_query_repeat_addresses G N d k c hc ν hz hr + obtain ⟨i,rfl⟩ := List.mem_iff_get.mp ha + obtain ⟨j,rfl⟩ := List.mem_iff_get.mp hb + have hij : i ≠ j := fun he => hab (he ▸ rfl) + exact F.call_path_collision_witness hM hG i j hij T haT hbT + +end SharpTerminalLeave + +open Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/CanonicalCollisionSingletonSum.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/CanonicalCollisionSingletonSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..4b0f28fe92758d2b0848644bbeeb1018e3120e4c --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/CanonicalCollisionSingletonSum.lean @@ -0,0 +1,104 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.CardBiUnion +import OAI.Combinatorics.TriangleRemoval.Probability.UniformSingletonRootSet + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open scoped BigOperators +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +theorem canonical_collision_singleton_sum (c₀ C₀ : ℝ) (hc₀ : 0 < c₀) : + ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c₀ C₀ G → + ∀ (e : Finset (Fin n)), e ∈ G → + ∀ (N : ℕ) [NeZero N] (b : ℕ → ℝ) (_hb : ∀ t, 0 ≤ b t) + (_hq : GridRowQuality (triangleHypergraph G) N b) + (C : ℝ) (_hC : 1 ≤ C) (_hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (_hkd : k ≤ d) (_hkN : k ≤ N), + tracedCollisionProbability (triangleHypergraph G) N d k {e} none ≤ + ∑ W : BoundedEmbeddedWitness G 2 d, + if WitnessEmbeddingBound 1 W ∧ embeddedWitnessRoots W = {e} then + C^3 * ((3*prefixWeight (fun t => (2/(N : ℝ))*b t) k)^W.1.val.2.val / + (W.1.val.2.val.factorial : ℝ)) else 0 := by + classical + filter_upwards [canonical_collision_sum c₀ C₀ hc₀] with n hn + intro G hGood e he N _ b hb hq C hC hlower d k hkd hkN + have he2 := mem_completeGraph.mp (hGood.1 he) + have hh := hn G hGood {e} none (EdgeMatching.singleton e he2) + (Finset.singleton_subset_iff.mpr he) (by simp) (separated_singleton _ [] e none) + N b hb hq C hC hlower d k hkd hkN + have hbi : (({e} : Graph n).biUnion id).card = 2 := by simpa only [Finset.singleton_biUnion,id_eq] using he2 + rw [hbi] at hh + simpa only [Finset.card_singleton] using hh + +theorem averaged_singleton_grid_collision (c₀ C₀ : ℝ) (hc₀ : 0 < c₀) : + ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c₀ C₀ G → + ∀ (hne : G.Nonempty) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (_hb : ∀ t, 0 ≤ b t) (_hq : GridRowQuality (triangleHypergraph G) N b) + (C : ℝ) (_hC : 1 ≤ C) (_hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (_hkd : k ≤ d) (_hkN : k ≤ N), + pmfMean (PMF.uniformOfFinset G hne) (fun e => + tracedCollisionProbability (triangleHypergraph G) N d k {e} none) ≤ + (8192*C^3/prefixD n^50)* + Real.exp (45*prefixD n*prefixWeight (fun t => (2/(N : ℝ))*b t) k) := by + classical + filter_upwards [canonical_collision_singleton_sum c₀ C₀ hc₀] with n hn + intro G hGood hne N _ b hb hq C hC hlower d k hkd hkN + let x := prefixWeight (fun t => (2/(N : ℝ))*b t) k + have hx : 0 ≤ x := by + apply Finset.sum_nonneg + intro t _ + exact mul_nonneg (by positivity) (hb t) + let w (W : BoundedEmbeddedWitness G 2 d) : ℝ := + if WitnessEmbeddingBound 1 W then C^3*((3*x)^W.1.val.2.val/(W.1.val.2.val.factorial : ℝ)) else 0 + have hw (W : BoundedEmbeddedWitness G 2 d) : 0 ≤ w W := by + dsimp only [w] + split_ifs <;> positivity + have hcover : pmfMean (PMF.uniformOfFinset G hne) (fun e => + tracedCollisionProbability (triangleHypergraph G) N d k {e} none) ≤ + pmfMean (PMF.uniformOfFinset G hne) (fun e => + ∑ W : BoundedEmbeddedWitness G 2 d, + if embeddedWitnessRoots W = {e} then w W else 0) := by + apply pmfMean_mono + intro e he + have heG := (PMF.mem_support_uniformOfFinset_iff hne e).mp he + have hh := hn G hGood e heG N b hb hq C hC hlower d k hkd hkN + apply hh.trans_eq + apply Finset.sum_congr rfl + intro W _ + by_cases hW : WitnessEmbeddingBound 1 W <;> + by_cases hroot : embeddedWitnessRoots W = {e} <;> + simp [w,x,hW,hroot] + have hsample := uniform_singleton_root_weighted_sum G hne embeddedWitnessRoots w hw + have hm : 0 ≤ prefixM n := by rw [← hGood.2.1]; positivity + have hmpos : 0 < prefixM n := by rw [← hGood.2.1]; exact_mod_cast hne.card_pos + have hsum := witness_total_weight_bound (d := d) (r := 1) G (by norm_num : 2 ≤ 4) hm + (show 0 ≤ C by linarith) hx + apply (hcover.trans hsample).trans + change (1/(G.card : ℝ))*(∑ W, w W) ≤ _ + apply (mul_le_mul_of_nonneg_left hsum (by positivity : 0 ≤ 1/(G.card : ℝ))).trans_eq + rw [hGood.2.1] + dsimp only [x] + field_simp [ne_of_gt hmpos] + ring + +end SharpTerminalLeave + +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/CanonicalCollisionSum.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/CanonicalCollisionSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..38c203e1ef9a61d67ee95a74cea54f2694d00632 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/CanonicalCollisionSum.lean @@ -0,0 +1,100 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.RootedCountedTracedRepeat +import OAI.Combinatorics.TriangleRemoval.Embeddings.EmbeddedWitnessPathSize + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +theorem canonical_collision_sum (c₀ C₀ : ℝ) (hc₀ : 0 < c₀) : + ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c₀ C₀ G → + ∀ (focus : Graph n) (parent : Option (Finset (Fin n))) + (_hM : EdgeMatching focus) (_hG : focus ⊆ G) (_hr : focus.card ≤ 2) + (_hc : (QueryCall.mk [] focus parent).Separated (triangleHypergraph G)) + (N : ℕ) [NeZero N] (b : ℕ → ℝ) (_hb : ∀ t, 0 ≤ b t) + (_hq : GridRowQuality (triangleHypergraph G) N b) + (C : ℝ) (_hC : 1 ≤ C) (_hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (_hkd : k ≤ d) (_hkN : k ≤ N), + tracedCollisionProbability (triangleHypergraph G) N d k focus parent ≤ + ∑ W : BoundedEmbeddedWitness G (focus.biUnion id).card d, + if WitnessEmbeddingBound focus.card W ∧ embeddedWitnessRoots W = focus then + C^3 * ((3*prefixWeight (fun t => (2/(N : ℝ))*b t) k)^W.1.val.2.val / + (W.1.val.2.val.factorial : ℝ)) else 0 := by + classical + filter_upwards [rooted_counted_traced_repeat_cover c₀ C₀ hc₀] with n hn + intro G hGood focus parent hM hG hr hc N _ b hb hq C hC hlower d k hkd hkN + let H := triangleHypergraph G + let P := ExposureTree.freshLog (gridPriorities N) + (tracedGridQuery H N d k ⟨[],focus,parent⟩) + let S : Finset (BoundedEmbeddedWitness G (focus.biUnion id).card d) := + Finset.univ.filter (fun W => WitnessEmbeddingBound focus.card W ∧ embeddedWitnessRoots W = focus) + let ev := fun (W : BoundedEmbeddedWitness G (focus.biUnion id).card d) + (z : (Bool × List (QueryCall (Finset (Fin n)) (Finset (Fin n)))) × List (Finset (Fin n))) => + z.1.2.any (fun a => decide (a.address = (embeddedWitnessPaths W).1.reverse)) && + z.1.2.any (fun a => decide (a.address = (embeddedWitnessPaths W).2.reverse)) + have hcov : ∀ z ∈ P.support, ExposureTree.repeats ∅ z.2 = true → + ∃ W ∈ S, ev W z = true := by + intro z hz hzrep + obtain ⟨W,hW,hroots,⟨a,ha,hae⟩,⟨b,hb',hbe⟩⟩ := + hn G hGood focus parent hM hG hr hc N d k (gridPriorities N) z hz hzrep + refine ⟨W,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hW,hroots⟩,?_⟩ + apply Bool.and_eq_true_iff.mpr + exact ⟨List.any_eq_true.mpr ⟨a,ha,decide_eq_true hae⟩, + List.any_eq_true.mpr ⟨b,hb',decide_eq_true hbe⟩⟩ + have hh := pmf_boolean_finite_cover P S (fun z => ExposureTree.repeats ∅ z.2) ev hcov + change tracedCollisionProbability H N d k focus parent ≤ _ at hh + apply hh.trans + rw [← Finset.sum_filter] + apply Finset.sum_le_sum + intro W _ + change (((ExposureTree.freshLog (gridPriorities N) + (tracedGridQuery H N d k ⟨[],focus,parent⟩)).map (fun z => + z.1.2.any (fun a => decide (a.address = (embeddedWitnessPaths W).1.reverse)) && + z.1.2.any (fun a => decide (a.address = (embeddedWitnessPaths W).2.reverse)))) true).toReal ≤ _ + rw [log_pair_probability] + apply (actualPairVisitProbability_weight_any H N b hb hq C hC hlower + d k hkd hkN focus parent (embeddedWitnessPaths W).1 (embeddedWitnessPaths W).2).trans + apply mul_le_mul_of_nonneg_left _ (pow_nonneg (by linarith) _) + apply embeddedWitness_factorial_weight W + apply Finset.sum_nonneg + intro t _ + exact mul_nonneg (by positivity) (hb t) + +end SharpTerminalLeave + +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +noncomputable instance canonicalCollisionSumIndexedWitnessCodeFintype + {K s : ℕ} (E : Graph K) (birth : Fin s → Fin K) + (mark : Fin K → Option (Fin s)) : Fintype (IndexedWitnessCode E birth mark) := by + classical + unfold IndexedWitnessCode + infer_instance + +end SharpTerminalLeave + +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/Child.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/Child.lean new file mode 100644 index 0000000000000000000000000000000000000000..ef305813d56111d0a5b96ec48fda4234d34b223e --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/Child.lean @@ -0,0 +1,104 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Asymptotics.FreshLogExposeLabeled +import OAI.Combinatorics.TriangleRemoval.Spectral.FreshLogCheckNone3 + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +section TraceParents +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +def QueryCall.Child (H : τ → Finset ι) (c a : QueryCall ι τ) : Prop := + ∃ p ∈ gridCandidates H c.focus c.parent, + a = ⟨p :: c.address, (H p.2).erase p.1, some p.2⟩ + +noncomputable def QueryCall.RootedTrace (H : τ → Finset ι) + (c : QueryCall ι τ) (cs : List (QueryCall ι τ)) : Prop := + c ∈ cs ∧ ∀ a ∈ cs, a = c ∨ ∃ p ∈ cs, p.Child H a + +theorem tracedGridQuery_parents (H : τ → Finset ι) (N d k : ℕ) (c : QueryCall ι τ) + (ν : τ → PMF (Fin N)) + {z : (Bool × List (QueryCall ι τ)) × List τ} + (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) : + c.RootedTrace H z.1.2 := by + induction d generalizing k c z with + | zero => + rw [tracedGridQuery,ExposureTree.freshLog_bind] at hz + obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + have he : y = ((true,[c]),[]) := by + simpa [ExposureTree.freshLog] using hy + subst y + constructor + · simp + · intro a ha + exact Or.inl (List.mem_singleton.mp ha) + | succ d ih => + rw [tracedGridQuery,ExposureTree.freshLog_bind] at hz + obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + rw [ExposureTree.freshLog_mapOutput] at hy + obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy + have hxv := (ExposureTree.freshLog_exposeLabeled_support ν Prod.snd + (gridCandidates H c.focus c.parent).toList hx).1 + let P : List (QueryCall ι τ) → Prop := fun cs => + ∀ a ∈ cs, ∃ p ∈ c :: cs, p.Child H a + have h0 : P [] := by intro a ha; simp at ha + have happend : ∀ a b, P a → P b → P (a ++ b) := by + intro a b ha hb x hx + rcases List.mem_append.mp hx with hx | hx + · obtain ⟨p,hp,hpx⟩ := ha x hx + refine ⟨p,?_,hpx⟩ + rcases List.mem_cons.mp hp with rfl | hp + · simp + · exact List.mem_cons_of_mem _ (List.mem_append_left _ hp) + · obtain ⟨p,hp,hpx⟩ := hb x hx + refine ⟨p,?_,hpx⟩ + rcases List.mem_cons.mp hp with rfl | hp + · simp + · exact List.mem_cons_of_mem _ (List.mem_append_right _ hp) + have hall : P w.1.2 := by + apply ExposureTree.freshLog_checkNoneTrace_append ν P h0 happend _ ?_ hw + intro A hA q hq + obtain ⟨p,hp,rfl⟩ := List.mem_map.mp hA + have hp' : p ∈ x.1 := (List.mergeSort_perm _ _).mem_iff.mp hp + have hcand : p.1 ∈ gridCandidates H c.focus c.parent := by + have hmem : p.1 ∈ x.1.map Prod.fst := List.mem_map.mpr ⟨p,hp',rfl⟩ + rw [hxv] at hmem + exact Finset.mem_toList.mp hmem + split_ifs at hq with hpk + · have ht := ih p.2.val + ⟨p.1 :: c.address, (H p.1.2).erase p.1.1, some p.1.2⟩ hq + intro a ha + rcases ht.2 a ha with rfl | ⟨b,hb,hba⟩ + · exact ⟨c,by simp, p.1,hcand,rfl⟩ + · exact ⟨b,List.mem_cons_of_mem _ hb,hba⟩ + · have he : q = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using hq + simpa only [he] using h0 + constructor + · simp + · intro a ha + rcases List.mem_cons.mp ha with rfl | ha + · exact Or.inl rfl + · exact Or.inr (hall a ha) + +theorem QueryCall.Child.address_length {H : τ → Finset ι} {c a : QueryCall ι τ} + (h : c.Child H a) : a.address.length = c.address.length + 1 := by + obtain ⟨p,_,rfl⟩ := h + rfl + +end TraceParents +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/ContinuationCollisionRemainderTendsto.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/ContinuationCollisionRemainderTendsto.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d7ad852468ea3aa375a1984e69994c4cf6fd292 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/ContinuationCollisionRemainderTendsto.lean @@ -0,0 +1,102 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixDTendstoTop + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +lemma continuation_collision_remainder_tendsto : + Tendsto (fun n : ℕ => (81920*(3 : ℝ)^49)/prefixD n+8/(n : ℝ)+ + 16*(prefixD n/(n : ℝ))) atTop (𝓝 (0 : ℝ)) := by + have h1 := prefixD_inv_tendsto.const_mul (81920*(3 : ℝ)^49) + have h2 := tendsto_one_div_atTop_nhds_zero_nat.const_mul (8 : ℝ) + have h3 := prefixD_div_n_tendsto.const_mul (16 : ℝ) + simpa only [mul_one_div,add_zero,mul_zero] using (h1.add h2).add h3 + +theorem goodPrefix_relative_l2 (c C : ℝ) (hc : 0 < c) : + ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, + ∀ (G : Graph n), GoodPrefixGraph n c C G → + pmfMean (finish G) (fun H => + ((H.card : ℝ)/((G.card : ℝ)*cavityReference (prefixD n) 1)-1)^2) < δ := by + intro δ hδ + let ε := min (δ/10) 1 + have hε : 0 < ε := lt_min (by positivity) zero_lt_one + have hε1 : ε ≤ 1 := min_le_right _ _ + have hεδ : ε ≤ δ/10 := min_le_left _ _ + have hsmall : 4*ε+ε^2 ≤ δ/2 := by nlinarith [sq_nonneg ε] + filter_upwards [goodPrefix_relative_l2_bound c C hc hε, + continuation_collision_remainder_tendsto.eventually (gt_mem_nhds (by linarith : (0 : ℝ) < δ/2))] + with n hbound hrem + intro G hG + exact (hbound G hG).trans_lt (by linarith) + +lemma normalization_sq (n : ℕ) : normalization n ^ 2 = (n : ℝ)^3 := by + unfold normalization + rw [← Real.rpow_mul_natCast (Nat.cast_nonneg n)] + norm_num + +lemma normalization_pos {n : ℕ} (hn : 0 < n) : 0 < normalization n := by + exact Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ + +lemma sharpConstant_pos : 0 < sharpConstant := by + unfold sharpConstant + positivity + +lemma sharpConstant_sq : sharpConstant^2 = (1/8 : ℝ) := by + unfold sharpConstant + rw [div_pow,mul_pow,Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2)] + norm_num + +theorem prefix_terminal_scale_tendsto : + Tendsto (fun n => prefixM n*cavityReference (prefixD n) 1/normalization n) + atTop (𝓝 sharpConstant) := by + have hinv : Tendsto (fun n => 1 / (4*(1/prefixD n+2))) atTop (𝓝 (1/8 : ℝ)) := by + have hh := (prefixD_inv_tendsto.add_const (2 : ℝ)).const_mul (4 : ℝ) + have hh' := (tendsto_const_nhds : Tendsto (fun _ : ℕ => (1 : ℝ)) atTop (𝓝 1)).div + hh (by norm_num : (4*((0 : ℝ)+2)) ≠ 0) + change Tendsto (fun n => 1/(4*(1/prefixD n+2))) atTop (𝓝 (1/(4*((0 : ℝ)+2)))) at hh' + convert hh' using 1 + norm_num + have hsq : ∀ᶠ n : ℕ in atTop, + (prefixM n*cavityReference (prefixD n) 1/normalization n)^2 = + 1 / (4*(1/prefixD n+2)) := by + filter_upwards [prefix_scales_eventually_pos,eventually_ge_atTop (1 : ℕ)] with n hp hn + have hn0 : (0 : ℝ) < n := by + exact_mod_cast (show 0 < n by omega) + have hD0 : 0 < prefixD n := by linarith [hp.2] + rw [div_pow,mul_pow,normalization_sq,cavityReference_sq hD0.le (by norm_num)] + simp only [cavityWeight,mul_one] + unfold prefixM prefixD + have hp0 := hp.1 + field_simp + ring + have hpos : ∀ᶠ n : ℕ in atTop, + 0 ≤ prefixM n*cavityReference (prefixD n) 1/normalization n := by + filter_upwards [prefix_scales_eventually_pos,eventually_ge_atTop (1 : ℕ)] with n hp hn + have hn0 : 0 < n := by omega + have hm0 : 0 < prefixM n := by unfold prefixM; have := hp.1; positivity + have hq0 : 0 < cavityReference (prefixD n) 1 := cavityReference_pos (by linarith [hp.2]) (by norm_num) + exact (div_pos (mul_pos hm0 hq0) (normalization_pos hn0)).le + have hl := Real.continuous_sqrt.continuousAt.tendsto.comp hinv + have hroot : Real.sqrt (1/8 : ℝ) = sharpConstant := by + rw [← sharpConstant_sq,Real.sqrt_sq sharpConstant_pos.le] + rw [hroot] at hl + apply hl.congr' + filter_upwards [hsq,hpos] with n he hp + dsimp only [Function.comp_def] + rw [← he,Real.sqrt_sq hp] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/FinsetCandidateOrder.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/FinsetCandidateOrder.lean new file mode 100644 index 0000000000000000000000000000000000000000..60183c18e8d90bc9ffa6a283734d7f910293a037 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/FinsetCandidateOrder.lean @@ -0,0 +1,147 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.MarkedRow +import OAI.Combinatorics.TriangleRemoval.Queries.OrderedMarkedRow + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +noncomputable def finsetCandidateOrder {A : Type*} [DecidableEq A] (C : Finset A) : List C := + C.toList.attach.map (fun a => ⟨a.val,Finset.mem_toList.mp a.property⟩) + +lemma finsetCandidateOrder_map {A : Type*} [DecidableEq A] (C : Finset A) : + (finsetCandidateOrder C).map Subtype.val = C.toList := by + simp only [finsetCandidateOrder,List.map_map,Function.comp_def] + simp + +lemma finsetCandidateOrder_perm {A : Type*} [DecidableEq A] (C : Finset A) : + (finsetCandidateOrder C).Perm (Finset.univ : Finset C).toList := by + have hn : (finsetCandidateOrder C).Nodup := List.Nodup.of_map Subtype.val (by + rw [finsetCandidateOrder_map] + exact Finset.nodup_toList _) + apply (List.perm_ext_iff_of_nodup hn (Finset.nodup_toList _)).mpr + intro a + simp only [Finset.mem_toList,Finset.mem_univ,iff_true] + apply List.mem_map.mpr + exact ⟨⟨a.val,Finset.mem_toList.mpr a.property⟩,List.mem_attach _ _,by apply Subtype.ext; rfl⟩ + +namespace ExposureTree +variable {K A B V : Type*} +lemma exposeLabeled_relabel (key : B → K) (f : A → B) (as : List A) : + mapOutput (List.map (fun p : A × V => (f p.1,p.2))) + (exposeLabeled (key ∘ f) as) = exposeLabeled key (as.map f) := by + induction as with + | nil => rfl + | cons a as ih => + simp only [exposeLabeled,List.map_cons,mapOutput,mapOutput_bind] + congr 1 + funext v + rw [← ih] + rw [bind_mapOutput] +end ExposureTree + +section CandidateKernel +variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def requiredCandidates (H : τ → Finset ι) + (required : List (ι × τ) → Bool) (address : List (ι × τ)) + (focus : Finset ι) (parent : Option τ) : Finset (gridCandidates H focus parent) := + Finset.univ.filter (fun a => required (a.val :: address)) + +noncomputable def markedChildKernel (H : τ → Finset ι) (N : ℕ) [NeZero N] + (required : List (ι × τ) → Bool) (d : ℕ) (address : List (ι × τ)) + (focus : Finset ι) (parent : Option τ) + (a : gridCandidates H focus parent) (u : Fin N) : PMF (Bool × Bool) := + ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required d u.val (a.val :: address) + ((H a.val.2).erase a.val.1) (some a.val.2)) + +omit [Fintype ι] in +lemma candidate_clock_table (H : τ → Finset ι) (N : ℕ) [NeZero N] + (focus : Finset ι) (parent : Option τ) : + (productPMF (fun _ : gridCandidates H focus parent => PMF.uniformOfFintype (Fin N))).map + (fun ω => (finsetCandidateOrder (gridCandidates H focus parent)).map + (fun a => (a.val,ω a))) = + ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H focus parent).toList) := by + let C := gridCandidates H focus parent + let order := finsetCandidateOrder C + have ho : order.Nodup := (finsetCandidateOrder_perm C).nodup_iff.mpr (Finset.nodup_toList _) + have htable := ExposureTree.exposeLabeled_table + (fun _ : τ => PMF.uniformOfFintype (Fin N)) (fun a : C => a.val.2) + order ho (fun _ : C => PMF.uniformOfFintype (Fin N)) (by intros; rfl) + have hm := congrArg (PMF.map (List.map (fun p : C × Fin N => (p.1.val,p.2)))) htable + rw [PMF.map_comp,← ExposureTree.fresh_mapOutput] at hm + simp only [Function.comp_def,List.map_map] at hm + have he := ExposureTree.exposeLabeled_relabel (V := Fin N) Prod.snd + (Subtype.val : C → ι × τ) order + dsimp only [Function.comp_def] at he + rw [he] at hm + simpa only [order,C,finsetCandidateOrder_map] using hm + +omit [Fintype ι] in + +theorem markedGridQueryDepth_candidate_kernel (H : τ → Finset ι) + (N : ℕ) [NeZero N] (required : List (ι × τ) → Bool) + (d k : ℕ) (address : List (ι × τ)) (focus : Finset ι) (parent : Option τ) : + ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required (d+1) k address focus parent) = + (productPMF (fun _ : gridCandidates H focus parent => PMF.uniformOfFintype (Fin N))).bind + (fun ω => markedCheck (orderedMarkedRow + (finsetCandidateOrder (gridCandidates H focus parent)) + (requiredCandidates H required address focus parent) + (markedChildKernel H N required d address focus parent) k ω)) := by + classical + rw [markedGridQueryDepth,ExposureTree.fresh_bind,← candidate_clock_table H N focus parent, + PMF.bind_map] + congr 1 + funext ω + dsimp only [Function.comp_def] + rw [ExposureTree.fresh_checkMarked] + simp only [List.map_map,Function.comp_def] + let order := finsetCandidateOrder (gridCandidates H focus parent) + let as := (order.map (fun a => (a.val,ω a))).mergeSort (fun a b => a.2.val ≤ b.2.val) + have hp := markedCheck_map_priority as + (fun p => required (p.1 :: address)) + (fun p => if p.2.val < k then ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required d p.2.val (p.1 :: address) + ((H p.1.2).erase p.1.1) (some p.1.2)) else PMF.pure (false,false)) + (fun _ => 0) (fun p => p.2.val) + calc + _ = markedCheck (as.map (fun p => (⟨required (p.1 :: address), + if p.2.val < k then ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required d p.2.val (p.1 :: address) + ((H p.1.2).erase p.1.1) (some p.1.2)) else PMF.pure (false,false),0⟩ : MarkedChild))) := by + congr 1 + apply List.map_congr_left + intro p _ + split <;> rfl + _ = _ := by + rw [hp] + congr 1 + dsimp only [as] + rw [List.map_mergeSort (s := fun a b : MarkedChild => decide (a.priority ≤ b.priority)) + (by intros; rfl),List.map_map] + unfold orderedMarkedRow + congr 1 + apply List.map_congr_left + intro a _ + dsimp [rowChild,markedChildKernel] + simp only [requiredCandidates,Finset.mem_filter,Finset.mem_univ,true_and] + cases required (a.val :: address) <;> rfl + +end CandidateKernel +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/ForkAddressesNotSuffix.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/ForkAddressesNotSuffix.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ba1723769ba505e4361265d73889e6251f50351 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/ForkAddressesNotSuffix.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.Child +import OAI.Combinatorics.TriangleRemoval.Spectral.TracedGridQueryAddress + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave +section ChronologicalTrace +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +lemma fork_addresses_not_suffix {α : Type*} {p q : α} {base a b : List α} + (hpq : p ≠ q) (ha : p :: base <:+ a) (hb : q :: base <:+ b) : ¬ b <:+ a := by + intro hba + have hh := List.suffix_of_suffix_length_le ha (hb.trans hba) (by simp) + have heq := hh.eq_of_length (by simp) + exact hpq (List.cons.inj heq).1 + +lemma child_address_not_suffix {α : Type*} {p : α} {base a : List α} + (ha : p :: base <:+ a) : ¬ a <:+ base := by + intro hab + have h₁ := ha.length_le + have h₂ := hab.length_le + simp only [List.length_cons] at h₁ + omega + +theorem tracedGridQuery_no_later_ancestor (H : τ → Finset ι) (N d k : ℕ) (c : QueryCall ι τ) + (ν : τ → PMF (Fin N)) {z : (Bool × List (QueryCall ι τ)) × List τ} + (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) : + (z.1.2.Pairwise (fun a b => ¬ b.address <:+ a.address)) := by + induction d generalizing k c z with + | zero => + rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz + obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + have heq : y = ((true,[c]),[]) := by simpa [ExposureTree.freshLog] using hy + simp [heq] + | succ d ih => + rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz + obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + rw [ExposureTree.freshLog_mapOutput] at hy + obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy + have hxvals := (ExposureTree.freshLog_exposeLabeled_support ν Prod.snd _ hx).1 + have hnd : (x.1.map Prod.fst).Nodup := by rw [hxvals]; exact Finset.nodup_toList _ + have hsnd := ((List.mergeSort_perm x.1 (fun a b => a.2.val ≤ b.2.val)).map Prod.fst).nodup_iff.mpr hnd + have hpair : (x.1.mergeSort (fun a b => a.2.val ≤ b.2.val)).Pairwise + (fun a b => a.1 ≠ b.1) := by + simpa only [List.Nodup, List.pairwise_map] using hsnd + have hwR := ExposureTree.freshLog_checkNoneTrace_pairwise ν + (fun a b : QueryCall ι τ => ¬ b.address <:+ a.address) _ + (by + intro A hA a ha + obtain ⟨p,_,rfl⟩ := List.mem_map.mp hA + split_ifs at ha with hp + · exact ih _ _ ha + · have heq : a = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using ha + simp [heq]) + (by + apply List.pairwise_map.mpr + apply hpair.imp + intro p q hpq x hx y hy a ha b hb + split_ifs at hx hy with hp hq + · exact fork_addresses_not_suffix hpq + (tracedGridQuery_address H N d _ _ ν hx a ha) + (tracedGridQuery_address H N d _ _ ν hy b hb) + · have heq : y = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using hy + simp [heq] at hb + · have heq : x = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using hx + simp [heq] at ha + · have heq : x = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using hx + simp [heq] at ha) hw + have hwP := ExposureTree.freshLog_checkNoneTrace_forall ν + (fun a : QueryCall ι τ => ¬ a.address <:+ c.address) _ + (by + intro A hA a ha + obtain ⟨p,_,rfl⟩ := List.mem_map.mp hA + split_ifs at ha with hp + · intro b hb + exact child_address_not_suffix (tracedGridQuery_address H N d _ _ ν ha b hb) + · have heq : a = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using ha + simp [heq]) hw + exact List.pairwise_cons.mpr ⟨hwP,hwR⟩ + +theorem tracedGridQuery_parent_before (H : τ → Finset ι) (N d k : ℕ) + (c : QueryCall ι τ) (ν : τ → PMF (Fin N)) + {z : (Bool × List (QueryCall ι τ)) × List τ} + (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) + (i j : Fin z.1.2.length) (h : (z.1.2.get j).Child H (z.1.2.get i)) : j < i := by + have ho := tracedGridQuery_no_later_ancestor H N d k c ν hz + obtain ⟨p,_,he⟩ := h + have hs : (z.1.2.get j).address <:+ (z.1.2.get i).address := by + rw [he] + exact List.suffix_cons _ _ + rcases lt_trichotomy j i with hlt | rfl | hgt + · exact hlt + · have hlen := congrArg (fun a => a.address.length) he + simp only [List.length_cons] at hlen + omega + · exact False.elim ((List.pairwise_iff_get.mp ho i j hgt) hs) + +end ChronologicalTrace +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/GridCollision.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/GridCollision.lean new file mode 100644 index 0000000000000000000000000000000000000000..1438eec3a6d632977654af3df3dc8d4b32bfd58d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/GridCollision.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraph +import OAI.Combinatorics.TriangleRemoval.Stability.GridCavityError + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +section Continuum +variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem gridAnswer_tendsto_terminal (H : τ → Finset ι) (focus : Finset ι) + (parent : Option τ) : + Tendsto (fun n : ℕ => gridAnswerProbability H (n + 1) (n + 1) (n + 1) focus parent) + atTop (𝓝 (∏ e ∈ focus, cavityLimit H e parent 1)) := by + have hh := tendsto_finsetProd focus (fun e _ => gridMessage_tendsto_terminal H e parent) + convert hh using 1 + funext n + exact gridAnswerProbability_factor H (n + 1) (n + 1) (n + 1) focus parent + +noncomputable def gridCollision (H : τ → Finset ι) (focus : Finset ι) + (parent : Option τ) (n : ℕ) : ℝ := + trueProbability ((ExposureTree.freshRecorded (gridPriorities (n + 1)) + (gridQueryDepth H (n + 1) (n + 1) (n + 1) focus parent) ∅).map Prod.snd) + +noncomputable def collisionCost (H : τ → Finset ι) (focus : Finset ι) + (parent : Option τ) : ℝ := + Filter.liminf (gridCollision H focus parent) atTop + +omit [Fintype ι] in +theorem gridCollision_mem_unit (H : τ → Finset ι) (focus : Finset ι) + (parent : Option τ) (n : ℕ) : gridCollision H focus parent n ∈ Set.Icc (0 : ℝ) 1 := + ⟨trueProbability_nonneg _, trueProbability_le_one _⟩ + +omit [Fintype ι] in +theorem collisionCost_mem_unit (H : τ → Finset ι) (focus : Finset ι) + (parent : Option τ) : collisionCost H focus parent ∈ Set.Icc (0 : ℝ) 1 := by + have hlow : atTop.IsBoundedUnder (· ≥ ·) (gridCollision H focus parent) := + Filter.isBoundedUnder_of ⟨0, fun n => (gridCollision_mem_unit H focus parent n).1⟩ + have hupp : atTop.IsBoundedUnder (· ≤ ·) (gridCollision H focus parent) := + Filter.isBoundedUnder_of ⟨1, fun n => (gridCollision_mem_unit H focus parent n).2⟩ + constructor + · exact le_liminf_of_le hupp.isCobounded_flip + (Filter.Eventually.of_forall (fun n => (gridCollision_mem_unit H focus parent n).1)) + · apply liminf_le_of_le hlow + intro b hb + obtain ⟨n, hn⟩ := hb.exists + exact hn.trans (gridCollision_mem_unit H focus parent n).2 + +end Continuum + +theorem graph_cavity_error {n : ℕ} (G focus : Graph n) (hf : focus ⊆ G) : + |focusSurvival G focus - ∏ e ∈ focus, cavityLimit (triangleHypergraph G) e none 1| ≤ + collisionCost (triangleHypergraph G) focus none := by + let H := triangleHypergraph G + let C : ℝ := 2 * (Fintype.card (Finset (Fin n)) : ℝ) ^ 2 + let a : ℕ → ℝ := fun k => + |focusSurvival G focus - gridAnswerProbability H (k + 1) (k + 1) (k + 1) focus none| - + C / (k + 1 : ℕ) + have hden : Tendsto (fun k : ℕ => (1 : ℝ) / ((k + 1 : ℕ) : ℝ)) atTop (𝓝 0) := by + simpa only [Nat.cast_add, Nat.cast_one] using + (tendsto_one_div_add_atTop_nhds_zero_nat : + Tendsto (fun k : ℕ => (1 : ℝ) / (k + 1)) atTop (𝓝 0)) + have ha : Tendsto a atTop + (𝓝 |focusSurvival G focus - ∏ e ∈ focus, cavityLimit H e none 1|) := by + have hh := (((tendsto_const_nhds (x := focusSurvival G focus)).sub (gridAnswer_tendsto_terminal H focus none)).abs).sub + ((tendsto_const_nhds (x := C)).mul hden) + simpa only [a, mul_zero, sub_zero, div_eq_mul_inv, one_mul] using hh + have he : ∀ᶠ k in atTop, a k ≤ gridCollision H focus none k := by + apply Filter.Eventually.of_forall + intro k + have hh := graph_grid_exposure_error G focus hf (k + 1) + dsimp only [a, C, H, gridCollision] + linarith + have hupp : atTop.IsBoundedUnder (· ≤ ·) (gridCollision H focus none) := + Filter.isBoundedUnder_of ⟨1, fun k => (gridCollision_mem_unit H focus none k).2⟩ + have hh := liminf_le_liminf he ha.isBoundedUnder_ge hupp.isCobounded_flip + rw [ha.liminf_eq] at hh + exact hh + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/JointMarkedQuery.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/JointMarkedQuery.lean new file mode 100644 index 0000000000000000000000000000000000000000..c613d220a73020cd58824820c34aedd7baa92009 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/JointMarkedQuery.lean @@ -0,0 +1,105 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.TracedGridQueryAddress +import OAI.Combinatorics.TriangleRemoval.Spectral.CheckMarkedTrace + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave +section MarkedTrace +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def jointMarkedQuery (H : τ → Finset ι) (N : ℕ) + (required : List (ι × τ) → Bool) : + ℕ → ℕ → QueryCall ι τ → ExposureTree τ (Fin N) (Bool × Bool × List (QueryCall ι τ)) + | 0, _, c => ExposureTree.bind + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H c.focus c.parent).toList) + (fun _ => .done (true,true,[c])) + | d+1, k, c => ExposureTree.bind + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H c.focus c.parent).toList) + (fun values => ExposureTree.mapOutput (fun z => (z.1,z.2.1,c :: z.2.2)) + (ExposureTree.checkMarkedTrace + ((values.mergeSort (fun a b => a.2.val ≤ b.2.val)).map + (fun p => (required (p.1 :: c.address), if p.2.val < k then + jointMarkedQuery H N required d p.2.val + ⟨p.1 :: c.address,(H p.1.2).erase p.1.1,some p.1.2⟩ + else .done (false,false,[])))))) + +theorem jointMarkedQuery_marked (H : τ → Finset ι) (N : ℕ) + (required : List (ι × τ) → Bool) (d k : ℕ) (c : QueryCall ι τ) : + ExposureTree.mapOutput (fun z => (z.1,z.2.1)) (jointMarkedQuery H N required d k c) = + markedGridQueryDepth H N required d k c.address c.focus c.parent := by + induction d generalizing k c with + | zero => simp only [jointMarkedQuery,markedGridQueryDepth, + ExposureTree.mapOutput_bind,ExposureTree.mapOutput_done] + | succ d ih => + simp only [jointMarkedQuery,markedGridQueryDepth,ExposureTree.mapOutput_bind, + ExposureTree.mapOutput_comp] + congr 1 + funext values + rw [show (fun x : Bool × Bool × List (QueryCall ι τ) => (x.1,x.2.1)) ∘ + (fun z : Bool × Bool × List (QueryCall ι τ) => (z.1,z.2.1,c :: z.2.2)) = + (fun z : Bool × Bool × List (QueryCall ι τ) => (z.1,z.2.1)) from rfl, + ExposureTree.checkMarkedTrace_marked,List.map_map] + congr 1 + apply List.map_congr_left + intro p _ + dsimp only [Function.comp_def] + congr 1 + split + · exact ih _ _ + · rfl + +theorem jointMarkedQuery_trace (H : τ → Finset ι) (N : ℕ) + (required : List (ι × τ) → Bool) (d k : ℕ) (c : QueryCall ι τ) : + ExposureTree.mapOutput (fun z => (z.1,z.2.2)) (jointMarkedQuery H N required d k c) = + tracedGridQuery H N d k c := by + induction d generalizing k c with + | zero => simp only [jointMarkedQuery,tracedGridQuery, + ExposureTree.mapOutput_bind,ExposureTree.mapOutput_done] + | succ d ih => + simp only [jointMarkedQuery,tracedGridQuery,ExposureTree.mapOutput_bind, + ExposureTree.mapOutput_comp] + congr 1 + funext values + rw [show (fun x : Bool × Bool × List (QueryCall ι τ) => (x.1,x.2.2)) ∘ + (fun z : Bool × Bool × List (QueryCall ι τ) => (z.1,z.2.1,c :: z.2.2)) = + (fun z : Bool × List (QueryCall ι τ) => (z.1,c :: z.2)) ∘ + (fun z : Bool × Bool × List (QueryCall ι τ) => (z.1,z.2.2)) from rfl, + ← ExposureTree.mapOutput_comp,ExposureTree.checkMarkedTrace_trace,List.map_map] + congr 2 + apply List.map_congr_left + intro p _ + dsimp only [Function.comp_def] + split + · exact ih _ _ + · rfl + +theorem jointMarkedQuery_address (H : τ → Finset ι) (N : ℕ) + (required : List (ι × τ) → Bool) (d k : ℕ) (c : QueryCall ι τ) + (ν : τ → PMF (Fin N)) {z : Bool × Bool × List (QueryCall ι τ)} + (hz : z ∈ (ExposureTree.fresh ν (jointMarkedQuery H N required d k c)).support) : + ∀ a ∈ z.2.2, c.address <:+ a.address := by + have ht : (z.1,z.2.2) ∈ (ExposureTree.fresh ν (tracedGridQuery H N d k c)).support := by + rw [← jointMarkedQuery_trace H N required d k c,ExposureTree.fresh_mapOutput] + exact (PMF.mem_support_map_iff _ _ _).mpr ⟨z,hz,rfl⟩ + rw [← ExposureTree.freshLog_outcome] at ht + obtain ⟨x,hx,hxe⟩ := (PMF.mem_support_map_iff _ _ _).mp ht + have hh := tracedGridQuery_address H N d k c ν hx + rw [hxe] at hh + exact hh + +end MarkedTrace +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/JointMarkedQueryPair.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/JointMarkedQueryPair.lean new file mode 100644 index 0000000000000000000000000000000000000000..33ebfec49b30a4be7f737d63fa8c2ddb04aedb5c --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/JointMarkedQueryPair.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.CheckMarkedTraceCommon +import OAI.Combinatorics.TriangleRemoval.Process.PathRequiredBaseAppend + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave +section JointPairHit +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem jointMarkedQuery_pair_hit (H : τ → Finset ι) (N d k : ℕ) + (c : QueryCall ι τ) (path₁ path₂ : List (ι × τ)) (ν : τ → PMF (Fin N)) + {z : Bool × Bool × List (QueryCall ι τ)} + (hz : z ∈ (ExposureTree.fresh ν + (jointMarkedQuery H N + (pairRequired (c.address.reverse ++ path₁) (c.address.reverse ++ path₂)) d k c)).support) + (hp : ∃ a ∈ z.2.2, a.address = path₁.reverse ++ c.address) + (hq : ∃ a ∈ z.2.2, a.address = path₂.reverse ++ c.address) : z.2.1 = true := by + induction d generalizing k c path₁ path₂ z with + | zero => + rw [jointMarkedQuery,ExposureTree.fresh_bind] at hz + obtain ⟨_,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + have he : z = (true,true,[c]) := by + simpa only [ExposureTree.fresh,PMF.mem_support_pure_iff] using hz + rw [he] + | succ d ih => + cases path₁ with + | nil => + simp only [List.append_nil] at hz + rw [jointMarkedQuery_pair_nil] at hz + exact jointMarkedQuery_hit H N (d+1) k c path₂ ν hz hq + | cons a as => + cases path₂ with + | nil => + simp only [List.append_nil] at hz + have he : pairRequired (c.address.reverse ++ a :: as) c.address.reverse = + pairRequired c.address.reverse (c.address.reverse ++ a :: as) := by + funext l + exact Bool.or_comm _ _ + rw [he,jointMarkedQuery_pair_nil] at hz + exact jointMarkedQuery_hit H N (d+1) k c (a :: as) ν hz hp + | cons b bs => + rw [jointMarkedQuery,ExposureTree.fresh_bind] at hz + obtain ⟨values,hvalues,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + rw [ExposureTree.fresh_mapOutput] at hz + obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + have hp' := query_trace_cons_hit_tail c w.2.2 a as hp + have hq' := query_trace_cons_hit_tail c w.2.2 b bs hq + let cs := values.mergeSort (fun a b => a.2.val ≤ b.2.val) + let req := pairRequired (c.address.reverse ++ a :: as) (c.address.reverse ++ b :: bs) + let program (p : (ι × τ) × Fin N) := if p.2.val < k then + jointMarkedQuery H N req d p.2.val + ⟨p.1 :: c.address,(H p.1.2).erase p.1.1,some p.1.2⟩ + else ExposureTree.done (false,false,[]) + have hnd : (cs.map Prod.fst).Nodup := by + rw [← ExposureTree.freshLog_outcome] at hvalues + obtain ⟨x,hx,hxe⟩ := (PMF.mem_support_map_iff _ _ _).mp hvalues + have he := (ExposureTree.freshLog_exposeLabeled_support ν Prod.snd _ hx).1 + rw [hxe] at he + apply ((List.mergeSort_perm values (fun a b => a.2.val ≤ b.2.val)).map Prod.fst).nodup_iff.mpr + rw [he] + exact Finset.nodup_toList _ + have hhead (v : ι × τ) (vs : List (ι × τ)) + (p : (ι × τ) × Fin N) (_ : p ∈ cs) + (y : Bool × Bool × List (QueryCall ι τ)) + (hy : y ∈ (ExposureTree.fresh ν (program p)).support) + (hh : ∃ q ∈ y.2.2, q.address = (v :: vs).reverse ++ c.address) : p.1 = v := by + dsimp only [program] at hy + split_ifs at hy with hk + · exact jointMarkedQuery_hit_head H N d p.2.val req ν c.address p.1 v vs _ _ hy hh + · have he : y = (false,false,[]) := by + simpa only [ExposureTree.fresh,PMF.mem_support_pure_iff] using hy + simp only [he,List.not_mem_nil,false_and,exists_false] at hh + change w ∈ (ExposureTree.fresh ν (ExposureTree.checkMarkedTrace + (cs.map (fun p => (req (p.1 :: c.address),program p))))).support at hw + by_cases hab : a = b + · subst b + have hrow : cs.map (fun p => (req (p.1 :: c.address),program p)) = + cs.map (fun p => (decide (p.1 = a),program p)) := by + apply List.map_congr_left + intro p _ + simp only [req,pairRequired_base_child,or_self] + rw [hrow] at hw + apply ExposureTree.checkMarkedTrace_common_hit ν + (fun q : QueryCall ι τ => q.address = (a :: as).reverse ++ c.address) + (fun q : QueryCall ι τ => q.address = (a :: bs).reverse ++ c.address) + Prod.fst program a cs hnd (hhead a as) (hhead a bs) _ hw hp' hq' + intro p hp y hy hpy hqy + have hpa := hhead a as p hp y hy hpy + dsimp only [program] at hy + split_ifs at hy with hk + · apply ih p.2.val + ⟨p.1 :: c.address,(H p.1.2).erase p.1.1,some p.1.2⟩ as bs + · simpa only [req,List.reverse_cons,List.append_assoc,List.singleton_append,hpa] using hy + · simpa only [List.reverse_cons,List.append_assoc,List.singleton_append,hpa] using hpy + · simpa only [List.reverse_cons,List.append_assoc,List.singleton_append,hpa] using hqy + · have he : y = (false,false,[]) := by + simpa only [ExposureTree.fresh,PMF.mem_support_pure_iff] using hy + simp only [he,List.not_mem_nil,false_and,exists_false] at hpy + · have hrow : cs.map (fun p => (req (p.1 :: c.address),program p)) = + cs.map (fun p => (decide (p.1 = a ∨ p.1 = b),program p)) := by + apply List.map_congr_left + intro p _ + rw [show req (p.1 :: c.address) = decide (p.1 = a ∨ p.1 = b) from + pairRequired_base_child c.address a b p.1 as bs] + rw [hrow] at hw + apply ExposureTree.checkMarkedTrace_two_hit ν + (fun q : QueryCall ι τ => q.address = (a :: as).reverse ++ c.address) + (fun q : QueryCall ι τ => q.address = (b :: bs).reverse ++ c.address) + Prod.fst program a b hab cs hnd _ _ hw hp' hq' + · intro p hp y hy hh + have hpa := hhead a as p hp y hy hh + refine ⟨hpa,?_⟩ + dsimp only [program,req] at hy + split_ifs at hy with hk + · simp only [hpa] at hy + rw [jointMarkedQuery_pair_child H N d p.2.val c.address a b as bs hab] at hy + apply jointMarkedQuery_hit H N d p.2.val + ⟨a :: c.address,(H a.2).erase a.1,some a.2⟩ as ν hy + simpa only [List.reverse_cons,List.append_assoc,List.singleton_append] using hh + · have he : y = (false,false,[]) := by + simpa only [ExposureTree.fresh,PMF.mem_support_pure_iff] using hy + simp only [he,List.not_mem_nil,false_and,exists_false] at hh + · intro p hp y hy hh + have hpb := hhead b bs p hp y hy hh + refine ⟨hpb,?_⟩ + dsimp only [program,req] at hy + split_ifs at hy with hk + · simp only [hpb] at hy + have he : pairRequired (c.address.reverse ++ a :: as) (c.address.reverse ++ b :: bs) = + pairRequired (c.address.reverse ++ b :: bs) (c.address.reverse ++ a :: as) := by + funext l + exact Bool.or_comm _ _ + rw [he,jointMarkedQuery_pair_child H N d p.2.val c.address b a bs as (Ne.symm hab)] at hy + apply jointMarkedQuery_hit H N d p.2.val + ⟨b :: c.address,(H b.2).erase b.1,some b.2⟩ bs ν hy + simpa only [List.reverse_cons,List.append_assoc,List.singleton_append] using hh + · have he : y = (false,false,[]) := by + simpa only [ExposureTree.fresh,PMF.mem_support_pure_iff] using hy + simp only [he,List.not_mem_nil,false_and,exists_false] at hh + +end JointPairHit +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/KeyCandidate.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/KeyCandidate.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e0128b40146ae82c507b6e7e7b4bbb85346c57b --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/KeyCandidate.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraphLinear +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Process.LookupGraph +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching +import OAI.Combinatorics.TriangleRemoval.Process.FreshMemSelected + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma QueryCall.key_has_candidate {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + (H : τ → Finset ι) (c : QueryCall ι τ) (T : τ) (h : T ∈ c.keys H) : + ∃ e, (e,T) ∈ gridCandidates H c.focus c.parent := by + obtain ⟨p,hp,he⟩ := List.mem_map.mp h + exact ⟨p.1,he ▸ Finset.mem_toList.mp hp⟩ + +namespace RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) +variable (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) + +lemma key_exposed (i : Fin F.size) (T : Finset (Fin n)) + (hT : T ∈ (F.call i).keys (triangleHypergraph G)) : + ∃ v : Fin F.vertexCount, + ((i = F.root ∧ v.val < F.rootCount) ∨ (∃ hi : i ≠ F.root, v = F.birthIndex i hi)) ∧ + (F.toTriangleGrowth hM hG).birthGraph.ExposedAt (lookupGraph G) F.vertexLabel v T := by + obtain ⟨e,he⟩ := (F.call i).key_has_candidate (triangleHypergraph G) T hT + by_cases hi : i = F.root + · subst i + rw [F.root_eq] at he + obtain ⟨v,hv,hve⟩ := F.candidate_root_exposed hM hG (e,T) he + exact ⟨v,Or.inl ⟨rfl,hv⟩,hve⟩ + · exact ⟨F.birthIndex i hi,Or.inr ⟨hi,rfl⟩,F.candidate_nonroot_exposed hM hG i hi (e,T) he⟩ + +theorem call_collision_witness (i j : Fin F.size) (hne : i ≠ j) (T : Finset (Fin n)) + (hi : T ∈ (F.call i).keys (triangleHypergraph G)) + (hj : T ∈ (F.call j).keys (triangleHypergraph G)) : + ∃ S : Set (Fin F.vertexCount), IsLowerSet S ∧ Set.InjOn F.vertexLabel S ∧ + ∃ a ∈ S, ∃ b ∈ S, + (F.toTriangleGrowth hM hG).birthGraph.ExtraEdge (lookupGraph G) F.vertexLabel a b := by + let A := F.toTriangleGrowth hM hG + obtain ⟨v,hv,hve⟩ := F.key_exposed hM hG i T hi + obtain ⟨w,hw,hwe⟩ := F.key_exposed hM hG j T hj + have hvw : v ≠ w := by + rcases hv with ⟨hiv,hvr⟩ | ⟨hiv,rfl⟩ <;> rcases hw with ⟨hjw,hwr⟩ | ⟨hjw,rfl⟩ + · exact False.elim (hne (hiv.trans hjw.symm)) + · intro he + have hh := F.birthIndex_nonroot j hjw + rw [← he] at hh + omega + · intro he + have hh := F.birthIndex_nonroot i hiv + rw [he] at hh + omega + · exact fun he => hne (F.birthIndex_injective i j hiv hjw he) + exact A.birthGraph.exposed_collision_witness (lookupGraph G) F.vertexLabel A.spawnRules + F.rootCount F.vertexLabel_injective_roots + (fun v hv => ((A.older_invariants v).2 hv).1) hvw hve hwe + +end RecordedCallForest + +theorem traced_graph_collision_witness {n : ℕ} (G : Graph n) (N d k : ℕ) + (c : QueryCall (Finset (Fin n)) (Finset (Fin n))) + (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) + (hc : c.Separated (triangleHypergraph G)) + (ν : Finset (Fin n) → PMF (Fin N)) + (z : (Bool × List (QueryCall (Finset (Fin n)) (Finset (Fin n)))) × List (Finset (Fin n))) + (hz : z ∈ (ExposureTree.freshLog ν + (tracedGridQuery (triangleHypergraph G) N d k c)).support) + (hr : ExposureTree.repeats ∅ z.2 = true) : + let F := extractCallForest (triangleHypergraph G) N d k c ν z hz + ∃ S : Set (Fin F.vertexCount), IsLowerSet S ∧ Set.InjOn F.vertexLabel S ∧ + ∃ a ∈ S, ∃ b ∈ S, + (F.toTriangleGrowth hM hG).birthGraph.ExtraEdge (lookupGraph G) F.vertexLabel a b := by + let F := extractCallForest (triangleHypergraph G) N d k c ν z hz + obtain ⟨a,ha,b,hb,hab,T,haT,hbT⟩ := graph_query_repeat_addresses G N d k c hc ν hz hr + obtain ⟨i,rfl⟩ := List.mem_iff_get.mp ha + obtain ⟨j,rfl⟩ := List.mem_iff_get.mp hb + have hij : i ≠ j := fun he => hab (he ▸ rfl) + exact F.call_collision_witness hM hG i j hij T haT hbT + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/LegalCollisionPairs.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/LegalCollisionPairs.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6ab23915da52cacb2bfc100ee9614a4daf7a3f6 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/LegalCollisionPairs.lean @@ -0,0 +1,124 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.GridCollision +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraphLinear +import OAI.Combinatorics.TriangleRemoval.Queries.SplitQueryPaths + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave +section CollisionPathSum +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def legalCollisionPairs (H : τ → Finset ι) (d : ℕ) + (focus : Finset ι) (parent : Option τ) : Finset (List (ι × τ) × List (ι × τ)) := by + classical + let c : QueryCall ι τ := ⟨[],focus,parent⟩ + exact ((legalPaths H d focus parent).product (legalPaths H d focus parent)).filter + (fun pq => pq.1 ≠ pq.2 ∧ ∃ T, T ∈ (callAtPath H c pq.1).keys H ∧ + T ∈ (callAtPath H c pq.2).keys H) + +noncomputable def tracedCollisionProbability (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) : ℝ := + (((ExposureTree.freshLog (gridPriorities N) + (tracedGridQuery H N d k ⟨[],focus,parent⟩)).map + (fun z => ExposureTree.repeats ∅ z.2)) true).toReal + +lemma gridCollision_eq_trace (H : τ → Finset ι) (focus : Finset ι) + (parent : Option τ) (j : ℕ) : + gridCollision H focus parent j = tracedCollisionProbability H (j+1) (j+1) (j+1) focus parent := by + unfold gridCollision trueProbability tracedCollisionProbability + rw [ExposureTree.freshRecorded_eq_log,PMF.map_comp] + rw [← tracedGridQuery_outcome H (j+1) (j+1) (j+1) ⟨[],focus,parent⟩, + ExposureTree.freshLog_mapOutput,PMF.map_comp] + rfl + +lemma log_pair_probability (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) (p q : List (ι × τ)) : + (((ExposureTree.freshLog (gridPriorities N) + (tracedGridQuery H N d k ⟨[],focus,parent⟩)).map (fun z => + z.1.2.any (fun c => decide (c.address = p.reverse)) && + z.1.2.any (fun c => decide (c.address = q.reverse)))) true).toReal = + actualPairVisitProbability H N d k focus parent p q := by + unfold actualPairVisitProbability + change _ = (((ExposureTree.fresh (gridPriorities N) + (tracedGridQuery H N d k ⟨[],focus,parent⟩)).map _) true).toReal + rw [← ExposureTree.freshLog_outcome,PMF.map_comp] + rfl + +end CollisionPathSum + +theorem graph_collision_path_sum {n : ℕ} (G focus : Graph n) (parent : Option (Finset (Fin n))) + (hc : (QueryCall.mk [] focus parent).Separated (triangleHypergraph G)) + (N : ℕ) [NeZero N] (d k : ℕ) : + tracedCollisionProbability (triangleHypergraph G) N d k focus parent ≤ + ∑ pq ∈ legalCollisionPairs (triangleHypergraph G) d focus parent, + actualPairVisitProbability (triangleHypergraph G) N d k focus parent pq.1 pq.2 := by + classical + let H := triangleHypergraph G + let c : QueryCall (Finset (Fin n)) (Finset (Fin n)) := ⟨[],focus,parent⟩ + let P := ExposureTree.freshLog (gridPriorities N) (tracedGridQuery H N d k c) + let ev := fun (pq : List (Finset (Fin n) × Finset (Fin n)) × + List (Finset (Fin n) × Finset (Fin n))) + (z : (Bool × List (QueryCall (Finset (Fin n)) (Finset (Fin n)))) × List (Finset (Fin n))) => + z.1.2.any (fun a : QueryCall (Finset (Fin n)) (Finset (Fin n)) => decide (a.address = pq.1.reverse)) && + z.1.2.any (fun a : QueryCall (Finset (Fin n)) (Finset (Fin n)) => decide (a.address = pq.2.reverse)) + have hcov : ∀ z ∈ P.support, ExposureTree.repeats ∅ z.2 = true → + ∃ pq ∈ legalCollisionPairs H d focus parent, ev pq z = true := by + intro z hz hr + obtain ⟨a,ha,b,hb,hab,T,haT,hbT⟩ := graph_query_repeat_addresses G N d k c hc + (gridPriorities N) hz hr + obtain ⟨p,hp,rfl⟩ := tracedGridQuery_legal_path H N d k c (gridPriorities N) hz a ha + obtain ⟨q,hq,rfl⟩ := tracedGridQuery_legal_path H N d k c (gridPriorities N) hz b hb + have hpq : p ≠ q := by intro he; subst q; exact hab rfl + refine ⟨(p,q),?_,Bool.and_eq_true_iff.mpr ⟨?_,?_⟩⟩ + · apply Finset.mem_filter.mpr + exact ⟨Finset.mem_product.mpr ⟨hp,hq⟩,hpq,T,haT,hbT⟩ + · apply List.any_eq_true.mpr + refine ⟨callAtPath H c p,ha,?_⟩ + simp only [callAtPath_address,c,List.append_nil,decide_true] + · apply List.any_eq_true.mpr + refine ⟨callAtPath H c q,hb,?_⟩ + simp only [callAtPath_address,c,List.append_nil,decide_true] + have hh := pmf_boolean_finite_cover P (legalCollisionPairs H d focus parent) + (fun z => ExposureTree.repeats ∅ z.2) ev hcov + change tracedCollisionProbability H N d k focus parent ≤ _ + apply hh.trans_eq + apply Finset.sum_congr rfl + intro pq _ + exact log_pair_probability H N d k focus parent pq.1 pq.2 + +theorem graph_collision_weighted_path_sum {n : ℕ} (G focus : Graph n) + (parent : Option (Finset (Fin n))) + (hc : (QueryCall.mk [] focus parent).Separated (triangleHypergraph G)) + (N : ℕ) [NeZero N] (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) + (hq : GridRowQuality (triangleHypergraph G) N b) + (C : ℝ) (hC : 1 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) : + tracedCollisionProbability (triangleHypergraph G) N d k focus parent ≤ + C^3 * ∑ pq ∈ legalCollisionPairs (triangleHypergraph G) d focus parent, + pairFactorialWeight (prefixWeight (fun t => (2/(N : ℝ))*b t) k) pq.1 pq.2 := by + apply (graph_collision_path_sum G focus parent hc N d k).trans + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro pq hpq + obtain ⟨hp,hq'⟩ := Finset.mem_product.mp (Finset.mem_filter.mp hpq).1 + exact actualPairVisitProbability_weight (triangleHypergraph G) N b hb hq C hC hlower + d k hkd hkN focus parent pq.1 pq.2 hp hq' + +end SharpTerminalLeave + +open Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedChild.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedChild.lean new file mode 100644 index 0000000000000000000000000000000000000000..0e0fe57ab360e8235af62154b6a9171bc9b53bce --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedChild.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Probability.FiniteMean + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +structure MarkedChild where + required : Bool + law : PMF (Bool × Bool) + priority : ℕ := 0 + +noncomputable def markedDemand : List MarkedChild → Bool + | [] => false + | a :: as => a.required || markedDemand as + +noncomputable def markedCheck : List MarkedChild → PMF (Bool × Bool) + | [] => PMF.pure (true, true) + | a :: as => a.law.bind (fun z => + if z.1 then PMF.pure (false, ((!a.required) || z.2) && !markedDemand as) + else (markedCheck as).map (fun y => (y.1, ((!a.required) || z.2) && y.2))) + +noncomputable def markedGood (p : PMF (Bool × Bool)) : ℝ := + pmfMean p (fun z => if z.2 then 1 else 0) + +noncomputable def markedFailure (p : PMF (Bool × Bool)) : ℝ := + pmfMean p (fun z => if z.1 then 0 else 1) + +theorem markedGood_nonneg (p : PMF (Bool × Bool)) : 0 ≤ markedGood p := by + apply pmfMean_nonneg + intro z _ + split <;> norm_num + +theorem markedGood_le_one (p : PMF (Bool × Bool)) : markedGood p ≤ 1 := by + rw [← pmfMean_const p 1] + apply pmfMean_mono + intro z _ + split <;> norm_num + +theorem markedFailure_nonneg (p : PMF (Bool × Bool)) : 0 ≤ markedFailure p := by + apply pmfMean_nonneg + intro z _ + split <;> norm_num + +noncomputable def markedBound : List MarkedChild → ℝ + | [] => 1 + | a :: as => (if a.required then markedGood a.law + else if markedDemand as then markedFailure a.law else 1) * markedBound as + +theorem markedBound_nonneg (as : List MarkedChild) : 0 ≤ markedBound as := by + induction as with + | nil => exact zero_le_one + | cons a as ih => + apply mul_nonneg _ ih + split + · exact markedGood_nonneg _ + · split + · exact markedFailure_nonneg _ + · exact zero_le_one + +theorem markedBound_of_no_demand (as : List MarkedChild) (h : markedDemand as = false) : + markedBound as = 1 := by + induction as with + | nil => rfl + | cons a as ih => + have hh : a.required = false ∧ markedDemand as = false := by + simpa only [markedDemand, Bool.or_eq_false_iff] using h + simp [markedBound, hh.1, hh.2, ih hh.2] + +theorem marked_visitation_bound (as : List MarkedChild) : + markedGood (markedCheck as) ≤ markedBound as := by + induction as with + | nil => simp [markedGood, markedCheck, markedBound] + | cons a as ih => + let f : Bool × Bool → ℝ := fun z => + if a.required then (if z.2 then 1 else 0) + else if markedDemand as then (if z.1 then 0 else 1) else 1 + have hf : pmfMean a.law f = + if a.required then markedGood a.law + else if markedDemand as then markedFailure a.law else 1 := by + cases hr : a.required <;> cases hd : markedDemand as <;> + simp [f, hr, hd, markedGood, markedFailure] + change pmfMean (a.law.bind _) _ ≤ _ + rw [pmfMean_bind] + calc + _ ≤ pmfMean a.law (fun z => f z * markedBound as) := by + apply pmfMean_mono + rintro ⟨b, g⟩ _ + have hb := markedBound_nonneg as + have hg := markedGood_nonneg (markedCheck as) + have hu := markedGood_le_one (markedCheck as) + cases hr : a.required <;> cases hd : markedDemand as <;> + cases b <;> cases g <;> + simp only [hr, hd, Bool.not_false, Bool.not_true, Bool.false_or, + Bool.true_or, Bool.false_and, Bool.true_and, Bool.and_false, + Bool.and_true, Bool.false_eq_true, ↓reduceIte, + pmfMean_pure, pmfMean_map, f, pmfMean_const, + zero_mul, one_mul] + all_goals first + | exact ih + | exact hb + | exact le_refl _ + | simpa only [markedBound_of_no_demand as hd] using hu + | simp only [markedBound_of_no_demand as hd, le_refl] + _ = markedBound (a :: as) := by + rw [pmfMean_mul_const, hf] + rfl + +noncomputable def ordinaryCheck : List (PMF Bool) → PMF Bool + | [] => PMF.pure true + | p :: ps => p.bind (fun b => if b then PMF.pure false else ordinaryCheck ps) + +theorem markedCheck_original (as : List MarkedChild) : + (markedCheck as).map Prod.fst = ordinaryCheck (as.map (fun a => a.law.map Prod.fst)) := by + induction as with + | nil => simp [markedCheck, ordinaryCheck, PMF.pure_map] + | cons a as ih => + simp only [markedCheck, PMF.map_bind, List.map_cons, ordinaryCheck, PMF.bind_map] + congr 1 + funext z + simp only [Function.comp_apply] + cases z.1 <;> + simp only [ Bool.false_eq_true, ↓reduceIte, PMF.pure_map, PMF.map_comp] + exact ih + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedChildKernelProspective.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedChildKernelProspective.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd73271b7047419fc69a773a003dc6e67ba1c1a0 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedChildKernelProspective.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Coupling.GridUniformError +import OAI.Combinatorics.TriangleRemoval.Probability.MarkedSuccessTrueProbability +import OAI.Combinatorics.TriangleRemoval.Coupling.SelectedClockLawPair + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave +section ActualMarkedRows +variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +omit [Fintype ι] in + +lemma markedChildKernel_prospective (H : τ → Finset ι) (N : ℕ) [NeZero N] + (required : List (ι × τ) → Bool) (d t : ℕ) (htd : t ≤ d+1) (htN : t ≤ N) + (address : List (ι × τ)) (focus : Finset ι) (parent : Option τ) + (a : gridCandidates H focus parent) : + prospectiveFailure N t (fun u => markedSuccess + (markedChildKernel H N required d address focus parent a u)) = + gridCandidateFailure H N t a.val.1 a.val.2 := by + have hsum : (∑ u : Fin N, if u.val < t then markedSuccess + (markedChildKernel H N required d address focus parent a u) else 0) = + ∑ j ∈ Finset.range t, ∏ f ∈ (H a.val.2).erase a.val.1, + gridMessage H N N j f (some a.val.2) := by + calc + _ = ∑ u : Fin N, if u.val < t then + ∏ f ∈ (H a.val.2).erase a.val.1, gridMessage H N N u.val f (some a.val.2) + else 0 := by + apply Finset.sum_congr rfl + intro u _ + by_cases hu : u.val < t + · simp only [hu,↓reduceIte] + exact markedChildKernel_success_complete H N required d address focus parent a u (by omega) + · simp only [hu,↓reduceIte] + _ = _ := by + simpa only [Finset.sum_filter] using sum_fin_filter_lt_eq_range N t htN + (fun j => ∏ f ∈ (H a.val.2).erase a.val.1, gridMessage H N N j f (some a.val.2)) + unfold prospectiveFailure gridCandidateFailure + rw [hsum] + ring + +omit [Fintype ι] in + +theorem markedQuery_single_path (H : τ → Finset ι) (N : ℕ) [NeZero N] + (required : List (ι × τ) → Bool) (d k : ℕ) (hkd : k ≤ d+1) (hkN : k ≤ N) + (address : List (ι × τ)) (focus : Finset ι) (parent : Option τ) + (a : gridCandidates H focus parent) + (hreq : requiredCandidates H required address focus parent = {a}) (b : ℕ → ℝ) + (hfactor : ∀ t < k, ∀ (e : ι) (T : τ), e ∈ H T → + (7/8 : ℝ) ≤ gridCandidateFailure H N t e T) + (hfull : ∀ t < k, gridAnswerProbability H N N t focus parent ≤ (9/8 : ℝ)*b t) : + markedGood (ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required (d+1) k address focus parent)) ≤ + (1/(N : ℝ))*∑ u : Fin N, if u.val < k then + markedGood (markedChildKernel H N required d address focus parent a u)*(2*b u.val) + else 0 := by + rw [markedGridQueryDepth_candidate_kernel,hreq] + apply marked_row_single_path N _ (finsetCandidateOrder_perm _) a _ + (fun a u => markedSuccess (markedChildKernel H N required d address focus parent a u)) + k b (by intros; rfl) + · intro t ht a + rw [markedChildKernel_prospective H N required d t (by omega) (by omega)] + exact hfactor t ht a.val.1 a.val.2 (by + have ha := a.property + simp only [gridCandidates,Finset.mem_filter] at ha + exact ha.2.1) + · intro t ht + simp_rw [markedChildKernel_prospective H N required d t (by omega) (by omega)] + rw [gridCandidateFailure_product H N t (by omega)] + exact hfull t ht + +omit [Fintype ι] in + +theorem markedQuery_two_paths (H : τ → Finset ι) (N : ℕ) [NeZero N] + (required : List (ι × τ) → Bool) (d k : ℕ) (hkd : k ≤ d+1) (hkN : k ≤ N) + (address : List (ι × τ)) (focus : Finset ι) (parent : Option τ) + (a b : gridCandidates H focus parent) (hab : a ≠ b) + (hreq : requiredCandidates H required address focus parent = {a,b}) (w : ℕ → ℝ) + (hfactor : ∀ t < k, ∀ (e : ι) (T : τ), e ∈ H T → + (7/8 : ℝ) ≤ gridCandidateFailure H N t e T) + (hfull : ∀ t < k, gridAnswerProbability H N N t focus parent ≤ (9/8 : ℝ)*w t) : + markedGood (ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required (d+1) k address focus parent)) ≤ + (1/(N : ℝ))*∑ u : Fin N, (1/(N : ℝ))*∑ v : Fin N, + if u.val < k ∧ v.val < k then + (markedGood (markedChildKernel H N required d address focus parent a u)* + markedGood (markedChildKernel H N required d address focus parent b v))* + (2*w (max u.val v.val)) else 0 := by + rw [markedGridQueryDepth_candidate_kernel,hreq] + apply marked_row_two_paths N _ (finsetCandidateOrder_perm _) a b hab _ + (fun a u => markedSuccess (markedChildKernel H N required d address focus parent a u)) + k w (by intros; rfl) + · intro t ht a + rw [markedChildKernel_prospective H N required d t (by omega) (by omega)] + exact hfactor t ht a.val.1 a.val.2 (by + have ha := a.property + simp only [gridCandidates,Finset.mem_filter] at ha + exact ha.2.1) + · intro t ht + simp_rw [markedChildKernel_prospective H N required d t (by omega) (by omega)] + rw [gridCandidateFailure_product H N t (by omega)] + exact hfull t ht + +end ActualMarkedRows +end SharpTerminalLeave + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedDemand.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedDemand.lean new file mode 100644 index 0000000000000000000000000000000000000000..07df5fcc5be4d4bc99c58cb397a9174398bcbe02 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedDemand.lean @@ -0,0 +1,53 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ChargesCovered + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +theorem markedDemand_iff (as : List MarkedChild) : + markedDemand as = true ↔ ∃ a ∈ as, a.required = true := by + induction as with + | nil => simp [markedDemand] + | cons a as ih => simp [markedDemand, ih, or_and_right, exists_or] + +theorem priority_charges_covered (as : List MarkedChild) (t : ℕ) + (hs : as.Pairwise (fun a b => a.priority ≤ b.priority)) + (ht : ∃ b ∈ as, b.required = true ∧ t ≤ b.priority) : + ChargesCovered (fun a => decide (a.priority < t)) as := by + intro pre a post heq _ hcharge + have ha : a.priority < t := of_decide_eq_true hcharge + rcases ht with ⟨b, hb, hbr, hbt⟩ + rw [heq, List.mem_append] at hb + have hp := List.pairwise_append.mp (heq ▸ hs) + have hbp : b ∈ post := by + rcases hb with hb | hb + · have hle := hp.2.2 b hb a (by simp) + omega + · simp only [List.mem_cons] at hb + rcases hb with rfl | hb + · omega + · exact hb + exact (markedDemand_iff post).mpr ⟨b, hbp, hbr⟩ + +theorem marked_visitation_priority (as : List MarkedChild) (t : ℕ) + (hs : as.Pairwise (fun a b => a.priority ≤ b.priority)) + (ht : ∃ b ∈ as, b.required = true ∧ t ≤ b.priority) : + markedGood (markedCheck as) ≤ + (as.map (chargedFactor (fun a => decide (a.priority < t)))).prod := + marked_visitation_charged _ _ (priority_charges_covered as t hs ht) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedIndexedAttachmentPattern.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedIndexedAttachmentPattern.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c5b77dfddfb862a81f0f3c6e84b2d46ff79901f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedIndexedAttachmentPattern.lean @@ -0,0 +1,64 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching +import OAI.Combinatorics.TriangleRemoval.Process.ValidIndexedAttachments + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave +open Classical in + +theorem marked_indexed_attachment_pattern_count {K s : ℕ} + (E : Finset (Finset (Fin K))) (birth : Fin s → Fin K) (hE : E.card ≤ 2) (a b : Option (Fin s)) : + Fintype.card (Σ F : {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v}, + {f // f ∈ indexedAttachmentFamily E birth F.val}) ≤ 6^s := by + classical + rw [Fintype.card_sigma] + calc + ∑ F : {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v}, + Fintype.card {f // f ∈ indexedAttachmentFamily E birth F.val} + ≤ ∑ _F : {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v}, 2^s := by + apply Finset.sum_le_sum + intro F _ + simpa only [Fintype.card_coe] using fixed_forest_indexed_attachment_count E birth hE F.val + _ = Fintype.card {F : PathForest s // ∀ v, F.OnPath a v ∨ F.OnPath b v} * 2^s := by + simp only [Finset.sum_const,Finset.card_univ,smul_eq_mul] + _ ≤ 3^s * 2^s := Nat.mul_le_mul_right _ (PathForest.two_path_forest_count a b) + _ = 6^s := by rw [← Nat.mul_pow] + +open Classical in + +theorem all_marked_indexed_attachment_pattern_count {K s : ℕ} {M : Type*} [Fintype M] + (E : Finset (Finset (Fin K))) (birth : Fin s → Fin K) (hE : E.card ≤ 2) (mark : M → Option (Fin s)) : + Fintype.card (Σ ab : M × M, + Σ F : {F : PathForest s // ∀ v, F.OnPath (mark ab.1) v ∨ F.OnPath (mark ab.2) v}, + {f // f ∈ indexedAttachmentFamily E birth F.val}) ≤ (Fintype.card M)^2 * 6^s := by + classical + rw [Fintype.card_sigma] + calc + _ ≤ ∑ _ab : M × M, 6^s := by + apply Finset.sum_le_sum + intro ab _ + exact marked_indexed_attachment_pattern_count E birth hE _ _ + _ = (Fintype.card M)^2 * 6^s := by + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_prod,smul_eq_mul,pow_two] + +end SharpTerminalLeave + +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedRow.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedRow.lean new file mode 100644 index 0000000000000000000000000000000000000000..41259752f03ab59257785c12971462509e202dd8 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedRow.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ProgramDemand + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +theorem markedDemand_map_priority {A : Type*} (as : List A) + (req : A → Bool) (law : A → PMF (Bool × Bool)) (s t : A → ℕ) : + markedDemand (as.map (fun a => (⟨req a,law a,s a⟩ : MarkedChild))) = + markedDemand (as.map (fun a => (⟨req a,law a,t a⟩ : MarkedChild))) := by + induction as with + | nil => rfl + | cons a as ih => simp only [List.map_cons,markedDemand,ih] + +theorem markedCheck_map_priority {A : Type*} (as : List A) + (req : A → Bool) (law : A → PMF (Bool × Bool)) (s t : A → ℕ) : + markedCheck (as.map (fun a => (⟨req a,law a,s a⟩ : MarkedChild))) = + markedCheck (as.map (fun a => (⟨req a,law a,t a⟩ : MarkedChild))) := by + induction as with + | nil => rfl + | cons a as ih => + simp only [List.map_cons,markedCheck,ih, + markedDemand_map_priority as req law s t] + +section GridKernel +variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def actualMarkedRow (H : τ → Finset ι) (N : ℕ) [NeZero N] + (required : List (ι × τ) → Bool) (d k : ℕ) (address : List (ι × τ)) + (focus : Finset ι) (parent : Option τ) (ω : (ι × τ) → Fin N) : List MarkedChild := + ((((gridCandidates H focus parent).toList).map (fun a => (a,ω a))).mergeSort + (fun a b => a.2.val ≤ b.2.val)).map (fun p => + ⟨required (p.1 :: address), + if p.2.val < k then ExposureTree.fresh (fun _ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required d p.2.val (p.1 :: address) + ((H p.1.2).erase p.1.1) (some p.1.2)) + else PMF.pure (false,false), p.2.val⟩) + +theorem markedGridQueryDepth_kernel (H : τ → Finset ι) (N : ℕ) [NeZero N] + (required : List (ι × τ) → Bool) (d k : ℕ) (address : List (ι × τ)) + (focus : Finset ι) (parent : Option τ) : + ExposureTree.fresh (fun _ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required (d+1) k address focus parent) = + (productPMF (fun _ : ι × τ => PMF.uniformOfFintype (Fin N))).bind + (fun ω => markedCheck (actualMarkedRow H N required d k address focus parent ω)) := by + classical + rw [markedGridQueryDepth,ExposureTree.fresh_bind] + rw [← ExposureTree.exposeLabeled_table + (fun _ : τ => PMF.uniformOfFintype (Fin N)) Prod.snd + (gridCandidates H focus parent).toList (Finset.nodup_toList _) + (fun _ : ι × τ => PMF.uniformOfFintype (Fin N)) (by intros; rfl)] + rw [PMF.bind_map] + congr 1 + funext ω + dsimp only [Function.comp_def] + rw [ExposureTree.fresh_checkMarked] + simp only [List.map_map,Function.comp_def] + unfold actualMarkedRow + calc + _ = markedCheck + (((((gridCandidates H focus parent).toList).map (fun a => (a,ω a))).mergeSort + (fun a b => a.2.val ≤ b.2.val)).map (fun p => + (⟨required (p.1 :: address), + if p.2.val < k then ExposureTree.fresh (fun _ : τ => PMF.uniformOfFintype (Fin N)) + (markedGridQueryDepth H N required d p.2.val (p.1 :: address) + ((H p.1.2).erase p.1.1) (some p.1.2)) + else PMF.pure (false,false),0⟩ : MarkedChild))) := by + congr 1 + apply List.map_congr_left + intro p _ + split <;> rfl + _ = _ := markedCheck_map_priority _ _ _ _ _ + +end GridKernel +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedSuccess.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedSuccess.lean new file mode 100644 index 0000000000000000000000000000000000000000..935ddd05b2c472c7f42c7a3459b95d86396ffcbe --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MarkedSuccess.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.MarkedDemand +import OAI.Combinatorics.TriangleRemoval.Probability.ProductPMFMeanProduct + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +noncomputable def markedSuccess (p : PMF (Bool × Bool)) : ℝ := + pmfMean p (fun z => if z.1 then 1 else 0) + +@[simp] theorem markedFailure_eq_one_sub (p : PMF (Bool × Bool)) : + markedFailure p = 1 - markedSuccess p := by + unfold markedFailure markedSuccess + rw [← pmfMean_const p 1, ← pmfMean_sub] + apply pmfMean_congr + intro z _ + cases z.1 <;> simp + +noncomputable def selectedClockLaw {K : Type*} [DecidableEq K] + (N : ℕ) [NeZero N] (S : Finset K) (σ : K → Fin N) (k : K) : PMF (Fin N) := + if k ∈ S then PMF.pure (σ k) else PMF.uniformOfFintype (Fin N) + +theorem selectedClockLaw_support {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (S : Finset K) (σ ω : K → Fin N) + (hω : ω ∈ (productPMF (selectedClockLaw N S σ)).support) : + ∀ k ∈ S, ω k = σ k := by + intro k hk + have h := (productPMF_support _ ω).mp hω k + simpa [selectedClockLaw,hk] using h + +noncomputable def rowChild {K : Type*} [DecidableEq K] {N : ℕ} + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline : ℕ) (ω : K → Fin N) (k : K) : MarkedChild := + ⟨decide (k ∈ S), if (ω k).val < deadline then p k (ω k) + else PMF.pure (false,false), (ω k).val⟩ + +noncomputable def markedRow {K : Type*} [Fintype K] [DecidableEq K] {N : ℕ} + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline : ℕ) (ω : K → Fin N) : List MarkedChild := + ((Finset.univ.toList).map (rowChild S p deadline ω)).mergeSort + (fun a b => decide (a.priority ≤ b.priority)) + +theorem markedRow_sorted {K : Type*} [Fintype K] [DecidableEq K] {N : ℕ} + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline : ℕ) (ω : K → Fin N) : + (markedRow S p deadline ω).Pairwise (fun a b => a.priority ≤ b.priority) := by + unfold markedRow + simpa only [decide_eq_true_eq] using List.pairwise_mergeSort + (le := fun a b : MarkedChild => decide (a.priority ≤ b.priority)) + (fun a b c hab hbc => by simp only [decide_eq_true_eq] at *; omega) + (fun a b => by simp only [Bool.or_eq_true,decide_eq_true_eq]; omega) _ + +theorem markedRow_factor_product {K : Type*} [Fintype K] [DecidableEq K] {N : ℕ} + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline t : ℕ) (ω : K → Fin N) : + ((markedRow S p deadline ω).map + (chargedFactor (fun a => decide (a.priority < t)))).prod = + ∏ k, chargedFactor (fun a => decide (a.priority < t)) (rowChild S p deadline ω k) := by + unfold markedRow + rw [(List.mergeSort_perm _ _).map _ |>.prod_eq,List.map_map] + exact Finset.prod_map_toList _ _ + +theorem markedRow_pointwise {K : Type*} [Fintype K] [DecidableEq K] {N : ℕ} + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline t : ℕ) (htd : t ≤ deadline) (ω : K → Fin N) + (hsel : ∀ k ∈ S, (ω k).val < deadline) + (ht : ∃ k ∈ S, t ≤ (ω k).val) : + markedGood (markedCheck (markedRow S p deadline ω)) ≤ + ∏ k, if k ∈ S then markedGood (p k (ω k)) + else if (ω k).val < t then markedFailure (p k (ω k)) else 1 := by + have hw : ∃ a ∈ markedRow S p deadline ω, a.required = true ∧ t ≤ a.priority := by + obtain ⟨k,hk,hkt⟩ := ht + refine ⟨rowChild S p deadline ω k, ?_, ?_, hkt⟩ + · simp only [markedRow,List.mem_mergeSort,List.mem_map,Finset.mem_toList] + exact ⟨k,Finset.mem_univ _,rfl⟩ + · simpa only [rowChild,decide_eq_true_eq] using hk + have hb := marked_visitation_priority _ t (markedRow_sorted S p deadline ω) hw + rw [markedRow_factor_product] at hb + convert hb using 1 + apply Finset.prod_congr rfl + intro k _ + by_cases hk : k ∈ S + · simp [chargedFactor,rowChild,hk,hsel k hk] + · by_cases hkt : (ω k).val < t + · have hkd : (ω k).val < deadline := lt_of_lt_of_le hkt htd + simp [chargedFactor,rowChild,hk,hkt,hkd] + · simp [chargedFactor,rowChild,hk,hkt] + +theorem markedRow_integrated {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (S : Finset K) (σ : K → Fin N) + (p : K → Fin N → PMF (Bool × Bool)) (deadline t : ℕ) + (htd : t ≤ deadline) (hsel : ∀ k ∈ S, (σ k).val < deadline) + (ht : ∃ k ∈ S, t ≤ (σ k).val) : + pmfMean (productPMF (selectedClockLaw N S σ)) + (fun ω => markedGood (markedCheck (markedRow S p deadline ω))) ≤ + ∏ k, if k ∈ S then markedGood (p k (σ k)) else + 1 - (∑ u : Fin N, if u.val < t then markedSuccess (p k u) else 0) / (N : ℝ) := by + calc + _ ≤ pmfMean (productPMF (selectedClockLaw N S σ)) + (fun ω => ∏ k, if k ∈ S then markedGood (p k (ω k)) + else if (ω k).val < t then markedFailure (p k (ω k)) else 1) := by + apply pmfMean_mono + intro ω hω + have he := selectedClockLaw_support N S σ ω hω + apply markedRow_pointwise S p deadline t htd ω + · intro k hk + simpa only [he k hk] using hsel k hk + · obtain ⟨k,hk,htk⟩ := ht + exact ⟨k,hk,by rwa [he k hk]⟩ + _ = _ := by + rw [productPMF_mean_product (selectedClockLaw N S σ) + (fun k u => if k ∈ S then markedGood (p k u) + else if u.val < t then markedFailure (p k u) else 1)] + apply Finset.prod_congr rfl + intro k _ + by_cases hk : k ∈ S + · simp [selectedClockLaw,hk] + · simp only [selectedClockLaw,hk,↓reduceIte,markedFailure_eq_one_sub] + exact uniform_prospective_failure N t (fun u => markedSuccess (p k u)) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/MemAddressId.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MemAddressId.lean new file mode 100644 index 0000000000000000000000000000000000000000..abb67928d575b7b25cc52dc70a24112cb935bea1 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MemAddressId.lean @@ -0,0 +1,100 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth +import OAI.Combinatorics.TriangleRemoval.Queries.RecordedCallForest +import OAI.Combinatorics.TriangleRemoval.Process.EdgeMatching +import OAI.Combinatorics.TriangleRemoval.Process.PathForest +import OAI.Combinatorics.TriangleRemoval.Queries.Address + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.PathForest +variable {s : ℕ} {α : Type*} + +lemma mem_address_id (F : PathForest s) (i j : Fin s) : + i ∈ F.address id j ↔ F.Ancestor i j := by + induction j using (measure (fun j : Fin s => j.val)).wf.induction with + | h j ih => + cases hp : F.parent j with + | none => + rw [F.address_none id j hp,List.mem_singleton] + constructor + · rintro rfl + exact Relation.ReflTransGen.refl + · intro h + rcases F.ancestor_eq_or_predecessor h with he | ⟨k,hk,_⟩ + · exact he + · exact False.elim (by change F.parent j = some k at hk; rw [hp] at hk; cases hk) + | some k => + rw [F.address_some id j k hp,List.mem_cons,ih k (F.property j k hp)] + constructor + · rintro (rfl | hik) + · exact Relation.ReflTransGen.refl + · exact hik.tail hp + · intro h + rcases F.ancestor_eq_or_predecessor h with he | ⟨l,hl,hil⟩ + · exact Or.inl he + · have he := F.predecessor_unique hl hp + subst l + exact Or.inr hil + +lemma address_map (F : PathForest s) (key : Fin s → α) (i : Fin s) : + F.address key i = (F.address id i).map key := by + induction i using (measure (fun i : Fin s => i.val)).wf.induction with + | h i ih => + cases hp : F.parent i with + | none => rw [F.address_none key i hp,F.address_none id i hp]; rfl + | some j => + rw [F.address_some key i j hp,F.address_some id i j hp, + ih j (F.property i j hp)] + rfl + +lemma option_address_length (F : PathForest s) (key : Fin s → α) (a : Option (Fin s)) : + (a.elim [] (F.address key)).length = (a.elim [] (F.address id)).length := by + cases a with + | none => rfl + | some i => simp only [Option.elim_some,F.address_map key,List.length_map] + +lemma mem_option_address (F : PathForest s) (a : Option (Fin s)) (i : Fin s) : + i ∈ a.elim [] (F.address id) ↔ F.OnPath a i := by + cases a with + | none => simp [OnPath] + | some j => + simp only [Option.elim_some,F.mem_address_id,OnPath,Option.some.injEq] + exact ⟨fun h => ⟨j,rfl,h⟩,fun ⟨w,hw,h⟩ => hw ▸ h⟩ + +lemma two_mark_size (F : PathForest s) (key : Fin s → α) (a b : Option (Fin s)) + (hcover : ∀ i, F.OnPath a i ∨ F.OnPath b i) : + s ≤ (a.elim [] (F.address key)).length + (b.elim [] (F.address key)).length := by + classical + rw [F.option_address_length key a,F.option_address_length key b] + have hsub : (Finset.univ : Finset (Fin s)) ⊆ + (a.elim [] (F.address id)).toFinset ∪ (b.elim [] (F.address id)).toFinset := by + intro i _ + rcases hcover i with h | h + · exact Finset.mem_union_left _ (List.mem_toFinset.mpr ((F.mem_option_address a i).mpr h)) + · exact Finset.mem_union_right _ (List.mem_toFinset.mpr ((F.mem_option_address b i).mpr h)) + calc + s = (Finset.univ : Finset (Fin s)).card := (Finset.card_fin s).symm + _ ≤ _ := Finset.card_le_card hsub + _ ≤ _ := Finset.card_union_le _ _ + _ ≤ _ := Nat.add_le_add (List.toFinset_card_le _) (List.toFinset_card_le _) + +end SharpTerminalLeave.PathForest + +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/MessageCandidatesReindex.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MessageCandidatesReindex.lean new file mode 100644 index 0000000000000000000000000000000000000000..834bb80e4a482ed02347992ac2327c30bbe2d9b9 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/MessageCandidatesReindex.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Coupling.UnitTime + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave +section Reindex +variable {ι τ ι' τ' : Type*} [Fintype ι] [Fintype τ] [Fintype ι'] [Fintype τ'] + [DecidableEq ι] [DecidableEq τ] [DecidableEq ι'] [DecidableEq τ'] + (H : τ → Finset ι) (H' : τ' → Finset ι') (f : ι' ↪ ι) (g : τ' ↪ τ) + (hH : ∀ T, H (g T) = (H' T).map f) + (hlocal : ∀ e : ι', ∀ T, f e ∈ H T → ∃ T', g T' = T) +include hH hlocal + +omit [Fintype ι] [Fintype ι'] in + +theorem messageCandidates_reindex (e : ι') (p : Option τ') : + messageCandidates H (f e) (p.map g) = (messageCandidates H' e p).map g := by + ext T + simp only [messageCandidates, Finset.mem_filter, Finset.mem_univ, true_and, + Finset.mem_map] + constructor + · rintro ⟨he, hp⟩ + obtain ⟨T', rfl⟩ := hlocal e T he + refine ⟨T', ⟨?_, ?_⟩, rfl⟩ + · rw [hH] at he + exact Finset.mem_map.mp he |>.elim (fun _ hz => f.injective hz.2 ▸ hz.1) + · intro hh + exact hp (by rw [← hh]; rfl) + · rintro ⟨T', ⟨he, hp⟩, rfl⟩ + refine ⟨?_, ?_⟩ + · rw [hH] + exact Finset.mem_map.mpr ⟨e, he, rfl⟩ + · intro hh + apply hp + cases p with + | none => contradiction + | some S => + simp only [Option.map_some, Option.some.injEq] at hh ⊢ + exact g.injective hh + +omit [Fintype ι] [Fintype ι'] in + +theorem cavityDepth_reindex (k : ℕ) (e : ι') (p : Option τ') (t : ℝ) : + cavityDepth H k (f e) (p.map g) t = cavityDepth H' k e p t := by + induction k generalizing e p t with + | zero => rfl + | succ k ih => + simp only [cavityDepth, cavityOperator, messageCandidates_reindex H H' f g hH hlocal, + Finset.prod_map] + apply Finset.prod_congr rfl + intro T _ + congr 1 + unfold messageIntegral + apply intervalIntegral.integral_congr + intro s _ + dsimp only + rw [hH, ← Finset.map_erase, Finset.prod_map] + apply Finset.prod_congr rfl + intro e' _ + exact ih e' (some T) s + +theorem cavityLimit_reindex (e : ι') (p : Option τ') (t : ℝ) : + cavityLimit H (f e) (p.map g) t = cavityLimit H' e p t := by + apply tendsto_nhds_unique (tendsto_cavityDepth H (f e) (p.map g) t) + convert tendsto_cavityDepth H' e p t using 1 + funext k + exact cavityDepth_reindex H H' f g hH hlocal k e p t + +end Reindex +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/OrderedMarkedRow.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/OrderedMarkedRow.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c439ce9c0528ef042b1d8b87736faa33a0b304d --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/OrderedMarkedRow.lean @@ -0,0 +1,149 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ProspectiveFailure + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +noncomputable def orderedMarkedRow {K : Type*} [DecidableEq K] {N : ℕ} + (order : List K) (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline : ℕ) (ω : K → Fin N) : List MarkedChild := + (order.map (rowChild S p deadline ω)).mergeSort + (fun a b => decide (a.priority ≤ b.priority)) + +theorem orderedMarkedRow_sorted {K : Type*} [DecidableEq K] {N : ℕ} + (order : List K) (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline : ℕ) (ω : K → Fin N) : + (orderedMarkedRow order S p deadline ω).Pairwise (fun a b => a.priority ≤ b.priority) := by + unfold orderedMarkedRow + simpa only [decide_eq_true_eq] using List.pairwise_mergeSort + (le := fun a b : MarkedChild => decide (a.priority ≤ b.priority)) + (fun a b c hab hbc => by simp only [decide_eq_true_eq] at *; omega) + (fun a b => by simp only [Bool.or_eq_true,decide_eq_true_eq]; omega) _ + +theorem orderedMarkedRow_factor_product {K : Type*} [Fintype K] [DecidableEq K] {N : ℕ} + (order : List K) (horder : order.Perm Finset.univ.toList) + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline t : ℕ) (ω : K → Fin N) : + ((orderedMarkedRow order S p deadline ω).map + (chargedFactor (fun a => decide (a.priority < t)))).prod = + ∏ k, chargedFactor (fun a => decide (a.priority < t)) (rowChild S p deadline ω k) := by + unfold orderedMarkedRow + rw [(List.mergeSort_perm _ _).map _ |>.prod_eq,List.map_map] + rw [(horder.map _).prod_eq] + exact Finset.prod_map_toList _ _ + +theorem orderedMarkedRow_pointwise {K : Type*} [Fintype K] [DecidableEq K] {N : ℕ} + (order : List K) (horder : order.Perm Finset.univ.toList) + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) + (deadline t : ℕ) (htd : t ≤ deadline) (ω : K → Fin N) + (hsel : ∀ k ∈ S, (ω k).val < deadline) + (ht : ∃ k ∈ S, t ≤ (ω k).val) : + markedGood (markedCheck (orderedMarkedRow order S p deadline ω)) ≤ + ∏ k, if k ∈ S then markedGood (p k (ω k)) + else if (ω k).val < t then markedFailure (p k (ω k)) else 1 := by + have hw : ∃ a ∈ orderedMarkedRow order S p deadline ω, + a.required = true ∧ t ≤ a.priority := by + obtain ⟨k,hk,hkt⟩ := ht + refine ⟨rowChild S p deadline ω k, ?_, ?_, hkt⟩ + · simp only [orderedMarkedRow,List.mem_mergeSort,List.mem_map] + exact ⟨k,horder.mem_iff.mpr (by simp),rfl⟩ + · simpa only [rowChild,decide_eq_true_eq] using hk + have hb := marked_visitation_priority _ t (orderedMarkedRow_sorted order S p deadline ω) hw + rw [orderedMarkedRow_factor_product order horder] at hb + convert hb using 1 + apply Finset.prod_congr rfl + intro k _ + by_cases hk : k ∈ S + · simp [chargedFactor,rowChild,hk,hsel k hk] + · by_cases hkt : (ω k).val < t + · have hkd : (ω k).val < deadline := lt_of_lt_of_le hkt htd + simp [chargedFactor,rowChild,hk,hkt,hkd] + · simp [chargedFactor,rowChild,hk,hkt] + +theorem orderedMarkedRow_integrated {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (order : List K) (horder : order.Perm Finset.univ.toList) + (S : Finset K) (σ : K → Fin N) + (p : K → Fin N → PMF (Bool × Bool)) (deadline t : ℕ) + (htd : t ≤ deadline) (hsel : ∀ k ∈ S, (σ k).val < deadline) + (ht : ∃ k ∈ S, t ≤ (σ k).val) : + pmfMean (productPMF (selectedClockLaw N S σ)) + (fun ω => markedGood (markedCheck (orderedMarkedRow order S p deadline ω))) ≤ + ∏ k, if k ∈ S then markedGood (p k (σ k)) else + 1 - (∑ u : Fin N, if u.val < t then markedSuccess (p k u) else 0) / (N : ℝ) := by + calc + _ ≤ pmfMean (productPMF (selectedClockLaw N S σ)) + (fun ω => ∏ k, if k ∈ S then markedGood (p k (ω k)) + else if (ω k).val < t then markedFailure (p k (ω k)) else 1) := by + apply pmfMean_mono + intro ω hω + have he := selectedClockLaw_support N S σ ω hω + apply orderedMarkedRow_pointwise order horder S p deadline t htd ω + · intro k hk + simpa only [he k hk] using hsel k hk + · obtain ⟨k,hk,htk⟩ := ht + exact ⟨k,hk,by rwa [he k hk]⟩ + _ = _ := by + rw [productPMF_mean_product (selectedClockLaw N S σ) + (fun k u => if k ∈ S then markedGood (p k u) + else if u.val < t then markedFailure (p k u) else 1)] + apply Finset.prod_congr rfl + intro k _ + by_cases hk : k ∈ S + · simp [selectedClockLaw,hk] + · simp only [selectedClockLaw,hk,↓reduceIte,markedFailure_eq_one_sub] + exact uniform_prospective_failure N t (fun u => markedSuccess (p k u)) + +theorem orderedMarkedRow_cavity_bound {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (order : List K) (horder : order.Perm Finset.univ.toList) + (S : Finset K) (σ : K → Fin N) + (p : K → Fin N → PMF (Bool × Bool)) (q : K → Fin N → ℝ) + (deadline t : ℕ) (htd : t ≤ deadline) (hsel : ∀ k ∈ S, (σ k).val < deadline) + (ht : ∃ k ∈ S, t ≤ (σ k).val) (hS : S.card ≤ 2) + (hmarg : ∀ k ∉ S, ∀ u, markedSuccess (p k u) = q k u) + (b : ℝ) (hfactor : ∀ k, (7 / 8 : ℝ) ≤ prospectiveFailure N t (q k)) + (hfull : ∏ k, prospectiveFailure N t (q k) ≤ (9 / 8 : ℝ) * b) : + markedGood ((productPMF (selectedClockLaw N S σ)).bind + (fun ω => markedCheck (orderedMarkedRow order S p deadline ω))) ≤ + (∏ k ∈ S, markedGood (p k (σ k))) * (2 * b) := by + rw [markedGood_bind] + have h := orderedMarkedRow_integrated N order horder S σ p deadline t htd hsel ht + let f : K → ℝ := fun k => prospectiveFailure N t (q k) + have he : (∏ k, if k ∈ S then markedGood (p k (σ k)) else + 1 - (∑ u : Fin N, if u.val < t then markedSuccess (p k u) else 0) / (N : ℝ)) = + (∏ k ∈ S, markedGood (p k (σ k))) * (∏ k ∈ Finset.univ \ S, f k) := by + have hp : (fun k => if k ∈ S then markedGood (p k (σ k)) else + 1 - (∑ u : Fin N, if u.val < t then markedSuccess (p k u) else 0) / (N : ℝ)) = + (fun k => if k ∈ S then markedGood (p k (σ k)) else f k) := by + funext k + by_cases hk : k ∈ S + · simp only [hk,↓reduceIte] + · simp only [hk,↓reduceIte,f,prospectiveFailure,hmarg k hk] + rw [hp,Finset.prod_ite] + congr 1 + · congr 1 + ext k + simp + · congr 1 + ext k + simp + rw [he] at h + have hf := offpattern_product_bound Finset.univ S (Finset.subset_univ S) hS f b + (fun k _ => hfactor k) hfull + exact h.trans (mul_le_mul_of_nonneg_left hf (Finset.prod_nonneg + (fun k _ => markedGood_nonneg (p k (σ k))))) + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/OrderedMarkedRowUnweighted.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/OrderedMarkedRowUnweighted.lean new file mode 100644 index 0000000000000000000000000000000000000000..1568576a4f6dfe2608d578fdaefdac7249395e67 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/OrderedMarkedRowUnweighted.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.OrderedMarkedRow + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave + +theorem orderedMarkedRow_unweighted {K : Type*} [Fintype K] [DecidableEq K] {N : ℕ} + (order : List K) (horder : order.Perm Finset.univ.toList) + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) (deadline : ℕ) (ω : K → Fin N) : + markedGood (markedCheck (orderedMarkedRow order S p deadline ω)) ≤ + ∏ k ∈ S, if (ω k).val < deadline then markedGood (p k (ω k)) else 0 := by + have hc : ChargesCovered (fun _ => false) (orderedMarkedRow order S p deadline ω) := by + intro pre a post hh ha hb + simp at hb + have hb := marked_visitation_charged _ _ hc + refine hb.trans_eq ?_ + unfold orderedMarkedRow + rw [(List.mergeSort_perm _ _).map _ |>.prod_eq,List.map_map,(horder.map _).prod_eq, + Finset.prod_map_toList] + calc + _ = ∏ k, if k ∈ S then + (if (ω k).val < deadline then markedGood (p k (ω k)) else 0) else 1 := by + apply Finset.prod_congr rfl + intro k _ + by_cases hk : k ∈ S + · by_cases hu : (ω k).val < deadline + · simp [chargedFactor,rowChild,hk,hu] + · simp [chargedFactor,rowChild,hk,hu,markedGood] + · simp [chargedFactor,rowChild,hk] + _ = _ := by + rw [Finset.prod_ite] + simp only [Finset.prod_const_one,mul_one] + congr 1 + ext k + simp + +theorem orderedMarkedRow_forbidden {K : Type*} [Fintype K] [DecidableEq K] {N : ℕ} + (order : List K) (horder : order.Perm Finset.univ.toList) + (S : Finset K) (p : K → Fin N → PMF (Bool × Bool)) (deadline : ℕ) (ω : K → Fin N) + (k : K) (hk : k ∈ S) (hu : deadline ≤ (ω k).val) : + markedGood (markedCheck (orderedMarkedRow order S p deadline ω)) = 0 := by + apply le_antisymm _ (markedGood_nonneg _) + have hb := orderedMarkedRow_unweighted order horder S p deadline ω + have hz : (∏ a ∈ S, if (ω a).val < deadline then markedGood (p a (ω a)) else 0) = 0 := by + apply Finset.prod_eq_zero hk + simp only [not_lt_of_ge hu,↓reduceIte] + rwa [hz] at hb + +theorem selectedClockLaw_singleton {K : Type*} [DecidableEq K] + (N : ℕ) [NeZero N] (a : K) (u : Fin N) : + selectedClockLaw N {a} (fun _ => u) = + Function.update (fun _ : K => PMF.uniformOfFintype (Fin N)) a (PMF.pure u) := by + funext k + by_cases hk : k = a + · subst k + simp [selectedClockLaw] + · simp [selectedClockLaw,hk] + +theorem marked_row_single_path {K : Type*} [Fintype K] [DecidableEq K] + (N : ℕ) [NeZero N] (order : List K) (horder : order.Perm Finset.univ.toList) + (a : K) (p : K → Fin N → PMF (Bool × Bool)) (q : K → Fin N → ℝ) + (deadline : ℕ) (b : ℕ → ℝ) + (hmarg : ∀ k ≠ a, ∀ u, markedSuccess (p k u) = q k u) + (hfactor : ∀ t < deadline, ∀ k, (7 / 8 : ℝ) ≤ prospectiveFailure N t (q k)) + (hfull : ∀ t < deadline, ∏ k, prospectiveFailure N t (q k) ≤ (9 / 8 : ℝ) * b t) : + markedGood ((productPMF (fun _ : K => PMF.uniformOfFintype (Fin N))).bind + (fun ω => markedCheck (orderedMarkedRow order {a} p deadline ω))) ≤ + (1 / (N : ℝ)) * ∑ u : Fin N, + if u.val < deadline then markedGood (p a u) * (2 * b u.val) else 0 := by + rw [productPMF_split (fun _ : K => PMF.uniformOfFintype (Fin N)) a, + PMF.bind_bind,markedGood_bind] + have hpoint : ∀ u : Fin N, + markedGood ((productPMF (Function.update (fun _ : K => PMF.uniformOfFintype (Fin N)) + a (PMF.pure u))).bind + (fun ω => markedCheck (orderedMarkedRow order {a} p deadline ω))) ≤ + if u.val < deadline then markedGood (p a u) * (2 * b u.val) else 0 := by + intro u + rw [← selectedClockLaw_singleton N a u] + by_cases hu : u.val < deadline + · simp only [hu,↓reduceIte] + have hs : ∀ k ∈ ({a} : Finset K), ((fun _ => u) k).val < deadline := by + intro k _ + exact hu + have ht : ∃ k ∈ ({a} : Finset K), u.val ≤ ((fun _ => u) k).val := ⟨a,by simp,le_rfl⟩ + simpa only [Finset.prod_singleton] using orderedMarkedRow_cavity_bound N order horder {a} + (fun _ => u) p q deadline u.val (Nat.le_of_lt hu) hs ht (by simp) + (fun k hk v => hmarg k (by simpa only [Finset.mem_singleton] using hk) v) + (b u.val) (hfactor u.val hu) (hfull u.val hu) + · simp only [hu,↓reduceIte] + rw [markedGood_bind] + apply le_trans (pmfMean_mono _ (g := fun _ => 0) ?_) (by simp) + intro ω hω + have he := selectedClockLaw_support N {a} (fun _ => u) ω hω a (by simp) + rw [orderedMarkedRow_forbidden order horder {a} p deadline ω a (by simp) + (by simpa only [he] using Nat.le_of_not_gt hu)] + calc + _ ≤ pmfMean (PMF.uniformOfFintype (Fin N)) + (fun u => if u.val < deadline then markedGood (p a u) * (2 * b u.val) else 0) := + pmfMean_mono _ (fun u _ => hpoint u) + _ = _ := by + simp only [pmfMean,PMF.uniformOfFintype_apply,ENNReal.toReal_inv, + ENNReal.toReal_natCast,Fintype.card_fin,one_div,Finset.mul_sum] + +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/RecordedCallForest.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/RecordedCallForest.lean new file mode 100644 index 0000000000000000000000000000000000000000..2394a19f040257933ff0e83f08f4ad3749436e52 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/RecordedCallForest.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Queries.Child +import OAI.Combinatorics.TriangleRemoval.Queries.ForkAddressesNotSuffix + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology + +namespace SharpTerminalLeave + +structure RecordedCallForest {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + (H : τ → Finset ι) (c : QueryCall ι τ) where + size : ℕ + call : Fin size → QueryCall ι τ + root : Fin size + root_eq : call root = c + address_injective : Function.Injective (fun i => (call i).address) + parent : (i : Fin size) → i ≠ root → Fin size + is_child : ∀ i h, (call (parent i h)).Child H (call i) + parent_lt : ∀ i h, parent i h < i + +namespace RecordedCallForest +section General +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] +variable {H : τ → Finset ι} {c : QueryCall ι τ} (F : RecordedCallForest H c) + +theorem parent_depth (i : Fin F.size) (h : i ≠ F.root) : + (F.call (F.parent i h)).address.length < (F.call i).address.length := by + rw [(F.is_child i h).address_length] + omega + +theorem parent_wellFounded : + WellFounded (fun i j => ∃ h : j ≠ F.root, i = F.parent j h) := by + apply (measure (fun i : Fin F.size => (F.call i).address.length)).wf.mono + intro i j hij + obtain ⟨h,rfl⟩ := hij + exact F.parent_depth j h + +theorem root_le (i : Fin F.size) : F.root ≤ i := by + induction i using (measure (fun i : Fin F.size => i.val)).wf.induction with + | h i ih => + by_cases hi : i = F.root + · exact le_of_eq hi.symm + · exact (ih (F.parent i hi) (F.parent_lt i hi)).trans (le_of_lt (F.parent_lt i hi)) + +theorem root_val : F.root.val = 0 := by + by_contra hn + have hs : 0 < F.size := lt_of_le_of_lt (Nat.zero_le _) F.root.isLt + have hl := F.root_le ⟨0,hs⟩ + exact hn (Nat.eq_zero_of_le_zero hl) + +theorem reachable_root (i : Fin F.size) : + Relation.ReflTransGen (fun i j => ∃ h : j ≠ F.root, i = F.parent j h) F.root i := by + induction i using F.parent_wellFounded.induction with + | h i ih => + by_cases hi : i = F.root + · subst i + exact Relation.ReflTransGen.refl + · exact (ih (F.parent i hi) ⟨hi,rfl⟩).tail ⟨hi,rfl⟩ + +end General +end RecordedCallForest + +section ExtractForest +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +noncomputable def extractCallForest (H : τ → Finset ι) (N d k : ℕ) (c : QueryCall ι τ) + (ν : τ → PMF (Fin N)) + (z : (Bool × List (QueryCall ι τ)) × List τ) + (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) : + RecordedCallForest H c := by + classical + have ht := tracedGridQuery_parents H N d k c ν hz + have hnd := tracedGridQuery_address_nodup H N d k c ν hz + let r := (List.mem_iff_get.mp ht.1).choose + have hr : z.1.2.get r = c := (List.mem_iff_get.mp ht.1).choose_spec + have hinj : Function.Injective (fun i : Fin z.1.2.length => (z.1.2.get i).address) := by + intro i j he + have hp : z.1.2.Pairwise (fun a b => a.address ≠ b.address) := by + simpa only [List.Nodup,List.pairwise_map] using hnd + by_contra hne + rcases lt_or_gt_of_ne hne with hlt | hgt + · exact (List.pairwise_iff_get.mp hp i j hlt) he + · exact (List.pairwise_iff_get.mp hp j i hgt) he.symm + have hp (i : Fin z.1.2.length) (hi : i ≠ r) : + ∃ p : Fin z.1.2.length, (z.1.2.get p).Child H (z.1.2.get i) := by + rcases ht.2 _ (List.get_mem _ _) with he | ⟨p,hp,hpc⟩ + · have hh : i = r := hinj (congrArg QueryCall.address (he.trans hr.symm)) + exact False.elim (hi hh) + · obtain ⟨j,rfl⟩ := List.mem_iff_get.mp hp + exact ⟨j,hpc⟩ + exact ⟨z.1.2.length,z.1.2.get,r,hr,hinj, + fun i hi => (hp i hi).choose, fun i hi => (hp i hi).choose_spec, + fun i hi => tracedGridQuery_parent_before H N d k c ν hz i _ (hp i hi).choose_spec⟩ + +end ExtractForest +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/Separated.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/Separated.lean new file mode 100644 index 0000000000000000000000000000000000000000..4bfab91b77fbae9419076fcb98cd9aed45221d85 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/Separated.lean @@ -0,0 +1,68 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.MapOutput + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter + +namespace SharpTerminalLeave +section CandidateUniqueness +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +def QueryCall.Separated (H : τ → Finset ι) (c : QueryCall ι τ) : Prop := + ∀ T, some T ≠ c.parent → ((H T) ∩ c.focus).card ≤ 1 + +lemma gridCandidates_key_injective (H : τ → Finset ι) (c : QueryCall ι τ) + (hc : c.Separated H) : + Set.InjOn Prod.snd (↑(gridCandidates H c.focus c.parent) : Set (ι × τ)) := by + intro a ha b hb hab + obtain ⟨haF,haT,haP⟩ := Finset.mem_filter.mp ha + obtain ⟨hbF,hbT,_⟩ := Finset.mem_filter.mp hb + have haF := (Finset.mem_product.mp haF).1 + have hbF := (Finset.mem_product.mp hbF).1 + apply Prod.ext _ hab + have haI : a.1 ∈ H a.2 ∩ c.focus := Finset.mem_inter.mpr ⟨haT,haF⟩ + have hbI : b.1 ∈ H a.2 ∩ c.focus := Finset.mem_inter.mpr ⟨hab ▸ hbT,hbF⟩ + exact (Finset.card_le_one.mp (hc a.2 haP)) _ haI _ hbI + +theorem QueryCall.keys_nodup (H : τ → Finset ι) (c : QueryCall ι τ) + (hc : c.Separated H) : (c.keys H).Nodup := by + apply List.Nodup.map_on _ (Finset.nodup_toList _) + intro a ha b hb hab + exact gridCandidates_key_injective H c hc + (Finset.mem_toList.mp ha) (Finset.mem_toList.mp hb) hab + +omit [Fintype τ] [DecidableEq τ] in +lemma separated_singleton (H : τ → Finset ι) (address : List (ι × τ)) + (e : ι) (parent : Option τ) : + (QueryCall.mk address {e} parent).Separated H := by + intro T _ + exact (Finset.card_le_card Finset.inter_subset_right).trans (by simp) + +omit [Fintype τ] [DecidableEq τ] in + +lemma separated_child (H : τ → Finset ι) + (hlin : ∀ T S, T ≠ S → (H T ∩ H S).card ≤ 1) + (address : List (ι × τ)) (e : ι) (T : τ) : + (QueryCall.mk ((e,T)::address) ((H T).erase e) (some T)).Separated H := by + intro S hS + have hne : S ≠ T := by simpa using hS + change (H S ∩ (H T).erase e).card ≤ 1 + apply (Finset.card_le_card (show H S ∩ (H T).erase e ⊆ H S ∩ H T from + fun x hx => Finset.mem_inter.mpr ⟨(Finset.mem_inter.mp hx).1, + Finset.erase_subset _ _ (Finset.mem_inter.mp hx).2⟩)).trans + exact hlin S T hne + +end CandidateUniqueness +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/SplitQueryPaths.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/SplitQueryPaths.lean new file mode 100644 index 0000000000000000000000000000000000000000..58b407e01ce5c5bd3211bea964f6f0298599c778 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/SplitQueryPaths.lean @@ -0,0 +1,109 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.DivergentArms +import OAI.Combinatorics.TriangleRemoval.Queries.CallPath + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave + +lemma pmf_boolean_finite_cover {A J : Type*} (P : PMF A) (s : Finset J) + (f : A → Bool) (g : J → A → Bool) + (hcover : ∀ a ∈ P.support, f a = true → ∃ j ∈ s, g j a = true) : + ((P.map f) true).toReal ≤ ∑ j ∈ s, ((P.map (g j)) true).toReal := by + classical + have hc (q : J → A → ℝ≥0∞) : + (∑' a, ∑ j ∈ s, q j a) = ∑ j ∈ s, ∑' a, q j a := by + clear hcover + induction s using Finset.induction_on with + | empty => simp + | @insert j s hj ih => simp only [Finset.sum_insert hj,ENNReal.tsum_add,ih] + have hp : (P.map f) true ≤ ∑ j ∈ s, (P.map (g j)) true := by + simp only [PMF.map_apply] + rw [← hc] + apply ENNReal.tsum_le_tsum + intro a + by_cases h0 : P a = 0 + · simp only [h0,ite_self,Finset.sum_const_zero,le_refl] + by_cases hf : f a = true + · obtain ⟨j,hj,hg⟩ := hcover a ((PMF.mem_support_iff _ _).mpr h0) hf + simp only [hf,↓reduceIte] + have hterm : (if true = g j a then P a else 0) ≤ + ∑ j ∈ s, if true = g j a then P a else 0 := + Finset.single_le_sum (f := fun j => (if true = g j a then P a else 0)) + (fun _ _ => by positivity) hj + convert hterm using 1 <;> simp [hg] + · simp only [Ne.symm hf,↓reduceIte,zero_le] + have hf : ∀ j ∈ s, (P.map (g j)) true ≠ ⊤ := fun j _ => PMF.apply_ne_top _ _ + have hh := ENNReal.toReal_mono (ENNReal.sum_ne_top.mpr hf) hp + rwa [ENNReal.toReal_sum hf] at hh + +def splitQueryPaths {A : Type*} [DecidableEq A] : List A → List A → List A × List A × List A + | [], q => ([],[],q) + | p, [] => ([],p,[]) + | a :: p, b :: q => if a = b then + let s := splitQueryPaths p q + (a :: s.1,s.2.1,s.2.2) + else ([],a :: p,b :: q) + +theorem splitQueryPaths_spec {A : Type*} [DecidableEq A] (p q : List A) : + p = (splitQueryPaths p q).1 ++ (splitQueryPaths p q).2.1 ∧ + q = (splitQueryPaths p q).1 ++ (splitQueryPaths p q).2.2 ∧ + DivergentArms (splitQueryPaths p q).2.1 (splitQueryPaths p q).2.2 := by + induction p generalizing q with + | nil => simp [splitQueryPaths,DivergentArms] + | cons a p ih => + cases q with + | nil => simp [splitQueryPaths,DivergentArms] + | cons b q => + by_cases hab : a = b + · subst b + obtain ⟨hp,hq,hd⟩ := ih q + simpa only [splitQueryPaths,↓reduceIte,List.cons_append,List.cons.injEq,true_and] using + And.intro hp (And.intro hq hd) + · simp [splitQueryPaths,hab,DivergentArms] + +noncomputable def pairFactorialWeight {A : Type*} [DecidableEq A] (x : ℝ) (p q : List A) : ℝ := + let s := splitQueryPaths p q + x ^ (s.1.length+s.2.1.length+s.2.2.length) / + ((s.1.length.factorial : ℝ)*(s.2.1.length.factorial : ℝ)*(s.2.2.length.factorial : ℝ)) + +lemma pairFactorialWeight_nonneg {A : Type*} [DecidableEq A] {x : ℝ} + (hx : 0 ≤ x) (p q : List A) : 0 ≤ pairFactorialWeight x p q := by + unfold pairFactorialWeight + positivity + +section PairWeight +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +theorem actualPairVisitProbability_weight (H : τ → Finset ι) (N : ℕ) [NeZero N] + (b : ℕ → ℝ) (hb : ∀ t, 0 ≤ b t) (hq : GridRowQuality H N b) + (C : ℝ) (hC : 1 ≤ C) (hlower : ∀ t ≤ N, 1 ≤ C*b t) + (d k : ℕ) (hkd : k ≤ d) (hkN : k ≤ N) (focus : Finset ι) (parent : Option τ) + (p q : List (ι × τ)) + (hp : p ∈ legalPaths H d focus parent) (hqp : q ∈ legalPaths H d focus parent) : + actualPairVisitProbability H N d k focus parent p q ≤ + C^3 * pairFactorialWeight (prefixWeight (fun t => (2/(N : ℝ))*b t) k) p q := by + obtain ⟨hpl,hplen⟩ := (mem_legalPaths H d focus parent p).mp hp + obtain ⟨hql,hqlen⟩ := (mem_legalPaths H d focus parent q).mp hqp + obtain ⟨he₁,he₂,hd⟩ := splitQueryPaths_spec p q + unfold pairFactorialWeight + have ht := actualPairVisitProbability_pattern_factorial H N b hb hq C hC hlower + (splitQueryPaths p q).1 (splitQueryPaths p q).2.1 (splitQueryPaths p q).2.2 hd + d k hkd hkN focus parent (he₁ ▸ hpl) (he₂ ▸ hql) (he₁ ▸ hplen) (he₂ ▸ hqlen) + rwa [← he₁,← he₂] at ht + +end PairWeight +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/TreeBind.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/TreeBind.lean new file mode 100644 index 0000000000000000000000000000000000000000..35a9e333db7d553897721e0277d66b6d2357adce --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/TreeBind.lean @@ -0,0 +1,365 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Coupling.UnitTime +import OAI.Combinatorics.TriangleRemoval.Probability.ProductPMF + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave +namespace ExposureTree +variable {K V O P : Type*} + +def bind : ExposureTree K V O → (O → ExposureTree K V P) → ExposureTree K V P + | .done o, f => f o + | .ask k g, f => .ask k (fun v => bind (g v) f) + +@[simp] theorem evaluate_bind (ω : K → V) (A : ExposureTree K V O) + (f : O → ExposureTree K V P) : evaluate ω (bind A f) = evaluate ω (f (evaluate ω A)) := by + induction A with + | done o => rfl + | ask k g ih => exact ih (ω k) + +@[simp] theorem fresh_bind (ν : K → PMF V) (A : ExposureTree K V O) + (f : O → ExposureTree K V P) : fresh ν (bind A f) = (fresh ν A).bind (fun o => fresh ν (f o)) := by + induction A with + | done o => simp [bind, fresh] + | ask k g ih => simp only [bind, fresh, ih, PMF.bind_bind] + +def exposeValues : List K → ExposureTree K V (List (K × V)) + | [] => .done [] + | k :: ks => .ask k (fun v => bind (exposeValues ks) (fun xs => .done ((k, v) :: xs))) + +def checkNone : List (ExposureTree K V Bool) → ExposureTree K V Bool + | [] => .done true + | A :: As => bind A (fun b => if b then .done false else checkNone As) + +end ExposureTree + +noncomputable def trueProbability (p : PMF Bool) : ℝ := (p true).toReal +noncomputable def falseProbability (p : PMF Bool) : ℝ := (p false).toReal + +theorem bool_probability_sum (p : PMF Bool) : trueProbability p + falseProbability p = 1 := by + have hh := p.tsum_coe + rw [tsum_fintype, Fintype.sum_bool] at hh + have hr := congrArg ENNReal.toReal hh + simpa only [ENNReal.toReal_add (p.apply_ne_top _) (p.apply_ne_top _), + ENNReal.toReal_one, trueProbability, falseProbability] using hr + +theorem trueProbability_nonneg (p : PMF Bool) : 0 ≤ trueProbability p := ENNReal.toReal_nonneg + +theorem falseProbability_nonneg (p : PMF Bool) : 0 ≤ falseProbability p := ENNReal.toReal_nonneg + +theorem trueProbability_le_one (p : PMF Bool) : trueProbability p ≤ 1 := by + have := bool_probability_sum p + have := falseProbability_nonneg p + linarith + +@[simp] theorem trueProbability_pure (b : Bool) : trueProbability (PMF.pure b) = if b then 1 else 0 := by + cases b <;> simp [trueProbability] + +@[simp] theorem falseProbability_pure (b : Bool) : falseProbability (PMF.pure b) = if b then 0 else 1 := by + cases b <;> simp [falseProbability] + +theorem trueProbability_bind {V : Type*} [Fintype V] (p : PMF V) (f : V → PMF Bool) : + trueProbability (p.bind f) = ∑ v, (p v).toReal * trueProbability (f v) := by + unfold trueProbability + rw [PMF.bind_apply, tsum_fintype, ENNReal.toReal_sum] + · simp only [ENNReal.toReal_mul] + · intro v _ + exact ENNReal.mul_ne_top (p.apply_ne_top v) ((f v).apply_ne_top true) + +theorem trueProbability_bool_bind (p : PMF Bool) (f : Bool → PMF Bool) : + trueProbability (p.bind f) = trueProbability p * trueProbability (f true) + + falseProbability p * trueProbability (f false) := by + rw [trueProbability_bind, Fintype.sum_bool] + rfl + +namespace ExposureTree +variable {K V : Type*} + +theorem fresh_checkNone_true (ν : K → PMF V) (As : List (ExposureTree K V Bool)) : + trueProbability (fresh ν (checkNone As)) = (As.map (fun A => falseProbability (fresh ν A))).prod := by + induction As with + | nil => simp [checkNone, fresh] + | cons A As ih => + rw [checkNone, fresh_bind, trueProbability_bool_bind] + simp [fresh, ih] + +theorem exposeValues_product [Fintype V] (ν : K → PMF V) (ks : List K) + (C : List (K × V) → ExposureTree K V Bool) (h : K → V → ℝ) + (hc : ∀ xs, trueProbability (fresh ν (C xs)) = (xs.map (fun p => h p.1 p.2)).prod) : + trueProbability (fresh ν (ExposureTree.bind (exposeValues ks) C)) = + (ks.map (fun k => ∑ v, (ν k v).toReal * h k v)).prod := by + + suffices hh : ∀ (ks : List K) (a : ℝ) (C : List (K × V) → ExposureTree K V Bool), + (∀ xs, trueProbability (fresh ν (C xs)) = a * (xs.map (fun p => h p.1 p.2)).prod) → + trueProbability (fresh ν (ExposureTree.bind (exposeValues ks) C)) = + a * (ks.map (fun k => ∑ v, (ν k v).toReal * h k v)).prod by + simpa only [one_mul] using hh ks 1 C (by simpa only [one_mul] using hc) + intro ks + induction ks with + | nil => + intro a C hh + simpa only [exposeValues, bind, List.map_nil, List.prod_nil] using hh [] + | cons k ks ih => + intro a C hh + simp only [exposeValues, bind, fresh, trueProbability_bind] + have hx : ∀ v, trueProbability (fresh ν + (bind (bind (exposeValues ks) (fun xs => .done ((k, v) :: xs))) C)) = + (a * h k v) * (ks.map (fun k => ∑ v, (ν k v).toReal * h k v)).prod := by + intro v + have hassoc : bind (bind (exposeValues (V := V) ks) (fun xs => .done ((k, v) :: xs))) C = + bind (exposeValues ks) (fun xs => C ((k, v) :: xs)) := by + induction exposeValues (V := V) ks with + | done xs => rfl + | ask k f hi => simp only [bind, hi] + rw [hassoc] + apply ih + intro xs + rw [hh] + simp only [List.map_cons, List.prod_cons] + ring + simp only [hx, List.map_cons, List.prod_cons] + rw [Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro v _ + ring + +def exposeLabeled {A : Type*} (key : A → K) : List A → ExposureTree K V (List (A × V)) + | [] => .done [] + | a :: as => .ask (key a) (fun v => bind (exposeLabeled key as) + (fun xs => .done ((a, v) :: xs))) + +theorem exposeLabeled_product {A : Type*} [Fintype V] (ν : K → PMF V) (key : A → K) (ks : List A) + (C : List (A × V) → ExposureTree K V Bool) (h : A → V → ℝ) + (hc : ∀ xs, trueProbability (fresh ν (C xs)) = (xs.map (fun p => h p.1 p.2)).prod) : + trueProbability (fresh ν (ExposureTree.bind (exposeLabeled key ks) C)) = + (ks.map (fun k => ∑ v, (ν (key k) v).toReal * h k v)).prod := by + + suffices hh : ∀ (ks : List A) (a : ℝ) (C : List (A × V) → ExposureTree K V Bool), + (∀ xs, trueProbability (fresh ν (C xs)) = a * (xs.map (fun p => h p.1 p.2)).prod) → + trueProbability (fresh ν (ExposureTree.bind (exposeLabeled key ks) C)) = + a * (ks.map (fun k => ∑ v, (ν (key k) v).toReal * h k v)).prod by + simpa only [one_mul] using hh ks 1 C (by simpa only [one_mul] using hc) + intro ks + induction ks with + | nil => + intro a C hh + simpa only [exposeLabeled, bind, List.map_nil, List.prod_nil] using hh [] + | cons k ks ih => + intro a C hh + simp only [exposeLabeled, bind, fresh, trueProbability_bind] + have hx : ∀ v, trueProbability (fresh ν + (bind (bind (exposeLabeled key ks) (fun xs => .done ((k, v) :: xs))) C)) = + (a * h k v) * (ks.map (fun k => ∑ v, (ν (key k) v).toReal * h k v)).prod := by + intro v + have hassoc : bind (bind (exposeLabeled (V := V) key ks) (fun xs => .done ((k, v) :: xs))) C = + bind (exposeLabeled key ks) (fun xs => C ((k, v) :: xs)) := by + induction exposeLabeled (V := V) key ks with + | done xs => rfl + | ask k f hi => simp only [bind, hi] + rw [hassoc] + apply ih + intro xs + rw [hh] + simp only [List.map_cons, List.prod_cons] + ring + simp only [hx, List.map_cons, List.prod_cons] + rw [Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro v _ + ring + +end ExposureTree + +section GridQuery +variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ] + +def gridCandidates (H : τ → Finset ι) (focus : Finset ι) (parent : Option τ) : + Finset (ι × τ) := + (focus.product Finset.univ).filter (fun p => p.1 ∈ H p.2 ∧ some p.2 ≠ parent) + +noncomputable def gridQueryDepth (H : τ → Finset ι) (N : ℕ) : + ℕ → ℕ → Finset ι → Option τ → ExposureTree τ (Fin N) Bool + | 0, _, focus, parent => + ExposureTree.bind + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H focus parent).toList) + (fun _ => .done true) + | d + 1, k, focus, parent => + ExposureTree.bind + (ExposureTree.exposeLabeled Prod.snd (gridCandidates H focus parent).toList) + (fun values => ExposureTree.checkNone + (((values.mergeSort (fun a b => a.2.val ≤ b.2.val)).map + (fun p => if p.2.val < k then + gridQueryDepth H N d p.2.val ((H p.1.2).erase p.1.1) (some p.1.2) + else .done false)))) + +noncomputable def gridPriorities (N : ℕ) [NeZero N] : τ → PMF (Fin N) := + fun _ => PMF.uniformOfFintype (Fin N) + +noncomputable def gridAnswerProbability (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) : ℝ := + trueProbability (ExposureTree.fresh (gridPriorities N) (gridQueryDepth H N d k focus parent)) + +theorem gridAnswerProbability_step (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) : + gridAnswerProbability H N (d + 1) k focus parent = + ∏ p ∈ gridCandidates H focus parent, + ∑ u : Fin N, (1 / (N : ℝ)) * + (if u.val < k then 1 - gridAnswerProbability H N d u.val + ((H p.2).erase p.1) (some p.2) else 1) := by + unfold gridAnswerProbability + rw [gridQueryDepth] + have hh := ExposureTree.exposeLabeled_product (gridPriorities (τ := τ) N) Prod.snd + (gridCandidates H focus parent).toList + (fun values => ExposureTree.checkNone + (((values.mergeSort (fun a b => a.2.val ≤ b.2.val)).map + (fun p => if p.2.val < k then + gridQueryDepth H N d p.2.val ((H p.1.2).erase p.1.1) (some p.1.2) + else .done false)))) + (fun p u => if u.val < k then 1 - gridAnswerProbability H N d u.val + ((H p.2).erase p.1) (some p.2) else 1) (by + intro values + rw [ExposureTree.fresh_checkNone_true, List.map_map] + have hp := (List.mergeSort_perm values (fun a b => a.2.val ≤ b.2.val)).map + (fun p => falseProbability (ExposureTree.fresh (gridPriorities N) + (if p.2.val < k then gridQueryDepth H N d p.2.val + ((H p.1.2).erase p.1.1) (some p.1.2) else .done false))) + refine hp.prod_eq.trans ?_ + congr 1 + apply List.map_congr_left + intro p _ + by_cases hpk : p.2.val < k + · simp only [hpk, ite_true] + have hb := bool_probability_sum (ExposureTree.fresh (gridPriorities N) + (gridQueryDepth H N d p.2.val ((H p.1.2).erase p.1.1) (some p.1.2))) + change falseProbability _ = 1 - trueProbability _ + linarith + · simp [hpk, ExposureTree.fresh]) + convert hh using 1 + simp only [gridPriorities, PMF.uniformOfFintype_apply, ENNReal.toReal_inv, + ENNReal.toReal_natCast, Fintype.card_fin, one_div] + exact (Finset.prod_map_toList _ _).symm + +@[simp] theorem gridAnswerProbability_zero (H : τ → Finset ι) (N : ℕ) [NeZero N] + (k : ℕ) (focus : Finset ι) (parent : Option τ) : + gridAnswerProbability H N 0 k focus parent = 1 := by + simp [gridAnswerProbability, gridQueryDepth, ExposureTree.fresh_bind, + ExposureTree.fresh, PMF.bind_const] + +theorem gridAnswerProbability_mem_unit (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) : + gridAnswerProbability H N d k focus parent ∈ Set.Icc (0 : ℝ) 1 := by + exact ⟨trueProbability_nonneg _, trueProbability_le_one _⟩ + +theorem prod_gridCandidates {M : Type*} [CommMonoid M] (H : τ → Finset ι) + (focus : Finset ι) (parent : Option τ) (f : ι × τ → M) : + (∏ p ∈ gridCandidates H focus parent, f p) = + ∏ e ∈ focus, ∏ T ∈ messageCandidates H e parent, f (e, T) := by + simp only [gridCandidates, messageCandidates, Finset.prod_filter] + exact Finset.prod_product _ _ _ + +theorem gridAnswerProbability_factor (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (focus : Finset ι) (parent : Option τ) : + gridAnswerProbability H N d k focus parent = + ∏ e ∈ focus, gridAnswerProbability H N d k {e} parent := by + cases d with + | zero => simp + | succ d => + simp only [gridAnswerProbability_step, prod_gridCandidates, Finset.prod_singleton] + +noncomputable def gridMessage (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (e : ι) (parent : Option τ) : ℝ := + gridAnswerProbability H N d k {e} parent + +theorem uniform_grid_average (N : ℕ) [NeZero N] (k : ℕ) (f : Fin N → ℝ) : + (∑ u : Fin N, (1 / (N : ℝ)) * (if u.val < k then 1 - f u else 1)) = + 1 - (1 / (N : ℝ)) * ∑ u ∈ Finset.univ.filter (fun u : Fin N => u.val < k), f u := by + have hpoint : ∀ u : Fin N, (if u.val < k then 1 - f u else 1) = + 1 - (if u.val < k then f u else 0) := by + intro u; split_ifs <;> ring + simp only [hpoint, mul_sub, mul_one, Finset.sum_sub_distrib, Finset.sum_const, + Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, Finset.mul_sum, + Finset.sum_filter, mul_ite, mul_zero] + have hN : (N : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne N) + rw [mul_one_div_cancel hN] + +theorem gridMessage_step (H : τ → Finset ι) (N : ℕ) [NeZero N] + (d k : ℕ) (e : ι) (parent : Option τ) : + gridMessage H N (d + 1) k e parent = + ∏ T ∈ messageCandidates H e parent, + (1 - (1 / (N : ℝ)) * ∑ u ∈ Finset.univ.filter (fun u : Fin N => u.val < k), + ∏ f ∈ (H T).erase e, gridMessage H N d u.val f (some T)) := by + simp only [gridMessage, gridAnswerProbability_step, prod_gridCandidates, + Finset.prod_singleton, uniform_grid_average] + apply Finset.prod_congr rfl + intro T _ + congr 2 + apply Finset.sum_congr rfl + intro u _ + exact gridAnswerProbability_factor H N d u.val ((H T).erase e) (some T) + +namespace ExposureTree +@[simp] theorem checkNone_done_false {K V A : Type*} (xs : List A) : + checkNone (xs.map (fun _ => (done false : ExposureTree K V Bool))) = done true := by + induction xs with + | nil => rfl + | cons x xs ih => simp only [List.map_cons, checkNone, bind, Bool.false_eq_true, + ↓reduceIte, ih] +end ExposureTree + +theorem gridQueryDepth_threshold_zero (H : τ → Finset ι) (N d : ℕ) + (focus : Finset ι) (parent : Option τ) : + gridQueryDepth H N d 0 focus parent = gridQueryDepth H N 0 0 focus parent := by + cases d with + | zero => rfl + | succ d => simp only [gridQueryDepth, Nat.not_lt_zero, ↓reduceIte, + ExposureTree.checkNone_done_false] + +theorem gridQueryDepth_stable (H : τ → Finset ι) (N k d d' : ℕ) + (hd : k ≤ d) (hd' : k ≤ d') (focus : Finset ι) (parent : Option τ) : + gridQueryDepth H N d k focus parent = gridQueryDepth H N d' k focus parent := by + induction k using Nat.strong_induction_on generalizing d d' focus parent with + | h k ih => + by_cases hk : k = 0 + · subst k + exact (gridQueryDepth_threshold_zero H N d focus parent).trans + (gridQueryDepth_threshold_zero H N d' focus parent).symm + · obtain ⟨d, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d ≠ 0) + obtain ⟨d', rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d' ≠ 0) + simp only [gridQueryDepth] + congr 1 + funext values + congr 1 + apply List.map_congr_left + intro x _ + split_ifs with hx + · exact ih x.2.val hx d d' (by omega) (by omega) _ _ + · rfl + +theorem gridMessage_stable (H : τ → Finset ι) (N : ℕ) [NeZero N] + (k d d' : ℕ) (hd : k ≤ d) (hd' : k ≤ d') (e : ι) (parent : Option τ) : + gridMessage H N d k e parent = gridMessage H N d' k e parent := by + unfold gridMessage gridAnswerProbability + rw [gridQueryDepth_stable H N k d d' hd hd'] + +theorem gridMessage_exact (H : τ → Finset ι) (N : ℕ) [NeZero N] + (k : ℕ) (hk : k ≤ N) (e : ι) (parent : Option τ) : + gridMessage H N N k e parent = + ∏ T ∈ messageCandidates H e parent, + (1 - (1 / (N : ℝ)) * ∑ u ∈ Finset.univ.filter (fun u : Fin N => u.val < k), + ∏ f ∈ (H T).erase e, gridMessage H N N u.val f (some T)) := by + rw [gridMessage_stable H N k N (N + 1) hk (by omega), gridMessage_step] + +end GridQuery +end SharpTerminalLeave + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Queries/VertexCall.lean b/lean/OAI/Combinatorics/TriangleRemoval/Queries/VertexCall.lean new file mode 100644 index 0000000000000000000000000000000000000000..b22ef5e830b5e2b405a4f5665dc02589b1f36b40 --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Queries/VertexCall.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Embeddings.TriangleGrowth2 +import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraph +import OAI.Combinatorics.TriangleRemoval.Process.Parent +import OAI.Combinatorics.TriangleRemoval.Process.PathSuffix +import OAI.Combinatorics.TriangleRemoval.Process.SuffixProjection +import OAI.Combinatorics.TriangleRemoval.Queries.Address + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open Filter MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +namespace SharpTerminalLeave.RecordedCallForest +variable {n : ℕ} {G : Graph n} {c : QueryCall (Finset (Fin n)) (Finset (Fin n))} +variable (F : RecordedCallForest (triangleHypergraph G) c) + +def vertexCall (v : Fin F.vertexCount) : Fin F.size := + if hv : F.rootCount ≤ v.val then F.callIndex v hv else F.root + +lemma vertexCall_nonroot (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + F.vertexCall v = F.callIndex v hv := dite_eq_left hv + +lemma vertexCall_root (v : Fin F.vertexCount) (hv : v.val < F.rootCount) : + F.vertexCall v = F.root := dite_eq_right (Nat.not_le.mpr hv) + +lemma birthParent_vertexCall (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + (F.birthParent v).elim F.root F.vertexCall = + F.parent (F.callIndex v hv) (F.callIndex_nonroot v hv) := by + rw [F.birthParent_nonroot v hv] + split_ifs with hp + · simp only [Option.elim_some,vertexCall,dite_eq_left (F.birthIndex_nonroot _ hp),F.callIndex_birthIndex] + · simpa only [Option.elim_none] using (not_ne_iff.mp hp).symm + +lemma vertexCall_address (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + (F.call (F.vertexCall v)).address = + (F.attachment v,insert (F.vertexLabel v) (F.attachment v)) :: + (F.call ((F.birthParent v).elim F.root F.vertexCall)).address := by + rw [F.vertexCall_nonroot v hv,F.birthParent_vertexCall v hv, + F.newTriangle v hv,F.attachment_nonroot v hv] + exact congrArg QueryCall.address (F.incoming_spec _ _).2 + +lemma vertexCall_address_empty_root (hc : c.address = []) + (v : Fin F.vertexCount) (hv : F.rootCount ≤ v.val) : + (F.call (F.vertexCall v)).address = + (F.attachment v,insert (F.vertexLabel v) (F.attachment v)) :: + (F.birthParent v).elim [] (fun p => (F.call (F.vertexCall p)).address) := by + rw [F.vertexCall_address v hv] + cases F.birthParent v <;> simp only [Option.elim_none,Option.elim_some,F.root_eq,hc] + +lemma decoded_path_address (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) + (hc : c.address = []) (a b : Fin F.vertexCount) + (hR : F.rootCount ≤ F.vertexCount) + (hi : Set.InjOn F.vertexLabel ((F.toTriangleGrowth hM hG).pathUnion a b)) + (i : Fin ((F.toTriangleGrowth hM hG).pathSuffix a b F.rootCount).card) : + let A := F.toTriangleGrowth hM hG + (A.pathForest a b).address + (indexedTriangleKey (A.pathBirthIndex a b hR) (A.pathAttachments a b hR) + (A.pathAssignment a b hi)) i = + (F.call (F.vertexCall ((A.pathSuffix a b F.rootCount).orderEmbOfFin rfl i))).address := by + dsimp only + let A := F.toTriangleGrowth hM hG + apply PathForest.address_unique + intro j + rw [A.indexedTriangleKey_actual a b hR hi j] + have hv : F.rootCount ≤ ((A.pathSuffix a b F.rootCount).orderEmbOfFin rfl j).val := + ((A.mem_pathSuffix a b _ F.rootCount).mp + ((A.pathSuffix a b F.rootCount).orderEmbOfFin_mem rfl j)).2 + rw [F.vertexCall_address_empty_root hc _ hv] + congr 1 + cases hp : (A.pathForest a b).parent j with + | none => + have he := (A.pathForest_parent_none a b j).mp hp + change F.birthParent _ = none at he + rw [he] + rfl + | some k => + have he := (A.pathForest_parent_some a b j k).mp hp + change F.birthParent _ = some _ at he + rw [he] + rfl + +lemma decoded_mark_address (hM : EdgeMatching c.focus) (hG : c.focus ⊆ G) + (hc : c.address = []) (a b : Fin F.vertexCount) + (hR : F.rootCount ≤ F.vertexCount) + (hi : Set.InjOn F.vertexLabel ((F.toTriangleGrowth hM hG).pathUnion a b)) + (x : Fin F.vertexCount) (hx : x ∈ (F.toTriangleGrowth hM hG).pathUnion a b) : + let A := F.toTriangleGrowth hM hG + (suffixProjection (A.path_card_split a b hR) (A.pathIndex a b x hx)).elim [] + ((A.pathForest a b).address + (indexedTriangleKey (A.pathBirthIndex a b hR) (A.pathAttachments a b hR) + (A.pathAssignment a b hi))) = (F.call (F.vertexCall x)).address := by + dsimp only + let A := F.toTriangleGrowth hM hG + rw [A.path_mark_projection a b hR x hx,PathForest.restrictMark] + split_ifs with hn + · simp only [Option.elim_some] + rw [F.decoded_path_address hM hG hc a b hR hi] + rw [PathForest.embed_index] + · have hv : x.val < F.rootCount := by + by_contra h + exact hn ((A.mem_pathSuffix a b x F.rootCount).mpr ⟨hx,by omega⟩) + rw [F.vertexCall_root x hv,F.root_eq,hc] + rfl + +end SharpTerminalLeave.RecordedCallForest + +open scoped BigOperators ENNReal Classical +open Filter +open scoped BigOperators Topology +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTrace.lean b/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..1b4fd50f25a3ba20ff40025dae8e9b7b2208d27f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTrace.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Process.ProgramDemand + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave.ExposureTree +variable {K V R : Type*} + +def checkMarkedTrace : List (Bool × ExposureTree K V (Bool × Bool × List R)) → + ExposureTree K V (Bool × Bool × List R) + | [] => .done (true,true,[]) + | a :: as => bind a.2 (fun z => + if z.1 then .done (false,((!a.1)||z.2.1) && !(as.any Prod.fst),z.2.2) + else mapOutput (fun y => (y.1,((!a.1)||z.2.1) && y.2.1,z.2.2 ++ y.2.2)) + (checkMarkedTrace as)) + +lemma programDemand_marked_trace (as : List (Bool × ExposureTree K V (Bool × Bool × List R))) : + programDemand (as.map (fun a => (a.1,mapOutput (fun z => (z.1,z.2.1)) a.2))) = + as.any Prod.fst := by + induction as with + | nil => rfl + | cons a as ih => simp only [List.map_cons,programDemand,List.any_cons,ih] + +lemma checkMarkedTrace_marked (as : List (Bool × ExposureTree K V (Bool × Bool × List R))) : + mapOutput (fun z => (z.1,z.2.1)) (checkMarkedTrace as) = + checkMarked (as.map (fun a => (a.1,mapOutput (fun z => (z.1,z.2.1)) a.2))) := by + induction as with + | nil => rfl + | cons a as ih => + simp only [checkMarkedTrace,mapOutput_bind,List.map_cons,checkMarked,bind_mapOutput] + congr 1 + funext z + cases z.1 <;> simp only [Bool.false_eq_true,↓reduceIte,mapOutput_done, + mapOutput_comp,programDemand_marked_trace] + rw [← ih] + rw [mapOutput_comp] + rfl + +lemma checkMarkedTrace_trace (as : List (Bool × ExposureTree K V (Bool × Bool × List R))) : + mapOutput (fun z => (z.1,z.2.2)) (checkMarkedTrace as) = + checkNoneTrace (as.map (fun a => mapOutput (fun z => (z.1,z.2.2)) a.2)) := by + induction as with + | nil => rfl + | cons a as ih => + simp only [checkMarkedTrace,mapOutput_bind,List.map_cons,checkNoneTrace,bind_mapOutput] + congr 1 + funext z + cases z.1 <;> simp only [Bool.false_eq_true,↓reduceIte,mapOutput_done,mapOutput_comp] + rw [← ih] + rw [mapOutput_comp] + rfl + +lemma any_fst_false (as : List (Bool × ExposureTree K V (Bool × Bool × List R))) : + as.any Prod.fst = false ↔ ∀ a ∈ as, a.1 = false := by + induction as with + | nil => simp + | cons a as ih => simp only [List.any_cons,Bool.or_eq_false_iff,ih,List.forall_mem_cons] + +theorem checkMarkedTrace_no_demands (ν : K → PMF V) + (as : List (Bool × ExposureTree K V (Bool × Bool × List R))) + (ha : as.any Prod.fst = false) + {z : Bool × Bool × List R} (hz : z ∈ (fresh ν (checkMarkedTrace as)).support) : + z.2.1 = true := by + induction as generalizing z with + | nil => + have he : z = (true,true,[]) := by + simpa only [checkMarkedTrace,fresh,PMF.mem_support_pure_iff] using hz + subst z + rfl + | cons a as ih => + have haa := Bool.or_eq_false_iff.mp ha + rw [checkMarkedTrace,fresh_bind] at hz + obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + by_cases hx : x.1 = true + · simp only [hx,↓reduceIte,fresh,PMF.mem_support_pure_iff] at hz + subst z + simp only [haa.1,haa.2,Bool.not_false,Bool.true_or,Bool.and_self] + · simp only [hx,Bool.false_eq_true,↓reduceIte,fresh_mapOutput] at hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + simp only [haa.1,Bool.not_false,Bool.true_or,Bool.true_and] + exact ih haa.2 hy + +theorem checkMarkedTrace_one_hit (ν : K → PMF V) (P : R → Prop) + (as : List (Bool × ExposureTree K V (Bool × Bool × List R))) + (hunique : as.Pairwise (fun a b => a.1 = true → b.1 = false)) + (hchild : ∀ a ∈ as, ∀ z ∈ (fresh ν a.2).support, + (∃ r ∈ z.2.2, P r) → a.1 = true ∧ z.2.1 = true) + {z : Bool × Bool × List R} (hz : z ∈ (fresh ν (checkMarkedTrace as)).support) + (hhit : ∃ r ∈ z.2.2, P r) : as.any Prod.fst = true ∧ z.2.1 = true := by + induction as generalizing z with + | nil => + have he : z = (true,true,[]) := by simpa only [checkMarkedTrace,fresh, + PMF.mem_support_pure_iff] using hz + subst z + simp only [List.not_mem_nil,false_and,exists_false] at hhit + | cons a as ih => + obtain ⟨hun,hup⟩ := List.pairwise_cons.mp hunique + rw [checkMarkedTrace,fresh_bind] at hz + obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + have haresult := hchild a (List.mem_cons_self) x hx + have htail := fun a ha => hchild a (List.mem_cons_of_mem _ ha) + have hnodemand (ha : a.1 = true) : as.any Prod.fst = false := + (any_fst_false as).mpr (fun b hb => hun b hb ha) + by_cases hxv : x.1 = true + · simp only [hxv,↓reduceIte,fresh,PMF.mem_support_pure_iff] at hz + subst z + obtain ⟨ha,hgood⟩ := haresult hhit + simp only [List.any_cons,ha,hgood,hnodemand ha,Bool.true_or,Bool.not_false, + Bool.or_true,Bool.and_self,and_self] + · simp only [hxv,Bool.false_eq_true,↓reduceIte,fresh_mapOutput] at hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + obtain ⟨r,hr,hPr⟩ := hhit + rcases List.mem_append.mp hr with hr | hr + · obtain ⟨ha,hgood⟩ := haresult ⟨r,hr,hPr⟩ + have hygood := checkMarkedTrace_no_demands ν as (hnodemand ha) hy + simp only [List.any_cons,ha,hgood,hygood,Bool.true_or,Bool.or_true, + Bool.and_self,and_self] + · obtain ⟨hd,hgood⟩ := ih hup htail hy ⟨r,hr,hPr⟩ + have ha : a.1 = false := by + cases hh : a.1 + · rfl + · have hh' := hnodemand hh + rw [hh'] at hd + contradiction + simp only [List.any_cons,ha,hgood,hd,Bool.false_or,Bool.not_false, + Bool.true_or,Bool.and_self,and_self] + +end SharpTerminalLeave.ExposureTree + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTraceCommon.lean b/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTraceCommon.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f1df168f7672221fee2d272c3d4a176bec9fdee --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTraceCommon.lean @@ -0,0 +1,92 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.CheckMarkedTraceHit + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave.ExposureTree +variable {K V R A C : Type*} + +theorem checkMarkedTrace_common_hit [DecidableEq A] (ν : K → PMF V) + (P Q : R → Prop) (key : C → A) (program : C → ExposureTree K V (Bool × Bool × List R)) + (a : A) (cs : List C) (hnd : (cs.map key).Nodup) + (hP : ∀ c ∈ cs, ∀ z ∈ (fresh ν (program c)).support, + (∃ r ∈ z.2.2, P r) → key c = a) + (hQ : ∀ c ∈ cs, ∀ z ∈ (fresh ν (program c)).support, + (∃ r ∈ z.2.2, Q r) → key c = a) + (hG : ∀ c ∈ cs, ∀ z ∈ (fresh ν (program c)).support, + (∃ r ∈ z.2.2, P r) → (∃ r ∈ z.2.2, Q r) → z.2.1 = true) + {z : Bool × Bool × List R} + (hz : z ∈ (fresh ν (checkMarkedTrace + (cs.map (fun c => (decide (key c = a),program c))))).support) + (hp : ∃ r ∈ z.2.2, P r) (hq : ∃ r ∈ z.2.2, Q r) : z.2.1 = true := by + induction cs generalizing z with + | nil => + have he : z = (true,true,[]) := by + simpa only [List.map_nil,checkMarkedTrace,fresh,PMF.mem_support_pure_iff] using hz + rw [he] + | cons c cs ih => + obtain ⟨hc,hnd⟩ := List.nodup_cons.mp hnd + have hcne : ∀ c' ∈ cs, key c ≠ key c' := by + intro c' hc' he + exact hc (List.mem_map.mpr ⟨c',hc',he.symm⟩) + have hPt := fun c' hc' => hP c' (List.mem_cons_of_mem _ hc') + have hQt := fun c' hc' => hQ c' (List.mem_cons_of_mem _ hc') + have hGt := fun c' hc' => hG c' (List.mem_cons_of_mem _ hc') + have hnone (he : key c = a) : + (cs.map (fun c => (decide (key c = a),program c))).any Prod.fst = false := by + apply List.any_eq_false.mpr + intro d hd + obtain ⟨c',hc',rfl⟩ := List.mem_map.mp hd + simp only [decide_eq_true_eq] + exact fun h => hcne c' hc' (he.trans h.symm) + have hsrc (U : R → Prop) + (hu : ∀ c' ∈ cs, ∀ x ∈ (fresh ν (program c')).support, + (∃ r ∈ x.2.2, U r) → key c' = a) + {w : Bool × Bool × List R} + (hw : w ∈ (fresh ν (checkMarkedTrace + (cs.map (fun c => (decide (key c = a),program c))))).support) + (hh : ∃ r ∈ w.2.2, U r) : key c ≠ a := by + obtain ⟨d,hd,x,hx,hh⟩ := checkMarkedTrace_hit_source ν U _ hw hh + obtain ⟨c',hc',rfl⟩ := List.mem_map.mp hd + have he := hu c' hc' x hx hh + intro hv + exact hcne c' hc' (hv.trans he.symm) + rw [List.map_cons,checkMarkedTrace,fresh_bind] at hz + obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + by_cases hv : x.1 = true + · simp only [hv,↓reduceIte,fresh,PMF.mem_support_pure_iff] at hz + subst z + have hgood := hG c List.mem_cons_self x hx hp hq + have he := hP c List.mem_cons_self x hx hp + simp only [hgood,hnone he,Bool.or_true,Bool.not_false,Bool.and_self] + · simp only [hv,Bool.false_eq_true,↓reduceIte,fresh_mapOutput] at hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + have hp' : (∃ r ∈ x.2.2, P r) ∨ (∃ r ∈ y.2.2, P r) := by + simpa only [List.mem_append,or_and_right,exists_or] using hp + have hq' : (∃ r ∈ x.2.2, Q r) ∨ (∃ r ∈ y.2.2, Q r) := by + simpa only [List.mem_append,or_and_right,exists_or] using hq + rcases hp' with hp' | hp' <;> rcases hq' with hq' | hq' + · have hgood := hG c List.mem_cons_self x hx hp' hq' + have he := hP c List.mem_cons_self x hx hp' + have hygood := checkMarkedTrace_no_demands ν _ (hnone he) hy + simp only [hgood,hygood,Bool.or_true,Bool.and_self] + · exact ((hsrc Q hQt hy hq') (hP c List.mem_cons_self x hx hp')).elim + · exact ((hsrc P hPt hy hp') (hQ c List.mem_cons_self x hx hq')).elim + · have hca := hsrc P hPt hy hp' + have hgood := ih hnd hPt hQt hGt hy hp' hq' + simp only [hca,decide_false,Bool.not_false,Bool.true_or,Bool.true_and,hgood] + +end SharpTerminalLeave.ExposureTree + +end + +end OAI diff --git a/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTraceHit.lean b/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTraceHit.lean new file mode 100644 index 0000000000000000000000000000000000000000..fd4f242d5fede23eedb82cb584346e64b83c4e0f --- /dev/null +++ b/lean/OAI/Combinatorics/TriangleRemoval/Spectral/CheckMarkedTraceHit.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Combinatorics.TriangleRemoval.Spectral.CheckMarkedTrace + +namespace OAI + +section +open scoped BigOperators Topology Matrix.Norms.Operator +open MeasureTheory +open scoped BigOperators ENNReal Classical +open Filter MeasureTheory +open scoped BigOperators Topology +open Filter +open scoped BigOperators + +namespace SharpTerminalLeave.ExposureTree +variable {K V R A C : Type*} + +theorem checkMarkedTrace_hit_source (ν : K → PMF V) (P : R → Prop) + (as : List (Bool × ExposureTree K V (Bool × Bool × List R))) + {z : Bool × Bool × List R} (hz : z ∈ (fresh ν (checkMarkedTrace as)).support) + (hh : ∃ r ∈ z.2.2, P r) : + ∃ a ∈ as, ∃ x ∈ (fresh ν a.2).support, ∃ r ∈ x.2.2, P r := by + induction as generalizing z with + | nil => + have he : z = (true,true,[]) := by + simpa only [checkMarkedTrace,fresh,PMF.mem_support_pure_iff] using hz + simp only [he,List.not_mem_nil,false_and,exists_false] at hh + | cons a as ih => + rw [checkMarkedTrace,fresh_bind] at hz + obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + by_cases hv : x.1 = true + · simp only [hv,↓reduceIte,fresh,PMF.mem_support_pure_iff] at hz + subst z + exact ⟨a,List.mem_cons_self,x,hx,hh⟩ + · simp only [hv,Bool.false_eq_true,↓reduceIte,fresh_mapOutput] at hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + obtain ⟨r,hr,hP⟩ := hh + rcases List.mem_append.mp hr with hr | hr + · exact ⟨a,List.mem_cons_self,x,hx,r,hr,hP⟩ + · obtain ⟨b,hb,w,hw,r,hr,hP⟩ := ih hy ⟨r,hr,hP⟩ + exact ⟨b,List.mem_cons_of_mem _ hb,w,hw,r,hr,hP⟩ + +theorem checkMarkedTrace_two_hit [DecidableEq A] (ν : K → PMF V) + (P Q : R → Prop) (key : C → A) (program : C → ExposureTree K V (Bool × Bool × List R)) + (a b : A) (hab : a ≠ b) (cs : List C) (hnd : (cs.map key).Nodup) + (hP : ∀ c ∈ cs, ∀ z ∈ (fresh ν (program c)).support, + (∃ r ∈ z.2.2, P r) → key c = a ∧ z.2.1 = true) + (hQ : ∀ c ∈ cs, ∀ z ∈ (fresh ν (program c)).support, + (∃ r ∈ z.2.2, Q r) → key c = b ∧ z.2.1 = true) + {z : Bool × Bool × List R} + (hz : z ∈ (fresh ν (checkMarkedTrace + (cs.map (fun c => (decide (key c = a ∨ key c = b),program c))))).support) + (hp : ∃ r ∈ z.2.2, P r) (hq : ∃ r ∈ z.2.2, Q r) : z.2.1 = true := by + induction cs generalizing z with + | nil => + have he : z = (true,true,[]) := by + simpa only [List.map_nil,checkMarkedTrace,fresh,PMF.mem_support_pure_iff] using hz + rw [he] + | cons c cs ih => + obtain ⟨hc,hnd⟩ := List.nodup_cons.mp hnd + have hcne : ∀ c' ∈ cs, key c ≠ key c' := by + intro c' hc' he + exact hc (List.mem_map.mpr ⟨c',hc',he.symm⟩) + have hPt := fun c' hc' => hP c' (List.mem_cons_of_mem _ hc') + have hQt := fun c' hc' => hQ c' (List.mem_cons_of_mem _ hc') + have hsrc (U : R → Prop) (v : A) + (hu : ∀ c' ∈ cs, ∀ x ∈ (fresh ν (program c')).support, + (∃ r ∈ x.2.2, U r) → key c' = v ∧ x.2.1 = true) + {w : Bool × Bool × List R} + (hw : w ∈ (fresh ν (checkMarkedTrace + (cs.map (fun c => (decide (key c = a ∨ key c = b),program c))))).support) + (hh : ∃ r ∈ w.2.2, U r) : key c ≠ v := by + obtain ⟨d,hd,x,hx,hh⟩ := checkMarkedTrace_hit_source ν U _ hw hh + obtain ⟨c',hc',rfl⟩ := List.mem_map.mp hd + have he := (hu c' hc' x hx hh).1 + intro hv + exact hcne c' hc' (hv.trans he.symm) + rw [List.map_cons,checkMarkedTrace,fresh_bind] at hz + obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz + have hpx := hP c List.mem_cons_self x hx + have hqx := hQ c List.mem_cons_self x hx + by_cases hv : x.1 = true + · simp only [hv,↓reduceIte,fresh,PMF.mem_support_pure_iff] at hz + subst z + exact (hab ((hpx hp).1.symm.trans (hqx hq).1)).elim + · simp only [hv,Bool.false_eq_true,↓reduceIte,fresh_mapOutput] at hz + obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz + have hp' : (∃ r ∈ x.2.2, P r) ∨ (∃ r ∈ y.2.2, P r) := by + simpa only [List.mem_append,or_and_right,exists_or] using hp + have hq' : (∃ r ∈ x.2.2, Q r) ∨ (∃ r ∈ y.2.2, Q r) := by + simpa only [List.mem_append,or_and_right,exists_or] using hq + have hone (v other : A) (hvother : v ≠ other) (hcv : key c = other) + (heq : ∀ c' ∈ cs, (key c' = a ∨ key c' = b) ↔ key c' = v) + (U : R → Prop) + (hu : ∀ c' ∈ cs, ∀ x ∈ (fresh ν (program c')).support, + (∃ r ∈ x.2.2, U r) → key c' = v ∧ x.2.1 = true) + (hh : ∃ r ∈ y.2.2, U r) : y.2.1 = true := by + apply (checkMarkedTrace_one_hit ν U _ _ _ hy hh).2 + · apply List.pairwise_map.mpr + have hpw : cs.Pairwise (fun x y => key x ≠ key y) := by + simpa only [List.Nodup,List.pairwise_map] using hnd + apply List.pairwise_iff_get.mpr + intro i j hij + have hi := (List.pairwise_iff_get.mp hpw) i j hij + intro hd + simp only [decide_eq_true_eq] at hd + simp only [decide_eq_false_iff_not] + intro he + exact hi (((heq _ (List.get_mem ..)).mp hd).trans + ((heq _ (List.get_mem ..)).mp he).symm) + · intro d hd w hw hh' + obtain ⟨c',hc',rfl⟩ := List.mem_map.mp hd + obtain ⟨he,hg⟩ := hu c' hc' w hw hh' + exact ⟨decide_eq_true ((heq c' hc').mpr he),hg⟩ + rcases hp' with hp' | hp' <;> rcases hq' with hq' | hq' + · exact (hab ((hpx hp').1.symm.trans (hqx hq').1)).elim + · obtain ⟨hca,hgood⟩ := hpx hp' + have heq : ∀ c' ∈ cs, (key c' = a ∨ key c' = b) ↔ key c' = b := by + intro c' hc' + have hh : key c' ≠ a := fun he => hcne c' hc' (hca.trans he.symm) + simp only [hh,false_or] + have hygood := hone b a (Ne.symm hab) hca heq Q hQt hq' + simp only [hgood,hygood,Bool.or_true,Bool.and_self] + · obtain ⟨hcb,hgood⟩ := hqx hq' + have heq : ∀ c' ∈ cs, (key c' = a ∨ key c' = b) ↔ key c' = a := by + intro c' hc' + have hh : key c' ≠ b := fun he => hcne c' hc' (hcb.trans he.symm) + simp only [hh,or_false] + have hygood := hone a b hab hcb heq P hPt hp' + simp only [hgood,hygood,Bool.or_true,Bool.and_self] + · have hca := hsrc P a hPt hy hp' + have hcb := hsrc Q b hQt hy hq' + have hgood := ih hnd hPt hQt hy hp' hq' + simp only [hca,hcb,false_or,decide_false,Bool.not_false, + Bool.true_or,Bool.true_and,hgood] + +end SharpTerminalLeave.ExposureTree + +end + +end OAI