| | @@ -0,0 +1,236 @@ |
| 1 | +import ErdosSwarm.Erdos530Gap.RefinementRules |
| 2 | + |
| 3 | +/-! |
| 4 | +# Counting yes answers and quadruples in the graph refinement for Erdős #530 |
| 5 | + |
| 6 | +This is the accounting in §1 of |
| 7 | +`experiments/erdos530/upper-canonical-deletion/NOTES.md`. Edges lost on a |
| 8 | +step have a removed endpoint. A discarded triple meets a removed vertex or |
| 9 | +contains a newly inserted edge. These two charges bound the total insertions, |
| 10 | +including constraints that do not survive to the leaf. The initial containers |
| 11 | +come from the one-step construction of [Phal and Gemini, §4](https://github.com/shubhamphal/erdos-530/blob/42a01f6/paper/erdos_530.tex). |
| 12 | +-/ |
| 13 | + |
| 14 | +namespace ErdosSwarm.Erdos530Gap |
| 15 | + |
| 16 | +open Finset Refinement Refinement.Accounting |
| 17 | + |
| 18 | +private lemma card_biUnion_bound {α : Type*} [DecidableEq α] {S : Finset α} |
| 19 | + {f : α → Faces} {d : ℕ} (h : ∀ p ∈ S, (f p).card ≤ d) : |
| 20 | + (S.biUnion f).card ≤ S.card * d := calc |
| 21 | + _ ≤ ∑ p ∈ S, (f p).card := card_biUnion_le |
| 22 | + _ ≤ ∑ _ ∈ S, d := sum_le_sum h |
| 23 | + _ = _ := by simp |
| 24 | + |
| 25 | +/-- Charge every lost constraint using the degrees just before the pruning. -/ |
| 26 | +private lemma charge_discarded {s : State} {l : ℕ} {fixed D : Finset ℕ} {E T : Faces} |
| 27 | + (hs : Invariant s l) (b : Batch s l D E T) : |
| 28 | + let s' := prune s fixed D E T |
| 29 | + s.edges.card + E.card ≤ s'.edges.card + D.card * (2 * l) ∧ |
| 30 | + s.triples.card + T.card ≤ s'.triples.card + D.card * (2 * l ^ 2) + E.card * (2 * l) := by |
| 31 | + let s' := prune s fixed D E T |
| 32 | + let edges := s.edges ∪ E |
| 33 | + let triples := s.triples ∪ T |
| 34 | + let atVertex (F : Faces) (x : ℕ) := incident F {x} |
| 35 | + have outside (t : Finset ℕ) (ht : t ⊆ s.live) (hn : ¬t ⊆ s'.live) : |
| 36 | + ∃ x ∈ D, x ∈ t := by |
| 37 | + by_contra! h |
| 38 | + exact hn (fun x hx => mem_sdiff.mpr ⟨ht hx, fun hd => h x hd hx⟩) |
| 39 | + have edgeCover : edges ⊆ s'.edges ∪ D.biUnion (atVertex edges) := by |
| 40 | + intro e he |
| 41 | + by_cases h : e ⊆ s'.live |
| 42 | + · exact mem_union_left _ (mem_filter.mpr ⟨he, h⟩) |
| 43 | + · obtain ⟨x, hx, hxe⟩ := outside e ((hs.edges.union b.edges) e he).1 h |
| 44 | + exact mem_union_right _ (mem_biUnion.mpr ⟨x, hx, mem_filter.mpr ⟨he, singleton_subset_iff.mpr hxe⟩⟩) |
| 45 | + have tripleCover : triples ⊆ (s'.triples ∪ D.biUnion (atVertex triples)) ∪ |
| 46 | + E.biUnion (incident triples) := by |
| 47 | + intro t ht |
| 48 | + by_cases hlive : t ⊆ s'.live |
| 49 | + · by_cases hclean : ∀ e ∈ s'.edges, ¬ e ⊆ t |
| 50 | + · exact mem_union_left _ (mem_union_left _ (mem_filter.mpr ⟨ht, hlive, hclean⟩)) |
| 51 | + · push Not at hclean |
| 52 | + obtain ⟨e, he, het⟩ := hclean |
| 53 | + have hnew : e ∈ E := (mem_union.mp (mem_filter.mp he).1).resolve_left (fun heOld => |
| 54 | + (mem_union.mp ht).elim (fun htOld => hs.avoids t htOld e heOld het) |
| 55 | + (fun htNew => b.avoids t htNew e heOld het)) |
| 56 | + exact mem_union_right _ (mem_biUnion.mpr ⟨e, hnew, mem_filter.mpr ⟨ht, het⟩⟩) |
| 57 | + · obtain ⟨x, hx, hxt⟩ := outside t ((hs.triples.union b.triples) t ht).1 hlive |
| 58 | + exact mem_union_left _ (mem_union_right _ (mem_biUnion.mpr |
| 59 | + ⟨x, hx, mem_filter.mpr ⟨ht, singleton_subset_iff.mpr hxt⟩⟩)) |
| 60 | + have hve : (D.biUnion (atVertex edges)).card ≤ D.card * (2 * l) := |
| 61 | + card_biUnion_bound fun x _ => b.edgeDeg {x} (card_singleton x) |
| 62 | + have hvt : (D.biUnion (atVertex triples)).card ≤ D.card * (2 * l ^ 2) := |
| 63 | + card_biUnion_bound fun x _ => b.tripleDeg {x} (card_singleton x) |
| 64 | + have het : (E.biUnion (incident triples)).card ≤ E.card * (2 * l) := |
| 65 | + card_biUnion_bound fun e he => b.pairDeg e (b.edges e he).2 |
| 66 | + constructor |
| 67 | + · calc |
| 68 | + _ = edges.card := (card_union_of_disjoint b.freshEdges).symm |
| 69 | + _ ≤ _ := (card_le_card edgeCover).trans (card_union_le _ _) |
| 70 | + _ ≤ _ := Nat.add_le_add_left hve _ |
| 71 | + · calc |
| 72 | + _ = triples.card := (card_union_of_disjoint b.freshTriples).symm |
| 73 | + _ ≤ _ := (card_le_card tripleCover).trans (card_union_le _ _) |
| 74 | + _ ≤ _ := Nat.add_le_add ((card_union_le _ _).trans (Nat.add_le_add_left hvt _)) het |
| 75 | + |
| 76 | +/-- Each effective step spends a vertex or a pair still available as a new edge. -/ |
| 77 | +private def available (s : State) : Faces := s.live.powersetCard 2 \ s.edges |
| 78 | + |
| 79 | +private def fuel (s : State) := s.live.card + (available s).card |
| 80 | + |
| 81 | +private lemma fuel_decreases {s : State} {l : ℕ} {fixed D : Finset ℕ} {E T : Faces} |
| 82 | + (b : Batch s l D E T) (h : D.Nonempty ∨ E.Nonempty) : fuel (prune s fixed D E T) < fuel s := by |
| 83 | + let s' := prune s fixed D E T |
| 84 | + have hU : s'.live ⊆ s.live := sdiff_subset |
| 85 | + have subset : available s' ⊆ available s := by |
| 86 | + intro e he |
| 87 | + obtain ⟨heU, heG⟩ := mem_sdiff.mp he |
| 88 | + obtain ⟨heU, hcard⟩ := mem_powersetCard.mp heU |
| 89 | + exact mem_sdiff.mpr ⟨mem_powersetCard.mpr ⟨heU.trans hU, hcard⟩, |
| 90 | + fun hg => heG (mem_filter.mpr ⟨mem_union_left _ hg, heU⟩)⟩ |
| 91 | + change s'.live.card + (available s').card < s.live.card + (available s).card |
| 92 | + rcases h with hr | he |
| 93 | + · have hsum : s'.live.card + D.card = s.live.card := card_sdiff_add_card_eq_card b.removed |
| 94 | + have hpos := card_pos.mpr hr |
| 95 | + exact Nat.add_lt_add_of_lt_of_le (by omega) (card_le_card subset) |
| 96 | + · obtain ⟨e, he⟩ := he |
| 97 | + have old : e ∈ available s := |
| 98 | + mem_sdiff.mpr ⟨mem_powersetCard.mpr (b.edges e he), fun hg => disjoint_left.mp b.freshEdges hg he⟩ |
| 99 | + have new : e ∉ available s' := by |
| 100 | + intro h' |
| 101 | + obtain ⟨hm, hn⟩ := mem_sdiff.mp h' |
| 102 | + exact hn (mem_filter.mpr ⟨mem_union_right _ he, (mem_powersetCard.mp hm).1⟩) |
| 103 | + have strict : available s' ⊂ available s := ssubset_of_subset_of_ne subset (fun eq => new (eq ▸ old)) |
| 104 | + exact Nat.add_lt_add_of_le_of_lt (card_le_card hU) (card_lt_card strict) |
| 105 | + |
| 106 | +/-- The witnesses are the cumulative numbers of edge and triple insertions. |
| 107 | +The live constraints are carried forward to charge them if they disappear later. -/ |
| 108 | +private def AccountingBound (n l : ℕ) (s : State) (Y : Finset ℕ) : Prop := |
| 109 | + ∃ g t : ℕ, |
| 110 | + g + 2 * l * s.live.card ≤ 2 * l * n + s.edges.card ∧ |
| 111 | + t + 2 * l ^ 2 * s.live.card ≤ 2 * l ^ 2 * n + 2 * l * g + s.triples.card ∧ |
| 112 | + l ^ 3 * Y.card + l ^ 2 * s.live.card ≤ l ^ 2 * n + l * g + t |
| 113 | + |
| 114 | +private lemma accounting_after {n l i : ℕ} {s s' : State} {Y : Finset ℕ} {yes : Bool} |
| 115 | + (hs : Invariant s l) (h : AccountingBound n l s Y) (step : Effect s s' l yes) : |
| 116 | + AccountingBound n l s' (if yes then insert i Y else Y) := by |
| 117 | + obtain ⟨fixed, D, E, T, rfl, b, _, cost⟩ := step |
| 118 | + let s' := prune s fixed D E T |
| 119 | + obtain ⟨g, t, hg, ht, hy⟩ := h |
| 120 | + obtain ⟨he, htr⟩ := charge_discarded (fixed := fixed) hs b |
| 121 | + have hd : s'.live.card + D.card = s.live.card := card_sdiff_add_card_eq_card b.removed |
| 122 | + change s.edges.card + E.card ≤ s'.edges.card + D.card * (2 * l) at he |
| 123 | + change s.triples.card + T.card ≤ s'.triples.card + D.card * (2 * l ^ 2) + E.card * (2 * l) at htr |
| 124 | + refine ⟨g + E.card, t + T.card, ?_, ?_, ?_⟩ |
| 125 | + · change g + E.card + 2 * l * s'.live.card ≤ _ |
| 126 | + linarith only [hg, he, congrArg (fun k => 2 * l * k) hd] |
| 127 | + · change t + T.card + 2 * l ^ 2 * s'.live.card ≤ _ |
| 128 | + linarith only [ht, htr, congrArg (fun k => 2 * l ^ 2 * k) hd] |
| 129 | + · change l ^ 3 * (if yes = true then insert i Y else Y).card + l ^ 2 * s'.live.card ≤ _ |
| 130 | + cases yes |
| 131 | + · simp only [Bool.false_eq_true, ↓reduceIte] |
| 132 | + linarith only [hy, congrArg (fun k => l ^ 2 * k) hd, Nat.zero_le (l ^ 2 * D.card), |
| 133 | + Nat.zero_le (l * E.card), Nat.zero_le T.card] |
| 134 | + · simp only [↓reduceIte] |
| 135 | + linarith only [hy, congrArg (fun k => l ^ 2 * k) hd, cost rfl, |
| 136 | + Nat.mul_le_mul_left (l ^ 3) (card_insert_le i Y)] |
| 137 | + |
| 138 | +private lemma accounting_initial (C : Finset ℕ) (l : ℕ) : |
| 139 | + Invariant ⟨∅, C, ∅, ∅⟩ l := by |
| 140 | + constructor <;> simp [Uniform, Avoids, Bounded, incident] |
| 141 | + |
| 142 | +private lemma run_bounds (C : Finset ℕ) (l : ℕ) (answer : ℕ → Finset ℕ → Bool) (hl : 3 ≤ l) |
| 143 | + (i : ℕ) : |
| 144 | + let r := run C l answer i |
| 145 | + Invariant r.1 l ∧ r.1.live ⊆ C ∧ AccountingBound C.card l r.1 r.2 ∧ |
| 146 | + (query r.1 l = none ∨ i + fuel r.1 ≤ steps C) := by |
| 147 | + induction i with |
| 148 | + | zero => |
| 149 | + refine ⟨accounting_initial C l, Subset.rfl, ⟨0, 0, ?_⟩, Or.inr ?_⟩ |
| 150 | + · simp [run] |
| 151 | + · simp [run, fuel, steps, available] |
| 152 | + | succ i ih => |
| 153 | + rcases hr : run C l answer i with ⟨s, Y⟩ |
| 154 | + obtain ⟨hs, hC, hb, hi⟩ : Invariant s l ∧ s.live ⊆ C ∧ AccountingBound C.card l s Y ∧ |
| 155 | + (query s l = none ∨ i + fuel s ≤ steps C) := by simpa only [hr] using ih |
| 156 | + cases hq : query s l with |
| 157 | + | none => |
| 158 | + have hh : query s l = none ∨ i + 1 + fuel s ≤ steps C := Or.inl hq |
| 159 | + simpa only [run, hr, hq] using And.intro hs (And.intro hC (And.intro hb hh)) |
| 160 | + | some q => |
| 161 | + obtain ⟨step⟩ := selection_effect hl hs (hq ▸ selection hs) (answer i q.face) |
| 162 | + have hb' := accounting_after (i := i) hs hb step |
| 163 | + obtain ⟨fixed, D, E, T, heq, b, hp, _⟩ := step |
| 164 | + simp only [run, hr, hq, heq] at hb' ⊢ |
| 165 | + refine ⟨b.invariant hs, sdiff_subset.trans hC, hb', Or.inr ?_⟩ |
| 166 | + have hbefore := hi.resolve_left (by simp [hq]) |
| 167 | + have hafter := fuel_decreases (fixed := fixed) b hp |
| 168 | + omega |
| 169 | + |
| 170 | +/-- The first two rules share the removal budget, and the next two share the |
| 171 | +edge-insertion budget. Charging each yes only once gives the coefficient nine. -/ |
| 172 | +private lemma yes_bound {n l : ℕ} {s : State} {Y : Finset ℕ} (hl : 3 ≤ l) |
| 173 | + (hs : Invariant s l) (h : AccountingBound n l s Y) : l * Y.card ≤ 9 * n := by |
| 174 | + obtain ⟨g, t, hg, ht, hy⟩ := h |
| 175 | + have he := card_mul_width_le hs.edges hs.edgeDeg |
| 176 | + have htr := card_mul_width_le hs.triples hs.tripleDeg |
| 177 | + have hG : g ≤ 2 * n * l := by linarith only [hg, he, Nat.zero_le s.edges.card] |
| 178 | + have hT : t ≤ 6 * n * l ^ 2 := by |
| 179 | + linarith only [ht, htr, Nat.zero_le s.triples.card, Nat.mul_le_mul_left (2 * l) hG] |
| 180 | + have hY : l ^ 2 * (l * Y.card) ≤ l ^ 2 * (9 * n) := by |
| 181 | + linarith only [hy, hT, Nat.mul_le_mul_left l hG, Nat.zero_le (l ^ 2 * s.live.card)] |
| 182 | + exact Nat.le_of_mul_le_mul_left hY (by positivity) |
| 183 | + |
| 184 | +/-- In an independent set, each nonactive quadruple contains a stored triple. -/ |
| 185 | +private lemma terminal_bound {s : State} {l : ℕ} (hs : Invariant s l) (stop : query s l = none) |
| 186 | + {J : Finset ℕ} (hJ : J ⊆ s.live) (hind : s.leaf.graph.IsIndepSet (J : Set ℕ)) : |
| 187 | + 4 * (additiveQuadruples J).card ≤ s.live.card * (l ^ 3 + 8 * l ^ 2) := by |
| 188 | + have sel : Selection s l none := stop ▸ selection hs |
| 189 | + have ha : Bounded (active s) 1 (l ^ 3) := by cases sel with | stop h => exact h |
| 190 | + have noEdge : ∀ e ∈ s.edges, ¬e ⊆ J := by |
| 191 | + intro e he hsub |
| 192 | + obtain ⟨x, y, hxy, rfl⟩ := card_eq_two.mp (hs.edges e he).2 |
| 193 | + exact hind (hsub (mem_insert_self _ _)) (hsub (mem_insert_of_mem (mem_singleton_self _))) |
| 194 | + hxy ⟨hxy, he⟩ |
| 195 | + have cover : quads J ⊆ active s ∪ s.triples.biUnion (incident (quads J)) := by |
| 196 | + intro q hq |
| 197 | + by_cases h : ∃ t ∈ s.triples, t ⊆ q |
| 198 | + · obtain ⟨t, ht, htq⟩ := h |
| 199 | + exact mem_union_right _ (mem_biUnion.mpr ⟨t, ht, mem_filter.mpr ⟨hq, htq⟩⟩) |
| 200 | + · exact mem_union_left _ (mem_filter.mpr ⟨quads_mono hJ hq, fun u hu huq => |
| 201 | + (mem_union.mp hu).elim (fun he => noEdge u he (huq.trans ((quads_uniform J) q hq).1)) |
| 202 | + (fun ht => h ⟨u, ht, huq⟩)⟩) |
| 203 | + have hc := (card_le_card cover).trans (card_union_le _ _) |
| 204 | + have hd := card_biUnion_bound (S := s.triples) (f := incident (quads J)) |
| 205 | + (fun t ht => quads_triple_degree J t (hs.triples t ht).2) |
| 206 | + have hA := card_mul_width_le ((quads_uniform s.live).subfamily (active_sub s)) ha |
| 207 | + have hT := card_mul_width_le hs.triples hs.tripleDeg |
| 208 | + rw [card_quads] at hc |
| 209 | + linarith only [hc, hd, hA, hT] |
| 210 | + |
| 211 | +/-- The five-rule run uses at most `16 |C| / l` yes answers. In the resulting |
| 212 | +leaf, double counting active quadruples and the triples on an independent |
| 213 | +set bounds all of its additive quadruples. -/ |
| 214 | +theorem refinement_accounting (C I : Finset ℕ) (l : ℕ) (hl : 3 ≤ l) : |
| 215 | + (hI : I ⊆ C) → (hsid : IsSidon (I : Set ℕ)) → |
| 216 | + let r := follow C l I |
| 217 | + l * r.2.card ≤ 16 * C.card ∧ |
| 218 | + ∀ J ⊆ r.1.live, r.1.leaf.graph.IsIndepSet (J : Set ℕ) → |
| 219 | + 4 * (additiveQuadruples J).card ≤ C.card * (l ^ 3 + 8 * l ^ 2) := by |
| 220 | + intro _ _ |
| 221 | + let r := follow C l I |
| 222 | + obtain ⟨hs, hC, hb, hi⟩ := run_bounds C l (fun _ q => decide (q ⊆ I)) hl (steps C) |
| 223 | + change query r.1 l = none ∨ steps C + fuel r.1 ≤ steps C at hi |
| 224 | + have stop : query r.1 l = none := by |
| 225 | + cases hq : query r.1 l with |
| 226 | + | none => rfl |
| 227 | + | some q => |
| 228 | + have hz := hi.resolve_left (by simp [hq]) |
| 229 | + obtain ⟨step⟩ := selection_effect hl (s := r.1) hs (hq ▸ selection hs) false |
| 230 | + have hlt := fuel_decreases (fixed := step.fixed) step.batch step.progress |
| 231 | + omega |
| 232 | + refine ⟨(yes_bound hl hs hb).trans (Nat.mul_le_mul_right _ (by decide : 9 ≤ 16)), |
| 233 | + fun J hJ hind => ?_⟩ |
| 234 | + exact (terminal_bound hs stop hJ hind).trans (Nat.mul_le_mul_right _ (card_le_card hC)) |
| 235 | + |
| 236 | +end ErdosSwarm.Erdos530Gap |