roseking commited on
Commit
8df23f4
·
verified ·
1 Parent(s): b0ad150

Add lean source and binary files (part 59)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. lean/OAI/Combinatorics/TriangleRemoval/Spectral/ClosedWalkFamily.lean +145 -0
  2. lean/OAI/Combinatorics/TriangleRemoval/Spectral/ClosedWalkPattern.lean +120 -0
  3. lean/OAI/Combinatorics/TriangleRemoval/Spectral/ClosedWords.lean +123 -0
  4. lean/OAI/Combinatorics/TriangleRemoval/Spectral/CountClosedWalk.lean +99 -0
  5. lean/OAI/Combinatorics/TriangleRemoval/Spectral/DensityGlobalSpectral.lean +111 -0
  6. lean/OAI/Combinatorics/TriangleRemoval/Spectral/EdgeStar.lean +96 -0
  7. lean/OAI/Combinatorics/TriangleRemoval/Spectral/ExtendStarApply.lean +51 -0
  8. lean/OAI/Combinatorics/TriangleRemoval/Spectral/ExtendStarMulVec.lean +86 -0
  9. lean/OAI/Combinatorics/TriangleRemoval/Spectral/FallingFactorialNormalizedProduct.lean +130 -0
  10. lean/OAI/Combinatorics/TriangleRemoval/Spectral/FreshLogCheckNone.lean +49 -0
  11. lean/OAI/Combinatorics/TriangleRemoval/Spectral/FreshLogCheckNone2.lean +54 -0
  12. lean/OAI/Combinatorics/TriangleRemoval/Spectral/FreshLogCheckNone3.lean +47 -0
  13. lean/OAI/Combinatorics/TriangleRemoval/Spectral/GlobalLinkAdjacencyHermitian.lean +85 -0
  14. lean/OAI/Combinatorics/TriangleRemoval/Spectral/GraphStarApproximation.lean +92 -0
  15. lean/OAI/Combinatorics/TriangleRemoval/Spectral/LinkStarMatrix.lean +116 -0
  16. lean/OAI/Combinatorics/TriangleRemoval/Spectral/MatrixEuclideanAlgHom.lean +74 -0
  17. lean/OAI/Combinatorics/TriangleRemoval/Spectral/MatrixExpL2Bound.lean +60 -0
  18. lean/OAI/Combinatorics/TriangleRemoval/Spectral/MatrixInfinityAlgHom.lean +42 -0
  19. lean/OAI/Combinatorics/TriangleRemoval/Spectral/MatrixRowAbsSum.lean +89 -0
  20. lean/OAI/Combinatorics/TriangleRemoval/Spectral/MovingStarDegree.lean +327 -0
  21. lean/OAI/Combinatorics/TriangleRemoval/Spectral/NormalizedOnes.lean +143 -0
  22. lean/OAI/Combinatorics/TriangleRemoval/Spectral/RealTraceAdjMatrix.lean +132 -0
  23. lean/OAI/Combinatorics/TriangleRemoval/Spectral/StarInclusion.lean +127 -0
  24. lean/OAI/Combinatorics/TriangleRemoval/Spectral/TracedGridQueryAddress.lean +133 -0
  25. lean/OAI/Combinatorics/TriangleRemoval/Spectral/TracedGridQueryLog.lean +55 -0
  26. lean/OAI/Combinatorics/TriangleRemoval/Spectral/TracedGridQuerySeparated.lean +88 -0
  27. lean/OAI/Combinatorics/TriangleRemoval/Spectral/WheelSpoke.lean +246 -0
  28. lean/OAI/Combinatorics/TriangleRemoval/Stability/ActiveCavityFactorProduct.lean +129 -0
  29. lean/OAI/Combinatorics/TriangleRemoval/Stability/CavityGenerator.lean +361 -0
  30. lean/OAI/Combinatorics/TriangleRemoval/Stability/CavityReference.lean +183 -0
  31. lean/OAI/Combinatorics/TriangleRemoval/Stability/CavityWeight.lean +138 -0
  32. lean/OAI/Combinatorics/TriangleRemoval/Stability/CavityWeightLipschitz.lean +119 -0
  33. lean/OAI/Combinatorics/TriangleRemoval/Stability/ContinuousCavityWeightClip.lean +111 -0
  34. lean/OAI/Combinatorics/TriangleRemoval/Stability/EdgeStabilityRate.lean +117 -0
  35. lean/OAI/Combinatorics/TriangleRemoval/Stability/GeometricVolterraIdentity.lean +123 -0
  36. lean/OAI/Combinatorics/TriangleRemoval/Stability/GridCavityError.lean +304 -0
  37. lean/OAI/Combinatorics/TriangleRemoval/Stability/GridCavityWeightLower.lean +131 -0
  38. lean/OAI/Combinatorics/TriangleRemoval/Stability/MovingPerturbationFiniteExpansion.lean +96 -0
  39. lean/OAI/Combinatorics/TriangleRemoval/Stability/MovingResidualForcing.lean +171 -0
  40. lean/OAI/Combinatorics/TriangleRemoval/Stability/RelativeTemplateResidual.lean +77 -0
  41. lean/OAI/Combinatorics/TriangleRemoval/Stability/Volterra.lean +231 -0
  42. lean/OAI/Combinatorics/TriangleRemoval/Tracking/BalancedJump.lean +205 -0
  43. lean/OAI/Combinatorics/TriangleRemoval/Tracking/CenteredCodegreeNeighborSum.lean +72 -0
  44. lean/OAI/Combinatorics/TriangleRemoval/Tracking/CodegreeNoiseRadius.lean +79 -0
  45. lean/OAI/Combinatorics/TriangleRemoval/Tracking/CodegreeRelativeNoiseTail.lean +52 -0
  46. lean/OAI/Combinatorics/TriangleRemoval/Tracking/CodegreeVarianceRate.lean +89 -0
  47. lean/OAI/Combinatorics/TriangleRemoval/Tracking/CodegreeVertexCount.lean +103 -0
  48. lean/OAI/Combinatorics/TriangleRemoval/Tracking/GoodPrefixStarApproximation.lean +67 -0
  49. lean/OAI/Combinatorics/TriangleRemoval/Tracking/GoodPrefixSurvivalMoments.lean +85 -0
  50. lean/OAI/Combinatorics/TriangleRemoval/Tracking/NormalizedTrackingAbsolute.lean +125 -0
lean/OAI/Combinatorics/TriangleRemoval/Spectral/ClosedWalkFamily.lean ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.ClosedWords
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ section
8
+ open Filter
9
+ open scoped BigOperators Topology
10
+ open InnerProductSpace
11
+ open scoped InnerProductSpace
12
+ open scoped BigOperators NNReal
13
+ open Matrix
14
+ open scoped BigOperators Matrix.Norms.L2Operator
15
+ open Matrix InnerProductSpace
16
+ open scoped BigOperators
17
+
18
+ namespace SharpTerminalLeave
19
+ section TraceBridge
20
+ variable {V : Type*} [Fintype V] [DecidableEq V]
21
+ variable (G : SimpleGraph V) [DecidableRel G.Adj]
22
+
23
+ abbrev closedWalkFamily (r : ℕ) := Σ v : V, {p : G.Walk v v // p.length = r}
24
+
25
+ omit [Fintype V] [DecidableEq V] [DecidableRel G.Adj] in
26
+
27
+ lemma wordOfWalk_adj {r : ℕ} {a : V} (p : G.Walk a a) (hp : p.length = r)
28
+ (i j : Fin r) (hij : (SimpleGraph.cycleGraph r).Adj i j) :
29
+ G.Adj (p.getVert i.val) (p.getVert j.val) := by
30
+ obtain ⟨x,hx⟩ := i
31
+ obtain ⟨y,hy⟩ := j
32
+ have hne : x ≠ y := by
33
+ intro h
34
+ subst y
35
+ exact hij.ne rfl
36
+ wlog hgt : x > y generalizing x y
37
+ · exact (this y hy x hx hij.symm hne.symm (by omega)).symm
38
+ rcases SimpleGraph.cycleGraph_adj'.mp hij with h | h
39
+ · rw [Fin.sub_val_of_le (show (⟨y, hy⟩ : Fin r) ≤ ⟨x, hx⟩ from hgt.le)] at h
40
+ dsimp only at h
41
+ have heq : x = y+1 := by omega
42
+ subst x
43
+ exact (p.adj_getVert_succ (by omega : y < p.length)).symm
44
+ · rw [Fin.coe_sub_iff_lt.mpr hgt] at h
45
+ dsimp only at h
46
+ have hx' : x = r-1 := by omega
47
+ have hy' : y = 0 := by omega
48
+ subst x; subst y
49
+ have hlast := p.adj_getVert_succ (by omega : r-1 < p.length)
50
+ simpa only [show r-1+1 = p.length by omega, SimpleGraph.Walk.getVert_length,
51
+ SimpleGraph.Walk.getVert_zero] using hlast
52
+
53
+ noncomputable def wordOfWalk {r : ℕ} (p : closedWalkFamily G r) : closedWords G r :=
54
+ ⟨fun i => p.2.1.getVert i.val, by
55
+ classical
56
+ simp only [closedWords, Finset.mem_filter, Finset.mem_univ, true_and]
57
+ exact wordOfWalk_adj G p.2.1 p.2.2⟩
58
+
59
+ omit [DecidableEq V] in
60
+ lemma wordOfWalk_injective {r : ℕ} (hr : 0 < r) :
61
+ Function.Injective (wordOfWalk (G := G) (r := r)) := by
62
+ intro p q hpq
63
+ obtain ⟨a,p,hp⟩ := p
64
+ obtain ⟨b,q,hq⟩ := q
65
+ have hword : (fun i : Fin r => p.getVert i.val) = (fun i : Fin r => q.getVert i.val) :=
66
+ Subtype.ext_iff.mp hpq
67
+ have hab : a = b := by simpa using congrFun hword ⟨0,hr⟩
68
+ subst b
69
+ apply congrArg (Sigma.mk a)
70
+ apply Subtype.ext
71
+ apply SimpleGraph.Walk.ext_getVert_le_length (hp.trans hq.symm)
72
+ intro k hk
73
+ by_cases hkr : k < r
74
+ · exact congrFun hword ⟨k,hkr⟩
75
+ · have heq : k = r := by omega
76
+ subst k
77
+ simpa only [hp, hq] using p.getVert_length.trans q.getVert_length.symm
78
+
79
+ noncomputable def walkOfWord (n : ℕ) (f : closedWords G (n+3)) :
80
+ closedWalkFamily G (n+3) := by
81
+ let h : SimpleGraph.cycleGraph (n+3) →g G := ⟨f.val, by
82
+ have hf := f.property
83
+ simpa only [closedWords, Finset.mem_filter, Finset.mem_univ, true_and] using hf⟩
84
+ exact ⟨f.val 0, (SimpleGraph.cycleGraph.cycle n).map h, by
85
+ change ((SimpleGraph.cycleGraph.cycle n).map h).length = n+3
86
+ rw [SimpleGraph.Walk.length_map, SimpleGraph.cycleGraph.length_cycle]⟩
87
+
88
+ omit [DecidableEq V] in
89
+ lemma walkOfWord_injective (n : ℕ) : Function.Injective (walkOfWord G n) := by
90
+ intro f g hfg
91
+ apply Subtype.ext
92
+ funext i
93
+ let k := (SimpleGraph.cycleGraph.cycle n).support.idxOf i
94
+ have hk := (SimpleGraph.cycleGraph.cycle n).getVert_support_idxOf
95
+ (canonical_cycle_spanning n i)
96
+ have hget := congrArg (fun w : closedWalkFamily G (n+3) => w.2.1.getVert k) hfg
97
+ simpa [walkOfWord, SimpleGraph.Walk.getVert_map, k, hk] using hget
98
+
99
+ theorem trace_adjMatrix_eq_closedWords (n : ℕ) :
100
+ Matrix.trace (G.adjMatrix ℕ ^ (n+3)) = (closedWords G (n+3)).card := by
101
+ have hcard : Fintype.card (closedWalkFamily G (n+3)) =
102
+ Fintype.card (closedWords G (n+3)) := le_antisymm
103
+ (Fintype.card_le_of_injective _ (wordOfWalk_injective G (by omega)))
104
+ (Fintype.card_le_of_injective _ (walkOfWord_injective G n))
105
+ rw [Fintype.card_coe] at hcard
106
+ rw [← hcard, Fintype.card_sigma]
107
+ simp only [Matrix.trace, Matrix.diag_apply, SimpleGraph.adjMatrix_pow_apply_eq_card_walk, Nat.cast_id]
108
+ apply Finset.sum_congr rfl
109
+ intro i hi
110
+ exact Fintype.card_congr (Equiv.refl _)
111
+
112
+ lemma closedWords_card_eq (r : ℕ) :
113
+ (closedWords G r).card = (graphEmbeddings (SimpleGraph.cycleGraph r) G).card +
114
+ (nonsimpleWords G r).card := by
115
+ classical
116
+ have hfun : ((closedWords G r).filter Function.Injective) =
117
+ (graphEmbeddings (SimpleGraph.cycleGraph r) G).image (fun (τ : Fin r ↪ V) => (τ : Fin r → V)) := by
118
+ ext f
119
+ simp only [Finset.mem_filter, closedWords, Finset.mem_univ, true_and, Finset.mem_image]
120
+ constructor
121
+ · rintro ⟨hf, hi⟩
122
+ exact ⟨⟨f,hi⟩, (mem_graphEmbeddings _).mpr hf, rfl⟩
123
+ · rintro ⟨τ,hτ,rfl⟩
124
+ exact ⟨(mem_graphEmbeddings τ).mp hτ, τ.injective⟩
125
+ have hc := Finset.card_filter_add_card_filter_not (s := closedWords G r) Function.Injective
126
+ rw [hfun, Finset.card_image_of_injective _ (fun _ _ h => Function.Embedding.ext (congrFun h))] at hc
127
+ exact hc.symm
128
+
129
+ theorem link_trace_count_bound (n : ℕ) (Δ C : ℕ) (hΔ0 : 1 ≤ Δ)
130
+ (hΔ : ∀ x : V, (Finset.univ.filter (G.Adj x)).card ≤ Δ)
131
+ (hcyc : ∀ b, 3 ≤ b → b < n+3 →
132
+ (graphEmbeddings (SimpleGraph.cycleGraph b) G).card ≤ C * Δ ^ b) :
133
+ Matrix.trace (G.adjMatrix ℕ ^ (n+3)) -
134
+ (graphEmbeddings (SimpleGraph.cycleGraph (n+3)) G).card ≤
135
+ (n+3) ^ (n+4) * (Fintype.card V * Δ ^ ((n+3)/2) + C * Δ ^ (n+2)) := by
136
+ rw [trace_adjMatrix_eq_closedWords, closedWords_card_eq, Nat.add_sub_cancel_left]
137
+ exact nonsimpleWords_card_le G n Δ C hΔ0 hΔ hcyc
138
+
139
+ end TraceBridge
140
+ end SharpTerminalLeave
141
+
142
+ end
143
+ end
144
+
145
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/ClosedWalkPattern.lean ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Embeddings.GraphEmbeddingsRestriction
3
+ import OAI.Combinatorics.TriangleRemoval.Spectral.CountClosedWalk
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ section
9
+ open Filter
10
+ open scoped BigOperators Topology
11
+ open InnerProductSpace
12
+ open scoped InnerProductSpace
13
+ open scoped BigOperators NNReal
14
+ open Matrix
15
+ open scoped BigOperators Matrix.Norms.L2Operator
16
+ open Matrix InnerProductSpace
17
+ open scoped BigOperators
18
+
19
+ namespace SharpTerminalLeave
20
+
21
+ theorem canonical_cycle_spanning (n : ℕ) (v : Fin (n+3)) :
22
+ v ∈ (SimpleGraph.cycleGraph.cycle n).support := by
23
+ let f : Fin (n+3) → Fin (n+3) := fun i => (SimpleGraph.cycleGraph.cycle n).getVert i
24
+ have hf : Function.Injective f := by
25
+ intro i j hij
26
+ apply Fin.ext
27
+ exact SimpleGraph.cycleGraph.isCycle_cycle.getVert_injOn'
28
+ (by simp only [Set.mem_ofPred_eq, SimpleGraph.cycleGraph.length_cycle]; omega)
29
+ (by simp only [Set.mem_ofPred_eq, SimpleGraph.cycleGraph.length_cycle]; omega) hij
30
+ obtain ⟨i, hi⟩ := Finite.surjective_of_injective hf v
31
+ exact hi ▸ (SimpleGraph.cycleGraph.cycle n).getVert_mem_support i
32
+
33
+ section WalkPatterns
34
+ variable {r k : ℕ}
35
+
36
+ def closedWalkPattern (σ : Fin r → Fin k) : SimpleGraph (Fin k) :=
37
+ (SimpleGraph.cycleGraph r).map σ
38
+
39
+ def PatternProper (σ : Fin r → Fin k) : Prop :=
40
+ ∀ i j, (SimpleGraph.cycleGraph r).Adj i j → σ i ≠ σ j
41
+
42
+ noncomputable def patternHom (σ : Fin r → Fin k) (hσ : PatternProper σ) :
43
+ SimpleGraph.cycleGraph r →g closedWalkPattern σ :=
44
+ SimpleGraph.Hom.map σ _ (fun hij => hσ _ _ hij)
45
+
46
+ @[simp] lemma patternHom_apply (σ : Fin r → Fin k) (hσ : PatternProper σ) (i : Fin r) :
47
+ patternHom σ hσ i = σ i := rfl
48
+
49
+ lemma pattern_preconnected (σ : Fin r → Fin k) (hσ : PatternProper σ)
50
+ (hs : Function.Surjective σ) : (closedWalkPattern σ).Preconnected :=
51
+ SimpleGraph.Preconnected.map (patternHom σ hσ) hs SimpleGraph.cycleGraph_preconnected
52
+
53
+ theorem pattern_spanning_walk {n k : ℕ} (σ : Fin (n+3) → Fin k)
54
+ (hσ : PatternProper σ) (hs : Function.Surjective σ) :
55
+ ∃ a : Fin k, ∃ p : (closedWalkPattern σ).Walk a a,
56
+ p.length = n+3 ∧ ∀ v, v ∈ p.support := by
57
+ let p := (SimpleGraph.cycleGraph.cycle n).map (patternHom σ hσ)
58
+ refine ⟨σ 0, p, ?_, ?_⟩
59
+ · change ((SimpleGraph.cycleGraph.cycle n).map (patternHom σ hσ)).length = n+3
60
+ rw [SimpleGraph.Walk.length_map, SimpleGraph.cycleGraph.length_cycle]
61
+ · intro v
62
+ obtain ⟨i, rfl⟩ := hs v
63
+ change σ i ∈ ((SimpleGraph.cycleGraph.cycle n).map (patternHom σ hσ)).support
64
+ rw [SimpleGraph.Walk.support_map]
65
+ exact List.mem_map.mpr ⟨i, canonical_cycle_spanning n i, rfl⟩
66
+
67
+ end WalkPatterns
68
+
69
+ section PatternCounting
70
+ variable {A V : Type*} [Fintype A] [DecidableEq A] [Fintype V] [DecidableEq V]
71
+ variable (H : SimpleGraph A) (G : SimpleGraph V) [DecidableRel G.Adj]
72
+
73
+ theorem noninjective_pattern_count (r : ℕ) (hH : H.Preconnected)
74
+ (hsize : Fintype.card A < r) (a : A) (p : H.Walk a a)
75
+ (hlength : p.length = r) (hspan : ∀ v, v ∈ p.support)
76
+ (Δ C : ℕ) (hΔ0 : 1 ≤ Δ)
77
+ (hΔ : ∀ x : V, (Finset.univ.filter (G.Adj x)).card ≤ Δ)
78
+ (hcyc : ∀ b, 3 ≤ b → b < r →
79
+ (graphEmbeddings (SimpleGraph.cycleGraph b) G).card ≤ C * Δ ^ b) :
80
+ (graphEmbeddings H G).card ≤
81
+ Fintype.card V * Δ ^ (r / 2) + C * Δ ^ (r-1) := by
82
+ classical
83
+ by_cases htree : H.IsAcyclic
84
+ · have hv := acyclic_spanning_walk_vertices p htree hspan
85
+ rw [hlength] at hv
86
+ calc
87
+ _ ≤ Fintype.card V * Δ ^ (Fintype.card A - 1) :=
88
+ connected_embedding_count H G hH a Δ hΔ
89
+ _ ≤ Fintype.card V * Δ ^ (r/2) :=
90
+ Nat.mul_le_mul_left _ (Nat.pow_le_pow_right hΔ0 hv)
91
+ _ ≤ _ := Nat.le_add_right _ _
92
+ · obtain ⟨v, c, hc⟩ : ∃ v : A, ∃ c : H.Walk v v, c.IsCycle := by
93
+ simpa only [SimpleGraph.IsAcyclic, not_forall, not_not] using htree
94
+ have hb : 3 ≤ c.length := hc.three_le_length
95
+ obtain ⟨f⟩ := (SimpleGraph.cycleGraph_isContained_iff (by omega : 2 < c.length)).mpr
96
+ ⟨v, c, hc, rfl⟩
97
+ have hcard : c.length ≤ Fintype.card A := by
98
+ simpa using Fintype.card_le_of_injective f.toEmbedding f.injective
99
+ have hh := cyclic_seed_embedding_count H G hH (SimpleGraph.cycleGraph c.length)
100
+ f.toEmbedding (by exact Fin.pos_iff_nonempty.mp (by omega))
101
+ (fun i j hij => f.toHom.map_adj hij) Δ hΔ
102
+ have hp : Δ ^ c.length * Δ ^ (Fintype.card A - c.length) =
103
+ Δ ^ Fintype.card A := by rw [← pow_add, Nat.add_sub_of_le hcard]
104
+ calc
105
+ _ ≤ (graphEmbeddings (SimpleGraph.cycleGraph c.length) G).card *
106
+ Δ ^ (Fintype.card A-c.length) := by simpa using hh
107
+ _ ≤ (C * Δ ^ c.length) * Δ ^ (Fintype.card A-c.length) :=
108
+ Nat.mul_le_mul_right _ (hcyc _ hb (hcard.trans_lt hsize))
109
+ _ = C * Δ ^ Fintype.card A := by rw [mul_assoc, hp]
110
+ _ ≤ C * Δ ^ (r-1) := Nat.mul_le_mul_left _
111
+ (Nat.pow_le_pow_right hΔ0 (by omega))
112
+ _ ≤ _ := Nat.le_add_left _ _
113
+
114
+ end PatternCounting
115
+ end SharpTerminalLeave
116
+
117
+ end
118
+ end
119
+
120
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/ClosedWords.lean ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.ClosedWalkPattern
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ section
8
+ open Filter
9
+ open scoped BigOperators Topology
10
+ open InnerProductSpace
11
+ open scoped InnerProductSpace
12
+ open scoped BigOperators NNReal
13
+ open Matrix
14
+ open scoped BigOperators Matrix.Norms.L2Operator
15
+ open Matrix InnerProductSpace
16
+ open scoped BigOperators
17
+
18
+ namespace SharpTerminalLeave
19
+ section ClosedWords
20
+ variable {V : Type*} [Fintype V] [DecidableEq V]
21
+ variable (G : SimpleGraph V) [DecidableRel G.Adj]
22
+
23
+ noncomputable def closedWords (r : ℕ) : Finset (Fin r → V) := by
24
+ classical
25
+ exact Finset.univ.filter (fun f => ∀ i j, (SimpleGraph.cycleGraph r).Adj i j →
26
+ G.Adj (f i) (f j))
27
+
28
+ noncomputable def nonsimpleWords (r : ℕ) : Finset (Fin r → V) := by
29
+ classical
30
+ exact (closedWords G r).filter (fun f => ¬Function.Injective f)
31
+
32
+ theorem nonsimple_word_factor {r : ℕ} {f : Fin r → V}
33
+ (hf : f ∈ nonsimpleWords G r) :
34
+ ∃ k : Fin r, ∃ σ : Fin r → Fin k.val,
35
+ PatternProper σ ∧ Function.Surjective σ ∧
36
+ ∃ τ ∈ graphEmbeddings (closedWalkPattern σ) G, (fun i => τ (σ i)) = f := by
37
+ classical
38
+ have hfadj : ∀ i j, (SimpleGraph.cycleGraph r).Adj i j → G.Adj (f i) (f j) := by
39
+ simpa only [nonsimpleWords, closedWords, Finset.mem_filter, Finset.mem_univ,
40
+ true_and] using (Finset.mem_filter.mp hf).1
41
+ have hnot := (Finset.mem_filter.mp hf).2
42
+ let S := Finset.univ.image f
43
+ have hcard : S.card < r := by
44
+ have hle : S.card ≤ r := by simpa [S] using (Finset.card_image_le (s := Finset.univ) (f := f))
45
+ refine lt_of_le_of_ne hle ?_
46
+ intro heq
47
+ apply hnot
48
+ have hi : Set.InjOn f (↑(Finset.univ : Finset (Fin r))) :=
49
+ Finset.card_image_iff.mp (by simpa [S] using heq)
50
+ exact fun i j hij => hi (by simp) (by simp) hij
51
+ let e : S ≃ Fin S.card := (Fintype.equivFin S).trans (finCongr (Fintype.card_coe S))
52
+ let σ : Fin r → Fin S.card := fun i => e ⟨f i, Finset.mem_image.mpr ⟨i, by simp, rfl⟩⟩
53
+ let τ : Fin S.card ↪ V := e.symm.toEmbedding.trans (Function.Embedding.subtype _)
54
+ have hτσ : ∀ i, τ (σ i) = f i := by intro i; simp [τ, σ]
55
+ have hs : Function.Surjective σ := by
56
+ intro a
57
+ obtain ⟨i, _, hi⟩ := Finset.mem_image.mp (e.symm a).property
58
+ refine ⟨i, ?_⟩
59
+ apply e.symm.injective
60
+ apply Subtype.ext
61
+ simpa [σ] using hi
62
+ have hp : PatternProper σ := by
63
+ intro i j hij heq
64
+ exact (hfadj i j hij).ne (by rw [← hτσ i, ← hτσ j, heq])
65
+ refine ⟨⟨S.card, hcard⟩, σ, hp, hs, τ, ?_, funext hτσ⟩
66
+ apply (mem_graphEmbeddings τ).mpr
67
+ intro a b hab
68
+ obtain ⟨_, i, j, hij, hi, hj⟩ := hab
69
+ subst a; subst b
70
+ simpa only [hτσ] using hfadj i j hij
71
+
72
+ theorem nonsimpleWords_card_le (n : ℕ) (Δ C : ℕ) (hΔ0 : 1 ≤ Δ)
73
+ (hΔ : ∀ x : V, (Finset.univ.filter (G.Adj x)).card ≤ Δ)
74
+ (hcyc : ∀ b, 3 ≤ b → b < n+3 →
75
+ (graphEmbeddings (SimpleGraph.cycleGraph b) G).card ≤ C * Δ ^ b) :
76
+ (nonsimpleWords G (n+3)).card ≤
77
+ (n+3) ^ (n+4) * (Fintype.card V * Δ ^ ((n+3)/2) + C * Δ ^ (n+2)) := by
78
+ classical
79
+ let t : (k : Fin (n+3)) → Finset (Fin (n+3) → Fin k.val) := fun _ =>
80
+ Finset.univ.filter (fun σ => PatternProper σ ∧ Function.Surjective σ)
81
+ let R := fun (k : Fin (n+3)) (σ : Fin (n+3) → Fin k.val) =>
82
+ (graphEmbeddings (closedWalkPattern σ) G).image (fun τ i => τ (σ i))
83
+ have hsub : nonsimpleWords G (n+3) ⊆ Finset.univ.biUnion (fun k => (t k).biUnion (R k)) := by
84
+ intro f hf
85
+ obtain ⟨k, σ, hp, hs, τ, hτ, rfl⟩ := nonsimple_word_factor G hf
86
+ exact Finset.mem_biUnion.mpr ⟨k, by simp, Finset.mem_biUnion.mpr
87
+ ⟨σ, by simp [t, hp, hs], Finset.mem_image.mpr ⟨τ, hτ, rfl⟩⟩⟩
88
+ let B := Fintype.card V * Δ ^ ((n+3)/2) + C * Δ ^ (n+2)
89
+ have hR : ∀ k, ∀ σ ∈ t k, (R k σ).card ≤ B := by
90
+ intro k σ hσ
91
+ have hh : PatternProper σ ∧ Function.Surjective σ := by simpa only
92
+ [t, Finset.mem_filter, Finset.mem_univ, true_and] using hσ
93
+ obtain ⟨a, p, hp, hs⟩ := pattern_spanning_walk σ hh.1 hh.2
94
+ exact (Finset.card_image_le).trans (by
95
+ simpa [B] using noninjective_pattern_count (closedWalkPattern σ) G (n+3)
96
+ (pattern_preconnected σ hh.1 hh.2) (by simpa only [Fintype.card_fin] using k.isLt)
97
+ a p hp hs Δ C hΔ0 hΔ hcyc)
98
+ calc
99
+ _ ≤ (Finset.univ.biUnion (fun k => (t k).biUnion (R k))).card := Finset.card_le_card hsub
100
+ _ ≤ ∑ k : Fin (n+3), ∑ σ ∈ t k, (R k σ).card := by
101
+ exact (Finset.card_biUnion_le).trans (Finset.sum_le_sum (fun k _ => Finset.card_biUnion_le))
102
+ _ ≤ ∑ k : Fin (n+3), (t k).card * B := by
103
+ apply Finset.sum_le_sum
104
+ intro k hk
105
+ simpa using Finset.sum_le_sum (hR k)
106
+ _ ≤ ∑ _k : Fin (n+3), (n+3)^(n+3) * B := by
107
+ apply Finset.sum_le_sum
108
+ intro k hk
109
+ apply Nat.mul_le_mul_right B
110
+ calc
111
+ (t k).card ≤ Fintype.card (Fin (n+3) → Fin k.val) := Finset.card_le_univ _
112
+ _ = k.val^(n+3) := by simp
113
+ _ ≤ (n+3)^(n+3) := Nat.pow_le_pow_left k.isLt.le _
114
+ _ = (n+3)^(n+4) * B := by simp only [Finset.sum_const, Finset.card_univ,
115
+ Fintype.card_fin, smul_eq_mul]; rw [show n+4 = (n+3)+1 by omega, pow_succ]; ring
116
+
117
+ end ClosedWords
118
+ end SharpTerminalLeave
119
+
120
+ end
121
+ end
122
+
123
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/CountClosedWalk.lean ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ namespace OAI
4
+
5
+ section
6
+ section
7
+ open Filter
8
+ open scoped BigOperators Topology
9
+ open InnerProductSpace
10
+ open scoped InnerProductSpace
11
+ open scoped BigOperators NNReal
12
+ open Matrix
13
+ open scoped BigOperators Matrix.Norms.L2Operator
14
+ open Matrix InnerProductSpace
15
+ open scoped BigOperators
16
+
17
+ namespace SharpTerminalLeave
18
+
19
+ variable {V : Type*} [DecidableEq V] {G : SimpleGraph V}
20
+
21
+ theorem bridge_count_closedWalk {a : V} (p : G.Walk a a) {e : Sym2 V}
22
+ (he : e ∈ p.edges) (hb : G.IsBridge e) : 2 ≤ p.edges.count e := by
23
+ classical
24
+ induction e using Sym2.inductionOn with
25
+ | _ x y =>
26
+ obtain ⟨i, hi, heq⟩ := (p.mk_mem_edges_iff_exists).mp he
27
+ let q := p.drop i
28
+ have hq : ¬ q.Nil := by
29
+ rw [← SimpleGraph.Walk.length_eq_zero_iff]
30
+ dsimp [q]
31
+ rw [SimpleGraph.Walk.drop_length]
32
+ omega
33
+ have he' : s(p.getVert i, q.snd) = s(x,y) := by
34
+ simpa only [q, SimpleGraph.Walk.snd, SimpleGraph.Walk.drop_getVert] using heq
35
+ have hmem : s(p.getVert i, q.snd) ∈ (q.tail.append (p.take i)).edges := by
36
+ have hh : G.IsBridge s(p.getVert i, q.snd) := he'.symm ▸ hb
37
+ have hwalk := (SimpleGraph.isBridge_iff_forall_walk_mem_edges.mp hh)
38
+ (q.tail.append (p.take i)).reverse
39
+ simpa only [SimpleGraph.Walk.edges_reverse, List.mem_reverse] using hwalk
40
+ have hcount : 1 ≤ (q.tail.append (p.take i)).edges.count s(x,y) := by
41
+ exact List.one_le_count_iff.mpr (he' ▸ hmem)
42
+ have hp : p.edges = (p.take i).edges ++ s(x,y) :: q.tail.edges := by
43
+ conv_lhs => rw [← p.append_take_drop_eq i]
44
+ rw [SimpleGraph.Walk.edges_append]
45
+ change (p.take i).edges ++ q.edges = _
46
+ rw [← q.cons_tail_eq hq, SimpleGraph.Walk.edges_cons, he']
47
+ simp
48
+ rw [SimpleGraph.Walk.edges_append, List.count_append] at hcount
49
+ rw [hp, List.count_append, List.count_cons_self]
50
+ omega
51
+
52
+ theorem acyclic_closedWalk_distinct_edges {a : V} (p : G.Walk a a)
53
+ (hG : G.IsAcyclic) : 2 * p.edges.toFinset.card ≤ p.length := by
54
+ classical
55
+ have hh : ∀ e ∈ p.edges.toFinset, 2 ≤ p.edges.count e := by
56
+ intro e he
57
+ have he' := List.mem_toFinset.mp he
58
+ exact bridge_count_closedWalk p he'
59
+ ((SimpleGraph.isAcyclic_iff_forall_isBridge.mp hG) (p.edges_subset_edgeSet he'))
60
+ calc
61
+ _ = ∑ _e ∈ p.edges.toFinset, 2 := by simp [Nat.mul_comm]
62
+ _ ≤ ∑ e ∈ p.edges.toFinset, p.edges.count e := Finset.sum_le_sum hh
63
+ _ = p.edges.length := by exact List.sum_toFinset_count_eq_length _
64
+ _ = p.length := p.length_edges
65
+
66
+ theorem walk_support_card_le_edges {a b : V} (p : G.Walk a b) :
67
+ p.support.toFinset.card ≤ p.edges.toFinset.card + 1 := by
68
+ classical
69
+ induction p with
70
+ | nil => simp
71
+ | @cons a b c hab p ih =>
72
+ simp only [SimpleGraph.Walk.support_cons, SimpleGraph.Walk.edges_cons,
73
+ List.toFinset_cons]
74
+ by_cases ha : a ∈ p.support.toFinset
75
+ · rw [Finset.insert_eq_of_mem ha]
76
+ exact ih.trans (Nat.add_le_add_right (Finset.card_le_card (Finset.subset_insert _ _)) 1)
77
+ · have he : s(a,b) ∉ p.edges.toFinset := by
78
+ intro he
79
+ exact ha (List.mem_toFinset.mpr
80
+ (p.fst_mem_support_of_mem_edges (List.mem_toFinset.mp he)))
81
+ rw [Finset.card_insert_of_notMem ha, Finset.card_insert_of_notMem he]
82
+ omega
83
+
84
+ theorem acyclic_spanning_walk_vertices [Fintype V] {a : V} (p : G.Walk a a)
85
+ (hG : G.IsAcyclic) (hspan : ∀ v, v ∈ p.support) :
86
+ Fintype.card V - 1 ≤ p.length / 2 := by
87
+ have hc := acyclic_closedWalk_distinct_edges p hG
88
+ have hv := walk_support_card_le_edges p
89
+ have hs : p.support.toFinset = Finset.univ := by
90
+ exact Finset.eq_univ_iff_forall.mpr (fun v => List.mem_toFinset.mpr (hspan v))
91
+ rw [hs, Finset.card_univ] at hv
92
+ omega
93
+
94
+ end SharpTerminalLeave
95
+
96
+ end
97
+ end
98
+
99
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/DensityGlobalSpectral.lean ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixCodegreeDriftTerm
3
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixBalancedNoise
4
+ import OAI.Combinatorics.TriangleRemoval.Spectral.WheelSpoke
5
+ import OAI.Combinatorics.TriangleRemoval.Embeddings.DegreeTemplate
6
+
7
+ namespace OAI
8
+
9
+ section
10
+ noncomputable section
11
+ open scoped BigOperators Matrix.Norms.L2Operator
12
+ open Filter Classical
13
+
14
+ namespace SharpTerminalLeave
15
+
16
+ theorem density_global_spectral {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n)
17
+ (D c : ℝ) (hD : prefixD n ≤ D) (hDmin : 1 ≤ prefixD n)
18
+ (hδ : (n : ℝ)^(-c) ≤ 1) (hne : ∀ u, (neighbors G u).Nonempty)
19
+ (hrow : ∀ u v : Fin n, {u,v} ∈ G →
20
+ |(currentCodegree G u v : ℝ)-D| ≤ (n : ℝ)^(-c)*D)
21
+ (hcyc : ∀ j, 3 ≤ j → j ≤ 8000 → ∀ u : Fin n,
22
+ |linkCycleCount j G u-D^j| ≤ (n : ℝ)^(-c)*D^j) :
23
+ ‖D⁻¹ • globalLinkAdjacency G hG-globalStarAverage G‖ ≤ 2*prefixSpectralError n c := by
24
+ have hD1 : 1 ≤ D := hDmin.trans hD
25
+ have hD0 : 0 < D := lt_of_lt_of_le zero_lt_one hD1
26
+ have hd0 : 0 ≤ (n : ℝ)^(-c) := Real.rpow_nonneg (Nat.cast_nonneg _) _
27
+ let M (u : Fin n) : Matrix (neighbors G u) (neighbors G u) ℝ :=
28
+ D⁻¹ • (linkSimpleGraph G hG u).adjMatrix ℝ-averagingProjector
29
+ let N (u : Fin n) : Matrix (edgeStar G u) (edgeStar G u) ℝ :=
30
+ Matrix.reindex (neighborEdgeEquiv G hG u) (neighborEdgeEquiv G hG u) (M u)
31
+ have hM : ∀ u, (M u).IsHermitian := by
32
+ intro u
33
+ exact ((linkSimpleGraph G hG u).isHermitian_adjMatrix ℝ).smul
34
+ (isSelfAdjoint_iff.mpr rfl) |>.sub averagingProjector_hermitian
35
+ have hlocal : ∀ u, ‖N u‖ ≤ prefixSpectralError n c := by
36
+ intro u
37
+ have : Nonempty (neighbors G u) := (hne u).to_subtype
38
+ apply (hermitian_reindex_norm_le _ _ (hM u)).trans
39
+ have hr : ∀ v : neighbors G u,
40
+ |((Finset.univ.filter ((linkSimpleGraph G hG u).Adj v)).card : ℝ)-D| ≤ (n : ℝ)^(-c)*D := by
41
+ intro v
42
+ rw [link_degree_eq G hG u v]
43
+ exact hrow u v.val (Finset.mem_filter.mp v.property).2
44
+ have hm := hcyc 8000 (by decide) le_rfl u
45
+ rw [linkCycleCount_eq_graphEmbeddings (j := 7998) G hG u] at hm
46
+ have hc : ∀ b, 3 ≤ b → b < 8000 →
47
+ ((graphEmbeddings (SimpleGraph.cycleGraph b) (linkSimpleGraph G hG u)).card : ℝ) ≤ 2*D^b := by
48
+ intro b hb hb'
49
+ have hh := (abs_le.mp (hcyc b hb hb'.le u)).2
50
+ have he : b = b-2+2 := by omega
51
+ have hcount : linkCycleCount b G u =
52
+ ((graphEmbeddings (SimpleGraph.cycleGraph b) (linkSimpleGraph G hG u)).card : ℝ) := by
53
+ rw [he]
54
+ exact linkCycleCount_eq_graphEmbeddings G hG u
55
+ rw [hcount] at hh
56
+ have hx := mul_le_mul_of_nonneg_right hδ (pow_nonneg hD0.le b)
57
+ nlinarith
58
+ have hh := graph_star_approximation (linkSimpleGraph G hG u) 7997 (by decide)
59
+ D ((n : ℝ)^(-c)) hD1 hd0 hδ hr hm hc
60
+ apply hh.trans
61
+ have hn : (Fintype.card (neighbors G u) : ℝ) ≤ n := by
62
+ exact_mod_cast (show Fintype.card (neighbors G u) ≤ n by
63
+ simpa using (neighbors G u).card_le_univ)
64
+ change 4*((8001 : ℝ)*(n : ℝ)^(-c)+(8000 : ℝ)^8001*2^8000*
65
+ ((Fintype.card (neighbors G u) : ℝ)/D^4000+1/D))^(1/(8000 : ℝ))+7*(n : ℝ)^(-c) ≤ _
66
+ unfold prefixSpectralError
67
+ gcongr
68
+ have hsplit : D⁻¹ • globalLinkAdjacency G hG-globalStarAverage G =
69
+ ∑ u, extendStar (edgeStar G u) (N u) := by
70
+ simp only [globalLinkAdjacency,globalStarAverage,Finset.smul_sum,← Finset.sum_sub_distrib]
71
+ apply Finset.sum_congr rfl
72
+ intro u _
73
+ have he : N u = D⁻¹ • linkStarMatrix G hG u-averagingProjector := by
74
+ ext i j
75
+ simp only [N,M,linkStarMatrix,Matrix.reindex_apply,Matrix.submatrix_apply,
76
+ Matrix.sub_apply,Matrix.smul_apply,averagingProjector]
77
+ rw [Fintype.card_congr (neighborEdgeEquiv G hG u)]
78
+ rw [he]
79
+ simp [extendStar,Matrix.mul_sub,Matrix.sub_mul,Matrix.smul_mul,Matrix.mul_smul]
80
+ rw [hsplit]
81
+ exact graph_star_error_norm G hG N (fun u => (Matrix.isHermitian_reindex_iff _).mpr (hM u))
82
+ (prefixSpectralError n c) (prefixSpectralError_nonneg n c (zero_le_one.trans hDmin)) hlocal
83
+
84
+ theorem prefix_degree_wheel_tracking : ∀ᶠ n : ℕ in atTop,
85
+ ∀ ω : History (Graph n) (prefixTime n),
86
+ ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support →
87
+ PrefixRootedUpper 8001 n ω → PrefixBalancedNoise 8001 n ω →
88
+ ∀ i ≤ prefixTime n,
89
+ historyAlive (fun j => densityEdgeSafe n (earlyDensity n j) (prefixEdgeRadius n)) (prefixTime n) i ω →
90
+ (∀ u : Fin n, |(currentDegree (ω (historyIndex (prefixTime n) i)) u : ℝ)/
91
+ ((n : ℝ)*earlyDensity n i)-1| ≤ prefixWheelRadius n/2) ∧
92
+ (∀ j, 3 ≤ j → j ≤ 8000 → ∀ u : Fin n,
93
+ |linkCycleCount j (ω (historyIndex (prefixTime n) i)) u/
94
+ ((n : ℝ)*earlyDensity n i^2)^j-1| ≤ prefixWheelRadius n/2) := by
95
+ filter_upwards [prefix_balanced_tracking 8001] with n hn
96
+ intro ω hω hu hnse i hi hs
97
+ have hG : ω (historyIndex (prefixTime n) i) ⊆ completeGraph n := complete_history_valid ω hω i hi
98
+ constructor
99
+ · intro u
100
+ have h := hn ω hω hu hnse i hi hs 2 (by decide) degreeTemplate degreeTemplate_balanced (degreeRoot u)
101
+ rwa [degree_rootedCount _ hG,degree_rootedScaling] at h
102
+ · intro j hj hj' u
103
+ have h := hn ω hω hu hnse i hi hs (j+1) (by omega)
104
+ (wheelTemplate j hj) (wheelTemplate_balanced j hj) (wheelRoot hj u)
105
+ rwa [wheel_rootedCount hj _ hG,wheel_rootedScaling] at h
106
+
107
+ end SharpTerminalLeave
108
+ end
109
+ end
110
+
111
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/EdgeStar.lean ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEpsilon
3
+ import OAI.Combinatorics.TriangleRemoval.Spectral.StarInclusion
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ section
9
+ open Filter
10
+ open scoped BigOperators Topology
11
+ open InnerProductSpace
12
+ open scoped InnerProductSpace
13
+ open scoped BigOperators NNReal
14
+ open Matrix InnerProductSpace
15
+ open scoped BigOperators
16
+ open scoped BigOperators Matrix.Norms.L2Operator
17
+ open Matrix
18
+
19
+ namespace SharpTerminalLeave
20
+
21
+ def edgeStar {n : ℕ} (G : Graph n) (u : Fin n) : Finset G :=
22
+ Finset.univ.filter (fun e => u ∈ e.val)
23
+
24
+ @[simp] theorem mem_edgeStar {n : ℕ} (G : Graph n) (u : Fin n) (e : G) :
25
+ e ∈ edgeStar G u ↔ u ∈ e.val := by simp [edgeStar]
26
+
27
+ def neighborEdge {n : ℕ} (G : Graph n) (u : Fin n) (v : neighbors G u) : edgeStar G u :=
28
+ ⟨⟨{u,v.val},(Finset.mem_filter.mp v.property).2⟩,by simp⟩
29
+
30
+ theorem neighborEdge_injective {n : ℕ} (G : Graph n) (u : Fin n) :
31
+ Function.Injective (neighborEdge G u) := by
32
+ intro v w h
33
+ have he : ({u,v.val} : Finset (Fin n)) = {u,w.val} := congrArg (fun e => e.val.val) h
34
+ have hv : v.val ∈ ({u,w.val} : Finset (Fin n)) := he ▸ (by simp)
35
+ have hw : w.val ∈ ({u,v.val} : Finset (Fin n)) := he.symm ▸ (by simp)
36
+ simp only [Finset.mem_insert,Finset.mem_singleton] at hv hw
37
+ apply Subtype.ext
38
+ rcases hv with hv | hv
39
+ · rcases hw with hw | hw
40
+ · exact hv.trans hw.symm
41
+ · exact hw.symm
42
+ · exact hv
43
+
44
+ theorem neighborEdge_surjective {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) :
45
+ Function.Surjective (neighborEdge G u) := by
46
+ intro e
47
+ obtain ⟨a,b,hab,he⟩ := Finset.card_eq_two.mp (mem_completeGraph.mp (hG e.val.property))
48
+ have hu : u ∈ e.val.val := (mem_edgeStar G u e.val).mp e.property
49
+ rw [he] at hu
50
+ simp only [Finset.mem_insert,Finset.mem_singleton] at hu
51
+ have hm : ({a,b} : Finset (Fin n)) ∈ G := he ▸ e.val.property
52
+ rcases hu with rfl | rfl
53
+ · refine ⟨⟨b,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hm⟩⟩,?_⟩
54
+ apply Subtype.ext
55
+ apply Subtype.ext
56
+ exact he.symm
57
+ · refine ⟨⟨a,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩⟩,?_⟩
58
+ · simpa only [Finset.pair_comm] using hm
59
+ · apply Subtype.ext
60
+ apply Subtype.ext
61
+ exact (Finset.pair_comm _ _).trans he.symm
62
+
63
+ noncomputable def neighborEdgeEquiv {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) :
64
+ neighbors G u ≃ edgeStar G u :=
65
+ Equiv.ofBijective (neighborEdge G u) ⟨neighborEdge_injective G u,neighborEdge_surjective G hG u⟩
66
+
67
+ theorem edgeStar_card {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) :
68
+ (edgeStar G u).card = currentDegree G u := by
69
+ have h := Fintype.card_congr (neighborEdgeEquiv G hG u)
70
+ simpa only [Fintype.card_coe,currentDegree] using h.symm
71
+
72
+ theorem edgeStar_exact_overlap {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (e : G) :
73
+ (Finset.univ.filter fun u => e ∈ edgeStar G u).card = 2 := by
74
+ have he : (Finset.univ.filter fun u => e ∈ edgeStar G u) = e.val := by
75
+ ext u
76
+ simp
77
+ rw [he]
78
+ exact mem_completeGraph.mp (hG e.property)
79
+
80
+ open scoped Matrix.Norms.L2Operator in
81
+
82
+ theorem graph_star_error_norm {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n)
83
+ (M : (u : Fin n) → Matrix (edgeStar G u) (edgeStar G u) ℝ)
84
+ (hM : ∀ u, (M u).IsHermitian) (ε : ℝ) (hε : 0 ≤ ε) (hlocal : ∀ u, ‖M u‖ ≤ ε) :
85
+ ‖∑ u, extendStar (edgeStar G u) (M u)‖ ≤ 2*ε := by
86
+ apply sum_star_norm_bound _ _ hM ε 2 hε (by norm_num) hlocal
87
+ intro e
88
+ rw [edgeStar_exact_overlap G hG e]
89
+ norm_num
90
+
91
+ end SharpTerminalLeave
92
+
93
+ end
94
+ end
95
+
96
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/ExtendStarApply.lean ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.StarInclusion
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ section
8
+ open Filter
9
+ open scoped BigOperators Topology
10
+ open InnerProductSpace
11
+ open scoped InnerProductSpace
12
+ open scoped BigOperators NNReal
13
+ open Matrix InnerProductSpace
14
+ open scoped BigOperators
15
+ open scoped BigOperators Matrix.Norms.L2Operator
16
+ open Matrix
17
+
18
+ namespace SharpTerminalLeave
19
+
20
+ variable {E : Type*} [Fintype E] [DecidableEq E]
21
+
22
+ omit [Fintype E] in
23
+
24
+ theorem extendStar_apply (S : Finset E) (M : Matrix S S ℝ) (i j : E) :
25
+ extendStar S M i j = if hi : i ∈ S then if hj : j ∈ S then
26
+ M ⟨i,hi⟩ ⟨j,hj⟩ else 0 else 0 := by
27
+ simp only [extendStar,Matrix.mul_apply,Matrix.conjTranspose_apply,starInclusion,
28
+ star_trivial]
29
+ by_cases hi : i ∈ S
30
+ · by_cases hj : j ∈ S
31
+ · have hei : ∀ x : S, i = x.val ↔ x = ⟨i,hi⟩ := fun x => by
32
+ rw [Subtype.ext_iff]
33
+ exact eq_comm
34
+ have hej : ∀ x : S, j = x.val ↔ x = ⟨j,hj⟩ := fun x => by
35
+ rw [Subtype.ext_iff]
36
+ exact eq_comm
37
+ simp [hi,hj,hei,hej]
38
+ · have hej : ∀ x : S, j ≠ x.val := fun x hx => hj (hx.symm ▸ x.property)
39
+ simp [hi,hj,hej]
40
+ · have hei : ∀ x : S, i ≠ x.val := fun x hx => hi (hx.symm ▸ x.property)
41
+ simp [hi,hei]
42
+
43
+ end SharpTerminalLeave
44
+
45
+ open scoped BigOperators Topology NNReal Matrix.Norms.Operator
46
+ open MeasureTheory
47
+
48
+ end
49
+ end
50
+
51
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/ExtendStarMulVec.lean ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.LinkStarMatrix
3
+ import OAI.Combinatorics.TriangleRemoval.Process.CompleteEdge
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ noncomputable section
9
+ open scoped BigOperators
10
+ open Classical Matrix
11
+
12
+ namespace SharpTerminalLeave
13
+
14
+ lemma extendStar_mulVec_apply {E : Type*} [Fintype E] [DecidableEq E]
15
+ (S : Finset E) (M : Matrix S S ℝ) (z : E → ℝ) (e : E) :
16
+ (extendStar S M *ᵥ z) e = if he : e ∈ S then
17
+ (M *ᵥ fun f : S => z f.val) ⟨e,he⟩ else 0 := by
18
+ rw [extendStar,← Matrix.mulVec_mulVec,← Matrix.mulVec_mulVec,starInclusion_mulVec]
19
+ simp only [Matrix.mulVec,dotProduct,starInclusion]
20
+ by_cases he : e ∈ S
21
+ · have hh : ∀ f : S, e = f.val ↔ f = ⟨e,he⟩ := fun f => by rw [Subtype.ext_iff]; exact eq_comm
22
+ simp [he,hh]
23
+ · have hh : ∀ f : S, e ≠ f.val := fun f hf => he (hf.symm ▸ f.property)
24
+ simp [he,hh]
25
+
26
+ lemma extendStar_average_apply {E : Type*} [Fintype E] [DecidableEq E]
27
+ (S : Finset E) (z : E → ℝ) (e : E) :
28
+ (extendStar S averagingProjector *ᵥ z) e =
29
+ if e ∈ S then (∑ f ∈ S, z f)/(S.card : ℝ) else 0 := by
30
+ rw [extendStar_mulVec_apply]
31
+ split_ifs with he
32
+ · simp only [Matrix.mulVec,dotProduct,averagingProjector,Fintype.card_coe]
33
+ rw [← Finset.mul_sum,Finset.sum_coe_sort]
34
+ ring
35
+ · rfl
36
+
37
+ lemma graphActive_star_sum {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n)
38
+ (x : CompleteEdge n → ℝ) (u : Fin n) :
39
+ (∑ e ∈ (graphActive G).filter (fun e => u ∈ e.val), x e) =
40
+ ∑ e ∈ edgeStar G u, graphRestrict G hG x e := by
41
+ rw [Finset.sum_filter]
42
+ rw [graphActive_sum G hG]
43
+ simp only [edgeStar,Finset.sum_filter]
44
+ rfl
45
+
46
+ lemma graphActive_star_card {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) :
47
+ ((graphActive G).filter (fun e => u ∈ e.val)).card = (edgeStar G u).card := by
48
+ have hh := graphActive_star_sum G hG (fun _ => 1) u
49
+ simpa only [graphRestrict,LinearMap.coe_mk,AddHom.coe_mk,Finset.sum_const,nsmul_eq_mul,mul_one,
50
+ Nat.cast_inj] using hh
51
+
52
+ lemma graph_movingStarMean {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n)
53
+ (x : CompleteEdge n → ℝ) (u : Fin n) :
54
+ movingStarMean (fun e : CompleteEdge n => e.val) (graphActive G) x u =
55
+ (∑ e ∈ edgeStar G u, graphRestrict G hG x e)/(edgeStar G u).card := by
56
+ unfold movingStarMean movingStarDegree
57
+ congr 1
58
+ · convert graphActive_star_sum G hG x u using 1
59
+ congr 1
60
+ ext e
61
+ simp
62
+ · convert congrArg (Nat.cast : ℕ → ℝ) (graphActive_star_card G hG u) using 1
63
+ congr 2
64
+ ext e
65
+ simp
66
+
67
+ lemma graph_movingStarLift {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n)
68
+ (x : CompleteEdge n → ℝ) (e : CompleteEdge n) (he : e ∈ graphActive G) :
69
+ movingStarLift (fun e : CompleteEdge n => e.val)
70
+ (movingStarMean (fun e : CompleteEdge n => e.val) (graphActive G) x) e =
71
+ graphMatrixLift G hG (globalStarAverage G) x e := by
72
+ have heG : e.val ∈ G := (mem_graphActive G e).mp he
73
+ change (∑ u ∈ e.val, _) = (graphExtend G (globalStarAverage G *ᵥ graphRestrict G hG x)) e
74
+ simp only [graphExtend,LinearMap.coe_mk,AddHom.coe_mk,dite_eq_left heG]
75
+ rw [globalStarAverage,Matrix.sum_mulVec]
76
+ simp only [Finset.sum_apply,extendStar_average_apply,mem_edgeStar]
77
+ rw [← Finset.sum_filter]
78
+ have heq : Finset.univ.filter (fun u => u ∈ e.val) = e.val := by ext; simp
79
+ rw [heq]
80
+ exact Finset.sum_congr rfl (fun u _ => graph_movingStarMean G hG x u)
81
+
82
+ end SharpTerminalLeave
83
+ end
84
+ end
85
+
86
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/FallingFactorialNormalizedProduct.lean ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Coupling.UnitTime
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open scoped BigOperators
10
+ open scoped BigOperators ENNReal Classical
11
+ open Filter MeasureTheory
12
+ open Filter
13
+ open scoped BigOperators Topology
14
+
15
+ namespace SharpTerminalLeave
16
+
17
+ lemma fallingFactorial_normalized_product (r a n : ℕ) (hn : r+a ≤ n) (hn0 : 0 < n) :
18
+ ((n-r).descFactorial a : ℝ)/(n : ℝ)^a =
19
+ ∏ i ∈ Finset.range a, (1-((r+i : ℕ) : ℝ)/(n : ℝ)) := by
20
+ have hnR : (0 : ℝ) < n := by exact_mod_cast hn0
21
+ rw [Nat.descFactorial_eq_prod_range,Nat.cast_prod]
22
+ have hh : (n : ℝ)^a = ∏ _i ∈ Finset.range a, (n : ℝ) := by simp
23
+ rw [hh,← Finset.prod_div_distrib]
24
+ apply Finset.prod_congr rfl
25
+ intro i hi
26
+ have hri : r+i ≤ n := by have := Finset.mem_range.mp hi; omega
27
+ rw [Nat.sub_sub,Nat.cast_sub hri]
28
+ field_simp
29
+
30
+ theorem fallingFactorial_normalized_error (r a n : ℕ) (hn : r+a ≤ n) (hn0 : 0 < n) :
31
+ |((n-r).descFactorial a : ℝ)/(n : ℝ)^a-1| ≤
32
+ (a : ℝ)*(r+a : ℕ)/(n : ℝ) := by
33
+ have hnR : (0 : ℝ) < n := by exact_mod_cast hn0
34
+ rw [fallingFactorial_normalized_product r a n hn hn0]
35
+ let f := fun i : ℕ => 1-((r+i : ℕ) : ℝ)/(n : ℝ)
36
+ have hf : ∀ i ∈ Finset.range a, f i ∈ Set.Icc (0 : ℝ) 1 := by
37
+ intro i hi
38
+ have hri : r+i ≤ n := by have := Finset.mem_range.mp hi; omega
39
+ have h0 : 0 ≤ ((r+i : ℕ) : ℝ)/(n : ℝ) := by positivity
40
+ have h1 : ((r+i : ℕ) : ℝ)/(n : ℝ) ≤ 1 := by
41
+ apply (div_le_one hnR).mpr
42
+ exact_mod_cast hri
43
+ exact ⟨by dsimp [f]; linarith,by dsimp [f]; linarith⟩
44
+ have hh := abs_prod_sub_prod_le_sum (Finset.range a) f (fun _ => 1) hf
45
+ (fun _ _ => ⟨zero_le_one,le_rfl⟩)
46
+ simp only [Finset.prod_const_one] at hh
47
+ apply hh.trans
48
+ calc
49
+ (∑ i ∈ Finset.range a, |f i-1|) =
50
+ ∑ i ∈ Finset.range a, ((r+i : ℕ) : ℝ)/(n : ℝ) := by
51
+ apply Finset.sum_congr rfl
52
+ intro i _
53
+ dsimp [f]
54
+ have h0 : 0 ≤ ((r+i : ℕ) : ℝ)/(n : ℝ) := by positivity
55
+ rw [show 1-((r+i : ℕ) : ℝ)/(n : ℝ)-1 = -(((r+i : ℕ) : ℝ)/(n : ℝ)) by ring,
56
+ abs_neg,abs_of_nonneg h0]
57
+ _ ≤ ∑ _i ∈ Finset.range a, ((r+a : ℕ) : ℝ)/(n : ℝ) := by
58
+ apply Finset.sum_le_sum
59
+ intro i hi
60
+ apply div_le_div_of_nonneg_right _ hnR.le
61
+ exact_mod_cast (by have := Finset.mem_range.mp hi; omega : r+i ≤ r+a)
62
+ _ = _ := by simp; ring
63
+
64
+ theorem initialDensity_power_error (b n : ℕ) (hn : 1 ≤ n) :
65
+ |(1-1/(n : ℝ))^b-1| ≤ (b : ℝ)/(n : ℝ) := by
66
+ have hnR : (1 : ℝ) ≤ n := by exact_mod_cast hn
67
+ have hp0 : 0 ≤ 1-1/(n : ℝ) := by
68
+ have : 1/(n : ℝ) ≤ 1 := by apply (div_le_one (by linarith)).mpr; exact hnR
69
+ linarith
70
+ have hp1 : 1-1/(n : ℝ) ≤ 1 := by
71
+ have : 0 ≤ 1/(n : ℝ) := by positivity
72
+ linarith
73
+ have hh := abs_prod_sub_prod_le_sum (Finset.range b) (fun _ => 1-1/(n : ℝ))
74
+ (fun _ => 1) (fun _ _ => ⟨hp0,hp1⟩) (fun _ _ => ⟨zero_le_one,le_rfl⟩)
75
+ simpa only [Finset.prod_const,Finset.card_range,one_pow,
76
+ show 1-1/(n : ℝ)-1 = -(1/(n : ℝ)) by ring,abs_neg,
77
+ abs_of_nonneg (by positivity : 0 ≤ 1/(n : ℝ)),Finset.sum_const,
78
+ nsmul_eq_mul,mul_one_div] using hh
79
+
80
+ theorem initialRootedScaling_error (r a b n : ℕ) (hn : r+a ≤ n) (hn2 : 2 ≤ n) :
81
+ |((n-r).descFactorial a : ℝ) /
82
+ ((n : ℝ)^a * (1-1/(n : ℝ))^b)-1| ≤
83
+ (2 : ℝ)^b * ((a : ℝ)*(r+a : ℕ)+(b : ℝ))/(n : ℝ) := by
84
+ have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn2
85
+ have hn0 : 0 < n := by omega
86
+ have hnR0 : (0 : ℝ) < n := by linarith
87
+ have hp : (1/2 : ℝ) ≤ 1-1/(n : ℝ) := by
88
+ have hh : 1/(n : ℝ) ≤ 1/2 := (div_le_div_iff₀ hnR0 (by norm_num)).mpr (by linarith)
89
+ linarith
90
+ have hp0 : 0 < (1-1/(n : ℝ))^b := pow_pos (by linarith) _
91
+ have hi : 1/(1-1/(n : ℝ))^b ≤ (2 : ℝ)^b := by
92
+ have hh := pow_le_pow_left₀ (by norm_num : (0 : ℝ) ≤ 1/2) hp b
93
+ have hh2 : (1/2 : ℝ)^b = 1/(2 : ℝ)^b := by rw [div_pow,one_pow]
94
+ rw [hh2] at hh
95
+ exact (div_le_iff₀ hp0).mpr (by
96
+ have ht : (0 : ℝ) < (2 : ℝ)^b := by positivity
97
+ have hmul := (div_le_iff₀ ht).mp hh
98
+ simpa only [mul_comm] using hmul)
99
+ have hf := fallingFactorial_normalized_error r a n hn hn0
100
+ have ht := initialDensity_power_error b n (by omega)
101
+ have he : |((n-r).descFactorial a : ℝ) /
102
+ ((n : ℝ)^a*(1-1/(n : ℝ))^b)-1| =
103
+ |((n-r).descFactorial a : ℝ)/(n : ℝ)^a-(1-1/(n : ℝ))^b| /
104
+ (1-1/(n : ℝ))^b := by
105
+ calc
106
+ _ = |(((n-r).descFactorial a : ℝ)/(n : ℝ)^a-(1-1/(n : ℝ))^b) /
107
+ (1-1/(n : ℝ))^b| := by
108
+ rw [sub_div,div_self (ne_of_gt hp0),div_div]
109
+ _ = _ := by rw [abs_div,abs_of_pos hp0]
110
+ rw [he,div_eq_mul_inv]
111
+ have he2 : |((n-r).descFactorial a : ℝ)/(n : ℝ)^a-(1-1/(n : ℝ))^b| ≤
112
+ ((a : ℝ)*(r+a : ℕ)+(b : ℝ))/(n : ℝ) := by
113
+ calc
114
+ _ ≤ |((n-r).descFactorial a : ℝ)/(n : ℝ)^a-1| +
115
+ |(1-1/(n : ℝ))^b-1| := by
116
+ simpa only [abs_sub_comm (1 : ℝ)] using
117
+ (abs_sub_le (((n-r).descFactorial a : ℝ)/(n : ℝ)^a) 1 ((1-1/(n : ℝ))^b))
118
+ _ ≤ (a : ℝ)*(r+a : ℕ)/(n : ℝ)+(b : ℝ)/(n : ℝ) := add_le_add hf ht
119
+ _ = _ := by ring
120
+ calc
121
+ _ ≤ (((a : ℝ)*(r+a : ℕ)+(b : ℝ))/(n : ℝ)) * (2 : ℝ)^b :=
122
+ mul_le_mul he2 (by simpa only [one_div] using hi) (inv_nonneg.mpr hp0.le)
123
+ (by positivity)
124
+ _ = _ := by ring
125
+
126
+ end SharpTerminalLeave
127
+
128
+ end
129
+
130
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/FreshLogCheckNone.lean ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.MapOutput
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open scoped BigOperators
10
+ open scoped BigOperators ENNReal Classical
11
+ open Filter MeasureTheory
12
+ open scoped BigOperators Topology
13
+ open Filter
14
+
15
+ namespace SharpTerminalLeave.ExposureTree
16
+ variable {K V R : Type*}
17
+
18
+ theorem freshLog_checkNoneTrace_forall (ν : K → PMF V) (P : R → Prop)
19
+ (as : List (ExposureTree K V (Bool × List R)))
20
+ (ha : ∀ A ∈ as, ∀ z ∈ (freshLog ν A).support, ∀ c ∈ z.1.2, P c)
21
+ {z : (Bool × List R) × List K}
22
+ (hz : z ∈ (freshLog ν (checkNoneTrace as)).support) :
23
+ ∀ c ∈ z.1.2, P c := by
24
+ induction as generalizing z with
25
+ | nil =>
26
+ have heq : z = ((true,[]),[]) := by simpa [checkNoneTrace,freshLog] using hz
27
+ simp [heq]
28
+ | cons A as ih =>
29
+ rw [checkNoneTrace, freshLog_bind] at hz
30
+ obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
31
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
32
+ have hxP := ha A (by simp) x hx
33
+ have has (B) (hB : B ∈ as) := ha B (by simp [hB])
34
+ cases hb : x.1.1
35
+ · simp only [hb, Bool.false_eq_true, ↓reduceIte, freshLog_mapOutput] at hy
36
+ obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy
37
+ intro c hc
38
+ rcases List.mem_append.mp hc with hc | hc
39
+ · exact hxP c hc
40
+ · exact ih has hw c hc
41
+ · simp only [hb, ↓reduceIte, freshLog, PMF.mem_support_pure_iff] at hy
42
+ subst y
43
+ exact hxP
44
+
45
+ end SharpTerminalLeave.ExposureTree
46
+
47
+ end
48
+
49
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/FreshLogCheckNone2.lean ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.FreshLogCheckNone
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open scoped BigOperators
10
+ open scoped BigOperators ENNReal Classical
11
+ open Filter MeasureTheory
12
+ open scoped BigOperators Topology
13
+ open Filter
14
+
15
+ namespace SharpTerminalLeave.ExposureTree
16
+ variable {K V R : Type*}
17
+
18
+ theorem freshLog_checkNoneTrace_pairwise (ν : K → PMF V) (rel : R → R → Prop)
19
+ (as : List (ExposureTree K V (Bool × List R)))
20
+ (ha : ∀ A ∈ as, ∀ z ∈ (freshLog ν A).support, z.1.2.Pairwise rel)
21
+ (hab : as.Pairwise (fun A B =>
22
+ ∀ x ∈ (freshLog ν A).support, ∀ y ∈ (freshLog ν B).support,
23
+ ∀ c ∈ x.1.2, ∀ d ∈ y.1.2, rel c d))
24
+ {z : (Bool × List R) × List K}
25
+ (hz : z ∈ (freshLog ν (checkNoneTrace as)).support) :
26
+ z.1.2.Pairwise rel := by
27
+ induction as generalizing z with
28
+ | nil =>
29
+ have heq : z = ((true,[]),[]) := by simpa [checkNoneTrace,freshLog] using hz
30
+ simp [heq]
31
+ | cons A as ih =>
32
+ obtain ⟨hhead,htail⟩ := List.pairwise_cons.mp hab
33
+ rw [checkNoneTrace, freshLog_bind] at hz
34
+ obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
35
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
36
+ have hxR := ha A (by simp) x hx
37
+ have has (B) (hB : B ∈ as) := ha B (by simp [hB])
38
+ cases hb : x.1.1
39
+ · simp only [hb, Bool.false_eq_true, ↓reduceIte, freshLog_mapOutput] at hy
40
+ obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy
41
+ apply List.pairwise_append.mpr
42
+ refine ⟨hxR, ih has htail hw, ?_⟩
43
+ intro c hc
44
+ exact freshLog_checkNoneTrace_forall ν (rel c) as
45
+ (fun B hB y hy' d hd => hhead B hB x hx y hy' c hc d hd) hw
46
+ · simp only [hb, ↓reduceIte, freshLog, PMF.mem_support_pure_iff] at hy
47
+ subst y
48
+ exact hxR
49
+
50
+ end SharpTerminalLeave.ExposureTree
51
+
52
+ end
53
+
54
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/FreshLogCheckNone3.lean ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.MapOutput
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open Filter MeasureTheory
10
+ open scoped BigOperators
11
+ open scoped BigOperators ENNReal Classical
12
+ open Filter
13
+ open scoped BigOperators Topology
14
+
15
+ namespace SharpTerminalLeave.ExposureTree
16
+ variable {K V R : Type*}
17
+
18
+ theorem freshLog_checkNoneTrace_append (ν : K → PMF V)
19
+ (P : List R → Prop) (h0 : P [])
20
+ (happend : ∀ a b, P a → P b → P (a ++ b))
21
+ (as : List (ExposureTree K V (Bool × List R)))
22
+ (ha : ∀ A ∈ as, ∀ z ∈ (freshLog ν A).support, P z.1.2)
23
+ {z : (Bool × List R) × List K}
24
+ (hz : z ∈ (freshLog ν (checkNoneTrace as)).support) : P z.1.2 := by
25
+ induction as generalizing z with
26
+ | nil =>
27
+ have he : z = ((true,[]),[]) := by simpa [checkNoneTrace,freshLog] using hz
28
+ simpa only [he] using h0
29
+ | cons A as ih =>
30
+ rw [checkNoneTrace, freshLog_bind] at hz
31
+ obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
32
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
33
+ have hxa := ha A (by simp) x hx
34
+ have has (B) (hB : B ∈ as) := ha B (by simp [hB])
35
+ cases hb : x.1.1
36
+ · simp only [hb,Bool.false_eq_true,↓reduceIte,freshLog_mapOutput] at hy
37
+ obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy
38
+ exact happend _ _ hxa (ih has hw)
39
+ · simp only [hb,↓reduceIte,freshLog,PMF.mem_support_pure_iff] at hy
40
+ subst y
41
+ exact hxa
42
+
43
+ end SharpTerminalLeave.ExposureTree
44
+
45
+ end
46
+
47
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/GlobalLinkAdjacencyHermitian.lean ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.EdgeIncidence
3
+ import OAI.Combinatorics.TriangleRemoval.Process.AveragingProjectorInftyOne
4
+ import OAI.Combinatorics.TriangleRemoval.Spectral.MatrixEuclideanAlgHom
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ open scoped BigOperators Topology Matrix.Norms.Operator
10
+ open MeasureTheory
11
+
12
+ namespace SharpTerminalLeave
13
+ open scoped Matrix.Norms.Operator
14
+
15
+ theorem globalLinkAdjacency_hermitian {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) :
16
+ (globalLinkAdjacency G hG).IsHermitian := by
17
+ apply Matrix.IsHermitian.ext
18
+ intro i j
19
+ simp only [globalLinkAdjacency,Matrix.sum_apply]
20
+ apply Finset.sum_congr rfl
21
+ intro u _
22
+ exact (Matrix.isHermitian_mul_mul_conjTranspose (starInclusion (edgeStar G u))
23
+ ((Matrix.isHermitian_reindex_iff _).mpr
24
+ ((linkSimpleGraph G hG u).isHermitian_adjMatrix ℝ))).apply i j
25
+
26
+ theorem goodPrefix_semigroup_quantitative {n : ℕ} [NeZero n] {G : Graph n} [Nonempty G]
27
+ {c C : ℝ} (h : GoodPrefixGraph n c C G) (hne : ∀ u, (neighbors G u).Nonempty)
28
+ (hD : 1 ≤ prefixD n) (hδ : (n : ℝ)^(-c) ≤ 1)
29
+ (T : ℝ) (hT : 0 ≤ T) (K : ℕ) (s : ℝ) (hs : s ∈ Set.Icc (0 : ℝ) T) :
30
+ ‖NormedSpace.exp ((-s) • ((prefixD n)⁻¹ • globalLinkAdjacency G h.1))‖ ≤
31
+ (∑ j ∈ Finset.range K, ((1+2*T)*6*T)^j*(1+2*T)) +
32
+ Real.sqrt G.card * ((2*prefixSpectralError n c*T)^K *
33
+ Real.exp (T*(2*prefixSpectralError n c))) := by
34
+ let P := globalStarAverage G
35
+ let R := (prefixD n)⁻¹ • globalLinkAdjacency G h.1 - P
36
+ let ε := 2*prefixSpectralError n c
37
+ have hε : 0 ≤ ε := mul_nonneg (by norm_num)
38
+ (prefixSpectralError_nonneg n c (le_trans zero_le_one hD))
39
+ have hPR : P+R = (prefixD n)⁻¹ • globalLinkAdjacency G h.1 := by dsimp [R]; abel
40
+ have hP : P.PosSemidef := globalStarAverage_posSemidef G
41
+ have hR : IsSelfAdjoint R := by
42
+ exact ((globalLinkAdjacency_hermitian G h.1).smul
43
+ (isSelfAdjoint_iff.mpr rfl) |>.sub hP.isHermitian).isSelfAdjoint
44
+ have hR₂ : ‖matrixEuclideanAlgHom R‖ ≤ ε := goodPrefix_global_spectral h hne hD hδ
45
+ have hRinf : ‖R‖ ≤ 6 := goodPrefix_residual_infty h hD hδ
46
+ have hF : Continuous (matrixEuclideanAlgHom (I := G)) :=
47
+ (matrixEuclideanAlgHom (I := G)).toLinearMap.continuous_of_finiteDimensional
48
+ have hb : ∀ t ∈ Set.Icc (0 : ℝ) T, ‖NormedSpace.exp ((-t) • P)‖ ≤ 1+2*T := by
49
+ intro t ht
50
+ have hdeg : ∀ u, 0 < currentDegree G u := fun u => Finset.card_pos.mpr (hne u)
51
+ exact (graph_star_semigroup_bound G h.1 hdeg t ht.1).trans (by linarith [ht.2])
52
+ have hb₂ : ∀ t ∈ Set.Icc (0 : ℝ) T,
53
+ ‖NormedSpace.exp ((-t) • matrixEuclideanAlgHom P)‖ ≤ 1 :=
54
+ fun t ht => euclidean_posSemidef_exp_bound P hP t ht.1
55
+ have hf₂ : ∀ t ∈ Set.Icc (0 : ℝ) T,
56
+ ‖NormedSpace.exp ((-t) • (matrixEuclideanAlgHom P + matrixEuclideanAlgHom R))‖ ≤
57
+ Real.exp (T*ε) := by
58
+ intro t ht
59
+ apply (euclidean_perturbed_exp_bound P R hP hR t ht.1).trans
60
+ apply Real.exp_le_exp.mpr
61
+ exact (mul_le_mul_of_nonneg_left hR₂ ht.1).trans
62
+ (mul_le_mul_of_nonneg_right ht.2 hε)
63
+ let : CompleteSpace (EuclideanSpace ℝ G) := PiLp.completeSpace 2 (fun _ : G => ℝ)
64
+ let : CompleteSpace (EuclideanSpace ℝ G →L[ℝ] EuclideanSpace ℝ G) :=
65
+ ContinuousLinearMap.instCompleteSpace
66
+ have hh := perturbation_mixed_norm_bound (matrixEuclideanAlgHom (I := G)) hF P R
67
+ T (1+2*T) (Real.exp (T*ε)) (Real.sqrt G.card) hT (by positivity) (by positivity)
68
+ (by positivity) (by simpa only [Fintype.card_coe] using
69
+ (matrix_infty_le_sqrt_card_euclidean (I := G))) hb hb₂ hf₂ K s hs
70
+ rw [hPR] at hh
71
+ apply hh.trans
72
+ apply add_le_add
73
+ · apply Finset.sum_le_sum
74
+ intro j _
75
+ gcongr
76
+ · gcongr
77
+
78
+ end SharpTerminalLeave
79
+
80
+ open Filter
81
+ open scoped BigOperators Topology
82
+
83
+ end
84
+
85
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/GraphStarApproximation.lean ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.NormalizedOnes
3
+ import OAI.Combinatorics.TriangleRemoval.Spectral.RealTraceAdjMatrix
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ section
9
+ open Filter
10
+ open scoped BigOperators Topology
11
+ open InnerProductSpace
12
+ open scoped InnerProductSpace
13
+ open scoped BigOperators NNReal
14
+ open Matrix
15
+ open scoped BigOperators Matrix.Norms.L2Operator
16
+ open Matrix InnerProductSpace
17
+ open scoped BigOperators
18
+
19
+ namespace SharpTerminalLeave
20
+ open scoped BigOperators Matrix.Norms.L2Operator
21
+
22
+ section GraphStar
23
+ variable {V : Type*} [Fintype V] [DecidableEq V] [Nonempty V]
24
+ variable (G : SimpleGraph V) [DecidableRel G.Adj]
25
+
26
+ theorem graph_star_approximation (n : ℕ) (hr : Even (n+3)) (D δ : ℝ)
27
+ (hD : 1 ≤ D) (hδ0 : 0 ≤ δ) (hδ1 : δ ≤ 1)
28
+ (hrow : ∀ x : V, |((Finset.univ.filter (G.Adj x)).card : ℝ) - D| ≤ δ*D)
29
+ (hmain : |((graphEmbeddings (SimpleGraph.cycleGraph (n+3)) G).card : ℝ) - D^(n+3)| ≤
30
+ δ * D^(n+3))
31
+ (hcyc : ∀ b, 3 ≤ b → b < n+3 →
32
+ ((graphEmbeddings (SimpleGraph.cycleGraph b) G).card : ℝ) ≤ 2 * D^b) :
33
+ ‖D⁻¹ • G.adjMatrix ℝ - averagingProjector‖ ≤
34
+ 4 * (((n+4 : ℕ) : ℝ) * δ + ((n+3 : ℕ) : ℝ)^(n+4) * 2^(n+3) *
35
+ ((Fintype.card V : ℝ) / D^((n+3)/2) + 1/D)) ^ (1 / ((n+3 : ℕ) : ℝ)) + 7*δ := by
36
+ have hD0 : 0 < D := lt_of_lt_of_le zero_lt_one hD
37
+ have hDne : D ≠ 0 := ne_of_gt hD0
38
+ let W : ℝ := ((n+3 : ℕ) : ℝ)^(n+4) * 2^(n+3) *
39
+ ((Fintype.card V : ℝ) / D^((n+3)/2) + 1/D)
40
+ let E : ℝ := ((n+4 : ℕ) : ℝ)*δ + W
41
+ let θ : ℝ := E ^ (1 / ((n+3 : ℕ) : ℝ))
42
+ have hW : 0 ≤ W := by dsimp [W]; positivity
43
+ have hE : 0 ≤ E := by dsimp [E]; positivity
44
+ have hθ : 0 ≤ θ := Real.rpow_nonneg hE _
45
+ have hθpow : θ ^ (n+3) = E := by
46
+ dsimp [θ]
47
+ rw [← Real.rpow_mul_natCast hE]
48
+ have hn : ((n+3 : ℕ) : ℝ) ≠ 0 := by positivity
49
+ rw [div_mul_cancel₀ _ hn,Real.rpow_one]
50
+ have hdeg : ∀ x : V, ((Finset.univ.filter (G.Adj x)).card : ℝ) ≤ 2*D := by
51
+ intro x
52
+ have hh := (abs_le.mp (hrow x)).2
53
+ nlinarith
54
+ have htrace := normalized_link_trace_bound G n hr D δ hD hdeg hmain hcyc
55
+ have hber : 1 - ((n+3 : ℕ) : ℝ)*δ ≤ (1-δ)^(n+3) := by
56
+ simpa only [sub_eq_add_neg, mul_neg] using
57
+ (one_add_mul_le_pow (a := -δ) (by linarith) (n+3))
58
+ have htrace' : Matrix.trace ((D⁻¹ • G.adjMatrix ℝ)^(n+3)) ≤ (1-δ)^(n+3) + θ^(n+3) := by
59
+ rw [hθpow]
60
+ have hh := (abs_le.mp htrace).2
61
+ dsimp [E]
62
+ change Matrix.trace ((D⁻¹ • G.adjMatrix ℝ)^(n+3)) - 1 ≤ δ + W at hh
63
+ push_cast at hber ⊢
64
+ nlinarith
65
+ have hrows : ∀ x : V, |(∑ y, (D⁻¹ • G.adjMatrix ℝ) x y) - 1| ≤ δ := by
66
+ intro x
67
+ have hsum : (∑ y, G.adjMatrix ℝ x y) =
68
+ ((Finset.univ.filter (G.Adj x)).card : ℝ) := by
69
+ simp only [SimpleGraph.adjMatrix_apply]
70
+ exact Finset.sum_boole _ _
71
+ simp only [Matrix.smul_apply,smul_eq_mul,← Finset.mul_sum,hsum]
72
+ have heq : D⁻¹ * ((Finset.univ.filter (G.Adj x)).card : ℝ) - 1 =
73
+ D⁻¹ * (((Finset.univ.filter (G.Adj x)).card : ℝ) - D) := by
74
+ field_simp
75
+ rw [heq,abs_mul,abs_of_pos (inv_pos.mpr hD0)]
76
+ calc
77
+ _ ≤ D⁻¹ * (δ*D) := mul_le_mul_of_nonneg_left (hrow x) (inv_nonneg.mpr hD0.le)
78
+ _ = δ := by field_simp
79
+ have hpos : ∀ x y, 0 ≤ (D⁻¹ • G.adjMatrix ℝ) x y := by
80
+ intro x y
81
+ change 0 ≤ D⁻¹ * G.adjMatrix ℝ x y
82
+ exact mul_nonneg (inv_nonneg.mpr hD0.le) (by simp [SimpleGraph.adjMatrix_apply]; split_ifs <;> norm_num)
83
+ exact star_approximation_from_trace _ ((G.isHermitian_adjMatrix ℝ).smul (isSelfAdjoint_iff.mpr rfl))
84
+ δ θ hδ0 hδ1 hθ hpos hrows (n+3) hr (by omega) htrace'
85
+
86
+ end GraphStar
87
+ end SharpTerminalLeave
88
+
89
+ end
90
+ end
91
+
92
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/LinkStarMatrix.lean ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Tracking.GoodPrefixStarApproximation
3
+ import OAI.Combinatorics.TriangleRemoval.Process.ReindexQuadratic
4
+ import OAI.Combinatorics.TriangleRemoval.Spectral.EdgeStar
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ section
10
+ open Filter
11
+ open scoped BigOperators Topology
12
+ open InnerProductSpace
13
+ open scoped InnerProductSpace
14
+ open scoped BigOperators NNReal
15
+ open Matrix InnerProductSpace
16
+ open scoped BigOperators
17
+ open scoped BigOperators Matrix.Norms.L2Operator
18
+ open Matrix
19
+
20
+ namespace SharpTerminalLeave
21
+ open scoped Matrix.Norms.L2Operator
22
+
23
+ theorem averagingProjector_reindex {I J : Type*} [Fintype I] [Fintype J]
24
+ (e : I ≃ J) : Matrix.reindex e e (averagingProjector : Matrix I I ℝ) =
25
+ (averagingProjector : Matrix J J ℝ) := by
26
+ ext i j
27
+ simp only [Matrix.reindex_apply,Matrix.submatrix_apply,averagingProjector]
28
+ rw [Fintype.card_congr e]
29
+
30
+ theorem averagingProjector_hermitian {I : Type*} [Fintype I] :
31
+ (averagingProjector : Matrix I I ℝ).IsHermitian := by
32
+ apply Matrix.IsHermitian.ext
33
+ intro i j
34
+ simp [averagingProjector]
35
+
36
+ theorem averagingProjector_posSemidef {I : Type*} [Fintype I] :
37
+ (averagingProjector : Matrix I I ℝ).PosSemidef := by
38
+ apply Matrix.PosSemidef.of_dotProduct_mulVec_nonneg averagingProjector_hermitian
39
+ intro x
40
+ have heq : star x ⬝ᵥ ((averagingProjector : Matrix I I ℝ) *ᵥ x) =
41
+ (Fintype.card I : ℝ)⁻¹ * (∑ i, x i)^2 := by
42
+ simp [averagingProjector,dotProduct,Matrix.mulVec,← Finset.sum_mul,pow_two,
43
+ mul_comm,mul_assoc]
44
+ rw [heq]
45
+ positivity
46
+
47
+ noncomputable def linkStarMatrix {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) :
48
+ Matrix (edgeStar G u) (edgeStar G u) ℝ :=
49
+ Matrix.reindex (neighborEdgeEquiv G hG u) (neighborEdgeEquiv G hG u)
50
+ ((linkSimpleGraph G hG u).adjMatrix ℝ)
51
+
52
+ noncomputable def globalLinkAdjacency {n : ℕ} (G : Graph n) (hG : G ⊆ completeGraph n) :
53
+ Matrix G G ℝ := ∑ u, extendStar (edgeStar G u) (linkStarMatrix G hG u)
54
+
55
+ noncomputable def globalStarAverage {n : ℕ} (G : Graph n) : Matrix G G ℝ :=
56
+ ∑ u, extendStar (edgeStar G u) averagingProjector
57
+
58
+ theorem globalStarAverage_posSemidef {n : ℕ} (G : Graph n) :
59
+ (globalStarAverage G).PosSemidef := by
60
+ apply Matrix.posSemidef_sum
61
+ intro u _
62
+ exact averagingProjector_posSemidef.mul_mul_conjTranspose_same _
63
+
64
+ noncomputable def prefixSpectralError (n : ℕ) (c : ℝ) : ℝ :=
65
+ 4 * ((8001 : ℝ) * (n : ℝ)^(-c) + (8000 : ℝ)^8001 * 2^8000 *
66
+ ((n : ℝ) / prefixD n^4000 + 1/prefixD n)) ^ (1 / (8000 : ℝ)) + 7*(n : ℝ)^(-c)
67
+
68
+ theorem prefixSpectralError_nonneg (n : ℕ) (c : ℝ) (hD : 0 ≤ prefixD n) :
69
+ 0 ≤ prefixSpectralError n c := by
70
+ unfold prefixSpectralError
71
+ positivity
72
+
73
+ theorem goodPrefix_global_spectral {n : ℕ} {G : Graph n} {c C : ℝ}
74
+ (h : GoodPrefixGraph n c C G) (hne : ∀ u, (neighbors G u).Nonempty)
75
+ (hD : 1 ≤ prefixD n) (hδ : (n : ℝ)^(-c) ≤ 1) :
76
+ ‖(prefixD n)⁻¹ • globalLinkAdjacency G h.1 - globalStarAverage G‖ ≤
77
+ 2 * prefixSpectralError n c := by
78
+ let M (u : Fin n) : Matrix (neighbors G u) (neighbors G u) ℝ :=
79
+ (prefixD n)⁻¹ • (linkSimpleGraph G h.1 u).adjMatrix ℝ - averagingProjector
80
+ let N (u : Fin n) : Matrix (edgeStar G u) (edgeStar G u) ℝ :=
81
+ Matrix.reindex (neighborEdgeEquiv G h.1 u) (neighborEdgeEquiv G h.1 u) (M u)
82
+ have hM : ∀ u, (M u).IsHermitian := by
83
+ intro u
84
+ exact ((linkSimpleGraph G h.1 u).isHermitian_adjMatrix ℝ).smul
85
+ (isSelfAdjoint_iff.mpr rfl) |>.sub averagingProjector_hermitian
86
+ have hlocal : ∀ u, ‖N u‖ ≤ prefixSpectralError n c := by
87
+ intro u
88
+ have : Nonempty (neighbors G u) := (hne u).to_subtype
89
+ apply (hermitian_reindex_norm_le _ _ (hM u)).trans
90
+ apply (goodPrefix_star_fixed h u hD hδ).trans
91
+ have hn : ((neighbors G u).card : ℝ) ≤ n := by
92
+ exact_mod_cast (show (neighbors G u).card ≤ n by simpa using (neighbors G u).card_le_univ)
93
+ unfold prefixSpectralError
94
+ gcongr
95
+ have hsplit : (prefixD n)⁻¹ • globalLinkAdjacency G h.1 - globalStarAverage G =
96
+ ∑ u, extendStar (edgeStar G u) (N u) := by
97
+ simp only [globalLinkAdjacency,globalStarAverage,Finset.smul_sum,← Finset.sum_sub_distrib]
98
+ apply Finset.sum_congr rfl
99
+ intro u _
100
+ have heq : N u = (prefixD n)⁻¹ • linkStarMatrix G h.1 u - averagingProjector := by
101
+ ext i j
102
+ simp only [N,M,linkStarMatrix,Matrix.reindex_apply,Matrix.submatrix_apply,
103
+ Matrix.sub_apply,Matrix.smul_apply,averagingProjector]
104
+ rw [Fintype.card_congr (neighborEdgeEquiv G h.1 u)]
105
+ rw [heq]
106
+ simp [extendStar,Matrix.mul_sub,Matrix.sub_mul,Matrix.smul_mul,Matrix.mul_smul]
107
+ rw [hsplit]
108
+ apply graph_star_error_norm G h.1 N (fun u => (Matrix.isHermitian_reindex_iff _).mpr (hM u))
109
+ (prefixSpectralError n c) (prefixSpectralError_nonneg n c (le_trans zero_le_one hD)) hlocal
110
+
111
+ end SharpTerminalLeave
112
+
113
+ end
114
+ end
115
+
116
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/MatrixEuclideanAlgHom.lean ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.IncidenceDegree
3
+ import OAI.Combinatorics.TriangleRemoval.Stability.Volterra
4
+ import OAI.Combinatorics.TriangleRemoval.Spectral.MatrixExpL2Bound
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ open scoped BigOperators Topology Matrix.Norms.Operator
10
+ open MeasureTheory
11
+
12
+ namespace SharpTerminalLeave
13
+
14
+ noncomputable def matrixEuclideanAlgHom {I : Type*} [Fintype I] [DecidableEq I] :
15
+ Matrix I I ℝ →ₐ[ℝ] (EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) :=
16
+ (Matrix.toEuclideanCLM (n := I) (𝕜 := ℝ)).toAlgEquiv.toAlgHom
17
+
18
+ open scoped Matrix.Norms.L2Operator in
19
+
20
+ theorem euclidean_posSemidef_exp_bound {I : Type*} [Fintype I] [DecidableEq I]
21
+ (P : Matrix I I ℝ) (hP : P.PosSemidef) (s : ℝ) (hs : 0 ≤ s) :
22
+ ‖NormedSpace.exp ((-s) • matrixEuclideanAlgHom P)‖ ≤ 1 := by
23
+ have hF : Continuous (matrixEuclideanAlgHom (I := I)) :=
24
+ (matrixEuclideanAlgHom (I := I)).toLinearMap.continuous_of_finiteDimensional
25
+ rw [← map_smul,← continuous_algHom_map_exp (matrixEuclideanAlgHom (I := I)) hF]
26
+ exact matrix_posSemidef_exp_l2_le_one P hP s hs
27
+
28
+ open scoped Matrix.Norms.L2Operator in
29
+
30
+ theorem euclidean_perturbed_exp_bound {I : Type*} [Fintype I] [DecidableEq I] [Nonempty I]
31
+ (P R : Matrix I I ℝ) (hP : P.PosSemidef) (hR : IsSelfAdjoint R)
32
+ (s : ℝ) (hs : 0 ≤ s) :
33
+ ‖NormedSpace.exp ((-s) • (matrixEuclideanAlgHom P + matrixEuclideanAlgHom R))‖ ≤
34
+ Real.exp (s * ‖matrixEuclideanAlgHom R‖) := by
35
+ have hF : Continuous (matrixEuclideanAlgHom (I := I)) :=
36
+ (matrixEuclideanAlgHom (I := I)).toLinearMap.continuous_of_finiteDimensional
37
+ rw [← map_add,← map_smul,← continuous_algHom_map_exp (matrixEuclideanAlgHom (I := I)) hF]
38
+ exact matrix_perturbed_exp_l2_bound P R hP hR s hs
39
+
40
+ open scoped Matrix.Norms.Operator in
41
+
42
+ theorem matrix_infty_le_sqrt_card_euclidean {I : Type*} [Fintype I] [DecidableEq I]
43
+ (A : Matrix I I ℝ) : ‖A‖ ≤ Real.sqrt (Fintype.card I) * ‖matrixEuclideanAlgHom A‖ := by
44
+ apply matrix_norm_le_of_row_abs_sum_le _ _ (by positivity)
45
+ intro i
46
+ let v : EuclideanSpace ℝ I := WithLp.toLp 2 (fun j => if 0 ≤ A i j then 1 else -1)
47
+ have hv : ‖v‖ = Real.sqrt (Fintype.card I) := by
48
+ rw [EuclideanSpace.norm_eq]
49
+ congr 1
50
+ calc
51
+ _ = ∑ _j : I, (1 : ℝ) := by
52
+ apply Finset.sum_congr rfl
53
+ intro j _
54
+ simp only [v]
55
+ split_ifs <;> norm_num
56
+ _ = _ := by simp
57
+ have heq : (matrixEuclideanAlgHom A v).ofLp i = ∑ j, |A i j| := by
58
+ change (Matrix.toEuclideanCLM (n := I) (𝕜 := ℝ) A v).ofLp i = _
59
+ simp only [Matrix.ofLp_toEuclideanCLM,v,Matrix.mulVec,dotProduct]
60
+ apply Finset.sum_congr rfl
61
+ intro j _
62
+ by_cases h : 0 ≤ A i j
63
+ · simp [h,abs_of_nonneg h]
64
+ · simp [h,abs_of_neg (lt_of_not_ge h)]
65
+ have hp := (PiLp.norm_apply_le (matrixEuclideanAlgHom A v) i).trans
66
+ ((matrixEuclideanAlgHom A).le_opNorm v)
67
+ rw [heq,Real.norm_eq_abs,abs_of_nonneg (Finset.sum_nonneg fun j _ => abs_nonneg _),hv] at hp
68
+ simpa only [mul_comm] using hp
69
+
70
+ end SharpTerminalLeave
71
+
72
+ end
73
+
74
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/MatrixExpL2Bound.lean ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ namespace OAI
4
+
5
+ section
6
+ open scoped BigOperators Topology Matrix.Norms.Operator
7
+ open MeasureTheory
8
+
9
+ section
10
+ open scoped BigOperators Topology Matrix.Norms.L2Operator MatrixOrder
11
+
12
+ namespace SharpTerminalLeave
13
+
14
+ theorem matrix_exp_l2_bound {ι : Type*} [Fintype ι] [DecidableEq ι]
15
+ (A : Matrix ι ι ℝ) (hA : IsSelfAdjoint A) (r s : ℝ) (hs : 0 ≤ s)
16
+ (hlower : ∀ x ∈ spectrum ℝ A, -r ≤ x) :
17
+ ‖NormedSpace.exp ((-s) • A)‖ ≤ Real.exp (s * r) := by
18
+ have heq : NormedSpace.exp ((-s) • A) =
19
+ cfc (fun x : ℝ => Real.exp ((-s) * x)) A := by
20
+ rw [← CFC.real_exp_eq_normedSpace_exp ((isSelfAdjoint_iff.mpr rfl).smul hA)]
21
+ rw [← cfc_smul_id (R := ℝ) (-s) A hA, ← cfc_comp Real.exp (fun x : ℝ => (-s) • x) A hA]
22
+ rfl
23
+ rw [heq]
24
+ apply norm_cfc_le (Real.exp_pos _).le
25
+ intro x hx
26
+ rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)]
27
+ exact Real.exp_le_exp.mpr (by nlinarith [hlower x hx])
28
+
29
+ theorem matrix_posSemidef_exp_l2_le_one {ι : Type*} [Fintype ι] [DecidableEq ι]
30
+ (P : Matrix ι ι ℝ) (hP : P.PosSemidef) (s : ℝ) (hs : 0 ≤ s) :
31
+ ‖NormedSpace.exp ((-s) • P)‖ ≤ 1 := by
32
+ have h : ∀ x ∈ spectrum ℝ P, -(0 : ℝ) ≤ x := by
33
+ simpa only [neg_zero] using (algebraMap_le_iff_le_spectrum
34
+ (IsSelfAdjoint.of_nonneg hP.nonneg)).mp (show algebraMap ℝ _ 0 ≤ P by simp [hP.nonneg])
35
+ simpa only [mul_zero, Real.exp_zero] using
36
+ matrix_exp_l2_bound P (IsSelfAdjoint.of_nonneg hP.nonneg) 0 s hs h
37
+
38
+ theorem matrix_perturbed_exp_l2_bound {ι : Type*} [Fintype ι] [DecidableEq ι]
39
+ [Nonempty ι]
40
+ (P R : Matrix ι ι ℝ) (hP : P.PosSemidef) (hR : IsSelfAdjoint R)
41
+ (s : ℝ) (hs : 0 ≤ s) :
42
+ ‖NormedSpace.exp ((-s) • (P + R))‖ ≤ Real.exp (s * ‖R‖) := by
43
+ have hPR : IsSelfAdjoint (P + R) := (IsSelfAdjoint.of_nonneg hP.nonneg).add hR
44
+ have hRlower : algebraMap ℝ (Matrix ι ι ℝ) (-‖R‖) ≤ R := by
45
+ apply algebraMap_le_of_le_spectrum (ha := hR)
46
+ intro x hx
47
+ have hxnorm := spectrum.norm_le_norm_of_mem hx
48
+ rw [Real.norm_eq_abs] at hxnorm
49
+ exact (abs_le.mp hxnorm).1
50
+ apply matrix_exp_l2_bound (P + R) hPR ‖R‖ s hs
51
+ apply (algebraMap_le_iff_le_spectrum hPR).mp
52
+ exact hRlower.trans (le_add_of_nonneg_left hP.nonneg)
53
+
54
+ end SharpTerminalLeave
55
+
56
+ end
57
+
58
+ end
59
+
60
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/MatrixInfinityAlgHom.lean ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Stability.Volterra
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open Filter
10
+ open scoped BigOperators Topology
11
+
12
+ namespace SharpTerminalLeave
13
+ noncomputable def matrixInfinityAlgHom {I : Type*} [Fintype I] [DecidableEq I] :
14
+ Matrix I I ℝ →ₐ[ℝ] ((I → ℝ) →L[ℝ] (I → ℝ)) :=
15
+ (Matrix.toLinAlgEquiv'.trans (Module.End.toContinuousLinearMap (I → ℝ))).toAlgHom
16
+
17
+ @[simp] theorem matrixInfinityAlgHom_apply {I : Type*} [Fintype I] [DecidableEq I]
18
+ (A : Matrix I I ℝ) (z : I → ℝ) (i : I) :
19
+ matrixInfinityAlgHom A z i = ∑ j, A i j * z j := rfl
20
+
21
+ open scoped Matrix.Norms.Operator in
22
+
23
+ @[simp] theorem matrixInfinityAlgHom_norm {I : Type*} [Fintype I] [DecidableEq I]
24
+ (A : Matrix I I ℝ) : ‖matrixInfinityAlgHom A‖ = ‖A‖ :=
25
+ (Matrix.linfty_opNorm_eq_opNorm A).symm
26
+
27
+ open scoped Matrix.Norms.Operator in
28
+
29
+ theorem matrixInfinityAlgHom_exp_norm {I : Type*} [Fintype I] [DecidableEq I]
30
+ (A : Matrix I I ℝ) (s : ℝ) :
31
+ ‖NormedSpace.exp ((-s) • matrixInfinityAlgHom A)‖ =
32
+ ‖NormedSpace.exp ((-s) • A)‖ := by
33
+ have hc : Continuous (matrixInfinityAlgHom (I := I)) :=
34
+ (matrixInfinityAlgHom (I := I)).toLinearMap.continuous_of_finiteDimensional
35
+ rw [← map_smul,← continuous_algHom_map_exp (matrixInfinityAlgHom (I := I)) hc,
36
+ matrixInfinityAlgHom_norm]
37
+ rfl
38
+ end SharpTerminalLeave
39
+
40
+ end
41
+
42
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/MatrixRowAbsSum.lean ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.ExtendStarApply
3
+ import OAI.Combinatorics.TriangleRemoval.Process.IncidenceDegree
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ section
9
+ open Filter
10
+ open scoped BigOperators Topology
11
+ open InnerProductSpace
12
+ open scoped InnerProductSpace
13
+ open scoped BigOperators NNReal
14
+ open Matrix InnerProductSpace
15
+ open scoped BigOperators
16
+ open scoped BigOperators Matrix.Norms.L2Operator
17
+ open Matrix
18
+ open scoped BigOperators Topology NNReal Matrix.Norms.Operator
19
+ open MeasureTheory
20
+
21
+ namespace SharpTerminalLeave
22
+ open scoped Matrix.Norms.Operator
23
+
24
+ theorem matrix_row_abs_sum_le {I J : Type*} [Fintype I] [Fintype J]
25
+ (M : Matrix I J ℝ) (i : I) : ∑ j, |M i j| ≤ ‖M‖ := by
26
+ rw [Matrix.linfty_opNorm_def]
27
+ have hh : ∑ j, ‖M i j‖₊ ≤ Finset.univ.sup (fun k => ∑ j, ‖M k j‖₊) :=
28
+ Finset.le_sup (f := fun k => ∑ j, ‖M k j‖₊) (Finset.mem_univ i)
29
+ have hc := NNReal.coe_le_coe.mpr hh
30
+ simpa only [NNReal.coe_sum,coe_nnnorm,Real.norm_eq_abs] using hc
31
+
32
+ theorem extendStar_row_abs_sum {E : Type*} [Fintype E] [DecidableEq E]
33
+ (S : Finset E) (M : Matrix S S ℝ) (i : E) :
34
+ ∑ j, |extendStar S M i j| =
35
+ if hi : i ∈ S then ∑ j : S, |M ⟨i,hi⟩ j| else 0 := by
36
+ by_cases hi : i ∈ S
37
+ · rw [dite_eq_left hi]
38
+ have he : ∑ j : E, |extendStar S M i j| = ∑ j ∈ S, |extendStar S M i j| := by
39
+ symm
40
+ apply Finset.sum_subset (Finset.subset_univ S)
41
+ intro j _ hj
42
+ simp [extendStar_apply,hj]
43
+ rw [he,← Finset.sum_coe_sort S]
44
+ apply Finset.sum_congr rfl
45
+ intro j _
46
+ simp [extendStar_apply,hi,j.property]
47
+ · simp [extendStar_apply,hi]
48
+
49
+ theorem sum_star_infty_norm_bound {E U : Type*} [Fintype E] [DecidableEq E] [Fintype U]
50
+ (S : U → Finset E) (M : (u : U) → Matrix (S u) (S u) ℝ)
51
+ (ε K : ℝ) (hε : 0 ≤ ε) (hK : 0 ≤ K) (hM : ∀ u, ‖M u‖ ≤ ε)
52
+ (hoverlap : ∀ e, ((Finset.univ.filter fun u => e ∈ S u).card : ℝ) ≤ K) :
53
+ ‖∑ u, extendStar (S u) (M u)‖ ≤ K*ε := by
54
+ apply matrix_norm_le_of_row_abs_sum_le _ _ (mul_nonneg hK hε)
55
+ intro e
56
+ calc
57
+ _ ≤ ∑ f, ∑ u, |extendStar (S u) (M u) e f| := by
58
+ apply Finset.sum_le_sum
59
+ intro f _
60
+ simp only [Matrix.sum_apply]
61
+ exact Finset.abs_sum_le_sum_abs _ _
62
+ _ = ∑ u, ∑ f, |extendStar (S u) (M u) e f| := Finset.sum_comm
63
+ _ ≤ ∑ u, if e ∈ S u then ε else 0 := by
64
+ apply Finset.sum_le_sum
65
+ intro u _
66
+ rw [extendStar_row_abs_sum]
67
+ by_cases he : e ∈ S u
68
+ · simp only [he,↓reduceDIte,↓reduceIte]
69
+ exact (matrix_row_abs_sum_le (M u) ⟨e,he⟩).trans (hM u)
70
+ · simp [he]
71
+ _ = ((Finset.univ.filter fun u => e ∈ S u).card : ℝ) * ε := by
72
+ rw [← Finset.sum_filter]
73
+ simp
74
+ _ ≤ K*ε := mul_le_mul_of_nonneg_right (hoverlap e) hε
75
+
76
+ theorem infty_reindex_norm_le {I J : Type*} [Fintype I] [Fintype J]
77
+ (e : I ≃ J) (M : Matrix I I ℝ) : ‖Matrix.reindex e e M‖ ≤ ‖M‖ := by
78
+ apply matrix_norm_le_of_row_abs_sum_le _ _ (norm_nonneg _)
79
+ intro i
80
+ simp only [Matrix.reindex_apply,Matrix.submatrix_apply]
81
+ rw [e.symm.sum_comp (fun j => |M (e.symm i) j|)]
82
+ exact matrix_row_abs_sum_le M (e.symm i)
83
+
84
+ end SharpTerminalLeave
85
+
86
+ end
87
+ end
88
+
89
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/MovingStarDegree.lean ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ namespace OAI
4
+
5
+ section
6
+ open scoped BigOperators
7
+
8
+ namespace SharpTerminalLeave
9
+
10
+ open Classical
11
+
12
+ private lemma moving_abs_sub_bound (x y : ℝ) : |x-y| ≤ |x|+|y| := by
13
+ simpa using (abs_sub_le x 0 y)
14
+
15
+ noncomputable def movingStarDegree {E V : Type*} [Fintype E] [Fintype V]
16
+ (ends : E → Finset V) (active : Finset E) (u : V) : ℝ := by
17
+ classical
18
+ exact ((active.filter (fun e => u ∈ ends e)).card : ℝ)
19
+
20
+ noncomputable def movingStarMean {E V : Type*} [Fintype E] [Fintype V]
21
+ (ends : E → Finset V) (active : Finset E) (x : E → ℝ) (u : V) : ℝ := by
22
+ classical
23
+ exact (∑ e ∈ active.filter (fun e => u ∈ ends e), x e) / movingStarDegree ends active u
24
+
25
+ noncomputable def movingStarLift {E V : Type*} [Fintype E] [Fintype V]
26
+ (ends : E → Finset V) (b : V → ℝ) (e : E) : ℝ := ∑ u ∈ ends e, b u
27
+
28
+ noncomputable def movingStarOtherMean {E V : Type*} [Fintype E] [Fintype V]
29
+ (ends : E → Finset V) (active : Finset E) (b : V → ℝ) (u : V) : ℝ := by
30
+ classical
31
+ exact (∑ e ∈ active.filter (fun e => u ∈ ends e), ∑ v ∈ (ends e).erase u, b v) /
32
+ movingStarDegree ends active u
33
+
34
+ lemma movingStarDegree_nonneg {E V : Type*} [Fintype E] [Fintype V]
35
+ (ends : E → Finset V) (active : Finset E) (u : V) :
36
+ 0 ≤ movingStarDegree ends active u := Nat.cast_nonneg _
37
+
38
+ lemma movingStarMean_congr {E V : Type*} [Fintype E] [Fintype V]
39
+ (ends : E → Finset V) (active : Finset E) {x y : E → ℝ}
40
+ (h : ∀ e ∈ active, x e = y e) : movingStarMean ends active x = movingStarMean ends active y := by
41
+ classical
42
+ funext u
43
+ unfold movingStarMean
44
+ congr 1
45
+ apply Finset.sum_congr rfl
46
+ intro e he
47
+ exact h e (Finset.mem_filter.mp he).1
48
+
49
+ lemma movingStarMean_sub {E V : Type*} [Fintype E] [Fintype V]
50
+ (ends : E → Finset V) (active : Finset E) (x y : E → ℝ) (u : V) :
51
+ movingStarMean ends active (fun e => x e-y e) u =
52
+ movingStarMean ends active x u-movingStarMean ends active y u := by
53
+ classical
54
+ simp only [movingStarMean,Finset.sum_sub_distrib,sub_div]
55
+
56
+ lemma movingStarMean_zero_degree {E V : Type*} [Fintype E] [Fintype V]
57
+ (ends : E → Finset V) (active : Finset E) (x : E → ℝ) (u : V)
58
+ (hd : movingStarDegree ends active u = 0) : movingStarMean ends active x u = 0 := by
59
+ simp [movingStarMean,hd]
60
+
61
+ lemma movingStarMean_bound {E V : Type*} [Fintype E] [Fintype V]
62
+ (ends : E → Finset V) (active : Finset E) (x : E → ℝ) (u : V)
63
+ {M : ℝ} (hM : 0 ≤ M) (hx : ∀ e ∈ active, |x e| ≤ M) :
64
+ |movingStarMean ends active x u| ≤ M := by
65
+ classical
66
+ by_cases hd : movingStarDegree ends active u = 0
67
+ · simpa [movingStarMean_zero_degree ends active x u hd] using hM
68
+ · have hp : 0 < movingStarDegree ends active u :=
69
+ lt_of_le_of_ne (movingStarDegree_nonneg ends active u) (Ne.symm hd)
70
+ unfold movingStarMean
71
+ rw [abs_div,abs_of_pos hp]
72
+ apply (div_le_iff₀ hp).mpr
73
+ calc
74
+ _ ≤ ∑ e ∈ active.filter (fun e => u ∈ ends e), |x e| := Finset.abs_sum_le_sum_abs _ _
75
+ _ ≤ ∑ _e ∈ active.filter (fun e => u ∈ ends e), M := by
76
+ apply Finset.sum_le_sum
77
+ intro e he
78
+ exact hx e (Finset.mem_filter.mp he).1
79
+ _ = _ := by simp [movingStarDegree,mul_comm]
80
+
81
+ lemma movingStarLift_bound {E V : Type*} [Fintype E] [Fintype V]
82
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2) (b : V → ℝ)
83
+ {B : ℝ} (hb : ∀ v, |b v| ≤ B) (e : E) : |movingStarLift ends b e| ≤ 2*B := by
84
+ classical
85
+ unfold movingStarLift
86
+ calc
87
+ _ ≤ ∑ v ∈ ends e, |b v| := Finset.abs_sum_le_sum_abs _ _
88
+ _ ≤ ∑ _v ∈ ends e, B := Finset.sum_le_sum (fun v _ => hb v)
89
+ _ = _ := by simp [hends]
90
+
91
+ lemma movingStarOtherMean_bound {E V : Type*} [Fintype E] [Fintype V]
92
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2) (active : Finset E)
93
+ (b : V → ℝ) (u : V) {B : ℝ} (hB : 0 ≤ B) (hb : ∀ v, |b v| ≤ B) :
94
+ |movingStarOtherMean ends active b u| ≤ B := by
95
+ classical
96
+ by_cases hd : movingStarDegree ends active u = 0
97
+ · simpa [movingStarOtherMean,hd] using hB
98
+ · have hp : 0 < movingStarDegree ends active u :=
99
+ lt_of_le_of_ne (movingStarDegree_nonneg ends active u) (Ne.symm hd)
100
+ unfold movingStarOtherMean
101
+ rw [abs_div,abs_of_pos hp]
102
+ apply (div_le_iff₀ hp).mpr
103
+ calc
104
+ _ ≤ ∑ e ∈ active.filter (fun e => u ∈ ends e), |∑ v ∈ (ends e).erase u, b v| :=
105
+ Finset.abs_sum_le_sum_abs _ _
106
+ _ ≤ ∑ _e ∈ active.filter (fun e => u ∈ ends e), B := by
107
+ apply Finset.sum_le_sum
108
+ intro e he
109
+ have hu := (Finset.mem_filter.mp he).2
110
+ have hc : ((ends e).erase u).card = 1 := by
111
+ rw [Finset.card_erase_of_mem hu,hends]
112
+ calc
113
+ _ ≤ ∑ v ∈ (ends e).erase u, |b v| := Finset.abs_sum_le_sum_abs _ _
114
+ _ ≤ ∑ _v ∈ (ends e).erase u, B := Finset.sum_le_sum (fun v _ => hb v)
115
+ _ = B := by simp [hc]
116
+ _ = _ := by simp [movingStarDegree,mul_comm]
117
+
118
+ lemma movingStarMean_lift {E V : Type*} [Fintype E] [Fintype V]
119
+ (ends : E → Finset V) (active : Finset E) (b : V → ℝ) (u : V)
120
+ (hd : movingStarDegree ends active u ≠ 0) :
121
+ movingStarMean ends active (movingStarLift ends b) u =
122
+ b u + movingStarOtherMean ends active b u := by
123
+ classical
124
+ have he : (∑ e ∈ active.filter (fun e => u ∈ ends e), movingStarLift ends b e) =
125
+ movingStarDegree ends active u*b u +
126
+ ∑ e ∈ active.filter (fun e => u ∈ ends e), ∑ v ∈ (ends e).erase u, b v := by
127
+ calc
128
+ _ = ∑ e ∈ active.filter (fun e => u ∈ ends e), (b u+∑ v ∈ (ends e).erase u, b v) := by
129
+ apply Finset.sum_congr rfl
130
+ intro e he
131
+ exact (Finset.add_sum_erase _ b (Finset.mem_filter.mp he).2).symm
132
+ _ = _ := by simp [Finset.sum_add_distrib,movingStarDegree]
133
+ unfold movingStarMean movingStarOtherMean
134
+ rw [he,add_div,mul_div_cancel_left₀ _ hd]
135
+
136
+ theorem movingStar_vertex_step_bound {E V : Type*} [Fintype E] [Fintype V]
137
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2) (active : Finset E)
138
+ (b : V → ℝ) (M : E → ℝ) {B R a : ℝ} (hB : 0 ≤ B) (hR : 0 ≤ R)
139
+ (ha : 0 ≤ a) (ha1 : a ≤ 1) (hb : ∀ u, |b u| ≤ B)
140
+ (hM : ∀ e ∈ active, |M e| ≤ R) (u : V) :
141
+ |b u + a*movingStarMean ends active (fun e => M e-movingStarLift ends b e) u| ≤ B+a*R := by
142
+ classical
143
+ rw [movingStarMean_sub]
144
+ by_cases hd : movingStarDegree ends active u = 0
145
+ · rw [movingStarMean_zero_degree ends active M u hd,
146
+ movingStarMean_zero_degree ends active (movingStarLift ends b) u hd]
147
+ simp only [sub_self,mul_zero,add_zero]
148
+ exact (hb u).trans (le_add_of_nonneg_right (mul_nonneg ha hR))
149
+ · rw [movingStarMean_lift ends active b u hd]
150
+ have hid : b u+a*(movingStarMean ends active M u-(b u+movingStarOtherMean ends active b u)) =
151
+ (1-a)*b u-a*movingStarOtherMean ends active b u+a*movingStarMean ends active M u := by ring
152
+ rw [hid]
153
+ calc
154
+ _ ≤ |(1-a)*b u-a*movingStarOtherMean ends active b u|+
155
+ |a*movingStarMean ends active M u| := abs_add_le _ _
156
+ _ ≤ (|(1-a)*b u|+|a*movingStarOtherMean ends active b u|)+
157
+ |a*movingStarMean ends active M u| := by
158
+ exact add_le_add (moving_abs_sub_bound _ _) le_rfl
159
+ _ = ((1-a)*|b u|+a*|movingStarOtherMean ends active b u|)+
160
+ a*|movingStarMean ends active M u| := by
161
+ rw [abs_mul,abs_mul,abs_mul,abs_of_nonneg (sub_nonneg.mpr ha1),abs_of_nonneg ha]
162
+ _ ≤ ((1-a)*B+a*B)+a*R := by
163
+ gcongr
164
+ · exact hb u
165
+ · exact movingStarOtherMean_bound ends hends active b u hB hb
166
+ · exact movingStarMean_bound ends active M u hR hM
167
+ _ = _ := by ring
168
+
169
+ noncomputable def movingStarVertices {E V : Type*} [Fintype E] [Fintype V]
170
+ (ends : E → Finset V) (active : ℕ → Finset E) (a : ℕ → ℝ)
171
+ (M : ℕ → E → ℝ) : ℕ → V → ℝ
172
+ | 0 => fun _ => 0
173
+ | k+1 => fun u => movingStarVertices ends active a M k u + a k *
174
+ movingStarMean ends (active k)
175
+ (fun e => M k e-movingStarLift ends (movingStarVertices ends active a M k) e) u
176
+
177
+ theorem movingStarVertices_bound {E V : Type*} [Fintype E] [Fintype V]
178
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2)
179
+ (active : ℕ → Finset E) (a : ℕ → ℝ) (M : ℕ → E → ℝ) (T : ℕ)
180
+ {R : ℝ} (hR : 0 ≤ R) (ha : ∀ k < T, 0 ≤ a k ∧ a k ≤ 1)
181
+ (hM : ∀ k < T, ∀ e ∈ active k, |M k e| ≤ R) :
182
+ ∀ u, |movingStarVertices ends active a M T u| ≤ R*∑ k ∈ Finset.range T, a k := by
183
+ induction T with
184
+ | zero => intro u; simp [movingStarVertices]
185
+ | succ T ih =>
186
+ have haT := ha T (by omega)
187
+ have hb := ih (fun k hk => ha k (by omega)) (fun k hk => hM k (by omega))
188
+ have hB : 0 ≤ R*∑ k ∈ Finset.range T, a k := by
189
+ exact mul_nonneg hR (Finset.sum_nonneg (fun k hk => (ha k (by have := Finset.mem_range.mp hk; omega)).1))
190
+ intro u
191
+ have hh := movingStar_vertex_step_bound ends hends (active T)
192
+ (movingStarVertices ends active a M T) (M T) hB hR haT.1 haT.2 hb (hM T (by omega)) u
193
+ simpa only [movingStarVertices,Finset.sum_range_succ,mul_add,mul_comm] using hh
194
+
195
+ theorem movingStar_trajectory_representation {E V : Type*} [Fintype E] [Fintype V]
196
+ (ends : E → Finset V) (active : ℕ → Finset E) (a : ℕ → ℝ)
197
+ (M x : ℕ → E → ℝ) (T : ℕ)
198
+ (hnest : ∀ k < T, active (k+1) ⊆ active k)
199
+ (hinit : ∀ e ∈ active 0, x 0 e = M 0 e)
200
+ (hstep : ∀ k < T, ∀ e ∈ active (k+1), x (k+1) e = x k e -
201
+ a k*movingStarLift ends (movingStarMean ends (active k) (x k)) e + (M (k+1) e-M k e)) :
202
+ ∀ e ∈ active T, x T e = M T e-movingStarLift ends (movingStarVertices ends active a M T) e := by
203
+ induction T with
204
+ | zero => intro e he; simpa [movingStarVertices,movingStarLift] using hinit e he
205
+ | succ T ih =>
206
+ have hx := ih (fun k hk => hnest k (by omega)) (fun k hk => hstep k (by omega))
207
+ have hm := movingStarMean_congr ends (active T) hx
208
+ intro e he
209
+ rw [hstep T (by omega) e he,hx e (hnest T (by omega) he),hm]
210
+ simp only [movingStarVertices,movingStarLift,Finset.sum_add_distrib,Finset.mul_sum]
211
+ ring
212
+
213
+ theorem movingStar_trajectory_bound {E V : Type*} [Fintype E] [Fintype V]
214
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2)
215
+ (active : ℕ → Finset E) (a : ℕ → ℝ) (M x : ℕ → E → ℝ) (T : ℕ)
216
+ (hnest : ∀ k < T, active (k+1) ⊆ active k)
217
+ (hinit : ∀ e ∈ active 0, x 0 e = M 0 e)
218
+ (hstep : ∀ k < T, ∀ e ∈ active (k+1), x (k+1) e = x k e -
219
+ a k*movingStarLift ends (movingStarMean ends (active k) (x k)) e + (M (k+1) e-M k e))
220
+ {R : ℝ} (hR : 0 ≤ R) (ha : ∀ k < T, 0 ≤ a k ∧ a k ≤ 1)
221
+ (hM : ∀ k ≤ T, ∀ e ∈ active k, |M k e| ≤ R) :
222
+ ∀ e ∈ active T, |x T e| ≤ R*(1+2*∑ k ∈ Finset.range T, a k) := by
223
+ have hb := movingStarVertices_bound ends hends active a M T hR ha (fun k hk => hM k (by omega))
224
+ intro e he
225
+ rw [movingStar_trajectory_representation ends active a M x T hnest hinit hstep e he]
226
+ calc
227
+ _ ≤ |M T e|+|movingStarLift ends (movingStarVertices ends active a M T) e| := moving_abs_sub_bound _ _
228
+ _ ≤ R+2*(R*∑ k ∈ Finset.range T, a k) := add_le_add (hM T le_rfl e he)
229
+ (movingStarLift_bound ends hends _ hb e)
230
+ _ = _ := by ring
231
+
232
+ lemma movingStar_incidence_swap {E V : Type*} [Fintype E] [Fintype V]
233
+ (ends : E → Finset V) (active : Finset E) (f : E → V → ℝ) :
234
+ (∑ e ∈ active, ∑ u ∈ ends e, f e u) =
235
+ ∑ u, ∑ e ∈ active.filter (fun e => u ∈ ends e), f e u := by
236
+ classical
237
+ have he (e : E) : (∑ u ∈ ends e, f e u) = ∑ u, if u ∈ ends e then f e u else 0 := by simp
238
+ simp_rw [he]
239
+ rw [Finset.sum_comm]
240
+ simp only [Finset.sum_filter]
241
+
242
+ lemma movingStarMean_mass {E V : Type*} [Fintype E] [Fintype V]
243
+ (ends : E → Finset V) (active : Finset E) (x : E → ℝ) (u : V) :
244
+ movingStarDegree ends active u*movingStarMean ends active x u =
245
+ ∑ e ∈ active.filter (fun e => u ∈ ends e), x e := by
246
+ classical
247
+ by_cases hd : movingStarDegree ends active u = 0
248
+ · have hc : (active.filter (fun e => u ∈ ends e)).card = 0 := by
249
+ exact_mod_cast (show ((active.filter (fun e => u ∈ ends e)).card : ℝ) = 0 from hd)
250
+ have he := Finset.card_eq_zero.mp hc
251
+ simp [movingStarMean,hd,he]
252
+ · unfold movingStarMean
253
+ exact mul_div_cancel₀ _ hd
254
+
255
+ theorem movingStar_energy_identity {E V : Type*} [Fintype E] [Fintype V]
256
+ (ends : E → Finset V) (active : Finset E) (x : E → ℝ) :
257
+ (∑ e ∈ active, x e*movingStarLift ends (movingStarMean ends active x) e) =
258
+ ∑ u, movingStarDegree ends active u*(movingStarMean ends active x u)^2 := by
259
+ classical
260
+ simp only [movingStarLift,Finset.mul_sum]
261
+ rw [movingStar_incidence_swap]
262
+ apply Finset.sum_congr rfl
263
+ intro u _
264
+ rw [← Finset.sum_mul,← movingStarMean_mass ends active x u]
265
+ ring
266
+
267
+ lemma movingStar_lift_sq_bound {E V : Type*} [Fintype E] [Fintype V]
268
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2)
269
+ (active : Finset E) (b : V → ℝ) :
270
+ (∑ e ∈ active, (movingStarLift ends b e)^2) ≤
271
+ 2*∑ u, movingStarDegree ends active u*(b u)^2 := by
272
+ classical
273
+ calc
274
+ _ ≤ ∑ e ∈ active, 2*∑ u ∈ ends e, (b u)^2 := by
275
+ apply Finset.sum_le_sum
276
+ intro e _
277
+ simpa only [movingStarLift,hends,Nat.cast_ofNat] using
278
+ (sq_sum_le_card_mul_sum_sq (s := ends e) (f := b))
279
+ _ = _ := by
280
+ rw [← Finset.mul_sum,movingStar_incidence_swap]
281
+ congr 1
282
+ apply Finset.sum_congr rfl
283
+ intro u _
284
+ simp [movingStarDegree]
285
+
286
+ theorem movingStar_euler_energy_le {E V : Type*} [Fintype E] [Fintype V]
287
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2)
288
+ (active : Finset E) (x : E → ℝ) {a : ℝ} (ha : 0 ≤ a) (ha1 : a ≤ 1) :
289
+ (∑ e ∈ active, (x e-a*movingStarLift ends (movingStarMean ends active x) e)^2) ≤
290
+ ∑ e ∈ active, (x e)^2 := by
291
+ classical
292
+ let P := movingStarLift ends (movingStarMean ends active x)
293
+ let V := ∑ u, movingStarDegree ends active u*(movingStarMean ends active x u)^2
294
+ have hV : 0 ≤ V := Finset.sum_nonneg (fun u _ =>
295
+ mul_nonneg (movingStarDegree_nonneg ends active u) (sq_nonneg _))
296
+ have hlin : (∑ e ∈ active, x e*P e) = V := movingStar_energy_identity ends active x
297
+ have hsq : (∑ e ∈ active, (P e)^2) ≤ 2*V :=
298
+ movingStar_lift_sq_bound ends hends active (movingStarMean ends active x)
299
+ have hexpand : (∑ e ∈ active, (x e-a*P e)^2) =
300
+ (∑ e ∈ active, (x e)^2)-2*a*(∑ e ∈ active, x e*P e)+
301
+ a^2*(∑ e ∈ active, (P e)^2) := by
302
+ calc
303
+ _ = ∑ e ∈ active, ((x e)^2-2*a*(x e*P e)+a^2*(P e)^2) := by
304
+ apply Finset.sum_congr rfl
305
+ intro e _
306
+ ring
307
+ _ = _ := by simp only [Finset.sum_add_distrib,Finset.sum_sub_distrib,Finset.mul_sum]
308
+ change (∑ e ∈ active, (x e-a*P e)^2) ≤ _
309
+ rw [hexpand,hlin]
310
+ have hsq' := mul_le_mul_of_nonneg_left hsq (sq_nonneg a)
311
+ have hab : a^2 ≤ a := by nlinarith
312
+ have hb := mul_le_mul_of_nonneg_right hab hV
313
+ nlinarith only [hsq',hb]
314
+
315
+ theorem movingStar_euler_energy_subset_le {E V : Type*} [Fintype E] [Fintype V]
316
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2)
317
+ (active remaining : Finset E) (hsub : remaining ⊆ active) (x : E → ℝ)
318
+ {a : ℝ} (ha : 0 ≤ a) (ha1 : a ≤ 1) :
319
+ (∑ e ∈ remaining, (x e-a*movingStarLift ends (movingStarMean ends active x) e)^2) ≤
320
+ ∑ e ∈ active, (x e)^2 := by
321
+ apply le_trans _ (movingStar_euler_energy_le ends hends active x ha ha1)
322
+ exact Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => sq_nonneg _)
323
+
324
+ end SharpTerminalLeave
325
+ end
326
+
327
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/NormalizedOnes.lean ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.UnitLineRemainder
3
+ import OAI.Combinatorics.TriangleRemoval.Process.EigenProjector
4
+ import OAI.Combinatorics.TriangleRemoval.Process.EigenvalueAbsRowsum
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ section
10
+ open Filter
11
+ open scoped BigOperators Topology
12
+ open InnerProductSpace
13
+ open scoped InnerProductSpace
14
+ open scoped BigOperators NNReal
15
+ open Matrix
16
+ open scoped BigOperators Matrix.Norms.L2Operator
17
+ open Matrix InnerProductSpace
18
+
19
+ namespace SharpTerminalLeave
20
+
21
+ variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι]
22
+
23
+ noncomputable def normalizedOnes : EuclideanSpace ℝ ι :=
24
+ WithLp.toLp 2 (fun _ => (Real.sqrt (Fintype.card ι : ℝ))⁻¹)
25
+
26
+ noncomputable def averagingProjector : Matrix ι ι ℝ :=
27
+ fun _ _ => (Fintype.card ι : ℝ)⁻¹
28
+
29
+ omit [DecidableEq ι] in
30
+ theorem normalizedOnes_norm : ‖(normalizedOnes : EuclideanSpace ℝ ι)‖ = 1 := by
31
+ have hn : 0 < (Fintype.card ι : ℝ) := Nat.cast_pos.mpr Fintype.card_pos
32
+ have hs : (Real.sqrt (Fintype.card ι : ℝ)) ^ 2 = Fintype.card ι :=
33
+ Real.sq_sqrt (le_of_lt hn)
34
+ have hnorm : ‖(normalizedOnes : EuclideanSpace ℝ ι)‖ ^ 2 = 1 := by
35
+ rw [EuclideanSpace.norm_sq_eq]
36
+ simp only [normalizedOnes, WithLp.ofLp_toLp, Real.norm_eq_abs, sq_abs,
37
+ Finset.sum_const, Finset.card_univ, nsmul_eq_mul, inv_pow, hs]
38
+ exact mul_inv_cancel₀ (ne_of_gt hn)
39
+ nlinarith [norm_nonneg (normalizedOnes : EuclideanSpace ℝ ι)]
40
+
41
+ theorem normalizedOnes_residual (A : Matrix ι ι ℝ) (δ : ℝ) (hδ : 0 ≤ δ)
42
+ (hrow : ∀ i, |(∑ j, A i j) - 1| ≤ δ) :
43
+ ‖(Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ)) A normalizedOnes - normalizedOnes‖ ≤ δ := by
44
+ have hn : 0 < (Fintype.card ι : ℝ) := Nat.cast_pos.mpr Fintype.card_pos
45
+ have hs : (Real.sqrt (Fintype.card ι : ℝ)) ^ 2 = Fintype.card ι :=
46
+ Real.sq_sqrt (le_of_lt hn)
47
+ have hcoords : ∀ i, ((Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ)) A normalizedOnes - normalizedOnes).ofLp i =
48
+ ((∑ j, A i j) - 1) * (Real.sqrt (Fintype.card ι : ℝ))⁻¹ := by
49
+ intro i
50
+ simp [normalizedOnes, Matrix.toEuclideanCLM_toLp, Matrix.mulVec, dotProduct,
51
+ Finset.sum_mul, sub_mul]
52
+ have hsq : ‖(Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ)) A normalizedOnes - normalizedOnes‖ ^ 2 ≤ δ ^ 2 := by
53
+ rw [EuclideanSpace.norm_sq_eq]
54
+ calc
55
+ _ = ∑ i, |((∑ j, A i j) - 1)| ^ 2 * (Real.sqrt (Fintype.card ι : ℝ))⁻¹ ^ 2 := by
56
+ simp only [hcoords, Real.norm_eq_abs, sq_abs, mul_pow]
57
+ _ ≤ ∑ _ : ι, δ ^ 2 * (Real.sqrt (Fintype.card ι : ℝ))⁻¹ ^ 2 := by
58
+ apply Finset.sum_le_sum
59
+ intro i _
60
+ exact mul_le_mul_of_nonneg_right
61
+ (pow_le_pow_left₀ (abs_nonneg _) (hrow i) 2) (sq_nonneg _)
62
+ _ = δ ^ 2 := by
63
+ simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, inv_pow, hs]
64
+ field_simp
65
+ nlinarith [norm_nonneg ((Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ)) A normalizedOnes - normalizedOnes)]
66
+
67
+ omit [Nonempty ι] in
68
+ theorem eigenProjector_entry (A : Matrix ι ι ℝ) (hA : A.IsHermitian) (k i j : ι) :
69
+ eigenProjector A hA k i j = hA.eigenvectorBasis k i * hA.eigenvectorBasis k j := by
70
+ simp [eigenProjector, Unitary.conjStarAlgAut_apply, Matrix.mul_apply,
71
+ Matrix.diagonal_apply, Pi.single_apply]
72
+
73
+ omit [Nonempty ι] in
74
+ theorem eigenProjector_toCLM (A : Matrix ι ι ℝ) (hA : A.IsHermitian) (k : ι) :
75
+ (Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ)) (eigenProjector A hA k) =
76
+ rankOne ℝ (hA.eigenvectorBasis k) (hA.eigenvectorBasis k) := by
77
+ ext x i
78
+ change ((eigenProjector A hA k) *ᵥ x.ofLp) i = _
79
+ simp only [rankOne_apply, PiLp.smul_apply, smul_eq_mul, Matrix.mulVec, dotProduct,
80
+ eigenProjector_entry, PiLp.inner_apply, RCLike.inner_apply, conj_trivial]
81
+ simp_rw [Finset.sum_mul]
82
+ apply Finset.sum_congr rfl
83
+ intro j _
84
+ ring
85
+
86
+ omit [Nonempty ι] in
87
+ theorem averagingProjector_toCLM :
88
+ (Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ)) (averagingProjector : Matrix ι ι ℝ) =
89
+ rankOne ℝ (normalizedOnes : EuclideanSpace ℝ ι) normalizedOnes := by
90
+ have hn : 0 ≤ (Fintype.card ι : ℝ) := Nat.cast_nonneg _
91
+ have hs : (Real.sqrt (Fintype.card ι : ℝ))⁻¹ ^ 2 = (Fintype.card ι : ℝ)⁻¹ := by
92
+ rw [inv_pow, Real.sq_sqrt hn]
93
+ ext x i
94
+ change (averagingProjector *ᵥ x.ofLp) i = _
95
+ simp only [rankOne_apply, PiLp.smul_apply, smul_eq_mul, Matrix.mulVec, dotProduct,
96
+ averagingProjector, PiLp.inner_apply, RCLike.inner_apply, conj_trivial,
97
+ normalizedOnes]
98
+ rw [Finset.sum_mul]
99
+ apply Finset.sum_congr rfl
100
+ intro j _
101
+ nlinarith [congrArg (fun t : ℝ => t * x.ofLp j) hs]
102
+
103
+ theorem star_approximation_from_trace (A : Matrix ι ι ℝ) (hA : A.IsHermitian)
104
+ (δ θ : ℝ) (hδ0 : 0 ≤ δ) (hδ1 : δ ≤ 1) (hθ : 0 ≤ θ)
105
+ (hpos : ∀ i j, 0 ≤ A i j) (hrow : ∀ i, |(∑ j, A i j) - 1| ≤ δ)
106
+ (r : ℕ) (hr : Even r) (hr0 : r ≠ 0)
107
+ (htrace : (A ^ r).trace ≤ (1 - δ) ^ r + θ ^ r) :
108
+ ‖A - averagingProjector‖ ≤ 4 * θ + 7 * δ := by
109
+ have hrlo : ∀ i, 1 - δ ≤ ∑ j, A i j := fun i => by
110
+ have hh := (abs_le.mp (hrow i)).1
111
+ linarith
112
+ have hrhi : ∀ i, ∑ j, |A i j| ≤ 1 + δ := fun i => by
113
+ simp_rw [abs_of_nonneg (hpos i _)]
114
+ have hh := (abs_le.mp (hrow i)).2
115
+ linarith
116
+ obtain ⟨k, hklo, hkhi, _⟩ := exists_leading_of_rowsums A hA (1-δ) (1+δ)
117
+ (by linarith) hrlo hrhi
118
+ have hlam : |hA.eigenvalues k - 1| ≤ δ := by
119
+ have hhi := (abs_le.mp hkhi).2
120
+ exact abs_le.mpr ⟨by linarith, by linarith⟩
121
+ have htail := eigenvalue_tail_of_trace A hA k r hr hr0 (1-δ) θ
122
+ (by linarith) hθ hklo htrace
123
+ have happrox := eigenProjector_approximation A hA k θ hθ htail
124
+ have heig : ‖(Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ)) A - hA.eigenvalues k •
125
+ rankOne ℝ (hA.eigenvectorBasis k) (hA.eigenvectorBasis k)‖ ≤ θ := by
126
+ rw [← eigenProjector_toCLM A hA k, ← map_smul, ← map_sub,
127
+ Matrix.l2_opNorm_toEuclideanCLM]
128
+ exact happrox
129
+ have hfinal := projector_transfer ((Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ)) A)
130
+ (hA.eigenvectorBasis k) normalizedOnes (hA.eigenvectorBasis.norm_eq_one k)
131
+ normalizedOnes_norm (hA.eigenvalues k) θ δ δ heig hlam
132
+ (normalizedOnes_residual A δ hδ0 hrow)
133
+ rw [← averagingProjector_toCLM, ← map_sub, Matrix.l2_opNorm_toEuclideanCLM] at hfinal
134
+ linarith
135
+
136
+ end SharpTerminalLeave
137
+
138
+ open scoped BigOperators
139
+
140
+ end
141
+ end
142
+
143
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/RealTraceAdjMatrix.lean ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.ClosedWalkFamily
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ section
8
+ open Filter
9
+ open scoped BigOperators Topology
10
+ open InnerProductSpace
11
+ open scoped InnerProductSpace
12
+ open scoped BigOperators NNReal
13
+ open Matrix
14
+ open scoped BigOperators Matrix.Norms.L2Operator
15
+ open Matrix InnerProductSpace
16
+ open scoped BigOperators
17
+
18
+ namespace SharpTerminalLeave
19
+ section RealTrace
20
+ variable {V : Type*} [Fintype V] [DecidableEq V]
21
+ variable (G : SimpleGraph V) [DecidableRel G.Adj]
22
+
23
+ lemma real_trace_adjMatrix_eq (n : ℕ) :
24
+ Matrix.trace (G.adjMatrix ℝ ^ (n+3)) =
25
+ ((graphEmbeddings (SimpleGraph.cycleGraph (n+3)) G).card : ℝ) +
26
+ (nonsimpleWords G (n+3)).card := by
27
+ have hNat := trace_adjMatrix_eq_closedWords G n
28
+ rw [closedWords_card_eq] at hNat
29
+ have ht : Matrix.trace (G.adjMatrix ℝ ^ (n+3)) =
30
+ ((Matrix.trace (G.adjMatrix ℕ ^ (n+3)) : ℕ) : ℝ) := by
31
+ simp only [Matrix.trace, Matrix.diag_apply, Nat.cast_sum,
32
+ SimpleGraph.adjMatrix_pow_apply_eq_card_walk, Nat.cast_id]
33
+ rw [ht, hNat, Nat.cast_add]
34
+
35
+ theorem normalized_link_trace_bound (n : ℕ) (hr : Even (n+3)) (D δ : ℝ)
36
+ (hD : 1 ≤ D)
37
+ (hdeg : ∀ x : V, ((Finset.univ.filter (G.Adj x)).card : ℝ) ≤ 2*D)
38
+ (hmain : |((graphEmbeddings (SimpleGraph.cycleGraph (n+3)) G).card : ℝ) - D^(n+3)| ≤
39
+ δ * D^(n+3))
40
+ (hcyc : ∀ b, 3 ≤ b → b < n+3 →
41
+ ((graphEmbeddings (SimpleGraph.cycleGraph b) G).card : ℝ) ≤ 2 * D^b) :
42
+ |Matrix.trace (((D⁻¹) • G.adjMatrix ℝ) ^ (n+3)) - 1| ≤
43
+ δ + ((n+3 : ℕ) : ℝ)^(n+4) * 2^(n+3) *
44
+ ((Fintype.card V : ℝ) / D^((n+3)/2) + 1/D) := by
45
+ classical
46
+ have hD0 : 0 < D := lt_of_lt_of_le zero_lt_one hD
47
+ have hDne : D ≠ 0 := ne_of_gt hD0
48
+ let Δ : ℕ := ⌊2*D⌋₊
49
+ have hΔlo : D ≤ (Δ : ℝ) := by
50
+ have hh := Nat.lt_floor_add_one (2*D)
51
+ change 2*D < (Δ : ℝ)+1 at hh
52
+ linarith
53
+ have hΔhi : (Δ : ℝ) ≤ 2*D := Nat.floor_le (by positivity)
54
+ have hΔ0 : 1 ≤ Δ := by exact_mod_cast hD.trans hΔlo
55
+ have hdeg' : ∀ x : V, (Finset.univ.filter (G.Adj x)).card ≤ Δ := by
56
+ intro x
57
+ exact (Nat.le_floor_iff (by positivity : 0 ≤ 2*D)).mpr (hdeg x)
58
+ have hcyc' : ∀ b, 3 ≤ b → b < n+3 →
59
+ (graphEmbeddings (SimpleGraph.cycleGraph b) G).card ≤ 2 * Δ^b := by
60
+ intro b hb hbr
61
+ have hh := (hcyc b hb hbr).trans (mul_le_mul_of_nonneg_left
62
+ (pow_le_pow_left₀ hD0.le hΔlo b) (by norm_num : (0:ℝ) ≤ 2))
63
+ exact_mod_cast hh
64
+ have hcount := nonsimpleWords_card_le G n Δ 2 hΔ0 hdeg' hcyc'
65
+ have hcountR : ((nonsimpleWords G (n+3)).card : ℝ) ≤
66
+ ((n+3 : ℕ) : ℝ)^(n+4) *
67
+ ((Fintype.card V : ℝ) * (2*D)^((n+3)/2) + 2*(2*D)^(n+2)) := by
68
+ have hh : ((nonsimpleWords G (n+3)).card : ℝ) ≤
69
+ ((n+3 : ℕ) : ℝ)^(n+4) *
70
+ ((Fintype.card V : ℝ) * (Δ:ℝ)^((n+3)/2) + 2*(Δ:ℝ)^(n+2)) := by
71
+ exact_mod_cast hcount
72
+ refine hh.trans (mul_le_mul_of_nonneg_left ?_ (by positivity))
73
+ exact add_le_add
74
+ (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (Nat.cast_nonneg Δ) hΔhi _) (Nat.cast_nonneg _))
75
+ (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (Nat.cast_nonneg Δ) hΔhi _) (by norm_num))
76
+ have hhalf : (n+3)/2 + (n+3)/2 = n+3 := by
77
+ obtain ⟨k, hk⟩ := hr
78
+ omega
79
+ have hhalfle : (n+3)/2 ≤ n+3 := Nat.div_le_self _ _
80
+ have hp2 : (2:ℝ)^((n+3)/2) ≤ 2^(n+3) := pow_le_pow_right₀ (by norm_num) hhalfle
81
+ have hpow : D^(n+3) = D^((n+3)/2) * D^((n+3)/2) := by rw [← pow_add, hhalf]
82
+ have hpow' : D^(n+3) = D^(n+2) * D := by rw [← pow_succ]
83
+ have hratio : ((nonsimpleWords G (n+3)).card : ℝ) / D^(n+3) ≤
84
+ ((n+3 : ℕ) : ℝ)^(n+4) * 2^(n+3) *
85
+ ((Fintype.card V : ℝ) / D^((n+3)/2) + 1/D) := by
86
+ apply (div_le_iff₀ (pow_pos hD0 _)).mpr
87
+ have htree : (Fintype.card V : ℝ) * (2*D)^((n+3)/2) ≤
88
+ 2^(n+3) * ((Fintype.card V : ℝ)/D^((n+3)/2)) * D^(n+3) := by
89
+ rw [mul_pow, hpow]
90
+ field_simp
91
+ nlinarith [mul_le_mul_of_nonneg_right hp2
92
+ (mul_nonneg (Nat.cast_nonneg (Fintype.card V)) (pow_nonneg hD0.le ((n+3)/2)))]
93
+ have hcycle : 2*(2*D)^(n+2) = 2^(n+3) * (1/D) * D^(n+3) := by
94
+ rw [mul_pow, hpow', show n+3 = (n+2)+1 by omega, pow_succ]
95
+ field_simp
96
+ ring
97
+ calc
98
+ _ ≤ ((n+3 : ℕ) : ℝ)^(n+4) *
99
+ ((Fintype.card V : ℝ) * (2*D)^((n+3)/2) + 2*(2*D)^(n+2)) := hcountR
100
+ _ ≤ ((n+3 : ℕ) : ℝ)^(n+4) *
101
+ (2^(n+3) * ((Fintype.card V : ℝ)/D^((n+3)/2)) * D^(n+3) +
102
+ 2^(n+3) * (1/D) * D^(n+3)) := mul_le_mul_of_nonneg_left (add_le_add htree hcycle.le) (by positivity)
103
+ _ = _ := by ring
104
+ have htrace : Matrix.trace (((D⁻¹) • G.adjMatrix ℝ) ^ (n+3)) =
105
+ (((graphEmbeddings (SimpleGraph.cycleGraph (n+3)) G).card : ℝ) +
106
+ (nonsimpleWords G (n+3)).card) / D^(n+3) := by
107
+ rw [smul_pow, Matrix.trace_smul, real_trace_adjMatrix_eq]
108
+ simp only [smul_eq_mul, inv_pow, div_eq_mul_inv, mul_comm]
109
+ rw [htrace]
110
+ calc
111
+ _ = |(((graphEmbeddings (SimpleGraph.cycleGraph (n+3)) G).card : ℝ) - D^(n+3)) /
112
+ D^(n+3) + (nonsimpleWords G (n+3)).card / D^(n+3)| := by
113
+ congr 1
114
+ field_simp
115
+ ring
116
+ _ ≤ |(((graphEmbeddings (SimpleGraph.cycleGraph (n+3)) G).card : ℝ) - D^(n+3)) /
117
+ D^(n+3)| + |((nonsimpleWords G (n+3)).card : ℝ) / D^(n+3)| := abs_add_le _ _
118
+ _ ≤ δ + ((n+3 : ℕ) : ℝ)^(n+4) * 2^(n+3) *
119
+ ((Fintype.card V : ℝ) / D^((n+3)/2) + 1/D) := by
120
+ apply add_le_add
121
+ · rw [abs_div, abs_of_pos (pow_pos hD0 _)]
122
+ exact (div_le_iff₀ (pow_pos hD0 _)).mpr hmain
123
+ · rw [abs_of_nonneg (div_nonneg (Nat.cast_nonneg _) (pow_nonneg hD0.le _))]
124
+ exact hratio
125
+
126
+ end RealTrace
127
+ end SharpTerminalLeave
128
+
129
+ end
130
+ end
131
+
132
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/StarInclusion.lean ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ namespace OAI
4
+
5
+ section
6
+ section
7
+ open Filter
8
+ open scoped BigOperators Topology
9
+ open InnerProductSpace
10
+ open scoped InnerProductSpace
11
+ open scoped BigOperators NNReal
12
+ open Matrix InnerProductSpace
13
+ open scoped BigOperators
14
+ open scoped BigOperators Matrix.Norms.L2Operator
15
+ open Matrix
16
+
17
+ namespace SharpTerminalLeave
18
+
19
+ variable {E U : Type*} [Fintype E] [DecidableEq E] [Fintype U]
20
+
21
+ def starInclusion (S : Finset E) : Matrix E S ℝ :=
22
+ fun e f => if e = f.val then 1 else 0
23
+
24
+ noncomputable def extendStar (S : Finset E) (M : Matrix S S ℝ) : Matrix E E ℝ :=
25
+ starInclusion S * M * (starInclusion S)ᴴ
26
+
27
+ theorem starInclusion_mulVec (S : Finset E) (x : E → ℝ) :
28
+ (starInclusion S)ᴴ *ᵥ x = fun e : S => x e.val := by
29
+ ext e
30
+ simp [starInclusion,Matrix.mulVec,dotProduct]
31
+
32
+ theorem extendStar_quadratic (S : Finset E) (M : Matrix S S ℝ) (x : E → ℝ) :
33
+ x ⬝ᵥ (extendStar S M *ᵥ x) =
34
+ (fun e : S => x e.val) ⬝ᵥ (M *ᵥ fun e : S => x e.val) := by
35
+ rw [extendStar,← Matrix.mulVec_mulVec,← Matrix.mulVec_mulVec,starInclusion_mulVec,
36
+ Matrix.dotProduct_mulVec]
37
+ congr 1
38
+ ext e
39
+ simp [starInclusion,Matrix.vecMul,dotProduct]
40
+
41
+ theorem matrix_quadratic_abs (M : Matrix E E ℝ) (x : E → ℝ) :
42
+ |x ⬝ᵥ (M *ᵥ x)| ≤ ‖M‖ * ∑ e, (x e)^2 := by
43
+ let y : EuclideanSpace ℝ E := WithLp.toLp 2 x
44
+ let T := (Matrix.toEuclideanCLM (n := E) (𝕜 := ℝ)) M
45
+ have heq : x ⬝ᵥ (M *ᵥ x) = inner ℝ y (T y) := by
46
+ simp [T,y,Matrix.toEuclideanCLM_toLp,EuclideanSpace.inner_eq_star_dotProduct,dotProduct,
47
+ mul_comm]
48
+ have hn : ‖y‖^2 = ∑ e, (x e)^2 := by
49
+ simp [EuclideanSpace.norm_sq_eq,y,Real.norm_eq_abs]
50
+ rw [heq]
51
+ calc
52
+ _ ≤ ‖y‖ * ‖T y‖ := abs_real_inner_le_norm _ _
53
+ _ ≤ ‖y‖ * (‖T‖ * ‖y‖) := mul_le_mul_of_nonneg_left (T.le_opNorm y) (norm_nonneg _)
54
+ _ = ‖M‖ * ∑ e, (x e)^2 := by
55
+ rw [mul_left_comm,← pow_two,hn]
56
+ exact congrArg (fun a : ℝ => a * ∑ e, (x e)^2) (Matrix.l2_opNorm_toEuclideanCLM M)
57
+
58
+ theorem hermitian_norm_le_of_quadratic (M : Matrix E E ℝ) (hM : M.IsHermitian)
59
+ (a : ℝ) (ha : 0 ≤ a)
60
+ (hquad : ∀ x : E → ℝ, |x ⬝ᵥ (M *ᵥ x)| ≤ a * ∑ e, (x e)^2) : ‖M‖ ≤ a := by
61
+ have hev : ∀ e, |hM.eigenvalues e| ≤ a := by
62
+ intro e
63
+ have h := hquad (hM.eigenvectorBasis e).ofLp
64
+ have hn : ∑ i, ((hM.eigenvectorBasis e).ofLp i)^2 = 1 := by
65
+ have hh := hM.eigenvectorBasis.norm_eq_one e
66
+ have hs := EuclideanSpace.norm_sq_eq (hM.eigenvectorBasis e)
67
+ simpa [hh,Real.norm_eq_abs] using hs.symm
68
+ rw [hn,mul_one] at h
69
+ simpa [hM.eigenvalues_eq e] using h
70
+ conv_lhs => rw [hM.spectral_theorem]
71
+ rw [Unitary.conjStarAlgAut_apply,← Unitary.coe_star,CStarRing.norm_mul_coe_unitary,
72
+ CStarRing.norm_coe_unitary_mul,Matrix.l2_opNorm_diagonal]
73
+ exact (pi_norm_le_iff_of_nonneg ha).mpr (fun e => hev e)
74
+
75
+ theorem sum_star_norm_bound (S : U → Finset E) (M : (u : U) → Matrix (S u) (S u) ℝ)
76
+ (hM : ∀ u, (M u).IsHermitian) (ε K : ℝ) (hε : 0 ≤ ε) (hK : 0 ≤ K)
77
+ (hlocal : ∀ u, ‖M u‖ ≤ ε)
78
+ (hoverlap : ∀ e : E, ((Finset.univ.filter fun u => e ∈ S u).card : ℝ) ≤ K) :
79
+ ‖∑ u, extendStar (S u) (M u)‖ ≤ K*ε := by
80
+ have hsym : (∑ u, extendStar (S u) (M u)).IsHermitian := by
81
+ apply Matrix.IsHermitian.ext
82
+ intro i j
83
+ simp only [Matrix.sum_apply,star_sum]
84
+ apply Finset.sum_congr rfl
85
+ intro u _
86
+ exact (Matrix.isHermitian_mul_mul_conjTranspose (starInclusion (S u)) (hM u)).apply i j
87
+ apply hermitian_norm_le_of_quadratic _ hsym (K*ε) (mul_nonneg hK hε)
88
+ intro x
89
+ have hsum : x ⬝ᵥ ((∑ u, extendStar (S u) (M u)) *ᵥ x) =
90
+ ∑ u, (fun e : S u => x e.val) ⬝ᵥ (M u *ᵥ fun e : S u => x e.val) := by
91
+ simp only [Matrix.sum_mulVec,dotProduct_sum,extendStar_quadratic]
92
+ have hcount : (∑ u, ∑ e : S u, (x e.val)^2) ≤ K * ∑ e, (x e)^2 := by
93
+ have hrewrite : ∀ u, (∑ e : S u, (x e.val)^2) =
94
+ ∑ e : E, if e ∈ S u then (x e)^2 else 0 := by
95
+ intro u
96
+ rw [← Finset.sum_filter]
97
+ exact (Finset.sum_subtype (Finset.univ.filter fun e => e ∈ S u)
98
+ (fun e => by simp only [Finset.mem_filter,Finset.mem_univ,true_and])
99
+ (fun e => (x e)^2)).symm
100
+ simp_rw [hrewrite]
101
+ rw [Finset.sum_comm,Finset.mul_sum]
102
+ apply Finset.sum_le_sum
103
+ intro e _
104
+ have heq : (∑ u : U, if e ∈ S u then (x e)^2 else 0) =
105
+ ((Finset.univ.filter fun u => e ∈ S u).card : ℝ) * (x e)^2 := by
106
+ rw [← Finset.sum_filter,Finset.sum_const,nsmul_eq_mul]
107
+ rw [heq]
108
+ exact mul_le_mul_of_nonneg_right (hoverlap e) (sq_nonneg _)
109
+ rw [hsum]
110
+ calc
111
+ _ ≤ ∑ u, |(fun e : S u => x e.val) ⬝ᵥ (M u *ᵥ fun e : S u => x e.val)| :=
112
+ Finset.abs_sum_le_sum_abs _ _
113
+ _ ≤ ∑ u, ε * ∑ e : S u, (x e.val)^2 := by
114
+ apply Finset.sum_le_sum
115
+ intro u _
116
+ exact (matrix_quadratic_abs _ _).trans
117
+ (mul_le_mul_of_nonneg_right (hlocal u) (Finset.sum_nonneg fun _ _ => sq_nonneg _))
118
+ _ = ε * (∑ u, ∑ e : S u, (x e.val)^2) := by rw [Finset.mul_sum]
119
+ _ ≤ ε * (K * ∑ e, (x e)^2) := mul_le_mul_of_nonneg_left hcount hε
120
+ _ = K * ε * ∑ e, (x e)^2 := by ring
121
+
122
+ end SharpTerminalLeave
123
+
124
+ end
125
+ end
126
+
127
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/TracedGridQueryAddress.lean ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Asymptotics.FreshLogExposeLabeled
3
+ import OAI.Combinatorics.TriangleRemoval.Spectral.FreshLogCheckNone2
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ open scoped BigOperators Topology Matrix.Norms.Operator
9
+ open MeasureTheory
10
+ open scoped BigOperators
11
+ open scoped BigOperators ENNReal Classical
12
+ open Filter MeasureTheory
13
+ open scoped BigOperators Topology
14
+ open Filter
15
+
16
+ namespace SharpTerminalLeave
17
+ section TraceAddress
18
+ variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ]
19
+
20
+ theorem tracedGridQuery_address (H : τ → Finset ι) (N d k : ℕ) (c : QueryCall ι τ)
21
+ (ν : τ → PMF (Fin N)) {z : (Bool × List (QueryCall ι τ)) × List τ}
22
+ (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) :
23
+ ∀ a ∈ z.1.2, c.address <:+ a.address := by
24
+ induction d generalizing k c z with
25
+ | zero =>
26
+ rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz
27
+ obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
28
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
29
+ have heq : y = ((true,[c]),[]) := by simpa [ExposureTree.freshLog] using hy
30
+ simp [heq]
31
+ | succ d ih =>
32
+ rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz
33
+ obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
34
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
35
+ rw [ExposureTree.freshLog_mapOutput] at hy
36
+ obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy
37
+ have hwP := ExposureTree.freshLog_checkNoneTrace_forall ν
38
+ (fun a : QueryCall ι τ => c.address <:+ a.address) _
39
+ (by
40
+ intro A hA a ha
41
+ obtain ⟨p,_,rfl⟩ := List.mem_map.mp hA
42
+ split_ifs at ha with hp
43
+ · intro b hb
44
+ exact (List.suffix_cons p.1 c.address).trans (ih _ _ ha b hb)
45
+ · have heq : a = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using ha
46
+ simp [heq]) hw
47
+ intro a ha
48
+ rcases List.mem_cons.mp ha with rfl | ha
49
+ · exact ⟨[],rfl⟩
50
+ · exact hwP a ha
51
+
52
+ lemma fork_addresses_ne {α : Type*} {p q : α} {base a b : List α} (hpq : p ≠ q)
53
+ (ha : p :: base <:+ a) (hb : q :: base <:+ b) : a ≠ b := by
54
+ intro hab
55
+ subst b
56
+ have hh := List.suffix_of_suffix_length_le ha hb (by simp)
57
+ have heq := hh.eq_of_length (by simp)
58
+ exact hpq (List.cons.inj heq).1
59
+
60
+ lemma child_address_ne {α : Type*} {p : α} {base a : List α}
61
+ (ha : p :: base <:+ a) : base ≠ a := by
62
+ intro h
63
+ have hh := ha.length_le
64
+ simp only [List.length_cons, ← h] at hh
65
+ omega
66
+
67
+ theorem tracedGridQuery_address_nodup (H : τ → Finset ι) (N d k : ℕ) (c : QueryCall ι τ)
68
+ (ν : τ → PMF (Fin N)) {z : (Bool × List (QueryCall ι τ)) × List τ}
69
+ (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) :
70
+ (z.1.2.map QueryCall.address).Nodup := by
71
+ induction d generalizing k c z with
72
+ | zero =>
73
+ rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz
74
+ obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
75
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
76
+ have heq : y = ((true,[c]),[]) := by simpa [ExposureTree.freshLog] using hy
77
+ simp [heq]
78
+ | succ d ih =>
79
+ rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz
80
+ obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
81
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
82
+ rw [ExposureTree.freshLog_mapOutput] at hy
83
+ obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy
84
+ have hxvals := (ExposureTree.freshLog_exposeLabeled_support ν Prod.snd _ hx).1
85
+ have hnd : (x.1.map Prod.fst).Nodup := by rw [hxvals]; exact Finset.nodup_toList _
86
+ have hsnd := ((List.mergeSort_perm x.1 (fun a b => a.2.val ≤ b.2.val)).map Prod.fst).nodup_iff.mpr hnd
87
+ have hpair : (x.1.mergeSort (fun a b => a.2.val ≤ b.2.val)).Pairwise
88
+ (fun a b => a.1 ≠ b.1) := by
89
+ simpa only [List.Nodup, List.pairwise_map] using hsnd
90
+ have hwR := ExposureTree.freshLog_checkNoneTrace_pairwise ν
91
+ (fun a b : QueryCall ι τ => a.address ≠ b.address) _
92
+ (by
93
+ intro A hA a ha
94
+ obtain ⟨p,_,rfl⟩ := List.mem_map.mp hA
95
+ split_ifs at ha with hp
96
+ · have hh := ih _ _ ha
97
+ simpa only [List.Nodup, List.pairwise_map] using hh
98
+ · have heq : a = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using ha
99
+ simp [heq])
100
+ (by
101
+ apply List.pairwise_map.mpr
102
+ apply hpair.imp
103
+ intro p q hpq x hx y hy a ha b hb
104
+ split_ifs at hx hy with hp hq
105
+ · exact fork_addresses_ne hpq
106
+ (tracedGridQuery_address H N d _ _ ν hx a ha)
107
+ (tracedGridQuery_address H N d _ _ ν hy b hb)
108
+ · have heq : y = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using hy
109
+ simp [heq] at hb
110
+ · have heq : x = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using hx
111
+ simp [heq] at ha
112
+ · have heq : x = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using hx
113
+ simp [heq] at ha) hw
114
+ have hwP := ExposureTree.freshLog_checkNoneTrace_forall ν
115
+ (fun a : QueryCall ι τ => c.address ≠ a.address) _
116
+ (by
117
+ intro A hA a ha
118
+ obtain ⟨p,_,rfl⟩ := List.mem_map.mp hA
119
+ split_ifs at ha with hp
120
+ · intro b hb
121
+ exact child_address_ne (tracedGridQuery_address H N d _ _ ν ha b hb)
122
+ · have heq : a = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using ha
123
+ simp [heq]) hw
124
+ simpa only [List.Nodup, List.map_cons, List.pairwise_cons, List.pairwise_map,
125
+ List.mem_map, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
126
+ using (And.intro hwP hwR)
127
+
128
+ end TraceAddress
129
+ end SharpTerminalLeave
130
+
131
+ end
132
+
133
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/TracedGridQueryLog.lean ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Asymptotics.FreshLogExposeLabeled
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open scoped BigOperators
10
+ open scoped BigOperators ENNReal Classical
11
+ open Filter MeasureTheory
12
+ open scoped BigOperators Topology
13
+ open Filter
14
+
15
+ namespace SharpTerminalLeave
16
+ section TraceAccounting
17
+ variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ]
18
+
19
+ theorem tracedGridQuery_log (H : τ → Finset ι) (N d k : ℕ) (c : QueryCall ι τ)
20
+ (ν : τ → PMF (Fin N)) {z : (Bool × List (QueryCall ι τ)) × List τ}
21
+ (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) :
22
+ z.2 = z.1.2.flatMap (QueryCall.keys H) := by
23
+ induction d generalizing k c z with
24
+ | zero =>
25
+ rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz
26
+ obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
27
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
28
+ have heq : y = ((true,[c]),[]) := by
29
+ simpa [ExposureTree.freshLog] using hy
30
+ have hkeys := (ExposureTree.freshLog_exposeLabeled_support ν Prod.snd _ hx).2
31
+ simp [heq, hkeys, QueryCall.keys]
32
+ | succ d ih =>
33
+ rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz
34
+ obtain ⟨x,hx,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
35
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
36
+ rw [ExposureTree.freshLog_mapOutput] at hy
37
+ obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy
38
+ have hxkeys := (ExposureTree.freshLog_exposeLabeled_support ν Prod.snd _ hx).2
39
+ have hwkeys := ExposureTree.freshLog_checkNoneTrace_support ν (QueryCall.keys H) _
40
+ (by
41
+ intro A hA a ha
42
+ obtain ⟨p,_,rfl⟩ := List.mem_map.mp hA
43
+ split_ifs at ha with hp
44
+ · exact ih _ _ ha
45
+ · have heq : a = ((false,[]),[]) := by
46
+ simpa [ExposureTree.freshLog] using ha
47
+ simp [heq]) hw
48
+ simp only [List.flatMap_cons, hxkeys, hwkeys, QueryCall.keys]
49
+
50
+ end TraceAccounting
51
+ end SharpTerminalLeave
52
+
53
+ end
54
+
55
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/TracedGridQuerySeparated.lean ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.TracedGridQueryLog
3
+ import OAI.Combinatorics.TriangleRemoval.Queries.Separated
4
+ import OAI.Combinatorics.TriangleRemoval.Spectral.FreshLogCheckNone
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ open scoped BigOperators Topology Matrix.Norms.Operator
10
+ open MeasureTheory
11
+ open scoped BigOperators
12
+ open scoped BigOperators ENNReal Classical
13
+ open Filter MeasureTheory
14
+ open scoped BigOperators Topology
15
+ open Filter
16
+
17
+ namespace SharpTerminalLeave
18
+ section TrueRepeatedCall
19
+ variable {ι τ : Type*} [Fintype τ] [DecidableEq ι] [DecidableEq τ]
20
+
21
+ theorem tracedGridQuery_separated (H : τ → Finset ι)
22
+ (hlin : ∀ T S, T ≠ S → (H T ∩ H S).card ≤ 1)
23
+ (N d k : ℕ) (c : QueryCall ι τ) (hc : c.Separated H)
24
+ (ν : τ → PMF (Fin N)) {z : (Bool × List (QueryCall ι τ)) × List τ}
25
+ (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support) :
26
+ ∀ a ∈ z.1.2, a.Separated H := by
27
+ induction d generalizing k c z with
28
+ | zero =>
29
+ rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz
30
+ obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
31
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
32
+ have heq : y = ((true,[c]),[]) := by simpa [ExposureTree.freshLog] using hy
33
+ simpa [heq] using hc
34
+ | succ d ih =>
35
+ rw [tracedGridQuery, ExposureTree.freshLog_bind] at hz
36
+ obtain ⟨x,_,hz⟩ := (PMF.mem_support_bind_iff _ _ _).mp hz
37
+ obtain ⟨y,hy,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hz
38
+ rw [ExposureTree.freshLog_mapOutput] at hy
39
+ obtain ⟨w,hw,rfl⟩ := (PMF.mem_support_map_iff _ _ _).mp hy
40
+ have hwP := ExposureTree.freshLog_checkNoneTrace_forall ν (fun a => a.Separated H) _
41
+ (by
42
+ intro A hA a ha
43
+ obtain ⟨p,_,rfl⟩ := List.mem_map.mp hA
44
+ split_ifs at ha with hp
45
+ · exact ih _ _ (separated_child H hlin _ _ _) ha
46
+ · have heq : a = ((false,[]),[]) := by simpa [ExposureTree.freshLog] using ha
47
+ simp [heq]) hw
48
+ intro a ha
49
+ rcases List.mem_cons.mp ha with rfl | ha
50
+ · exact hc
51
+ · exact hwP a ha
52
+
53
+ theorem repeated_flatMap_calls {R K : Type*} [DecidableEq K]
54
+ (calls : List R) (keys : R → List K)
55
+ (hc : ∀ c ∈ calls, (keys c).Nodup)
56
+ (hr : ExposureTree.repeats ∅ (calls.flatMap keys) = true) :
57
+ ∃ i j : Fin calls.length, i < j ∧ ∃ T,
58
+ T ∈ keys (calls.get i) ∧ T ∈ keys (calls.get j) := by
59
+ by_contra hn
60
+ have hnd : (calls.flatMap keys).Nodup := by
61
+ apply List.nodup_flatMap.mpr
62
+ refine ⟨hc, List.pairwise_iff_get.mpr ?_⟩
63
+ intro i j hij
64
+ apply List.disjoint_left.mpr
65
+ intro T hTi hTj
66
+ exact hn ⟨i,j,hij,T,hTi,hTj⟩
67
+ have hf := (ExposureTree.repeats_empty_false_iff _).mpr hnd
68
+ rw [hr] at hf
69
+ contradiction
70
+
71
+ theorem tracedGridQuery_repeat_calls (H : τ → Finset ι)
72
+ (hlin : ∀ T S, T ≠ S → (H T ∩ H S).card ≤ 1)
73
+ (N d k : ℕ) (c : QueryCall ι τ) (hc : c.Separated H)
74
+ (ν : τ → PMF (Fin N)) {z : (Bool × List (QueryCall ι τ)) × List τ}
75
+ (hz : z ∈ (ExposureTree.freshLog ν (tracedGridQuery H N d k c)).support)
76
+ (hr : ExposureTree.repeats ∅ z.2 = true) :
77
+ ∃ i j : Fin z.1.2.length, i < j ∧ ∃ T,
78
+ T ∈ (z.1.2.get i).keys H ∧ T ∈ (z.1.2.get j).keys H := by
79
+ have hp := tracedGridQuery_separated H hlin N d k c hc ν hz
80
+ rw [tracedGridQuery_log H N d k c ν hz] at hr
81
+ exact repeated_flatMap_calls _ _ (fun a ha => a.keys_nodup H (hp a ha)) hr
82
+
83
+ end TrueRepeatedCall
84
+ end SharpTerminalLeave
85
+
86
+ end
87
+
88
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Spectral/WheelSpoke.lean ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Embeddings.RerootTemplate
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ noncomputable section
8
+ open scoped BigOperators
9
+ open Filter Classical
10
+
11
+ namespace SharpTerminalLeave
12
+
13
+ lemma cycleNext_val {j : ℕ} (i : Fin j) :
14
+ (cycleNext i).val = if i.val+1 < j then i.val+1 else 0 := by
15
+ unfold cycleNext
16
+ dsimp
17
+ split_ifs with h
18
+ · exact Nat.mod_eq_of_lt h
19
+ · have he : i.val+1 = j := by omega
20
+ simp [he]
21
+
22
+ lemma cycleNext_injective (j : ℕ) : Function.Injective (@cycleNext j) := by
23
+ intro i k h
24
+ have hh := congrArg Fin.val h
25
+ rw [cycleNext_val,cycleNext_val] at hh
26
+ apply Fin.ext
27
+ split_ifs at hh <;> omega
28
+
29
+ lemma cycleNext_ne {j : ℕ} (hj : 2 ≤ j) (i : Fin j) : cycleNext i ≠ i := by
30
+ intro h
31
+ have hh := congrArg Fin.val h
32
+ rw [cycleNext_val] at hh
33
+ split_ifs at hh <;> omega
34
+
35
+ lemma cycleNext_twice_ne {j : ℕ} (hj : 3 ≤ j) (i : Fin j) :
36
+ cycleNext (cycleNext i) ≠ i := by
37
+ intro h
38
+ have hh := congrArg Fin.val h
39
+ have h1 := cycleNext_val i
40
+ have h2 := cycleNext_val (cycleNext i)
41
+ split_ifs at h1 h2 <;> omega
42
+
43
+ def wheelSpoke {j : ℕ} (i : Fin j) : Finset (Fin (j+1)) := {0,i.succ}
44
+ def wheelRim {j : ℕ} (i : Fin j) : Finset (Fin (j+1)) := {i.succ,(cycleNext i).succ}
45
+
46
+ lemma wheelSpoke_injective (j : ℕ) : Function.Injective (@wheelSpoke j) := by
47
+ intro i k h
48
+ have hh : i.succ ∈ wheelSpoke k := h ▸ Finset.mem_insert_of_mem (Finset.mem_singleton_self _)
49
+ simp only [wheelSpoke,Finset.mem_insert,Finset.mem_singleton] at hh
50
+ rcases hh with hh | hh
51
+ · exact (Fin.succ_ne_zero i hh).elim
52
+ · exact Fin.succ_injective _ hh
53
+
54
+ lemma wheelRim_injective {j : ℕ} (hj : 3 ≤ j) : Function.Injective (@wheelRim j) := by
55
+ intro i k h
56
+ have ha : i.succ ∈ wheelRim k := h ▸ Finset.mem_insert_self _ _
57
+ have hb : (cycleNext i).succ ∈ wheelRim k := h ▸ Finset.mem_insert_of_mem (Finset.mem_singleton_self _)
58
+ simp only [wheelRim,Finset.mem_insert,Finset.mem_singleton,Fin.succ_inj] at ha hb
59
+ rcases ha with rfl | ha
60
+ · rfl
61
+ rcases hb with hb | hb
62
+ · have hh : cycleNext (cycleNext k) = k := by rw [← ha,hb]
63
+ exact (cycleNext_twice_ne hj k hh).elim
64
+ · exact ((cycleNext_ne (by omega) i) (hb.trans ha.symm)).elim
65
+
66
+ lemma wheelSpoke_ne_rim {j : ℕ} (i k : Fin j) : wheelSpoke i ≠ wheelRim k := by
67
+ intro h
68
+ have hh : (0 : Fin (j+1)) ∈ wheelRim k := h ▸ Finset.mem_insert_self _ _
69
+ simp only [wheelRim,Finset.mem_insert,Finset.mem_singleton,(Ne.symm (Fin.succ_ne_zero _)),or_self] at hh
70
+
71
+ def wheelTemplate (j : ℕ) (hj : 3 ≤ j) : RootedTemplate (j+1) where
72
+ edges := Finset.univ.image wheelSpoke ∪ Finset.univ.image wheelRim
73
+ roots := {0}
74
+ simple := by
75
+ intro e he
76
+ rcases Finset.mem_union.mp he with he | he
77
+ · obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp he
78
+ simp [wheelSpoke,(Ne.symm (Fin.succ_ne_zero _))]
79
+ · obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp he
80
+ have hne : i.succ ≠ (cycleNext i).succ := by
81
+ intro h; exact cycleNext_ne (by omega) i (Fin.succ_injective _ h).symm
82
+ simp [wheelRim,hne]
83
+ independent := by
84
+ intro e he hsub
85
+ rcases Finset.mem_union.mp he with he | he
86
+ · obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp he
87
+ have hh := hsub (show i.succ ∈ wheelSpoke i by simp [wheelSpoke])
88
+ simp at hh
89
+ · obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp he
90
+ have hh := hsub (show i.succ ∈ wheelRim i by simp [wheelRim])
91
+ simp at hh
92
+
93
+ @[simp] lemma wheelTemplate_roots_card (j : ℕ) (hj : 3 ≤ j) :
94
+ (wheelTemplate j hj).roots.card = 1 := Finset.card_singleton _
95
+
96
+ @[simp] lemma wheelTemplate_edges_card (j : ℕ) (hj : 3 ≤ j) :
97
+ (wheelTemplate j hj).edges.card = 2*j := by
98
+ have hd : Disjoint (Finset.univ.image (@wheelSpoke j)) (Finset.univ.image (@wheelRim j)) := by
99
+ apply Finset.disjoint_left.mpr
100
+ intro e he hf
101
+ obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp he
102
+ obtain ⟨k,_,hk⟩ := Finset.mem_image.mp hf
103
+ exact wheelSpoke_ne_rim i k hk.symm
104
+ rw [wheelTemplate,Finset.card_union_of_disjoint hd,
105
+ Finset.card_image_of_injective _ (wheelSpoke_injective j),
106
+ Finset.card_image_of_injective _ (wheelRim_injective hj)]
107
+ simp
108
+ omega
109
+
110
+ lemma wheelTemplate_balanced (j : ℕ) (hj : 3 ≤ j) : RootedTwoBalanced (wheelTemplate j hj) := by
111
+ intro J hJ
112
+ have h0 : (0 : Fin (j+1)) ∈ J := hJ (Finset.mem_singleton_self _)
113
+ let A := Finset.univ.filter (fun i : Fin j => i.succ ∈ J)
114
+ have hsub : ((wheelTemplate j hj).edges.filter (· ⊆ J)) ⊆
115
+ A.image wheelSpoke ∪ A.image wheelRim := by
116
+ intro e he
117
+ obtain ⟨he,hsub⟩ := Finset.mem_filter.mp he
118
+ rcases Finset.mem_union.mp he with he | he
119
+ · obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp he
120
+ exact Finset.mem_union_left _ (Finset.mem_image.mpr ⟨i,Finset.mem_filter.mpr
121
+ ⟨Finset.mem_univ _,hsub (Finset.mem_insert_of_mem (Finset.mem_singleton_self _))⟩,rfl⟩)
122
+ · obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp he
123
+ exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨i,Finset.mem_filter.mpr
124
+ ⟨Finset.mem_univ _,hsub (Finset.mem_insert_self _ _)⟩,rfl⟩)
125
+ have hA : A.card ≤ (J.erase 0).card := by
126
+ apply Finset.card_le_card_of_injOn Fin.succ
127
+ · intro i hi
128
+ exact Finset.mem_erase.mpr ⟨Fin.succ_ne_zero i,(Finset.mem_filter.mp hi).2⟩
129
+ · intro a _ b _ hab
130
+ exact Fin.succ_injective _ hab
131
+ have hc := (Finset.card_le_card hsub).trans (Finset.card_union_le _ _)
132
+ have h1 := Finset.card_image_le (s := A) (f := wheelSpoke)
133
+ have h2 := Finset.card_image_le (s := A) (f := wheelRim)
134
+ rw [Finset.card_erase_of_mem h0] at hA
135
+ rw [wheelTemplate_roots_card]
136
+ omega
137
+
138
+ def wheelRoot {j n : ℕ} (hj : 3 ≤ j) (u : Fin n) :
139
+ {v // v ∈ (wheelTemplate j hj).roots} ↪ Fin n where
140
+ toFun := fun _ => u
141
+ inj' := by
142
+ intro a b _
143
+ apply Subtype.ext
144
+ have ha : a.val = 0 := Finset.mem_singleton.mp a.property
145
+ have hb : b.val = 0 := Finset.mem_singleton.mp b.property
146
+ exact ha.trans hb.symm
147
+
148
+ lemma wheelRooted_zero {j n : ℕ} (hj : 3 ≤ j) (u : Fin n)
149
+ (φ : RootedInjection (wheelTemplate j hj) (wheelRoot hj u)) : φ.val 0 = u :=
150
+ φ.property ⟨0,Finset.mem_singleton_self _⟩
151
+
152
+ def wheelRestrict {j n : ℕ} (hj : 3 ≤ j) (u : Fin n)
153
+ (φ : RootedInjection (wheelTemplate j hj) (wheelRoot hj u)) : Fin j ↪ Fin n :=
154
+ (Fin.succEmb j).trans φ.val
155
+
156
+ lemma wheel_image_subset {j n : ℕ} (hj : 3 ≤ j) (u : Fin n)
157
+ (φ : RootedInjection (wheelTemplate j hj) (wheelRoot hj u)) (G : Graph n) :
158
+ imageEdges (wheelTemplate j hj) φ.val ⊆ G ↔
159
+ ∀ i, {u,wheelRestrict hj u φ i} ∈ G ∧
160
+ {wheelRestrict hj u φ i,wheelRestrict hj u φ (cycleNext i)} ∈ G := by
161
+ have hs (i : Fin j) : (wheelSpoke i).map φ.val = {u,wheelRestrict hj u φ i} := by
162
+ simp [wheelSpoke,wheelRestrict,wheelRooted_zero hj u φ]
163
+ have hr (i : Fin j) : (wheelRim i).map φ.val =
164
+ {wheelRestrict hj u φ i,wheelRestrict hj u φ (cycleNext i)} := by simp [wheelRim,wheelRestrict]
165
+ constructor
166
+ · intro h i
167
+ constructor
168
+ · rw [← hs]
169
+ exact h (Finset.mem_image.mpr ⟨wheelSpoke i,Finset.mem_union_left _ (Finset.mem_image.mpr
170
+ ⟨i,Finset.mem_univ _,rfl⟩),rfl⟩)
171
+ · rw [← hr]
172
+ exact h (Finset.mem_image.mpr ⟨wheelRim i,Finset.mem_union_right _ (Finset.mem_image.mpr
173
+ ⟨i,Finset.mem_univ _,rfl⟩),rfl⟩)
174
+ · intro h e he
175
+ obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp he
176
+ rcases Finset.mem_union.mp hf with hf | hf
177
+ · obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hf
178
+ rw [hs]; exact (h i).1
179
+ · obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hf
180
+ rw [hr]; exact (h i).2
181
+
182
+ lemma wheelRestrict_injective {j n : ℕ} (hj : 3 ≤ j) (u : Fin n) :
183
+ Function.Injective (wheelRestrict hj u) := by
184
+ intro φ χ h
185
+ apply Subtype.ext
186
+ apply Function.Embedding.ext
187
+ intro i
188
+ refine Fin.cases ?_ (fun i => ?_) i
189
+ · exact (wheelRooted_zero hj u φ).trans (wheelRooted_zero hj u χ).symm
190
+ · exact congrArg (fun f : Fin j ↪ Fin n => f i) h
191
+
192
+ lemma wheelRestrict_surj {j n : ℕ} (hj : 3 ≤ j) (u : Fin n) (φ : Fin j ↪ Fin n)
193
+ (havoid : ∀ i, φ i ≠ u) :
194
+ ∃ χ : RootedInjection (wheelTemplate j hj) (wheelRoot hj u), wheelRestrict hj u χ = φ := by
195
+ let f : Fin (j+1) → Fin n := Fin.cases u φ
196
+ have hf : Function.Injective f := by
197
+ intro a b h
198
+ revert h
199
+ refine Fin.cases ?_ (fun a => ?_) a
200
+ · refine Fin.cases ?_ (fun b => ?_) b
201
+ · intro _; rfl
202
+ · intro h; exact (havoid b h.symm).elim
203
+ · refine Fin.cases ?_ (fun b => ?_) b
204
+ · intro h; exact (havoid a h).elim
205
+ · intro h; exact congrArg Fin.succ (φ.injective h)
206
+ let χ : RootedInjection (wheelTemplate j hj) (wheelRoot hj u) :=
207
+ ⟨⟨f,hf⟩,by intro v; have hv : v.val = 0 := Finset.mem_singleton.mp v.property; change f v.val = u; rw [hv]; rfl⟩
208
+ exact ⟨χ,by ext i; rfl⟩
209
+
210
+ theorem wheel_rootedCount {j n : ℕ} (hj : 3 ≤ j) (G : Graph n) (hG : G ⊆ completeGraph n) (u : Fin n) :
211
+ rootedCount (wheelTemplate j hj) (wheelRoot hj u) G = linkCycleCount j G u := by
212
+ let A := Finset.univ.filter (fun φ : RootedInjection (wheelTemplate j hj) (wheelRoot hj u) =>
213
+ imageEdges (wheelTemplate j hj) φ.val ⊆ G)
214
+ let B := Finset.univ.filter (fun φ : Fin j ↪ Fin n =>
215
+ ∀ i, {u,φ i} ∈ G ∧ {φ i,φ (cycleNext i)} ∈ G)
216
+ have hA : rootedCount (wheelTemplate j hj) (wheelRoot hj u) G = (A.card : ℝ) := by
217
+ simp [rootedCount,copyCount,intact,A]
218
+ have hB : linkCycleCount j G u = (B.card : ℝ) := by
219
+ simp [linkCycleCount,B,Finset.sum_boole]
220
+ rw [hA,hB]
221
+ congr 1
222
+ apply Finset.card_bij (fun φ _ => wheelRestrict hj u φ)
223
+ · intro φ hφ
224
+ exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,(wheel_image_subset hj u φ G).mp (Finset.mem_filter.mp hφ).2⟩
225
+ · intro φ _ χ _ h
226
+ exact wheelRestrict_injective hj u h
227
+ · intro φ hφ
228
+ have hp := (Finset.mem_filter.mp hφ).2
229
+ have hav : ∀ i, φ i ≠ u := by
230
+ intro i he
231
+ have hh := mem_completeGraph.mp (hG (hp i).1)
232
+ simp [he] at hh
233
+ obtain ⟨χ,hχ⟩ := wheelRestrict_surj hj u φ hav
234
+ refine ⟨χ,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩,hχ⟩
235
+ exact (wheel_image_subset hj u χ G).mpr (hχ.symm ▸ hp)
236
+
237
+ @[simp] theorem wheel_rootedScaling {j n : ℕ} (hj : 3 ≤ j) (p : ℝ) :
238
+ rootedScaling (wheelTemplate j hj) n p = ((n : ℝ)*p^2)^j := by
239
+ simp only [rootedScaling,wheelTemplate_roots_card,wheelTemplate_edges_card,Nat.add_sub_cancel,
240
+ mul_pow,← pow_mul]
241
+
242
+ end SharpTerminalLeave
243
+ end
244
+ end
245
+
246
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/ActiveCavityFactorProduct.lean ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.TriangleHypergraphReindex
3
+ import OAI.Combinatorics.TriangleRemoval.Stability.CavityWeight
4
+ import OAI.Combinatorics.TriangleRemoval.Process.PathRequired
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ open scoped BigOperators Topology Matrix.Norms.Operator
10
+ open MeasureTheory
11
+ open scoped BigOperators
12
+ open scoped BigOperators ENNReal Classical
13
+ open Filter MeasureTheory
14
+ open scoped BigOperators Topology
15
+ open Filter
16
+
17
+ namespace SharpTerminalLeave
18
+
19
+ lemma active_cavity_factor_product {n : ℕ} (G : Graph n) (e : G) (T : triangles G) (t : ℝ) :
20
+ (∏ f ∈ (triangleHypergraph G T.val).erase e.val,
21
+ cavityLimit (triangleHypergraph G) f (some T.val) t) =
22
+ ∏ f ∈ (activeHypergraph G T).erase e, cavityLimit (activeHypergraph G) f (some T) t := by
23
+ change (∏ f ∈ (triangleHypergraph G (triangleEmbedding G T)).erase (edgeEmbedding G e), _) = _
24
+ rw [triangleHypergraph_reindex,← Finset.map_erase,Finset.prod_map]
25
+ apply Finset.prod_congr rfl
26
+ intro f _
27
+ exact active_cavity_eq G f (some T) t
28
+
29
+ lemma active_messageIntegral {n : ℕ} (G : Graph n) (e : G) (T : triangles G) (t : ℝ) :
30
+ messageIntegral (triangleHypergraph G) (cavityLimit (triangleHypergraph G)) e.val T.val t =
31
+ messageIntegral (activeHypergraph G) (cavityLimit (activeHypergraph G)) e T t := by
32
+ unfold messageIntegral
33
+ apply intervalIntegral.integral_congr
34
+ intro s _
35
+ exact active_cavity_factor_product G e T s
36
+
37
+ lemma goodPrefix_full_continuous_rows {c : ℝ} (hc : 0 < c) :
38
+ ∀ᶠ n : ℕ in atTop, 0 < prefixD n ∧
39
+ ∀ (C : ℝ) (G : Graph n), GoodPrefixGraph n c C G →
40
+ ∀ t ∈ Set.Icc (0 : ℝ) 1, ∀ (e T : Finset (Fin n)), e ∈ triangleHypergraph G T →
41
+ messageIntegral (triangleHypergraph G) (cavityLimit (triangleHypergraph G)) e T t ≤ 1/16 ∧
42
+ (∏ f ∈ (triangleHypergraph G T).erase e,
43
+ cavityLimit (triangleHypergraph G) f (some T) t) ≤
44
+ (17/16 : ℝ)*cavityWeight (prefixD n) t := by
45
+ filter_upwards [goodPrefix_continuous_rows hc] with n hn
46
+ refine ⟨hn.1,?_⟩
47
+ intro C G hG t ht e T he
48
+ have heG := triangleHypergraph_subset G T he
49
+ have hT : T ∈ triangles G := by
50
+ by_contra hT
51
+ simp only [triangleHypergraph,hT,ite_false,Finset.notMem_empty] at he
52
+ let ee : G := ⟨e,heG⟩
53
+ let TT : triangles G := ⟨T,hT⟩
54
+ have heact : ee ∈ activeHypergraph G TT := by
55
+ have hh : edgeEmbedding G ee ∈ (activeHypergraph G TT).map (edgeEmbedding G) := by
56
+ rw [← triangleHypergraph_reindex]
57
+ exact he
58
+ exact Finset.mem_map.mp hh |>.elim (fun _ ha => (edgeEmbedding G).injective ha.2 ▸ ha.1)
59
+ obtain ⟨h1,h2⟩ := hn.2 C G hG t ht
60
+ rw [show e = ee.val from rfl,show T = TT.val from rfl,
61
+ active_messageIntegral,active_cavity_factor_product]
62
+ exact ⟨h1 ee TT heact,h2 ee TT heact⟩
63
+
64
+ theorem goodPrefix_full_grid_rows {c : ℝ} (hc : 0 < c) :
65
+ ∀ᶠ n : ℕ in atTop, ∀ (C : ℝ) (G : Graph n), GoodPrefixGraph n c C G →
66
+ ∃ N₀ : ℕ, ∀ (N : ℕ) [NeZero N], N₀ ≤ N →
67
+ GridRowQuality (triangleHypergraph G) N
68
+ (fun k => cavityWeight (prefixD n) ((k : ℝ)/N)) := by
69
+ filter_upwards [goodPrefix_full_continuous_rows hc] with n hn
70
+ intro C G h
71
+ let H := triangleHypergraph G
72
+ let A : ℝ := (Fintype.card (Finset (Fin n)) : ℝ)*gridUniformError H +
73
+ (Fintype.card (Finset (Fin n)) : ℝ)*Fintype.card (Finset (Fin n))
74
+ let B : ℝ := 2*gridUniformError H
75
+ have hA : Tendsto (fun N : ℕ => A/(N : ℝ)) atTop (𝓝 0) :=
76
+ tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop (R := ℝ))
77
+ have hB : Tendsto (fun N : ℕ => B/(N : ℝ)) atTop (𝓝 0) :=
78
+ tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop (R := ℝ))
79
+ have hsmall : ∀ᶠ N : ℕ in atTop, A/(N : ℝ) ≤ 1/16 ∧
80
+ B/(N : ℝ) ≤ cavityWeight (prefixD n) 1/16 := by
81
+ filter_upwards [hA.eventually_le_const (by norm_num : (0 : ℝ) < 1/16),
82
+ hB.eventually_le_const (show 0 < cavityWeight (prefixD n) 1/16 from
83
+ div_pos (cavityWeight_pos hn.1.le zero_le_one) (by norm_num))]
84
+ with N ha hb
85
+ exact ⟨ha,hb⟩
86
+ obtain ⟨N₀,hN₀⟩ := eventually_atTop.mp hsmall
87
+ refine ⟨N₀,?_⟩
88
+ intro N _ hN
89
+ have hNpos : (0 : ℝ) < N := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne N)
90
+ have ht (k : ℕ) (hk : k ≤ N) : (k : ℝ)/N ∈ Set.Icc (0 : ℝ) 1 :=
91
+ ⟨by positivity,(div_le_one hNpos).mpr (by exact_mod_cast hk)⟩
92
+ obtain ⟨ha,hb⟩ := hN₀ N hN
93
+ constructor
94
+ · intro k hk e T he
95
+ obtain ⟨hi,_⟩ := hn.2 C G h _ (ht k hk) e T he
96
+ have herr := gridCandidateFailure_error H N k hk e T
97
+ change |gridCandidateFailure H N k e T - _| ≤ A/(N : ℝ) at herr
98
+ have hh := (abs_le.mp herr).1
99
+ dsimp only [H] at hh
100
+ linarith
101
+ · intro k hk e T he
102
+ obtain ⟨_,hp⟩ := hn.2 C G h _ (ht k hk) e T he
103
+ have hT : T ∈ triangles G := by
104
+ by_contra hh
105
+ simp only [triangleHypergraph,hh,ite_false,Finset.notMem_empty] at he
106
+ have hcard : ((H T).erase e).card = 2 := by
107
+ rw [Finset.card_erase_of_mem he]
108
+ simp only [triangleHypergraph,hT,ite_true,Finset.card_powersetCard,(mem_triangles.mp hT).1]
109
+ decide
110
+ have herr := gridAnswer_uniform_error H N k hk ((H T).erase e) (some T)
111
+ rw [hcard] at herr
112
+ have herr' := (abs_le.mp herr).2
113
+ have hbl := cavityWeight_lower hn.1.le (ht k hk)
114
+ dsimp only [B,H] at hb herr'
115
+ linarith
116
+
117
+ end SharpTerminalLeave
118
+
119
+ open scoped BigOperators Topology Matrix.Norms.Operator
120
+ open MeasureTheory
121
+ open scoped BigOperators
122
+ open scoped BigOperators ENNReal Classical
123
+ open Filter MeasureTheory
124
+ open scoped BigOperators Topology
125
+ open Filter
126
+
127
+ end
128
+
129
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/CavityGenerator.lean ADDED
@@ -0,0 +1,361 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Coupling.UnitTime
3
+ import OAI.Combinatorics.TriangleRemoval.Process.TripleFactorBounds
4
+ import OAI.Combinatorics.TriangleRemoval.Process.VariationConstants
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ open scoped BigOperators Topology Matrix.Norms.Operator
10
+ open MeasureTheory
11
+ open Filter
12
+ open scoped BigOperators Topology
13
+
14
+ section
15
+ open scoped BigOperators Topology BoundedContinuousFunction
16
+ open scoped BigOperators
17
+ open Filter MeasureTheory
18
+ open scoped Topology
19
+
20
+ namespace SharpTerminalLeave
21
+ section CavityStability
22
+ variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ]
23
+
24
+ noncomputable def cavityGenerator (H : τ → Finset ι) (D : ℝ) :
25
+ (ι → ℝ) →L[ℝ] (ι → ℝ) :=
26
+ ContinuousLinearMap.pi fun e => (1 / D) •
27
+ ∑ T ∈ messageCandidates H e none, ∑ f ∈ (H T).erase e, ContinuousLinearMap.proj f
28
+
29
+ omit [Fintype ι] in
30
+ @[simp] theorem cavityGenerator_apply (H : τ → Finset ι) (D : ℝ) (z : ι → ℝ) (e : ι) :
31
+ cavityGenerator H D z e = (1 / D) *
32
+ ∑ T ∈ messageCandidates H e none, ∑ f ∈ (H T).erase e, z f := by
33
+ simp [cavityGenerator]
34
+
35
+ noncomputable def cavityVelocity (H : τ → Finset ι) (D : ℝ) (s : ℝ) (e : ι) : ℝ :=
36
+ 1 - Real.exp (2 * s) / D * ∑ T ∈ messageCandidates H e none,
37
+ (∏ f ∈ (H T).erase e, cavityLimit H f (some T) (cavityTime D s)) /
38
+ (1 - cavityMessage H D e T s)
39
+
40
+ noncomputable def cavityResidual (H : τ → Finset ι) (D : ℝ) (s : ℝ) : ι → ℝ :=
41
+ cavityVelocity H D s + cavityGenerator H D (fun e => cavityLog H D e s)
42
+
43
+ theorem cavityMessage_derivative_bound (H : τ → Finset ι) {D δ s : ℝ}
44
+ (hD : 0 < D) (hδ : δ ≤ 1 / 2) (hcard : ∀ T, (H T).card = 3)
45
+ (hz : ∀ f, |cavityLog H D f s| ≤ δ)
46
+ (hI : ∀ f T, f ∈ H T → cavityMessage H D f T s ≤ 1 / 2)
47
+ (ht : cavityTime D s ∈ Set.Ioo (0 : ℝ) 1) (e : ι) (T : τ) (he : e ∈ H T) :
48
+ deriv (cavityMessage H D e T) s ≤ 12 / D := by
49
+ rw [(cavityMessage_hasDerivAt H D e T ht).deriv]
50
+ obtain ⟨f, g, hfg, hset, hf, hg⟩ := triangle_children (hcard T) he
51
+ have heq := cavity_triangle_message_summand H D e T hfg hset hf hg ht.2
52
+ have hprod : 1 / 4 ≤ (1 - cavityMessage H D f T s) * (1 - cavityMessage H D g T s) := by
53
+ have h1 : 1 / 2 ≤ 1 - cavityMessage H D f T s := by linarith [hI f T hf]
54
+ have h2 : 1 / 2 ≤ 1 - cavityMessage H D g T s := by linarith [hI g T hg]
55
+ nlinarith [mul_le_mul h1 h2 (by norm_num : (0 : ℝ) ≤ 1 / 2) (by linarith)]
56
+ have he2 : Real.exp (cavityLog H D f s + cavityLog H D g s) ≤ 3 := by
57
+ apply (Real.exp_le_exp.mpr (show cavityLog H D f s + cavityLog H D g s ≤ 1 from
58
+ by linarith [(abs_le.mp (hz f)).2, (abs_le.mp (hz g)).2])).trans
59
+ exact Real.exp_one_lt_d9.le.trans (by norm_num)
60
+ have hb : Real.exp (2 * s) *
61
+ (∏ u ∈ (H T).erase e, cavityLimit H u (some T) (cavityTime D s)) ≤ 12 := by
62
+ rw [heq]
63
+ apply (div_le_iff₀ (by linarith : 0 <
64
+ (1 - cavityMessage H D f T s) * (1 - cavityMessage H D g T s))).mpr
65
+ linarith
66
+ calc
67
+ _ = (Real.exp (2 * s) *
68
+ ∏ u ∈ (H T).erase e, cavityLimit H u (some T) (cavityTime D s)) / D := by ring
69
+ _ ≤ _ := div_le_div_of_nonneg_right hb hD.le
70
+
71
+ theorem cavityMessage_bound (H : τ → Finset ι) {D δ s : ℝ}
72
+ (hD : 0 < D) (hs : 0 ≤ s) (hδ : δ ≤ 1 / 2) (hcard : ∀ T, (H T).card = 3)
73
+ (hz : ∀ u ∈ Set.Icc 0 s, ∀ f, |cavityLog H D f u| ≤ δ)
74
+ (hI : ∀ u ∈ Set.Icc 0 s, ∀ f T, f ∈ H T → cavityMessage H D f T u ≤ 1 / 2)
75
+ (ht : cavityTime D s < 1) (e : ι) (T : τ) (he : e ∈ H T) :
76
+ cavityMessage H D e T s ≤ 12 * s / D := by
77
+ have hi : ∀ u ∈ Set.Ioo 0 s, cavityTime D u ∈ Set.Ioo (0 : ℝ) 1 := by
78
+ intro u hu
79
+ exact ⟨cavityTime_pos hD hu.1, (cavityTime_mono hD hu.2.le).trans_lt ht⟩
80
+ have hh := (convex_Icc (0 : ℝ) s).image_sub_le_mul_sub_of_deriv_le
81
+ (continuous_cavityMessage H D e T).continuousOn
82
+ (fun u hu => ((cavityMessage_hasDerivAt H D e T (hi u (by simpa using hu))).differentiableAt).differentiableWithinAt)
83
+ (C := 12 / D) (fun u hu => by
84
+ have hu' : u ∈ Set.Ioo 0 s := by simpa only [interior_Icc] using hu
85
+ exact cavityMessage_derivative_bound H hD hδ hcard
86
+ (hz u ⟨hu'.1.le, hu'.2.le⟩) (hI u ⟨hu'.1.le, hu'.2.le⟩) (hi u hu') e T he)
87
+ 0 ⟨le_rfl, hs⟩ s ⟨hs, le_rfl⟩ hs
88
+ simpa only [cavityMessage_zero, sub_zero, div_mul_eq_mul_div] using hh
89
+
90
+ theorem cavityResidual_bound (H : τ → Finset ι) {D δ ε η s : ℝ}
91
+ (hD : 0 < D) (hδ : δ ≤ 1 / 2) (hε : 0 ≤ ε) (hε' : ε ≤ 1 / 2) (hη : 0 ≤ η)
92
+ (hcard : ∀ T, (H T).card = 3)
93
+ (hdeg : ∀ e, |((messageCandidates H e none).card : ℝ) / D - 1| ≤ η)
94
+ (hrow : ∀ e, ((messageCandidates H e none).card : ℝ) / D ≤ 2)
95
+ (hz : ∀ e, |cavityLog H D e s| ≤ δ)
96
+ (hI : ∀ e T, e ∈ H T → cavityMessage H D e T s ≤ ε)
97
+ (ht : cavityTime D s < 1) :
98
+ ‖cavityResidual H D s‖ �� η + 64 * δ ^ 2 + 96 * ε := by
99
+ apply (pi_norm_le_iff_of_nonneg (by positivity)).mpr
100
+ intro e
101
+ let R : τ → ℝ := fun T => Real.exp (2 * s) *
102
+ ((∏ f ∈ (H T).erase e, cavityLimit H f (some T) (cavityTime D s)) /
103
+ (1 - cavityMessage H D e T s))
104
+ let L : τ → ℝ := fun T => ∑ f ∈ (H T).erase e, cavityLog H D f s
105
+ have hres : cavityResidual H D s e =
106
+ 1 - (1 / D) * (∑ T ∈ messageCandidates H e none, R T) +
107
+ (1 / D) * (∑ T ∈ messageCandidates H e none, L T) := by
108
+ simp only [cavityResidual, Pi.add_apply, cavityVelocity, cavityGenerator_apply, R, L,
109
+ ← Finset.mul_sum]
110
+ ring
111
+ rw [Real.norm_eq_abs, hres]
112
+ have hb := cavity_row_error (messageCandidates H e none) R L hD
113
+ (show 0 ≤ 32 * δ ^ 2 + 48 * ε by positivity) (hdeg e) (hrow e) (by
114
+ intro T hT
115
+ have he : e ∈ H T := (Finset.mem_filter.mp hT).2.1
116
+ obtain ⟨f, g, hfg, hset, hf, hg⟩ := triangle_children (hcard T) he
117
+ have hR := cavity_triangle_summand H D e T hfg hset hf hg ht
118
+ have hL : L T = cavityLog H D f s + cavityLog H D g s := by
119
+ simp only [L, hset, Finset.sum_pair hfg]
120
+ dsimp only [R]
121
+ rw [hR, hL]
122
+ convert cavity_summand_taylor hδ (hz f) (hz g) hε'
123
+ ⟨cavityMessage_nonneg H D e T s, hI e T he⟩
124
+ ⟨cavityMessage_nonneg H D f T s, hI f T hf⟩
125
+ ⟨cavityMessage_nonneg H D g T s, hI g T hg⟩ using 1
126
+ congr 1
127
+ ring)
128
+ nlinarith
129
+
130
+ theorem continuousOn_cavityVelocity (H : τ → Finset ι) {D S : ℝ}
131
+ (hD : 0 < D) (hS : cavityTime D S < 1) :
132
+ ContinuousOn (cavityVelocity H D) (Set.Icc 0 S) := by
133
+ apply continuousOn_pi.mpr
134
+ intro e
135
+ unfold cavityVelocity
136
+ apply continuousOn_const.sub
137
+ apply ContinuousOn.mul
138
+ · exact ((Real.continuous_exp.comp (continuous_const.mul continuous_id)).div_const D).continuousOn
139
+ · apply continuousOn_finsetSum
140
+ intro T _
141
+ apply ContinuousOn.div
142
+ · apply continuousOn_finsetProd
143
+ intro f _
144
+ exact ((continuous_cavityLimit H f (some T)).comp (continuous_cavityTime D)).continuousOn
145
+ · exact continuousOn_const.sub (continuous_cavityMessage H D e T).continuousOn
146
+ · intro s hs
147
+ exact (cavityLimit_factor_pos H e T ((cavityTime_mono hD hs.2).trans_lt hS)).ne'
148
+
149
+ theorem continuousOn_cavityLog_vector (H : τ → Finset ι) {D S : ℝ}
150
+ (hD : 0 < D) (hS : cavityTime D S < 1) :
151
+ ContinuousOn (fun s e => cavityLog H D e s) (Set.Icc 0 S) :=
152
+ continuousOn_pi.mpr (continuousOn_cavityLog H hD hS)
153
+
154
+ theorem continuousOn_cavityResidual (H : τ → Finset ι) {D S : ℝ}
155
+ (hD : 0 < D) (hS : cavityTime D S < 1) :
156
+ ContinuousOn (cavityResidual H D) (Set.Icc 0 S) :=
157
+ (continuousOn_cavityVelocity H hD hS).add
158
+ ((cavityGenerator H D).continuous.comp_continuousOn (continuousOn_cavityLog_vector H hD hS))
159
+
160
+ theorem cavityLog_provisional_bound (H : τ → Finset ι) {D δ η K s : ℝ}
161
+ (hD : 0 < D) (hs : 0 ≤ s) (hδ : δ ≤ 1 / 2) (hη : 0 ≤ η) (hK : 0 ≤ K)
162
+ (hcard : ∀ T, (H T).card = 3)
163
+ (hdeg : ∀ e, |((messageCandidates H e none).card : ℝ) / D - 1| ≤ η)
164
+ (hrow : ∀ e, ((messageCandidates H e none).card : ℝ) / D ≤ 2)
165
+ (hz : ∀ u ∈ Set.Icc 0 s, ∀ e, |cavityLog H D e u| ≤ δ)
166
+ (hI : ∀ u ∈ Set.Icc 0 s, ∀ e T, e ∈ H T → cavityMessage H D e T u ≤ 1 / 2)
167
+ (ht : cavityTime D s < 1) (hsmall : 12 * s / D ≤ 1 / 2)
168
+ (hsem : ∀ u ∈ Set.Icc 0 s, ‖NormedSpace.exp ((-u) • cavityGenerator H D)‖ ≤ K) :
169
+ ‖fun e => cavityLog H D e s‖ ≤ K * (η + 64 * δ ^ 2 + 1152 * s / D) * s := by
170
+ have hi : ∀ u ∈ Set.Icc 0 s, ∀ e T, e ∈ H T →
171
+ cavityMessage H D e T u ≤ 12 * s / D := by
172
+ intro u hu e T he
173
+ apply (cavityMessage_bound H hD hu.1 hδ hcard
174
+ (fun v hv => hz v ⟨hv.1, hv.2.trans hu.2⟩)
175
+ (fun v hv => hI v ⟨hv.1, hv.2.trans hu.2⟩)
176
+ ((cavityTime_mono hD hu.2).trans_lt ht) e T he).trans
177
+ exact div_le_div_of_nonneg_right (by linarith [hu.2]) hD.le
178
+ have hh := forcing_norm_bound (cavityGenerator H D)
179
+ (fun u e => cavityLog H D e u) (cavityResidual H D) hs hK
180
+ (continuousOn_cavityLog_vector H hD ht) (continuousOn_cavityResidual H hD ht)
181
+ (funext (cavityLog_zero H D)) (by
182
+ intro u hu
183
+ apply hasDerivAt_pi.mpr
184
+ intro e
185
+ convert cavityLog_hasDerivAt H D e
186
+ ⟨cavityTime_pos hD hu.1, (cavityTime_mono hD hu.2.le).trans_lt ht⟩ using 1
187
+ dsimp [cavityResidual, cavityVelocity]
188
+ ring) hsem (d := η + 64 * δ ^ 2 + 1152 * s / D) (by
189
+ intro u hu
190
+ have hr := cavityResidual_bound H hD hδ (by positivity : 0 ≤ 12 * s / D)
191
+ hsmall hη hcard hdeg hrow (hz u hu) (hi u hu)
192
+ ((cavityTime_mono hD hu.2).trans_lt ht)
193
+ convert hr using 1
194
+ ring)
195
+ exact hh
196
+
197
+ noncomputable def cavityIncidentMessages (H : τ → Finset ι) (D s : ℝ) : ι × τ → ℝ :=
198
+ fun p => if p.1 ∈ H p.2 then cavityMessage H D p.1 p.2 s else 0
199
+
200
+ theorem continuous_cavityIncidentMessages (H : τ → Finset ι) (D : ℝ) :
201
+ Continuous (cavityIncidentMessages H D) := by
202
+ apply continuous_pi
203
+ intro p
204
+ by_cases hp : p.1 ∈ H p.2
205
+ · simpa only [cavityIncidentMessages, ite_eq_left hp] using continuous_cavityMessage H D p.1 p.2
206
+ · simpa only [cavityIncidentMessages, ite_eq_right hp] using (continuous_const : Continuous (fun _ : ℝ => (0 : ℝ)))
207
+
208
+ @[simp] theorem cavityIncidentMessages_zero (H : τ → Finset ι) (D : ℝ) :
209
+ cavityIncidentMessages H D 0 = 0 := by
210
+ ext p
211
+ simp [cavityIncidentMessages]
212
+
213
+ theorem cavityIncidentMessages_norm_iff (H : τ → Finset ι) (D s b : ℝ) (hb : 0 ≤ b) :
214
+ ‖cavityIncidentMessages H D s‖ ≤ b ↔
215
+ ∀ e T, e ∈ H T → cavityMessage H D e T s ≤ b := by
216
+ rw [pi_norm_le_iff_of_nonneg hb]
217
+ constructor
218
+ · intro hh e T he
219
+ simpa only [cavityIncidentMessages, ite_eq_left he, Real.norm_eq_abs,
220
+ abs_of_nonneg (cavityMessage_nonneg H D e T s)] using hh (e, T)
221
+ · intro hh p
222
+ by_cases hp : p.1 ∈ H p.2
223
+ · simpa only [cavityIncidentMessages, ite_eq_left hp, Real.norm_eq_abs,
224
+ abs_of_nonneg (cavityMessage_nonneg H D p.1 p.2 s)] using hh p.1 p.2 hp
225
+ · simpa only [cavityIncidentMessages, ite_eq_right hp, norm_zero] using hb
226
+
227
+ theorem cavity_strict_continuation (H : τ → Finset ι) {D S δ η K : ℝ}
228
+ (hD : 0 < D) (hS : 0 ≤ S) (hδ : 0 < δ) (hδ' : δ ≤ 1 / 2)
229
+ (hη : 0 ≤ η) (hK : 0 ≤ K) (hcard : ∀ T, (H T).card = 3)
230
+ (hdeg : ∀ e, |((messageCandidates H e none).card : ℝ) / D - 1| ≤ η)
231
+ (hrow : ∀ e, ((messageCandidates H e none).card : ℝ) / D ≤ 2)
232
+ (ht : cavityTime D S < 1)
233
+ (hsmall : 12 * S / D ≤ 1 / 4)
234
+ (himprove : K * (η + 64 * δ ^ 2 + 1152 * S / D) * S ≤ δ / 2)
235
+ (hsem : ∀ u ∈ Set.Icc 0 S, ‖NormedSpace.exp ((-u) • cavityGenerator H D)‖ ≤ K) :
236
+ ∀ s ∈ Set.Icc 0 S,
237
+ (∀ e, |cavityLog H D e s| ≤ δ / 2) ∧
238
+ (∀ e T, e ∈ H T → cavityMessage H D e T s ≤ 12 * s / D) := by
239
+ let Q : ℝ → ℝ := fun s => max (‖fun e => cavityLog H D e s‖ / δ)
240
+ (2 * ‖cavityIncidentMessages H D s‖)
241
+ have hQ : ContinuousOn Q (Set.Icc 0 S) :=
242
+ ((continuousOn_cavityLog_vector H hD ht).norm.div_const δ).sup
243
+ (continuousOn_const.mul (continuous_cavityIncidentMessages H D).continuousOn.norm)
244
+ have hzero : Q 0 ≤ 1 := by
245
+ simp only [Q, cavityLog_zero, show (fun _ : ι => (0 : ℝ)) = 0 from rfl,
246
+ norm_zero, zero_div, cavityIncidentMessages_zero, mul_zero, max_self, zero_le_one]
247
+ have hdecode : ∀ s, Q s ≤ 1 →
248
+ (∀ e, |cavityLog H D e s| ≤ δ) ∧
249
+ (∀ e T, e ∈ H T → cavityMessage H D e T s ≤ 1 / 2) := by
250
+ intro s hh
251
+ have hm := max_le_iff.mp hh
252
+ constructor
253
+ · have hb : ‖fun e => cavityLog H D e s‖ ≤ δ := by
254
+ exact (div_le_one hδ).mp hm.1
255
+ simpa only [Real.norm_eq_abs] using (pi_norm_le_iff_of_nonneg hδ.le).mp hb
256
+ · apply (cavityIncidentMessages_norm_iff H D s _ (by norm_num)).mp
257
+ linarith [hm.2]
258
+ have hboot : ∀ s ∈ Set.Icc 0 S, Q s ≤ 1 / 2 := by
259
+ apply strict_bootstrap (δ := 1) (by norm_num) hQ hzero
260
+ intro s hs hp
261
+ have hz := fun u hu => (hdecode u (hp u hu)).1
262
+ have hI := fun u hu => (hdecode u (hp u hu)).2
263
+ have ht' : cavityTime D s < 1 := (cavityTime_mono hD hs.2).trans_lt ht
264
+ have hsmall' : 12 * s / D ≤ 1 / 4 :=
265
+ (div_le_div_of_nonneg_right (by linarith [hs.2]) hD.le).trans hsmall
266
+ apply max_le_iff.mpr
267
+ constructor
268
+ · apply (div_le_iff₀ hδ).mpr
269
+ have hh := cavityLog_provisional_bound H hD hs.1 hδ' hη hK hcard hdeg hrow hz hI
270
+ ht' (by linarith) (fun u hu => hsem u ⟨hu.1, hu.2.trans hs.2⟩)
271
+ have hforce : η + 64 * δ ^ 2 + 1152 * s / D ≤ η + 64 * δ ^ 2 + 1152 * S / D := by
272
+ have := div_le_div_of_nonneg_right (by linarith [hs.2] : 1152 * s ≤ 1152 * S) hD.le
273
+ linarith
274
+ have hcmp : K * (η + 64 * δ ^ 2 + 1152 * s / D) * s ≤
275
+ K * (η + 64 * δ ^ 2 + 1152 * S / D) * S := by
276
+ apply mul_le_mul (mul_le_mul_of_nonneg_left hforce hK) hs.2 hs.1
277
+ positivity
278
+ linarith [hh.trans hcmp, himprove]
279
+ · have hm : ‖cavityIncidentMessages H D s‖ ≤ 12 * s / D := by
280
+ apply (cavityIncidentMessages_norm_iff H D s _
281
+ (div_nonneg (mul_nonneg (by norm_num) hs.1) hD.le)).mpr
282
+ exact cavityMessage_bound H hD hs.1 hδ' hcard hz hI ht'
283
+ linarith
284
+ intro s hs
285
+ have hpre : ∀ u ∈ Set.Icc 0 s, Q u ≤ 1 := fun u hu =>
286
+ (hboot u ⟨hu.1, hu.2.trans hs.2⟩).trans (by norm_num)
287
+ constructor
288
+ · have hh := (max_le_iff.mp (hboot s hs)).1
289
+ have hn : ‖fun e => cavityLog H D e s‖ ≤ δ / 2 := by
290
+ have := (div_le_iff₀ hδ).mp hh
291
+ linarith
292
+ simpa only [Real.norm_eq_abs] using (pi_norm_le_iff_of_nonneg (by positivity)).mp hn
293
+ · exact cavityMessage_bound H hD hs.1 hδ' hcard
294
+ (fun u hu => (hdecode u (hpre u hu)).1)
295
+ (fun u hu => (hdecode u (hpre u hu)).2)
296
+ ((cavityTime_mono hD hs.2).trans_lt ht)
297
+
298
+ omit [Fintype ι] [Fintype τ] [DecidableEq ��] [DecidableEq τ] in
299
+ theorem cavityTime_strictMono {D : ℝ} (hD : 0 < D) : StrictMono (cavityTime D) := by
300
+ intro s t hst
301
+ apply div_lt_div_of_pos_right _ (by positivity)
302
+ exact sub_lt_sub_right (Real.exp_lt_exp.mpr (by linarith)) _
303
+
304
+ theorem cavity_closed_continuation (H : τ → Finset ι) {D S δ η K : ℝ}
305
+ (hD : 0 < D) (hS : 0 < S) (hδ : 0 < δ) (hδ' : δ ≤ 1 / 2)
306
+ (hη : 0 ≤ η) (hK : 0 ≤ K) (hcard : ∀ T, (H T).card = 3)
307
+ (hdeg : ∀ e, |((messageCandidates H e none).card : ℝ) / D - 1| ≤ η)
308
+ (hrow : ∀ e, ((messageCandidates H e none).card : ℝ) / D ≤ 2)
309
+ (ht : cavityTime D S ≤ 1)
310
+ (hsmall : 12 * S / D ≤ 1 / 4)
311
+ (himprove : K * (η + 64 * δ ^ 2 + 1152 * S / D) * S ≤ δ / 2)
312
+ (hsem : ∀ u ∈ Set.Icc 0 S, ‖NormedSpace.exp ((-u) • cavityGenerator H D)‖ ≤ K) :
313
+ ∀ s ∈ Set.Icc 0 S,
314
+ (∀ e, Real.exp (-s - δ / 2) ≤ cavityLimit H e none (cavityTime D s) ∧
315
+ cavityLimit H e none (cavityTime D s) ≤ Real.exp (-s + δ / 2)) ∧
316
+ (∀ e T, e ∈ H T → cavityMessage H D e T s ≤ 12 * s / D) := by
317
+ have hpre : ∀ s ∈ Set.Ico 0 S,
318
+ (∀ e, Real.exp (-s - δ / 2) ≤ cavityLimit H e none (cavityTime D s) ∧
319
+ cavityLimit H e none (cavityTime D s) ≤ Real.exp (-s + δ / 2)) ∧
320
+ (∀ e T, e ∈ H T → cavityMessage H D e T s ≤ 12 * s / D) := by
321
+ intro s hs
322
+ have ht' : cavityTime D s < 1 := (cavityTime_strictMono hD hs.2).trans_le ht
323
+ have hsmall' : 12 * s / D ≤ 1 / 4 :=
324
+ (div_le_div_of_nonneg_right (by linarith [hs.2]) hD.le).trans hsmall
325
+ have hforce : η + 64 * δ ^ 2 + 1152 * s / D ≤ η + 64 * δ ^ 2 + 1152 * S / D := by
326
+ linarith [div_le_div_of_nonneg_right (by linarith [hs.2] : 1152 * s ≤ 1152 * S) hD.le]
327
+ have hcmp : K * (η + 64 * δ ^ 2 + 1152 * s / D) * s ≤
328
+ K * (η + 64 * δ ^ 2 + 1152 * S / D) * S := by
329
+ apply mul_le_mul (mul_le_mul_of_nonneg_left hforce hK) hs.2.le hs.1
330
+ positivity
331
+ have hh := cavity_strict_continuation H hD hs.1 hδ hδ' hη hK hcard hdeg hrow ht'
332
+ hsmall' (hcmp.trans himprove) (fun u hu => hsem u ⟨hu.1, hu.2.trans hs.2.le⟩) s ⟨hs.1, le_rfl⟩
333
+ refine ⟨?_, hh.2⟩
334
+ intro e
335
+ rw [cavityLog_exp H D e ht']
336
+ constructor <;> apply Real.exp_le_exp.mpr <;> linarith [(abs_le.mp (hh.1 e)).1, (abs_le.mp (hh.1 e)).2]
337
+ have hclose {P : ℝ → Prop} (hp : IsClosed {s | P s})
338
+ (hh : ∀ s ∈ Set.Ico 0 S, P s) : ∀ s ∈ Set.Icc 0 S, P s := by
339
+ have hx : closure (Set.Ico 0 S) ⊆ {s | P s} := closure_minimal hh hp
340
+ simpa only [closure_Ico hS.ne, Set.subset_def, Set.mem_ofPred_eq] using hx
341
+ intro s hs
342
+ constructor
343
+ · intro e
344
+ have hc := (continuous_cavityLimit H e none).comp (continuous_cavityTime D)
345
+ constructor
346
+ · exact hclose (isClosed_le (Real.continuous_exp.comp
347
+ (continuous_id.neg.sub continuous_const)) hc) (fun u hu => (hpre u hu).1 e |>.1) s hs
348
+ · exact hclose (isClosed_le hc (Real.continuous_exp.comp
349
+ (continuous_id.neg.add continuous_const))) (fun u hu => (hpre u hu).1 e |>.2) s hs
350
+ · intro e T he
351
+ exact hclose (isClosed_le (continuous_cavityMessage H D e T)
352
+ ((continuous_const.mul continuous_id).div_const D)) (fun u hu => (hpre u hu).2 e T he) s hs
353
+
354
+ end CavityStability
355
+ end SharpTerminalLeave
356
+
357
+ end
358
+
359
+ end
360
+
361
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/CavityReference.lean ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.IncidentTriangleThird
3
+ import OAI.Combinatorics.TriangleRemoval.Process.ActivePairMembership
4
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixHorizon
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ open scoped BigOperators Topology Matrix.Norms.Operator
10
+ open MeasureTheory
11
+ open Filter
12
+ open scoped BigOperators Topology
13
+
14
+ namespace SharpTerminalLeave
15
+
16
+ lemma goodPrefix_active_degree {n : ℕ} {c C : ℝ} {G : Graph n}
17
+ (h : GoodPrefixGraph n c C G) (hD : 0 < prefixD n) (e : G) :
18
+ |((messageCandidates (activeHypergraph G) e none).card : ℝ)/prefixD n-1| ≤
19
+ (n : ℝ)^(-c) := by
20
+ classical
21
+ rw [active_messageCandidates_card]
22
+ obtain ⟨u,v,huv,hev⟩ := Finset.card_eq_two.mp (mem_completeGraph.mp (h.1 e.property))
23
+ have heG : ({u,v} : Finset (Fin n)) ∈ G := hev ▸ e.property
24
+ rw [hev,triangleDegree_eq_codegree h.1 heG]
25
+ have hcode := h.2.2.2.1 u v huv
26
+ have heq : (currentCodegree G u v : ℝ)/prefixD n-1 =
27
+ ((currentCodegree G u v : ℝ)-prefixD n)/prefixD n := by
28
+ rw [sub_div,div_self hD.ne']
29
+ rw [heq,abs_div,abs_of_pos hD]
30
+ exact (div_le_iff₀ hD).mpr hcode
31
+
32
+ lemma cavityTime_prefixHorizon {n : ℕ} (hD : 0 < prefixD n) :
33
+ cavityTime (prefixD n) (prefixHorizon n) = 1 := by
34
+ unfold cavityTime prefixHorizon
35
+ rw [show 2*(Real.log (1+2*prefixD n)/2)=Real.log (1+2*prefixD n) by ring,
36
+ Real.exp_log (by linarith : 0 < 1+2*prefixD n)]
37
+ field_simp
38
+ ring
39
+
40
+ theorem goodPrefix_cavity_continuation {c : ℝ} (hc : 0 < c) :
41
+ ∃ a : ℝ, 0 < a ∧ a < min c (1/1000 : ℝ) ∧ ∀ᶠ n : ℕ in atTop,
42
+ ∀ (C : ℝ) (G : Graph n), GoodPrefixGraph n c C G →
43
+ ∀ s ∈ Set.Icc (0 : ℝ) (prefixHorizon n),
44
+ (∀ e : G, Real.exp (-s-(n : ℝ)^(-a)/2) ≤
45
+ cavityLimit (activeHypergraph G) e none (cavityTime (prefixD n) s) ∧
46
+ cavityLimit (activeHypergraph G) e none (cavityTime (prefixD n) s) ≤
47
+ Real.exp (-s+(n : ℝ)^(-a)/2)) ∧
48
+ (∀ (e : G) (T : triangles G), e ∈ activeHypergraph G T →
49
+ cavityMessage (activeHypergraph G) (prefixD n) e T s ≤ 12*s/prefixD n) := by
50
+ obtain ⟨C₁,hC₁,J,hsem⟩ := goodPrefix_cavity_semigroup hc
51
+ obtain ⟨a,ha,hac,hnum⟩ := prefix_bootstrap_numerics hc hC₁ J
52
+ refine ⟨a,ha,hac,?_⟩
53
+ filter_upwards [hsem,hnum,prefix_scales_eventually_pos,eventually_ge_atTop (1 : ℕ)]
54
+ with n hsem hnum hp hn
55
+ intro C G h
56
+ have hD : 0 < prefixD n := lt_of_lt_of_le zero_lt_one hp.2
57
+ have hδc : (n : ℝ)^(-c) ≤ (n : ℝ)^(-a) :=
58
+ Real.rpow_le_rpow_of_exponent_le (by exact_mod_cast hn)
59
+ (by linarith [(lt_min_iff.mp hac).1])
60
+ apply cavity_closed_continuation (activeHypergraph G)
61
+ (K := C₁*(1+Real.log (n : ℝ))^J) hD hnum.2.2.1 hnum.1 hnum.2.1
62
+ (Real.rpow_nonneg (Nat.cast_nonneg n) _) (by positivity)
63
+ (activeHypergraph_card G) (goodPrefix_active_degree h hD)
64
+ · intro e
65
+ have hh := (abs_le.mp (goodPrefix_active_degree h hD e)).2
66
+ linarith [hnum.2.1]
67
+ · exact (cavityTime_prefixHorizon hD).le
68
+ · exact hnum.2.2.2.2.1
69
+ · exact hnum.2.2.2.2.2
70
+ · intro s hs
71
+ exact hsem C G h s ⟨hs.1,hs.2.trans hnum.2.2.2.1⟩
72
+
73
+ noncomputable def cavityReference (D t : ℝ) : ℝ := (1+2*D*t)^(-(1/2 : ℝ))
74
+ noncomputable def cavityClock (D t : ℝ) : ℝ := Real.log (1+2*D*t)/2
75
+
76
+ lemma cavityClock_mem {D t : ℝ} (hD : 0 < D) (ht : t ∈ Set.Icc (0 : ℝ) 1) :
77
+ cavityClock D t ∈ Set.Icc (0 : ℝ) (Real.log (1+2*D)/2) := by
78
+ have harg : 1 ≤ 1+2*D*t := by nlinarith [ht.1]
79
+ have hlo := Real.log_nonneg harg
80
+ have hhi := Real.log_le_log (by linarith : 0 < 1+2*D*t)
81
+ (by nlinarith [ht.2] : 1+2*D*t ≤ 1+2*D)
82
+ exact ⟨by dsimp [cavityClock]; linarith,by dsimp [cavityClock]; linarith⟩
83
+
84
+ lemma cavityTime_clock {D t : ℝ} (hD : 0 < D) (ht : 0 ≤ t) :
85
+ cavityTime D (cavityClock D t) = t := by
86
+ unfold cavityTime cavityClock
87
+ rw [show 2*(Real.log (1+2*D*t)/2)=Real.log (1+2*D*t) by ring,
88
+ Real.exp_log (by nlinarith : 0 < 1+2*D*t)]
89
+ field_simp
90
+ ring
91
+
92
+ lemma cavityReference_exp {D t : ℝ} (hD : 0 < D) (ht : 0 ≤ t) :
93
+ cavityReference D t = Real.exp (-cavityClock D t) := by
94
+ rw [cavityReference,Real.rpow_def_of_pos (by nlinarith : 0 < 1+2*D*t)]
95
+ congr 1
96
+ dsimp [cavityClock]
97
+ ring
98
+
99
+ lemma cavityReference_pos {D t : ℝ} (hD : 0 < D) (ht : 0 ≤ t) :
100
+ 0 < cavityReference D t := by rw [cavityReference_exp hD ht]; positivity
101
+
102
+ theorem goodPrefix_cavity_relative {c : ℝ} (hc : 0 < c) :
103
+ ∃ a : ℝ, 0 < a ∧ ∀ᶠ n : ℕ in atTop,
104
+ let δ := (n : ℝ)^(-a)
105
+ let Imax := 12*prefixHorizon n/prefixD n
106
+ Imax ≤ 1/4 ∧ ∀ (C : ℝ) (G : Graph n), GoodPrefixGraph n c C G →
107
+ ∀ t ∈ Set.Icc (0 : ℝ) 1,
108
+ (∀ e : G, Real.exp (-δ/2) ≤ cavityLimit (activeHypergraph G) e none t /
109
+ cavityReference (prefixD n) t ∧
110
+ cavityLimit (activeHypergraph G) e none t / cavityReference (prefixD n) t ≤
111
+ Real.exp (δ/2)) ∧
112
+ (∀ (e : G) (T : triangles G), e ∈ activeHypergraph G T →
113
+ messageIntegral (activeHypergraph G) (cavityLimit (activeHypergraph G)) e T t ≤ Imax ∧
114
+ Real.exp (-δ/2) ≤ cavityLimit (activeHypergraph G) e (some T) t /
115
+ cavityReference (prefixD n) t ∧
116
+ cavityLimit (activeHypergraph G) e (some T) t / cavityReference (prefixD n) t ≤
117
+ Real.exp (δ/2)/(1-Imax)) := by
118
+ obtain ⟨a,ha,hac,hcont⟩ := goodPrefix_cavity_continuation hc
119
+ obtain ⟨C₁,hC₁,J,_⟩ := goodPrefix_cavity_semigroup hc
120
+ obtain ⟨b,hb,_,hnum⟩ := prefix_bootstrap_numerics hc hC₁ J
121
+ refine ⟨a,ha,?_⟩
122
+ filter_upwards [hcont,hnum,prefix_scales_eventually_pos] with n hcavity hn hp
123
+ dsimp only
124
+ have hD : 0 < prefixD n := lt_of_lt_of_le zero_lt_one hp.2
125
+ have hI : 12*prefixHorizon n/prefixD n ≤ 1/4 := hn.2.2.2.2.1
126
+ refine ⟨hI,?_⟩
127
+ intro C G h t ht
128
+ let s := cavityClock (prefixD n) t
129
+ have hs : s ∈ Set.Icc (0 : ℝ) (prefixHorizon n) := cavityClock_mem hD ht
130
+ have hst : cavityTime (prefixD n) s = t := cavityTime_clock hD ht.1
131
+ obtain ⟨hq,hmsg⟩ := hcavity C G h s hs
132
+ rw [hst] at hq
133
+ have href := cavityReference_exp hD ht.1
134
+ have href0 := cavityReference_pos hD ht.1
135
+ have helo : Real.exp (-s-(n : ℝ)^(-a)/2) =
136
+ Real.exp (-(n : ℝ)^(-a)/2)*cavityReference (prefixD n) t := by
137
+ rw [href,← Real.exp_add]
138
+ congr 1
139
+ dsimp [s]
140
+ ring
141
+ have hehi : Real.exp (-s+(n : ℝ)^(-a)/2) =
142
+ Real.exp ((n : ℝ)^(-a)/2)*cavityReference (prefixD n) t := by
143
+ rw [href,← Real.exp_add]
144
+ congr 1
145
+ dsimp [s]
146
+ ring
147
+ have hroot (e : G) := hq e
148
+ simp only [helo,hehi] at hroot
149
+ constructor
150
+ · intro e
151
+ exact ⟨(le_div_iff₀ href0).mpr (hroot e).1,(div_le_iff₀ href0).mpr (hroot e).2⟩
152
+ · intro e T he
153
+ let I := messageIntegral (activeHypergraph G) (cavityLimit (activeHypergraph G)) e T t
154
+ have hI0 : 0 ≤ I := (messageIntegral_mem_unit _ _ (continuous_cavityLimit _)
155
+ (cavityLimit_mem_unit _) _ _ _).1
156
+ have hIm : I ≤ 12*prefixHorizon n/prefixD n := by
157
+ have hh := hmsg e T he
158
+ change messageIntegral _ _ _ _ (cavityTime (prefixD n) s) ≤ _ at hh
159
+ rw [hst] at hh
160
+ exact hh.trans (div_le_div_of_nonneg_right (by linarith [hs.2]) hD.le)
161
+ have hIf : 0 < 1-I := by linarith
162
+ have hMax : 0 < 1-12*prefixHorizon n/prefixD n := by linarith
163
+ have ho := cavityLimit_omission (activeHypergraph G) e T he t
164
+ change cavityLimit (activeHypergraph G) e none t =
165
+ cavityLimit (activeHypergraph G) e (some T) t * (1-I) at ho
166
+ have hparent : cavityLimit (activeHypergraph G) e (some T) t =
167
+ cavityLimit (activeHypergraph G) e none t/(1-I) := (eq_div_iff hIf.ne').mpr ho.symm
168
+ refine ⟨hIm,?_,?_⟩
169
+ · apply (le_div_iff₀ href0).mpr
170
+ have hpar0 := (cavityLimit_mem_unit (activeHypergraph G) e (some T) t).1
171
+ have hm : cavityLimit (activeHypergraph G) e none t ≤
172
+ cavityLimit (activeHypergraph G) e (some T) t := by rw [ho]; nlinarith
173
+ exact (hroot e).1.trans hm
174
+ · rw [hparent]
175
+ calc
176
+ _ = (cavityLimit (activeHypergraph G) e none t/cavityReference (prefixD n) t)/(1-I) := by ring
177
+ _ ≤ Real.exp ((n : ℝ)^(-a)/2)/(1-12*prefixHorizon n/prefixD n) :=
178
+ div_le_div₀ (by positivity) ((div_le_iff₀ href0).mpr (hroot e).2) hMax (by linarith)
179
+ end SharpTerminalLeave
180
+
181
+ end
182
+
183
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/CavityWeight.lean ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixMessageEnvelopeSmall
3
+ import OAI.Combinatorics.TriangleRemoval.Coupling.GridUniformError
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ open scoped BigOperators Topology Matrix.Norms.Operator
9
+ open MeasureTheory
10
+ open scoped BigOperators
11
+ open scoped BigOperators ENNReal Classical
12
+ open Filter MeasureTheory
13
+ open scoped BigOperators Topology
14
+ open Filter
15
+
16
+ namespace SharpTerminalLeave
17
+
18
+ noncomputable def cavityWeight (D t : ℝ) : ℝ := 1/(1+2*D*t)
19
+
20
+ lemma cavityReference_sq {D t : ℝ} (hD : 0 ≤ D) (ht : 0 ≤ t) :
21
+ cavityReference D t ^ 2 = cavityWeight D t := by
22
+ have hx : 0 ≤ 1+2*D*t := by positivity
23
+ unfold cavityReference cavityWeight
24
+ rw [← Real.rpow_mul_natCast hx]
25
+ norm_num [Real.rpow_neg_one]
26
+
27
+ lemma cavityWeight_pos {D t : ℝ} (hD : 0 ≤ D) (ht : 0 ≤ t) :
28
+ 0 < cavityWeight D t := by unfold cavityWeight; positivity
29
+
30
+ lemma cavityWeight_lower {D t : ℝ} (hD : 0 ≤ D) (ht : t ∈ Set.Icc (0 : ℝ) 1) :
31
+ cavityWeight D 1 ≤ cavityWeight D t := by
32
+ unfold cavityWeight
33
+ have ht0 := ht.1
34
+ apply one_div_le_one_div_of_le
35
+ · positivity
36
+ · nlinarith [ht.2]
37
+
38
+ theorem goodPrefix_continuous_rows {c : ℝ} (hc : 0 < c) :
39
+ ∀ᶠ n : ℕ in atTop, 0 < prefixD n ∧
40
+ ∀ (C : ℝ) (G : Graph n), GoodPrefixGraph n c C G →
41
+ ∀ t ∈ Set.Icc (0 : ℝ) 1,
42
+ (∀ (e : G) (T : triangles G), e ∈ activeHypergraph G T →
43
+ messageIntegral (activeHypergraph G) (cavityLimit (activeHypergraph G)) e T t ≤ 1/16) ∧
44
+ (∀ (e : G) (T : triangles G), e ∈ activeHypergraph G T →
45
+ (∏ f ∈ (activeHypergraph G T).erase e,
46
+ cavityLimit (activeHypergraph G) f (some T) t) ≤
47
+ (17/16 : ℝ)*cavityWeight (prefixD n) t) := by
48
+ obtain ⟨a,ha,hrel⟩ := goodPrefix_cavity_relative hc
49
+ filter_upwards [goodPrefix_cavity_stability hc (by norm_num : (0 : ℝ) < 1/64),
50
+ hrel,prefix_message_envelope_small (by norm_num : (0 : ℝ) < 1/16),
51
+ prefix_scales_eventually_pos] with n hs hr hi hp
52
+ have hD : 0 < prefixD n := lt_of_lt_of_le zero_lt_one hp.2
53
+ refine ⟨hD,?_⟩
54
+ intro C G h t ht
55
+ refine ⟨fun e T he => ((hr.2 C G h t ht).2 e T he).1.trans hi.2,?_⟩
56
+ intro e T he
57
+ have hcard : ((activeHypergraph G T).erase e).card = 2 := by
58
+ rw [Finset.card_erase_of_mem he,activeHypergraph_card]
59
+ have href := cavityReference_pos hD ht.1
60
+ have hprod : (∏ f ∈ (activeHypergraph G T).erase e,
61
+ cavityLimit (activeHypergraph G) f (some T) t) ≤
62
+ ((65/64 : ℝ)*cavityReference (prefixD n) t)^2 := by
63
+ calc
64
+ _ ≤ ∏ _f ∈ (activeHypergraph G T).erase e,
65
+ (65/64 : ℝ)*cavityReference (prefixD n) t := by
66
+ apply Finset.prod_le_prod₀
67
+ · intro f _; exact (cavityLimit_mem_unit _ _ _ _).1
68
+ · intro f hf
69
+ have hh := (abs_le.mp ((hs C G h t ht).2 f T (Finset.mem_of_mem_erase hf))).2
70
+ apply (div_le_iff₀ href).mp
71
+ linarith
72
+ _ = _ := by simp [hcard]
73
+ calc
74
+ _ ≤ ((65/64 : ℝ)*cavityReference (prefixD n) t)^2 := hprod
75
+ _ = (65/64 : ℝ)^2*cavityWeight (prefixD n) t := by
76
+ rw [mul_pow,cavityReference_sq hD.le ht.1]
77
+ _ ≤ _ := mul_le_mul_of_nonneg_right (by norm_num) (cavityWeight_pos hD.le ht.1).le
78
+
79
+ theorem goodPrefix_grid_rows {c : ℝ} (hc : 0 < c) :
80
+ ∀ᶠ n : ℕ in atTop, ∀ (C : ℝ) (G : Graph n), GoodPrefixGraph n c C G →
81
+ ∃ N₀ : ℕ, ∀ (N : ℕ) [NeZero N], N₀ ≤ N → ∀ k ≤ N,
82
+ (∀ (e : G) (T : triangles G), e ∈ activeHypergraph G T →
83
+ (7/8 : ℝ) ≤ gridCandidateFailure (activeHypergraph G) N k e T) ∧
84
+ (∀ (e : G) (T : triangles G), e ∈ activeHypergraph G T →
85
+ gridAnswerProbability (activeHypergraph G) N N k
86
+ ((activeHypergraph G T).erase e) (some T) ≤
87
+ (9/8 : ℝ)*cavityWeight (prefixD n) ((k : ℝ)/N)) := by
88
+ filter_upwards [goodPrefix_continuous_rows hc] with n hn
89
+ intro C G h
90
+ let H := activeHypergraph G
91
+ let A : ℝ := (Fintype.card G : ℝ)*gridUniformError H +
92
+ (Fintype.card G : ℝ)*Fintype.card (triangles G)
93
+ let B : ℝ := 2*gridUniformError H
94
+ have hA : Tendsto (fun N : ℕ => A/(N : ℝ)) atTop (𝓝 0) :=
95
+ tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop (R := ℝ))
96
+ have hB : Tendsto (fun N : ℕ => B/(N : ℝ)) atTop (𝓝 0) :=
97
+ tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop (R := ℝ))
98
+ have hsmall : ∀ᶠ N : ℕ in atTop, A/(N : ℝ) ≤ 1/16 ∧
99
+ B/(N : ℝ) ≤ cavityWeight (prefixD n) 1/16 := by
100
+ filter_upwards [hA.eventually_le_const (by norm_num : (0 : ℝ) < 1/16),
101
+ hB.eventually_le_const (show 0 < cavityWeight (prefixD n) 1/16 from
102
+ div_pos (cavityWeight_pos hn.1.le zero_le_one) (by norm_num))]
103
+ with N ha hb
104
+ exact ⟨ha,hb⟩
105
+ obtain ⟨N₀,hN₀⟩ := eventually_atTop.mp hsmall
106
+ refine ⟨N₀,?_⟩
107
+ intro N _ hN k hk
108
+ have hNpos : (0 : ℝ) < N := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne N)
109
+ have ht : (k : ℝ)/N ∈ Set.Icc (0 : ℝ) 1 :=
110
+ ⟨by positivity,(div_le_one hNpos).mpr (by exact_mod_cast hk)⟩
111
+ obtain ⟨hi,hpair⟩ := hn.2 C G h _ ht
112
+ obtain ⟨ha,hb⟩ := hN₀ N hN
113
+ constructor
114
+ · intro e T he
115
+ have herr := gridCandidateFailure_error H N k hk e T
116
+ have herr' := (abs_le.mp herr).1
117
+ have hh := hi e T he
118
+ change _ ≤ A/(N : ℝ) at herr
119
+ dsimp only [A] at ha
120
+ dsimp only [H] at herr'
121
+ linarith
122
+ · intro e T he
123
+ have hcard : ((H T).erase e).card = 2 := by
124
+ rw [Finset.card_erase_of_mem he,activeHypergraph_card]
125
+ have herr := gridAnswer_uniform_error H N k hk ((H T).erase e) (some T)
126
+ rw [hcard] at herr
127
+ have herr' := (abs_le.mp herr).2
128
+ have hp := hpair e T he
129
+ have hbl := cavityWeight_lower hn.1.le ht
130
+ dsimp only [B,H] at hb herr'
131
+ norm_num only [Nat.cast_ofNat] at herr'
132
+ linarith
133
+
134
+ end SharpTerminalLeave
135
+
136
+ end
137
+
138
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/CavityWeightLipschitz.lean ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Stability.CavityWeight
3
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixWeight
4
+ import OAI.Combinatorics.TriangleRemoval.Process.WitnessMu
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ open scoped BigOperators Topology Matrix.Norms.Operator
10
+ open MeasureTheory
11
+ open scoped BigOperators ENNReal Classical
12
+ open Filter MeasureTheory
13
+ open scoped BigOperators Topology
14
+ open Filter
15
+ open scoped BigOperators
16
+
17
+ namespace SharpTerminalLeave
18
+ open Filter MeasureTheory
19
+ open scoped BigOperators Topology
20
+
21
+ lemma cavityWeight_lipschitz {D : ℝ} (hD : 0 ≤ D)
22
+ {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) :
23
+ |cavityWeight D x - cavityWeight D y| ≤ (2*D)*|x-y| := by
24
+ have hx1 : 1 ≤ 1+2*D*x := by nlinarith [mul_nonneg hD hx]
25
+ have hy1 : 1 ≤ 1+2*D*y := by nlinarith [mul_nonneg hD hy]
26
+ have hx0 : 0 < 1+2*D*x := by linarith
27
+ have hy0 : 0 < 1+2*D*y := by linarith
28
+ have he : cavityWeight D x - cavityWeight D y =
29
+ (2*D*(y-x))/((1+2*D*x)*(1+2*D*y)) := by
30
+ unfold cavityWeight
31
+ field_simp
32
+ ring
33
+ rw [he,abs_div,abs_mul,abs_of_nonneg (mul_nonneg (by norm_num : (0 : ℝ) ≤ 2) hD),
34
+ abs_of_pos (mul_pos hx0 hy0),abs_sub_comm y x]
35
+ have hden : 1 ≤ (1+2*D*x)*(1+2*D*y) := by nlinarith
36
+ exact (div_le_iff₀ (mul_pos hx0 hy0)).mpr (by
37
+ nlinarith [mul_nonneg (mul_nonneg (mul_nonneg (by norm_num : (0 : ℝ) ≤ 2) hD)
38
+ (abs_nonneg (x-y))) (sub_nonneg.mpr hden)])
39
+
40
+ lemma continuous_clipped_cavityWeight {D : ℝ} (hD : 0 ≤ D) :
41
+ Continuous (fun t => cavityWeight D (unitTime t)) := by
42
+ unfold cavityWeight
43
+ apply Continuous.div continuous_const
44
+ (continuous_const.add (continuous_const.mul continuous_unitTime))
45
+ intro t
46
+ change 1 + 2*D*unitTime t ≠ 0
47
+ have ht := mul_nonneg (mul_nonneg (by norm_num : (0 : ℝ) ≤ 2) hD) (unitTime_nonneg t)
48
+ linarith
49
+
50
+ lemma cavityWeight_integral {D : ℝ} (hD : 0 < D) :
51
+ (∫ t in (0 : ℝ)..1, cavityWeight D (unitTime t)) = witnessMu D := by
52
+ have hc : 2*D ≠ 0 := by positivity
53
+ have he : (∫ t in (0 : ℝ)..1, cavityWeight D (unitTime t)) =
54
+ ∫ t in (0 : ℝ)..1, 1/(1+(2*D)*t) := by
55
+ apply intervalIntegral.integral_congr
56
+ intro t ht
57
+ rw [Set.uIcc_of_le (by norm_num : (0 : ℝ) ≤ 1)] at ht
58
+ simp only [unitTime_of_mem ht,cavityWeight]
59
+ rw [he,intervalIntegral.integral_comp_add_mul (fun x : ℝ => 1/x) hc 1]
60
+ simp only [mul_zero,add_zero,mul_one,smul_eq_mul]
61
+ rw [integral_one_div_of_pos (by norm_num : (0 : ℝ) < 1) (by linarith : 0 < 1+2*D)]
62
+ simp only [div_one,witnessMu]
63
+ ring
64
+
65
+ theorem gridWitnessWeight_error {D : ℝ} (hD : 0 < D) (N : ℕ) (hN : 0 < N) :
66
+ |prefixWeight (fun j => (2/(N : ℝ))*cavityWeight D ((j : ℝ)/N)) N -
67
+ 2*witnessMu D| ≤ 4*D/N := by
68
+ have hNr : (0 : ℝ) < N := by exact_mod_cast hN
69
+ have hh := uniform_grid_quadrature (fun t => cavityWeight D (unitTime t))
70
+ (continuous_clipped_cavityWeight hD.le) (by positivity : (0 : ℝ) ≤ 2*D)
71
+ (fun x hx y hy => by
72
+ rw [unitTime_of_mem hx,unitTime_of_mem hy]
73
+ exact cavityWeight_lipschitz hD.le hx.1 hy.1) N N hN le_rfl
74
+ rw [div_self (ne_of_gt hNr),cavityWeight_integral hD] at hh
75
+ have hs : (∑ j ∈ Finset.range N, cavityWeight D (unitTime ((j : ℝ)/N))) =
76
+ ∑ j ∈ Finset.range N, cavityWeight D ((j : ℝ)/N) := by
77
+ apply Finset.sum_congr rfl
78
+ intro j hj
79
+ rw [unitTime_of_mem ⟨by positivity,(div_le_one hNr).mpr (by exact_mod_cast (Finset.mem_range.mp hj).le)⟩]
80
+ rw [hs,abs_sub_comm] at hh
81
+ have he : prefixWeight (fun j => (2/(N : ℝ))*cavityWeight D ((j : ℝ)/N)) N -
82
+ 2*witnessMu D =
83
+ 2*((1/(N : ℝ))*(∑ j ∈ Finset.range N, cavityWeight D ((j : ℝ)/N)) - witnessMu D) := by
84
+ unfold prefixWeight
85
+ rw [← Finset.mul_sum]
86
+ ring
87
+ rw [he,abs_mul,abs_of_pos (by norm_num : (0 : ℝ) < 2)]
88
+ calc
89
+ _ ≤ 2*(2*D/N) := mul_le_mul_of_nonneg_left hh (by norm_num)
90
+ _ = _ := by ring
91
+
92
+ theorem gridWitnessWeight_tendsto {D : ℝ} (hD : 0 < D) :
93
+ Tendsto (fun N : ℕ => prefixWeight
94
+ (fun j => (2/((N+1 : ℕ) : ℝ))*cavityWeight D ((j : ℝ)/(N+1 : ℕ))) (N+1))
95
+ atTop (𝓝 (2*witnessMu D)) := by
96
+ have hz : Tendsto (fun N : ℕ => 4*D/((N+1 : ℕ) : ℝ)) atTop (𝓝 0) := by
97
+ have h := (tendsto_const_nhds (x := 4*D)).mul
98
+ (tendsto_one_div_add_atTop_nhds_zero_nat :
99
+ Tendsto (fun N : ℕ => (1 : ℝ)/(N+1)) atTop (𝓝 0))
100
+ simpa only [Nat.cast_add,Nat.cast_one,mul_zero,div_eq_mul_inv,one_mul] using h
101
+ have hl : Tendsto (fun N : ℕ => 2*witnessMu D - 4*D/((N+1 : ℕ) : ℝ))
102
+ atTop (𝓝 (2*witnessMu D)) := by
103
+ simpa only [sub_zero] using (tendsto_const_nhds (x := 2*witnessMu D)).sub hz
104
+ have hu : Tendsto (fun N : ℕ => 2*witnessMu D + 4*D/((N+1 : ℕ) : ℝ))
105
+ atTop (𝓝 (2*witnessMu D)) := by
106
+ simpa only [add_zero] using (tendsto_const_nhds (x := 2*witnessMu D)).add hz
107
+ apply tendsto_of_tendsto_of_tendsto_of_le_of_le hl hu
108
+ · intro N
109
+ have h := (abs_le.mp (gridWitnessWeight_error hD (N+1) (by omega))).1
110
+ linarith
111
+ · intro N
112
+ have h := (abs_le.mp (gridWitnessWeight_error hD (N+1) (by omega))).2
113
+ linarith
114
+
115
+ end SharpTerminalLeave
116
+
117
+ end
118
+
119
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/ContinuousCavityWeightClip.lean ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Stability.CavityWeightLipschitz
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open scoped BigOperators
10
+ open scoped BigOperators ENNReal Classical
11
+ open Filter MeasureTheory
12
+ open scoped BigOperators Topology
13
+ open Filter
14
+
15
+ namespace SharpTerminalLeave
16
+
17
+ lemma continuous_cavityWeight_clip {D : ℝ} (hD : 0 ≤ D) :
18
+ Continuous (fun t => cavityWeight D (unitTime t)) := by
19
+ unfold cavityWeight
20
+ apply continuous_const.div
21
+ (continuous_const.add ((continuous_const.mul continuous_const).mul continuous_unitTime))
22
+ intro t
23
+ have ht := unitTime_nonneg t
24
+ apply ne_of_gt
25
+ change 0 < 1+2*D*unitTime t
26
+ have hh : 0 ≤ 2*D*unitTime t := mul_nonneg (mul_nonneg (by norm_num) hD) ht
27
+ linarith
28
+
29
+ lemma cavityWeight_lipschitz_cell {D x y : ℝ} (hD : 0 ≤ D)
30
+ (hx : 0 ≤ x) (hy : 0 ≤ y) :
31
+ |cavityWeight D x - cavityWeight D y| ≤ (2*D)*|x-y| := by
32
+ have ha : 1 ≤ 1+2*D*x := le_add_of_nonneg_right (mul_nonneg (mul_nonneg (by norm_num) hD) hx)
33
+ have hb : 1 ≤ 1+2*D*y := le_add_of_nonneg_right (mul_nonneg (mul_nonneg (by norm_num) hD) hy)
34
+ have ha0 : 0 < 1+2*D*x := lt_of_lt_of_le zero_lt_one ha
35
+ have hb0 : 0 < 1+2*D*y := lt_of_lt_of_le zero_lt_one hb
36
+ have hid : 1/(1+2*D*x)-1/(1+2*D*y) =
37
+ (2*D*(y-x))/((1+2*D*x)*(1+2*D*y)) := by
38
+ field_simp
39
+ ring
40
+ unfold cavityWeight
41
+ rw [hid,abs_div,abs_mul,abs_of_nonneg (by positivity : 0 ≤ 2*D),
42
+ abs_of_pos (mul_pos ha0 hb0),abs_sub_comm y x]
43
+ exact div_le_self (by positivity) (one_le_mul_of_one_le_of_one_le ha hb)
44
+
45
+ theorem grid_prefixWeight_tendsto {D : ℝ} (hD : 0 < D) :
46
+ Tendsto (fun j : ℕ =>
47
+ prefixWeight (fun t => (2/((j+1 : ℕ) : ℝ))*cavityWeight D ((t : ℝ)/(j+1 : ℕ))) (j+1))
48
+ atTop (𝓝 (2*witnessMu D)) := by
49
+ have hquad (j : ℕ) :
50
+ |prefixWeight (fun t => (2/((j+1 : ℕ) : ℝ))*cavityWeight D ((t : ℝ)/(j+1 : ℕ))) (j+1) -
51
+ 2*witnessMu D| ≤ 4*D/((j+1 : ℕ) : ℝ) := by
52
+ have hN : 0 < j+1 := Nat.succ_pos j
53
+ have hNr : (0 : ℝ) < (j+1 : ℕ) := by exact_mod_cast hN
54
+ have hh := uniform_grid_quadrature (fun t => cavityWeight D (unitTime t))
55
+ (continuous_cavityWeight_clip hD.le) (show 0 ≤ 2*D by positivity)
56
+ (fun x hx y hy => by
57
+ rw [unitTime_of_mem hx,unitTime_of_mem hy]
58
+ exact cavityWeight_lipschitz_cell hD.le hx.1 hy.1) (j+1) (j+1) hN le_rfl
59
+ rw [div_self (ne_of_gt hNr),cavityWeight_integral hD] at hh
60
+ have heq : (∑ t ∈ Finset.range (j+1), cavityWeight D (unitTime ((t : ℝ)/(j+1 : ℕ)))) =
61
+ ∑ t ∈ Finset.range (j+1), cavityWeight D ((t : ℝ)/(j+1 : ℕ)) := by
62
+ apply Finset.sum_congr rfl
63
+ intro t ht
64
+ rw [unitTime_of_mem ⟨by positivity,(div_le_one hNr).mpr
65
+ (by exact_mod_cast (Finset.mem_range.mp ht).le)⟩]
66
+ rw [heq] at hh
67
+ have hb := mul_le_mul_of_nonneg_left hh (by norm_num : (0 : ℝ) ≤ 2)
68
+ calc
69
+ _ = 2*|witnessMu D - (1/((j+1 : ℕ) : ℝ))*
70
+ ∑ t ∈ Finset.range (j+1), cavityWeight D ((t : ℝ)/(j+1 : ℕ))| := by
71
+ unfold prefixWeight
72
+ rw [← Finset.mul_sum]
73
+ rw [show (2 : ℝ) = |(2 : ℝ)| by norm_num, ← abs_mul, ← abs_neg]
74
+ congr 1
75
+ ring
76
+ _ ≤ _ := by
77
+ calc
78
+ _ ≤ 2*(2*D/((j+1 : ℕ) : ℝ)) := hb
79
+ _ = _ := by ring
80
+ have hden : Tendsto (fun j : ℕ => (4*D)/((j+1 : ℕ) : ℝ)) atTop (𝓝 0) := by
81
+ have hh := tendsto_one_div_add_atTop_nhds_zero_nat.mul_const (4*D)
82
+ simpa only [Nat.cast_add,Nat.cast_one,mul_comm,one_div,div_eq_mul_inv,one_mul,zero_mul] using hh
83
+ apply tendsto_iff_norm_sub_tendsto_zero.mpr
84
+ exact squeeze_zero (fun _ => norm_nonneg _) (fun j => by rw [Real.norm_eq_abs]; exact hquad j) hden
85
+
86
+ lemma collision_exponential_identity {D : ℝ} (hD : 0 < D) :
87
+ (1+2*D)^3*Real.exp (45*D*(2*witnessMu D)) = (1+2*D)^48 := by
88
+ have he : 45*D*(2*witnessMu D) = 45*Real.log (1+2*D) := by
89
+ unfold witnessMu
90
+ field_simp
91
+ rw [he,show (45 : ℝ) = (45 : ℕ) by norm_num,Real.exp_nat_mul,
92
+ Real.exp_log (by linarith : 0 < 1+2*D),← pow_add]
93
+
94
+ lemma collision_power_48_bound {D : ℝ} (hD : 1 ≤ D) :
95
+ (1+2*D)^48/D^50 ≤ (3 : ℝ)^48/D^2 := by
96
+ have hpos : 0 < D := lt_of_lt_of_le zero_lt_one hD
97
+ have hh := div_le_div_of_nonneg_right
98
+ (pow_le_pow_left₀ (by positivity : 0 ≤ 1+2*D) (by linarith : 1+2*D ≤ 3*D) 48)
99
+ (by positivity : 0 ≤ D^50)
100
+ apply hh.trans_eq
101
+ rw [mul_pow,show 50 = 48+2 by norm_num,pow_add]
102
+ field_simp
103
+
104
+ end SharpTerminalLeave
105
+
106
+ open Filter
107
+ open scoped BigOperators Topology
108
+
109
+ end
110
+
111
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/EdgeStabilityRate.lean ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEdgeRadius
3
+ import OAI.Combinatorics.TriangleRemoval.Process.TriangleIndex
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ noncomputable section
9
+ open scoped BigOperators
10
+ open Filter Classical
11
+
12
+ namespace SharpTerminalLeave
13
+
14
+ noncomputable def edgeStabilityRate (s t Q : ℝ) : ℝ := s^2/(Q*t)
15
+ noncomputable def edgeStabilityScalar (s t Q κ : ℝ) : ℝ := s/t-1-2*edgeStabilityRate s t Q+κ*s/(Q*t)
16
+
17
+ lemma triangle_relative_inverse_bound {Q S r : ℝ} (hS : 0 < S) (hr : r ≤ 1/2)
18
+ (h : |Q/S-1| ≤ r) : 0 < Q ∧ |1-S/Q| ≤ 2*r ∧ S/Q ≤ 2 := by
19
+ obtain ⟨hl,hu⟩ := abs_le.mp h
20
+ have hlow : S/2 ≤ Q := by
21
+ have hh : 1/2 ≤ Q/S := by linarith
22
+ have hh' := (le_div_iff₀ hS).mp hh
23
+ linarith only [hh']
24
+ have hQ : 0 < Q := lt_of_lt_of_le (by positivity) hlow
25
+ have hab : |Q-S| ≤ r*S := by
26
+ have he : Q/S-1 = (Q-S)/S := by field_simp
27
+ rw [he,abs_div,abs_of_pos hS] at h
28
+ exact (div_le_iff₀ hS).mp h
29
+ have hratio : S/Q ≤ 2 := (div_le_iff₀ hQ).mpr (by linarith)
30
+ have hr0 : 0 ≤ r := (abs_nonneg _).trans h
31
+ refine ⟨hQ,?_,hratio⟩
32
+ have he : 1-S/Q = (Q-S)/Q := by field_simp
33
+ rw [he,abs_div,abs_of_pos hQ]
34
+ calc
35
+ _ ≤ r*S/Q := div_le_div_of_nonneg_right hab hQ.le
36
+ _ = r*(S/Q) := by ring
37
+ _ ≤ _ := by nlinarith only [mul_le_mul_of_nonneg_left hratio hr0]
38
+
39
+ lemma edge_stability_coefficients {s t Q S lam r κ : ℝ}
40
+ (hs : 0 < s) (ht : 0 < t) (hS : 0 < S) (hl : 0 ≤ lam)
41
+ (hscale : t = s*(1-lam)^2) (hratio : s ≤ 2*t)
42
+ (hident : s = lam*S) (hr : r ≤ 1/2) (hQerr : |Q/S-1| ≤ r)
43
+ (hκ : 0 ≤ κ) (hκ1 : κ ≤ 1) :
44
+ (0 ≤ edgeStabilityRate s t Q ∧ edgeStabilityRate s t Q ≤ 4*lam) ∧
45
+ |edgeStabilityScalar s t Q κ| ≤ 8*r*lam+2*lam^2+4*lam/s := by
46
+ obtain ⟨hQ,habs,hSQ⟩ := triangle_relative_inverse_bound hS hr hQerr
47
+ have hr0 : 0 ≤ r := (abs_nonneg _).trans hQerr
48
+ have hsQ : s/Q ≤ 2*lam := by
49
+ rw [hident,mul_div_assoc]
50
+ simpa only [mul_comm lam 2] using mul_le_mul_of_nonneg_left hSQ hl
51
+ have hsQdiff : |lam-s/Q| ≤ 2*r*lam := by
52
+ have he : lam-s/Q = lam*(1-S/Q) := by rw [hident]; ring
53
+ rw [he,abs_mul,abs_of_nonneg hl]
54
+ nlinarith only [mul_le_mul_of_nonneg_left habs hl]
55
+ have hsT : s/t ≤ 2 := (div_le_iff₀ ht).mpr hratio
56
+ have haeq : edgeStabilityRate s t Q = (s/t)*(s/Q) := by unfold edgeStabilityRate; ring
57
+ have hbeq : edgeStabilityScalar s t Q κ =
58
+ (s/t)*(2*(lam-s/Q)-lam^2+κ/Q) := by
59
+ unfold edgeStabilityScalar edgeStabilityRate
60
+ apply (mul_right_cancel₀ ht.ne')
61
+ field_simp [hs.ne',ht.ne',hQ.ne']
62
+ rw [hscale]
63
+ ring
64
+ constructor
65
+ · rw [haeq]
66
+ exact ⟨by positivity,(mul_le_mul hsT hsQ (by positivity) (by norm_num)).trans_eq (by ring)⟩
67
+ · have hκQ : |κ/Q| ≤ 2*lam/s := by
68
+ rw [abs_of_nonneg (div_nonneg hκ hQ.le)]
69
+ apply (le_div_iff₀ hs).mpr
70
+ have hh := div_le_div_of_nonneg_right hκ1 hQ.le
71
+ have hm := mul_le_mul_of_nonneg_right hh hs.le
72
+ calc
73
+ _ ≤ (1/Q)*s := hm
74
+ _ = s/Q := by ring
75
+ _ ≤ _ := hsQ
76
+ have hb : |2*(lam-s/Q)-lam^2+κ/Q| ≤ 4*r*lam+lam^2+2*lam/s := by
77
+ calc
78
+ _ ≤ |2*(lam-s/Q)-lam^2|+|κ/Q| := abs_add_le _ _
79
+ _ ≤ |2*(lam-s/Q)|+|lam^2|+|κ/Q| := by linarith only [abs_sub (2*(lam-s/Q)) (lam^2)]
80
+ _ ≤ 4*r*lam+lam^2+2*lam/s := by
81
+ rw [abs_mul,abs_of_nonneg (by norm_num : (0 : ℝ) ≤ 2),abs_of_nonneg (sq_nonneg lam)]
82
+ linarith only [hsQdiff,hκQ]
83
+ rw [hbeq,abs_mul,abs_of_pos (div_pos hs ht)]
84
+ calc
85
+ _ ≤ 2*(4*r*lam+lam^2+2*lam/s) := mul_le_mul hsT hb (abs_nonneg _) (by norm_num)
86
+ _ = _ := by ring
87
+
88
+ lemma early_codegree_grid {n i : ℕ} (hn : 0 < n)
89
+ (hp : 1/(n : ℝ) ≤ prefixDensity n) (hi : i < prefixTime n) :
90
+ earlyTemplateScale 1 2 n (i+1) = earlyTemplateScale 1 2 n i*
91
+ (1-6/(n : ℝ)^2/earlyDensity n i)^2 ∧
92
+ earlyTemplateScale 1 2 n i = (6/(n : ℝ)^2/earlyDensity n i)*earlyTriangleScale n i ∧
93
+ 0 ≤ 6/(n : ℝ)^2/earlyDensity n i ∧
94
+ 6/(n : ℝ)^2/earlyDensity n i ≤ 6/(n : ℝ) := by
95
+ have hnR : (0 : ℝ) < n := by exact_mod_cast hn
96
+ have hpi := early_density_positive hn hp hi.le
97
+ have hs := earlyDensity_succ n i
98
+ have he : earlyDensity n (i+1) = earlyDensity n i*(1-6/(n : ℝ)^2/earlyDensity n i) := by
99
+ have he : earlyDensity n (i+1) = earlyDensity n i-6/(n : ℝ)^2 := by linarith only [hs]
100
+ rw [he]
101
+ field_simp
102
+ refine ⟨?_,?_,by positivity,?_⟩
103
+ · simp only [earlyTemplateScale,pow_one,he,mul_pow]; ring
104
+ · unfold earlyTriangleScale
105
+ simp only [earlyTemplateScale,pow_one]
106
+ field_simp
107
+ · have hp' := hp.trans (earlyDensity_antitone n hi.le)
108
+ apply (div_le_iff₀ hpi).mpr
109
+ have hm := mul_le_mul_of_nonneg_left hp' (show 0 ≤ 6/(n : ℝ) by positivity)
110
+ convert hm using 1
111
+ field_simp
112
+
113
+ end SharpTerminalLeave
114
+ end
115
+ end
116
+
117
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/GeometricVolterraIdentity.lean ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ namespace OAI
4
+
5
+ section
6
+ open scoped BigOperators Topology Matrix.Norms.Operator
7
+ open MeasureTheory
8
+ open scoped BigOperators
9
+ open scoped BigOperators ENNReal Classical
10
+ open Filter MeasureTheory
11
+ open scoped BigOperators Topology
12
+ open Filter
13
+
14
+ namespace SharpTerminalLeave
15
+
16
+ theorem geometric_volterra_identity (a c : ℝ) (k : ℕ) :
17
+ c + a * (∑ j ∈ Finset.range k, c * (1 + a) ^ j) = c * (1 + a) ^ k := by
18
+ induction k with
19
+ | zero => simp
20
+ | succ k ih =>
21
+ rw [Finset.sum_range_succ, pow_succ]
22
+ nlinarith [ih]
23
+
24
+ theorem discrete_volterra_bound (E : ℕ → ℝ) (a c : ℝ) (ha : 0 ≤ a)
25
+ (M : ℕ) (hE : ∀ k ≤ M, E k ≤ c + a * ∑ j ∈ Finset.range k, E j)
26
+ (k : ℕ) (hk : k ≤ M) : E k ≤ c * (1 + a) ^ k := by
27
+ induction k using Nat.strong_induction_on with
28
+ | h k ih =>
29
+ calc
30
+ E k ≤ c + a * ∑ j ∈ Finset.range k, E j := hE k hk
31
+ _ ≤ c + a * ∑ j ∈ Finset.range k, c * (1 + a) ^ j := by
32
+ gcongr with j hj
33
+ exact ih j (Finset.mem_range.mp hj) ((Nat.le_of_lt (Finset.mem_range.mp hj)).trans hk)
34
+ _ = c * (1 + a) ^ k := geometric_volterra_identity a c k
35
+
36
+ theorem discrete_volterra_exp_bound (E : ℕ → ℝ) (A C : ℝ)
37
+ (hA : 0 ≤ A) (hC : 0 ≤ C) (N : ℕ) (hN : 0 < N)
38
+ (hE : ∀ k ≤ N, E k ≤ C / N + (A / N) * ∑ j ∈ Finset.range k, E j)
39
+ (k : ℕ) (hk : k ≤ N) : E k ≤ (C / N) * Real.exp A := by
40
+ have hNr : (0 : ℝ) < N := by exact_mod_cast hN
41
+ have hd : 0 ≤ A / N := div_nonneg hA hNr.le
42
+ have hh := discrete_volterra_bound E (A / N) (C / N) hd N hE k hk
43
+ apply hh.trans
44
+ apply mul_le_mul_of_nonneg_left _ (div_nonneg hC hNr.le)
45
+ calc
46
+ (1 + A / N) ^ k ≤ (Real.exp (A / N)) ^ k := by
47
+ apply pow_le_pow_left₀ (by positivity)
48
+ simpa only [add_comm] using Real.add_one_le_exp (A / N)
49
+ _ = Real.exp ((k : ℝ) * (A / N)) := (Real.exp_nat_mul _ _).symm
50
+ _ ≤ Real.exp A := by
51
+ apply Real.exp_le_exp.mpr
52
+ have hkr : (k : ℝ) ≤ N := by exact_mod_cast hk
53
+ calc
54
+ (k : ℝ) * (A / N) ≤ (N : ℝ) * (A / N) := mul_le_mul_of_nonneg_right hkr hd
55
+ _ = A := by field_simp
56
+
57
+ theorem integral_cell_error (f : ℝ → ℝ) {a b L : ℝ} (hab : a ≤ b)
58
+ (hf : Continuous f) (hL : 0 ≤ L)
59
+ (hLip : ∀ x ∈ Set.Icc a b, |f x - f a| ≤ L * (x - a)) :
60
+ |(∫ x in a..b, f x) - (b - a) * f a| ≤ L * (b - a) ^ 2 := by
61
+ have heq : (∫ x in a..b, f x) - (b - a) * f a = ∫ x in a..b, f x - f a := by
62
+ rw [intervalIntegral.integral_sub (hf.intervalIntegrable _ _) (continuous_const.intervalIntegrable _ _)]
63
+ simp only [intervalIntegral.integral_const, smul_eq_mul]
64
+ rw [heq, ← Real.norm_eq_abs]
65
+ have hb := intervalIntegral.norm_integral_le_of_norm_le_const
66
+ (a := a) (b := b) (f := fun x => f x - f a) (C := L * (b - a)) (by
67
+ intro x hx
68
+ rw [Set.uIoc_of_le hab] at hx
69
+ rw [Real.norm_eq_abs]
70
+ exact (hLip x ⟨hx.1.le, hx.2⟩).trans
71
+ (mul_le_mul_of_nonneg_left (sub_le_sub_right hx.2 a) hL))
72
+ rw [abs_of_nonneg (sub_nonneg.mpr hab)] at hb
73
+ convert hb using 1
74
+ ring
75
+
76
+ theorem uniform_grid_quadrature (f : ℝ → ℝ) (hf : Continuous f)
77
+ {L : ℝ} (hL : 0 ≤ L)
78
+ (hLip : ∀ x ∈ Set.Icc (0 : ℝ) 1, ∀ y ∈ Set.Icc (0 : ℝ) 1,
79
+ |f x - f y| ≤ L * |x - y|)
80
+ (N k : ℕ) (hN : 0 < N) (hk : k ≤ N) :
81
+ |(∫ x in (0 : ℝ)..((k : ℝ) / N), f x) -
82
+ (1 / (N : ℝ)) * ∑ j ∈ Finset.range k, f ((j : ℝ) / N)| ≤ L / N := by
83
+ have hNr : (0 : ℝ) < N := by exact_mod_cast hN
84
+ have hsum : (∫ x in (0 : ℝ)..((k : ℝ) / N), f x) =
85
+ ∑ j ∈ Finset.range k, ∫ x in ((j : ℝ) / N)..(((j + 1 : ℕ) : ℝ) / N), f x := by
86
+ simpa only [Nat.cast_zero, zero_div] using
87
+ (intervalIntegral.sum_integral_adjacent_intervals
88
+ (a := fun j => (j : ℝ) / N) (n := k) (fun _ _ => hf.intervalIntegrable _ _)).symm
89
+ rw [hsum, Finset.mul_sum, ← Finset.sum_sub_distrib]
90
+ calc
91
+ _ ≤ ∑ j ∈ Finset.range k,
92
+ |(∫ x in ((j : ℝ) / N)..(((j + 1 : ℕ) : ℝ) / N), f x) -
93
+ (1 / N) * f ((j : ℝ) / N)| := Finset.abs_sum_le_sum_abs _ _
94
+ _ ≤ ∑ _j ∈ Finset.range k, L * (1 / (N : ℝ)) ^ 2 := by
95
+ apply Finset.sum_le_sum
96
+ intro j hj
97
+ have hjk : j < k := Finset.mem_range.mp hj
98
+ have hjN : (j : ℝ) + 1 ≤ N := by exact_mod_cast (show j + 1 ≤ N by omega)
99
+ have hja : (j : ℝ) / N ≤ ((j + 1 : ℕ) : ℝ) / N := by
100
+ gcongr; exact_mod_cast (Nat.le_succ j)
101
+ have hdif : (((j + 1 : ℕ) : ℝ) / N) - (j : ℝ) / N = 1 / (N : ℝ) := by
102
+ push_cast; ring
103
+ have he := integral_cell_error f hja hf hL (by
104
+ intro x hx
105
+ have ha0 : (0 : ℝ) ≤ (j : ℝ) / N := by positivity
106
+ have hb1 : (((j + 1 : ℕ) : ℝ) / N) ≤ 1 := by
107
+ rw [div_le_one hNr]; simpa using hjN
108
+ have hh := hLip x ⟨ha0.trans hx.1, hx.2.trans hb1⟩
109
+ ((j : ℝ) / N) ⟨ha0, hja.trans hb1⟩
110
+ simpa only [abs_of_nonneg (sub_nonneg.mpr hx.1)] using hh)
111
+ simpa only [hdif] using he
112
+ _ ≤ L / N := by
113
+ simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul]
114
+ have hkr : (k : ℝ) ≤ N := by exact_mod_cast hk
115
+ calc
116
+ _ ≤ (N : ℝ) * (L * (1 / (N : ℝ)) ^ 2) := by gcongr
117
+ _ = L / N := by field_simp
118
+
119
+ end SharpTerminalLeave
120
+
121
+ end
122
+
123
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/GridCavityError.lean ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Queries.TreeBind
3
+ import OAI.Combinatorics.TriangleRemoval.Stability.GeometricVolterraIdentity
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ open scoped BigOperators Topology Matrix.Norms.Operator
9
+ open MeasureTheory
10
+ open scoped BigOperators
11
+ open scoped BigOperators ENNReal Classical
12
+ open Filter MeasureTheory
13
+ open scoped BigOperators Topology
14
+ open Filter
15
+
16
+ namespace SharpTerminalLeave
17
+ open Filter
18
+ open scoped BigOperators Topology
19
+
20
+ section GridApproximation
21
+ variable {ι τ : Type*} [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ]
22
+
23
+ theorem messageIntegral_time_lipschitz (H : τ → Finset ι) (e : ι) (T : τ)
24
+ {s t : ℝ} (hs : s ∈ Set.Icc (0 : ℝ) 1) (ht : t ∈ Set.Icc (0 : ℝ) 1) :
25
+ |messageIntegral H (cavityLimit H) e T t - messageIntegral H (cavityLimit H) e T s| ≤
26
+ |t - s| := by
27
+ let f : ℝ → ℝ := fun x => ∏ a ∈ (H T).erase e, cavityLimit H a (some T) x
28
+ have hc : Continuous f := continuous_message_integrand H _ (continuous_cavityLimit H) e T
29
+ have hf : ∀ x, f x ∈ Set.Icc (0 : ℝ) 1 := by
30
+ intro x
31
+ exact ⟨Finset.prod_nonneg (fun a _ => (cavityLimit_mem_unit H a (some T) x).1),
32
+ Finset.prod_le_one₀ (fun a _ => (cavityLimit_mem_unit H a (some T) x).1)
33
+ (fun a _ => (cavityLimit_mem_unit H a (some T) x).2)⟩
34
+ simp only [messageIntegral, unitTime_of_mem hs, unitTime_of_mem ht]
35
+ change |(∫ x in (0 : ℝ)..t, f x) - ∫ x in (0 : ℝ)..s, f x| ≤ _
36
+ rw [intervalIntegral.integral_interval_sub_left (hc.intervalIntegrable _ _) (hc.intervalIntegrable _ _),
37
+ ← Real.norm_eq_abs]
38
+ simpa only [one_mul] using
39
+ (intervalIntegral.norm_integral_le_of_norm_le_const (a := s) (b := t) (C := (1 : ℝ))
40
+ (f := f) (fun x _ => by simpa only [Real.norm_eq_abs, abs_of_nonneg (hf x).1] using (hf x).2))
41
+
42
+ theorem cavityLimit_time_lipschitz (H : τ → Finset ι) (e : ι) (p : Option τ)
43
+ {s t : ℝ} (hs : s ∈ Set.Icc (0 : ℝ) 1) (ht : t ∈ Set.Icc (0 : ℝ) 1) :
44
+ |cavityLimit H e p t - cavityLimit H e p s| ≤ (Fintype.card τ : ℝ) * |t - s| := by
45
+ rw [cavityLimit_product H e p t, cavityLimit_product H e p s]
46
+ unfold cavityOperator
47
+ have hm : ∀ T u, 1 - messageIntegral H (cavityLimit H) e T u ∈ Set.Icc (0 : ℝ) 1 := by
48
+ intro T u
49
+ have h := messageIntegral_mem_unit H _ (continuous_cavityLimit H) (cavityLimit_mem_unit H) e T u
50
+ constructor <;> linarith [h.1, h.2]
51
+ calc
52
+ _ ≤ ∑ T ∈ messageCandidates H e p,
53
+ |(1 - messageIntegral H (cavityLimit H) e T t) -
54
+ (1 - messageIntegral H (cavityLimit H) e T s)| :=
55
+ abs_prod_sub_prod_le_sum _ _ _ (fun T _ => hm T t) (fun T _ => hm T s)
56
+ _ ≤ ∑ _T ∈ messageCandidates H e p, |t - s| := by
57
+ apply Finset.sum_le_sum
58
+ intro T _
59
+ rw [sub_sub_sub_cancel_left, abs_sub_comm]
60
+ exact messageIntegral_time_lipschitz H e T hs ht
61
+ _ ≤ (Fintype.card τ : ℝ) * |t - s| := by
62
+ simp only [Finset.sum_const, nsmul_eq_mul]
63
+ gcongr
64
+ exact_mod_cast Finset.card_le_univ (messageCandidates H e p)
65
+
66
+ theorem cavity_integrand_time_lipschitz (H : τ → Finset ι) (e : ι) (T : τ)
67
+ {s t : ℝ} (hs : s ∈ Set.Icc (0 : ℝ) 1) (ht : t ∈ Set.Icc (0 : ℝ) 1) :
68
+ |(∏ f ∈ (H T).erase e, cavityLimit H f (some T) t) -
69
+ ∏ f ∈ (H T).erase e, cavityLimit H f (some T) s| ≤
70
+ ((Fintype.card ι : ℝ) * Fintype.card τ) * |t - s| := by
71
+ calc
72
+ _ ≤ ∑ f ∈ (H T).erase e, |cavityLimit H f (some T) t - cavityLimit H f (some T) s| :=
73
+ abs_prod_sub_prod_le_sum _ _ _ (fun f _ => cavityLimit_mem_unit H f (some T) t)
74
+ (fun f _ => cavityLimit_mem_unit H f (some T) s)
75
+ _ ≤ ∑ _f ∈ (H T).erase e, (Fintype.card τ : ℝ) * |t - s| :=
76
+ Finset.sum_le_sum (fun f _ => cavityLimit_time_lipschitz H f (some T) hs ht)
77
+ _ ≤ ((Fintype.card ι : ℝ) * Fintype.card τ) * |t - s| := by
78
+ simp only [Finset.sum_const, nsmul_eq_mul, mul_assoc]
79
+ gcongr
80
+ exact_mod_cast Finset.card_le_univ ((H T).erase e)
81
+
82
+ omit [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] in
83
+ theorem sum_fin_filter_lt_eq_range (N k : ℕ) (hk : k ≤ N) (f : ℕ → ℝ) :
84
+ (∑ u ∈ Finset.univ.filter (fun u : Fin N => u.val < k), f u.val) =
85
+ ∑ j ∈ Finset.range k, f j := by
86
+ rw [Finset.sum_filter]
87
+ calc
88
+ _ = ∑ j ∈ Finset.range N, if j < k then f j else 0 :=
89
+ Fin.sum_univ_eq_sum_range (fun j => if j < k then f j else 0) N
90
+ _ =
91
+ ∑ j ∈ Finset.range k, if j < k then f j else 0 := by
92
+ symm
93
+ apply Finset.sum_subset (Finset.range_mono hk)
94
+ intro j _ hj
95
+ simp only [Finset.mem_range] at hj
96
+ simp only [hj, ↓reduceIte]
97
+ _ = _ := by
98
+ apply Finset.sum_congr rfl
99
+ intro j hj
100
+ simp only [Finset.mem_range.mp hj, ↓reduceIte]
101
+
102
+ omit [Fintype ι] in
103
+
104
+ theorem gridMessage_exact_range (H : τ → Finset ι) (N : ℕ) [NeZero N]
105
+ (k : ℕ) (hk : k ≤ N) (e : ι) (parent : Option τ) :
106
+ gridMessage H N N k e parent =
107
+ ∏ T ∈ messageCandidates H e parent,
108
+ (1 - (1 / (N : ℝ)) * ∑ j ∈ Finset.range k,
109
+ ∏ f ∈ (H T).erase e, gridMessage H N N j f (some T)) := by
110
+ rw [gridMessage_exact H N k hk]
111
+ apply Finset.prod_congr rfl
112
+ intro T _
113
+ congr 2
114
+ exact sum_fin_filter_lt_eq_range N k hk
115
+ (fun j => ∏ f ∈ (H T).erase e, gridMessage H N N j f (some T))
116
+
117
+ omit [Fintype ι] [Fintype τ] [DecidableEq ι] [DecidableEq τ] in
118
+ theorem uniform_subaverage_mem_unit (N k : ℕ) (hN : 0 < N) (hk : k ≤ N)
119
+ (f : ℕ → ℝ) (hf : ∀ j < k, f j ∈ Set.Icc (0 : ℝ) 1) :
120
+ 1 - (1 / (N : ℝ)) * ∑ j ∈ Finset.range k, f j ∈ Set.Icc (0 : ℝ) 1 := by
121
+ have hNr : (0 : ℝ) < N := by exact_mod_cast hN
122
+ have hs0 : 0 ≤ (1 / (N : ℝ)) * ∑ j ∈ Finset.range k, f j :=
123
+ mul_nonneg (by positivity) (Finset.sum_nonneg (fun j hj => (hf j (Finset.mem_range.mp hj)).1))
124
+ have hs1 : (∑ j ∈ Finset.range k, f j) ≤ (N : ℝ) := by
125
+ calc
126
+ _ ≤ ∑ _j ∈ Finset.range k, (1 : ℝ) :=
127
+ Finset.sum_le_sum (fun j hj => (hf j (Finset.mem_range.mp hj)).2)
128
+ _ = (k : ℝ) := by simp
129
+ _ ≤ (N : ℝ) := by exact_mod_cast hk
130
+ have hs2 : (1 / (N : ℝ)) * ∑ j ∈ Finset.range k, f j ≤ 1 := by
131
+ calc
132
+ _ ≤ (1 / (N : ℝ)) * N := mul_le_mul_of_nonneg_left hs1 (by positivity)
133
+ _ = 1 := by field_simp
134
+ constructor <;> linarith
135
+
136
+ omit [Fintype ι] in
137
+ theorem gridMessage_mem_unit (H : τ → Finset ι) (N : ℕ) [NeZero N]
138
+ (d k : ℕ) (e : ι) (p : Option τ) : gridMessage H N d k e p ∈ Set.Icc (0 : ℝ) 1 :=
139
+ gridAnswerProbability_mem_unit H N d k {e} p
140
+
141
+ noncomputable def gridCavityError (H : τ → Finset ι) (N : ℕ) [NeZero N] (k : ℕ) : ℝ :=
142
+ ‖(fun ep : ι × Option τ => gridMessage H N N k ep.1 ep.2 -
143
+ cavityLimit H ep.1 ep.2 ((k : ℝ) / N))‖
144
+
145
+ theorem gridCavityError_nonneg (H : τ → Finset ι) (N : ℕ) [NeZero N] (k : ℕ) :
146
+ 0 ≤ gridCavityError H N k := norm_nonneg _
147
+
148
+ theorem gridCavityError_coord (H : τ → Finset ι) (N : ℕ) [NeZero N]
149
+ (k : ℕ) (e : ι) (p : Option τ) :
150
+ |gridMessage H N N k e p - cavityLimit H e p ((k : ℝ) / N)| ≤ gridCavityError H N k := by
151
+ exact norm_le_pi_norm (fun ep : ι × Option τ =>
152
+ gridMessage H N N k ep.1 ep.2 - cavityLimit H ep.1 ep.2 ((k : ℝ) / N)) (e, p)
153
+
154
+ theorem grid_integrand_error (H : τ → Finset ι) (N : ℕ) [NeZero N]
155
+ (k : ℕ) (e : ι) (T : τ) :
156
+ |(∏ f ∈ (H T).erase e, gridMessage H N N k f (some T)) -
157
+ ∏ f ∈ (H T).erase e, cavityLimit H f (some T) ((k : ℝ) / N)| ≤
158
+ (Fintype.card ι : ℝ) * gridCavityError H N k := by
159
+ calc
160
+ _ ≤ ∑ f ∈ (H T).erase e,
161
+ |gridMessage H N N k f (some T) - cavityLimit H f (some T) ((k : ℝ) / N)| :=
162
+ abs_prod_sub_prod_le_sum _ _ _ (fun f _ => gridMessage_mem_unit H N N k f (some T))
163
+ (fun f _ => cavityLimit_mem_unit H f (some T) ((k : ℝ) / N))
164
+ _ ≤ ∑ _f ∈ (H T).erase e, gridCavityError H N k :=
165
+ Finset.sum_le_sum (fun f _ => gridCavityError_coord H N k f (some T))
166
+ _ ≤ (Fintype.card ι : ℝ) * gridCavityError H N k := by
167
+ simp only [Finset.sum_const, nsmul_eq_mul]
168
+ apply mul_le_mul_of_nonneg_right _ (gridCavityError_nonneg H N k)
169
+ exact_mod_cast Finset.card_le_univ ((H T).erase e)
170
+
171
+ theorem grid_message_integral_error (H : τ → Finset ι) (N : ℕ) [NeZero N]
172
+ (k : ℕ) (hk : k ≤ N) (e : ι) (T : τ) :
173
+ |(1 / (N : ℝ)) * (∑ j ∈ Finset.range k,
174
+ ∏ f ∈ (H T).erase e, gridMessage H N N j f (some T)) -
175
+ messageIntegral H (cavityLimit H) e T ((k : ℝ) / N)| ≤
176
+ ((Fintype.card ι : ℝ) / N) * ∑ j ∈ Finset.range k, gridCavityError H N j +
177
+ ((Fintype.card ι : ℝ) * Fintype.card τ) / N := by
178
+ have hN : 0 < N := Nat.pos_of_ne_zero (NeZero.ne N)
179
+ have hNr : (0 : ℝ) < N := by exact_mod_cast hN
180
+ let f : ℝ → ℝ := fun s => ∏ a ∈ (H T).erase e, cavityLimit H a (some T) s
181
+ have hc : Continuous f := continuous_message_integrand H _ (continuous_cavityLimit H) e T
182
+ have hquad := uniform_grid_quadrature f hc (by positivity :
183
+ 0 ≤ (Fintype.card ι : ℝ) * Fintype.card τ)
184
+ (fun x hx y hy => cavity_integrand_time_lipschitz H e T hy hx) N k hN hk
185
+ have htime : (k : ℝ) / N ∈ Set.Icc (0 : ℝ) 1 :=
186
+ ⟨by positivity, (div_le_one hNr).mpr (by exact_mod_cast hk)⟩
187
+ have hi : messageIntegral H (cavityLimit H) e T ((k : ℝ) / N) =
188
+ ∫ s in (0 : ℝ)..((k : ℝ) / N), f s := by
189
+ simp only [messageIntegral, unitTime_of_mem htime, f]
190
+ rw [hi]
191
+ calc
192
+ _ ≤ |(1 / (N : ℝ)) * (∑ j ∈ Finset.range k,
193
+ ∏ a ∈ (H T).erase e, gridMessage H N N j a (some T)) -
194
+ (1 / (N : ℝ)) * ∑ j ∈ Finset.range k, f ((j : ℝ) / N)| +
195
+ |(1 / (N : ℝ)) * (∑ j ∈ Finset.range k, f ((j : ℝ) / N)) -
196
+ ∫ s in (0 : ℝ)..((k : ℝ) / N), f s| := abs_sub_le _ _ _
197
+ _ ≤ ((Fintype.card ι : ℝ) / N) * ∑ j ∈ Finset.range k, gridCavityError H N j +
198
+ ((Fintype.card ι : ℝ) * Fintype.card τ) / N := by
199
+ apply add_le_add _ (by simpa only [abs_sub_comm] using hquad)
200
+ rw [← mul_sub, abs_mul, abs_of_nonneg (by positivity : 0 ≤ 1 / (N : ℝ)),
201
+ ← Finset.sum_sub_distrib]
202
+ calc
203
+ _ ≤ (1 / (N : ℝ)) * ∑ j ∈ Finset.range k,
204
+ |(∏ a ∈ (H T).erase e, gridMessage H N N j a (some T)) - f ((j : ℝ) / N)| :=
205
+ mul_le_mul_of_nonneg_left (Finset.abs_sum_le_sum_abs _ _) (by positivity)
206
+ _ ≤ (1 / (N : ℝ)) * ∑ j ∈ Finset.range k,
207
+ (Fintype.card ι : ℝ) * gridCavityError H N j := by
208
+ gcongr with j hj
209
+ exact grid_integrand_error H N j e T
210
+ _ = _ := by rw [← Finset.mul_sum]; ring
211
+
212
+ theorem gridCavityError_volterra (H : τ → Finset ι) (N : ℕ) [NeZero N]
213
+ (k : ℕ) (hk : k ≤ N) :
214
+ gridCavityError H N k ≤
215
+ ((Fintype.card τ : ℝ) ^ 2 * Fintype.card ι) / N +
216
+ ((Fintype.card τ : ℝ) * Fintype.card ι / N) *
217
+ ∑ j ∈ Finset.range k, gridCavityError H N j := by
218
+ have hN : 0 < N := Nat.pos_of_ne_zero (NeZero.ne N)
219
+ have hNr : (0 : ℝ) < N := by exact_mod_cast hN
220
+ have hb : 0 ≤ ((Fintype.card ι : ℝ) / N) * ∑ j ∈ Finset.range k, gridCavityError H N j +
221
+ ((Fintype.card ι : ℝ) * Fintype.card τ) / N := by
222
+ have := Finset.sum_nonneg (s := Finset.range k) (fun j _ => gridCavityError_nonneg H N j)
223
+ positivity
224
+ unfold gridCavityError
225
+ apply (pi_norm_le_iff_of_nonneg (by positivity)).mpr
226
+ intro ep
227
+ rw [Real.norm_eq_abs, gridMessage_exact_range H N k hk,
228
+ cavityLimit_product H ep.1 ep.2 ((k : ℝ) / N)]
229
+ unfold cavityOperator
230
+ let g : τ → ℝ := fun T => 1 - (1 / (N : ℝ)) * ∑ j ∈ Finset.range k,
231
+ ∏ f ∈ (H T).erase ep.1, gridMessage H N N j f (some T)
232
+ let q : τ → ℝ := fun T => 1 - messageIntegral H (cavityLimit H) ep.1 T ((k : ℝ) / N)
233
+ have hg : ∀ T, g T ∈ Set.Icc (0 : ℝ) 1 := by
234
+ intro T
235
+ apply uniform_subaverage_mem_unit N k hN hk
236
+ intro j _
237
+ exact ⟨Finset.prod_nonneg (fun f _ => (gridMessage_mem_unit H N N j f (some T)).1),
238
+ Finset.prod_le_one₀ (fun f _ => (gridMessage_mem_unit H N N j f (some T)).1)
239
+ (fun f _ => (gridMessage_mem_unit H N N j f (some T)).2)⟩
240
+ have hq : ∀ T, q T ∈ Set.Icc (0 : ℝ) 1 := by
241
+ intro T
242
+ have h := messageIntegral_mem_unit H _ (continuous_cavityLimit H) (cavityLimit_mem_unit H)
243
+ ep.1 T ((k : ℝ) / N)
244
+ change 1 - _ ∈ _
245
+ constructor <;> linarith [h.1, h.2]
246
+ change |(∏ T ∈ messageCandidates H ep.1 ep.2, g T) -
247
+ ∏ T ∈ messageCandidates H ep.1 ep.2, q T| ≤ _
248
+ calc
249
+ _ ≤ ∑ T ∈ messageCandidates H ep.1 ep.2, |g T - q T| :=
250
+ abs_prod_sub_prod_le_sum _ _ _ (fun T _ => hg T) (fun T _ => hq T)
251
+ _ ≤ ∑ _T ∈ messageCandidates H ep.1 ep.2,
252
+ (((Fintype.card ι : ℝ) / N) * ∑ j ∈ Finset.range k, gridCavityError H N j +
253
+ ((Fintype.card ι : ℝ) * Fintype.card τ) / N) := by
254
+ apply Finset.sum_le_sum
255
+ intro T _
256
+ dsimp only [g, q]
257
+ rw [sub_sub_sub_cancel_left, abs_sub_comm]
258
+ exact grid_message_integral_error H N k hk ep.1 T
259
+ _ ≤ (Fintype.card τ : ℝ) *
260
+ (((Fintype.card ι : ℝ) / N) * ∑ j ∈ Finset.range k, gridCavityError H N j +
261
+ ((Fintype.card ι : ℝ) * Fintype.card τ) / N) := by
262
+ simp only [Finset.sum_const, nsmul_eq_mul]
263
+ apply mul_le_mul_of_nonneg_right _ hb
264
+ exact_mod_cast Finset.card_le_univ (messageCandidates H ep.1 ep.2)
265
+ _ = _ := by unfold gridCavityError; ring
266
+
267
+ theorem gridCavityError_bound (H : τ → Finset ι) (N : ℕ) [NeZero N]
268
+ (k : ℕ) (hk : k ≤ N) :
269
+ gridCavityError H N k ≤
270
+ (((Fintype.card τ : ℝ) ^ 2 * Fintype.card ι) / N) *
271
+ Real.exp ((Fintype.card τ : ℝ) * Fintype.card ι) := by
272
+ exact discrete_volterra_exp_bound (gridCavityError H N)
273
+ ((Fintype.card τ : ℝ) * Fintype.card ι)
274
+ ((Fintype.card τ : ℝ) ^ 2 * Fintype.card ι) (by positivity) (by positivity)
275
+ N (Nat.pos_of_ne_zero (NeZero.ne N)) (gridCavityError_volterra H N) k hk
276
+
277
+ theorem gridMessage_tendsto_terminal (H : τ → Finset ι) (e : ι) (p : Option τ) :
278
+ Tendsto (fun n : ℕ => gridMessage H (n + 1) (n + 1) (n + 1) e p)
279
+ atTop (𝓝 (cavityLimit H e p 1)) := by
280
+ have hden : Tendsto (fun n : ℕ => (1 : ℝ) / ((n + 1 : ℕ) : ℝ)) atTop (𝓝 0) := by
281
+ simpa only [Nat.cast_add, Nat.cast_one] using
282
+ (tendsto_one_div_add_atTop_nhds_zero_nat :
283
+ Tendsto (fun n : ℕ => (1 : ℝ) / (n + 1)) atTop (𝓝 0))
284
+ let C : ℝ := ((Fintype.card τ : ℝ) ^ 2 * Fintype.card ι) *
285
+ Real.exp ((Fintype.card τ : ℝ) * Fintype.card ι)
286
+ have hbound : ∀ n : ℕ,
287
+ ‖gridMessage H (n + 1) (n + 1) (n + 1) e p - cavityLimit H e p 1‖ ≤
288
+ C * (1 / ((n + 1 : ℕ) : ℝ)) := by
289
+ intro n
290
+ have hn : ((n + 1 : ℕ) : ℝ) ≠ 0 := by positivity
291
+ have hx := (gridCavityError_coord H (n + 1) (n + 1) e p).trans
292
+ (gridCavityError_bound H (n + 1) (n + 1) le_rfl)
293
+ simpa only [div_self hn, Real.norm_eq_abs, C, div_eq_mul_inv, one_mul,
294
+ mul_assoc, mul_comm, mul_left_comm] using hx
295
+ apply tendsto_iff_norm_sub_tendsto_zero.mpr
296
+ exact squeeze_zero (fun n => norm_nonneg _) hbound
297
+ (by simpa using tendsto_const_nhds.mul hden)
298
+
299
+ end GridApproximation
300
+ end SharpTerminalLeave
301
+
302
+ end
303
+
304
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/GridCavityWeightLower.lean ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Queries.CanonicalCollisionSingletonSum
3
+ import OAI.Combinatorics.TriangleRemoval.Stability.ActiveCavityFactorProduct
4
+ import OAI.Combinatorics.TriangleRemoval.Stability.ContinuousCavityWeightClip
5
+ import OAI.Combinatorics.TriangleRemoval.Probability.PmfMeanLiminfTendsto
6
+
7
+ namespace OAI
8
+
9
+ section
10
+ open scoped BigOperators Topology Matrix.Norms.Operator
11
+ open MeasureTheory
12
+ open scoped BigOperators
13
+ open scoped BigOperators ENNReal Classical
14
+ open Filter MeasureTheory
15
+ open Filter
16
+ open scoped BigOperators Topology
17
+
18
+ namespace SharpTerminalLeave
19
+
20
+ lemma grid_cavityWeight_lower {D : ℝ} (hD : 0 ≤ D) (N : ℕ) [NeZero N] :
21
+ ∀ t ≤ N, 1 ≤ (1+2*D)*cavityWeight D ((t : ℝ)/N) := by
22
+ intro t ht
23
+ have hNr : (0 : ℝ) < N := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne N)
24
+ have hmem : (t : ℝ)/N ∈ Set.Icc (0 : ℝ) 1 :=
25
+ ⟨by positivity,(div_le_one hNr).mpr (by exact_mod_cast ht)⟩
26
+ have hh := mul_le_mul_of_nonneg_left (cavityWeight_lower hD hmem)
27
+ (show 0 ≤ 1+2*D by positivity)
28
+ have heq : (1+2*D)*cavityWeight D 1 = 1 := by
29
+ unfold cavityWeight
30
+ rw [mul_one,mul_one_div_cancel (by positivity : 1+2*D ≠ 0)]
31
+ rwa [heq] at hh
32
+
33
+ lemma grid_collision_majorant_tendsto (K : ℝ) {D : ℝ} (hD : 0 < D) :
34
+ Tendsto (fun j : ℕ => (K*(1+2*D)^3/D^50)*
35
+ Real.exp (45*D*prefixWeight (fun t => (2/((j+1 : ℕ) : ℝ))*
36
+ cavityWeight D ((t : ℝ)/(j+1 : ℕ))) (j+1)))
37
+ atTop (𝓝 (K*(1+2*D)^48/D^50)) := by
38
+ have hh := (Real.continuous_exp.continuousAt.tendsto.comp
39
+ ((grid_prefixWeight_tendsto hD).const_mul (45*D))).const_mul
40
+ (K*(1+2*D)^3/D^50)
41
+ have he : (K*(1+2*D)^3/D^50)*Real.exp (45*D*(2*witnessMu D)) =
42
+ K*(1+2*D)^48/D^50 := by
43
+ calc
44
+ _ = K*((1+2*D)^3*Real.exp (45*D*(2*witnessMu D)))/D^50 := by ring
45
+ _ = _ := by rw [collision_exponential_identity hD]
46
+ rwa [he] at hh
47
+
48
+ theorem averaged_disjoint_collisionCost (c₀ C₀ : ℝ) (hc₀ : 0 < c₀) :
49
+ ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c₀ C₀ G →
50
+ ∀ hne : G.Nonempty,
51
+ pmfMean (PMF.uniformOfFinset G hne) (fun e =>
52
+ pmfMean (PMF.uniformOfFinset G hne) (fun f => if Disjoint e f then
53
+ collisionCost (triangleHypergraph G) {e,f} none else 0)) ≤
54
+ 65536*(1+2*prefixD n)^48/prefixD n^50 := by
55
+ classical
56
+ filter_upwards [averaged_disjoint_grid_collision c₀ C₀ hc₀,
57
+ goodPrefix_full_grid_rows hc₀,goodPrefix_full_continuous_rows hc₀] with n hfinite hrows hn
58
+ intro G hGood hne
59
+ let D := prefixD n
60
+ let P := PMF.uniformOfFinset G hne
61
+ let PP := P.bind (fun e => P.map (Prod.mk e))
62
+ let f : (Finset (Fin n) × Finset (Fin n)) → ℕ → ℝ := fun ef j =>
63
+ if Disjoint ef.1 ef.2 then gridCollision (triangleHypergraph G) {ef.1,ef.2} none j else 0
64
+ let g : ℕ → ℝ := fun j => (65536*(1+2*D)^3/D^50)*
65
+ Real.exp (45*D*prefixWeight (fun t => (2/((j+1 : ℕ) : ℝ))*
66
+ cavityWeight D ((t : ℝ)/(j+1 : ℕ))) (j+1))
67
+ have hbound (ef : Finset (Fin n) × Finset (Fin n)) (j : ℕ) : 0 ≤ f ef j := by
68
+ dsimp only [f]
69
+ split_ifs <;> first | exact (gridCollision_mem_unit _ _ _ _).1 | rfl
70
+ obtain ⟨N₀,hN₀⟩ := hrows C₀ G hGood
71
+ have hupper : ∀ᶠ j : ℕ in atTop, pmfMean PP (fun ef => f ef j) ≤ g j := by
72
+ filter_upwards [eventually_ge_atTop N₀] with j hj
73
+ dsimp only [PP]
74
+ rw [pmfMean_bind]
75
+ simp_rw [pmfMean_map]
76
+ have hh := hfinite G hGood hne (j+1)
77
+ (fun t => cavityWeight D ((t : ℝ)/(j+1 : ℕ)))
78
+ (fun t => (cavityWeight_pos hn.1.le (by positivity)).le)
79
+ (hN₀ (j+1) (by omega)) (1+2*D)
80
+ (by dsimp only [D]; linarith [hn.1]) (grid_cavityWeight_lower hn.1.le (j+1))
81
+ (j+1) (j+1) le_rfl le_rfl
82
+ simpa only [gridCollision_eq_trace,P,f,g,D] using hh
83
+ have hh := pmfMean_liminf_le_of_tendsto_upper PP f hbound g
84
+ (grid_collision_majorant_tendsto 65536 hn.1) hupper
85
+ dsimp only [PP] at hh
86
+ rw [pmfMean_bind] at hh
87
+ simp_rw [pmfMean_map] at hh
88
+ have hf (e f' : Finset (Fin n)) : Filter.liminf (f (e,f')) atTop =
89
+ if Disjoint e f' then collisionCost (triangleHypergraph G) {e,f'} none else 0 := by
90
+ by_cases hd : Disjoint e f'
91
+ · simp only [f,hd,ite_true,collisionCost]
92
+ · simp only [f,hd,ite_false,Filter.liminf_const]
93
+ simp_rw [hf] at hh
94
+ exact hh
95
+
96
+ theorem averaged_singleton_collisionCost (c₀ C₀ : ℝ) (hc₀ : 0 < c₀) :
97
+ ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c₀ C₀ G →
98
+ ∀ hne : G.Nonempty,
99
+ pmfMean (PMF.uniformOfFinset G hne) (fun e =>
100
+ collisionCost (triangleHypergraph G) {e} none) ≤
101
+ 8192*(1+2*prefixD n)^48/prefixD n^50 := by
102
+ classical
103
+ filter_upwards [averaged_singleton_grid_collision c₀ C₀ hc₀,
104
+ goodPrefix_full_grid_rows hc₀,goodPrefix_full_continuous_rows hc₀] with n hfinite hrows hn
105
+ intro G hGood hne
106
+ let D := prefixD n
107
+ let P := PMF.uniformOfFinset G hne
108
+ let f : Finset (Fin n) → ℕ → ℝ := fun e j => gridCollision (triangleHypergraph G) {e} none j
109
+ let g : ℕ → ℝ := fun j => (8192*(1+2*D)^3/D^50)*
110
+ Real.exp (45*D*prefixWeight (fun t => (2/((j+1 : ℕ) : ℝ))*
111
+ cavityWeight D ((t : ℝ)/(j+1 : ℕ))) (j+1))
112
+ have hbound (e : Finset (Fin n)) (j : ℕ) : 0 ≤ f e j :=
113
+ (gridCollision_mem_unit _ _ _ _).1
114
+ obtain ⟨N₀,hN₀⟩ := hrows C₀ G hGood
115
+ have hupper : ∀ᶠ j : ℕ in atTop, pmfMean P (fun e => f e j) ≤ g j := by
116
+ filter_upwards [eventually_ge_atTop N₀] with j hj
117
+ have hh := hfinite G hGood hne (j+1)
118
+ (fun t => cavityWeight D ((t : ℝ)/(j+1 : ℕ)))
119
+ (fun t => (cavityWeight_pos hn.1.le (by positivity)).le)
120
+ (hN₀ (j+1) (by omega)) (1+2*D)
121
+ (by dsimp only [D]; linarith [hn.1]) (grid_cavityWeight_lower hn.1.le (j+1))
122
+ (j+1) (j+1) le_rfl le_rfl
123
+ simpa only [gridCollision_eq_trace,P,f,g,D] using hh
124
+ exact pmfMean_liminf_le_of_tendsto_upper P f hbound g
125
+ (grid_collision_majorant_tendsto 8192 hn.1) hupper
126
+
127
+ end SharpTerminalLeave
128
+
129
+ end
130
+
131
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/MovingPerturbationFiniteExpansion.lean ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ namespace OAI
4
+
5
+ section
6
+ noncomputable section
7
+ open scoped BigOperators
8
+
9
+ namespace SharpTerminalLeave
10
+
11
+ theorem moving_perturbation_finite_expansion {X : Type*} [AddCommGroup X] [Module ℝ X]
12
+ (V : Module.End ℝ X) (x y : X) (h : x = y + V x) (K : ℕ) :
13
+ x = (∑ j ∈ Finset.range K, (V^j) y) + (V^K) x := by
14
+ induction K with
15
+ | zero => simp
16
+ | succ K ih =>
17
+ rw [Finset.sum_range_succ, pow_succ]
18
+ calc
19
+ x = (∑ j ∈ Finset.range K, (V^j) y) + (V^K) x := ih
20
+ _ = (∑ j ∈ Finset.range K, (V^j) y) + (V^K) (y + V x) := by rw [← h]
21
+ _ = _ := by simp [Module.End.mul_apply, add_assoc]
22
+
23
+ lemma seminorm_end_pow_le {X : Type*} [AddCommGroup X] [Module ℝ X]
24
+ (p : Seminorm ℝ X) (V : Module.End ℝ X) {A : ℝ} (hA : 0 ≤ A)
25
+ (hV : ∀ x, p (V x) ≤ A * p x) (K : ℕ) (x : X) :
26
+ p ((V^K) x) ≤ A^K * p x := by
27
+ induction K with
28
+ | zero => simp
29
+ | succ K ih =>
30
+ rw [pow_succ',Module.End.mul_apply,pow_succ']
31
+ exact (hV _).trans (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_left ih hA)
32
+
33
+ lemma seminorm_finset_sum_le {X I : Type*} [AddCommGroup X] [Module ℝ X]
34
+ (p : Seminorm ℝ X) (s : Finset I) (f : I → X) :
35
+ p (∑ i ∈ s, f i) ≤ ∑ i ∈ s, p (f i) := by
36
+ classical
37
+ induction s using Finset.induction_on with
38
+ | empty => simp
39
+ | @insert i s hi ih =>
40
+ simp only [Finset.sum_insert hi]
41
+ exact (map_add_le_add p _ _).trans (add_le_add le_rfl ih)
42
+
43
+ theorem moving_perturbation_mixed_norm_bound {X : Type*} [AddCommGroup X] [Module ℝ X]
44
+ (p q : Seminorm ℝ X) (V : Module.End ℝ X) (x y : X)
45
+ {A B C : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B)
46
+ (hVp : ∀ z, p (V z) ≤ A * p z) (hVq : ∀ z, q (V z) ≤ B * q z)
47
+ (hpq : ∀ z, p z ≤ q z) (hqp : ∀ z, q z ≤ C * p z)
48
+ (h : x = y + V x) (K : ℕ) :
49
+ p x ≤ (∑ j ∈ Finset.range K, A^j) * p y + B^K * C * p x := by
50
+ have he := moving_perturbation_finite_expansion V x y h K
51
+ calc
52
+ p x = p ((∑ j ∈ Finset.range K, (V^j) y) + (V^K) x) := congrArg p he
53
+ _ ≤ p (∑ j ∈ Finset.range K, (V^j) y) + p ((V^K) x) := map_add_le_add p _ _
54
+ _ ≤ (∑ j ∈ Finset.range K, p ((V^j) y)) + q ((V^K) x) :=
55
+ add_le_add (seminorm_finset_sum_le p _ _) (hpq _)
56
+ _ ≤ (∑ j ∈ Finset.range K, A^j * p y) + B^K * q x :=
57
+ add_le_add (Finset.sum_le_sum (fun j _ => seminorm_end_pow_le p V hA hVp j y))
58
+ (seminorm_end_pow_le q V hB hVq K x)
59
+ _ ≤ (∑ j ∈ Finset.range K, A^j * p y) + B^K * (C * p x) :=
60
+ add_le_add le_rfl (mul_le_mul_of_nonneg_left (hqp x) (pow_nonneg hB K))
61
+ _ = _ := by rw [Finset.sum_mul]; ring
62
+
63
+ theorem moving_perturbation_mixed_norm_absorb {X : Type*} [AddCommGroup X] [Module ℝ X]
64
+ (p q : Seminorm ℝ X) (V : Module.End ℝ X) (x y : X)
65
+ {A B C : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B)
66
+ (hVp : ∀ z, p (V z) ≤ A * p z) (hVq : ∀ z, q (V z) ≤ B * q z)
67
+ (hpq : ∀ z, p z ≤ q z) (hqp : ∀ z, q z ≤ C * p z)
68
+ (h : x = y + V x) (K : ℕ) (hK : B^K*C ≤ 1/2) :
69
+ p x ≤ 2*(∑ j ∈ Finset.range K, A^j)*p y := by
70
+ have hb := moving_perturbation_mixed_norm_bound p q V x y hA hB hVp hVq hpq hqp h K
71
+ have hp : 0 ≤ p x := apply_nonneg p x
72
+ have ht := mul_le_mul_of_nonneg_right hK hp
73
+ nlinarith only [hb,ht]
74
+
75
+ theorem moving_perturbation_mixed_norm_absorb_modulo {X : Type*} [AddCommGroup X] [Module ℝ X]
76
+ (p q : Seminorm ℝ X) (V : Module.End ℝ X) (x y : X)
77
+ {A B C : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B)
78
+ (hVp : ∀ z, p (V z) ≤ A * p z) (hVq : ∀ z, q (V z) ≤ B * q z)
79
+ (hpq : ∀ z, p z ≤ q z) (hqp : ∀ z, q z ≤ C * p z)
80
+ (h : p (x-y-V x) = 0) (K : ℕ) (hK : B^K*C ≤ 1/2) :
81
+ p x ≤ 2*(∑ j ∈ Finset.range K, A^j)*p y := by
82
+ let z := x-y-V x
83
+ have he : x = (y+z)+V x := by dsimp only [z]; abel
84
+ have hb := moving_perturbation_mixed_norm_absorb p q V x (y+z) hA hB hVp hVq hpq hqp he K hK
85
+ have hy : p (y+z) ≤ p y := by
86
+ have hh := map_add_le_add p y z
87
+ change p z = 0 at h
88
+ linarith only [hh,h]
89
+ apply hb.trans
90
+ exact mul_le_mul_of_nonneg_left hy (by positivity)
91
+
92
+ end SharpTerminalLeave
93
+ end
94
+ end
95
+
96
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/MovingResidualForcing.lean ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Stability.MovingPerturbationFiniteExpansion
3
+ import OAI.Combinatorics.TriangleRemoval.Asymptotics.ActiveL2Map
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ noncomputable section
9
+ open scoped BigOperators
10
+
11
+ namespace SharpTerminalLeave
12
+ open Classical
13
+
14
+ lemma moving_active_subset {E : Type*} (active : ℕ → Finset E) (T : ℕ)
15
+ (hnest : ∀ k < T, active (k+1) ⊆ active k) {i j : ℕ} (hij : i ≤ j) (hj : j ≤ T) :
16
+ active j ⊆ active i := by
17
+ induction j, hij using Nat.le_induction with
18
+ | base => exact Finset.Subset.refl _
19
+ | succ k hik ih => exact (hnest k (by omega)).trans (ih (by omega))
20
+
21
+ lemma activeLinf_mono {E : Type*} [Fintype E] {s t : Finset E} (h : s ⊆ t) (x : E → ℝ) :
22
+ activeLinf s x ≤ activeLinf t x :=
23
+ activeLinf_bound s x (apply_nonneg _ _) (fun _ he => activeLinf_coordinate t x (h he))
24
+
25
+ noncomputable def movingResidualForcing {E : Type*} [Fintype E]
26
+ (a : ℕ → ℝ) (R : ℕ → Module.End ℝ (E → ℝ)) : Module.End ℝ (ℕ → E → ℝ) where
27
+ toFun x t := ∑ i ∈ Finset.range t, (-a i) • (R i (x i))
28
+ map_add' x y := by
29
+ funext t
30
+ simp only [Pi.add_apply,map_add,smul_add,Finset.sum_add_distrib]
31
+ map_smul' c x := by
32
+ funext t
33
+ simp only [Pi.smul_apply,map_smul,smul_comm (-a _) c,Finset.smul_sum,RingHom.id_apply]
34
+
35
+ lemma movingResidualForcing_zero {E : Type*} [Fintype E]
36
+ (a : ℕ → ℝ) (R : ℕ → Module.End ℝ (E → ℝ)) (x : ℕ → E → ℝ) :
37
+ movingResidualForcing a R x 0 = 0 := by simp [movingResidualForcing]
38
+
39
+ lemma movingResidualForcing_succ {E : Type*} [Fintype E]
40
+ (a : ℕ → ℝ) (R : ℕ → Module.End ℝ (E → ℝ)) (x : ℕ → E → ℝ) (t : ℕ) :
41
+ movingResidualForcing a R x (t+1) = movingResidualForcing a R x t-a t • R t (x t) := by
42
+ simp [movingResidualForcing,Finset.sum_range_succ,sub_eq_add_neg,add_comm]
43
+
44
+ lemma movingResidualForcing_bound {E : Type*} [Fintype E]
45
+ (P : ℕ → Seminorm ℝ (E → ℝ)) (a : ℕ → ℝ) (R : ℕ → Module.End ℝ (E → ℝ))
46
+ (T : ℕ) (ha : ∀ i < T, 0 ≤ a i)
47
+ (hmono : ∀ i j, i ≤ j → j ≤ T → ∀ x, P j x ≤ P i x)
48
+ {B : ℝ} (hB : 0 ≤ B) (hR : ∀ i < T, ∀ x, P i (R i x) ≤ B*P i x)
49
+ (x : ℕ → E → ℝ) :
50
+ trajectorySeminorm P T (movingResidualForcing a R x) ≤
51
+ (∑ i ∈ Finset.range T, a i)*B*trajectorySeminorm P T x := by
52
+ have hS : 0 ≤ ∑ i ∈ Finset.range T, a i :=
53
+ Finset.sum_nonneg (fun i hi => ha i (Finset.mem_range.mp hi))
54
+ have hx0 := apply_nonneg (trajectorySeminorm P T) x
55
+ apply trajectorySeminorm_bound _ _ _ (by positivity)
56
+ intro t ht
57
+ change P t (∑ i ∈ Finset.range t, (-a i) • R i (x i)) ≤ _
58
+ calc
59
+ _ ≤ ∑ i ∈ Finset.range t, P t ((-a i) • R i (x i)) := seminorm_finset_sum_le _ _ _
60
+ _ ≤ ∑ i ∈ Finset.range t, a i*(B*trajectorySeminorm P T x) := by
61
+ apply Finset.sum_le_sum
62
+ intro i hi
63
+ have hit : i < t := Finset.mem_range.mp hi
64
+ have hiT : i < T := by omega
65
+ rw [map_smul_eq_mul,Real.norm_eq_abs,abs_neg,abs_of_nonneg (ha i hiT)]
66
+ apply mul_le_mul_of_nonneg_left _ (ha i hiT)
67
+ exact (hmono i t hit.le ht _).trans ((hR i hiT _).trans
68
+ (mul_le_mul_of_nonneg_left (trajectorySeminorm_at P T x (by omega)) hB))
69
+ _ ≤ ∑ i ∈ Finset.range T, a i*(B*trajectorySeminorm P T x) :=
70
+ Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono ht)
71
+ (fun i hi _ => mul_nonneg (ha i (Finset.mem_range.mp hi)) (mul_nonneg hB hx0))
72
+ _ = _ := by rw [← Finset.sum_mul]; ring
73
+
74
+ lemma movingStar_actual_response {E V : Type*} [Fintype E] [Fintype V]
75
+ (ends : E → Finset V) (active : ℕ → Finset E) (a : ℕ → ℝ)
76
+ (R : ℕ → Module.End ℝ (E → ℝ)) (M x : ℕ → E → ℝ) (T : ℕ)
77
+ (hnest : ∀ k < T, active (k+1) ⊆ active k)
78
+ (hinit : ∀ e ∈ active 0, x 0 e = M 0 e)
79
+ (hstep : ∀ k < T, ∀ e ∈ active (k+1), x (k+1) e = x k e -
80
+ a k*(movingStarLift ends (movingStarMean ends (active k) (x k)) e+R k (x k) e) +
81
+ (M (k+1) e-M k e)) :
82
+ trajectorySeminorm (fun t => activeLinf (active t)) T
83
+ (x-movingStarResponse ends active a M-
84
+ movingStarResponse ends active a (movingResidualForcing a R x)) = 0 := by
85
+ let F := M+movingResidualForcing a R x
86
+ have hi : ∀ e ∈ active 0, x 0 e = F 0 e := by
87
+ intro e he
88
+ simp only [F,Pi.add_apply,movingResidualForcing_zero,Pi.zero_apply,add_zero]
89
+ exact hinit e he
90
+ have hs : ∀ k < T, ∀ e ∈ active (k+1), x (k+1) e = x k e -
91
+ a k*movingStarLift ends (movingStarMean ends (active k) (x k)) e + (F (k+1) e-F k e) := by
92
+ intro k hk e he
93
+ rw [hstep k hk e he]
94
+ simp only [F,Pi.add_apply,movingResidualForcing_succ,Pi.sub_apply,Pi.smul_apply,smul_eq_mul]
95
+ ring
96
+ apply le_antisymm _ (apply_nonneg _ _)
97
+ apply trajectorySeminorm_bound _ _ _ le_rfl
98
+ intro t ht
99
+ apply activeLinf_bound _ _ le_rfl
100
+ intro e he
101
+ have h₁ := movingStar_trajectory_representation ends active a F x t
102
+ (fun k hk => hnest k (by omega)) hi (fun k hk => hs k (by omega)) e he
103
+ have h₂ := movingStar_trajectory_representation ends active a F
104
+ (movingStarSolve ends active a F) t (fun k hk => hnest k (by omega))
105
+ (fun _ _ => rfl) (fun _ _ _ _ => rfl) e he
106
+ have h_eq : x t e = movingStarResponse ends active a F t e := h₁.trans h₂.symm
107
+ change |x t e-movingStarResponse ends active a M t e-
108
+ movingStarResponse ends active a (movingResidualForcing a R x) t e| ≤ 0
109
+ have hadd := congrFun (congrFun (map_add (movingStarResponse ends active a)
110
+ M (movingResidualForcing a R x)) t) e
111
+ change movingStarResponse ends active a F t e = _ at hadd
112
+ rw [h_eq,hadd]
113
+ simp
114
+
115
+ theorem movingStar_mixed_stability {E V : Type*} [Fintype E] [Fintype V]
116
+ (ends : E → Finset V) (hends : ∀ e, (ends e).card = 2)
117
+ (active : ℕ → Finset E) (a : ℕ → ℝ) (R : ℕ → Module.End ℝ (E → ℝ))
118
+ (M x : ℕ → E → ℝ) (T K : ℕ)
119
+ (hnest : ∀ k < T, active (k+1) ⊆ active k)
120
+ (ha : ∀ k < T, 0 ≤ a k ∧ a k ≤ 1)
121
+ (hinit : ∀ e ∈ active 0, x 0 e = M 0 e)
122
+ (hstep : ∀ k < T, ∀ e ∈ active (k+1), x (k+1) e = x k e -
123
+ a k*(movingStarLift ends (movingStarMean ends (active k) (x k)) e+R k (x k) e) +
124
+ (M (k+1) e-M k e))
125
+ {B δ : ℝ} (hB : 0 ≤ B) (hδ : 0 ≤ δ)
126
+ (hRinf : ∀ k < T, ∀ z, activeLinf (active k) (R k z) ≤ B*activeLinf (active k) z)
127
+ (hR₂ : ∀ k < T, ∀ z, activeL2 (active k) (R k z) ≤ δ*activeL2 (active k) z)
128
+ (hK : ((1+2*∑ k ∈ Finset.range T, a k)*(∑ k ∈ Finset.range T, a k)*δ)^K*
129
+ (Fintype.card E : ℝ) ≤ 1/2) :
130
+ trajectorySeminorm (fun t => activeLinf (active t)) T x ≤
131
+ 2*(∑ j ∈ Finset.range K,
132
+ ((1+2*∑ k ∈ Finset.range T, a k)*(∑ k ∈ Finset.range T, a k)*B)^j)*
133
+ (1+2*∑ k ∈ Finset.range T, a k)*trajectorySeminorm (fun t => activeLinf (active t)) T M := by
134
+ let p := trajectorySeminorm (fun t => activeLinf (active t)) T
135
+ let q := trajectorySeminorm (fun t => activeL2 (active t)) T
136
+ let V₁ := (movingStarResponse ends active a).comp (movingResidualForcing a R)
137
+ let S := ∑ k ∈ Finset.range T, a k
138
+ let L := 1+2*S
139
+ have hS : 0 ≤ S := Finset.sum_nonneg (fun k hk => (ha k (Finset.mem_range.mp hk)).1)
140
+ have hL : 0 ≤ L := by dsimp [L]; positivity
141
+ have hVp : ∀ z, p (V₁ z) ≤ L*S*B*p z := by
142
+ intro z
143
+ have hb := movingStarResponse_linf ends hends active a T hnest ha (movingResidualForcing a R z)
144
+ have hf := movingResidualForcing_bound (fun t => activeLinf (active t)) a R T
145
+ (fun k hk => (ha k hk).1)
146
+ (fun i j hij hj z => activeLinf_mono (moving_active_subset active T hnest hij hj) z) hB hRinf z
147
+ exact hb.trans (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_left hf hL)
148
+ have hVq : ∀ z, q (V₁ z) ≤ L*S*δ*q z := by
149
+ intro z
150
+ have hb := movingStarResponse_l2 ends hends active a T hnest ha (movingResidualForcing a R z)
151
+ have hf := movingResidualForcing_bound (fun t => activeL2 (active t)) a R T
152
+ (fun k hk => (ha k hk).1)
153
+ (fun i j hij hj z => activeL2_mono (moving_active_subset active T hnest hij hj) z) hδ hR₂ z
154
+ exact hb.trans (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_left hf hL)
155
+ have hb := moving_perturbation_mixed_norm_absorb_modulo p q V₁ x
156
+ (movingStarResponse ends active a M) (by positivity : 0 ≤ L*S*B) (by positivity : 0 ≤ L*S*δ)
157
+ hVp hVq (fun z => (trajectory_mixed_seminorms active T z).1)
158
+ (fun z => (trajectory_mixed_seminorms active T z).2)
159
+ (movingStar_actual_response ends active a R M x T hnest hinit hstep) K hK
160
+ have hy := movingStarResponse_linf ends hends active a T hnest ha M
161
+ apply hb.trans
162
+ calc
163
+ _ ≤ 2*(∑ j ∈ Finset.range K, (L*S*B)^j)*(L*p M) :=
164
+ mul_le_mul_of_nonneg_left hy (by positivity)
165
+ _ = _ := by dsimp only [p,L,S]; ring
166
+
167
+ end SharpTerminalLeave
168
+ end
169
+ end
170
+
171
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/RelativeTemplateResidual.lean ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.RelativeScaleBudget
3
+ import OAI.Combinatorics.TriangleRemoval.Process.TriangleLiftCount
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ open scoped BigOperators Topology Matrix.Norms.Operator
9
+ open MeasureTheory
10
+ open scoped BigOperators
11
+ open scoped BigOperators ENNReal Classical
12
+ open Filter MeasureTheory
13
+ open Filter
14
+ open scoped BigOperators Topology
15
+
16
+ namespace SharpTerminalLeave
17
+
18
+ noncomputable def relativeTemplateResidual {n : ℕ} {α : Type*} [Fintype α]
19
+ (required : α → Graph n) (s : ℕ → ℝ) (T j : ℕ)
20
+ (ω : History (Graph n) T) : ℝ :=
21
+ copyCount required (ω (historyIndex T j))/s j -
22
+ copyCount required (ω (historyIndex T 0))/s 0 -
23
+ historyNoise (fun _ => step) (fun k H => copyCount required H/s k) T j ω +
24
+ historyCounter (fun k G => triangleLiftCount required G/
25
+ ((triangles G).card*s (k+1))) T j ω -
26
+ ∑ k ∈ Finset.range j,
27
+ copyCount required (ω (historyIndex T k))*(1/s (k+1)-1/s k)
28
+
29
+ lemma relativeTemplateResidual_eq {n : ℕ} {α : Type*} [Fintype α]
30
+ (required : α → Graph n) (s : ℕ → ℝ) (T j : ℕ) (hj : j ≤ T)
31
+ (ω : History (Graph n) T) :
32
+ relativeTemplateResidual required s T j ω = historyCounter
33
+ (fun k G => (pmfMean (step G) (copyCount required)-copyCount required G+
34
+ triangleLiftCount required G/(triangles G).card)/s (k+1)) T j ω := by
35
+ have hid := history_relative_loss_counter (fun _ => step) (copyCount required) s T j hj ω
36
+ have hsum : historyCounter
37
+ (fun k G => (pmfMean (step G) (copyCount required)-copyCount required G+
38
+ triangleLiftCount required G/(triangles G).card)/s (k+1)) T j ω =
39
+ historyCounter (fun k G => triangleLiftCount required G/
40
+ ((triangles G).card*s (k+1))) T j ω -
41
+ historyCounter (fun k G => (copyCount required G-
42
+ pmfMean (step G) (copyCount required))/s (k+1)) T j ω := by
43
+ unfold historyCounter
44
+ rw [← Finset.sum_sub_distrib]
45
+ apply Finset.sum_congr rfl
46
+ intro k _
47
+ simp only [div_eq_mul_inv,mul_inv_rev]
48
+ ring
49
+ rw [hsum,hid]
50
+ unfold relativeTemplateResidual
51
+ ring
52
+
53
+ theorem history_relative_template_hierarchy {n : ℕ} {α : Type*} [Fintype α]
54
+ (required : α → Graph n) (b : ℕ) (hsize : ∀ a, (required a).card ≤ b)
55
+ (s : ℕ → ℝ) (T j : ℕ) (hj : j ≤ T) (hs : ∀ k < j, 0 < s (k+1))
56
+ (ω : History (Graph n) T) :
57
+ 0 ≤ relativeTemplateResidual required s T j ω ∧
58
+ relativeTemplateResidual required s T j ω ≤ historyCounter
59
+ (fun k G => ((b : ℝ)^2/(triangles G).card*copyCount required G)/s (k+1)) T j ω := by
60
+ rw [relativeTemplateResidual_eq required s T j hj]
61
+ constructor
62
+ · apply Finset.sum_nonneg
63
+ intro k hk
64
+ have hkj : k < j := by simpa only [Nat.min_eq_left hj,Finset.mem_range] using hk
65
+ exact div_nonneg (copyCount_triangleLift_drift_all required
66
+ (ω (historyIndex T k)) b hsize).1 (hs k hkj).le
67
+ · apply Finset.sum_le_sum
68
+ intro k hk
69
+ have hkj : k < j := by simpa only [Nat.min_eq_left hj,Finset.mem_range] using hk
70
+ exact div_le_div_of_nonneg_right (copyCount_triangleLift_drift_all required
71
+ (ω (historyIndex T k)) b hsize).2 (hs k hkj).le
72
+
73
+ end SharpTerminalLeave
74
+
75
+ end
76
+
77
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Stability/Volterra.lean ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ namespace OAI
4
+
5
+ section
6
+ open scoped BigOperators Topology Matrix.Norms.Operator
7
+ open MeasureTheory
8
+
9
+ namespace SharpTerminalLeave
10
+
11
+ theorem exp_neg_smul_perturbation {A : Type*} [NormedRing A]
12
+ [NormedAlgebra ℝ A] [CompleteSpace A] (P R : A) (s : ℝ) :
13
+ NormedSpace.exp ((-s) • (P + R)) = NormedSpace.exp ((-s) • P) -
14
+ ∫ t in (0 : ℝ)..s,
15
+ NormedSpace.exp ((t - s) • P) * R * NormedSpace.exp ((-t) • (P + R)) := by
16
+ let f : ℝ → A := fun t =>
17
+ NormedSpace.exp ((t - s) • P) * NormedSpace.exp ((-t) • (P + R))
18
+ let g : ℝ → A := fun t =>
19
+ NormedSpace.exp ((t - s) • P) * R * NormedSpace.exp ((-t) • (P + R))
20
+ have hd : ∀ t, HasDerivAt f (-g t) t := by
21
+ intro t
22
+ have h1 := (hasDerivAt_exp_smul_const (𝕂 := ℝ) P (t - s)).scomp t
23
+ ((hasDerivAt_id t).sub_const s)
24
+ have h2 := (hasDerivAt_exp_smul_const' (𝕂 := ℝ) (P + R) (-t)).scomp t
25
+ ((hasDerivAt_id t).neg)
26
+ have hh := h1.mul h2
27
+ simp only [Function.comp_apply, id_eq, one_smul, neg_one_smul] at hh
28
+ convert hh using 1
29
+ · rfl
30
+ · dsimp [g]
31
+ noncomm_ring
32
+ have hg : Continuous (fun t => -g t) := by
33
+ have hP := (differentiable_exp_smul_const ℝ P).continuous
34
+ have hA := (differentiable_exp_smul_const ℝ (P + R)).continuous
35
+ exact (((hP.comp (continuous_id.sub continuous_const)).mul continuous_const).mul
36
+ (hA.comp continuous_neg)).neg
37
+ have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt
38
+ (a := 0) (b := s) (fun t _ => hd t) (hg.intervalIntegrable 0 s)
39
+ simp only [f, sub_self, zero_smul, NormedSpace.exp_zero, one_mul,
40
+ neg_zero, mul_one, zero_sub, intervalIntegral.integral_neg] at hi
41
+ change _ = _ - ∫ t in (0 : ℝ)..s, g t
42
+ rw [neg_eq_iff_eq_neg.mp hi]
43
+ abel
44
+
45
+ section Volterra
46
+ variable {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] [CompleteSpace A]
47
+
48
+ noncomputable def volterra (P R : A) (f : ℝ → A) (s : ℝ) : A :=
49
+ ∫ t in (0 : ℝ)..s, NormedSpace.exp ((t - s) • P) * R * f t
50
+
51
+ noncomputable def volterraIter (P R : A) (f : ℝ → A) : ℕ → ℝ → A
52
+ | 0 => f
53
+ | k + 1 => volterra P R (volterraIter P R f k)
54
+
55
+ theorem continuous_volterra_integrand (P R : A) {f : ℝ → A}
56
+ (hf : Continuous f) :
57
+ Continuous (fun q : ℝ × ℝ => NormedSpace.exp ((q.2 - q.1) • P) * R * f q.2) :=
58
+ (((differentiable_exp_smul_const ℝ P).continuous.comp
59
+ (continuous_snd.sub continuous_fst)).mul continuous_const).mul (hf.comp continuous_snd)
60
+
61
+ theorem continuous_volterra (P R : A) {f : ℝ → A} (hf : Continuous f) :
62
+ Continuous (volterra P R f) :=
63
+ intervalIntegral.continuous_parametric_intervalIntegral_of_continuous
64
+ (continuous_volterra_integrand P R hf) continuous_id
65
+
66
+ theorem continuous_volterraIter (P R : A) {f : ℝ → A} (hf : Continuous f) (k : ℕ) :
67
+ Continuous (volterraIter P R f k) := by
68
+ induction k with
69
+ | zero => exact hf
70
+ | succ k ih => exact continuous_volterra P R ih
71
+
72
+ theorem volterra_sub (P R : A) {f g : ℝ → A} (hf : Continuous f) (hg : Continuous g) :
73
+ volterra P R (fun t => f t - g t) = fun s => volterra P R f s - volterra P R g s := by
74
+ funext s
75
+ simp only [volterra, mul_sub]
76
+ apply intervalIntegral.integral_sub
77
+ · exact ((continuous_volterra_integrand P R hf).comp
78
+ (continuous_const.prodMk continuous_id)).intervalIntegrable 0 s
79
+ · exact ((continuous_volterra_integrand P R hg).comp
80
+ (continuous_const.prodMk continuous_id)).intervalIntegrable 0 s
81
+
82
+ theorem volterraIter_sub (P R : A) {f g : ℝ → A} (hf : Continuous f) (hg : Continuous g)
83
+ (k : ℕ) : volterraIter P R (fun t => f t - g t) k =
84
+ fun s => volterraIter P R f k s - volterraIter P R g k s := by
85
+ induction k with
86
+ | zero => rfl
87
+ | succ k ih =>
88
+ simp only [volterraIter, ih]
89
+ exact volterra_sub P R (continuous_volterraIter P R hf k)
90
+ (continuous_volterraIter P R hg k)
91
+
92
+ omit [CompleteSpace A] in
93
+ theorem volterraIter_shift (P R : A) (f : ℝ → A) (k : ℕ) :
94
+ volterraIter P R (volterra P R f) k = volterraIter P R f (k + 1) := by
95
+ induction k with
96
+ | zero => rfl
97
+ | succ k ih => simp only [volterraIter, ih]
98
+
99
+ theorem perturbation_iteration (P R : A) (k : ℕ) :
100
+ volterraIter P R (fun t => NormedSpace.exp ((-t) • (P + R))) k =
101
+ fun s => volterraIter P R (fun t => NormedSpace.exp ((-t) • P)) k s -
102
+ volterraIter P R (fun t => NormedSpace.exp ((-t) • (P + R))) (k + 1) s := by
103
+ have h0 : Continuous (fun t : ℝ => NormedSpace.exp ((-t) • P)) :=
104
+ (differentiable_exp_smul_const ℝ P).continuous.comp continuous_neg
105
+ have h1 : Continuous (fun t : ℝ => NormedSpace.exp ((-t) • (P + R))) :=
106
+ (differentiable_exp_smul_const ℝ (P + R)).continuous.comp continuous_neg
107
+ have heq : (fun t : ℝ => NormedSpace.exp ((-t) • (P + R))) =
108
+ fun s => NormedSpace.exp ((-s) • P) -
109
+ volterra P R (fun t => NormedSpace.exp ((-t) • (P + R))) s := by
110
+ funext s
111
+ exact exp_neg_smul_perturbation P R s
112
+ conv_lhs => rw [heq]
113
+ rw [volterraIter_sub P R h0 (continuous_volterra P R h1), volterraIter_shift]
114
+
115
+ theorem perturbation_finite_expansion (P R : A) (K : ℕ) (s : ℝ) :
116
+ NormedSpace.exp ((-s) • (P + R)) =
117
+ (∑ j ∈ Finset.range K, (-1 : ℝ) ^ j •
118
+ volterraIter P R (fun t => NormedSpace.exp ((-t) • P)) j s) +
119
+ (-1 : ℝ) ^ K •
120
+ volterraIter P R (fun t => NormedSpace.exp ((-t) • (P + R))) K s := by
121
+ induction K with
122
+ | zero => simp [volterraIter]
123
+ | succ K ih =>
124
+ rw [ih, Finset.sum_range_succ]
125
+ have hi := congrFun (perturbation_iteration P R K) s
126
+ rw [hi, smul_sub, pow_succ]
127
+ simp only [mul_neg_one, neg_smul]
128
+ abel
129
+
130
+ omit [CompleteSpace A] in
131
+
132
+ theorem volterraIter_norm_le (P R : A) (f : ℝ → A) (T a b : ℝ)
133
+ (hT : 0 ≤ T) (ha : 0 ≤ a) (hb : 0 ≤ b)
134
+ (hP : ∀ t ∈ Set.Icc (0 : ℝ) T, ‖NormedSpace.exp ((-t) • P)‖ ≤ a)
135
+ (hf : ∀ t ∈ Set.Icc (0 : ℝ) T, ‖f t‖ ≤ b)
136
+ (k : ℕ) (s : ℝ) (hs : s ∈ Set.Icc (0 : ℝ) T) :
137
+ ‖volterraIter P R f k s‖ ≤ (a * ‖R‖ * T) ^ k * b := by
138
+ induction k generalizing s with
139
+ | zero => simpa [volterraIter] using hf s hs
140
+ | succ k ih =>
141
+ have hn : 0 ≤ a * ‖R‖ * ((a * ‖R‖ * T) ^ k * b) := by positivity
142
+ have hi : ‖volterraIter P R f (k + 1) s‖ ≤
143
+ (a * ‖R‖ * ((a * ‖R‖ * T) ^ k * b)) * |s - 0| := by
144
+ apply intervalIntegral.norm_integral_le_of_norm_le_const
145
+ intro t ht
146
+ rw [Set.uIoc_of_le hs.1] at ht
147
+ have hst : s - t ∈ Set.Icc (0 : ℝ) T := ⟨sub_nonneg.mpr ht.2, by linarith [ht.1, hs.2]⟩
148
+ have htt : t ∈ Set.Icc (0 : ℝ) T := ⟨ht.1.le, ht.2.trans hs.2⟩
149
+ have hPe : ‖NormedSpace.exp ((t - s) • P)‖ ≤ a := by
150
+ simpa only [neg_sub] using hP (s - t) hst
151
+ exact (norm_mul_le _ _).trans (mul_le_mul
152
+ ((norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right hPe (norm_nonneg R)))
153
+ (ih t htt) (norm_nonneg _) (mul_nonneg ha (norm_nonneg R)))
154
+ calc
155
+ _ ≤ (a * ‖R‖ * ((a * ‖R‖ * T) ^ k * b)) * s := by
156
+ simpa only [sub_zero, abs_of_nonneg hs.1] using hi
157
+ _ ≤ (a * ‖R‖ * ((a * ‖R‖ * T) ^ k * b)) * T :=
158
+ mul_le_mul_of_nonneg_left hs.2 hn
159
+ _ = (a * ‖R‖ * T) ^ (k + 1) * b := by rw [pow_succ]; ring
160
+
161
+ variable {B : Type*} [NormedRing B] [NormedAlgebra ℝ B] [CompleteSpace B]
162
+
163
+ omit [CompleteSpace B] in
164
+ theorem continuous_algHom_map_exp (F : A →ₐ[ℝ] B) (hF : Continuous F) (x : A) :
165
+ F (NormedSpace.exp x) = NormedSpace.exp (F x) := by
166
+ apply NormedSpace.map_exp_of_mem_ball (𝕂 := ℝ) F hF
167
+ rw [NormedSpace.expSeries_radius_eq_top]
168
+ exact edist_lt_top _ _
169
+
170
+ theorem map_volterraIter (F : A →ₐ[ℝ] B) (hF : Continuous F) (P R : A)
171
+ {f : ℝ → A} (hf : Continuous f) (k : ℕ) (s : ℝ) :
172
+ F (volterraIter P R f k s) =
173
+ volterraIter (F P) (F R) (fun t => F (f t)) k s := by
174
+ let L : A →L[ℝ] B := ⟨F.toLinearMap, hF⟩
175
+ induction k generalizing s with
176
+ | zero => rfl
177
+ | succ k ih =>
178
+ change L (∫ t in (0 : ℝ)..s,
179
+ NormedSpace.exp ((t - s) • P) * R * volterraIter P R f k t) = _
180
+ have hint : IntervalIntegrable (fun t =>
181
+ NormedSpace.exp ((t - s) • P) * R * volterraIter P R f k t) volume 0 s :=
182
+ ((continuous_volterra_integrand P R (continuous_volterraIter P R hf k)).comp
183
+ (continuous_const.prodMk continuous_id)).intervalIntegrable 0 s
184
+ rw [← L.intervalIntegral_comp_comm hint]
185
+ change (∫ t in (0 : ℝ)..s,
186
+ F (NormedSpace.exp ((t - s) • P) * R * volterraIter P R f k t)) = _
187
+ simp only [map_mul, continuous_algHom_map_exp F hF, map_smul, ih]
188
+ rfl
189
+
190
+ theorem perturbation_mixed_norm_bound (F : A →ₐ[ℝ] B) (hF : Continuous F)
191
+ (P R : A) (T a b N : ℝ) (hT : 0 ≤ T) (ha : 0 ≤ a) (hb : 0 ≤ b) (hN : 0 ≤ N)
192
+ (hcompare : ∀ x : A, ‖x‖ ≤ N * ‖F x‖)
193
+ (hbase : ∀ t ∈ Set.Icc (0 : ℝ) T, ‖NormedSpace.exp ((-t) • P)‖ ≤ a)
194
+ (hbase₂ : ∀ t ∈ Set.Icc (0 : ℝ) T, ‖NormedSpace.exp ((-t) • F P)‖ ≤ 1)
195
+ (hfull₂ : ∀ t ∈ Set.Icc (0 : ℝ) T, ‖NormedSpace.exp ((-t) • (F P + F R))‖ ≤ b)
196
+ (K : ℕ) (s : ℝ) (hs : s ∈ Set.Icc (0 : ℝ) T) :
197
+ ‖NormedSpace.exp ((-s) • (P + R))‖ ≤
198
+ (∑ j ∈ Finset.range K, (a * ‖R‖ * T) ^ j * a) +
199
+ N * ((‖F R‖ * T) ^ K * b) := by
200
+ have hc : Continuous (fun t : ℝ => NormedSpace.exp ((-t) • (P + R))) :=
201
+ (differentiable_exp_smul_const ℝ (P + R)).continuous.comp continuous_neg
202
+ have hr : ‖volterraIter P R (fun t => NormedSpace.exp ((-t) • (P + R))) K s‖ ≤
203
+ N * ((‖F R‖ * T) ^ K * b) := by
204
+ apply (hcompare _).trans
205
+ apply mul_le_mul_of_nonneg_left _ hN
206
+ rw [map_volterraIter F hF P R hc]
207
+ simp_rw [continuous_algHom_map_exp F hF, map_smul, map_add]
208
+ simpa only [one_mul] using
209
+ volterraIter_norm_le (F P) (F R) (fun t => NormedSpace.exp ((-t) • (F P + F R)))
210
+ T 1 b hT zero_le_one hb hbase₂ hfull₂ K s hs
211
+ rw [perturbation_finite_expansion P R K s]
212
+ calc
213
+ _ ≤ (∑ j ∈ Finset.range K,
214
+ ‖(-1 : ℝ) ^ j • volterraIter P R (fun t => NormedSpace.exp ((-t) • P)) j s‖) +
215
+ ‖(-1 : ℝ) ^ K • volterraIter P R (fun t => NormedSpace.exp ((-t) • (P + R))) K s‖ :=
216
+ (norm_add_le _ _).trans (add_le_add (norm_sum_le _ _) (le_refl _))
217
+ _ = (∑ j ∈ Finset.range K,
218
+ ‖volterraIter P R (fun t => NormedSpace.exp ((-t) • P)) j s‖) +
219
+ ‖volterraIter P R (fun t => NormedSpace.exp ((-t) • (P + R))) K s‖ := by
220
+ simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul]
221
+ _ ≤ _ := by
222
+ apply add_le_add _ hr
223
+ exact Finset.sum_le_sum fun j _ => volterraIter_norm_le P R _ T a a hT ha ha
224
+ hbase hbase j s hs
225
+
226
+ end Volterra
227
+ end SharpTerminalLeave
228
+
229
+ end
230
+
231
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/BalancedJump.lean ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Tracking.RootedTemplateEdgesCard
3
+ import OAI.Combinatorics.TriangleRemoval.Process.RelativeNoiseExit
4
+ import OAI.Combinatorics.TriangleRemoval.Tracking.CodegreeVertexCount
5
+ import OAI.Combinatorics.TriangleRemoval.Tracking.CodegreeNoiseRadius
6
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixEdgeRadius
7
+
8
+ namespace OAI
9
+
10
+ section
11
+ noncomputable section
12
+ open scoped BigOperators
13
+ open Filter Classical
14
+
15
+ namespace SharpTerminalLeave
16
+
17
+ lemma earlyTemplateScale_uniform_regular (H : ℕ) : ∀ᶠ n : ℕ in atTop,
18
+ ∀ a ≤ H, ∀ b ≤ H^2,
19
+ (∀ i ≤ prefixTime n, 0 < earlyTemplateScale a b n i) ∧
20
+ (∀ i < prefixTime n, earlyTemplateScale a b n (i+1) ≤ earlyTemplateScale a b n i) ∧
21
+ (∀ i < prefixTime n, earlyTemplateScale a b n i ≤ 2*earlyTemplateScale a b n (i+1)) ∧
22
+ relativeScaleBudget (earlyTemplateScale a b n) (prefixTime n) ≤ 2*(b : ℝ)*Real.log n := by
23
+ have hh : ∀ z : Fin (H+1) × Fin (H^2+1), ∀ᶠ n : ℕ in atTop,
24
+ (∀ i ≤ prefixTime n, 0 < earlyTemplateScale z.1.val z.2.val n i) ∧
25
+ (∀ i < prefixTime n, earlyTemplateScale z.1.val z.2.val n (i+1) ≤ earlyTemplateScale z.1.val z.2.val n i) ∧
26
+ (∀ i < prefixTime n, earlyTemplateScale z.1.val z.2.val n i ≤ 2*earlyTemplateScale z.1.val z.2.val n (i+1)) ∧
27
+ relativeScaleBudget (earlyTemplateScale z.1.val z.2.val n) (prefixTime n) ≤ 2*(z.2.val : ℝ)*Real.log n := by
28
+ intro z
29
+ filter_upwards [earlyTemplateScale_regular z.1.val z.2.val,
30
+ earlyTemplateScale_log_budget z.1.val z.2.val] with n hr hb
31
+ exact ⟨hr.1,hr.2.1,hr.2.2,hb⟩
32
+ filter_upwards [Filter.eventually_all.mpr hh] with n hn
33
+ intro a ha b hb
34
+ exact hn (⟨a,by omega⟩,⟨b,by omega⟩)
35
+
36
+ noncomputable def balancedJump (n : ℕ) : ℝ := (n : ℝ)^(-1/2000 : ℝ)
37
+ noncomputable def balancedLoad (H : ℕ) {k : ℕ} (T : RootedTemplate k) (n i : ℕ) : ℝ :=
38
+ 4*(T.edges.card : ℝ)*(1+Real.log (n : ℝ))^(3*H+2)*
39
+ rootedScaling T n (earlyDensity n i)/((n : ℝ)*earlyDensity n i^2)
40
+
41
+ lemma balanced_jump_budget (H : ℕ) : ∀ᶠ n : ℕ in atTop,
42
+ 24*(H : ℝ)^2*(1+Real.log (n : ℝ))^(3*H+2)/prefixD n ≤ balancedJump n := by
43
+ have hc : 0 < 1/(24*(H : ℝ)^2+1) := by positivity
44
+ filter_upwards [prefixTemplateFactor_subpower ((3*H+2 : ℕ) : ℝ) (by norm_num : (0 : ℝ) < 1/2000) hc,
45
+ prefixD_eventual_envelope,eventually_ge_atTop (1 : ℕ)] with n hb hd hn
46
+ have hn0 : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n)
47
+ have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn
48
+ have hln : 0 ≤ 1+Real.log (n : ℝ) := by have := Real.log_nonneg hn1; linarith
49
+ have hb' : (1+Real.log (n : ℝ))^(3*H+2 : ℕ) ≤
50
+ 1/(24*(H : ℝ)^2+1)*(n : ℝ)^(1/2000 : ℝ) := by
51
+ simpa only [prefixTemplateFactor,Real.rpow_natCast] using hb
52
+ have hcoef : 24*(H : ℝ)^2/(24*(H : ℝ)^2+1) ≤ 1 := by
53
+ apply (div_le_one (by positivity)).mpr; linarith
54
+ have hnum : 24*(H : ℝ)^2*(1+Real.log (n : ℝ))^(3*H+2) ≤ (n : ℝ)^(1/2000 : ℝ) := by
55
+ have hh := mul_le_mul_of_nonneg_left hb' (show 0 ≤ 24*(H : ℝ)^2 by positivity)
56
+ have he := mul_le_mul_of_nonneg_right hcoef (Real.rpow_nonneg hn0.le (1/2000 : ℝ))
57
+ ring_nf at hh he ⊢
58
+ exact hh.trans he
59
+ calc
60
+ _ ≤ (n : ℝ)^(1/2000 : ℝ)/(n : ℝ)^(1/1000 : ℝ) :=
61
+ div_le_div₀ (by positivity) hnum (by positivity) hd.1
62
+ _ = _ := by unfold balancedJump; rw [← Real.rpow_sub hn0]; norm_num
63
+
64
+ lemma rooted_initial_ratio_le_two (H : ℕ) : ∀ᶠ n : ℕ in atTop,
65
+ ∀ k ≤ H, ∀ T : RootedTemplate k, ∀ ψ : {v // v ∈ T.roots} ↪ Fin n,
66
+ rootedCount T ψ (completeGraph n)/rootedScaling T n (earlyDensity n 0) ≤ 2 := by
67
+ let C : ℝ := (2 : ℝ)^(H^2)*(2*(H : ℝ)^2)
68
+ filter_upwards [tendsto_natCast_atTop_atTop.eventually_ge_atTop C,
69
+ eventually_ge_atTop H,eventually_ge_atTop (2 : ℕ)] with n hC hn hn2
70
+ intro k hk T ψ
71
+ have hh := rootedCount_initial_uniform_error H hk hn hn2 T ψ
72
+ have hnR : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n)
73
+ have hdiv : C/(n : ℝ) ≤ 1 := (div_le_one hnR).mpr hC
74
+ have he : earlyDensity n 0 = 1-1/(n : ℝ) := by simp [earlyDensity]
75
+ rw [he]
76
+ have hp := (abs_le.mp hh).2
77
+ change _ ≤ C/(n : ℝ) at hp
78
+ linarith only [hp,hdiv]
79
+
80
+ lemma balanced_noise_exponent_budget (H : ℕ) : ∀ᶠ n : ℕ in atTop,
81
+ (Real.log (n : ℝ))^2/4 ≤ codegreeNoiseRadius n^2/
82
+ (4*(balancedJump n*(2+4*(H : ℝ)^2*Real.log n+codegreeNoiseRadius n+balancedJump n)+
83
+ balancedJump n*codegreeNoiseRadius n)) := by
84
+ let C : ℝ := 20+16*(H : ℝ)^2
85
+ have hC : 0 < C := by dsimp [C]; positivity
86
+ filter_upwards [prefixTemplateFactor_subpower 1 (by norm_num : (0 : ℝ) < 1/10000) (one_div_pos.mpr hC),
87
+ prefixTemplateFactor_subpower 2 (by norm_num : (0 : ℝ) < 1/5000) (by norm_num : (0 : ℝ) < 4),
88
+ eventually_ge_atTop (1 : ℕ)] with n hp hl hn
89
+ have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn
90
+ have hn0 : (0 : ℝ) < n := lt_of_lt_of_le zero_lt_one hn1
91
+ have hlog : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg hn1
92
+ have hr : 0 < codegreeNoiseRadius n := Real.rpow_pos_of_pos hn0 _
93
+ have hc : 0 < balancedJump n := Real.rpow_pos_of_pos hn0 _
94
+ have hr1 : codegreeNoiseRadius n ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos hn1 (by norm_num)
95
+ have hc1 : balancedJump n ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos hn1 (by norm_num)
96
+ let d := 4*(balancedJump n*(2+4*(H : ℝ)^2*Real.log n+codegreeNoiseRadius n+balancedJump n)+
97
+ balancedJump n*codegreeNoiseRadius n)
98
+ have hdpos : 0 < d := by dsimp [d]; positivity
99
+ have hd : d ≤ (n : ℝ)^(-1/2500 : ℝ) := by
100
+ have hp' : 1+Real.log (n : ℝ) ≤ (1/C)*(n : ℝ)^(1/10000 : ℝ) := by
101
+ simpa only [prefixTemplateFactor,Real.rpow_one] using hp
102
+ have hh := mul_le_mul_of_nonneg_left hp' hC.le
103
+ simp only [← mul_assoc,mul_one_div_cancel hC.ne',one_mul] at hh
104
+ have hbracket : 4*(2+4*(H : ℝ)^2*Real.log n+codegreeNoiseRadius n+balancedJump n+codegreeNoiseRadius n) ≤
105
+ C*(1+Real.log (n : ℝ)) := by dsimp [C]; nlinarith only [hr1,hc1,hlog,sq_nonneg (H : ℝ)]
106
+ have hm := mul_le_mul_of_nonneg_left (hbracket.trans hh) hc.le
107
+ have he : balancedJump n*(n : ℝ)^(1/10000 : ℝ) = (n : ℝ)^(-1/2500 : ℝ) := by
108
+ unfold balancedJump; rw [← Real.rpow_add hn0]; norm_num
109
+ rw [he] at hm
110
+ dsimp only [d]
111
+ nlinarith only [hm]
112
+ have hr2 : codegreeNoiseRadius n^2 = (n : ℝ)^(-1/5000 : ℝ) := by
113
+ unfold codegreeNoiseRadius
114
+ rw [← Real.rpow_mul_natCast hn0.le]; norm_num
115
+ have hratio : (n : ℝ)^(1/5000 : ℝ) ≤ codegreeNoiseRadius n^2/d := by
116
+ apply (le_div_iff₀ hdpos).mpr
117
+ have hh := mul_le_mul_of_nonneg_left hd (Real.rpow_nonneg hn0.le (1/5000 : ℝ))
118
+ rw [← Real.rpow_add hn0] at hh
119
+ rw [hr2]
120
+ convert hh using 1
121
+ norm_num
122
+ have hl' : (1+Real.log (n : ℝ))^2 ≤ 4*(n : ℝ)^(1/5000 : ℝ) := by
123
+ simpa only [prefixTemplateFactor,Real.rpow_two] using hl
124
+ exact (show (Real.log (n : ℝ))^2/4 ≤ (n : ℝ)^(1/5000 : ℝ) by nlinarith only [hl',hlog]).trans hratio
125
+
126
+ theorem prefix_balanced_noise_single (H : ℕ) : ∀ᶠ n : ℕ in atTop,
127
+ ∀ k ≤ H, ∀ T : RootedTemplate k, ∀ ψ : {v // v ∈ T.roots} ↪ Fin n,
128
+ pmfMean (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n))
129
+ (fun ω => if RelativeNoiseExit (fun φ : RootedInjection T ψ => imageEdges T φ.val)
130
+ (balancedLoad H T n) (earlyTemplateScale (k-T.roots.card) T.edges.card n) 2
131
+ (codegreeNoiseRadius n) (prefixTime n) ω then 1 else 0) ≤
132
+ 2*(prefixTime n+1 : ℝ)*Real.exp (-(Real.log (n : ℝ))^2/4) := by
133
+ filter_upwards [earlyTemplateScale_uniform_regular H,balanced_jump_budget H,
134
+ rooted_initial_ratio_le_two H,balanced_noise_exponent_budget H,
135
+ prefixDensity_eventually_inverse_lower,eventually_ge_atTop (1 : ℕ)] with n hreg hjump hinit hexp hp hn
136
+ intro k hk T ψ
137
+ have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn
138
+ have hn0 : (0 : ℝ) < n := lt_of_lt_of_le zero_lt_one hn1
139
+ have hln : 0 ≤ 1+Real.log (n : ℝ) := by have := Real.log_nonneg hn1; linarith
140
+ have hb : T.edges.card ≤ H^2 := (rootedTemplate_edges_card_le_sq T).trans (Nat.pow_le_pow_left hk 2)
141
+ have hbR : (T.edges.card : ℝ) ≤ (H : ℝ)^2 := by exact_mod_cast hb
142
+ have hr := hreg (k-T.roots.card) ((Nat.sub_le _ _).trans hk) T.edges.card hb
143
+ let s := earlyTemplateScale (k-T.roots.card) T.edges.card n
144
+ have hD : 0 < prefixD n := by unfold prefixD; have hh : 0 < prefixDensity n := lt_of_lt_of_le (by positivity) hp; positivity
145
+ have hc : 0 < balancedJump n := Real.rpow_pos_of_pos hn0 _
146
+ have hnoise : 0 < codegreeNoiseRadius n := Real.rpow_pos_of_pos hn0 _
147
+ have hL : ∀ i < prefixTime n, 0 ≤ balancedLoad H T n i := by
148
+ intro i hi
149
+ have hpi := early_density_positive (by omega) hp hi.le
150
+ unfold balancedLoad rootedScaling
151
+ positivity
152
+ have hJ : ∀ i < prefixTime n, 3*balancedLoad H T n i/s (i+1) ≤ balancedJump n := by
153
+ intro i hi
154
+ have hsi := hr.1 (i+1) (by omega)
155
+ have hpi := early_density_positive (by omega) hp hi.le
156
+ have hDi : prefixD n ≤ (n : ℝ)*earlyDensity n i^2 := by
157
+ simpa only [earlyTemplateScale,pow_one] using earlyCodegreeScale_ge_prefixD n i hi.le (le_trans (by positivity) hp)
158
+ have hratio := hr.2.2.1 i hi
159
+ have hcoeff : 0 ≤ 12*(T.edges.card : ℝ)*(1+Real.log (n : ℝ))^(3*H+2)/((n : ℝ)*earlyDensity n i^2) := by positivity
160
+ have hm := mul_le_mul_of_nonneg_left hratio hcoeff
161
+ have hstep : 3*balancedLoad H T n i/s (i+1) ≤
162
+ 24*(T.edges.card : ℝ)*(1+Real.log (n : ℝ))^(3*H+2)/((n : ℝ)*earlyDensity n i^2) := by
163
+ apply (div_le_iff₀ hsi).mpr
164
+ dsimp only [balancedLoad,rootedScaling,s,earlyTemplateScale] at hm ⊢
165
+ convert hm using 1 <;> ring
166
+ apply hstep.trans (_root_.le_trans _ hjump)
167
+ apply div_le_div₀ (by positivity) _ hD hDi
168
+ exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hbR (by norm_num)) (by positivity)
169
+ have ht := triangle_relative_template_self_bounded_tail
170
+ (fun φ : RootedInjection T ψ => imageEdges T φ.val) (completeGraph n) (prefixTime n)
171
+ (balancedLoad H T n) s (balancedJump n) 2 hc (by norm_num) hr.1 hr.2.1 hL hJ
172
+ (codegreeNoiseRadius n) hnoise
173
+ refine (show _ ≤ 2*(prefixTime n+1 : ℝ)*Real.exp
174
+ (-codegreeNoiseRadius n^2/(4*(balancedJump n*(copyCount (fun φ : RootedInjection T ψ => imageEdges T φ.val)
175
+ (completeGraph n)/s 0+2*relativeScaleBudget s (prefixTime n)+codegreeNoiseRadius n+balancedJump n)+
176
+ balancedJump n*codegreeNoiseRadius n))) from ?_).trans ?_
177
+ · convert ht using 1
178
+ apply congrArg (pmfMean _)
179
+ funext ω
180
+ unfold RelativeNoiseExit
181
+ split_ifs <;> rfl
182
+ apply mul_le_mul_of_nonneg_left _ (by positivity)
183
+ apply Real.exp_le_exp.mpr
184
+ rw [neg_div,neg_div]
185
+ apply neg_le_neg
186
+ apply hexp.trans
187
+ apply div_le_div_of_nonneg_left (sq_nonneg _)
188
+ · have hscale : 0 ≤ copyCount (fun φ : RootedInjection T ψ => imageEdges T φ.val) (completeGraph n)/s 0 :=
189
+ div_nonneg (copyCount_nonneg _ _) (hr.1 0 (Nat.zero_le _)).le
190
+ have hbudget := relativeScaleBudget_nonneg s (prefixTime n) hr.1 hr.2.1
191
+ positivity
192
+ · have hi := hinit k hk T ψ
193
+ change copyCount _ (completeGraph n)/s 0 ≤ 2 at hi
194
+ have hbgt : relativeScaleBudget s (prefixTime n) ≤ 2*(H : ℝ)^2*Real.log n :=
195
+ hr.2.2.2.trans (by nlinarith only [mul_le_mul_of_nonneg_right hbR (Real.log_nonneg hn1)])
196
+ have hh := mul_le_mul_of_nonneg_left (show copyCount (fun φ : RootedInjection T ψ => imageEdges T φ.val) (completeGraph n)/s 0+
197
+ 2*relativeScaleBudget s (prefixTime n)+codegreeNoiseRadius n+balancedJump n ≤
198
+ 2+4*(H : ℝ)^2*Real.log n+codegreeNoiseRadius n+balancedJump n by linarith only [hi,hbgt]) hc.le
199
+ linarith only [hh]
200
+
201
+ end SharpTerminalLeave
202
+ end
203
+ end
204
+
205
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/CenteredCodegreeNeighborSum.lean ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.HistoryCompensator
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open scoped BigOperators
10
+ open scoped BigOperators ENNReal Classical
11
+ open Filter MeasureTheory
12
+ open Filter
13
+ open scoped BigOperators Topology
14
+
15
+ namespace SharpTerminalLeave
16
+
17
+ noncomputable def centeredCodegreeNeighborSum {n : ℕ} (G : Graph n)
18
+ (u v : Fin n) (s : ℝ) : ℝ :=
19
+ ∑ w ∈ commonNeighbors G u v,
20
+ ((currentCodegree G u w : ℝ)+currentCodegree G v w-2*s)
21
+
22
+ lemma codegree_hazard_centering {n : ℕ} (G : Graph n) (u v : Fin n) (s : ℝ) :
23
+ (∑ w ∈ commonNeighbors G u v,
24
+ ((currentCodegree G u w : ℝ)+currentCodegree G v w-if {u,v} ∈ G then 1 else 0)) =
25
+ (2*s-if {u,v} ∈ G then 1 else 0)*(currentCodegree G u v : ℝ)+
26
+ centeredCodegreeNeighborSum G u v s := by
27
+ classical
28
+ have he : (∑ w ∈ commonNeighbors G u v,
29
+ ((currentCodegree G u w : ℝ)+currentCodegree G v w-if {u,v} ∈ G then 1 else 0)) =
30
+ (∑ _w ∈ commonNeighbors G u v, (2*s-if {u,v} ∈ G then 1 else 0))+
31
+ centeredCodegreeNeighborSum G u v s := by
32
+ rw [centeredCodegreeNeighborSum,← Finset.sum_add_distrib]
33
+ apply Finset.sum_congr rfl
34
+ intro w _
35
+ ring
36
+ rw [he]
37
+ simp only [Finset.sum_const,nsmul_eq_mul,currentCodegree]
38
+ ring
39
+
40
+ theorem normalized_codegree_centered_drift {n : ℕ} {G : Graph n}
41
+ (hG : G ⊆ completeGraph n) (u v : Fin n) (huv : u ≠ v) (s t : ℝ) :
42
+ pmfMean (step G) (fun H => (currentCodegree H u v : ℝ)/t)-
43
+ (currentCodegree G u v : ℝ)/s =
44
+ (currentCodegree G u v : ℝ)*(1/t-1/s)-
45
+ ((2*s-if {u,v} ∈ G then 1 else 0)*(currentCodegree G u v : ℝ)+
46
+ centeredCodegreeNeighborSum G u v s)/((triangles G).card*t) := by
47
+ by_cases hQ : (triangles G).Nonempty
48
+ · have hd := step_mean_codegree hG hQ u v huv
49
+ rw [codegree_hazard_centering G u v s] at hd
50
+ simp only [div_eq_mul_inv,pmfMean_mul_const] at hd ⊢
51
+ rw [hd,mul_inv_rev]
52
+ ring
53
+ · have hzero : triangles G = ∅ := Finset.not_nonempty_iff_eq_empty.mp hQ
54
+ rw [step,dite_eq_right hQ,pmfMean_pure,hzero,Finset.card_empty,Nat.cast_zero,zero_mul,div_zero]
55
+ ring
56
+
57
+ theorem prefix_codegree_centered_drift {n : ℕ} {G : Graph n}
58
+ (hG : G ⊆ completeGraph n) (u v : Fin n) (huv : u ≠ v) (k : ℕ) :
59
+ pmfMean (step G) (prefixNormalizedCodegree u v (k+1))-
60
+ prefixNormalizedCodegree u v k G =
61
+ (currentCodegree G u v : ℝ)*(1/earlyTemplateScale 1 2 n (k+1)-1/earlyTemplateScale 1 2 n k)-
62
+ ((2*earlyTemplateScale 1 2 n k-if {u,v} ∈ G then 1 else 0)*
63
+ (currentCodegree G u v : ℝ)+
64
+ centeredCodegreeNeighborSum G u v (earlyTemplateScale 1 2 n k))/
65
+ ((triangles G).card*earlyTemplateScale 1 2 n (k+1)) :=
66
+ normalized_codegree_centered_drift hG u v huv _ _
67
+
68
+ end SharpTerminalLeave
69
+
70
+ end
71
+
72
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/CodegreeNoiseRadius.lean ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixDTendstoTop
3
+
4
+ namespace OAI
5
+
6
+ section
7
+ open scoped BigOperators Topology Matrix.Norms.Operator
8
+ open MeasureTheory
9
+ open scoped BigOperators
10
+ open scoped BigOperators ENNReal Classical
11
+ open Filter MeasureTheory
12
+ open Filter
13
+ open scoped BigOperators Topology
14
+
15
+ namespace SharpTerminalLeave
16
+
17
+ noncomputable def codegreeNoiseRadius (n : ℕ) : ℝ := (n : ℝ)^(-1/10000 : ℝ)
18
+ noncomputable def codegreeNoiseDenominator (n : ℕ) : ℝ :=
19
+ 4*((6/prefixD n)*(4+8*Real.log n+codegreeNoiseRadius n+6/prefixD n)+
20
+ (6/prefixD n)*codegreeNoiseRadius n)
21
+
22
+ theorem codegree_noise_exponent_lower : ∀ᶠ n : ℕ in atTop,
23
+ (n : ℝ)^(1/2500 : ℝ) ≤ codegreeNoiseRadius n^2/codegreeNoiseDenominator n := by
24
+ have hlog := ((isLittleO_log_rpow_atTop (by norm_num : (0 : ℝ) < 1/2500)).comp_tendsto
25
+ tendsto_natCast_atTop_atTop).bound (by norm_num : (0 : ℝ) < 1/384)
26
+ have hpow : Tendsto (fun n : ℕ => (n : ℝ)^(1/2500 : ℝ)) atTop atTop :=
27
+ (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 1/2500)).comp tendsto_natCast_atTop_atTop
28
+ filter_upwards [prefixD_eventual_envelope,prefixD_tendsto_atTop.eventually_ge_atTop 6,
29
+ hlog,hpow.eventually_ge_atTop 336,eventually_ge_atTop (1 : ℕ)] with n hD hD6 hl hn336 hn
30
+ have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn
31
+ have hn0 : (0 : ℝ) < n := lt_of_lt_of_le zero_lt_one hn1
32
+ have hD0 : 0 < prefixD n := by linarith
33
+ have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg hn1
34
+ have hc0 : 0 < 6/prefixD n := by positivity
35
+ have hc1 : 6/prefixD n ≤ 1 := (div_le_one hD0).mpr hD6
36
+ have hr0 : 0 < codegreeNoiseRadius n := Real.rpow_pos_of_pos hn0 _
37
+ have hr1 : codegreeNoiseRadius n ≤ 1 :=
38
+ Real.rpow_le_one_of_one_le_of_nonpos hn1 (by norm_num)
39
+ have hc : 6/prefixD n ≤ 6*(n : ℝ)^(-1/1000 : ℝ) := by
40
+ have hh := div_le_div_of_nonneg_left (by norm_num : (0 : ℝ) ≤ 6)
41
+ (Real.rpow_pos_of_pos hn0 (1/1000 : ℝ)) hD.1
42
+ calc
43
+ _ ≤ 6/(n : ℝ)^(1/1000 : ℝ) := hh
44
+ _ = _ := by
45
+ rw [show (-1/1000 : ℝ) = -(1/1000 : ℝ) by norm_num,Real.rpow_neg hn0.le]
46
+ rfl
47
+ have hr2 : codegreeNoiseRadius n^2 = (n : ℝ)^(-1/5000 : ℝ) := by
48
+ unfold codegreeNoiseRadius
49
+ rw [← Real.rpow_natCast,← Real.rpow_mul hn0.le]
50
+ norm_num
51
+ have hd0 : 0 < codegreeNoiseDenominator n := by unfold codegreeNoiseDenominator; positivity
52
+ have hd : codegreeNoiseDenominator n ≤ (n : ℝ)^(-1/1000 : ℝ)*(24*(7+8*Real.log n)) := by
53
+ unfold codegreeNoiseDenominator
54
+ calc
55
+ _ = 4*(6/prefixD n)*(4+8*Real.log n+codegreeNoiseRadius n+6/prefixD n+codegreeNoiseRadius n) := by ring
56
+ _ ≤ 4*(6/prefixD n)*(7+8*Real.log n) := by
57
+ apply mul_le_mul_of_nonneg_left _ (by positivity)
58
+ linarith only [hr1,hc1]
59
+ _ ≤ 4*(6*(n : ℝ)^(-1/1000 : ℝ))*(7+8*Real.log n) := by
60
+ exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hc (by norm_num))
61
+ (by positivity)
62
+ _ = _ := by ring
63
+ have hsmall : 24*(7+8*Real.log (n : ℝ)) ≤ (n : ℝ)^(1/2500 : ℝ) := by
64
+ dsimp at hl
65
+ rw [abs_of_nonneg hln,abs_of_nonneg (Real.rpow_nonneg hn0.le (1/2500 : ℝ))] at hl
66
+ linarith only [hl,hn336]
67
+ have hd' := hd.trans (mul_le_mul_of_nonneg_left hsmall
68
+ (Real.rpow_nonneg hn0.le (-1/1000 : ℝ)))
69
+ apply (le_div_iff₀ hd0).mpr
70
+ have hh := mul_le_mul_of_nonneg_left hd' (Real.rpow_nonneg hn0.le (1/2500 : ℝ))
71
+ rw [← Real.rpow_add hn0,← Real.rpow_add hn0] at hh
72
+ rw [hr2]
73
+ convert hh using 1; norm_num
74
+
75
+ end SharpTerminalLeave
76
+
77
+ end
78
+
79
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/CodegreeRelativeNoiseTail.lean ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.RelativeCopyNoiseFirst
3
+ import OAI.Combinatorics.TriangleRemoval.Embeddings.FixedEndpointPairInjective
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ open scoped BigOperators Topology Matrix.Norms.Operator
9
+ open MeasureTheory
10
+ open scoped BigOperators
11
+ open scoped BigOperators ENNReal Classical
12
+ open Filter MeasureTheory
13
+ open Filter
14
+ open scoped BigOperators Topology
15
+
16
+ namespace SharpTerminalLeave
17
+
18
+ open Classical in
19
+
20
+ theorem codegree_relative_noise_tail {n : ℕ} (u v : Fin n) (G : Graph n)
21
+ (T : ℕ) (s : ℕ → ℝ) (c B : ℝ) (hc : 0 < c) (hB : 0 ≤ B)
22
+ (hs : ∀ k ≤ T, 0 < s k) (hdec : ∀ k < T, s (k+1) ≤ s k)
23
+ (hjump : ∀ k < T, 6/s (k+1) ≤ c) (r : ℝ) (hr : 0 < r) :
24
+ pmfMean (historyLaw (PMF.pure G) (fun _ => step) T T)
25
+ (fun ω => if ∃ j ≤ T,
26
+ (∀ k < j, (currentCodegree (ω (historyIndex T k)) u v : ℝ) ≤ B*s k) ∧
27
+ r ≤ |historyNoise (fun _ => step)
28
+ (fun k H => (currentCodegree H u v : ℝ)/s k) T j ω| then 1 else 0) ≤
29
+ 2*(T+1 : ℝ)*Real.exp
30
+ (-r^2/(4*(c*((currentCodegree G u v : ℝ)/s 0+B*relativeScaleBudget s T+r+c)+c*r))) := by
31
+ have ht := triangle_relative_template_self_bounded_tail (wedgeEdges u v) G T
32
+ (fun _ => 2) s c B hc hB hs hdec (fun _ _ => by norm_num)
33
+ (fun k hk => by simpa only [show (3 : ℝ)*2 = 6 by norm_num] using hjump k hk) r hr
34
+ simp_rw [← currentCodegree_copyCount] at ht
35
+ apply le_trans _ ht
36
+ apply pmfMean_mono
37
+ intro ω _
38
+ by_cases hex : ∃ j ≤ T,
39
+ (∀ k < j, (currentCodegree (ω (historyIndex T k)) u v : ℝ) ≤ B*s k) ∧
40
+ r ≤ |historyNoise (fun _ => step)
41
+ (fun k H => (currentCodegree H u v : ℝ)/s k) T j ω|
42
+ · obtain ⟨j,hj,hcounts,hcross⟩ := hex
43
+ rw [ite_eq_left ⟨j,hj,hcounts,hcross⟩,
44
+ ite_eq_left ⟨j,hj,wedge_pastRelativeCopyLoadsSafe u v T j ω,hcounts,hcross⟩]
45
+ · rw [ite_eq_right hex]
46
+ split <;> norm_num
47
+
48
+ end SharpTerminalLeave
49
+
50
+ end
51
+
52
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/CodegreeVarianceRate.lean ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.PowersetCardTriple
3
+ import OAI.Combinatorics.TriangleRemoval.Process.History
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ open scoped BigOperators Topology Matrix.Norms.Operator
9
+ open MeasureTheory
10
+ open Filter MeasureTheory
11
+ open scoped BigOperators ENNReal Classical
12
+ open scoped BigOperators
13
+ open Filter
14
+ open scoped BigOperators Topology
15
+
16
+ namespace SharpTerminalLeave
17
+
18
+ theorem pmfMean_centered_sq_le {α : Type*} [Fintype α]
19
+ (p : PMF α) (f : α → ℝ) (a : ℝ) :
20
+ pmfMean p (fun b => (f b - pmfMean p f)^2) ≤
21
+ pmfMean p (fun b => (f b - a)^2) := by
22
+ rw [pmfMean_sq_sub,pmfMean_sq_sub]
23
+ nlinarith [sq_nonneg (pmfMean p f - a)]
24
+
25
+ theorem codegree_centered_range {n : ℕ} {G H : Graph n}
26
+ (hG : G ⊆ completeGraph n) (u v : Fin n) (hH : H ∈ (step G).support) :
27
+ |(currentCodegree H u v : ℝ) -
28
+ pmfMean (step G) (fun J => (currentCodegree J u v : ℝ))| ≤ 2 := by
29
+ have hmlo : (currentCodegree G u v : ℝ) - 2 ≤
30
+ pmfMean (step G) (fun J => (currentCodegree J u v : ℝ)) := by
31
+ rw [← pmfMean_const (step G) ((currentCodegree G u v : ℝ) - 2)]
32
+ apply pmfMean_mono
33
+ intro J hJ
34
+ have hJ' := (codegree_step_range hG u v hJ).2
35
+ linarith
36
+ have hmhi : pmfMean (step G) (fun J => (currentCodegree J u v : ℝ)) ≤
37
+ (currentCodegree G u v : ℝ) := by
38
+ rw [← pmfMean_const (step G) (currentCodegree G u v : ℝ)]
39
+ apply pmfMean_mono
40
+ intro J hJ
41
+ have hJ' := (codegree_step_range hG u v hJ).1
42
+ linarith
43
+ obtain ⟨hlo,hhi⟩ := codegree_step_range hG u v hH
44
+ exact abs_le.mpr ⟨by linarith,by linarith⟩
45
+
46
+ theorem codegree_centered_variance {n : ℕ} {G : Graph n}
47
+ (hG : G ⊆ completeGraph n) (u v : Fin n) :
48
+ pmfMean (step G) (fun H => ((currentCodegree H u v : ℝ) -
49
+ pmfMean (step G) (fun J => (currentCodegree J u v : ℝ)))^2) ≤
50
+ 2 * ((currentCodegree G u v : ℝ) -
51
+ pmfMean (step G) (fun H => (currentCodegree H u v : ℝ))) := by
52
+ exact (pmfMean_centered_sq_le _ _ (currentCodegree G u v : ℝ)).trans
53
+ (codegree_step_second_moment hG u v)
54
+
55
+ @[simp] theorem markovLaw_triangle_step {n : ℕ} (G : Graph n) (k : ℕ) :
56
+ markovLaw (PMF.pure G) (fun _ => step) k = evolve G k := by
57
+ induction k with
58
+ | zero => rfl
59
+ | succ k ih => rw [markovLaw,evolve,ih]
60
+
61
+ noncomputable def codegreeVarianceRate {n : ℕ} (u v : Fin n) (_k : ℕ) (G : Graph n) : ℝ :=
62
+ 2 * ((currentCodegree G u v : ℝ) -
63
+ pmfMean (step G) (fun H => (currentCodegree H u v : ℝ)))
64
+
65
+ theorem triangle_codegree_noise_freedman {n : ℕ} (G : Graph n)
66
+ (hG : G ⊆ completeGraph n) (u v : Fin n) (T k : ℕ)
67
+ (r V : ℝ) (hr : 0 < r) (hV : 0 ≤ V) :
68
+ pmfMean (historyLaw (PMF.pure G) (fun _ => step) T k)
69
+ (fun ω => if r ≤ historyNoise (fun _ => step)
70
+ (fun _ H => (currentCodegree H u v : ℝ)) T k ω ∧
71
+ historyCounter (codegreeVarianceRate u v) T k ω ≤ V then 1 else 0) ≤
72
+ Real.exp (-r ^ 2 / (4 * (V + 2 * r))) := by
73
+ apply history_noise_freedman (PMF.pure G) (fun _ => step)
74
+ (fun _ H => (currentCodegree H u v : ℝ)) (codegreeVarianceRate u v) T 2
75
+ (by norm_num)
76
+ · intro j _ H hH J hJ
77
+ rw [markovLaw_triangle_step] at hH
78
+ exact codegree_centered_range ((evolve_support_subset G j hH).trans hG) u v hJ
79
+ · intro j _ H hH
80
+ rw [markovLaw_triangle_step] at hH
81
+ exact codegree_centered_variance ((evolve_support_subset G j hH).trans hG) u v
82
+ · exact hr
83
+ · exact hV
84
+
85
+ end SharpTerminalLeave
86
+
87
+ end
88
+
89
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/CodegreeVertexCount.lean ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Asymptotics.EarlyDensity
3
+ import OAI.Combinatorics.TriangleRemoval.Tracking.CodegreeRelativeNoiseTail
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ open scoped BigOperators Topology Matrix.Norms.Operator
9
+ open MeasureTheory
10
+ open scoped BigOperators
11
+ open scoped BigOperators ENNReal Classical
12
+ open Filter MeasureTheory
13
+ open Filter
14
+ open scoped BigOperators Topology
15
+
16
+ namespace SharpTerminalLeave
17
+
18
+ lemma codegree_le_vertex_count {n : ℕ} (G : Graph n) (u v : Fin n) :
19
+ currentCodegree G u v ≤ n := by
20
+ unfold currentCodegree
21
+ exact (Finset.card_le_univ _).trans (by simp)
22
+
23
+ lemma earlyCodegreeScale_ge_prefixD (n i : ℕ) (hi : i ≤ prefixTime n)
24
+ (hp : 0 ≤ prefixDensity n) : prefixD n ≤ earlyTemplateScale 1 2 n i := by
25
+ unfold earlyTemplateScale prefixD
26
+ rw [pow_one]
27
+ exact mul_le_mul_of_nonneg_left
28
+ (pow_le_pow_left₀ hp (earlyDensity_antitone n hi) 2) (Nat.cast_nonneg n)
29
+
30
+ lemma initial_codegree_relative_le_four {n : ℕ} (hn : 2 ≤ n) (u v : Fin n) :
31
+ (currentCodegree (completeGraph n) u v : ℝ)/earlyTemplateScale 1 2 n 0 ≤ 4 := by
32
+ have hn0 : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n)
33
+ have hn2 : (2 : ℝ) ≤ n := by exact_mod_cast hn
34
+ have hp : (1/2 : ℝ) ≤ earlyDensity n 0 := by
35
+ have hh : 1/(n : ℝ) ≤ 1/2 := (div_le_iff₀ hn0).mpr (by linarith)
36
+ simp only [earlyDensity,Nat.cast_zero,mul_zero,zero_div,sub_zero]
37
+ linarith
38
+ have hs : (n : ℝ)/4 ≤ earlyTemplateScale 1 2 n 0 := by
39
+ have hh := mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (by norm_num : (0 : ℝ) ≤ 1/2) hp 2)
40
+ hn0.le
41
+ unfold earlyTemplateScale
42
+ norm_num only [pow_one,div_pow,one_pow] at hh ⊢
43
+ nlinarith only [hh]
44
+ apply (div_le_iff₀ (lt_of_lt_of_le (by positivity) hs)).mpr
45
+ have hh : (currentCodegree (completeGraph n) u v : ℝ) ≤ n := by
46
+ exact_mod_cast codegree_le_vertex_count (completeGraph n) u v
47
+ linarith
48
+
49
+ open Classical in
50
+
51
+ theorem prefix_codegree_relative_noise_bound : ∀ᶠ n : ℕ in atTop,
52
+ ∀ u v : Fin n, ∀ r : ℝ, 0 < r →
53
+ pmfMean (historyLaw (PMF.pure (completeGraph n)) (fun _ => step)
54
+ (prefixTime n) (prefixTime n))
55
+ (fun ω => if ∃ j ≤ prefixTime n,
56
+ (∀ k < j, (currentCodegree (ω (historyIndex (prefixTime n) k)) u v : ℝ) ≤
57
+ 2*earlyTemplateScale 1 2 n k) ∧
58
+ r ≤ |historyNoise (fun _ => step)
59
+ (fun k H => (currentCodegree H u v : ℝ)/earlyTemplateScale 1 2 n k)
60
+ (prefixTime n) j ω| then 1 else 0) ≤
61
+ 2*(prefixTime n+1 : ℝ)*Real.exp
62
+ (-r^2/(4*((6/prefixD n)*(4+8*Real.log n+r+6/prefixD n)+(6/prefixD n)*r))) := by
63
+ filter_upwards [earlyTemplateScale_regular 1 2,earlyTemplateScale_log_budget 1 2,
64
+ prefixDensity_eventually_inverse_lower,eventually_ge_atTop (2 : ℕ)] with n hreg hbudget hp hn
65
+ intro u v r hr
66
+ have hn0 : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n)
67
+ have hpp : 0 < prefixDensity n := lt_of_lt_of_le (by positivity) hp
68
+ have hD : 0 < prefixD n := by unfold prefixD; positivity
69
+ have hc : 0 < 6/prefixD n := by positivity
70
+ have hjump : ∀ k < prefixTime n, 6/earlyTemplateScale 1 2 n (k+1) ≤ 6/prefixD n := by
71
+ intro k hk
72
+ exact div_le_div_of_nonneg_left (by norm_num) hD
73
+ (earlyCodegreeScale_ge_prefixD n (k+1) (by omega) hpp.le)
74
+ have ht := codegree_relative_noise_tail u v (completeGraph n) (prefixTime n)
75
+ (earlyTemplateScale 1 2 n) (6/prefixD n) 2 hc (by norm_num)
76
+ hreg.1 hreg.2.1 hjump r hr
77
+ apply ht.trans
78
+ apply mul_le_mul_of_nonneg_left _ (by positivity)
79
+ apply Real.exp_le_exp.mpr
80
+ rw [neg_div,neg_div]
81
+ apply neg_le_neg
82
+ have hinit := initial_codegree_relative_le_four hn u v
83
+ have hz := relativeScaleBudget_nonneg (earlyTemplateScale 1 2 n) (prefixTime n)
84
+ hreg.1 hreg.2.1
85
+ have hi0 : 0 ≤ (currentCodegree (completeGraph n) u v : ℝ)/earlyTemplateScale 1 2 n 0 :=
86
+ div_nonneg (Nat.cast_nonneg _) (hreg.1 0 (Nat.zero_le _)).le
87
+ have hd0 : 0 < 4*((6/prefixD n)*
88
+ ((currentCodegree (completeGraph n) u v : ℝ)/earlyTemplateScale 1 2 n 0+
89
+ 2*relativeScaleBudget (earlyTemplateScale 1 2 n) (prefixTime n)+r+6/prefixD n)+
90
+ (6/prefixD n)*r) := by positivity
91
+ apply div_le_div_of_nonneg_left (sq_nonneg r) hd0
92
+ have hh := mul_le_mul_of_nonneg_left (show
93
+ (currentCodegree (completeGraph n) u v : ℝ)/earlyTemplateScale 1 2 n 0+
94
+ 2*relativeScaleBudget (earlyTemplateScale 1 2 n) (prefixTime n)+r+6/prefixD n ≤
95
+ 4+8*Real.log n+r+6/prefixD n by norm_num at hbudget; linarith)
96
+ hc.le
97
+ linarith
98
+
99
+ end SharpTerminalLeave
100
+
101
+ end
102
+
103
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/GoodPrefixStarApproximation.lean ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Spectral.GraphStarApproximation
3
+ import OAI.Combinatorics.TriangleRemoval.Process.LinkSimpleGraph
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ section
9
+ open Filter
10
+ open scoped BigOperators Topology
11
+ open InnerProductSpace
12
+ open scoped InnerProductSpace
13
+ open scoped BigOperators NNReal
14
+ open Matrix
15
+ open scoped BigOperators Matrix.Norms.L2Operator
16
+ open Matrix InnerProductSpace
17
+ open scoped BigOperators
18
+
19
+ namespace SharpTerminalLeave
20
+ open scoped Matrix.Norms.L2Operator
21
+
22
+ theorem goodPrefix_star_approximation {n : ℕ} {G : Graph n} {c C : ℝ}
23
+ (h : GoodPrefixGraph n c C G) (u : Fin n) [Nonempty (neighbors G u)]
24
+ (j : ℕ) (hj : j+3 ≤ prefixCycleCap) (heven : Even (j+3))
25
+ (hD : 1 ≤ prefixD n) (hδ : (n : ℝ)^(-c) ≤ 1) :
26
+ ‖(prefixD n)⁻¹ • (linkSimpleGraph G h.1 u).adjMatrix ℝ - averagingProjector‖ ≤
27
+ 4 * (((j+4 : ℕ) : ℝ) * (n : ℝ)^(-c) + ((j+3 : ℕ) : ℝ)^(j+4) * 2^(j+3) *
28
+ ((neighbors G u).card / prefixD n^((j+3)/2) + 1/prefixD n)) ^
29
+ (1 / ((j+3 : ℕ) : ℝ)) + 7*(n : ℝ)^(-c) := by
30
+ have hc := h.2.2.2.2.1
31
+ have hmain := hc (j+3) (by omega) hj u
32
+ rw [linkCycleCount_eq_graphEmbeddings (j := j+1) G h.1 u] at hmain
33
+ have hcyc : ∀ b, 3 ≤ b → b < j+3 →
34
+ ((graphEmbeddings (SimpleGraph.cycleGraph b) (linkSimpleGraph G h.1 u)).card : ℝ) ≤
35
+ 2 * prefixD n ^ b := by
36
+ intro b hb hbj
37
+ have hh := (abs_le.mp (hc b hb (by omega) u)).2
38
+ have heq : b = b-2+2 := by omega
39
+ have hcount : linkCycleCount b G u =
40
+ ((graphEmbeddings (SimpleGraph.cycleGraph b) (linkSimpleGraph G h.1 u)).card : ℝ) := by
41
+ rw [heq]
42
+ exact linkCycleCount_eq_graphEmbeddings G h.1 u
43
+ rw [hcount] at hh
44
+ have hx := mul_le_mul_of_nonneg_right hδ (pow_nonneg (le_trans zero_le_one hD) b)
45
+ nlinarith
46
+ simpa only [Fintype.card_coe] using graph_star_approximation (linkSimpleGraph G h.1 u)
47
+ j heven (prefixD n) ((n : ℝ)^(-c)) hD (Real.rpow_nonneg (Nat.cast_nonneg _) _) hδ
48
+ (goodPrefix_link_rows h u) hmain hcyc
49
+
50
+ theorem goodPrefix_star_fixed {n : ℕ} {G : Graph n} {c C : ℝ}
51
+ (h : GoodPrefixGraph n c C G) (u : Fin n) [Nonempty (neighbors G u)]
52
+ (hD : 1 ≤ prefixD n) (hδ : (n : ℝ)^(-c) ≤ 1) :
53
+ ‖(prefixD n)⁻¹ • (linkSimpleGraph G h.1 u).adjMatrix ℝ - averagingProjector‖ ≤
54
+ 4 * ((8001 : ℝ) * (n : ℝ)^(-c) + (8000 : ℝ)^8001 * 2^8000 *
55
+ ((neighbors G u).card / prefixD n^4000 + 1/prefixD n)) ^ (1 / (8000 : ℝ)) +
56
+ 7*(n : ℝ)^(-c) := by
57
+ exact goodPrefix_star_approximation h u 7997 (by decide) (by decide) hD hδ
58
+
59
+ end SharpTerminalLeave
60
+
61
+ open scoped BigOperators Matrix.Norms.L2Operator
62
+ open Matrix
63
+
64
+ end
65
+ end
66
+
67
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/GoodPrefixSurvivalMoments.lean ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.FinishSupportSubset
3
+ import OAI.Combinatorics.TriangleRemoval.Stability.GridCavityWeightLower
4
+ import OAI.Combinatorics.TriangleRemoval.Process.AveragedSingletonSurvivalError
5
+
6
+ namespace OAI
7
+
8
+ section
9
+ open scoped BigOperators Topology Matrix.Norms.Operator
10
+ open MeasureTheory
11
+ open scoped BigOperators
12
+ open scoped BigOperators ENNReal Classical
13
+ open Filter MeasureTheory
14
+ open Filter
15
+ open scoped BigOperators Topology
16
+
17
+ namespace SharpTerminalLeave
18
+
19
+ theorem goodPrefix_survival_moments (c C : ℝ) (hc : 0 < c) {ε : ℝ} (hε : 0 < ε) :
20
+ ∀ᶠ n : ℕ in atTop, ∀ (G : Graph n), GoodPrefixGraph n c C G →
21
+ ∀ hne : G.Nonempty,
22
+ (|pmfMean (PMF.uniformOfFinset G hne) (fun e => focusSurvival G {e})-
23
+ cavityReference (prefixD n) 1| ≤
24
+ 8192*(1+2*prefixD n)^48/prefixD n^50+ε*cavityReference (prefixD n) 1) ∧
25
+ (|pmfMean (PMF.uniformOfFinset G hne) (fun e =>
26
+ pmfMean (PMF.uniformOfFinset G hne) (fun f => focusSurvival G {e,f}))-
27
+ (cavityReference (prefixD n) 1)^2| ≤
28
+ 65536*(1+2*prefixD n)^48/prefixD n^50+8/(n : ℝ)+
29
+ (2*ε+ε^2)*(cavityReference (prefixD n) 1)^2) := by
30
+ filter_upwards [goodPrefix_cavity_stability hc hε,
31
+ averaged_singleton_collisionCost c C hc,averaged_disjoint_collisionCost c C hc,
32
+ goodPrefix_rootOverlap hc,goodPrefix_full_continuous_rows hc] with n hrel hsingle hpair hover hpos
33
+ intro G hG hne
34
+ have hr := (hrel C G hG 1 ⟨by norm_num,le_rfl⟩).1
35
+ constructor
36
+ · exact (averaged_singleton_survival_error G hne (prefixD n) ε hpos.1 hr).trans
37
+ (add_le_add (hsingle G hG hne) le_rfl)
38
+ · exact (averaged_pair_survival_error G hne hG.1 (prefixD n) ε hpos.1 hε.le hr).trans
39
+ (add_le_add (add_le_add (hpair G hG hne) (hover C G hG hne)) le_rfl)
40
+
41
+ lemma focusSurvival_singleton_mean {n : ℕ} (G : Graph n) (e : Finset (Fin n)) :
42
+ focusSurvival G {e} = pmfMean (finish G) (fun H => if e ∈ H then 1 else 0) := by
43
+ classical
44
+ unfold focusSurvival
45
+ rw [trueProbability_map]
46
+ simp only [Finset.singleton_subset_iff,decide_eq_true_eq,pmfMean]
47
+
48
+ lemma focusSurvival_pair_mean {n : ℕ} (G : Graph n) (e f : Finset (Fin n)) :
49
+ focusSurvival G {e,f} = pmfMean (finish G) (fun H => if e ∈ H ∧ f ∈ H then 1 else 0) := by
50
+ classical
51
+ unfold focusSurvival
52
+ rw [trueProbability_map]
53
+ simp only [Finset.insert_subset_iff,Finset.singleton_subset_iff,decide_eq_true_eq,pmfMean]
54
+
55
+ theorem terminal_first_focus_moment {n : ℕ} (G : Graph n) (hne : G.Nonempty) :
56
+ pmfMean (PMF.uniformOfFinset G hne) (fun e => focusSurvival G {e}) =
57
+ pmfMean (finish G) (fun H => (H.card : ℝ))/(G.card : ℝ) := by
58
+ simp_rw [focusSurvival_singleton_mean]
59
+ rw [pmfMean_swap]
60
+ exact terminal_first_edge_moment G hne
61
+
62
+ theorem terminal_second_focus_moment {n : ℕ} (G : Graph n) (hne : G.Nonempty) :
63
+ pmfMean (PMF.uniformOfFinset G hne) (fun e =>
64
+ pmfMean (PMF.uniformOfFinset G hne) (fun f => focusSurvival G {e,f})) =
65
+ pmfMean (finish G) (fun H => (H.card : ℝ)^2)/(G.card : ℝ)^2 := by
66
+ simp_rw [focusSurvival_pair_mean]
67
+ calc
68
+ _ = pmfMean (PMF.uniformOfFinset G hne) (fun e =>
69
+ pmfMean (finish G) (fun H =>
70
+ pmfMean (PMF.uniformOfFinset G hne) (fun f =>
71
+ if e ∈ H ∧ f ∈ H then 1 else 0))) := by
72
+ apply congrArg
73
+ funext e
74
+ exact pmfMean_swap _ _ _
75
+ _ = pmfMean (finish G) (fun H =>
76
+ pmfMean (PMF.uniformOfFinset G hne) (fun e =>
77
+ pmfMean (PMF.uniformOfFinset G hne) (fun f =>
78
+ if e ∈ H ∧ f ∈ H then 1 else 0))) := pmfMean_swap _ _ _
79
+ _ = _ := terminal_second_edge_moment G hne
80
+
81
+ end SharpTerminalLeave
82
+
83
+ end
84
+
85
+ end OAI
lean/OAI/Combinatorics/TriangleRemoval/Tracking/NormalizedTrackingAbsolute.lean ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Combinatorics.TriangleRemoval.Process.TriangleNoiseJumpBudget
3
+ import OAI.Combinatorics.TriangleRemoval.Tracking.PrefixPairClosureBudget
4
+
5
+ namespace OAI
6
+
7
+ section
8
+ noncomputable section
9
+ open scoped BigOperators Topology
10
+ open Filter Classical
11
+
12
+ namespace SharpTerminalLeave
13
+
14
+ lemma normalized_tracking_absolute {X s r : ℝ} (hs : 0 < s) (hr : 0 ≤ r)
15
+ (h : |X/s-1| ≤ r/2) : |X-s| ≤ r*s := by
16
+ rw [show X/s-1 = (X-s)/s by rw [sub_div,div_self hs.ne'],abs_div,abs_of_pos hs] at h
17
+ exact ((div_le_iff₀ hs).mp h).trans (mul_le_mul_of_nonneg_right (by linarith only [hr]) hs.le)
18
+
19
+ theorem prefix_good_history : ∀ᶠ n : ℕ in atTop,
20
+ ∀ ω : History (Graph n) (prefixTime n),
21
+ ω ∈ (historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)).support →
22
+ PrefixRootedUpper 8001 n ω → PrefixBalancedNoise 8001 n ω →
23
+ PrefixTriangleNoise n ω → PrefixCodegreeNoiseGood n ω →
24
+ GoodPrefixGraph n (1/80000) (3*(8001 : ℕ)+2 : ℕ) (ω (historyIndex (prefixTime n) (prefixTime n))) := by
25
+ filter_upwards [prefix_present_edge_closure,prefix_all_pair_closure,prefix_degree_wheel_tracking,
26
+ prefixDensity_eventually_inverse_lower,eventually_ge_atTop (1 : ℕ)] with n hedge hpair hwheel hp hn
27
+ intro ω hω hroot hbalanced htri hnoise
28
+ have hn0 : 0 < n := by omega
29
+ have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn
30
+ have hnR : (0 : ℝ) < n := lt_of_lt_of_le zero_lt_one hn1
31
+ have hedges := hedge ω hω hroot hbalanced htri hnoise
32
+ have halive : historyAlive (fun i => densityEdgeSafe n (earlyDensity n i) (prefixEdgeRadius n))
33
+ (prefixTime n) (prefixTime n) ω := fun i hi => hedges i hi.le
34
+ have he := hedges (prefixTime n) le_rfl
35
+ have hw := hwheel ω hω hroot hbalanced (prefixTime n) le_rfl halive
36
+ have hc := hpair ω hω hroot hbalanced htri hnoise (prefixTime n) le_rfl
37
+ have hpp : 0 < prefixDensity n := (div_pos zero_lt_one hnR).trans_le hp
38
+ have hr : 0 ≤ prefixWheelRadius n := Real.rpow_nonneg hnR.le _
39
+ have hdeg := mul_pos hnR hpp
40
+ have hD : 0 < prefixD n := mul_pos hnR (sq_pos_of_pos hpp)
41
+ refine ⟨he.1,?_,?_,?_,?_,?_⟩
42
+ · simpa only [earlyDensity_prefix,prefixM] using he.2.1
43
+ · intro u
44
+ have hh := hw.1 u
45
+ rw [earlyDensity_prefix] at hh
46
+ simpa only [prefixWheelRadius,neg_div] using normalized_tracking_absolute hdeg hr hh
47
+ · intro u v huv
48
+ have hh := hc u v huv
49
+ simp only [prefixNormalizedCodegree,earlyTemplateScale,pow_one,earlyDensity_prefix] at hh
50
+ simpa only [prefixD,prefixWheelRadius,neg_div] using normalized_tracking_absolute hD hr hh
51
+ · intro j hj hj' u
52
+ have hh := hw.2 j hj hj' u
53
+ rw [earlyDensity_prefix] at hh
54
+ simpa only [prefixD,prefixWheelRadius,neg_div] using normalized_tracking_absolute (pow_pos hD j) hr hh
55
+ · intro k hk T ψ
56
+ have hh := (hroot (prefixTime n) le_rfl halive k hk T ψ).le
57
+ rw [earlyDensity_prefix] at hh
58
+ have hfac : (1+Real.log (n : ℝ))^(3*8001+2) = prefixTemplateFactor n (3*(8001 : ℕ)+2 : ℕ) := by
59
+ simp only [prefixTemplateFactor,Real.rpow_natCast]
60
+ rw [hfac] at hh
61
+ have hfac0 : 0 ≤ prefixTemplateFactor n (3*(8001 : ℕ)+2 : ℕ) := Real.rpow_nonneg (by have := Real.log_nonneg hn1; linarith) _
62
+ constructor
63
+ · intro hlarge
64
+ exact hh.trans (mul_le_mul_of_nonneg_left (rootedCompletionMax_large T hpp.le hlarge) hfac0)
65
+ · intro hsmall
66
+ exact hh.trans ((mul_le_mul_of_nonneg_left (rootedCompletionMax_small T hsmall) hfac0).trans_eq (mul_one _))
67
+
68
+ lemma four_prefix_margins : ∀ᶠ n : ℕ in atTop,
69
+ 4*Real.exp (-2*(Real.log (n : ℝ))^(4/3 : ℝ)) ≤
70
+ Real.exp (-(Real.log (n : ℝ))^(4/3 : ℝ)) := by
71
+ have ht : Tendsto (fun n : ℕ => (Real.log (n : ℝ))^(4/3 : ℝ)) atTop atTop :=
72
+ (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 4/3)).comp
73
+ (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop)
74
+ filter_upwards [ht.eventually (eventually_ge_atTop (Real.log 4))] with n hn
75
+ have hh : (4 : ℝ) ≤ Real.exp ((Real.log (n : ℝ))^(4/3 : ℝ)) := by
76
+ calc
77
+ (4 : ℝ) = Real.exp (Real.log 4) := (Real.exp_log (by norm_num)).symm
78
+ _ ≤ _ := Real.exp_le_exp.mpr hn
79
+ calc
80
+ _ ≤ Real.exp ((Real.log (n : ℝ))^(4/3 : ℝ))*Real.exp (-2*(Real.log (n : ℝ))^(4/3 : ℝ)) :=
81
+ mul_le_mul_of_nonneg_right hh (Real.exp_pos _).le
82
+ _ = _ := by rw [← Real.exp_add]; congr 1; ring
83
+
84
+ theorem uniform_prefix_obligation : UniformPrefixObligation := by
85
+ refine ⟨1/80000,by norm_num,(3*(8001 : ℕ)+2 : ℕ),?_⟩
86
+ filter_upwards [prefix_good_history,prefix_rooted_upper_failure 8001,
87
+ prefix_balanced_noise_failure 8001,prefix_triangle_noise_failure,
88
+ prefix_codegree_noise_failure,four_prefix_margins] with n hgood hr hb ht hc hmargin
89
+ let μ := historyLaw (PMF.pure (completeGraph n)) (fun _ => step) (prefixTime n) (prefixTime n)
90
+ have hm : μ.map (fun ω => ω (historyIndex (prefixTime n) (prefixTime n))) = prefixLaw n := by
91
+ rw [historyLaw_marginal _ _ _ _ le_rfl,markovLaw_triangle_step]
92
+ rfl
93
+ unfold prefixFailure
94
+ rw [← hm,pmfMean_map]
95
+ have hpoint : ∀ ω ∈ μ.support,
96
+ (if GoodPrefixGraph n (1/80000) (3*(8001 : ℕ)+2 : ℕ) (ω (historyIndex (prefixTime n) (prefixTime n))) then (0 : ℝ) else 1) ≤
97
+ (if PrefixRootedUpper 8001 n ω then 0 else 1)+
98
+ (if PrefixBalancedNoise 8001 n ω then 0 else 1)+
99
+ (if PrefixTriangleNoise n ω then 0 else 1)+
100
+ (if PrefixCodegreeNoiseGood n ω then 0 else 1) := by
101
+ intro ω hω
102
+ by_cases h₁ : PrefixRootedUpper 8001 n ω <;>
103
+ by_cases h₂ : PrefixBalancedNoise 8001 n ω <;>
104
+ by_cases h₃ : PrefixTriangleNoise n ω <;>
105
+ by_cases h₄ : PrefixCodegreeNoiseGood n ω
106
+ all_goals simp only [h₁,h₂,h₃,h₄,ite_true,ite_false]
107
+ · rw [ite_eq_left (hgood ω hω h₁ h₂ h₃ h₄)]; norm_num
108
+ all_goals split_ifs <;> norm_num
109
+ have hs := pmfMean_mono μ hpoint
110
+ simp only [pmfMean_add] at hs
111
+ apply hs.trans
112
+ have hs' := add_le_add (add_le_add (add_le_add hr hb) ht) hc
113
+ calc
114
+ _ ≤ ((Real.exp (-2*(Real.log (n : ℝ))^(4/3 : ℝ))+
115
+ Real.exp (-2*(Real.log (n : ℝ))^(4/3 : ℝ)))+
116
+ Real.exp (-2*(Real.log (n : ℝ))^(4/3 : ℝ)))+
117
+ Real.exp (-2*(Real.log (n : ℝ))^(4/3 : ℝ)) := hs'
118
+ _ = 4*Real.exp (-2*(Real.log (n : ℝ))^(4/3 : ℝ)) := by ring
119
+ _ ≤ _ := hmargin
120
+
121
+ end SharpTerminalLeave
122
+ end
123
+ end
124
+
125
+ end OAI